okno 1.0.0-beta.37 → 1.0.0-beta.39

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.
@@ -3,27 +3,53 @@ let O = !1;
3
3
  function M() {
4
4
  const t = globalThis;
5
5
  O || typeof t.document > "u" || (O = !0, t.document.addEventListener("okno:change", (r) => {
6
- const { path: i, value: f } = r.detail;
7
- _.get(i)?.forEach((n) => n(f));
6
+ const { path: o, value: s } = r.detail;
7
+ _.get(o)?.forEach((n) => n(s));
8
8
  }));
9
9
  }
10
+ let x = {};
11
+ function yt(t) {
12
+ t && typeof t == "object" && (x = t);
13
+ }
10
14
  let L = {};
11
- function nt(t) {
12
- t && typeof t == "object" && (L = t);
15
+ function _t(t) {
16
+ const r = t?.collections;
17
+ if (!r || typeof r != "object") return;
18
+ const o = {};
19
+ for (const [s, n] of Object.entries(r)) {
20
+ const e = n?.url;
21
+ typeof e == "string" && e.trim() && (o[s] = e.trim());
22
+ }
23
+ L = o;
24
+ }
25
+ function H(t, r) {
26
+ const o = [];
27
+ for (const s of t.split("/")) {
28
+ if (!s) continue;
29
+ const n = s.match(/^\[(.+)\]$/)?.[1];
30
+ if (!n) {
31
+ o.push(s);
32
+ continue;
33
+ }
34
+ let e = r[n];
35
+ if (Array.isArray(e) && (e = e[0]), e && typeof e == "object" && (e = e.slug), e == null || e === "") return "";
36
+ o.push(String(e));
37
+ }
38
+ return "/" + o.join("/");
13
39
  }
14
- function rt(t, r = Date.now()) {
40
+ function ht(t, r = Date.now()) {
15
41
  if (!t || typeof t != "object") return !0;
16
- const i = t, f = typeof i.publishAt == "string" ? Date.parse(i.publishAt) : NaN;
17
- if (!Number.isNaN(f) && f > r) return !1;
18
- const n = typeof i.unpublishAt == "string" ? Date.parse(i.unpublishAt) : NaN;
42
+ const o = t, s = typeof o.publishAt == "string" ? Date.parse(o.publishAt) : NaN;
43
+ if (!Number.isNaN(s) && s > r) return !1;
44
+ const n = typeof o.unpublishAt == "string" ? Date.parse(o.unpublishAt) : NaN;
19
45
  return !(!Number.isNaN(n) && n <= r);
20
46
  }
21
- function x(t) {
47
+ function z(t) {
22
48
  if (typeof t != "string") return t;
23
- const r = L[t];
49
+ const r = x[t];
24
50
  return typeof r == "function" ? r() : r ?? t;
25
51
  }
26
- const C = /* @__PURE__ */ new Set([
52
+ const K = /* @__PURE__ */ new Set([
27
53
  "src",
28
54
  "href",
29
55
  "alt",
@@ -36,97 +62,97 @@ const C = /* @__PURE__ */ new Set([
36
62
  "name",
37
63
  "value"
38
64
  ]);
39
- function z(t) {
65
+ function J(t) {
40
66
  return t.replace(/[-_]+/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").trim().replace(/^./, (r) => r.toUpperCase());
41
67
  }
42
68
  function j(t, r = "") {
43
69
  if (t == null) {
44
70
  if (!r) return "";
45
- const i = r.split(".").pop() ?? "";
46
- return !i || C.has(i) ? "" : z(i);
71
+ const o = r.split(".").pop() ?? "";
72
+ return !o || K.has(o) ? "" : J(o);
47
73
  }
48
- return typeof t != "object" ? String(t) : k(t) ? t.text ?? "" : D(t) ? t.name ?? "" : "";
74
+ return typeof t != "object" ? String(t) : g(t) ? t.text ?? "" : W(t) ? t.name ?? "" : "";
49
75
  }
50
- function v(t) {
76
+ function p(t) {
51
77
  return typeof t == "object" && t !== null && !Array.isArray(t) && "src" in t;
52
78
  }
53
- function k(t) {
79
+ function g(t) {
54
80
  return typeof t == "object" && t !== null && !Array.isArray(t) && "url" in t && "text" in t && "external" in t;
55
81
  }
56
- function D(t) {
82
+ function W(t) {
57
83
  return typeof t != "object" || t === null || Array.isArray(t) ? !1 : Object.keys(t).length === 2 && "name" in t && "value" in t;
58
84
  }
59
- function P(t, r) {
85
+ function I(t, r) {
60
86
  if (r === void 0) return t;
61
87
  if (t === null || typeof t != "object" || Array.isArray(t) || r === null || typeof r != "object" || Array.isArray(r))
62
88
  return r;
63
- const i = { ...t };
64
- for (const f of Object.keys(r))
65
- i[f] = P(t[f], r[f]);
66
- return i;
89
+ const o = { ...t };
90
+ for (const s of Object.keys(r))
91
+ o[s] = I(t[s], r[s]);
92
+ return o;
67
93
  }
68
- function ot(t, r) {
69
- const i = { ...t };
70
- for (const f of Object.keys(r))
71
- i[f] = P(t, r[f]);
72
- return i;
94
+ function dt(t, r) {
95
+ const o = { ...t };
96
+ for (const s of Object.keys(r))
97
+ o[s] = I(t, r[s]);
98
+ return o;
73
99
  }
74
- function it(t) {
100
+ function bt(t) {
75
101
  if (!t || typeof t != "object" || Array.isArray(t)) return {};
76
102
  const r = {};
77
- for (const [i, f] of Object.entries(t)) {
78
- const n = i.split(".");
103
+ for (const [o, s] of Object.entries(t)) {
104
+ const n = o.split(".");
79
105
  let e = r;
80
- for (let o = 0; o < n.length - 1; o++) {
81
- const c = n[o];
82
- (!e[c] || typeof e[c] != "object" || Array.isArray(e[c])) && (e[c] = {}), e = e[c];
106
+ for (let i = 0; i < n.length - 1; i++) {
107
+ const f = n[i];
108
+ (!e[f] || typeof e[f] != "object" || Array.isArray(e[f])) && (e[f] = {}), e = e[f];
83
109
  }
84
- e[n[n.length - 1]] = f;
110
+ e[n[n.length - 1]] = s;
85
111
  }
86
112
  return r;
87
113
  }
88
- const w = "string:", K = { slots: {} };
89
- function J(t, r) {
114
+ const w = "string:", F = { slots: {} };
115
+ function G(t, r) {
90
116
  try {
91
117
  return new Intl.PluralRules(t || void 0).select(r);
92
118
  } catch {
93
119
  return "other";
94
120
  }
95
121
  }
96
- function E(t, r) {
122
+ function N(t, r) {
97
123
  try {
98
124
  return new Intl.NumberFormat(t || void 0).format(r);
99
125
  } catch {
100
126
  return String(r);
101
127
  }
102
128
  }
103
- function q(t, r, i, f) {
104
- const n = Object.keys(r).find((c) => r[c] === "count");
129
+ function X(t, r, o, s) {
130
+ const n = Object.keys(r).find((f) => r[f] === "count");
105
131
  let e;
106
132
  if (n && t && typeof t == "object" && !Array.isArray(t)) {
107
- const c = t, s = J(f, Number(i?.[n])), u = c[s] ?? c.other ?? Object.values(c)[0] ?? "";
133
+ const f = t, c = G(s, Number(o?.[n])), u = f[c] ?? f.other ?? Object.values(f)[0] ?? "";
108
134
  e = String(u);
109
135
  } else
110
136
  e = typeof t == "string" ? t : String(t ?? "");
111
- let o = e.replace(/\{([a-zA-Z0-9_]+)\}/g, (c, s) => {
112
- if (!(s in r)) return c;
113
- const u = i?.[s];
114
- return r[s] === "number" || r[s] === "count" ? E(f, Number(u)) : u == null ? "" : String(u);
137
+ let i = e.replace(/\{([a-zA-Z0-9_]+)\}/g, (f, c) => {
138
+ if (!(c in r)) return f;
139
+ const u = o?.[c];
140
+ return r[c] === "number" || r[c] === "count" ? N(s, Number(u)) : u == null ? "" : String(u);
115
141
  });
116
- return n && (o = o.replace(/#/g, E(f, Number(i?.[n])))), o;
142
+ return n && (i = i.replace(/#/g, N(s, Number(o?.[n])))), i;
117
143
  }
118
- function ut(t, r, i) {
119
- const f = {};
144
+ function mt(t, r, o) {
145
+ const s = {};
120
146
  if (r && typeof r == "object" && !Array.isArray(r))
121
147
  for (const [n, e] of Object.entries(r)) {
122
- const o = e?.slots;
123
- o && typeof o == "object" && !Array.isArray(o) && Object.keys(o).length > 0 && (f[n] = o);
148
+ const i = e?.slots;
149
+ i && typeof i == "object" && !Array.isArray(i) && Object.keys(i).length > 0 && (s[n] = i);
124
150
  }
125
- return d(t, "", { slots: f, locale: i, defaultLocale: i });
151
+ return b(t, "", { slots: s, locale: o, defaultLocale: o });
126
152
  }
127
- function d(t, r = "", i = K) {
128
- const f = { __raw: t, __path: r };
129
- return new Proxy(f, {
153
+ function b(t, r = "", o = F) {
154
+ const s = { __raw: t, __path: r };
155
+ return new Proxy(s, {
130
156
  get(n, e) {
131
157
  if (e === "data-okno") return w + n.__path;
132
158
  if (e === Symbol.toPrimitive || e === "toString" || e === "valueOf")
@@ -150,18 +176,18 @@ function d(t, r = "", i = K) {
150
176
  if (e === "locale")
151
177
  return (u) => {
152
178
  const l = n.__raw;
153
- return u && l !== null && typeof l == "object" && !Array.isArray(l) && typeof l[u] == "object" && l[u] !== null ? d(l[u], n.__path, { ...i, locale: u }) : d(l, n.__path, { ...i, locale: i.defaultLocale });
179
+ return u && l !== null && typeof l == "object" && !Array.isArray(l) && typeof l[u] == "object" && l[u] !== null ? b(l[u], n.__path, { ...o, locale: u }) : b(l, n.__path, { ...o, locale: o.defaultLocale });
154
180
  };
155
- const o = n.__raw, c = n.__path ? `${n.__path}.${String(e)}` : String(e), s = i.slots[c];
156
- if (s && Object.keys(s).length > 0) {
157
- const u = o && typeof o == "object" ? o[String(e)] : void 0;
158
- return (l = {}) => d(q(u, s, l, i.locale), c, i);
181
+ const i = n.__raw, f = n.__path ? `${n.__path}.${String(e)}` : String(e), c = o.slots[f];
182
+ if (c && Object.keys(c).length > 0) {
183
+ const u = i && typeof i == "object" ? i[String(e)] : void 0;
184
+ return (l = {}) => b(X(u, c, l, o.locale), f, o);
159
185
  }
160
- if (o != null && typeof o != "object") {
161
- const u = o[e];
162
- return u !== void 0 ? typeof u == "function" ? (...l) => u.apply(o, l) : u : d(null, c, i);
186
+ if (i != null && typeof i != "object") {
187
+ const u = i[e];
188
+ return u !== void 0 ? typeof u == "function" ? (...l) => u.apply(i, l) : u : b(null, f, o);
163
189
  }
164
- return o != null && typeof o == "object" && !Array.isArray(o) ? d(o[String(e)], c, i) : d(null, c, i);
190
+ return i != null && typeof i == "object" && !Array.isArray(i) ? b(i[String(e)], f, o) : b(null, f, o);
165
191
  },
166
192
  // Spread carries ONLY the hook — strings have no HTML attributes (unlike
167
193
  // media `{src}` / link `{url,text}`).
@@ -174,78 +200,87 @@ function d(t, r = "", i = K) {
174
200
  },
175
201
  has(n, e) {
176
202
  if (e === "data-okno" || e === Symbol.toPrimitive || e === "toString") return !0;
177
- const o = n.__raw;
178
- return typeof o == "object" && o !== null ? e in o : o != null ? e in Object(o) : !1;
203
+ const i = n.__raw;
204
+ return typeof i == "object" && i !== null ? e in i : i != null ? e in Object(i) : !1;
179
205
  }
180
206
  });
181
207
  }
182
- function m(t, r, i) {
183
- const f = { __raw: t, __path: r, __drag: i };
184
- return new Proxy(f, {
208
+ function m(t, r, o) {
209
+ const s = { __raw: t, __path: r, __drag: o };
210
+ return new Proxy(s, {
185
211
  get(n, e) {
186
212
  if (e === "data-okno") return n.__path;
187
213
  if (e === "children") return;
188
214
  if (e === "drag") return { "data-okno-item": n.__drag ?? n.__path };
189
215
  if (e === "data-okno-item") return n.__drag ?? void 0;
190
216
  if (e === "exists") return n.__raw !== null && n.__raw !== void 0;
191
- if (e === "image" && v(n.__raw)) {
192
- const s = n.__raw;
217
+ if (e === "value" && (n.__raw === null || typeof n.__raw != "object"))
218
+ return n.__raw;
219
+ if (e === "image" && p(n.__raw)) {
220
+ const c = n.__raw;
193
221
  return {
194
- src: x(s.src),
195
- alt: s.alt,
196
- width: s.width,
197
- height: s.height,
222
+ src: z(c.src),
223
+ alt: c.alt,
224
+ width: c.width,
225
+ height: c.height,
198
226
  "data-okno": n.__path
199
227
  };
200
228
  }
229
+ if (e === "href" && !g(n.__raw) && !p(n.__raw)) {
230
+ const c = n.__raw, u = n.__path.split(".");
231
+ if (c && typeof c == "object" && !Array.isArray(c) && !("href" in c) && u.length === 2) {
232
+ const l = L[u[0]];
233
+ if (l) return H(l, c);
234
+ }
235
+ }
201
236
  if (e === Symbol.toPrimitive || e === "toString" || e === "valueOf")
202
237
  return () => j(n.__raw, n.__path);
203
238
  if (e === Symbol.iterator) {
204
- const s = j(n.__raw, n.__path);
239
+ const c = j(n.__raw, n.__path);
205
240
  return function* () {
206
- yield s;
241
+ yield c;
207
242
  };
208
243
  }
209
244
  if (typeof e == "symbol") return;
210
245
  if (e === "toJSON") return () => n.__raw;
211
246
  if (e === "onedit")
212
- return (s) => {
247
+ return (c) => {
213
248
  M();
214
249
  const u = n.__path;
215
- return _.has(u) || _.set(u, /* @__PURE__ */ new Set()), _.get(u).add(s), () => {
216
- _.get(u)?.delete(s), _.get(u)?.size === 0 && _.delete(u);
250
+ return _.has(u) || _.set(u, /* @__PURE__ */ new Set()), _.get(u).add(c), () => {
251
+ _.get(u)?.delete(c), _.get(u)?.size === 0 && _.delete(u);
217
252
  };
218
253
  };
219
254
  if (e === "locale")
220
- return (s) => {
255
+ return (c) => {
221
256
  const u = n.__raw;
222
- return s && u !== null && typeof u == "object" && !Array.isArray(u) && typeof u[s] == "object" && u[s] !== null ? m(
223
- u[s],
257
+ return c && u !== null && typeof u == "object" && !Array.isArray(u) && typeof u[c] == "object" && u[c] !== null ? m(
258
+ u[c],
224
259
  n.__path
225
260
  ) : m(u, n.__path);
226
261
  };
227
- const o = n.__raw, c = n.__path ? `${n.__path}.${String(e)}` : String(e);
228
- if (k(o) && typeof e == "string") {
229
- if (e === "href") return o.url ?? "";
230
- if (e === "target" && o.external) return "_blank";
231
- if (e === "rel" && o.external) return "noopener noreferrer";
262
+ const i = n.__raw, f = n.__path ? `${n.__path}.${String(e)}` : String(e);
263
+ if (g(i) && typeof e == "string") {
264
+ if (e === "href") return i.url ?? "";
265
+ if (e === "target" && i.external) return "_blank";
266
+ if (e === "rel" && i.external) return "noopener noreferrer";
232
267
  }
233
- if (v(o) && typeof e == "string" && e !== "focal" && e in o)
234
- return o[e];
235
- if (o != null && typeof o != "object") {
236
- const s = o[e];
237
- return s !== void 0 ? typeof s == "function" ? (...u) => s.apply(o, u) : s : m(null, c);
268
+ if (p(i) && typeof e == "string" && e !== "focal" && e in i)
269
+ return i[e];
270
+ if (i != null && typeof i != "object") {
271
+ const c = i[e];
272
+ return c !== void 0 ? typeof c == "function" ? (...u) => c.apply(i, u) : c : m(null, f);
238
273
  }
239
- if (o != null && typeof o == "object" && !Array.isArray(o)) {
240
- const s = o[String(e)];
241
- return s == null ? m(null, c) : I(s, c);
274
+ if (i != null && typeof i == "object" && !Array.isArray(i)) {
275
+ const c = i[String(e)];
276
+ return c == null ? m(null, f) : P(c, f);
242
277
  }
243
- return m(null, c);
278
+ return m(null, f);
244
279
  },
245
280
  // For spread: expose data-okno, plus all keys for file objects (src, alt, width, height, etc.)
246
281
  ownKeys(n) {
247
- const e = n.__raw, o = n.__drag != null ? ["data-okno-item"] : [];
248
- return v(e) ? [...Object.keys(e).filter((c) => c !== "focal"), "data-okno", ...o] : k(e) ? e.external ? ["href", "target", "rel", "data-okno", ...o] : ["href", "data-okno", ...o] : ["data-okno", ...o];
282
+ const e = n.__raw, i = n.__drag != null ? ["data-okno-item"] : [];
283
+ return p(e) ? [...Object.keys(e).filter((f) => f !== "focal"), "data-okno", ...i] : g(e) ? e.external ? ["href", "target", "rel", "data-okno", ...i] : ["href", "data-okno", ...i] : ["data-okno", ...i];
249
284
  },
250
285
  getOwnPropertyDescriptor(n, e) {
251
286
  if (e === "data-okno")
@@ -256,221 +291,304 @@ function m(t, r, i) {
256
291
  };
257
292
  if (e === "data-okno-item")
258
293
  return n.__drag == null ? void 0 : { value: n.__drag, enumerable: !0, configurable: !0 };
259
- const o = n.__raw;
260
- if (v(o) && typeof e == "string" && e in o && e !== "focal")
294
+ const i = n.__raw;
295
+ if (p(i) && typeof e == "string" && e in i && e !== "focal")
261
296
  return {
262
- value: o[e],
297
+ value: i[e],
263
298
  enumerable: !0,
264
299
  configurable: !0
265
300
  };
266
- if (k(o) && (e === "href" || o.external && (e === "target" || e === "rel")))
301
+ if (g(i) && (e === "href" || i.external && (e === "target" || e === "rel")))
267
302
  return { value: void 0, enumerable: !0, configurable: !0 };
268
303
  },
269
304
  has(n, e) {
270
305
  if (e === "data-okno" || e === Symbol.toPrimitive || e === "toString") return !0;
271
- const o = n.__raw;
272
- return typeof o == "object" && o !== null ? e in o : o != null ? e in Object(o) : !1;
306
+ const i = n.__raw;
307
+ return typeof i == "object" && i !== null ? e in i : i != null ? e in Object(i) : !1;
273
308
  }
274
309
  });
275
310
  }
276
311
  function T(t) {
277
312
  return t !== null && typeof t == "object" && !Array.isArray(t) && "__oknoRef" in t;
278
313
  }
279
- function I(t, r, i) {
314
+ function P(t, r, o) {
280
315
  if (T(t)) {
281
- const { path: f, data: n } = t.__oknoRef;
282
- return m(n, f, i ?? f);
316
+ const { path: s, data: n } = t.__oknoRef;
317
+ return m(n, s, o ?? s);
283
318
  }
284
319
  if (Array.isArray(t)) {
285
- const f = t.map((n, e) => I(n, `${r}.${e}`, `${r}.${e}`));
286
- return Object.defineProperty(f, "toJSON", {
320
+ const s = t.map((n, e) => P(n, `${r}.${e}`, `${r}.${e}`));
321
+ return Object.defineProperty(s, "toJSON", {
287
322
  value: () => t.map((n) => T(n) ? n.__oknoRef.data : n),
288
323
  enumerable: !1
289
- }), f;
324
+ }), s;
290
325
  }
291
- return m(t, r, i);
326
+ return m(t, r, o);
292
327
  }
293
- function B(t, r) {
328
+ function Z(t, r) {
294
329
  if (r && t && typeof t == "object" && !Array.isArray(t)) {
295
- const i = t[r];
296
- if (i && typeof i == "object" && !Array.isArray(i)) return i;
330
+ const o = t[r];
331
+ if (o && typeof o == "object" && !Array.isArray(o)) return o;
297
332
  }
298
333
  return t;
299
334
  }
300
- function st(t, r, i, f = []) {
335
+ function pt(t, r, o, s = []) {
301
336
  if (!t || typeof t != "object" || Array.isArray(t) || !r) return t;
302
337
  const n = Object.keys(r).filter(
303
- (s) => r[s]?.type === "reference" && typeof r[s]?.collection == "string"
338
+ (c) => r[c]?.type === "reference" && typeof r[c]?.collection == "string"
304
339
  );
305
340
  if (n.length === 0) return t;
306
341
  const e = {};
307
- for (const s of n) {
308
- const u = r[s].collection;
342
+ for (const c of n) {
343
+ const u = r[c].collection;
309
344
  if (e[u]) continue;
310
- const l = i?.[u] ?? i?.[u.replace(/-/g, "_")] ?? [], a = /* @__PURE__ */ new Map();
311
- for (const b of l) {
312
- const y = b && typeof b.toJSON == "function" ? b.toJSON() : b;
345
+ const l = o?.[u] ?? o?.[u.replace(/-/g, "_")] ?? [], a = /* @__PURE__ */ new Map();
346
+ for (const h of l) {
347
+ const y = h && typeof h.toJSON == "function" ? h.toJSON() : h;
313
348
  y && typeof y == "object" && typeof y.slug == "string" && a.set(y.slug, y);
314
349
  }
315
350
  e[u] = a;
316
351
  }
317
- const o = (s, u) => {
318
- const l = { ...s };
352
+ const i = (c, u) => {
353
+ const l = { ...c };
319
354
  for (const a of n) {
320
- const b = r[a], y = e[b.collection], $ = (p) => {
321
- if (typeof p != "string" || !p) return null;
322
- const N = y.get(p);
323
- return N === void 0 ? null : { __oknoRef: { path: `${b.collection}.${p}`, data: B(N, u) } };
324
- }, S = s[a];
355
+ const h = r[a], y = e[h.collection], $ = (k) => {
356
+ if (typeof k != "string" || !k) return null;
357
+ const E = y.get(k);
358
+ return E === void 0 ? null : { __oknoRef: { path: `${h.collection}.${k}`, data: Z(E, u) } };
359
+ }, S = c[a];
325
360
  l[a] = Array.isArray(S) ? S.map($).filter(Boolean) : $(S);
326
361
  }
327
362
  return l;
328
- }, c = o(t, void 0);
329
- for (const s of f) {
330
- const u = c[s];
331
- u && typeof u == "object" && !Array.isArray(u) && (c[s] = o(u, s));
363
+ }, f = i(t, void 0);
364
+ for (const c of s) {
365
+ const u = f[c];
366
+ u && typeof u == "object" && !Array.isArray(u) && (f[c] = i(u, c));
332
367
  }
333
- return c;
368
+ return f;
334
369
  }
335
- function ft(t, r, i = []) {
370
+ function gt(t, r, o = []) {
336
371
  if (!t || typeof t != "object" || Array.isArray(t) || !r) return t;
337
- const f = Object.keys(r).filter(
338
- (c) => r[c]?.type === "enum" && Array.isArray(r[c]?.options)
372
+ const s = Object.keys(r).filter(
373
+ (f) => r[f]?.type === "enum" && Array.isArray(r[f]?.options)
339
374
  );
340
- if (f.length === 0) return t;
375
+ if (s.length === 0) return t;
341
376
  const n = {};
342
- for (const c of f) {
343
- const s = /* @__PURE__ */ new Map();
344
- for (const u of r[c].options)
345
- if (typeof u == "string") s.set(u, { name: u, value: u });
377
+ for (const f of s) {
378
+ const c = /* @__PURE__ */ new Map();
379
+ for (const u of r[f].options)
380
+ if (typeof u == "string") c.set(u, { name: u, value: u });
346
381
  else if (u && typeof u == "object" && u.value != null) {
347
382
  const l = String(u.value);
348
- s.set(l, { name: String(u.name ?? l), value: l });
383
+ c.set(l, { name: String(u.name ?? l), value: l });
349
384
  }
350
- n[c] = s;
385
+ n[f] = c;
351
386
  }
352
- const e = (c) => {
353
- const s = { ...c };
354
- for (const u of f) {
355
- const l = n[u], a = (y) => typeof y != "string" || !y ? null : l.get(y) ?? { name: y, value: y }, b = c[u];
356
- s[u] = Array.isArray(b) ? b.map(a).filter(Boolean) : a(b);
387
+ const e = (f) => {
388
+ const c = { ...f };
389
+ for (const u of s) {
390
+ const l = n[u], a = (y) => typeof y != "string" || !y ? null : l.get(y) ?? { name: y, value: y }, h = f[u];
391
+ c[u] = Array.isArray(h) ? h.map(a).filter(Boolean) : a(h);
357
392
  }
358
- return s;
359
- }, o = e(t);
360
- for (const c of i) {
361
- const s = o[c];
362
- s && typeof s == "object" && !Array.isArray(s) && (o[c] = e(s));
393
+ return c;
394
+ }, i = e(t);
395
+ for (const f of o) {
396
+ const c = i[f];
397
+ c && typeof c == "object" && !Array.isArray(c) && (i[f] = e(c));
363
398
  }
364
- return o;
399
+ return i;
400
+ }
401
+ const d = "data-okno-item", v = "data-okno", Y = [v, d];
402
+ function V(t) {
403
+ return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
365
404
  }
366
- const h = "data-okno-item", A = "data-okno", H = [A, h];
367
- function g(t, r, i, f = H) {
368
- if (r === i) return;
405
+ function A(t, r, o, s = Y) {
406
+ if (r === o) return;
369
407
  const n = (e) => {
370
- for (const o of f) {
371
- const c = e.getAttribute(o);
372
- c != null && (c === r ? e.setAttribute(o, i) : c.startsWith(r + ".") && e.setAttribute(o, i + c.slice(r.length)));
408
+ for (const i of s) {
409
+ const f = e.getAttribute(i);
410
+ f != null && (f === r ? e.setAttribute(i, o) : f.startsWith(r + ".") && e.setAttribute(i, o + f.slice(r.length)));
373
411
  }
374
412
  };
375
413
  n(t);
376
- for (const e of f) t.querySelectorAll(`[${e}]`).forEach(n);
414
+ for (const e of s) t.querySelectorAll(`[${e}]`).forEach(n);
377
415
  }
378
- function W(t) {
416
+ function C(t) {
379
417
  if (typeof document > "u") return [];
380
- const r = new RegExp(`^${t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\.(\\d+)$`), i = /* @__PURE__ */ new Map();
381
- document.querySelectorAll(`[${h}]`).forEach((n) => {
382
- const e = n.getAttribute(h);
383
- if (!e || !r.test(e) || !n.parentElement || !(n instanceof HTMLElement) || n.parentElement.closest(`[${h}]`)?.getAttribute(h) === e) return;
384
- const o = i.get(n.parentElement) ?? [];
385
- o.push(n), i.set(n.parentElement, o);
386
- });
387
- const f = (n) => Number(n.getAttribute(h).match(r)[1]);
388
- return [...i.entries()].map(([n, e]) => ({
418
+ const r = new RegExp(`^${V(t)}\\.(\\d+)$`), o = [], s = t.replace(/["\\]/g, "\\$&");
419
+ return document.querySelectorAll(`[${d}^="${s}."]`).forEach((n) => {
420
+ const e = n.getAttribute(d);
421
+ !e || !r.test(e) || !n.parentElement || !(n instanceof HTMLElement) || n.parentElement.closest(`[${d}]`)?.getAttribute(d) !== e && o.push(n);
422
+ }), o;
423
+ }
424
+ function B(t, r) {
425
+ if (t.length < 2) return r;
426
+ const o = (n) => t.reduce((e, i) => e + (n === i || n.contains(i) ? 1 : 0), 0);
427
+ let s = r;
428
+ for (; s.parentElement && o(s.parentElement) === o(s); ) s = s.parentElement;
429
+ return s;
430
+ }
431
+ function At(t, r) {
432
+ if (!(r instanceof HTMLElement)) return null;
433
+ const o = C(t), s = o.find((n) => n === r) ?? o.find((n) => n.contains(r) || r.contains(n));
434
+ return s ? B(o, s) : null;
435
+ }
436
+ function D(t, r) {
437
+ const o = new RegExp(`^${V(t)}\\.(\\d+)$`), s = r.getAttribute(d)?.match(o);
438
+ if (s) return Number(s[1]);
439
+ for (const n of Array.from(r.querySelectorAll(`[${d}]`))) {
440
+ const e = n.getAttribute(d)?.match(o);
441
+ if (e) return Number(e[1]);
442
+ }
443
+ return null;
444
+ }
445
+ function Q(t) {
446
+ const r = C(t);
447
+ if (r.length === 0) return [];
448
+ const o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
449
+ for (const n of r) {
450
+ const e = B(r, n);
451
+ if (o.has(e) || !e.parentElement) continue;
452
+ o.add(e);
453
+ const i = D(t, n);
454
+ if (i == null) continue;
455
+ const f = s.get(e.parentElement) ?? [];
456
+ f.push({ unit: e, index: i }), s.set(e.parentElement, f);
457
+ }
458
+ return [...s.entries()].map(([n, e]) => ({
389
459
  parent: n,
390
- wrappers: e.sort((o, c) => f(o) - f(c))
460
+ wrappers: e.sort((i, f) => i.index - f.index).map((i) => i.unit)
391
461
  }));
392
462
  }
393
- function V(t) {
394
- const r = Array.from(t.querySelectorAll(`[${A}]`));
395
- return t.hasAttribute(A) && r.unshift(t), r;
463
+ function U(t, r) {
464
+ const o = D(r, t);
465
+ return `${r}.${o ?? 0}`;
466
+ }
467
+ function q(t) {
468
+ const r = Array.from(t.querySelectorAll(`[${v}]`));
469
+ return t.hasAttribute(v) && r.unshift(t), r;
396
470
  }
397
- function F(t) {
398
- for (const r of V(t))
471
+ function tt(t) {
472
+ for (const r of q(t))
399
473
  r.children.length > 0 || (r.textContent = "", r.tagName === "A" && (r.setAttribute("href", ""), r.removeAttribute("target"), r.removeAttribute("rel")));
400
474
  }
401
- function G(t, r) {
402
- for (const i of V(t)) {
403
- const f = i.getAttribute(A);
404
- f && f in r && i.children.length === 0 && (i.textContent = r[f] ?? "");
475
+ function et(t, r) {
476
+ for (const o of q(t)) {
477
+ if (o.children.length > 0) continue;
478
+ const s = o.getAttribute(v), n = s != null && s in r, e = o.tagName;
479
+ if (e === "IMG" || e === "VIDEO" || e === "SOURCE") {
480
+ o.setAttribute("src", n ? r[s] ?? "" : "");
481
+ continue;
482
+ }
483
+ if (e === "A" && !n) {
484
+ o.textContent = "", o.setAttribute("href", ""), o.removeAttribute("target"), o.removeAttribute("rel");
485
+ continue;
486
+ }
487
+ o.textContent = n ? r[s] ?? "" : "";
405
488
  }
406
489
  }
407
- function X() {
490
+ function nt(t, r, o) {
491
+ if (!r || !o || r === o || typeof document > "u") return;
492
+ const s = (i) => i.length > 1 && i.endsWith("/") ? i.slice(0, -1) : i, n = s(r), e = Array.from(t.querySelectorAll("a[href]"));
493
+ t.matches("a[href]") && e.unshift(t);
494
+ for (const i of e) {
495
+ const f = i.getAttribute("href");
496
+ if (!f) continue;
497
+ let c;
498
+ try {
499
+ c = new URL(f, document.baseURI);
500
+ } catch {
501
+ continue;
502
+ }
503
+ c.origin === new URL(document.baseURI).origin && s(c.pathname) === n && i.setAttribute("href", o + c.search + c.hash);
504
+ }
505
+ }
506
+ function rt() {
408
507
  return typeof window < "u" && typeof window.matchMedia == "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
409
508
  }
410
- function Z(t) {
509
+ function ot(t) {
411
510
  const r = document;
412
- return typeof r.startViewTransition != "function" || X() ? (t(), Promise.resolve()) : r.startViewTransition(t).finished.catch(() => {
511
+ return typeof r.startViewTransition != "function" || rt() ? (t(), Promise.resolve()) : r.startViewTransition(t).finished.catch(() => {
413
512
  });
414
513
  }
415
- let U = 0;
416
- function Y(t) {
514
+ let it = 0;
515
+ function ut(t) {
417
516
  if (typeof document > "u" || !t?.list || !t.op) return;
418
- const { list: r, op: i } = t, f = W(r);
419
- if (i === "insert" && f.every((s) => s.wrappers.length === 0) || f.length === 0) return;
420
- const n = [], e = (s) => {
421
- s.style.viewTransitionName = `okno-vt-${++U}`, n.push(s);
517
+ const { list: r, op: o } = t, s = Q(r);
518
+ if (o === "insert" && s.every((u) => u.wrappers.length === 0) || s.length === 0) return;
519
+ const n = [], e = (u) => {
520
+ u.style.viewTransitionName = `okno-vt-${++it}`, n.push(u);
422
521
  };
423
- for (const s of f) for (const u of s.wrappers) e(u);
424
- const o = document.documentElement;
425
- o.classList.add("okno-vt-active"), Z(() => {
426
- for (const s of f)
427
- i === "reorder" ? Q(s, r, t.from, t.to) : i === "remove" ? tt(s, r, t.index) : i === "insert" && et(s, r, t, e);
522
+ for (const u of s) for (const l of u.wrappers) e(l);
523
+ const i = document.documentElement;
524
+ i.classList.add("okno-vt-active");
525
+ const f = ct();
526
+ ot(() => {
527
+ for (const u of s)
528
+ o === "reorder" ? ft(u, r, t.from, t.to) : o === "remove" ? lt(u, r, t.index) : o === "insert" && at(u, r, t, e);
428
529
  }).finally(() => {
429
- for (const s of n) s.style.viewTransitionName = "";
430
- o.classList.remove("okno-vt-active");
530
+ for (const u of n) u.style.viewTransitionName = "";
531
+ f(), i.classList.remove("okno-vt-active");
431
532
  });
432
533
  }
433
- function Q(t, r, i, f) {
534
+ const st = "okno-shadow-root";
535
+ function ct() {
536
+ const t = document.getElementById(st);
537
+ if (!(t instanceof HTMLElement)) return () => {
538
+ };
539
+ const r = t.style.cssText;
540
+ t.style.cssText = `${r};position:fixed;inset:0;height:auto;pointer-events:none;view-transition-name:okno-editor`;
541
+ const o = t.getBoundingClientRect();
542
+ return globalThis.__oknoVtPin = o.width < 1 || o.height < 1 ? `fallback (${Math.round(o.width)}×${Math.round(o.height)})` : "ok", o.width < 1 || o.height < 1 ? (t.style.cssText = r, () => {
543
+ }) : () => {
544
+ t.style.cssText = r;
545
+ };
546
+ }
547
+ function ft(t, r, o, s) {
434
548
  const n = t.wrappers, e = n.length;
435
- if (i < 0 || i >= e || f < 0 || f >= e || i === f) return;
436
- const o = n.slice(), [c] = o.splice(i, 1);
437
- o.splice(f, 0, c);
438
- const s = o.map((l) => l.getAttribute(h));
439
- o.forEach((l, a) => g(l, s[a], `${r}.${a}`));
549
+ if (o < 0 || o >= e || s < 0 || s >= e || o === s) return;
550
+ const i = n.slice(), [f] = i.splice(o, 1);
551
+ i.splice(s, 0, f);
552
+ const c = i.map((l) => U(l, r));
553
+ i.forEach((l, a) => A(l, c[a], `${r}.${a}`));
440
554
  const u = n[e - 1].nextSibling;
441
- for (const l of o) t.parent.insertBefore(l, u);
555
+ for (const l of i) t.parent.insertBefore(l, u);
442
556
  }
443
- function tt(t, r, i) {
444
- const f = t.wrappers;
445
- if (!(i < 0 || i >= f.length)) {
446
- f[i].remove();
447
- for (let n = i + 1; n < f.length; n++) g(f[n], `${r}.${n}`, `${r}.${n - 1}`);
557
+ function lt(t, r, o) {
558
+ const s = t.wrappers;
559
+ if (!(o < 0 || o >= s.length)) {
560
+ s[o].remove();
561
+ for (let n = o + 1; n < s.length; n++) A(s[n], `${r}.${n}`, `${r}.${n - 1}`);
448
562
  }
449
563
  }
450
- function et(t, r, i, f) {
564
+ function at(t, r, o, s) {
451
565
  const n = t.wrappers, e = n.length;
452
566
  if (e === 0) return;
453
- const o = Math.max(0, Math.min(i.index ?? e, e)), c = o < e ? o : e - 1, s = n[c].getAttribute(h), u = n[c].cloneNode(!0);
454
- for (let a = e - 1; a >= o; a--) g(n[a], `${r}.${a}`, `${r}.${a + 1}`);
455
- g(u, s, `${r}.${o}`), i.remap && g(u, i.remap.from, i.remap.to, [A]), i.values ? G(u, i.values) : F(u), u.style.viewTransitionName = "", f(u);
456
- const l = o < e ? n[o] : n[e - 1].nextSibling;
567
+ const i = Math.max(0, Math.min(o.index ?? e, e)), f = i < e ? i : e - 1, c = U(n[f], r), u = n[f].cloneNode(!0);
568
+ for (let a = e - 1; a >= i; a--) A(n[a], `${r}.${a}`, `${r}.${a + 1}`);
569
+ A(u, c, `${r}.${i}`), o.remap && A(u, o.remap.from, o.remap.to, [v]), o.href && nt(u, o.href.from, o.href.to), o.values ? et(u, o.values) : tt(u), u.style.viewTransitionName = "", s(u);
570
+ const l = i < e ? n[i] : n[e - 1].nextSibling;
457
571
  t.parent.insertBefore(u, l);
458
572
  }
459
573
  let R = !1;
460
- function ct() {
574
+ function vt() {
461
575
  const t = globalThis;
462
- R || typeof t.document > "u" || (R = !0, t.document.addEventListener("okno:structure", (r) => Y(r.detail)));
576
+ R || typeof t.document > "u" || (R = !0, t.document.addEventListener("okno:structure", (r) => ut(r.detail)));
463
577
  }
464
578
  export {
465
- Y as __oknoApplyStructure,
466
- it as __oknoExpandStrings,
467
- ct as __oknoInitStructure,
468
- ot as __oknoLocalize,
469
- ut as __oknoMakeStrings,
470
- ft as __oknoResolveEnums,
471
- st as __oknoResolveRefs,
472
- nt as __oknoSetImages,
473
- rt as __oknoVisible,
579
+ ut as __oknoApplyStructure,
580
+ bt as __oknoExpandStrings,
581
+ vt as __oknoInitStructure,
582
+ dt as __oknoLocalize,
583
+ mt as __oknoMakeStrings,
584
+ gt as __oknoResolveEnums,
585
+ pt as __oknoResolveRefs,
586
+ yt as __oknoSetImages,
587
+ _t as __oknoSetRoutes,
588
+ D as __oknoUnitIndex,
589
+ At as __oknoUnitOf,
590
+ ht as __oknoVisible,
474
591
  m as __oknoWrap,
475
- d as __oknoWrapStrings
592
+ b as __oknoWrapStrings,
593
+ V as escapeReg
476
594
  };