@react-x11/components 0.8.0 → 0.9.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 +95 -34
- package/dist/charts/node.d.ts +1 -1
- package/dist/charts/node.d.ts.map +1 -1
- package/dist/charts/node.js +6 -2
- package/dist/charts/node.js.map +1 -1
- package/dist/embed/client.d.ts +48 -3
- package/dist/embed/client.d.ts.map +1 -1
- package/dist/embed/client.js +79 -5
- package/dist/embed/client.js.map +1 -1
- package/dist/embed/index.d.ts +1 -1
- package/dist/embed/index.d.ts.map +1 -1
- package/dist/embed/index.js +1 -1
- package/dist/embed/index.js.map +1 -1
- package/dist/html/node.d.ts +3 -1
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +7 -5
- package/dist/html/node.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{markdown → internal/markdown}/ast.d.ts +12 -0
- package/dist/internal/markdown/ast.d.ts.map +1 -0
- package/dist/internal/markdown/ast.js +22 -0
- package/dist/internal/markdown/ast.js.map +1 -0
- package/dist/internal/markdown/parse.d.ts.map +1 -0
- package/dist/{markdown → internal/markdown}/parse.js +112 -22
- package/dist/internal/markdown/parse.js.map +1 -0
- package/dist/internal/markdown/stringify.d.ts +4 -0
- package/dist/internal/markdown/stringify.d.ts.map +1 -0
- package/dist/internal/markdown/stringify.js +684 -0
- package/dist/internal/markdown/stringify.js.map +1 -0
- package/dist/internal/markdown/tags.d.ts.map +1 -0
- package/dist/internal/markdown/tags.js.map +1 -0
- package/dist/internal/scroll.d.ts +3 -2
- package/dist/internal/scroll.d.ts.map +1 -1
- package/dist/internal/scroll.js +1 -0
- package/dist/internal/scroll.js.map +1 -1
- package/dist/maps/anchors.d.ts +98 -0
- package/dist/maps/anchors.d.ts.map +1 -0
- package/dist/maps/anchors.js +531 -0
- package/dist/maps/anchors.js.map +1 -0
- package/dist/maps/controller.d.ts +283 -0
- package/dist/maps/controller.d.ts.map +1 -0
- package/dist/maps/controller.js +743 -0
- package/dist/maps/controller.js.map +1 -0
- package/dist/maps/gl/buckets.d.ts +95 -0
- package/dist/maps/gl/buckets.d.ts.map +1 -0
- package/dist/maps/gl/buckets.js +362 -0
- package/dist/maps/gl/buckets.js.map +1 -0
- package/dist/maps/gl/build-worker.d.ts +13 -0
- package/dist/maps/gl/build-worker.d.ts.map +1 -0
- package/dist/maps/gl/build-worker.js +44 -0
- package/dist/maps/gl/build-worker.js.map +1 -0
- package/dist/maps/gl/color.d.ts +8 -0
- package/dist/maps/gl/color.d.ts.map +1 -0
- package/dist/maps/gl/color.js +57 -0
- package/dist/maps/gl/color.js.map +1 -0
- package/dist/maps/gl/cover.d.ts +51 -0
- package/dist/maps/gl/cover.d.ts.map +1 -0
- package/dist/maps/gl/cover.js +124 -0
- package/dist/maps/gl/cover.js.map +1 -0
- package/dist/maps/gl/index.d.ts +3 -0
- package/dist/maps/gl/index.d.ts.map +1 -0
- package/dist/maps/gl/index.js +20 -0
- package/dist/maps/gl/index.js.map +1 -0
- package/dist/maps/gl/markers.d.ts +28 -0
- package/dist/maps/gl/markers.d.ts.map +1 -0
- package/dist/maps/gl/markers.js +60 -0
- package/dist/maps/gl/markers.js.map +1 -0
- package/dist/maps/gl/overlays.d.ts +68 -0
- package/dist/maps/gl/overlays.d.ts.map +1 -0
- package/dist/maps/gl/overlays.js +300 -0
- package/dist/maps/gl/overlays.js.map +1 -0
- package/dist/maps/gl/pane.d.ts +12 -0
- package/dist/maps/gl/pane.d.ts.map +1 -0
- package/dist/maps/gl/pane.js +37 -0
- package/dist/maps/gl/pane.js.map +1 -0
- package/dist/maps/gl/placement.d.ts +111 -0
- package/dist/maps/gl/placement.d.ts.map +1 -0
- package/dist/maps/gl/placement.js +567 -0
- package/dist/maps/gl/placement.js.map +1 -0
- package/dist/maps/gl/renderer.d.ts +352 -0
- package/dist/maps/gl/renderer.d.ts.map +1 -0
- package/dist/maps/gl/renderer.js +1127 -0
- package/dist/maps/gl/renderer.js.map +1 -0
- package/dist/maps/gl/shaders.d.ts +120 -0
- package/dist/maps/gl/shaders.d.ts.map +1 -0
- package/dist/maps/gl/shaders.js +451 -0
- package/dist/maps/gl/shaders.js.map +1 -0
- package/dist/maps/gl/store.d.ts +115 -0
- package/dist/maps/gl/store.d.ts.map +1 -0
- package/dist/maps/gl/store.js +469 -0
- package/dist/maps/gl/store.js.map +1 -0
- package/dist/maps/gl/text.d.ts +154 -0
- package/dist/maps/gl/text.d.ts.map +1 -0
- package/dist/maps/gl/text.js +382 -0
- package/dist/maps/gl/text.js.map +1 -0
- package/dist/maps/gl/view.d.ts +54 -0
- package/dist/maps/gl/view.d.ts.map +1 -0
- package/dist/maps/gl/view.js +974 -0
- package/dist/maps/gl/view.js.map +1 -0
- package/dist/maps/index.d.ts +1 -1
- package/dist/maps/index.d.ts.map +1 -1
- package/dist/maps/index.js +216 -52
- package/dist/maps/index.js.map +1 -1
- package/dist/maps/labels.d.ts +37 -16
- package/dist/maps/labels.d.ts.map +1 -1
- package/dist/maps/labels.js +188 -119
- package/dist/maps/labels.js.map +1 -1
- package/dist/maps/node.d.ts +162 -56
- package/dist/maps/node.d.ts.map +1 -1
- package/dist/maps/node.js +607 -515
- package/dist/maps/node.js.map +1 -1
- package/dist/maps/overlay.d.ts +72 -9
- package/dist/maps/overlay.d.ts.map +1 -1
- package/dist/maps/overlay.js +108 -28
- package/dist/maps/overlay.js.map +1 -1
- package/dist/maps/paint.d.ts +3 -0
- package/dist/maps/paint.d.ts.map +1 -1
- package/dist/maps/paint.js.map +1 -1
- package/dist/maps/proj.d.ts +14 -0
- package/dist/maps/proj.d.ts.map +1 -1
- package/dist/maps/proj.js +28 -0
- package/dist/maps/proj.js.map +1 -1
- package/dist/maps/renderer.d.ts +69 -0
- package/dist/maps/renderer.d.ts.map +1 -0
- package/dist/maps/renderer.js +66 -0
- package/dist/maps/renderer.js.map +1 -0
- package/dist/maps/sources.d.ts +25 -3
- package/dist/maps/sources.d.ts.map +1 -1
- package/dist/maps/sources.js +17 -0
- package/dist/maps/sources.js.map +1 -1
- package/dist/maps/theme.d.ts +19 -0
- package/dist/maps/theme.d.ts.map +1 -0
- package/dist/maps/theme.js +44 -0
- package/dist/maps/theme.js.map +1 -0
- package/dist/maps/tiles.d.ts +117 -17
- package/dist/maps/tiles.d.ts.map +1 -1
- package/dist/maps/tiles.js +163 -30
- package/dist/maps/tiles.js.map +1 -1
- package/dist/maps/types.d.ts +188 -20
- package/dist/maps/types.d.ts.map +1 -1
- package/dist/markdown/expressions.d.ts +1 -1
- package/dist/markdown/expressions.d.ts.map +1 -1
- package/dist/markdown/expressions.js.map +1 -1
- package/dist/markdown/index.d.ts +7 -6
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +9 -7
- package/dist/markdown/index.js.map +1 -1
- package/dist/markdown/spans.d.ts +1 -1
- package/dist/markdown/spans.d.ts.map +1 -1
- package/dist/media-player/index.d.ts +11 -3
- package/dist/media-player/index.d.ts.map +1 -1
- package/dist/media-player/index.js +13 -2
- package/dist/media-player/index.js.map +1 -1
- package/dist/rich-text-editor/clipboard.d.ts +23 -0
- package/dist/rich-text-editor/clipboard.d.ts.map +1 -0
- package/dist/rich-text-editor/clipboard.js +307 -0
- package/dist/rich-text-editor/clipboard.js.map +1 -0
- package/dist/rich-text-editor/collab.d.ts +32 -0
- package/dist/rich-text-editor/collab.d.ts.map +1 -0
- package/dist/rich-text-editor/collab.js +55 -0
- package/dist/rich-text-editor/collab.js.map +1 -0
- package/dist/rich-text-editor/commands.d.ts +50 -0
- package/dist/rich-text-editor/commands.d.ts.map +1 -0
- package/dist/rich-text-editor/commands.js +376 -0
- package/dist/rich-text-editor/commands.js.map +1 -0
- package/dist/rich-text-editor/drag.d.ts +68 -0
- package/dist/rich-text-editor/drag.d.ts.map +1 -0
- package/dist/rich-text-editor/drag.js +148 -0
- package/dist/rich-text-editor/drag.js.map +1 -0
- package/dist/rich-text-editor/html.d.ts +145 -0
- package/dist/rich-text-editor/html.d.ts.map +1 -0
- package/dist/rich-text-editor/html.js +516 -0
- package/dist/rich-text-editor/html.js.map +1 -0
- package/dist/rich-text-editor/index.d.ts +263 -0
- package/dist/rich-text-editor/index.d.ts.map +1 -0
- package/dist/rich-text-editor/index.js +822 -0
- package/dist/rich-text-editor/index.js.map +1 -0
- package/dist/rich-text-editor/inline.d.ts +94 -0
- package/dist/rich-text-editor/inline.d.ts.map +1 -0
- package/dist/rich-text-editor/inline.js +252 -0
- package/dist/rich-text-editor/inline.js.map +1 -0
- package/dist/rich-text-editor/keymap.d.ts +71 -0
- package/dist/rich-text-editor/keymap.d.ts.map +1 -0
- package/dist/rich-text-editor/keymap.js +393 -0
- package/dist/rich-text-editor/keymap.js.map +1 -0
- package/dist/rich-text-editor/keys.d.ts +29 -0
- package/dist/rich-text-editor/keys.d.ts.map +1 -0
- package/dist/rich-text-editor/keys.js +93 -0
- package/dist/rich-text-editor/keys.js.map +1 -0
- package/dist/rich-text-editor/look.d.ts +71 -0
- package/dist/rich-text-editor/look.d.ts.map +1 -0
- package/dist/rich-text-editor/look.js +342 -0
- package/dist/rich-text-editor/look.js.map +1 -0
- package/dist/rich-text-editor/markdown.d.ts +18 -0
- package/dist/rich-text-editor/markdown.d.ts.map +1 -0
- package/dist/rich-text-editor/markdown.js +496 -0
- package/dist/rich-text-editor/markdown.js.map +1 -0
- package/dist/rich-text-editor/nodes.d.ts +135 -0
- package/dist/rich-text-editor/nodes.d.ts.map +1 -0
- package/dist/rich-text-editor/nodes.js +397 -0
- package/dist/rich-text-editor/nodes.js.map +1 -0
- package/dist/rich-text-editor/render.d.ts +68 -0
- package/dist/rich-text-editor/render.d.ts.map +1 -0
- package/dist/rich-text-editor/render.js +500 -0
- package/dist/rich-text-editor/render.js.map +1 -0
- package/dist/rich-text-editor/schema.d.ts +16 -0
- package/dist/rich-text-editor/schema.d.ts.map +1 -0
- package/dist/rich-text-editor/schema.js +386 -0
- package/dist/rich-text-editor/schema.js.map +1 -0
- package/dist/rich-text-editor/store.d.ts +11 -0
- package/dist/rich-text-editor/store.d.ts.map +1 -0
- package/dist/rich-text-editor/store.js +43 -0
- package/dist/rich-text-editor/store.js.map +1 -0
- package/dist/rich-text-editor/suggest.d.ts +127 -0
- package/dist/rich-text-editor/suggest.d.ts.map +1 -0
- package/dist/rich-text-editor/suggest.js +0 -0
- package/dist/rich-text-editor/suggest.js.map +1 -0
- package/dist/rich-text-editor/tables.d.ts +41 -0
- package/dist/rich-text-editor/tables.d.ts.map +1 -0
- package/dist/rich-text-editor/tables.js +204 -0
- package/dist/rich-text-editor/tables.js.map +1 -0
- package/dist/rich-text-editor/toolbar.d.ts +58 -0
- package/dist/rich-text-editor/toolbar.d.ts.map +1 -0
- package/dist/rich-text-editor/toolbar.js +548 -0
- package/dist/rich-text-editor/toolbar.js.map +1 -0
- package/dist/rich-text-editor/view.d.ts +368 -0
- package/dist/rich-text-editor/view.d.ts.map +1 -0
- package/dist/rich-text-editor/view.js +1968 -0
- package/dist/rich-text-editor/view.js.map +1 -0
- package/dist/rich-text-editor/virtual.d.ts +54 -0
- package/dist/rich-text-editor/virtual.d.ts.map +1 -0
- package/dist/rich-text-editor/virtual.js +262 -0
- package/dist/rich-text-editor/virtual.js.map +1 -0
- package/dist/richtext/node.d.ts +25 -2
- package/dist/richtext/node.d.ts.map +1 -1
- package/dist/richtext/node.js +46 -24
- package/dist/richtext/node.js.map +1 -1
- package/dist/terminal/backends.d.ts +4 -1
- package/dist/terminal/backends.d.ts.map +1 -1
- package/dist/terminal/backends.js.map +1 -1
- package/dist/terminal/index.d.ts +18 -7
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +28 -11
- package/dist/terminal/index.js.map +1 -1
- package/package.json +23 -4
- package/src/charts/node.ts +6 -2
- package/src/embed/client.ts +102 -8
- package/src/embed/index.ts +2 -0
- package/src/html/node.ts +7 -5
- package/src/index.ts +2 -0
- package/src/{markdown → internal/markdown}/ast.ts +24 -7
- package/src/{markdown → internal/markdown}/parse.ts +134 -24
- package/src/internal/markdown/stringify.ts +772 -0
- package/src/internal/scroll.ts +5 -3
- package/src/maps/anchors.ts +607 -0
- package/src/maps/controller.ts +999 -0
- package/src/maps/gl/buckets.ts +457 -0
- package/src/maps/gl/build-worker.ts +55 -0
- package/src/maps/gl/color.ts +62 -0
- package/src/maps/gl/cover.ts +170 -0
- package/src/maps/gl/index.ts +23 -0
- package/src/maps/gl/markers.ts +83 -0
- package/src/maps/gl/overlays.ts +379 -0
- package/src/maps/gl/pane.ts +42 -0
- package/src/maps/gl/placement.ts +816 -0
- package/src/maps/gl/renderer.ts +1576 -0
- package/src/maps/gl/shaders.ts +486 -0
- package/src/maps/gl/store.ts +566 -0
- package/src/maps/gl/text.ts +495 -0
- package/src/maps/gl/view.ts +1224 -0
- package/src/maps/index.ts +270 -81
- package/src/maps/labels.ts +214 -121
- package/src/maps/node.ts +763 -629
- package/src/maps/overlay.ts +148 -43
- package/src/maps/paint.ts +3 -0
- package/src/maps/proj.ts +31 -0
- package/src/maps/renderer.ts +155 -0
- package/src/maps/sources.ts +38 -3
- package/src/maps/theme.ts +51 -0
- package/src/maps/tiles.ts +191 -33
- package/src/maps/types.ts +188 -20
- package/src/markdown/expressions.ts +5 -1
- package/src/markdown/index.ts +14 -11
- package/src/markdown/spans.ts +1 -1
- package/src/media-player/index.ts +18 -4
- package/src/rich-text-editor/clipboard.ts +439 -0
- package/src/rich-text-editor/collab.ts +91 -0
- package/src/rich-text-editor/commands.ts +448 -0
- package/src/rich-text-editor/dom-globals.d.ts +23 -0
- package/src/rich-text-editor/drag.ts +211 -0
- package/src/rich-text-editor/html.ts +619 -0
- package/src/rich-text-editor/index.ts +1331 -0
- package/src/rich-text-editor/inline.ts +345 -0
- package/src/rich-text-editor/keymap.ts +510 -0
- package/src/rich-text-editor/keys.ts +119 -0
- package/src/rich-text-editor/look.ts +427 -0
- package/src/rich-text-editor/markdown.ts +653 -0
- package/src/rich-text-editor/nodes.ts +497 -0
- package/src/rich-text-editor/render.ts +800 -0
- package/src/rich-text-editor/schema.ts +431 -0
- package/src/rich-text-editor/store.ts +39 -0
- package/src/rich-text-editor/suggest.ts +597 -0
- package/src/rich-text-editor/tables.ts +272 -0
- package/src/rich-text-editor/toolbar.ts +724 -0
- package/src/rich-text-editor/view.ts +2287 -0
- package/src/rich-text-editor/virtual.ts +347 -0
- package/src/richtext/node.ts +59 -30
- package/src/terminal/backends.ts +4 -1
- package/src/terminal/index.ts +43 -15
- package/dist/markdown/ast.d.ts.map +0 -1
- package/dist/markdown/ast.js +0 -17
- package/dist/markdown/ast.js.map +0 -1
- package/dist/markdown/parse.d.ts.map +0 -1
- package/dist/markdown/parse.js.map +0 -1
- package/dist/markdown/tags.d.ts.map +0 -1
- package/dist/markdown/tags.js.map +0 -1
- /package/dist/{markdown → internal/markdown}/parse.d.ts +0 -0
- /package/dist/{markdown → internal/markdown}/tags.d.ts +0 -0
- /package/dist/{markdown → internal/markdown}/tags.js +0 -0
- /package/src/{markdown → internal/markdown}/tags.ts +0 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
// Labels, the text half: strings set by the platform's own text engine,
|
|
2
|
+
// read back as coverage, and packed into one GL texture.
|
|
3
|
+
//
|
|
4
|
+
// A `<glarea>` is stacked over every 2D thing in its window, so a label on a
|
|
5
|
+
// GL map has to be *in* the GL frame — there is no drawing text over it
|
|
6
|
+
// afterwards. The glyphs come from where every other string in the app
|
|
7
|
+
// comes from: `app.fonts.layout()` shapes it (CoreText on the Cocoa
|
|
8
|
+
// backend, ntk's own shaper on X11, font fallback and all), and the layout
|
|
9
|
+
// draws into an offscreen {@link Surface} whose pixels are read back. That
|
|
10
|
+
// is one readback per *batch* of labels, not per label, and each label is
|
|
11
|
+
// set once and drawn every frame after.
|
|
12
|
+
//
|
|
13
|
+
// A label is rasterized **whole**, not glyph by glyph: placement sets every
|
|
14
|
+
// line label on a straight stretch, so a label is one rigid piece of type —
|
|
15
|
+
// one textured quad, rotated as a unit — and shaping, kerning and scripts
|
|
16
|
+
// stay the text engine's business. What is stored is **coverage**, drawn in
|
|
17
|
+
// white and read from the alpha channel; colour and halo are the shader's
|
|
18
|
+
// (see `./shaders.ts`), so one raster serves every palette and a
|
|
19
|
+
// light-to-dark switch re-rasterizes nothing.
|
|
20
|
+
import { Surface } from 'react-x11/ntk';
|
|
21
|
+
/** The offscreen surface a batch is set on, in device pixels. A readback
|
|
22
|
+
* has to stay inside it — X answers a GetImage past a pixmap's edge with
|
|
23
|
+
* BadMatch — so a batch is whatever fits. */
|
|
24
|
+
const STAGING_WIDTH = 1024;
|
|
25
|
+
const STAGING_HEIGHT = 512;
|
|
26
|
+
/** Milliseconds of drawing one batch may take. A batch runs between two
|
|
27
|
+
* frames, and at 75 Hz the gap between them is a few milliseconds. */
|
|
28
|
+
const DRAW_BUDGET_MS = 1.5;
|
|
29
|
+
/** The text engine over an app's fonts and an offscreen surface. */
|
|
30
|
+
export class SurfaceTextEngine {
|
|
31
|
+
_app;
|
|
32
|
+
_fonts;
|
|
33
|
+
_family;
|
|
34
|
+
_layouts = new Map();
|
|
35
|
+
_surface = null;
|
|
36
|
+
_ctx = null;
|
|
37
|
+
constructor(app, fonts, family) {
|
|
38
|
+
this._app = app;
|
|
39
|
+
this._fonts = fonts;
|
|
40
|
+
this._family = family;
|
|
41
|
+
}
|
|
42
|
+
/** The engine for the app a node belongs to, or null where there is
|
|
43
|
+
* nothing to set text with. */
|
|
44
|
+
static forApp(app, family) {
|
|
45
|
+
const fonts = app?.fonts;
|
|
46
|
+
if (!fonts || typeof fonts.layout !== 'function')
|
|
47
|
+
return null;
|
|
48
|
+
return new SurfaceTextEngine(app, fonts, family);
|
|
49
|
+
}
|
|
50
|
+
_layout(text, size) {
|
|
51
|
+
const key = `${size}|${text}`;
|
|
52
|
+
let layout = this._layouts.get(key);
|
|
53
|
+
if (!layout) {
|
|
54
|
+
// Bounded like the retained renderer's shaper: cleared wholesale, and
|
|
55
|
+
// what is on screen is set again once.
|
|
56
|
+
if (this._layouts.size > 8000)
|
|
57
|
+
this._layouts.clear();
|
|
58
|
+
layout = this._fonts.layout(text, {
|
|
59
|
+
family: this._family,
|
|
60
|
+
size,
|
|
61
|
+
weight: 400,
|
|
62
|
+
style: 'normal',
|
|
63
|
+
color: '#ffffff',
|
|
64
|
+
});
|
|
65
|
+
this._layouts.set(key, layout);
|
|
66
|
+
}
|
|
67
|
+
return layout;
|
|
68
|
+
}
|
|
69
|
+
measure(text, size) {
|
|
70
|
+
const layout = this._layout(text, size);
|
|
71
|
+
return { width: Math.ceil(layout.width), height: Math.ceil(layout.height) };
|
|
72
|
+
}
|
|
73
|
+
async rasterize(items, pad) {
|
|
74
|
+
const places = [];
|
|
75
|
+
let x = 0;
|
|
76
|
+
let y = 0;
|
|
77
|
+
let row = 0;
|
|
78
|
+
for (const item of items) {
|
|
79
|
+
const box = this.measure(item.text, item.size);
|
|
80
|
+
const w = box.width + pad * 2;
|
|
81
|
+
const h = box.height + pad * 2;
|
|
82
|
+
if (w > STAGING_WIDTH || h > STAGING_HEIGHT) {
|
|
83
|
+
places.push(null);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (x + w > STAGING_WIDTH) {
|
|
87
|
+
x = 0;
|
|
88
|
+
y += row;
|
|
89
|
+
row = 0;
|
|
90
|
+
}
|
|
91
|
+
if (y + h > STAGING_HEIGHT) {
|
|
92
|
+
places.push(undefined);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
places.push({ x, y, w, h });
|
|
96
|
+
x += w;
|
|
97
|
+
row = Math.max(row, h);
|
|
98
|
+
}
|
|
99
|
+
if (!places.some((p) => p)) {
|
|
100
|
+
return places.map((p) => (p === null ? null : undefined));
|
|
101
|
+
}
|
|
102
|
+
if (!this._surface) {
|
|
103
|
+
this._surface = new Surface(this._app, {
|
|
104
|
+
width: STAGING_WIDTH,
|
|
105
|
+
height: STAGING_HEIGHT,
|
|
106
|
+
});
|
|
107
|
+
this._ctx = this._surface.getContext('2d');
|
|
108
|
+
}
|
|
109
|
+
const surface = this._surface;
|
|
110
|
+
const ctx = this._ctx;
|
|
111
|
+
surface.clear();
|
|
112
|
+
const started = now();
|
|
113
|
+
// The rows drawn into: what is read back, and no more.
|
|
114
|
+
let used = 0;
|
|
115
|
+
items.forEach((item, i) => {
|
|
116
|
+
const place = places[i];
|
|
117
|
+
if (!place)
|
|
118
|
+
return;
|
|
119
|
+
// Drawing is this thread's time; past the budget the rest wait for
|
|
120
|
+
// the next batch.
|
|
121
|
+
if (now() - started > DRAW_BUDGET_MS) {
|
|
122
|
+
places[i] = undefined;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this._layout(item.text, item.size).draw(ctx, place.x + pad, place.y + pad);
|
|
126
|
+
used = Math.max(used, place.y + place.h);
|
|
127
|
+
});
|
|
128
|
+
const image = await ctx.getImageData(0, 0, STAGING_WIDTH, used);
|
|
129
|
+
return places.map((place) => {
|
|
130
|
+
if (!place)
|
|
131
|
+
return place;
|
|
132
|
+
// Row by row, as the readback has them: a copy, not a pass over the
|
|
133
|
+
// pixels, and uploaded as it is — the shader reads alpha alone.
|
|
134
|
+
const rowBytes = place.w * 4;
|
|
135
|
+
const pixels = new Uint8Array(rowBytes * place.h);
|
|
136
|
+
for (let r = 0; r < place.h; r++) {
|
|
137
|
+
const src = ((place.y + r) * image.width + place.x) * 4;
|
|
138
|
+
pixels.set(image.data.subarray(src, src + rowBytes), r * rowBytes);
|
|
139
|
+
}
|
|
140
|
+
return { width: place.w, height: place.h, pixels };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
dispose() {
|
|
144
|
+
this._ctx?.destroy?.();
|
|
145
|
+
this._ctx = null;
|
|
146
|
+
this._surface?.destroy();
|
|
147
|
+
this._surface = null;
|
|
148
|
+
this._layouts.clear();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const keyOf = (text, size) => `${size}|${text}`;
|
|
152
|
+
/**
|
|
153
|
+
* The widest halo a raster's margin holds, in pixels. The drawn quad sits
|
|
154
|
+
* {@link quadInset} inside the margin and a halo samples up to this far
|
|
155
|
+
* past the quad, so its samples stay a texel inside the raster's own clear
|
|
156
|
+
* margin and never reach a neighbour's.
|
|
157
|
+
*/
|
|
158
|
+
export const haloReach = (pad) => Math.max(0, Math.floor((pad - 2) / 2));
|
|
159
|
+
export const quadInset = (pad) => pad - haloReach(pad) - 1;
|
|
160
|
+
/** Strings a frame measures however little budget it has left, so a frame
|
|
161
|
+
* that starts late still makes progress. One: on X11 a string's first
|
|
162
|
+
* measurement can cost milliseconds, and a floor of several put a pan
|
|
163
|
+
* frame 27 ms over. */
|
|
164
|
+
const MIN_MEASURES = 1;
|
|
165
|
+
/** Strings per rasterization batch at most — a few rows of the staging
|
|
166
|
+
* surface, so the readback and the copies out of it stay small too. */
|
|
167
|
+
const BATCH = 32;
|
|
168
|
+
/** Frames an unused entry survives a compaction for. */
|
|
169
|
+
const KEEP_FRAMES = 120;
|
|
170
|
+
/**
|
|
171
|
+
* Every label raster, packed into one texture's worth of shelves, with the
|
|
172
|
+
* uploads the renderer owes it.
|
|
173
|
+
*
|
|
174
|
+
* The atlas is CPU-side and outlives any one GL context: it keeps each
|
|
175
|
+
* entry's raster, so a renderer that is new — the surface was recreated —
|
|
176
|
+
* uploads it again from here ({@link restart}), and asks nothing of the text
|
|
177
|
+
* engine. What it holds is bounded by the texture it packs into: 16 MB for
|
|
178
|
+
* the default 2048², whatever is panned past.
|
|
179
|
+
*
|
|
180
|
+
* **Measuring is budgeted, drawing is asynchronous, uploading is metered.**
|
|
181
|
+
* Placement needs a label's box the frame it is considered, which is a
|
|
182
|
+
* synchronous shaping call — tens of microseconds on the Cocoa backend, but
|
|
183
|
+
* milliseconds each the first time on X11, where fonts load and glyphs
|
|
184
|
+
* rasterize in JS — so a frame measures until its deadline and leaves the
|
|
185
|
+
* rest for the next. A raster is asked for only once a label has won a
|
|
186
|
+
* place, and arrives a batch at a time, a readback later; the renderer
|
|
187
|
+
* takes a few dozen a frame into the texture, and a label fades in once its
|
|
188
|
+
* raster is there.
|
|
189
|
+
*/
|
|
190
|
+
export class LabelAtlas {
|
|
191
|
+
size;
|
|
192
|
+
/** Clear margin rasterized around every string, in pixels — what a halo
|
|
193
|
+
* grows into, and what keeps it from sampling a neighbour. */
|
|
194
|
+
pad;
|
|
195
|
+
/** A frame's measuring ran out of budget: there is more to place. */
|
|
196
|
+
starved = false;
|
|
197
|
+
onChange = null;
|
|
198
|
+
_engine;
|
|
199
|
+
_entries = new Map();
|
|
200
|
+
/** Entries the texture does not have where they are, oldest first. */
|
|
201
|
+
_uploads = [];
|
|
202
|
+
_wanted = new Map();
|
|
203
|
+
_failed = new Set();
|
|
204
|
+
_measured = new Map();
|
|
205
|
+
_busy = false;
|
|
206
|
+
_shelves = [];
|
|
207
|
+
_top = 0;
|
|
208
|
+
_frame = 0;
|
|
209
|
+
_deadline = Infinity;
|
|
210
|
+
_measures = 0;
|
|
211
|
+
constructor(engine, options) {
|
|
212
|
+
this._engine = engine;
|
|
213
|
+
this.size = options.size ?? 2048;
|
|
214
|
+
this.pad = options.pad;
|
|
215
|
+
}
|
|
216
|
+
/** Strings asked for and not yet rasterized, or a batch in flight. */
|
|
217
|
+
get pending() {
|
|
218
|
+
return this._busy || this._wanted.size > 0;
|
|
219
|
+
}
|
|
220
|
+
/** Rasters waiting for the texture. */
|
|
221
|
+
get uploading() {
|
|
222
|
+
return this._uploads.length > 0;
|
|
223
|
+
}
|
|
224
|
+
get entries() {
|
|
225
|
+
return this._entries.size;
|
|
226
|
+
}
|
|
227
|
+
/** A new frame, whose measuring stops at `deadline` (after one). */
|
|
228
|
+
beginFrame(deadline) {
|
|
229
|
+
this._frame++;
|
|
230
|
+
this._deadline = deadline;
|
|
231
|
+
this._measures = 0;
|
|
232
|
+
this.starved = false;
|
|
233
|
+
}
|
|
234
|
+
/** The box a string sets in, or null when this frame's budget is spent. */
|
|
235
|
+
measure(text, size) {
|
|
236
|
+
const key = keyOf(text, size);
|
|
237
|
+
const hit = this._measured.get(key);
|
|
238
|
+
if (hit)
|
|
239
|
+
return hit;
|
|
240
|
+
const engine = this._engine;
|
|
241
|
+
if (!engine)
|
|
242
|
+
return null;
|
|
243
|
+
if (this._measures >= MIN_MEASURES && now() > this._deadline) {
|
|
244
|
+
this.starved = true;
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
this._measures++;
|
|
248
|
+
const box = engine.measure(text, size);
|
|
249
|
+
if (this._measured.size > 20000)
|
|
250
|
+
this._measured.clear();
|
|
251
|
+
this._measured.set(key, box);
|
|
252
|
+
return box;
|
|
253
|
+
}
|
|
254
|
+
/** The string's raster, once the texture has it; null until then —
|
|
255
|
+
* asking is what gets it rasterized. */
|
|
256
|
+
entry(text, size) {
|
|
257
|
+
const key = keyOf(text, size);
|
|
258
|
+
const entry = this._entries.get(key);
|
|
259
|
+
if (entry) {
|
|
260
|
+
entry.used = this._frame;
|
|
261
|
+
return entry.ready ? entry : null;
|
|
262
|
+
}
|
|
263
|
+
if (!this._failed.has(key) && !this._wanted.has(key)) {
|
|
264
|
+
this._wanted.set(key, { text, size });
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
/** Start rasterizing what has been asked for, unless a batch is out. */
|
|
269
|
+
pump() {
|
|
270
|
+
const engine = this._engine;
|
|
271
|
+
if (!engine || this._busy || this._wanted.size === 0)
|
|
272
|
+
return;
|
|
273
|
+
const batch = [];
|
|
274
|
+
for (const item of this._wanted.values()) {
|
|
275
|
+
batch.push(item);
|
|
276
|
+
if (batch.length >= BATCH)
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
this._busy = true;
|
|
280
|
+
engine.rasterize(batch, this.pad).then((rasters) => {
|
|
281
|
+
this._busy = false;
|
|
282
|
+
rasters.forEach((raster, i) => {
|
|
283
|
+
if (raster === undefined)
|
|
284
|
+
return;
|
|
285
|
+
const key = keyOf(batch[i].text, batch[i].size);
|
|
286
|
+
this._wanted.delete(key);
|
|
287
|
+
if (raster === null || !this._add(key, raster))
|
|
288
|
+
this._failed.add(key);
|
|
289
|
+
});
|
|
290
|
+
this.onChange?.();
|
|
291
|
+
}, () => {
|
|
292
|
+
// A readback that fails once fails every time (no surface, a
|
|
293
|
+
// backend without one): stop asking, and draw no labels.
|
|
294
|
+
this._busy = false;
|
|
295
|
+
this._engine = null;
|
|
296
|
+
this._wanted.clear();
|
|
297
|
+
this.onChange?.();
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
/** Up to `max` rasters for the texture, oldest first. The renderer marks
|
|
301
|
+
* each `ready` once it is uploaded. */
|
|
302
|
+
takeUploads(max) {
|
|
303
|
+
return this._uploads.splice(0, max);
|
|
304
|
+
}
|
|
305
|
+
/** The texture is new, and has none of it: everything goes up again. */
|
|
306
|
+
restart() {
|
|
307
|
+
for (const entry of this._entries.values())
|
|
308
|
+
entry.ready = false;
|
|
309
|
+
this._uploads = [...this._entries.values()];
|
|
310
|
+
}
|
|
311
|
+
dispose() {
|
|
312
|
+
this._engine?.dispose();
|
|
313
|
+
this._engine = null;
|
|
314
|
+
}
|
|
315
|
+
_add(key, raster) {
|
|
316
|
+
let place = this._allocate(raster.width, raster.height);
|
|
317
|
+
if (!place) {
|
|
318
|
+
this._compact();
|
|
319
|
+
place = this._allocate(raster.width, raster.height);
|
|
320
|
+
}
|
|
321
|
+
if (!place)
|
|
322
|
+
return false;
|
|
323
|
+
const entry = {
|
|
324
|
+
key,
|
|
325
|
+
x: place.x,
|
|
326
|
+
y: place.y,
|
|
327
|
+
width: raster.width,
|
|
328
|
+
height: raster.height,
|
|
329
|
+
pixels: raster.pixels,
|
|
330
|
+
ready: false,
|
|
331
|
+
used: this._frame,
|
|
332
|
+
};
|
|
333
|
+
this._entries.set(key, entry);
|
|
334
|
+
this._uploads.push(entry);
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
/** A shelf packer: rows of one height class (rounded up to 8 pixels),
|
|
338
|
+
* filled left to right, a new row below the last when none has room. */
|
|
339
|
+
_allocate(w, h) {
|
|
340
|
+
if (w > this.size || h > this.size)
|
|
341
|
+
return null;
|
|
342
|
+
const height = Math.ceil(h / 8) * 8;
|
|
343
|
+
for (const shelf of this._shelves) {
|
|
344
|
+
if (shelf.height === height && shelf.x + w <= this.size) {
|
|
345
|
+
const at = { x: shelf.x, y: shelf.y };
|
|
346
|
+
shelf.x += w;
|
|
347
|
+
return at;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (this._top + height > this.size)
|
|
351
|
+
return null;
|
|
352
|
+
const shelf = { y: this._top, height, x: w };
|
|
353
|
+
this._shelves.push(shelf);
|
|
354
|
+
this._top += height;
|
|
355
|
+
return { x: 0, y: shelf.y };
|
|
356
|
+
}
|
|
357
|
+
/** Drop what has not been drawn for a while and pack the rest again,
|
|
358
|
+
* tallest first. Everything kept has moved, so none of it is drawn
|
|
359
|
+
* until the renderer has uploaded it where it now is. */
|
|
360
|
+
_compact() {
|
|
361
|
+
const keep = [...this._entries.values()]
|
|
362
|
+
.filter((e) => e.used >= this._frame - KEEP_FRAMES)
|
|
363
|
+
.sort((a, b) => b.height - a.height);
|
|
364
|
+
this._entries.clear();
|
|
365
|
+
this._shelves = [];
|
|
366
|
+
this._top = 0;
|
|
367
|
+
this._uploads = [];
|
|
368
|
+
for (const entry of keep) {
|
|
369
|
+
const place = this._allocate(entry.width, entry.height);
|
|
370
|
+
if (!place)
|
|
371
|
+
continue;
|
|
372
|
+
entry.x = place.x;
|
|
373
|
+
entry.y = place.y;
|
|
374
|
+
entry.ready = false;
|
|
375
|
+
this._entries.set(entry.key, entry);
|
|
376
|
+
this._uploads.push(entry);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const globals = globalThis;
|
|
381
|
+
const now = () => globals.performance?.now() ?? Date.now();
|
|
382
|
+
//# sourceMappingURL=text.js.map
|
|
@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AG,EAAE,CAAC;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YACxD,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;YAClB,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;YAClB,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,GAAG,UAAiD,CAAC;AAClE,MAAM,GAAG,GAAG,GAAW,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { Style } from 'react-x11/style';
|
|
3
|
+
import type { MapController } from '../controller.js';
|
|
4
|
+
import type { MapProps } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Adaptive quality's rungs, cheapest last. Each leaves out more than the
|
|
7
|
+
* one before it, in the order that costs the picture least:
|
|
8
|
+
*
|
|
9
|
+
* 1. **The fill edge pass** — the half-pixel line that antialiases every
|
|
10
|
+
* polygon. A fifth of a dense frame, measured, and a staircase edge is
|
|
11
|
+
* invisible on a map in motion.
|
|
12
|
+
* 2. **The style's newest detail layers** — those whose `minZoom` is within
|
|
13
|
+
* `detail` levels of the zoom: buildings and service roads first, then
|
|
14
|
+
* sites, minor roads. The style already says which layers are details,
|
|
15
|
+
* by bringing them in last.
|
|
16
|
+
* 3. **A coarser tile level** — the parent level's tiles, drawn at this
|
|
17
|
+
* zoom: generalized geometry and fewer features, which is what a low-zoom
|
|
18
|
+
* frame (all land and water polygons) is made cheaper by.
|
|
19
|
+
*/
|
|
20
|
+
export declare const QUALITY_LADDER: readonly {
|
|
21
|
+
edges: boolean;
|
|
22
|
+
detail: number;
|
|
23
|
+
coarser: number;
|
|
24
|
+
}[];
|
|
25
|
+
/**
|
|
26
|
+
* The rung a moving frame is drawn at: the lowest predicted to fit the
|
|
27
|
+
* budget, and a rung up only once that one is predicted well inside it —
|
|
28
|
+
* so a frame that sits at the budget does not flicker between two rungs.
|
|
29
|
+
*/
|
|
30
|
+
export declare function chooseQuality(current: number, predict: (rung: number) => number, budgetMs: number): number;
|
|
31
|
+
/** What `<Map>` hands the GL renderer. */
|
|
32
|
+
export interface GlMapPaneProps {
|
|
33
|
+
/** The map's controller: its camera, its gestures and its handle. */
|
|
34
|
+
controller: MapController;
|
|
35
|
+
/** Everything `<Map>` was given. */
|
|
36
|
+
map: MapProps;
|
|
37
|
+
/** GL failed — the surface, the context, a shader, a frame. Called once;
|
|
38
|
+
* what happens next is `<Map>`'s decision. */
|
|
39
|
+
onFailure: (error: Error) => void;
|
|
40
|
+
style?: Style;
|
|
41
|
+
role?: string;
|
|
42
|
+
'aria-label'?: string;
|
|
43
|
+
'data-testname'?: string;
|
|
44
|
+
/** Drawn above the surface, as core draws a `<glarea>`'s children — given
|
|
45
|
+
* only where `useSupports('glOverlay')` says this connection does. */
|
|
46
|
+
children?: ReactNode;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The GL half of `<Map>`: a pane with a `<glarea>` in it, drawn every frame
|
|
50
|
+
* from vector tiles. Mounted by `<Map>` when it chooses GL; not exported
|
|
51
|
+
* from the package on its own.
|
|
52
|
+
*/
|
|
53
|
+
export declare function GlMapPane(props: GlMapPaneProps): ReactElement;
|
|
54
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/maps/gl/view.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,EAAE,aAAa,EAA4B,MAAM,kBAAkB,CAAC;AAoBhF,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAC;AA6B3D;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB,EAOA,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EACjC,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR;AA2ID,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,UAAU,EAAE,aAAa,CAAC;IAC1B,oCAAoC;IACpC,GAAG,EAAE,QAAQ,CAAC;IACd;mDAC+C;IAC/C,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;2EACuE;IACvE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAo4BD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CAsC7D"}
|