@visual-layer/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifact-store/index.d.ts +70 -0
- package/dist/artifact-store/index.d.ts.map +1 -0
- package/dist/artifact-store/index.js +289 -0
- package/dist/artifact-store/index.js.map +1 -0
- package/dist/browser-adapter.d.ts +1362 -0
- package/dist/browser-adapter.d.ts.map +1 -0
- package/dist/browser-adapter.js +264 -0
- package/dist/browser-adapter.js.map +1 -0
- package/dist/confidence.d.ts +8 -0
- package/dist/confidence.d.ts.map +1 -0
- package/dist/confidence.js +28 -0
- package/dist/confidence.js.map +1 -0
- package/dist/errors.d.ts +41 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +33 -0
- package/dist/errors.js.map +1 -0
- package/dist/geometry/bbox.d.ts +30 -0
- package/dist/geometry/bbox.d.ts.map +1 -0
- package/dist/geometry/bbox.js +77 -0
- package/dist/geometry/bbox.js.map +1 -0
- package/dist/geometry/coordinates.d.ts +26 -0
- package/dist/geometry/coordinates.d.ts.map +1 -0
- package/dist/geometry/coordinates.js +25 -0
- package/dist/geometry/coordinates.js.map +1 -0
- package/dist/geometry/index.d.ts +3 -0
- package/dist/geometry/index.d.ts.map +1 -0
- package/dist/geometry/index.js +3 -0
- package/dist/geometry/index.js.map +1 -0
- package/dist/ids.d.ts +7 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +21 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/provenance.d.ts +7 -0
- package/dist/provenance.d.ts.map +1 -0
- package/dist/provenance.js +9 -0
- package/dist/provenance.js.map +1 -0
- package/dist/redaction/index.d.ts +28 -0
- package/dist/redaction/index.d.ts.map +1 -0
- package/dist/redaction/index.js +97 -0
- package/dist/redaction/index.js.map +1 -0
- package/dist/schema/index.d.ts +383 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +96 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/text/index.d.ts +18 -0
- package/dist/text/index.d.ts.map +1 -0
- package/dist/text/index.js +60 -0
- package/dist/text/index.js.map +1 -0
- package/dist/trace/index.d.ts +64 -0
- package/dist/trace/index.d.ts.map +1 -0
- package/dist/trace/index.js +63 -0
- package/dist/trace/index.js.map +1 -0
- package/dist/warnings.d.ts +7 -0
- package/dist/warnings.d.ts.map +1 -0
- package/dist/warnings.js +10 -0
- package/dist/warnings.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-adapter.d.ts","sourceRoot":"","sources":["../src/browser-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,KAAK,WAAW,EAGhB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EAQhB,MAAM,YAAY,CAAC;AASpB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAmBd,CAAC;AAEjB,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7D,eAAO,MAAM,oBAAoB;IAE7B,kDAAkD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEvC,mDAAmD;;gCAGvC,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAgCnE,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAE,mBAAwB,GAAG,IAAI,CAkB7F;AA2BD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,8CAA8C;IAC9C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,OAAO,EACpB,IAAI,GAAE,cAAmB,GACxB,aAAa,CA6Gf"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser snapshot adapter — the SOLE coupling point with the external browser
|
|
3
|
+
* engine (chrome-devtools-mcp). `snapshotToScreenGraph` normalizes a Chromium
|
|
4
|
+
* AX/DOM snapshot into a `ScreenGraph` with `source: "browser"`.
|
|
5
|
+
*
|
|
6
|
+
* Boundary rules (§18.12): never fork/import/vendor the engine. Coupling is
|
|
7
|
+
* the JSON shape of the snapshot, isolated here and protected by golden tests.
|
|
8
|
+
*/
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { SCHEMA_VERSION, assertBbox, deterministicId, warn, errorw, info, ErrorCodes, } from './index.js';
|
|
11
|
+
/* ---------- permissive input schema ---------- */
|
|
12
|
+
const BboxInput = z.union([
|
|
13
|
+
z.tuple([z.number(), z.number(), z.number(), z.number()]),
|
|
14
|
+
z.object({ x: z.number(), y: z.number(), width: z.number(), height: z.number() }),
|
|
15
|
+
]);
|
|
16
|
+
export const SnapshotNodeInput = z
|
|
17
|
+
.object({
|
|
18
|
+
role: z.string().optional(),
|
|
19
|
+
name: z.string().optional(),
|
|
20
|
+
text: z.string().optional(),
|
|
21
|
+
value: z.unknown().optional(),
|
|
22
|
+
bbox: BboxInput.optional(),
|
|
23
|
+
boundingBox: BboxInput.optional(),
|
|
24
|
+
boundingbox: BboxInput.optional(),
|
|
25
|
+
ref: z.string().optional(),
|
|
26
|
+
nodeId: z.union([z.string(), z.number()]).optional(),
|
|
27
|
+
backendDOMNodeId: z.union([z.string(), z.number()]).optional(),
|
|
28
|
+
domPath: z.string().optional(),
|
|
29
|
+
xpath: z.string().optional(),
|
|
30
|
+
children: z.array(z.lazy(() => SnapshotNodeInput)).optional(),
|
|
31
|
+
visible: z.boolean().optional(),
|
|
32
|
+
hidden: z.boolean().optional(),
|
|
33
|
+
attributes: z.record(z.string(), z.unknown()).optional(),
|
|
34
|
+
})
|
|
35
|
+
.passthrough();
|
|
36
|
+
export const BrowserSnapshotInput = z
|
|
37
|
+
.object({
|
|
38
|
+
/** Flat node list (preferred by some engines). */
|
|
39
|
+
nodes: z.array(SnapshotNodeInput).optional(),
|
|
40
|
+
/** Tree root (preferred by others). */
|
|
41
|
+
root: SnapshotNodeInput.optional(),
|
|
42
|
+
/** Raw text/markdown content, kept for context. */
|
|
43
|
+
content: z.string().optional(),
|
|
44
|
+
})
|
|
45
|
+
.passthrough();
|
|
46
|
+
/* ---------- interactive role table (Playwright-locator aligned) ---------- */
|
|
47
|
+
const INTERACTIVE_ROLES = new Set([
|
|
48
|
+
'button',
|
|
49
|
+
'link',
|
|
50
|
+
'textbox',
|
|
51
|
+
'searchbox',
|
|
52
|
+
'combobox',
|
|
53
|
+
'listbox',
|
|
54
|
+
'checkbox',
|
|
55
|
+
'radio',
|
|
56
|
+
'slider',
|
|
57
|
+
'spinbutton',
|
|
58
|
+
'switch',
|
|
59
|
+
'menuitem',
|
|
60
|
+
'menuitemcheckbox',
|
|
61
|
+
'menuitemradio',
|
|
62
|
+
'tab',
|
|
63
|
+
'option',
|
|
64
|
+
'treeitem',
|
|
65
|
+
'tree',
|
|
66
|
+
'menu',
|
|
67
|
+
'menubar',
|
|
68
|
+
'grid',
|
|
69
|
+
'list',
|
|
70
|
+
'navigation',
|
|
71
|
+
]);
|
|
72
|
+
export function assertSnapshotPayload(snapshot, opts = {}) {
|
|
73
|
+
const maxBytes = opts.maxBytes ?? 8 * 1024 * 1024;
|
|
74
|
+
const maxDepth = opts.maxDepth ?? 500;
|
|
75
|
+
let bytes;
|
|
76
|
+
try {
|
|
77
|
+
bytes = Buffer.byteLength(JSON.stringify(snapshot), 'utf8');
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw payloadOversized('cannot serialize snapshot');
|
|
81
|
+
}
|
|
82
|
+
if (bytes > maxBytes) {
|
|
83
|
+
throw payloadOversized(`snapshot ${bytes}B exceeds cap ${maxBytes}B`);
|
|
84
|
+
}
|
|
85
|
+
const depth = measureDepth(snapshot);
|
|
86
|
+
if (depth > maxDepth) {
|
|
87
|
+
throw payloadOversized(`snapshot nesting depth ${depth} exceeds cap ${maxDepth}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function payloadOversized(detail) {
|
|
91
|
+
const e = new Error(`${ErrorCodes.snapshot_payload_oversized}: ${detail}`);
|
|
92
|
+
e.code = ErrorCodes.snapshot_payload_oversized;
|
|
93
|
+
return e;
|
|
94
|
+
}
|
|
95
|
+
function measureDepth(node, acc = 0) {
|
|
96
|
+
if (acc > 10_000)
|
|
97
|
+
return acc;
|
|
98
|
+
if (Array.isArray(node)) {
|
|
99
|
+
let max = acc;
|
|
100
|
+
for (const c of node)
|
|
101
|
+
max = Math.max(max, measureDepth(c, acc + 1));
|
|
102
|
+
return max;
|
|
103
|
+
}
|
|
104
|
+
if (node && typeof node === 'object') {
|
|
105
|
+
let max = acc;
|
|
106
|
+
for (const v of Object.values(node)) {
|
|
107
|
+
max = Math.max(max, measureDepth(v, acc + 1));
|
|
108
|
+
}
|
|
109
|
+
return max;
|
|
110
|
+
}
|
|
111
|
+
return acc;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Normalize a Chromium-style snapshot into a ScreenGraph.
|
|
115
|
+
* Throws structured errors for malformed/oversized/missing-field input.
|
|
116
|
+
*/
|
|
117
|
+
export function snapshotToScreenGraph(rawSnapshot, opts = {}) {
|
|
118
|
+
assertSnapshotPayload(rawSnapshot);
|
|
119
|
+
const parsed = BrowserSnapshotInput.safeParse(rawSnapshot);
|
|
120
|
+
if (!parsed.success) {
|
|
121
|
+
throw malformed(parsed.error.message);
|
|
122
|
+
}
|
|
123
|
+
const snap = parsed.data;
|
|
124
|
+
const flat = [];
|
|
125
|
+
if (snap.root)
|
|
126
|
+
flatten(snap.root, flat);
|
|
127
|
+
if (snap.nodes)
|
|
128
|
+
for (const n of snap.nodes)
|
|
129
|
+
flatten(n, flat);
|
|
130
|
+
if (flat.length === 0) {
|
|
131
|
+
throw missingFields('snapshot has no nodes');
|
|
132
|
+
}
|
|
133
|
+
const baseConfidence = opts.baseConfidence ?? 0.9;
|
|
134
|
+
const warnings = [];
|
|
135
|
+
const interactables = [];
|
|
136
|
+
const seenLabels = new Map();
|
|
137
|
+
let idx = 0;
|
|
138
|
+
for (const node of flat) {
|
|
139
|
+
const role = (node.role ?? '').toLowerCase();
|
|
140
|
+
if (!INTERACTIVE_ROLES.has(role))
|
|
141
|
+
continue;
|
|
142
|
+
const bbox = normalizeBbox(node);
|
|
143
|
+
const axRef = node.ref ?? (node.nodeId !== undefined ? String(node.nodeId) : undefined);
|
|
144
|
+
const domPath = node.domPath ?? node.xpath;
|
|
145
|
+
const label = pickLabel(node);
|
|
146
|
+
// hidden / no bbox => warning, skip emitting (do not emit partial)
|
|
147
|
+
const isHidden = node.hidden === true || node.visible === false;
|
|
148
|
+
if (!bbox) {
|
|
149
|
+
if (axRef || label) {
|
|
150
|
+
warnings.push(warn('snapshot_missing_fields', `interactive "${role}" has no bbox`, undefined));
|
|
151
|
+
}
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (isHidden || (bbox[2] === 0 && bbox[3] === 0)) {
|
|
155
|
+
warnings.push(info('hidden_interactable', `hidden ${role} skipped`, undefined));
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
assertBbox(bbox);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
warnings.push(errorw('snapshot_missing_fields', `invalid bbox on ${role}`));
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const idSeed = domPath ?? axRef ?? `${role}:${label}:${idx}`;
|
|
166
|
+
const id = deterministicId('i', idSeed);
|
|
167
|
+
const sources = ['ax'];
|
|
168
|
+
if (domPath)
|
|
169
|
+
sources.push('dom');
|
|
170
|
+
const attributes = collectAttributes(node);
|
|
171
|
+
const inter = {
|
|
172
|
+
id,
|
|
173
|
+
role: role || undefined,
|
|
174
|
+
name: node.name,
|
|
175
|
+
text: label !== node.name ? label : undefined,
|
|
176
|
+
bbox,
|
|
177
|
+
coordinateSpace: 'viewport',
|
|
178
|
+
source: sources,
|
|
179
|
+
confidence: baseConfidence,
|
|
180
|
+
...(domPath !== undefined ? { domPath } : {}),
|
|
181
|
+
...(axRef !== undefined ? { axRef } : {}),
|
|
182
|
+
...(Object.keys(attributes).length > 0 ? { attributes } : {}),
|
|
183
|
+
};
|
|
184
|
+
interactables.push(inter);
|
|
185
|
+
if (label)
|
|
186
|
+
seenLabels.set(label, (seenLabels.get(label) ?? 0) + 1);
|
|
187
|
+
idx++;
|
|
188
|
+
}
|
|
189
|
+
// duplicate-label warnings
|
|
190
|
+
for (const [label, count] of seenLabels) {
|
|
191
|
+
if (count > 1) {
|
|
192
|
+
warnings.push(warn('duplicate_label', `"${label}" appears ${count}x`, undefined));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (interactables.length === 0) {
|
|
196
|
+
warnings.push(warn('no_interactables', 'snapshot yielded no interactables', undefined));
|
|
197
|
+
}
|
|
198
|
+
if (!opts.screenshot) {
|
|
199
|
+
warnings.push(info('screenshot_ref_missing', 'no screenshot artifact attached', undefined));
|
|
200
|
+
}
|
|
201
|
+
const graph = {
|
|
202
|
+
id: opts.id ?? deterministicId('sg', `browser:${idx}`),
|
|
203
|
+
version: SCHEMA_VERSION,
|
|
204
|
+
source: 'browser',
|
|
205
|
+
createdAt: new Date().toISOString(),
|
|
206
|
+
...(opts.viewport ? { viewport: opts.viewport } : {}),
|
|
207
|
+
...(opts.screenshot ? { screenshot: opts.screenshot } : {}),
|
|
208
|
+
interactables,
|
|
209
|
+
mappings: [],
|
|
210
|
+
axNodes: flat,
|
|
211
|
+
warnings,
|
|
212
|
+
provenance: [
|
|
213
|
+
{ field: 'interactables', source: 'ax', confidence: baseConfidence, note: 'chrome-devtools-mcp snapshot' },
|
|
214
|
+
],
|
|
215
|
+
};
|
|
216
|
+
return { graph, warnings };
|
|
217
|
+
}
|
|
218
|
+
/* ---------- helpers ---------- */
|
|
219
|
+
function flatten(node, out) {
|
|
220
|
+
out.push(node);
|
|
221
|
+
const kids = node.children;
|
|
222
|
+
if (Array.isArray(kids)) {
|
|
223
|
+
for (const c of kids)
|
|
224
|
+
flatten(c, out);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function normalizeBbox(node) {
|
|
228
|
+
const raw = node.bbox ?? node.boundingBox ?? node.boundingbox;
|
|
229
|
+
if (!raw)
|
|
230
|
+
return null;
|
|
231
|
+
if (Array.isArray(raw)) {
|
|
232
|
+
if (raw.length !== 4)
|
|
233
|
+
return null;
|
|
234
|
+
return [Number(raw[0]), Number(raw[1]), Number(raw[2]), Number(raw[3])];
|
|
235
|
+
}
|
|
236
|
+
const { x, y, width, height } = raw;
|
|
237
|
+
return [Number(x), Number(y), Number(width), Number(height)];
|
|
238
|
+
}
|
|
239
|
+
function pickLabel(node) {
|
|
240
|
+
return (node.text ?? node.name ?? '').toString();
|
|
241
|
+
}
|
|
242
|
+
function collectAttributes(node) {
|
|
243
|
+
const out = {};
|
|
244
|
+
const attrs = node.attributes;
|
|
245
|
+
if (attrs && typeof attrs === 'object') {
|
|
246
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
247
|
+
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') {
|
|
248
|
+
out[k] = v;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
function malformed(detail) {
|
|
255
|
+
const e = new Error(`snapshot_malformed: ${detail}`);
|
|
256
|
+
e.code = ErrorCodes.snapshot_malformed;
|
|
257
|
+
return e;
|
|
258
|
+
}
|
|
259
|
+
function missingFields(detail) {
|
|
260
|
+
const e = new Error(`snapshot_missing_fields: ${detail}`);
|
|
261
|
+
e.code = ErrorCodes.snapshot_missing_fields;
|
|
262
|
+
return e;
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=browser-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-adapter.js","sourceRoot":"","sources":["../src/browser-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAOL,cAAc,EACd,UAAU,EACV,eAAe,EACf,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,mDAAmD;AAEnD,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;IACxB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAA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
export declare function assertConfidence(c: number): asserts c is number;
|
|
2
|
+
export declare function clampConfidence(c: number): number;
|
|
3
|
+
/** Weighted average of confidences, weights need not sum to 1. */
|
|
4
|
+
export declare function blendConfidence(values: ReadonlyArray<{
|
|
5
|
+
value: number;
|
|
6
|
+
weight: number;
|
|
7
|
+
}>): number;
|
|
8
|
+
//# sourceMappingURL=confidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence.d.ts","sourceRoot":"","sources":["../src/confidence.ts"],"names":[],"mappings":"AAGA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,IAAI,MAAM,CAK/D;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAUhG"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Confidence helpers. All confidences are finite numbers in [0, 1]. */
|
|
2
|
+
import { Confidence } from './schema/index.js';
|
|
3
|
+
export function assertConfidence(c) {
|
|
4
|
+
const parsed = Confidence.safeParse(c);
|
|
5
|
+
if (!parsed.success) {
|
|
6
|
+
throw new Error(`confidence must be a finite number in [0,1], got ${c}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function clampConfidence(c) {
|
|
10
|
+
if (!Number.isFinite(c))
|
|
11
|
+
return 0;
|
|
12
|
+
return Math.max(0, Math.min(1, c));
|
|
13
|
+
}
|
|
14
|
+
/** Weighted average of confidences, weights need not sum to 1. */
|
|
15
|
+
export function blendConfidence(values) {
|
|
16
|
+
let totalWeight = 0;
|
|
17
|
+
let acc = 0;
|
|
18
|
+
for (const { value, weight } of values) {
|
|
19
|
+
if (!Number.isFinite(weight) || weight < 0)
|
|
20
|
+
continue;
|
|
21
|
+
acc += clampConfidence(value) * weight;
|
|
22
|
+
totalWeight += weight;
|
|
23
|
+
}
|
|
24
|
+
if (totalWeight === 0)
|
|
25
|
+
return 0;
|
|
26
|
+
return acc / totalWeight;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=confidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence.js","sourceRoot":"","sources":["../src/confidence.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,CAAS;IACxC,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAS;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,MAAwD;IACtF,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC;YAAE,SAAS;QACrD,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;QACvC,WAAW,IAAI,MAAM,CAAC;IACxB,CAAC;IACD,IAAI,WAAW,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAChC,OAAO,GAAG,GAAG,WAAW,CAAC;AAC3B,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured errors. Every tool boundary returns these instead of throwing
|
|
3
|
+
* raw Error objects so MCP/CLI clients get a consistent shape with a code,
|
|
4
|
+
* message, optional details, and a link back to the run's trace.
|
|
5
|
+
*/
|
|
6
|
+
export interface StructuredError {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
details?: unknown;
|
|
10
|
+
tracePath?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function structuredError(code: string, message: string, opts?: {
|
|
13
|
+
details?: unknown;
|
|
14
|
+
tracePath?: string;
|
|
15
|
+
}): StructuredError;
|
|
16
|
+
/** Canonical error codes used across packages. Keep stable. */
|
|
17
|
+
export declare const ErrorCodes: {
|
|
18
|
+
readonly invalid_input: "invalid_input";
|
|
19
|
+
readonly snapshot_malformed: "snapshot_malformed";
|
|
20
|
+
readonly snapshot_missing_fields: "snapshot_missing_fields";
|
|
21
|
+
readonly snapshot_payload_oversized: "snapshot_payload_oversized";
|
|
22
|
+
readonly screenshot_ref_missing: "screenshot_ref_missing";
|
|
23
|
+
readonly missing_token: "missing_token";
|
|
24
|
+
readonly auth_failed: "auth_failed";
|
|
25
|
+
readonly rate_limited: "rate_limited";
|
|
26
|
+
readonly node_not_found: "node_not_found";
|
|
27
|
+
readonly no_candidates: "no_candidates";
|
|
28
|
+
readonly coordinate_transform_missing: "coordinate_transform_missing";
|
|
29
|
+
readonly unsupported_compare_mode: "unsupported_compare_mode";
|
|
30
|
+
readonly compare_truncated: "compare_truncated";
|
|
31
|
+
readonly fixture_invalid: "fixture_invalid";
|
|
32
|
+
readonly artifact_write_failed: "artifact_write_failed";
|
|
33
|
+
readonly artifact_forbidden: "artifact_forbidden";
|
|
34
|
+
readonly artifact_not_found: "artifact_not_found";
|
|
35
|
+
readonly graph_not_found: "graph_not_found";
|
|
36
|
+
readonly element_not_found: "element_not_found";
|
|
37
|
+
readonly redaction_failed: "redaction_failed";
|
|
38
|
+
readonly internal_error: "internal_error";
|
|
39
|
+
};
|
|
40
|
+
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
41
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,eAAe,CAKpI;AAED,+DAA+D;AAC/D,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;CAsBb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function structuredError(code, message, opts = {}) {
|
|
2
|
+
const e = { code, message };
|
|
3
|
+
if (opts.details !== undefined)
|
|
4
|
+
e.details = opts.details;
|
|
5
|
+
if (opts.tracePath !== undefined)
|
|
6
|
+
e.tracePath = opts.tracePath;
|
|
7
|
+
return e;
|
|
8
|
+
}
|
|
9
|
+
/** Canonical error codes used across packages. Keep stable. */
|
|
10
|
+
export const ErrorCodes = {
|
|
11
|
+
invalid_input: 'invalid_input',
|
|
12
|
+
snapshot_malformed: 'snapshot_malformed',
|
|
13
|
+
snapshot_missing_fields: 'snapshot_missing_fields',
|
|
14
|
+
snapshot_payload_oversized: 'snapshot_payload_oversized',
|
|
15
|
+
screenshot_ref_missing: 'screenshot_ref_missing',
|
|
16
|
+
missing_token: 'missing_token',
|
|
17
|
+
auth_failed: 'auth_failed',
|
|
18
|
+
rate_limited: 'rate_limited',
|
|
19
|
+
node_not_found: 'node_not_found',
|
|
20
|
+
no_candidates: 'no_candidates',
|
|
21
|
+
coordinate_transform_missing: 'coordinate_transform_missing',
|
|
22
|
+
unsupported_compare_mode: 'unsupported_compare_mode',
|
|
23
|
+
compare_truncated: 'compare_truncated',
|
|
24
|
+
fixture_invalid: 'fixture_invalid',
|
|
25
|
+
artifact_write_failed: 'artifact_write_failed',
|
|
26
|
+
artifact_forbidden: 'artifact_forbidden',
|
|
27
|
+
artifact_not_found: 'artifact_not_found',
|
|
28
|
+
graph_not_found: 'graph_not_found',
|
|
29
|
+
element_not_found: 'element_not_found',
|
|
30
|
+
redaction_failed: 'redaction_failed',
|
|
31
|
+
internal_error: 'internal_error',
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,OAAe,EAAE,OAAkD,EAAE;IACjH,MAAM,CAAC,GAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IAC7C,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAAE,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IACzD,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS;QAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IAC/D,OAAO,CAAC,CAAC;AACX,CAAC;AAED,+DAA+D;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,eAAe;IAC9B,kBAAkB,EAAE,oBAAoB;IACxC,uBAAuB,EAAE,yBAAyB;IAClD,0BAA0B,EAAE,4BAA4B;IACxD,sBAAsB,EAAE,wBAAwB;IAChD,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;IAC9B,4BAA4B,EAAE,8BAA8B;IAC5D,wBAAwB,EAAE,0BAA0B;IACpD,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,qBAAqB,EAAE,uBAAuB;IAC9C,kBAAkB,EAAE,oBAAoB;IACxC,kBAAkB,EAAE,oBAAoB;IACxC,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,gBAAgB;CACxB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bbox geometry primitives. bbox is always `[x, y, width, height]`.
|
|
3
|
+
*/
|
|
4
|
+
import type { Bbox } from '../schema/index.js';
|
|
5
|
+
export interface Point {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
}
|
|
9
|
+
/** Validate that a 4-tuple is a well-formed bbox. Throws on malformed input. */
|
|
10
|
+
export declare function assertBbox(b: ReadonlyArray<number>): asserts b is Bbox;
|
|
11
|
+
/** true when bbox has positive area. */
|
|
12
|
+
export declare function hasArea(b: Bbox): boolean;
|
|
13
|
+
export declare function area(b: Bbox): number;
|
|
14
|
+
export declare function center(b: Bbox): Point;
|
|
15
|
+
/** Intersection of two boxes, or null if disjoint. */
|
|
16
|
+
export declare function intersection(a: Bbox, b: Bbox): Bbox | null;
|
|
17
|
+
/** Union bounding box of two boxes. */
|
|
18
|
+
export declare function union(a: Bbox, b: Bbox): Bbox;
|
|
19
|
+
/** Intersection-over-union in [0, 1]. Returns 0 when either box has no area or they are disjoint. */
|
|
20
|
+
export declare function iou(a: Bbox, b: Bbox): number;
|
|
21
|
+
/** True when box `inner` is fully contained inside `outer`. */
|
|
22
|
+
export declare function contains(outer: Bbox, inner: Bbox): boolean;
|
|
23
|
+
/** Distance between centers. Useful as a spatial fallback score. */
|
|
24
|
+
export declare function centerDistance(a: Bbox, b: Bbox): number;
|
|
25
|
+
/**
|
|
26
|
+
* Scale a bbox by a factor (e.g. viewport->screenshot uses dpr).
|
|
27
|
+
* Origin scales too — this is a pure coordinate rescale, not a resize-about-center.
|
|
28
|
+
*/
|
|
29
|
+
export declare function scale(b: Bbox, factor: number): Bbox;
|
|
30
|
+
//# sourceMappingURL=bbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.d.ts","sourceRoot":"","sources":["../../src/geometry/bbox.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,IAAI,CAatE;AAED,wCAAwC;AACxC,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAExC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAEpC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,KAAK,CAErC;AAED,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAO1D;AAED,uCAAuC;AACvC,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,IAAI,CAM5C;AAED,qGAAqG;AACrG,wBAAgB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAO5C;AAED,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,CAO1D;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAIvD;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAKnD"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** Validate that a 4-tuple is a well-formed bbox. Throws on malformed input. */
|
|
2
|
+
export function assertBbox(b) {
|
|
3
|
+
if (b.length !== 4) {
|
|
4
|
+
throw new Error(`bbox must have 4 elements, got ${b.length}`);
|
|
5
|
+
}
|
|
6
|
+
for (let i = 0; i < 4; i++) {
|
|
7
|
+
const v = b[i];
|
|
8
|
+
if (v === undefined || !Number.isFinite(v)) {
|
|
9
|
+
throw new Error(`bbox[${i}] must be finite, got ${String(v)}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (b[2] < 0 || b[3] < 0) {
|
|
13
|
+
throw new Error(`bbox width/height must be non-negative, got [${b.join(', ')}]`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** true when bbox has positive area. */
|
|
17
|
+
export function hasArea(b) {
|
|
18
|
+
return b[2] > 0 && b[3] > 0;
|
|
19
|
+
}
|
|
20
|
+
export function area(b) {
|
|
21
|
+
return b[2] * b[3];
|
|
22
|
+
}
|
|
23
|
+
export function center(b) {
|
|
24
|
+
return { x: b[0] + b[2] / 2, y: b[1] + b[3] / 2 };
|
|
25
|
+
}
|
|
26
|
+
/** Intersection of two boxes, or null if disjoint. */
|
|
27
|
+
export function intersection(a, b) {
|
|
28
|
+
const x0 = Math.max(a[0], b[0]);
|
|
29
|
+
const y0 = Math.max(a[1], b[1]);
|
|
30
|
+
const x1 = Math.min(a[0] + a[2], b[0] + b[2]);
|
|
31
|
+
const y1 = Math.min(a[1] + a[3], b[1] + b[3]);
|
|
32
|
+
if (x1 <= x0 || y1 <= y0)
|
|
33
|
+
return null;
|
|
34
|
+
return [x0, y0, x1 - x0, y1 - y0];
|
|
35
|
+
}
|
|
36
|
+
/** Union bounding box of two boxes. */
|
|
37
|
+
export function union(a, b) {
|
|
38
|
+
const x0 = Math.min(a[0], b[0]);
|
|
39
|
+
const y0 = Math.min(a[1], b[1]);
|
|
40
|
+
const x1 = Math.max(a[0] + a[2], b[0] + b[2]);
|
|
41
|
+
const y1 = Math.max(a[1] + a[3], b[1] + b[3]);
|
|
42
|
+
return [x0, y0, x1 - x0, y1 - y0];
|
|
43
|
+
}
|
|
44
|
+
/** Intersection-over-union in [0, 1]. Returns 0 when either box has no area or they are disjoint. */
|
|
45
|
+
export function iou(a, b) {
|
|
46
|
+
const aa = area(a);
|
|
47
|
+
const ab = area(b);
|
|
48
|
+
if (aa === 0 || ab === 0)
|
|
49
|
+
return 0;
|
|
50
|
+
const inter = intersection(a, b);
|
|
51
|
+
const interArea = inter ? area(inter) : 0;
|
|
52
|
+
return interArea / (aa + ab - interArea);
|
|
53
|
+
}
|
|
54
|
+
/** True when box `inner` is fully contained inside `outer`. */
|
|
55
|
+
export function contains(outer, inner) {
|
|
56
|
+
return (inner[0] >= outer[0] &&
|
|
57
|
+
inner[1] >= outer[1] &&
|
|
58
|
+
inner[0] + inner[2] <= outer[0] + outer[2] &&
|
|
59
|
+
inner[1] + inner[3] <= outer[1] + outer[3]);
|
|
60
|
+
}
|
|
61
|
+
/** Distance between centers. Useful as a spatial fallback score. */
|
|
62
|
+
export function centerDistance(a, b) {
|
|
63
|
+
const ca = center(a);
|
|
64
|
+
const cb = center(b);
|
|
65
|
+
return Math.hypot(ca.x - cb.x, ca.y - cb.y);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Scale a bbox by a factor (e.g. viewport->screenshot uses dpr).
|
|
69
|
+
* Origin scales too — this is a pure coordinate rescale, not a resize-about-center.
|
|
70
|
+
*/
|
|
71
|
+
export function scale(b, factor) {
|
|
72
|
+
if (!Number.isFinite(factor) || factor <= 0) {
|
|
73
|
+
throw new Error(`scale factor must be positive and finite, got ${factor}`);
|
|
74
|
+
}
|
|
75
|
+
return [b[0] * factor, b[1] * factor, b[2] * factor, b[3] * factor];
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=bbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bbox.js","sourceRoot":"","sources":["../../src/geometry/bbox.ts"],"names":[],"mappings":"AAUA,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,CAAwB;IACjD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,yBAAyB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IACD,IAAI,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CA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,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate-space conversions. Two spaces matter for MVP:
|
|
3
|
+
* - viewport: CSS logical pixels (what the agent reasons about).
|
|
4
|
+
* - screenshot: physical pixels in the captured PNG (viewport * dpr).
|
|
5
|
+
*
|
|
6
|
+
* Figma uses its own internal space; treat it as opaque and require an explicit
|
|
7
|
+
* transform when comparing Figma graphs to browser graphs (compare_graphs
|
|
8
|
+
* returns `coordinate_transform_missing` when none is supplied).
|
|
9
|
+
*/
|
|
10
|
+
import type { Bbox, CoordinateSpace } from '../schema/index.js';
|
|
11
|
+
export interface Transform {
|
|
12
|
+
from: CoordinateSpace;
|
|
13
|
+
to: CoordinateSpace;
|
|
14
|
+
/** Multiplicative factor applied to all four bbox components. */
|
|
15
|
+
factor: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Derive the viewport<->screenshot transform from a DPR value.
|
|
19
|
+
* dpr=2 means screenshot is 2x viewport in each dimension.
|
|
20
|
+
*/
|
|
21
|
+
export declare function viewportScreenshotTransform(dpr: number, direction: 'viewport-to-screenshot' | 'screenshot-to-viewport'): Transform;
|
|
22
|
+
/** Apply a transform to a bbox. Throws if the transform's from/to do not match. */
|
|
23
|
+
export declare function convertBbox(b: Bbox, transform: Transform): Bbox;
|
|
24
|
+
/** Apply a transform to many bboxes. */
|
|
25
|
+
export declare function convertBboxes(bs: readonly Bbox[], transform: Transform): Bbox[];
|
|
26
|
+
//# sourceMappingURL=coordinates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.d.ts","sourceRoot":"","sources":["../../src/geometry/coordinates.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGhE,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,eAAe,CAAC;IACtB,EAAE,EAAE,eAAe,CAAC;IACpB,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,wBAAwB,GAAG,wBAAwB,GAAG,SAAS,CAUlI;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,CAE/D;AAED,wCAAwC;AACxC,wBAAgB,aAAa,CAAC,EAAE,EAAE,SAAS,IAAI,EAAE,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI,EAAE,CAE/E"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { scale } from './bbox.js';
|
|
2
|
+
/**
|
|
3
|
+
* Derive the viewport<->screenshot transform from a DPR value.
|
|
4
|
+
* dpr=2 means screenshot is 2x viewport in each dimension.
|
|
5
|
+
*/
|
|
6
|
+
export function viewportScreenshotTransform(dpr, direction) {
|
|
7
|
+
if (!Number.isFinite(dpr) || dpr <= 0) {
|
|
8
|
+
throw new Error(`dpr must be positive and finite, got ${dpr}`);
|
|
9
|
+
}
|
|
10
|
+
const factor = direction === 'viewport-to-screenshot' ? dpr : 1 / dpr;
|
|
11
|
+
return {
|
|
12
|
+
from: direction === 'viewport-to-screenshot' ? 'viewport' : 'screenshot',
|
|
13
|
+
to: direction === 'viewport-to-screenshot' ? 'screenshot' : 'viewport',
|
|
14
|
+
factor,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** Apply a transform to a bbox. Throws if the transform's from/to do not match. */
|
|
18
|
+
export function convertBbox(b, transform) {
|
|
19
|
+
return scale(b, transform.factor);
|
|
20
|
+
}
|
|
21
|
+
/** Apply a transform to many bboxes. */
|
|
22
|
+
export function convertBboxes(bs, transform) {
|
|
23
|
+
return bs.map((b) => convertBbox(b, transform));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../../src/geometry/coordinates.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AASlC;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAW,EAAE,SAA8D;IACrH,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,wCAAwC,GAAG,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,KAAK,wBAAwB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACtE,OAAO;QACL,IAAI,EAAE,SAAS,KAAK,wBAAwB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY;QACxE,EAAE,EAAE,SAAS,KAAK,wBAAwB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;QACtE,MAAM;KACP,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,WAAW,CAAC,CAAO,EAAE,SAAoB;IACvD,OAAO,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,aAAa,CAAC,EAAmB,EAAE,SAAoB;IACrE,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geometry/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/geometry/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
|
package/dist/ids.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** e.g. makeId('sg') -> "sg_a1b2c3d4e5f6g7h8" */
|
|
2
|
+
export declare function makeId(prefix: string): string;
|
|
3
|
+
/** Short stable ID derived from content. Deterministic for identical input. */
|
|
4
|
+
export declare function deterministicId(prefix: string, content: string): string;
|
|
5
|
+
/** sha256 hex of a string/buffer. */
|
|
6
|
+
export declare function sha256(content: string | Buffer | Uint8Array): string;
|
|
7
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAOA,iDAAiD;AACjD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED,+EAA+E;AAC/E,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGvE;AAED,qCAAqC;AACrC,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,CAEpE"}
|