@pairdraw/scene-graph 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +2 -2
- package/dist/components/properties.d.ts +6 -1
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +14 -3
- package/dist/components/properties.js.map +1 -1
- package/dist/copy.d.ts.map +1 -1
- package/dist/copy.js +1 -0
- package/dist/copy.js.map +1 -1
- package/dist/css/gradient.d.ts +23 -0
- package/dist/css/gradient.d.ts.map +1 -0
- package/dist/css/gradient.js +404 -0
- package/dist/css/gradient.js.map +1 -0
- package/dist/css/index.d.ts +2 -1
- package/dist/css/index.js +2 -1
- package/dist/css/shadows.d.ts.map +1 -1
- package/dist/css/shadows.js +2 -13
- package/dist/css/shadows.js.map +1 -1
- package/dist/css/values.js +24 -1
- package/dist/css/values.js.map +1 -1
- package/dist/font-style.d.ts +2 -1
- package/dist/font-style.d.ts.map +1 -1
- package/dist/font-style.js +31 -6
- package/dist/font-style.js.map +1 -1
- package/dist/geometry.d.ts +10 -1
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +21 -6
- package/dist/geometry.js.map +1 -1
- package/dist/graph.d.ts +49 -3
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +179 -17
- package/dist/graph.js.map +1 -1
- package/dist/hit-test.d.ts +3 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +38 -23
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/index.d.ts +2 -2
- package/dist/icons/index.js +2 -2
- package/dist/icons/model.d.ts +8 -2
- package/dist/icons/model.d.ts.map +1 -1
- package/dist/icons/model.js +10 -1
- package/dist/icons/model.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/instances/assignments.js +40 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/fields.d.ts +2 -2
- package/dist/instances/fields.d.ts.map +1 -1
- package/dist/instances/fields.js +18 -1
- package/dist/instances/fields.js.map +1 -1
- package/dist/instances/index.d.ts +38 -2
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +134 -15
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/overrides.d.ts +10 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +28 -2
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/placement.js +1 -1
- package/dist/instances/placement.js.map +1 -1
- package/dist/instances/swap-overrides.js +94 -0
- package/dist/instances/swap-overrides.js.map +1 -0
- package/dist/instances/sync.js +90 -12
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/draw-order.d.ts +11 -0
- package/dist/layout/draw-order.d.ts.map +1 -0
- package/dist/layout/draw-order.js +14 -0
- package/dist/layout/draw-order.js.map +1 -0
- package/dist/layout/index.d.ts +2 -1
- package/dist/layout/index.js +2 -1
- package/dist/node-defaults.d.ts +11 -1
- package/dist/node-defaults.d.ts.map +1 -1
- package/dist/node-defaults.js +16 -1
- 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/resize.d.ts +29 -9
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +95 -62
- package/dist/resize.js.map +1 -1
- package/dist/shared-styles.d.ts.map +1 -1
- package/dist/shared-styles.js +1 -8
- 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/source-metadata.d.ts +4 -2
- package/dist/source-metadata.d.ts.map +1 -1
- package/dist/source-metadata.js +10 -3
- package/dist/source-metadata.js.map +1 -1
- package/dist/strokes.d.ts +39 -0
- package/dist/strokes.d.ts.map +1 -0
- package/dist/strokes.js +104 -0
- package/dist/strokes.js.map +1 -0
- package/dist/text/direction.d.ts +6 -2
- package/dist/text/direction.d.ts.map +1 -1
- package/dist/text/direction.js +2 -1
- package/dist/text/direction.js.map +1 -1
- package/dist/text/index.d.ts +3 -3
- package/dist/text/index.js +3 -3
- package/dist/text/lengths.d.ts +6 -1
- package/dist/text/lengths.d.ts.map +1 -1
- package/dist/text/lengths.js +10 -1
- package/dist/text/lengths.js.map +1 -1
- package/dist/text/overflow.d.ts +22 -6
- package/dist/text/overflow.d.ts.map +1 -1
- package/dist/text/overflow.js +24 -6
- package/dist/text/overflow.js.map +1 -1
- package/dist/transfer/nodes.js +9 -5
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +18 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/undo.d.ts +36 -1
- package/dist/undo.d.ts.map +1 -1
- package/dist/undo.js +52 -2
- package/dist/undo.js.map +1 -1
- package/dist/variables/bindings.d.ts +14 -6
- package/dist/variables/bindings.d.ts.map +1 -1
- package/dist/variables/bindings.js +42 -67
- package/dist/variables/bindings.js.map +1 -1
- package/dist/variables/formula/signatures.js +1 -1
- package/dist/variables/index.d.ts +10 -4
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +58 -15
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/paints.d.ts +101 -0
- package/dist/variables/paints.d.ts.map +1 -0
- package/dist/variables/paints.js +313 -0
- package/dist/variables/paints.js.map +1 -0
- package/dist/variables/resolution.d.ts +14 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +44 -4
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +17 -0
- package/dist/variables/subtree.js.map +1 -0
- package/package.json +6 -1
- package/src/components/properties.ts +17 -2
- package/src/copy.ts +1 -0
- package/src/css/gradient.ts +438 -0
- package/src/css/index.ts +1 -0
- package/src/css/shadows.ts +2 -18
- package/src/css/values.ts +27 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +25 -6
- package/src/graph.ts +207 -17
- package/src/hit-test.ts +67 -24
- package/src/icons/model.ts +11 -1
- package/src/instances/assignments.ts +65 -7
- package/src/instances/fields.ts +21 -0
- package/src/instances/index.ts +237 -14
- package/src/instances/overrides.ts +36 -1
- package/src/instances/placement.ts +5 -1
- package/src/instances/swap-overrides.ts +123 -0
- package/src/instances/sync.ts +139 -12
- package/src/layout/draw-order.ts +13 -0
- package/src/layout/index.ts +1 -0
- package/src/node-defaults.ts +21 -0
- package/src/order-keys.ts +6 -0
- package/src/resize.ts +133 -69
- package/src/shared-styles.ts +1 -3
- package/src/slots/authoring.ts +5 -3
- package/src/slots/content.ts +4 -1
- package/src/source-metadata.ts +18 -3
- package/src/strokes.ts +121 -0
- package/src/text/direction.ts +7 -5
- package/src/text/lengths.ts +10 -0
- package/src/text/overflow.ts +30 -7
- package/src/transfer/nodes.ts +7 -5
- package/src/types.ts +17 -0
- package/src/undo.ts +79 -2
- package/src/variables/bindings.ts +52 -74
- package/src/variables/index.ts +80 -14
- package/src/variables/paints.ts +413 -0
- package/src/variables/resolution.ts +56 -5
- package/src/variables/subtree.ts +15 -0
package/dist/layout/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { drawnChildIds } from "./draw-order.js";
|
|
1
2
|
import { aspectRatioLockEditable, enforcedAspectRatio, lockedAspectRatioTarget, recapturedAspectRatio, sizeKeepingAspectRatio } from "./aspect-ratio.js";
|
|
2
3
|
import { autoLayoutSizingFields, fillSizingFields, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, textAutoResizeFor } from "./sizing.js";
|
|
3
4
|
import { paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign } from "./keywords.js";
|
|
4
5
|
import { AUTO_LAYOUT_GRID_COUNT, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections } from "./guides.js";
|
|
5
|
-
export { AUTO_LAYOUT_GRID_COUNT, aspectRatioLockEditable, autoLayoutSizingFields, enforcedAspectRatio, fillSizingFields, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|
|
6
|
+
export { AUTO_LAYOUT_GRID_COUNT, aspectRatioLockEditable, autoLayoutSizingFields, drawnChildIds, enforcedAspectRatio, fillSizingFields, isAutoGridCount, layoutGridCount, layoutGuideLines, layoutGuideSections, layoutSizing, layoutSizingError, layoutSizingInParent, layoutSizingOptions, layoutSizingUpdates, lockedAspectRatioTarget, paddingFromShorthand, parseAutoLayoutDirection, parseCounterAxisAlign, parseLayoutAlignSelf, parsePrimaryAxisAlign, recapturedAspectRatio, sizeKeepingAspectRatio, textAutoResizeFor };
|
package/dist/node-defaults.d.ts
CHANGED
|
@@ -8,6 +8,16 @@ declare function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'];
|
|
|
8
8
|
* with none. Adding a stroke from the panel and from the plugin API both go through here.
|
|
9
9
|
*/
|
|
10
10
|
declare function newStrokeGeometry(node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>): Pick<SceneNode['strokes'][number], 'weight' | 'align'>;
|
|
11
|
+
/**
|
|
12
|
+
* The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words
|
|
13
|
+
* of a compound type apart, so a shape with text is a "Shape with text".
|
|
14
|
+
*/
|
|
15
|
+
declare function defaultNodeName(type: NodeType): string;
|
|
16
|
+
/**
|
|
17
|
+
* The name Figma gives a layer that follows its text: the characters trimmed, on one line, and
|
|
18
|
+
* the type's own name while they hold nothing.
|
|
19
|
+
*/
|
|
20
|
+
declare function textLayerName(type: NodeType, text: string): string;
|
|
11
21
|
declare function createDefaultNode(generateId: () => string, type: NodeType, overrides?: Partial<SceneNode>): SceneNode;
|
|
12
22
|
/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */
|
|
13
23
|
declare const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType>;
|
|
@@ -15,5 +25,5 @@ declare const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType>;
|
|
|
15
25
|
declare const SIDE_STROKE_TYPES: ReadonlySet<NodeType>;
|
|
16
26
|
declare const CONTAINER_TYPES: Set<NodeType>;
|
|
17
27
|
//#endregion
|
|
18
|
-
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, newStrokeGeometry };
|
|
28
|
+
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultNodeName, defaultStrokeAlign, newStrokeGeometry, textLayerName };
|
|
19
29
|
//# sourceMappingURL=node-defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAWgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;
|
|
1
|
+
{"version":3,"file":"node-defaults.d.ts","names":[],"sources":["../src/node-defaults.ts"],"mappings":";;iBAWgB,+BAA+B;;iBA4B/B,mBAAmB,MAAM,WAAW;;;;;iBASpC,kBACd,MAAM,KAAK,yDACV,KAAK;;;;;iBASQ,gBAAgB,MAAM;;;;;iBAStB,cAAc,MAAM,UAAU;iBAQ9B,kBACd,0BACA,MAAM,UACN,YAAW,QAAQ,aAClB;;cAoLU,wBAAwB,YAAY;;cAMpC,mBAAmB,YAAY;cAQ/B,iBAAe,IAAA"}
|
package/dist/node-defaults.js
CHANGED
|
@@ -38,6 +38,21 @@ function newStrokeGeometry(node) {
|
|
|
38
38
|
align: first?.align ?? node.strokeAlign
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words
|
|
43
|
+
* of a compound type apart, so a shape with text is a "Shape with text".
|
|
44
|
+
*/
|
|
45
|
+
function defaultNodeName(type) {
|
|
46
|
+
const words = type.toLowerCase().replaceAll("_", " ");
|
|
47
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The name Figma gives a layer that follows its text: the characters trimmed, on one line, and
|
|
51
|
+
* the type's own name while they hold nothing.
|
|
52
|
+
*/
|
|
53
|
+
function textLayerName(type, text) {
|
|
54
|
+
return text.split(/\r\n|\r|\n/).map((line) => line.trim()).filter((line) => line !== "").join(" ") || defaultNodeName(type);
|
|
55
|
+
}
|
|
41
56
|
function createDefaultNode(generateId, type, overrides = {}) {
|
|
42
57
|
const node = {
|
|
43
58
|
id: generateId(),
|
|
@@ -241,6 +256,6 @@ const CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
241
256
|
"INSTANCE"
|
|
242
257
|
]);
|
|
243
258
|
//#endregion
|
|
244
|
-
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultStrokeAlign, newStrokeGeometry };
|
|
259
|
+
export { CONTAINER_TYPES, FITTED_CONTAINER_TYPES, SIDE_STROKE_TYPES, createDefaultNode, createDefaultSourceMetadata, defaultNodeName, defaultStrokeAlign, newStrokeGeometry, textLayerName };
|
|
245
260
|
|
|
246
261
|
//# sourceMappingURL=node-defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n const node = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\n prototypeReactions: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n node.effects = normalizeEffects(node.effects)\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;;AAWA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BAA0B,CAAC;GAC3B,mBAAmB,CAAC;GACpB,gCAAgC;GAChC,oBAAoB;EACtB;CACF;AACF;;AAUA,SAAgB,mBAAmB,MAA0C;CAC3E,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO;CACjD,OAAO,SAAS,SAAS,YAAY;AACvC;;;;;AAMA,SAAgB,kBACd,MACwD;CACxD,MAAM,QAAQ,KAAK,QAAQ,GAAG,CAAC;CAC/B,OAAO;EAAE,QAAQ,OAAO,UAAU,KAAK;EAAc,OAAO,OAAO,SAAS,KAAK;CAAY;AAC/F;AAEA,SAAgB,kBACd,YACA,MACA,YAAgC,CAAC,GACtB;CACX,MAAM,OAAO;EACX,IAAI,WAAW;EACf;EACA,MAAM,KAAK,OAAO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ACb,kBAAkB,KAAA;EAClB,GAAG;CACL;CACA,KAAK,UAAU,iBAAiB,KAAK,OAAO;CAC5C,OAAO;AACT;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { normalizeEffects } from './effects'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/**\n * The name a layer of `type` carries when nothing names it, as Figma writes a type's name: words\n * of a compound type apart, so a shape with text is a \"Shape with text\".\n */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\n/**\n * The name Figma gives a layer that follows its text: the characters trimmed, on one line, and\n * the type's own name while they hold nothing.\n */\nexport function textLayerName(type: NodeType, text: string): string {\n const lines = text\n .split(/\\r\\n|\\r|\\n/)\n .map((line) => line.trim())\n .filter((line) => line !== '')\n return lines.join(' ') || defaultNodeName(type)\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n const node = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: [],\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: createDefaultSourceMetadata(),\n derivedLayout: null,\n fills:\n type === 'TEXT' ? [{ type: 'SOLID' as const, color: BLACK, opacity: 1, visible: true }] : [],\n strokes: [],\n effects: [],\n layoutGrids: [],\n guides: [],\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: [],\n strokeGeometry: [],\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: [],\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: [],\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: [],\n fontVariations: [],\n opticalSizeFromFontSize: true,\n fontFeatures: [],\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: [],\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: [],\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: [],\n gridTemplateRows: [],\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n starInnerRadius: 0.38,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: createInstanceOverrideState(),\n componentPropertyDefinitions: [],\n componentPropertyReferences: [],\n componentPropertyAssignments: {},\n componentPropertyValues: {},\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: [],\n variantPropSpecs: [],\n boundVariables: {},\n variableBindingScales: {},\n variableAssignmentScales: {},\n componentScale: 1,\n variableModes: {},\n exportSettings: [],\n status: null,\n pluginData: [],\n pluginRelaunchData: [],\n prototypeReactions: [],\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined,\n ...overrides\n } satisfies CompleteNodeFields\n node.effects = normalizeEffects(node.effects)\n return node\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',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AAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
package/dist/order-keys.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* comparison, as Figma writes `parentIndex.position`. A new key fits between two neighbours
|
|
5
5
|
* without renumbering the others.
|
|
6
6
|
*/
|
|
7
|
+
/** Sorts order keys as Figma does: by plain string comparison. */
|
|
8
|
+
declare function compareOrderKeys(a: string, b: string): number;
|
|
7
9
|
/** The order key for position `index` of a freshly numbered sibling list. */
|
|
8
10
|
declare function fractionalPosition(index: number): string;
|
|
9
11
|
/**
|
|
@@ -35,5 +37,5 @@ interface SiblingOrderKeyOptions {
|
|
|
35
37
|
*/
|
|
36
38
|
declare function siblingOrderKeys(sourceKeys: ReadonlyArray<string | null | undefined>, options?: SiblingOrderKeyOptions): string[];
|
|
37
39
|
//#endregion
|
|
38
|
-
export { SiblingOrderKeyOptions, fractionalPosition, hasOrderKeyBetween, orderKeyBetween, siblingOrderKeys };
|
|
40
|
+
export { SiblingOrderKeyOptions, compareOrderKeys, fractionalPosition, hasOrderKeyBetween, orderKeyBetween, siblingOrderKeys };
|
|
39
41
|
//# sourceMappingURL=order-keys.d.ts.map
|
package/dist/order-keys.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-keys.d.ts","names":[],"sources":["../src/order-keys.ts"],"mappings":";;;;;;;iBAYgB,mBAAmB;;;;;;;;;;;;iBAoDnB,gBAAgB,mBAAmB,mBAAmB;;iBAStD,mBAAmB,mBAAmB;UA4BrC;;;;;EAKf;;;;;;;;iBASc,iBACd,YAAY,0CACZ,UAAS"}
|
|
1
|
+
{"version":3,"file":"order-keys.d.ts","names":[],"sources":["../src/order-keys.ts"],"mappings":";;;;;;;iBAYgB,iBAAiB,WAAW;;iBAM5B,mBAAmB;;;;;;;;;;;;iBAoDnB,gBAAgB,mBAAmB,mBAAmB;;iBAStD,mBAAmB,mBAAmB;UA4BrC;;;;;EAKf;;;;;;;;iBASc,iBACd,YAAY,0CACZ,UAAS"}
|
package/dist/order-keys.js
CHANGED
|
@@ -8,6 +8,11 @@ const ORDER_KEY_MIN = 33;
|
|
|
8
8
|
const ORDER_KEY_MAX = 126;
|
|
9
9
|
const ORDER_KEY_MID = "O";
|
|
10
10
|
const INDEX_KEY_BASE = 94;
|
|
11
|
+
/** Sorts order keys as Figma does: by plain string comparison. */
|
|
12
|
+
function compareOrderKeys(a, b) {
|
|
13
|
+
if (a === b) return 0;
|
|
14
|
+
return a < b ? -1 : 1;
|
|
15
|
+
}
|
|
11
16
|
/** The order key for position `index` of a freshly numbered sibling list. */
|
|
12
17
|
function fractionalPosition(index) {
|
|
13
18
|
const numTildes = Math.floor(index / INDEX_KEY_BASE);
|
|
@@ -131,6 +136,6 @@ function siblingOrderKeys(sourceKeys, options = {}) {
|
|
|
131
136
|
return keys;
|
|
132
137
|
}
|
|
133
138
|
//#endregion
|
|
134
|
-
export { fractionalPosition, hasOrderKeyBetween, orderKeyBetween, siblingOrderKeys };
|
|
139
|
+
export { compareOrderKeys, fractionalPosition, hasOrderKeyBetween, orderKeyBetween, siblingOrderKeys };
|
|
135
140
|
|
|
136
141
|
//# sourceMappingURL=order-keys.js.map
|
package/dist/order-keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-keys.js","names":[],"sources":["../src/order-keys.ts"],"sourcesContent":["/**\n * Fractional order keys: printable-ASCII strings (`!` to `~`) that order siblings by plain string\n * comparison, as Figma writes `parentIndex.position`. A new key fits between two neighbours\n * without renumbering the others.\n */\n\nconst ORDER_KEY_MIN = 33 // '!'\nconst ORDER_KEY_MAX = 126 // '~'\nconst ORDER_KEY_MID = 'O'\nconst INDEX_KEY_BASE = ORDER_KEY_MAX - ORDER_KEY_MIN + 1\n\n/** The order key for position `index` of a freshly numbered sibling list. */\nexport function fractionalPosition(index: number): string {\n const numTildes = Math.floor(index / INDEX_KEY_BASE)\n const lastChar = String.fromCharCode(ORDER_KEY_MIN + (index % INDEX_KEY_BASE))\n return String.fromCharCode(ORDER_KEY_MAX).repeat(numTildes) + lastChar\n}\n\n/**\n * The shortest key strictly between `lo` and `hi` (either may be open), or null when the\n * printable alphabet has none. Splits at the first character where they differ when a character\n * fits between; otherwise keeps that character and recurses into the remainder.\n */\nfunction keyBetween(lo: string | null, hi: string | null): string | null {\n if (lo !== null && hi !== null && lo >= hi) return null\n const low = lo ?? ''\n // An open upper bound shares no prefix, so the empty string ends the scan immediately.\n const high = hi ?? ''\n let i = 0\n while (i < low.length && i < high.length && low[i] === high[i]) i++\n const a = i < low.length ? low.charCodeAt(i) : ORDER_KEY_MIN - 1\n const b = hi !== null && i < hi.length ? hi.charCodeAt(i) : ORDER_KEY_MAX + 1\n if (b - a > 1) return low.slice(0, i) + String.fromCharCode(Math.floor((a + b) / 2))\n // Keep lo's character: anything above the rest of lo then sorts below hi.\n if (i < low.length) {\n return low.slice(0, i + 1) + (keyBetween(low.slice(i + 1), null) ?? ORDER_KEY_MID)\n }\n // lo is a prefix of hi whose next character can't be lowered: keep it and go below the rest.\n const rest = hi?.slice(i + 1) ?? ''\n if (!hi || rest === '') return null\n return hi.slice(0, i + 1) + (keyBetween(null, rest) ?? '')\n}\n\n/** A key above `lo` that has room for `suffix` while staying below `hi`, or null. */\nfunction keyWithSuffix(lo: string | null, hi: string, suffix: string): string | null {\n // A key that is a prefix of hi leaves no room after it; go one level deeper until it is not.\n for (let key = keyBetween(lo, hi); key !== null; key = keyBetween(key, hi)) {\n if (key + suffix < hi) return key + suffix\n if (!hi.startsWith(key)) return null\n }\n return null\n}\n\n/**\n * A key above `lo` and below `hi`; either bound may be open.\n *\n * `suffix`, a few random printable characters, is appended where it fits, so two peers that\n * insert at the same spot at once get distinct keys with room between them. The key stays short:\n * it grows by about one character for every five keys inserted into the same gap.\n *\n * Every pair of bounds gets a key. When no printable key sorts between them, because `lo` is not\n * below `hi` or `hi` is `lo` followed only by `!`, the result is the key `orderKeyBetween(lo, null)`\n * gives, which is above `lo` but not below `hi`, and the caller must re-key `hi`.\n */\nexport function orderKeyBetween(lo: string | null, hi: string | null, suffix = ''): string {\n const key = keyBetween(lo, hi)\n if (key === null) return (keyBetween(lo, null) ?? ORDER_KEY_MID) + suffix\n if (!suffix) return key\n if (hi === null) return key + suffix\n return keyWithSuffix(lo, hi, suffix) ?? key\n}\n\n/** Whether some printable key sorts strictly between `lo` and `hi`. */\nexport function hasOrderKeyBetween(lo: string | null, hi: string | null): boolean {\n return keyBetween(lo, hi) !== null\n}\n\n/** Indices of the longest strictly increasing run of keys, so a moved layer re-keys alone. */\nfunction increasingKeyIndices(sourceKeys: ReadonlyArray<string | null | undefined>): Set<number> {\n const tails: number[] = []\n const previous = new Map<number, number>()\n for (let index = 0; index < sourceKeys.length; index++) {\n const key = sourceKeys[index]\n if (!key) continue\n let low = 0\n let high = tails.length\n while (low < high) {\n const mid = (low + high) >> 1\n if ((sourceKeys[tails[mid]] ?? '') < key) low = mid + 1\n else high = mid\n }\n // A key with nothing below it cannot start the run once a sibling has to precede it.\n if (low === 0 && index > 0 && !hasOrderKeyBetween(null, key)) continue\n if (low > 0) previous.set(index, tails[low - 1])\n tails[low] = index\n }\n const kept = new Set<number>()\n for (let index = tails.at(-1); index !== undefined; index = previous.get(index)) kept.add(index)\n return kept\n}\n\nexport interface SiblingOrderKeyOptions {\n /**\n * Returns a suffix for each key the function makes up, as `orderKeyBetween` takes. Without it,\n * a sibling that needs a key gets its index key when that fits between its neighbours.\n */\n suffix?: () => string\n}\n\n/**\n * Order keys for siblings in their current order. The longest increasing run of existing keys\n * is kept; other siblings get the index key when it fits between their neighbours (or a key with\n * a suffix, when `options.suffix` is given), and otherwise a key between them, so no two siblings\n * share a key.\n */\nexport function siblingOrderKeys(\n sourceKeys: ReadonlyArray<string | null | undefined>,\n options: SiblingOrderKeyOptions = {}\n): string[] {\n const keys: string[] = []\n let prev: string | null = null\n let pending: number[] = []\n\n const nextKey = (index: number, lo: string | null, upper: string | null): string | null => {\n if (options.suffix) {\n const key = orderKeyBetween(lo, upper, options.suffix())\n return upper === null || key < upper ? key : null\n }\n const candidate = fractionalPosition(index)\n if ((lo === null || candidate > lo) && (upper === null || candidate < upper)) return candidate\n return keyBetween(lo, upper)\n }\n\n const fill = (upper: string | null): string[] | null => {\n const filled: string[] = []\n let lo = prev\n for (const index of pending) {\n const key = nextKey(index, lo, upper)\n if (key === null) return null\n filled.push(key)\n lo = key\n }\n return filled\n }\n\n const kept = increasingKeyIndices(sourceKeys)\n for (let index = 0; index < sourceKeys.length; index++) {\n const key = sourceKeys[index]\n const filled = key && kept.has(index) ? fill(key) : null\n if (key && filled) {\n pending.forEach((pendingIndex, i) => (keys[pendingIndex] = filled[i]))\n keys[index] = key\n prev = key\n pending = []\n } else {\n pending.push(index)\n }\n }\n const rest = fill(null) ?? []\n pending.forEach((pendingIndex, i) => (keys[pendingIndex] = rest[i]))\n return keys\n}\n"],"mappings":";;;;;;AAMA,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;;AAGvB,SAAgB,mBAAmB,OAAuB;CACxD,MAAM,YAAY,KAAK,MAAM,QAAQ,cAAc;CACnD,MAAM,WAAW,OAAO,aAAa,gBAAiB,QAAQ,cAAe;CAC7E,OAAO,OAAO,aAAa,aAAa,CAAC,CAAC,OAAO,SAAS,IAAI;AAChE;;;;;;AAOA,SAAS,WAAW,IAAmB,IAAkC;CACvE,IAAI,OAAO,QAAQ,OAAO,QAAQ,MAAM,IAAI,OAAO;CACnD,MAAM,MAAM,MAAM;CAElB,MAAM,OAAO,MAAM;CACnB,IAAI,IAAI;CACR,OAAO,IAAI,IAAI,UAAU,IAAI,KAAK,UAAU,IAAI,OAAO,K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O,KAAK,GAAG;GACf,KAAK;EACP;EACA,OAAO;CACT;CAEA,MAAM,OAAO,qBAAqB,UAAU;CAC5C,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS;EACtD,MAAM,MAAM,WAAW;EACvB,MAAM,SAAS,OAAO,KAAK,IAAI,KAAK,IAAI,KAAK,GAAG,IAAI;EACpD,IAAI,OAAO,QAAQ;GACjB,QAAQ,SAAS,cAAc,MAAO,KAAK,gBAAgB,OAAO,EAAG;GACrE,KAAK,SAAS;GACd,OAAO;GACP,UAAU,CAAC;EACb,OACE,QAAQ,KAAK,KAAK;CAEtB;CACA,MAAM,OAAO,KAAK,IAAI,KAAK,CAAC;CAC5B,QAAQ,SAAS,cAAc,MAAO,KAAK,gBAAgB,KAAK,EAAG;CACnE,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"order-keys.js","names":[],"sources":["../src/order-keys.ts"],"sourcesContent":["/**\n * Fractional order keys: printable-ASCII strings (`!` to `~`) that order siblings by plain string\n * comparison, as Figma writes `parentIndex.position`. A new key fits between two neighbours\n * without renumbering the others.\n */\n\nconst ORDER_KEY_MIN = 33 // '!'\nconst ORDER_KEY_MAX = 126 // '~'\nconst ORDER_KEY_MID = 'O'\nconst INDEX_KEY_BASE = ORDER_KEY_MAX - ORDER_KEY_MIN + 1\n\n/** Sorts order keys as Figma does: by plain string comparison. */\nexport function compareOrderKeys(a: string, b: string): number {\n if (a === b) return 0\n return a < b ? -1 : 1\n}\n\n/** The order key for position `index` of a freshly numbered sibling list. */\nexport function fractionalPosition(index: number): string {\n const numTildes = Math.floor(index / INDEX_KEY_BASE)\n const lastChar = String.fromCharCode(ORDER_KEY_MIN + (index % INDEX_KEY_BASE))\n return String.fromCharCode(ORDER_KEY_MAX).repeat(numTildes) + lastChar\n}\n\n/**\n * The shortest key strictly between `lo` and `hi` (either may be open), or null when the\n * printable alphabet has none. Splits at the first character where they differ when a character\n * fits between; otherwise keeps that character and recurses into the remainder.\n */\nfunction keyBetween(lo: string | null, hi: string | null): string | null {\n if (lo !== null && hi !== null && lo >= hi) return null\n const low = lo ?? ''\n // An open upper bound shares no prefix, so the empty string ends the scan immediately.\n const high = hi ?? ''\n let i = 0\n while (i < low.length && i < high.length && low[i] === high[i]) i++\n const a = i < low.length ? low.charCodeAt(i) : ORDER_KEY_MIN - 1\n const b = hi !== null && i < hi.length ? hi.charCodeAt(i) : ORDER_KEY_MAX + 1\n if (b - a > 1) return low.slice(0, i) + String.fromCharCode(Math.floor((a + b) / 2))\n // Keep lo's character: anything above the rest of lo then sorts below hi.\n if (i < low.length) {\n return low.slice(0, i + 1) + (keyBetween(low.slice(i + 1), null) ?? ORDER_KEY_MID)\n }\n // lo is a prefix of hi whose next character can't be lowered: keep it and go below the rest.\n const rest = hi?.slice(i + 1) ?? ''\n if (!hi || rest === '') return null\n return hi.slice(0, i + 1) + (keyBetween(null, rest) ?? '')\n}\n\n/** A key above `lo` that has room for `suffix` while staying below `hi`, or null. */\nfunction keyWithSuffix(lo: string | null, hi: string, suffix: string): string | null {\n // A key that is a prefix of hi leaves no room after it; go one level deeper until it is not.\n for (let key = keyBetween(lo, hi); key !== null; key = keyBetween(key, hi)) {\n if (key + suffix < hi) return key + suffix\n if (!hi.startsWith(key)) return null\n }\n return null\n}\n\n/**\n * A key above `lo` and below `hi`; either bound may be open.\n *\n * `suffix`, a few random printable characters, is appended where it fits, so two peers that\n * insert at the same spot at once get distinct keys with room between them. The key stays short:\n * it grows by about one character for every five keys inserted into the same gap.\n *\n * Every pair of bounds gets a key. When no printable key sorts between them, because `lo` is not\n * below `hi` or `hi` is `lo` followed only by `!`, the result is the key `orderKeyBetween(lo, null)`\n * gives, which is above `lo` but not below `hi`, and the caller must re-key `hi`.\n */\nexport function orderKeyBetween(lo: string | null, hi: string | null, suffix = ''): string {\n const key = keyBetween(lo, hi)\n if (key === null) return (keyBetween(lo, null) ?? ORDER_KEY_MID) + suffix\n if (!suffix) return key\n if (hi === null) return key + suffix\n return keyWithSuffix(lo, hi, suffix) ?? key\n}\n\n/** Whether some printable key sorts strictly between `lo` and `hi`. */\nexport function hasOrderKeyBetween(lo: string | null, hi: string | null): boolean {\n return keyBetween(lo, hi) !== null\n}\n\n/** Indices of the longest strictly increasing run of keys, so a moved layer re-keys alone. */\nfunction increasingKeyIndices(sourceKeys: ReadonlyArray<string | null | undefined>): Set<number> {\n const tails: number[] = []\n const previous = new Map<number, number>()\n for (let index = 0; index < sourceKeys.length; index++) {\n const key = sourceKeys[index]\n if (!key) continue\n let low = 0\n let high = tails.length\n while (low < high) {\n const mid = (low + high) >> 1\n if ((sourceKeys[tails[mid]] ?? '') < key) low = mid + 1\n else high = mid\n }\n // A key with nothing below it cannot start the run once a sibling has to precede it.\n if (low === 0 && index > 0 && !hasOrderKeyBetween(null, key)) continue\n if (low > 0) previous.set(index, tails[low - 1])\n tails[low] = index\n }\n const kept = new Set<number>()\n for (let index = tails.at(-1); index !== undefined; index = previous.get(index)) kept.add(index)\n return kept\n}\n\nexport interface SiblingOrderKeyOptions {\n /**\n * Returns a suffix for each key the function makes up, as `orderKeyBetween` takes. Without it,\n * a sibling that needs a key gets its index key when that fits between its neighbours.\n */\n suffix?: () => string\n}\n\n/**\n * Order keys for siblings in their current order. The longest increasing run of existing keys\n * is kept; other siblings get the index key when it fits between their neighbours (or a key with\n * a suffix, when `options.suffix` is given), and otherwise a key between them, so no two siblings\n * share a key.\n */\nexport function siblingOrderKeys(\n sourceKeys: ReadonlyArray<string | null | undefined>,\n options: SiblingOrderKeyOptions = {}\n): string[] {\n const keys: string[] = []\n let prev: string | null = null\n let pending: number[] = []\n\n const nextKey = (index: number, lo: string | null, upper: string | null): string | null => {\n if (options.suffix) {\n const key = orderKeyBetween(lo, upper, options.suffix())\n return upper === null || key < upper ? key : null\n }\n const candidate = fractionalPosition(index)\n if ((lo === null || candidate > lo) && (upper === null || candidate < upper)) return candidate\n return keyBetween(lo, upper)\n }\n\n const fill = (upper: string | null): string[] | null => {\n const filled: string[] = []\n let lo = prev\n for (const index of pending) {\n const key = nextKey(index, lo, upper)\n if (key === null) return null\n filled.push(key)\n lo = key\n }\n return filled\n }\n\n const kept = increasingKeyIndices(sourceKeys)\n for (let index = 0; index < sourceKeys.length; index++) {\n const key = sourceKeys[index]\n const filled = key && kept.has(index) ? fill(key) : null\n if (key && filled) {\n pending.forEach((pendingIndex, i) => (keys[pendingIndex] = filled[i]))\n keys[index] = key\n prev = key\n pending = []\n } else {\n pending.push(index)\n }\n }\n const rest = fill(null) ?? []\n pending.forEach((pendingIndex, i) => (keys[pendingIndex] = rest[i]))\n return keys\n}\n"],"mappings":";;;;;;AAMA,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AACtB,MAAM,iBAAiB;;AAGvB,SAAgB,iBAAiB,GAAW,GAAmB;CAC7D,IAAI,MAAM,GAAG,OAAO;CACpB,OAAO,IAAI,IAAI,KAAK;AACtB;;AAGA,SAAgB,mBAAmB,OAAuB;CACxD,MAAM,YAAY,KAAK,MAAM,QAAQ,cAAc;CACnD,MAAM,WAAW,OAAO,aAAa,gBAAiB,QAAQ,cAAe;CAC7E,OAAO,OAAO,aAAa,aAAa,CAAC,CAAC,OAAO,SAAS,IAAI;AAChE;;;;;;AAOA,SAAS,WAAW,IAAmB,IAAkC;CACvE,IAAI,OAAO,QAAQ,OAAO,QAAQ,MAAM,IAAI,OAAO;CACnD,MAAM,MAAM,MAAM;CAElB,MAAM,OAAO,MAAM;CACnB,IAAI,IAAI;CACR,OAAO,IAAI,IAAI,UAAU,IAAI,KAAK,UAAU,IAAI,OAAO,KAAK,IAAI;CAChE,MAAM,IAAI,IAAI,IAAI,SAAS,IAAI,WAAW,CAAC,IAAI;CAC/C,MAAM,IAAI,OAAO,QAAQ,IAAI,GAAG,SAAS,GAAG,WAAW,CAAC,IAAI;CAC5D,IAAI,IAAI,IAAI,GAAG,OAAO,IAAI,MAAM,GAAG,CAAC,IAAI,OAAO,aAAa,KAAK,OAAO,I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,OAAO,QAAQ;GACjB,QAAQ,SAAS,cAAc,MAAO,KAAK,gBAAgB,OAAO,EAAG;GACrE,KAAK,SAAS;GACd,OAAO;GACP,UAAU,CAAC;EACb,OACE,QAAQ,KAAK,KAAK;CAEtB;CACA,MAAM,OAAO,KAAK,IAAI,KAAK,CAAC;CAC5B,QAAQ,SAAS,cAAc,MAAO,KAAK,gBAAgB,KAAK,EAAG;CACnE,OAAO;AACT"}
|
package/dist/resize.d.ts
CHANGED
|
@@ -7,22 +7,29 @@ import { ConstraintType, SceneNode, VectorNetwork } from "./types.js";
|
|
|
7
7
|
* geometry that must scale with the node, and textPathBox is the layout box the
|
|
8
8
|
* glyphs were reflowed against.
|
|
9
9
|
*/
|
|
10
|
-
type ResizeSnapshot = Pick<SceneNode, 'type' | 'x' | 'y' | 'width' | 'height' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>;
|
|
10
|
+
type ResizeSnapshot = Pick<SceneNode, 'type' | 'x' | 'y' | 'width' | 'height' | 'flipX' | 'flipY' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>;
|
|
11
11
|
interface ResizeGraph {
|
|
12
12
|
getNode(id: string): SceneNode | undefined;
|
|
13
13
|
}
|
|
14
|
+
/** A child's box after its parent resizes, and the axes on which it turned over. */
|
|
15
|
+
type ConstrainedRect = Rect & {
|
|
16
|
+
flipsX?: boolean;
|
|
17
|
+
flipsY?: boolean;
|
|
18
|
+
};
|
|
14
19
|
/** Keep a placed box's constrained edges or center when its content determines its size. */
|
|
15
20
|
declare function resizedChildRect(placed: Rect, size: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType): Rect;
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
type ChildRectPlacer = (child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType, aspectRatio?: number | null) => ConstrainedRect;
|
|
22
|
+
/**
|
|
23
|
+
* A child's box after its parent is resized, by a handle or `resize()`, keeping a locked aspect
|
|
24
|
+
* ratio as Figma does.
|
|
25
|
+
*/
|
|
26
|
+
declare const constrainedChildRect: ChildRectPlacer;
|
|
18
27
|
/**
|
|
19
28
|
* Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
|
|
20
|
-
* layout when its Hug frame grows (measured on desktop 126):
|
|
21
|
-
*
|
|
22
|
-
* rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
|
|
23
|
-
* rounded, so applying a run of changes one at a time lands where applying them at once does.
|
|
29
|
+
* layout when its Hug frame grows (measured on desktop 126): as `constrainedChildRect`, except
|
|
30
|
+
* that a scaled position lands on 1/128 of a pixel.
|
|
24
31
|
*/
|
|
25
|
-
declare
|
|
32
|
+
declare const layoutConstrainedChildRect: ChildRectPlacer;
|
|
26
33
|
declare function scaledChildRect(child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>): Rect;
|
|
27
34
|
declare function scaleVectorNetworkForResize(vectorNetwork: VectorNetwork | null, originalWidth: number, originalHeight: number, width: number, height: number): VectorNetwork | null;
|
|
28
35
|
/** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */
|
|
@@ -34,11 +41,24 @@ declare function createResizeSnapshot(node: SceneNode): ResizeSnapshot;
|
|
|
34
41
|
* OUTSIDE outlines look massively thick (DomeSticker resize bug).
|
|
35
42
|
*/
|
|
36
43
|
declare function scaledGeometryChanges(orig: Pick<ResizeSnapshot, 'type' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>, origWidth: number, origHeight: number, width: number, height: number): Partial<SceneNode>;
|
|
44
|
+
/**
|
|
45
|
+
* The saved outlines a size change invalidates on a layer drawn from its live box: its fill
|
|
46
|
+
* outline follows the box, and its saved stroke outline goes, so the stroke is drawn again at its
|
|
47
|
+
* weight through the live shape. A vector and text draw from outlines of their own, which scaling
|
|
48
|
+
* keeps. Without this, a layer that came from a `.fig` with frame outlines keeps drawing the old
|
|
49
|
+
* box after layout, the Plugin API or an instance sync resizes it.
|
|
50
|
+
*/
|
|
51
|
+
declare function shapeGeometryChanges(node: SceneNode, width: number, height: number): Pick<Partial<SceneNode>, 'fillGeometry' | 'strokeGeometry'>;
|
|
37
52
|
type PathTextFields = Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>;
|
|
38
53
|
/** The baked glyphs and layout box of path text, scaled with the layer; nothing for other text. */
|
|
39
54
|
declare function scaledPathTextChanges(orig: PathTextFields, sx: number, sy: number): Pick<Partial<SceneNode>, 'derivedTextGlyphs' | 'textPathBox'>;
|
|
40
55
|
declare function collectResizeDescendants(graph: ResizeGraph, rootId: string): Map<string, ResizeSnapshot> | null;
|
|
56
|
+
/**
|
|
57
|
+
* The flips a child takes when its constraints place it from `from`, written only where they
|
|
58
|
+
* differ from the ones it has now, so a drag that crosses back undoes its own turn.
|
|
59
|
+
*/
|
|
60
|
+
declare function flipChanges(from: Pick<SceneNode, 'flipX' | 'flipY'>, current: Pick<SceneNode, 'flipX' | 'flipY'>, flipsX?: boolean, flipsY?: boolean): Partial<Pick<SceneNode, 'flipX' | 'flipY'>>;
|
|
41
61
|
declare function computeConstrainedResizeChanges(graph: ResizeGraph, rootId: string, rootBefore: Pick<Rect, 'width' | 'height'>, rootAfter: Pick<Rect, 'width' | 'height'>, originals: ReadonlyMap<string, ResizeSnapshot>): Map<string, Partial<SceneNode>>;
|
|
42
62
|
//#endregion
|
|
43
|
-
export { ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges };
|
|
63
|
+
export { ConstrainedRect, ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, flipChanges, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges, shapeGeometryChanges };
|
|
44
64
|
//# sourceMappingURL=resize.d.ts.map
|
package/dist/resize.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAkBY,iBAAiB,KAC3B;
|
|
1
|
+
{"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAkBY,iBAAiB,KAC3B;UAiBQ;EACR,QAAQ,aAAa;;;KAeX,kBAAkB;EAAS;EAAkB;;;iBAyDzC,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;KAwBE,mBACH,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,gCACG;;;;;cAuCQ,sBAAoB;;;;;;cAOpB,4BAA0B;iBAEvB,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBAIa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA8Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAoDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;;;;;;;;iBA0CK,qBACd,MAAM,WACN,eACA,iBACC,KAAK,QAAQ;KAkBX,iBAAiB,KAAK;;iBAeX,sBACd,MAAM,gBACN,YACA,aACC,KAAK,QAAQ;iBAmBA,yBACd,OAAO,aACP,iBACC,YAAY;;;;;iBAwBC,YACd,MAAM,KAAK,+BACX,SAAS,KAAK,+BACd,kBACA,mBACC,QAAQ,KAAK;iBASA,gCACd,OAAO,aACP,gBACA,YAAY,KAAK,2BACjB,WAAW,KAAK,2BAChB,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
|
package/dist/resize.js
CHANGED
|
@@ -10,25 +10,51 @@ const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
|
|
|
10
10
|
"GROUP",
|
|
11
11
|
"BOOLEAN_OPERATION"
|
|
12
12
|
]);
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Where a constraint places a child on one axis when its parent goes from `parentBefore` to
|
|
15
|
+
* `parentAfter`, as Figma does: Right and Left & right move or grow it by the change in the
|
|
16
|
+
* parent's size rounded to whole pixels, Center by the change in its rounded half, and Scale by
|
|
17
|
+
* the exact ratio. The child's own box is never rounded, so a resize to the same size changes
|
|
18
|
+
* nothing. Left & right that would leave no size keeps the axis as it was; past zero, the child
|
|
19
|
+
* turns over and its box runs back from the edge it was pinned to, as the layer is mirrored in
|
|
20
|
+
* Figma. `scaleStep` snaps a scaled position to that fraction of a pixel.
|
|
21
|
+
*/
|
|
22
|
+
function constrainedAxis(position, size, parentBefore, parentAfter, constraint, scaleStep = 0, allowFlips = true) {
|
|
23
|
+
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
15
24
|
if (constraint === "MAX") return {
|
|
16
25
|
position: position + delta,
|
|
17
26
|
size
|
|
18
27
|
};
|
|
19
28
|
if (constraint === "CENTER") return {
|
|
20
|
-
position: position +
|
|
29
|
+
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
21
30
|
size
|
|
22
31
|
};
|
|
23
|
-
if (constraint === "STRETCH")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
if (constraint === "STRETCH") {
|
|
33
|
+
const stretched = size + delta;
|
|
34
|
+
if (!allowFlips) return {
|
|
35
|
+
position,
|
|
36
|
+
size: Math.abs(stretched)
|
|
37
|
+
};
|
|
38
|
+
if (stretched === 0) return {
|
|
39
|
+
position,
|
|
40
|
+
size
|
|
41
|
+
};
|
|
42
|
+
if (stretched > 0) return {
|
|
43
|
+
position,
|
|
44
|
+
size: stretched
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
position: position + stretched,
|
|
48
|
+
size: -stretched,
|
|
49
|
+
flipped: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
27
52
|
if (constraint === "SCALE" && parentBefore > 0) {
|
|
28
53
|
const scale = parentAfter / parentBefore;
|
|
54
|
+
const scaled = position * scale;
|
|
29
55
|
return {
|
|
30
|
-
position:
|
|
31
|
-
size:
|
|
56
|
+
position: scaleStep > 0 ? Math.round(scaled / scaleStep) * scaleStep : scaled,
|
|
57
|
+
size: size * scale
|
|
32
58
|
};
|
|
33
59
|
}
|
|
34
60
|
return {
|
|
@@ -87,60 +113,32 @@ function keepLockedRatio(x, y, horizontal, vertical, aspectRatio) {
|
|
|
87
113
|
y
|
|
88
114
|
};
|
|
89
115
|
}
|
|
90
|
-
/**
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
height: Math.round(y.size)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function layoutConstrainedAxis(position, size, parentBefore, parentAfter, constraint) {
|
|
103
|
-
const delta = Math.round(parentAfter) - Math.round(parentBefore);
|
|
104
|
-
if (constraint === "MAX") return {
|
|
105
|
-
position: position + delta,
|
|
106
|
-
size
|
|
107
|
-
};
|
|
108
|
-
if (constraint === "CENTER") return {
|
|
109
|
-
position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
|
|
110
|
-
size
|
|
111
|
-
};
|
|
112
|
-
if (constraint === "STRETCH") return {
|
|
113
|
-
position,
|
|
114
|
-
size: Math.abs(size + delta)
|
|
115
|
-
};
|
|
116
|
-
if (constraint === "SCALE" && parentBefore > 0) {
|
|
117
|
-
const scale = parentAfter / parentBefore;
|
|
118
|
-
return {
|
|
119
|
-
position: Math.round(position * scale * 128) / 128,
|
|
120
|
-
size: size * scale
|
|
116
|
+
/** Places a child by its constraints, snapping a scaled position to `scaleStep` when it is set. */
|
|
117
|
+
function childRectPlacer(scaleStep, allowFlips = true) {
|
|
118
|
+
return (child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) => {
|
|
119
|
+
const { x, y } = keepLockedRatio(constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal, scaleStep, allowFlips), constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical, scaleStep, allowFlips), horizontal, vertical, aspectRatio);
|
|
120
|
+
const rect = {
|
|
121
|
+
x: x.position,
|
|
122
|
+
y: y.position,
|
|
123
|
+
width: x.size,
|
|
124
|
+
height: y.size
|
|
121
125
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
size
|
|
126
|
+
if (x.flipped) rect.flipsX = true;
|
|
127
|
+
if (y.flipped) rect.flipsY = true;
|
|
128
|
+
return rect;
|
|
126
129
|
};
|
|
127
130
|
}
|
|
128
131
|
/**
|
|
132
|
+
* A child's box after its parent is resized, by a handle or `resize()`, keeping a locked aspect
|
|
133
|
+
* ratio as Figma does.
|
|
134
|
+
*/
|
|
135
|
+
const constrainedChildRect = childRectPlacer(0);
|
|
136
|
+
/**
|
|
129
137
|
* Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
|
|
130
|
-
* layout when its Hug frame grows (measured on desktop 126):
|
|
131
|
-
*
|
|
132
|
-
* rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
|
|
133
|
-
* rounded, so applying a run of changes one at a time lands where applying them at once does.
|
|
138
|
+
* layout when its Hug frame grows (measured on desktop 126): as `constrainedChildRect`, except
|
|
139
|
+
* that a scaled position lands on 1/128 of a pixel.
|
|
134
140
|
*/
|
|
135
|
-
|
|
136
|
-
const placed = keepLockedRatio(layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal), layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical), horizontal, vertical, aspectRatio);
|
|
137
|
-
return {
|
|
138
|
-
x: placed.x.position,
|
|
139
|
-
y: placed.y.position,
|
|
140
|
-
width: placed.x.size,
|
|
141
|
-
height: placed.y.size
|
|
142
|
-
};
|
|
143
|
-
}
|
|
141
|
+
const layoutConstrainedChildRect = childRectPlacer(1 / 128, false);
|
|
144
142
|
function scaledChildRect(child, parentBefore, parentAfter) {
|
|
145
143
|
return constrainedChildRect(child, parentBefore, parentAfter, "SCALE", "SCALE");
|
|
146
144
|
}
|
|
@@ -177,6 +175,8 @@ function createResizeSnapshot(node) {
|
|
|
177
175
|
y: node.y,
|
|
178
176
|
width: node.width,
|
|
179
177
|
height: node.height,
|
|
178
|
+
flipX: node.flipX,
|
|
179
|
+
flipY: node.flipY,
|
|
180
180
|
vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,
|
|
181
181
|
fillGeometry: copyGeometryPaths(node.fillGeometry),
|
|
182
182
|
strokeGeometry: copyGeometryPaths(node.strokeGeometry),
|
|
@@ -229,6 +229,26 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
|
|
|
229
229
|
if (orig.strokes.length > 0 && isScaledPathText(orig)) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
|
|
230
230
|
return changes;
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* The saved outlines a size change invalidates on a layer drawn from its live box: its fill
|
|
234
|
+
* outline follows the box, and its saved stroke outline goes, so the stroke is drawn again at its
|
|
235
|
+
* weight through the live shape. A vector and text draw from outlines of their own, which scaling
|
|
236
|
+
* keeps. Without this, a layer that came from a `.fig` with frame outlines keeps drawing the old
|
|
237
|
+
* box after layout, the Plugin API or an instance sync resizes it.
|
|
238
|
+
*/
|
|
239
|
+
function shapeGeometryChanges(node, width, height) {
|
|
240
|
+
if (node.type === "VECTOR" || node.type === "TEXT") return {};
|
|
241
|
+
if (node.fillGeometry.length === 0 && node.strokeGeometry.length === 0) return {};
|
|
242
|
+
if (node.width <= 0 || node.height <= 0) return {
|
|
243
|
+
fillGeometry: [],
|
|
244
|
+
strokeGeometry: []
|
|
245
|
+
};
|
|
246
|
+
const changes = scaledGeometryChanges(createResizeSnapshot(node), node.width, node.height, width, height);
|
|
247
|
+
const geometry = {};
|
|
248
|
+
if (changes.fillGeometry) geometry.fillGeometry = changes.fillGeometry;
|
|
249
|
+
if (changes.strokeGeometry) geometry.strokeGeometry = changes.strokeGeometry;
|
|
250
|
+
return geometry;
|
|
251
|
+
}
|
|
232
252
|
function isScaledPathText(orig) {
|
|
233
253
|
const glyphs = orig.derivedTextGlyphs ?? [];
|
|
234
254
|
return glyphs.length > 0 && (!!orig.textPathData || !!orig.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0));
|
|
@@ -262,6 +282,18 @@ function collectResizeDescendants(graph, rootId) {
|
|
|
262
282
|
collect(rootId);
|
|
263
283
|
return snapshots.size > 0 ? snapshots : null;
|
|
264
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* The flips a child takes when its constraints place it from `from`, written only where they
|
|
287
|
+
* differ from the ones it has now, so a drag that crosses back undoes its own turn.
|
|
288
|
+
*/
|
|
289
|
+
function flipChanges(from, current, flipsX = false, flipsY = false) {
|
|
290
|
+
const changes = {};
|
|
291
|
+
const flipX = from.flipX !== flipsX;
|
|
292
|
+
const flipY = from.flipY !== flipsY;
|
|
293
|
+
if (flipX !== current.flipX) changes.flipX = flipX;
|
|
294
|
+
if (flipY !== current.flipY) changes.flipY = flipY;
|
|
295
|
+
return changes;
|
|
296
|
+
}
|
|
265
297
|
function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
|
|
266
298
|
const changes = /* @__PURE__ */ new Map();
|
|
267
299
|
const compute = (parentId, parentBefore, parentAfter) => {
|
|
@@ -276,19 +308,20 @@ function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, o
|
|
|
276
308
|
compute(childId, original, child);
|
|
277
309
|
continue;
|
|
278
310
|
}
|
|
279
|
-
const
|
|
311
|
+
const { flipsX, flipsY, ...box } = scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child));
|
|
280
312
|
const childChanges = {
|
|
281
|
-
...
|
|
282
|
-
...
|
|
313
|
+
...box,
|
|
314
|
+
...flipChanges(original, child, flipsX, flipsY),
|
|
315
|
+
...scaledGeometryChanges(original, original.width, original.height, box.width, box.height)
|
|
283
316
|
};
|
|
284
317
|
changes.set(childId, childChanges);
|
|
285
|
-
compute(childId, original, child.layoutMode === "NONE" ?
|
|
318
|
+
compute(childId, original, child.layoutMode === "NONE" ? box : child);
|
|
286
319
|
}
|
|
287
320
|
};
|
|
288
321
|
compute(rootId, rootBefore, rootAfter);
|
|
289
322
|
return changes;
|
|
290
323
|
}
|
|
291
324
|
//#endregion
|
|
292
|
-
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges };
|
|
325
|
+
export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, flipChanges, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges, scaledPathTextChanges, shapeGeometryChanges };
|
|
293
326
|
|
|
294
327
|
//# sourceMappingURL=resize.js.map
|