@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
package/dist/html/node.js
CHANGED
|
@@ -39,19 +39,25 @@
|
|
|
39
39
|
import { registerElement, registeredElements } from 'react-x11/host';
|
|
40
40
|
import { Node } from 'react-x11/node';
|
|
41
41
|
import { codePointAtOffset, codeUnitOffsets } from '../internal/text.js';
|
|
42
|
-
import { attr, HtmlSource, isElement, tagOf } from './dom.js';
|
|
42
|
+
import { attr, HtmlSource, imageUrlOf, isElement, tagOf } from './dom.js';
|
|
43
43
|
import { Cascade } from './css/cascade.js';
|
|
44
|
-
import { parseStylesheet } from './css/parse.js';
|
|
44
|
+
import { mediaMatches, parseStylesheet } from './css/parse.js';
|
|
45
45
|
import { uaStylesheet } from './css/ua.js';
|
|
46
|
-
import { buildBoxes } from './layout/boxes.js';
|
|
46
|
+
import { BOX_RAISES, buildBoxes, CONTENT_IMAGES, LINE_BOX_RAISES, SHIFTED_LINES, } from './layout/boxes.js';
|
|
47
47
|
import { layoutDocument } from './layout/block.js';
|
|
48
|
+
import { TextLayoutCache } from './layout/cache.js';
|
|
49
|
+
import { shapingSafe } from './layout/shaping.js';
|
|
50
|
+
import { SurfaceCache } from './surfaces.js';
|
|
51
|
+
import { faceExtentOf, inlineDecoration, runFor } from './layout/inline.js';
|
|
48
52
|
// Through the inline module rather than a second cache: the offsets table for
|
|
49
53
|
// a layout is built once, on the first selection that needs it.
|
|
50
|
-
import { layoutOffsets as layoutOffsetsOf } from './layout/inline.js';
|
|
54
|
+
import { documentOffsetOf, layoutOffsetOf, layoutOffsets as layoutOffsetsOf, } from './layout/inline.js';
|
|
51
55
|
import { lineBands as bandsFor } from '../richtext/runs.js';
|
|
52
|
-
import { paintDocument, queryChildIndex } from './paint.js';
|
|
56
|
+
import { clipsOverflow, containingBlockOf, hasRect, holds, holdsAbsolute, paintDocument, queryChildIndex, } from './paint.js';
|
|
53
57
|
import { controlRectsOf, measureControl } from './controls.js';
|
|
54
58
|
import { ResourceStore } from './resources.js';
|
|
59
|
+
import { WebFonts } from './fonts.js';
|
|
60
|
+
import { resolveUrl, UrlResolver } from './url.js';
|
|
55
61
|
/** The element name — registration key, `node.kind` and JSX tag alike. */
|
|
56
62
|
export const ELEMENT = 'htmlview';
|
|
57
63
|
export function registerHtmlView() {
|
|
@@ -62,10 +68,35 @@ export function registerHtmlView() {
|
|
|
62
68
|
// `source` and `look` are this element's own vocabulary and neither is a
|
|
63
69
|
// style name today; declaring them keeps the DEV flat-style-prop
|
|
64
70
|
// assertion honest if core's vocabulary grows underneath us.
|
|
65
|
-
semanticNames: [
|
|
71
|
+
semanticNames: [
|
|
72
|
+
'source',
|
|
73
|
+
'look',
|
|
74
|
+
'stylesheet',
|
|
75
|
+
'charset',
|
|
76
|
+
'complete',
|
|
77
|
+
'baseUrl',
|
|
78
|
+
],
|
|
66
79
|
childrenAllowed: false,
|
|
67
80
|
});
|
|
68
81
|
}
|
|
82
|
+
/** How many widths' sizes a document keeps (`HtmlViewNode._sizeAt`): the
|
|
83
|
+
* two a frame of a resize asks, and a little slack for a drag that turns
|
|
84
|
+
* back. */
|
|
85
|
+
const SIZES_KEPT = 4;
|
|
86
|
+
/**
|
|
87
|
+
* A size in the whole pixels core lays out in, rounded up — less the float
|
|
88
|
+
* noise a sum of Yoga's single-precision positions carries: a page exactly
|
|
89
|
+
* `100vh` tall came to 737.0000076 under a 737-pixel viewport, and a
|
|
90
|
+
* rounding that took it for 738 scrolled it by a pixel under a scrollbar.
|
|
91
|
+
*/
|
|
92
|
+
function wholePixels(n) {
|
|
93
|
+
return Math.max(0, Math.ceil(n - 1 / 64));
|
|
94
|
+
}
|
|
95
|
+
/** How deep `@import`s are followed: an import in an import in an import is
|
|
96
|
+
* a stylesheet; sixteen of them is a loop that changes its URL each time. */
|
|
97
|
+
const MAX_IMPORT_DEPTH = 16;
|
|
98
|
+
/** A scheme at the start: an absolute URL, a base that means something. */
|
|
99
|
+
const ABSOLUTE_URL = /^[a-zA-Z][a-zA-Z0-9+.-]*:/;
|
|
69
100
|
/** What changed, and therefore how far back up the pipeline to go. */
|
|
70
101
|
var Stale;
|
|
71
102
|
(function (Stale) {
|
|
@@ -77,16 +108,43 @@ var Stale;
|
|
|
77
108
|
})(Stale || (Stale = {}));
|
|
78
109
|
export class HtmlViewNode extends Node {
|
|
79
110
|
_source = new HtmlSource();
|
|
111
|
+
/** Where the document's relative URLs resolve: its `<base href>` against
|
|
112
|
+
* the `baseUrl` prop, or the prop, or nowhere (`url.ts`). */
|
|
113
|
+
_urls = new UrlResolver();
|
|
80
114
|
_resources;
|
|
115
|
+
/** The families the document's `@font-face` rules declare (`fonts.ts`). */
|
|
116
|
+
_webFonts;
|
|
117
|
+
/** The sheets the last restyle read, and the cascade built from them. */
|
|
118
|
+
_sheetsRead = null;
|
|
119
|
+
/** Blurred shadows, drawn once each. */
|
|
120
|
+
_shadowCache = null;
|
|
81
121
|
_cascade = null;
|
|
82
122
|
_tree = null;
|
|
123
|
+
/** The faces `_warmFaces` has asked the font matcher for, and of which
|
|
124
|
+
* fonts. */
|
|
125
|
+
_warmedFaces = new Set();
|
|
126
|
+
_warmedFor = null;
|
|
83
127
|
_stale = Stale.Everything;
|
|
84
128
|
/** The width the document was last laid out at. Not `_laidOutAt`: core's
|
|
85
129
|
* `Node` has a method of that name, which a field would hide. */
|
|
86
130
|
_laidOutWidth = -1;
|
|
87
131
|
_mediaBand = -1;
|
|
132
|
+
/** The viewport the box tree's styles were computed at, for the ones
|
|
133
|
+
* that read it (`vw`, `vh`). */
|
|
134
|
+
_styledWidth = -1;
|
|
135
|
+
_styledHeight = -1;
|
|
88
136
|
_documentHeight = 0;
|
|
89
137
|
_documentWidth = 0;
|
|
138
|
+
/** The viewport height the document was last laid out under, and whether
|
|
139
|
+
* that layout read it (`LayoutResult.readsViewportHeight`). */
|
|
140
|
+
_laidOutUnder = -1;
|
|
141
|
+
_layoutReadsViewport = false;
|
|
142
|
+
/** Whether core is asking for this element's size right now — inside
|
|
143
|
+
* its layout pass, where a node must not ask to be measured again. */
|
|
144
|
+
_measuring = false;
|
|
145
|
+
/** What the document came to at the widths it was last laid out at, while
|
|
146
|
+
* nothing a layout reads has changed (`_sizeAt`). */
|
|
147
|
+
_sizes = new Map();
|
|
90
148
|
_textPoints = null;
|
|
91
149
|
/** Whether code points and code units are the same index — true unless
|
|
92
150
|
* the text carries surrogate pairs. null until checked. */
|
|
@@ -97,12 +155,23 @@ export class HtmlViewNode extends Node {
|
|
|
97
155
|
_reportedDomRevision = -1;
|
|
98
156
|
constructor(props, app) {
|
|
99
157
|
super(ELEMENT, props, app);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
//
|
|
158
|
+
const ask = (request) => this._props().onResource?.(request) ?? null;
|
|
159
|
+
this._resources = new ResourceStore(ask, (what) => {
|
|
160
|
+
// A late stylesheet is a new cascade: its rules, what it imports,
|
|
161
|
+
// the faces it declares. A late image changes intrinsic sizes, so
|
|
162
|
+
// the box tree is what has to be rebuilt — not merely repainted.
|
|
163
|
+
// Either arriving after first paint is the ordinary case, not an
|
|
164
|
+
// error path: a host on a network answers every request that way.
|
|
165
|
+
this._invalidate(what === 'stylesheet' ? Stale.Style : Stale.Boxes);
|
|
166
|
+
}, this._urls);
|
|
167
|
+
this._webFonts = new WebFonts(app, ask, () => {
|
|
168
|
+
// A face arrived: the family lists change, so the styles do, and
|
|
169
|
+
// every text layout kept from before was set in the face it
|
|
170
|
+
// replaces — under the same list, where a family of the document's
|
|
171
|
+
// had loaded one weight and now has another.
|
|
172
|
+
this._layouts = null;
|
|
104
173
|
this._invalidate(Stale.Boxes);
|
|
105
|
-
});
|
|
174
|
+
}, 'sans-serif');
|
|
106
175
|
this._read();
|
|
107
176
|
}
|
|
108
177
|
_props() {
|
|
@@ -183,8 +252,24 @@ export class HtmlViewNode extends Node {
|
|
|
183
252
|
props.onDocument?.(this._source.document);
|
|
184
253
|
this._reportedDomRevision = props.domRevision ?? 0;
|
|
185
254
|
}
|
|
255
|
+
this._updateBase();
|
|
186
256
|
this._sweep();
|
|
187
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* The document's base URL: its first `<base href>`, resolved against the
|
|
260
|
+
* `baseUrl` prop, or the prop — and only an absolute one, since a relative
|
|
261
|
+
* base resolves nothing. Everything resolved against the old one is
|
|
262
|
+
* stale when it moves, the sheets' URLs with it, so the cascade is.
|
|
263
|
+
*/
|
|
264
|
+
_updateBase() {
|
|
265
|
+
const given = this._props().baseUrl || null;
|
|
266
|
+
const href = this._source.facts().base;
|
|
267
|
+
let base = href ? resolveUrl(href, given) : given;
|
|
268
|
+
if (base && !ABSOLUTE_URL.test(base))
|
|
269
|
+
base = null;
|
|
270
|
+
if (this._urls.setBase(base))
|
|
271
|
+
this._invalidate(Stale.Style);
|
|
272
|
+
}
|
|
188
273
|
/**
|
|
189
274
|
* Hand the document's own declarations to the host: every `<script>` once,
|
|
190
275
|
* and every resource that has not been asked for.
|
|
@@ -213,7 +298,7 @@ export class HtmlViewNode extends Node {
|
|
|
213
298
|
}
|
|
214
299
|
for (const el of facts.resources) {
|
|
215
300
|
const tag = tagOf(el);
|
|
216
|
-
const url = tag === 'link' ? attr(el, 'href') :
|
|
301
|
+
const url = tag === 'link' ? attr(el, 'href') : imageUrlOf(el);
|
|
217
302
|
if (!url)
|
|
218
303
|
continue;
|
|
219
304
|
this._resources.request({
|
|
@@ -223,75 +308,356 @@ export class HtmlViewNode extends Node {
|
|
|
223
308
|
});
|
|
224
309
|
}
|
|
225
310
|
}
|
|
311
|
+
/**
|
|
312
|
+
* Ask for every `background-image` the styles name. Known only once the
|
|
313
|
+
* cascade has run, where an `<img>` is known from the markup; the store
|
|
314
|
+
* asks once a URL, so a tree built again asks nothing new.
|
|
315
|
+
*/
|
|
316
|
+
_requestBackgrounds(tree) {
|
|
317
|
+
for (const box of tree.backgrounds) {
|
|
318
|
+
if (!box.el)
|
|
319
|
+
continue;
|
|
320
|
+
// each layer's, where there is more than one
|
|
321
|
+
for (const url of box.style.backgroundImages ?? [
|
|
322
|
+
box.style.backgroundImage,
|
|
323
|
+
]) {
|
|
324
|
+
if (typeof url === 'string') {
|
|
325
|
+
this._resources.request({ url, kind: 'image', element: box.el });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const border = box.style.borderImage.source;
|
|
329
|
+
if (typeof border === 'string') {
|
|
330
|
+
this._resources.request({
|
|
331
|
+
url: border,
|
|
332
|
+
kind: 'image',
|
|
333
|
+
element: box.el,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// and every image generated content names, which is only known there
|
|
338
|
+
// too
|
|
339
|
+
for (const { url, element } of tree.contentImages) {
|
|
340
|
+
this._resources.request({ url, kind: 'image', element });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/** Whether an image generated content names arrived as it was asked for,
|
|
344
|
+
* the tree built without its size: a host that answers at once is told
|
|
345
|
+
* nothing later, where an `<img>` is asked for before the build. */
|
|
346
|
+
_contentImagesArrived(tree) {
|
|
347
|
+
for (const { url, sized } of tree.contentImages) {
|
|
348
|
+
if (!sized && this._resources.imageSize(url))
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Ask the font matcher for the faces the document's text is set in, as
|
|
355
|
+
* soon as its boxes say which and while its layout is still ahead. A face
|
|
356
|
+
* nothing had warmed was a synchronous fc-match inside that layout: the
|
|
357
|
+
* benchmark report's `th`, at 600, waited 38 ms before its first paint.
|
|
358
|
+
* One child answers every face a call names, off the event loop (ntk's
|
|
359
|
+
* `FontManager#prewarm`), and a layout reaching a face still on its way
|
|
360
|
+
* takes the answer rather than asking again. Each face is asked once, by
|
|
361
|
+
* the family, weight and style the layout hands the engine.
|
|
362
|
+
*/
|
|
363
|
+
_warmFaces(tree) {
|
|
364
|
+
const fonts = this._fonts();
|
|
365
|
+
if (typeof fonts?.prewarm !== 'function')
|
|
366
|
+
return;
|
|
367
|
+
if (this._warmedFor !== fonts) {
|
|
368
|
+
this._warmedFor = fonts;
|
|
369
|
+
this._warmedFaces.clear();
|
|
370
|
+
}
|
|
371
|
+
let faces = null;
|
|
372
|
+
for (const style of tree.textStyles) {
|
|
373
|
+
const key = `${style.fontFamily}|${style.fontWeight}|${style.fontStyle}`;
|
|
374
|
+
if (this._warmedFaces.has(key))
|
|
375
|
+
continue;
|
|
376
|
+
this._warmedFaces.add(key);
|
|
377
|
+
faces ??= new Map();
|
|
378
|
+
let named = faces.get(style.fontFamily);
|
|
379
|
+
if (!named)
|
|
380
|
+
faces.set(style.fontFamily, (named = []));
|
|
381
|
+
named.push({ weight: style.fontWeight, style: style.fontStyle });
|
|
382
|
+
}
|
|
383
|
+
if (faces)
|
|
384
|
+
for (const [family, named] of faces)
|
|
385
|
+
fonts.prewarm(family, named);
|
|
386
|
+
}
|
|
226
387
|
/** Rebuild the cascade — the document's sheets plus the host's. */
|
|
227
388
|
_restyle(width) {
|
|
228
389
|
const props = this._props();
|
|
229
390
|
const look = this._deviceLook();
|
|
230
|
-
const
|
|
231
|
-
|
|
391
|
+
const documentBase = this._urls.base;
|
|
392
|
+
// What the sheets are read from, in order: a `<style>`'s text or a
|
|
393
|
+
// fetched `<link>`'s, and after them the host's — each with the URL its
|
|
394
|
+
// own relative URLs resolve against: the document's for a `<style>`,
|
|
395
|
+
// the sheet's own for a `<link>`.
|
|
396
|
+
const read = [];
|
|
232
397
|
for (const ref of this._source.facts().sheets) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
398
|
+
// A sheet handed over as bytes that names no encoding of its own is in
|
|
399
|
+
// its referrer's: a `<link charset>`, then the document's (CSS 2.1
|
|
400
|
+
// 4.4), and an import is in the encoding of the sheet importing it.
|
|
401
|
+
const linked = ref.kind === 'inline'
|
|
402
|
+
? null
|
|
403
|
+
: this._resources.stylesheet(ref.href, [
|
|
404
|
+
attr(ref.element, 'charset') || undefined,
|
|
405
|
+
props.charset,
|
|
406
|
+
]);
|
|
407
|
+
const text = ref.kind === 'inline' ? ref.text : linked?.text;
|
|
236
408
|
if (!text)
|
|
237
409
|
continue;
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this._resources.request({
|
|
244
|
-
url,
|
|
245
|
-
kind: 'stylesheet',
|
|
246
|
-
element: ref.element,
|
|
247
|
-
});
|
|
248
|
-
const imported = this._resources.stylesheetText(url);
|
|
249
|
-
if (imported) {
|
|
250
|
-
const parsed = parseStylesheet(imported, order);
|
|
251
|
-
order += parsed.rules.length + 1;
|
|
252
|
-
sheets.push(parsed);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
sheets.push(sheet);
|
|
410
|
+
const encoding = linked ? linked.encoding : props.charset;
|
|
411
|
+
const base = ref.kind === 'inline'
|
|
412
|
+
? documentBase
|
|
413
|
+
: this._resources.sheetBase(ref.href);
|
|
414
|
+
read.push({ text, encoding, element: ref.element, base });
|
|
256
415
|
}
|
|
257
416
|
const extra = props.stylesheet;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
417
|
+
const extras = Array.isArray(extra) ? extra : extra ? [extra] : [];
|
|
418
|
+
const fonts = this._fonts();
|
|
419
|
+
// Sheets that read as they did last time are the same rules: an append
|
|
420
|
+
// to a streamed document, or a width across a `@media` breakpoint,
|
|
421
|
+
// restyles the elements without parsing a framework's stylesheet again
|
|
422
|
+
// or indexing its thousand rules again.
|
|
423
|
+
const kept = this._sheetsRead;
|
|
424
|
+
let faces;
|
|
425
|
+
if (kept &&
|
|
426
|
+
kept.look === look &&
|
|
427
|
+
kept.scale === this._scale &&
|
|
428
|
+
kept.fonts === fonts &&
|
|
429
|
+
this._sameSheets(kept, read, extras)) {
|
|
430
|
+
this._cascade = kept.cascade;
|
|
431
|
+
kept.cascade.viewportWidth = width;
|
|
432
|
+
kept.cascade.viewportHeight = this._viewportHeight();
|
|
433
|
+
faces = kept.faces;
|
|
262
434
|
}
|
|
263
|
-
|
|
435
|
+
else {
|
|
436
|
+
const sheets = [uaStylesheet(look)];
|
|
437
|
+
const imports = [];
|
|
438
|
+
faces = [];
|
|
439
|
+
let order = 0;
|
|
440
|
+
const layers = new Map();
|
|
441
|
+
// A sheet takes its place in the cascade's order once everything it
|
|
442
|
+
// imports has taken theirs: `@import` is a resource like any other,
|
|
443
|
+
// and an imported sheet's rules sit *before* the importing sheet's
|
|
444
|
+
// (CSS 2.1 6.4.1), or an imported rule would win a tie against the
|
|
445
|
+
// sheet importing it.
|
|
446
|
+
const place = (sheet, element) => {
|
|
447
|
+
for (const rule of sheet.rules)
|
|
448
|
+
rule.order = order++;
|
|
449
|
+
order += 1;
|
|
450
|
+
sheets.push(sheet);
|
|
451
|
+
for (const rule of sheet.fontFaces)
|
|
452
|
+
faces.push({ rule, element });
|
|
453
|
+
};
|
|
454
|
+
for (const { text, encoding, element, base } of read) {
|
|
455
|
+
const sheet = parseStylesheet(text, 0, layers, base);
|
|
456
|
+
const seen = [];
|
|
457
|
+
this._placeImports(sheet, encoding, element, layers, seen, place);
|
|
458
|
+
imports.push(seen);
|
|
459
|
+
place(sheet, element);
|
|
460
|
+
}
|
|
461
|
+
for (const text of extras) {
|
|
462
|
+
const sheet = parseStylesheet(text, order, layers);
|
|
463
|
+
order += sheet.rules.length + 1;
|
|
464
|
+
sheets.push(sheet);
|
|
465
|
+
}
|
|
466
|
+
this._cascade = new Cascade(sheets, look, width, this._viewportHeight(), this._scale, fonts ? (face) => xHeightOf(fonts, face) : null, fonts ? (face) => zeroWidthOf(fonts, face) : null, fonts ? (face) => normalLineOf(fonts, face) : null, faces.length ? this._webFonts : null);
|
|
467
|
+
this._sheetsRead = {
|
|
468
|
+
look,
|
|
469
|
+
scale: this._scale,
|
|
470
|
+
fonts,
|
|
471
|
+
texts: read.map((r) => r.text),
|
|
472
|
+
encodings: read.map((r) => r.encoding),
|
|
473
|
+
bases: read.map((r) => r.base),
|
|
474
|
+
imports,
|
|
475
|
+
extras,
|
|
476
|
+
faces,
|
|
477
|
+
cascade: this._cascade,
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
// The faces this width and scheme declare: a `@font-face` may sit in a
|
|
481
|
+
// `@media` block like any rule.
|
|
482
|
+
const cssWidth = width / this._scale;
|
|
483
|
+
this._webFonts.setFallback(look.fontFamily);
|
|
484
|
+
this._webFonts.setFaces(faces.filter((f) => mediaMatches(f.rule.media, cssWidth, look.colorScheme)));
|
|
264
485
|
this._cascade.setPointer({
|
|
265
486
|
hovered: new Set(this._hovered),
|
|
266
487
|
active: EMPTY_SET,
|
|
267
488
|
});
|
|
268
489
|
this._mediaBand = this._cascade.mediaBand(width);
|
|
269
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Place what a sheet imports, and what each of those imports, depth
|
|
493
|
+
* first — asking for each through the seam, as a parse of the sheet has
|
|
494
|
+
* to. `seen` records every import read, in order, which is what tells the
|
|
495
|
+
* next restyle whether the sheets read the same (`_sameSheets`). A sheet
|
|
496
|
+
* that imports itself, or one of the sheets importing it, is read once.
|
|
497
|
+
*/
|
|
498
|
+
_placeImports(sheet, encoding, element, layers, seen, place, depth = 0, chain = new Set()) {
|
|
499
|
+
for (const url of sheet.imports) {
|
|
500
|
+
this._resources.request({ url, kind: 'stylesheet', element });
|
|
501
|
+
const fetched = this._resources.stylesheet(url, [encoding]);
|
|
502
|
+
const base = this._resources.sheetBase(url);
|
|
503
|
+
seen.push({ url, text: fetched?.text ?? null, base });
|
|
504
|
+
const key = base ?? url;
|
|
505
|
+
if (!fetched || depth >= MAX_IMPORT_DEPTH || chain.has(key))
|
|
506
|
+
continue;
|
|
507
|
+
const imported = parseStylesheet(fetched.text, 0, layers, base);
|
|
508
|
+
chain.add(key);
|
|
509
|
+
this._placeImports(imported, fetched.encoding, element, layers, seen, place, depth + 1, chain);
|
|
510
|
+
chain.delete(key);
|
|
511
|
+
place(imported, element);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/** Whether the sheets read the same as the ones `kept` was built from,
|
|
515
|
+
* down to what each imports — asking for the imports again, as a parse
|
|
516
|
+
* of the sheet would have. */
|
|
517
|
+
_sameSheets(kept, read, extras) {
|
|
518
|
+
if (read.length !== kept.texts.length)
|
|
519
|
+
return false;
|
|
520
|
+
if (extras.length !== kept.extras.length)
|
|
521
|
+
return false;
|
|
522
|
+
for (let i = 0; i < extras.length; i += 1) {
|
|
523
|
+
if (extras[i] !== kept.extras[i])
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
for (let i = 0; i < read.length; i += 1) {
|
|
527
|
+
const r = read[i];
|
|
528
|
+
if (r.text !== kept.texts[i] ||
|
|
529
|
+
r.encoding !== kept.encodings[i] ||
|
|
530
|
+
r.base !== kept.bases[i]) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
// The encodings an import falls back to are its importer's, which
|
|
534
|
+
// only a parse knows; the text an import decoded to under them is what
|
|
535
|
+
// was kept, and bytes that decode differently now are a new sheet.
|
|
536
|
+
for (const { url, text, base } of kept.imports[i]) {
|
|
537
|
+
this._resources.request({
|
|
538
|
+
url,
|
|
539
|
+
kind: 'stylesheet',
|
|
540
|
+
element: r.element,
|
|
541
|
+
});
|
|
542
|
+
const fetched = this._resources.stylesheet(url, [r.encoding]);
|
|
543
|
+
if ((fetched?.text ?? null) !== text)
|
|
544
|
+
return false;
|
|
545
|
+
if (this._resources.sheetBase(url) !== base)
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
270
551
|
_viewportHeight() {
|
|
271
|
-
// The viewport a `vh` resolves against is the
|
|
272
|
-
// document
|
|
273
|
-
// taller with it.
|
|
552
|
+
// The viewport a `vh` resolves against is the one the document is seen
|
|
553
|
+
// through, not the document — a document taller than it does not make
|
|
554
|
+
// `100vh` taller with it. That is the box that scrolls the element,
|
|
555
|
+
// where one does: a browser's page area, below its tab strip and its
|
|
556
|
+
// toolbar, where `100vh` measured by the window put a page's footer the
|
|
557
|
+
// toolbar's height below the fold. The window, where nothing scrolls it.
|
|
558
|
+
for (let node = this.parent; node; node = node.parent) {
|
|
559
|
+
// `Scrollable`'s, and not every node's: asked the way core asks it
|
|
560
|
+
const scroller = node;
|
|
561
|
+
if (!scroller.isScroller?.())
|
|
562
|
+
continue;
|
|
563
|
+
const height = node.contentBox().height;
|
|
564
|
+
if (height > 0)
|
|
565
|
+
return height;
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
274
568
|
const root = this.root;
|
|
275
569
|
const height = root?.abs?.height;
|
|
276
570
|
return height && height > 0 ? height : 600;
|
|
277
571
|
}
|
|
278
572
|
_fonts() {
|
|
279
573
|
const fonts = this.app?.fonts;
|
|
280
|
-
|
|
574
|
+
// a face the engine cannot shape from costs its characters, not the
|
|
575
|
+
// document (`shaping.ts`)
|
|
576
|
+
return fonts ? shapingSafe(fonts) : null;
|
|
577
|
+
}
|
|
578
|
+
/** The text layouts the last pass made, for this one to reuse. */
|
|
579
|
+
_layouts = null;
|
|
580
|
+
/** The fonts a layout pass lays text out with: the engine's, through the
|
|
581
|
+
* layouts the pass before made (`TextLayoutCache`). */
|
|
582
|
+
_layoutFonts() {
|
|
583
|
+
const fonts = this._fonts();
|
|
584
|
+
if (!fonts)
|
|
585
|
+
return null;
|
|
586
|
+
if (this._layouts?.engine !== fonts)
|
|
587
|
+
this._layouts = new TextLayoutCache(fonts);
|
|
588
|
+
this._layouts.begin();
|
|
589
|
+
return this._layouts.fonts;
|
|
281
590
|
}
|
|
282
|
-
/**
|
|
591
|
+
/**
|
|
592
|
+
* Bring the pipeline up to date for a width — or, where that throws, leave
|
|
593
|
+
* the document blank. From a paint a throw is the application's end, for
|
|
594
|
+
* a document it did not write: a stack a thousand nested elements run
|
|
595
|
+
* down, or a limit of the text engine's or the server's that one more
|
|
596
|
+
* document finds. Reported once for each thing that went wrong, and tried
|
|
597
|
+
* again only when something changes, or the width does.
|
|
598
|
+
*/
|
|
283
599
|
_prepare(width) {
|
|
284
600
|
const target = Math.max(1, Math.floor(width));
|
|
601
|
+
if (this._failedAt === target && this._stale === Stale.Nothing)
|
|
602
|
+
return;
|
|
603
|
+
try {
|
|
604
|
+
this._update(target);
|
|
605
|
+
this._failedAt = -1;
|
|
606
|
+
}
|
|
607
|
+
catch (error) {
|
|
608
|
+
this._fail(error, target);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/** The width the pipeline threw at, until something changes (`_prepare`). */
|
|
612
|
+
_failedAt = -1;
|
|
613
|
+
_failures = null;
|
|
614
|
+
_fail(error, width) {
|
|
615
|
+
this._tree = null;
|
|
616
|
+
this._stale = Stale.Nothing;
|
|
617
|
+
this._failedAt = width;
|
|
618
|
+
this._laidOutWidth = -1;
|
|
619
|
+
this._documentWidth = 0;
|
|
620
|
+
this._documentHeight = 0;
|
|
621
|
+
const message = String(error?.stack ?? error);
|
|
622
|
+
this._failures ??= new Set();
|
|
623
|
+
if (this._failures.has(message))
|
|
624
|
+
return;
|
|
625
|
+
this._failures.add(message);
|
|
626
|
+
const g = globalThis;
|
|
627
|
+
if (g.process?.env?.NODE_ENV === 'production')
|
|
628
|
+
return;
|
|
629
|
+
g.console?.error('@react-x11/components: <Html> could not lay out or paint its ' +
|
|
630
|
+
`document, and leaves it blank.\n${message}`);
|
|
631
|
+
}
|
|
632
|
+
_update(target) {
|
|
285
633
|
const props = this._props();
|
|
286
634
|
if ((props.domRevision ?? 0) !== this._reportedDomRevision) {
|
|
287
635
|
this._reportedDomRevision = props.domRevision ?? 0;
|
|
288
636
|
this._source.touch();
|
|
637
|
+
this._updateBase();
|
|
289
638
|
this._sweep();
|
|
290
639
|
if (this._stale < Stale.Style)
|
|
291
640
|
this._stale = Stale.Style;
|
|
292
641
|
}
|
|
293
|
-
|
|
642
|
+
// A document that reads its viewport's height — a `vh`, a percentage
|
|
643
|
+
// height on the root, a box placed against the initial containing block
|
|
644
|
+
// — is laid out again when that height moves. One that reads none, which
|
|
645
|
+
// is most, goes on skipping layout when the window only grew taller.
|
|
646
|
+
const viewport = this._viewportHeight();
|
|
647
|
+
const viewportMoved = viewport !== this._laidOutUnder && this._readsViewportHeight();
|
|
648
|
+
// the sizes other widths came to were read from what just changed
|
|
649
|
+
if (this._stale !== Stale.Nothing || viewportMoved)
|
|
650
|
+
this._sizes.clear();
|
|
651
|
+
if (this._stale === Stale.Nothing &&
|
|
652
|
+
this._laidOutWidth === target &&
|
|
653
|
+
!viewportMoved) {
|
|
294
654
|
return;
|
|
655
|
+
}
|
|
656
|
+
// Nothing but the viewport: the size core laid this element out at came
|
|
657
|
+
// from a layout under the old one, and nothing else will tell it so.
|
|
658
|
+
const onlyViewport = this._stale === Stale.Nothing && this._laidOutWidth === target;
|
|
659
|
+
const wasWidth = this._documentWidth;
|
|
660
|
+
const wasHeight = this._documentHeight;
|
|
295
661
|
if (this._stale >= Stale.Style || !this._cascade) {
|
|
296
662
|
this._restyle(target);
|
|
297
663
|
this._stale = Math.max(this._stale, Stale.Boxes);
|
|
@@ -307,28 +673,74 @@ export class HtmlViewNode extends Node {
|
|
|
307
673
|
if (!cascade)
|
|
308
674
|
return;
|
|
309
675
|
cascade.viewportWidth = target;
|
|
310
|
-
cascade.viewportHeight =
|
|
676
|
+
cascade.viewportHeight = viewport;
|
|
677
|
+
// A `vw` or a `vh` is a number by the time a style holds it, so the
|
|
678
|
+
// styles computed for another viewport are wrong for this one: built
|
|
679
|
+
// again, where some style reads the side that moved. A document that
|
|
680
|
+
// reads neither — most — goes on skipping the cascade on a resize.
|
|
681
|
+
if (this._stale < Stale.Boxes &&
|
|
682
|
+
((cascade.readsViewportWidth && this._styledWidth !== target) ||
|
|
683
|
+
(cascade.readsViewportHeight && this._styledHeight !== viewport))) {
|
|
684
|
+
this._stale = Stale.Boxes;
|
|
685
|
+
}
|
|
311
686
|
if (this._stale >= Stale.Boxes || !this._tree) {
|
|
312
687
|
const look = this._deviceLook();
|
|
313
|
-
|
|
688
|
+
const build = () => buildBoxes(this._source.document, {
|
|
314
689
|
cascade,
|
|
315
690
|
scale: this._scale,
|
|
316
|
-
imageSize: (el) => this._resources.imageSize(
|
|
691
|
+
imageSize: (el) => this._resources.imageSize(imageUrlOf(el) ?? ''),
|
|
692
|
+
urlSize: (url) => this._resources.imageSize(url),
|
|
317
693
|
controlSize: (el, kind, style) => measureControl(el, kind, style, this._fonts(), look),
|
|
318
694
|
});
|
|
695
|
+
this._tree = build();
|
|
696
|
+
this._styledWidth = target;
|
|
697
|
+
this._styledHeight = viewport;
|
|
698
|
+
this._requestBackgrounds(this._tree);
|
|
699
|
+
let again = this._contentImagesArrived(this._tree);
|
|
700
|
+
// the faces the styles just asked for, of the families the document
|
|
701
|
+
// loads itself — which, answered at once, change the styles asking
|
|
702
|
+
if (this._webFonts.request(this._tree.text)) {
|
|
703
|
+
this._layouts = null;
|
|
704
|
+
again = true;
|
|
705
|
+
}
|
|
706
|
+
if (again)
|
|
707
|
+
this._tree = build();
|
|
708
|
+
this._warmFaces(this._tree);
|
|
319
709
|
this._textPoints = null;
|
|
320
710
|
this._pointsAreUnits = null;
|
|
321
711
|
this._laidOutWidth = -1;
|
|
322
712
|
}
|
|
323
713
|
if (this._tree &&
|
|
324
|
-
(this._laidOutWidth !== target ||
|
|
325
|
-
|
|
714
|
+
(this._laidOutWidth !== target ||
|
|
715
|
+
viewportMoved ||
|
|
716
|
+
this._stale >= Stale.Layout)) {
|
|
717
|
+
const result = layoutDocument(this._tree, this._layoutFonts(), target, viewport);
|
|
326
718
|
this._documentWidth = result.width;
|
|
327
719
|
this._documentHeight = result.height;
|
|
328
720
|
this._laidOutWidth = target;
|
|
721
|
+
this._laidOutUnder = viewport;
|
|
722
|
+
this._layoutReadsViewport = result.readsViewportHeight;
|
|
723
|
+
this._sizes.delete(target);
|
|
724
|
+
this._sizes.set(target, { width: result.width, height: result.height });
|
|
725
|
+
if (this._sizes.size > SIZES_KEPT) {
|
|
726
|
+
this._sizes.delete(this._sizes.keys().next().value);
|
|
727
|
+
}
|
|
329
728
|
this._reportControls();
|
|
330
729
|
}
|
|
331
730
|
this._stale = Stale.Nothing;
|
|
731
|
+
// Read after core's layout pass — the viewport is the box around this
|
|
732
|
+
// one, whose new height only that pass decides — so it is a paint that
|
|
733
|
+
// finds it moved, and the next frame that measures this element again.
|
|
734
|
+
// Inside a measure the answer already is the new size.
|
|
735
|
+
if (onlyViewport &&
|
|
736
|
+
!this._measuring &&
|
|
737
|
+
(this._documentWidth !== wasWidth || this._documentHeight !== wasHeight)) {
|
|
738
|
+
this.invalidateMeasure('content');
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
/** Whether the document as laid out reads its viewport's height. */
|
|
742
|
+
_readsViewportHeight() {
|
|
743
|
+
return (this._layoutReadsViewport || this._cascade?.readsViewportHeight === true);
|
|
332
744
|
}
|
|
333
745
|
_reportControls() {
|
|
334
746
|
const tree = this._tree;
|
|
@@ -346,6 +758,16 @@ export class HtmlViewNode extends Node {
|
|
|
346
758
|
y: r.y / s,
|
|
347
759
|
width: r.width / s,
|
|
348
760
|
height: r.height / s,
|
|
761
|
+
...(r.bare && {
|
|
762
|
+
bare: {
|
|
763
|
+
...r.bare,
|
|
764
|
+
x: r.bare.x / s,
|
|
765
|
+
y: r.bare.y / s,
|
|
766
|
+
width: r.bare.width / s,
|
|
767
|
+
height: r.bare.height / s,
|
|
768
|
+
fontSize: r.bare.fontSize / s,
|
|
769
|
+
},
|
|
770
|
+
}),
|
|
349
771
|
});
|
|
350
772
|
if (sameRects(rects, this._controls))
|
|
351
773
|
return;
|
|
@@ -364,17 +786,57 @@ export class HtmlViewNode extends Node {
|
|
|
364
786
|
*/
|
|
365
787
|
measureContent({ width }) {
|
|
366
788
|
const offered = Number.isFinite(width) ? width : 800;
|
|
367
|
-
this.
|
|
789
|
+
this._measuring = true;
|
|
790
|
+
let size;
|
|
791
|
+
try {
|
|
792
|
+
size = this._sizeAt(offered);
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
this._measuring = false;
|
|
796
|
+
}
|
|
797
|
+
// core takes finite numbers only, and throws on any other from the
|
|
798
|
+
// layout — a document of lengths no clamp foresaw is none too tall
|
|
799
|
+
const finite = (n) => (Number.isFinite(n) ? n : 0);
|
|
368
800
|
return {
|
|
369
|
-
width:
|
|
370
|
-
height:
|
|
801
|
+
width: wholePixels(Math.min(finite(size.width), offered)),
|
|
802
|
+
height: wholePixels(finite(size.height)),
|
|
371
803
|
};
|
|
372
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* The size the document comes to at `width`.
|
|
807
|
+
*
|
|
808
|
+
* Core asks a leaf for its height at the width it was measured at as well
|
|
809
|
+
* as at the one it has now (`probeHeightFloors`), to learn whether a
|
|
810
|
+
* relayout changed what the leaf needs — so every frame of a resize asks
|
|
811
|
+
* two widths, and the boxes hold one. Laying the document out at the old
|
|
812
|
+
* width to answer, and then at the new one again for the pass after, was
|
|
813
|
+
* three whole passes a frame. The size a width came to is kept instead,
|
|
814
|
+
* and answers until anything a layout reads changes: the source, the
|
|
815
|
+
* styles, a resource, the viewport height. Nothing but a size comes from
|
|
816
|
+
* it — paint and the text accessors read the boxes, which are only ever
|
|
817
|
+
* laid out for real (`_prepare`).
|
|
818
|
+
*/
|
|
819
|
+
_sizeAt(width) {
|
|
820
|
+
const target = Math.max(1, Math.floor(width));
|
|
821
|
+
if (target !== this._laidOutWidth &&
|
|
822
|
+
this._stale === Stale.Nothing &&
|
|
823
|
+
(this._props().domRevision ?? 0) === this._reportedDomRevision &&
|
|
824
|
+
(!this._readsViewportHeight() ||
|
|
825
|
+
this._viewportHeight() === this._laidOutUnder)) {
|
|
826
|
+
const known = this._sizes.get(target);
|
|
827
|
+
if (known)
|
|
828
|
+
return known;
|
|
829
|
+
}
|
|
830
|
+
this._prepare(width);
|
|
831
|
+
return { width: this._documentWidth, height: this._documentHeight };
|
|
832
|
+
}
|
|
373
833
|
applyProps(nextProps, prevProps) {
|
|
374
834
|
super.applyProps(nextProps, prevProps);
|
|
375
835
|
const next = nextProps;
|
|
376
836
|
const prev = prevProps;
|
|
377
|
-
if (next.look !== prev.look ||
|
|
837
|
+
if (next.look !== prev.look ||
|
|
838
|
+
next.stylesheet !== prev.stylesheet ||
|
|
839
|
+
next.charset !== prev.charset) {
|
|
378
840
|
this._invalidate(Stale.Style);
|
|
379
841
|
}
|
|
380
842
|
if (next.source !== prev.source || next.complete !== prev.complete) {
|
|
@@ -383,10 +845,19 @@ export class HtmlViewNode extends Node {
|
|
|
383
845
|
else if ((next.domRevision ?? 0) !== (prev.domRevision ?? 0)) {
|
|
384
846
|
this._invalidate(Stale.Style);
|
|
385
847
|
}
|
|
848
|
+
else if ((next.baseUrl ?? null) !== (prev.baseUrl ?? null)) {
|
|
849
|
+
// the same document somewhere else: every URL in it is another one
|
|
850
|
+
this._updateBase();
|
|
851
|
+
this._sweep();
|
|
852
|
+
}
|
|
386
853
|
}
|
|
387
854
|
destroySubtree() {
|
|
388
855
|
this._resources.destroy();
|
|
856
|
+
this._webFonts.destroy();
|
|
389
857
|
this._source.destroy();
|
|
858
|
+
this._shadowCache?.destroy();
|
|
859
|
+
this._shadowCache = null;
|
|
860
|
+
this._sheetsRead = null;
|
|
390
861
|
this._tree = null;
|
|
391
862
|
this._cascade = null;
|
|
392
863
|
super.destroySubtree();
|
|
@@ -484,27 +955,122 @@ export class HtmlViewNode extends Node {
|
|
|
484
955
|
// event's `x`/`y` carry and what `useLinkClicks` and an application's
|
|
485
956
|
// handler hand over — and are the one place the two units meet on the way
|
|
486
957
|
// in. `_toDocument` multiplies.
|
|
487
|
-
/** The link under a logical window point, if any
|
|
488
|
-
*
|
|
489
|
-
* #291, so following a
|
|
958
|
+
/** The link under a logical window point, if any — resolved against the
|
|
959
|
+
* document's base where it has one. Not part of the selection seam: core
|
|
960
|
+
* deliberately left hover and `cursorAt` out of #291, so following a
|
|
961
|
+
* link stays this package's. */
|
|
490
962
|
hrefAtPoint(x, y) {
|
|
491
963
|
const el = this.elementAtPoint(x, y);
|
|
492
964
|
let node = el;
|
|
493
965
|
while (node) {
|
|
494
966
|
const href = attr(node, 'href');
|
|
495
|
-
if (href && (tagOf(node) === 'a' || tagOf(node) === 'area'))
|
|
496
|
-
return href;
|
|
967
|
+
if (href && (tagOf(node) === 'a' || tagOf(node) === 'area')) {
|
|
968
|
+
return this._urls.resolve(href);
|
|
969
|
+
}
|
|
497
970
|
node = isElement(node.parent) ? node.parent : null;
|
|
498
971
|
}
|
|
499
972
|
return null;
|
|
500
973
|
}
|
|
974
|
+
/** The URL the document's relative URLs resolve against, or null where
|
|
975
|
+
* it has none (`_updateBase`). */
|
|
976
|
+
get documentBase() {
|
|
977
|
+
return this._urls.base;
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Where an element is, in document coordinates: logical pixels from this
|
|
981
|
+
* element's top left, the space the scroll offset of a box around it is
|
|
982
|
+
* in — so scrolling to a fragment is `scrollTo({ y: rect.y })`. A block's
|
|
983
|
+
* border box. An inline element's fragments, from its first line to its
|
|
984
|
+
* last, each across its text, the inline-blocks and inline boxes' edges
|
|
985
|
+
* it holds, and its own padding and border where it starts or ends — its
|
|
986
|
+
* border box across, as `getBoundingClientRect` is (CSSOM View 6.1) — and
|
|
987
|
+
* as tall as its lines; or where its text would start when it has none,
|
|
988
|
+
* as `<a name>` has none. Null for an element with no box — `display:
|
|
989
|
+
* none`, or not in the document.
|
|
990
|
+
*/
|
|
991
|
+
elementRect(element) {
|
|
992
|
+
this._prepare(this.abs.width || 1);
|
|
993
|
+
const tree = this._tree;
|
|
994
|
+
if (!tree)
|
|
995
|
+
return null;
|
|
996
|
+
const box = boxFor(tree.root, element);
|
|
997
|
+
if (!box)
|
|
998
|
+
return null;
|
|
999
|
+
let rect = null;
|
|
1000
|
+
if (box.kind !== 'inline' && box.kind !== 'text') {
|
|
1001
|
+
rect = { x: box.x, y: box.y, width: box.width, height: box.height };
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
const bands = [];
|
|
1005
|
+
// an inline box's fragments are on the lines of the block it is laid
|
|
1006
|
+
// out in, and no text of a float or a positioned box inside it — on
|
|
1007
|
+
// lines of their own — is one of them (CSSOM View 6.1): a list item
|
|
1008
|
+
// made inline around an absolute link measured as the link
|
|
1009
|
+
let block = box.parent;
|
|
1010
|
+
while (block && !block.lines)
|
|
1011
|
+
block = block.parent;
|
|
1012
|
+
if (box.subtreeTextEnd > box.subtreeTextStart) {
|
|
1013
|
+
if (box.kind === 'inline' && block?.lines) {
|
|
1014
|
+
lineBands(block.lines, box.subtreeTextStart, box.subtreeTextEnd, 0, 0, bands);
|
|
1015
|
+
}
|
|
1016
|
+
else {
|
|
1017
|
+
collectBands(tree.root, box.subtreeTextStart, box.subtreeTextEnd, 0, 0, bands);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (box.kind === 'inline') {
|
|
1021
|
+
fragmentReach(box, bands);
|
|
1022
|
+
const fonts = this._layouts?.fonts;
|
|
1023
|
+
if (fonts)
|
|
1024
|
+
fragmentHeights(box, bands, fonts);
|
|
1025
|
+
}
|
|
1026
|
+
for (const band of bands)
|
|
1027
|
+
rect = rect ? unionRect(rect, band) : band;
|
|
1028
|
+
if (!rect) {
|
|
1029
|
+
// an empty subtree's range is `[0, 0)`, wherever it stands: where
|
|
1030
|
+
// its text would be is where the text after it starts
|
|
1031
|
+
const caret = caretAt(tree.root, textAfter(tree.root, box));
|
|
1032
|
+
if (!caret)
|
|
1033
|
+
return null;
|
|
1034
|
+
rect = { x: caret.x, y: caret.y, width: 0, height: caret.height };
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
const s = this._scale;
|
|
1038
|
+
return {
|
|
1039
|
+
x: rect.x / s,
|
|
1040
|
+
y: rect.y / s,
|
|
1041
|
+
width: rect.width / s,
|
|
1042
|
+
height: rect.height / s,
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
501
1045
|
/** The deepest element whose box contains a logical window point. */
|
|
502
1046
|
elementAtPoint(x, y) {
|
|
503
1047
|
const tree = this._tree;
|
|
504
1048
|
if (!tree)
|
|
505
1049
|
return null;
|
|
506
1050
|
const local = this._toDocument(x, y);
|
|
507
|
-
return deepestAt(tree
|
|
1051
|
+
return deepestAt(tree, local.x, local.y);
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* The cursor for a point of this element's, in device pixels: what core
|
|
1055
|
+
* asks a drawn element as the pointer moves over it (`cursorAt`,
|
|
1056
|
+
* react-x11#757). The `cursor` the document's styles give what is under
|
|
1057
|
+
* it — a link's `pointer`, the user-agent sheet's — and where they say
|
|
1058
|
+
* nothing, text's I-beam over text and the arrow elsewhere, as a browser
|
|
1059
|
+
* shows them. The arrow is named rather than left to null: null lets
|
|
1060
|
+
* core fall through to the element's `defaultCursor`, which is the
|
|
1061
|
+
* I-beam on a selectable surface, and every `<Html>` is one.
|
|
1062
|
+
*/
|
|
1063
|
+
cursorAt(x, y) {
|
|
1064
|
+
const tree = this._tree;
|
|
1065
|
+
if (!tree)
|
|
1066
|
+
return null;
|
|
1067
|
+
const hit = { text: false };
|
|
1068
|
+
const el = deepestAt(tree, x - this.abs.x, y - this.abs.y, hit);
|
|
1069
|
+
const cursor = el ? tree.styles.get(el)?.style.cursor : null;
|
|
1070
|
+
// a keyword; a `url()` this cannot load falls back, as its list would
|
|
1071
|
+
if (cursor && cursor !== 'auto' && /^[a-z-]+$/.test(cursor))
|
|
1072
|
+
return cursor;
|
|
1073
|
+
return hit.text ? 'text' : 'default';
|
|
508
1074
|
}
|
|
509
1075
|
/**
|
|
510
1076
|
* The pointer moved, to a logical window point. Returns true when the
|
|
@@ -524,19 +1090,233 @@ export class HtmlViewNode extends Node {
|
|
|
524
1090
|
}
|
|
525
1091
|
if (sameChain(chain, this._hovered))
|
|
526
1092
|
return false;
|
|
1093
|
+
const was = this._hovered;
|
|
527
1094
|
this._hovered = chain;
|
|
528
1095
|
cascade.setPointer({ hovered: new Set(chain), active: EMPTY_SET });
|
|
529
|
-
this.
|
|
1096
|
+
this._restyleHover(was, chain);
|
|
530
1097
|
return true;
|
|
531
1098
|
}
|
|
532
1099
|
clearHover() {
|
|
533
1100
|
if (!this._hovered.length)
|
|
534
1101
|
return false;
|
|
1102
|
+
const was = this._hovered;
|
|
535
1103
|
this._hovered = [];
|
|
536
1104
|
this._cascade?.setPointer({ hovered: new Set(), active: EMPTY_SET });
|
|
537
|
-
this.
|
|
1105
|
+
this._restyleHover(was, []);
|
|
538
1106
|
return true;
|
|
539
1107
|
}
|
|
1108
|
+
/** The hovered chain moved: restyle where it did, or the document. */
|
|
1109
|
+
_restyleHover(was, now) {
|
|
1110
|
+
const done = this._hoverInPlace(was, now);
|
|
1111
|
+
if (done === 'painted')
|
|
1112
|
+
this.invalidate(false, this, 'props');
|
|
1113
|
+
else if (done === false)
|
|
1114
|
+
this._invalidate(Stale.Boxes);
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* A pointer move restyled where it happened, when all it changed is ink.
|
|
1118
|
+
*
|
|
1119
|
+
* A move to another element is a change to the cascade, and the pipeline
|
|
1120
|
+
* answers one by building every box again and laying the document out:
|
|
1121
|
+
* 270 ms on X11 and twice that on Cocoa for a Wikipedia article, on every
|
|
1122
|
+
* link the pointer crossed. But the rules a page writes for `:hover`
|
|
1123
|
+
* nearly all change a colour, an underline, a background or a border's
|
|
1124
|
+
* colour — 77 of that article's 79 — and those move nothing. So:
|
|
1125
|
+
*
|
|
1126
|
+
* - Only an element whose hover state flipped and that a compound testing
|
|
1127
|
+
* the pointer could match can change (`Cascade.hoverTouches`), with its
|
|
1128
|
+
* subtree, and its later siblings where a sibling combinator follows.
|
|
1129
|
+
* A move between two paragraphs under `a:hover` touches nothing.
|
|
1130
|
+
* - Those are styled again from their parents. Where anything but ink
|
|
1131
|
+
* differs (`PAINT_ONLY`), or a box is not the element's own — an
|
|
1132
|
+
* anonymous or a pseudo-element box, a marker, a control — this is
|
|
1133
|
+
* not the move to take.
|
|
1134
|
+
* - The boxes take their new styles, and each layout of their text is
|
|
1135
|
+
* made again from the runs it was made from (`TextLayoutCache.inputsOf`)
|
|
1136
|
+
* with the new ink (`runFor`), where its geometry comes out the same.
|
|
1137
|
+
*
|
|
1138
|
+
* Everything is checked before anything is changed. 'none' where nothing
|
|
1139
|
+
* could change, 'painted' where it was restyled here, false where the
|
|
1140
|
+
* document has to be built again.
|
|
1141
|
+
*/
|
|
1142
|
+
_hoverInPlace(was, now) {
|
|
1143
|
+
const cascade = this._cascade;
|
|
1144
|
+
const tree = this._tree;
|
|
1145
|
+
const layouts = this._layouts;
|
|
1146
|
+
if (!cascade || !tree || !layouts || !cascade.hoverLocal)
|
|
1147
|
+
return false;
|
|
1148
|
+
if (this._stale !== Stale.Nothing || this._laidOutWidth < 0)
|
|
1149
|
+
return false;
|
|
1150
|
+
const before = new Set(was);
|
|
1151
|
+
const after = new Set(now);
|
|
1152
|
+
const roots = [];
|
|
1153
|
+
// and the elements a `:has()` testing the pointer may flip, which
|
|
1154
|
+
// are around the ones that changed; the chains are ancestor chains,
|
|
1155
|
+
// so the deepest that changed on each side is where to look from
|
|
1156
|
+
const flipped = (el, other) => {
|
|
1157
|
+
if (other.has(el))
|
|
1158
|
+
return;
|
|
1159
|
+
if (cascade.hoverTouches(el))
|
|
1160
|
+
roots.push(el);
|
|
1161
|
+
};
|
|
1162
|
+
for (const el of was)
|
|
1163
|
+
flipped(el, after);
|
|
1164
|
+
for (const el of now)
|
|
1165
|
+
flipped(el, before);
|
|
1166
|
+
const deepest = (chain, other) => {
|
|
1167
|
+
const el = chain[0];
|
|
1168
|
+
if (el && !other.has(el))
|
|
1169
|
+
cascade.hoverAnchors(el, roots);
|
|
1170
|
+
};
|
|
1171
|
+
deepest(was, after);
|
|
1172
|
+
deepest(now, before);
|
|
1173
|
+
if (!roots.length)
|
|
1174
|
+
return 'none';
|
|
1175
|
+
// what may restyle: the roots' subtrees, which inherit from them and a
|
|
1176
|
+
// descendant combinator reaches, and their later siblings' too where a
|
|
1177
|
+
// sibling combinator follows a compound that tests the pointer
|
|
1178
|
+
const reach = new Set();
|
|
1179
|
+
const collect = (el) => {
|
|
1180
|
+
const stack = [el];
|
|
1181
|
+
while (stack.length) {
|
|
1182
|
+
const at = stack.pop();
|
|
1183
|
+
if (reach.has(at))
|
|
1184
|
+
continue;
|
|
1185
|
+
reach.add(at);
|
|
1186
|
+
if (reach.size > HOVER_RESTYLE_LIMIT)
|
|
1187
|
+
return false;
|
|
1188
|
+
for (const child of at.children)
|
|
1189
|
+
if (isElement(child))
|
|
1190
|
+
stack.push(child);
|
|
1191
|
+
}
|
|
1192
|
+
return true;
|
|
1193
|
+
};
|
|
1194
|
+
for (const root of roots) {
|
|
1195
|
+
if (!collect(root))
|
|
1196
|
+
return false;
|
|
1197
|
+
if (!cascade.hoverSiblings)
|
|
1198
|
+
continue;
|
|
1199
|
+
for (let s = root.nextSibling; s; s = s.nextSibling) {
|
|
1200
|
+
if (isElement(s) && !collect(s))
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
// styled again from their parents, a parent first
|
|
1205
|
+
const fresh = new Map();
|
|
1206
|
+
const changed = new Map();
|
|
1207
|
+
let refused = false;
|
|
1208
|
+
const styleOf = (el) => {
|
|
1209
|
+
const kept = tree.styles.get(el);
|
|
1210
|
+
if (!kept)
|
|
1211
|
+
return null;
|
|
1212
|
+
if (!reach.has(el))
|
|
1213
|
+
return kept.style;
|
|
1214
|
+
const done = fresh.get(el);
|
|
1215
|
+
if (done)
|
|
1216
|
+
return done;
|
|
1217
|
+
// an element at the top of the document is styled from the box above
|
|
1218
|
+
// it all, as the builder styled it (`BoxBuilder.run`)
|
|
1219
|
+
const parent = isElement(el.parent) ? el.parent : null;
|
|
1220
|
+
const parentStyle = parent ? styleOf(parent) : tree.root.style;
|
|
1221
|
+
if (!parentStyle) {
|
|
1222
|
+
refused = true;
|
|
1223
|
+
return null;
|
|
1224
|
+
}
|
|
1225
|
+
const style = cascade.styleFor(el, parentStyle, kept.inFlex);
|
|
1226
|
+
fresh.set(el, style);
|
|
1227
|
+
const diff = inkOnly(kept.style, style);
|
|
1228
|
+
if (diff === false)
|
|
1229
|
+
refused = true;
|
|
1230
|
+
else if (diff)
|
|
1231
|
+
changed.set(el, style);
|
|
1232
|
+
return style;
|
|
1233
|
+
};
|
|
1234
|
+
for (const el of reach) {
|
|
1235
|
+
styleOf(el);
|
|
1236
|
+
if (refused)
|
|
1237
|
+
return false;
|
|
1238
|
+
}
|
|
1239
|
+
if (!changed.size)
|
|
1240
|
+
return 'none';
|
|
1241
|
+
for (const el of changed.keys()) {
|
|
1242
|
+
const tag = tagOf(el);
|
|
1243
|
+
// their backgrounds are the canvas's
|
|
1244
|
+
if (tag === 'html' || tag === 'body')
|
|
1245
|
+
return false;
|
|
1246
|
+
}
|
|
1247
|
+
// the boxes: each changed element's own, and nothing that takes its
|
|
1248
|
+
// style from one without being it
|
|
1249
|
+
const fonts = layouts.fonts;
|
|
1250
|
+
const restyled = [];
|
|
1251
|
+
const redecorated = [];
|
|
1252
|
+
const walk = [tree.root];
|
|
1253
|
+
while (walk.length) {
|
|
1254
|
+
const box = walk.pop();
|
|
1255
|
+
for (const child of box.children)
|
|
1256
|
+
walk.push(child);
|
|
1257
|
+
const owner = box.el ?? nearestElement(box);
|
|
1258
|
+
if (!owner)
|
|
1259
|
+
continue;
|
|
1260
|
+
const style = changed.get(owner);
|
|
1261
|
+
if (!style)
|
|
1262
|
+
continue;
|
|
1263
|
+
const kept = tree.styles.get(owner);
|
|
1264
|
+
// an anonymous box, a pseudo-element, a marker, a control: a style
|
|
1265
|
+
// derived from the element's, or drawn from it somewhere else
|
|
1266
|
+
if (!box.el || box.style !== kept.style)
|
|
1267
|
+
return false;
|
|
1268
|
+
if (box.marker || box.replaced !== 'none')
|
|
1269
|
+
return false;
|
|
1270
|
+
restyled.push([box, style]);
|
|
1271
|
+
if (box.kind === 'inline') {
|
|
1272
|
+
const decoration = inlineDecoration(fonts, box, style);
|
|
1273
|
+
if ((decoration === null) !== (box.decoration === null)) {
|
|
1274
|
+
// a rounded box with a background is laid out with its edges
|
|
1275
|
+
if (style.borderRadius.some((r) => r !== 0))
|
|
1276
|
+
return false;
|
|
1277
|
+
}
|
|
1278
|
+
if (decoration !== box.decoration)
|
|
1279
|
+
redecorated.push([box, decoration]);
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
// the text: each layout holding a run of a changed element's, made
|
|
1283
|
+
// again with its new ink, where it comes out the same shape
|
|
1284
|
+
const relaid = new Map();
|
|
1285
|
+
const texts = [];
|
|
1286
|
+
walk.push(tree.root);
|
|
1287
|
+
while (walk.length) {
|
|
1288
|
+
const box = walk.pop();
|
|
1289
|
+
for (const child of box.children)
|
|
1290
|
+
walk.push(child);
|
|
1291
|
+
if (!box.lines)
|
|
1292
|
+
continue;
|
|
1293
|
+
for (const line of box.lines) {
|
|
1294
|
+
for (const text of line.texts) {
|
|
1295
|
+
texts.push(text);
|
|
1296
|
+
if (relaid.has(text.layout))
|
|
1297
|
+
continue;
|
|
1298
|
+
const next = reinked(text, layouts, changed, tree.styles);
|
|
1299
|
+
if (next === false)
|
|
1300
|
+
return false;
|
|
1301
|
+
relaid.set(text.layout, next);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
// and only now, all of it
|
|
1306
|
+
for (const [box, style] of restyled)
|
|
1307
|
+
box.style = style;
|
|
1308
|
+
for (const [box, decoration] of redecorated)
|
|
1309
|
+
box.decoration = decoration;
|
|
1310
|
+
for (const text of texts) {
|
|
1311
|
+
const next = relaid.get(text.layout);
|
|
1312
|
+
if (next)
|
|
1313
|
+
text.layout = next;
|
|
1314
|
+
}
|
|
1315
|
+
for (const [el, style] of changed) {
|
|
1316
|
+
tree.styles.set(el, { style, inFlex: tree.styles.get(el).inFlex });
|
|
1317
|
+
}
|
|
1318
|
+
return 'painted';
|
|
1319
|
+
}
|
|
540
1320
|
/** The document, for an application that wants to read or change it. */
|
|
541
1321
|
get document() {
|
|
542
1322
|
return this._source.document;
|
|
@@ -550,6 +1330,7 @@ export class HtmlViewNode extends Node {
|
|
|
550
1330
|
*/
|
|
551
1331
|
touchDocument() {
|
|
552
1332
|
this._source.touch();
|
|
1333
|
+
this._updateBase();
|
|
553
1334
|
this._sweep();
|
|
554
1335
|
this._invalidate(Stale.Style);
|
|
555
1336
|
}
|
|
@@ -600,20 +1381,86 @@ export class HtmlViewNode extends Node {
|
|
|
600
1381
|
damage = { x: 0, y: 0, width: window.width, height: window.height };
|
|
601
1382
|
}
|
|
602
1383
|
}
|
|
1384
|
+
try {
|
|
1385
|
+
this._paint(ctx, tree, range, damage);
|
|
1386
|
+
}
|
|
1387
|
+
catch (error) {
|
|
1388
|
+
this._fail(error, this._laidOutWidth);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
_paint(ctx, tree, range, damage) {
|
|
603
1392
|
paintDocument(ctx, tree, {
|
|
604
1393
|
originX: this.abs.x,
|
|
605
1394
|
originY: this.abs.y,
|
|
1395
|
+
// the root's background covers the whole element, not only the
|
|
1396
|
+
// document: an element grown past its content is canvas too
|
|
1397
|
+
canvas: this.abs,
|
|
606
1398
|
scale: this._scale,
|
|
607
1399
|
damage,
|
|
608
1400
|
selection: range
|
|
609
1401
|
? { start: this._toUnits(range.start), end: this._toUnits(range.end) }
|
|
610
1402
|
: null,
|
|
611
1403
|
selectionColor: this.selectionColor,
|
|
612
|
-
imageFor: (box) =>
|
|
1404
|
+
imageFor: (box) => {
|
|
1405
|
+
const url = box.el ? imageUrlOf(box.el) : CONTENT_IMAGES.get(box);
|
|
1406
|
+
return url === undefined ? null : this._resources.image(url);
|
|
1407
|
+
},
|
|
1408
|
+
backgroundImageFor: (url) => {
|
|
1409
|
+
const image = this._resources.image(url);
|
|
1410
|
+
const size = image ? this._resources.imageSize(url) : null;
|
|
1411
|
+
return image && size ? { image, ...size } : null;
|
|
1412
|
+
},
|
|
1413
|
+
cached: (key, width, height, draw) => (this._shadowCache ??= new SurfaceCache(this.app)).get(key, width, height, draw),
|
|
613
1414
|
});
|
|
614
1415
|
}
|
|
615
1416
|
}
|
|
616
1417
|
const EMPTY_SET = new Set();
|
|
1418
|
+
/** The first box an element made, depth first. */
|
|
1419
|
+
function boxFor(root, element) {
|
|
1420
|
+
const stack = [root];
|
|
1421
|
+
while (stack.length) {
|
|
1422
|
+
const box = stack.pop();
|
|
1423
|
+
if (box.el === element)
|
|
1424
|
+
return box;
|
|
1425
|
+
for (let i = box.children.length - 1; i >= 0; i -= 1) {
|
|
1426
|
+
stack.push(box.children[i]);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
return null;
|
|
1430
|
+
}
|
|
1431
|
+
/** Where the document's text goes on after a box with none: the start of
|
|
1432
|
+
* the next text in document order, or the end of the last before it. */
|
|
1433
|
+
function textAfter(root, target) {
|
|
1434
|
+
const stack = [root];
|
|
1435
|
+
let passed = false;
|
|
1436
|
+
let before = 0;
|
|
1437
|
+
while (stack.length) {
|
|
1438
|
+
const box = stack.pop();
|
|
1439
|
+
if (box === target) {
|
|
1440
|
+
passed = true;
|
|
1441
|
+
continue;
|
|
1442
|
+
}
|
|
1443
|
+
if (box.kind === 'text' && box.textEnd > box.textStart) {
|
|
1444
|
+
if (passed)
|
|
1445
|
+
return box.textStart;
|
|
1446
|
+
before = box.textEnd;
|
|
1447
|
+
}
|
|
1448
|
+
for (let i = box.children.length - 1; i >= 0; i -= 1) {
|
|
1449
|
+
stack.push(box.children[i]);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
return before;
|
|
1453
|
+
}
|
|
1454
|
+
function unionRect(a, b) {
|
|
1455
|
+
const x = Math.min(a.x, b.x);
|
|
1456
|
+
const y = Math.min(a.y, b.y);
|
|
1457
|
+
return {
|
|
1458
|
+
x,
|
|
1459
|
+
y,
|
|
1460
|
+
width: Math.max(a.x + a.width, b.x + b.width) - x,
|
|
1461
|
+
height: Math.max(a.y + a.height, b.y + b.height) - y,
|
|
1462
|
+
};
|
|
1463
|
+
}
|
|
617
1464
|
function textOf(el) {
|
|
618
1465
|
let out = '';
|
|
619
1466
|
for (const child of el.children) {
|
|
@@ -640,12 +1487,24 @@ function sameRects(a, b) {
|
|
|
640
1487
|
p.x !== q.x ||
|
|
641
1488
|
p.y !== q.y ||
|
|
642
1489
|
p.width !== q.width ||
|
|
643
|
-
p.height !== q.height
|
|
1490
|
+
p.height !== q.height ||
|
|
1491
|
+
!sameBare(p.bare, q.bare)) {
|
|
644
1492
|
return false;
|
|
645
1493
|
}
|
|
646
1494
|
}
|
|
647
1495
|
return true;
|
|
648
1496
|
}
|
|
1497
|
+
function sameBare(a, b) {
|
|
1498
|
+
if (!a || !b)
|
|
1499
|
+
return a === b;
|
|
1500
|
+
return (a.x === b.x &&
|
|
1501
|
+
a.y === b.y &&
|
|
1502
|
+
a.width === b.width &&
|
|
1503
|
+
a.height === b.height &&
|
|
1504
|
+
a.color === b.color &&
|
|
1505
|
+
a.fontFamily === b.fontFamily &&
|
|
1506
|
+
a.fontSize === b.fontSize);
|
|
1507
|
+
}
|
|
649
1508
|
// --- walks over the laid-out tree -------------------------------------------
|
|
650
1509
|
/** Distance from a coordinate to an interval, zero inside it. */
|
|
651
1510
|
function axisDistance(v, lo, span) {
|
|
@@ -685,7 +1544,7 @@ function nearestText(box, x, y) {
|
|
|
685
1544
|
const units = offsets.length
|
|
686
1545
|
? offsets[Math.max(0, Math.min(local, offsets.length - 1))]
|
|
687
1546
|
: local;
|
|
688
|
-
best = text.textStart
|
|
1547
|
+
best = Math.max(text.textStart, documentOffsetOf(text, units));
|
|
689
1548
|
}
|
|
690
1549
|
};
|
|
691
1550
|
const visit = (node) => {
|
|
@@ -799,7 +1658,7 @@ function caretAt(box, units) {
|
|
|
799
1658
|
if (units < text.textStart || units > text.textEnd)
|
|
800
1659
|
continue;
|
|
801
1660
|
const offsets = layoutOffsetsOf(text.layout);
|
|
802
|
-
const layoutUnits = text
|
|
1661
|
+
const layoutUnits = layoutOffsetOf(text, units);
|
|
803
1662
|
const caret = text.layout.caretPosition(codePointAtOffset(offsets, layoutUnits));
|
|
804
1663
|
found = { x: text.drawX + caret.x, y: line.y, height: line.height };
|
|
805
1664
|
return;
|
|
@@ -820,50 +1679,140 @@ function caretAt(box, units) {
|
|
|
820
1679
|
/** Every band a document range covers, in window coordinates. The subtree
|
|
821
1680
|
* text ranges prune the walk to the boxes the range actually crosses, so a
|
|
822
1681
|
* drag's small range costs its own paragraphs; only Ctrl+A pays for all. */
|
|
823
|
-
|
|
824
|
-
|
|
1682
|
+
/**
|
|
1683
|
+
* What an inline box reaches on each line besides its text, as `out`
|
|
1684
|
+
* rectangles as tall as the line: its own padding and border where it
|
|
1685
|
+
* starts or ends there — its edge less its margin, which is outside it —
|
|
1686
|
+
* and the inline-blocks and inline boxes' edges inside it, whole. The rest
|
|
1687
|
+
* of its border box across, which its text alone missed: a padded link was
|
|
1688
|
+
* as wide as its words (`elementRect`).
|
|
1689
|
+
*/
|
|
1690
|
+
function fragmentReach(box, out) {
|
|
1691
|
+
let block = box.parent;
|
|
1692
|
+
while (block && !block.lines)
|
|
1693
|
+
block = block.parent;
|
|
1694
|
+
if (!block?.lines)
|
|
825
1695
|
return;
|
|
826
|
-
|
|
1696
|
+
const inside = (b) => {
|
|
1697
|
+
for (let at = b; at && at !== block; at = at.parent) {
|
|
1698
|
+
if (at === box)
|
|
1699
|
+
return true;
|
|
1700
|
+
}
|
|
1701
|
+
return false;
|
|
1702
|
+
};
|
|
1703
|
+
const rtl = box.style.direction === 'rtl';
|
|
1704
|
+
for (const line of block.lines) {
|
|
1705
|
+
let left = Infinity;
|
|
1706
|
+
let right = -Infinity;
|
|
1707
|
+
for (const edge of line.edges ?? []) {
|
|
1708
|
+
if (edge.box === box) {
|
|
1709
|
+
// the element's `direction` says which side its start is on, as
|
|
1710
|
+
// paint reads it (`paintInlineBoxes`)
|
|
1711
|
+
const onLeft = (edge.side === 'start') !== rtl;
|
|
1712
|
+
left = Math.min(left, onLeft ? edge.x + box.marginLeft : edge.x);
|
|
1713
|
+
right = Math.max(right, onLeft ? edge.x + edge.width : edge.x + edge.width - box.marginRight);
|
|
1714
|
+
}
|
|
1715
|
+
else if (inside(edge.box)) {
|
|
1716
|
+
left = Math.min(left, edge.x);
|
|
1717
|
+
right = Math.max(right, edge.x + edge.width);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
for (const placed of line.atomics) {
|
|
1721
|
+
if (!inside(placed.box))
|
|
1722
|
+
continue;
|
|
1723
|
+
left = Math.min(left, placed.x - placed.box.marginLeft);
|
|
1724
|
+
right = Math.max(right, placed.x + placed.box.width + placed.box.marginRight);
|
|
1725
|
+
}
|
|
1726
|
+
if (right > left) {
|
|
1727
|
+
out.push({
|
|
1728
|
+
x: left,
|
|
1729
|
+
y: line.y,
|
|
1730
|
+
width: right - left,
|
|
1731
|
+
height: line.height,
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* An inline element's bands made as tall as its fragments' border boxes,
|
|
1738
|
+
* as CSSOM View takes an inline box's client rects (6.1): its font's
|
|
1739
|
+
* content area about its own baseline, with the padding and the border
|
|
1740
|
+
* above and below it, which take no room on the line (CSS 2.1 10.6.1) and
|
|
1741
|
+
* which paint draws the background over (`paintInlineBoxes`). A band is a
|
|
1742
|
+
* line's height across until then: a link padded 10px below measured as
|
|
1743
|
+
* tall as its line and no taller.
|
|
1744
|
+
*/
|
|
1745
|
+
function fragmentHeights(box, bands, fonts) {
|
|
1746
|
+
let block = box.parent;
|
|
1747
|
+
while (block && !block.lines)
|
|
1748
|
+
block = block.parent;
|
|
1749
|
+
if (!block?.lines?.length)
|
|
827
1750
|
return;
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1751
|
+
const face = faceExtentOf(fonts, box.style);
|
|
1752
|
+
const byTop = new Map();
|
|
1753
|
+
for (const line of block.lines)
|
|
1754
|
+
byTop.set(line.y, line);
|
|
1755
|
+
for (let i = 0; i < bands.length; i += 1) {
|
|
1756
|
+
const band = bands[i];
|
|
1757
|
+
const line = byTop.get(band.y);
|
|
1758
|
+
if (!line)
|
|
1759
|
+
continue;
|
|
1760
|
+
// on its own baseline, which `vertical-align` may raise off the line's
|
|
1761
|
+
const raise = SHIFTED_LINES.has(line)
|
|
1762
|
+
? (LINE_BOX_RAISES.get(line)?.get(box) ?? BOX_RAISES.get(box) ?? 0)
|
|
1763
|
+
: 0;
|
|
1764
|
+
const baseline = line.y + line.baseline - raise;
|
|
1765
|
+
const top = baseline - face.ascent - box.padTop - box.borderTop;
|
|
1766
|
+
const bottom = baseline + face.descent + box.padBottom + box.borderBottom;
|
|
1767
|
+
bands[i] = { x: band.x, y: top, width: band.width, height: bottom - top };
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
/** The bands of a text range on one block's own lines. */
|
|
1771
|
+
function lineBands(lines, from, to, dx, dy, out) {
|
|
1772
|
+
// First line whose text can reach `from`, by binary search over the
|
|
1773
|
+
// sorted text starts; stop at the first line past `to`.
|
|
1774
|
+
let lo = 0;
|
|
1775
|
+
let hi = lines.length;
|
|
1776
|
+
while (lo < hi) {
|
|
1777
|
+
const mid = (lo + hi) >> 1;
|
|
1778
|
+
if (lines[mid].textEnd > from)
|
|
1779
|
+
hi = mid;
|
|
1780
|
+
else
|
|
1781
|
+
lo = mid + 1;
|
|
1782
|
+
}
|
|
1783
|
+
for (let i = lo; i < lines.length; i += 1) {
|
|
1784
|
+
const line = lines[i];
|
|
1785
|
+
if (line.textStart >= to)
|
|
1786
|
+
break;
|
|
1787
|
+
if (line.textEnd > from && line.textStart < to) {
|
|
1788
|
+
for (const text of line.texts) {
|
|
1789
|
+
const natural = text.layout.lines[text.layoutLine];
|
|
1790
|
+
if (!natural)
|
|
1791
|
+
continue;
|
|
1792
|
+
const a = Math.max(from, text.textStart);
|
|
1793
|
+
const b = Math.min(to, text.textEnd);
|
|
1794
|
+
if (b <= a)
|
|
1795
|
+
continue;
|
|
1796
|
+
const offsets = layoutOffsetsOf(text.layout);
|
|
1797
|
+
for (const band of bandsFor(text.layout, natural, offsets, layoutOffsetOf(text, a), layoutOffsetOf(text, b, true))) {
|
|
1798
|
+
out.push({
|
|
1799
|
+
x: dx + band.x + text.drawX,
|
|
1800
|
+
y: dy + line.y,
|
|
1801
|
+
width: band.width,
|
|
1802
|
+
height: line.height,
|
|
1803
|
+
});
|
|
863
1804
|
}
|
|
864
1805
|
}
|
|
865
1806
|
}
|
|
866
1807
|
}
|
|
1808
|
+
}
|
|
1809
|
+
function collectBands(box, from, to, dx, dy, out) {
|
|
1810
|
+
if (box.subtreeTextEnd <= box.subtreeTextStart)
|
|
1811
|
+
return;
|
|
1812
|
+
if (box.subtreeTextEnd <= from || box.subtreeTextStart >= to)
|
|
1813
|
+
return;
|
|
1814
|
+
if (box.lines)
|
|
1815
|
+
lineBands(box.lines, from, to, dx, dy, out);
|
|
867
1816
|
// Atomics are ordinary children, reached below.
|
|
868
1817
|
for (const child of box.children) {
|
|
869
1818
|
if (child.kind === 'text' || child.kind === 'break')
|
|
@@ -871,10 +1820,105 @@ function collectBands(box, from, to, dx, dy, out) {
|
|
|
871
1820
|
collectBands(child, from, to, dx, dy, out);
|
|
872
1821
|
}
|
|
873
1822
|
}
|
|
1823
|
+
/** The layers of a hit test, in the order CSS paints them within a
|
|
1824
|
+
* context (`deepestAt`). */
|
|
1825
|
+
const HIT_NEGATIVE = -1;
|
|
1826
|
+
const HIT_BLOCK = 0;
|
|
1827
|
+
const HIT_FLOAT = 1;
|
|
1828
|
+
const HIT_INLINE = 2;
|
|
1829
|
+
const HIT_POSITIONED = 3;
|
|
874
1830
|
/** The deepest element box containing a document-space point. */
|
|
875
|
-
function deepestAt(
|
|
1831
|
+
function deepestAt(tree, x, y,
|
|
1832
|
+
/** Told whether what was found was found under text: a run's, rather
|
|
1833
|
+
* than a box's. */
|
|
1834
|
+
hit) {
|
|
1835
|
+
const box = tree.root;
|
|
876
1836
|
let found = box.el;
|
|
877
|
-
|
|
1837
|
+
let foundKey = [];
|
|
1838
|
+
let viaText = false;
|
|
1839
|
+
// What is under a point is what was painted there last (CSS 2.1 Appendix
|
|
1840
|
+
// E): within a context, an in-flow block's own box, then a float over it,
|
|
1841
|
+
// then a line's text and atomics, then a positioned box — and a float, an
|
|
1842
|
+
// atomic or a positioned box paints its own content whole in its turn,
|
|
1843
|
+
// those layers again inside it. So a hit carries the layers down to it,
|
|
1844
|
+
// and takes the place of the one before where those come after them, or
|
|
1845
|
+
// tie: an infobox floated out of one section hangs over the next, whose
|
|
1846
|
+
// own box took every link in it, and a skin that puts the article in a
|
|
1847
|
+
// `position: relative` box put all of it in one layer. Positioned boxes
|
|
1848
|
+
// are painted in `z-index` order and then the document's (`byZIndex`),
|
|
1849
|
+
// the negative ones under the flow: the Zen Garden's `›` has
|
|
1850
|
+
// `z-index: 3` over the bar the "View All Designs" link fills after it.
|
|
1851
|
+
const take = (el, key, text) => {
|
|
1852
|
+
if (compareKeys(key, foundKey) < 0)
|
|
1853
|
+
return;
|
|
1854
|
+
found = el;
|
|
1855
|
+
foundKey = key;
|
|
1856
|
+
viaText = text;
|
|
1857
|
+
};
|
|
1858
|
+
// A box is walked into wherever it draws — its reach, overflow and all
|
|
1859
|
+
// (`computePaintBounds`) — and named only where its own rectangle is. A
|
|
1860
|
+
// page's `html, body { height: 100% }` is one viewport tall and its
|
|
1861
|
+
// article overflows it, and a walk that went no further than a box's own
|
|
1862
|
+
// rectangle found nothing below the first screen: once Wikipedia was
|
|
1863
|
+
// scrolled, no link lit up. One whose reach is not known yet — before its
|
|
1864
|
+
// first paint — is walked into at its rectangle, as before.
|
|
1865
|
+
//
|
|
1866
|
+
// A box that clips what overflows it hides what it holds past its edge —
|
|
1867
|
+
// but not the positioned boxes whose containing block is outside it (CSS
|
|
1868
|
+
// 2.1 11.1.1), which paint puts off until its clip ends
|
|
1869
|
+
// (`paintPositioned`). So past the edge the walk goes on only into a box
|
|
1870
|
+
// that holds positioned ones, carrying the clips the point is outside
|
|
1871
|
+
// of, and names nothing until a positioned box escapes them all: the
|
|
1872
|
+
// Zen Garden's archive links are absolute `<li>`s in an `overflow:
|
|
1873
|
+
// hidden` list with no height of its own, and not one of them could be
|
|
1874
|
+
// hovered or pressed.
|
|
1875
|
+
const enter = (child, context, clipped) => {
|
|
1876
|
+
const style = child.style;
|
|
1877
|
+
if (style.position !== 'static' ||
|
|
1878
|
+
(child.parent?.kind === 'flex' && typeof style.zIndex === 'number')) {
|
|
1879
|
+
// a flex item with a `z-index` is layered unpositioned (`layered`)
|
|
1880
|
+
const z = style.zIndex === 'auto' ? 0 : style.zIndex;
|
|
1881
|
+
context = [...context, z < 0 ? HIT_NEGATIVE : HIT_POSITIONED, z];
|
|
1882
|
+
}
|
|
1883
|
+
else if (style.float !== 'none')
|
|
1884
|
+
context = [...context, HIT_FLOAT];
|
|
1885
|
+
if (clipped.length !== 0 && child.outOfFlow) {
|
|
1886
|
+
const containing = containingBlockOf(child);
|
|
1887
|
+
clipped = containing
|
|
1888
|
+
? clipped.filter((clip) => holds(clip, containing))
|
|
1889
|
+
: [];
|
|
1890
|
+
}
|
|
1891
|
+
const inside = x >= child.x &&
|
|
1892
|
+
x < child.x + child.width &&
|
|
1893
|
+
y >= child.y &&
|
|
1894
|
+
y < child.y + child.height;
|
|
1895
|
+
const own = inside && hasRect(child);
|
|
1896
|
+
if (!own) {
|
|
1897
|
+
const reach = child.boundsY;
|
|
1898
|
+
const known = Number.isFinite(reach) &&
|
|
1899
|
+
(child.boundsWidth > 0 || child.boundsHeight > 0);
|
|
1900
|
+
if (!known) {
|
|
1901
|
+
if (!inside)
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
else if (x < child.boundsX ||
|
|
1905
|
+
x >= child.boundsX + child.boundsWidth ||
|
|
1906
|
+
y < reach ||
|
|
1907
|
+
y >= reach + child.boundsHeight) {
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
if (clipsOverflow(child)) {
|
|
1911
|
+
if (!holdsAbsolute(child))
|
|
1912
|
+
return;
|
|
1913
|
+
clipped = [...clipped, child];
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
if (own && child.el && clipped.length === 0) {
|
|
1917
|
+
take(child.el, [...context, HIT_BLOCK], false);
|
|
1918
|
+
}
|
|
1919
|
+
visit(child, context, clipped);
|
|
1920
|
+
};
|
|
1921
|
+
const visit = (node, context, clipped) => {
|
|
878
1922
|
// The paint index answers a point query too — the wide level of a flat
|
|
879
1923
|
// document is the root's child list, and a hit test that walked all of
|
|
880
1924
|
// it would run per pointer move once hover is in the picture.
|
|
@@ -884,43 +1928,26 @@ function deepestAt(box, x, y) {
|
|
|
884
1928
|
for (const child of candidates) {
|
|
885
1929
|
if (child.kind === 'text' || child.kind === 'break')
|
|
886
1930
|
continue;
|
|
887
|
-
|
|
888
|
-
x < child.x + child.width &&
|
|
889
|
-
y >= child.y &&
|
|
890
|
-
y < child.y + child.height) {
|
|
891
|
-
if (child.el)
|
|
892
|
-
found = child.el;
|
|
893
|
-
visit(child);
|
|
894
|
-
}
|
|
1931
|
+
enter(child, context, clipped);
|
|
895
1932
|
}
|
|
896
1933
|
if (node.paintIndex && node.positionedPaint) {
|
|
897
1934
|
for (const child of node.positionedPaint) {
|
|
898
|
-
|
|
899
|
-
x < child.x + child.width &&
|
|
900
|
-
y >= child.y &&
|
|
901
|
-
y < child.y + child.height) {
|
|
902
|
-
if (child.el)
|
|
903
|
-
found = child.el;
|
|
904
|
-
visit(child);
|
|
905
|
-
}
|
|
1935
|
+
enter(child, context, clipped);
|
|
906
1936
|
}
|
|
907
1937
|
}
|
|
908
1938
|
if (node.lines) {
|
|
909
1939
|
for (const line of node.lines) {
|
|
910
1940
|
for (const placed of line.atomics) {
|
|
911
|
-
|
|
912
|
-
x < placed.box.x + placed.box.width &&
|
|
913
|
-
y >= placed.box.y &&
|
|
914
|
-
y < placed.box.y + placed.box.height) {
|
|
915
|
-
if (placed.box.el)
|
|
916
|
-
found = placed.box.el;
|
|
917
|
-
visit(placed.box);
|
|
918
|
-
}
|
|
1941
|
+
enter(placed.box, [...context, HIT_INLINE], clipped);
|
|
919
1942
|
}
|
|
920
1943
|
// An inline box has no box of its own — its extent is the runs on
|
|
921
1944
|
// this line — so the element under a point inside a paragraph is
|
|
922
|
-
// found from the run rather than from a rectangle
|
|
923
|
-
|
|
1945
|
+
// found from the run rather than from a rectangle: from where its
|
|
1946
|
+
// text sits in the document, whose text boxes know their element.
|
|
1947
|
+
// Not from the run itself, whose layout may be one an earlier parse
|
|
1948
|
+
// made (`TextLayoutCache`), and which an engine may hand back with
|
|
1949
|
+
// nothing on it but its extent.
|
|
1950
|
+
if (clipped.length === 0 && y >= line.y && y < line.y + line.height) {
|
|
924
1951
|
for (const text of line.texts) {
|
|
925
1952
|
const natural = text.layout.lines[text.layoutLine];
|
|
926
1953
|
if (!natural)
|
|
@@ -928,10 +1955,9 @@ function deepestAt(box, x, y) {
|
|
|
928
1955
|
for (const run of natural.runs) {
|
|
929
1956
|
const left = text.drawX + natural.x + run.x;
|
|
930
1957
|
if (x >= left && x < left + run.width) {
|
|
931
|
-
const owner = run.
|
|
932
|
-
?.element;
|
|
1958
|
+
const owner = ownerOf(tree.textBoxes, text.spans.documentAt(run.start));
|
|
933
1959
|
if (owner)
|
|
934
|
-
|
|
1960
|
+
take(owner, [...context, HIT_INLINE], true);
|
|
935
1961
|
}
|
|
936
1962
|
}
|
|
937
1963
|
}
|
|
@@ -939,7 +1965,273 @@ function deepestAt(box, x, y) {
|
|
|
939
1965
|
}
|
|
940
1966
|
}
|
|
941
1967
|
};
|
|
942
|
-
visit(box);
|
|
1968
|
+
visit(box, [], []);
|
|
1969
|
+
if (hit)
|
|
1970
|
+
hit.text = viaText;
|
|
943
1971
|
return found;
|
|
944
1972
|
}
|
|
1973
|
+
/** Paint order between two hits' layers, outermost first: negative where
|
|
1974
|
+
* `a` was painted under `b`. */
|
|
1975
|
+
function compareKeys(a, b) {
|
|
1976
|
+
const n = Math.min(a.length, b.length);
|
|
1977
|
+
for (let i = 0; i < n; i += 1)
|
|
1978
|
+
if (a[i] !== b[i])
|
|
1979
|
+
return a[i] - b[i];
|
|
1980
|
+
return a.length - b.length;
|
|
1981
|
+
}
|
|
1982
|
+
// --- a pointer move restyled where it happened (`_hoverInPlace`) -----------
|
|
1983
|
+
/** How many elements a pointer move restyles in place before the document
|
|
1984
|
+
* is built again instead: a link's subtree is a handful, and a compound
|
|
1985
|
+
* that matches a container reaches everything in it. */
|
|
1986
|
+
const HOVER_RESTYLE_LIMIT = 300;
|
|
1987
|
+
/**
|
|
1988
|
+
* The computed properties a pointer move may change in place: ink, which
|
|
1989
|
+
* moves nothing. A background colour is drawn inside the box it colours
|
|
1990
|
+
* and a border's colour on the border it has; `box-shadow`, `text-shadow`
|
|
1991
|
+
* and an outline's width reach past it, where the paint index has already
|
|
1992
|
+
* looked, and a background image has to be fetched.
|
|
1993
|
+
*/
|
|
1994
|
+
const PAINT_ONLY = new Set([
|
|
1995
|
+
'color',
|
|
1996
|
+
'textFillColor',
|
|
1997
|
+
'cursor',
|
|
1998
|
+
'backgroundColor',
|
|
1999
|
+
'borderTopColor',
|
|
2000
|
+
'borderRightColor',
|
|
2001
|
+
'borderBottomColor',
|
|
2002
|
+
'borderLeftColor',
|
|
2003
|
+
'outlineColor',
|
|
2004
|
+
'textDecorationLine',
|
|
2005
|
+
'textDecorationColor',
|
|
2006
|
+
'textDecorationStyle',
|
|
2007
|
+
'textDecorationThickness',
|
|
2008
|
+
'textUnderlineOffset',
|
|
2009
|
+
'underline',
|
|
2010
|
+
'underlineStyle',
|
|
2011
|
+
'underlineThickness',
|
|
2012
|
+
'underlineOffset',
|
|
2013
|
+
'lineThrough',
|
|
2014
|
+
]);
|
|
2015
|
+
/** The fields of a run its ink is: what `runFor` takes from `PAINT_ONLY`. */
|
|
2016
|
+
const INK_FIELDS = [
|
|
2017
|
+
'color',
|
|
2018
|
+
'underline',
|
|
2019
|
+
'underlineStyle',
|
|
2020
|
+
'underlineOffset',
|
|
2021
|
+
'underlineThickness',
|
|
2022
|
+
'strike',
|
|
2023
|
+
];
|
|
2024
|
+
/** The fields of a run its shape is, which ink never changes. */
|
|
2025
|
+
const FACE_FIELDS = [
|
|
2026
|
+
'family',
|
|
2027
|
+
'size',
|
|
2028
|
+
'weight',
|
|
2029
|
+
'style',
|
|
2030
|
+
'letterSpacing',
|
|
2031
|
+
'features',
|
|
2032
|
+
];
|
|
2033
|
+
/** Whether two styles differ in ink alone: true where they do, null where
|
|
2034
|
+
* they do not differ, false where something else does. Custom properties
|
|
2035
|
+
* are read through the properties that use them. */
|
|
2036
|
+
function inkOnly(was, now) {
|
|
2037
|
+
const a = was;
|
|
2038
|
+
const b = now;
|
|
2039
|
+
let ink = false;
|
|
2040
|
+
for (const key in b) {
|
|
2041
|
+
if (key === 'custom' || sameValue(a[key], b[key]))
|
|
2042
|
+
continue;
|
|
2043
|
+
if (!PAINT_ONLY.has(key))
|
|
2044
|
+
return false;
|
|
2045
|
+
ink = true;
|
|
2046
|
+
}
|
|
2047
|
+
return ink ? true : null;
|
|
2048
|
+
}
|
|
2049
|
+
/** Structural equality for a computed value: a number, a string, or the
|
|
2050
|
+
* plain objects and arrays a length or a shadow list is. */
|
|
2051
|
+
function sameValue(x, y) {
|
|
2052
|
+
if (x === y)
|
|
2053
|
+
return true;
|
|
2054
|
+
if (typeof x === 'number' && typeof y === 'number') {
|
|
2055
|
+
return Number.isNaN(x) && Number.isNaN(y);
|
|
2056
|
+
}
|
|
2057
|
+
if (!x || !y || typeof x !== 'object' || typeof y !== 'object')
|
|
2058
|
+
return false;
|
|
2059
|
+
if (Array.isArray(x) !== Array.isArray(y))
|
|
2060
|
+
return false;
|
|
2061
|
+
const a = x;
|
|
2062
|
+
const b = y;
|
|
2063
|
+
const keys = Object.keys(a);
|
|
2064
|
+
if (keys.length !== Object.keys(b).length)
|
|
2065
|
+
return false;
|
|
2066
|
+
for (const key of keys)
|
|
2067
|
+
if (!sameValue(a[key], b[key]))
|
|
2068
|
+
return false;
|
|
2069
|
+
return true;
|
|
2070
|
+
}
|
|
2071
|
+
/** The element an anonymous box takes its style from: its nearest
|
|
2072
|
+
* ancestor's that has one. */
|
|
2073
|
+
function nearestElement(box) {
|
|
2074
|
+
for (let at = box.parent; at; at = at.parent)
|
|
2075
|
+
if (at.el)
|
|
2076
|
+
return at.el;
|
|
2077
|
+
return null;
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* `text`'s layout made again with the ink of the elements a pointer move
|
|
2081
|
+
* restyled: from the runs it was made from, each of a changed element's
|
|
2082
|
+
* given the ink its new style makes (`runFor`) and nothing else. Null where
|
|
2083
|
+
* none of its runs is theirs; false where that cannot be told — a run this
|
|
2084
|
+
* cannot place in the document, one some other pass inked (a first line's),
|
|
2085
|
+
* or a layout that comes out another shape.
|
|
2086
|
+
*/
|
|
2087
|
+
function reinked(text, layouts, changed, styles) {
|
|
2088
|
+
const spans = text.spans;
|
|
2089
|
+
const ownerAt = (offset) => spans.boxAt ? (spans.boxAt(offset)?.el ?? null) : null;
|
|
2090
|
+
const inputs = layouts.inputsOf(text.layout);
|
|
2091
|
+
if (!inputs || !spans.boxAt) {
|
|
2092
|
+
// not one this could make again: none of its text may be theirs
|
|
2093
|
+
for (const line of text.layout.lines) {
|
|
2094
|
+
for (const run of line.runs) {
|
|
2095
|
+
const owner = spans.boxAt ? ownerAt(run.start) : null;
|
|
2096
|
+
if (!spans.boxAt || (owner && changed.has(owner)))
|
|
2097
|
+
return false;
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
return null;
|
|
2101
|
+
}
|
|
2102
|
+
let runs = null;
|
|
2103
|
+
let offset = 0;
|
|
2104
|
+
const content = inputs.content;
|
|
2105
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
2106
|
+
const run = content[i];
|
|
2107
|
+
const length = run.text.length;
|
|
2108
|
+
const owner = length ? ownerAt(offset) : null;
|
|
2109
|
+
const style = owner ? changed.get(owner) : undefined;
|
|
2110
|
+
if (owner && style) {
|
|
2111
|
+
if (ownerAt(offset + length - 1) !== owner)
|
|
2112
|
+
return false;
|
|
2113
|
+
const was = runFor(run.text, styles.get(owner).style);
|
|
2114
|
+
const now = runFor(run.text, style);
|
|
2115
|
+
for (const f of FACE_FIELDS)
|
|
2116
|
+
if (!sameValue(was[f], now[f]))
|
|
2117
|
+
return false;
|
|
2118
|
+
let next = null;
|
|
2119
|
+
for (const f of INK_FIELDS) {
|
|
2120
|
+
// a run that is not what its style made — a first line's colour
|
|
2121
|
+
if (!sameValue(run[f], was[f]))
|
|
2122
|
+
return false;
|
|
2123
|
+
if (sameValue(was[f], now[f]))
|
|
2124
|
+
continue;
|
|
2125
|
+
next ??= { ...run };
|
|
2126
|
+
if (now[f] === undefined)
|
|
2127
|
+
delete next[f];
|
|
2128
|
+
else
|
|
2129
|
+
next[f] = now[f];
|
|
2130
|
+
}
|
|
2131
|
+
if (next) {
|
|
2132
|
+
runs ??= content.slice();
|
|
2133
|
+
runs[i] = next;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
offset += length;
|
|
2137
|
+
}
|
|
2138
|
+
if (!runs)
|
|
2139
|
+
return null;
|
|
2140
|
+
const layout = layouts.fonts.layout(runs, inputs.style, inputs.options);
|
|
2141
|
+
return sameShape(text.layout, layout) ? layout : false;
|
|
2142
|
+
}
|
|
2143
|
+
/** Whether two layouts put the same text in the same places: ink aside,
|
|
2144
|
+
* the same layout. */
|
|
2145
|
+
function sameShape(a, b) {
|
|
2146
|
+
if (a.width !== b.width || a.height !== b.height)
|
|
2147
|
+
return false;
|
|
2148
|
+
if (a.lines.length !== b.lines.length)
|
|
2149
|
+
return false;
|
|
2150
|
+
for (let i = 0; i < a.lines.length; i += 1) {
|
|
2151
|
+
const x = a.lines[i];
|
|
2152
|
+
const y = b.lines[i];
|
|
2153
|
+
if (x.x !== y.x ||
|
|
2154
|
+
x.y !== y.y ||
|
|
2155
|
+
x.width !== y.width ||
|
|
2156
|
+
x.height !== y.height ||
|
|
2157
|
+
x.baseline !== y.baseline ||
|
|
2158
|
+
x.ascent !== y.ascent ||
|
|
2159
|
+
x.descent !== y.descent ||
|
|
2160
|
+
x.start !== y.start ||
|
|
2161
|
+
x.end !== y.end ||
|
|
2162
|
+
x.runs.length !== y.runs.length) {
|
|
2163
|
+
return false;
|
|
2164
|
+
}
|
|
2165
|
+
for (let j = 0; j < x.runs.length; j += 1) {
|
|
2166
|
+
const r = x.runs[j];
|
|
2167
|
+
const t = y.runs[j];
|
|
2168
|
+
if (r.x !== t.x ||
|
|
2169
|
+
r.width !== t.width ||
|
|
2170
|
+
r.start !== t.start ||
|
|
2171
|
+
r.end !== t.end) {
|
|
2172
|
+
return false;
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
return true;
|
|
2177
|
+
}
|
|
2178
|
+
/** The element whose text holds a document index: the text box around it,
|
|
2179
|
+
* found by bisecting the boxes in document order. */
|
|
2180
|
+
function ownerOf(boxes, index) {
|
|
2181
|
+
let lo = 0;
|
|
2182
|
+
let hi = boxes.length - 1;
|
|
2183
|
+
while (lo < hi) {
|
|
2184
|
+
const mid = (lo + hi + 1) >> 1;
|
|
2185
|
+
if (boxes[mid].textStart <= index)
|
|
2186
|
+
lo = mid;
|
|
2187
|
+
else
|
|
2188
|
+
hi = mid - 1;
|
|
2189
|
+
}
|
|
2190
|
+
const box = boxes[lo];
|
|
2191
|
+
return box && index >= box.textStart && index < box.textEnd ? box.el : null;
|
|
2192
|
+
}
|
|
2193
|
+
/** The advance of a face's "0", laid out: null where the engine cannot
|
|
2194
|
+
* lay it out. */
|
|
2195
|
+
function zeroWidthOf(fonts, face) {
|
|
2196
|
+
const { family, size, weight } = face;
|
|
2197
|
+
// a run is upright or slanted, as `inline.ts` sets one
|
|
2198
|
+
const style = face.style === 'normal' ? 'normal' : 'italic';
|
|
2199
|
+
try {
|
|
2200
|
+
const run = { family, size, weight, style };
|
|
2201
|
+
return fonts.layout([{ text: '0', ...run }], run, {}).width;
|
|
2202
|
+
}
|
|
2203
|
+
catch {
|
|
2204
|
+
return null;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
/** A face's own line height, as the engine reports it: null where it
|
|
2208
|
+
* cannot say. */
|
|
2209
|
+
function normalLineOf(fonts, face) {
|
|
2210
|
+
const { family, size, weight, style } = face;
|
|
2211
|
+
try {
|
|
2212
|
+
const line = fonts
|
|
2213
|
+
.match(family, { size, weight, style })
|
|
2214
|
+
.metrics(size).lineHeight;
|
|
2215
|
+
return line > 0 ? line : null;
|
|
2216
|
+
}
|
|
2217
|
+
catch {
|
|
2218
|
+
return null;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
/** A face's x-height, as the engine reports it: null where the face
|
|
2222
|
+
* states none, or the engine does not say. */
|
|
2223
|
+
function xHeightOf(fonts, face) {
|
|
2224
|
+
const { family, size, weight, style } = face;
|
|
2225
|
+
try {
|
|
2226
|
+
const metrics = fonts
|
|
2227
|
+
.match(family, { size, weight, style })
|
|
2228
|
+
.metrics(size);
|
|
2229
|
+
const x = metrics.xHeight;
|
|
2230
|
+
// NaN where the face states none, which is a number
|
|
2231
|
+
return typeof x === 'number' && x > 0 ? x : null;
|
|
2232
|
+
}
|
|
2233
|
+
catch {
|
|
2234
|
+
return null;
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
945
2237
|
//# sourceMappingURL=node.js.map
|