@pixerate/editor-svelte 0.195.0 → 0.196.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,8 @@
17
17
  onchange: (brush: Brush) => void;
18
18
  /** A live preview stroke of `brush`: pixels (e.g. `controller.brushThumbnail`) or an image URL. */
19
19
  preview?: { width: number; height: number; data: Uint8ClampedArray } | string | null;
20
+ /** The colour behind an image-URL preview, for transparent previews (see `brushPreviewColours`). */
21
+ previewBackground?: string;
20
22
  /** With it, a "Save" button (labelled `saveLabel`) saves the brush in place. */
21
23
  onsave?: () => unknown;
22
24
  /** The Save button's label (default "Save"; e.g. "Save a copy" for a built-in). */
@@ -27,7 +29,7 @@
27
29
  extra?: Snippet<[string]>;
28
30
  class?: string;
29
31
  }
30
- let { brush, profile = PAINT_PROFILE, onchange, preview, onsave, saveLabel = 'Save', onsaveas, extra, class: className = '' }: Props = $props();
32
+ let { brush, profile = PAINT_PROFILE, onchange, preview, previewBackground, onsave, saveLabel = 'Save', onsaveas, extra, class: className = '' }: Props = $props();
31
33
  const sections = $derived(brushEditorSections(brush, profile));
32
34
  const scope = $derived(brushEditorScope(brush, profile));
33
35
  let problems = $state<string | null>(null);
@@ -58,7 +60,7 @@
58
60
  -->
59
61
  <div class={`flex flex-col gap-2 ${className}`} data-testid="brush-editor">
60
62
  {#if typeof preview === 'string'}
61
- <img src={preview} alt="Brush preview" class="rounded object-contain" style="width: 100%; aspect-ratio: 4 / 1" />
63
+ <img src={preview} alt="Brush preview" class="rounded object-contain" style={`width: 100%; aspect-ratio: 4 / 1${previewBackground ? `; background: ${previewBackground}` : ''}`} />
62
64
  {:else if preview !== undefined}
63
65
  <PixelCanvas pixels={preview} label="Brush preview" class="rounded" style={`width: 100%; aspect-ratio: ${preview ? `${preview.width} / ${preview.height}` : '4 / 1'}`} />
64
66
  {/if}
@@ -16,6 +16,8 @@ interface Props {
16
16
  height: number;
17
17
  data: Uint8ClampedArray;
18
18
  } | string | null;
19
+ /** The colour behind an image-URL preview, for transparent previews (see `brushPreviewColours`). */
20
+ previewBackground?: string;
19
21
  /** With it, a "Save" button (labelled `saveLabel`) saves the brush in place. */
20
22
  onsave?: () => unknown;
21
23
  /** The Save button's label (default "Save"; e.g. "Save a copy" for a built-in). */
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { brushColourHex, checkBrushEdit, newBrushFor, saveBrushEdit, type Brush, type BrushHostProfile, type BrushLibrary, type BrushPreviewRenderer } from '@pixerate/editor/brushes';
2
+ import { brushPreviewColours, checkBrushEdit, newBrushFor, saveBrushEdit, type Brush, type BrushHostProfile, type BrushLibrary, type BrushPreviewRenderer } from '@pixerate/editor/brushes';
3
3
  import { button } from './styles.js';
4
4
  import BrushEditor from './BrushEditor.svelte';
5
5
 
@@ -12,7 +12,12 @@
12
12
  profile: BrushHostProfile;
13
13
  /** Draws the preview stroke (the host's renderer, as for `preview_brush`). Without it there is no preview. */
14
14
  renderPreview?: BrushPreviewRenderer;
15
- /** The preview colour for brushes with no solid default colour (default slate). */
15
+ /**
16
+ * What a transparent preview is shown on (#rrggbb, default white); the renderer's own `paper`
17
+ * wins. The preview colour is chosen to read on it (`brushPreviewColours`).
18
+ */
19
+ previewPaper?: string;
20
+ /** A fixed preview colour instead (overrides the brush's own and the contrast check). */
16
21
  previewColor?: string;
17
22
  /** Called with the brush as saved (a copy has a new id): e.g. pick it in the host. */
18
23
  onsaved?: (brush: Brush) => void;
@@ -20,7 +25,7 @@
20
25
  onclose?: () => void;
21
26
  class?: string;
22
27
  }
23
- let { library, brushId = null, profile, renderPreview, previewColor = '#64748b', onsaved, onclose, class: className = '' }: Props = $props();
28
+ let { library, brushId = null, profile, renderPreview, previewPaper = '#ffffff', previewColor, onsaved, onclose, class: className = '' }: Props = $props();
24
29
 
25
30
  let original = $state<Brush | null>(null);
26
31
  let builtin = $state(false);
@@ -46,7 +51,9 @@
46
51
  };
47
52
  });
48
53
 
49
- const colour = $derived((draft && brushColourHex(draft.colour?.default ?? '', 'light')) || previewColor);
54
+ // The preview colour reads on what the preview is drawn on: the renderer's paper, or the box behind it.
55
+ const colours = $derived(draft ? brushPreviewColours($state.snapshot(draft) as Brush, { paper: renderPreview?.paper ?? previewPaper, profile }) : null);
56
+ const colour = $derived(previewColor ?? colours?.color ?? '#475569');
50
57
  $effect(() => {
51
58
  const d = draft;
52
59
  const render = renderPreview;
@@ -99,6 +106,7 @@
99
106
  brush={draft}
100
107
  {profile}
101
108
  preview={renderPreview ? preview : undefined}
109
+ previewBackground={colours?.background}
102
110
  onchange={(next) => {
103
111
  draft = next;
104
112
  status = null;
@@ -8,7 +8,12 @@ interface Props {
8
8
  profile: BrushHostProfile;
9
9
  /** Draws the preview stroke (the host's renderer, as for `preview_brush`). Without it there is no preview. */
10
10
  renderPreview?: BrushPreviewRenderer;
11
- /** The preview colour for brushes with no solid default colour (default slate). */
11
+ /**
12
+ * What a transparent preview is shown on (#rrggbb, default white); the renderer's own `paper`
13
+ * wins. The preview colour is chosen to read on it (`brushPreviewColours`).
14
+ */
15
+ previewPaper?: string;
16
+ /** A fixed preview colour instead (overrides the brush's own and the contrast check). */
12
17
  previewColor?: string;
13
18
  /** Called with the brush as saved (a copy has a new id): e.g. pick it in the host. */
14
19
  onsaved?: (brush: Brush) => void;
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import StickerPicker from './StickerPicker.svelte';
3
3
  import { brushLoadColor, brushTakesPaint, downloadBytes, toggleStickerRef, DEFAULT_PAINT_GRADIENT, type PaintEditorController } from '@pixerate/editor/paint-editor';
4
- import { brushColourHex, PAINT_PROFILE, type Brush, type BrushLibraryEntry } from '@pixerate/editor/brushes';
4
+ import { brushColourHex, brushPreviewColours, PAINT_PROFILE, type Brush, type BrushLibraryEntry } from '@pixerate/editor/brushes';
5
5
  import { untrack } from 'svelte';
6
6
  import BrushEditor from '../brushes/BrushEditor.svelte';
7
7
  import BrushLibraryBrowser from '../brushes/BrushLibraryBrowser.svelte';
@@ -28,7 +28,7 @@
28
28
  const thumbs = $derived.by(() => {
29
29
  const list = library;
30
30
  void paper;
31
- return untrack(() => new Map(list.map((b) => [b.id, controller.brushThumbnail(b.id, { width: thumbnailWidth, height: thumbnailHeight, color: '#26324a' })])));
31
+ return untrack(() => new Map(list.map((b) => [b.id, controller.brushThumbnail(b.id, { width: thumbnailWidth, height: thumbnailHeight, color: brushPreviewColours(controller.getBrushSpec(b.id)!, { paper: controller.getState().document.paper.color }).color })])));
32
32
  });
33
33
  const entries = $derived.by<BrushLibraryEntry[]>(() => {
34
34
  const list = library;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-svelte",
3
- "version": "0.195.0",
3
+ "version": "0.196.0",
4
4
  "description": "Svelte bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -175,7 +175,7 @@
175
175
  "**/*.css"
176
176
  ],
177
177
  "dependencies": {
178
- "@pixerate/editor": "0.264.0"
178
+ "@pixerate/editor": "0.265.0"
179
179
  },
180
180
  "peerDependencies": {
181
181
  "@dagrejs/dagre": "^1.1.4",