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

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 (345) hide show
  1. package/dist/buffered-events.js +1 -1
  2. package/dist/buffered-events.js.map +1 -1
  3. package/dist/clipping.d.ts +7 -1
  4. package/dist/clipping.d.ts.map +1 -1
  5. package/dist/clipping.js +23 -19
  6. package/dist/clipping.js.map +1 -1
  7. package/dist/comments/schema.d.ts.map +1 -1
  8. package/dist/comments/schema.js +1 -0
  9. package/dist/comments/schema.js.map +1 -1
  10. package/dist/comments/threads.d.ts +2 -0
  11. package/dist/comments/threads.d.ts.map +1 -1
  12. package/dist/comments/threads.js +11 -5
  13. package/dist/comments/threads.js.map +1 -1
  14. package/dist/components/index.d.ts +2 -2
  15. package/dist/components/index.js +2 -2
  16. package/dist/components/properties.d.ts +1 -3
  17. package/dist/components/properties.d.ts.map +1 -1
  18. package/dist/components/properties.js +3 -10
  19. package/dist/components/properties.js.map +1 -1
  20. package/dist/constants.d.ts +12 -2
  21. package/dist/constants.d.ts.map +1 -1
  22. package/dist/constants.js +42 -1
  23. package/dist/constants.js.map +1 -1
  24. package/dist/copy.d.ts.map +1 -1
  25. package/dist/copy.js +2 -0
  26. package/dist/copy.js.map +1 -1
  27. package/dist/corners.d.ts +22 -0
  28. package/dist/corners.d.ts.map +1 -0
  29. package/dist/corners.js +52 -0
  30. package/dist/corners.js.map +1 -0
  31. package/dist/css/grid.d.ts +4 -1
  32. package/dist/css/grid.d.ts.map +1 -1
  33. package/dist/css/grid.js +40 -7
  34. package/dist/css/grid.js.map +1 -1
  35. package/dist/css/index.d.ts +3 -3
  36. package/dist/css/index.js +3 -3
  37. package/dist/css/layout.d.ts +13 -1
  38. package/dist/css/layout.d.ts.map +1 -1
  39. package/dist/css/layout.js +26 -1
  40. package/dist/css/layout.js.map +1 -1
  41. package/dist/css/values.d.ts +23 -1
  42. package/dist/css/values.d.ts.map +1 -1
  43. package/dist/css/values.js +39 -1
  44. package/dist/css/values.js.map +1 -1
  45. package/dist/font-style.d.ts +2 -1
  46. package/dist/font-style.d.ts.map +1 -1
  47. package/dist/font-style.js +31 -6
  48. package/dist/font-style.js.map +1 -1
  49. package/dist/geometry.d.ts +68 -3
  50. package/dist/geometry.d.ts.map +1 -1
  51. package/dist/geometry.js +159 -25
  52. package/dist/geometry.js.map +1 -1
  53. package/dist/gradient.d.ts +9 -2
  54. package/dist/gradient.d.ts.map +1 -1
  55. package/dist/gradient.js +29 -1
  56. package/dist/gradient.js.map +1 -1
  57. package/dist/graph.d.ts +9 -2
  58. package/dist/graph.d.ts.map +1 -1
  59. package/dist/graph.js +46 -10
  60. package/dist/graph.js.map +1 -1
  61. package/dist/group-bounds.d.ts.map +1 -1
  62. package/dist/group-bounds.js +4 -3
  63. package/dist/group-bounds.js.map +1 -1
  64. package/dist/guides.d.ts +11 -2
  65. package/dist/guides.d.ts.map +1 -1
  66. package/dist/guides.js +30 -1
  67. package/dist/guides.js.map +1 -1
  68. package/dist/hit-test.d.ts.map +1 -1
  69. package/dist/hit-test.js +57 -5
  70. package/dist/hit-test.js.map +1 -1
  71. package/dist/icons/fit.d.ts +17 -0
  72. package/dist/icons/fit.d.ts.map +1 -0
  73. package/dist/icons/fit.js +21 -0
  74. package/dist/icons/fit.js.map +1 -0
  75. package/dist/icons/glyph.d.ts.map +1 -1
  76. package/dist/icons/glyph.js +5 -4
  77. package/dist/icons/glyph.js.map +1 -1
  78. package/dist/icons/index.d.ts +2 -1
  79. package/dist/icons/index.js +2 -1
  80. package/dist/ids.js +1 -1
  81. package/dist/ids.js.map +1 -1
  82. package/dist/images.d.ts +14 -4
  83. package/dist/images.d.ts.map +1 -1
  84. package/dist/images.js +45 -5
  85. package/dist/images.js.map +1 -1
  86. package/dist/index.d.ts +2 -2
  87. package/dist/instances/assignments.js +39 -6
  88. package/dist/instances/assignments.js.map +1 -1
  89. package/dist/instances/index.d.ts +6 -1
  90. package/dist/instances/index.d.ts.map +1 -1
  91. package/dist/instances/index.js +58 -9
  92. package/dist/instances/index.js.map +1 -1
  93. package/dist/instances/kept-overrides.js +2 -2
  94. package/dist/instances/kept-overrides.js.map +1 -1
  95. package/dist/instances/matching.js +68 -0
  96. package/dist/instances/matching.js.map +1 -0
  97. package/dist/instances/overrides.d.ts +4 -1
  98. package/dist/instances/overrides.d.ts.map +1 -1
  99. package/dist/instances/overrides.js +13 -1
  100. package/dist/instances/overrides.js.map +1 -1
  101. package/dist/instances/protection.js +67 -0
  102. package/dist/instances/protection.js.map +1 -0
  103. package/dist/instances/swap.js +7 -5
  104. package/dist/instances/swap.js.map +1 -1
  105. package/dist/instances/sync.js +34 -116
  106. package/dist/instances/sync.js.map +1 -1
  107. package/dist/layout/guides.d.ts +17 -1
  108. package/dist/layout/guides.d.ts.map +1 -1
  109. package/dist/layout/guides.js +31 -11
  110. package/dist/layout/guides.js.map +1 -1
  111. package/dist/layout/index.d.ts +5 -2
  112. package/dist/layout/index.js +5 -2
  113. package/dist/layout/limits.d.ts +40 -0
  114. package/dist/layout/limits.d.ts.map +1 -0
  115. package/dist/layout/limits.js +54 -0
  116. package/dist/layout/limits.js.map +1 -0
  117. package/dist/layout/sizing.d.ts.map +1 -1
  118. package/dist/layout/sizing.js +0 -1
  119. package/dist/layout/sizing.js.map +1 -1
  120. package/dist/layout/spacing.d.ts +10 -0
  121. package/dist/layout/spacing.d.ts.map +1 -0
  122. package/dist/layout/spacing.js +12 -0
  123. package/dist/layout/spacing.js.map +1 -0
  124. package/dist/layout/strokes.d.ts +10 -0
  125. package/dist/layout/strokes.d.ts.map +1 -0
  126. package/dist/layout/strokes.js +30 -0
  127. package/dist/layout/strokes.js.map +1 -0
  128. package/dist/masks.d.ts +28 -0
  129. package/dist/masks.d.ts.map +1 -0
  130. package/dist/masks.js +53 -0
  131. package/dist/masks.js.map +1 -0
  132. package/dist/matrix.d.ts +2 -1
  133. package/dist/matrix.d.ts.map +1 -1
  134. package/dist/matrix.js +14 -1
  135. package/dist/matrix.js.map +1 -1
  136. package/dist/node-defaults.d.ts +9 -1
  137. package/dist/node-defaults.d.ts.map +1 -1
  138. package/dist/node-defaults.js +65 -38
  139. package/dist/node-defaults.js.map +1 -1
  140. package/dist/outline/flatten.d.ts.map +1 -1
  141. package/dist/outline/flatten.js +24 -17
  142. package/dist/outline/flatten.js.map +1 -1
  143. package/dist/outline/hit.d.ts +2 -8
  144. package/dist/outline/hit.d.ts.map +1 -1
  145. package/dist/outline/hit.js +16 -25
  146. package/dist/outline/hit.js.map +1 -1
  147. package/dist/outline/index.d.ts +3 -3
  148. package/dist/outline/index.js +3 -3
  149. package/dist/outline/shapes.d.ts +3 -1
  150. package/dist/outline/shapes.d.ts.map +1 -1
  151. package/dist/outline/shapes.js +18 -39
  152. package/dist/outline/shapes.js.map +1 -1
  153. package/dist/paints/index.d.ts +3 -1
  154. package/dist/paints/index.js +3 -1
  155. package/dist/paints/pattern.d.ts +13 -0
  156. package/dist/paints/pattern.d.ts.map +1 -0
  157. package/dist/paints/pattern.js +47 -0
  158. package/dist/paints/pattern.js.map +1 -0
  159. package/dist/paints/shows.d.ts +11 -0
  160. package/dist/paints/shows.d.ts.map +1 -0
  161. package/dist/paints/shows.js +16 -0
  162. package/dist/paints/shows.js.map +1 -0
  163. package/dist/parse-path.d.ts +4 -1
  164. package/dist/parse-path.d.ts.map +1 -1
  165. package/dist/parse-path.js +15 -1
  166. package/dist/parse-path.js.map +1 -1
  167. package/dist/paths/arc.d.ts +32 -0
  168. package/dist/paths/arc.d.ts.map +1 -0
  169. package/dist/paths/arc.js +49 -0
  170. package/dist/paths/arc.js.map +1 -0
  171. package/dist/paths/index.d.ts +5 -0
  172. package/dist/paths/index.js +5 -0
  173. package/dist/paths/network.d.ts +63 -0
  174. package/dist/paths/network.d.ts.map +1 -0
  175. package/dist/paths/network.js +315 -0
  176. package/dist/paths/network.js.map +1 -0
  177. package/dist/paths/sink.d.ts +20 -0
  178. package/dist/paths/sink.d.ts.map +1 -0
  179. package/dist/paths/sink.js +32 -0
  180. package/dist/paths/sink.js.map +1 -0
  181. package/dist/paths/smooth-corners.d.ts +25 -0
  182. package/dist/paths/smooth-corners.d.ts.map +1 -0
  183. package/dist/paths/smooth-corners.js +196 -0
  184. package/dist/paths/smooth-corners.js.map +1 -0
  185. package/dist/plugin-data/fields.d.ts +4 -0
  186. package/dist/plugin-data/fields.d.ts.map +1 -1
  187. package/dist/plugin-data/fields.js +2 -0
  188. package/dist/plugin-data/fields.js.map +1 -1
  189. package/dist/polygon.d.ts +1 -3
  190. package/dist/polygon.d.ts.map +1 -1
  191. package/dist/polygon.js +1 -16
  192. package/dist/polygon.js.map +1 -1
  193. package/dist/primitives/index.d.ts +1 -7
  194. package/dist/primitives/index.d.ts.map +1 -1
  195. package/dist/resize.d.ts.map +1 -1
  196. package/dist/resize.js +5 -5
  197. package/dist/resize.js.map +1 -1
  198. package/dist/scaling/node.d.ts.map +1 -1
  199. package/dist/scaling/node.js +25 -3
  200. package/dist/scaling/node.js.map +1 -1
  201. package/dist/shaders/model.d.ts.map +1 -1
  202. package/dist/shaders/model.js +1 -1
  203. package/dist/shaders/model.js.map +1 -1
  204. package/dist/shared-styles.d.ts.map +1 -1
  205. package/dist/shared-styles.js +2 -9
  206. package/dist/shared-styles.js.map +1 -1
  207. package/dist/strokes.d.ts +39 -0
  208. package/dist/strokes.d.ts.map +1 -0
  209. package/dist/strokes.js +104 -0
  210. package/dist/strokes.js.map +1 -0
  211. package/dist/text/auto-resize.d.ts +15 -0
  212. package/dist/text/auto-resize.d.ts.map +1 -0
  213. package/dist/text/auto-resize.js +23 -0
  214. package/dist/text/auto-resize.js.map +1 -0
  215. package/dist/text/index.d.ts +5 -3
  216. package/dist/text/index.js +5 -3
  217. package/dist/text/lengths.d.ts +6 -1
  218. package/dist/text/lengths.d.ts.map +1 -1
  219. package/dist/text/lengths.js +10 -1
  220. package/dist/text/lengths.js.map +1 -1
  221. package/dist/text/overflow.d.ts +14 -5
  222. package/dist/text/overflow.d.ts.map +1 -1
  223. package/dist/text/overflow.js +24 -6
  224. package/dist/text/overflow.js.map +1 -1
  225. package/dist/text/path.js +10 -0
  226. package/dist/text/path.js.map +1 -0
  227. package/dist/text/picture.js +5 -5
  228. package/dist/text/picture.js.map +1 -1
  229. package/dist/text/runs.d.ts +29 -0
  230. package/dist/text/runs.d.ts.map +1 -0
  231. package/dist/text/runs.js +72 -0
  232. package/dist/text/runs.js.map +1 -0
  233. package/dist/transfer/dependencies.d.ts.map +1 -1
  234. package/dist/transfer/dependencies.js +3 -2
  235. package/dist/transfer/dependencies.js.map +1 -1
  236. package/dist/transfer/nodes.js +2 -1
  237. package/dist/transfer/nodes.js.map +1 -1
  238. package/dist/types.d.ts +56 -10
  239. package/dist/types.d.ts.map +1 -1
  240. package/dist/types.js.map +1 -1
  241. package/dist/variables/index.d.ts +4 -3
  242. package/dist/variables/index.d.ts.map +1 -1
  243. package/dist/variables/index.js +4 -3
  244. package/dist/variables/index.js.map +1 -1
  245. package/dist/variables/lookup.d.ts +20 -0
  246. package/dist/variables/lookup.d.ts.map +1 -0
  247. package/dist/variables/lookup.js +34 -0
  248. package/dist/variables/lookup.js.map +1 -0
  249. package/dist/variables/paints.d.ts +35 -4
  250. package/dist/variables/paints.d.ts.map +1 -1
  251. package/dist/variables/paints.js +67 -16
  252. package/dist/variables/paints.js.map +1 -1
  253. package/dist/variables/resolution.d.ts +3 -1
  254. package/dist/variables/resolution.d.ts.map +1 -1
  255. package/dist/variables/resolution.js +8 -3
  256. package/dist/variables/resolution.js.map +1 -1
  257. package/dist/variables/subtree.js +1 -1
  258. package/dist/variables/subtree.js.map +1 -1
  259. package/dist/vector-network.d.ts.map +1 -1
  260. package/dist/vector-network.js +13 -79
  261. package/dist/vector-network.js.map +1 -1
  262. package/package.json +28 -7
  263. package/src/buffered-events.ts +2 -1
  264. package/src/clipping.ts +11 -8
  265. package/src/comments/schema.ts +1 -0
  266. package/src/comments/threads.ts +13 -5
  267. package/src/components/properties.ts +3 -14
  268. package/src/constants.ts +25 -1
  269. package/src/copy.ts +2 -0
  270. package/src/corners.ts +93 -0
  271. package/src/css/grid.ts +49 -7
  272. package/src/css/index.ts +13 -2
  273. package/src/css/layout.ts +36 -0
  274. package/src/css/values.ts +49 -0
  275. package/src/font-style.ts +38 -4
  276. package/src/geometry.ts +223 -28
  277. package/src/gradient.ts +23 -1
  278. package/src/graph.ts +35 -10
  279. package/src/group-bounds.ts +7 -3
  280. package/src/guides.ts +26 -1
  281. package/src/hit-test.ts +68 -10
  282. package/src/icons/fit.ts +24 -0
  283. package/src/icons/glyph.ts +6 -4
  284. package/src/icons/index.ts +1 -0
  285. package/src/ids.ts +1 -1
  286. package/src/images.ts +67 -7
  287. package/src/instances/assignments.ts +65 -7
  288. package/src/instances/index.ts +77 -13
  289. package/src/instances/kept-overrides.ts +2 -5
  290. package/src/instances/matching.ts +101 -0
  291. package/src/instances/overrides.ts +18 -0
  292. package/src/instances/protection.ts +103 -0
  293. package/src/instances/swap.ts +12 -9
  294. package/src/instances/sync.ts +52 -184
  295. package/src/layout/guides.ts +42 -9
  296. package/src/layout/index.ts +3 -0
  297. package/src/layout/limits.ts +64 -0
  298. package/src/layout/sizing.ts +0 -2
  299. package/src/layout/spacing.ts +11 -0
  300. package/src/layout/strokes.ts +23 -0
  301. package/src/masks.ts +51 -0
  302. package/src/matrix.ts +15 -2
  303. package/src/node-defaults.ts +71 -36
  304. package/src/outline/flatten.ts +31 -18
  305. package/src/outline/hit.ts +16 -33
  306. package/src/outline/index.ts +2 -2
  307. package/src/outline/shapes.ts +19 -36
  308. package/src/paints/index.ts +2 -0
  309. package/src/paints/pattern.ts +45 -0
  310. package/src/paints/shows.ts +13 -0
  311. package/src/parse-path.ts +14 -0
  312. package/src/paths/arc.ts +59 -0
  313. package/src/paths/index.ts +4 -0
  314. package/src/paths/network.ts +411 -0
  315. package/src/paths/sink.ts +50 -0
  316. package/src/paths/smooth-corners.ts +357 -0
  317. package/src/plugin-data/fields.ts +2 -0
  318. package/src/polygon.ts +0 -17
  319. package/src/primitives/index.ts +0 -5
  320. package/src/resize.ts +6 -7
  321. package/src/scaling/node.ts +29 -3
  322. package/src/shaders/model.ts +2 -1
  323. package/src/shared-styles.ts +3 -4
  324. package/src/strokes.ts +121 -0
  325. package/src/text/auto-resize.ts +25 -0
  326. package/src/text/index.ts +2 -0
  327. package/src/text/lengths.ts +11 -0
  328. package/src/text/overflow.ts +32 -6
  329. package/src/text/path.ts +13 -0
  330. package/src/text/picture.ts +5 -5
  331. package/src/text/runs.ts +80 -0
  332. package/src/transfer/dependencies.ts +4 -2
  333. package/src/transfer/nodes.ts +2 -1
  334. package/src/types.ts +62 -8
  335. package/src/variables/index.ts +1 -0
  336. package/src/variables/lookup.ts +31 -0
  337. package/src/variables/paints.ts +101 -20
  338. package/src/variables/resolution.ts +15 -2
  339. package/src/variables/subtree.ts +1 -1
  340. package/src/vector-network.ts +19 -142
  341. package/dist/random.d.ts +0 -7
  342. package/dist/random.d.ts.map +0 -1
  343. package/dist/random.js +0 -25
  344. package/dist/random.js.map +0 -1
  345. package/src/random.ts +0 -28
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-resize.js","names":[],"sources":["../../src/text/auto-resize.ts"],"sourcesContent":["import type { SceneNode, TextAutoResize } from '../types'\n\n/** A text's resizing as Figma's plugin API names it, where `TRUNCATE` is a fixed box that truncates. */\nexport type FigmaTextAutoResize = TextAutoResize | 'TRUNCATE'\n\ntype TextResizeFields = Pick<SceneNode, 'textAutoResize' | 'textTruncation' | 'maxLines'>\n\n/** The resizing Figma's plugin API reads for a text: a fixed box that truncates reads `TRUNCATE`. */\nexport function figmaTextAutoResize(\n node: Pick<SceneNode, 'textAutoResize' | 'textTruncation'>\n): FigmaTextAutoResize {\n return node.textAutoResize === 'NONE' && node.textTruncation === 'ENDING'\n ? 'TRUNCATE'\n : node.textAutoResize\n}\n\n/**\n * The fields setting a resizing writes, as Figma's setter does: `TRUNCATE` fixes the box and\n * truncates its end with no line limit, and any other mode stops truncating.\n */\nexport function textAutoResizeFields(mode: FigmaTextAutoResize): Partial<TextResizeFields> {\n return mode === 'TRUNCATE'\n ? { textAutoResize: 'NONE', textTruncation: 'ENDING', maxLines: null }\n : { textAutoResize: mode, textTruncation: 'DISABLED' }\n}\n"],"mappings":";;AAQA,SAAgB,oBACd,MACqB;CACrB,OAAO,KAAK,mBAAmB,UAAU,KAAK,mBAAmB,WAC7D,aACA,KAAK;AACX;;;;;AAMA,SAAgB,qBAAqB,MAAsD;CACzF,OAAO,SAAS,aACZ;EAAE,gBAAgB;EAAQ,gBAAgB;EAAU,UAAU;CAAK,IACnE;EAAE,gBAAgB;EAAM,gBAAgB;CAAW;AACzD"}
@@ -1,7 +1,9 @@
1
+ import { FigmaTextAutoResize, figmaTextAutoResize, textAutoResizeFields } from "./auto-resize.js";
1
2
  import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, TextParagraphRange, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
2
3
  import { LIST_BULLET, ListNumberFormat, TextListItem, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
3
4
  import { StyleRunReferences, remapStyleRunReferences, styleRunReferences } from "./references.js";
4
- import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
5
- import { textLinesOverflow } from "./overflow.js";
5
+ import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
6
+ import { TextLinesReach, textLinesReach, textVerticalOffset } from "./overflow.js";
6
7
  import { textLengthSchema } from "./schema.js";
7
- export { LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextListItem, TextParagraphRange, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
8
+ import { StyleRunPiece, appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt } from "./runs.js";
9
+ export { FigmaTextAutoResize, LIST_BULLET, ListNumberFormat, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, StyleRunPiece, StyleRunReferences, TEXT_PARAGRAPH_SPACING_FIELDS, TextLinesReach, TextListItem, TextParagraphRange, appendStyleRun, characterOverrides, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunAt, styleRunPieces, styleRunReferences, textAutoResizeFields, textLanguageAt, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
@@ -1,7 +1,9 @@
1
- import { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
1
+ import { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels } from "./lengths.js";
2
2
  import { remapStyleRunReferences, styleRunReferences } from "./references.js";
3
3
  import { MAX_LIST_INDENTATION, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, hasParagraphSpacing, hasTextList, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, sharedParagraphSpacing, textParagraphRanges, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing } from "./paragraphs.js";
4
+ import { figmaTextAutoResize, textAutoResizeFields } from "./auto-resize.js";
4
5
  import { LIST_BULLET, formatListNumber, listNumberFormat, textListItems, topLevelNumberDigits } from "./lists.js";
5
- import { textLinesOverflow } from "./overflow.js";
6
+ import { textLinesReach, textVerticalOffset } from "./overflow.js";
6
7
  import { textLengthSchema } from "./schema.js";
7
- export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunReferences, textLengthPixels, textLengthSchema, textLinesOverflow, textListItems, textParagraphRanges, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
8
+ import { appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt } from "./runs.js";
9
+ export { LIST_BULLET, MAX_LIST_INDENTATION, NO_LETTER_SPACING, PLAIN_PARAGRAPH, TEXT_PARAGRAPH_SPACING_FIELDS, appendStyleRun, characterOverrides, estimatedLineStep, figmaTextAutoResize, formatListNumber, formatTextLength, hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, listNumberFormat, paragraphCount, paragraphIndexAt, paragraphSpacingAt, paragraphStyleAt, paragraphStylesAfterEdit, paragraphStylesAfterTextChange, paragraphStylesInRange, paragraphStylesWithoutSpacing, percentLength, pixelLength, remapStyleRunReferences, scaledTextLength, sharedParagraphSpacing, styleRunAt, styleRunPieces, styleRunReferences, textAutoResizeFields, textLanguageAt, textLengthPixels, textLengthSchema, textLinesReach, textListItems, textParagraphRanges, textVerticalOffset, topLevelNumberDigits, trimParagraphStyles, withIndentation, withListType, withParagraphSpacing };
@@ -11,6 +11,11 @@ declare function lineHeightPixels(lineHeight: TextLength | null, fontSize: numbe
11
11
  * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.
12
12
  */
13
13
  declare function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null;
14
+ /**
15
+ * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,
16
+ * and 1.2 times the font size when automatic.
17
+ */
18
+ declare function estimatedLineStep(lineHeight: TextLength | null, fontSize: number): number;
14
19
  /** A length in pixels, as a bound number variable and most authored formats give one. */
15
20
  declare function pixelLength(value: number): TextLength;
16
21
  /** A length as a percent of the font size. */
@@ -20,5 +25,5 @@ declare function scaledTextLength(length: TextLength, factor: number): TextLengt
20
25
  /** `length` as people read it: `24px` or `150%`. */
21
26
  declare function formatTextLength(length: TextLength): string;
22
27
  //#endregion
23
- export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
28
+ export { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
24
29
  //# sourceMappingURL=lengths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;;;;iBAQhD,eAAe,YAAY,mBAAmB;;iBAO9C,YAAY,gBAAgB;;iBAK5B,cAAc,gBAAgB;;iBAK9B,iBAAiB,QAAQ,YAAY,iBAAiB;;iBAKtD,iBAAiB,QAAQ"}
1
+ {"version":3,"file":"lengths.d.ts","names":[],"sources":["../../src/text/lengths.ts"],"mappings":";;;cAGa,mBAAmB;;iBAGhB,iBAAiB,QAAQ,YAAY;;iBAKrC,iBAAiB,YAAY,mBAAmB;;;;;iBAQhD,eAAe,YAAY,mBAAmB;;;;;iBAa9C,kBAAkB,YAAY,mBAAmB;;iBAKjD,YAAY,gBAAgB;;iBAK5B,cAAc,gBAAgB;;iBAK9B,iBAAiB,QAAQ,YAAY,iBAAiB;;iBAKtD,iBAAiB,QAAQ"}
@@ -21,6 +21,15 @@ function lineStepPixels(lineHeight, fontSize) {
21
21
  const pixels = textLengthPixels(lineHeight, fontSize);
22
22
  return lineHeight.unit === "PIXELS" ? pixels : Math.round(pixels);
23
23
  }
24
+ /** How far an automatic line height steps lines when no font metrics measure them. */
25
+ const ESTIMATED_LINE_STEP = 1.2;
26
+ /**
27
+ * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,
28
+ * and 1.2 times the font size when automatic.
29
+ */
30
+ function estimatedLineStep(lineHeight, fontSize) {
31
+ return lineStepPixels(lineHeight, fontSize) ?? fontSize * ESTIMATED_LINE_STEP;
32
+ }
24
33
  /** A length in pixels, as a bound number variable and most authored formats give one. */
25
34
  function pixelLength(value) {
26
35
  return {
@@ -44,6 +53,6 @@ function formatTextLength(length) {
44
53
  return length.unit === "PIXELS" ? `${length.value}px` : `${length.value}%`;
45
54
  }
46
55
  //#endregion
47
- export { NO_LETTER_SPACING, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
56
+ export { NO_LETTER_SPACING, estimatedLineStep, formatTextLength, lineHeightPixels, lineStepPixels, percentLength, pixelLength, scaledTextLength, textLengthPixels };
48
57
 
49
58
  //# sourceMappingURL=lengths.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/**\n * How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels\n * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.\n */\nexport function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n if (!lineHeight) return null\n const pixels = textLengthPixels(lineHeight, fontSize)\n return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;;;;AAMA,SAAgB,eAAe,YAA+B,UAAiC;CAC7F,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,SAAS,iBAAiB,YAAY,QAAQ;CACpD,OAAO,WAAW,SAAS,WAAW,SAAS,KAAK,MAAM,MAAM;AAClE;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
1
+ {"version":3,"file":"lengths.js","names":[],"sources":["../../src/text/lengths.ts"],"sourcesContent":["import type { TextLength } from '../types'\n\n/** No letter spacing, as a new text has it and as Figma writes it. */\nexport const NO_LETTER_SPACING: TextLength = { value: 0, unit: 'PERCENT' }\n\n/** `length` in pixels at `fontSize`. */\nexport function textLengthPixels(length: TextLength, fontSize: number): number {\n return length.unit === 'PIXELS' ? length.value : (length.value / 100) * fontSize\n}\n\n/** A line height in pixels at `fontSize`, or null when it is automatic. */\nexport function lineHeightPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n return lineHeight ? textLengthPixels(lineHeight, fontSize) : null\n}\n\n/**\n * How far apart a line height sets lines at `fontSize`, as Figma steps them: a height in pixels\n * as it is, a percent one to whole pixels (Figma desktop 126); null when it is automatic.\n */\nexport function lineStepPixels(lineHeight: TextLength | null, fontSize: number): number | null {\n if (!lineHeight) return null\n const pixels = textLengthPixels(lineHeight, fontSize)\n return lineHeight.unit === 'PIXELS' ? pixels : Math.round(pixels)\n}\n\n/** How far an automatic line height steps lines when no font metrics measure them. */\nconst ESTIMATED_LINE_STEP = 1.2\n\n/**\n * How far apart lines step where no font metrics measure them: as `lineStepPixels` steps them,\n * and 1.2 times the font size when automatic.\n */\nexport function estimatedLineStep(lineHeight: TextLength | null, fontSize: number): number {\n return lineStepPixels(lineHeight, fontSize) ?? fontSize * ESTIMATED_LINE_STEP\n}\n\n/** A length in pixels, as a bound number variable and most authored formats give one. */\nexport function pixelLength(value: number): TextLength {\n return { value, unit: 'PIXELS' }\n}\n\n/** A length as a percent of the font size. */\nexport function percentLength(value: number): TextLength {\n return { value, unit: 'PERCENT' }\n}\n\n/** `length` scaled by `factor`: pixels scale, a percent already follows the font size. */\nexport function scaledTextLength(length: TextLength, factor: number): TextLength {\n return length.unit === 'PIXELS' ? pixelLength(length.value * factor) : length\n}\n\n/** `length` as people read it: `24px` or `150%`. */\nexport function formatTextLength(length: TextLength): string {\n return length.unit === 'PIXELS' ? `${length.value}px` : `${length.value}%`\n}\n"],"mappings":";;AAGA,MAAa,oBAAgC;CAAE,OAAO;CAAG,MAAM;AAAU;;AAGzE,SAAgB,iBAAiB,QAAoB,UAA0B;CAC7E,OAAO,OAAO,SAAS,WAAW,OAAO,QAAS,OAAO,QAAQ,MAAO;AAC1E;;AAGA,SAAgB,iBAAiB,YAA+B,UAAiC;CAC/F,OAAO,aAAa,iBAAiB,YAAY,QAAQ,IAAI;AAC/D;;;;;AAMA,SAAgB,eAAe,YAA+B,UAAiC;CAC7F,IAAI,CAAC,YAAY,OAAO;CACxB,MAAM,SAAS,iBAAiB,YAAY,QAAQ;CACpD,OAAO,WAAW,SAAS,WAAW,SAAS,KAAK,MAAM,MAAM;AAClE;;AAGA,MAAM,sBAAsB;;;;;AAM5B,SAAgB,kBAAkB,YAA+B,UAA0B;CACzF,OAAO,eAAe,YAAY,QAAQ,KAAK,WAAW;AAC5D;;AAGA,SAAgB,YAAY,OAA2B;CACrD,OAAO;EAAE;EAAO,MAAM;CAAS;AACjC;;AAGA,SAAgB,cAAc,OAA2B;CACvD,OAAO;EAAE;EAAO,MAAM;CAAU;AAClC;;AAGA,SAAgB,iBAAiB,QAAoB,QAA4B;CAC/E,OAAO,OAAO,SAAS,WAAW,YAAY,OAAO,QAAQ,MAAM,IAAI;AACzE;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,OAAO,SAAS,WAAW,GAAG,OAAO,MAAM,MAAM,GAAG,OAAO,MAAM;AAC1E"}
@@ -1,11 +1,20 @@
1
1
  import { SceneNode } from "../types.js";
2
+ import { VisualBounds } from "../geometry.js";
2
3
  //#region src/text/overflow.d.ts
3
- type TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>;
4
+ type TextBoxNode = Pick<SceneNode, 'height' | 'textAlignVertical'>;
5
+ type TextBoundsNode = TextBoxNode & Pick<SceneNode, 'type' | 'derivedTextHeight'>;
6
+ type TextLinesReach = Pick<VisualBounds, 'minY' | 'maxY'>;
4
7
  /**
5
- * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
6
- * and the renderer starts them at its top.
8
+ * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical
9
+ * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma
10
+ * lays them out.
7
11
  */
8
- declare function textLinesOverflow(node: TextBoundsNode): number;
12
+ declare function textVerticalOffset(node: TextBoxNode, contentHeight: number): number;
13
+ /**
14
+ * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size
15
+ * box lets run past it above or below, as in Figma.
16
+ */
17
+ declare function textLinesReach(node: TextBoundsNode): TextLinesReach;
9
18
  //#endregion
10
- export { textLinesOverflow };
19
+ export { TextLinesReach, textLinesReach, textVerticalOffset };
11
20
  //# sourceMappingURL=overflow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"overflow.d.ts","names":[],"sources":["../../src/text/overflow.ts"],"mappings":";;KAEK,iBAAiB,KAAK;;;;;iBAMX,kBAAkB,MAAM"}
1
+ {"version":3,"file":"overflow.d.ts","names":[],"sources":["../../src/text/overflow.ts"],"mappings":";;;KAGK,cAAc,KAAK;KACnB,iBAAiB,cAAc,KAAK;KAE7B,iBAAiB,KAAK;;;;;;iBAOlB,mBAAmB,MAAM,aAAa;;;;;iBAetC,eAAe,MAAM,iBAAiB"}
@@ -1,13 +1,31 @@
1
1
  //#region src/text/overflow.ts
2
2
  /**
3
- * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,
4
- * and the renderer starts them at its top.
3
+ * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical
4
+ * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma
5
+ * lays them out.
5
6
  */
6
- function textLinesOverflow(node) {
7
- if (node.type !== "TEXT" || !node.derivedTextHeight) return 0;
8
- return Math.max(0, node.derivedTextHeight - node.height);
7
+ function textVerticalOffset(node, contentHeight) {
8
+ const available = node.height - contentHeight;
9
+ if (node.textAlignVertical === "CENTER") return available / 2;
10
+ if (node.textAlignVertical === "BOTTOM") return available;
11
+ return 0;
12
+ }
13
+ /**
14
+ * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size
15
+ * box lets run past it above or below, as in Figma.
16
+ */
17
+ function textLinesReach(node) {
18
+ if (node.type !== "TEXT" || !node.derivedTextHeight) return {
19
+ minY: 0,
20
+ maxY: node.height
21
+ };
22
+ const linesTop = textVerticalOffset(node, node.derivedTextHeight);
23
+ return {
24
+ minY: Math.min(0, linesTop),
25
+ maxY: Math.max(node.height, linesTop + node.derivedTextHeight)
26
+ };
9
27
  }
10
28
  //#endregion
11
- export { textLinesOverflow };
29
+ export { textLinesReach, textVerticalOffset };
12
30
 
13
31
  //# sourceMappingURL=overflow.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\ntype TextBoundsNode = Pick<SceneNode, 'type' | 'height' | 'derivedTextHeight'>\n\n/**\n * How far a text's lines reach below its box: a fixed-size box does not clip them, as in Figma,\n * and the renderer starts them at its top.\n */\nexport function textLinesOverflow(node: TextBoundsNode): number {\n if (node.type !== 'TEXT' || !node.derivedTextHeight) return 0\n return Math.max(0, node.derivedTextHeight - node.height)\n}\n"],"mappings":";;;;;AAQA,SAAgB,kBAAkB,MAA8B;CAC9D,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,mBAAmB,OAAO;CAC5D,OAAO,KAAK,IAAI,GAAG,KAAK,oBAAoB,KAAK,MAAM;AACzD"}
1
+ {"version":3,"file":"overflow.js","names":[],"sources":["../../src/text/overflow.ts"],"sourcesContent":["import type { VisualBounds } from '../geometry'\nimport type { SceneNode } from '../types'\n\ntype TextBoxNode = Pick<SceneNode, 'height' | 'textAlignVertical'>\ntype TextBoundsNode = TextBoxNode & Pick<SceneNode, 'type' | 'derivedTextHeight'>\n\nexport type TextLinesReach = Pick<VisualBounds, 'minY' | 'maxY'>\n\n/**\n * Where the top of laid-out lines `contentHeight` tall sits in a text's box, by its vertical\n * alignment. Lines taller than the box overflow on the side away from the alignment, as Figma\n * lays them out.\n */\nexport function textVerticalOffset(node: TextBoxNode, contentHeight: number): number {\n const available = node.height - contentHeight\n if (node.textAlignVertical === 'CENTER') {\n return available / 2\n }\n if (node.textAlignVertical === 'BOTTOM') {\n return available\n }\n return 0\n}\n\n/**\n * The rows a text draws its lines over, in its own axes: its box, grown by the lines a fixed-size\n * box lets run past it above or below, as in Figma.\n */\nexport function textLinesReach(node: TextBoundsNode): TextLinesReach {\n if (node.type !== 'TEXT' || !node.derivedTextHeight) {\n return { minY: 0, maxY: node.height }\n }\n const linesTop = textVerticalOffset(node, node.derivedTextHeight)\n return {\n minY: Math.min(0, linesTop),\n maxY: Math.max(node.height, linesTop + node.derivedTextHeight)\n }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,mBAAmB,MAAmB,eAA+B;CACnF,MAAM,YAAY,KAAK,SAAS;CAChC,IAAI,KAAK,sBAAsB,UAC7B,OAAO,YAAY;CAErB,IAAI,KAAK,sBAAsB,UAC7B,OAAO;CAET,OAAO;AACT;;;;;AAMA,SAAgB,eAAe,MAAsC;CACnE,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,mBAChC,OAAO;EAAE,MAAM;EAAG,MAAM,KAAK;CAAO;CAEtC,MAAM,WAAW,mBAAmB,MAAM,KAAK,iBAAiB;CAChE,OAAO;EACL,MAAM,KAAK,IAAI,GAAG,QAAQ;EAC1B,MAAM,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,iBAAiB;CAC/D;AACF"}
@@ -0,0 +1,10 @@
1
+ //#region src/text/path.ts
2
+ function followsPath(node) {
3
+ const glyphs = node.derivedTextGlyphs ?? [];
4
+ if (glyphs.length === 0) return false;
5
+ return !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0);
6
+ }
7
+ //#endregion
8
+ export { followsPath };
9
+
10
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","names":[],"sources":["../../src/text/path.ts"],"sourcesContent":["import type { SceneNode } from '../types'\n\nexport function followsPath(\n node: Pick<SceneNode, 'derivedTextGlyphs' | 'textPathData' | 'textPathBox'>\n): boolean {\n const glyphs = node.derivedTextGlyphs ?? []\n if (glyphs.length === 0) {\n return false\n }\n return (\n !!node.textPathData || !!node.textPathBox || glyphs.some((glyph) => (glyph.rotation ?? 0) !== 0)\n )\n}\n"],"mappings":";AAEA,SAAgB,YACd,MACS;CACT,MAAM,SAAS,KAAK,qBAAqB,CAAC;CAC1C,IAAI,OAAO,WAAW,GACpB,OAAO;CAET,OACE,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,KAAK,eAAe,OAAO,MAAM,WAAW,MAAM,YAAY,OAAO,CAAC;AAEnG"}
@@ -24,11 +24,11 @@ function textCacheInvalidationChanges(node, changes) {
24
24
  if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key))) invalidated.textPicture = null;
25
25
  const glyphsInvalidated = keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) || TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key));
26
26
  if (glyphsInvalidated && !("derivedLayout" in changes)) invalidated.derivedLayout = null;
27
- if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {
28
- if (!(!!node.textPathData && keys.every((key) => key === "width" || key === "height"))) {
29
- invalidated.derivedTextGlyphs = null;
30
- invalidated.textPathData = null;
31
- }
27
+ if (glyphsInvalidated && !changes.derivedTextGlyphs) {
28
+ const onlyPathBoxResize = !!node.textPathData && keys.every((key) => key === "width" || key === "height");
29
+ const placesPath = keys.includes("textPathBox") && !!changes.textPathBox;
30
+ if (node.derivedTextGlyphs && !onlyPathBoxResize) invalidated.derivedTextGlyphs = null;
31
+ if (node.textPathData && !onlyPathBoxResize && !placesPath) invalidated.textPathData = null;
32
32
  }
33
33
  return invalidated;
34
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n // A successful path-text edit supplies reflowed glyphs in `changes`. Every\n // other mutation path must drop stale baked glyphs and path identity rather\n // than pair new text/style with old visible outlines.\n if (node.derivedTextGlyphs && glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n if (!onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n"],"mappings":";;;;;;;AASA,MAAa,oCAAyC,IAAI,IAAI;CAC5D,GAAG;CACH;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAA4C,IAAI,IAAI,mBAAmB;;;;;;AAOpF,SAAgB,6BACd,MACA,SACoB;CACpB,MAAM,cAAkC,CAAC;CACzC,MAAM,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,QAC/B,QAAQ,CAAC,QAAQ,KAAK,MAAyB,QAAQ,IAAuB,CACjF;CACA,IAAI,KAAK,eAAe,KAAK,MAAM,QAAQ,kBAAkB,IAAI,GAAG,CAAC,GACnE,YAAY,cAAc;CAC5B,MAAM,oBACJ,KAAK,MAAM,QAAQ,qBAAqB,IAAI,GAAG,CAAC,KAChD,mBAAmB,MAAM,QAAQ,KAAK,SAAS,GAAG,CAAC;CACrD,IAAI,qBAAqB,EAAE,mBAAmB,UAAU,YAAY,gBAAgB;CAIpF,IAAI,KAAK,qBAAqB,qBAAqB,CAAC,QAAQ,mBAKtD;MAAA,EADF,CAAC,CAAC,KAAK,gBAAgB,KAAK,OAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ,IACxD;GACtB,YAAY,oBAAoB;GAChC,YAAY,eAAe;EAC7B;;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"picture.js","names":[],"sources":["../../src/text/picture.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { TEXT_SHAPING_FIELDS, TEXT_LAYOUT_FIELDS } from '../fields/text'\nimport type { SceneNode } from '../types'\n\n/**\n * Invalidate cached Skia textPicture (Paragraph snapshot). Includes width/height\n * because wrapping/layout depends on the box.\n */\nexport const TEXT_PICTURE_KEYS: ReadonlySet<string> = new Set([\n ...TEXT_SHAPING_FIELDS,\n 'textDecoration',\n 'fills',\n 'width',\n 'height'\n])\n\nexport const GLYPH_AFFECTING_KEYS: ReadonlySet<string> = new Set(TEXT_SHAPING_FIELDS)\n\n/**\n * Shared by SceneGraph.updateNode and updateNodePreview (drag hot path) so the\n * two invalidation rules cannot drift. Glyphs are kept when the caller\n * replaces them in the same update (resize supplies scaled copies).\n */\nexport function textCacheInvalidationChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const invalidated: Partial<SceneNode> = {}\n const keys = Object.keys(changes).filter(\n (key) => !isEqual(node[key as keyof SceneNode], changes[key as keyof SceneNode])\n )\n if (node.textPicture && keys.some((key) => TEXT_PICTURE_KEYS.has(key)))\n invalidated.textPicture = null\n const glyphsInvalidated =\n keys.some((key) => GLYPH_AFFECTING_KEYS.has(key)) ||\n TEXT_LAYOUT_FIELDS.some((key) => keys.includes(key))\n if (glyphsInvalidated && !('derivedLayout' in changes)) invalidated.derivedLayout = null\n if (glyphsInvalidated && !changes.derivedTextGlyphs) {\n // Path-text resize supplies transformed glyphs through the resize workflow. A raw box\n // preview keeps them until that workflow commits or an actual shaping edit occurs.\n const onlyPathBoxResize =\n !!node.textPathData && keys.every((key) => key === 'width' || key === 'height')\n const placesPath = keys.includes('textPathBox') && !!changes.textPathBox\n if (node.derivedTextGlyphs && !onlyPathBoxResize) {\n invalidated.derivedTextGlyphs = null\n }\n if (node.textPathData && !onlyPathBoxResize && !placesPath) {\n invalidated.textPathData = null\n }\n }\n return invalidated\n}\n"],"mappings":";;;;;;;AASA,MAAa,oCAAyC,IAAI,IAAI;CAC5D,GAAG;CACH;CACA;CACA;CACA;AACF,CAAC;AAED,MAAa,uBAA4C,IAAI,IAAI,mBAAmB;;;;;;AAOpF,SAAgB,6BACd,MACA,SACoB;CACpB,MAAM,cAAkC,CAAC;CACzC,MAAM,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,QAC/B,QAAQ,CAAC,QAAQ,KAAK,MAAyB,QAAQ,IAAuB,CACjF;CACA,IAAI,KAAK,eAAe,KAAK,MAAM,QAAQ,kBAAkB,IAAI,GAAG,CAAC,GACnE,YAAY,cAAc;CAC5B,MAAM,oBACJ,KAAK,MAAM,QAAQ,qBAAqB,IAAI,GAAG,CAAC,KAChD,mBAAmB,MAAM,QAAQ,KAAK,SAAS,GAAG,CAAC;CACrD,IAAI,qBAAqB,EAAE,mBAAmB,UAAU,YAAY,gBAAgB;CACpF,IAAI,qBAAqB,CAAC,QAAQ,mBAAmB;EAGnD,MAAM,oBACJ,CAAC,CAAC,KAAK,gBAAgB,KAAK,OAAO,QAAQ,QAAQ,WAAW,QAAQ,QAAQ;EAChF,MAAM,aAAa,KAAK,SAAS,aAAa,KAAK,CAAC,CAAC,QAAQ;EAC7D,IAAI,KAAK,qBAAqB,CAAC,mBAC7B,YAAY,oBAAoB;EAElC,IAAI,KAAK,gBAAgB,CAAC,qBAAqB,CAAC,YAC9C,YAAY,eAAe;CAE/B;CACA,OAAO;AACT"}
@@ -0,0 +1,29 @@
1
+ import { CharacterStyleOverride, SceneNode, StyleRun } from "../types.js";
2
+ //#region src/text/runs.d.ts
3
+ /** The run that styles `text[index]`, if one does. */
4
+ declare function styleRunAt(runs: readonly StyleRun[], index: number): StyleRun | undefined;
5
+ /** The language `text[index]` is shaped in: its run's, or the text's own. */
6
+ declare function textLanguageAt(node: Pick<SceneNode, 'styleRuns' | 'textLanguage'>, index: number): string | null;
7
+ /**
8
+ * Adds `style` over `[start, start + length)` to runs built in text order, extending the last
9
+ * run instead when it ends at `start` with an equal style. An empty style or range adds nothing,
10
+ * since those characters keep the text's own style.
11
+ */
12
+ declare function appendStyleRun(runs: StyleRun[], start: number, length: number, style: CharacterStyleOverride): void;
13
+ /** A stretch of text in one style: a run's, or the text's own where `style` is null. */
14
+ interface StyleRunPiece {
15
+ start: number;
16
+ end: number;
17
+ style: CharacterStyleOverride | null;
18
+ }
19
+ /**
20
+ * The first `length` characters cut at their runs, in order and covering every character once:
21
+ * a run's part that an earlier run already covers, or that lies past the text, is left out.
22
+ * `boundary` moves each cut to where the text may be cut, such as out of a surrogate pair.
23
+ */
24
+ declare function styleRunPieces(runs: readonly StyleRun[], length: number, boundary?: (index: number) => number): StyleRunPiece[];
25
+ /** Each of the first `length` characters' overrides, merged from the runs over it in order. */
26
+ declare function characterOverrides(runs: readonly StyleRun[], length: number): CharacterStyleOverride[];
27
+ //#endregion
28
+ export { StyleRunPiece, appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt };
29
+ //# sourceMappingURL=runs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runs.d.ts","names":[],"sources":["../../src/text/runs.ts"],"mappings":";;;iBAKgB,WAAW,eAAe,YAAY,gBAAgB;;iBAKtD,eACd,MAAM,KAAK,0CACX;;;;;;iBAWc,eACd,MAAM,YACN,eACA,gBACA,OAAO;;UAUQ;EACf;EACA;EACA,OAAO;;;;;;;iBAQO,eACd,eAAe,YACf,gBACA,YAAW,2BACV;;iBAea,mBACd,eAAe,YACf,iBACC"}
@@ -0,0 +1,72 @@
1
+ import { isEqual } from "es-toolkit/predicate";
2
+ //#region src/text/runs.ts
3
+ /** The run that styles `text[index]`, if one does. */
4
+ function styleRunAt(runs, index) {
5
+ return runs.find((run) => index >= run.start && index < run.start + run.length);
6
+ }
7
+ /** The language `text[index]` is shaped in: its run's, or the text's own. */
8
+ function textLanguageAt(node, index) {
9
+ const language = styleRunAt(node.styleRuns, index)?.style.textLanguage;
10
+ return language !== void 0 ? language : node.textLanguage;
11
+ }
12
+ /**
13
+ * Adds `style` over `[start, start + length)` to runs built in text order, extending the last
14
+ * run instead when it ends at `start` with an equal style. An empty style or range adds nothing,
15
+ * since those characters keep the text's own style.
16
+ */
17
+ function appendStyleRun(runs, start, length, style) {
18
+ if (length <= 0 || Object.keys(style).length === 0) return;
19
+ const previous = runs.at(-1);
20
+ if (previous && previous.start + previous.length === start && isEqual(previous.style, style)) previous.length += length;
21
+ else runs.push({
22
+ start,
23
+ length,
24
+ style
25
+ });
26
+ }
27
+ /**
28
+ * The first `length` characters cut at their runs, in order and covering every character once:
29
+ * a run's part that an earlier run already covers, or that lies past the text, is left out.
30
+ * `boundary` moves each cut to where the text may be cut, such as out of a surrogate pair.
31
+ */
32
+ function styleRunPieces(runs, length, boundary = (index) => index) {
33
+ const pieces = [];
34
+ let at = 0;
35
+ for (const run of runs.toSorted((a, b) => a.start - b.start)) {
36
+ const start = Math.min(length, Math.max(at, boundary(run.start)));
37
+ const end = Math.min(length, boundary(run.start + run.length));
38
+ if (start > at) pieces.push({
39
+ start: at,
40
+ end: start,
41
+ style: null
42
+ });
43
+ if (end > start) pieces.push({
44
+ start,
45
+ end,
46
+ style: run.style
47
+ });
48
+ at = Math.max(start, end);
49
+ }
50
+ if (at < length) pieces.push({
51
+ start: at,
52
+ end: length,
53
+ style: null
54
+ });
55
+ return pieces;
56
+ }
57
+ /** Each of the first `length` characters' overrides, merged from the runs over it in order. */
58
+ function characterOverrides(runs, length) {
59
+ const styles = Array.from({ length }, () => ({}));
60
+ for (const run of runs) {
61
+ const end = Math.min(length, run.start + run.length);
62
+ for (let index = Math.max(0, run.start); index < end; index++) styles[index] = {
63
+ ...styles[index],
64
+ ...run.style
65
+ };
66
+ }
67
+ return styles;
68
+ }
69
+ //#endregion
70
+ export { appendStyleRun, characterOverrides, styleRunAt, styleRunPieces, textLanguageAt };
71
+
72
+ //# sourceMappingURL=runs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runs.js","names":[],"sources":["../../src/text/runs.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { CharacterStyleOverride, SceneNode, StyleRun } from '../types'\n\n/** The run that styles `text[index]`, if one does. */\nexport function styleRunAt(runs: readonly StyleRun[], index: number): StyleRun | undefined {\n return runs.find((run) => index >= run.start && index < run.start + run.length)\n}\n\n/** The language `text[index]` is shaped in: its run's, or the text's own. */\nexport function textLanguageAt(\n node: Pick<SceneNode, 'styleRuns' | 'textLanguage'>,\n index: number\n): string | null {\n const language = styleRunAt(node.styleRuns, index)?.style.textLanguage\n return language !== undefined ? language : node.textLanguage\n}\n\n/**\n * Adds `style` over `[start, start + length)` to runs built in text order, extending the last\n * run instead when it ends at `start` with an equal style. An empty style or range adds nothing,\n * since those characters keep the text's own style.\n */\nexport function appendStyleRun(\n runs: StyleRun[],\n start: number,\n length: number,\n style: CharacterStyleOverride\n): void {\n if (length <= 0 || Object.keys(style).length === 0) return\n const previous = runs.at(-1)\n if (previous && previous.start + previous.length === start && isEqual(previous.style, style))\n previous.length += length\n else runs.push({ start, length, style })\n}\n\n/** A stretch of text in one style: a run's, or the text's own where `style` is null. */\nexport interface StyleRunPiece {\n start: number\n end: number\n style: CharacterStyleOverride | null\n}\n\n/**\n * The first `length` characters cut at their runs, in order and covering every character once:\n * a run's part that an earlier run already covers, or that lies past the text, is left out.\n * `boundary` moves each cut to where the text may be cut, such as out of a surrogate pair.\n */\nexport function styleRunPieces(\n runs: readonly StyleRun[],\n length: number,\n boundary: (index: number) => number = (index) => index\n): StyleRunPiece[] {\n const pieces: StyleRunPiece[] = []\n let at = 0\n for (const run of runs.toSorted((a, b) => a.start - b.start)) {\n const start = Math.min(length, Math.max(at, boundary(run.start)))\n const end = Math.min(length, boundary(run.start + run.length))\n if (start > at) pieces.push({ start: at, end: start, style: null })\n if (end > start) pieces.push({ start, end, style: run.style })\n at = Math.max(start, end)\n }\n if (at < length) pieces.push({ start: at, end: length, style: null })\n return pieces\n}\n\n/** Each of the first `length` characters' overrides, merged from the runs over it in order. */\nexport function characterOverrides(\n runs: readonly StyleRun[],\n length: number\n): CharacterStyleOverride[] {\n const styles = Array.from({ length }, (): CharacterStyleOverride => ({}))\n for (const run of runs) {\n const end = Math.min(length, run.start + run.length)\n for (let index = Math.max(0, run.start); index < end; index++) {\n styles[index] = { ...styles[index], ...run.style }\n }\n }\n return styles\n}\n"],"mappings":";;;AAKA,SAAgB,WAAW,MAA2B,OAAqC;CACzF,OAAO,KAAK,MAAM,QAAQ,SAAS,IAAI,SAAS,QAAQ,IAAI,QAAQ,IAAI,MAAM;AAChF;;AAGA,SAAgB,eACd,MACA,OACe;CACf,MAAM,WAAW,WAAW,KAAK,WAAW,KAAK,CAAC,EAAE,MAAM;CAC1D,OAAO,aAAa,KAAA,IAAY,WAAW,KAAK;AAClD;;;;;;AAOA,SAAgB,eACd,MACA,OACA,QACA,OACM;CACN,IAAI,UAAU,KAAK,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GAAG;CACpD,MAAM,WAAW,KAAK,GAAG,EAAE;CAC3B,IAAI,YAAY,SAAS,QAAQ,SAAS,WAAW,SAAS,QAAQ,SAAS,OAAO,KAAK,GACzF,SAAS,UAAU;MAChB,KAAK,KAAK;EAAE;EAAO;EAAQ;CAAM,CAAC;AACzC;;;;;;AAcA,SAAgB,eACd,MACA,QACA,YAAuC,UAAU,OAChC;CACjB,MAAM,SAA0B,CAAC;CACjC,IAAI,KA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.d.ts","names":[],"sources":["../../src/transfer/dependencies.ts"],"mappings":";;;;UAYiB;;EAEf,WAAW;;;;;EAKX,aAAa;;EAEb,QAAQ;;EAER,QAAQ;;;iBAIM,iBAAiB,MAAM;;;;;iBAgBvB,iBAAiB,MAAM;;;;;;iBAkBvB,kBACd,OAAO,YACP,QAAQ,SAAS,aAChB;;;;;iBA8Ba,qBACd,OAAO,YACP,KAAK,mBACJ,KAAK"}
@@ -4,6 +4,7 @@ import { styleRunReferences } from "../text/references.js";
4
4
  import { referencedStyleIds, sharedStyleLayers } from "../shared-styles.js";
5
5
  import { regionFills } from "../vector-network.js";
6
6
  import { imagePaintHashes } from "../images.js";
7
+ import { appendAll } from "@open-pencil/std/arrays";
7
8
  //#region src/transfer/dependencies.ts
8
9
  /** The variables a layer names: its own bindings, its characters', and its overrides'. */
9
10
  function layerVariableIds(node) {
@@ -42,7 +43,7 @@ function layerDependencies(graph, layers) {
42
43
  const styleLayer = (id) => (styleLayers ??= sharedStyleLayers(graph)).get(id);
43
44
  const visit = (node) => {
44
45
  for (const hash of layerImageHashes(node)) images.add(hash);
45
- pending.push(...layerVariableIds(node));
46
+ appendAll(pending, layerVariableIds(node));
46
47
  for (const id of Object.keys(node.variableModes)) if (graph.variableCollections.has(id)) collections.add(id);
47
48
  for (const id of referencedStyleIds(node)) {
48
49
  const style = styles.has(id) ? void 0 : styleLayer(id);
@@ -81,7 +82,7 @@ function variableDependencies(graph, ids) {
81
82
  variables.add(id);
82
83
  collections.add(variable.collectionId);
83
84
  for (const value of Object.values(variable.valuesByMode)) {
84
- pending.push(...variableValueReferences(value));
85
+ appendAll(pending, variableValueReferences(value));
85
86
  if (!isUnsupportedVariableValue(value)) continue;
86
87
  for (const modeId of value.modes) {
87
88
  const collection = collectionOfMode(modeId);
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","names":[],"sources":["../../src/transfer/dependencies.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { imagePaintHashes } from '../images'\nimport { overriddenBindingField } from '../instances/overrides'\nimport { referencedStyleIds, sharedStyleLayers } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { SceneNode } from '../types'\nimport { isUnsupportedVariableValue, variableValueReferences } from '../variables/value'\nimport { regionFills } from '../vector-network'\n\n/** What layers need from their document to draw the same in another one. */\nexport interface LayerDependencies {\n /** The variables the layers and their styles bind, and every variable those alias. */\n variables: Set<string>\n /**\n * The collections of those variables, those the layers set a mode of, and those a kept\n * expression names a mode of.\n */\n collections: Set<string>\n /** The shared styles the layers use, as the style layers that define them. */\n styles: SceneNode[]\n /** The images the layers and their styles paint with. */\n images: Set<string>\n}\n\n/** The variables a layer names: its own bindings, its characters', and its overrides'. */\nexport function layerVariableIds(node: SceneNode): string[] {\n const { self, descendants } = node.instanceOverrides\n const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])]\n return [\n ...Object.values(node.boundVariables),\n ...styleRunReferences(node.styleRuns).variables,\n ...overridden.flatMap(([field, value]) =>\n typeof value === 'string' && overriddenBindingField(field) !== null ? [value] : []\n )\n ]\n}\n\n/**\n * The images a layer paints with: its fills, strokes, vector regions, text decorations, and\n * characters.\n */\nexport function layerImageHashes(node: SceneNode): string[] {\n return imagePaintHashes([\n ...node.fills,\n ...node.strokes,\n ...regionFills(node.vectorNetwork),\n ...node.textDecorationFills,\n ...node.styleRuns.flatMap((run) => [\n ...(run.style.fills ?? []),\n ...(run.style.textDecorationFills ?? [])\n ])\n ])\n}\n\n/**\n * The variables, collections, styles, and images `layers` depend on, as a copy into another\n * document must carry them: a style brings what it binds and paints with in turn, and a variable\n * brings the variables it aliases.\n */\nexport function layerDependencies(\n graph: SceneGraph,\n layers: Iterable<SceneNode>\n): LayerDependencies {\n const collections = new Set<string>()\n const images = new Set<string>()\n const styles = new Map<string, SceneNode>()\n const pending: string[] = []\n let styleLayers: Map<string, SceneNode> | undefined\n const styleLayer = (id: string): SceneNode | undefined =>\n (styleLayers ??= sharedStyleLayers(graph)).get(id)\n const visit = (node: SceneNode): void => {\n for (const hash of layerImageHashes(node)) images.add(hash)\n pending.push(...layerVariableIds(node))\n for (const id of Object.keys(node.variableModes))\n if (graph.variableCollections.has(id)) collections.add(id)\n for (const id of referencedStyleIds(node)) {\n const style = styles.has(id) ? undefined : styleLayer(id)\n if (!style) continue\n styles.set(id, style)\n visit(style)\n }\n }\n for (const node of layers) visit(node)\n const resolved = variableDependencies(graph, pending)\n for (const id of resolved.collections) collections.add(id)\n return { variables: resolved.variables, collections, styles: [...styles.values()], images }\n}\n\n/**\n * These variables and every variable they alias, at any depth, with their collections and the\n * collections a kept expression names a mode of.\n */\nexport function variableDependencies(\n graph: SceneGraph,\n ids: Iterable<string>\n): Pick<LayerDependencies, 'variables' | 'collections'> {\n const pending = [...ids]\n const variables = new Set<string>()\n const collections = new Set<string>()\n let modeCollections: Map<string, string> | undefined\n const collectionOfMode = (modeId: string): string | undefined => {\n modeCollections ??= new Map(\n [...graph.variableCollections.values()].flatMap((collection) =>\n collection.modes.map((mode) => [mode.modeId, collection.id] as const)\n )\n )\n return modeCollections.get(modeId)\n }\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (variables.has(id)) continue\n const variable = graph.variables.get(id)\n if (!variable) continue\n variables.add(id)\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode)) {\n pending.push(...variableValueReferences(value))\n // A kept expression can name a mode of a collection none of its aliases reach.\n if (!isUnsupportedVariableValue(value)) continue\n for (const modeId of value.modes) {\n const collection = collectionOfMode(modeId)\n if (collection) collections.add(collection)\n }\n }\n }\n return { variables, collections }\n}\n"],"mappings":";;;;;;;;AAyBA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,EAAE,MAAM,gBAAgB,KAAK;CACnC,MAAM,aAAa,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,MAAM,CAAC,CAAC;CAC1F,OAAO;EACL,GAAG,O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OAAO;CACpD,KAAK,MAAM,MAAM,SAAS,aAAa,YAAY,IAAI,EAAE;CACzD,OAAO;EAAE,WAAW,SAAS;EAAW;EAAa,QAAQ,CAAC,GAAG,OAAO,OAAO,CAAC;EAAG;CAAO;AAC5F;;;;;AAMA,SAAgB,qBACd,OACA,KACsD;CACtD,MAAM,UAAU,CAAC,GAAG,GAAG;CACvB,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,8BAAc,IAAI,IAAY;CACpC,IAAI;CACJ,MAAM,oBAAoB,WAAuC;EAC/D,oBAAoB,IAAI,IACtB,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,SAAS,eAC/C,WAAW,MAAM,KAAK,SAAS,CAAC,KAAK,QAAQ,WAAW,EAAE,CAAU,CACtE,CACF;EACA,OAAO,gBAAgB,IAAI,MAAM;CACnC;CACA,KAAK,IAAI,KAAK,QAAQ,IAAI,GAAG,OAAO,KAAA,GAAW,KAAK,QAAQ,IAAI,GAAG;EACjE,IAAI,UAAU,IAAI,EAAE,GAAG;EACvB,MAAM,WAAW,MAAM,UAAU,IAAI,EAAE;EACvC,IAAI,CAAC,UAAU;EACf,UAAU,IAAI,EAAE;EAChB,YAAY,IAAI,SAAS,YAAY;EACrC,KAAK,MAAM,SAAS,OAAO,OAAO,SAAS,YAAY,GAAG;GACxD,QAAQ,KAAK,GAAG,wBAAwB,KAAK,CAAC;GAE9C,IAAI,CAAC,2BAA2B,KAAK,GAAG;GACxC,KAAK,MAAM,UAAU,MAAM,OAAO;IAChC,MAAM,aAAa,iBAAiB,MAAM;IAC1C,IAAI,YAAY,YAAY,IAAI,UAAU;GAC5C;EACF;CACF;CACA,OAAO;EAAE;EAAW;CAAY;AAClC"}
1
+ {"version":3,"file":"dependencies.js","names":[],"sources":["../../src/transfer/dependencies.ts"],"sourcesContent":["import { appendAll } from '@open-pencil/std/arrays'\n\nimport type { SceneGraph } from '../graph'\nimport { imagePaintHashes } from '../images'\nimport { overriddenBindingField } from '../instances/overrides'\nimport { referencedStyleIds, sharedStyleLayers } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { SceneNode } from '../types'\nimport { isUnsupportedVariableValue, variableValueReferences } from '../variables/value'\nimport { regionFills } from '../vector-network'\n\n/** What layers need from their document to draw the same in another one. */\nexport interface LayerDependencies {\n /** The variables the layers and their styles bind, and every variable those alias. */\n variables: Set<string>\n /**\n * The collections of those variables, those the layers set a mode of, and those a kept\n * expression names a mode of.\n */\n collections: Set<string>\n /** The shared styles the layers use, as the style layers that define them. */\n styles: SceneNode[]\n /** The images the layers and their styles paint with. */\n images: Set<string>\n}\n\n/** The variables a layer names: its own bindings, its characters', and its overrides'. */\nexport function layerVariableIds(node: SceneNode): string[] {\n const { self, descendants } = node.instanceOverrides\n const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])]\n return [\n ...Object.values(node.boundVariables),\n ...styleRunReferences(node.styleRuns).variables,\n ...overridden.flatMap(([field, value]) =>\n typeof value === 'string' && overriddenBindingField(field) !== null ? [value] : []\n )\n ]\n}\n\n/**\n * The images a layer paints with: its fills, strokes, vector regions, text decorations, and\n * characters.\n */\nexport function layerImageHashes(node: SceneNode): string[] {\n return imagePaintHashes([\n ...node.fills,\n ...node.strokes,\n ...regionFills(node.vectorNetwork),\n ...node.textDecorationFills,\n ...node.styleRuns.flatMap((run) => [\n ...(run.style.fills ?? []),\n ...(run.style.textDecorationFills ?? [])\n ])\n ])\n}\n\n/**\n * The variables, collections, styles, and images `layers` depend on, as a copy into another\n * document must carry them: a style brings what it binds and paints with in turn, and a variable\n * brings the variables it aliases.\n */\nexport function layerDependencies(\n graph: SceneGraph,\n layers: Iterable<SceneNode>\n): LayerDependencies {\n const collections = new Set<string>()\n const images = new Set<string>()\n const styles = new Map<string, SceneNode>()\n const pending: string[] = []\n let styleLayers: Map<string, SceneNode> | undefined\n const styleLayer = (id: string): SceneNode | undefined =>\n (styleLayers ??= sharedStyleLayers(graph)).get(id)\n const visit = (node: SceneNode): void => {\n for (const hash of layerImageHashes(node)) images.add(hash)\n appendAll(pending, layerVariableIds(node))\n for (const id of Object.keys(node.variableModes))\n if (graph.variableCollections.has(id)) collections.add(id)\n for (const id of referencedStyleIds(node)) {\n const style = styles.has(id) ? undefined : styleLayer(id)\n if (!style) continue\n styles.set(id, style)\n visit(style)\n }\n }\n for (const node of layers) visit(node)\n const resolved = variableDependencies(graph, pending)\n for (const id of resolved.collections) collections.add(id)\n return { variables: resolved.variables, collections, styles: [...styles.values()], images }\n}\n\n/**\n * These variables and every variable they alias, at any depth, with their collections and the\n * collections a kept expression names a mode of.\n */\nexport function variableDependencies(\n graph: SceneGraph,\n ids: Iterable<string>\n): Pick<LayerDependencies, 'variables' | 'collections'> {\n const pending = [...ids]\n const variables = new Set<string>()\n const collections = new Set<string>()\n let modeCollections: Map<string, string> | undefined\n const collectionOfMode = (modeId: string): string | undefined => {\n modeCollections ??= new Map(\n [...graph.variableCollections.values()].flatMap((collection) =>\n collection.modes.map((mode) => [mode.modeId, collection.id] as const)\n )\n )\n return modeCollections.get(modeId)\n }\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (variables.has(id)) continue\n const variable = graph.variables.get(id)\n if (!variable) continue\n variables.add(id)\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode)) {\n appendAll(pending, variableValueReferences(value))\n // A kept expression can name a mode of a collection none of its aliases reach.\n if (!isUnsupportedVariableValue(value)) continue\n for (const modeId of value.modes) {\n const collection = collectionOfMode(modeId)\n if (collection) collections.add(collection)\n }\n }\n }\n return { variables, collections }\n}\n"],"mappings":";;;;;;;;;AA2BA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,EAAE,MAAM,gBAAgB,KAAK;CACnC,MAAM,aAAa,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,MAAM,CAAC,CAAC;CAC1F,OAAO;EACL,GAAG,OAAO,OA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AK,MAAM,MAAM,SAAS,aAAa,YAAY,IAAI,EAAE;CACzD,OAAO;EAAE,WAAW,SAAS;EAAW;EAAa,QAAQ,CAAC,GAAG,OAAO,OAAO,CAAC;EAAG;CAAO;AAC5F;;;;;AAMA,SAAgB,qBACd,OACA,KACsD;CACtD,MAAM,UAAU,CAAC,GAAG,GAAG;CACvB,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,8BAAc,IAAI,IAAY;CACpC,IAAI;CACJ,MAAM,oBAAoB,WAAuC;EAC/D,oBAAoB,IAAI,IACtB,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,SAAS,eAC/C,WAAW,MAAM,KAAK,SAAS,CAAC,KAAK,QAAQ,WAAW,EAAE,CAAU,CACtE,CACF;EACA,OAAO,gBAAgB,IAAI,MAAM;CACnC;CACA,KAAK,IAAI,KAAK,QAAQ,IAAI,GAAG,OAAO,KAAA,GAAW,KAAK,QAAQ,IAAI,GAAG;EACjE,IAAI,UAAU,IAAI,EAAE,GAAG;EACvB,MAAM,WAAW,MAAM,UAAU,IAAI,EAAE;EACvC,IAAI,CAAC,UAAU;EACf,UAAU,IAAI,EAAE;EAChB,YAAY,IAAI,SAAS,YAAY;EACrC,KAAK,MAAM,SAAS,OAAO,OAAO,SAAS,YAAY,GAAG;GACxD,UAAU,SAAS,wBAAwB,KAAK,CAAC;GAEjD,IAAI,CAAC,2BAA2B,KAAK,GAAG;GACxC,KAAK,MAAM,UAAU,MAAM,OAAO;IAChC,MAAM,aAAa,iBAAiB,MAAM;IAC1C,IAAI,YAAY,YAAY,IAAI,UAAU;GAC5C;EACF;CACF;CACA,OAAO;EAAE;EAAW;CAAY;AAClC"}
@@ -36,7 +36,8 @@ function prepareNodeTransfer(source, refs) {
36
36
  result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {
37
37
  node,
38
38
  variable,
39
- collection: (id) => refs.collections.get(id)
39
+ collection: (id) => refs.collections.get(id),
40
+ property: (id) => refs.properties.get(id)
40
41
  });
41
42
  Object.assign(result, remappedResourceReferences(source, {
42
43
  variable,
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.js","names":["required"],"sources":["../../src/transfer/nodes.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'\nimport { referencedStyleIds } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { requireTransferReference as required } from './references'\nimport { remappedResourceReferences } from './resources'\nimport type { VariableTransferReferences } from './variables'\n\nexport function semanticTransferReferences(node: SceneNode): string[] {\n const runs = styleRunReferences(node.styleRuns)\n return [\n ...(node.componentId ? [node.componentId] : []),\n ...Object.values(node.boundVariables),\n ...runs.variables,\n ...referencedStyleIds(node),\n ...Object.entries(node.componentPropertyAssignments).flatMap(([id, value]) => [id, value]),\n ...node.componentPropertyReferences.map((reference) => reference.propertyId),\n ...node.componentPropertyDefinitions.flatMap((definition) => [\n definition.id,\n ...(definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? [definition.defaultValue]\n : [])\n ]),\n ...node.instanceOverrides.descendants.keys(),\n ...[\n ...node.instanceOverrides.self,\n ...[...node.instanceOverrides.descendants.values()].flatMap((fields) => [...fields])\n ].flatMap(([field, value]) =>\n typeof value === 'string' &&\n (field === 'componentId' ||\n field === 'sourceComponentId' ||\n overriddenBindingField(field) !== null)\n ? [value]\n : []\n )\n ]\n}\n\nexport interface NodeTransferReferences extends VariableTransferReferences {\n nodes: ReadonlyMap<string, string>\n styles: ReadonlyMap<string, string>\n properties: ReadonlyMap<string, string>\n propertyTypes: ReadonlyMap<string, ComponentPropertyType>\n}\n\n/** Prepare runtime references without rewriting original format identities or ordinary text. */\nexport function prepareNodeTransfer(\n source: SceneNode,\n refs: NodeTransferReferences\n): Partial<SceneNode> {\n const node = (id: string) => required(refs.nodes, id, 'node')\n const variable = (id: string) => required(refs.variables, id, 'variable')\n const property = (id: string) => required(refs.properties, id, 'property')\n const style = (id: string) => required(refs.styles, id, 'style')\n const propertyValue = (id: string, value: string): string => {\n const type = refs.propertyTypes.get(id)\n if (!type) throw new Error(`Missing property transfer type: ${id}`)\n return type === 'INSTANCE_SWAP' && value ? node(value) : value\n }\n const values = (entries: Record<string, string>) =>\n Object.fromEntries(\n Object.entries(entries).map(([id, value]) => [property(id), propertyValue(id, value)])\n )\n const result = cloneNodeProps(source, null)\n result.componentId = source.componentId ? node(source.componentId) : null\n result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {\n node,\n variable,\n collection: (id) => refs.collections.get(id)\n })\n Object.assign(\n result,\n remappedResourceReferences(source, {\n variable,\n collection: (id) => required(refs.collections, id, 'collection'),\n mode: (id) => required(refs.modes, id, 'mode'),\n style,\n // A link to a layer the transfer leaves behind keeps naming it.\n layer: (id) => refs.nodes.get(id) ?? id\n })\n )\n // A connector keeps the layers it was attached to when they are left behind; the end becomes\n // free where nothing by that ID exists, as a pasted Figma connector does.\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = result[field]\n if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId\n }\n result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({\n ...structuredClone(definition),\n id: property(definition.id),\n defaultValue: propertyValue(definition.id, definition.defaultValue)\n }))\n // A reference to a property that neither the transfer nor its destination defines names nothing.\n result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {\n const propertyId = refs.properties.get(reference.propertyId)\n return propertyId ? [{ ...reference, propertyId }] : []\n })\n result.componentPropertyAssignments = values(source.componentPropertyAssignments)\n // Variant values are keyed by display names, unlike definition-ID assignments.\n result.componentPropertyValues = { ...source.componentPropertyValues }\n return result\n}\n"],"mappings":";;;;;;;AASA,SAAgB,2BAA2B,MAA2B;CACpE,MAAM,OAAO,mBAAmB,KAAK,SAAS;CAC9C,OAAO;EACL,GAAI,KAAK,cAAc,CAAC,KAA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CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,SAAS,EAAE,GAAG,cAAc,IAAI,KAAK,CAAC,CAAC,CACvF;CACF,MAAM,SAAS,eAAe,QAAQ,IAAI;CAC1C,OAAO,cAAc,OAAO,cAAc,KAAK,OAAO,WAAW,IAAI;CACrE,OAAO,oBAAoB,2BAA2B,OAAO,mBAAmB;EAC9E;EACA;EACA,aAAa,OAAO,KAAK,YAAY,IAAI,EAAE;CAC7C,CAAC;CACD,OAAO,OACL,QACA,2BAA2B,QAAQ;EACjC;EACA,aAAa,OAAOA,yBAAS,KAAK,aAAa,IAAI,YAAY;EAC/D,OAAO,OAAOA,yBAAS,KAAK,OAAO,IAAI,MAAM;EAC7C;EAEA,QAAQ,OAAO,KAAK,MAAM,IAAI,EAAE,KAAK;CACvC,CAAC,CACH;CAGA,KAAK,MAAM,SAAS,CAAC,kBAAkB,cAAc,GAAY;EAC/D,MAAM,WAAW,OAAO;EACxB,IAAI,UAAU,QAAQ,SAAS,SAAS,KAAK,MAAM,IAAI,SAAS,MAAM,KAAK,SAAS;CACtF;CACA,OAAO,+BAA+B,OAAO,6BAA6B,KAAK,gBAAgB;EAC7F,GAAG,gBAAgB,UAAU;EAC7B,IAAI,SAAS,WAAW,EAAE;EAC1B,cAAc,cAAc,WAAW,IAAI,WAAW,YAAY;CACpE,EAAE;CAEF,OAAO,8BAA8B,OAAO,4BAA4B,SAAS,cAAc;EAC7F,MAAM,aAAa,KAAK,WAAW,IAAI,UAAU,UAAU;EAC3D,OAAO,aAAa,CAAC;GAAE,GAAG;GAAW;EAAW,CAAC,IAAI,CAAC;CACxD,CAAC;CACD,OAAO,+BAA+B,OAAO,OAAO,4BAA4B;CAEhF,OAAO,0BAA0B,EAAE,GAAG,OAAO,wBAAwB;CACrE,OAAO;AACT"}
1
+ {"version":3,"file":"nodes.js","names":["required"],"sources":["../../src/transfer/nodes.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'\nimport { referencedStyleIds } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { requireTransferReference as required } from './references'\nimport { remappedResourceReferences } from './resources'\nimport type { VariableTransferReferences } from './variables'\n\nexport function semanticTransferReferences(node: SceneNode): string[] {\n const runs = styleRunReferences(node.styleRuns)\n return [\n ...(node.componentId ? [node.componentId] : []),\n ...Object.values(node.boundVariables),\n ...runs.variables,\n ...referencedStyleIds(node),\n ...Object.entries(node.componentPropertyAssignments).flatMap(([id, value]) => [id, value]),\n ...node.componentPropertyReferences.map((reference) => reference.propertyId),\n ...node.componentPropertyDefinitions.flatMap((definition) => [\n definition.id,\n ...(definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? [definition.defaultValue]\n : [])\n ]),\n ...node.instanceOverrides.descendants.keys(),\n ...[\n ...node.instanceOverrides.self,\n ...[...node.instanceOverrides.descendants.values()].flatMap((fields) => [...fields])\n ].flatMap(([field, value]) =>\n typeof value === 'string' &&\n (field === 'componentId' ||\n field === 'sourceComponentId' ||\n overriddenBindingField(field) !== null)\n ? [value]\n : []\n )\n ]\n}\n\nexport interface NodeTransferReferences extends VariableTransferReferences {\n nodes: ReadonlyMap<string, string>\n styles: ReadonlyMap<string, string>\n properties: ReadonlyMap<string, string>\n propertyTypes: ReadonlyMap<string, ComponentPropertyType>\n}\n\n/** Prepare runtime references without rewriting original format identities or ordinary text. */\nexport function prepareNodeTransfer(\n source: SceneNode,\n refs: NodeTransferReferences\n): Partial<SceneNode> {\n const node = (id: string) => required(refs.nodes, id, 'node')\n const variable = (id: string) => required(refs.variables, id, 'variable')\n const property = (id: string) => required(refs.properties, id, 'property')\n const style = (id: string) => required(refs.styles, id, 'style')\n const propertyValue = (id: string, value: string): string => {\n const type = refs.propertyTypes.get(id)\n if (!type) throw new Error(`Missing property transfer type: ${id}`)\n return type === 'INSTANCE_SWAP' && value ? node(value) : value\n }\n const values = (entries: Record<string, string>) =>\n Object.fromEntries(\n Object.entries(entries).map(([id, value]) => [property(id), propertyValue(id, value)])\n )\n const result = cloneNodeProps(source, null)\n result.componentId = source.componentId ? node(source.componentId) : null\n result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {\n node,\n variable,\n collection: (id) => refs.collections.get(id),\n property: (id) => refs.properties.get(id)\n })\n Object.assign(\n result,\n remappedResourceReferences(source, {\n variable,\n collection: (id) => required(refs.collections, id, 'collection'),\n mode: (id) => required(refs.modes, id, 'mode'),\n style,\n // A link to a layer the transfer leaves behind keeps naming it.\n layer: (id) => refs.nodes.get(id) ?? id\n })\n )\n // A connector keeps the layers it was attached to when they are left behind; the end becomes\n // free where nothing by that ID exists, as a pasted Figma connector does.\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = result[field]\n if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId\n }\n result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({\n ...structuredClone(definition),\n id: property(definition.id),\n defaultValue: propertyValue(definition.id, definition.defaultValue)\n }))\n // A reference to a property that neither the transfer nor its destination defines names nothing.\n result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {\n const propertyId = refs.properties.get(reference.propertyId)\n return propertyId ? [{ ...reference, propertyId }] : []\n })\n result.componentPropertyAssignments = values(source.componentPropertyAssignments)\n // Variant values are keyed by display names, unlike definition-ID assignments.\n result.componentPropertyValues = { ...source.componentPropertyValues }\n return result\n}\n"],"mappings":";;;;;;;AASA,SAAgB,2BAA2B,MAA2B;CACpE,MAAM,OAAO,mBAAmB,KAAK,SAAS;CAC9C,OAAO;EACL,GAAI,KAAK,cAAc,CAAC,KAAK,WAAW,IAAI,CAAC;EAC7C,GAAG,OAAO,OAAO,KAAK,cAAc;EACpC,GAAG,KAAK;EACR,GAAG,mBAAmB,IAAI;EAC1B,GAAG,OAAO,QAAQ,KAAK,4BAA4B,CAAC,CAAC,SAAS,CAAC,I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