@docling/docling-components
Version:
Web components for displaying Docling output.
997 lines (984 loc) • 33.5 kB
JavaScript
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const z = globalThis, Q = z.ShadowRoot && (z.ShadyCSS === void 0 || z.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, X = Symbol(), et = /* @__PURE__ */ new WeakMap();
let dt = class {
constructor(t, e, s) {
if (this._$cssResult$ = !0, s !== X) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
this.cssText = t, this.t = e;
}
get styleSheet() {
let t = this.o;
const e = this.t;
if (Q && t === void 0) {
const s = e !== void 0 && e.length === 1;
s && (t = et.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && et.set(e, t));
}
return t;
}
toString() {
return this.cssText;
}
};
const _t = (r) => new dt(typeof r == "string" ? r : r + "", void 0, X), ut = (r, ...t) => {
const e = r.length === 1 ? r[0] : t.reduce((s, i, o) => s + ((n) => {
if (n._$cssResult$ === !0) return n.cssText;
if (typeof n == "number") return n;
throw Error("Value passed to 'css' function must be a 'css' function result: " + n + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
})(i) + r[o + 1], r[0]);
return new dt(e, r, X);
}, yt = (r, t) => {
if (Q) r.adoptedStyleSheets = t.map((e) => e instanceof CSSStyleSheet ? e : e.styleSheet);
else for (const e of t) {
const s = document.createElement("style"), i = z.litNonce;
i !== void 0 && s.setAttribute("nonce", i), s.textContent = e.cssText, r.appendChild(s);
}
}, st = Q ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((t) => {
let e = "";
for (const s of t.cssRules) e += s.cssText;
return _t(e);
})(r) : r;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const { is: vt, defineProperty: At, getOwnPropertyDescriptor: bt, getOwnPropertyNames: wt, getOwnPropertySymbols: Et, getPrototypeOf: St } = Object, w = globalThis, it = w.trustedTypes, Pt = it ? it.emptyScript : "", F = w.reactiveElementPolyfillSupport, H = (r, t) => r, L = { toAttribute(r, t) {
switch (t) {
case Boolean:
r = r ? Pt : null;
break;
case Object:
case Array:
r = r == null ? r : JSON.stringify(r);
}
return r;
}, fromAttribute(r, t) {
let e = r;
switch (t) {
case Boolean:
e = r !== null;
break;
case Number:
e = r === null ? null : Number(r);
break;
case Object:
case Array:
try {
e = JSON.parse(r);
} catch {
e = null;
}
}
return e;
} }, B = (r, t) => !vt(r, t), rt = { attribute: !0, type: String, converter: L, reflect: !1, hasChanged: B };
Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), w.litPropertyMetadata ?? (w.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
class C extends HTMLElement {
static addInitializer(t) {
this._$Ei(), (this.l ?? (this.l = [])).push(t);
}
static get observedAttributes() {
return this.finalize(), this._$Eh && [...this._$Eh.keys()];
}
static createProperty(t, e = rt) {
if (e.state && (e.attribute = !1), this._$Ei(), this.elementProperties.set(t, e), !e.noAccessor) {
const s = Symbol(), i = this.getPropertyDescriptor(t, s, e);
i !== void 0 && At(this.prototype, t, i);
}
}
static getPropertyDescriptor(t, e, s) {
const { get: i, set: o } = bt(this.prototype, t) ?? { get() {
return this[e];
}, set(n) {
this[e] = n;
} };
return { get() {
return i == null ? void 0 : i.call(this);
}, set(n) {
const c = i == null ? void 0 : i.call(this);
o.call(this, n), this.requestUpdate(t, c, s);
}, configurable: !0, enumerable: !0 };
}
static getPropertyOptions(t) {
return this.elementProperties.get(t) ?? rt;
}
static _$Ei() {
if (this.hasOwnProperty(H("elementProperties"))) return;
const t = St(this);
t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
}
static finalize() {
if (this.hasOwnProperty(H("finalized"))) return;
if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(H("properties"))) {
const e = this.properties, s = [...wt(e), ...Et(e)];
for (const i of s) this.createProperty(i, e[i]);
}
const t = this[Symbol.metadata];
if (t !== null) {
const e = litPropertyMetadata.get(t);
if (e !== void 0) for (const [s, i] of e) this.elementProperties.set(s, i);
}
this._$Eh = /* @__PURE__ */ new Map();
for (const [e, s] of this.elementProperties) {
const i = this._$Eu(e, s);
i !== void 0 && this._$Eh.set(i, e);
}
this.elementStyles = this.finalizeStyles(this.styles);
}
static finalizeStyles(t) {
const e = [];
if (Array.isArray(t)) {
const s = new Set(t.flat(1 / 0).reverse());
for (const i of s) e.unshift(st(i));
} else t !== void 0 && e.push(st(t));
return e;
}
static _$Eu(t, e) {
const s = e.attribute;
return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
}
constructor() {
super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
}
_$Ev() {
var t;
this._$ES = new Promise((e) => this.enableUpdating = e), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), (t = this.constructor.l) == null || t.forEach((e) => e(this));
}
addController(t) {
var e;
(this._$EO ?? (this._$EO = /* @__PURE__ */ new Set())).add(t), this.renderRoot !== void 0 && this.isConnected && ((e = t.hostConnected) == null || e.call(t));
}
removeController(t) {
var e;
(e = this._$EO) == null || e.delete(t);
}
_$E_() {
const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
for (const s of e.keys()) this.hasOwnProperty(s) && (t.set(s, this[s]), delete this[s]);
t.size > 0 && (this._$Ep = t);
}
createRenderRoot() {
const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
return yt(t, this.constructor.elementStyles), t;
}
connectedCallback() {
var t;
this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(!0), (t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostConnected) == null ? void 0 : s.call(e);
});
}
enableUpdating(t) {
}
disconnectedCallback() {
var t;
(t = this._$EO) == null || t.forEach((e) => {
var s;
return (s = e.hostDisconnected) == null ? void 0 : s.call(e);
});
}
attributeChangedCallback(t, e, s) {
this._$AK(t, s);
}
_$EC(t, e) {
var o;
const s = this.constructor.elementProperties.get(t), i = this.constructor._$Eu(t, s);
if (i !== void 0 && s.reflect === !0) {
const n = (((o = s.converter) == null ? void 0 : o.toAttribute) !== void 0 ? s.converter : L).toAttribute(e, s.type);
this._$Em = t, n == null ? this.removeAttribute(i) : this.setAttribute(i, n), this._$Em = null;
}
}
_$AK(t, e) {
var o;
const s = this.constructor, i = s._$Eh.get(t);
if (i !== void 0 && this._$Em !== i) {
const n = s.getPropertyOptions(i), c = typeof n.converter == "function" ? { fromAttribute: n.converter } : ((o = n.converter) == null ? void 0 : o.fromAttribute) !== void 0 ? n.converter : L;
this._$Em = i, this[i] = c.fromAttribute(e, n.type), this._$Em = null;
}
}
requestUpdate(t, e, s) {
if (t !== void 0) {
if (s ?? (s = this.constructor.getPropertyOptions(t)), !(s.hasChanged ?? B)(this[t], e)) return;
this.P(t, e, s);
}
this.isUpdatePending === !1 && (this._$ES = this._$ET());
}
P(t, e, s) {
this._$AL.has(t) || this._$AL.set(t, e), s.reflect === !0 && this._$Em !== t && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t);
}
async _$ET() {
this.isUpdatePending = !0;
try {
await this._$ES;
} catch (e) {
Promise.reject(e);
}
const t = this.scheduleUpdate();
return t != null && await t, !this.isUpdatePending;
}
scheduleUpdate() {
return this.performUpdate();
}
performUpdate() {
var s;
if (!this.isUpdatePending) return;
if (!this.hasUpdated) {
if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
for (const [o, n] of this._$Ep) this[o] = n;
this._$Ep = void 0;
}
const i = this.constructor.elementProperties;
if (i.size > 0) for (const [o, n] of i) n.wrapped !== !0 || this._$AL.has(o) || this[o] === void 0 || this.P(o, this[o], n);
}
let t = !1;
const e = this._$AL;
try {
t = this.shouldUpdate(e), t ? (this.willUpdate(e), (s = this._$EO) == null || s.forEach((i) => {
var o;
return (o = i.hostUpdate) == null ? void 0 : o.call(i);
}), this.update(e)) : this._$EU();
} catch (i) {
throw t = !1, this._$EU(), i;
}
t && this._$AE(e);
}
willUpdate(t) {
}
_$AE(t) {
var e;
(e = this._$EO) == null || e.forEach((s) => {
var i;
return (i = s.hostUpdated) == null ? void 0 : i.call(s);
}), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
}
_$EU() {
this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
}
get updateComplete() {
return this.getUpdateComplete();
}
getUpdateComplete() {
return this._$ES;
}
shouldUpdate(t) {
return !0;
}
update(t) {
this._$Ej && (this._$Ej = this._$Ej.forEach((e) => this._$EC(e, this[e]))), this._$EU();
}
updated(t) {
}
firstUpdated(t) {
}
}
C.elementStyles = [], C.shadowRootOptions = { mode: "open" }, C[H("elementProperties")] = /* @__PURE__ */ new Map(), C[H("finalized")] = /* @__PURE__ */ new Map(), F == null || F({ ReactiveElement: C }), (w.reactiveElementVersions ?? (w.reactiveElementVersions = [])).push("2.0.4");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const N = globalThis, q = N.trustedTypes, ot = q ? q.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, ft = "$lit$", b = `lit$${Math.random().toFixed(9).slice(2)}$`, $t = "?" + b, xt = `<${$t}>`, P = document, k = () => P.createComment(""), M = (r) => r === null || typeof r != "object" && typeof r != "function", Y = Array.isArray, Ct = (r) => Y(r) || typeof (r == null ? void 0 : r[Symbol.iterator]) == "function", J = `[
\f\r]`, I = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, nt = /-->/g, ht = />/g, E = RegExp(`>|${J}(?:([^\\s"'>=/]+)(${J}*=${J}*(?:[^
\f\r"'\`<>=]|("|')|))|$)`, "g"), at = /'/g, ct = /"/g, mt = /^(?:script|style|textarea|title)$/i, Ut = (r) => (t, ...e) => ({ _$litType$: r, strings: t, values: e }), A = Ut(1), U = Symbol.for("lit-noChange"), $ = Symbol.for("lit-nothing"), lt = /* @__PURE__ */ new WeakMap(), S = P.createTreeWalker(P, 129);
function gt(r, t) {
if (!Y(r) || !r.hasOwnProperty("raw")) throw Error("invalid template strings array");
return ot !== void 0 ? ot.createHTML(t) : t;
}
const Tt = (r, t) => {
const e = r.length - 1, s = [];
let i, o = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", n = I;
for (let c = 0; c < e; c++) {
const a = r[c];
let p, d, h = -1, l = 0;
for (; l < a.length && (n.lastIndex = l, d = n.exec(a), d !== null); ) l = n.lastIndex, n === I ? d[1] === "!--" ? n = nt : d[1] !== void 0 ? n = ht : d[2] !== void 0 ? (mt.test(d[2]) && (i = RegExp("</" + d[2], "g")), n = E) : d[3] !== void 0 && (n = E) : n === E ? d[0] === ">" ? (n = i ?? I, h = -1) : d[1] === void 0 ? h = -2 : (h = n.lastIndex - d[2].length, p = d[1], n = d[3] === void 0 ? E : d[3] === '"' ? ct : at) : n === ct || n === at ? n = E : n === nt || n === ht ? n = I : (n = E, i = void 0);
const u = n === E && r[c + 1].startsWith("/>") ? " " : "";
o += n === I ? a + xt : h >= 0 ? (s.push(p), a.slice(0, h) + ft + a.slice(h) + b + u) : a + b + (h === -2 ? c : u);
}
return [gt(r, o + (r[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
};
class D {
constructor({ strings: t, _$litType$: e }, s) {
let i;
this.parts = [];
let o = 0, n = 0;
const c = t.length - 1, a = this.parts, [p, d] = Tt(t, e);
if (this.el = D.createElement(p, s), S.currentNode = this.el.content, e === 2 || e === 3) {
const h = this.el.content.firstChild;
h.replaceWith(...h.childNodes);
}
for (; (i = S.nextNode()) !== null && a.length < c; ) {
if (i.nodeType === 1) {
if (i.hasAttributes()) for (const h of i.getAttributeNames()) if (h.endsWith(ft)) {
const l = d[n++], u = i.getAttribute(h).split(b), m = /([.?@])?(.*)/.exec(l);
a.push({ type: 1, index: o, name: m[2], strings: u, ctor: m[1] === "." ? It : m[1] === "?" ? Ht : m[1] === "@" ? Nt : W }), i.removeAttribute(h);
} else h.startsWith(b) && (a.push({ type: 6, index: o }), i.removeAttribute(h));
if (mt.test(i.tagName)) {
const h = i.textContent.split(b), l = h.length - 1;
if (l > 0) {
i.textContent = q ? q.emptyScript : "";
for (let u = 0; u < l; u++) i.append(h[u], k()), S.nextNode(), a.push({ type: 2, index: ++o });
i.append(h[l], k());
}
}
} else if (i.nodeType === 8) if (i.data === $t) a.push({ type: 2, index: o });
else {
let h = -1;
for (; (h = i.data.indexOf(b, h + 1)) !== -1; ) a.push({ type: 7, index: o }), h += b.length - 1;
}
o++;
}
}
static createElement(t, e) {
const s = P.createElement("template");
return s.innerHTML = t, s;
}
}
function T(r, t, e = r, s) {
var n, c;
if (t === U) return t;
let i = s !== void 0 ? (n = e._$Co) == null ? void 0 : n[s] : e._$Cl;
const o = M(t) ? void 0 : t._$litDirective$;
return (i == null ? void 0 : i.constructor) !== o && ((c = i == null ? void 0 : i._$AO) == null || c.call(i, !1), o === void 0 ? i = void 0 : (i = new o(r), i._$AT(r, e, s)), s !== void 0 ? (e._$Co ?? (e._$Co = []))[s] = i : e._$Cl = i), i !== void 0 && (t = T(r, i._$AS(r, t.values), i, s)), t;
}
class Ot {
constructor(t, e) {
this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e;
}
get parentNode() {
return this._$AM.parentNode;
}
get _$AU() {
return this._$AM._$AU;
}
u(t) {
const { el: { content: e }, parts: s } = this._$AD, i = ((t == null ? void 0 : t.creationScope) ?? P).importNode(e, !0);
S.currentNode = i;
let o = S.nextNode(), n = 0, c = 0, a = s[0];
for (; a !== void 0; ) {
if (n === a.index) {
let p;
a.type === 2 ? p = new j(o, o.nextSibling, this, t) : a.type === 1 ? p = new a.ctor(o, a.name, a.strings, this, t) : a.type === 6 && (p = new Rt(o, this, t)), this._$AV.push(p), a = s[++c];
}
n !== (a == null ? void 0 : a.index) && (o = S.nextNode(), n++);
}
return S.currentNode = P, i;
}
p(t) {
let e = 0;
for (const s of this._$AV) s !== void 0 && (s.strings !== void 0 ? (s._$AI(t, s, e), e += s.strings.length - 2) : s._$AI(t[e])), e++;
}
}
class j {
get _$AU() {
var t;
return ((t = this._$AM) == null ? void 0 : t._$AU) ?? this._$Cv;
}
constructor(t, e, s, i) {
this.type = 2, this._$AH = $, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = s, this.options = i, this._$Cv = (i == null ? void 0 : i.isConnected) ?? !0;
}
get parentNode() {
let t = this._$AA.parentNode;
const e = this._$AM;
return e !== void 0 && (t == null ? void 0 : t.nodeType) === 11 && (t = e.parentNode), t;
}
get startNode() {
return this._$AA;
}
get endNode() {
return this._$AB;
}
_$AI(t, e = this) {
t = T(this, t, e), M(t) ? t === $ || t == null || t === "" ? (this._$AH !== $ && this._$AR(), this._$AH = $) : t !== this._$AH && t !== U && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : Ct(t) ? this.k(t) : this._(t);
}
O(t) {
return this._$AA.parentNode.insertBefore(t, this._$AB);
}
T(t) {
this._$AH !== t && (this._$AR(), this._$AH = this.O(t));
}
_(t) {
this._$AH !== $ && M(this._$AH) ? this._$AA.nextSibling.data = t : this.T(P.createTextNode(t)), this._$AH = t;
}
$(t) {
var o;
const { values: e, _$litType$: s } = t, i = typeof s == "number" ? this._$AC(t) : (s.el === void 0 && (s.el = D.createElement(gt(s.h, s.h[0]), this.options)), s);
if (((o = this._$AH) == null ? void 0 : o._$AD) === i) this._$AH.p(e);
else {
const n = new Ot(i, this), c = n.u(this.options);
n.p(e), this.T(c), this._$AH = n;
}
}
_$AC(t) {
let e = lt.get(t.strings);
return e === void 0 && lt.set(t.strings, e = new D(t)), e;
}
k(t) {
Y(this._$AH) || (this._$AH = [], this._$AR());
const e = this._$AH;
let s, i = 0;
for (const o of t) i === e.length ? e.push(s = new j(this.O(k()), this.O(k()), this, this.options)) : s = e[i], s._$AI(o), i++;
i < e.length && (this._$AR(s && s._$AB.nextSibling, i), e.length = i);
}
_$AR(t = this._$AA.nextSibling, e) {
var s;
for ((s = this._$AP) == null ? void 0 : s.call(this, !1, !0, e); t && t !== this._$AB; ) {
const i = t.nextSibling;
t.remove(), t = i;
}
}
setConnected(t) {
var e;
this._$AM === void 0 && (this._$Cv = t, (e = this._$AP) == null || e.call(this, t));
}
}
class W {
get tagName() {
return this.element.tagName;
}
get _$AU() {
return this._$AM._$AU;
}
constructor(t, e, s, i, o) {
this.type = 1, this._$AH = $, this._$AN = void 0, this.element = t, this.name = e, this._$AM = i, this.options = o, s.length > 2 || s[0] !== "" || s[1] !== "" ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = $;
}
_$AI(t, e = this, s, i) {
const o = this.strings;
let n = !1;
if (o === void 0) t = T(this, t, e, 0), n = !M(t) || t !== this._$AH && t !== U, n && (this._$AH = t);
else {
const c = t;
let a, p;
for (t = o[0], a = 0; a < o.length - 1; a++) p = T(this, c[s + a], e, a), p === U && (p = this._$AH[a]), n || (n = !M(p) || p !== this._$AH[a]), p === $ ? t = $ : t !== $ && (t += (p ?? "") + o[a + 1]), this._$AH[a] = p;
}
n && !i && this.j(t);
}
j(t) {
t === $ ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
}
}
class It extends W {
constructor() {
super(...arguments), this.type = 3;
}
j(t) {
this.element[this.name] = t === $ ? void 0 : t;
}
}
class Ht extends W {
constructor() {
super(...arguments), this.type = 4;
}
j(t) {
this.element.toggleAttribute(this.name, !!t && t !== $);
}
}
class Nt extends W {
constructor(t, e, s, i, o) {
super(t, e, s, i, o), this.type = 5;
}
_$AI(t, e = this) {
if ((t = T(this, t, e, 0) ?? $) === U) return;
const s = this._$AH, i = t === $ && s !== $ || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive, o = t !== $ && (s === $ || i);
i && this.element.removeEventListener(this.name, this, s), o && this.element.addEventListener(this.name, this, t), this._$AH = t;
}
handleEvent(t) {
var e;
typeof this._$AH == "function" ? this._$AH.call(((e = this.options) == null ? void 0 : e.host) ?? this.element, t) : this._$AH.handleEvent(t);
}
}
class Rt {
constructor(t, e, s) {
this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = s;
}
get _$AU() {
return this._$AM._$AU;
}
_$AI(t) {
T(this, t);
}
}
const K = N.litHtmlPolyfillSupport;
K == null || K(D, j), (N.litHtmlVersions ?? (N.litHtmlVersions = [])).push("3.2.1");
const kt = (r, t, e) => {
const s = (e == null ? void 0 : e.renderBefore) ?? t;
let i = s._$litPart$;
if (i === void 0) {
const o = (e == null ? void 0 : e.renderBefore) ?? null;
s._$litPart$ = i = new j(t.insertBefore(k(), o), o, void 0, e ?? {});
}
return i._$AI(r), i;
};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
let R = class extends C {
constructor() {
super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
}
createRenderRoot() {
var e;
const t = super.createRenderRoot();
return (e = this.renderOptions).renderBefore ?? (e.renderBefore = t.firstChild), t;
}
update(t) {
const e = this.render();
this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = kt(e, this.renderRoot, this.renderOptions);
}
connectedCallback() {
var t;
super.connectedCallback(), (t = this._$Do) == null || t.setConnected(!0);
}
disconnectedCallback() {
var t;
super.disconnectedCallback(), (t = this._$Do) == null || t.setConnected(!1);
}
render() {
return U;
}
};
var pt;
R._$litElement$ = !0, R.finalized = !0, (pt = globalThis.litElementHydrateSupport) == null || pt.call(globalThis, { LitElement: R });
const Z = globalThis.litElementPolyfillSupport;
Z == null || Z({ LitElement: R });
(globalThis.litElementVersions ?? (globalThis.litElementVersions = [])).push("4.1.1");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const Mt = (r) => (t, e) => {
e !== void 0 ? e.addInitializer(() => {
customElements.define(r, t);
}) : customElements.define(r, t);
};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const Dt = { attribute: !0, type: String, converter: L, reflect: !1, hasChanged: B }, jt = (r = Dt, t, e) => {
const { kind: s, metadata: i } = e;
let o = globalThis.litPropertyMetadata.get(i);
if (o === void 0 && globalThis.litPropertyMetadata.set(i, o = /* @__PURE__ */ new Map()), o.set(e.name, r), s === "accessor") {
const { name: n } = e;
return { set(c) {
const a = t.get.call(this);
t.set.call(this, c), this.requestUpdate(n, a, r);
}, init(c) {
return c !== void 0 && this.P(n, void 0, r), c;
} };
}
if (s === "setter") {
const { name: n } = e;
return function(c) {
const a = this[n];
t.call(this, c), this.requestUpdate(n, a, r);
};
}
throw Error("Unsupported decorator location: " + s);
};
function v(r) {
return (t, e) => typeof e == "object" ? jt(r, t, e) : ((s, i, o) => {
const n = i.hasOwnProperty(o);
return i.constructor.createProperty(o, n ? { ...s, wrapped: !0 } : s), n ? Object.getOwnPropertyDescriptor(i, o) : void 0;
})(r, t, e);
}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const zt = Symbol();
class Lt {
get taskComplete() {
return this.t || (this.i === 1 ? this.t = new Promise((t, e) => {
this.o = t, this.h = e;
}) : this.i === 3 ? this.t = Promise.reject(this.l) : this.t = Promise.resolve(this.u)), this.t;
}
constructor(t, e, s) {
var o;
this.p = 0, this.i = 0, (this._ = t).addController(this);
const i = typeof e == "object" ? e : { task: e, args: s };
this.v = i.task, this.j = i.args, this.m = i.argsEqual ?? qt, this.k = i.onComplete, this.A = i.onError, this.autoRun = i.autoRun ?? !0, "initialValue" in i && (this.u = i.initialValue, this.i = 2, this.O = (o = this.T) == null ? void 0 : o.call(this));
}
hostUpdate() {
this.autoRun === !0 && this.S();
}
hostUpdated() {
this.autoRun === "afterUpdate" && this.S();
}
T() {
if (this.j === void 0) return;
const t = this.j();
if (!Array.isArray(t)) throw Error("The args function must return an array");
return t;
}
async S() {
const t = this.T(), e = this.O;
this.O = t, t === e || t === void 0 || e !== void 0 && this.m(e, t) || await this.run(t);
}
async run(t) {
var n, c, a, p, d;
let e, s;
t ?? (t = this.T()), this.O = t, this.i === 1 ? (n = this.q) == null || n.abort() : (this.t = void 0, this.o = void 0, this.h = void 0), this.i = 1, this.autoRun === "afterUpdate" ? queueMicrotask(() => this._.requestUpdate()) : this._.requestUpdate();
const i = ++this.p;
this.q = new AbortController();
let o = !1;
try {
e = await this.v(t, { signal: this.q.signal });
} catch (h) {
o = !0, s = h;
}
if (this.p === i) {
if (e === zt) this.i = 0;
else {
if (o === !1) {
try {
(c = this.k) == null || c.call(this, e);
} catch {
}
this.i = 2, (a = this.o) == null || a.call(this, e);
} else {
try {
(p = this.A) == null || p.call(this, s);
} catch {
}
this.i = 3, (d = this.h) == null || d.call(this, s);
}
this.u = e, this.l = s;
}
this._.requestUpdate();
}
}
abort(t) {
var e;
this.i === 1 && ((e = this.q) == null || e.abort(t));
}
get value() {
return this.u;
}
get error() {
return this.l;
}
get status() {
return this.i;
}
render(t) {
var e, s, i, o;
switch (this.i) {
case 0:
return (e = t.initial) == null ? void 0 : e.call(t);
case 1:
return (s = t.pending) == null ? void 0 : s.call(t);
case 2:
return (i = t.complete) == null ? void 0 : i.call(t, this.value);
case 3:
return (o = t.error) == null ? void 0 : o.call(t, this.error);
default:
throw Error("Unexpected status: " + this.i);
}
}
}
const qt = (r, t) => r === t || r.length === t.length && r.every((e, s) => !B(e, t[s]));
function x(...r) {
return function(t) {
return y.DocItem(t) && r.includes(t.label);
};
}
var Bt = {
CodeItem: x("code"),
ListItem: x("list_item"),
PictureItem: x("picture"),
SectionHeaderItem: x("section_header"),
TableItem: x("document_index", "table"),
TextItem: x(
"caption",
"checkbox_selected",
"checkbox_unselected",
"footnote",
"page_footer",
"page_header",
"paragraph",
"reference",
"text"
)
}, y = {
Document(r) {
return "schema_name" in r && r.schema_name === "DoclingDocument";
},
NodeItem(r) {
return "self_ref" in r;
},
GroupItem(r) {
return y.NodeItem(r) && (r.self_ref.startsWith("#/groups/") || r.self_ref === "#/body");
},
DocItem(r) {
return y.NodeItem(r) && !y.GroupItem(r);
},
...Bt
};
function* Wt(r, t = {}) {
r && (yield* e(t.root ?? r.body));
function* e(s, i = 0) {
var o;
if ((!y.GroupItem(s) || t.withGroups) && (y.DocItem(s) ? (t.pageNo === void 0 || (o = s.prov) != null && o.some((n) => n.page_no === t.pageNo)) && (yield [s, i]) : yield [s, i]), !(y.PictureItem(s) && !t.traversePictures))
for (const n of s.children ?? []) {
const c = Vt(r, n);
y.NodeItem(c) && (yield* e(c, i + 1));
}
}
}
function Vt(r, t) {
return t.$ref.split("/").slice(1).reduce(
(s, i) => s[i],
r
);
}
function Gt(r) {
return Object.values((r == null ? void 0 : r.pages) ?? {}).sort(
(t, e) => t.page_no - e.page_no
);
}
async function Ft(r, t = {}) {
var a, p, d;
let e;
typeof r == "string" ? e = await (await fetch(r)).json() : typeof r == "object" && y.Document(r) && (e = r);
const s = Gt(e), i = Array.from(Wt(e)).map(
([h]) => h
);
let o = i;
const n = /* @__PURE__ */ new Set();
if (typeof t.items == "string") {
const h = new Set(
t.items.split(",").map((l) => l.trim()).filter((l) => l.length > 0)
);
if (h.size > 0) {
o = [];
for (const l of i) {
const u = l.self_ref.split("/"), m = [];
for (let f = 2; f < u.length + 1; f++)
m.push(u.slice(0, f).join("/"));
(a = l.prov) == null || a.forEach((f) => m.push(`#/pages/${f.page_no}`)), m.some((f) => h.has(f)) ? o.push(l) : (p = l.prov) == null || p.forEach((f) => n.add(f.page_no));
}
}
} else if (Array.isArray(t.items)) {
o = [];
const h = new Set(t.items);
for (const l of i)
h.has(l) ? o.push(l) : (d = l.prov) == null || d.forEach((u) => n.add(u.page_no));
}
const c = {};
for (const h of s)
c[h.page_no] = [];
for (const h of o)
for (const l of h.prov ?? [])
c[l.page_no].push(h);
return s.map((h) => ({
page: h,
items: c[h.page_no],
trimmed: n.has(h.page_no)
}));
}
function Jt({
page: r,
items: t = [],
pagenumbers: e,
backdrop: s,
// tooltip,
itemPart: i,
itemStyle: o,
onclickitem: n
}) {
if (r.image) {
const { size: a } = r, { width: p = 1, height: d = 1 } = a, h = n ? (l, u) => n(l, r, u) : void 0;
return A`
<div part="page" class="page" @onclick=${(l) => h == null ? void 0 : h(l)} role="tab">
<svg width=${r.image.size.width} viewBox="0 0 ${p} ${d}">
<!-- Suppressed backdrop image. -->
${s ? A`
<image
class="backdrop"
href=${r.image.uri}
width=${p}
height=${d}
/>
<clippath id="clip-page-${r.page_no}">
${t.map((l) => {
var m;
const u = (m = l.prov) == null ? void 0 : m.find((f) => f.page_no === r.page_no);
if (u) {
const { l: f, r: V, t: O, b: G } = u.bbox;
return A`<rect
x=${f}
y=${d - O}
width=${V - f}
height=${O - G}
/>`;
}
})}
</clippath>
` : ""}
<!-- Foreground image. -->
<image
id="image"
href=${r.image.uri}
clip-path="url(#clip-page-${r.page_no})"
width=${p}
height${d}
/>
${t.map((l) => {
var m;
const u = (m = l.prov) == null ? void 0 : m.find((f) => f.page_no === r.page_no);
if (u) {
const { l: f, r: V, t: O, b: G } = u.bbox;
return A`<rect
part=${"item" + (i ? " " + i(r, l) : "")}
style=${o == null ? void 0 : o(r, l)}
x=${f}
y=${d - O}
width=${V - f}
height=${O - G}
vector-effect="non-scaling-stroke"
@onclick=${(tt) => {
tt.stopPropagation(), h == null || h(tt, l);
}}
@onmouseenter={(e: MouseEvent) => {
const bounds = e.currentTarget.getBoundingClientRect();
// Sizes of surrounding areas: Top, right, bottom, left.
const areas = [
bounds.top * window.innerWidth,
(window.innerWidth - bounds.right) * window.innerHeight,
(window.innerHeight - bounds.bottom) * window.innerWidth,
bounds.left * window.innerHeight,
];
const maxArea = Math.max(...areas);
const quadrant = areas.findIndex(a => a === maxArea);
hovered = {
item,
bounds,
quadrant,
};
}}
/>`;
}
})}
</svg>
${e ? A`<header
part="page-number-top"
class="page-number-top"
title="Page ${r.page_no}"
>
${r.page_no}
</header>
<header
part="page-number-bottom"
class="page-number-bottom"
title="Page ${r.page_no}"
>
${r.page_no}
</header>` : ""}
<!-- Tooltip. -->
${c()}
</div>
`;
} else
return A`Invalid page image.`;
function c() {
return "";
}
}
const Kt = ut`
.page {
width: fit-content;
max-width: 100%;
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
color: black;
}
`;
var Zt = Object.defineProperty, Qt = Object.getOwnPropertyDescriptor, _ = (r, t, e, s) => {
for (var i = s > 1 ? void 0 : s ? Qt(t, e) : t, o = r.length - 1, n; o >= 0; o--)
(n = r[o]) && (i = (s ? n(t, e, i) : n(i)) || i);
return s && i && Zt(t, e, i), i;
};
let g = class extends R {
constructor() {
super(...arguments), this.src = "", this.trim = "pages", this._fetchTask = new Lt(this, {
task: async ([r, t]) => Ft(r, { items: t }),
args: () => [this.src, this.items]
});
}
render() {
return this._fetchTask.render({
pending: () => A`<p>...</p>`,
complete: (r) => A`
<div part="paged">
${r.filter((t) => !this.trim || t.items.length > 0).map(
({ page: t, items: e }) => Jt({
page: t,
items: e,
pagenumbers: this.pagenumbers !== void 0,
backdrop: this.backdrop !== void 0,
itemPart: this.itemPart,
itemStyle: this.itemStyle,
onclickitem: this.onclickitem
})
)}
</div>
`
});
}
};
g.styles = [
ut`
div {
width: fit-content;
max-width: 100%;
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
color: black;
}
`,
Kt
];
_([
v()
], g.prototype, "alt", 2);
_([
v()
], g.prototype, "backdrop", 2);
_([
v()
], g.prototype, "items", 2);
_([
v()
], g.prototype, "pagenumbers", 2);
_([
v()
], g.prototype, "src", 2);
_([
v()
], g.prototype, "trim", 2);
_([
v()
], g.prototype, "itemPart", 2);
_([
v()
], g.prototype, "itemStyle", 2);
_([
v()
], g.prototype, "onclickitem", 2);
g = _([
Mt("docling-img")
], g);
export {
g as ImgPages
};