@mushi-mushi/web 1.35.0 → 1.37.3

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.
@@ -1,8 +1,13 @@
1
1
  import { reporterStatus, fillReporterTemplate, reporterCopy, isReporterConversation, reporterTimelineEntryText } from '@mushi-mushi/core/reporter-ui';
2
2
  import '@mushi-mushi/core';
3
+ import '@mushi-mushi/core/diagnostics';
3
4
  import '@mushi-mushi/core/reporter-channels';
4
5
 
5
6
  var __defProp = Object.defineProperty;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -243,6 +248,591 @@ function crossAppView(ctx) {
243
248
  }
244
249
  var esc2, btn2, renderHeader2, chipLabel2, skeleton2, formatRelativeTime2, renderAppIconHtml2;
245
250
 
251
+ // src/capture/screenshot-dom.ts
252
+ var screenshot_dom_exports = {};
253
+ __export(screenshot_dom_exports, {
254
+ captureDomScreenshot: () => captureDomScreenshot
255
+ });
256
+ async function captureDomScreenshot(privacy, fail) {
257
+ const canvas = document.createElement("canvas");
258
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
259
+ if (!ctx) {
260
+ fail("unsupported");
261
+ return null;
262
+ }
263
+ const width = window.innerWidth;
264
+ const height = window.innerHeight;
265
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
266
+ canvas.width = width * dpr;
267
+ canvas.height = height * dpr;
268
+ ctx.scale(dpr, dpr);
269
+ const safeDocument = await buildPrivacySafeDocument(privacy);
270
+ const markup = new XMLSerializer().serializeToString(safeDocument).replace(XML_INVALID_CHARS, "");
271
+ const svgData = `
272
+ <svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}">
273
+ <foreignObject width="100%" height="100%">
274
+ <div xmlns="http://www.w3.org/1999/xhtml">
275
+ ${markup}
276
+ </div>
277
+ </foreignObject>
278
+ </svg>
279
+ `;
280
+ const img = new Image();
281
+ const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
282
+ let cspBlocked = false;
283
+ const onViolation = (e) => {
284
+ const v = e;
285
+ if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
286
+ };
287
+ document.addEventListener("securitypolicyviolation", onViolation);
288
+ return new Promise((resolve) => {
289
+ let settled = false;
290
+ const settle = (value, reason) => {
291
+ if (settled) return;
292
+ settled = true;
293
+ clearTimeout(timer);
294
+ document.removeEventListener("securitypolicyviolation", onViolation);
295
+ if (reason) fail(reason);
296
+ resolve(value);
297
+ };
298
+ const timer = setTimeout(() => settle(null, "timeout"), 5e3);
299
+ img.onload = () => {
300
+ try {
301
+ ctx.drawImage(img, 0, 0, width, height);
302
+ if (isCanvasBlank(ctx, width, height)) {
303
+ settle(null, "unsupported");
304
+ return;
305
+ }
306
+ settle(canvas.toDataURL("image/jpeg", 0.7));
307
+ } catch {
308
+ settle(null, "taint");
309
+ }
310
+ };
311
+ img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
312
+ img.src = url;
313
+ });
314
+ }
315
+ async function buildPrivacySafeDocument(privacy) {
316
+ const live = document.documentElement;
317
+ const clone = live.cloneNode(true);
318
+ const liveLinks = live.querySelectorAll("link");
319
+ const cloneLinks = clone.querySelectorAll("link");
320
+ const linkSlots = /* @__PURE__ */ new Map();
321
+ if (liveLinks.length === cloneLinks.length) liveLinks.forEach((l, i) => linkSlots.set(l, cloneLinks[i]));
322
+ const { offscreen, pins, backgrounds } = replayLiveState(live, clone);
323
+ fillScriptedStyleElements(live, clone);
324
+ const hidden = [
325
+ ALWAYS_REDACT_SELECTORS,
326
+ ...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS,
327
+ ...privacy?.maskSelectors ?? [],
328
+ ...privacy?.blockSelectors ?? []
329
+ ];
330
+ inlineMedia(
331
+ Array.from(live.querySelectorAll(MEDIA_SELECTOR)),
332
+ Array.from(clone.querySelectorAll(MEDIA_SELECTOR)));
333
+ pinOffscreen(pins);
334
+ await inlineBackgrounds(backgrounds.filter((bg) => !hidden.some((selector) => matchesOrInside(bg.live, selector))));
335
+ clone.querySelector("#mushi-mushi-widget")?.remove();
336
+ await inlineDocumentStyles(clone, linkSlots);
337
+ stripTaintSources(clone);
338
+ makeXmlSafe(clone);
339
+ freezeMotion(clone);
340
+ fillViewport(clone);
341
+ const redactSelectors = [
342
+ ALWAYS_REDACT_SELECTORS,
343
+ ...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
344
+ ];
345
+ for (const selector of redactSelectors) {
346
+ for (const el of safeQueryAll(clone, selector)) {
347
+ redactElement(el);
348
+ }
349
+ }
350
+ for (const selector of privacy?.blockSelectors ?? []) {
351
+ for (const el of safeQueryAll(clone, selector)) {
352
+ el.remove();
353
+ }
354
+ }
355
+ for (const selector of privacy?.maskSelectors ?? []) {
356
+ for (const el of safeQueryAll(clone, selector)) {
357
+ maskElement(el);
358
+ }
359
+ }
360
+ return clone;
361
+ }
362
+ function replayLiveState(live, clone) {
363
+ const offscreen = /* @__PURE__ */ new Set();
364
+ const pins = [];
365
+ const backgrounds = [];
366
+ const liveAll = [live, ...Array.from(live.querySelectorAll("*"))];
367
+ const cloneAll = [clone, ...Array.from(clone.querySelectorAll("*"))];
368
+ if (liveAll.length !== cloneAll.length) return { offscreen, pins, backgrounds };
369
+ const animated = animationTargets();
370
+ const styles = [];
371
+ const scroller = document.scrollingElement;
372
+ const pending = /* @__PURE__ */ new Map();
373
+ const set = (el, prop, value) => {
374
+ let decls = pending.get(el);
375
+ if (!decls) pending.set(el, decls = /* @__PURE__ */ new Map());
376
+ decls.set(prop, value);
377
+ };
378
+ const scrolled = [];
379
+ const withBackground = [];
380
+ let inBody = false;
381
+ for (let i = 0; i < liveAll.length; i++) {
382
+ const liveEl = liveAll[i];
383
+ const cloneEl = cloneAll[i];
384
+ const computed = getComputedStyle(liveEl);
385
+ styles.push(computed);
386
+ if (liveEl === document.body) inBody = true;
387
+ if (inBody) {
388
+ if (computed.display === "none") set(cloneEl, "display", "none");
389
+ else {
390
+ const parent = liveEl.parentElement;
391
+ if (computed.visibility !== "visible" && parent && getComputedStyle(parent).visibility === "visible") {
392
+ set(cloneEl, "visibility", computed.visibility);
393
+ }
394
+ if (computed.opacity === "0") set(cloneEl, "opacity", "0");
395
+ if (computed.backgroundImage.includes("url(")) withBackground.push(i);
396
+ }
397
+ }
398
+ if (animated.has(liveEl)) {
399
+ for (const p of ANIMATED_PROPERTIES) set(cloneEl, p, computed.getPropertyValue(p));
400
+ }
401
+ if (computed.position === "sticky" && liveEl instanceof HTMLElement) {
402
+ const offset = stickyOffset(liveEl);
403
+ if (offset) {
404
+ set(cloneEl, "position", "relative");
405
+ set(cloneEl, "top", `${offset.top}px`);
406
+ set(cloneEl, "left", `${offset.left}px`);
407
+ set(cloneEl, "bottom", "auto");
408
+ set(cloneEl, "right", "auto");
409
+ }
410
+ }
411
+ if (liveEl !== scroller && (liveEl.scrollTop > 0 || liveEl.scrollLeft > 0)) scrolled.push(i);
412
+ }
413
+ for (const i of scrolled) {
414
+ const liveEl = liveAll[i];
415
+ const liveKids = liveEl.children;
416
+ const cloneKids = cloneAll[i].children;
417
+ for (let j = 0; j < liveKids.length && j < cloneKids.length; j++) {
418
+ const kid = getComputedStyle(liveKids[j]);
419
+ if (kid.position === "fixed") continue;
420
+ const own = pending.get(cloneKids[j])?.get("transform") ?? kid.transform;
421
+ const shift = `translate(${-liveEl.scrollLeft}px, ${-liveEl.scrollTop}px)`;
422
+ set(cloneKids[j], "transform", own && own !== "none" ? `${shift} ${own}` : shift);
423
+ }
424
+ }
425
+ if (window.scrollX || window.scrollY) {
426
+ set(clone, "position", "relative");
427
+ set(clone, "top", `${-window.scrollY}px`);
428
+ set(clone, "left", `${-window.scrollX}px`);
429
+ }
430
+ for (const [el, decls] of pending) {
431
+ const held = Array.from(decls, ([p, v]) => `${p}:${v}!important`).join(";");
432
+ el.setAttribute("style", `${el.getAttribute("style") ?? ""};${held}`);
433
+ }
434
+ findOffscreen(liveAll, cloneAll, styles, offscreen, pins);
435
+ for (const i of withBackground) {
436
+ if (!offscreen.has(liveAll[i])) {
437
+ backgrounds.push({ live: liveAll[i], clone: cloneAll[i], value: styles[i].backgroundImage });
438
+ }
439
+ }
440
+ return { offscreen, pins, backgrounds };
441
+ }
442
+ async function inlineBackgrounds(backgrounds) {
443
+ const urls = /* @__PURE__ */ new Map();
444
+ let bytes = 0;
445
+ const load = (url) => {
446
+ let pending = urls.get(url);
447
+ if (!pending) {
448
+ pending = urls.size >= MAX_BACKGROUND_URLS ? Promise.resolve(null) : readAsDataUrl(url).then((data) => {
449
+ if (!data || bytes + data.length > MAX_BACKGROUND_BYTES) return null;
450
+ bytes += data.length;
451
+ return data;
452
+ });
453
+ urls.set(url, pending);
454
+ }
455
+ return pending;
456
+ };
457
+ await Promise.all(
458
+ backgrounds.map(async (bg) => {
459
+ const refs = Array.from(bg.value.matchAll(CSS_URL), (m) => m[2].trim()).filter((u) => !u.startsWith("data:"));
460
+ if (refs.length === 0) return;
461
+ const data = await Promise.all(refs.map(load));
462
+ let value = bg.value;
463
+ refs.forEach((ref, k) => {
464
+ if (data[k]) value = value.split(ref).join(data[k]);
465
+ });
466
+ if (value !== bg.value) {
467
+ bg.clone.setAttribute("style", `${bg.clone.getAttribute("style") ?? ""};background-image:${value}!important`);
468
+ }
469
+ })
470
+ );
471
+ }
472
+ async function readAsDataUrl(url) {
473
+ if (typeof fetch !== "function") return null;
474
+ const abort = typeof AbortController === "function" ? new AbortController() : null;
475
+ const timer = setTimeout(() => abort?.abort(), SHEET_FETCH_TIMEOUT_MS);
476
+ try {
477
+ const res = await fetch(url, { cache: "force-cache", signal: abort?.signal });
478
+ if (!res.ok) return null;
479
+ const blob = await res.blob();
480
+ if (blob.size > MAX_BACKGROUND_IMAGE_BYTES || !blob.type.startsWith("image/")) return null;
481
+ const bytes = new Uint8Array(await blob.arrayBuffer());
482
+ let binary = "";
483
+ for (let i = 0; i < bytes.length; i += 32768) {
484
+ binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
485
+ }
486
+ return `data:${blob.type};base64,${btoa(binary)}`;
487
+ } catch {
488
+ return null;
489
+ } finally {
490
+ clearTimeout(timer);
491
+ }
492
+ }
493
+ function findOffscreen(liveAll, cloneAll, styles, offscreen, pins) {
494
+ const bodyIndex = document.body ? liveAll.indexOf(document.body) : -1;
495
+ if (bodyIndex < 0) return;
496
+ const vw = window.innerWidth;
497
+ const vh = window.innerHeight;
498
+ const index = /* @__PURE__ */ new Map();
499
+ const visible = new Array(liveAll.length).fill(false);
500
+ const outside = new Array(liveAll.length).fill(false);
501
+ for (let i = bodyIndex; i < liveAll.length; i++) index.set(liveAll[i], i);
502
+ visible[bodyIndex] = true;
503
+ for (let i = liveAll.length - 1; i > bodyIndex; i--) {
504
+ const el = liveAll[i];
505
+ const r = el.getBoundingClientRect();
506
+ if (r.width > 0 || r.height > 0) {
507
+ if (r.bottom > 0 && r.top < vh && r.right > 0 && r.left < vw) visible[i] = true;
508
+ else outside[i] = true;
509
+ }
510
+ if (styles[i].position === "fixed") visible[i] = true;
511
+ if (visible[i]) {
512
+ outside[i] = false;
513
+ const parent = el.parentElement ? index.get(el.parentElement) : void 0;
514
+ if (parent !== void 0) visible[parent] = true;
515
+ } else if (outside[i]) {
516
+ offscreen.add(el);
517
+ }
518
+ }
519
+ const covered = new Array(liveAll.length).fill(false);
520
+ for (let i = bodyIndex + 1; i < liveAll.length; i++) {
521
+ const el = liveAll[i];
522
+ const parentIndex = el.parentElement ? index.get(el.parentElement) : void 0;
523
+ if (parentIndex === void 0) continue;
524
+ if (covered[parentIndex]) {
525
+ covered[i] = true;
526
+ continue;
527
+ }
528
+ if (!outside[i] || !(el instanceof HTMLElement)) continue;
529
+ const s = styles[i];
530
+ if (!PINNABLE_DISPLAY.test(s.display)) continue;
531
+ covered[i] = true;
532
+ const inFlow = BLOCK_FLOW.test(styles[parentIndex].display) && s.float === "none" && (s.position === "static" || s.position === "relative");
533
+ pins.push({
534
+ clone: cloneAll[i],
535
+ width: el.offsetWidth,
536
+ height: el.offsetHeight,
537
+ marginTop: inFlow ? gapAbove(el) : null,
538
+ marginBottom: inFlow ? gapBelow(el) : null
539
+ });
540
+ }
541
+ }
542
+ function gapAbove(el) {
543
+ const prev = el.previousElementSibling;
544
+ if (!(prev instanceof HTMLElement) || prev.offsetParent !== el.offsetParent) return null;
545
+ return Math.max(0, el.offsetTop - (prev.offsetTop + prev.offsetHeight));
546
+ }
547
+ function gapBelow(el) {
548
+ const next = el.nextElementSibling;
549
+ if (!(next instanceof HTMLElement) || next.offsetParent !== el.offsetParent) return null;
550
+ return Math.max(0, next.offsetTop - (el.offsetTop + el.offsetHeight));
551
+ }
552
+ function pinOffscreen(pins) {
553
+ for (const pin of pins) {
554
+ pin.clone.replaceChildren();
555
+ let pinned = `width:${pin.width}px!important;height:${pin.height}px!important;box-sizing:border-box!important;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;content-visibility:visible!important;contain:none!important;`;
556
+ if (pin.marginTop !== null) pinned += `margin-top:${pin.marginTop}px!important;`;
557
+ if (pin.marginBottom !== null) pinned += `margin-bottom:${pin.marginBottom}px!important;`;
558
+ pin.clone.setAttribute("style", `${pin.clone.getAttribute("style") ?? ""};${pinned}`);
559
+ }
560
+ }
561
+ function animationTargets() {
562
+ try {
563
+ return new Set(
564
+ document.getAnimations().map((a) => a.effect?.target).filter((t) => t instanceof Element && !t.pseudoElement)
565
+ );
566
+ } catch {
567
+ return /* @__PURE__ */ new Set();
568
+ }
569
+ }
570
+ function stickyOffset(el) {
571
+ const stuck = el.getBoundingClientRect();
572
+ const value = el.style.getPropertyValue("position");
573
+ const priority = el.style.getPropertyPriority("position");
574
+ el.style.setProperty("position", "static", "important");
575
+ const flow = el.getBoundingClientRect();
576
+ el.style.removeProperty("position");
577
+ if (value) el.style.setProperty("position", value, priority);
578
+ const top = stuck.top - flow.top;
579
+ const left = stuck.left - flow.left;
580
+ return top || left ? { top, left } : null;
581
+ }
582
+ function inlineMedia(liveMedia, clonedMedia, isHidden) {
583
+ let count = 0;
584
+ for (let i = 0; i < clonedMedia.length; i++) {
585
+ const cloned = clonedMedia[i];
586
+ const liveEl = liveMedia[i];
587
+ const rect = liveEl?.getBoundingClientRect();
588
+ const layout = liveEl instanceof HTMLElement && liveEl.offsetWidth > 0 ? { width: liveEl.offsetWidth, height: liveEl.offsetHeight } : rect && { width: rect.width, height: rect.height };
589
+ let pixels = null;
590
+ if (liveEl && layout && layout.width > 0 && layout.height > 0 && count < MAX_INLINED_MEDIA) ;
591
+ replaceMedia(cloned, pixels, layout);
592
+ }
593
+ }
594
+ function matchesOrInside(el, selector) {
595
+ try {
596
+ return el.closest(selector) !== null;
597
+ } catch {
598
+ return false;
599
+ }
600
+ }
601
+ function replaceMedia(cloned, pixels, layout) {
602
+ const box = cloned.ownerDocument.createElement("div");
603
+ for (const name of cloned.getAttributeNames()) {
604
+ if (!SOURCE_ATTRIBUTES.has(name)) box.setAttribute(name, cloned.getAttribute(name) ?? "");
605
+ }
606
+ const size = layout ? `width:${layout.width}px;height:${layout.height}px;` : "";
607
+ {
608
+ box.setAttribute(
609
+ "style",
610
+ `${box.getAttribute("style") ?? ""};${size}background:#d4d4d4!important;display:${cloned.tagName === "IMG" || cloned.tagName === "CANVAS" ? "inline-block" : "block"};`
611
+ );
612
+ }
613
+ const parent = cloned.parentElement;
614
+ const target = parent && parent.tagName === "PICTURE" ? parent : cloned;
615
+ target.replaceWith(box);
616
+ }
617
+ function makeXmlSafe(root) {
618
+ const doc = root.ownerDocument;
619
+ const walker = doc.createTreeWalker(root, NodeFilter.SHOW_COMMENT);
620
+ const comments = [];
621
+ for (let n = walker.nextNode(); n; n = walker.nextNode()) comments.push(n);
622
+ for (const c of comments) c.parentNode?.removeChild(c);
623
+ for (const el of [root, ...Array.from(root.querySelectorAll("*"))]) {
624
+ for (const name of el.getAttributeNames()) {
625
+ if (!XML_ATTRIBUTE_NAME.test(name)) el.removeAttribute(name);
626
+ }
627
+ }
628
+ }
629
+ function safeQueryAll(root, selector) {
630
+ try {
631
+ return Array.from(root.querySelectorAll(selector));
632
+ } catch {
633
+ return [];
634
+ }
635
+ }
636
+ function redactElement(el) {
637
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
638
+ el.value = "";
639
+ el.setAttribute("value", "");
640
+ }
641
+ el.textContent = "";
642
+ el.setAttribute(
643
+ "style",
644
+ `${el.getAttribute("style") ?? ""};background:#000!important;color:#000!important;text-shadow:none!important;border-color:#000!important;`
645
+ );
646
+ el.setAttribute("data-mushi-redacted", "true");
647
+ while (el.firstChild) el.removeChild(el.firstChild);
648
+ }
649
+ function stripTaintSources(root) {
650
+ const pageOrigin = typeof location !== "undefined" ? location.origin : "";
651
+ for (const link of root.querySelectorAll('link[rel="stylesheet"], link[as="style"]')) {
652
+ link.remove();
653
+ }
654
+ for (const styleEl of root.querySelectorAll("style")) {
655
+ const cleaned = stripCssUrlRefs(styleEl.textContent ?? "", pageOrigin);
656
+ if (cleaned !== styleEl.textContent) styleEl.textContent = cleaned;
657
+ }
658
+ for (const el of root.querySelectorAll("[style]")) {
659
+ const s = el.getAttribute("style");
660
+ if (!s) continue;
661
+ const cleaned = stripCssUrlRefs(s, pageOrigin);
662
+ if (cleaned !== s) el.setAttribute("style", cleaned);
663
+ }
664
+ for (const script of root.querySelectorAll("script, noscript, template")) {
665
+ script.remove();
666
+ }
667
+ }
668
+ function stripCssUrlRefs(css, pageOrigin) {
669
+ return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (_match, _q, href) => {
670
+ const trimmed = href.trim();
671
+ if (!trimmed || trimmed.startsWith("data:") || trimmed.startsWith("#")) return _match;
672
+ if (isCrossOriginUrl(trimmed, pageOrigin)) return "none";
673
+ return _match;
674
+ });
675
+ }
676
+ async function inlineDocumentStyles(clone, linkSlots) {
677
+ const sheets = [
678
+ ...Array.from(document.styleSheets),
679
+ ...document.adoptedStyleSheets ?? []
680
+ ];
681
+ const texts = await Promise.all(
682
+ sheets.map(async (sheet) => {
683
+ const owner = sheet.ownerNode;
684
+ if (sheet.disabled || owner instanceof Element && owner.tagName === "STYLE") return "";
685
+ return withMedia(await sheetSource(sheet) ?? serializeSheet(sheet), sheet);
686
+ })
687
+ );
688
+ const head = clone.querySelector("head") ?? clone;
689
+ sheets.forEach((sheet, i) => {
690
+ if (!texts[i]) return;
691
+ const styleEl = document.createElement("style");
692
+ styleEl.textContent = texts[i];
693
+ const slot = sheet.ownerNode ? linkSlots.get(sheet.ownerNode) : void 0;
694
+ if (slot && clone.contains(slot)) slot.replaceWith(styleEl);
695
+ else head.appendChild(styleEl);
696
+ });
697
+ }
698
+ async function sheetSource(sheet, depth = 0) {
699
+ const href = sheet.href;
700
+ if (!href || depth > 3 || typeof fetch !== "function") return null;
701
+ const abort = typeof AbortController === "function" ? new AbortController() : null;
702
+ const timer = setTimeout(() => abort?.abort(), SHEET_FETCH_TIMEOUT_MS);
703
+ try {
704
+ const res = await fetch(href, { cache: "force-cache", signal: abort?.signal });
705
+ if (!res.ok) return null;
706
+ let imported = "";
707
+ for (const rule of readableRules(sheet)) {
708
+ if (!(rule instanceof CSSImportRule) || !rule.styleSheet) continue;
709
+ const text = await sheetSource(rule.styleSheet, depth + 1) ?? serializeSheet(rule.styleSheet);
710
+ imported += wrapImport(text, rule);
711
+ }
712
+ const own = absolutizeCssUrls((await res.text()).replace(/@import\s[^;]*;/gi, ""), href);
713
+ return `${imported}
714
+ ${own}`;
715
+ } catch {
716
+ return null;
717
+ } finally {
718
+ clearTimeout(timer);
719
+ }
720
+ }
721
+ function readableRules(sheet) {
722
+ try {
723
+ return Array.from(sheet.cssRules);
724
+ } catch {
725
+ return [];
726
+ }
727
+ }
728
+ function wrapImport(text, rule) {
729
+ const layer = rule.layerName;
730
+ let out = layer == null ? text : `@layer ${layer}{${text}}`;
731
+ const media = rule.media?.mediaText;
732
+ if (media && media !== "all") out = `@media ${media}{${out}}`;
733
+ return `${out}
734
+ `;
735
+ }
736
+ function withMedia(text, sheet) {
737
+ const media = sheet.media?.mediaText;
738
+ return text && media && media !== "all" ? `@media ${media}{${text}}` : text;
739
+ }
740
+ function absolutizeCssUrls(css, base) {
741
+ return css.replace(/url\(\s*(['"]?)([^)'"]+)\1\s*\)/gi, (match, quote, ref) => {
742
+ const trimmed = ref.trim();
743
+ if (!trimmed || /^(data:|#|[a-z][a-z\d+.-]*:)/i.test(trimmed)) return match;
744
+ try {
745
+ return `url(${quote}${new URL(trimmed, base).href}${quote})`;
746
+ } catch {
747
+ return match;
748
+ }
749
+ });
750
+ }
751
+ function fillScriptedStyleElements(live, clone) {
752
+ const liveStyles = live.querySelectorAll("style");
753
+ const cloneStyles = clone.querySelectorAll("style");
754
+ if (liveStyles.length !== cloneStyles.length) return;
755
+ liveStyles.forEach((el, i) => {
756
+ if ((el.textContent ?? "").trim() || !el.sheet) return;
757
+ const text = serializeSheet(el.sheet);
758
+ if (text) cloneStyles[i].textContent = text;
759
+ });
760
+ }
761
+ function fillViewport(clone) {
762
+ const clear = (c) => !c || c === "transparent" || /^rgba\(.*,\s*0\)$/.test(c);
763
+ let bg = getComputedStyle(document.documentElement).backgroundColor;
764
+ if (clear(bg) && document.body) bg = getComputedStyle(document.body).backgroundColor;
765
+ const root = clone;
766
+ root.style.setProperty("background-color", clear(bg) ? "Canvas" : bg);
767
+ root.style.setProperty("min-height", `${window.innerHeight}px`);
768
+ }
769
+ function freezeMotion(clone) {
770
+ const styleEl = document.createElement("style");
771
+ styleEl.textContent = FREEZE_MOTION_CSS;
772
+ (clone.querySelector("head") ?? clone).appendChild(styleEl);
773
+ }
774
+ function serializeSheet(sheet) {
775
+ let rules;
776
+ try {
777
+ rules = sheet.cssRules;
778
+ } catch {
779
+ return "";
780
+ }
781
+ let text = "";
782
+ for (const rule of Array.from(rules)) {
783
+ if (rule instanceof CSSImportRule) {
784
+ if (rule.styleSheet) text += serializeSheet(rule.styleSheet);
785
+ continue;
786
+ }
787
+ text += `${rule.cssText}
788
+ `;
789
+ }
790
+ return text;
791
+ }
792
+ function isCanvasBlank(ctx, width, height) {
793
+ try {
794
+ const stepX = Math.max(1, Math.floor(width / 8));
795
+ const stepY = Math.max(1, Math.floor(height / 8));
796
+ for (let y = 0; y < height; y += stepY) {
797
+ for (let x = 0; x < width; x += stepX) {
798
+ if (ctx.getImageData(x, y, 1, 1).data[3] !== 0) return false;
799
+ }
800
+ }
801
+ return true;
802
+ } catch {
803
+ return false;
804
+ }
805
+ }
806
+ function isCrossOriginUrl(raw, pageOrigin) {
807
+ if (!raw || raw.startsWith("data:") || raw.startsWith("blob:")) return false;
808
+ try {
809
+ const resolved = new URL(raw, typeof location !== "undefined" ? location.href : "http://localhost/");
810
+ return Boolean(pageOrigin) && resolved.origin !== pageOrigin;
811
+ } catch {
812
+ return true;
813
+ }
814
+ }
815
+ function maskElement(el) {
816
+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
817
+ el.value = "";
818
+ el.setAttribute("value", "");
819
+ el.setAttribute("placeholder", "\u2022\u2022\u2022\u2022");
820
+ }
821
+ el.textContent = el.children.length === 0 ? "\u2022\u2022\u2022\u2022" : el.textContent;
822
+ el.setAttribute(
823
+ "style",
824
+ `${el.getAttribute("style") ?? ""};background:#8f8f8f!important;color:transparent!important;text-shadow:none!important;`
825
+ );
826
+ el.setAttribute("data-mushi-masked", "true");
827
+ }
828
+ var XML_INVALID_CHARS, XML_ATTRIBUTE_NAME, MAX_INLINED_MEDIA, MEDIA_SELECTOR, DEFAULT_REDACT_SELECTORS, ANIMATED_PROPERTIES, MAX_BACKGROUND_URLS, MAX_BACKGROUND_BYTES, MAX_BACKGROUND_IMAGE_BYTES, CSS_URL, PINNABLE_DISPLAY, BLOCK_FLOW, SOURCE_ATTRIBUTES, SHEET_FETCH_TIMEOUT_MS, FREEZE_MOTION_CSS;
829
+ var ALWAYS_REDACT_SELECTORS;
830
+ var init_screenshot = __esm({
831
+ "src/capture/screenshot.ts"() {
832
+ ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
833
+ }
834
+ });
835
+
246
836
  // src/journey-recording.ts
247
837
  var journey_recording_exports = {};
248
838
  __export(journey_recording_exports, {
@@ -459,6 +1049,12 @@ function createScreenshotAnnotation(imageDataUrl, container) {
459
1049
  });
460
1050
  }
461
1051
 
1052
+ // src/capture/index.ts
1053
+ init_screenshot();
1054
+
1055
+ // src/mushi.ts
1056
+ init_screenshot();
1057
+
462
1058
  // src/test-utils.ts
463
1059
  async function triggerBug(opts = {}) {
464
1060
  return null;