@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.4

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 (244) hide show
  1. package/dist/asset-keys.d.ts +11 -1
  2. package/dist/asset-keys.d.ts.map +1 -1
  3. package/dist/asset-keys.js +16 -1
  4. package/dist/asset-keys.js.map +1 -1
  5. package/dist/checkpoint.d.ts +3 -3
  6. package/dist/checkpoint.d.ts.map +1 -1
  7. package/dist/checkpoint.js +53 -23
  8. package/dist/checkpoint.js.map +1 -1
  9. package/dist/components/index.d.ts +2 -2
  10. package/dist/components/index.js +2 -2
  11. package/dist/components/properties.d.ts +6 -1
  12. package/dist/components/properties.d.ts.map +1 -1
  13. package/dist/components/properties.js +9 -1
  14. package/dist/components/properties.js.map +1 -1
  15. package/dist/constants.d.ts +6 -1
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/constants.js +17 -1
  18. package/dist/constants.js.map +1 -1
  19. package/dist/constraints.d.ts +25 -0
  20. package/dist/constraints.d.ts.map +1 -0
  21. package/dist/constraints.js +51 -0
  22. package/dist/constraints.js.map +1 -0
  23. package/dist/coordinate.d.ts +64 -1
  24. package/dist/coordinate.d.ts.map +1 -1
  25. package/dist/coordinate.js +217 -1
  26. package/dist/coordinate.js.map +1 -1
  27. package/dist/copy.d.ts.map +1 -1
  28. package/dist/copy.js +8 -1
  29. package/dist/copy.js.map +1 -1
  30. package/dist/css/index.d.ts +3 -2
  31. package/dist/css/index.js +3 -2
  32. package/dist/css/text.d.ts +28 -1
  33. package/dist/css/text.d.ts.map +1 -1
  34. package/dist/css/text.js +84 -17
  35. package/dist/css/text.js.map +1 -1
  36. package/dist/css/transform.d.ts +34 -0
  37. package/dist/css/transform.d.ts.map +1 -0
  38. package/dist/css/transform.js +320 -0
  39. package/dist/css/transform.js.map +1 -0
  40. package/dist/css/values.d.ts.map +1 -1
  41. package/dist/css/values.js +11 -1
  42. package/dist/css/values.js.map +1 -1
  43. package/dist/figjam/palette.d.ts +1 -1
  44. package/dist/figjam/palette.js +1 -1
  45. package/dist/figjam/palette.js.map +1 -1
  46. package/dist/geometry.d.ts +8 -1
  47. package/dist/geometry.d.ts.map +1 -1
  48. package/dist/geometry.js +19 -8
  49. package/dist/geometry.js.map +1 -1
  50. package/dist/graph.d.ts +48 -12
  51. package/dist/graph.d.ts.map +1 -1
  52. package/dist/graph.js +110 -24
  53. package/dist/graph.js.map +1 -1
  54. package/dist/group-bounds.d.ts +14 -4
  55. package/dist/group-bounds.d.ts.map +1 -1
  56. package/dist/group-bounds.js +76 -11
  57. package/dist/group-bounds.js.map +1 -1
  58. package/dist/hit-test.d.ts +5 -0
  59. package/dist/hit-test.d.ts.map +1 -1
  60. package/dist/hit-test.js +18 -12
  61. package/dist/hit-test.js.map +1 -1
  62. package/dist/images.d.ts +27 -3
  63. package/dist/images.d.ts.map +1 -1
  64. package/dist/images.js +57 -3
  65. package/dist/images.js.map +1 -1
  66. package/dist/index.d.ts +2 -2
  67. package/dist/instances/index.d.ts.map +1 -1
  68. package/dist/instances/index.js +3 -0
  69. package/dist/instances/index.js.map +1 -1
  70. package/dist/instances/placement.js +55 -12
  71. package/dist/instances/placement.js.map +1 -1
  72. package/dist/instances/swap.js +3 -0
  73. package/dist/instances/swap.js.map +1 -1
  74. package/dist/instances/sync.js +34 -13
  75. package/dist/instances/sync.js.map +1 -1
  76. package/dist/node-defaults.d.ts.map +1 -1
  77. package/dist/node-defaults.js +1 -0
  78. package/dist/node-defaults.js.map +1 -1
  79. package/dist/order-keys.d.ts +3 -1
  80. package/dist/order-keys.d.ts.map +1 -1
  81. package/dist/order-keys.js +6 -1
  82. package/dist/order-keys.js.map +1 -1
  83. package/dist/plugin-data/fields.d.ts +2 -0
  84. package/dist/plugin-data/fields.d.ts.map +1 -1
  85. package/dist/plugin-data/fields.js +2 -0
  86. package/dist/plugin-data/fields.js.map +1 -1
  87. package/dist/resize.d.ts +22 -11
  88. package/dist/resize.d.ts.map +1 -1
  89. package/dist/resize.js +227 -93
  90. package/dist/resize.js.map +1 -1
  91. package/dist/scaling/index.d.ts +3 -2
  92. package/dist/scaling/index.js +3 -2
  93. package/dist/scaling/node.d.ts.map +1 -1
  94. package/dist/scaling/node.js +5 -1
  95. package/dist/scaling/node.js.map +1 -1
  96. package/dist/scaling/snapshot.d.ts +25 -0
  97. package/dist/scaling/snapshot.d.ts.map +1 -0
  98. package/dist/scaling/snapshot.js +39 -0
  99. package/dist/scaling/snapshot.js.map +1 -0
  100. package/dist/scaling/tree.d.ts +24 -2
  101. package/dist/scaling/tree.d.ts.map +1 -1
  102. package/dist/scaling/tree.js +37 -14
  103. package/dist/scaling/tree.js.map +1 -1
  104. package/dist/shaders/model.d.ts.map +1 -1
  105. package/dist/shaders/model.js +2 -1
  106. package/dist/shaders/model.js.map +1 -1
  107. package/dist/shared-styles.d.ts +3 -1
  108. package/dist/shared-styles.d.ts.map +1 -1
  109. package/dist/shared-styles.js +7 -1
  110. package/dist/shared-styles.js.map +1 -1
  111. package/dist/slots/authoring.d.ts +3 -2
  112. package/dist/slots/authoring.d.ts.map +1 -1
  113. package/dist/slots/authoring.js +5 -3
  114. package/dist/slots/authoring.js.map +1 -1
  115. package/dist/slots/content.d.ts.map +1 -1
  116. package/dist/slots/content.js +4 -1
  117. package/dist/slots/content.js.map +1 -1
  118. package/dist/text/direction.d.ts +3 -1
  119. package/dist/text/direction.d.ts.map +1 -1
  120. package/dist/text/direction.js +5 -1
  121. package/dist/text/direction.js.map +1 -1
  122. package/dist/transfer/apply.d.ts.map +1 -1
  123. package/dist/transfer/apply.js +1 -6
  124. package/dist/transfer/apply.js.map +1 -1
  125. package/dist/transfer/copied.d.ts +35 -3
  126. package/dist/transfer/copied.d.ts.map +1 -1
  127. package/dist/transfer/copied.js +44 -13
  128. package/dist/transfer/copied.js.map +1 -1
  129. package/dist/transfer/dependencies.d.ts +38 -0
  130. package/dist/transfer/dependencies.d.ts.map +1 -0
  131. package/dist/transfer/dependencies.js +100 -0
  132. package/dist/transfer/dependencies.js.map +1 -0
  133. package/dist/transfer/history.js +0 -1
  134. package/dist/transfer/history.js.map +1 -1
  135. package/dist/transfer/index.d.ts +5 -3
  136. package/dist/transfer/index.js +5 -3
  137. package/dist/transfer/nodes.d.ts.map +1 -1
  138. package/dist/transfer/nodes.js +7 -14
  139. package/dist/transfer/nodes.js.map +1 -1
  140. package/dist/transfer/plan.d.ts +0 -1
  141. package/dist/transfer/plan.js +3 -5
  142. package/dist/transfer/plan.js.map +1 -1
  143. package/dist/transfer/remove.js +5 -2
  144. package/dist/transfer/remove.js.map +1 -1
  145. package/dist/transfer/resources.d.ts +21 -0
  146. package/dist/transfer/resources.d.ts.map +1 -0
  147. package/dist/transfer/resources.js +38 -0
  148. package/dist/transfer/resources.js.map +1 -0
  149. package/dist/transfer/variables.d.ts +8 -1
  150. package/dist/transfer/variables.d.ts.map +1 -1
  151. package/dist/transfer/variables.js +24 -1
  152. package/dist/transfer/variables.js.map +1 -1
  153. package/dist/types.d.ts +47 -2
  154. package/dist/types.d.ts.map +1 -1
  155. package/dist/types.js.map +1 -1
  156. package/dist/undo.d.ts +28 -3
  157. package/dist/undo.d.ts.map +1 -1
  158. package/dist/undo.js +24 -7
  159. package/dist/undo.js.map +1 -1
  160. package/dist/variables/bindings.d.ts +17 -14
  161. package/dist/variables/bindings.d.ts.map +1 -1
  162. package/dist/variables/bindings.js +30 -72
  163. package/dist/variables/bindings.js.map +1 -1
  164. package/dist/variables/fields.d.ts +1 -1
  165. package/dist/variables/fields.js +1 -1
  166. package/dist/variables/fields.js.map +1 -1
  167. package/dist/variables/formula/check.d.ts +1 -1
  168. package/dist/variables/formula/index.d.ts +2 -2
  169. package/dist/variables/formula/index.js +1 -1
  170. package/dist/variables/formula/index.js.map +1 -1
  171. package/dist/variables/formula/print.d.ts +1 -1
  172. package/dist/variables/formula/signatures.js +1 -1
  173. package/dist/variables/index.d.ts +6 -6
  174. package/dist/variables/index.d.ts.map +1 -1
  175. package/dist/variables/index.js +40 -24
  176. package/dist/variables/index.js.map +1 -1
  177. package/dist/variables/paints.d.ts +57 -0
  178. package/dist/variables/paints.d.ts.map +1 -0
  179. package/dist/variables/paints.js +231 -0
  180. package/dist/variables/paints.js.map +1 -0
  181. package/dist/variables/resolution.d.ts +14 -11
  182. package/dist/variables/resolution.d.ts.map +1 -1
  183. package/dist/variables/resolution.js +36 -17
  184. package/dist/variables/resolution.js.map +1 -1
  185. package/dist/variables/subtree.js +17 -0
  186. package/dist/variables/subtree.js.map +1 -0
  187. package/dist/vector-network.d.ts.map +1 -1
  188. package/dist/vector-network.js +2 -8
  189. package/dist/vector-network.js.map +1 -1
  190. package/package.json +8 -1
  191. package/src/asset-keys.ts +20 -0
  192. package/src/checkpoint.ts +87 -32
  193. package/src/components/properties.ts +9 -0
  194. package/src/constants.ts +17 -0
  195. package/src/constraints.ts +60 -0
  196. package/src/coordinate.ts +220 -0
  197. package/src/copy.ts +9 -4
  198. package/src/css/index.ts +17 -1
  199. package/src/css/text.ts +85 -17
  200. package/src/css/transform.ts +266 -0
  201. package/src/css/values.ts +8 -0
  202. package/src/figjam/palette.ts +1 -1
  203. package/src/geometry.ts +20 -9
  204. package/src/graph.ts +128 -42
  205. package/src/group-bounds.ts +84 -17
  206. package/src/hit-test.ts +30 -14
  207. package/src/images.ts +71 -3
  208. package/src/instances/index.ts +4 -0
  209. package/src/instances/placement.ts +63 -10
  210. package/src/instances/swap.ts +5 -0
  211. package/src/instances/sync.ts +48 -21
  212. package/src/node-defaults.ts +1 -0
  213. package/src/order-keys.ts +6 -0
  214. package/src/plugin-data/fields.ts +6 -0
  215. package/src/resize.ts +267 -119
  216. package/src/scaling/index.ts +9 -1
  217. package/src/scaling/node.ts +9 -1
  218. package/src/scaling/snapshot.ts +51 -0
  219. package/src/scaling/tree.ts +63 -19
  220. package/src/shaders/model.ts +2 -3
  221. package/src/shared-styles.ts +8 -0
  222. package/src/slots/authoring.ts +5 -3
  223. package/src/slots/content.ts +4 -1
  224. package/src/text/direction.ts +5 -0
  225. package/src/transfer/apply.ts +1 -13
  226. package/src/transfer/copied.ts +83 -15
  227. package/src/transfer/dependencies.ts +126 -0
  228. package/src/transfer/history.ts +0 -6
  229. package/src/transfer/index.ts +20 -2
  230. package/src/transfer/nodes.ts +10 -26
  231. package/src/transfer/plan.ts +3 -11
  232. package/src/transfer/remove.ts +5 -2
  233. package/src/transfer/resources.ts +54 -0
  234. package/src/transfer/variables.ts +34 -0
  235. package/src/types.ts +55 -1
  236. package/src/undo.ts +48 -10
  237. package/src/variables/bindings.ts +44 -91
  238. package/src/variables/fields.ts +1 -1
  239. package/src/variables/formula/index.ts +3 -1
  240. package/src/variables/index.ts +56 -38
  241. package/src/variables/paints.ts +296 -0
  242. package/src/variables/resolution.ts +39 -28
  243. package/src/variables/subtree.ts +15 -0
  244. package/src/vector-network.ts +4 -2
@@ -219,7 +219,7 @@ declare function figJamOutlineColorName(color: Color | undefined): FigJamColorNa
219
219
  * How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the
220
220
  * outline drawn on top, with white text on the palette's darkest colours and black on the rest;
221
221
  * null for a section without an outline from the palette. `colorOf` reads an outline's colour as
222
- * drawn, such as a variable's value in the active mode.
222
+ * drawn, such as a variable's value in the section's mode.
223
223
  */
224
224
  declare function figJamSectionTitleColors(section: Pick<SceneNode, 'strokes'>, colorOf?: (stroke: Stroke, index: number) => Color): {
225
225
  strokeIndex: number;
@@ -226,7 +226,7 @@ function figJamOutlineColorName(color) {
226
226
  * How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the
227
227
  * outline drawn on top, with white text on the palette's darkest colours and black on the rest;
228
228
  * null for a section without an outline from the palette. `colorOf` reads an outline's colour as
229
- * drawn, such as a variable's value in the active mode.
229
+ * drawn, such as a variable's value in the section's mode.
230
230
  */
231
231
  function figJamSectionTitleColors(section, colorOf = (stroke) => stroke.color) {
232
232
  const strokeIndex = section.strokes.findLastIndex((stroke) => stroke.visible && stroke.opacity > 0);
@@ -1 +1 @@
1
- {"version":3,"file":"palette.js","names":[],"sources":["../../src/figjam/palette.ts"],"sourcesContent":["import { omit } from 'es-toolkit'\n\nimport { parseColor } from '../color'\nimport { BLACK, WHITE } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\n\n/**\n * FigJam's board palette, in its menus' order, as its colour menu paints a shape with text: each\n * fill pairs with a darker stroke, a light label on the darkest fills, and, made transparent, a\n * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours, and\n * a section takes a pale tint of each with the colour itself as its outline.\n */\nconst PALETTE = {\n black: {\n fill: '#1e1e1e',\n stroke: '#242424',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#929292',\n sectionFill: '#dddddd',\n sectionStroke: '#2c2c2c'\n },\n darkGray: {\n fill: '#757575',\n stroke: '#424242',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a1a1a1',\n sectionFill: '#eaeaea',\n sectionStroke: '#757575'\n },\n red: {\n fill: '#f24822',\n stroke: '#bd2915',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#c7968f',\n sectionFill: '#ffe2e0',\n sectionStroke: '#f24822'\n },\n orange: {\n fill: '#ff9e42',\n stroke: '#eb7500',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#e9b780',\n sectionFill: '#ffead6',\n sectionStroke: '#ff9e42'\n },\n yellow: {\n fill: '#ffc943',\n stroke: '#e8a302',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f5d280',\n sectionFill: '#fff3d6',\n sectionStroke: '#ffc943'\n },\n green: {\n fill: '#66d575',\n stroke: '#3e9b4b',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c79e',\n sectionFill: '#ddf8e2',\n sectionStroke: '#66d575'\n },\n teal: {\n fill: '#5ad8cc',\n stroke: '#369e94',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c9c6',\n sectionFill: '#defcfa',\n sectionStroke: '#5ad8cc'\n },\n blue: {\n fill: '#3dadff',\n stroke: '#007ad2',\n lightLabel: true,\n transparent: 0.7,\n transparentStroke: '#4d99d3',\n sectionFill: '#dbf0ff',\n sectionStroke: '#3dadff'\n },\n violet: {\n fill: '#874fff',\n stroke: '#5427b4',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a792d0',\n sectionFill: '#eae1ff',\n sectionStroke: '#874fff'\n },\n pink: {\n fill: '#f849c1',\n stroke: '#b42487',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#ce92bb',\n sectionFill: '#ffd6f2',\n sectionStroke: '#f849c1'\n },\n white: {\n fill: '#ffffff',\n stroke: '#757575',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f1f1f1',\n sectionFill: '#ffffff',\n sectionStroke: '#e6e6e6'\n },\n gray: {\n fill: '#b3b3b3',\n stroke: '#797979',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcbcbc',\n sectionFill: '#f4f4f4',\n sectionStroke: '#b3b3b3'\n },\n lightGray: {\n fill: '#d9d9d9',\n stroke: '#a5a5a5',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#c0c0c0',\n sectionFill: '#f9f9f9',\n sectionStroke: '#d9d9d9'\n },\n lightRed: {\n fill: '#ffc7c2',\n stroke: '#f24822',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#ff9d8f',\n sectionFill: '#fff5f5',\n sectionStroke: '#ffc7c2'\n },\n lightOrange: {\n fill: '#ffe0c2',\n stroke: '#ff9e42',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#f6c34d',\n sectionFill: '#fff7f0',\n sectionStroke: '#ffe0c2'\n },\n lightYellow: {\n fill: '#ffecbd',\n stroke: '#ffc943',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#efd54d',\n sectionFill: '#fffbf0',\n sectionStroke: '#ffecbd'\n },\n lightGreen: {\n fill: '#cdf4d3',\n stroke: '#66d575',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#a8d7b4',\n sectionFill: '#ebffee',\n sectionStroke: '#cdf4d3'\n },\n lightTeal: {\n fill: '#c6faf6',\n stroke: '#5ad8cc',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcebeb',\n sectionFill: '#f1fefd',\n sectionStroke: '#c6faf6'\n },\n lightBlue: {\n fill: '#c2e5ff',\n stroke: '#3dadff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#76ccff',\n sectionFill: '#f5fbff',\n sectionStroke: '#c2e5ff'\n },\n lightViolet: {\n fill: '#dcccff',\n stroke: '#874fff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#d5a3ff',\n sectionFill: '#f8f5ff',\n sectionStroke: '#dcccff'\n },\n lightPink: {\n fill: '#ffc2ec',\n stroke: '#f849c1',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#ffaaeb',\n sectionFill: '#fff0fa',\n sectionStroke: '#ffc2ec'\n }\n} as const\n\nexport type FigJamColorName = keyof typeof PALETTE\n\nexport const FIGJAM_COLOR_NAMES = Object.keys(PALETTE) as FigJamColorName[]\n\n/** How a shape's colour fills it: solid, see-through, or not at all, as FigJam's menu sets it. */\nexport type FigJamFillMode = 'fill' | 'transparent' | 'none'\n\n/** How a shape's outline is drawn, as FigJam's line menu sets it. */\nexport type FigJamLineStyle = 'solid' | 'dashed' | 'none'\n\n/** The dash FigJam's line menu draws a shape's outline with. */\nexport const FIGJAM_SHAPE_DASH = [16, 10] as const\n\n/** A palette colour as a colour. */\nexport function figJamColor(name: FigJamColorName): Color {\n return parseColor(PALETTE[name].fill)\n}\n\nfunction sameColor(a: Color | undefined, b: Color): boolean {\n if (!a) return false\n const close = (x: number, y: number) => Math.abs(x - y) < 1 / 512\n return close(a.r, b.r) && close(a.g, b.g) && close(a.b, b.b)\n}\n\n/** The palette colour a paint is, if any. */\nexport function figJamColorName(color: Color | undefined): FigJamColorName | null {\n return FIGJAM_COLOR_NAMES.find((name) => sameColor(color, figJamColor(name))) ?? null\n}\n\n/**\n * The palette colour an outline is drawn in: a colour itself, or the outline a section of that\n * colour takes, which is darker for black and lighter for white.\n */\nexport function figJamOutlineColorName(color: Color | undefined): FigJamColorName | null {\n return (\n figJamColorName(color) ??\n FIGJAM_COLOR_NAMES.find((name) => sameColor(color, parseColor(PALETTE[name].sectionStroke))) ??\n null\n )\n}\n\n/**\n * How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the\n * outline drawn on top, with white text on the palette's darkest colours and black on the rest;\n * null for a section without an outline from the palette. `colorOf` reads an outline's colour as\n * drawn, such as a variable's value in the active mode.\n */\nexport function figJamSectionTitleColors(\n section: Pick<SceneNode, 'strokes'>,\n colorOf: (stroke: Stroke, index: number) => Color = (stroke) => stroke.color\n): { strokeIndex: number; background: Color; lightText: boolean } | null {\n const strokeIndex = section.strokes.findLastIndex(\n (stroke) => stroke.visible && stroke.opacity > 0\n )\n const outline = section.strokes.at(strokeIndex)\n if (strokeIndex === -1 || !outline) return null\n const color = colorOf(outline, strokeIndex)\n const name = figJamOutlineColorName(color)\n if (!name) return null\n return { strokeIndex, background: { ...color, a: 1 }, lightText: PALETTE[name].lightLabel }\n}\n\n/** The fill mode a shape's first fill shows. */\nexport function figJamFillMode(fill: Fill | undefined): FigJamFillMode {\n if (!fill || !fill.visible || fill.opacity === 0) return 'none'\n return fill.opacity < 1 ? 'transparent' : 'fill'\n}\n\n/** The outline FigJam pairs with a colour in a fill mode. */\nexport function figJamPairedStroke(name: FigJamColorName, mode: FigJamFillMode): Color {\n const entry = PALETTE[name]\n return parseColor(mode === 'fill' ? entry.stroke : entry.transparentStroke)\n}\n\n/** The label paint FigJam pairs with a colour in a fill mode. */\nfunction pairedLabel(name: FigJamColorName, mode: FigJamFillMode): Fill {\n const light = PALETTE[name].lightLabel && (mode === 'fill' || name === 'black') && mode !== 'none'\n return light\n ? { type: 'SOLID', color: { ...WHITE }, opacity: 1, visible: true }\n : { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n}\n\n/** How opaque FigJam fills a colour in a fill mode. */\nfunction fillOpacity(name: FigJamColorName, mode: FigJamFillMode): number {\n if (mode === 'transparent') return PALETTE[name].transparent\n return mode === 'fill' ? 1 : 0\n}\n\n/** What a shape with text and its label become when painted `name` in `mode`. */\nexport interface FigJamShapePaint {\n shape: Partial<SceneNode>\n label: Partial<SceneNode>\n}\n\n/**\n * A shape painted `name` in `mode`, as FigJam's colour menu paints it. The stroke and label follow\n * the colour only while they are still the ones FigJam paired with the current paint: a line or\n * text colour set by hand stays.\n */\nexport function figJamShapePaint(\n shape: Pick<SceneNode, 'fills' | 'strokes'>,\n label: Pick<SceneNode, 'fills'> | null,\n name: FigJamColorName,\n mode: FigJamFillMode\n): FigJamShapePaint {\n const fill = shape.fills.at(0)\n const current = figJamColorName(fill?.color)\n const currentMode = figJamFillMode(fill)\n const opacity = fillOpacity(name, mode)\n const result: FigJamShapePaint = {\n shape: { fills: [{ type: 'SOLID', color: figJamColor(name), opacity, visible: true }] },\n label: {}\n }\n const stroke = shape.strokes.at(0)\n const strokeFollows =\n !stroke || !current || sameColor(stroke.color, figJamPairedStroke(current, currentMode))\n if (stroke && strokeFollows) {\n result.shape.strokes = [\n { ...stroke, color: figJamPairedStroke(name, mode) },\n ...shape.strokes.slice(1)\n ]\n }\n const labelFill = label?.fills.at(0)\n const paired = current ? pairedLabel(current, currentMode) : null\n const labelFollows =\n !labelFill ||\n !paired ||\n (sameColor(labelFill.color, paired.color) &&\n Math.abs(labelFill.opacity - paired.opacity) < 0.01)\n if (label && labelFollows) result.label = { fills: [pairedLabel(name, mode)] }\n return result\n}\n\n/**\n * A shape's outline drawn `style`, as FigJam's line menu draws it; the weight stays. The dash is\n * the layer's, as files keep it, and each stroke's, as it is drawn.\n */\nexport function figJamLineStyleFields(\n shape: Pick<SceneNode, 'strokes'>,\n style: FigJamLineStyle\n): Partial<SceneNode> {\n const dashPattern = style === 'dashed' ? [...FIGJAM_SHAPE_DASH] : []\n const strokes = shape.strokes.map((stroke): Stroke => ({\n ...stroke,\n opacity: style === 'none' ? 0 : 1,\n dashPattern: [...dashPattern]\n }))\n return { strokes, dashPattern }\n}\n\n/** The line style a shape's outline shows. */\nexport function figJamLineStyle(shape: Pick<SceneNode, 'strokes'>): FigJamLineStyle {\n const stroke = shape.strokes.at(0)\n if (!stroke || !stroke.visible || stroke.opacity === 0) return 'none'\n return (stroke.dashPattern?.length ?? 0) > 0 ? 'dashed' : 'solid'\n}\n\n/**\n * A shape's outline in palette colour `name`, as FigJam's line menu colours it; a hidden outline\n * shows again, keeping its dash.\n */\nexport function figJamLineColorFields(\n shape: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const strokes =\n shape.strokes.length > 0\n ? shape.strokes.map((stroke): Stroke => ({ ...stroke, color, opacity: 1 }))\n : [\n {\n type: 'SOLID',\n color,\n opacity: 1,\n visible: true,\n weight: 4,\n align: 'CENTER'\n } satisfies Stroke\n ]\n return { strokes }\n}\n\n/** How heavy FigJam outlines a coloured section, and a coloured layer that had no stroke. */\nconst SECTION_STROKE_WEIGHT = 2\nconst LAYER_STROKE_WEIGHT = 1\n\n/** `strokes` recoloured, or a new stroke of `weight` when there are none. */\nfunction strokesIn(strokes: Stroke[], color: Color, weight: number): Stroke[] {\n if (strokes.length > 0) return strokes.map((stroke) => ({ ...stroke, type: 'SOLID', color }))\n return [{ type: 'SOLID', color, opacity: 1, visible: true, weight, align: 'INSIDE' }]\n}\n\n/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */\nexport function figJamSectionColorFields(\n section: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const { sectionFill, sectionStroke } = PALETTE[name]\n // The outline shows in full at FigJam's 2, as its menu draws it, unless the line menu hid it.\n const strokes = strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT).map(\n (stroke): Stroke =>\n stroke.opacity === 0\n ? stroke\n : { ...stroke, opacity: 1, visible: true, weight: SECTION_STROKE_WEIGHT }\n )\n return {\n fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],\n strokes,\n strokeWeight: SECTION_STROKE_WEIGHT\n }\n}\n\n/**\n * The paint of `paints` the canvas shows on top: the last it draws, skipping hidden and fully\n * transparent ones, which show nothing.\n */\nfunction drawnPaint<P extends Fill>(paints: readonly P[]): P | undefined {\n return paints.findLast((paint) => paint.visible && paint.opacity > 0)\n}\n\n/** The palette colour a section is painted, by its tint. */\nexport function figJamSectionColorName(section: Pick<SceneNode, 'fills'>): FigJamColorName | null {\n const fill = drawnPaint(section.fills)?.color\n return (\n FIGJAM_COLOR_NAMES.find((name) => sameColor(fill, parseColor(PALETTE[name].sectionFill))) ??\n null\n )\n}\n\n/**\n * Whether a layer takes a palette colour as its stroke alone: a line, or a pen stroke, which is a\n * vector with nothing filled. A filled vector takes it as any other layer does.\n */\nfunction colorsStroke(node: Pick<SceneNode, 'type' | 'fills'>): boolean {\n if (node.type === 'LINE') return true\n return node.type === 'VECTOR' && !drawnPaint(node.fills)\n}\n\n/**\n * A plain layer painted `name`, as FigJam's colour menu paints one: text takes it as its fill, a\n * line or a pen stroke as its stroke, and any other layer as its fill and a stroke of the same\n * colour.\n */\nexport function figJamLayerColorFields(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes' | 'styleRuns'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const fills: Fill[] = [{ type: 'SOLID', color, opacity: 1, visible: true }]\n if (node.type === 'TEXT') {\n // The whole text takes the colour, ranges coloured on their own included.\n const styleRuns = node.styleRuns.map((run) => ({\n ...run,\n style: omit(run.style, ['fills', 'fillStyleId'])\n }))\n return { fills, styleRuns }\n }\n const strokes = strokesIn(node.strokes, color, LAYER_STROKE_WEIGHT)\n return colorsStroke(node) ? { strokes } : { fills, strokes }\n}\n\n/** The palette colour a plain layer shows, read where {@link figJamLayerColorFields} paints it. */\nexport function figJamLayerColorName(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes'>\n): FigJamColorName | null {\n const paints: Fill[] = colorsStroke(node) ? node.strokes : node.fills\n return figJamColorName(drawnPaint(paints)?.color)\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,UAAU;CACd,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,UAAU;EACR,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,KAAK;EACH,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;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import { parseColor } from '../color'\nimport { BLACK, WHITE } from '../constants'\nimport type { Color } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\n\n/**\n * FigJam's board palette, in its menus' order, as its colour menu paints a shape with text: each\n * fill pairs with a darker stroke, a light label on the darkest fills, and, made transparent, a\n * lighter fill and its own stroke. Its line menu and connectors take the fills as line colours, and\n * a section takes a pale tint of each with the colour itself as its outline.\n */\nconst PALETTE = {\n black: {\n fill: '#1e1e1e',\n stroke: '#242424',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#929292',\n sectionFill: '#dddddd',\n sectionStroke: '#2c2c2c'\n },\n darkGray: {\n fill: '#757575',\n stroke: '#424242',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a1a1a1',\n sectionFill: '#eaeaea',\n sectionStroke: '#757575'\n },\n red: {\n fill: '#f24822',\n stroke: '#bd2915',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#c7968f',\n sectionFill: '#ffe2e0',\n sectionStroke: '#f24822'\n },\n orange: {\n fill: '#ff9e42',\n stroke: '#eb7500',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#e9b780',\n sectionFill: '#ffead6',\n sectionStroke: '#ff9e42'\n },\n yellow: {\n fill: '#ffc943',\n stroke: '#e8a302',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f5d280',\n sectionFill: '#fff3d6',\n sectionStroke: '#ffc943'\n },\n green: {\n fill: '#66d575',\n stroke: '#3e9b4b',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c79e',\n sectionFill: '#ddf8e2',\n sectionStroke: '#66d575'\n },\n teal: {\n fill: '#5ad8cc',\n stroke: '#369e94',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#80c9c6',\n sectionFill: '#defcfa',\n sectionStroke: '#5ad8cc'\n },\n blue: {\n fill: '#3dadff',\n stroke: '#007ad2',\n lightLabel: true,\n transparent: 0.7,\n transparentStroke: '#4d99d3',\n sectionFill: '#dbf0ff',\n sectionStroke: '#3dadff'\n },\n violet: {\n fill: '#874fff',\n stroke: '#5427b4',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#a792d0',\n sectionFill: '#eae1ff',\n sectionStroke: '#874fff'\n },\n pink: {\n fill: '#f849c1',\n stroke: '#b42487',\n lightLabel: true,\n transparent: 0.5,\n transparentStroke: '#ce92bb',\n sectionFill: '#ffd6f2',\n sectionStroke: '#f849c1'\n },\n white: {\n fill: '#ffffff',\n stroke: '#757575',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#f1f1f1',\n sectionFill: '#ffffff',\n sectionStroke: '#e6e6e6'\n },\n gray: {\n fill: '#b3b3b3',\n stroke: '#797979',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcbcbc',\n sectionFill: '#f4f4f4',\n sectionStroke: '#b3b3b3'\n },\n lightGray: {\n fill: '#d9d9d9',\n stroke: '#a5a5a5',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#c0c0c0',\n sectionFill: '#f9f9f9',\n sectionStroke: '#d9d9d9'\n },\n lightRed: {\n fill: '#ffc7c2',\n stroke: '#f24822',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#ff9d8f',\n sectionFill: '#fff5f5',\n sectionStroke: '#ffc7c2'\n },\n lightOrange: {\n fill: '#ffe0c2',\n stroke: '#ff9e42',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#f6c34d',\n sectionFill: '#fff7f0',\n sectionStroke: '#ffe0c2'\n },\n lightYellow: {\n fill: '#ffecbd',\n stroke: '#ffc943',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#efd54d',\n sectionFill: '#fffbf0',\n sectionStroke: '#ffecbd'\n },\n lightGreen: {\n fill: '#cdf4d3',\n stroke: '#66d575',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#a8d7b4',\n sectionFill: '#ebffee',\n sectionStroke: '#cdf4d3'\n },\n lightTeal: {\n fill: '#c6faf6',\n stroke: '#5ad8cc',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#bcebeb',\n sectionFill: '#f1fefd',\n sectionStroke: '#c6faf6'\n },\n lightBlue: {\n fill: '#c2e5ff',\n stroke: '#3dadff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#76ccff',\n sectionFill: '#f5fbff',\n sectionStroke: '#c2e5ff'\n },\n lightViolet: {\n fill: '#dcccff',\n stroke: '#874fff',\n lightLabel: false,\n transparent: 0.7,\n transparentStroke: '#d5a3ff',\n sectionFill: '#f8f5ff',\n sectionStroke: '#dcccff'\n },\n lightPink: {\n fill: '#ffc2ec',\n stroke: '#f849c1',\n lightLabel: false,\n transparent: 0.5,\n transparentStroke: '#ffaaeb',\n sectionFill: '#fff0fa',\n sectionStroke: '#ffc2ec'\n }\n} as const\n\nexport type FigJamColorName = keyof typeof PALETTE\n\nexport const FIGJAM_COLOR_NAMES = Object.keys(PALETTE) as FigJamColorName[]\n\n/** How a shape's colour fills it: solid, see-through, or not at all, as FigJam's menu sets it. */\nexport type FigJamFillMode = 'fill' | 'transparent' | 'none'\n\n/** How a shape's outline is drawn, as FigJam's line menu sets it. */\nexport type FigJamLineStyle = 'solid' | 'dashed' | 'none'\n\n/** The dash FigJam's line menu draws a shape's outline with. */\nexport const FIGJAM_SHAPE_DASH = [16, 10] as const\n\n/** A palette colour as a colour. */\nexport function figJamColor(name: FigJamColorName): Color {\n return parseColor(PALETTE[name].fill)\n}\n\nfunction sameColor(a: Color | undefined, b: Color): boolean {\n if (!a) return false\n const close = (x: number, y: number) => Math.abs(x - y) < 1 / 512\n return close(a.r, b.r) && close(a.g, b.g) && close(a.b, b.b)\n}\n\n/** The palette colour a paint is, if any. */\nexport function figJamColorName(color: Color | undefined): FigJamColorName | null {\n return FIGJAM_COLOR_NAMES.find((name) => sameColor(color, figJamColor(name))) ?? null\n}\n\n/**\n * The palette colour an outline is drawn in: a colour itself, or the outline a section of that\n * colour takes, which is darker for black and lighter for white.\n */\nexport function figJamOutlineColorName(color: Color | undefined): FigJamColorName | null {\n return (\n figJamColorName(color) ??\n FIGJAM_COLOR_NAMES.find((name) => sameColor(color, parseColor(PALETTE[name].sectionStroke))) ??\n null\n )\n}\n\n/**\n * How FigJam draws a section's title on a board, measured in FigJam: a pill in the colour of the\n * outline drawn on top, with white text on the palette's darkest colours and black on the rest;\n * null for a section without an outline from the palette. `colorOf` reads an outline's colour as\n * drawn, such as a variable's value in the section's mode.\n */\nexport function figJamSectionTitleColors(\n section: Pick<SceneNode, 'strokes'>,\n colorOf: (stroke: Stroke, index: number) => Color = (stroke) => stroke.color\n): { strokeIndex: number; background: Color; lightText: boolean } | null {\n const strokeIndex = section.strokes.findLastIndex(\n (stroke) => stroke.visible && stroke.opacity > 0\n )\n const outline = section.strokes.at(strokeIndex)\n if (strokeIndex === -1 || !outline) return null\n const color = colorOf(outline, strokeIndex)\n const name = figJamOutlineColorName(color)\n if (!name) return null\n return { strokeIndex, background: { ...color, a: 1 }, lightText: PALETTE[name].lightLabel }\n}\n\n/** The fill mode a shape's first fill shows. */\nexport function figJamFillMode(fill: Fill | undefined): FigJamFillMode {\n if (!fill || !fill.visible || fill.opacity === 0) return 'none'\n return fill.opacity < 1 ? 'transparent' : 'fill'\n}\n\n/** The outline FigJam pairs with a colour in a fill mode. */\nexport function figJamPairedStroke(name: FigJamColorName, mode: FigJamFillMode): Color {\n const entry = PALETTE[name]\n return parseColor(mode === 'fill' ? entry.stroke : entry.transparentStroke)\n}\n\n/** The label paint FigJam pairs with a colour in a fill mode. */\nfunction pairedLabel(name: FigJamColorName, mode: FigJamFillMode): Fill {\n const light = PALETTE[name].lightLabel && (mode === 'fill' || name === 'black') && mode !== 'none'\n return light\n ? { type: 'SOLID', color: { ...WHITE }, opacity: 1, visible: true }\n : { type: 'SOLID', color: { ...BLACK }, opacity: 0.8, visible: true }\n}\n\n/** How opaque FigJam fills a colour in a fill mode. */\nfunction fillOpacity(name: FigJamColorName, mode: FigJamFillMode): number {\n if (mode === 'transparent') return PALETTE[name].transparent\n return mode === 'fill' ? 1 : 0\n}\n\n/** What a shape with text and its label become when painted `name` in `mode`. */\nexport interface FigJamShapePaint {\n shape: Partial<SceneNode>\n label: Partial<SceneNode>\n}\n\n/**\n * A shape painted `name` in `mode`, as FigJam's colour menu paints it. The stroke and label follow\n * the colour only while they are still the ones FigJam paired with the current paint: a line or\n * text colour set by hand stays.\n */\nexport function figJamShapePaint(\n shape: Pick<SceneNode, 'fills' | 'strokes'>,\n label: Pick<SceneNode, 'fills'> | null,\n name: FigJamColorName,\n mode: FigJamFillMode\n): FigJamShapePaint {\n const fill = shape.fills.at(0)\n const current = figJamColorName(fill?.color)\n const currentMode = figJamFillMode(fill)\n const opacity = fillOpacity(name, mode)\n const result: FigJamShapePaint = {\n shape: { fills: [{ type: 'SOLID', color: figJamColor(name), opacity, visible: true }] },\n label: {}\n }\n const stroke = shape.strokes.at(0)\n const strokeFollows =\n !stroke || !current || sameColor(stroke.color, figJamPairedStroke(current, currentMode))\n if (stroke && strokeFollows) {\n result.shape.strokes = [\n { ...stroke, color: figJamPairedStroke(name, mode) },\n ...shape.strokes.slice(1)\n ]\n }\n const labelFill = label?.fills.at(0)\n const paired = current ? pairedLabel(current, currentMode) : null\n const labelFollows =\n !labelFill ||\n !paired ||\n (sameColor(labelFill.color, paired.color) &&\n Math.abs(labelFill.opacity - paired.opacity) < 0.01)\n if (label && labelFollows) result.label = { fills: [pairedLabel(name, mode)] }\n return result\n}\n\n/**\n * A shape's outline drawn `style`, as FigJam's line menu draws it; the weight stays. The dash is\n * the layer's, as files keep it, and each stroke's, as it is drawn.\n */\nexport function figJamLineStyleFields(\n shape: Pick<SceneNode, 'strokes'>,\n style: FigJamLineStyle\n): Partial<SceneNode> {\n const dashPattern = style === 'dashed' ? [...FIGJAM_SHAPE_DASH] : []\n const strokes = shape.strokes.map((stroke): Stroke => ({\n ...stroke,\n opacity: style === 'none' ? 0 : 1,\n dashPattern: [...dashPattern]\n }))\n return { strokes, dashPattern }\n}\n\n/** The line style a shape's outline shows. */\nexport function figJamLineStyle(shape: Pick<SceneNode, 'strokes'>): FigJamLineStyle {\n const stroke = shape.strokes.at(0)\n if (!stroke || !stroke.visible || stroke.opacity === 0) return 'none'\n return (stroke.dashPattern?.length ?? 0) > 0 ? 'dashed' : 'solid'\n}\n\n/**\n * A shape's outline in palette colour `name`, as FigJam's line menu colours it; a hidden outline\n * shows again, keeping its dash.\n */\nexport function figJamLineColorFields(\n shape: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const strokes =\n shape.strokes.length > 0\n ? shape.strokes.map((stroke): Stroke => ({ ...stroke, color, opacity: 1 }))\n : [\n {\n type: 'SOLID',\n color,\n opacity: 1,\n visible: true,\n weight: 4,\n align: 'CENTER'\n } satisfies Stroke\n ]\n return { strokes }\n}\n\n/** How heavy FigJam outlines a coloured section, and a coloured layer that had no stroke. */\nconst SECTION_STROKE_WEIGHT = 2\nconst LAYER_STROKE_WEIGHT = 1\n\n/** `strokes` recoloured, or a new stroke of `weight` when there are none. */\nfunction strokesIn(strokes: Stroke[], color: Color, weight: number): Stroke[] {\n if (strokes.length > 0) return strokes.map((stroke) => ({ ...stroke, type: 'SOLID', color }))\n return [{ type: 'SOLID', color, opacity: 1, visible: true, weight, align: 'INSIDE' }]\n}\n\n/** A section painted `name`, as FigJam's colour menu paints one: a pale tint outlined in the colour. */\nexport function figJamSectionColorFields(\n section: Pick<SceneNode, 'strokes'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const { sectionFill, sectionStroke } = PALETTE[name]\n // The outline shows in full at FigJam's 2, as its menu draws it, unless the line menu hid it.\n const strokes = strokesIn(section.strokes, parseColor(sectionStroke), SECTION_STROKE_WEIGHT).map(\n (stroke): Stroke =>\n stroke.opacity === 0\n ? stroke\n : { ...stroke, opacity: 1, visible: true, weight: SECTION_STROKE_WEIGHT }\n )\n return {\n fills: [{ type: 'SOLID', color: parseColor(sectionFill), opacity: 1, visible: true }],\n strokes,\n strokeWeight: SECTION_STROKE_WEIGHT\n }\n}\n\n/**\n * The paint of `paints` the canvas shows on top: the last it draws, skipping hidden and fully\n * transparent ones, which show nothing.\n */\nfunction drawnPaint<P extends Fill>(paints: readonly P[]): P | undefined {\n return paints.findLast((paint) => paint.visible && paint.opacity > 0)\n}\n\n/** The palette colour a section is painted, by its tint. */\nexport function figJamSectionColorName(section: Pick<SceneNode, 'fills'>): FigJamColorName | null {\n const fill = drawnPaint(section.fills)?.color\n return (\n FIGJAM_COLOR_NAMES.find((name) => sameColor(fill, parseColor(PALETTE[name].sectionFill))) ??\n null\n )\n}\n\n/**\n * Whether a layer takes a palette colour as its stroke alone: a line, or a pen stroke, which is a\n * vector with nothing filled. A filled vector takes it as any other layer does.\n */\nfunction colorsStroke(node: Pick<SceneNode, 'type' | 'fills'>): boolean {\n if (node.type === 'LINE') return true\n return node.type === 'VECTOR' && !drawnPaint(node.fills)\n}\n\n/**\n * A plain layer painted `name`, as FigJam's colour menu paints one: text takes it as its fill, a\n * line or a pen stroke as its stroke, and any other layer as its fill and a stroke of the same\n * colour.\n */\nexport function figJamLayerColorFields(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes' | 'styleRuns'>,\n name: FigJamColorName\n): Partial<SceneNode> {\n const color = figJamColor(name)\n const fills: Fill[] = [{ type: 'SOLID', color, opacity: 1, visible: true }]\n if (node.type === 'TEXT') {\n // The whole text takes the colour, ranges coloured on their own included.\n const styleRuns = node.styleRuns.map((run) => ({\n ...run,\n style: omit(run.style, ['fills', 'fillStyleId'])\n }))\n return { fills, styleRuns }\n }\n const strokes = strokesIn(node.strokes, color, LAYER_STROKE_WEIGHT)\n return colorsStroke(node) ? { strokes } : { fills, strokes }\n}\n\n/** The palette colour a plain layer shows, read where {@link figJamLayerColorFields} paints it. */\nexport function figJamLayerColorName(\n node: Pick<SceneNode, 'type' | 'fills' | 'strokes'>\n): FigJamColorName | null {\n const paints: Fill[] = colorsStroke(node) ? node.strokes : node.fills\n return figJamColorName(drawnPaint(paints)?.color)\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,UAAU;CACd,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,UAAU;EACR,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,KAAK;EACH,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,QAAQ;EACN,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,OAAO;EACL,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,aAAa;EACb,eAAe;CACjB;CACA,MAAM;EACJ,MAAM;EACN,QAAQ;EACR,YAAY;EACZ,aAAa;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WAAW;GAAG,SAAS;GAAG,SAAS;EAAK,CAAC;EACpF;EACA,cAAc;CAChB;AACF;;;;;AAMA,SAAS,WAA2B,QAAqC;CACvE,OAAO,OAAO,UAAU,UAAU,MAAM,WAAW,MAAM,UAAU,CAAC;AACtE;;AAGA,SAAgB,uBAAuB,SAA2D;CAChG,MAAM,OAAO,WAAW,QAAQ,KAAK,CAAC,EAAE;CACxC,OACE,mBAAmB,MAAM,SAAS,UAAU,MAAM,WAAW,QAAQ,KAAK,CAAC,WAAW,CAAC,CAAC,KACxF;AAEJ;;;;;AAMA,SAAS,aAAa,MAAkD;CACtE,IAAI,KAAK,SAAS,QAAQ,OAAO;CACjC,OAAO,KAAK,SAAS,YAAY,CAAC,WAAW,KAAK,KAAK;AACzD;;;;;;AAOA,SAAgB,uBACd,MACA,MACoB;CACpB,MAAM,QAAQ,YAAY,IAAI;CAC9B,MAAM,QAAgB,CAAC;EAAE,MAAM;EAAS;EAAO,SAAS;EAAG,SAAS;CAAK,CAAC;CAC1E,IAAI,KAAK,SAAS,QAMhB,OAAO;EAAE;EAAO,WAJE,KAAK,UAAU,KAAK,SAAS;GAC7C,GAAG;GACH,OAAO,KAAK,IAAI,OAAO,CAAC,SAAS,aAAa,CAAC;EACjD,EACwB;CAAE;CAE5B,MAAM,UAAU,UAAU,KAAK,SAAS,OAAO,mBAAmB;CAClE,OAAO,aAAa,IAAI,IAAI,EAAE,QAAQ,IAAI;EAAE;EAAO;CAAQ;AAC7D;;AAGA,SAAgB,qBACd,MACwB;CAExB,OAAO,gBAAgB,WADA,aAAa,IAAI,IAAI,KAAK,UAAU,KAAK,KACxB,CAAC,EAAE,KAAK;AAClD"}
@@ -20,6 +20,8 @@ interface VisualBounds {
20
20
  maxX: number;
21
21
  maxY: number;
22
22
  }
23
+ /** `bounds` as a rect at its top-left corner. */
24
+ declare function visualBoundsToRect(bounds: VisualBounds): Rect;
23
25
  declare function computeBounds(items: Iterable<Rect>): Rect;
24
26
  declare function polygonVertices(node: {
25
27
  width: number;
@@ -43,6 +45,11 @@ declare function strokeOverflow(strokes?: Stroke[], fallbackCap?: StrokeCap, net
43
45
  * blur, though the layer keeps the value.
44
46
  */
45
47
  declare function drawnBlurRadius(radius: number): number;
48
+ /**
49
+ * The widest radius an effect blurs by: its radius, or the larger end of a progressive blur,
50
+ * which can start wider than it ends. Bounds and padding that must hold the whole blur use it.
51
+ */
52
+ declare function widestBlurRadius(effect: Pick<Effect, 'radius' | 'progressive'>): number;
46
53
  /**
47
54
  * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
48
55
  * layer blur, both shadows, and background blur fall off as a Gaussian of 0.43 × radius; Figma's
@@ -85,5 +92,5 @@ declare function geometryBlobBounds(paths: Array<{
85
92
  /** How far a text node's underline or strikethrough reaches below its box. */
86
93
  declare function textDecorationOverflow(node: Pick<SceneNode, 'type' | 'fontSize' | 'textDecoration' | 'textUnderlineOffset' | 'textDecorationThickness'>): number;
87
94
  //#endregion
88
- export { GeometryCommand, StrokeShape, VisualBounds, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
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 };
89
96
  //# sourceMappingURL=geometry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","names":[],"sources":["../src/geometry.ts"],"mappings":";;;;iBAMgB,SAAS;iBAIT,SAAS;iBAIT,YAAY,YAAY,YA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U,sBACV,QAAQ;;;;;iBAmEM,gBAAgB;;;;;iBAQhB,iBAAiB,QAAQ,KAAK;;;;;;iBAW9B,UAAU;;iBAKV,mBAAmB;iBAInB,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
@@ -82,18 +82,22 @@ function includeRect(bounds, rect) {
82
82
  includePoint(bounds, rect.x, rect.y);
83
83
  includePoint(bounds, rect.x + rect.width, rect.y + rect.height);
84
84
  }
85
+ /** `bounds` as a rect at its top-left corner. */
86
+ function visualBoundsToRect(bounds) {
87
+ return {
88
+ x: bounds.minX,
89
+ y: bounds.minY,
90
+ width: bounds.maxX - bounds.minX,
91
+ height: bounds.maxY - bounds.minY
92
+ };
93
+ }
85
94
  function boundsToRect(bounds) {
86
95
  return bounds.minX === Infinity ? {
87
96
  x: 0,
88
97
  y: 0,
89
98
  width: 0,
90
99
  height: 0
91
- } : {
92
- x: bounds.minX,
93
- y: bounds.minY,
94
- width: bounds.maxX - bounds.minX,
95
- height: bounds.maxY - bounds.minY
96
- };
100
+ } : visualBoundsToRect(bounds);
97
101
  }
98
102
  function computeBounds(items) {
99
103
  const bounds = createBoundsAccumulator();
@@ -179,6 +183,13 @@ function miterRatio(network, join, limit = 4) {
179
183
  function drawnBlurRadius(radius) {
180
184
  return Math.max(0, radius);
181
185
  }
186
+ /**
187
+ * The widest radius an effect blurs by: its radius, or the larger end of a progressive blur,
188
+ * which can start wider than it ends. Bounds and padding that must hold the whole blur use it.
189
+ */
190
+ function widestBlurRadius(effect) {
191
+ return Math.max(effect.radius, effect.progressive?.startRadius ?? effect.radius);
192
+ }
182
193
  const BLUR_SIGMA_PER_RADIUS = .43;
183
194
  /**
184
195
  * The Gaussian sigma that draws a Figma blur radius as Figma does. Measured on Figma 126 exports,
@@ -200,7 +211,7 @@ function effectOverflow(effects) {
200
211
  for (const effect of effects ?? []) {
201
212
  if (!effect.visible) continue;
202
213
  if (effect.type !== "DROP_SHADOW" && effect.type !== "LAYER_BLUR" && effect.type !== "FOREGROUND_BLUR") continue;
203
- const blurSpread = drawnBlurRadius(effect.radius) + effect.spread;
214
+ const blurSpread = drawnBlurRadius(widestBlurRadius(effect)) + effect.spread;
204
215
  left = Math.max(left, blurSpread + Math.max(0, -effect.offset.x));
205
216
  right = Math.max(right, blurSpread + Math.max(0, effect.offset.x));
206
217
  top = Math.max(top, blurSpread + Math.max(0, -effect.offset.y));
@@ -301,6 +312,6 @@ function textDecorationOverflow(node) {
301
312
  return (node.textUnderlineOffset ?? fontSize * .18) + (node.textDecorationThickness ?? Math.max(1, fontSize / 16)) + fontSize * .35;
302
313
  }
303
314
  //#endregion
304
- export { GeometryCommand, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds };
315
+ export { GeometryCommand, blurRadiusForSigma, blurSigma, computeAbsoluteBounds, computeBounds, cubicPoint, degToRad, drawnBlurRadius, effectOverflow, geometryBlobBounds, intersectVisualBounds, polygonVertices, radToDeg, readGeometryBlob, rotatePoint, rotatedBBox, rotatedCorners, strokeOverflow, textDecorationOverflow, unionVisualBounds, visualBoundsToRect, widestBlurRadius };
305
316
 
306
317
  //# sourceMappingURL=geometry.js.map
@@ -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\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\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\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(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\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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AK,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"}
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,OAAO;EACL;GAAE,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC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I,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/graph.d.ts CHANGED
@@ -4,7 +4,6 @@ import { NodeCloneMode } from "./copy.js";
4
4
  import { DropTargetOptions, SelectableHitOptions } from "./hit-test.js";
5
5
  import { SwapInstanceOptions } from "./instances/index.js";
6
6
  import { NodePreviewObserver } from "./preview.js";
7
- import { VariableModeFallback } from "./variables/resolution.js";
8
7
  import { DocumentColorSpace, DocumentKind, EnabledLibraryBinding, NodeChangeObserver, NodeType, SceneGraphEventHandlers, SceneNode, Variable, VariableCollection, VariableLiteral, VariableType, VariableValue } from "./types.js";
9
8
  //#region src/graph.d.ts
10
9
  declare class SceneGraph {
@@ -13,7 +12,6 @@ declare class SceneGraph {
13
12
  images: Map<string, Uint8Array<ArrayBufferLike>>;
14
13
  variables: Map<string, Variable>;
15
14
  variableCollections: Map<string, VariableCollection>;
16
- activeMode: Map<string, string>;
17
15
  rootId: string;
18
16
  figKiwiVersion: number | null;
19
17
  /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */
@@ -26,6 +24,9 @@ declare class SceneGraph {
26
24
  private readonly scopeDepths;
27
25
  private previewObservers;
28
26
  private readonly changeObservers;
27
+ /** How many waits outside the edit each recorder is paused for. */
28
+ private readonly outsideWaits;
29
+ private outsideWrites;
29
30
  private importedIdGenerator;
30
31
  private layoutWrites;
31
32
  positionPreviewVersion: number;
@@ -39,14 +40,42 @@ declare class SceneGraph {
39
40
  getNode(id: string): SceneNode | undefined;
40
41
  onNodeEvents(handlers: SceneGraphEventHandlers): () => void;
41
42
  /**
42
- * Tells `observer` about each node an edit adds and, before it changes, each node it is about
43
- * to change, so a recorder can keep the node as it was. Unlike node events these are never
44
- * buffered. Graph methods report the nodes they change; code that writes into a node directly
45
- * reports it with `willChangeNode` first.
43
+ * Tells `observer` about each node an edit adds and, before it changes, each node, variable,
44
+ * and collection it is about to change, so a recorder can keep it as it was. Unlike node events
45
+ * these are never buffered. Graph methods report what they change; code that writes into a
46
+ * node, variable, or collection directly reports it with `willChangeNode`,
47
+ * `willChangeVariable`, or `willChangeCollection` first.
46
48
  */
47
49
  observeNodeChanges(observer: NodeChangeObserver): () => void;
50
+ /**
51
+ * Waits for `promise`, such as a font or an image download an edit needs, outside the edit in
52
+ * progress: what changes meanwhile, such as the user's or a collaborator's edit, is not recorded
53
+ * as the waiting edit's. Only for code that writes nothing itself until the wait ends.
54
+ */
55
+ waitOutsideEdit<T>(promise: Promise<T>): Promise<T>;
56
+ /**
57
+ * Runs `write`, a change someone else makes, such as a collaborator's arriving or an undo,
58
+ * outside every edit in progress, so none records it as its own.
59
+ */
60
+ runOutsideEdits<T>(write: () => T): T;
61
+ /** Whether a write run with `runOutsideEdits`, such as a collaborator's change, is in progress. */
62
+ get isWritingOutsideEdits(): boolean;
63
+ /**
64
+ * Pauses the recorders open now, and only those, until the returned function resumes them: a
65
+ * recorder that opens while an earlier pause is still pending, such as during a script's load
66
+ * left unawaited, pauses for its own waits and is not resumed by the earlier one.
67
+ */
68
+ private pauseOpenEdits;
48
69
  /** Tells `observeNodeChanges` observers that `node` is about to change. */
49
70
  willChangeNode(node: SceneNode | undefined): void;
71
+ /**
72
+ * Tells `observeNodeChanges` observers that the variable `id` is about to change, be added, or
73
+ * be removed. Graph methods report the variables they change; code that writes into one
74
+ * directly reports it first.
75
+ */
76
+ willChangeVariable(id: string): void;
77
+ /** As `willChangeVariable`, for the collection `id`. */
78
+ willChangeCollection(id: string): void;
50
79
  countDescendants(nodeId: string): number;
51
80
  addVariable(variable: Variable): void;
52
81
  removeVariable(id: string): void;
@@ -55,9 +84,7 @@ declare class SceneGraph {
55
84
  createCollection(name: string): VariableCollection;
56
85
  createMode(collectionId: string, name: string, sourceModeId?: string): string | undefined;
57
86
  removeCollection(id: string): void;
58
- getActiveModeId(collectionId: string): string;
59
87
  getNodeVariableModeId(nodeId: string, collectionId: string): string;
60
- setActiveMode(collectionId: string, modeId: string): void;
61
88
  addMode(collectionId: string, modeId: string, name: string, sourceMode?: string): void;
62
89
  removeMode(collectionId: string, modeId: string): void;
63
90
  renameMode(collectionId: string, modeId: string, name: string): void;
@@ -65,10 +92,10 @@ declare class SceneGraph {
65
92
  resolveVariable(variableId: string, modeId?: string, visited?: Set<string>): VariableLiteral | undefined;
66
93
  resolveColorVariable(variableId: string): Color | undefined;
67
94
  resolveNumberVariable(variableId: string): number | undefined;
68
- resolveColorVariableForNode(nodeId: string, variableId: string, fallback?: VariableModeFallback): Color | undefined;
69
- resolveNumberVariableForNode(nodeId: string, variableId: string, fallback?: VariableModeFallback): number | undefined;
70
- resolveVariableForNode(nodeId: string, variableId: string, fallback?: VariableModeFallback): VariableLiteral | undefined;
71
- resolveStringVariableForNode(nodeId: string, variableId: string, fallback?: VariableModeFallback): string | undefined;
95
+ resolveColorVariableForNode(nodeId: string, variableId: string): Color | undefined;
96
+ resolveNumberVariableForNode(nodeId: string, variableId: string): number | undefined;
97
+ resolveVariableForNode(nodeId: string, variableId: string): VariableLiteral | undefined;
98
+ resolveStringVariableForNode(nodeId: string, variableId: string): string | undefined;
72
99
  getVariablesForCollection(collectionId: string): Variable[];
73
100
  getVariablesByType(type: VariableType): Variable[];
74
101
  bindVariable(nodeId: string, field: string, variableId: string): void;
@@ -116,6 +143,13 @@ declare class SceneGraph {
116
143
  * arrive. What this writes derives from the document; an edit's own layout is not this.
117
144
  */
118
145
  applyDerivedLayoutDuring(fn: () => void): void;
146
+ /**
147
+ * Runs `fn` as values a copy takes from its component, such as the bound paints of a layer an
148
+ * instance copies, refreshed for it. Source metadata is preserved, and a save leaves them to the
149
+ * component rather than writing them as edits of the copy.
150
+ */
151
+ applyComponentDerivedDuring(fn: () => void): void;
152
+ get isApplyingComponentDerived(): boolean;
119
153
  get isApplyingDerivedLayout(): boolean;
120
154
  /**
121
155
  * Runs `fn` as layout. Its updates are published once the outermost layout ends, still as
@@ -137,6 +171,8 @@ declare class SceneGraph {
137
171
  /** Replay captured properties without dropping explicit undefined values or absent keys. */
138
172
  restoreNodeProperties(id: string, changes: Partial<SceneNode>, absent: readonly (keyof SceneNode)[]): void;
139
173
  private applyNodeChanges;
174
+ /** Bindings of paints and effects a write sets follow the lists it wrote. */
175
+ private followListBindings;
140
176
  /** Marks fields an edit changed, unless metadata is being restored or layout is writing them. */
141
177
  private markEdited;
142
178
  /** Publishes an update now, or leaves it to the running layout, which publishes once it ends. */
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","names":[],"sources":["../src/graph.ts"],"mappings":";;;;;;;;;cAkDa;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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