@mushi-mushi/web 1.29.0 → 1.31.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/README.md +19 -5
- package/dist/chunks/display-capture-5ZJSTBUK.js +34 -0
- package/dist/chunks/display-capture-5ZJSTBUK.js.map +1 -0
- package/dist/chunks/screenshot-annotation-IG7C5B6Z.js +132 -0
- package/dist/chunks/screenshot-annotation-IG7C5B6Z.js.map +1 -0
- package/dist/chunks/widget-views-DX3OYHGR.js +233 -0
- package/dist/chunks/widget-views-DX3OYHGR.js.map +1 -0
- package/dist/headless.cjs +39 -13
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +1 -1
- package/dist/headless.d.ts +72 -2
- package/dist/headless.js +39 -13
- package/dist/headless.js.map +1 -1
- package/dist/i18n/index.cjs +178 -234
- package/dist/i18n/index.cjs.map +1 -1
- package/dist/i18n/index.d.cts +114 -32
- package/dist/i18n/index.d.ts +114 -32
- package/dist/i18n/index.js +178 -234
- package/dist/i18n/index.js.map +1 -1
- package/dist/index.cjs +2495 -4386
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +203 -181
- package/dist/index.d.ts +541 -183
- package/dist/index.js +2011 -4325
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +21 -2279
- package/dist/test-utils.cjs +410 -1
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.js +410 -1
- package/dist/test-utils.js.map +1 -1
- package/dist/{timeline-BuqAn2FH.d.cts → timeline-B8nMyZyM.d.cts} +12 -2
- package/package.json +19 -4
- package/dist/timeline-BuqAn2FH.d.ts +0 -63
package/dist/headless.cjs
CHANGED
|
@@ -349,8 +349,12 @@ function createScreenshotCapture(options = {}) {
|
|
|
349
349
|
try {
|
|
350
350
|
if (typeof document === "undefined") return null;
|
|
351
351
|
const canvas = document.createElement("canvas");
|
|
352
|
-
const ctx = canvas.getContext("2d");
|
|
353
|
-
if (!ctx)
|
|
352
|
+
const ctx = canvas.getContext("2d", { willReadFrequently: true });
|
|
353
|
+
if (!ctx) {
|
|
354
|
+
activeOptions.onFailed?.("unsupported");
|
|
355
|
+
emitScreenshotFailed("unsupported");
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
354
358
|
const width = window.innerWidth;
|
|
355
359
|
const height = window.innerHeight;
|
|
356
360
|
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
@@ -368,27 +372,32 @@ function createScreenshotCapture(options = {}) {
|
|
|
368
372
|
</svg>
|
|
369
373
|
`;
|
|
370
374
|
const img = new Image();
|
|
371
|
-
const
|
|
372
|
-
|
|
375
|
+
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgData)}`;
|
|
376
|
+
let cspBlocked = false;
|
|
377
|
+
const onViolation = (e) => {
|
|
378
|
+
const v = e;
|
|
379
|
+
if (/^img-src|^default-src/.test(v.violatedDirective ?? "") && /^data/.test(v.blockedURI ?? "")) cspBlocked = true;
|
|
380
|
+
};
|
|
381
|
+
document.addEventListener("securitypolicyviolation", onViolation);
|
|
373
382
|
return new Promise((resolve) => {
|
|
374
383
|
let settled = false;
|
|
375
384
|
const settle = (value, reason) => {
|
|
376
385
|
if (settled) return;
|
|
377
386
|
settled = true;
|
|
378
387
|
clearTimeout(timer);
|
|
379
|
-
|
|
388
|
+
document.removeEventListener("securitypolicyviolation", onViolation);
|
|
380
389
|
if (reason) {
|
|
381
390
|
activeOptions.onFailed?.(reason);
|
|
382
391
|
emitScreenshotFailed(reason);
|
|
383
392
|
}
|
|
384
393
|
resolve(value);
|
|
385
394
|
};
|
|
386
|
-
const timer = setTimeout(() => settle(null, "
|
|
395
|
+
const timer = setTimeout(() => settle(null, "timeout"), 5e3);
|
|
387
396
|
img.onload = () => {
|
|
388
397
|
try {
|
|
389
398
|
ctx.drawImage(img, 0, 0, width, height);
|
|
390
399
|
if (isCanvasBlank(ctx, width, height)) {
|
|
391
|
-
settle(null, "
|
|
400
|
+
settle(null, "unsupported");
|
|
392
401
|
return;
|
|
393
402
|
}
|
|
394
403
|
settle(canvas.toDataURL("image/jpeg", 0.7));
|
|
@@ -396,7 +405,7 @@ function createScreenshotCapture(options = {}) {
|
|
|
396
405
|
settle(null, "taint");
|
|
397
406
|
}
|
|
398
407
|
};
|
|
399
|
-
img.onerror = () => settle(null, "error");
|
|
408
|
+
img.onerror = () => setTimeout(() => settle(null, cspBlocked ? "csp" : "error"), 0);
|
|
400
409
|
img.src = url;
|
|
401
410
|
});
|
|
402
411
|
} catch {
|
|
@@ -418,16 +427,19 @@ function emitScreenshotFailed(reason) {
|
|
|
418
427
|
} catch {
|
|
419
428
|
}
|
|
420
429
|
}
|
|
421
|
-
var
|
|
422
|
-
|
|
423
|
-
"[data-mushi-redact]"
|
|
424
|
-
];
|
|
430
|
+
var ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
|
|
431
|
+
var DEFAULT_REDACT_SELECTORS = ["[data-mushi-redact]"];
|
|
425
432
|
function buildPrivacySafeDocument(privacy) {
|
|
426
433
|
const clone = document.documentElement.cloneNode(true);
|
|
427
434
|
clone.querySelector("#mushi-mushi-widget")?.remove();
|
|
428
435
|
stripTaintSources(clone);
|
|
429
436
|
inlineDocumentStyles(clone);
|
|
430
|
-
|
|
437
|
+
freezeMotion(clone);
|
|
438
|
+
fillViewport(clone);
|
|
439
|
+
const redactSelectors = [
|
|
440
|
+
ALWAYS_REDACT_SELECTORS,
|
|
441
|
+
...privacy?.redactSelectors ?? DEFAULT_REDACT_SELECTORS
|
|
442
|
+
];
|
|
431
443
|
for (const selector of redactSelectors) {
|
|
432
444
|
for (const el of safeQueryAll(clone, selector)) {
|
|
433
445
|
redactElement(el);
|
|
@@ -513,6 +525,20 @@ function inlineDocumentStyles(clone) {
|
|
|
513
525
|
styleEl.textContent = css;
|
|
514
526
|
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
515
527
|
}
|
|
528
|
+
var FREEZE_MOTION_CSS = "*,*::before,*::after{animation:none!important;transition:none!important}";
|
|
529
|
+
function fillViewport(clone) {
|
|
530
|
+
const clear = (c) => !c || c === "transparent" || /^rgba\(.*,\s*0\)$/.test(c);
|
|
531
|
+
let bg = getComputedStyle(document.documentElement).backgroundColor;
|
|
532
|
+
if (clear(bg) && document.body) bg = getComputedStyle(document.body).backgroundColor;
|
|
533
|
+
const root = clone;
|
|
534
|
+
root.style.setProperty("background-color", clear(bg) ? "Canvas" : bg);
|
|
535
|
+
root.style.setProperty("min-height", `${window.innerHeight}px`);
|
|
536
|
+
}
|
|
537
|
+
function freezeMotion(clone) {
|
|
538
|
+
const styleEl = document.createElement("style");
|
|
539
|
+
styleEl.textContent = FREEZE_MOTION_CSS;
|
|
540
|
+
(clone.querySelector("head") ?? clone).appendChild(styleEl);
|
|
541
|
+
}
|
|
516
542
|
function serializeSheet(sheet) {
|
|
517
543
|
let rules;
|
|
518
544
|
try {
|