@nika-js/onlymap 0.9.1 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +27 -3
  3. package/dist/{basemap-DL0mk9Bf.js → basemap-DzQBuqBn.js} +3882 -3980
  4. package/dist/cartograph/elements/om-frame.d.ts +67 -1
  5. package/dist/cartograph/georef.d.ts +18 -4
  6. package/dist/cartograph/schema.d.ts +11 -0
  7. package/dist/cartograph.js +1480 -1311
  8. package/dist/cartograph.standalone.js +1808 -1615
  9. package/dist/{cityjson-D_V5GY8b.js → cityjson-k-z1r6c0.js} +1 -1
  10. package/dist/{crs-DsDQ4Q4i.js → crs-BzE_KP4M.js} +25 -2
  11. package/dist/{crs-Ciu7Xs7a.js → crs-ChglCB3O.js} +39 -16
  12. package/dist/elements/om-map.d.ts +10 -0
  13. package/dist/{geoparquet-DJxZA0if.js → geoparquet-BlFSeNwf.js} +10 -10
  14. package/dist/globe-view-qTt7YaiC.js +104 -0
  15. package/dist/hillshade-Ds0pONmA.js +298 -0
  16. package/dist/{hillshade-shader-n_zManfZ.js → hillshade-shader-DI2uLSNU.js} +15 -10
  17. package/dist/hillshade-shader.d.ts +18 -2
  18. package/dist/hillshade.d.ts +30 -0
  19. package/dist/{ifc-Dc-TdSJr.js → ifc-DXwePQRv.js} +131 -131
  20. package/dist/{index-vLXZuog4.js → index-B9kwlhFA.js} +1 -1
  21. package/dist/index-BCTAq6uy.js +65 -0
  22. package/dist/{index-DdTZSuAb.js → index-BK99wPf_.js} +106 -106
  23. package/dist/index-BSwEOxkR.js +322 -0
  24. package/dist/{index-BjcPjICh.js → index-Bpk1EipB.js} +59 -59
  25. package/dist/index-C2VK-Is6.js +641 -0
  26. package/dist/index-C4oddUIX.js +459 -0
  27. package/dist/{index-oY3XHIux.js → index-CBYDP-_0.js} +18178 -16943
  28. package/dist/{index-CvuDsvnk.js → index-oL_18WvP.js} +47 -47
  29. package/dist/index.d.ts +4 -0
  30. package/dist/layer-registry.d.ts +27 -0
  31. package/dist/{lerc-Bph62dCb.js → lerc-xM89n_hR.js} +1 -1
  32. package/dist/onlymap.standalone.js +48211 -45574
  33. package/dist/onlymapjs.js +77 -74
  34. package/dist/parse-manifest.d.ts +6 -0
  35. package/dist/plane-camera.d.ts +59 -0
  36. package/dist/plane-layers.d.ts +56 -0
  37. package/dist/plane-tiles.d.ts +99 -0
  38. package/dist/plane-tileset.d.ts +31 -0
  39. package/dist/plane-warp.d.ts +91 -0
  40. package/dist/post-process-effect-CNMzoP-h.js +197 -0
  41. package/dist/programmatic.d.ts +16 -1
  42. package/dist/projection.d.ts +118 -0
  43. package/dist/{raster-pipeline-BlOnMPJe.js → raster-pipeline-B_gY9-5f.js} +4 -3
  44. package/dist/{raster-D-eTzCE3.js → raster-yVRqHYLH.js} +4 -4
  45. package/dist/runtime-core.d.ts +140 -1
  46. package/dist/serialize/clip.d.ts +50 -0
  47. package/dist/serialize/declutter.d.ts +44 -0
  48. package/dist/serialize/emit.d.ts +60 -0
  49. package/dist/serialize/index.d.ts +64 -0
  50. package/dist/serialize/strategy.d.ts +30 -0
  51. package/dist/serialize/style.d.ts +77 -0
  52. package/dist/snapshot.d.ts +46 -0
  53. package/dist/surface-anchor.d.ts +6 -0
  54. package/dist/text-on-path-D-fhYDqa.js +146 -0
  55. package/dist/text-on-path.d.ts +157 -0
  56. package/dist/transform/buffer.d.ts +63 -0
  57. package/dist/transform/contour.d.ts +37 -0
  58. package/dist/transform/dot-density.d.ts +19 -0
  59. package/dist/transform/field.d.ts +80 -0
  60. package/dist/transform/geometry.d.ts +20 -0
  61. package/dist/transform/index.d.ts +29 -0
  62. package/dist/transform/simplify.d.ts +10 -0
  63. package/dist/transform/smooth.d.ts +12 -0
  64. package/dist/transform-stage.d.ts +92 -0
  65. package/dist/version.d.ts +1 -1
  66. package/dist/{zarr-BGDoEtFb.js → zarr-BPeWy3ro.js} +2 -2
  67. package/docs/cartograph.md +12 -4
  68. package/docs/cartography.md +328 -0
  69. package/docs/design/arrows.md +182 -0
  70. package/docs/design/carto-substrate.md +1055 -0
  71. package/docs/design/extensions.md +250 -0
  72. package/llms.txt +3 -2
  73. package/onlymapjs.attributes.json +18 -0
  74. package/onlymapjs.html-data.json +169 -19
  75. package/package.json +1 -1
  76. package/skills/onlymapjs/SKILL.md +6 -2
  77. package/skills/onlymapjs/references/syntax.md +22 -2
  78. package/dist/hillshade-DR3TxO1a.js +0 -186
  79. package/dist/index-DO_w0tqR.js +0 -514
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The CPU label pass (docs/design/carto-substrate.md §6, "Text").
3
+ *
4
+ * `CollisionFilterExtension` decides survivors on the GPU, in a framebuffer
5
+ * sized from the canvas and halved — so the set of labels it kept depends on
6
+ * the capture ratio, and the serializer cannot ask deck which ones they were.
7
+ * It runs its own pass instead: greedy by priority over measured boxes,
8
+ * deterministic and resolution-independent.
9
+ *
10
+ * That is a feature rather than a workaround. Deck-side collision stays the
11
+ * interactive preview; this is the print truth, and it is the natural home for
12
+ * the placement work the GPU path has no room for — candidate positions,
13
+ * leader lines, text on a path — when that lands.
14
+ */
15
+ export interface LabelBox {
16
+ id: string;
17
+ /** Higher wins. Ties break by index, so the pass is a pure function of its input order. */
18
+ priority: number;
19
+ left: number;
20
+ top: number;
21
+ right: number;
22
+ bottom: number;
23
+ }
24
+ /**
25
+ * Greedy by priority. Returns the indices that survive, in the INPUT's order —
26
+ * so the caller emits labels in document order rather than priority order, and
27
+ * two runs over the same input produce the same file byte for byte.
28
+ *
29
+ * `padding` is the breathing room between boxes, in the same pixels the boxes
30
+ * are measured in. It exists because two labels that merely touch read as one
31
+ * word, and because deck's own `collisionTestProps` convention is to reserve
32
+ * more room than the glyphs occupy.
33
+ */
34
+ export declare function declutter(boxes: readonly LabelBox[], padding?: number): number[];
35
+ /**
36
+ * Measure a label's box from its text, size and anchor, without a DOM.
37
+ *
38
+ * A real measurement needs the font; this is the fallback the serializer uses
39
+ * when no measurer is supplied, and it is DELIBERATELY generous: 0.6em per
40
+ * character is wider than most proportional faces, so the pass drops a label
41
+ * that would have fitted rather than keeping one that would have collided.
42
+ * Erring toward a sparser sheet is the right direction for print.
43
+ */
44
+ export declare function estimateLabelBox(text: string, x: number, y: number, sizePx: number, anchor?: "start" | "middle" | "end", baseline?: "top" | "center" | "bottom"): Omit<LabelBox, "id" | "priority">;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * IR + viewport → SVG elements (docs/design/carto-substrate.md §6).
3
+ *
4
+ * Pure: no DOM, no deck, no map state. Everything it needs arrives as an
5
+ * argument, which is what lets the whole strategy table be unit-tested against
6
+ * hand-written IR instead of a GPU.
7
+ */
8
+ import type { LayerIR } from "../ir";
9
+ import { type Point, type Rect } from "./clip";
10
+ /** Projects lng/lat to screen pixels — `viewport.project`, narrowed to what this needs. */
11
+ export type Project = (lngLat: [number, number]) => Point;
12
+ export interface EmitContext {
13
+ project: Project;
14
+ frame: Rect;
15
+ /** Ground metres per screen pixel at the frame centre — for metre-valued widths and radii. */
16
+ metresPerPixel: number;
17
+ /** Above this many emitted elements the caller is told to simplify. */
18
+ featureBudget: number;
19
+ }
20
+ export interface EmitResult {
21
+ markup: string;
22
+ elementCount: number;
23
+ }
24
+ /**
25
+ * A layer's features as `<path>` / `<circle>`.
26
+ *
27
+ * Holes are emitted as extra subpaths of ONE `<path>` with the default
28
+ * `fill-rule: nonzero`... which is wrong for a ring wound the same way as its
29
+ * outer. GeoJSON does not guarantee winding, so `fill-rule="evenodd"` is used
30
+ * instead: it needs no winding convention and gives the right answer for every
31
+ * ring order, at no cost the renderer can see.
32
+ */
33
+ export declare function emitVectorLayer(ir: LayerIR, ctx: EmitContext): EmitResult;
34
+ /** Text measurement, when the caller has a real one (a canvas 2D context). */
35
+ export type MeasureText = (text: string, sizePx: number, family: string) => number;
36
+ /**
37
+ * A TextLayer as real `<text>`, after the CPU declutter pass.
38
+ *
39
+ * Positions are the MEASURED ones, not re-derived here — `textlayout.ts`
40
+ * already states the rule that two measurers disagree at the margins, so every
41
+ * renderer draws the same computed boxes. The serializer follows it: when a
42
+ * measurer is supplied it is the SAME one the frame was laid out with.
43
+ */
44
+ export declare function emitTextLayer(ir: LayerIR, ctx: EmitContext, measure?: MeasureText): EmitResult;
45
+ /**
46
+ * A `TextOnPathLayer` as SVG `<textPath>` — one editable string per label,
47
+ * still following its own line.
48
+ *
49
+ * This is the one place the exporter produces BETTER output than the renderer
50
+ * rather than merely equivalent output. The layer draws N independently
51
+ * rotated glyphs because that is what a GPU text layer can do; SVG has the
52
+ * real primitive, so the file carries the word "Rio Grande" attached to the
53
+ * river's own path. An editor lets you retype it; the glyphs would not.
54
+ *
55
+ * The path goes in a `<defs>` and is referenced, because a `<textPath>` needs a
56
+ * path it can name and the line itself is usually drawn by a different layer.
57
+ */
58
+ export declare function emitTextOnPathLayer(ir: LayerIR, ctx: EmitContext): EmitResult;
59
+ /** A raster band as `<image>`, at the frame's own size. */
60
+ export declare function emitRasterBand(href: string, frame: Rect, ids: readonly string[]): string;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `snapshot({ format: "svg" })` — the vector serializer
3
+ * (docs/design/carto-substrate.md §6, Part C).
4
+ *
5
+ * A lazy chunk. A map that never asks for SVG must never download it, which is
6
+ * asserted from both ends: an e2e that watches the network, and a bundle
7
+ * assertion that no serializer symbol appears in the core chunk.
8
+ *
9
+ * The output is a HYBRID by design — vector linework over placed raster bands.
10
+ * That is not a fallback: it is how cartographic production has always worked,
11
+ * and it lets the serializer be honest about what it cannot vectorise rather
12
+ * than refusing or faking it.
13
+ */
14
+ import type { LayerIR } from "../ir";
15
+ import { type MeasureText } from "./emit";
16
+ export { groupIntoRuns, strategyFor, isKnownType } from "./strategy";
17
+ export { declutter, estimateLabelBox } from "./declutter";
18
+ export { emitVectorLayer, emitTextLayer, emitTextOnPathLayer, emitRasterBand } from "./emit";
19
+ export { clipRing, clipPolyline, clipSegment } from "./clip";
20
+ export { resolveFeatureStyle, resolveLineWidth, resolveRadius, resolveDashArray, deckColorToSvg } from "./style";
21
+ /** A dev notice — something the author should be told, not left to find in a print shop. */
22
+ export interface SerializerNotice {
23
+ code: "rasterised-by-effect" | "unknown-layer-type" | "feature-budget";
24
+ message: string;
25
+ fix: string;
26
+ }
27
+ export interface SerializeOptions {
28
+ width: number;
29
+ height: number;
30
+ project: (lngLat: [number, number]) => [number, number];
31
+ metresPerPixel: number;
32
+ /**
33
+ * Captures a band for the named layers and returns a data URI. The caller
34
+ * owns this because it is the one thing here that needs the renderer.
35
+ */
36
+ captureBand: (layerIds: string[] | null, dpi: number) => Promise<string>;
37
+ /**
38
+ * True when the RESOLVED effect chain contains a real post-process pass.
39
+ *
40
+ * The caller tests `instanceof PostProcessEffect` against the chain deck is
41
+ * actually running — not "is there an `<om-effect>` element" and not "does
42
+ * deck have any effects". Both of those are wrong, in opposite directions:
43
+ * deck's array also carries effects it installs itself (a decluttering layer
44
+ * adds one), while an authored element is not the only way a real pass
45
+ * arrives (`setEffects()` is the other). §13.1 has the reasoning.
46
+ */
47
+ hasPostProcessPass: boolean;
48
+ /** The pass's name, for the notice. */
49
+ postProcessLabel?: string;
50
+ /** Raster band resolution, independent of the sheet's. Default 600 (§12.2). */
51
+ effectDpi?: number;
52
+ featureBudget?: number;
53
+ measureText?: MeasureText;
54
+ }
55
+ export interface SerializeResult {
56
+ svg: string;
57
+ notices: SerializerNotice[];
58
+ elementCount: number;
59
+ }
60
+ export declare const DEFAULT_EFFECT_DPI = 600;
61
+ export declare const DEFAULT_FEATURE_BUDGET = 50000;
62
+ /** CSS pixels are 96 dpi by definition; a band at `dpi` is that much denser. */
63
+ export declare function bandScaleFor(dpi: number): number;
64
+ export declare function serializeToSvg(irs: readonly LayerIR[], opts: SerializeOptions): Promise<SerializeResult>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Which route each layer takes out of the renderer
3
+ * (docs/design/carto-substrate.md §6, "Contract").
4
+ *
5
+ * The "hybrid" output — vector linework over placed relief — is not a
6
+ * fallback. It is how cartographic production has always worked, and it is the
7
+ * reason this serializer can be honest about the layers it cannot vectorise
8
+ * instead of refusing or faking them.
9
+ */
10
+ export type Strategy = "vector" | "raster" | "text" | "path-text";
11
+ export declare function strategyFor(type: string): Strategy;
12
+ /** For diagnostics — whether the type was RECOGNISED, as opposed to defaulted into a band. */
13
+ export declare function isKnownType(type: string): boolean;
14
+ export interface LayerRun {
15
+ strategy: Strategy;
16
+ /** Layer ids, in document order. */
17
+ ids: string[];
18
+ }
19
+ /**
20
+ * Group layers into runs, merging CONSECUTIVE raster layers into one band.
21
+ *
22
+ * Consecutive is load-bearing: two raster layers with a vector layer between
23
+ * them are three bands, not two, because merging them would move the vector
24
+ * layer's linework underneath relief it was authored above. Stacking order is
25
+ * the one thing a serializer must not quietly rearrange.
26
+ */
27
+ export declare function groupIntoRuns(layers: readonly {
28
+ id: string;
29
+ type: string;
30
+ }[]): LayerRun[];
@@ -0,0 +1,77 @@
1
+ /**
2
+ * deck props → SVG presentation attributes
3
+ * (docs/design/carto-substrate.md §6, "Style mapping").
4
+ *
5
+ * The mapping is EXPLICIT and its divergences are documented rather than
6
+ * discovered. deck's blending, antialiasing and dash rendering do not match
7
+ * SVG's exactly; what matters is that every difference here is a decision
8
+ * somebody made, and that the visual-diff gate measures the total.
9
+ */
10
+ import type { LayerIR } from "../ir";
11
+ export interface ResolvedStyle {
12
+ fill: string;
13
+ fillOpacity: number;
14
+ stroke: string;
15
+ strokeOpacity: number;
16
+ strokeWidth: number;
17
+ dashArray?: string;
18
+ /** Point radius in px — Scatterplot and friends. */
19
+ radius?: number;
20
+ }
21
+ /** deck colours are `[r, g, b]` or `[r, g, b, a]` with a in 0-255; SVG wants a hex triple plus a 0-1 opacity. */
22
+ export declare function deckColorToSvg(value: unknown): {
23
+ color: string;
24
+ opacity: number;
25
+ };
26
+ /**
27
+ * The accessor names, per family, in the order they should be tried.
28
+ *
29
+ * deck does NOT use one vocabulary. `PathLayer` and `LineLayer` say
30
+ * `getColor`/`getWidth`; `GeoJsonLayer`, `PolygonLayer` and `ScatterplotLayer`
31
+ * say `getLineColor`/`getLineWidth`; `ArcLayer` says `getSourceColor`. Reading
32
+ * only the GeoJSON names made every PathLayer export as a black hairline —
33
+ * deck's defaults, faithfully rendered, and nothing like the authored map.
34
+ * Enumerated from the registry rather than remembered, and pinned by a test.
35
+ */
36
+ export declare const STROKE_COLOR_PROPS: readonly ["getLineColor", "getColor", "getSourceColor"];
37
+ export declare const STROKE_WIDTH_PROPS: readonly ["getLineWidth", "getWidth"];
38
+ export declare const WIDTH_SCALE_PROPS: readonly ["lineWidthScale", "widthScale"];
39
+ export declare const WIDTH_UNITS_PROPS: readonly ["lineWidthUnits", "widthUnits"];
40
+ export declare const WIDTH_MIN_PROPS: readonly ["lineWidthMinPixels", "widthMinPixels"];
41
+ export declare const WIDTH_MAX_PROPS: readonly ["lineWidthMaxPixels", "widthMaxPixels"];
42
+ export declare const RADIUS_PROPS: readonly ["getRadius", "getPointRadius"];
43
+ export declare const RADIUS_SCALE_PROPS: readonly ["radiusScale", "pointRadiusScale"];
44
+ export declare const RADIUS_UNITS_PROPS: readonly ["radiusUnits", "pointRadiusUnits"];
45
+ export declare const RADIUS_MIN_PROPS: readonly ["radiusMinPixels", "pointRadiusMinPixels"];
46
+ export declare const RADIUS_MAX_PROPS: readonly ["radiusMaxPixels", "pointRadiusMaxPixels"];
47
+ /**
48
+ * Line width in SCREEN PIXELS, which is what SVG needs.
49
+ *
50
+ * `lineWidthUnits: "meters"` is deck's other mode, and it is the one that
51
+ * cannot be resolved per feature without the viewport's scale — so the caller
52
+ * passes `metresPerPixel` and this converts. Getting that wrong is not subtle:
53
+ * a 20-metre road casing emitted as 20 px is a black sheet.
54
+ */
55
+ export declare function resolveLineWidth(ir: LayerIR, row: unknown, index: number, metresPerPixel: number): number;
56
+ /** Point radius in screen pixels, by the same rules deck applies to `getRadius`. */
57
+ export declare function resolveRadius(ir: LayerIR, row: unknown, index: number, metresPerPixel: number): number;
58
+ /**
59
+ * `dash` → `stroke-dasharray`.
60
+ *
61
+ * deck's `PathStyleExtension` states the dash in LINE-WIDTH UNITS, and SVG's
62
+ * dasharray is in user units — pixels here. So the pattern scales with the
63
+ * resolved stroke width, which is also what makes a dashed border look the
64
+ * same after a zoom change.
65
+ */
66
+ export declare function resolveDashArray(ir: LayerIR, strokeWidthPx: number): string | undefined;
67
+ /**
68
+ * Everything a single feature needs to be drawn, resolved once.
69
+ *
70
+ * `filled` and `stroked` are honoured as deck honours them — a `filled: false`
71
+ * polygon layer emits `fill="none"` rather than a transparent fill, because a
72
+ * transparent fill still costs the renderer a shape and still shows in an
73
+ * editor's object list.
74
+ */
75
+ export declare function resolveFeatureStyle(ir: LayerIR, row: unknown, index: number, metresPerPixel: number): ResolvedStyle;
76
+ /** The presentation attributes for a filled+stroked shape, as an attribute string. */
77
+ export declare function styleAttributes(style: ResolvedStyle, kind: "area" | "line"): string;
@@ -4,6 +4,30 @@
4
4
  * serialized to the consumer's preferred shape.
5
5
  */
6
6
  export interface SnapshotOptions {
7
+ /**
8
+ * `"raster"` (the default) is the canvas capture every existing caller gets.
9
+ * `"svg"` runs the vector serializer instead (docs/design/carto-substrate.md
10
+ * §6): vector linework for the layers whose geometry IS the data, raster
11
+ * bands for the ones whose appearance is pixels, real `<text>` for labels.
12
+ *
13
+ * The serializer is a LAZY chunk — asking for raster never downloads it.
14
+ */
15
+ format?: "raster" | "svg";
16
+ /**
17
+ * SVG only: the raster bands' own resolution, independent of the sheet's.
18
+ * Default 600 — anyone exporting vector is exporting for print quality, and
19
+ * a surprising file size is easier to discover and fix than surprising soft
20
+ * type.
21
+ */
22
+ effectDpi?: number;
23
+ /** SVG only: above this many emitted elements the result carries a notice offering `simplify`. */
24
+ featureBudget?: number;
25
+ /** SVG only: receives the serializer's dev notices. Without it they go to the console. */
26
+ onNotice?: (notice: {
27
+ code: string;
28
+ message: string;
29
+ fix: string;
30
+ }) => void;
7
31
  /** Image MIME type — default "image/png". */
8
32
  type?: "image/png" | "image/jpeg" | "image/webp";
9
33
  /** Lossy-format quality 0–1 (jpeg/webp). */
@@ -44,3 +68,25 @@ export declare function captureStable(core: {
44
68
  maxRounds?: number;
45
69
  requiredStableRuns?: number;
46
70
  }): Promise<string | Blob>;
71
+ /**
72
+ * `snapshot({ format: "svg" })` — shared by both front-ends, one definition,
73
+ * for the same reason `captureStable` is.
74
+ *
75
+ * Notices reach the caller through `onNotice` when it supplies one, and the
76
+ * console otherwise. They are never silent: an author who wanted editable type
77
+ * and did not realise a finish forecloses it should be told here, not in a
78
+ * print shop.
79
+ */
80
+ export declare function snapshotSvg(core: {
81
+ serializeSvg(opts: {
82
+ effectDpi?: number;
83
+ featureBudget?: number;
84
+ }): Promise<{
85
+ svg: string;
86
+ notices: {
87
+ code: string;
88
+ message: string;
89
+ fix: string;
90
+ }[];
91
+ }>;
92
+ }, opts: SnapshotOptions): Promise<string | Blob>;
@@ -11,6 +11,12 @@
11
11
  */
12
12
  import type { LayerData } from "./ir";
13
13
  import type { Shape } from "./expr";
14
+ /**
15
+ * Even-odd crossing test. Exported because `transform/dot-density.ts` needs
16
+ * exactly this and had a byte-identical private copy — so a fix to the
17
+ * degenerate horizontal-edge case would have landed in one of them.
18
+ */
19
+ export declare function pointInRing(ring: readonly (readonly number[])[], x: number, y: number): boolean;
14
20
  /** A point guaranteed inside the largest ring of the geometry (see module doc). */
15
21
  export declare function pointOnSurface(coords: unknown): [number, number] | null;
16
22
  /** Installs the surface-anchored getPosition (no-ops: no anchor, authored position, no rows yet). */
@@ -0,0 +1,146 @@
1
+ import { c as S, a3 as b } from "./index-CBYDP-_0.js";
2
+ const A = Math.PI / 180, P = /* @__PURE__ */ new Map();
3
+ let d = null;
4
+ function T(t) {
5
+ if (typeof document > "u") return null;
6
+ if (!d) {
7
+ const r = document.createElement("canvas");
8
+ r.width = 8, r.height = 8, d = r.getContext("2d");
9
+ }
10
+ return d && (d.font = t), d;
11
+ }
12
+ function C(t, r, e) {
13
+ const n = `${e} 100px ${r}`;
14
+ let s = P.get(n);
15
+ s || (s = /* @__PURE__ */ new Map(), P.set(n, s));
16
+ const c = s.get(t);
17
+ if (c !== void 0) return c;
18
+ const l = T(n), a = l ? l.measureText(t).width / 100 : 0.6;
19
+ return s.set(t, a), a;
20
+ }
21
+ function L(t) {
22
+ const r = [0];
23
+ let e = 0;
24
+ for (let n = 1; n < t.length; n++)
25
+ e += Math.hypot(t[n][0] - t[n - 1][0], t[n][1] - t[n - 1][1]), r.push(e);
26
+ return { cumulative: r, total: e };
27
+ }
28
+ function x(t, r, e) {
29
+ const { cumulative: n } = r;
30
+ if (t.length < 2) return null;
31
+ let s = 1;
32
+ for (; s < n.length - 1 && n[s] < e; ) s++;
33
+ const c = n[s] - n[s - 1], l = c > 0 ? (e - n[s - 1]) / c : 0, a = t[s - 1], o = t[s];
34
+ return {
35
+ position: [a[0] + (o[0] - a[0]) * l, a[1] + (o[1] - a[1]) * l],
36
+ angle: Math.atan2(-(o[1] - a[1]), o[0] - a[0]) * 180 / Math.PI
37
+ };
38
+ }
39
+ function M(t, r, e) {
40
+ if (e === 0) return t;
41
+ const n = (r + 90) * A;
42
+ return [t[0] + Math.cos(n) * e, t[1] - Math.sin(n) * e];
43
+ }
44
+ function z(t) {
45
+ return t === "start" ? "end" : t === "end" ? "start" : "middle";
46
+ }
47
+ function w(t, r, e) {
48
+ if (t.length < 2 || !r) return [];
49
+ const n = L(t);
50
+ if (!(n.total > 0)) return [];
51
+ const s = [...r], c = s.map((i) => C(i, e.fontFamily, e.fontWeight) * e.sizePx + e.letterSpacing), l = c.reduce((i, u) => i + u, 0) - e.letterSpacing;
52
+ if (l > n.total) return [];
53
+ const a = n.total - l, o = e.placement === "start" ? 0 : e.placement === "end" ? a : a / 2, g = x(t, n, o), h = x(t, n, o + l);
54
+ if (g && h && h.position[0] < g.position[0]) {
55
+ const i = [...t].reverse();
56
+ return w(i, r, { ...e, placement: z(e.placement), offsetPx: -e.offsetPx });
57
+ }
58
+ let p = o;
59
+ const m = [];
60
+ for (let i = 0; i < s.length; i++) {
61
+ const u = x(t, n, p + (c[i] - e.letterSpacing) / 2);
62
+ if (!u) break;
63
+ m.push({ position: M(u.position, u.angle, e.offsetPx), angle: u.angle, char: s[i] }), p += c[i];
64
+ }
65
+ return m;
66
+ }
67
+ function y(t, r, e, n, s) {
68
+ if (typeof t != "function") return t ?? s;
69
+ try {
70
+ return t(r, { index: e, data: n });
71
+ } catch {
72
+ return s;
73
+ }
74
+ }
75
+ class O extends S {
76
+ static layerName = "OmTextOnPathLayer";
77
+ static defaultProps = {
78
+ getPath: { type: "accessor", value: (r) => r.path },
79
+ getText: { type: "accessor", value: (r) => r.text },
80
+ getSize: { type: "accessor", value: 14 },
81
+ getColor: { type: "accessor", value: [30, 30, 30, 255] },
82
+ fontFamily: { type: "string", value: "sans-serif" },
83
+ fontWeight: { type: "string", value: "normal" },
84
+ letterSpacing: { type: "number", value: 0 },
85
+ offset: { type: "number", value: 0 },
86
+ placement: { type: "string", value: "middle" },
87
+ maxLabels: { type: "number", value: 2e3 }
88
+ };
89
+ /** Recompute on a viewport change: a glyph advance is pixels and a path is world distance. */
90
+ shouldUpdateState({ changeFlags: r }) {
91
+ return !!r.somethingChanged;
92
+ }
93
+ renderLayers() {
94
+ const r = this.context.viewport;
95
+ if (!r || !r.width) return null;
96
+ const e = Array.isArray(this.props.data) ? this.props.data : [], n = ["start", "middle", "end"].includes(this.props.placement) ? this.props.placement : "middle", s = this.props.fontFamily ?? "sans-serif", c = this.props.fontWeight ?? "normal", l = this.props.maxLabels ?? 2e3, a = [];
97
+ for (let o = 0; o < e.length && a.length < l; o++) {
98
+ const g = e[o], h = y(this.props.getPath, g, o, e, void 0), p = String(y(this.props.getText, g, o, e, "") ?? "");
99
+ if (!Array.isArray(h) || h.length < 2 || !p) continue;
100
+ const m = Number(y(this.props.getSize, g, o, e, 14)) || 14, i = y(this.props.getColor, g, o, e, [30, 30, 30, 255]), u = h.map((f) => r.project([f[0], f[1]]).slice(0, 2));
101
+ for (const f of w(u, p, {
102
+ fontFamily: s,
103
+ fontWeight: c,
104
+ sizePx: m,
105
+ letterSpacing: this.props.letterSpacing ?? 0,
106
+ offsetPx: this.props.offset ?? 0,
107
+ placement: n
108
+ })) {
109
+ const v = r.unproject([f.position[0], f.position[1]]);
110
+ if (a.push({
111
+ char: f.char,
112
+ position: [v[0], v[1]],
113
+ angle: f.angle,
114
+ size: m,
115
+ color: Array.isArray(i) ? i : [30, 30, 30, 255]
116
+ }), a.length >= l) break;
117
+ }
118
+ }
119
+ return a.length === 0 ? null : new b(
120
+ this.getSubLayerProps({ id: "glyphs" }),
121
+ {
122
+ data: a,
123
+ getText: (o) => o.char,
124
+ getPosition: (o) => o.position,
125
+ getAngle: (o) => o.angle,
126
+ getSize: (o) => o.size,
127
+ getColor: (o) => o.color,
128
+ fontFamily: s,
129
+ fontWeight: c,
130
+ getTextAnchor: "middle",
131
+ getAlignmentBaseline: "center",
132
+ characterSet: "auto",
133
+ // Every glyph is its own instance, so deck's own collision would fight
134
+ // the word it belongs to. The whole label is placed or dropped.
135
+ updateTriggers: { getText: a.length, getPosition: a.length }
136
+ }
137
+ );
138
+ }
139
+ }
140
+ export {
141
+ O as OmTextOnPathLayer,
142
+ C as charAdvance,
143
+ L as pathMetrics,
144
+ w as placeTextOnPath,
145
+ x as pointAtDistance
146
+ };
@@ -0,0 +1,157 @@
1
+ /**
2
+ * `TextOnPathLayer` — a label that follows the line it names.
3
+ *
4
+ * The oldest label convention there is: a river's name runs along the river, a
5
+ * coastline's along the coast, a contour's along the contour. deck has no such
6
+ * layer, so this is a composite that explodes each string into ONE TEXT
7
+ * INSTANCE PER GLYPH, each placed at its own arc-length position along the path
8
+ * and rotated to the local tangent. The rendering is therefore an ordinary
9
+ * `TextLayer` — same font atlas, same collision behaviour, same picking.
10
+ *
11
+ * **Placement is recomputed when the camera moves, and cannot not be.** A glyph
12
+ * advance is a length in PIXELS while a path is a length in the world, so the
13
+ * mapping between them is the current scale. On a print sheet, where the camera
14
+ * is fixed, that resolves once and stays put — which is the case this exists
15
+ * for. On a live map it follows the zoom, which is why the work is bounded by
16
+ * `maxLabels` rather than by the data.
17
+ *
18
+ * Measured with a real canvas rather than an estimate, for the reason
19
+ * `cartograph/textlayout.ts` already states: two measurers disagree at the
20
+ * margins, so everything that has to agree must read the SAME numbers. The
21
+ * serializer emits SVG `<textPath>` from the same path and string, which is the
22
+ * one output where the browser re-measures — and it is also the output where
23
+ * `<textPath>` is exactly the right primitive.
24
+ */
25
+ import { CompositeLayer, type Layer } from "@deck.gl/core";
26
+ export type PathPlacement = "start" | "middle" | "end";
27
+ export interface OmTextOnPathLayerProps {
28
+ data?: unknown;
29
+ getPath?: unknown;
30
+ getText?: unknown;
31
+ getSize?: unknown;
32
+ getColor?: unknown;
33
+ fontFamily?: string;
34
+ fontWeight?: string | number;
35
+ /** Extra tracking between glyphs, in pixels. Letter-spaced names are a cartographic convention, not a flourish. */
36
+ letterSpacing?: number;
37
+ /** Perpendicular offset in pixels — positive is to the LEFT of the path's direction. */
38
+ offset?: number;
39
+ placement?: PathPlacement;
40
+ /** Ceiling on emitted glyphs, so one enormous label set cannot wedge a frame. */
41
+ maxLabels?: number;
42
+ opacity?: number;
43
+ visible?: boolean;
44
+ }
45
+ /** Advance width of one character at 100px, which scales linearly to any size. */
46
+ export declare function charAdvance(char: string, fontFamily: string, fontWeight: string | number): number;
47
+ /**
48
+ * Placement happens in SCREEN PIXELS, and that is the whole design.
49
+ *
50
+ * The first version worked in ground metres and was wrong in a way that only a
51
+ * projected sheet revealed: a glyph advance is a length in PIXELS, so turning
52
+ * it into a world distance needs a scale — and "the world" is lng/lat on a
53
+ * Mercator map and plane metres on a projected one, with the layer's own data
54
+ * already converted to whichever by the time it arrives. Two spaces, one set
55
+ * of arithmetic, and it produced label lengths off by seven orders of
56
+ * magnitude on an Albers plate.
57
+ *
58
+ * Projecting the path first removes the question entirely: advances are
59
+ * already pixels, the path is already pixels, and each glyph's centre is
60
+ * unprojected back into whatever space the viewport uses. Correct in every
61
+ * projection, and shorter.
62
+ */
63
+ export type ScreenPoint = [number, number];
64
+ /** Cumulative pixel length along a projected path. */
65
+ export declare function pathMetrics(path: readonly ScreenPoint[]): {
66
+ cumulative: number[];
67
+ total: number;
68
+ };
69
+ /**
70
+ * The screen point and tangent angle at a pixel distance along the path.
71
+ *
72
+ * The angle is in deck's `getAngle` convention: DEGREES COUNTERCLOCKWISE with
73
+ * 0 pointing east. Screen y runs DOWN, so the sign is flipped on the way out —
74
+ * without that every label reads mirrored, which looks like a broken font
75
+ * rather than a wrong angle.
76
+ */
77
+ export declare function pointAtDistance(path: readonly ScreenPoint[], metrics: {
78
+ cumulative: number[];
79
+ }, distance: number): {
80
+ position: ScreenPoint;
81
+ angle: number;
82
+ } | null;
83
+ export interface PlaceOptions {
84
+ fontFamily: string;
85
+ fontWeight: string | number;
86
+ sizePx: number;
87
+ letterSpacing: number;
88
+ offsetPx: number;
89
+ placement: PathPlacement;
90
+ }
91
+ /**
92
+ * Lay one string along one projected path. Returns nothing when the label is
93
+ * longer than the path — a name that does not fit is DROPPED rather than
94
+ * compressed or run off the end, which is what a cartographer would do and the
95
+ * only option that never leaves a label pointing at nothing.
96
+ */
97
+ export declare function placeTextOnPath(path: readonly ScreenPoint[], text: string, opts: PlaceOptions): {
98
+ position: ScreenPoint;
99
+ angle: number;
100
+ char: string;
101
+ }[];
102
+ export declare class OmTextOnPathLayer extends CompositeLayer<OmTextOnPathLayerProps> {
103
+ static layerName: string;
104
+ static defaultProps: {
105
+ getPath: {
106
+ type: string;
107
+ value: (d: {
108
+ path?: number[][];
109
+ }) => number[][] | undefined;
110
+ };
111
+ getText: {
112
+ type: string;
113
+ value: (d: {
114
+ text?: string;
115
+ }) => string | undefined;
116
+ };
117
+ getSize: {
118
+ type: string;
119
+ value: number;
120
+ };
121
+ getColor: {
122
+ type: string;
123
+ value: number[];
124
+ };
125
+ fontFamily: {
126
+ type: string;
127
+ value: string;
128
+ };
129
+ fontWeight: {
130
+ type: string;
131
+ value: string;
132
+ };
133
+ letterSpacing: {
134
+ type: string;
135
+ value: number;
136
+ };
137
+ offset: {
138
+ type: string;
139
+ value: number;
140
+ };
141
+ placement: {
142
+ type: string;
143
+ value: string;
144
+ };
145
+ maxLabels: {
146
+ type: string;
147
+ value: number;
148
+ };
149
+ };
150
+ /** Recompute on a viewport change: a glyph advance is pixels and a path is world distance. */
151
+ shouldUpdateState({ changeFlags }: {
152
+ changeFlags: {
153
+ somethingChanged?: boolean;
154
+ };
155
+ }): boolean;
156
+ renderLayers(): Layer | null;
157
+ }