"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("i2djs"),f=require("vue"),p=["i-g","i-group","i-circle","i-line","i-path","i-ellipse","i-polygon","i-polyline","i-rect","i-text","i-image","i-page","i-linearGradient","i-radialGradient","i-page-template","i-animate","i-animatePath"];function q(r){const l={},s={},n={},{render:y}=f.createRenderer({patchProp(e,t,i,a,u,b,c,w,N){e&&d(t)(e,a)},insert:(e,t,i)=>{if(t=t||r,e&&t instanceof m.PDFCreator&&t.pages&&(["template","page"].includes(e.nodeName)||(t=t.pages.length?t.pages[0]:t.addPage())),!(!e||!(t!=null&&t.child))&&!(e instanceof m.canvasGradient))if(e.nodeName==="animate"||e.nodeName==="animatePath"){const a=e.nodeName==="animate"?"animateTo":"animatePathTo";e.parent=t,f.nextTick().then(()=>{t[a](e,e.from)})}else t.child([e])},remove:e=>{e!=null&&e.remove()},createElement:(e,t,i,a)=>{var N,T,A;const u=e.split("-").slice(1).join("-");let b=p.indexOf(e),c=null,w=r instanceof m.PDFCreator?"pdf":"canvas";if(b===-1&&console.warn(`Unknown PDF-Frame tag: ${e}`),(u==="animate"||u==="animatePath")&&w==="pdf")return null;switch(u){case"page-template":if(w!=="pdf")return console.warn("page-template element is invalid in canvas context"),null;c=r.createTemplate(),c.nodeName="template",s[a.id]=c;break;case"page":if(w!=="pdf")return console.warn("Page element is invalid in canvas context"),null;c=r.addPage(),c.nodeName="page";break;case"linearGradient":c=m.createLinearGradient(),n[a.id]=c,c.nodeName="linearGradient";break;case"radialGradient":c=m.createRadialGradient(),n[a.id]=c,c.nodeName="radialGradient";break;case"animate":c=x(a),a.from&&(c.from={attr:{...a.from,style:null},style:((N=a.from)==null?void 0:N.style)??{}});break;case"animatePath":c=O(a),a.from&&(c.from={attr:{d:((T=a==null?void 0:a.from)==null?void 0:T.d)??"",style:null},style:((A=a.from)==null?void 0:A.style)??{}});break;default:c=h(u,a);break}return c},createText:e=>{},createComment:e=>{},setText:(e,t)=>{},setElementText:(e,t)=>{},parentNode:e=>e&&e.dom.parent?e.dom.parent:null,nextSibling:e=>(t,i)=>{},querySelector:e=>r.fetchEl(e)||null}),S=e=>e.includes("-")?e.replace(/-([a-z])/g,(t,i)=>i.toUpperCase()):e,C=(e,t,i)=>{if(t)switch(e){case"src":l[i]?t.setAttr(e,l[i]):(l[i]=r.createAsyncTexture({attr:{src:i}}),l[i].then(a=>{l[i]=a.exportAsDataUrl(),t.setAttr(e,l[i])}));break;case"text":t.text(i);break;case"p-template":case"pTemplate":t instanceof m.canvasNodeExe&&t.addTemplate(s[i]);break;case"event":Object.entries(i).forEach(([a,u])=>{var b;return(b=t.on)==null?void 0:b.call(t,a,u)});break;case"block":t.block=!0;break;case"data":t.data(i);break;case"transform":t.setAttr(e,o(i));break;case"bbox":t.bbox=i;break;default:t.setAttr(e,i)}},k=(e,t)=>{Object.entries(t).forEach(([i,a])=>{let u=typeof a=="function"?a(e):a;if((i==="fillStyle"||i==="strokeStyle")&&typeof u=="string"&&u.startsWith("grad")){const b=u.match(/\(([^)]+)\)/)[1];u=g(b)}e.setStyle(i,u)})},d=e=>(e=S(e),(t,i)=>{if(/^on[A-Z]/.test(e)){const a=e.slice(2).toLowerCase();t.on&&t.on(a,i)}else typeof i=="function"&&(i=i(t));e!=="style"?C(e,t,i):k(t,i)});function h(e,t){return new m.canvasNodeExe(r.ctx,{el:e==="group"?"g":e,attr:{},style:{},bbox:t&&t.bbox!==void 0?t.bbox:!0},Math.round(Math.random()*1e7),0)}function o(e){if(typeof e=="object"&&!Array.isArray(e)&&e!==null)return e;const t={};for(const i in e=e.match(/(\w+\((\-?\d+\.?\d*e?\-?\d*,?)+\))+/g)){const a=e[i].match(/[\w\.\-]+/g);t[a.shift()]=a.map(u=>parseFloat(u))}return t}function g(e){return n[e]}function x(e){var t;return{nodeName:"animate",attr:{...(e==null?void 0:e.to)??{},style:null},style:((t=e==null?void 0:e.to)==null?void 0:t.style)??{},duration:e.duration||0,ease:e.ease||"default",loop:e.loop||0,end:e.end||null,delay:e.delay||0,direction:e.direction||"default",setAttr:function(i,a){},setStyle:function(i,a){},remove:function(){this.parent.interrupt()}}}function O(e){var t,i;return{nodeName:"animatePath",attr:{d:((t=e==null?void 0:e.to)==null?void 0:t.d)??"",style:null},style:((i=e==null?void 0:e.to)==null?void 0:i.style)??{},duration:e.duration||0,ease:e.ease||"default",loop:e.loop||0,end:e.end||null,delay:e.delay||0,direction:e.direction||"default",setAttr:function(a,u){},setStyle:function(a,u){},remove:function(){this.parent.interrupt()}}}return y}const j=f.defineComponent({props:{type:{type:String,required:!0,default:"pdf"},id:{type:String,required:!0,default:"pdf-frame-id"},height:{type:Number,required:!1,default:void 0},width:{type:Number,required:!1,default:void 0},layerSetting:{type:Object,required:!1,default:()=>{}},needOnUpdated:{type:Boolean,required:!1,default:!1},setCtxClear:{type:Function,required:!1,default:null},config:{type:Object,required:!1,default:()=>{}},info:{type:Object,required:!1,default:()=>{}},encryption:{type:Object,required:!1,default:()=>{}},autoPagination:{type:Boolean,required:!1,default:!0}},emits:["on-resize","on-ready","on-updated"],setup(r,l){let s,n=null;const y=f.getCurrentInstance();f.onMounted(()=>{f.nextTick().then(()=>{const d=l.slots.default;n||(r.type==="pdf"||r.type==="pdf-blob"?n=C(r):r.type==="canvas"?n=k(r):console.warn(`Unknown render context: ${r.type}`)),n!=null&&n.onResize&&n.onResize(()=>{l.emit("on-resize",{height:n.height,width:n.width})}),n!=null&&n.onChange&&n.onChange(g=>{var x;n instanceof m.PDFCreator&&((x=n==null?void 0:n.container)==null?void 0:x.tagName)==="IFRAME"&&n.container.setAttribute("src",g),r.needOnUpdated&&l.emit("on-updated",g)}),n!=null&&n.setClear&&typeof r.setCtxClear=="function"&&n.setClear(r.setCtxClear);const h=q(n),o=f.h(S,d);h(o,n),l.emit("on-ready",n)})}),f.onUnmounted(()=>{n&&(n.destroy(),n=null)}),f.watch([()=>r.height,()=>r.width],d=>{n.setSize&&n.setSize(r.width,r.height)},{deep:!0}),f.watch(()=>r.encryption,d=>{n.setConfig&&n.setConfig({encryption:d})},{deep:!0}),f.watch(()=>r.info,d=>{n.setConfig&&n.setConfig({info:d})},{deep:!0}),f.watch(()=>r.config,d=>{n.setConfig&&n.setConfig({...d})},{deep:!0});const S=f.defineComponent({setup(d,h){const o=f.getCurrentInstance();o.parent=y,o.appContext=y.appContext,o.root=y.root,o.provides=y.provides;const g=h.slots.default;return()=>f.h(f.Fragment,g())}});function C(d){let h=document.getElementById(s.props.id),o={...d.height!==void 0&&{height:d.height},...d.width!==void 0&&{width:d.width},...d.config||{},info:d.info||{},encryption:d.encryption||{}};return m.pdfLayer(h,o,{autoUpdate:!0,autoPagination:d.autoPagination})}function k(d){let h=document.getElementById(s.props.id);return m.canvasLayer(h,d.config,{...d.layerSetting})}switch(r.type){case"pdf":s=f.h("iframe",{id:r.id,class:"pdfIframe renderOutput",type:"application/pdf",src:null,style:{height:"100%",width:"100%"}});break;case"pdf-blob":s=f.h("div",{id:r.id,class:"renderOutput",style:{height:"100%",width:"100%"}});break;case"canvas":s=f.h("div",{id:r.id,class:"renderOutput",style:{height:r.height?r.height+"px":"100%",width:r.width?r.width+"px":"100%"}});break;case"default":s=f.h("iframe",{id:r.id,class:"pdfIframe renderOutput",type:"application/pdf",src:null,style:{height:"100%",width:"100%"}});break}return()=>s}});exports.default=j;