@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.
Files changed (181) hide show
  1. package/dist/components/index.d.ts +2 -2
  2. package/dist/components/index.js +2 -2
  3. package/dist/components/properties.d.ts +6 -1
  4. package/dist/components/properties.d.ts.map +1 -1
  5. package/dist/components/properties.js +14 -3
  6. package/dist/components/properties.js.map +1 -1
  7. package/dist/copy.d.ts.map +1 -1
  8. package/dist/copy.js +1 -0
  9. package/dist/copy.js.map +1 -1
  10. package/dist/css/gradient.d.ts +23 -0
  11. package/dist/css/gradient.d.ts.map +1 -0
  12. package/dist/css/gradient.js +404 -0
  13. package/dist/css/gradient.js.map +1 -0
  14. package/dist/css/index.d.ts +2 -1
  15. package/dist/css/index.js +2 -1
  16. package/dist/css/shadows.d.ts.map +1 -1
  17. package/dist/css/shadows.js +2 -13
  18. package/dist/css/shadows.js.map +1 -1
  19. package/dist/css/values.js +24 -1
  20. package/dist/css/values.js.map +1 -1
  21. package/dist/font-style.d.ts +2 -1
  22. package/dist/font-style.d.ts.map +1 -1
  23. package/dist/font-style.js +31 -6
  24. package/dist/font-style.js.map +1 -1
  25. package/dist/geometry.d.ts +10 -1
  26. package/dist/geometry.d.ts.map +1 -1
  27. package/dist/geometry.js +21 -6
  28. package/dist/geometry.js.map +1 -1
  29. package/dist/graph.d.ts +49 -3
  30. package/dist/graph.d.ts.map +1 -1
  31. package/dist/graph.js +179 -17
  32. package/dist/graph.js.map +1 -1
  33. package/dist/hit-test.d.ts +3 -1
  34. package/dist/hit-test.d.ts.map +1 -1
  35. package/dist/hit-test.js +38 -23
  36. package/dist/hit-test.js.map +1 -1
  37. package/dist/icons/index.d.ts +2 -2
  38. package/dist/icons/index.js +2 -2
  39. package/dist/icons/model.d.ts +8 -2
  40. package/dist/icons/model.d.ts.map +1 -1
  41. package/dist/icons/model.js +10 -1
  42. package/dist/icons/model.js.map +1 -1
  43. package/dist/index.d.ts +2 -2
  44. package/dist/instances/assignments.js +40 -6
  45. package/dist/instances/assignments.js.map +1 -1
  46. package/dist/instances/fields.d.ts +2 -2
  47. package/dist/instances/fields.d.ts.map +1 -1
  48. package/dist/instances/fields.js +18 -1
  49. package/dist/instances/fields.js.map +1 -1
  50. package/dist/instances/index.d.ts +38 -2
  51. package/dist/instances/index.d.ts.map +1 -1
  52. package/dist/instances/index.js +134 -15
  53. package/dist/instances/index.js.map +1 -1
  54. package/dist/instances/overrides.d.ts +10 -1
  55. package/dist/instances/overrides.d.ts.map +1 -1
  56. package/dist/instances/overrides.js +28 -2
  57. package/dist/instances/overrides.js.map +1 -1
  58. package/dist/instances/placement.js +1 -1
  59. package/dist/instances/placement.js.map +1 -1
  60. package/dist/instances/swap-overrides.js +94 -0
  61. package/dist/instances/swap-overrides.js.map +1 -0
  62. package/dist/instances/sync.js +90 -12
  63. package/dist/instances/sync.js.map +1 -1
  64. package/dist/layout/draw-order.d.ts +11 -0
  65. package/dist/layout/draw-order.d.ts.map +1 -0
  66. package/dist/layout/draw-order.js +14 -0
  67. package/dist/layout/draw-order.js.map +1 -0
  68. package/dist/layout/index.d.ts +2 -1
  69. package/dist/layout/index.js +2 -1
  70. package/dist/node-defaults.d.ts +11 -1
  71. package/dist/node-defaults.d.ts.map +1 -1
  72. package/dist/node-defaults.js +16 -1
  73. package/dist/node-defaults.js.map +1 -1
  74. package/dist/order-keys.d.ts +3 -1
  75. package/dist/order-keys.d.ts.map +1 -1
  76. package/dist/order-keys.js +6 -1
  77. package/dist/order-keys.js.map +1 -1
  78. package/dist/resize.d.ts +29 -9
  79. package/dist/resize.d.ts.map +1 -1
  80. package/dist/resize.js +95 -62
  81. package/dist/resize.js.map +1 -1
  82. package/dist/shared-styles.d.ts.map +1 -1
  83. package/dist/shared-styles.js +1 -8
  84. package/dist/shared-styles.js.map +1 -1
  85. package/dist/slots/authoring.d.ts +3 -2
  86. package/dist/slots/authoring.d.ts.map +1 -1
  87. package/dist/slots/authoring.js +5 -3
  88. package/dist/slots/authoring.js.map +1 -1
  89. package/dist/slots/content.d.ts.map +1 -1
  90. package/dist/slots/content.js +4 -1
  91. package/dist/slots/content.js.map +1 -1
  92. package/dist/source-metadata.d.ts +4 -2
  93. package/dist/source-metadata.d.ts.map +1 -1
  94. package/dist/source-metadata.js +10 -3
  95. package/dist/source-metadata.js.map +1 -1
  96. package/dist/strokes.d.ts +39 -0
  97. package/dist/strokes.d.ts.map +1 -0
  98. package/dist/strokes.js +104 -0
  99. package/dist/strokes.js.map +1 -0
  100. package/dist/text/direction.d.ts +6 -2
  101. package/dist/text/direction.d.ts.map +1 -1
  102. package/dist/text/direction.js +2 -1
  103. package/dist/text/direction.js.map +1 -1
  104. package/dist/text/index.d.ts +3 -3
  105. package/dist/text/index.js +3 -3
  106. package/dist/text/lengths.d.ts +6 -1
  107. package/dist/text/lengths.d.ts.map +1 -1
  108. package/dist/text/lengths.js +10 -1
  109. package/dist/text/lengths.js.map +1 -1
  110. package/dist/text/overflow.d.ts +22 -6
  111. package/dist/text/overflow.d.ts.map +1 -1
  112. package/dist/text/overflow.js +24 -6
  113. package/dist/text/overflow.js.map +1 -1
  114. package/dist/transfer/nodes.js +9 -5
  115. package/dist/transfer/nodes.js.map +1 -1
  116. package/dist/types.d.ts +18 -2
  117. package/dist/types.d.ts.map +1 -1
  118. package/dist/types.js.map +1 -1
  119. package/dist/undo.d.ts +36 -1
  120. package/dist/undo.d.ts.map +1 -1
  121. package/dist/undo.js +52 -2
  122. package/dist/undo.js.map +1 -1
  123. package/dist/variables/bindings.d.ts +14 -6
  124. package/dist/variables/bindings.d.ts.map +1 -1
  125. package/dist/variables/bindings.js +42 -67
  126. package/dist/variables/bindings.js.map +1 -1
  127. package/dist/variables/formula/signatures.js +1 -1
  128. package/dist/variables/index.d.ts +10 -4
  129. package/dist/variables/index.d.ts.map +1 -1
  130. package/dist/variables/index.js +58 -15
  131. package/dist/variables/index.js.map +1 -1
  132. package/dist/variables/paints.d.ts +101 -0
  133. package/dist/variables/paints.d.ts.map +1 -0
  134. package/dist/variables/paints.js +313 -0
  135. package/dist/variables/paints.js.map +1 -0
  136. package/dist/variables/resolution.d.ts +14 -1
  137. package/dist/variables/resolution.d.ts.map +1 -1
  138. package/dist/variables/resolution.js +44 -4
  139. package/dist/variables/resolution.js.map +1 -1
  140. package/dist/variables/subtree.js +17 -0
  141. package/dist/variables/subtree.js.map +1 -0
  142. package/package.json +6 -1
  143. package/src/components/properties.ts +17 -2
  144. package/src/copy.ts +1 -0
  145. package/src/css/gradient.ts +438 -0
  146. package/src/css/index.ts +1 -0
  147. package/src/css/shadows.ts +2 -18
  148. package/src/css/values.ts +27 -1
  149. package/src/font-style.ts +38 -4
  150. package/src/geometry.ts +25 -6
  151. package/src/graph.ts +207 -17
  152. package/src/hit-test.ts +67 -24
  153. package/src/icons/model.ts +11 -1
  154. package/src/instances/assignments.ts +65 -7
  155. package/src/instances/fields.ts +21 -0
  156. package/src/instances/index.ts +237 -14
  157. package/src/instances/overrides.ts +36 -1
  158. package/src/instances/placement.ts +5 -1
  159. package/src/instances/swap-overrides.ts +123 -0
  160. package/src/instances/sync.ts +139 -12
  161. package/src/layout/draw-order.ts +13 -0
  162. package/src/layout/index.ts +1 -0
  163. package/src/node-defaults.ts +21 -0
  164. package/src/order-keys.ts +6 -0
  165. package/src/resize.ts +133 -69
  166. package/src/shared-styles.ts +1 -3
  167. package/src/slots/authoring.ts +5 -3
  168. package/src/slots/content.ts +4 -1
  169. package/src/source-metadata.ts +18 -3
  170. package/src/strokes.ts +121 -0
  171. package/src/text/direction.ts +7 -5
  172. package/src/text/lengths.ts +10 -0
  173. package/src/text/overflow.ts +30 -7
  174. package/src/transfer/nodes.ts +7 -5
  175. package/src/types.ts +17 -0
  176. package/src/undo.ts +79 -2
  177. package/src/variables/bindings.ts +52 -74
  178. package/src/variables/index.ts +80 -14
  179. package/src/variables/paints.ts +413 -0
  180. package/src/variables/resolution.ts +56 -5
  181. package/src/variables/subtree.ts +15 -0
@@ -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\nexport function parseFontStyle(style: string | undefined): ParsedFontStyle {\n const raw = style ?? ''\n const italic = /(?:italic|oblique)/iu.test(raw)\n const normalized = normalizeFontStyleName(raw)\n const numericWeight = normalized.match(/(?:^|[^0-9])([1-9]00)(?:[^0-9]|$)/u)?.[1]\n return {\n weight: numericWeight ? Number(numericWeight) : (FONT_WEIGHT_BY_STYLE.get(normalized) ?? 400),\n italic\n }\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)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,OAAO,eAAe,KAAK,CAAC,CAAC;AAC/B;AAEA,SAAgB,oBAAoB,QAAwB;CAC1D,OAAO,OAAO,QAAQ,mCAAmC,EAAE;AAC7D;AAEA,SAAgB,YAAY,QAAgB,SAAS,OAAe;CAClE,MAAM,UAAU,KAAK,MAAM,SAAS,GAAG,IAAI;CAC3C,MAAM,QAAQ,kBAAkB,YAAY;CAC5C,OAAO,SAAS,GAAG,MAAM,WAAW;AACtC;;;;;AAMA,SAAgB,kBAAkB,QAAgB,SAAS,OAAe;CACxE,MAAM,QAAQ,kBAAkB,KAAK,MAAM,SAAS,GAAG,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"}
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,OAAO,aAAa,MAAM,KAAK,SAAS,CAAC,MAAM,MAAM,CAAU,CAAC,CACjG;AAEA,SAAS,uBAAuB,OAAuB;CACrD,OAAO,MACJ,YAAY,CAAC,CACb,QAAQ,mBAAmB,EAAE,CAAC,CAC9B,QAAQ,gBAAgB,EAAE;AAC/B;AAwBA,MAAM,kBAAkB,IAAI,OAC1B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,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"}
@@ -38,6 +38,14 @@ interface StrokeShape {
38
38
  strokeMiterLimit?: number;
39
39
  }
40
40
  declare function strokeOverflow(strokes?: Stroke[], fallbackCap?: StrokeCap, network?: VectorNetwork | null, shape?: StrokeShape): number;
41
+ /**
42
+ * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
43
+ * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's
44
+ * SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).
45
+ */
46
+ declare function blurSigma(radius: number): number;
47
+ /** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
48
+ declare function blurRadiusForSigma(sigma: number): number;
41
49
  declare function effectOverflow(effects?: Effect[]): {
42
50
  left: number;
43
51
  right: number;
@@ -84,6 +92,7 @@ interface VisualBoundsNode {
84
92
  textUnderlineOffset?: number | null;
85
93
  textDecorationThickness?: number | null;
86
94
  derivedTextHeight?: number | null;
95
+ textAlignVertical?: string;
87
96
  }
88
97
  declare function unionVisualBounds(a: VisualBounds | null, b: VisualBounds | null): VisualBounds | null;
89
98
  declare function intersectVisualBounds(a: VisualBounds, b: VisualBounds): VisualBounds | null;
@@ -108,5 +117,5 @@ declare function nodeVisualBounds(node: VisualBoundsNode, getAbsolutePosition: (
108
117
  declare function textDecorationOverflow(node: VisualBoundsNode): number;
109
118
  declare function computeDescendantVisualBounds(nodeIds: string[], getNode: (id: string) => VisualBoundsNode | undefined, getAbsolutePosition: (id: string) => Vector): VisualBounds | null;
110
119
  //#endregion
111
- export { StrokeShape, VisualBounds, VisualBoundsNode, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
120
+ export { StrokeShape, VisualBounds, VisualBoundsNode, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
112
121
  //# sourceMappingURL=geometry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAOgB,SAAS;iBAIT,SAAS;iBAIT,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;;iBAgCc,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;;;;UA0Ba;EACf;EACA,aAAa;EACb;;iBAGc,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;iBA+DM,eAAe,UAAU;;;;;;;iBA0BzB,sBACd,OAAO,SAAS,YAChB,OAAO,KAAK,yBACX;iBAMa,oBACd,OAAO;EAEH;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;IACR,cAEN,sBAAsB,eAAe,SACpC;UAec;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,eAAe;IAAQ,cAAc;;EACrC,iBAAiB;IAAQ,cAAc;;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;;;;;iBAazD,0BAA0B;iBAQ1B,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;;;;;iBAsHhE,sBACd,OAAO;EAAQ,cAAc;IAC7B,sBACC;iBAmDa,iBACd,MAAM,kBACN,sBAAsB,eAAe,SACpC;;iBAiCa,uBAAuB,MAAM;iBA8C7B,8BACd,mBACA,UAAU,eAAe,8BACzB,sBAAsB,eAAe,SACpC"}
1
+ {"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAOgB,SAAS;iBAIT,SAAS;iBAIT,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;;iBAgCc,cAAc,OAAO,SAAS,QAAQ;iBAMtC,gBAAgB;EAC9B;EACA;EACA;EACA;EACA;IACE;;;;;UA0Ba;EACf;EACA,aAAa;EACb;;iBAGc,eACd,UAAU,UACV,cAAc,WACd,UAAU,sBACV,QAAQ;;;;;;iBAsEM,UAAU;;iBAKV,mBAAmB;iBAInB,eAAe,UAAU;;;;;;;iBA0BzB,sBACd,OAAO,SAAS,YAChB,OAAO,KAAK,yBACX;iBAMa,oBACd,OAAO;EAEH;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;IACR,cAEN,sBAAsB,eAAe,SACpC;UAec;EACf;EACA;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,UAAU;EACV,eAAe;IAAQ,cAAc;;EACrC,iBAAiB;IAAQ,cAAc;;EACvC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGc,kBACd,GAAG,qBACH,GAAG,sBACF;iBAWa,sBAAsB,GAAG,cAAc,GAAG,eAAe;;;;;;iBAazD,0BAA0B;iBAQ1B,mBAAmB,OAAO;EAAQ,cAAc;KAAgB;;;;;iBAsHhE,sBACd,OAAO;EAAQ,cAAc;IAC7B,sBACC;iBAmDa,iBACd,MAAM,kBACN,sBAAsB,eAAe,SACpC;;iBAmCa,uBAAuB,MAAM;iBA8C7B,8BACd,mBACA,UAAU,eAAe,8BACzB,sBAAsB,eAAe,SACpC"}
package/dist/geometry.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getAxisAlignedWorldBounds } from "./coordinate.js";
2
2
  import { arrowCapOverflow } from "./arrow-caps.js";
3
- import { textLinesOverflow } from "./text/overflow.js";
3
+ import { textLinesReach } from "./text/overflow.js";
4
4
  //#region src/geometry.ts
5
5
  function degToRad(degrees) {
6
6
  return degrees * Math.PI / 180;
@@ -173,6 +173,19 @@ function miterRatio(network, join, limit = 4) {
173
173
  }
174
174
  return ratio;
175
175
  }
176
+ const BLUR_SIGMA_PER_RADIUS = .43;
177
+ /**
178
+ * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
179
+ * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's
180
+ * SVG export writes radius / 2, which is wider (`packages/core/tests/canvas/blur.test.ts`).
181
+ */
182
+ function blurSigma(radius) {
183
+ return Math.max(0, radius) * BLUR_SIGMA_PER_RADIUS;
184
+ }
185
+ /** The Figma blur radius that draws a Gaussian of `sigma`, the inverse of `blurSigma`. */
186
+ function blurRadiusForSigma(sigma) {
187
+ return Math.max(0, sigma) / BLUR_SIGMA_PER_RADIUS;
188
+ }
176
189
  function effectOverflow(effects) {
177
190
  let left = 0;
178
191
  let right = 0;
@@ -428,13 +441,15 @@ function nodeVisualBounds(node, getAbsolutePosition) {
428
441
  const hasNonInsideStroke = node.strokes?.some((stroke) => stroke.visible && stroke.align !== "INSIDE");
429
442
  const localGeometry = geometryBlobBounds([...node.fillGeometry ?? [], ...hasNonInsideStroke ? node.strokeGeometry ?? [] : []]);
430
443
  if (localGeometry) bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds;
431
- const below = Math.max(textLinesOverflow(node), 0) + textDecorationOverflow(node);
432
- if (below > 0) {
444
+ const reach = textLinesReach(node);
445
+ const above = Math.min(reach.minY, 0);
446
+ const below = Math.max(reach.maxY, node.height) + textDecorationOverflow(node);
447
+ if (above < 0 || below > node.height) {
433
448
  const lines = {
434
449
  x: 0,
435
- y: 0,
450
+ y: above,
436
451
  width: node.width,
437
- height: node.height + below
452
+ height: below - above
438
453
  };
439
454
  bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds;
440
455
  }
@@ -473,6 +488,6 @@ function computeDescendantVisualBounds(nodeIds, getNode, getAbsolutePosition) {
473
488
  return bounds;
474
489
  }
475
490
  //#endregion
476
- export { computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
491
+ export { blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, computeDescendantVisualBounds, computeVisualBounds, degToRad, effectOverflow, geometryBlobBounds, geometryBlobPolylines, geometryCommandCoordCount, intersectVisualBounds, nodeVisualBounds, polygonVertices, radToDeg, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
477
492
 
478
493
  //# sourceMappingURL=geometry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport { getAxisAlignedWorldBounds } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport type { Rect, Vector } from './primitives'\nimport { textLinesOverflow } from './text/overflow'\nimport type { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\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\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\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\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 = effect.radius + 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\n/** Axis-aligned canvas box around the layers, through each one's rotation, flips, and ancestors. */\nexport function computeAbsoluteBounds(\n nodes: Iterable<SceneNode>,\n graph: Pick<SceneGraph, 'getNode'>\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) includeRect(bounds, getAxisAlignedWorldBounds(n, graph))\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeShape\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = unturnedTopLeft(n, getAbsolutePosition(n.id))\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n derivedTextHeight?: number | null\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/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How many straight steps a curve is sampled in when its outline is needed as points. */\nconst OUTLINE_CURVE_STEPS = 8\n\n/**\n * Points along a quad (`command` 3) or cubic (4) from `start`, sampled so the curve's outline can\n * be tested without a path engine. The last coordinate pair is the curve's end.\n */\nfunction curvePoints(\n command: number,\n start: Vector,\n points: readonly Vector[],\n steps: number\n): Vector[] {\n const end = points[points.length - 1]\n const sampled: Vector[] = []\n for (let step = 1; step <= steps; step++) {\n const t = step / steps\n const u = 1 - t\n if (command === 3) {\n const control = points[0]\n sampled.push({\n x: u * u * start.x + 2 * u * t * control.x + t * t * end.x,\n y: u * u * start.y + 2 * u * t * control.y + t * t * end.y\n })\n continue\n }\n const [first, second] = points\n sampled.push({\n x:\n u * u * u * start.x +\n 3 * u * u * t * first.x +\n 3 * u * t * t * second.x +\n t * t * t * end.x,\n y:\n u * u * u * start.y + 3 * u * u * t * first.y + 3 * u * t * t * second.y + t * t * t * end.y\n })\n }\n return sampled\n}\n\n/** One blob's subpaths as polylines in the layer's own coordinates. */\nfunction blobPolylines(blob: Uint8Array, curveSteps: number): Vector[][] {\n const polylines: Vector[][] = []\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n let current: Vector[] = []\n let cursor: Vector = { x: 0, y: 0 }\n const readPoint = (): Vector | null => {\n if (offset + 8 > blob.length) return null\n const point = { x: view.getFloat32(offset, true), y: view.getFloat32(offset + 4, true) }\n offset += 8\n return point\n }\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords === null) break\n if (command === 0) {\n if (current.length > 0) polylines.push(current)\n current = []\n continue\n }\n const points: Vector[] = []\n let complete = true\n for (let index = 0; index < Math.max(coords, 1); index++) {\n const point = readPoint()\n if (!point) {\n complete = false\n break\n }\n points.push(point)\n }\n if (!complete) break\n const end = points[points.length - 1]\n if (command === 1) {\n if (current.length > 0) polylines.push(current)\n current = [end]\n } else if (command === 2) {\n if (current.length === 0) current.push(cursor)\n current.push(end)\n } else {\n if (current.length === 0) current.push(cursor)\n current.push(...curvePoints(command, cursor, points, curveSteps))\n }\n cursor = end\n }\n if (current.length > 0) polylines.push(current)\n return polylines\n}\n\n/**\n * The subpaths a layer's geometry blobs draw, as polylines in its own coordinates. Curves are\n * sampled, so a caller can test a point against the outline without a path engine.\n */\nexport function geometryBlobPolylines(\n paths: Array<{ commandsBlob: Uint8Array }>,\n curveSteps = OUTLINE_CURVE_STEPS\n): Vector[][] {\n const polylines: Vector[][] = []\n for (const path of paths) polylines.push(...blobPolylines(path.commandsBlob, curveSteps))\n return polylines\n}\n\ntype TurnedBox = Pick<VisualBoundsNode, 'width' | 'height' | 'rotation' | 'flipX' | 'flipY'>\n\n/**\n * Where a local point lands relative to the box's unturned top-left, turned about the center and\n * then flipped about it, in the order `getNodeLocalMatrix` composes the same two steps.\n */\nfunction transformLocalPoint(node: TurnedBox, point: Vector): Vector {\n let { x, y } = point\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n if (node.flipX) x = node.width - x\n if (node.flipY) y = node.height - y\n return { x, y }\n}\n\n/**\n * The unturned top-left of a box whose origin (its own 0,0, as `SceneGraph.getAbsolutePosition`\n * returns it) sits at `origin` after the rotation.\n */\nfunction unturnedTopLeft(node: TurnedBox, origin: Vector): Vector {\n // `getAbsolutePosition` maps the box's own origin through the world matrix, flips included.\n const offset = transformLocalPoint(node, { x: 0, y: 0 })\n return { x: origin.x - offset.x, y: origin.y - offset.y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n const linesOverflow = Math.max(textLinesOverflow(node), 0)\n // An underline or strikethrough reaches below the last line, turning with the text.\n const below = linesOverflow + textDecorationOverflow(node)\n if (below > 0) {\n const lines = { x: 0, y: 0, width: node.width, height: node.height + below }\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds\n }\n\n return bounds\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(node: VisualBoundsNode): number {\n if (node.type !== 'TEXT' || !node.textDecoration || node.textDecoration === 'NONE') return 0\n const fontSize = node.fontSize ?? 14\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\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n // The frame's own drawn box, so a turned frame clips where it is drawn. For an unturned,\n // unflipped frame this is the same box as its position and size give.\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const nodeClip = transformedLocalBounds(\n node,\n { x: 0, y: 0, width: node.width, height: node.height },\n abs\n )\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n"],"mappings":";;;;AAOA,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,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;EAAI;EAC/D;GAAE,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK;EAAI;EAC7D;GAAE,GAAG,KAAK,KAAK,MAAM,KAAK;GAAK,GAAG,KAAK,KAAK,MAAM,KAAK;EAAI;EAC3D;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,KAAK;GAAK,GAAG,KAAK,CAAC,KAAK,MAAM,KAAK;EAAI;CAC/D;AACF;AAEA,SAAgB,YACd,GACA,GACA,GACA,GACA,aACgG;CAChG,IAAI,gBAAgB,GAClB,OA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,SACA,SACA,qBACqB;CACrB,IAAI,SAA8B;CAClC,KAAK,MAAM,UAAU,SACnB,SAAS,kBACP,QACA,8BAA8B,QAAQ,SAAS,mBAAmB,CACpE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"geometry.js","names":[],"sources":["../src/geometry.ts"],"sourcesContent":["import { arrowCapOverflow } from './arrow-caps'\nimport { getAxisAlignedWorldBounds } from './coordinate'\nimport type { SceneGraph } from './graph'\nimport type { Rect, Vector } from './primitives'\nimport { textLinesReach } from './text/overflow'\nimport type { Effect, SceneNode, Stroke, StrokeCap, StrokeJoin, VectorNetwork } from './types'\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\nfunction boundsToRect(bounds: BoundsAccumulator): Rect {\n return bounds.minX === Infinity\n ? { x: 0, y: 0, width: 0, height: 0 }\n : {\n x: bounds.minX,\n y: bounds.minY,\n width: bounds.maxX - bounds.minX,\n height: bounds.maxY - bounds.minY\n }\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\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 Math.max(0, 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 = effect.radius + 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\n/** Axis-aligned canvas box around the layers, through each one's rotation, flips, and ancestors. */\nexport function computeAbsoluteBounds(\n nodes: Iterable<SceneNode>,\n graph: Pick<SceneGraph, 'getNode'>\n): Rect {\n const bounds = createBoundsAccumulator()\n for (const n of nodes) includeRect(bounds, getAxisAlignedWorldBounds(n, graph))\n return boundsToRect(bounds)\n}\n\nexport function computeVisualBounds(\n nodes: Iterable<\n {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n } & StrokeShape\n >,\n getAbsolutePosition: (id: string) => Vector\n): Rect {\n const bounds = createBoundsAccumulator()\n\n for (const n of nodes) {\n const abs = unturnedTopLeft(n, getAbsolutePosition(n.id))\n const bbox = rotatedBBox(abs.x, abs.y, n.width, n.height, n.rotation ?? 0)\n const stroke = strokeOverflow(n.strokes, n.strokeCap, n.vectorNetwork, n)\n const effects = effectOverflow(n.effects)\n includePoint(bounds, bbox.left - stroke - effects.left, bbox.top - stroke - effects.top)\n includePoint(bounds, bbox.right + stroke + effects.right, bbox.bottom + stroke + effects.bottom)\n }\n\n return boundsToRect(bounds)\n}\n\nexport interface VisualBoundsNode {\n id: string\n width: number\n height: number\n rotation?: number\n flipX?: boolean\n flipY?: boolean\n strokes?: Stroke[]\n strokeCap?: StrokeCap\n vectorNetwork?: VectorNetwork | null\n effects?: Effect[]\n fillGeometry?: Array<{ commandsBlob: Uint8Array }>\n strokeGeometry?: Array<{ commandsBlob: Uint8Array }>\n childIds?: string[]\n visible?: boolean\n type?: string\n clipsContent?: boolean\n fontSize?: number\n textDecoration?: string\n textUnderlineOffset?: number | null\n textDecorationThickness?: number | null\n derivedTextHeight?: number | null\n textAlignVertical?: string\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/**\n * Coordinate pairs per path blob command: 0=close, 1=move, 2=line,\n * 3=quad (glyph-derived blobs are quad-heavy), 4=cubic. Unknown → null so\n * walkers stop instead of desyncing into coordinate bytes.\n */\nexport function geometryCommandCoordCount(command: number): number | null {\n if (command === 0) return 0\n if (command === 1 || command === 2) return 1\n if (command === 3) return 2\n if (command === 4) return 3\n return null\n}\n\nexport function geometryBlobBounds(paths: Array<{ commandsBlob: Uint8Array }>): Rect | null {\n const bounds = createBoundsAccumulator()\n\n for (const path of paths) {\n const blob = path.commandsBlob\n const dv = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords == null) break\n for (let i = 0; i < coords; i++) {\n if (offset + 8 > blob.length) break\n const x = dv.getFloat32(offset, true)\n const y = dv.getFloat32(offset + 4, true)\n includePoint(bounds, x, y)\n offset += 8\n }\n }\n }\n\n return bounds.minX === Infinity ? null : boundsToRect(bounds)\n}\n\n/** How many straight steps a curve is sampled in when its outline is needed as points. */\nconst OUTLINE_CURVE_STEPS = 8\n\n/**\n * Points along a quad (`command` 3) or cubic (4) from `start`, sampled so the curve's outline can\n * be tested without a path engine. The last coordinate pair is the curve's end.\n */\nfunction curvePoints(\n command: number,\n start: Vector,\n points: readonly Vector[],\n steps: number\n): Vector[] {\n const end = points[points.length - 1]\n const sampled: Vector[] = []\n for (let step = 1; step <= steps; step++) {\n const t = step / steps\n const u = 1 - t\n if (command === 3) {\n const control = points[0]\n sampled.push({\n x: u * u * start.x + 2 * u * t * control.x + t * t * end.x,\n y: u * u * start.y + 2 * u * t * control.y + t * t * end.y\n })\n continue\n }\n const [first, second] = points\n sampled.push({\n x:\n u * u * u * start.x +\n 3 * u * u * t * first.x +\n 3 * u * t * t * second.x +\n t * t * t * end.x,\n y:\n u * u * u * start.y + 3 * u * u * t * first.y + 3 * u * t * t * second.y + t * t * t * end.y\n })\n }\n return sampled\n}\n\n/** One blob's subpaths as polylines in the layer's own coordinates. */\nfunction blobPolylines(blob: Uint8Array, curveSteps: number): Vector[][] {\n const polylines: Vector[][] = []\n const view = new DataView(blob.buffer, blob.byteOffset, blob.byteLength)\n let offset = 0\n let current: Vector[] = []\n let cursor: Vector = { x: 0, y: 0 }\n const readPoint = (): Vector | null => {\n if (offset + 8 > blob.length) return null\n const point = { x: view.getFloat32(offset, true), y: view.getFloat32(offset + 4, true) }\n offset += 8\n return point\n }\n while (offset < blob.length) {\n const command = blob[offset++]\n const coords = geometryCommandCoordCount(command)\n if (coords === null) break\n if (command === 0) {\n if (current.length > 0) polylines.push(current)\n current = []\n continue\n }\n const points: Vector[] = []\n let complete = true\n for (let index = 0; index < Math.max(coords, 1); index++) {\n const point = readPoint()\n if (!point) {\n complete = false\n break\n }\n points.push(point)\n }\n if (!complete) break\n const end = points[points.length - 1]\n if (command === 1) {\n if (current.length > 0) polylines.push(current)\n current = [end]\n } else if (command === 2) {\n if (current.length === 0) current.push(cursor)\n current.push(end)\n } else {\n if (current.length === 0) current.push(cursor)\n current.push(...curvePoints(command, cursor, points, curveSteps))\n }\n cursor = end\n }\n if (current.length > 0) polylines.push(current)\n return polylines\n}\n\n/**\n * The subpaths a layer's geometry blobs draw, as polylines in its own coordinates. Curves are\n * sampled, so a caller can test a point against the outline without a path engine.\n */\nexport function geometryBlobPolylines(\n paths: Array<{ commandsBlob: Uint8Array }>,\n curveSteps = OUTLINE_CURVE_STEPS\n): Vector[][] {\n const polylines: Vector[][] = []\n for (const path of paths) polylines.push(...blobPolylines(path.commandsBlob, curveSteps))\n return polylines\n}\n\ntype TurnedBox = Pick<VisualBoundsNode, 'width' | 'height' | 'rotation' | 'flipX' | 'flipY'>\n\n/**\n * Where a local point lands relative to the box's unturned top-left, turned about the center and\n * then flipped about it, in the order `getNodeLocalMatrix` composes the same two steps.\n */\nfunction transformLocalPoint(node: TurnedBox, point: Vector): Vector {\n let { x, y } = point\n const rotation = node.rotation ?? 0\n if (rotation !== 0) {\n const rotated = rotatePoint(x, y, node.width / 2, node.height / 2, degToRad(rotation))\n x = rotated.x\n y = rotated.y\n }\n if (node.flipX) x = node.width - x\n if (node.flipY) y = node.height - y\n return { x, y }\n}\n\n/**\n * The unturned top-left of a box whose origin (its own 0,0, as `SceneGraph.getAbsolutePosition`\n * returns it) sits at `origin` after the rotation.\n */\nfunction unturnedTopLeft(node: TurnedBox, origin: Vector): Vector {\n // `getAbsolutePosition` maps the box's own origin through the world matrix, flips included.\n const offset = transformLocalPoint(node, { x: 0, y: 0 })\n return { x: origin.x - offset.x, y: origin.y - offset.y }\n}\n\nfunction transformedLocalBounds(node: VisualBoundsNode, local: Rect, abs: Vector): VisualBounds {\n const points = [\n { x: local.x, y: local.y },\n { x: local.x + local.width, y: local.y },\n { x: local.x + local.width, y: local.y + local.height },\n { x: local.x, y: local.y + local.height }\n ].map((point) => transformLocalPoint(node, point))\n\n return {\n minX: abs.x + Math.min(...points.map((point) => point.x)),\n minY: abs.y + Math.min(...points.map((point) => point.y)),\n maxX: abs.x + Math.max(...points.map((point) => point.x)),\n maxY: abs.y + Math.max(...points.map((point) => point.y))\n }\n}\n\nexport function nodeVisualBounds(\n node: VisualBoundsNode,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds {\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const base = computeVisualBounds([node], getAbsolutePosition)\n let bounds: VisualBounds = {\n minX: base.x,\n minY: base.y,\n maxX: base.x + base.width,\n maxY: base.y + base.height\n }\n\n const hasNonInsideStroke = node.strokes?.some(\n (stroke) => stroke.visible && stroke.align !== 'INSIDE'\n )\n const localGeometry = geometryBlobBounds([\n ...(node.fillGeometry ?? []),\n ...(hasNonInsideStroke ? (node.strokeGeometry ?? []) : [])\n ])\n if (localGeometry) {\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, localGeometry, abs)) ?? bounds\n }\n\n // A fixed-size box lets its lines run past it on the side away from the vertical alignment,\n // and an underline or strikethrough reaches below the last line, turning with the text.\n const reach = textLinesReach(node)\n const above = Math.min(reach.minY, 0)\n const below = Math.max(reach.maxY, node.height) + textDecorationOverflow(node)\n if (above < 0 || below > node.height) {\n const lines = { x: 0, y: above, width: node.width, height: below - above }\n bounds = unionVisualBounds(bounds, transformedLocalBounds(node, lines, abs)) ?? bounds\n }\n\n return bounds\n}\n\n/** How far a text node's underline or strikethrough reaches below its box. */\nexport function textDecorationOverflow(node: VisualBoundsNode): number {\n if (node.type !== 'TEXT' || !node.textDecoration || node.textDecoration === 'NONE') return 0\n const fontSize = node.fontSize ?? 14\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\nfunction collectDescendantVisualBounds(\n nodeId: string,\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector,\n clip: VisualBounds | null = null\n): VisualBounds | null {\n const node = getNode(nodeId)\n if (!node?.visible) return null\n\n const own = nodeVisualBounds(node, getAbsolutePosition)\n let bounds = clip ? intersectVisualBounds(own, clip) : own\n\n const isClippableContainer =\n node.type === 'FRAME' || node.type === 'COMPONENT' || node.type === 'INSTANCE'\n let childClip = clip\n if (isClippableContainer && node.clipsContent) {\n // The frame's own drawn box, so a turned frame clips where it is drawn. For an unturned,\n // unflipped frame this is the same box as its position and size give.\n const abs = unturnedTopLeft(node, getAbsolutePosition(node.id))\n const nodeClip = transformedLocalBounds(\n node,\n { x: 0, y: 0, width: node.width, height: node.height },\n abs\n )\n childClip = childClip ? intersectVisualBounds(childClip, nodeClip) : nodeClip\n if (!childClip) return bounds\n }\n\n for (const childId of node.childIds ?? []) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(childId, getNode, getAbsolutePosition, childClip)\n )\n }\n\n return bounds\n}\n\nexport function computeDescendantVisualBounds(\n nodeIds: string[],\n getNode: (id: string) => VisualBoundsNode | undefined,\n getAbsolutePosition: (id: string) => Vector\n): VisualBounds | null {\n let bounds: VisualBounds | null = null\n for (const nodeId of nodeIds) {\n bounds = unionVisualBounds(\n bounds,\n collectDescendantVisualBounds(nodeId, getNode, getAbsolutePosition)\n )\n }\n return bounds\n}\n"],"mappings":";;;;AAOA,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,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK;GAAK,GAAG,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,OAA4B,MACP;CACrB,MAAM,OAAO,QAAQ,MAAM;CAC3B,IAAI,CAAC,MAAM,SAAS,OAAO;CAE3B,MAAM,MAAM,iBAAiB,MAAM,mBAAmB;CACtD,IAAI,SAAS,OAAO,sBAAsB,KAAK,IAAI,IAAI;CAEvD,MAAM,uBACJ,KAAK,SAAS,WAAW,KAAK,SAAS,eAAe,KAAK,SAAS;CACtE,IAAI,YAAY;CAChB,IAAI,wBAAwB,KAAK,cAAc;EAG7C,MAAM,MAAM,gBAAgB,MAAM,oBAAoB,KAAK,EAAE,CAAC;EAC9D,MAAM,WAAW,uBACf,MACA;GAAE,GAAG;GAAG,GAAG;GAAG,OAAO,KAAK;GAAO,QAAQ,KAAK;EAAO,GACrD,GACF;EACA,YAAY,YAAY,sBAAsB,WAAW,QAAQ,IAAI;EACrE,IAAI,CAAC,WAAW,OAAO;CACzB;CAEA,KAAK,MAAM,WAAW,KAAK,YAAY,CAAC,GACtC,SAAS,kBACP,QACA,8BAA8B,SAAS,SAAS,qBAAqB,SAAS,CAChF;CAGF,OAAO;AACT;AAEA,SAAgB,8BACd,SACA,SACA,qBACqB;CACrB,IAAI,SAA8B;CAClC,KAAK,MAAM,UAAU,SACnB,SAAS,kBACP,QACA,8BAA8B,QAAQ,SAAS,mBAAmB,CACpE;CAEF,OAAO;AACT"}
package/dist/graph.d.ts CHANGED
@@ -25,7 +25,12 @@ declare class SceneGraph {
25
25
  private absPosCache;
26
26
  private readonly scopeDepths;
27
27
  private previewObservers;
28
+ /** Edited-field marks added since the last undo step, which that step takes back when undone. */
29
+ private pendingSourceMarks;
30
+ private readonly observeSourceMark;
28
31
  private readonly changeObservers;
32
+ /** How many waits outside the edit each recorder is paused for. */
33
+ private readonly outsideWaits;
29
34
  private importedIdGenerator;
30
35
  private layoutWrites;
31
36
  positionPreviewVersion: number;
@@ -45,6 +50,19 @@ declare class SceneGraph {
45
50
  * reports it with `willChangeNode` first.
46
51
  */
47
52
  observeNodeChanges(observer: NodeChangeObserver): () => void;
53
+ /**
54
+ /**
55
+ * Runs `write`, a change someone else makes, such as a page the reader worker loaded or a
56
+ * collaborator's arriving, outside every edit in progress: the recorders open now do not see
57
+ * it, so none records it as its own. A recorder opened while the write runs is not paused.
58
+ */
59
+ runOutsideEdits<T>(write: () => T): T;
60
+ /**
61
+ * Waits for `promise`, such as a font or an image download an edit needs, outside the edit in
62
+ * progress: what changes meanwhile, such as the user's or a collaborator's edit, is not recorded
63
+ * as the waiting edit's. Only for code that writes nothing itself until the wait ends.
64
+ */
65
+ waitOutsideEdit<T>(promise: Promise<T>): Promise<T>;
48
66
  /** Tells `observeNodeChanges` observers that `node` is about to change. */
49
67
  willChangeNode(node: SceneNode | undefined): void;
50
68
  countDescendants(nodeId: string): number;
@@ -119,6 +137,12 @@ declare class SceneGraph {
119
137
  runPreviewUpdates(fn: () => void, beforeUpdate?: NodePreviewObserver): void;
120
138
  preserveSourceMetadataDuring<T>(fn: () => T): T;
121
139
  get isPreservingSourceMetadata(): boolean;
140
+ /** The edited-field marks added since the last call, which that undo step takes back. */
141
+ takeSourceMarks(): Array<[string, string]>;
142
+ /** Marks fields as edited again, for redo of a step that marked them. */
143
+ addSourceMarks(id: string, fields: readonly string[]): void;
144
+ /** Takes back the marks a step added, for undo of that step. */
145
+ removeSourceMarks(id: string, fields: readonly string[]): void;
122
146
  applyImportedStateDuring<T>(fn: () => T, idGenerator?: () => string): T;
123
147
  get isApplyingImportedState(): boolean;
124
148
  /**
@@ -126,6 +150,13 @@ declare class SceneGraph {
126
150
  * arrive. What this writes derives from the document; an edit's own layout is not this.
127
151
  */
128
152
  applyDerivedLayoutDuring(fn: () => void): void;
153
+ /**
154
+ * Runs `fn` as values a copy takes from its component, such as the bound paints of a layer an
155
+ * instance copies, refreshed for it. Source metadata is preserved, and a save leaves them to the
156
+ * component rather than writing them as edits of the copy.
157
+ */
158
+ applyComponentDerivedDuring(fn: () => void): void;
159
+ get isApplyingComponentDerived(): boolean;
129
160
  get isApplyingDerivedLayout(): boolean;
130
161
  /**
131
162
  * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as
@@ -142,13 +173,21 @@ declare class SceneGraph {
142
173
  * they get here (`styleDetachmentChanges`); resolving bindings or loading a file does not.
143
174
  */
144
175
  updateNode(id: string, changes: Partial<SceneNode>): void;
145
- /** A size set from outside layout, with what it also sets on a generated frame. */
146
- private sizedChanges;
176
+ /**
177
+ * `changes` with what they also set: a size from outside layout on a generated frame, and
178
+ * strokes and the layer's line fields kept in agreement (`strokeLineChanges`).
179
+ */
180
+ private impliedChanges;
147
181
  /** Replay captured properties without dropping explicit undefined values or absent keys. */
148
182
  restoreNodeProperties(id: string, changes: Partial<SceneNode>, absent: readonly (keyof SceneNode)[]): void;
149
183
  private applyNodeChanges;
184
+ /** Marks fields an edit changed, unless metadata is being restored or layout is writing them. */
185
+ private markEdited;
150
186
  /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */
151
187
  private publishNodeUpdate;
188
+ /** Whether moving `node` under `parentId` would put an instance inside the component it draws. */
189
+ private movesIntoInstanceOutsideSlot;
190
+ private movesInstanceIntoItsComponent;
152
191
  reparentNode(nodeId: string, newParentId: string): void;
153
192
  /**
154
193
  * Moves a node to `index` among `parentId`'s children, from wherever it was, without changing
@@ -160,7 +199,10 @@ declare class SceneGraph {
160
199
  hitTest(px: number, py: number, scopeId?: string): SceneNode | null;
161
200
  /** `pad`, in canvas units, grows each shape's box, as Figma takes clicks just outside one. */
162
201
  hitTestDeep(px: number, py: number, scopeId?: string, pad?: number): SceneNode | null;
163
- hitTestSelectable(px: number, py: number, scopeId: string, selectedIds: ReadonlySet<string>, pad?: number): SceneNode | null;
202
+ /**
203
+ * The layer a press selects at the point; `locked` hits locked layers too, as a right-click does.
204
+ */
205
+ hitTestSelectable(px: number, py: number, scopeId: string, selectedIds: ReadonlySet<string>, pad?: number, locked?: boolean): SceneNode | null;
164
206
  hitTestOpenContainer(px: number, py: number, scopeId: string): SceneNode | null;
165
207
  isOpenContainer(nodeId: string): boolean;
166
208
  isPointInNode(nodeId: string, px: number, py: number): boolean;
@@ -176,6 +218,10 @@ declare class SceneGraph {
176
218
  detachInstance(instanceId: string): void;
177
219
  getMainComponent(instanceId: string): SceneNode | undefined;
178
220
  getInstances(componentId: string): SceneNode[];
221
+ /**
222
+ * The descendants of a layer in depth-first order with their depths. Each layer with children is
223
+ * walked once, so a cycle or repeated links in bad data cannot hang it or repeat its subtree.
224
+ */
179
225
  flattenTree(parentId?: string, depth?: number): Array<{
180
226
  node: SceneNode;
181
227
  depth: number;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;cAiDa;mBA+BkB;EA9B7B,OAAK,YAAA;EACL,QAAM,YAAA,WAAA;EACN,WAAS,YAAA;EACT,qBAAmB,YAAA;EACnB,YAAU;EACV;EACA;;EAEA,mBAAmB;EACnB,oBAAoB;EACpB,cAAc;EACd,kBAAgB,YAAA;WACP,SAAO;UACR;mBACS;UAOT;mBACS;UACT;UACA;EACR;EACA,eAAa,YAAA;;EAEb,cAAY;EAEiB,YAAA;EAW7B,QAAQ,eAAe;EAIvB,SAAS,4BAA0B;EAKnC,eAAe,SAAS;EAGxB,QAAQ,aAAa;EAGrB,aAAa,UAAU;;;;;;;EAUvB,mBAAmB,UAAU;;EAM7B,eAAe,MAAM;EAKrB,iBAAiB;EAkBjB,YAAY,UAAU;EAGtB,eAAe;EAGf,cAAc,YAAY;EAG1B,eACE,cACA,MAAM,cACN,sBACA,QAAQ,gBACP;EAWH,iBAAiB,eAAe;EAMhC,WAAW,sBAAsB,cAAc;;;;;EAc/C;EAKA,iBAAiB;EAIjB,gBAAgB;EAIhB,sBAAsB,gBAAgB;EAItC,cAAc,sBAAsB;EAIpC,QAAQ,sBAAsB,gBAAgB,cAAc;EAI5D,WAAW,sBAAsB;EAIjC,WAAW,sBAAsB,gBAAgB;EAIjD,eAAe,sBAAsB;EAIrC,gBACE,oBACA,iBACA,UAAU,cAC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