@pairdraw/scene-graph 0.19.2 → 0.20.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/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/variants.d.ts +12 -1
- package/dist/components/variants.d.ts.map +1 -1
- package/dist/components/variants.js +30 -1
- package/dist/components/variants.js.map +1 -1
- package/dist/constants.d.ts +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +94 -1
- package/dist/constants.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +17 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/text.d.ts +17 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +62 -1
- package/dist/css/text.js.map +1 -1
- package/dist/design-memory/index.d.ts +3 -0
- package/dist/design-memory/index.js +3 -0
- package/dist/design-memory/model.d.ts +33 -0
- package/dist/design-memory/model.d.ts.map +1 -0
- package/dist/design-memory/model.js +142 -0
- package/dist/design-memory/model.js.map +1 -0
- package/dist/design-memory/schema.d.ts +76 -0
- package/dist/design-memory/schema.d.ts.map +1 -0
- package/dist/design-memory/schema.js +72 -0
- package/dist/design-memory/schema.js.map +1 -0
- package/dist/effects.d.ts +7 -4
- package/dist/effects.d.ts.map +1 -1
- package/dist/effects.js +9 -4
- package/dist/effects.js.map +1 -1
- package/dist/empty-values.js +93 -0
- package/dist/empty-values.js.map +1 -0
- package/dist/fields/components.d.ts +9 -0
- package/dist/fields/components.d.ts.map +1 -0
- package/dist/fields/components.js +24 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/index.d.ts +3 -2
- package/dist/fields/index.js +3 -2
- package/dist/fields/layout.d.ts +3 -1
- package/dist/fields/layout.d.ts.map +1 -1
- package/dist/fields/layout.js +10 -1
- package/dist/fields/layout.js.map +1 -1
- package/dist/graph.d.ts +8 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +28 -5
- package/dist/graph.js.map +1 -1
- package/dist/grid-values.d.ts +10 -0
- package/dist/grid-values.d.ts.map +1 -0
- package/dist/grid-values.js +53 -0
- package/dist/grid-values.js.map +1 -0
- package/dist/hit-test/drop.d.ts +20 -0
- package/dist/hit-test/drop.d.ts.map +1 -0
- package/dist/hit-test/drop.js +54 -0
- package/dist/hit-test/drop.js.map +1 -0
- package/dist/hit-test/geometry.js +86 -0
- package/dist/hit-test/geometry.js.map +1 -0
- package/dist/hit-test/masks.d.ts +14 -0
- package/dist/hit-test/masks.d.ts.map +1 -0
- package/dist/hit-test/masks.js +41 -0
- package/dist/hit-test/masks.js.map +1 -0
- package/dist/hit-test/paint.d.ts +6 -0
- package/dist/hit-test/paint.d.ts.map +1 -0
- package/dist/hit-test/paint.js +19 -0
- package/dist/hit-test/paint.js.map +1 -0
- package/dist/hit-test.d.ts +4 -15
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +5 -173
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +2 -0
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +2 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +1 -1
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/source-walk.d.ts +12 -0
- package/dist/instances/source-walk.d.ts.map +1 -0
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +41 -36
- package/dist/node-defaults.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +75 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +18 -1
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +2 -0
- package/dist/preview.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +5 -1
- package/dist/scaling/node.js.map +1 -1
- package/dist/token-sources/document.d.ts +26 -0
- package/dist/token-sources/document.d.ts.map +1 -0
- package/dist/token-sources/document.js +80 -0
- package/dist/token-sources/document.js.map +1 -0
- package/dist/token-sources/index.d.ts +3 -0
- package/dist/token-sources/index.js +3 -0
- package/dist/token-sources/schema.d.ts +43 -0
- package/dist/token-sources/schema.d.ts.map +1 -0
- package/dist/token-sources/schema.js +50 -0
- package/dist/token-sources/schema.js.map +1 -0
- package/dist/types.d.ts +102 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variations/copy.d.ts +16 -0
- package/dist/variations/copy.d.ts.map +1 -0
- package/dist/variations/copy.js +78 -0
- package/dist/variations/copy.js.map +1 -0
- package/dist/variations/index.d.ts +6 -0
- package/dist/variations/index.js +6 -0
- package/dist/variations/match.d.ts +23 -0
- package/dist/variations/match.d.ts.map +1 -0
- package/dist/variations/match.js +80 -0
- package/dist/variations/match.js.map +1 -0
- package/dist/variations/model.d.ts +39 -0
- package/dist/variations/model.d.ts.map +1 -0
- package/dist/variations/model.js +90 -0
- package/dist/variations/model.js.map +1 -0
- package/dist/variations/pick.d.ts +43 -0
- package/dist/variations/pick.d.ts.map +1 -0
- package/dist/variations/pick.js +211 -0
- package/dist/variations/pick.js.map +1 -0
- package/dist/variations/schema.d.ts +27 -0
- package/dist/variations/schema.d.ts.map +1 -0
- package/dist/variations/schema.js +27 -0
- package/dist/variations/schema.js.map +1 -0
- package/package.json +21 -1
- package/src/components/variants.ts +39 -0
- package/src/constants.ts +75 -0
- package/src/copy.ts +20 -1
- package/src/css/index.ts +7 -1
- package/src/css/text.ts +62 -0
- package/src/design-memory/index.ts +2 -0
- package/src/design-memory/model.ts +143 -0
- package/src/design-memory/schema.ts +84 -0
- package/src/effects.ts +16 -7
- package/src/empty-values.ts +101 -0
- package/src/fields/components.ts +21 -0
- package/src/fields/index.ts +1 -0
- package/src/fields/layout.ts +10 -0
- package/src/graph.ts +37 -5
- package/src/grid-values.ts +47 -0
- package/src/hit-test/drop.ts +90 -0
- package/src/hit-test/geometry.ts +131 -0
- package/src/hit-test/masks.ts +57 -0
- package/src/hit-test/paint.ts +24 -0
- package/src/hit-test.ts +8 -277
- package/src/instances/fields.ts +2 -0
- package/src/instances/index.ts +1 -0
- package/src/node-defaults.ts +49 -39
- package/src/plugin-data/fields.ts +18 -1
- package/src/preview.ts +2 -0
- package/src/scaling/node.ts +7 -2
- package/src/token-sources/document.ts +104 -0
- package/src/token-sources/index.ts +2 -0
- package/src/token-sources/schema.ts +59 -0
- package/src/types.ts +115 -13
- package/src/variations/copy.ts +89 -0
- package/src/variations/index.ts +5 -0
- package/src/variations/match.ts +100 -0
- package/src/variations/model.ts +132 -0
- package/src/variations/pick.ts +293 -0
- package/src/variations/schema.ts +29 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { DesignDecisionAuthor, DesignMemory, DesignMemoryGroup } from "./schema.js";
|
|
3
|
+
//#region src/design-memory/model.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* A new memory: every group allows the document's own variables and styles. Off-system colors
|
|
6
|
+
* and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.
|
|
7
|
+
*/
|
|
8
|
+
declare function createDesignMemory(): DesignMemory;
|
|
9
|
+
/** The document's memory, or null when it has none or it is unreadable. */
|
|
10
|
+
declare function readDesignMemory(graph: SceneGraph): DesignMemory | null;
|
|
11
|
+
/**
|
|
12
|
+
* The document's memory, read once per state of its document node: an edit replaces the node's
|
|
13
|
+
* plugin data, so a check on every agent call parses nothing new.
|
|
14
|
+
*/
|
|
15
|
+
declare function cachedDesignMemory(graph: SceneGraph): DesignMemory | null;
|
|
16
|
+
/** Stores the memory on the document node as an undoable change; `null` removes it. */
|
|
17
|
+
declare function writeDesignMemory(graph: SceneGraph, memory: DesignMemory | null): void;
|
|
18
|
+
/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */
|
|
19
|
+
declare function normalizeDesignValue(group: DesignMemoryGroup, value: string | number): string | number | null;
|
|
20
|
+
/**
|
|
21
|
+
* The memory with `value` allowed in `group`, once; a value the group cannot read, or one past
|
|
22
|
+
* its limit, leaves it as it was.
|
|
23
|
+
*/
|
|
24
|
+
declare function allowDesignValue(memory: DesignMemory, group: DesignMemoryGroup, value: string | number): DesignMemory;
|
|
25
|
+
/** The memory with `value` no longer allowed in `group` by itself. */
|
|
26
|
+
declare function disallowDesignValue(memory: DesignMemory, group: DesignMemoryGroup, value: string | number): DesignMemory;
|
|
27
|
+
/** The memory with a decision added last; blank text or a full list leaves it as it was. */
|
|
28
|
+
declare function addDesignDecision(memory: DesignMemory, text: string, author: DesignDecisionAuthor): DesignMemory;
|
|
29
|
+
/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */
|
|
30
|
+
declare function pinDesignExample(memory: DesignMemory, nodeId: string): DesignMemory;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
33
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/design-memory/model.ts"],"mappings":";;;;;;;iBA2BgB,sBAAsB;;iBActB,iBAAiB,OAAO,aAAa;;;;;iBAarC,mBAAmB,OAAO,aAAa;;iBAUvC,kBAAkB,OAAO,YAAY,QAAQ;;iBAS7C,qBACd,OAAO,mBACP;;;;;iBAoBc,iBACd,QAAQ,cACR,OAAO,mBACP,yBACC;;iBASa,oBACd,QAAQ,cACR,OAAO,mBACP,yBACC;;iBASa,kBACd,QAAQ,cACR,cACA,QAAQ,uBACP;;iBAUa,iBAAiB,QAAQ,cAAc,iBAAiB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { randomHex } from "../random.js";
|
|
2
|
+
import { readPluginData, withPluginData } from "../plugin-data/field.js";
|
|
3
|
+
import { DESIGN_MEMORY_LIMITS } from "./schema.js";
|
|
4
|
+
import { PAIRDRAW_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
5
|
+
import { colorToHex, tryParseColor } from "../color/index.js";
|
|
6
|
+
//#region src/design-memory/model.ts
|
|
7
|
+
const { designMemory } = PAIRDRAW_PLUGIN_DATA;
|
|
8
|
+
const GROUP_LIMITS = {
|
|
9
|
+
colors: DESIGN_MEMORY_LIMITS.colors,
|
|
10
|
+
fonts: DESIGN_MEMORY_LIMITS.fonts,
|
|
11
|
+
fontSizes: DESIGN_MEMORY_LIMITS.numbers,
|
|
12
|
+
spacing: DESIGN_MEMORY_LIMITS.numbers,
|
|
13
|
+
radius: DESIGN_MEMORY_LIMITS.numbers
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A new memory: every group allows the document's own variables and styles. Off-system colors
|
|
17
|
+
* and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.
|
|
18
|
+
*/
|
|
19
|
+
function createDesignMemory() {
|
|
20
|
+
return {
|
|
21
|
+
version: 1,
|
|
22
|
+
colors: {
|
|
23
|
+
fromSystem: true,
|
|
24
|
+
values: [],
|
|
25
|
+
enforce: "refuse"
|
|
26
|
+
},
|
|
27
|
+
fonts: {
|
|
28
|
+
fromSystem: true,
|
|
29
|
+
values: [],
|
|
30
|
+
enforce: "refuse"
|
|
31
|
+
},
|
|
32
|
+
fontSizes: {
|
|
33
|
+
fromSystem: true,
|
|
34
|
+
values: [],
|
|
35
|
+
enforce: "warn"
|
|
36
|
+
},
|
|
37
|
+
spacing: {
|
|
38
|
+
fromSystem: true,
|
|
39
|
+
values: [],
|
|
40
|
+
enforce: "warn"
|
|
41
|
+
},
|
|
42
|
+
radius: {
|
|
43
|
+
fromSystem: true,
|
|
44
|
+
values: [],
|
|
45
|
+
enforce: "warn"
|
|
46
|
+
},
|
|
47
|
+
decisions: [],
|
|
48
|
+
examples: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** The document's memory, or null when it has none or it is unreadable. */
|
|
52
|
+
function readDesignMemory(graph) {
|
|
53
|
+
return readPluginData(graph.getNode(graph.rootId)?.pluginData, designMemory) ?? null;
|
|
54
|
+
}
|
|
55
|
+
const MEMORIES = /* @__PURE__ */ new WeakMap();
|
|
56
|
+
/**
|
|
57
|
+
* The document's memory, read once per state of its document node: an edit replaces the node's
|
|
58
|
+
* plugin data, so a check on every agent call parses nothing new.
|
|
59
|
+
*/
|
|
60
|
+
function cachedDesignMemory(graph) {
|
|
61
|
+
const entries = graph.getNode(graph.rootId)?.pluginData;
|
|
62
|
+
const known = MEMORIES.get(graph);
|
|
63
|
+
if (known && known.entries === entries) return known.memory;
|
|
64
|
+
const memory = readDesignMemory(graph);
|
|
65
|
+
MEMORIES.set(graph, {
|
|
66
|
+
entries,
|
|
67
|
+
memory
|
|
68
|
+
});
|
|
69
|
+
return memory;
|
|
70
|
+
}
|
|
71
|
+
/** Stores the memory on the document node as an undoable change; `null` removes it. */
|
|
72
|
+
function writeDesignMemory(graph, memory) {
|
|
73
|
+
const root = graph.getNode(graph.rootId);
|
|
74
|
+
if (!root) return;
|
|
75
|
+
graph.updateNode(root.id, { pluginData: withPluginData(root.pluginData, designMemory, memory ?? void 0) });
|
|
76
|
+
}
|
|
77
|
+
/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */
|
|
78
|
+
function normalizeDesignValue(group, value) {
|
|
79
|
+
if (group === "colors") {
|
|
80
|
+
const color = typeof value === "string" ? tryParseColor(value.trim()) : null;
|
|
81
|
+
return color ? colorToHex(color) : null;
|
|
82
|
+
}
|
|
83
|
+
if (group === "fonts") {
|
|
84
|
+
const family = typeof value === "string" ? value.trim() : "";
|
|
85
|
+
return family && family.length <= DESIGN_MEMORY_LIMITS.fontLength ? family : null;
|
|
86
|
+
}
|
|
87
|
+
const number = typeof value === "number" ? value : Number(value);
|
|
88
|
+
if (!Number.isFinite(number)) return null;
|
|
89
|
+
return number > 0 || number === 0 && group !== "fontSizes" ? number : null;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The memory with `value` allowed in `group`, once; a value the group cannot read, or one past
|
|
93
|
+
* its limit, leaves it as it was.
|
|
94
|
+
*/
|
|
95
|
+
function allowDesignValue(memory, group, value) {
|
|
96
|
+
const normalized = normalizeDesignValue(group, value);
|
|
97
|
+
const values = memory[group].values;
|
|
98
|
+
if (normalized === null || values.includes(normalized) || values.length >= GROUP_LIMITS[group]) return memory;
|
|
99
|
+
return {
|
|
100
|
+
...memory,
|
|
101
|
+
[group]: {
|
|
102
|
+
...memory[group],
|
|
103
|
+
values: [...values, normalized]
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** The memory with `value` no longer allowed in `group` by itself. */
|
|
108
|
+
function disallowDesignValue(memory, group, value) {
|
|
109
|
+
const values = memory[group].values;
|
|
110
|
+
return {
|
|
111
|
+
...memory,
|
|
112
|
+
[group]: {
|
|
113
|
+
...memory[group],
|
|
114
|
+
values: values.filter((item) => item !== value)
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** The memory with a decision added last; blank text or a full list leaves it as it was. */
|
|
119
|
+
function addDesignDecision(memory, text, author) {
|
|
120
|
+
const trimmed = text.trim().slice(0, DESIGN_MEMORY_LIMITS.decisionLength).trim();
|
|
121
|
+
if (!trimmed || memory.decisions.length >= DESIGN_MEMORY_LIMITS.decisions) return memory;
|
|
122
|
+
return {
|
|
123
|
+
...memory,
|
|
124
|
+
decisions: [...memory.decisions, {
|
|
125
|
+
id: randomHex(8),
|
|
126
|
+
text: trimmed,
|
|
127
|
+
author
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */
|
|
132
|
+
function pinDesignExample(memory, nodeId) {
|
|
133
|
+
if (memory.examples.some((example) => example.nodeId === nodeId) || memory.examples.length >= DESIGN_MEMORY_LIMITS.examples) return memory;
|
|
134
|
+
return {
|
|
135
|
+
...memory,
|
|
136
|
+
examples: [...memory.examples, { nodeId }]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//#endregion
|
|
140
|
+
export { addDesignDecision, allowDesignValue, cachedDesignMemory, createDesignMemory, disallowDesignValue, normalizeDesignValue, pinDesignExample, readDesignMemory, writeDesignMemory };
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/design-memory/model.ts"],"sourcesContent":["import { tryParseColor, colorToHex } from '../color'\nimport type { SceneGraph } from '../graph'\nimport { readPluginData, withPluginData } from '../plugin-data/field'\nimport { PAIRDRAW_PLUGIN_DATA } from '../plugin-data/fields'\nimport { randomHex } from '../random'\nimport type { PluginDataEntry } from '../types'\nimport {\n DESIGN_MEMORY_LIMITS,\n type DesignDecisionAuthor,\n type DesignMemory,\n type DesignMemoryGroup\n} from './schema'\n\nconst { designMemory } = PAIRDRAW_PLUGIN_DATA\n\nconst GROUP_LIMITS = {\n colors: DESIGN_MEMORY_LIMITS.colors,\n fonts: DESIGN_MEMORY_LIMITS.fonts,\n fontSizes: DESIGN_MEMORY_LIMITS.numbers,\n spacing: DESIGN_MEMORY_LIMITS.numbers,\n radius: DESIGN_MEMORY_LIMITS.numbers\n} as const satisfies Record<DesignMemoryGroup, number>\n\n/**\n * A new memory: every group allows the document's own variables and styles. Off-system colors\n * and fonts refuse an agent's edit; sizes, spacing and radii have real exceptions, so they warn.\n */\nexport function createDesignMemory(): DesignMemory {\n return {\n version: 1,\n colors: { fromSystem: true, values: [], enforce: 'refuse' },\n fonts: { fromSystem: true, values: [], enforce: 'refuse' },\n fontSizes: { fromSystem: true, values: [], enforce: 'warn' },\n spacing: { fromSystem: true, values: [], enforce: 'warn' },\n radius: { fromSystem: true, values: [], enforce: 'warn' },\n decisions: [],\n examples: []\n }\n}\n\n/** The document's memory, or null when it has none or it is unreadable. */\nexport function readDesignMemory(graph: SceneGraph): DesignMemory | null {\n return readPluginData(graph.getNode(graph.rootId)?.pluginData, designMemory) ?? null\n}\n\nconst MEMORIES = new WeakMap<\n SceneGraph,\n { entries: readonly PluginDataEntry[] | undefined; memory: DesignMemory | null }\n>()\n\n/**\n * The document's memory, read once per state of its document node: an edit replaces the node's\n * plugin data, so a check on every agent call parses nothing new.\n */\nexport function cachedDesignMemory(graph: SceneGraph): DesignMemory | null {\n const entries = graph.getNode(graph.rootId)?.pluginData\n const known = MEMORIES.get(graph)\n if (known && known.entries === entries) return known.memory\n const memory = readDesignMemory(graph)\n MEMORIES.set(graph, { entries, memory })\n return memory\n}\n\n/** Stores the memory on the document node as an undoable change; `null` removes it. */\nexport function writeDesignMemory(graph: SceneGraph, memory: DesignMemory | null): void {\n const root = graph.getNode(graph.rootId)\n if (!root) return\n graph.updateNode(root.id, {\n pluginData: withPluginData(root.pluginData, designMemory, memory ?? undefined)\n })\n}\n\n/** A value as a group keeps it, or null when it is not one: colors become `#RRGGBB`. */\nexport function normalizeDesignValue(\n group: DesignMemoryGroup,\n value: string | number\n): string | number | null {\n if (group === 'colors') {\n const color = typeof value === 'string' ? tryParseColor(value.trim()) : null\n return color ? colorToHex(color) : null\n }\n if (group === 'fonts') {\n const family = typeof value === 'string' ? value.trim() : ''\n return family && family.length <= DESIGN_MEMORY_LIMITS.fontLength ? family : null\n }\n const number = typeof value === 'number' ? value : Number(value)\n if (!Number.isFinite(number)) return null\n // A text has a size; spacing and radii may be zero.\n return number > 0 || (number === 0 && group !== 'fontSizes') ? number : null\n}\n\n/**\n * The memory with `value` allowed in `group`, once; a value the group cannot read, or one past\n * its limit, leaves it as it was.\n */\nexport function allowDesignValue(\n memory: DesignMemory,\n group: DesignMemoryGroup,\n value: string | number\n): DesignMemory {\n const normalized = normalizeDesignValue(group, value)\n const values: readonly (string | number)[] = memory[group].values\n if (normalized === null || values.includes(normalized) || values.length >= GROUP_LIMITS[group])\n return memory\n return { ...memory, [group]: { ...memory[group], values: [...values, normalized] } }\n}\n\n/** The memory with `value` no longer allowed in `group` by itself. */\nexport function disallowDesignValue(\n memory: DesignMemory,\n group: DesignMemoryGroup,\n value: string | number\n): DesignMemory {\n const values: readonly (string | number)[] = memory[group].values\n return {\n ...memory,\n [group]: { ...memory[group], values: values.filter((item) => item !== value) }\n }\n}\n\n/** The memory with a decision added last; blank text or a full list leaves it as it was. */\nexport function addDesignDecision(\n memory: DesignMemory,\n text: string,\n author: DesignDecisionAuthor\n): DesignMemory {\n const trimmed = text.trim().slice(0, DESIGN_MEMORY_LIMITS.decisionLength).trim()\n if (!trimmed || memory.decisions.length >= DESIGN_MEMORY_LIMITS.decisions) return memory\n return {\n ...memory,\n decisions: [...memory.decisions, { id: randomHex(8), text: trimmed, author }]\n }\n}\n\n/** The memory with a layer pinned as an example, once; a full list leaves it as it was. */\nexport function pinDesignExample(memory: DesignMemory, nodeId: string): DesignMemory {\n if (\n memory.examples.some((example) => example.nodeId === nodeId) ||\n memory.examples.length >= DESIGN_MEMORY_LIMITS.examples\n )\n return memory\n return { ...memory, examples: [...memory.examples, { nodeId }] }\n}\n"],"mappings":";;;;;;AAaA,MAAM,EAAE,iBAAiB;AAEzB,MAAM,eAAe;CACnB,QAAQ,qBAAqB;CAC7B,OAAO,qBAAqB;CAC5B,WAAW,qBAAqB;CAChC,SAAS,qBAAqB;CAC9B,QAAQ,qBAAqB;AAC/B;;;;;AAMA,SAAgB,qBAAmC;CACjD,OAAO;EACL,SAAS;EACT,QAAQ;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAS;EAC1D,OAAO;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAS;EACzD,WAAW;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EAC3D,SAAS;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EACzD,QAAQ;GAAE,YAAY;GAAM,QAAQ,CAAC;GAAG,SAAS;EAAO;EACxD,WAAW,CAAC;EACZ,UAAU,CAAC;CACb;AACF;;AAGA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,eAAe,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE,YAAY,YAAY,KAAK;AAClF;AAEA,MAAM,2BAAW,IAAI,QAGnB;;;;;AAMF,SAAgB,mBAAmB,OAAwC;CACzE,MAAM,UAAU,MAAM,QAAQ,MAAM,MAAM,CAAC,EAAE;CAC7C,MAAM,QAAQ,SAAS,IAAI,KAAK;CAChC,IAAI,SAAS,MAAM,YAAY,SAAS,OAAO,MAAM;CACrD,MAAM,SAAS,iBAAiB,KAAK;CACrC,SAAS,IAAI,OAAO;EAAE;EAAS;CAAO,CAAC;CACvC,OAAO;AACT;;AAGA,SAAgB,kBAAkB,OAAmB,QAAmC;CACtF,MAAM,OAAO,MAAM,QAAQ,MAAM,MAAM;CACvC,IAAI,CAAC,MAAM;CACX,MAAM,WAAW,KAAK,IAAI,EACxB,YAAY,eAAe,KAAK,YAAY,cAAc,UAAU,KAAA,CAAS,EAC/E,CAAC;AACH;;AAGA,SAAgB,qBACd,OACA,OACwB;CACxB,IAAI,UAAU,UAAU;EACtB,MAAM,QAAQ,OAAO,UAAU,WAAW,cAAc,MAAM,KAAK,CAAC,IAAI;EACxE,OAAO,QAAQ,WAAW,KAAK,IAAI;CACrC;CACA,IAAI,UAAU,SAAS;EACrB,MAAM,SAAS,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;EAC1D,OAAO,UAAU,OAAO,UAAU,qBAAqB,aAAa,SAAS;CAC/E;CACA,MAAM,SAAS,OAAO,UAAU,WAAW,QAAQ,OAAO,KAAK;CAC/D,IAAI,CAAC,OAAO,SAAS,MAAM,GAAG,OAAO;CAErC,OAAO,SAAS,KAAM,WAAW,KAAK,UAAU,cAAe,SAAS;AAC1E;;;;;AAMA,SAAgB,iBACd,QACA,OACA,OACc;CACd,MAAM,aAAa,qBAAqB,OAAO,KAAK;CACpD,MAAM,SAAuC,OAAO,MAAM,CAAC;CAC3D,IAAI,eAAe,QAAQ,OAAO,SAAS,UAAU,KAAK,OAAO,UAAU,aAAa,QACtF,OAAO;CACT,OAAO;EAAE,GAAG;GAAS,QAAQ;GAAE,GAAG,OAAO;GAAQ,QAAQ,CAAC,GAAG,QAAQ,UAAU;EAAE;CAAE;AACrF;;AAGA,SAAgB,oBACd,QACA,OACA,OACc;CACd,MAAM,SAAuC,OAAO,MAAM,CAAC;CAC3D,OAAO;EACL,GAAG;GACF,QAAQ;GAAE,GAAG,OAAO;GAAQ,QAAQ,OAAO,QAAQ,SAAS,SAAS,KAAK;EAAE;CAC/E;AACF;;AAGA,SAAgB,kBACd,QACA,MACA,QACc;CACd,MAAM,UAAU,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,qBAAqB,cAAc,CAAC,CAAC,KAAK;CAC/E,IAAI,CAAC,WAAW,OAAO,UAAU,UAAU,qBAAqB,WAAW,OAAO;CAClF,OAAO;EACL,GAAG;EACH,WAAW,CAAC,GAAG,OAAO,WAAW;GAAE,IAAI,UAAU,CAAC;GAAG,MAAM;GAAS;EAAO,CAAC;CAC9E;AACF;;AAGA,SAAgB,iBAAiB,QAAsB,QAA8B;CACnF,IACE,OAAO,SAAS,MAAM,YAAY,QAAQ,WAAW,MAAM,KAC3D,OAAO,SAAS,UAAU,qBAAqB,UAE/C,OAAO;CACT,OAAO;EAAE,GAAG;EAAQ,UAAU,CAAC,GAAG,OAAO,UAAU,EAAE,OAAO,CAAC;CAAE;AACjE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/design-memory/schema.d.ts
|
|
3
|
+
/** How many values, decisions and examples one document's memory keeps. */
|
|
4
|
+
declare const DESIGN_MEMORY_LIMITS: {
|
|
5
|
+
readonly colors: 128;
|
|
6
|
+
readonly fonts: 16;
|
|
7
|
+
readonly numbers: 32;
|
|
8
|
+
readonly decisions: 40;
|
|
9
|
+
readonly decisionLength: 400;
|
|
10
|
+
readonly examples: 12;
|
|
11
|
+
readonly fontLength: 100;
|
|
12
|
+
};
|
|
13
|
+
/** The kinds of value a memory allows, each with its own list and enforcement. */
|
|
14
|
+
declare const DESIGN_MEMORY_GROUPS: readonly ["colors", "fonts", "fontSizes", "spacing", "radius"];
|
|
15
|
+
type DesignMemoryGroup = (typeof DESIGN_MEMORY_GROUPS)[number];
|
|
16
|
+
/**
|
|
17
|
+
* What happens to an agent's edit that uses a value the memory does not allow: it is undone and
|
|
18
|
+
* the agent told the allowed values, it goes through with a warning, or nothing is checked.
|
|
19
|
+
* People's own edits are never refused; lint lists them.
|
|
20
|
+
*/
|
|
21
|
+
declare const DESIGN_MEMORY_ENFORCEMENTS: readonly ["refuse", "warn", "off"];
|
|
22
|
+
type DesignMemoryEnforcement = (typeof DESIGN_MEMORY_ENFORCEMENTS)[number];
|
|
23
|
+
declare const DESIGN_DECISION_AUTHORS: readonly ["person", "agent"];
|
|
24
|
+
type DesignDecisionAuthor = (typeof DESIGN_DECISION_AUTHORS)[number];
|
|
25
|
+
/**
|
|
26
|
+
* A document's design rules for agents: the values its designs may use, decisions written down
|
|
27
|
+
* about them, and frames pinned as examples to follow.
|
|
28
|
+
*/
|
|
29
|
+
declare const designMemorySchema: v.ObjectSchema<{
|
|
30
|
+
readonly version: v.LiteralSchema<1, undefined>;
|
|
31
|
+
readonly colors: v.ObjectSchema<{
|
|
32
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
33
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, string>, undefined>, v.MaxLengthAction<string[], number, undefined>]>;
|
|
34
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
35
|
+
}, undefined>;
|
|
36
|
+
readonly fonts: v.ObjectSchema<{
|
|
37
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
38
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, string>, undefined>, v.MaxLengthAction<string[], number, undefined>]>;
|
|
39
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
readonly fontSizes: v.ObjectSchema<{
|
|
42
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
43
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
44
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
45
|
+
}, undefined>;
|
|
46
|
+
readonly spacing: v.ObjectSchema<{
|
|
47
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
48
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
49
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
50
|
+
}, undefined>;
|
|
51
|
+
readonly radius: v.ObjectSchema<{
|
|
52
|
+
readonly fromSystem: v.BooleanSchema<undefined>;
|
|
53
|
+
readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<unknown, number>, undefined>, v.MaxLengthAction<number[], number, undefined>]>;
|
|
54
|
+
readonly enforce: v.PicklistSchema<readonly ["refuse", "warn", "off"], undefined>;
|
|
55
|
+
}, undefined>;
|
|
56
|
+
readonly decisions: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
57
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
58
|
+
readonly text: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.NonEmptyAction<string, undefined>, v.MaxLengthAction<string, 400, undefined>]>;
|
|
59
|
+
readonly author: v.PicklistSchema<readonly ["person", "agent"], undefined>;
|
|
60
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
61
|
+
id: string;
|
|
62
|
+
text: string;
|
|
63
|
+
author: "person" | "agent";
|
|
64
|
+
}[], 40, undefined>]>;
|
|
65
|
+
readonly examples: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
66
|
+
readonly nodeId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
|
|
67
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
68
|
+
nodeId: string;
|
|
69
|
+
}[], 12, undefined>]>;
|
|
70
|
+
}, undefined>;
|
|
71
|
+
type DesignMemory = v.InferOutput<typeof designMemorySchema>;
|
|
72
|
+
type DesignDecision = DesignMemory['decisions'][number];
|
|
73
|
+
type DesignExample = DesignMemory['examples'][number];
|
|
74
|
+
//#endregion
|
|
75
|
+
export { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, DesignDecision, DesignDecisionAuthor, DesignExample, DesignMemory, DesignMemoryEnforcement, DesignMemoryGroup, designMemorySchema };
|
|
76
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/design-memory/schema.ts"],"mappings":";;;cAGa;;;;;;;;;;cAWA;KACD,4BAA4B;;;;;;cAO3B;KACD,kCAAkC;cAEjC;KACD,+BAA+B;;;;;cA4C9B,oBAAkB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAWnB,eAAe,EAAE,mBAAmB;KACpC,iBAAiB;KACjB,gBAAgB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/design-memory/schema.ts
|
|
3
|
+
/** How many values, decisions and examples one document's memory keeps. */
|
|
4
|
+
const DESIGN_MEMORY_LIMITS = {
|
|
5
|
+
colors: 128,
|
|
6
|
+
fonts: 16,
|
|
7
|
+
numbers: 32,
|
|
8
|
+
decisions: 40,
|
|
9
|
+
decisionLength: 400,
|
|
10
|
+
examples: 12,
|
|
11
|
+
fontLength: 100
|
|
12
|
+
};
|
|
13
|
+
/** The kinds of value a memory allows, each with its own list and enforcement. */
|
|
14
|
+
const DESIGN_MEMORY_GROUPS = [
|
|
15
|
+
"colors",
|
|
16
|
+
"fonts",
|
|
17
|
+
"fontSizes",
|
|
18
|
+
"spacing",
|
|
19
|
+
"radius"
|
|
20
|
+
];
|
|
21
|
+
/**
|
|
22
|
+
* What happens to an agent's edit that uses a value the memory does not allow: it is undone and
|
|
23
|
+
* the agent told the allowed values, it goes through with a warning, or nothing is checked.
|
|
24
|
+
* People's own edits are never refused; lint lists them.
|
|
25
|
+
*/
|
|
26
|
+
const DESIGN_MEMORY_ENFORCEMENTS = [
|
|
27
|
+
"refuse",
|
|
28
|
+
"warn",
|
|
29
|
+
"off"
|
|
30
|
+
];
|
|
31
|
+
const DESIGN_DECISION_AUTHORS = ["person", "agent"];
|
|
32
|
+
const enforcementSchema = v.picklist(DESIGN_MEMORY_ENFORCEMENTS);
|
|
33
|
+
/** A color as a memory keeps it: `#RRGGBB`, since alpha is never compared. */
|
|
34
|
+
const hexColorSchema = v.pipe(v.string(), v.regex(/^#[0-9A-F]{6}$/));
|
|
35
|
+
const fontFamilySchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(DESIGN_MEMORY_LIMITS.fontLength));
|
|
36
|
+
const fontSizeSchema = v.pipe(v.number(), v.finite(), v.gtValue(0));
|
|
37
|
+
const lengthSchema = v.pipe(v.number(), v.finite(), v.minValue(0));
|
|
38
|
+
/**
|
|
39
|
+
* One group: `fromSystem` allows what the document's variables and styles hold, and `values`
|
|
40
|
+
* adds values of the person's own.
|
|
41
|
+
*/
|
|
42
|
+
function valueGroup(value, max) {
|
|
43
|
+
return v.object({
|
|
44
|
+
fromSystem: v.boolean(),
|
|
45
|
+
values: v.pipe(v.array(value), v.maxLength(max)),
|
|
46
|
+
enforce: enforcementSchema
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const decisionSchema = v.object({
|
|
50
|
+
id: v.pipe(v.string(), v.nonEmpty()),
|
|
51
|
+
text: v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(DESIGN_MEMORY_LIMITS.decisionLength)),
|
|
52
|
+
author: v.picklist(DESIGN_DECISION_AUTHORS)
|
|
53
|
+
});
|
|
54
|
+
const exampleSchema = v.object({ nodeId: v.pipe(v.string(), v.nonEmpty()) });
|
|
55
|
+
/**
|
|
56
|
+
* A document's design rules for agents: the values its designs may use, decisions written down
|
|
57
|
+
* about them, and frames pinned as examples to follow.
|
|
58
|
+
*/
|
|
59
|
+
const designMemorySchema = v.object({
|
|
60
|
+
version: v.literal(1),
|
|
61
|
+
colors: valueGroup(hexColorSchema, DESIGN_MEMORY_LIMITS.colors),
|
|
62
|
+
fonts: valueGroup(fontFamilySchema, DESIGN_MEMORY_LIMITS.fonts),
|
|
63
|
+
fontSizes: valueGroup(fontSizeSchema, DESIGN_MEMORY_LIMITS.numbers),
|
|
64
|
+
spacing: valueGroup(lengthSchema, DESIGN_MEMORY_LIMITS.numbers),
|
|
65
|
+
radius: valueGroup(lengthSchema, DESIGN_MEMORY_LIMITS.numbers),
|
|
66
|
+
decisions: v.pipe(v.array(decisionSchema), v.maxLength(DESIGN_MEMORY_LIMITS.decisions)),
|
|
67
|
+
examples: v.pipe(v.array(exampleSchema), v.maxLength(DESIGN_MEMORY_LIMITS.examples))
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
70
|
+
export { DESIGN_DECISION_AUTHORS, DESIGN_MEMORY_ENFORCEMENTS, DESIGN_MEMORY_GROUPS, DESIGN_MEMORY_LIMITS, designMemorySchema };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/design-memory/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/** How many values, decisions and examples one document's memory keeps. */\nexport const DESIGN_MEMORY_LIMITS = {\n colors: 128,\n fonts: 16,\n numbers: 32,\n decisions: 40,\n decisionLength: 400,\n examples: 12,\n fontLength: 100\n} as const\n\n/** The kinds of value a memory allows, each with its own list and enforcement. */\nexport const DESIGN_MEMORY_GROUPS = ['colors', 'fonts', 'fontSizes', 'spacing', 'radius'] as const\nexport type DesignMemoryGroup = (typeof DESIGN_MEMORY_GROUPS)[number]\n\n/**\n * What happens to an agent's edit that uses a value the memory does not allow: it is undone and\n * the agent told the allowed values, it goes through with a warning, or nothing is checked.\n * People's own edits are never refused; lint lists them.\n */\nexport const DESIGN_MEMORY_ENFORCEMENTS = ['refuse', 'warn', 'off'] as const\nexport type DesignMemoryEnforcement = (typeof DESIGN_MEMORY_ENFORCEMENTS)[number]\n\nexport const DESIGN_DECISION_AUTHORS = ['person', 'agent'] as const\nexport type DesignDecisionAuthor = (typeof DESIGN_DECISION_AUTHORS)[number]\n\nconst enforcementSchema = v.picklist(DESIGN_MEMORY_ENFORCEMENTS)\n\n/** A color as a memory keeps it: `#RRGGBB`, since alpha is never compared. */\nconst hexColorSchema = v.pipe(v.string(), v.regex(/^#[0-9A-F]{6}$/))\nconst fontFamilySchema = v.pipe(\n v.string(),\n v.trim(),\n v.nonEmpty(),\n v.maxLength(DESIGN_MEMORY_LIMITS.fontLength)\n)\nconst fontSizeSchema = v.pipe(v.number(), v.finite(), v.gtValue(0))\nconst lengthSchema = v.pipe(v.number(), v.finite(), v.minValue(0))\n\n/**\n * One group: `fromSystem` allows what the document's variables and styles hold, and `values`\n * adds values of the person's own.\n */\nfunction valueGroup<T>(value: v.GenericSchema<unknown, T>, max: number) {\n return v.object({\n fromSystem: v.boolean(),\n values: v.pipe(v.array(value), v.maxLength(max)),\n enforce: enforcementSchema\n })\n}\n\nconst decisionSchema = v.object({\n id: v.pipe(v.string(), v.nonEmpty()),\n text: v.pipe(\n v.string(),\n v.trim(),\n v.nonEmpty(),\n v.maxLength(DESIGN_MEMORY_LIMITS.decisionLength)\n ),\n author: v.picklist(DESIGN_DECISION_AUTHORS)\n})\n\nconst exampleSchema = v.object({ nodeId: v.pipe(v.string(), v.nonEmpty()) })\n\n/**\n * A document's design rules for agents: the values its designs may use, decisions written down\n * about them, and frames pinned as examples to follow.\n */\nexport const designMemorySchema = v.object({\n version: v.literal(1),\n colors: valueGroup(hexColorSchema, DESIGN_MEMORY_LIMITS.colors),\n fonts: valueGroup(fontFamilySchema, DESIGN_MEMORY_LIMITS.fonts),\n fontSizes: valueGroup(fontSizeSchema, DESIGN_MEMORY_LIMITS.numbers),\n spacing: valueGroup(lengthSchema, DESIGN_MEMORY_LIMITS.numbers),\n radius: valueGroup(lengthSchema, DESIGN_MEMORY_LIMITS.numbers),\n decisions: v.pipe(v.array(decisionSchema), v.maxLength(DESIGN_MEMORY_LIMITS.decisions)),\n examples: v.pipe(v.array(exampleSchema), v.maxLength(DESIGN_MEMORY_LIMITS.examples))\n})\n\nexport type DesignMemory = v.InferOutput<typeof designMemorySchema>\nexport type DesignDecision = DesignMemory['decisions'][number]\nexport type DesignExample = DesignMemory['examples'][number]\n"],"mappings":";;;AAGA,MAAa,uBAAuB;CAClC,QAAQ;CACR,OAAO;CACP,SAAS;CACT,WAAW;CACX,gBAAgB;CAChB,UAAU;CACV,YAAY;AACd;;AAGA,MAAa,uBAAuB;CAAC;CAAU;CAAS;CAAa;CAAW;AAAQ;;;;;;AAQxF,MAAa,6BAA6B;CAAC;CAAU;CAAQ;AAAK;AAGlE,MAAa,0BAA0B,CAAC,UAAU,OAAO;AAGzD,MAAM,oBAAoB,EAAE,SAAS,0BAA0B;;AAG/D,MAAM,iBAAiB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACnE,MAAM,mBAAmB,EAAE,KACzB,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,SAAS,GACX,EAAE,UAAU,qBAAqB,UAAU,CAC7C;AACA,MAAM,iBAAiB,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;AAClE,MAAM,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;;;;;AAMjE,SAAS,WAAc,OAAoC,KAAa;CACtE,OAAO,EAAE,OAAO;EACd,YAAY,EAAE,QAAQ;EACtB,QAAQ,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,EAAE,UAAU,GAAG,CAAC;EAC/C,SAAS;CACX,CAAC;AACH;AAEA,MAAM,iBAAiB,EAAE,OAAO;CAC9B,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACnC,MAAM,EAAE,KACN,EAAE,OAAO,GACT,EAAE,KAAK,GACP,EAAE,SAAS,GACX,EAAE,UAAU,qBAAqB,cAAc,CACjD;CACA,QAAQ,EAAE,SAAS,uBAAuB;AAC5C,CAAC;AAED,MAAM,gBAAgB,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC;;;;;AAM3E,MAAa,qBAAqB,EAAE,OAAO;CACzC,SAAS,EAAE,QAAQ,CAAC;CACpB,QAAQ,WAAW,gBAAgB,qBAAqB,MAAM;CAC9D,OAAO,WAAW,kBAAkB,qBAAqB,KAAK;CAC9D,WAAW,WAAW,gBAAgB,qBAAqB,OAAO;CAClE,SAAS,WAAW,cAAc,qBAAqB,OAAO;CAC9D,QAAQ,WAAW,cAAc,qBAAqB,OAAO;CAC7D,WAAW,EAAE,KAAK,EAAE,MAAM,cAAc,GAAG,EAAE,UAAU,qBAAqB,SAAS,CAAC;CACtF,UAAU,EAAE,KAAK,EAAE,MAAM,aAAa,GAAG,EAAE,UAAU,qBAAqB,QAAQ,CAAC;AACrF,CAAC"}
|
package/dist/effects.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Vector } from "./primitives/index.js";
|
|
2
|
-
import { Effect,
|
|
2
|
+
import { Effect, ShadowEffect } from "./types.js";
|
|
3
3
|
//#region src/effects.d.ts
|
|
4
4
|
/** A shadow or blur whose offset may still be missing or only partly present. */
|
|
5
5
|
type ShadowInput = Omit<ShadowEffect, 'offset'> & {
|
|
6
6
|
offset?: Partial<Vector> | null;
|
|
7
7
|
};
|
|
8
|
+
/** An effect as a caller may pass it, before its geometry is made finite. */
|
|
9
|
+
type EffectInput = Effect | ShadowInput;
|
|
8
10
|
/**
|
|
9
11
|
* Shadows and blurs keep a finite offset. A drop or inner shadow missing one uses `{x: 0, y: 4}`,
|
|
10
|
-
* the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader
|
|
11
|
-
* are left alone. An array that is already valid is
|
|
12
|
+
* the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader, noise,
|
|
13
|
+
* and texture effects carry no offset and are left alone. An array that is already valid is
|
|
14
|
+
* returned as itself.
|
|
12
15
|
*/
|
|
13
|
-
declare function normalizeEffects(effects:
|
|
16
|
+
declare function normalizeEffects(effects: EffectInput[]): Effect[];
|
|
14
17
|
//#endregion
|
|
15
18
|
export { normalizeEffects };
|
|
16
19
|
//# sourceMappingURL=effects.d.ts.map
|
package/dist/effects.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effects.d.ts","names":[],"sources":["../src/effects.ts"],"mappings":";;;;KAOK,cAAc,KAAK;EACtB,SAAS,QAAQ;;;;;;;
|
|
1
|
+
{"version":3,"file":"effects.d.ts","names":[],"sources":["../src/effects.ts"],"mappings":";;;;KAOK,cAAc,KAAK;EACtB,SAAS,QAAQ;;;KAId,cAAc,SAAS;;;;;;;iBA0DZ,iBAAiB,SAAS,gBAAgB"}
|
package/dist/effects.js
CHANGED
|
@@ -35,6 +35,10 @@ function isStoredShadow(effect) {
|
|
|
35
35
|
const offset = effect.offset;
|
|
36
36
|
return !!offset && typeof offset.x === "number" && Number.isFinite(offset.x) && typeof offset.y === "number" && Number.isFinite(offset.y);
|
|
37
37
|
}
|
|
38
|
+
/** An effect that carries geometry of its own, which has to be finite to render. */
|
|
39
|
+
function isOffsetEffect(effect) {
|
|
40
|
+
return effect.type !== "SHADER" && effect.type !== "NOISE" && effect.type !== "TEXTURE";
|
|
41
|
+
}
|
|
38
42
|
function withFiniteOffset(effect) {
|
|
39
43
|
const offset = finiteOffset(effect);
|
|
40
44
|
if (!offset) {
|
|
@@ -50,17 +54,18 @@ function withFiniteOffset(effect) {
|
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
function isStoredEffect(effect) {
|
|
53
|
-
return effect
|
|
57
|
+
return !isOffsetEffect(effect) || isStoredShadow(effect);
|
|
54
58
|
}
|
|
55
59
|
/**
|
|
56
60
|
* Shadows and blurs keep a finite offset. A drop or inner shadow missing one uses `{x: 0, y: 4}`,
|
|
57
|
-
* the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader
|
|
58
|
-
* are left alone. An array that is already valid is
|
|
61
|
+
* the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader, noise,
|
|
62
|
+
* and texture effects carry no offset and are left alone. An array that is already valid is
|
|
63
|
+
* returned as itself.
|
|
59
64
|
*/
|
|
60
65
|
function normalizeEffects(effects) {
|
|
61
66
|
let next = null;
|
|
62
67
|
for (const [index, effect] of effects.entries()) {
|
|
63
|
-
const normalized = effect
|
|
68
|
+
const normalized = isOffsetEffect(effect) ? withFiniteOffset(effect) : effect;
|
|
64
69
|
if (normalized === effect) {
|
|
65
70
|
if (next && isStoredEffect(effect)) next.push(effect);
|
|
66
71
|
continue;
|
package/dist/effects.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"effects.js","names":[],"sources":["../src/effects.ts"],"sourcesContent":["import type { Vector } from './primitives'\nimport type { Effect,
|
|
1
|
+
{"version":3,"file":"effects.js","names":[],"sources":["../src/effects.ts"],"sourcesContent":["import type { Vector } from './primitives'\nimport type { Effect, ShadowEffect } from './types'\n\nconst SHADOW_OFFSET: Vector = { x: 0, y: 4 }\nconst BLUR_OFFSET: Vector = { x: 0, y: 0 }\n\n/** A shadow or blur whose offset may still be missing or only partly present. */\ntype ShadowInput = Omit<ShadowEffect, 'offset'> & {\n offset?: Partial<Vector> | null\n}\n\n/** An effect as a caller may pass it, before its geometry is made finite. */\ntype EffectInput = Effect | ShadowInput\n\nfunction fallbackOffset(type: ShadowEffect['type']): Vector {\n return type === 'DROP_SHADOW' || type === 'INNER_SHADOW' ? SHADOW_OFFSET : BLUR_OFFSET\n}\n\nfunction component(offset: object, key: 'x' | 'y', fallback: number): number {\n if (!(key in offset)) return fallback\n const value: unknown = Reflect.get(offset, key)\n return typeof value === 'number' && Number.isFinite(value) ? value : fallback\n}\n\n/** A new offset when `effect.offset` is missing or not finite; null when it can stay. */\nfunction finiteOffset(effect: ShadowInput): Vector | null {\n const fallback = fallbackOffset(effect.type)\n const offset: unknown = effect.offset\n if (offset === null || typeof offset !== 'object') return { x: fallback.x, y: fallback.y }\n const x = component(offset, 'x', fallback.x)\n const y = component(offset, 'y', fallback.y)\n if (Reflect.get(offset, 'x') === x && Reflect.get(offset, 'y') === y) return null\n return { x, y }\n}\n\nfunction isStoredShadow(effect: ShadowInput): effect is ShadowEffect {\n const offset = effect.offset\n return (\n !!offset &&\n typeof offset.x === 'number' &&\n Number.isFinite(offset.x) &&\n typeof offset.y === 'number' &&\n Number.isFinite(offset.y)\n )\n}\n\n/** An effect that carries geometry of its own, which has to be finite to render. */\nfunction isOffsetEffect(effect: EffectInput): effect is ShadowInput {\n return effect.type !== 'SHADER' && effect.type !== 'NOISE' && effect.type !== 'TEXTURE'\n}\n\nfunction withFiniteOffset(effect: ShadowInput): Effect {\n const offset = finiteOffset(effect)\n if (!offset) {\n if (isStoredShadow(effect)) return effect\n return { ...effect, offset: fallbackOffset(effect.type) }\n }\n return { ...effect, offset }\n}\n\nfunction isStoredEffect(effect: EffectInput): effect is Effect {\n return !isOffsetEffect(effect) || isStoredShadow(effect)\n}\n\n/**\n * Shadows and blurs keep a finite offset. A drop or inner shadow missing one uses `{x: 0, y: 4}`,\n * the same default as `dropShadow()` and `set_effects`; a blur uses `{x: 0, y: 0}`. Shader, noise,\n * and texture effects carry no offset and are left alone. An array that is already valid is\n * returned as itself.\n */\nexport function normalizeEffects(effects: EffectInput[]): Effect[] {\n let next: Effect[] | null = null\n for (const [index, effect] of effects.entries()) {\n const normalized = isOffsetEffect(effect) ? withFiniteOffset(effect) : effect\n if (normalized === effect) {\n if (next && isStoredEffect(effect)) next.push(effect)\n continue\n }\n next ??= effects.slice(0, index).filter(isStoredEffect)\n next.push(normalized)\n }\n if (next) return next\n if (effects.every(isStoredEffect)) return effects\n return effects.filter(isStoredEffect)\n}\n"],"mappings":";AAGA,MAAM,gBAAwB;CAAE,GAAG;CAAG,GAAG;AAAE;AAC3C,MAAM,cAAsB;CAAE,GAAG;CAAG,GAAG;AAAE;AAUzC,SAAS,eAAe,MAAoC;CAC1D,OAAO,SAAS,iBAAiB,SAAS,iBAAiB,gBAAgB;AAC7E;AAEA,SAAS,UAAU,QAAgB,KAAgB,UAA0B;CAC3E,IAAI,EAAE,OAAO,SAAS,OAAO;CAC7B,MAAM,QAAiB,QAAQ,IAAI,QAAQ,GAAG;CAC9C,OAAO,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK,IAAI,QAAQ;AACvE;;AAGA,SAAS,aAAa,QAAoC;CACxD,MAAM,WAAW,eAAe,OAAO,IAAI;CAC3C,MAAM,SAAkB,OAAO;CAC/B,IAAI,WAAW,QAAQ,OAAO,WAAW,UAAU,OAAO;EAAE,GAAG,SAAS;EAAG,GAAG,SAAS;CAAE;CACzF,MAAM,IAAI,UAAU,QAAQ,KAAK,SAAS,CAAC;CAC3C,MAAM,IAAI,UAAU,QAAQ,KAAK,SAAS,CAAC;CAC3C,IAAI,QAAQ,IAAI,QAAQ,GAAG,MAAM,KAAK,QAAQ,IAAI,QAAQ,GAAG,MAAM,GAAG,OAAO;CAC7E,OAAO;EAAE;EAAG;CAAE;AAChB;AAEA,SAAS,eAAe,QAA6C;CACnE,MAAM,SAAS,OAAO;CACtB,OACE,CAAC,CAAC,UACF,OAAO,OAAO,MAAM,YACpB,OAAO,SAAS,OAAO,CAAC,KACxB,OAAO,OAAO,MAAM,YACpB,OAAO,SAAS,OAAO,CAAC;AAE5B;;AAGA,SAAS,eAAe,QAA4C;CAClE,OAAO,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW,OAAO,SAAS;AAChF;AAEA,SAAS,iBAAiB,QAA6B;CACrD,MAAM,SAAS,aAAa,MAAM;CAClC,IAAI,CAAC,QAAQ;EACX,IAAI,eAAe,MAAM,GAAG,OAAO;EACnC,OAAO;GAAE,GAAG;GAAQ,QAAQ,eAAe,OAAO,IAAI;EAAE;CAC1D;CACA,OAAO;EAAE,GAAG;EAAQ;CAAO;AAC7B;AAEA,SAAS,eAAe,QAAuC;CAC7D,OAAO,CAAC,eAAe,MAAM,KAAK,eAAe,MAAM;AACzD;;;;;;;AAQA,SAAgB,iBAAiB,SAAkC;CACjE,IAAI,OAAwB;CAC5B,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,QAAQ,GAAG;EAC/C,MAAM,aAAa,eAAe,MAAM,IAAI,iBAAiB,MAAM,IAAI;EACvE,IAAI,eAAe,QAAQ;GACzB,IAAI,QAAQ,eAAe,MAAM,GAAG,KAAK,KAAK,MAAM;GACpD;EACF;EACA,SAAS,QAAQ,MAAM,GAAG,KAAK,CAAC,CAAC,OAAO,cAAc;EACtD,KAAK,KAAK,UAAU;CACtB;CACA,IAAI,MAAM,OAAO;CACjB,IAAI,QAAQ,MAAM,cAAc,GAAG,OAAO;CAC1C,OAAO,QAAQ,OAAO,cAAc;AACtC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isEmptyObject, isPlainObject } from "es-toolkit";
|
|
2
|
+
//#region src/empty-values.ts
|
|
3
|
+
/**
|
|
4
|
+
* The empty list and record every layer holds until a field gets a value of its own. All layers
|
|
5
|
+
* share them, so they are frozen: a field is replaced, never written into, and a write into one
|
|
6
|
+
* throws instead of reaching every layer of every document.
|
|
7
|
+
*/
|
|
8
|
+
const EMPTY_LIST = Object.freeze([]);
|
|
9
|
+
const EMPTY_RECORD = Object.freeze({});
|
|
10
|
+
/** The child list is the graph's to grow in place, so every layer keeps its own. */
|
|
11
|
+
const OWN_LIST_FIELDS = /* @__PURE__ */ new Set(["childIds"]);
|
|
12
|
+
/** Fields keyed by name, such as bindings and property values, that start empty. */
|
|
13
|
+
const RECORD_FIELDS = /* @__PURE__ */ new Set([
|
|
14
|
+
"componentPropertyAssignments",
|
|
15
|
+
"componentPropertyValues",
|
|
16
|
+
"boundVariables",
|
|
17
|
+
"variableBindingScales",
|
|
18
|
+
"variableAssignmentScales",
|
|
19
|
+
"variableModes"
|
|
20
|
+
]);
|
|
21
|
+
const SOURCE_LIST_FIELDS = ["editedFields"];
|
|
22
|
+
const FIG_SOURCE_LIST_FIELDS = [
|
|
23
|
+
"symbolOverrides",
|
|
24
|
+
"componentPropAssignments",
|
|
25
|
+
"derivedSymbolData"
|
|
26
|
+
];
|
|
27
|
+
function sharedEmptyList(value) {
|
|
28
|
+
return Array.isArray(value) && value.length === 0 ? EMPTY_LIST : value;
|
|
29
|
+
}
|
|
30
|
+
function sharedEmptyRecord(value) {
|
|
31
|
+
return isPlainObject(value) && isEmptyObject(value) ? EMPTY_RECORD : value;
|
|
32
|
+
}
|
|
33
|
+
function sharedEmptyValue(field, value) {
|
|
34
|
+
if (Array.isArray(value)) return OWN_LIST_FIELDS.has(field) ? value : sharedEmptyList(value);
|
|
35
|
+
return RECORD_FIELDS.has(field) ? sharedEmptyRecord(value) : value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* `record` with the empty lists among `lists` and the empty record at `recordField` swapped for
|
|
39
|
+
* the shared ones: a copy when anything changes, so the caller's object is never written into.
|
|
40
|
+
* A field the record lacks stays absent.
|
|
41
|
+
*/
|
|
42
|
+
function withSharedEmpties(record, lists, recordField) {
|
|
43
|
+
const fields = lists.map((field) => [field, sharedEmptyList]);
|
|
44
|
+
if (recordField !== void 0) fields.push([recordField, sharedEmptyRecord]);
|
|
45
|
+
let copy = null;
|
|
46
|
+
for (const [field, shared] of fields) {
|
|
47
|
+
if (!Object.hasOwn(record, field)) continue;
|
|
48
|
+
const value = Reflect.get(record, field);
|
|
49
|
+
const next = shared(value);
|
|
50
|
+
if (next === value) continue;
|
|
51
|
+
copy ??= { ...record };
|
|
52
|
+
Reflect.set(copy, field, next);
|
|
53
|
+
}
|
|
54
|
+
return copy ?? record;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Source metadata with its empty lists and raw fields swapped for the shared ones. The metadata
|
|
58
|
+
* object and its `fig` part stay the layer's own, since readers and edits write their scalars in
|
|
59
|
+
* place; metadata missing parts, as libraries and plugins may give, is kept as given.
|
|
60
|
+
*/
|
|
61
|
+
function withSharedEmptySource(source) {
|
|
62
|
+
const outer = withSharedEmpties(source, SOURCE_LIST_FIELDS);
|
|
63
|
+
const fig = Reflect.get(source, "fig");
|
|
64
|
+
if (!isPlainObject(fig)) return outer;
|
|
65
|
+
const sharedFig = withSharedEmpties(fig, FIG_SOURCE_LIST_FIELDS, "rawNodeFields");
|
|
66
|
+
if (sharedFig === fig) return outer;
|
|
67
|
+
return {
|
|
68
|
+
...outer,
|
|
69
|
+
fig: {
|
|
70
|
+
...source.fig,
|
|
71
|
+
...sharedFig
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Swap the `fields` of `node` that hold an empty list or record, its source metadata's included,
|
|
77
|
+
* for the shared ones. Writing known keys keeps the shape every layer shares.
|
|
78
|
+
*/
|
|
79
|
+
function shareEmptyNodeValues(node, fields) {
|
|
80
|
+
for (const field of fields) {
|
|
81
|
+
const value = Reflect.get(node, field);
|
|
82
|
+
if (field === "source") {
|
|
83
|
+
if (isPlainObject(value)) node.source = withSharedEmptySource(node.source);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const shared = sharedEmptyValue(field, value);
|
|
87
|
+
if (shared !== value) Reflect.set(node, field, shared);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { EMPTY_LIST, EMPTY_RECORD, shareEmptyNodeValues };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=empty-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"empty-values.js","names":[],"sources":["../src/empty-values.ts"],"sourcesContent":["import { isEmptyObject, isPlainObject } from 'es-toolkit'\n\nimport type { SceneNode, SourceMetadata } from './types'\n\n/**\n * The empty list and record every layer holds until a field gets a value of its own. All layers\n * share them, so they are frozen: a field is replaced, never written into, and a write into one\n * throws instead of reaching every layer of every document.\n */\nexport const EMPTY_LIST: never[] = Object.freeze<never[]>([]) as never[]\nexport const EMPTY_RECORD: Record<string, never> = Object.freeze({})\n\n/** The child list is the graph's to grow in place, so every layer keeps its own. */\nconst OWN_LIST_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>(['childIds'])\n\n/** Fields keyed by name, such as bindings and property values, that start empty. */\nconst RECORD_FIELDS: ReadonlySet<string> = new Set<keyof SceneNode>([\n 'componentPropertyAssignments',\n 'componentPropertyValues',\n 'boundVariables',\n 'variableBindingScales',\n 'variableAssignmentScales',\n 'variableModes'\n])\n\nconst SOURCE_LIST_FIELDS = ['editedFields'] as const\nconst FIG_SOURCE_LIST_FIELDS = [\n 'symbolOverrides',\n 'componentPropAssignments',\n 'derivedSymbolData'\n] as const\n\nfunction sharedEmptyList(value: unknown): unknown {\n return Array.isArray(value) && value.length === 0 ? EMPTY_LIST : value\n}\n\nfunction sharedEmptyRecord(value: unknown): unknown {\n return isPlainObject(value) && isEmptyObject(value) ? EMPTY_RECORD : value\n}\n\nfunction sharedEmptyValue(field: string, value: unknown): unknown {\n if (Array.isArray(value)) return OWN_LIST_FIELDS.has(field) ? value : sharedEmptyList(value)\n return RECORD_FIELDS.has(field) ? sharedEmptyRecord(value) : value\n}\n\n/**\n * `record` with the empty lists among `lists` and the empty record at `recordField` swapped for\n * the shared ones: a copy when anything changes, so the caller's object is never written into.\n * A field the record lacks stays absent.\n */\nfunction withSharedEmpties<T extends object>(\n record: T,\n lists: readonly string[],\n recordField?: string\n): T {\n const fields: [string, (value: unknown) => unknown][] = lists.map((field) => [\n field,\n sharedEmptyList\n ])\n if (recordField !== undefined) fields.push([recordField, sharedEmptyRecord])\n let copy: T | null = null\n for (const [field, shared] of fields) {\n if (!Object.hasOwn(record, field)) continue\n const value: unknown = Reflect.get(record, field)\n const next = shared(value)\n if (next === value) continue\n copy ??= { ...record }\n Reflect.set(copy, field, next)\n }\n return copy ?? record\n}\n\n/**\n * Source metadata with its empty lists and raw fields swapped for the shared ones. The metadata\n * object and its `fig` part stay the layer's own, since readers and edits write their scalars in\n * place; metadata missing parts, as libraries and plugins may give, is kept as given.\n */\nfunction withSharedEmptySource(source: SourceMetadata): SourceMetadata {\n const outer = withSharedEmpties(source, SOURCE_LIST_FIELDS)\n const fig: unknown = Reflect.get(source, 'fig')\n if (!isPlainObject(fig)) return outer\n const sharedFig = withSharedEmpties(fig, FIG_SOURCE_LIST_FIELDS, 'rawNodeFields')\n if (sharedFig === fig) return outer\n return { ...outer, fig: { ...source.fig, ...sharedFig } }\n}\n\n/**\n * Swap the `fields` of `node` that hold an empty list or record, its source metadata's included,\n * for the shared ones. Writing known keys keeps the shape every layer shares.\n */\nexport function shareEmptyNodeValues(node: SceneNode, fields: Iterable<string>): void {\n for (const field of fields) {\n const value: unknown = Reflect.get(node, field)\n if (field === 'source') {\n if (isPlainObject(value)) node.source = withSharedEmptySource(node.source)\n continue\n }\n const shared = sharedEmptyValue(field, value)\n if (shared !== value) Reflect.set(node, field, shared)\n }\n}\n"],"mappings":";;;;;;;AASA,MAAa,aAAsB,OAAO,OAAgB,CAAC,CAAC;AAC5D,MAAa,eAAsC,OAAO,OAAO,CAAC,CAAC;;AAGnE,MAAM,kCAAuC,IAAI,IAAqB,CAAC,UAAU,CAAC;;AAGlF,MAAM,gCAAqC,IAAI,IAAqB;CAClE;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,qBAAqB,CAAC,cAAc;AAC1C,MAAM,yBAAyB;CAC7B;CACA;CACA;AACF;AAEA,SAAS,gBAAgB,OAAyB;CAChD,OAAO,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,IAAI,aAAa;AACnE;AAEA,SAAS,kBAAkB,OAAyB;CAClD,OAAO,cAAc,KAAK,KAAK,cAAc,KAAK,IAAI,eAAe;AACvE;AAEA,SAAS,iBAAiB,OAAe,OAAyB;CAChE,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,gBAAgB,IAAI,KAAK,IAAI,QAAQ,gBAAgB,KAAK;CAC3F,OAAO,cAAc,IAAI,KAAK,IAAI,kBAAkB,KAAK,IAAI;AAC/D;;;;;;AAOA,SAAS,kBACP,QACA,OACA,aACG;CACH,MAAM,SAAkD,MAAM,KAAK,UAAU,CAC3E,OACA,eACF,CAAC;CACD,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAK,CAAC,aAAa,iBAAiB,CAAC;CAC3E,IAAI,OAAiB;CACrB,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ;EACpC,IAAI,CAAC,OAAO,OAAO,QAAQ,KAAK,GAAG;EACnC,MAAM,QAAiB,QAAQ,IAAI,QAAQ,KAAK;EAChD,MAAM,OAAO,OAAO,KAAK;EACzB,IAAI,SAAS,OAAO;EACpB,SAAS,EAAE,GAAG,OAAO;EACrB,QAAQ,IAAI,MAAM,OAAO,IAAI;CAC/B;CACA,OAAO,QAAQ;AACjB;;;;;;AAOA,SAAS,sBAAsB,QAAwC;CACrE,MAAM,QAAQ,kBAAkB,QAAQ,kBAAkB;CAC1D,MAAM,MAAe,QAAQ,IAAI,QAAQ,KAAK;CAC9C,IAAI,CAAC,cAAc,GAAG,GAAG,OAAO;CAChC,MAAM,YAAY,kBAAkB,KAAK,wBAAwB,eAAe;CAChF,IAAI,cAAc,KAAK,OAAO;CAC9B,OAAO;EAAE,GAAG;EAAO,KAAK;GAAE,GAAG,OAAO;GAAK,GAAG;EAAU;CAAE;AAC1D;;;;;AAMA,SAAgB,qBAAqB,MAAiB,QAAgC;CACpF,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,QAAiB,QAAQ,IAAI,MAAM,KAAK;EAC9C,IAAI,UAAU,UAAU;GACtB,IAAI,cAAc,KAAK,GAAG,KAAK,SAAS,sBAAsB,KAAK,MAAM;GACzE;EACF;EACA,MAAM,SAAS,iBAAiB,OAAO,KAAK;EAC5C,IAAI,WAAW,OAAO,QAAQ,IAAI,MAAM,OAAO,MAAM;CACvD;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/fields/components.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* What makes a layer a main component beyond its type: its key, its properties and variant
|
|
4
|
+
* specs, and how it is published to libraries.
|
|
5
|
+
*/
|
|
6
|
+
declare const MAIN_COMPONENT_FIELDS: readonly ["componentKey", "componentPropertyDefinitions", "variantPropSpecs", "sourceLibraryKey", "publishId", "overrideKey", "sharedSymbolVersion", "publishedVersion", "librarySource", "isPublishable", "isSymbolPublishable", "symbolDescription", "symbolLinks"];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MAIN_COMPONENT_FIELDS };
|
|
9
|
+
//# sourceMappingURL=components.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.d.ts","names":[],"sources":["../../src/fields/components.ts"],"mappings":";;;;;cAMa"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/fields/components.ts
|
|
2
|
+
/**
|
|
3
|
+
* What makes a layer a main component beyond its type: its key, its properties and variant
|
|
4
|
+
* specs, and how it is published to libraries.
|
|
5
|
+
*/
|
|
6
|
+
const MAIN_COMPONENT_FIELDS = [
|
|
7
|
+
"componentKey",
|
|
8
|
+
"componentPropertyDefinitions",
|
|
9
|
+
"variantPropSpecs",
|
|
10
|
+
"sourceLibraryKey",
|
|
11
|
+
"publishId",
|
|
12
|
+
"overrideKey",
|
|
13
|
+
"sharedSymbolVersion",
|
|
14
|
+
"publishedVersion",
|
|
15
|
+
"librarySource",
|
|
16
|
+
"isPublishable",
|
|
17
|
+
"isSymbolPublishable",
|
|
18
|
+
"symbolDescription",
|
|
19
|
+
"symbolLinks"
|
|
20
|
+
];
|
|
21
|
+
//#endregion
|
|
22
|
+
export { MAIN_COMPONENT_FIELDS };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","names":[],"sources":["../../src/fields/components.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\n/**\n * What makes a layer a main component beyond its type: its key, its properties and variant\n * specs, and how it is published to libraries.\n */\nexport const MAIN_COMPONENT_FIELDS = [\n 'componentKey',\n 'componentPropertyDefinitions',\n 'variantPropSpecs',\n 'sourceLibraryKey',\n 'publishId',\n 'overrideKey',\n 'sharedSymbolVersion',\n 'publishedVersion',\n 'librarySource',\n 'isPublishable',\n 'isSymbolPublishable',\n 'symbolDescription',\n 'symbolLinks'\n] as const satisfies readonly (keyof SceneNode)[]\n"],"mappings":";;;;;AAMA,MAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/fields/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from "./appearance.js";
|
|
2
|
+
import { MAIN_COMPONENT_FIELDS } from "./components.js";
|
|
2
3
|
import { SIZE_FIELDS, TRANSFORM_FIELDS } from "./geometry.js";
|
|
3
|
-
import { AUTO_LAYOUT_FIELDS, LAYOUT_AFFECTING_KEYS, SIZE_CONSTRAINT_FIELDS } from "./layout.js";
|
|
4
|
+
import { AUTO_LAYOUT_FIELDS, LAYOUT_AFFECTING_KEYS, PARENT_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from "./layout.js";
|
|
4
5
|
import { TEXT_DECORATION_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS, TEXT_STYLE_FIELDS } from "./text.js";
|
|
5
|
-
export { AUTO_LAYOUT_FIELDS, CORNER_FIELDS, LAYOUT_AFFECTING_KEYS, PAINT_FIELDS, SIZE_CONSTRAINT_FIELDS, SIZE_FIELDS, STROKE_FIELDS, TEXT_DECORATION_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS, TEXT_STYLE_FIELDS, TRANSFORM_FIELDS };
|
|
6
|
+
export { AUTO_LAYOUT_FIELDS, CORNER_FIELDS, LAYOUT_AFFECTING_KEYS, MAIN_COMPONENT_FIELDS, PAINT_FIELDS, PARENT_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS, SIZE_FIELDS, STROKE_FIELDS, TEXT_DECORATION_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS, TEXT_STYLE_FIELDS, TRANSFORM_FIELDS };
|
package/dist/fields/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SIZE_FIELDS, TRANSFORM_FIELDS } from "./geometry.js";
|
|
2
|
-
import { AUTO_LAYOUT_FIELDS, LAYOUT_AFFECTING_KEYS, SIZE_CONSTRAINT_FIELDS } from "./layout.js";
|
|
2
|
+
import { AUTO_LAYOUT_FIELDS, LAYOUT_AFFECTING_KEYS, PARENT_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS } from "./layout.js";
|
|
3
3
|
import { TEXT_DECORATION_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS, TEXT_STYLE_FIELDS } from "./text.js";
|
|
4
4
|
import { CORNER_FIELDS, PAINT_FIELDS, STROKE_FIELDS } from "./appearance.js";
|
|
5
|
-
|
|
5
|
+
import { MAIN_COMPONENT_FIELDS } from "./components.js";
|
|
6
|
+
export { AUTO_LAYOUT_FIELDS, CORNER_FIELDS, LAYOUT_AFFECTING_KEYS, MAIN_COMPONENT_FIELDS, PAINT_FIELDS, PARENT_LAYOUT_FIELDS, SIZE_CONSTRAINT_FIELDS, SIZE_FIELDS, STROKE_FIELDS, TEXT_DECORATION_FIELDS, TEXT_LAYOUT_FIELDS, TEXT_METRIC_FIELDS, TEXT_SHAPING_FIELDS, TEXT_STYLE_FIELDS, TRANSFORM_FIELDS };
|