@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 +1 -1
- package/dist/{chunk-OZAYBSMO.js → chunk-QOCBK67L.js} +32 -24
- package/dist/chunk-QOCBK67L.js.map +1 -0
- package/dist/{chunk-QJ5FJFNR.js → chunk-S6QTXVCH.js} +2 -2
- package/dist/{chunk-QJ5FJFNR.js.map → chunk-S6QTXVCH.js.map} +1 -1
- package/dist/index.d.ts +22 -16
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/mesh.d.ts +3 -2
- package/dist/mesh.js +4 -4
- package/dist/mesh.js.map +1 -1
- package/dist/meshKindLazy.d.ts +1 -1
- package/dist/meshKindLazy.js +305 -153
- package/dist/meshKindLazy.js.map +1 -1
- package/dist/{paintKindEntry-Ct0YJP8X.d.ts → paintKindEntry-Z83R9G-J.d.ts} +1 -1
- package/dist/react.js +1 -1
- package/dist/test-seams.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-OZAYBSMO.js.map +0 -1
|
@@ -55,7 +55,7 @@ interface PaintKindEntry extends PaintDrawKind {
|
|
|
55
55
|
/**
|
|
56
56
|
* The stop list this paint reads as. With `fromStops`, it is what makes a
|
|
57
57
|
* kind a gradient: `listGradientKinds` returns the kinds carrying both, and
|
|
58
|
-
* `
|
|
58
|
+
* `withPaintKind` converts between any two of them through the list.
|
|
59
59
|
*/
|
|
60
60
|
stopsOf?(paint: Paint): GradStop[];
|
|
61
61
|
/** A paint of this kind built from a stop list, in `bounds` units. The
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { paintKindRegistry, listPaintKinds, listGradientKinds, getPaintKind } from './chunk-
|
|
1
|
+
import { paintKindRegistry, listPaintKinds, listGradientKinds, getPaintKind } from './chunk-QOCBK67L.js';
|
|
2
2
|
import { useSyncExternalStore, useCallback } from 'react';
|
|
3
3
|
|
|
4
4
|
function usePaintKinds() {
|
package/dist/test-seams.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/paint-kinds",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "The registry of paint kinds a weasel paint can be: solid, the gradients, the tile patterns, image, texture, mesh and any a consumer registers, each with its label, glyph, seed color, editor and SVG output, and the renderer's draw slots.",
|
|
5
5
|
"weasel": {
|
|
6
6
|
"tier": "base"
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
"test": "node ../../scripts/package-test.mjs"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@weasel-js/geom": "
|
|
67
|
-
"@weasel-js/icons": "
|
|
68
|
-
"@weasel-js/paint": "
|
|
69
|
-
"@weasel-js/registry": "
|
|
70
|
-
"@weasel-js/renderer": "
|
|
66
|
+
"@weasel-js/geom": "2.0.0",
|
|
67
|
+
"@weasel-js/icons": "2.0.0",
|
|
68
|
+
"@weasel-js/paint": "2.0.0",
|
|
69
|
+
"@weasel-js/registry": "2.0.0",
|
|
70
|
+
"@weasel-js/renderer": "2.0.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"react": ">=18"
|
|
@@ -1 +0,0 @@
|
|
|
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,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AA,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,gBAAgB,KAAK,CAAA,IAAK,gBAAgB,EAAE,IAAA,EAAe,CAAA,EAAG;AAChE,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,IAAA,EAAyC;AACnE,EAAA,OAAO,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"]}
|