@pairdraw/core 0.17.0 → 0.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/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/outline-stroke.d.ts.map +1 -1
- package/dist/canvas/outline-stroke.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/prototype.d.ts +2 -5
- package/dist/canvas/overlays/prototype.d.ts.map +1 -1
- package/dist/canvas/overlays/prototype.js +3 -19
- package/dist/canvas/overlays/prototype.js.map +1 -1
- 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 +25 -10
- 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 +26 -7
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +50 -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 +90 -54
- 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 +4 -3
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +13 -9
- 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 +2 -9
- 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 +18 -9
- 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 +3 -3
- package/dist/canvas/text/placed.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -0
- package/dist/canvas/text/renderer.d.ts.map +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/design-jsx/renderer.d.ts.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/bridges/undo.d.ts +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 +18 -4
- 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 +63 -10
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +104 -17
- 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 +12 -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/connectors.js +2 -14
- package/dist/geometry/connectors.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 +3 -3
- package/dist/geometry/index.js +2 -2
- package/dist/geometry/scene.d.ts +3 -1
- package/dist/geometry/scene.d.ts.map +1 -1
- package/dist/geometry/scene.js +16 -1
- package/dist/geometry/scene.js.map +1 -1
- package/dist/geometry/types.d.ts +7 -1
- package/dist/geometry/types.d.ts.map +1 -1
- 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/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/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +10 -0
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +32 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/shapes.d.ts +10 -5
- package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
- package/dist/io/formats/drawio/shapes.js +10 -6
- package/dist/io/formats/drawio/shapes.js.map +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +11 -0
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
- package/dist/io/formats/drawio/warnings.js +23 -0
- package/dist/io/formats/drawio/warnings.js.map +1 -0
- 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 +10 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +96 -2
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +3 -2
- package/dist/io/formats/pdf/export.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 +3 -3
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +25 -14
- 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 +8 -2
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +42 -8
- 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/formats.d.ts.map +1 -1
- package/dist/io/formats.js +3 -1
- package/dist/io/formats.js.map +1 -1
- package/dist/io/registry.d.ts +2 -0
- package/dist/io/registry.d.ts.map +1 -1
- package/dist/io/registry.js +5 -0
- package/dist/io/registry.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/io/types.d.ts +2 -0
- package/dist/io/types.d.ts.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 +11 -2
- package/dist/library/snapshot.js.map +1 -1
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +11 -2
- package/dist/lint/linter.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/rpc/variables-command.d.ts.map +1 -1
- package/dist/rpc/variables-command.js +4 -2
- package/dist/rpc/variables-command.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 +16 -14
- 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 +26 -3
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +135 -18
- 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 +50 -6
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +178 -32
- 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 +71 -71
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/path/caret.d.ts +2 -4
- package/dist/text/path/caret.d.ts.map +1 -1
- package/dist/text/path/caret.js.map +1 -1
- package/dist/text/prepare.d.ts +5 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +26 -3
- 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/text/web-font/assets.d.ts.map +1 -1
- package/dist/text/web-font/assets.js +13 -21
- package/dist/text/web-font/assets.js.map +1 -1
- package/dist/text/web-font/resolver.d.ts.map +1 -1
- package/dist/text/web-font/resolver.js +4 -1
- package/dist/text/web-font/resolver.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/components.d.ts +2 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +27 -1
- package/dist/tools/create/components.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 +14 -6
- 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 +13 -10
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/create.d.ts +2 -2
- package/dist/tools/create.js +2 -2
- 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/effects.d.ts.map +1 -1
- package/dist/tools/modify/effects.js +5 -3
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +9 -6
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +7 -5
- package/dist/tools/modify/paint.js.map +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/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +28 -8
- package/dist/tools/modify/text.js.map +1 -1
- 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 +18 -4
- 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 +6 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +30 -5
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +125 -7
- 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 +86 -90
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -2
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/export.d.ts.map +1 -1
- package/dist/tools/vector/export.js +5 -2
- package/dist/tools/vector/export.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/outline-stroke.ts +2 -6
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/prototype.ts +5 -27
- 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 +42 -18
- 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 +43 -11
- package/src/canvas/rulers.ts +55 -26
- package/src/canvas/scene.ts +127 -77
- 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 +14 -7
- package/src/canvas/text/index.ts +3 -9
- 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 +19 -10
- package/src/canvas/text/paragraph/inputs.ts +4 -2
- package/src/canvas/text/placed.ts +2 -2
- package/src/canvas/text/renderer.ts +2 -0
- 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 +170 -19
- 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 +16 -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/connectors.ts +2 -12
- package/src/geometry/figma.ts +9 -0
- package/src/geometry/index.ts +2 -1
- package/src/geometry/scene.ts +19 -0
- package/src/geometry/types.ts +8 -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/drawio/export.ts +11 -0
- package/src/io/formats/drawio/index.ts +36 -1
- package/src/io/formats/drawio/shapes.ts +13 -9
- package/src/io/formats/drawio/warnings.ts +27 -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 +125 -3
- package/src/io/formats/pdf/export.ts +3 -2
- 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 +40 -14
- package/src/io/formats/raster/index.ts +3 -0
- package/src/io/formats/raster/render.ts +66 -8
- 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/formats.ts +3 -1
- package/src/io/registry.ts +12 -0
- package/src/io/subgraph.ts +3 -1
- package/src/io/types.ts +2 -0
- 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 +12 -2
- package/src/lint/linter.ts +12 -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/rpc/variables-command.ts +6 -5
- package/src/text/character-style.ts +29 -9
- package/src/text/coverage.ts +29 -15
- package/src/text/editor.ts +3 -8
- package/src/text/fallbacks.ts +163 -22
- 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 +220 -49
- package/src/text/font/style.ts +52 -3
- package/src/text/index.ts +1 -0
- package/src/text/outlines.ts +106 -90
- package/src/text/path/caret.ts +3 -4
- package/src/text/prepare.ts +51 -2
- package/src/text/style-runs.ts +43 -16
- package/src/text/web-font/assets.ts +11 -15
- package/src/text/web-font/resolver.ts +7 -1
- 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/components.ts +33 -0
- package/src/tools/create/html.ts +3 -1
- package/src/tools/create/icons.ts +16 -6
- 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 +20 -10
- package/src/tools/create.ts +1 -0
- package/src/tools/image-ai/generate.ts +3 -0
- package/src/tools/modify/effects.ts +11 -4
- package/src/tools/modify/matching.ts +10 -6
- package/src/tools/modify/paint.ts +13 -5
- package/src/tools/modify/reactions.ts +40 -0
- package/src/tools/modify/text.ts +53 -20
- 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 +24 -4
- package/src/tools/read/nodes.ts +47 -17
- package/src/tools/read/pages.ts +7 -3
- 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 +6 -0
- package/src/tools/schema.ts +166 -6
- package/src/tools/stock-photo/apply.ts +17 -5
- package/src/tools/structure/batch.ts +84 -98
- package/src/tools/variables/values.ts +6 -3
- package/src/tools/vector/export.ts +5 -1
- 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":"index.js","names":[],"sources":["../../../../src/canvas/text/layout/index.ts"],"sourcesContent":["import type {\n Canvas,\n CanvasKit,\n LineMetrics,\n Paragraph,\n PositionWithAffinity,\n RectHeightStyle,\n RectWidthStyle,\n RectWithDirection,\n ShapedLine\n} from 'canvaskit-wasm'\n\nimport {\n placeLines,\n shapedLinesByLine,\n type BlockPlacement,\n type TextLayoutBlockLines\n} from '#core/canvas/text/layout/lines'\n\n/** A list item's number or bullet, laid out on its own. */\nexport interface TextLayoutMarker {\n paragraph: Paragraph\n kind: 'bullet' | 'number'\n /** Font size of the list's first character, which sets the marker's distance from the text. */\n em: number\n /** The face the marker is set in, for its glyph outlines. */\n face: { family: string; style: string }\n /** Where the marker is drawn and the line of the item it marks, set by layout. */\n x: number\n y: number\n lineNumber: number\n}\n\n/** One paragraph of the text, or the whole text when it needs no paragraph layout of its own. */\nexport interface TextLayoutBlock {\n paragraph: Paragraph\n /** Rebuilds the paragraph to show at most `maxLines` lines, when the text is truncated. */\n rebuild?: (maxLines: number) => Paragraph\n /** The first character the block holds, as an index into the text and in UTF-8 bytes. */\n start: number\n utf8Start: number\n /** Characters the block holds, not counting the newline that ends it. */\n length: number\n /** Indices before the text, in UTF-16 and UTF-8, and its width: a first-line indent. */\n lead: number\n utf8Lead: number\n leadWidth: number\n /** Laid out from a space, standing for a paragraph with no characters. */\n empty: boolean\n /** Distance of the text from the start edge: a list item's indent. */\n inset: number\n rtl: boolean\n /** Space above the block, from the paragraph before it. */\n spaceBefore: number\n marker: TextLayoutMarker | null\n /** What placing its lines as Figma does needs; without it they stack as the paragraph's. */\n lines?: TextLayoutBlockLines\n x: number\n y: number\n /** Whether the block is shown, as truncation hides blocks past its last line. */\n visible: boolean\n}\n\nexport interface TextCaretBox {\n x: number\n top: number\n bottom: number\n}\n\n/**\n * A laid-out text node: one native paragraph per block, stacked with paragraph and list\n * spacing, each indented by its list level and preceded by its marker. It answers the\n * `Paragraph` queries the renderer, measurement, and the text editor ask, in indices of the\n * whole text and coordinates of the whole layout.\n */\nexport class TextLayout {\n private lines: LineMetrics[] = []\n private lineOffsets: number[] = []\n private truncated = false\n private readonly placements = new Map<TextLayoutBlock, BlockPlacement>()\n /** The text's height when layout placed its lines itself. */\n private placedHeight: number | null = null\n\n /** Text laid out as one native paragraph of `length` characters, not yet laid out. */\n static ofParagraph(\n ck: CanvasKit,\n paragraph: Paragraph,\n length: number,\n lines?: TextLayoutBlockLines\n ): TextLayout {\n return new TextLayout(ck, [\n {\n paragraph,\n start: 0,\n utf8Start: 0,\n length,\n lead: 0,\n utf8Lead: 0,\n leadWidth: 0,\n empty: false,\n inset: 0,\n rtl: false,\n spaceBefore: 0,\n marker: null,\n lines,\n x: 0,\n y: 0,\n visible: true\n }\n ])\n }\n\n constructor(\n private readonly ck: CanvasKit,\n readonly blocks: TextLayoutBlock[],\n /** Lines the text may show in all, when it is truncated across blocks. */\n private readonly maxLines?: number\n ) {}\n\n /** The line cap a block's paragraph was rebuilt with, when it differs from `maxLines`. */\n private readonly caps = new Map<TextLayoutBlock, number>()\n\n private visibleBlocks(): TextLayoutBlock[] {\n return this.blocks.filter((block) => block.visible)\n }\n\n layout(width: number): void {\n let y = 0\n let lines = 0\n this.truncated = false\n this.clearPlacements()\n for (const [index, block] of this.blocks.entries()) {\n const remaining = this.maxLines === undefined ? Infinity : this.maxLines - lines\n block.visible = remaining > 0\n if (!block.visible) {\n this.truncated = true\n continue\n }\n block.paragraph.layout(Math.max(1, width - block.inset))\n // A block capped for a narrower layout gets its lines back when there is room for them.\n const cap = this.caps.get(block) ?? this.maxLines ?? Infinity\n const overflows = block.paragraph.getLineMetrics().length > remaining\n const clipped = cap < remaining && block.paragraph.didExceedMaxLines()\n if ((overflows || clipped) && block.rebuild) {\n block.paragraph.delete()\n block.paragraph = block.rebuild(remaining)\n this.caps.set(block, remaining)\n block.paragraph.layout(Math.max(1, width - block.inset))\n }\n if (block.paragraph.didExceedMaxLines()) this.truncated = true\n if (index > 0) y += block.spaceBefore\n block.x = block.rtl ? 0 : block.inset\n block.y = y\n y += block.paragraph.getHeight()\n lines += block.paragraph.getLineMetrics().length\n }\n this.placeLines(width)\n for (const block of this.visibleBlocks()) this.placeMarker(block)\n this.collectLines()\n }\n\n private clearPlacements(): void {\n for (const placement of this.placements.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n this.placements.clear()\n this.placedHeight = null\n }\n\n /**\n * Places lines as Figma does when they differ in height, keeping the paragraph's placement\n * otherwise (`placeLines`).\n */\n private placeLines(width: number): void {\n const placed = placeLines(this.ck, this.visibleBlocks(), width)\n if (!placed) return\n for (const [block, { y, ...placement }] of placed.blocks) {\n block.y = y\n this.placements.set(block, placement)\n }\n this.placedHeight = placed.height\n }\n\n /** The block's line `index` stands this far below where its paragraph has it. */\n private lineOffset(block: TextLayoutBlock, index: number): number {\n return this.placements.get(block)?.offsets[index] ?? 0\n }\n\n /** How far a point `y` of the block's paragraph moves, by the line it falls on. */\n private offsetAt(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return 0\n const lines = block.paragraph.getLineMetrics()\n const index = lines.findIndex((line) => y < line.baseline + line.descent)\n return placement.offsets[index === -1 ? lines.length - 1 : index] ?? 0\n }\n\n private blockHeight(block: TextLayoutBlock): number {\n return this.placements.get(block)?.height ?? block.paragraph.getHeight()\n }\n\n private placeMarker(block: TextLayoutBlock): void {\n const marker = block.marker\n const first = block.paragraph.getLineMetrics().at(0)\n if (!marker || !first) return\n const markerLine = marker.paragraph.getLineMetrics().at(0)\n const width = marker.paragraph.getLongestLine()\n // A bullet centres on the middle of the indent; a number ends a third of an em before the\n // text, so numbers of any width line up on their periods.\n if (block.rtl) {\n const start = block.x + first.left + first.width\n marker.x =\n marker.kind === 'bullet' ? start + marker.em * 0.75 - width / 2 : start + marker.em / 3\n } else {\n const start = block.x + first.left\n marker.x =\n marker.kind === 'bullet'\n ? start - marker.em * 0.75 - width / 2\n : start - marker.em / 3 - width\n }\n marker.y = block.y + first.baseline - (markerLine?.baseline ?? 0)\n }\n\n private toTextIndex(block: TextLayoutBlock, index: number): number {\n return block.start + Math.max(0, Math.min(block.length, index - block.lead))\n }\n\n private collectLines(): void {\n this.lines = []\n this.lineOffsets = []\n const visible = this.visibleBlocks()\n for (const [blockIndex, block] of visible.entries()) {\n this.lineOffsets.push(this.lines.length)\n if (block.marker) block.marker.lineNumber = this.lines.length\n const metrics = block.paragraph.getLineMetrics()\n const boxes = this.placements.get(block)?.boxes\n const blockEnd = block.start + block.length\n for (const [lineIndex, line] of metrics.entries()) {\n const lastOfBlock = lineIndex === metrics.length - 1\n const endsAtNewline = lastOfBlock && blockIndex < visible.length - 1\n // A first-line indent is room before the text, not part of the line.\n const indent = lineIndex === 0 ? block.leadWidth : 0\n const box = boxes?.[lineIndex]\n this.lines.push({\n ...line,\n ...(box && {\n ascent: box.ascent,\n descent: box.height - box.ascent,\n height: box.height\n }),\n startIndex: this.toTextIndex(block, line.startIndex),\n endIndex: this.toTextIndex(block, line.endIndex),\n endExcludingWhitespaces: this.toTextIndex(block, line.endExcludingWhitespaces),\n endIncludingNewline: endsAtNewline\n ? blockEnd + 1\n : this.toTextIndex(block, line.endIncludingNewline),\n isHardBreak: endsAtNewline || line.isHardBreak,\n width: block.empty ? 0 : line.width - indent,\n left: line.left + block.x + (block.rtl ? 0 : indent),\n baseline: line.baseline + block.y + this.lineOffset(block, lineIndex),\n lineNumber: this.lines.length\n })\n }\n }\n }\n\n getHeight(): number {\n const last = this.visibleBlocks().at(-1)\n if (this.placedHeight !== null) return this.placedHeight\n return last ? last.y + last.paragraph.getHeight() : 0\n }\n\n getLongestLine(): number {\n let longest = 0\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n longest = Math.max(longest, block.inset + block.paragraph.getLongestLine())\n }\n return longest\n }\n\n didExceedMaxLines(): boolean {\n return this.truncated\n }\n\n getLineMetrics(): LineMetrics[] {\n return this.lines\n }\n\n getLineMetricsAt(lineNumber: number): LineMetrics | null {\n return this.lines[lineNumber] ?? null\n }\n\n /** The block holding text index `index`; the newline ending a block belongs to it. */\n private blockAt(index: number): { block: TextLayoutBlock; order: number } | null {\n const visible = this.visibleBlocks()\n for (const [order, block] of visible.entries()) {\n if (index <= block.start + block.length) return { block, order }\n }\n const last = visible.at(-1)\n return last ? { block: last, order: visible.length - 1 } : null\n }\n\n getLineNumberAt(index: number): number {\n const found = this.blockAt(index)\n if (!found) return -1\n const { block, order } = found\n const local = block.empty\n ? 0\n : block.paragraph.getLineNumberAt(index - block.start + block.lead)\n const isLast = order === this.lineOffsets.length - 1\n if (local < 0) {\n if (isLast) return local\n return this.lineOffsets[order] + block.paragraph.getLineMetrics().length - 1\n }\n return this.lineOffsets[order] + local\n }\n\n getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity {\n const visible = this.visibleBlocks()\n let block = visible.at(-1)\n for (const [index, candidate] of visible.entries()) {\n const next = visible.at(index + 1)\n const bottom = candidate.y + this.blockHeight(candidate)\n if (!next || y < bottom + next.spaceBefore / 2) {\n block = candidate\n break\n }\n }\n if (!block) return { pos: 0, affinity: this.ck.Affinity.Downstream }\n const local = block.paragraph.getGlyphPositionAtCoordinate(\n x - block.x,\n this.paragraphY(block, y - block.y)\n )\n return {\n pos: block.empty ? block.start : this.toTextIndex(block, local.pos),\n affinity: local.affinity\n }\n }\n\n getRectsForRange(\n start: number,\n end: number,\n heightStyle: RectHeightStyle,\n widthStyle: RectWidthStyle\n ): RectWithDirection[] {\n const rects: RectWithDirection[] = []\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n const from = Math.max(start, block.start)\n const to = Math.min(end, block.start + block.length)\n if (to <= from) continue\n const local = block.paragraph.getRectsForRange(\n from - block.start + block.lead,\n to - block.start + block.lead,\n heightStyle,\n widthStyle\n )\n for (const { rect, dir } of local) {\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n rects.push({\n rect: Float32Array.of(rect[0] + block.x, rect[1] + y, rect[2] + block.x, rect[3] + y),\n dir\n })\n }\n }\n return rects\n }\n\n /**\n * Where the caret stands before text index `index`: at the start edge of the character\n * there, or after the last character of its paragraph.\n */\n getCaretRect(index: number, rtl: boolean): TextCaretBox | null {\n const found = this.blockAt(index)\n if (!found) return null\n const { block } = found\n const local = index - block.start\n const first = block.paragraph.getLineMetrics().at(0)\n if (block.empty || block.length === 0) {\n if (!first) return null\n const top = block.y + first.baseline - first.ascent\n // The caret stands where typing starts: after a first-line indent.\n return {\n x: block.x + first.left + (rtl ? first.width - block.leadWidth : block.leadWidth),\n top,\n bottom: top + first.height\n }\n }\n const after = this.caretAfterLineBreak(block, local)\n if (after) return after\n let lo = local\n let hi = local + 1\n let useRight = false\n if (local <= 0) {\n lo = 0\n hi = 1\n useRight = rtl\n } else if (local >= block.length) {\n lo = block.length - 1\n hi = block.length\n useRight = !rtl\n }\n // The box of the whole character beside the caret: half an emoji or a surrogate pair has none.\n const cluster = block.paragraph.getGlyphInfoAt(lo + block.lead)?.graphemeClusterTextRange\n const rects = block.paragraph.getRectsForRange(\n cluster?.start ?? lo + block.lead,\n cluster?.end ?? hi + block.lead,\n this.ck.RectHeightStyle.Max,\n this.ck.RectWidthStyle.Tight\n )\n const rect = rects.at(0)?.rect\n if (!rect) return null\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n return {\n x: block.x + (useRight ? rect[2] : rect[0]),\n top: y + rect[1],\n bottom: y + rect[3]\n }\n }\n\n /**\n * The caret after a line break that ends the paragraph: at the start of the empty line Skia\n * lays out below it, where typing goes, not after the break on the line above.\n */\n private caretAfterLineBreak(block: TextLayoutBlock, local: number): TextCaretBox | null {\n if (local < block.length) return null\n const lines = block.paragraph.getLineMetrics()\n const last = lines.at(-1)\n const previous = lines.at(-2)\n if (!last || !previous?.isHardBreak || last.endIndex > previous.endIncludingNewline) return null\n const lineTop = last.baseline - last.ascent\n const y = block.y + this.offsetAt(block, lineTop + last.height / 2)\n return { x: block.x + last.left, top: y + lineTop, bottom: y + lineTop + last.height }\n }\n\n /**\n * Shaped lines of the text in whole-text coordinates, one per line; run offsets are UTF-8\n * byte offsets into the whole text, as CanvasKit gives them. An empty line, which shaping\n * leaves out, has no runs and starts where the line before it ends.\n */\n getShapedLines(): ShapedLine[] {\n const shaped: ShapedLine[] = []\n for (const block of this.visibleBlocks()) {\n const metrics = block.paragraph.getLineMetrics()\n for (const [lineIndex, line] of shapedLinesByLine(block.paragraph).entries()) {\n const y = block.y + this.lineOffset(block, lineIndex)\n if (!line) {\n const { baseline, ascent, descent } = metrics[lineIndex]\n const previous = lineIndex > 0 ? shaped.at(-1) : undefined\n const start = previous?.textRange.last ?? block.utf8Start\n shaped.push({\n textRange: { first: start, last: start },\n top: baseline - ascent + y,\n bottom: baseline + descent + y,\n baseline: baseline + y,\n runs: []\n })\n continue\n }\n shaped.push({\n textRange: {\n first: this.toUtf8(block, line.textRange.first),\n last: this.toUtf8(block, line.textRange.last)\n },\n top: line.top + y,\n bottom: line.bottom + y,\n baseline: line.baseline + y,\n runs: block.empty\n ? []\n : line.runs.map((run) => ({\n ...run,\n positions: run.positions.map(\n (value, index) => value + (index % 2 === 0 ? block.x : y)\n ),\n offsets: run.offsets.map((offset) => this.toUtf8(block, offset))\n }))\n })\n }\n }\n return shaped\n }\n\n private toUtf8(block: TextLayoutBlock, offset: number): number {\n return block.empty ? block.utf8Start : block.utf8Start + Math.max(0, offset - block.utf8Lead)\n }\n\n /** Markers of the visible list items, where layout placed them. */\n getMarkers(): TextLayoutMarker[] {\n const markers: TextLayoutMarker[] = []\n for (const block of this.visibleBlocks()) if (block.marker) markers.push(block.marker)\n return markers\n }\n\n draw(canvas: Canvas, x: number, y: number): void {\n for (const block of this.visibleBlocks()) {\n const pieces = this.placements.get(block)?.pieces\n if (!pieces) canvas.drawParagraph(block.paragraph, x + block.x, y + block.y)\n for (const piece of pieces ?? []) {\n canvas.drawParagraph(piece.paragraph, x + block.x + piece.x, y + block.y + piece.y)\n }\n const marker = block.marker\n if (marker) canvas.drawParagraph(marker.paragraph, x + marker.x, y + marker.y)\n }\n }\n\n /** Where in the block's paragraph a point `y` below the block's top falls, by its line. */\n private paragraphY(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return y\n const lines = block.paragraph.getLineMetrics()\n // A point belongs to the line whose box it is in, or the nearest after the one above it.\n const index = lines.findIndex((line, lineIndex) => {\n const box = placement.boxes[lineIndex]\n const baseline = line.baseline + placement.offsets[lineIndex]\n return y < baseline - box.ascent + box.height\n })\n const line = lines[index === -1 ? lines.length - 1 : index]\n return line.baseline\n }\n\n isDeleted(): boolean {\n return this.blocks.every((block) => block.paragraph.isDeleted())\n }\n\n delete(): void {\n this.clearPlacements()\n for (const block of this.blocks) {\n block.paragraph.delete()\n block.marker?.paragraph.delete()\n }\n }\n}\n"],"mappings":";;;;;;;;AA2EA,IAAa,aAAb,MAAa,WAAW;CAsCH;CACR;CAEQ;CAxCnB,QAA+B,CAAC;CAChC,cAAgC,CAAC;CACjC,YAAoB;CACpB,6BAA8B,IAAI,IAAqC;;CAEvE,eAAsC;;CAGtC,OAAO,YACL,IACA,WACA,QACA,OACY;EACZ,OAAO,IAAI,WAAW,IAAI,CACxB;GACE;GACA,OAAO;GACP,WAAW;GACX;GACA,MAAM;GAC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MAAM,WAAW,IAAI,MAAM,GAAG,IAAI,MAAM,CAAC;GAC3E,KAAK,MAAM,SAAS,UAAU,CAAC,GAC7B,OAAO,cAAc,MAAM,WAAW,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,MAAM,IAAI,MAAM,CAAC;GAEpF,MAAM,SAAS,MAAM;GACrB,IAAI,QAAQ,OAAO,cAAc,OAAO,WAAW,IAAI,OAAO,GAAG,IAAI,OAAO,CAAC;EAC/E;CACF;;CAGA,WAAmB,OAAwB,GAAmB;EAC5D,MAAM,YAAY,KAAK,WAAW,IAAI,KAAK;EAC3C,IAAI,CAAC,WAAW,OAAO;EACvB,MAAM,QAAQ,MAAM,UAAU,eAAe;EAE7C,MAAM,QAAQ,MAAM,WAAW,MAAM,cAAc;GACjD,MAAM,MAAM,UAAU,MAAM;GAE5B,OAAO,IADU,KAAK,WAAW,UAAU,QAAQ,aAC7B,IAAI,SAAS,IAAI;EACzC,CAAC;EAED,OADa,MAAM,UAAU,KAAK,MAAM,SAAS,IAAI,MAC1C,CAAC;CACd;CAEA,YAAqB;EACnB,OAAO,KAAK,OAAO,OAAO,UAAU,MAAM,UAAU,UAAU,CAAC;CACjE;CAEA,SAAe;EACb,KAAK,gBAAgB;EACrB,KAAK,MAAM,SAAS,KAAK,QAAQ;GAC/B,MAAM,UAAU,OAAO;GACvB,MAAM,QAAQ,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/layout/index.ts"],"sourcesContent":["import type {\n Canvas,\n CanvasKit,\n LineMetrics,\n Paragraph,\n PositionWithAffinity,\n RectHeightStyle,\n RectWidthStyle,\n RectWithDirection,\n ShapedLine\n} from 'canvaskit-wasm'\n\nimport {\n placeLines,\n shapedLinesByLine,\n type BlockPlacement,\n type TextLayoutBlockLines\n} from '#core/canvas/text/layout/lines'\n\n/** A list item's number or bullet, laid out on its own. */\nexport interface TextLayoutMarker {\n paragraph: Paragraph\n kind: 'bullet' | 'number'\n /** Font size of the list's first character, which sets the marker's distance from the text. */\n em: number\n /** The face the marker is set in, for its glyph outlines. */\n face: { family: string; style: string }\n /** Where the marker is drawn and the line of the item it marks, set by layout. */\n x: number\n y: number\n lineNumber: number\n}\n\n/** One paragraph of the text, or the whole text when it needs no paragraph layout of its own. */\nexport interface TextLayoutBlock {\n paragraph: Paragraph\n /** Rebuilds the paragraph to show at most `maxLines` lines, when the text is truncated. */\n rebuild?: (maxLines: number) => Paragraph\n /** The first character the block holds, as an index into the text and in UTF-8 bytes. */\n start: number\n utf8Start: number\n /** Characters the block holds, not counting the newline that ends it. */\n length: number\n /** Indices before the text, in UTF-16 and UTF-8, and its width: a first-line indent. */\n lead: number\n utf8Lead: number\n leadWidth: number\n /** Laid out from a space, standing for a paragraph with no characters. */\n empty: boolean\n /** Distance of the text from the start edge: a list item's indent. */\n inset: number\n rtl: boolean\n /** Space above the block, from the paragraph before it. */\n spaceBefore: number\n marker: TextLayoutMarker | null\n /** What placing its lines as Figma does needs; without it they stack as the paragraph's. */\n lines?: TextLayoutBlockLines\n x: number\n y: number\n /** Whether the block is shown, as truncation hides blocks past its last line. */\n visible: boolean\n}\n\nexport interface TextCaretBox {\n x: number\n top: number\n bottom: number\n}\n\n/**\n * A laid-out text node: one native paragraph per block, stacked with paragraph and list\n * spacing, each indented by its list level and preceded by its marker. It answers the\n * `Paragraph` queries the renderer, measurement, and the text editor ask, in indices of the\n * whole text and coordinates of the whole layout.\n */\nexport class TextLayout {\n private lines: LineMetrics[] = []\n private lineOffsets: number[] = []\n private truncated = false\n private readonly placements = new Map<TextLayoutBlock, BlockPlacement>()\n /** The text's height when layout placed its lines itself. */\n private placedHeight: number | null = null\n\n /** Text laid out as one native paragraph of `length` characters, not yet laid out. */\n static ofParagraph(\n ck: CanvasKit,\n paragraph: Paragraph,\n length: number,\n lines?: TextLayoutBlockLines\n ): TextLayout {\n return new TextLayout(ck, [\n {\n paragraph,\n start: 0,\n utf8Start: 0,\n length,\n lead: 0,\n utf8Lead: 0,\n leadWidth: 0,\n empty: false,\n inset: 0,\n rtl: false,\n spaceBefore: 0,\n marker: null,\n lines,\n x: 0,\n y: 0,\n visible: true\n }\n ])\n }\n\n constructor(\n private readonly ck: CanvasKit,\n readonly blocks: TextLayoutBlock[],\n /** Lines the text may show in all, when it is truncated across blocks. */\n private readonly maxLines?: number\n ) {}\n\n /** The line cap a block's paragraph was rebuilt with, when it differs from `maxLines`. */\n private readonly caps = new Map<TextLayoutBlock, number>()\n\n private visibleBlocks(): TextLayoutBlock[] {\n return this.blocks.filter((block) => block.visible)\n }\n\n layout(width: number): void {\n let y = 0\n let lines = 0\n this.truncated = false\n this.clearPlacements()\n for (const [index, block] of this.blocks.entries()) {\n const remaining = this.maxLines === undefined ? Infinity : this.maxLines - lines\n block.visible = remaining > 0\n if (!block.visible) {\n this.truncated = true\n continue\n }\n block.paragraph.layout(Math.max(1, width - block.inset))\n // A block capped for a narrower layout gets its lines back when there is room for them.\n const cap = this.caps.get(block) ?? this.maxLines ?? Infinity\n const overflows = block.paragraph.getLineMetrics().length > remaining\n const clipped = cap < remaining && block.paragraph.didExceedMaxLines()\n if ((overflows || clipped) && block.rebuild) {\n block.paragraph.delete()\n block.paragraph = block.rebuild(remaining)\n this.caps.set(block, remaining)\n block.paragraph.layout(Math.max(1, width - block.inset))\n }\n if (block.paragraph.didExceedMaxLines()) this.truncated = true\n if (index > 0) y += block.spaceBefore\n block.x = block.rtl ? 0 : block.inset\n block.y = y\n y += block.paragraph.getHeight()\n lines += block.paragraph.getLineMetrics().length\n }\n this.placeLines(width)\n for (const block of this.visibleBlocks()) this.placeMarker(block)\n this.collectLines()\n }\n\n private clearPlacements(): void {\n for (const placement of this.placements.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n this.placements.clear()\n this.placedHeight = null\n }\n\n /**\n * Places lines as Figma does when they differ in height, keeping the paragraph's placement\n * otherwise (`placeLines`).\n */\n private placeLines(width: number): void {\n const placed = placeLines(this.ck, this.visibleBlocks(), width)\n if (!placed) return\n for (const [block, { y, ...placement }] of placed.blocks) {\n block.y = y\n this.placements.set(block, placement)\n }\n this.placedHeight = placed.height\n }\n\n /** The block's line `index` stands this far below where its paragraph has it. */\n private lineOffset(block: TextLayoutBlock, index: number): number {\n return this.placements.get(block)?.offsets[index] ?? 0\n }\n\n /** How far a point `y` of the block's paragraph moves, by the line it falls on. */\n private offsetAt(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return 0\n const lines = block.paragraph.getLineMetrics()\n const index = lines.findIndex((line) => y < line.baseline + line.descent)\n return placement.offsets[index === -1 ? lines.length - 1 : index] ?? 0\n }\n\n private blockHeight(block: TextLayoutBlock): number {\n return this.placements.get(block)?.height ?? block.paragraph.getHeight()\n }\n\n private placeMarker(block: TextLayoutBlock): void {\n const marker = block.marker\n const first = block.paragraph.getLineMetrics().at(0)\n if (!marker || !first) return\n const markerLine = marker.paragraph.getLineMetrics().at(0)\n const width = marker.paragraph.getLongestLine()\n // A bullet centres on the middle of the indent; a number ends a third of an em before the\n // text, so numbers of any width line up on their periods.\n if (block.rtl) {\n const start = block.x + first.left + first.width\n marker.x =\n marker.kind === 'bullet' ? start + marker.em * 0.75 - width / 2 : start + marker.em / 3\n } else {\n const start = block.x + first.left\n marker.x =\n marker.kind === 'bullet'\n ? start - marker.em * 0.75 - width / 2\n : start - marker.em / 3 - width\n }\n marker.y = block.y + first.baseline - (markerLine?.baseline ?? 0)\n }\n\n private toTextIndex(block: TextLayoutBlock, index: number): number {\n return block.start + Math.max(0, Math.min(block.length, index - block.lead))\n }\n\n private collectLines(): void {\n this.lines = []\n this.lineOffsets = []\n const visible = this.visibleBlocks()\n for (const [blockIndex, block] of visible.entries()) {\n this.lineOffsets.push(this.lines.length)\n if (block.marker) block.marker.lineNumber = this.lines.length\n const metrics = block.paragraph.getLineMetrics()\n const boxes = this.placements.get(block)?.boxes\n const blockEnd = block.start + block.length\n // Skia starts the empty line after a closing line break at that break; a line starts where\n // the one before it ends, its line break included.\n let previousEnd = block.start\n for (const [lineIndex, line] of metrics.entries()) {\n const lastOfBlock = lineIndex === metrics.length - 1\n const endsAtNewline = lastOfBlock && blockIndex < visible.length - 1\n // A first-line indent is room before the text, not part of the line.\n const indent = lineIndex === 0 ? block.leadWidth : 0\n const box = boxes?.[lineIndex]\n const startIndex = Math.max(previousEnd, this.toTextIndex(block, line.startIndex))\n const endIncludingNewline = endsAtNewline\n ? blockEnd + 1\n : this.toTextIndex(block, line.endIncludingNewline)\n previousEnd = endIncludingNewline\n this.lines.push({\n ...line,\n ...(box && {\n ascent: box.ascent,\n descent: box.height - box.ascent,\n height: box.height\n }),\n startIndex,\n endIndex: Math.max(startIndex, this.toTextIndex(block, line.endIndex)),\n endExcludingWhitespaces: Math.max(\n startIndex,\n this.toTextIndex(block, line.endExcludingWhitespaces)\n ),\n endIncludingNewline,\n isHardBreak: endsAtNewline || line.isHardBreak,\n width: block.empty ? 0 : line.width - indent,\n left: line.left + block.x + (block.rtl ? 0 : indent),\n baseline: line.baseline + block.y + this.lineOffset(block, lineIndex),\n lineNumber: this.lines.length\n })\n }\n }\n }\n\n getHeight(): number {\n const last = this.visibleBlocks().at(-1)\n if (this.placedHeight !== null) return this.placedHeight\n return last ? last.y + last.paragraph.getHeight() : 0\n }\n\n getLongestLine(): number {\n let longest = 0\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n longest = Math.max(longest, block.inset + block.paragraph.getLongestLine())\n }\n return longest\n }\n\n didExceedMaxLines(): boolean {\n return this.truncated\n }\n\n getLineMetrics(): LineMetrics[] {\n return this.lines\n }\n\n getLineMetricsAt(lineNumber: number): LineMetrics | null {\n return this.lines[lineNumber] ?? null\n }\n\n /** The block holding text index `index`; the newline ending a block belongs to it. */\n private blockAt(index: number): { block: TextLayoutBlock; order: number } | null {\n const visible = this.visibleBlocks()\n for (const [order, block] of visible.entries()) {\n if (index <= block.start + block.length) return { block, order }\n }\n const last = visible.at(-1)\n return last ? { block: last, order: visible.length - 1 } : null\n }\n\n getLineNumberAt(index: number): number {\n const found = this.blockAt(index)\n if (!found) return -1\n const { block, order } = found\n const local = block.empty\n ? 0\n : block.paragraph.getLineNumberAt(index - block.start + block.lead)\n const isLast = order === this.lineOffsets.length - 1\n if (local < 0) {\n if (isLast) return local\n return this.lineOffsets[order] + block.paragraph.getLineMetrics().length - 1\n }\n return this.lineOffsets[order] + local\n }\n\n getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity {\n const visible = this.visibleBlocks()\n let block = visible.at(-1)\n for (const [index, candidate] of visible.entries()) {\n const next = visible.at(index + 1)\n const bottom = candidate.y + this.blockHeight(candidate)\n if (!next || y < bottom + next.spaceBefore / 2) {\n block = candidate\n break\n }\n }\n if (!block) return { pos: 0, affinity: this.ck.Affinity.Downstream }\n const local = block.paragraph.getGlyphPositionAtCoordinate(\n x - block.x,\n this.paragraphY(block, y - block.y)\n )\n return {\n pos: block.empty ? block.start : this.toTextIndex(block, local.pos),\n affinity: local.affinity\n }\n }\n\n getRectsForRange(\n start: number,\n end: number,\n heightStyle: RectHeightStyle,\n widthStyle: RectWidthStyle\n ): RectWithDirection[] {\n const rects: RectWithDirection[] = []\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n const from = Math.max(start, block.start)\n const to = Math.min(end, block.start + block.length)\n if (to <= from) continue\n const local = block.paragraph.getRectsForRange(\n from - block.start + block.lead,\n to - block.start + block.lead,\n heightStyle,\n widthStyle\n )\n for (const { rect, dir } of local) {\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n rects.push({\n rect: Float32Array.of(rect[0] + block.x, rect[1] + y, rect[2] + block.x, rect[3] + y),\n dir\n })\n }\n }\n return rects\n }\n\n /**\n * Where the caret stands before text index `index`: at the start edge of the character\n * there, or after the last character of its paragraph.\n */\n getCaretRect(index: number, rtl: boolean): TextCaretBox | null {\n const found = this.blockAt(index)\n if (!found) return null\n const { block } = found\n const local = index - block.start\n const first = block.paragraph.getLineMetrics().at(0)\n if (block.empty || block.length === 0) {\n if (!first) return null\n const top = block.y + first.baseline - first.ascent\n // The caret stands where typing starts: after a first-line indent.\n return {\n x: block.x + first.left + (rtl ? first.width - block.leadWidth : block.leadWidth),\n top,\n bottom: top + first.height\n }\n }\n const after = this.caretAfterLineBreak(block, local)\n if (after) return after\n let lo = local\n let hi = local + 1\n let useRight = false\n if (local <= 0) {\n lo = 0\n hi = 1\n useRight = rtl\n } else if (local >= block.length) {\n lo = block.length - 1\n hi = block.length\n useRight = !rtl\n }\n // The box of the whole character beside the caret: half an emoji or a surrogate pair has none.\n const cluster = block.paragraph.getGlyphInfoAt(lo + block.lead)?.graphemeClusterTextRange\n const rects = block.paragraph.getRectsForRange(\n cluster?.start ?? lo + block.lead,\n cluster?.end ?? hi + block.lead,\n this.ck.RectHeightStyle.Max,\n this.ck.RectWidthStyle.Tight\n )\n const rect = rects.at(0)?.rect\n if (!rect) return null\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n return {\n x: block.x + (useRight ? rect[2] : rect[0]),\n top: y + rect[1],\n bottom: y + rect[3]\n }\n }\n\n /**\n * The caret after a line break that ends the paragraph: at the start of the empty line Skia\n * lays out below it, where typing goes, not after the break on the line above.\n */\n private caretAfterLineBreak(block: TextLayoutBlock, local: number): TextCaretBox | null {\n if (local < block.length) return null\n const lines = block.paragraph.getLineMetrics()\n const last = lines.at(-1)\n const previous = lines.at(-2)\n if (!last || !previous?.isHardBreak || last.endIndex > previous.endIncludingNewline) return null\n const lineTop = last.baseline - last.ascent\n const y = block.y + this.offsetAt(block, lineTop + last.height / 2)\n return { x: block.x + last.left, top: y + lineTop, bottom: y + lineTop + last.height }\n }\n\n /**\n * Shaped lines of the text in whole-text coordinates, one per line; run offsets are UTF-8\n * byte offsets into the whole text, as CanvasKit gives them. An empty line, which shaping\n * leaves out, has no runs and starts where the line before it ends.\n */\n getShapedLines(): ShapedLine[] {\n const shaped: ShapedLine[] = []\n for (const block of this.visibleBlocks()) {\n const metrics = block.paragraph.getLineMetrics()\n for (const [lineIndex, line] of shapedLinesByLine(block.paragraph).entries()) {\n const y = block.y + this.lineOffset(block, lineIndex)\n if (!line) {\n const { baseline, ascent, descent } = metrics[lineIndex]\n const previous = lineIndex > 0 ? shaped.at(-1) : undefined\n const start = previous?.textRange.last ?? block.utf8Start\n shaped.push({\n textRange: { first: start, last: start },\n top: baseline - ascent + y,\n bottom: baseline + descent + y,\n baseline: baseline + y,\n runs: []\n })\n continue\n }\n shaped.push({\n textRange: {\n first: this.toUtf8(block, line.textRange.first),\n last: this.toUtf8(block, line.textRange.last)\n },\n top: line.top + y,\n bottom: line.bottom + y,\n baseline: line.baseline + y,\n runs: block.empty\n ? []\n : line.runs.map((run) => ({\n ...run,\n positions: run.positions.map(\n (value, index) => value + (index % 2 === 0 ? block.x : y)\n ),\n offsets: run.offsets.map((offset) => this.toUtf8(block, offset))\n }))\n })\n }\n }\n return shaped\n }\n\n private toUtf8(block: TextLayoutBlock, offset: number): number {\n return block.empty ? block.utf8Start : block.utf8Start + Math.max(0, offset - block.utf8Lead)\n }\n\n /** Markers of the visible list items, where layout placed them. */\n getMarkers(): TextLayoutMarker[] {\n const markers: TextLayoutMarker[] = []\n for (const block of this.visibleBlocks()) if (block.marker) markers.push(block.marker)\n return markers\n }\n\n draw(canvas: Canvas, x: number, y: number): void {\n for (const block of this.visibleBlocks()) {\n const pieces = this.placements.get(block)?.pieces\n if (!pieces) canvas.drawParagraph(block.paragraph, x + block.x, y + block.y)\n for (const piece of pieces ?? []) {\n canvas.drawParagraph(piece.paragraph, x + block.x + piece.x, y + block.y + piece.y)\n }\n const marker = block.marker\n if (marker) canvas.drawParagraph(marker.paragraph, x + marker.x, y + marker.y)\n }\n }\n\n /** Where in the block's paragraph a point `y` below the block's top falls, by its line. */\n private paragraphY(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return y\n const lines = block.paragraph.getLineMetrics()\n // A point belongs to the line whose box it is in, or the nearest after the one above it.\n const index = lines.findIndex((line, lineIndex) => {\n const box = placement.boxes[lineIndex]\n const baseline = line.baseline + placement.offsets[lineIndex]\n return y < baseline - box.ascent + box.height\n })\n const line = lines[index === -1 ? lines.length - 1 : index]\n return line.baseline\n }\n\n isDeleted(): boolean {\n return this.blocks.every((block) => block.paragraph.isDeleted())\n }\n\n delete(): void {\n this.clearPlacements()\n for (const block of this.blocks) {\n block.paragraph.delete()\n block.marker?.paragraph.delete()\n }\n }\n}\n"],"mappings":";;;;;;;;AA2EA,IAAa,aAAb,MAAa,WAAW;CAsCH;CACR;CAEQ;CAxCnB,QAA+B,CAAC;CAChC,cAAgC,CAAC;CACjC,YAAoB;CACpB,6BAA8B,IAAI,IAAqC;;CAEvE,eAAsC;;CAGtC,OAAO,YACL,IACA,WACA,QACA,OACY;EACZ,OAAO,IAAI,WAAW,IAAI,CACxB;GACE;GACA,OAAO;GACP,WAAW;GACX;GACA,MAAM;GACN,UAAU;GACV,WAAW;GACX,OAAO;GACP,OAAO;GACP,KAAK;GACL,aAAa;GACb,QAAQ;GACR;GACA,GAAG;GACH,GAAG;GACH,SAAS;EACX,CACF,CAAC;CACH;CAEA,YACE,IACA,QAEA,UACA;EAJiB,KAAA,KAAA;EACR,KAAA,SAAA;EAEQ,KAAA,WAAA;CAChB;;CAGH,uBAAwB,IAAI,IAA6B;CAEzD,gBAA2C;EACzC,OAAO,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;CACpD;CAEA,OAAO,OAAqB;EAC1B,IAAI,IAAI;EACR,IAAI,QAAQ;EACZ,KAAK,YAAY;EACjB,KAAK,gBAAgB;EACrB,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,OAAO,QAAQ,GAAG;GAClD,MAAM,YAAY,KAAK,aAAa,KAAA,IAAY,WAAW,KAAK,WAAW;GAC3E,MAAM,UAAU,YAAY;GAC5B,IAAI,CAAC,MAAM,SAAS;IAClB,KAAK,YAAY;IACjB;GACF;GACA,MAAM,UAA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AE5B,OAAO,IADU,KAAK,WAAW,UAAU,QAAQ,aAC7B,IAAI,SAAS,IAAI;EACzC,CAAC;EAED,OADa,MAAM,UAAU,KAAK,MAAM,SAAS,IAAI,MAC1C,CAAC;CACd;CAEA,YAAqB;EACnB,OAAO,KAAK,OAAO,OAAO,UAAU,MAAM,UAAU,UAAU,CAAC;CACjE;CAEA,SAAe;EACb,KAAK,gBAAgB;EACrB,KAAK,MAAM,SAAS,KAAK,QAAQ;GAC/B,MAAM,UAAU,OAAO;GACvB,MAAM,QAAQ,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -33,7 +33,7 @@ function figmaLineBox(ck, paragraph, line, runs, lines = paragraph.getLineMetric
|
|
|
33
33
|
for (const { rect } of rects) {
|
|
34
34
|
const runNatural = metric(rect[3] - rect[1]);
|
|
35
35
|
if (runNatural <= 0) continue;
|
|
36
|
-
height = Math.max(height,
|
|
36
|
+
height = Math.max(height, run.lineHeight ?? Math.round(runNatural));
|
|
37
37
|
if (runNatural > natural) {
|
|
38
38
|
natural = runNatural;
|
|
39
39
|
ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1]);
|
|
@@ -165,13 +165,15 @@ function placeLines(ck, blocks, width) {
|
|
|
165
165
|
const boxes = lineBoxes(ck, blocks, metrics);
|
|
166
166
|
if (!boxes) return null;
|
|
167
167
|
const all = boxes.flat();
|
|
168
|
-
|
|
168
|
+
const height = all[0].height;
|
|
169
|
+
if (allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent)) && allSame([height, Math.round(height)])) return null;
|
|
169
170
|
const first = all[0];
|
|
170
171
|
const last = all[all.length - 1];
|
|
172
|
+
const start = Math.round(first.ascent);
|
|
171
173
|
let below = 0;
|
|
172
174
|
const baselines = blocks.map((block, index) => boxes[index].map((box, line) => {
|
|
173
175
|
if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0);
|
|
174
|
-
return first.ascent + below;
|
|
176
|
+
return first.ascent + Math.round(first.ascent + below) - start;
|
|
175
177
|
}));
|
|
176
178
|
const placed = /* @__PURE__ */ new Map();
|
|
177
179
|
for (const [index, block] of blocks.entries()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lines.js","names":[],"sources":["../../../../src/canvas/text/layout/lines.ts"],"sourcesContent":["import type { CanvasKit, LineMetrics, Paragraph, ShapedLine } from 'canvaskit-wasm'\n\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/** A stretch of a paragraph's characters set at one line height, `null` for auto. */\nexport interface LineHeightRun {\n start: number\n end: number\n lineHeight: number | null\n}\n\n/** A block's line heights, and how to lay one of its lines out on its own. */\nexport interface TextLayoutBlockLines {\n /** Line heights by paragraph index, lead included. */\n heights: LineHeightRun[]\n /**\n * The paragraph's characters from `start` as a paragraph of their own, holding its `lines`\n * lines up to `end`, and ending in the ellipsis when `truncated`; absent when lines cannot\n * be drawn apart from the others.\n */\n build?: (start: number, end: number, lines: number, truncated: boolean) => Paragraph\n}\n\n/** What placing a text layout block's lines reads of it. */\ninterface LineBlock {\n paragraph: Paragraph\n lines?: TextLayoutBlockLines\n lead: number\n length: number\n inset: number\n spaceBefore: number\n y: number\n}\n\n/** Lines laid out as a paragraph of their own, and where its top left goes in its block. */\nexport interface LinePiece {\n paragraph: Paragraph\n x: number\n y: number\n}\n\n/** Where a block's lines go when they do not stack as its paragraph has them. */\nexport interface BlockPlacement {\n height: number\n /** How far each line stands below where the paragraph has it. */\n offsets: number[]\n boxes: LineBox[]\n /** Paragraphs of lines that move together, drawn in place of the block's when lines move apart. */\n pieces: LinePiece[] | null\n}\n\n/** A line as Figma sets it: its height, and how far its baseline stands below its top. */\nexport interface LineBox {\n height: number\n ascent: number\n}\n\n/** The difference below which two line positions count as the same. */\nconst LINE_EPSILON = 0.01\n/**\n * Steps font metrics are measured in. Rects come in float32, whose error at a line far down a\n * text reaches the sixth digit, so lines in the same font would measure apart.\n */\nconst METRIC_STEPS = 1e4\n\nfunction metric(value: number): number {\n return Math.round(value * METRIC_STEPS) / METRIC_STEPS\n}\n\n/**\n * A line's box as Figma sets it. The line is as tall as the tallest line height on it, auto\n * standing for a font's own height rounded to a whole pixel, and its baseline sits where its\n * tallest font, centred in that height, puts it. Fonts' heights are the shaped runs' own, so a\n * fallback font counts with its metrics. Returns `null` for a line with nothing to measure.\n */\n/** The line a point `y` of the paragraph falls on, or `fallback` past them all. */\nfunction lineAt(lines: readonly LineMetrics[], y: number, fallback: LineMetrics): LineMetrics {\n return lines.find((line) => y < line.baseline + line.descent) ?? fallback\n}\n\nexport function figmaLineBox(\n ck: CanvasKit,\n paragraph: Paragraph,\n line: LineMetrics,\n runs: readonly LineHeightRun[],\n lines: readonly LineMetrics[] = paragraph.getLineMetrics()\n): LineBox | null {\n // An empty line is as tall as the newline that makes it.\n const start = line.startIndex\n const end = Math.max(line.endIndex, start + 1)\n let height = 0\n let natural = 0\n let ascent = 0\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.end)\n if (to <= from) continue\n const rects = paragraph.getRectsForRange(\n from,\n to,\n ck.RectHeightStyle.Tight,\n ck.RectWidthStyle.Tight\n )\n for (const { rect } of rects) {\n const runNatural = metric(rect[3] - rect[1])\n // A first-line indent is a placeholder with no height.\n if (runNatural <= 0) continue\n height = Math.max(height, Math.round(run.lineHeight ?? runNatural))\n if (runNatural > natural) {\n natural = runNatural\n // The newline that makes an empty line stands on the line above, so its box is\n // measured from the baseline of the line it stands on.\n ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1])\n }\n }\n }\n if (natural === 0) return null\n return { height, ascent: (height - natural) / 2 + ascent }\n}\n\n/** Whether all `values` are the same, to within the precision lines are placed with. */\nexport function allSame(values: readonly number[]): boolean {\n const first = values.at(0)\n return first === undefined || values.every((value) => Math.abs(value - first) < LINE_EPSILON)\n}\n\n/** Each block's lines as Figma sets them, or `null` when one cannot be measured. */\nfunction lineBoxes(\n ck: CanvasKit,\n blocks: readonly LineBlock[],\n metrics: readonly LineMetrics[][]\n): LineBox[][] | null {\n const boxes: LineBox[][] = []\n for (const [index, block] of blocks.entries()) {\n const heights = block.lines?.heights\n if (!heights) return null\n const blockBoxes: LineBox[] = []\n for (const line of metrics[index]) {\n const box = figmaLineBox(ck, block.paragraph, line, heights, metrics[index])\n if (!box) return null\n blockBoxes.push(box)\n }\n boxes.push(blockBoxes)\n }\n return boxes\n}\n\n/**\n * A paragraph's shaped lines by line number. Shaping leaves empty lines out, so each shaped\n * line goes to the line whose baseline is nearest its own.\n */\nexport function shapedLinesByLine(paragraph: Paragraph): Array<ShapedLine | undefined> {\n const lines = paragraph.getLineMetrics()\n const byLine: Array<ShapedLine | undefined> = Array.from({ length: lines.length })\n for (const shaped of paragraph.getShapedLines()) {\n let nearest = 0\n for (const [index, line] of lines.entries()) {\n const distance = Math.abs(line.baseline - shaped.baseline)\n if (distance < Math.abs(lines[nearest].baseline - shaped.baseline)) nearest = index\n }\n byLine[nearest] = shaped\n }\n return byLine\n}\n\n/** Where a shaped line's first glyph stands, if it has one. */\nfunction firstGlyph(line: ShapedLine | undefined): [number, number] | null {\n const positions = line?.runs.find((run) => run.glyphs.length > 0)?.positions\n return positions ? [positions[0], positions[1]] : null\n}\n\n/** How far glyphs a piece draws must move to land where the block's lines have them. */\nfunction pieceShift(\n shaped: ReadonlyArray<ShapedLine | undefined>,\n own: ReadonlyArray<ShapedLine | undefined>\n): (Vector & { agrees: number }) | null {\n let shift: Vector | null = null\n // Paragraphs snap each line to whole-pixel baselines their own way, so lines of one piece\n // may need different shifts; the piece holds the lines that agree with its first.\n for (const [index, line] of own.entries()) {\n const glyph = firstGlyph(shaped[index])\n const ownGlyph = firstGlyph(line)\n if (!glyph || !ownGlyph) continue\n const x = glyph[0] - ownGlyph[0]\n const y = glyph[1] - ownGlyph[1]\n if (!shift) shift = { x, y }\n else if (!allSame([shift.x, x]) || !allSame([shift.y, y])) return { ...shift, agrees: index }\n }\n return shift && { ...shift, agrees: own.length }\n}\n\n/**\n * The block's lines as paragraphs of their own, one for each run of lines that move by the\n * same offset, or one per line when not `grouped`, placed so their glyphs land where the\n * block's paragraph has them, moved by that offset. `null` when lines cannot be laid out\n * apart from the others.\n */\nfunction buildPieces(\n block: LineBlock,\n width: number,\n offsets: readonly number[],\n grouped = true\n): LinePiece[] | null {\n const build = block.lines?.build\n if (!build) return null\n const lines = block.paragraph.getLineMetrics()\n const shaped = shapedLinesByLine(block.paragraph)\n const truncated = block.paragraph.didExceedMaxLines()\n const textEnd = block.lead + block.length\n const pieces: LinePiece[] = []\n let from = 0\n while (from < lines.length) {\n let to = from + 1\n if (grouped) while (to < lines.length && allSame([offsets[from], offsets[to]])) to++\n const start = lines[from].startIndex\n const end = to === lines.length ? textEnd : lines[to - 1].endIndex\n // Empty lines draw nothing.\n if (end <= start) {\n from = to\n continue\n }\n const count = to - from\n const paragraph = build(start, end, count, to === lines.length && truncated)\n paragraph.layout(Math.max(1, width - block.inset))\n const own = paragraph.getLineMetrics().length === count ? shapedLinesByLine(paragraph) : null\n const shift = own && pieceShift(shaped.slice(from, to), own)\n if (!shift || shift.agrees < count) {\n paragraph.delete()\n for (const piece of pieces) piece.paragraph.delete()\n // Lines that lay out or snap apart are drawn one by one.\n return grouped ? buildPieces(block, width, offsets, false) : null\n }\n pieces.push({ paragraph, x: shift.x, y: shift.y + offsets[from] })\n from = to\n }\n return pieces\n}\n\n/** Where `placeLines` puts each block, and the text's height. */\nexport interface PlacedLines<Block> {\n blocks: Map<Block, BlockPlacement & { y: number }>\n height: number\n}\n\n/**\n * Lines of laid-out blocks placed as Figma places them when they differ in height: each\n * line is as tall as its tallest line height, and each baseline stands that far, plus the\n * paragraph's spacing, below the one before, where a paragraph would stack the lines' boxes.\n * `null` keeps the paragraphs' placement: for lines alike, where it is the same, and for\n * lines that cannot be measured or drawn apart.\n */\nexport function placeLines<Block extends LineBlock>(\n ck: CanvasKit,\n blocks: readonly Block[],\n width: number\n): PlacedLines<Block> | null {\n const metrics = blocks.map((block) => block.paragraph.getLineMetrics())\n // A single line has none to be spaced from.\n if (metrics.flat().length < 2) return null\n const boxes = lineBoxes(ck, blocks, metrics)\n if (!boxes) return null\n const all = boxes.flat()\n if (allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent))) return null\n\n // Distances from the first baseline add up whole-pixel line heights, so they stay exact.\n const first = all[0]\n const last = all[all.length - 1]\n let below = 0\n const baselines = blocks.map((block, index) =>\n boxes[index].map((box, line) => {\n if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0)\n return first.ascent + below\n })\n )\n const placed = new Map<Block, BlockPlacement & { y: number }>()\n for (const [index, block] of blocks.entries()) {\n const lines = metrics[index]\n const blockBoxes = boxes[index]\n const blockBaselines = baselines[index]\n const end = blockBoxes.length - 1\n const y = blockBaselines[0] - lines[0].baseline\n const offsets = lines.map((line, lineIndex) => blockBaselines[lineIndex] - y - line.baseline)\n const apart = !allSame(offsets)\n const pieces = apart ? buildPieces(block, width, offsets) : null\n placed.set(block, {\n y,\n height: blockBaselines[end] - blockBoxes[end].ascent + blockBoxes[end].height - y,\n offsets,\n boxes: blockBoxes,\n pieces\n })\n // Lines that cannot be drawn apart keep the paragraph's placement, and so does the text.\n if (apart && !pieces) {\n for (const placement of placed.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n return null\n }\n }\n return { blocks: placed, height: first.ascent - last.ascent + below + last.height }\n}\n"],"mappings":";;AA0DA,MAAM,eAAe;;;;;AAKrB,MAAM,eAAe;AAErB,SAAS,OAAO,OAAuB;CACrC,OAAO,KAAK,MAAM,QAAQ,YAAY,IAAI;AAC5C;;;;;;;;AASA,SAAS,OAAO,OAA+B,GAAW,UAAoC;CAC5F,OAAO,MAAM,MAAM,SAAS,IAAI,KAAK,WAAW,KAAK,OAAO,KAAK;AACnE;AAEA,SAAgB,aACd,IACA,WACA,MACA,MACA,QAAgC,UAAU,eAAe,GACzC;CAEhB,MAAM,QAAQ,KAAK;CACn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K,MAAM,SAAS,UAAU,UAAU,CAAC,GAAG,MAAM,UAAU,OAAO;GAErE,OAAO;EACT;CACF;CACA,OAAO;EAAE,QAAQ;EAAQ,QAAQ,MAAM,SAAS,KAAK,SAAS,QAAQ,KAAK;CAAO;AACpF"}
|
|
1
|
+
{"version":3,"file":"lines.js","names":[],"sources":["../../../../src/canvas/text/layout/lines.ts"],"sourcesContent":["import type { CanvasKit, LineMetrics, Paragraph, ShapedLine } from 'canvaskit-wasm'\n\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/** A stretch of a paragraph's characters set at one line height, `null` for auto. */\nexport interface LineHeightRun {\n start: number\n end: number\n lineHeight: number | null\n}\n\n/** A block's line heights, and how to lay one of its lines out on its own. */\nexport interface TextLayoutBlockLines {\n /** Line heights by paragraph index, lead included. */\n heights: LineHeightRun[]\n /**\n * The paragraph's characters from `start` as a paragraph of their own, holding its `lines`\n * lines up to `end`, and ending in the ellipsis when `truncated`; absent when lines cannot\n * be drawn apart from the others.\n */\n build?: (start: number, end: number, lines: number, truncated: boolean) => Paragraph\n}\n\n/** What placing a text layout block's lines reads of it. */\ninterface LineBlock {\n paragraph: Paragraph\n lines?: TextLayoutBlockLines\n lead: number\n length: number\n inset: number\n spaceBefore: number\n y: number\n}\n\n/** Lines laid out as a paragraph of their own, and where its top left goes in its block. */\nexport interface LinePiece {\n paragraph: Paragraph\n x: number\n y: number\n}\n\n/** Where a block's lines go when they do not stack as its paragraph has them. */\nexport interface BlockPlacement {\n height: number\n /** How far each line stands below where the paragraph has it. */\n offsets: number[]\n boxes: LineBox[]\n /** Paragraphs of lines that move together, drawn in place of the block's when lines move apart. */\n pieces: LinePiece[] | null\n}\n\n/** A line as Figma sets it: its height, and how far its baseline stands below its top. */\nexport interface LineBox {\n height: number\n ascent: number\n}\n\n/** The difference below which two line positions count as the same. */\nconst LINE_EPSILON = 0.01\n/**\n * Steps font metrics are measured in. Rects come in float32, whose error at a line far down a\n * text reaches the sixth digit, so lines in the same font would measure apart.\n */\nconst METRIC_STEPS = 1e4\n\nfunction metric(value: number): number {\n return Math.round(value * METRIC_STEPS) / METRIC_STEPS\n}\n\n/**\n * A line's box as Figma sets it. The line is as tall as the tallest line height on it, auto\n * standing for a font's own height rounded to a whole pixel, and its baseline sits where its\n * tallest font, centred in that height, puts it. Fonts' heights are the shaped runs' own, so a\n * fallback font counts with its metrics. Returns `null` for a line with nothing to measure.\n */\n/** The line a point `y` of the paragraph falls on, or `fallback` past them all. */\nfunction lineAt(lines: readonly LineMetrics[], y: number, fallback: LineMetrics): LineMetrics {\n return lines.find((line) => y < line.baseline + line.descent) ?? fallback\n}\n\nexport function figmaLineBox(\n ck: CanvasKit,\n paragraph: Paragraph,\n line: LineMetrics,\n runs: readonly LineHeightRun[],\n lines: readonly LineMetrics[] = paragraph.getLineMetrics()\n): LineBox | null {\n // An empty line is as tall as the newline that makes it.\n const start = line.startIndex\n const end = Math.max(line.endIndex, start + 1)\n let height = 0\n let natural = 0\n let ascent = 0\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.end)\n if (to <= from) continue\n const rects = paragraph.getRectsForRange(\n from,\n to,\n ck.RectHeightStyle.Tight,\n ck.RectWidthStyle.Tight\n )\n for (const { rect } of rects) {\n const runNatural = metric(rect[3] - rect[1])\n // A first-line indent is a placeholder with no height.\n if (runNatural <= 0) continue\n height = Math.max(height, run.lineHeight ?? Math.round(runNatural))\n if (runNatural > natural) {\n natural = runNatural\n // The newline that makes an empty line stands on the line above, so its box is\n // measured from the baseline of the line it stands on.\n ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1])\n }\n }\n }\n if (natural === 0) return null\n return { height, ascent: (height - natural) / 2 + ascent }\n}\n\n/** Whether all `values` are the same, to within the precision lines are placed with. */\nexport function allSame(values: readonly number[]): boolean {\n const first = values.at(0)\n return first === undefined || values.every((value) => Math.abs(value - first) < LINE_EPSILON)\n}\n\n/** Each block's lines as Figma sets them, or `null` when one cannot be measured. */\nfunction lineBoxes(\n ck: CanvasKit,\n blocks: readonly LineBlock[],\n metrics: readonly LineMetrics[][]\n): LineBox[][] | null {\n const boxes: LineBox[][] = []\n for (const [index, block] of blocks.entries()) {\n const heights = block.lines?.heights\n if (!heights) return null\n const blockBoxes: LineBox[] = []\n for (const line of metrics[index]) {\n const box = figmaLineBox(ck, block.paragraph, line, heights, metrics[index])\n if (!box) return null\n blockBoxes.push(box)\n }\n boxes.push(blockBoxes)\n }\n return boxes\n}\n\n/**\n * A paragraph's shaped lines by line number. Shaping leaves empty lines out, so each shaped\n * line goes to the line whose baseline is nearest its own.\n */\nexport function shapedLinesByLine(paragraph: Paragraph): Array<ShapedLine | undefined> {\n const lines = paragraph.getLineMetrics()\n const byLine: Array<ShapedLine | undefined> = Array.from({ length: lines.length })\n for (const shaped of paragraph.getShapedLines()) {\n let nearest = 0\n for (const [index, line] of lines.entries()) {\n const distance = Math.abs(line.baseline - shaped.baseline)\n if (distance < Math.abs(lines[nearest].baseline - shaped.baseline)) nearest = index\n }\n byLine[nearest] = shaped\n }\n return byLine\n}\n\n/** Where a shaped line's first glyph stands, if it has one. */\nfunction firstGlyph(line: ShapedLine | undefined): [number, number] | null {\n const positions = line?.runs.find((run) => run.glyphs.length > 0)?.positions\n return positions ? [positions[0], positions[1]] : null\n}\n\n/** How far glyphs a piece draws must move to land where the block's lines have them. */\nfunction pieceShift(\n shaped: ReadonlyArray<ShapedLine | undefined>,\n own: ReadonlyArray<ShapedLine | undefined>\n): (Vector & { agrees: number }) | null {\n let shift: Vector | null = null\n // Paragraphs snap each line to whole-pixel baselines their own way, so lines of one piece\n // may need different shifts; the piece holds the lines that agree with its first.\n for (const [index, line] of own.entries()) {\n const glyph = firstGlyph(shaped[index])\n const ownGlyph = firstGlyph(line)\n if (!glyph || !ownGlyph) continue\n const x = glyph[0] - ownGlyph[0]\n const y = glyph[1] - ownGlyph[1]\n if (!shift) shift = { x, y }\n else if (!allSame([shift.x, x]) || !allSame([shift.y, y])) return { ...shift, agrees: index }\n }\n return shift && { ...shift, agrees: own.length }\n}\n\n/**\n * The block's lines as paragraphs of their own, one for each run of lines that move by the\n * same offset, or one per line when not `grouped`, placed so their glyphs land where the\n * block's paragraph has them, moved by that offset. `null` when lines cannot be laid out\n * apart from the others.\n */\nfunction buildPieces(\n block: LineBlock,\n width: number,\n offsets: readonly number[],\n grouped = true\n): LinePiece[] | null {\n const build = block.lines?.build\n if (!build) return null\n const lines = block.paragraph.getLineMetrics()\n const shaped = shapedLinesByLine(block.paragraph)\n const truncated = block.paragraph.didExceedMaxLines()\n const textEnd = block.lead + block.length\n const pieces: LinePiece[] = []\n let from = 0\n while (from < lines.length) {\n let to = from + 1\n if (grouped) while (to < lines.length && allSame([offsets[from], offsets[to]])) to++\n const start = lines[from].startIndex\n const end = to === lines.length ? textEnd : lines[to - 1].endIndex\n // Empty lines draw nothing.\n if (end <= start) {\n from = to\n continue\n }\n const count = to - from\n const paragraph = build(start, end, count, to === lines.length && truncated)\n paragraph.layout(Math.max(1, width - block.inset))\n const own = paragraph.getLineMetrics().length === count ? shapedLinesByLine(paragraph) : null\n const shift = own && pieceShift(shaped.slice(from, to), own)\n if (!shift || shift.agrees < count) {\n paragraph.delete()\n for (const piece of pieces) piece.paragraph.delete()\n // Lines that lay out or snap apart are drawn one by one.\n return grouped ? buildPieces(block, width, offsets, false) : null\n }\n pieces.push({ paragraph, x: shift.x, y: shift.y + offsets[from] })\n from = to\n }\n return pieces\n}\n\n/** Where `placeLines` puts each block, and the text's height. */\nexport interface PlacedLines<Block> {\n blocks: Map<Block, BlockPlacement & { y: number }>\n height: number\n}\n\n/**\n * Lines of laid-out blocks placed as Figma places them when they differ in height: each\n * line is as tall as its tallest line height, and each baseline stands that far, plus the\n * paragraph's spacing, below the one before, where a paragraph would stack the lines' boxes.\n * `null` keeps the paragraphs' placement: for lines alike, where it is the same, and for\n * lines that cannot be measured or drawn apart.\n */\nexport function placeLines<Block extends LineBlock>(\n ck: CanvasKit,\n blocks: readonly Block[],\n width: number\n): PlacedLines<Block> | null {\n const metrics = blocks.map((block) => block.paragraph.getLineMetrics())\n // A single line has none to be spaced from.\n if (metrics.flat().length < 2) return null\n const boxes = lineBoxes(ck, blocks, metrics)\n if (!boxes) return null\n const all = boxes.flat()\n // A paragraph steps lines by whole pixels, so lines alike at a whole-pixel height already\n // stand where Figma puts them.\n const height = all[0].height\n const alike = allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent))\n if (alike && allSame([height, Math.round(height)])) return null\n\n // Figma steps lines by their exact heights and puts each baseline on a whole pixel, so a\n // baseline stands the whole pixels between those below the first (Figma desktop 126).\n const first = all[0]\n const last = all[all.length - 1]\n const start = Math.round(first.ascent)\n let below = 0\n const baselines = blocks.map((block, index) =>\n boxes[index].map((box, line) => {\n if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0)\n return first.ascent + Math.round(first.ascent + below) - start\n })\n )\n const placed = new Map<Block, BlockPlacement & { y: number }>()\n for (const [index, block] of blocks.entries()) {\n const lines = metrics[index]\n const blockBoxes = boxes[index]\n const blockBaselines = baselines[index]\n const end = blockBoxes.length - 1\n const y = blockBaselines[0] - lines[0].baseline\n const offsets = lines.map((line, lineIndex) => blockBaselines[lineIndex] - y - line.baseline)\n const apart = !allSame(offsets)\n const pieces = apart ? buildPieces(block, width, offsets) : null\n placed.set(block, {\n y,\n height: blockBaselines[end] - blockBoxes[end].ascent + blockBoxes[end].height - y,\n offsets,\n boxes: blockBoxes,\n pieces\n })\n // Lines that cannot be drawn apart keep the paragraph's placement, and so does the text.\n if (apart && !pieces) {\n for (const placement of placed.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n return null\n }\n }\n return { blocks: placed, height: first.ascent - last.ascent + below + last.height }\n}\n"],"mappings":";;AA0DA,MAAM,eAAe;;;;;AAKrB,MAAM,eAAe;AAErB,SAAS,OAAO,OAAuB;CACrC,OAAO,KAAK,MAAM,QAAQ,YAAY,IAAI;AAC5C;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CAAC;EACvC,MAAM,UAAU,MAAM,KAAK,MAAM,cAAc,eAAe,aAAa,IAAI,KAAK,QAAQ;EAC5F,MAAM,QAAQ,CAAC,QAAQ,OAAO;EAC9B,MAAM,SAAS,QAAQ,YAAY,OAAO,OAAO,OAAO,IAAI;EAC5D,OAAO,IAAI,OAAO;GAChB;GACA,QAAQ,eAAe,OAAO,WAAW,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS;GAChF;GACA,OAAO;GACP;EACF,CAAC;EAED,IAAI,SAAS,CAAC,QAAQ;GACpB,KAAK,MAAM,aAAa,OAAO,OAAO,GACpC,KAAK,MAAM,SAAS,UAAU,UAAU,CAAC,GAAG,MAAM,UAAU,OAAO;GAErE,OAAO;EACT;CACF;CACA,OAAO;EAAE,QAAQ;EAAQ,QAAQ,MAAM,SAAS,KAAK,SAAS,QAAQ,KAAK;CAAO;AACpF"}
|
|
@@ -5,6 +5,11 @@ import { CanvasKit, Paragraph, TextFontFeatures, TextFontVariations } from "canv
|
|
|
5
5
|
import { SceneNode } from "@pairdraw/scene-graph";
|
|
6
6
|
//#region src/canvas/text/paragraph/index.d.ts
|
|
7
7
|
declare function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as
|
|
10
|
+
* Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even
|
|
11
|
+
* where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.
|
|
12
|
+
*/
|
|
8
13
|
declare function buildTruncateOpts(node: ParagraphNode): {
|
|
9
14
|
maxLines?: number;
|
|
10
15
|
ellipsis?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;iBAuCgB,4BAA4B,MAAM,eAAe;;;;;;iBAajD,kBAAkB,MAAM;EAAkB;EAAmB;;;iBA4B7D,mBACd,YAAY,yCACZ,WAAU,qCACT;iBAUa,iBACd,UAAU,wCACT;iBAQa,wBAAwB,GACtC;EAAM;IAAsB,YAAY;;GACxC,aAAa,2BACZ;;UAKc;EACf;EACA;;;iBAsCc,cACd,IAAI,WACJ,OAAO,yCACP,WAAW,eACV;;UAiHc;;EAEf;;EAEA;IAAe;IAAmB;;EAClC,QAAQ;;;;;;iBAYM,iBACd,GAAG,cACH,MAAM,eACN,QAAQ,gBACN,aAAqB,oBAAmB,uBAC1C,QAAO,wBACN"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import "../../../constants.js";
|
|
2
|
+
import { makeParagraphBuilder } from "../../../text/font/collection.js";
|
|
2
3
|
import { shownTextSlice } from "../../../text/case.js";
|
|
3
4
|
import { fontManager } from "../../../text/font/manager.js";
|
|
4
|
-
import { laidOutText } from "../keycap.js";
|
|
5
5
|
import { drawnFontVariations, loadedFace, resolveParagraphFontFamilies } from "../font-families.js";
|
|
6
|
+
import { laidOutText } from "../keycap.js";
|
|
6
7
|
import { pushParagraphStyle } from "../paint.js";
|
|
8
|
+
import { autoWidthWrapWidth } from "../../../layout/text-measurement.js";
|
|
7
9
|
import "../../../text/ellipsis.js";
|
|
8
10
|
import { lineHeightPixels, textLengthPixels } from "@pairdraw/scene-graph/text";
|
|
9
11
|
import { faceStyleKey } from "@pairdraw/scene-graph/font-style";
|
|
@@ -13,14 +15,21 @@ import { resolveNodeTextDirection } from "@pairdraw/scene-graph/text/direction";
|
|
|
13
15
|
//#region src/canvas/text/paragraph/index.ts
|
|
14
16
|
function resolveParagraphLayoutWidth(node, maxWidth) {
|
|
15
17
|
if (maxWidth !== void 0) return maxWidth;
|
|
16
|
-
if (node.textAutoResize === "WIDTH_AND_HEIGHT") return 1e6;
|
|
18
|
+
if (node.textAutoResize === "WIDTH_AND_HEIGHT") return autoWidthWrapWidth(node) ?? 1e6;
|
|
17
19
|
return node.width || 1e6;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as
|
|
23
|
+
* Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even
|
|
24
|
+
* where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.
|
|
25
|
+
*/
|
|
19
26
|
function buildTruncateOpts(node) {
|
|
20
|
-
if (node.textTruncation !== "ENDING") return {};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
if (node.textTruncation !== "ENDING" && node.textAutoResize !== "TRUNCATE") return {};
|
|
28
|
+
if (node.maxLines == null || node.maxLines <= 0) return node.textAutoResize === "TRUNCATE" ? {} : { ellipsis: "…" };
|
|
29
|
+
return {
|
|
30
|
+
maxLines: node.maxLines,
|
|
31
|
+
ellipsis: "…"
|
|
32
|
+
};
|
|
24
33
|
}
|
|
25
34
|
function getParagraphTextAlign(ck, node) {
|
|
26
35
|
const direction = resolveNodeTextDirection(node);
|
|
@@ -152,14 +161,14 @@ function buildSkParagraph(r, node, color, { halfLeading = false, foregroundPaint
|
|
|
152
161
|
const baseFontSize = node.fontSize || 14;
|
|
153
162
|
const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize);
|
|
154
163
|
const cjkFallbacks = fontManager.getCJKFallbackFamilies();
|
|
155
|
-
const
|
|
164
|
+
const letterFallbacks = fontManager.getLetterFallbackFamilies();
|
|
156
165
|
const textDirection = resolveNodeTextDirection(node);
|
|
157
166
|
const truncateOpts = block.truncation ?? buildTruncateOpts(node);
|
|
158
167
|
const fontFamilies = (primary, face) => resolveParagraphFontFamilies(primary, {
|
|
159
168
|
weight: face.fontWeight,
|
|
160
169
|
italic: face.italic,
|
|
161
170
|
style: faceStyleKey(face)
|
|
162
|
-
},
|
|
171
|
+
}, letterFallbacks, cjkFallbacks);
|
|
163
172
|
const nodeKey = faceStyleKey(node);
|
|
164
173
|
const baseTextStyle = {
|
|
165
174
|
color: baseColor,
|
|
@@ -189,7 +198,7 @@ function buildSkParagraph(r, node, color, { halfLeading = false, foregroundPaint
|
|
|
189
198
|
textStyle: baseTextStyle
|
|
190
199
|
});
|
|
191
200
|
if (!r.fontProvider) throw new Error("Font provider not initialized");
|
|
192
|
-
const builder = ck
|
|
201
|
+
const builder = makeParagraphBuilder(ck, paraStyle, r.fontProvider);
|
|
193
202
|
let background;
|
|
194
203
|
try {
|
|
195
204
|
let paintStyle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"sourcesContent":["import type {\n CanvasKit,\n FontStyle,\n Paint,\n Paragraph,\n ParagraphBuilder,\n TextFontFeatures,\n TextFontVariations,\n TextHeightBehavior\n} from 'canvaskit-wasm'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey, type NamedFace } from '@pairdraw/scene-graph/font-style'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport {\n drawnFontVariations,\n loadedFace,\n resolveParagraphFontFamilies\n} from '#core/canvas/text/font-families'\nimport { laidOutText } from '#core/canvas/text/keycap'\nimport {\n pushParagraphStyle,\n type ParagraphPaintStyle,\n type ParagraphBuildOptions\n} from '#core/canvas/text/paint'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { shownTextSlice } from '#core/text/case'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport { fontManager } from '#core/text/font/manager'\n\nimport type { ParagraphNode } from './inputs'\n\nexport function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number {\n if (maxWidth !== undefined) return maxWidth\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') return 1e6\n return node.width || 1e6\n}\n\nexport function buildTruncateOpts(node: ParagraphNode): { maxLines?: number; ellipsis?: string } {\n if (node.textTruncation !== 'ENDING') return {}\n\n const opts: { maxLines?: number; ellipsis: string } = { ellipsis: ELLIPSIS }\n if (node.maxLines != null && node.maxLines > 0) {\n opts.maxLines = node.maxLines\n }\n return opts\n}\n\nfunction getParagraphTextAlign(\n ck: CanvasKit,\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n) {\n const direction = resolveNodeTextDirection(node)\n switch (node.textAlignHorizontal) {\n case 'CENTER':\n return ck.TextAlign.Center\n case 'RIGHT':\n return direction === 'RTL' ? ck.TextAlign.Left : ck.TextAlign.Right\n case 'JUSTIFIED':\n return ck.TextAlign.Justify\n default:\n return direction === 'RTL' ? ck.TextAlign.Right : ck.TextAlign.Left\n }\n}\n\n/** Explicit axes win over the named-instance axes of a variable face (`implicit`). */\nexport function textFontVariations(\n variations: SceneNode['fontVariations'] | undefined,\n implicit: SceneNode['fontVariations'] | null = null\n): TextFontVariations[] | undefined {\n const explicitAxes = new Set(variations?.map((variation) => variation.axis))\n const merged = [\n ...(implicit ?? []).filter((variation) => !explicitAxes.has(variation.axis)),\n ...(variations ?? [])\n ]\n if (merged.length === 0) return undefined\n return merged.map((variation) => ({ axis: variation.axis, value: variation.value }))\n}\n\nexport function textFontFeatures(\n features: SceneNode['fontFeatures'] | undefined\n): TextFontFeatures[] | undefined {\n if (!features || features.length === 0) return undefined\n return features.map((feature) => ({\n name: feature.tag.toLowerCase(),\n value: feature.enabled ? 1 : 0\n }))\n}\n\nexport function textHeightBehaviorValue<T>(\n ck: { TextHeightBehavior: { DisableAll: T } },\n leadingTrim: SceneNode['leadingTrim']\n): T | undefined {\n return leadingTrim === 'CAP_HEIGHT' ? ck.TextHeightBehavior.DisableAll : undefined\n}\n\n/** Which edges of the text a paragraph is: leading trim only trims the text's own edges. */\nexport interface ParagraphEdges {\n first: boolean\n last: boolean\n}\n\nfunction blockHeightBehavior(\n ck: CanvasKit,\n leadingTrim: SceneNode['leadingTrim'],\n edges: ParagraphEdges | undefined\n): TextHeightBehavior | undefined {\n if (!edges) return textHeightBehaviorValue(ck, leadingTrim)\n const { first, last } = edges\n if (leadingTrim !== 'CAP_HEIGHT') return undefined\n if (first && last) return ck.TextHeightBehavior.DisableAll\n if (first) return ck.TextHeightBehavior.DisableFirstAscent\n if (last) return ck.TextHeightBehavior.DisableLastDescent\n return ck.TextHeightBehavior.All\n}\n\n/**\n * The style a paragraph asks CanvasKit for: the face of the family that is loaded. Asked for a\n * face it lacks, CanvasKit slants and emboldens another, which neither Figma, a browser, nor a\n * native text stack draws the same, so a missing face is drawn as the face that exists and\n * reported missing, as Figma does. A family with no face loaded asks for the style as given.\n */\nfunction drawnFontStyle(\n ck: CanvasKit,\n family: string,\n weight: number,\n italic: boolean,\n style: string\n): FontStyle {\n const face = loadedFace(family, weight, italic, style) ?? { weight, italic }\n return {\n weight: { value: face.weight },\n slant: face.italic ? ck.FontSlant.Italic : ck.FontSlant.Upright\n }\n}\n\n/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */\nexport function styleRunColor(\n ck: CanvasKit,\n style: SceneNode['styleRuns'][number]['style'],\n baseColor: Float32Array\n): Float32Array {\n const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === 'SOLID')\n if (!visibleFill) return baseColor\n const color = resolveRGBAForPreview(visibleFill.color).color\n return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity)\n}\n\nfunction styleRunLanguage(\n style: SceneNode['styleRuns'][number]['style'],\n node: Pick<ParagraphNode, 'textLanguage'>\n): string | undefined {\n return (style.textLanguage !== undefined ? style.textLanguage : node.textLanguage) ?? undefined\n}\n\nfunction pushStyleRun(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n run: SceneNode['styleRuns'][number],\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const ck = r.ck\n const style = run.style\n const runFontSize = style.fontSize ?? baseFontSize\n // A percent follows the run's own font size, as in Figma.\n const runLineHeight = lineHeightPixels(\n style.lineHeight !== undefined ? style.lineHeight : node.lineHeight,\n runFontSize\n )\n const runFamily = style.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY)\n const runWeight = style.fontWeight ?? node.fontWeight\n const runItalic = style.italic ?? node.italic\n const runFace = {\n fontWeight: runWeight,\n italic: runItalic,\n fontStyle: rangeFontStyle(node, style)\n }\n const runKey = faceStyleKey(runFace)\n\n const textStyle = new ck.TextStyle({\n color: styleRunColor(ck, style, baseColor),\n fontFamilies: fontFamilies(runFamily, runFace),\n fontSize: runFontSize,\n locale: styleRunLanguage(style, node),\n fontStyle: drawnFontStyle(ck, runFamily, runWeight, runItalic, runKey),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: runFamily,\n weight: runWeight,\n italic: runItalic,\n style: runKey,\n fontSize: runFontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(style.fontFeatures ?? node.fontFeatures),\n letterSpacing: textLengthPixels(style.letterSpacing ?? node.letterSpacing, runFontSize),\n heightMultiplier: runLineHeight ? runLineHeight / runFontSize : undefined,\n halfLeading\n })\n pushParagraphStyle(builder, textStyle, paintStyle)\n}\n\n/** `text[start, end)` in the case each of its characters has. */\nfunction addParagraphText(\n builder: ParagraphBuilder,\n node: ParagraphNode,\n start: number,\n end: number\n): void {\n builder.addText(laidOutText(shownTextSlice(node, start, end)))\n}\n\nfunction addStyledRuns(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const text = node.text\n let pos = 0\n\n for (const run of node.styleRuns) {\n if (pos < run.start) addParagraphText(builder, node, pos, run.start)\n pushStyleRun(\n r,\n builder,\n node,\n run,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n addParagraphText(builder, node, run.start, run.start + run.length)\n builder.pop()\n pos = run.start + run.length\n }\n\n if (pos < text.length) addParagraphText(builder, node, pos, text.length)\n}\n\n/** What a paragraph that is one block of a longer text needs beyond its node's own style. */\nexport interface ParagraphBlockOptions {\n /** Room before the first line, as a plain paragraph's first-line indent. */\n firstLineIndent?: number\n /** Truncation for this block in place of the node's. */\n truncation?: { maxLines?: number; ellipsis?: string }\n edges?: ParagraphEdges\n}\n\n/** Room before a paragraph's first line, as an empty placeholder on its baseline. */\nfunction addFirstLineIndent(ck: CanvasKit, builder: ParagraphBuilder, width: number): void {\n builder.addPlaceholder(width, 0, ck.PlaceholderAlignment.Baseline, ck.TextBaseline.Alphabetic, 0)\n}\n\n/**\n * A native paragraph for `node`'s text in its style runs, not yet laid out. A first-line\n * indent is a placeholder before the text, which takes the first character index.\n */\nexport function buildSkParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n { halfLeading = false, foregroundPaint }: ParagraphBuildOptions = {},\n block: ParagraphBlockOptions = {}\n): Paragraph {\n const ck = r.ck\n const baseColor = color ?? ck.BLACK\n const baseFontSize = node.fontSize || DEFAULT_FONT_SIZE\n const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize)\n const cjkFallbacks = fontManager.getCJKFallbackFamilies()\n const arabicFallbacks = fontManager.getArabicFallbackFamilies()\n const textDirection = resolveNodeTextDirection(node)\n\n const truncateOpts = block.truncation ?? buildTruncateOpts(node)\n\n const fontFamilies = (primary: string, face: NamedFace) =>\n resolveParagraphFontFamilies(\n primary,\n { weight: face.fontWeight, italic: face.italic, style: faceStyleKey(face) },\n arabicFallbacks,\n cjkFallbacks\n )\n const nodeKey = faceStyleKey(node)\n\n const baseTextStyle = {\n color: baseColor,\n fontFamilies: fontFamilies(node.fontFamily || DEFAULT_FONT_FAMILY, node),\n fontSize: baseFontSize,\n locale: node.textLanguage ?? undefined,\n fontStyle: drawnFontStyle(\n ck,\n node.fontFamily || DEFAULT_FONT_FAMILY,\n node.fontWeight,\n node.italic,\n nodeKey\n ),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: node.fontFamily || DEFAULT_FONT_FAMILY,\n weight: node.fontWeight,\n italic: node.italic,\n style: nodeKey,\n fontSize: baseFontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(node.fontFeatures),\n letterSpacing: textLengthPixels(node.letterSpacing, baseFontSize),\n heightMultiplier: baseLineHeight ? baseLineHeight / baseFontSize : undefined,\n halfLeading\n }\n const paraStyle = new ck.ParagraphStyle({\n textAlign: getParagraphTextAlign(ck, node),\n textDirection: textDirection === 'RTL' ? ck.TextDirection.RTL : ck.TextDirection.LTR,\n textHeightBehavior: blockHeightBehavior(ck, node.leadingTrim, block.edges),\n ...truncateOpts,\n textStyle: baseTextStyle\n })\n\n if (!r.fontProvider) throw new Error('Font provider not initialized')\n const builder = ck.ParagraphBuilder.MakeFromFontProvider(paraStyle, r.fontProvider)\n\n let background: Paint | undefined\n try {\n let paintStyle: ParagraphPaintStyle | undefined\n if (foregroundPaint) {\n background = new ck.Paint()\n background.setColor(ck.TRANSPARENT)\n paintStyle = { foreground: foregroundPaint, background }\n builder.pushPaintStyle(new ck.TextStyle(baseTextStyle), foregroundPaint, background)\n }\n if (block.firstLineIndent) addFirstLineIndent(ck, builder, block.firstLineIndent)\n if (node.styleRuns.length === 0) {\n addParagraphText(builder, node, 0, node.text.length)\n } else {\n addStyledRuns(\n r,\n builder,\n node,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n }\n\n return builder.build()\n } finally {\n builder.delete()\n background?.delete()\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iB,eAAe,KAAA;EACnE;CACF;CACA,MAAM,YAAY,IAAI,GAAG,eAAe;EACtC,WAAW,sBAAsB,IAAI,IAAI;EACzC,eAAe,kBAAkB,QAAQ,GAAG,cAAc,MAAM,GAAG,cAAc;EACjF,oBAAoB,oBAAoB,IAAI,KAAK,aAAa,MAAM,KAAK;EACzE,GAAG;EACH,WAAW;CACb,CAAC;CAED,IAAI,CAAC,EAAE,cAAc,MAAM,IAAI,MAAM,+BAA+B;CACpE,MAAM,UAAU,GAAG,iBAAiB,qBAAqB,WAAW,EAAE,YAAY;CAElF,IAAI;CACJ,IAAI;EACF,IAAI;EACJ,IAAI,iBAAiB;GACnB,aAAa,IAAI,GAAG,MAAM;GAC1B,WAAW,SAAS,GAAG,WAAW;GAClC,aAAa;IAAE,YAAY;IAAiB;GAAW;GACvD,QAAQ,eAAe,IAAI,GAAG,UAAU,aAAa,GAAG,iBAAiB,UAAU;EACrF;EACA,IAAI,MAAM,iBAAiB,mBAAmB,IAAI,SAAS,MAAM,eAAe;EAChF,IAAI,KAAK,UAAU,WAAW,GAC5B,iBAAiB,SAAS,MAAM,GAAG,KAAK,KAAK,MAAM;OAEnD,cACE,GACA,SACA,MACA,WACA,cACA,cACA,aACA,UACF;EAGF,OAAO,QAAQ,MAAM;CACvB,UAAU;EACR,QAAQ,OAAO;EACf,YAAY,OAAO;CACrB;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"sourcesContent":["import type {\n CanvasKit,\n FontStyle,\n Paint,\n Paragraph,\n ParagraphBuilder,\n TextFontFeatures,\n TextFontVariations,\n TextHeightBehavior\n} from 'canvaskit-wasm'\n\nimport type { SceneNode } from '@pairdraw/scene-graph'\nimport { resolveRGBAForPreview } from '@pairdraw/scene-graph/color'\nimport { faceStyleKey, type NamedFace } from '@pairdraw/scene-graph/font-style'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport { lineHeightPixels, textLengthPixels } from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport {\n drawnFontVariations,\n loadedFace,\n resolveParagraphFontFamilies\n} from '#core/canvas/text/font-families'\nimport { laidOutText } from '#core/canvas/text/keycap'\nimport {\n pushParagraphStyle,\n type ParagraphPaintStyle,\n type ParagraphBuildOptions\n} from '#core/canvas/text/paint'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { autoWidthWrapWidth } from '#core/layout/text-measurement'\nimport { shownTextSlice } from '#core/text/case'\nimport { ELLIPSIS } from '#core/text/ellipsis'\nimport { makeParagraphBuilder } from '#core/text/font/collection'\nimport { fontManager } from '#core/text/font/manager'\n\nimport type { ParagraphNode } from './inputs'\n\nexport function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number {\n if (maxWidth !== undefined) return maxWidth\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') {\n return autoWidthWrapWidth(node) ?? 1e6\n }\n return node.width || 1e6\n}\n\n/**\n * The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as\n * Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even\n * where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.\n */\nexport function buildTruncateOpts(node: ParagraphNode): { maxLines?: number; ellipsis?: string } {\n if (node.textTruncation !== 'ENDING' && node.textAutoResize !== 'TRUNCATE') return {}\n // A box that truncates only by its height is measured as it is, then capped by the lines that\n // fit and built again with that count.\n if (node.maxLines == null || node.maxLines <= 0) {\n return node.textAutoResize === 'TRUNCATE' ? {} : { ellipsis: ELLIPSIS }\n }\n return { maxLines: node.maxLines, ellipsis: ELLIPSIS }\n}\n\nfunction getParagraphTextAlign(\n ck: CanvasKit,\n node: Pick<SceneNode, 'textAlignHorizontal' | 'textDirection' | 'text'>\n) {\n const direction = resolveNodeTextDirection(node)\n switch (node.textAlignHorizontal) {\n case 'CENTER':\n return ck.TextAlign.Center\n case 'RIGHT':\n return direction === 'RTL' ? ck.TextAlign.Left : ck.TextAlign.Right\n case 'JUSTIFIED':\n return ck.TextAlign.Justify\n default:\n return direction === 'RTL' ? ck.TextAlign.Right : ck.TextAlign.Left\n }\n}\n\n/** Explicit axes win over the named-instance axes of a variable face (`implicit`). */\nexport function textFontVariations(\n variations: SceneNode['fontVariations'] | undefined,\n implicit: SceneNode['fontVariations'] | null = null\n): TextFontVariations[] | undefined {\n const explicitAxes = new Set(variations?.map((variation) => variation.axis))\n const merged = [\n ...(implicit ?? []).filter((variation) => !explicitAxes.has(variation.axis)),\n ...(variations ?? [])\n ]\n if (merged.length === 0) return undefined\n return merged.map((variation) => ({ axis: variation.axis, value: variation.value }))\n}\n\nexport function textFontFeatures(\n features: SceneNode['fontFeatures'] | undefined\n): TextFontFeatures[] | undefined {\n if (!features || features.length === 0) return undefined\n return features.map((feature) => ({\n name: feature.tag.toLowerCase(),\n value: feature.enabled ? 1 : 0\n }))\n}\n\nexport function textHeightBehaviorValue<T>(\n ck: { TextHeightBehavior: { DisableAll: T } },\n leadingTrim: SceneNode['leadingTrim']\n): T | undefined {\n return leadingTrim === 'CAP_HEIGHT' ? ck.TextHeightBehavior.DisableAll : undefined\n}\n\n/** Which edges of the text a paragraph is: leading trim only trims the text's own edges. */\nexport interface ParagraphEdges {\n first: boolean\n last: boolean\n}\n\nfunction blockHeightBehavior(\n ck: CanvasKit,\n leadingTrim: SceneNode['leadingTrim'],\n edges: ParagraphEdges | undefined\n): TextHeightBehavior | undefined {\n if (!edges) return textHeightBehaviorValue(ck, leadingTrim)\n const { first, last } = edges\n if (leadingTrim !== 'CAP_HEIGHT') return undefined\n if (first && last) return ck.TextHeightBehavior.DisableAll\n if (first) return ck.TextHeightBehavior.DisableFirstAscent\n if (last) return ck.TextHeightBehavior.DisableLastDescent\n return ck.TextHeightBehavior.All\n}\n\n/**\n * The style a paragraph asks CanvasKit for: the face of the family that is loaded. Asked for a\n * face it lacks, CanvasKit slants and emboldens another, which neither Figma, a browser, nor a\n * native text stack draws the same, so a missing face is drawn as the face that exists and\n * reported missing, as Figma does. A family with no face loaded asks for the style as given.\n */\nfunction drawnFontStyle(\n ck: CanvasKit,\n family: string,\n weight: number,\n italic: boolean,\n style: string\n): FontStyle {\n const face = loadedFace(family, weight, italic, style) ?? { weight, italic }\n return {\n weight: { value: face.weight },\n slant: face.italic ? ck.FontSlant.Italic : ck.FontSlant.Upright\n }\n}\n\n/** The colour a style run's text is drawn in: its first visible solid fill, or `baseColor`. */\nexport function styleRunColor(\n ck: CanvasKit,\n style: SceneNode['styleRuns'][number]['style'],\n baseColor: Float32Array\n): Float32Array {\n const visibleFill = style.fills?.find((fill) => fill.visible && fill.type === 'SOLID')\n if (!visibleFill) return baseColor\n const color = resolveRGBAForPreview(visibleFill.color).color\n return ck.Color4f(color.r, color.g, color.b, color.a * visibleFill.opacity)\n}\n\nfunction styleRunLanguage(\n style: SceneNode['styleRuns'][number]['style'],\n node: Pick<ParagraphNode, 'textLanguage'>\n): string | undefined {\n return (style.textLanguage !== undefined ? style.textLanguage : node.textLanguage) ?? undefined\n}\n\nfunction pushStyleRun(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n run: SceneNode['styleRuns'][number],\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const ck = r.ck\n const style = run.style\n const runFontSize = style.fontSize ?? baseFontSize\n // A percent follows the run's own font size, as in Figma.\n const runLineHeight = lineHeightPixels(\n style.lineHeight !== undefined ? style.lineHeight : node.lineHeight,\n runFontSize\n )\n const runFamily = style.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY)\n const runWeight = style.fontWeight ?? node.fontWeight\n const runItalic = style.italic ?? node.italic\n const runFace = {\n fontWeight: runWeight,\n italic: runItalic,\n fontStyle: rangeFontStyle(node, style)\n }\n const runKey = faceStyleKey(runFace)\n\n const textStyle = new ck.TextStyle({\n color: styleRunColor(ck, style, baseColor),\n fontFamilies: fontFamilies(runFamily, runFace),\n fontSize: runFontSize,\n locale: styleRunLanguage(style, node),\n fontStyle: drawnFontStyle(ck, runFamily, runWeight, runItalic, runKey),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: runFamily,\n weight: runWeight,\n italic: runItalic,\n style: runKey,\n fontSize: runFontSize,\n variations: style.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: style.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(style.fontFeatures ?? node.fontFeatures),\n letterSpacing: textLengthPixels(style.letterSpacing ?? node.letterSpacing, runFontSize),\n heightMultiplier: runLineHeight ? runLineHeight / runFontSize : undefined,\n halfLeading\n })\n pushParagraphStyle(builder, textStyle, paintStyle)\n}\n\n/** `text[start, end)` in the case each of its characters has. */\nfunction addParagraphText(\n builder: ParagraphBuilder,\n node: ParagraphNode,\n start: number,\n end: number\n): void {\n builder.addText(laidOutText(shownTextSlice(node, start, end)))\n}\n\nfunction addStyledRuns(\n r: TextRenderer,\n builder: ParagraphBuilder,\n node: ParagraphNode,\n baseColor: Float32Array,\n baseFontSize: number,\n fontFamilies: (primary: string, face: NamedFace) => string[],\n halfLeading: boolean,\n paintStyle?: ParagraphPaintStyle\n): void {\n const text = node.text\n let pos = 0\n\n for (const run of node.styleRuns) {\n if (pos < run.start) addParagraphText(builder, node, pos, run.start)\n pushStyleRun(\n r,\n builder,\n node,\n run,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n addParagraphText(builder, node, run.start, run.start + run.length)\n builder.pop()\n pos = run.start + run.length\n }\n\n if (pos < text.length) addParagraphText(builder, node, pos, text.length)\n}\n\n/** What a paragraph that is one block of a longer text needs beyond its node's own style. */\nexport interface ParagraphBlockOptions {\n /** Room before the first line, as a plain paragraph's first-line indent. */\n firstLineIndent?: number\n /** Truncation for this block in place of the node's. */\n truncation?: { maxLines?: number; ellipsis?: string }\n edges?: ParagraphEdges\n}\n\n/** Room before a paragraph's first line, as an empty placeholder on its baseline. */\nfunction addFirstLineIndent(ck: CanvasKit, builder: ParagraphBuilder, width: number): void {\n builder.addPlaceholder(width, 0, ck.PlaceholderAlignment.Baseline, ck.TextBaseline.Alphabetic, 0)\n}\n\n/**\n * A native paragraph for `node`'s text in its style runs, not yet laid out. A first-line\n * indent is a placeholder before the text, which takes the first character index.\n */\nexport function buildSkParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n { halfLeading = false, foregroundPaint }: ParagraphBuildOptions = {},\n block: ParagraphBlockOptions = {}\n): Paragraph {\n const ck = r.ck\n const baseColor = color ?? ck.BLACK\n const baseFontSize = node.fontSize || DEFAULT_FONT_SIZE\n const baseLineHeight = lineHeightPixels(node.lineHeight, baseFontSize)\n const cjkFallbacks = fontManager.getCJKFallbackFamilies()\n const letterFallbacks = fontManager.getLetterFallbackFamilies()\n const textDirection = resolveNodeTextDirection(node)\n\n const truncateOpts = block.truncation ?? buildTruncateOpts(node)\n\n const fontFamilies = (primary: string, face: NamedFace) =>\n resolveParagraphFontFamilies(\n primary,\n { weight: face.fontWeight, italic: face.italic, style: faceStyleKey(face) },\n letterFallbacks,\n cjkFallbacks\n )\n const nodeKey = faceStyleKey(node)\n\n const baseTextStyle = {\n color: baseColor,\n fontFamilies: fontFamilies(node.fontFamily || DEFAULT_FONT_FAMILY, node),\n fontSize: baseFontSize,\n locale: node.textLanguage ?? undefined,\n fontStyle: drawnFontStyle(\n ck,\n node.fontFamily || DEFAULT_FONT_FAMILY,\n node.fontWeight,\n node.italic,\n nodeKey\n ),\n fontVariations: textFontVariations(\n drawnFontVariations({\n family: node.fontFamily || DEFAULT_FONT_FAMILY,\n weight: node.fontWeight,\n italic: node.italic,\n style: nodeKey,\n fontSize: baseFontSize,\n variations: node.fontVariations,\n opticalSizeFromFontSize: node.opticalSizeFromFontSize\n })\n ),\n fontFeatures: textFontFeatures(node.fontFeatures),\n letterSpacing: textLengthPixels(node.letterSpacing, baseFontSize),\n heightMultiplier: baseLineHeight ? baseLineHeight / baseFontSize : undefined,\n halfLeading\n }\n const paraStyle = new ck.ParagraphStyle({\n textAlign: getParagraphTextAlign(ck, node),\n textDirection: textDirection === 'RTL' ? ck.TextDirection.RTL : ck.TextDirection.LTR,\n textHeightBehavior: blockHeightBehavior(ck, node.leadingTrim, block.edges),\n ...truncateOpts,\n textStyle: baseTextStyle\n })\n\n if (!r.fontProvider) throw new Error('Font provider not initialized')\n const builder = makeParagraphBuilder(ck, paraStyle, r.fontProvider)\n\n let background: Paint | undefined\n try {\n let paintStyle: ParagraphPaintStyle | undefined\n if (foregroundPaint) {\n background = new ck.Paint()\n background.setColor(ck.TRANSPARENT)\n paintStyle = { foreground: foregroundPaint, background }\n builder.pushPaintStyle(new ck.TextStyle(baseTextStyle), foregroundPaint, background)\n }\n if (block.firstLineIndent) addFirstLineIndent(ck, builder, block.firstLineIndent)\n if (node.styleRuns.length === 0) {\n addParagraphText(builder, node, 0, node.text.length)\n } else {\n addStyledRuns(\n r,\n builder,\n node,\n baseColor,\n baseFontSize,\n fontFamilies,\n halfLeading,\n paintStyle\n )\n }\n\n return builder.build()\n } finally {\n builder.delete()\n background?.delete()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuCA,SAAgB,4BAA4B,MAAqB,UAA2B;CAC1F,IAAI,aAAa,KAAA,GAAW,OAAO;CACnC,IAAI,KAAK,mBAAmB,oBAC1B,OAAO,mBAAmB,IAAI,KAAK;CAErC,OAAO,KAAK,SAAS;AACvB;;;;;;AAOA,SAAgB,kBAAkB,MAA+D;CAC/F,IAAI,KAAK,mBAAmB,YAAY,KAAK,mBAAmB,YAAY,OAAO,CAAC;CAGpF,IAAI,KAAK,YAAY,QAAQ,KAAK,YAAY,GAC5C,OAAO,KAAK,mBAAmB,aAAa,CAAC,IAAI,EAAE,UAAA,IAAmB;CAExE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W,EAAE,YAAY;CAElE,IAAI;CACJ,IAAI;EACF,IAAI;EACJ,IAAI,iBAAiB;GACnB,aAAa,IAAI,GAAG,MAAM;GAC1B,WAAW,SAAS,GAAG,WAAW;GAClC,aAAa;IAAE,YAAY;IAAiB;GAAW;GACvD,QAAQ,eAAe,IAAI,GAAG,UAAU,aAAa,GAAG,iBAAiB,UAAU;EACrF;EACA,IAAI,MAAM,iBAAiB,mBAAmB,IAAI,SAAS,MAAM,eAAe;EAChF,IAAI,KAAK,UAAU,WAAW,GAC5B,iBAAiB,SAAS,MAAM,GAAG,KAAK,KAAK,MAAM;OAEnD,cACE,GACA,SACA,MACA,WACA,cACA,cACA,aACA,UACF;EAGF,OAAO,QAAQ,MAAM;CACvB,UAAU;EACR,QAAQ,OAAO;EACf,YAAY,OAAO;CACrB;AACF"}
|
|
@@ -4,7 +4,7 @@ import { SceneNode } from "@pairdraw/scene-graph";
|
|
|
4
4
|
* Paragraph construction is typed against this list, which also drives cache invalidation; the
|
|
5
5
|
* decoration fields keep the decorations a prepared text holds current with it.
|
|
6
6
|
*/
|
|
7
|
-
declare const PARAGRAPH_INPUT_KEYS: readonly ["text", "fontFamily", "fontSize", "fontWeight", "italic", "fontStyle", "styleRuns", "fontVariations", "opticalSizeFromFontSize", "fontFeatures", "textLanguage", "textDirection", "textCase", "letterSpacing", "lineHeight", "textAlignHorizontal", "leadingTrim", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textDecorationFills", "textDecorationSkipInk", "textUnderlineOffset", "textTruncation", "maxLines", "textParagraphs", "listSpacing", "paragraphSpacing", "paragraphIndent", "hangingList", "textAutoResize", "width", "height"];
|
|
7
|
+
declare const PARAGRAPH_INPUT_KEYS: readonly ["text", "fontFamily", "fontSize", "fontWeight", "italic", "fontStyle", "styleRuns", "fontVariations", "opticalSizeFromFontSize", "fontFeatures", "textLanguage", "textDirection", "textCase", "letterSpacing", "lineHeight", "textAlignHorizontal", "leadingTrim", "textDecoration", "textDecorationStyle", "textDecorationThickness", "textDecorationFills", "textDecorationSkipInk", "textUnderlineOffset", "textTruncation", "maxLines", "textParagraphs", "listSpacing", "paragraphSpacing", "paragraphIndent", "hangingList", "textAutoResize", "width", "height", "minWidth", "maxWidth"];
|
|
8
8
|
type ParagraphNode = Pick<SceneNode, (typeof PARAGRAPH_INPUT_KEYS)[number]>;
|
|
9
9
|
/**
|
|
10
10
|
* The paragraph inputs that decide how text shapes: which glyphs it needs and how big it is at a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/inputs.ts"],"mappings":";;;;;;cAMa;
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/inputs.ts"],"mappings":";;;;;;cAMa;KAsCD,gBAAgB,KAAK,mBAAmB;;;;;;iBASpC,cAAc,MAAM,gBAAgB,oBAAoB;;iBAQxD,eAAe,sBAAsB"}
|
|
@@ -36,9 +36,16 @@ const PARAGRAPH_INPUT_KEYS = [
|
|
|
36
36
|
"hangingList",
|
|
37
37
|
"textAutoResize",
|
|
38
38
|
"width",
|
|
39
|
-
"height"
|
|
39
|
+
"height",
|
|
40
|
+
"minWidth",
|
|
41
|
+
"maxWidth"
|
|
40
42
|
];
|
|
41
|
-
const BOX_SIZE_KEYS = /* @__PURE__ */ new Set([
|
|
43
|
+
const BOX_SIZE_KEYS = /* @__PURE__ */ new Set([
|
|
44
|
+
"width",
|
|
45
|
+
"height",
|
|
46
|
+
"minWidth",
|
|
47
|
+
"maxWidth"
|
|
48
|
+
]);
|
|
42
49
|
/**
|
|
43
50
|
* The paragraph inputs that decide how text shapes: which glyphs it needs and how big it is at a
|
|
44
51
|
* given layout width. The box size only matters when the text is truncated, since it decides
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.js","names":[],"sources":["../../../../src/canvas/text/paragraph/inputs.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\n/**\n * Paragraph construction is typed against this list, which also drives cache invalidation; the\n * decoration fields keep the decorations a prepared text holds current with it.\n */\nexport const PARAGRAPH_INPUT_KEYS = [\n 'text',\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'styleRuns',\n 'fontVariations',\n 'opticalSizeFromFontSize',\n 'fontFeatures',\n 'textLanguage',\n 'textDirection',\n 'textCase',\n 'letterSpacing',\n 'lineHeight',\n 'textAlignHorizontal',\n 'leadingTrim',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'textTruncation',\n 'maxLines',\n 'textParagraphs',\n 'listSpacing',\n 'paragraphSpacing',\n 'paragraphIndent',\n 'hangingList',\n 'textAutoResize',\n 'width',\n 'height'\n] as const satisfies readonly (keyof SceneNode)[]\n\nexport type ParagraphNode = Pick<SceneNode, (typeof PARAGRAPH_INPUT_KEYS)[number]>\n\nconst BOX_SIZE_KEYS = new Set<keyof SceneNode>(['width', 'height'])\n\n/**\n * The paragraph inputs that decide how text shapes: which glyphs it needs and how big it is at a\n * given layout width. The box size only matters when the text is truncated, since it decides\n * which characters are shown; otherwise layout resizing the box leaves both as they were.\n */\nexport function shapingInputs(node: ParagraphNode): ParagraphNode[keyof ParagraphNode][] {\n const truncated = node.textTruncation === 'ENDING'\n return PARAGRAPH_INPUT_KEYS.filter((key) => truncated || !BOX_SIZE_KEYS.has(key)).map(\n (key) => node[key]\n )\n}\n\n/** Whether a change to `keys` can change shaping beyond what `shapingInputs` sees. */\nexport function changesShaping(keys: readonly (keyof SceneNode)[]): boolean {\n return keys.some(\n (key) => !BOX_SIZE_KEYS.has(key) && (PARAGRAPH_INPUT_KEYS as readonly string[]).includes(key)\n )\n}\n"],"mappings":";;;;;AAMA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,gCAAgB,IAAI,IAAqB
|
|
1
|
+
{"version":3,"file":"inputs.js","names":[],"sources":["../../../../src/canvas/text/paragraph/inputs.ts"],"sourcesContent":["import type { SceneNode } from '@pairdraw/scene-graph'\n\n/**\n * Paragraph construction is typed against this list, which also drives cache invalidation; the\n * decoration fields keep the decorations a prepared text holds current with it.\n */\nexport const PARAGRAPH_INPUT_KEYS = [\n 'text',\n 'fontFamily',\n 'fontSize',\n 'fontWeight',\n 'italic',\n 'fontStyle',\n 'styleRuns',\n 'fontVariations',\n 'opticalSizeFromFontSize',\n 'fontFeatures',\n 'textLanguage',\n 'textDirection',\n 'textCase',\n 'letterSpacing',\n 'lineHeight',\n 'textAlignHorizontal',\n 'leadingTrim',\n 'textDecoration',\n 'textDecorationStyle',\n 'textDecorationThickness',\n 'textDecorationFills',\n 'textDecorationSkipInk',\n 'textUnderlineOffset',\n 'textTruncation',\n 'maxLines',\n 'textParagraphs',\n 'listSpacing',\n 'paragraphSpacing',\n 'paragraphIndent',\n 'hangingList',\n 'textAutoResize',\n 'width',\n 'height',\n 'minWidth',\n 'maxWidth'\n] as const satisfies readonly (keyof SceneNode)[]\n\nexport type ParagraphNode = Pick<SceneNode, (typeof PARAGRAPH_INPUT_KEYS)[number]>\n\nconst BOX_SIZE_KEYS = new Set<keyof SceneNode>(['width', 'height', 'minWidth', 'maxWidth'])\n\n/**\n * The paragraph inputs that decide how text shapes: which glyphs it needs and how big it is at a\n * given layout width. The box size only matters when the text is truncated, since it decides\n * which characters are shown; otherwise layout resizing the box leaves both as they were.\n */\nexport function shapingInputs(node: ParagraphNode): ParagraphNode[keyof ParagraphNode][] {\n const truncated = node.textTruncation === 'ENDING'\n return PARAGRAPH_INPUT_KEYS.filter((key) => truncated || !BOX_SIZE_KEYS.has(key)).map(\n (key) => node[key]\n )\n}\n\n/** Whether a change to `keys` can change shaping beyond what `shapingInputs` sees. */\nexport function changesShaping(keys: readonly (keyof SceneNode)[]): boolean {\n return keys.some(\n (key) => !BOX_SIZE_KEYS.has(key) && (PARAGRAPH_INPUT_KEYS as readonly string[]).includes(key)\n )\n}\n"],"mappings":";;;;;AAMA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAIA,MAAM,gCAAgB,IAAI,IAAqB;CAAC;CAAS;CAAU;CAAY;AAAU,CAAC;;;;;;AAO1F,SAAgB,cAAc,MAA2D;CACvF,MAAM,YAAY,KAAK,mBAAmB;CAC1C,OAAO,qBAAqB,QAAQ,QAAQ,aAAa,CAAC,cAAc,IAAI,GAAG,CAAC,CAAC,CAAC,KAC/E,QAAQ,KAAK,IAChB;AACF;;AAGA,SAAgB,eAAe,MAA6C;CAC1E,OAAO,KAAK,MACT,QAAQ,CAAC,cAAc,IAAI,GAAG,KAAM,qBAA2C,SAAS,GAAG,CAC9F;AACF"}
|
|
@@ -2,9 +2,9 @@ import "../../constants.js";
|
|
|
2
2
|
import { shownCharacters } from "../../text/case.js";
|
|
3
3
|
import { textFontFace } from "../../text/requirements/collect.js";
|
|
4
4
|
import { fontManager } from "../../text/font/manager.js";
|
|
5
|
+
import { drawnFontVariations, loadedFace, paragraphSourceFamilies } from "./font-families.js";
|
|
5
6
|
import { glyphOutlineSourceSync, shardCovers, shardOutlineSources } from "../../text/font/glyphs.js";
|
|
6
7
|
import { laidOutText } from "./keycap.js";
|
|
7
|
-
import { drawnFontVariations, loadedFace, paragraphSourceFamilies } from "./font-families.js";
|
|
8
8
|
import "../../text/ellipsis.js";
|
|
9
9
|
import { utf16IndicesByUtf8 } from "./utf8.js";
|
|
10
10
|
import { textLengthPixels } from "@pairdraw/scene-graph/text";
|
|
@@ -78,10 +78,10 @@ function featuresOf(node, run) {
|
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* The style a family of the paragraph is drawn in: the face its own family draws the asked style
|
|
81
|
-
* in, and Regular for the
|
|
81
|
+
* in, and Regular for the script fallbacks, as the paragraph asks CanvasKit for them.
|
|
82
82
|
*/
|
|
83
83
|
function sourceStyle(family, font) {
|
|
84
|
-
if (family !== font.family && (fontManager.
|
|
84
|
+
if (family !== font.family && (fontManager.getLetterFallbackFamilies().includes(family) || fontManager.getCJKFallbackFamilies().includes(family))) return fontManager.isStyleLoaded(family, "Regular") ? "Regular" : null;
|
|
85
85
|
return loadedStyle(family, font.drawn.weight, font.drawn.italic, font.drawn.style);
|
|
86
86
|
}
|
|
87
87
|
/**
|