@react-x11/components 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist/charts/node.d.ts +11 -1
- package/dist/charts/node.d.ts.map +1 -1
- package/dist/charts/node.js +44 -14
- package/dist/charts/node.js.map +1 -1
- package/dist/charts/render.d.ts +12 -3
- package/dist/charts/render.d.ts.map +1 -1
- package/dist/charts/render.js +94 -25
- package/dist/charts/render.js.map +1 -1
- package/dist/code/index.d.ts.map +1 -1
- package/dist/code/index.js +27 -24
- package/dist/code/index.js.map +1 -1
- package/dist/code-editor/completion.d.ts.map +1 -1
- package/dist/code-editor/completion.js +3 -2
- package/dist/code-editor/completion.js.map +1 -1
- package/dist/code-editor/index.d.ts.map +1 -1
- package/dist/code-editor/index.js +19 -0
- package/dist/code-editor/index.js.map +1 -1
- package/dist/code-editor/node.d.ts +177 -7
- package/dist/code-editor/node.d.ts.map +1 -1
- package/dist/code-editor/node.js +1329 -164
- package/dist/code-editor/node.js.map +1 -1
- package/dist/code-language/index.d.ts +1 -1
- package/dist/code-language/index.d.ts.map +1 -1
- package/dist/code-language/index.js +1 -1
- package/dist/code-language/index.js.map +1 -1
- package/dist/code-language/languages/glsl.d.ts.map +1 -1
- package/dist/code-language/languages/glsl.js +10 -2
- package/dist/code-language/languages/glsl.js.map +1 -1
- package/dist/code-language/languages/javascript.d.ts.map +1 -1
- package/dist/code-language/languages/javascript.js +18 -3
- package/dist/code-language/languages/javascript.js.map +1 -1
- package/dist/code-language/languages/json.d.ts.map +1 -1
- package/dist/code-language/languages/json.js +10 -2
- package/dist/code-language/languages/json.js.map +1 -1
- package/dist/code-language/languages/shell.d.ts.map +1 -1
- package/dist/code-language/languages/shell.js +10 -2
- package/dist/code-language/languages/shell.js.map +1 -1
- package/dist/code-language/languages/sql.d.ts.map +1 -1
- package/dist/code-language/languages/sql.js +20 -2
- package/dist/code-language/languages/sql.js.map +1 -1
- package/dist/code-language/runs.d.ts +31 -0
- package/dist/code-language/runs.d.ts.map +1 -1
- package/dist/code-language/runs.js +105 -0
- package/dist/code-language/runs.js.map +1 -1
- package/dist/code-language/stream.d.ts +22 -0
- package/dist/code-language/stream.d.ts.map +1 -1
- package/dist/code-language/stream.js +259 -9
- package/dist/code-language/stream.js.map +1 -1
- package/dist/code-language/types.d.ts +5 -4
- package/dist/code-language/types.d.ts.map +1 -1
- package/dist/codeblock/index.d.ts +26 -2
- package/dist/codeblock/index.d.ts.map +1 -1
- package/dist/codeblock/index.js +57 -4
- package/dist/codeblock/index.js.map +1 -1
- package/dist/flow/draw.d.ts +50 -0
- package/dist/flow/draw.d.ts.map +1 -1
- package/dist/flow/draw.js +132 -33
- package/dist/flow/draw.js.map +1 -1
- package/dist/flow/gl/color.d.ts +13 -0
- package/dist/flow/gl/color.d.ts.map +1 -0
- package/dist/flow/gl/color.js +82 -0
- package/dist/flow/gl/color.js.map +1 -0
- package/dist/flow/gl/index.d.ts +60 -0
- package/dist/flow/gl/index.d.ts.map +1 -0
- package/dist/flow/gl/index.js +283 -0
- package/dist/flow/gl/index.js.map +1 -0
- package/dist/flow/gl/pack.d.ts +133 -0
- package/dist/flow/gl/pack.d.ts.map +1 -0
- package/dist/flow/gl/pack.js +408 -0
- package/dist/flow/gl/pack.js.map +1 -0
- package/dist/flow/gl/renderer.d.ts +95 -0
- package/dist/flow/gl/renderer.d.ts.map +1 -0
- package/dist/flow/gl/renderer.js +459 -0
- package/dist/flow/gl/renderer.js.map +1 -0
- package/dist/flow/gl/shaders.d.ts +79 -0
- package/dist/flow/gl/shaders.d.ts.map +1 -0
- package/dist/flow/gl/shaders.js +346 -0
- package/dist/flow/gl/shaders.js.map +1 -0
- package/dist/flow/gl/text.d.ts +318 -0
- package/dist/flow/gl/text.d.ts.map +1 -0
- package/dist/flow/gl/text.js +1103 -0
- package/dist/flow/gl/text.js.map +1 -0
- package/dist/flow/index.d.ts +1 -1
- package/dist/flow/index.d.ts.map +1 -1
- package/dist/flow/index.js +619 -64
- package/dist/flow/index.js.map +1 -1
- package/dist/flow/node.d.ts +621 -72
- package/dist/flow/node.d.ts.map +1 -1
- package/dist/flow/node.js +2253 -1018
- package/dist/flow/node.js.map +1 -1
- package/dist/flow/paint.d.ts +35 -0
- package/dist/flow/paint.d.ts.map +1 -0
- package/dist/flow/paint.js +393 -0
- package/dist/flow/paint.js.map +1 -0
- package/dist/flow/paths.d.ts +14 -0
- package/dist/flow/paths.d.ts.map +1 -1
- package/dist/flow/paths.js +45 -19
- package/dist/flow/paths.js.map +1 -1
- package/dist/flow/scene.d.ts +584 -0
- package/dist/flow/scene.d.ts.map +1 -0
- package/dist/flow/scene.js +1453 -0
- package/dist/flow/scene.js.map +1 -0
- package/dist/flow/types.d.ts +111 -1
- package/dist/flow/types.d.ts.map +1 -1
- package/dist/html/controls.d.ts +28 -0
- package/dist/html/controls.d.ts.map +1 -1
- package/dist/html/controls.js +52 -2
- package/dist/html/controls.js.map +1 -1
- package/dist/html/css/calc.d.ts +14 -0
- package/dist/html/css/calc.d.ts.map +1 -0
- package/dist/html/css/calc.js +344 -0
- package/dist/html/css/calc.js.map +1 -0
- package/dist/html/css/cascade.d.ts +262 -6
- package/dist/html/css/cascade.d.ts.map +1 -1
- package/dist/html/css/cascade.js +1373 -67
- package/dist/html/css/cascade.js.map +1 -1
- package/dist/html/css/color.d.ts +23 -0
- package/dist/html/css/color.d.ts.map +1 -0
- package/dist/html/css/color.js +740 -0
- package/dist/html/css/color.js.map +1 -0
- package/dist/html/css/content.d.ts +92 -0
- package/dist/html/css/content.d.ts.map +1 -0
- package/dist/html/css/content.js +388 -0
- package/dist/html/css/content.js.map +1 -0
- package/dist/html/css/counter-styles.d.ts +76 -0
- package/dist/html/css/counter-styles.d.ts.map +1 -0
- package/dist/html/css/counter-styles.js +893 -0
- package/dist/html/css/counter-styles.js.map +1 -0
- package/dist/html/css/decode.d.ts +12 -0
- package/dist/html/css/decode.d.ts.map +1 -0
- package/dist/html/css/decode.js +116 -0
- package/dist/html/css/decode.js.map +1 -0
- package/dist/html/css/parse.d.ts +110 -10
- package/dist/html/css/parse.d.ts.map +1 -1
- package/dist/html/css/parse.js +1473 -180
- package/dist/html/css/parse.js.map +1 -1
- package/dist/html/css/style.d.ts +501 -15
- package/dist/html/css/style.d.ts.map +1 -1
- package/dist/html/css/style.js +3729 -206
- package/dist/html/css/style.js.map +1 -1
- package/dist/html/css/ua.d.ts.map +1 -1
- package/dist/html/css/ua.js +65 -16
- package/dist/html/css/ua.js.map +1 -1
- package/dist/html/css/values.d.ts +37 -3
- package/dist/html/css/values.d.ts.map +1 -1
- package/dist/html/css/values.js +122 -48
- package/dist/html/css/values.js.map +1 -1
- package/dist/html/css/vars.d.ts +52 -0
- package/dist/html/css/vars.d.ts.map +1 -0
- package/dist/html/css/vars.js +358 -0
- package/dist/html/css/vars.js.map +1 -0
- package/dist/html/dom.d.ts +30 -4
- package/dist/html/dom.d.ts.map +1 -1
- package/dist/html/dom.js +278 -17
- package/dist/html/dom.js.map +1 -1
- package/dist/html/fonts.d.ts +106 -0
- package/dist/html/fonts.d.ts.map +1 -0
- package/dist/html/fonts.js +565 -0
- package/dist/html/fonts.js.map +1 -0
- package/dist/html/gif.d.ts +15 -0
- package/dist/html/gif.d.ts.map +1 -0
- package/dist/html/gif.js +229 -0
- package/dist/html/gif.js.map +1 -0
- package/dist/html/index.d.ts +50 -11
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +115 -9
- package/dist/html/index.js.map +1 -1
- package/dist/html/layout/block.d.ts +226 -3
- package/dist/html/layout/block.d.ts.map +1 -1
- package/dist/html/layout/block.js +3077 -219
- package/dist/html/layout/block.js.map +1 -1
- package/dist/html/layout/boxes.d.ts +367 -17
- package/dist/html/layout/boxes.d.ts.map +1 -1
- package/dist/html/layout/boxes.js +1742 -182
- package/dist/html/layout/boxes.js.map +1 -1
- package/dist/html/layout/cache.d.ts +58 -0
- package/dist/html/layout/cache.d.ts.map +1 -0
- package/dist/html/layout/cache.js +224 -0
- package/dist/html/layout/cache.js.map +1 -0
- package/dist/html/layout/collapse.d.ts +45 -0
- package/dist/html/layout/collapse.d.ts.map +1 -0
- package/dist/html/layout/collapse.js +246 -0
- package/dist/html/layout/collapse.js.map +1 -0
- package/dist/html/layout/css-grid.d.ts +7 -0
- package/dist/html/layout/css-grid.d.ts.map +1 -0
- package/dist/html/layout/css-grid.js +900 -0
- package/dist/html/layout/css-grid.js.map +1 -0
- package/dist/html/layout/flex.d.ts.map +1 -1
- package/dist/html/layout/flex.js +1025 -89
- package/dist/html/layout/flex.js.map +1 -1
- package/dist/html/layout/floats.d.ts +45 -6
- package/dist/html/layout/floats.d.ts.map +1 -1
- package/dist/html/layout/floats.js +113 -14
- package/dist/html/layout/floats.js.map +1 -1
- package/dist/html/layout/grid-lines.d.ts +39 -0
- package/dist/html/layout/grid-lines.d.ts.map +1 -0
- package/dist/html/layout/grid-lines.js +119 -0
- package/dist/html/layout/grid-lines.js.map +1 -0
- package/dist/html/layout/grid.d.ts +53 -0
- package/dist/html/layout/grid.d.ts.map +1 -0
- package/dist/html/layout/grid.js +153 -0
- package/dist/html/layout/grid.js.map +1 -0
- package/dist/html/layout/inline.d.ts +154 -1
- package/dist/html/layout/inline.d.ts.map +1 -1
- package/dist/html/layout/inline.js +3598 -175
- package/dist/html/layout/inline.js.map +1 -1
- package/dist/html/layout/shaping.d.ts +6 -0
- package/dist/html/layout/shaping.d.ts.map +1 -0
- package/dist/html/layout/shaping.js +100 -0
- package/dist/html/layout/shaping.js.map +1 -0
- package/dist/html/layout/table.d.ts +3 -0
- package/dist/html/layout/table.d.ts.map +1 -1
- package/dist/html/layout/table.js +681 -175
- package/dist/html/layout/table.js.map +1 -1
- package/dist/html/layout/tracks.d.ts +44 -0
- package/dist/html/layout/tracks.d.ts.map +1 -0
- package/dist/html/layout/tracks.js +349 -0
- package/dist/html/layout/tracks.js.map +1 -0
- package/dist/html/node.d.ts +169 -4
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +1429 -137
- package/dist/html/node.js.map +1 -1
- package/dist/html/paint.d.ts +92 -3
- package/dist/html/paint.d.ts.map +1 -1
- package/dist/html/paint.js +3635 -107
- package/dist/html/paint.js.map +1 -1
- package/dist/html/resources.d.ts +60 -14
- package/dist/html/resources.d.ts.map +1 -1
- package/dist/html/resources.js +122 -36
- package/dist/html/resources.js.map +1 -1
- package/dist/html/surfaces.d.ts +23 -0
- package/dist/html/surfaces.d.ts.map +1 -0
- package/dist/html/surfaces.js +68 -0
- package/dist/html/surfaces.js.map +1 -0
- package/dist/html/svg.d.ts +80 -0
- package/dist/html/svg.d.ts.map +1 -0
- package/dist/html/svg.js +442 -0
- package/dist/html/svg.js.map +1 -0
- package/dist/html/url.d.ts +23 -0
- package/dist/html/url.d.ts.map +1 -0
- package/dist/html/url.js +80 -0
- package/dist/html/url.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/codelines.d.ts +42 -0
- package/dist/internal/codelines.d.ts.map +1 -0
- package/dist/internal/codelines.js +170 -0
- package/dist/internal/codelines.js.map +1 -0
- package/dist/internal/collate.d.ts +3 -0
- package/dist/internal/collate.d.ts.map +1 -0
- package/dist/internal/collate.js +11 -0
- package/dist/internal/collate.js.map +1 -0
- package/dist/internal/markdown/ast.d.ts +11 -0
- package/dist/internal/markdown/ast.d.ts.map +1 -1
- package/dist/internal/markdown/parse.d.ts.map +1 -1
- package/dist/internal/markdown/parse.js +109 -8
- package/dist/internal/markdown/parse.js.map +1 -1
- package/dist/internal/prewarm.d.ts +18 -0
- package/dist/internal/prewarm.d.ts.map +1 -0
- package/dist/internal/prewarm.js +42 -0
- package/dist/internal/prewarm.js.map +1 -0
- package/dist/internal/sdf.d.ts +20 -0
- package/dist/internal/sdf.d.ts.map +1 -0
- package/dist/internal/sdf.js +216 -0
- package/dist/internal/sdf.js.map +1 -0
- package/dist/internal/splice.d.ts +12 -0
- package/dist/internal/splice.d.ts.map +1 -0
- package/dist/internal/splice.js +23 -0
- package/dist/internal/splice.js.map +1 -0
- package/dist/internal/window.d.ts +12 -0
- package/dist/internal/window.d.ts.map +1 -1
- package/dist/internal/window.js +23 -6
- package/dist/internal/window.js.map +1 -1
- package/dist/maps/anchors.d.ts +6 -1
- package/dist/maps/anchors.d.ts.map +1 -1
- package/dist/maps/anchors.js +260 -1
- package/dist/maps/anchors.js.map +1 -1
- package/dist/maps/controller.d.ts +57 -0
- package/dist/maps/controller.d.ts.map +1 -1
- package/dist/maps/controller.js +97 -18
- package/dist/maps/controller.js.map +1 -1
- package/dist/maps/gl/buckets.d.ts +5 -1
- package/dist/maps/gl/buckets.d.ts.map +1 -1
- package/dist/maps/gl/buckets.js +5 -2
- package/dist/maps/gl/buckets.js.map +1 -1
- package/dist/maps/gl/build-worker.d.ts +2 -0
- package/dist/maps/gl/build-worker.d.ts.map +1 -1
- package/dist/maps/gl/build-worker.js +1 -1
- package/dist/maps/gl/build-worker.js.map +1 -1
- package/dist/maps/gl/cover.d.ts +23 -4
- package/dist/maps/gl/cover.d.ts.map +1 -1
- package/dist/maps/gl/cover.js +61 -48
- package/dist/maps/gl/cover.js.map +1 -1
- package/dist/maps/gl/placement.d.ts +21 -8
- package/dist/maps/gl/placement.d.ts.map +1 -1
- package/dist/maps/gl/placement.js +133 -58
- package/dist/maps/gl/placement.js.map +1 -1
- package/dist/maps/gl/renderer.d.ts +36 -4
- package/dist/maps/gl/renderer.d.ts.map +1 -1
- package/dist/maps/gl/renderer.js +81 -24
- package/dist/maps/gl/renderer.js.map +1 -1
- package/dist/maps/gl/shaders.d.ts +18 -17
- package/dist/maps/gl/shaders.d.ts.map +1 -1
- package/dist/maps/gl/shaders.js +34 -32
- package/dist/maps/gl/shaders.js.map +1 -1
- package/dist/maps/gl/store.d.ts +10 -0
- package/dist/maps/gl/store.d.ts.map +1 -1
- package/dist/maps/gl/store.js +47 -4
- package/dist/maps/gl/store.js.map +1 -1
- package/dist/maps/gl/text.d.ts +153 -24
- package/dist/maps/gl/text.d.ts.map +1 -1
- package/dist/maps/gl/text.js +379 -63
- package/dist/maps/gl/text.js.map +1 -1
- package/dist/maps/gl/view.d.ts +293 -2
- package/dist/maps/gl/view.d.ts.map +1 -1
- package/dist/maps/gl/view.js +317 -82
- package/dist/maps/gl/view.js.map +1 -1
- package/dist/maps/icons.d.ts +32 -0
- package/dist/maps/icons.d.ts.map +1 -0
- package/dist/maps/icons.js +151 -0
- package/dist/maps/icons.js.map +1 -0
- package/dist/maps/index.d.ts +2 -0
- package/dist/maps/index.d.ts.map +1 -1
- package/dist/maps/index.js +2 -0
- package/dist/maps/index.js.map +1 -1
- package/dist/maps/labels.d.ts +56 -4
- package/dist/maps/labels.d.ts.map +1 -1
- package/dist/maps/labels.js +213 -46
- package/dist/maps/labels.js.map +1 -1
- package/dist/maps/node.d.ts +17 -0
- package/dist/maps/node.d.ts.map +1 -1
- package/dist/maps/node.js +64 -30
- package/dist/maps/node.js.map +1 -1
- package/dist/maps/proj.d.ts +48 -0
- package/dist/maps/proj.d.ts.map +1 -1
- package/dist/maps/proj.js +73 -0
- package/dist/maps/proj.js.map +1 -1
- package/dist/maps/sources.d.ts +5 -3
- package/dist/maps/sources.d.ts.map +1 -1
- package/dist/maps/sources.js +5 -3
- package/dist/maps/sources.js.map +1 -1
- package/dist/maps/style.d.ts +35 -0
- package/dist/maps/style.d.ts.map +1 -1
- package/dist/maps/style.js.map +1 -1
- package/dist/maps/styles.d.ts +12 -0
- package/dist/maps/styles.d.ts.map +1 -1
- package/dist/maps/styles.js +120 -6
- package/dist/maps/styles.js.map +1 -1
- package/dist/maps/tiles.d.ts +31 -11
- package/dist/maps/tiles.d.ts.map +1 -1
- package/dist/maps/tiles.js +61 -27
- package/dist/maps/tiles.js.map +1 -1
- package/dist/maps/types.d.ts +28 -4
- package/dist/maps/types.d.ts.map +1 -1
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +209 -68
- package/dist/markdown/index.js.map +1 -1
- package/dist/markdown/spans.d.ts.map +1 -1
- package/dist/markdown/spans.js +6 -0
- package/dist/markdown/spans.js.map +1 -1
- package/dist/qml/containers.d.ts.map +1 -1
- package/dist/qml/containers.js +6 -1
- package/dist/qml/containers.js.map +1 -1
- package/dist/qml/interaction.d.ts.map +1 -1
- package/dist/qml/interaction.js +38 -5
- package/dist/qml/interaction.js.map +1 -1
- package/dist/qml/layouts.d.ts.map +1 -1
- package/dist/qml/layouts.js +21 -6
- package/dist/qml/layouts.js.map +1 -1
- package/dist/qml/qtquick.d.ts.map +1 -1
- package/dist/qml/qtquick.js +9 -2
- package/dist/qml/qtquick.js.map +1 -1
- package/dist/qml/react.d.ts.map +1 -1
- package/dist/qml/react.js +9 -7
- package/dist/qml/react.js.map +1 -1
- package/dist/reorder/clock.d.ts +7 -0
- package/dist/reorder/clock.d.ts.map +1 -0
- package/dist/reorder/clock.js +26 -0
- package/dist/reorder/clock.js.map +1 -0
- package/dist/reorder/index.d.ts +25 -3
- package/dist/reorder/index.d.ts.map +1 -1
- package/dist/reorder/index.js +64 -19
- package/dist/reorder/index.js.map +1 -1
- package/dist/rich-text-editor/index.d.ts +0 -11
- package/dist/rich-text-editor/index.d.ts.map +1 -1
- package/dist/rich-text-editor/index.js +38 -9
- package/dist/rich-text-editor/index.js.map +1 -1
- package/dist/rich-text-editor/keymap.d.ts.map +1 -1
- package/dist/rich-text-editor/keymap.js +2 -1
- package/dist/rich-text-editor/keymap.js.map +1 -1
- package/dist/rich-text-editor/keys.d.ts +17 -6
- package/dist/rich-text-editor/keys.d.ts.map +1 -1
- package/dist/rich-text-editor/keys.js +135 -26
- package/dist/rich-text-editor/keys.js.map +1 -1
- package/dist/rich-text-editor/markdown.d.ts.map +1 -1
- package/dist/rich-text-editor/markdown.js +30 -1
- package/dist/rich-text-editor/markdown.js.map +1 -1
- package/dist/rich-text-editor/marks.d.ts +9 -0
- package/dist/rich-text-editor/marks.d.ts.map +1 -0
- package/dist/rich-text-editor/marks.js +83 -0
- package/dist/rich-text-editor/marks.js.map +1 -0
- package/dist/rich-text-editor/render.d.ts.map +1 -1
- package/dist/rich-text-editor/render.js +28 -10
- package/dist/rich-text-editor/render.js.map +1 -1
- package/dist/rich-text-editor/replace.d.ts +13 -0
- package/dist/rich-text-editor/replace.d.ts.map +1 -0
- package/dist/rich-text-editor/replace.js +64 -0
- package/dist/rich-text-editor/replace.js.map +1 -0
- package/dist/rich-text-editor/toolbar.d.ts.map +1 -1
- package/dist/rich-text-editor/toolbar.js +1 -1
- package/dist/rich-text-editor/toolbar.js.map +1 -1
- package/dist/rich-text-editor/virtual.d.ts.map +1 -1
- package/dist/rich-text-editor/virtual.js +17 -0
- package/dist/rich-text-editor/virtual.js.map +1 -1
- package/dist/richtext/node.d.ts +46 -2
- package/dist/richtext/node.d.ts.map +1 -1
- package/dist/richtext/node.js +187 -4
- package/dist/richtext/node.js.map +1 -1
- package/dist/richtext/runs.d.ts +13 -8
- package/dist/richtext/runs.d.ts.map +1 -1
- package/dist/richtext/runs.js +18 -8
- package/dist/richtext/runs.js.map +1 -1
- package/dist/table/index.d.ts.map +1 -1
- package/dist/table/index.js +23 -0
- package/dist/table/index.js.map +1 -1
- package/dist/table/rows.d.ts +3 -2
- package/dist/table/rows.d.ts.map +1 -1
- package/dist/table/rows.js +20 -6
- package/dist/table/rows.js.map +1 -1
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +4 -0
- package/dist/terminal/index.js.map +1 -1
- package/dist/terminal/vt/pty.d.ts +13 -2
- package/dist/terminal/vt/pty.d.ts.map +1 -1
- package/dist/terminal/vt/pty.js +18 -3
- package/dist/terminal/vt/pty.js.map +1 -1
- package/dist/terminal-output/index.d.ts.map +1 -1
- package/dist/terminal-output/index.js +103 -23
- package/dist/terminal-output/index.js.map +1 -1
- package/dist/terminal-output/runs.d.ts +4 -1
- package/dist/terminal-output/runs.d.ts.map +1 -1
- package/dist/terminal-output/runs.js +5 -1
- package/dist/terminal-output/runs.js.map +1 -1
- package/dist/three/canvas.d.ts.map +1 -1
- package/dist/three/canvas.js +85 -7
- package/dist/three/canvas.js.map +1 -1
- package/dist/three/events.d.ts +22 -4
- package/dist/three/events.d.ts.map +1 -1
- package/dist/three/events.js +34 -4
- package/dist/three/events.js.map +1 -1
- package/dist/tree/index.d.ts.map +1 -1
- package/dist/tree/index.js +17 -0
- package/dist/tree/index.js.map +1 -1
- package/package.json +42 -33
- package/src/charts/node.ts +62 -26
- package/src/charts/render.ts +120 -30
- package/src/code/index.ts +36 -32
- package/src/code-editor/completion.ts +3 -2
- package/src/code-editor/index.ts +19 -0
- package/src/code-editor/node.ts +1574 -184
- package/src/code-language/index.ts +1 -1
- package/src/code-language/languages/glsl.ts +12 -2
- package/src/code-language/languages/javascript.ts +21 -4
- package/src/code-language/languages/json.ts +12 -2
- package/src/code-language/languages/shell.ts +12 -2
- package/src/code-language/languages/sql.ts +22 -2
- package/src/code-language/runs.ts +111 -1
- package/src/code-language/stream.ts +257 -17
- package/src/code-language/types.ts +5 -4
- package/src/codeblock/index.ts +68 -4
- package/src/flow/draw.ts +167 -41
- package/src/flow/gl/color.ts +85 -0
- package/src/flow/gl/index.ts +342 -0
- package/src/flow/gl/pack.ts +585 -0
- package/src/flow/gl/renderer.ts +679 -0
- package/src/flow/gl/shaders.ts +371 -0
- package/src/flow/gl/text.ts +1295 -0
- package/src/flow/index.ts +794 -67
- package/src/flow/node.ts +2496 -1256
- package/src/flow/paint.ts +511 -0
- package/src/flow/paths.ts +80 -15
- package/src/flow/scene.ts +2199 -0
- package/src/flow/types.ts +113 -1
- package/src/html/controls.ts +73 -2
- package/src/html/css/calc.ts +385 -0
- package/src/html/css/cascade.ts +1481 -62
- package/src/html/css/color.ts +755 -0
- package/src/html/css/content.ts +417 -0
- package/src/html/css/counter-styles.ts +973 -0
- package/src/html/css/decode.ts +130 -0
- package/src/html/css/parse.ts +1514 -160
- package/src/html/css/style.ts +4131 -223
- package/src/html/css/ua.ts +66 -17
- package/src/html/css/values.ts +150 -50
- package/src/html/css/vars.ts +348 -0
- package/src/html/dom.ts +284 -17
- package/src/html/fonts.ts +641 -0
- package/src/html/gif.ts +233 -0
- package/src/html/index.ts +180 -20
- package/src/html/layout/block.ts +3560 -208
- package/src/html/layout/boxes.ts +2141 -190
- package/src/html/layout/cache.ts +289 -0
- package/src/html/layout/collapse.ts +317 -0
- package/src/html/layout/css-grid.ts +1063 -0
- package/src/html/layout/flex.ts +1115 -106
- package/src/html/layout/floats.ts +128 -14
- package/src/html/layout/grid-lines.ts +141 -0
- package/src/html/layout/grid.ts +181 -0
- package/src/html/layout/inline.ts +4187 -192
- package/src/html/layout/shaping.ts +140 -0
- package/src/html/layout/table.ts +696 -186
- package/src/html/layout/tracks.ts +437 -0
- package/src/html/node.ts +1585 -156
- package/src/html/paint.ts +4582 -267
- package/src/html/resources.ts +161 -50
- package/src/html/surfaces.ts +81 -0
- package/src/html/svg.ts +504 -0
- package/src/html/url.ts +86 -0
- package/src/index.ts +2 -0
- package/src/internal/codelines.ts +200 -0
- package/src/internal/collate.ts +12 -0
- package/src/internal/markdown/ast.ts +11 -0
- package/src/internal/markdown/parse.ts +154 -11
- package/src/internal/prewarm.ts +45 -0
- package/src/internal/sdf.ts +227 -0
- package/src/internal/splice.ts +25 -0
- package/src/internal/window.ts +36 -5
- package/src/maps/anchors.ts +307 -1
- package/src/maps/controller.ts +116 -31
- package/src/maps/gl/buckets.ts +5 -1
- package/src/maps/gl/build-worker.ts +13 -2
- package/src/maps/gl/cover.ts +79 -44
- package/src/maps/gl/placement.ts +221 -69
- package/src/maps/gl/renderer.ts +104 -20
- package/src/maps/gl/shaders.ts +35 -32
- package/src/maps/gl/store.ts +66 -17
- package/src/maps/gl/text.ts +444 -71
- package/src/maps/gl/view.ts +361 -96
- package/src/maps/icons.ts +183 -0
- package/src/maps/index.ts +4 -0
- package/src/maps/labels.ts +269 -49
- package/src/maps/node.ts +82 -49
- package/src/maps/proj.ts +87 -0
- package/src/maps/sources.ts +5 -3
- package/src/maps/style.ts +32 -0
- package/src/maps/styles.ts +215 -4
- package/src/maps/tiles.ts +64 -31
- package/src/maps/types.ts +28 -4
- package/src/markdown/index.ts +293 -92
- package/src/markdown/spans.ts +5 -0
- package/src/qml/containers.tsx +6 -1
- package/src/qml/interaction.tsx +42 -5
- package/src/qml/layouts.tsx +21 -6
- package/src/qml/qtquick.tsx +9 -2
- package/src/qml/react.tsx +7 -5
- package/src/reorder/clock.ts +27 -0
- package/src/reorder/index.ts +100 -27
- package/src/rich-text-editor/index.ts +37 -12
- package/src/rich-text-editor/keymap.ts +1 -1
- package/src/rich-text-editor/keys.ts +135 -26
- package/src/rich-text-editor/markdown.ts +36 -1
- package/src/rich-text-editor/marks.ts +101 -0
- package/src/rich-text-editor/render.ts +49 -12
- package/src/rich-text-editor/replace.ts +85 -0
- package/src/rich-text-editor/toolbar.ts +1 -1
- package/src/rich-text-editor/virtual.ts +25 -0
- package/src/richtext/node.ts +235 -14
- package/src/richtext/runs.ts +23 -12
- package/src/table/index.ts +29 -0
- package/src/table/rows.ts +18 -8
- package/src/terminal/index.ts +4 -0
- package/src/terminal/vt/pty.ts +16 -2
- package/src/terminal-output/index.ts +129 -31
- package/src/terminal-output/runs.ts +16 -2
- package/src/three/canvas.ts +102 -8
- package/src/three/events.ts +49 -9
- package/src/tree/index.ts +19 -0
|
@@ -0,0 +1,2199 @@
|
|
|
1
|
+
// The scene: everything a frame draws, as data.
|
|
2
|
+
//
|
|
3
|
+
// `./node.ts` used to hold both halves of drawing — deciding *what* a frame
|
|
4
|
+
// shows and issuing the 2D calls that show it — in one pass of interleaved
|
|
5
|
+
// private methods. This module is the first half, lifted out and made pure,
|
|
6
|
+
// and `./paint.ts` is the second.
|
|
7
|
+
//
|
|
8
|
+
// Three things wanted the split, in the order they mattered:
|
|
9
|
+
//
|
|
10
|
+
// - **A second renderer.** A `<glarea>` draws from instance buffers, not
|
|
11
|
+
// from a `FlowPainter`, but it draws the *same scene*: the same cards in
|
|
12
|
+
// the same order, the same routed edges, the same culling. A description
|
|
13
|
+
// that names no drawing API is what both can read
|
|
14
|
+
// (`docs/prd-flow-gl.md`).
|
|
15
|
+
// - **Measuring.** A frame's cost could not be told apart from a window's:
|
|
16
|
+
// building the scene needs no server, no surface and no display, so
|
|
17
|
+
// `scripts/bench/flow.ts` can price it on its own.
|
|
18
|
+
// - **Reading it.** What the pane draws is now a value you can print.
|
|
19
|
+
//
|
|
20
|
+
// Everything here is in **screen space** — logical pixels relative to the
|
|
21
|
+
// window, the unit `FlowPainter` takes — because that is where culling has
|
|
22
|
+
// to happen and where a routed edge's sample density is decided. The
|
|
23
|
+
// exception is {@link SceneNodeSource.rect}, which is graph space: it is
|
|
24
|
+
// what the handle anchors and the minimap are computed from.
|
|
25
|
+
//
|
|
26
|
+
// Purity is the point, so the live state a gesture holds does not reach in
|
|
27
|
+
// here: the element resolves it into {@link SceneNodeSource} once per paint
|
|
28
|
+
// — a drag's position already applied, a resize's box already substituted —
|
|
29
|
+
// and this module reads that. The one callback left is text measurement,
|
|
30
|
+
// which needs the app's font cache and cannot be a constant.
|
|
31
|
+
import { tint } from 'react-x11/style';
|
|
32
|
+
|
|
33
|
+
import { snapToGrid } from './draw.js';
|
|
34
|
+
import {
|
|
35
|
+
DEFAULT_MARKER_SIZE,
|
|
36
|
+
EDGE_SLOP,
|
|
37
|
+
EDGE_STEP_OFFSET,
|
|
38
|
+
gripPoint,
|
|
39
|
+
handleAnchor,
|
|
40
|
+
inflateRect,
|
|
41
|
+
NODE_DESC_SIZE,
|
|
42
|
+
NODE_LABEL_SIZE,
|
|
43
|
+
NODE_PAD_X,
|
|
44
|
+
NODE_PAD_Y,
|
|
45
|
+
normalizeMarker,
|
|
46
|
+
rectsOverlap,
|
|
47
|
+
RESIZE_GRIP,
|
|
48
|
+
unionRects,
|
|
49
|
+
} from './model.js';
|
|
50
|
+
import {
|
|
51
|
+
edgePath,
|
|
52
|
+
endAngle,
|
|
53
|
+
pathBounds,
|
|
54
|
+
pointAtFraction,
|
|
55
|
+
startAngle,
|
|
56
|
+
trimEnd,
|
|
57
|
+
} from './paths.js';
|
|
58
|
+
import type {
|
|
59
|
+
BackgroundVariant,
|
|
60
|
+
EdgeMarker,
|
|
61
|
+
EdgeType,
|
|
62
|
+
FlowEdge,
|
|
63
|
+
FlowNode,
|
|
64
|
+
FlowNodeData,
|
|
65
|
+
FlowNodeType,
|
|
66
|
+
FlowPalette,
|
|
67
|
+
FlowRect,
|
|
68
|
+
HandleAnchor,
|
|
69
|
+
HandleSpec,
|
|
70
|
+
MarkerType,
|
|
71
|
+
TextOptions,
|
|
72
|
+
Viewport,
|
|
73
|
+
XYPosition,
|
|
74
|
+
} from './types.js';
|
|
75
|
+
|
|
76
|
+
type AnyNode = FlowNode<unknown>;
|
|
77
|
+
type AnyEdge = FlowEdge<unknown>;
|
|
78
|
+
type AnyType = FlowNodeType<unknown>;
|
|
79
|
+
|
|
80
|
+
/** Below these zooms the pane stops drawing detail nobody could read — the
|
|
81
|
+
* cheapest optimisation there is, and the one that keeps a zoomed-out
|
|
82
|
+
* overview interactive. Exported because the element's hit testing has to
|
|
83
|
+
* agree with what was drawn. */
|
|
84
|
+
export const LABEL_ZOOM = 0.45;
|
|
85
|
+
export const HANDLE_ZOOM = 0.5;
|
|
86
|
+
export const DESC_ZOOM = 0.6;
|
|
87
|
+
|
|
88
|
+
/** The grid never draws denser than this on screen, whatever the zoom. */
|
|
89
|
+
export const MIN_GRID_PX = 16;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* How far outside its own box a node's ink can land: handles (capped at
|
|
93
|
+
* 6 × 1.4 plus their outline), resize grips, the selection border, a pixel
|
|
94
|
+
* of antialiasing. Damage rects grow by this before they are invalidated,
|
|
95
|
+
* and cull tests grow their target by the same amount — the two must agree,
|
|
96
|
+
* or a moved node leaves crumbs of its old handles behind.
|
|
97
|
+
*/
|
|
98
|
+
export const CULL_MARGIN = 16;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* From this many edges on the pane, they are stroked a pen at a time — every
|
|
102
|
+
* run of a pen, and every arrowhead of a colour, as one path — and below
|
|
103
|
+
* it an edge at a time, in the graph's order.
|
|
104
|
+
*
|
|
105
|
+
* A path's mask is its bounding box, so a pen's scattered runs as one path
|
|
106
|
+
* cost a mask the size of the pane where each alone costs its own small
|
|
107
|
+
* one: nineteen long edges criss-crossing a pane measured 634 KB a repaint
|
|
108
|
+
* batched against 97 KB one at a time, and seven hundred measured 3.9 MB
|
|
109
|
+
* one at a time against 1.3 MB batched. And the two do not draw the same
|
|
110
|
+
* pixels where edges overlap: coverage adds inside one path and lays one
|
|
111
|
+
* over the other between two, so a fan-out's shared leg came out as much
|
|
112
|
+
* as 35 levels apart at its edges. So the choice is the pane's, never a
|
|
113
|
+
* pass's — decided from the edges on the pane and kept across the passes
|
|
114
|
+
* of every frame until a repaint of the whole pane takes the other one
|
|
115
|
+
* ({@link SceneInput.batch}).
|
|
116
|
+
*/
|
|
117
|
+
export const EDGE_BATCH = 24;
|
|
118
|
+
/** …and below this many a batched pane goes back, so that a pan across the
|
|
119
|
+
* threshold does not change the way every step. */
|
|
120
|
+
const EDGE_UNBATCH = 16;
|
|
121
|
+
|
|
122
|
+
/** Whether `onPane` edges are stroked a pen at a time, given whether they
|
|
123
|
+
* were (`EDGE_BATCH`). */
|
|
124
|
+
export function batchesEdges(onPane: number, was = false): boolean {
|
|
125
|
+
return onPane >= (was ? EDGE_UNBATCH : EDGE_BATCH);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const DEFAULT_DASH = [7, 5];
|
|
129
|
+
|
|
130
|
+
// --- the cache ----------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* One edge's route, kept between frames.
|
|
134
|
+
*
|
|
135
|
+
* The saved work is everything above the arithmetic: resolving which handle
|
|
136
|
+
* each end uses (which allocates an anchor per spec), evaluating the curve
|
|
137
|
+
* (up to 48 points), and dropping the vertices that crowd each other.
|
|
138
|
+
*
|
|
139
|
+
* What makes it reusable is a property of the routing rather than of the
|
|
140
|
+
* cache: **every edge type is translation-equivariant and none is
|
|
141
|
+
* scale-equivariant.** Move both endpoints by the same vector and the whole
|
|
142
|
+
* route moves with them, because every route is built from distances
|
|
143
|
+
* between the two ends; change the zoom and it does not, because a bezier's
|
|
144
|
+
* shoulder, a step's offset, a fillet's radius and a loop's reach are all
|
|
145
|
+
* clamped against pixel constants that do not scale. So the route is stored
|
|
146
|
+
* in screen space next to the viewport origin it was built at, and a pan —
|
|
147
|
+
* which keeps the zoom and moves the origin — is an addition per vertex
|
|
148
|
+
* into an array that already exists. A zoom rebuilds.
|
|
149
|
+
*
|
|
150
|
+
* The screen arrays are **reused and mutated in place**, which is where the
|
|
151
|
+
* allocation goes: a frame of 2000 edges was spending a sixth of itself in
|
|
152
|
+
* the collector. A scene is built and drawn inside one paint and nothing
|
|
153
|
+
* retains it, so the only rule is the one stated on {@link buildScene} —
|
|
154
|
+
* do not hold a scene past the frame that made it.
|
|
155
|
+
*/
|
|
156
|
+
interface CachedRoute {
|
|
157
|
+
// what it was built from
|
|
158
|
+
zoom: number;
|
|
159
|
+
originX: number;
|
|
160
|
+
originY: number;
|
|
161
|
+
sx: number;
|
|
162
|
+
sy: number;
|
|
163
|
+
sw: number;
|
|
164
|
+
sh: number;
|
|
165
|
+
tx: number;
|
|
166
|
+
ty: number;
|
|
167
|
+
tw: number;
|
|
168
|
+
th: number;
|
|
169
|
+
sourceSpecs: readonly HandleSpec[];
|
|
170
|
+
targetSpecs: readonly HandleSpec[];
|
|
171
|
+
sourceHandle: string | null;
|
|
172
|
+
targetHandle: string | null;
|
|
173
|
+
/** The node ids too: an id can be reused for a different pair between
|
|
174
|
+
* commits, and the rects alone would not notice two nodes that happen to
|
|
175
|
+
* sit in the same place. */
|
|
176
|
+
source: string;
|
|
177
|
+
target: string;
|
|
178
|
+
type: EdgeType | undefined;
|
|
179
|
+
loop: boolean;
|
|
180
|
+
/** The arrowheads' shapes and sizes, which decide where the stroke stops
|
|
181
|
+
* and what the heads look like. Their *colours* are not here: those
|
|
182
|
+
* change with selection and hover and move no geometry. */
|
|
183
|
+
markerKey: string;
|
|
184
|
+
// what came out, in screen space at `originX`/`originY`
|
|
185
|
+
points: XYPosition[];
|
|
186
|
+
/** The stroke's own points, stopped behind the arrowhead — null when
|
|
187
|
+
* there is no head and the stroke is the whole route. Kept apart from
|
|
188
|
+
* `points` because the label sits at the middle of the *whole* route. */
|
|
189
|
+
trimmed: XYPosition[] | null;
|
|
190
|
+
endHead: XYPosition[] | null;
|
|
191
|
+
startHead: XYPosition[] | null;
|
|
192
|
+
from: HandleAnchor;
|
|
193
|
+
to: HandleAnchor;
|
|
194
|
+
bounds: FlowRect;
|
|
195
|
+
/** The middle of the whole route, where a label sits: worked out the
|
|
196
|
+
* first time a label asks (`middleOf`), and moved with the route. */
|
|
197
|
+
middle: XYPosition | null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Bounded, so a graph that churns edge ids cannot turn this into a leak. */
|
|
201
|
+
const ROUTE_LIMIT = 20000;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Move a polyline, in place.
|
|
205
|
+
*
|
|
206
|
+
* Addition in place drifts by float rounding — `(x + a) + b` is not always
|
|
207
|
+
* `x + (a + b)` — so a route panned many times sits a few units in the last
|
|
208
|
+
* place off one routed fresh. That is ~1e-14 px a pan, the painter puts
|
|
209
|
+
* every coordinate on the device grid before it draws, and any zoom or node
|
|
210
|
+
* move rebuilds the route from scratch and resets it. Reading through a
|
|
211
|
+
* per-frame copy instead would be exact and would bring back the allocation
|
|
212
|
+
* this cache exists to remove.
|
|
213
|
+
*/
|
|
214
|
+
function shift(points: XYPosition[], dx: number, dy: number): void {
|
|
215
|
+
for (const p of points) {
|
|
216
|
+
p.x += dx;
|
|
217
|
+
p.y += dy;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* What a renderer keeps between frames. Owned by whoever draws — the
|
|
223
|
+
* element, or a GL renderer — and handed to {@link buildScene}, which reads
|
|
224
|
+
* and fills it. Passing none is correct and simply recomputes everything.
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* One edge routed from scratch, arrowheads and all — the miss path of
|
|
228
|
+
* {@link SceneCache}, and the whole path for a caller that keeps none.
|
|
229
|
+
*/
|
|
230
|
+
function buildRoute(
|
|
231
|
+
v: Viewport,
|
|
232
|
+
edge: AnyEdge,
|
|
233
|
+
from: SceneNodeSource,
|
|
234
|
+
to: SceneNodeSource,
|
|
235
|
+
markerEnd: EdgeMarker | null,
|
|
236
|
+
markerStart: EdgeMarker | null,
|
|
237
|
+
into?: CachedRoute,
|
|
238
|
+
): CachedRoute | null {
|
|
239
|
+
const routed = edgeRoute(v, edge, from, to);
|
|
240
|
+
if (!routed) return null;
|
|
241
|
+
const markerKey = markerKeyOf(markerEnd, markerStart);
|
|
242
|
+
const loop = edge.source === edge.target;
|
|
243
|
+
const all = routed.points;
|
|
244
|
+
const { endHead, startHead, endTrim } = routeHeads(
|
|
245
|
+
v,
|
|
246
|
+
all,
|
|
247
|
+
markerEnd,
|
|
248
|
+
markerStart,
|
|
249
|
+
);
|
|
250
|
+
// Copied vertex by vertex, not just sliced. `trimEnd` returns a shallow
|
|
251
|
+
// copy — the same point *objects* as the route, less the last — and a
|
|
252
|
+
// pan moves both arrays in place, so a shared vertex moved twice: the
|
|
253
|
+
// stroke slid away from its own head by the pan's distance. Caught by
|
|
254
|
+
// test/flow-scene.test.ts, which the gesture tests could not have seen.
|
|
255
|
+
const trimmed = endHead
|
|
256
|
+
? trimEnd(all, endTrim).map((p) => ({ x: p.x, y: p.y }))
|
|
257
|
+
: null;
|
|
258
|
+
// Written over the entry this edge already had, where there is one. A
|
|
259
|
+
// zoom misses on every edge of every frame, and allocating a fresh record
|
|
260
|
+
// for each — plus the `Map.set` to file it — cost more than the routing
|
|
261
|
+
// the cache saves: a drag and a zoom both came out ~10% slower than with
|
|
262
|
+
// no cache at all, before this.
|
|
263
|
+
const entry = into ?? ({} as CachedRoute);
|
|
264
|
+
Object.assign(entry, {
|
|
265
|
+
zoom: v.zoom,
|
|
266
|
+
originX: v.x,
|
|
267
|
+
originY: v.y,
|
|
268
|
+
sx: from.rect.x,
|
|
269
|
+
sy: from.rect.y,
|
|
270
|
+
sw: from.rect.width,
|
|
271
|
+
sh: from.rect.height,
|
|
272
|
+
tx: to.rect.x,
|
|
273
|
+
ty: to.rect.y,
|
|
274
|
+
tw: to.rect.width,
|
|
275
|
+
th: to.rect.height,
|
|
276
|
+
sourceSpecs: from.specs,
|
|
277
|
+
targetSpecs: to.specs,
|
|
278
|
+
sourceHandle: edge.sourceHandle ?? null,
|
|
279
|
+
targetHandle: edge.targetHandle ?? null,
|
|
280
|
+
source: edge.source,
|
|
281
|
+
target: edge.target,
|
|
282
|
+
type: edge.type,
|
|
283
|
+
loop,
|
|
284
|
+
markerKey,
|
|
285
|
+
points: all,
|
|
286
|
+
trimmed,
|
|
287
|
+
endHead,
|
|
288
|
+
startHead,
|
|
289
|
+
from: routed.from,
|
|
290
|
+
to: routed.to,
|
|
291
|
+
bounds: withHeads(pathBounds(all), endHead, startHead),
|
|
292
|
+
middle: null,
|
|
293
|
+
});
|
|
294
|
+
return entry;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Where a route's label sits. Walking the route to its middle is the length
|
|
299
|
+
* of every segment twice, and a 2D pan's passes asked it of every labelled
|
|
300
|
+
* edge they reached, every frame; kept, it is two additions a pan. A copy,
|
|
301
|
+
* never one of the route's own points, which the pan moves as well.
|
|
302
|
+
*/
|
|
303
|
+
function middleOf(route: CachedRoute): XYPosition {
|
|
304
|
+
if (route.middle === null) {
|
|
305
|
+
const p = pointAtFraction(route.points, 0.5);
|
|
306
|
+
route.middle = { x: p.x, y: p.y };
|
|
307
|
+
}
|
|
308
|
+
return route.middle;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* An edge's arrowheads on a route, and how much of the route's end the
|
|
313
|
+
* stroke leaves to the one at the end: the one place a head is placed, so
|
|
314
|
+
* what is drawn and what a move claims ({@link edgeInkBox}) cannot disagree.
|
|
315
|
+
*/
|
|
316
|
+
function routeHeads(
|
|
317
|
+
v: Viewport,
|
|
318
|
+
all: readonly XYPosition[],
|
|
319
|
+
markerEnd: EdgeMarker | null,
|
|
320
|
+
markerStart: EdgeMarker | null,
|
|
321
|
+
): {
|
|
322
|
+
endHead: XYPosition[] | null;
|
|
323
|
+
startHead: XYPosition[] | null;
|
|
324
|
+
endTrim: number;
|
|
325
|
+
} {
|
|
326
|
+
// The tip stops short of the handle rather than at it: the handle dot is
|
|
327
|
+
// drawn *over* the edges, with the nodes, so an arrow aimed at the
|
|
328
|
+
// handle's centre is an arrow mostly hidden under a white circle.
|
|
329
|
+
const inset = v.zoom >= HANDLE_ZOOM ? handleRadius(v.zoom) + 1 : 1;
|
|
330
|
+
let endHead: XYPosition[] | null = null;
|
|
331
|
+
let startHead: XYPosition[] | null = null;
|
|
332
|
+
let endTrim = 0;
|
|
333
|
+
if (markerEnd) {
|
|
334
|
+
const size = (markerEnd.size ?? DEFAULT_MARKER_SIZE) * v.zoom;
|
|
335
|
+
const last = all[all.length - 1];
|
|
336
|
+
const angle = endAngle(all);
|
|
337
|
+
// and the stroke stops behind the head, so a filled triangle is a
|
|
338
|
+
// triangle rather than a triangle with a line through it
|
|
339
|
+
endTrim = size * 0.8 + inset;
|
|
340
|
+
endHead = markerPoints(
|
|
341
|
+
{
|
|
342
|
+
x: last.x - Math.cos(angle) * inset,
|
|
343
|
+
y: last.y - Math.sin(angle) * inset,
|
|
344
|
+
},
|
|
345
|
+
angle,
|
|
346
|
+
markerEnd.type,
|
|
347
|
+
size,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (markerStart) {
|
|
351
|
+
const size = (markerStart.size ?? DEFAULT_MARKER_SIZE) * v.zoom;
|
|
352
|
+
const angle = startAngle(all);
|
|
353
|
+
startHead = markerPoints(
|
|
354
|
+
{
|
|
355
|
+
x: all[0].x - Math.cos(angle) * inset,
|
|
356
|
+
y: all[0].y - Math.sin(angle) * inset,
|
|
357
|
+
},
|
|
358
|
+
angle,
|
|
359
|
+
markerStart.type,
|
|
360
|
+
size,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
return { endHead, startHead, endTrim };
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* A route's box with its arrowheads in it. A head lies along the route's
|
|
368
|
+
* last stretch, but as wide as it is long: where the route runs along its
|
|
369
|
+
* box's side, a wing of it is outside the box — by nine pixels at `zoom` 2.
|
|
370
|
+
*/
|
|
371
|
+
function withHeads(
|
|
372
|
+
box: FlowRect,
|
|
373
|
+
endHead: XYPosition[] | null,
|
|
374
|
+
startHead: XYPosition[] | null,
|
|
375
|
+
): FlowRect {
|
|
376
|
+
if (endHead) box = unionRects(box, pathBounds(endHead));
|
|
377
|
+
if (startHead) box = unionRects(box, pathBounds(startHead));
|
|
378
|
+
return box;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** The head an edge ends in. Left out, it is an arrow: a directed graph
|
|
382
|
+
* whose edges do not say which way they point is a set of lines. `null`
|
|
383
|
+
* opts out. */
|
|
384
|
+
function endMarkerOf(edge: AnyEdge): EdgeMarker | null {
|
|
385
|
+
return normalizeMarker(
|
|
386
|
+
edge.markerEnd === undefined ? 'arrowclosed' : edge.markerEnd,
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** An edge's pen, on screen. */
|
|
391
|
+
function edgeLineWidth(edge: AnyEdge, zoom: number): number {
|
|
392
|
+
return Math.max(
|
|
393
|
+
1,
|
|
394
|
+
(edge.style?.strokeWidth ?? (edge.selected ? 2 : 1.5)) * zoom,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** How far ink reaches from a segment, as a cull asks it: the pen and its
|
|
399
|
+
* join — a miter at the sharpest corner a route takes, or at an
|
|
400
|
+
* arrowhead's tip, stays well inside three widths. Loose on purpose: a
|
|
401
|
+
* cull that keeps an edge too many draws it clipped away. */
|
|
402
|
+
function penReach(lineWidth: number): number {
|
|
403
|
+
return lineWidth * 3 + 2;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** How far it reaches in fact, as a claim asks it, where too much is pixels
|
|
407
|
+
* repainted for nothing: an edge and an open head are stroked round-joined
|
|
408
|
+
* and round-capped, so half the pen, and a filled head is not stroked at
|
|
409
|
+
* all — plus the edge pixels and the device grid every point is put on. */
|
|
410
|
+
function inkReach(lineWidth: number): number {
|
|
411
|
+
return lineWidth / 2 + 2;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Everything drawing `edge` along `points` can ink, in the same pixels: the
|
|
416
|
+
* route and its arrowheads, the pen's reach past both, and the label's
|
|
417
|
+
* plate — what a change that moves the edge has to claim. From the heads
|
|
418
|
+
* and the pen {@link buildScene} draws with: a claim that took the route's
|
|
419
|
+
* points alone reached a head's wing only through the margin it was grown
|
|
420
|
+
* by, and a large head, a deep zoom or a wide pen outgrows any margin.
|
|
421
|
+
*
|
|
422
|
+
* `margin` is what the caller grows the box by afterwards, and the pen and
|
|
423
|
+
* the heads count only past it: an ordinary pen and a default arrow stay
|
|
424
|
+
* inside a claim's margin at any zoom a pane allows by default, and adding
|
|
425
|
+
* them again made every move on a small graph claim a fifth more.
|
|
426
|
+
*/
|
|
427
|
+
export function edgeInkBox(
|
|
428
|
+
v: Viewport,
|
|
429
|
+
edge: AnyEdge,
|
|
430
|
+
points: readonly XYPosition[],
|
|
431
|
+
margin = 0,
|
|
432
|
+
): FlowRect {
|
|
433
|
+
const { endHead, startHead } = routeHeads(
|
|
434
|
+
v,
|
|
435
|
+
points,
|
|
436
|
+
endMarkerOf(edge),
|
|
437
|
+
normalizeMarker(edge.markerStart),
|
|
438
|
+
);
|
|
439
|
+
// how far ink reaches past the geometry, less the margin: below zero for
|
|
440
|
+
// any pen short of the margin's width
|
|
441
|
+
const past = inkReach(edgeLineWidth(edge, v.zoom)) - margin;
|
|
442
|
+
let box = withLabelPlate(pathBounds(points), edge, v.zoom);
|
|
443
|
+
if (past > 0) box = inflateRect(box, past);
|
|
444
|
+
if (endHead) box = reachingPast(box, pathBounds(endHead), past);
|
|
445
|
+
if (startHead) box = reachingPast(box, pathBounds(startHead), past);
|
|
446
|
+
return box;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** `box`, grown on each side until it reaches `by` past `part` — or, where
|
|
450
|
+
* `by` is negative, until it comes within that much of it. */
|
|
451
|
+
function reachingPast(box: FlowRect, part: FlowRect, by: number): FlowRect {
|
|
452
|
+
const x = Math.min(box.x, part.x - by);
|
|
453
|
+
const y = Math.min(box.y, part.y - by);
|
|
454
|
+
return {
|
|
455
|
+
x,
|
|
456
|
+
y,
|
|
457
|
+
width: Math.max(box.x + box.width, part.x + part.width + by) - x,
|
|
458
|
+
height: Math.max(box.y + box.height, part.y + part.height + by) - y,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Which arrowheads a route was built for — their shapes and sizes, never
|
|
463
|
+
* their colours, which move nothing. */
|
|
464
|
+
function markerKeyOf(
|
|
465
|
+
markerEnd: EdgeMarker | null,
|
|
466
|
+
markerStart: EdgeMarker | null,
|
|
467
|
+
): string {
|
|
468
|
+
return `${markerEnd?.type ?? ''}:${markerEnd?.size ?? ''}|${
|
|
469
|
+
markerStart?.type ?? ''
|
|
470
|
+
}:${markerStart?.size ?? ''}`;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/** A route with nothing kept between frames. */
|
|
474
|
+
export function uncachedRoute(
|
|
475
|
+
v: Viewport,
|
|
476
|
+
edge: AnyEdge,
|
|
477
|
+
from: SceneNodeSource,
|
|
478
|
+
to: SceneNodeSource,
|
|
479
|
+
markerEnd: EdgeMarker | null,
|
|
480
|
+
markerStart: EdgeMarker | null,
|
|
481
|
+
): CachedRoute | null {
|
|
482
|
+
return buildRoute(v, edge, from, to, markerEnd, markerStart);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** An edge a pass may draw: both ends resolved and its coarse box on
|
|
486
|
+
* screen, which is everything about it no pass's clip changes. */
|
|
487
|
+
interface EdgeCandidate {
|
|
488
|
+
edge: AnyEdge;
|
|
489
|
+
from: SceneNodeSource;
|
|
490
|
+
to: SceneNodeSource;
|
|
491
|
+
coarse: FlowRect;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** A node on screen, with its screen box. */
|
|
495
|
+
interface NodeCandidate {
|
|
496
|
+
source: SceneNodeSource;
|
|
497
|
+
rect: FlowRect;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** What a list of candidates was culled for: the arrays it came from, the
|
|
501
|
+
* viewport and the rect it was culled to. */
|
|
502
|
+
interface CullKey {
|
|
503
|
+
from: readonly unknown[];
|
|
504
|
+
all: readonly SceneNodeSource[] | null;
|
|
505
|
+
vx: number;
|
|
506
|
+
vy: number;
|
|
507
|
+
zoom: number;
|
|
508
|
+
kx: number;
|
|
509
|
+
ky: number;
|
|
510
|
+
kw: number;
|
|
511
|
+
kh: number;
|
|
512
|
+
scale: number;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function sameCull(
|
|
516
|
+
key: CullKey | null,
|
|
517
|
+
from: readonly unknown[],
|
|
518
|
+
all: readonly SceneNodeSource[] | null,
|
|
519
|
+
v: Viewport,
|
|
520
|
+
kept: FlowRect,
|
|
521
|
+
scale: number,
|
|
522
|
+
): boolean {
|
|
523
|
+
return (
|
|
524
|
+
key != null &&
|
|
525
|
+
key.from === from &&
|
|
526
|
+
key.all === all &&
|
|
527
|
+
key.vx === v.x &&
|
|
528
|
+
key.vy === v.y &&
|
|
529
|
+
key.zoom === v.zoom &&
|
|
530
|
+
key.kx === kept.x &&
|
|
531
|
+
key.ky === kept.y &&
|
|
532
|
+
key.kw === kept.width &&
|
|
533
|
+
key.kh === kept.height &&
|
|
534
|
+
key.scale === scale
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* A box an edge's route stays in, grown to hold its label's plate too. The
|
|
540
|
+
* plate is centred on the route's middle and as wide as its text, which can
|
|
541
|
+
* be far wider than the route: a long name on a short edge put a plate on
|
|
542
|
+
* the pane whose edge was culled for being off it, and a node that moved
|
|
543
|
+
* such an edge claimed its route and left the plate's ends behind. Every
|
|
544
|
+
* cull and every claim asks this of every labelled edge, so the plate is
|
|
545
|
+
* bounded rather than measured — an em and a quarter a code unit, wider
|
|
546
|
+
* than any label is set — and grows nothing where no labels are drawn.
|
|
547
|
+
*/
|
|
548
|
+
export function withLabelPlate(
|
|
549
|
+
box: FlowRect,
|
|
550
|
+
edge: AnyEdge,
|
|
551
|
+
zoom: number,
|
|
552
|
+
): FlowRect {
|
|
553
|
+
if (!edge.label || zoom < LABEL_ZOOM) return box;
|
|
554
|
+
const size = Math.max(8, 11 * zoom);
|
|
555
|
+
const dx = (edge.label.length * size * 1.25) / 2 + 5 * zoom + 1;
|
|
556
|
+
const dy = size + 2 * zoom + 1;
|
|
557
|
+
return {
|
|
558
|
+
x: box.x - dx,
|
|
559
|
+
y: box.y - dy,
|
|
560
|
+
width: box.width + dx * 2,
|
|
561
|
+
height: box.height + dy * 2,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function cullEdges(
|
|
566
|
+
v: Viewport,
|
|
567
|
+
kept: FlowRect,
|
|
568
|
+
edges: readonly AnyEdge[],
|
|
569
|
+
byId: ReadonlyMap<string, SceneNodeSource>,
|
|
570
|
+
scale: number,
|
|
571
|
+
): EdgeCandidate[] {
|
|
572
|
+
const list: EdgeCandidate[] = [];
|
|
573
|
+
for (const edge of edges) {
|
|
574
|
+
if (edge.hidden) continue;
|
|
575
|
+
const from = byId.get(edge.source);
|
|
576
|
+
const to = byId.get(edge.target);
|
|
577
|
+
if (!from || !to || from.node.hidden || to.node.hidden) continue;
|
|
578
|
+
const coarse = withLabelPlate(
|
|
579
|
+
edgeCoarseBox(v, from, to, scale),
|
|
580
|
+
edge,
|
|
581
|
+
v.zoom,
|
|
582
|
+
);
|
|
583
|
+
if (rectsOverlap(coarse, kept)) list.push({ edge, from, to, coarse });
|
|
584
|
+
}
|
|
585
|
+
return list;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function cullNodes(
|
|
589
|
+
v: Viewport,
|
|
590
|
+
kept: FlowRect,
|
|
591
|
+
nodes: readonly SceneNodeSource[],
|
|
592
|
+
scale: number,
|
|
593
|
+
): NodeCandidate[] {
|
|
594
|
+
const list: NodeCandidate[] = [];
|
|
595
|
+
for (const source of nodes) {
|
|
596
|
+
if (source.node.hidden) continue;
|
|
597
|
+
const rect = screenRect(v, source.rect, scale);
|
|
598
|
+
// By what the node inks, not by its card: a handle sits on the card's
|
|
599
|
+
// edge and reaches past it, and a node whose card had just left the
|
|
600
|
+
// pane lost the half ring still inside it. The margin every claim and
|
|
601
|
+
// the damage test below grow a node by.
|
|
602
|
+
if (rectsOverlap(inflateRect(rect, CULL_MARGIN), kept)) {
|
|
603
|
+
list.push({ source, rect });
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return list;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function cullKey(
|
|
610
|
+
from: readonly unknown[],
|
|
611
|
+
all: readonly SceneNodeSource[] | null,
|
|
612
|
+
v: Viewport,
|
|
613
|
+
kept: FlowRect,
|
|
614
|
+
scale: number,
|
|
615
|
+
): CullKey {
|
|
616
|
+
return {
|
|
617
|
+
from,
|
|
618
|
+
all,
|
|
619
|
+
vx: v.x,
|
|
620
|
+
vy: v.y,
|
|
621
|
+
zoom: v.zoom,
|
|
622
|
+
kx: kept.x,
|
|
623
|
+
ky: kept.y,
|
|
624
|
+
kw: kept.width,
|
|
625
|
+
kh: kept.height,
|
|
626
|
+
scale,
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
export class SceneCache {
|
|
631
|
+
private readonly routes = new Map<string, CachedRoute>();
|
|
632
|
+
/** The node index, memoized on the array it was built from: at two
|
|
633
|
+
* thousand nodes, rebuilding this Map every frame was a tenth of the
|
|
634
|
+
* build. */
|
|
635
|
+
private index: Map<string, SceneNodeSource> | null = null;
|
|
636
|
+
private indexFor: readonly SceneNodeSource[] | null = null;
|
|
637
|
+
/** The edges and nodes on screen, for the passes of one frame. */
|
|
638
|
+
private edgeCull: { key: CullKey; list: EdgeCandidate[] } | null = null;
|
|
639
|
+
private nodeCull: { key: CullKey; list: NodeCandidate[] } | null = null;
|
|
640
|
+
|
|
641
|
+
/** Everything is derived, so forgetting it is always safe. */
|
|
642
|
+
clear(): void {
|
|
643
|
+
this.routes.clear();
|
|
644
|
+
this.index = null;
|
|
645
|
+
this.indexFor = null;
|
|
646
|
+
this.edgeCull = null;
|
|
647
|
+
this.nodeCull = null;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* The edges whose coarse box reaches `kept`, with their ends — the list a
|
|
652
|
+
* pass walks, culled once for every pass of a frame. A 2D frame paints its
|
|
653
|
+
* damage as several passes, a pan's strips and corners and furniture, and
|
|
654
|
+
* each one walked every edge in the graph to throw nearly all of them
|
|
655
|
+
* away: at four thousand edges that was most of what a pan frame cost
|
|
656
|
+
* once the drawing had become a copy. Keyed on the arrays themselves, so
|
|
657
|
+
* the element has to hand the same ones to every pass of a frame.
|
|
658
|
+
*/
|
|
659
|
+
edgesOnScreen(
|
|
660
|
+
v: Viewport,
|
|
661
|
+
kept: FlowRect,
|
|
662
|
+
edges: readonly AnyEdge[],
|
|
663
|
+
all: readonly SceneNodeSource[],
|
|
664
|
+
scale: number,
|
|
665
|
+
): EdgeCandidate[] {
|
|
666
|
+
const hit = this.edgeCull;
|
|
667
|
+
if (hit && sameCull(hit.key, edges, all, v, kept, scale)) return hit.list;
|
|
668
|
+
const list = cullEdges(v, kept, edges, this.byId(all), scale);
|
|
669
|
+
this.edgeCull = { key: cullKey(edges, all, v, kept, scale), list };
|
|
670
|
+
return list;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** The nodes whose screen box reaches `kept`, culled once for every pass
|
|
674
|
+
* of a frame the way `edgesOnScreen` culls the edges. */
|
|
675
|
+
nodesOnScreen(
|
|
676
|
+
v: Viewport,
|
|
677
|
+
kept: FlowRect,
|
|
678
|
+
nodes: readonly SceneNodeSource[],
|
|
679
|
+
scale: number,
|
|
680
|
+
): NodeCandidate[] {
|
|
681
|
+
const hit = this.nodeCull;
|
|
682
|
+
if (hit && sameCull(hit.key, nodes, null, v, kept, scale)) return hit.list;
|
|
683
|
+
const list = cullNodes(v, kept, nodes, scale);
|
|
684
|
+
this.nodeCull = { key: cullKey(nodes, null, v, kept, scale), list };
|
|
685
|
+
return list;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
byId(all: readonly SceneNodeSource[]): Map<string, SceneNodeSource> {
|
|
689
|
+
if (this.indexFor === all && this.index) return this.index;
|
|
690
|
+
const map = new Map<string, SceneNodeSource>();
|
|
691
|
+
for (const source of all) map.set(source.node.id, source);
|
|
692
|
+
this.index = map;
|
|
693
|
+
this.indexFor = all;
|
|
694
|
+
return map;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* The route for `edge` at `v`, from the cache where it still holds. With
|
|
699
|
+
* `within`, a cached route whose box, carried to `v`, misses that rect is
|
|
700
|
+
* left where it is and null comes back: the pass has nothing of it to
|
|
701
|
+
* draw, and the pan it was not moved by is added to the next one that
|
|
702
|
+
* reaches it.
|
|
703
|
+
*/
|
|
704
|
+
route(
|
|
705
|
+
v: Viewport,
|
|
706
|
+
edge: AnyEdge,
|
|
707
|
+
from: SceneNodeSource,
|
|
708
|
+
to: SceneNodeSource,
|
|
709
|
+
markerEnd: EdgeMarker | null,
|
|
710
|
+
markerStart: EdgeMarker | null,
|
|
711
|
+
within: FlowRect | null = null,
|
|
712
|
+
): CachedRoute | null {
|
|
713
|
+
const loop = edge.source === edge.target;
|
|
714
|
+
const markerKey = markerKeyOf(markerEnd, markerStart);
|
|
715
|
+
const hit = this.routes.get(edge.id);
|
|
716
|
+
if (
|
|
717
|
+
hit &&
|
|
718
|
+
hit.zoom === v.zoom &&
|
|
719
|
+
hit.sx === from.rect.x &&
|
|
720
|
+
hit.sy === from.rect.y &&
|
|
721
|
+
hit.sw === from.rect.width &&
|
|
722
|
+
hit.sh === from.rect.height &&
|
|
723
|
+
hit.tx === to.rect.x &&
|
|
724
|
+
hit.ty === to.rect.y &&
|
|
725
|
+
hit.tw === to.rect.width &&
|
|
726
|
+
hit.th === to.rect.height &&
|
|
727
|
+
hit.sourceSpecs === from.specs &&
|
|
728
|
+
hit.targetSpecs === to.specs &&
|
|
729
|
+
hit.sourceHandle === (edge.sourceHandle ?? null) &&
|
|
730
|
+
hit.targetHandle === (edge.targetHandle ?? null) &&
|
|
731
|
+
hit.source === edge.source &&
|
|
732
|
+
hit.target === edge.target &&
|
|
733
|
+
hit.type === edge.type &&
|
|
734
|
+
hit.loop === loop &&
|
|
735
|
+
hit.markerKey === markerKey
|
|
736
|
+
) {
|
|
737
|
+
const dx = v.x - hit.originX;
|
|
738
|
+
const dy = v.y - hit.originY;
|
|
739
|
+
if (within) {
|
|
740
|
+
const b = hit.bounds;
|
|
741
|
+
if (!(
|
|
742
|
+
b.x + dx < within.x + within.width &&
|
|
743
|
+
b.x + dx + b.width > within.x &&
|
|
744
|
+
b.y + dy < within.y + within.height &&
|
|
745
|
+
b.y + dy + b.height > within.y
|
|
746
|
+
)) {
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (dx !== 0 || dy !== 0) {
|
|
751
|
+
shift(hit.points, dx, dy);
|
|
752
|
+
// `trimmed` is null when it would be `points`, so nothing is moved
|
|
753
|
+
// twice — the bug that aliasing invites here.
|
|
754
|
+
if (hit.trimmed) shift(hit.trimmed, dx, dy);
|
|
755
|
+
if (hit.endHead) shift(hit.endHead, dx, dy);
|
|
756
|
+
if (hit.startHead) shift(hit.startHead, dx, dy);
|
|
757
|
+
hit.bounds.x += dx;
|
|
758
|
+
hit.bounds.y += dy;
|
|
759
|
+
if (hit.middle) {
|
|
760
|
+
hit.middle.x += dx;
|
|
761
|
+
hit.middle.y += dy;
|
|
762
|
+
}
|
|
763
|
+
hit.originX = v.x;
|
|
764
|
+
hit.originY = v.y;
|
|
765
|
+
}
|
|
766
|
+
return hit;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const entry = buildRoute(v, edge, from, to, markerEnd, markerStart, hit);
|
|
770
|
+
if (!entry) {
|
|
771
|
+
this.routes.delete(edge.id);
|
|
772
|
+
return null;
|
|
773
|
+
}
|
|
774
|
+
if (!hit) {
|
|
775
|
+
if (this.routes.size >= ROUTE_LIMIT) this.routes.clear();
|
|
776
|
+
this.routes.set(edge.id, entry);
|
|
777
|
+
}
|
|
778
|
+
return entry;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// --- what goes in -------------------------------------------------------------
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* One node, resolved. The element builds these: a drag's live position is
|
|
786
|
+
* already in `rect`, a resize's live box has already replaced it, and
|
|
787
|
+
* `grips` is already filtered by whatever the handles took.
|
|
788
|
+
*/
|
|
789
|
+
export interface SceneNodeSource {
|
|
790
|
+
node: AnyNode;
|
|
791
|
+
/** **Graph space**, unlike everything else here. */
|
|
792
|
+
rect: FlowRect;
|
|
793
|
+
specs: readonly HandleSpec[];
|
|
794
|
+
type: AnyType | undefined;
|
|
795
|
+
/** The title bar's height in graph units — only read when `mounted`. */
|
|
796
|
+
header: number;
|
|
797
|
+
/** Whether a React body is mounted over this node, which is what makes
|
|
798
|
+
* the card draw a title bar rather than a centred label. */
|
|
799
|
+
mounted: boolean;
|
|
800
|
+
connectable: boolean;
|
|
801
|
+
/** Which resize grips to draw, already filtered. Empty for most nodes. */
|
|
802
|
+
grips: readonly XYPosition[];
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/** The pointer's business, for hover styling. */
|
|
806
|
+
export interface SceneHover {
|
|
807
|
+
nodeId: string | null;
|
|
808
|
+
handle: HandleAnchor | null;
|
|
809
|
+
edgeId: string | null;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/** A connection being dragged out of a handle. */
|
|
813
|
+
export interface SceneConnectionSource {
|
|
814
|
+
from: HandleAnchor;
|
|
815
|
+
to: HandleAnchor | null;
|
|
816
|
+
pointer: XYPosition;
|
|
817
|
+
valid: boolean;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/** The minimap's frame, as the element resolved it. */
|
|
821
|
+
export interface SceneMiniMapSource {
|
|
822
|
+
panel: FlowRect;
|
|
823
|
+
bounds: FlowRect;
|
|
824
|
+
scale: number;
|
|
825
|
+
nodeColor?: string | ((node: FlowNode<never>) => string);
|
|
826
|
+
maskColor?: string;
|
|
827
|
+
/** The rect this pass repaints of it, where the scene is built with no
|
|
828
|
+
* clip of its own — the furniture's, which is drawn over the rest. Only
|
|
829
|
+
* the nodes that reach it are built (`buildMiniMap`). */
|
|
830
|
+
reach?: FlowRect | null;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/** One control button's box and what it does. */
|
|
834
|
+
export interface SceneControlButton {
|
|
835
|
+
rect: FlowRect;
|
|
836
|
+
action: 'in' | 'out' | 'fit';
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/** The background, normalized. */
|
|
840
|
+
export interface SceneBackgroundSource {
|
|
841
|
+
variant: BackgroundVariant;
|
|
842
|
+
gap: number;
|
|
843
|
+
size: number;
|
|
844
|
+
color?: string;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/** Everything {@link buildScene} reads. */
|
|
848
|
+
export interface SceneInput {
|
|
849
|
+
viewport: Viewport;
|
|
850
|
+
/** The pane's content box, in screen space. */
|
|
851
|
+
pane: FlowRect;
|
|
852
|
+
/**
|
|
853
|
+
* The damage rect this pass repaints, in screen space — null for a full
|
|
854
|
+
* pass. Everything outside it survives on the window from the last frame,
|
|
855
|
+
* so it is a second cull on top of the pane's.
|
|
856
|
+
*
|
|
857
|
+
* A renderer that redraws the whole frame every time (the GL one) passes
|
|
858
|
+
* null, and the scene is the whole pane.
|
|
859
|
+
*/
|
|
860
|
+
clip: FlowRect | null;
|
|
861
|
+
/**
|
|
862
|
+
* What is kept, in the same window pixels — the pane when left out.
|
|
863
|
+
*
|
|
864
|
+
* A renderer that keeps a scene across frames wants more than the pane:
|
|
865
|
+
* the GL one builds the graph at a pinned origin and pans it by moving a
|
|
866
|
+
* uniform, so it culls to an *overscan* region round the view, and only
|
|
867
|
+
* rebuilds once the view leaves it (`./node.ts`, `glFrame`).
|
|
868
|
+
*/
|
|
869
|
+
cull?: FlowRect | null;
|
|
870
|
+
palette: FlowPalette;
|
|
871
|
+
/** The pane's own background, when its style set one. */
|
|
872
|
+
paneBackground?: string;
|
|
873
|
+
background: SceneBackgroundSource;
|
|
874
|
+
/** Paint order: z-index, then selection, with a dragged node on top. */
|
|
875
|
+
nodes: readonly SceneNodeSource[];
|
|
876
|
+
/** Every node, for the minimap — which summarises the graph, not the
|
|
877
|
+
* pass. */
|
|
878
|
+
all: readonly SceneNodeSource[];
|
|
879
|
+
edges: readonly AnyEdge[];
|
|
880
|
+
/** How far an animated edge's dash has marched, in graph units. */
|
|
881
|
+
dashPhase: number;
|
|
882
|
+
hover: SceneHover;
|
|
883
|
+
connection: SceneConnectionSource | null;
|
|
884
|
+
/** The box-selection rectangle, in screen space. */
|
|
885
|
+
selection: FlowRect | null;
|
|
886
|
+
miniMap: SceneMiniMapSource | null;
|
|
887
|
+
controls: readonly SceneControlButton[];
|
|
888
|
+
/** Device pixels per logical pixel — only to put node boxes on whole
|
|
889
|
+
* device pixels; everything else here is scale-free. */
|
|
890
|
+
scale: number;
|
|
891
|
+
/** Text metrics, which need the app's font cache. */
|
|
892
|
+
measure(
|
|
893
|
+
text: string,
|
|
894
|
+
options?: TextOptions,
|
|
895
|
+
): { width: number; height: number };
|
|
896
|
+
/** What survived the last frame. Optional: without one every route is
|
|
897
|
+
* computed again, which is correct and slower. */
|
|
898
|
+
cache?: SceneCache;
|
|
899
|
+
/**
|
|
900
|
+
* Whether the edges are stroked a pen at a time ({@link EDGE_BATCH}) —
|
|
901
|
+
* the pane's choice, which every pass that repaints part of it has to
|
|
902
|
+
* follow. Left out, this pass makes it from the edges on the pane, going
|
|
903
|
+
* by `batchWas` for which side of the threshold it was on.
|
|
904
|
+
*/
|
|
905
|
+
batch?: boolean;
|
|
906
|
+
batchWas?: boolean;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// --- what comes out -----------------------------------------------------------
|
|
910
|
+
|
|
911
|
+
/** A filled and/or stroked rectangle. */
|
|
912
|
+
export interface SceneRect {
|
|
913
|
+
rect: FlowRect;
|
|
914
|
+
radius: number;
|
|
915
|
+
fill?: string;
|
|
916
|
+
stroke?: string;
|
|
917
|
+
lineWidth?: number;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/** A string to set. */
|
|
921
|
+
export interface SceneText {
|
|
922
|
+
kind: 'text';
|
|
923
|
+
text: string;
|
|
924
|
+
x: number;
|
|
925
|
+
y: number;
|
|
926
|
+
size: number;
|
|
927
|
+
color: string;
|
|
928
|
+
weight?: 'bold';
|
|
929
|
+
align?: 'left' | 'center' | 'right';
|
|
930
|
+
baseline?: 'middle';
|
|
931
|
+
maxWidth?: number;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** A hairline: the rule under a title bar, a separator between two control
|
|
935
|
+
* buttons. Stroked rather than filled, so it lands where a 1px border
|
|
936
|
+
* does. */
|
|
937
|
+
export interface SceneRule {
|
|
938
|
+
kind: 'rule';
|
|
939
|
+
points: readonly XYPosition[];
|
|
940
|
+
color: string;
|
|
941
|
+
lineWidth: number;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/** An arrowhead. `filled` is a closed triangle; the open kind is a
|
|
945
|
+
* two-segment chevron. */
|
|
946
|
+
export interface SceneMarker {
|
|
947
|
+
points: readonly XYPosition[];
|
|
948
|
+
filled: boolean;
|
|
949
|
+
color: string;
|
|
950
|
+
lineWidth: number;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/** One edge, routed and ready. */
|
|
954
|
+
export interface SceneEdge {
|
|
955
|
+
id: string;
|
|
956
|
+
/** The polyline, already shortened behind an arrowhead. */
|
|
957
|
+
points: readonly XYPosition[];
|
|
958
|
+
stroke: string;
|
|
959
|
+
lineWidth: number;
|
|
960
|
+
dash?: readonly number[];
|
|
961
|
+
dashOffset: number;
|
|
962
|
+
/** Whether the dash marches. `dashOffset` already holds this frame's
|
|
963
|
+
* phase; a renderer that keeps edges across frames reads this instead and
|
|
964
|
+
* moves the phase itself, so a tick is not a rebuild. */
|
|
965
|
+
animated: boolean;
|
|
966
|
+
/** The pieces of `points` a pass that reaches only part of the edge draws
|
|
967
|
+
* — each run of segments whose ink can land in its rect. Absent where the
|
|
968
|
+
* whole route is drawn. */
|
|
969
|
+
runs?: readonly (readonly XYPosition[])[];
|
|
970
|
+
/** For a dashed edge with `runs`: how far along `points` each run
|
|
971
|
+
* starts, logical pixels — its pattern goes on from there rather than
|
|
972
|
+
* starting again at every cut. */
|
|
973
|
+
runStarts?: readonly number[];
|
|
974
|
+
markers: readonly SceneMarker[];
|
|
975
|
+
/** Which edges a batched pane strokes over which: a selected one over a
|
|
976
|
+
* hovered one over the rest. Left out, the rest. */
|
|
977
|
+
layer?: number;
|
|
978
|
+
/** The plate behind a label, so it sits above every edge. */
|
|
979
|
+
chip?: SceneRect;
|
|
980
|
+
label?: SceneText;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/** A connection point. */
|
|
984
|
+
export interface SceneHandle {
|
|
985
|
+
at: XYPosition;
|
|
986
|
+
radius: number;
|
|
987
|
+
fill: string;
|
|
988
|
+
stroke?: string;
|
|
989
|
+
lineWidth?: number;
|
|
990
|
+
label?: SceneText;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/** One node's drawing. `custom` means the node's type draws its own body,
|
|
994
|
+
* and everything but the handles and grips is its business. */
|
|
995
|
+
export interface SceneNodeItem {
|
|
996
|
+
id: string;
|
|
997
|
+
rect: FlowRect;
|
|
998
|
+
selected: boolean;
|
|
999
|
+
hovered: boolean;
|
|
1000
|
+
/** Present unless the type paints itself. */
|
|
1001
|
+
card?: { shape: SceneRect; accent?: SceneRect };
|
|
1002
|
+
/** The label, the description, and the rule under a title bar. */
|
|
1003
|
+
ink: readonly (SceneText | SceneRule)[];
|
|
1004
|
+
handles: readonly SceneHandle[];
|
|
1005
|
+
grips: readonly SceneRect[];
|
|
1006
|
+
/** Set when the type has a `paint`: the painter calls it, and a renderer
|
|
1007
|
+
* that cannot must say so rather than draw the wrong thing. */
|
|
1008
|
+
custom?: {
|
|
1009
|
+
type: AnyType;
|
|
1010
|
+
node: AnyNode;
|
|
1011
|
+
/** The node's handles in screen space, which is what the hook is
|
|
1012
|
+
* handed. */
|
|
1013
|
+
anchors: readonly HandleAnchor[];
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
/** The grid, described rather than drawn: a renderer works it out per pixel,
|
|
1018
|
+
* as a pattern tile or as a pile of runs, and the choice is the
|
|
1019
|
+
* renderer's. */
|
|
1020
|
+
export interface SceneGrid {
|
|
1021
|
+
variant: BackgroundVariant;
|
|
1022
|
+
/** The pitch on screen, already doubled past {@link MIN_GRID_PX}. */
|
|
1023
|
+
step: number;
|
|
1024
|
+
/** Where a grid line falls: the viewport origin, in screen space. */
|
|
1025
|
+
origin: XYPosition;
|
|
1026
|
+
/** A mark's size in graph units — multiply by the zoom for screen. */
|
|
1027
|
+
size: number;
|
|
1028
|
+
color: string;
|
|
1029
|
+
/** The part of the pane this pass covers. */
|
|
1030
|
+
region: FlowRect;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/** The connection line being dragged out of a handle. */
|
|
1034
|
+
export interface SceneConnection {
|
|
1035
|
+
points: readonly XYPosition[];
|
|
1036
|
+
stroke: string;
|
|
1037
|
+
lineWidth: number;
|
|
1038
|
+
dash?: readonly number[];
|
|
1039
|
+
tip: SceneHandle;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/** The minimap panel. */
|
|
1043
|
+
export interface SceneMiniMap {
|
|
1044
|
+
panel: SceneRect;
|
|
1045
|
+
nodes: readonly SceneMiniMapNode[];
|
|
1046
|
+
view: SceneRect;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* A node in the minimap, with the run it is filled in: a run of plain
|
|
1051
|
+
* squares of one colour, next to each other in the graph's order, is one
|
|
1052
|
+
* path and one fill (`paintPanels`). The run is worked out over every node,
|
|
1053
|
+
* so a pass that culls some away fills what it keeps as a whole repaint
|
|
1054
|
+
* does — nodes that overlap are one path's coverage or one over another,
|
|
1055
|
+
* and which one is the run's to say, not the pass's. `batched` says whether
|
|
1056
|
+
* the whole run was more than one node, for the same reason: a lone square
|
|
1057
|
+
* is filled as a rectangle, and that is not the pixels a path gives.
|
|
1058
|
+
*/
|
|
1059
|
+
export interface SceneMiniMapNode extends SceneRect {
|
|
1060
|
+
run: number;
|
|
1061
|
+
batched: boolean;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/** Where a box of the graph sits in the minimap, as it is drawn there — the
|
|
1065
|
+
* one formula the pass that draws the minimap and a claim on it share. */
|
|
1066
|
+
export function miniMapPlace(
|
|
1067
|
+
map: Pick<SceneMiniMapSource, 'panel' | 'bounds' | 'scale'>,
|
|
1068
|
+
rect: FlowRect,
|
|
1069
|
+
): FlowRect {
|
|
1070
|
+
const ox = map.panel.x + (map.panel.width - map.bounds.width * map.scale) / 2;
|
|
1071
|
+
const oy =
|
|
1072
|
+
map.panel.y + (map.panel.height - map.bounds.height * map.scale) / 2;
|
|
1073
|
+
return {
|
|
1074
|
+
x: ox + (rect.x - map.bounds.x) * map.scale,
|
|
1075
|
+
y: oy + (rect.y - map.bounds.y) * map.scale,
|
|
1076
|
+
width: Math.max(1, rect.width * map.scale),
|
|
1077
|
+
height: Math.max(1, rect.height * map.scale),
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/** How far a minimap node's fill reaches past its box: its antialiased
|
|
1082
|
+
* edge, which a pass has to take in to draw the node's part of a pixel it
|
|
1083
|
+
* shares. */
|
|
1084
|
+
export const MINIMAP_BLEED = 2;
|
|
1085
|
+
|
|
1086
|
+
/** One button's mark: its runs go in one path, which is what the 2D painter
|
|
1087
|
+
* did per button before any of this moved. */
|
|
1088
|
+
export interface SceneGlyph {
|
|
1089
|
+
runs: readonly (readonly XYPosition[])[];
|
|
1090
|
+
color: string;
|
|
1091
|
+
lineWidth: number;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** The zoom controls. */
|
|
1095
|
+
export interface SceneControls {
|
|
1096
|
+
panel: SceneRect;
|
|
1097
|
+
rules: readonly SceneRule[];
|
|
1098
|
+
glyphs: readonly SceneGlyph[];
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/** The whole frame. */
|
|
1102
|
+
export interface FlowScene {
|
|
1103
|
+
viewport: Viewport;
|
|
1104
|
+
pane: FlowRect;
|
|
1105
|
+
/** Carried so a custom node type's `paint` can be handed it — the hook
|
|
1106
|
+
* takes the palette the rest of the frame was drawn from. */
|
|
1107
|
+
palette: FlowPalette;
|
|
1108
|
+
/** What this pass covers: the pane, or the damage rect inside it. Null
|
|
1109
|
+
* when the pass reaches nothing. */
|
|
1110
|
+
region: FlowRect | null;
|
|
1111
|
+
background: SceneRect | null;
|
|
1112
|
+
grid: SceneGrid | null;
|
|
1113
|
+
edges: readonly SceneEdge[];
|
|
1114
|
+
nodes: readonly SceneNodeItem[];
|
|
1115
|
+
connection: SceneConnection | null;
|
|
1116
|
+
selection: SceneRect | null;
|
|
1117
|
+
miniMap: SceneMiniMap | null;
|
|
1118
|
+
controls: SceneControls | null;
|
|
1119
|
+
/** Whether any edge in view is animated — the element keeps a timer alive
|
|
1120
|
+
* only while this is true. */
|
|
1121
|
+
animated: boolean;
|
|
1122
|
+
/** The box those animated edges actually inked, so a dash tick repaints
|
|
1123
|
+
* that rather than the pane. Null when this pass drew none. */
|
|
1124
|
+
animBox: FlowRect | null;
|
|
1125
|
+
/** Whether the edges are stroked a pen at a time (`SceneInput.batch`). */
|
|
1126
|
+
batch: boolean;
|
|
1127
|
+
/** How many edges reach the pane, whatever this pass reaches: what the
|
|
1128
|
+
* next choice of `batch` goes by. */
|
|
1129
|
+
edgesOnPane: number;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// --- geometry -----------------------------------------------------------------
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* The viewport as the *window* sees it: the pane's own origin folded into
|
|
1136
|
+
* the translation.
|
|
1137
|
+
*
|
|
1138
|
+
* A {@link Viewport} is the pane's — `x`/`y` place the graph relative to the
|
|
1139
|
+
* pane's top-left, which is what `setViewport` and `onViewportChange` speak
|
|
1140
|
+
* — while everything this module draws and everything the element hit-tests
|
|
1141
|
+
* is in window pixels. Every graph-to-window conversion goes through this
|
|
1142
|
+
* first. The scene extraction once skipped it, so a pane that did not sit at
|
|
1143
|
+
* the window's origin drew and hit-tested shifted by its own offset — and
|
|
1144
|
+
* agreed with itself while doing it, which is why only an off-origin test
|
|
1145
|
+
* could see it (`test/flow.test.ts`, "off the window origin").
|
|
1146
|
+
*/
|
|
1147
|
+
export function screenViewport(v: Viewport, pane: FlowRect): Viewport {
|
|
1148
|
+
return { x: pane.x + v.x, y: pane.y + v.y, zoom: v.zoom };
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/** Graph point to window, through a {@link screenViewport}. */
|
|
1152
|
+
export function toScreen(v: Viewport, p: XYPosition): XYPosition {
|
|
1153
|
+
return { x: p.x * v.zoom + v.x, y: p.y * v.zoom + v.y };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* A node's box on screen, put on whole device pixels.
|
|
1158
|
+
*
|
|
1159
|
+
* Rounded as *edges* rather than as a size, so two nodes that share a column
|
|
1160
|
+
* still share it after rounding.
|
|
1161
|
+
*/
|
|
1162
|
+
export function screenRect(
|
|
1163
|
+
v: Viewport,
|
|
1164
|
+
rect: FlowRect,
|
|
1165
|
+
scale: number,
|
|
1166
|
+
): FlowRect {
|
|
1167
|
+
// Written out rather than through `toScreen` and a rounding closure: a
|
|
1168
|
+
// drag or a pan asks this of every node in the graph each step, to find
|
|
1169
|
+
// the few on screen, and the two allocations a call were most of it.
|
|
1170
|
+
const px = rect.x * v.zoom + v.x;
|
|
1171
|
+
const py = rect.y * v.zoom + v.y;
|
|
1172
|
+
const x = snapToGrid(px * scale) / scale;
|
|
1173
|
+
const y = snapToGrid(py * scale) / scale;
|
|
1174
|
+
return {
|
|
1175
|
+
x,
|
|
1176
|
+
y,
|
|
1177
|
+
width: snapToGrid((px + rect.width * v.zoom) * scale) / scale - x,
|
|
1178
|
+
height: snapToGrid((py + rect.height * v.zoom) * scale) / scale - y,
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/** A handle's drawn radius: it grows with the zoom, but only so far, so a
|
|
1183
|
+
* zoomed-out graph still has something to aim at. */
|
|
1184
|
+
export function handleRadius(zoom: number): number {
|
|
1185
|
+
return Math.min(6, Math.max(2.5, 4.5 * zoom));
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export function sameHandle(
|
|
1189
|
+
a: HandleAnchor | null | undefined,
|
|
1190
|
+
b: HandleAnchor,
|
|
1191
|
+
): boolean {
|
|
1192
|
+
return (
|
|
1193
|
+
a != null &&
|
|
1194
|
+
a.nodeId === b.nodeId &&
|
|
1195
|
+
(a.id ?? null) === (b.id ?? null) &&
|
|
1196
|
+
a.type === b.type &&
|
|
1197
|
+
a.position === b.position
|
|
1198
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
function intersect(a: FlowRect, b: FlowRect): FlowRect | null {
|
|
1202
|
+
const x = Math.max(a.x, b.x);
|
|
1203
|
+
const y = Math.max(a.y, b.y);
|
|
1204
|
+
const right = Math.min(a.x + a.width, b.x + b.width);
|
|
1205
|
+
const bottom = Math.min(a.y + a.height, b.y + b.height);
|
|
1206
|
+
if (right <= x || bottom <= y) return null;
|
|
1207
|
+
return { x, y, width: right - x, height: bottom - y };
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
function centre(rect: FlowRect): XYPosition {
|
|
1211
|
+
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* A node's handle anchors, in graph space.
|
|
1216
|
+
*
|
|
1217
|
+
* Takes the three fields it reads rather than a whole
|
|
1218
|
+
* {@link SceneNodeSource}, and that is load-bearing rather than tidy: a
|
|
1219
|
+
* source carries `grips`, and which grips a node shows depends on where its
|
|
1220
|
+
* handles are — asking for the whole source here is a cycle.
|
|
1221
|
+
*/
|
|
1222
|
+
export function anchorsOf(source: {
|
|
1223
|
+
node: { id: string };
|
|
1224
|
+
rect: FlowRect;
|
|
1225
|
+
specs: readonly HandleSpec[];
|
|
1226
|
+
}): HandleAnchor[] {
|
|
1227
|
+
return source.specs.map((spec) =>
|
|
1228
|
+
handleAnchor(source.node.id, source.rect, spec),
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/** An arrowhead's points. */
|
|
1233
|
+
function markerPoints(
|
|
1234
|
+
at: XYPosition,
|
|
1235
|
+
angle: number,
|
|
1236
|
+
type: MarkerType,
|
|
1237
|
+
size: number,
|
|
1238
|
+
): XYPosition[] {
|
|
1239
|
+
const spread = 0.42; // radians off the shaft — a ~24° half-angle
|
|
1240
|
+
const back = {
|
|
1241
|
+
x: at.x - Math.cos(angle) * size,
|
|
1242
|
+
y: at.y - Math.sin(angle) * size,
|
|
1243
|
+
};
|
|
1244
|
+
const left = {
|
|
1245
|
+
x: at.x - Math.cos(angle - spread) * size,
|
|
1246
|
+
y: at.y - Math.sin(angle - spread) * size,
|
|
1247
|
+
};
|
|
1248
|
+
const right = {
|
|
1249
|
+
x: at.x - Math.cos(angle + spread) * size,
|
|
1250
|
+
y: at.y - Math.sin(angle + spread) * size,
|
|
1251
|
+
};
|
|
1252
|
+
return type === 'arrowclosed' ? [at, left, back, right] : [left, at, right];
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// --- the builder --------------------------------------------------------------
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* The scene for one pass.
|
|
1259
|
+
*
|
|
1260
|
+
* Pure but for one thing, and it is worth stating plainly: with a
|
|
1261
|
+
* {@link SceneCache} the routes it returns are **arrays the cache owns and
|
|
1262
|
+
* the next frame will move in place**. A scene is built and drawn inside one
|
|
1263
|
+
* paint and nothing keeps it, so the rule is simply that — do not hold a
|
|
1264
|
+
* scene past the frame that made it, and do not mutate what it hands back.
|
|
1265
|
+
* Without a cache every array is fresh and the rule is vacuous.
|
|
1266
|
+
*/
|
|
1267
|
+
export function buildScene(input: SceneInput): FlowScene {
|
|
1268
|
+
const { viewport: v, pane, clip, palette } = input;
|
|
1269
|
+
const region = clip ? intersect(pane, clip) : pane;
|
|
1270
|
+
|
|
1271
|
+
const scene: FlowScene = {
|
|
1272
|
+
viewport: v,
|
|
1273
|
+
pane,
|
|
1274
|
+
palette,
|
|
1275
|
+
region,
|
|
1276
|
+
background: region
|
|
1277
|
+
? {
|
|
1278
|
+
rect: region,
|
|
1279
|
+
radius: 0,
|
|
1280
|
+
fill: input.paneBackground ?? palette.background,
|
|
1281
|
+
}
|
|
1282
|
+
: null,
|
|
1283
|
+
grid: null,
|
|
1284
|
+
edges: [],
|
|
1285
|
+
nodes: [],
|
|
1286
|
+
connection: null,
|
|
1287
|
+
selection: null,
|
|
1288
|
+
miniMap: null,
|
|
1289
|
+
controls: null,
|
|
1290
|
+
animated: false,
|
|
1291
|
+
animBox: null,
|
|
1292
|
+
batch: input.batch ?? input.batchWas ?? false,
|
|
1293
|
+
edgesOnPane: 0,
|
|
1294
|
+
};
|
|
1295
|
+
if (!region) return scene;
|
|
1296
|
+
|
|
1297
|
+
scene.grid = buildGrid(input, region);
|
|
1298
|
+
scene.edges = buildEdges(input, scene);
|
|
1299
|
+
scene.nodes = buildNodes(input);
|
|
1300
|
+
scene.connection = buildConnection(input);
|
|
1301
|
+
if (input.selection) {
|
|
1302
|
+
scene.selection = {
|
|
1303
|
+
rect: input.selection,
|
|
1304
|
+
radius: 2,
|
|
1305
|
+
fill: palette.selection,
|
|
1306
|
+
stroke: palette.accent,
|
|
1307
|
+
lineWidth: 1,
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
// Both panels are pinned to a corner, so a pass whose damage misses them
|
|
1311
|
+
// skips the walk that builds them — which for the minimap is every node in
|
|
1312
|
+
// the graph, not just the ones in view.
|
|
1313
|
+
if (input.miniMap && (!clip || rectsOverlap(input.miniMap.panel, clip))) {
|
|
1314
|
+
scene.miniMap = buildMiniMap(
|
|
1315
|
+
input,
|
|
1316
|
+
input.miniMap,
|
|
1317
|
+
clip ?? input.miniMap.reach,
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
if (
|
|
1321
|
+
input.controls.length > 0 &&
|
|
1322
|
+
(!clip || input.controls.some((b) => rectsOverlap(b.rect, clip)))
|
|
1323
|
+
) {
|
|
1324
|
+
scene.controls = buildControls(input);
|
|
1325
|
+
}
|
|
1326
|
+
return scene;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
function buildGrid(input: SceneInput, region: FlowRect): SceneGrid | null {
|
|
1330
|
+
const { background: options, viewport: v, pane, palette } = input;
|
|
1331
|
+
if (options.variant === 'none') return null;
|
|
1332
|
+
let step = options.gap * v.zoom;
|
|
1333
|
+
if (!(step > 0)) return null;
|
|
1334
|
+
// Doubling rather than clamping keeps the grid *aligned* to the graph
|
|
1335
|
+
// while zooming out: every visible line is still a real one.
|
|
1336
|
+
while (step < MIN_GRID_PX) step *= 2;
|
|
1337
|
+
return {
|
|
1338
|
+
variant: options.variant,
|
|
1339
|
+
step,
|
|
1340
|
+
origin: { x: pane.x + v.x, y: pane.y + v.y },
|
|
1341
|
+
size: options.size,
|
|
1342
|
+
color: options.color ?? palette.grid,
|
|
1343
|
+
region,
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
function indexOf(
|
|
1348
|
+
all: readonly SceneNodeSource[],
|
|
1349
|
+
): Map<string, SceneNodeSource> {
|
|
1350
|
+
const map = new Map<string, SceneNodeSource>();
|
|
1351
|
+
for (const source of all) map.set(source.node.id, source);
|
|
1352
|
+
return map;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
function buildEdges(input: SceneInput, scene: FlowScene): SceneEdge[] {
|
|
1356
|
+
const { pane, clip, palette, hover, scale } = input;
|
|
1357
|
+
const v = screenViewport(input.viewport, pane);
|
|
1358
|
+
const kept = input.cull ?? pane;
|
|
1359
|
+
const labels = v.zoom >= LABEL_ZOOM;
|
|
1360
|
+
const out: SceneEdge[] = [];
|
|
1361
|
+
const cache = input.cache;
|
|
1362
|
+
let animBox: FlowRect | null = null;
|
|
1363
|
+
// a label's plate, the same for every edge that names none of its own
|
|
1364
|
+
let plateFill: string | undefined;
|
|
1365
|
+
|
|
1366
|
+
// Two rejects: one from the nodes alone — the coarse box, culled once for
|
|
1367
|
+
// every pass of a frame where there is a cache — and one from the route
|
|
1368
|
+
// the edge took.
|
|
1369
|
+
const onPane = cache
|
|
1370
|
+
? cache.edgesOnScreen(v, kept, input.edges, input.all, scale)
|
|
1371
|
+
: cullEdges(v, kept, input.edges, indexOf(input.all), scale);
|
|
1372
|
+
scene.edgesOnPane = onPane.length;
|
|
1373
|
+
scene.batch = input.batch ?? batchesEdges(onPane.length, input.batchWas);
|
|
1374
|
+
for (const { edge, from, to, coarse } of onPane) {
|
|
1375
|
+
// Tracked before the damage skip, deliberately: whether the dash timer
|
|
1376
|
+
// runs is a question about the viewport, not about what this particular
|
|
1377
|
+
// pass repaints — deciding it after the skip is how a drag in one corner
|
|
1378
|
+
// would stop the dash marching in the other. And so is the box the ticks
|
|
1379
|
+
// repaint, below, for the same reason: a pass over one corner that
|
|
1380
|
+
// reached one animated edge made that edge the only one the next tick
|
|
1381
|
+
// repainted, and every other dash on screen stopped.
|
|
1382
|
+
if (edge.animated) scene.animated = true;
|
|
1383
|
+
const reached = !clip || rectsOverlap(coarse, clip);
|
|
1384
|
+
if (!reached && !edge.animated) continue;
|
|
1385
|
+
|
|
1386
|
+
const markerEnd = endMarkerOf(edge);
|
|
1387
|
+
const markerStart = normalizeMarker(edge.markerStart);
|
|
1388
|
+
|
|
1389
|
+
const selected = edge.selected ?? false;
|
|
1390
|
+
const hovered = hover.edgeId === edge.id;
|
|
1391
|
+
const stroke =
|
|
1392
|
+
edge.style?.stroke ??
|
|
1393
|
+
(selected ? palette.edgeSelected : hovered ? palette.text : palette.edge);
|
|
1394
|
+
const lineWidth = edgeLineWidth(edge, v.zoom);
|
|
1395
|
+
const reach = penReach(lineWidth);
|
|
1396
|
+
|
|
1397
|
+
// The route, from the cache where there is one: a pan keeps the zoom, so
|
|
1398
|
+
// the cached route is the same curve translated, and re-deriving it —
|
|
1399
|
+
// the handles, the curve, the arrowheads — is the work this skips.
|
|
1400
|
+
//
|
|
1401
|
+
// And a cached route that cannot reach this pass is not moved to it at
|
|
1402
|
+
// all. A long edge's coarse box reaches a strip its curve never comes
|
|
1403
|
+
// near — the lattice's diagonals reach every corner of the pane — and
|
|
1404
|
+
// carrying each such route to the frame, cutting it to the pass and
|
|
1405
|
+
// finding it empty was most of what a 2D pan's strips cost. Only where
|
|
1406
|
+
// nothing of the edge could land there: its stroke stays within `reach`
|
|
1407
|
+
// of its route's box, heads and all; a label's plate is sized by its
|
|
1408
|
+
// text, and a marching edge's box is tracked whatever it reaches.
|
|
1409
|
+
const within =
|
|
1410
|
+
clip && reached && !edge.animated && !(labels && edge.label)
|
|
1411
|
+
? inflateRect(clip, reach)
|
|
1412
|
+
: null;
|
|
1413
|
+
const routed = cache
|
|
1414
|
+
? cache.route(v, edge, from, to, markerEnd, markerStart, within)
|
|
1415
|
+
: uncachedRoute(v, edge, from, to, markerEnd, markerStart);
|
|
1416
|
+
if (!routed) continue;
|
|
1417
|
+
const bounds = routed.bounds;
|
|
1418
|
+
// the heads are in the box and the pen reaches past it: an edge whose
|
|
1419
|
+
// route had just left the pane culled the wing of a head still on it
|
|
1420
|
+
if (
|
|
1421
|
+
!rectsOverlap(
|
|
1422
|
+
inflateRect(withLabelPlate(bounds, edge, v.zoom), reach),
|
|
1423
|
+
kept,
|
|
1424
|
+
)
|
|
1425
|
+
) {
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
if (edge.animated) {
|
|
1429
|
+
// The coarse box carries the bezier's slack, and a tick that repaints
|
|
1430
|
+
// slack repaints a card-sized halo of neighbours sixteen times a
|
|
1431
|
+
// second — so the box the ticks invalidate comes off the *drawn*
|
|
1432
|
+
// geometry.
|
|
1433
|
+
const tight = inflateRect(bounds, CULL_MARGIN);
|
|
1434
|
+
animBox = animBox ? unionRects(animBox, tight) : tight;
|
|
1435
|
+
}
|
|
1436
|
+
if (!reached) continue;
|
|
1437
|
+
|
|
1438
|
+
// The heads' geometry came with the route; only their ink is this
|
|
1439
|
+
// frame's, because selection and hover recolour without moving anything.
|
|
1440
|
+
const markers: SceneMarker[] = [];
|
|
1441
|
+
if (routed.endHead && markerEnd) {
|
|
1442
|
+
markers.push({
|
|
1443
|
+
points: routed.endHead,
|
|
1444
|
+
filled: markerEnd.type === 'arrowclosed',
|
|
1445
|
+
color: markerEnd.color ?? stroke,
|
|
1446
|
+
lineWidth,
|
|
1447
|
+
});
|
|
1448
|
+
}
|
|
1449
|
+
if (routed.startHead && markerStart) {
|
|
1450
|
+
markers.push({
|
|
1451
|
+
points: routed.startHead,
|
|
1452
|
+
filled: markerStart.type === 'arrowclosed',
|
|
1453
|
+
color: markerStart.color ?? stroke,
|
|
1454
|
+
lineWidth,
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
const dash = edge.style?.dash ?? (edge.animated ? DEFAULT_DASH : undefined);
|
|
1459
|
+
const points = routed.trimmed ?? routed.points;
|
|
1460
|
+
|
|
1461
|
+
const item: SceneEdge = {
|
|
1462
|
+
id: edge.id,
|
|
1463
|
+
points,
|
|
1464
|
+
stroke,
|
|
1465
|
+
lineWidth,
|
|
1466
|
+
dash: dash?.map((d) => d * v.zoom),
|
|
1467
|
+
dashOffset: edge.animated ? -input.dashPhase * v.zoom : 0,
|
|
1468
|
+
animated: edge.animated ?? false,
|
|
1469
|
+
markers,
|
|
1470
|
+
layer: selected ? 2 : hovered ? 1 : 0,
|
|
1471
|
+
};
|
|
1472
|
+
// A pass over part of the edge draws the part it reaches: a strip down
|
|
1473
|
+
// the pane's edge crossed by a hundred long edges traced every point of
|
|
1474
|
+
// every one of them, to keep the handful of segments inside it
|
|
1475
|
+
// (`reach`, above).
|
|
1476
|
+
//
|
|
1477
|
+
// A dashed edge too, with where each run starts along it: the pattern
|
|
1478
|
+
// is picked up there through the dash offset (`paintEdges`). Left
|
|
1479
|
+
// whole, every marching edge a 2D pan's strip crossed was stroked end
|
|
1480
|
+
// to end, and on X11 that is a coverage mask the size of the edge's box
|
|
1481
|
+
// uploaded for a strip two pixels wide — 1.1 MB a frame over the
|
|
1482
|
+
// stress example's widgets, a pan held to 38 fps by ten dashed edges.
|
|
1483
|
+
if (clip) {
|
|
1484
|
+
const starts: number[] | undefined = dash ? [] : undefined;
|
|
1485
|
+
const runs = runsReaching(points, clip, reach, starts);
|
|
1486
|
+
if (runs) {
|
|
1487
|
+
item.runs = runs;
|
|
1488
|
+
if (starts) item.runStarts = distancesAt(points, starts);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
if (labels && edge.label) {
|
|
1493
|
+
const at = middleOf(routed);
|
|
1494
|
+
const size = Math.max(8, 11 * v.zoom);
|
|
1495
|
+
const metrics = input.measure(edge.label, { size });
|
|
1496
|
+
const padX = 5 * v.zoom;
|
|
1497
|
+
const padY = 2 * v.zoom;
|
|
1498
|
+
item.chip = {
|
|
1499
|
+
rect: {
|
|
1500
|
+
x: snapToGrid(at.x - metrics.width / 2 - padX),
|
|
1501
|
+
y: snapToGrid(at.y - metrics.height / 2 - padY),
|
|
1502
|
+
width: Math.round(metrics.width + padX * 2),
|
|
1503
|
+
height: Math.round(metrics.height + padY * 2),
|
|
1504
|
+
},
|
|
1505
|
+
radius: Math.max(2, Math.round(3 * v.zoom)),
|
|
1506
|
+
fill:
|
|
1507
|
+
edge.style?.labelBackground ??
|
|
1508
|
+
(plateFill ??= tint(palette.background, 0.92)),
|
|
1509
|
+
};
|
|
1510
|
+
item.label = {
|
|
1511
|
+
kind: 'text',
|
|
1512
|
+
text: edge.label,
|
|
1513
|
+
x: at.x,
|
|
1514
|
+
y: at.y,
|
|
1515
|
+
size,
|
|
1516
|
+
color: edge.style?.labelColor ?? palette.text,
|
|
1517
|
+
align: 'center',
|
|
1518
|
+
baseline: 'middle',
|
|
1519
|
+
};
|
|
1520
|
+
}
|
|
1521
|
+
// …and of what is left, only what this pass reaches: an arrowhead or a
|
|
1522
|
+
// label plate beside the rect is drawn by the pass that holds it, and an
|
|
1523
|
+
// edge with nothing here is not drawn at all.
|
|
1524
|
+
if (clip) {
|
|
1525
|
+
if (item.chip && !rectsOverlap(item.chip.rect, clip)) {
|
|
1526
|
+
item.chip = undefined;
|
|
1527
|
+
item.label = undefined;
|
|
1528
|
+
}
|
|
1529
|
+
if (markers.length > 0) {
|
|
1530
|
+
item.markers = markers.filter((m) =>
|
|
1531
|
+
rectsOverlap(inflateRect(pointsBox(m.points), reach), clip),
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
const stroked = item.runs
|
|
1535
|
+
? item.runs.length > 0
|
|
1536
|
+
: rectsOverlap(inflateRect(bounds, reach), clip);
|
|
1537
|
+
if (!stroked && !item.chip && item.markers.length === 0) continue;
|
|
1538
|
+
}
|
|
1539
|
+
out.push(item);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
scene.animBox = animBox;
|
|
1543
|
+
return out;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
/** The box around a handful of points. */
|
|
1547
|
+
function pointsBox(points: readonly XYPosition[]): FlowRect {
|
|
1548
|
+
let x0 = Infinity;
|
|
1549
|
+
let y0 = Infinity;
|
|
1550
|
+
let x1 = -Infinity;
|
|
1551
|
+
let y1 = -Infinity;
|
|
1552
|
+
for (const p of points) {
|
|
1553
|
+
if (p.x < x0) x0 = p.x;
|
|
1554
|
+
if (p.y < y0) y0 = p.y;
|
|
1555
|
+
if (p.x > x1) x1 = p.x;
|
|
1556
|
+
if (p.y > y1) y1 = p.y;
|
|
1557
|
+
}
|
|
1558
|
+
return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
/**
|
|
1562
|
+
* The runs of `points` whose ink can land in `clip`: each maximal run of
|
|
1563
|
+
* segments whose box comes within `reach` of it, or null when every segment
|
|
1564
|
+
* does and the route is one run already. A run ends at a vertex farther
|
|
1565
|
+
* than `reach` from the rect, so the cap and the join the cut replaced are
|
|
1566
|
+
* drawn where the rect cannot see them.
|
|
1567
|
+
*/
|
|
1568
|
+
export function runsReaching(
|
|
1569
|
+
points: readonly XYPosition[],
|
|
1570
|
+
clip: FlowRect,
|
|
1571
|
+
reach: number,
|
|
1572
|
+
/** Filled, when given, with the index in `points` each run starts at. */
|
|
1573
|
+
starts?: number[],
|
|
1574
|
+
): (readonly XYPosition[])[] | null {
|
|
1575
|
+
const x0 = clip.x - reach;
|
|
1576
|
+
const y0 = clip.y - reach;
|
|
1577
|
+
const x1 = clip.x + clip.width + reach;
|
|
1578
|
+
const y1 = clip.y + clip.height + reach;
|
|
1579
|
+
let runs: (readonly XYPosition[])[] | null = null;
|
|
1580
|
+
let start = -1;
|
|
1581
|
+
for (let i = 0; i + 1 < points.length; i++) {
|
|
1582
|
+
const a = points[i];
|
|
1583
|
+
const b = points[i + 1];
|
|
1584
|
+
const inside =
|
|
1585
|
+
(a.x > b.x ? a.x : b.x) >= x0 &&
|
|
1586
|
+
(a.x < b.x ? a.x : b.x) <= x1 &&
|
|
1587
|
+
(a.y > b.y ? a.y : b.y) >= y0 &&
|
|
1588
|
+
(a.y < b.y ? a.y : b.y) <= y1;
|
|
1589
|
+
if (inside) {
|
|
1590
|
+
if (start < 0) start = i;
|
|
1591
|
+
} else {
|
|
1592
|
+
runs ??= [];
|
|
1593
|
+
if (start >= 0) {
|
|
1594
|
+
runs.push(points.slice(start, i + 1));
|
|
1595
|
+
starts?.push(start);
|
|
1596
|
+
start = -1;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (!runs) return null;
|
|
1601
|
+
if (start >= 0) {
|
|
1602
|
+
runs.push(points.slice(start));
|
|
1603
|
+
starts?.push(start);
|
|
1604
|
+
}
|
|
1605
|
+
return runs;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
/** How far along a polyline each of `indices` is, in its own units. */
|
|
1609
|
+
function distancesAt(
|
|
1610
|
+
points: readonly XYPosition[],
|
|
1611
|
+
indices: readonly number[],
|
|
1612
|
+
): number[] {
|
|
1613
|
+
const out: number[] = [];
|
|
1614
|
+
let at = 0;
|
|
1615
|
+
let length = 0;
|
|
1616
|
+
for (const index of indices) {
|
|
1617
|
+
for (; at < index; at++) {
|
|
1618
|
+
length += Math.hypot(
|
|
1619
|
+
points[at + 1].x - points[at].x,
|
|
1620
|
+
points[at + 1].y - points[at].y,
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
out.push(length);
|
|
1624
|
+
}
|
|
1625
|
+
return out;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
/** The box two nodes' edge cannot leave, before it is routed. */
|
|
1629
|
+
export function edgeCoarseBox(
|
|
1630
|
+
v: Viewport,
|
|
1631
|
+
from: SceneNodeSource,
|
|
1632
|
+
to: SceneNodeSource,
|
|
1633
|
+
// unused: a coarse box with pixels of slack has no use for the device
|
|
1634
|
+
// grid `screenRect` snaps to, and snapping two rects per edge was most of
|
|
1635
|
+
// what this cost — every edge, every frame of a drag
|
|
1636
|
+
_scale?: number,
|
|
1637
|
+
): FlowRect {
|
|
1638
|
+
const z = v.zoom;
|
|
1639
|
+
const f = from.rect;
|
|
1640
|
+
const t = to.rect;
|
|
1641
|
+
const ax = f.x * z + v.x;
|
|
1642
|
+
const ay = f.y * z + v.y;
|
|
1643
|
+
const aw = f.width * z;
|
|
1644
|
+
const ah = f.height * z;
|
|
1645
|
+
const bx = t.x * z + v.x;
|
|
1646
|
+
const by = t.y * z + v.y;
|
|
1647
|
+
const bw = t.width * z;
|
|
1648
|
+
const bh = t.height * z;
|
|
1649
|
+
const span = Math.hypot(
|
|
1650
|
+
ax + aw / 2 - (bx + bw / 2),
|
|
1651
|
+
ay + ah / 2 - (by + bh / 2),
|
|
1652
|
+
);
|
|
1653
|
+
const slack =
|
|
1654
|
+
Math.max(5, EDGE_SLOP * z) +
|
|
1655
|
+
Math.max(EDGE_STEP_OFFSET * 3 * z, 8 * Math.sqrt(z * span));
|
|
1656
|
+
const x = Math.min(ax, bx) - slack;
|
|
1657
|
+
const y = Math.min(ay, by) - slack;
|
|
1658
|
+
return {
|
|
1659
|
+
x,
|
|
1660
|
+
y,
|
|
1661
|
+
width: Math.max(ax + aw, bx + bw) + slack - x,
|
|
1662
|
+
height: Math.max(ay + ah, by + bh) + slack - y,
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
/** Which handles an edge joins, and the polyline between them. */
|
|
1667
|
+
export function edgeRoute(
|
|
1668
|
+
v: Viewport,
|
|
1669
|
+
edge: AnyEdge,
|
|
1670
|
+
from: SceneNodeSource,
|
|
1671
|
+
to: SceneNodeSource,
|
|
1672
|
+
): { points: XYPosition[]; from: HandleAnchor; to: HandleAnchor } | null {
|
|
1673
|
+
const a = endpoint(from, edge.sourceHandle, 'source', centre(to.rect));
|
|
1674
|
+
const b = endpoint(to, edge.targetHandle, 'target', centre(from.rect));
|
|
1675
|
+
if (!a || !b) return null;
|
|
1676
|
+
const s = toScreen(v, a);
|
|
1677
|
+
const t = toScreen(v, b);
|
|
1678
|
+
return {
|
|
1679
|
+
points: edgePath(
|
|
1680
|
+
edge.type as EdgeType | undefined,
|
|
1681
|
+
{ x: s.x, y: s.y, position: a.position },
|
|
1682
|
+
{ x: t.x, y: t.y, position: b.position },
|
|
1683
|
+
{
|
|
1684
|
+
stepOffset: EDGE_STEP_OFFSET * v.zoom,
|
|
1685
|
+
radius: 8 * v.zoom,
|
|
1686
|
+
scale: v.zoom,
|
|
1687
|
+
loop: edge.source === edge.target,
|
|
1688
|
+
},
|
|
1689
|
+
),
|
|
1690
|
+
from: a,
|
|
1691
|
+
to: b,
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
export function endpoint(
|
|
1696
|
+
source: {
|
|
1697
|
+
node: { id: string };
|
|
1698
|
+
rect: FlowRect;
|
|
1699
|
+
specs: readonly HandleSpec[];
|
|
1700
|
+
},
|
|
1701
|
+
handleId: string | null | undefined,
|
|
1702
|
+
type: 'source' | 'target',
|
|
1703
|
+
towards: XYPosition | null,
|
|
1704
|
+
): HandleAnchor | null {
|
|
1705
|
+
const anchors = anchorsOf(source);
|
|
1706
|
+
if (handleId != null) {
|
|
1707
|
+
const named = anchors.find((a) => a.id === handleId);
|
|
1708
|
+
if (named) return named;
|
|
1709
|
+
}
|
|
1710
|
+
const typed = anchors.filter((a) => a.type === type);
|
|
1711
|
+
const candidates = typed.length > 0 ? typed : anchors;
|
|
1712
|
+
if (candidates.length === 0) return null;
|
|
1713
|
+
if (candidates.length === 1 || !towards) return candidates[0];
|
|
1714
|
+
let best = candidates[0];
|
|
1715
|
+
let bestDistance = Infinity;
|
|
1716
|
+
for (const anchor of candidates) {
|
|
1717
|
+
const d = Math.hypot(anchor.x - towards.x, anchor.y - towards.y);
|
|
1718
|
+
if (d < bestDistance) {
|
|
1719
|
+
bestDistance = d;
|
|
1720
|
+
best = anchor;
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return best;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
/** The node items of a scene alone — what a mounted node's card is painted
|
|
1727
|
+
* from, apart from the rest of the scene (`FlowGraphNode.paintCard`). */
|
|
1728
|
+
export function buildNodeItems(input: SceneInput): SceneNodeItem[] {
|
|
1729
|
+
return buildNodes(input);
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
function buildNodes(input: SceneInput): SceneNodeItem[] {
|
|
1733
|
+
const { pane, clip, hover, scale } = input;
|
|
1734
|
+
const v = screenViewport(input.viewport, pane);
|
|
1735
|
+
const kept = input.cull ?? pane;
|
|
1736
|
+
const out: SceneNodeItem[] = [];
|
|
1737
|
+
for (const { source, rect } of input.cache
|
|
1738
|
+
? input.cache.nodesOnScreen(v, kept, input.nodes, scale)
|
|
1739
|
+
: cullNodes(v, kept, input.nodes, scale)) {
|
|
1740
|
+
// inflated by the margin its handles and grips can ink outside the box —
|
|
1741
|
+
// the same margin every invalidate grew by, so the two agree
|
|
1742
|
+
if (clip && !rectsOverlap(inflateRect(rect, CULL_MARGIN), clip)) continue;
|
|
1743
|
+
|
|
1744
|
+
const selected = source.node.selected ?? false;
|
|
1745
|
+
const hovered = hover.nodeId === source.node.id;
|
|
1746
|
+
const anchors = anchorsOf(source).map((anchor) => {
|
|
1747
|
+
const s = toScreen(v, anchor);
|
|
1748
|
+
return { ...anchor, x: s.x, y: s.y };
|
|
1749
|
+
});
|
|
1750
|
+
|
|
1751
|
+
const item: SceneNodeItem = {
|
|
1752
|
+
id: source.node.id,
|
|
1753
|
+
rect,
|
|
1754
|
+
selected,
|
|
1755
|
+
hovered,
|
|
1756
|
+
ink: [],
|
|
1757
|
+
handles: [],
|
|
1758
|
+
grips: [],
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
if (source.type?.paint) {
|
|
1762
|
+
// Never described: a type that draws its own body is drawing whatever
|
|
1763
|
+
// it likes, in an order only it knows.
|
|
1764
|
+
item.custom = { type: source.type, node: source.node, anchors };
|
|
1765
|
+
} else {
|
|
1766
|
+
item.card = buildCard(input, source, rect, selected, hovered);
|
|
1767
|
+
item.ink = buildCardInk(input, source, rect);
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
if (source.connectable && (v.zoom >= HANDLE_ZOOM || hovered)) {
|
|
1771
|
+
item.handles = buildHandles(input, anchors);
|
|
1772
|
+
}
|
|
1773
|
+
item.grips = buildGrips(input, source, rect);
|
|
1774
|
+
out.push(item);
|
|
1775
|
+
}
|
|
1776
|
+
return out;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
function buildCard(
|
|
1780
|
+
input: SceneInput,
|
|
1781
|
+
source: SceneNodeSource,
|
|
1782
|
+
rect: FlowRect,
|
|
1783
|
+
selected: boolean,
|
|
1784
|
+
hovered: boolean,
|
|
1785
|
+
): { shape: SceneRect; accent?: SceneRect } {
|
|
1786
|
+
const { viewport: v, palette } = input;
|
|
1787
|
+
const style = source.node.style;
|
|
1788
|
+
const radius = Math.round((style?.borderRadius ?? 6) * v.zoom);
|
|
1789
|
+
const border = selected
|
|
1790
|
+
? palette.accent
|
|
1791
|
+
: hovered
|
|
1792
|
+
? tint(palette.accent, 0.55)
|
|
1793
|
+
: (style?.borderColor ?? palette.nodeBorder);
|
|
1794
|
+
const shape: SceneRect = {
|
|
1795
|
+
rect,
|
|
1796
|
+
radius,
|
|
1797
|
+
fill: style?.background ?? palette.nodeBackground,
|
|
1798
|
+
stroke: border,
|
|
1799
|
+
lineWidth: Math.max(
|
|
1800
|
+
1,
|
|
1801
|
+
Math.round((style?.borderWidth ?? (selected ? 2 : 1)) * v.zoom),
|
|
1802
|
+
),
|
|
1803
|
+
};
|
|
1804
|
+
if (!style?.accent) return { shape };
|
|
1805
|
+
return {
|
|
1806
|
+
shape,
|
|
1807
|
+
// Inset past the rounded corners instead of clipped to them: a
|
|
1808
|
+
// non-rectangular clip forfeits ntk's rounded-box fast path for every
|
|
1809
|
+
// fill under it — measured as a pixmap create/free and a trapezoid pass
|
|
1810
|
+
// per card per repaint.
|
|
1811
|
+
accent: {
|
|
1812
|
+
rect: {
|
|
1813
|
+
x: rect.x + Math.max(1, v.zoom),
|
|
1814
|
+
y: rect.y + radius,
|
|
1815
|
+
width: Math.max(2, 3 * v.zoom),
|
|
1816
|
+
height: rect.height - radius * 2,
|
|
1817
|
+
},
|
|
1818
|
+
radius: 0,
|
|
1819
|
+
fill: style.accent,
|
|
1820
|
+
},
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
function buildCardInk(
|
|
1825
|
+
input: SceneInput,
|
|
1826
|
+
source: SceneNodeSource,
|
|
1827
|
+
rect: FlowRect,
|
|
1828
|
+
): (SceneText | SceneRule)[] {
|
|
1829
|
+
const { viewport: v, palette } = input;
|
|
1830
|
+
if (v.zoom < LABEL_ZOOM) return [];
|
|
1831
|
+
const style = source.node.style;
|
|
1832
|
+
const header = source.mounted ? source.header : 0;
|
|
1833
|
+
const data = source.node.data as FlowNodeData | undefined;
|
|
1834
|
+
const label = data?.label ?? source.node.id;
|
|
1835
|
+
const description = data?.description;
|
|
1836
|
+
const color = style?.color ?? palette.text;
|
|
1837
|
+
const padX = NODE_PAD_X * v.zoom;
|
|
1838
|
+
const centreX = rect.x + rect.width / 2;
|
|
1839
|
+
const maxWidth = Math.max(8, rect.width - padX * 2);
|
|
1840
|
+
const showDescription = Boolean(description) && v.zoom >= DESC_ZOOM;
|
|
1841
|
+
|
|
1842
|
+
if (header > 0) {
|
|
1843
|
+
// The title bar of a node whose body is somebody else's: left-aligned,
|
|
1844
|
+
// with a hairline under it so the strip reads as the thing to grab.
|
|
1845
|
+
const band = header * v.zoom;
|
|
1846
|
+
return [
|
|
1847
|
+
{
|
|
1848
|
+
kind: 'text',
|
|
1849
|
+
text: label,
|
|
1850
|
+
x: rect.x + padX,
|
|
1851
|
+
y: rect.y + band / 2,
|
|
1852
|
+
size: NODE_LABEL_SIZE * v.zoom,
|
|
1853
|
+
weight: 'bold',
|
|
1854
|
+
color,
|
|
1855
|
+
baseline: 'middle',
|
|
1856
|
+
maxWidth,
|
|
1857
|
+
},
|
|
1858
|
+
{
|
|
1859
|
+
kind: 'rule',
|
|
1860
|
+
points: [
|
|
1861
|
+
{ x: rect.x + 1, y: rect.y + band },
|
|
1862
|
+
{ x: rect.x + rect.width - 1, y: rect.y + band },
|
|
1863
|
+
],
|
|
1864
|
+
color: palette.nodeBorder,
|
|
1865
|
+
lineWidth: 1,
|
|
1866
|
+
},
|
|
1867
|
+
];
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
if (!showDescription) {
|
|
1871
|
+
return [
|
|
1872
|
+
{
|
|
1873
|
+
kind: 'text',
|
|
1874
|
+
text: label,
|
|
1875
|
+
x: centreX,
|
|
1876
|
+
y: rect.y + rect.height / 2,
|
|
1877
|
+
size: NODE_LABEL_SIZE * v.zoom,
|
|
1878
|
+
weight: 'bold',
|
|
1879
|
+
color,
|
|
1880
|
+
align: 'center',
|
|
1881
|
+
baseline: 'middle',
|
|
1882
|
+
maxWidth,
|
|
1883
|
+
},
|
|
1884
|
+
];
|
|
1885
|
+
}
|
|
1886
|
+
const top = rect.y + NODE_PAD_Y * v.zoom;
|
|
1887
|
+
return [
|
|
1888
|
+
{
|
|
1889
|
+
kind: 'text',
|
|
1890
|
+
text: label,
|
|
1891
|
+
x: centreX,
|
|
1892
|
+
y: top,
|
|
1893
|
+
size: NODE_LABEL_SIZE * v.zoom,
|
|
1894
|
+
weight: 'bold',
|
|
1895
|
+
color,
|
|
1896
|
+
align: 'center',
|
|
1897
|
+
maxWidth,
|
|
1898
|
+
},
|
|
1899
|
+
{
|
|
1900
|
+
kind: 'text',
|
|
1901
|
+
text: description!,
|
|
1902
|
+
x: centreX,
|
|
1903
|
+
y: top + NODE_LABEL_SIZE * 1.35 * v.zoom,
|
|
1904
|
+
size: NODE_DESC_SIZE * v.zoom,
|
|
1905
|
+
color: palette.dim,
|
|
1906
|
+
align: 'center',
|
|
1907
|
+
maxWidth,
|
|
1908
|
+
},
|
|
1909
|
+
];
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
function buildHandles(
|
|
1913
|
+
input: SceneInput,
|
|
1914
|
+
anchors: readonly HandleAnchor[],
|
|
1915
|
+
): SceneHandle[] {
|
|
1916
|
+
const { viewport: v, palette, hover, connection } = input;
|
|
1917
|
+
const radius = handleRadius(v.zoom);
|
|
1918
|
+
const lineWidth = Math.max(1, 1.5 * v.zoom);
|
|
1919
|
+
return anchors.map((anchor) => {
|
|
1920
|
+
const active =
|
|
1921
|
+
sameHandle(hover.handle, anchor) ||
|
|
1922
|
+
sameHandle(connection?.to ?? null, anchor) ||
|
|
1923
|
+
sameHandle(connection?.from ?? null, anchor);
|
|
1924
|
+
const handle: SceneHandle = {
|
|
1925
|
+
at: { x: anchor.x, y: anchor.y },
|
|
1926
|
+
radius: active ? radius * 1.4 : radius,
|
|
1927
|
+
fill: active ? palette.accent : palette.nodeBackground,
|
|
1928
|
+
stroke: active ? palette.accent : palette.handle,
|
|
1929
|
+
lineWidth,
|
|
1930
|
+
};
|
|
1931
|
+
if (anchor.label && v.zoom >= DESC_ZOOM) {
|
|
1932
|
+
const outside = anchor.position === 'left' || anchor.position === 'top';
|
|
1933
|
+
handle.label = {
|
|
1934
|
+
kind: 'text',
|
|
1935
|
+
text: anchor.label,
|
|
1936
|
+
x:
|
|
1937
|
+
anchor.x +
|
|
1938
|
+
(anchor.position === 'left'
|
|
1939
|
+
? -radius - 4 * v.zoom
|
|
1940
|
+
: radius + 4 * v.zoom),
|
|
1941
|
+
y: anchor.y,
|
|
1942
|
+
size: 10 * v.zoom,
|
|
1943
|
+
color: palette.dim,
|
|
1944
|
+
align: outside ? 'right' : 'left',
|
|
1945
|
+
baseline: 'middle',
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
return handle;
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
function buildGrips(
|
|
1953
|
+
input: SceneInput,
|
|
1954
|
+
source: SceneNodeSource,
|
|
1955
|
+
rect: FlowRect,
|
|
1956
|
+
): SceneRect[] {
|
|
1957
|
+
if (source.grips.length === 0) return [];
|
|
1958
|
+
const { viewport: v, palette } = input;
|
|
1959
|
+
const size = Math.max(4, RESIZE_GRIP * 2 * v.zoom);
|
|
1960
|
+
return source.grips.map((dir) => {
|
|
1961
|
+
const at = gripPoint(rect, dir);
|
|
1962
|
+
return {
|
|
1963
|
+
rect: {
|
|
1964
|
+
x: at.x - size / 2,
|
|
1965
|
+
y: at.y - size / 2,
|
|
1966
|
+
width: size,
|
|
1967
|
+
height: size,
|
|
1968
|
+
},
|
|
1969
|
+
radius: 1,
|
|
1970
|
+
fill: palette.nodeBackground,
|
|
1971
|
+
stroke: palette.accent,
|
|
1972
|
+
lineWidth: 1.5,
|
|
1973
|
+
};
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* The line a connection gesture draws, routed. Exported because the element
|
|
1979
|
+
* claims damage for it between frames and the two must be the same curve —
|
|
1980
|
+
* a box drawn from a second derivation is a box that leaves crumbs.
|
|
1981
|
+
*/
|
|
1982
|
+
export function connectionPath(
|
|
1983
|
+
v: Viewport,
|
|
1984
|
+
source: SceneConnectionSource,
|
|
1985
|
+
): XYPosition[] {
|
|
1986
|
+
const from = toScreen(v, source.from);
|
|
1987
|
+
const to = toScreen(v, source.to ?? source.pointer);
|
|
1988
|
+
const toPosition =
|
|
1989
|
+
source.to?.position ??
|
|
1990
|
+
(source.from.position === 'left'
|
|
1991
|
+
? 'right'
|
|
1992
|
+
: source.from.position === 'right'
|
|
1993
|
+
? 'left'
|
|
1994
|
+
: source.from.position === 'top'
|
|
1995
|
+
? 'bottom'
|
|
1996
|
+
: 'top');
|
|
1997
|
+
return edgePath(
|
|
1998
|
+
'bezier',
|
|
1999
|
+
{ x: from.x, y: from.y, position: source.from.position },
|
|
2000
|
+
{ x: to.x, y: to.y, position: toPosition },
|
|
2001
|
+
{
|
|
2002
|
+
stepOffset: EDGE_STEP_OFFSET * v.zoom,
|
|
2003
|
+
radius: 8 * v.zoom,
|
|
2004
|
+
scale: v.zoom,
|
|
2005
|
+
},
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
function buildConnection(input: SceneInput): SceneConnection | null {
|
|
2010
|
+
const { palette, connection } = input;
|
|
2011
|
+
if (!connection) return null;
|
|
2012
|
+
const v = screenViewport(input.viewport, input.pane);
|
|
2013
|
+
const to = toScreen(v, connection.to ?? connection.pointer);
|
|
2014
|
+
const invalid = connection.to != null && !connection.valid;
|
|
2015
|
+
const color = invalid ? palette.dim : palette.accent;
|
|
2016
|
+
return {
|
|
2017
|
+
points: connectionPath(v, connection),
|
|
2018
|
+
stroke: color,
|
|
2019
|
+
lineWidth: Math.max(1.5, 2 * v.zoom),
|
|
2020
|
+
dash:
|
|
2021
|
+
connection.to && connection.valid ? undefined : [5 * v.zoom, 4 * v.zoom],
|
|
2022
|
+
tip: { at: to, radius: handleRadius(v.zoom), fill: color },
|
|
2023
|
+
};
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function buildMiniMap(
|
|
2027
|
+
input: SceneInput,
|
|
2028
|
+
map: SceneMiniMapSource,
|
|
2029
|
+
clip: FlowRect | null | undefined,
|
|
2030
|
+
): SceneMiniMap {
|
|
2031
|
+
const { viewport: v, pane, palette } = input;
|
|
2032
|
+
const ox = map.panel.x + (map.panel.width - map.bounds.width * map.scale) / 2;
|
|
2033
|
+
const oy =
|
|
2034
|
+
map.panel.y + (map.panel.height - map.bounds.height * map.scale) / 2;
|
|
2035
|
+
const place = (p: XYPosition): XYPosition => ({
|
|
2036
|
+
x: ox + (p.x - map.bounds.x) * map.scale,
|
|
2037
|
+
y: oy + (p.y - map.bounds.y) * map.scale,
|
|
2038
|
+
});
|
|
2039
|
+
// A pass over a corner of the minimap — a node a drag moves claims its
|
|
2040
|
+
// places there and no more — builds the nodes that reach its clip. Every
|
|
2041
|
+
// node is still walked, for its run; only the ones kept are made.
|
|
2042
|
+
const reach = clip ? inflateRect(clip, MINIMAP_BLEED) : null;
|
|
2043
|
+
const colour = map.nodeColor;
|
|
2044
|
+
const nodes: SceneMiniMapNode[] = [];
|
|
2045
|
+
let run = 0;
|
|
2046
|
+
let runFill: string | null = null;
|
|
2047
|
+
let runStart = 0;
|
|
2048
|
+
let runLength = 0;
|
|
2049
|
+
const closeRun = (): void => {
|
|
2050
|
+
if (runLength <= 1) return;
|
|
2051
|
+
for (let k = runStart; k < nodes.length; k++) nodes[k].batched = true;
|
|
2052
|
+
};
|
|
2053
|
+
for (const source of input.all) {
|
|
2054
|
+
if (source.node.hidden) continue;
|
|
2055
|
+
const fill =
|
|
2056
|
+
typeof colour === 'function'
|
|
2057
|
+
? colour(source.node as FlowNode<never>)
|
|
2058
|
+
: (colour ??
|
|
2059
|
+
(source.node.selected ? palette.accent : palette.nodeBorder));
|
|
2060
|
+
// a plain square of the run's colour joins it, as `paintPanels` groups
|
|
2061
|
+
if (runLength === 0 || fill == null || fill !== runFill) {
|
|
2062
|
+
closeRun();
|
|
2063
|
+
run++;
|
|
2064
|
+
runFill = fill ?? null;
|
|
2065
|
+
runStart = nodes.length;
|
|
2066
|
+
runLength = 0;
|
|
2067
|
+
}
|
|
2068
|
+
runLength++;
|
|
2069
|
+
// `miniMapPlace`, written out so that a node the pass does not reach
|
|
2070
|
+
// makes nothing
|
|
2071
|
+
const r = source.rect;
|
|
2072
|
+
const x = ox + (r.x - map.bounds.x) * map.scale;
|
|
2073
|
+
const y = oy + (r.y - map.bounds.y) * map.scale;
|
|
2074
|
+
const width = Math.max(1, r.width * map.scale);
|
|
2075
|
+
const height = Math.max(1, r.height * map.scale);
|
|
2076
|
+
if (
|
|
2077
|
+
reach &&
|
|
2078
|
+
(x >= reach.x + reach.width ||
|
|
2079
|
+
reach.x >= x + width ||
|
|
2080
|
+
y >= reach.y + reach.height ||
|
|
2081
|
+
reach.y >= y + height)
|
|
2082
|
+
) {
|
|
2083
|
+
continue;
|
|
2084
|
+
}
|
|
2085
|
+
nodes.push({
|
|
2086
|
+
rect: { x, y, width, height },
|
|
2087
|
+
radius: 0,
|
|
2088
|
+
fill,
|
|
2089
|
+
run,
|
|
2090
|
+
batched: false,
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
closeRun();
|
|
2094
|
+
const view = place({ x: -v.x / v.zoom, y: -v.y / v.zoom });
|
|
2095
|
+
return {
|
|
2096
|
+
panel: {
|
|
2097
|
+
rect: map.panel,
|
|
2098
|
+
radius: 4,
|
|
2099
|
+
fill: tint(palette.surface, 0.92),
|
|
2100
|
+
stroke: palette.surfaceBorder,
|
|
2101
|
+
lineWidth: 1,
|
|
2102
|
+
},
|
|
2103
|
+
nodes,
|
|
2104
|
+
// The viewport, as an outline over a wash on everything outside it —
|
|
2105
|
+
// cheaper than four mask rectangles and reads the same.
|
|
2106
|
+
view: {
|
|
2107
|
+
rect: {
|
|
2108
|
+
x: view.x,
|
|
2109
|
+
y: view.y,
|
|
2110
|
+
width: (pane.width / v.zoom) * map.scale,
|
|
2111
|
+
height: (pane.height / v.zoom) * map.scale,
|
|
2112
|
+
},
|
|
2113
|
+
radius: 2,
|
|
2114
|
+
fill: map.maskColor ?? tint(palette.accent, 0.1),
|
|
2115
|
+
stroke: palette.accent,
|
|
2116
|
+
lineWidth: 1,
|
|
2117
|
+
},
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
function buildControls(input: SceneInput): SceneControls {
|
|
2122
|
+
const { palette, controls } = input;
|
|
2123
|
+
const first = controls[0].rect;
|
|
2124
|
+
const last = controls[controls.length - 1].rect;
|
|
2125
|
+
const glyphs: SceneGlyph[] = [];
|
|
2126
|
+
const rules: SceneRule[] = [];
|
|
2127
|
+
for (let i = 0; i < controls.length; i++) {
|
|
2128
|
+
const { rect, action } = controls[i];
|
|
2129
|
+
if (i > 0) {
|
|
2130
|
+
rules.push({
|
|
2131
|
+
kind: 'rule',
|
|
2132
|
+
points: [
|
|
2133
|
+
{ x: rect.x + 4, y: rect.y },
|
|
2134
|
+
{ x: rect.x + rect.width - 4, y: rect.y },
|
|
2135
|
+
],
|
|
2136
|
+
color: palette.surfaceBorder,
|
|
2137
|
+
lineWidth: 1,
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
const cx = rect.x + rect.width / 2;
|
|
2141
|
+
const cy = rect.y + rect.height / 2;
|
|
2142
|
+
const arm = 5;
|
|
2143
|
+
const runs: XYPosition[][] = [];
|
|
2144
|
+
if (action === 'in' || action === 'out') {
|
|
2145
|
+
runs.push([
|
|
2146
|
+
{ x: cx - arm, y: cy },
|
|
2147
|
+
{ x: cx + arm, y: cy },
|
|
2148
|
+
]);
|
|
2149
|
+
if (action === 'in') {
|
|
2150
|
+
runs.push([
|
|
2151
|
+
{ x: cx, y: cy - arm },
|
|
2152
|
+
{ x: cx, y: cy + arm },
|
|
2153
|
+
]);
|
|
2154
|
+
}
|
|
2155
|
+
} else {
|
|
2156
|
+
// a frame with its sides opened out: "fit what is there into this"
|
|
2157
|
+
const a = 5;
|
|
2158
|
+
runs.push(
|
|
2159
|
+
[
|
|
2160
|
+
{ x: cx - a, y: cy - a + 3 },
|
|
2161
|
+
{ x: cx - a, y: cy - a },
|
|
2162
|
+
{ x: cx - a + 3, y: cy - a },
|
|
2163
|
+
],
|
|
2164
|
+
[
|
|
2165
|
+
{ x: cx + a - 3, y: cy - a },
|
|
2166
|
+
{ x: cx + a, y: cy - a },
|
|
2167
|
+
{ x: cx + a, y: cy - a + 3 },
|
|
2168
|
+
],
|
|
2169
|
+
[
|
|
2170
|
+
{ x: cx + a, y: cy + a - 3 },
|
|
2171
|
+
{ x: cx + a, y: cy + a },
|
|
2172
|
+
{ x: cx + a - 3, y: cy + a },
|
|
2173
|
+
],
|
|
2174
|
+
[
|
|
2175
|
+
{ x: cx - a + 3, y: cy + a },
|
|
2176
|
+
{ x: cx - a, y: cy + a },
|
|
2177
|
+
{ x: cx - a, y: cy + a - 3 },
|
|
2178
|
+
],
|
|
2179
|
+
);
|
|
2180
|
+
}
|
|
2181
|
+
glyphs.push({ runs, color: palette.text, lineWidth: 1.5 });
|
|
2182
|
+
}
|
|
2183
|
+
return {
|
|
2184
|
+
panel: {
|
|
2185
|
+
rect: {
|
|
2186
|
+
x: first.x,
|
|
2187
|
+
y: first.y,
|
|
2188
|
+
width: first.width,
|
|
2189
|
+
height: last.y + last.height - first.y,
|
|
2190
|
+
},
|
|
2191
|
+
radius: 4,
|
|
2192
|
+
fill: tint(palette.surface, 0.94),
|
|
2193
|
+
stroke: palette.surfaceBorder,
|
|
2194
|
+
lineWidth: 1,
|
|
2195
|
+
},
|
|
2196
|
+
rules,
|
|
2197
|
+
glyphs,
|
|
2198
|
+
};
|
|
2199
|
+
}
|