@johnoscott/isometric-engine 0.0.0-stage → 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.
- package/EDITOR-GUIDE.md +355 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +269 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +39 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +443 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1403 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +149 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +511 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +147 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +477 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1227 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +39 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +153 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +178 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +307 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +49 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// The timeline's search language (docs/timeline/README.md §5): free text, "quoted phrases", field:value and -negation.
|
|
2
|
+
// Pure: parseSearch reads a query, matcher() turns it into a test of one event, rangeOf() into the range it narrows to,
|
|
3
|
+
// and highlights() finds the free text's hits in a line. The component parses; a query carries the parse (toAst, a
|
|
4
|
+
// SearchAst, times already resolved), so a host never needs a parser: matchAst() is the reference for applying it.
|
|
5
|
+
// The language's link fields, and how a link matches, are the domain's (searchFor(cat)).
|
|
6
|
+
|
|
7
|
+
import { SEVERITIES, type Severity, type TimelineEvent, type SearchAst, type AstTerm, type Match, type TimelineCatalog } from './timeline-contract.ts';
|
|
8
|
+
import { within } from './timeline-scope.ts';
|
|
9
|
+
|
|
10
|
+
/** the fields every domain's search has; its link fields follow */
|
|
11
|
+
export const BASE_FIELDS = ['kind', 'source', 'severity', 'scope', 'since', 'before'] as const;
|
|
12
|
+
export type Field = string;
|
|
13
|
+
export type SearchDialect = Pick<TimelineCatalog, 'links' | 'linkMatch' | 'topKinds'>;
|
|
14
|
+
|
|
15
|
+
export interface Term {
|
|
16
|
+
neg: boolean;
|
|
17
|
+
/** absent: free text */
|
|
18
|
+
field?: Field;
|
|
19
|
+
/** severity only */
|
|
20
|
+
op?: '=' | '>=' | '>' | '<=' | '<';
|
|
21
|
+
value: string;
|
|
22
|
+
/** since and before: the time read (ms) */
|
|
23
|
+
time?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ParsedSearch { terms: Term[]; warnings: string[] }
|
|
26
|
+
|
|
27
|
+
/** split into tokens: -, field:, "quoted" values and phrases kept whole */
|
|
28
|
+
function tokens(q: string): { neg: boolean; raw: string; quoted: boolean; field?: string }[] {
|
|
29
|
+
const out: { neg: boolean; raw: string; quoted: boolean; field?: string }[] = [];
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (i < q.length) {
|
|
32
|
+
while (i < q.length && /\s/.test(q[i])) i++;
|
|
33
|
+
if (i >= q.length) break;
|
|
34
|
+
let neg = false;
|
|
35
|
+
if (q[i] === '-' && i + 1 < q.length && !/\s/.test(q[i + 1])) { neg = true; i++; }
|
|
36
|
+
// field: a known name (or attr.KEY) then ":"
|
|
37
|
+
const m = /^(attr\.[a-z][a-z0-9_]*|[a-z]+):/.exec(q.slice(i));
|
|
38
|
+
let field: string | undefined;
|
|
39
|
+
if (m) { field = m[1]; i += m[0].length; }
|
|
40
|
+
let raw = '', quoted = false;
|
|
41
|
+
if (q[i] === '"') {
|
|
42
|
+
const j = q.indexOf('"', i + 1);
|
|
43
|
+
raw = q.slice(i + 1, j < 0 ? q.length : j); quoted = true;
|
|
44
|
+
i = j < 0 ? q.length : j + 1;
|
|
45
|
+
} else { const s = i; while (i < q.length && !/\s/.test(q[i])) i++; raw = q.slice(s, i); }
|
|
46
|
+
out.push({ neg, raw, quoted, field });
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const REL = /^(\d+)(s|m|h|d|w)$/;
|
|
52
|
+
const UNIT: Record<string, number> = { s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000, w: 7 * 86_400_000 };
|
|
53
|
+
/** a time: 15m, 2h, 3d, 1w back from now; or a date or date-time, local unless it has a zone */
|
|
54
|
+
export function readTime(v: string, now: number): number | undefined {
|
|
55
|
+
const r = REL.exec(v);
|
|
56
|
+
if (r) return now - Number(r[1]) * UNIT[r[2]];
|
|
57
|
+
const d = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(v);
|
|
58
|
+
if (!d) return undefined;
|
|
59
|
+
const [, y, mo, da, hh = '0', mi = '0', ss = '0', ms = '0', zone] = d;
|
|
60
|
+
if (zone) { const t = Date.parse(v.replace(' ', 'T')); return Number.isNaN(t) ? undefined : t; }
|
|
61
|
+
const t = new Date(+y, +mo - 1, +da, +hh, +mi, +ss, +ms.padEnd(3, '0')).getTime();
|
|
62
|
+
return Number.isNaN(t) ? undefined : t;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseWith(fields: readonly string[], q: string, now = Date.now()): ParsedSearch {
|
|
66
|
+
const terms: Term[] = [], warnings: string[] = [];
|
|
67
|
+
for (const t of tokens(q ?? '')) {
|
|
68
|
+
const asText = (why?: string) => {
|
|
69
|
+
const value = t.field ? `${t.field}:${t.raw}` : t.raw;
|
|
70
|
+
if (why) warnings.push(`${JSON.stringify(value)}: ${why}; searched as text`);
|
|
71
|
+
if (value) terms.push({ neg: t.neg, value });
|
|
72
|
+
};
|
|
73
|
+
if (!t.field) { asText(); continue; }
|
|
74
|
+
const known = fields.includes(t.field) || t.field.startsWith('attr.');
|
|
75
|
+
if (!known) { asText(`no field ${t.field}`); continue; }
|
|
76
|
+
if (!t.raw) { asText(`${t.field}: needs a value`); continue; }
|
|
77
|
+
const field = t.field as Field;
|
|
78
|
+
if (field === 'severity') {
|
|
79
|
+
const m = /^(>=|<=|>|<|=)?(.*)$/.exec(t.raw)!;
|
|
80
|
+
if (!(SEVERITIES as readonly string[]).includes(m[2])) { asText(`no severity ${m[2]} (${SEVERITIES.join(', ')})`); continue; }
|
|
81
|
+
terms.push({ neg: t.neg, field, op: (m[1] as Term['op']) ?? '=', value: m[2] });
|
|
82
|
+
} else if (field === 'since' || field === 'before') {
|
|
83
|
+
const time = readTime(t.raw, now);
|
|
84
|
+
if (time === undefined) { asText(`can't read the time ${t.raw} (15m, 2h, 3d, 1w, or a date like 2026-11-20 or 2026-11-20T09:30)`); continue; }
|
|
85
|
+
if (t.neg) { asText(`-${field} isn't allowed (use ${field === 'since' ? 'before' : 'since'})`); continue; }
|
|
86
|
+
terms.push({ neg: false, field, value: t.raw, time });
|
|
87
|
+
} else terms.push({ neg: t.neg, field, value: t.raw });
|
|
88
|
+
}
|
|
89
|
+
return { terms, warnings };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const sevRank = (s: string) => (SEVERITIES as readonly string[]).indexOf(s);
|
|
93
|
+
const OPS = { '=': 'eq', '>=': 'ge', '>': 'gt', '<=': 'le', '<': 'lt' } as const;
|
|
94
|
+
|
|
95
|
+
/** one term as a match (since and before have none: they narrow the range) */
|
|
96
|
+
function matchOf(t: Term, d: SearchDialect): Match | undefined {
|
|
97
|
+
switch (t.field) {
|
|
98
|
+
case undefined: return { field: 'text', value: t.value };
|
|
99
|
+
case 'kind': case 'source': return t.value.endsWith('*') ? { field: t.field, value: t.value.slice(0, -1), prefix: true } : { field: t.field, value: t.value };
|
|
100
|
+
case 'severity': return { field: 'severity', op: OPS[t.op ?? '='], value: t.value as Severity };
|
|
101
|
+
case 'scope': return { field: 'scope', value: t.value, from: d.topKinds.some(k => t.value.startsWith(`${k}:`)) ? 'top' : 'segments' };
|
|
102
|
+
case 'since': case 'before': return undefined;
|
|
103
|
+
default:
|
|
104
|
+
if (d.links.includes(t.field)) return { field: 'link', link: t.field, value: t.value };
|
|
105
|
+
return { field: 'attr', key: t.field.slice(5), value: t.value };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The parse as the query carries it: the same field twice (positive) is one term of either; free text, severity and
|
|
110
|
+
* each negation are terms of their own. */
|
|
111
|
+
function toAstWith(d: SearchDialect, p: ParsedSearch): SearchAst {
|
|
112
|
+
const all: AstTerm[] = [], groups = new Map<string, AstTerm>();
|
|
113
|
+
for (const t of p.terms) {
|
|
114
|
+
const m = matchOf(t, d);
|
|
115
|
+
if (!m) continue;
|
|
116
|
+
if (t.neg) { all.push({ not: true, any: [m] }); continue; }
|
|
117
|
+
if (m.field === 'text' || m.field === 'severity') { all.push({ any: [m] }); continue; }
|
|
118
|
+
const key = m.field === 'link' ? `link.${m.link}` : m.field === 'attr' ? `attr.${m.key}` : m.field;
|
|
119
|
+
const g = groups.get(key);
|
|
120
|
+
if (g) g.any.push(m); else { const n = { any: [m] }; groups.set(key, n); all.push(n); }
|
|
121
|
+
}
|
|
122
|
+
return { all };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** one match against one event */
|
|
126
|
+
function test1(d: SearchDialect, m: Match, e: TimelineEvent, sensitive: Set<string>): boolean {
|
|
127
|
+
switch (m.field) {
|
|
128
|
+
case 'text': {
|
|
129
|
+
const v = m.value.toLowerCase();
|
|
130
|
+
if (e.summary.toLowerCase().includes(v) || e.kind.toLowerCase().includes(v) || e.source.toLowerCase().includes(v) || e.scope.toLowerCase().includes(v)) return true;
|
|
131
|
+
for (const [k, a] of Object.entries(e.attrs)) if (typeof a === 'string' && !sensitive.has(`${e.source}.${k}`) && a.toLowerCase().includes(v)) return true;
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
case 'kind': case 'source': { const v = e[m.field]; return m.prefix ? v.startsWith(m.value) : v === m.value; }
|
|
135
|
+
case 'severity': {
|
|
136
|
+
const a = sevRank(e.severity), b = sevRank(m.value);
|
|
137
|
+
return m.op === 'ge' ? a >= b : m.op === 'gt' ? a > b : m.op === 'le' ? a <= b : m.op === 'lt' ? a < b : a === b;
|
|
138
|
+
}
|
|
139
|
+
case 'scope': return m.from === 'top' ? within(e.scope, m.value) : `/${e.scope}/`.includes(`/${m.value}/`);
|
|
140
|
+
case 'link': {
|
|
141
|
+
const own = d.linkMatch?.(String(m.link), m.value, e);
|
|
142
|
+
return own ?? (e.links as Record<string, unknown>)[m.link as string] === m.value;
|
|
143
|
+
}
|
|
144
|
+
case 'attr': { const a = e.attrs[m.key]; return a !== undefined && a !== null && String(a).toLowerCase() === m.value.toLowerCase(); }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The search language of one domain: its fields (the base ones, then its links), and
|
|
149
|
+
* - parseSearch: the query, read;
|
|
150
|
+
* - toAst: the parse, as a query carries it;
|
|
151
|
+
* - compileSearch: what the component sends: the parse, the range narrowed by since: and before:, and what couldn't
|
|
152
|
+
* be read;
|
|
153
|
+
* - matchAst: the parsed search (as a query carries it) as a test of one event (sensitive: "source.attr" names free
|
|
154
|
+
* text never looks in);
|
|
155
|
+
* - matcher: the search as typed, as a test of one event. */
|
|
156
|
+
export function searchFor(d: SearchDialect) {
|
|
157
|
+
const FIELDS = [...BASE_FIELDS, ...d.links];
|
|
158
|
+
const parseSearch = (q: string, now = Date.now()): ParsedSearch => parseWith(FIELDS, q, now);
|
|
159
|
+
const toAst = (p: ParsedSearch): SearchAst => toAstWith(d, p);
|
|
160
|
+
function compileSearch(q: string, now: number, from: number, to: number): { where: SearchAst; from: number; to: number; warnings: string[] } {
|
|
161
|
+
const p = parseSearch(q, now);
|
|
162
|
+
return { where: toAst(p), ...rangeOf(p, from, to), warnings: p.warnings };
|
|
163
|
+
}
|
|
164
|
+
function matchAst(ast: SearchAst | undefined, sensitive: Iterable<string> = []): (e: TimelineEvent) => boolean {
|
|
165
|
+
const sens = new Set(sensitive), all = ast?.all ?? [];
|
|
166
|
+
if (!all.length) return () => true;
|
|
167
|
+
return e => all.every(t => t.any.some(m => test1(d, m, e, sens)) !== !!t.not);
|
|
168
|
+
}
|
|
169
|
+
const matcher = (p: ParsedSearch, sensitive: Iterable<string> = []) => matchAst(toAst(p), sensitive);
|
|
170
|
+
return { FIELDS, parseSearch, toAst, compileSearch, matchAst, matcher };
|
|
171
|
+
}
|
|
172
|
+
export type Search = ReturnType<typeof searchFor>;
|
|
173
|
+
|
|
174
|
+
/** the range since: and before: narrow [from, to) to (never wider) */
|
|
175
|
+
export function rangeOf(p: ParsedSearch, from: number, to: number): { from: number; to: number } {
|
|
176
|
+
for (const t of p.terms) {
|
|
177
|
+
if (t.field === 'since') from = Math.max(from, t.time!);
|
|
178
|
+
if (t.field === 'before') to = Math.min(to, t.time!);
|
|
179
|
+
}
|
|
180
|
+
return { from, to: Math.max(from, to) };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** where the free text (positive terms) hits a line: [start, end) ranges, merged, in order */
|
|
184
|
+
export function highlights(p: ParsedSearch, line: string): [number, number][] {
|
|
185
|
+
const low = line.toLowerCase(), out: [number, number][] = [];
|
|
186
|
+
for (const t of p.terms) {
|
|
187
|
+
if (t.neg || t.field || !t.value) continue;
|
|
188
|
+
const v = t.value.toLowerCase();
|
|
189
|
+
for (let i = low.indexOf(v); i >= 0; i = low.indexOf(v, i + v.length)) out.push([i, i + v.length]);
|
|
190
|
+
}
|
|
191
|
+
out.sort((a, b) => a[0] - b[0]);
|
|
192
|
+
const merged: [number, number][] = [];
|
|
193
|
+
for (const r of out) { const l = merged[merged.length - 1]; if (l && r[0] <= l[1]) l[1] = Math.max(l[1], r[1]); else merged.push([...r]); }
|
|
194
|
+
return merged;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** a severity filter as a set (for facets) */
|
|
198
|
+
export const severities = (min: Severity) => SEVERITIES.filter(s => sevRank(s) >= sevRank(min));
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Bins in the owner's time zone (docs/timeline/README.md §3): a 1d bin starts at local midnight (so a day isn't split
|
|
2
|
+
// in UTC, and run ids' local days line up); a 1h bin starts on the local hour, which is the UTC hour unless the offset
|
|
3
|
+
// isn't whole hours (+05:30, +05:45); a 1m bin is the UTC minute (every offset is whole minutes). A local day may be 23
|
|
4
|
+
// or 25 hours. Pure (Intl only).
|
|
5
|
+
|
|
6
|
+
import type { Bin } from './timeline-contract.ts';
|
|
7
|
+
|
|
8
|
+
const MIN = 60_000, HOUR = 3_600_000, DAY = 86_400_000;
|
|
9
|
+
const formats = new Map<string, Intl.DateTimeFormat>();
|
|
10
|
+
const offsets = new Map<string, number>();
|
|
11
|
+
|
|
12
|
+
/** the zone's offset from UTC at t, in ms (UTC, or an unknown zone: 0) */
|
|
13
|
+
export function offsetAt(tz: string | undefined, t: number): number {
|
|
14
|
+
if (!tz || tz === 'UTC') return 0;
|
|
15
|
+
const key = `${tz}|${Math.floor(t / (15 * MIN))}`;
|
|
16
|
+
const hit = offsets.get(key);
|
|
17
|
+
if (hit !== undefined) return hit;
|
|
18
|
+
let f = formats.get(tz);
|
|
19
|
+
if (!f) {
|
|
20
|
+
try { f = new Intl.DateTimeFormat('en-US', { timeZone: tz, hourCycle: 'h23', year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric' }); }
|
|
21
|
+
catch { return 0; }
|
|
22
|
+
formats.set(tz, f);
|
|
23
|
+
}
|
|
24
|
+
const p: Record<string, number> = {};
|
|
25
|
+
for (const x of f.formatToParts(new Date(t))) if (x.type !== 'literal') p[x.type] = Number(x.value);
|
|
26
|
+
const local = Date.UTC(p.year, p.month - 1, p.day, p.hour % 24, p.minute, p.second);
|
|
27
|
+
const off = Math.round((local - Math.floor(t / 1000) * 1000) / MIN) * MIN;
|
|
28
|
+
if (offsets.size > 50_000) offsets.clear();
|
|
29
|
+
offsets.set(key, off);
|
|
30
|
+
return off;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const isZone = (tz: string) => { try { new Intl.DateTimeFormat('en-US', { timeZone: tz }); return true; } catch { return false; } };
|
|
34
|
+
|
|
35
|
+
/** the start of the bin t falls in */
|
|
36
|
+
export function binStart(t: number, bin: Bin, tz?: string): number {
|
|
37
|
+
if (bin === '1m') return Math.floor(t / MIN) * MIN;
|
|
38
|
+
const off = offsetAt(tz, t);
|
|
39
|
+
if (bin === '1h') return off % HOUR === 0 ? Math.floor(t / HOUR) * HOUR : Math.floor((t + off) / HOUR) * HOUR - off;
|
|
40
|
+
// local midnight: the local day's start, at the offset in force then
|
|
41
|
+
const day = Math.floor((t + off) / DAY) * DAY;
|
|
42
|
+
let s = day - offsetAt(tz, day - off);
|
|
43
|
+
if (s > t) s = day - DAY - offsetAt(tz, day - DAY - off);
|
|
44
|
+
else if (binNext(s, tz) <= t) s = binNext(s, tz);
|
|
45
|
+
return s;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** the start of the next bin after a bin starting at s */
|
|
49
|
+
export function binNext(s: number, tz?: string, bin: Bin = '1d'): number {
|
|
50
|
+
if (bin === '1m') return s + MIN;
|
|
51
|
+
if (bin === '1h') return s + HOUR;
|
|
52
|
+
const off = offsetAt(tz, s), day = Math.floor((s + off) / DAY) * DAY + DAY;
|
|
53
|
+
return day - offsetAt(tz, day - off);
|
|
54
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// A drawing's stylesheet, scoped so it can live in a host's page beside the host's own (no frame): every rule under one
|
|
2
|
+
// root class (nothing styles html, body, * or a bare element), keyframes renamed iso-*, and the drawing's custom
|
|
3
|
+
// properties renamed --iso-* so they never meet the page's. Pure: used at build time and by a still render.
|
|
4
|
+
|
|
5
|
+
/** --name → --iso-name, in declarations and in var() alike */
|
|
6
|
+
export const isoVars = (css: string) => css.replace(/--([a-zA-Z][\w-]*)/g, '--iso-$1');
|
|
7
|
+
|
|
8
|
+
/** Split CSS into its top-level blocks: [prelude, body] (a rule's selectors, or an at-rule and what it holds). */
|
|
9
|
+
function blocks(css: string): [string, string][] {
|
|
10
|
+
const out: [string, string][] = [];
|
|
11
|
+
let i = 0;
|
|
12
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
13
|
+
while (i < text.length) {
|
|
14
|
+
const open = text.indexOf('{', i);
|
|
15
|
+
if (open < 0) break;
|
|
16
|
+
let depth = 1, j = open + 1;
|
|
17
|
+
while (j < text.length && depth) { if (text[j] === '{') depth++; else if (text[j] === '}') depth--; j++; }
|
|
18
|
+
out.push([text.slice(i, open).trim(), text.slice(open + 1, j - 1)]);
|
|
19
|
+
i = j;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** a selector list split at its top-level commas */
|
|
25
|
+
function selectors(list: string): string[] {
|
|
26
|
+
const out: string[] = [];
|
|
27
|
+
let depth = 0, cut = 0;
|
|
28
|
+
for (let i = 0; i < list.length; i++) {
|
|
29
|
+
const c = list[i];
|
|
30
|
+
if (c === '(' || c === '[') depth++;
|
|
31
|
+
else if (c === ')' || c === ']') depth--;
|
|
32
|
+
else if (c === ',' && !depth) { out.push(list.slice(cut, i).trim()); cut = i + 1; }
|
|
33
|
+
}
|
|
34
|
+
out.push(list.slice(cut).trim());
|
|
35
|
+
return out.filter(Boolean);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One selector under the root class. :root (the theme's tokens) becomes the root class itself; any state it names
|
|
39
|
+
* (data-theme: light or dark) is stateRoot's (the element the theme is set on), not the page's. */
|
|
40
|
+
export function scopeSelector(sel: string, root: string, stateRoot: string): string {
|
|
41
|
+
const m = /^:root((?:\[[^\]]*\]|:not\([^)]*\))*)(.*)$/.exec(sel);
|
|
42
|
+
// the state root as a class name, given with its dot (as root is) or without (0.7.1: both read the same)
|
|
43
|
+
const st = stateRoot.replace(/^\./, '');
|
|
44
|
+
if (m) { const state = m[1], rest = m[2].trim(); return `${state ? `.${st}${state} ` : ''}${root}${rest ? ' ' + rest : ''}`; }
|
|
45
|
+
if (/^(html|body|\*)\b/.test(sel) || /^[a-z]+$/.test(sel) && !/^(svg|g|text|path|polygon|rect|circle|line)$/.test(sel)) throw new Error(`the canvas's CSS can't style the page: "${sel}"`);
|
|
46
|
+
return `${root} ${sel}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Scope a stylesheet: every rule under the root class; keyframes renamed iso-*; at-rules kept with their rules scoped. */
|
|
50
|
+
export function scope(css: string, root: string, stateRoot: string): string {
|
|
51
|
+
let out = '';
|
|
52
|
+
for (const [pre, body] of blocks(css)) {
|
|
53
|
+
if (pre.startsWith('@keyframes')) { out += `@keyframes iso-${pre.slice('@keyframes'.length).trim()}{${body}}\n`; continue; }
|
|
54
|
+
if (pre.startsWith('@media') || pre.startsWith('@supports')) { out += `${pre}{${scope(body, root, stateRoot)}}\n`; continue; }
|
|
55
|
+
if (pre.startsWith('@')) throw new Error(`the canvas's CSS has an at-rule it can't scope: ${pre}`);
|
|
56
|
+
out += `${selectors(pre).map(x => scopeSelector(x, root, stateRoot)).join(',')}{${body.replace(/\banimation:\s*([a-z][\w-]*)/g, 'animation:iso-$1')}}\n`;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// The view of a drawn scene (docs/editor/LAYERS.md §2): pan and zoom (10%–800%), fit, the page ↔ drawing coordinates,
|
|
2
|
+
// and v0.4.2's rule: the view is fitted until the person moves it (a zoom, a pan, 100%, a reveal); after that it is
|
|
3
|
+
// theirs. Fit fits again and gives it back. Changes the view makes itself go through quietly(). A resize keeps a moved
|
|
4
|
+
// view's zoom and re-centres it; a fitted view is fitted again. The overlay's marks keep their size on screen, so a
|
|
5
|
+
// new zoom (past 2%) asks for them to be drawn again (onRezoom), and a fit with marks showing repeats until it holds.
|
|
6
|
+
// Moved here from the editor canvas (R1 S4); the canvas owns the drawing, the overlay and the pointer.
|
|
7
|
+
|
|
8
|
+
export type View = { x: number; y: number; w: number; h: number };
|
|
9
|
+
export const MIN_ZOOM = 0.1, MAX_ZOOM = 8;
|
|
10
|
+
|
|
11
|
+
export interface ViewportOpts {
|
|
12
|
+
/** the drawing on the stage (its viewBox is the view), if any */
|
|
13
|
+
svg(): SVGSVGElement | undefined;
|
|
14
|
+
/** after each change of the view, at its zoom (pixels per unit): the host's zoom readout */
|
|
15
|
+
onApply(k: number): void;
|
|
16
|
+
/** the marks drawn at another zoom: draw them again */
|
|
17
|
+
onRezoom(): void;
|
|
18
|
+
/** what a fit frames (the drawing's own things, the overlay's shown marks), if not the whole scene */
|
|
19
|
+
itemsBox(): View | undefined;
|
|
20
|
+
/** the overlay has marks that keep their size on screen (a fit repeats while they are showing) */
|
|
21
|
+
marksShowing(): boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function viewport(host: HTMLElement, o: ViewportOpts) {
|
|
25
|
+
let view: View | undefined, full: View | undefined;
|
|
26
|
+
let moved = false, quiet = 0, keptK = 0;
|
|
27
|
+
let paintedK = 0, rezoom = 0, resizeFrame = 0, disposed = false;
|
|
28
|
+
|
|
29
|
+
const size = () => { const r = host.getBoundingClientRect(); return { w: Math.max(1, r.width), h: Math.max(1, r.height) }; };
|
|
30
|
+
/** pixels per SVG unit (the scale preserveAspectRatio meet gives) */
|
|
31
|
+
const scale = (v = view!) => { const s = size(); return Math.min(s.w / v.w, s.h / v.h); };
|
|
32
|
+
const quietly = (f: () => void) => { quiet++; try { f(); } finally { quiet--; } };
|
|
33
|
+
function applyView() {
|
|
34
|
+
const svg = o.svg();
|
|
35
|
+
if (!svg || !view) return;
|
|
36
|
+
if (!quiet) moved = true;
|
|
37
|
+
// keep the view's aspect the host's, so the readout's zoom is exact
|
|
38
|
+
const s = size(), k = scale();
|
|
39
|
+
const vw = s.w / k, vh = s.h / k;
|
|
40
|
+
view = { x: view.x + (view.w - vw) / 2, y: view.y + (view.h - vh) / 2, w: vw, h: vh };
|
|
41
|
+
svg.setAttribute('viewBox', `${view.x.toFixed(2)} ${view.y.toFixed(2)} ${view.w.toFixed(2)} ${view.h.toFixed(2)}`);
|
|
42
|
+
keptK = k;
|
|
43
|
+
o.onApply(k);
|
|
44
|
+
// the overlay's marks keep their size on screen: drawn again once the zoom has settled at a new scale
|
|
45
|
+
if (paintedK && Math.abs(k / paintedK - 1) > 0.02) { cancelAnimationFrame(rezoom); rezoom = requestAnimationFrame(() => { rezoom = 0; o.onRezoom(); }); }
|
|
46
|
+
}
|
|
47
|
+
/** client (page) point → SVG point */
|
|
48
|
+
const toSvg = (cx: number, cy: number) => {
|
|
49
|
+
const r = host.getBoundingClientRect(), k = scale();
|
|
50
|
+
return { x: view!.x + (cx - r.left) / k, y: view!.y + (cy - r.top) / k };
|
|
51
|
+
};
|
|
52
|
+
function zoomAt(f: number, cx?: number, cy?: number) {
|
|
53
|
+
if (!view) return;
|
|
54
|
+
const k = scale(), nk = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, k * f));
|
|
55
|
+
const r = host.getBoundingClientRect();
|
|
56
|
+
const px = cx ?? r.left + r.width / 2, py = cy ?? r.top + r.height / 2;
|
|
57
|
+
const p = toSvg(px, py);
|
|
58
|
+
const s = size();
|
|
59
|
+
view = { x: p.x - (px - r.left) / nk, y: p.y - (py - r.top) / nk, w: s.w / nk, h: s.h / nk };
|
|
60
|
+
applyView();
|
|
61
|
+
}
|
|
62
|
+
function fit(box = full) {
|
|
63
|
+
if (!box) return;
|
|
64
|
+
const s = size(), pad = 24;
|
|
65
|
+
const k = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, Math.min((s.w - pad * 2) / box.w, (s.h - pad * 2) / box.h)));
|
|
66
|
+
const cx = box.x + box.w / 2, cy = box.y + box.h / 2;
|
|
67
|
+
const next = { x: cx - s.w / k / 2, y: cy - s.h / k / 2, w: s.w / k, h: s.h / k };
|
|
68
|
+
// v0.4.2: a fit that lands where the view already is (a refit after a resize that changed nothing it fits) leaves
|
|
69
|
+
// it alone: no new zoom by a rounding error, so nothing on the overlay is redrawn
|
|
70
|
+
if (view && Math.abs(next.w / view.w - 1) < 1e-3 && Math.abs(next.h / view.h - 1) < 1e-3 && Math.abs(next.x - view.x) < next.w * 1e-3 && Math.abs(next.y - view.y) < next.h * 1e-3) { applyView(); return; }
|
|
71
|
+
view = next;
|
|
72
|
+
applyView();
|
|
73
|
+
}
|
|
74
|
+
/** Fit the drawing's things with a margin. */
|
|
75
|
+
function fitItems() {
|
|
76
|
+
// the overlay's marks keep their size on screen, so in the drawing's units they grow as the view zooms out: fit,
|
|
77
|
+
// draw the marks at the new zoom, and fit again until the box holds still (a few rounds at most)
|
|
78
|
+
for (let round = 0, last = ''; round < 4; round++) {
|
|
79
|
+
const b = o.itemsBox() ?? full;
|
|
80
|
+
if (!b) return;
|
|
81
|
+
const key = [b.x, b.y, b.w, b.h].map(n => Math.round(n)).join();
|
|
82
|
+
if (key === last) break;
|
|
83
|
+
last = key;
|
|
84
|
+
const m = Math.max(24, Math.min(b.w, b.h) * 0.06);
|
|
85
|
+
quietly(() => fit({ x: b.x - m, y: b.y - m, w: b.w + m * 2, h: b.h + m * 2 }));
|
|
86
|
+
// the marks are redrawn for a new zoom only past the same 2% the zoom itself uses (applyView's rezoom)
|
|
87
|
+
if (!o.marksShowing() || !paintedK || Math.abs(scale() / paintedK - 1) <= 0.02) break;
|
|
88
|
+
cancelAnimationFrame(rezoom); rezoom = 0;
|
|
89
|
+
o.onRezoom();
|
|
90
|
+
}
|
|
91
|
+
moved = false;
|
|
92
|
+
}
|
|
93
|
+
/** v0.4.2: fit, unless the person has moved the view; not before the stage has a size (a hidden or unlaid-out host) */
|
|
94
|
+
function autoFit() {
|
|
95
|
+
if (moved || !o.svg() || !view) return;
|
|
96
|
+
const r = host.getBoundingClientRect();
|
|
97
|
+
if (r.width < 2 || r.height < 2) return;
|
|
98
|
+
fitItems();
|
|
99
|
+
}
|
|
100
|
+
function actual() { if (!view) return; const k = scale(); zoomAt(1 / k); }
|
|
101
|
+
/** v0.4.2: resolves once the view has settled: no refit or overlay repaint waiting, and the zoom unchanged, for two
|
|
102
|
+
* frames in a row. The overlay's marks keep their size on screen, so a new zoom redraws them; a test (or a host)
|
|
103
|
+
* that measures the overlay waits for this first. */
|
|
104
|
+
function settled(): Promise<void> {
|
|
105
|
+
return new Promise(res => {
|
|
106
|
+
let calm = 0, k0 = keptK;
|
|
107
|
+
const tick = () => {
|
|
108
|
+
if (disposed) { res(); return; }
|
|
109
|
+
const busy = !!(rezoom || resizeFrame) || keptK !== k0;
|
|
110
|
+
k0 = keptK; calm = busy ? 0 : calm + 1;
|
|
111
|
+
if (calm >= 2) res(); else requestAnimationFrame(tick);
|
|
112
|
+
};
|
|
113
|
+
requestAnimationFrame(tick);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// a resize: until the person has moved the view it stays fitted (the host's layout settling, narrow ↔ wide); after,
|
|
117
|
+
// their zoom is kept, and the view is only re-centred to the new size
|
|
118
|
+
const resizes = new ResizeObserver(() => {
|
|
119
|
+
if (!view || disposed) return;
|
|
120
|
+
// their zoom kept: the view re-centred at the same scale for the new size
|
|
121
|
+
if (moved && keptK) { const sz = size(), cx = view.x + view.w / 2, cy = view.y + view.h / 2; view = { x: cx - sz.w / keptK / 2, y: cy - sz.h / keptK / 2, w: sz.w / keptK, h: sz.h / keptK }; }
|
|
122
|
+
if (!moved) { cancelAnimationFrame(resizeFrame); resizeFrame = requestAnimationFrame(() => { resizeFrame = 0; if (!disposed) autoFit(); }); }
|
|
123
|
+
quietly(applyView);
|
|
124
|
+
});
|
|
125
|
+
resizes.observe(host);
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
/** the view (the drawing's units): set by a pan or a reveal, then applyView() */
|
|
129
|
+
get view() { return view; }, set view(v: View | undefined) { view = v; },
|
|
130
|
+
/** the scene's whole frame */
|
|
131
|
+
get full() { return full; }, set full(v: View | undefined) { full = v; },
|
|
132
|
+
/** the person has moved the view since the last fit */
|
|
133
|
+
get moved() { return moved; },
|
|
134
|
+
/** the zoom the view was last applied at */
|
|
135
|
+
get zoom() { return keptK; },
|
|
136
|
+
/** the marks were drawn at this zoom (0: none drawn) */
|
|
137
|
+
painted(k: number) { paintedK = k; },
|
|
138
|
+
size, scale, quietly, applyView, toSvg, zoomAt, fit, fitItems, autoFit, actual, settled,
|
|
139
|
+
dispose() { cancelAnimationFrame(resizeFrame); cancelAnimationFrame(rezoom); resizes.disconnect(); disposed = true; },
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export type Viewport = ReturnType<typeof viewport>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Ajv2020Mod from 'ajv/dist/2020.js';
|
|
2
|
+
import type { ValidateFunction } from 'ajv';
|
|
3
|
+
export declare const Ajv2020: typeof Ajv2020Mod.default;
|
|
4
|
+
export declare const AJV_OPTIONS: {
|
|
5
|
+
readonly allErrors: true;
|
|
6
|
+
readonly verbose: true;
|
|
7
|
+
readonly strict: false;
|
|
8
|
+
};
|
|
9
|
+
export declare function compileSchema(schema: object): ValidateFunction;
|
|
10
|
+
/** A stable fingerprint of a schema (FNV-1a over its JSON): the browser build looks validators up by it. */
|
|
11
|
+
export declare function fingerprint(schema: object): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Severity = 'error' | 'warning';
|
|
2
|
+
export interface Diag {
|
|
3
|
+
severity: Severity;
|
|
4
|
+
message: string;
|
|
5
|
+
/** 1-based; 0 when the place is unknown */
|
|
6
|
+
line: number;
|
|
7
|
+
col: number;
|
|
8
|
+
/** the JSON path in the document, for tools and tests, e.g. /scenes/0/nodes/2/asset */
|
|
9
|
+
path: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
/** another file the place is in (a defaults or override file), with its text for the excerpt */
|
|
12
|
+
file?: string;
|
|
13
|
+
source?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class DiagError extends Error {
|
|
16
|
+
diags: Diag[];
|
|
17
|
+
constructor(diags: Diag[]);
|
|
18
|
+
}
|
|
19
|
+
/** Edit distance where swapping two neighbouring letters counts as one edit (optimal string alignment). */
|
|
20
|
+
export declare function distance(a: string, b: string): number;
|
|
21
|
+
/** The closest candidate, if it is close enough to be a likely typo. */
|
|
22
|
+
export declare function didYouMean(word: string, candidates: Iterable<string>): string | undefined;
|
|
23
|
+
export declare function formatDiag(d: Diag, file: string, source?: string): string;
|
|
24
|
+
export declare function formatDiags(diags: Diag[], file: string, source?: string): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Box, type Kernel } from './kernel.js';
|
|
2
|
+
/** "terminal lines" on the +y (front-left) face */
|
|
3
|
+
export declare function termLines(k: Kernel, b: Box, n: number): string;
|
|
4
|
+
/** Envelope on the top face (a mailbox, an inbox). */
|
|
5
|
+
export declare function envelope(k: Kernel, b: Box): string;
|
|
6
|
+
/** Chat bubble on the top face: a frame with two lines of text (chat servers). */
|
|
7
|
+
export declare function bubble(k: Kernel, b: Box): string;
|
|
8
|
+
/** Two lines of text on the top face (files, records). */
|
|
9
|
+
export declare function fileLines(k: Kernel, b: Box): string;
|
|
10
|
+
/** A key glyph on the top face: a bow and a bit. */
|
|
11
|
+
export declare function keyGlyph(k: Kernel, b: Box): string;
|
|
12
|
+
/** A socket: a round opening on the top face. */
|
|
13
|
+
export declare function socketGlyph(k: Kernel, b: Box): string;
|
|
14
|
+
/** what a screen shows, drawn in its own 2D plane; a host adds its own by name (iso-objects' registerMarks) */
|
|
15
|
+
export type FacePainter = (w: number, h: number) => string;
|
|
16
|
+
export declare const screenFaces: Record<string, FacePainter>;
|
|
17
|
+
/** a face the drawing names but nothing has registered: a dashed frame with a question mark, so the gap shows */
|
|
18
|
+
export declare function placeholderFace(w: number, h: number): string;
|
|
19
|
+
export declare function screenGlass(w: number, h: number): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { S, C, iso, n1, pt, esc, tag, FONTS, textWidth, apply, matStr, faceFrame, Bounds, Kernel, center } from './kernel.js';
|
|
2
|
+
export type { P2, P3, Box, Attrs, FontKey, Font, Mat, Face, TextRect } from './kernel.js';
|
|
3
|
+
export { termLines, envelope, bubble, fileLines, keyGlyph, socketGlyph, screenFaces, screenGlass, placeholderFace } from './glyphs.js';
|
|
4
|
+
export type { FacePainter } from './glyphs.js';
|
|
5
|
+
export { depthSort } from './depth.js';
|
|
6
|
+
export type { Drawable } from './depth.js';
|
|
7
|
+
export { loadTheme, extendTheme, colorRef, themeCss, themeParts } from './theme.js';
|
|
8
|
+
export type { RawRole, RawKind, Theme } from './theme.js';
|
|
9
|
+
export { DiagError, distance, didYouMean, formatDiag, formatDiags } from './errors.js';
|
|
10
|
+
export type { Severity, Diag } from './errors.js';
|
|
11
|
+
export { parse } from './parse.js';
|
|
12
|
+
export type { Parsed } from './parse.js';
|
|
13
|
+
export { allowed, parseSvg, buildSvg } from './svg-dom.js';
|
|
14
|
+
export type { SvgNode } from './svg-dom.js';
|
|
15
|
+
export { VEl, vdoc, serialize } from './vdom.js';
|
|
16
|
+
export type { VNode } from './vdom.js';
|
|
17
|
+
export { createHash, sha256Hex } from './shims/crypto.js';
|