@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.3
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/asset-keys.d.ts +11 -1
- package/dist/asset-keys.d.ts.map +1 -1
- package/dist/asset-keys.js +16 -1
- package/dist/asset-keys.js.map +1 -1
- package/dist/checkpoint.d.ts +3 -3
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +53 -23
- package/dist/checkpoint.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +9 -1
- package/dist/components/properties.js.map +1 -1
- package/dist/constants.d.ts +6 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -1
- package/dist/constants.js.map +1 -1
- package/dist/constraints.d.ts +25 -0
- package/dist/constraints.d.ts.map +1 -0
- package/dist/constraints.js +51 -0
- package/dist/constraints.js.map +1 -0
- package/dist/coordinate.d.ts +64 -1
- package/dist/coordinate.d.ts.map +1 -1
- package/dist/coordinate.js +217 -1
- package/dist/coordinate.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +8 -1
- package/dist/copy.js.map +1 -1
- package/dist/css/index.d.ts +3 -2
- package/dist/css/index.js +3 -2
- package/dist/css/text.d.ts +28 -1
- package/dist/css/text.d.ts.map +1 -1
- package/dist/css/text.js +84 -17
- package/dist/css/text.js.map +1 -1
- package/dist/css/transform.d.ts +34 -0
- package/dist/css/transform.d.ts.map +1 -0
- package/dist/css/transform.js +320 -0
- package/dist/css/transform.js.map +1 -0
- package/dist/css/values.d.ts.map +1 -1
- package/dist/css/values.js +11 -1
- package/dist/css/values.js.map +1 -1
- package/dist/figjam/palette.d.ts +1 -1
- package/dist/figjam/palette.js +1 -1
- package/dist/figjam/palette.js.map +1 -1
- package/dist/geometry.d.ts +8 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +19 -8
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +48 -12
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +110 -24
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts +14 -4
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +76 -11
- package/dist/group-bounds.js.map +1 -1
- package/dist/hit-test.d.ts +5 -0
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +18 -12
- package/dist/hit-test.js.map +1 -1
- package/dist/images.d.ts +27 -3
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +57 -3
- package/dist/images.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +3 -0
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/placement.js +55 -12
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap.js +3 -0
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +34 -13
- package/dist/instances/sync.js.map +1 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +1 -0
- package/dist/node-defaults.js.map +1 -1
- package/dist/order-keys.d.ts +3 -1
- package/dist/order-keys.d.ts.map +1 -1
- package/dist/order-keys.js +6 -1
- package/dist/order-keys.js.map +1 -1
- package/dist/plugin-data/fields.d.ts +2 -0
- package/dist/plugin-data/fields.d.ts.map +1 -1
- package/dist/plugin-data/fields.js +2 -0
- package/dist/plugin-data/fields.js.map +1 -1
- package/dist/resize.d.ts +22 -11
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +227 -93
- package/dist/resize.js.map +1 -1
- package/dist/scaling/index.d.ts +3 -2
- package/dist/scaling/index.js +3 -2
- 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/scaling/snapshot.d.ts +25 -0
- package/dist/scaling/snapshot.d.ts.map +1 -0
- package/dist/scaling/snapshot.js +39 -0
- package/dist/scaling/snapshot.js.map +1 -0
- package/dist/scaling/tree.d.ts +24 -2
- package/dist/scaling/tree.d.ts.map +1 -1
- package/dist/scaling/tree.js +37 -14
- package/dist/scaling/tree.js.map +1 -1
- package/dist/shaders/model.d.ts.map +1 -1
- package/dist/shaders/model.js +2 -1
- package/dist/shaders/model.js.map +1 -1
- package/dist/shared-styles.d.ts +3 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +7 -1
- package/dist/shared-styles.js.map +1 -1
- package/dist/slots/authoring.d.ts +3 -2
- package/dist/slots/authoring.d.ts.map +1 -1
- package/dist/slots/authoring.js +5 -3
- package/dist/slots/authoring.js.map +1 -1
- package/dist/slots/content.d.ts.map +1 -1
- package/dist/slots/content.js +4 -1
- package/dist/slots/content.js.map +1 -1
- package/dist/text/direction.d.ts +3 -1
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +5 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/transfer/apply.d.ts.map +1 -1
- package/dist/transfer/apply.js +1 -6
- package/dist/transfer/apply.js.map +1 -1
- package/dist/transfer/copied.d.ts +35 -3
- package/dist/transfer/copied.d.ts.map +1 -1
- package/dist/transfer/copied.js +44 -13
- package/dist/transfer/copied.js.map +1 -1
- package/dist/transfer/dependencies.d.ts +38 -0
- package/dist/transfer/dependencies.d.ts.map +1 -0
- package/dist/transfer/dependencies.js +100 -0
- package/dist/transfer/dependencies.js.map +1 -0
- package/dist/transfer/history.js +0 -1
- package/dist/transfer/history.js.map +1 -1
- package/dist/transfer/index.d.ts +5 -3
- package/dist/transfer/index.js +5 -3
- package/dist/transfer/nodes.d.ts.map +1 -1
- package/dist/transfer/nodes.js +7 -14
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/transfer/plan.d.ts +0 -1
- package/dist/transfer/plan.js +3 -5
- package/dist/transfer/plan.js.map +1 -1
- package/dist/transfer/remove.js +5 -2
- package/dist/transfer/remove.js.map +1 -1
- package/dist/transfer/resources.d.ts +21 -0
- package/dist/transfer/resources.d.ts.map +1 -0
- package/dist/transfer/resources.js +38 -0
- package/dist/transfer/resources.js.map +1 -0
- package/dist/transfer/variables.d.ts +8 -1
- package/dist/transfer/variables.d.ts.map +1 -1
- package/dist/transfer/variables.js +24 -1
- package/dist/transfer/variables.js.map +1 -1
- package/dist/types.d.ts +47 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +28 -3
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +24 -7
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +17 -14
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +30 -72
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/fields.d.ts +1 -1
- package/dist/variables/fields.js +1 -1
- package/dist/variables/fields.js.map +1 -1
- package/dist/variables/formula/check.d.ts +1 -1
- package/dist/variables/formula/index.d.ts +2 -2
- package/dist/variables/formula/index.js +1 -1
- package/dist/variables/formula/index.js.map +1 -1
- package/dist/variables/formula/print.d.ts +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +6 -6
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +40 -24
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +57 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +231 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -11
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +36 -17
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +2 -8
- package/dist/vector-network.js.map +1 -1
- package/package.json +8 -1
- package/src/asset-keys.ts +20 -0
- package/src/checkpoint.ts +87 -32
- package/src/components/properties.ts +9 -0
- package/src/constants.ts +17 -0
- package/src/constraints.ts +60 -0
- package/src/coordinate.ts +220 -0
- package/src/copy.ts +9 -4
- package/src/css/index.ts +17 -1
- package/src/css/text.ts +85 -17
- package/src/css/transform.ts +266 -0
- package/src/css/values.ts +8 -0
- package/src/figjam/palette.ts +1 -1
- package/src/geometry.ts +20 -9
- package/src/graph.ts +128 -42
- package/src/group-bounds.ts +84 -17
- package/src/hit-test.ts +30 -14
- package/src/images.ts +71 -3
- package/src/instances/index.ts +4 -0
- package/src/instances/placement.ts +63 -10
- package/src/instances/swap.ts +5 -0
- package/src/instances/sync.ts +48 -21
- package/src/node-defaults.ts +1 -0
- package/src/order-keys.ts +6 -0
- package/src/plugin-data/fields.ts +6 -0
- package/src/resize.ts +267 -119
- package/src/scaling/index.ts +9 -1
- package/src/scaling/node.ts +9 -1
- package/src/scaling/snapshot.ts +51 -0
- package/src/scaling/tree.ts +63 -19
- package/src/shaders/model.ts +2 -3
- package/src/shared-styles.ts +8 -0
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/text/direction.ts +5 -0
- package/src/transfer/apply.ts +1 -13
- package/src/transfer/copied.ts +83 -15
- package/src/transfer/dependencies.ts +126 -0
- package/src/transfer/history.ts +0 -6
- package/src/transfer/index.ts +20 -2
- package/src/transfer/nodes.ts +10 -26
- package/src/transfer/plan.ts +3 -11
- package/src/transfer/remove.ts +5 -2
- package/src/transfer/resources.ts +54 -0
- package/src/transfer/variables.ts +34 -0
- package/src/types.ts +55 -1
- package/src/undo.ts +48 -10
- package/src/variables/bindings.ts +44 -91
- package/src/variables/fields.ts +1 -1
- package/src/variables/formula/index.ts +3 -1
- package/src/variables/index.ts +56 -38
- package/src/variables/paints.ts +296 -0
- package/src/variables/resolution.ts +39 -28
- package/src/variables/subtree.ts +15 -0
- package/src/vector-network.ts +4 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { placeScaledAbout, selectionPlacement } from "../coordinate.js";
|
|
2
|
+
import { rescaleNodeChanges, rescaleTargets } from "./tree.js";
|
|
3
|
+
//#region src/scaling/snapshot.ts
|
|
4
|
+
/** Records the roots and the layers inside them that Figma's Scale tool changes. */
|
|
5
|
+
function snapshotScale(graph, roots) {
|
|
6
|
+
const snapshot = {
|
|
7
|
+
roots: /* @__PURE__ */ new Map(),
|
|
8
|
+
nodes: /* @__PURE__ */ new Map()
|
|
9
|
+
};
|
|
10
|
+
for (const root of roots) {
|
|
11
|
+
snapshot.roots.set(root.id, selectionPlacement(root, graph));
|
|
12
|
+
for (const node of rescaleTargets(graph, root, { keepLocked: true })) snapshot.nodes.set(node.id, { ...node });
|
|
13
|
+
}
|
|
14
|
+
return snapshot;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* What scaling the snapshot evenly by `scale` about a canvas point writes to each layer: its
|
|
18
|
+
* lengths, and for a root its place, so the point stays put and the root keeps its angle.
|
|
19
|
+
*/
|
|
20
|
+
function scaledSnapshotChanges(graph, snapshot, scale, anchor) {
|
|
21
|
+
const changes = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const [id, node] of snapshot.nodes) {
|
|
23
|
+
const placement = snapshot.roots.get(id);
|
|
24
|
+
const change = rescaleNodeChanges(graph, node, scale, placement !== void 0);
|
|
25
|
+
if (placement) {
|
|
26
|
+
const { x, y } = scale === 1 ? node : placeScaledAbout(placement, anchor, scale);
|
|
27
|
+
Object.assign(change, {
|
|
28
|
+
x,
|
|
29
|
+
y
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
changes.set(id, change);
|
|
33
|
+
}
|
|
34
|
+
return changes;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { scaledSnapshotChanges, snapshotScale };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","names":[],"sources":["../../src/scaling/snapshot.ts"],"sourcesContent":["import { placeScaledAbout, selectionPlacement, type SelectionPlacement } from '../coordinate'\nimport type { SceneGraph } from '../graph'\nimport type { Vector } from '../primitives'\nimport type { SceneNode } from '../types'\nimport { rescaleNodeChanges, rescaleTargets } from './tree'\n\n/**\n * The layers a Scale edit changes, as they were when it began, so every step of a drag or a\n * scrubbed field scales from the same start rather than from its own last preview.\n */\nexport interface ScaleSnapshot {\n /** Each scaled root's place in its parent and on the canvas, by ID. */\n roots: Map<string, SelectionPlacement>\n /** Every layer the edit changes, roots first; locked layers inside are left out. */\n nodes: Map<string, SceneNode>\n}\n\n/** Records the roots and the layers inside them that Figma's Scale tool changes. */\nexport function snapshotScale(graph: SceneGraph, roots: readonly SceneNode[]): ScaleSnapshot {\n const snapshot: ScaleSnapshot = { roots: new Map(), nodes: new Map() }\n for (const root of roots) {\n snapshot.roots.set(root.id, selectionPlacement(root, graph))\n for (const node of rescaleTargets(graph, root, { keepLocked: true }))\n snapshot.nodes.set(node.id, { ...node })\n }\n return snapshot\n}\n\n/**\n * What scaling the snapshot evenly by `scale` about a canvas point writes to each layer: its\n * lengths, and for a root its place, so the point stays put and the root keeps its angle.\n */\nexport function scaledSnapshotChanges(\n graph: SceneGraph,\n snapshot: ScaleSnapshot,\n scale: number,\n anchor: Vector\n): Map<string, Partial<SceneNode>> {\n const changes = new Map<string, Partial<SceneNode>>()\n for (const [id, node] of snapshot.nodes) {\n const placement = snapshot.roots.get(id)\n const change = rescaleNodeChanges(graph, node, scale, placement !== undefined)\n // At its own size, a root takes back exactly the place it started from.\n if (placement) {\n const { x, y } = scale === 1 ? node : placeScaledAbout(placement, anchor, scale)\n Object.assign(change, { x, y })\n }\n changes.set(id, change)\n }\n return changes\n}\n"],"mappings":";;;;AAkBA,SAAgB,cAAc,OAAmB,OAA4C;CAC3F,MAAM,WAA0B;EAAE,uBAAO,IAAI,IAAI;EAAG,uBAAO,IAAI,IAAI;CAAE;CACrE,KAAK,MAAM,QAAQ,OAAO;EACxB,SAAS,MAAM,IAAI,KAAK,IAAI,mBAAmB,MAAM,KAAK,CAAC;EAC3D,KAAK,MAAM,QAAQ,eAAe,OAAO,MAAM,EAAE,YAAY,KAAK,CAAC,GACjE,SAAS,MAAM,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,CAAC;CAC3C;CACA,OAAO;AACT;;;;;AAMA,SAAgB,sBACd,OACA,UACA,OACA,QACiC;CACjC,MAAM,0BAAU,IAAI,IAAgC;CACpD,KAAK,MAAM,CAAC,IAAI,SAAS,SAAS,OAAO;EACvC,MAAM,YAAY,SAAS,MAAM,IAAI,EAAE;EACvC,MAAM,SAAS,mBAAmB,OAAO,MAAM,OAAO,cAAc,KAAA,CAAS;EAE7E,IAAI,WAAW;GACb,MAAM,EAAE,GAAG,MAAM,UAAU,IAAI,OAAO,iBAAiB,WAAW,QAAQ,KAAK;GAC/E,OAAO,OAAO,QAAQ;IAAE;IAAG;GAAE,CAAC;EAChC;EACA,QAAQ,IAAI,IAAI,MAAM;CACxB;CACA,OAAO;AACT"}
|
package/dist/scaling/tree.d.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
import { SceneGraph } from "../graph.js";
|
|
2
|
+
import { SceneNode } from "../types.js";
|
|
2
3
|
//#region src/scaling/tree.d.ts
|
|
3
|
-
/**
|
|
4
|
+
/** The smallest scale a node tree takes. */
|
|
5
|
+
declare const MIN_RESCALE = 0.01;
|
|
6
|
+
interface RescaleOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Locked layers below the root, and everything inside them, keep their size and their place in
|
|
9
|
+
* their parent, as Figma's Scale tool leaves them; the plugin API's `rescale()` scales them.
|
|
10
|
+
*/
|
|
11
|
+
keepLocked?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The selected layers the Scale tool scales: unlocked layers of a type that rescales, outside any
|
|
15
|
+
* instance, and not inside another of them, which scales them with itself.
|
|
16
|
+
*/
|
|
17
|
+
declare function scaleRoots(graph: SceneGraph, nodes: readonly SceneNode[]): SceneNode[];
|
|
18
|
+
/** The root and every layer below it that a rescale changes, root first. */
|
|
19
|
+
declare function rescaleTargets(graph: SceneGraph, root: SceneNode, { keepLocked }?: RescaleOptions): SceneNode[];
|
|
20
|
+
/**
|
|
21
|
+
* What a rescale by `scale` writes to `node`: its own lengths and those of its bound variables,
|
|
22
|
+
* the scale of an instance's occurrence, and, below the root, its place in its parent.
|
|
23
|
+
*/
|
|
24
|
+
declare function rescaleNodeChanges(graph: SceneGraph, node: SceneNode, scale: number, isRoot: boolean): Partial<SceneNode>;
|
|
25
|
+
/** Scale a node tree from the root node's top-left, matching Figma's `rescale()`. */
|
|
4
26
|
declare function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void;
|
|
5
27
|
//#endregion
|
|
6
|
-
export { rescaleNodeTree };
|
|
28
|
+
export { MIN_RESCALE, RescaleOptions, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleRoots };
|
|
7
29
|
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.d.ts","names":[],"sources":["../../src/scaling/tree.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tree.d.ts","names":[],"sources":["../../src/scaling/tree.ts"],"mappings":";;;;cAOa;UAmBI;;;;;EAKf;;;;;;iBAOc,WAAW,OAAO,YAAY,gBAAgB,cAAc;;iBAU5D,eACd,OAAO,YACP,MAAM,aACJ,eAAsB,iBACvB;;;;;iBAiBa,mBACd,OAAO,YACP,MAAM,WACN,eACA,kBACC,QAAQ;;iBAWK,gBAAgB,OAAO,YAAY,gBAAgB"}
|
package/dist/scaling/tree.js
CHANGED
|
@@ -2,7 +2,8 @@ import { findInstanceAncestor } from "../instances/main-component.js";
|
|
|
2
2
|
import { scaleNodeChanges } from "./node.js";
|
|
3
3
|
import { scaleVariableBindingUnits } from "../variables/units.js";
|
|
4
4
|
//#region src/scaling/tree.ts
|
|
5
|
-
|
|
5
|
+
/** The smallest scale a node tree takes. */
|
|
6
|
+
const MIN_RESCALE = .01;
|
|
6
7
|
const RESCALABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
7
8
|
"BOOLEAN_OPERATION",
|
|
8
9
|
"COMPONENT",
|
|
@@ -19,29 +20,51 @@ const RESCALABLE_NODE_TYPES = /* @__PURE__ */ new Set([
|
|
|
19
20
|
"TEXT",
|
|
20
21
|
"VECTOR"
|
|
21
22
|
]);
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The selected layers the Scale tool scales: unlocked layers of a type that rescales, outside any
|
|
25
|
+
* instance, and not inside another of them, which scales them with itself.
|
|
26
|
+
*/
|
|
27
|
+
function scaleRoots(graph, nodes) {
|
|
28
|
+
const ids = new Set(nodes.map((node) => node.id));
|
|
29
|
+
return nodes.filter((node) => {
|
|
30
|
+
if (node.locked || !RESCALABLE_NODE_TYPES.has(node.type) || !node.parentId) return false;
|
|
31
|
+
if (findInstanceAncestor(graph, node.parentId)) return false;
|
|
32
|
+
return !graph.closest(node.parentId, (parent) => ids.has(parent.id));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The root and every layer below it that a rescale changes, root first. */
|
|
36
|
+
function rescaleTargets(graph, root, { keepLocked = false } = {}) {
|
|
28
37
|
const nodes = [root];
|
|
29
38
|
const collect = (node) => {
|
|
30
|
-
for (const
|
|
31
|
-
|
|
32
|
-
if (!child) continue;
|
|
39
|
+
for (const child of graph.getChildren(node.id)) {
|
|
40
|
+
if (keepLocked && child.locked) continue;
|
|
33
41
|
nodes.push(child);
|
|
34
42
|
collect(child);
|
|
35
43
|
}
|
|
36
44
|
};
|
|
37
45
|
collect(root);
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
return nodes;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What a rescale by `scale` writes to `node`: its own lengths and those of its bound variables,
|
|
50
|
+
* the scale of an instance's occurrence, and, below the root, its place in its parent.
|
|
51
|
+
*/
|
|
52
|
+
function rescaleNodeChanges(graph, node, scale, isRoot) {
|
|
53
|
+
return {
|
|
54
|
+
...scaleNodeChanges(node, scale, !isRoot),
|
|
40
55
|
...scaleVariableBindingUnits(node, scale),
|
|
41
56
|
componentScale: findInstanceAncestor(graph, node.id) ? node.componentScale * scale : node.componentScale
|
|
42
|
-
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Scale a node tree from the root node's top-left, matching Figma's `rescale()`. */
|
|
60
|
+
function rescaleNodeTree(graph, rootId, scale) {
|
|
61
|
+
if (!Number.isFinite(scale)) throw new TypeError("Scale must be a finite number");
|
|
62
|
+
if (scale < .01) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`);
|
|
63
|
+
const root = graph.getNode(rootId);
|
|
64
|
+
if (!root || !RESCALABLE_NODE_TYPES.has(root.type)) throw new Error("rescale() is not supported on this node");
|
|
65
|
+
for (const node of rescaleTargets(graph, root)) graph.updateNode(node.id, rescaleNodeChanges(graph, node, scale, node.id === rootId));
|
|
43
66
|
}
|
|
44
67
|
//#endregion
|
|
45
|
-
export { rescaleNodeTree };
|
|
68
|
+
export { MIN_RESCALE, rescaleNodeChanges, rescaleNodeTree, rescaleTargets, scaleRoots };
|
|
46
69
|
|
|
47
70
|
//# sourceMappingURL=tree.js.map
|
package/dist/scaling/tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","names":[],"sources":["../../src/scaling/tree.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { scaleNodeChanges } from './node'\n\
|
|
1
|
+
{"version":3,"file":"tree.js","names":[],"sources":["../../src/scaling/tree.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor } from '../instances'\nimport type { SceneNode } from '../types'\nimport { scaleVariableBindingUnits } from '../variables/units'\nimport { scaleNodeChanges } from './node'\n\n/** The smallest scale a node tree takes. */\nexport const MIN_RESCALE = 0.01\n\nconst RESCALABLE_NODE_TYPES = new Set<SceneNode['type']>([\n 'BOOLEAN_OPERATION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'ELLIPSE',\n 'FRAME',\n 'GROUP',\n 'INSTANCE',\n 'LINE',\n 'POLYGON',\n 'RECTANGLE',\n 'STAR',\n 'STICKY',\n 'TEXT',\n 'VECTOR'\n])\n\nexport interface RescaleOptions {\n /**\n * Locked layers below the root, and everything inside them, keep their size and their place in\n * their parent, as Figma's Scale tool leaves them; the plugin API's `rescale()` scales them.\n */\n keepLocked?: boolean\n}\n\n/**\n * The selected layers the Scale tool scales: unlocked layers of a type that rescales, outside any\n * instance, and not inside another of them, which scales them with itself.\n */\nexport function scaleRoots(graph: SceneGraph, nodes: readonly SceneNode[]): SceneNode[] {\n const ids = new Set(nodes.map((node) => node.id))\n return nodes.filter((node) => {\n if (node.locked || !RESCALABLE_NODE_TYPES.has(node.type) || !node.parentId) return false\n if (findInstanceAncestor(graph, node.parentId)) return false\n return !graph.closest(node.parentId, (parent) => ids.has(parent.id))\n })\n}\n\n/** The root and every layer below it that a rescale changes, root first. */\nexport function rescaleTargets(\n graph: SceneGraph,\n root: SceneNode,\n { keepLocked = false }: RescaleOptions = {}\n): SceneNode[] {\n const nodes: SceneNode[] = [root]\n const collect = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n if (keepLocked && child.locked) continue\n nodes.push(child)\n collect(child)\n }\n }\n collect(root)\n return nodes\n}\n\n/**\n * What a rescale by `scale` writes to `node`: its own lengths and those of its bound variables,\n * the scale of an instance's occurrence, and, below the root, its place in its parent.\n */\nexport function rescaleNodeChanges(\n graph: SceneGraph,\n node: SceneNode,\n scale: number,\n isRoot: boolean\n): Partial<SceneNode> {\n return {\n ...scaleNodeChanges(node, scale, !isRoot),\n ...scaleVariableBindingUnits(node, scale),\n componentScale: findInstanceAncestor(graph, node.id)\n ? node.componentScale * scale\n : node.componentScale\n }\n}\n\n/** Scale a node tree from the root node's top-left, matching Figma's `rescale()`. */\nexport function rescaleNodeTree(graph: SceneGraph, rootId: string, scale: number): void {\n if (!Number.isFinite(scale)) throw new TypeError('Scale must be a finite number')\n if (scale < MIN_RESCALE) throw new RangeError(`Scale must be at least ${MIN_RESCALE}`)\n const root = graph.getNode(rootId)\n if (!root || !RESCALABLE_NODE_TYPES.has(root.type))\n throw new Error('rescale() is not supported on this node')\n for (const node of rescaleTargets(graph, root)) {\n graph.updateNode(node.id, rescaleNodeChanges(graph, node, scale, node.id === rootId))\n }\n}\n"],"mappings":";;;;;AAOA,MAAa,cAAc;AAE3B,MAAM,wCAAwB,IAAI,IAAuB;CACvD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;AAcD,SAAgB,WAAW,OAAmB,OAA0C;CACtF,MAAM,MAAM,IAAI,IAAI,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC;CAChD,OAAO,MAAM,QAAQ,SAAS;EAC5B,IAAI,KAAK,UAAU,CAAC,sBAAsB,IAAI,KAAK,IAAI,KAAK,CAAC,KAAK,UAAU,OAAO;EACnF,IAAI,qBAAqB,OAAO,KAAK,QAAQ,GAAG,OAAO;EACvD,OAAO,CAAC,MAAM,QAAQ,KAAK,WAAW,WAAW,IAAI,IAAI,OAAO,EAAE,CAAC;CACrE,CAAC;AACH;;AAGA,SAAgB,eACd,OACA,MACA,EAAE,aAAa,UAA0B,CAAC,GAC7B;CACb,MAAM,QAAqB,CAAC,IAAI;CAChC,MAAM,WAAW,SAA0B;EACzC,KAAK,MAAM,SAAS,MAAM,YAAY,KAAK,EAAE,GAAG;GAC9C,IAAI,cAAc,MAAM,QAAQ;GAChC,MAAM,KAAK,KAAK;GAChB,QAAQ,KAAK;EACf;CACF;CACA,QAAQ,IAAI;CACZ,OAAO;AACT;;;;;AAMA,SAAgB,mBACd,OACA,MACA,OACA,QACoB;CACpB,OAAO;EACL,GAAG,iBAAiB,MAAM,OAAO,CAAC,MAAM;EACxC,GAAG,0BAA0B,MAAM,KAAK;EACxC,gBAAgB,qBAAqB,OAAO,KAAK,EAAE,IAC/C,KAAK,iBAAiB,QACtB,KAAK;CACX;AACF;;AAGA,SAAgB,gBAAgB,OAAmB,QAAgB,OAAqB;CACtF,IAAI,CAAC,OAAO,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,+BAA+B;CAChF,IAAI,QAAA,KAAqB,MAAM,IAAI,WAAW,0BAA0B,aAAa;CACrF,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,IAAI,KAAK,IAAI,GAC/C,MAAM,IAAI,MAAM,yCAAyC;CAC3D,KAAK,MAAM,QAAQ,eAAe,OAAO,IAAI,GAC3C,MAAM,WAAW,KAAK,IAAI,mBAAmB,OAAO,MAAM,OAAO,KAAK,OAAO,MAAM,CAAC;AAExF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/shaders/model.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"model.d.ts","names":[],"sources":["../../src/shaders/model.ts"],"mappings":";;;;KAYK,aAAa,KAAK;;iBAGP,iBAAiB,MAAM,KAAK,2BAA2B;;;;;;iBASvD,cACd,MAAM,KAAK,0BACX,OAAO,OACN;;iBAMa,eAAe,MAAM;;;;;iBAQrB,iBACd,MAAM,KAAK,0BACX,iBAAiB,QACjB,mBAAkB,gBACjB;;;;;iBAea,kBAAkB,QAAQ;EACxC,OAAO;EACP,QAAQ;;;iBAiBM,gBAAgB,QAAQ;;;;;iBAQxB,qBACd,QAAQ,aACR;EAAQ;EAAe"}
|
package/dist/shaders/model.js
CHANGED
|
@@ -2,6 +2,7 @@ import { TRANSPARENT } from "../constants.js";
|
|
|
2
2
|
import { randomHex } from "../random.js";
|
|
3
3
|
import { readAllPluginData, withAllPluginData } from "../plugin-data/field.js";
|
|
4
4
|
import { OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
|
|
5
|
+
import { imagePaintHashes } from "../images.js";
|
|
5
6
|
import { sha1 } from "@noble/hashes/legacy.js";
|
|
6
7
|
import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
|
|
7
8
|
//#region src/shaders/model.ts
|
|
@@ -27,7 +28,7 @@ function hasShaderPaint(node) {
|
|
|
27
28
|
* stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
|
|
28
29
|
*/
|
|
29
30
|
function withShaderPaints(node, paints, shaders = []) {
|
|
30
|
-
const shown = new Set(paints
|
|
31
|
+
const shown = new Set(imagePaintHashes(paints));
|
|
31
32
|
const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]));
|
|
32
33
|
for (const shader of shaders) byImage.set(shader.image, shader);
|
|
33
34
|
return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader, [...byImage.values()].filter((shader) => shown.has(shader.image)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport { TRANSPARENT } from '../constants'\nimport { readAllPluginData, withAllPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport { randomHex } from '../random'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset } from './schema'\n\n/** What shader paints read of a node. */\ntype ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>\n\n/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */\nexport function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {\n return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader)\n}\n\n/**\n * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.\n * Null for any other paint, including one whose image was replaced, which then draws as the\n * image it holds.\n */\nexport function shaderOfPaint(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill\n): ShaderPaint | null {\n if (paint.type !== 'IMAGE' || !paint.imageHash) return null\n return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null\n}\n\n/** Whether any paint of `node` draws a shader. */\nexport function hasShaderPaint(node: ShaderNode): boolean {\n return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null)\n}\n\n/**\n * The node's plugin data with `shaders` set by their image, keeping only shaders a fill or\n * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withShaderPaints(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n shaders: readonly ShaderPaint[] = []\n): SceneNode['pluginData'] {\n const shown = new Set(
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport { TRANSPARENT } from '../constants'\nimport { imagePaintHashes } from '../images'\nimport { readAllPluginData, withAllPluginData } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport { randomHex } from '../random'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset } from './schema'\n\n/** What shader paints read of a node. */\ntype ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>\n\n/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */\nexport function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {\n return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader)\n}\n\n/**\n * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.\n * Null for any other paint, including one whose image was replaced, which then draws as the\n * image it holds.\n */\nexport function shaderOfPaint(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill\n): ShaderPaint | null {\n if (paint.type !== 'IMAGE' || !paint.imageHash) return null\n return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null\n}\n\n/** Whether any paint of `node` draws a shader. */\nexport function hasShaderPaint(node: ShaderNode): boolean {\n return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null)\n}\n\n/**\n * The node's plugin data with `shaders` set by their image, keeping only shaders a fill or\n * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withShaderPaints(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n shaders: readonly ShaderPaint[] = []\n): SceneNode['pluginData'] {\n const shown = new Set(imagePaintHashes(paints))\n const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]))\n for (const shader of shaders) byImage.set(shader.image, shader)\n return withAllPluginData(\n node.pluginData,\n OPEN_PENCIL_PLUGIN_DATA.shader,\n [...byImage.values()].filter((shader) => shown.has(shader.image))\n )\n}\n\n/**\n * A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet\n * rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.\n */\nexport function createShaderPaint(preset: ShaderPreset): {\n paint: Fill\n shader: ShaderPaint\n} {\n const image = randomHex(20)\n return {\n paint: {\n type: 'IMAGE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true,\n imageHash: image,\n imageScaleMode: 'FILL'\n },\n shader: { image, preset: structuredClone(preset) }\n }\n}\n\n/** A short key that tells one preset from another, which a rendered frame records. */\nexport function shaderPresetKey(preset: ShaderPreset): string {\n return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))))\n}\n\n/**\n * Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a\n * preset change after reopening the document does not keep a frame of the newer preset.\n */\nexport function isShaderFrameCurrent(\n shader: ShaderPaint,\n size: { width: number; height: number }\n): boolean {\n const { frame } = shader\n return (\n frame !== undefined &&\n frame.preset === shaderPresetKey(shader.preset) &&\n Math.round(frame.width) === Math.round(size.width) &&\n Math.round(frame.height) === Math.round(size.height)\n )\n}\n"],"mappings":";;;;;;;;;AAeA,SAAgB,iBAAiB,MAAoD;CACnF,OAAO,kBAAkB,KAAK,YAAY,wBAAwB,MAAM;AAC1E;;;;;;AAOA,SAAgB,cACd,MACA,OACoB;CACpB,IAAI,MAAM,SAAS,WAAW,CAAC,MAAM,WAAW,OAAO;CACvD,OAAO,iBAAiB,IAAI,CAAC,CAAC,MAAM,WAAW,OAAO,UAAU,MAAM,SAAS,KAAK;AACtF;;AAGA,SAAgB,eAAe,MAA2B;CACxD,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,cAAc,MAAM,KAAK,MAAM,IAAI;AAC7F;;;;;AAMA,SAAgB,iBACd,MACA,QACA,UAAkC,CAAC,GACV;CACzB,MAAM,QAAQ,IAAI,IAAI,iBAAiB,MAAM,CAAC;CAC9C,MAAM,UAAU,IAAI,IAAI,iBAAiB,IAAI,CAAC,CAAC,KAAK,WAAW,CAAC,OAAO,OAAO,MAAM,CAAC,CAAC;CACtF,KAAK,MAAM,UAAU,SAAS,QAAQ,IAAI,OAAO,OAAO,MAAM;CAC9D,OAAO,kBACL,KAAK,YACL,wBAAwB,QACxB,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW,MAAM,IAAI,OAAO,KAAK,CAAC,CAClE;AACF;;;;;AAMA,SAAgB,kBAAkB,QAGhC;CACA,MAAM,QAAQ,UAAU,EAAE;CAC1B,OAAO;EACL,OAAO;GACL,MAAM;GACN,OAAO;GACP,SAAS;GACT,SAAS;GACT,WAAW;GACX,gBAAgB;EAClB;EACA,QAAQ;GAAE;GAAO,QAAQ,gBAAgB,MAAM;EAAE;CACnD;AACF;;AAGA,SAAgB,gBAAgB,QAA8B;CAC5D,OAAO,WAAW,KAAK,YAAY,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC;AAC7D;;;;;AAMA,SAAgB,qBACd,QACA,MACS;CACT,MAAM,EAAE,UAAU;CAClB,OACE,UAAU,KAAA,KACV,MAAM,WAAW,gBAAgB,OAAO,MAAM,KAC9C,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,KAAK,KACjD,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM;AAEvD"}
|
package/dist/shared-styles.d.ts
CHANGED
|
@@ -31,6 +31,8 @@ declare const FACE_KEYS: readonly ["fontFamily", "fontWeight", "italic"];
|
|
|
31
31
|
declare function rangeFontStyle(node: Pick<SceneNode, 'fontStyle'>, style: CharacterStyleOverride): string | null;
|
|
32
32
|
declare function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind];
|
|
33
33
|
declare function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType;
|
|
34
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
35
|
+
declare function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode>;
|
|
34
36
|
declare function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[];
|
|
35
37
|
declare function styleDetachmentChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
36
38
|
/** The node of the shared style with `id`, when the document holds one of `type`. */
|
|
@@ -47,5 +49,5 @@ declare function sharedStylePatch(kind: SharedStyleKind, target: SceneNode, styl
|
|
|
47
49
|
/** A layer leaving a shared style: it keeps the style's values, without the reference. */
|
|
48
50
|
declare function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode>;
|
|
49
51
|
//#endregion
|
|
50
|
-
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
52
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStyleLayers, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
51
53
|
//# sourceMappingURL=shared-styles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-styles.d.ts","names":[],"sources":["../src/shared-styles.ts"],"mappings":";;;cAiBM;;;;;;;;cASO;;iBAGG,mBAAmB,MAAM;;cAiB5B;;cAwBA;;;;;;;;cASA;;;;;iBAUG,eACd,MAAM,KAAK,yBACX,OAAO;iBAMO,kBAAkB,MAAM,0BAA0B,gBAAgB;iBAIlE,uBAAuB,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"shared-styles.d.ts","names":[],"sources":["../src/shared-styles.ts"],"mappings":";;;cAiBM;;;;;;;;cASO;;iBAGG,mBAAmB,MAAM;;cAiB5B;;cAwBA;;;;;;;;cASA;;;;;iBAUG,eACd,MAAM,KAAK,yBACX,OAAO;iBAMO,kBAAkB,MAAM,0BAA0B,gBAAgB;iBAIlE,uBAAuB,MAAM,kBAAkB;;iBAK/C,kBAAkB,OAAO,aAAa,YAAY;iBAOlD,gBAAgB,OAAO,YAAY,MAAM,kBAAkB;iBA0B3D,uBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;;iBAmBK,gBACd,OAAO,YACP,YACA,MAAM,kBACL;;iBASa;;iBAOA,eAAe,OAAO,aAAa;;;;;iBAmCnC,iBACd,MAAM,iBACN,QAAQ,WACR,iBACA,OAAO,mBACN,QAAQ;;iBAYK,uBAAuB,MAAM,kBAAkB,QAAQ"}
|
package/dist/shared-styles.js
CHANGED
|
@@ -79,6 +79,12 @@ function sharedStyleRefKey(kind) {
|
|
|
79
79
|
function sharedStyleTypeForKind(kind) {
|
|
80
80
|
return STYLE_TYPES[kind];
|
|
81
81
|
}
|
|
82
|
+
/** The document's shared style layers, by the source ID layers link them by. */
|
|
83
|
+
function sharedStyleLayers(graph) {
|
|
84
|
+
const styles = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const node of graph.getAllNodes()) if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node);
|
|
86
|
+
return styles;
|
|
87
|
+
}
|
|
82
88
|
function getSharedStyles(graph, kind) {
|
|
83
89
|
const type = sharedStyleTypeForKind(kind);
|
|
84
90
|
const styles = [];
|
|
@@ -181,6 +187,6 @@ function sharedStyleDetachPatch(kind) {
|
|
|
181
187
|
return { [STYLE_REF_KEYS[kind]]: null };
|
|
182
188
|
}
|
|
183
189
|
//#endregion
|
|
184
|
-
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
190
|
+
export { FACE_KEYS, SHARED_STYLE_FIELDS, SHARED_TEXT_STYLE_FIELDS, STYLE_LINK_FIELDS, findSharedStyle, getSharedStyles, internalCanvas, newSharedStyleId, rangeFontStyle, referencedStyleIds, sharedStyleDetachPatch, sharedStyleLayers, sharedStylePatch, sharedStyleRefKey, sharedStyleTypeForKind, styleDetachmentChanges };
|
|
185
191
|
|
|
186
192
|
//# sourceMappingURL=shared-styles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { compact, isEqual, omit, pick } from 'es-toolkit'\n\nimport { BLACK } from './constants'\nimport { copyEffects, copyFills, copyLayoutGrids } from './copy'\nimport type { SceneGraph } from './graph'\nimport { newStrokeGeometry } from './node-defaults'\nimport { randomHex } from './random'\nimport { styleRunReferences } from './text/references'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\n/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */\nexport function referencedStyleIds(node: SceneNode): string[] {\n return compact([\n ...STYLE_LINK_FIELDS.map((field) => node[field]),\n ...styleRunReferences(node.styleRuns).styles,\n ...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)\n ])\n}\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */\nconst STROKE_LINE_KEYS = ['weight', 'align', 'cap', 'join', 'dashPattern'] as const\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n\n/** The node of the shared style with `id`, when the document holds one of `type`. */\nexport function findSharedStyle(\n graph: SceneGraph,\n id: string,\n type: SharedStyleType\n): SceneNode | undefined {\n if (!id) return undefined\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType === type && node.source.id === id) return node\n }\n return undefined\n}\n\n/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */\nexport function newSharedStyleId(): string {\n return `S:${randomHex(20)},`\n}\n\nconst INTERNAL_CANVAS_NAME = 'Internal Only Canvas'\n\n/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */\nexport function internalCanvas(graph: SceneGraph): SceneNode {\n const existing = graph.getPages(true).find((page) => page.internalOnly)\n if (existing) return existing\n return graph.createNode('CANVAS', graph.rootId, {\n name: INTERNAL_CANVAS_NAME,\n width: 0,\n height: 0,\n internalOnly: true\n })\n}\n\n/**\n * A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,\n * and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes\n * (Figma desktop 126).\n */\nfunction strokesFromStyle(target: SceneNode, style: SceneNode): SceneNode['strokes'] {\n // Without strokes, the layer keeps the weight and alignment a new stroke takes.\n const fallback: Stroke = target.strokes[0] ?? {\n type: 'SOLID',\n color: BLACK,\n opacity: 1,\n visible: true,\n ...newStrokeGeometry(target)\n }\n return copyFills(style.fills).map((paint, index) => ({\n ...paint,\n ...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)\n }))\n}\n\n/**\n * What a layer takes from a shared style it starts using: the style's fields and the reference\n * that keeps it attached. Without the style's node, the reference alone.\n */\nexport function sharedStylePatch(\n kind: SharedStyleKind,\n target: SceneNode,\n styleId: string,\n style: SceneNode | null\n): Partial<SceneNode> {\n const patch: Partial<SceneNode> = { [STYLE_REF_KEYS[kind]]: styleId }\n if (!style) return patch\n if (kind === 'fill') patch.fills = copyFills(style.fills)\n else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)\n else if (kind === 'effect') patch.effects = copyEffects(style.effects)\n else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)\n else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))\n return patch\n}\n\n/** A layer leaving a shared style: it keeps the style's values, without the reference. */\nexport function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {\n return { [STYLE_REF_KEYS[kind]]: null }\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;;AAG7D,SAAgB,mBAAmB,MAA2B;CAC5D,OAAO,QAAQ;EACb,GAAG,kBAAkB,KAAK,UAAU,KAAK,MAAM;EAC/C,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACtC,IAAI,KAAK,eAAe,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,WAAW;CAC3E,CAAC;AACH;AAEA,MAAM,cAAc;CAClB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;C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CAAC,KAAK,OAAO,WAAW;EACnD,GAAG;EACH,GAAG,KAAK,OAAO,QAAQ,UAAU,UAAU,gBAAgB;CAC7D,EAAE;AACJ;;;;;AAMA,SAAgB,iBACd,MACA,QACA,SACA,OACoB;CACpB,MAAM,QAA4B,GAAG,eAAe,QAAQ,QAAQ;CACpE,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,SAAS,QAAQ,MAAM,QAAQ,UAAU,MAAM,KAAK;MACnD,IAAI,SAAS,UAAU,MAAM,UAAU,iBAAiB,QAAQ,KAAK;MACrE,IAAI,SAAS,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO;MAChE,IAAI,SAAS,QAAQ,MAAM,cAAc,gBAAgB,MAAM,WAAW;MAC1E,OAAO,OAAO,OAAO,gBAAgB,KAAK,OAAO,oBAAoB,IAAI,CAAC,CAAC;CAChF,OAAO;AACT;;AAGA,SAAgB,uBAAuB,MAA2C;CAChF,OAAO,GAAG,eAAe,QAAQ,KAAK;AACxC"}
|
|
1
|
+
{"version":3,"file":"shared-styles.js","names":[],"sources":["../src/shared-styles.ts"],"sourcesContent":["import { compact, isEqual, omit, pick } from 'es-toolkit'\n\nimport { BLACK } from './constants'\nimport { copyEffects, copyFills, copyLayoutGrids } from './copy'\nimport type { SceneGraph } from './graph'\nimport { newStrokeGeometry } from './node-defaults'\nimport { randomHex } from './random'\nimport { styleRunReferences } from './text/references'\nimport type {\n CharacterStyleOverride,\n SceneNode,\n SharedStyle,\n SharedStyleKind,\n SharedStyleType,\n Stroke\n} from './types'\n\nconst STYLE_REF_KEYS = {\n fill: 'fillStyleId',\n stroke: 'strokeStyleId',\n text: 'textStyleId',\n effect: 'effectStyleId',\n grid: 'gridStyleId'\n} as const satisfies Record<SharedStyleKind, keyof SceneNode>\n\n/** The fields that link a layer to its shared styles. */\nexport const STYLE_LINK_FIELDS = Object.values(STYLE_REF_KEYS)\n\n/** The shared styles a layer uses: its own, its text ranges', and its vector regions'. */\nexport function referencedStyleIds(node: SceneNode): string[] {\n return compact([\n ...STYLE_LINK_FIELDS.map((field) => node[field]),\n ...styleRunReferences(node.styleRuns).styles,\n ...(node.vectorNetwork?.regions ?? []).map((region) => region.fillStyleId)\n ])\n}\n\nconst STYLE_TYPES = {\n fill: 'FILL',\n stroke: 'FILL',\n text: 'TEXT',\n effect: 'EFFECT',\n grid: 'GRID'\n} as const satisfies Record<SharedStyleKind, SharedStyleType>\n\n/** The fields a text style gives what uses it; changing one leaves the style. */\nexport const SHARED_TEXT_STYLE_FIELDS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textDecoration',\n 'textCase',\n 'fontFeatures'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The paragraph fields a text style also gives the whole text; a range takes only the character\n * ones. Changing one leaves the style, and a cleared style resets them (live-verified).\n */\nconst TEXT_STYLE_PARAGRAPH_FIELDS = [\n 'paragraphSpacing',\n 'paragraphIndent',\n 'listSpacing'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/** The fields each kind of shared style gives what uses it; changing one leaves the style. */\nexport const SHARED_STYLE_FIELDS = {\n fill: ['fills'],\n stroke: ['strokes'],\n text: [...SHARED_TEXT_STYLE_FIELDS, ...TEXT_STYLE_PARAGRAPH_FIELDS],\n effect: ['effects'],\n grid: ['layoutGrids']\n} as const satisfies Record<SharedStyleKind, readonly (keyof SceneNode)[]>\n\n/** The fields that pick a text's face, which its style name names. */\nexport const FACE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic'\n] as const satisfies readonly (keyof SceneNode)[]\n\n/**\n * The face name of characters with `style` over the text: their own, none where they set another\n * face without one (as ranges from HTML or `.pen` do), else the text's.\n */\nexport function rangeFontStyle(\n node: Pick<SceneNode, 'fontStyle'>,\n style: CharacterStyleOverride\n): string | null {\n if (style.fontStyle !== undefined) return style.fontStyle\n return FACE_KEYS.some((key) => style[key] !== undefined) ? null : node.fontStyle\n}\n\nexport function sharedStyleRefKey(kind: SharedStyleKind): (typeof STYLE_REF_KEYS)[SharedStyleKind] {\n return STYLE_REF_KEYS[kind]\n}\n\nexport function sharedStyleTypeForKind(kind: SharedStyleKind): SharedStyleType {\n return STYLE_TYPES[kind]\n}\n\n/** The document's shared style layers, by the source ID layers link them by. */\nexport function sharedStyleLayers(graph: SceneGraph): Map<string, SceneNode> {\n const styles = new Map<string, SceneNode>()\n for (const node of graph.getAllNodes())\n if (node.sharedStyleType !== null && node.source.id) styles.set(node.source.id, node)\n return styles\n}\n\nexport function getSharedStyles(graph: SceneGraph, kind: SharedStyleKind): SharedStyle[] {\n const type = sharedStyleTypeForKind(kind)\n const styles: SharedStyle[] = []\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType !== type || !node.source.id) continue\n styles.push({ id: node.source.id, nodeId: node.id, name: node.name, type })\n }\n return styles.sort((left, right) => left.name.localeCompare(right.name))\n}\n\n/** What a stroke draws along beside its paint: the layer's, not its stroke style's. */\nconst STROKE_LINE_KEYS = ['weight', 'align', 'cap', 'join', 'dashPattern'] as const\n\n/**\n * Whether new strokes only change how their lines run, keeping every paint. A stroke style gives\n * paints only, so such a write keeps it; any other strokes write leaves it, as setting even the\n * same paints does in Figma (live-verified).\n */\nfunction restylesStrokeLines(current: readonly Stroke[], next: readonly Stroke[]): boolean {\n const paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, STROKE_LINE_KEYS))\n const lines = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => STROKE_LINE_KEYS.map((key) => stroke[key]))\n return isEqual(paints(current), paints(next)) && !isEqual(lines(current), lines(next))\n}\n\nexport function styleDetachmentChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const next = { ...changes }\n for (const [kind, fields] of Object.entries(SHARED_STYLE_FIELDS)) {\n const reference = STYLE_REF_KEYS[kind as SharedStyleKind]\n if (reference in changes || !node[reference]) continue\n if (!fields.some((field) => field in changes)) continue\n if (kind === 'stroke' && changes.strokes && restylesStrokeLines(node.strokes, changes.strokes))\n continue\n next[reference] = null\n }\n // A face named for another family, weight, or slant names none; the new one takes its own name.\n const changesFace = FACE_KEYS.some((key) => key in changes && changes[key] !== node[key])\n if (changesFace && !('fontStyle' in changes) && node.fontStyle) {\n next.fontStyle = null\n }\n return next\n}\n\n/** The node of the shared style with `id`, when the document holds one of `type`. */\nexport function findSharedStyle(\n graph: SceneGraph,\n id: string,\n type: SharedStyleType\n): SceneNode | undefined {\n if (!id) return undefined\n for (const node of graph.getAllNodes()) {\n if (node.sharedStyleType === type && node.source.id === id) return node\n }\n return undefined\n}\n\n/** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */\nexport function newSharedStyleId(): string {\n return `S:${randomHex(20)},`\n}\n\nconst INTERNAL_CANVAS_NAME = 'Internal Only Canvas'\n\n/** The page that holds the document's styles out of view, as a `.fig` file keeps them; made once. */\nexport function internalCanvas(graph: SceneGraph): SceneNode {\n const existing = graph.getPages(true).find((page) => page.internalOnly)\n if (existing) return existing\n return graph.createNode('CANVAS', graph.rootId, {\n name: INTERNAL_CANVAS_NAME,\n width: 0,\n height: 0,\n internalOnly: true\n })\n}\n\n/**\n * A paint style's paints as a layer's strokes: every paint, each keeping the weight, alignment,\n * and line style of the stroke it replaces, or of the layer's first; no paints clear the strokes\n * (Figma desktop 126).\n */\nfunction strokesFromStyle(target: SceneNode, style: SceneNode): SceneNode['strokes'] {\n // Without strokes, the layer keeps the weight and alignment a new stroke takes.\n const fallback: Stroke = target.strokes[0] ?? {\n type: 'SOLID',\n color: BLACK,\n opacity: 1,\n visible: true,\n ...newStrokeGeometry(target)\n }\n return copyFills(style.fills).map((paint, index) => ({\n ...paint,\n ...pick(target.strokes[index] ?? fallback, STROKE_LINE_KEYS)\n }))\n}\n\n/**\n * What a layer takes from a shared style it starts using: the style's fields and the reference\n * that keeps it attached. Without the style's node, the reference alone.\n */\nexport function sharedStylePatch(\n kind: SharedStyleKind,\n target: SceneNode,\n styleId: string,\n style: SceneNode | null\n): Partial<SceneNode> {\n const patch: Partial<SceneNode> = { [STYLE_REF_KEYS[kind]]: styleId }\n if (!style) return patch\n if (kind === 'fill') patch.fills = copyFills(style.fills)\n else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)\n else if (kind === 'effect') patch.effects = copyEffects(style.effects)\n else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)\n else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))\n return patch\n}\n\n/** A layer leaving a shared style: it keeps the style's values, without the reference. */\nexport function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {\n return { [STYLE_REF_KEYS[kind]]: null }\n}\n"],"mappings":";;;;;;;AAiBA,MAAM,iBAAiB;CACrB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,oBAAoB,OAAO,OAAO,cAAc;;AAG7D,SAAgB,mBAAmB,MAA2B;CAC5D,OAAO,QAAQ;EACb,GAAG,kBAAkB,KAAK,UAAU,KAAK,MAAM;EAC/C,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACtC,IAAI,KAAK,eAAe,WAAW,CAAC,EAAA,CAAG,KAAK,WAAW,OAAO,WAAW;CAC3E,CAAC;AACH;AAEA,MAAM,cAAc;CAClB,MAAM;CACN,QAAQ;CACR,MAAM;CACN,QAAQ;CACR,MAAM;AACR;;AAGA,MAAa,2BAA2B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,MAAM,8BAA8B;CAClC;CACA;CACA;AACF;;AAGA,MAAa,sBAAsB;CACjC,MAAM,CAAC,OAAO;CACd,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,GAAG,0BAA0B,GAAG,2BAA2B;CAClE,QAAQ,CAAC,SAAS;CAClB,MAAM,CAAC,aAAa;AACtB;;AAGA,MAAa,YAAY;CACvB;CACA;CACA;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AAO,QAAQ,UAAU,UAAU,gBAAgB;CAC7D,EAAE;AACJ;;;;;AAMA,SAAgB,iBACd,MACA,QACA,SACA,OACoB;CACpB,MAAM,QAA4B,GAAG,eAAe,QAAQ,QAAQ;CACpE,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,SAAS,QAAQ,MAAM,QAAQ,UAAU,MAAM,KAAK;MACnD,IAAI,SAAS,UAAU,MAAM,UAAU,iBAAiB,QAAQ,KAAK;MACrE,IAAI,SAAS,UAAU,MAAM,UAAU,YAAY,MAAM,OAAO;MAChE,IAAI,SAAS,QAAQ,MAAM,cAAc,gBAAgB,MAAM,WAAW;MAC1E,OAAO,OAAO,OAAO,gBAAgB,KAAK,OAAO,oBAAoB,IAAI,CAAC,CAAC;CAChF,OAAO;AACT;;AAGA,SAAgB,uBAAuB,MAA2C;CAChF,OAAO,GAAG,eAAe,QAAQ,KAAK;AACxC"}
|
|
@@ -4,8 +4,9 @@ import { ComponentPropertyDefinition, SceneNode, SlotSettings } from "../types.j
|
|
|
4
4
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
5
5
|
declare const DEFAULT_SLOT_SETTINGS: SlotSettings;
|
|
6
6
|
/**
|
|
7
|
-
* The main component
|
|
8
|
-
* instance are not authored there, so a
|
|
7
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
8
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
9
|
+
* layer under an instance has none.
|
|
9
10
|
*/
|
|
10
11
|
declare function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined;
|
|
11
12
|
/** Whether a frame inside a main component can become a slot. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"authoring.d.ts","names":[],"sources":["../../src/slots/authoring.ts"],"mappings":";;;;cAMa,uBAAuB;;;;;;iBAWpB,UAAU,OAAO,YAAY,MAAM,YAAY;;iBAW/C,cAAc,OAAO,YAAY,MAAM;;;;;;iBAiBvC,mBACd,OAAO,YACP,iBACA,aACC;;KAyBS,oBAAoB,QAC9B,KAAK;EACD,eAAe,QAAQ;;;iBAGb,mBACd,OAAO,YACP,iBACA,oBACA,OAAO"}
|
package/dist/slots/authoring.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { slotPropertyId } from "./frames.js";
|
|
2
|
+
import { propertyOwner } from "../components/properties.js";
|
|
2
3
|
//#region src/slots/authoring.ts
|
|
3
4
|
/** The settings a new slot starts with: no limits, any layer allowed. */
|
|
4
5
|
const DEFAULT_SLOT_SETTINGS = {
|
|
@@ -7,13 +8,14 @@ const DEFAULT_SLOT_SETTINGS = {
|
|
|
7
8
|
stretchChildOnInsert: false
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
10
|
-
* The main component
|
|
11
|
-
* instance are not authored there, so a
|
|
11
|
+
* The main component or set that defines the slots inside a layer: the component the layer
|
|
12
|
+
* belongs to, or that component's set. Layers of an instance are not authored there, so a
|
|
13
|
+
* layer under an instance has none.
|
|
12
14
|
*/
|
|
13
15
|
function slotOwner(graph, node) {
|
|
14
16
|
let current = node.parentId ? graph.getNode(node.parentId) : void 0;
|
|
15
17
|
while (current && current.type !== "CANVAS") {
|
|
16
|
-
if (current.type === "COMPONENT") return current;
|
|
18
|
+
if (current.type === "COMPONENT") return propertyOwner(graph, current);
|
|
17
19
|
if (current.type === "INSTANCE") return void 0;
|
|
18
20
|
current = current.parentId ? graph.getNode(current.parentId) : void 0;
|
|
19
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component a layer belongs to,
|
|
1
|
+
{"version":3,"file":"authoring.js","names":[],"sources":["../../src/slots/authoring.ts"],"sourcesContent":["import { propertyOwner } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport type { ComponentPropertyDefinition, SceneNode, SlotSettings } from '../types'\nimport { slotPropertyId } from './frames'\n\n/** The settings a new slot starts with: no limits, any layer allowed. */\nexport const DEFAULT_SLOT_SETTINGS: SlotSettings = {\n allowPreferredValuesOnly: false,\n displayEmptyByDefault: false,\n stretchChildOnInsert: false\n}\n\n/**\n * The main component or set that defines the slots inside a layer: the component the layer\n * belongs to, or that component's set. Layers of an instance are not authored there, so a\n * layer under an instance has none.\n */\nexport function slotOwner(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = node.parentId ? graph.getNode(node.parentId) : undefined\n while (current && current.type !== 'CANVAS') {\n if (current.type === 'COMPONENT') return propertyOwner(graph, current)\n if (current.type === 'INSTANCE') return undefined\n current = current.parentId ? graph.getNode(current.parentId) : undefined\n }\n return undefined\n}\n\n/** Whether a frame inside a main component can become a slot. */\nexport function canCreateSlot(graph: SceneGraph, node: SceneNode): boolean {\n return node.type === 'FRAME' && !slotPropertyId(node) && !!slotOwner(graph, node)\n}\n\nfunction uniqueSlotName(owner: SceneNode, base: string): string {\n const taken = new Set(owner.componentPropertyDefinitions.map((definition) => definition.name))\n if (!taken.has(base)) return base\n let index = 2\n while (taken.has(`${base} ${index}`)) index++\n return `${base} ${index}`\n}\n\n/**\n * Make a frame of a main component a slot: define a SLOT property, named after the frame, on\n * the component and bind the frame's children to it. Instances pick up the slot on their next\n * sync.\n */\nexport function createSlotProperty(\n graph: SceneGraph,\n frameId: string,\n id: string\n): ComponentPropertyDefinition | null {\n const frame = graph.getNode(frameId)\n const owner = frame && canCreateSlot(graph, frame) ? slotOwner(graph, frame) : undefined\n if (!frame || !owner) return null\n const definition: ComponentPropertyDefinition = {\n id,\n name: uniqueSlotName(owner, frame.name.trim() || 'Slot'),\n type: 'SLOT',\n defaultValue: '',\n preferredValues: [],\n slotSettings: { ...DEFAULT_SLOT_SETTINGS }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: [...owner.componentPropertyDefinitions, definition]\n })\n graph.updateNode(frame.id, {\n componentPropertyReferences: [\n ...frame.componentPropertyReferences,\n { propertyId: id, field: 'SLOT_CONTENT' }\n ]\n })\n return definition\n}\n\n/** What a slot's settings panel can change. */\nexport type SlotPropertyPatch = Partial<\n Pick<ComponentPropertyDefinition, 'name' | 'description' | 'preferredValues'>\n> & { slotSettings?: Partial<SlotSettings> }\n\n/** Change a slot property's name, description, preferred components, or limits. */\nexport function updateSlotProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string,\n patch: SlotPropertyPatch\n): boolean {\n const owner = graph.getNode(ownerId)\n const current = owner?.componentPropertyDefinitions.find(\n (definition) => definition.id === propertyId && definition.type === 'SLOT'\n )\n if (!owner || !current) return false\n const { slotSettings, ...fields } = patch\n const next: ComponentPropertyDefinition = {\n ...current,\n ...fields,\n slotSettings: { ...DEFAULT_SLOT_SETTINGS, ...current.slotSettings, ...slotSettings }\n }\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.map((definition) =>\n definition.id === propertyId ? next : definition\n )\n })\n return true\n}\n"],"mappings":";;;;AAMA,MAAa,wBAAsC;CACjD,0BAA0B;CAC1B,uBAAuB;CACvB,sBAAsB;AACxB;;;;;;AAOA,SAAgB,UAAU,OAAmB,MAAwC;CACnF,IAAI,UAAU,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;CAC7D,OAAO,WAAW,QAAQ,SAAS,UAAU;EAC3C,IAAI,QAAQ,SAAS,aAAa,OAAO,cAAc,OAAO,OAAO;EACrE,IAAI,QAAQ,SAAS,YAAY,OAAO,KAAA;EACxC,UAAU,QAAQ,WAAW,MAAM,QAAQ,QAAQ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AAc,GAAG,WAAW;CACpC,MAAM,OAAoC;EACxC,GAAG;EACH,GAAG;EACH,cAAc;GAAE,GAAG;GAAuB,GAAG,QAAQ;GAAc,GAAG;EAAa;CACrF;CACA,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,KAAK,eACpE,WAAW,OAAO,aAAa,OAAO,UACxC,EACF,CAAC;CACD,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"content.d.ts","names":[],"sources":["../../src/slots/content.ts"],"mappings":";;;;;;;;;;KAeY;EACN;;EACA;EAAc,OAAO;EAAW,UAAU;EAAW;;EACrD;EAAgB,OAAO;;iBAYb,UAAU,OAAO,YAAY,mBAAmB;;;;;;iBAmChD,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBA0Cd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa;;;iBAcd,iBACd,OAAO,YACP,OAAO,QAAQ;EAAa"}
|
package/dist/slots/content.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceOverride, setInstanceOverride } from "../instances/overrides.js";
|
|
2
2
|
import { isGeneratedFrame } from "../generated/index.js";
|
|
3
3
|
import { ownsSlotContent, slotPropertyId } from "./frames.js";
|
|
4
|
+
import { applyBoundPaintColorsIn } from "../variables/paints.js";
|
|
4
5
|
import { cloneChildrenWithMapping } from "../instances/sync.js";
|
|
5
6
|
//#region src/slots/content.ts
|
|
6
7
|
function parentOf(graph, node) {
|
|
@@ -92,7 +93,9 @@ function resetSlotContent(graph, scope) {
|
|
|
92
93
|
Reflect.deleteProperty(assignments, propertyId);
|
|
93
94
|
graph.updateNode(instance.id, { componentPropertyAssignments: assignments });
|
|
94
95
|
const source = componentSource(instance, frame);
|
|
95
|
-
if (source
|
|
96
|
+
if (!source || !graph.nodes.has(source)) return;
|
|
97
|
+
cloneChildrenWithMapping(graph, source, frame.id);
|
|
98
|
+
for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId);
|
|
96
99
|
}
|
|
97
100
|
/** Remove everything from the slot; the instance keeps owning it, now empty. */
|
|
98
101
|
function clearSlotContent(graph, scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction parentOf(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.nodes.get(node.parentId) : undefined\n}\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = parentOf(graph, node)\n while (current && current.type !== 'INSTANCE') current = parentOf(graph, current)\n return current\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n let current = graph.nodes.get(parentId)\n while (current) {\n const propertyId = slotPropertyId(current)\n if (propertyId) {\n const instance = nearestInstance(graph, current)\n return instance ? { kind: 'slot', frame: current, instance, propertyId } : { kind: 'free' }\n }\n if (current.type === 'INSTANCE' || isGeneratedFrame(current))\n return { kind: 'locked', owner: current }\n current = parentOf(graph, current)\n }\n return { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n graph.willChangeNode(instance)\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n graph.willChangeNode(node)\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (source
|
|
1
|
+
{"version":3,"file":"content.js","names":[],"sources":["../../src/slots/content.ts"],"sourcesContent":["import { isGeneratedFrame } from '../generated'\nimport type { SceneGraph } from '../graph'\nimport { getInstanceOverride, setInstanceOverride } from '../instances/overrides'\nimport { cloneChildrenWithMapping } from '../instances/sync'\nimport type { SceneNode } from '../types'\nimport { applyBoundPaintColorsIn } from '../variables/paints'\nimport { ownsSlotContent, slotPropertyId } from './frames'\n\n/**\n * Where layers may be added, moved, or removed under a parent:\n * - `free`: outside any instance, or inside a component definition;\n * - `slot`: inside a slot of an instance, whose content the instance owns or can claim;\n * - `locked`: anywhere else inside an instance, whose layers come from its component, or inside a\n * generated frame such as a sticky note, whose layers come from its template.\n */\nexport type SlotScope =\n | { kind: 'free' }\n | { kind: 'slot'; frame: SceneNode; instance: SceneNode; propertyId: string }\n | { kind: 'locked'; owner: SceneNode }\n\nfunction parentOf(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n return node.parentId ? graph.nodes.get(node.parentId) : undefined\n}\n\nfunction nearestInstance(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n let current = parentOf(graph, node)\n while (current && current.type !== 'INSTANCE') current = parentOf(graph, current)\n return current\n}\n\nexport function slotScope(graph: SceneGraph, parentId: string): SlotScope {\n let current = graph.nodes.get(parentId)\n while (current) {\n const propertyId = slotPropertyId(current)\n if (propertyId) {\n const instance = nearestInstance(graph, current)\n return instance ? { kind: 'slot', frame: current, instance, propertyId } : { kind: 'free' }\n }\n if (current.type === 'INSTANCE' || isGeneratedFrame(current))\n return { kind: 'locked', owner: current }\n current = parentOf(graph, current)\n }\n return { kind: 'free' }\n}\n\n/** Every layer below `node`; `enterInstances` also walks the layers of nested instances. */\nfunction descendants(graph: SceneGraph, node: SceneNode, enterInstances: boolean): SceneNode[] {\n const result: SceneNode[] = []\n const visit = (parent: SceneNode): void => {\n for (const childId of parent.childIds) {\n const child = graph.nodes.get(childId)\n if (!child) continue\n result.push(child)\n if (enterInstances || child.type !== 'INSTANCE') visit(child)\n }\n }\n visit(node)\n return result\n}\n\n/**\n * Make the instance own its slot's content, as Figma does on the first edit: the layers\n * stay where they are, but stop following the component. Overrides the instance held for\n * them become their own values, or move to the nested instance they belong to.\n */\nexport function claimSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n if (ownsSlotContent(graph, frame, propertyId)) return\n graph.willChangeNode(instance)\n const overrides = instance.instanceOverrides\n for (const node of descendants(graph, frame, false)) {\n overrides.descendants.delete(node.id)\n if (node.type !== 'INSTANCE') {\n graph.updateNode(node.id, { componentId: null })\n continue\n }\n // A nested instance keeps the overrides its former owner applied inside it.\n graph.willChangeNode(node)\n for (const inner of descendants(graph, node, true)) {\n const fields = overrides.descendants.get(inner.id)\n if (!fields) continue\n for (const [field, value] of fields)\n if (field !== 'sourceComponentId')\n setInstanceOverride(node.instanceOverrides, node.id, inner.id, field, value)\n overrides.descendants.delete(inner.id)\n }\n graph.updateNode(node.id, { instanceOverrides: node.instanceOverrides })\n }\n graph.updateNode(instance.id, {\n instanceOverrides: overrides,\n componentPropertyAssignments: { ...instance.componentPropertyAssignments, [propertyId]: '' }\n })\n}\n\n/** The component layer an instance layer was cloned from. */\nfunction componentSource(instance: SceneNode, node: SceneNode): string | null {\n const mapped = getInstanceOverride(\n instance.instanceOverrides,\n instance.id,\n node.id,\n 'sourceComponentId'\n )\n return typeof mapped === 'string' ? mapped : node.componentId\n}\n\n/** Return the slot to its component's content: the instance stops owning it. */\nexport function resetSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n const { frame, instance, propertyId } = scope\n for (const childId of Array.from(frame.childIds)) graph.deleteNode(childId)\n const assignments = { ...instance.componentPropertyAssignments }\n Reflect.deleteProperty(assignments, propertyId)\n graph.updateNode(instance.id, { componentPropertyAssignments: assignments })\n const source = componentSource(instance, frame)\n if (!source || !graph.nodes.has(source)) return\n cloneChildrenWithMapping(graph, source, frame.id)\n for (const childId of frame.childIds) applyBoundPaintColorsIn(graph, childId)\n}\n\n/** Remove everything from the slot; the instance keeps owning it, now empty. */\nexport function clearSlotContent(\n graph: SceneGraph,\n scope: Extract<SlotScope, { kind: 'slot' }>\n): void {\n claimSlotContent(graph, scope)\n for (const childId of Array.from(scope.frame.childIds)) graph.deleteNode(childId)\n}\n"],"mappings":";;;;;;AAoBA,SAAS,SAAS,OAAmB,MAAwC;CAC3E,OAAO,KAAK,WAAW,MAAM,MAAM,IAAI,KAAK,QAAQ,IAAI,KAAA;AAC1D;AAEA,SAAS,gBAAgB,OAAmB,MAAwC;CAClF,IAAI,UAAU,SAAS,OAAO,IAAI;CAClC,OAAO,WAAW,QAAQ,SAAS,YAAY,UAAU,SAAS,OAAO,OAAO;CAChF,OAAO;AACT;AAEA,SAAgB,UAAU,OAAmB,UAA6B;CACxE,IAAI,UAAU,MAAM,MAAM,IAAI,QAAQ;CACtC,OAAO,SAAS;EACd,MAAM,aAAa,eAAe,OAAO;EACzC,IAAI,YAAY;GACd,MAAM,WAAW,gBAAgB,OAAO,OAAO;GAC/C,OAAO,WAAW;IAAE,MAAM;IAAQ,OAAO;IAAS;IAAU;GAAW,IAAI,EAAE,MAAM,OAAO;EAC5F;EACA,IAAI,QAAQ,SAAS,cAAc,iBAAiB,OAAO,GACzD,OAAO;GAAE,MAAM;GAAU,OAAO;EAAQ;EAC1C,UAAU,SAAS,OAAO,OAAO;CACnC;CACA,OAAO,EAAE,MAAM,OAAO;AACxB;;AAGA,SAAS,YAAY,OAAmB,MAAiB,gBAAsC;CAC7F,MAAM,SAAsB,CAAC;CAC7B,MAAM,SAAS,WAA4B;EACzC,KAAK,MAAM,WAAW,OAAO,UAAU;GACrC,MAAM,QAAQ,MAAM,M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C,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;CAC1E,MAAM,cAAc,EAAE,GAAG,SAAS,6BAA6B;CAC/D,QAAQ,eAAe,aAAa,UAAU;CAC9C,MAAM,WAAW,SAAS,IAAI,EAAE,8BAA8B,YAAY,CAAC;CAC3E,MAAM,SAAS,gBAAgB,UAAU,KAAK;CAC9C,IAAI,CAAC,UAAU,CAAC,MAAM,MAAM,IAAI,MAAM,GAAG;CACzC,yBAAyB,OAAO,QAAQ,MAAM,EAAE;CAChD,KAAK,MAAM,WAAW,MAAM,UAAU,wBAAwB,OAAO,OAAO;AAC9E;;AAGA,SAAgB,iBACd,OACA,OACM;CACN,iBAAiB,OAAO,KAAK;CAC7B,KAAK,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,QAAQ,GAAG,MAAM,WAAW,OAAO;AAClF"}
|
package/dist/text/direction.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LayoutDirection, SceneNode, TextDirection } from "../types.js";
|
|
2
2
|
//#region src/text/direction.d.ts
|
|
3
|
+
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
4
|
+
declare function containsRTLText(text: string): boolean;
|
|
3
5
|
declare function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'>;
|
|
4
6
|
declare function resolveTextDirection(direction: TextDirection, text: string): Exclude<TextDirection, 'AUTO'>;
|
|
5
7
|
declare function resolveNodeTextDirection(node: Pick<SceneNode, 'textDirection' | 'text'>): 'LTR' | 'RTL';
|
|
@@ -9,5 +11,5 @@ declare function resolveNodeLayoutDirection(node: {
|
|
|
9
11
|
declare function isLogicalTextAlignStart(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
10
12
|
declare function isLogicalTextAlignEnd(node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>): boolean;
|
|
11
13
|
//#endregion
|
|
12
|
-
export { detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
14
|
+
export { containsRTLText, detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
13
15
|
//# sourceMappingURL=direction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"direction.d.ts","names":[],"sources":["../../src/text/direction.ts"],"mappings":";;;iBAOgB,gBAAgB;iBAIhB,oBAAoB,eAAe,QAAQ;iBAQ3C,qBACd,WAAW,eACX,eACC,QAAQ;iBAIK,yBACd,MAAM,KAAK;iBAKG,2BACd;EAAQ,kBAAkB;GAC1B,qBAAoB,QAAQ,2BAC3B,QAAQ;iBAMK,wBACd,MAAM,KAAK;iBASG,sBACd,MAAM,KAAK"}
|
package/dist/text/direction.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
//#region src/text/direction.ts
|
|
2
2
|
const RTL_CHAR_RE = /\p{Script=Arabic}|\p{Script=Hebrew}|\p{Script=Syriac}|\p{Script=Thaana}|\p{Script=Nko}|\p{Script=Adlam}/u;
|
|
3
3
|
const LTR_CHAR_RE = /\p{Script=Latin}|\p{Script=Cyrillic}|\p{Script=Greek}/u;
|
|
4
|
+
/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */
|
|
5
|
+
function containsRTLText(text) {
|
|
6
|
+
return RTL_CHAR_RE.test(text);
|
|
7
|
+
}
|
|
4
8
|
function detectTextDirection(text) {
|
|
5
9
|
for (const char of text) {
|
|
6
10
|
if (RTL_CHAR_RE.test(char)) return "RTL";
|
|
@@ -26,6 +30,6 @@ function isLogicalTextAlignEnd(node) {
|
|
|
26
30
|
return direction === "LTR" && node.textAlignHorizontal === "RIGHT" || direction === "RTL" && node.textAlignHorizontal === "LEFT";
|
|
27
31
|
}
|
|
28
32
|
//#endregion
|
|
29
|
-
export { detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
33
|
+
export { containsRTLText, detectTextDirection, isLogicalTextAlignEnd, isLogicalTextAlignStart, resolveNodeLayoutDirection, resolveNodeTextDirection, resolveTextDirection };
|
|
30
34
|
|
|
31
35
|
//# sourceMappingURL=direction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n node: Pick<SceneNode, 'textDirection' | 'text'>\n): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n\nexport function isLogicalTextAlignStart(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')\n )\n}\n\nexport function isLogicalTextAlignEnd(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n"],"mappings":";AAEA,MAAM,cACJ;AACF,MAAM,cAAc;
|
|
1
|
+
{"version":3,"file":"direction.js","names":[],"sources":["../../src/text/direction.ts"],"sourcesContent":["import type { LayoutDirection, SceneNode, TextDirection } from '../types'\n\nconst RTL_CHAR_RE =\n /\\p{Script=Arabic}|\\p{Script=Hebrew}|\\p{Script=Syriac}|\\p{Script=Thaana}|\\p{Script=Nko}|\\p{Script=Adlam}/u\nconst LTR_CHAR_RE = /\\p{Script=Latin}|\\p{Script=Cyrillic}|\\p{Script=Greek}/u\n\n/** Whether the text has a letter of a right-to-left script, such as Arabic or Hebrew. */\nexport function containsRTLText(text: string): boolean {\n return RTL_CHAR_RE.test(text)\n}\n\nexport function detectTextDirection(text: string): Exclude<TextDirection, 'AUTO'> {\n for (const char of text) {\n if (RTL_CHAR_RE.test(char)) return 'RTL'\n if (LTR_CHAR_RE.test(char)) return 'LTR'\n }\n return 'LTR'\n}\n\nexport function resolveTextDirection(\n direction: TextDirection,\n text: string\n): Exclude<TextDirection, 'AUTO'> {\n return direction === 'AUTO' ? detectTextDirection(text) : direction\n}\n\nexport function resolveNodeTextDirection(\n node: Pick<SceneNode, 'textDirection' | 'text'>\n): 'LTR' | 'RTL' {\n return resolveTextDirection(node.textDirection, node.text)\n}\n\nexport function resolveNodeLayoutDirection(\n node: { layoutDirection?: LayoutDirection },\n inheritedDirection: Exclude<LayoutDirection, 'AUTO'> = 'LTR'\n): Exclude<LayoutDirection, 'AUTO'> {\n return !node.layoutDirection || node.layoutDirection === 'AUTO'\n ? inheritedDirection\n : node.layoutDirection\n}\n\nexport function isLogicalTextAlignStart(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'LEFT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'RIGHT')\n )\n}\n\nexport function isLogicalTextAlignEnd(\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n): boolean {\n const direction = resolveNodeTextDirection(node)\n return (\n (direction === 'LTR' && node.textAlignHorizontal === 'RIGHT') ||\n (direction === 'RTL' && node.textAlignHorizontal === 'LEFT')\n )\n}\n"],"mappings":";AAEA,MAAM,cACJ;AACF,MAAM,cAAc;;AAGpB,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,YAAY,KAAK,IAAI;AAC9B;AAEA,SAAgB,oBAAoB,MAA8C;CAChF,KAAK,MAAM,QAAQ,MAAM;EACvB,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;EACnC,IAAI,YAAY,KAAK,IAAI,GAAG,OAAO;CACrC;CACA,OAAO;AACT;AAEA,SAAgB,qBACd,WACA,MACgC;CAChC,OAAO,cAAc,SAAS,oBAAoB,IAAI,IAAI;AAC5D;AAEA,SAAgB,yBACd,MACe;CACf,OAAO,qBAAqB,KAAK,eAAe,KAAK,IAAI;AAC3D;AAEA,SAAgB,2BACd,MACA,qBAAuD,OACrB;CAClC,OAAO,CAAC,KAAK,mBAAmB,KAAK,oBAAoB,SACrD,qBACA,KAAK;AACX;AAEA,SAAgB,wBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,UACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD;AAEA,SAAgB,sBACd,MACS;CACT,MAAM,YAAY,yBAAyB,IAAI;CAC/C,OACG,cAAc,SAAS,KAAK,wBAAwB,WACpD,cAAc,SAAS,KAAK,wBAAwB;AAEzD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/transfer/apply.ts"],"mappings":";;;KAQY,oBAAoB,kBAAkB;;iBA0ClC,mBAAmB,QAAQ,YAAY,OAAO"}
|
package/dist/transfer/apply.js
CHANGED
|
@@ -15,7 +15,6 @@ function validate(target, plan) {
|
|
|
15
15
|
reserved.add(id);
|
|
16
16
|
};
|
|
17
17
|
prepareVariableTransfer(plan.variables, plan.collections, variableIdentityReferences(plan.variables, plan.collections));
|
|
18
|
-
for (const [id, mode] of plan.activeModes) if (!plan.collections.find((collection) => collection.id === id)?.modes.some((entry) => entry.modeId === mode)) throw new Error(`Invalid transferred active mode ${id}:${mode}`);
|
|
19
18
|
for (const collection of plan.collections) claim(collection.id);
|
|
20
19
|
for (const variable of plan.variables) claim(variable.id);
|
|
21
20
|
const parents = new Set(target.nodes.keys());
|
|
@@ -41,7 +40,6 @@ function applyGraphTransfer(target, input) {
|
|
|
41
40
|
try {
|
|
42
41
|
for (const collection of plan.collections) target.addCollection(collection);
|
|
43
42
|
for (const variable of plan.variables) target.addVariable(variable);
|
|
44
|
-
for (const [id, mode] of plan.activeModes) target.activeMode.set(id, mode);
|
|
45
43
|
for (const [hash, bytes] of plan.images) if (!target.images.has(hash)) target.images.set(hash, bytes);
|
|
46
44
|
for (const node of plan.nodes) target.createNodeWithId(node.id, node.type, node.parentId, {
|
|
47
45
|
...node.props,
|
|
@@ -50,10 +48,7 @@ function applyGraphTransfer(target, input) {
|
|
|
50
48
|
} catch (error) {
|
|
51
49
|
for (const node of plan.nodes.toReversed()) if (target.getNode(node.id)) target.deleteNode(node.id);
|
|
52
50
|
for (const variable of plan.variables) target.variables.delete(variable.id);
|
|
53
|
-
for (const collection of plan.collections)
|
|
54
|
-
target.variableCollections.delete(collection.id);
|
|
55
|
-
target.activeMode.delete(collection.id);
|
|
56
|
-
}
|
|
51
|
+
for (const collection of plan.collections) target.variableCollections.delete(collection.id);
|
|
57
52
|
for (const hash of imageIds) target.images.delete(hash);
|
|
58
53
|
throw error;
|
|
59
54
|
}
|