@weasel-js/paint-kinds 1.19.1 → 2.0.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.
package/README.md CHANGED
@@ -9,7 +9,7 @@ editor and a serializer read: its label and glyph, the paint it seeds from a col
9
9
  SVG.
10
10
 
11
11
  ```ts
12
- import { getPaintKind, registerPaintKind, switchGradientKind } from '@weasel-js/paint-kinds';
12
+ import { getPaintKind, registerPaintKind, withPaintKind } from '@weasel-js/paint-kinds';
13
13
  import { usePaintKinds } from '@weasel-js/paint-kinds/react';
14
14
  ```
15
15
 
@@ -1,6 +1,6 @@
1
- import { gradientForBounds, isTilePaint, isGradientPaint, withGradientKind } from '@weasel-js/paint';
1
+ import { gradientForBounds, isTilePaint, tryParseColor, isGradientPaint, withGradientKind } from '@weasel-js/paint';
2
2
  import { createReflectable } from '@weasel-js/registry';
3
- import { registerPaintDrawKind, registerPaintDrawKindLoader, getPaintDrawKind } from '@weasel-js/renderer';
3
+ import { registerPaintDrawKind, registerPaintDrawKindLoader, isPaintKindKnown, warmPaintKinds } from '@weasel-js/renderer';
4
4
 
5
5
  // src/paintKinds.ts
6
6
  var patternFamily = { id: "pattern", label: "Pattern", icon: (
@@ -57,6 +57,7 @@ var BUILTINS = [
57
57
  colorOf: () => void 0
58
58
  }
59
59
  ];
60
+ var BUILTIN_ENTRIES = new Set(BUILTINS);
60
61
  function tileKind(id, label) {
61
62
  return {
62
63
  id,
@@ -76,54 +77,61 @@ function gradientKind(id, label, icon) {
76
77
  icon,
77
78
  // `bounds` units make the seed independent of the node's actual size.
78
79
  seed: (color) => gradientForBounds(id, UNIT_BOX, twoStopRamp(color), "bounds"),
79
- colorOf: (paint) => paint.stops?.[0]?.color,
80
+ colorOf: (paint) => firstStop(paint.stops)?.color,
80
81
  stopsOf: (paint) => paint.stops,
81
82
  fromStops: (stops) => gradientForBounds(id, UNIT_BOX, stops, "bounds")
82
83
  };
83
84
  }
85
+ function firstStop(stops) {
86
+ let first;
87
+ for (const stop of stops ?? []) if (!first || stop.offset < first.offset) first = stop;
88
+ return first;
89
+ }
84
90
  var UNIT_BOX = { x: 0, y: 0, width: 1, height: 1 };
85
91
  function twoStopRamp(color) {
86
- const isWhite = color.slice(0, 7).toLowerCase() === "#ffffff";
92
+ const rgba = tryParseColor(color);
93
+ const isWhite = rgba !== null && rgba[0] === 1 && rgba[1] === 1 && rgba[2] === 1;
87
94
  return [{ offset: 0, color }, { offset: 1, color: isWhite ? "#000000ff" : "#ffffffff" }];
88
95
  }
89
- var KINDS = createReflectable();
96
+ var KINDS = createReflectable({ name: "paint kinds" });
90
97
  var LAZY_BUILTINS = [
91
98
  ["mesh-gradient", async () => (await import('./meshKindLazy.js')).meshGradientKind]
92
99
  ];
93
100
  function seed() {
94
101
  for (const entry of BUILTINS) {
95
- KINDS.push(entry.id, entry, { source: "kit" });
96
- registerPaintDrawKind(entry);
102
+ KINDS.push(entry.id, entry, { source: "kit", fallback: true });
103
+ registerPaintDrawKind(entry, { fallback: true });
97
104
  }
98
- for (const [id, load] of LAZY_BUILTINS) registerPaintKindLoader(id, load);
105
+ for (const [id, load] of LAZY_BUILTINS) registerPaintKindLoader(id, load, { fallback: true });
99
106
  }
100
107
  seed();
101
108
  var paintKindRegistry = KINDS.reflection;
102
- function registerPaintKind(entry) {
109
+ function registerPaintKind(entry, options) {
103
110
  if (entry.stopsOf === void 0 !== (entry.fromStops === void 0)) {
104
111
  const missing = entry.stopsOf === void 0 ? "stopsOf" : "fromStops";
105
112
  throw new Error(
106
113
  `weasel registerPaintKind: kind "${entry.id}" is missing ${missing}. A gradient kind reads as a stop list and builds from one; supply both or neither.`
107
114
  );
108
115
  }
109
- const dropDraw = registerPaintDrawKind(entry);
110
- const dropEntry = KINDS.push(entry.id, entry);
116
+ const dropDraw = registerPaintDrawKind(entry, options);
117
+ const dropEntry = KINDS.push(entry.id, entry, options);
111
118
  return () => {
112
119
  dropEntry();
113
120
  dropDraw();
114
121
  };
115
122
  }
116
- function registerPaintKindLoader(id, load) {
117
- return registerPaintDrawKindLoader(id, async () => {
118
- const entry = await load();
119
- if (entry.id === id && !KINDS.has(id)) registerPaintKind(entry);
120
- return entry;
123
+ function registerPaintKindLoader(id, load, options) {
124
+ return registerPaintDrawKindLoader(id, load, {
125
+ fallback: options?.fallback,
126
+ register: (entry) => registerPaintKind(entry, options),
127
+ has: (kind) => KINDS.has(kind)
121
128
  });
122
129
  }
123
130
  function getPaintKind(kind) {
124
131
  const id = kind ?? "solid";
125
132
  const entry = KINDS.get(id);
126
- if (!entry) getPaintDrawKind(id);
133
+ if (!entry && isPaintKindKnown(id)) void warmPaintKinds([id]).catch(() => {
134
+ });
127
135
  return entry;
128
136
  }
129
137
  function derivedList(derive) {
@@ -148,12 +156,12 @@ function listGradientKinds() {
148
156
  var gradientKinds = derivedList(
149
157
  (all) => all.map((e) => e.value).filter((entry) => entry.stopsOf && entry.fromStops)
150
158
  );
151
- function switchGradientKind(paint, kind) {
159
+ function withPaintKind(paint, kind) {
152
160
  const from = paintKindOf(paint);
153
161
  const to = getPaintKind(kind);
154
162
  if (!from?.stopsOf || !to?.fromStops) return void 0;
155
163
  if (from.id === to.id) return paint;
156
- if (isGradientPaint(paint) && isGradientPaint({ kind })) {
164
+ if (BUILTIN_ENTRIES.has(from) && BUILTIN_ENTRIES.has(to) && isGradientPaint(paint) && isGradientPaint({ kind })) {
157
165
  return withGradientKind(paint, kind);
158
166
  }
159
167
  const { interpolate, opacity } = paint;
@@ -163,14 +171,14 @@ function switchGradientKind(paint, kind) {
163
171
  ...opacity !== void 0 ? { opacity } : {}
164
172
  };
165
173
  }
166
- function paintKindOf(fill) {
167
- return getPaintKind(fill.kind ?? "solid");
174
+ function paintKindOf(paint) {
175
+ return getPaintKind(paint.kind ?? "solid");
168
176
  }
169
177
  function _reseedPaintKinds() {
170
178
  KINDS.clear();
171
179
  seed();
172
180
  }
173
181
 
174
- export { _reseedPaintKinds, getPaintKind, listGradientKinds, listPaintKinds, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, switchGradientKind };
175
- //# sourceMappingURL=chunk-OZAYBSMO.js.map
176
- //# sourceMappingURL=chunk-OZAYBSMO.js.map
182
+ export { _reseedPaintKinds, getPaintKind, listGradientKinds, listPaintKinds, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, withPaintKind };
183
+ //# sourceMappingURL=chunk-QOCBK67L.js.map
184
+ //# sourceMappingURL=chunk-QOCBK67L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/paintKinds.ts"],"names":[],"mappings":";;;;;AAsBO,IAAM,aAAA,GAAiC,EAAE,EAAA,EAAI,SAAA,EAAW,OAAO,SAAA,EAAW,IAAA;;AAAM,EAAA;AAAgB,CAAA;AAEvG,IAAM,QAAA,GAAsC;AAC1C,EAAA;IACE,EAAA,EAAI,OAAA;IACJ,KAAA,EAAO,OAAA;AACP,IAAA,IAAA;;AAAM,MAAA;;IACN,IAAA,EAAM,CAAC,KAAA,MAAW,EAAE,KAAA,EAAM,CAAA;AAC1B,IAAA,OAAA,EAAS,CAAC,KAAA,KAAA,CAAY,KAAA,CAAM,QAAQ,OAAA,MAAa,OAAA,GAC5C,MAA4B,KAAA,GAC7B;AACN,GAAA;AACA,EAAA,YAAA;AAAa,IAAA,iBAAA;AAAmB,IAAA,QAAA;;AAAU,IAAA;AAAc,GAAA;AACxD,EAAA,YAAA;AAAa,IAAA,iBAAA;AAAmB,IAAA,QAAA;;AAAU,IAAA;AAAc,GAAA;AACxD,EAAA,YAAA;AAAa,IAAA,gBAAA;AAAkB,IAAA,OAAA;;AAAS,IAAA;AAAa,GAAA;AACrD,EAAA,QAAA,CAAS,SAAS,OAAO,CAAA;AACzB,EAAA,QAAA,CAAS,cAAc,YAAY,CAAA;AACnC,EAAA,QAAA,CAAS,QAAQ,MAAM,CAAA;AACvB,EAAA,QAAA,CAAS,UAAU,QAAQ,CAAA;AAC3B,EAA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O,CAAC,KAAA,KAAU,KAAA,CAAM,OAAA,IAAW,MAAM,SAAS;AACrF,CAAA;AAYO,SAAS,aAAA,CAAc,OAAc,IAAA,EAAoC;AAC9E,EAAA,MAAM,IAAA,GAAO,YAAY,KAAK,CAAA;AAC9B,EAAA,MAAM,EAAA,GAAK,aAAa,IAAI,CAAA;AAC5B,EAAA,IAAI,CAAC,IAAA,EAAM,OAAA,IAAW,CAAC,EAAA,EAAI,WAAW,OAAO,MAAA;AAC7C,EAAA,IAAI,IAAA,CAAK,EAAA,KAAO,EAAA,CAAG,EAAA,EAAI,OAAO,KAAA;AAC9B,EAAA,IAAI,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA,IAAK,gBAAgB,GAAA,CAAI,EAAE,CAAA,IAAK,eAAA,CAAgB,KAAK,CAAA,IAAK,eAAA,CAAgB,EAAE,IAAA,EAAe,CAAA,EAAG;AACxH,IAAA,OAAO,gBAAA,CAAiB,OAAO,IAAoB,CAAA;AACrD,EAAA;AACA,EAAA,MAAM,EAAE,WAAA,EAAa,OAAA,EAAQ,GAAI,KAAA;AACjC,EAAA,OAAO;AACL,IAAA,GAAG,EAAA,CAAG,SAAA,CAAU,IAAA,CAAK,OAAA,CAAQ,KAAK,CAAC,CAAA;AACnC,IAAA,GAAI,WAAA,KAAgB,MAAA,GAAY,EAAE,WAAA,KAAgB,EAAC;AACnD,IAAA,GAAI,OAAA,KAAY,MAAA,GAAY,EAAE,OAAA,KAAY;AAC5C,GAAA;AACF;AAGO,SAAS,YAAY,KAAA,EAA0C;AACpE,EAAA,OAAO,YAAA,CAAa,KAAA,CAAM,IAAA,IAAQ,OAAO,CAAA;AAC3C;AAIO,SAAS,iBAAA,GAA0B;AACxC,EAAA,KAAA,CAAM,KAAA,EAAM;AACZ,EAAA,IAAA,EAAK;AACP","file":"chunk-QOCBK67L.js","sourcesContent":["/**\n * The paint-kind registry — what makes `Paint` open. The built-in kinds\n * are registered here at module load so an editor's kind bar can enumerate\n * every kind through one list.\n *\n * Every entry is also handed to the renderer's own registry, which reads only\n * its draw slots. A built-in kind has none: its render slot is a branch in the\n * GL renderer and its serialize slot lives in `@weasel-js/svg`.\n */\n\nimport type {\n ColorSpace, Paint, GradientPaint, GradientKind, GradStop, TileKind, TilePaint,\n} from '@weasel-js/paint';\nimport { gradientForBounds, isGradientPaint, isTilePaint, tryParseColor, withGradientKind } from '@weasel-js/paint';\nimport { createReflectable, type PushOptions, type ReflectedEntry, type Reflection } from '@weasel-js/registry';\nimport { isPaintKindKnown, registerPaintDrawKind, registerPaintDrawKindLoader, warmPaintKinds } from '@weasel-js/renderer';\nimport type { PaintKind, PaintKindEntry, PaintKindFamily } from './paintKindEntry';\nimport type { IconRef } from '@weasel-js/icons';\nimport { icon } from './icons.gen';\n\n/** The family the built-in tiles, `image` and `texture` are offered under. A consumer's\n * own pattern kind joins it by naming this as its `family`. */\nexport const patternFamily: PaintKindFamily = { id: 'pattern', label: 'Pattern', icon: /* @icon */ 'paint-kinds:pattern' };\n\nconst BUILTINS: readonly PaintKindEntry[] = [\n {\n id: 'solid',\n label: 'Solid',\n icon: /* @icon */ 'paint-kinds:solid',\n seed: (color) => ({ color }),\n colorOf: (paint) => ((paint.kind ?? 'solid') === 'solid'\n ? (paint as { color: string }).color\n : undefined),\n },\n gradientKind('linear-gradient', 'Linear', /* @icon */ 'paint-kinds:linear'),\n gradientKind('radial-gradient', 'Radial', /* @icon */ 'paint-kinds:radial'),\n gradientKind('conic-gradient', 'Conic', /* @icon */ 'paint-kinds:conic'),\n tileKind('hatch', 'Hatch'),\n tileKind('crosshatch', 'Crosshatch'),\n tileKind('dots', 'Dots'),\n tileKind('chunks', 'Chunks'),\n {\n id: 'image',\n label: 'Image',\n family: patternFamily,\n // An image is chosen by the user and cannot be made from a color.\n seed: (color) => seedTile('hatch', color),\n colorOf: () => undefined,\n },\n {\n id: 'texture',\n label: 'Texture',\n family: patternFamily,\n // A texture is built by the consumer and cannot be made from a color.\n seed: (color) => seedTile('hatch', color),\n colorOf: () => undefined,\n },\n];\n\nconst BUILTIN_ENTRIES: ReadonlySet<PaintKindEntry> = new Set(BUILTINS);\n\nfunction tileKind(id: TileKind, label: string): PaintKindEntry {\n return {\n id,\n label,\n family: patternFamily,\n seed: (color) => seedTile(id, color),\n colorOf: (paint) => (isTilePaint(paint) ? paint.color : undefined),\n };\n}\n\n/** A tile paint seeded from a color. `units: 'bounds'` anchors the tile to the\n * node's box, so the texture travels with the shape. */\nexport function seedTile(kind: TileKind, color: string): TilePaint {\n // `chunks` is a scatter over a ground rather than a line texture; without a\n // background it reads as loose specks on whatever sits beneath.\n return kind === 'chunks'\n ? { kind, color, bg: '#00000000', units: 'bounds' }\n : { kind, color, units: 'bounds' };\n}\n\nfunction gradientKind(id: GradientKind, label: string, icon: IconRef): PaintKindEntry {\n return {\n id,\n label,\n icon,\n // `bounds` units make the seed independent of the node's actual size.\n seed: (color) => gradientForBounds(id, UNIT_BOX, twoStopRamp(color), 'bounds'),\n colorOf: (paint) => firstStop((paint as Partial<GradientPaint>).stops)?.color,\n stopsOf: (paint) => (paint as GradientPaint).stops,\n fromStops: (stops) => gradientForBounds(id, UNIT_BOX, stops, 'bounds'),\n };\n}\n\n/** The stop at the gradient's start: stop lists are drawn sorted, but need not be written so. */\nfunction firstStop(stops: readonly GradStop[] | undefined): GradStop | undefined {\n let first: GradStop | undefined;\n for (const stop of stops ?? []) if (!first || stop.offset < first.offset) first = stop;\n return first;\n}\n\nconst UNIT_BOX = { x: 0, y: 0, width: 1, height: 1 };\n\n/** `color` to a contrasting end — white reads against any hue; against white\n * itself, black does. */\nfunction twoStopRamp(color: string): GradStop[] {\n const rgba = tryParseColor(color);\n const isWhite = rgba !== null && rgba[0] === 1 && rgba[1] === 1 && rgba[2] === 1;\n return [{ offset: 0, color }, { offset: 1, color: isWhite ? '#000000ff' : '#ffffffff' }];\n}\n\nconst KINDS = createReflectable<PaintKindEntry>({ name: 'paint kinds' });\n\n/** Resolves with the entry for a kind that is loaded on first use. */\nexport type PaintKindLoader = () => Promise<PaintKindEntry>;\n\n// A built-in kind heavy enough to keep off a consumer's bundle until a paint\n// of it turns up. Importing the module statically still registers it at once.\nconst LAZY_BUILTINS: ReadonlyArray<readonly [string, PaintKindLoader]> = [\n ['mesh-gradient', async () => (await import('./meshKindLazy')).meshGradientKind],\n];\n\nfunction seed(): void {\n for (const entry of BUILTINS) {\n KINDS.push(entry.id, entry, { source: 'kit', fallback: true });\n registerPaintDrawKind(entry, { fallback: true });\n }\n for (const [id, load] of LAZY_BUILTINS) registerPaintKindLoader(id, load, { fallback: true });\n}\nseed();\n\n/** Every registered paint kind, with the overrides each displaced. */\nexport const paintKindRegistry: Reflection<PaintKindEntry> = KINDS.reflection;\n\n/** Register a paint kind. Returns a disposer that removes it. Re-registering an\n * existing id is an override; disposing it uncovers whatever it displaced.\n * `fallback` marks an engine default, which a later registration replaces\n * without the development clash warning. */\nexport function registerPaintKind(entry: PaintKindEntry, options?: Pick<PushOptions, 'fallback'>): () => void {\n if ((entry.stopsOf === undefined) !== (entry.fromStops === undefined)) {\n const missing = entry.stopsOf === undefined ? 'stopsOf' : 'fromStops';\n throw new Error(\n `weasel registerPaintKind: kind \"${entry.id}\" is missing ${missing}. A ` +\n 'gradient kind reads as a stop list and builds from one; supply both or neither.',\n );\n }\n // The draw half goes first: it is the one that can throw, and the editor's\n // list fires its subscribers on push.\n const dropDraw = registerPaintDrawKind(entry, options);\n const dropEntry = KINDS.push(entry.id, entry, options);\n return () => {\n dropEntry();\n dropDraw();\n };\n}\n\n/**\n * Declare a paint kind that is loaded the first time something looks it up,\n * so its code stays out of the bundle until a paint of it appears — typically\n * `() => import('./myKind').then((m) => m.myKindEntry)`.\n *\n * Until it lands the kind is unregistered: the renderer draws nothing for its\n * paints, and every other reader treats it as unknown. Registering it fires\n * `paintKindRegistry`'s subscribers. Call `warmPaintKinds` to load ahead of\n * the first frame instead.\n *\n * A kind that is already registered never calls its loader. Declaring a\n * second loader for an id overrides the first, whether or not the first has\n * started or failed. The returned disposer removes this loader, uncovering\n * whatever it displaced, and the kind it registered.\n */\nexport function registerPaintKindLoader(id: string, load: PaintKindLoader, options?: Pick<PushOptions, 'fallback'>): () => void {\n return registerPaintDrawKindLoader(id, load, {\n fallback: options?.fallback,\n register: (entry: PaintKindEntry) => registerPaintKind(entry, options),\n has: (kind) => KINDS.has(kind),\n });\n}\n\n/** The entry for `kind`, or `undefined`. A lookup that misses on a kind with\n * a loader starts that load; see {@link registerPaintKindLoader}. */\nexport function getPaintKind(kind: string | undefined): PaintKindEntry | undefined {\n const id = kind ?? 'solid';\n const entry = KINDS.get(id);\n if (!entry && isPaintKindKnown(id)) void warmPaintKinds([id]).catch(() => {});\n return entry;\n}\n\n/** A list derived from the registry, recomputed only when it changes — so\n * its identity is a `useSyncExternalStore` snapshot. */\nfunction derivedList(\n derive: (all: readonly ReflectedEntry<PaintKindEntry>[]) => readonly PaintKindEntry[],\n): () => readonly PaintKindEntry[] {\n let from: readonly ReflectedEntry<PaintKindEntry>[] | undefined;\n let list: readonly PaintKindEntry[] = [];\n return () => {\n const entries = KINDS.entries();\n if (entries !== from) {\n from = entries;\n list = Object.freeze(derive(entries));\n }\n return list;\n };\n}\n\n/** Every registered kind, built-ins first, in registration order. The same\n * array until the registry changes. */\nexport function listPaintKinds(): readonly PaintKindEntry[] {\n return allKinds();\n}\nconst allKinds = derivedList((all) => all.map((e) => e.value));\n\n/** Every registered gradient kind — the ones that read as and build from a\n * stop list — in registration order. The same array until the registry\n * changes. */\nexport function listGradientKinds(): readonly PaintKindEntry[] {\n return gradientKinds();\n}\nconst gradientKinds = derivedList(\n (all) => all.map((e) => e.value).filter((entry) => entry.stopsOf && entry.fromStops),\n);\n\n/**\n * `paint` retargeted to gradient kind `kind`, or `undefined` when either side\n * is not a gradient kind.\n *\n * Between two of the built-in stop gradients this is `withGradientKind`, which\n * carries the geometry. Any other pair, an override of a built-in included,\n * goes through the stop list — `stopsOf` on the way out, `fromStops` on the\n * way in — keeping `interpolate` and `opacity`.\n * Lossy wherever the kinds hold different information.\n */\nexport function withPaintKind(paint: Paint, kind: PaintKind): Paint | undefined {\n const from = paintKindOf(paint);\n const to = getPaintKind(kind);\n if (!from?.stopsOf || !to?.fromStops) return undefined;\n if (from.id === to.id) return paint;\n if (BUILTIN_ENTRIES.has(from) && BUILTIN_ENTRIES.has(to) && isGradientPaint(paint) && isGradientPaint({ kind } as Paint)) {\n return withGradientKind(paint, kind as GradientKind);\n }\n const { interpolate, opacity } = paint as { interpolate?: ColorSpace; opacity?: number };\n return {\n ...to.fromStops(from.stopsOf(paint)),\n ...(interpolate !== undefined ? { interpolate } : {}),\n ...(opacity !== undefined ? { opacity } : {}),\n } as Paint;\n}\n\n/** The registry entry for a paint, or `undefined` when its kind is unknown. */\nexport function paintKindOf(paint: Paint): PaintKindEntry | undefined {\n return getPaintKind(paint.kind ?? 'solid');\n}\n\n/** @internal Back to the built-ins alone, once the renderer's half is reset too; tests reach it\n * through `_resetPaintKindsForTests` in `@weasel-js/paint-kinds/test-seams`. */\nexport function _reseedPaintKinds(): void {\n KINDS.clear();\n seed();\n}\n"]}
@@ -21,5 +21,5 @@ var meshGradientKind = {
21
21
  };
22
22
 
23
23
  export { meshGradientKind };
24
- //# sourceMappingURL=chunk-QJ5FJFNR.js.map
25
- //# sourceMappingURL=chunk-QJ5FJFNR.js.map
24
+ //# sourceMappingURL=chunk-S6QTXVCH.js.map
25
+ //# sourceMappingURL=chunk-S6QTXVCH.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/meshKind.ts"],"names":[],"mappings":";;;AASA,IAAM,MAAA,GAAS,CAAC,IAAA,KAAmC,IAAA;AACnD,IAAM,MAAA,GAAS,CAAC,IAAA,KAAmC,IAAA;AAI5C,IAAM,gBAAA,GAAmC;AAAA,EAC9C,GAAG,YAAA;AAAA,EACH,KAAA,EAAO,MAAA;AAAA;AAAA,EAEP,IAAA;AAAA;AAAA,IAAkB;AAAA,GAAA;AAAA,EAClB,MAAM,CAAC,KAAA,KAAU,MAAA,CAAO,aAAA,CAAc,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA,EAG5C,OAAA,EAAS,CAAC,KAAA,KAAU,MAAA,CAAO,KAAK,EAAE,OAAA,GAAU,CAAC,CAAA,EAAG,MAAA,GAAS,CAAC,CAAA;AAAA,EAC1D,SAAS,CAAC,KAAA,KAAU,SAAA,CAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAC3C,WAAW,CAAC,KAAA,KAAU,MAAA,CAAO,aAAA,CAAc,KAAK,CAAC,CAAA;AAAA,EACjD,KAAA,EAAO,CAAC,EAAA,EAAI,IAAA,KAAS,gBAAgB,EAAA,EAAI,MAAA,CAAO,IAAI,CAAC;AACvD","file":"chunk-QJ5FJFNR.js","sourcesContent":["import type { IconRef } from '@weasel-js/icons';\nimport type { Paint } from '@weasel-js/paint';\nimport {\n meshDrawKind, meshFromStops, meshGradientXml, meshStops, seedMeshPatch, type MeshGradientPaint,\n} from '@weasel-js/renderer/mesh';\nimport type { PaintKindEntry } from './paintKindEntry';\n\n// `asPaint`'s cast both ways, kept local: this module must import nothing\n// stateful, or `meshKindLazy`'s self-contained copy would duplicate it.\nconst asMesh = (fill: Paint): MeshGradientPaint => fill as unknown as MeshGradientPaint;\nconst asFill = (mesh: MeshGradientPaint): Paint => mesh as unknown as Paint;\n\n/** The `mesh-gradient` kind's registry entry. `./registerMesh` registers it;\n * the paint-kind registry loads it on demand otherwise. */\nexport const meshGradientKind: PaintKindEntry = {\n ...meshDrawKind,\n label: 'Mesh',\n // Written as library mode emits `icon('mesh')`: the call would pull the icons package into meshKindLazy.\n icon: /* @icon */ 'paint-kinds:mesh' as IconRef,\n seed: (color) => asFill(seedMeshPatch(color)),\n // The first corner of the first patch: a mesh has no single color, and this\n // is the one a fallback swatch and an SVG paint fallback both read.\n colorOf: (paint) => asMesh(paint).patches?.[0]?.colors?.[0],\n stopsOf: (paint) => meshStops(asMesh(paint)),\n fromStops: (stops) => asFill(meshFromStops(stops)),\n toSvg: (id, fill) => meshGradientXml(id, asMesh(fill)),\n};\n"]}
1
+ {"version":3,"sources":["../src/meshKind.ts"],"names":[],"mappings":";;;AASA,IAAM,MAAA,GAAS,CAAC,IAAA,KAAmC,IAAA;AACnD,IAAM,MAAA,GAAS,CAAC,IAAA,KAAmC,IAAA;AAK5C,IAAM,gBAAA,GAAmC;AAAA,EAC9C,GAAG,YAAA;AAAA,EACH,KAAA,EAAO,MAAA;AAAA;AAAA,EAEP,IAAA;AAAA;AAAA,IAAkB;AAAA,GAAA;AAAA,EAClB,MAAM,CAAC,KAAA,KAAU,MAAA,CAAO,aAAA,CAAc,KAAK,CAAC,CAAA;AAAA;AAAA;AAAA,EAG5C,OAAA,EAAS,CAAC,KAAA,KAAU,MAAA,CAAO,KAAK,EAAE,OAAA,GAAU,CAAC,CAAA,EAAG,MAAA,GAAS,CAAC,CAAA;AAAA,EAC1D,SAAS,CAAC,KAAA,KAAU,SAAA,CAAU,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAC3C,WAAW,CAAC,KAAA,KAAU,MAAA,CAAO,aAAA,CAAc,KAAK,CAAC,CAAA;AAAA,EACjD,KAAA,EAAO,CAAC,EAAA,EAAI,IAAA,KAAS,gBAAgB,EAAA,EAAI,MAAA,CAAO,IAAI,CAAC;AACvD","file":"chunk-S6QTXVCH.js","sourcesContent":["import type { IconRef } from '@weasel-js/icons';\nimport type { Paint } from '@weasel-js/paint';\nimport {\n meshDrawKind, meshFromStops, meshGradientXml, meshStops, seedMeshPatch, type MeshGradientPaint,\n} from '@weasel-js/renderer/mesh';\nimport type { PaintKindEntry } from './paintKindEntry';\n\n// `asPaint`'s cast both ways, kept local: this module must import nothing\n// stateful, or `meshKindLazy`'s self-contained copy would duplicate it.\nconst asMesh = (fill: Paint): MeshGradientPaint => fill as unknown as MeshGradientPaint;\nconst asFill = (mesh: MeshGradientPaint): Paint => mesh as unknown as Paint;\n\n/** The `mesh-gradient` kind's registry entry. Importing\n * `@weasel-js/paint-kinds/mesh` registers it; the paint-kind registry loads\n * it on demand otherwise. */\nexport const meshGradientKind: PaintKindEntry = {\n ...meshDrawKind,\n label: 'Mesh',\n // Written as library mode emits `icon('mesh')`: the call would pull the icons package into meshKindLazy.\n icon: /* @icon */ 'paint-kinds:mesh' as IconRef,\n seed: (color) => asFill(seedMeshPatch(color)),\n // The first corner of the first patch: a mesh has no single color, and this\n // is the one a fallback swatch and an SVG paint fallback both read.\n colorOf: (paint) => asMesh(paint).patches?.[0]?.colors?.[0],\n stopsOf: (paint) => meshStops(asMesh(paint)),\n fromStops: (stops) => asFill(meshFromStops(stops)),\n toSvg: (id, fill) => meshGradientXml(id, asMesh(fill)),\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Paint, TileKind, TilePaint, TilePatternSpec } from '@weasel-js/paint';
2
- import { Reflection } from '@weasel-js/registry';
3
- import { P as PaintKindEntry, a as PaintKindFamily, b as PaintKind } from './paintKindEntry-Ct0YJP8X.js';
4
- export { c as PaintKindEditorProps, d as asPaint } from './paintKindEntry-Ct0YJP8X.js';
2
+ import { Reflection, PushOptions } from '@weasel-js/registry';
3
+ import { P as PaintKindEntry, a as PaintKindFamily, b as PaintKind } from './paintKindEntry-Z83R9G-J.js';
4
+ export { c as PaintKindEditorProps, d as asPaint } from './paintKindEntry-Z83R9G-J.js';
5
5
  import { TileShape } from '@weasel-js/renderer/patterns-builtin';
6
6
  import 'react';
7
7
  import '@weasel-js/icons';
@@ -28,8 +28,10 @@ type PaintKindLoader = () => Promise<PaintKindEntry>;
28
28
  /** Every registered paint kind, with the overrides each displaced. */
29
29
  declare const paintKindRegistry: Reflection<PaintKindEntry>;
30
30
  /** Register a paint kind. Returns a disposer that removes it. Re-registering an
31
- * existing id is an override; disposing it uncovers whatever it displaced. */
32
- declare function registerPaintKind(entry: PaintKindEntry): () => void;
31
+ * existing id is an override; disposing it uncovers whatever it displaced.
32
+ * `fallback` marks an engine default, which a later registration replaces
33
+ * without the development clash warning. */
34
+ declare function registerPaintKind(entry: PaintKindEntry, options?: Pick<PushOptions, 'fallback'>): () => void;
33
35
  /**
34
36
  * Declare a paint kind that is loaded the first time something looks it up,
35
37
  * so its code stays out of the bundle until a paint of it appears — typically
@@ -40,10 +42,12 @@ declare function registerPaintKind(entry: PaintKindEntry): () => void;
40
42
  * `paintKindRegistry`'s subscribers. Call `warmPaintKinds` to load ahead of
41
43
  * the first frame instead.
42
44
  *
43
- * A kind that is already registered never calls its loader. Returns a
44
- * disposer that removes the loader.
45
+ * A kind that is already registered never calls its loader. Declaring a
46
+ * second loader for an id overrides the first, whether or not the first has
47
+ * started or failed. The returned disposer removes this loader, uncovering
48
+ * whatever it displaced, and the kind it registered.
45
49
  */
46
- declare function registerPaintKindLoader(id: string, load: PaintKindLoader): () => void;
50
+ declare function registerPaintKindLoader(id: string, load: PaintKindLoader, options?: Pick<PushOptions, 'fallback'>): () => void;
47
51
  /** The entry for `kind`, or `undefined`. A lookup that misses on a kind with
48
52
  * a loader starts that load; see {@link registerPaintKindLoader}. */
49
53
  declare function getPaintKind(kind: string | undefined): PaintKindEntry | undefined;
@@ -58,14 +62,15 @@ declare function listGradientKinds(): readonly PaintKindEntry[];
58
62
  * `paint` retargeted to gradient kind `kind`, or `undefined` when either side
59
63
  * is not a gradient kind.
60
64
  *
61
- * Between two of the stop gradients this is `withGradientKind`, which carries
62
- * the geometry. Any other pair goes through the stop list — `stopsOf` on the
63
- * way out, `fromStops` on the way in — keeping `interpolate` and `opacity`.
65
+ * Between two of the built-in stop gradients this is `withGradientKind`, which
66
+ * carries the geometry. Any other pair, an override of a built-in included,
67
+ * goes through the stop list — `stopsOf` on the way out, `fromStops` on the
68
+ * way in — keeping `interpolate` and `opacity`.
64
69
  * Lossy wherever the kinds hold different information.
65
70
  */
66
- declare function switchGradientKind(paint: Paint, kind: PaintKind): Paint | undefined;
71
+ declare function withPaintKind(paint: Paint, kind: PaintKind): Paint | undefined;
67
72
  /** The registry entry for a paint, or `undefined` when its kind is unknown. */
68
- declare function paintKindOf(fill: Paint): PaintKindEntry | undefined;
73
+ declare function paintKindOf(paint: Paint): PaintKindEntry | undefined;
69
74
 
70
75
  /** A glyph this package draws, by its bare name. */
71
76
  type PaintKindsIconName = 'solid' | 'linear' | 'radial' | 'conic' | 'mesh' | 'pattern' | 'inherit' | 'none';
@@ -83,8 +88,9 @@ declare module '@weasel-js/icons' {
83
88
  }
84
89
 
85
90
  /** Whether SVG has its own paint server for paint kind `kind`: solids, the
86
- * linear and radial gradients, and patterns. Any other kind is written in
87
- * weasel's namespace with a fallback color, which other renderers paint flat. */
91
+ * linear and radial gradients, tiles, and images. Any other kind, `texture`
92
+ * included, is written in weasel's namespace with a fallback color, which
93
+ * other renderers paint flat. */
88
94
  declare function nativeSvgKind(kind: string): boolean;
89
95
  /** Whether a gradient interpolating through `space` blends the same in every
90
96
  * SVG renderer — only sRGB, the default. A perceptual space still exports,
@@ -101,5 +107,5 @@ declare function tilePreviewSvg(spec: TilePatternSpec, background?: string): str
101
107
  /** `tilePreviewSvg` packed as a `url(...)` value for CSS `background-image`. */
102
108
  declare function tilePreviewCssUrl(spec: TilePatternSpec, background?: string): string;
103
109
 
104
- export { PaintKind, PaintKindEntry, PaintKindFamily, getPaintKind, listGradientKinds, listPaintKinds, nativeSvgKind, nativeSvgSpace, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, switchGradientKind, tilePreviewCssUrl, tilePreviewSvg, tileShapeXml };
110
+ export { PaintKind, PaintKindEntry, PaintKindFamily, getPaintKind, listGradientKinds, listPaintKinds, nativeSvgKind, nativeSvgSpace, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, tilePreviewCssUrl, tilePreviewSvg, tileShapeXml, withPaintKind };
105
111
  export type { PaintKindLoader, PaintKindsIconName };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { getPaintKind, listGradientKinds, listPaintKinds, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, switchGradientKind } from './chunk-OZAYBSMO.js';
1
+ export { getPaintKind, listGradientKinds, listPaintKinds, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, withPaintKind } from './chunk-QOCBK67L.js';
2
2
  import { isTileKind } from '@weasel-js/paint';
3
3
  import { trimNumber, RAD_TO_DEG } from '@weasel-js/geom';
4
4
  import { escapeAttr } from '@weasel-js/registry';
@@ -9,7 +9,7 @@ function asPaint(paint) {
9
9
  return paint;
10
10
  }
11
11
  function nativeSvgKind(kind) {
12
- return kind === "solid" || kind === "linear-gradient" || kind === "radial-gradient" || kind === "texture" || kind === "image" || isTileKind(kind);
12
+ return kind === "solid" || kind === "linear-gradient" || kind === "radial-gradient" || kind === "image" || isTileKind(kind);
13
13
  }
14
14
  function nativeSvgSpace(space) {
15
15
  return !space || space === "rgb";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/paintKindEntry.ts","../src/svgNative.ts","../src/tileSvg.ts"],"names":[],"mappings":";;;;;;;AA0FO,SAAS,QAAoC,KAAA,EAAiB;AACnE,EAAA,OAAO,KAAA;AACT;ACnFO,SAAS,cAAc,IAAA,EAAuB;AACnD,EAAA,OAAO,IAAA,KAAS,OAAA,IAAW,IAAA,KAAS,iBAAA,IAAqB,IAAA,KAAS,iBAAA,IAAqB,IAAA,KAAS,SAAA,IAAa,IAAA,KAAS,OAAA,IAAW,UAAA,CAAW,IAAI,CAAA;AAClJ;AAKO,SAAS,eAAe,KAAA,EAA2C;AACxE,EAAA,OAAO,CAAC,SAAS,KAAA,KAAU,KAAA;AAC7B;ACRO,SAAS,aAAa,KAAA,EAA0B;AACrD,EAAA,QAAQ,MAAM,IAAA;AAAM,IAClB,KAAK,MAAA;AACH,MAAA,OAAO,CAAA,UAAA,EAAa,UAAA,CAAW,KAAA,CAAM,EAAE,CAAC,CAAA,MAAA,EAAS,UAAA,CAA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CAAC,QAAQ,UAAA,CAAW,KAAA,CAAM,CAAC,CAAC,CAAA,SAAA,EACnD,UAAA,CAAW,MAAM,KAAK,CAAC,CAAA,UAAA,EAAa,UAAA,CAAW,KAAA,CAAM,MAAM,CAAC,CAAA,QAAA,EAC7D,UAAA,CAAW,KAAA,CAAM,KAAK,CAAC,CAAA,GAAA,CAAA;AAAA,IACtC;AACE,MAAA,OAAO,EAAA;AAAA;AAEb;AAMO,SAAS,cAAA,CAAe,MAAuB,UAAA,EAA6B;AACjF,EAAA,MAAM,QAAA,GAAW,aAAa,IAAI,CAAA;AAClC,EAAA,MAAM,CAAA,GAAI,UAAA,CAAW,QAAA,CAAS,IAAI,CAAA;AAClC,EAAA,MAAM,EAAA,GAAK,UAAA,GACP,CAAA,aAAA,EAAgB,CAAC,CAAA,UAAA,EAAa,CAAC,CAAA,QAAA,EAAW,UAAA,CAAW,UAAU,CAAC,CAAA,GAAA,CAAA,GAChE,EAAA;AACJ,EAAA,OAAO,kDAAkD,CAAC,CAAA,UAAA,EAAa,CAAC,CAAA,eAAA,EACpD,CAAC,IAAI,CAAC,CAAA,EAAA,EAAK,EAAE,CAAA,EAAG,SAAS,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,CAAE,IAAA,CAAK,EAAE,CAAC,CAAA,MAAA,CAAA;AAChF;AAGO,SAAS,iBAAA,CAAkB,MAAuB,UAAA,EAA6B;AACpF,EAAA,OAAO,2BAA2B,kBAAA,CAAmB,cAAA,CAAe,IAAA,EAAM,UAAU,CAAC,CAAC,CAAA,EAAA,CAAA;AACxF","file":"index.js","sourcesContent":["import type { ComponentType } from 'react';\nimport type { IconSpec } from '@weasel-js/icons';\nimport type { Paint, GradStop, TileKind } from '@weasel-js/paint';\nimport type { PaintDrawKind } from '@weasel-js/renderer';\n\n/**\n * `Paint`'s discriminant, open on the string the way `ChromeId` is: the\n * kinds the kit ships, plus whatever a consumer registers.\n */\nexport type PaintKind =\n | 'solid' | 'linear-gradient' | 'radial-gradient' | 'conic-gradient'\n | TileKind | 'image' | 'texture'\n | (string & {});\n\n/**\n * A set of kinds an editor offers as one choice. Kinds sharing a family show\n * as a single segment in a kind bar, named by the family, and the member is\n * picked inside that segment's body. The built-in tiles, `image` and `texture` are the\n * `patternFamily`.\n */\nexport interface PaintKindFamily {\n id: string;\n label: string;\n /** Glyph for the family's segment. */\n icon?: IconSpec;\n}\n\n/** What a registered kind's editor renders. `PaintInput` and `GradientEditor`\n * in `@weasel-js/ui` mount it, and draw a gradient kind's blend-space switch\n * beneath it. */\nexport interface PaintKindEditorProps {\n value: Paint;\n onInput?(next: Paint): void;\n onChange(next: Paint): void;\n /** An edit was abandoned, after `onInput` got its starting paint back. */\n onCancel?(): void;\n}\n\n/**\n * One paint kind: the renderer's draw slots, plus what an editor and a\n * serializer read.\n *\n * `seed`, `label` and `colorOf` are the editor's slots and every kind has\n * them. The rest are optional because a kind may not need them.\n */\nexport interface PaintKindEntry extends PaintDrawKind {\n label: string;\n /** Glyph naming this kind in an editor's kind bar. A kind without one is\n * named by its `label`. */\n icon?: IconSpec;\n /** The family this kind is offered under; see {@link PaintKindFamily}. A\n * kind without one is its own segment. */\n family?: PaintKindFamily;\n /** A paint of this kind seeded from a color — what an editor writes when a\n * consumer switches a solid to this kind. */\n seed(fromColor: string): Paint;\n /** The single color this paint shows, or `undefined` when it has none. */\n colorOf(paint: Paint): string | undefined;\n /** Editor slot. */\n Editor?: ComponentType<PaintKindEditorProps>;\n /**\n * The stop list this paint reads as. With `fromStops`, it is what makes a\n * kind a gradient: `listGradientKinds` returns the kinds carrying both, and\n * `switchGradientKind` converts between any two of them through the list.\n */\n stopsOf?(paint: Paint): GradStop[];\n /** A paint of this kind built from a stop list, in `bounds` units. The\n * converse of `stopsOf`; supply both or neither. */\n fromStops?(stops: GradStop[]): Paint;\n /**\n * The `<defs>` entry backing a `url(#id)` reference.\n *\n * SVG has paint servers for two gradients and a pattern and nothing else, so\n * a kind beyond those has no element to target: write a foreign-namespaced\n * one under the `wzl:` prefix `@weasel-js/svg` declares on the root whenever\n * a document holds such a paint. That package emits the fallback color\n * beside the reference on its own, from `colorOf`.\n */\n toSvg?(id: string, fill: Paint): string;\n}\n\n/**\n * A consumer's own paint, typed as a `Paint`.\n *\n * `Paint` stays a closed union: opening its discriminant would widen every\n * built-in member and break the narrowing the kit's own branches depend on.\n * A registered kind declares its own interface instead and passes it through\n * here — the kit reads only `kind` and hands the whole object back to that\n * kind's slots.\n */\nexport function asPaint<T extends { kind: string }>(paint: T): Paint {\n return paint as unknown as Paint;\n}\n","/**\n * Which paints SVG draws with its own elements, and which only through\n * weasel's namespace with a fallback.\n */\nimport { isTileKind } from '@weasel-js/paint';\n\n/** Whether SVG has its own paint server for paint kind `kind`: solids, the\n * linear and radial gradients, and patterns. Any other kind is written in\n * weasel's namespace with a fallback color, which other renderers paint flat. */\nexport function nativeSvgKind(kind: string): boolean {\n return kind === 'solid' || kind === 'linear-gradient' || kind === 'radial-gradient' || kind === 'texture' || kind === 'image' || isTileKind(kind);\n}\n\n/** Whether a gradient interpolating through `space` blends the same in every\n * SVG renderer — only sRGB, the default. A perceptual space still exports,\n * but renderers other than weasel blend it in sRGB. */\nexport function nativeSvgSpace(space: string | null | undefined): boolean {\n return !space || space === 'rgb';\n}\n","/**\n * A tile pattern as SVG markup: each shape of its geometry, and the tile alone\n * as a standalone document a swatch can show.\n */\nimport { RAD_TO_DEG, trimNumber } from '@weasel-js/geom';\nimport type { TilePatternSpec } from '@weasel-js/paint';\nimport { escapeAttr } from '@weasel-js/registry';\nimport { tileGeometry, type TileShape } from '@weasel-js/renderer/patterns-builtin';\n\n/** One shape of a tile as SVG markup: what a `<pattern>` holds, and a preview's body. */\nexport function tileShapeXml(shape: TileShape): string {\n switch (shape.kind) {\n case 'line':\n return `<line x1=\"${trimNumber(shape.x1)}\" y1=\"${trimNumber(shape.y1)}\" `\n + `x2=\"${trimNumber(shape.x2)}\" y2=\"${trimNumber(shape.y2)}\" `\n + `stroke=\"${escapeAttr(shape.color)}\" stroke-width=\"${trimNumber(shape.width)}\"/>`;\n case 'circle':\n return `<circle cx=\"${trimNumber(shape.cx)}\" cy=\"${trimNumber(shape.cy)}\" `\n + `r=\"${trimNumber(shape.r)}\" fill=\"${escapeAttr(shape.color)}\"/>`;\n case 'ellipse': {\n const deg = shape.rotation * RAD_TO_DEG;\n const transform = deg === 0\n ? ''\n : ` transform=\"rotate(${trimNumber(deg)} ${trimNumber(shape.cx)} ${trimNumber(shape.cy)})\"`;\n return `<ellipse cx=\"${trimNumber(shape.cx)}\" cy=\"${trimNumber(shape.cy)}\" `\n + `rx=\"${trimNumber(shape.rx)}\" ry=\"${trimNumber(shape.ry)}\" `\n + `fill=\"${escapeAttr(shape.color)}\"${transform}/>`;\n }\n case 'rect':\n return `<rect x=\"${trimNumber(shape.x)}\" y=\"${trimNumber(shape.y)}\" `\n + `width=\"${trimNumber(shape.width)}\" height=\"${trimNumber(shape.height)}\" `\n + `fill=\"${escapeAttr(shape.color)}\"/>`;\n default:\n return '';\n }\n}\n\n/**\n * A single tile as a standalone `<svg>` document, sized to its own extent,\n * for UI that shows a tile outside a document, such as a picker swatch.\n */\nexport function tilePreviewSvg(spec: TilePatternSpec, background?: string): string {\n const geometry = tileGeometry(spec);\n const s = trimNumber(geometry.size);\n const bg = background\n ? `<rect width=\"${s}\" height=\"${s}\" fill=\"${escapeAttr(background)}\"/>`\n : '';\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${s}\" height=\"${s}\" `\n + `viewBox=\"0 0 ${s} ${s}\">${bg}${geometry.shapes.map(tileShapeXml).join('')}</svg>`;\n}\n\n/** `tilePreviewSvg` packed as a `url(...)` value for CSS `background-image`. */\nexport function tilePreviewCssUrl(spec: TilePatternSpec, background?: string): string {\n return `url(\"data:image/svg+xml,${encodeURIComponent(tilePreviewSvg(spec, background))}\")`;\n}\n"]}
1
+ {"version":3,"sources":["../src/paintKindEntry.ts","../src/svgNative.ts","../src/tileSvg.ts"],"names":[],"mappings":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G,SAAS,MAAA,CAAO,GAAA,CAAI,YAAY,CAAA,CAAE,IAAA,CAAK,EAAE,CAAC,CAAA,MAAA,CAAA;AAChF;AAGO,SAAS,iBAAA,CAAkB,MAAuB,UAAA,EAA6B;AACpF,EAAA,OAAO,2BAA2B,kBAAA,CAAmB,cAAA,CAAe,IAAA,EAAM,UAAU,CAAC,CAAC,CAAA,EAAA,CAAA;AACxF","file":"index.js","sourcesContent":["import type { ComponentType } from 'react';\nimport type { IconSpec } from '@weasel-js/icons';\nimport type { Paint, GradStop, TileKind } from '@weasel-js/paint';\nimport type { PaintDrawKind } from '@weasel-js/renderer';\n\n/**\n * `Paint`'s discriminant, open on the string the way `ChromeId` is: the\n * kinds the kit ships, plus whatever a consumer registers.\n */\nexport type PaintKind =\n | 'solid' | 'linear-gradient' | 'radial-gradient' | 'conic-gradient'\n | TileKind | 'image' | 'texture'\n | (string & {});\n\n/**\n * A set of kinds an editor offers as one choice. Kinds sharing a family show\n * as a single segment in a kind bar, named by the family, and the member is\n * picked inside that segment's body. The built-in tiles, `image` and `texture` are the\n * `patternFamily`.\n */\nexport interface PaintKindFamily {\n id: string;\n label: string;\n /** Glyph for the family's segment. */\n icon?: IconSpec;\n}\n\n/** What a registered kind's editor renders. `PaintInput` and `GradientEditor`\n * in `@weasel-js/ui` mount it, and draw a gradient kind's blend-space switch\n * beneath it. */\nexport interface PaintKindEditorProps {\n value: Paint;\n onInput?(next: Paint): void;\n onChange(next: Paint): void;\n /** An edit was abandoned, after `onInput` got its starting paint back. */\n onCancel?(): void;\n}\n\n/**\n * One paint kind: the renderer's draw slots, plus what an editor and a\n * serializer read.\n *\n * `seed`, `label` and `colorOf` are the editor's slots and every kind has\n * them. The rest are optional because a kind may not need them.\n */\nexport interface PaintKindEntry extends PaintDrawKind {\n label: string;\n /** Glyph naming this kind in an editor's kind bar. A kind without one is\n * named by its `label`. */\n icon?: IconSpec;\n /** The family this kind is offered under; see {@link PaintKindFamily}. A\n * kind without one is its own segment. */\n family?: PaintKindFamily;\n /** A paint of this kind seeded from a color — what an editor writes when a\n * consumer switches a solid to this kind. */\n seed(fromColor: string): Paint;\n /** The single color this paint shows, or `undefined` when it has none. */\n colorOf(paint: Paint): string | undefined;\n /** Editor slot. */\n Editor?: ComponentType<PaintKindEditorProps>;\n /**\n * The stop list this paint reads as. With `fromStops`, it is what makes a\n * kind a gradient: `listGradientKinds` returns the kinds carrying both, and\n * `withPaintKind` converts between any two of them through the list.\n */\n stopsOf?(paint: Paint): GradStop[];\n /** A paint of this kind built from a stop list, in `bounds` units. The\n * converse of `stopsOf`; supply both or neither. */\n fromStops?(stops: GradStop[]): Paint;\n /**\n * The `<defs>` entry backing a `url(#id)` reference.\n *\n * SVG has paint servers for two gradients and a pattern and nothing else, so\n * a kind beyond those has no element to target: write a foreign-namespaced\n * one under the `wzl:` prefix `@weasel-js/svg` declares on the root whenever\n * a document holds such a paint. That package emits the fallback color\n * beside the reference on its own, from `colorOf`.\n */\n toSvg?(id: string, fill: Paint): string;\n}\n\n/**\n * A consumer's own paint, typed as a `Paint`.\n *\n * `Paint` stays a closed union: opening its discriminant would widen every\n * built-in member and break the narrowing the kit's own branches depend on.\n * A registered kind declares its own interface instead and passes it through\n * here — the kit reads only `kind` and hands the whole object back to that\n * kind's slots.\n */\nexport function asPaint<T extends { kind: string }>(paint: T): Paint {\n return paint as unknown as Paint;\n}\n","/**\n * Which paints SVG draws with its own elements, and which only through\n * weasel's namespace with a fallback.\n */\nimport { isTileKind } from '@weasel-js/paint';\n\n/** Whether SVG has its own paint server for paint kind `kind`: solids, the\n * linear and radial gradients, tiles, and images. Any other kind, `texture`\n * included, is written in weasel's namespace with a fallback color, which\n * other renderers paint flat. */\nexport function nativeSvgKind(kind: string): boolean {\n return kind === 'solid' || kind === 'linear-gradient' || kind === 'radial-gradient' || kind === 'image' || isTileKind(kind);\n}\n\n/** Whether a gradient interpolating through `space` blends the same in every\n * SVG renderer — only sRGB, the default. A perceptual space still exports,\n * but renderers other than weasel blend it in sRGB. */\nexport function nativeSvgSpace(space: string | null | undefined): boolean {\n return !space || space === 'rgb';\n}\n","/**\n * A tile pattern as SVG markup: each shape of its geometry, and the tile alone\n * as a standalone document a swatch can show.\n */\nimport { RAD_TO_DEG, trimNumber } from '@weasel-js/geom';\nimport type { TilePatternSpec } from '@weasel-js/paint';\nimport { escapeAttr } from '@weasel-js/registry';\nimport { tileGeometry, type TileShape } from '@weasel-js/renderer/patterns-builtin';\n\n/** One shape of a tile as SVG markup: what a `<pattern>` holds, and a preview's body. */\nexport function tileShapeXml(shape: TileShape): string {\n switch (shape.kind) {\n case 'line':\n return `<line x1=\"${trimNumber(shape.x1)}\" y1=\"${trimNumber(shape.y1)}\" `\n + `x2=\"${trimNumber(shape.x2)}\" y2=\"${trimNumber(shape.y2)}\" `\n + `stroke=\"${escapeAttr(shape.color)}\" stroke-width=\"${trimNumber(shape.width)}\"/>`;\n case 'circle':\n return `<circle cx=\"${trimNumber(shape.cx)}\" cy=\"${trimNumber(shape.cy)}\" `\n + `r=\"${trimNumber(shape.r)}\" fill=\"${escapeAttr(shape.color)}\"/>`;\n case 'ellipse': {\n const deg = shape.rotation * RAD_TO_DEG;\n const transform = deg === 0\n ? ''\n : ` transform=\"rotate(${trimNumber(deg)} ${trimNumber(shape.cx)} ${trimNumber(shape.cy)})\"`;\n return `<ellipse cx=\"${trimNumber(shape.cx)}\" cy=\"${trimNumber(shape.cy)}\" `\n + `rx=\"${trimNumber(shape.rx)}\" ry=\"${trimNumber(shape.ry)}\" `\n + `fill=\"${escapeAttr(shape.color)}\"${transform}/>`;\n }\n case 'rect':\n return `<rect x=\"${trimNumber(shape.x)}\" y=\"${trimNumber(shape.y)}\" `\n + `width=\"${trimNumber(shape.width)}\" height=\"${trimNumber(shape.height)}\" `\n + `fill=\"${escapeAttr(shape.color)}\"/>`;\n default:\n return '';\n }\n}\n\n/**\n * A single tile as a standalone `<svg>` document, sized to its own extent,\n * for UI that shows a tile outside a document, such as a picker swatch.\n */\nexport function tilePreviewSvg(spec: TilePatternSpec, background?: string): string {\n const geometry = tileGeometry(spec);\n const s = trimNumber(geometry.size);\n const bg = background\n ? `<rect width=\"${s}\" height=\"${s}\" fill=\"${escapeAttr(background)}\"/>`\n : '';\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${s}\" height=\"${s}\" `\n + `viewBox=\"0 0 ${s} ${s}\">${bg}${geometry.shapes.map(tileShapeXml).join('')}</svg>`;\n}\n\n/** `tilePreviewSvg` packed as a `url(...)` value for CSS `background-image`. */\nexport function tilePreviewCssUrl(spec: TilePatternSpec, background?: string): string {\n return `url(\"data:image/svg+xml,${encodeURIComponent(tilePreviewSvg(spec, background))}\")`;\n}\n"]}
package/dist/mesh.d.ts CHANGED
@@ -4,8 +4,9 @@ import '@weasel-js/icons';
4
4
  import '@weasel-js/paint';
5
5
  import '@weasel-js/renderer';
6
6
 
7
- /** The `mesh-gradient` kind's registry entry. `./registerMesh` registers it;
8
- * the paint-kind registry loads it on demand otherwise. */
7
+ /** The `mesh-gradient` kind's registry entry. Importing
8
+ * `@weasel-js/paint-kinds/mesh` registers it; the paint-kind registry loads
9
+ * it on demand otherwise. */
9
10
  declare const meshGradientKind: PaintKindEntry;
10
11
 
11
12
  export { meshGradientKind };
package/dist/mesh.js CHANGED
@@ -1,8 +1,8 @@
1
- import { meshGradientKind } from './chunk-QJ5FJFNR.js';
2
- export { meshGradientKind } from './chunk-QJ5FJFNR.js';
3
- import { registerPaintKind } from './chunk-OZAYBSMO.js';
1
+ import { meshGradientKind } from './chunk-S6QTXVCH.js';
2
+ export { meshGradientKind } from './chunk-S6QTXVCH.js';
3
+ import { registerPaintKind } from './chunk-QOCBK67L.js';
4
4
 
5
5
  // src/mesh.ts
6
- registerPaintKind(meshGradientKind);
6
+ registerPaintKind(meshGradientKind, { fallback: true });
7
7
  //# sourceMappingURL=mesh.js.map
8
8
  //# sourceMappingURL=mesh.js.map
package/dist/mesh.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mesh.ts"],"names":[],"mappings":";;;;;AAWA,iBAAA,CAAkB,gBAAgB,CAAA","file":"mesh.js","sourcesContent":["/**\n * @weasel-js/paint-kinds/mesh — importing it registers the `mesh-gradient`\n * kind at once, where the registry otherwise loads it on first use. It is the\n * one module of this package with a side effect, which is why the manifest\n * lists it under `sideEffects`.\n *\n * @packageDocumentation\n */\nimport { registerPaintKind } from './paintKinds';\nimport { meshGradientKind } from './meshKind';\n\nregisterPaintKind(meshGradientKind);\n\nexport { meshGradientKind };\n"]}
1
+ {"version":3,"sources":["../src/mesh.ts"],"names":[],"mappings":";;;;;AAWA,iBAAA,CAAkB,gBAAA,EAAkB,EAAE,QAAA,EAAU,IAAA,EAAM,CAAA","file":"mesh.js","sourcesContent":["/**\n * @weasel-js/paint-kinds/mesh — importing it registers the `mesh-gradient`\n * kind at once, where the registry otherwise loads it on first use. It is the\n * one module of this package with a side effect, which is why the manifest\n * lists it under `sideEffects`.\n *\n * @packageDocumentation\n */\nimport { registerPaintKind } from './paintKinds';\nimport { meshGradientKind } from './meshKind';\n\nregisterPaintKind(meshGradientKind, { fallback: true });\n\nexport { meshGradientKind };\n"]}
@@ -1,5 +1,5 @@
1
1
  export { meshGradientKind } from './mesh.js';
2
- import './paintKindEntry-Ct0YJP8X.js';
2
+ import './paintKindEntry-Z83R9G-J.js';
3
3
  import 'react';
4
4
  import '@weasel-js/icons';
5
5
  import '@weasel-js/paint';