UNPKG

@docling/docling-components

Version:
141 lines (128 loc) 26.1 kB
(function($,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):($=typeof globalThis<"u"?globalThis:$||self,A($.DoclingComponents={}))})(this,function($){"use strict";/** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */var gt;const A=globalThis,V=A.ShadowRoot&&(A.ShadyCSS===void 0||A.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,G=Symbol(),tt=new WeakMap;let et=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==G)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(V&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=tt.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&tt.set(e,t))}return t}toString(){return this.cssText}};const _t=r=>new et(typeof r=="string"?r:r+"",void 0,G),st=(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 et(e,r,G)},yt=(r,t)=>{if(V)r.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const s=document.createElement("style"),i=A.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,r.appendChild(s)}},it=V?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:Pt}=Object,b=globalThis,rt=b.trustedTypes,St=rt?rt.emptyScript:"",F=b.reactiveElementPolyfillSupport,O=(r,t)=>r,L={toAttribute(r,t){switch(t){case Boolean:r=r?St: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}},q=(r,t)=>!vt(r,t),ot={attribute:!0,type:String,converter:L,reflect:!1,hasChanged:q};Symbol.metadata??(Symbol.metadata=Symbol("metadata")),b.litPropertyMetadata??(b.litPropertyMetadata=new WeakMap);class x 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=ot){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)??ot}static _$Ei(){if(this.hasOwnProperty(O("elementProperties")))return;const t=Pt(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(O("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(O("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=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(it(i))}else t!==void 0&&e.push(it(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=new Map,this._$E_(),this.requestUpdate(),(t=this.constructor.l)==null||t.forEach(e=>e(this))}addController(t){var e;(this._$EO??(this._$EO=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=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??q)(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=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=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){}}x.elementStyles=[],x.shadowRootOptions={mode:"open"},x[O("elementProperties")]=new Map,x[O("finalized")]=new Map,F==null||F({ReactiveElement:x}),(b.reactiveElementVersions??(b.reactiveElementVersions=[])).push("2.0.4");/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const H=globalThis,B=H.trustedTypes,nt=B?B.createPolicy("lit-html",{createHTML:r=>r}):void 0,at="$lit$",w=`lit$${Math.random().toFixed(9).slice(2)}$`,ht="?"+w,Ct=`<${ht}>`,P=document,N=()=>P.createComment(""),R=r=>r===null||typeof r!="object"&&typeof r!="function",J=Array.isArray,xt=r=>J(r)||typeof(r==null?void 0:r[Symbol.iterator])=="function",K=`[ \f\r]`,k=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ct=/-->/g,lt=/>/g,S=RegExp(`>|${K}(?:([^\\s"'>=/]+)(${K}*=${K}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),dt=/'/g,pt=/"/g,ut=/^(?:script|style|textarea|title)$/i,It=r=>(t,...e)=>({_$litType$:r,strings:t,values:e}),E=It(1),I=Symbol.for("lit-noChange"),g=Symbol.for("lit-nothing"),ft=new WeakMap,C=P.createTreeWalker(P,129);function $t(r,t){if(!J(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return nt!==void 0?nt.createHTML(t):t}const Ut=(r,t)=>{const e=r.length-1,s=[];let i,o=t===2?"<svg>":t===3?"<math>":"",n=k;for(let c=0;c<e;c++){const h=r[c];let d,p,a=-1,l=0;for(;l<h.length&&(n.lastIndex=l,p=n.exec(h),p!==null);)l=n.lastIndex,n===k?p[1]==="!--"?n=ct:p[1]!==void 0?n=lt:p[2]!==void 0?(ut.test(p[2])&&(i=RegExp("</"+p[2],"g")),n=S):p[3]!==void 0&&(n=S):n===S?p[0]===">"?(n=i??k,a=-1):p[1]===void 0?a=-2:(a=n.lastIndex-p[2].length,d=p[1],n=p[3]===void 0?S:p[3]==='"'?pt:dt):n===pt||n===dt?n=S:n===ct||n===lt?n=k:(n=S,i=void 0);const u=n===S&&r[c+1].startsWith("/>")?" ":"";o+=n===k?h+Ct:a>=0?(s.push(d),h.slice(0,a)+at+h.slice(a)+w+u):h+w+(a===-2?c:u)}return[$t(r,o+(r[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class M{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let o=0,n=0;const c=t.length-1,h=this.parts,[d,p]=Ut(t,e);if(this.el=M.createElement(d,s),C.currentNode=this.el.content,e===2||e===3){const a=this.el.content.firstChild;a.replaceWith(...a.childNodes)}for(;(i=C.nextNode())!==null&&h.length<c;){if(i.nodeType===1){if(i.hasAttributes())for(const a of i.getAttributeNames())if(a.endsWith(at)){const l=p[n++],u=i.getAttribute(a).split(w),m=/([.?@])?(.*)/.exec(l);h.push({type:1,index:o,name:m[2],strings:u,ctor:m[1]==="."?Ot:m[1]==="?"?Ht:m[1]==="@"?Nt:W}),i.removeAttribute(a)}else a.startsWith(w)&&(h.push({type:6,index:o}),i.removeAttribute(a));if(ut.test(i.tagName)){const a=i.textContent.split(w),l=a.length-1;if(l>0){i.textContent=B?B.emptyScript:"";for(let u=0;u<l;u++)i.append(a[u],N()),C.nextNode(),h.push({type:2,index:++o});i.append(a[l],N())}}}else if(i.nodeType===8)if(i.data===ht)h.push({type:2,index:o});else{let a=-1;for(;(a=i.data.indexOf(w,a+1))!==-1;)h.push({type:7,index:o}),a+=w.length-1}o++}}static createElement(t,e){const s=P.createElement("template");return s.innerHTML=t,s}}function U(r,t,e=r,s){var n,c;if(t===I)return t;let i=s!==void 0?(n=e._$Co)==null?void 0:n[s]:e._$Cl;const o=R(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=U(r,i._$AS(r,t.values),i,s)),t}class Tt{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);C.currentNode=i;let o=C.nextNode(),n=0,c=0,h=s[0];for(;h!==void 0;){if(n===h.index){let d;h.type===2?d=new D(o,o.nextSibling,this,t):h.type===1?d=new h.ctor(o,h.name,h.strings,this,t):h.type===6&&(d=new Rt(o,this,t)),this._$AV.push(d),h=s[++c]}n!==(h==null?void 0:h.index)&&(o=C.nextNode(),n++)}return C.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 D{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=g,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=U(this,t,e),R(t)?t===g||t==null||t===""?(this._$AH!==g&&this._$AR(),this._$AH=g):t!==this._$AH&&t!==I&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):xt(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!==g&&R(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=M.createElement($t(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 Tt(i,this),c=n.u(this.options);n.p(e),this.T(c),this._$AH=n}}_$AC(t){let e=ft.get(t.strings);return e===void 0&&ft.set(t.strings,e=new M(t)),e}k(t){J(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 D(this.O(N()),this.O(N()),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=g,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=g}_$AI(t,e=this,s,i){const o=this.strings;let n=!1;if(o===void 0)t=U(this,t,e,0),n=!R(t)||t!==this._$AH&&t!==I,n&&(this._$AH=t);else{const c=t;let h,d;for(t=o[0],h=0;h<o.length-1;h++)d=U(this,c[s+h],e,h),d===I&&(d=this._$AH[h]),n||(n=!R(d)||d!==this._$AH[h]),d===g?t=g:t!==g&&(t+=(d??"")+o[h+1]),this._$AH[h]=d}n&&!i&&this.j(t)}j(t){t===g?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Ot extends W{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===g?void 0:t}}class Ht extends W{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==g)}}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=U(this,t,e,0)??g)===I)return;const s=this._$AH,i=t===g&&s!==g||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,o=t!==g&&(s===g||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){U(this,t)}}const Z=H.litHtmlPolyfillSupport;Z==null||Z(M,D),(H.litHtmlVersions??(H.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 D(t.insertBefore(N(),o),o,void 0,e??{})}return i._$AI(r),i};/** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */let j=class extends x{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 I}};j._$litElement$=!0,j.finalized=!0,(gt=globalThis.litElementHydrateSupport)==null||gt.call(globalThis,{LitElement:j});const Q=globalThis.litElementPolyfillSupport;Q==null||Q({LitElement:j}),(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:q},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=new Map),o.set(e.name,r),s==="accessor"){const{name:n}=e;return{set(c){const h=t.get.call(this);t.set.call(this,c),this.requestUpdate(n,h,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 h=this[n];t.call(this,c),this.requestUpdate(n,h,r)}}throw Error("Unsupported decorator location: "+s)};function y(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,h,d,p;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(a){o=!0,s=a}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,(h=this.o)==null||h.call(this,e)}else{try{(d=this.A)==null||d.call(this,s)}catch{}this.i=3,(p=this.h)==null||p.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)=>!q(e,t[s]));function T(...r){return function(t){return v.DocItem(t)&&r.includes(t.label)}}var Bt={CodeItem:T("code"),ListItem:T("list_item"),PictureItem:T("picture"),SectionHeaderItem:T("section_header"),TableItem:T("document_index","table"),TextItem:T("caption","checkbox_selected","checkbox_unselected","footnote","page_footer","page_header","paragraph","reference","text")},v={Document(r){return"schema_name"in r&&r.schema_name==="DoclingDocument"},NodeItem(r){return"self_ref"in r},GroupItem(r){return v.NodeItem(r)&&(r.self_ref.startsWith("#/groups/")||r.self_ref==="#/body")},DocItem(r){return v.NodeItem(r)&&!v.GroupItem(r)},...Bt};function*Wt(r,t={}){r&&(yield*e(t.root??r.body));function*e(s,i=0){var o;if((!v.GroupItem(s)||t.withGroups)&&(v.DocItem(s)?(t.pageNo===void 0||(o=s.prov)!=null&&o.some(n=>n.page_no===t.pageNo))&&(yield[s,i]):yield[s,i]),!(v.PictureItem(s)&&!t.traversePictures))for(const n of s.children??[]){const c=Vt(r,n);v.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 h,d,p;let e;typeof r=="string"?e=await(await fetch(r)).json():typeof r=="object"&&v.Document(r)&&(e=r);const s=Gt(e),i=Array.from(Wt(e)).map(([a])=>a);let o=i;const n=new Set;if(typeof t.items=="string"){const a=new Set(t.items.split(",").map(l=>l.trim()).filter(l=>l.length>0));if(a.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("/"));(h=l.prov)==null||h.forEach(f=>m.push(`#/pages/${f.page_no}`)),m.some(f=>a.has(f))?o.push(l):(d=l.prov)==null||d.forEach(f=>n.add(f.page_no))}}}else if(Array.isArray(t.items)){o=[];const a=new Set(t.items);for(const l of i)a.has(l)?o.push(l):(p=l.prov)==null||p.forEach(u=>n.add(u.page_no))}const c={};for(const a of s)c[a.page_no]=[];for(const a of o)for(const l of a.prov??[])c[l.page_no].push(a);return s.map(a=>({page:a,items:c[a.page_no],trimmed:n.has(a.page_no)}))}function Jt({page:r,items:t=[],pagenumbers:e,backdrop:s,itemPart:i,itemStyle:o,onclickitem:n}){if(r.image){const{size:h}=r,{width:d=1,height:p=1}=h,a=n?(l,u)=>n(l,r,u):void 0;return E` <div part="page" class="page" @onclick=${l=>a==null?void 0:a(l)} role="tab"> <svg width=${r.image.size.width} viewBox="0 0 ${d} ${p}"> <!-- Suppressed backdrop image. --> ${s?E` <image class="backdrop" href=${r.image.uri} width=${d} height=${p} /> <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:X,t:z,b:Y}=u.bbox;return E`<rect x=${f} y=${p-z} width=${X-f} height=${z-Y} />`}})} </clippath> `:""} <!-- Foreground image. --> <image id="image" href=${r.image.uri} clip-path="url(#clip-page-${r.page_no})" width=${d} height${p} /> ${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:X,t:z,b:Y}=u.bbox;return E`<rect part=${"item"+(i?" "+i(r,l):"")} style=${o==null?void 0:o(r,l)} x=${f} y=${p-z} width=${X-f} height=${z-Y} vector-effect="non-scaling-stroke" @onclick=${mt=>{mt.stopPropagation(),a==null||a(mt,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?E`<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 E`Invalid page image.`;function c(){return""}}const Kt=st` .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};$.ImgPages=class extends j{constructor(){super(...arguments),this.src="",this.trim="pages",this._fetchTask=new Lt(this,{task:async([t,e])=>Ft(t,{items:e}),args:()=>[this.src,this.items]})}render(){return this._fetchTask.render({pending:()=>E`<p>...</p>`,complete:t=>E` <div part="paged"> ${t.filter(e=>!this.trim||e.items.length>0).map(({page:e,items:s})=>Jt({page:e,items:s,pagenumbers:this.pagenumbers!==void 0,backdrop:this.backdrop!==void 0,itemPart:this.itemPart,itemStyle:this.itemStyle,onclickitem:this.onclickitem}))} </div> `})}},$.ImgPages.styles=[st` div { width: fit-content; max-width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px; color: black; } `,Kt],_([y()],$.ImgPages.prototype,"alt",2),_([y()],$.ImgPages.prototype,"backdrop",2),_([y()],$.ImgPages.prototype,"items",2),_([y()],$.ImgPages.prototype,"pagenumbers",2),_([y()],$.ImgPages.prototype,"src",2),_([y()],$.ImgPages.prototype,"trim",2),_([y()],$.ImgPages.prototype,"itemPart",2),_([y()],$.ImgPages.prototype,"itemStyle",2),_([y()],$.ImgPages.prototype,"onclickitem",2),$.ImgPages=_([Mt("docling-img")],$.ImgPages),Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});