@pairdraw/core 0.21.1 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/boolean.d.ts +6 -1
- package/dist/canvas/boolean.d.ts.map +1 -1
- package/dist/canvas/boolean.js +10 -2
- package/dist/canvas/boolean.js.map +1 -1
- package/dist/canvas/color-space.d.ts +45 -0
- package/dist/canvas/color-space.d.ts.map +1 -0
- package/dist/canvas/color-space.js +39 -0
- package/dist/canvas/color-space.js.map +1 -0
- package/dist/canvas/fills.d.ts +10 -10
- package/dist/canvas/fills.d.ts.map +1 -1
- package/dist/canvas/fills.js +116 -62
- package/dist/canvas/fills.js.map +1 -1
- package/dist/canvas/flatten.d.ts +11 -3
- package/dist/canvas/flatten.d.ts.map +1 -1
- package/dist/canvas/flatten.js +62 -4
- package/dist/canvas/flatten.js.map +1 -1
- package/dist/canvas/index.d.ts +2 -1
- package/dist/canvas/index.js +2 -1
- package/dist/canvas/layout-grids.d.ts +5 -2
- package/dist/canvas/layout-grids.d.ts.map +1 -1
- package/dist/canvas/layout-grids.js +7 -2
- package/dist/canvas/layout-grids.js.map +1 -1
- package/dist/canvas/noise/render.d.ts +17 -4
- package/dist/canvas/noise/render.d.ts.map +1 -1
- package/dist/canvas/noise/render.js +21 -6
- package/dist/canvas/noise/render.js.map +1 -1
- package/dist/canvas/noise/shader.d.ts +4 -4
- package/dist/canvas/noise/shader.d.ts.map +1 -1
- package/dist/canvas/noise/shader.js +5 -6
- package/dist/canvas/noise/shader.js.map +1 -1
- package/dist/canvas/overlays/annotations.d.ts +19 -0
- package/dist/canvas/overlays/annotations.d.ts.map +1 -0
- package/dist/canvas/overlays/annotations.js +110 -0
- package/dist/canvas/overlays/annotations.js.map +1 -0
- package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
- package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
- package/dist/canvas/overlays/auto-layout-hover.js +25 -1
- package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
- package/dist/canvas/overlays/feedback.js +1 -1
- package/dist/canvas/overlays/feedback.js.map +1 -1
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/measurement.d.ts +7 -1
- package/dist/canvas/overlays/measurement.d.ts.map +1 -1
- package/dist/canvas/overlays/measurement.js +42 -4
- package/dist/canvas/overlays/measurement.js.map +1 -1
- package/dist/canvas/overlays/presence.d.ts.map +1 -1
- package/dist/canvas/overlays/presence.js +21 -24
- package/dist/canvas/overlays/presence.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts +7 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +9 -1
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/document-surface.d.ts +15 -6
- package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
- package/dist/canvas/renderer/document-surface.js +1 -0
- package/dist/canvas/renderer/document-surface.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +2 -2
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +1 -0
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +4 -1
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +6 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +7 -0
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +10 -0
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +10 -2
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +15 -3
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +9 -9
- package/dist/canvas/scene.js.map +1 -1
- package/dist/clipboard/pairdraw.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.js +1 -0
- package/dist/clipboard/pairdraw.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +2 -0
- package/dist/editor/bridges/clipboard.d.ts.map +1 -1
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +14 -7
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +6 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -1
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/clipboard/code.d.ts +32 -0
- package/dist/editor/clipboard/code.d.ts.map +1 -0
- package/dist/editor/clipboard/code.js +30 -0
- package/dist/editor/clipboard/code.js.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
- package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/dependencies.js +0 -0
- package/dist/editor/clipboard/paste/run.d.ts +14 -0
- package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
- package/dist/editor/clipboard/paste/run.js +47 -0
- package/dist/editor/clipboard/paste/run.js.map +1 -0
- package/dist/editor/clipboard/styled.d.ts +2 -8
- package/dist/editor/clipboard/styled.d.ts.map +1 -1
- package/dist/editor/clipboard/styled.js +2 -32
- package/dist/editor/clipboard/styled.js.map +1 -1
- package/dist/editor/clipboard.d.ts +2 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +34 -0
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/components/instances.d.ts +5 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +69 -4
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/slots/index.d.ts.map +1 -1
- package/dist/editor/components/slots/index.js +7 -0
- package/dist/editor/components/slots/index.js.map +1 -1
- package/dist/editor/components.d.ts +6 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/components.js +14 -2
- package/dist/editor/components.js.map +1 -1
- package/dist/editor/create.d.ts +29 -2
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +11 -2
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/design-tokens.d.ts +1 -1
- package/dist/editor/design-tokens.d.ts.map +1 -1
- package/dist/editor/design-tokens.js +4 -18
- package/dist/editor/design-tokens.js.map +1 -1
- package/dist/editor/image-edit.d.ts.map +1 -1
- package/dist/editor/image-edit.js +1 -2
- package/dist/editor/image-edit.js.map +1 -1
- package/dist/editor/index.d.ts +4 -4
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts +3 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +97 -2
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/nodes.d.ts +2 -0
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +22 -7
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/read-only/actions.js +6 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/overlays.d.ts +1 -0
- package/dist/editor/selection/overlays.d.ts.map +1 -1
- package/dist/editor/selection/overlays.js +7 -0
- package/dist/editor/selection/overlays.js.map +1 -1
- package/dist/editor/selection/read.d.ts +8 -0
- package/dist/editor/selection.d.ts +9 -0
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/state/shared.js +1 -0
- package/dist/editor/state/shared.js.map +1 -1
- package/dist/editor/state/view.d.ts.map +1 -1
- package/dist/editor/state/view.js +2 -0
- package/dist/editor/state/view.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +1 -1
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js +20 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/container-wrap.d.ts +8 -2
- package/dist/editor/structure/container-wrap.d.ts.map +1 -1
- package/dist/editor/structure/container-wrap.js +17 -5
- package/dist/editor/structure/container-wrap.js.map +1 -1
- package/dist/editor/structure/flatten.d.ts.map +1 -1
- package/dist/editor/structure/flatten.js +8 -7
- package/dist/editor/structure/flatten.js.map +1 -1
- package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
- package/dist/editor/structure/group/ungroup.js +2 -0
- package/dist/editor/structure/group/ungroup.js.map +1 -1
- package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
- package/dist/editor/structure/outline-stroke.js +5 -0
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -1
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/styles.d.ts +26 -0
- package/dist/editor/styles.d.ts.map +1 -0
- package/dist/editor/styles.js +127 -0
- package/dist/editor/styles.js.map +1 -0
- package/dist/editor/text/selection-style.d.ts +1 -0
- package/dist/editor/text/selection-style.d.ts.map +1 -1
- package/dist/editor/text/selection-style.js +10 -2
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/tool-registry.d.ts.map +1 -1
- package/dist/editor/tool-registry.js +6 -0
- package/dist/editor/tool-registry.js.map +1 -1
- package/dist/editor/types.d.ts +14 -2
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +6 -1
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +22 -1
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/shape.js +1 -1
- package/dist/figma-api/accessors/text/index.js +1 -1
- package/dist/figma-api/accessors/text/ranges.js +1 -1
- package/dist/figma-api/accessors/text/references.js +1 -1
- package/dist/figma-api/accessors/variables.js +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +8 -22
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.js +1 -1
- package/dist/figma-api/compatibility.d.ts +1 -1
- package/dist/figma-api/compatibility.d.ts.map +1 -1
- package/dist/figma-api/component-scope.d.ts +14 -0
- package/dist/figma-api/component-scope.d.ts.map +1 -0
- package/dist/figma-api/component-scope.js +28 -0
- package/dist/figma-api/component-scope.js.map +1 -0
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +26 -2
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/flatten.js +3 -3
- package/dist/figma-api/flatten.js.map +1 -1
- package/dist/figma-api/index.d.ts +77 -6
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +188 -2
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/node-types.d.ts +2 -1
- package/dist/figma-api/node-types.d.ts.map +1 -1
- package/dist/figma-api/overrides.d.ts +26 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +157 -10
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/proxy.d.ts +2 -0
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +10 -2
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +61 -5
- package/dist/figma-api/reactions.d.ts.map +1 -1
- package/dist/figma-api/reactions.js +144 -11
- package/dist/figma-api/reactions.js.map +1 -1
- package/dist/figma-api/shape-with-text.js +1 -1
- package/dist/figma-api/slots.d.ts +3 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +9 -8
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/io/formats/code/detect.d.ts +23 -0
- package/dist/io/formats/code/detect.d.ts.map +1 -0
- package/dist/io/formats/code/detect.js +46 -0
- package/dist/io/formats/code/detect.js.map +1 -0
- package/dist/io/formats/code/index.d.ts +5 -0
- package/dist/io/formats/code/index.js +5 -0
- package/dist/io/formats/code/read.d.ts +45 -0
- package/dist/io/formats/code/read.d.ts.map +1 -0
- package/dist/io/formats/code/read.js +86 -0
- package/dist/io/formats/code/read.js.map +1 -0
- package/dist/io/formats/code/stylesheet.d.ts +13 -0
- package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
- package/dist/io/formats/code/stylesheet.js +21 -0
- package/dist/io/formats/code/stylesheet.js.map +1 -0
- package/dist/io/formats/code/tokens.d.ts +18 -0
- package/dist/io/formats/code/tokens.d.ts.map +1 -0
- package/dist/io/formats/code/tokens.js +135 -0
- package/dist/io/formats/code/tokens.js.map +1 -0
- package/dist/io/formats/design-tokens/apply.d.ts +7 -3
- package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/apply.js.map +1 -1
- package/dist/io/formats/fig/export/patch/fields.js +5 -0
- package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
- package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
- package/dist/io/formats/fig/export/patch/index.js +20 -20
- package/dist/io/formats/fig/export/patch/index.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +5 -1
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +3 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +5 -2
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +3 -1
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +6 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/export.d.ts.map +1 -1
- package/dist/io/formats/pdf/export.js +7 -3
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/pdf/plan.d.ts +3 -0
- package/dist/io/formats/pdf/plan.d.ts.map +1 -1
- package/dist/io/formats/pdf/plan.js +60 -36
- package/dist/io/formats/pdf/plan.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +3 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/index.d.ts +2 -2
- package/dist/io/formats/raster/index.js +2 -2
- package/dist/io/formats/raster/render.d.ts +10 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +35 -9
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +19 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts +5 -2
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +59 -10
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/index.d.ts +2 -2
- package/dist/io/formats/svg/index.js +2 -2
- package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
- package/dist/io/formats/svg/text/layout.js +4 -2
- package/dist/io/formats/svg/text/layout.js.map +1 -1
- package/dist/io/formats/video/record.d.ts.map +1 -1
- package/dist/io/formats/video/record.js +24 -9
- package/dist/io/formats/video/record.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +20 -13
- package/dist/io/formats.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +2 -1
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +46 -2
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +113 -5
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/options.d.ts +4 -0
- package/dist/kiwi/fig/session/options.d.ts.map +1 -1
- package/dist/kiwi/fig/session/options.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +8 -4
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/auto-layout-handles.js +1 -1
- package/dist/layout/auto-layout-handles.js.map +1 -1
- package/dist/layout/axis-sizing.d.ts.map +1 -1
- package/dist/layout/axis-sizing.js +1 -1
- package/dist/layout/axis-sizing.js.map +1 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +1 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/effective-generated-text.js +1 -1
- package/dist/layout/effective-generated-text.js.map +1 -1
- package/dist/layout/grid.d.ts +3 -1
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +57 -16
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.js +6 -5
- package/dist/layout.js.map +1 -1
- package/dist/node/fs.d.ts.map +1 -1
- package/dist/node/fs.js +28 -7
- package/dist/node/fs.js.map +1 -1
- package/dist/prototype/easing.d.ts +13 -5
- package/dist/prototype/easing.d.ts.map +1 -1
- package/dist/prototype/easing.js +46 -6
- package/dist/prototype/easing.js.map +1 -1
- package/dist/prototype/scenes.d.ts +31 -0
- package/dist/prototype/scenes.d.ts.map +1 -1
- package/dist/prototype/scenes.js +220 -31
- package/dist/prototype/scenes.js.map +1 -1
- package/dist/prototype/session.d.ts.map +1 -1
- package/dist/prototype/session.js +1 -0
- package/dist/prototype/session.js.map +1 -1
- package/dist/prototype/smart-animate/animation.d.ts +2 -1
- package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
- package/dist/prototype/smart-animate/animation.js +2 -2
- package/dist/prototype/smart-animate/animation.js.map +1 -1
- package/dist/prototype/timeline.d.ts +10 -1
- package/dist/prototype/timeline.d.ts.map +1 -1
- package/dist/prototype/timeline.js +69 -23
- package/dist/prototype/timeline.js.map +1 -1
- package/dist/prototype/variables.d.ts +23 -0
- package/dist/prototype/variables.d.ts.map +1 -0
- package/dist/prototype/variables.js +237 -0
- package/dist/prototype/variables.js.map +1 -0
- package/dist/rpc/read-commands.d.ts +5 -0
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +4 -1
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/character-style.d.ts +8 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +39 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/create/basic.js +3 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/behaviours.js +1 -1
- package/dist/tools/create/code.d.ts +6 -0
- package/dist/tools/create/code.d.ts.map +1 -0
- package/dist/tools/create/code.js +68 -0
- package/dist/tools/create/code.js.map +1 -0
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +9 -57
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.js +1 -1
- package/dist/tools/create/inputs.d.ts +11 -0
- package/dist/tools/create/inputs.d.ts.map +1 -0
- package/dist/tools/create/inputs.js +15 -0
- package/dist/tools/create/inputs.js.map +1 -0
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +5 -6
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/place.d.ts +30 -0
- package/dist/tools/create/place.d.ts.map +1 -0
- package/dist/tools/create/place.js +70 -0
- package/dist/tools/create/place.js.map +1 -0
- package/dist/tools/create/render.js +1 -1
- package/dist/tools/create/svg.js +1 -1
- package/dist/tools/create/vector.js +1 -1
- package/dist/tools/create.d.ts +2 -1
- package/dist/tools/create.js +2 -1
- package/dist/tools/css/gradient.d.ts +28 -0
- package/dist/tools/css/gradient.d.ts.map +1 -0
- package/dist/tools/css/gradient.js +118 -0
- package/dist/tools/css/gradient.js.map +1 -0
- package/dist/tools/image-ai/generate.js +1 -1
- package/dist/tools/modify/geometry.js +5 -5
- package/dist/tools/modify/geometry.js.map +1 -1
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +7 -1
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/overrides.d.ts +6 -0
- package/dist/tools/modify/overrides.d.ts.map +1 -0
- package/dist/tools/modify/overrides.js +27 -0
- package/dist/tools/modify/overrides.js.map +1 -0
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +84 -39
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts +2 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +79 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/modify/update.d.ts.map +1 -1
- package/dist/tools/modify/update.js +18 -2
- package/dist/tools/modify/update.js.map +1 -1
- package/dist/tools/modify.d.ts +3 -2
- package/dist/tools/modify.js +3 -2
- package/dist/tools/read/css.d.ts.map +1 -1
- package/dist/tools/read/css.js +29 -12
- package/dist/tools/read/css.js.map +1 -1
- package/dist/tools/read/libraries.js +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +19 -5
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/text-range.d.ts +11 -0
- package/dist/tools/text-range.d.ts.map +1 -0
- package/dist/tools/text-range.js +26 -0
- package/dist/tools/text-range.js.map +1 -0
- package/dist/tools/variables/bindings.js +1 -1
- package/dist/tools/variables/bindings.js.map +1 -1
- package/dist/tools/variables/unbind.js +1 -1
- package/dist/tools/variables/unbind.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +7 -21
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/vector/rebase.d.ts +17 -0
- package/dist/vector/rebase.d.ts.map +1 -0
- package/dist/vector/rebase.js +32 -0
- package/dist/vector/rebase.js.map +1 -0
- package/package.json +14 -9
- package/src/canvas/boolean.ts +12 -1
- package/src/canvas/color-space.ts +73 -0
- package/src/canvas/fills.ts +130 -83
- package/src/canvas/flatten.ts +92 -7
- package/src/canvas/index.ts +9 -0
- package/src/canvas/layout-grids.ts +15 -2
- package/src/canvas/noise/render.ts +35 -7
- package/src/canvas/noise/shader.ts +8 -10
- package/src/canvas/overlays/annotations.ts +117 -0
- package/src/canvas/overlays/auto-layout-hover.ts +41 -1
- package/src/canvas/overlays/feedback.ts +7 -2
- package/src/canvas/overlays/index.ts +1 -1
- package/src/canvas/overlays/measurement.ts +49 -3
- package/src/canvas/overlays/presence.ts +35 -32
- package/src/canvas/renderer/colors.ts +14 -0
- package/src/canvas/renderer/document-surface.ts +16 -6
- package/src/canvas/renderer/lifecycle.ts +2 -2
- package/src/canvas/renderer/methods.ts +4 -0
- package/src/canvas/renderer/overlay-pass.ts +4 -0
- package/src/canvas/renderer/pipeline.ts +8 -0
- package/src/canvas/renderer/types.ts +8 -0
- package/src/canvas/renderer.ts +21 -2
- package/src/canvas/scene.ts +15 -7
- package/src/clipboard/pairdraw.ts +1 -0
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +10 -0
- package/src/editor/clipboard/code.ts +50 -0
- package/src/editor/clipboard/paste/dependencies.ts +18 -0
- package/src/editor/clipboard/paste/run.ts +64 -0
- package/src/editor/clipboard/styled.ts +4 -52
- package/src/editor/clipboard.ts +40 -0
- package/src/editor/components/instances.ts +92 -4
- package/src/editor/components/slots/index.ts +7 -0
- package/src/editor/components.ts +16 -2
- package/src/editor/create.ts +15 -1
- package/src/editor/design-tokens.ts +3 -23
- package/src/editor/image-edit.ts +5 -2
- package/src/editor/index.ts +1 -0
- package/src/editor/layout-mode.ts +131 -3
- package/src/editor/nodes.ts +30 -5
- package/src/editor/read-only/actions.ts +6 -0
- package/src/editor/selection/overlays.ts +8 -0
- package/src/editor/state/shared.ts +1 -0
- package/src/editor/state/view.ts +2 -0
- package/src/editor/structure/boolean.ts +29 -1
- package/src/editor/structure/container-wrap.ts +20 -4
- package/src/editor/structure/flatten.ts +15 -8
- package/src/editor/structure/group/ungroup.ts +2 -0
- package/src/editor/structure/outline-stroke.ts +5 -0
- package/src/editor/styles.ts +203 -0
- package/src/editor/text/selection-style.ts +18 -1
- package/src/editor/tool-registry.ts +2 -0
- package/src/editor/types.ts +14 -0
- package/src/editor/variable-bindings.ts +11 -0
- package/src/figma-api/accessors/basic.ts +33 -1
- package/src/figma-api/accessors/vector.ts +6 -13
- package/src/figma-api/compatibility.ts +1 -0
- package/src/figma-api/component-scope.ts +36 -0
- package/src/figma-api/components.ts +24 -0
- package/src/figma-api/flatten.ts +7 -3
- package/src/figma-api/index.ts +302 -6
- package/src/figma-api/node-types.ts +1 -0
- package/src/figma-api/overrides.ts +192 -5
- package/src/figma-api/proxy.ts +16 -1
- package/src/figma-api/reactions.ts +163 -12
- package/src/figma-api/slots.ts +10 -9
- package/src/io/formats/code/detect.ts +67 -0
- package/src/io/formats/code/index.ts +17 -0
- package/src/io/formats/code/read.ts +143 -0
- package/src/io/formats/code/stylesheet.ts +24 -0
- package/src/io/formats/code/tokens.ts +159 -0
- package/src/io/formats/design-tokens/apply.ts +3 -2
- package/src/io/formats/fig/export/patch/fields.ts +11 -0
- package/src/io/formats/fig/export/patch/index.ts +23 -19
- package/src/io/formats/fig/export/setup.ts +8 -1
- package/src/io/formats/fig/index.ts +6 -0
- package/src/io/formats/fig/read.ts +11 -2
- package/src/io/formats/html/layers.ts +7 -0
- package/src/io/formats/pdf/export.ts +19 -7
- package/src/io/formats/pdf/plan.ts +71 -32
- package/src/io/formats/raster/headless.ts +3 -1
- package/src/io/formats/raster/index.ts +2 -0
- package/src/io/formats/raster/render.ts +49 -9
- package/src/io/formats/svg/defs.ts +27 -1
- package/src/io/formats/svg/export.ts +75 -13
- package/src/io/formats/svg/index.ts +1 -0
- package/src/io/formats/svg/text/layout.ts +5 -3
- package/src/io/formats/video/record.ts +33 -9
- package/src/io/formats.ts +35 -15
- package/src/kiwi/fig/population/client.ts +6 -1
- package/src/kiwi/fig/session/document-state.ts +195 -5
- package/src/kiwi/fig/session/options.ts +2 -0
- package/src/layout/apply.ts +12 -4
- package/src/layout/auto-layout-handles.ts +1 -1
- package/src/layout/axis-sizing.ts +3 -1
- package/src/layout/derived.ts +3 -1
- package/src/layout/effective-generated-text.ts +1 -1
- package/src/layout/grid.ts +91 -21
- package/src/layout.ts +16 -3
- package/src/node/fs.ts +32 -7
- package/src/prototype/easing.ts +79 -7
- package/src/prototype/scenes.ts +244 -15
- package/src/prototype/session.ts +1 -0
- package/src/prototype/smart-animate/animation.ts +4 -3
- package/src/prototype/timeline.ts +118 -26
- package/src/prototype/variables.ts +189 -0
- package/src/rpc/read-commands.ts +19 -1
- package/src/text/character-style.ts +47 -0
- package/src/text/index.ts +1 -1
- package/src/tools/create/basic.ts +2 -3
- package/src/tools/create/code.ts +85 -0
- package/src/tools/create/html.ts +9 -46
- package/src/tools/create/inputs.ts +12 -0
- package/src/tools/create/mermaid.ts +6 -6
- package/src/tools/create/place.ts +80 -0
- package/src/tools/create.ts +1 -0
- package/src/tools/css/gradient.ts +147 -0
- package/src/tools/modify/geometry.ts +5 -5
- package/src/tools/modify/layout.ts +19 -0
- package/src/tools/modify/overrides.ts +35 -0
- package/src/tools/modify/paint.ts +124 -54
- package/src/tools/modify/text.ts +91 -7
- package/src/tools/modify/update.ts +23 -2
- package/src/tools/modify.ts +9 -1
- package/src/tools/read/css.ts +46 -12
- package/src/tools/read/nodes.ts +26 -4
- package/src/tools/registry/extended.ts +6 -0
- package/src/tools/text-range.ts +29 -0
- package/src/tools/variables/bindings.ts +4 -1
- package/src/tools/variables/unbind.ts +4 -1
- package/src/tools/vector/path.ts +11 -13
- package/src/vector/rebase.ts +33 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-commands.js","names":[],"sources":["../../src/rpc/read-commands.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\n\nimport type { BooleanOperation, MaskType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { shapeDetailFields } from '#core/figma-api/shape-details'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport type { FontReadiness } from '#core/text/font/readiness'\nimport { resolveFontReadiness } from '#core/text/prepare'\nimport { queryByXPath } from '#core/xpath'\n\nimport type { RPCCommand } from './types'\n\n/** Walk descendants. Callback returns `false` to stop traversal. */\nfunction walkNodes(graph: SceneGraph, rootId: string, fn: (node: SceneNode) => boolean): boolean {\n const node = graph.getNode(rootId)\n if (!node) return true\n if (!fn(node)) return false\n for (const childId of node.childIds) {\n if (!walkNodes(graph, childId, fn)) return false\n }\n return true\n}\n\n/** A page picked by its ID, `page_id`, or by its name, `page`; the ID wins when both are given. */\nexport interface PageArgs {\n page?: string\n page_id?: string\n}\n\n/** The pages `args` picks: the one it names, none when it names a missing page, else `fallback`. */\nfunction pickedPages(graph: SceneGraph, args: PageArgs, fallback: SceneNode[]): SceneNode[] {\n const pages = graph.getPages()\n if (args.page_id) return pages.filter((page) => page.id === args.page_id)\n if (args.page) return pages.filter((page) => page.name === args.page).slice(0, 1)\n return fallback\n}\n\nfunction missingPageError(graph: SceneGraph, args: PageArgs): string {\n const pages = graph.getPages()\n const [label, available] = args.page_id\n ? [args.page_id, pages.map((page) => page.id)]\n : [args.page ?? '', pages.map((page) => page.name)]\n return `Page \"${label}\" not found. Available: ${available.join(', ')}`\n}\n\nfunction countDescendants(graph: SceneGraph, rootId: string): number {\n let count = 0\n walkNodes(graph, rootId, () => {\n count++\n return true\n })\n return count\n}\n\nfunction countNodes(graph: SceneGraph, pageId: string): number {\n const page = graph.getNode(pageId)\n return page ? sumBy(page.childIds, (id) => countDescendants(graph, id)) : 0\n}\n\nfunction nodeFrame(node: SceneNode) {\n return {\n x: Math.round(node.x),\n y: Math.round(node.y),\n width: Math.round(node.width),\n height: Math.round(node.height)\n }\n}\n\n// ── info ──\n\nexport interface InfoResult {\n pages: number\n totalNodes: number\n types: Record<string, number>\n fonts: string[]\n pageCounts: Record<string, number>\n}\n\nexport const infoCommand: RPCCommand<void, InfoResult> = {\n name: 'info',\n execute: (graph) => {\n const pages = graph.getPages()\n let totalNodes = 0\n const types: Record<string, number> = {}\n const fonts = new Set<string>()\n const pageCounts: Record<string, number> = {}\n\n const countNode = (node: SceneNode) => {\n totalNodes++\n types[node.type] = (types[node.type] ?? 0) + 1\n if (node.fontFamily) fonts.add(node.fontFamily)\n return true\n }\n\n for (const page of pages) {\n const beforePage = totalNodes\n for (const cid of page.childIds) {\n walkNodes(graph, cid, countNode)\n }\n pageCounts[page.name] = totalNodes - beforePage\n }\n\n return { pages: pages.length, totalNodes, types, fonts: [...fonts].sort(), pageCounts }\n }\n}\n\nexport const fontStatusCommand: RPCCommand<void, FontReadiness> = {\n name: 'font-status',\n execute: async (graph) => {\n const pageIds = graph.getPages().map((page) => page.id)\n return resolveFontReadiness(graph, pageIds.length > 0 ? pageIds : [graph.rootId])\n }\n}\n\n// ── pages ──\n\nexport interface PageItem {\n id: string\n name: string\n nodes: number\n}\n\nexport const pagesCommand: RPCCommand<void, PageItem[]> = {\n name: 'pages',\n execute: (graph) => {\n return graph.getPages().map((p) => ({ id: p.id, name: p.name, nodes: countNodes(graph, p.id) }))\n }\n}\n\n// ── tree ──\n\nexport interface TreeArgs extends PageArgs {\n depth?: number\n}\n\nexport interface TreeNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n children?: TreeNodeResult[]\n}\n\nfunction buildTreeNode(\n graph: SceneGraph,\n id: string,\n depth: number,\n maxDepth: number\n): TreeNodeResult | null {\n const node = graph.getNode(id)\n if (!node) return null\n const result: TreeNodeResult = {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node)\n }\n if (node.childIds.length > 0 && depth < maxDepth) {\n result.children = node.childIds\n .map((cid) => buildTreeNode(graph, cid, depth + 1, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n return result\n}\n\nexport interface TreeResult {\n page: { id: string; name: string; type: string }\n children: TreeNodeResult[]\n}\n\nexport const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> = {\n name: 'tree',\n execute: (graph, args) => {\n const maxDepth = args.depth ?? Infinity\n const page = pickedPages(graph, args, graph.getPages().slice(0, 1)).at(0)\n if (!page) return { error: missingPageError(graph, args) }\n\n return {\n page: { id: page.id, name: page.name, type: page.type },\n children: page.childIds\n .map((cid) => buildTreeNode(graph, cid, 0, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n }\n}\n\n// ── find ──\n\nexport interface FindArgs extends PageArgs {\n name?: string\n type?: string\n limit?: number\n}\n\nexport interface FindNodeResult {\n id: string\n name: string\n type: string\n width: number\n height: number\n}\n\nexport const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {\n name: 'find',\n execute: (graph, args) => {\n const max = args.limit ?? 100\n const namePattern = args.name?.toLowerCase()\n const typeFilter = args.type?.toUpperCase()\n const results: FindNodeResult[] = []\n\n const searchPage = (page: SceneNode) => {\n for (const cid of page.childIds) {\n const cont = walkNodes(graph, cid, (node) => {\n if (results.length >= max) return false\n const matchesName = !namePattern || node.name.toLowerCase().includes(namePattern)\n const matchesType = !typeFilter || node.type === typeFilter\n if (matchesName && matchesType) {\n results.push({\n id: node.id,\n name: node.name,\n type: node.type,\n width: Math.round(node.width),\n height: Math.round(node.height)\n })\n }\n return true\n })\n if (!cont) break\n }\n }\n\n for (const page of pickedPages(graph, args, graph.getPages())) searchPage(page)\n\n return results\n }\n}\n\n// ── query (xpath) ──\n\nexport interface QueryArgs extends PageArgs {\n selector: string\n limit?: number\n}\n\nexport interface QueryNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const queryCommand: RPCCommand<QueryArgs, QueryNodeResult[] | { error: string }> = {\n name: 'query',\n execute: async (graph, args) => {\n try {\n const nodes = await queryByXPath(graph, args.selector, {\n page: args.page,\n pageId: args.page_id,\n limit: args.limit\n })\n return nodes.map((n) => ({\n id: n.id,\n name: n.name,\n type: n.type,\n x: Math.round(n.x),\n y: Math.round(n.y),\n width: Math.round(n.width),\n height: Math.round(n.height)\n }))\n } catch (err) {\n return { error: `XPath error: ${err instanceof Error ? err.message : String(err)}` }\n }\n }\n}\n\n// ── node ──\n\nexport interface NodeArgs {\n id: string\n}\n\nexport interface NodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n visible: boolean\n locked: boolean\n opacity: number\n rotation: number\n fills: unknown[]\n strokes: unknown[]\n effects: unknown[]\n cornerRadius?: number\n topLeftRadius?: number\n topRightRadius?: number\n bottomRightRadius?: number\n bottomLeftRadius?: number\n isMask?: boolean\n maskType?: MaskType\n booleanOperation?: BooleanOperation\n blendMode: string\n layoutMode: string\n layoutDirection: string\n fontFamily: string\n fontSize: number\n fontWeight: number\n textDirection: string\n text: string | null\n parent: { id: string; name: string; type: string } | null\n children: number\n boundVariables: Record<string, string>\n}\n\nexport const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> = {\n name: 'node',\n execute: (graph, args) => {\n const node = graph.getNode(args.id)\n if (!node) return { error: `Node \"${args.id}\" not found` }\n\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const boundVars: Record<string, string> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n boundVars[field] = variable?.name ?? varId\n }\n return {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node),\n visible: node.visible,\n locked: node.locked,\n opacity: node.opacity,\n rotation: node.rotation,\n fills: node.fills,\n strokes: node.strokes,\n effects: node.effects,\n ...shapeDetailFields(node),\n blendMode: node.blendMode,\n layoutMode: node.layoutMode,\n layoutDirection: node.layoutDirection,\n fontFamily: node.fontFamily,\n fontSize: node.fontSize,\n fontWeight: node.fontWeight,\n textDirection: node.textDirection,\n text: (() => {\n if (!node.text.length) return null\n if (node.text.length > 200) return node.text.slice(0, 200) + ELLIPSIS\n return node.text\n })(),\n parent: parent ? { id: parent.id, name: parent.name, type: parent.type } : null,\n children: node.childIds.length,\n boundVariables: boundVars\n }\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAS,UAAU,OAAmB,QAAgB,IAA2C;CAC/F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO;CACtB,KAAK,MAAM,WAAW,KAAK,UACzB,IAAI,CAAC,UAAU,OAAO,SAAS,EAAE,GAAG,OAAO;CAE7C,OAAO;AACT;;AASA,SAAS,YAAY,OAAmB,MAAgB,UAAoC;CAC1F,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,KAAK,SAAS,OAAO,MAAM,QAAQ,SAAS,KAAK,OAAO,KAAK,OAAO;CACxE,IAAI,KAAK,MAAM,OAAO,MAAM,QAAQ,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;CAChF,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAmB,MAAwB;CACnE,MAAM,QAAQ,MAAM,SAAS;CAC7B,MAAM,CAAC,OAAO,aAAa,KAAK,UAC5B,CAAC,KAAK,SAAS,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC,IAC3C,CAAC,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CACpD,OAAO,SAAS,MAAM,0BAA0B,UAAU,KAAK,IAAI;AACrE;AAEA,SAAS,iBAAiB,OAAmB,QAAwB;CACnE,IAAI,QAAQ;CACZ,UAAU,OAAO,cAAc;EAC7B;EACA,OAAO;CACT,CAAC;CACD,OAAO;AACT;AAEA,SAAS,WAAW,OAAmB,Q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,MAAM,YAAoC,CAAC;EAC3C,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,cAAc,GAE7D,UAAU,SADO,MAAM,UAAU,IAAI,KACX,CAAC,EAAE,QAAQ;EAEvC,OAAO;GACL,IAAI,KAAK;GACT,MAAM,KAAK;GACX,MAAM,KAAK;GACX,GAAG,UAAU,IAAI;GACjB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;GACf,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,SAAS,KAAK;GACd,GAAG,kBAAkB,IAAI;GACzB,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,iBAAiB,KAAK;GACtB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,aAAa;IACX,IAAI,CAAC,KAAK,KAAK,QAAQ,OAAO;IAC9B,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM,GAAG,GAAG,IAAA;IACzD,OAAO,KAAK;GACd,EAAA,CAAG;GACH,QAAQ,SAAS;IAAE,IAAI,OAAO;IAAI,MAAM,OAAO;IAAM,MAAM,OAAO;GAAK,IAAI;GAC3E,UAAU,KAAK,SAAS;GACxB,gBAAgB;EAClB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"read-commands.js","names":[],"sources":["../../src/rpc/read-commands.ts"],"sourcesContent":["import { sumBy } from 'es-toolkit'\n\nimport type { BooleanOperation, MaskType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { shapeDetailFields } from '#core/figma-api/shape-details'\nimport {\n readerDiagnosticComponents,\n readerDiagnosticCounts,\n type ReaderDiagnosticComponent,\n type ReaderDiagnosticCount\n} from '#core/kiwi/fig/session/document-state'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport type { FontReadiness } from '#core/text/font/readiness'\nimport { resolveFontReadiness } from '#core/text/prepare'\nimport { queryByXPath } from '#core/xpath'\n\nimport type { RPCCommand } from './types'\n\n/** Walk descendants. Callback returns `false` to stop traversal. */\nfunction walkNodes(graph: SceneGraph, rootId: string, fn: (node: SceneNode) => boolean): boolean {\n const node = graph.getNode(rootId)\n if (!node) return true\n if (!fn(node)) return false\n for (const childId of node.childIds) {\n if (!walkNodes(graph, childId, fn)) return false\n }\n return true\n}\n\n/** A page picked by its ID, `page_id`, or by its name, `page`; the ID wins when both are given. */\nexport interface PageArgs {\n page?: string\n page_id?: string\n}\n\n/** The pages `args` picks: the one it names, none when it names a missing page, else `fallback`. */\nfunction pickedPages(graph: SceneGraph, args: PageArgs, fallback: SceneNode[]): SceneNode[] {\n const pages = graph.getPages()\n if (args.page_id) return pages.filter((page) => page.id === args.page_id)\n if (args.page) return pages.filter((page) => page.name === args.page).slice(0, 1)\n return fallback\n}\n\nfunction missingPageError(graph: SceneGraph, args: PageArgs): string {\n const pages = graph.getPages()\n const [label, available] = args.page_id\n ? [args.page_id, pages.map((page) => page.id)]\n : [args.page ?? '', pages.map((page) => page.name)]\n return `Page \"${label}\" not found. Available: ${available.join(', ')}`\n}\n\nfunction countDescendants(graph: SceneGraph, rootId: string): number {\n let count = 0\n walkNodes(graph, rootId, () => {\n count++\n return true\n })\n return count\n}\n\nfunction countNodes(graph: SceneGraph, pageId: string): number {\n const page = graph.getNode(pageId)\n return page ? sumBy(page.childIds, (id) => countDescendants(graph, id)) : 0\n}\n\nfunction nodeFrame(node: SceneNode) {\n return {\n x: Math.round(node.x),\n y: Math.round(node.y),\n width: Math.round(node.width),\n height: Math.round(node.height)\n }\n}\n\n// ── info ──\n\nexport interface InfoResult {\n pages: number\n totalNodes: number\n types: Record<string, number>\n fonts: string[]\n pageCounts: Record<string, number>\n /** What the reader skipped, counted by kind; empty for a graph not read as a Figma file. */\n diagnostics: ReaderDiagnosticCount[]\n /** The same records under the components they belong to, largest first. */\n diagnosticComponents: readonly ReaderDiagnosticComponent[]\n}\n\nexport const infoCommand: RPCCommand<void, InfoResult> = {\n name: 'info',\n execute: (graph) => {\n const pages = graph.getPages()\n let totalNodes = 0\n const types: Record<string, number> = {}\n const fonts = new Set<string>()\n const pageCounts: Record<string, number> = {}\n\n const countNode = (node: SceneNode) => {\n totalNodes++\n types[node.type] = (types[node.type] ?? 0) + 1\n if (node.fontFamily) fonts.add(node.fontFamily)\n return true\n }\n\n for (const page of pages) {\n const beforePage = totalNodes\n for (const cid of page.childIds) {\n walkNodes(graph, cid, countNode)\n }\n pageCounts[page.name] = totalNodes - beforePage\n }\n\n return {\n pages: pages.length,\n totalNodes,\n types,\n fonts: [...fonts].sort(),\n pageCounts,\n diagnostics: readerDiagnosticCounts(graph),\n diagnosticComponents: readerDiagnosticComponents(graph)\n }\n }\n}\n\nexport const fontStatusCommand: RPCCommand<void, FontReadiness> = {\n name: 'font-status',\n execute: async (graph) => {\n const pageIds = graph.getPages().map((page) => page.id)\n return resolveFontReadiness(graph, pageIds.length > 0 ? pageIds : [graph.rootId])\n }\n}\n\n// ── pages ──\n\nexport interface PageItem {\n id: string\n name: string\n nodes: number\n}\n\nexport const pagesCommand: RPCCommand<void, PageItem[]> = {\n name: 'pages',\n execute: (graph) => {\n return graph.getPages().map((p) => ({ id: p.id, name: p.name, nodes: countNodes(graph, p.id) }))\n }\n}\n\n// ── tree ──\n\nexport interface TreeArgs extends PageArgs {\n depth?: number\n}\n\nexport interface TreeNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n children?: TreeNodeResult[]\n}\n\nfunction buildTreeNode(\n graph: SceneGraph,\n id: string,\n depth: number,\n maxDepth: number\n): TreeNodeResult | null {\n const node = graph.getNode(id)\n if (!node) return null\n const result: TreeNodeResult = {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node)\n }\n if (node.childIds.length > 0 && depth < maxDepth) {\n result.children = node.childIds\n .map((cid) => buildTreeNode(graph, cid, depth + 1, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n return result\n}\n\nexport interface TreeResult {\n page: { id: string; name: string; type: string }\n children: TreeNodeResult[]\n}\n\nexport const treeCommand: RPCCommand<TreeArgs, TreeResult | { error: string }> = {\n name: 'tree',\n execute: (graph, args) => {\n const maxDepth = args.depth ?? Infinity\n const page = pickedPages(graph, args, graph.getPages().slice(0, 1)).at(0)\n if (!page) return { error: missingPageError(graph, args) }\n\n return {\n page: { id: page.id, name: page.name, type: page.type },\n children: page.childIds\n .map((cid) => buildTreeNode(graph, cid, 0, maxDepth))\n .filter((n): n is TreeNodeResult => n !== null)\n }\n }\n}\n\n// ── find ──\n\nexport interface FindArgs extends PageArgs {\n name?: string\n type?: string\n limit?: number\n}\n\nexport interface FindNodeResult {\n id: string\n name: string\n type: string\n width: number\n height: number\n}\n\nexport const findCommand: RPCCommand<FindArgs, FindNodeResult[]> = {\n name: 'find',\n execute: (graph, args) => {\n const max = args.limit ?? 100\n const namePattern = args.name?.toLowerCase()\n const typeFilter = args.type?.toUpperCase()\n const results: FindNodeResult[] = []\n\n const searchPage = (page: SceneNode) => {\n for (const cid of page.childIds) {\n const cont = walkNodes(graph, cid, (node) => {\n if (results.length >= max) return false\n const matchesName = !namePattern || node.name.toLowerCase().includes(namePattern)\n const matchesType = !typeFilter || node.type === typeFilter\n if (matchesName && matchesType) {\n results.push({\n id: node.id,\n name: node.name,\n type: node.type,\n width: Math.round(node.width),\n height: Math.round(node.height)\n })\n }\n return true\n })\n if (!cont) break\n }\n }\n\n for (const page of pickedPages(graph, args, graph.getPages())) searchPage(page)\n\n return results\n }\n}\n\n// ── query (xpath) ──\n\nexport interface QueryArgs extends PageArgs {\n selector: string\n limit?: number\n}\n\nexport interface QueryNodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n}\n\nexport const queryCommand: RPCCommand<QueryArgs, QueryNodeResult[] | { error: string }> = {\n name: 'query',\n execute: async (graph, args) => {\n try {\n const nodes = await queryByXPath(graph, args.selector, {\n page: args.page,\n pageId: args.page_id,\n limit: args.limit\n })\n return nodes.map((n) => ({\n id: n.id,\n name: n.name,\n type: n.type,\n x: Math.round(n.x),\n y: Math.round(n.y),\n width: Math.round(n.width),\n height: Math.round(n.height)\n }))\n } catch (err) {\n return { error: `XPath error: ${err instanceof Error ? err.message : String(err)}` }\n }\n }\n}\n\n// ── node ──\n\nexport interface NodeArgs {\n id: string\n}\n\nexport interface NodeResult {\n id: string\n name: string\n type: string\n x: number\n y: number\n width: number\n height: number\n visible: boolean\n locked: boolean\n opacity: number\n rotation: number\n fills: unknown[]\n strokes: unknown[]\n effects: unknown[]\n cornerRadius?: number\n topLeftRadius?: number\n topRightRadius?: number\n bottomRightRadius?: number\n bottomLeftRadius?: number\n isMask?: boolean\n maskType?: MaskType\n booleanOperation?: BooleanOperation\n blendMode: string\n layoutMode: string\n layoutDirection: string\n fontFamily: string\n fontSize: number\n fontWeight: number\n textDirection: string\n text: string | null\n parent: { id: string; name: string; type: string } | null\n children: number\n boundVariables: Record<string, string>\n}\n\nexport const nodeCommand: RPCCommand<NodeArgs, NodeResult | { error: string }> = {\n name: 'node',\n execute: (graph, args) => {\n const node = graph.getNode(args.id)\n if (!node) return { error: `Node \"${args.id}\" not found` }\n\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const boundVars: Record<string, string> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n boundVars[field] = variable?.name ?? varId\n }\n return {\n id: node.id,\n name: node.name,\n type: node.type,\n ...nodeFrame(node),\n visible: node.visible,\n locked: node.locked,\n opacity: node.opacity,\n rotation: node.rotation,\n fills: node.fills,\n strokes: node.strokes,\n effects: node.effects,\n ...shapeDetailFields(node),\n blendMode: node.blendMode,\n layoutMode: node.layoutMode,\n layoutDirection: node.layoutDirection,\n fontFamily: node.fontFamily,\n fontSize: node.fontSize,\n fontWeight: node.fontWeight,\n textDirection: node.textDirection,\n text: (() => {\n if (!node.text.length) return null\n if (node.text.length > 200) return node.text.slice(0, 200) + ELLIPSIS\n return node.text\n })(),\n parent: parent ? { id: parent.id, name: parent.name, type: parent.type } : null,\n children: node.childIds.length,\n boundVariables: boundVars\n }\n }\n}\n"],"mappings":";;;;;;;;AAmBA,SAAS,UAAU,OAAmB,QAAgB,IAA2C;CAC/F,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO;CACtB,KAAK,MAAM,WAAW,KAAK,UACzB,IAAI,CAAC,UAAU,OAAO,SAAS,EAAE,GAAG,OAAO;CAE7C,OAAO;AACT;;AASA,SAAS,YAAY,OAAmB,MAAgB,UAAoC;CAC1F,MAAM,QAAQ,MAAM,SAAS;CAC7B,IAAI,KAAK,SAAS,OAAO,MAAM,QAAQ,SAAS,KAAK,OAAO,KAAK,OAAO;CACxE,IAAI,KAAK,MAAM,OAAO,MAAM,QAAQ,SAAS,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC;CAChF,OAAO;AACT;AAEA,SAAS,iBAAiB,OAAmB,MAAwB;CACnE,MAAM,QAAQ,MAAM,SAAS;CAC7B,MAAM,CAAC,OAAO,aAAa,KAAK,UAC5B,CAAC,KAAK,SAAS,MAAM,KAAK,SAAS,KAAK,EAAE,CAAC,IAC3C,CAAC,KAAK,QAAQ,IAAI,MAAM,KAAK,SAAS,KAAK,IAAI,CAAC;CACpD,OAAO,SAAS,MAAM,0BAA0B,UAAU,KAAK,IAAI;AACrE;AAEA,SAAS,iBAAiB,OAAmB,QAAwB;CACnE,IAAI,QAAQ;CACZ,UAAU,OAAO,cAAc;EAC7B;EACA,OAAO;CACT,CAAC;CACD,OAAO;AACT;AAEA,SAAS,WAAW,OAAmB,QAAwB;CAC7D,MAAM,OAAO,MAAM,QAAQ,MAAM;CACjC,OAAO,OAAO,MAAM,KAAK,WAAW,OAAO,iBAAiB,OAAO,EAAE,CAAC,IAAI;AAC5E;AAEA,SAAS,UAAU,MAAiB;CAClC,OAAO;EACL,GAAG,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AC,EAAE,QAAQ;EAEvC,OAAO;GACL,IAAI,KAAK;GACT,MAAM,KAAK;GACX,MAAM,KAAK;GACX,GAAG,UAAU,IAAI;GACjB,SAAS,KAAK;GACd,QAAQ,KAAK;GACb,SAAS,KAAK;GACd,UAAU,KAAK;GACf,OAAO,KAAK;GACZ,SAAS,KAAK;GACd,SAAS,KAAK;GACd,GAAG,kBAAkB,IAAI;GACzB,WAAW,KAAK;GAChB,YAAY,KAAK;GACjB,iBAAiB,KAAK;GACtB,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,YAAY,KAAK;GACjB,eAAe,KAAK;GACpB,aAAa;IACX,IAAI,CAAC,KAAK,KAAK,QAAQ,OAAO;IAC9B,IAAI,KAAK,KAAK,SAAS,KAAK,OAAO,KAAK,KAAK,MAAM,GAAG,GAAG,IAAA;IACzD,OAAO,KAAK;GACd,EAAA,CAAG;GACH,QAAQ,SAAS;IAAE,IAAI,OAAO;IAAI,MAAM,OAAO;IAAM,MAAM,OAAO;GAAK,IAAI;GAC3E,UAAU,KAAK,SAAS;GACxB,gBAAgB;EAClB;CACF;AACF"}
|
|
@@ -35,11 +35,18 @@ declare function textStyleChanges(node: SceneNode, changes: Partial<Pick<SceneNo
|
|
|
35
35
|
* every character, as Figma's node setters do, so no range keeps its own value of it.
|
|
36
36
|
*/
|
|
37
37
|
declare function layerTextStyleChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode>;
|
|
38
|
+
/**
|
|
39
|
+
* Text styles whose characters do not all have the same effective value, which the panel shows as
|
|
40
|
+
* Mixed: a run's own value where it sets one, the layer's elsewhere. A style every character shares
|
|
41
|
+
* is not mixed even when only the runs set it. `start`/`end` narrow it to a range, as the
|
|
42
|
+
* characters selected while editing.
|
|
43
|
+
*/
|
|
44
|
+
declare function mixedTextStyleKeys(node: SceneNode, start?: number, end?: number): TextStyleKey[];
|
|
38
45
|
/**
|
|
39
46
|
* The style a text layer shows as its own: its first character's, which a range may set; the
|
|
40
47
|
* panel shows it, as it shows the first selected character's while text is edited.
|
|
41
48
|
*/
|
|
42
49
|
declare function shownTextStyle(node: SceneNode): Partial<SceneNode> | null;
|
|
43
50
|
//#endregion
|
|
44
|
-
export { CHARACTER_STYLE_KEYS, CharacterStyle, TEXT_STYLE_KEYS, TextStyleKey, TextStylePatch, characterStyles, layerTextStyleChanges, nodeStyle, shownTextStyle, styleRunsWithPatch, textStyleChanges };
|
|
51
|
+
export { CHARACTER_STYLE_KEYS, CharacterStyle, TEXT_STYLE_KEYS, TextStyleKey, TextStylePatch, characterStyles, layerTextStyleChanges, mixedTextStyleKeys, nodeStyle, shownTextStyle, styleRunsWithPatch, textStyleChanges };
|
|
45
52
|
//# sourceMappingURL=character-style.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-style.d.ts","names":[],"sources":["../../src/text/character-style.ts"],"mappings":";;;KAqBY,iBAAiB,SAC3B,KACE;EAiBF;EACA,YAAY;EACZ;EACA;EACA,WAAW;EACX;EACA;EACA,gBAAgB;;KAGN,uBAAuB;cAEtB;;cA4BA;iBAKG,UAAU,MAAM,YAAY;;iBA4B5B,gBAAgB,MAAM,WAAW,eAAe,cAAc;;;;;KAuDlE,iBAAiB,2BAA2B,qBAAqB;;iBAwB7D,mBACd,MAAM,WACN,eACA,aACA,OAAO,iBACN;;;;;iBAwCa,iBACd,MAAM,WACN,SAAS,QAAQ,KAAK,WAAW,gDACjC,SAAS,qBAAqB,yBAC7B,QAAQ;;;;;iBA6BK,sBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;;;;;
|
|
1
|
+
{"version":3,"file":"character-style.d.ts","names":[],"sources":["../../src/text/character-style.ts"],"mappings":";;;KAqBY,iBAAiB,SAC3B,KACE;EAiBF;EACA,YAAY;EACZ;EACA;EACA,WAAW;EACX;EACA;EACA,gBAAgB;;KAGN,uBAAuB;cAEtB;;cA4BA;iBAKG,UAAU,MAAM,YAAY;;iBA4B5B,gBAAgB,MAAM,WAAW,eAAe,cAAc;;;;;KAuDlE,iBAAiB,2BAA2B,qBAAqB;;iBAwB7D,mBACd,MAAM,WACN,eACA,aACA,OAAO,iBACN;;;;;iBAwCa,iBACd,MAAM,WACN,SAAS,QAAQ,KAAK,WAAW,gDACjC,SAAS,qBAAqB,yBAC7B,QAAQ;;;;;iBA6BK,sBACd,MAAM,WACN,SAAS,QAAQ,aAChB,QAAQ;;;;;;;iBAYK,mBACd,MAAM,WACN,gBACA,eACC;;;;;iBAyCa,eAAe,MAAM,YAAY,QAAQ"}
|
|
@@ -205,6 +205,44 @@ function layerTextStyleChanges(node, changes) {
|
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
+
* Text styles whose characters do not all have the same effective value, which the panel shows as
|
|
209
|
+
* Mixed: a run's own value where it sets one, the layer's elsewhere. A style every character shares
|
|
210
|
+
* is not mixed even when only the runs set it. `start`/`end` narrow it to a range, as the
|
|
211
|
+
* characters selected while editing.
|
|
212
|
+
*/
|
|
213
|
+
function mixedTextStyleKeys(node, start = 0, end = node.text.length) {
|
|
214
|
+
if (node.type !== "TEXT" || node.styleRuns.length === 0 || end <= start) return [];
|
|
215
|
+
const base = nodeStyle(node);
|
|
216
|
+
const runs = node.styleRuns.map((run) => ({
|
|
217
|
+
from: Math.max(start, run.start),
|
|
218
|
+
to: Math.min(end, run.start + run.length),
|
|
219
|
+
style: run.style
|
|
220
|
+
})).filter((run) => run.to > run.from);
|
|
221
|
+
const mixed = /* @__PURE__ */ new Set();
|
|
222
|
+
for (const key of TEXT_STYLE_KEYS) {
|
|
223
|
+
let first;
|
|
224
|
+
let seen = false;
|
|
225
|
+
const outcome = { differs: false };
|
|
226
|
+
const consider = (value) => {
|
|
227
|
+
if (!seen) {
|
|
228
|
+
first = value;
|
|
229
|
+
seen = true;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (!isEqual(value, first)) outcome.differs = true;
|
|
233
|
+
};
|
|
234
|
+
let cursor = start;
|
|
235
|
+
for (const run of runs) {
|
|
236
|
+
if (run.from > cursor) consider(base[key]);
|
|
237
|
+
consider(run.style[key] ?? base[key]);
|
|
238
|
+
cursor = Math.max(cursor, run.to);
|
|
239
|
+
}
|
|
240
|
+
if (cursor < end) consider(base[key]);
|
|
241
|
+
if (outcome.differs) mixed.add(key);
|
|
242
|
+
}
|
|
243
|
+
return TEXT_STYLE_KEYS.filter((key) => mixed.has(key));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
208
246
|
* The style a text layer shows as its own: its first character's, which a range may set; the
|
|
209
247
|
* panel shows it, as it shows the first selected character's while text is edited.
|
|
210
248
|
*/
|
|
@@ -214,6 +252,6 @@ function shownTextStyle(node) {
|
|
|
214
252
|
return pick(style, TEXT_STYLE_KEYS);
|
|
215
253
|
}
|
|
216
254
|
//#endregion
|
|
217
|
-
export { CHARACTER_STYLE_KEYS, TEXT_STYLE_KEYS, characterStyles, layerTextStyleChanges, nodeStyle, shownTextStyle, styleRunsWithPatch, textStyleChanges };
|
|
255
|
+
export { CHARACTER_STYLE_KEYS, TEXT_STYLE_KEYS, characterStyles, layerTextStyleChanges, mixedTextStyleKeys, nodeStyle, shownTextStyle, styleRunsWithPatch, textStyleChanges };
|
|
218
256
|
|
|
219
257
|
//# sourceMappingURL=character-style.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"character-style.js","names":[],"sources":["../../src/text/character-style.ts"],"sourcesContent":["import { omit, omitBy, pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual, isUndefined } from 'es-toolkit/predicate'\n\nimport {\n TEXT_BINDABLE_FIELDS,\n type CharacterStyleOverride,\n type HyperlinkTarget,\n type SceneNode,\n type StyleRun,\n type TextBoundVariables,\n type TextLength\n} from '@pairdraw/scene-graph'\nimport {\n FACE_KEYS,\n rangeFontStyle,\n SHARED_TEXT_STYLE_FIELDS,\n styleDetachmentChanges\n} from '@pairdraw/scene-graph/shared-styles'\nimport { withBoundBindingScales } from '@pairdraw/scene-graph/variables'\n\n/** A character's style: the text's own, with its run's overrides over it. */\nexport type CharacterStyle = Required<\n Pick<\n CharacterStyleOverride,\n | 'fontFamily'\n | 'fontWeight'\n | 'italic'\n | 'fontSize'\n | 'letterSpacing'\n | 'fills'\n | 'textDecoration'\n | 'textDecorationStyle'\n | 'textDecorationFills'\n | 'textDecorationSkipInk'\n | 'fontFeatures'\n | 'fontVariations'\n | 'opticalSizeFromFontSize'\n | 'textCase'\n >\n> & {\n fontStyle: string | null\n lineHeight: TextLength | null\n textDecorationThickness: number | null\n textUnderlineOffset: number | null\n hyperlink: HyperlinkTarget | null\n textStyleId: string | null\n fillStyleId: string | null\n boundVariables: TextBoundVariables\n}\n\nexport type TextStyleKey = (typeof TEXT_STYLE_KEYS)[number]\n\nexport const TEXT_STYLE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'letterSpacing',\n 'lineHeight',\n 'fills',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'fontFeatures',\n 'fontVariations',\n 'opticalSizeFromFontSize',\n 'textCase'\n] as const satisfies readonly (keyof CharacterStyle)[]\n\n/**\n * What a range of characters can hold that is not a style of the text's own: a link, the\n * styles it uses, and its bindings. The text's styles and bindings are what ranges start from.\n */\nconst RANGE_STYLE_KEYS = ['hyperlink', 'textStyleId', 'fillStyleId', 'boundVariables'] as const\n\n/** Every field a character's style has, as runs override it. */\nexport const CHARACTER_STYLE_KEYS = [\n ...TEXT_STYLE_KEYS,\n ...RANGE_STYLE_KEYS\n] as const satisfies readonly (keyof CharacterStyle)[]\n\nexport function nodeStyle(node: SceneNode): CharacterStyle {\n return {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontStyle: node.fontStyle,\n fontSize: node.fontSize,\n letterSpacing: node.letterSpacing,\n lineHeight: node.lineHeight,\n fills: node.fills,\n textDecoration: node.textDecoration,\n textDecorationStyle: node.textDecorationStyle,\n textDecorationThickness: node.textDecorationThickness,\n textDecorationFills: node.textDecorationFills,\n textDecorationSkipInk: node.textDecorationSkipInk,\n textUnderlineOffset: node.textUnderlineOffset,\n fontFeatures: node.fontFeatures,\n fontVariations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize,\n textCase: node.textCase,\n hyperlink: null,\n textStyleId: node.textStyleId,\n fillStyleId: node.fillStyleId,\n boundVariables: pick(node.boundVariables, TEXT_BINDABLE_FIELDS)\n }\n}\n\n/** Every character's style, from the text's own and the runs over it. */\nexport function characterStyles(node: SceneNode, start: number, end: number): CharacterStyle[] {\n const base = nodeStyle(node)\n const styles = Array.from({ length: end - start }, () => base)\n for (const run of node.styleRuns) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.start + run.length)\n for (let index = from; index < to; index++) {\n styles[index - start] = {\n ...styles[index - start],\n ...definedOverrides(run.style),\n fontStyle: rangeFontStyle(node, run.style)\n }\n }\n }\n return styles\n}\n\nfunction definedOverrides(style: CharacterStyleOverride): Partial<CharacterStyle> {\n const defined: Partial<Record<keyof CharacterStyle, unknown>> = {}\n for (const key of CHARACTER_STYLE_KEYS) {\n if (style[key] !== undefined) defined[key] = style[key]\n }\n return defined as Partial<CharacterStyle>\n}\n\n/** Style runs with no override that only repeats the text's own value. */\nfunction withoutRedundantOverrides(node: SceneNode, runs: StyleRun[]): StyleRun[] {\n const base = nodeStyle(node)\n const result: StyleRun[] = []\n for (const run of runs) {\n // A range keeps a binding's scale only while it binds the number itself.\n const repeated = CHARACTER_STYLE_KEYS.filter(\n (key) => run.style[key] !== undefined && isEqual(run.style[key], base[key])\n )\n // A key a copy left undefined overrides nothing either.\n const style = withBoundBindingScales(omitBy(omit(run.style, repeated), isUndefined))\n if (Object.keys(style).length === 0) continue\n const previous = result.at(-1)\n if (\n previous &&\n previous.start + previous.length === run.start &&\n isEqual(previous.style, style)\n ) {\n previous.length += run.length\n } else {\n result.push({ start: run.start, length: run.length, style })\n }\n }\n return result\n}\n\n/**\n * A style for a range, or one per font size for a length given in percent of the font size,\n * which characters of each size resolve to their own length.\n */\nexport type TextStylePatch = CharacterStyleOverride | ((fontSize: number) => CharacterStyleOverride)\n\n/**\n * The styles characters leave when `style` changes what a style gave them, as a text leaves its\n * own: a font size leaves the text style, and fills leave the fill style.\n */\nfunction detachedStyles(\n node: SceneNode,\n current: CharacterStyleOverride,\n style: CharacterStyleOverride | undefined\n): CharacterStyleOverride {\n if (!style) return {}\n const styled = { ...node, ...current }\n const changes = pick(style, [...TEXT_STYLE_KEYS, 'fills', 'textStyleId', 'fillStyleId'])\n const detached = styleDetachmentChanges(styled, changes)\n return pick(\n detached,\n (['textStyleId', 'fillStyleId', 'fontStyle'] as const).filter(\n (key) => !Object.hasOwn(changes, key) && Object.hasOwn(detached, key)\n )\n )\n}\n\n/** Style runs with `patch` over `text[start, end)`, as Figma restyles a range. */\nexport function styleRunsWithPatch(\n node: SceneNode,\n start: number,\n end: number,\n patch: TextStylePatch\n): StyleRun[] {\n const length = node.text.length\n const chars: CharacterStyleOverride[] = Array.from({ length }, () => ({}))\n for (const run of node.styleRuns) {\n for (let index = run.start; index < run.start + run.length && index < length; index++) {\n chars[index] = { ...chars[index], ...run.style }\n }\n }\n const sized = typeof patch === 'function' ? patch : null\n const patches = new Map<number, CharacterStyleOverride>()\n for (let index = start; index < end; index++) {\n let style = sized ? undefined : (patch as CharacterStyleOverride)\n if (sized) {\n const fontSize = chars[index].fontSize ?? node.fontSize\n style = patches.get(fontSize) ?? sized(fontSize)\n patches.set(fontSize, style)\n }\n chars[index] = { ...chars[index], ...style, ...detachedStyles(node, chars[index], style) }\n }\n // A newline takes the style of the character before it, as in Figma: a range that ends a\n // paragraph styles its newline too, and a newline cannot be styled on its own.\n for (let index = 1; index < length; index++) {\n if (node.text[index] === '\\n') chars[index] = chars[index - 1]\n }\n const runs: StyleRun[] = []\n for (const [index, style] of chars.entries()) {\n const previous = runs.at(-1)\n if (previous && isEqual(previous.style, style)) previous.length++\n else runs.push({ start: index, length: 1, style })\n }\n return withoutRedundantOverrides(\n node,\n runs.filter((run) => Object.keys(run.style).length > 0)\n )\n}\n\n/**\n * The change that sets a style for the whole text, as Figma's node setters do: the text takes\n * the value and no range keeps one of its own.\n */\nexport function textStyleChanges(\n node: SceneNode,\n changes: Partial<Pick<SceneNode, TextStyleKey | 'textStyleId' | 'fillStyleId'>>,\n sized?: (fontSize: number) => CharacterStyleOverride\n): Partial<SceneNode> {\n const changed = Object.keys(changes) as (keyof CharacterStyleOverride)[]\n // A style a range keeps no longer gives it what the whole text now sets.\n const keys = [\n ...changed,\n ...(changed.some((key) => (SHARED_TEXT_STYLE_FIELDS as readonly string[]).includes(key))\n ? (['textStyleId'] as const)\n : []),\n ...(changed.includes('fills') ? (['fillStyleId'] as const) : []),\n // A range's face name names none once the text's face changes under it.\n ...(changed.some((key) => (FACE_KEYS as readonly string[]).includes(key))\n ? (['fontStyle'] as const)\n : [])\n ]\n const runs = node.styleRuns.map((run) => ({ ...run, style: omit(run.style, keys) }))\n const updated = { ...node, ...changes }\n const styleRuns = withoutRedundantOverrides(updated, runs)\n // A percent gives characters of another size their own length.\n if (!sized) return { ...changes, styleRuns }\n return {\n ...changes,\n styleRuns: styleRunsWithPatch({ ...updated, styleRuns }, 0, node.text.length, sized)\n }\n}\n\n/**\n * A change to a text layer as a whole, such as from the design panel: a style it sets applies to\n * every character, as Figma's node setters do, so no range keeps its own value of it.\n */\nexport function layerTextStyleChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const style = pick(changes, TEXT_STYLE_KEYS)\n if (node.type !== 'TEXT' || node.styleRuns.length === 0 || isEmptyObject(style)) return changes\n return { ...changes, ...textStyleChanges(node, style) }\n}\n\n/**\n * The style a text layer shows as its own: its first character's, which a range may set; the\n * panel shows it, as it shows the first selected character's while text is edited.\n */\nexport function shownTextStyle(node: SceneNode): Partial<SceneNode> | null {\n if (node.type !== 'TEXT' || node.styleRuns.length === 0 || node.text.length === 0) return null\n const [style] = characterStyles(node, 0, 1)\n return pick(style, TEXT_STYLE_KEYS)\n}\n"],"mappings":";;;;;;AAoDA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAMA,MAAM,mBAAmB;CAAC;CAAa;CAAe;CAAe;AAAgB;;AAGrF,MAAa,uBAAuB,CAClC,GAAG,iBACH,GAAG,gBACL;AAEA,SAAgB,UAAU,MAAiC;CACzD,OAAO;EACL,YAAY,KAAK;EACjB,YAAY,KAAK;EACjB,QAAQ,KAAK;EACb,WAAW,KAAK;EAChB,UAAU,KAAK;EACf,eAAe,KAAK;EACpB,YAAY,KAAK;EACjB,OAAO,KAAK;EACZ,gBAAgB,KAAK;EACrB,qBAAqB,KAAK;EAC1B,yBAAyB,KAAK;EAC9B,qBAAqB,KAAK;EAC1B,uBAAuB,KAAK;EAC5B,qBAAqB,KAAK;EAC1B,cAAc,KAAK;EACnB,gBAAgB,KAAK;EACrB,yBAAyB,KAAK;EAC9B,UAAU,KAAK;EACf,WAAW;EACX,aAAa,KAAK;EAClB,aAAa,KAAK;EAClB,gBAAgB,KAAK,KAAK,gBAAgB,oBAAoB;CAChE;AACF;;AAGA,SAAgB,gBAAgB,MAAiB,OAAe,KAA+B;CAC7F,MAAM,OAAO,UAAU,IAAI;CAC3B,MAAM,SAAS,MAAM,KAAK,EAAE,QAAQ,MAAM,MAAM,SAAS,IAAI;CAC7D,KAAK,MAAM,OAAO,KAAK,WAAW;EAChC,MAAM,OAAO,KAAK,IAAI,OAAO,IAAI,KAAK;EACtC,MAAM,KAAK,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,MAAM;EAC/C,KAAK,IAAI,QAAQ,MAAM,QAAQ,IAAI,SACjC,OAAO,QAAQ,SAAS;GACtB,GAAG,OAAO,QAAQ;GAClB,GAAG,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ACpB,MAAM,UAAU,OAAO,KAAK,OAAO;CAEnC,MAAM,OAAO;EACX,GAAG;EACH,GAAI,QAAQ,MAAM,QAAS,yBAA+C,SAAS,GAAG,CAAC,IAClF,CAAC,aAAa,IACf,CAAC;EACL,GAAI,QAAQ,SAAS,OAAO,IAAK,CAAC,aAAa,IAAc,CAAC;EAE9D,GAAI,QAAQ,MAAM,QAAS,UAAgC,SAAS,GAAG,CAAC,IACnE,CAAC,WAAW,IACb,CAAC;CACP;CACA,MAAM,OAAO,KAAK,UAAU,KAAK,SAAS;EAAE,GAAG;EAAK,OAAO,KAAK,IAAI,OAAO,IAAI;CAAE,EAAE;CACnF,MAAM,UAAU;EAAE,GAAG;EAAM,GAAG;CAAQ;CACtC,MAAM,YAAY,0BAA0B,SAAS,IAAI;CAEzD,IAAI,CAAC,OAAO,OAAO;EAAE,GAAG;EAAS;CAAU;CAC3C,OAAO;EACL,GAAG;EACH,WAAW,mBAAmB;GAAE,GAAG;GAAS;EAAU,GAAG,GAAG,KAAK,KAAK,QAAQ,KAAK;CACrF;AACF;;;;;AAMA,SAAgB,sBACd,MACA,SACoB;CACpB,MAAM,QAAQ,KAAK,SAAS,eAAe;CAC3C,IAAI,KAAK,SAAS,UAAU,KAAK,UAAU,WAAW,KAAK,cAAc,KAAK,GAAG,OAAO;CACxF,OAAO;EAAE,GAAG;EAAS,GAAG,iBAAiB,MAAM,KAAK;CAAE;AACxD;;;;;AAMA,SAAgB,eAAe,MAA4C;CACzE,IAAI,KAAK,SAAS,UAAU,KAAK,UAAU,WAAW,KAAK,KAAK,KAAK,WAAW,GAAG,OAAO;CAC1F,MAAM,CAAC,SAAS,gBAAgB,MAAM,GAAG,CAAC;CAC1C,OAAO,KAAK,OAAO,eAAe;AACpC"}
|
|
1
|
+
{"version":3,"file":"character-style.js","names":[],"sources":["../../src/text/character-style.ts"],"sourcesContent":["import { omit, omitBy, pick } from 'es-toolkit/object'\nimport { isEmptyObject, isEqual, isUndefined } from 'es-toolkit/predicate'\n\nimport {\n TEXT_BINDABLE_FIELDS,\n type CharacterStyleOverride,\n type HyperlinkTarget,\n type SceneNode,\n type StyleRun,\n type TextBoundVariables,\n type TextLength\n} from '@pairdraw/scene-graph'\nimport {\n FACE_KEYS,\n rangeFontStyle,\n SHARED_TEXT_STYLE_FIELDS,\n styleDetachmentChanges\n} from '@pairdraw/scene-graph/shared-styles'\nimport { withBoundBindingScales } from '@pairdraw/scene-graph/variables'\n\n/** A character's style: the text's own, with its run's overrides over it. */\nexport type CharacterStyle = Required<\n Pick<\n CharacterStyleOverride,\n | 'fontFamily'\n | 'fontWeight'\n | 'italic'\n | 'fontSize'\n | 'letterSpacing'\n | 'fills'\n | 'textDecoration'\n | 'textDecorationStyle'\n | 'textDecorationFills'\n | 'textDecorationSkipInk'\n | 'fontFeatures'\n | 'fontVariations'\n | 'opticalSizeFromFontSize'\n | 'textCase'\n >\n> & {\n fontStyle: string | null\n lineHeight: TextLength | null\n textDecorationThickness: number | null\n textUnderlineOffset: number | null\n hyperlink: HyperlinkTarget | null\n textStyleId: string | null\n fillStyleId: string | null\n boundVariables: TextBoundVariables\n}\n\nexport type TextStyleKey = (typeof TEXT_STYLE_KEYS)[number]\n\nexport const TEXT_STYLE_KEYS = [\n 'fontFamily',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'fontSize',\n 'letterSpacing',\n 'lineHeight',\n 'fills',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'fontFeatures',\n 'fontVariations',\n 'opticalSizeFromFontSize',\n 'textCase'\n] as const satisfies readonly (keyof CharacterStyle)[]\n\n/**\n * What a range of characters can hold that is not a style of the text's own: a link, the\n * styles it uses, and its bindings. The text's styles and bindings are what ranges start from.\n */\nconst RANGE_STYLE_KEYS = ['hyperlink', 'textStyleId', 'fillStyleId', 'boundVariables'] as const\n\n/** Every field a character's style has, as runs override it. */\nexport const CHARACTER_STYLE_KEYS = [\n ...TEXT_STYLE_KEYS,\n ...RANGE_STYLE_KEYS\n] as const satisfies readonly (keyof CharacterStyle)[]\n\nexport function nodeStyle(node: SceneNode): CharacterStyle {\n return {\n fontFamily: node.fontFamily,\n fontWeight: node.fontWeight,\n italic: node.italic,\n fontStyle: node.fontStyle,\n fontSize: node.fontSize,\n letterSpacing: node.letterSpacing,\n lineHeight: node.lineHeight,\n fills: node.fills,\n textDecoration: node.textDecoration,\n textDecorationStyle: node.textDecorationStyle,\n textDecorationThickness: node.textDecorationThickness,\n textDecorationFills: node.textDecorationFills,\n textDecorationSkipInk: node.textDecorationSkipInk,\n textUnderlineOffset: node.textUnderlineOffset,\n fontFeatures: node.fontFeatures,\n fontVariations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize,\n textCase: node.textCase,\n hyperlink: null,\n textStyleId: node.textStyleId,\n fillStyleId: node.fillStyleId,\n boundVariables: pick(node.boundVariables, TEXT_BINDABLE_FIELDS)\n }\n}\n\n/** Every character's style, from the text's own and the runs over it. */\nexport function characterStyles(node: SceneNode, start: number, end: number): CharacterStyle[] {\n const base = nodeStyle(node)\n const styles = Array.from({ length: end - start }, () => base)\n for (const run of node.styleRuns) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.start + run.length)\n for (let index = from; index < to; index++) {\n styles[index - start] = {\n ...styles[index - start],\n ...definedOverrides(run.style),\n fontStyle: rangeFontStyle(node, run.style)\n }\n }\n }\n return styles\n}\n\nfunction definedOverrides(style: CharacterStyleOverride): Partial<CharacterStyle> {\n const defined: Partial<Record<keyof CharacterStyle, unknown>> = {}\n for (const key of CHARACTER_STYLE_KEYS) {\n if (style[key] !== undefined) defined[key] = style[key]\n }\n return defined as Partial<CharacterStyle>\n}\n\n/** Style runs with no override that only repeats the text's own value. */\nfunction withoutRedundantOverrides(node: SceneNode, runs: StyleRun[]): StyleRun[] {\n const base = nodeStyle(node)\n const result: StyleRun[] = []\n for (const run of runs) {\n // A range keeps a binding's scale only while it binds the number itself.\n const repeated = CHARACTER_STYLE_KEYS.filter(\n (key) => run.style[key] !== undefined && isEqual(run.style[key], base[key])\n )\n // A key a copy left undefined overrides nothing either.\n const style = withBoundBindingScales(omitBy(omit(run.style, repeated), isUndefined))\n if (Object.keys(style).length === 0) continue\n const previous = result.at(-1)\n if (\n previous &&\n previous.start + previous.length === run.start &&\n isEqual(previous.style, style)\n ) {\n previous.length += run.length\n } else {\n result.push({ start: run.start, length: run.length, style })\n }\n }\n return result\n}\n\n/**\n * A style for a range, or one per font size for a length given in percent of the font size,\n * which characters of each size resolve to their own length.\n */\nexport type TextStylePatch = CharacterStyleOverride | ((fontSize: number) => CharacterStyleOverride)\n\n/**\n * The styles characters leave when `style` changes what a style gave them, as a text leaves its\n * own: a font size leaves the text style, and fills leave the fill style.\n */\nfunction detachedStyles(\n node: SceneNode,\n current: CharacterStyleOverride,\n style: CharacterStyleOverride | undefined\n): CharacterStyleOverride {\n if (!style) return {}\n const styled = { ...node, ...current }\n const changes = pick(style, [...TEXT_STYLE_KEYS, 'fills', 'textStyleId', 'fillStyleId'])\n const detached = styleDetachmentChanges(styled, changes)\n return pick(\n detached,\n (['textStyleId', 'fillStyleId', 'fontStyle'] as const).filter(\n (key) => !Object.hasOwn(changes, key) && Object.hasOwn(detached, key)\n )\n )\n}\n\n/** Style runs with `patch` over `text[start, end)`, as Figma restyles a range. */\nexport function styleRunsWithPatch(\n node: SceneNode,\n start: number,\n end: number,\n patch: TextStylePatch\n): StyleRun[] {\n const length = node.text.length\n const chars: CharacterStyleOverride[] = Array.from({ length }, () => ({}))\n for (const run of node.styleRuns) {\n for (let index = run.start; index < run.start + run.length && index < length; index++) {\n chars[index] = { ...chars[index], ...run.style }\n }\n }\n const sized = typeof patch === 'function' ? patch : null\n const patches = new Map<number, CharacterStyleOverride>()\n for (let index = start; index < end; index++) {\n let style = sized ? undefined : (patch as CharacterStyleOverride)\n if (sized) {\n const fontSize = chars[index].fontSize ?? node.fontSize\n style = patches.get(fontSize) ?? sized(fontSize)\n patches.set(fontSize, style)\n }\n chars[index] = { ...chars[index], ...style, ...detachedStyles(node, chars[index], style) }\n }\n // A newline takes the style of the character before it, as in Figma: a range that ends a\n // paragraph styles its newline too, and a newline cannot be styled on its own.\n for (let index = 1; index < length; index++) {\n if (node.text[index] === '\\n') chars[index] = chars[index - 1]\n }\n const runs: StyleRun[] = []\n for (const [index, style] of chars.entries()) {\n const previous = runs.at(-1)\n if (previous && isEqual(previous.style, style)) previous.length++\n else runs.push({ start: index, length: 1, style })\n }\n return withoutRedundantOverrides(\n node,\n runs.filter((run) => Object.keys(run.style).length > 0)\n )\n}\n\n/**\n * The change that sets a style for the whole text, as Figma's node setters do: the text takes\n * the value and no range keeps one of its own.\n */\nexport function textStyleChanges(\n node: SceneNode,\n changes: Partial<Pick<SceneNode, TextStyleKey | 'textStyleId' | 'fillStyleId'>>,\n sized?: (fontSize: number) => CharacterStyleOverride\n): Partial<SceneNode> {\n const changed = Object.keys(changes) as (keyof CharacterStyleOverride)[]\n // A style a range keeps no longer gives it what the whole text now sets.\n const keys = [\n ...changed,\n ...(changed.some((key) => (SHARED_TEXT_STYLE_FIELDS as readonly string[]).includes(key))\n ? (['textStyleId'] as const)\n : []),\n ...(changed.includes('fills') ? (['fillStyleId'] as const) : []),\n // A range's face name names none once the text's face changes under it.\n ...(changed.some((key) => (FACE_KEYS as readonly string[]).includes(key))\n ? (['fontStyle'] as const)\n : [])\n ]\n const runs = node.styleRuns.map((run) => ({ ...run, style: omit(run.style, keys) }))\n const updated = { ...node, ...changes }\n const styleRuns = withoutRedundantOverrides(updated, runs)\n // A percent gives characters of another size their own length.\n if (!sized) return { ...changes, styleRuns }\n return {\n ...changes,\n styleRuns: styleRunsWithPatch({ ...updated, styleRuns }, 0, node.text.length, sized)\n }\n}\n\n/**\n * A change to a text layer as a whole, such as from the design panel: a style it sets applies to\n * every character, as Figma's node setters do, so no range keeps its own value of it.\n */\nexport function layerTextStyleChanges(\n node: SceneNode,\n changes: Partial<SceneNode>\n): Partial<SceneNode> {\n const style = pick(changes, TEXT_STYLE_KEYS)\n if (node.type !== 'TEXT' || node.styleRuns.length === 0 || isEmptyObject(style)) return changes\n return { ...changes, ...textStyleChanges(node, style) }\n}\n\n/**\n * Text styles whose characters do not all have the same effective value, which the panel shows as\n * Mixed: a run's own value where it sets one, the layer's elsewhere. A style every character shares\n * is not mixed even when only the runs set it. `start`/`end` narrow it to a range, as the\n * characters selected while editing.\n */\nexport function mixedTextStyleKeys(\n node: SceneNode,\n start = 0,\n end = node.text.length\n): TextStyleKey[] {\n if (node.type !== 'TEXT' || node.styleRuns.length === 0 || end <= start) return []\n const base = nodeStyle(node)\n const runs = node.styleRuns\n .map((run) => ({\n from: Math.max(start, run.start),\n to: Math.min(end, run.start + run.length),\n style: run.style\n }))\n .filter((run) => run.to > run.from)\n const mixed = new Set<TextStyleKey>()\n for (const key of TEXT_STYLE_KEYS) {\n let first: unknown\n let seen = false\n const outcome = { differs: false }\n const consider = (value: unknown) => {\n if (!seen) {\n first = value\n seen = true\n return\n }\n if (!isEqual(value, first)) outcome.differs = true\n }\n // The characters a run covers carry its value, or the layer's where the run leaves the key\n // alone; a gap between runs carries the layer's. Only two different values make it mixed.\n let cursor = start\n for (const run of runs) {\n if (run.from > cursor) consider(base[key])\n consider(run.style[key] ?? base[key])\n cursor = Math.max(cursor, run.to)\n }\n if (cursor < end) consider(base[key])\n if (outcome.differs) mixed.add(key)\n }\n return TEXT_STYLE_KEYS.filter((key) => mixed.has(key))\n}\n\n/**\n * The style a text layer shows as its own: its first character's, which a range may set; the\n * panel shows it, as it shows the first selected character's while text is edited.\n */\nexport function shownTextStyle(node: SceneNode): Partial<SceneNode> | null {\n if (node.type !== 'TEXT' || node.styleRuns.length === 0 || node.text.length === 0) return null\n const [style] = characterStyles(node, 0, 1)\n return pick(style, TEXT_STYLE_KEYS)\n}\n"],"mappings":";;;;;;AAoDA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CAC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;EACjC,MAAM,YAAY,UAAmB;GACnC,IAAI,CAAC,MAAM;IACT,QAAQ;IACR,OAAO;IACP;GACF;GACA,IAAI,CAAC,QAAQ,OAAO,KAAK,GAAG,QAAQ,UAAU;EAChD;EAGA,IAAI,SAAS;EACb,KAAK,MAAM,OAAO,MAAM;GACtB,IAAI,IAAI,OAAO,QAAQ,SAAS,KAAK,IAAI;GACzC,SAAS,IAAI,MAAM,QAAQ,KAAK,IAAI;GACpC,SAAS,KAAK,IAAI,QAAQ,IAAI,EAAE;EAClC;EACA,IAAI,SAAS,KAAK,SAAS,KAAK,IAAI;EACpC,IAAI,QAAQ,SAAS,MAAM,IAAI,GAAG;CACpC;CACA,OAAO,gBAAgB,QAAQ,QAAQ,MAAM,IAAI,GAAG,CAAC;AACvD;;;;;AAMA,SAAgB,eAAe,MAA4C;CACzE,IAAI,KAAK,SAAS,UAAU,KAAK,UAAU,WAAW,KAAK,KAAK,KAAK,WAAW,GAAG,OAAO;CAC1F,MAAM,CAAC,SAAS,gBAAgB,MAAM,GAAG,CAAC;CAC1C,OAAO,KAAK,OAAO,eAAe;AACpC"}
|
package/dist/text/index.d.ts
CHANGED
|
@@ -33,5 +33,5 @@ import { HyperlinkRunOptions, HyperlinkSpan, hyperlinkInRange, hyperlinkSpanAt,
|
|
|
33
33
|
import { resolveFontReadiness } from "./prepare.js";
|
|
34
34
|
import { TextFace, collectNamedNodeFontFaces, faceForStyle, faceStyleName, textFaceName, textStyleName } from "./font/names.js";
|
|
35
35
|
import { DocumentFont, FontFaceReference, FontReplacement, FontReplacementCounts, listDocumentFonts, replaceDocumentFonts } from "./replace-fonts.js";
|
|
36
|
-
import { layerTextStyleChanges, shownTextStyle } from "./character-style.js";
|
|
37
|
-
export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, BrowserFaceDescriptors, type BundledFontLocator, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, DocumentFont, DocumentFontEntry, DocumentFontInput, DownloadedFontCache, FaceWeight, FamilyFace, FontAxis, FontCandidateSource, FontFaceReadiness, FontFaceRef, FontFaceReference, FontFallbackManifestEntry, FontFallbackScript, FontFamilyOption, FontFamilySource, FontInfo, FontLoadedSource, FontManager, FontProviderLease, FontReadiness, FontReadinessStatus, FontReplacement, FontReplacementCounts, FontResolutionCandidate, FontResolutionDemand, FontResolutionEvent, FontResolutionListener, FontResolutionLoader, FontResolutionSettled, FontResolutionSnapshot, FontResolutionState, FontResolver, FontUnavailableReason, type GlyphOutlineProbe, GraphFontRequirements, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, type HarfBuzzSubsetLocator, type HostFontFamily, HostFontLoader, HyperlinkRunOptions, HyperlinkSpan, InsertStyleSource, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, LetterFallbackScript, LocalFontAccessState, MissingGlyphOccurrence, MissingGraphFontScriptsOptions, NamedInstance, NamedLocalFont, ObservedShapedLine, type OutlineCommand, PathPoint, PathTextCaret, PathTextLayout, PathTextLineMetrics, ResolvedWebFont, SampledPath, THAI_CHARACTER, TextCaret, TextCaseSegment, TextEditor, TextEditorState, TextFace, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontFetch, WebFontProviderId, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
|
|
36
|
+
import { layerTextStyleChanges, mixedTextStyleKeys, shownTextStyle } from "./character-style.js";
|
|
37
|
+
export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, BrowserFaceDescriptors, type BundledFontLocator, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, DocumentFont, DocumentFontEntry, DocumentFontInput, DownloadedFontCache, FaceWeight, FamilyFace, FontAxis, FontCandidateSource, FontFaceReadiness, FontFaceRef, FontFaceReference, FontFallbackManifestEntry, FontFallbackScript, FontFamilyOption, FontFamilySource, FontInfo, FontLoadedSource, FontManager, FontProviderLease, FontReadiness, FontReadinessStatus, FontReplacement, FontReplacementCounts, FontResolutionCandidate, FontResolutionDemand, FontResolutionEvent, FontResolutionListener, FontResolutionLoader, FontResolutionSettled, FontResolutionSnapshot, FontResolutionState, FontResolver, FontUnavailableReason, type GlyphOutlineProbe, GraphFontRequirements, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, type HarfBuzzSubsetLocator, type HostFontFamily, HostFontLoader, HyperlinkRunOptions, HyperlinkSpan, InsertStyleSource, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, LetterFallbackScript, LocalFontAccessState, MissingGlyphOccurrence, MissingGraphFontScriptsOptions, NamedInstance, NamedLocalFont, ObservedShapedLine, type OutlineCommand, PathPoint, PathTextCaret, PathTextLayout, PathTextLineMetrics, ResolvedWebFont, SampledPath, THAI_CHARACTER, TextCaret, TextCaseSegment, TextEditor, TextEditorState, TextFace, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontFetch, WebFontProviderId, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, mixedTextStyleKeys, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
|
package/dist/text/index.js
CHANGED
|
@@ -19,7 +19,7 @@ import { getTextPathData } from "./path/index.js";
|
|
|
19
19
|
import { FontResolver } from "./resolver/resolver.js";
|
|
20
20
|
import { missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript } from "./resolver/coverage.js";
|
|
21
21
|
import { fontCoverageDemand, fontFaceDemand, fontRemoteCoverageDemand, fontResolver } from "./resolver/index.js";
|
|
22
|
-
import { layerTextStyleChanges, shownTextStyle } from "./character-style.js";
|
|
22
|
+
import { layerTextStyleChanges, mixedTextStyleKeys, shownTextStyle } from "./character-style.js";
|
|
23
23
|
import { collectNamedNodeFontFaces, faceForStyle, faceStyleName, textFaceName, textStyleName } from "./font/names.js";
|
|
24
24
|
import { leaseFontProvider } from "./font/provider.js";
|
|
25
25
|
import { textFallbackScriptsWithoutCoverage, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript } from "./coverage.js";
|
|
@@ -31,4 +31,4 @@ import { TextEditor } from "./editor.js";
|
|
|
31
31
|
import { adjustRunsForDelete, applyStyleToRange, getStyleAt, insertRunsWithStyle, insertedStyleAt, removeStyleFromRange, runsAfterTyping, selectionHasStyle, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange } from "./style-runs.js";
|
|
32
32
|
import { listDocumentFonts, replaceDocumentFonts } from "./replace-fonts.js";
|
|
33
33
|
import { hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, isOpenableLinkURL, normalizeLinkURL, styleRunsWithHyperlink } from "./hyperlink.js";
|
|
34
|
-
export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, FontManager, FontResolver, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, THAI_CHARACTER, TextEditor, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
|
|
34
|
+
export { ARABIC_CHARACTER, ARABIC_LOCAL_FALLBACK_FAMILIES, ARABIC_REMOTE_FALLBACK_FAMILIES, CJK_CHARACTER, CJK_FALLBACK_CHARACTER, DEFAULT_WEB_FONT_PROVIDER_SETTINGS, DEVANAGARI_CHARACTER, FontManager, FontResolver, HANGUL_CHARACTER, HAN_CHARACTER, HEBREW_CHARACTER, KANA_CHARACTER, LETTER_FALLBACK_SCRIPTS, THAI_CHARACTER, TextEditor, UnsupportedFontFormatError, WEB_FONT_PROVIDER_IDS, WEB_FONT_PROVIDER_LABELS, WebFontResolver, adjustRunsForDelete, applyStyleToRange, browserFaceDescriptors, calibratePathTextLayout, chooseLocalFontMatch, cjkFallbackScriptForLanguage, cjkLocalFallbackFamilies, collectGraphFontKeys, collectGraphFontRequirements, collectNamedNodeFontFaces, collectNodeFontFaces, documentFontData, documentFontsOf, faceForStyle, faceStyleName, facesFromStyles, fallbackDrawsCharacter, findLocalFont, fitTextPathBoxToGlyphs, fontAxes, fontCoverageDemand, fontFaceDemand, fontFaceFromFigmaFontName, fontFaceRenderFamily, fontFallbackEntry, fontFallbackManifest, fontFallbackScriptForCharacter, fontFeatureTags, fontManager, fontRemoteCoverageDemand, fontResolver, fontTableView, fontWeightMatchOrder, getStyleAt, getTextPathData, hasFamilyFace, hasNamedInstance, hasTrueTypeOutlines, hyperlinkInRange, hyperlinkSpanAt, hyperlinkSpans, insertRunsWithStyle, insertedStyleAt, isDocumentFontFileName, isOpenableLinkURL, isTraditionalOnlyHan, isVariableFont, isWOFF2, layerTextStyleChanges, layoutPathTextFromAdvances, leaseFontProvider, listDocumentFonts, mergeArchiveFonts, missingGlyphCharacters, missingGlyphOccurrences, missingGlyphScripts, missingGlyphsByScript, missingGraphFontScripts, mixedTextStyleKeys, namedInstanceVariations, namedInstances, nearestArcPoint, nearestFamilyFace, normalizeLinkURL, normalizedCoverageText, pathTextCaret, pathTextIndexAt, pathTextSelectionQuads, pointAtArc, prepareDocumentFonts, probeGlyphOutlineCommands, readFontReadiness, reflowPathTextGlyphs, registerDocumentFonts, removeStyleFromRange, replaceDocumentFonts, resolveFontReadiness, runsAfterTyping, sampleTextPath, selectionHasStyle, setHarfBuzzSubsetLocator, sfntFamilyNames, sfntFont, sfntFontName, shownCharacters, shownText, shownTextSlice, shownTextStyle, standardFace, standardFaces, styleRunsWithHyperlink, textCaseSegments, textFaceName, textFallbackScriptsWithoutCoverage, textFontFace, textHasFallbackScript, textNeededFallbackScripts, textNeedsFallbackScript, textPathStartArc, textPathStartDistance, textStyleName, toggleBoldInRange, toggleDecorationInRange, toggleItalicInRange, transformTextCase, webFontSubsetsForText };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineTool, nodeSummary, positionInputs, toolNumber } from "../schema.js";
|
|
2
1
|
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
2
|
+
import { defineTool, nodeSummary, positionInputs, toolNumber } from "../schema.js";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
//#region src/tools/create/basic.ts
|
|
5
5
|
const createShape = defineTool({
|
|
@@ -67,7 +67,7 @@ const createPage = defineTool({
|
|
|
67
67
|
});
|
|
68
68
|
const createSlice = defineTool({
|
|
69
69
|
name: "create_slice",
|
|
70
|
-
description: "Create a slice (export region) on the canvas.",
|
|
70
|
+
description: "Create a slice layer (export region) on the canvas.",
|
|
71
71
|
execution: {
|
|
72
72
|
kind: "sync",
|
|
73
73
|
mutation: "document"
|
|
@@ -82,12 +82,11 @@ const createSlice = defineTool({
|
|
|
82
82
|
execute: (figma, args) => {
|
|
83
83
|
const parent = args.parent_id ? figma.getNodeById(args.parent_id) : null;
|
|
84
84
|
if (parent) prepareSlotInsertion(figma.graph, parent.id, "create_slice");
|
|
85
|
-
const node = figma.
|
|
85
|
+
const node = figma.createSlice();
|
|
86
86
|
node.x = args.x;
|
|
87
87
|
node.y = args.y;
|
|
88
88
|
node.resize(args.width, args.height);
|
|
89
89
|
node.name = args.name ?? "Slice";
|
|
90
|
-
node.fills = [];
|
|
91
90
|
if (parent) parent.appendChild(node);
|
|
92
91
|
return nodeSummary(node);
|
|
93
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic.js","names":[],"sources":["../../../src/tools/create/basic.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { toolNumber, positionInputs, defineTool, nodeSummary } from '#core/tools/schema'\n\nexport const createShape = defineTool({\n name: 'create_shape',\n\n description:\n 'Create a shape on the canvas. Use FRAME for containers/cards, RECTANGLE for solid blocks, ELLIPSE for circles, TEXT for labels, LINE for rules and dividers, STAR for starbursts and badges, POLYGON for triangles and regular polygons, and SECTION for page sections. Use create_vector with an SVG path for arbitrary shapes.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n type: v.pipe(\n v.picklist(['FRAME', 'RECTANGLE', 'ELLIPSE', 'TEXT', 'LINE', 'STAR', 'POLYGON', 'SECTION']),\n v.description('Node type')\n ),\n ...positionInputs,\n width: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width in pixels'))),\n height: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height in pixels'))),\n name: v.optional(v.pipe(v.string(), v.description('Node name shown in layers panel'))),\n parent_id: v.optional(v.pipe(v.string(), v.description('Parent node ID to nest inside')))\n }),\n execute: (figma, args) => {\n const parentId = args.parent_id\n const parent = parentId ? figma.getNodeById(parentId) : null\n // Refuse before creating, so a refused parent leaves no layer behind on the page.\n if (parent) prepareSlotInsertion(figma.graph, parent.id, 'create_shape')\n const createMap: Record<string, () => FigmaNodeProxy> = {\n FRAME: () => figma.createFrame(),\n RECTANGLE: () => figma.createRectangle(),\n ELLIPSE: () => figma.createEllipse(),\n TEXT: () => figma.createText(),\n LINE: () => figma.createLine(),\n STAR: () => figma.createStar(),\n POLYGON: () => figma.createPolygon(),\n SECTION: () => figma.createSection()\n }\n const node = createMap[args.type]()\n node.x = args.x\n node.y = args.y\n node.resize(args.width, args.height)\n if (args.name) node.name = args.name\n if (parent) parent.appendChild(node)\n return nodeSummary(node)\n }\n})\n\nexport const createPage = defineTool({\n name: 'create_page',\n\n description: 'Create a new page.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n name: v.pipe(v.string(), v.description('Page name'))\n }),\n execute: (figma, { name }) => {\n const page = figma.createPage()\n page.name = name\n return { id: page.id, name }\n }\n})\n\nexport const createSlice = defineTool({\n name: 'create_slice',\n\n description: 'Create a slice (export region) on the canvas.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n ...positionInputs,\n width: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width'))),\n height: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height'))),\n name: v.optional(v.pipe(v.string(), v.description('Slice name'))),\n parent_id: v.optional(v.pipe(v.string(), v.description('Parent node ID')))\n }),\n execute: (figma, args) => {\n const parent = args.parent_id ? figma.getNodeById(args.parent_id) : null\n if (parent) prepareSlotInsertion(figma.graph, parent.id, 'create_slice')\n const node = figma.
|
|
1
|
+
{"version":3,"file":"basic.js","names":[],"sources":["../../../src/tools/create/basic.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { FigmaNodeProxy } from '#core/figma-api'\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { toolNumber, positionInputs, defineTool, nodeSummary } from '#core/tools/schema'\n\nexport const createShape = defineTool({\n name: 'create_shape',\n\n description:\n 'Create a shape on the canvas. Use FRAME for containers/cards, RECTANGLE for solid blocks, ELLIPSE for circles, TEXT for labels, LINE for rules and dividers, STAR for starbursts and badges, POLYGON for triangles and regular polygons, and SECTION for page sections. Use create_vector with an SVG path for arbitrary shapes.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n type: v.pipe(\n v.picklist(['FRAME', 'RECTANGLE', 'ELLIPSE', 'TEXT', 'LINE', 'STAR', 'POLYGON', 'SECTION']),\n v.description('Node type')\n ),\n ...positionInputs,\n width: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width in pixels'))),\n height: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height in pixels'))),\n name: v.optional(v.pipe(v.string(), v.description('Node name shown in layers panel'))),\n parent_id: v.optional(v.pipe(v.string(), v.description('Parent node ID to nest inside')))\n }),\n execute: (figma, args) => {\n const parentId = args.parent_id\n const parent = parentId ? figma.getNodeById(parentId) : null\n // Refuse before creating, so a refused parent leaves no layer behind on the page.\n if (parent) prepareSlotInsertion(figma.graph, parent.id, 'create_shape')\n const createMap: Record<string, () => FigmaNodeProxy> = {\n FRAME: () => figma.createFrame(),\n RECTANGLE: () => figma.createRectangle(),\n ELLIPSE: () => figma.createEllipse(),\n TEXT: () => figma.createText(),\n LINE: () => figma.createLine(),\n STAR: () => figma.createStar(),\n POLYGON: () => figma.createPolygon(),\n SECTION: () => figma.createSection()\n }\n const node = createMap[args.type]()\n node.x = args.x\n node.y = args.y\n node.resize(args.width, args.height)\n if (args.name) node.name = args.name\n if (parent) parent.appendChild(node)\n return nodeSummary(node)\n }\n})\n\nexport const createPage = defineTool({\n name: 'create_page',\n\n description: 'Create a new page.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n name: v.pipe(v.string(), v.description('Page name'))\n }),\n execute: (figma, { name }) => {\n const page = figma.createPage()\n page.name = name\n return { id: page.id, name }\n }\n})\n\nexport const createSlice = defineTool({\n name: 'create_slice',\n\n description: 'Create a slice layer (export region) on the canvas.',\n execution: { kind: 'sync', mutation: 'document' },\n input: v.strictObject({\n ...positionInputs,\n width: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Width'))),\n height: toolNumber(v.pipe(v.number(), v.minValue(1), v.description('Height'))),\n name: v.optional(v.pipe(v.string(), v.description('Slice name'))),\n parent_id: v.optional(v.pipe(v.string(), v.description('Parent node ID')))\n }),\n execute: (figma, args) => {\n const parent = args.parent_id ? figma.getNodeById(args.parent_id) : null\n if (parent) prepareSlotInsertion(figma.graph, parent.id, 'create_slice')\n const node = figma.createSlice()\n node.x = args.x\n node.y = args.y\n node.resize(args.width, args.height)\n node.name = args.name ?? 'Slice'\n if (parent) parent.appendChild(node)\n return nodeSummary(node)\n }\n})\n"],"mappings":";;;;AAMA,MAAa,cAAc,WAAW;CACpC,MAAM;CAEN,aACE;CACF,WAAW;EAAE,MAAM;EAAQ,UAAU;CAAW;CAChD,OAAO,EAAE,aAAa;EACpB,MAAM,EAAE,KACN,E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|
|
2
|
+
import { defineTool, toolFailure, toolNumber } from "../schema.js";
|
|
3
3
|
import { PairdrawAPI } from "../../pairdraw-api/index.js";
|
|
4
4
|
import { slotOwner, slotPropertyId, updateSlotProperty } from "@pairdraw/scene-graph/slots";
|
|
5
5
|
import { behaviourSpecSchema } from "@pairdraw/scene-graph/behaviours";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","names":[],"sources":["../../../src/tools/create/code.ts"],"mappings":";;cAgCa,YAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { findPageId } from "../../io/subgraph.js";
|
|
2
|
+
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
3
|
+
import { readCodeDocument } from "../../io/formats/code/read.js";
|
|
4
|
+
import { bindCodeTokens, codeLayerNodes } from "../../io/formats/code/tokens.js";
|
|
5
|
+
import { defineTool, toolFailure } from "../schema.js";
|
|
6
|
+
import { insertionInput } from "./inputs.js";
|
|
7
|
+
import { insertionParent, placeGraphLayers } from "./place.js";
|
|
8
|
+
import * as v from "valibot";
|
|
9
|
+
import { tokenStylesheet } from "@pairdraw/dom-css/export";
|
|
10
|
+
//#region src/tools/create/code.ts
|
|
11
|
+
/** The layers a call's code draws, with the document's own tokens as its theme. */
|
|
12
|
+
async function readImportCode(graph, args) {
|
|
13
|
+
const tailwind = args.tailwind !== false;
|
|
14
|
+
const tokens = tailwind ? await tokenStylesheet(graph, { format: "tailwind" }) : void 0;
|
|
15
|
+
return readCodeDocument(args.code, {
|
|
16
|
+
css: args.css,
|
|
17
|
+
tokensCSS: tokens?.css,
|
|
18
|
+
kind: args.language === "auto" ? void 0 : args.language,
|
|
19
|
+
tailwind
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const importCode = defineTool({
|
|
23
|
+
name: "import_code",
|
|
24
|
+
description: "Import React or JSX source with Tailwind classes or inline styles, or HTML with CSS, as editable layers. Nothing in the pasted code runs: components it does not define become named frames and expressions it cannot know become placeholder text. css adds a stylesheet (a project globals.css); without x and y the layers go to the right of what the parent already holds. Returns the ids of the top-level layers and what the import could not keep.",
|
|
25
|
+
execution: {
|
|
26
|
+
kind: "async",
|
|
27
|
+
mutation: "document"
|
|
28
|
+
},
|
|
29
|
+
content: "imported",
|
|
30
|
+
input: v.strictObject({
|
|
31
|
+
code: v.pipe(v.string(), v.nonEmpty(), v.description("JSX, TSX, or HTML source: a component, a fragment, or a whole document")),
|
|
32
|
+
css: v.optional(v.pipe(v.string(), v.description("Extra CSS applied after the code’s own styles"))),
|
|
33
|
+
language: v.optional(v.pipe(v.picklist([
|
|
34
|
+
"auto",
|
|
35
|
+
"jsx",
|
|
36
|
+
"html"
|
|
37
|
+
]), v.description("How to read the code; auto detects it (default)"))),
|
|
38
|
+
tailwind: v.optional(v.pipe(v.boolean(), v.description("Compile Tailwind classes; true unless the paste carries no Tailwind"))),
|
|
39
|
+
...insertionInput("X of the imported content", "Y of the imported content")
|
|
40
|
+
}),
|
|
41
|
+
execute: async (figma, args) => {
|
|
42
|
+
const { graph, parentId } = insertionParent(figma, args.parent_id);
|
|
43
|
+
prepareSlotInsertion(graph, parentId, "import_code");
|
|
44
|
+
const parent = graph.getNode(parentId);
|
|
45
|
+
if (!parent || parent.type !== "CANVAS" && !findPageId(graph, parentId)) return { error: `Parent "${parentId}" not found` };
|
|
46
|
+
let source;
|
|
47
|
+
let report;
|
|
48
|
+
try {
|
|
49
|
+
const read = await readImportCode(graph, args);
|
|
50
|
+
source = read.graph;
|
|
51
|
+
report = read.report;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return toolFailure(error);
|
|
54
|
+
}
|
|
55
|
+
const placed = placeGraphLayers(graph, parentId, source, args, (ids) => {
|
|
56
|
+
bindCodeTokens(codeLayerNodes(graph, ids), graph, report);
|
|
57
|
+
});
|
|
58
|
+
if (!placed) return { error: "The code draws no layers" };
|
|
59
|
+
return {
|
|
60
|
+
...placed,
|
|
61
|
+
report
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
//#endregion
|
|
66
|
+
export { importCode };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","names":[],"sources":["../../../src/tools/create/code.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { tokenStylesheet } from '@pairdraw/dom-css/export'\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { bindCodeTokens, codeLayerNodes, readCodeDocument } from '#core/io/formats/code'\nimport { findPageId } from '#core/io/subgraph'\nimport { defineTool, toolFailure } from '#core/tools/schema'\n\nimport { insertionInput } from './inputs'\nimport { insertionParent, placeGraphLayers } from './place'\n\ninterface ImportCodeArgs {\n code: string\n css?: string\n language?: 'auto' | 'jsx' | 'html'\n tailwind?: boolean\n}\n\n/** The layers a call's code draws, with the document's own tokens as its theme. */\nasync function readImportCode(graph: SceneGraph, args: ImportCodeArgs) {\n const tailwind = args.tailwind !== false\n const tokens = tailwind ? await tokenStylesheet(graph, { format: 'tailwind' }) : undefined\n return readCodeDocument(args.code, {\n css: args.css,\n tokensCSS: tokens?.css,\n kind: args.language === 'auto' ? undefined : args.language,\n tailwind\n })\n}\n\nexport const importCode = defineTool({\n name: 'import_code',\n description:\n 'Import React or JSX source with Tailwind classes or inline styles, or HTML with CSS, as editable layers. Nothing in the pasted code runs: components it does not define become named frames and expressions it cannot know become placeholder text. css adds a stylesheet (a project globals.css); without x and y the layers go to the right of what the parent already holds. Returns the ids of the top-level layers and what the import could not keep.',\n execution: { kind: 'async', mutation: 'document' },\n content: 'imported',\n input: v.strictObject({\n code: v.pipe(\n v.string(),\n v.nonEmpty(),\n v.description('JSX, TSX, or HTML source: a component, a fragment, or a whole document')\n ),\n css: v.optional(\n v.pipe(v.string(), v.description('Extra CSS applied after the code’s own styles'))\n ),\n language: v.optional(\n v.pipe(\n v.picklist(['auto', 'jsx', 'html']),\n v.description('How to read the code; auto detects it (default)')\n )\n ),\n tailwind: v.optional(\n v.pipe(\n v.boolean(),\n v.description('Compile Tailwind classes; true unless the paste carries no Tailwind')\n )\n ),\n ...insertionInput('X of the imported content', 'Y of the imported content')\n }),\n execute: async (figma, args) => {\n const { graph, parentId } = insertionParent(figma, args.parent_id)\n prepareSlotInsertion(graph, parentId, 'import_code')\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n let source: SceneGraph\n let report: Awaited<ReturnType<typeof readImportCode>>['report']\n try {\n const read = await readImportCode(graph, args)\n source = read.graph\n report = read.report\n } catch (error) {\n return toolFailure(error)\n }\n const placed = placeGraphLayers(graph, parentId, source, args, (ids) => {\n // Bound after the transfer: the layers now hold the document's own variable IDs.\n bindCodeTokens(codeLayerNodes(graph, ids), graph, report)\n })\n if (!placed) return { error: 'The code draws no layers' }\n return { ...placed, report }\n }\n})\n"],"mappings":";;;;;;;;;;;AAqBA,eAAe,eAAe,OAAmB,MAAsB;CACrE,MAAM,WAAW,KAAK,aAAa;CACnC,MAAM,SAAS,WAAW,MAAM,gBAAgB,OAAO,EAAE,QAAQ,WAAW,CAAC,IAAI,KAAA;CACjF,OAAO,iBAAiB,KAAK,MAAM;EACjC,KAAK,KAAK;EACV,WAAW,QAAQ;EACnB,MAAM,KAAK,aAAa,SAAS,KAAA,IAAY,KAAK;EAClD;CACF,CAAC;AACH;AAEA,MAAa,aAAa,WAAW;CACnC,MAAM;CACN,aACE;CACF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAW;CACjD,SAAS;CACT,OAAO,EAAE,aAAa;EACpB,MAAM,EAAE,KACN,EAAE,OAAO,GACT,EAAE,SAAS,GACX,EAAE,YAAY,wEAAwE,CACxF;EACA,KAAK,EAAE,SACL,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,+CAA+C,CAAC,CACnF;EACA,UAAU,EAAE,SACV,EAAE,KACA,EAAE,SAAS;GAAC;GAAQ;GAAO;EAAM,CAAC,GAClC,EAAE,YAAY,iDAAiD,CACjE,CACF;EACA,UAAU,EAAE,SACV,EAAE,KACA,EAAE,QAAQ,GACV,EAAE,YAAY,qEAAqE,CACrF,CACF;EACA,GAAG,eAAe,6BAA6B,2BAA2B;CAC5E,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,MAAM,EAAE,OAAO,aAAa,gBAAgB,OAAO,KAAK,SAAS;EACjE,qBAAqB,OAAO,UAAU,aAAa;EACnD,MAAM,SAAS,MAAM,QAAQ,QAAQ;EACrC,IAAI,CAAC,UAAW,OAAO,SAAS,YAAY,CAAC,WAAW,OAAO,QAAQ,GACrE,OAAO,EAAE,OAAO,WAAW,SAAS,aAAa;EAEnD,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,MAAM,OAAO,MAAM,eAAe,OAAO,IAAI;GAC7C,SAAS,KAAK;GACd,SAAS,KAAK;EAChB,SAAS,OAAO;GACd,OAAO,YAAY,KAAK;EAC1B;EACA,MAAM,SAAS,iBAAiB,OAAO,UAAU,QAAQ,OAAO,QAAQ;GAEtE,eAAe,eAAe,OAAO,GAAG,GAAG,OAAO,MAAM;EAC1D,CAAC;EACD,IAAI,CAAC,QAAQ,OAAO,EAAE,OAAO,2BAA2B;EACxD,OAAO;GAAE,GAAG;GAAQ;EAAO;CAC7B;AACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/tools/create/html.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/tools/create/html.ts"],"mappings":";;cAaa,YAAA"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { findPageId } from "../../io/subgraph.js";
|
|
2
|
-
import { layoutAuthoredNodes } from "../../layout.js";
|
|
3
|
-
import { sceneGraphFromStyledHTML } from "../../io/formats/html/layers.js";
|
|
4
|
-
import { defineTool, toolFailure, toolNumber } from "../schema.js";
|
|
5
|
-
import { spaceBesideContent } from "../read/space.js";
|
|
6
2
|
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
3
|
+
import { sceneGraphFromStyledHTML } from "../../io/formats/html/layers.js";
|
|
4
|
+
import { defineTool, toolFailure } from "../schema.js";
|
|
7
5
|
import { getHTMLToolHost } from "../html-host.js";
|
|
8
|
-
import {
|
|
6
|
+
import { insertionInput } from "./inputs.js";
|
|
7
|
+
import { insertionParent, placeGraphLayers } from "./place.js";
|
|
9
8
|
import * as v from "valibot";
|
|
10
|
-
import { applyGraphTransfer, prepareGraphTransfer } from "@pairdraw/scene-graph/transfer";
|
|
11
9
|
//#region src/tools/create/html.ts
|
|
12
10
|
const importHTML = defineTool({
|
|
13
11
|
name: "import_html",
|
|
@@ -21,13 +19,10 @@ const importHTML = defineTool({
|
|
|
21
19
|
html: v.pipe(v.string(), v.nonEmpty(), v.description("HTML markup: a fragment or a whole document with <style> blocks")),
|
|
22
20
|
css: v.optional(v.pipe(v.string(), v.description("Extra CSS applied after the HTML’s own"))),
|
|
23
21
|
tailwind: v.optional(v.pipe(v.boolean(), v.description("Compile the Tailwind utility classes the markup uses")), false),
|
|
24
|
-
|
|
25
|
-
x: v.optional(toolNumber(v.pipe(v.number(), v.description("X of the imported content")))),
|
|
26
|
-
y: v.optional(toolNumber(v.pipe(v.number(), v.description("Y of the imported content"))))
|
|
22
|
+
...insertionInput("X of the imported content", "Y of the imported content")
|
|
27
23
|
}),
|
|
28
24
|
execute: async (figma, args) => {
|
|
29
|
-
const graph = figma.
|
|
30
|
-
const parentId = args.parent_id ?? figma.currentPage.id;
|
|
25
|
+
const { graph, parentId } = insertionParent(figma, args.parent_id);
|
|
31
26
|
prepareSlotInsertion(graph, parentId, "import_html");
|
|
32
27
|
const host = getHTMLToolHost(graph);
|
|
33
28
|
if (!host) return { error: "import_html needs a CSS runtime, which this environment does not provide" };
|
|
@@ -43,52 +38,9 @@ const importHTML = defineTool({
|
|
|
43
38
|
} catch (error) {
|
|
44
39
|
return toolFailure(error);
|
|
45
40
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const bounds = getAxisAlignedBoundsInParent(roots, page.id, source);
|
|
50
|
-
let topLeft = {
|
|
51
|
-
x: args.x ?? 0,
|
|
52
|
-
y: args.y ?? 0
|
|
53
|
-
};
|
|
54
|
-
if (args.x === void 0 || args.y === void 0) {
|
|
55
|
-
const beside = spaceBesideContent(graph, parentId, bounds);
|
|
56
|
-
topLeft = {
|
|
57
|
-
x: args.x ?? beside.x,
|
|
58
|
-
y: args.y ?? beside.y
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const plan = prepareGraphTransfer({
|
|
62
|
-
source,
|
|
63
|
-
rootIds: roots.map((root) => root.id),
|
|
64
|
-
dependencyPageIds: [],
|
|
65
|
-
target: graph,
|
|
66
|
-
parentId
|
|
67
|
-
});
|
|
68
|
-
const rootIds = new Set(plan.rootIds);
|
|
69
|
-
for (const node of plan.nodes) {
|
|
70
|
-
if (!rootIds.has(node.id)) continue;
|
|
71
|
-
node.props.x = (node.props.x ?? 0) - bounds.x + topLeft.x;
|
|
72
|
-
node.props.y = (node.props.y ?? 0) - bounds.y + topLeft.y;
|
|
73
|
-
}
|
|
74
|
-
applyGraphTransfer(graph, plan);
|
|
75
|
-
layoutAuthoredNodes(graph, plan.rootIds);
|
|
76
|
-
const layers = plan.rootIds.flatMap((id) => {
|
|
77
|
-
const node = graph.getNode(id);
|
|
78
|
-
return node ? [{
|
|
79
|
-
id: node.id,
|
|
80
|
-
name: node.name,
|
|
81
|
-
type: node.type
|
|
82
|
-
}] : [];
|
|
83
|
-
});
|
|
84
|
-
return {
|
|
85
|
-
ids: layers.map((layer) => layer.id),
|
|
86
|
-
layers,
|
|
87
|
-
x: topLeft.x,
|
|
88
|
-
y: topLeft.y,
|
|
89
|
-
width: bounds.width,
|
|
90
|
-
height: bounds.height
|
|
91
|
-
};
|
|
41
|
+
const placed = placeGraphLayers(graph, parentId, source, args);
|
|
42
|
+
if (!placed) return { error: "The HTML has no content to import" };
|
|
43
|
+
return placed;
|
|
92
44
|
}
|
|
93
45
|
});
|
|
94
46
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","names":[],"sources":["../../../src/tools/create/html.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\
|
|
1
|
+
{"version":3,"file":"html.js","names":[],"sources":["../../../src/tools/create/html.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { prepareSlotInsertion } from '#core/figma-api/slots'\nimport { sceneGraphFromStyledHTML } from '#core/io/formats/html/layers'\nimport { findPageId } from '#core/io/subgraph'\nimport { getHTMLToolHost } from '#core/tools/html-host'\nimport { defineTool, toolFailure } from '#core/tools/schema'\n\nimport { insertionInput } from './inputs'\nimport { insertionParent, placeGraphLayers } from './place'\n\nexport const importHTML = defineTool({\n name: 'import_html',\n description:\n 'Import HTML and CSS as editable layers in the open document, styled as a browser styles them: flex and grid become auto layout, and text, fills, borders, radii, shadows, and images carry over. <style> blocks in the HTML apply; css adds a stylesheet; tailwind compiles the Tailwind classes the markup uses. Without x and y the layers go to the right of what the parent already holds. Returns the ids of the top-level layers.',\n execution: { kind: 'async', mutation: 'document' },\n content: 'imported',\n input: v.strictObject({\n html: v.pipe(\n v.string(),\n v.nonEmpty(),\n v.description('HTML markup: a fragment or a whole document with <style> blocks')\n ),\n css: v.optional(v.pipe(v.string(), v.description('Extra CSS applied after the HTML’s own'))),\n tailwind: v.optional(\n v.pipe(v.boolean(), v.description('Compile the Tailwind utility classes the markup uses')),\n false\n ),\n ...insertionInput('X of the imported content', 'Y of the imported content')\n }),\n execute: async (figma, args) => {\n const { graph, parentId } = insertionParent(figma, args.parent_id)\n prepareSlotInsertion(graph, parentId, 'import_html')\n const host = getHTMLToolHost(graph)\n if (!host) {\n return { error: 'import_html needs a CSS runtime, which this environment does not provide' }\n }\n const parent = graph.getNode(parentId)\n if (!parent || (parent.type !== 'CANVAS' && !findPageId(graph, parentId))) {\n return { error: `Parent \"${parentId}\" not found` }\n }\n let source: SceneGraph\n try {\n const styled = await host.style(args.html, {\n cssText: args.css,\n tailwind: args.tailwind\n })\n source = sceneGraphFromStyledHTML(styled)\n } catch (error) {\n return toolFailure(error)\n }\n const placed = placeGraphLayers(graph, parentId, source, args)\n if (!placed) return { error: 'The HTML has no content to import' }\n return placed\n }\n})\n"],"mappings":";;;;;;;;;AAaA,MAAa,aAAa,WAAW;CACnC,MAAM;CACN,aACE;CACF,WAAW;EAAE,MAAM;EAAS,UAAU;CAAW;CACjD,SAAS;CACT,OAAO,EAAE,aAAa;EACpB,MAAM,EAAE,KACN,EAAE,OAAO,GACT,EAAE,SAAS,GACX,EAAE,YAAY,iEAAiE,CACjF;EACA,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,YAAY,wCAAwC,CAAC,CAAC;EAC3F,UAAU,EAAE,SACV,EAAE,KAAK,EAAE,QAAQ,GAAG,EAAE,YAAY,sDAAsD,CAAC,GACzF,KACF;EACA,GAAG,eAAe,6BAA6B,2BAA2B;CAC5E,CAAC;CACD,SAAS,OAAO,OAAO,SAAS;EAC9B,MAAM,EAAE,OAAO,aAAa,gBAAgB,OAAO,KAAK,SAAS;EACjE,qBAAqB,OAAO,UAAU,aAAa;EACnD,MAAM,OAAO,gBAAgB,KAAK;EAClC,IAAI,CAAC,MACH,OAAO,EAAE,OAAO,2EAA2E;EAE7F,MAAM,SAAS,MAAM,QAAQ,QAAQ;EACrC,IAAI,CAAC,UAAW,OAAO,SAAS,YAAY,CAAC,WAAW,OAAO,QAAQ,GACrE,OAAO,EAAE,OAAO,WAAW,SAAS,aAAa;EAEnD,IAAI;EACJ,IAAI;GACF,MAAM,SAAS,MAAM,KAAK,MAAM,KAAK,MAAM;IACzC,SAAS,KAAK;IACd,UAAU,KAAK;GACjB,CAAC;GACD,SAAS,yBAAyB,MAAM;EAC1C,SAAS,OAAO;GACd,OAAO,YAAY,KAAK;EAC1B;EACA,MAAM,SAAS,iBAAiB,OAAO,UAAU,QAAQ,IAAI;EAC7D,IAAI,CAAC,QAAQ,OAAO,EAAE,OAAO,oCAAoC;EACjE,OAAO;CACT;AACF,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { placeIcon } from "../../icons/render.js";
|
|
2
|
-
import { defineTool, parseToolColor, toolNumber } from "../schema.js";
|
|
3
2
|
import { prepareSlotInsertion } from "../../figma-api/slots.js";
|
|
3
|
+
import { defineTool, parseToolColor, toolNumber } from "../schema.js";
|
|
4
4
|
import { iconOptionsSchema } from "@pairdraw/scene-graph/icons";
|
|
5
5
|
import * as v from "valibot";
|
|
6
6
|
//#region src/tools/create/icons.ts
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
//#region src/tools/create/inputs.d.ts
|
|
3
|
+
/** The parent and position every import tool accepts, with the tool's own position wording. */
|
|
4
|
+
declare function insertionInput(xDescription: string, yDescription: string): {
|
|
5
|
+
parent_id: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "Parent node ID (default: the page)">]>, undefined>;
|
|
6
|
+
x: v.OptionalSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Expected a nonblank numeric string">, v.DescriptionAction<string, string>, v.TransformAction<any, number>, v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>]>], undefined>, undefined>;
|
|
7
|
+
y: v.OptionalSchema<v.UnionSchema<[v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>, v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "Expected a nonblank numeric string">, v.DescriptionAction<string, string>, v.TransformAction<any, number>, v.SchemaWithPipe<readonly [v.GenericSchema<number, number>, v.MinValueAction<number, number, undefined>, v.MaxValueAction<number, number, undefined>]>]>], undefined>, undefined>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { insertionInput };
|
|
11
|
+
//# sourceMappingURL=inputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","names":[],"sources":["../../../src/tools/create/inputs.ts"],"mappings":";;;iBAKgB,eAAe,sBAAsB"}
|