@pairdraw/core 0.18.0 → 0.19.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/effects.d.ts +5 -11
- package/dist/canvas/effects.d.ts.map +1 -1
- package/dist/canvas/effects.js +25 -30
- package/dist/canvas/effects.js.map +1 -1
- package/dist/canvas/labels/hit-test.d.ts +5 -0
- package/dist/canvas/labels/hit-test.d.ts.map +1 -1
- package/dist/canvas/labels/hit-test.js +1 -1
- package/dist/canvas/labels/hit-test.js.map +1 -1
- package/dist/canvas/labels/paragraph-cache.d.ts.map +1 -1
- package/dist/canvas/labels/paragraph-cache.js +3 -2
- package/dist/canvas/labels/paragraph-cache.js.map +1 -1
- package/dist/canvas/labels/selection.js +3 -2
- package/dist/canvas/labels/selection.js.map +1 -1
- package/dist/canvas/labels/style.d.ts +1 -1
- package/dist/canvas/node-edit-overlay.js +2 -2
- package/dist/canvas/node-edit-overlay.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/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +4 -37
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/region-hatch.js +3 -2
- package/dist/canvas/region-hatch.js.map +1 -1
- package/dist/canvas/renderer/colors.d.ts.map +1 -1
- package/dist/canvas/renderer/colors.js +36 -18
- package/dist/canvas/renderer/colors.js.map +1 -1
- package/dist/canvas/renderer/font-waiters.d.ts +9 -0
- package/dist/canvas/renderer/font-waiters.d.ts.map +1 -0
- package/dist/canvas/renderer/font-waiters.js +26 -0
- package/dist/canvas/renderer/font-waiters.js.map +1 -0
- package/dist/canvas/renderer/fonts.d.ts +4 -2
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +23 -9
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
- package/dist/canvas/renderer/lifecycle.js +6 -9
- package/dist/canvas/renderer/lifecycle.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +4 -5
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/paints.d.ts.map +1 -1
- package/dist/canvas/renderer/paints.js +0 -6
- package/dist/canvas/renderer/paints.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +20 -2
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/retained-backing.js +4 -4
- package/dist/canvas/renderer/retained-backing.js.map +1 -1
- package/dist/canvas/renderer/state.js +1 -1
- package/dist/canvas/renderer/state.js.map +1 -1
- package/dist/canvas/renderer/tiles/controller.d.ts +2 -0
- package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
- package/dist/canvas/renderer/tiles/controller.js +8 -0
- package/dist/canvas/renderer/tiles/controller.js.map +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js +1 -1
- package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
- package/dist/canvas/renderer/visual-bounds.d.ts.map +1 -1
- package/dist/canvas/renderer/visual-bounds.js +7 -5
- package/dist/canvas/renderer/visual-bounds.js.map +1 -1
- package/dist/canvas/renderer.d.ts +22 -7
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +46 -11
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/rulers.d.ts +8 -1
- package/dist/canvas/rulers.d.ts.map +1 -1
- package/dist/canvas/rulers.js +30 -5
- package/dist/canvas/rulers.js.map +1 -1
- package/dist/canvas/scene.d.ts +2 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +30 -18
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/shadows/shape.js +1 -1
- package/dist/canvas/shadows/shape.js.map +1 -1
- package/dist/canvas/shadows/silhouette.d.ts.map +1 -1
- package/dist/canvas/shadows/silhouette.js +4 -2
- package/dist/canvas/shadows/silhouette.js.map +1 -1
- package/dist/canvas/shadows.d.ts.map +1 -1
- package/dist/canvas/shadows.js +3 -2
- package/dist/canvas/shadows.js.map +1 -1
- package/dist/canvas/text/derived.d.ts +1 -2
- package/dist/canvas/text/derived.d.ts.map +1 -1
- package/dist/canvas/text/derived.js +1 -7
- package/dist/canvas/text/derived.js.map +1 -1
- package/dist/canvas/text/emoji/index.js +1 -1
- package/dist/canvas/text/emoji/raster.d.ts.map +1 -1
- package/dist/canvas/text/emoji/raster.js +14 -10
- package/dist/canvas/text/emoji/raster.js.map +1 -1
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +5 -2
- package/dist/canvas/text/font-families.js.map +1 -1
- package/dist/canvas/text/index.d.ts +1 -3
- package/dist/canvas/text/index.d.ts.map +1 -1
- package/dist/canvas/text/index.js +1 -8
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/layout/build.d.ts.map +1 -1
- package/dist/canvas/text/layout/build.js +25 -9
- package/dist/canvas/text/layout/build.js.map +1 -1
- package/dist/canvas/text/layout/index.d.ts.map +1 -1
- package/dist/canvas/text/layout/index.js +8 -4
- package/dist/canvas/text/layout/index.js.map +1 -1
- package/dist/canvas/text/layout/lines.js +5 -3
- package/dist/canvas/text/layout/lines.js.map +1 -1
- package/dist/canvas/text/paragraph/index.d.ts +5 -0
- package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/index.js +16 -7
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts +1 -1
- package/dist/canvas/text/paragraph/inputs.d.ts.map +1 -1
- package/dist/canvas/text/paragraph/inputs.js +9 -2
- package/dist/canvas/text/paragraph/inputs.js.map +1 -1
- package/dist/canvas/text/placed.js +1 -1
- package/dist/canvas/text/shape.d.ts +4 -3
- package/dist/canvas/text/shape.d.ts.map +1 -1
- package/dist/canvas/text/shape.js +9 -22
- package/dist/canvas/text/shape.js.map +1 -1
- package/dist/constants.d.ts +6 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -2
- package/dist/constants.js.map +1 -1
- package/dist/editor/bridges/clipboard.d.ts +1 -0
- package/dist/editor/bridges/clipboard.js +1 -0
- package/dist/editor/bridges/clipboard.js.map +1 -1
- package/dist/editor/bridges/components.d.ts +2 -0
- package/dist/editor/bridges/components.d.ts.map +1 -1
- package/dist/editor/bridges/components.js +2 -0
- package/dist/editor/bridges/components.js.map +1 -1
- package/dist/editor/bridges/frames.d.ts +4 -3
- package/dist/editor/bridges/frames.d.ts.map +1 -1
- package/dist/editor/bridges/frames.js +6 -4
- package/dist/editor/bridges/frames.js.map +1 -1
- package/dist/editor/bridges/structure.d.ts +1 -0
- package/dist/editor/bridges/structure.d.ts.map +1 -1
- package/dist/editor/bridges/structure.js +1 -0
- package/dist/editor/bridges/structure.js.map +1 -1
- package/dist/editor/clipboard/detach.js +2 -2
- package/dist/editor/clipboard/detach.js.map +1 -1
- package/dist/editor/clipboard/paste/properties.js +1 -1
- package/dist/editor/clipboard/paste/target.js +2 -2
- package/dist/editor/clipboard/paste/target.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts +3 -0
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +2 -0
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard/variables.d.ts.map +1 -1
- package/dist/editor/clipboard/variables.js +14 -1
- package/dist/editor/clipboard/variables.js.map +1 -1
- package/dist/editor/clipboard.d.ts +1 -0
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +122 -16
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/component-sync.d.ts +10 -1
- package/dist/editor/component-sync.d.ts.map +1 -1
- package/dist/editor/component-sync.js +25 -8
- package/dist/editor/component-sync.js.map +1 -1
- package/dist/editor/components/authoring/text-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/text-edit.js +11 -2
- package/dist/editor/components/authoring/text-edit.js.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.d.ts.map +1 -1
- package/dist/editor/components/authoring/visibility-edit.js +7 -3
- package/dist/editor/components/authoring/visibility-edit.js.map +1 -1
- package/dist/editor/components/instances.d.ts +2 -0
- package/dist/editor/components/instances.d.ts.map +1 -1
- package/dist/editor/components/instances.js +37 -7
- package/dist/editor/components/instances.js.map +1 -1
- package/dist/editor/components/properties.d.ts.map +1 -1
- package/dist/editor/components/properties.js +3 -0
- package/dist/editor/components/properties.js.map +1 -1
- package/dist/editor/components/slots/authoring.js +2 -1
- package/dist/editor/components/slots/authoring.js.map +1 -1
- package/dist/editor/components.d.ts +2 -0
- package/dist/editor/components.d.ts.map +1 -1
- package/dist/editor/create.d.ts +17 -3
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +43 -6
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/guides.d.ts.map +1 -1
- package/dist/editor/guides.js +20 -13
- package/dist/editor/guides.js.map +1 -1
- package/dist/editor/history/document-change.d.ts +19 -3
- package/dist/editor/history/document-change.d.ts.map +1 -1
- package/dist/editor/history/document-change.js +94 -8
- package/dist/editor/history/document-change.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +56 -12
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/history/position.js +1 -4
- package/dist/editor/history/position.js.map +1 -1
- package/dist/editor/history/sources.d.ts +14 -0
- package/dist/editor/history/sources.d.ts.map +1 -0
- package/dist/editor/history/sources.js +24 -0
- package/dist/editor/history/sources.js.map +1 -0
- package/dist/editor/index.d.ts +2 -2
- package/dist/editor/index.js +1 -1
- package/dist/editor/layout-mode.d.ts.map +1 -1
- package/dist/editor/layout-mode.js +16 -1
- package/dist/editor/layout-mode.js.map +1 -1
- package/dist/editor/node-preview.d.ts.map +1 -1
- package/dist/editor/node-preview.js +26 -7
- package/dist/editor/node-preview.js.map +1 -1
- package/dist/editor/nodes.d.ts.map +1 -1
- package/dist/editor/nodes.js +33 -10
- package/dist/editor/nodes.js.map +1 -1
- package/dist/editor/nudge.d.ts.map +1 -1
- package/dist/editor/nudge.js +12 -2
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/pages.d.ts +2 -1
- package/dist/editor/pages.d.ts.map +1 -1
- package/dist/editor/pages.js +94 -15
- package/dist/editor/pages.js.map +1 -1
- package/dist/editor/play/states.d.ts.map +1 -1
- package/dist/editor/play/states.js +0 -5
- package/dist/editor/play/states.js.map +1 -1
- package/dist/editor/read-only/actions.js +3 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/hit-test.d.ts +2 -1
- package/dist/editor/selection/hit-test.d.ts.map +1 -1
- package/dist/editor/selection/hit-test.js +29 -4
- package/dist/editor/selection/hit-test.js.map +1 -1
- package/dist/editor/selection.d.ts +2 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/pen.js +6 -2
- package/dist/editor/shapes/pen.js.map +1 -1
- package/dist/editor/shapes.d.ts.map +1 -1
- package/dist/editor/shapes.js +2 -1
- package/dist/editor/shapes.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.d.ts.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +12 -0
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.js +1 -1
- package/dist/editor/structure/group/bounds.d.ts +4 -2
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +17 -4
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/rename.d.ts +2 -3
- package/dist/editor/structure/rename.d.ts.map +1 -1
- package/dist/editor/structure/rename.js +2 -5
- package/dist/editor/structure/rename.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +20 -9
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure.d.ts +1 -0
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +76 -20
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/text/hyperlink.d.ts.map +1 -1
- package/dist/editor/text/hyperlink.js +1 -1
- package/dist/editor/text/hyperlink.js.map +1 -1
- package/dist/editor/text/name.d.ts +13 -5
- package/dist/editor/text/name.d.ts.map +1 -1
- package/dist/editor/text/name.js +47 -17
- package/dist/editor/text/name.js.map +1 -1
- package/dist/editor/text/pending-layout.d.ts +2 -1
- package/dist/editor/text/pending-layout.d.ts.map +1 -1
- package/dist/editor/text/pending-layout.js +33 -6
- package/dist/editor/text/pending-layout.js.map +1 -1
- 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 +16 -4
- package/dist/editor/text/selection-style.js.map +1 -1
- package/dist/editor/text.d.ts +5 -0
- package/dist/editor/text.d.ts.map +1 -1
- package/dist/editor/text.js +70 -3
- package/dist/editor/text.js.map +1 -1
- package/dist/editor/types.d.ts +18 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/undo.d.ts.map +1 -1
- package/dist/editor/undo.js +14 -2
- package/dist/editor/undo.js.map +1 -1
- package/dist/editor/variable-bindings.d.ts.map +1 -1
- package/dist/editor/variable-bindings.js +21 -2
- package/dist/editor/variable-bindings.js.map +1 -1
- package/dist/editor/variables.d.ts +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +7 -8
- package/dist/editor/variables.js.map +1 -1
- package/dist/editor/viewport.d.ts +11 -2
- package/dist/editor/viewport.d.ts.map +1 -1
- package/dist/editor/viewport.js +61 -21
- package/dist/editor/viewport.js.map +1 -1
- package/dist/editor/views/actions.d.ts.map +1 -1
- package/dist/editor/views/actions.js +13 -5
- package/dist/editor/views/actions.js.map +1 -1
- package/dist/editor/views/present.d.ts +6 -4
- package/dist/editor/views/present.d.ts.map +1 -1
- package/dist/editor/views/present.js +12 -10
- package/dist/editor/views/present.js.map +1 -1
- package/dist/editor/views/types.d.ts +11 -5
- package/dist/editor/views/types.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.d.ts.map +1 -1
- package/dist/figma-api/accessor-utils.js +4 -1
- package/dist/figma-api/accessor-utils.js.map +1 -1
- package/dist/figma-api/accessors/basic.d.ts.map +1 -1
- package/dist/figma-api/accessors/basic.js +41 -21
- package/dist/figma-api/accessors/basic.js.map +1 -1
- package/dist/figma-api/accessors/layout.d.ts.map +1 -1
- package/dist/figma-api/accessors/layout.js +37 -7
- package/dist/figma-api/accessors/layout.js.map +1 -1
- package/dist/figma-api/accessors/reactions.d.ts +11 -0
- package/dist/figma-api/accessors/reactions.d.ts.map +1 -0
- package/dist/figma-api/accessors/reactions.js +30 -0
- package/dist/figma-api/accessors/reactions.js.map +1 -0
- package/dist/figma-api/accessors/strokes.d.ts.map +1 -1
- package/dist/figma-api/accessors/strokes.js +12 -4
- package/dist/figma-api/accessors/strokes.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +3 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/accessors/vector.d.ts.map +1 -1
- package/dist/figma-api/accessors/vector.js +1 -1
- package/dist/figma-api/accessors/vector.js.map +1 -1
- package/dist/figma-api/accessors/visual.d.ts +6 -5
- package/dist/figma-api/accessors/visual.d.ts.map +1 -1
- package/dist/figma-api/accessors/visual.js +20 -17
- package/dist/figma-api/accessors/visual.js.map +1 -1
- package/dist/figma-api/components.d.ts.map +1 -1
- package/dist/figma-api/components.js +2 -1
- package/dist/figma-api/components.js.map +1 -1
- package/dist/figma-api/finite.d.ts +27 -0
- package/dist/figma-api/finite.d.ts.map +1 -0
- package/dist/figma-api/finite.js +69 -0
- package/dist/figma-api/finite.js.map +1 -0
- package/dist/figma-api/fonts/list.d.ts +13 -0
- package/dist/figma-api/fonts/list.d.ts.map +1 -0
- package/dist/figma-api/fonts/list.js +25 -0
- package/dist/figma-api/fonts/list.js.map +1 -0
- package/dist/figma-api/index.d.ts +21 -3
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +58 -13
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/overrides.d.ts +6 -1
- package/dist/figma-api/overrides.d.ts.map +1 -1
- package/dist/figma-api/overrides.js +2 -2
- package/dist/figma-api/overrides.js.map +1 -1
- package/dist/figma-api/pending-layout.d.ts +12 -2
- package/dist/figma-api/pending-layout.d.ts.map +1 -1
- package/dist/figma-api/pending-layout.js +41 -1
- package/dist/figma-api/pending-layout.js.map +1 -1
- package/dist/figma-api/pending-sync.d.ts +19 -0
- package/dist/figma-api/pending-sync.d.ts.map +1 -0
- package/dist/figma-api/pending-sync.js +52 -0
- package/dist/figma-api/pending-sync.js.map +1 -0
- package/dist/figma-api/proxy.d.ts +15 -2
- package/dist/figma-api/proxy.d.ts.map +1 -1
- package/dist/figma-api/proxy.js +23 -3
- package/dist/figma-api/proxy.js.map +1 -1
- package/dist/figma-api/reactions.d.ts +104 -0
- package/dist/figma-api/reactions.d.ts.map +1 -0
- package/dist/figma-api/reactions.js +157 -0
- package/dist/figma-api/reactions.js.map +1 -0
- package/dist/figma-api/render-bounds.d.ts.map +1 -1
- package/dist/figma-api/render-bounds.js +4 -4
- package/dist/figma-api/render-bounds.js.map +1 -1
- package/dist/figma-api/serialization.js +2 -2
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/slots.d.ts +7 -1
- package/dist/figma-api/slots.d.ts.map +1 -1
- package/dist/figma-api/slots.js +12 -4
- package/dist/figma-api/slots.js.map +1 -1
- package/dist/figma-api/strokes.d.ts +5 -2
- package/dist/figma-api/strokes.d.ts.map +1 -1
- package/dist/figma-api/strokes.js +12 -19
- package/dist/figma-api/strokes.js.map +1 -1
- package/dist/figma-api/text/bindings.js +1 -1
- package/dist/figma-api/text/index.d.ts +2 -3
- package/dist/figma-api/text/index.d.ts.map +1 -1
- package/dist/figma-api/text/index.js +2 -12
- package/dist/figma-api/text/index.js.map +1 -1
- package/dist/figma-api/variables/bindings.js +1 -1
- package/dist/figma-api/variables/variable.d.ts.map +1 -1
- package/dist/figma-api/variables/variable.js +2 -2
- package/dist/figma-api/variables/variable.js.map +1 -1
- package/dist/geometry/figma.d.ts +6 -1
- package/dist/geometry/figma.d.ts.map +1 -1
- package/dist/geometry/figma.js +8 -1
- package/dist/geometry/figma.js.map +1 -1
- package/dist/geometry/index.d.ts +2 -2
- package/dist/geometry/index.js +2 -2
- package/dist/icons/api.d.ts +3 -2
- package/dist/icons/api.d.ts.map +1 -1
- package/dist/icons/api.js +12 -12
- package/dist/icons/api.js.map +1 -1
- package/dist/icons/provider.d.ts +4 -3
- package/dist/icons/provider.d.ts.map +1 -1
- package/dist/icons/provider.js +6 -13
- package/dist/icons/provider.js.map +1 -1
- package/dist/icons/schema.d.ts +33 -1
- package/dist/icons/schema.d.ts.map +1 -1
- package/dist/icons/schema.js +30 -1
- package/dist/icons/schema.js.map +1 -1
- package/dist/icons/svg/presentation.d.ts +8 -1
- package/dist/icons/svg/presentation.d.ts.map +1 -1
- package/dist/icons/svg/presentation.js +21 -3
- package/dist/icons/svg/presentation.js.map +1 -1
- package/dist/icons/svg/text.js +1 -1
- package/dist/icons/svg/text.js.map +1 -1
- package/dist/icons/svg.d.ts +8 -3
- package/dist/icons/svg.d.ts.map +1 -1
- package/dist/icons/svg.js +15 -13
- package/dist/icons/svg.js.map +1 -1
- package/dist/icons/types.d.ts +1 -19
- package/dist/icons/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/io/formats/design-tokens/apply.d.ts +1 -1
- package/dist/io/formats/design-tokens/css/read.js +1 -1
- package/dist/io/formats/design-tokens/decode.js +1 -1
- package/dist/io/formats/design-tokens/plan/index.js +4 -2
- package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/plan/styles.js +23 -3
- package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/styles.d.ts +9 -1
- package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/styles.js +41 -4
- package/dist/io/formats/design-tokens/styles.js.map +1 -1
- package/dist/io/formats/design-tokens/types.d.ts +5 -0
- package/dist/io/formats/design-tokens/types.d.ts.map +1 -1
- package/dist/io/formats/design-tokens/types.js +1 -0
- package/dist/io/formats/design-tokens/types.js.map +1 -1
- package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
- package/dist/io/formats/fig/export/setup.js +8 -4
- package/dist/io/formats/fig/export/setup.js.map +1 -1
- package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
- package/dist/io/formats/fig/export/variables.js +2 -2
- package/dist/io/formats/fig/export/variables.js.map +1 -1
- package/dist/io/formats/fig/index.d.ts +2 -2
- package/dist/io/formats/fig/index.js +2 -2
- package/dist/io/formats/fig/read.d.ts +9 -2
- package/dist/io/formats/fig/read.d.ts.map +1 -1
- package/dist/io/formats/fig/read.js +44 -20
- package/dist/io/formats/fig/read.js.map +1 -1
- package/dist/io/formats/html/index.d.ts.map +1 -1
- package/dist/io/formats/html/index.js +2 -6
- package/dist/io/formats/html/index.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +65 -1
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/prepare.js +1 -1
- package/dist/io/formats/pen/fonts.d.ts +14 -0
- package/dist/io/formats/pen/fonts.d.ts.map +1 -0
- package/dist/io/formats/pen/fonts.js +39 -0
- package/dist/io/formats/pen/fonts.js.map +1 -0
- package/dist/io/formats/pen/index.d.ts.map +1 -1
- package/dist/io/formats/pen/index.js +25 -6
- package/dist/io/formats/pen/index.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts +2 -2
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +24 -13
- 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 +7 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +40 -6
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +28 -24
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/io/formats/svg/paths.d.ts +8 -2
- package/dist/io/formats/svg/paths.d.ts.map +1 -1
- package/dist/io/formats/svg/paths.js +11 -3
- package/dist/io/formats/svg/paths.js.map +1 -1
- package/dist/io/formats/svg/strokes.d.ts.map +1 -1
- package/dist/io/formats/svg/strokes.js +2 -5
- package/dist/io/formats/svg/strokes.js.map +1 -1
- package/dist/io/formats/svg/text/export.d.ts.map +1 -1
- package/dist/io/formats/svg/text/export.js +19 -1
- package/dist/io/formats/svg/text/export.js.map +1 -1
- package/dist/io/formats/svg/text/import.d.ts.map +1 -1
- package/dist/io/formats/svg/text/import.js +2 -1
- package/dist/io/formats/svg/text/import.js.map +1 -1
- package/dist/io/subgraph.d.ts.map +1 -1
- package/dist/io/subgraph.js +5 -2
- package/dist/io/subgraph.js.map +1 -1
- package/dist/kiwi/fig/population/client.d.ts.map +1 -1
- package/dist/kiwi/fig/population/client.js +63 -45
- package/dist/kiwi/fig/population/client.js.map +1 -1
- package/dist/kiwi/fig/population/delta.d.ts +34 -3
- package/dist/kiwi/fig/population/delta.d.ts.map +1 -1
- package/dist/kiwi/fig/population/delta.js +99 -16
- package/dist/kiwi/fig/population/delta.js.map +1 -1
- package/dist/kiwi/fig/population/edits.d.ts +51 -0
- package/dist/kiwi/fig/population/edits.d.ts.map +1 -0
- package/dist/kiwi/fig/population/edits.js +169 -0
- package/dist/kiwi/fig/population/edits.js.map +1 -0
- package/dist/kiwi/fig/session/archive/access.d.ts +3 -0
- package/dist/kiwi/fig/session/archive/access.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/access.js +8 -1
- package/dist/kiwi/fig/session/archive/access.js.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts +2 -1
- package/dist/kiwi/fig/session/archive/changes.d.ts.map +1 -1
- package/dist/kiwi/fig/session/archive/changes.js +12 -5
- package/dist/kiwi/fig/session/archive/changes.js.map +1 -1
- package/dist/kiwi/fig/session/document-state.d.ts +7 -1
- package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
- package/dist/kiwi/fig/session/document-state.js +16 -2
- package/dist/kiwi/fig/session/document-state.js.map +1 -1
- package/dist/kiwi/fig/session/protocol.d.ts +31 -3
- package/dist/kiwi/fig/session/protocol.d.ts.map +1 -1
- package/dist/kiwi/fig/session/worker.js +33 -8
- package/dist/kiwi/fig/session/worker.js.map +1 -1
- package/dist/layout/apply.d.ts +6 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +39 -14
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/arrange/boxes.d.ts.map +1 -1
- package/dist/layout/arrange/boxes.js +31 -0
- package/dist/layout/arrange/boxes.js.map +1 -1
- package/dist/layout/flow-edges.d.ts +26 -0
- package/dist/layout/flow-edges.d.ts.map +1 -0
- package/dist/layout/flow-edges.js +105 -0
- package/dist/layout/flow-edges.js.map +1 -0
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +9 -5
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/text-auto-resize.d.ts.map +1 -1
- package/dist/layout/text-auto-resize.js +9 -4
- package/dist/layout/text-auto-resize.js.map +1 -1
- package/dist/layout/text-measurement.d.ts +15 -1
- package/dist/layout/text-measurement.d.ts.map +1 -1
- package/dist/layout/text-measurement.js +40 -4
- package/dist/layout/text-measurement.js.map +1 -1
- package/dist/layout/variables.d.ts +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +35 -35
- package/dist/layout.js.map +1 -1
- package/dist/library/asset-keys.d.ts +3 -2
- package/dist/library/asset-keys.d.ts.map +1 -1
- package/dist/library/asset-keys.js +4 -3
- package/dist/library/asset-keys.js.map +1 -1
- package/dist/library/copied-references.d.ts +8 -3
- package/dist/library/copied-references.d.ts.map +1 -1
- package/dist/library/copied-references.js +15 -5
- package/dist/library/copied-references.js.map +1 -1
- package/dist/library/materialize.js +1 -1
- package/dist/library/materialize.js.map +1 -1
- package/dist/library/schema.js.map +1 -1
- package/dist/library/snapshot.d.ts.map +1 -1
- package/dist/library/snapshot.js +10 -2
- package/dist/library/snapshot.js.map +1 -1
- package/dist/pairdraw-api/variables.d.ts.map +1 -1
- package/dist/pairdraw-api/variables.js +0 -2
- package/dist/pairdraw-api/variables.js.map +1 -1
- package/dist/profiler/hud-controller.d.ts +4 -3
- package/dist/profiler/hud-controller.d.ts.map +1 -1
- package/dist/profiler/hud-controller.js +7 -5
- package/dist/profiler/hud-controller.js.map +1 -1
- package/dist/profiler/hud-renderer.d.ts +5 -2
- package/dist/profiler/hud-renderer.d.ts.map +1 -1
- package/dist/profiler/hud-renderer.js +8 -5
- package/dist/profiler/hud-renderer.js.map +1 -1
- package/dist/profiler/render-profiler.d.ts +3 -2
- package/dist/profiler/render-profiler.d.ts.map +1 -1
- package/dist/profiler/render-profiler.js +3 -2
- package/dist/profiler/render-profiler.js.map +1 -1
- package/dist/text/character-style.d.ts +11 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +27 -5
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/coverage.d.ts.map +1 -1
- package/dist/text/coverage.js +15 -16
- package/dist/text/coverage.js.map +1 -1
- package/dist/text/editor.d.ts.map +1 -1
- package/dist/text/editor.js +3 -8
- package/dist/text/editor.js.map +1 -1
- package/dist/text/fallbacks.d.ts +19 -2
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +63 -12
- package/dist/text/fallbacks.js.map +1 -1
- package/dist/text/font/catalog.d.ts +4 -0
- package/dist/text/font/catalog.d.ts.map +1 -1
- package/dist/text/font/catalog.js +8 -0
- package/dist/text/font/catalog.js.map +1 -1
- package/dist/text/font/collection.d.ts +13 -0
- package/dist/text/font/collection.d.ts.map +1 -0
- package/dist/text/font/collection.js +51 -0
- package/dist/text/font/collection.js.map +1 -0
- package/dist/text/font/faces.d.ts +2 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +9 -5
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/glyphs.d.ts +14 -3
- package/dist/text/font/glyphs.d.ts.map +1 -1
- package/dist/text/font/glyphs.js +22 -5
- package/dist/text/font/glyphs.js.map +1 -1
- package/dist/text/font/local.js +2 -2
- package/dist/text/font/local.js.map +1 -1
- package/dist/text/font/manager.d.ts +36 -0
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +139 -19
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/font/style.d.ts +7 -2
- package/dist/text/font/style.d.ts.map +1 -1
- package/dist/text/font/style.js +31 -3
- package/dist/text/font/style.js.map +1 -1
- package/dist/text/index.d.ts +5 -4
- package/dist/text/index.js +5 -4
- package/dist/text/outlines.d.ts.map +1 -1
- package/dist/text/outlines.js +70 -70
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +7 -1
- package/dist/text/prepare.js.map +1 -1
- package/dist/text/style-runs.d.ts +14 -2
- package/dist/text/style-runs.d.ts.map +1 -1
- package/dist/text/style-runs.js +22 -14
- package/dist/text/style-runs.js.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/helpers.js +9 -1
- package/dist/tools/analyze/overlaps/helpers.js.map +1 -1
- package/dist/tools/analyze/overlaps/index.d.ts.map +1 -1
- package/dist/tools/analyze/overlaps/index.js +27 -5
- package/dist/tools/analyze/overlaps/index.js.map +1 -1
- package/dist/tools/codegen/component-map.js +3 -3
- package/dist/tools/codegen/component-map.js.map +1 -1
- package/dist/tools/create/basic.d.ts.map +1 -1
- package/dist/tools/create/basic.js +5 -4
- package/dist/tools/create/basic.js.map +1 -1
- package/dist/tools/create/html.d.ts.map +1 -1
- package/dist/tools/create/html.js +4 -2
- package/dist/tools/create/html.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +3 -1
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/mermaid.d.ts.map +1 -1
- package/dist/tools/create/mermaid.js +2 -0
- package/dist/tools/create/mermaid.js.map +1 -1
- package/dist/tools/create/render.d.ts.map +1 -1
- package/dist/tools/create/render.js +2 -0
- package/dist/tools/create/render.js.map +1 -1
- package/dist/tools/create/script.js +3 -1
- package/dist/tools/create/script.js.map +1 -1
- package/dist/tools/create/svg.d.ts.map +1 -1
- package/dist/tools/create/svg.js +4 -1
- package/dist/tools/create/svg.js.map +1 -1
- package/dist/tools/create/vector.d.ts.map +1 -1
- package/dist/tools/create/vector.js +4 -4
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/image-ai/apply.js +1 -1
- package/dist/tools/image-ai/generate.d.ts.map +1 -1
- package/dist/tools/image-ai/generate.js +3 -0
- package/dist/tools/image-ai/generate.js.map +1 -1
- package/dist/tools/modify/matching.js +1 -1
- package/dist/tools/modify/reactions.d.ts +6 -0
- package/dist/tools/modify/reactions.d.ts.map +1 -0
- package/dist/tools/modify/reactions.js +35 -0
- package/dist/tools/modify/reactions.js.map +1 -0
- package/dist/tools/modify.d.ts +2 -1
- package/dist/tools/modify.js +2 -1
- package/dist/tools/read/components.js +20 -22
- package/dist/tools/read/components.js.map +1 -1
- package/dist/tools/read/fonts.js +1 -1
- package/dist/tools/read/fonts.js.map +1 -1
- package/dist/tools/read/libraries.d.ts.map +1 -1
- package/dist/tools/read/libraries.js +2 -0
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js +38 -16
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/read/pages.d.ts.map +1 -1
- package/dist/tools/read/pages.js +4 -3
- package/dist/tools/read/pages.js.map +1 -1
- package/dist/tools/read/query.js +1 -0
- package/dist/tools/read/query.js.map +1 -1
- package/dist/tools/read/reactions.d.ts +6 -0
- package/dist/tools/read/reactions.d.ts.map +1 -0
- package/dist/tools/read/reactions.js +24 -0
- package/dist/tools/read/reactions.js.map +1 -0
- package/dist/tools/read/space.js +1 -1
- package/dist/tools/read.d.ts +2 -1
- package/dist/tools/read.js +2 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +4 -0
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +6 -0
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +53 -9
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/stock-photo/apply.js +8 -9
- package/dist/tools/stock-photo/apply.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +85 -90
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/vector/fill-geometry.d.ts +4 -1
- package/dist/vector/fill-geometry.d.ts.map +1 -1
- package/dist/vector/fill-geometry.js +8 -5
- package/dist/vector/fill-geometry.js.map +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/vector/index.js.map +1 -1
- package/dist/vector/path-helpers.d.ts +1 -1
- package/dist/vector/path-helpers.d.ts.map +1 -1
- package/dist/vector/path-helpers.js +24 -7
- package/dist/vector/path-helpers.js.map +1 -1
- package/dist/vector/placement.js +1 -1
- package/dist/vector/placement.js.map +1 -1
- package/dist/vector/vectorize/preprocess.js +1 -1
- package/dist/vector/vectorize/preprocess.js.map +1 -1
- package/package.json +10 -10
- package/src/canvas/effects.ts +29 -33
- package/src/canvas/labels/hit-test.ts +6 -2
- package/src/canvas/labels/paragraph-cache.ts +2 -1
- package/src/canvas/labels/selection.ts +3 -3
- package/src/canvas/node-edit-overlay.ts +3 -2
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +4 -52
- package/src/canvas/region-hatch.ts +7 -2
- package/src/canvas/renderer/colors.ts +41 -26
- package/src/canvas/renderer/font-waiters.ts +25 -0
- package/src/canvas/renderer/fonts.ts +40 -17
- package/src/canvas/renderer/lifecycle.ts +8 -10
- package/src/canvas/renderer/methods.ts +9 -13
- package/src/canvas/renderer/paints.ts +0 -10
- package/src/canvas/renderer/pipeline.ts +29 -3
- package/src/canvas/renderer/retained-backing.ts +4 -4
- package/src/canvas/renderer/state.ts +1 -1
- package/src/canvas/renderer/tiles/controller.ts +8 -0
- package/src/canvas/renderer/tiles/surface-pool.ts +1 -1
- package/src/canvas/renderer/visual-bounds.ts +7 -6
- package/src/canvas/renderer.ts +39 -11
- package/src/canvas/rulers.ts +55 -26
- package/src/canvas/scene.ts +37 -16
- package/src/canvas/shadows/shape.ts +1 -1
- package/src/canvas/shadows/silhouette.ts +4 -2
- package/src/canvas/shadows.ts +4 -2
- package/src/canvas/text/derived.ts +0 -9
- package/src/canvas/text/emoji/raster.ts +14 -10
- package/src/canvas/text/font-families.ts +6 -0
- package/src/canvas/text/index.ts +0 -8
- package/src/canvas/text/layout/build.ts +35 -18
- package/src/canvas/text/layout/index.ts +15 -6
- package/src/canvas/text/layout/lines.ts +10 -4
- package/src/canvas/text/paragraph/index.ts +17 -8
- package/src/canvas/text/paragraph/inputs.ts +4 -2
- package/src/canvas/text/shape.ts +20 -31
- package/src/constants.ts +6 -1
- package/src/editor/bridges/clipboard.ts +1 -0
- package/src/editor/bridges/components.ts +2 -0
- package/src/editor/bridges/frames.ts +6 -4
- package/src/editor/bridges/structure.ts +1 -0
- package/src/editor/clipboard/detach.ts +3 -3
- package/src/editor/clipboard/paste/target.ts +2 -2
- package/src/editor/clipboard/snapshot.ts +7 -0
- package/src/editor/clipboard/variables.ts +20 -0
- package/src/editor/clipboard.ts +133 -14
- package/src/editor/component-sync.ts +28 -7
- package/src/editor/components/authoring/text-edit.ts +15 -2
- package/src/editor/components/authoring/visibility-edit.ts +11 -3
- package/src/editor/components/instances.ts +61 -11
- package/src/editor/components/properties.ts +10 -0
- package/src/editor/components/slots/authoring.ts +4 -1
- package/src/editor/create.ts +58 -8
- package/src/editor/guides.ts +27 -12
- package/src/editor/history/document-change.ts +115 -7
- package/src/editor/history/edit.ts +62 -14
- package/src/editor/history/position.ts +1 -4
- package/src/editor/history/sources.ts +25 -0
- package/src/editor/index.ts +3 -1
- package/src/editor/layout-mode.ts +20 -1
- package/src/editor/node-preview.ts +44 -8
- package/src/editor/nodes.ts +52 -12
- package/src/editor/nudge.ts +16 -2
- package/src/editor/pages.ts +100 -17
- package/src/editor/play/states.ts +0 -7
- package/src/editor/read-only/actions.ts +4 -0
- package/src/editor/selection/hit-test.ts +37 -4
- package/src/editor/shapes/pen.ts +6 -3
- package/src/editor/shapes.ts +2 -1
- package/src/editor/structure/auto-layout-wrap.ts +26 -0
- package/src/editor/structure/group/bounds.ts +22 -4
- package/src/editor/structure/rename.ts +2 -6
- package/src/editor/structure/reorder.ts +26 -8
- package/src/editor/structure.ts +88 -24
- package/src/editor/text/hyperlink.ts +2 -1
- package/src/editor/text/name.ts +51 -15
- package/src/editor/text/pending-layout.ts +42 -4
- package/src/editor/text/selection-style.ts +17 -3
- package/src/editor/text.ts +86 -4
- package/src/editor/types.ts +19 -0
- package/src/editor/undo.ts +21 -2
- package/src/editor/variable-bindings.ts +22 -2
- package/src/editor/variables.ts +10 -6
- package/src/editor/viewport.ts +55 -21
- package/src/editor/views/actions.ts +17 -7
- package/src/editor/views/present.ts +20 -11
- package/src/editor/views/types.ts +11 -5
- package/src/figma-api/accessor-utils.ts +4 -1
- package/src/figma-api/accessors/basic.ts +54 -18
- package/src/figma-api/accessors/layout.ts +46 -7
- package/src/figma-api/accessors/reactions.ts +29 -0
- package/src/figma-api/accessors/strokes.ts +28 -8
- package/src/figma-api/accessors/text/index.ts +4 -0
- package/src/figma-api/accessors/vector.ts +3 -1
- package/src/figma-api/accessors/visual.ts +25 -28
- package/src/figma-api/components.ts +9 -7
- package/src/figma-api/finite.ts +102 -0
- package/src/figma-api/fonts/list.ts +24 -0
- package/src/figma-api/index.ts +82 -12
- package/src/figma-api/overrides.ts +1 -1
- package/src/figma-api/pending-layout.ts +50 -1
- package/src/figma-api/pending-sync.ts +61 -0
- package/src/figma-api/proxy.ts +35 -2
- package/src/figma-api/reactions.ts +212 -0
- package/src/figma-api/render-bounds.ts +13 -4
- package/src/figma-api/serialization.ts +2 -2
- package/src/figma-api/slots.ts +12 -3
- package/src/figma-api/strokes.ts +16 -12
- package/src/figma-api/text/index.ts +9 -15
- package/src/figma-api/variables/variable.ts +3 -2
- package/src/geometry/figma.ts +9 -0
- package/src/geometry/index.ts +1 -0
- package/src/global.d.ts +6 -0
- package/src/icons/api.ts +27 -16
- package/src/icons/provider.ts +9 -20
- package/src/icons/schema.ts +31 -0
- package/src/icons/svg/presentation.ts +27 -3
- package/src/icons/svg/text.ts +1 -1
- package/src/icons/svg.ts +21 -19
- package/src/icons/types.ts +0 -14
- package/src/io/formats/design-tokens/plan/index.ts +7 -1
- package/src/io/formats/design-tokens/plan/styles.ts +40 -4
- package/src/io/formats/design-tokens/styles.ts +60 -3
- package/src/io/formats/design-tokens/types.ts +3 -0
- package/src/io/formats/fig/export/setup.ts +16 -14
- package/src/io/formats/fig/export/variables.ts +7 -8
- package/src/io/formats/fig/index.ts +1 -0
- package/src/io/formats/fig/read.ts +66 -23
- package/src/io/formats/html/index.ts +2 -6
- package/src/io/formats/pdf/dom.ts +96 -3
- package/src/io/formats/pen/fonts.ts +45 -0
- package/src/io/formats/pen/index.ts +30 -6
- package/src/io/formats/raster/headless.ts +31 -12
- package/src/io/formats/raster/index.ts +3 -0
- package/src/io/formats/raster/render.ts +62 -6
- package/src/io/formats/svg/export.ts +24 -25
- package/src/io/formats/svg/paths.ts +11 -2
- package/src/io/formats/svg/strokes.ts +8 -2
- package/src/io/formats/svg/text/export.ts +23 -0
- package/src/io/formats/svg/text/import.ts +2 -1
- package/src/io/subgraph.ts +3 -1
- package/src/kiwi/fig/population/client.ts +77 -43
- package/src/kiwi/fig/population/delta.ts +141 -18
- package/src/kiwi/fig/population/edits.ts +235 -0
- package/src/kiwi/fig/session/archive/access.ts +15 -0
- package/src/kiwi/fig/session/archive/changes.ts +27 -6
- package/src/kiwi/fig/session/document-state.ts +23 -1
- package/src/kiwi/fig/session/protocol.ts +26 -1
- package/src/kiwi/fig/session/worker.ts +38 -11
- package/src/layout/apply.ts +52 -10
- package/src/layout/arrange/boxes.ts +36 -0
- package/src/layout/flow-edges.ts +139 -0
- package/src/layout/grid.ts +14 -4
- package/src/layout/text-auto-resize.ts +13 -4
- package/src/layout/text-measurement.ts +46 -3
- package/src/layout.ts +60 -66
- package/src/library/asset-keys.ts +4 -3
- package/src/library/copied-references.ts +29 -5
- package/src/library/materialize.ts +1 -1
- package/src/library/schema.ts +1 -1
- package/src/library/snapshot.ts +11 -2
- package/src/pairdraw-api/variables.ts +1 -3
- package/src/profiler/hud-controller.ts +8 -6
- package/src/profiler/hud-renderer.ts +9 -6
- package/src/profiler/render-profiler.ts +4 -3
- package/src/text/character-style.ts +29 -9
- package/src/text/coverage.ts +17 -18
- package/src/text/editor.ts +3 -8
- package/src/text/fallbacks.ts +82 -15
- package/src/text/font/catalog.ts +10 -0
- package/src/text/font/collection.ts +60 -0
- package/src/text/font/faces.ts +9 -5
- package/src/text/font/glyphs.ts +29 -4
- package/src/text/font/local.ts +2 -2
- package/src/text/font/manager.ts +170 -32
- package/src/text/font/style.ts +52 -3
- package/src/text/index.ts +1 -0
- package/src/text/outlines.ts +105 -89
- package/src/text/prepare.ts +17 -0
- package/src/text/style-runs.ts +43 -16
- package/src/tools/analyze/overlaps/helpers.ts +18 -1
- package/src/tools/analyze/overlaps/index.ts +37 -6
- package/src/tools/codegen/component-map.ts +3 -3
- package/src/tools/create/basic.ts +6 -4
- package/src/tools/create/html.ts +3 -1
- package/src/tools/create/icons.ts +3 -1
- package/src/tools/create/mermaid.ts +2 -0
- package/src/tools/create/render.ts +2 -0
- package/src/tools/create/script.ts +5 -1
- package/src/tools/create/svg.ts +4 -1
- package/src/tools/create/vector.ts +4 -4
- package/src/tools/image-ai/generate.ts +3 -0
- package/src/tools/modify/reactions.ts +40 -0
- package/src/tools/modify.ts +1 -0
- package/src/tools/read/components.ts +28 -25
- package/src/tools/read/fonts.ts +1 -1
- package/src/tools/read/libraries.ts +3 -0
- package/src/tools/read/nodes.ts +47 -17
- package/src/tools/read/pages.ts +7 -4
- package/src/tools/read/query.ts +2 -0
- package/src/tools/read/reactions.ts +21 -0
- package/src/tools/read.ts +1 -0
- package/src/tools/registry/extended.ts +4 -0
- package/src/tools/schema.ts +68 -12
- package/src/tools/stock-photo/apply.ts +17 -5
- package/src/tools/structure/batch.ts +82 -101
- package/src/vector/fill-geometry.ts +11 -5
- package/src/vector/index.ts +1 -1
- package/src/vector/path-helpers.ts +34 -8
- package/src/vector/placement.ts +1 -1
- package/src/vector/vectorize/preprocess.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/canvas/shadows.ts"],"sourcesContent":["import type { Canvas, ImageFilter } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { nodeOrientationMatrix } from '#core/geometry'\n\nimport { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'\nimport { makeBooleanOperationPath } from './boolean'\nimport { blurSigma, renderNoiseEffects } from './effects'\nimport type { SkiaRenderer } from './renderer'\nimport {\n castsFromOwnShape,\n castsOwnShapeDropShadow,\n clipOutShapeKnockout,\n drawOutlineDropShadow,\n drawRingDropShadow,\n drawShapeDropShadow,\n drawShapeInnerShadow,\n regularStrokeOutline,\n strokeGrowsOutline\n} from './shadows/shape'\nimport {\n drawSilhouette,\n fillsCastShadow,\n isLayerContainer,\n paintsCastShadow,\n paintsOverKnockout,\n shadowIncludesChildren,\n silhouetteBounds,\n separateShadowChildren\n} from './shadows/silhouette'\nfunction resetEffectLayerPaint(r: SkiaRenderer): void {\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)\n}\n\n/** `behind` draws drop shadows and background blur, `inner` inner shadows over fills, `front` noise. */\nexport type EffectPass = 'behind' | 'inner' | 'front'\n\n/**\n * Layers whose shadows Figma 126 never spreads: only boxes and ellipses, arcs among them, take a\n * spread, for drop and inner shadows alike.\n */\nconst UNSPREAD_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'TEXT',\n 'BOOLEAN_OPERATION',\n 'STAR',\n 'POLYGON',\n 'VECTOR'\n])\n\n/** Figma spreads a shadow only where it follows the layer's own outline: shapes and filled frames that clip. */\nfunction shadowSpread(node: SceneNode, effect: ShadowEffect): number {\n if (UNSPREAD_TYPES.has(node.type)) return 0\n if (!isLayerContainer(node)) return effect.spread\n return node.clipsContent && fillsCastShadow(node) ? effect.spread : 0\n}\n\n/** The spread an inner shadow takes, inside any layer whose type Figma spreads. */\nfunction innerShadowSpread(node: SceneNode, effect: ShadowEffect): number {\n return UNSPREAD_TYPES.has(node.type) ? 0 : effect.spread\n}\n\nfunction shadowLayerBounds(\n r: SkiaRenderer,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n includeChildren: boolean\n): Float32Array {\n const box = silhouetteBounds(graph, node, includeChildren) ?? {\n x: 0,\n y: 0,\n width: node.width,\n height: node.height\n }\n const offset = effect.offset\n const padding = effect.radius * 2 + Math.abs(spread)\n return r.ck.LTRBRect(\n box.x + Math.min(0, offset.x) - padding,\n box.y + Math.min(0, offset.y) - padding,\n box.x + box.width + Math.max(0, offset.x) + padding,\n box.y + box.height + Math.max(0, offset.y) + padding\n )\n}\n\n/** Grows or shrinks a silhouette by the spread, square as Figma spreads a rectangle. */\nfunction spreadFilter(r: SkiaRenderer, spread: number): ImageFilter | null {\n if (spread > 0) return r.ck.ImageFilter.MakeDilate(spread, spread, null)\n if (spread < 0) return r.ck.ImageFilter.MakeErode(-spread, -spread, null)\n return null\n}\n\n/** Draws a shadow cast by whatever `draw` paints: its alpha is the outline, offset and blurred. */\nfunction drawSilhouetteDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n spread: number,\n bounds: Float32Array,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n const ck = r.ck\n const color = ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)\n const sigma = blurSigma(effect.radius)\n const morphology = spreadFilter(r, spread)\n const filter = morphology\n ? ck.ImageFilter.MakeDropShadowOnly(\n effect.offset.x,\n effect.offset.y,\n sigma,\n sigma,\n color,\n morphology\n )\n : r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color)\n const paint = new ck.Paint()\n paint.setImageFilter(filter)\n setPaintBlendMode(r, paint, blendMode)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n if (morphology) {\n filter.delete()\n morphology.delete()\n }\n }\n}\n\nfunction drawKnockout(r: SkiaRenderer, canvas: Canvas, bounds: Float32Array, draw: () => void) {\n const paint = new r.ck.Paint()\n paint.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n }\n}\n\n/**\n * Draws a shadow cast by the node's own outline without a layer, when that outline is a shape\n * grown by its stroke; false when the node needs its silhouette drawn instead.\n */\nfunction drawOwnShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined,\n knockout: boolean\n): boolean {\n const outline = regularStrokeOutline(node, spread)\n if (!outline && !castsFromOwnShape(node)) return false\n const castsFill = fillsCastShadow(node)\n canvas.save()\n try {\n if (knockout) clipOutShapeKnockout(r, canvas, node, outline)\n if (castsFill && outline && strokeGrowsOutline(outline)) {\n drawOutlineDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n } else if (castsFill) {\n drawShapeDropShadow(r, canvas, node, effect, spread, blendMode)\n } else if (outline) {\n drawRingDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n }\n } finally {\n canvas.restore()\n }\n return true\n}\n\n/**\n * How far apart a container's children must be for their shadows to reach neither each other nor\n * another child: the blur's reach from both, any spread, and the offset.\n */\nfunction shadowGap(effect: ShadowEffect, spread: number): number {\n const reach = 3 * blurSigma(effect.radius) + Math.abs(spread) + 1\n return 2 * reach + Math.hypot(effect.offset.x, effect.offset.y)\n}\n\n/**\n * Draws a shadow cast by `child`, in its parent's coordinates. The parent's effect is drawn in the\n * child's own space, so its offset is turned back by the child's rotation and flips; blur and\n * spread are the same in every direction.\n */\nfunction withChildCoordinates<T>(\n canvas: Canvas,\n child: SceneNode,\n effect: ShadowEffect,\n draw: (local: ShadowEffect) => T\n): T {\n const orientation = nodeOrientationMatrix(child)\n const inverse = Matrix.invert(orientation) ?? Matrix.identity()\n const origin = Matrix.mapPoint(inverse, { x: 0, y: 0 })\n const offset = Matrix.mapPoint(inverse, effect.offset)\n canvas.save()\n try {\n canvas.translate(child.x, child.y)\n canvas.concat(orientation)\n return draw({ ...effect, offset: { x: offset.x - origin.x, y: offset.y - origin.y } })\n } finally {\n canvas.restore()\n }\n}\n\nfunction renderDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const spread = shadowSpread(node, effect)\n const blendMode = effect.blendMode\n const knockout =\n effect.showShadowBehindNode === false && !paintsOverKnockout(graph, node, includeChildren)\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, spread))\n : null\n if (children?.every((child) => castsOwnShapeDropShadow(child, spread))) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawOwnShapeDropShadow(r, canvas, child, local, spread, blendMode, knockout)\n )\n }\n return\n }\n if (\n !includeChildren &&\n drawOwnShapeDropShadow(r, canvas, node, effect, spread, blendMode, knockout)\n ) {\n return\n }\n\n const bounds = shadowLayerBounds(r, graph, node, effect, spread, includeChildren)\n const isolation = knockout ? new r.ck.Paint() : null\n if (isolation) {\n setPaintBlendMode(r, isolation, blendMode)\n canvas.saveLayer(isolation, bounds)\n }\n try {\n drawSilhouetteDropShadow(\n r,\n canvas,\n effect,\n spread,\n bounds,\n isolation ? 'NORMAL' : blendMode,\n () => drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n if (knockout) {\n drawKnockout(r, canvas, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'knockout', includeChildren)\n )\n }\n } finally {\n if (isolation) {\n canvas.restore()\n isolation.delete()\n }\n resetEffectLayerPaint(r)\n }\n}\n\n/** Draws an inner shadow inside whatever `draw` paints, cut from an offset, blurred inverse of it. */\nfunction drawSilhouetteInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n bounds: Float32Array,\n draw: () => void\n): void {\n const ck = r.ck\n\n resetEffectLayerPaint(r)\n let restoreCount = 0\n let tintFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n let solidBlackFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n\n try {\n setPaintBlendMode(r, r.effectLayerPaint, effect.blendMode)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n draw()\n\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcIn)\n tintFilter = ck.ColorFilter.MakeBlend(\n ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a),\n ck.BlendMode.SrcIn\n )\n r.effectLayerPaint.setColorFilter(tintFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n\n canvas.save()\n restoreCount++\n canvas.translate(effect.offset.x, effect.offset.y)\n\n // The inverse is drawn in offset coordinates, so it covers `bounds` once shifted back.\n const { x: dx, y: dy } = effect.offset\n const inverse = ck.LTRBRect(bounds[0] - dx, bounds[1] - dy, bounds[2] - dx, bounds[3] - dy)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n canvas.saveLayer(r.effectLayerPaint, inverse)\n restoreCount++\n\n r.auxFill.setColor(ck.Color4f(0, 0, 0, 1))\n canvas.drawRect(inverse, r.auxFill)\n\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.DstOut)\n solidBlackFilter = ck.ColorFilter.MakeBlend(ck.Color4f(0, 0, 0, 1), ck.BlendMode.SrcIn)\n r.effectLayerPaint.setColorFilter(solidBlackFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n draw()\n } finally {\n while (restoreCount > 0) {\n canvas.restore()\n restoreCount--\n }\n r.effectLayerPaint.setColorFilter(null)\n if (solidBlackFilter) solidBlackFilter.delete()\n if (tintFilter) tintFilter.delete()\n resetEffectLayerPaint(r)\n }\n}\n\nfunction renderInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, 0))\n : null\n if (children?.every(castsFromOwnShape)) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawShapeInnerShadow(r, canvas, child, local, innerShadowSpread(child, local))\n )\n }\n return\n }\n if (!includeChildren && castsFromOwnShape(node)) {\n const spread = innerShadowSpread(node, effect)\n drawShapeInnerShadow(r, canvas, node, effect, spread, isolatesInnerShadows(node))\n return\n }\n const bounds = shadowLayerBounds(r, graph, node, effect, 0, includeChildren)\n drawSilhouetteInnerShadow(r, canvas, effect, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n}\n\n/**\n * Whether a shape draws its fills and inner shadows in a layer of their own. There each shadow\n * replaces the fill under it before taking the shape's outline, so the antialiased edge applies\n * once, as in Figma, rather than letting the fill show through. Blended fills and shadows mix with\n * what lies under the shape, so they keep drawing in place.\n */\nexport function isolatesInnerShadows(node: SceneNode): boolean {\n if (isLayerContainer(node) || !castsFromOwnShape(node)) return false\n const shadows = node.effects.filter((effect) => effect.visible && effect.type === 'INNER_SHADOW')\n return (\n shadows.length > 0 &&\n shadows.every((effect) => !needsIsolatedBlendLayer(effect.blendMode)) &&\n [...node.fills, ...node.fillGeometry.flatMap((geometry) => geometry.fills ?? [])].every(\n (fill) => !fill.visible || !needsIsolatedBlendLayer(fill.blendMode)\n )\n )\n}\n\n/**\n * Draws a shape's own effects. Frames, groups, and other containers take their shadows from\n * `renderLayerShadows` instead, because Figma casts them from the children as well.\n */\nexport function renderEffects(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n graph: SceneGraph,\n pass: EffectPass\n): void {\n // Noise draws per pixel and a background blur reads back what is behind; both are left out\n // while the renderer keeps effects cheap.\n if (pass === 'front' && !r.effectsReduced) renderNoiseEffects(r, canvas, node)\n\n const ownShadows = !isLayerContainer(node)\n for (const effect of node.effects) {\n if (!effect.visible) continue\n\n if (pass === 'behind' && effect.type === 'DROP_SHADOW' && ownShadows) {\n renderDropShadow(r, canvas, graph, node, effect, false)\n }\n\n if (pass === 'behind' && effect.type === 'BACKGROUND_BLUR' && !r.effectsReduced) {\n const shape =\n node.type === 'BOOLEAN_OPERATION' ? makeBooleanOperationPath(r, node, graph) : null\n r.applyClippedBlur(canvas, node, blurSigma(effect.radius), shape)\n shape?.delete()\n }\n\n if (pass === 'inner' && effect.type === 'INNER_SHADOW' && ownShadows) {\n renderInnerShadow(r, canvas, graph, node, effect, false)\n }\n }\n}\n\n/**\n * Draws a container's drop shadows before it (`behind`) and its inner shadows over its fills,\n * strokes, and children (`front`), cast from the children too unless its own fill covers them.\n */\nexport function renderLayerShadows(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n pass: 'behind' | 'front'\n): void {\n if (!isLayerContainer(node)) return\n const effects = node.effects.filter(\n (effect): effect is ShadowEffect =>\n effect.visible && effect.type === (pass === 'behind' ? 'DROP_SHADOW' : 'INNER_SHADOW')\n )\n if (effects.length === 0) return\n const includeChildren = shadowIncludesChildren(graph, node)\n for (const effect of effects) {\n if (pass === 'behind') renderDropShadow(r, canvas, graph, node, effect, includeChildren)\n else renderInnerShadow(r, canvas, graph, node, effect, includeChildren)\n }\n}\n"],"mappings":";;;;;;;;AAgCA,SAAS,sBAAsB,GAAuB;CACpD,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,aAAa,EAAE,GAAG,UAAU,OAAO;AACxD;;;;;AASA,MAAM,iCAAiD,IAAI,IAAuB;CAChF;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,aAAa,MAAiB,QAA8B;CACnE,IAAI,eAAe,IAAI,KAAK,IAAI,GAAG,OAAO;CAC1C,IAAI,CAAC,iBAAiB,IAAI,GAAG,OAAO,OAAO;CAC3C,OAAO,KAAK,gBAAgB,gBAAgB,IAAI,IAAI,OAAO,SAAS;AACtE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AAMA,SAAgB,mBACd,GACA,QACA,OACA,MACA,MACM;CACN,IAAI,CAAC,iBAAiB,IAAI,GAAG;CAC7B,MAAM,UAAU,KAAK,QAAQ,QAC1B,WACC,OAAO,WAAW,OAAO,UAAU,SAAS,WAAW,gBAAgB,eAC3E;CACA,IAAI,QAAQ,WAAW,GAAG;CAC1B,MAAM,kBAAkB,uBAAuB,OAAO,IAAI;CAC1D,KAAK,MAAM,UAAU,SACnB,IAAI,SAAS,UAAU,iBAAiB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;MAClF,kBAAkB,GAAG,QAAQ,OAAO,MAAM,QAAQ,eAAe;AAE1E"}
|
|
1
|
+
{"version":3,"file":"shadows.js","names":[],"sources":["../../src/canvas/shadows.ts"],"sourcesContent":["import type { Canvas, ImageFilter } from 'canvaskit-wasm'\n\nimport type { BlendMode, ShadowEffect, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { blurSigma } from '@pairdraw/scene-graph/geometry'\nimport Matrix from '@pairdraw/scene-graph/matrix'\n\nimport { nodeOrientationMatrix } from '#core/geometry'\n\nimport { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'\nimport { makeBooleanOperationPath } from './boolean'\nimport { renderNoiseEffects } from './effects'\nimport type { SkiaRenderer } from './renderer'\nimport {\n castsFromOwnShape,\n castsOwnShapeDropShadow,\n clipOutShapeKnockout,\n drawOutlineDropShadow,\n drawRingDropShadow,\n drawShapeDropShadow,\n drawShapeInnerShadow,\n regularStrokeOutline,\n strokeGrowsOutline\n} from './shadows/shape'\nimport {\n drawSilhouette,\n fillsCastShadow,\n isLayerContainer,\n paintsCastShadow,\n paintsOverKnockout,\n shadowIncludesChildren,\n silhouetteBounds,\n separateShadowChildren\n} from './shadows/silhouette'\nfunction resetEffectLayerPaint(r: SkiaRenderer): void {\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setBlendMode(r.ck.BlendMode.SrcOver)\n}\n\n/** `behind` draws drop shadows and background blur, `inner` inner shadows over fills, `front` noise. */\nexport type EffectPass = 'behind' | 'inner' | 'front'\n\n/**\n * Layers whose shadows Figma 126 never spreads: only boxes and ellipses, arcs among them, take a\n * spread, for drop and inner shadows alike.\n */\nconst UNSPREAD_TYPES: ReadonlySet<SceneNode['type']> = new Set<SceneNode['type']>([\n 'TEXT',\n 'BOOLEAN_OPERATION',\n 'STAR',\n 'POLYGON',\n 'VECTOR'\n])\n\n/** Figma spreads a shadow only where it follows the layer's own outline: shapes and filled frames that clip. */\nfunction shadowSpread(node: SceneNode, effect: ShadowEffect): number {\n if (UNSPREAD_TYPES.has(node.type)) return 0\n if (!isLayerContainer(node)) return effect.spread\n return node.clipsContent && fillsCastShadow(node) ? effect.spread : 0\n}\n\n/** The spread an inner shadow takes, inside any layer whose type Figma spreads. */\nfunction innerShadowSpread(node: SceneNode, effect: ShadowEffect): number {\n return UNSPREAD_TYPES.has(node.type) ? 0 : effect.spread\n}\n\nfunction shadowLayerBounds(\n r: SkiaRenderer,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n includeChildren: boolean\n): Float32Array {\n const box = silhouetteBounds(graph, node, includeChildren) ?? {\n x: 0,\n y: 0,\n width: node.width,\n height: node.height\n }\n const offset = effect.offset\n const padding = effect.radius * 2 + Math.abs(spread)\n return r.ck.LTRBRect(\n box.x + Math.min(0, offset.x) - padding,\n box.y + Math.min(0, offset.y) - padding,\n box.x + box.width + Math.max(0, offset.x) + padding,\n box.y + box.height + Math.max(0, offset.y) + padding\n )\n}\n\n/** Grows or shrinks a silhouette by the spread, square as Figma spreads a rectangle. */\nfunction spreadFilter(r: SkiaRenderer, spread: number): ImageFilter | null {\n if (spread > 0) return r.ck.ImageFilter.MakeDilate(spread, spread, null)\n if (spread < 0) return r.ck.ImageFilter.MakeErode(-spread, -spread, null)\n return null\n}\n\n/** Draws a shadow cast by whatever `draw` paints: its alpha is the outline, offset and blurred. */\nfunction drawSilhouetteDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n spread: number,\n bounds: Float32Array,\n blendMode: BlendMode | undefined,\n draw: () => void\n): void {\n const ck = r.ck\n const color = ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)\n const sigma = blurSigma(effect.radius)\n const morphology = spreadFilter(r, spread)\n const filter = morphology\n ? ck.ImageFilter.MakeDropShadowOnly(\n effect.offset.x,\n effect.offset.y,\n sigma,\n sigma,\n color,\n morphology\n )\n : r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color)\n const paint = new ck.Paint()\n paint.setImageFilter(filter)\n setPaintBlendMode(r, paint, blendMode)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n if (morphology) {\n // The filter built with the morphology is ours; a zero sigma hands back none.\n filter?.delete()\n morphology.delete()\n }\n }\n}\n\nfunction drawKnockout(r: SkiaRenderer, canvas: Canvas, bounds: Float32Array, draw: () => void) {\n const paint = new r.ck.Paint()\n paint.setBlendMode(r.ck.BlendMode.DstOut)\n canvas.saveLayer(paint, bounds)\n try {\n draw()\n } finally {\n canvas.restore()\n paint.delete()\n }\n}\n\n/**\n * Draws a shadow cast by the node's own outline without a layer, when that outline is a shape\n * grown by its stroke; false when the node needs its silhouette drawn instead.\n */\nfunction drawOwnShapeDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n effect: ShadowEffect,\n spread: number,\n blendMode: BlendMode | undefined,\n knockout: boolean\n): boolean {\n const outline = regularStrokeOutline(node, spread)\n if (!outline && !castsFromOwnShape(node)) return false\n const castsFill = fillsCastShadow(node)\n canvas.save()\n try {\n if (knockout) clipOutShapeKnockout(r, canvas, node, outline)\n if (castsFill && outline && strokeGrowsOutline(outline)) {\n drawOutlineDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n } else if (castsFill) {\n drawShapeDropShadow(r, canvas, node, effect, spread, blendMode)\n } else if (outline) {\n drawRingDropShadow(r, canvas, node, effect, outline, spread, blendMode)\n }\n } finally {\n canvas.restore()\n }\n return true\n}\n\n/**\n * How far apart a container's children must be for their shadows to reach neither each other nor\n * another child: the blur's reach from both, any spread, and the offset.\n */\nfunction shadowGap(effect: ShadowEffect, spread: number): number {\n const reach = 3 * blurSigma(effect.radius) + Math.abs(spread) + 1\n return 2 * reach + Math.hypot(effect.offset.x, effect.offset.y)\n}\n\n/**\n * Draws a shadow cast by `child`, in its parent's coordinates. The parent's effect is drawn in the\n * child's own space, so its offset is turned back by the child's rotation and flips; blur and\n * spread are the same in every direction.\n */\nfunction withChildCoordinates<T>(\n canvas: Canvas,\n child: SceneNode,\n effect: ShadowEffect,\n draw: (local: ShadowEffect) => T\n): T {\n const orientation = nodeOrientationMatrix(child)\n const inverse = Matrix.invert(orientation) ?? Matrix.identity()\n const origin = Matrix.mapPoint(inverse, { x: 0, y: 0 })\n const offset = Matrix.mapPoint(inverse, effect.offset)\n canvas.save()\n try {\n canvas.translate(child.x, child.y)\n canvas.concat(orientation)\n return draw({ ...effect, offset: { x: offset.x - origin.x, y: offset.y - origin.y } })\n } finally {\n canvas.restore()\n }\n}\n\nfunction renderDropShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const spread = shadowSpread(node, effect)\n const blendMode = effect.blendMode\n const knockout =\n effect.showShadowBehindNode === false && !paintsOverKnockout(graph, node, includeChildren)\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, spread))\n : null\n if (children?.every((child) => castsOwnShapeDropShadow(child, spread))) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawOwnShapeDropShadow(r, canvas, child, local, spread, blendMode, knockout)\n )\n }\n return\n }\n if (\n !includeChildren &&\n drawOwnShapeDropShadow(r, canvas, node, effect, spread, blendMode, knockout)\n ) {\n return\n }\n\n const bounds = shadowLayerBounds(r, graph, node, effect, spread, includeChildren)\n const isolation = knockout ? new r.ck.Paint() : null\n if (isolation) {\n setPaintBlendMode(r, isolation, blendMode)\n canvas.saveLayer(isolation, bounds)\n }\n try {\n drawSilhouetteDropShadow(\n r,\n canvas,\n effect,\n spread,\n bounds,\n isolation ? 'NORMAL' : blendMode,\n () => drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n if (knockout) {\n drawKnockout(r, canvas, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'knockout', includeChildren)\n )\n }\n } finally {\n if (isolation) {\n canvas.restore()\n isolation.delete()\n }\n resetEffectLayerPaint(r)\n }\n}\n\n/** Draws an inner shadow inside whatever `draw` paints, cut from an offset, blurred inverse of it. */\nfunction drawSilhouetteInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n effect: ShadowEffect,\n bounds: Float32Array,\n draw: () => void\n): void {\n const ck = r.ck\n\n resetEffectLayerPaint(r)\n let restoreCount = 0\n let tintFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n let solidBlackFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null\n\n try {\n setPaintBlendMode(r, r.effectLayerPaint, effect.blendMode)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n draw()\n\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcIn)\n tintFilter = ck.ColorFilter.MakeBlend(\n ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a),\n ck.BlendMode.SrcIn\n )\n r.effectLayerPaint.setColorFilter(tintFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n\n canvas.save()\n restoreCount++\n canvas.translate(effect.offset.x, effect.offset.y)\n\n // The inverse is drawn in offset coordinates, so it covers `bounds` once shifted back.\n const { x: dx, y: dy } = effect.offset\n const inverse = ck.LTRBRect(bounds[0] - dx, bounds[1] - dy, bounds[2] - dx, bounds[3] - dy)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)\n r.effectLayerPaint.setColorFilter(null)\n r.effectLayerPaint.setImageFilter(r.getCachedDecalBlur(blurSigma(effect.radius)))\n canvas.saveLayer(r.effectLayerPaint, inverse)\n restoreCount++\n\n r.auxFill.setColor(ck.Color4f(0, 0, 0, 1))\n canvas.drawRect(inverse, r.auxFill)\n\n r.effectLayerPaint.setImageFilter(null)\n r.effectLayerPaint.setBlendMode(ck.BlendMode.DstOut)\n solidBlackFilter = ck.ColorFilter.MakeBlend(ck.Color4f(0, 0, 0, 1), ck.BlendMode.SrcIn)\n r.effectLayerPaint.setColorFilter(solidBlackFilter)\n canvas.saveLayer(r.effectLayerPaint, bounds)\n restoreCount++\n draw()\n } finally {\n while (restoreCount > 0) {\n canvas.restore()\n restoreCount--\n }\n r.effectLayerPaint.setColorFilter(null)\n if (solidBlackFilter) solidBlackFilter.delete()\n if (tintFilter) tintFilter.delete()\n resetEffectLayerPaint(r)\n }\n}\n\nfunction renderInnerShadow(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n effect: ShadowEffect,\n includeChildren: boolean\n): void {\n if (!includeChildren && !paintsCastShadow(node)) return\n const children = includeChildren\n ? separateShadowChildren(graph, node, shadowGap(effect, 0))\n : null\n if (children?.every(castsFromOwnShape)) {\n for (const child of children) {\n withChildCoordinates(canvas, child, effect, (local) =>\n drawShapeInnerShadow(r, canvas, child, local, innerShadowSpread(child, local))\n )\n }\n return\n }\n if (!includeChildren && castsFromOwnShape(node)) {\n const spread = innerShadowSpread(node, effect)\n drawShapeInnerShadow(r, canvas, node, effect, spread, isolatesInnerShadows(node))\n return\n }\n const bounds = shadowLayerBounds(r, graph, node, effect, 0, includeChildren)\n drawSilhouetteInnerShadow(r, canvas, effect, bounds, () =>\n drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)\n )\n}\n\n/**\n * Whether a shape draws its fills and inner shadows in a layer of their own. There each shadow\n * replaces the fill under it before taking the shape's outline, so the antialiased edge applies\n * once, as in Figma, rather than letting the fill show through. Blended fills and shadows mix with\n * what lies under the shape, so they keep drawing in place.\n */\nexport function isolatesInnerShadows(node: SceneNode): boolean {\n if (isLayerContainer(node) || !castsFromOwnShape(node)) return false\n const shadows = node.effects.filter((effect) => effect.visible && effect.type === 'INNER_SHADOW')\n return (\n shadows.length > 0 &&\n shadows.every((effect) => !needsIsolatedBlendLayer(effect.blendMode)) &&\n [...node.fills, ...node.fillGeometry.flatMap((geometry) => geometry.fills ?? [])].every(\n (fill) => !fill.visible || !needsIsolatedBlendLayer(fill.blendMode)\n )\n )\n}\n\n/**\n * Draws a shape's own effects. Frames, groups, and other containers take their shadows from\n * `renderLayerShadows` instead, because Figma casts them from the children as well.\n */\nexport function renderEffects(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n graph: SceneGraph,\n pass: EffectPass\n): void {\n // Noise draws per pixel and a background blur reads back what is behind; both are left out\n // while the renderer keeps effects cheap.\n if (pass === 'front' && !r.effectsReduced) renderNoiseEffects(r, canvas, node)\n\n const ownShadows = !isLayerContainer(node)\n for (const effect of node.effects) {\n if (!effect.visible) continue\n\n if (pass === 'behind' && effect.type === 'DROP_SHADOW' && ownShadows) {\n renderDropShadow(r, canvas, graph, node, effect, false)\n }\n\n if (pass === 'behind' && effect.type === 'BACKGROUND_BLUR' && !r.effectsReduced) {\n const shape =\n node.type === 'BOOLEAN_OPERATION' ? makeBooleanOperationPath(r, node, graph) : null\n r.applyClippedBlur(canvas, node, blurSigma(effect.radius), shape)\n shape?.delete()\n }\n\n if (pass === 'inner' && effect.type === 'INNER_SHADOW' && ownShadows) {\n renderInnerShadow(r, canvas, graph, node, effect, false)\n }\n }\n}\n\n/**\n * Draws a container's drop shadows before it (`behind`) and its inner shadows over its fills,\n * strokes, and children (`front`), cast from the children too unless its own fill covers them.\n */\nexport function renderLayerShadows(\n r: SkiaRenderer,\n canvas: Canvas,\n graph: SceneGraph,\n node: SceneNode,\n pass: 'behind' | 'front'\n): void {\n if (!isLayerContainer(node)) return\n const effects = node.effects.filter(\n (effect): effect is ShadowEffect =>\n effect.visible && effect.type === (pass === 'behind' ? 'DROP_SHADOW' : 'INNER_SHADOW')\n )\n if (effects.length === 0) return\n const includeChildren = shadowIncludesChildren(graph, node)\n for (const effect of effects) {\n if (pass === 'behind') renderDropShadow(r, canvas, graph, node, effect, includeChildren)\n else renderInnerShadow(r, canvas, graph, node, effect, includeChildren)\n }\n}\n"],"mappings":";;;;;;;;;AAiCA,SAAS,sBAAsB,GAAuB;CACpD,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,eAAe,IAAI;CACtC,EAAE,iBAAiB,aAAa,EAAE,GAAG,UAAU,OAAO;AACxD;;;;;AASA,MAAM,iCAAiD,IAAI,IAAuB;CAChF;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAS,aAAa,MAAiB,QAA8B;CACnE,IAAI,eAAe,IAAI,KAAK,IAAI,GAAG,OAAO;CAC1C,IAAI,CAAC,iBAAiB,IAAI,GAAG,OAAO,OAAO;CAC3C,OAAO,KAAK,gBAAgB,gBAAgB,IAAI,IAAI,OAAO,SAAS;AACtE;;AAGA,SAAS,kBAAkB,MAAiB,QAA8B;CACxE,OAAO,eAAe,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO;AACpD;AAEA,SAAS,kBACP,GACA,OACA,MACA,QACA,QACA,iBACc;CACd,MAAM,MAAM,iBAAiB,OAAO,MAAM,eAAe,KAAK;EAC5D,GAAG;EACH,GAAG;EACH,OAAO,KAAK;EACZ,QAAQ,KAAK;CACf;CACA,MAAM,SAAS,OAAO;CACtB,MAAM,UAAU,OAAO,SAAS,IAAI,KAAK,IAAI,MAAM;CACnD,OAAO,EAAE,GAAG,SACV,IAAI,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,SAChC,IAAI,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,SAChC,IAAI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8
8
|
declare function createDerivedGlyphPathCache(): ResourceCache<Uint8Array, Path>;
|
|
9
9
|
declare function createGlyphSilhouetteCache(): ResourceCache<string, Path>;
|
|
10
10
|
declare function snapDerivedGlyphBaseline(y: number): number;
|
|
11
|
-
declare function shouldUseHardDerivedGlyphCoverage(node: Pick<SceneNode, 'fontSize' | 'fontWeight'>): boolean;
|
|
12
11
|
/**
|
|
13
12
|
* Path-text glyphs carry non-zero Figma `Glyph.rotation` (radians). Used to
|
|
14
13
|
* disable axis-aligned assumptions (baseline snap, underline decorations).
|
|
@@ -41,5 +40,5 @@ declare function canDrawSavedText(node: SceneNode, fill?: Fill): boolean;
|
|
|
41
40
|
declare function drawsSavedText(node: SceneNode): boolean;
|
|
42
41
|
declare function drawDerivedText(r: SkiaRenderer, canvas: Canvas, node: SceneNode, fill?: Fill): boolean;
|
|
43
42
|
//#endregion
|
|
44
|
-
export { applyGlyphTransform, canDrawSavedText, createDerivedGlyphPathCache, createGlyphSilhouetteCache, drawDerivedText, drawReflowedPathTextSilhouettes, drawsSavedText, hasRotatedDerivedGlyphs, isReflowedPathText,
|
|
43
|
+
export { applyGlyphTransform, canDrawSavedText, createDerivedGlyphPathCache, createGlyphSilhouetteCache, drawDerivedText, drawReflowedPathTextSilhouettes, drawsSavedText, hasRotatedDerivedGlyphs, isReflowedPathText, snapDerivedGlyphBaseline };
|
|
45
44
|
//# sourceMappingURL=derived.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.d.ts","names":[],"sources":["../../../src/canvas/text/derived.ts"],"mappings":";;;;;;;iBA4BgB,+BAA+B,cAAc,YAAY;iBAazD,8BAA8B,sBAAsB;iBAIpD,yBAAyB
|
|
1
|
+
{"version":3,"file":"derived.d.ts","names":[],"sources":["../../../src/canvas/text/derived.ts"],"mappings":";;;;;;;iBA4BgB,+BAA+B,cAAc,YAAY;iBAazD,8BAA8B,sBAAsB;iBAIpD,yBAAyB;;;;;iBAQzB,wBAAwB,MAAM,KAAK;;;;;;iBASnC,mBAAmB,MAAM;;;;;;;iBAuEzB,oBAAoB,QAAQ,QAAQ,OAAO,kBAAkB;;;;;;iBAwC7D,gCACd,GAAG,cACH,QAAQ,QACR,MAAM,WACN,QAAQ,QACR,OAAO;iBA2GO,iBAAiB,MAAM,WAAW,OAAO;;;;;iBASzC,eAAe,MAAM;iBA2BrB,gBACd,GAAG,cACH,QAAQ,QACR,MAAM,WACN,OAAO"}
|
|
@@ -26,9 +26,6 @@ function createGlyphSilhouetteCache() {
|
|
|
26
26
|
function snapDerivedGlyphBaseline(y) {
|
|
27
27
|
return Math.round(y);
|
|
28
28
|
}
|
|
29
|
-
function shouldUseHardDerivedGlyphCoverage(node) {
|
|
30
|
-
return node.fontSize === 20 && node.fontWeight === 400;
|
|
31
|
-
}
|
|
32
29
|
/**
|
|
33
30
|
* Path-text glyphs carry non-zero Figma `Glyph.rotation` (radians). Used to
|
|
34
31
|
* disable axis-aligned assumptions (baseline snap, underline decorations).
|
|
@@ -241,12 +238,9 @@ function drawDerivedText(r, canvas, node, fill) {
|
|
|
241
238
|
const path = paintsLayerSpace ? layerSpaceGlyphPath(r, emPath, glyph, glyphY) : emPath;
|
|
242
239
|
canvas.save();
|
|
243
240
|
if (!paintsLayerSpace) applyGlyphEmTransform(canvas, glyph, glyphY);
|
|
244
|
-
const shouldUseHardCoverage = shouldUseHardDerivedGlyphCoverage(node);
|
|
245
|
-
if (shouldUseHardCoverage) r.fillPaint.setAntiAlias(false);
|
|
246
241
|
const character = glyph.firstCharacter ?? markerCharacters.get(index);
|
|
247
242
|
const run = character === void 0 ? void 0 : node.styleRuns.find((run) => character >= run.start && character < run.start + run.length);
|
|
248
243
|
drawGlyphOutline(r, canvas, path, savedTextEligible ? run?.style.fills : void 0);
|
|
249
|
-
if (shouldUseHardCoverage) r.fillPaint.setAntiAlias(true);
|
|
250
244
|
if (path !== emPath) path.delete();
|
|
251
245
|
canvas.restore();
|
|
252
246
|
}
|
|
@@ -258,6 +252,6 @@ function drawDerivedText(r, canvas, node, fill) {
|
|
|
258
252
|
return true;
|
|
259
253
|
}
|
|
260
254
|
//#endregion
|
|
261
|
-
export { applyGlyphTransform, canDrawSavedText, createDerivedGlyphPathCache, createGlyphSilhouetteCache, drawDerivedText, drawReflowedPathTextSilhouettes, drawsSavedText, hasRotatedDerivedGlyphs, isReflowedPathText,
|
|
255
|
+
export { applyGlyphTransform, canDrawSavedText, createDerivedGlyphPathCache, createGlyphSilhouetteCache, drawDerivedText, drawReflowedPathTextSilhouettes, drawsSavedText, hasRotatedDerivedGlyphs, isReflowedPathText, snapDerivedGlyphBaseline };
|
|
262
256
|
|
|
263
257
|
//# sourceMappingURL=derived.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derived.js","names":[],"sources":["../../../src/canvas/text/derived.ts"],"sourcesContent":["import type { Canvas, Path } from 'canvaskit-wasm'\nimport { fromUint8Array } from 'js-base64'\n\nimport type { Fill, DerivedTextGlyph, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { isGradientFill } from '@pairdraw/scene-graph/gradient'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\nimport {\n hasTextList,\n textListItems,\n textParagraphRanges,\n type TextParagraphRange\n} from '@pairdraw/scene-graph/text'\n\nimport type { ResourceCache } from '#core/cache/resource'\nimport { createPathCache } from '#core/canvas/paths/cache'\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport {\n drawTextDecorations,\n hasDecoration,\n savedTextDecorationRects\n} from '#core/canvas/text/decorations'\nimport { geometryBlobToPath } from '#core/vector'\n\nconst MAX_GLYPH_SILHOUETTES = 512\n/** Saved glyphs a renderer keeps decoded: every text on a page of saved text redraws at once. */\nconst MAX_DERIVED_GLYPH_PATHS = 16384\n\n/** Decoded saved glyph outlines, by the glyph's command bytes, which a node keeps until it changes. */\nexport function createDerivedGlyphPathCache(): ResourceCache<Uint8Array, Path> {\n return createPathCache({ maxEntries: MAX_DERIVED_GLYPH_PATHS })\n}\n\n/** A saved glyph's outline, decoded once and borrowed from the renderer's cache. */\nfunction derivedGlyphPath(r: SkiaRenderer, blob: Uint8Array): Path {\n const cached = r.derivedGlyphPathCache.get(blob)\n if (cached) return cached\n const path = geometryBlobToPath(r.ck, blob, 'NONZERO')\n r.derivedGlyphPathCache.set(blob, path)\n return path\n}\n\nexport function createGlyphSilhouetteCache(): ResourceCache<string, Path> {\n return createPathCache({ maxEntries: MAX_GLYPH_SILHOUETTES })\n}\n\nexport function snapDerivedGlyphBaseline(y: number): number {\n return Math.round(y)\n}\n\nexport function shouldUseHardDerivedGlyphCoverage(\n node: Pick<SceneNode, 'fontSize' | 'fontWeight'>\n): boolean {\n return node.fontSize === 20 && node.fontWeight === 400\n}\n\n/**\n * Path-text glyphs carry non-zero Figma `Glyph.rotation` (radians). Used to\n * disable axis-aligned assumptions (baseline snap, underline decorations).\n */\nexport function hasRotatedDerivedGlyphs(node: Pick<SceneNode, 'derivedTextGlyphs'>): boolean {\n return node.derivedTextGlyphs?.some((glyph) => (glyph.rotation ?? 0) !== 0) === true\n}\n\n/**\n * Resize-reflowed TEXT_PATH node: glyphs were re-laid along the path and the\n * baked node-level strokeGeometry was cleared — strokes must be re-derived\n * per glyph (see drawReflowedPathTextSilhouettes).\n */\nexport function isReflowedPathText(node: SceneNode): boolean {\n return (\n node.type === 'TEXT' &&\n (node.derivedTextGlyphs?.length ?? 0) > 0 &&\n node.textPathBox !== null &&\n node.strokeGeometry.length === 0 &&\n node.textPathData !== null\n )\n}\n\ninterface GlyphSilhouette {\n path: Path\n cached: boolean\n}\n\n/**\n * Silhouette = glyph outline dilated by the stroke weight, unioned with the\n * glyph itself (font units, so one cache entry serves every placement).\n * Cached paths are never deleted — the cache is content-keyed and bounded by\n * the number of distinct glyph outlines.\n *\n * ponytail: approximates every stroke.align as OUTSIDE (full-weight band\n * outside the glyph, backfilled by the union). Matches the baked path-text\n * stroke pipeline, which is OUTSIDE-oriented too, so it's consistent — but\n * CENTER sits too far out and INSIDE shows a band the fill should cover. Full\n * parity means per-align geometry (+ align in the cache key); deferred as the\n * reflow fallback only fires on resized stroked path text.\n */\nfunction getGlyphSilhouette(\n r: SkiaRenderer,\n glyph: DerivedTextGlyph,\n stroke: Stroke\n): GlyphSilhouette {\n const blob = glyph.commandsBlob\n const relativeWeight = stroke.weight / glyph.fontSize\n const key = `${fromUint8Array(blob)}:${relativeWeight.toFixed(5)}`\n const cached = r.glyphSilhouetteCache.peek(key)\n if (cached) return { path: cached, cached: true }\n\n const base = geometryBlobToPath(r.ck, blob, 'NONZERO')\n const outline = base.copy()\n // Round join/cap: miter spikes on glyph cusps (e.g. 'A' apex) shoot far\n // outside the letterform. Width doubles because half the band is swallowed\n // by the union with the glyph body (OUTSIDE-stroke look).\n const stroked = outline.makeStroked({\n width: relativeWeight * 2,\n join: r.ck.StrokeJoin.Round,\n cap: r.ck.StrokeCap.Round\n })\n const merged = stroked ? r.ck.Path.MakeFromOp(stroked, base, r.ck.PathOp.Union) : null\n if (!merged) {\n // Degenerate outline — draw the bare glyph, uncached so callers free it.\n outline.delete()\n stroked?.delete()\n return { path: base, cached: false }\n }\n base.delete()\n stroked?.delete()\n outline.delete()\n // Preserve reset-at-capacity for stroke-weight sweeps; the cache owns path disposal.\n if (r.glyphSilhouetteCache.size >= MAX_GLYPH_SILHOUETTES) r.glyphSilhouetteCache.clear()\n r.glyphSilhouetteCache.set(key, merged)\n return { path: merged, cached: true }\n}\n\n/**\n * Push a glyph's on-path transform: baseline → non-uniform scale → rotate →\n * font-units→px (Y-flipped). The fill and silhouette passes share it so they\n * stay registered; see drawDerivedText for the order rationale.\n */\n/** Moves to a saved glyph's pen position, in pixels: its baseline, resize scale, and rotation. */\nexport function applyGlyphTransform(canvas: Canvas, glyph: DerivedTextGlyph, glyphY: number): void {\n canvas.translate(glyph.x, glyphY)\n const scaleX = glyph.scaleX ?? 1\n const scaleY = glyph.scaleY ?? 1\n if (scaleX !== 1 || scaleY !== 1) canvas.scale(scaleX, scaleY)\n const rotation = glyph.rotation ?? 0\n if (rotation !== 0) canvas.rotate((-rotation * 180) / Math.PI, 0, 0)\n}\n\nfunction applyGlyphEmTransform(canvas: Canvas, glyph: DerivedTextGlyph, glyphY: number): void {\n applyGlyphTransform(canvas, glyph, glyphY)\n canvas.scale(glyph.fontSize, -glyph.fontSize)\n}\n\n/** The outline moved by the transform `applyGlyphEmTransform` applies to the canvas. */\nfunction layerSpaceGlyphPath(\n r: SkiaRenderer,\n path: Path,\n glyph: DerivedTextGlyph,\n glyphY: number\n): Path {\n const { Matrix } = r.ck\n const builder = new r.ck.PathBuilder()\n builder.addPath(\n path,\n Matrix.multiply(\n Matrix.translated(glyph.x, glyphY),\n Matrix.scaled(glyph.scaleX ?? 1, glyph.scaleY ?? 1),\n Matrix.rotated(-(glyph.rotation ?? 0)),\n Matrix.scaled(glyph.fontSize, -glyph.fontSize)\n )\n )\n return builder.detachAndDelete()\n}\n\n/**\n * Paint per-glyph stroke silhouettes under a reflowed path-text node.\n * Transform chain mirrors drawDerivedText exactly so silhouettes and\n * fills stay registered.\n */\nexport function drawReflowedPathTextSilhouettes(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n stroke: Stroke,\n color: Color\n): void {\n const glyphs = node.derivedTextGlyphs\n if (!glyphs?.length || stroke.weight <= 0) return\n\n const snapBaselines = !hasRotatedDerivedGlyphs(node)\n const paint = new r.ck.Paint()\n paint.setAntiAlias(true)\n paint.setStyle(r.ck.PaintStyle.Fill)\n paint.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a))\n paint.setAlphaf(stroke.opacity)\n try {\n for (const glyph of glyphs) {\n if (glyph.fontSize <= 0 || glyph.emojiCodePoints) continue\n const silhouette = getGlyphSilhouette(r, glyph, stroke)\n canvas.save()\n applyGlyphEmTransform(\n canvas,\n glyph,\n snapBaselines ? snapDerivedGlyphBaseline(glyph.y) : glyph.y\n )\n canvas.drawPath(silhouette.path, paint)\n canvas.restore()\n if (!silhouette.cached) silhouette.path.delete()\n }\n } finally {\n paint.delete()\n }\n}\n\n/**\n * Paint Figma-baked glyph outlines (missing-font / path-text fidelity path).\n *\n * Transform order is intentional and matched against real TEXT_PATH fixtures\n * (e.g. DomeSticker circular lettering):\n *\n * 1. translate(x, y) — baseline on the path (already resize-scaled)\n * 2. scale(scaleX,Y) — non-uniform resize (must be *outside* rotation;\n * S and R do not commute — see resize scaleX/Y)\n * 3. rotate(-θ°) — negate: CanvasKit degrees + following Y-flip;\n * positive Figma radians would otherwise misalign\n * black fills vs white strokeGeometry\n * 4. scale(fontSize,-fs) — font units → px; Y flip (font space is up-positive)\n */\n/** The paragraph holding text index `index`, found by bisection: saved glyphs can be many. */\nfunction rangeIndexAt(ranges: readonly TextParagraphRange[], index: number): number {\n let lo = 0\n let hi = ranges.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (ranges[mid].start <= index) lo = mid\n else hi = mid - 1\n }\n return lo\n}\n\n/**\n * The character whose style each saved list marker takes: the first of its list, as Figma\n * draws markers. Figma saves a marker, with no character of its own, before its item's glyphs.\n */\nfunction markerStyleCharacters(node: SceneNode): Map<number, number> {\n const characters = new Map<number, number>()\n if (!hasTextList(node)) return characters\n const ranges = textParagraphRanges(node.text)\n const listStarts = new Map(\n textListItems(node.text, node.textParagraphs).map((item) => [\n item.paragraph,\n ranges[item.groupStart].start\n ])\n )\n let markers: number[] = []\n for (const [index, glyph] of (node.derivedTextGlyphs ?? []).entries()) {\n if (glyph.firstCharacter === undefined) {\n markers.push(index)\n continue\n }\n const start = listStarts.get(rangeIndexAt(ranges, glyph.firstCharacter))\n if (start !== undefined) for (const marker of markers) characters.set(marker, start)\n markers = []\n }\n return characters\n}\n\nfunction savedTextEligibility(node: SceneNode): boolean {\n // Glyphs without a character are list markers in a list, and unknown text otherwise.\n const charactersKnown = hasTextList(node)\n ? !!node.derivedTextGlyphs?.some((glyph) => glyph.firstCharacter !== undefined)\n : !!node.derivedTextGlyphs?.every((glyph) => glyph.firstCharacter !== undefined)\n return (\n node.styleRuns.length === 0 ||\n (node.fills.filter((paint) => paint.visible).length === 1 &&\n charactersKnown &&\n node.styleRuns.every(\n (run) =>\n !run.style.fills ||\n run.style.fills.every(\n (paint) => paint.type === 'SOLID' && (!paint.blendMode || paint.blendMode === 'NORMAL')\n )\n ))\n )\n}\n\n/** Solid and gradient fills paint saved glyph outlines as they paint shapes; images do not. */\nfunction paintsSavedGlyphs(fill: Fill): boolean {\n return fill.type === 'SOLID' || isGradientFill(fill.type)\n}\n\nexport function canDrawSavedText(node: SceneNode, fill?: Fill): boolean {\n if (fill && !paintsSavedGlyphs(fill)) return false\n return savedTextEligibility(node)\n}\n\n/**\n * Whether the text is drawn from its saved glyphs whatever fills it has: every visible fill\n * draws them, or it has none. The emoji among them are then drawn once, apart from the fills.\n */\nexport function drawsSavedText(node: SceneNode): boolean {\n return (\n (node.derivedTextGlyphs?.length ?? 0) > 0 &&\n node.fills.every((fill) => !fill.visible || paintsSavedGlyphs(fill)) &&\n savedTextEligibility(node)\n )\n}\n\n/** One glyph's outline in its style run's solid fills, or in the layer's fill paint. */\nfunction drawGlyphOutline(r: SkiaRenderer, canvas: Canvas, path: Path, runFills?: Fill[]): void {\n if (!runFills) {\n canvas.drawPath(path, r.fillPaint)\n return\n }\n const paint = r.fillPaint.copy()\n try {\n for (const fill of runFills) {\n if (!fill.visible || fill.type !== 'SOLID') continue\n const color = fill.color\n paint.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a * fill.opacity))\n canvas.drawPath(path, paint)\n }\n } finally {\n paint.delete()\n }\n}\n\nexport function drawDerivedText(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n fill?: Fill\n): boolean {\n if (!node.derivedTextGlyphs?.length) return false\n\n // Pixel-snap is for horizontal Figma baselines only — on a curve it stair-steps\n // letter positions and breaks registration with strokeGeometry.\n const snapBaselines = !hasRotatedDerivedGlyphs(node)\n const savedTextEligible = savedTextEligibility(node)\n const markerCharacters = markerStyleCharacters(node)\n // A gradient spans the layer, so its glyphs are moved into layer space rather than drawn\n // under an em-scaled canvas that would stretch the gradient by the font size.\n const paintsLayerSpace = fill !== undefined && fill.type !== 'SOLID'\n for (const [index, glyph] of node.derivedTextGlyphs.entries()) {\n // An emoji's outline is a placeholder square; its image is drawn apart from the fills.\n if (glyph.emojiCodePoints) continue\n const glyphY = snapBaselines ? snapDerivedGlyphBaseline(glyph.y) : glyph.y\n const emPath = derivedGlyphPath(r, glyph.commandsBlob)\n const path = paintsLayerSpace ? layerSpaceGlyphPath(r, emPath, glyph, glyphY) : emPath\n canvas.save()\n if (!paintsLayerSpace) applyGlyphEmTransform(canvas, glyph, glyphY)\n const shouldUseHardCoverage = shouldUseHardDerivedGlyphCoverage(node)\n if (shouldUseHardCoverage) r.fillPaint.setAntiAlias(false)\n const character = glyph.firstCharacter ?? markerCharacters.get(index)\n const run =\n character === undefined\n ? undefined\n : node.styleRuns.find((run) => character >= run.start && character < run.start + run.length)\n drawGlyphOutline(r, canvas, path, savedTextEligible ? run?.style.fills : undefined)\n if (shouldUseHardCoverage) r.fillPaint.setAntiAlias(true)\n if (path !== emPath) path.delete()\n canvas.restore()\n }\n\n // Decorations follow horizontal lines; path text has none.\n if (snapBaselines && hasDecoration(node)) {\n const glyphs = node.derivedTextGlyphs\n const rects = savedTextDecorationRects(r.derivedDecorationCache, node, glyphs, r.fontGeneration)\n drawTextDecorations(r.ck, canvas, rects, r.fillPaint)\n }\n return true\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,wBAAwB;;AAE9B,MAAM,0BAA0B;;AAGhC,SAAgB,8BAA+D;CAC7E,OAAO,gBAAgB,EAAE,YAAY,wBAAwB,CAAC;AAChE;;AAGA,SAAS,iBAAiB,GAAiB,MAAwB;CACjE,MAAM,SAAS,EAAE,sBAAsB,IAAI,IAAI;CAC/C,IAAI,QAAQ,OAAO;CACnB,MAAM,OAAO,mBAAmB,EAAE,IAAI,MAAM,SAAS;CACrD,EAAE,sBAAsB,IAAI,MAAM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AO;EACjC,OAAO,QAAQ;CACjB;CAGA,IAAI,iBAAiB,cAAc,IAAI,GAAG;EACxC,MAAM,SAAS,KAAK;EACpB,MAAM,QAAQ,yBAAyB,EAAE,wBAAwB,MAAM,QAAQ,EAAE,cAAc;EAC/F,oBAAoB,EAAE,IAAI,QAAQ,OAAO,EAAE,SAAS;CACtD;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"derived.js","names":[],"sources":["../../../src/canvas/text/derived.ts"],"sourcesContent":["import type { Canvas, Path } from 'canvaskit-wasm'\nimport { fromUint8Array } from 'js-base64'\n\nimport type { Fill, DerivedTextGlyph, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { isGradientFill } from '@pairdraw/scene-graph/gradient'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\nimport {\n hasTextList,\n textListItems,\n textParagraphRanges,\n type TextParagraphRange\n} from '@pairdraw/scene-graph/text'\n\nimport type { ResourceCache } from '#core/cache/resource'\nimport { createPathCache } from '#core/canvas/paths/cache'\nimport type { SkiaRenderer } from '#core/canvas/renderer'\nimport {\n drawTextDecorations,\n hasDecoration,\n savedTextDecorationRects\n} from '#core/canvas/text/decorations'\nimport { geometryBlobToPath } from '#core/vector'\n\nconst MAX_GLYPH_SILHOUETTES = 512\n/** Saved glyphs a renderer keeps decoded: every text on a page of saved text redraws at once. */\nconst MAX_DERIVED_GLYPH_PATHS = 16384\n\n/** Decoded saved glyph outlines, by the glyph's command bytes, which a node keeps until it changes. */\nexport function createDerivedGlyphPathCache(): ResourceCache<Uint8Array, Path> {\n return createPathCache({ maxEntries: MAX_DERIVED_GLYPH_PATHS })\n}\n\n/** A saved glyph's outline, decoded once and borrowed from the renderer's cache. */\nfunction derivedGlyphPath(r: SkiaRenderer, blob: Uint8Array): Path {\n const cached = r.derivedGlyphPathCache.get(blob)\n if (cached) return cached\n const path = geometryBlobToPath(r.ck, blob, 'NONZERO')\n r.derivedGlyphPathCache.set(blob, path)\n return path\n}\n\nexport function createGlyphSilhouetteCache(): ResourceCache<string, Path> {\n return createPathCache({ maxEntries: MAX_GLYPH_SILHOUETTES })\n}\n\nexport function snapDerivedGlyphBaseline(y: number): number {\n return Math.round(y)\n}\n\n/**\n * Path-text glyphs carry non-zero Figma `Glyph.rotation` (radians). Used to\n * disable axis-aligned assumptions (baseline snap, underline decorations).\n */\nexport function hasRotatedDerivedGlyphs(node: Pick<SceneNode, 'derivedTextGlyphs'>): boolean {\n return node.derivedTextGlyphs?.some((glyph) => (glyph.rotation ?? 0) !== 0) === true\n}\n\n/**\n * Resize-reflowed TEXT_PATH node: glyphs were re-laid along the path and the\n * baked node-level strokeGeometry was cleared — strokes must be re-derived\n * per glyph (see drawReflowedPathTextSilhouettes).\n */\nexport function isReflowedPathText(node: SceneNode): boolean {\n return (\n node.type === 'TEXT' &&\n (node.derivedTextGlyphs?.length ?? 0) > 0 &&\n node.textPathBox !== null &&\n node.strokeGeometry.length === 0 &&\n node.textPathData !== null\n )\n}\n\ninterface GlyphSilhouette {\n path: Path\n cached: boolean\n}\n\n/**\n * Silhouette = glyph outline dilated by the stroke weight, unioned with the\n * glyph itself (font units, so one cache entry serves every placement).\n * Cached paths are never deleted — the cache is content-keyed and bounded by\n * the number of distinct glyph outlines.\n *\n * ponytail: approximates every stroke.align as OUTSIDE (full-weight band\n * outside the glyph, backfilled by the union). Matches the baked path-text\n * stroke pipeline, which is OUTSIDE-oriented too, so it's consistent — but\n * CENTER sits too far out and INSIDE shows a band the fill should cover. Full\n * parity means per-align geometry (+ align in the cache key); deferred as the\n * reflow fallback only fires on resized stroked path text.\n */\nfunction getGlyphSilhouette(\n r: SkiaRenderer,\n glyph: DerivedTextGlyph,\n stroke: Stroke\n): GlyphSilhouette {\n const blob = glyph.commandsBlob\n const relativeWeight = stroke.weight / glyph.fontSize\n const key = `${fromUint8Array(blob)}:${relativeWeight.toFixed(5)}`\n const cached = r.glyphSilhouetteCache.peek(key)\n if (cached) return { path: cached, cached: true }\n\n const base = geometryBlobToPath(r.ck, blob, 'NONZERO')\n const outline = base.copy()\n // Round join/cap: miter spikes on glyph cusps (e.g. 'A' apex) shoot far\n // outside the letterform. Width doubles because half the band is swallowed\n // by the union with the glyph body (OUTSIDE-stroke look).\n const stroked = outline.makeStroked({\n width: relativeWeight * 2,\n join: r.ck.StrokeJoin.Round,\n cap: r.ck.StrokeCap.Round\n })\n const merged = stroked ? r.ck.Path.MakeFromOp(stroked, base, r.ck.PathOp.Union) : null\n if (!merged) {\n // Degenerate outline — draw the bare glyph, uncached so callers free it.\n outline.delete()\n stroked?.delete()\n return { path: base, cached: false }\n }\n base.delete()\n stroked?.delete()\n outline.delete()\n // Preserve reset-at-capacity for stroke-weight sweeps; the cache owns path disposal.\n if (r.glyphSilhouetteCache.size >= MAX_GLYPH_SILHOUETTES) r.glyphSilhouetteCache.clear()\n r.glyphSilhouetteCache.set(key, merged)\n return { path: merged, cached: true }\n}\n\n/**\n * Push a glyph's on-path transform: baseline → non-uniform scale → rotate →\n * font-units→px (Y-flipped). The fill and silhouette passes share it so they\n * stay registered; see drawDerivedText for the order rationale.\n */\n/** Moves to a saved glyph's pen position, in pixels: its baseline, resize scale, and rotation. */\nexport function applyGlyphTransform(canvas: Canvas, glyph: DerivedTextGlyph, glyphY: number): void {\n canvas.translate(glyph.x, glyphY)\n const scaleX = glyph.scaleX ?? 1\n const scaleY = glyph.scaleY ?? 1\n if (scaleX !== 1 || scaleY !== 1) canvas.scale(scaleX, scaleY)\n const rotation = glyph.rotation ?? 0\n if (rotation !== 0) canvas.rotate((-rotation * 180) / Math.PI, 0, 0)\n}\n\nfunction applyGlyphEmTransform(canvas: Canvas, glyph: DerivedTextGlyph, glyphY: number): void {\n applyGlyphTransform(canvas, glyph, glyphY)\n canvas.scale(glyph.fontSize, -glyph.fontSize)\n}\n\n/** The outline moved by the transform `applyGlyphEmTransform` applies to the canvas. */\nfunction layerSpaceGlyphPath(\n r: SkiaRenderer,\n path: Path,\n glyph: DerivedTextGlyph,\n glyphY: number\n): Path {\n const { Matrix } = r.ck\n const builder = new r.ck.PathBuilder()\n builder.addPath(\n path,\n Matrix.multiply(\n Matrix.translated(glyph.x, glyphY),\n Matrix.scaled(glyph.scaleX ?? 1, glyph.scaleY ?? 1),\n Matrix.rotated(-(glyph.rotation ?? 0)),\n Matrix.scaled(glyph.fontSize, -glyph.fontSize)\n )\n )\n return builder.detachAndDelete()\n}\n\n/**\n * Paint per-glyph stroke silhouettes under a reflowed path-text node.\n * Transform chain mirrors drawDerivedText exactly so silhouettes and\n * fills stay registered.\n */\nexport function drawReflowedPathTextSilhouettes(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n stroke: Stroke,\n color: Color\n): void {\n const glyphs = node.derivedTextGlyphs\n if (!glyphs?.length || stroke.weight <= 0) return\n\n const snapBaselines = !hasRotatedDerivedGlyphs(node)\n const paint = new r.ck.Paint()\n paint.setAntiAlias(true)\n paint.setStyle(r.ck.PaintStyle.Fill)\n paint.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a))\n paint.setAlphaf(stroke.opacity)\n try {\n for (const glyph of glyphs) {\n if (glyph.fontSize <= 0 || glyph.emojiCodePoints) continue\n const silhouette = getGlyphSilhouette(r, glyph, stroke)\n canvas.save()\n applyGlyphEmTransform(\n canvas,\n glyph,\n snapBaselines ? snapDerivedGlyphBaseline(glyph.y) : glyph.y\n )\n canvas.drawPath(silhouette.path, paint)\n canvas.restore()\n if (!silhouette.cached) silhouette.path.delete()\n }\n } finally {\n paint.delete()\n }\n}\n\n/**\n * Paint Figma-baked glyph outlines (missing-font / path-text fidelity path).\n *\n * Transform order is intentional and matched against real TEXT_PATH fixtures\n * (e.g. DomeSticker circular lettering):\n *\n * 1. translate(x, y) — baseline on the path (already resize-scaled)\n * 2. scale(scaleX,Y) — non-uniform resize (must be *outside* rotation;\n * S and R do not commute — see resize scaleX/Y)\n * 3. rotate(-θ°) — negate: CanvasKit degrees + following Y-flip;\n * positive Figma radians would otherwise misalign\n * black fills vs white strokeGeometry\n * 4. scale(fontSize,-fs) — font units → px; Y flip (font space is up-positive)\n */\n/** The paragraph holding text index `index`, found by bisection: saved glyphs can be many. */\nfunction rangeIndexAt(ranges: readonly TextParagraphRange[], index: number): number {\n let lo = 0\n let hi = ranges.length - 1\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1\n if (ranges[mid].start <= index) lo = mid\n else hi = mid - 1\n }\n return lo\n}\n\n/**\n * The character whose style each saved list marker takes: the first of its list, as Figma\n * draws markers. Figma saves a marker, with no character of its own, before its item's glyphs.\n */\nfunction markerStyleCharacters(node: SceneNode): Map<number, number> {\n const characters = new Map<number, number>()\n if (!hasTextList(node)) return characters\n const ranges = textParagraphRanges(node.text)\n const listStarts = new Map(\n textListItems(node.text, node.textParagraphs).map((item) => [\n item.paragraph,\n ranges[item.groupStart].start\n ])\n )\n let markers: number[] = []\n for (const [index, glyph] of (node.derivedTextGlyphs ?? []).entries()) {\n if (glyph.firstCharacter === undefined) {\n markers.push(index)\n continue\n }\n const start = listStarts.get(rangeIndexAt(ranges, glyph.firstCharacter))\n if (start !== undefined) for (const marker of markers) characters.set(marker, start)\n markers = []\n }\n return characters\n}\n\nfunction savedTextEligibility(node: SceneNode): boolean {\n // Glyphs without a character are list markers in a list, and unknown text otherwise.\n const charactersKnown = hasTextList(node)\n ? !!node.derivedTextGlyphs?.some((glyph) => glyph.firstCharacter !== undefined)\n : !!node.derivedTextGlyphs?.every((glyph) => glyph.firstCharacter !== undefined)\n return (\n node.styleRuns.length === 0 ||\n (node.fills.filter((paint) => paint.visible).length === 1 &&\n charactersKnown &&\n node.styleRuns.every(\n (run) =>\n !run.style.fills ||\n run.style.fills.every(\n (paint) => paint.type === 'SOLID' && (!paint.blendMode || paint.blendMode === 'NORMAL')\n )\n ))\n )\n}\n\n/** Solid and gradient fills paint saved glyph outlines as they paint shapes; images do not. */\nfunction paintsSavedGlyphs(fill: Fill): boolean {\n return fill.type === 'SOLID' || isGradientFill(fill.type)\n}\n\nexport function canDrawSavedText(node: SceneNode, fill?: Fill): boolean {\n if (fill && !paintsSavedGlyphs(fill)) return false\n return savedTextEligibility(node)\n}\n\n/**\n * Whether the text is drawn from its saved glyphs whatever fills it has: every visible fill\n * draws them, or it has none. The emoji among them are then drawn once, apart from the fills.\n */\nexport function drawsSavedText(node: SceneNode): boolean {\n return (\n (node.derivedTextGlyphs?.length ?? 0) > 0 &&\n node.fills.every((fill) => !fill.visible || paintsSavedGlyphs(fill)) &&\n savedTextEligibility(node)\n )\n}\n\n/** One glyph's outline in its style run's solid fills, or in the layer's fill paint. */\nfunction drawGlyphOutline(r: SkiaRenderer, canvas: Canvas, path: Path, runFills?: Fill[]): void {\n if (!runFills) {\n canvas.drawPath(path, r.fillPaint)\n return\n }\n const paint = r.fillPaint.copy()\n try {\n for (const fill of runFills) {\n if (!fill.visible || fill.type !== 'SOLID') continue\n const color = fill.color\n paint.setColor(r.ck.Color4f(color.r, color.g, color.b, color.a * fill.opacity))\n canvas.drawPath(path, paint)\n }\n } finally {\n paint.delete()\n }\n}\n\nexport function drawDerivedText(\n r: SkiaRenderer,\n canvas: Canvas,\n node: SceneNode,\n fill?: Fill\n): boolean {\n if (!node.derivedTextGlyphs?.length) return false\n\n // Pixel-snap is for horizontal Figma baselines only — on a curve it stair-steps\n // letter positions and breaks registration with strokeGeometry.\n const snapBaselines = !hasRotatedDerivedGlyphs(node)\n const savedTextEligible = savedTextEligibility(node)\n const markerCharacters = markerStyleCharacters(node)\n // A gradient spans the layer, so its glyphs are moved into layer space rather than drawn\n // under an em-scaled canvas that would stretch the gradient by the font size.\n const paintsLayerSpace = fill !== undefined && fill.type !== 'SOLID'\n for (const [index, glyph] of node.derivedTextGlyphs.entries()) {\n // An emoji's outline is a placeholder square; its image is drawn apart from the fills.\n if (glyph.emojiCodePoints) continue\n const glyphY = snapBaselines ? snapDerivedGlyphBaseline(glyph.y) : glyph.y\n const emPath = derivedGlyphPath(r, glyph.commandsBlob)\n const path = paintsLayerSpace ? layerSpaceGlyphPath(r, emPath, glyph, glyphY) : emPath\n canvas.save()\n if (!paintsLayerSpace) applyGlyphEmTransform(canvas, glyph, glyphY)\n const character = glyph.firstCharacter ?? markerCharacters.get(index)\n const run =\n character === undefined\n ? undefined\n : node.styleRuns.find((run) => character >= run.start && character < run.start + run.length)\n drawGlyphOutline(r, canvas, path, savedTextEligible ? run?.style.fills : undefined)\n if (path !== emPath) path.delete()\n canvas.restore()\n }\n\n // Decorations follow horizontal lines; path text has none.\n if (snapBaselines && hasDecoration(node)) {\n const glyphs = node.derivedTextGlyphs\n const rects = savedTextDecorationRects(r.derivedDecorationCache, node, glyphs, r.fontGeneration)\n drawTextDecorations(r.ck, canvas, rects, r.fillPaint)\n }\n return true\n}\n"],"mappings":";;;;;;;AAuBA,MAAM,wBAAwB;;AAE9B,MAAM,0BAA0B;;AAGhC,SAAgB,8BAA+D;CAC7E,OAAO,gBAAgB,EAAE,YAAY,wBAAwB,CAAC;AAChE;;AAGA,SAAS,iBAAiB,GAAiB,MAAwB;CACjE,MAAM,SAAS,EAAE,sBAAsB,IAAI,IAAI;CAC/C,IAAI,QAAQ,OAAO;CACnB,MAAM,OAAO,mBAAmB,EAAE,IAAI,MAAM,SAAS;CACrD,EAAE,sBAAsB,IAAI,MAAM,IAAI;CACtC,OAAO;AACT;AAEA,SAAgB,6BAA0D;CACxE,OAAO,gBAAgB,EAAE,YAAY,sBAAsB,CAAC;AAC9D;AAEA,SAAgB,yBAAyB,GAAmB;CAC1D,OAAO,KAAK,MAAM,CAAC;AACrB;;;;;AAMA,SAAgB,wBAAwB,MAAqD;CAC3F,OAAO,KAAK,mBAAmB,MAAM,WAAW,MAAM,YAAY,OAAO,CAAC,MAAM;AAClF;;;;;;AAOA,SAAgB,mBAAmB,MAA0B;CAC3D,OACE,KAAK,SAAS,WACb,KAAK,mBAAmB,UAAU,KAAK,KACxC,KAAK,gBAAgB,QACrB,KAAK,eAAe,WAAW,KAC/B,KAAK,iBAAiB;AAE1B;;;;;;;;;;;;;;AA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KAAK,kBAAkB,QAAQ,GAAG;EAE7D,IAAI,MAAM,iBAAiB;EAC3B,MAAM,SAAS,gBAAgB,yBAAyB,MAAM,CAAC,IAAI,MAAM;EACzE,MAAM,SAAS,iBAAiB,GAAG,MAAM,YAAY;EACrD,MAAM,OAAO,mBAAmB,oBAAoB,GAAG,QAAQ,OAAO,MAAM,IAAI;EAChF,OAAO,KAAK;EACZ,IAAI,CAAC,kBAAkB,sBAAsB,QAAQ,OAAO,MAAM;EAClE,MAAM,YAAY,MAAM,kBAAkB,iBAAiB,IAAI,KAAK;EACpE,MAAM,MACJ,cAAc,KAAA,IACV,KAAA,IACA,KAAK,UAAU,MAAM,QAAQ,aAAa,IAAI,SAAS,YAAY,IAAI,QAAQ,IAAI,MAAM;EAC/F,iBAAiB,GAAG,QAAQ,MAAM,oBAAoB,KAAK,MAAM,QAAQ,KAAA,CAAS;EAClF,IAAI,SAAS,QAAQ,KAAK,OAAO;EACjC,OAAO,QAAQ;CACjB;CAGA,IAAI,iBAAiB,cAAc,IAAI,GAAG;EACxC,MAAM,SAAS,KAAK;EACpB,MAAM,QAAQ,yBAAyB,EAAE,wBAAwB,MAAM,QAAQ,EAAE,cAAc;EAC/F,oBAAoB,EAAE,IAAI,QAAQ,OAAO,EAAE,SAAS;CACtD;CACA,OAAO;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ResourceCache } from "../../../cache/resource.js";
|
|
2
|
-
import { shownText } from "../../../text/case.js";
|
|
3
2
|
import { canDrawPlatformEmoji, emojiText, mayHoldEmoji } from "../../../text/emoji.js";
|
|
3
|
+
import { shownText } from "../../../text/case.js";
|
|
4
4
|
import { characterFamily, laidOutGlyphs } from "../placed.js";
|
|
5
5
|
import { nextGraphemeBoundary } from "../../../text/graphemes.js";
|
|
6
6
|
import { applyGlyphTransform, hasRotatedDerivedGlyphs, snapDerivedGlyphBaseline } from "../derived.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raster.d.ts","names":[],"sources":["../../../../src/canvas/text/emoji/raster.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"raster.d.ts","names":[],"sources":["../../../../src/canvas/text/emoji/raster.ts"],"mappings":";;;cAMa;;iBA0BG,uBAAuB,IAAI,WAAW,eAAe;;;;;iBAcrD,mBACd,IAAI,WACJ,UAAU,sBACV,eACC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NOTO_COLOR_EMOJI_FAMILY } from "../../../text/emoji.js";
|
|
2
|
+
import { makeParagraphBuilder } from "../../../text/font/collection.js";
|
|
2
3
|
//#region src/canvas/text/emoji/raster.ts
|
|
3
4
|
/** Emoji are drawn from square images this many pixels wide, as Figma draws its own. */
|
|
4
5
|
const EMOJI_IMAGE_SIZE = 160;
|
|
@@ -32,14 +33,12 @@ function rasterizePlatformEmoji(ck, text) {
|
|
|
32
33
|
* than they are tall; the glyph's advance fills the image's width, centred on its height.
|
|
33
34
|
*/
|
|
34
35
|
function rasterizeNotoEmoji(ck, provider, text) {
|
|
35
|
-
const surface = ck.MakeSurface(160, 160);
|
|
36
|
-
if (!surface) return null;
|
|
37
36
|
const style = new ck.ParagraphStyle({ textStyle: {
|
|
38
37
|
fontFamilies: [NOTO_COLOR_EMOJI_FAMILY],
|
|
39
38
|
fontSize: 160,
|
|
40
39
|
color: ck.BLACK
|
|
41
40
|
} });
|
|
42
|
-
const builder = ck
|
|
41
|
+
const builder = makeParagraphBuilder(ck, style, provider);
|
|
43
42
|
try {
|
|
44
43
|
builder.addText(text);
|
|
45
44
|
const paragraph = builder.build();
|
|
@@ -48,18 +47,23 @@ function rasterizeNotoEmoji(ck, provider, text) {
|
|
|
48
47
|
const advance = paragraph.getMaxIntrinsicWidth();
|
|
49
48
|
if (advance <= 0) return null;
|
|
50
49
|
const scale = 160 / advance;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const surface = ck.MakeSurface(160, 160);
|
|
51
|
+
if (!surface) return null;
|
|
52
|
+
try {
|
|
53
|
+
const canvas = surface.getCanvas();
|
|
54
|
+
canvas.clear(ck.TRANSPARENT);
|
|
55
|
+
canvas.translate(0, (160 - paragraph.getHeight() * scale) / 2);
|
|
56
|
+
canvas.scale(scale, scale);
|
|
57
|
+
canvas.drawParagraph(paragraph, 0, 0);
|
|
58
|
+
return surface.makeImageSnapshot();
|
|
59
|
+
} finally {
|
|
60
|
+
surface.dispose();
|
|
61
|
+
}
|
|
57
62
|
} finally {
|
|
58
63
|
paragraph.delete();
|
|
59
64
|
}
|
|
60
65
|
} finally {
|
|
61
66
|
builder.delete();
|
|
62
|
-
surface.delete();
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raster.js","names":[],"sources":["../../../../src/canvas/text/emoji/raster.ts"],"sourcesContent":["import type { CanvasKit, Image, TypefaceFontProvider } from 'canvaskit-wasm'\n\nimport { NOTO_COLOR_EMOJI_FAMILY } from '#core/text/emoji'\n\n/** Emoji are drawn from square images this many pixels wide, as Figma draws its own. */\nexport const EMOJI_IMAGE_SIZE = 160\n\n/**\n * Where the platform's emoji font puts its pen in an image `EMOJI_IMAGE_SIZE` wide at that font\n * size: the baseline this far down. Measured against Figma's Apple images, which Apple Color\n * Emoji draws to within a pixel at this offset.\n */\nconst PLATFORM_BASELINE = 0.8775\n\nconst PLATFORM_EMOJI_FONTS = '\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\"'\n\nfunction imageFromPixels(ck: CanvasKit, pixels: Uint8Array | Uint8ClampedArray): Image | null {\n return ck.MakeImage(\n {\n width: EMOJI_IMAGE_SIZE,\n height: EMOJI_IMAGE_SIZE,\n colorType: ck.ColorType.RGBA_8888,\n alphaType: ck.AlphaType.Unpremul,\n colorSpace: ck.ColorSpace.SRGB\n },\n pixels,\n EMOJI_IMAGE_SIZE * 4\n )\n}\n\n/** The emoji as the platform's own emoji font draws it, through the browser's 2D canvas. */\nexport function rasterizePlatformEmoji(ck: CanvasKit, text: string): Image | null {\n const canvas = new OffscreenCanvas(EMOJI_IMAGE_SIZE, EMOJI_IMAGE_SIZE)\n const context = canvas.getContext('2d')\n if (!context) return null\n context.font = `${EMOJI_IMAGE_SIZE}px ${PLATFORM_EMOJI_FONTS}`\n context.textBaseline = 'alphabetic'\n context.fillText(text, 0, EMOJI_IMAGE_SIZE * PLATFORM_BASELINE)\n return imageFromPixels(ck, context.getImageData(0, 0, EMOJI_IMAGE_SIZE, EMOJI_IMAGE_SIZE).data)\n}\n\n/**\n * The emoji drawn with Noto Color Emoji, once loaded into `provider`. Noto's glyphs are wider\n * than they are tall; the glyph's advance fills the image's width, centred on its height.\n */\nexport function rasterizeNotoEmoji(\n ck: CanvasKit,\n provider: TypefaceFontProvider,\n text: string\n): Image | null {\n const
|
|
1
|
+
{"version":3,"file":"raster.js","names":[],"sources":["../../../../src/canvas/text/emoji/raster.ts"],"sourcesContent":["import type { CanvasKit, Image, TypefaceFontProvider } from 'canvaskit-wasm'\n\nimport { NOTO_COLOR_EMOJI_FAMILY } from '#core/text/emoji'\nimport { makeParagraphBuilder } from '#core/text/font/collection'\n\n/** Emoji are drawn from square images this many pixels wide, as Figma draws its own. */\nexport const EMOJI_IMAGE_SIZE = 160\n\n/**\n * Where the platform's emoji font puts its pen in an image `EMOJI_IMAGE_SIZE` wide at that font\n * size: the baseline this far down. Measured against Figma's Apple images, which Apple Color\n * Emoji draws to within a pixel at this offset.\n */\nconst PLATFORM_BASELINE = 0.8775\n\nconst PLATFORM_EMOJI_FONTS = '\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\"'\n\nfunction imageFromPixels(ck: CanvasKit, pixels: Uint8Array | Uint8ClampedArray): Image | null {\n return ck.MakeImage(\n {\n width: EMOJI_IMAGE_SIZE,\n height: EMOJI_IMAGE_SIZE,\n colorType: ck.ColorType.RGBA_8888,\n alphaType: ck.AlphaType.Unpremul,\n colorSpace: ck.ColorSpace.SRGB\n },\n pixels,\n EMOJI_IMAGE_SIZE * 4\n )\n}\n\n/** The emoji as the platform's own emoji font draws it, through the browser's 2D canvas. */\nexport function rasterizePlatformEmoji(ck: CanvasKit, text: string): Image | null {\n const canvas = new OffscreenCanvas(EMOJI_IMAGE_SIZE, EMOJI_IMAGE_SIZE)\n const context = canvas.getContext('2d')\n if (!context) return null\n context.font = `${EMOJI_IMAGE_SIZE}px ${PLATFORM_EMOJI_FONTS}`\n context.textBaseline = 'alphabetic'\n context.fillText(text, 0, EMOJI_IMAGE_SIZE * PLATFORM_BASELINE)\n return imageFromPixels(ck, context.getImageData(0, 0, EMOJI_IMAGE_SIZE, EMOJI_IMAGE_SIZE).data)\n}\n\n/**\n * The emoji drawn with Noto Color Emoji, once loaded into `provider`. Noto's glyphs are wider\n * than they are tall; the glyph's advance fills the image's width, centred on its height.\n */\nexport function rasterizeNotoEmoji(\n ck: CanvasKit,\n provider: TypefaceFontProvider,\n text: string\n): Image | null {\n const style = new ck.ParagraphStyle({\n textStyle: {\n fontFamilies: [NOTO_COLOR_EMOJI_FAMILY],\n fontSize: EMOJI_IMAGE_SIZE,\n color: ck.BLACK\n }\n })\n const builder = makeParagraphBuilder(ck, style, provider)\n try {\n builder.addText(text)\n const paragraph = builder.build()\n try {\n paragraph.layout(EMOJI_IMAGE_SIZE * 4)\n const advance = paragraph.getMaxIntrinsicWidth()\n if (advance <= 0) return null\n const scale = EMOJI_IMAGE_SIZE / advance\n const surface = ck.MakeSurface(EMOJI_IMAGE_SIZE, EMOJI_IMAGE_SIZE)\n if (!surface) return null\n try {\n const canvas = surface.getCanvas()\n canvas.clear(ck.TRANSPARENT)\n canvas.translate(0, (EMOJI_IMAGE_SIZE - paragraph.getHeight() * scale) / 2)\n canvas.scale(scale, scale)\n canvas.drawParagraph(paragraph, 0, 0)\n return surface.makeImageSnapshot()\n } finally {\n surface.dispose()\n }\n } finally {\n paragraph.delete()\n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,KAAK;IACzB,OAAO,cAAc,WAAW,GAAG,CAAC;IACpC,OAAO,QAAQ,kBAAkB;GACnC,UAAU;IACR,QAAQ,QAAQ;GAClB;EACF,UAAU;GACR,UAAU,OAAO;EACnB;CACF,UAAU;EACR,QAAQ,OAAO;CACjB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-families.d.ts","names":[],"sources":["../../../src/canvas/text/font-families.ts"],"mappings":";;;;;UAgBiB;EACf;EACA;EACA;;EAEA;EACA;;EAEA,qBAAqB;EACrB;;;;;;;iBAQc,oBAAoB,MAAM,gBAAgB;;
|
|
1
|
+
{"version":3,"file":"font-families.d.ts","names":[],"sources":["../../../src/canvas/text/font-families.ts"],"mappings":";;;;;UAgBiB;EACf;EACA;EACA;;EAEA;EACA;;EAEA,qBAAqB;EACrB;;;;;;;iBAQc,oBAAoB,MAAM,gBAAgB;;UAuBzC,sBAAsB;EACrC;;;;;;iBAOc,cAAc,MAAM,gBAAgB;;UAWnC,mBAAmB;EAClC;;;;;;;iBAQc,WACd,gBACA,gBACA,iBACA,iBACC;;;;;;;;iBAoBa,wBACd,iBACA,qCACA;;;;;iBAuBc,6BACd,iBACA;EAAQ;EAAgB;EAAiB;GACzC,qCACA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_FONT_FAMILY } from "../../constants.js";
|
|
2
2
|
import { ResourceCache } from "../../cache/resource.js";
|
|
3
|
+
import { EMOJI_METRICS_FAMILY } from "../../text/emoji.js";
|
|
3
4
|
import { fontWeightMatchOrder } from "../../text/font/style.js";
|
|
4
5
|
import { fontManager } from "../../text/font/manager.js";
|
|
5
|
-
import { EMOJI_METRICS_FAMILY } from "../../text/emoji.js";
|
|
6
6
|
import { faceLoadKey } from "@pairdraw/scene-graph/font-style";
|
|
7
7
|
import { uniq } from "es-toolkit/array";
|
|
8
8
|
//#region src/canvas/text/font-families.ts
|
|
@@ -19,7 +19,9 @@ function drawnFontVariations(font) {
|
|
|
19
19
|
axis: "opsz",
|
|
20
20
|
value: font.fontSize
|
|
21
21
|
}] : font.variations;
|
|
22
|
-
|
|
22
|
+
const axes = new Map([...named, ...set].map(({ axis, value }) => [axis, value]));
|
|
23
|
+
if (!axes.has("wght") && !loadedFace(font.family, font.weight, font.italic, font.style)) axes.set("wght", font.weight);
|
|
24
|
+
return [...axes].map(([axis, value]) => ({
|
|
23
25
|
axis,
|
|
24
26
|
value
|
|
25
27
|
}));
|
|
@@ -43,6 +45,7 @@ function drawnFontAxes(font) {
|
|
|
43
45
|
* `null` when the family has none loaded.
|
|
44
46
|
*/
|
|
45
47
|
function loadedFace(family, weight, italic, style = faceLoadKey(weight, italic)) {
|
|
48
|
+
if (!fontManager.isLoaded(family)) return null;
|
|
46
49
|
if (fontManager.isStyleLoaded(family, style)) return {
|
|
47
50
|
weight,
|
|
48
51
|
italic,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font-families.js","names":[],"sources":["../../../src/canvas/text/font-families.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n\nimport type { FontVariation } from '@pairdraw/scene-graph'\nimport { faceLoadKey } from '@pairdraw/scene-graph/font-style'\n\nimport { ResourceCache } from '#core/cache/resource'\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { EMOJI_METRICS_FAMILY } from '#core/text/emoji'\nimport type { FaceWeight } from '#core/text/font/faces'\nimport { fontManager } from '#core/text/font/manager'\nimport { fontWeightMatchOrder } from '#core/text/font/style'\nimport type { FontAxis } from '#core/text/font/variation'\n\nconst familiesCache = new ResourceCache<string, string[]>({ maxEntries: 256 })\n\n/** What decides the axis values of a variable font text is drawn in. */\nexport interface DrawnFontAxes {\n family: string\n weight: number\n italic: boolean\n /** The face's key, as {@link faceStyleKey} gives it; its weight's key when left out. */\n style?: string\n fontSize: number\n /** The axes the text sets. */\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/**\n * The axis values text is drawn at, as Figma draws a variable font: its style's named instance,\n * then the axes it sets. While the optical size follows the font size, `opsz` is the font size and\n * a stored `opsz` is ignored. Fonts without an axis ignore its value.\n */\nexport function drawnFontVariations(font: DrawnFontAxes): FontVariation[] {\n // A face named apart from its weight (\"Condensed Bold\") is the instance of that name.\n const weightKey = faceLoadKey(font.weight, font.italic)\n const named =\n fontManager.namedInstanceVariations(font.family, font.style ?? weightKey) ??\n fontManager.namedInstanceVariations(font.family, weightKey) ??\n []\n const set = font.opticalSizeFromFontSize\n ? [\n ...font.variations.filter((variation) => variation.axis !== 'opsz'),\n { axis: 'opsz', value: font.fontSize }\n ]\n : font.variations\n const axes = new Map([...named, ...set].map(({ axis, value }) => [axis, value]))\n return [...axes].map(([axis, value]) => ({ axis, value }))\n}\n\n/** An axis of the variable font text is drawn in, with the value it is drawn at. */\nexport interface DrawnFontAxis extends FontAxis {\n value: number\n}\n\n/**\n * The axes of the variable font text is drawn in, in the font's order, each at the value it is\n * drawn at, within its range. `null` when the family's loaded faces are static or it has none.\n */\nexport function drawnFontAxes(font: DrawnFontAxes): DrawnFontAxis[] | null {\n const variation = fontManager.familyVariation(font.family, font.italic)\n if (!variation) return null\n const drawn = new Map(drawnFontVariations(font).map(({ axis, value }) => [axis, value]))\n return variation.axes.map((axis) => ({\n ...axis,\n value: Math.min(axis.max, Math.max(axis.min, drawn.get(axis.tag) ?? axis.default))\n }))\n}\n\n/** A loaded face text is drawn in: its weight and slant, and the key it is loaded under. */\nexport interface LoadedFace extends FaceWeight {\n style: string\n}\n\n/**\n * The loaded face of a family that text asking for a face is drawn in: that face, by its key,\n * or the nearest loaded weight in the same slant, then the other, as font matching picks it;\n * `null` when the family has none loaded.\n */\nexport function loadedFace(\n family: string,\n weight: number,\n italic: boolean,\n style = faceLoadKey(weight, italic)\n): LoadedFace | null {\n if (fontManager.isStyleLoaded(family, style)) return { weight, italic, style }\n for (const slant of [italic, !italic]) {\n for (const candidate of fontWeightMatchOrder(weight)) {\n const key = faceLoadKey(candidate, slant)\n if (fontManager.isStyleLoaded(family, key))\n return { weight: candidate, italic: slant, style: key }\n }\n }\n return null\n}\n\n/**\n * The families a paragraph's text falls back through, by their own names: its family, the\n * default family, the fallbacks of scripts written in letters (Arabic, Hebrew, Thai,\n * Devanagari) and CJK, then emoji, so a character a script's font has\n * stays in that font. Fonts are read by these names; CanvasKit is asked for them as\n * {@link resolveParagraphFontFamilies} names them.\n */\nexport function paragraphSourceFamilies(\n primary: string,\n letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),\n cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()\n): string[] {\n return uniq([\n primary,\n ...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),\n ...letterFallbacks,\n ...cjkFallbacks,\n EMOJI_METRICS_FAMILY\n ])\n}\n\n/** `style` of `family` by the names CanvasKit draws it under: its own file, then its shards. */\nfunction renderFamilies(family: string, style: string): string[] {\n return [\n fontManager.renderFamily(family, style),\n ...fontManager.renderShardFamilies(family, style)\n ]\n}\n\n/**\n * The paragraph's families as CanvasKit is asked for them: the family in the face it draws the\n * face in, and its fallbacks, each by the names `renderFamilies` gives it.\n */\nexport function resolveParagraphFontFamilies(\n primary: string,\n face: { weight: number; italic: boolean; style: string },\n letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),\n cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()\n): string[] {\n // The face the family draws it in, which may be the nearest one loaded.\n const drawn = loadedFace(primary, face.weight, face.italic, face.style)\n const renderPrimary = renderFamilies(primary, drawn?.style ?? face.style)\n const renderLetterFallbacks = letterFallbacks.flatMap((family) =>\n renderFamilies(family, 'Regular')\n )\n const renderCJKFallbacks = cjkFallbacks.flatMap((family) => renderFamilies(family, 'Regular'))\n const key = [\n primary,\n ...renderPrimary,\n '',\n ...renderLetterFallbacks,\n '',\n ...renderCJKFallbacks\n ].join('\\0')\n const cached = familiesCache.peek(key)\n if (cached) return cached\n const resolved = uniq([\n ...renderPrimary,\n ...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),\n ...renderLetterFallbacks,\n ...renderCJKFallbacks,\n EMOJI_METRICS_FAMILY\n ])\n familiesCache.set(key, resolved)\n return resolved\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,gBAAgB,IAAI,cAAgC,EAAE,YAAY,IAAI,CAAC;;;;;;AAoB7E,SAAgB,oBAAoB,MAAsC;CAExE,MAAM,YAAY,YAAY,KAAK,QAAQ,KAAK,MAAM;CACtD,MAAM,QACJ,YAAY,wBAAwB,KAAK,QAAQ,KAAK,SAAS,SAAS,KACxE,YAAY,wBAAwB,KAAK,QAAQ,SAAS,KAC1D,CAAC;CACH,MAAM,MAAM,KAAK,0BACb,CACE,GAAG,KAAK,WAAW,QAAQ,cAAc,UAAU,SAAS,MAAM,GAClE;EAAE,MAAM;EAAQ,OAAO,KAAK;CAAS,CACvC,IACA,KAAK;
|
|
1
|
+
{"version":3,"file":"font-families.js","names":[],"sources":["../../../src/canvas/text/font-families.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n\nimport type { FontVariation } from '@pairdraw/scene-graph'\nimport { faceLoadKey } from '@pairdraw/scene-graph/font-style'\n\nimport { ResourceCache } from '#core/cache/resource'\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { EMOJI_METRICS_FAMILY } from '#core/text/emoji'\nimport type { FaceWeight } from '#core/text/font/faces'\nimport { fontManager } from '#core/text/font/manager'\nimport { fontWeightMatchOrder } from '#core/text/font/style'\nimport type { FontAxis } from '#core/text/font/variation'\n\nconst familiesCache = new ResourceCache<string, string[]>({ maxEntries: 256 })\n\n/** What decides the axis values of a variable font text is drawn in. */\nexport interface DrawnFontAxes {\n family: string\n weight: number\n italic: boolean\n /** The face's key, as {@link faceStyleKey} gives it; its weight's key when left out. */\n style?: string\n fontSize: number\n /** The axes the text sets. */\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/**\n * The axis values text is drawn at, as Figma draws a variable font: its style's named instance,\n * then the axes it sets. While the optical size follows the font size, `opsz` is the font size and\n * a stored `opsz` is ignored. Fonts without an axis ignore its value.\n */\nexport function drawnFontVariations(font: DrawnFontAxes): FontVariation[] {\n // A face named apart from its weight (\"Condensed Bold\") is the instance of that name.\n const weightKey = faceLoadKey(font.weight, font.italic)\n const named =\n fontManager.namedInstanceVariations(font.family, font.style ?? weightKey) ??\n fontManager.namedInstanceVariations(font.family, weightKey) ??\n []\n const set = font.opticalSizeFromFontSize\n ? [\n ...font.variations.filter((variation) => variation.axis !== 'opsz'),\n { axis: 'opsz', value: font.fontSize }\n ]\n : font.variations\n const axes = new Map([...named, ...set].map(({ axis, value }) => [axis, value]))\n // A family with no face loaded is drawn in its fallbacks, and a variable fallback takes the\n // text's weight on its axis unless the text sets one, rather than emboldening its default one.\n if (!axes.has('wght') && !loadedFace(font.family, font.weight, font.italic, font.style)) {\n axes.set('wght', font.weight)\n }\n return [...axes].map(([axis, value]) => ({ axis, value }))\n}\n\n/** An axis of the variable font text is drawn in, with the value it is drawn at. */\nexport interface DrawnFontAxis extends FontAxis {\n value: number\n}\n\n/**\n * The axes of the variable font text is drawn in, in the font's order, each at the value it is\n * drawn at, within its range. `null` when the family's loaded faces are static or it has none.\n */\nexport function drawnFontAxes(font: DrawnFontAxes): DrawnFontAxis[] | null {\n const variation = fontManager.familyVariation(font.family, font.italic)\n if (!variation) return null\n const drawn = new Map(drawnFontVariations(font).map(({ axis, value }) => [axis, value]))\n return variation.axes.map((axis) => ({\n ...axis,\n value: Math.min(axis.max, Math.max(axis.min, drawn.get(axis.tag) ?? axis.default))\n }))\n}\n\n/** A loaded face text is drawn in: its weight and slant, and the key it is loaded under. */\nexport interface LoadedFace extends FaceWeight {\n style: string\n}\n\n/**\n * The loaded face of a family that text asking for a face is drawn in: that face, by its key,\n * or the nearest loaded weight in the same slant, then the other, as font matching picks it;\n * `null` when the family has none loaded.\n */\nexport function loadedFace(\n family: string,\n weight: number,\n italic: boolean,\n style = faceLoadKey(weight, italic)\n): LoadedFace | null {\n if (!fontManager.isLoaded(family)) return null\n if (fontManager.isStyleLoaded(family, style)) return { weight, italic, style }\n for (const slant of [italic, !italic]) {\n for (const candidate of fontWeightMatchOrder(weight)) {\n const key = faceLoadKey(candidate, slant)\n if (fontManager.isStyleLoaded(family, key))\n return { weight: candidate, italic: slant, style: key }\n }\n }\n return null\n}\n\n/**\n * The families a paragraph's text falls back through, by their own names: its family, the\n * default family, the fallbacks of scripts written in letters (Arabic, Hebrew, Thai,\n * Devanagari) and CJK, then emoji, so a character a script's font has\n * stays in that font. Fonts are read by these names; CanvasKit is asked for them as\n * {@link resolveParagraphFontFamilies} names them.\n */\nexport function paragraphSourceFamilies(\n primary: string,\n letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),\n cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()\n): string[] {\n return uniq([\n primary,\n ...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),\n ...letterFallbacks,\n ...cjkFallbacks,\n EMOJI_METRICS_FAMILY\n ])\n}\n\n/** `style` of `family` by the names CanvasKit draws it under: its own file, then its shards. */\nfunction renderFamilies(family: string, style: string): string[] {\n return [\n fontManager.renderFamily(family, style),\n ...fontManager.renderShardFamilies(family, style)\n ]\n}\n\n/**\n * The paragraph's families as CanvasKit is asked for them: the family in the face it draws the\n * face in, and its fallbacks, each by the names `renderFamilies` gives it.\n */\nexport function resolveParagraphFontFamilies(\n primary: string,\n face: { weight: number; italic: boolean; style: string },\n letterFallbacks: readonly string[] = fontManager.getLetterFallbackFamilies(),\n cjkFallbacks: readonly string[] = fontManager.getCJKFallbackFamilies()\n): string[] {\n // The face the family draws it in, which may be the nearest one loaded.\n const drawn = loadedFace(primary, face.weight, face.italic, face.style)\n const renderPrimary = renderFamilies(primary, drawn?.style ?? face.style)\n const renderLetterFallbacks = letterFallbacks.flatMap((family) =>\n renderFamilies(family, 'Regular')\n )\n const renderCJKFallbacks = cjkFallbacks.flatMap((family) => renderFamilies(family, 'Regular'))\n const key = [\n primary,\n ...renderPrimary,\n '',\n ...renderLetterFallbacks,\n '',\n ...renderCJKFallbacks\n ].join('\\0')\n const cached = familiesCache.peek(key)\n if (cached) return cached\n const resolved = uniq([\n ...renderPrimary,\n ...(primary === DEFAULT_FONT_FAMILY ? [] : [DEFAULT_FONT_FAMILY]),\n ...renderLetterFallbacks,\n ...renderCJKFallbacks,\n EMOJI_METRICS_FAMILY\n ])\n familiesCache.set(key, resolved)\n return resolved\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,gBAAgB,IAAI,cAAgC,EAAE,YAAY,IAAI,CAAC;;;;;;AAoB7E,SAAgB,oBAAoB,MAAsC;CAExE,MAAM,YAAY,YAAY,KAAK,QAAQ,KAAK,MAAM;CACtD,MAAM,QACJ,YAAY,wBAAwB,KAAK,QAAQ,KAAK,SAAS,SAAS,KACxE,YAAY,wBAAwB,KAAK,QAAQ,SAAS,KAC1D,CAAC;CACH,MAAM,MAAM,KAAK,0BACb,CACE,GAAG,KAAK,WAAW,QAAQ,cAAc,UAAU,SAAS,MAAM,GAClE;EAAE,MAAM;EAAQ,OAAO,KAAK;CAAS,CACvC,IACA,KAAK;CACT,MAAM,OAAO,IAAI,IAAI,CAAC,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,YAAY,CAAC,MAAM,KAAK,CAAC,CAAC;CAG/E,IAAI,CAAC,KAAK,IAAI,MAAM,KAAK,CAAC,WAAW,KAAK,QAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK,KAAK,GACpF,KAAK,IAAI,QAAQ,KAAK,MAAM;CAE9B,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY;EAAE;EAAM;CAAM,EAAE;AAC3D;;;;;AAWA,SAAgB,cAAc,MAA6C;CACzE,MAAM,YAAY,YAAY,gBAAgB,KAAK,QAAQ,KAAK,MAAM;CAC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K,QAAQ,KAAK,QAAQ,KAAK,KACf,CAAC,EAAE,SAAS,KAAK,KAAK;CACxE,MAAM,wBAAwB,gBAAgB,SAAS,WACrD,eAAe,QAAQ,SAAS,CAClC;CACA,MAAM,qBAAqB,aAAa,SAAS,WAAW,eAAe,QAAQ,SAAS,CAAC;CAC7F,MAAM,MAAM;EACV;EACA,GAAG;EACH;EACA,GAAG;EACH;EACA,GAAG;CACL,CAAC,CAAC,KAAK,IAAI;CACX,MAAM,SAAS,cAAc,KAAK,GAAG;CACrC,IAAI,QAAQ,OAAO;CACnB,MAAM,WAAW,KAAK;EACpB,GAAG;EACH,GAAI,YAAA,UAAkC,CAAC,IAAI,CAAC,mBAAmB;EAC/D,GAAG;EACH,GAAG;EACH;CACF,CAAC;CACD,cAAc,IAAI,KAAK,QAAQ;CAC/B,OAAO;AACT"}
|
|
@@ -14,8 +14,6 @@ declare function measureTextNode(r: TextRenderer, node: SceneNode, maxWidth?: nu
|
|
|
14
14
|
height: number;
|
|
15
15
|
} | null;
|
|
16
16
|
declare function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array | null;
|
|
17
|
-
/** Offset that places laid-out text of `contentHeight` in the node box by vertical alignment. */
|
|
18
|
-
declare function textVerticalOffset(node: SceneNode, contentHeight: number): number;
|
|
19
17
|
//#endregion
|
|
20
|
-
export { NodeFontReadiness, type ParagraphBuildOptions, type TextLayout, buildParagraph, buildTextPicture, isNodeFontLoaded, measureTextNode, nodeFontReadiness, textFontFeatures, textFontVariations, textHeightBehaviorValue,
|
|
18
|
+
export { NodeFontReadiness, type ParagraphBuildOptions, type TextLayout, buildParagraph, buildTextPicture, isNodeFontLoaded, measureTextNode, nodeFontReadiness, textFontFeatures, textFontVariations, textHeightBehaviorValue, withTextParagraph };
|
|
21
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/canvas/text/index.ts"],"mappings":";;;;;;;;KA8DY;iBA8GI,kBAAkB,GAAG,uBAAuB,MAAM,YAAY;iBAY9D,iBAAiB,GAAG,uBAAuB,MAAM;iBAKjD,gBACd,GAAG,cACH,MAAM,WACN;EACG;EAAe;;iBAyBJ,iBAAiB,GAAG,cAAc,MAAM,YAAY
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/canvas/text/index.ts"],"mappings":";;;;;;;;KA8DY;iBA8GI,kBAAkB,GAAG,uBAAuB,MAAM,YAAY;iBAY9D,iBAAiB,GAAG,uBAAuB,MAAM;iBAKjD,gBACd,GAAG,cACH,MAAM,WACN;EACG;EAAe;;iBAyBJ,iBAAiB,GAAG,cAAc,MAAM,YAAY"}
|
|
@@ -161,14 +161,7 @@ function buildTextPicture(r, node) {
|
|
|
161
161
|
picture.delete();
|
|
162
162
|
return bytes ?? null;
|
|
163
163
|
}
|
|
164
|
-
/** Offset that places laid-out text of `contentHeight` in the node box by vertical alignment. */
|
|
165
|
-
function textVerticalOffset(node, contentHeight) {
|
|
166
|
-
const available = Math.max(0, node.height - contentHeight);
|
|
167
|
-
if (node.textAlignVertical === "CENTER") return available / 2;
|
|
168
|
-
if (node.textAlignVertical === "BOTTOM") return available;
|
|
169
|
-
return 0;
|
|
170
|
-
}
|
|
171
164
|
//#endregion
|
|
172
|
-
export { buildParagraph, buildTextPicture, isNodeFontLoaded, measureTextNode, nodeFontReadiness, textFontFeatures, textFontVariations, textHeightBehaviorValue,
|
|
165
|
+
export { buildParagraph, buildTextPicture, isNodeFontLoaded, measureTextNode, nodeFontReadiness, textFontFeatures, textFontVariations, textHeightBehaviorValue, withTextParagraph };
|
|
173
166
|
|
|
174
167
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/canvas/text/index.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { fontManager } from '#core/text/font/manager'\nimport { textFontFace } from '#core/text/requirements/collect'\nimport {\n fontCoverageDemand,\n fontFaceDemand,\n fontRemoteCoverageDemand,\n fontResolver,\n missingGlyphOccurrences,\n missingGlyphsByScript\n} from '#core/text/resolver'\n\nimport { drawTextLayout } from './decorations'\nimport { buildParagraph } from './layout/build'\nimport { resolveParagraphLayoutWidth } from './paragraph'\nimport { withPreparedText } from './preparation'\nimport type { FontReadinessRenderer, TextRenderer } from './renderer'\n\nexport { buildParagraph } from './layout/build'\nexport type { TextLayout } from './layout'\nexport type { ParagraphBuildOptions } from './paint'\nexport { textFontFeatures, textFontVariations, textHeightBehaviorValue } from './paragraph'\nexport { withTextParagraph } from './preparation'\n\nfunction demandFace(\n r: FontReadinessRenderer,\n node: SceneNode,\n family: string,\n style: string\n): boolean {\n if (fontManager.isStyleLoaded(family, style)) return true\n const demand = fontFaceDemand(family, style, node.text)\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return false\n}\n\nfunction requiredNodeFaces(node: SceneNode): Array<{ family: string; style: string }> {\n const baseFamily = node.fontFamily || DEFAULT_FONT_FAMILY\n const faces = new Map<string, { family: string; style: string }>()\n const add = (family: string, style: string) => faces.set(`${family}\\0${style}`, { family, style })\n add(baseFamily, textFontFace(node).style)\n for (const run of node.styleRuns) {\n add(run.style.fontFamily ?? baseFamily, textFontFace(node, run.style).style)\n }\n return Array.from(faces.values())\n}\n\nfunction languageForCharacter(node: SceneNode, sourceIndex: number): string | null {\n const run = node.styleRuns.find(\n (item) => sourceIndex >= item.start && sourceIndex < item.start + item.length\n )\n return run?.style.textLanguage !== undefined ? run.style.textLanguage : node.textLanguage\n}\n\nfunction transformedSourceOffsets(node: SceneNode): number[] {\n return shownCharacters(node).map((shown) => shown.sourceIndex)\n}\n\nexport type NodeFontReadiness = 'ready' | 'substituted' | 'pending' | 'exhausted'\n\nfunction requiredFacesReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n let pending = false\n let exhausted = false\n for (const { family, style } of requiredNodeFaces(node)) {\n if (fontManager.isStyleLoaded(family, style)) continue\n const demand = fontFaceDemand(family, style, node.text)\n const state = fontResolver.state(demand).state\n demandFace(r, node, family, style)\n if (state === 'failed' || state === 'exhausted') {\n // A missing face is drawn in another loaded face of the family, as Figma draws it, and\n // reported missing; the text stays visible when an exact face (Italic) is unavailable.\n if (fontManager.isLoaded(family)) continue\n exhausted = true\n } else {\n pending = true\n }\n }\n if (pending) return 'pending'\n if (exhausted && fontManager.isStyleLoaded(DEFAULT_FONT_FAMILY, 'Regular')) return 'substituted'\n return exhausted ? 'exhausted' : 'ready'\n}\n\nfunction demandRemoteCoverage(r: TextRenderer, node: SceneNode, characters: string[]): boolean {\n for (const { family, style } of requiredNodeFaces(node)) {\n if (!fontManager.remoteStyleNeedsCoverage(family, style, characters)) continue\n const demand = fontRemoteCoverageDemand(family, style, characters)\n const state = fontResolver.state(demand).state\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return true\n }\n if (state === 'loading') return true\n if (state === 'loaded') fontResolver.exhaust(demand)\n }\n return false\n}\n\nfunction observedGlyphReadiness(r: TextRenderer, node: SceneNode): NodeFontReadiness {\n if (\n r.fontProvider &&\n r.textPreparationCache?.hasGlyphCoverage(node, fontManager.generation(), r.fontProvider)\n )\n return 'ready'\n\n const missingOccurrences = withPreparedText(\n r,\n node,\n 'coverage',\n () => buildParagraph(r, node),\n (prepared) => {\n if (!prepared.missingGlyphs) {\n prepared.paragraph.layout(resolveParagraphLayoutWidth(node))\n prepared.missingGlyphs = missingGlyphOccurrences(\n shownText(node),\n prepared.paragraph.getShapedLines(),\n transformedSourceOffsets(node)\n )\n }\n return prepared.missingGlyphs\n }\n )\n if (missingOccurrences.length === 0) {\n r.textPreparationCache?.recordGlyphCoverage(node)\n return 'ready'\n }\n\n const charactersByScript = missingGlyphsByScript(missingOccurrences, (offset) =>\n languageForCharacter(node, offset)\n )\n\n let pending = false\n let exhausted = charactersByScript.size === 0\n for (const [script, characters] of charactersByScript) {\n if (demandRemoteCoverage(r, node, characters)) {\n pending = true\n continue\n }\n\n const demand = fontCoverageDemand(script, characters)\n const state = fontResolver.state(demand).state\n if (state === 'loaded') {\n fontResolver.exhaust(demand)\n exhausted = true\n continue\n }\n if (state === 'exhausted' || state === 'failed') {\n exhausted = true\n continue\n }\n pending = true\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n }\n }\n // An export draws once: a face that has not arrived by then is not coming, and the characters\n // it would have covered keep the text's own fonts rather than leaving the layer blank.\n if (pending) return r.exportFontsSettled ? 'substituted' : 'pending'\n // Once no fallback is left for a character, the text draws with the fonts it has, the font's\n // missing-glyph box standing in for that character, rather than not at all.\n return exhausted ? 'substituted' : 'ready'\n}\n\nfunction canObserveGlyphCoverage(r: FontReadinessRenderer): r is TextRenderer {\n return r.ck !== undefined && r.fontProvider != null && r.fontsLoaded !== undefined\n}\n\nexport function nodeFontReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n if (node.type !== 'TEXT') return 'ready'\n const faces = requiredFacesReadiness(r, node)\n if (faces === 'pending' || faces === 'exhausted') return faces\n if (!node.text || !canObserveGlyphCoverage(r)) return faces\n const glyphs = observedGlyphReadiness(r, node)\n // Substituted text still needs script fallbacks (for example CJK) for glyphs the substitute\n // lacks, but stays visible when none can be found.\n if (faces === 'substituted') return glyphs === 'pending' ? 'pending' : 'substituted'\n return glyphs\n}\n\nexport function isNodeFontLoaded(r: FontReadinessRenderer, node: SceneNode): boolean {\n const readiness = nodeFontReadiness(r, node)\n return readiness === 'ready' || readiness === 'substituted'\n}\n\nexport function measureTextNode(\n r: TextRenderer,\n node: SceneNode,\n maxWidth?: number\n): { width: number; height: number } | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const layoutWidth = resolveParagraphLayoutWidth(node, maxWidth)\n const measure = () => {\n const paragraph = buildParagraph(r, node)\n paragraph.layout(layoutWidth)\n const width = paragraph.getLongestLine()\n const height = paragraph.getHeight()\n paragraph.delete()\n return { width: Math.ceil(width), height: Math.ceil(height) }\n }\n // Layout asks for the same text at the same width many times per pass.\n return r.textPreparationCache\n ? r.textPreparationCache.measure(\n node,\n layoutWidth,\n fontManager.generation(),\n r.fontProvider,\n measure\n )\n : measure()\n}\n\nexport function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const ck = r.ck\n const recorder = new ck.PictureRecorder()\n const bounds = ck.LTRBRect(0, 0, node.width || 1e6, node.height || 1e6)\n const recCanvas = recorder.beginRecording(bounds)\n\n const layout = buildParagraph(r, node)\n const paint = new ck.Paint()\n try {\n drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint)\n } finally {\n paint.delete()\n layout.delete()\n }\n\n const picture = recorder.finishRecordingAsPicture()\n recorder.delete()\n\n const bytes = picture.serialize()\n picture.delete()\n return bytes ?? null\n}\n\n/** Offset that places laid-out text of `contentHeight` in the node box by vertical alignment. */\nexport function textVerticalOffset(node: SceneNode, contentHeight: number): number {\n const available = Math.max(0, node.height - contentHeight)\n if (node.textAlignVertical === 'CENTER') return available / 2\n if (node.textAlignVertical === 'BOTTOM') return available\n return 0\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,WACP,GACA,MACA,QACA,OACS;CACT,IAAI,YAAY,cAAc,QAAQ,KAAK,GAAG,OAAO;CACrD,MAAM,SAAS,eAAe,QAAQ,OAAO,KAAK,IAAI;CACtD,EAAE,kBAAkB,MAAM,OAAO,GAAG;CACpC,aAAkB,cAAc,QAAQ,KAAK,IAAI,EAAE,uBAAuB;C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../src/canvas/text/index.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\nimport { DEFAULT_FONT_FAMILY } from '#core/constants'\nimport { shownCharacters, shownText } from '#core/text/case'\nimport { fontManager } from '#core/text/font/manager'\nimport { textFontFace } from '#core/text/requirements/collect'\nimport {\n fontCoverageDemand,\n fontFaceDemand,\n fontRemoteCoverageDemand,\n fontResolver,\n missingGlyphOccurrences,\n missingGlyphsByScript\n} from '#core/text/resolver'\n\nimport { drawTextLayout } from './decorations'\nimport { buildParagraph } from './layout/build'\nimport { resolveParagraphLayoutWidth } from './paragraph'\nimport { withPreparedText } from './preparation'\nimport type { FontReadinessRenderer, TextRenderer } from './renderer'\n\nexport { buildParagraph } from './layout/build'\nexport type { TextLayout } from './layout'\nexport type { ParagraphBuildOptions } from './paint'\nexport { textFontFeatures, textFontVariations, textHeightBehaviorValue } from './paragraph'\nexport { withTextParagraph } from './preparation'\n\nfunction demandFace(\n r: FontReadinessRenderer,\n node: SceneNode,\n family: string,\n style: string\n): boolean {\n if (fontManager.isStyleLoaded(family, style)) return true\n const demand = fontFaceDemand(family, style, node.text)\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return false\n}\n\nfunction requiredNodeFaces(node: SceneNode): Array<{ family: string; style: string }> {\n const baseFamily = node.fontFamily || DEFAULT_FONT_FAMILY\n const faces = new Map<string, { family: string; style: string }>()\n const add = (family: string, style: string) => faces.set(`${family}\\0${style}`, { family, style })\n add(baseFamily, textFontFace(node).style)\n for (const run of node.styleRuns) {\n add(run.style.fontFamily ?? baseFamily, textFontFace(node, run.style).style)\n }\n return Array.from(faces.values())\n}\n\nfunction languageForCharacter(node: SceneNode, sourceIndex: number): string | null {\n const run = node.styleRuns.find(\n (item) => sourceIndex >= item.start && sourceIndex < item.start + item.length\n )\n return run?.style.textLanguage !== undefined ? run.style.textLanguage : node.textLanguage\n}\n\nfunction transformedSourceOffsets(node: SceneNode): number[] {\n return shownCharacters(node).map((shown) => shown.sourceIndex)\n}\n\nexport type NodeFontReadiness = 'ready' | 'substituted' | 'pending' | 'exhausted'\n\nfunction requiredFacesReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n let pending = false\n let exhausted = false\n for (const { family, style } of requiredNodeFaces(node)) {\n if (fontManager.isStyleLoaded(family, style)) continue\n const demand = fontFaceDemand(family, style, node.text)\n const state = fontResolver.state(demand).state\n demandFace(r, node, family, style)\n if (state === 'failed' || state === 'exhausted') {\n // A missing face is drawn in another loaded face of the family, as Figma draws it, and\n // reported missing; the text stays visible when an exact face (Italic) is unavailable.\n if (fontManager.isLoaded(family)) continue\n exhausted = true\n } else {\n pending = true\n }\n }\n if (pending) return 'pending'\n if (exhausted && fontManager.isStyleLoaded(DEFAULT_FONT_FAMILY, 'Regular')) return 'substituted'\n return exhausted ? 'exhausted' : 'ready'\n}\n\nfunction demandRemoteCoverage(r: TextRenderer, node: SceneNode, characters: string[]): boolean {\n for (const { family, style } of requiredNodeFaces(node)) {\n if (!fontManager.remoteStyleNeedsCoverage(family, style, characters)) continue\n const demand = fontRemoteCoverageDemand(family, style, characters)\n const state = fontResolver.state(demand).state\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n return true\n }\n if (state === 'loading') return true\n if (state === 'loaded') fontResolver.exhaust(demand)\n }\n return false\n}\n\nfunction observedGlyphReadiness(r: TextRenderer, node: SceneNode): NodeFontReadiness {\n if (\n r.fontProvider &&\n r.textPreparationCache?.hasGlyphCoverage(node, fontManager.generation(), r.fontProvider)\n )\n return 'ready'\n\n const missingOccurrences = withPreparedText(\n r,\n node,\n 'coverage',\n () => buildParagraph(r, node),\n (prepared) => {\n if (!prepared.missingGlyphs) {\n prepared.paragraph.layout(resolveParagraphLayoutWidth(node))\n prepared.missingGlyphs = missingGlyphOccurrences(\n shownText(node),\n prepared.paragraph.getShapedLines(),\n transformedSourceOffsets(node)\n )\n }\n return prepared.missingGlyphs\n }\n )\n if (missingOccurrences.length === 0) {\n r.textPreparationCache?.recordGlyphCoverage(node)\n return 'ready'\n }\n\n const charactersByScript = missingGlyphsByScript(missingOccurrences, (offset) =>\n languageForCharacter(node, offset)\n )\n\n let pending = false\n let exhausted = charactersByScript.size === 0\n for (const [script, characters] of charactersByScript) {\n if (demandRemoteCoverage(r, node, characters)) {\n pending = true\n continue\n }\n\n const demand = fontCoverageDemand(script, characters)\n const state = fontResolver.state(demand).state\n if (state === 'loaded') {\n fontResolver.exhaust(demand)\n exhausted = true\n continue\n }\n if (state === 'exhausted' || state === 'failed') {\n exhausted = true\n continue\n }\n pending = true\n if (state === 'idle') {\n r.trackFontDemand?.(node, demand.key)\n void fontResolver.demandForNode(demand, node.id, r.onFontResolutionSettled)\n }\n }\n // An export draws once: a face that has not arrived by then is not coming, and the characters\n // it would have covered keep the text's own fonts rather than leaving the layer blank.\n if (pending) return r.exportFontsSettled ? 'substituted' : 'pending'\n // Once no fallback is left for a character, the text draws with the fonts it has, the font's\n // missing-glyph box standing in for that character, rather than not at all.\n return exhausted ? 'substituted' : 'ready'\n}\n\nfunction canObserveGlyphCoverage(r: FontReadinessRenderer): r is TextRenderer {\n return r.ck !== undefined && r.fontProvider != null && r.fontsLoaded !== undefined\n}\n\nexport function nodeFontReadiness(r: FontReadinessRenderer, node: SceneNode): NodeFontReadiness {\n if (node.type !== 'TEXT') return 'ready'\n const faces = requiredFacesReadiness(r, node)\n if (faces === 'pending' || faces === 'exhausted') return faces\n if (!node.text || !canObserveGlyphCoverage(r)) return faces\n const glyphs = observedGlyphReadiness(r, node)\n // Substituted text still needs script fallbacks (for example CJK) for glyphs the substitute\n // lacks, but stays visible when none can be found.\n if (faces === 'substituted') return glyphs === 'pending' ? 'pending' : 'substituted'\n return glyphs\n}\n\nexport function isNodeFontLoaded(r: FontReadinessRenderer, node: SceneNode): boolean {\n const readiness = nodeFontReadiness(r, node)\n return readiness === 'ready' || readiness === 'substituted'\n}\n\nexport function measureTextNode(\n r: TextRenderer,\n node: SceneNode,\n maxWidth?: number\n): { width: number; height: number } | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const layoutWidth = resolveParagraphLayoutWidth(node, maxWidth)\n const measure = () => {\n const paragraph = buildParagraph(r, node)\n paragraph.layout(layoutWidth)\n const width = paragraph.getLongestLine()\n const height = paragraph.getHeight()\n paragraph.delete()\n return { width: Math.ceil(width), height: Math.ceil(height) }\n }\n // Layout asks for the same text at the same width many times per pass.\n return r.textPreparationCache\n ? r.textPreparationCache.measure(\n node,\n layoutWidth,\n fontManager.generation(),\n r.fontProvider,\n measure\n )\n : measure()\n}\n\nexport function buildTextPicture(r: TextRenderer, node: SceneNode): Uint8Array | null {\n if (!r.fontsLoaded || !r.fontProvider || !isNodeFontLoaded(r, node)) return null\n if (node.type !== 'TEXT' || !node.text) return null\n\n const ck = r.ck\n const recorder = new ck.PictureRecorder()\n const bounds = ck.LTRBRect(0, 0, node.width || 1e6, node.height || 1e6)\n const recCanvas = recorder.beginRecording(bounds)\n\n const layout = buildParagraph(r, node)\n const paint = new ck.Paint()\n try {\n drawTextLayout(ck, recCanvas, node, { paragraph: layout }, 0, paint)\n } finally {\n paint.delete()\n layout.delete()\n }\n\n const picture = recorder.finishRecordingAsPicture()\n recorder.delete()\n\n const bytes = picture.serialize()\n picture.delete()\n return bytes ?? null\n}\n"],"mappings":";;;;;;;;;;;AA2BA,SAAS,WACP,GACA,MACA,QACA,OACS;CACT,IAAI,YAAY,cAAc,QAAQ,KAAK,GAAG,OAAO;CACrD,MAAM,SAAS,eAAe,QAAQ,OAAO,KAAK,IAAI;CACtD,EAAE,kBAAkB,MAAM,OAAO,GAAG;CACpC,aAAkB,cAAc,QAAQ,KAAK,IAAI,EAAE,uBAAuB;CAC1E,OAAO;AACT;AAEA,SAAS,kBAAkB,MAA2D;CACpF,MAAM,aAAa,KAA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;EACvC,MAAM,SAAS,UAAU,UAAU;EACnC,UAAU,OAAO;EACjB,OAAO;GAAE,OAAO,KAAK,KAAK,KAAK;GAAG,QAAQ,KAAK,KAAK,MAAM;EAAE;CAC9D;CAEA,OAAO,EAAE,uBACL,EAAE,qBAAqB,QACrB,MACA,aACA,YAAY,WAAW,GACvB,EAAE,cACF,OACF,IACA,QAAQ;AACd;AAEA,SAAgB,iBAAiB,GAAiB,MAAoC;CACpF,IAAI,CAAC,EAAE,eAAe,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,GAAG,IAAI,GAAG,OAAO;CAC5E,IAAI,KAAK,SAAS,UAAU,CAAC,KAAK,MAAM,OAAO;CAE/C,MAAM,KAAK,EAAE;CACb,MAAM,WAAW,IAAI,GAAG,gBAAgB;CACxC,MAAM,SAAS,GAAG,SAAS,GAAG,GAAG,KAAK,SAAS,KAAK,KAAK,UAAU,GAAG;CACtE,MAAM,YAAY,SAAS,eAAe,MAAM;CAEhD,MAAM,SAAS,eAAe,GAAG,IAAI;CACrC,MAAM,QAAQ,IAAI,GAAG,MAAM;CAC3B,IAAI;EACF,eAAe,IAAI,WAAW,MAAM,EAAE,WAAW,OAAO,GAAG,GAAG,KAAK;CACrE,UAAU;EACR,MAAM,OAAO;EACb,OAAO,OAAO;CAChB;CAEA,MAAM,UAAU,SAAS,yBAAyB;CAClD,SAAS,OAAO;CAEhB,MAAM,QAAQ,QAAQ,UAAU;CAChC,QAAQ,OAAO;CACf,OAAO,SAAS;AAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","names":[],"sources":["../../../../src/canvas/text/layout/build.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"build.d.ts","names":[],"sources":["../../../../src/canvas/text/layout/build.ts"],"mappings":";;;;;;iBAuYgB,eACd,GAAG,cACH,MAAM,eACN,QAAQ,cACR,UAAS,wBACR"}
|