@nika-js/onlymap 0.1.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.
Files changed (77) hide show
  1. package/.vscode/onlymap.code-snippets +173 -0
  2. package/LICENSE.md +133 -0
  3. package/README.md +188 -0
  4. package/bin/onlymapjs.mjs +182 -0
  5. package/dist/Arrow.dom-7AXne1TU.js +5233 -0
  6. package/dist/actions.d.ts +30 -0
  7. package/dist/attribute-resolution.d.ts +73 -0
  8. package/dist/basemap-D95W0IIA.js +25203 -0
  9. package/dist/basemap.d.ts +72 -0
  10. package/dist/convert-arrow-schema-CvZ3cT5m.js +94 -0
  11. package/dist/csp-sandbox.d.ts +20 -0
  12. package/dist/ctx.d.ts +49 -0
  13. package/dist/d3-bundle.d.ts +218 -0
  14. package/dist/data-emit.d.ts +10 -0
  15. package/dist/data-layer.d.ts +150 -0
  16. package/dist/declarative-filter.d.ts +12 -0
  17. package/dist/dev-error-panel.d.ts +15 -0
  18. package/dist/draw-controller.d.ts +51 -0
  19. package/dist/draw.d.ts +102 -0
  20. package/dist/effects.d.ts +39 -0
  21. package/dist/elements/om-behavior.d.ts +13 -0
  22. package/dist/elements/om-layer.d.ts +11 -0
  23. package/dist/elements/om-map.d.ts +168 -0
  24. package/dist/elements/om-overlay.d.ts +82 -0
  25. package/dist/elements/om-step.d.ts +12 -0
  26. package/dist/elements/om-story.d.ts +67 -0
  27. package/dist/elements/om-widget.d.ts +29 -0
  28. package/dist/env.d.ts +41 -0
  29. package/dist/expr/cache.d.ts +28 -0
  30. package/dist/expr/compile.d.ts +27 -0
  31. package/dist/expr/errors.d.ts +10 -0
  32. package/dist/expr/full-js-block.d.ts +17 -0
  33. package/dist/expr/index.d.ts +12 -0
  34. package/dist/expr/output-type.d.ts +12 -0
  35. package/dist/expr/scale.d.ts +13 -0
  36. package/dist/expr/script-block.d.ts +16 -0
  37. package/dist/expr/whitelist.d.ts +28 -0
  38. package/dist/field-access.d.ts +24 -0
  39. package/dist/html-data.d.ts +25 -0
  40. package/dist/index-2v2NXF_n.js +435 -0
  41. package/dist/index-BFjXVHly.js +605 -0
  42. package/dist/index-C9w78NS9.js +4883 -0
  43. package/dist/index-CU-iOTdr.js +75292 -0
  44. package/dist/index-D74olQ9w.js +3907 -0
  45. package/dist/index-Do7hmHwi.js +1457 -0
  46. package/dist/index.d.ts +76 -0
  47. package/dist/ir-snapshot.d.ts +54 -0
  48. package/dist/ir.d.ts +66 -0
  49. package/dist/layer-registry.d.ts +27 -0
  50. package/dist/layers/popup-layer.d.ts +65 -0
  51. package/dist/onlymapjs.css +1 -0
  52. package/dist/onlymapjs.js +30 -0
  53. package/dist/onlymapjs.umd.cjs +8618 -0
  54. package/dist/parse-manifest.d.ts +19 -0
  55. package/dist/recordbatch-HRu0SMKp.js +4742 -0
  56. package/dist/runtime-core.d.ts +170 -0
  57. package/dist/selection.d.ts +31 -0
  58. package/dist/stats.d.ts +29 -0
  59. package/dist/table-accessors-DBjWgN0C.js +204 -0
  60. package/dist/template-interpolation.d.ts +6 -0
  61. package/dist/testing.d.ts +90 -0
  62. package/dist/timeline.d.ts +37 -0
  63. package/dist/validation.d.ts +22 -0
  64. package/dist/vega-loader.d.ts +22 -0
  65. package/dist/viewport-filter.d.ts +25 -0
  66. package/dist/widget-registry.d.ts +23 -0
  67. package/dist/widget-script.d.ts +1 -0
  68. package/dist/widgets/built-in.d.ts +1 -0
  69. package/dist/widgets/dom-utils.d.ts +4 -0
  70. package/llms.txt +43 -0
  71. package/onlymapjs.html-data.json +1688 -0
  72. package/package.json +111 -0
  73. package/skills/onlymapjs/SKILL.md +61 -0
  74. package/skills/onlymapjs/agents/openai.yaml +4 -0
  75. package/skills/onlymapjs/references/patterns.md +213 -0
  76. package/skills/onlymapjs/references/syntax.md +342 -0
  77. package/skills/onlymapjs/references/testing.md +126 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Accessor cache (spec: Phase 2 "Accessor cache (memoize by source string)").
3
+ * Same string (+ shape + bound param) always returns the same compiled
4
+ * reference — this is the reference-stability half of the reconciliation
5
+ * story (see "Memoize-by-source" in Layer Reconciliation); the correctness
6
+ * half (`updateTriggers` fingerprinting) is the reconciler's job (see
7
+ * runtime-core.ts / LayerIR.updateTriggers), not this module's — but this
8
+ * module's key format IS the fingerprint value, so the same string serves
9
+ * both purposes.
10
+ *
11
+ * Eviction (Q4: mark-and-sweep against the reconciler's live accessor set)
12
+ * is implemented here as `sweep()`, but this cache still doesn't know what's
13
+ * live on its own — the caller (parse-manifest.ts, once per full reconcile,
14
+ * across all layers) collects the live key set via `cacheKey()` and passes
15
+ * it in.
16
+ */
17
+ import { type CompileOptions, type CompiledExpression } from "./compile";
18
+ /** The cache key — also used directly as the deck.gl `updateTrigger` fingerprint. */
19
+ export declare function cacheKey(source: string, opts: CompileOptions): string;
20
+ export declare class AccessorCache {
21
+ #private;
22
+ compile(source: string, opts: CompileOptions): CompiledExpression;
23
+ keys(): IterableIterator<string>;
24
+ delete(key: string): boolean;
25
+ /** Drop every cached entry whose key is not in `liveKeys` (mark-and-sweep, Q4). */
26
+ sweep(liveKeys: ReadonlySet<string>): void;
27
+ get size(): number;
28
+ }
@@ -0,0 +1,27 @@
1
+ export type Shape = "flat" | "geojson" | "columnar";
2
+ export interface CompileOptions {
3
+ shape: Shape;
4
+ /** The bound datum parameter name. Default "d" (attribute mode). */
5
+ paramName?: string;
6
+ /** `$field` sugar is attribute-only per spec; script-block mode disables it. */
7
+ allowDollarSugar?: boolean;
8
+ /** Used only for the dev-mode `//# sourceURL` and error messages. */
9
+ debugName?: string;
10
+ /** e.g. "getFillColor" — enables a best-effort static output-shape check. */
11
+ accessorName?: string;
12
+ }
13
+ export interface CompiledExpression {
14
+ /** The validated, rewritten JS expression text (what `new Function` receives). */
15
+ jsBody: string;
16
+ /**
17
+ * The ready-to-use accessor — `(d) => value` for row shapes. Columnar
18
+ * accessors never read `d`; they read `info.data.columns.<field>[info.index]`
19
+ * from deck.gl's second accessor argument (its non-iterable-data calling
20
+ * convention), which is why `info` is part of the signature.
21
+ */
22
+ fn: (d: unknown, info?: {
23
+ index: number;
24
+ data: unknown;
25
+ }) => unknown;
26
+ }
27
+ export declare function compileExpression(source: string, opts: CompileOptions): CompiledExpression;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Structured, plain-English errors (spec: Phase 2 "Plain-English error
3
+ * messages"). Shape is forward-compatible with the full Manifest Validation
4
+ * entry (Phase 6) — `{ element, attribute, message, fix }` — this module
5
+ * only owns `message` + `fix`; the caller attaches element/attribute context.
6
+ */
7
+ export declare class CompileError extends Error {
8
+ readonly fix: string;
9
+ constructor(message: string, fix: string);
10
+ }
@@ -0,0 +1,17 @@
1
+ export interface CompiledJsBlock {
2
+ /** exported name -> whatever the block assigned it (function or constant — deck.gl accepts both). */
3
+ accessors: Record<string, unknown>;
4
+ }
5
+ /**
6
+ * Strips `export` from each top-level declaration, collecting the exported
7
+ * names into a trailing `return { ... }`. Exported (not just used internally
8
+ * by `compileFullJsAccessorBlock`) so the CSP-safe sandboxed evaluator
9
+ * (csp-sandbox.ts) can produce the exact same transformed source and hand
10
+ * it to a `new Function` running inside an isolated iframe instead of the
11
+ * main-world one here.
12
+ */
13
+ export declare function buildFullJsSource(blockText: string): {
14
+ source: string;
15
+ names: string[];
16
+ };
17
+ export declare function compileFullJsAccessorBlock(blockText: string, debugName?: string): CompiledJsBlock;
@@ -0,0 +1,12 @@
1
+ export { compileExpression } from "./compile";
2
+ export type { Shape, CompileOptions, CompiledExpression } from "./compile";
3
+ export { AccessorCache, cacheKey } from "./cache";
4
+ export { CompileError } from "./errors";
5
+ export { SCALE_TYPES, isScaleType } from "./scale";
6
+ export type { ScaleType } from "./scale";
7
+ export { ACCESSOR_OUTPUT_SHAPES } from "./output-type";
8
+ export type { AccessorOutputShape } from "./output-type";
9
+ export { parseRestrictedAccessorBlock } from "./script-block";
10
+ export type { AccessorExport } from "./script-block";
11
+ export { compileFullJsAccessorBlock, buildFullJsSource } from "./full-js-block";
12
+ export type { CompiledJsBlock } from "./full-js-block";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Output type validation per accessor (spec: "Type validation per accessor").
3
+ * A best-effort STATIC shape check on the parsed AST — not full type
4
+ * inference. It only raises an error when it can positively prove a
5
+ * mismatch (e.g. a bare number literal where an array was expected);
6
+ * anything opaque (a field reference, a call result, arithmetic) is left
7
+ * unchecked rather than risk a false positive on a valid expression.
8
+ */
9
+ import type { Expression } from "estree";
10
+ export type AccessorOutputShape = "position" | "color" | "number" | "string";
11
+ export declare const ACCESSOR_OUTPUT_SHAPES: Readonly<Record<string, AccessorOutputShape>>;
12
+ export declare function validateOutputShape(node: Expression, accessorName: string): void;
@@ -0,0 +1,13 @@
1
+ export declare const SCALE_TYPES: readonly ["sequential", "diverging", "threshold", "sqrt", "log", "pow"];
2
+ export type ScaleType = (typeof SCALE_TYPES)[number];
3
+ export declare function isScaleType(name: string): name is ScaleType;
4
+ /** A resolved, callable D3 scale — `(value) => output`. */
5
+ export type CompiledScale = (value: number) => unknown;
6
+ export declare function buildScale(type: ScaleType, range: unknown[], domain: number[]): CompiledScale;
7
+ /**
8
+ * `colorRamp(value, domain, colors)` — the doc names this as a registered
9
+ * built-in alongside scale()/clamp()/lerp() without giving a worked example;
10
+ * implemented as sugar for a two-stop-or-more sequential color scale, the
11
+ * natural reading of "ramp a value across a set of colors".
12
+ */
13
+ export declare function buildColorRamp(domain: [number, number], colors: string[]): CompiledScale;
@@ -0,0 +1,16 @@
1
+ export interface AccessorExport {
2
+ /** The exported name — a deck.gl accessor prop verbatim, e.g. "getFillColor". */
3
+ name: string;
4
+ /** The arrow's own parameter name (usually "d", but any identifier is allowed). */
5
+ paramName: string;
6
+ /** The arrow body's own source text, ready to feed into `compileExpression`. */
7
+ bodySource: string;
8
+ }
9
+ /**
10
+ * Parses a restricted (no `js`/`unsafe`) accessor block into one entry per
11
+ * `export const name = d => <expression>`. Throws a CompileError, with the
12
+ * `js`/`unsafe` opt-in suggested as the fix, for any shape outside that one
13
+ * form — block bodies, extra/destructured params, function declarations,
14
+ * imports, helper statements, etc.
15
+ */
16
+ export declare function parseRestrictedAccessorBlock(blockText: string): AccessorExport[];
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Shared whitelist constants (spec: "AST node whitelist (derived from
3
+ * necessity)" and "Contextual rules for MemberExpression and CallExpression").
4
+ * The node-type dispatch itself lives in compile.ts; this module is just the
5
+ * small, auditable set of names the contextual rules check against.
6
+ */
7
+ /** Reserved property keys blocked on any MemberExpression, regardless of root. */
8
+ export declare const BLOCKED_KEYS: ReadonlySet<string>;
9
+ /**
10
+ * Bare identifiers allowed as VALUES (not necessarily as further member-access
11
+ * roots — see MEMBER_ROOT_IDENTIFIERS below, which is stricter). The datum
12
+ * parameter name itself is added by the caller since it's configurable.
13
+ */
14
+ export declare const SAFE_VALUE_IDENTIFIERS: ReadonlySet<string>;
15
+ /**
16
+ * Identifiers allowed as the ultimate root of a MemberExpression chain
17
+ * (`d.field`, `Math.sqrt`). Deliberately narrower than SAFE_VALUE_IDENTIFIERS —
18
+ * no documented pattern needs `Number.foo`/`String.foo`/`Boolean.foo` member
19
+ * access, only their bare call forms (`Number(x)`), so member-rooting is
20
+ * restricted to the datum and `Math`.
21
+ */
22
+ export declare const MEMBER_ROOT_IDENTIFIERS: ReadonlySet<string>;
23
+ /** Bare-identifier CallExpression callees allowed beyond the registered scale/clamp/lerp/colorRamp builtins. */
24
+ export declare const CONSTRUCTOR_STYLE_CALLS: ReadonlySet<string>;
25
+ /** Unary operators allowed (delete/void excluded per spec). */
26
+ export declare const ALLOWED_UNARY_OPERATORS: ReadonlySet<string>;
27
+ /** Binary operators allowed (in/instanceof excluded per spec). */
28
+ export declare function isAllowedBinaryOperator(op: string): boolean;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Shape-aware field access (spec: "Feature Field Resolution & Data Shape").
3
+ * The same field name resolves differently depending on the layer's detected
4
+ * shape — `d.field` (flat) vs `d.properties.field` (GeoJSON) — mirrored here
5
+ * for ctx.stats/dataInViewport so widget code never has to think about it.
6
+ */
7
+ import type { Shape, LayerData } from "./ir";
8
+ export declare function getField(row: unknown, field: string, shape: Shape): unknown;
9
+ /** Normalizes a picked feature to flat (GeoJSON properties lifted to the top level) — for ctx.selection.object. */
10
+ export declare function flattenFeature(row: unknown, shape: Shape): unknown;
11
+ /**
12
+ * Best-effort feature-id matching for the `highlight-feature` action and the
13
+ * id form of `zoom-to-feature` (spec: "Action payload contract"). The spec
14
+ * doesn't prescribe an id-extraction convention, so this checks the two
15
+ * conventional sources: a GeoJSON Feature's own top-level `id` (RFC 7946),
16
+ * and a plain `id` field on the (possibly shape-flattened) datum.
17
+ */
18
+ export declare function matchesFeatureId(row: unknown, featureId: string, shape: Shape): boolean;
19
+ /**
20
+ * Id → row index over any LayerData (`highlight-feature`, `zoom-to-feature`
21
+ * id form). Id lookup is row-semantics, so columnar layers scan the memoized
22
+ * asRows view — the Tier-2 rule, stated once here instead of at each caller.
23
+ */
24
+ export declare function findRowIndexById(data: LayerData, featureId: string, shape: Shape): number;
@@ -0,0 +1,25 @@
1
+ interface AttrData {
2
+ name: string;
3
+ description: string;
4
+ values?: {
5
+ name: string;
6
+ }[];
7
+ }
8
+ interface TagData {
9
+ name: string;
10
+ description: string;
11
+ attributes: AttrData[];
12
+ references?: {
13
+ name: string;
14
+ url: string;
15
+ }[];
16
+ }
17
+ /** Hand-authored action list — validated against hasAction() in html-data.test.ts. */
18
+ export declare const BUILTIN_ACTIONS: readonly ["toggle-layer", "zoom-in", "zoom-out", "filter-layer", "highlight-feature", "fade", "pulse", "populate", "trace", "story-play", "story-pause", "story-seek", "fly-to", "zoom-to-feature", "show-overlay", "hide-overlay", "show-tooltip", "hide-tooltip", "draw-mode", "draw-commit", "draw-cancel", "draw-delete", "draw-clear", "draw-config", "draw-save"];
19
+ /** Hand-authored widget types — validated against the widget registry in html-data.test.ts. */
20
+ export declare const BUILTIN_WIDGETS: readonly ["legend", "layer-switcher", "zoom-controls", "scale-bar", "attribution", "filter", "vega-lite", "player", "draw"];
21
+ export declare function buildHtmlCustomData(): {
22
+ version: number;
23
+ tags: TagData[];
24
+ };
25
+ export {};
@@ -0,0 +1,435 @@
1
+ var gr = ArrayBuffer, F = Uint8Array, _ = Uint16Array, zr = Int16Array, s = Int32Array, t = function(r, e, i) {
2
+ if (F.prototype.slice)
3
+ return F.prototype.slice.call(r, e, i);
4
+ (e == null || e < 0) && (e = 0), (i == null || i > r.length) && (i = r.length);
5
+ var n = new F(i - e);
6
+ return n.set(r.subarray(e, i)), n;
7
+ }, P = function(r, e, i, n) {
8
+ if (F.prototype.fill)
9
+ return F.prototype.fill.call(r, e, i, n);
10
+ for ((i == null || i < 0) && (i = 0), (n == null || n > r.length) && (n = r.length); i < n; ++i)
11
+ r[i] = e;
12
+ return r;
13
+ }, yr = function(r, e, i, n) {
14
+ if (F.prototype.copyWithin)
15
+ return F.prototype.copyWithin.call(r, e, i, n);
16
+ for ((i == null || i < 0) && (i = 0), (n == null || n > r.length) && (n = r.length); i < n; )
17
+ r[e++] = r[i++];
18
+ }, Ir = {
19
+ InvalidData: 0,
20
+ WindowSizeTooLarge: 1,
21
+ InvalidBlockType: 2,
22
+ FSEAccuracyTooHigh: 3,
23
+ DistanceTooFarBack: 4,
24
+ UnexpectedEOF: 5
25
+ }, pr = [
26
+ "invalid zstd data",
27
+ "window size too large (>2046MB)",
28
+ "invalid block type",
29
+ "FSE accuracy too high",
30
+ "match distance too far back",
31
+ "unexpected EOF"
32
+ ], z = function(r, e, i) {
33
+ var n = new Error(e || pr[r]);
34
+ if (n.code = r, Error.captureStackTrace && Error.captureStackTrace(n, z), !i)
35
+ throw n;
36
+ return n;
37
+ }, fr = function(r, e, i) {
38
+ for (var n = 0, a = 0; n < i; ++n)
39
+ a |= r[e++] << (n << 3);
40
+ return a;
41
+ }, Er = function(r, e) {
42
+ return (r[e] | r[e + 1] << 8 | r[e + 2] << 16 | r[e + 3] << 24) >>> 0;
43
+ }, or = function(r, e) {
44
+ var i = r[0] | r[1] << 8 | r[2] << 16;
45
+ if (i == 3126568 && r[3] == 253) {
46
+ var n = r[4], a = n >> 5 & 1, h = n >> 2 & 1, v = n & 3, l = n >> 6;
47
+ n & 8 && z(0);
48
+ var w = 6 - a, p = v == 3 ? 4 : v, S = fr(r, w, p);
49
+ w += p;
50
+ var g = l ? 1 << l : a, E = fr(r, w, g) + (l == 1 && 256), T = E;
51
+ if (!a) {
52
+ var I = 1 << 10 + (r[5] >> 3);
53
+ T = I + (I >> 3) * (r[5] & 7);
54
+ }
55
+ T > 2145386496 && z(1);
56
+ var o = new F((e == 1 ? E || T : e ? 0 : T) + 12);
57
+ return o[0] = 1, o[4] = 4, o[8] = 8, {
58
+ b: w + g,
59
+ y: 0,
60
+ l: 0,
61
+ d: S,
62
+ w: e && e != 1 ? e : o.subarray(12),
63
+ e: T,
64
+ o: new s(o.buffer, 0, 3),
65
+ u: E,
66
+ c: h,
67
+ m: Math.min(131072, T)
68
+ };
69
+ } else if ((i >> 4 | r[3] << 20) == 25481893)
70
+ return Er(r, 4) + 8;
71
+ z(0);
72
+ }, Z = function(r) {
73
+ for (var e = 0; 1 << e <= r; ++e)
74
+ ;
75
+ return e - 1;
76
+ }, Q = function(r, e, i) {
77
+ var n = (e << 3) + 4, a = (r[e] & 15) + 5;
78
+ a > i && z(3);
79
+ for (var h = 1 << a, v = h, l = -1, w = -1, p = -1, S = h, g = new gr(512 + (h << 2)), E = new zr(g, 0, 256), T = new _(g, 0, 256), I = new _(g, 512, h), o = 512 + (h << 1), A = new F(g, o, h), c = new F(g, o + h); l < 255 && v > 0; ) {
80
+ var m = Z(v + 1), B = n >> 3, H = (1 << m + 1) - 1, D = (r[B] | r[B + 1] << 8 | r[B + 2] << 16) >> (n & 7) & H, f = (1 << m) - 1, x = H - v - 1, W = D & f;
81
+ if (W < x ? (n += m, D = W) : (n += m + 1, D > f && (D -= x)), E[++l] = --D, D == -1 ? (v += D, A[--S] = l) : v -= D, !D)
82
+ do {
83
+ var j = n >> 3;
84
+ w = (r[j] | r[j + 1] << 8) >> (n & 7) & 3, n += 2, l += w;
85
+ } while (w == 3);
86
+ }
87
+ (l > 255 || v) && z(0);
88
+ for (var M = 0, q = (h >> 1) + (h >> 3) + 3, C = h - 1, O = 0; O <= l; ++O) {
89
+ var u = E[O];
90
+ if (u < 1) {
91
+ T[O] = -u;
92
+ continue;
93
+ }
94
+ for (p = 0; p < u; ++p) {
95
+ A[M] = O;
96
+ do
97
+ M = M + q & C;
98
+ while (M >= S);
99
+ }
100
+ }
101
+ for (M && z(0), p = 0; p < h; ++p) {
102
+ var y = T[A[p]]++, U = c[p] = a - Z(y);
103
+ I[p] = (y << U) - h;
104
+ }
105
+ return [n + 7 >> 3, {
106
+ b: a,
107
+ s: A,
108
+ n: c,
109
+ t: I
110
+ }];
111
+ }, Ar = function(r, e) {
112
+ var i = 0, n = -1, a = new F(292), h = r[e], v = a.subarray(0, 256), l = a.subarray(256, 268), w = new _(a.buffer, 268);
113
+ if (h < 128) {
114
+ var p = Q(r, e + 1, 6), S = p[0], g = p[1];
115
+ e += h;
116
+ var E = S << 3, T = r[e];
117
+ T || z(0);
118
+ for (var I = 0, o = 0, A = g.b, c = A, m = (++e << 3) - 8 + Z(T); m -= A, !(m < E); ) {
119
+ var B = m >> 3;
120
+ if (I += (r[B] | r[B + 1] << 8) >> (m & 7) & (1 << A) - 1, v[++n] = g.s[I], m -= c, m < E)
121
+ break;
122
+ B = m >> 3, o += (r[B] | r[B + 1] << 8) >> (m & 7) & (1 << c) - 1, v[++n] = g.s[o], A = g.n[I], I = g.t[I], c = g.n[o], o = g.t[o];
123
+ }
124
+ ++n > 255 && z(0);
125
+ } else {
126
+ for (n = h - 127; i < n; i += 2) {
127
+ var H = r[++e];
128
+ v[i] = H >> 4, v[i + 1] = H & 15;
129
+ }
130
+ ++e;
131
+ }
132
+ var D = 0;
133
+ for (i = 0; i < n; ++i) {
134
+ var f = v[i];
135
+ f > 11 && z(0), D += f && 1 << f - 1;
136
+ }
137
+ var x = Z(D) + 1, W = 1 << x, j = W - D;
138
+ for (j & j - 1 && z(0), v[n++] = Z(j) + 1, i = 0; i < n; ++i) {
139
+ var f = v[i];
140
+ ++l[v[i] = f && x + 1 - f];
141
+ }
142
+ var M = new F(W << 1), q = M.subarray(0, W), C = M.subarray(W);
143
+ for (w[x] = 0, i = x; i > 0; --i) {
144
+ var O = w[i];
145
+ P(C, i, O, w[i - 1] = O + l[i] * (1 << x - i));
146
+ }
147
+ for (w[0] != W && z(0), i = 0; i < n; ++i) {
148
+ var u = v[i];
149
+ if (u) {
150
+ var y = w[u];
151
+ P(q, i, y, w[u] = y + (1 << x - u));
152
+ }
153
+ }
154
+ return [e, {
155
+ n: C,
156
+ b: x,
157
+ s: q
158
+ }];
159
+ }, Fr = Q(/* @__PURE__ */ new F([
160
+ 81,
161
+ 16,
162
+ 99,
163
+ 140,
164
+ 49,
165
+ 198,
166
+ 24,
167
+ 99,
168
+ 12,
169
+ 33,
170
+ 196,
171
+ 24,
172
+ 99,
173
+ 102,
174
+ 102,
175
+ 134,
176
+ 70,
177
+ 146,
178
+ 4
179
+ ]), 0, 6)[1], Tr = Q(/* @__PURE__ */ new F([
180
+ 33,
181
+ 20,
182
+ 196,
183
+ 24,
184
+ 99,
185
+ 140,
186
+ 33,
187
+ 132,
188
+ 16,
189
+ 66,
190
+ 8,
191
+ 33,
192
+ 132,
193
+ 16,
194
+ 66,
195
+ 8,
196
+ 33,
197
+ 68,
198
+ 68,
199
+ 68,
200
+ 68,
201
+ 68,
202
+ 68,
203
+ 68,
204
+ 68,
205
+ 36,
206
+ 9
207
+ ]), 0, 6)[1], Br = Q(/* @__PURE__ */ new F([
208
+ 32,
209
+ 132,
210
+ 16,
211
+ 66,
212
+ 102,
213
+ 70,
214
+ 68,
215
+ 68,
216
+ 68,
217
+ 68,
218
+ 36,
219
+ 73,
220
+ 2
221
+ ]), 0, 5)[1], lr = function(r, e) {
222
+ for (var i = r.length, n = new s(i), a = 0; a < i; ++a)
223
+ n[a] = e, e += 1 << r[a];
224
+ return n;
225
+ }, d = /* @__PURE__ */ new F((/* @__PURE__ */ new s([
226
+ 0,
227
+ 0,
228
+ 0,
229
+ 0,
230
+ 16843009,
231
+ 50528770,
232
+ 134678020,
233
+ 202050057,
234
+ 269422093
235
+ ])).buffer, 0, 36), Dr = /* @__PURE__ */ lr(d, 0), rr = /* @__PURE__ */ new F((/* @__PURE__ */ new s([
236
+ 0,
237
+ 0,
238
+ 0,
239
+ 0,
240
+ 0,
241
+ 0,
242
+ 0,
243
+ 0,
244
+ 16843009,
245
+ 50528770,
246
+ 117769220,
247
+ 185207048,
248
+ 252579084,
249
+ 16
250
+ ])).buffer, 0, 53), Sr = /* @__PURE__ */ lr(rr, 3), N = function(r, e, i) {
251
+ var n = r.length, a = e.length, h = r[n - 1], v = (1 << i.b) - 1, l = -i.b;
252
+ h || z(0);
253
+ for (var w = 0, p = i.b, S = (n << 3) - 8 + Z(h) - p, g = -1; S > l && g < a; ) {
254
+ var E = S >> 3, T = (r[E] | r[E + 1] << 8 | r[E + 2] << 16) >> (S & 7);
255
+ w = (w << p | T) & v, e[++g] = i.s[w], S -= p = i.n[w];
256
+ }
257
+ (S != l || g + 1 != a) && z(0);
258
+ }, mr = function(r, e, i) {
259
+ var n = 6, a = e.length, h = a + 3 >> 2, v = h << 1, l = h + v;
260
+ N(r.subarray(n, n += r[0] | r[1] << 8), e.subarray(0, h), i), N(r.subarray(n, n += r[2] | r[3] << 8), e.subarray(h, v), i), N(r.subarray(n, n += r[4] | r[5] << 8), e.subarray(v, l), i), N(r.subarray(n), e.subarray(l), i);
261
+ }, wr = function(r, e, i) {
262
+ var n, a = e.b, h = r[a], v = h >> 1 & 3;
263
+ e.l = h & 1;
264
+ var l = h >> 3 | r[a + 1] << 5 | r[a + 2] << 13, w = (a += 3) + l;
265
+ if (v == 1)
266
+ return a >= r.length ? void 0 : (e.b = a + 1, i ? (P(i, r[a], e.y, e.y += l), i) : P(new F(l), r[a]));
267
+ if (!(w > r.length)) {
268
+ if (v == 0)
269
+ return e.b = w, i ? (i.set(r.subarray(a, w), e.y), e.y += l, i) : t(r, a, w);
270
+ if (v == 2) {
271
+ var p = r[a], S = p & 3, g = p >> 2 & 3, E = p >> 4, T = 0, I = 0;
272
+ S < 2 ? g & 1 ? E |= r[++a] << 4 | (g & 2 && r[++a] << 12) : E = p >> 3 : (I = g, g < 2 ? (E |= (r[++a] & 63) << 4, T = r[a] >> 6 | r[++a] << 2) : g == 2 ? (E |= r[++a] << 4 | (r[++a] & 3) << 12, T = r[a] >> 2 | r[++a] << 6) : (E |= r[++a] << 4 | (r[++a] & 63) << 12, T = r[a] >> 6 | r[++a] << 2 | r[++a] << 10)), ++a;
273
+ var o = i ? i.subarray(e.y, e.y + e.m) : new F(e.m), A = o.length - E;
274
+ if (S == 0)
275
+ o.set(r.subarray(a, a += E), A);
276
+ else if (S == 1)
277
+ P(o, r[a++], A);
278
+ else {
279
+ var c = e.h;
280
+ if (S == 2) {
281
+ var m = Ar(r, a);
282
+ T += a - (a = m[0]), e.h = c = m[1];
283
+ } else c || z(0);
284
+ (I ? mr : N)(r.subarray(a, a += T), o.subarray(A), c);
285
+ }
286
+ var B = r[a++];
287
+ if (B) {
288
+ B == 255 ? B = (r[a++] | r[a++] << 8) + 32512 : B > 127 && (B = B - 128 << 8 | r[a++]);
289
+ var H = r[a++];
290
+ H & 3 && z(0);
291
+ for (var D = [Tr, Br, Fr], f = 2; f > -1; --f) {
292
+ var x = H >> (f << 1) + 2 & 3;
293
+ if (x == 1) {
294
+ var W = new F([0, 0, r[a++]]);
295
+ D[f] = {
296
+ s: W.subarray(2, 3),
297
+ n: W.subarray(0, 1),
298
+ t: new _(W.buffer, 0, 1),
299
+ b: 0
300
+ };
301
+ } else x == 2 ? (n = Q(r, a, 9 - (f & 1)), a = n[0], D[f] = n[1]) : x == 3 && (e.t || z(0), D[f] = e.t[f]);
302
+ }
303
+ var j = e.t = D, M = j[0], q = j[1], C = j[2], O = r[w - 1];
304
+ O || z(0);
305
+ var u = (w << 3) - 8 + Z(O) - C.b, y = u >> 3, U = 0, R = (r[y] | r[y + 1] << 8) >> (u & 7) & (1 << C.b) - 1;
306
+ y = (u -= q.b) >> 3;
307
+ var V = (r[y] | r[y + 1] << 8) >> (u & 7) & (1 << q.b) - 1;
308
+ y = (u -= M.b) >> 3;
309
+ var X = (r[y] | r[y + 1] << 8) >> (u & 7) & (1 << M.b) - 1;
310
+ for (++B; --B; ) {
311
+ var k = C.s[R], ir = C.n[R], b = M.s[X], ar = M.n[X], nr = q.s[V], vr = q.n[V];
312
+ y = (u -= nr) >> 3;
313
+ var hr = 1 << nr, L = hr + ((r[y] | r[y + 1] << 8 | r[y + 2] << 16 | r[y + 3] << 24) >>> (u & 7) & hr - 1);
314
+ y = (u -= rr[b]) >> 3;
315
+ var G = Sr[b] + ((r[y] | r[y + 1] << 8 | r[y + 2] << 16) >> (u & 7) & (1 << rr[b]) - 1);
316
+ y = (u -= d[k]) >> 3;
317
+ var Y = Dr[k] + ((r[y] | r[y + 1] << 8 | r[y + 2] << 16) >> (u & 7) & (1 << d[k]) - 1);
318
+ if (y = (u -= ir) >> 3, R = C.t[R] + ((r[y] | r[y + 1] << 8) >> (u & 7) & (1 << ir) - 1), y = (u -= ar) >> 3, X = M.t[X] + ((r[y] | r[y + 1] << 8) >> (u & 7) & (1 << ar) - 1), y = (u -= vr) >> 3, V = q.t[V] + ((r[y] | r[y + 1] << 8) >> (u & 7) & (1 << vr) - 1), L > 3)
319
+ e.o[2] = e.o[1], e.o[1] = e.o[0], e.o[0] = L -= 3;
320
+ else {
321
+ var $ = L - (Y != 0);
322
+ $ ? (L = $ == 3 ? e.o[0] - 1 : e.o[$], $ > 1 && (e.o[2] = e.o[1]), e.o[1] = e.o[0], e.o[0] = L) : L = e.o[0];
323
+ }
324
+ for (var f = 0; f < Y; ++f)
325
+ o[U + f] = o[A + f];
326
+ U += Y, A += Y;
327
+ var J = U - L;
328
+ if (J < 0) {
329
+ var K = -J, ur = e.e + J;
330
+ K > G && (K = G);
331
+ for (var f = 0; f < K; ++f)
332
+ o[U + f] = e.w[ur + f];
333
+ U += K, G -= K, J = 0;
334
+ }
335
+ for (var f = 0; f < G; ++f)
336
+ o[U + f] = o[J + f];
337
+ U += G;
338
+ }
339
+ if (U != A)
340
+ for (; A < o.length; )
341
+ o[U++] = o[A++];
342
+ else
343
+ U = o.length;
344
+ i ? e.y += U : o = t(o, 0, U);
345
+ } else if (i) {
346
+ if (e.y += E, A)
347
+ for (var f = 0; f < E; ++f)
348
+ o[f] = o[A + f];
349
+ } else A && (o = t(o, A));
350
+ return e.b = w, o;
351
+ }
352
+ z(2);
353
+ }
354
+ }, er = function(r, e) {
355
+ if (r.length == 1)
356
+ return r[0];
357
+ for (var i = new F(e), n = 0, a = 0; n < r.length; ++n) {
358
+ var h = r[n];
359
+ i.set(h, a), a += h.length;
360
+ }
361
+ return i;
362
+ };
363
+ function xr(r, e) {
364
+ for (var i = [], n = +!e, a = 0, h = 0; r.length; ) {
365
+ var v = or(r, n || e);
366
+ if (typeof v == "object") {
367
+ for (n ? (e = null, v.w.length == v.u && (i.push(e = v.w), h += v.u)) : (i.push(e), v.e = 0); !v.l; ) {
368
+ var l = wr(r, v, e);
369
+ l || z(5), e ? v.e = v.y : (i.push(l), h += l.length, yr(v.w, 0, l.length), v.w.set(l, v.w.length - l.length));
370
+ }
371
+ a = v.b + v.c * 4;
372
+ } else
373
+ a = v;
374
+ r = r.subarray(a);
375
+ }
376
+ return er(i, h);
377
+ }
378
+ var Mr = /* @__PURE__ */ (function() {
379
+ function r(e) {
380
+ this.ondata = e, this.c = [], this.l = 0, this.z = 0;
381
+ }
382
+ return r.prototype.push = function(e, i) {
383
+ if (typeof this.s == "number") {
384
+ var n = Math.min(e.length, this.s);
385
+ e = e.subarray(n), this.s -= n;
386
+ }
387
+ var a = e.length, h = a + this.l;
388
+ if (!this.s) {
389
+ if (i) {
390
+ if (!h) {
391
+ this.ondata(new F(0), !0);
392
+ return;
393
+ }
394
+ h < 5 && z(5);
395
+ } else if (h < 18) {
396
+ this.c.push(e), this.l = h;
397
+ return;
398
+ }
399
+ if (this.l && (this.c.push(e), e = er(this.c, h), this.c = [], this.l = 0), typeof (this.s = or(e)) == "number")
400
+ return this.push(e, i);
401
+ }
402
+ if (typeof this.s != "number") {
403
+ if (h < (this.z || 3)) {
404
+ i && z(5), this.c.push(e), this.l = h;
405
+ return;
406
+ }
407
+ if (this.l && (this.c.push(e), e = er(this.c, h), this.c = [], this.l = 0), !this.z && h < (this.z = e[this.s.b] & 2 ? 4 : 3 + (e[this.s.b] >> 3 | e[this.s.b + 1] << 5 | e[this.s.b + 2] << 13))) {
408
+ i && z(5), this.c.push(e), this.l = h;
409
+ return;
410
+ } else
411
+ this.z = 0;
412
+ for (; ; ) {
413
+ var v = wr(e, this.s);
414
+ if (v)
415
+ this.ondata(v, !1), yr(this.s.w, 0, v.length), this.s.w.set(v, this.s.w.length - v.length);
416
+ else {
417
+ i && z(5);
418
+ var l = e.subarray(this.s.b);
419
+ this.s.b = 0, this.c.push(l), this.l += l.length;
420
+ return;
421
+ }
422
+ if (this.s.l) {
423
+ var w = e.subarray(this.s.b);
424
+ this.s = this.s.c * 4, this.push(w, i);
425
+ return;
426
+ }
427
+ }
428
+ } else i && z(5);
429
+ }, r;
430
+ })();
431
+ export {
432
+ Mr as Decompress,
433
+ Ir as ZstdErrorCode,
434
+ xr as decompress
435
+ };