@weasel-js/paint-kinds 0.0.0-stage → 1.19.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 orochi235
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @weasel-js/paint-kinds
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The registry of the kinds a weasel `Paint` can be.
4
+
5
+ `Paint` is a closed union whose `kind` names a registered entry. Solid, the three gradients, the tile patterns,
6
+ image and texture are built in, mesh loads on first use, and a consumer adds its own kind with `registerPaintKind`.
7
+ An entry carries the renderer's draw slots, which the same call registers with `@weasel-js/renderer`, and what an
8
+ editor and a serializer read: its label and glyph, the paint it seeds from a color, its editor, its stops, and its
9
+ SVG.
10
+
11
+ ```ts
12
+ import { getPaintKind, registerPaintKind, switchGradientKind } from '@weasel-js/paint-kinds';
13
+ import { usePaintKinds } from '@weasel-js/paint-kinds/react';
14
+ ```
15
+
16
+ The glyphs naming each kind, and the `none` and `inherit` paint states, are in the `paint-kinds` icon namespace:
17
+ `@weasel-js/paint-kinds/icons` is the table.
@@ -0,0 +1,176 @@
1
+ import { gradientForBounds, isTilePaint, isGradientPaint, withGradientKind } from '@weasel-js/paint';
2
+ import { createReflectable } from '@weasel-js/registry';
3
+ import { registerPaintDrawKind, registerPaintDrawKindLoader, getPaintDrawKind } from '@weasel-js/renderer';
4
+
5
+ // src/paintKinds.ts
6
+ var patternFamily = { id: "pattern", label: "Pattern", icon: (
7
+ /* @icon */
8
+ "paint-kinds:pattern"
9
+ ) };
10
+ var BUILTINS = [
11
+ {
12
+ id: "solid",
13
+ label: "Solid",
14
+ icon: (
15
+ /* @icon */
16
+ "paint-kinds:solid"
17
+ ),
18
+ seed: (color) => ({ color }),
19
+ colorOf: (paint) => (paint.kind ?? "solid") === "solid" ? paint.color : void 0
20
+ },
21
+ gradientKind(
22
+ "linear-gradient",
23
+ "Linear",
24
+ /* @icon */
25
+ "paint-kinds:linear"
26
+ ),
27
+ gradientKind(
28
+ "radial-gradient",
29
+ "Radial",
30
+ /* @icon */
31
+ "paint-kinds:radial"
32
+ ),
33
+ gradientKind(
34
+ "conic-gradient",
35
+ "Conic",
36
+ /* @icon */
37
+ "paint-kinds:conic"
38
+ ),
39
+ tileKind("hatch", "Hatch"),
40
+ tileKind("crosshatch", "Crosshatch"),
41
+ tileKind("dots", "Dots"),
42
+ tileKind("chunks", "Chunks"),
43
+ {
44
+ id: "image",
45
+ label: "Image",
46
+ family: patternFamily,
47
+ // An image is chosen by the user and cannot be made from a color.
48
+ seed: (color) => seedTile("hatch", color),
49
+ colorOf: () => void 0
50
+ },
51
+ {
52
+ id: "texture",
53
+ label: "Texture",
54
+ family: patternFamily,
55
+ // A texture is built by the consumer and cannot be made from a color.
56
+ seed: (color) => seedTile("hatch", color),
57
+ colorOf: () => void 0
58
+ }
59
+ ];
60
+ function tileKind(id, label) {
61
+ return {
62
+ id,
63
+ label,
64
+ family: patternFamily,
65
+ seed: (color) => seedTile(id, color),
66
+ colorOf: (paint) => isTilePaint(paint) ? paint.color : void 0
67
+ };
68
+ }
69
+ function seedTile(kind, color) {
70
+ return kind === "chunks" ? { kind, color, bg: "#00000000", units: "bounds" } : { kind, color, units: "bounds" };
71
+ }
72
+ function gradientKind(id, label, icon) {
73
+ return {
74
+ id,
75
+ label,
76
+ icon,
77
+ // `bounds` units make the seed independent of the node's actual size.
78
+ seed: (color) => gradientForBounds(id, UNIT_BOX, twoStopRamp(color), "bounds"),
79
+ colorOf: (paint) => paint.stops?.[0]?.color,
80
+ stopsOf: (paint) => paint.stops,
81
+ fromStops: (stops) => gradientForBounds(id, UNIT_BOX, stops, "bounds")
82
+ };
83
+ }
84
+ var UNIT_BOX = { x: 0, y: 0, width: 1, height: 1 };
85
+ function twoStopRamp(color) {
86
+ const isWhite = color.slice(0, 7).toLowerCase() === "#ffffff";
87
+ return [{ offset: 0, color }, { offset: 1, color: isWhite ? "#000000ff" : "#ffffffff" }];
88
+ }
89
+ var KINDS = createReflectable();
90
+ var LAZY_BUILTINS = [
91
+ ["mesh-gradient", async () => (await import('./meshKindLazy.js')).meshGradientKind]
92
+ ];
93
+ function seed() {
94
+ for (const entry of BUILTINS) {
95
+ KINDS.push(entry.id, entry, { source: "kit" });
96
+ registerPaintDrawKind(entry);
97
+ }
98
+ for (const [id, load] of LAZY_BUILTINS) registerPaintKindLoader(id, load);
99
+ }
100
+ seed();
101
+ var paintKindRegistry = KINDS.reflection;
102
+ function registerPaintKind(entry) {
103
+ if (entry.stopsOf === void 0 !== (entry.fromStops === void 0)) {
104
+ const missing = entry.stopsOf === void 0 ? "stopsOf" : "fromStops";
105
+ throw new Error(
106
+ `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
+ );
108
+ }
109
+ const dropDraw = registerPaintDrawKind(entry);
110
+ const dropEntry = KINDS.push(entry.id, entry);
111
+ return () => {
112
+ dropEntry();
113
+ dropDraw();
114
+ };
115
+ }
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;
121
+ });
122
+ }
123
+ function getPaintKind(kind) {
124
+ const id = kind ?? "solid";
125
+ const entry = KINDS.get(id);
126
+ if (!entry) getPaintDrawKind(id);
127
+ return entry;
128
+ }
129
+ function derivedList(derive) {
130
+ let from;
131
+ let list = [];
132
+ return () => {
133
+ const entries = KINDS.entries();
134
+ if (entries !== from) {
135
+ from = entries;
136
+ list = Object.freeze(derive(entries));
137
+ }
138
+ return list;
139
+ };
140
+ }
141
+ function listPaintKinds() {
142
+ return allKinds();
143
+ }
144
+ var allKinds = derivedList((all) => all.map((e) => e.value));
145
+ function listGradientKinds() {
146
+ return gradientKinds();
147
+ }
148
+ var gradientKinds = derivedList(
149
+ (all) => all.map((e) => e.value).filter((entry) => entry.stopsOf && entry.fromStops)
150
+ );
151
+ function switchGradientKind(paint, kind) {
152
+ const from = paintKindOf(paint);
153
+ const to = getPaintKind(kind);
154
+ if (!from?.stopsOf || !to?.fromStops) return void 0;
155
+ if (from.id === to.id) return paint;
156
+ if (isGradientPaint(paint) && isGradientPaint({ kind })) {
157
+ return withGradientKind(paint, kind);
158
+ }
159
+ const { interpolate, opacity } = paint;
160
+ return {
161
+ ...to.fromStops(from.stopsOf(paint)),
162
+ ...interpolate !== void 0 ? { interpolate } : {},
163
+ ...opacity !== void 0 ? { opacity } : {}
164
+ };
165
+ }
166
+ function paintKindOf(fill) {
167
+ return getPaintKind(fill.kind ?? "solid");
168
+ }
169
+ function _reseedPaintKinds() {
170
+ KINDS.clear();
171
+ seed();
172
+ }
173
+
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
@@ -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,EAAA;IACE,EAAA,EAAI,OAAA;IACJ,KAAA,EAAO,OAAA;IACP,MAAA,EAAQ,aAAA;;AAER,IAAA,IAAA,EAAM,CAAC,KAAA,KAAU,QAAA,CAAS,OAAA,EAAS,KA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YAAA,CAAa,IAAA,CAAK,IAAA,IAAQ,OAAO,CAAA;AAC1C;AAIO,SAAS,iBAAA,GAA0B;AACxC,EAAA,KAAA,CAAM,KAAA,EAAM;AACZ,EAAA,IAAA,EAAK;AACP","file":"chunk-OZAYBSMO.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, withGradientKind } from '@weasel-js/paint';\nimport { createReflectable, type ReflectedEntry, type Reflection } from '@weasel-js/registry';\nimport { getPaintDrawKind, registerPaintDrawKind, registerPaintDrawKindLoader } 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\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) => (paint as Partial<GradientPaint>).stops?.[0]?.color,\n stopsOf: (paint) => (paint as GradientPaint).stops,\n fromStops: (stops) => gradientForBounds(id, UNIT_BOX, stops, 'bounds'),\n };\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 isWhite = color.slice(0, 7).toLowerCase() === '#ffffff';\n return [{ offset: 0, color }, { offset: 1, color: isWhite ? '#000000ff' : '#ffffffff' }];\n}\n\nconst KINDS = createReflectable<PaintKindEntry>();\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' });\n registerPaintDrawKind(entry);\n }\n for (const [id, load] of LAZY_BUILTINS) registerPaintKindLoader(id, load);\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. */\nexport function registerPaintKind(entry: PaintKindEntry): () => 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);\n const dropEntry = KINDS.push(entry.id, entry);\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. Returns a\n * disposer that removes the loader.\n */\nexport function registerPaintKindLoader(id: string, load: PaintKindLoader): () => void {\n return registerPaintDrawKindLoader(id, async () => {\n const entry = await load();\n if (entry.id === id && !KINDS.has(id)) registerPaintKind(entry);\n return entry;\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) getPaintDrawKind(id);\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 stop gradients this is `withGradientKind`, which carries\n * the geometry. Any other pair goes through the stop list — `stopsOf` on the\n * way out, `fromStops` on the way in — keeping `interpolate` and `opacity`.\n * Lossy wherever the kinds hold different information.\n */\nexport function switchGradientKind(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 (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(fill: Paint): PaintKindEntry | undefined {\n return getPaintKind(fill.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"]}
@@ -0,0 +1,25 @@
1
+ import { meshDrawKind, meshGradientXml, meshFromStops, meshStops, seedMeshPatch } from '@weasel-js/renderer/mesh';
2
+
3
+ // src/meshKind.ts
4
+ var asMesh = (fill) => fill;
5
+ var asFill = (mesh) => mesh;
6
+ var meshGradientKind = {
7
+ ...meshDrawKind,
8
+ label: "Mesh",
9
+ // Written as library mode emits `icon('mesh')`: the call would pull the icons package into meshKindLazy.
10
+ icon: (
11
+ /* @icon */
12
+ "paint-kinds:mesh"
13
+ ),
14
+ seed: (color) => asFill(seedMeshPatch(color)),
15
+ // The first corner of the first patch: a mesh has no single color, and this
16
+ // is the one a fallback swatch and an SVG paint fallback both read.
17
+ colorOf: (paint) => asMesh(paint).patches?.[0]?.colors?.[0],
18
+ stopsOf: (paint) => meshStops(asMesh(paint)),
19
+ fromStops: (stops) => asFill(meshFromStops(stops)),
20
+ toSvg: (id, fill) => meshGradientXml(id, asMesh(fill))
21
+ };
22
+
23
+ export { meshGradientKind };
24
+ //# sourceMappingURL=chunk-QJ5FJFNR.js.map
25
+ //# sourceMappingURL=chunk-QJ5FJFNR.js.map
@@ -0,0 +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"]}
@@ -0,0 +1,6 @@
1
+ import { IconTable } from '@weasel-js/icons';
2
+
3
+ /** Every glyph this package ships, under the `paint-kinds` namespace. */
4
+ declare const icons: IconTable;
5
+
6
+ export { icons };
@@ -0,0 +1,54 @@
1
+ // src/icons.table.json
2
+ var icons_table_default = {
3
+ namespace: "paint-kinds",
4
+ owner: "@weasel-js/paint-kinds",
5
+ icons: {
6
+ solid: {
7
+ body: '<path d="M3.4 3.4H16.6V16.6H3.4Z" fill="currentColor" stroke="none" fill-opacity="1"/>',
8
+ group: "Paint kinds",
9
+ tags: []
10
+ },
11
+ linear: {
12
+ body: '<path d="M3.4 3.4H6.7V16.6H3.4Z" fill="currentColor" stroke="none" fill-opacity="1"/><path d="M6.7 3.4H10V16.6H6.7Z" fill="currentColor" stroke="none" fill-opacity="0.68"/><path d="M10 3.4H13.3V16.6H10Z" fill="currentColor" stroke="none" fill-opacity="0.42"/><path d="M13.3 3.4H16.6V16.6H13.3Z" fill="currentColor" stroke="none" fill-opacity="0.2"/>',
13
+ group: "Paint kinds",
14
+ tags: []
15
+ },
16
+ radial: {
17
+ body: '<path d="M3.4 3.4H16.6V16.6H3.4ZM4.95 4.95H15.05V15.05H4.95Z" fill="currentColor" stroke="none" fill-rule="evenodd" fill-opacity="0.7"/><path d="M4.95 4.95H15.05V15.05H4.95ZM6.5 6.5H13.5V13.5H6.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" fill-opacity="0.53"/><path d="M6.5 6.5H13.5V13.5H6.5ZM8.05 8.05H11.95V11.95H8.05Z" fill="currentColor" stroke="none" fill-rule="evenodd" fill-opacity="0.37"/><path d="M8.05 8.05H11.95V11.95H8.05Z" fill="currentColor" stroke="none" fill-rule="evenodd" fill-opacity="0.2"/>',
18
+ group: "Paint kinds",
19
+ tags: []
20
+ },
21
+ conic: {
22
+ body: '<path d="M10 10L16.6 3.4L16.6 16.6Z" fill="currentColor" stroke="none" fill-opacity="1"/><path d="M10 10L16.6 16.6L3.4 16.6Z" fill="currentColor" stroke="none" fill-opacity="0.68"/><path d="M10 10L3.4 16.6L3.4 3.4Z" fill="currentColor" stroke="none" fill-opacity="0.42"/><path d="M10 10L3.4 3.4L16.6 3.4Z" fill="currentColor" stroke="none" fill-opacity="0.2"/>',
23
+ group: "Paint kinds",
24
+ tags: []
25
+ },
26
+ mesh: {
27
+ body: '<path d="M3.4 3.4L10 3.4C10 6.26 11.6 5.74 11.6 8.6C7.09 8.6 7.91 10 3.4 10L3.4 3.4Z" fill="currentColor" stroke="none" fill-opacity="1"/><path d="M10 3.4L16.6 3.4L16.6 10C13.85 10 14.35 8.6 11.6 8.6C11.6 5.74 10 6.26 10 3.4Z" fill="currentColor" stroke="none" fill-opacity="0.68"/><path d="M11.6 8.6C14.35 8.6 13.85 10 16.6 10L16.6 16.6L10 16.6C10 12.2 11.6 13 11.6 8.6Z" fill="currentColor" stroke="none" fill-opacity="0.42"/><path d="M11.6 8.6C11.6 13 10 12.2 10 16.6L3.4 16.6L3.4 10C7.91 10 7.09 8.6 11.6 8.6Z" fill="currentColor" stroke="none" fill-opacity="0.2"/>',
28
+ group: "Paint kinds",
29
+ tags: []
30
+ },
31
+ pattern: {
32
+ body: '<path d="M3.4 3.4L4.7 3.4L3.4 4.7Z" fill="currentColor" stroke="none"/><path d="M8.7 3.4L11.3 3.4L3.4 11.3L3.4 8.7Z" fill="currentColor" stroke="none"/><path d="M15.3 3.4L16.6 3.4L16.6 4.7L4.7 16.6L3.4 16.6L3.4 15.3Z" fill="currentColor" stroke="none"/><path d="M16.6 8.7L16.6 11.3L11.3 16.6L8.7 16.6Z" fill="currentColor" stroke="none"/><path d="M16.6 15.3L16.6 16.6L15.3 16.6Z" fill="currentColor" stroke="none"/><path d="M15.3 3.4L16.6 3.4L16.6 4.7Z" fill="currentColor" stroke="none"/><path d="M8.7 3.4L11.3 3.4L16.6 8.7L16.6 11.3Z" fill="currentColor" stroke="none"/><path d="M3.4 3.4L4.7 3.4L16.6 15.3L16.6 16.6L15.3 16.6L3.4 4.7Z" fill="currentColor" stroke="none"/><path d="M11.3 16.6L8.7 16.6L3.4 11.3L3.4 8.7Z" fill="currentColor" stroke="none"/><path d="M4.7 16.6L3.4 16.6L3.4 15.3Z" fill="currentColor" stroke="none"/>',
33
+ group: "Paint kinds",
34
+ tags: []
35
+ },
36
+ inherit: {
37
+ body: '<path d="M2.8571 2.8571H8.5714V8.5714H2.8571Z" fill="currentColor" stroke="none"/><path d="M5 8.5714V13.5714H10.7143"/><path d="M10.7143 10.7143H16.4286V16.4286H10.7143Z" stroke-linejoin="miter"/>',
38
+ group: "Paint kinds",
39
+ tags: []
40
+ },
41
+ none: {
42
+ body: '<path d="M3.4 3.4H16.6V16.6H3.4Z"/><path d="M3.4 16.6L16.6 3.4" stroke="var(--wzl-danger, #d94a3f)" stroke-width="1.8" stroke-linecap="butt"/>',
43
+ group: "Paint kinds",
44
+ tags: []
45
+ }
46
+ }
47
+ };
48
+
49
+ // src/icons.table.ts
50
+ var icons = icons_table_default;
51
+
52
+ export { icons };
53
+ //# sourceMappingURL=icons.table.js.map
54
+ //# sourceMappingURL=icons.table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/icons.table.json","../src/icons.table.ts"],"names":[],"mappings":";AAAA,IAAA,mBAAA,GAAA;AAAA,EACE,SAAA,EAAa,aAAA;AAAA,EACb,KAAA,EAAS,wBAAA;AAAA,EACT,KAAA,EAAS;AAAA,IACP,KAAA,EAAS;AAAA,MACP,IAAA,EAAQ,wFAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,MAAA,EAAU;AAAA,MACR,IAAA,EAAQ,+VAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,MAAA,EAAU;AAAA,MACR,IAAA,EAAQ,6gBAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,KAAA,EAAS;AAAA,MACP,IAAA,EAAQ,0WAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,IAAA,EAAQ;AAAA,MACN,IAAA,EAAQ,2jBAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,OAAA,EAAW;AAAA,MACT,IAAA,EAAQ,g0BAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,OAAA,EAAW;AAAA,MACT,IAAA,EAAQ,sMAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC,KACX;AAAA,IACA,IAAA,EAAQ;AAAA,MACN,IAAA,EAAQ,gJAAA;AAAA,MACR,KAAA,EAAS,aAAA;AAAA,MACT,MAAQ;AAAC;AACX;AAEJ,CAAA;;;ACvCO,IAAM,KAAA,GAAmB","file":"icons.table.js","sourcesContent":["{\n \"namespace\": \"paint-kinds\",\n \"owner\": \"@weasel-js/paint-kinds\",\n \"icons\": {\n \"solid\": {\n \"body\": \"<path d=\\\"M3.4 3.4H16.6V16.6H3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"1\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"linear\": {\n \"body\": \"<path d=\\\"M3.4 3.4H6.7V16.6H3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"1\\\"/><path d=\\\"M6.7 3.4H10V16.6H6.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.68\\\"/><path d=\\\"M10 3.4H13.3V16.6H10Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.42\\\"/><path d=\\\"M13.3 3.4H16.6V16.6H13.3Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.2\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"radial\": {\n \"body\": \"<path d=\\\"M3.4 3.4H16.6V16.6H3.4ZM4.95 4.95H15.05V15.05H4.95Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-rule=\\\"evenodd\\\" fill-opacity=\\\"0.7\\\"/><path d=\\\"M4.95 4.95H15.05V15.05H4.95ZM6.5 6.5H13.5V13.5H6.5Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-rule=\\\"evenodd\\\" fill-opacity=\\\"0.53\\\"/><path d=\\\"M6.5 6.5H13.5V13.5H6.5ZM8.05 8.05H11.95V11.95H8.05Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-rule=\\\"evenodd\\\" fill-opacity=\\\"0.37\\\"/><path d=\\\"M8.05 8.05H11.95V11.95H8.05Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-rule=\\\"evenodd\\\" fill-opacity=\\\"0.2\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"conic\": {\n \"body\": \"<path d=\\\"M10 10L16.6 3.4L16.6 16.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"1\\\"/><path d=\\\"M10 10L16.6 16.6L3.4 16.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.68\\\"/><path d=\\\"M10 10L3.4 16.6L3.4 3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.42\\\"/><path d=\\\"M10 10L3.4 3.4L16.6 3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.2\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"mesh\": {\n \"body\": \"<path d=\\\"M3.4 3.4L10 3.4C10 6.26 11.6 5.74 11.6 8.6C7.09 8.6 7.91 10 3.4 10L3.4 3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"1\\\"/><path d=\\\"M10 3.4L16.6 3.4L16.6 10C13.85 10 14.35 8.6 11.6 8.6C11.6 5.74 10 6.26 10 3.4Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.68\\\"/><path d=\\\"M11.6 8.6C14.35 8.6 13.85 10 16.6 10L16.6 16.6L10 16.6C10 12.2 11.6 13 11.6 8.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.42\\\"/><path d=\\\"M11.6 8.6C11.6 13 10 12.2 10 16.6L3.4 16.6L3.4 10C7.91 10 7.09 8.6 11.6 8.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\" fill-opacity=\\\"0.2\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"pattern\": {\n \"body\": \"<path d=\\\"M3.4 3.4L4.7 3.4L3.4 4.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M8.7 3.4L11.3 3.4L3.4 11.3L3.4 8.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M15.3 3.4L16.6 3.4L16.6 4.7L4.7 16.6L3.4 16.6L3.4 15.3Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M16.6 8.7L16.6 11.3L11.3 16.6L8.7 16.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M16.6 15.3L16.6 16.6L15.3 16.6Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M15.3 3.4L16.6 3.4L16.6 4.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M8.7 3.4L11.3 3.4L16.6 8.7L16.6 11.3Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M3.4 3.4L4.7 3.4L16.6 15.3L16.6 16.6L15.3 16.6L3.4 4.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M11.3 16.6L8.7 16.6L3.4 11.3L3.4 8.7Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M4.7 16.6L3.4 16.6L3.4 15.3Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"inherit\": {\n \"body\": \"<path d=\\\"M2.8571 2.8571H8.5714V8.5714H2.8571Z\\\" fill=\\\"currentColor\\\" stroke=\\\"none\\\"/><path d=\\\"M5 8.5714V13.5714H10.7143\\\"/><path d=\\\"M10.7143 10.7143H16.4286V16.4286H10.7143Z\\\" stroke-linejoin=\\\"miter\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n },\n \"none\": {\n \"body\": \"<path d=\\\"M3.4 3.4H16.6V16.6H3.4Z\\\"/><path d=\\\"M3.4 16.6L16.6 3.4\\\" stroke=\\\"var(--wzl-danger, #d94a3f)\\\" stroke-width=\\\"1.8\\\" stroke-linecap=\\\"butt\\\"/>\",\n \"group\": \"Paint kinds\",\n \"tags\": []\n }\n }\n}\n","// GENERATED by packages/icons/scripts/gen-icons.mjs — do not edit by hand.\n\nimport type { IconTable } from '@weasel-js/icons';\nimport data from './icons.table.json';\n\n/** Every glyph this package ships, under the `paint-kinds` namespace. */\nexport const icons: IconTable = data;\n"]}
@@ -0,0 +1,46 @@
1
+ {
2
+ "namespace": "paint-kinds",
3
+ "owner": "@weasel-js/paint-kinds",
4
+ "icons": {
5
+ "solid": {
6
+ "body": "<path d=\"M3.4 3.4H16.6V16.6H3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"1\"/>",
7
+ "group": "Paint kinds",
8
+ "tags": []
9
+ },
10
+ "linear": {
11
+ "body": "<path d=\"M3.4 3.4H6.7V16.6H3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"1\"/><path d=\"M6.7 3.4H10V16.6H6.7Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.68\"/><path d=\"M10 3.4H13.3V16.6H10Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.42\"/><path d=\"M13.3 3.4H16.6V16.6H13.3Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.2\"/>",
12
+ "group": "Paint kinds",
13
+ "tags": []
14
+ },
15
+ "radial": {
16
+ "body": "<path d=\"M3.4 3.4H16.6V16.6H3.4ZM4.95 4.95H15.05V15.05H4.95Z\" fill=\"currentColor\" stroke=\"none\" fill-rule=\"evenodd\" fill-opacity=\"0.7\"/><path d=\"M4.95 4.95H15.05V15.05H4.95ZM6.5 6.5H13.5V13.5H6.5Z\" fill=\"currentColor\" stroke=\"none\" fill-rule=\"evenodd\" fill-opacity=\"0.53\"/><path d=\"M6.5 6.5H13.5V13.5H6.5ZM8.05 8.05H11.95V11.95H8.05Z\" fill=\"currentColor\" stroke=\"none\" fill-rule=\"evenodd\" fill-opacity=\"0.37\"/><path d=\"M8.05 8.05H11.95V11.95H8.05Z\" fill=\"currentColor\" stroke=\"none\" fill-rule=\"evenodd\" fill-opacity=\"0.2\"/>",
17
+ "group": "Paint kinds",
18
+ "tags": []
19
+ },
20
+ "conic": {
21
+ "body": "<path d=\"M10 10L16.6 3.4L16.6 16.6Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"1\"/><path d=\"M10 10L16.6 16.6L3.4 16.6Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.68\"/><path d=\"M10 10L3.4 16.6L3.4 3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.42\"/><path d=\"M10 10L3.4 3.4L16.6 3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.2\"/>",
22
+ "group": "Paint kinds",
23
+ "tags": []
24
+ },
25
+ "mesh": {
26
+ "body": "<path d=\"M3.4 3.4L10 3.4C10 6.26 11.6 5.74 11.6 8.6C7.09 8.6 7.91 10 3.4 10L3.4 3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"1\"/><path d=\"M10 3.4L16.6 3.4L16.6 10C13.85 10 14.35 8.6 11.6 8.6C11.6 5.74 10 6.26 10 3.4Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.68\"/><path d=\"M11.6 8.6C14.35 8.6 13.85 10 16.6 10L16.6 16.6L10 16.6C10 12.2 11.6 13 11.6 8.6Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.42\"/><path d=\"M11.6 8.6C11.6 13 10 12.2 10 16.6L3.4 16.6L3.4 10C7.91 10 7.09 8.6 11.6 8.6Z\" fill=\"currentColor\" stroke=\"none\" fill-opacity=\"0.2\"/>",
27
+ "group": "Paint kinds",
28
+ "tags": []
29
+ },
30
+ "pattern": {
31
+ "body": "<path d=\"M3.4 3.4L4.7 3.4L3.4 4.7Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M8.7 3.4L11.3 3.4L3.4 11.3L3.4 8.7Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M15.3 3.4L16.6 3.4L16.6 4.7L4.7 16.6L3.4 16.6L3.4 15.3Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M16.6 8.7L16.6 11.3L11.3 16.6L8.7 16.6Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M16.6 15.3L16.6 16.6L15.3 16.6Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M15.3 3.4L16.6 3.4L16.6 4.7Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M8.7 3.4L11.3 3.4L16.6 8.7L16.6 11.3Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M3.4 3.4L4.7 3.4L16.6 15.3L16.6 16.6L15.3 16.6L3.4 4.7Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M11.3 16.6L8.7 16.6L3.4 11.3L3.4 8.7Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M4.7 16.6L3.4 16.6L3.4 15.3Z\" fill=\"currentColor\" stroke=\"none\"/>",
32
+ "group": "Paint kinds",
33
+ "tags": []
34
+ },
35
+ "inherit": {
36
+ "body": "<path d=\"M2.8571 2.8571H8.5714V8.5714H2.8571Z\" fill=\"currentColor\" stroke=\"none\"/><path d=\"M5 8.5714V13.5714H10.7143\"/><path d=\"M10.7143 10.7143H16.4286V16.4286H10.7143Z\" stroke-linejoin=\"miter\"/>",
37
+ "group": "Paint kinds",
38
+ "tags": []
39
+ },
40
+ "none": {
41
+ "body": "<path d=\"M3.4 3.4H16.6V16.6H3.4Z\"/><path d=\"M3.4 16.6L16.6 3.4\" stroke=\"var(--wzl-danger, #d94a3f)\" stroke-width=\"1.8\" stroke-linecap=\"butt\"/>",
42
+ "group": "Paint kinds",
43
+ "tags": []
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,105 @@
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';
5
+ import { TileShape } from '@weasel-js/renderer/patterns-builtin';
6
+ import 'react';
7
+ import '@weasel-js/icons';
8
+ import '@weasel-js/renderer';
9
+
10
+ /**
11
+ * The paint-kind registry — what makes `Paint` open. The built-in kinds
12
+ * are registered here at module load so an editor's kind bar can enumerate
13
+ * every kind through one list.
14
+ *
15
+ * Every entry is also handed to the renderer's own registry, which reads only
16
+ * its draw slots. A built-in kind has none: its render slot is a branch in the
17
+ * GL renderer and its serialize slot lives in `@weasel-js/svg`.
18
+ */
19
+
20
+ /** The family the built-in tiles, `image` and `texture` are offered under. A consumer's
21
+ * own pattern kind joins it by naming this as its `family`. */
22
+ declare const patternFamily: PaintKindFamily;
23
+ /** A tile paint seeded from a color. `units: 'bounds'` anchors the tile to the
24
+ * node's box, so the texture travels with the shape. */
25
+ declare function seedTile(kind: TileKind, color: string): TilePaint;
26
+ /** Resolves with the entry for a kind that is loaded on first use. */
27
+ type PaintKindLoader = () => Promise<PaintKindEntry>;
28
+ /** Every registered paint kind, with the overrides each displaced. */
29
+ declare const paintKindRegistry: Reflection<PaintKindEntry>;
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;
33
+ /**
34
+ * Declare a paint kind that is loaded the first time something looks it up,
35
+ * so its code stays out of the bundle until a paint of it appears — typically
36
+ * `() => import('./myKind').then((m) => m.myKindEntry)`.
37
+ *
38
+ * Until it lands the kind is unregistered: the renderer draws nothing for its
39
+ * paints, and every other reader treats it as unknown. Registering it fires
40
+ * `paintKindRegistry`'s subscribers. Call `warmPaintKinds` to load ahead of
41
+ * the first frame instead.
42
+ *
43
+ * A kind that is already registered never calls its loader. Returns a
44
+ * disposer that removes the loader.
45
+ */
46
+ declare function registerPaintKindLoader(id: string, load: PaintKindLoader): () => void;
47
+ /** The entry for `kind`, or `undefined`. A lookup that misses on a kind with
48
+ * a loader starts that load; see {@link registerPaintKindLoader}. */
49
+ declare function getPaintKind(kind: string | undefined): PaintKindEntry | undefined;
50
+ /** Every registered kind, built-ins first, in registration order. The same
51
+ * array until the registry changes. */
52
+ declare function listPaintKinds(): readonly PaintKindEntry[];
53
+ /** Every registered gradient kind — the ones that read as and build from a
54
+ * stop list — in registration order. The same array until the registry
55
+ * changes. */
56
+ declare function listGradientKinds(): readonly PaintKindEntry[];
57
+ /**
58
+ * `paint` retargeted to gradient kind `kind`, or `undefined` when either side
59
+ * is not a gradient kind.
60
+ *
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`.
64
+ * Lossy wherever the kinds hold different information.
65
+ */
66
+ declare function switchGradientKind(paint: Paint, kind: PaintKind): Paint | undefined;
67
+ /** The registry entry for a paint, or `undefined` when its kind is unknown. */
68
+ declare function paintKindOf(fill: Paint): PaintKindEntry | undefined;
69
+
70
+ /** A glyph this package draws, by its bare name. */
71
+ type PaintKindsIconName = 'solid' | 'linear' | 'radial' | 'conic' | 'mesh' | 'pattern' | 'inherit' | 'none';
72
+ declare module '@weasel-js/icons' {
73
+ interface IconName {
74
+ 'paint-kinds:solid': true;
75
+ 'paint-kinds:linear': true;
76
+ 'paint-kinds:radial': true;
77
+ 'paint-kinds:conic': true;
78
+ 'paint-kinds:mesh': true;
79
+ 'paint-kinds:pattern': true;
80
+ 'paint-kinds:inherit': true;
81
+ 'paint-kinds:none': true;
82
+ }
83
+ }
84
+
85
+ /** 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. */
88
+ declare function nativeSvgKind(kind: string): boolean;
89
+ /** Whether a gradient interpolating through `space` blends the same in every
90
+ * SVG renderer — only sRGB, the default. A perceptual space still exports,
91
+ * but renderers other than weasel blend it in sRGB. */
92
+ declare function nativeSvgSpace(space: string | null | undefined): boolean;
93
+
94
+ /** One shape of a tile as SVG markup: what a `<pattern>` holds, and a preview's body. */
95
+ declare function tileShapeXml(shape: TileShape): string;
96
+ /**
97
+ * A single tile as a standalone `<svg>` document, sized to its own extent,
98
+ * for UI that shows a tile outside a document, such as a picker swatch.
99
+ */
100
+ declare function tilePreviewSvg(spec: TilePatternSpec, background?: string): string;
101
+ /** `tilePreviewSvg` packed as a `url(...)` value for CSS `background-image`. */
102
+ declare function tilePreviewCssUrl(spec: TilePatternSpec, background?: string): string;
103
+
104
+ export { PaintKind, PaintKindEntry, PaintKindFamily, getPaintKind, listGradientKinds, listPaintKinds, nativeSvgKind, nativeSvgSpace, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, switchGradientKind, tilePreviewCssUrl, tilePreviewSvg, tileShapeXml };
105
+ export type { PaintKindLoader, PaintKindsIconName };
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ export { getPaintKind, listGradientKinds, listPaintKinds, paintKindOf, paintKindRegistry, patternFamily, registerPaintKind, registerPaintKindLoader, seedTile, switchGradientKind } from './chunk-OZAYBSMO.js';
2
+ import { isTileKind } from '@weasel-js/paint';
3
+ import { trimNumber, RAD_TO_DEG } from '@weasel-js/geom';
4
+ import { escapeAttr } from '@weasel-js/registry';
5
+ import { tileGeometry } from '@weasel-js/renderer/patterns-builtin';
6
+
7
+ // src/paintKindEntry.ts
8
+ function asPaint(paint) {
9
+ return paint;
10
+ }
11
+ function nativeSvgKind(kind) {
12
+ return kind === "solid" || kind === "linear-gradient" || kind === "radial-gradient" || kind === "texture" || kind === "image" || isTileKind(kind);
13
+ }
14
+ function nativeSvgSpace(space) {
15
+ return !space || space === "rgb";
16
+ }
17
+ function tileShapeXml(shape) {
18
+ switch (shape.kind) {
19
+ case "line":
20
+ return `<line x1="${trimNumber(shape.x1)}" y1="${trimNumber(shape.y1)}" x2="${trimNumber(shape.x2)}" y2="${trimNumber(shape.y2)}" stroke="${escapeAttr(shape.color)}" stroke-width="${trimNumber(shape.width)}"/>`;
21
+ case "circle":
22
+ return `<circle cx="${trimNumber(shape.cx)}" cy="${trimNumber(shape.cy)}" r="${trimNumber(shape.r)}" fill="${escapeAttr(shape.color)}"/>`;
23
+ case "ellipse": {
24
+ const deg = shape.rotation * RAD_TO_DEG;
25
+ const transform = deg === 0 ? "" : ` transform="rotate(${trimNumber(deg)} ${trimNumber(shape.cx)} ${trimNumber(shape.cy)})"`;
26
+ return `<ellipse cx="${trimNumber(shape.cx)}" cy="${trimNumber(shape.cy)}" rx="${trimNumber(shape.rx)}" ry="${trimNumber(shape.ry)}" fill="${escapeAttr(shape.color)}"${transform}/>`;
27
+ }
28
+ case "rect":
29
+ return `<rect x="${trimNumber(shape.x)}" y="${trimNumber(shape.y)}" width="${trimNumber(shape.width)}" height="${trimNumber(shape.height)}" fill="${escapeAttr(shape.color)}"/>`;
30
+ default:
31
+ return "";
32
+ }
33
+ }
34
+ function tilePreviewSvg(spec, background) {
35
+ const geometry = tileGeometry(spec);
36
+ const s = trimNumber(geometry.size);
37
+ const bg = background ? `<rect width="${s}" height="${s}" fill="${escapeAttr(background)}"/>` : "";
38
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${s}" height="${s}" viewBox="0 0 ${s} ${s}">${bg}${geometry.shapes.map(tileShapeXml).join("")}</svg>`;
39
+ }
40
+ function tilePreviewCssUrl(spec, background) {
41
+ return `url("data:image/svg+xml,${encodeURIComponent(tilePreviewSvg(spec, background))}")`;
42
+ }
43
+
44
+ export { asPaint, nativeSvgKind, nativeSvgSpace, tilePreviewCssUrl, tilePreviewSvg, tileShapeXml };
45
+ //# sourceMappingURL=index.js.map
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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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W,KAAA,CAAM,KAAK,CAAC,CAAA,CAAA,EAAI,SAAS,CAAA,EAAA,CAAA;AAAA,IACnD;AAAA,IACA,KAAK,MAAA;AACH,MAAA,OAAO,CAAA,SAAA,EAAY,UAAA,CAAW,KAAA,CAAM,CAAC,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"]}
package/dist/mesh.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { PaintKindEntry } from './index.js';
2
+ import 'react';
3
+ import '@weasel-js/icons';
4
+ import '@weasel-js/paint';
5
+ import '@weasel-js/renderer';
6
+
7
+ /** The `mesh-gradient` kind's registry entry. `./registerMesh` registers it;
8
+ * the paint-kind registry loads it on demand otherwise. */
9
+ declare const meshGradientKind: PaintKindEntry;
10
+
11
+ export { meshGradientKind };
package/dist/mesh.js ADDED
@@ -0,0 +1,8 @@
1
+ import { meshGradientKind } from './chunk-QJ5FJFNR.js';
2
+ export { meshGradientKind } from './chunk-QJ5FJFNR.js';
3
+ import { registerPaintKind } from './chunk-OZAYBSMO.js';
4
+
5
+ // src/mesh.ts
6
+ registerPaintKind(meshGradientKind);
7
+ //# sourceMappingURL=mesh.js.map
8
+ //# sourceMappingURL=mesh.js.map
@@ -0,0 +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"]}