@mushi-mushi/web 1.37.0 → 1.38.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 CHANGED
@@ -44,7 +44,7 @@ Building in Lovable or Bolt with no terminal? A script tag works too: [Mushi Mus
44
44
  | **Privacy** | A built-in PII scrubber, selector masking for screenshots, and opt-in session replay. |
45
45
  | **Stays out of the way** | Zero-size host with `pointer-events: none`, keyboard-first, respects reduced motion. |
46
46
  | **Runtime config** | Change the widget from the console without a deploy. Values you set in code win. |
47
- | **Size** | CI caps the core bundle at 90.5 KB gzipped (105 KB uncompressed). Screenshot markup and the Your reports views load only when used. |
47
+ | **Size** | CI caps the core bundle at 89.2 KB gzipped (105 KB uncompressed). Screenshot capture, screenshot markup and the Your reports views load only when used. |
48
48
 
49
49
  ## Recipes
50
50
 
@@ -0,0 +1,35 @@
1
+ // src/capture/screenshot.ts
2
+ var ALWAYS_REDACT_SELECTORS = 'input[type="password"],input[autocomplete^="cc-"],[data-private],[data-mushi-mask]';
3
+ function createScreenshotCapture(options = {}) {
4
+ let activeOptions = options;
5
+ const fail = (reason) => {
6
+ activeOptions.onFailed?.(reason);
7
+ emitScreenshotFailed(reason);
8
+ };
9
+ async function take() {
10
+ try {
11
+ if (typeof document === "undefined") return null;
12
+ const { captureDomScreenshot } = await import('./screenshot-dom-K3N2HPNN.js');
13
+ return await captureDomScreenshot(activeOptions.privacy, fail);
14
+ } catch {
15
+ fail("error");
16
+ return null;
17
+ }
18
+ }
19
+ return {
20
+ take,
21
+ updateOptions(nextOptions) {
22
+ activeOptions = nextOptions;
23
+ }
24
+ };
25
+ }
26
+ function emitScreenshotFailed(reason) {
27
+ try {
28
+ document.dispatchEvent(new CustomEvent("mushi:screenshot_failed", { detail: { reason }, bubbles: false }));
29
+ } catch {
30
+ }
31
+ }
32
+
33
+ export { ALWAYS_REDACT_SELECTORS, createScreenshotCapture };
34
+ //# sourceMappingURL=chunk-ONXNS7MQ.js.map
35
+ //# sourceMappingURL=chunk-ONXNS7MQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/capture/screenshot.ts"],"names":[],"mappings":";AA6BO,IAAM,uBAAA,GAAyB;AAM/B,SAAS,uBAAA,CAAwB,OAAA,GAAoC,EAAC,EAAsB;AACjG,EAAA,IAAI,aAAA,GAAgB,OAAA;AAEpB,EAAA,MAAM,IAAA,GAAO,CAAC,MAAA,KAAoC;AAChD,IAAA,aAAA,CAAc,WAAW,MAAM,CAAA;AAC/B,IAAA,oBAAA,CAAqB,MAAM,CAAA;AAAA,EAC7B,CAAA;AAEA,EAAA,eAAe,IAAA,GAA+B;AAC5C,IAAA,IAAI;AACF,MAAA,IAAI,OAAO,QAAA,KAAa,WAAA,EAAa,OAAO,IAAA;AAC5C,MAAA,MAAM,EAAE,oBAAA,EAAqB,GAAI,MAAM,OAAO,8BAAkB,CAAA;AAChE,MAAA,OAAO,MAAM,oBAAA,CAAqB,aAAA,CAAc,OAAA,EAAS,IAAI,CAAA;AAAA,IAC/D,CAAA,CAAA,MAAQ;AACN,MAAA,IAAA,CAAK,OAAO,CAAA;AACZ,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,cAAc,WAAA,EAAa;AACzB,MAAA,aAAA,GAAgB,WAAA;AAAA,IAClB;AAAA,GACF;AACF;AAGA,SAAS,qBAAqB,MAAA,EAAuC;AACnE,EAAA,IAAI;AACF,IAAA,QAAA,CAAS,aAAA,CAAc,IAAI,WAAA,CAAY,yBAAA,EAA2B,EAAE,MAAA,EAAQ,EAAE,MAAA,EAAO,EAAG,OAAA,EAAS,KAAA,EAAO,CAAC,CAAA;AAAA,EAC3G,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"chunk-ONXNS7MQ.js","sourcesContent":["import type { MushiPrivacyConfig } from '@mushi-mushi/core';\n\nexport interface ScreenshotCapture {\n take(): Promise<string | null>;\n updateOptions(options: ScreenshotCaptureOptions): void;\n}\n\nexport interface ScreenshotCaptureOptions {\n privacy?: MushiPrivacyConfig;\n /** Callback invoked when capture fails (taint, security policy, etc.). */\n onFailed?: (reason: ScreenshotFailureReason) => void;\n}\n\n/**\n * Why a capture produced no image. Also the `detail.reason` of the\n * `mushi:screenshot_failed` document event.\n * - taint: cross-origin content made the canvas unreadable\n * - timeout: the SVG never loaded or errored within 5 s\n * - unsupported: no 2D canvas, or the engine rasterised nothing (WebKit)\n * - csp: the host's Content-Security-Policy img-src blocks data: images\n * - error: anything else\n */\nexport type ScreenshotFailureReason = 'taint' | 'timeout' | 'unsupported' | 'csp' | 'error';\n\n/**\n * Always blacked out of every screenshot — DOM capture and tab share alike —\n * before any pixel is produced. `redactSelectors` adds to this list and can't\n * remove from it: a host passing its own list used to drop password redaction.\n */\nexport const ALWAYS_REDACT_SELECTORS ='input[type=\"password\"],input[autocomplete^=\"cc-\"],[data-private],[data-mushi-mask]';\n\n/**\n * The capture code lives in ./screenshot-dom and loads on the first\n * screenshot, so a page that never takes one never downloads it.\n */\nexport function createScreenshotCapture(options: ScreenshotCaptureOptions = {}): ScreenshotCapture {\n let activeOptions = options;\n\n const fail = (reason: ScreenshotFailureReason) => {\n activeOptions.onFailed?.(reason);\n emitScreenshotFailed(reason);\n };\n\n async function take(): Promise<string | null> {\n try {\n if (typeof document === 'undefined') return null;\n const { captureDomScreenshot } = await import('./screenshot-dom');\n return await captureDomScreenshot(activeOptions.privacy, fail);\n } catch {\n fail('error');\n return null;\n }\n }\n\n return {\n take,\n updateOptions(nextOptions) {\n activeOptions = nextOptions;\n },\n };\n}\n\n/** Dispatch a CustomEvent on document so host apps can react to capture failures. */\nfunction emitScreenshotFailed(reason: ScreenshotFailureReason): void {\n try {\n document.dispatchEvent(new CustomEvent('mushi:screenshot_failed', { detail: { reason }, bubbles: false }));\n } catch {\n // Silently ignore if CustomEvent is not available (SSR/test env)\n }\n}\n"]}