@panphora/clayjs 1.12.1 → 1.12.2
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 +1 -1
- package/dist/clay.standalone.js +319 -184
- package/entries/clay-data.js +1 -1
- package/package.json +12 -1
- package/src/loader-logic.js +5 -1
- package/src/loader.js +2 -0
- package/src/page/model.js +213 -0
- package/src/page/schema.js +157 -0
- package/src/plugins/message.js +159 -0
- package/src/plugins/visitor-drafts/prompt-style.js +5 -16
- package/src/plugins/visitor-drafts/prompt.js +6 -41
- package/src/plugins/visitor-drafts/source.js +0 -5
- package/src/plugins/visitor-drafts.js +2 -2
- package/src/vendor/hyper-html-api-data.vendor.js +1 -1
- package/src/vendor/prosemirror.vendor.js +12 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* message.js — send a visitor's form to the document's owner (the host's `/_/message`).
|
|
3
|
+
*
|
|
4
|
+
* <form message-form="Thanks, I'll reply soon"> ... </form>
|
|
5
|
+
* const result = await clay.message.send({ email, note }); // { ok, error }
|
|
6
|
+
*
|
|
7
|
+
* Any form carrying `message-form`, or whose `action` is `/_/message`, is sent by
|
|
8
|
+
* script on submit: its fields as JSON, with the `Document-URL` header so the host
|
|
9
|
+
* knows whose document it came from. The form resets, the attribute's text shows
|
|
10
|
+
* as a toast, and `clay:message-sent` or `clay:message-failed` fires on the form.
|
|
11
|
+
* Cancel that event to draw your own confirmation instead of the toast.
|
|
12
|
+
*
|
|
13
|
+
* The bot check. The host refuses a message that carries no token from
|
|
14
|
+
* `GET /_/form-token`, so a bot that posts without running the page sends nothing.
|
|
15
|
+
* The token is fetched the first time the visitor focuses or types inside a
|
|
16
|
+
* message form (an untouched form costs no request), and again at submit when it
|
|
17
|
+
* is missing or old. Each token is used once. `formSignals` counts trusted
|
|
18
|
+
* events and reads `navigator.webdriver`; the host only logs it.
|
|
19
|
+
*
|
|
20
|
+
* `send` never rejects, matching upload: one result shape from every exit.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import getDataFromForm from "../dom/form-data.js";
|
|
24
|
+
|
|
25
|
+
const MESSAGE_PATH = "/_/message";
|
|
26
|
+
const TOKEN_PATH = "/_/form-token";
|
|
27
|
+
// The host accepts a token for two hours; refetch well before that.
|
|
28
|
+
const TOKEN_MAX_AGE_MS = 90 * 60 * 1000;
|
|
29
|
+
|
|
30
|
+
const TRUSTED_EVENTS = ["click", "keydown", "pointerdown", "touchstart", "input", "change"];
|
|
31
|
+
const trusted = Object.fromEntries(TRUSTED_EVENTS.map((type) => [type, 0]));
|
|
32
|
+
|
|
33
|
+
let token = null;
|
|
34
|
+
let tokenAt = 0;
|
|
35
|
+
let tokenRequest = null;
|
|
36
|
+
const sending = new WeakSet();
|
|
37
|
+
|
|
38
|
+
function fetchToken() {
|
|
39
|
+
if (!tokenRequest) {
|
|
40
|
+
tokenRequest = fetch(TOKEN_PATH, { credentials: "omit", cache: "no-store" })
|
|
41
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
42
|
+
.then((body) => {
|
|
43
|
+
if (body && typeof body.token === "string") {
|
|
44
|
+
token = body.token;
|
|
45
|
+
tokenAt = Date.now();
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.catch(() => {})
|
|
49
|
+
.finally(() => {
|
|
50
|
+
tokenRequest = null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return tokenRequest;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function takeToken() {
|
|
57
|
+
if (!token || Date.now() - tokenAt > TOKEN_MAX_AGE_MS) await fetchToken();
|
|
58
|
+
const taken = token;
|
|
59
|
+
token = null;
|
|
60
|
+
return taken;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function signals() {
|
|
64
|
+
return { webdriver: navigator.webdriver === true, trusted: { ...trusted } };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isMessageForm(form) {
|
|
68
|
+
if (!(form instanceof HTMLFormElement)) return false;
|
|
69
|
+
if (form.hasAttribute("message-form")) return true;
|
|
70
|
+
const action = form.getAttribute("action");
|
|
71
|
+
if (!action) return false;
|
|
72
|
+
try {
|
|
73
|
+
const url = new URL(action, window.location.href);
|
|
74
|
+
return url.origin === window.location.origin && url.pathname === MESSAGE_PATH;
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Send one message to the document's owner.
|
|
82
|
+
*
|
|
83
|
+
* @param {Object} data - the fields, as the owner should read them
|
|
84
|
+
* @returns {Promise<{ok: boolean, error: ?string}>}
|
|
85
|
+
*/
|
|
86
|
+
export async function send(data = {}) {
|
|
87
|
+
const result = await post(data);
|
|
88
|
+
// The host refused the token itself (it restarted, or the token expired): one fresh token,
|
|
89
|
+
// one more try, and the visitor never knows.
|
|
90
|
+
if (result.code === "form-token") return post(data);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function post(data) {
|
|
95
|
+
const formToken = await takeToken();
|
|
96
|
+
let res;
|
|
97
|
+
try {
|
|
98
|
+
res = await fetch(MESSAGE_PATH, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
// A signed-in owner testing their own form must not trip the host's CSRF
|
|
101
|
+
// guard, and the message never needs the visitor's cookies.
|
|
102
|
+
credentials: "omit",
|
|
103
|
+
headers: { "Content-Type": "application/json", "Document-URL": window.location.href },
|
|
104
|
+
body: JSON.stringify({ ...data, formToken, formSignals: signals() }),
|
|
105
|
+
});
|
|
106
|
+
} catch {
|
|
107
|
+
return { ok: false, error: "The message couldn't be sent. Check your connection and try again." };
|
|
108
|
+
}
|
|
109
|
+
const body = await res.json().catch(() => null);
|
|
110
|
+
// A host without the message endpoint can answer any path with its HTML page at 200.
|
|
111
|
+
if (res.ok) return body ? { ok: true, error: null } : { ok: false, error: "This page can't send messages." };
|
|
112
|
+
if (!body) return { ok: false, error: `The message couldn't be sent (${res.status}).` };
|
|
113
|
+
const error = body.error || body.msg || `The message couldn't be sent (${res.status}).`;
|
|
114
|
+
return body.code === "form-token" ? { ok: false, error, code: "form-token" } : { ok: false, error };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function onSubmit(event) {
|
|
118
|
+
const form = event.target;
|
|
119
|
+
if (event.defaultPrevented || !isMessageForm(form)) return;
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
if (sending.has(form)) return;
|
|
122
|
+
sending.add(form);
|
|
123
|
+
try {
|
|
124
|
+
const result = await send(getDataFromForm(form));
|
|
125
|
+
if (result.ok) form.reset();
|
|
126
|
+
const outcome = new CustomEvent(result.ok ? "clay:message-sent" : "clay:message-failed", {
|
|
127
|
+
bubbles: true,
|
|
128
|
+
cancelable: true,
|
|
129
|
+
detail: result,
|
|
130
|
+
});
|
|
131
|
+
if (!form.dispatchEvent(outcome)) return;
|
|
132
|
+
const toast = window.clay?.toast;
|
|
133
|
+
if (!toast) return;
|
|
134
|
+
if (result.ok) toast(form.getAttribute("message-form") || "Sent", "success");
|
|
135
|
+
else toast(result.error, "error");
|
|
136
|
+
} finally {
|
|
137
|
+
sending.delete(form);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function warmToken(event) {
|
|
142
|
+
if (token || tokenRequest) return;
|
|
143
|
+
const form = event.target?.closest?.("form");
|
|
144
|
+
if (form && isMessageForm(form)) fetchToken();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (typeof document !== "undefined") {
|
|
148
|
+
for (const type of TRUSTED_EVENTS) {
|
|
149
|
+
document.addEventListener(type, (event) => {
|
|
150
|
+
if (event.isTrusted) trusted[type]++;
|
|
151
|
+
}, { capture: true, passive: true });
|
|
152
|
+
}
|
|
153
|
+
document.addEventListener("focusin", warmToken, true);
|
|
154
|
+
document.addEventListener("input", warmToken, true);
|
|
155
|
+
document.addEventListener("submit", onSubmit);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const message = { send };
|
|
159
|
+
export default message;
|
|
@@ -91,6 +91,8 @@ export const PROMPT_CSS = `.hcp {
|
|
|
91
91
|
.hcp .hcp-btn--primary:hover { background: color-mix(in srgb, var(--hcp-ink), var(--hcp-ground) 12%); color: var(--hcp-ground); }
|
|
92
92
|
|
|
93
93
|
.hcp-dock { display: flex; align-items: stretch; box-shadow: 0 6px 16px -8px rgba(43, 36, 27, .45); }
|
|
94
|
+
.hcp:not([data-hcp-arrived]) .hcp-dock { animation: hcp-arrive 2.4s cubic-bezier(.16, 1, .3, 1) 3s both; }
|
|
95
|
+
@keyframes hcp-arrive { from { transform: translateX(calc(100% + 48px)); } to { transform: none; } }
|
|
94
96
|
.hcp-tab { font-size: 13.5px; padding: 0 12px 0 10px; }
|
|
95
97
|
.hcp-tab svg { color: var(--hcp-brass); }
|
|
96
98
|
.hcp-dock .hcp-x {
|
|
@@ -151,22 +153,7 @@ export const PROMPT_CSS = `.hcp {
|
|
|
151
153
|
.hcp-file small { display: block; font-size: 12px; color: var(--hcp-muted); line-height: 1.4; }
|
|
152
154
|
.hcp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
|
|
153
155
|
.hcp-actions .hcp-btn--primary { flex: 1 1 auto; }
|
|
154
|
-
.hcp-
|
|
155
|
-
.hcp-signup label { display: block; font-size: 13px; line-height: 1.45; color: var(--hcp-ink-2); margin-bottom: 8px; }
|
|
156
|
-
.hcp-signup-row { display: flex; gap: 8px; }
|
|
157
|
-
.hcp-signup-row[hidden] { display: none; }
|
|
158
|
-
.hcp-signup input[type="email"] {
|
|
159
|
-
flex: 1 1 auto; min-width: 0; height: 34px; padding: 0 10px; margin: 0;
|
|
160
|
-
font: 14px var(--hcp-sans); color: var(--hcp-ink); background: var(--hcp-surface);
|
|
161
|
-
border: 1px solid var(--hcp-line-2); border-radius: 0; box-shadow: none;
|
|
162
|
-
}
|
|
163
|
-
.hcp-signup input[type="email"]:focus-visible { outline: 2px solid var(--hcp-brass); outline-offset: 1px; }
|
|
164
|
-
.hcp-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
|
|
165
|
-
.hcp-msg { margin-top: 8px; font-size: 13px; color: var(--hcp-ink-2); }
|
|
166
|
-
.hcp[data-hcp-reason="error"] .hcp-signup { display: none; }
|
|
167
|
-
@media (max-width: 360px) { .hcp-signup-row { flex-direction: column; } }
|
|
168
|
-
.hcp-foot { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
|
|
169
|
-
.hcp-foot small { font-size: 12px; color: var(--hcp-muted); }
|
|
156
|
+
.hcp-foot { margin-top: 12px; display: flex; justify-content: flex-end; }
|
|
170
157
|
.hcp-quiet {
|
|
171
158
|
min-height: 0; border-radius: 0;
|
|
172
159
|
font-size: 12px; color: var(--hcp-muted); cursor: pointer;
|
|
@@ -188,6 +175,8 @@ export const PROMPT_CSS = `.hcp {
|
|
|
188
175
|
@media (prefers-reduced-motion: reduce) {
|
|
189
176
|
.hcp { transition: none; }
|
|
190
177
|
.hcp[data-hcp-state="card"] .hcp-card { animation: none; }
|
|
178
|
+
.hcp:not([data-hcp-arrived]) .hcp-dock { animation: hcp-arrive-fade .4s ease 3s both; }
|
|
179
|
+
@keyframes hcp-arrive-fade { from { opacity: 0; } to { opacity: 1; } }
|
|
191
180
|
.hcp-btn:active > span { translate: none; }
|
|
192
181
|
}
|
|
193
182
|
@media (forced-colors: active) {
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { PROMPT_CSS } from "./prompt-style.js";
|
|
2
2
|
import { announceBottomUi, bottomBarHeight } from "./bottom-ui.js";
|
|
3
3
|
|
|
4
|
-
export const SIGNUP_COPY = {
|
|
5
|
-
thanks: "Thanks. Check your email for a link to confirm.",
|
|
6
|
-
failed: "That didn't go through. Check the address and try again.",
|
|
7
|
-
};
|
|
8
|
-
|
|
9
4
|
const FONT_HREF = "https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500&family=IBM+Plex+Sans:wght@400;500;600&family=Newsreader:opsz,wght@6..72,500&display=swap";
|
|
10
5
|
|
|
11
6
|
const ASIDE = `<aside class="hcp" id="hcp" hidden aria-label="Download this app" data-hcp-state="tab" data-hcp-reason="open" sap-ignore clay="editor-ui">
|
|
@@ -18,18 +13,10 @@ const ASIDE = `<aside class="hcp" id="hcp" hidden aria-label="Download this app"
|
|
|
18
13
|
<svg width="20" height="20" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true"><path d="M224,144v64a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V144a8,8,0,0,1,16,0v56H208V144a8,8,0,0,1,16,0Zm-101.66,5.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0-11.32-11.32L136,124.69V32a8,8,0,0,0-16,0v92.69L93.66,98.34a8,8,0,0,0-11.32,11.32Z"/></svg>
|
|
19
14
|
<div><b class="hcp-name" data-hcp-name>This app</b><small>One file with the whole app and your work in it</small></div>
|
|
20
15
|
</div>
|
|
21
|
-
<p class="hcp-body">Open it with HTML Clay, a free app for Mac, Windows and Linux. It opens the file in a window and saves every change into it, so your work stays on your computer.</p>
|
|
22
16
|
<div class="hcp-actions">
|
|
23
17
|
<a class="hcp-btn hcp-btn--primary" data-hcp-link href="/_/download?as=htmlclay"><span><svg width="16" height="16" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true"><path d="M224,144v64a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V144a8,8,0,0,1,16,0v56H208V144a8,8,0,0,1,16,0Zm-101.66,5.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0-11.32-11.32L136,124.69V32a8,8,0,0,0-16,0v92.69L93.66,98.34a8,8,0,0,0-11.32,11.32Z"/></svg>Download free</span></a>
|
|
24
|
-
<button type="button" class="hcp-btn" data-hcp="minimize"><span>Not now</span></button>
|
|
25
18
|
</div>
|
|
26
|
-
<
|
|
27
|
-
<label for="hcp-email">I make one of these about every two weeks. Get the next one by email.</label>
|
|
28
|
-
<div class="hcp-signup-row"><input id="hcp-email" type="email" autocomplete="email" required placeholder="you@example.com"><button type="submit" class="hcp-btn"><span>Send me the next one</span></button></div>
|
|
29
|
-
<input class="hcp-hp" name="website" tabindex="-1" autocomplete="off" aria-hidden="true">
|
|
30
|
-
<p class="hcp-msg" role="status" hidden></p>
|
|
31
|
-
</form>
|
|
32
|
-
<div class="hcp-foot"><small>Free, and the file is yours to keep.</small><button type="button" class="hcp-quiet" data-hcp="dismiss">Don’t show again</button></div>
|
|
19
|
+
<div class="hcp-foot"><button type="button" class="hcp-quiet" data-hcp="dismiss">Don’t show again</button></div>
|
|
33
20
|
</section>
|
|
34
21
|
<div class="hcp-dock">
|
|
35
22
|
<button type="button" class="hcp-btn hcp-tab" data-hcp="open" aria-controls="hcp-card" aria-expanded="false" aria-label="This app is free to keep"><span><svg width="16" height="16" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true"><path d="M224,144v64a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V144a8,8,0,0,1,16,0v56H208V144a8,8,0,0,1,16,0Zm-101.66,5.66a8,8,0,0,0,11.32,0l40-40a8,8,0,0,0-11.32-11.32L136,124.69V32a8,8,0,0,0-16,0v92.69L93.66,98.34a8,8,0,0,0-11.32,11.32Z"/></svg><span class="hcp-tab__label">This app is free to keep</span></span></button>
|
|
@@ -37,7 +24,7 @@ const ASIDE = `<aside class="hcp" id="hcp" hidden aria-label="Download this app"
|
|
|
37
24
|
</div>
|
|
38
25
|
</aside>`;
|
|
39
26
|
|
|
40
|
-
export function mountPrompt({ memory, appName, link
|
|
27
|
+
export function mountPrompt({ memory, appName, link }) {
|
|
41
28
|
if (!document.getElementById("hcp-style")) {
|
|
42
29
|
document.head.insertAdjacentHTML("beforeend", `<link rel="stylesheet" clay="editor-ui" href="${FONT_HREF}">\n<style clay="editor-ui" id="hcp-style">${PROMPT_CSS}</style>`);
|
|
43
30
|
}
|
|
@@ -55,31 +42,6 @@ export function mountPrompt({ memory, appName, link, tag, source }) {
|
|
|
55
42
|
const linkEl = root.querySelector("[data-hcp-link]");
|
|
56
43
|
linkEl.href = link;
|
|
57
44
|
|
|
58
|
-
const signup = root.querySelector("[data-hcp-signup]");
|
|
59
|
-
if (signup) {
|
|
60
|
-
const email = signup.querySelector("#hcp-email");
|
|
61
|
-
const honey = signup.querySelector(".hcp-hp");
|
|
62
|
-
const row = signup.querySelector(".hcp-signup-row");
|
|
63
|
-
const message = signup.querySelector(".hcp-msg");
|
|
64
|
-
signup.addEventListener("submit", (event) => {
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
fetch("/_/newsletter/subscribe", {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: { "Content-Type": "application/json" },
|
|
69
|
-
credentials: "same-origin",
|
|
70
|
-
body: JSON.stringify({ email: email.value.trim(), tags: [tag], source, website: honey.value }),
|
|
71
|
-
}).then((response) => {
|
|
72
|
-
if (!response.ok) throw new Error("signup failed");
|
|
73
|
-
row.hidden = true;
|
|
74
|
-
message.textContent = SIGNUP_COPY.thanks;
|
|
75
|
-
message.hidden = false;
|
|
76
|
-
}).catch(() => {
|
|
77
|
-
message.textContent = SIGNUP_COPY.failed;
|
|
78
|
-
message.hidden = false;
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
45
|
if (appName) root.querySelector("[data-hcp-name]").textContent = appName;
|
|
84
46
|
|
|
85
47
|
const tab = root.querySelector("[data-hcp=open]");
|
|
@@ -88,7 +50,7 @@ export function mountPrompt({ memory, appName, link, tag, source }) {
|
|
|
88
50
|
root.setAttribute("data-hcp-state", state);
|
|
89
51
|
if (reason) root.setAttribute("data-hcp-reason", reason);
|
|
90
52
|
tab.setAttribute("aria-expanded", state === "card" ? "true" : "false");
|
|
91
|
-
if (state === "card") { mem.shown = true; memory.save(); }
|
|
53
|
+
if (state === "card") { mem.shown = true; memory.save(); root.setAttribute("data-hcp-arrived", ""); }
|
|
92
54
|
lift();
|
|
93
55
|
}
|
|
94
56
|
|
|
@@ -176,6 +138,9 @@ export function mountPrompt({ memory, appName, link, tag, source }) {
|
|
|
176
138
|
mem.downloaded = true; mem.shown = true; memory.save();
|
|
177
139
|
}
|
|
178
140
|
});
|
|
141
|
+
root.addEventListener("animationend", (e) => {
|
|
142
|
+
if (e.animationName === "hcp-arrive" || e.animationName === "hcp-arrive-fade") root.setAttribute("data-hcp-arrived", "");
|
|
143
|
+
});
|
|
179
144
|
root.addEventListener("keydown", (e) => {
|
|
180
145
|
if (e.key === "Escape" && root.getAttribute("data-hcp-state") === "card") { set("mini"); tab.focus(); }
|
|
181
146
|
});
|
|
@@ -14,8 +14,3 @@ export function downloadUrl(src, loc = window.location) {
|
|
|
14
14
|
return `/_/download${path}?as=htmlclay${src ? `&src=${encodeURIComponent(src)}` : ""}`;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function signupTag(slot, template) {
|
|
18
|
-
const explicit = template?.getAttribute("signup-tag");
|
|
19
|
-
const name = explicit || slot.replace(/-v\d+$/, "");
|
|
20
|
-
return `app-${name}`.slice(0, 50);
|
|
21
|
-
}
|
|
@@ -3,7 +3,7 @@ import { hasSaveToken } from "../core/host-attrs.js";
|
|
|
3
3
|
import { draftSlot, setDraftTransport, setDraftFlush } from "../core/draft-mode.js";
|
|
4
4
|
import { createStore, safeStorage } from "./visitor-drafts/store.js";
|
|
5
5
|
import { createUiMemory } from "./visitor-drafts/ui-memory.js";
|
|
6
|
-
import { rememberSource, downloadUrl
|
|
6
|
+
import { rememberSource, downloadUrl } from "./visitor-drafts/source.js";
|
|
7
7
|
import { mountPrompt } from "./visitor-drafts/prompt.js";
|
|
8
8
|
import { mountIntro } from "./visitor-drafts/intro.js";
|
|
9
9
|
import { mountOwnerChip } from "./visitor-drafts/owner-chip.js";
|
|
@@ -30,7 +30,7 @@ if (isDraftMode && slot && rulesTag) {
|
|
|
30
30
|
const appName = document.querySelector('meta[name="application-name"]')?.content?.trim() || document.title.split(/:|\s\|\s/)[0].trim() || "This app";
|
|
31
31
|
const template = document.querySelector("template[visitor-intro]");
|
|
32
32
|
const start = () => {
|
|
33
|
-
const prompt = mountPrompt({ memory, appName, link: downloadLink
|
|
33
|
+
const prompt = mountPrompt({ memory, appName, link: downloadLink });
|
|
34
34
|
mountIntro({ memory, template, appName, hadDraft: result.hadDraft });
|
|
35
35
|
if (isOwner) mountOwnerChip();
|
|
36
36
|
document.addEventListener("clay:drafts-store-failed", () => prompt.showError());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// GENERATED — do not edit. Vendored from
|
|
2
2
|
// hyper-html-api/dist/hyper-html-api.engine.esm.js via hyper-html-api
|
|
3
3
|
// `npm run copy-to-clayjs`. Edit the hyper-html-api source and re-run.
|
|
4
|
-
var Qe=Object.defineProperty;var et=(e,t)=>{for(var n in t)Qe(e,n,{get:t[n],enumerable:!0})};var X=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Y=new Set(X),re=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),$=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Ee=new Set(["checked","selected","disabled","readOnly","paused"]);function ie(e,t){return t==null?Ee.has(e)?!1:"":Ee.has(e)?t==="false"?!1:!!t:t}var R={};et(R,{EmptyListInsert:()=>N,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>oe,RuleTargetReadOnly:()=>B,RulesParseError:()=>k,ShapeMismatch:()=>v,UnknownRulesVersion:()=>W,WriteNotRoundTripped:()=>Z,WriteRefused:()=>H,WriteRejected:()=>se});var k=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},W=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},L=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},v=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},N=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},B=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},H=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function tt(e){return e.reduce((n,r)=>typeof r=="number"?`${n}[${r}]`:n?`${n}.${r}`:String(r),"")||"(root)"}var Z=class extends Error{constructor(t){super(`write did not round-trip at "${tt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},oe=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},se=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function b(e){let t=0,n=null,r=-1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(r=i)}return r}function le(e){let t=b(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function ce(e){let t=0,n=null,r=-1,i=!1;for(let s=0;s<e.length;s++){let l=e[s];l==="\\"?s++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?r=s:t===0&&l===","&&(i=!0)}return i||r===-1||!nt(e,r+1)?null:e.slice(0,r).trim()||null}function nt(e,t){let n=t,r=e.replace(/\s+$/,"").length;for(;n<r&&/\s/.test(e[n]);)n++;let i=0,s=null;for(;n<r;n++){let l=e[n];if(l==="\\")n++;else if(s)l===s&&(s=null);else if(l==='"'||l==="'")s=l;else if(l==="["||l==="(")i++;else if(l==="]"||l===")")i>0&&i--;else if(i===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}function C(e,t,n,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return fe(e,t,n,{depth:0,path:[]},r)}function fe(e,t,n,r,i){if(r.depth>L)throw new P(r.path);if(typeof n=="string")return rt(e,t,n,r,i);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,i);return xe(i,r,c),c.map((o,f)=>fe(e,o,l,{depth:r.depth+1,path:[...r.path,f]},i))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=fe(e,t,c,{depth:r.depth+1,path:[...r.path,l]},i);return s}return null}function rt(e,t,n,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2),o=e.find(t,c,i);return xe(i,r,o),o.map(f=>e.text(f))}if(n.startsWith("@"))return Oe(e,t,n.slice(1));let s=b(n);if(s!==-1){let c=n.slice(0,s),o=n.slice(s+1),f=c?e.find(t,c,i):[t];return f.length===0?null:Oe(e,f[0],o)}if(n===".")return e.text(t);let l=e.find(t,n,i);return l.length===0?null:e.text(l[0])}function xe(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(r){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,r)}}function Oe(e,t,n){if(Y.has(n)){let i=e.prop(t,n);return i==null?null:String(i)}let r=e.attr(t,n);return r??null}function Re(e,t,n,r){let i=e.length,s=t.length,l=new Array(i).fill(-1);if(r){let h=new Set;for(let y=0;y<i;y++){let A=r[y];!(A>=0&&A<s)||h.has(A)||(l[y]=A,h.add(A))}}if(i===0||s===0)return l;let c=e.map(h=>Se(h,n)),o=t.map(h=>Se(h,n)),f=new Array(s).fill(!1);for(let h of l)h>=0&&(f[h]=!0);let u=new Map;o.forEach((h,y)=>{f[y]||u.set(h,u.has(h)?-1:y)});let m=new Map;c.forEach((h,y)=>{l[y]>=0||m.set(h,(m.get(h)||0)+1)}),c.forEach((h,y)=>{if(l[y]>=0||m.get(h)!==1)return;let A=u.get(h);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let d=[];for(let h=0;h<i;h++)l[h]<0&&d.push(h);let w=[];for(let h=0;h<s;h++)f[h]||w.push(h);if(d.length===0||w.length===0)return l;let a=i*s+1,p=it(e,t,n),g=(h,y)=>p(h,y)*a+Math.abs(h-y);for(let[h,y]of ot(d,w,g))l[h]=y;return l}var Ne=e=>typeof e=="object"&&e!==null;function Se(e,t){if(!Ne(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(r=>{let i=JSON.stringify(e?.[r]);return i===void 0?" undef":i}))}function it(e,t,n){if(!Ne(n))return(c,o)=>e[c]===t[o]?0:1;let r=Object.keys(n),i=c=>r.map(o=>JSON.stringify(c?.[o])),s=e.map(i),l=t.map(i);return(c,o)=>{let f=s[c],u=l[o],m=0;for(let d=0;d<r.length;d++)f[d]!==u[d]&&m++;return m}}function ot(e,t,n){return e.length<=t.length?be(e,t,n,!1):be(t,e,(r,i)=>n(i,r),!0)}function be(e,t,n,r){let i=e.length,s=t.length,l=[];for(let m=0;m<=i;m++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let m=0;m<=i;m++)c.push(new Uint8Array(s+1));for(let m=0;m<=s;m++)l[i][m]=0;for(let m=i-1;m>=0;m--)for(let d=s-1;d>=0;d--){let w=n(e[m],t[d])+l[m+1][d+1],a=l[m][d+1];w<=a?(l[m][d]=w,c[m][d]=1):l[m][d]=a}let o=[],f=0,u=0;for(;f<i&&u<s;)c[f][u]&&(o.push(r?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return o}function ae(e,t,n,r,i,s,l,c={}){let o=e.find(t,n,c);if(i.length===0){o.forEach(T=>e.remove(T)),ue(c,"onRowsApplied",s.path,[]);return}let f=i.length>o.length,u=o[0]||null;if(f&&!u&&(u=ft(e,t,n,c),!u))throw new N(s.path);let m=o.map(T=>ct(e,T,r,c)),d=null;if(f&&u){d=e.clone(u),c.templateAttr&&e.removeAttr(d,c.templateAttr);let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let w=Re(i,m,r,st(e,o,i,s,c)),a=o.length>0?e.parent(o[0]):dt(e,t,n,u,s,c),p=o.length>0?ke(e,a,o[0]):0,g=yt(e,o),h=new Set,y=[],A=i.map((T,S)=>{let O=w[S];if(O>=0)return h.add(O),y.push(!1),o[O];y.push(!0);let E=e.clone(d);return e.stripIds(E),E});o.forEach((T,S)=>{h.has(S)||e.remove(T)}),g?mt(e,a,p,A,y):gt(e,A,y,a,p),lt(e,A,r,i,s,l,c),ue(c,"onRowsApplied",s.path,A)}function ue(e,t,n,r){if(typeof e[t]=="function")try{return e[t](n.slice(),r)}catch(i){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,i);return}}function st(e,t,n,r,i){let s=ue(i,"identifyRows",r.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set,o=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!s[f])continue;let u=o.get(e.identity(s[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function lt(e,t,n,r,i,s,l){t.forEach((c,o)=>{if(n===null){let f=r[o],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,r[o],{depth:i.depth+1,path:[...i.path,o]},l);f&&f!==c&&(t[o]=f)}})}function ct(e,t,n,r){return n===null?e.text(t):C(e,t,n,r.onRowsRead?{...r,onRowsRead:void 0}:r)}function ke(e,t,n){let r=e.children(t);for(let i=0;i<r.length;i++)if(e.sameNode(r[i],n))return i;return-1}function ft(e,t,n,r){if(!r.templateAttr)return null;let i=/^\s*:scope\s*>\s*/.test(n),s=new RegExp(":not\\(\\["+r.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(s,""),c=i?ut(l):0,o=ce(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let m of u)if(e.attr(m,r.templateAttr)!=null&&!(i&&!ht(e,t,m,c))&&!(o&&!e.matches(e.parent(m),o)))return m;f=e.parent(f)}return null}function ut(e){let t=0,n=null,r=1;for(let i=0;i<e.length;i++){let s=e[i];if(s==="\\")i++;else if(n)s===n&&(n=null);else if(s==='"'||s==="'")n=s;else if(s==="["||s==="(")t++;else if(s==="]"||s===")")t>0&&t--;else if(t===0&&s===">")r++;else{if(t===0&&(s==="+"||s==="~"))return null;if(t===0&&/\s/.test(s)){if(!at(e,i))return null;for(;i+1<e.length&&/\s/.test(e[i+1]);)i++}}}return r}function at(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let r=t>0?e[t-1]:"",i=n<e.length?e[n]:"";return Ce(r)||Ce(i)}function Ce(e){return e===">"||e==="+"||e==="~"}function ht(e,t,n,r){if(r===null)return!0;let i=n;for(let o=0;o<r;o++)if(i=e.parent(i),!i)return!1;let s=e.prop(t,"tagName");if(!s)return!0;let l=e.prop(i,"tagName");if(!l||String(l).toLowerCase()!==String(s).toLowerCase())return!1;let c=new Set(Me(e,i));return Me(e,t).every(o=>c.has(o))}function Me(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function dt(e,t,n,r,i,s){let l=e.parent(r);if(l&&pt(e,t,l)&&!Ie(e,l,s))return l;let c=ce(n);if(!c)throw new N(i.path,`the list selector "${n}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,s)).filter(u=>!Ie(e,u,s));if(f.length===0)throw new N(i.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new N(i.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function pt(e,t,n){let r=n;for(;r;){if(e.sameNode(r,t))return!0;r=e.parent(r)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(i=>e.sameNode(i,n))}var Pe=["no-data","editor-ui"];function Ie(e,t,n){let r=t;for(;r;){if(n.templateAttr&&e.attr(r,n.templateAttr)!=null||Pe.some(s=>e.attr(r,s)!=null))return!0;let i=e.attr(r,"clay");if(i&&i.split(/\s+/).some(s=>Pe.includes(s)))return!0;r=e.parent(r)}return!1}function mt(e,t,n,r,i){let s=e.children(t),l=s.map(o=>e.identity(o)),c=!1;r.forEach((o,f)=>{let u=e.identity(o),m=n+f;if(l[m]===u)return;if(!i[f]){let w=l.indexOf(u);w!==-1&&(l.splice(w,1),s.splice(w,1))}let d=Math.min(m,s.length);d<s.length?e.insertBefore(s[d],o):s.length?c?e.insertAfter(s[s.length-1],o):(e.insertAt(t,o,m),c=!0):e.insertAt(t,o,0),l.splice(d,0,u),s.splice(d,0,o)})}function yt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let r=new Map(e.children(n).map((s,l)=>[e.identity(s),l])),i=[];for(let s of t){let l=r.get(e.identity(s));if(l===void 0)return!1;i.push(l)}return i.sort((s,l)=>s-l),i[i.length-1]-i[0]===i.length-1}function gt(e,t,n,r,i){let s=null,l=i;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let o=s?e.parent(s):r;if(!o)continue;let f=s?ke(e,o,s)+1:l++;e.insertAt(o,t[c],f),s=t[c]}}function I(e,t,n,r,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(he(n,r,[],s),s.length)throw new v(s);Q(e,t,n,r,{depth:0,path:[]},i)}function Q(e,t,n,r,i,s={}){if(i.depth>L)throw new P(i.path);if(r===void 0)return t;if(typeof n=="string")return At(e,t,n,r,i,s);if(Array.isArray(n)){let[l,c]=n;return ae(e,t,l,c,r,i,Q,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let o=Q(e,t,c,r==null?r:r[l],{depth:i.depth+1,path:[...i.path,l]},s);o&&o!==t&&(t=o)}return t}return t}function At(e,t,n,r,i,s){if(n.endsWith("[]")){let o=n.slice(0,-2);return ae(e,t,o,null,r,i,Q,s),t}if(n.startsWith("@"))return je(e,t,n.slice(1),r);let l=b(n);if(l!==-1){let o=n.slice(0,l),f=n.slice(l+1),u=o?e.find(t,o,s):[t];return u.length===0||je(e,u[0],f,r),t}if(n===".")return Le(e,t,r),t;let c=e.find(t,n,s);return c.length===0||Le(e,c[0],r),t}function Le(e,t,n){let r=n==null?"":String(n);e.text(t)!==r&&e.text(t,r)}function je(e,t,n,r){if($.has(n)){let i=e.prop(t,n);if(i===r||i!=null&&r!=null&&String(i)===String(r))return t;throw new B(n)}if(n==="outerHTML"){let i=r==null?"":String(r);return e.replaceWith(t,i)}if(re.has(n)){let i=ie(n,r);return e.prop(t,n)!==i&&e.prop(t,n,i),t}if(r==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let i=String(r);e.attr(t,n)!==i&&e.attr(t,n,i)}return t}function he(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((i,s)=>{typeof i=="object"&&i!==null&&r.push({path:U([...n,s]),expected:"scalar",got:q(i)})}):r.push({path:U(n),expected:"array",got:q(t)});return}t!==null&&typeof t=="object"&&r.push({path:U(n),expected:"scalar",got:q(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){r.push({path:U(n),expected:"array",got:q(t)});return}let i=e[1];t.forEach((s,l)=>he(i,s,[...n,l],r));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){r.push({path:U(n),expected:"object",got:q(t)});return}for(let[i,s]of Object.entries(e))he(s,t[i],[...n,i],r)}}}function q(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function de(e){try{return JSON.parse(e)}catch(t){throw new k(`Invalid strict JSON: ${t.message}`,t)}}function z(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(i){let s=[],l=0;for(;l<i.length;){let c=i[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){s.push({type:c,value:c}),l++;continue}if(c==="["){let m=!1,d=l+1;for(;d<i.length&&/\s/.test(i[d]);)d++;if(d<i.length&&/[a-zA-Z_]/.test(i[d])&&(m=!0),!m){s.push({type:c,value:c}),l++;continue}}if(c==="]"){s.push({type:c,value:c}),l++;continue}if(c===":"){s.push({type:t.COLON,value:c}),l++;continue}if(c===","){s.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let m=c,d=l+1;for(;d<i.length&&i[d]!==m;)i[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:i.substring(l+1,d),quoted:!0,sourceQuote:m}),l=d+1;continue}let o=l,f;for(;o<i.length&&!/[{},]/.test(i[o]);)if(i[o]===":"){let m=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let w of m){let a=w.substring(1);if(i.substring(o+1,o+1+a.length)===a){d=!0,o+=a.length;break}}if(!d)break}else if(i[o]==="["){for(o++;o<i.length&&i[o]!=="]";){if(i[o]==='"'||i[o]==="'"){let m=i[o];for(o++;o<i.length&&i[o]!==m;)i[o]==="\\"&&o++,o++}o++}o<i.length&&i[o]==="]"&&o++}else o++;f=i.substring(l,o);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),s.push({type:u,value:f,quoted:!1}),l=o}return s}function r(i){let s="";for(let l=0;l<i.length;l++){let c=i[l];if("{}".includes(c.type)||"[]".includes(c.type)){s+=c.value;continue}if(c.type===t.COLON){s+=c.value;continue}if(c.type===t.COMMA){let o=i[l+1];if(o&&(o.type==="}"||o.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let o=c.value;c.sourceQuote==="'"&&(o=o.replace(/\\'/g,"'"),o=o.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${o}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){s+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){s+=`"${c.value}"`;continue}s+=`"${c.value}"`}return s}try{let i=n(e),s=r(i);return JSON.parse(s)}catch(i){throw new k("Invalid extraction rules syntax: "+i.message,i)}}var Tt="1",_e=/^[a-zA-Z0-9_-]+$/;function j(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!_e.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${_e})`);r=`script[data-rules-name~="${n}"]`}let i=e.find(t,r,{includeRulesTag:!0});if(i.length===0)return null;n!==void 0&&i.length>1&&console.warn(`hyper-html-api: ${i.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=i[0],l=e.attr(s,"data-rules-version");if(l!==Tt)throw new W(l);return{rules:z(e.text(s)),tagNode:s}}var ee=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),wt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),De=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function K(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function pe(e,t){if(K(e,t))return!0;for(let[n,r]of Object.entries(wt))if(r.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=ee[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Et(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let r=ee[t];if(!r)throw new Error(`Unknown region capability: ${t}`);if(r.tokens.some(i=>pe(n,i))||r.bundles.some(i=>K(n,i)))return n;n=n.parentElement}return null}function $e(e,t){return!!Et(e,t)}var me=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...De],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]}),Ot=new Set(["textContent","innerText"]);function We(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var xt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function ve(e,t,n=me){if(!xt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let r=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(i=>r.startsWith(i)))return`attribute "${r}" can run script`;if(n.refusedAttributes.includes(r))return`attribute "${r}" is not content`;if(n.urlAttributes.includes(r)&&t!=null){let i=r==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of i){let l=We(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${r}"`}}return null}function ye(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function St(e,t){let n=ye(e,t)||"node",r=e.attr(t,"id");return r?`<${n}#${r}>`:`<${n}>`}function bt(e,t,n){let r=t;for(;r;){let i=ye(e,r);if(i&&n.refusedTargets.includes(i))return i;r=e.parent(r)}return null}function Be(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Rt(e,t){return ye(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:Be(e,t)}function te(e,t=me){let n=[],r=(o,f)=>(n.push({target:St(e,o),reason:f}),!1),i=o=>{let f=bt(e,o,t);return f?r(o,`inside <${f}>, which is not content`):!0},s=o=>i(o)?Be(e,o)?r(o,"a text write here would delete the data rules tag"):!0:!1,l=(o,f,u)=>{if(!i(o))return!1;let m=ve(f,u,t);return m?r(o,m):!0};return{...e,text(o,f){if(f===void 0)return e.text(o);s(o)&&e.text(o,f)},attr(o,f,u){if(u===void 0)return e.attr(o,f);l(o,f,u)&&e.attr(o,f,u)},removeAttr(o,f){l(o,f,null)&&e.removeAttr(o,f)},prop(o,f,u){if(u===void 0)return e.prop(o,f);if(t.refusedRuleForms.includes(f))return r(o,`"@${f}" writes HTML, only text is allowed`);if(Ot.has(f)){s(o)&&e.prop(o,f,u);return}l(o,f==="className"?"class":f,u)&&e.prop(o,f,u)},remove(o){if(Rt(e,o)){r(o,"removing this would delete the data rules tag");return}e.remove(o)},replaceWith(o,f){return f===e.prop(o,"outerHTML")||r(o,'"@outerHTML" writes HTML, only text is allowed'),o},refusals:n,assertClean(){if(n.length)throw new H(n.slice())}}}function V(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function He(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function ge(e,t,n,r,i={}){let s=[],l=[];function c(f,u,m){if(Array.isArray(f)){let[,d]=f;if(!Array.isArray(u)||!V(d))return;u.forEach((w,a)=>c(d,w,[...m,a]));return}if(!(!V(f)||!V(u)))for(let d of Object.keys(u))Object.prototype.hasOwnProperty.call(f,d)?c(f[d],u[d],[...m,d]):s.push(He([...m,d]))}function o(f,u,m,d){if(m!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let w=b(u),a=w===-1?u:u.slice(0,w);if(!a)return;e.find(f,a,i).length===0&&l.push({path:He(d),selector:a});return}if(!Array.isArray(u)&&V(u)&&V(m))for(let[w,a]of Object.entries(u))o(f,a,m[w],[...d,w])}}return c(n,r,[]),o(t,n,r,[]),{unknownKeys:s,unmatched:l}}function Ae(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let r=t&&t.ownerDocument?t.ownerDocument:t;return j(e,r,n)}return null}var Ct=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Mt(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function qe(e,t,n,r){if(r)return!!e.closest?.(t);let i=e;for(;i?.nodeType===1;){if(i.matches(t))return!0;if(i===n)break;i=i.parentElement}return!1}function Ue(e,t,n,r,i,s){return(s?$e(e,t):qe(e,n,i,!1))||!!(r&&(s&&e!==i?e.matches(r):qe(e,r,i,s)))}function Pt(e,t){let n=ee[t];return n.tokens.some(r=>pe(e,r))||n.bundles.some(r=>K(e,r))}var It=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ze(e,t,n,r){if(e.nodeType===1&&r(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let i=e,s=t;if(e.nodeType===1){if(It.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);i=e.content,s=t.content,n.cloneToLive.set(s,i),n.liveToClone.set(i,s)}}else if(e.nodeType!==11)return;let l=s.firstChild;for(let c=i.firstChild;c&&l;c=c.nextSibling)ze(c,l,n,r),l=l.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:r=!0,provenance:i=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let s=e.nodeType===9?e:e.ownerDocument;if(!s?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=s.implementation.createHTMLDocument(""),c=i||new WeakMap,o=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=F(t),m=r?a=>Pt(a,t)||!!(n&&a.matches(n)):a=>Ue(a,t,u,n,f,!1),d=null;if(f.nodeType!==1||!Ue(f,t,u,n,f,r)){d=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:o,dropped:[],controls:[]};ze(f,d,a,m);for(let p of a.dropped)p.remove();for(let p=0;p<a.controls.length;p+=2)Mt(a.controls[p],a.controls[p+1])}e.nodeType===9&&d&&(l.replaceChild(d,l.documentElement),o.set(e,l),c.set(l,e));let w=a=>{if(Ct.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:d,document:l,capability:t,selector:F(t),cloneToLive:c,liveToClone:o,original(a){return c.get(a)||null},cloneOf(a){return o.get(a)||null},query(a,p=d){return w(a),Array.from(p.querySelectorAll(a),g=>c.get(g)||g)},text(a=d){return(a===d?d:o.get(a))?.textContent||""},html(a=d){return(a===d?d:o.get(a))?.innerHTML??""},clone(a=d){let p=a===d?d:o.get(a);return p?l.importNode(p,!0):null}}}function Fe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function kt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Ke(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function Ve(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Je(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let r=n.type;r!=="file"&&r!=="checkbox"&&r!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var x={semanticExclude:!0,find(e,t,n={}){let r=kt(e);if(!r||!r.querySelectorAll)return[];let i=Array.from(r.querySelectorAll(t));n.includeRulesTag||(i=i.filter(c=>!Fe(c)));let s=[];n.skip&&s.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&s.push("["+l+"]"),s.length){let c=s.join(", ");i=i.filter(o=>!o.closest||!o.closest(c))}return i},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,Ve(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Ke(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Ke(e,t,null)},prop(e,t,n){if(n===void 0){let r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return Je(t),t},insertAt(e,t,n){let r=e.children[n]||null;e.insertBefore(t,r)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let r=e.ownerDocument.createElement("template");r.innerHTML=t;let i=r.content.firstElementChild;if(!i)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(i,e),i},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return x;let n=[F("data"),t.exclude].filter(Boolean).join(", "),r=e.nodeType===9?e:e.ownerDocument||e,i=e.nodeType===9?e.documentElement:e;if(!t._write&&!i?.matches?.(n)&&!i?.querySelector?.(n)&&!r?.querySelector?.(n))return x;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,o=()=>c||(c=J(s,{capability:"data",exclude:t.exclude||null})),f=a=>{let p=o();return a===e?p.cloneOf(e):p.cloneOf(a)||a},u=a=>c?.original(a)||a,m=(a,p)=>{o().liveToClone.set(a,p),o().cloneToLive.set(p,a);let g=a.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(g.length,h.length);y++)m(g[y],h[y])},d=(a,p,g,h)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=h;for(let D of Array.from(E.content.childNodes))a.insertBefore(D,T||null)}else a.insertBefore(l.createTextNode(h),T||null),Ve(a,h);let S=J(a,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(S.root?.childNodes||[]));let O=E=>{let D=S.original(E);D&&(c.liveToClone.set(D,E),c.cloneToLive.set(E,D));for(let Ze of Array.from(E.childNodes||[]))O(Ze)};for(let E of Array.from(p.childNodes))O(E)},w={...x,find(a,p,g={}){let h=f(a);if(!h?.querySelectorAll)return[];let y=o().query(p,h);g.includeRulesTag||(y=y.filter(S=>!Fe(S)));let A=[];g.skip&&A.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&A.push(`[${T}]`),A.length){let S=A.join(", ");y=y.filter(O=>!O.closest?.(S))}return y},parent(a){let p=f(a)?.parentElement;return p?u(p):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,p){if(p===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?x.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){x.text(g,p);return}let h=o().cloneOf(g);h?d(g,h,"textContent",p):x.text(g,p)},attr(a,p,g){let h=u(a);if(g===void 0)return x.attr(h,p);x.attr(h,p,g);let y=c?.cloneOf(h);y&&(x.attr(y,p,g),J(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(h),c.cloneToLive.delete(y)))},removeAttr(a,p){let g=u(a);x.removeAttr(g,p);let h=c?.cloneOf(g);h&&x.removeAttr(h,p)},prop(a,p,g){let h=u(a);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?x.prop(f(h),p):x.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?o().cloneOf(h):c?.cloneOf(h);A&&y?d(h,A,p,g):(x.prop(h,p,g),A&&x.prop(A,p,g))},clone(a){let p=f(a);if(p===a)return x.clone(a);let g=l.importNode(p,!0);return Je(g),g},insertAt(a,p,g){let h=u(a),A=w.children(h)[g]||(()=>{for(let O=h.children.length-1;O>=0;O--){let E=h.children[O];if(o().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),T=u(p);h.insertBefore(T,A||null);let S=o().cloneOf(h);if(S){let O=o().cloneOf(T);O||(O=l.importNode(T,!0),m(T,O));let E=Array.from(S.children);S.insertBefore(O,E[g]||null)}},insertBefore(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.before(A):y.appendChild(A)}},insertAfter(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g.nextSibling);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let p=u(a),g=o().cloneOf(p);x.remove(p),g&&x.remove(g)},replaceWith(a,p){let g=u(a),h=o().cloneOf(g),y=x.replaceWith(g,p);if(h){let A=J(y,{capability:"data",exclude:t.exclude||null});if(!A.root)h.remove();else{h.replaceWith(A.root);let T=S=>{let O=A.original(S);O&&(c.liveToClone.set(O,S),c.cloneToLive.set(S,O));for(let E of Array.from(S.childNodes||[]))T(E)};T(A.root)}}return y}};return w}var G=x;var ne={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,r={})=>I(M(e,{...r,_write:!0}),e,t,n,r),findRulesIn:(e,t)=>j(G,e,t),findRules:(e,t)=>Ae(G,e,t),bind:(e,t,n={})=>{let r=Ae(G,e,t);if(!r){let i=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}return{...r,get:()=>C(M(e,n),e,r.rules,n),set:i=>I(M(e,{...n,_write:!0}),e,r.rules,i,n)}},parseStrict:de,parseRelaxed:z,ruleAttrIndex:b,splitRule:le,errors:R,DOM_PROPERTIES:X},Te=e=>!!e&&typeof e.nodeType=="number";function Ge(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=j(G,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Lt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function jt(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function _t(e,t){let n=[];for(;t!==e;){let r=t.parentNode;n.push(Array.prototype.indexOf.call(r.childNodes,t)),t=r}return n.reverse()}function Dt(e,t){return t.reduce((n,r)=>n.childNodes[r],e)}function _(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function $t(e,t){let n=_(e,"option"),r=_(t,"option");n.forEach((o,f)=>r[f].selected=o.selected);let i=_(e,"input"),s=_(t,"input");i.forEach((o,f)=>{let u=o.type.toLowerCase();u!=="file"&&(s[f].value=o.value),(u==="checkbox"||u==="radio")&&(s[f].checked=o.checked)});let l=_(e,"textarea"),c=_(t,"textarea");l.forEach((o,f)=>c[f].value=o.value)}function we(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:b(e);if(n===-1)return;let r=e.slice(n+1);if($.has(r))throw new R.RuleTargetReadOnly(r);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>we(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,r]of Object.entries(e))we(r,t[n])}}function Wt(e,t,n){let r={templateAttr:"cms-template"},i=Lt(e),s=_t(i,e),l=jt(i);$t(i,l);let c=Dt(l,s),o=M(l,{...r,_write:!0}),f=ge(o,c,t,n,r);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=te(o);I(u,c,t,n,r),u.assertClean(),we(t,n);let m=te(M(i,{...r,_write:!0}));I(m,e,t,n,r),m.assertClean()}function vt(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function Xe(e,t){let n=Te(e)?e:document,r=Te(e)?t:e;return r===void 0?C(M(n),n,Ge(n)):ne.bind(n,r).get()}function Ye(e,t,n){try{if(!Te(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let r=n===void 0?Ge(e):ne.bind(e,n).rules;Wt(e,r,t)}catch(r){throw vt(r)}return e}var Bt={engine:ne,extractData:Xe,applyData:Ye},Fn=Bt;export{Ye as applyData,Fn as default,ne as engine,Xe as extractData};
|
|
4
|
+
var Qe=Object.defineProperty;var et=(e,t)=>{for(var n in t)Qe(e,n,{get:t[n],enumerable:!0})};var G=["textContent","innerText","innerHTML","outerHTML","value","checked","selected","disabled","readOnly","type","tagName","nodeName","nodeType","nodeValue","childElementCount","id","className","classList","baseURI","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","dataset","currentSrc","duration","paused","title","documentURI","contentType"],Y=new Set(G),re=new Set(["textContent","innerText","innerHTML","value","checked","selected","disabled","readOnly","type","id","className","title"]),$=new Set(["tagName","nodeName","nodeType","nodeValue","childElementCount","classList","baseURI","documentURI","contentType","offsetWidth","offsetHeight","clientWidth","clientHeight","scrollWidth","scrollHeight","currentSrc","duration","paused","dataset"]),Ee=new Set(["checked","selected","disabled","readOnly","paused"]);function ie(e,t){return t==null?Ee.has(e)?!1:"":Ee.has(e)?t==="false"?!1:!!t:t}var R={};et(R,{EmptyListInsert:()=>N,MAX_RULE_DEPTH:()=>L,MaxRuleDepthExceeded:()=>P,NoRulesTag:()=>oe,RuleTargetReadOnly:()=>B,RulesParseError:()=>k,ShapeMismatch:()=>v,UnknownRulesVersion:()=>W,WriteNotRoundTripped:()=>Z,WriteRefused:()=>H,WriteRejected:()=>se});var k=class extends Error{constructor(t,n){super(t),this.name="RulesParseError",this.cause=n}},W=class extends Error{constructor(t){super(`unknown rules version: ${t}. Library supports "1".`),this.name="UnknownRulesVersion",this.version=t}},L=20,P=class extends Error{constructor(t){super(`rule depth exceeded ${L} at path: ${t.join(".")}`),this.name="MaxRuleDepthExceeded",this.path=t}},v=class extends Error{constructor(t){super(`shape mismatch: ${t.length} field(s) failed validation`),this.name="ShapeMismatch",this.mismatches=t}},N=class extends Error{constructor(t,n){super(n?`cannot add items to empty list at "${t.join(".")}" \u2014 ${n}`:`cannot add items to empty list at "${t.join(".")}" \u2014 no sibling to clone as template. Seed the list with a hidden item first.`),this.name="EmptyListInsert",this.path=t}},B=class extends Error{constructor(t){super(`cannot write to read-only DOM property "${t}"`),this.name="RuleTargetReadOnly",this.target=t}},H=class extends Error{constructor(t){super(`write refused: ${t.length} write(s) broke the content-only policy`),this.name="WriteRefused",this.refusals=t}};function tt(e){return e.reduce((n,r)=>typeof r=="number"?`${n}[${r}]`:n?`${n}.${r}`:String(r),"")||"(root)"}var Z=class extends Error{constructor(t){super(`write did not round-trip at "${tt(t)}"`),this.name="WriteNotRoundTripped",this.path=t}},oe=class extends Error{constructor(t){super(`no <script data-rules-name~="${t}"> rules tag in this document`),this.name="NoRulesTag",this.token=t}},se=class extends Error{constructor(t,n){super(`write rejected: ${t.length} unknown key(s), ${n.length} rule(s) with no matching element`),this.name="WriteRejected",this.unknownKeys=t,this.unmatched=n}};function b(e){let t=0,n=null,r=-1;for(let i=0;i<e.length;i++){let s=e[i];s==="\\"?i++:n?s===n&&(n=null):s==='"'||s==="'"?n=s:s==="["||s==="("?t++:s==="]"||s===")"?t>0&&t--:s==="@"&&t===0&&(r=i)}return r}function le(e){let t=b(e);return t===-1?{selector:e,prop:null}:{selector:e.slice(0,t),prop:e.slice(t+1)||null}}function ce(e){let t=0,n=null,r=-1,i=!1;for(let s=0;s<e.length;s++){let l=e[s];l==="\\"?s++:n?l===n&&(n=null):l==='"'||l==="'"?n=l:l==="["||l==="("?t++:l==="]"||l===")"?t>0&&t--:t===0&&l===">"?r=s:t===0&&l===","&&(i=!0)}return i||r===-1||!nt(e,r+1)?null:e.slice(0,r).trim()||null}function nt(e,t){let n=t,r=e.replace(/\s+$/,"").length;for(;n<r&&/\s/.test(e[n]);)n++;let i=0,s=null;for(;n<r;n++){let l=e[n];if(l==="\\")n++;else if(s)l===s&&(s=null);else if(l==='"'||l==="'")s=l;else if(l==="["||l==="(")i++;else if(l==="]"||l===")")i>0&&i--;else if(i===0&&(l==="+"||l==="~"||/\s/.test(l)))return!1}return!0}function C(e,t,n,r={}){if(Object.prototype.hasOwnProperty.call(r,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");return fe(e,t,n,{depth:0,path:[]},r)}function fe(e,t,n,r,i){if(r.depth>L)throw new P(r.path);if(typeof n=="string")return rt(e,t,n,r,i);if(Array.isArray(n)){let[s,l]=n,c=e.find(t,s,i);return xe(i,r,c),c.map((o,f)=>fe(e,o,l,{depth:r.depth+1,path:[...r.path,f]},i))}if(typeof n=="object"&&n!==null){let s={};for(let[l,c]of Object.entries(n))s[l]=fe(e,t,c,{depth:r.depth+1,path:[...r.path,l]},i);return s}return null}function rt(e,t,n,r,i){if(n.endsWith("[]")){let c=n.slice(0,-2),o=e.find(t,c,i);return xe(i,r,o),o.map(f=>e.text(f))}if(n.startsWith("@"))return Oe(e,t,n.slice(1));let s=b(n);if(s!==-1){let c=n.slice(0,s),o=n.slice(s+1),f=c?e.find(t,c,i):[t];return f.length===0?null:Oe(e,f[0],o)}if(n===".")return e.text(t);let l=e.find(t,n,i);return l.length===0?null:e.text(l[0])}function xe(e,t,n){if(typeof e.onRowsRead=="function")try{e.onRowsRead(t.path.slice(),n)}catch(r){console.warn(`[hyper-html-api] onRowsRead threw at "${t.path.join(".")||"(root)"}"`,r)}}function Oe(e,t,n){if(Y.has(n)){let i=e.prop(t,n);return i==null?null:String(i)}let r=e.attr(t,n);return r??null}function Re(e,t,n,r){let i=e.length,s=t.length,l=new Array(i).fill(-1);if(r){let h=new Set;for(let y=0;y<i;y++){let A=r[y];!(A>=0&&A<s)||h.has(A)||(l[y]=A,h.add(A))}}if(i===0||s===0)return l;let c=e.map(h=>Se(h,n)),o=t.map(h=>Se(h,n)),f=new Array(s).fill(!1);for(let h of l)h>=0&&(f[h]=!0);let u=new Map;o.forEach((h,y)=>{f[y]||u.set(h,u.has(h)?-1:y)});let m=new Map;c.forEach((h,y)=>{l[y]>=0||m.set(h,(m.get(h)||0)+1)}),c.forEach((h,y)=>{if(l[y]>=0||m.get(h)!==1)return;let A=u.get(h);A===void 0||A===-1||f[A]||(l[y]=A,f[A]=!0)});let d=[];for(let h=0;h<i;h++)l[h]<0&&d.push(h);let w=[];for(let h=0;h<s;h++)f[h]||w.push(h);if(d.length===0||w.length===0)return l;let a=i*s+1,p=it(e,t,n),g=(h,y)=>p(h,y)*a+Math.abs(h-y);for(let[h,y]of ot(d,w,g))l[h]=y;return l}var Ne=e=>typeof e=="object"&&e!==null;function Se(e,t){if(!Ne(t))return e==null?" null":String(e);let n=Object.keys(t);return JSON.stringify(n.map(r=>{let i=JSON.stringify(e?.[r]);return i===void 0?" undef":i}))}function it(e,t,n){if(!Ne(n))return(c,o)=>e[c]===t[o]?0:1;let r=Object.keys(n),i=c=>r.map(o=>JSON.stringify(c?.[o])),s=e.map(i),l=t.map(i);return(c,o)=>{let f=s[c],u=l[o],m=0;for(let d=0;d<r.length;d++)f[d]!==u[d]&&m++;return m}}function ot(e,t,n){return e.length<=t.length?be(e,t,n,!1):be(t,e,(r,i)=>n(i,r),!0)}function be(e,t,n,r){let i=e.length,s=t.length,l=[];for(let m=0;m<=i;m++)l.push(new Float64Array(s+1).fill(1/0));let c=[];for(let m=0;m<=i;m++)c.push(new Uint8Array(s+1));for(let m=0;m<=s;m++)l[i][m]=0;for(let m=i-1;m>=0;m--)for(let d=s-1;d>=0;d--){let w=n(e[m],t[d])+l[m+1][d+1],a=l[m][d+1];w<=a?(l[m][d]=w,c[m][d]=1):l[m][d]=a}let o=[],f=0,u=0;for(;f<i&&u<s;)c[f][u]&&(o.push(r?[t[u],e[f]]:[e[f],t[u]]),f++),u++;return o}function ae(e,t,n,r,i,s,l,c={}){let o=e.find(t,n,c);if(i.length===0){o.forEach(T=>e.remove(T)),ue(c,"onRowsApplied",s.path,[]);return}let f=i.length>o.length,u=o[0]||null;if(f&&!u&&(u=ft(e,t,n,c),!u))throw new N(s.path);let m=o.map(T=>ct(e,T,r,c)),d=null;if(f&&u){d=e.clone(u),c.templateAttr&&e.removeAttr(d,c.templateAttr);let T=e.stripIds(d);T>0&&console.warn(`[hyper-html-api] stripped ${T} id attribute(s) from cloned template at "${s.path.join(".")||"(root)"}"`)}let w=Re(i,m,r,st(e,o,i,s,c)),a=o.length>0?e.parent(o[0]):dt(e,t,n,u,s,c),p=o.length>0?ke(e,a,o[0]):0,g=yt(e,o),h=new Set,y=[],A=i.map((T,S)=>{let O=w[S];if(O>=0)return h.add(O),y.push(!1),o[O];y.push(!0);let E=e.clone(d);return e.stripIds(E),E});o.forEach((T,S)=>{h.has(S)||e.remove(T)}),g?mt(e,a,p,A,y):gt(e,A,y,a,p),lt(e,A,r,i,s,l,c),ue(c,"onRowsApplied",s.path,A)}function ue(e,t,n,r){if(typeof e[t]=="function")try{return e[t](n.slice(),r)}catch(i){console.warn(`[hyper-html-api] ${t} threw at "${n.join(".")||"(root)"}"`,i);return}}function st(e,t,n,r,i){let s=ue(i,"identifyRows",r.path,n);if(!Array.isArray(s))return null;let l=new Array(n.length).fill(-1),c=new Set,o=new Map(t.map((f,u)=>[e.identity(f),u]));for(let f=0;f<n.length;f++){if(!s[f])continue;let u=o.get(e.identity(s[f]));u===void 0||c.has(u)||(l[f]=u,c.add(u))}return l}function lt(e,t,n,r,i,s,l){t.forEach((c,o)=>{if(n===null){let f=r[o],u=f==null?"":String(f);e.text(c)!==u&&e.text(c,u)}else{let f=s(e,c,n,r[o],{depth:i.depth+1,path:[...i.path,o]},l);f&&f!==c&&(t[o]=f)}})}function ct(e,t,n,r){return n===null?e.text(t):C(e,t,n,r.onRowsRead?{...r,onRowsRead:void 0}:r)}function ke(e,t,n){let r=e.children(t);for(let i=0;i<r.length;i++)if(e.sameNode(r[i],n))return i;return-1}function ft(e,t,n,r){if(!r.templateAttr)return null;let i=/^\s*:scope\s*>\s*/.test(n),s=new RegExp(":not\\(\\["+r.templateAttr.replace(/[.*+?^${}()|[\]\\-]/g,"\\$&")+"\\]\\)","g"),l=n.replace(/^\s*:scope\s*>\s*/,"").replace(s,""),c=i?ut(l):0,o=ce(l),f=t;for(;f;){let u=e.find(f,l,{includeRulesTag:!1,templateAttr:null});for(let m of u)if(e.attr(m,r.templateAttr)!=null&&!(i&&!ht(e,t,m,c))&&!(o&&!e.matches(e.parent(m),o)))return m;f=e.parent(f)}return null}function ut(e){let t=0,n=null,r=1;for(let i=0;i<e.length;i++){let s=e[i];if(s==="\\")i++;else if(n)s===n&&(n=null);else if(s==='"'||s==="'")n=s;else if(s==="["||s==="(")t++;else if(s==="]"||s===")")t>0&&t--;else if(t===0&&s===">")r++;else{if(t===0&&(s==="+"||s==="~"))return null;if(t===0&&/\s/.test(s)){if(!at(e,i))return null;for(;i+1<e.length&&/\s/.test(e[i+1]);)i++}}}return r}function at(e,t){let n=t;for(;n<e.length&&/\s/.test(e[n]);)n++;let r=t>0?e[t-1]:"",i=n<e.length?e[n]:"";return Ce(r)||Ce(i)}function Ce(e){return e===">"||e==="+"||e==="~"}function ht(e,t,n,r){if(r===null)return!0;let i=n;for(let o=0;o<r;o++)if(i=e.parent(i),!i)return!1;let s=e.prop(t,"tagName");if(!s)return!0;let l=e.prop(i,"tagName");if(!l||String(l).toLowerCase()!==String(s).toLowerCase())return!1;let c=new Set(Me(e,i));return Me(e,t).every(o=>c.has(o))}function Me(e,t){let n=e.attr(t,"class");return n?String(n).split(/\s+/).filter(Boolean):[]}function dt(e,t,n,r,i,s){let l=e.parent(r);if(l&&pt(e,t,l)&&!Ie(e,l,s))return l;let c=ce(n);if(!c)throw new N(i.path,`the list selector "${n}" names no container to hold the new rows \u2014 write it as "container > row" (for example "ol.comments > li") so the cloned row lands in the list`);let f=(c===":scope"?e.prop(t,"tagName")?[t]:[]:e.find(t,c,s)).filter(u=>!Ie(e,u,s));if(f.length===0)throw new N(i.path,`no container matching "${c}" inside this context to hold the new rows`);if(f.length>1)throw new N(i.path,`"${c}" matches ${f.length} containers inside this context, so the new rows have no single destination`);return f[0]}function pt(e,t,n){let r=n;for(;r;){if(e.sameNode(r,t))return!0;r=e.parent(r)}return e.parent(t)?!1:e.find(t,"*",{includeRulesTag:!0,templateAttr:null}).some(i=>e.sameNode(i,n))}var Pe=["no-data","editor-ui"];function Ie(e,t,n){let r=t;for(;r;){if(n.templateAttr&&e.attr(r,n.templateAttr)!=null||Pe.some(s=>e.attr(r,s)!=null))return!0;let i=e.attr(r,"clay");if(i&&i.split(/\s+/).some(s=>Pe.includes(s)))return!0;r=e.parent(r)}return!1}function mt(e,t,n,r,i){let s=e.children(t),l=s.map(o=>e.identity(o)),c=!1;r.forEach((o,f)=>{let u=e.identity(o),m=n+f;if(l[m]===u)return;if(!i[f]){let w=l.indexOf(u);w!==-1&&(l.splice(w,1),s.splice(w,1))}let d=Math.min(m,s.length);d<s.length?e.insertBefore(s[d],o):s.length?c?e.insertAfter(s[s.length-1],o):(e.insertAt(t,o,m),c=!0):e.insertAt(t,o,0),l.splice(d,0,u),s.splice(d,0,o)})}function yt(e,t){if(t.length<=1)return!0;let n=e.parent(t[0]);if(!n)return!1;let r=new Map(e.children(n).map((s,l)=>[e.identity(s),l])),i=[];for(let s of t){let l=r.get(e.identity(s));if(l===void 0)return!1;i.push(l)}return i.sort((s,l)=>s-l),i[i.length-1]-i[0]===i.length-1}function gt(e,t,n,r,i){let s=null,l=i;for(let c=0;c<t.length;c++){if(!n[c]){s=t[c];continue}let o=s?e.parent(s):r;if(!o)continue;let f=s?ke(e,o,s)+1:l++;e.insertAt(o,t[c],f),s=t[c]}}function I(e,t,n,r,i={}){if(Object.prototype.hasOwnProperty.call(i,"exclude")&&e.semanticExclude===!1)throw new Error("This adapter does not support semantic exclude queries; omit exclude or use the DOM adapter.");let s=[];if(he(n,r,[],s),s.length)throw new v(s);Q(e,t,n,r,{depth:0,path:[]},i)}function Q(e,t,n,r,i,s={}){if(i.depth>L)throw new P(i.path);if(r===void 0)return t;if(typeof n=="string")return At(e,t,n,r,i,s);if(Array.isArray(n)){let[l,c]=n;return ae(e,t,l,c,r,i,Q,s),t}if(typeof n=="object"&&n!==null){for(let[l,c]of Object.entries(n)){let o=Q(e,t,c,r==null?r:r[l],{depth:i.depth+1,path:[...i.path,l]},s);o&&o!==t&&(t=o)}return t}return t}function At(e,t,n,r,i,s){if(n.endsWith("[]")){let o=n.slice(0,-2);return ae(e,t,o,null,r,i,Q,s),t}if(n.startsWith("@"))return je(e,t,n.slice(1),r);let l=b(n);if(l!==-1){let o=n.slice(0,l),f=n.slice(l+1),u=o?e.find(t,o,s):[t];return u.length===0||je(e,u[0],f,r),t}if(n===".")return Le(e,t,r),t;let c=e.find(t,n,s);return c.length===0||Le(e,c[0],r),t}function Le(e,t,n){let r=n==null?"":String(n);e.text(t)!==r&&e.text(t,r)}function je(e,t,n,r){if($.has(n)){let i=e.prop(t,n);if(i===r||i!=null&&r!=null&&String(i)===String(r))return t;throw new B(n)}if(n==="outerHTML"){let i=r==null?"":String(r);return e.replaceWith(t,i)}if(re.has(n)){let i=ie(n,r);return e.prop(t,n)!==i&&e.prop(t,n,i),t}if(r==null)e.attr(t,n)!=null&&e.removeAttr(t,n);else{let i=String(r);e.attr(t,n)!==i&&e.attr(t,n,i)}return t}function he(e,t,n,r){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]")){Array.isArray(t)?t.forEach((i,s)=>{typeof i=="object"&&i!==null&&r.push({path:U([...n,s]),expected:"scalar",got:q(i)})}):r.push({path:U(n),expected:"array",got:q(t)});return}t!==null&&typeof t=="object"&&r.push({path:U(n),expected:"scalar",got:q(t)});return}if(Array.isArray(e)){if(!Array.isArray(t)){r.push({path:U(n),expected:"array",got:q(t)});return}let i=e[1];t.forEach((s,l)=>he(i,s,[...n,l],r));return}if(typeof e=="object"&&e!==null){if(t===null||Array.isArray(t)||typeof t!="object"){r.push({path:U(n),expected:"object",got:q(t)});return}for(let[i,s]of Object.entries(e))he(s,t[i],[...n,i],r)}}}function q(e){return e===null?"null":Array.isArray(e)?"array":typeof e}function U(e){return e.join(".")}function de(e){try{return JSON.parse(e)}catch(t){throw new k(`Invalid strict JSON: ${t.message}`,t)}}function z(e){try{return JSON.parse(e)}catch{}let t={BRACE_OPEN:"{",BRACE_CLOSE:"}",BRACKET_OPEN:"[",BRACKET_CLOSE:"]",COLON:":",COMMA:",",STRING:"STRING",SELECTOR:"SELECTOR",IDENTIFIER:"IDENTIFIER",NUMBER:"NUMBER",BOOLEAN:"BOOLEAN"};function n(i){let s=[],l=0;for(;l<i.length;){let c=i[l];if(/\s/.test(c)){l++;continue}if("{}".includes(c)){s.push({type:c,value:c}),l++;continue}if(c==="["){let m=!1,d=l+1;for(;d<i.length&&/\s/.test(i[d]);)d++;if(d<i.length&&/[a-zA-Z_]/.test(i[d])&&(m=!0),!m){s.push({type:c,value:c}),l++;continue}}if(c==="]"){s.push({type:c,value:c}),l++;continue}if(c===":"){s.push({type:t.COLON,value:c}),l++;continue}if(c===","){s.push({type:t.COMMA,value:c}),l++;continue}if(c==='"'||c==="'"){let m=c,d=l+1;for(;d<i.length&&i[d]!==m;)i[d]==="\\"&&d++,d++;s.push({type:t.STRING,value:i.substring(l+1,d),quoted:!0,sourceQuote:m}),l=d+1;continue}let o=l,f;for(;o<i.length&&!/[{},]/.test(i[o]);)if(i[o]===":"){let m=[":first",":last",":nth-child",":nth-of-type",":first-child",":last-child",":first-of-type",":last-of-type",":only-child",":only-of-type",":hover",":focus",":active",":visited",":disabled",":enabled",":checked",":empty",":root",":target",":not",":before",":after",":nth-last-child",":nth-last-of-type"],d=!1;for(let w of m){let a=w.substring(1);if(i.substring(o+1,o+1+a.length)===a){d=!0,o+=a.length;break}}if(!d)break}else if(i[o]==="["){for(o++;o<i.length&&i[o]!=="]";){if(i[o]==='"'||i[o]==="'"){let m=i[o];for(o++;o<i.length&&i[o]!==m;)i[o]==="\\"&&o++,o++}o++}o<i.length&&i[o]==="]"&&o++}else o++;f=i.substring(l,o);let u=t.IDENTIFIER;/^-?\d+(\.\d+)?$/.test(f)?u=t.NUMBER:f==="true"||f==="false"||f==="null"?u=t.BOOLEAN:/^[.#@\[]|[.#@\[]| /.test(f)&&(u=t.SELECTOR),s.push({type:u,value:f,quoted:!1}),l=o}return s}function r(i){let s="";for(let l=0;l<i.length;l++){let c=i[l];if("{}".includes(c.type)||"[]".includes(c.type)){s+=c.value;continue}if(c.type===t.COLON){s+=c.value;continue}if(c.type===t.COMMA){let o=i[l+1];if(o&&(o.type==="}"||o.type==="]"))continue;s+=c.value;continue}if(c.type===t.STRING&&c.quoted){let o=c.value;c.sourceQuote==="'"&&(o=o.replace(/\\'/g,"'"),o=o.replace(/(\\*)"/g,(f,u)=>u.length%2===0?u+'\\"':f)),s+=`"${o}"`;continue}if(c.type===t.NUMBER||c.type===t.BOOLEAN){s+=c.value;continue}if(c.type===t.SELECTOR||c.type===t.IDENTIFIER){s+=`"${c.value}"`;continue}s+=`"${c.value}"`}return s}try{let i=n(e),s=r(i);return JSON.parse(s)}catch(i){throw new k("Invalid extraction rules syntax: "+i.message,i)}}var Tt="1",_e=/^[a-zA-Z0-9_-]+$/;function j(e,t,n){let r;if(n===void 0)r="script[data-rules-name]";else{if(typeof n!="string"||!_e.test(n))throw new Error(`hyper-html-api: invalid rules token ${JSON.stringify(n)} (must match ${_e})`);r=`script[data-rules-name~="${n}"]`}let i=e.find(t,r,{includeRulesTag:!0});if(i.length===0)return null;n!==void 0&&i.length>1&&console.warn(`hyper-html-api: ${i.length} rules tags match data-rules-name~="${n}"; using the first.`);let s=i[0],l=e.attr(s,"data-rules-version");if(l!==Tt)throw new W(l);return{rules:z(e.text(s)),tagNode:s}}var ee=Object.freeze({data:Object.freeze({tokens:["no-data"],bundles:["editor-ui"]}),save:Object.freeze({tokens:["no-save"],bundles:["editor-ui"]}),snapshot:Object.freeze({tokens:["no-snapshot"],bundles:["editor-ui"]}),watch:Object.freeze({tokens:["no-watch"],bundles:["editor-ui"]}),undo:Object.freeze({tokens:["no-undo"],bundles:["editor-ui"]}),history:Object.freeze({tokens:[],bundles:["editor-ui"]})}),wt=Object.freeze({"editor-ui":Object.freeze(["no-data","no-save","no-snapshot","no-watch","no-undo"])}),De=Object.freeze(["no-save","no-snapshot","no-trigger-autosave","no-dirty","no-watch","no-undo","no-data","freeze","editor-ui","live"]);function K(e,t){if(!e||e.nodeType!==1)return!1;let n=e.getAttribute?.("clay");return!!(n&&n.split(/\s+/).includes(t)||e.hasAttribute?.(t))}function pe(e,t){if(K(e,t))return!0;for(let[n,r]of Object.entries(wt))if(r.includes(t)&&K(e,n))return!0;return!1}function F(e){let t=ee[e];if(!t)throw new Error(`Unknown region capability: ${e}`);return[...t.tokens,...t.bundles].flatMap(n=>[`[clay~="${n}"]`,`[${n}]`]).join(", ")}function Et(e,t){let n=e&&e.nodeType===1?e:e?.parentElement;for(;n&&n.nodeType===1;){let r=ee[t];if(!r)throw new Error(`Unknown region capability: ${t}`);if(r.tokens.some(i=>pe(n,i))||r.bundles.some(i=>K(n,i)))return n;n=n.parentElement}return null}function $e(e,t){return!!Et(e,t)}var me=Object.freeze({refusedRuleForms:["innerHTML","outerHTML"],refusedTargets:["script","style","template","noscript","iframe","object","embed","xmp","plaintext","noembed","noframes","meta","link","base","animate","set","animatemotion","animatetransform"],refusedAttributes:["style","srcdoc","is","http-equiv","sandbox","allow","nonce","integrity","charset","htmlclaytoken","htmlclayid","data-rules-name","data-rules-version","clay","contenteditable",...De],refusedAttributePrefixes:["on"],urlAttributes:["href","src","srcset","action","formaction","poster","cite","data","ping","background","longdesc","usemap","xlink:href","manifest","codebase","icon"],refusedSchemes:["javascript","vbscript","data"]}),Ot=new Set(["textContent","innerText"]);function We(e){let n=String(e).replace(/^[\u0000- ]+|[\u0000- ]+$/g,"").replace(/[\t\n\r]/g,"").match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);return n?n[1].toLowerCase():null}var xt=/^[^\t\n\f\r "'>/=\u0000-\u001f\u007f]+$/;function ve(e,t,n=me){if(!xt.test(String(e)))return`attribute name ${JSON.stringify(String(e))} is not valid`;let r=String(e).toLowerCase();if(n.refusedAttributePrefixes.some(i=>r.startsWith(i)))return`attribute "${r}" can run script`;if(n.refusedAttributes.includes(r))return`attribute "${r}" is not content`;if(n.urlAttributes.includes(r)&&t!=null){let i=r==="srcset"?String(t).split(",").map(s=>s.trim().split(/\s+/)[0]).filter(Boolean):[String(t)];for(let s of i){let l=We(s);if(l&&n.refusedSchemes.includes(l))return`"${l}:" URLs are not allowed in "${r}"`}}return null}function ye(e,t){let n=e.prop(t,"tagName");return n?String(n).toLowerCase():""}function St(e,t){let n=ye(e,t)||"node",r=e.attr(t,"id");return r?`<${n}#${r}>`:`<${n}>`}function bt(e,t,n){let r=t;for(;r;){let i=ye(e,r);if(i&&n.refusedTargets.includes(i))return i;r=e.parent(r)}return null}function Be(e,t){return e.find(t,"script[data-rules-name]",{includeRulesTag:!0,templateAttr:null}).length>0}function Rt(e,t){return ye(e,t)==="script"&&e.attr(t,"data-rules-name")!=null?!0:Be(e,t)}function te(e,t=me){let n=[],r=(o,f)=>(n.push({target:St(e,o),reason:f}),!1),i=o=>{let f=bt(e,o,t);return f?r(o,`inside <${f}>, which is not content`):!0},s=o=>i(o)?Be(e,o)?r(o,"a text write here would delete the data rules tag"):!0:!1,l=(o,f,u)=>{if(!i(o))return!1;let m=ve(f,u,t);return m?r(o,m):!0};return{...e,text(o,f){if(f===void 0)return e.text(o);s(o)&&e.text(o,f)},attr(o,f,u){if(u===void 0)return e.attr(o,f);l(o,f,u)&&e.attr(o,f,u)},removeAttr(o,f){l(o,f,null)&&e.removeAttr(o,f)},prop(o,f,u){if(u===void 0)return e.prop(o,f);if(t.refusedRuleForms.includes(f))return r(o,`"@${f}" writes HTML, only text is allowed`);if(Ot.has(f)){s(o)&&e.prop(o,f,u);return}l(o,f==="className"?"class":f,u)&&e.prop(o,f,u)},remove(o){if(Rt(e,o)){r(o,"removing this would delete the data rules tag");return}e.remove(o)},replaceWith(o,f){return f===e.prop(o,"outerHTML")||r(o,'"@outerHTML" writes HTML, only text is allowed'),o},refusals:n,assertClean(){if(n.length)throw new H(n.slice())}}}function V(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function He(e){return e.reduce((t,n)=>typeof n=="number"?`${t}[${n}]`:t?`${t}.${n}`:n,"")}function ge(e,t,n,r,i={}){let s=[],l=[];function c(f,u,m){if(Array.isArray(f)){let[,d]=f;if(!Array.isArray(u)||!V(d))return;u.forEach((w,a)=>c(d,w,[...m,a]));return}if(!(!V(f)||!V(u)))for(let d of Object.keys(u))Object.prototype.hasOwnProperty.call(f,d)?c(f[d],u[d],[...m,d]):s.push(He([...m,d]))}function o(f,u,m,d){if(m!==void 0){if(typeof u=="string"){if(u.endsWith("[]")||u==="."||u.startsWith("@"))return;let w=b(u),a=w===-1?u:u.slice(0,w);if(!a)return;e.find(f,a,i).length===0&&l.push({path:He(d),selector:a});return}if(!Array.isArray(u)&&V(u)&&V(m))for(let[w,a]of Object.entries(u))o(f,a,m[w],[...d,w])}}return c(n,r,[]),o(t,n,r,[]),{unknownKeys:s,unmatched:l}}function Ae(e,t,n){if(n&&typeof n=="object")return{rules:n,tagNode:null};if(typeof n=="string"){let r=t&&t.ownerDocument?t.ownerDocument:t;return j(e,r,n)}return null}var Ct=/:(?:focus(?:-within|-visible)?|hover|active|visited|defined)\b/i;function Mt(e,t){if(!/^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(e.tagName||""))return;let n=(e.getAttribute?.("type")||"").toLowerCase();"value"in e&&"value"in t&&e.tagName!=="OPTION"&&n!=="checkbox"&&n!=="radio"&&n!=="file"&&(t.value=e.value),e.tagName==="INPUT"&&(n==="checkbox"||n==="radio")&&(t.checked=e.checked),e.tagName==="OPTION"&&(t.selected=e.selected),"indeterminate"in e&&"indeterminate"in t&&(t.indeterminate=e.indeterminate)}function qe(e,t,n,r){if(r)return!!e.closest?.(t);let i=e;for(;i?.nodeType===1;){if(i.matches(t))return!0;if(i===n)break;i=i.parentElement}return!1}function Ue(e,t,n,r,i,s){return(s?$e(e,t):qe(e,n,i,!1))||!!(r&&(s&&e!==i?e.matches(r):qe(e,r,i,s)))}function Pt(e,t){let n=ee[t];return n.tokens.some(r=>pe(e,r))||n.bundles.some(r=>K(e,r))}var It=new Set(["INPUT","TEXTAREA","SELECT","OPTION"]);function ze(e,t,n,r){if(e.nodeType===1&&r(e)){n.dropped.push(t);return}n.cloneToLive.set(t,e),n.liveToClone.set(e,t);let i=e,s=t;if(e.nodeType===1){if(It.has(e.tagName)&&n.controls.push(e,t),e.tagName==="TEMPLATE"){for(;t.firstChild;)t.removeChild(t.firstChild);i=e.content,s=t.content,n.cloneToLive.set(s,i),n.liveToClone.set(i,s)}}else if(e.nodeType!==11)return;let l=s.firstChild;for(let c=i.firstChild;c&&l;c=c.nextSibling)ze(c,l,n,r),l=l.nextSibling}function J(e,{capability:t="data",exclude:n=null,inherit:r=!0,provenance:i=null}={}){if(!e)throw new TypeError("createContentView requires a DOM context");let s=e.nodeType===9?e:e.ownerDocument;if(!s?.implementation?.createHTMLDocument)throw new TypeError("createContentView requires an HTML DOM implementation");let l=s.implementation.createHTMLDocument(""),c=i||new WeakMap,o=new WeakMap,f=e.nodeType===9?e.documentElement:e;n&&l.documentElement.matches(n);let u=F(t),m=r?a=>Pt(a,t)||!!(n&&a.matches(n)):a=>Ue(a,t,u,n,f,!1),d=null;if(f.nodeType!==1||!Ue(f,t,u,n,f,r)){d=l.importNode(f,!0);let a={cloneToLive:c,liveToClone:o,dropped:[],controls:[]};ze(f,d,a,m);for(let p of a.dropped)p.remove();for(let p=0;p<a.controls.length;p+=2)Mt(a.controls[p],a.controls[p+1])}e.nodeType===9&&d&&(l.replaceChild(d,l.documentElement),o.set(e,l),c.set(l,e));let w=a=>{if(Ct.test(a))throw new Error(`Filtered content queries do not support stateful selector: ${a}`)};return{root:d,document:l,capability:t,selector:F(t),cloneToLive:c,liveToClone:o,original(a){return c.get(a)||null},cloneOf(a){return o.get(a)||null},query(a,p=d){return w(a),Array.from(p.querySelectorAll(a),g=>c.get(g)||g)},text(a=d){return(a===d?d:o.get(a))?.textContent||""},html(a=d){return(a===d?d:o.get(a))?.innerHTML??""},clone(a=d){let p=a===d?d:o.get(a);return p?l.importNode(p,!0):null}}}function Fe(e){return e&&e.nodeType===1&&e.tagName==="SCRIPT"&&e.hasAttribute&&e.hasAttribute("data-rules-name")}function kt(e){return e?(e.nodeType===9||e.nodeType===11,e):null}function Ke(e,t,n){!e||e.nodeType!==1||(t==="value"&&e.tagName==="INPUT"?e.value=n===null?"":n:t==="checked"&&e.tagName==="INPUT"?e.checked=n!==null:t==="selected"&&e.tagName==="OPTION"&&(e.selected=n!==null))}function Ve(e,t){e&&e.tagName==="TEXTAREA"&&(e.value=t)}function Je(e){if(!e||e.nodeType!==1)return;let t=[e,...e.querySelectorAll?e.querySelectorAll("textarea, input, option"):[]];for(let n of t)if(n.tagName==="TEXTAREA")n.value=n.defaultValue;else if(n.tagName==="INPUT"){let r=n.type;r!=="file"&&r!=="checkbox"&&r!=="radio"&&(n.value=n.defaultValue),n.checked=n.defaultChecked}else n.tagName==="OPTION"&&(n.selected=n.defaultSelected)}var x={semanticExclude:!0,find(e,t,n={}){let r=kt(e);if(!r||!r.querySelectorAll)return[];let i=Array.from(r.querySelectorAll(t));n.includeRulesTag||(i=i.filter(c=>!Fe(c)));let s=[];n.skip&&s.push(n.skip);let l=n.templateAttr===null?null:n.templateAttr||"cms-template";if(l&&s.push("["+l+"]"),s.length){let c=s.join(", ");i=i.filter(o=>!o.closest||!o.closest(c))}return i},parent(e){return e?e.parentElement:null},children(e){return e?Array.from(e.children):[]},matches(e,t){return!!(e&&e.matches)&&e.matches(t)},text(e,t){if(t===void 0)return(e.textContent||"").trim();e.textContent=t,Ve(e,t)},attr(e,t,n){if(n===void 0)return e.hasAttribute&&e.hasAttribute(t)?e.getAttribute(t):null;e.setAttribute(t,n),Ke(e,t,n)},removeAttr(e,t){e&&e.removeAttribute&&e.removeAttribute(t),Ke(e,t,null)},prop(e,t,n){if(n===void 0){let r=e?e[t]:void 0;return r!==void 0?r:null}e[t]=n},clone(e){let t=e.cloneNode(!0);return Je(t),t},insertAt(e,t,n){let r=e.children[n]||null;e.insertBefore(t,r)},insertBefore(e,t){e.parentNode.insertBefore(t,e)},insertAfter(e,t){e.parentNode.insertBefore(t,e.nextSibling)},identity(e){return e||null},remove(e){e&&e.parentNode&&e.parentNode.removeChild(e)},replaceWith(e,t){if(!e||!e.parentNode)throw new Error("dom.replaceWith: node has no parent");let r=e.ownerDocument.createElement("template");r.innerHTML=t;let i=r.content.firstElementChild;if(!i)throw new Error("dom.replaceWith: html did not parse to an element");return e.parentNode.replaceChild(i,e),i},stripIds(e){let t=0;return e.id&&(e.removeAttribute("id"),t++),(e.querySelectorAll?e.querySelectorAll("[id]"):[]).forEach(r=>{r.removeAttribute("id"),t++}),t},sameNode(e,t){return e===t}};function M(e,t={}){if(t.exclude===null)return x;let n=[F("data"),t.exclude].filter(Boolean).join(", "),r=e.nodeType===9?e:e.ownerDocument||e,i=e.nodeType===9?e.documentElement:e;if(!t._write&&!i?.matches?.(n)&&!i?.querySelector?.(n)&&!r?.querySelector?.(n))return x;let s=e.nodeType===9||!e.isConnected?e:e.ownerDocument,l=e.nodeType===9?e:e.ownerDocument,c=null,o=()=>c||(c=J(s,{capability:"data",exclude:t.exclude||null})),f=a=>{let p=o();return a===e?p.cloneOf(e):p.cloneOf(a)||a},u=a=>c?.original(a)||a,m=(a,p)=>{o().liveToClone.set(a,p),o().cloneToLive.set(p,a);let g=a.childNodes||[],h=p.childNodes||[];for(let y=0;y<Math.min(g.length,h.length);y++)m(g[y],h[y])},d=(a,p,g,h)=>{let y=Array.from(a.childNodes).filter(E=>c.cloneOf(E)),T=y[0];for(;T&&y.includes(T);)T=T.nextSibling;for(let E of y)E.remove();if(g==="innerHTML"){let E=l.createElement("template");E.innerHTML=h;for(let D of Array.from(E.content.childNodes))a.insertBefore(D,T||null)}else a.insertBefore(l.createTextNode(h),T||null),Ve(a,h);let S=J(a,{capability:"data",exclude:t.exclude||null});p.replaceChildren(...Array.from(S.root?.childNodes||[]));let O=E=>{let D=S.original(E);D&&(c.liveToClone.set(D,E),c.cloneToLive.set(E,D));for(let Ze of Array.from(E.childNodes||[]))O(Ze)};for(let E of Array.from(p.childNodes))O(E)},w={...x,find(a,p,g={}){let h=f(a);if(!h?.querySelectorAll)return[];let y=o().query(p,h);g.includeRulesTag||(y=y.filter(S=>!Fe(S)));let A=[];g.skip&&A.push(g.skip);let T=g.templateAttr===null?null:g.templateAttr||"cms-template";if(T&&A.push(`[${T}]`),A.length){let S=A.join(", ");y=y.filter(O=>!O.closest?.(S))}return y},parent(a){let p=f(a)?.parentElement;return p?u(p):null},children(a){return Array.from(f(a)?.children||[],u)},text(a,p){if(p===void 0){let y=u(a);return!y?.matches?.(n)&&!y?.querySelector?.(n)?x.text(y):(f(a)?.textContent||"").trim()}let g=u(a);if(!g?.matches?.(n)&&!g?.querySelector?.(n)&&!c){x.text(g,p);return}let h=o().cloneOf(g);h?d(g,h,"textContent",p):x.text(g,p)},attr(a,p,g){let h=u(a);if(g===void 0)return x.attr(h,p);x.attr(h,p,g);let y=c?.cloneOf(h);y&&(x.attr(y,p,g),J(h,{capability:"data",exclude:t.exclude||null}).root===null&&(y.remove(),c.liveToClone.delete(h),c.cloneToLive.delete(y)))},removeAttr(a,p){let g=u(a);x.removeAttr(g,p);let h=c?.cloneOf(g);h&&x.removeAttr(h,p)},prop(a,p,g){let h=u(a);if(g===void 0)return p==="innerHTML"||p==="outerHTML"||p==="textContent"||p==="innerText"?x.prop(f(h),p):x.prop(h,p);let y=p==="innerHTML"||p==="textContent"||p==="innerText",A=y?o().cloneOf(h):c?.cloneOf(h);A&&y?d(h,A,p,g):(x.prop(h,p,g),A&&x.prop(A,p,g))},clone(a){let p=f(a);if(p===a)return x.clone(a);let g=l.importNode(p,!0);return Je(g),g},insertAt(a,p,g){let h=u(a),A=w.children(h)[g]||(()=>{for(let O=h.children.length-1;O>=0;O--){let E=h.children[O];if(o().cloneOf(E))return E.nextElementSibling}return h.firstElementChild})(),T=u(p);h.insertBefore(T,A||null);let S=o().cloneOf(h);if(S){let O=o().cloneOf(T);O||(O=l.importNode(T,!0),m(T,O));let E=Array.from(S.children);S.insertBefore(O,E[g]||null)}},insertBefore(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.before(A):y.appendChild(A)}},insertAfter(a,p){let g=u(a),h=u(p);g.parentNode.insertBefore(h,g.nextSibling);let y=o().cloneOf(g.parentNode);if(y){let A=o().cloneOf(h);A||(A=l.importNode(h,!0),m(h,A));let T=o().cloneOf(g);T?T.after(A):y.appendChild(A)}},identity(a){return u(a)||null},remove(a){let p=u(a),g=o().cloneOf(p);x.remove(p),g&&x.remove(g)},replaceWith(a,p){let g=u(a),h=o().cloneOf(g),y=x.replaceWith(g,p);if(h){let A=J(y,{capability:"data",exclude:t.exclude||null});if(!A.root)h.remove();else{h.replaceWith(A.root);let T=S=>{let O=A.original(S);O&&(c.liveToClone.set(O,S),c.cloneToLive.set(S,O));for(let E of Array.from(S.childNodes||[]))T(E)};T(A.root)}}return y}};return w}var X=x;var ne={extract:(e,t,n={})=>C(M(e,n),e,t,n),apply:(e,t,n,r={})=>I(M(e,{...r,_write:!0}),e,t,n,r),findRulesIn:(e,t)=>j(X,e,t),findRules:(e,t)=>Ae(X,e,t),bind:(e,t,n={})=>{let r=Ae(X,e,t);if(!r){let i=typeof t=="string"?`data-rules-name~="${t}"`:"the provided rules object";throw new Error(`hyper-html-api: could not resolve rules for ${i}`)}return{...r,get:()=>C(M(e,n),e,r.rules,n),set:i=>I(M(e,{...n,_write:!0}),e,r.rules,i,n)}},parseStrict:de,parseRelaxed:z,ruleAttrIndex:b,splitRule:le,errors:R,DOM_PROPERTIES:G},Te=e=>!!e&&typeof e.nodeType=="number";function Xe(e){let t=e&&e.ownerDocument?e.ownerDocument:e,n=j(X,t,"api");if(!n)throw new R.NoRulesTag("api");return n.rules}function Lt(e){if(e.nodeType===9)return e;let t=e.ownerDocument?.documentElement;if(t?.contains(e))return t;let n=e;for(;n.parentNode;)n=n.parentNode;return n}function jt(e){if(e.nodeType!==11||!e.host)return e.cloneNode(!0);let t=e.ownerDocument.createDocumentFragment();for(let n of e.childNodes)t.appendChild(n.cloneNode(!0));return t}function _t(e,t){let n=[];for(;t!==e;){let r=t.parentNode;n.push(Array.prototype.indexOf.call(r.childNodes,t)),t=r}return n.reverse()}function Dt(e,t){return t.reduce((n,r)=>n.childNodes[r],e)}function _(e,t){let n=e.querySelectorAll?Array.from(e.querySelectorAll(t)):[];return e.matches?.(t)&&n.unshift(e),n}function $t(e,t){let n=_(e,"option"),r=_(t,"option");n.forEach((o,f)=>r[f].selected=o.selected);let i=_(e,"input"),s=_(t,"input");i.forEach((o,f)=>{let u=o.type.toLowerCase();u!=="file"&&(s[f].value=o.value),(u==="checkbox"||u==="radio")&&(s[f].checked=o.checked)});let l=_(e,"textarea"),c=_(t,"textarea");l.forEach((o,f)=>c[f].value=o.value)}function we(e,t){if(t!==void 0){if(typeof e=="string"){if(e.endsWith("[]"))return;let n=e.startsWith("@")?0:b(e);if(n===-1)return;let r=e.slice(n+1);if($.has(r))throw new R.RuleTargetReadOnly(r);return}if(Array.isArray(e)){if(!Array.isArray(t))return;t.forEach(n=>we(e[1],n));return}if(e&&typeof e=="object"&&t&&typeof t=="object"&&!Array.isArray(t))for(let[n,r]of Object.entries(e))we(r,t[n])}}function Wt(e,t,n){let r={templateAttr:"cms-template"},i=Lt(e),s=_t(i,e),l=jt(i);$t(i,l);let c=Dt(l,s),o=M(l,{...r,_write:!0}),f=ge(o,c,t,n,r);if(f.unknownKeys.length||f.unmatched.length)throw new R.WriteRejected(f.unknownKeys,f.unmatched);let u=te(o);I(u,c,t,n,r),u.assertClean(),we(t,n);let m=te(M(i,{...r,_write:!0}));I(m,e,t,n,r),m.assertClean()}function vt(e){if(!(e instanceof Error))return e;let t=e.name||"Error";try{e.code=t}catch{Object.defineProperty(e,"code",{value:t,configurable:!0,enumerable:!0})}return e instanceof R.WriteRefused?e.details=e.refusals:e instanceof R.WriteRejected?e.details={unknownKeys:e.unknownKeys,unmatched:e.unmatched}:e instanceof R.ShapeMismatch?e.details=e.mismatches:Array.isArray(e.path)?e.details={path:e.path}:typeof e.target=="string"?e.details={target:e.target}:e.token!==void 0?e.details={token:e.token}:e.version!==void 0?e.details={version:e.version}:e.details={},e}function Ge(e,t){let n=Te(e)?e:document,r=Te(e)?t:e;return r===void 0?C(M(n),n,Xe(n)):ne.bind(n,r).get()}function Ye(e,t,n){try{if(!Te(e))throw new Error("hyper-html-api: applyData(root, data, source?) needs a DOM root as the first argument.");let r=n===void 0?Xe(e):ne.bind(e,n).rules;Wt(e,r,t)}catch(r){throw vt(r)}return e}var Bt={engine:ne,extractData:Ge,applyData:Ye},Fn=Bt;export{Ye as applyData,Fn as default,ne as engine,Ge as extractData};
|