@pairdraw/core 0.16.0 → 0.16.2

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 (145) hide show
  1. package/README.md +1 -1
  2. package/dist/ai/providers.d.ts +6 -1
  3. package/dist/ai/providers.d.ts.map +1 -1
  4. package/dist/ai/providers.js +9 -0
  5. package/dist/ai/providers.js.map +1 -1
  6. package/dist/canvas/highlight-rect.d.ts +10 -1
  7. package/dist/canvas/highlight-rect.d.ts.map +1 -1
  8. package/dist/canvas/highlight-rect.js +16 -8
  9. package/dist/canvas/highlight-rect.js.map +1 -1
  10. package/dist/canvas/index.d.ts +2 -3
  11. package/dist/canvas/index.js +1 -2
  12. package/dist/canvas/issues/draw.d.ts +2 -6
  13. package/dist/canvas/issues/draw.d.ts.map +1 -1
  14. package/dist/canvas/issues/draw.js +2 -99
  15. package/dist/canvas/issues/draw.js.map +1 -1
  16. package/dist/canvas/issues/types.d.ts +2 -33
  17. package/dist/canvas/issues/types.d.ts.map +1 -1
  18. package/dist/canvas/overlays/{ai.d.ts → ai/draw.d.ts} +3 -3
  19. package/dist/canvas/overlays/ai/draw.d.ts.map +1 -0
  20. package/dist/canvas/overlays/ai/draw.js +102 -0
  21. package/dist/canvas/overlays/ai/draw.js.map +1 -0
  22. package/dist/canvas/overlays/ai/motion.d.ts +23 -0
  23. package/dist/canvas/overlays/ai/motion.d.ts.map +1 -0
  24. package/dist/canvas/overlays/ai/motion.js +32 -0
  25. package/dist/canvas/overlays/ai/motion.js.map +1 -0
  26. package/dist/canvas/renderer/methods.js +1 -1
  27. package/dist/canvas/renderer/methods.js.map +1 -1
  28. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  29. package/dist/canvas/renderer/overlay-pass.js +2 -47
  30. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  31. package/dist/canvas/renderer/pipeline.js +1 -1
  32. package/dist/canvas/renderer/pipeline.js.map +1 -1
  33. package/dist/canvas/renderer/state.d.ts +5 -3
  34. package/dist/canvas/renderer/state.d.ts.map +1 -1
  35. package/dist/canvas/renderer/state.js +18 -6
  36. package/dist/canvas/renderer/state.js.map +1 -1
  37. package/dist/canvas/renderer/types.d.ts +2 -2
  38. package/dist/canvas/renderer/types.d.ts.map +1 -1
  39. package/dist/canvas/renderer.d.ts +12 -8
  40. package/dist/canvas/renderer.d.ts.map +1 -1
  41. package/dist/canvas/renderer.js +9 -9
  42. package/dist/canvas/renderer.js.map +1 -1
  43. package/dist/canvas/text/preparation/cache.d.ts +5 -0
  44. package/dist/canvas/text/preparation/cache.d.ts.map +1 -1
  45. package/dist/canvas/text/preparation/cache.js +8 -1
  46. package/dist/canvas/text/preparation/cache.js.map +1 -1
  47. package/dist/constants.d.ts +13 -18
  48. package/dist/constants.d.ts.map +1 -1
  49. package/dist/constants.js +16 -21
  50. package/dist/constants.js.map +1 -1
  51. package/dist/design-jsx/index.d.ts +2 -2
  52. package/dist/design-jsx/index.js +2 -2
  53. package/dist/design-jsx/preview/picture.d.ts +12 -5
  54. package/dist/design-jsx/preview/picture.d.ts.map +1 -1
  55. package/dist/design-jsx/preview/picture.js +40 -15
  56. package/dist/design-jsx/preview/picture.js.map +1 -1
  57. package/dist/editor/bridges/undo.d.ts +1 -1
  58. package/dist/editor/create.d.ts +3 -6
  59. package/dist/editor/create.d.ts.map +1 -1
  60. package/dist/editor/history/atomic-tool.d.ts.map +1 -1
  61. package/dist/editor/history/atomic-tool.js +11 -8
  62. package/dist/editor/history/atomic-tool.js.map +1 -1
  63. package/dist/editor/history/document-change.d.ts +9 -1
  64. package/dist/editor/history/document-change.d.ts.map +1 -1
  65. package/dist/editor/history/document-change.js +100 -2
  66. package/dist/editor/history/document-change.js.map +1 -1
  67. package/dist/editor/history/snapshot/graph.d.ts +15 -3
  68. package/dist/editor/history/snapshot/graph.d.ts.map +1 -1
  69. package/dist/editor/history/snapshot/graph.js +29 -8
  70. package/dist/editor/history/snapshot/graph.js.map +1 -1
  71. package/dist/editor/index.d.ts +3 -3
  72. package/dist/editor/index.js +3 -3
  73. package/dist/editor/issues.d.ts +1 -4
  74. package/dist/editor/issues.d.ts.map +1 -1
  75. package/dist/editor/issues.js +5 -44
  76. package/dist/editor/issues.js.map +1 -1
  77. package/dist/editor/nudge.js +3 -2
  78. package/dist/editor/nudge.js.map +1 -1
  79. package/dist/editor/read-only/actions.js +0 -3
  80. package/dist/editor/read-only/actions.js.map +1 -1
  81. package/dist/editor/state/shared.js +1 -1
  82. package/dist/editor/state/shared.js.map +1 -1
  83. package/dist/editor/types.d.ts +7 -4
  84. package/dist/editor/types.d.ts.map +1 -1
  85. package/dist/index.d.ts +3 -3
  86. package/dist/index.js +3 -3
  87. package/dist/io/subgraph.d.ts +5 -2
  88. package/dist/io/subgraph.d.ts.map +1 -1
  89. package/dist/io/subgraph.js +6 -2
  90. package/dist/io/subgraph.js.map +1 -1
  91. package/dist/layout/mutations.d.ts +1 -1
  92. package/dist/layout/mutations.d.ts.map +1 -1
  93. package/dist/layout/mutations.js +1 -1
  94. package/dist/layout/mutations.js.map +1 -1
  95. package/dist/text/font/faces.js +1 -1
  96. package/dist/text/font/faces.js.map +1 -1
  97. package/dist/text/web-font/providers.d.ts +2 -11
  98. package/dist/text/web-font/providers.d.ts.map +1 -1
  99. package/dist/text/web-font/providers.js +8 -7
  100. package/dist/text/web-font/providers.js.map +1 -1
  101. package/dist/tools/analyze/diff/jsx.d.ts +2 -1
  102. package/dist/tools/analyze/diff/jsx.d.ts.map +1 -1
  103. package/dist/tools/analyze/diff/jsx.js +4 -2
  104. package/dist/tools/analyze/diff/jsx.js.map +1 -1
  105. package/package.json +24 -9
  106. package/src/ai/providers.ts +15 -1
  107. package/src/canvas/highlight-rect.ts +30 -9
  108. package/src/canvas/index.ts +1 -15
  109. package/src/canvas/issues/draw.ts +2 -165
  110. package/src/canvas/issues/types.ts +1 -36
  111. package/src/canvas/overlays/ai/draw.ts +129 -0
  112. package/src/canvas/overlays/ai/motion.ts +46 -0
  113. package/src/canvas/renderer/methods.ts +1 -1
  114. package/src/canvas/renderer/overlay-pass.ts +2 -49
  115. package/src/canvas/renderer/pipeline.ts +1 -1
  116. package/src/canvas/renderer/state.ts +20 -5
  117. package/src/canvas/renderer/types.ts +2 -2
  118. package/src/canvas/renderer.ts +9 -10
  119. package/src/canvas/text/preparation/cache.ts +9 -1
  120. package/src/constants.ts +12 -17
  121. package/src/design-jsx/index.ts +1 -1
  122. package/src/design-jsx/preview/picture.ts +55 -18
  123. package/src/editor/history/atomic-tool.ts +15 -8
  124. package/src/editor/history/document-change.ts +117 -1
  125. package/src/editor/history/snapshot/graph.ts +48 -8
  126. package/src/editor/index.ts +10 -2
  127. package/src/editor/issues.ts +6 -36
  128. package/src/editor/nudge.ts +4 -2
  129. package/src/editor/read-only/actions.ts +0 -3
  130. package/src/editor/state/shared.ts +1 -1
  131. package/src/editor/types.ts +6 -4
  132. package/src/io/subgraph.ts +10 -5
  133. package/src/layout/mutations.ts +2 -2
  134. package/src/text/font/faces.ts +1 -1
  135. package/src/text/web-font/providers.ts +19 -13
  136. package/src/tools/analyze/diff/jsx.ts +10 -5
  137. package/dist/canvas/issues/layout.d.ts +0 -37
  138. package/dist/canvas/issues/layout.d.ts.map +0 -1
  139. package/dist/canvas/issues/layout.js +0 -303
  140. package/dist/canvas/issues/layout.js.map +0 -1
  141. package/dist/canvas/overlays/ai.d.ts.map +0 -1
  142. package/dist/canvas/overlays/ai.js +0 -26
  143. package/dist/canvas/overlays/ai.js.map +0 -1
  144. package/src/canvas/issues/layout.ts +0 -376
  145. package/src/canvas/overlays/ai.ts +0 -34
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/read-only/actions.ts"],"sourcesContent":["/**\n * Editor actions a read-only document still offers: reading it, selecting, moving around and\n * between pages, previewing, copying, and the canvas's own lifecycle, as Figma keeps while a\n * version is viewed. Every other action changes the document and is refused, so an action added\n * later is refused until it is listed here (`packages/core/tests/editor/read-only.test.ts`).\n */\nexport const READ_ONLY_ACTIONS: ReadonlySet<string> = new Set([\n // Reads\n 'acceptingParent',\n 'acceptsChildren',\n 'canArrangeNodes',\n 'canAutoArrangeNodes',\n 'canConvertToFrame',\n 'canDistributeNodes',\n 'canEditImage',\n 'collectVariantOptions',\n 'componentInstanceCount',\n 'figCompression',\n 'findVariantByValues',\n 'getChildren',\n 'getCollection',\n 'getCollectionCount',\n 'getCollections',\n 'getComponentPropertyAuthoring',\n 'getComponentPropertyBindings',\n 'getComponentSetPropertyDefs',\n 'getComponentSetVariantConflicts',\n 'getDefaultVariantForComponentSet',\n 'getExposableInstances',\n 'getImage',\n 'getInstanceComponentPropertyDefinitions',\n 'getInstanceComponentPropertyValue',\n 'getLayerTree',\n 'getNode',\n 'getPages',\n 'getSelectedNode',\n 'getSelectedNodes',\n 'getShownStatus',\n 'getTextHyperlink',\n 'getTextSelectionStyle',\n 'getVariable',\n 'getVariableCount',\n 'getVariablesByType',\n 'getVariablesForCollection',\n 'getVariantOptionAvailability',\n 'getVariantOptions',\n 'hitTestAtPoint',\n 'hyperlinkAtPoint',\n 'isInteractiveEditing',\n 'isTopLevel',\n 'pageSwitchCount',\n 'previewRenameSelected',\n 'scaleSelectionBounds',\n // Recording only: what the edit runs is refused or allowed on its own.\n 'recordEdit',\n 'recordEditAsync',\n 'resolveColorVariable',\n 'resolveNumberVariable',\n 'replaceableInstanceLayers',\n 'screenToCanvas',\n 'selectionSpacing',\n 'snapshotPage',\n 'statusWorkflow',\n 'validateComponentSet',\n\n // Selection and hover\n 'clearSelection',\n 'enterContainer',\n 'exitContainer',\n 'select',\n 'selectAll',\n 'selectAtPoint',\n 'selectChildren',\n 'selectInverse',\n 'selectNextSibling',\n 'selectParent',\n 'selectPreviousSibling',\n 'setCodeFocusNode',\n 'setHoveredNode',\n 'setMarquee',\n 'setMeasurementMode',\n 'setTool',\n 'validateEnteredContainer',\n\n // Canvas overlays that show without changing anything\n 'clearDesignIssues',\n 'endImageEdit',\n 'setAutoLayoutHover',\n 'setDesignIssueHighlight',\n 'setDesignIssueMarkers',\n 'setDropTarget',\n 'setGuidePreview',\n 'setGuideRedline',\n 'setHoveredGuide',\n 'setHoveredIssueMarker',\n 'setLayoutInsertIndicator',\n 'setRenamingLabel',\n 'setRotationPreview',\n 'setSelectedGuide',\n 'setShapeHandleHover',\n 'setSnapGuides',\n 'setTransforming',\n\n // Viewport and pages\n 'applyZoom',\n 'centerOn',\n 'clearPageViewports',\n 'commitPageSwitch',\n 'focusComponent',\n 'followHyperlink',\n 'goToMainComponent',\n 'pan',\n 'preparePage',\n 'preparePageNodes',\n 'loadPageNodes',\n 'revealNodes',\n 'setZoomAroundPoint',\n 'switchPage',\n 'switchToNextPage',\n 'switchToPreviousPage',\n 'zoomTo100',\n 'zoomToArea',\n 'zoomToBounds',\n 'zoomToFit',\n 'zoomToLevel',\n 'zoomToNextFrame',\n 'zoomToPreviousFrame',\n 'zoomToSelection',\n\n // Preview\n 'leaveCanvasView',\n 'resetPlay',\n 'startPlay',\n 'stopPlay',\n 'togglePlay',\n\n // Presenting the page's slides\n 'fitPresentation',\n 'getPresentation',\n 'getSlides',\n 'presentNextSlide',\n 'presentPreviousSlide',\n 'presentSlide',\n 'scrollPresentation',\n 'setPresentationScale',\n 'startPresentation',\n 'stopPresentation',\n 'togglePresentation',\n\n // Shader Mode: looking at one shader; tuning it is an edit, refused like any other\n 'canStartShaderMode',\n 'getShaderMode',\n 'startShaderMode',\n 'stopShaderMode',\n 'toggleShaderMode',\n\n // Copying out\n 'copySelectionAsHTML',\n 'copySelectionAsJSX',\n 'copySelectionAsSVG',\n 'copySelectionAsText',\n 'prepareCopy',\n\n // Ending what was in progress\n 'cancelNodePreviews',\n 'flushNudge',\n 'penCancel',\n 'pencilCancel',\n\n // Canvas, layout, and document lifecycle\n 'beginInteractiveEdit',\n 'dispose',\n 'drawPageShaderFrames',\n 'hasShaderRasterizer',\n 'loadFontsForNodes',\n 'onEditorEvent',\n 'refreshDocumentSettings',\n 'refreshVariables',\n 'releaseGraphResources',\n 'removeCanvasRenderer',\n 'replaceGraph',\n 'requestRefresh',\n 'requestRender',\n 'requestRepaint',\n 'runLayoutForNode',\n 'setCanvasKit',\n 'setNavigationPhase',\n 'setReadOnly',\n 'setShaderRasterizer',\n 'settleShaderFrames',\n 'subscribeToGraph',\n 'textSelectionChanged'\n])\n"],"mappings":";;;;;;;AAMA,MAAa,oCAAyC,IAAI,IAAI;CAE5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"actions.js","names":[],"sources":["../../../src/editor/read-only/actions.ts"],"sourcesContent":["/**\n * Editor actions a read-only document still offers: reading it, selecting, moving around and\n * between pages, previewing, copying, and the canvas's own lifecycle, as Figma keeps while a\n * version is viewed. Every other action changes the document and is refused, so an action added\n * later is refused until it is listed here (`packages/core/tests/editor/read-only.test.ts`).\n */\nexport const READ_ONLY_ACTIONS: ReadonlySet<string> = new Set([\n // Reads\n 'acceptingParent',\n 'acceptsChildren',\n 'canArrangeNodes',\n 'canAutoArrangeNodes',\n 'canConvertToFrame',\n 'canDistributeNodes',\n 'canEditImage',\n 'collectVariantOptions',\n 'componentInstanceCount',\n 'figCompression',\n 'findVariantByValues',\n 'getChildren',\n 'getCollection',\n 'getCollectionCount',\n 'getCollections',\n 'getComponentPropertyAuthoring',\n 'getComponentPropertyBindings',\n 'getComponentSetPropertyDefs',\n 'getComponentSetVariantConflicts',\n 'getDefaultVariantForComponentSet',\n 'getExposableInstances',\n 'getImage',\n 'getInstanceComponentPropertyDefinitions',\n 'getInstanceComponentPropertyValue',\n 'getLayerTree',\n 'getNode',\n 'getPages',\n 'getSelectedNode',\n 'getSelectedNodes',\n 'getShownStatus',\n 'getTextHyperlink',\n 'getTextSelectionStyle',\n 'getVariable',\n 'getVariableCount',\n 'getVariablesByType',\n 'getVariablesForCollection',\n 'getVariantOptionAvailability',\n 'getVariantOptions',\n 'hitTestAtPoint',\n 'hyperlinkAtPoint',\n 'isInteractiveEditing',\n 'isTopLevel',\n 'pageSwitchCount',\n 'previewRenameSelected',\n 'scaleSelectionBounds',\n // Recording only: what the edit runs is refused or allowed on its own.\n 'recordEdit',\n 'recordEditAsync',\n 'resolveColorVariable',\n 'resolveNumberVariable',\n 'replaceableInstanceLayers',\n 'screenToCanvas',\n 'selectionSpacing',\n 'snapshotPage',\n 'statusWorkflow',\n 'validateComponentSet',\n\n // Selection and hover\n 'clearSelection',\n 'enterContainer',\n 'exitContainer',\n 'select',\n 'selectAll',\n 'selectAtPoint',\n 'selectChildren',\n 'selectInverse',\n 'selectNextSibling',\n 'selectParent',\n 'selectPreviousSibling',\n 'setCodeFocusNode',\n 'setHoveredNode',\n 'setMarquee',\n 'setMeasurementMode',\n 'setTool',\n 'validateEnteredContainer',\n\n // Canvas overlays that show without changing anything\n 'endImageEdit',\n 'setAutoLayoutHover',\n 'setDesignIssueHighlight',\n 'setDropTarget',\n 'setGuidePreview',\n 'setGuideRedline',\n 'setHoveredGuide',\n 'setLayoutInsertIndicator',\n 'setRenamingLabel',\n 'setRotationPreview',\n 'setSelectedGuide',\n 'setShapeHandleHover',\n 'setSnapGuides',\n 'setTransforming',\n\n // Viewport and pages\n 'applyZoom',\n 'centerOn',\n 'clearPageViewports',\n 'commitPageSwitch',\n 'focusComponent',\n 'followHyperlink',\n 'goToMainComponent',\n 'pan',\n 'preparePage',\n 'preparePageNodes',\n 'loadPageNodes',\n 'revealNodes',\n 'setZoomAroundPoint',\n 'switchPage',\n 'switchToNextPage',\n 'switchToPreviousPage',\n 'zoomTo100',\n 'zoomToArea',\n 'zoomToBounds',\n 'zoomToFit',\n 'zoomToLevel',\n 'zoomToNextFrame',\n 'zoomToPreviousFrame',\n 'zoomToSelection',\n\n // Preview\n 'leaveCanvasView',\n 'resetPlay',\n 'startPlay',\n 'stopPlay',\n 'togglePlay',\n\n // Presenting the page's slides\n 'fitPresentation',\n 'getPresentation',\n 'getSlides',\n 'presentNextSlide',\n 'presentPreviousSlide',\n 'presentSlide',\n 'scrollPresentation',\n 'setPresentationScale',\n 'startPresentation',\n 'stopPresentation',\n 'togglePresentation',\n\n // Shader Mode: looking at one shader; tuning it is an edit, refused like any other\n 'canStartShaderMode',\n 'getShaderMode',\n 'startShaderMode',\n 'stopShaderMode',\n 'toggleShaderMode',\n\n // Copying out\n 'copySelectionAsHTML',\n 'copySelectionAsJSX',\n 'copySelectionAsSVG',\n 'copySelectionAsText',\n 'prepareCopy',\n\n // Ending what was in progress\n 'cancelNodePreviews',\n 'flushNudge',\n 'penCancel',\n 'pencilCancel',\n\n // Canvas, layout, and document lifecycle\n 'beginInteractiveEdit',\n 'dispose',\n 'drawPageShaderFrames',\n 'hasShaderRasterizer',\n 'loadFontsForNodes',\n 'onEditorEvent',\n 'refreshDocumentSettings',\n 'refreshVariables',\n 'releaseGraphResources',\n 'removeCanvasRenderer',\n 'replaceGraph',\n 'requestRefresh',\n 'requestRender',\n 'requestRepaint',\n 'runLayoutForNode',\n 'setCanvasKit',\n 'setNavigationPhase',\n 'setReadOnly',\n 'setShaderRasterizer',\n 'settleShaderFrames',\n 'subscribeToGraph',\n 'textSelectionChanged'\n])\n"],"mappings":";;;;;;;AAMA,MAAa,oCAAyC,IAAI,IAAI;CAE5D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
@@ -12,7 +12,7 @@ function createDefaultEditorSharedState() {
12
12
  imageEdit: null,
13
13
  presenceCursors: [],
14
14
  documentName: "Untitled",
15
- designIssues: null,
15
+ designIssueHighlight: null,
16
16
  codeFocusNodeId: null,
17
17
  rulerTheme: void 0,
18
18
  selectionTheme: void 0,
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","names":[],"sources":["../../../src/editor/state/shared.ts"],"sourcesContent":["import { DEFAULT_SNAPPING_PREFERENCES } from '#core/editor/preferences'\nimport type { EditorSharedState } from '#core/editor/types'\n\nexport function createDefaultEditorSharedState(): EditorSharedState {\n return {\n activeTool: 'SELECT',\n shapeWithTextKind: 'SQUARE',\n hostRestrictions: { readOnly: false },\n documentKind: 'design',\n snappingPreferences: { ...DEFAULT_SNAPPING_PREFERENCES },\n showPixelGrid: true,\n gradientEdit: null,\n imageEdit: null,\n presenceCursors: [],\n documentName: 'Untitled',\n designIssues: null,\n codeFocusNodeId: null,\n rulerTheme: undefined,\n selectionTheme: undefined,\n sceneVersion: 0,\n canvasVersion: 0\n }\n}\n"],"mappings":";;AAGA,SAAgB,iCAAoD;CAClE,OAAO;EACL,YAAY;EACZ,mBAAmB;EACnB,kBAAkB,EAAE,UAAU,MAAM;EACpC,cAAc;EACd,qBAAqB,EAAE,GAAG,6BAA6B;EACvD,eAAe;EACf,cAAc;EACd,WAAW;EACX,iBAAiB,CAAC;EAClB,cAAc;EACd,cAAc;EACd,iBAAiB;EACjB,YAAY,KAAA;EACZ,gBAAgB,KAAA;EAChB,cAAc;EACd,eAAe;CACjB;AACF"}
1
+ {"version":3,"file":"shared.js","names":[],"sources":["../../../src/editor/state/shared.ts"],"sourcesContent":["import { DEFAULT_SNAPPING_PREFERENCES } from '#core/editor/preferences'\nimport type { EditorSharedState } from '#core/editor/types'\n\nexport function createDefaultEditorSharedState(): EditorSharedState {\n return {\n activeTool: 'SELECT',\n shapeWithTextKind: 'SQUARE',\n hostRestrictions: { readOnly: false },\n documentKind: 'design',\n snappingPreferences: { ...DEFAULT_SNAPPING_PREFERENCES },\n showPixelGrid: true,\n gradientEdit: null,\n imageEdit: null,\n presenceCursors: [],\n documentName: 'Untitled',\n designIssueHighlight: null,\n codeFocusNodeId: null,\n rulerTheme: undefined,\n selectionTheme: undefined,\n sceneVersion: 0,\n canvasVersion: 0\n }\n}\n"],"mappings":";;AAGA,SAAgB,iCAAoD;CAClE,OAAO;EACL,YAAY;EACZ,mBAAmB;EACnB,kBAAkB,EAAE,UAAU,MAAM;EACpC,cAAc;EACd,qBAAqB,EAAE,GAAG,6BAA6B;EACvD,eAAe;EACf,cAAc;EACd,WAAW;EACX,iBAAiB,CAAC;EAClB,cAAc;EACd,sBAAsB;EACtB,iBAAiB;EACjB,YAAY,KAAA;EACZ,gBAAgB,KAAA;EAChB,cAAc;EACd,eAAe;CACjB;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { GuideOverlayState } from "../canvas/guides/types.js";
2
- import { DesignIssueOverlay } from "../canvas/issues/types.js";
2
+ import { DesignIssueHighlight } from "../canvas/issues/types.js";
3
3
  import { ConnectorTarget } from "./connectors/attach.js";
4
4
  import { RotationPreview } from "../geometry/types.js";
5
5
  import { ShapeHandleKind } from "../geometry/handles/shape.js";
@@ -18,6 +18,7 @@ import { DocumentColorSpace, DocumentKind, SceneGraph, SceneGraphEvents, SceneNo
18
18
  import { ShapeWithTextType } from "@pairdraw/scene-graph/shape-with-text";
19
19
  import { CanvasGuide } from "@pairdraw/scene-graph/guides";
20
20
  import { UndoManager } from "@pairdraw/scene-graph/undo";
21
+ import { SceneMutationImpact } from "@pairdraw/scene-graph/mutation-impact";
21
22
  import { Color as Color$1, Rect, Vector } from "@pairdraw/scene-graph/primitives";
22
23
  import { SnapGuide } from "@pairdraw/scene-graph/snap";
23
24
  //#region src/editor/types.d.ts
@@ -72,8 +73,8 @@ interface EditorSharedState {
72
73
  imageEdit?: ImageEdit | null;
73
74
  presenceCursors: PresenceCursor[];
74
75
  documentName: string;
75
- /** Design check markers and highlight, shared by every canvas pane. */
76
- designIssues: DesignIssueOverlay | null;
76
+ /** The layer a design check issue points at, highlighted in every canvas pane. */
77
+ designIssueHighlight: DesignIssueHighlight | null;
77
78
  /** The layer of the code element around the cursor in a code editor, shown in every pane. */
78
79
  codeFocusNodeId: string | null;
79
80
  rulerTheme?: RulerTheme;
@@ -277,7 +278,9 @@ interface EditorContext {
277
278
  setActiveTool: (tool: Tool) => void;
278
279
  setNavigationPhase: (phase: NavigationPhase, inputAt?: number) => void;
279
280
  runLayoutForNode: (id: string) => void;
280
- runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string, beforeLayout?: (result: T) => Promise<void> | void) => Promise<T>;
281
+ runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string,
282
+ /** Runs once the operation is done and before layout, with the layers it touched. */
283
+ beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void) => Promise<T>;
281
284
  subscribeToGraph: () => void;
282
285
  }
283
286
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/editor/types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;KAqCY;;;;;;UAuBK;EACf;EACA;EACA;;EAEA;;;UAIe;EACf;;EAEA;;;UAIe;EACf;;EAEA;;EAEA,QAAQ;;EAER;;EAEA,SAAS;;UAGM;EACf,YAAY;;EAEZ,mBAAmB;;;;;;EAMnB,cAAc;EACd,kBAAkB;EAClB,qBAAqB;;EAErB;;EAEA,eAAe;;EAEf,YAAY;EACZ,iBAAiB;EACjB;;EAEA,cAAc;;EAEd;EACA,aAAa;;EAEb,iBAAiB;;EAEjB,QAAQ;;EAER;;;;;EAKA;;;;;;UAOe;EACf,SAAS;;EAET;;EAEA,UAAU;IAAQ;IAAe;;;UAGlB;EACf,QAAQ;;EAER;;EAEA;IAAW,OAAO;IAAO;;;UAGV;EACf;EACA,aAAa;EACb,SAAS;EACT,YAAY;EACZ,QAAQ;EACR,iBAAiB;EACjB;EACA;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;EAEA;EACA,iBAAiB;EACjB;;EAEA;EACA;IACE,UAAU;IACV,UAAU;IACV,aAAa;IACb,qBAAqB;IACrB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SAAS;EAC7B,qBAAqB;EACrB;;EAEA;EACA;EACA;EACA,gBAAgB,UAAU,iBAAiB,OAAO,GAAG,SAAS,aAAa;EAC3E,kBAAkB,UAAU,iBAC1B,OAAO,MACJ,MAAM,WAAW,aAAa;EAEnC,iBAAiB,KAAK;EACtB,gBAAgB,MAAM;EACtB,qBAAqB,OAAO,iBAAiB;EAC7C,mBAAmB;EACnB,wBAAwB,GACtB,iBAAiB,IAAI,QAAQ,IAC7B,qBACA,gBAAgB,QAAQ,MAAM,yBAC3B,QAAQ;EACb"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/editor/types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;KAsCY;;;;;;UAuBK;EACf;EACA;EACA;;EAEA;;;UAIe;EACf;;EAEA;;;UAIe;EACf;;EAEA;;EAEA,QAAQ;;EAER;;EAEA,SAAS;;UAGM;EACf,YAAY;;EAEZ,mBAAmB;;;;;;EAMnB,cAAc;EACd,kBAAkB;EAClB,qBAAqB;;EAErB;;EAEA,eAAe;;EAEf,YAAY;EACZ,iBAAiB;EACjB;;EAEA,sBAAsB;;EAEtB;EACA,aAAa;;EAEb,iBAAiB;;EAEjB,QAAQ;;EAER;;;;;EAKA;;;;;;UAOe;EACf,SAAS;;EAET;;EAEA,UAAU;IAAQ;IAAe;;;UAGlB;EACf,QAAQ;;EAER;;EAEA;IAAW,OAAO;IAAO;;;UAGV;EACf;EACA,aAAa;EACb,SAAS;EACT,YAAY;EACZ,QAAQ;EACR,iBAAiB;EACjB;EACA;IACE;IACA;IACA;IACA;IACA;IACA;;EAEF;;EAEA;EACA,iBAAiB;EACjB;;EAEA;EACA;IACE,UAAU;IACV,UAAU;IACV,aAAa;IACb,qBAAqB;IACrB;IACA;IACA;IACA,cAAc;IACd,eAAe;IACf,iBAAiB;;EAEnB;EACA;;EAEA,aAAa;EACb;IACE;IACA;IACA;IACA;;EAEF,kBAAkB;;EAElB,iBAAiB;EACjB;EACA,WAAW;EACX;E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aAAa;EAEnC,iBAAiB,KAAK;EACtB,gBAAgB,MAAM;EACtB,qBAAqB,OAAO,iBAAiB;EAC7C,mBAAmB;EACnB,wBAAwB,GACtB,iBAAiB,IAAI,QAAQ,IAC7B,qBAEA;;EAAA,gBAAgB,QAAQ,GAAG,QAAQ,wBAAwB,yBACxD,QAAQ;EACb"}
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ import { createDocumentGraph } from "./editor/document-settings.js";
13
13
  import { createDefaultEditorSharedState } from "./editor/state/shared.js";
14
14
  import { editedGradient, editedGradientLayout } from "./editor/gradient-edit.js";
15
15
  import { EditedImage, ImageEditModifiers, editableImageFillIndex, editedImage, editedImageLayout, imageEditChanges, imageEditCrops } from "./editor/image-edit.js";
16
- import { DocumentChange, isEmptyDocumentChange } from "./editor/history/document-change.js";
16
+ import { DocumentChange, isEmptyDocumentChange, touchedTopLevelIds } from "./editor/history/document-change.js";
17
17
  import { RecordEditOptions } from "./editor/history/edit.js";
18
18
  import { PageSnapshot } from "./editor/history/snapshot/page.js";
19
19
  import { MovePlace } from "./editor/undo.js";
@@ -34,7 +34,7 @@ import { createDefaultEditorState } from "./editor/state/index.js";
34
34
  import { Editor, createEditor } from "./editor/create.js";
35
35
  import { syncEditedComponents } from "./editor/component-sync.js";
36
36
  import { executeAtomicTool } from "./editor/history/atomic-tool.js";
37
- import { graphFromDocumentChange, graphFromPageSnapshot } from "./editor/history/snapshot/graph.js";
37
+ import { graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange } from "./editor/history/snapshot/graph.js";
38
38
  import { pastedPropertyChanges } from "./editor/clipboard/paste/properties.js";
39
39
  import { resolvePasteTarget } from "./editor/clipboard/paste/target.js";
40
40
  import { playIslandRoots } from "./editor/play/islands.js";
@@ -52,4 +52,4 @@ import { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, EDITOR_TOOLS, EditorToolDef, TOOL_SH
52
52
  import { newLayerDefaults } from "./editor/shapes/defaults.js";
53
53
  import { RenameSelectionOptions, RenameSelectionPreview } from "./editor/structure/rename.js";
54
54
  import "./editor/index.js";
55
- export { type AttachModifiers, BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, type CanvasView, type ClipboardCollectionDependency, type ClipboardConflictResolution, type ClipboardImageResolution, type ClipboardImportChoice, type ClipboardImportPlan, type ClipboardPayload, type ClipboardSnapshot, type ClipboardStyleDependency, type CopyOptions, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, type DocumentChange, EDITOR_TOOLS, EDIT_VIEW, type EditedImage, type Editor, type EditorContext, type EditorEventName, type EditorEvents, type EditorOptions, type EditorProfile, type EditorProfileInputs, type EditorRestrictions, type EditorSharedState, type EditorState, type EditorToolDef, type EditorViewState, type ExposableComponentField, type FigmaClipboardImageResolver, type GradientEdit, type HyperlinkHit, type ImageEdit, type ImageEditModifiers, type InstanceState, type LayerType, type MovePlace, type NodeEditCapability, type NodePreview, type PageSnapshot, type PageSwitchProgress, type PreparePageOptions, type PreparedPage, type PresentationScale, type PresentationState, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, type RecordEditOptions, type RenameSelectionOptions, type RenameSelectionPreview, type RescaleSnapshot, type ResumedPath, SCALE_ANCHORS, type ScaleAnchor, type ScaleSession, type SelectionColor, type SelectionSpacing, type ShaderModeState, type ShaderModeTarget, type ShaderPaintList, type ShaderRasterizer, type ShaderView, type ShapeHandleHover, type SlideMoveTarget, type SnappingPreferences, type SwitchPageOptions, TOOL_SHORTCUTS, type TextHyperlinkState, type Tool, type VariableTokenFields, type VariantConflict, type VariantMutationResult, type VariantValidationIssue, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents };
55
+ export { type AttachModifiers, BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, type CanvasView, type ClipboardCollectionDependency, type ClipboardConflictResolution, type ClipboardImageResolution, type ClipboardImportChoice, type ClipboardImportPlan, type ClipboardPayload, type ClipboardSnapshot, type ClipboardStyleDependency, type CopyOptions, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, type DocumentChange, EDITOR_TOOLS, EDIT_VIEW, type EditedImage, type Editor, type EditorContext, type EditorEventName, type EditorEvents, type EditorOptions, type EditorProfile, type EditorProfileInputs, type EditorRestrictions, type EditorSharedState, type EditorState, type EditorToolDef, type EditorViewState, type ExposableComponentField, type FigmaClipboardImageResolver, type GradientEdit, type HyperlinkHit, type ImageEdit, type ImageEditModifiers, type InstanceState, type LayerType, type MovePlace, type NodeEditCapability, type NodePreview, type PageSnapshot, type PageSwitchProgress, type PreparePageOptions, type PreparedPage, type PresentationScale, type PresentationState, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, type RecordEditOptions, type RenameSelectionOptions, type RenameSelectionPreview, type RescaleSnapshot, type ResumedPath, SCALE_ANCHORS, type ScaleAnchor, type ScaleSession, type SelectionColor, type SelectionSpacing, type ShaderModeState, type ShaderModeTarget, type ShaderPaintList, type ShaderRasterizer, type ShaderView, type ShapeHandleHover, type SlideMoveTarget, type SnappingPreferences, type SwitchPageOptions, TOOL_SHORTCUTS, type TextHyperlinkState, type Tool, type VariableTokenFields, type VariantConflict, type VariantMutationResult, type VariantValidationIssue, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents, touchedTopLevelIds };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import { createDocumentGraph } from "./editor/document-settings.js";
13
13
  import { createDefaultEditorSharedState } from "./editor/state/shared.js";
14
14
  import { replaceSelectionColor, selectionColors, selectionColorsShown } from "./editor/selection/colors.js";
15
15
  import { copyEditorViewState, createDefaultEditorViewState, pickEditorViewState } from "./editor/state/view.js";
16
- import { isEmptyDocumentChange } from "./editor/history/document-change.js";
16
+ import { isEmptyDocumentChange, touchedTopLevelIds } from "./editor/history/document-change.js";
17
17
  import { resolvePasteTarget } from "./editor/clipboard/paste/target.js";
18
18
  import { clipboardImportHasConflicts, clipboardImportHasDependencies, planClipboardImport } from "./editor/clipboard/conflicts.js";
19
19
  import { reapplyInstanceComponentProperties } from "./editor/components/properties.js";
@@ -30,6 +30,6 @@ import { layerTypeOptions } from "./editor/structure/layer-type.js";
30
30
  import { createTextActions } from "./editor/text.js";
31
31
  import { createEditor } from "./editor/create.js";
32
32
  import { executeAtomicTool } from "./editor/history/atomic-tool.js";
33
- import { graphFromDocumentChange, graphFromPageSnapshot } from "./editor/history/snapshot/graph.js";
33
+ import { graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange } from "./editor/history/snapshot/graph.js";
34
34
  import { resolvePlayState } from "./editor/play/states.js";
35
- export { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, EDITOR_TOOLS, EDIT_VIEW, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, SCALE_ANCHORS, TOOL_SHORTCUTS, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents };
35
+ export { BOARD_TOOLS, BOARD_TOOL_SHORTCUTS, DEFAULT_SCALE_ANCHOR, DEFAULT_SNAPPING_PREFERENCES, EDITOR_TOOLS, EDIT_VIEW, ReadOnlyDocumentError, ReadOnlyLibraryDefinitionError, SCALE_ANCHORS, TOOL_SHORTCUTS, assertNodeEditable, clipboardImportHasConflicts, clipboardImportHasDependencies, copyEditorViewState, createDefaultEditorSharedState, createDefaultEditorState, createDefaultEditorViewState, createDocumentGraph, createEditor, createGuideActions, createTextActions, editableImageFillIndex, editedGradient, editedGradientLayout, editedImage, editedImageLayout, executeAtomicTool, findShaderModeTarget, getNodeEditCapability, graphFromDocumentChange, graphFromPageSnapshot, graphsFromDocumentChange, imageEditChanges, imageEditCrops, isEmptyDocumentChange, isScaleAnchor, layerTypeOptions, newLayerDefaults, opacityFromBuffer, pageSlides, parseScaleFactor, pastedPropertyChanges, pickEditorViewState, planClipboardImport, playIslandRoots, presentationViewport, reapplyInstanceComponentProperties, replaceSelectionColor, rescaleNodes, resizedPathTextGlyphs, resolveEditorProfile, resolvePasteTarget, resolvePlayState, scaleAnchorFraction, scaleAnchorPoint, scaleFactorForSize, scaledBounds, selectionColors, selectionColorsShown, slideMoveTarget, syncEditedComponents, touchedTopLevelIds };
@@ -18,8 +18,11 @@ interface ExtractedGraph {
18
18
  declare function findPageId(source: SceneGraph, nodeId: string): string | null;
19
19
  /** The page child containing `nodeId`, or the node itself when it is a page child. */
20
20
  declare function findPageChildId(source: SceneGraph, nodeId: string): string | null;
21
- /** Clone `pageId` with only the subtrees of `nodeIds` (none keeps an empty page) and their dependencies. */
22
- declare function extractPageContext(source: SceneGraph, pageId: string, nodeIds: string[], options?: ExtractOptions): SceneGraph;
21
+ /**
22
+ * Clone `pageId`, or each of several pages, with only the subtrees of `nodeIds` (none keeps an
23
+ * empty page) and their dependencies.
24
+ */
25
+ declare function extractPageContext(source: SceneGraph, pageId: string | readonly string[], nodeIds: readonly string[], options?: ExtractOptions): SceneGraph;
23
26
  declare function extractExportGraph(source: SceneGraph, target: ExportTarget): ExtractedGraph;
24
27
  //#endregion
25
28
  export { ExtractOptions, ExtractedGraph, extractExportGraph, extractPageContext, findPageChildId, findPageId };
@@ -1 +1 @@
1
- {"version":3,"file":"subgraph.d.ts","names":[],"sources":["../../src/io/subgraph.ts"],"mappings":";;;UAMiB;;EAEf;;;;;EAKA;;UAGe;EACf,OAAO;EACP;EACA;;iBAmNc,WAAW,QAAQ,YAAY;;iBAY/B,gBAAgB,QAAQ,YAAY;;iBA+DpC,mBACd,QAAQ,YACR,gBACA,mBACA,UAAS,iBACR;iBAMa,mBAAmB,QAAQ,YAAY,QAAQ,eAAe"}
1
+ {"version":3,"file":"subgraph.d.ts","names":[],"sources":["../../src/io/subgraph.ts"],"mappings":";;;UAMiB;;EAEf;;;;;EAKA;;UAGe;EACf,OAAO;EACP;EACA;;iBAqNc,WAAW,QAAQ,YAAY;;iBAY/B,gBAAgB,QAAQ,YAAY;;;;;iBAkEpC,mBACd,QAAQ,YACR,oCACA,4BACA,UAAS,iBACR;iBAMa,mBAAmB,QAAQ,YAAY,QAAQ,eAAe"}
@@ -16,6 +16,7 @@ function includeReferencedStyles(source, ids) {
16
16
  ...styleRunReferences(node.styleRuns).styles
17
17
  ]) if (styleId) referencedStyleIds.add(styleId);
18
18
  }
19
+ if (referencedStyleIds.size === 0) return;
19
20
  for (const node of source.getAllNodes()) if (node.sharedStyleType && node.source.id && referencedStyleIds.has(node.source.id)) ids.add(node.id);
20
21
  }
21
22
  function cloneIntoGraph(source, ids, { shareTables = false } = {}) {
@@ -218,10 +219,13 @@ function rootNodeIds(source) {
218
219
  for (const node of source.nodes.values()) ids.add(node.id);
219
220
  return ids;
220
221
  }
221
- /** Clone `pageId` with only the subtrees of `nodeIds` (none keeps an empty page) and their dependencies. */
222
+ /**
223
+ * Clone `pageId`, or each of several pages, with only the subtrees of `nodeIds` (none keeps an
224
+ * empty page) and their dependencies.
225
+ */
222
226
  function extractPageContext(source, pageId, nodeIds, options = {}) {
223
227
  const ids = collectSelectionIds(source, nodeIds, options);
224
- ids.add(pageId);
228
+ for (const id of typeof pageId === "string" ? [pageId] : pageId) ids.add(id);
225
229
  return cloneIntoGraph(source, ids, options);
226
230
  }
227
231
  function extractExportGraph(source, target) {
@@ -1 +1 @@
1
- {"version":3,"file":"subgraph.js","names":[],"sources":["../../src/io/subgraph.ts"],"sourcesContent":["import { SceneGraph } from '@pairdraw/scene-graph'\nimport { styleRunReferences } from '@pairdraw/scene-graph/text'\nimport { variableValueReferences } from '@pairdraw/scene-graph/variables'\n\nimport type { ExportTarget } from './types'\n\nexport interface ExtractOptions {\n /** Every variant of an instance's set, not only its main component, so it can switch variant. */\n componentSets?: boolean\n /**\n * Use the source's variables, collections, and images instead of copies, for a read-only view\n * rebuilt often, such as preview's. A copy may change its tables without touching the source.\n */\n shareTables?: boolean\n}\n\nexport interface ExtractedGraph {\n graph: SceneGraph\n pageId: string | null\n nodeIds: string[]\n}\n\nfunction includeReferencedStyles(source: SceneGraph, ids: Set<string>): void {\n const referencedStyleIds = new Set<string>()\n for (const id of ids) {\n const node = source.getNode(id)\n if (!node) continue\n for (const styleId of [\n node.fillStyleId,\n node.strokeStyleId,\n node.textStyleId,\n node.effectStyleId,\n node.gridStyleId,\n ...styleRunReferences(node.styleRuns).styles\n ]) {\n if (styleId) referencedStyleIds.add(styleId)\n }\n }\n for (const node of source.getAllNodes()) {\n if (node.sharedStyleType && node.source.id && referencedStyleIds.has(node.source.id)) {\n ids.add(node.id)\n }\n }\n}\n\nfunction cloneIntoGraph(\n source: SceneGraph,\n ids: Set<string>,\n { shareTables = false }: ExtractOptions = {}\n): SceneGraph {\n const graph = new SceneGraph()\n graph.rootId = source.rootId\n graph.nodes = new Map()\n graph.images = new Map()\n graph.variables = new Map()\n graph.variableCollections = new Map()\n graph.activeMode = new Map(source.activeMode)\n graph.figKiwiVersion = source.figKiwiVersion\n graph.figSchemaDeflated = source.figSchemaDeflated\n graph.documentColorSpace = source.documentColorSpace\n graph.documentKind = source.documentKind\n\n includeReferencedStyles(source, ids)\n\n const sortedIds = [...ids].sort((a, b) => {\n if (a === source.rootId) return -1\n if (b === source.rootId) return 1\n const aNode = source.getNode(a)\n const bNode = source.getNode(b)\n const aDepth = depthOf(source, aNode)\n const bDepth = depthOf(source, bNode)\n return aDepth - bDepth\n })\n\n for (const id of sortedIds) {\n const node = source.getNode(id)\n if (!node) continue\n const copy = structuredClone(node)\n graph.nodes.set(id, copy)\n // Syncing and swapping find an instance through its component's index.\n if (copy.type === 'INSTANCE' && copy.componentId) {\n const instances = graph.instanceIndex.get(copy.componentId) ?? new Set<string>()\n instances.add(id)\n graph.instanceIndex.set(copy.componentId, instances)\n }\n if (copy.type === 'CONNECTOR') graph.connectorIds.add(id)\n }\n\n const rootClone = graph.getNode(source.rootId)\n if (rootClone) {\n rootClone.parentId = null\n rootClone.childIds = rootClone.childIds.filter((id) => ids.has(id))\n }\n\n for (const id of sortedIds) {\n if (id === source.rootId) continue\n const node = graph.getNode(id)\n if (!node) continue\n if (!node.parentId || !ids.has(node.parentId)) {\n node.parentId = source.rootId\n }\n node.childIds = node.childIds.filter((childId) => ids.has(childId))\n }\n\n if (shareTables) {\n graph.images = source.images\n graph.variables = source.variables\n graph.variableCollections = source.variableCollections\n } else copyReferencedTables(source, graph)\n\n graph.clearAbsPosCache()\n return graph\n}\n\n/** The images and variables the copied layers use, with their collections, copied in. */\nfunction copyReferencedTables(source: SceneGraph, graph: SceneGraph): void {\n const { imageHashes, variableIds } = collectReferencedResources(source, graph)\n\n for (const imageHash of imageHashes) {\n const image = source.images.get(imageHash)\n if (image) graph.images.set(imageHash, image)\n }\n\n for (const variableId of variableIds) {\n const variable = source.variables.get(variableId)\n if (!variable) continue\n graph.variables.set(variableId, structuredClone(variable))\n const collection = source.variableCollections.get(variable.collectionId)\n if (!collection) continue\n const existing = graph.variableCollections.get(collection.id)\n if (!existing) {\n graph.variableCollections.set(collection.id, {\n ...structuredClone(collection),\n variableIds: []\n })\n }\n graph.variableCollections.get(collection.id)?.variableIds.push(variableId)\n }\n}\n\nfunction collectReferencedResources(source: SceneGraph, graph: SceneGraph) {\n const imageHashes = new Set<string>()\n const variableIds = new Set<string>()\n for (const node of graph.nodes.values()) {\n for (const fill of node.fills) {\n if (fill.type === 'IMAGE' && fill.imageHash) imageHashes.add(fill.imageHash)\n }\n const bound = [\n ...Object.values(node.boundVariables),\n ...styleRunReferences(node.styleRuns).variables\n ]\n for (const variableId of bound) collectVariableClosure(source, variableId, variableIds)\n }\n return { imageHashes, variableIds }\n}\n\nfunction collectVariableClosure(source: SceneGraph, variableId: string, out: Set<string>) {\n if (out.has(variableId)) return\n const variable = source.variables.get(variableId)\n if (!variable) return\n out.add(variableId)\n for (const value of Object.values(variable.valuesByMode)) {\n for (const id of variableValueReferences(value)) collectVariableClosure(source, id, out)\n }\n}\n\nfunction depthOf(source: SceneGraph, node: ReturnType<SceneGraph['getNode']>): number {\n let depth = 0\n let current = node\n while (current?.parentId) {\n depth += 1\n current = source.getNode(current.parentId)\n }\n return depth\n}\n\nfunction collectDescendants(source: SceneGraph, id: string, out: Set<string>) {\n if (out.has(id)) return\n out.add(id)\n const node = source.getNode(id)\n if (!node) return\n for (const childId of node.childIds) {\n collectDescendants(source, childId, out)\n }\n}\n\nfunction collectAncestors(source: SceneGraph, id: string, out: Set<string>) {\n let current = source.getNode(id)\n while (current?.parentId) {\n out.add(current.parentId)\n current = source.getNode(current.parentId)\n }\n}\n\nfunction resolveInstanceComponentId(source: SceneGraph, componentId: string): string {\n const seen = new Set<string>()\n let currentId = componentId\n while (!seen.has(currentId)) {\n seen.add(currentId)\n const node = source.getNode(currentId)\n if (node?.type !== 'INSTANCE' || !node.componentId) return currentId\n currentId = node.componentId\n }\n return componentId\n}\n\nfunction collectComponentDependencies(\n source: SceneGraph,\n ids: Set<string>,\n { componentSets = false }: ExtractOptions = {}\n) {\n let changed = true\n while (changed) {\n changed = false\n for (const id of Array.from(ids)) {\n const node = source.getNode(id)\n if (node?.type !== 'INSTANCE' || !node.componentId) continue\n const componentId = resolveInstanceComponentId(source, node.componentId)\n const component = source.getNode(componentId)\n const set = component?.parentId ? source.getNode(component.parentId) : undefined\n const dependency = componentSets && set?.type === 'COMPONENT_SET' ? set.id : componentId\n if (ids.has(dependency)) continue\n const before = ids.size\n collectAncestors(source, dependency, ids)\n collectDescendants(source, dependency, ids)\n changed ||= ids.size !== before\n }\n }\n}\n\nexport function findPageId(source: SceneGraph, nodeId: string): string | null {\n let current = source.getNode(nodeId)\n while (current?.parentId) {\n const parent = source.getNode(current.parentId)\n if (!parent) return null\n if (parent.type === 'CANVAS') return parent.id\n current = parent\n }\n return current?.type === 'CANVAS' ? current.id : null\n}\n\n/** The page child containing `nodeId`, or the node itself when it is a page child. */\nexport function findPageChildId(source: SceneGraph, nodeId: string): string | null {\n let current = source.getNode(nodeId)\n while (current?.parentId) {\n const parent = source.getNode(current.parentId)\n if (parent?.type === 'CANVAS') return current.id\n current = parent\n }\n return null\n}\n\nfunction ancestorChain(source: SceneGraph, id: string): string[] {\n const chain: string[] = []\n let current = source.getNode(id)\n while (current?.parentId) {\n chain.push(current.parentId)\n current = source.getNode(current.parentId)\n }\n return chain.reverse()\n}\n\nfunction collectSelectionIds(\n source: SceneGraph,\n nodeIds: string[],\n options: ExtractOptions = {}\n): Set<string> {\n const ids = new Set<string>([source.rootId])\n const pageIds = new Set<string>()\n\n for (const nodeId of nodeIds) {\n const node = source.getNode(nodeId)\n if (!node) continue\n for (const ancestorId of ancestorChain(source, nodeId)) {\n ids.add(ancestorId)\n const ancestor = source.getNode(ancestorId)\n if (ancestor?.type === 'CANVAS') pageIds.add(ancestorId)\n }\n collectDescendants(source, nodeId, ids)\n }\n\n for (const pageId of pageIds) {\n ids.add(pageId)\n }\n\n collectComponentDependencies(source, ids, options)\n return ids\n}\n\nfunction pageNodeIds(source: SceneGraph, pageId: string): Set<string> {\n const ids = new Set<string>([source.rootId])\n collectDescendants(source, pageId, ids)\n collectComponentDependencies(source, ids)\n return ids\n}\n\nfunction rootNodeIds(source: SceneGraph): Set<string> {\n const ids = new Set<string>()\n for (const node of source.nodes.values()) {\n ids.add(node.id)\n }\n return ids\n}\n\n/** Clone `pageId` with only the subtrees of `nodeIds` (none keeps an empty page) and their dependencies. */\nexport function extractPageContext(\n source: SceneGraph,\n pageId: string,\n nodeIds: string[],\n options: ExtractOptions = {}\n): SceneGraph {\n const ids = collectSelectionIds(source, nodeIds, options)\n ids.add(pageId)\n return cloneIntoGraph(source, ids, options)\n}\n\nexport function extractExportGraph(source: SceneGraph, target: ExportTarget): ExtractedGraph {\n switch (target.scope) {\n case 'document': {\n const graph = cloneIntoGraph(source, rootNodeIds(source))\n return {\n graph,\n pageId: graph.getPages()[0]?.id ?? null,\n nodeIds: graph.getPages()[0]?.childIds ?? []\n }\n }\n case 'page': {\n const graph = cloneIntoGraph(source, pageNodeIds(source, target.pageId))\n const page = graph.getNode(target.pageId)\n return {\n graph,\n pageId: page?.id ?? null,\n nodeIds: page?.childIds ?? []\n }\n }\n case 'selection': {\n const graph = cloneIntoGraph(source, collectSelectionIds(source, target.nodeIds))\n const firstId = target.nodeIds[0]\n const first = firstId ? source.getNode(firstId) : undefined\n const pageId = first\n ? (ancestorChain(source, first.id).find((id) => source.getNode(id)?.type === 'CANVAS') ??\n null)\n : null\n return {\n graph,\n pageId,\n nodeIds: target.nodeIds.filter((id) => graph.getNode(id) !== undefined)\n }\n }\n case 'node':\n return extractExportGraph(source, { scope: 'selection', nodeIds: [target.nodeId] })\n default:\n return extractExportGraph(source, { scope: 'document' })\n }\n}\n"],"mappings":";;;;AAsBA,SAAS,wBAAwB,QAAoB,KAAwB;CAC3E,MAAM,qCAAqB,IAAI,IAAY;CAC3C,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,OAAO,OAAO,QAAQ,EAAE;EAC9B,IAAI,CAAC,MAAM;EACX,KAAK,MAAM,WAAW;GACpB,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACxC,GACE,IAAI,SAAS,mBAAmB,IAAI,OAAO;CAE/C;CACA,KAAK,MAAM,QAAQ,OAAO,YAAY,GACpC,IAAI,KAAK,mBAAmB,KAAK,OAAO,MAAM,mBAAmB,IAAI,KAAK,OAAO,EAAE,GACjF,IAAI,IAAI,KAAK,EAAE;AAGrB;AAEA,SAAS,eACP,QACA,KACA,EAAE,cAAc,UAA0B,CAAC,GAC/B;CACZ,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{ SceneGraph } from '@pairdraw/scene-graph'\nimport { styleRunReferences } from '@pairdraw/scene-graph/text'\nimport { variableValueReferences } from '@pairdraw/scene-graph/variables'\n\nimport type { ExportTarget } from './types'\n\nexport interface ExtractOptions {\n /** Every variant of an instance's set, not only its main component, so it can switch variant. */\n componentSets?: boolean\n /**\n * Use the source's variables, collections, and images instead of copies, for a read-only view\n * rebuilt often, such as preview's. A copy may change its tables without touching the source.\n */\n shareTables?: boolean\n}\n\nexport interface ExtractedGraph {\n graph: SceneGraph\n pageId: string | null\n nodeIds: string[]\n}\n\nfunction includeReferencedStyles(source: SceneGraph, ids: Set<string>): void {\n const referencedStyleIds = new Set<string>()\n for (const id of ids) {\n const node = source.getNode(id)\n if (!node) continue\n for (const styleId of [\n node.fillStyleId,\n node.strokeStyleId,\n node.textStyleId,\n node.effectStyleId,\n node.gridStyleId,\n ...styleRunReferences(node.styleRuns).styles\n ]) {\n if (styleId) referencedStyleIds.add(styleId)\n }\n }\n // Style definitions can sit anywhere in the document; only layers that use one need the search.\n if (referencedStyleIds.size === 0) return\n for (const node of source.getAllNodes()) {\n if (node.sharedStyleType && node.source.id && referencedStyleIds.has(node.source.id)) {\n ids.add(node.id)\n }\n }\n}\n\nfunction cloneIntoGraph(\n source: SceneGraph,\n ids: Set<string>,\n { shareTables = false }: ExtractOptions = {}\n): SceneGraph {\n const graph = new SceneGraph()\n graph.rootId = source.rootId\n graph.nodes = new Map()\n graph.images = new Map()\n graph.variables = new Map()\n graph.variableCollections = new Map()\n graph.activeMode = new Map(source.activeMode)\n graph.figKiwiVersion = source.figKiwiVersion\n graph.figSchemaDeflated = source.figSchemaDeflated\n graph.documentColorSpace = source.documentColorSpace\n graph.documentKind = source.documentKind\n\n includeReferencedStyles(source, ids)\n\n const sortedIds = [...ids].sort((a, b) => {\n if (a === source.rootId) return -1\n if (b === source.rootId) return 1\n const aNode = source.getNode(a)\n const bNode = source.getNode(b)\n const aDepth = depthOf(source, aNode)\n const bDepth = depthOf(source, bNode)\n return aDepth - bDepth\n })\n\n for (const id of sortedIds) {\n const node = source.getNode(id)\n if (!node) continue\n const copy = structuredClone(node)\n graph.nodes.set(id, copy)\n // Syncing and swapping find an instance through its component's index.\n if (copy.type === 'INSTANCE' && copy.componentId) {\n const instances = graph.instanceIndex.get(copy.componentId) ?? new Set<string>()\n instances.add(id)\n graph.instanceIndex.set(copy.componentId, instances)\n }\n if (copy.type === 'CONNECTOR') graph.connectorIds.add(id)\n }\n\n const rootClone = graph.getNode(source.rootId)\n if (rootClone) {\n rootClone.parentId = null\n rootClone.childIds = rootClone.childIds.filter((id) => ids.has(id))\n }\n\n for (const id of sortedIds) {\n if (id === source.rootId) continue\n const node = graph.getNode(id)\n if (!node) continue\n if (!node.parentId || !ids.has(node.parentId)) {\n node.parentId = source.rootId\n }\n node.childIds = node.childIds.filter((childId) => ids.has(childId))\n }\n\n if (shareTables) {\n graph.images = source.images\n graph.variables = source.variables\n graph.variableCollections = source.variableCollections\n } else copyReferencedTables(source, graph)\n\n graph.clearAbsPosCache()\n return graph\n}\n\n/** The images and variables the copied layers use, with their collections, copied in. */\nfunction copyReferencedTables(source: SceneGraph, graph: SceneGraph): void {\n const { imageHashes, variableIds } = collectReferencedResources(source, graph)\n\n for (const imageHash of imageHashes) {\n const image = source.images.get(imageHash)\n if (image) graph.images.set(imageHash, image)\n }\n\n for (const variableId of variableIds) {\n const variable = source.variables.get(variableId)\n if (!variable) continue\n graph.variables.set(variableId, structuredClone(variable))\n const collection = source.variableCollections.get(variable.collectionId)\n if (!collection) continue\n const existing = graph.variableCollections.get(collection.id)\n if (!existing) {\n graph.variableCollections.set(collection.id, {\n ...structuredClone(collection),\n variableIds: []\n })\n }\n graph.variableCollections.get(collection.id)?.variableIds.push(variableId)\n }\n}\n\nfunction collectReferencedResources(source: SceneGraph, graph: SceneGraph) {\n const imageHashes = new Set<string>()\n const variableIds = new Set<string>()\n for (const node of graph.nodes.values()) {\n for (const fill of node.fills) {\n if (fill.type === 'IMAGE' && fill.imageHash) imageHashes.add(fill.imageHash)\n }\n const bound = [\n ...Object.values(node.boundVariables),\n ...styleRunReferences(node.styleRuns).variables\n ]\n for (const variableId of bound) collectVariableClosure(source, variableId, variableIds)\n }\n return { imageHashes, variableIds }\n}\n\nfunction collectVariableClosure(source: SceneGraph, variableId: string, out: Set<string>) {\n if (out.has(variableId)) return\n const variable = source.variables.get(variableId)\n if (!variable) return\n out.add(variableId)\n for (const value of Object.values(variable.valuesByMode)) {\n for (const id of variableValueReferences(value)) collectVariableClosure(source, id, out)\n }\n}\n\nfunction depthOf(source: SceneGraph, node: ReturnType<SceneGraph['getNode']>): number {\n let depth = 0\n let current = node\n while (current?.parentId) {\n depth += 1\n current = source.getNode(current.parentId)\n }\n return depth\n}\n\nfunction collectDescendants(source: SceneGraph, id: string, out: Set<string>) {\n if (out.has(id)) return\n out.add(id)\n const node = source.getNode(id)\n if (!node) return\n for (const childId of node.childIds) {\n collectDescendants(source, childId, out)\n }\n}\n\nfunction collectAncestors(source: SceneGraph, id: string, out: Set<string>) {\n let current = source.getNode(id)\n while (current?.parentId) {\n out.add(current.parentId)\n current = source.getNode(current.parentId)\n }\n}\n\nfunction resolveInstanceComponentId(source: SceneGraph, componentId: string): string {\n const seen = new Set<string>()\n let currentId = componentId\n while (!seen.has(currentId)) {\n seen.add(currentId)\n const node = source.getNode(currentId)\n if (node?.type !== 'INSTANCE' || !node.componentId) return currentId\n currentId = node.componentId\n }\n return componentId\n}\n\nfunction collectComponentDependencies(\n source: SceneGraph,\n ids: Set<string>,\n { componentSets = false }: ExtractOptions = {}\n) {\n let changed = true\n while (changed) {\n changed = false\n for (const id of Array.from(ids)) {\n const node = source.getNode(id)\n if (node?.type !== 'INSTANCE' || !node.componentId) continue\n const componentId = resolveInstanceComponentId(source, node.componentId)\n const component = source.getNode(componentId)\n const set = component?.parentId ? source.getNode(component.parentId) : undefined\n const dependency = componentSets && set?.type === 'COMPONENT_SET' ? set.id : componentId\n if (ids.has(dependency)) continue\n const before = ids.size\n collectAncestors(source, dependency, ids)\n collectDescendants(source, dependency, ids)\n changed ||= ids.size !== before\n }\n }\n}\n\nexport function findPageId(source: SceneGraph, nodeId: string): string | null {\n let current = source.getNode(nodeId)\n while (current?.parentId) {\n const parent = source.getNode(current.parentId)\n if (!parent) return null\n if (parent.type === 'CANVAS') return parent.id\n current = parent\n }\n return current?.type === 'CANVAS' ? current.id : null\n}\n\n/** The page child containing `nodeId`, or the node itself when it is a page child. */\nexport function findPageChildId(source: SceneGraph, nodeId: string): string | null {\n let current = source.getNode(nodeId)\n while (current?.parentId) {\n const parent = source.getNode(current.parentId)\n if (parent?.type === 'CANVAS') return current.id\n current = parent\n }\n return null\n}\n\nfunction ancestorChain(source: SceneGraph, id: string): string[] {\n const chain: string[] = []\n let current = source.getNode(id)\n while (current?.parentId) {\n chain.push(current.parentId)\n current = source.getNode(current.parentId)\n }\n return chain.reverse()\n}\n\nfunction collectSelectionIds(\n source: SceneGraph,\n nodeIds: readonly string[],\n options: ExtractOptions = {}\n): Set<string> {\n const ids = new Set<string>([source.rootId])\n const pageIds = new Set<string>()\n\n for (const nodeId of nodeIds) {\n const node = source.getNode(nodeId)\n if (!node) continue\n for (const ancestorId of ancestorChain(source, nodeId)) {\n ids.add(ancestorId)\n const ancestor = source.getNode(ancestorId)\n if (ancestor?.type === 'CANVAS') pageIds.add(ancestorId)\n }\n collectDescendants(source, nodeId, ids)\n }\n\n for (const pageId of pageIds) {\n ids.add(pageId)\n }\n\n collectComponentDependencies(source, ids, options)\n return ids\n}\n\nfunction pageNodeIds(source: SceneGraph, pageId: string): Set<string> {\n const ids = new Set<string>([source.rootId])\n collectDescendants(source, pageId, ids)\n collectComponentDependencies(source, ids)\n return ids\n}\n\nfunction rootNodeIds(source: SceneGraph): Set<string> {\n const ids = new Set<string>()\n for (const node of source.nodes.values()) {\n ids.add(node.id)\n }\n return ids\n}\n\n/**\n * Clone `pageId`, or each of several pages, with only the subtrees of `nodeIds` (none keeps an\n * empty page) and their dependencies.\n */\nexport function extractPageContext(\n source: SceneGraph,\n pageId: string | readonly string[],\n nodeIds: readonly string[],\n options: ExtractOptions = {}\n): SceneGraph {\n const ids = collectSelectionIds(source, nodeIds, options)\n for (const id of typeof pageId === 'string' ? [pageId] : pageId) ids.add(id)\n return cloneIntoGraph(source, ids, options)\n}\n\nexport function extractExportGraph(source: SceneGraph, target: ExportTarget): ExtractedGraph {\n switch (target.scope) {\n case 'document': {\n const graph = cloneIntoGraph(source, rootNodeIds(source))\n return {\n graph,\n pageId: graph.getPages()[0]?.id ?? null,\n nodeIds: graph.getPages()[0]?.childIds ?? []\n }\n }\n case 'page': {\n const graph = cloneIntoGraph(source, pageNodeIds(source, target.pageId))\n const page = graph.getNode(target.pageId)\n return {\n graph,\n pageId: page?.id ?? null,\n nodeIds: page?.childIds ?? []\n }\n }\n case 'selection': {\n const graph = cloneIntoGraph(source, collectSelectionIds(source, target.nodeIds))\n const firstId = target.nodeIds[0]\n const first = firstId ? source.getNode(firstId) : undefined\n const pageId = first\n ? (ancestorChain(source, first.id).find((id) => source.getNode(id)?.type === 'CANVAS') ??\n null)\n : null\n return {\n graph,\n pageId,\n nodeIds: target.nodeIds.filter((id) => graph.getNode(id) !== undefined)\n }\n }\n case 'node':\n return extractExportGraph(source, { scope: 'selection', nodeIds: [target.nodeId] })\n default:\n return extractExportGraph(source, { scope: 'document' })\n }\n}\n"],"mappings":";;;;AAsBA,SAAS,wBAAwB,QAAoB,KAAwB;CAC3E,MAAM,qCAAqB,IAAI,IAAY;CAC3C,KAAK,MAAM,MAAM,KAAK;EACpB,MAAM,OAAO,OAAO,QAAQ,EAAE;EAC9B,IAAI,CAAC,MAAM;EACX,KAAK,MAAM,WAAW;GACpB,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,KAAK;GACL,GAAG,mBAAmB,KAAK,SAAS,CAAC,CAAC;EACxC,GACE,IAAI,SAAS,mBAAmB,IAAI,OAAO;CAE/C;CAEA,IAAI,mBAAmB,SAA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,QAAQ,OAAO,MAAM,QAAQ,EAAE,MAAM,KAAA,CAAS;GACxE;EACF;EACA,KAAK,QACH,OAAO,mBAAmB,QAAQ;GAAE,OAAO;GAAa,SAAS,CAAC,OAAO,MAAM;EAAE,CAAC;EACpF,SACE,OAAO,mBAAmB,QAAQ,EAAE,OAAO,WAAW,CAAC;CAC3D;AACF"}
@@ -4,7 +4,7 @@ import { SceneMutationImpact } from "@pairdraw/scene-graph/mutation-impact";
4
4
  declare function createLayoutRunner(getGraph: () => SceneGraph): {
5
5
  runLayoutForNode: (id: string) => void;
6
6
  runLayoutForImpact: (impact: SceneMutationImpact) => boolean;
7
- runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string, beforeLayout?: (result: T) => Promise<void> | void) => Promise<T>;
7
+ runMutationWithLayout: <T>(operation: () => T | Promise<T>, fallbackId?: string, beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void) => Promise<T>;
8
8
  };
9
9
  //#endregion
10
10
  export { createLayoutRunner };
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.d.ts","names":[],"sources":["../../src/layout/mutations.ts"],"mappings":";;;iBAYgB,mBAAmB,gBAAgB;EACnB,mBAAA;EA6CM,qBAAA,QAAA;EAhBC,wBAAA,GAAC,iBACnB,IAAI,QAAQ,IAAE,qBACZ,gBACH,QAAQ,MAAM,yBAC7B,QAAQ"}
1
+ {"version":3,"file":"mutations.d.ts","names":[],"sources":["../../src/layout/mutations.ts"],"mappings":";;;iBAYgB,mBAAmB,gBAAgB;EACnB,mBAAA;EA6CM,qBAAA,QAAA;EAhBC,wBAAA,GAAC,iBACnB,IAAI,QAAQ,IAAE,qBACZ,gBACH,QAAQ,GAAG,QAAQ,wBAAwB,yBAC1D,QAAQ"}
@@ -30,7 +30,7 @@ function createLayoutRunner(getGraph) {
30
30
  async function runMutationWithLayout(operation, fallbackId, beforeLayout) {
31
31
  const graph = getGraph();
32
32
  const { result, impact } = await collectSceneMutation(graph, operation);
33
- await beforeLayout?.(result);
33
+ await beforeLayout?.(result, impact);
34
34
  if (!runLayoutForImpact(impact) && fallbackId) computeAllLayouts(graph, fallbackId);
35
35
  return result;
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mutations.js","names":[],"sources":["../../src/layout/mutations.ts"],"sourcesContent":["import { uniq } from 'es-toolkit'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorsAffectedBy, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport {\n collectSceneMutation,\n mutationLayoutScopeIds,\n type SceneMutationImpact\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport { computeAllLayouts, computeLayout } from '#core/layout'\n\nexport function createLayoutRunner(getGraph: () => SceneGraph) {\n function runLayoutForNode(id: string) {\n const graph = getGraph()\n const node = graph.getNode(id)\n if (!node) return\n\n computeAllLayouts(graph, id)\n\n let parent = node.parentId ? graph.getNode(node.parentId) : undefined\n while (parent) {\n if (parent.layoutMode !== 'NONE') {\n computeLayout(graph, parent.id)\n }\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n }\n\n function compactLayoutScope(impact: SceneMutationImpact): string[] {\n const graph = getGraph()\n const candidates = new Set(mutationLayoutScopeIds(impact).filter((id) => graph.getNode(id)))\n return [...candidates].filter((id) => {\n let parentId = graph.getNode(id)?.parentId ?? null\n while (parentId) {\n if (candidates.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId ?? null\n }\n return true\n })\n }\n\n async function runMutationWithLayout<T>(\n operation: () => T | Promise<T>,\n fallbackId?: string,\n beforeLayout?: (result: T) => Promise<void> | void\n ): Promise<T> {\n const graph = getGraph()\n const { result, impact } = await collectSceneMutation(graph, operation)\n await beforeLayout?.(result)\n if (!runLayoutForImpact(impact) && fallbackId) computeAllLayouts(graph, fallbackId)\n return result\n }\n\n /**\n * Lays out what an edit touched, and routes again the connectors it moved; returns whether\n * there was anything to lay out.\n */\n function runLayoutForImpact(impact: SceneMutationImpact): boolean {\n const scopeIds = compactLayoutScope(impact)\n for (const id of scopeIds) runLayoutForNode(id)\n routeConnectors(impact)\n return scopeIds.length > 0\n }\n\n /**\n * Routes the connectors an edit moved. One created together with the layers it joins, as a\n * paste makes it, keeps the route it came with; one that joins layers already there routes to\n * them.\n */\n function routeConnectors(impact: SceneMutationImpact) {\n const graph = getGraph()\n const created = impact.createdNodeIds\n const joinsExisting = (connector: SceneNode) =>\n [connector.connectorStart?.nodeId, connector.connectorEnd?.nodeId].some(\n (id) => id && !created.has(id) && graph.getNode(id)\n )\n const connectors = [\n ...connectorsAffectedBy(graph, impact.changedNodeIds),\n ...[...created].flatMap((id) => {\n const node = graph.getNode(id)\n return node?.type === 'CONNECTOR' && joinsExisting(node) ? [node] : []\n })\n ]\n graph.withLayoutMutations(() => {\n for (const connector of uniq(connectors)) layoutConnector(graph, connector)\n })\n }\n\n return { runLayoutForNode, runLayoutForImpact, runMutationWithLayout }\n}\n"],"mappings":";;;;;AAYA,SAAgB,mBAAmB,UAA4B;CAC7D,SAAS,iBAAiB,IAAY;EACpC,MAAM,QAAQ,SAAS;EACvB,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EAEX,kBAAkB,OAAO,EAAE;EAE3B,IAAI,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EAC5D,OAAO,QAAQ;GACb,IAAI,OAAO,eAAe,QACxB,cAAc,OAAO,OAAO,EAAE;GAEhC,SAAS,OAAO,WAAW,MAAM,QAAQ,OAAO,QAAQ,IAAI,KAAA;EAC9D;CACF;CAEA,SAAS,mBAAmB,QAAuC;EACjE,MAAM,QAAQ,SAAS;EACvB,MAAM,aAAa,IAAI,IAAI,uBAAuB,MAAM,CAAC,CAAC,QAAQ,OAAO,MAAM,QAAQ,EAAE,CAAC,CAAC;EAC3F,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC,QAAQ,OAAO;GACpC,IAAI,WAAW,MAAM,QAAQ,EAAE,C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ourcesContent":["import { uniq } from 'es-toolkit'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { connectorsAffectedBy, layoutConnector } from '@pairdraw/scene-graph/connectors'\nimport {\n collectSceneMutation,\n mutationLayoutScopeIds,\n type SceneMutationImpact\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport { computeAllLayouts, computeLayout } from '#core/layout'\n\nexport function createLayoutRunner(getGraph: () => SceneGraph) {\n function runLayoutForNode(id: string) {\n const graph = getGraph()\n const node = graph.getNode(id)\n if (!node) return\n\n computeAllLayouts(graph, id)\n\n let parent = node.parentId ? graph.getNode(node.parentId) : undefined\n while (parent) {\n if (parent.layoutMode !== 'NONE') {\n computeLayout(graph, parent.id)\n }\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n }\n\n function compactLayoutScope(impact: SceneMutationImpact): string[] {\n const graph = getGraph()\n const candidates = new Set(mutationLayoutScopeIds(impact).filter((id) => graph.getNode(id)))\n return [...candidates].filter((id) => {\n let parentId = graph.getNode(id)?.parentId ?? null\n while (parentId) {\n if (candidates.has(parentId)) return false\n parentId = graph.getNode(parentId)?.parentId ?? null\n }\n return true\n })\n }\n\n async function runMutationWithLayout<T>(\n operation: () => T | Promise<T>,\n fallbackId?: string,\n beforeLayout?: (result: T, impact: SceneMutationImpact) => Promise<void> | void\n ): Promise<T> {\n const graph = getGraph()\n const { result, impact } = await collectSceneMutation(graph, operation)\n await beforeLayout?.(result, impact)\n if (!runLayoutForImpact(impact) && fallbackId) computeAllLayouts(graph, fallbackId)\n return result\n }\n\n /**\n * Lays out what an edit touched, and routes again the connectors it moved; returns whether\n * there was anything to lay out.\n */\n function runLayoutForImpact(impact: SceneMutationImpact): boolean {\n const scopeIds = compactLayoutScope(impact)\n for (const id of scopeIds) runLayoutForNode(id)\n routeConnectors(impact)\n return scopeIds.length > 0\n }\n\n /**\n * Routes the connectors an edit moved. One created together with the layers it joins, as a\n * paste makes it, keeps the route it came with; one that joins layers already there routes to\n * them.\n */\n function routeConnectors(impact: SceneMutationImpact) {\n const graph = getGraph()\n const created = impact.createdNodeIds\n const joinsExisting = (connector: SceneNode) =>\n [connector.connectorStart?.nodeId, connector.connectorEnd?.nodeId].some(\n (id) => id && !created.has(id) && graph.getNode(id)\n )\n const connectors = [\n ...connectorsAffectedBy(graph, impact.changedNodeIds),\n ...[...created].flatMap((id) => {\n const node = graph.getNode(id)\n return node?.type === 'CONNECTOR' && joinsExisting(node) ? [node] : []\n })\n ]\n graph.withLayoutMutations(() => {\n for (const connector of uniq(connectors)) layoutConnector(graph, connector)\n })\n }\n\n return { runLayoutForNode, runLayoutForImpact, runMutationWithLayout }\n}\n"],"mappings":";;;;;AAYA,SAAgB,mBAAmB,UAA4B;CAC7D,SAAS,iBAAiB,IAAY;EACpC,MAAM,QAAQ,SAAS;EACvB,MAAM,OAAO,MAAM,QAAQ,EAAE;EAC7B,IAAI,CAAC,MAAM;EAEX,kBAAkB,OAAO,EAAE;EAE3B,IAAI,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EAC5D,OAAO,QAAQ;GACb,IAAI,OAAO,eAAe,QACxB,cAAc,OAAO,OAAO,EAAE;GAEhC,SAAS,OAAO,WAAW,MAAM,QAAQ,OAAO,QAAQ,IAAI,KAAA;EAC9D;CACF;CAEA,SAAS,mBAAmB,QAAuC;EACjE,MAAM,QAAQ,SAAS;EACvB,MAAM,aAAa,IAAI,IAAI,uBAAuB,MAAM,CAAC,CAAC,QAAQ,OAAO,MAAM,QAAQ,EAAE,CAAC,CAAC;EAC3F,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC,QAAQ,OAAO;GACpC,IAAI,WAAW,MAAM,QAAQ,EAAE,CAAC,EAAE,YAAY;GAC9C,OAAO,UAAU;IACf,IAAI,WAAW,IAAI,QAAQ,GAAG,OAAO;IACrC,WAAW,MAAM,QAAQ,QAAQ,CAAC,EAAE,YAAY;GAClD;GACA,OAAO;EACT,CAAC;CACH;CAEA,eAAe,sBACb,WACA,YACA,cACY;EACZ,MAAM,QAAQ,SAAS;EACvB,MAAM,EAAE,QAAQ,WAAW,MAAM,qBAAqB,OAAO,SAAS;EACtE,MAAM,eAAe,QAAQ,MAAM;EACnC,IAAI,CAAC,mBAAmB,MAAM,KAAK,YAAY,kBAAkB,OAAO,UAAU;EAClF,OAAO;CACT;;;;;CAMA,SAAS,mBAAmB,QAAsC;EAChE,MAAM,WAAW,mBAAmB,MAAM;EAC1C,KAAK,MAAM,MAAM,UAAU,iBAAiB,EAAE;EAC9C,gBAAgB,MAAM;EACtB,OAAO,SAAS,SAAS;CAC3B;;;;;;CAOA,SAAS,gBAAgB,QAA6B;EACpD,MAAM,QAAQ,SAAS;EACvB,MAAM,UAAU,OAAO;EACvB,MAAM,iBAAiB,cACrB,CAAC,UAAU,gBAAgB,QAAQ,UAAU,cAAc,MAAM,CAAC,CAAC,MAChE,OAAO,MAAM,CAAC,QAAQ,IAAI,EAAE,KAAK,MAAM,QAAQ,EAAE,CACpD;EACF,MAAM,aAAa,CACjB,GAAG,qBAAqB,OAAO,OAAO,cAAc,GACpD,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,SAAS,OAAO;GAC9B,MAAM,OAAO,MAAM,QAAQ,EAAE;GAC7B,OAAO,MAAM,SAAS,eAAe,cAAc,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC;EACvE,CAAC,CACH;EACA,MAAM,0BAA0B;GAC9B,KAAK,MAAM,aAAa,KAAK,UAAU,GAAG,gBAAgB,OAAO,SAAS;EAC5E,CAAC;CACH;CAEA,OAAO;EAAE;EAAkB;EAAoB;CAAsB;AACvE"}
@@ -52,7 +52,7 @@ function fontFaceFromFigmaFontName(fontName) {
52
52
  };
53
53
  }
54
54
  function fontFaceRenderFamily(family, style) {
55
- return `__op_font__${family.replace(/[^a-z0-9_-]+/giu, "_")}__${style.replace(/[^a-z0-9_-]+/giu, "_")}`;
55
+ return `__pairdraw_font__${family.replace(/[^a-z0-9_-]+/giu, "_")}__${style.replace(/[^a-z0-9_-]+/giu, "_")}`;
56
56
  }
57
57
  //#endregion
58
58
  export { facesFromStyles, fontFaceFromFigmaFontName, fontFaceRenderFamily, hasFamilyFace, nearestFamilyFace, standardFace, standardFaces };
@@ -1 +1 @@
1
- {"version":3,"file":"faces.js","names":[],"sources":["../../../src/text/font/faces.ts"],"sourcesContent":["import { uniqBy } from 'es-toolkit'\n\nimport {\n parseFontStyle,\n standardStyleName,\n type ParsedFontStyle\n} from '@pairdraw/scene-graph/font-style'\n\n/** A weight, upright or italic. */\nexport interface FaceWeight {\n weight: number\n italic: boolean\n}\n\n/** One face a font family has: a weight, upright or italic, and the name its font gives it. */\nexport interface FamilyFace extends FaceWeight {\n style: string\n}\n\n/**\n * The faces named by a family's style names, such as \"Bold Italic\" or \"Semi Bold\", each keeping\n * its name. Of two names for one weight and slant, the first listed is the face's.\n */\nexport function facesFromStyles(styles: readonly string[]): FamilyFace[] {\n return uniqBy(\n styles.map((style) => ({ ...parseFontStyle(style), style })),\n (face) => `${face.weight}${face.italic ? 'i' : ''}`\n )\n}\n\n/** A face named as Google Fonts names it, for a source that gives weights but no names. */\nexport function standardFace(weight: number, italic: boolean): FamilyFace {\n return { weight, italic, style: standardStyleName(weight, italic) }\n}\n\n/** The faces style keys stand for, named as Google Fonts names them. */\nexport function standardFaces(styles: readonly string[]): FamilyFace[] {\n return facesFromStyles(styles).map((face) => standardFace(face.weight, face.italic))\n}\n\nexport function hasFamilyFace(faces: readonly FaceWeight[], weight: number, italic: boolean) {\n return faces.some((face) => face.weight === weight && face.italic === italic)\n}\n\n/**\n * The face a text takes in a family, as Figma picks it when the family changes: the same weight\n * and slant where the family has it, otherwise the nearest weight with the same slant, or the\n * nearest weight at all in a family without that slant. Equally near weights take the lighter.\n */\nexport function nearestFamilyFace(\n faces: readonly FamilyFace[],\n weight: number,\n italic: boolean\n): FamilyFace | null {\n const sameSlant = faces.filter((face) => face.italic === italic)\n const candidates = sameSlant.length > 0 ? sameSlant : faces\n let nearest: FamilyFace | null = null\n for (const face of candidates) {\n const distance = Math.abs(face.weight - weight)\n const best = nearest ? Math.abs(nearest.weight - weight) : Infinity\n if (distance < best || (distance === best && nearest && face.weight < nearest.weight))\n nearest = face\n }\n return nearest\n}\n\n/** A face text asks the font manager for: its family, its style key, and its weight and slant. */\nexport interface FontFaceRef extends ParsedFontStyle {\n family: string\n style: string\n postscriptName?: string\n}\n\nexport function fontFaceFromFigmaFontName(fontName: {\n family?: string\n style?: string\n postscript?: string\n}): FontFaceRef {\n const style = fontName.style ?? 'Regular'\n return {\n family: fontName.family ?? 'Inter',\n style,\n postscriptName: fontName.postscript,\n ...parseFontStyle(style)\n }\n}\n\nexport function fontFaceRenderFamily(family: string, style: string): string {\n return `__op_font__${family.replace(/[^a-z0-9_-]+/giu, '_')}__${style.replace(/[^a-z0-9_-]+/giu, '_')}`\n}\n"],"mappings":";;;;;;;AAuBA,SAAgB,gBAAgB,QAAyC;CACvE,OAAO,OACL,OAAO,KAAK,WAAW;EAAE,GAAG,eAAe,KAAK;EAAG;CAAM,EAAE,IAC1D,SAAS,GAAG,KAAK,SAAS,KAAK,SAAS,MAAM,IACjD;AACF;;AAGA,SAAgB,aAAa,QAAgB,QAA6B;CACxE,OAAO;EAAE;EAAQ;EAAQ,OAAO,kBAAkB,QAAQ,MAAM;CAAE;AACpE;;AAGA,SAAgB,cAAc,QAAyC;CACrE,OAAO,gBAAgB,MAAM,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,QAAQ,KAAK,MAAM,CAAC;AACrF;AAEA,SAAgB,cAAc,OAA8B,QAAgB,QAAiB;CAC3F,OAAO,MAAM,MAAM,SAAS,KAAK,WAAW,UAAU,KAAK,WAAW,MAAM;AAC9E;;;;;;AAOA,SAAgB,kBACd,OACA,QACA,QACmB;CACnB,MAAM,YAAY,MAAM,QAAQ,SAAS,KAAK,WAAW,MAAM;CAC/D,MAAM,aAAa,UAAU,SAAS,IAAI,YAAY;CACtD,IAAI,UAA6B;CACjC,KAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,WAAW,KAAK,IAAI,KAAK,SAAS,MAAM;EAC9C,MAAM,OAAO,UAAU,KAAK,IAAI,QAAQ,SAAS,MAAM,IAAI;EAC3D,IAAI,WAAW,QAAS,aAAa,QAAQ,WAAW,KAAK,SAAS,QAAQ,QAC5E,UAAU;CACd;CACA,OAAO;AACT;AASA,SAAgB,0BAA0B,UAI1B;CACd,MAAM,QAAQ,SAAS,SAAS;CAChC,OAAO;EACL,QAAQ,SAAS,UAAU;EAC3B;EACA,gBAAgB,SAAS;EACzB,GAAG,eAAe,KAAK;CACzB;AACF;AAEA,SAAgB,qBAAqB,QAAgB,OAAuB;CAC1E,OAAO,cAAc,OAAO,QAAQ,mBAAmB,GAAG,EAAE,IAAI,MAAM,QAAQ,mBAAmB,GAAG;AACtG"}
1
+ {"version":3,"file":"faces.js","names":[],"sources":["../../../src/text/font/faces.ts"],"sourcesContent":["import { uniqBy } from 'es-toolkit'\n\nimport {\n parseFontStyle,\n standardStyleName,\n type ParsedFontStyle\n} from '@pairdraw/scene-graph/font-style'\n\n/** A weight, upright or italic. */\nexport interface FaceWeight {\n weight: number\n italic: boolean\n}\n\n/** One face a font family has: a weight, upright or italic, and the name its font gives it. */\nexport interface FamilyFace extends FaceWeight {\n style: string\n}\n\n/**\n * The faces named by a family's style names, such as \"Bold Italic\" or \"Semi Bold\", each keeping\n * its name. Of two names for one weight and slant, the first listed is the face's.\n */\nexport function facesFromStyles(styles: readonly string[]): FamilyFace[] {\n return uniqBy(\n styles.map((style) => ({ ...parseFontStyle(style), style })),\n (face) => `${face.weight}${face.italic ? 'i' : ''}`\n )\n}\n\n/** A face named as Google Fonts names it, for a source that gives weights but no names. */\nexport function standardFace(weight: number, italic: boolean): FamilyFace {\n return { weight, italic, style: standardStyleName(weight, italic) }\n}\n\n/** The faces style keys stand for, named as Google Fonts names them. */\nexport function standardFaces(styles: readonly string[]): FamilyFace[] {\n return facesFromStyles(styles).map((face) => standardFace(face.weight, face.italic))\n}\n\nexport function hasFamilyFace(faces: readonly FaceWeight[], weight: number, italic: boolean) {\n return faces.some((face) => face.weight === weight && face.italic === italic)\n}\n\n/**\n * The face a text takes in a family, as Figma picks it when the family changes: the same weight\n * and slant where the family has it, otherwise the nearest weight with the same slant, or the\n * nearest weight at all in a family without that slant. Equally near weights take the lighter.\n */\nexport function nearestFamilyFace(\n faces: readonly FamilyFace[],\n weight: number,\n italic: boolean\n): FamilyFace | null {\n const sameSlant = faces.filter((face) => face.italic === italic)\n const candidates = sameSlant.length > 0 ? sameSlant : faces\n let nearest: FamilyFace | null = null\n for (const face of candidates) {\n const distance = Math.abs(face.weight - weight)\n const best = nearest ? Math.abs(nearest.weight - weight) : Infinity\n if (distance < best || (distance === best && nearest && face.weight < nearest.weight))\n nearest = face\n }\n return nearest\n}\n\n/** A face text asks the font manager for: its family, its style key, and its weight and slant. */\nexport interface FontFaceRef extends ParsedFontStyle {\n family: string\n style: string\n postscriptName?: string\n}\n\nexport function fontFaceFromFigmaFontName(fontName: {\n family?: string\n style?: string\n postscript?: string\n}): FontFaceRef {\n const style = fontName.style ?? 'Regular'\n return {\n family: fontName.family ?? 'Inter',\n style,\n postscriptName: fontName.postscript,\n ...parseFontStyle(style)\n }\n}\n\nexport function fontFaceRenderFamily(family: string, style: string): string {\n return `__pairdraw_font__${family.replace(/[^a-z0-9_-]+/giu, '_')}__${style.replace(/[^a-z0-9_-]+/giu, '_')}`\n}\n"],"mappings":";;;;;;;AAuBA,SAAgB,gBAAgB,QAAyC;CACvE,OAAO,OACL,OAAO,KAAK,WAAW;EAAE,GAAG,eAAe,KAAK;EAAG;CAAM,EAAE,IAC1D,SAAS,GAAG,KAAK,SAAS,KAAK,SAAS,MAAM,IACjD;AACF;;AAGA,SAAgB,aAAa,QAAgB,QAA6B;CACxE,OAAO;EAAE;EAAQ;EAAQ,OAAO,kBAAkB,QAAQ,MAAM;CAAE;AACpE;;AAGA,SAAgB,cAAc,QAAyC;CACrE,OAAO,gBAAgB,MAAM,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,QAAQ,KAAK,MAAM,CAAC;AACrF;AAEA,SAAgB,cAAc,OAA8B,QAAgB,QAAiB;CAC3F,OAAO,MAAM,MAAM,SAAS,KAAK,WAAW,UAAU,KAAK,WAAW,MAAM;AAC9E;;;;;;AAOA,SAAgB,kBACd,OACA,QACA,QACmB;CACnB,MAAM,YAAY,MAAM,QAAQ,SAAS,KAAK,WAAW,MAAM;CAC/D,MAAM,aAAa,UAAU,SAAS,IAAI,YAAY;CACtD,IAAI,UAA6B;CACjC,KAAK,MAAM,QAAQ,YAAY;EAC7B,MAAM,WAAW,KAAK,IAAI,KAAK,SAAS,MAAM;EAC9C,MAAM,OAAO,UAAU,KAAK,IAAI,QAAQ,SAAS,MAAM,IAAI;EAC3D,IAAI,WAAW,QAAS,aAAa,QAAQ,WAAW,KAAK,SAAS,QAAQ,QAC5E,UAAU;CACd;CACA,OAAO;AACT;AASA,SAAgB,0BAA0B,UAI1B;CACd,MAAM,QAAQ,SAAS,SAAS;CAChC,OAAO;EACL,QAAQ,SAAS,UAAU;EAC3B;EACA,gBAAgB,SAAS;EACzB,GAAG,eAAe,KAAK;CACzB;AACF;AAEA,SAAgB,qBAAqB,QAAgB,OAAuB;CAC1E,OAAO,oBAAoB,OAAO,QAAQ,mBAAmB,GAAG,EAAE,IAAI,MAAM,QAAQ,mBAAmB,GAAG;AAC5G"}
@@ -8,20 +8,11 @@ type WebUnifont = Unifont<WebFontProviders>;
8
8
  type WebFontResolveOptions = Pick<ResolveFontOptions<{
9
9
  google?: GoogleFamilyOptions;
10
10
  }>, 'weights' | 'styles' | 'formats' | 'subsets' | 'variableAxis' | 'options'>;
11
- /**
12
- * The unifont providers behind each provider setting. Google serves its Material Symbols from
13
- * its icon catalogue, as variable fonts with every axis, so its setting covers both.
14
- */
15
- declare const providerFactories: {
16
- google: () => WebFontProviders;
17
- fontsource: () => WebFontProviders;
18
- bunny: () => WebFontProviders;
19
- fontshare: () => WebFontProviders;
20
- };
11
+ /** Unifont, with its CSS parser, loads with the first font looked up rather than with the editor. */
21
12
  declare function createProviderUnifont(provider: WebFontProviderId): Promise<WebUnifont>;
22
13
  declare function isRemoteFontSource(source: RemoteFontSource | {
23
14
  name: string;
24
15
  }): source is RemoteFontSource;
25
16
  //#endregion
26
- export { WebFontProvider, WebFontProviders, WebFontResolveOptions, WebUnifont, createProviderUnifont, isRemoteFontSource, providerFactories };
17
+ export { WebFontProvider, WebFontProviders, WebFontResolveOptions, WebUnifont, createProviderUnifont, isRemoteFontSource };
27
18
  //# sourceMappingURL=providers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"providers.d.ts","names":[],"sources":["../../../src/text/web-font/providers.ts"],"mappings":";;;KAWY,kBACR,kBAAkB,UAAU,UAC5B,kBAAkB,UAAU,eAC5B,kBAAkB,UAAU,cAC5B,kBAAkB,UAAU,SAC5B,kBAAkB,UAAU;;KAEpB,oBAAoB,oBAAoB;KACxC,aAAa,QAAQ;KACrB,wBAAwB,KAClC;EAAqB,SAAS;;;;;;cAQnB;EACC,cAAA;EACI,kBAAA;EACL,aAAA;EACI,iBAAA;;iBAGK,sBAAsB,UAAU,oBAAoB,QAAQ;iBAMlE,mBACd,QAAQ;EAAqB;IAC5B,UAAU"}
1
+ {"version":3,"file":"providers.d.ts","names":[],"sources":["../../../src/text/web-font/providers.ts"],"mappings":";;;KAUY,kBACR,kBAAkB,UAAU,UAC5B,kBAAkB,UAAU,eAC5B,kBAAkB,UAAU,cAC5B,kBAAkB,UAAU,SAC5B,kBAAkB,UAAU;;KAEpB,oBAAoB,oBAAoB;KACxC,aAAa,QAAQ;KACrB,wBAAwB,KAClC;EAAqB,SAAS;;;iBAkBV,sBAAsB,UAAU,oBAAoB,QAAQ;iBAUlE,mBACd,QAAQ;EAAqB;IAC5B,UAAU"}
@@ -1,17 +1,18 @@
1
- import { createUnifont, providers } from "unifont";
2
1
  //#region src/text/web-font/providers.ts
3
2
  /**
4
3
  * The unifont providers behind each provider setting. Google serves its Material Symbols from
5
4
  * its icon catalogue, as variable fonts with every axis, so its setting covers both.
6
5
  */
7
6
  const providerFactories = {
8
- google: () => [providers.google(), providers.googleicons()],
9
- fontsource: () => [providers.fontsource()],
10
- bunny: () => [providers.bunny()],
11
- fontshare: () => [providers.fontshare()]
7
+ google: (from) => [from.google(), from.googleicons()],
8
+ fontsource: (from) => [from.fontsource()],
9
+ bunny: (from) => [from.bunny()],
10
+ fontshare: (from) => [from.fontshare()]
12
11
  };
12
+ /** Unifont, with its CSS parser, loads with the first font looked up rather than with the editor. */
13
13
  async function createProviderUnifont(provider) {
14
- return createUnifont(providerFactories[provider](), {
14
+ const { createUnifont, providers: unifontProviders } = await import("unifont");
15
+ return createUnifont(providerFactories[provider](unifontProviders), {
15
16
  throwOnError: false,
16
17
  apiBase: false
17
18
  });
@@ -20,6 +21,6 @@ function isRemoteFontSource(source) {
20
21
  return "url" in source;
21
22
  }
22
23
  //#endregion
23
- export { createProviderUnifont, isRemoteFontSource, providerFactories };
24
+ export { createProviderUnifont, isRemoteFontSource };
24
25
 
25
26
  //# sourceMappingURL=providers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"providers.js","names":[],"sources":["../../../src/text/web-font/providers.ts"],"sourcesContent":["import {\n createUnifont,\n providers,\n type GoogleFamilyOptions,\n type RemoteFontSource,\n type ResolveFontOptions,\n type Unifont\n} from 'unifont'\n\nimport type { WebFontProviderId } from '#core/text/web-font/resolver'\n\nexport type WebFontProvider =\n | ReturnType<typeof providers.google>\n | ReturnType<typeof providers.googleicons>\n | ReturnType<typeof providers.fontsource>\n | ReturnType<typeof providers.bunny>\n | ReturnType<typeof providers.fontshare>\n/** One or more providers behind a provider setting. */\nexport type WebFontProviders = [WebFontProvider, ...WebFontProvider[]]\nexport type WebUnifont = Unifont<WebFontProviders>\nexport type WebFontResolveOptions = Pick<\n ResolveFontOptions<{ google?: GoogleFamilyOptions }>,\n 'weights' | 'styles' | 'formats' | 'subsets' | 'variableAxis' | 'options'\n>\n\n/**\n * The unifont providers behind each provider setting. Google serves its Material Symbols from\n * its icon catalogue, as variable fonts with every axis, so its setting covers both.\n */\nexport const providerFactories = {\n google: (): WebFontProviders => [providers.google(), providers.googleicons()],\n fontsource: (): WebFontProviders => [providers.fontsource()],\n bunny: (): WebFontProviders => [providers.bunny()],\n fontshare: (): WebFontProviders => [providers.fontshare()]\n} satisfies Record<WebFontProviderId, () => WebFontProviders>\n\nexport async function createProviderUnifont(provider: WebFontProviderId): Promise<WebUnifont> {\n // In a page unifont sends provider requests to its hosted proxy; ours go through the host's\n // fetch, which reaches the providers itself.\n return createUnifont(providerFactories[provider](), { throwOnError: false, apiBase: false })\n}\n\nexport function isRemoteFontSource(\n source: RemoteFontSource | { name: string }\n): source is RemoteFontSource {\n return 'url' in source\n}\n"],"mappings":";;;;;;AA6BA,MAAa,oBAAoB;CAC/B,cAAgC,CAAC,UAAU,OAAO,GAAG,UAAU,YAAY,CAAC;CAC5E,kBAAoC,CAAC,UAAU,WAAW,CAAC;CAC3D,aAA+B,CAAC,UAAU,MAAM,CAAC;CACjD,iBAAmC,CAAC,UAAU,UAAU,CAAC;AAC3D;AAEA,eAAsB,sBAAsB,UAAkD;CAG5F,OAAO,cAAc,kBAAkB,SAAS,CAAC,GAAG;EAAE,cAAc;EAAO,SAAS;CAAM,CAAC;AAC7F;AAEA,SAAgB,mBACd,QAC4B;CAC5B,OAAO,SAAS;AAClB"}
1
+ {"version":3,"file":"providers.js","names":[],"sources":["../../../src/text/web-font/providers.ts"],"sourcesContent":["import type {\n GoogleFamilyOptions,\n providers,\n RemoteFontSource,\n ResolveFontOptions,\n Unifont\n} from 'unifont'\n\nimport type { WebFontProviderId } from '#core/text/web-font/resolver'\n\nexport type WebFontProvider =\n | ReturnType<typeof providers.google>\n | ReturnType<typeof providers.googleicons>\n | ReturnType<typeof providers.fontsource>\n | ReturnType<typeof providers.bunny>\n | ReturnType<typeof providers.fontshare>\n/** One or more providers behind a provider setting. */\nexport type WebFontProviders = [WebFontProvider, ...WebFontProvider[]]\nexport type WebUnifont = Unifont<WebFontProviders>\nexport type WebFontResolveOptions = Pick<\n ResolveFontOptions<{ google?: GoogleFamilyOptions }>,\n 'weights' | 'styles' | 'formats' | 'subsets' | 'variableAxis' | 'options'\n>\n\ntype UnifontProviders = typeof providers\n\n/**\n * The unifont providers behind each provider setting. Google serves its Material Symbols from\n * its icon catalogue, as variable fonts with every axis, so its setting covers both.\n */\nconst providerFactories = {\n google: (from: UnifontProviders): WebFontProviders => [from.google(), from.googleicons()],\n fontsource: (from: UnifontProviders): WebFontProviders => [from.fontsource()],\n bunny: (from: UnifontProviders): WebFontProviders => [from.bunny()],\n fontshare: (from: UnifontProviders): WebFontProviders => [from.fontshare()]\n} satisfies Record<WebFontProviderId, (from: UnifontProviders) => WebFontProviders>\n\n/** Unifont, with its CSS parser, loads with the first font looked up rather than with the editor. */\nexport async function createProviderUnifont(provider: WebFontProviderId): Promise<WebUnifont> {\n const { createUnifont, providers: unifontProviders } = await import('unifont')\n // In a page unifont sends provider requests to its hosted proxy; ours go through the host's\n // fetch, which reaches the providers itself.\n return createUnifont(providerFactories[provider](unifontProviders), {\n throwOnError: false,\n apiBase: false\n })\n}\n\nexport function isRemoteFontSource(\n source: RemoteFontSource | { name: string }\n): source is RemoteFontSource {\n return 'url' in source\n}\n"],"mappings":";;;;;AA8BA,MAAM,oBAAoB;CACxB,SAAS,SAA6C,CAAC,KAAK,OAAO,GAAG,KAAK,YAAY,CAAC;CACxF,aAAa,SAA6C,CAAC,KAAK,WAAW,CAAC;CAC5E,QAAQ,SAA6C,CAAC,KAAK,MAAM,CAAC;CAClE,YAAY,SAA6C,CAAC,KAAK,UAAU,CAAC;AAC5E;;AAGA,eAAsB,sBAAsB,UAAkD;CAC5F,MAAM,EAAE,eAAe,WAAW,qBAAqB,MAAM,OAAO;CAGpE,OAAO,cAAc,kBAAkB,SAAS,CAAC,gBAAgB,GAAG;EAClE,cAAc;EACd,SAAS;CACX,CAAC;AACH;AAEA,SAAgB,mBACd,QAC4B;CAC5B,OAAO,SAAS;AAClB"}
@@ -13,8 +13,9 @@ interface LayerJSXChange {
13
13
  /**
14
14
  * Top-level layers of a page whose JSX differs between two states of a document, in their
15
15
  * order afterwards, then removed ones. Both graphs must share node IDs, as a snapshot does.
16
+ * `layerIds` limits the comparison to those top-level layers, such as the ones an edit touched.
16
17
  */
17
- declare function diffPageLayersJSX(before: SceneGraph, after: SceneGraph, pageId: string): LayerJSXChange[];
18
+ declare function diffPageLayersJSX(before: SceneGraph, after: SceneGraph, pageId: string, layerIds?: readonly string[]): LayerJSXChange[];
18
19
  //#endregion
19
20
  export { LayerJSXChange, diffPageLayersJSX, jsxPatch };
20
21
  //# sourceMappingURL=jsx.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsx.d.ts","names":[],"sources":["../../../../src/tools/analyze/diff/jsx.ts"],"mappings":";;;iBAMgB,SACd,kBACA,gBACA,iBACA;UAWe;EACf;;EAEA;;EAEA;EACA;;;;;;iBAWc,kBACd,QAAQ,YACR,OAAO,YACP,iBACC"}
1
+ {"version":3,"file":"jsx.d.ts","names":[],"sources":["../../../../src/tools/analyze/diff/jsx.ts"],"mappings":";;;iBAMgB,SACd,kBACA,gBACA,iBACA;UAWe;EACf;;EAEA;;EAEA;EACA;;;;;;;iBAYc,kBACd,QAAQ,YACR,OAAO,YACP,gBACA,+BACC"}
@@ -16,9 +16,11 @@ function layerJSX(graph, id) {
16
16
  /**
17
17
  * Top-level layers of a page whose JSX differs between two states of a document, in their
18
18
  * order afterwards, then removed ones. Both graphs must share node IDs, as a snapshot does.
19
+ * `layerIds` limits the comparison to those top-level layers, such as the ones an edit touched.
19
20
  */
20
- function diffPageLayersJSX(before, after, pageId) {
21
- return [.../* @__PURE__ */ new Set([...after.getNode(pageId)?.childIds ?? [], ...before.getNode(pageId)?.childIds ?? []])].flatMap((id) => {
21
+ function diffPageLayersJSX(before, after, pageId, layerIds) {
22
+ const only = layerIds ? new Set(layerIds) : null;
23
+ return [...new Set([...after.getNode(pageId)?.childIds ?? [], ...before.getNode(pageId)?.childIds ?? []].filter((id) => !only || only.has(id)))].flatMap((id) => {
22
24
  const from = layerJSX(before, id);
23
25
  const to = layerJSX(after, id);
24
26
  const name = after.getNode(id)?.name ?? before.getNode(id)?.name ?? id;
@@ -1 +1 @@
1
- {"version":3,"file":"jsx.js","names":[],"sources":["../../../../src/tools/analyze/diff/jsx.ts"],"sourcesContent":["import { createTwoFilesPatch, FILE_HEADERS_ONLY } from 'diff'\n\nimport { sceneNodeToJSX } from '@pairdraw/design-jsx'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\n/** Unified diff of two JSX sources, as `diff_jsx` returns it; `null` when they match. */\nexport function jsxPatch(\n fromName: string,\n toName: string,\n fromJSX: string,\n toJSX: string\n): string | null {\n if (fromJSX === toJSX) return null\n // Line-terminated sources keep \"No newline at end of file\" out of the patch.\n const lines = (jsx: string) => (jsx ? `${jsx}\\n` : '')\n return createTwoFilesPatch(fromName, toName, lines(fromJSX), lines(toJSX), undefined, undefined, {\n context: 3,\n headerOptions: FILE_HEADERS_ONLY\n })\n}\n\nexport interface LayerJSXChange {\n id: string\n /** Empty when the layer was added. */\n before: string\n /** Empty when the layer was removed. */\n after: string\n patch: string\n}\n\nfunction layerJSX(graph: SceneGraph, id: string): string {\n return graph.getNode(id) ? sceneNodeToJSX(id, graph) : ''\n}\n\n/**\n * Top-level layers of a page whose JSX differs between two states of a document, in their\n * order afterwards, then removed ones. Both graphs must share node IDs, as a snapshot does.\n */\nexport function diffPageLayersJSX(\n before: SceneGraph,\n after: SceneGraph,\n pageId: string\n): LayerJSXChange[] {\n const ids = new Set([\n ...(after.getNode(pageId)?.childIds ?? []),\n ...(before.getNode(pageId)?.childIds ?? [])\n ])\n return [...ids].flatMap((id) => {\n const from = layerJSX(before, id)\n const to = layerJSX(after, id)\n const name = after.getNode(id)?.name ?? before.getNode(id)?.name ?? id\n const patch = jsxPatch(`${name} #${id}`, `${name} #${id}`, from, to)\n return patch === null ? [] : [{ id, before: from, after: to, patch }]\n })\n}\n"],"mappings":";;;;AAMA,SAAgB,SACd,UACA,QACA,SACA,OACe;CACf,IAAI,YAAY,OAAO,OAAO;CAE9B,MAAM,SAAS,QAAiB,MAAM,GAAG,IAAI,MAAM;CACnD,OAAO,oBAAoB,UAAU,QAAQ,MAAM,OAAO,GAAG,MAAM,KAAK,GAAG,KAAA,GAAW,KAAA,GAAW;EAC/F,SAAS;EACT,eAAe;CACjB,CAAC;AACH;AAWA,SAAS,SAAS,OAAmB,IAAoB;CACvD,OAAO,MAAM,QAAQ,EAAE,IAAI,eAAe,IAAI,KAAK,IAAI;AACzD;;;;;AAMA,SAAgB,kBACd,QACA,OACA,QACkB;CAKlB,OAAO,CAAC,mBAAG,IAJK,IAAI,CAClB,GAAI,MAAM,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC,GACxC,GAAI,OAAO,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC,CAC3C,CACa,CAAC,CAAC,CAAC,SAAS,OAAO;EAC9B,MAAM,OAAO,SAAS,QAAQ,EAAE;EAChC,MAAM,KAAK,SAAS,OAAO,EAAE;EAC7B,MAAM,OAAO,MAAM,QAAQ,EAAE,CAAC,EAAE,QAAQ,OAAO,QAAQ,EAAE,CAAC,EAAE,QAAQ;EACpE,MAAM,QAAQ,SAAS,GAAG,KAAK,IAAI,MAAM,GAAG,KAAK,IAAI,MAAM,MAAM,EAAE;EACnE,OAAO,UAAU,OAAO,CAAC,IAAI,CAAC;GAAE;GAAI,QAAQ;GAAM,OAAO;GAAI;EAAM,CAAC;CACtE,CAAC;AACH"}
1
+ {"version":3,"file":"jsx.js","names":[],"sources":["../../../../src/tools/analyze/diff/jsx.ts"],"sourcesContent":["import { createTwoFilesPatch, FILE_HEADERS_ONLY } from 'diff'\n\nimport { sceneNodeToJSX } from '@pairdraw/design-jsx'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\n/** Unified diff of two JSX sources, as `diff_jsx` returns it; `null` when they match. */\nexport function jsxPatch(\n fromName: string,\n toName: string,\n fromJSX: string,\n toJSX: string\n): string | null {\n if (fromJSX === toJSX) return null\n // Line-terminated sources keep \"No newline at end of file\" out of the patch.\n const lines = (jsx: string) => (jsx ? `${jsx}\\n` : '')\n return createTwoFilesPatch(fromName, toName, lines(fromJSX), lines(toJSX), undefined, undefined, {\n context: 3,\n headerOptions: FILE_HEADERS_ONLY\n })\n}\n\nexport interface LayerJSXChange {\n id: string\n /** Empty when the layer was added. */\n before: string\n /** Empty when the layer was removed. */\n after: string\n patch: string\n}\n\nfunction layerJSX(graph: SceneGraph, id: string): string {\n return graph.getNode(id) ? sceneNodeToJSX(id, graph) : ''\n}\n\n/**\n * Top-level layers of a page whose JSX differs between two states of a document, in their\n * order afterwards, then removed ones. Both graphs must share node IDs, as a snapshot does.\n * `layerIds` limits the comparison to those top-level layers, such as the ones an edit touched.\n */\nexport function diffPageLayersJSX(\n before: SceneGraph,\n after: SceneGraph,\n pageId: string,\n layerIds?: readonly string[]\n): LayerJSXChange[] {\n const only = layerIds ? new Set(layerIds) : null\n const ids = new Set(\n [\n ...(after.getNode(pageId)?.childIds ?? []),\n ...(before.getNode(pageId)?.childIds ?? [])\n ].filter((id) => !only || only.has(id))\n )\n return [...ids].flatMap((id) => {\n const from = layerJSX(before, id)\n const to = layerJSX(after, id)\n const name = after.getNode(id)?.name ?? before.getNode(id)?.name ?? id\n const patch = jsxPatch(`${name} #${id}`, `${name} #${id}`, from, to)\n return patch === null ? [] : [{ id, before: from, after: to, patch }]\n })\n}\n"],"mappings":";;;;AAMA,SAAgB,SACd,UACA,QACA,SACA,OACe;CACf,IAAI,YAAY,OAAO,OAAO;CAE9B,MAAM,SAAS,QAAiB,MAAM,GAAG,IAAI,MAAM;CACnD,OAAO,oBAAoB,UAAU,QAAQ,MAAM,OAAO,GAAG,MAAM,KAAK,GAAG,KAAA,GAAW,KAAA,GAAW;EAC/F,SAAS;EACT,eAAe;CACjB,CAAC;AACH;AAWA,SAAS,SAAS,OAAmB,IAAoB;CACvD,OAAO,MAAM,QAAQ,EAAE,IAAI,eAAe,IAAI,KAAK,IAAI;AACzD;;;;;;AAOA,SAAgB,kBACd,QACA,OACA,QACA,UACkB;CAClB,MAAM,OAAO,WAAW,IAAI,IAAI,QAAQ,IAAI;CAO5C,OAAO,CAAC,GAAG,IANK,IACd,CACE,GAAI,MAAM,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC,GACxC,GAAI,OAAO,QAAQ,MAAM,CAAC,EAAE,YAAY,CAAC,CAC3C,CAAC,CAAC,QAAQ,OAAO,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC,CAE3B,CAAC,CAAC,CAAC,SAAS,OAAO;EAC9B,MAAM,OAAO,SAAS,QAAQ,EAAE;EAChC,MAAM,KAAK,SAAS,OAAO,EAAE;EAC7B,MAAM,OAAO,MAAM,QAAQ,EAAE,CAAC,EAAE,QAAQ,OAAO,QAAQ,EAAE,CAAC,EAAE,QAAQ;EACpE,MAAM,QAAQ,SAAS,GAAG,KAAK,IAAI,MAAM,GAAG,KAAK,IAAI,MAAM,MAAM,EAAE;EACnE,OAAO,UAAU,OAAO,CAAC,IAAI,CAAC;GAAE;GAAI,QAAQ;GAAM,OAAO;GAAI;EAAM,CAAC;CACtE,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/core",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -12,14 +12,14 @@
12
12
  "dependencies": {
13
13
  "@chenglou/pretext": "^0.0.7",
14
14
  "@iconify/utils": "^3.1.4",
15
- "@pairdraw/design-jsx": "^0.16.0",
16
- "@pairdraw/dom-css": "^0.16.0",
17
- "@pairdraw/drawio": "^0.16.0",
18
- "@pairdraw/fig": "^0.16.0",
19
- "@pairdraw/kiwi": "^0.16.0",
20
- "@pairdraw/mermaid": "^0.16.0",
21
- "@pairdraw/pen": "^0.16.0",
22
- "@pairdraw/scene-graph": "^0.16.0",
15
+ "@pairdraw/design-jsx": "^0.16.2",
16
+ "@pairdraw/dom-css": "^0.16.2",
17
+ "@pairdraw/drawio": "^0.16.2",
18
+ "@pairdraw/fig": "^0.16.2",
19
+ "@pairdraw/kiwi": "^0.16.2",
20
+ "@pairdraw/mermaid": "^0.16.2",
21
+ "@pairdraw/pen": "^0.16.2",
22
+ "@pairdraw/scene-graph": "^0.16.2",
23
23
  "@tauri-apps/api": "^2.12.1",
24
24
  "@valibot/to-json-schema": "^1.8.0",
25
25
  "@xmldom/xmldom": "^0.9.12",
@@ -214,6 +214,21 @@
214
214
  "#core/*": "./src/*.ts",
215
215
  "#core-tests/*": "./tests/*.ts"
216
216
  },
217
+ "description": "Pairdraw editor engine: the CanvasKit renderer, Yoga layout, the framework-agnostic editor, the Figma Plugin API, and the AI/MCP tool definitions.",
218
+ "keywords": [
219
+ "pairdraw",
220
+ "design",
221
+ "editor",
222
+ "figma",
223
+ "canvaskit",
224
+ "skia",
225
+ "layout"
226
+ ],
227
+ "author": "Badryansah Bangsawan",
228
+ "homepage": "https://github.com/BadryansahBangsawan/pairdraw/tree/main/packages/core#readme",
229
+ "bugs": {
230
+ "url": "https://github.com/BadryansahBangsawan/pairdraw/issues"
231
+ },
217
232
  "repository": {
218
233
  "type": "git",
219
234
  "url": "git+https://github.com/BadryansahBangsawan/pairdraw.git",