@lyads/visual-editor 0.0.0-stage → 1.0.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/CHANGELOG.md +15 -0
- package/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +135 -2
- package/THIRD_PARTY_NOTICES.md +21259 -0
- package/dist/application/block-placement.d.ts +30 -0
- package/dist/application/block-session.d.ts +135 -0
- package/dist/application/content-service.d.ts +73 -0
- package/dist/application/document-commands.d.ts +51 -0
- package/dist/application/document-metadata.d.ts +30 -0
- package/dist/application/document-presentation.d.ts +35 -0
- package/dist/application/email-insertion.d.ts +76 -0
- package/dist/application/host.d.ts +36 -0
- package/dist/application/image-link.d.ts +36 -0
- package/dist/application/section-layout.d.ts +25 -0
- package/dist/application/session.d.ts +128 -0
- package/dist/assets/browser-worker-D56tNvnb.js +1014 -0
- package/dist/assets/browser-worker-D56tNvnb.js.map +1 -0
- package/dist/block-controller-RjYGvOcn.js +2468 -0
- package/dist/block-controller-RjYGvOcn.js.map +1 -0
- package/dist/block-factory-C5oHi4Fm.js +5397 -0
- package/dist/block-factory-C5oHi4Fm.js.map +1 -0
- package/dist/blocks/block-checks.d.ts +34 -0
- package/dist/blocks/block-inspector.d.ts +55 -0
- package/dist/blocks/block-output.d.ts +28 -0
- package/dist/blocks/block-type.d.ts +124 -0
- package/dist/blocks/content-guard.d.ts +52 -0
- package/dist/blocks/conversion.d.ts +22 -0
- package/dist/blocks/definitions.d.ts +43 -0
- package/dist/blocks/device-styles.d.ts +31 -0
- package/dist/blocks/email-generator.d.ts +22 -0
- package/dist/blocks/email-preview.d.ts +23 -0
- package/dist/blocks/email-renderer.d.ts +20 -0
- package/dist/blocks/fields.d.ts +34 -0
- package/dist/blocks/page-generator.d.ts +16 -0
- package/dist/blocks/render-context.d.ts +58 -0
- package/dist/blocks/styles.d.ts +54 -0
- package/dist/blocks/types/embed.d.ts +40 -0
- package/dist/blocks/types/layout.d.ts +41 -0
- package/dist/blocks/types/media.d.ts +53 -0
- package/dist/blocks/types/structure.d.ts +44 -0
- package/dist/blocks/types/text.d.ts +88 -0
- package/dist/blocks/values.d.ts +64 -0
- package/dist/browser.js +69 -0
- package/dist/browser.js.map +1 -0
- package/dist/canvas-runtime/action-bar.d.ts +19 -0
- package/dist/canvas-runtime/auto-scroll.d.ts +10 -0
- package/dist/canvas-runtime/block-drag.d.ts +29 -0
- package/dist/canvas-runtime/bridge.d.ts +6 -0
- package/dist/canvas-runtime/context.d.ts +53 -0
- package/dist/canvas-runtime/document-sync.d.ts +21 -0
- package/dist/canvas-runtime/drop-targets.d.ts +34 -0
- package/dist/canvas-runtime/embed-markers.d.ts +15 -0
- package/dist/canvas-runtime/file-guard.d.ts +12 -0
- package/dist/canvas-runtime/image-tools.d.ts +31 -0
- package/dist/canvas-runtime/keyboard.d.ts +18 -0
- package/dist/canvas-runtime/main.d.ts +1 -0
- package/dist/canvas-runtime/messages.d.ts +26 -0
- package/dist/canvas-runtime/morph.d.ts +21 -0
- package/dist/canvas-runtime/navigation.d.ts +29 -0
- package/dist/canvas-runtime/overlay.d.ts +15 -0
- package/dist/canvas-runtime/pointer-intents.d.ts +14 -0
- package/dist/canvas-runtime/selection-layer.d.ts +16 -0
- package/dist/canvas-runtime/shared/shortcuts.d.ts +27 -0
- package/dist/canvas-runtime/text-editor.d.ts +55 -0
- package/dist/canvas-runtime/text-session.d.ts +39 -0
- package/dist/canvas-runtime/variable-marks.d.ts +20 -0
- package/dist/canvas-runtime/viewport.d.ts +10 -0
- package/dist/codecs/css.d.ts +74 -0
- package/dist/codecs/html.d.ts +81 -0
- package/dist/compilation/browser-compiler.d.ts +14 -0
- package/dist/compilation/browser-worker.d.ts +1 -0
- package/dist/compilation/compile-lanes.d.ts +18 -0
- package/dist/compilation/generated-mjml.d.ts +25 -0
- package/dist/compilation/guard.d.ts +40 -0
- package/dist/compilation/node-compiler.d.ts +17 -0
- package/dist/compilation/node-worker.d.ts +1 -0
- package/dist/composition/block-factory.d.ts +84 -0
- package/dist/composition/browser.d.ts +48 -0
- package/dist/composition/factory.d.ts +48 -0
- package/dist/composition/server.d.ts +43 -0
- package/dist/core/any-document.d.ts +16 -0
- package/dist/core/block-document.d.ts +215 -0
- package/dist/core/budget.d.ts +32 -0
- package/dist/core/canvas-contract.d.ts +29 -0
- package/dist/core/canvas-layout.d.ts +66 -0
- package/dist/core/catalog.d.ts +35 -0
- package/dist/core/document-presentation.d.ts +21 -0
- package/dist/core/document.d.ts +99 -0
- package/dist/core/history.d.ts +26 -0
- package/dist/core/html-content-model.d.ts +32 -0
- package/dist/core/html-escape.d.ts +2 -0
- package/dist/core/rich-text-format.d.ts +14 -0
- package/dist/core/rich-text-markup.d.ts +28 -0
- package/dist/core/section-layout.d.ts +83 -0
- package/dist/generated-mjml-CtzE-f3v.js +1235 -0
- package/dist/generated-mjml-CtzE-f3v.js.map +1 -0
- package/dist/identity-CJHb6l9N.js +13759 -0
- package/dist/identity-CJHb6l9N.js.map +1 -0
- package/dist/renderers/canvas-bridge.d.ts +75 -0
- package/dist/renderers/canvas-icons.d.ts +1 -0
- package/dist/renderers/canvas-runtime.generated.d.ts +3 -0
- package/dist/renderers/element-source.d.ts +13 -0
- package/dist/renderers/email-renderer.d.ts +14 -0
- package/dist/renderers/marked-preview.d.ts +34 -0
- package/dist/renderers/markup-tree.d.ts +36 -0
- package/dist/renderers/page-renderer.d.ts +15 -0
- package/dist/renderers/preview-document.d.ts +39 -0
- package/dist/renderers/preview-frame.d.ts +102 -0
- package/dist/renderers/section-scaffold.d.ts +16 -0
- package/dist/renderers/selection-preview.d.ts +47 -0
- package/dist/rich-text/command-executor.d.ts +26 -0
- package/dist/rich-text/commands.d.ts +36 -0
- package/dist/rich-text/document-builder.d.ts +52 -0
- package/dist/rich-text/formatting.d.ts +17 -0
- package/dist/rich-text/projection-export.d.ts +17 -0
- package/dist/rich-text/projection-rules.d.ts +13 -0
- package/dist/rich-text/schema.d.ts +50 -0
- package/dist/rich-text/whitespace.d.ts +7 -0
- package/dist/security/bounded-parser.d.ts +18 -0
- package/dist/security/conditional-comment.d.ts +30 -0
- package/dist/security/content-inventory.d.ts +78 -0
- package/dist/security/email-sanitizer.d.ts +36 -0
- package/dist/security/identity.d.ts +6 -0
- package/dist/security/markup-rules.d.ts +31 -0
- package/dist/security/policy.d.ts +61 -0
- package/dist/security/preview-message.d.ts +317 -0
- package/dist/security/rich-text-projection.d.ts +19 -0
- package/dist/security/sha256.d.ts +6 -0
- package/dist/security/source-markup.d.ts +53 -0
- package/dist/security/text-presentation.d.ts +19 -0
- package/dist/security/url-policy.d.ts +23 -0
- package/dist/server-worker.js +17 -0
- package/dist/server-worker.js.map +1 -0
- package/dist/server.js +79 -0
- package/dist/server.js.map +1 -0
- package/dist/templates/blank-email.d.ts +6 -0
- package/dist/templates/blocks/catalog.d.ts +31 -0
- package/dist/templates/catalog.d.ts +31 -0
- package/dist/visual-editor.css +2 -0
- package/dist/vue/block-controller.d.ts +106 -0
- package/dist/vue/block-workbench.d.ts +70 -0
- package/dist/vue/canvas/canvas-theme.d.ts +8 -0
- package/dist/vue/canvas/file-drop.d.ts +38 -0
- package/dist/vue/canvas/frame-window.d.ts +26 -0
- package/dist/vue/canvas/inline-text.d.ts +98 -0
- package/dist/vue/canvas/palette-drag.d.ts +55 -0
- package/dist/vue/canvas/piece-requests.d.ts +48 -0
- package/dist/vue/canvas/strip-reserve.d.ts +14 -0
- package/dist/vue/canvas-content-label.d.ts +5 -0
- package/dist/vue/components/BlockVisualEditor.vue.d.ts +44 -0
- package/dist/vue/components/CanvasSurface.vue.d.ts +11 -0
- package/dist/vue/components/CodeEditor.vue.d.ts +22 -0
- package/dist/vue/components/EditorBlockMenus.vue.d.ts +3 -0
- package/dist/vue/components/EditorBlockPalette.vue.d.ts +3 -0
- package/dist/vue/components/EditorDiagnostics.vue.d.ts +3 -0
- package/dist/vue/components/EditorDialogs.vue.d.ts +16 -0
- package/dist/vue/components/EditorDocumentMetadata.vue.d.ts +3 -0
- package/dist/vue/components/EditorDocumentStyles.vue.d.ts +15 -0
- package/dist/vue/components/EditorImageSizeControls.vue.d.ts +23 -0
- package/dist/vue/components/EditorLayoutControls.vue.d.ts +16 -0
- package/dist/vue/components/EditorLeftPanel.vue.d.ts +3 -0
- package/dist/vue/components/EditorNoticeIndicator.vue.d.ts +3 -0
- package/dist/vue/components/EditorPreview.vue.d.ts +8 -0
- package/dist/vue/components/EditorProperties.vue.d.ts +14 -0
- package/dist/vue/components/EditorRichTextControls.vue.d.ts +25 -0
- package/dist/vue/components/EditorSelectionPath.vue.d.ts +11 -0
- package/dist/vue/components/EditorShortcutHelp.vue.d.ts +3 -0
- package/dist/vue/components/EditorSourcePane.vue.d.ts +3 -0
- package/dist/vue/components/EditorStructureTree.vue.d.ts +3 -0
- package/dist/vue/components/EditorTemplateGallery.vue.d.ts +15 -0
- package/dist/vue/components/EditorTopBar.vue.d.ts +33 -0
- package/dist/vue/components/RichTextEditor.vue.d.ts +47 -0
- package/dist/vue/components/SelectionPreviewFrame.vue.d.ts +212 -0
- package/dist/vue/components/VisualEditor.vue.d.ts +53 -0
- package/dist/vue/components/blocks/BlockCanvas.vue.d.ts +15 -0
- package/dist/vue/components/blocks/BlockFieldControl.vue.d.ts +39 -0
- package/dist/vue/components/blocks/BlockGlobalStyles.vue.d.ts +3 -0
- package/dist/vue/components/blocks/BlockPalette.vue.d.ts +6 -0
- package/dist/vue/components/blocks/BlockProperties.vue.d.ts +5 -0
- package/dist/vue/components/blocks/BlockReview.vue.d.ts +5 -0
- package/dist/vue/components/properties/EditorPropertyAdvanced.vue.d.ts +8 -0
- package/dist/vue/components/properties/EditorPropertyContent.vue.d.ts +13 -0
- package/dist/vue/components/properties/EditorPropertyStyle.vue.d.ts +8 -0
- package/dist/vue/components/ui/EditorAnchoredMenu.vue.d.ts +36 -0
- package/dist/vue/components/ui/EditorBadge.vue.d.ts +18 -0
- package/dist/vue/components/ui/EditorButton.vue.d.ts +28 -0
- package/dist/vue/components/ui/EditorCheckbox.vue.d.ts +13 -0
- package/dist/vue/components/ui/EditorColorInput.vue.d.ts +27 -0
- package/dist/vue/components/ui/EditorConfirmDialog.vue.d.ts +35 -0
- package/dist/vue/components/ui/EditorContextMenu.vue.d.ts +27 -0
- package/dist/vue/components/ui/EditorContextPopover.vue.d.ts +33 -0
- package/dist/vue/components/ui/EditorEmpty.vue.d.ts +8 -0
- package/dist/vue/components/ui/EditorField.vue.d.ts +24 -0
- package/dist/vue/components/ui/EditorGroup.vue.d.ts +16 -0
- package/dist/vue/components/ui/EditorIcon.vue.d.ts +6 -0
- package/dist/vue/components/ui/EditorIconButton.vue.d.ts +19 -0
- package/dist/vue/components/ui/EditorInput.vue.d.ts +41 -0
- package/dist/vue/components/ui/EditorKeys.vue.d.ts +6 -0
- package/dist/vue/components/ui/EditorMeasurement.vue.d.ts +34 -0
- package/dist/vue/components/ui/EditorMenu.vue.d.ts +56 -0
- package/dist/vue/components/ui/EditorNotice.vue.d.ts +30 -0
- package/dist/vue/components/ui/EditorPropertyGroup.vue.d.ts +22 -0
- package/dist/vue/components/ui/EditorRecoveryDialog.vue.d.ts +23 -0
- package/dist/vue/components/ui/EditorScrollArea.vue.d.ts +13 -0
- package/dist/vue/components/ui/EditorSelect.vue.d.ts +25 -0
- package/dist/vue/components/ui/EditorSeparator.vue.d.ts +8 -0
- package/dist/vue/components/ui/EditorSidePanel.vue.d.ts +26 -0
- package/dist/vue/components/ui/EditorSwitch.vue.d.ts +12 -0
- package/dist/vue/components/ui/EditorTabs.vue.d.ts +28 -0
- package/dist/vue/components/ui/EditorTemplatePreview.vue.d.ts +9 -0
- package/dist/vue/components/ui/EditorTextToolbar.vue.d.ts +16 -0
- package/dist/vue/components/ui/EditorTree.vue.d.ts +37 -0
- package/dist/vue/components/ui/EditorUiProvider.vue.d.ts +13 -0
- package/dist/vue/components/ui/EditorVariablePicker.vue.d.ts +20 -0
- package/dist/vue/components/ui/color-style-value.d.ts +9 -0
- package/dist/vue/components/ui/composition-dismissal.d.ts +1 -0
- package/dist/vue/components/ui/editor-dialog-focus.d.ts +6 -0
- package/dist/vue/components/ui/numeric-style-value.d.ts +15 -0
- package/dist/vue/controller.d.ts +115 -0
- package/dist/vue/font-options.d.ts +6 -0
- package/dist/vue/icon-data.d.ts +233 -0
- package/dist/vue/icons.d.ts +5 -0
- package/dist/vue/locale.d.ts +7 -0
- package/dist/vue/outline.d.ts +26 -0
- package/dist/vue/projection-key.d.ts +7 -0
- package/dist/vue/properties/selection-properties.d.ts +40 -0
- package/dist/vue/properties/style-fields.d.ts +30 -0
- package/dist/vue/public.d.ts +14 -0
- package/dist/vue/recovery.d.ts +30 -0
- package/dist/vue/responsive-panel.d.ts +1 -0
- package/dist/vue/rich-text-commands.d.ts +29 -0
- package/dist/vue/services/block-command-definitions.d.ts +14 -0
- package/dist/vue/services/block-commands.d.ts +114 -0
- package/dist/vue/services/block-menu.d.ts +12 -0
- package/dist/vue/services/block-palette.d.ts +21 -0
- package/dist/vue/services/block-presentation.d.ts +16 -0
- package/dist/vue/services/diagnostic-groups.d.ts +25 -0
- package/dist/vue/services/image-requests.d.ts +80 -0
- package/dist/vue/services/live-change.d.ts +26 -0
- package/dist/vue/services/property-commands.d.ts +28 -0
- package/dist/vue/services/saved-blocks.d.ts +32 -0
- package/dist/vue/services/selection-path.d.ts +20 -0
- package/dist/vue/services/shortcuts.d.ts +39 -0
- package/dist/vue/services/structure-tree.d.ts +38 -0
- package/dist/vue/services/template-application.d.ts +33 -0
- package/dist/vue/services/tree-drag.d.ts +28 -0
- package/dist/vue/session/blocks.d.ts +44 -0
- package/dist/vue/session/guard.d.ts +13 -0
- package/dist/vue/session/structure.d.ts +36 -0
- package/dist/vue/session/text.d.ts +23 -0
- package/dist/vue/session/transfer.d.ts +23 -0
- package/dist/vue/theme.d.ts +20 -0
- package/dist/vue/variables.d.ts +21 -0
- package/dist/vue/workbench.d.ts +100 -0
- package/dist/vue.js +71418 -0
- package/dist/vue.js.map +1 -0
- package/package.json +125 -4
|
@@ -0,0 +1,1235 @@
|
|
|
1
|
+
import { C as e, S as t, d as n, f as r, g as i, h as a, l as o, m as s, n as c, r as l, s as u, t as d, u as f, v as p, w as m, x as h, y as g } from "./identity-CJHb6l9N.js";
|
|
2
|
+
//#region src/security/markup-rules.ts
|
|
3
|
+
var _ = /* @__PURE__ */ new Set([
|
|
4
|
+
"iframe",
|
|
5
|
+
"object",
|
|
6
|
+
"embed",
|
|
7
|
+
"applet",
|
|
8
|
+
"frame",
|
|
9
|
+
"portal",
|
|
10
|
+
"fencedframe"
|
|
11
|
+
]), v = /* @__PURE__ */ new Set([
|
|
12
|
+
"href",
|
|
13
|
+
"src",
|
|
14
|
+
"action",
|
|
15
|
+
"formaction",
|
|
16
|
+
"background",
|
|
17
|
+
"poster",
|
|
18
|
+
"cite",
|
|
19
|
+
"longdesc",
|
|
20
|
+
"xlink:href",
|
|
21
|
+
"lowsrc",
|
|
22
|
+
"dynsrc",
|
|
23
|
+
"data",
|
|
24
|
+
"codebase",
|
|
25
|
+
"ping",
|
|
26
|
+
"manifest"
|
|
27
|
+
]), y = /* @__PURE__ */ new Set([
|
|
28
|
+
"set",
|
|
29
|
+
"animate",
|
|
30
|
+
"animatetransform",
|
|
31
|
+
"animatemotion",
|
|
32
|
+
"animatecolor"
|
|
33
|
+
]), b = [
|
|
34
|
+
"to",
|
|
35
|
+
"from",
|
|
36
|
+
"by",
|
|
37
|
+
"values"
|
|
38
|
+
], x = /^on(?:webkit|moz|ms|before|after)[a-z]+$/, S = new Set("abort activate afterprint afterscriptexecute afterupdate animationcancel animationend animationiteration animationstart auxclick beforeactivate beforecopy beforecut beforedeactivate beforeeditfocus beforeinput beforematch beforepaste beforeprint beforescriptexecute beforetoggle beforeunload beforeupdate begin blur bounce cancel canplay canplaythrough cellchange change click close command contentvisibilityautostatechange contextlost contextmenu contextrestored controlselect copy cuechange cut dataavailable datasetchanged datasetcomplete dblclick deactivate drag dragend dragenter dragexit dragleave dragover dragstart drop durationchange emptied end ended error errorupdate filterchange finish focus focusin focusout formdata fullscreenchange fullscreenerror gesturechange gestureend gesturestart gotpointercapture hashchange help input invalid keydown keypress keyup languagechange layoutcomplete load loadeddata loadedmetadata loadstart losecapture lostpointercapture message messageerror mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup mousewheel move moveend movestart offline online pagehide pagereveal pageshow pageswap paste pause play playing pointercancel pointerdown pointerenter pointerleave pointerlockchange pointerlockerror pointermove pointerout pointerover pointerrawupdate pointerup popstate progress propertychange ratechange readystatechange rejectionhandled repeat reset resize resizeend resizestart rowenter rowexit rowsdelete rowsinserted scroll scrollend scrollsnapchange scrollsnapchanging search securitypolicyviolation seeked seeking select selectionchange selectstart show slotchange stalled start stop storage submit suspend timeupdate toggle touchcancel touchend touchmove touchstart transitioncancel transitionend transitionrun transitionstart unhandledrejection unload volumechange waiting webkitanimationend webkitanimationiteration webkitanimationstart webkitfullscreenchange webkitfullscreenerror webkittransitionend wheel zoom".split(" ").map((e) => `on${e}`)), C = class {
|
|
39
|
+
urls;
|
|
40
|
+
constructor(e = new u()) {
|
|
41
|
+
this.urls = e;
|
|
42
|
+
}
|
|
43
|
+
element(e) {
|
|
44
|
+
let t = e.toLowerCase();
|
|
45
|
+
return t === "script" ? "script" : _.has(t) ? "embed" : void 0;
|
|
46
|
+
}
|
|
47
|
+
elementWith(e, t) {
|
|
48
|
+
let n = e.toLowerCase(), r = Object.create(null);
|
|
49
|
+
for (let [e, n] of Object.entries(t)) r[e.toLowerCase()] = n;
|
|
50
|
+
if (n === "link" && (r.rel ?? "").toLowerCase().split(/\s+/).includes("import")) return "embed";
|
|
51
|
+
if (n === "meta" && (r["http-equiv"] ?? "").trim().toLowerCase() === "refresh") {
|
|
52
|
+
let e = r.content ?? "", t = e.search(/[;,]/), n = t < 0 ? "" : e.slice(t + 1).trim();
|
|
53
|
+
return /^url\s*=/i.test(n) && (n = n.slice(n.indexOf("=") + 1).trim()), n = n.replace(/^['"]/, ""), this.urls.isActive(n) ? "url" : void 0;
|
|
54
|
+
}
|
|
55
|
+
if (y.has(n) && ["href", "xlink:href"].includes((r.attributename ?? "").trim().toLowerCase()) && b.some((e) => (r[e] ?? "").split(";").some((e) => this.urls.isActive(e)))) return "url";
|
|
56
|
+
}
|
|
57
|
+
navigation(e, t) {
|
|
58
|
+
let n = e.toLowerCase();
|
|
59
|
+
if (n === "base") return "url";
|
|
60
|
+
if (n === "meta") return (Object.entries(t).find(([e]) => e.toLowerCase() === "http-equiv")?.[1])?.trim().toLowerCase() === "refresh" ? "url" : void 0;
|
|
61
|
+
}
|
|
62
|
+
attribute(e, t) {
|
|
63
|
+
let n = e.toLowerCase();
|
|
64
|
+
return S.has(n) || x.test(n) ? "handler" : v.has(n) && this.urls.isActive(t) ? "url" : void 0;
|
|
65
|
+
}
|
|
66
|
+
handlerLike(e) {
|
|
67
|
+
let t = e.toLowerCase();
|
|
68
|
+
return t.length < 3 || !t.startsWith("on") ? !1 : [...t.slice(2)].every((e) => e >= "a" && e <= "z");
|
|
69
|
+
}
|
|
70
|
+
urlPurpose(e) {
|
|
71
|
+
let t = e.toLowerCase();
|
|
72
|
+
if (v.has(t)) return [
|
|
73
|
+
"src",
|
|
74
|
+
"background",
|
|
75
|
+
"poster",
|
|
76
|
+
"lowsrc",
|
|
77
|
+
"dynsrc"
|
|
78
|
+
].includes(t) ? "image" : "link";
|
|
79
|
+
}
|
|
80
|
+
}, w = Object.freeze({
|
|
81
|
+
noscript: "html",
|
|
82
|
+
noembed: "html",
|
|
83
|
+
noframes: "html",
|
|
84
|
+
template: "html",
|
|
85
|
+
svg: "svg",
|
|
86
|
+
math: "math"
|
|
87
|
+
});
|
|
88
|
+
function T(e) {
|
|
89
|
+
return e.trimStart().toLowerCase().startsWith("[if");
|
|
90
|
+
}
|
|
91
|
+
var E = /* @__PURE__ */ new Set(["script", "iframe"]), D = 4, O = class {
|
|
92
|
+
rules;
|
|
93
|
+
styles;
|
|
94
|
+
#e = new c();
|
|
95
|
+
constructor(e = new C(), t) {
|
|
96
|
+
this.rules = e, this.styles = t;
|
|
97
|
+
}
|
|
98
|
+
elements(e, t = "html") {
|
|
99
|
+
return this.walk(e, t, !1)?.map((e) => ({
|
|
100
|
+
tag: e.tagName,
|
|
101
|
+
attrs: Object.fromEntries(e.attrs.map((e) => [this.name(e), e.value])),
|
|
102
|
+
text: e.childNodes.map((e) => r.isTextNode(e) ? e.value : "").join("")
|
|
103
|
+
})) ?? [];
|
|
104
|
+
}
|
|
105
|
+
strip(e, t = "html") {
|
|
106
|
+
let n = e, r = [];
|
|
107
|
+
for (let e = 0; e < D; e++) {
|
|
108
|
+
let e = this.cuts(n, t);
|
|
109
|
+
if (!e) return;
|
|
110
|
+
if (!e.length) return {
|
|
111
|
+
source: n,
|
|
112
|
+
removed: r
|
|
113
|
+
};
|
|
114
|
+
let i = [];
|
|
115
|
+
for (let t of [...e].sort((e, t) => e.start - t.start)) {
|
|
116
|
+
let e = i.at(-1);
|
|
117
|
+
e && t.start < e.end ? i[i.length - 1] = {
|
|
118
|
+
...e,
|
|
119
|
+
end: Math.max(e.end, t.end)
|
|
120
|
+
} : i.push(t);
|
|
121
|
+
}
|
|
122
|
+
let a = "", o = 0;
|
|
123
|
+
for (let e of i) a += n.slice(o, e.start), o = e.end, r.push(e.kind);
|
|
124
|
+
n = a + n.slice(o);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
cuts(e, t) {
|
|
128
|
+
let n = this.walk(e, t, !0);
|
|
129
|
+
if (!n) return;
|
|
130
|
+
let r = [];
|
|
131
|
+
for (let e of n) {
|
|
132
|
+
let t = e.sourceCodeLocation, n = this.rules.element(e.tagName) ?? this.rules.elementWith(e.tagName, this.attributes(e)) ?? this.rules.navigation(e.tagName, this.attributes(e)) ?? this.activeSheet(e);
|
|
133
|
+
if (n) {
|
|
134
|
+
if (!t) return;
|
|
135
|
+
let i = t.endTag || e.namespaceURI === s.HTML && E.has(e.tagName);
|
|
136
|
+
r.push({
|
|
137
|
+
kind: n,
|
|
138
|
+
start: t.startOffset,
|
|
139
|
+
end: i ? t.endOffset : t.startTag?.endOffset ?? t.endOffset
|
|
140
|
+
});
|
|
141
|
+
} else for (let n of e.attrs) {
|
|
142
|
+
let e = this.name(n), i = this.rules.attribute(e, n.value) ?? (e.toLowerCase() === "style" && this.styles?.stripActive(n.value, "declarationList").removed ? "style" : void 0);
|
|
143
|
+
if (!i) continue;
|
|
144
|
+
let a = Object.entries(t?.attrs ?? {}).find(([t]) => t.toLowerCase() === e.toLowerCase())?.[1];
|
|
145
|
+
if (!a) return;
|
|
146
|
+
r.push({
|
|
147
|
+
kind: i,
|
|
148
|
+
start: a.startOffset,
|
|
149
|
+
end: a.endOffset
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return r;
|
|
154
|
+
}
|
|
155
|
+
activeSheet(e) {
|
|
156
|
+
if (e.tagName !== "style" || !this.styles) return;
|
|
157
|
+
let t = e.childNodes.map((e) => r.isTextNode(e) ? e.value : "").join("");
|
|
158
|
+
return this.styles.stripActive(t).removed ? "style" : void 0;
|
|
159
|
+
}
|
|
160
|
+
walk(t, n, i) {
|
|
161
|
+
let a = {
|
|
162
|
+
sourceCodeLocationInfo: i,
|
|
163
|
+
scriptingEnabled: !1
|
|
164
|
+
}, o = n === "html" ? this.#e.fragment(t, a) : this.#e.fragment(t, a, r.createElement(n, n === "svg" ? s.SVG : s.MATHML, [])), c = [], l = [...o.childNodes].reverse(), u = 0;
|
|
165
|
+
for (; l.length;) {
|
|
166
|
+
let t = l.pop();
|
|
167
|
+
if (!t) break;
|
|
168
|
+
if (++u > e.limits.totalNodes) return;
|
|
169
|
+
if (!r.isElementNode(t)) continue;
|
|
170
|
+
c.push(t);
|
|
171
|
+
let n = "content" in t ? t.content.childNodes : t.childNodes;
|
|
172
|
+
for (let e = n.length - 1; e >= 0; e--) {
|
|
173
|
+
let t = n[e];
|
|
174
|
+
t && l.push(t);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return c;
|
|
178
|
+
}
|
|
179
|
+
attributes(e) {
|
|
180
|
+
return Object.fromEntries(e.attrs.map((e) => [this.name(e), e.value]));
|
|
181
|
+
}
|
|
182
|
+
name(e) {
|
|
183
|
+
return e.prefix ? `${e.prefix}:${e.name}` : e.name;
|
|
184
|
+
}
|
|
185
|
+
}, k = /* @__PURE__ */ new Set([
|
|
186
|
+
"",
|
|
187
|
+
"module",
|
|
188
|
+
"text/javascript",
|
|
189
|
+
"application/javascript",
|
|
190
|
+
"application/x-javascript",
|
|
191
|
+
"text/ecmascript",
|
|
192
|
+
"application/ecmascript",
|
|
193
|
+
"text/jscript",
|
|
194
|
+
"text/livescript",
|
|
195
|
+
"text/javascript1.0",
|
|
196
|
+
"text/javascript1.1",
|
|
197
|
+
"text/javascript1.2",
|
|
198
|
+
"text/javascript1.3",
|
|
199
|
+
"text/javascript1.4",
|
|
200
|
+
"text/javascript1.5",
|
|
201
|
+
"text/x-javascript",
|
|
202
|
+
"text/x-ecmascript"
|
|
203
|
+
]), A = class {
|
|
204
|
+
#e;
|
|
205
|
+
#t;
|
|
206
|
+
#n;
|
|
207
|
+
constructor(e, t, n = new O(t)) {
|
|
208
|
+
this.#e = e, this.#t = t, this.#n = n;
|
|
209
|
+
}
|
|
210
|
+
inspect(e) {
|
|
211
|
+
return this.survey(g.from(e).snapshot()).inventory;
|
|
212
|
+
}
|
|
213
|
+
survey(e) {
|
|
214
|
+
let t = {
|
|
215
|
+
inline: 0,
|
|
216
|
+
data: 0,
|
|
217
|
+
external: [],
|
|
218
|
+
frames: [],
|
|
219
|
+
embeds: 0,
|
|
220
|
+
stylesheets: [],
|
|
221
|
+
links: [],
|
|
222
|
+
forms: 0,
|
|
223
|
+
actions: [],
|
|
224
|
+
inlineHandlers: 0,
|
|
225
|
+
scriptUrls: 0,
|
|
226
|
+
metaRefresh: 0,
|
|
227
|
+
baseUrls: [],
|
|
228
|
+
charsets: [],
|
|
229
|
+
fontFaces: 0,
|
|
230
|
+
activeCss: 0,
|
|
231
|
+
anchors: {}
|
|
232
|
+
};
|
|
233
|
+
this.stylesheet(e.css, t, void 0);
|
|
234
|
+
let n = [...e.nodes].reverse();
|
|
235
|
+
for (; n.length;) {
|
|
236
|
+
let e = n.pop();
|
|
237
|
+
if (!e) break;
|
|
238
|
+
if (e.type === "comment" && this.conditional(e.value ?? "") && this.source(e.value ?? "", "html", t, e.id), e.type !== "element") continue;
|
|
239
|
+
let r = (e.tag ?? "").toLowerCase(), i = this.text(e);
|
|
240
|
+
this.element(r, e.attrs ?? {}, i, t, e.id), r === "style" && this.stylesheet(i, t, e.id);
|
|
241
|
+
let a = w[r];
|
|
242
|
+
a && this.source(i, a, t, e.id);
|
|
243
|
+
let o = e.children ?? [];
|
|
244
|
+
for (let e = o.length - 1; e >= 0; e--) {
|
|
245
|
+
let t = o[e];
|
|
246
|
+
t && n.push(t);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
anchors: t.anchors,
|
|
251
|
+
inventory: {
|
|
252
|
+
kind: e.kind,
|
|
253
|
+
scripts: {
|
|
254
|
+
inline: t.inline,
|
|
255
|
+
external: t.external,
|
|
256
|
+
data: t.data
|
|
257
|
+
},
|
|
258
|
+
frames: t.frames,
|
|
259
|
+
embeds: t.embeds,
|
|
260
|
+
stylesheets: t.stylesheets,
|
|
261
|
+
links: t.links,
|
|
262
|
+
forms: {
|
|
263
|
+
count: t.forms,
|
|
264
|
+
actions: t.actions
|
|
265
|
+
},
|
|
266
|
+
inlineHandlers: t.inlineHandlers,
|
|
267
|
+
scriptUrls: t.scriptUrls,
|
|
268
|
+
metaRefresh: t.metaRefresh,
|
|
269
|
+
baseUrls: t.baseUrls,
|
|
270
|
+
charsets: t.charsets,
|
|
271
|
+
fontFaces: t.fontFaces,
|
|
272
|
+
activeCss: t.activeCss
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
conditional(e) {
|
|
277
|
+
return T(e);
|
|
278
|
+
}
|
|
279
|
+
source(e, t, n, r) {
|
|
280
|
+
for (let i of this.#n.elements(e, t)) {
|
|
281
|
+
let e = i.tag.toLowerCase();
|
|
282
|
+
this.element(e, i.attrs, i.text, n, r), e === "style" && this.stylesheet(i.text, n, r);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
element(e, t, n, r, i) {
|
|
286
|
+
let a = Object.create(null);
|
|
287
|
+
for (let [e, n] of Object.entries(t)) a[e.toLowerCase()] = n;
|
|
288
|
+
let o = (e) => {
|
|
289
|
+
r.anchors[e] ??= i;
|
|
290
|
+
}, s = this.#t.element(e);
|
|
291
|
+
if (this.#t.elementWith(e, t) === "url" && (r.scriptUrls++, o("handler")), s === "script") {
|
|
292
|
+
let e = (a.type ?? "").trim().toLowerCase().split(";", 1)[0] ?? "";
|
|
293
|
+
k.has(e.trim()) ? (a.src === void 0 ? n.trim() && r.inline++ : r.external.push(this.reference(a.src)), o("script")) : r.data++;
|
|
294
|
+
} else s === "embed" && (e === "iframe" || e === "frame" ? r.frames.push(this.reference(a.src ?? "")) : r.embeds++, o("embed"));
|
|
295
|
+
if (e === "link") {
|
|
296
|
+
let e = (a.rel ?? "").trim().toLowerCase(), t = this.reference(a.href ?? "");
|
|
297
|
+
e.split(/\s+/).includes("stylesheet") ? (r.stylesheets.push(t), o("stylesheet")) : r.links.push({
|
|
298
|
+
...t,
|
|
299
|
+
rel: e
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
if (e === "form" && (r.forms++, a.action !== void 0 && r.actions.push(this.reference(a.action)), o("form")), e === "base" && a.href !== void 0 && r.baseUrls.push(a.href), e === "meta") {
|
|
303
|
+
let e = this.declaredCharset(a);
|
|
304
|
+
e !== void 0 && (r.charsets.push(e), e !== "utf-8" && o("charset")), (a["http-equiv"] ?? "").trim().toLowerCase() === "refresh" && r.metaRefresh++;
|
|
305
|
+
}
|
|
306
|
+
for (let [e, t] of Object.entries(a)) {
|
|
307
|
+
let n = this.#t.attribute(e, t);
|
|
308
|
+
n === "handler" && r.inlineHandlers++, n === "url" && r.scriptUrls++, n && o("handler"), e === "style" && this.mayBeActive(t) && (r.activeCss += this.#e.survey(t, "declarationList").active);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
mayBeActive(e) {
|
|
312
|
+
let t = e.toLowerCase();
|
|
313
|
+
return [
|
|
314
|
+
"url",
|
|
315
|
+
"expression",
|
|
316
|
+
"behavior",
|
|
317
|
+
"binding",
|
|
318
|
+
"\\"
|
|
319
|
+
].some((e) => t.includes(e));
|
|
320
|
+
}
|
|
321
|
+
stylesheet(e, t, n) {
|
|
322
|
+
let r = this.#e.survey(e);
|
|
323
|
+
t.fontFaces += r.fontFaces, t.activeCss += r.active;
|
|
324
|
+
for (let e of r.imports) t.stylesheets.push(this.reference(e)), n && (t.anchors.stylesheet ??= n);
|
|
325
|
+
}
|
|
326
|
+
declaredCharset(e) {
|
|
327
|
+
if (e.charset !== void 0) return e.charset.trim().toLowerCase();
|
|
328
|
+
if ((e["http-equiv"] ?? "").trim().toLowerCase() === "content-type") for (let t of (e.content ?? "").split(";")) {
|
|
329
|
+
let [e, n] = t.split("=");
|
|
330
|
+
if (e?.trim().toLowerCase() === "charset" && n !== void 0) return n.trim().toLowerCase();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
reference(e) {
|
|
334
|
+
let t = e.trim();
|
|
335
|
+
try {
|
|
336
|
+
let e = new URL(t.startsWith("//") ? `https:${t}` : t);
|
|
337
|
+
return e.protocol === "https:" || e.protocol === "http:" ? {
|
|
338
|
+
url: t,
|
|
339
|
+
origin: e.origin
|
|
340
|
+
} : { url: t };
|
|
341
|
+
} catch {
|
|
342
|
+
return { url: t };
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
text(e) {
|
|
346
|
+
return (e.children ?? []).map((e) => e.type === "text" ? e.value ?? "" : "").join("");
|
|
347
|
+
}
|
|
348
|
+
}, j = "text/html; charset=utf-8", M = class {
|
|
349
|
+
#e;
|
|
350
|
+
#t;
|
|
351
|
+
#n;
|
|
352
|
+
constructor(e = new C(), t, n = new O(e, t)) {
|
|
353
|
+
this.#e = e, this.#n = t, this.#t = n;
|
|
354
|
+
}
|
|
355
|
+
stylesheet(e) {
|
|
356
|
+
let t = this.#n?.stripActive(e);
|
|
357
|
+
return t?.removed ? {
|
|
358
|
+
css: t.css,
|
|
359
|
+
removed: Array(t.removed).fill("style")
|
|
360
|
+
} : {
|
|
361
|
+
css: e,
|
|
362
|
+
removed: []
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
sanitize(e) {
|
|
366
|
+
let t = [], n = this.nodes(e, t);
|
|
367
|
+
return t.length ? {
|
|
368
|
+
nodes: n,
|
|
369
|
+
removed: t
|
|
370
|
+
} : {
|
|
371
|
+
nodes: e,
|
|
372
|
+
removed: t
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
nodes(e, t) {
|
|
376
|
+
let n = [];
|
|
377
|
+
for (let r of e) {
|
|
378
|
+
let e = this.node(r, t);
|
|
379
|
+
e && n.push(e);
|
|
380
|
+
}
|
|
381
|
+
return n;
|
|
382
|
+
}
|
|
383
|
+
node(e, t) {
|
|
384
|
+
if (e.type === "comment") {
|
|
385
|
+
let n = e.value ?? "";
|
|
386
|
+
if (!T(n)) return e;
|
|
387
|
+
let r = this.source(n, "html", t);
|
|
388
|
+
return r === void 0 ? void 0 : r === n ? e : {
|
|
389
|
+
...e,
|
|
390
|
+
value: r
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (e.type !== "element") return e;
|
|
394
|
+
let n = (e.tag ?? "").toLowerCase(), r = this.#e.element(n) ?? this.#e.elementWith(n, e.attrs ?? {}) ?? this.#e.navigation(n, e.attrs ?? {});
|
|
395
|
+
if (r) {
|
|
396
|
+
t.push(r);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
let i = e.attrs;
|
|
400
|
+
for (let [n, r] of Object.entries(e.attrs ?? {})) {
|
|
401
|
+
let e = this.#e.attribute(n, r);
|
|
402
|
+
if (e) {
|
|
403
|
+
t.push(e), i = Object.fromEntries(Object.entries(i ?? {}).filter(([e]) => e !== n));
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (n.toLowerCase() !== "style") continue;
|
|
407
|
+
let a = this.#n?.stripActive(r, "declarationList");
|
|
408
|
+
a?.removed && (t.push(...Array(a.removed).fill("style")), i = Object.fromEntries(Object.entries(i ?? {}).flatMap(([e, t]) => e === n ? a.css.trim() ? [[e, a.css]] : [] : [[e, t]])));
|
|
409
|
+
}
|
|
410
|
+
n === "meta" && (i = this.charset(i, t));
|
|
411
|
+
let a = w[n], o = e.children;
|
|
412
|
+
if (a) {
|
|
413
|
+
let n = (o ?? []).map((e) => e.value ?? "").join(""), r = this.source(n, a, t);
|
|
414
|
+
if (r === void 0) return;
|
|
415
|
+
r !== n && (o = r ? [{
|
|
416
|
+
id: o?.[0]?.id ?? `${e.id}-source`,
|
|
417
|
+
type: "text",
|
|
418
|
+
value: r
|
|
419
|
+
}] : []);
|
|
420
|
+
} else if (n === "style") {
|
|
421
|
+
let n = (o ?? []).map((e) => e.value ?? "").join(""), r = this.#n?.stripActive(n);
|
|
422
|
+
r?.removed && (t.push(...Array(r.removed).fill("style")), o = r.css ? [{
|
|
423
|
+
id: o?.[0]?.id ?? `${e.id}-source`,
|
|
424
|
+
type: "text",
|
|
425
|
+
value: r.css
|
|
426
|
+
}] : []);
|
|
427
|
+
} else if (o) {
|
|
428
|
+
let e = this.nodes(o, t);
|
|
429
|
+
(e.length !== o.length || e.some((e, t) => e !== o?.[t])) && (o = e);
|
|
430
|
+
}
|
|
431
|
+
return i === e.attrs && o === e.children ? e : {
|
|
432
|
+
...e,
|
|
433
|
+
...i ? { attrs: i } : {},
|
|
434
|
+
...o ? { children: o } : {}
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
source(e, t, n) {
|
|
438
|
+
let r = this.#t.strip(e, t);
|
|
439
|
+
if (!r) n.push("embed");
|
|
440
|
+
else return n.push(...r.removed), r.source;
|
|
441
|
+
}
|
|
442
|
+
charset(e, t) {
|
|
443
|
+
if (!e) return e;
|
|
444
|
+
let n = { ...e }, r = !1;
|
|
445
|
+
for (let [t, i] of Object.entries(e)) {
|
|
446
|
+
let a = t.toLowerCase();
|
|
447
|
+
if (a === "charset" && i.trim().toLowerCase() !== "utf-8" && (n[t] = "utf-8", r = !0), a !== "content" || (Object.entries(e).find(([e]) => e.toLowerCase() === "http-equiv")?.[1])?.trim().toLowerCase() !== "content-type") continue;
|
|
448
|
+
let o = i.split(";").map((e) => e.split("=")).find(([e]) => e?.trim().toLowerCase() === "charset")?.[1];
|
|
449
|
+
o !== void 0 && o.trim().toLowerCase() !== "utf-8" && (n[t] = j, r = !0);
|
|
450
|
+
}
|
|
451
|
+
return r ? (t.push("charset"), n) : e;
|
|
452
|
+
}
|
|
453
|
+
}, N = class extends Error {
|
|
454
|
+
diagnostics;
|
|
455
|
+
constructor(e) {
|
|
456
|
+
super("UNSAFE_DOCUMENT"), this.diagnostics = e, this.name = "ContentPolicyError";
|
|
457
|
+
}
|
|
458
|
+
}, P = "http://www.w3.org/1999/xhtml", F = Object.freeze({
|
|
459
|
+
svg: "http://www.w3.org/2000/svg",
|
|
460
|
+
math: "http://www.w3.org/1998/Math/MathML"
|
|
461
|
+
}), I = Object.freeze({
|
|
462
|
+
script: "SCRIPT_REMOVED",
|
|
463
|
+
embed: "EMBED_REMOVED",
|
|
464
|
+
handler: "INLINE_HANDLER_REMOVED",
|
|
465
|
+
url: "UNSAFE_URL_REMOVED",
|
|
466
|
+
style: "ACTIVE_STYLE_REMOVED",
|
|
467
|
+
charset: "CHARSET_NORMALIZED"
|
|
468
|
+
}), L = Object.freeze({
|
|
469
|
+
script: "FORBIDDEN_HTML_TAG",
|
|
470
|
+
embed: "FORBIDDEN_HTML_TAG",
|
|
471
|
+
handler: "FORBIDDEN_HTML_ATTRIBUTE",
|
|
472
|
+
url: "UNSAFE_HTML_URL",
|
|
473
|
+
style: "UNSAFE_CSS",
|
|
474
|
+
charset: "FORBIDDEN_META_DIRECTIVE"
|
|
475
|
+
}), R = class {
|
|
476
|
+
#e;
|
|
477
|
+
#t;
|
|
478
|
+
#n;
|
|
479
|
+
#r;
|
|
480
|
+
#i;
|
|
481
|
+
constructor(e = new u(), t) {
|
|
482
|
+
this.#e = e, this.#n = t ?? new l(e);
|
|
483
|
+
let n = new C(e);
|
|
484
|
+
this.#t = n, this.#r = new A(this.#n, n), this.#i = new M(n, this.#n);
|
|
485
|
+
}
|
|
486
|
+
validate(e) {
|
|
487
|
+
let t;
|
|
488
|
+
try {
|
|
489
|
+
t = this.snapshot(e);
|
|
490
|
+
} catch (e) {
|
|
491
|
+
return [this.error(e instanceof p ? e.code : "INVALID_DOCUMENT_SCHEMA")];
|
|
492
|
+
}
|
|
493
|
+
let n = [...this.#n.documentDiagnostics(t.css)], r = [...t.nodes];
|
|
494
|
+
for (; r.length;) {
|
|
495
|
+
let e = r.pop();
|
|
496
|
+
if (!e) break;
|
|
497
|
+
this.structure(e, n), r.push(...e.children ?? []);
|
|
498
|
+
}
|
|
499
|
+
try {
|
|
500
|
+
if (t.kind === "email") for (let e of [...this.#i.sanitize(t.nodes).removed, ...this.#i.stylesheet(t.css).removed]) n.push(this.error(L[e]));
|
|
501
|
+
return this.group([...n, ...this.notices(t)]);
|
|
502
|
+
} catch (e) {
|
|
503
|
+
if (!(e instanceof p)) throw e;
|
|
504
|
+
return this.group([...n, this.error(e.code)]);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
assertSafe(e) {
|
|
508
|
+
let t = this.validate(e);
|
|
509
|
+
if (t.some((e) => e.severity === "error")) throw new N(t);
|
|
510
|
+
}
|
|
511
|
+
sanitize(e) {
|
|
512
|
+
let t = this.snapshot(e);
|
|
513
|
+
if (t.kind !== "email") return {
|
|
514
|
+
document: t,
|
|
515
|
+
diagnostics: []
|
|
516
|
+
};
|
|
517
|
+
let n = this.#i.sanitize(t.nodes), r = this.#i.stylesheet(t.css), i = [...n.removed, ...r.removed];
|
|
518
|
+
return i.length ? {
|
|
519
|
+
document: g.from({
|
|
520
|
+
...t,
|
|
521
|
+
nodes: n.nodes,
|
|
522
|
+
css: r.css
|
|
523
|
+
}).snapshot(),
|
|
524
|
+
diagnostics: this.group(i.map((e) => this.notice(I[e], "warning", 1)))
|
|
525
|
+
} : {
|
|
526
|
+
document: t,
|
|
527
|
+
diagnostics: []
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
writable(e) {
|
|
531
|
+
let t = [...e];
|
|
532
|
+
for (; t.length;) {
|
|
533
|
+
let e = t.pop();
|
|
534
|
+
if (!e) break;
|
|
535
|
+
if (e.type === "element") {
|
|
536
|
+
if (this.#t.element(e.tag ?? "") || this.#t.elementWith(e.tag ?? "", e.attrs ?? {}) || this.#t.navigation(e.tag ?? "", e.attrs ?? {})) return !1;
|
|
537
|
+
for (let [t, n] of Object.entries(e.attrs ?? {})) {
|
|
538
|
+
if (this.#t.attribute(t, n) || this.#t.handlerLike(t)) return !1;
|
|
539
|
+
let e = this.#t.urlPurpose(t);
|
|
540
|
+
if (e && !this.#e.isSafe(n, e) || [
|
|
541
|
+
"srcdoc",
|
|
542
|
+
"srcset",
|
|
543
|
+
"imagesrcset"
|
|
544
|
+
].includes(t.toLowerCase())) return !1;
|
|
545
|
+
}
|
|
546
|
+
t.push(...e.children ?? []);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return !0;
|
|
550
|
+
}
|
|
551
|
+
inspect(e) {
|
|
552
|
+
return this.#r.inspect(e);
|
|
553
|
+
}
|
|
554
|
+
notices(e) {
|
|
555
|
+
let { inventory: t, anchors: n } = this.#r.survey(e), r = [], i = (e, t, n) => {
|
|
556
|
+
t > 0 && r.push(this.notice(e, "info", t, n));
|
|
557
|
+
};
|
|
558
|
+
return e.kind === "page" && (i("SCRIPT_PRESERVED", t.scripts.inline + t.scripts.external.length, n.script), i("EMBED_PRESERVED", t.frames.length + t.embeds, n.embed), i("INLINE_HANDLER_PRESERVED", t.inlineHandlers + t.scriptUrls, n.handler)), i("EXTERNAL_STYLE_PRESERVED", t.stylesheets.length, n.stylesheet), i("FORM_PRESERVED", t.forms.count, n.form), r;
|
|
559
|
+
}
|
|
560
|
+
snapshot(e) {
|
|
561
|
+
return (e instanceof g ? e : g.from(e)).snapshot();
|
|
562
|
+
}
|
|
563
|
+
structure(e, t) {
|
|
564
|
+
if ((e.value?.includes("\0") || Object.values(e.attrs ?? {}).some((e) => e.includes("\0"))) && t.push(this.error("INVALID_HTML_CHARACTER", e.id)), e.type === "element") {
|
|
565
|
+
let n = (e.tag ?? "").toLowerCase();
|
|
566
|
+
this.tagName(n) || t.push(this.error("FORBIDDEN_HTML_TAG", e.id)), (e.metadata?.namespace ?? F[n] ?? P) !== (F[n] ?? P) && t.push(this.error("FORBIDDEN_NAMESPACE", e.id));
|
|
567
|
+
for (let n of Object.keys(e.attrs ?? {})) this.attributeName(n) || t.push(this.error("FORBIDDEN_HTML_ATTRIBUTE", e.id));
|
|
568
|
+
} else {
|
|
569
|
+
if (e.type === "comment") {
|
|
570
|
+
let n = e.value ?? "", r = e.metadata?.commentOpener ?? "<!--";
|
|
571
|
+
(r === "<!--" ? n.includes("-->") || n.includes("--!>") : n.includes(">") || r === "<?" && !n.startsWith("?")) && t.push(this.error("INVALID_HTML_COMMENT", e.id));
|
|
572
|
+
}
|
|
573
|
+
if (e.type === "doctype") {
|
|
574
|
+
let n = Object.entries(e.attrs ?? {});
|
|
575
|
+
(!this.tagName((e.value ?? "").toLowerCase() || "html") || n.some(([e]) => !["publicId", "systemId"].includes(e)) || n.some(([, e]) => e.includes(">") || e.includes("\"") && e.includes("'"))) && t.push(this.error("INVALID_DOCTYPE", e.id));
|
|
576
|
+
} else e.attrs && Object.keys(e.attrs).length && t.push(this.error("INVALID_LEAF", e.id));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
tagName(e) {
|
|
580
|
+
let t = e.charCodeAt(0);
|
|
581
|
+
return (t >= 65 && t <= 90 || t >= 97 && t <= 122) && this.nameCharacters(e);
|
|
582
|
+
}
|
|
583
|
+
attributeName(e) {
|
|
584
|
+
return e.length > 0 && e !== "__proto__" && !e.slice(1).includes("=") && this.nameCharacters(e);
|
|
585
|
+
}
|
|
586
|
+
nameCharacters(e) {
|
|
587
|
+
return ![...e].some((e) => e === "/" || e === ">" || e === "\0" || e === " " || e === " " || e === "\n" || e === "\f" || e === "\r");
|
|
588
|
+
}
|
|
589
|
+
group(e) {
|
|
590
|
+
let t = /* @__PURE__ */ new Map();
|
|
591
|
+
for (let n of e) {
|
|
592
|
+
let e = t.get(n.code);
|
|
593
|
+
if (!e) {
|
|
594
|
+
t.set(n.code, n);
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
let r = e.nodeId ?? n.nodeId;
|
|
598
|
+
t.set(n.code, {
|
|
599
|
+
code: e.code,
|
|
600
|
+
severity: e.severity,
|
|
601
|
+
messageKey: e.messageKey,
|
|
602
|
+
...r ? { nodeId: r } : {},
|
|
603
|
+
count: (e.count ?? 1) + (n.count ?? 1)
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return [...t.values()];
|
|
607
|
+
}
|
|
608
|
+
notice(e, t, n, r) {
|
|
609
|
+
return {
|
|
610
|
+
code: e,
|
|
611
|
+
severity: t,
|
|
612
|
+
messageKey: `diagnostics.${e}`,
|
|
613
|
+
...r ? { nodeId: r } : {},
|
|
614
|
+
count: n
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
error(e, t) {
|
|
618
|
+
return {
|
|
619
|
+
code: e,
|
|
620
|
+
severity: "error",
|
|
621
|
+
messageKey: `diagnostics.${e}`,
|
|
622
|
+
...t ? { nodeId: t } : {}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
}, z = /* @__PURE__ */ new Set(["mso", "ie"]), B = /* @__PURE__ */ new Set([
|
|
626
|
+
"gt",
|
|
627
|
+
"gte",
|
|
628
|
+
"lt",
|
|
629
|
+
"lte"
|
|
630
|
+
]), V = /* @__PURE__ */ new Set([
|
|
631
|
+
"!",
|
|
632
|
+
"(",
|
|
633
|
+
")",
|
|
634
|
+
"&",
|
|
635
|
+
"|"
|
|
636
|
+
]), H = 100, U = class {
|
|
637
|
+
isOpening(e) {
|
|
638
|
+
return e.length > H || !e.startsWith("[if ") || !e.endsWith("]") ? !1 : this.validExpression(e.slice(4, -1));
|
|
639
|
+
}
|
|
640
|
+
isClosing(e) {
|
|
641
|
+
return e === "[endif]";
|
|
642
|
+
}
|
|
643
|
+
isMarker(e) {
|
|
644
|
+
return this.isOpening(e) || this.isClosing(e);
|
|
645
|
+
}
|
|
646
|
+
isClosingLookalike(e) {
|
|
647
|
+
return !this.isClosing(e) && e.trim().toLowerCase() === "[endif]";
|
|
648
|
+
}
|
|
649
|
+
isBalanced(e) {
|
|
650
|
+
let t = !1;
|
|
651
|
+
for (let n of e) if (this.isOpening(n)) {
|
|
652
|
+
if (t) return !1;
|
|
653
|
+
t = !0;
|
|
654
|
+
} else this.isClosing(n) && (t = !1);
|
|
655
|
+
return !t;
|
|
656
|
+
}
|
|
657
|
+
validExpression(e) {
|
|
658
|
+
let t = this.tokens(e);
|
|
659
|
+
return t?.length ? this.expression(t, 0) === t.length : !1;
|
|
660
|
+
}
|
|
661
|
+
tokens(e) {
|
|
662
|
+
let t = [], n = "";
|
|
663
|
+
for (let r of e) {
|
|
664
|
+
if (r === " " || V.has(r)) {
|
|
665
|
+
n && t.push(n.toLowerCase()), n = "", r !== " " && t.push(r);
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
let e = r.charCodeAt(0);
|
|
669
|
+
if (!(e >= 65 && e <= 90 || e >= 97 && e <= 122) && !(e >= 48 && e <= 57) && r !== ".") return;
|
|
670
|
+
n += r;
|
|
671
|
+
}
|
|
672
|
+
return n && t.push(n.toLowerCase()), t;
|
|
673
|
+
}
|
|
674
|
+
expression(e, t) {
|
|
675
|
+
let n = this.term(e, t);
|
|
676
|
+
for (; n >= 0 && (e[n] === "&" || e[n] === "|");) n = this.term(e, n + 1);
|
|
677
|
+
return n;
|
|
678
|
+
}
|
|
679
|
+
term(e, t) {
|
|
680
|
+
let n = e[t] === "!" ? t + 1 : t;
|
|
681
|
+
if (e[n] === "(") {
|
|
682
|
+
let t = this.expression(e, n + 1);
|
|
683
|
+
return t >= 0 && e[t] === ")" ? t + 1 : -1;
|
|
684
|
+
}
|
|
685
|
+
return B.has(e[n] ?? "") && n++, z.has(e[n] ?? "") ? (n++, this.version(e[n] ?? "") ? n + 1 : n) : -1;
|
|
686
|
+
}
|
|
687
|
+
version(e) {
|
|
688
|
+
let t = e.split(".");
|
|
689
|
+
return t.length <= 2 && t.every((e) => e.length > 0 && e.length <= 3 && [...e].every((e) => e.charCodeAt(0) >= 48 && e.charCodeAt(0) <= 57));
|
|
690
|
+
}
|
|
691
|
+
}, W = Object.freeze([
|
|
692
|
+
"pre",
|
|
693
|
+
"textarea",
|
|
694
|
+
"listing"
|
|
695
|
+
]), G = /* @__PURE__ */ new Set([
|
|
696
|
+
"td",
|
|
697
|
+
"th",
|
|
698
|
+
"tr",
|
|
699
|
+
"tbody",
|
|
700
|
+
"thead",
|
|
701
|
+
"tfoot",
|
|
702
|
+
"caption",
|
|
703
|
+
"colgroup",
|
|
704
|
+
"col"
|
|
705
|
+
]), K = 2e4, q = class {
|
|
706
|
+
#e;
|
|
707
|
+
#t;
|
|
708
|
+
#n = /* @__PURE__ */ new Map();
|
|
709
|
+
#r = /* @__PURE__ */ new Set();
|
|
710
|
+
#i;
|
|
711
|
+
#a = 8e6;
|
|
712
|
+
#o = 0;
|
|
713
|
+
#s = new d().next();
|
|
714
|
+
#c = new U();
|
|
715
|
+
#l = new t();
|
|
716
|
+
#u = /* @__PURE__ */ new WeakMap();
|
|
717
|
+
#d = new e();
|
|
718
|
+
#f = new c(i.depth);
|
|
719
|
+
constructor(e = new R(), t = new a(), n = 20) {
|
|
720
|
+
if (!Number.isInteger(n) || n < 1 || n > 100) throw RangeError("INVALID_CODEC_CACHE_LIMIT");
|
|
721
|
+
this.#e = e, this.#t = t, this.#i = n;
|
|
722
|
+
}
|
|
723
|
+
import(e, t, n) {
|
|
724
|
+
let r = this.read(e, t, n, !0);
|
|
725
|
+
if (!r.document || this.roundTrips(r.document)) return r;
|
|
726
|
+
this.forget(r.document.id);
|
|
727
|
+
let i = this.read({
|
|
728
|
+
html: this.plain(r.document),
|
|
729
|
+
css: e.css
|
|
730
|
+
}, t, n, !0);
|
|
731
|
+
if (!i.document || !this.roundTrips(i.document)) return i.document && this.forget(i.document.id), { diagnostics: [this.error("INVALID_HTML")] };
|
|
732
|
+
let a = /* @__PURE__ */ new Map();
|
|
733
|
+
for (let e of [
|
|
734
|
+
...r.diagnostics.filter((e) => e.severity === "warning"),
|
|
735
|
+
...i.diagnostics,
|
|
736
|
+
this.notice("HTML_NORMALIZED")
|
|
737
|
+
]) a.has(e.code) || a.set(e.code, e);
|
|
738
|
+
return {
|
|
739
|
+
document: i.document,
|
|
740
|
+
diagnostics: [...a.values()]
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
inspect(e, t) {
|
|
744
|
+
return this.read(e, t, void 0, !1);
|
|
745
|
+
}
|
|
746
|
+
read(e, t, n, r) {
|
|
747
|
+
if (typeof e?.html != "string" || typeof e.css != "string" || !["email", "page"].includes(t)) return { diagnostics: [this.error("INVALID_SOURCE")] };
|
|
748
|
+
try {
|
|
749
|
+
this.#d.assertSource(e.html, e.css);
|
|
750
|
+
} catch (e) {
|
|
751
|
+
return { diagnostics: [this.error(e instanceof m ? e.code : "DOCUMENT_TOO_LARGE")] };
|
|
752
|
+
}
|
|
753
|
+
if (n) {
|
|
754
|
+
try {
|
|
755
|
+
this.#e.assertSafe(n);
|
|
756
|
+
} catch {
|
|
757
|
+
return { diagnostics: [this.error("INVALID_PREVIOUS_DOCUMENT")] };
|
|
758
|
+
}
|
|
759
|
+
if (n.kind !== t) return { diagnostics: [this.error("DOCUMENT_KIND_MISMATCH")] };
|
|
760
|
+
}
|
|
761
|
+
let i = e.html.includes("\0") ? e.html.replaceAll("\0", "") : e.html, a = {
|
|
762
|
+
html: i,
|
|
763
|
+
css: e.css
|
|
764
|
+
};
|
|
765
|
+
try {
|
|
766
|
+
let { nodes: o, slices: s } = this.tree(i), c = g.from({
|
|
767
|
+
schemaVersion: 1,
|
|
768
|
+
id: n?.id ?? this.newId("document"),
|
|
769
|
+
kind: t,
|
|
770
|
+
revision: (n?.revision ?? -1) + 1,
|
|
771
|
+
title: (this.findTitle(o) ?? n?.title ?? "").slice(0, 1e3),
|
|
772
|
+
nodes: o,
|
|
773
|
+
css: e.css
|
|
774
|
+
}), l = this.#e.sanitize(c), u = l.document.nodes, d = n ? this.reconcileIds(u, n.nodes) : u, f = /* @__PURE__ */ new Map(), p = d.map((e, t) => ({
|
|
775
|
+
node: e,
|
|
776
|
+
origin: u[t]
|
|
777
|
+
}));
|
|
778
|
+
for (; p.length;) {
|
|
779
|
+
let e = p.pop();
|
|
780
|
+
if (!e) break;
|
|
781
|
+
let t = e.origin ? s.get(e.origin.id) : void 0;
|
|
782
|
+
t && f.set(e.node.id, t), (e.node.children ?? []).forEach((t, n) => p.push({
|
|
783
|
+
node: t,
|
|
784
|
+
origin: e.origin?.children?.[n]
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
let m = n || l.diagnostics.length ? g.from({
|
|
788
|
+
...l.document,
|
|
789
|
+
nodes: d
|
|
790
|
+
}) : c, h = this.#e.validate(m);
|
|
791
|
+
if (h.some((e) => e.severity === "error")) return { diagnostics: h };
|
|
792
|
+
let _ = m.snapshot();
|
|
793
|
+
return r && this.remember(_, a, f, l.diagnostics.length === 0), {
|
|
794
|
+
document: _,
|
|
795
|
+
validated: m,
|
|
796
|
+
diagnostics: [...l.diagnostics, ...h]
|
|
797
|
+
};
|
|
798
|
+
} catch (e) {
|
|
799
|
+
return { diagnostics: [this.error(e instanceof p ? e.code : "INVALID_HTML")] };
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
tree(e) {
|
|
803
|
+
let t = this.#f.document(e, {
|
|
804
|
+
sourceCodeLocationInfo: !0,
|
|
805
|
+
scriptingEnabled: !0
|
|
806
|
+
}), n = this.isDocument(t) ? t.childNodes : this.fragment(t, e), a = 0, o = 0, s = /* @__PURE__ */ new WeakSet(), c = (t, n) => {
|
|
807
|
+
if (n > i.depth) throw new p("DOCUMENT_TOO_DEEP");
|
|
808
|
+
let l = this.newId("node"), u = t.sourceCodeLocation, d = u ? {
|
|
809
|
+
sourceStart: u.startOffset,
|
|
810
|
+
sourceEnd: u.endOffset
|
|
811
|
+
} : {}, f;
|
|
812
|
+
if (r.isElementNode(t)) {
|
|
813
|
+
let i = Object.fromEntries(t.attrs.map((e) => [e.prefix ? `${e.prefix}:${e.name}` : e.name, e.value]).filter(([e]) => e !== "__proto__")), a = this.island(t, e, l), o = a?.children ?? r.getChildNodes(t).map((e) => c(e, n + 1));
|
|
814
|
+
f = {
|
|
815
|
+
id: l,
|
|
816
|
+
type: "element",
|
|
817
|
+
tag: t.tagName,
|
|
818
|
+
attrs: i,
|
|
819
|
+
children: o,
|
|
820
|
+
metadata: {
|
|
821
|
+
...d,
|
|
822
|
+
namespace: t.namespaceURI
|
|
823
|
+
}
|
|
824
|
+
};
|
|
825
|
+
let u = this.#t.recognize(f);
|
|
826
|
+
u && (f = {
|
|
827
|
+
...f,
|
|
828
|
+
metadata: {
|
|
829
|
+
...f.metadata,
|
|
830
|
+
blockType: u.type
|
|
831
|
+
}
|
|
832
|
+
}), (a ? a.contained : this.selfContainedElement(t, o, s)) && s.add(f);
|
|
833
|
+
} else if (r.isTextNode(t)) f = {
|
|
834
|
+
id: l,
|
|
835
|
+
type: "text",
|
|
836
|
+
value: t.value,
|
|
837
|
+
metadata: d
|
|
838
|
+
}, u && !e.slice(u.startOffset, u.endOffset).includes("<") && s.add(f);
|
|
839
|
+
else if (r.isCommentNode(t)) {
|
|
840
|
+
let n = u ? this.opener(e, u.startOffset) : "<!--";
|
|
841
|
+
f = {
|
|
842
|
+
id: l,
|
|
843
|
+
type: "comment",
|
|
844
|
+
value: t.data,
|
|
845
|
+
metadata: n !== "<!--" || this.#c.isMarker(t.data) ? {
|
|
846
|
+
...d,
|
|
847
|
+
commentOpener: n
|
|
848
|
+
} : d
|
|
849
|
+
}, u && s.add(f);
|
|
850
|
+
} else if (r.isDocumentTypeNode(t)) f = {
|
|
851
|
+
id: l,
|
|
852
|
+
type: "doctype",
|
|
853
|
+
value: t.name,
|
|
854
|
+
attrs: {
|
|
855
|
+
publicId: t.publicId,
|
|
856
|
+
systemId: t.systemId
|
|
857
|
+
},
|
|
858
|
+
metadata: d
|
|
859
|
+
}, u && s.add(f);
|
|
860
|
+
else throw new p("UNSUPPORTED_HTML_NODE");
|
|
861
|
+
if (this.#d.countable(f) && a++, a > i.nodes || ++o > i.totalNodes) throw new p("DOCUMENT_TOO_MANY_NODES");
|
|
862
|
+
return f;
|
|
863
|
+
}, l = n.map((e) => c(e, 0)), u = /* @__PURE__ */ new Map(), d = [...l];
|
|
864
|
+
for (; d.length;) {
|
|
865
|
+
let e = d.pop();
|
|
866
|
+
if (!e) break;
|
|
867
|
+
let t = e.metadata?.sourceStart, n = e.metadata?.sourceEnd;
|
|
868
|
+
s.has(e) && t !== void 0 && n !== void 0 && n > t && u.set(e.id, {
|
|
869
|
+
node: e,
|
|
870
|
+
start: t,
|
|
871
|
+
end: n
|
|
872
|
+
}), d.push(...e.children ?? []);
|
|
873
|
+
}
|
|
874
|
+
return {
|
|
875
|
+
nodes: l,
|
|
876
|
+
slices: u
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
export(e) {
|
|
880
|
+
let t = e instanceof g ? e : g.from(e);
|
|
881
|
+
this.#e.assertSafe(t);
|
|
882
|
+
let n = t.snapshot(), r = this.#n.get(n.id);
|
|
883
|
+
r && (this.#n.delete(n.id), this.#n.set(n.id, r), this.#r.add(n.id));
|
|
884
|
+
let i = this.documentFingerprint(n);
|
|
885
|
+
if (r?.fingerprint !== void 0 && r.fingerprint === i) return { ...r.source };
|
|
886
|
+
if (r) {
|
|
887
|
+
let e = n.nodes.map((e) => this.serialize(e, r)).join("");
|
|
888
|
+
if (this.verification(e, n, i) === void 0) return {
|
|
889
|
+
html: e,
|
|
890
|
+
css: n.css
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
let a = this.plain(n), o = this.verification(a, n, i);
|
|
894
|
+
if (o) throw Error(o);
|
|
895
|
+
return {
|
|
896
|
+
html: a,
|
|
897
|
+
css: n.css
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
clearCache() {
|
|
901
|
+
this.#n.clear(), this.#r.clear();
|
|
902
|
+
}
|
|
903
|
+
plain(e) {
|
|
904
|
+
return e.nodes.map((e) => this.serialize(e)).join("");
|
|
905
|
+
}
|
|
906
|
+
roundTrips(e) {
|
|
907
|
+
return this.verification(this.plain(e), e, this.documentFingerprint(e)) === void 0;
|
|
908
|
+
}
|
|
909
|
+
forget(e) {
|
|
910
|
+
this.#n.delete(e), this.#r.delete(e);
|
|
911
|
+
}
|
|
912
|
+
island(e, t, n) {
|
|
913
|
+
if (!this.#l.isSourceIsland(e.tagName) || e.tagName === "template" != (e.namespaceURI === s.HTML)) return;
|
|
914
|
+
let r = e.sourceCodeLocation?.startTag?.endOffset, i = e.sourceCodeLocation?.endTag?.startOffset, a = r !== void 0 && i !== void 0, o = a ? t.slice(r, i) : f(e);
|
|
915
|
+
return {
|
|
916
|
+
children: o ? [{
|
|
917
|
+
id: `${n}-source`,
|
|
918
|
+
type: "text",
|
|
919
|
+
value: o
|
|
920
|
+
}] : [],
|
|
921
|
+
contained: a
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
opener(e, t) {
|
|
925
|
+
return e.startsWith("<!--", t) ? "<!--" : e.startsWith("<!", t) ? "<!" : e.startsWith("</", t) ? "</" : e.startsWith("<?", t) ? "<?" : "<!--";
|
|
926
|
+
}
|
|
927
|
+
commentOpener(e) {
|
|
928
|
+
return e.metadata?.commentOpener ?? (this.#c.isMarker(e.value ?? "") ? "<!" : "<!--");
|
|
929
|
+
}
|
|
930
|
+
namespace(e) {
|
|
931
|
+
let t = e.tag?.toLowerCase();
|
|
932
|
+
return t === "svg" ? s.SVG : t === "math" ? s.MATHML : e.metadata?.namespace ?? s.HTML;
|
|
933
|
+
}
|
|
934
|
+
verification(e, t, n) {
|
|
935
|
+
try {
|
|
936
|
+
this.#d.assertSource(e, t.css);
|
|
937
|
+
let r = this.tree(e).nodes;
|
|
938
|
+
return this.documentFingerprint({
|
|
939
|
+
...t,
|
|
940
|
+
nodes: r
|
|
941
|
+
}) === n ? void 0 : "SERIALIZED_STRUCTURE_CHANGED";
|
|
942
|
+
} catch {
|
|
943
|
+
return "UNSAFE_SERIALIZED_DOCUMENT";
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
selfContainedElement(e, t, n) {
|
|
947
|
+
let i = e.sourceCodeLocation;
|
|
948
|
+
if (!i?.startTag) return !1;
|
|
949
|
+
let a = { offset: i.startTag.endOffset };
|
|
950
|
+
return this.tile(r.getChildNodes(e), t, n, a) && a.offset === (i.endTag?.startOffset ?? i.endOffset);
|
|
951
|
+
}
|
|
952
|
+
tile(e, t, n, i) {
|
|
953
|
+
for (let [a, o] of e.entries()) {
|
|
954
|
+
let e = t[a];
|
|
955
|
+
if (!e) return !1;
|
|
956
|
+
let s = o.sourceCodeLocation;
|
|
957
|
+
if (s) {
|
|
958
|
+
if (s.startOffset !== i.offset || e.type === "element" && !n.has(e)) return !1;
|
|
959
|
+
i.offset = s.endOffset;
|
|
960
|
+
} else if (!r.isElementNode(o) || !this.tile(r.getChildNodes(o), e.children ?? [], n, i)) return !1;
|
|
961
|
+
}
|
|
962
|
+
return !0;
|
|
963
|
+
}
|
|
964
|
+
serialize(e, t) {
|
|
965
|
+
let i = t?.regions.get(e.id);
|
|
966
|
+
if (i && this.nodeFingerprint(i.node) === this.nodeFingerprint(e)) return t?.source.html.slice(i.start, i.end) ?? "";
|
|
967
|
+
if (e.type === "doctype") {
|
|
968
|
+
let t = (e) => e.includes("\"") ? `'${e}'` : `"${e}"`, n = e.attrs?.publicId ?? "", r = e.attrs?.systemId ?? "", i = n ? ` PUBLIC ${t(n)}${r ? ` ${t(r)}` : ""}` : r ? ` SYSTEM ${t(r)}` : "";
|
|
969
|
+
return `<!DOCTYPE ${e.value || "html"}${i}>`;
|
|
970
|
+
}
|
|
971
|
+
if (e.type === "comment") {
|
|
972
|
+
let t = e.value ?? "", n = this.commentOpener(e);
|
|
973
|
+
return n === "<!--" ? `<!--${t}-->` : n === "<?" ? `<${t}>` : `${n}${t}>`;
|
|
974
|
+
}
|
|
975
|
+
if (e.type === "text") {
|
|
976
|
+
let t = r.createElement("div", s.HTML, []);
|
|
977
|
+
r.insertText(t, e.value ?? "");
|
|
978
|
+
let i = t.childNodes[0];
|
|
979
|
+
return i ? n(i).replaceAll("\r", " ") : "";
|
|
980
|
+
}
|
|
981
|
+
let a = e.tag ?? "div", o = a.toLowerCase() === "template", c = r.createElement(o ? "div" : a, s.HTML, Object.entries(e.attrs ?? {}).map(([e, t]) => ({
|
|
982
|
+
name: e,
|
|
983
|
+
value: t
|
|
984
|
+
}))), l = n(c).replaceAll("\r", " "), u = o ? `<${a}${l.slice(4, l.length - 6)}</${a}>` : l, d = `</${a}>`;
|
|
985
|
+
if (h.includes(a.toLowerCase()) || !u.endsWith(d)) return u;
|
|
986
|
+
let f = u.slice(0, u.length - d.length), p = e.children ?? [];
|
|
987
|
+
if (this.#l.holdsSource(a)) {
|
|
988
|
+
let e = p.map((e) => e.value ?? "").join("");
|
|
989
|
+
return a.toLowerCase() === "plaintext" ? `${f}${e}` : `${f}${e}${d}`;
|
|
990
|
+
}
|
|
991
|
+
let m = W.includes(a.toLowerCase()), g = p.map((e, n) => this.serialize(e, m && n === 0 ? void 0 : t)).join(""), _ = p[0];
|
|
992
|
+
return `${f}${m && _?.type === "text" && _.value?.startsWith("\n") ? "\n" : ""}${g}${d}`;
|
|
993
|
+
}
|
|
994
|
+
fragment(e, t) {
|
|
995
|
+
let n = e.childNodes.flatMap((e) => r.isElementNode(e) ? e.childNodes.flatMap((e) => r.isElementNode(e) ? e.childNodes : [e]) : []);
|
|
996
|
+
if (n.length > K) return n;
|
|
997
|
+
let i = this.#f.fragment(t, {
|
|
998
|
+
sourceCodeLocationInfo: !0,
|
|
999
|
+
scriptingEnabled: !0
|
|
1000
|
+
}).childNodes;
|
|
1001
|
+
return i.some((e) => r.isElementNode(e) && G.has(e.tagName)) ? n : i;
|
|
1002
|
+
}
|
|
1003
|
+
isDocument(e) {
|
|
1004
|
+
let t = [...e.childNodes];
|
|
1005
|
+
for (; t.length;) {
|
|
1006
|
+
let e = t.pop();
|
|
1007
|
+
if (!e) break;
|
|
1008
|
+
if (r.isDocumentTypeNode(e)) return !0;
|
|
1009
|
+
if (r.isElementNode(e)) {
|
|
1010
|
+
if ([
|
|
1011
|
+
"html",
|
|
1012
|
+
"head",
|
|
1013
|
+
"body"
|
|
1014
|
+
].includes(e.tagName) && e.sourceCodeLocation?.startTag) return !0;
|
|
1015
|
+
t.push(...e.childNodes);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return !1;
|
|
1019
|
+
}
|
|
1020
|
+
findTitle(e) {
|
|
1021
|
+
for (let t of e) {
|
|
1022
|
+
if (t.type === "element" && t.tag === "title") return (t.children ?? []).map((e) => e.value ?? "").join("");
|
|
1023
|
+
let e = this.findTitle(t.children ?? []);
|
|
1024
|
+
if (e !== void 0) return e;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
newId(e) {
|
|
1028
|
+
return `${e}-${this.#s}-${++this.#o}`;
|
|
1029
|
+
}
|
|
1030
|
+
reconcileIds(e, t) {
|
|
1031
|
+
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Set(), i = [...t];
|
|
1032
|
+
for (; i.length;) {
|
|
1033
|
+
let e = i.pop();
|
|
1034
|
+
if (!e) break;
|
|
1035
|
+
let t = this.nodeFingerprint(e), r = n.get(t);
|
|
1036
|
+
r ? r.push(e) : n.set(t, [e]), i.push(...e.children ?? []);
|
|
1037
|
+
}
|
|
1038
|
+
let a = [...e];
|
|
1039
|
+
for (; a.length;) {
|
|
1040
|
+
let e = a.pop();
|
|
1041
|
+
if (!e) break;
|
|
1042
|
+
r.add(this.nodeFingerprint(e)), a.push(...e.children ?? []);
|
|
1043
|
+
}
|
|
1044
|
+
let o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map(), c = (e) => {
|
|
1045
|
+
let t = n.get(e);
|
|
1046
|
+
if (!t) return;
|
|
1047
|
+
let r = s.get(e) ?? 0;
|
|
1048
|
+
for (; r < t.length && o.has(t[r]?.id ?? "");) r++;
|
|
1049
|
+
return s.set(e, r), t[r];
|
|
1050
|
+
}, l = (e, t) => {
|
|
1051
|
+
let n = this.nodeFingerprint(e), i = c(n);
|
|
1052
|
+
t && this.nodeFingerprint(t) === n && !o.has(t.id) && (i = t), !i && t && t.type === e.type && t.tag === e.tag && !o.has(t.id) && !r.has(this.nodeFingerprint(t)) && (i = t);
|
|
1053
|
+
let a = i?.id ?? e.id;
|
|
1054
|
+
return o.add(a), {
|
|
1055
|
+
...e,
|
|
1056
|
+
id: a,
|
|
1057
|
+
...e.children ? { children: e.children.map((e, t) => l(e, i?.children?.[t])) } : {}
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
return e.map((e, n) => l(e, t[n]));
|
|
1061
|
+
}
|
|
1062
|
+
nodeFingerprint(e) {
|
|
1063
|
+
let t = this.#u.get(e);
|
|
1064
|
+
if (t !== void 0) return t;
|
|
1065
|
+
let n = (e.children ?? []).map((e) => this.nodeFingerprint(e)).join(","), r = this.digest(`${JSON.stringify(this.ownStructure(e))}|${n}`);
|
|
1066
|
+
return this.#u.set(e, r), r;
|
|
1067
|
+
}
|
|
1068
|
+
digest(e) {
|
|
1069
|
+
let t = 2166136261, n = 2654435769;
|
|
1070
|
+
for (let r = 0; r < e.length; r++) {
|
|
1071
|
+
let i = e.charCodeAt(r);
|
|
1072
|
+
t = Math.imul(t ^ i, 16777619), n = Math.imul(n ^ i, 2246822507) ^ n >>> 13;
|
|
1073
|
+
}
|
|
1074
|
+
return `${(t >>> 0).toString(36)}.${(n >>> 0).toString(36)}.${e.length.toString(36)}`;
|
|
1075
|
+
}
|
|
1076
|
+
ownStructure(e) {
|
|
1077
|
+
let t = e.type === "doctype" ? {
|
|
1078
|
+
publicId: e.attrs?.publicId ?? "",
|
|
1079
|
+
systemId: e.attrs?.systemId ?? ""
|
|
1080
|
+
} : e.attrs ?? {};
|
|
1081
|
+
return {
|
|
1082
|
+
type: e.type,
|
|
1083
|
+
tag: e.tag?.toLowerCase(),
|
|
1084
|
+
value: e.type === "doctype" ? e.value?.toLowerCase() : e.value,
|
|
1085
|
+
opener: e.type === "comment" ? this.commentOpener(e) : void 0,
|
|
1086
|
+
attrs: Object.entries(t).map(([t, n]) => [e.type === "doctype" ? t : t.toLowerCase(), n]).sort(([e], [t]) => e < t ? -1 : +(e > t)),
|
|
1087
|
+
namespace: e.type === "element" ? this.namespace(e) : void 0
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
nodeStructure(e) {
|
|
1091
|
+
return {
|
|
1092
|
+
...this.ownStructure(e),
|
|
1093
|
+
children: (e.children ?? []).map((e) => this.nodeStructure(e))
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
documentFingerprint(e) {
|
|
1097
|
+
return JSON.stringify({
|
|
1098
|
+
kind: e.kind,
|
|
1099
|
+
css: e.css,
|
|
1100
|
+
nodes: e.nodes.map((e) => this.nodeStructure(e))
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
remember(e, t, n, r) {
|
|
1104
|
+
this.#n.delete(e.id);
|
|
1105
|
+
let i = r ? this.documentFingerprint(e) : void 0, a = t.html.length + t.css.length + (i?.length ?? t.html.length);
|
|
1106
|
+
if (a > this.#a) this.#r.delete(e.id);
|
|
1107
|
+
else for (this.#n.set(e.id, {
|
|
1108
|
+
source: { ...t },
|
|
1109
|
+
fingerprint: i,
|
|
1110
|
+
regions: n,
|
|
1111
|
+
weight: a
|
|
1112
|
+
}); this.#n.size > this.#i || [...this.#n.values()].reduce((e, t) => e + t.weight, 0) > this.#a;) {
|
|
1113
|
+
let e = [...this.#n.keys()], t = e.find((e) => !this.#r.has(e)) ?? e[0];
|
|
1114
|
+
if (t === void 0) break;
|
|
1115
|
+
this.#n.delete(t), this.#r.delete(t);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
error(e) {
|
|
1119
|
+
return {
|
|
1120
|
+
code: e,
|
|
1121
|
+
severity: "error",
|
|
1122
|
+
messageKey: `diagnostics.${e}`
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
notice(e) {
|
|
1126
|
+
return {
|
|
1127
|
+
code: e,
|
|
1128
|
+
severity: "info",
|
|
1129
|
+
messageKey: `diagnostics.${e}`
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
}, J = Object.freeze({
|
|
1133
|
+
sourceBytes: 2e5,
|
|
1134
|
+
outputBytes: 2e6,
|
|
1135
|
+
timeoutMs: 15e3,
|
|
1136
|
+
parallelJobs: 2
|
|
1137
|
+
}), Y = [
|
|
1138
|
+
"mj-include",
|
|
1139
|
+
"mj-font",
|
|
1140
|
+
"mj-raw",
|
|
1141
|
+
"script",
|
|
1142
|
+
"iframe",
|
|
1143
|
+
"object",
|
|
1144
|
+
"embed"
|
|
1145
|
+
], X = /^ve-p-[a-f0-9]{32}-[A-Za-z0-9_-]{1,64}$/, Z = /^padding:(0|\d{1,3}(px)?)( (0|\d{1,3}(px)?)){0,3}$/, Q = class {
|
|
1146
|
+
codec = new q(new R());
|
|
1147
|
+
source(e, t) {
|
|
1148
|
+
if (new TextEncoder().encode(e).length > J.sourceBytes) throw Error("COMPILE_SOURCE_LIMIT");
|
|
1149
|
+
let n = t ? new Set(t) : void 0;
|
|
1150
|
+
for (let e of n ?? []) this.rawFragment(e);
|
|
1151
|
+
let r = o(e, { sourceCodeLocationInfo: !0 }).childNodes.map((e) => ({
|
|
1152
|
+
node: e,
|
|
1153
|
+
parent: ""
|
|
1154
|
+
})), i = 0;
|
|
1155
|
+
for (; r.length;) {
|
|
1156
|
+
let t = r.pop();
|
|
1157
|
+
if (!t) break;
|
|
1158
|
+
let { node: a } = t;
|
|
1159
|
+
if (++i > 1e4) throw Error("COMPILE_NODE_LIMIT");
|
|
1160
|
+
if ("tagName" in a) {
|
|
1161
|
+
if (a.tagName === "mj-raw" && n) this.rawRegion(a, t.parent, e, n);
|
|
1162
|
+
else if (Y.includes(a.tagName)) throw Error("COMPILE_FORBIDDEN_TAG");
|
|
1163
|
+
}
|
|
1164
|
+
if ("childNodes" in a) {
|
|
1165
|
+
let e = "tagName" in a ? a.tagName : "";
|
|
1166
|
+
r.push(...a.childNodes.map((t) => ({
|
|
1167
|
+
node: t,
|
|
1168
|
+
parent: e
|
|
1169
|
+
})));
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
rawFragment(e) {
|
|
1174
|
+
if (/<\/?mj-/i.test(e)) throw Error("COMPILE_UNSAFE_RAW");
|
|
1175
|
+
let t = r.createElement("tbody", s.HTML, []), n = o(t, e, {}), i = n.childNodes[0];
|
|
1176
|
+
if (n.childNodes.length !== 1 || !i || !("tagName" in i) || i.tagName !== "tr") throw Error("COMPILE_UNSAFE_RAW");
|
|
1177
|
+
let a = i.childNodes[0];
|
|
1178
|
+
if (i.attrs.length || i.childNodes.length !== 1 || !a || !("tagName" in a) || a.tagName !== "td") throw Error("COMPILE_UNSAFE_RAW");
|
|
1179
|
+
for (let e of a.attrs) if (!(e.name === "class" && X.test(e.value)) && !(e.name === "style" && Z.test(e.value))) throw Error("COMPILE_UNSAFE_RAW");
|
|
1180
|
+
let c = f(a);
|
|
1181
|
+
if (!c) return;
|
|
1182
|
+
let l = this.codec.inspect({
|
|
1183
|
+
html: c,
|
|
1184
|
+
css: ""
|
|
1185
|
+
}, "email");
|
|
1186
|
+
if (!l.document || l.diagnostics.some((e) => e.severity !== "info")) throw Error("COMPILE_UNSAFE_RAW");
|
|
1187
|
+
}
|
|
1188
|
+
output(e) {
|
|
1189
|
+
if (typeof e != "string" || new TextEncoder().encode(e).length > J.outputBytes) throw Error("COMPILE_OUTPUT_LIMIT");
|
|
1190
|
+
let t = this.codec.inspect({
|
|
1191
|
+
html: e,
|
|
1192
|
+
css: ""
|
|
1193
|
+
}, "email");
|
|
1194
|
+
if (!t.document || t.diagnostics.some((e) => e.severity !== "info")) throw Error("COMPILE_UNSAFE_OUTPUT");
|
|
1195
|
+
return e;
|
|
1196
|
+
}
|
|
1197
|
+
rawRegion(e, t, n, r) {
|
|
1198
|
+
let i = e.sourceCodeLocation;
|
|
1199
|
+
if (t !== "mj-column" || !i?.startTag || !i.endTag) throw Error("COMPILE_FORBIDDEN_TAG");
|
|
1200
|
+
let a = n.slice(i.startTag.endOffset, i.endTag.startOffset);
|
|
1201
|
+
if (!r.has(a)) throw Error("COMPILE_FORBIDDEN_TAG");
|
|
1202
|
+
}
|
|
1203
|
+
}, $ = Object.freeze({
|
|
1204
|
+
fonts: {},
|
|
1205
|
+
validationLevel: "strict",
|
|
1206
|
+
ignoreIncludes: !0,
|
|
1207
|
+
useMjmlConfigOptions: !1,
|
|
1208
|
+
keepComments: !0,
|
|
1209
|
+
minify: !1,
|
|
1210
|
+
juiceOptions: { webResources: {
|
|
1211
|
+
images: !1,
|
|
1212
|
+
scripts: !1,
|
|
1213
|
+
links: !1
|
|
1214
|
+
} }
|
|
1215
|
+
}), ee = class {
|
|
1216
|
+
source;
|
|
1217
|
+
fragments;
|
|
1218
|
+
constructor(e, t = []) {
|
|
1219
|
+
if (typeof e != "string" || !t.every((e) => typeof e == "string")) throw TypeError("INVALID_GENERATED_MJML");
|
|
1220
|
+
this.source = e, this.fragments = Object.freeze([...t]), Object.freeze(this);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
function te(e) {
|
|
1224
|
+
if (typeof e == "string") return { source: e };
|
|
1225
|
+
if (!e || typeof e != "object") return;
|
|
1226
|
+
let t = Object.getOwnPropertyDescriptor(e, "source")?.value, n = Object.getOwnPropertyDescriptor(e, "fragments")?.value;
|
|
1227
|
+
if (typeof t == "string" && Array.isArray(n) && n.every((e) => typeof e == "string")) return {
|
|
1228
|
+
source: t,
|
|
1229
|
+
fragments: n
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
//#endregion
|
|
1233
|
+
export { $ as a, N as c, Q as i, te as n, q as o, J as r, R as s, ee as t };
|
|
1234
|
+
|
|
1235
|
+
//# sourceMappingURL=generated-mjml-CtzE-f3v.js.map
|