@open-pencil/scene-graph 0.17.0-beta.3 → 0.17.0-beta.5
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/arrays.d.ts +17 -0
- package/dist/arrays.d.ts.map +1 -0
- package/dist/arrays.js +38 -0
- package/dist/arrays.js.map +1 -0
- package/dist/buffered-events.js +1 -1
- package/dist/buffered-events.js.map +1 -1
- package/dist/clipping.d.ts +7 -1
- package/dist/clipping.d.ts.map +1 -1
- package/dist/clipping.js +23 -19
- package/dist/clipping.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 +1 -3
- package/dist/components/properties.d.ts.map +1 -1
- package/dist/components/properties.js +2 -9
- package/dist/components/properties.js.map +1 -1
- package/dist/corners.d.ts +22 -0
- package/dist/corners.d.ts.map +1 -0
- package/dist/corners.js +52 -0
- package/dist/corners.js.map +1 -0
- package/dist/css/grid.d.ts +4 -1
- package/dist/css/grid.d.ts.map +1 -1
- package/dist/css/grid.js +16 -7
- package/dist/css/grid.js.map +1 -1
- package/dist/css/index.d.ts +2 -2
- package/dist/css/index.js +2 -2
- package/dist/css/values.d.ts +6 -1
- package/dist/css/values.d.ts.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 +68 -3
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +155 -5
- package/dist/geometry.js.map +1 -1
- package/dist/gradient.d.ts +9 -2
- package/dist/gradient.d.ts.map +1 -1
- package/dist/gradient.js +29 -1
- package/dist/gradient.js.map +1 -1
- package/dist/graph.d.ts +4 -0
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +30 -4
- package/dist/graph.js.map +1 -1
- package/dist/group-bounds.d.ts.map +1 -1
- package/dist/group-bounds.js +4 -3
- package/dist/group-bounds.js.map +1 -1
- package/dist/guides.d.ts +11 -2
- package/dist/guides.d.ts.map +1 -1
- package/dist/guides.js +30 -1
- package/dist/guides.js.map +1 -1
- package/dist/hit-test.d.ts.map +1 -1
- package/dist/hit-test.js +57 -5
- package/dist/hit-test.js.map +1 -1
- package/dist/icons/fit.d.ts +17 -0
- package/dist/icons/fit.d.ts.map +1 -0
- package/dist/icons/fit.js +21 -0
- package/dist/icons/fit.js.map +1 -0
- package/dist/icons/glyph.d.ts.map +1 -1
- package/dist/icons/glyph.js +5 -4
- package/dist/icons/glyph.js.map +1 -1
- package/dist/icons/index.d.ts +2 -1
- package/dist/icons/index.js +2 -1
- package/dist/images.d.ts +14 -4
- package/dist/images.d.ts.map +1 -1
- package/dist/images.js +45 -5
- package/dist/images.js.map +1 -1
- package/dist/instances/assignments.js +39 -6
- package/dist/instances/assignments.js.map +1 -1
- package/dist/instances/index.d.ts.map +1 -1
- package/dist/instances/index.js +39 -2
- package/dist/instances/index.js.map +1 -1
- package/dist/instances/kept-overrides.js +2 -2
- package/dist/instances/kept-overrides.js.map +1 -1
- package/dist/instances/matching.js +68 -0
- package/dist/instances/matching.js.map +1 -0
- package/dist/instances/overrides.d.ts +4 -1
- package/dist/instances/overrides.d.ts.map +1 -1
- package/dist/instances/overrides.js +13 -1
- package/dist/instances/overrides.js.map +1 -1
- package/dist/instances/protection.js +67 -0
- package/dist/instances/protection.js.map +1 -0
- package/dist/instances/swap.js +7 -5
- package/dist/instances/swap.js.map +1 -1
- package/dist/instances/sync.js +10 -116
- package/dist/instances/sync.js.map +1 -1
- package/dist/layout/guides.d.ts +17 -1
- package/dist/layout/guides.d.ts.map +1 -1
- package/dist/layout/guides.js +31 -11
- package/dist/layout/guides.js.map +1 -1
- package/dist/layout/index.d.ts +4 -2
- package/dist/layout/index.js +4 -2
- package/dist/layout/limits.d.ts +40 -0
- package/dist/layout/limits.d.ts.map +1 -0
- package/dist/layout/limits.js +54 -0
- package/dist/layout/limits.js.map +1 -0
- package/dist/layout/sizing.d.ts.map +1 -1
- package/dist/layout/sizing.js +0 -1
- package/dist/layout/sizing.js.map +1 -1
- package/dist/layout/spacing.d.ts +10 -0
- package/dist/layout/spacing.d.ts.map +1 -0
- package/dist/layout/spacing.js +12 -0
- package/dist/layout/spacing.js.map +1 -0
- package/dist/masks.d.ts +28 -0
- package/dist/masks.d.ts.map +1 -0
- package/dist/masks.js +53 -0
- package/dist/masks.js.map +1 -0
- package/dist/matrix.d.ts +2 -1
- package/dist/matrix.d.ts.map +1 -1
- package/dist/matrix.js +14 -1
- package/dist/matrix.js.map +1 -1
- package/dist/node-defaults.d.ts +9 -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/outline/flatten.d.ts.map +1 -1
- package/dist/outline/flatten.js +24 -17
- package/dist/outline/flatten.js.map +1 -1
- package/dist/outline/hit.d.ts +2 -8
- package/dist/outline/hit.d.ts.map +1 -1
- package/dist/outline/hit.js +16 -25
- package/dist/outline/hit.js.map +1 -1
- package/dist/outline/index.d.ts +3 -3
- package/dist/outline/index.js +3 -3
- package/dist/outline/shapes.d.ts +3 -1
- package/dist/outline/shapes.d.ts.map +1 -1
- package/dist/outline/shapes.js +18 -39
- package/dist/outline/shapes.js.map +1 -1
- package/dist/paints/index.d.ts +3 -1
- package/dist/paints/index.js +3 -1
- package/dist/paints/pattern.d.ts +13 -0
- package/dist/paints/pattern.d.ts.map +1 -0
- package/dist/paints/pattern.js +47 -0
- package/dist/paints/pattern.js.map +1 -0
- package/dist/paints/shows.d.ts +11 -0
- package/dist/paints/shows.d.ts.map +1 -0
- package/dist/paints/shows.js +16 -0
- package/dist/paints/shows.js.map +1 -0
- package/dist/paths/arc.d.ts +32 -0
- package/dist/paths/arc.d.ts.map +1 -0
- package/dist/paths/arc.js +49 -0
- package/dist/paths/arc.js.map +1 -0
- package/dist/paths/index.d.ts +5 -0
- package/dist/paths/index.js +5 -0
- package/dist/paths/network.d.ts +43 -0
- package/dist/paths/network.d.ts.map +1 -0
- package/dist/paths/network.js +249 -0
- package/dist/paths/network.js.map +1 -0
- package/dist/paths/sink.d.ts +20 -0
- package/dist/paths/sink.d.ts.map +1 -0
- package/dist/paths/sink.js +32 -0
- package/dist/paths/sink.js.map +1 -0
- package/dist/paths/smooth-corners.d.ts +25 -0
- package/dist/paths/smooth-corners.d.ts.map +1 -0
- package/dist/paths/smooth-corners.js +196 -0
- package/dist/paths/smooth-corners.js.map +1 -0
- package/dist/plugin-data/fields.d.ts +4 -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/polygon.d.ts +1 -3
- package/dist/polygon.d.ts.map +1 -1
- package/dist/polygon.js +1 -16
- package/dist/polygon.js.map +1 -1
- package/dist/resize.d.ts.map +1 -1
- package/dist/resize.js +5 -5
- package/dist/resize.js.map +1 -1
- package/dist/scaling/node.d.ts.map +1 -1
- package/dist/scaling/node.js +25 -3
- package/dist/scaling/node.js.map +1 -1
- package/dist/text/auto-resize.d.ts +15 -0
- package/dist/text/auto-resize.d.ts.map +1 -0
- package/dist/text/auto-resize.js +23 -0
- package/dist/text/auto-resize.js.map +1 -0
- package/dist/text/index.d.ts +4 -3
- package/dist/text/index.js +4 -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 +14 -5
- 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/text/path.js +10 -0
- package/dist/text/path.js.map +1 -0
- package/dist/text/picture.js +5 -5
- package/dist/text/picture.js.map +1 -1
- package/dist/transfer/dependencies.d.ts.map +1 -1
- package/dist/transfer/dependencies.js +3 -2
- package/dist/transfer/dependencies.js.map +1 -1
- package/dist/transfer/nodes.js +2 -1
- package/dist/transfer/nodes.js.map +1 -1
- package/dist/types.d.ts +21 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/variables/index.d.ts +4 -3
- package/dist/variables/index.d.ts.map +1 -1
- package/dist/variables/index.js +4 -3
- package/dist/variables/index.js.map +1 -1
- package/dist/variables/lookup.d.ts +20 -0
- package/dist/variables/lookup.d.ts.map +1 -0
- package/dist/variables/lookup.js +34 -0
- package/dist/variables/lookup.js.map +1 -0
- package/dist/variables/paints.d.ts +35 -4
- package/dist/variables/paints.d.ts.map +1 -1
- package/dist/variables/paints.js +67 -16
- package/dist/variables/paints.js.map +1 -1
- package/dist/variables/resolution.d.ts +3 -1
- package/dist/variables/resolution.d.ts.map +1 -1
- package/dist/variables/resolution.js +8 -3
- package/dist/variables/resolution.js.map +1 -1
- package/dist/variables/subtree.js +1 -1
- package/dist/variables/subtree.js.map +1 -1
- package/dist/vector-network.d.ts.map +1 -1
- package/dist/vector-network.js +12 -76
- package/dist/vector-network.js.map +1 -1
- package/package.json +25 -1
- package/src/arrays.ts +37 -0
- package/src/buffered-events.ts +2 -1
- package/src/clipping.ts +11 -8
- package/src/components/properties.ts +1 -13
- package/src/corners.ts +93 -0
- package/src/css/grid.ts +21 -7
- package/src/css/index.ts +1 -1
- package/src/font-style.ts +38 -4
- package/src/geometry.ts +219 -6
- package/src/gradient.ts +23 -1
- package/src/graph.ts +22 -4
- package/src/group-bounds.ts +7 -3
- package/src/guides.ts +26 -1
- package/src/hit-test.ts +68 -10
- package/src/icons/fit.ts +24 -0
- package/src/icons/glyph.ts +5 -4
- package/src/icons/index.ts +1 -0
- package/src/images.ts +67 -7
- package/src/instances/assignments.ts +65 -7
- package/src/instances/index.ts +53 -4
- package/src/instances/kept-overrides.ts +2 -5
- package/src/instances/matching.ts +101 -0
- package/src/instances/overrides.ts +18 -0
- package/src/instances/protection.ts +103 -0
- package/src/instances/swap.ts +11 -9
- package/src/instances/sync.ts +11 -184
- package/src/layout/guides.ts +42 -9
- package/src/layout/index.ts +2 -0
- package/src/layout/limits.ts +64 -0
- package/src/layout/sizing.ts +0 -2
- package/src/layout/spacing.ts +11 -0
- package/src/masks.ts +51 -0
- package/src/matrix.ts +15 -2
- package/src/node-defaults.ts +23 -3
- package/src/outline/flatten.ts +30 -18
- package/src/outline/hit.ts +16 -33
- package/src/outline/index.ts +2 -2
- package/src/outline/shapes.ts +19 -36
- package/src/paints/index.ts +2 -0
- package/src/paints/pattern.ts +45 -0
- package/src/paints/shows.ts +13 -0
- package/src/paths/arc.ts +59 -0
- package/src/paths/index.ts +4 -0
- package/src/paths/network.ts +334 -0
- package/src/paths/sink.ts +50 -0
- package/src/paths/smooth-corners.ts +356 -0
- package/src/plugin-data/fields.ts +2 -0
- package/src/polygon.ts +0 -17
- package/src/resize.ts +6 -7
- package/src/scaling/node.ts +29 -3
- package/src/text/auto-resize.ts +25 -0
- package/src/text/index.ts +1 -0
- package/src/text/lengths.ts +11 -0
- package/src/text/overflow.ts +32 -6
- package/src/text/path.ts +13 -0
- package/src/text/picture.ts +5 -5
- package/src/transfer/dependencies.ts +3 -2
- package/src/transfer/nodes.ts +2 -1
- package/src/types.ts +25 -8
- package/src/variables/index.ts +1 -0
- package/src/variables/lookup.ts +31 -0
- package/src/variables/paints.ts +101 -20
- package/src/variables/resolution.ts +14 -2
- package/src/variables/subtree.ts +1 -1
- package/src/vector-network.ts +17 -138
package/dist/font-style.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface ParsedFontStyle {
|
|
|
13
13
|
*/
|
|
14
14
|
declare const FONT_WEIGHT_NAMES: Record<number, string>;
|
|
15
15
|
declare function parseFontStyle(style: string | undefined): ParsedFontStyle;
|
|
16
|
+
declare function namesWidth(style: string): boolean;
|
|
16
17
|
declare function styleToWeight(style: string | undefined): number;
|
|
17
18
|
declare function normalizeFontFamily(family: string): string;
|
|
18
19
|
declare function faceLoadKey(weight: number, italic?: boolean): string;
|
|
@@ -42,5 +43,5 @@ interface NamedFace {
|
|
|
42
43
|
*/
|
|
43
44
|
declare function faceStyleKey({ fontWeight, italic, fontStyle }: NamedFace): string;
|
|
44
45
|
//#endregion
|
|
45
|
-
export { FONT_WEIGHT_NAMES, FontFamilyStyle, NamedFace, ParsedFontStyle, faceLoadKey, faceStyleKey, namesWeight, normalizeFontFamily, parseFontStyle, standardStyleName, styleSpelling, styleToWeight };
|
|
46
|
+
export { FONT_WEIGHT_NAMES, FontFamilyStyle, NamedFace, ParsedFontStyle, faceLoadKey, faceStyleKey, namesWeight, namesWidth, normalizeFontFamily, parseFontStyle, standardStyleName, styleSpelling, styleToWeight };
|
|
46
47
|
//# sourceMappingURL=font-style.d.ts.map
|
package/dist/font-style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-style.d.ts","names":[],"sources":["../src/font-style.ts"],"mappings":";UAAiB;EACf;EACA;;UAGe;EACf;EACA;;;;;;cAOW,mBAAmB;
|
|
1
|
+
{"version":3,"file":"font-style.d.ts","names":[],"sources":["../src/font-style.ts"],"mappings":";UAAiB;EACf;EACA;;UAGe;EACf;EACA;;;;;;cAOW,mBAAmB;iBAmEhB,eAAe,4BAA4B;iBAS3C,WAAW;iBAIX,cAAc;iBAId,oBAAoB;iBAIpB,YAAY,gBAAgB;;;;;iBAU5B,kBAAkB,gBAAgB;;iBAOlC,cAAc;;;;;iBAQd,YAAY;;UASX;EACf;EACA;EACA;;;;;;;;iBASc,eAAe,YAAY,QAAQ,aAAa"}
|
package/dist/font-style.js
CHANGED
|
@@ -66,16 +66,41 @@ const FONT_WEIGHT_BY_STYLE = new Map([
|
|
|
66
66
|
function normalizeFontStyleName(style) {
|
|
67
67
|
return style.toLowerCase().replace(/italic|oblique/u, "").replace(/[^a-z0-9]+/gu, "");
|
|
68
68
|
}
|
|
69
|
+
const FONT_WIDTH_NAME = new RegExp([
|
|
70
|
+
"ultracondensed",
|
|
71
|
+
"ultracompressed",
|
|
72
|
+
"extracompressed",
|
|
73
|
+
"extracondensed",
|
|
74
|
+
"compressed",
|
|
75
|
+
"condensed",
|
|
76
|
+
"narrow",
|
|
77
|
+
"semicompressed",
|
|
78
|
+
"semicondensed",
|
|
79
|
+
"demicondensed",
|
|
80
|
+
"semiexpanded",
|
|
81
|
+
"semiextended",
|
|
82
|
+
"expanded",
|
|
83
|
+
"extended",
|
|
84
|
+
"wide",
|
|
85
|
+
"extraexpanded",
|
|
86
|
+
"extraextended",
|
|
87
|
+
"ultraexpanded",
|
|
88
|
+
"ultraextended"
|
|
89
|
+
].toSorted((a, b) => b.length - a.length).join("|"), "u");
|
|
90
|
+
function weightOfStyleName(name) {
|
|
91
|
+
const numericWeight = name.match(/(?:^|[^0-9])([1-9]00)(?:[^0-9]|$)/u)?.[1];
|
|
92
|
+
return numericWeight ? Number(numericWeight) : FONT_WEIGHT_BY_STYLE.get(name) ?? 400;
|
|
93
|
+
}
|
|
69
94
|
function parseFontStyle(style) {
|
|
70
95
|
const raw = style ?? "";
|
|
71
|
-
const italic = /(?:italic|oblique)/iu.test(raw);
|
|
72
|
-
const normalized = normalizeFontStyleName(raw);
|
|
73
|
-
const numericWeight = normalized.match(/(?:^|[^0-9])([1-9]00)(?:[^0-9]|$)/u)?.[1];
|
|
74
96
|
return {
|
|
75
|
-
weight:
|
|
76
|
-
italic
|
|
97
|
+
weight: weightOfStyleName(normalizeFontStyleName(raw).replace(FONT_WIDTH_NAME, "")),
|
|
98
|
+
italic: /(?:italic|oblique)/iu.test(raw)
|
|
77
99
|
};
|
|
78
100
|
}
|
|
101
|
+
function namesWidth(style) {
|
|
102
|
+
return FONT_WIDTH_NAME.test(normalizeFontStyleName(style));
|
|
103
|
+
}
|
|
79
104
|
function styleToWeight(style) {
|
|
80
105
|
return parseFontStyle(style).weight;
|
|
81
106
|
}
|
|
@@ -122,6 +147,6 @@ function faceStyleKey({ fontWeight, italic, fontStyle }) {
|
|
|
122
147
|
return [key, standardStyleName(fontWeight, italic)].map(styleSpelling).includes(spelling) ? key : fontStyle;
|
|
123
148
|
}
|
|
124
149
|
//#endregion
|
|
125
|
-
export { FONT_WEIGHT_NAMES, faceLoadKey, faceStyleKey, namesWeight, normalizeFontFamily, parseFontStyle, standardStyleName, styleSpelling, styleToWeight };
|
|
150
|
+
export { FONT_WEIGHT_NAMES, faceLoadKey, faceStyleKey, namesWeight, namesWidth, normalizeFontFamily, parseFontStyle, standardStyleName, styleSpelling, styleToWeight };
|
|
126
151
|
|
|
127
152
|
//# sourceMappingURL=font-style.js.map
|
package/dist/font-style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-style.js","names":[],"sources":["../src/font-style.ts"],"sourcesContent":["export interface FontFamilyStyle {\n family: string\n style: string\n}\n\nexport interface ParsedFontStyle {\n weight: number\n italic: boolean\n}\n\n/**\n * The standard weights by the names Google Fonts gives them, which most fonts and Figma's font\n * list use; a font's own names can differ (\"Semi Bold\", \"Book\", \"Heavy\").\n */\nexport const FONT_WEIGHT_NAMES: Record<number, string> = {\n 100: 'Thin',\n 200: 'ExtraLight',\n 300: 'Light',\n 400: 'Regular',\n 500: 'Medium',\n 600: 'SemiBold',\n 700: 'Bold',\n 800: 'ExtraBold',\n 900: 'Black'\n}\n\nconst FONT_WEIGHT_ALIASES = [\n { weight: 100, names: ['thin', 'hairline', 'extrathin', 'ultrathin'] },\n { weight: 200, names: ['extralight', 'ultralight'] },\n { weight: 300, names: ['light'] },\n { weight: 400, names: ['regular', 'normal', 'book', 'roman', 'plain'] },\n { weight: 500, names: ['medium'] },\n { weight: 600, names: ['semibold', 'demibold'] },\n { weight: 700, names: ['bold'] },\n { weight: 800, names: ['extrabold', 'ultrabold'] },\n { weight: 900, names: ['black', 'heavy'] }\n] as const\n\nconst FONT_WEIGHT_BY_STYLE: ReadonlyMap<string, number> = new Map(\n FONT_WEIGHT_ALIASES.flatMap(({ names, weight }) => names.map((name) => [name, weight] as const))\n)\n\nfunction normalizeFontStyleName(style: string): string {\n return style\n .toLowerCase()\n .replace(/italic|oblique/u, '')\n .replace(/[^a-z0-9]+/gu, '')\n}\n\
|
|
1
|
+
{"version":3,"file":"font-style.js","names":[],"sources":["../src/font-style.ts"],"sourcesContent":["export interface FontFamilyStyle {\n family: string\n style: string\n}\n\nexport interface ParsedFontStyle {\n weight: number\n italic: boolean\n}\n\n/**\n * The standard weights by the names Google Fonts gives them, which most fonts and Figma's font\n * list use; a font's own names can differ (\"Semi Bold\", \"Book\", \"Heavy\").\n */\nexport const FONT_WEIGHT_NAMES: Record<number, string> = {\n 100: 'Thin',\n 200: 'ExtraLight',\n 300: 'Light',\n 400: 'Regular',\n 500: 'Medium',\n 600: 'SemiBold',\n 700: 'Bold',\n 800: 'ExtraBold',\n 900: 'Black'\n}\n\nconst FONT_WEIGHT_ALIASES = [\n { weight: 100, names: ['thin', 'hairline', 'extrathin', 'ultrathin'] },\n { weight: 200, names: ['extralight', 'ultralight'] },\n { weight: 300, names: ['light'] },\n { weight: 400, names: ['regular', 'normal', 'book', 'roman', 'plain'] },\n { weight: 500, names: ['medium'] },\n { weight: 600, names: ['semibold', 'demibold'] },\n { weight: 700, names: ['bold'] },\n { weight: 800, names: ['extrabold', 'ultrabold'] },\n { weight: 900, names: ['black', 'heavy'] }\n] as const\n\nconst FONT_WEIGHT_BY_STYLE: ReadonlyMap<string, number> = new Map(\n FONT_WEIGHT_ALIASES.flatMap(({ names, weight }) => names.map((name) => [name, weight] as const))\n)\n\nfunction normalizeFontStyleName(style: string): string {\n return style\n .toLowerCase()\n .replace(/italic|oblique/u, '')\n .replace(/[^a-z0-9]+/gu, '')\n}\n\nconst FONT_WIDTH_NAMES = [\n 'ultracondensed',\n 'ultracompressed',\n 'extracompressed',\n 'extracondensed',\n 'compressed',\n 'condensed',\n 'narrow',\n 'semicompressed',\n 'semicondensed',\n 'demicondensed',\n 'semiexpanded',\n 'semiextended',\n 'expanded',\n 'extended',\n 'wide',\n 'extraexpanded',\n 'extraextended',\n 'ultraexpanded',\n 'ultraextended'\n]\n\nconst FONT_WIDTH_NAME = new RegExp(\n FONT_WIDTH_NAMES.toSorted((a, b) => b.length - a.length).join('|'),\n 'u'\n)\n\nfunction weightOfStyleName(name: string): number {\n const numericWeight = name.match(/(?:^|[^0-9])([1-9]00)(?:[^0-9]|$)/u)?.[1]\n return numericWeight ? Number(numericWeight) : (FONT_WEIGHT_BY_STYLE.get(name) ?? 400)\n}\n\nexport function parseFontStyle(style: string | undefined): ParsedFontStyle {\n const raw = style ?? ''\n const normalized = normalizeFontStyleName(raw)\n return {\n weight: weightOfStyleName(normalized.replace(FONT_WIDTH_NAME, '')),\n italic: /(?:italic|oblique)/iu.test(raw)\n }\n}\n\nexport function namesWidth(style: string): boolean {\n return FONT_WIDTH_NAME.test(normalizeFontStyleName(style))\n}\n\nexport function styleToWeight(style: string | undefined): number {\n return parseFontStyle(style).weight\n}\n\nexport function normalizeFontFamily(family: string): string {\n return family.replace(/\\s+(Variable|\\d+(?:pt|px|em))$/i, '')\n}\n\nexport function faceLoadKey(weight: number, italic = false): string {\n const rounded = Math.round(weight / 100) * 100\n const label = FONT_WEIGHT_NAMES[rounded] ?? 'Regular'\n return italic ? `${label} Italic` : label\n}\n\n/**\n * The name Google Fonts gives the face at `weight` and slant (\"SemiBold Italic\", and \"Italic\"\n * for the regular weight), for a face whose font has not said its own.\n */\nexport function standardStyleName(weight: number, italic = false): string {\n const label = FONT_WEIGHT_NAMES[Math.round(weight / 100) * 100] ?? 'Regular'\n if (!italic) return label\n return label === 'Regular' ? 'Italic' : `${label} Italic`\n}\n\n/** A style name compared without case or spaces, so \"Semi Bold\" and \"SemiBold\" name one face. */\nexport function styleSpelling(style: string): string {\n return style.toLowerCase().replace(/\\s+/gu, '')\n}\n\n/**\n * Whether `style` only names a weight and slant (\"Bold Italic\", \"Semi Bold\"), so any face of that\n * weight is it; a name such as \"Book\" or \"Condensed Bold\" is one face of its own.\n */\nexport function namesWeight(style: string): boolean {\n const { weight, italic } = parseFontStyle(style)\n const spelling = styleSpelling(style)\n return [faceLoadKey(weight, italic), standardStyleName(weight, italic)]\n .map(styleSpelling)\n .includes(spelling)\n}\n\n/** A face as text sets it: a weight and slant, and the name it was given, if any. */\nexport interface NamedFace {\n fontWeight: number\n italic: boolean\n fontStyle: string | null\n}\n\n/**\n * The style a face loads and draws as. A name that only spells its weight and slant (\"Semi Bold\",\n * \"Italic\") loads as the weight's key, so whichever font of the family draws that weight draws\n * it; any other name (\"Book\", \"Condensed Bold\", \"Retina\") is a face the weight cannot pick, and\n * it loads and draws by that name.\n */\nexport function faceStyleKey({ fontWeight, italic, fontStyle }: NamedFace): string {\n const key = faceLoadKey(fontWeight, italic)\n if (!fontStyle) return key\n const spelling = styleSpelling(fontStyle)\n const weightNames = [key, standardStyleName(fontWeight, italic)].map(styleSpelling)\n return weightNames.includes(spelling) ? key : fontStyle\n}\n"],"mappings":";;;;;AAcA,MAAa,oBAA4C;CACvD,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP;AAcA,MAAM,uBAAoD,IAAI,IAC5D;CAZA;EAAE,QAAQ;EAAK,OAAO;GAAC;GAAQ;GAAY;GAAa;EAAW;CAAE;CACrE;EAAE,QAAQ;EAAK,OAAO,CAAC,cAAc,YAAY;CAAE;CACnD;EAAE,QAAQ;EAAK,OAAO,CAAC,OAAO;CAAE;CAChC;EAAE,QAAQ;EAAK,OAAO;GAAC;GAAW;GAAU;GAAQ;GAAS;EAAO;CAAE;CACtE;EAAE,QAAQ;EAAK,OAAO,CAAC,QAAQ;CAAE;CACjC;EAAE,QAAQ;EAAK,OAAO,CAAC,YAAY,UAAU;CAAE;CAC/C;EAAE,QAAQ;EAAK,OAAO,CAAC,MAAM;CAAE;CAC/B;EAAE,QAAQ;EAAK,OAAO,CAAC,aAAa,WAAW;CAAE;CACjD;EAAE,QAAQ;EAAK,OAAO,CAAC,SAAS,OAAO;CAAE;AAIvB,CAAC,CAAC,SAAS,EAAE,OAA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AAG,IAAI,QAAQ;CACnE,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,UAAU,YAAY,WAAW,GAAG,MAAM;AACnD;;AAGA,SAAgB,cAAc,OAAuB;CACnD,OAAO,MAAM,YAAY,CAAC,CAAC,QAAQ,SAAS,EAAE;AAChD;;;;;AAMA,SAAgB,YAAY,OAAwB;CAClD,MAAM,EAAE,QAAQ,WAAW,eAAe,KAAK;CAC/C,MAAM,WAAW,cAAc,KAAK;CACpC,OAAO,CAAC,YAAY,QAAQ,MAAM,GAAG,kBAAkB,QAAQ,MAAM,CAAC,CAAC,CACpE,IAAI,aAAa,CAAC,CAClB,SAAS,QAAQ;AACtB;;;;;;;AAeA,SAAgB,aAAa,EAAE,YAAY,QAAQ,aAAgC;CACjF,MAAM,MAAM,YAAY,YAAY,MAAM;CAC1C,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,WAAW,cAAc,SAAS;CAExC,OADoB,CAAC,KAAK,kBAAkB,YAAY,MAAM,CAAC,CAAC,CAAC,IAAI,aACpD,CAAC,CAAC,SAAS,QAAQ,IAAI,MAAM;AAChD"}
|
package/dist/geometry.d.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { Rect, Vector } from "./primitives/index.js";
|
|
2
|
-
import { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
|
|
2
|
+
import { ArcData, Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from "./types.js";
|
|
3
3
|
import { cubicPoint } from "./cubic.js";
|
|
4
4
|
//#region src/geometry.d.ts
|
|
5
5
|
declare function degToRad(degrees: number): number;
|
|
6
6
|
declare function radToDeg(radians: number): number;
|
|
7
|
+
/**
|
|
8
|
+
* Whether a layer's shadows take their spread. Figma spreads those of boxes and ellipses, arcs
|
|
9
|
+
* among them, and frames, and counts it in their render bounds; a text, boolean, star, polygon or
|
|
10
|
+
* vector never spreads (Figma desktop, live).
|
|
11
|
+
*/
|
|
12
|
+
declare function shadowSpreads(node: Pick<SceneNode, 'type'>): boolean;
|
|
13
|
+
/** The spread a shadow on `node` takes: its own, or none on a layer Figma never spreads. */
|
|
14
|
+
declare function shadowSpreadOf(node: Pick<SceneNode, 'type'>, effect: Pick<Effect, 'spread'>): number;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a sweep from `start` to `end` is a whole turn: less than 0.001 rad short of one draws the
|
|
17
|
+
* whole ellipse in Figma (desktop, live: 0.00095 short is whole, 0.001 short an arc).
|
|
18
|
+
*/
|
|
19
|
+
declare function sweepsWholeTurn(start: number, end: number): boolean;
|
|
20
|
+
/** Whether an arc sweeps a whole turn, so it is drawn and edited as a whole ellipse or ring. */
|
|
21
|
+
declare function isWholeArc(arc: Pick<ArcData, 'startingAngle' | 'endingAngle'>): boolean;
|
|
7
22
|
declare function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector;
|
|
8
23
|
declare function rotatedCorners(cx: number, cy: number, hw: number, hh: number, rotationDeg: number): [Vector, Vector, Vector, Vector];
|
|
9
24
|
declare function rotatedBBox(x: number, y: number, w: number, h: number, rotationDeg: number): {
|
|
@@ -30,11 +45,41 @@ declare function polygonVertices(node: {
|
|
|
30
45
|
type: string;
|
|
31
46
|
starInnerRadius: number;
|
|
32
47
|
}): Vector[];
|
|
48
|
+
/** A rectangle's stroke weights, side by side: top, right, bottom, left. */
|
|
49
|
+
type SideWeights = readonly [top: number, right: number, bottom: number, left: number];
|
|
50
|
+
type SideStrokeNode = Pick<SceneNode, 'independentStrokeWeights' | 'borderTopWeight' | 'borderRightWeight' | 'borderBottomWeight' | 'borderLeftWeight'>;
|
|
51
|
+
/**
|
|
52
|
+
* Whether `node` strokes each side by its own weight. A line or vector keeps one weight whatever
|
|
53
|
+
* the flag says, since its outline has no sides.
|
|
54
|
+
*/
|
|
55
|
+
declare function drawsStrokeSides(node: Partial<SideStrokeNode> & {
|
|
56
|
+
type?: string;
|
|
57
|
+
}): boolean;
|
|
58
|
+
/** The share of a stroke's weight that lies outside the shape it outlines. */
|
|
59
|
+
declare function strokeAlignShare(align: Stroke['align']): number;
|
|
60
|
+
/** A layer's own side weights: top, right, bottom, left. */
|
|
61
|
+
declare function borderWeights(node: SideStrokeNode): SideWeights;
|
|
62
|
+
/** The weight of each side of `node` under `stroke`, its own when its sides have their own. */
|
|
63
|
+
declare function strokeSideWeights(node: SideStrokeNode & {
|
|
64
|
+
type?: string;
|
|
65
|
+
}, stroke: Pick<Stroke, 'weight'>): SideWeights;
|
|
66
|
+
/** A stroke's weight, or with sides of their own the widest side, for what is not drawn per side. */
|
|
67
|
+
declare function strokeWeightOf(node: Partial<SideStrokeNode> & {
|
|
68
|
+
type?: string;
|
|
69
|
+
}, stroke: Pick<Stroke, 'weight'>): number;
|
|
70
|
+
/**
|
|
71
|
+
* How far a layer's visible strokes reach past each side of its box: top, right, bottom, left.
|
|
72
|
+
* With sides of their own each side reaches by its own weight (Figma desktop, live: a 1px outside
|
|
73
|
+
* stroke with a 20px right side bounds a 100 × 100 rectangle at 121 × 102).
|
|
74
|
+
*/
|
|
75
|
+
declare function strokeSideReach(node: SideStrokeNode & Pick<SceneNode, 'strokes'> & {
|
|
76
|
+
type?: string;
|
|
77
|
+
}): SideWeights;
|
|
33
78
|
/**
|
|
34
79
|
* What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to
|
|
35
80
|
* one side, and its join and miter limit, for the tips mitered path corners reach.
|
|
36
81
|
*/
|
|
37
|
-
interface StrokeShape {
|
|
82
|
+
interface StrokeShape extends Partial<SideStrokeNode> {
|
|
38
83
|
type?: string;
|
|
39
84
|
strokeJoin?: StrokeJoin;
|
|
40
85
|
strokeMiterLimit?: number;
|
|
@@ -56,8 +101,28 @@ declare function widestBlurRadius(effect: Pick<Effect, 'radius' | 'progressive'>
|
|
|
56
101
|
* SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).
|
|
57
102
|
*/
|
|
58
103
|
declare function blurSigma(radius: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* How far past what it blurs a Gaussian of `sigma` leaves ink on screen: where Skia's kernel
|
|
106
|
+
* ends, and one more pixel holds its rounding.
|
|
107
|
+
*/
|
|
108
|
+
declare function kernelReach(sigma: number): number;
|
|
109
|
+
/** How far past what it blurs a Figma blur of `radius` leaves ink on screen (`kernelReach`). */
|
|
110
|
+
declare function blurReach(radius: number): number;
|
|
111
|
+
/**
|
|
112
|
+
* How far past its shape a drop shadow of `radius` and colour alpha `alpha` leaves ink on
|
|
113
|
+
* screen. Skia blurs the shape into an 8-bit mask and scales it by `alpha`, so a mask level shows
|
|
114
|
+
* once `alpha` times it rounds to a level: an opaque or half-opaque shadow shows its faintest
|
|
115
|
+
* level, out to where the kernel ends, and a fainter one ends sooner. Measured on CPU raster, the
|
|
116
|
+
* ink ends at 3.0 sigma for alpha 1 and 0.5, 2.4 for 0.25, and 2.1 for 0.1.
|
|
117
|
+
*/
|
|
118
|
+
declare function shadowReach(radius: number, alpha: number): number;
|
|
59
119
|
/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
|
|
60
120
|
declare function blurRadiusForSigma(sigma: number): number;
|
|
121
|
+
/**
|
|
122
|
+
* How far a layer's shadows and blurs reach past each side as Figma's render bounds count them:
|
|
123
|
+
* a blur by its radius, a shadow by its radius and spread, moved by its offset. Ink on screen
|
|
124
|
+
* reaches further, to `blurReach`.
|
|
125
|
+
*/
|
|
61
126
|
declare function effectOverflow(effects?: Effect[]): {
|
|
62
127
|
left: number;
|
|
63
128
|
right: number;
|
|
@@ -92,5 +157,5 @@ declare function geometryBlobBounds(paths: Array<{
|
|
|
92
157
|
/** How far a text node's underline or strikethrough reaches below its box. */
|
|
93
158
|
declare function textDecorationOverflow(node: Pick<SceneNode, 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'>): number;
|
|
94
159
|
//#endregion
|
|
95
|
-
export { GeometryCommand, StrokeShape, VisualBounds, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds, visualBoundsToRect, widestBlurRadius };
|
|
160
|
+
export { GeometryCommand, SideWeights, StrokeShape, VisualBounds, blurRadiusForSigma, blurReach, blurSigma, borderWeights, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, drawsStrokeSides, effectOverflow, geometryBlobBounds, intersectVisualBounds, isWholeArc, kernelReach, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, shadowReach, shadowSpreadOf, shadowSpreads, strokeAlignShare, strokeOverflow, strokeSideReach, strokeSideWeights, strokeWeightOf, sweepsWholeTurn, textDecorationOverflow, unionVisualBounds, visualBoundsToRect, widestBlurRadius };
|
|
96
161
|
//# sourceMappingURL=geometry.d.ts.map
|
package/dist/geometry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAcgB,SAAS;iBAIT,SAAS;;;;;;iBAoBT,cAAc,MAAM,KAAK;;iBAKzB,eACd,MAAM,KAAK,oBACX,QAAQ,KAAK;;;;;iBASC,gBAAgB,eAAe;;iBAK/B,WAAW,KAAK,KAAK;iBAIrB,YAAY,YAAY,YAAY,YAAY,YAAY,cAAc;iBAS1E,eACd,YACA,YACA,YACA,YACA,uBACE,QAAQ,QAAQ,QAAQ;iBAYZ,YACd,WACA,WACA,WACA,WACA;EACG;EAAc;EAAe;EAAa;EAAgB;EAAiB;;UAyB/D;EACf;EACA;EACA;EACA;;;iBAsBc,mBAAmB,QAAQ,eAAe;iBAa1C,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;KAuBQ,wBAAwB,aAAa,eAAe,gBAAgB;KAE3E,iBAAiB,KACpB;;;;;iBAuBc,iBAAiB,MAAM,QAAQ;EAAoB;;;iBAKnD,iBAAiB,OAAO;;iBAOxB,cAAc,MAAM,iBAAiB;;iBAUrC,kBACd,MAAM;EAAmB;GACzB,QAAQ,KAAK,oBACZ;;iBAMa,eACd,MAAM,QAAQ;EAAoB;GAClC,QAAQ,KAAK;;;;;;iBAgBC,gBACd,MAAM,iBAAiB,KAAK;EAA0B;IACrD;;;;;UAoBc,oBAAoB,QAAQ;EAC3C;EACA,aAAa;EACb;;iBAec,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;;;;;iBAiEM,gBAAgB;;;;;iBAQhB,iBAAiB,QAAQ,KAAK;;;;;;iBAW9B,UAAU;;;;;iBAWV,YAAY;;iBAKZ,UAAU;;;;;;;;iBAiCV,YAAY,gBAAgB;;iBAW5B,mBAAmB;;;;;;iBASnB,eAAe,UAAU;;;;;;iBAyBzB,sBACd,OAAO;EAAW;EAAY;EAAe;IAC7C,sBAAsB,eAAe,SACpC;iBASa,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;cAS5D;;;;;;;KACD,0BAA0B,8BAA8B;;;;;;iBAmBpD,iBACd,MAAM,YACN,QAAQ,SAAS,iBAAiB,2BAA2B;iBAmB/C,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;;iBAYhE,uBACd,MAAM,KACJ"}
|
package/dist/geometry.js
CHANGED
|
@@ -7,6 +7,38 @@ function degToRad(degrees) {
|
|
|
7
7
|
function radToDeg(radians) {
|
|
8
8
|
return radians * 180 / Math.PI;
|
|
9
9
|
}
|
|
10
|
+
const FULL_TURN = 2 * Math.PI;
|
|
11
|
+
/** Layers whose shadows Figma never spreads: a text, boolean, star, polygon or vector. */
|
|
12
|
+
const UNSPREAD_TYPES = /* @__PURE__ */ new Set([
|
|
13
|
+
"TEXT",
|
|
14
|
+
"BOOLEAN_OPERATION",
|
|
15
|
+
"STAR",
|
|
16
|
+
"POLYGON",
|
|
17
|
+
"VECTOR"
|
|
18
|
+
]);
|
|
19
|
+
/**
|
|
20
|
+
* Whether a layer's shadows take their spread. Figma spreads those of boxes and ellipses, arcs
|
|
21
|
+
* among them, and frames, and counts it in their render bounds; a text, boolean, star, polygon or
|
|
22
|
+
* vector never spreads (Figma desktop, live).
|
|
23
|
+
*/
|
|
24
|
+
function shadowSpreads(node) {
|
|
25
|
+
return !UNSPREAD_TYPES.has(node.type);
|
|
26
|
+
}
|
|
27
|
+
/** The spread a shadow on `node` takes: its own, or none on a layer Figma never spreads. */
|
|
28
|
+
function shadowSpreadOf(node, effect) {
|
|
29
|
+
return shadowSpreads(node) ? effect.spread : 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Whether a sweep from `start` to `end` is a whole turn: less than 0.001 rad short of one draws the
|
|
33
|
+
* whole ellipse in Figma (desktop, live: 0.00095 short is whole, 0.001 short an arc).
|
|
34
|
+
*/
|
|
35
|
+
function sweepsWholeTurn(start, end) {
|
|
36
|
+
return FULL_TURN - Math.abs(end - start) < .001;
|
|
37
|
+
}
|
|
38
|
+
/** Whether an arc sweeps a whole turn, so it is drawn and edited as a whole ellipse or ring. */
|
|
39
|
+
function isWholeArc(arc) {
|
|
40
|
+
return sweepsWholeTurn(arc.startingAngle, arc.endingAngle);
|
|
41
|
+
}
|
|
10
42
|
function rotatePoint(px, py, cx, cy, rad) {
|
|
11
43
|
const cos = Math.cos(rad);
|
|
12
44
|
const sin = Math.sin(rad);
|
|
@@ -123,6 +155,84 @@ function polygonVertices(node) {
|
|
|
123
155
|
};
|
|
124
156
|
});
|
|
125
157
|
}
|
|
158
|
+
/** The layers the canvas strokes side by side when their sides have weights of their own. */
|
|
159
|
+
const SIDE_STROKE_TYPES = /* @__PURE__ */ new Set([
|
|
160
|
+
"FRAME",
|
|
161
|
+
"RECTANGLE",
|
|
162
|
+
"ROUNDED_RECTANGLE",
|
|
163
|
+
"COMPONENT",
|
|
164
|
+
"INSTANCE",
|
|
165
|
+
"SECTION",
|
|
166
|
+
"GROUP"
|
|
167
|
+
]);
|
|
168
|
+
/**
|
|
169
|
+
* Whether `node` strokes each side by its own weight. A line or vector keeps one weight whatever
|
|
170
|
+
* the flag says, since its outline has no sides.
|
|
171
|
+
*/
|
|
172
|
+
function drawsStrokeSides(node) {
|
|
173
|
+
return node.independentStrokeWeights === true && (!node.type || SIDE_STROKE_TYPES.has(node.type));
|
|
174
|
+
}
|
|
175
|
+
/** The share of a stroke's weight that lies outside the shape it outlines. */
|
|
176
|
+
function strokeAlignShare(align) {
|
|
177
|
+
if (align === "OUTSIDE") return 1;
|
|
178
|
+
if (align === "CENTER") return .5;
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
/** A layer's own side weights: top, right, bottom, left. */
|
|
182
|
+
function borderWeights(node) {
|
|
183
|
+
return [
|
|
184
|
+
node.borderTopWeight,
|
|
185
|
+
node.borderRightWeight,
|
|
186
|
+
node.borderBottomWeight,
|
|
187
|
+
node.borderLeftWeight
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
/** The weight of each side of `node` under `stroke`, its own when its sides have their own. */
|
|
191
|
+
function strokeSideWeights(node, stroke) {
|
|
192
|
+
if (!drawsStrokeSides(node)) return [
|
|
193
|
+
stroke.weight,
|
|
194
|
+
stroke.weight,
|
|
195
|
+
stroke.weight,
|
|
196
|
+
stroke.weight
|
|
197
|
+
];
|
|
198
|
+
return borderWeights(node);
|
|
199
|
+
}
|
|
200
|
+
/** A stroke's weight, or with sides of their own the widest side, for what is not drawn per side. */
|
|
201
|
+
function strokeWeightOf(node, stroke) {
|
|
202
|
+
if (!drawsStrokeSides(node)) return stroke.weight;
|
|
203
|
+
return Math.max(node.borderTopWeight ?? 0, node.borderRightWeight ?? 0, node.borderBottomWeight ?? 0, node.borderLeftWeight ?? 0);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* How far a layer's visible strokes reach past each side of its box: top, right, bottom, left.
|
|
207
|
+
* With sides of their own each side reaches by its own weight (Figma desktop, live: a 1px outside
|
|
208
|
+
* stroke with a 20px right side bounds a 100 × 100 rectangle at 121 × 102).
|
|
209
|
+
*/
|
|
210
|
+
function strokeSideReach(node) {
|
|
211
|
+
let reach = [
|
|
212
|
+
0,
|
|
213
|
+
0,
|
|
214
|
+
0,
|
|
215
|
+
0
|
|
216
|
+
];
|
|
217
|
+
for (const stroke of node.strokes) {
|
|
218
|
+
if (!stroke.visible) continue;
|
|
219
|
+
const share = strokeAlignShare(stroke.align);
|
|
220
|
+
const sides = strokeSideWeights(node, stroke);
|
|
221
|
+
reach = [
|
|
222
|
+
Math.max(reach[0], sides[0] * share),
|
|
223
|
+
Math.max(reach[1], sides[1] * share),
|
|
224
|
+
Math.max(reach[2], sides[2] * share),
|
|
225
|
+
Math.max(reach[3], sides[3] * share)
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
return reach;
|
|
229
|
+
}
|
|
230
|
+
/** How far past a path a stroke of `weight` reaches, before mitered corners: a line's stroke lies wholly to one side. */
|
|
231
|
+
function strokeExtent(weight, align, line, open) {
|
|
232
|
+
if (line || align === "OUTSIDE") return weight;
|
|
233
|
+
if (align === "CENTER" || open) return weight / 2;
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
126
236
|
function strokeOverflow(strokes, fallbackCap, network, shape) {
|
|
127
237
|
const line = shape?.type === "LINE";
|
|
128
238
|
const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()));
|
|
@@ -131,10 +241,7 @@ function strokeOverflow(strokes, fallbackCap, network, shape) {
|
|
|
131
241
|
let overflow = 0;
|
|
132
242
|
for (const stroke of strokes ?? []) {
|
|
133
243
|
if (!stroke.visible) continue;
|
|
134
|
-
const
|
|
135
|
-
let extra = open ? stroke.weight / 2 : 0;
|
|
136
|
-
if (line || align === "OUTSIDE") extra = stroke.weight;
|
|
137
|
-
else if (align === "CENTER") extra = stroke.weight / 2;
|
|
244
|
+
const extra = strokeExtent(strokeWeightOf(shape ?? {}, stroke), sided ? stroke.align : "CENTER", line, open);
|
|
138
245
|
const miter = network ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit) : 1;
|
|
139
246
|
overflow = Math.max(overflow, extra * miter);
|
|
140
247
|
}
|
|
@@ -199,10 +306,53 @@ const BLUR_SIGMA_PER_RADIUS = .43;
|
|
|
199
306
|
function blurSigma(radius) {
|
|
200
307
|
return drawnBlurRadius(radius) * BLUR_SIGMA_PER_RADIUS;
|
|
201
308
|
}
|
|
309
|
+
/** Skia's Gaussian kernels end at 3 sigma. */
|
|
310
|
+
const KERNEL_SIGMAS = 3;
|
|
311
|
+
/**
|
|
312
|
+
* How far past what it blurs a Gaussian of `sigma` leaves ink on screen: where Skia's kernel
|
|
313
|
+
* ends, and one more pixel holds its rounding.
|
|
314
|
+
*/
|
|
315
|
+
function kernelReach(sigma) {
|
|
316
|
+
return sigma > 0 ? Math.ceil(KERNEL_SIGMAS * sigma) + 1 : 0;
|
|
317
|
+
}
|
|
318
|
+
/** How far past what it blurs a Figma blur of `radius` leaves ink on screen (`kernelReach`). */
|
|
319
|
+
function blurReach(radius) {
|
|
320
|
+
return kernelReach(blurSigma(radius));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* The distance, in sigmas, past a straight edge blurred by a Gaussian at which the edge's share
|
|
324
|
+
* drops to `share`: the inverse of the normal tail Q, by Abramowitz and Stegun 26.2.23, which is
|
|
325
|
+
* within 0.00045 of it.
|
|
326
|
+
*/
|
|
327
|
+
function gaussianTailDistance(share) {
|
|
328
|
+
if (share <= 0) return Number.POSITIVE_INFINITY;
|
|
329
|
+
if (share >= .5) return 0;
|
|
330
|
+
const s = Math.sqrt(-2 * Math.log(share));
|
|
331
|
+
return s - (2.515517 + .802853 * s + .010328 * s * s) / (1 + 1.432788 * s + .189269 * s * s + .001308 * s * s * s);
|
|
332
|
+
}
|
|
333
|
+
const COLOR_LEVELS = 255;
|
|
334
|
+
/**
|
|
335
|
+
* How far past its shape a drop shadow of `radius` and colour alpha `alpha` leaves ink on
|
|
336
|
+
* screen. Skia blurs the shape into an 8-bit mask and scales it by `alpha`, so a mask level shows
|
|
337
|
+
* once `alpha` times it rounds to a level: an opaque or half-opaque shadow shows its faintest
|
|
338
|
+
* level, out to where the kernel ends, and a fainter one ends sooner. Measured on CPU raster, the
|
|
339
|
+
* ink ends at 3.0 sigma for alpha 1 and 0.5, 2.4 for 0.25, and 2.1 for 0.1.
|
|
340
|
+
*/
|
|
341
|
+
function shadowReach(radius, alpha) {
|
|
342
|
+
const sigma = blurSigma(radius);
|
|
343
|
+
const faintestShownLevel = Math.ceil(.5 / Math.max(alpha, 1 / COLOR_LEVELS));
|
|
344
|
+
const sigmas = Math.min(KERNEL_SIGMAS, gaussianTailDistance((faintestShownLevel - 1) / COLOR_LEVELS));
|
|
345
|
+
return Math.ceil(sigmas * sigma) + 1;
|
|
346
|
+
}
|
|
202
347
|
/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
|
|
203
348
|
function blurRadiusForSigma(sigma) {
|
|
204
349
|
return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS;
|
|
205
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* How far a layer's shadows and blurs reach past each side as Figma's render bounds count them:
|
|
353
|
+
* a blur by its radius, a shadow by its radius and spread, moved by its offset. Ink on screen
|
|
354
|
+
* reaches further, to `blurReach`.
|
|
355
|
+
*/
|
|
206
356
|
function effectOverflow(effects) {
|
|
207
357
|
let left = 0;
|
|
208
358
|
let right = 0;
|
|
@@ -312,6 +462,6 @@ function textDecorationOverflow(node) {
|
|
|
312
462
|
return (node.textUnderlineOffset ?? fontSize * .18) + (node.textDecorationThickness ?? Math.max(1, fontSize / 16)) + fontSize * .35;
|
|
313
463
|
}
|
|
314
464
|
//#endregion
|
|
315
|
-
export { GeometryCommand, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds, visualBoundsToRect, widestBlurRadius };
|
|
465
|
+
export { GeometryCommand, blurRadiusForSigma, blurReach, blurSigma, borderWeights, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, drawsStrokeSides, effectOverflow, geometryBlobBounds, intersectVisualBounds, isWholeArc, kernelReach, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, shadowReach, shadowSpreadOf, shadowSpreads, strokeAlignShare, strokeOverflow, strokeSideReach, strokeSideWeights, strokeWeightOf, sweepsWholeTurn, textDecorationOverflow, unionVisualBounds, visualBoundsToRect, widestBlurRadius };
|
|
316
466
|
|
|
317
467
|
//# sourceMappingURL=geometry.js.map
|
package/dist/geometry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Rect, Vector } from './primitives'\nimport type { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\n\nexport { cubicPoint } from './cubic'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\n/** `bounds` as a rect at its top-left corner. */\nexport function visualBoundsToRect(bounds: VisualBounds): Rect {\n return {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity ? { x: 0, y: 0, width: 0, height: 0 } : visualBoundsToRect(bounds)\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const align = sided ? stroke.align : 'CENTER'\n let extra = open ? stroke.weight / 2 : 0\n if (line || align === 'OUTSIDE') extra = stroke.weight\n else if (align === 'CENTER') extra = stroke.weight / 2\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\n/**\n * The blur radius Figma draws: a negative one, which only a bound variable can give, draws as no\n * blur, though the layer keeps the value.\n */\nexport function drawnBlurRadius(radius: number): number {\n return Math.max(0, radius)\n}\n\n/**\n * The widest radius an effect blurs by: its radius, or the larger end of a progressive blur,\n * which can start wider than it ends. Bounds and padding that must hold the whole blur use it.\n */\nexport function widestBlurRadius(effect: Pick<Effect, 'radius' | 'progressive'>): number {\n return Math.max(effect.radius, effect.progressive?.startRadius ?? effect.radius)\n}\n\nconst BLUR_SIGMA_PER_RADIUS = 0.43\n\n/**\n * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,\n * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's\n * SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).\n */\nexport function blurSigma(radius: number): number {\n return drawnBlurRadius(radius) * BLUR_SIGMA_PER_RADIUS\n}\n\n/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */\nexport function blurRadiusForSigma(sigma: number): number {\n return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS\n}\n\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = drawnBlurRadius(widestBlurRadius(effect)) + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/** The path commands of a Figma geometry blob, by their byte code. */\nexport const GeometryCommand = { CLOSE: 0, MOVE: 1, LINE: 2, QUAD: 3, CUBIC: 4 } as const\nexport type GeometryCommand = (typeof GeometryCommand)[keyof typeof GeometryCommand]\n\n/**\n * Coordinate pairs per command: glyph-derived blobs are quad-heavy, so every code needs its\n * count. Unknown codes are null, so readers stop instead of desyncing into coordinate bytes.\n */\nfunction commandCoordCount(command: number): number | null {\n if (command === GeometryCommand.CLOSE) return 0\n if (command === GeometryCommand.MOVE || command === GeometryCommand.LINE) return 1\n if (command === GeometryCommand.QUAD) return 2\n if (command === GeometryCommand.CUBIC) return 3\n return null\n}\n\n/**\n * Walks a Figma geometry blob: `visit` gets each command, its coordinates as x, y pairs in one\n * array reused between calls, and the byte offset of the first coordinate. It stops at an\n * unknown command or one cut short.\n */\nexport function readGeometryBlob(\n blob: Uint8Array,\n visit: (command: GeometryCommand, coords: readonly number[], offset: number) => void\n): void {\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n const coords: number[] = []\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset]\n const count = commandCoordCount(command)\n if (count === null || offset + 1 + count * 8 > blob.length) return\n offset += 1\n coords.length = 0\n for (let i = 0; i < count; i++) {\n coords.push(view.getFloat32(offset + i * 8, true), view.getFloat32(offset + i * 8 + 4, true))\n }\n visit(command as GeometryCommand, coords, offset)\n offset += count * 8\n }\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n for (const path of paths) {\n readGeometryBlob(path.commandsBlob, (_, coords) => {\n for (let i = 0; i < coords.length; i += 2) includePoint(bounds, coords[i], coords[i + 1])\n })\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(\n node: Pick<\n SceneNode,\n 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'\n >\n): number {\n if (node.type !== 'TEXT' || node.textDecoration === 'NONE') {\n return 0\n }\n const { fontSize } = node\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n return underlineOffset + thickness + fontSize * 0.35\n}\n"],"mappings":";;;AAMA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,SAAgB,YAAY,IAAY,IAAY,IAAY,IAAY,KAAqB;CAC/F,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OAAO;EACL,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;EACtC,GAAG,MAAM,KAAK,MAAM,OAAO,KAAK,MAAM;CACxC;AACF;AAEA,SAAgB,eACd,IACA,IACA,IACA,IACA,aACkC;CAClC,MAAM,MAAM,SAAS,WAAW;CAChC,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,MAAM,MAAM,KAAK,IAAI,GAAG;CACxB,OA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AI,GAAG,IAAI,GAAG,KAAK,WAAW,SAAS,IAAI,IAAI,GAAG,IAAI,CAAC;EAE9F,MAAM,SAA4B,QAAQ,MAAM;EAChD,UAAU,QAAQ;CACpB;AACF;AAEA,SAAgB,mBAAmB,OAAyD;CAC1F,MAAM,SAAS,wBAAwB;CACvC,KAAK,MAAM,QAAQ,OACjB,iBAAiB,KAAK,eAAe,GAAG,WAAW;EACjD,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG,aAAa,QAAQ,OAAO,IAAI,OAAO,IAAI,EAAE;CAC1F,CAAC;CAGH,OAAO,OAAO,SAAS,WAAW,OAAO,aAAa,MAAM;AAC9D;;AAGA,SAAgB,uBACd,MAIQ;CACR,IAAI,KAAK,SAAS,UAAU,KAAK,mBAAmB,QAClD,OAAO;CAET,MAAM,EAAE,aAAa;CAGrB,QAFwB,KAAK,uBAAuB,WAAW,QAC7C,KAAK,2BAA2B,KAAK,IAAI,GAAG,WAAW,EAAE,KACtC,WAAW;AAClD"}
|
|
1
|
+
{"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport type { Rect, Vector } from './primitives'\nimport type {\n ArcData,\n Effect,\n SceneNode,\n Stroke,\n StrokeCap,\n StrokeJoin,\n VectorNetwork\n} from './types'\n\nexport { cubicPoint } from './cubic'\n\nexport function degToRad(degrees: number): number {\n return (degrees * Math.PI) / 180\n}\n\nexport function radToDeg(radians: number): number {\n return (radians * 180) / Math.PI\n}\n\nconst FULL_TURN = 2 * Math.PI\n\n/** Layers whose shadows Figma never spreads: a text, boolean, star, polygon or vector. */\nconst UNSPREAD_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'TEXT',\n 'BOOLEAN_OPERATION',\n 'STAR',\n 'POLYGON',\n 'VECTOR'\n])\n\n/**\n * Whether a layer's shadows take their spread. Figma spreads those of boxes and ellipses, arcs\n * among them, and frames, and counts it in their render bounds; a text, boolean, star, polygon or\n * vector never spreads (Figma desktop, live).\n */\nexport function shadowSpreads(node: Pick<SceneNode, 'type'>): boolean {\n return !UNSPREAD_TYPES.has(node.type)\n}\n\n/** The spread a shadow on `node` takes: its own, or none on a layer Figma never spreads. */\nexport function shadowSpreadOf(\n node: Pick<SceneNode, 'type'>,\n effect: Pick<Effect, 'spread'>\n): number {\n return shadowSpreads(node) ? effect.spread : 0\n}\n\n/**\n * Whether a sweep from `start` to `end` is a whole turn: less than 0.001 rad short of one draws the\n * whole ellipse in Figma (desktop, live: 0.00095 short is whole, 0.001 short an arc).\n */\nexport function sweepsWholeTurn(start: number, end: number): boolean {\n return FULL_TURN - Math.abs(end - start) < 0.001\n}\n\n/** Whether an arc sweeps a whole turn, so it is drawn and edited as a whole ellipse or ring. */\nexport function isWholeArc(arc: Pick<ArcData, 'startingAngle' | 'endingAngle'>): boolean {\n return sweepsWholeTurn(arc.startingAngle, arc.endingAngle)\n}\n\nexport function rotatePoint(px: number, py: number, cx: number, cy: number, rad: number): Vector {\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return {\n x: cx + (px - cx) * cos - (py - cy) * sin,\n y: cy + (px - cx) * sin + (py - cy) * cos\n }\n}\n\nexport function rotatedCorners(\n cx: number,\n cy: number,\n hw: number,\n hh: number,\n rotationDeg: number\n): [Vector, Vector, Vector, Vector] {\n const rad = degToRad(rotationDeg)\n const cos = Math.cos(rad)\n const sin = Math.sin(rad)\n return [\n { x: cx + -hw * cos - -hh * sin, y: cy + -hw * sin + -hh * cos },\n { x: cx + hw * cos - -hh * sin, y: cy + hw * sin + -hh * cos },\n { x: cx + hw * cos - hh * sin, y: cy + hw * sin + hh * cos },\n { x: cx + -hw * cos - hh * sin, y: cy + -hw * sin + hh * cos }\n ]\n}\n\nexport function rotatedBBox(\n x: number,\n y: number,\n w: number,\n h: number,\n rotationDeg: number\n): { left: number; right: number; top: number; bottom: number; centerX: number; centerY: number } {\n if (rotationDeg === 0) {\n return {\n left: x,\n right: x + w,\n top: y,\n bottom: y + h,\n centerX: x + w / 2,\n centerY: y + h / 2\n }\n }\n const corners = rotatedCorners(x + w / 2, y + h / 2, w / 2, h / 2, rotationDeg)\n let left = Infinity,\n right = -Infinity,\n top = Infinity,\n bottom = -Infinity\n for (const c of corners) {\n left = Math.min(left, c.x)\n right = Math.max(right, c.x)\n top = Math.min(top, c.y)\n bottom = Math.max(bottom, c.y)\n }\n return { left, right, top, bottom, centerX: (left + right) / 2, centerY: (top + bottom) / 2 }\n}\n\nexport interface VisualBounds {\n minX: number\n minY: number\n maxX: number\n maxY: number\n}\n\ntype BoundsAccumulator = VisualBounds\n\nfunction createBoundsAccumulator(): BoundsAccumulator {\n return { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity }\n}\n\nfunction includePoint(bounds: BoundsAccumulator, x: number, y: number): void {\n bounds.minX = Math.min(bounds.minX, x)\n bounds.minY = Math.min(bounds.minY, y)\n bounds.maxX = Math.max(bounds.maxX, x)\n bounds.maxY = Math.max(bounds.maxY, y)\n}\n\nfunction includeRect(bounds: BoundsAccumulator, rect: Rect): void {\n includePoint(bounds, rect.x, rect.y)\n includePoint(bounds, rect.x + rect.width, rect.y + rect.height)\n}\n\n/** `bounds` as a rect at its top-left corner. */\nexport function visualBoundsToRect(bounds: VisualBounds): Rect {\n return {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\n}\n\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity ? { x: 0, y: 0, width: 0, height: 0 } : visualBoundsToRect(bounds)\n}\n\nexport function computeBounds(items: Iterable<Rect>): Rect {\n const bounds = createBoundsAccumulator()\n for (const item of items) includeRect(bounds, item)\n return boundsToRect(bounds)\n}\n\nexport function polygonVertices(node: {\n width: number\n height: number\n pointCount: number\n type: string\n starInnerRadius: number\n}): Vector[] {\n const cx = node.width / 2\n const cy = node.height / 2\n const rx = node.width / 2\n const ry = node.height / 2\n const pointCount = Math.max(3, node.pointCount)\n const isStar = node.type === 'STAR'\n const innerRatio = isStar ? node.starInnerRadius : 1\n const totalPoints = isStar ? pointCount * 2 : pointCount\n const angleOffset = -Math.PI / 2\n\n return Array.from({ length: totalPoints }, (_, index) => {\n const angle = angleOffset + (2 * Math.PI * index) / totalPoints\n const isInner = isStar && index % 2 === 1\n const radius = isInner ? innerRatio : 1\n return {\n x: cx + rx * radius * Math.cos(angle),\n y: cy + ry * radius * Math.sin(angle)\n }\n })\n}\n\n/** A rectangle's stroke weights, side by side: top, right, bottom, left. */\nexport type SideWeights = readonly [top: number, right: number, bottom: number, left: number]\n\ntype SideStrokeNode = Pick<\n SceneNode,\n | 'independentStrokeWeights'\n | 'borderTopWeight'\n | 'borderRightWeight'\n | 'borderBottomWeight'\n | 'borderLeftWeight'\n>\n\n/** The layers the canvas strokes side by side when their sides have weights of their own. */\nconst SIDE_STROKE_TYPES: ReadonlySet<string> = new Set<SceneNode['type']>([\n 'FRAME',\n 'RECTANGLE',\n 'ROUNDED_RECTANGLE',\n 'COMPONENT',\n 'INSTANCE',\n 'SECTION',\n 'GROUP'\n])\n\n/**\n * Whether `node` strokes each side by its own weight. A line or vector keeps one weight whatever\n * the flag says, since its outline has no sides.\n */\nexport function drawsStrokeSides(node: Partial<SideStrokeNode> & { type?: string }): boolean {\n return node.independentStrokeWeights === true && (!node.type || SIDE_STROKE_TYPES.has(node.type))\n}\n\n/** The share of a stroke's weight that lies outside the shape it outlines. */\nexport function strokeAlignShare(align: Stroke['align']): number {\n if (align === 'OUTSIDE') return 1\n if (align === 'CENTER') return 0.5\n return 0\n}\n\n/** A layer's own side weights: top, right, bottom, left. */\nexport function borderWeights(node: SideStrokeNode): SideWeights {\n return [\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n ]\n}\n\n/** The weight of each side of `node` under `stroke`, its own when its sides have their own. */\nexport function strokeSideWeights(\n node: SideStrokeNode & { type?: string },\n stroke: Pick<Stroke, 'weight'>\n): SideWeights {\n if (!drawsStrokeSides(node)) return [stroke.weight, stroke.weight, stroke.weight, stroke.weight]\n return borderWeights(node)\n}\n\n/** A stroke's weight, or with sides of their own the widest side, for what is not drawn per side. */\nexport function strokeWeightOf(\n node: Partial<SideStrokeNode> & { type?: string },\n stroke: Pick<Stroke, 'weight'>\n): number {\n if (!drawsStrokeSides(node)) return stroke.weight\n return Math.max(\n node.borderTopWeight ?? 0,\n node.borderRightWeight ?? 0,\n node.borderBottomWeight ?? 0,\n node.borderLeftWeight ?? 0\n )\n}\n\n/**\n * How far a layer's visible strokes reach past each side of its box: top, right, bottom, left.\n * With sides of their own each side reaches by its own weight (Figma desktop, live: a 1px outside\n * stroke with a 20px right side bounds a 100 × 100 rectangle at 121 × 102).\n */\nexport function strokeSideReach(\n node: SideStrokeNode & Pick<SceneNode, 'strokes'> & { type?: string }\n): SideWeights {\n let reach: SideWeights = [0, 0, 0, 0]\n for (const stroke of node.strokes) {\n if (!stroke.visible) continue\n const share = strokeAlignShare(stroke.align)\n const sides = strokeSideWeights(node, stroke)\n reach = [\n Math.max(reach[0], sides[0] * share),\n Math.max(reach[1], sides[1] * share),\n Math.max(reach[2], sides[2] * share),\n Math.max(reach[3], sides[3] * share)\n ]\n }\n return reach\n}\n\n/**\n * What shapes how far a layer's stroke reaches past its box: its type, since a line is stroked to\n * one side, and its join and miter limit, for the tips mitered path corners reach.\n */\nexport interface StrokeShape extends Partial<SideStrokeNode> {\n type?: string\n strokeJoin?: StrokeJoin\n strokeMiterLimit?: number\n}\n\n/** How far past a path a stroke of `weight` reaches, before mitered corners: a line's stroke lies wholly to one side. */\nfunction strokeExtent(\n weight: number,\n align: Stroke['align'],\n line: boolean,\n open: boolean\n): number {\n if (line || align === 'OUTSIDE') return weight\n if (align === 'CENTER' || open) return weight / 2\n return 0\n}\n\nexport function strokeOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null,\n shape?: StrokeShape\n): number {\n const line = shape?.type === 'LINE'\n // Open segments enclose nothing to take a side of, so their strokes draw centred; a network\n // with closed regions still strokes those on their side.\n const enclosed = new Set(network?.regions.flatMap((region) => region.loops.flat()))\n const open = network?.segments.some((_, index) => !enclosed.has(index)) ?? false\n const sided = !network || network.regions.length > 0\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n const weight = strokeWeightOf(shape ?? {}, stroke)\n const extra = strokeExtent(weight, sided ? stroke.align : 'CENTER', line, open)\n const miter = network\n ? miterRatio(network, stroke.join ?? shape?.strokeJoin, shape?.strokeMiterLimit)\n : 1\n overflow = Math.max(overflow, extra * miter)\n }\n // A line's heads sit on its stroke's middle, half a weight off the line.\n const heads = arrowCapOverflow(strokes, fallbackCap, network)\n return Math.max(overflow, heads > 0 && line ? heads + overflow / 2 : heads)\n}\n\n/** The direction a segment leaves `vertex` in, along its handle when it has one. */\nfunction leaving(network: VectorNetwork, index: number, vertex: number): Vector {\n const segment = network.segments[index]\n const atStart = segment.start === vertex\n const handle = atStart ? segment.tangentStart : segment.tangentEnd\n if (handle.x !== 0 || handle.y !== 0) return handle\n const from = network.vertices[vertex]\n const to = network.vertices[atStart ? segment.end : segment.start]\n return { x: to.x - from.x, y: to.y - from.y }\n}\n\n/**\n * How far past half the stroke the sharpest mitered corner reaches, as a multiple: a corner of\n * angle θ mitres out to 1/sin(θ/2), unless that passes the miter limit and it bevels instead.\n * Corners are the vertices exactly two segments meet at, as the stroke joins them.\n */\nfunction miterRatio(network: VectorNetwork, join: StrokeJoin | undefined, limit = 4): number {\n const meeting = new Map<number, number[]>()\n for (const [index, segment] of network.segments.entries()) {\n for (const vertex of new Set([segment.start, segment.end])) {\n meeting.set(vertex, [...(meeting.get(vertex) ?? []), index])\n }\n }\n let ratio = 1\n for (const [vertex, indices] of meeting) {\n if (indices.length !== 2) continue\n if ((network.vertices[vertex].strokeJoin ?? join ?? 'MITER') !== 'MITER') continue\n const a = leaving(network, indices[0], vertex)\n const b = leaving(network, indices[1], vertex)\n const lengths = Math.hypot(a.x, a.y) * Math.hypot(b.x, b.y)\n if (lengths === 0) continue\n const angle = Math.acos(Math.max(-1, Math.min(1, (a.x * b.x + a.y * b.y) / lengths)))\n const miter = 1 / Math.sin(angle / 2)\n if (miter <= limit) ratio = Math.max(ratio, miter)\n }\n return ratio\n}\n\n/**\n * The blur radius Figma draws: a negative one, which only a bound variable can give, draws as no\n * blur, though the layer keeps the value.\n */\nexport function drawnBlurRadius(radius: number): number {\n return Math.max(0, radius)\n}\n\n/**\n * The widest radius an effect blurs by: its radius, or the larger end of a progressive blur,\n * which can start wider than it ends. Bounds and padding that must hold the whole blur use it.\n */\nexport function widestBlurRadius(effect: Pick<Effect, 'radius' | 'progressive'>): number {\n return Math.max(effect.radius, effect.progressive?.startRadius ?? effect.radius)\n}\n\nconst BLUR_SIGMA_PER_RADIUS = 0.43\n\n/**\n * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,\n * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's\n * SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).\n */\nexport function blurSigma(radius: number): number {\n return drawnBlurRadius(radius) * BLUR_SIGMA_PER_RADIUS\n}\n\n/** Skia's Gaussian kernels end at 3 sigma. */\nconst KERNEL_SIGMAS = 3\n\n/**\n * How far past what it blurs a Gaussian of `sigma` leaves ink on screen: where Skia's kernel\n * ends, and one more pixel holds its rounding.\n */\nexport function kernelReach(sigma: number): number {\n return sigma > 0 ? Math.ceil(KERNEL_SIGMAS * sigma) + 1 : 0\n}\n\n/** How far past what it blurs a Figma blur of `radius` leaves ink on screen (`kernelReach`). */\nexport function blurReach(radius: number): number {\n return kernelReach(blurSigma(radius))\n}\n\n/**\n * The distance, in sigmas, past a straight edge blurred by a Gaussian at which the edge's share\n * drops to `share`: the inverse of the normal tail Q, by Abramowitz and Stegun 26.2.23, which is\n * within 0.00045 of it.\n */\nfunction gaussianTailDistance(share: number): number {\n if (share <= 0) {\n return Number.POSITIVE_INFINITY\n }\n if (share >= 0.5) {\n return 0\n }\n const s = Math.sqrt(-2 * Math.log(share))\n return (\n s -\n (2.515517 + 0.802853 * s + 0.010328 * s * s) /\n (1 + 1.432788 * s + 0.189269 * s * s + 0.001308 * s * s * s)\n )\n}\n\nconst COLOR_LEVELS = 255\n\n/**\n * How far past its shape a drop shadow of `radius` and colour alpha `alpha` leaves ink on\n * screen. Skia blurs the shape into an 8-bit mask and scales it by `alpha`, so a mask level shows\n * once `alpha` times it rounds to a level: an opaque or half-opaque shadow shows its faintest\n * level, out to where the kernel ends, and a fainter one ends sooner. Measured on CPU raster, the\n * ink ends at 3.0 sigma for alpha 1 and 0.5, 2.4 for 0.25, and 2.1 for 0.1.\n */\nexport function shadowReach(radius: number, alpha: number): number {\n const sigma = blurSigma(radius)\n const faintestShownLevel = Math.ceil(0.5 / Math.max(alpha, 1 / COLOR_LEVELS))\n const sigmas = Math.min(\n KERNEL_SIGMAS,\n gaussianTailDistance((faintestShownLevel - 1) / COLOR_LEVELS)\n )\n return Math.ceil(sigmas * sigma) + 1\n}\n\n/** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */\nexport function blurRadiusForSigma(sigma: number): number {\n return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS\n}\n\n/**\n * How far a layer's shadows and blurs reach past each side as Figma's render bounds count them:\n * a blur by its radius, a shadow by its radius and spread, moved by its offset. Ink on screen\n * reaches further, to `blurReach`.\n */\nexport function effectOverflow(effects?: Effect[]) {\n let left = 0\n let right = 0\n let top = 0\n let bottom = 0\n\n for (const effect of effects ?? []) {\n if (!effect.visible) continue\n if (\n effect.type !== 'DROP_SHADOW' &&\n effect.type !== 'LAYER_BLUR' &&\n effect.type !== 'FOREGROUND_BLUR'\n ) {\n continue\n }\n const blurSpread = drawnBlurRadius(widestBlurRadius(effect)) + effect.spread\n left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x))\n right = Math.max(right, blurSpread + Math.max(0, effect.offset.x))\n top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y))\n bottom = Math.max(bottom, blurSpread + Math.max(0, effect.offset.y))\n }\n\n return { left, right, top, bottom }\n}\n\nexport function computeAbsoluteBounds(\n nodes: Iterable<{ id: string; width: number; height: number }>,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) {\n const abs = getAbsolutePosition(n.id)\n includeRect(bounds, { x: abs.x, y: abs.y, width: n.width, height: n.height })\n }\n return boundsToRect(bounds)\n}\n\nexport function unionVisualBounds(\n a: VisualBounds | null,\n b: VisualBounds | null\n): VisualBounds | null {\n if (!a) return b\n if (!b) return a\n return {\n minX: Math.min(a.minX, b.minX),\n minY: Math.min(a.minY, b.minY),\n maxX: Math.max(a.maxX, b.maxX),\n maxY: Math.max(a.maxY, b.maxY)\n }\n}\n\nexport function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null {\n const minX = Math.max(a.minX, b.minX)\n const minY = Math.max(a.minY, b.minY)\n const maxX = Math.min(a.maxX, b.maxX)\n const maxY = Math.min(a.maxY, b.maxY)\n return minX < maxX && minY < maxY ? { minX, minY, maxX, maxY } : null\n}\n\n/** The path commands of a Figma geometry blob, by their byte code. */\nexport const GeometryCommand = { CLOSE: 0, MOVE: 1, LINE: 2, QUAD: 3, CUBIC: 4 } as const\nexport type GeometryCommand = (typeof GeometryCommand)[keyof typeof GeometryCommand]\n\n/**\n * Coordinate pairs per command: glyph-derived blobs are quad-heavy, so every code needs its\n * count. Unknown codes are null, so readers stop instead of desyncing into coordinate bytes.\n */\nfunction commandCoordCount(command: number): number | null {\n if (command === GeometryCommand.CLOSE) return 0\n if (command === GeometryCommand.MOVE || command === GeometryCommand.LINE) return 1\n if (command === GeometryCommand.QUAD) return 2\n if (command === GeometryCommand.CUBIC) return 3\n return null\n}\n\n/**\n * Walks a Figma geometry blob: `visit` gets each command, its coordinates as x, y pairs in one\n * array reused between calls, and the byte offset of the first coordinate. It stops at an\n * unknown command or one cut short.\n */\nexport function readGeometryBlob(\n blob: Uint8Array,\n visit: (command: GeometryCommand, coords: readonly number[], offset: number) => void\n): void {\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n const coords: number[] = []\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset]\n const count = commandCoordCount(command)\n if (count === null || offset + 1 + count * 8 > blob.length) return\n offset += 1\n coords.length = 0\n for (let i = 0; i < count; i++) {\n coords.push(view.getFloat32(offset + i * 8, true), view.getFloat32(offset + i * 8 + 4, true))\n }\n visit(command as GeometryCommand, coords, offset)\n offset += count * 8\n }\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n for (const path of paths) {\n readGeometryBlob(path.commandsBlob, (_, coords) => {\n for (let i = 0; i < coords.length; i += 2) includePoint(bounds, coords[i], coords[i + 1])\n })\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(\n node: Pick<\n SceneNode,\n 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'\n >\n): number {\n if (node.type !== 'TEXT' || node.textDecoration === 'NONE') {\n return 0\n }\n const { fontSize } = node\n const underlineOffset = node.textUnderlineOffset ?? fontSize * 0.18\n const thickness = node.textDecorationThickness ?? Math.max(1, fontSize / 16)\n return underlineOffset + thickness + fontSize * 0.35\n}\n"],"mappings":";;;AAcA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,KAAK,KAAM;AAC/B;AAEA,SAAgB,SAAS,SAAyB;CAChD,OAAQ,UAAU,MAAO,KAAK;AAChC;AAEA,MAAM,YAAY,IAAI,KAAK;;AAG3B,MAAM,iCAAiD,IAAI,IAAuB;CAChF;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB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CAC1B,IAAI,SAAS;CACb,OAAO,SAAS,KAAK,QAAQ;EAC3B,MAAM,UAAU,KAAK;EACrB,MAAM,QAAQ,kBAAkB,OAAO;EACvC,IAAI,UAAU,QAAQ,SAAS,IAAI,QAAQ,IAAI,KAAK,QAAQ;EAC5D,UAAU;EACV,OAAO,SAAS;EAChB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,OAAO,KAAK,KAAK,WAAW,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,WAAW,SAAS,IAAI,IAAI,GAAG,IAAI,CAAC;EAE9F,MAAM,SAA4B,QAAQ,MAAM;EAChD,UAAU,QAAQ;CACpB;AACF;AAEA,SAAgB,mBAAmB,OAAyD;CAC1F,MAAM,SAAS,wBAAwB;CACvC,KAAK,MAAM,QAAQ,OACjB,iBAAiB,KAAK,eAAe,GAAG,WAAW;EACjD,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG,aAAa,QAAQ,OAAO,IAAI,OAAO,IAAI,EAAE;CAC1F,CAAC;CAGH,OAAO,OAAO,SAAS,WAAW,OAAO,aAAa,MAAM;AAC9D;;AAGA,SAAgB,uBACd,MAIQ;CACR,IAAI,KAAK,SAAS,UAAU,KAAK,mBAAmB,QAClD,OAAO;CAET,MAAM,EAAE,aAAa;CAGrB,QAFwB,KAAK,uBAAuB,WAAW,QAC7C,KAAK,2BAA2B,KAAK,IAAI,GAAG,WAAW,EAAE,KACtC,WAAW;AAClD"}
|
package/dist/gradient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Vector } from "./primitives/index.js";
|
|
1
|
+
import { Color, Rect, Vector } from "./primitives/index.js";
|
|
2
2
|
import { Fill, GradientStop, GradientTransform } from "./types.js";
|
|
3
3
|
//#region src/gradient.d.ts
|
|
4
4
|
/**
|
|
@@ -53,6 +53,13 @@ declare function linearGradientTransform(start: Vector, end: Vector, width?: num
|
|
|
53
53
|
* radii, all in the layer's unit square.
|
|
54
54
|
*/
|
|
55
55
|
declare function ellipticalGradientTransform(center: Vector, radiusX: Vector, radiusY: Vector): GradientTransform;
|
|
56
|
+
/**
|
|
57
|
+
* The transform that keeps a gradient where it was on the canvas when its layer's box becomes
|
|
58
|
+
* `box`, given in the old box's units, as Figma rewrites it when editing a path resizes the layer
|
|
59
|
+
* (Figma desktop 126: a 200 × 120 box grown to 380 × 160 and moved up 40 gives
|
|
60
|
+
* `[[1.9, 0, 0], [0, 1.333, -0.333]]` from the identity).
|
|
61
|
+
*/
|
|
62
|
+
declare function gradientTransformInBox(t: GradientTransform, box: Rect): GradientTransform;
|
|
56
63
|
//#endregion
|
|
57
|
-
export { DEFAULT_GRADIENT_TRANSFORM, GradientFillType, GradientTransformRows, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, gradientTransformRows, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
|
|
64
|
+
export { DEFAULT_GRADIENT_TRANSFORM, GradientFillType, GradientTransformRows, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, gradientTransformInBox, gradientTransformRows, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
|
|
58
65
|
//# sourceMappingURL=gradient.d.ts.map
|
package/dist/gradient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gradient.d.ts","names":[],"sources":["../src/gradient.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"gradient.d.ts","names":[],"sources":["../src/gradient.ts"],"mappings":";;;;;;;;;;KAYY,mBAAmB,QAC7B;iBAIc,eAAe,MAAM,eAAe,QAAQ;;cAU/C,6BAA6B;;;;;cAa7B,4BAA4B;;;;;KAa7B;;iBAGI,sBAAsB,GAAG,oBAAoB;;iBAW7C,qBAAqB,OAAO,QAAQ;iBAepC,4BAA4B,GAAG;;;;;iBAU/B,wBAAwB,GAAG,oBAAoB;;iBAkB/C,uBAAuB,GAAG,mBAAmB,OAAO,SAAS;;iBAQ7D,cAAc,GAAG,mBAAmB,OAAO,SAAS;;;;;iBAQpD,gCACd,OAAO,QACP,KAAK,QACL,QAAQ,SACP;;;;;;;iBAiBa,wBACd,OAAO,QACP,KAAK,QACL,gBACA,iBACA,iBACC;;;;;iBAYa,4BACd,QAAQ,QACR,SAAS,QACT,SAAS,SACR;;;;;;;iBAmBa,uBAAuB,GAAG,mBAAmB,KAAK,OAAO"}
|
package/dist/gradient.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Matrix from "./matrix.js";
|
|
1
2
|
//#region src/gradient.ts
|
|
2
3
|
function isGradientFill(type) {
|
|
3
4
|
return type === "GRADIENT_LINEAR" || type === "GRADIENT_RADIAL" || type === "GRADIENT_ANGULAR" || type === "GRADIENT_DIAMOND";
|
|
@@ -138,7 +139,34 @@ function ellipticalGradientTransform(center, radiusX, radiusY) {
|
|
|
138
139
|
m12: center.y - (xAxis.y + yAxis.y) / 2
|
|
139
140
|
});
|
|
140
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* The transform that keeps a gradient where it was on the canvas when its layer's box becomes
|
|
144
|
+
* `box`, given in the old box's units, as Figma rewrites it when editing a path resizes the layer
|
|
145
|
+
* (Figma desktop 126: a 200 × 120 box grown to 380 × 160 and moved up 40 gives
|
|
146
|
+
* `[[1.9, 0, 0], [0, 1.333, -0.333]]` from the identity).
|
|
147
|
+
*/
|
|
148
|
+
function gradientTransformInBox(t, box) {
|
|
149
|
+
const [m00, m01, m02, m10, m11, m12] = Matrix.multiply(Matrix.fromAffine(t), [
|
|
150
|
+
box.width,
|
|
151
|
+
0,
|
|
152
|
+
box.x,
|
|
153
|
+
0,
|
|
154
|
+
box.height,
|
|
155
|
+
box.y,
|
|
156
|
+
0,
|
|
157
|
+
0,
|
|
158
|
+
1
|
|
159
|
+
]);
|
|
160
|
+
return {
|
|
161
|
+
m00,
|
|
162
|
+
m01,
|
|
163
|
+
m02,
|
|
164
|
+
m10,
|
|
165
|
+
m11,
|
|
166
|
+
m12
|
|
167
|
+
};
|
|
168
|
+
}
|
|
141
169
|
//#endregion
|
|
142
|
-
export { DEFAULT_GRADIENT_TRANSFORM, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, gradientTransformRows, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
|
|
170
|
+
export { DEFAULT_GRADIENT_TRANSFORM, IDENTITY_GRADIENT_TRANSFORM, applyGradientTransform, defaultGradientStops, ellipticalGradientTransform, gradientPoint, gradientTransformInBox, gradientTransformRows, invertGradientTransform, isGradientFill, isIdentityGradientTransform, linearGradientTransform, linearGradientTransformFromAxes };
|
|
143
171
|
|
|
144
172
|
//# sourceMappingURL=gradient.js.map
|