@pairdraw/core 0.21.1 → 0.22.1
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/images/previews.d.ts +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/bridges/undo.d.ts +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 +30 -3
- 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 +65 -9
- 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/font/batch.d.ts +26 -0
- package/dist/text/font/batch.d.ts.map +1 -0
- package/dist/text/font/batch.js +31 -0
- package/dist/text/font/batch.js.map +1 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +14 -1
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +3 -2
- package/dist/text/index.js +3 -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/font/batch.ts +58 -0
- package/src/text/font/manager.ts +17 -1
- package/src/text/index.ts +2 -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,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Ae,QAAQ,IAAI,UAAU,OAAO,GAAG,IAAI;EACrF;CACF;AACF;AA4CA,MAAa,cAAoE;CAC/E,MAAM;CACN,UAAU,OAAO,SAAS;EACxB,MAAM,OAAO,MAAM,QAAQ,KAAK,EAAE;EAClC,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,SAAS,KAAK,GAAG,aAAa;EAEzD,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EAC9D,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,OAAm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AAO,MAAM,QAAQ,KAAK,EAAE;EAClC,IAAI,CAAC,MAAM,OAAO,EAAE,OAAO,SAAS,KAAK,GAAG,aAAa;EAEzD,MAAM,SAAS,KAAK,WAAW,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAA;EAC9D,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"}
|
|
@@ -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,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AS,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;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,Q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AM,KAAK,IAAI,OAAO,IAAI,KAAK;EAC/B,IAAI,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,MAAM;EACxC,OAAO,IAAI;CACb,EAAE,CAAC,CACF,QAAQ,QAAQ,IAAI,KAAK,IAAI,IAAI;CACpC,MAAM,wBAAQ,IAAI,IAAkB;CACpC,KAAK,MAAM,OAAO,iBAAiB;EACjC,IAAI;EACJ,IAAI,OAAO;EACX,MAAM,UAAU,EAAE,SAAS,MAAM;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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/text/font/batch.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Adds faces that arrive together to the page in one task. WebKit clears its style resolver on
|
|
4
|
+
* every `document.fonts.add` and rebuilds it on the next style update, walking each registered
|
|
5
|
+
* `@property` rule across every live animation, so a burst of font loads that adds one task per
|
|
6
|
+
* face pays that rebuild once per face instead of once per burst.
|
|
7
|
+
*/
|
|
8
|
+
interface FontFaceBatch<T> {
|
|
9
|
+
/** Queues an item and schedules the batch's single add when none is scheduled. */
|
|
10
|
+
push(item: T): void;
|
|
11
|
+
/** Adds everything queued now; a no-op when nothing is queued. */
|
|
12
|
+
flush(): void;
|
|
13
|
+
}
|
|
14
|
+
interface FontFaceBatchOptions<T> {
|
|
15
|
+
add: (item: T) => void;
|
|
16
|
+
/** Gets an item whose add failed; the rest of the batch is still added. */
|
|
17
|
+
onError?: (item: T, error: unknown) => void;
|
|
18
|
+
/** Runs `flush` once after the caller's batch window, which a test drives by hand. */
|
|
19
|
+
schedule: (run: () => void) => void;
|
|
20
|
+
}
|
|
21
|
+
/** How long fonts loaded for the editor wait, so a burst reaches the page as one change. */
|
|
22
|
+
declare const FONT_FACE_BATCH_DELAY_MS = 120;
|
|
23
|
+
declare function createFontFaceBatch<T>({ add, onError, schedule }: FontFaceBatchOptions<T>): FontFaceBatch<T>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { FONT_FACE_BATCH_DELAY_MS, FontFaceBatch, FontFaceBatchOptions, createFontFaceBatch };
|
|
26
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","names":[],"sources":["../../../src/text/font/batch.ts"],"mappings":";;;;;;;UAMiB,cAAc;;EAE7B,KAAK,MAAM;;EAEX;;UAGe,qBAAqB;EACpC,MAAM,MAAM;;EAEZ,WAAW,MAAM,GAAG;;EAEpB,WAAW;;;cAIA;iBAEG,oBAAoB,KAClC,KACA,SACA,YACC,qBAAqB,KAAK,cAAc"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/text/font/batch.ts
|
|
2
|
+
/** How long fonts loaded for the editor wait, so a burst reaches the page as one change. */
|
|
3
|
+
const FONT_FACE_BATCH_DELAY_MS = 120;
|
|
4
|
+
function createFontFaceBatch({ add, onError, schedule }) {
|
|
5
|
+
let queued = [];
|
|
6
|
+
let scheduled = false;
|
|
7
|
+
function flush() {
|
|
8
|
+
scheduled = false;
|
|
9
|
+
if (queued.length === 0) return;
|
|
10
|
+
const batch = queued;
|
|
11
|
+
queued = [];
|
|
12
|
+
for (const item of batch) try {
|
|
13
|
+
add(item);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
onError?.(item, error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
push(item) {
|
|
20
|
+
queued.push(item);
|
|
21
|
+
if (scheduled) return;
|
|
22
|
+
scheduled = true;
|
|
23
|
+
schedule(flush);
|
|
24
|
+
},
|
|
25
|
+
flush
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { FONT_FACE_BATCH_DELAY_MS, createFontFaceBatch };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","names":[],"sources":["../../../src/text/font/batch.ts"],"sourcesContent":["/**\n * Adds faces that arrive together to the page in one task. WebKit clears its style resolver on\n * every `document.fonts.add` and rebuilds it on the next style update, walking each registered\n * `@property` rule across every live animation, so a burst of font loads that adds one task per\n * face pays that rebuild once per face instead of once per burst.\n */\nexport interface FontFaceBatch<T> {\n /** Queues an item and schedules the batch's single add when none is scheduled. */\n push(item: T): void\n /** Adds everything queued now; a no-op when nothing is queued. */\n flush(): void\n}\n\nexport interface FontFaceBatchOptions<T> {\n add: (item: T) => void\n /** Gets an item whose add failed; the rest of the batch is still added. */\n onError?: (item: T, error: unknown) => void\n /** Runs `flush` once after the caller's batch window, which a test drives by hand. */\n schedule: (run: () => void) => void\n}\n\n/** How long fonts loaded for the editor wait, so a burst reaches the page as one change. */\nexport const FONT_FACE_BATCH_DELAY_MS = 120\n\nexport function createFontFaceBatch<T>({\n add,\n onError,\n schedule\n}: FontFaceBatchOptions<T>): FontFaceBatch<T> {\n let queued: T[] = []\n let scheduled = false\n\n function flush(): void {\n scheduled = false\n if (queued.length === 0) return\n const batch = queued\n queued = []\n // One face the page refuses must not take the rest of the burst with it, or throw from the\n // timer that called this.\n for (const item of batch) {\n try {\n add(item)\n } catch (error) {\n onError?.(item, error)\n }\n }\n }\n\n return {\n push(item: T): void {\n queued.push(item)\n if (scheduled) return\n scheduled = true\n schedule(flush)\n },\n flush\n }\n}\n"],"mappings":";;AAsBA,MAAa,2BAA2B;AAExC,SAAgB,oBAAuB,EACrC,KACA,SACA,YAC4C;CAC5C,IAAI,SAAc,CAAC;CACnB,IAAI,YAAY;CAEhB,SAAS,QAAc;EACrB,YAAY;EACZ,IAAI,OAAO,WAAW,GAAG;EACzB,MAAM,QAAQ;EACd,SAAS,CAAC;EAGV,KAAK,MAAM,QAAQ,OACjB,IAAI;GACF,IAAI,IAAI;EACV,SAAS,OAAO;GACd,UAAU,MAAM,KAAK;EACvB;CAEJ;CAEA,OAAO;EACL,KAAK,MAAe;GAClB,OAAO,KAAK,IAAI;GAChB,IAAI,WAAW;GACf,YAAY;GACZ,SAAS,KAAK;EAChB;EACA;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","names":[],"sources":["../../../src/text/font/manager.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","names":[],"sources":["../../../src/text/font/manager.ts"],"mappings":";;;;;;;;;;cA2Fa;UACH;;UAEA;UACA;UACA;UACA;;UAEA;;;;;;UAMA;;;;;;UAMA;UACA;UACA;UACA;UAIA;UACA;UACA;UACA;UACA;UACA;UACA;mBACS;UAIT;UACA;UACA;mBACS;UACT;mBACS;mBACA;mBACA;mBACA;mBACA;UAKT;UACA;;mBAES;mBAGA;;;;;;;;;EAUjB,gBAAgB,WAAW,YAAY;EAiBvC,gBAAgB,UAAU;EAY1B,eAAe,WAAW,WAAW,UAAU;EAgB/C,eAAe,UAAU;EASzB,YAAY;;EAKZ,YAAY,WAAW,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;;EAOpC,UAAU,gBAAgB,yBAAyB;;UAK3C;;UAWA;EAMR,gBAAgB,OAAO,YAAY,oBAAoB;EAIjD,qBAAqB;EAQ3B;EAIA,qBAAqB;UAMb;UAWA;;UAUA;EAIR,mBACE,UAAS,sBACT,qBACA,SAAS,cACR,QAAQ,QAAQ,OAAO;UAIZ;;;;;EA8Bd;EAIA,wBAAwB,QAAQ,sBAAsB;;;;;;;;UAYxC;;UAwCA;;;;;;UA0BN;UAyBA;UAQM;UAwBA;UAcA;;UAeN;UAiBA;;;;;EAoCR,aAAa,WAAW,gBAAgB;UAKhC;UAQA;;EAwBR,sBAAsB,gBAAgB,eAAe,MAAM;;cAsBhD,aAAW"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_FONT_FAMILY, IS_BROWSER } from "../../constants.js";
|
|
2
2
|
import { LETTER_FALLBACK_SCRIPTS, fallbackDrawsCharacter, fontFallbackEntry } from "../fallbacks.js";
|
|
3
|
+
import { createFontFaceBatch } from "./batch.js";
|
|
3
4
|
import { BundledFonts } from "./bundled.js";
|
|
4
5
|
import { fontAxes, hasNamedInstance, namedInstanceVariations, namedInstances } from "./variation.js";
|
|
5
6
|
import { browserFaceDescriptors, fontFaceRenderFamily } from "./faces.js";
|
|
@@ -805,7 +806,7 @@ var FontManager = class {
|
|
|
805
806
|
registerFontInBrowser(family, style, data) {
|
|
806
807
|
if (!IS_BROWSER) return;
|
|
807
808
|
const face = new FontFace(family, data, browserFaceDescriptors(style, data));
|
|
808
|
-
face.load().then(() =>
|
|
809
|
+
face.load().then(() => browserFaces?.push(face)).catch(() => {
|
|
809
810
|
console.warn(`Failed to load font "${family}" (${style})`);
|
|
810
811
|
});
|
|
811
812
|
}
|
|
@@ -820,6 +821,18 @@ function pageDrawsByName(source) {
|
|
|
820
821
|
return source === "local" || source === "fallback";
|
|
821
822
|
}
|
|
822
823
|
const fontManager = new FontManager();
|
|
824
|
+
/**
|
|
825
|
+
* Faces loaded for the page's own text, added once per burst. Each `document.fonts.add` makes
|
|
826
|
+
* WebKit rebuild its style resolver, and a rebuild registers every `@property` rule across every
|
|
827
|
+
* live animation, so a burst of font loads must not clear the resolver once per face.
|
|
828
|
+
*/
|
|
829
|
+
const browserFaces = IS_BROWSER ? createFontFaceBatch({
|
|
830
|
+
add: (face) => document.fonts.add(face),
|
|
831
|
+
onError: (face) => console.warn(`Failed to add font "${face.family}" to the page`),
|
|
832
|
+
schedule: (run) => {
|
|
833
|
+
setTimeout(run, 120);
|
|
834
|
+
}
|
|
835
|
+
}) : null;
|
|
823
836
|
function isLetterFallbackScript(script) {
|
|
824
837
|
return LETTER_FALLBACK_SCRIPTS.some((letter) => letter === script);
|
|
825
838
|
}
|