@open-pencil/scene-graph 0.15.0 → 0.16.0-beta.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 +21 -0
- package/README.md +1 -1
- package/dist/chunks/behaviours/kinds.js +273 -0
- package/dist/chunks/behaviours/kinds.js.map +1 -0
- package/dist/chunks/behaviours/layers.js +596 -0
- package/dist/chunks/behaviours/layers.js.map +1 -0
- package/dist/chunks/behaviours/spec.js +181 -0
- package/dist/chunks/behaviours/spec.js.map +1 -0
- package/dist/chunks/buffered-events.js +57 -0
- package/dist/chunks/buffered-events.js.map +1 -0
- package/dist/chunks/color/contrast.js +57 -0
- package/dist/chunks/color/contrast.js.map +1 -0
- package/dist/chunks/{components/properties.js → color/index.js} +573 -521
- package/dist/chunks/color/index.js.map +1 -0
- package/dist/chunks/comments/document.js +32 -0
- package/dist/chunks/comments/document.js.map +1 -0
- package/dist/chunks/comments/list.js +182 -0
- package/dist/chunks/comments/list.js.map +1 -0
- package/dist/chunks/comments/merge.js +58 -0
- package/dist/chunks/comments/merge.js.map +1 -0
- package/dist/chunks/components/exposure.js +2021 -0
- package/dist/chunks/components/exposure.js.map +1 -0
- package/dist/chunks/components/variants.js +32 -0
- package/dist/chunks/components/variants.js.map +1 -0
- package/dist/chunks/coordinate.js +93 -55
- package/dist/chunks/coordinate.js.map +1 -1
- package/dist/chunks/css/grid.js +94 -0
- package/dist/chunks/css/grid.js.map +1 -0
- package/dist/chunks/css/index.js +160 -0
- package/dist/chunks/css/index.js.map +1 -0
- package/dist/chunks/fields/geometry.js +14 -0
- package/dist/chunks/fields/geometry.js.map +1 -0
- package/dist/chunks/fields/text.js +36 -0
- package/dist/chunks/fields/text.js.map +1 -0
- package/dist/chunks/group-bounds.js +104 -0
- package/dist/chunks/group-bounds.js.map +1 -0
- package/dist/chunks/icons/glyph.js +147 -0
- package/dist/chunks/icons/glyph.js.map +1 -0
- package/dist/chunks/index.js +1712 -662
- package/dist/chunks/index.js.map +1 -1
- package/dist/color.d.ts +72 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +3 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +2 -2
- package/dist/constants2.d.ts +3 -1
- package/dist/constants2.d.ts.map +1 -1
- package/dist/coordinate.d.ts +2 -448
- package/dist/coordinate.js +2 -2
- package/dist/copy.d.ts +1 -1
- package/dist/copy.js +1 -1
- package/dist/css.d.ts +39 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +3 -0
- package/dist/geometry.d.ts +1 -1
- package/dist/geometry.js +1 -1
- package/dist/gradient.d.ts +51 -0
- package/dist/gradient.d.ts.map +1 -0
- package/dist/gradient.js +132 -0
- package/dist/gradient.js.map +1 -0
- package/dist/guides.d.ts +2 -2
- package/dist/guides.js +39 -0
- package/dist/guides.js.map +1 -0
- package/dist/hit-test.d.ts +2 -9
- package/dist/hit-test.js +154 -18
- package/dist/hit-test.js.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.js +20 -5
- package/dist/instances.d.ts +2 -2
- package/dist/instances.js +2 -2
- package/dist/layout.d.ts +2 -0
- package/dist/layout.js +4 -0
- package/dist/node-defaults.d.ts +2 -8
- package/dist/node-defaults.js +2 -2
- package/dist/order-keys.d.ts +39 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +136 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/parse-path.d.ts +7 -1
- package/dist/parse-path.d.ts.map +1 -1
- package/dist/parse-path.js +6 -2
- package/dist/parse-path.js.map +1 -1
- package/dist/polygon.d.ts +53 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +205 -0
- package/dist/polygon.js.map +1 -0
- package/dist/preview.d.ts +1 -1
- package/dist/random.d.ts +7 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +2 -0
- package/dist/resize.d.ts +11 -2
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +2 -184
- package/dist/snap.d.ts +1 -1
- package/dist/text-direction.d.ts +13 -0
- package/dist/text-direction.d.ts.map +1 -0
- package/dist/text-direction.js +31 -0
- package/dist/text-direction.js.map +1 -0
- package/dist/text-picture.d.ts +1 -1
- package/dist/text-picture.d.ts.map +1 -1
- package/dist/text.d.ts +2 -0
- package/dist/text.js +3 -0
- package/dist/types.d.ts +2063 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types2.d.ts +2 -2
- package/dist/undo.d.ts +2 -2
- package/dist/undo.js +2 -2
- package/dist/undo2.d.ts +29 -1
- package/dist/undo2.d.ts.map +1 -1
- package/dist/variables.d.ts +2 -29
- package/dist/variables.js +2 -2
- package/dist/variant-properties.d.ts +9 -1
- package/dist/variant-properties.d.ts.map +1 -1
- package/dist/variant-properties.js +36 -1
- package/dist/variant-properties.js.map +1 -1
- package/dist/vector-network.d.ts +1 -1
- package/dist/vector-network.js +1 -1
- package/package.json +60 -9
- package/src/behaviours/kinds.ts +185 -0
- package/src/behaviours/layers.ts +51 -0
- package/src/behaviours/model.ts +192 -0
- package/src/behaviours/schema.ts +58 -0
- package/src/behaviours/spec.ts +223 -0
- package/src/buffered-events.ts +64 -0
- package/src/color/contrast.ts +31 -0
- package/src/color/index.ts +88 -0
- package/src/color/management.ts +210 -0
- package/src/color/normalize.ts +7 -0
- package/src/color/okhcl.ts +201 -0
- package/src/comments/document.ts +51 -0
- package/src/comments/list.ts +52 -0
- package/src/comments/merge.ts +63 -0
- package/src/comments/threads.ts +156 -0
- package/src/components/exposure.ts +61 -0
- package/src/components/properties.ts +18 -15
- package/src/components/variants.ts +53 -0
- package/src/constants.ts +2 -0
- package/src/coordinate.ts +100 -43
- package/src/copy.ts +13 -5
- package/src/css/grid.ts +70 -0
- package/src/css/index.ts +9 -0
- package/src/css/layout.ts +53 -0
- package/src/css/shadows.ts +68 -0
- package/src/css/values.ts +42 -0
- package/src/export-format.ts +12 -0
- package/src/fields/geometry.ts +11 -0
- package/src/fields/text.ts +35 -0
- package/src/gradient.ts +166 -0
- package/src/group-bounds.ts +131 -0
- package/src/guides.ts +39 -0
- package/src/hit-test.ts +219 -25
- package/src/icons/glyph.ts +128 -0
- package/src/icons/model.ts +54 -0
- package/src/icons/schema.ts +18 -0
- package/src/index.ts +344 -56
- package/src/instance-overrides.ts +27 -0
- package/src/instances/copies.ts +239 -0
- package/src/instances/cycles.ts +73 -0
- package/src/instances/fields.ts +143 -0
- package/src/instances/main-component.ts +19 -0
- package/src/instances/placement.ts +29 -0
- package/src/instances/source-walk.ts +41 -0
- package/src/instances/sync.ts +599 -0
- package/src/instances.ts +122 -330
- package/src/layout/aspect-ratio.ts +51 -0
- package/src/{layout-guides.ts → layout/guides.ts} +1 -1
- package/src/layout/index.ts +4 -0
- package/src/layout/keywords.ts +73 -0
- package/src/layout/sizing.ts +196 -0
- package/src/mutation-impact.ts +25 -10
- package/src/node-defaults.ts +50 -2
- package/src/order-keys.ts +162 -0
- package/src/parse-path.ts +10 -2
- package/src/plugin-data/field.ts +131 -0
- package/src/plugin-data/fields.ts +246 -0
- package/src/polygon.ts +211 -0
- package/src/preview.ts +1 -1
- package/src/random.ts +28 -0
- package/src/resize.ts +99 -12
- package/src/scaling/index.ts +2 -0
- package/src/scaling/node.ts +164 -0
- package/src/scaling/tree.ts +50 -0
- package/src/shaders/model.ts +98 -0
- package/src/shaders/schema.ts +48 -0
- package/src/slots/authoring.ts +101 -0
- package/src/slots/content.ts +124 -0
- package/src/slots/frames.ts +160 -0
- package/src/slots/limits.ts +49 -0
- package/src/text/direction.ts +55 -0
- package/src/text/index.ts +2 -0
- package/src/text/lists.ts +138 -0
- package/src/text/paragraphs.ts +241 -0
- package/src/{text-picture.ts → text/picture.ts} +21 -29
- package/src/transfer/apply.ts +84 -0
- package/src/transfer/history.ts +49 -0
- package/src/transfer/identity.ts +16 -0
- package/src/transfer/index.ts +6 -0
- package/src/transfer/nodes.ts +108 -0
- package/src/transfer/plan.ts +107 -0
- package/src/transfer/references.ts +9 -0
- package/src/transfer/remove.ts +39 -0
- package/src/transfer/validation.ts +54 -0
- package/src/transfer/variables.ts +82 -0
- package/src/types.ts +221 -11
- package/src/undo.ts +54 -2
- package/src/variables/bindings.ts +186 -0
- package/src/variables/fields.ts +43 -0
- package/src/variables/token.ts +14 -0
- package/src/variables/units.ts +15 -0
- package/src/variables.ts +118 -69
- package/src/variant-properties.ts +50 -0
- package/dist/chunks/components/properties.js.map +0 -1
- package/dist/chunks/export-scale.js +0 -19
- package/dist/chunks/export-scale.js.map +0 -1
- package/dist/coordinate.d.ts.map +0 -1
- package/dist/coordinate2.d.ts +0 -2
- package/dist/guides2.d.ts +0 -11
- package/dist/guides2.d.ts.map +0 -1
- package/dist/hit-test.d.ts.map +0 -1
- package/dist/layout-guides.d.ts +0 -2
- package/dist/layout-guides.js +0 -2
- package/dist/layout-guides2.d.ts +0 -16
- package/dist/layout-guides2.d.ts.map +0 -1
- package/dist/node-defaults.d.ts.map +0 -1
- package/dist/preview2.d.ts +0 -12
- package/dist/preview2.d.ts.map +0 -1
- package/dist/resize.js.map +0 -1
- package/dist/variables.d.ts.map +0 -1
- package/dist/vector-network2.d.ts +0 -32
- package/dist/vector-network2.d.ts.map +0 -1
- package/src/instance-overrides.test.ts +0 -67
|
@@ -1,104 +1,8 @@
|
|
|
1
1
|
import { arrowCapOverflow } from "../../arrow-caps.js";
|
|
2
|
+
import { BLACK, DEFAULT_FONT_FAMILY } from "./contrast.js";
|
|
3
|
+
import { OPEN_PENCIL_PLUGIN_DATA, readAllPluginData, withAllPluginData } from "../behaviours/layers.js";
|
|
2
4
|
import { isEqual } from "es-toolkit/predicate";
|
|
3
|
-
|
|
4
|
-
function createInstanceOverrideState() {
|
|
5
|
-
return {
|
|
6
|
-
self: /* @__PURE__ */ new Map(),
|
|
7
|
-
descendants: /* @__PURE__ */ new Map()
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function serializeOverrideValue(value) {
|
|
11
|
-
return value === void 0 ? { defined: false } : {
|
|
12
|
-
defined: true,
|
|
13
|
-
value
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function deserializeOverrideValue(value) {
|
|
17
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return {
|
|
18
|
-
valid: false,
|
|
19
|
-
value: void 0
|
|
20
|
-
};
|
|
21
|
-
if (!("defined" in value) || typeof value.defined !== "boolean") return {
|
|
22
|
-
valid: false,
|
|
23
|
-
value: void 0
|
|
24
|
-
};
|
|
25
|
-
if (value.defined) return "value" in value ? {
|
|
26
|
-
valid: true,
|
|
27
|
-
value: value["value"]
|
|
28
|
-
} : {
|
|
29
|
-
valid: false,
|
|
30
|
-
value: void 0
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
valid: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function deserializeEntries(value) {
|
|
38
|
-
const result = /* @__PURE__ */ new Map();
|
|
39
|
-
if (!Array.isArray(value)) return result;
|
|
40
|
-
for (const entry of value) {
|
|
41
|
-
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string") continue;
|
|
42
|
-
const decoded = deserializeOverrideValue(entry[1]);
|
|
43
|
-
if (decoded.valid) result.set(entry[0], decoded.value);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
function serializeInstanceOverrideState(state) {
|
|
48
|
-
return {
|
|
49
|
-
self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),
|
|
50
|
-
descendants: [...state.descendants].map(([nodeId, fields]) => [nodeId, [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])])
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function deserializeInstanceOverrideState(state) {
|
|
54
|
-
if (!state || typeof state !== "object" || Array.isArray(state)) return createInstanceOverrideState();
|
|
55
|
-
const self = "self" in state ? deserializeEntries(state.self) : /* @__PURE__ */ new Map();
|
|
56
|
-
const descendants = /* @__PURE__ */ new Map();
|
|
57
|
-
if ("descendants" in state && Array.isArray(state.descendants)) for (const entry of state.descendants) {
|
|
58
|
-
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string") continue;
|
|
59
|
-
descendants.set(entry[0], deserializeEntries(entry[1]));
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
self,
|
|
63
|
-
descendants
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function cloneInstanceOverrideState(state) {
|
|
67
|
-
return {
|
|
68
|
-
self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),
|
|
69
|
-
descendants: new Map([...state.descendants].map(([id, fields]) => [id, new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))]))
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function getInstanceOverride(state, instanceId, nodeId, field) {
|
|
73
|
-
return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field);
|
|
74
|
-
}
|
|
75
|
-
function hasInstanceOverride$1(state, instanceId, nodeId, field) {
|
|
76
|
-
return (nodeId === instanceId ? state.self : state.descendants.get(nodeId))?.has(field) ?? false;
|
|
77
|
-
}
|
|
78
|
-
function setInstanceOverride(state, instanceId, nodeId, field, value = true) {
|
|
79
|
-
if (nodeId === instanceId) {
|
|
80
|
-
state.self.set(field, value);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const fields = state.descendants.get(nodeId) ?? /* @__PURE__ */ new Map();
|
|
84
|
-
fields.set(field, value);
|
|
85
|
-
state.descendants.set(nodeId, fields);
|
|
86
|
-
}
|
|
87
|
-
function deleteInstanceOverride(state, instanceId, nodeId, field) {
|
|
88
|
-
const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId);
|
|
89
|
-
if (!fields?.delete(field)) return false;
|
|
90
|
-
if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId);
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
function clearInstanceOverrides(state) {
|
|
94
|
-
state.self.clear();
|
|
95
|
-
state.descendants.clear();
|
|
96
|
-
}
|
|
97
|
-
function forEachInstanceOverride(state, callback) {
|
|
98
|
-
for (const [field, value] of state.self) callback("", field, value);
|
|
99
|
-
for (const [nodeId, fields] of state.descendants) for (const [field, value] of fields) callback(nodeId, field, value);
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
5
|
+
import { converter, differenceEuclidean, formatCss, formatHex, formatHex8, formatRgb, inGamut, parse, toGamut } from "culori";
|
|
102
6
|
//#region src/geometry.ts
|
|
103
7
|
function degToRad(degrees) {
|
|
104
8
|
return degrees * Math.PI / 180;
|
|
@@ -533,21 +437,124 @@ function clipBoundsToPolygon(bounds, clipCorners) {
|
|
|
533
437
|
} : null;
|
|
534
438
|
}
|
|
535
439
|
//#endregion
|
|
536
|
-
//#region src/
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
440
|
+
//#region src/instance-overrides.ts
|
|
441
|
+
function createInstanceOverrideState() {
|
|
442
|
+
return {
|
|
443
|
+
self: /* @__PURE__ */ new Map(),
|
|
444
|
+
descendants: /* @__PURE__ */ new Map()
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function serializeOverrideValue(value) {
|
|
448
|
+
return value === void 0 ? { defined: false } : {
|
|
449
|
+
defined: true,
|
|
450
|
+
value
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function deserializeOverrideValue(value) {
|
|
454
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {
|
|
455
|
+
valid: false,
|
|
456
|
+
value: void 0
|
|
457
|
+
};
|
|
458
|
+
if (!("defined" in value) || typeof value.defined !== "boolean") return {
|
|
459
|
+
valid: false,
|
|
460
|
+
value: void 0
|
|
461
|
+
};
|
|
462
|
+
if (value.defined) return "value" in value ? {
|
|
463
|
+
valid: true,
|
|
464
|
+
value: value["value"]
|
|
465
|
+
} : {
|
|
466
|
+
valid: false,
|
|
467
|
+
value: void 0
|
|
468
|
+
};
|
|
469
|
+
return {
|
|
470
|
+
valid: true,
|
|
471
|
+
value: void 0
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function deserializeEntries(value) {
|
|
475
|
+
const result = /* @__PURE__ */ new Map();
|
|
476
|
+
if (!Array.isArray(value)) return result;
|
|
477
|
+
for (const entry of value) {
|
|
478
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string") continue;
|
|
479
|
+
const decoded = deserializeOverrideValue(entry[1]);
|
|
480
|
+
if (decoded.valid) result.set(entry[0], decoded.value);
|
|
481
|
+
}
|
|
482
|
+
return result;
|
|
483
|
+
}
|
|
484
|
+
function serializeInstanceOverrideState(state) {
|
|
485
|
+
return {
|
|
486
|
+
self: [...state.self].map(([field, value]) => [field, serializeOverrideValue(value)]),
|
|
487
|
+
descendants: [...state.descendants].map(([nodeId, fields]) => [nodeId, [...fields].map(([field, value]) => [field, serializeOverrideValue(value)])])
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function deserializeInstanceOverrideState(state) {
|
|
491
|
+
if (!state || typeof state !== "object" || Array.isArray(state)) return createInstanceOverrideState();
|
|
492
|
+
const self = "self" in state ? deserializeEntries(state.self) : /* @__PURE__ */ new Map();
|
|
493
|
+
const descendants = /* @__PURE__ */ new Map();
|
|
494
|
+
if ("descendants" in state && Array.isArray(state.descendants)) for (const entry of state.descendants) {
|
|
495
|
+
if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string") continue;
|
|
496
|
+
descendants.set(entry[0], deserializeEntries(entry[1]));
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
self,
|
|
500
|
+
descendants
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function cloneInstanceOverrideState(state) {
|
|
504
|
+
return {
|
|
505
|
+
self: new Map([...state.self].map(([field, value]) => [field, structuredClone(value)])),
|
|
506
|
+
descendants: new Map([...state.descendants].map(([id, fields]) => [id, new Map([...fields].map(([field, value]) => [field, structuredClone(value)]))]))
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/** Remap runtime identities only; ordinary strings and source-format payloads stay opaque. */
|
|
510
|
+
function remapInstanceOverrideState(state, references) {
|
|
511
|
+
const remapValue = (field, value) => {
|
|
512
|
+
if (typeof value !== "string") return structuredClone(value);
|
|
513
|
+
if (field === "componentId" || field === "sourceComponentId") return references.node(value);
|
|
514
|
+
if (field.startsWith("boundVariables/")) return references.variable(value);
|
|
515
|
+
return value;
|
|
516
|
+
};
|
|
517
|
+
const fields = (entries) => new Map([...entries].map(([field, value]) => [field, remapValue(field, value)]));
|
|
518
|
+
const descendants = /* @__PURE__ */ new Map();
|
|
519
|
+
for (const [id, entries] of state.descendants) {
|
|
520
|
+
const mapped = references.node(id);
|
|
521
|
+
if (descendants.has(mapped)) throw new Error(`Duplicate remapped override target ${mapped}`);
|
|
522
|
+
descendants.set(mapped, fields(entries));
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
self: fields(state.self),
|
|
526
|
+
descendants
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function getInstanceOverride(state, instanceId, nodeId, field) {
|
|
530
|
+
return nodeId === instanceId ? state.self.get(field) : state.descendants.get(nodeId)?.get(field);
|
|
531
|
+
}
|
|
532
|
+
function hasInstanceOverride(state, instanceId, nodeId, field) {
|
|
533
|
+
return (nodeId === instanceId ? state.self : state.descendants.get(nodeId))?.has(field) ?? false;
|
|
534
|
+
}
|
|
535
|
+
function setInstanceOverride(state, instanceId, nodeId, field, value = true) {
|
|
536
|
+
if (nodeId === instanceId) {
|
|
537
|
+
state.self.set(field, value);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
const fields = state.descendants.get(nodeId) ?? /* @__PURE__ */ new Map();
|
|
541
|
+
fields.set(field, value);
|
|
542
|
+
state.descendants.set(nodeId, fields);
|
|
543
|
+
}
|
|
544
|
+
function deleteInstanceOverride(state, instanceId, nodeId, field) {
|
|
545
|
+
const fields = nodeId === instanceId ? state.self : state.descendants.get(nodeId);
|
|
546
|
+
if (!fields?.delete(field)) return false;
|
|
547
|
+
if (nodeId !== instanceId && fields.size === 0) state.descendants.delete(nodeId);
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
function clearInstanceOverrides(state) {
|
|
551
|
+
state.self.clear();
|
|
552
|
+
state.descendants.clear();
|
|
553
|
+
}
|
|
554
|
+
function forEachInstanceOverride(state, callback) {
|
|
555
|
+
for (const [field, value] of state.self) callback("", field, value);
|
|
556
|
+
for (const [nodeId, fields] of state.descendants) for (const [field, value] of fields) callback(nodeId, field, value);
|
|
557
|
+
}
|
|
551
558
|
//#endregion
|
|
552
559
|
//#region src/node-defaults.ts
|
|
553
560
|
function createDefaultSourceMetadata() {
|
|
@@ -569,6 +576,22 @@ function createDefaultSourceMetadata() {
|
|
|
569
576
|
}
|
|
570
577
|
};
|
|
571
578
|
}
|
|
579
|
+
/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */
|
|
580
|
+
function defaultStrokeAlign(type) {
|
|
581
|
+
if (type === "LINE" || type === "VECTOR") return "CENTER";
|
|
582
|
+
return type === "TEXT" ? "OUTSIDE" : "INSIDE";
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps
|
|
586
|
+
* with none. Adding a stroke from the panel and from the plugin API both go through here.
|
|
587
|
+
*/
|
|
588
|
+
function newStrokeGeometry(node) {
|
|
589
|
+
const first = node.strokes.at(0);
|
|
590
|
+
return {
|
|
591
|
+
weight: first?.weight ?? node.strokeWeight,
|
|
592
|
+
align: first?.align ?? node.strokeAlign
|
|
593
|
+
};
|
|
594
|
+
}
|
|
572
595
|
function createDefaultNode(generateId, type, overrides = {}) {
|
|
573
596
|
return {
|
|
574
597
|
id: generateId(),
|
|
@@ -653,6 +676,11 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
653
676
|
textDecorationSkipInk: true,
|
|
654
677
|
textUnderlineOffset: null,
|
|
655
678
|
maxLines: null,
|
|
679
|
+
textParagraphs: [],
|
|
680
|
+
listSpacing: 0,
|
|
681
|
+
paragraphSpacing: 0,
|
|
682
|
+
paragraphIndent: 0,
|
|
683
|
+
hangingList: false,
|
|
656
684
|
styleRuns: [],
|
|
657
685
|
fontVariations: [],
|
|
658
686
|
fontFeatures: [],
|
|
@@ -666,11 +694,14 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
666
694
|
borderBottomWeight: 0,
|
|
667
695
|
borderLeftWeight: 0,
|
|
668
696
|
independentStrokeWeights: false,
|
|
697
|
+
strokeWeight: 1,
|
|
698
|
+
strokeAlign: defaultStrokeAlign(type),
|
|
669
699
|
strokeMiterLimit: 4,
|
|
670
700
|
minWidth: null,
|
|
671
701
|
maxWidth: null,
|
|
672
702
|
minHeight: null,
|
|
673
703
|
maxHeight: null,
|
|
704
|
+
targetAspectRatio: null,
|
|
674
705
|
isMask: false,
|
|
675
706
|
maskType: "ALPHA",
|
|
676
707
|
maskIsOutline: false,
|
|
@@ -702,10 +733,14 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
702
733
|
librarySource: null,
|
|
703
734
|
isPublishable: false,
|
|
704
735
|
isSymbolPublishable: false,
|
|
736
|
+
isExposedInstance: false,
|
|
705
737
|
symbolDescription: "",
|
|
706
738
|
symbolLinks: [],
|
|
707
739
|
variantPropSpecs: [],
|
|
708
740
|
boundVariables: {},
|
|
741
|
+
variableBindingScales: {},
|
|
742
|
+
variableAssignmentScales: {},
|
|
743
|
+
componentScale: 1,
|
|
709
744
|
variableModes: {},
|
|
710
745
|
exportSettings: [],
|
|
711
746
|
pluginData: [],
|
|
@@ -717,9 +752,12 @@ function createDefaultNode(generateId, type, overrides = {}) {
|
|
|
717
752
|
derivedTextGlyphs: null,
|
|
718
753
|
textPathData: null,
|
|
719
754
|
textPathBox: null,
|
|
755
|
+
booleanOperation: void 0,
|
|
720
756
|
...overrides
|
|
721
757
|
};
|
|
722
758
|
}
|
|
759
|
+
/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */
|
|
760
|
+
const FITTED_CONTAINER_TYPES = /* @__PURE__ */ new Set(["GROUP", "BOOLEAN_OPERATION"]);
|
|
723
761
|
const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
724
762
|
"CANVAS",
|
|
725
763
|
"FRAME",
|
|
@@ -942,6 +980,7 @@ function normalizeVectorNetwork(vn) {
|
|
|
942
980
|
}
|
|
943
981
|
//#endregion
|
|
944
982
|
//#region src/copy.ts
|
|
983
|
+
/** Generic over the paint shape so a stroke keeps its own fields while the paint deep-copies. */
|
|
945
984
|
function copyFill(f) {
|
|
946
985
|
const copy = {
|
|
947
986
|
...f,
|
|
@@ -955,10 +994,7 @@ function copyFill(f) {
|
|
|
955
994
|
return copy;
|
|
956
995
|
}
|
|
957
996
|
function copyStroke(s) {
|
|
958
|
-
const copy =
|
|
959
|
-
...s,
|
|
960
|
-
color: { ...s.color }
|
|
961
|
-
};
|
|
997
|
+
const copy = copyFill(s);
|
|
962
998
|
if (s.dashPattern) copy.dashPattern = [...s.dashPattern];
|
|
963
999
|
return copy;
|
|
964
1000
|
}
|
|
@@ -1075,7 +1111,8 @@ function copyPropertyDefs(defs) {
|
|
|
1075
1111
|
return defs?.map((d) => ({
|
|
1076
1112
|
...d,
|
|
1077
1113
|
variantOptions: d.variantOptions ? [...d.variantOptions] : void 0,
|
|
1078
|
-
preferredValues: d.preferredValues ? [...d.preferredValues] : void 0
|
|
1114
|
+
preferredValues: d.preferredValues ? [...d.preferredValues] : void 0,
|
|
1115
|
+
slotSettings: d.slotSettings ? { ...d.slotSettings } : void 0
|
|
1079
1116
|
})) ?? [];
|
|
1080
1117
|
}
|
|
1081
1118
|
/** Deep-copy path-text glyphs (fresh commandsBlob buffers). */
|
|
@@ -1099,6 +1136,8 @@ function cloneNodeProps(src, componentId, mode = "deep") {
|
|
|
1099
1136
|
...componentId !== null ? { componentId } : {},
|
|
1100
1137
|
source: createDefaultSourceMetadata(),
|
|
1101
1138
|
boundVariables: { ...src.boundVariables },
|
|
1139
|
+
variableBindingScales: { ...src.variableBindingScales },
|
|
1140
|
+
variableAssignmentScales: { ...src.variableAssignmentScales },
|
|
1102
1141
|
variableModes: { ...src.variableModes },
|
|
1103
1142
|
instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),
|
|
1104
1143
|
componentPropertyAssignments: { ...src.componentPropertyAssignments },
|
|
@@ -1108,6 +1147,8 @@ function cloneNodeProps(src, componentId, mode = "deep") {
|
|
|
1108
1147
|
...rest,
|
|
1109
1148
|
...componentId !== null ? { componentId } : {},
|
|
1110
1149
|
boundVariables: { ...src.boundVariables },
|
|
1150
|
+
variableBindingScales: { ...src.variableBindingScales },
|
|
1151
|
+
variableAssignmentScales: { ...src.variableAssignmentScales },
|
|
1111
1152
|
variableModes: { ...src.variableModes },
|
|
1112
1153
|
instanceOverrides: cloneInstanceOverrideState(src.instanceOverrides),
|
|
1113
1154
|
fills: copyOpt(src.fills, (value) => markCopySource(value, copyFills(value))),
|
|
@@ -1120,6 +1161,7 @@ function cloneNodeProps(src, componentId, mode = "deep") {
|
|
|
1120
1161
|
dashPattern: copyOpt(src.dashPattern, (a) => [...a]),
|
|
1121
1162
|
fontVariations: copyOpt(src.fontVariations, (a) => a.map((v) => ({ ...v }))),
|
|
1122
1163
|
fontFeatures: copyOpt(src.fontFeatures, (a) => a.map((v) => ({ ...v }))),
|
|
1164
|
+
textParagraphs: copyOpt(src.textParagraphs, (a) => a.map((v) => ({ ...v }))),
|
|
1123
1165
|
textDecorationFills: copyOpt(src.textDecorationFills, copyFills),
|
|
1124
1166
|
fillGeometry: copyOpt(src.fillGeometry, copyGeometryPaths),
|
|
1125
1167
|
strokeGeometry: copyOpt(src.strokeGeometry, copyGeometryPaths),
|
|
@@ -1141,431 +1183,441 @@ function cloneNodeProps(src, componentId, mode = "deep") {
|
|
|
1141
1183
|
derivedTextGlyphs: src.derivedTextGlyphs ? markCopySource(src.derivedTextGlyphs, copyDerivedGlyphs(src.derivedTextGlyphs) ?? []) : null,
|
|
1142
1184
|
textPathData: src.textPathData ? structuredClone(src.textPathData) : null,
|
|
1143
1185
|
textPathBox: src.textPathBox ? { ...src.textPathBox } : null,
|
|
1144
|
-
gridPosition: src.gridPosition ? { ...src.gridPosition } : null
|
|
1186
|
+
gridPosition: src.gridPosition ? { ...src.gridPosition } : null,
|
|
1187
|
+
targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null
|
|
1145
1188
|
};
|
|
1146
1189
|
}
|
|
1147
1190
|
//#endregion
|
|
1148
|
-
//#region src/
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
const INSTANCE_SYNC_PROPS = [
|
|
1158
|
-
"width",
|
|
1159
|
-
"height",
|
|
1160
|
-
"minWidth",
|
|
1161
|
-
"maxWidth",
|
|
1162
|
-
"minHeight",
|
|
1163
|
-
"maxHeight",
|
|
1164
|
-
"fills",
|
|
1165
|
-
"strokes",
|
|
1166
|
-
"effects",
|
|
1167
|
-
"opacity",
|
|
1168
|
-
"cornerRadius",
|
|
1169
|
-
"topLeftRadius",
|
|
1170
|
-
"topRightRadius",
|
|
1171
|
-
"bottomRightRadius",
|
|
1172
|
-
"bottomLeftRadius",
|
|
1173
|
-
"independentCorners",
|
|
1174
|
-
"layoutMode",
|
|
1175
|
-
"layoutDirection",
|
|
1176
|
-
"layoutWrap",
|
|
1177
|
-
"primaryAxisAlign",
|
|
1178
|
-
"counterAxisAlign",
|
|
1179
|
-
"primaryAxisSizing",
|
|
1180
|
-
"counterAxisSizing",
|
|
1181
|
-
"itemSpacing",
|
|
1182
|
-
"counterAxisSpacing",
|
|
1183
|
-
"paddingTop",
|
|
1184
|
-
"paddingRight",
|
|
1185
|
-
"paddingBottom",
|
|
1186
|
-
"paddingLeft",
|
|
1187
|
-
"gridTemplateColumns",
|
|
1188
|
-
"gridTemplateRows",
|
|
1189
|
-
"gridColumnGap",
|
|
1190
|
-
"gridRowGap",
|
|
1191
|
-
"gridPosition",
|
|
1192
|
-
"clipsContent",
|
|
1193
|
-
"independentStrokeWeights",
|
|
1194
|
-
"borderTopWeight",
|
|
1195
|
-
"borderRightWeight",
|
|
1196
|
-
"borderBottomWeight",
|
|
1197
|
-
"borderLeftWeight",
|
|
1198
|
-
"boundVariables",
|
|
1199
|
-
"variableModes"
|
|
1200
|
-
];
|
|
1201
|
-
const INSTANCE_SYNC_FIELDS = [...INSTANCE_SYNC_PROPS, ...INSTANCE_SYNC_TEXT_PROPS];
|
|
1202
|
-
function setSceneProp(target, key, value) {
|
|
1203
|
-
target[key] = value;
|
|
1204
|
-
}
|
|
1205
|
-
function copyProp(target, source, key) {
|
|
1206
|
-
if (key === "fills") setSceneProp(target, key, copyFills(source.fills));
|
|
1207
|
-
else if (key === "strokes") setSceneProp(target, key, copyStrokes(source.strokes));
|
|
1208
|
-
else if (key === "effects") setSceneProp(target, key, copyEffects(source.effects));
|
|
1209
|
-
else if (key === "styleRuns") setSceneProp(target, key, copyStyleRuns(source.styleRuns));
|
|
1210
|
-
else if (key === "boundVariables") setSceneProp(target, key, { ...source.boundVariables });
|
|
1211
|
-
else if (key === "variableModes") setSceneProp(target, key, { ...source.variableModes });
|
|
1212
|
-
else if (key === "gridPosition") setSceneProp(target, key, source.gridPosition ? { ...source.gridPosition } : null);
|
|
1213
|
-
else {
|
|
1214
|
-
const value = source[key];
|
|
1215
|
-
setSceneProp(target, key, Array.isArray(value) ? structuredClone(value) : value);
|
|
1216
|
-
}
|
|
1191
|
+
//#region src/color/normalize.ts
|
|
1192
|
+
function normalizeColor(color) {
|
|
1193
|
+
if (!color) return { ...BLACK };
|
|
1194
|
+
return {
|
|
1195
|
+
r: color.r ?? 0,
|
|
1196
|
+
g: color.g ?? 0,
|
|
1197
|
+
b: color.b ?? 0,
|
|
1198
|
+
a: color.a ?? 1
|
|
1199
|
+
};
|
|
1217
1200
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1201
|
+
//#endregion
|
|
1202
|
+
//#region src/color/okhcl.ts
|
|
1203
|
+
const toRGB$2 = converter("rgb");
|
|
1204
|
+
const toP3$1 = converter("p3");
|
|
1205
|
+
const toOkHCL = converter("oklch");
|
|
1206
|
+
const toDisplayableRGB$1 = toGamut("rgb", "oklch");
|
|
1207
|
+
const toDisplayableP3$1 = toGamut("p3", "oklch");
|
|
1208
|
+
function clampUnit(value) {
|
|
1209
|
+
if (value < 0) return 0;
|
|
1210
|
+
if (value > 1) return 1;
|
|
1211
|
+
return value;
|
|
1212
|
+
}
|
|
1213
|
+
function normalizeHue(value) {
|
|
1214
|
+
const hue = value % 360;
|
|
1215
|
+
return hue < 0 ? hue + 360 : hue;
|
|
1216
|
+
}
|
|
1217
|
+
function normalizeOkHCLColor(color) {
|
|
1218
|
+
return {
|
|
1219
|
+
h: normalizeHue(color.h),
|
|
1220
|
+
c: Math.max(0, color.c),
|
|
1221
|
+
l: clampUnit(color.l),
|
|
1222
|
+
a: clampUnit(color.a ?? 1)
|
|
1223
|
+
};
|
|
1228
1224
|
}
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
if (!byName) {
|
|
1248
|
-
byName = /* @__PURE__ */ new Map();
|
|
1249
|
-
fallbackByType.set(child.type, byName);
|
|
1250
|
-
}
|
|
1251
|
-
const queue = byName.get(child.name);
|
|
1252
|
-
if (queue) queue.push(child);
|
|
1253
|
-
else byName.set(child.name, [child]);
|
|
1254
|
-
}
|
|
1255
|
-
for (const compChildId of compParent.childIds) {
|
|
1256
|
-
if (instChildMap.has(compChildId)) continue;
|
|
1257
|
-
const compChild = graph.nodes.get(compChildId);
|
|
1258
|
-
if (!compChild) continue;
|
|
1259
|
-
const candidatesByName = fallbackByType.get(compChild.type);
|
|
1260
|
-
const candidateCount = remainingCandidateCount.get(compChild.type) ?? 0;
|
|
1261
|
-
if (candidateCount > (unmatchedComponentCount.get(compChild.type) ?? 0)) continue;
|
|
1262
|
-
const match = candidatesByName?.get(compChild.name)?.shift();
|
|
1263
|
-
if (!match) continue;
|
|
1264
|
-
remainingCandidateCount.set(compChild.type, candidateCount - 1);
|
|
1265
|
-
instChildMap.set(compChildId, match);
|
|
1266
|
-
usedInstChildIds.add(match.id);
|
|
1267
|
-
linkMatchedChild(overrides, instParentId, match, compChildId);
|
|
1225
|
+
/** Coordinates in `colorSpace`, so callers can store colours in the document's profile. */
|
|
1226
|
+
function okhclToRGBA(color, colorSpace = "srgb") {
|
|
1227
|
+
const normalized = normalizeOkHCLColor(color);
|
|
1228
|
+
const oklch = {
|
|
1229
|
+
mode: "oklch",
|
|
1230
|
+
l: normalized.l,
|
|
1231
|
+
c: normalized.c,
|
|
1232
|
+
h: normalized.h,
|
|
1233
|
+
alpha: normalized.a
|
|
1234
|
+
};
|
|
1235
|
+
if (colorSpace === "display-p3") {
|
|
1236
|
+
const p3 = toP3$1(toDisplayableP3$1(oklch));
|
|
1237
|
+
return normalizeColor({
|
|
1238
|
+
r: p3.r,
|
|
1239
|
+
g: p3.g,
|
|
1240
|
+
b: p3.b,
|
|
1241
|
+
a: p3.alpha ?? normalized.a
|
|
1242
|
+
});
|
|
1268
1243
|
}
|
|
1244
|
+
const rgb = toRGB$2(toDisplayableRGB$1(oklch));
|
|
1245
|
+
return normalizeColor({
|
|
1246
|
+
r: rgb.r,
|
|
1247
|
+
g: rgb.g,
|
|
1248
|
+
b: rgb.b,
|
|
1249
|
+
a: rgb.alpha ?? normalized.a
|
|
1250
|
+
});
|
|
1269
1251
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
matchFallbackChildren(graph, compParent, instParent, instParentId, overrides, instChildMap, usedInstChildIds);
|
|
1307
|
-
for (const compChildId of compParent.childIds) if (!instChildMap.has(compChildId)) {
|
|
1308
|
-
const src = graph.nodes.get(compChildId);
|
|
1309
|
-
if (!src) continue;
|
|
1310
|
-
const clone = graph.createNode(src.type, instParentId, cloneNodeProps(src, compChildId));
|
|
1311
|
-
if (src.childIds.length > 0) cloneChildrenWithMapping(graph, compChildId, clone.id);
|
|
1312
|
-
instChildMap.set(compChildId, clone);
|
|
1313
|
-
usedInstChildIds.add(clone.id);
|
|
1314
|
-
}
|
|
1315
|
-
for (const compChildId of compParent.childIds) {
|
|
1316
|
-
const compChild = graph.nodes.get(compChildId);
|
|
1317
|
-
const instChild = instChildMap.get(compChildId);
|
|
1318
|
-
if (!compChild || !instChild) continue;
|
|
1319
|
-
for (const key of INSTANCE_SYNC_FIELDS) {
|
|
1320
|
-
if (hasInstanceOverride$1(overrides, instParentId, instChild.id, key)) continue;
|
|
1321
|
-
copyProp(instChild, compChild, key);
|
|
1322
|
-
}
|
|
1323
|
-
if (compChild.childIds.length > 0 && !hasInstanceOverride$1(overrides, instParentId, instChild.id, "componentId")) syncChildren(graph, compChildId, instChild.id, overrides);
|
|
1324
|
-
}
|
|
1325
|
-
sortInstanceChildren(graph, instParent, instParentId, compParent.childIds, overrides);
|
|
1326
|
-
}
|
|
1327
|
-
function copyInstanceComponentProps(component) {
|
|
1328
|
-
const props = {};
|
|
1329
|
-
for (const key of INSTANCE_SYNC_PROPS) copyProp(props, component, key);
|
|
1330
|
-
return props;
|
|
1331
|
-
}
|
|
1332
|
-
function createInstance(graph, componentId, parentId, overrides = {}) {
|
|
1333
|
-
const component = graph.nodes.get(componentId);
|
|
1334
|
-
if (component?.type !== "COMPONENT") return null;
|
|
1335
|
-
const props = {
|
|
1336
|
-
...copyInstanceComponentProps(component),
|
|
1337
|
-
name: component.name,
|
|
1338
|
-
componentId
|
|
1252
|
+
/** Reads `color` as coordinates in `colorSpace`, the inverse of {@link okhclToRGBA}. */
|
|
1253
|
+
function rgbaToOkHCL(color, colorSpace = "srgb") {
|
|
1254
|
+
const oklch = toOkHCL(colorSpace === "display-p3" ? {
|
|
1255
|
+
mode: "p3",
|
|
1256
|
+
r: color.r,
|
|
1257
|
+
g: color.g,
|
|
1258
|
+
b: color.b,
|
|
1259
|
+
alpha: color.a
|
|
1260
|
+
} : {
|
|
1261
|
+
mode: "rgb",
|
|
1262
|
+
r: color.r,
|
|
1263
|
+
g: color.g,
|
|
1264
|
+
b: color.b,
|
|
1265
|
+
alpha: color.a
|
|
1266
|
+
});
|
|
1267
|
+
return normalizeOkHCLColor({
|
|
1268
|
+
h: oklch.h ?? 0,
|
|
1269
|
+
c: oklch.c,
|
|
1270
|
+
l: oklch.l,
|
|
1271
|
+
a: oklch.alpha ?? color.a
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
function serializeOkHCLPayload(payload) {
|
|
1275
|
+
return OPEN_PENCIL_PLUGIN_DATA.okhcl.encode(payload);
|
|
1276
|
+
}
|
|
1277
|
+
function parseOkHCLPayload(value) {
|
|
1278
|
+
return OPEN_PENCIL_PLUGIN_DATA.okhcl.decode(value) ?? null;
|
|
1279
|
+
}
|
|
1280
|
+
function createOkHCLPayload(kind, index, color) {
|
|
1281
|
+
return {
|
|
1282
|
+
version: 1,
|
|
1283
|
+
kind,
|
|
1284
|
+
index,
|
|
1285
|
+
color: normalizeOkHCLColor(color)
|
|
1339
1286
|
};
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1287
|
+
}
|
|
1288
|
+
/** The node's plugin data with the payload for one paint replaced, or removed without `color`. */
|
|
1289
|
+
function withOkHCLPayload(node, kind, index, color) {
|
|
1290
|
+
const payloads = getNodeOkHCLPayloads(node).filter((payload) => payload.kind !== kind || payload.index !== index);
|
|
1291
|
+
if (color) payloads.push(createOkHCLPayload(kind, index, color));
|
|
1292
|
+
return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl, payloads);
|
|
1293
|
+
}
|
|
1294
|
+
function setNodeFillOkHCL(node, index, color, colorSpace = "srgb") {
|
|
1295
|
+
const fills = node.fills.map(copyFill);
|
|
1296
|
+
if (index < 0 || index >= fills.length) throw new Error(`Fill ${index} not found`);
|
|
1297
|
+
const fill = fills[index];
|
|
1298
|
+
const rgba = okhclToRGBA(color, colorSpace);
|
|
1299
|
+
fills[index] = {
|
|
1300
|
+
...fill,
|
|
1301
|
+
color: rgba,
|
|
1302
|
+
opacity: rgba.a
|
|
1303
|
+
};
|
|
1304
|
+
return {
|
|
1305
|
+
fills,
|
|
1306
|
+
pluginData: withOkHCLPayload(node, "fill", index, color)
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
function setNodeStrokeOkHCL(node, index, color, colorSpace = "srgb") {
|
|
1310
|
+
const strokes = node.strokes.map(copyStroke);
|
|
1311
|
+
if (index < 0 || index >= strokes.length) throw new Error(`Stroke ${index} not found`);
|
|
1312
|
+
const stroke = strokes[index];
|
|
1313
|
+
const rgba = okhclToRGBA(color, colorSpace);
|
|
1314
|
+
strokes[index] = {
|
|
1315
|
+
...stroke,
|
|
1316
|
+
color: rgba,
|
|
1317
|
+
opacity: rgba.a
|
|
1318
|
+
};
|
|
1319
|
+
return {
|
|
1320
|
+
strokes,
|
|
1321
|
+
pluginData: withOkHCLPayload(node, "stroke", index, color)
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
function clearNodeFillOkHCL(node, index) {
|
|
1325
|
+
return { pluginData: withOkHCLPayload(node, "fill", index) };
|
|
1326
|
+
}
|
|
1327
|
+
function clearNodeStrokeOkHCL(node, index) {
|
|
1328
|
+
return { pluginData: withOkHCLPayload(node, "stroke", index) };
|
|
1329
|
+
}
|
|
1330
|
+
function getNodeOkHCLPayloads(node) {
|
|
1331
|
+
return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.okhcl);
|
|
1332
|
+
}
|
|
1333
|
+
function getFillOkHCL(node, index) {
|
|
1334
|
+
return getNodeOkHCLPayloads(node).find((payload) => payload.kind === "fill" && payload.index === index) ?? null;
|
|
1335
|
+
}
|
|
1336
|
+
function getStrokeOkHCL(node, index) {
|
|
1337
|
+
return getNodeOkHCLPayloads(node).find((payload) => payload.kind === "stroke" && payload.index === index) ?? null;
|
|
1338
|
+
}
|
|
1339
|
+
//#endregion
|
|
1340
|
+
//#region src/color/management.ts
|
|
1341
|
+
const DEFAULT_COLOR_SPACE = "srgb";
|
|
1342
|
+
const toRGB$1 = converter("rgb");
|
|
1343
|
+
const toP3 = converter("p3");
|
|
1344
|
+
const toDisplayableRGB = toGamut("rgb", "oklch");
|
|
1345
|
+
const toDisplayableP3 = toGamut("p3", "oklch");
|
|
1346
|
+
const isDisplayableRGB = inGamut("rgb");
|
|
1347
|
+
const isDisplayableP3 = inGamut("p3");
|
|
1348
|
+
function normalizeOkLCH(color) {
|
|
1349
|
+
const hue = color.h % 360;
|
|
1350
|
+
return {
|
|
1351
|
+
mode: "oklch",
|
|
1352
|
+
l: Math.max(0, Math.min(1, color.l)),
|
|
1353
|
+
c: Math.max(0, color.c),
|
|
1354
|
+
h: hue < 0 ? hue + 360 : hue,
|
|
1355
|
+
alpha: Math.max(0, Math.min(1, color.a ?? 1))
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Numbers are stored in the document's profile, so painting into a surface with a different
|
|
1360
|
+
* profile has to convert them. Same profile means no work, which is the common case.
|
|
1361
|
+
*/
|
|
1362
|
+
function convertComponents(color, from, to) {
|
|
1363
|
+
if (from === to) return color;
|
|
1364
|
+
const source = from === "display-p3" ? {
|
|
1365
|
+
mode: "p3",
|
|
1366
|
+
r: color.r,
|
|
1367
|
+
g: color.g,
|
|
1368
|
+
b: color.b,
|
|
1369
|
+
alpha: color.a
|
|
1370
|
+
} : {
|
|
1371
|
+
mode: "rgb",
|
|
1372
|
+
r: color.r,
|
|
1373
|
+
g: color.g,
|
|
1374
|
+
b: color.b,
|
|
1375
|
+
alpha: color.a
|
|
1376
|
+
};
|
|
1377
|
+
const converted = to === "display-p3" ? toP3(source) : toRGB$1(source);
|
|
1378
|
+
return normalizeColor({
|
|
1379
|
+
r: converted.r,
|
|
1380
|
+
g: converted.g,
|
|
1381
|
+
b: converted.b,
|
|
1382
|
+
a: converted.alpha ?? color.a
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
function isOutsideGamut(color, space) {
|
|
1386
|
+
if (space === "display-p3") return !isDisplayableP3({
|
|
1387
|
+
mode: "p3",
|
|
1388
|
+
r: color.r,
|
|
1389
|
+
g: color.g,
|
|
1390
|
+
b: color.b,
|
|
1391
|
+
alpha: color.a
|
|
1392
|
+
});
|
|
1393
|
+
return !isDisplayableRGB({
|
|
1394
|
+
mode: "rgb",
|
|
1395
|
+
r: color.r,
|
|
1396
|
+
g: color.g,
|
|
1397
|
+
b: color.b,
|
|
1398
|
+
alpha: color.a
|
|
1343
1399
|
});
|
|
1344
|
-
cloneChildrenWithMapping(graph, component.id, instance.id);
|
|
1345
|
-
return instance;
|
|
1346
|
-
}
|
|
1347
|
-
function populateInstanceChildren(graph, instanceId, componentId, mode = "deep") {
|
|
1348
|
-
const instance = graph.nodes.get(instanceId);
|
|
1349
|
-
const component = graph.nodes.get(componentId);
|
|
1350
|
-
if (!instance || !component || instance.type !== "INSTANCE") return;
|
|
1351
|
-
cloneChildrenWithMapping(graph, componentId, instanceId, mode);
|
|
1352
|
-
}
|
|
1353
|
-
function swapInstanceComponent(graph, instanceId, componentId) {
|
|
1354
|
-
const instance = graph.nodes.get(instanceId);
|
|
1355
|
-
const component = graph.nodes.get(componentId);
|
|
1356
|
-
if (!instance || component?.type !== "COMPONENT" || instance.type !== "INSTANCE") return;
|
|
1357
|
-
const previousComponent = instance.componentId ? graph.nodes.get(instance.componentId) : void 0;
|
|
1358
|
-
const updates = { componentId };
|
|
1359
|
-
for (const key of INSTANCE_SYNC_PROPS) {
|
|
1360
|
-
if (hasInstanceOverride$1(instance.instanceOverrides, instance.id, instance.id, key)) continue;
|
|
1361
|
-
copyProp(updates, component, key);
|
|
1362
|
-
}
|
|
1363
|
-
if (!previousComponent || instance.name === previousComponent.name) updates.name = component.name;
|
|
1364
|
-
const childIds = Array.from(instance.childIds);
|
|
1365
|
-
for (const childId of childIds) graph.deleteNode(childId);
|
|
1366
|
-
graph.updateNode(instanceId, updates);
|
|
1367
|
-
cloneChildrenWithMapping(graph, componentId, instanceId);
|
|
1368
|
-
}
|
|
1369
|
-
const syncingComponentsByGraph = /* @__PURE__ */ new WeakMap();
|
|
1370
|
-
function syncInstances(graph, componentId) {
|
|
1371
|
-
const component = graph.nodes.get(componentId);
|
|
1372
|
-
if (component?.type !== "COMPONENT") return;
|
|
1373
|
-
let syncing = syncingComponentsByGraph.get(graph);
|
|
1374
|
-
if (!syncing) {
|
|
1375
|
-
syncing = /* @__PURE__ */ new Set();
|
|
1376
|
-
syncingComponentsByGraph.set(graph, syncing);
|
|
1377
|
-
}
|
|
1378
|
-
if (syncing.has(componentId)) return;
|
|
1379
|
-
syncing.add(componentId);
|
|
1380
|
-
try {
|
|
1381
|
-
for (const instance of getInstances(graph, componentId)) {
|
|
1382
|
-
for (const key of INSTANCE_SYNC_PROPS) {
|
|
1383
|
-
if (hasInstanceOverride$1(instance.instanceOverrides, instance.id, instance.id, key)) continue;
|
|
1384
|
-
copyProp(instance, component, key);
|
|
1385
|
-
}
|
|
1386
|
-
syncChildren(graph, component.id, instance.id, instance.instanceOverrides);
|
|
1387
|
-
}
|
|
1388
|
-
} finally {
|
|
1389
|
-
syncing.delete(componentId);
|
|
1390
|
-
}
|
|
1391
1400
|
}
|
|
1392
|
-
function
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
if (node) instances.push(node);
|
|
1401
|
+
function resolveTargetSpace(options) {
|
|
1402
|
+
return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE;
|
|
1403
|
+
}
|
|
1404
|
+
function formatCSSForTarget(color, targetSpace) {
|
|
1405
|
+
if (targetSpace === "display-p3") {
|
|
1406
|
+
const p3 = toP3({
|
|
1407
|
+
mode: "rgb",
|
|
1408
|
+
r: color.r,
|
|
1409
|
+
g: color.g,
|
|
1410
|
+
b: color.b,
|
|
1411
|
+
alpha: color.a
|
|
1412
|
+
});
|
|
1413
|
+
return formatCss({
|
|
1414
|
+
mode: "p3",
|
|
1415
|
+
r: p3.r,
|
|
1416
|
+
g: p3.g,
|
|
1417
|
+
b: p3.b,
|
|
1418
|
+
alpha: p3.alpha ?? color.a
|
|
1419
|
+
});
|
|
1412
1420
|
}
|
|
1413
|
-
return
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
+
return formatRgb({
|
|
1422
|
+
mode: "rgb",
|
|
1423
|
+
r: color.r,
|
|
1424
|
+
g: color.g,
|
|
1425
|
+
b: color.b,
|
|
1426
|
+
alpha: color.a
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
function resolveOkHCLForPreview(color, options) {
|
|
1430
|
+
const oklch = normalizeOkLCH(color);
|
|
1431
|
+
const targetSpace = resolveTargetSpace(options);
|
|
1432
|
+
if (targetSpace === "display-p3") {
|
|
1433
|
+
const clipped = !isDisplayableP3(oklch);
|
|
1434
|
+
const p3 = toP3(toDisplayableP3(oklch));
|
|
1435
|
+
return {
|
|
1436
|
+
color: normalizeColor({
|
|
1437
|
+
r: p3.r,
|
|
1438
|
+
g: p3.g,
|
|
1439
|
+
b: p3.b,
|
|
1440
|
+
a: p3.alpha ?? oklch.alpha
|
|
1441
|
+
}),
|
|
1442
|
+
cssColor: formatCss({
|
|
1443
|
+
mode: "p3",
|
|
1444
|
+
r: p3.r,
|
|
1445
|
+
g: p3.g,
|
|
1446
|
+
b: p3.b,
|
|
1447
|
+
alpha: p3.alpha ?? oklch.alpha
|
|
1448
|
+
}),
|
|
1449
|
+
sourceSpace: "oklch",
|
|
1450
|
+
targetSpace,
|
|
1451
|
+
clipped
|
|
1452
|
+
};
|
|
1421
1453
|
}
|
|
1454
|
+
const clipped = !isDisplayableRGB(oklch);
|
|
1455
|
+
const rgb = toRGB$1(toDisplayableRGB(oklch));
|
|
1456
|
+
const resolved = normalizeColor({
|
|
1457
|
+
r: rgb.r,
|
|
1458
|
+
g: rgb.g,
|
|
1459
|
+
b: rgb.b,
|
|
1460
|
+
a: rgb.alpha ?? oklch.alpha
|
|
1461
|
+
});
|
|
1462
|
+
return {
|
|
1463
|
+
color: resolved,
|
|
1464
|
+
cssColor: formatRgb({
|
|
1465
|
+
mode: "rgb",
|
|
1466
|
+
r: resolved.r,
|
|
1467
|
+
g: resolved.g,
|
|
1468
|
+
b: resolved.b,
|
|
1469
|
+
alpha: resolved.a
|
|
1470
|
+
}),
|
|
1471
|
+
sourceSpace: "oklch",
|
|
1472
|
+
targetSpace,
|
|
1473
|
+
clipped
|
|
1474
|
+
};
|
|
1422
1475
|
}
|
|
1423
1476
|
/**
|
|
1424
|
-
*
|
|
1477
|
+
* A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing
|
|
1478
|
+
* chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing
|
|
1479
|
+
* (`none`) component reads as zero. Null when `input` is not a color.
|
|
1425
1480
|
*/
|
|
1426
|
-
function
|
|
1427
|
-
const
|
|
1428
|
-
if (!
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
}
|
|
1437
|
-
function
|
|
1438
|
-
const
|
|
1439
|
-
|
|
1440
|
-
const
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1481
|
+
function parseDisplayableColor(input) {
|
|
1482
|
+
const parsed = parse(input);
|
|
1483
|
+
if (!parsed) return null;
|
|
1484
|
+
const rgb = isDisplayableRGB(parsed) ? toRGB$1(parsed) : toDisplayableRGB(parsed);
|
|
1485
|
+
return normalizeColor({
|
|
1486
|
+
r: rgb.r,
|
|
1487
|
+
g: rgb.g,
|
|
1488
|
+
b: rgb.b,
|
|
1489
|
+
a: parsed.alpha
|
|
1490
|
+
});
|
|
1491
|
+
}
|
|
1492
|
+
function resolveRGBAForPreview(color, options) {
|
|
1493
|
+
const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE;
|
|
1494
|
+
const targetSpace = options?.colorSpace ?? documentColorSpace;
|
|
1495
|
+
const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace);
|
|
1496
|
+
return {
|
|
1497
|
+
color: resolved,
|
|
1498
|
+
cssColor: formatCSSForTarget(resolved, targetSpace),
|
|
1499
|
+
sourceSpace: "srgb",
|
|
1500
|
+
targetSpace,
|
|
1501
|
+
clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function resolveNodeFillColor(fill, fillIndex, node, options) {
|
|
1505
|
+
const okhcl = getFillOkHCL(node, fillIndex)?.color;
|
|
1506
|
+
if (okhcl) return resolveOkHCLForPreview(okhcl, options);
|
|
1507
|
+
return resolveRGBAForPreview(fill.color, options);
|
|
1508
|
+
}
|
|
1509
|
+
function resolveNodeStrokeColor(stroke, strokeIndex, node, options) {
|
|
1510
|
+
const okhcl = getStrokeOkHCL(node, strokeIndex)?.color;
|
|
1511
|
+
if (okhcl) return resolveOkHCLForPreview(okhcl, options);
|
|
1512
|
+
return resolveRGBAForPreview(stroke.color, options);
|
|
1513
|
+
}
|
|
1514
|
+
function colorToDisplayCSS(color, options) {
|
|
1515
|
+
return resolveRGBAForPreview(color, options).cssColor;
|
|
1516
|
+
}
|
|
1517
|
+
function getDefaultRenderColorSpace() {
|
|
1518
|
+
return DEFAULT_COLOR_SPACE;
|
|
1444
1519
|
}
|
|
1445
1520
|
//#endregion
|
|
1446
|
-
//#region src/
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
}
|
|
1459
|
-
function resolveComponentPropertyValue(graph, value) {
|
|
1460
|
-
const direct = graph.getNode(value);
|
|
1461
|
-
if (direct?.type === "COMPONENT") return direct;
|
|
1462
|
-
if (direct?.type === "COMPONENT_SET") {
|
|
1463
|
-
const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === "COMPONENT");
|
|
1464
|
-
return componentId ? graph.getNode(componentId) ?? null : null;
|
|
1465
|
-
}
|
|
1466
|
-
for (const node of graph.getAllNodes()) if (node.type === "COMPONENT" && (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)) return node;
|
|
1467
|
-
return null;
|
|
1521
|
+
//#region src/color/index.ts
|
|
1522
|
+
const toRGB = converter("rgb");
|
|
1523
|
+
/** A CSS color, or null when `input` is not one. */
|
|
1524
|
+
function tryParseColor(input) {
|
|
1525
|
+
const parsed = parse(input);
|
|
1526
|
+
if (!parsed) return null;
|
|
1527
|
+
const rgb = toRGB(parsed);
|
|
1528
|
+
return {
|
|
1529
|
+
r: rgb.r,
|
|
1530
|
+
g: rgb.g,
|
|
1531
|
+
b: rgb.b,
|
|
1532
|
+
a: parsed.alpha ?? 1
|
|
1533
|
+
};
|
|
1468
1534
|
}
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1535
|
+
/** A CSS color, or black when `input` is not one. */
|
|
1536
|
+
function parseColor(input) {
|
|
1537
|
+
return tryParseColor(input) ?? { ...BLACK };
|
|
1538
|
+
}
|
|
1539
|
+
function colorToHex(color) {
|
|
1540
|
+
return formatHex({
|
|
1541
|
+
mode: "rgb",
|
|
1542
|
+
r: color.r,
|
|
1543
|
+
g: color.g,
|
|
1544
|
+
b: color.b
|
|
1545
|
+
}).toUpperCase();
|
|
1546
|
+
}
|
|
1547
|
+
function colorToHex8(color, alpha) {
|
|
1548
|
+
const a = alpha ?? color.a;
|
|
1549
|
+
if (a >= 1) return colorToHex(color);
|
|
1550
|
+
return formatHex8({
|
|
1551
|
+
mode: "rgb",
|
|
1552
|
+
r: color.r,
|
|
1553
|
+
g: color.g,
|
|
1554
|
+
b: color.b,
|
|
1555
|
+
alpha: a
|
|
1556
|
+
}).toUpperCase();
|
|
1557
|
+
}
|
|
1558
|
+
function colorToHexRaw(color) {
|
|
1559
|
+
return colorToHex(color).slice(1);
|
|
1560
|
+
}
|
|
1561
|
+
function colorToRgba255(color) {
|
|
1562
|
+
return {
|
|
1563
|
+
r: Math.round(color.r * 255),
|
|
1564
|
+
g: Math.round(color.g * 255),
|
|
1565
|
+
b: Math.round(color.b * 255),
|
|
1566
|
+
a: color.a
|
|
1491
1567
|
};
|
|
1492
|
-
visit(component, instance);
|
|
1493
|
-
return targets;
|
|
1494
|
-
}
|
|
1495
|
-
function applyTextProperty(graph, owner, targets, value) {
|
|
1496
|
-
for (const item of targets) {
|
|
1497
|
-
if (item.field !== "TEXT" || item.node.type !== "TEXT") continue;
|
|
1498
|
-
graph.updateNode(item.node.id, { text: value });
|
|
1499
|
-
if (findInstanceAncestor(graph, item.node.id)) setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "text", value);
|
|
1500
|
-
}
|
|
1501
1568
|
}
|
|
1502
|
-
function
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1569
|
+
function colorToCSS(color) {
|
|
1570
|
+
return formatRgb({
|
|
1571
|
+
mode: "rgb",
|
|
1572
|
+
r: color.r,
|
|
1573
|
+
g: color.g,
|
|
1574
|
+
b: color.b,
|
|
1575
|
+
alpha: color.a
|
|
1576
|
+
});
|
|
1509
1577
|
}
|
|
1510
|
-
function
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "componentId", target.id);
|
|
1516
|
-
setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "sourceComponentId", item.source.id);
|
|
1517
|
-
graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides });
|
|
1518
|
-
}
|
|
1578
|
+
function colorToCSSCompact(color) {
|
|
1579
|
+
const { r, g, b } = colorToRgba255(color);
|
|
1580
|
+
const a = Number(color.a.toFixed(3));
|
|
1581
|
+
if (a >= 1) return `rgb(${r},${g},${b})`;
|
|
1582
|
+
return `rgba(${r},${g},${b},${a})`;
|
|
1519
1583
|
}
|
|
1520
|
-
function
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
if (definition.type === "INSTANCE_SWAP" && !target) return null;
|
|
1527
|
-
if (definition.type === "TEXT") applyTextProperty(graph, instance, targets, value);
|
|
1528
|
-
else if (definition.type === "BOOLEAN") applyBooleanProperty(graph, instance, targets, value);
|
|
1529
|
-
else if (target) applyInstanceSwapProperty(graph, instance, targets, target);
|
|
1530
|
-
graph.updateNode(instance.id, { componentPropertyAssignments: {
|
|
1531
|
-
...instance.componentPropertyAssignments,
|
|
1532
|
-
[definition.id]: definition.type === "INSTANCE_SWAP" && target ? target.id : value
|
|
1533
|
-
} });
|
|
1534
|
-
return definition.type === "INSTANCE_SWAP" ? target : instance;
|
|
1535
|
-
}
|
|
1536
|
-
function componentSubtree(graph, componentId) {
|
|
1537
|
-
const component = graph.getNode(componentId);
|
|
1538
|
-
if (!component) return [];
|
|
1539
|
-
const nodes = [component];
|
|
1540
|
-
const visit = (node) => {
|
|
1541
|
-
for (const child of graph.getChildren(node.id)) {
|
|
1542
|
-
nodes.push(child);
|
|
1543
|
-
visit(child);
|
|
1544
|
-
}
|
|
1584
|
+
function rgba255ToColor(r, g, b, a = 1) {
|
|
1585
|
+
return {
|
|
1586
|
+
r: r / 255,
|
|
1587
|
+
g: g / 255,
|
|
1588
|
+
b: b / 255,
|
|
1589
|
+
a
|
|
1545
1590
|
};
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1591
|
+
}
|
|
1592
|
+
function colorToFill(color) {
|
|
1593
|
+
const rgba = typeof color === "string" ? parseColor(color) : color;
|
|
1594
|
+
return {
|
|
1595
|
+
type: "SOLID",
|
|
1596
|
+
color: {
|
|
1597
|
+
r: rgba.r,
|
|
1598
|
+
g: rgba.g,
|
|
1599
|
+
b: rgba.b,
|
|
1600
|
+
a: rgba.a
|
|
1601
|
+
},
|
|
1602
|
+
opacity: rgba.a,
|
|
1603
|
+
visible: true
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
const euclideanRGB255 = differenceEuclidean("rgb");
|
|
1607
|
+
function colorDistance(c1, c2) {
|
|
1608
|
+
return euclideanRGB255({
|
|
1609
|
+
mode: "rgb",
|
|
1610
|
+
r: c1.r,
|
|
1611
|
+
g: c1.g,
|
|
1612
|
+
b: c1.b
|
|
1613
|
+
}, {
|
|
1614
|
+
mode: "rgb",
|
|
1615
|
+
r: c2.r,
|
|
1616
|
+
g: c2.g,
|
|
1617
|
+
b: c2.b
|
|
1618
|
+
}) * 255;
|
|
1567
1619
|
}
|
|
1568
1620
|
//#endregion
|
|
1569
|
-
export {
|
|
1621
|
+
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, clearInstanceOverrides, clearNodeFillOkHCL, clearNodeStrokeOkHCL, clipBoundsToPolygon, clipPolygon, cloneInstanceOverrideState, cloneNodeProps, cloneVectorNetwork, colorDistance, colorToCSS, colorToCSSCompact, colorToDisplayCSS, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToRgba255, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, copyDerivedGlyphs, copyEffect, copyEffects, copyFill, copyFills, copyGeometryPaths, copyLayoutGrids, copyStroke, copyStrokes, copyStyleRun, copyStyleRuns, createDefaultNode, createDefaultSourceMetadata, createInstanceOverrideState, defaultStrokeAlign, degToRad, deleteInstanceOverride, deserializeInstanceOverrideState, effectOverflow, forEachInstanceOverride, geometryBlobBounds, geometryCommandCoordCount, getDefaultRenderColorSpace, getFillOkHCL, getInstanceOverride, getNodeOkHCLPayloads, getStrokeOkHCL, hasInstanceOverride, hasSameCopySource, intersectVisualBounds, markCopySource, mergeVectorNetworks, newStrokeGeometry, nodeVisualBounds, normalizeColor, normalizeVectorNetwork, okhclToRGBA, parseColor, parseDisplayableColor, parseOkHCLPayload, polygonVertices, radToDeg, remapInstanceOverrideState, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview, rgba255ToColor, rgbaToOkHCL, rotatePoint, rotatedBBox, rotatedCorners, scaleGeometryPaths, serializeInstanceOverrideState, serializeOkHCLPayload, setInstanceOverride, setNodeFillOkHCL, setNodeStrokeOkHCL, strokeOverflow, transformGeometryBlob, transformGeometryPaths, transformVectorNetwork, tryParseColor, unionVisualBounds, validateVectorNetwork, vectorNetworksEqual };
|
|
1570
1622
|
|
|
1571
|
-
//# sourceMappingURL=
|
|
1623
|
+
//# sourceMappingURL=index.js.map
|