article-content-renderer-vue2 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,43 +1,43 @@
1
- var v = Object.defineProperty, x = Object.defineProperties;
2
- var j = Object.getOwnPropertyDescriptors;
3
- var _ = Object.getOwnPropertySymbols;
4
- var z = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
5
- var L = (n, r, t) => r in n ? v(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t, m = (n, r) => {
1
+ var F = Object.defineProperty, Y = Object.defineProperties;
2
+ var K = Object.getOwnPropertyDescriptors;
3
+ var B = Object.getOwnPropertySymbols;
4
+ var G = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
5
+ var E = (n, r, t) => r in n ? F(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t, m = (n, r) => {
6
6
  for (var t in r || (r = {}))
7
- z.call(r, t) && L(n, t, r[t]);
8
- if (_)
9
- for (var t of _(r))
10
- M.call(r, t) && L(n, t, r[t]);
7
+ G.call(r, t) && E(n, t, r[t]);
8
+ if (B)
9
+ for (var t of B(r))
10
+ W.call(r, t) && E(n, t, r[t]);
11
11
  return n;
12
- }, A = (n, r) => x(n, j(r));
13
- var P = (n, r, t) => L(n, typeof r != "symbol" ? r + "" : r, t);
14
- import Y from "vue";
15
- const F = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]), K = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]), G = "https://article-content-renderer.invalid/", I = "https://www.doitme.link/";
16
- function W(n, r) {
12
+ }, A = (n, r) => Y(n, K(r));
13
+ var O = (n, r, t) => E(n, typeof r != "symbol" ? r + "" : r, t);
14
+ import $ from "vue";
15
+ const H = /* @__PURE__ */ new Set(["http:", "https:", "mailto:", "tel:"]), X = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]), J = "https://article-content-renderer.invalid/", N = "https://www.doitme.link/";
16
+ function Q(n, r) {
17
17
  if (typeof n != "string") return n;
18
18
  const t = n.trim();
19
- if (!t.startsWith(I)) return t;
20
- const i = (r.trim() || I).replace(/\/+$/u, ""), s = t.slice(I.length).replace(/^\/+/, "");
19
+ if (!t.startsWith(N)) return t;
20
+ const i = (r.trim() || N).replace(/\/+$/u, ""), s = t.slice(N.length).replace(/^\/+/, "");
21
21
  return `${i}/${s}`;
22
22
  }
23
- function E(n, r) {
23
+ function _(n, r) {
24
24
  if (typeof n != "string") return null;
25
25
  const t = n.trim();
26
26
  if (!t || /[\u0000-\u001F\u007F]/u.test(t)) return null;
27
27
  try {
28
- const e = new URL(t, G);
29
- return (r === "link" ? F : K).has(e.protocol) ? t : null;
28
+ const e = new URL(t, J);
29
+ return (r === "link" ? H : X).has(e.protocol) ? t : null;
30
30
  } catch (e) {
31
31
  return null;
32
32
  }
33
33
  }
34
- function V(n, r) {
34
+ function x(n, r) {
35
35
  const t = new Set(
36
36
  typeof n == "string" ? n.trim().split(/\s+/u).filter(Boolean) : []
37
37
  );
38
38
  return r === "_blank" && (t.add("noopener"), t.add("noreferrer")), t.size > 0 ? [...t].join(" ") : void 0;
39
39
  }
40
- const H = /* @__PURE__ */ new Set([
40
+ const Z = /* @__PURE__ */ new Set([
41
41
  "paragraph",
42
42
  "heading",
43
43
  "blockquote",
@@ -49,89 +49,89 @@ const H = /* @__PURE__ */ new Set([
49
49
  "articleButton",
50
50
  "table"
51
51
  ]);
52
- function p(n) {
52
+ function h(n) {
53
53
  return typeof n == "object" && n !== null && !Array.isArray(n);
54
54
  }
55
- function R(n) {
56
- return p(n) ? n : {};
57
- }
58
- function u(n, r, t, e) {
59
- var f;
60
- const i = p(t) ? t : {}, s = p(t) ? e : t, o = {}, a = {};
61
- for (const [l, h] of Object.entries(i))
62
- if (l === "class")
63
- o.class = h;
64
- else if (l === "style")
65
- o.style = h;
66
- else if (l.startsWith("on") && typeof h == "function") {
67
- const $ = l.slice(2).toLowerCase();
68
- o.on = A(m({}, (f = o.on) != null ? f : {}), { [$]: h });
69
- } else h !== void 0 && h !== !1 && (a[l] = h);
55
+ function P(n) {
56
+ return h(n) ? n : {};
57
+ }
58
+ function f(n, r, t, e) {
59
+ var l;
60
+ const i = h(t) ? t : {}, s = h(t) ? e : t, o = {}, a = {};
61
+ for (const [u, g] of Object.entries(i))
62
+ if (u === "class")
63
+ o.class = g;
64
+ else if (u === "style")
65
+ o.style = g;
66
+ else if (u.startsWith("on") && typeof g == "function") {
67
+ const y = u.slice(2).toLowerCase();
68
+ o.on = A(m({}, (l = o.on) != null ? l : {}), { [y]: g });
69
+ } else g !== void 0 && g !== !1 && (a[u] = g);
70
70
  return Object.keys(a).length > 0 && (o.attrs = a), n.createElement(r, o, s);
71
71
  }
72
- function y(n) {
72
+ function k(n) {
73
73
  return Array.isArray(n) ? n : [];
74
74
  }
75
- function g(n, ...r) {
75
+ function p(n, ...r) {
76
76
  return `${n}/${r.map(String).join("/")}`;
77
77
  }
78
- function S(n) {
78
+ function w(n) {
79
79
  return n === "left" || n === "center" || n === "right" || n === "justify";
80
80
  }
81
- function X(n) {
81
+ function tt(n) {
82
82
  return n === "left" || n === "center" || n === "right";
83
83
  }
84
- function N(n) {
84
+ function R(n) {
85
85
  return n === "_blank" || n === "_self";
86
86
  }
87
87
  function b(n, r) {
88
88
  n.reportIssue(r);
89
89
  }
90
- function J(n, r, t) {
91
- if (!p(n) || n.type !== "text" || typeof n.text != "string" || !n.text)
90
+ function et(n, r, t) {
91
+ if (!h(n) || n.type !== "text" || typeof n.text != "string" || !n.text)
92
92
  return null;
93
93
  let e = n.text;
94
- const i = y(n.marks);
94
+ const i = k(n.marks);
95
95
  for (let s = 0; s < i.length; s += 1) {
96
96
  const o = i[s];
97
- if (!p(o) || typeof o.type != "string") continue;
98
- const a = g(r, "marks", s);
97
+ if (!h(o) || typeof o.type != "string") continue;
98
+ const a = p(r, "marks", s);
99
99
  switch (o.type) {
100
100
  case "bold":
101
- e = u(t, "strong", { class: "acp-mark acp-mark--bold" }, [e]);
101
+ e = f(t, "strong", { class: "acp-mark acp-mark--bold" }, [e]);
102
102
  break;
103
103
  case "italic":
104
- e = u(t, "em", { class: "acp-mark acp-mark--italic" }, [e]);
104
+ e = f(t, "em", { class: "acp-mark acp-mark--italic" }, [e]);
105
105
  break;
106
106
  case "strike":
107
- e = u(t, "s", { class: "acp-mark acp-mark--strike" }, [e]);
107
+ e = f(t, "s", { class: "acp-mark acp-mark--strike" }, [e]);
108
108
  break;
109
109
  case "underline":
110
- e = u(t, "u", { class: "acp-mark acp-mark--underline" }, [e]);
110
+ e = f(t, "u", { class: "acp-mark acp-mark--underline" }, [e]);
111
111
  break;
112
112
  case "code":
113
- e = u(t, "code", { class: "acp-mark acp-mark--code" }, [e]);
113
+ e = f(t, "code", { class: "acp-mark acp-mark--code" }, [e]);
114
114
  break;
115
115
  case "link": {
116
- const f = R(o.attrs), l = E(f.href, "link");
117
- if (!l) {
116
+ const l = P(o.attrs), u = _(l.href, "link");
117
+ if (!u) {
118
118
  b(t, {
119
119
  code: "UNSAFE_URL",
120
- path: g(a, "attrs", "href"),
120
+ path: p(a, "attrs", "href"),
121
121
  message: "The link URL is empty, malformed, or uses a disallowed protocol.",
122
122
  nodeType: "link"
123
123
  });
124
124
  break;
125
125
  }
126
- const h = N(f.target) ? f.target : "_blank";
127
- e = u(
126
+ const g = R(l.target) ? l.target : "_blank";
127
+ e = f(
128
128
  t,
129
129
  "a",
130
130
  {
131
131
  class: "acp-link",
132
- href: l,
133
- target: h,
134
- rel: V(void 0, h)
132
+ href: u,
133
+ target: g,
134
+ rel: x(void 0, g)
135
135
  },
136
136
  [e]
137
137
  );
@@ -141,59 +141,69 @@ function J(n, r, t) {
141
141
  }
142
142
  return e;
143
143
  }
144
- function B(n, r, t) {
145
- return y(n).map((e, i) => J(e, g(r, i), t)).filter((e) => e !== null);
144
+ function V(n, r, t) {
145
+ return k(n).map((e, i) => et(e, p(r, i), t)).filter((e) => e !== null);
146
146
  }
147
- function w(n, r, t) {
148
- return !p(n) || n.type !== "listItem" ? null : u(
147
+ function q(n, r, t) {
148
+ return !h(n) || n.type !== "listItem" ? null : f(
149
149
  t,
150
150
  "li",
151
151
  { class: "acp-list-item", "data-node-type": "listItem" },
152
- T(n.content, g(r, "content"), t)
152
+ S(n.content, p(r, "content"), t)
153
153
  );
154
154
  }
155
- function Q(n, r, t) {
156
- return !p(n) || n.type !== "tableCell" ? null : u(
155
+ function rt(n, r, t) {
156
+ return !h(n) || n.type !== "tableCell" ? null : f(
157
157
  t,
158
158
  "td",
159
159
  { class: "acp-table-cell", "data-node-type": "tableCell" },
160
- T(n.content, g(r, "content"), t)
160
+ S(n.content, p(r, "content"), t)
161
161
  );
162
162
  }
163
- function Z(n, r, t) {
164
- if (!p(n) || n.type !== "tableRow") return null;
165
- const e = y(n.content).map((i, s) => Q(i, g(r, "content", s), t)).filter((i) => i !== null);
166
- return u(t, "tr", { class: "acp-table-row", "data-node-type": "tableRow" }, e);
163
+ function nt(n, r, t) {
164
+ if (!h(n) || n.type !== "tableRow") return null;
165
+ const e = k(n.content).map((i, s) => rt(i, p(r, "content", s), t)).filter((i) => i !== null);
166
+ return f(t, "tr", { class: "acp-table-row", "data-node-type": "tableRow" }, e);
167
167
  }
168
- function tt(n) {
168
+ function C(n) {
169
169
  var i;
170
- if (p(n) && n.target !== void 0 && !N(n.target) || p(n) && n.rel !== void 0 && typeof n.rel != "string") return null;
171
- const r = typeof n == "string" ? { href: n } : p(n) && typeof n.href == "string" ? m(m({
170
+ if (h(n) && n.target !== void 0 && !R(n.target) || h(n) && n.rel !== void 0 && typeof n.rel != "string") return null;
171
+ const r = typeof n == "string" ? { href: n } : h(n) && typeof n.href == "string" ? m(m({
172
172
  href: n.href
173
- }, N(n.target) ? { target: n.target } : {}), typeof n.rel == "string" ? { rel: n.rel } : {}) : null;
173
+ }, R(n.target) ? { target: n.target } : {}), typeof n.rel == "string" ? { rel: n.rel } : {}) : null;
174
174
  if (!r) return null;
175
- const t = E(r.href, "link");
175
+ const t = _(r.href, "link");
176
176
  if (!t) return null;
177
177
  const e = (i = r.target) != null ? i : "_self";
178
178
  return {
179
179
  href: t,
180
180
  target: e,
181
- rel: V(r.rel, e)
181
+ rel: x(r.rel, e)
182
182
  };
183
183
  }
184
- function et(n, r, t) {
185
- var f;
186
- const e = R(n.attrs);
187
- if (typeof e.id != "string" || !e.id || typeof e.text != "string" || !e.text || e.style !== "text" && e.style !== "button")
184
+ function it(n, r, t) {
185
+ var g;
186
+ const e = P(n.attrs), i = e.style === "text" || e.style === "button", s = e.style === "link";
187
+ if (typeof e.text != "string" || !e.text || !i && !s || i && (typeof e.id != "string" || !e.id) || s && e.id !== void 0 && (typeof e.id != "string" || !e.id))
188
188
  return null;
189
- const i = Object.freeze(A(m({
189
+ const o = Object.freeze(s ? m(A(m(m({}, typeof e.id == "string" ? { id: e.id } : {}), typeof e.title == "string" ? { title: e.title } : {}), {
190
+ text: e.text,
191
+ style: "link"
192
+ }), typeof e.href == "string" ? { href: e.href } : {}) : A(m({
190
193
  id: e.id
191
194
  }, typeof e.title == "string" ? { title: e.title } : {}), {
192
195
  text: e.text,
193
196
  style: e.style
194
- })), s = Object.freeze({ type: "articleButton", attrs: i });
195
- let o = null;
196
- if (!t.resolveArticleButtonLink)
197
+ })), a = Object.freeze({ type: "articleButton", attrs: o });
198
+ let l = null;
199
+ if (o.style === "link")
200
+ o.href !== void 0 && (l = C(o.href), l || b(t, {
201
+ code: "UNSAFE_URL",
202
+ path: `${r}/attrs/href`,
203
+ message: "The articleButton link href is not a usable safe URL.",
204
+ nodeType: "articleButton"
205
+ }));
206
+ else if (!t.resolveArticleButtonLink)
197
207
  b(t, {
198
208
  code: "LINK_RESOLUTION_FAILED",
199
209
  path: r,
@@ -202,54 +212,54 @@ function et(n, r, t) {
202
212
  });
203
213
  else
204
214
  try {
205
- const l = t.resolveArticleButtonLink(i, s);
206
- o = tt(l), o || b(t, {
207
- code: typeof l == "string" || p(l) && typeof l.href == "string" ? "UNSAFE_URL" : "LINK_RESOLUTION_FAILED",
215
+ const y = Object.freeze({ type: "articleButton", attrs: o }), L = t.resolveArticleButtonLink(o, y);
216
+ l = C(L), l || b(t, {
217
+ code: typeof L == "string" || h(L) && typeof L.href == "string" ? "UNSAFE_URL" : "LINK_RESOLUTION_FAILED",
208
218
  path: r,
209
219
  message: "The articleButton link resolver returned no usable safe URL.",
210
220
  nodeType: "articleButton"
211
221
  });
212
- } catch (l) {
222
+ } catch (y) {
213
223
  b(t, {
214
224
  code: "LINK_RESOLUTION_FAILED",
215
225
  path: r,
216
- message: `The articleButton link resolver threw an error: ${l instanceof Error ? l.message : String(l)}`,
226
+ message: `The articleButton link resolver threw an error: ${y instanceof Error ? y.message : String(y)}`,
217
227
  nodeType: "articleButton"
218
228
  });
219
229
  }
220
- const a = (f = o == null ? void 0 : o.href) != null ? f : null;
221
- return u(
230
+ const u = (g = l == null ? void 0 : l.href) != null ? g : null;
231
+ return f(
222
232
  t,
223
233
  "a",
224
234
  {
225
235
  class: [
226
236
  "acp-article-button",
227
- `acp-article-button--${i.style}`,
228
- !a && "acp-article-button--disabled"
237
+ `acp-article-button--${o.style}`,
238
+ !u && "acp-article-button--disabled"
229
239
  ],
230
- href: a != null ? a : void 0,
231
- target: o == null ? void 0 : o.target,
232
- rel: o == null ? void 0 : o.rel,
233
- title: i.title,
240
+ href: u != null ? u : void 0,
241
+ target: l == null ? void 0 : l.target,
242
+ rel: l == null ? void 0 : l.rel,
243
+ title: o.title,
234
244
  "data-node-type": "articleButton",
235
- "data-article-button-id": i.id,
236
- "data-article-button-style": i.style,
237
- "aria-disabled": a ? void 0 : "true",
238
- onClick: (l) => {
239
- a || l.preventDefault(), t.emitArticleButtonClick({ attrs: i, node: s, href: a, event: l });
245
+ "data-article-button-id": o.id,
246
+ "data-article-button-style": o.style,
247
+ "aria-disabled": u ? void 0 : "true",
248
+ onClick: (y) => {
249
+ u || y.preventDefault(), t.emitArticleButtonClick({ attrs: o, node: a, href: u, event: y });
240
250
  }
241
251
  },
242
- i.text
252
+ o.text
243
253
  );
244
254
  }
245
- function q(n, r, t) {
246
- if (!p(n) || typeof n.type != "string" || !H.has(n.type))
255
+ function v(n, r, t) {
256
+ if (!h(n) || typeof n.type != "string" || !Z.has(n.type))
247
257
  return null;
248
- const e = R(n.attrs);
258
+ const e = P(n.attrs);
249
259
  switch (n.type) {
250
260
  case "paragraph": {
251
- const i = S(e.textAlign) ? e.textAlign : void 0;
252
- return u(
261
+ const i = w(e.textAlign) ? e.textAlign : void 0;
262
+ return f(
253
263
  t,
254
264
  "p",
255
265
  {
@@ -257,12 +267,12 @@ function q(n, r, t) {
257
267
  "data-node-type": "paragraph",
258
268
  style: i ? { textAlign: i } : void 0
259
269
  },
260
- B(n.content, g(r, "content"), t)
270
+ V(n.content, p(r, "content"), t)
261
271
  );
262
272
  }
263
273
  case "heading": {
264
- const i = Number.isInteger(e.level) && Number(e.level) >= 1 && Number(e.level) <= 6 ? Number(e.level) : 1, s = S(e.textAlign) ? e.textAlign : void 0;
265
- return u(
274
+ const i = Number.isInteger(e.level) && Number(e.level) >= 1 && Number(e.level) <= 6 ? Number(e.level) : 1, s = w(e.textAlign) ? e.textAlign : void 0;
275
+ return f(
266
276
  t,
267
277
  `h${i}`,
268
278
  {
@@ -270,23 +280,23 @@ function q(n, r, t) {
270
280
  "data-node-type": "heading",
271
281
  style: s ? { textAlign: s } : void 0
272
282
  },
273
- B(n.content, g(r, "content"), t)
283
+ V(n.content, p(r, "content"), t)
274
284
  );
275
285
  }
276
286
  case "blockquote":
277
- return u(
287
+ return f(
278
288
  t,
279
289
  "blockquote",
280
290
  { class: "acp-blockquote", "data-node-type": "blockquote" },
281
- T(n.content, g(r, "content"), t)
291
+ S(n.content, p(r, "content"), t)
282
292
  );
283
293
  case "bulletList": {
284
- const i = y(n.content).map((s, o) => w(s, g(r, "content", o), t)).filter((s) => s !== null);
285
- return u(t, "ul", { class: "acp-list acp-list--bullet", "data-node-type": "bulletList" }, i);
294
+ const i = k(n.content).map((s, o) => q(s, p(r, "content", o), t)).filter((s) => s !== null);
295
+ return f(t, "ul", { class: "acp-list acp-list--bullet", "data-node-type": "bulletList" }, i);
286
296
  }
287
297
  case "orderedList": {
288
- const i = Number.isInteger(e.start) && Number(e.start) >= 1 ? Number(e.start) : 1, s = y(n.content).map((o, a) => w(o, g(r, "content", a), t)).filter((o) => o !== null);
289
- return u(
298
+ const i = Number.isInteger(e.start) && Number(e.start) >= 1 ? Number(e.start) : 1, s = k(n.content).map((o, a) => q(o, p(r, "content", a), t)).filter((o) => o !== null);
299
+ return f(
290
300
  t,
291
301
  "ol",
292
302
  {
@@ -298,8 +308,8 @@ function q(n, r, t) {
298
308
  );
299
309
  }
300
310
  case "codeBlock": {
301
- const i = typeof e.language == "string" && e.language ? e.language : void 0, s = y(n.content).filter((o) => p(o) && o.type === "text" && typeof o.text == "string").map((o) => o.text).join("");
302
- return u(
311
+ const i = typeof e.language == "string" && e.language ? e.language : void 0, s = k(n.content).filter((o) => h(o) && o.type === "text" && typeof o.text == "string").map((o) => o.text).join("");
312
+ return f(
303
313
  t,
304
314
  "pre",
305
315
  {
@@ -307,22 +317,22 @@ function q(n, r, t) {
307
317
  "data-node-type": "codeBlock",
308
318
  "data-language": i
309
319
  },
310
- [u(t, "code", { class: i ? `language-${i}` : void 0 }, s)]
320
+ [f(t, "code", { class: i ? `language-${i}` : void 0 }, s)]
311
321
  );
312
322
  }
313
323
  case "horizontalRule":
314
- return u(t, "hr", { class: "acp-horizontal-rule", "data-node-type": "horizontalRule" });
324
+ return f(t, "hr", { class: "acp-horizontal-rule", "data-node-type": "horizontalRule" });
315
325
  case "image": {
316
- const i = E(W(e.src, t.imageBaseUrl), "image");
326
+ const i = _(Q(e.src, t.imageBaseUrl), "image");
317
327
  if (!i)
318
328
  return b(t, {
319
329
  code: "UNSAFE_URL",
320
- path: g(r, "attrs", "src"),
330
+ path: p(r, "attrs", "src"),
321
331
  message: "The image URL is empty, malformed, or uses a disallowed protocol.",
322
332
  nodeType: "image"
323
333
  }), null;
324
- const s = X(e.imageAlign) ? e.imageAlign : "center", o = Number.isInteger(e.width) && Number(e.width) >= 1 && Number(e.width) <= 1e4 ? Number(e.width) : void 0, a = Number.isInteger(e.height) && Number(e.height) >= 1 && Number(e.height) <= 1e4 ? Number(e.height) : void 0;
325
- return u(
334
+ const s = tt(e.imageAlign) ? e.imageAlign : "center", o = Number.isInteger(e.width) && Number(e.width) >= 1 && Number(e.width) <= 1e4 ? Number(e.width) : void 0, a = Number.isInteger(e.height) && Number(e.height) >= 1 && Number(e.height) <= 1e4 ? Number(e.height) : void 0;
335
+ return f(
326
336
  t,
327
337
  "div",
328
338
  {
@@ -331,7 +341,7 @@ function q(n, r, t) {
331
341
  "data-image-align": s
332
342
  },
333
343
  [
334
- u(t, "img", {
344
+ f(t, "img", {
335
345
  class: "acp-image__element",
336
346
  src: i,
337
347
  alt: typeof e.alt == "string" ? e.alt : "",
@@ -344,24 +354,24 @@ function q(n, r, t) {
344
354
  );
345
355
  }
346
356
  case "articleButton":
347
- return et(n, r, t);
357
+ return it(n, r, t);
348
358
  case "table": {
349
- const i = y(n.content).map((s, o) => Z(s, g(r, "content", o), t)).filter((s) => s !== null);
350
- return u(
359
+ const i = k(n.content).map((s, o) => nt(s, p(r, "content", o), t)).filter((s) => s !== null);
360
+ return f(
351
361
  t,
352
362
  "div",
353
363
  { class: "acp-table-wrapper", "data-node-type": "table" },
354
- [u(t, "table", { class: "acp-table" }, [u(t, "tbody", i)])]
364
+ [f(t, "table", { class: "acp-table" }, [f(t, "tbody", i)])]
355
365
  );
356
366
  }
357
367
  }
358
368
  return null;
359
369
  }
360
- function T(n, r, t) {
361
- return y(n).map((e, i) => q(e, g(r, i), t)).filter((e) => e !== null);
370
+ function S(n, r, t) {
371
+ return k(n).map((e, i) => v(e, p(r, i), t)).filter((e) => e !== null);
362
372
  }
363
- function rt(n, r) {
364
- const t = y(n.content), e = /* @__PURE__ */ new Map();
373
+ function st(n, r) {
374
+ const t = k(n.content), e = /* @__PURE__ */ new Map();
365
375
  r.customSlots.forEach((s) => {
366
376
  var a;
367
377
  if (!Number.isInteger(s.location) || s.location < 1 || s.location > t.length)
@@ -371,17 +381,17 @@ function rt(n, r) {
371
381
  });
372
382
  const i = [];
373
383
  return t.forEach((s, o) => {
374
- var l;
384
+ var u;
375
385
  const a = o + 1;
376
- (l = e.get(a)) == null || l.forEach((h) => i.push(...h.content));
377
- const f = q(s, g("/content", o), r);
378
- f && typeof f != "string" && i.push(f);
386
+ (u = e.get(a)) == null || u.forEach((g) => i.push(...g.content));
387
+ const l = v(s, p("/content", o), r);
388
+ l && typeof l != "string" && i.push(l);
379
389
  }), i;
380
390
  }
381
- function nt(n, r) {
382
- return !p(n) || n.type !== "doc" ? [] : rt(n, r);
391
+ function ot(n, r) {
392
+ return !h(n) || n.type !== "doc" ? [] : st(n, r);
383
393
  }
384
- const it = /* @__PURE__ */ new Set([
394
+ const at = /* @__PURE__ */ new Set([
385
395
  "paragraph",
386
396
  "heading",
387
397
  "blockquote",
@@ -392,8 +402,8 @@ const it = /* @__PURE__ */ new Set([
392
402
  "image",
393
403
  "articleButton",
394
404
  "table"
395
- ]), st = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), ot = /* @__PURE__ */ new Set(["left", "center", "right"]), at = /* @__PURE__ */ new Set(["bold", "italic", "strike", "underline", "code"]);
396
- function k(n) {
405
+ ]), ct = /* @__PURE__ */ new Set(["left", "center", "right", "justify"]), lt = /* @__PURE__ */ new Set(["left", "center", "right"]), dt = /* @__PURE__ */ new Set(["bold", "italic", "strike", "underline", "code"]);
406
+ function I(n) {
397
407
  return typeof n == "object" && n !== null && !Array.isArray(n);
398
408
  }
399
409
  function c(n, r) {
@@ -404,12 +414,12 @@ function d(n, ...r) {
404
414
  for (const e of r) t = c(t, e);
405
415
  return t;
406
416
  }
407
- class ct {
417
+ class ut {
408
418
  constructor() {
409
- P(this, "issues", []);
419
+ O(this, "issues", []);
410
420
  }
411
421
  validate(r) {
412
- if (!k(r))
422
+ if (!I(r))
413
423
  return this.add("INVALID_ROOT", "", "The document must be an object."), this.result();
414
424
  this.checkProperties(r, "", ["type", "content"], ["type", "content"]), r.type !== "doc" && this.add("INVALID_ROOT", "/type", 'The root node type must be "doc".');
415
425
  const t = this.requireArray(r.content, "/content");
@@ -457,7 +467,7 @@ class ct {
457
467
  ), i;
458
468
  }
459
469
  requireRecord(r, t, e) {
460
- return k(r) ? r : (this.add("INVALID_TYPE", t, "Expected an object.", e), null);
470
+ return I(r) ? r : (this.add("INVALID_TYPE", t, "Expected an object.", e), null);
461
471
  }
462
472
  optionalRecord(r, t, e) {
463
473
  return r === void 0 ? {} : this.requireRecord(r, t, e);
@@ -480,7 +490,7 @@ class ct {
480
490
  return i !== void 0 && o < i ? (this.add("INVALID_VALUE", t, `Value must be at least ${i}.`, e), !1) : s !== void 0 && o > s ? (this.add("INVALID_VALUE", t, `Value must be at most ${s}.`, e), !1) : !0;
481
491
  }
482
492
  validateBlock(r, t) {
483
- if (!k(r)) {
493
+ if (!I(r)) {
484
494
  this.add("INVALID_TYPE", t, "A block node must be an object.");
485
495
  return;
486
496
  }
@@ -489,7 +499,7 @@ class ct {
489
499
  this.add("MISSING_PROPERTY", c(t, "type"), "A block node requires a type.");
490
500
  return;
491
501
  }
492
- if (!it.has(e)) {
502
+ if (!at.has(e)) {
493
503
  this.add("UNKNOWN_NODE", c(t, "type"), `Unknown block node "${e}".`, e);
494
504
  return;
495
505
  }
@@ -541,14 +551,14 @@ class ct {
541
551
  s && (this.checkProperties(s, t, ["textAlign"], [], e), this.validateTextAlign(s.textAlign, c(t, "textAlign"), e));
542
552
  }
543
553
  validateTextAlign(r, t, e) {
544
- r !== void 0 && (typeof r != "string" ? this.add("INVALID_TYPE", t, "Text alignment must be a string.", e) : st.has(r) || this.add("INVALID_VALUE", t, `Unsupported text alignment "${r}".`, e));
554
+ r !== void 0 && (typeof r != "string" ? this.add("INVALID_TYPE", t, "Text alignment must be a string.", e) : ct.has(r) || this.add("INVALID_VALUE", t, `Unsupported text alignment "${r}".`, e));
545
555
  }
546
556
  validateInlineContent(r, t, e) {
547
557
  const i = this.optionalArray(r, t, e);
548
558
  i == null || i.forEach((s, o) => this.validateText(s, c(t, o), !0));
549
559
  }
550
560
  validateText(r, t, e) {
551
- if (!k(r)) {
561
+ if (!I(r)) {
552
562
  this.add("INVALID_TYPE", t, "A text node must be an object.", "text");
553
563
  return;
554
564
  }
@@ -559,7 +569,7 @@ class ct {
559
569
  }
560
570
  }
561
571
  validateMark(r, t) {
562
- if (!k(r)) {
572
+ if (!I(r)) {
563
573
  this.add("INVALID_TYPE", t, "A mark must be an object.");
564
574
  return;
565
575
  }
@@ -567,7 +577,7 @@ class ct {
567
577
  this.add("MISSING_PROPERTY", c(t, "type"), "A mark requires a type.");
568
578
  return;
569
579
  }
570
- if (at.has(r.type)) {
580
+ if (dt.has(r.type)) {
571
581
  this.checkProperties(r, t, ["type"], ["type"], r.type);
572
582
  return;
573
583
  }
@@ -636,7 +646,7 @@ class ct {
636
646
  ["src", "alt", "title", "width", "height", "imageAlign"],
637
647
  ["src"],
638
648
  e
639
- ), this.requireString(i.src, d(t, "attrs", "src"), e), this.optionalString(i.alt, d(t, "attrs", "alt"), e, { allowEmpty: !0 }), this.optionalString(i.title, d(t, "attrs", "title"), e, { allowEmpty: !0 }), i.width !== void 0 && this.requireInteger(i.width, d(t, "attrs", "width"), e, 1, 1e4), i.height !== void 0 && this.requireInteger(i.height, d(t, "attrs", "height"), e, 1, 1e4), i.imageAlign !== void 0 && (typeof i.imageAlign != "string" ? this.add("INVALID_TYPE", d(t, "attrs", "imageAlign"), "Image alignment must be a string.", e) : ot.has(i.imageAlign) || this.add(
649
+ ), this.requireString(i.src, d(t, "attrs", "src"), e), this.optionalString(i.alt, d(t, "attrs", "alt"), e, { allowEmpty: !0 }), this.optionalString(i.title, d(t, "attrs", "title"), e, { allowEmpty: !0 }), i.width !== void 0 && this.requireInteger(i.width, d(t, "attrs", "width"), e, 1, 1e4), i.height !== void 0 && this.requireInteger(i.height, d(t, "attrs", "height"), e, 1, 1e4), i.imageAlign !== void 0 && (typeof i.imageAlign != "string" ? this.add("INVALID_TYPE", d(t, "attrs", "imageAlign"), "Image alignment must be a string.", e) : lt.has(i.imageAlign) || this.add(
640
650
  "INVALID_VALUE",
641
651
  d(t, "attrs", "imageAlign"),
642
652
  `Unsupported image alignment "${i.imageAlign}".`,
@@ -650,13 +660,23 @@ class ct {
650
660
  i && (this.checkProperties(
651
661
  i,
652
662
  c(t, "attrs"),
653
- ["id", "title", "text", "style"],
654
- ["id", "text", "style"],
663
+ ["id", "title", "text", "style", "href"],
664
+ ["text", "style"],
655
665
  e
656
- ), this.requireString(i.id, d(t, "attrs", "id"), e), this.optionalString(i.title, d(t, "attrs", "title"), e), this.requireString(i.text, d(t, "attrs", "text"), e), i.style !== "text" && i.style !== "button" && this.add(
666
+ ), i.style === "text" || i.style === "button" ? "id" in i ? this.requireString(i.id, d(t, "attrs", "id"), e) : this.add(
667
+ "MISSING_PROPERTY",
668
+ d(t, "attrs", "id"),
669
+ 'Required property "id" is missing for an articleButton with text or button style.',
670
+ e
671
+ ) : this.optionalString(i.id, d(t, "attrs", "id"), e), this.optionalString(i.title, d(t, "attrs", "title"), e), this.requireString(i.text, d(t, "attrs", "text"), e), this.optionalString(i.href, d(t, "attrs", "href"), e), i.style !== "text" && i.style !== "button" && i.style !== "link" && this.add(
657
672
  "INVALID_VALUE",
658
673
  d(t, "attrs", "style"),
659
- 'Article button style must be "text" or "button".',
674
+ 'Article button style must be "text", "button", or "link".',
675
+ e
676
+ ), i.href !== void 0 && i.style !== "link" && this.add(
677
+ "INVALID_VALUE",
678
+ d(t, "attrs", "href"),
679
+ 'Article button href may only be present when style is "link".',
660
680
  e
661
681
  ));
662
682
  }
@@ -667,11 +687,11 @@ class ct {
667
687
  if (!i) return;
668
688
  let s = null;
669
689
  i.forEach((o, a) => {
670
- const f = d(t, "content", a), l = this.validateTableRow(o, f);
671
- l !== null && (s === null ? s = l : l !== s && this.add(
690
+ const l = d(t, "content", a), u = this.validateTableRow(o, l);
691
+ u !== null && (s === null ? s = u : u !== s && this.add(
672
692
  "TABLE_COLUMN_MISMATCH",
673
- c(f, "content"),
674
- `Expected ${s} table cells but received ${l}.`,
693
+ c(l, "content"),
694
+ `Expected ${s} table cells but received ${u}.`,
675
695
  "tableRow"
676
696
  ));
677
697
  });
@@ -682,7 +702,7 @@ class ct {
682
702
  if (!i) return null;
683
703
  this.checkProperties(i, t, ["type", "content"], ["type", "content"], e), i.type !== e && this.add("INVALID_CONTENT", c(t, "type"), "Expected a tableRow node.", e);
684
704
  const s = this.requireNonEmptyArray(i.content, c(t, "content"), e);
685
- return s == null || s.forEach((a, f) => this.validateTableCell(a, d(t, "content", f))), (o = s == null ? void 0 : s.length) != null ? o : null;
705
+ return s == null || s.forEach((a, l) => this.validateTableCell(a, d(t, "content", l))), (o = s == null ? void 0 : s.length) != null ? o : null;
686
706
  }
687
707
  validateTableCell(r, t) {
688
708
  const e = "tableCell", i = this.requireRecord(r, t, e);
@@ -692,34 +712,86 @@ class ct {
692
712
  s == null || s.forEach((o, a) => this.validateBlock(o, d(t, "content", a)));
693
713
  }
694
714
  }
695
- function lt(n) {
696
- return new ct().validate(n);
715
+ function ft(n) {
716
+ return new ut().validate(n);
697
717
  }
698
- const O = Object.freeze({
718
+ const U = Object.freeze({
699
719
  version: 1,
700
- validate: lt,
701
- render: nt
702
- }), C = /* @__PURE__ */ new Map([[O.version, O]]), bt = Object.freeze([...C.keys()]), U = 1;
703
- function D(n) {
704
- return C.get(n);
720
+ validate: ft,
721
+ render: ot
722
+ }), j = /* @__PURE__ */ new Map([[U.version, U]]), Rt = Object.freeze([...j.keys()]), z = 1;
723
+ function M(n) {
724
+ return j.get(n);
705
725
  }
706
- function dt(n, r = {}) {
726
+ function gt(n, r = {}) {
707
727
  var s;
708
- const t = (s = r.protocolVersion) != null ? s : U, e = D(t);
728
+ const t = (s = r.protocolVersion) != null ? s : z, e = M(t);
709
729
  return e ? e.validate(n) : { valid: !1, issues: [{
710
730
  code: "UNSUPPORTED_PROTOCOL",
711
731
  path: "",
712
732
  message: `Article Content Protocol version ${t} is not supported.`
713
733
  }] };
714
734
  }
715
- function ut() {
735
+ function pt() {
716
736
  return [];
717
737
  }
718
- function ft(n) {
738
+ function T(n) {
719
739
  return `${n.code}:${n.path}:${n.message}`;
720
740
  }
721
- const gt = Y.extend({
741
+ function ht(n) {
742
+ const r = n.slots();
743
+ return n.props.customSlots.map((t) => {
744
+ var s, o, a, l;
745
+ const e = { id: t.id, location: t.location }, i = (l = (a = (o = (s = n.scopedSlots)[t.id]) == null ? void 0 : o.call(s, e)) != null ? a : r[t.id]) != null ? l : [];
746
+ return A(m({}, t), { content: i });
747
+ });
748
+ }
749
+ function yt(n, r) {
750
+ Array.isArray(n) ? n.forEach((t) => t(r)) : n == null || n(r);
751
+ }
752
+ const mt = $.extend({
753
+ name: "ArticleContentRenderIssueReporter",
754
+ props: {
755
+ issues: {
756
+ type: Array,
757
+ required: !0
758
+ }
759
+ },
760
+ data() {
761
+ return {
762
+ reportedFingerprint: ""
763
+ };
764
+ },
765
+ watch: {
766
+ issues: {
767
+ immediate: !0,
768
+ deep: !0,
769
+ handler(n) {
770
+ const r = n.map(T).join("|");
771
+ r !== this.reportedFingerprint && (this.reportedFingerprint = r, this.$nextTick(() => n.forEach((t) => this.$emit("render-error", t))));
772
+ }
773
+ }
774
+ },
775
+ render(n) {
776
+ var r, t;
777
+ return (t = (r = this.$slots.default) == null ? void 0 : r[0]) != null ? t : n();
778
+ }
779
+ });
780
+ function D(n, r, t, e) {
781
+ var a;
782
+ const i = (a = t[0]) != null ? a : n(), s = r.listeners["render-error"], o = n(
783
+ mt,
784
+ {
785
+ props: { issues: e },
786
+ on: s ? { "render-error": s } : void 0
787
+ },
788
+ [i]
789
+ );
790
+ return t.length > 1 ? [o, ...t.slice(1)] : o;
791
+ }
792
+ const kt = {
722
793
  name: "ArticleContentRenderer",
794
+ functional: !0,
723
795
  props: {
724
796
  document: {
725
797
  type: null,
@@ -727,7 +799,7 @@ const gt = Y.extend({
727
799
  },
728
800
  protocolVersion: {
729
801
  type: Number,
730
- default: U
802
+ default: z
731
803
  },
732
804
  strict: {
733
805
  type: Boolean,
@@ -735,68 +807,23 @@ const gt = Y.extend({
735
807
  },
736
808
  customSlots: {
737
809
  type: Array,
738
- default: ut
810
+ default: pt
739
811
  },
740
812
  imageBaseUrl: {
741
813
  type: String,
742
- default: I
814
+ default: N
743
815
  },
744
816
  resolveArticleButtonLink: {
745
817
  type: Function,
746
818
  default: void 0
747
819
  }
748
820
  },
749
- data() {
750
- return {
751
- reportedRuntimeIssues: /* @__PURE__ */ new Set()
752
- };
753
- },
754
- computed: {
755
- validation() {
756
- return dt(this.document, { protocolVersion: this.protocolVersion });
757
- }
758
- },
759
- watch: {
760
- validation: {
761
- immediate: !0,
762
- deep: !0,
763
- handler(n) {
764
- n.issues.forEach((r) => this.$emit("render-error", r));
765
- }
766
- },
767
- document: {
768
- deep: !0,
769
- handler() {
770
- this.reportedRuntimeIssues.clear();
771
- }
772
- },
773
- protocolVersion() {
774
- this.reportedRuntimeIssues.clear();
775
- },
776
- resolveArticleButtonLink() {
777
- this.reportedRuntimeIssues.clear();
778
- },
779
- imageBaseUrl() {
780
- this.reportedRuntimeIssues.clear();
781
- }
782
- },
783
- methods: {
784
- resolveCustomSlots() {
785
- return this.customSlots.map((n) => {
786
- var e, i, s, o;
787
- const r = { id: n.id, location: n.location }, t = (o = (s = (i = (e = this.$scopedSlots)[n.id]) == null ? void 0 : i.call(e, r)) != null ? s : this.$slots[n.id]) != null ? o : [];
788
- return A(m({}, n), { content: t });
789
- });
790
- },
791
- reportRuntimeIssue(n) {
792
- const r = ft(n);
793
- this.reportedRuntimeIssues.has(r) || (this.reportedRuntimeIssues.add(r), this.$nextTick(() => this.$emit("render-error", n)));
794
- }
795
- },
796
- render(n) {
797
- const r = D(this.protocolVersion);
798
- if (!r || this.strict && !this.validation.valid)
799
- return n(
821
+ render(n, r) {
822
+ const { props: t } = r, e = gt(t.document, {
823
+ protocolVersion: t.protocolVersion
824
+ }), i = M(t.protocolVersion), s = [];
825
+ if (!i || t.strict && !e.valid) {
826
+ const a = n(
800
827
  "div",
801
828
  {
802
829
  class: "acp-render-error",
@@ -807,38 +834,35 @@ const gt = Y.extend({
807
834
  },
808
835
  "Invalid article content"
809
836
  );
810
- const t = r.render(this.document, {
837
+ return D(n, r, [a], e.issues);
838
+ }
839
+ const o = i.render(t.document, {
811
840
  createElement: n,
812
- customSlots: this.resolveCustomSlots(),
813
- imageBaseUrl: this.imageBaseUrl,
814
- resolveArticleButtonLink: this.resolveArticleButtonLink,
815
- emitArticleButtonClick: (e) => this.$emit("article-button-click", e),
816
- reportIssue: this.reportRuntimeIssue
841
+ customSlots: ht(r),
842
+ imageBaseUrl: t.imageBaseUrl,
843
+ resolveArticleButtonLink: t.resolveArticleButtonLink,
844
+ emitArticleButtonClick: (a) => yt(r.listeners["article-button-click"], a),
845
+ reportIssue: (a) => s.push(a)
817
846
  });
818
- return n(
819
- "div",
820
- {
821
- class: "acp-document",
822
- attrs: {
823
- "data-node-type": "doc",
824
- "data-protocol-version": this.protocolVersion
825
- }
826
- },
827
- t
828
- );
829
- }
830
- });
831
- function pt(n, r, t, e, i, s, o, a) {
832
- var f = typeof n == "function" ? n.options : n;
847
+ return D(n, r, o, [
848
+ ...e.issues,
849
+ ...s.filter(
850
+ (a, l, u) => u.findIndex((g) => T(g) === T(a)) === l
851
+ )
852
+ ]);
853
+ }
854
+ }, bt = $.extend(kt);
855
+ function At(n, r, t, e, i, s, o, a) {
856
+ var l = typeof n == "function" ? n.options : n;
833
857
  return {
834
858
  exports: n,
835
- options: f
859
+ options: l
836
860
  };
837
861
  }
838
- var ht = /* @__PURE__ */ pt(
839
- gt
862
+ var It = /* @__PURE__ */ At(
863
+ bt
840
864
  );
841
- const yt = ht.exports, At = Object.freeze({
865
+ const Lt = It.exports, Tt = Object.freeze({
842
866
  fileFormat: "article-content-protocol",
843
867
  fileFormatVersion: 1,
844
868
  mediaType: "application/vnd.article-content-protocol+json",
@@ -865,17 +889,17 @@ const yt = ht.exports, At = Object.freeze({
865
889
  "text"
866
890
  ]),
867
891
  markTypes: Object.freeze(["bold", "italic", "strike", "underline", "code", "link"])
868
- }), It = {
892
+ }), _t = {
869
893
  install(n) {
870
- n.component("ArticleContentRenderer", yt);
894
+ n.component("ArticleContentRenderer", Lt);
871
895
  }
872
896
  };
873
897
  export {
874
- At as ARTICLE_CONTENT_PROTOCOL_V1,
875
- yt as ArticleContentRenderer,
876
- It as ArticleContentRendererPlugin,
877
- U as CURRENT_PROTOCOL_VERSION,
878
- bt as SUPPORTED_PROTOCOL_VERSIONS,
879
- yt as default,
880
- dt as validateArticleDocument
898
+ Tt as ARTICLE_CONTENT_PROTOCOL_V1,
899
+ Lt as ArticleContentRenderer,
900
+ _t as ArticleContentRendererPlugin,
901
+ z as CURRENT_PROTOCOL_VERSION,
902
+ Rt as SUPPORTED_PROTOCOL_VERSIONS,
903
+ Lt as default,
904
+ gt as validateArticleDocument
881
905
  };