@typecaast/capture 0.0.8 → 0.1.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/dist/{chunk-MJRHEKPU.js → chunk-4JQY5NEW.js} +112 -13
- package/dist/chunk-4JQY5NEW.js.map +1 -0
- package/dist/{chunk-2UORYZUZ.js → chunk-TBLY4L5G.js} +21 -4
- package/dist/chunk-TBLY4L5G.js.map +1 -0
- package/dist/{distill-kGI5Nt9q.d.cts → distill-CVvHwBKY.d.cts} +17 -0
- package/dist/{distill-DviDU75P.d.ts → distill-Cs7bOU8G.d.ts} +17 -0
- package/dist/draft.cjs +19 -2
- package/dist/draft.cjs.map +1 -1
- package/dist/draft.d.cts +6 -0
- package/dist/draft.d.ts +6 -0
- package/dist/draft.js +1 -1
- package/dist/import-page.cjs +109 -10
- package/dist/import-page.cjs.map +1 -1
- package/dist/import-page.d.cts +1 -1
- package/dist/import-page.d.ts +1 -1
- package/dist/import-page.js +1 -1
- package/dist/index.cjs +226 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -6
- package/dist/index.d.ts +71 -6
- package/dist/index.js +99 -152
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-2UORYZUZ.js.map +0 -1
- package/dist/chunk-MJRHEKPU.js.map +0 -1
|
@@ -62,6 +62,7 @@ var ALLOWED_ATTR = [
|
|
|
62
62
|
"class",
|
|
63
63
|
"style",
|
|
64
64
|
"role",
|
|
65
|
+
"contenteditable",
|
|
65
66
|
"alt",
|
|
66
67
|
"src",
|
|
67
68
|
"srcset",
|
|
@@ -143,8 +144,11 @@ function sanitizeHtml(html, opts = {}) {
|
|
|
143
144
|
return purify.sanitize(html, {
|
|
144
145
|
ALLOWED_TAGS,
|
|
145
146
|
ALLOWED_ATTR,
|
|
146
|
-
// Keep our slot marker even though data-* is otherwise dropped
|
|
147
|
-
|
|
147
|
+
// Keep our slot marker even though data-* is otherwise dropped, and
|
|
148
|
+
// keep `contenteditable` so the composer-detection heuristic can find
|
|
149
|
+
// div-based composers (Slack/PostHog/etc. fake the textarea with a
|
|
150
|
+
// contenteditable div). The distiller strips it later, after marking.
|
|
151
|
+
ADD_ATTR: ["data-tc-slot", "contenteditable"],
|
|
148
152
|
ALLOW_DATA_ATTR: false,
|
|
149
153
|
ALLOW_ARIA_ATTR: true,
|
|
150
154
|
FORBID_TAGS: [
|
|
@@ -254,10 +258,36 @@ var INLINE_PROPS = [
|
|
|
254
258
|
"gap",
|
|
255
259
|
"display",
|
|
256
260
|
"flex-direction",
|
|
261
|
+
"flex-wrap",
|
|
257
262
|
"align-items",
|
|
263
|
+
"align-self",
|
|
258
264
|
"justify-content",
|
|
265
|
+
"justify-self",
|
|
259
266
|
"box-shadow",
|
|
260
|
-
"opacity"
|
|
267
|
+
"opacity",
|
|
268
|
+
// Layout-bearing properties (added 2026-Q2 to fix Tailwind-style captures):
|
|
269
|
+
"width",
|
|
270
|
+
"max-width",
|
|
271
|
+
"min-width",
|
|
272
|
+
"height",
|
|
273
|
+
"max-height",
|
|
274
|
+
"min-height",
|
|
275
|
+
"flex",
|
|
276
|
+
"flex-grow",
|
|
277
|
+
"flex-shrink",
|
|
278
|
+
"flex-basis",
|
|
279
|
+
"position",
|
|
280
|
+
"top",
|
|
281
|
+
"right",
|
|
282
|
+
"bottom",
|
|
283
|
+
"left",
|
|
284
|
+
"z-index",
|
|
285
|
+
"overflow",
|
|
286
|
+
"overflow-x",
|
|
287
|
+
"overflow-y",
|
|
288
|
+
"white-space",
|
|
289
|
+
"overflow-wrap",
|
|
290
|
+
"word-break"
|
|
261
291
|
];
|
|
262
292
|
var HIDDEN_CLASS_RE = /\b(sr-only|visually-hidden|hidden)\b/;
|
|
263
293
|
function getWindow2(win) {
|
|
@@ -280,6 +310,25 @@ function isHidden(el, win) {
|
|
|
280
310
|
}
|
|
281
311
|
return false;
|
|
282
312
|
}
|
|
313
|
+
function pxValue(v) {
|
|
314
|
+
if (!v) return null;
|
|
315
|
+
const m = /^(-?\d+(?:\.\d+)?)px$/.exec(v.trim());
|
|
316
|
+
return m ? Number(m[1]) : null;
|
|
317
|
+
}
|
|
318
|
+
function normaliseDesktopMargins(decls, cs) {
|
|
319
|
+
const left = pxValue(cs.getPropertyValue("margin-left"));
|
|
320
|
+
const right = pxValue(cs.getPropertyValue("margin-right"));
|
|
321
|
+
if (left == null || right == null) return;
|
|
322
|
+
if (left < 24 || right < 24) return;
|
|
323
|
+
const ratio = Math.max(left, right) / Math.min(left, right);
|
|
324
|
+
if (ratio > 1.1) return;
|
|
325
|
+
const top = pxValue(cs.getPropertyValue("margin-top")) ?? 0;
|
|
326
|
+
const bot = pxValue(cs.getPropertyValue("margin-bottom")) ?? 0;
|
|
327
|
+
for (let i = decls.length - 1; i >= 0; i--) {
|
|
328
|
+
if (decls[i]?.startsWith("margin:")) decls.splice(i, 1);
|
|
329
|
+
}
|
|
330
|
+
decls.push(`margin: ${top}px auto ${bot}px`);
|
|
331
|
+
}
|
|
283
332
|
function inlineStyles(orig, clone, win) {
|
|
284
333
|
const cs = win.getComputedStyle?.(orig);
|
|
285
334
|
if (!cs) return;
|
|
@@ -289,6 +338,7 @@ function inlineStyles(orig, clone, win) {
|
|
|
289
338
|
if (v && v !== "none" && v !== "normal" && v.trim() !== "")
|
|
290
339
|
decls.push(`${prop}: ${v}`);
|
|
291
340
|
}
|
|
341
|
+
normaliseDesktopMargins(decls, cs);
|
|
292
342
|
if (decls.length) clone.setAttribute("style", decls.join("; "));
|
|
293
343
|
}
|
|
294
344
|
function pruneAndInline(orig, clone, win, inline, dropped) {
|
|
@@ -354,6 +404,10 @@ var TIME_TEXT_RE = /^\s*(\d{1,2}:\d{2}(\s?[ap]\.?m\.?)?|\d+\s*(m|min|h|hr|d|days
|
|
|
354
404
|
function classOf(el) {
|
|
355
405
|
return el.getAttribute("class") ?? "";
|
|
356
406
|
}
|
|
407
|
+
function stripContenteditable(el) {
|
|
408
|
+
if (el.hasAttribute("contenteditable")) el.removeAttribute("contenteditable");
|
|
409
|
+
for (const child of el.children) stripContenteditable(child);
|
|
410
|
+
}
|
|
357
411
|
function markSlot(el, slot, token) {
|
|
358
412
|
el.setAttribute(SLOT_ATTR, slot);
|
|
359
413
|
el.textContent = token;
|
|
@@ -425,12 +479,51 @@ function slotifyRow(row) {
|
|
|
425
479
|
}
|
|
426
480
|
return { html: row.outerHTML, detected };
|
|
427
481
|
}
|
|
428
|
-
var COMPOSER_RE = /\b(composer|compose|reply|message-?box|message-?input|input-?box|textbox|editor|prompt)\b/i;
|
|
482
|
+
var COMPOSER_RE = /\b(composer|compose|reply|message-?box|message-?input|input-?box|textbox|editor|prompt|chat-?input)\b/i;
|
|
483
|
+
var COMPOSER_ARIA_RE = /\b(compose|reply|message|prompt|input|chat)\b/i;
|
|
484
|
+
function blockAncestor(node, root) {
|
|
485
|
+
let cur = node;
|
|
486
|
+
while (cur.parentElement && cur.parentElement !== root) {
|
|
487
|
+
const parent = cur.parentElement;
|
|
488
|
+
const style = (parent.getAttribute("style") ?? "").toLowerCase();
|
|
489
|
+
if (/display\s*:\s*(flex|grid)/.test(style)) return parent;
|
|
490
|
+
cur = parent;
|
|
491
|
+
}
|
|
492
|
+
return cur;
|
|
493
|
+
}
|
|
429
494
|
function findComposer(root, exclude) {
|
|
430
|
-
const
|
|
495
|
+
const all = [...root.querySelectorAll("*")].filter(
|
|
431
496
|
(e) => !exclude.contains(e) && !e.contains(exclude)
|
|
432
497
|
);
|
|
433
|
-
|
|
498
|
+
const byAria = all.find((e) => {
|
|
499
|
+
const label = e.getAttribute("aria-label");
|
|
500
|
+
return label && COMPOSER_ARIA_RE.test(label);
|
|
501
|
+
});
|
|
502
|
+
if (byAria) return blockAncestor(byAria, root);
|
|
503
|
+
const byRole = all.find((e) => e.getAttribute("role") === "textbox");
|
|
504
|
+
if (byRole) return blockAncestor(byRole, root);
|
|
505
|
+
const byCe = all.find((e) => e.hasAttribute("contenteditable"));
|
|
506
|
+
if (byCe) return blockAncestor(byCe, root);
|
|
507
|
+
const byClass = all.find((e) => COMPOSER_RE.test(classOf(e)));
|
|
508
|
+
if (byClass) return byClass;
|
|
509
|
+
let cursor = exclude;
|
|
510
|
+
while (cursor && cursor !== root) {
|
|
511
|
+
let sib = cursor.nextElementSibling;
|
|
512
|
+
while (sib) {
|
|
513
|
+
const style = (sib.getAttribute("style") ?? "").toLowerCase();
|
|
514
|
+
const isBlock = !/display\s*:\s*inline/.test(style);
|
|
515
|
+
const hasButtonish = sib.querySelector(
|
|
516
|
+
"[role='button'], [contenteditable]"
|
|
517
|
+
);
|
|
518
|
+
const txt = (sib.textContent ?? "").trim();
|
|
519
|
+
if (isBlock && (hasButtonish || txt.length === 0 || txt.length < 200)) {
|
|
520
|
+
return sib;
|
|
521
|
+
}
|
|
522
|
+
sib = sib.nextElementSibling;
|
|
523
|
+
}
|
|
524
|
+
cursor = cursor.parentElement;
|
|
525
|
+
}
|
|
526
|
+
return null;
|
|
434
527
|
}
|
|
435
528
|
function emptyReport() {
|
|
436
529
|
return { found: false, detected: [], confidence: 0 };
|
|
@@ -502,7 +595,7 @@ function distill(root, opts = {}) {
|
|
|
502
595
|
if (composer) {
|
|
503
596
|
const c = composer.cloneNode(true);
|
|
504
597
|
c.setAttribute(SLOT_ATTR, "composer");
|
|
505
|
-
c
|
|
598
|
+
stripContenteditable(c);
|
|
506
599
|
c.textContent = "{{composer}}";
|
|
507
600
|
composerHtml = c.outerHTML;
|
|
508
601
|
detection.composer = {
|
|
@@ -515,6 +608,10 @@ function distill(root, opts = {}) {
|
|
|
515
608
|
"No composer detected \u2014 add one by hand if the skin needs it."
|
|
516
609
|
);
|
|
517
610
|
}
|
|
611
|
+
if (frameHtml)
|
|
612
|
+
frameHtml = frameHtml.replace(/\s+contenteditable="[^"]*"/g, "");
|
|
613
|
+
if (messageHtml)
|
|
614
|
+
messageHtml = messageHtml.replace(/\s+contenteditable="[^"]*"/g, "");
|
|
518
615
|
} else {
|
|
519
616
|
warnings.push(
|
|
520
617
|
"No repeating message row found \u2014 capture a tighter subtree around the thread."
|
|
@@ -532,17 +629,19 @@ function distill(root, opts = {}) {
|
|
|
532
629
|
name: opts.name ?? "Captured skin",
|
|
533
630
|
...opts.sourceUrl ? { sourceUrl: opts.sourceUrl } : {},
|
|
534
631
|
...opts.theme ? { theme: opts.theme } : {},
|
|
535
|
-
...canvas ? { canvas } : {}
|
|
632
|
+
...canvas ? { canvas } : {},
|
|
633
|
+
...opts.capturedAt ? { capturedAt: opts.capturedAt } : {}
|
|
536
634
|
},
|
|
537
635
|
slots: {
|
|
538
636
|
...frameHtml ? { frame: frameHtml } : {},
|
|
539
637
|
...messageHtml ? { message: messageHtml } : {},
|
|
540
638
|
...composerHtml ? { composer: composerHtml } : {}
|
|
541
639
|
},
|
|
542
|
-
css: "",
|
|
640
|
+
css: opts.css ?? "",
|
|
543
641
|
tokens,
|
|
544
642
|
detection,
|
|
545
|
-
warnings
|
|
643
|
+
warnings,
|
|
644
|
+
...opts.cssSkipped?.length ? { cssSkipped: opts.cssSkipped } : {}
|
|
546
645
|
};
|
|
547
646
|
}
|
|
548
647
|
function pathTo(root, target) {
|
|
@@ -564,6 +663,6 @@ function nodeAtPath(root, path) {
|
|
|
564
663
|
return node;
|
|
565
664
|
}
|
|
566
665
|
|
|
567
|
-
export {
|
|
568
|
-
//# sourceMappingURL=chunk-
|
|
569
|
-
//# sourceMappingURL=chunk-
|
|
666
|
+
export { distill, sanitizeHtml, scrubCss };
|
|
667
|
+
//# sourceMappingURL=chunk-4JQY5NEW.js.map
|
|
668
|
+
//# sourceMappingURL=chunk-4JQY5NEW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sanitize.ts","../src/tokens.ts","../src/distill.ts"],"names":["getWindow"],"mappings":";;;AAiBA,IAAM,YAAA,GAAe;AAAA,EACnB,KAAA;AAAA,EACA,MAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA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AAC3B,EAAA,KAAA,MAAW,KAAK,IAAA,EAAM;AACpB,IAAA,IAAI,CAAC,MAAM,OAAO,IAAA;AAClB,IAAA,IAAA,GAAO,IAAA,CAAK,QAAA,CAAS,CAAC,CAAA,IAAK,IAAA;AAAA,EAC7B;AACA,EAAA,OAAO,IAAA;AACT","file":"chunk-4JQY5NEW.js","sourcesContent":["import createDOMPurify from \"dompurify\";\n\n/**\n * Allowlist sanitizer for captured / imported HTML+CSS (PLAN §10). Captured\n * markup is **untrusted** — it can carry scripts, event handlers, hostile\n * `url(javascript:)` CSS, `data:text/html` payloads, and framed content. We do\n * not roll our own: the heavy lifting is a maintained, audited sanitizer\n * (DOMPurify), wrapped here with a strict allowlist and a CSS scrubber, and the\n * `TemplateSkinAdapter` *additionally* renders in a shadow root so a sanitizer\n * miss still can't reach the host page. Defense in depth, not a single gate.\n */\n\ninterface WindowLike {\n document: Document;\n}\n\n/** Tags we keep — pure presentational/structural HTML. No scripts, forms, media. */\nconst ALLOWED_TAGS = [\n \"div\",\n \"span\",\n \"p\",\n \"a\",\n \"b\",\n \"strong\",\n \"i\",\n \"em\",\n \"u\",\n \"s\",\n \"small\",\n \"sub\",\n \"sup\",\n \"br\",\n \"hr\",\n \"ul\",\n \"ol\",\n \"li\",\n \"img\",\n \"svg\",\n \"path\",\n \"g\",\n \"circle\",\n \"rect\",\n \"line\",\n \"polyline\",\n \"polygon\",\n \"ellipse\",\n \"defs\",\n \"use\",\n \"title\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"blockquote\",\n \"pre\",\n \"code\",\n \"time\",\n \"header\",\n \"footer\",\n \"section\",\n \"article\",\n \"aside\",\n \"nav\",\n \"figure\",\n \"figcaption\",\n \"table\",\n \"thead\",\n \"tbody\",\n \"tr\",\n \"td\",\n \"th\",\n];\n\n/**\n * Attributes we keep. `data-*` is dropped via `ALLOW_DATA_ATTR: false`, with the\n * single exception of our own `data-tc-slot` marker, which is re-allowed via\n * `ADD_ATTR` below so the slot contract survives a re-sanitize.\n */\nconst ALLOWED_ATTR = [\n \"class\",\n \"style\",\n \"role\",\n \"contenteditable\",\n \"alt\",\n \"src\",\n \"srcset\",\n \"width\",\n \"height\",\n \"dir\",\n \"title\",\n \"viewbox\",\n \"fill\",\n \"stroke\",\n \"stroke-width\",\n \"d\",\n \"points\",\n \"cx\",\n \"cy\",\n \"r\",\n \"x\",\n \"y\",\n \"x1\",\n \"x2\",\n \"y1\",\n \"y2\",\n \"rx\",\n \"ry\",\n \"transform\",\n \"xmlns\",\n \"href\",\n];\n\n/**\n * Strip CSS-level code execution and exfiltration vectors from a style string\n * (inline `style=\"\"` or a stylesheet body). Inline styles survive sanitize, so\n * this is where `expression()`, `url(javascript:)`, `@import`, `behavior:`, and\n * non-image `data:` URLs are removed.\n */\nexport function scrubCss(css: string): string {\n let out = css;\n // Hostile functions / properties.\n out = out.replace(/expression\\s*\\(/gi, \"/*blocked*/(\");\n out = out.replace(/-moz-binding\\s*:/gi, \"/*blocked*/:\");\n out = out.replace(/behavior\\s*:/gi, \"/*blocked*/:\");\n out = out.replace(/@import[^;]*;?/gi, \"/*blocked-import*/\");\n // url(...) targets: block scripting protocols and non-image data URLs.\n out = out.replace(/url\\(\\s*(['\"]?)([^)'\"]*)\\1\\s*\\)/gi, (whole, _q, uri) => {\n const u = String(uri).trim().toLowerCase();\n const blocked =\n u.startsWith(\"javascript:\") ||\n u.startsWith(\"vbscript:\") ||\n (u.startsWith(\"data:\") && !u.startsWith(\"data:image/\"));\n return blocked ? \"none\" : whole;\n });\n // Bare scripting protocols anywhere in the declaration.\n out = out.replace(/javascript:/gi, \"blocked:\");\n out = out.replace(/vbscript:/gi, \"blocked:\");\n return out;\n}\n\nfunction getWindow(win?: WindowLike): WindowLike {\n if (win) return win;\n if (typeof window !== \"undefined\") return window as unknown as WindowLike;\n throw new Error(\n \"sanitizeHtml requires a DOM window — pass { window } in non-browser environments.\",\n );\n}\n\nlet hooked: unknown = null;\n\ntype PurifyWindow = Parameters<typeof createDOMPurify>[0];\n\nfunction purifierFor(win: WindowLike): ReturnType<typeof createDOMPurify> {\n const purify = createDOMPurify(win as unknown as PurifyWindow);\n // Install hooks once per purifier instance.\n if (hooked !== purify) {\n purify.addHook(\"afterSanitizeAttributes\", (node) => {\n const el = node as Element;\n // Scrub inline styles for CSS hazards.\n const style = el.getAttribute?.(\"style\");\n if (style) el.setAttribute(\"style\", scrubCss(style));\n // Enforce image-only data: URLs on src.\n const src = el.getAttribute?.(\"src\");\n if (src) {\n const u = src.trim().toLowerCase();\n if (u.startsWith(\"data:\") && !u.startsWith(\"data:image/\")) {\n el.removeAttribute(\"src\");\n }\n }\n // Force links inert and safe — no navigation out of a simulation.\n if (el.tagName === \"A\") {\n el.removeAttribute(\"href\");\n el.setAttribute(\"role\", \"link\");\n }\n // target=_blank/opener hygiene (belt-and-braces; href already removed).\n if (el.getAttribute?.(\"target\")) el.removeAttribute(\"target\");\n });\n hooked = purify;\n }\n return purify;\n}\n\nexport interface SanitizeOptions {\n /** DOM window to use (required in Node; defaults to global `window`). */\n window?: WindowLike;\n}\n\n/**\n * Sanitize an untrusted HTML string to the capture allowlist. Returns inert,\n * presentational HTML safe to parse and slot-ify. Always pair with shadow-DOM\n * isolation at render time (`TemplateSkinAdapter`).\n */\nexport function sanitizeHtml(html: string, opts: SanitizeOptions = {}): string {\n const win = getWindow(opts.window);\n const purify = purifierFor(win);\n return purify.sanitize(html, {\n ALLOWED_TAGS,\n ALLOWED_ATTR,\n // Keep our slot marker even though data-* is otherwise dropped, and\n // keep `contenteditable` so the composer-detection heuristic can find\n // div-based composers (Slack/PostHog/etc. fake the textarea with a\n // contenteditable div). The distiller strips it later, after marking.\n ADD_ATTR: [\"data-tc-slot\", \"contenteditable\"],\n ALLOW_DATA_ATTR: false,\n ALLOW_ARIA_ATTR: true,\n FORBID_TAGS: [\n \"script\",\n \"style\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"form\",\n \"input\",\n \"button\",\n \"textarea\",\n \"select\",\n \"link\",\n \"meta\",\n \"base\",\n \"video\",\n \"audio\",\n \"source\",\n ],\n FORBID_ATTR: [\"srcdoc\", \"formaction\", \"xlink:href\"],\n }) as string;\n}\n","/**\n * Best-effort design-token extraction from the inline styles of a distilled\n * tree (PLAN §10). This is a starting palette for the skin author to rename and\n * curate — not an authoritative theme. We pull distinct colors (most-frequent\n * first), font families, border radii, and padding scales.\n */\n\ninterface Tokens {\n colors: Record<string, string>;\n fonts?: Record<string, string>;\n space?: Record<string, string>;\n radius?: Record<string, string>;\n}\n\nfunction parseStyle(style: string): Map<string, string> {\n const m = new Map<string, string>();\n for (const decl of style.split(\";\")) {\n const idx = decl.indexOf(\":\");\n if (idx === -1) continue;\n const prop = decl.slice(0, idx).trim().toLowerCase();\n const val = decl.slice(idx + 1).trim();\n if (prop && val) m.set(prop, val);\n }\n return m;\n}\n\nconst COLOR_RE = /(#[0-9a-f]{3,8}\\b|rgba?\\([^)]*\\)|hsla?\\([^)]*\\))/gi;\n\nexport function extractTokens(root: Element): Tokens {\n const colorFreq = new Map<string, number>();\n const fonts = new Set<string>();\n const radii = new Set<string>();\n const spaces = new Set<string>();\n\n const bump = (raw: string) => {\n const v = raw.trim();\n if (!v || v === \"transparent\" || v === \"inherit\" || v === \"currentcolor\")\n return;\n colorFreq.set(v, (colorFreq.get(v) ?? 0) + 1);\n };\n\n for (const el of [root, ...root.querySelectorAll(\"*\")]) {\n const style = el.getAttribute(\"style\");\n if (!style) continue;\n const decls = parseStyle(style);\n for (const [prop, val] of decls) {\n if (prop === \"color\" || prop.startsWith(\"background\")) {\n const matches = val.match(COLOR_RE);\n if (matches) for (const c of matches) bump(c);\n }\n if (prop === \"font-family\") fonts.add(val);\n if (prop === \"border-radius\") radii.add(val);\n if (prop === \"padding\" || prop === \"gap\") spaces.add(val);\n }\n }\n\n const colors: Record<string, string> = {};\n [...colorFreq.entries()]\n .sort((a, b) => b[1] - a[1])\n .slice(0, 12)\n .forEach(([c], i) => {\n colors[`color-${i + 1}`] = c;\n });\n\n const out: Tokens = { colors };\n if (fonts.size) {\n out.fonts = {};\n [...fonts].slice(0, 4).forEach((f, i) => {\n out.fonts![`font-${i + 1}`] = f;\n });\n }\n if (radii.size) {\n out.radius = {};\n [...radii].slice(0, 6).forEach((r, i) => {\n out.radius![`radius-${i + 1}`] = r;\n });\n }\n if (spaces.size) {\n out.space = {};\n [...spaces].slice(0, 8).forEach((s, i) => {\n out.space![`space-${i + 1}`] = s;\n });\n }\n return out;\n}\n","import { sanitizeHtml } from \"./sanitize.js\";\nimport { extractTokens } from \"./tokens.js\";\nimport type { SkinDraft, SlotReport } from \"./draft.js\";\n\n/**\n * The distiller (PLAN §10): given a chat-UI subtree, produce a sanitized,\n * slotted `SkinDraft`. The pipeline is\n *\n * clone → inline computed styles (live capture) → drop hidden/`data-*` →\n * sanitize (allowlist) → find the repeating message row → slot-ify\n * (author/avatar/body/time) → carve the frame chrome → find the composer →\n * extract tokens → report.\n *\n * Capture gets you ~80% of the way; the emitted `detection` report and\n * `warnings` tell the author exactly what to confirm by hand (the §10 quality\n * bar treats anything below the bar as \"draft only\", never a finished skin).\n * The function is DOM-agnostic — the extension passes a live element, the\n * saved-page importer passes a jsdom element.\n */\n\ninterface WindowLike {\n document: Document;\n getComputedStyle?: (el: Element) => CSSStyleDeclaration;\n}\n\nexport interface DistillOptions {\n /** DOM window (defaults to global `window`). Required in Node. */\n window?: WindowLike;\n /** Display name for the draft. */\n name?: string;\n sourceUrl?: string;\n theme?: \"light\" | \"dark\";\n /**\n * Inline computed styles from the live page so fidelity survives losing the\n * cascade. Off for saved-page import (the source CSS comes inline already).\n */\n inlineComputedStyles?: boolean;\n /**\n * Page CSS captured by `captureMatchedCss` to embed in the slot-template\n * renderer's shadow root. Without this, class-driven layout (Tailwind, CSS\n * modules) collapses because the captured class names lose their meaning.\n */\n css?: string;\n /** Stylesheets the CSS capture had to skip (CORS, parse errors). */\n cssSkipped?: string[];\n /**\n * Page context the capture was taken in. Forwarded into `meta.capturedAt`\n * so the renderer can expose `--captured-viewport-width` to authored CSS.\n */\n capturedAt?: {\n viewportWidth?: number;\n viewportHeight?: number;\n pixelRatio?: number;\n };\n}\n\n/** The slot-marker attribute the `TemplateSkinAdapter` keys off. */\nexport const SLOT_ATTR = \"data-tc-slot\";\n\n/**\n * Computed properties worth inlining. **Visual fidelity** (color, font,\n * border, padding, gap) plus **load-bearing layout** (width/max-width,\n * flex-grow/shrink/basis, position, overflow). The layout group used to be\n * omitted on the theory that \"we only want look, not frozen geometry\", but\n * modern apps drive layout from utility classes (Tailwind, CSS modules) and\n * those classes lose all meaning once they leave their stylesheet — without\n * the inlined layout properties, captures collapse into single-character\n * vertical columns when reflowed into a small canvas.\n */\nconst INLINE_PROPS = [\n \"color\",\n \"background-color\",\n \"background\",\n \"font-family\",\n \"font-size\",\n \"font-weight\",\n \"font-style\",\n \"line-height\",\n \"letter-spacing\",\n \"text-align\",\n \"text-transform\",\n \"border\",\n \"border-radius\",\n \"padding\",\n \"margin\",\n \"gap\",\n \"display\",\n \"flex-direction\",\n \"flex-wrap\",\n \"align-items\",\n \"align-self\",\n \"justify-content\",\n \"justify-self\",\n \"box-shadow\",\n \"opacity\",\n // Layout-bearing properties (added 2026-Q2 to fix Tailwind-style captures):\n \"width\",\n \"max-width\",\n \"min-width\",\n \"height\",\n \"max-height\",\n \"min-height\",\n \"flex\",\n \"flex-grow\",\n \"flex-shrink\",\n \"flex-basis\",\n \"position\",\n \"top\",\n \"right\",\n \"bottom\",\n \"left\",\n \"z-index\",\n \"overflow\",\n \"overflow-x\",\n \"overflow-y\",\n \"white-space\",\n \"overflow-wrap\",\n \"word-break\",\n];\n\nconst HIDDEN_CLASS_RE = /\\b(sr-only|visually-hidden|hidden)\\b/;\n\nfunction getWindow(win?: WindowLike): WindowLike {\n if (win) return win;\n if (typeof window !== \"undefined\") return window as unknown as WindowLike;\n throw new Error(\"distill requires a DOM window — pass { window } in Node.\");\n}\n\nfunction isHidden(el: Element, win: WindowLike): boolean {\n if (el.getAttribute(\"aria-hidden\") === \"true\") return true;\n if (el.hasAttribute(\"hidden\")) return true;\n const cls = el.getAttribute(\"class\") ?? \"\";\n if (HIDDEN_CLASS_RE.test(cls)) return true;\n const inline = (el.getAttribute(\"style\") ?? \"\").toLowerCase();\n if (/display\\s*:\\s*none/.test(inline)) return true;\n if (/visibility\\s*:\\s*hidden/.test(inline)) return true;\n const cs = win.getComputedStyle?.(el);\n if (cs) {\n if (cs.display === \"none\") return true;\n if (cs.visibility === \"hidden\") return true;\n }\n return false;\n}\n\n/**\n * Parse a pixel value (`\"234.5px\"` → 234.5; `\"auto\"`/`\"\"` → null). Used by\n * `normaliseDesktopMargins` to detect centering margins.\n */\nfunction pxValue(v: string | undefined): number | null {\n if (!v) return null;\n const m = /^(-?\\d+(?:\\.\\d+)?)px$/.exec(v.trim());\n return m ? Number(m[1]) : null;\n}\n\n/**\n * Captured pages run on desktop viewports, so a `mx-auto` ends up as\n * `margin-left: 234.5px; margin-right: 234.5px` once computed. Baked in\n * verbatim, that margin survives into a 480-px canvas and squeezes content\n * into a vertical column. When we see two horizontal margins that are\n * both > 24px and within 10% of each other, rewrite them to `margin: 0 auto`\n * (preserving top/bottom) so layout re-centers in any canvas size.\n */\nfunction normaliseDesktopMargins(\n decls: string[],\n cs: CSSStyleDeclaration,\n): void {\n const left = pxValue(cs.getPropertyValue(\"margin-left\"));\n const right = pxValue(cs.getPropertyValue(\"margin-right\"));\n if (left == null || right == null) return;\n if (left < 24 || right < 24) return;\n const ratio = Math.max(left, right) / Math.min(left, right);\n if (ratio > 1.1) return;\n const top = pxValue(cs.getPropertyValue(\"margin-top\")) ?? 0;\n const bot = pxValue(cs.getPropertyValue(\"margin-bottom\")) ?? 0;\n // Remove any margin entries we already pushed, then replace with the\n // responsive form so the captured layout re-centers fluidly.\n for (let i = decls.length - 1; i >= 0; i--) {\n if (decls[i]?.startsWith(\"margin:\")) decls.splice(i, 1);\n }\n decls.push(`margin: ${top}px auto ${bot}px`);\n}\n\nfunction inlineStyles(orig: Element, clone: Element, win: WindowLike): void {\n const cs = win.getComputedStyle?.(orig);\n if (!cs) return;\n const decls: string[] = [];\n for (const prop of INLINE_PROPS) {\n const v = cs.getPropertyValue(prop);\n if (v && v !== \"none\" && v !== \"normal\" && v.trim() !== \"\")\n decls.push(`${prop}: ${v}`);\n }\n normaliseDesktopMargins(decls, cs);\n if (decls.length) clone.setAttribute(\"style\", decls.join(\"; \"));\n}\n\n/** Recursively inline styles + drop hidden nodes, walking orig/clone in step. */\nfunction pruneAndInline(\n orig: Element,\n clone: Element,\n win: WindowLike,\n inline: boolean,\n dropped: { count: number },\n): void {\n if (inline) inlineStyles(orig, clone, win);\n // Strip data-* (defense-in-depth; sanitize also does this later).\n for (const attr of [...clone.attributes]) {\n if (attr.name.startsWith(\"data-\")) clone.removeAttribute(attr.name);\n }\n const origKids = [...orig.children];\n const cloneKids = [...clone.children];\n const remove: Element[] = [];\n for (let i = 0; i < origKids.length; i++) {\n const o = origKids[i];\n const c = cloneKids[i];\n if (!o || !c) continue;\n if (isHidden(o, win)) {\n remove.push(c);\n dropped.count++;\n continue;\n }\n pruneAndInline(o, c, win, inline, dropped);\n }\n for (const c of remove) c.remove();\n}\n\n/** A structural signature for grouping repeated rows. */\nfunction signature(el: Element): string {\n const tag = el.tagName.toLowerCase();\n const classes = (el.getAttribute(\"class\") ?? \"\")\n .split(/\\s+/)\n .filter(Boolean)\n .sort()\n .join(\".\");\n const kidTags = [...el.children]\n .map((c) => c.tagName.toLowerCase())\n .join(\",\");\n return `${tag}|${classes}|${kidTags}`;\n}\n\ninterface RepeatPick {\n container: Element;\n rows: Element[];\n}\n\n/** Find the container whose children are the most-repeated similar rows. */\nfunction findRepeatingRows(root: Element): RepeatPick | null {\n let best: RepeatPick | null = null;\n let bestScore = 0;\n const visit = (el: Element) => {\n const groups = new Map<string, Element[]>();\n for (const child of el.children) {\n const sig = signature(child);\n const arr = groups.get(sig) ?? [];\n arr.push(child);\n groups.set(sig, arr);\n }\n for (const rows of groups.values()) {\n if (rows.length < 2) continue;\n // Score: repetition count weighted by how much text the rows carry, so\n // a list of message bubbles beats e.g. a repeated row of icon buttons.\n const textLen = rows.reduce(\n (n, r) => n + (r.textContent ?? \"\").trim().length,\n 0,\n );\n const score = rows.length * 10 + Math.min(textLen, 400);\n if (score > bestScore) {\n bestScore = score;\n best = { container: el, rows };\n }\n }\n for (const child of el.children) visit(child);\n };\n visit(root);\n return best;\n}\n\nconst AUTHOR_RE =\n /\\b(name|author|sender|user|handle|username|display-?name)\\b/i;\nconst AVATAR_RE = /\\b(avatar|photo|userpic|profile-?pic|pic|gravatar)\\b/i;\nconst TIME_RE = /\\b(time|timestamp|date|ago|sent-?at)\\b/i;\nconst BODY_RE = /\\b(body|text|content|message|bubble|markdown|prose)\\b/i;\nconst TIME_TEXT_RE =\n /^\\s*(\\d{1,2}:\\d{2}(\\s?[ap]\\.?m\\.?)?|\\d+\\s*(m|min|h|hr|d|days?|hours?|minutes?)( ago)?|yesterday|today)\\s*$/i;\n\nfunction classOf(el: Element): string {\n return el.getAttribute(\"class\") ?? \"\";\n}\n\n/** Recursively drop `contenteditable` from a subtree (used after composer\n * detection — the attribute survives sanitize only to help detection and\n * shouldn't ship in the final slot templates). */\nfunction stripContenteditable(el: Element): void {\n if (el.hasAttribute(\"contenteditable\")) el.removeAttribute(\"contenteditable\");\n for (const child of el.children) stripContenteditable(child);\n}\n\nfunction markSlot(el: Element, slot: string, token: string): void {\n el.setAttribute(SLOT_ATTR, slot);\n el.textContent = token;\n}\n\n/** Identify and mark author/avatar/body/time inside a representative row. */\nfunction slotifyRow(row: Element): {\n html: string;\n detected: string[];\n} {\n const detected: string[] = [];\n const all = [...row.querySelectorAll(\"*\")];\n\n // Avatar: an <img> or an element whose class names it.\n let avatar =\n row.querySelector(\"img\") ??\n all.find((e) => AVATAR_RE.test(classOf(e))) ??\n null;\n if (avatar) {\n // Convert an <img> avatar into a styled container we can fill.\n if (avatar.tagName === \"IMG\") {\n const div = row.ownerDocument.createElement(\"div\");\n const cls = classOf(avatar);\n if (cls) div.setAttribute(\"class\", cls);\n const st = avatar.getAttribute(\"style\");\n if (st) div.setAttribute(\"style\", st);\n avatar.replaceWith(div);\n avatar = div;\n }\n markSlot(avatar, \"avatar\", \"{{avatar}}\");\n detected.push(\"avatar\");\n }\n\n // Author: a named element, else the first short bold-ish text run.\n let author = all.find(\n (e) =>\n e !== avatar &&\n AUTHOR_RE.test(classOf(e)) &&\n (e.textContent ?? \"\").trim(),\n );\n if (!author) {\n author = all.find((e) => {\n if (e === avatar || e.getAttribute(SLOT_ATTR)) return false;\n const t = (e.textContent ?? \"\").trim();\n const fw = (e.getAttribute(\"style\") ?? \"\").match(\n /font-weight:\\s*(\\d+|bold)/i,\n );\n const bold =\n e.tagName === \"B\" ||\n e.tagName === \"STRONG\" ||\n (fw ? fw[1] === \"bold\" || Number(fw[1]) >= 600 : false);\n return bold && t.length > 0 && t.length < 40;\n });\n }\n if (author && !author.getAttribute(SLOT_ATTR)) {\n markSlot(author, \"author\", \"{{author}}\");\n detected.push(\"author\");\n }\n\n // Time: a <time>, a named element, or an element whose text reads as a time.\n const time =\n row.querySelector(\"time\") ??\n all.find((e) => !e.getAttribute(SLOT_ATTR) && TIME_RE.test(classOf(e))) ??\n all.find(\n (e) =>\n !e.getAttribute(SLOT_ATTR) &&\n e.children.length === 0 &&\n TIME_TEXT_RE.test((e.textContent ?? \"\").trim()),\n );\n if (time && !time.getAttribute(SLOT_ATTR)) {\n markSlot(time, \"time\", \"{{time}}\");\n detected.push(\"time\");\n }\n\n // Body: the remaining element with the most text (or a named one). Never an\n // ancestor of an already-marked slot, or filling it would wipe author/time.\n const named = all.find(\n (e) =>\n !e.getAttribute(SLOT_ATTR) &&\n !e.querySelector(`[${SLOT_ATTR}]`) &&\n BODY_RE.test(classOf(e)),\n );\n let body = named ?? null;\n if (!body) {\n let bestLen = -1;\n for (const e of all) {\n if (e.getAttribute(SLOT_ATTR)) continue;\n if (e.querySelector(`[${SLOT_ATTR}]`)) continue; // don't pick an ancestor of a slot\n const t = (e.textContent ?? \"\").trim();\n if (t.length > bestLen) {\n bestLen = t.length;\n body = e;\n }\n }\n }\n if (body && !body.getAttribute(SLOT_ATTR)) {\n markSlot(body, \"body\", \"{{body}}\");\n detected.push(\"body\");\n } else if (!body) {\n // Fall back: slot the row itself.\n markSlot(row, \"body\", \"{{body}}\");\n detected.push(\"body\");\n }\n\n return { html: row.outerHTML, detected };\n}\n\nconst COMPOSER_RE =\n /\\b(composer|compose|reply|message-?box|message-?input|input-?box|textbox|editor|prompt|chat-?input)\\b/i;\nconst COMPOSER_ARIA_RE = /\\b(compose|reply|message|prompt|input|chat)\\b/i;\n\n/** Climb to the nearest container that *looks like* the composer outer block\n * (flex/grid parent, per its inlined `display:`), not the inner contenteditable.\n * Falls back to the node itself if no such ancestor exists below `root`. */\nfunction blockAncestor(node: Element, root: Element): Element {\n let cur: Element = node;\n while (cur.parentElement && cur.parentElement !== root) {\n const parent = cur.parentElement;\n const style = (parent.getAttribute(\"style\") ?? \"\").toLowerCase();\n if (/display\\s*:\\s*(flex|grid)/.test(style)) return parent;\n cur = parent;\n }\n return cur;\n}\n\n/**\n * Find the composer container in the sanitised frame tree. Priority order:\n * 1. `aria-label` matching `/compose|reply|message|prompt|input|chat/i`\n * 2. `[role=\"textbox\"]`\n * 3. ancestor of `[contenteditable]` (preserved through sanitise via the\n * sanitiser's ADD_ATTR list)\n * 4. class name matching the broadened composer regex\n * 5. structural — the next block sibling after the message list, or\n * walking up & forward\n * Returns null if none found; caller emits a draft warning.\n */\nfunction findComposer(root: Element, exclude: Element): Element | null {\n const all = [...root.querySelectorAll(\"*\")].filter(\n (e) => !exclude.contains(e) && !e.contains(exclude),\n );\n\n const byAria = all.find((e) => {\n const label = e.getAttribute(\"aria-label\");\n return label && COMPOSER_ARIA_RE.test(label);\n });\n if (byAria) return blockAncestor(byAria, root);\n\n const byRole = all.find((e) => e.getAttribute(\"role\") === \"textbox\");\n if (byRole) return blockAncestor(byRole, root);\n\n const byCe = all.find((e) => e.hasAttribute(\"contenteditable\"));\n if (byCe) return blockAncestor(byCe, root);\n\n const byClass = all.find((e) => COMPOSER_RE.test(classOf(e)));\n if (byClass) return byClass;\n\n // Structural fallback: the composer typically sits as a block after the\n // message list. Walk forward siblings, then walk up & forward again.\n let cursor: Element | null = exclude;\n while (cursor && cursor !== root) {\n let sib: Element | null = cursor.nextElementSibling;\n while (sib) {\n const style = (sib.getAttribute(\"style\") ?? \"\").toLowerCase();\n const isBlock = !/display\\s*:\\s*inline/.test(style);\n const hasButtonish = sib.querySelector(\n \"[role='button'], [contenteditable]\",\n );\n const txt = (sib.textContent ?? \"\").trim();\n if (isBlock && (hasButtonish || txt.length === 0 || txt.length < 200)) {\n return sib;\n }\n sib = sib.nextElementSibling;\n }\n cursor = cursor.parentElement;\n }\n\n return null;\n}\n\nfunction emptyReport(): SlotReport {\n return { found: false, detected: [], confidence: 0 };\n}\n\nexport function distill(root: Element, opts: DistillOptions = {}): SkinDraft {\n const win = getWindow(opts.window);\n const doc = win.document;\n const warnings: string[] = [];\n\n // 1. Clone, inline styles, drop hidden + data-*.\n const clone = root.cloneNode(true) as Element;\n const dropped = { count: 0 };\n pruneAndInline(root, clone, win, opts.inlineComputedStyles ?? false, dropped);\n if (dropped.count > 0)\n warnings.push(\n `Dropped ${dropped.count} hidden element(s) from the capture.`,\n );\n\n // 2. Sanitize (allowlist) and re-parse.\n const safe = sanitizeHtml(clone.outerHTML, { window: win });\n const host = doc.createElement(\"div\");\n host.innerHTML = safe;\n const frameRoot = (host.firstElementChild as Element | null) ?? host;\n\n // 3. Find the repeating message row.\n const pick = findRepeatingRows(frameRoot);\n const detection = {\n frame: emptyReport(),\n message: emptyReport(),\n composer: emptyReport(),\n typing: emptyReport(),\n };\n\n let messageHtml: string | undefined;\n let frameHtml: string | undefined;\n let composerHtml: string | undefined;\n\n if (pick) {\n // 4. Slot-ify a representative row.\n const sample = (pick.rows[0] as Element).cloneNode(true) as Element;\n const slotted = slotifyRow(sample);\n messageHtml = slotted.html;\n detection.message = {\n found: true,\n detected: slotted.detected,\n confidence: Math.min(1, slotted.detected.length / 4),\n };\n\n // 5. Carve the frame: replace the message list with a {{messages}} slot.\n const slot = doc.createElement(\"div\");\n slot.setAttribute(SLOT_ATTR, \"messages\");\n slot.textContent = \"{{messages}}\";\n const listCls = classOf(pick.container);\n if (listCls) slot.setAttribute(\"class\", `${listCls} tc-messages`);\n const containerClone = pick.container.cloneNode(false) as Element;\n // Preserve the list container's own styling, but it now holds only the slot.\n if (containerClone.getAttribute(\"style\"))\n slot.setAttribute(\n \"style\",\n containerClone.getAttribute(\"style\") as string,\n );\n // Build the frame by replacing the container subtree with the slot.\n const frameClone = frameRoot.cloneNode(true) as Element;\n const path = pathTo(frameRoot, pick.container);\n const targetInClone = path ? nodeAtPath(frameClone, path) : null;\n if (targetInClone && targetInClone.parentElement) {\n targetInClone.replaceWith(slot);\n frameHtml = frameClone.outerHTML;\n detection.frame = { found: true, detected: [\"messages\"], confidence: 1 };\n } else {\n // The list *is* the root; frame is just the slot.\n frameHtml = slot.outerHTML;\n detection.frame = {\n found: true,\n detected: [\"messages\"],\n confidence: 0.5,\n };\n warnings.push(\n \"Message list is the captured root; no surrounding chrome was found.\",\n );\n }\n\n // 6. Composer (outside the message list).\n const composer = findComposer(frameRoot, pick.container);\n if (composer) {\n const c = composer.cloneNode(true) as Element;\n c.setAttribute(SLOT_ATTR, \"composer\");\n stripContenteditable(c);\n c.textContent = \"{{composer}}\";\n composerHtml = c.outerHTML;\n detection.composer = {\n found: true,\n detected: [\"composer\"],\n confidence: 1,\n };\n } else {\n warnings.push(\n \"No composer detected — add one by hand if the skin needs it.\",\n );\n }\n // contenteditable was only kept through sanitize to help composer\n // detection; strip it from every output template so it doesn't ship.\n if (frameHtml)\n frameHtml = frameHtml.replace(/\\s+contenteditable=\"[^\"]*\"/g, \"\");\n if (messageHtml)\n messageHtml = messageHtml.replace(/\\s+contenteditable=\"[^\"]*\"/g, \"\");\n } else {\n warnings.push(\n \"No repeating message row found — capture a tighter subtree around the thread.\",\n );\n }\n\n // 7. Tokens.\n const tokens = extractTokens(frameRoot);\n\n // 8. Canvas suggestion from the captured box (best effort).\n let canvas: { width: number; height: number } | undefined;\n const rect = (\n root as Element & { getBoundingClientRect?: () => DOMRect }\n ).getBoundingClientRect?.();\n if (rect && rect.width > 0 && rect.height > 0) {\n canvas = { width: Math.round(rect.width), height: Math.round(rect.height) };\n }\n\n return {\n version: 1,\n meta: {\n name: opts.name ?? \"Captured skin\",\n ...(opts.sourceUrl ? { sourceUrl: opts.sourceUrl } : {}),\n ...(opts.theme ? { theme: opts.theme } : {}),\n ...(canvas ? { canvas } : {}),\n ...(opts.capturedAt ? { capturedAt: opts.capturedAt } : {}),\n },\n slots: {\n ...(frameHtml ? { frame: frameHtml } : {}),\n ...(messageHtml ? { message: messageHtml } : {}),\n ...(composerHtml ? { composer: composerHtml } : {}),\n },\n css: opts.css ?? \"\",\n tokens,\n detection,\n warnings,\n ...(opts.cssSkipped?.length ? { cssSkipped: opts.cssSkipped } : {}),\n };\n}\n\n/** Index path from `root` down to `target` (list of child indices). */\nfunction pathTo(root: Element, target: Element): number[] | null {\n if (root === target) return [];\n for (let i = 0; i < root.children.length; i++) {\n const child = root.children[i];\n if (!child) continue;\n const sub = pathTo(child, target);\n if (sub) return [i, ...sub];\n }\n return null;\n}\n\nfunction nodeAtPath(root: Element, path: number[]): Element | null {\n let node: Element | null = root;\n for (const i of path) {\n if (!node) return null;\n node = node.children[i] ?? null;\n }\n return node;\n}\n"]}
|
|
@@ -33,7 +33,18 @@ var skinDraftSchema = z.object({
|
|
|
33
33
|
/** Theme the capture was taken under, when known. */
|
|
34
34
|
theme: z.enum(["light", "dark"]).optional(),
|
|
35
35
|
/** Suggested canvas from the captured element's box. */
|
|
36
|
-
canvas: z.object({ width: z.number().int(), height: z.number().int() }).optional()
|
|
36
|
+
canvas: z.object({ width: z.number().int(), height: z.number().int() }).optional(),
|
|
37
|
+
/**
|
|
38
|
+
* Snapshot of the page context the draft was taken from. Used by the
|
|
39
|
+
* slot-template renderer to expose a `--captured-viewport-width` CSS
|
|
40
|
+
* variable so authored CSS can ratio-scale against the original
|
|
41
|
+
* viewport instead of the (much smaller) playback canvas.
|
|
42
|
+
*/
|
|
43
|
+
capturedAt: z.object({
|
|
44
|
+
viewportWidth: z.number().int().optional(),
|
|
45
|
+
viewportHeight: z.number().int().optional(),
|
|
46
|
+
pixelRatio: z.number().optional()
|
|
47
|
+
}).optional()
|
|
37
48
|
}),
|
|
38
49
|
/**
|
|
39
50
|
* Slotted, sanitized HTML per region. Elements carry inline `style`
|
|
@@ -62,7 +73,13 @@ var skinDraftSchema = z.object({
|
|
|
62
73
|
typing: slotReportSchema
|
|
63
74
|
}),
|
|
64
75
|
/** Human-readable warnings (hidden content dropped, slots missing, …). */
|
|
65
|
-
warnings: z.array(z.string())
|
|
76
|
+
warnings: z.array(z.string()),
|
|
77
|
+
/**
|
|
78
|
+
* Stylesheets the matched-CSS capture couldn't read (typically blocked by
|
|
79
|
+
* CORS). Informational — the slot template still renders, just without
|
|
80
|
+
* the rules those sheets defined.
|
|
81
|
+
*/
|
|
82
|
+
cssSkipped: z.array(z.string()).optional()
|
|
66
83
|
});
|
|
67
84
|
function detectionScore(draft) {
|
|
68
85
|
const checks = [
|
|
@@ -76,5 +93,5 @@ function detectionScore(draft) {
|
|
|
76
93
|
}
|
|
77
94
|
|
|
78
95
|
export { SLOT_TOKENS, detectionScore, skinDraftSchema, slotReportSchema };
|
|
79
|
-
//# sourceMappingURL=chunk-
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-TBLY4L5G.js.map
|
|
97
|
+
//# sourceMappingURL=chunk-TBLY4L5G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/draft.ts"],"names":[],"mappings":";;;AAiBO,I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,IACT,QAAA,EAAU,gBAAA;AAAA,IACV,MAAA,EAAQ;AAAA,GACT,CAAA;AAAA;AAAA,EAED,QAAA,EAAU,CAAA,CAAE,KAAA,CAAM,CAAA,CAAE,QAAQ,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM5B,YAAY,CAAA,CAAE,KAAA,CAAM,EAAE,MAAA,EAAQ,EAAE,QAAA;AAClC,CAAC;AAKM,SAAS,eAAe,KAAA,EAA0B;AAEvD,EAAA,MAAM,MAAA,GAAS;AAAA,IACb,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,MAAM,CAAA;AAAA,IAChD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,QAAQ,CAAA;AAAA,IAClD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,QAAQ,CAAA;AAAA,IAClD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,MAAM,CAAA;AAAA,IAChD,KAAA,CAAM,UAAU,QAAA,CAAS;AAAA,GAC3B;AACA,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,CAAE,SAAS,MAAA,CAAO,MAAA;AAChD","file":"chunk-TBLY4L5G.js","sourcesContent":["import { z } from \"zod\";\n\n/**\n * A `SkinDraft` is what the distiller emits from a captured chat UI: sanitized,\n * slotted HTML templates (with inline styles), extracted design tokens, and a\n * detection report describing what was auto-identified vs. what still needs a\n * human pass (PLAN §10). A draft is *not* a finished skin — `scaffold-skin`\n * turns one into an editable template-skin package, and the capture quality bar\n * (§10) decides whether it ships as a skin or stays \"draft only\".\n *\n * Slot tokens are double-brace placeholders the `TemplateSkinAdapter` fills:\n * frame: `{{messages}}` — where the message list mounts\n * message: `{{author}}` `{{avatar}}` `{{body}}` `{{time}}`\n * composer: `{{composer}}`\n * typing: `{{author}}`\n */\n\nexport const SLOT_TOKENS = {\n messages: \"{{messages}}\",\n author: \"{{author}}\",\n avatar: \"{{avatar}}\",\n body: \"{{body}}\",\n time: \"{{time}}\",\n composer: \"{{composer}}\",\n} as const;\n\nexport type SlotName = \"frame\" | \"message\" | \"composer\" | \"typing\";\n\n/** Per-slot detection outcome — drives the quality-bar metric (§10). */\nexport const slotReportSchema = z.object({\n /** Whether this region was found at all. */\n found: z.boolean(),\n /** Which inner slots were auto-detected (e.g. `[\"author\",\"body\"]`). */\n detected: z.array(z.string()),\n /** Heuristic confidence 0..1 for the auto-detection. */\n confidence: z.number().min(0).max(1),\n});\nexport type SlotReport = z.infer<typeof slotReportSchema>;\n\nconst tokenSetSchema = z.object({\n colors: z.record(z.string(), z.string()),\n fonts: z.record(z.string(), z.string()).optional(),\n space: z.record(z.string(), z.string()).optional(),\n radius: z.record(z.string(), z.string()).optional(),\n});\n\nexport const skinDraftSchema = z.object({\n version: z.literal(1),\n meta: z.object({\n /** Human label, defaulted from the source title/host. */\n name: z.string(),\n /** Source page URL, when known (informational only). */\n sourceUrl: z.string().optional(),\n /** Theme the capture was taken under, when known. */\n theme: z.enum([\"light\", \"dark\"]).optional(),\n /** Suggested canvas from the captured element's box. */\n canvas: z\n .object({ width: z.number().int(), height: z.number().int() })\n .optional(),\n /**\n * Snapshot of the page context the draft was taken from. Used by the\n * slot-template renderer to expose a `--captured-viewport-width` CSS\n * variable so authored CSS can ratio-scale against the original\n * viewport instead of the (much smaller) playback canvas.\n */\n capturedAt: z\n .object({\n viewportWidth: z.number().int().optional(),\n viewportHeight: z.number().int().optional(),\n pixelRatio: z.number().optional(),\n })\n .optional(),\n }),\n /**\n * Slotted, sanitized HTML per region. Elements carry inline `style`\n * attributes; `css` holds anything inline styles can't express.\n */\n slots: z.object({\n frame: z.string().optional(),\n message: z.string().optional(),\n composer: z.string().optional(),\n typing: z.string().optional(),\n }),\n /** Best-effort extra CSS (pseudo-elements, keyframes) — may be empty. */\n css: z.string(),\n /** Extracted design tokens (best effort) — the primary/captured theme. */\n tokens: tokenSetSchema,\n /**\n * Dark-theme tokens from a paired capture (M5.7 double-capture flow). When\n * present, the skin supports both themes and switches CSS vars by theme.\n */\n darkTokens: tokenSetSchema.optional(),\n /** Detection report per region. */\n detection: z.object({\n frame: slotReportSchema,\n message: slotReportSchema,\n composer: slotReportSchema,\n typing: slotReportSchema,\n }),\n /** Human-readable warnings (hidden content dropped, slots missing, …). */\n warnings: z.array(z.string()),\n /**\n * Stylesheets the matched-CSS capture couldn't read (typically blocked by\n * CORS). Informational — the slot template still renders, just without\n * the rules those sheets defined.\n */\n cssSkipped: z.array(z.string()).optional(),\n});\n\nexport type SkinDraft = z.infer<typeof skinDraftSchema>;\n\n/** Overall slot-detection ratio used by the §10 quality bar (0..1). */\nexport function detectionScore(draft: SkinDraft): number {\n // The five core slots: message-row found, author, avatar, body, composer.\n const checks = [\n draft.detection.message.detected.includes(\"body\"),\n draft.detection.message.detected.includes(\"author\"),\n draft.detection.message.detected.includes(\"avatar\"),\n draft.detection.message.detected.includes(\"time\"),\n draft.detection.composer.found,\n ];\n return checks.filter(Boolean).length / checks.length;\n}\n"]}
|
|
@@ -31,6 +31,23 @@ interface DistillOptions {
|
|
|
31
31
|
* cascade. Off for saved-page import (the source CSS comes inline already).
|
|
32
32
|
*/
|
|
33
33
|
inlineComputedStyles?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Page CSS captured by `captureMatchedCss` to embed in the slot-template
|
|
36
|
+
* renderer's shadow root. Without this, class-driven layout (Tailwind, CSS
|
|
37
|
+
* modules) collapses because the captured class names lose their meaning.
|
|
38
|
+
*/
|
|
39
|
+
css?: string;
|
|
40
|
+
/** Stylesheets the CSS capture had to skip (CORS, parse errors). */
|
|
41
|
+
cssSkipped?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Page context the capture was taken in. Forwarded into `meta.capturedAt`
|
|
44
|
+
* so the renderer can expose `--captured-viewport-width` to authored CSS.
|
|
45
|
+
*/
|
|
46
|
+
capturedAt?: {
|
|
47
|
+
viewportWidth?: number;
|
|
48
|
+
viewportHeight?: number;
|
|
49
|
+
pixelRatio?: number;
|
|
50
|
+
};
|
|
34
51
|
}
|
|
35
52
|
declare function distill(root: Element, opts?: DistillOptions): SkinDraft;
|
|
36
53
|
|
|
@@ -31,6 +31,23 @@ interface DistillOptions {
|
|
|
31
31
|
* cascade. Off for saved-page import (the source CSS comes inline already).
|
|
32
32
|
*/
|
|
33
33
|
inlineComputedStyles?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Page CSS captured by `captureMatchedCss` to embed in the slot-template
|
|
36
|
+
* renderer's shadow root. Without this, class-driven layout (Tailwind, CSS
|
|
37
|
+
* modules) collapses because the captured class names lose their meaning.
|
|
38
|
+
*/
|
|
39
|
+
css?: string;
|
|
40
|
+
/** Stylesheets the CSS capture had to skip (CORS, parse errors). */
|
|
41
|
+
cssSkipped?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Page context the capture was taken in. Forwarded into `meta.capturedAt`
|
|
44
|
+
* so the renderer can expose `--captured-viewport-width` to authored CSS.
|
|
45
|
+
*/
|
|
46
|
+
capturedAt?: {
|
|
47
|
+
viewportWidth?: number;
|
|
48
|
+
viewportHeight?: number;
|
|
49
|
+
pixelRatio?: number;
|
|
50
|
+
};
|
|
34
51
|
}
|
|
35
52
|
declare function distill(root: Element, opts?: DistillOptions): SkinDraft;
|
|
36
53
|
|
package/dist/draft.cjs
CHANGED
|
@@ -35,7 +35,18 @@ var skinDraftSchema = zod.z.object({
|
|
|
35
35
|
/** Theme the capture was taken under, when known. */
|
|
36
36
|
theme: zod.z.enum(["light", "dark"]).optional(),
|
|
37
37
|
/** Suggested canvas from the captured element's box. */
|
|
38
|
-
canvas: zod.z.object({ width: zod.z.number().int(), height: zod.z.number().int() }).optional()
|
|
38
|
+
canvas: zod.z.object({ width: zod.z.number().int(), height: zod.z.number().int() }).optional(),
|
|
39
|
+
/**
|
|
40
|
+
* Snapshot of the page context the draft was taken from. Used by the
|
|
41
|
+
* slot-template renderer to expose a `--captured-viewport-width` CSS
|
|
42
|
+
* variable so authored CSS can ratio-scale against the original
|
|
43
|
+
* viewport instead of the (much smaller) playback canvas.
|
|
44
|
+
*/
|
|
45
|
+
capturedAt: zod.z.object({
|
|
46
|
+
viewportWidth: zod.z.number().int().optional(),
|
|
47
|
+
viewportHeight: zod.z.number().int().optional(),
|
|
48
|
+
pixelRatio: zod.z.number().optional()
|
|
49
|
+
}).optional()
|
|
39
50
|
}),
|
|
40
51
|
/**
|
|
41
52
|
* Slotted, sanitized HTML per region. Elements carry inline `style`
|
|
@@ -64,7 +75,13 @@ var skinDraftSchema = zod.z.object({
|
|
|
64
75
|
typing: slotReportSchema
|
|
65
76
|
}),
|
|
66
77
|
/** Human-readable warnings (hidden content dropped, slots missing, …). */
|
|
67
|
-
warnings: zod.z.array(zod.z.string())
|
|
78
|
+
warnings: zod.z.array(zod.z.string()),
|
|
79
|
+
/**
|
|
80
|
+
* Stylesheets the matched-CSS capture couldn't read (typically blocked by
|
|
81
|
+
* CORS). Informational — the slot template still renders, just without
|
|
82
|
+
* the rules those sheets defined.
|
|
83
|
+
*/
|
|
84
|
+
cssSkipped: zod.z.array(zod.z.string()).optional()
|
|
68
85
|
});
|
|
69
86
|
function detectionScore(draft) {
|
|
70
87
|
const checks = [
|
package/dist/draft.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/draft.ts"],"names":["z"],"mappings":";;;;;AAiBO,IAAM,WAAA,GAAc;AAAA,EACzB,QAAA,EAAU,cAAA;AAAA,EACV,MAAA,EAAQ,YAAA;AAAA,EACR,MAAA,EAAQ,YAAA;AAAA,EACR,IAAA,EAAM,UAAA;AAAA,EACN,IAAA,EAAM,UAAA;AAAA,EACN,QAAA,EAAU;AACZ;AAKO,IAAM,gBAAA,GAAmBA,MAAE,MAAA,CAAO;AAAA;AAAA,EAEvC,KAAA,EAAOA,MAAE,OAAA,EAAQ;AAAA;AAAA,EAEjB,QAAA,EAAUA,KAAA,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AA,CAAQ,QAAA,CAAS,SAAS,MAAM,CAAA;AAAA,IAChD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,QAAQ,CAAA;AAAA,IAClD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,QAAQ,CAAA;AAAA,IAClD,KAAA,CAAM,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,SAAS,MAAM,CAAA;AAAA,IAChD,KAAA,CAAM,UAAU,QAAA,CAAS;AAAA,GAC3B;AACA,EAAA,OAAO,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA,CAAE,SAAS,MAAA,CAAO,MAAA;AAChD","file":"draft.cjs","sourcesContent":["import { z } from \"zod\";\n\n/**\n * A `SkinDraft` is what the distiller emits from a captured chat UI: sanitized,\n * slotted HTML templates (with inline styles), extracted design tokens, and a\n * detection report describing what was auto-identified vs. what still needs a\n * human pass (PLAN §10). A draft is *not* a finished skin — `scaffold-skin`\n * turns one into an editable template-skin package, and the capture quality bar\n * (§10) decides whether it ships as a skin or stays \"draft only\".\n *\n * Slot tokens are double-brace placeholders the `TemplateSkinAdapter` fills:\n * frame: `{{messages}}` — where the message list mounts\n * message: `{{author}}` `{{avatar}}` `{{body}}` `{{time}}`\n * composer: `{{composer}}`\n * typing: `{{author}}`\n */\n\nexport const SLOT_TOKENS = {\n messages: \"{{messages}}\",\n author: \"{{author}}\",\n avatar: \"{{avatar}}\",\n body: \"{{body}}\",\n time: \"{{time}}\",\n composer: \"{{composer}}\",\n} as const;\n\nexport type SlotName = \"frame\" | \"message\" | \"composer\" | \"typing\";\n\n/** Per-slot detection outcome — drives the quality-bar metric (§10). */\nexport const slotReportSchema = z.object({\n /** Whether this region was found at all. */\n found: z.boolean(),\n /** Which inner slots were auto-detected (e.g. `[\"author\",\"body\"]`). */\n detected: z.array(z.string()),\n /** Heuristic confidence 0..1 for the auto-detection. */\n confidence: z.number().min(0).max(1),\n});\nexport type SlotReport = z.infer<typeof slotReportSchema>;\n\nconst tokenSetSchema = z.object({\n colors: z.record(z.string(), z.string()),\n fonts: z.record(z.string(), z.string()).optional(),\n space: z.record(z.string(), z.string()).optional(),\n radius: z.record(z.string(), z.string()).optional(),\n});\n\nexport const skinDraftSchema = z.object({\n version: z.literal(1),\n meta: z.object({\n /** Human label, defaulted from the source title/host. */\n name: z.string(),\n /** Source page URL, when known (informational only). */\n sourceUrl: z.string().optional(),\n /** Theme the capture was taken under, when known. */\n theme: z.enum([\"light\", \"dark\"]).optional(),\n /** Suggested canvas from the captured element's box. */\n canvas: z\n .object({ width: z.number().int(), height: z.number().int() })\n .optional(),\n /**\n * Snapshot of the page context the draft was taken from. Used by the\n * slot-template renderer to expose a `--captured-viewport-width` CSS\n * variable so authored CSS can ratio-scale against the original\n * viewport instead of the (much smaller) playback canvas.\n */\n capturedAt: z\n .object({\n viewportWidth: z.number().int().optional(),\n viewportHeight: z.number().int().optional(),\n pixelRatio: z.number().optional(),\n })\n .optional(),\n }),\n /**\n * Slotted, sanitized HTML per region. Elements carry inline `style`\n * attributes; `css` holds anything inline styles can't express.\n */\n slots: z.object({\n frame: z.string().optional(),\n message: z.string().optional(),\n composer: z.string().optional(),\n typing: z.string().optional(),\n }),\n /** Best-effort extra CSS (pseudo-elements, keyframes) — may be empty. */\n css: z.string(),\n /** Extracted design tokens (best effort) — the primary/captured theme. */\n tokens: tokenSetSchema,\n /**\n * Dark-theme tokens from a paired capture (M5.7 double-capture flow). When\n * present, the skin supports both themes and switches CSS vars by theme.\n */\n darkTokens: tokenSetSchema.optional(),\n /** Detection report per region. */\n detection: z.object({\n frame: slotReportSchema,\n message: slotReportSchema,\n composer: slotReportSchema,\n typing: slotReportSchema,\n }),\n /** Human-readable warnings (hidden content dropped, slots missing, …). */\n warnings: z.array(z.string()),\n /**\n * Stylesheets the matched-CSS capture couldn't read (typically blocked by\n * CORS). Informational — the slot template still renders, just without\n * the rules those sheets defined.\n */\n cssSkipped: z.array(z.string()).optional(),\n});\n\nexport type SkinDraft = z.infer<typeof skinDraftSchema>;\n\n/** Overall slot-detection ratio used by the §10 quality bar (0..1). */\nexport function detectionScore(draft: SkinDraft): number {\n // The five core slots: message-row found, author, avatar, body, composer.\n const checks = [\n draft.detection.message.detected.includes(\"body\"),\n draft.detection.message.detected.includes(\"author\"),\n draft.detection.message.detected.includes(\"avatar\"),\n draft.detection.message.detected.includes(\"time\"),\n draft.detection.composer.found,\n ];\n return checks.filter(Boolean).length / checks.length;\n}\n"]}
|
package/dist/draft.d.cts
CHANGED
|
@@ -43,6 +43,11 @@ declare const skinDraftSchema: z.ZodObject<{
|
|
|
43
43
|
width: z.ZodNumber;
|
|
44
44
|
height: z.ZodNumber;
|
|
45
45
|
}, z.core.$strip>>;
|
|
46
|
+
capturedAt: z.ZodOptional<z.ZodObject<{
|
|
47
|
+
viewportWidth: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
viewportHeight: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
pixelRatio: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
46
51
|
}, z.core.$strip>;
|
|
47
52
|
slots: z.ZodObject<{
|
|
48
53
|
frame: z.ZodOptional<z.ZodString>;
|
|
@@ -86,6 +91,7 @@ declare const skinDraftSchema: z.ZodObject<{
|
|
|
86
91
|
}, z.core.$strip>;
|
|
87
92
|
}, z.core.$strip>;
|
|
88
93
|
warnings: z.ZodArray<z.ZodString>;
|
|
94
|
+
cssSkipped: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
95
|
}, z.core.$strip>;
|
|
90
96
|
type SkinDraft = z.infer<typeof skinDraftSchema>;
|
|
91
97
|
/** Overall slot-detection ratio used by the §10 quality bar (0..1). */
|
package/dist/draft.d.ts
CHANGED
|
@@ -43,6 +43,11 @@ declare const skinDraftSchema: z.ZodObject<{
|
|
|
43
43
|
width: z.ZodNumber;
|
|
44
44
|
height: z.ZodNumber;
|
|
45
45
|
}, z.core.$strip>>;
|
|
46
|
+
capturedAt: z.ZodOptional<z.ZodObject<{
|
|
47
|
+
viewportWidth: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
viewportHeight: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
pixelRatio: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
46
51
|
}, z.core.$strip>;
|
|
47
52
|
slots: z.ZodObject<{
|
|
48
53
|
frame: z.ZodOptional<z.ZodString>;
|
|
@@ -86,6 +91,7 @@ declare const skinDraftSchema: z.ZodObject<{
|
|
|
86
91
|
}, z.core.$strip>;
|
|
87
92
|
}, z.core.$strip>;
|
|
88
93
|
warnings: z.ZodArray<z.ZodString>;
|
|
94
|
+
cssSkipped: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
89
95
|
}, z.core.$strip>;
|
|
90
96
|
type SkinDraft = z.infer<typeof skinDraftSchema>;
|
|
91
97
|
/** Overall slot-detection ratio used by the §10 quality bar (0..1). */
|
package/dist/draft.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SLOT_TOKENS, detectionScore, skinDraftSchema, slotReportSchema } from './chunk-
|
|
1
|
+
export { SLOT_TOKENS, detectionScore, skinDraftSchema, slotReportSchema } from './chunk-TBLY4L5G.js';
|
|
2
2
|
//# sourceMappingURL=draft.js.map
|
|
3
3
|
//# sourceMappingURL=draft.js.map
|