@8sheets/data-grid 1.1.1 → 1.1.2
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/README.md +1 -1
- package/api/serialize.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calcx/lang/convert.js +1 -1
- package/cells/book-css.js +7 -2
- package/cells/cf-engine.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/find.js +1 -1
- package/cells/goto.js +1 -1
- package/cells/link-model.js +1 -0
- package/cells/selection-modes.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -1
- package/core/edit-ranges.js +1 -0
- package/core/host-rules.js +1 -0
- package/core/protection.js +1 -1
- package/core/sheet.js +1 -1
- package/core/structure.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/persist.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/i18n/en/cells.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/io/client.js +1 -1
- package/io/csv.js +7 -7
- package/io/encoding.js +1 -0
- package/io/foreign-sheets.js +2 -2
- package/io/plan.js +1 -1
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/note-pages.js +2 -0
- package/print/paginate.js +1 -1
- package/print/pdf-links.js +1 -0
- package/print/pdf.js +11 -11
- package/print/render-page.js +3 -3
- package/table-view/files.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/icons.js +1 -1
- package/ui/protection-ui.js +1 -1
package/pivot/xml.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{pivotCfNode as $e,pivotChartFormatsNode as _e}from"../slicers/pivot-file.js";import{dateFilterNodes as qe,isDateFilterType as He,parseDateFilter as Ve}from"../slicers/date-filters.js";import{MAX_COLS as Ge,parseRangeRef as de,rangeRef as fe}from"../core/address.js";import{BUILTIN_FORMATS as Y,partsToSerial as Xe,serialToParts as je}from"../core/numfmt.js";import{BOOL as Ue,EMPTY as We,ERR as Ke,ERRORS as Ye,NUM as pe,STR as Je}from"../core/sheet.js";import{decodeRange as L,unescapeXml as Qe,unescapeXstring as he,XmlScanner as me}from"../io/xml-scan.js";import{escapeMarkup as J,xmlAttr as ge}from"../io/xml-escape.js";import{relsPathOf as Ze,resolveTarget as ze}from"../io/package-paths.js";import{ERR_BY_CODE as we,ERR_BY_INDEX as be,XlError as et}from"../calc/values.js";import{applyNumFmt as Q,itemKey as $,LINE as j,PivotCache as tt,PivotField as nt,PivotTable as st,storeColumn as at,VALUES as Z,compileCalc as ot,valueFieldName as rt}from"./engine.js";const U="http://schemas.openxmlformats.org/spreadsheetml/2006/main",V="http://schemas.openxmlformats.org/officeDocument/2006/relationships",z="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",it="{E15A36E0-9728-4e99-A89B-3F7291B0FE68}",lt="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}",ct="{2946ED86-A175-432a-8AC1-64E0C546D7DE}",ee={table:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",definition:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",records:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"},_={table:`${V}/pivotTable`,definition:`${V}/pivotCacheDefinition`,records:`${V}/pivotCacheRecords`},xe=1048828,ye=1048829,ve=4294967294,ut=new Set(["percentOfParent","percentOfParentRow","percentOfParentCol","percentOfRunningTotal","rankAscending","rankDescending"]),te={sum:"sumSubtotal",count:"countASubtotal",average:"avgSubtotal",max:"maxSubtotal",min:"minSubtotal",product:"productSubtotal",countNums:"countSubtotal",stdDev:"stdDevSubtotal",stdDevp:"stdDevPSubtotal",var:"varSubtotal",varp:"varPSubtotal"},Fe={sum:"sum",count:"countA",average:"avg",max:"max",min:"min",product:"product",countNums:"count",stdDev:"stdDev",stdDevp:"stdDevP",var:"var",varp:"varP"},m=(t,e={},s=[])=>({n:t,a:e,c:s,t:""}),b=(t,e)=>t?.c.find(s=>s.n===e)??null,A=(t,e)=>t?t.c.filter(s=>s.n===e):[],T=(t,e)=>t===void 0?e:t==="1"||t==="true";function Se(t,e,s){const a={};let n=e;for(;n<s;){for(;n<s&&t[n]<=32;)n++;if(n>=s)break;const l=n;for(;n<s&&t[n]!==61&&t[n]>32;)n++;const o=n;for(;n<s&&t[n]!==34&&t[n]!==39;)n++;if(n>=s)break;const c=t[n++],r=n,i=t.indexOf(c,n),d=i<0||i>s?s:i;a[L(t,l,o)]=he(L(t,r,d)),n=d+1}return a}function dt(t,e,s){let a=e;for(;a>0&&t[a-1]!==60;)a--;return L(t,a,s)}function ne(t,e=[]){e.push("<",t.n);for(const s of Object.keys(t.a)){const a=t.a[s];a!=null&&e.push(" ",s,'="',ge(a),'"')}if(t.c.length===0&&t.t==="")return e.push("/>"),e;e.push(">"),t.t&&e.push(J(t.t));for(const s of t.c)typeof s=="string"?e.push(s):ne(s,e);return e.push("</",t.n,">"),e}const ft=new Set(["s","n","d","b","e","m"]);function Te(t,e){switch(t){case"n":return Number(e.v);case"s":return e.v??"";case"d":return W(e.v);case"b":return e.v==="1"||e.v==="true";case"e":return we.get(e.v)??be[6];default:return null}}class Ie{constructor(){this.root=m("#root"),this.stack=[this.root],this.shared=null,this.sharedDepth=0,this.scanner=new me(this)}feed(e){this.scanner.feed(e)}finish(){return this.root.c[0]??null}open(e,s,a,n,l,o){const c=this.stack[this.stack.length-1];if(this.shared!==null&&c===this.shared){const f=L(e,s,a);if(ft.has(f)){const u=Se(e,n,l);c.items.push(Te(f,u)),o||this.sharedDepth++;return}}if(this.sharedDepth>0){o||this.sharedDepth++;return}const r=Se(e,n,l);let i=dt(e,s,a);const d=i.indexOf(":");if(d>=0){const f="xmlns:"+i.slice(0,d);let u=r[f];for(let h=this.stack.length-1;u===void 0&&h>0;h--)u=this.stack[h].a[f];u===U&&(i=i.slice(d+1))}const p=m(i,r);p.n==="sharedItems"&&(p.items=[],this.shared=p),c.c.push(p),o?p.n==="sharedItems"&&(this.shared=null):this.stack.push(p)}close(){if(this.sharedDepth>0){this.sharedDepth--;return}this.stack.pop()===this.shared&&(this.shared=null),this.stack.length===0&&this.stack.push(this.root)}text(e,s,a){if(this.sharedDepth>0)return;let n=!0;for(let l=s;l<a;l++)if(e[l]>32){n=!1;break}n||(this.stack[this.stack.length-1].t+=Qe(L(e,s,a)))}}function Ne(t){const e=new Ie;return e.feed(typeof t=="string"?new TextEncoder().encode(t):t),e.finish()}async function Ce(t,e){if(t instanceof Uint8Array)e.feed(t);else if(t.getReader){const s=t.getReader();for(;;){const{done:a,value:n}=await s.read();if(a)break;e.feed(n)}}else for await(const s of t)e.feed(s);return e.finish()}function W(t){const e=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(\.\d+)?)?/.exec(t??"");if(!e)return 0;const s=Xe(Number(e[1]),Number(e[2]),Number(e[3]));return e[4]===void 0?s:s+(Number(e[4])*3600+Number(e[5])*60+Number(e[6])+Number(e[7]??0))/86400}const q=(t,e=2)=>String(t).padStart(e,"0");function H(t){const e=je(t),s=Math.floor(e.ms/1e3);return`${q(e.year,4)}-${q(e.month)}-${q(e.day)}T${q(Math.floor(s/3600))}:${q(Math.floor(s/60)%60)}:${q(s%60)}`}class pt{constructor(e){this.positions=e.fields.filter(a=>a.a.databaseField===void 0||T(a.a.databaseField,!0));const s=e.c?Number(e.a.recordCount??1024):1024;this.capacity=Math.max(s,16),this.count=0,this.columns=this.positions.map(()=>({ids:null,kinds:null,nums:null})),this.pool=new Map,this.strings=[],this.at=-1,this.scanner=new me(this),this.inRecord=!1}feed(e){this.scanner.feed(e)}_grow(){this.capacity*=2;const e=(s,a)=>{if(a===null)return null;const n=new s(this.capacity);return n.set(a),n};for(const s of this.columns)s.ids=e(Int32Array,s.ids),s.kinds=e(Uint8Array,s.kinds),s.nums=e(Float64Array,s.nums)}open(e,s,a,n,l){if(a-s!==1)return;const o=e[s];if(o===114){this.count===this.capacity&&this._grow(),this.count++,this.at=0;return}if(this.at<0)return;const c=this.at++,r=this.columns[c];if(r===void 0)return;const i=this.count-1;if(o===120){r.ids===null&&(r.ids=new Int32Array(this.capacity));let u=0,h=Ee(e,n,l);if(h>=0)for(;h<l;h++){const g=e[h]-48;if(g<0||g>9)break;u=u*10+g}r.ids[i]=u;return}if(r.kinds===null&&(r.kinds=new Uint8Array(this.capacity),r.nums=new Float64Array(this.capacity)),o===109)return;const d=Ee(e,n,l);if(d<0)return;let p=d;const f=e[d-1];for(;p<l&&e[p]!==f;)p++;switch(o){case 110:r.kinds[i]=pe,r.nums[i]=Number(L(e,d,p));break;case 115:{const u=he(L(e,d,p));let h=this.pool.get(u);h===void 0&&(h=this.strings.length,this.strings.push(u),this.pool.set(u,h)),r.kinds[i]=Je,r.nums[i]=h;break}case 100:r.kinds[i]=pe,r.nums[i]=W(L(e,d,p)),r.dates=!0;break;case 98:r.kinds[i]=Ue,r.nums[i]=e[d]===49||e[d]===116?1:0;break;case 101:{const u=we.get(L(e,d,p));r.kinds[i]=Ke,r.nums[i]=u?u.index:6;break}default:}}close(e,s,a){a-s===1&&e[s]===114&&(this.at=-1)}text(){}finish(){return this}}function Ee(t,e,s){for(let a=e;a<s-2;a++)if(t[a]===118&&t[a+1]===61&&t[a-1]<=32)return a+3;return-1}async function ht(t){const e=await Ce(t,new Ie),s=b(e,"cacheFields");return{root:e,fields:s?A(s,"cacheField"):[],a:e.a,c:e.c}}async function mt(t,e){return Ce(t,new pt(e))}function Re(t){const e=b(t,"groupItems");return e?e.c.map(s=>Te(s.n,s.a)):[]}function gt(t,e){const s=Number(t.numFmtId??0);return Y[s]??e?.(s)??"General"}function wt(t,e,{numFmtOf:s}={}){const a=new tt,{fields:n}=t;a.xml={root:t.root},a.needsRefresh=e==null;const l=e?e.count:0;a.recordCount=l,e&&(a.strings.list=e.strings,a.strings.index=e.pool);let o=0;n.forEach((c,r)=>{const i=new nt(a,r,c.a.name??`Field${r+1}`);i.xml={node:c},Q(i,gt(c.a,s));const d=b(c,"sharedItems"),p=d?.items??[],f=c.a.databaseField===void 0||T(c.a.databaseField,!0);if(d&&T(d.a.containsDate,!1)&&i.numFmt==="General"&&Q(i,"m/d/yyyy"),c.a.formula!==void 0)i.formula=c.a.formula;else if(f&&e){const u=e.columns[o];u?.ids?(i.rawIds=u.ids.subarray(0,l),i.shared=p.slice()):u?.kinds&&(at(i,u.kinds.subarray(0,l),u.nums.subarray(0,l),l),u.dates&&i.numFmt==="General"&&Q(i,"m/d/yyyy"))}else f&&(i.shared=p.slice(),i.rawIds=new Int32Array(0));f&&o++,a.fields.push(i)}),n.forEach((c,r)=>{const i=b(c,"fieldGroup");if(!i)return;const d=a.fields[r],p=i.a.base!==void 0?Number(i.a.base):r;i.a.par!==void 0&&(d.par=Number(i.a.par)),p!==r&&(d.base=p);const f=b(i,"rangePr"),u=b(i,"discretePr"),h=Re(i);if(f){const g=f.a.groupBy??"range",w=T(f.a.autoStart,!0),x=T(f.a.autoEnd,!0);if(g==="range"){const v=Number(f.a.startNum??0),y=Number(f.a.endNum??0),F=Number(f.a.groupInterval??1),S=h.length>1&&/^-?\d+--?\d+$/.test(String(h[1]))&&Number.isInteger(v)&&Number.isInteger(F)&&Number(String(h[1]).match(/^-?\d+-(-?\d+)$/)?.[1])===v+F-1;d.group={kind:"bins",start:v,end:y,interval:F,integer:S,autoStart:w,autoEnd:x,labels:h}}else d.group={kind:"date",part:g,start:Math.floor(W(f.a.startDate)),end:Math.floor(W(f.a.endDate))-1,autoStart:w,autoEnd:x,labels:h}}else if(u&&p!==r){const g=a.fields[p],w=A(u,"x").map(F=>Number(F.a.v??0)),x=h.map(()=>[]),v=b(n[p],"sharedItems")?.items??g.shared??[];w.forEach((F,S)=>{x[F]&&x[F].push($(v[S]??null))});const y=[];h.forEach((F,S)=>{x[S].length===1&&x[S][0]===$(F)||y.push({name:String(F),keys:x[S]})}),d.group={kind:"discrete",groups:y}}});for(const c of a.fields)if(c.formula!==null)try{c.calc=ot(c.formula,a)}catch{c.calc={fn:()=>{throw be[4]},refs:[]}}return a}function se(t,e){const s=t.fields[e].xml?.node,a=s?b(s,"fieldGroup"):null,n=a?Re(a):[];return n.length>0?n:(s?b(s,"sharedItems"):null)?.items??[]}function bt(t){const e=t.a.type??"",s=b(b(t,"autoFilter"),"filterColumn");if(e==="count"||e==="percent"||e==="sum"){const a=b(s,"top10");return a?{top:{count:Number(a.a.val??10),by:e==="count"?"items":e,bottom:a.a.top==="0"||a.a.top==="false",data:Number(t.a.iMeasureFld??0)}}:null}if(He(e))return{dateFilter:Ve(t)};if(e.startsWith("caption"))return{labelFilter:{op:e,value:t.a.stringValue1??"",value2:t.a.stringValue2??""}};if(e.startsWith("value")){const a=A(b(s,"customFilters"),"customFilter");return a.length===0?null:{valueFilter:{op:e,data:Number(t.a.iMeasureFld??0),value:Number(a[0].a.val),value2:a[1]?Number(a[1].a.val):void 0}}}return null}function xt(t){for(const e of A(b(t,"extLst"),"ext")){const s=b(e,"x14:pivotTableDefinition");if(s)return s}return null}function yt(t,e){const s=t?b(t,"extLst"):null,a=[];let n=!1;for(const l of s?.c??[]){const o=b(l,"x14:pivotTableDefinition");if(!o){a.push(l);continue}n=!0;const c={...o.a};delete c.hideValuesRow,e&&(c.hideValuesRow="1"),a.push(m("ext",l.a,l.c.map(r=>r===o?m(o.n,c,o.c):r)))}return!n&&e&&a.push(m("ext",{uri:lt,"xmlns:x14":z},[m("x14:pivotTableDefinition",{hideValuesRow:"1"})])),a.length>0?m("extLst",{},a):null}function vt(t,e,{numFmtOf:s,sheet:a}={}){const n={name:t.a.name??"PivotTable1",fieldOptions:{},rows:A(b(t,"rowFields"),"field").map(u=>Number(u.a.x)),cols:A(b(t,"colFields"),"field").map(u=>Number(u.a.x)),filters:[],values:[],grandRow:T(t.a.colGrandTotals,!0),grandCol:T(t.a.rowGrandTotals,!0),rowCaption:t.a.rowHeaderCaption??null,colCaption:t.a.colHeaderCaption??null,dataCaption:t.a.dataCaption??"Values",grandCaption:t.a.grandTotalCaption??null,emptyText:T(t.a.showMissing,!0)?t.a.missingCaption??"":"",showMissing:T(t.a.showMissing,!0),errorText:T(t.a.showError,!1)?t.a.errorCaption??"":null,showExpandButtons:T(t.a.showDrill,!0),showFieldHeaders:T(t.a.showHeaders,!0),hideValuesRow:T(xt(t)?.a.hideValuesRow,!1)},l=A(b(t,"pivotFields"),"pivotField"),o={root:t,fields:l,itemAttrs:[],pageFields:new Map,rawFilters:[]},c=[];l.forEach((u,h)=>{const g={},w=se(e,h),x=A(b(u,"items"),"item"),v=[],y=[],F=[],S={},C=new Map;for(const N of x){if(N.a.t!==void 0&&N.a.t!=="data")continue;const R=Number(N.a.x??0),k=$(w[R]??null);F.push(k),C.set(k,N.a),T(N.a.h,!1)&&v.push(k),N.a.sd!==void 0&&!T(N.a.sd,!0)&&y.push(k),N.a.n!==void 0&&(S[k]=N.a.n)}o.itemAttrs[h]=C,v.length&&(g.hidden=v),y.length&&(g.collapsedItems=y),Object.keys(S).length&&(g.itemCaptions=S),u.a.name!==void 0&&(g.caption=u.a.name);const D=u.a.sortType??"manual";if(D==="ascending"||D==="descending"){g.sort={order:D==="ascending"?"asc":"desc"};const N=b(b(u,"autoSortScope"),"pivotArea"),R=b(b(N,"references"),"reference");R&&Number(R.a.field)===ve&&(g.sort.data=Number(b(R,"x")?.a.v??0))}else F.length>0&&u.a.axis&&(g.sort={order:"manual",keys:F});const B=Object.entries(te).filter(([,N])=>T(u.a[N],!1)).map(([N])=>N);B.length>0?g.subtotals=B:T(u.a.defaultSubtotal,!0)||(g.subtotals="none"),u.a.subtotalTop!==void 0&&(g.subtotalTop=T(u.a.subtotalTop,!0)),T(u.a.insertBlankRow,!1)&&(g.blankLine=!0),u.a.axis&&T(u.a.showAll,!0)&&(g.showAll=!0),T(u.a.insertPageBreak,!1)&&(g.pageBreak=!0);for(const N of A(b(u,"extLst"),"ext"))T(b(N,"x14:pivotField")?.a.fillDownLabels,!1)&&(g.repeatLabels=!0);if(u.a.axis==="axisRow"||u.a.axis==="axisCol"){const N=T(u.a.compact,!0)?"compact":T(u.a.outline,!0)?"outline":"tabular";c.push([h,N])}Object.keys(g).length>0&&(n.fieldOptions[h]=g)});const r=new Map;for(const[,u]of c)r.set(u,(r.get(u)??0)+1);n.layout=[...r.entries()].sort((u,h)=>h[1]-u[1])[0]?.[0]??"compact";for(const[u,h]of c)h!==n.layout&&(n.fieldOptions[u]??={},n.fieldOptions[u].layout=h);for(const u of A(b(t,"pageFields"),"pageField")){const h=Number(u.a.fld);if(n.filters.push(h),o.pageFields.set(h,u.a),u.a.item!==void 0){const g=A(b(l[h],"items"),"item"),w=g[Number(u.a.item)],x=se(e,h);if(w){const v=$(x[Number(w.a.x??0)]??null),y=[];for(const F of g){if(F.a.t!==void 0&&F.a.t!=="data")continue;const S=$(x[Number(F.a.x??0)]??null);S!==v&&y.push(S)}n.fieldOptions[h]??={},n.fieldOptions[h].hidden=y}}}for(const u of A(b(t,"dataFields"),"dataField")){const h=Number(u.a.fld),g={field:h,name:u.a.name??rt(u.a.subtotal??"sum",e.fields[h].name),agg:u.a.subtotal??"sum",xml:u};let w=u.a.showDataAs??"normal";const x=b(b(u,"extLst"),"ext"),v=x?b(x,"x14:dataField"):null;if(v?.a.pivotShowAs&&(w=v.a.pivotShowAs),w!=="normal"&&(g.showAs={type:w},u.a.baseField!==void 0&&(g.showAs.baseField=Number(u.a.baseField)),u.a.baseItem!==void 0)){const y=Number(u.a.baseItem);if(y===xe)g.showAs.baseItem="prev";else if(y===ye)g.showAs.baseItem="next";else{const F=g.showAs.baseField,S=A(b(l[F],"items"),"item"),C=se(e,F),D=S[y];g.showAs.baseItem=D?$(C[Number(D.a.x??0)]??null):"prev"}}if(u.a.numFmtId!==void 0){const y=Number(u.a.numFmtId),F=Y[y]??s?.(y);F&&(g.numFmt=F)}n.values.push(g)}for(const u of A(b(t,"filters"),"filter")){const h=bt(u),g=Number(u.a.fld);if(h===null){o.rawFilters.push(u);continue}n.fieldOptions[g]??={},Object.assign(n.fieldOptions[g],h)}T(t.a.mergeItem,!1)&&(n.mergeLabels=!0);const i=b(t,"pivotTableStyleInfo");i&&(n.style={name:i.a.name??"PivotStyleLight16",rowHeaders:T(i.a.showRowHeaders,!0),colHeaders:T(i.a.showColHeaders,!0),rowStripes:T(i.a.showRowStripes,!1),colStripes:T(i.a.showColStripes,!1),lastColumn:T(i.a.showLastColumn,!0)});const d=new st(e,n);d.xml=o,d.dirty=!1;const p=b(t,"location"),f=p?de(p.a.ref??""):null;if(f){const u=n.filters.length>0?n.filters.length+1:0;d.anchor={sheet:a??null,row:Math.max(0,f.r0-u),col:f.c0},d.renderedRange={r0:d.anchor.row,c0:f.c0,r1:f.r1,c1:f.c1}}return d}async function ae(t,e){const s=Ze(e);if(!t.has(s))return[];const a=Ne(await t.bytes(s));return A(a,"Relationship").map(n=>({id:n.a.Id,type:n.a.Type,target:ze(e,n.a.Target??"")}))}async function zt(t,{sheets:e,book:s,tables:a=[],numFmtOf:n,readRecords:l=!0}){const o=new Map,c=[];for(const{part:r,sheet:i}of e)if(r)for(const d of await ae(t,r)){if(d.type!==_.table||!t.has(d.target))continue;const p=Ne(await t.bytes(d.target)),u=(await ae(t,d.target)).find(w=>w.type===_.definition);if(!u||!t.has(u.target))continue;let h=o.get(u.target);if(h===void 0){const w=await ht(await t.stream(u.target)),v=(await ae(t,u.target)).find(F=>F.type===_.records);let y=null;l&&v&&t.has(v.target)&&(y=await mt(await t.stream(v.target),w)),h=wt(w,y,{numFmtOf:n}),h.refreshOnLoad=["1","true"].includes(w.a.refreshOnLoad),h.part=u.target,h.id=p.a.cacheId!==void 0?Number(p.a.cacheId):0,Ft(h,w,s,a),o.set(u.target,h)}const g=vt(p,h,{numFmtOf:n,sheet:i});g.part=d.target,c.push(g)}return{caches:[...o.values()],pivots:c}}function Ft(t,e,s,a){if(!s)return;const n=b(b(e.root,"cacheSource"),"worksheetSource");if(!n)return;if(n.a.name!==void 0){const c=a.find(r=>r.name?.toLowerCase()===n.a.name.toLowerCase());c&&(t.source={type:"table",book:s,table:c});return}const l=de(n.a.ref??""),o=s.sheets.find(c=>c.name===n.a.sheet);l&&o&&(t.source={type:"range",book:s,sheet:o,range:l})}const K=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
-
`,oe=new TextEncoder;function ke(t){for(const[e,s]of Object.entries(Y))if(s===t)return Number(e);return null}function re(t,e){if(t==null)return"<m/>";switch(typeof t){case"number":return e?`<d v="${H(t)}"/>`:`<n v="${t}"/>`;case"string":return`<s v="${ge(t)}"/>`;case"boolean":return`<b v="${t?1:0}"/>`;default:return`<e v="${J(t.code)}"/>`}}function Ae(t,e){const{hasNum:s,hasInt:a,hasText:n,hasBlank:l,hasOther:o,min:c,max:r,longText:i}=e,d=t.isDate&&s&&!n&&!o,p={};return!n&&!l&&!o&&(p.containsSemiMixedTypes="0"),d&&!l&&(p.containsNonDate="0"),d&&(p.containsDate="1"),n||(p.containsString="0"),l&&(p.containsBlank="1"),(s?1:0)+(n?1:0)+(o?1:0)>1&&(p.containsMixedTypes="1"),s&&!d&&(p.containsNumber="1",a&&(p.containsInteger="1"),p.minValue=String(c),p.maxValue=String(r)),d&&(p.minDate=H(c),p.maxDate=H(Math.floor(r)+1)),i&&(p.longText="1"),{attrs:p,date:d}}function St(t){const e={hasNum:!1,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(const s of t)typeof s=="number"?(e.hasNum=!0,Number.isInteger(s)||(e.hasInt=!1),s<e.min&&(e.min=s),s>e.max&&(e.max=s)):typeof s=="string"?(e.hasText=!0,s.length>255&&(e.longText=!0)):s==null?e.hasBlank=!0:e.hasOther=!0;return e}function Tt(t){const e={hasNum:t.length>0,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(let s=0;s<t.length;s++){const a=t[s];a<e.min&&(e.min=a),a>e.max&&(e.max=a),e.hasInt&&Math.floor(a)!==a&&(e.hasInt=!1)}return e}function De(t){return t.ensureColumn(),t.rawIds!==null?!0:!(t.nums!==null&&t.kinds===null)}function It(t,e){const s=e.group;if(s===null)return e.par>=0?m("fieldGroup",{par:String(e.par)}):null;e.ensure();const a={};e.par>=0&&(a.par=String(e.par)),a.base=String(e.base>=0?e.base:e.index);const n=[],l=e.items.map(c=>re(c,!1)).join("");if(s.kind==="date"){const c={groupBy:s.part,startDate:H(s.start),endDate:H(s.end+1)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else if(s.kind==="bins"){const c={startNum:String(s.start),endNum:String(s.end),groupInterval:String(s.interval)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else{const c=e.groupMap,r=m("discretePr",{count:String(c.length)});for(let i=0;i<c.length;i++)r.c.push(m("x",{v:String(c[i])}));n.push(r)}const o=m("groupItems",{count:String(e.items.length)});return o.c.push(l),n.push(o),m("fieldGroup",a,n)}function Nt(t,e,s){const a=e.xml?.node??null,n={...a?.a??{}};if(n.name=e.name,n.numFmtId===void 0){const c=e.numFmt!=="General"?ke(e.numFmt)??s.numFmtId?.(e.numFmt)??(e.isDate?14:0):0;n.numFmtId=String(c)}const l=[];if(e.isCalculated)n.formula=e.formula,n.databaseField="0",delete n.uniqueList;else if(e.base>=0)n.databaseField="0";else if(t.recordCount===0&&a&&b(a,"sharedItems")){const c=b(a,"sharedItems"),r=m("sharedItems",{...c.a}),i=T(c.a.containsDate,!1);c.items.length>0&&r.c.push(c.items.map(d=>re(d,i&&typeof d=="number")).join("")),l.push(r)}else if(De(e)){e.ensureRaw();const{attrs:c,date:r}=Ae(e,St(e.shared)),i=m("sharedItems",{...c,count:String(e.shared.length)});i.c.push(e.shared.map(d=>re(d,r&&typeof d=="number")).join("")),l.push(i)}else{const{attrs:c}=Ae(e,Tt(e.nums));l.push(m("sharedItems",c))}const o=It(t,e);if(o&&l.push(o),a)for(const c of a.c)c.n!=="sharedItems"&&c.n!=="fieldGroup"&&l.push(c);return m("cacheField",n,l)}function Ct(t,{recordsRel:e=null,numFmtId:s,refreshOnLoad:a=!0,sourceSheetName:n}={}){const l=t.xml?.root??null,o={...l?.a??{}};o.xmlns??=U,o["xmlns:r"]??=V,e?o["r:id"]=e:delete o["r:id"],a&&(o.refreshOnLoad="1"),o.refreshedBy??="8sheets",o.refreshedDate=String(Et()),o.createdVersion??="6",o.refreshedVersion??="6",o.minRefreshableVersion??="3",o.recordCount=String(t.recordCount),e?delete o.saveData:o.saveData="0";const c=[],r=l?b(l,"cacheSource"):null;c.push(Rt(t,r,n));const i=m("cacheFields",{count:"0"}),d=t.fields;for(const p of d)i.c.push(Nt(t,p,{numFmtId:s}));if(i.a.count=String(d.length),c.push(i),l)for(const p of l.c)p.n!=="cacheSource"&&p.n!=="cacheFields"&&c.push(p);return K+ne(m("pivotCacheDefinition",o,c)).join("")}function Et(){return Math.round((Date.now()/864e5+25569)*1e5)/1e5}function Rt(t,e,s){const a=t.source;if(a===null)return e??m("cacheSource",{type:"worksheet"},[m("worksheetSource",{ref:"A1",sheet:"Sheet1"})]);const n={};if(a.type==="table")n.name=a.table.name;else{const i=a.range,d=s??(typeof a.sheet=="string"?a.sheet:a.sheet.name);n.ref=fe({r0:i.r0,c0:i.c0,r1:i.r1,c1:Math.min(i.c1,Ge-1)}),n.sheet=d}const l=e?{...e.a}:{type:"worksheet"},o=e?e.c.filter(i=>i.n!=="worksheetSource"):[],c=e?b(e,"worksheetSource"):null,r=c?{...c.a,...n}:n;return a.type==="table"&&(delete r.ref,delete r.sheet),m("cacheSource",l,[m("worksheetSource",r),...o])}const kt=4096;async function Oe(t,e){const s=t.recordCount,a=[];for(const l of t.fields)l.isVirtual||(De(l)?(l.ensureRaw(),a.push(At(l.rawIds))):a.push(Dt(l.nums,l.isDate)));await e(oe.encode(`${K}<pivotCacheRecords xmlns="${U}" xmlns:r="${V}" count="${s}">`));const n=[];for(let l=0;l<s;l++){n.push("<r>");for(let o=0;o<a.length;o++)n.push(a[o](l));n.push("</r>"),(l+1)%kt===0&&(await e(oe.encode(n.join(""))),n.length=0)}n.push("</pivotCacheRecords>"),await e(oe.encode(n.join("")))}function At(t){return e=>`<x v="${t[e]}"/>`}function Dt(t,e){return e?s=>`<d v="${H(t[s])}"/>`:s=>`<n v="${t[s]}"/>`}async function en(t){const e="application/xml";let s=new Blob([],{type:e}),a=[],n=0;return await Oe(t,l=>{a.push(l),n+=l.length,n>=1<<24&&(s=new Blob([s,...a],{type:e}),a=[],n=0)}),new Blob([s,...a],{type:e})}const Le=["location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","formats","conditionalFormats","chartFormats","pivotHierarchies","pivotTableStyleInfo","filters","rowHierarchiesUsage","colHierarchiesUsage","extLst"];function Ot(t,e){const s=t.cache.fields[e].ensure(),a=s.rank(),n=Array.from(s.items.keys()),o=t.spec.fieldOptions[e]?.sort;if(o?.order==="manual"){const r=new Map((o.keys??[]).map((p,f)=>[p,f])),i=r.size,d=p=>r.get($(s.items[p]))??i+a[p];n.sort((p,f)=>d(p)-d(f))}else o?.order==="desc"&&(o.data===void 0||o.data===null)?n.sort((r,i)=>a[i]-a[r]):n.sort((r,i)=>a[r]-a[i]);const c=new Int32Array(n.length);return n.forEach((r,i)=>{c[r]=i}),{order:n,position:c}}function Lt(t){return t.group!==null||t.base>=0}function Pt(t,e){return t.spec.fieldOptions[e]?.layout??t.spec.layout}const Bt=["axis","dataField","compact","outline","subtotalTop","sortType","defaultSubtotal","insertBlankRow","name","showDropDowns","dragToRow","dragToCol","dragToPage",...Object.values(te)];function Mt(t,e,s){const{spec:a,cache:n}=t,l=n.fields[e],o=a.fieldOptions[e]??{},c=t.xml?.fields?.[e]??null,r={...c?.a??{}};for(const S of Bt)delete r[S];o.caption!==void 0&&(r.name=o.caption);const i=a.rows.includes(e),d=a.cols.includes(e),p=a.filters.includes(e),f=a.values.some(S=>S.field===e);i?r.axis="axisRow":d?r.axis="axisCol":p&&(r.axis="axisPage"),f&&(r.dataField="1");const u=Pt(t,e);u!=="compact"&&(r.compact="0"),u==="tabular"&&(r.outline="0"),l.isCalculated&&(r.dragToRow="0",r.dragToCol="0",r.dragToPage="0"),r.showAll=o.showAll?"1":"0",o.pageBreak?r.insertPageBreak="1":delete r.insertPageBreak,(o.subtotalTop??a.subtotalTop)===!1&&(i||d)&&(r.subtotalTop="0"),o.blankLine&&(r.insertBlankRow="1"),o.sort?.order==="asc"?r.sortType="ascending":o.sort?.order==="desc"&&(r.sortType="descending");const h=o.subtotals??"auto",g=i||d||p,w=(o.hidden?.length??0)>0,x=g||Lt(l)||w||!!(o.range||o.dateFilter);if((l.isCalculated||h==="none"||Array.isArray(h)||l.base>=0&&!g)&&(r.defaultSubtotal="0"),Array.isArray(h))for(const S of h)r[te[S]]="1";const v=[];if(x&&!l.isCalculated){const{order:S}=s(e),C=m("items",{}),D=new Set(o.hidden??[]),B=new Set(o.collapsedItems??[]),N=t.xml?.itemAttrs?.[e]??null,R=o.itemCaptions??null;for(const k of S){const P=l.keyOf(k),O={...N?.get(P)??{}};delete O.h,delete O.sd,delete O.n,O.x=String(k),D.has(P)&&(O.h="1"),B.has(P)&&(O.sd="0"),R&&R[P]!==void 0&&(O.n=R[P]),C.c.push(m("item",O))}if((g||w||o.range||o.dateFilter)&&r.defaultSubtotal===void 0&&C.c.push(m("item",{t:"default"})),Array.isArray(h))for(const k of h)C.c.push(m("item",{t:Fe[k]}));C.a.count=String(C.c.length),v.push(C)}if(o.sort?.data!==void 0&&o.sort?.data!==null&&(o.sort.order==="asc"||o.sort.order==="desc")&&v.push(m("autoSortScope",{},[m("pivotArea",{dataOnly:"0",outline:"0",fieldPosition:"0"},[m("references",{count:"1"},[m("reference",{field:String(ve),count:"1",selected:"0"},[m("x",{v:String(o.sort.data)})])])])])),c)for(const S of c.c)S.n!=="items"&&S.n!=="autoSortScope"&&S.n!=="extLst"&&v.push(S);const y=o.repeatLabels===!0||a.repeatLabels===!0&&i&&u!=="compact",F=$t(c,y);return F&&v.push(F),m("pivotField",r,v)}function $t(t,e){const s=[];let a=!1;for(const n of A(t?b(t,"extLst"):null,"ext")){const l=b(n,"x14:pivotField");if(!l){s.push(n);continue}a=!0;const o={...l.a};delete o.fillDownLabels,e&&(o.fillDownLabels="1"),s.push(m("ext",n.a,n.c.map(c=>c===l?m(l.n,o,l.c):c)))}return!a&&e&&s.push(m("ext",{uri:ct,"xmlns:x14":z},[m("x14:pivotField",{fillDownLabels:"1"})])),s.length>0?m("extLst",{},s):null}function Pe(t,e,s,a){const n=s.lines,l=m(t,{}),{slots:o}=s;let c=[];for(let r=0;r<n.node.length;r++){const i=n.type[r],d=n.level[r],p={},f=[];if(o.length===0){l.c.push(m("i",{}));continue}if(i===j.GRAND){p.t="grand";const w=n.data[r];w>0&&(p.i=String(w));const x=m("i",p,[m("x",w>0?{v:String(w)}:{})]);l.c.push(x),c=[];continue}i===j.BLANK?p.t="blank":i===j.SUBTOTAL&&(p.t=n.func[r]?Fe[n.func[r]]:"default");let u=0;for(let w=0;w<=d;w++)if(o[w]===Z)f.push(n.data[r]>=0?n.data[r]:0);else{u++;const x=s.ancestorAt(n.node[r],u);f.push(a(o[w]).position[s.item[x]])}n.data[r]>0&&(p.i=String(n.data[r]));let h=0;if(i===j.ITEM)for(;h<f.length-1&&h<c.length&&c[h]===f[h];)h++;h>0&&(p.r=String(h));const g=m("i",p);for(let w=h;w<f.length;w++)g.c.push(m("x",f[w]===0?{}:{v:String(f[w])}));l.c.push(g),c=f}return l.c.length===0&&l.c.push(m("i",{})),l.a.count=String(l.c.length),l}function _t(t,e){const{spec:s}=t,a=[];let n=1;const l=(c,r,i,d)=>m("filter",{fld:String(c),type:r,evalOrder:"-1",id:String(n++),...i},[m("autoFilter",{ref:"A1"},[m("filterColumn",{colId:"0"},[d])])]),o=(c,r)=>m("customFilters",r?{and:"1"}:{},c.map(i=>m("customFilter",i)));for(const c of e){const r=s.fieldOptions[c];if(r){if(r.labelFilter){const i=r.labelFilter,d=String(i.value??""),p=String(i.value2??""),f={stringValue1:d};(i.op==="captionBetween"||i.op==="captionNotBetween")&&(f.stringValue2=p);const u={captionEqual:()=>o([{val:d}]),captionNotEqual:()=>o([{operator:"notEqual",val:d}]),captionBeginsWith:()=>o([{val:`${d}*`}]),captionNotBeginsWith:()=>o([{operator:"notEqual",val:`${d}*`}]),captionEndsWith:()=>o([{val:`*${d}`}]),captionNotEndsWith:()=>o([{operator:"notEqual",val:`*${d}`}]),captionContains:()=>o([{val:`*${d}*`}]),captionNotContains:()=>o([{operator:"notEqual",val:`*${d}*`}]),captionGreaterThan:()=>o([{operator:"greaterThan",val:d}]),captionGreaterThanOrEqual:()=>o([{operator:"greaterThanOrEqual",val:d}]),captionLessThan:()=>o([{operator:"lessThan",val:d}]),captionLessThanOrEqual:()=>o([{operator:"lessThanOrEqual",val:d}]),captionBetween:()=>o([{operator:"greaterThanOrEqual",val:d},{operator:"lessThanOrEqual",val:p}],!0),captionNotBetween:()=>o([{operator:"lessThan",val:d},{operator:"greaterThan",val:p}])}[i.op];u&&a.push(l(c,i.op,f,u()))}if(r.valueFilter){const i=r.valueFilter,d=String(i.value),p=String(i.value2??""),f={valueEqual:[[{val:d}]],valueNotEqual:[[{operator:"notEqual",val:d}]],valueGreaterThan:[[{operator:"greaterThan",val:d}]],valueGreaterThanOrEqual:[[{operator:"greaterThanOrEqual",val:d}]],valueLessThan:[[{operator:"lessThan",val:d}]],valueLessThanOrEqual:[[{operator:"lessThanOrEqual",val:d}]],valueBetween:[[{operator:"greaterThanOrEqual",val:d},{operator:"lessThanOrEqual",val:p}],!0],valueNotBetween:[[{operator:"lessThan",val:d},{operator:"greaterThan",val:p}]]}[i.op];f&&a.push(l(c,i.op,{iMeasureFld:String(i.data??0)},o(f[0],f[1]===!0)))}if(a.push(...qe(r,c,m,()=>n++)),r.top){const i=r.top,d={val:String(i.count??10),filterVal:String(i.count??10)};i.by==="percent"&&(d.percent="1"),i.bottom&&(d.top="0");const p=i.by==="percent"?"percent":i.by==="sum"?"sum":"count";a.push(l(c,p,{iMeasureFld:String(i.data??0)},m("top10",d)))}}}return a}function qt(t,e,s,a){const n=e.xml??null,l={...n?.a??{}};l.name=e.name,l.fld=String(e.field),e.agg&&e.agg!=="sum"?l.subtotal=e.agg:delete l.subtotal,delete l.showDataAs;const o=e.showAs?.type??"normal",c=n?n.c.filter(g=>g.n!=="extLst"):[];let r=null;ut.has(o)?r=o:o!=="normal"&&(l.showDataAs=o);const i=e.showAs?.baseField??0;l.baseField=String(i>=0?i:0);let d=0;const p=e.showAs?.baseItem;if(p==="prev")d=xe;else if(p==="next")d=ye;else if(p!==void 0&&e.showAs?.baseField>=0){const g=t.cache.fields[e.showAs.baseField].ensure(),w=g.keyIndex.get(p);w!==void 0&&(d=s(g.index).position[w])}l.baseItem=String(d);const f=e.numFmt??(o!=="normal"&&!o.startsWith("rank")&&o!=="difference"&&o!=="runTotal"?o==="index"?"0.00":"0.00%":null);if(f){const g=ke(f)??a.numFmtId?.(f);g!=null&&(l.numFmtId=String(g))}else delete l.numFmtId;const u=[],h=n?b(n,"extLst"):null;if(h)for(const g of h.c)if(b(g,"x14:dataField")){const w={...b(g,"x14:dataField").a};delete w.pivotShowAs,r&&(w.pivotShowAs=r),u.push(m("ext",g.a,[m("x14:dataField",w)])),r=null}else u.push(g);return r&&u.push(m("ext",{uri:it,"xmlns:x14":z},[m("x14:dataField",{pivotShowAs:r})])),u.length&&c.push(m("extLst",{},u)),m("dataField",l,c)}function Ht(t,{cacheId:e,numFmtId:s}={}){const a=t.result??t.update(),{spec:n,cache:l}=t,{layout:o,rows:c,cols:r}=a,i=new Map,d=I=>{let E=i.get(I);return E===void 0&&(E=Ot(t,I),i.set(I,E)),E},p=t.xml?.root??null,f={...p?.a??{}};f.xmlns??=U,f.name=n.name,f.cacheId=String(e??l.id??1),f.applyNumberFormats??="0",f.applyBorderFormats??="0",f.applyFontFormats??="0",f.applyPatternFormats??="0",f.applyAlignmentFormats??="0",f.applyWidthHeightFormats??="1",f.dataCaption=n.dataCaption,f.updatedVersion??="6",f.minRefreshableVersion??="3",f.useAutoFormatting??="1",f.itemPrintTitles??="1",f.createdVersion??="6",f.indent??="0",n.mergeLabels?f.mergeItem="1":delete f.mergeItem,t.fileAttrs&&Object.assign(f,t.fileAttrs);const u=(I,E,G)=>{E===G?delete f[I]:f[I]=E?"1":"0"};u("compact",n.layout==="compact",!0),u("compactData",n.layout==="compact",!0),f.outline=n.layout==="tabular"?f.outline??"1":"1",f.outlineData=n.layout==="tabular"?f.outlineData??"1":"1",u("colGrandTotals",n.grandRow,!0),u("rowGrandTotals",n.grandCol,!0),n.rowCaption!=null?f.rowHeaderCaption=n.rowCaption:delete f.rowHeaderCaption,n.colCaption!=null?f.colHeaderCaption=n.colCaption:delete f.colHeaderCaption,n.grandCaption!=null?f.grandTotalCaption=n.grandCaption:delete f.grandTotalCaption,n.emptyText!==""&&n.showMissing!==!1?f.missingCaption=n.emptyText:delete f.missingCaption,n.showMissing===!1?f.showMissing="0":delete f.showMissing,n.errorText!==null?(f.showError="1",f.errorCaption=n.errorText):(delete f.showError,delete f.errorCaption),c.slots.includes(Z)?(f.dataOnRows="1",f.dataPosition=String(c.slots.indexOf(Z))):(delete f.dataOnRows,delete f.dataPosition);const h=Object.keys(n.fieldOptions).map(Number),g=h.some(I=>{const E=n.fieldOptions[I];return(E.labelFilter?1:0)+(E.valueFilter?1:0)+(E.top?1:0)>1});f.multipleFieldFilters=g?"1":"0";const w=t.anchor??{row:0,col:0},x=w.row+o.pageRows,v={ref:fe({r0:x,c0:w.col,r1:w.row+o.rows-1,c1:w.col+Math.max(o.bodyCols,1)-1}),firstHeaderRow:String(o.firstHeaderRow),firstDataRow:String(o.firstDataRow),firstDataCol:String(o.firstDataCol)};n.filters.length>0&&(v.rowPageCount=String(n.filters.length),v.colPageCount="1");const y=new Map;y.set("location",m("location",v));const F=m("pivotFields",{count:String(l.fields.length)});for(let I=0;I<l.fields.length;I++)F.c.push(Mt(t,I,d));y.set("pivotFields",F);const S=(I,E)=>m(I,{count:String(E.length)},E.map(G=>m("field",{x:String(G)})));if(c.slots.length>0&&y.set("rowFields",S("rowFields",c.slots)),y.set("rowItems",Pe("rowItems",a,c,d)),r.slots.length>0&&y.set("colFields",S("colFields",r.slots)),y.set("colItems",Pe("colItems",a,r,d)),n.filters.length>0){const I=m("pageFields",{count:String(n.filters.length)});for(const E of n.filters){const X={...t.xml?.pageFields?.get(E)??{},fld:String(E)};delete X.item,X.hier??="-1";const le=l.fields[E].ensure(),ce=n.fieldOptions[E]?.hidden??[];if(ce.length===le.items.length-1){const Be=new Set(ce),ue=d(E).order.findIndex(Me=>!Be.has(le.keyOf(Me)));ue>=0&&(X.item=String(ue))}I.c.push(m("pageField",X))}y.set("pageFields",I)}n.values.length>0&&y.set("dataFields",m("dataFields",{count:String(n.values.length)},n.values.map(I=>qt(t,I,d,{numFmtId:s}))));const C=n.style,D=p?b(p,"pivotTableStyleInfo"):null;y.set("pivotTableStyleInfo",m("pivotTableStyleInfo",{...D?.a??{},name:C.name,showRowHeaders:C.rowHeaders?"1":"0",showColHeaders:C.colHeaders?"1":"0",showRowStripes:C.rowStripes?"1":"0",showColStripes:C.colStripes?"1":"0",showLastColumn:C.lastColumn===!1?"0":"1"}));const B=_t(t,h),N=t.xml?.rawFilters??[],R=[...B,...N];R.length>0&&y.set("filters",m("filters",{count:String(R.length)},R));const k=$e(t,m);k&&y.set("conditionalFormats",k);const P=_e(t,m);P&&y.set("chartFormats",P);const O=yt(p,n.hideValuesRow);O&&y.set("extLst",O);const M=[];for(const I of Le)if(y.has(I))M.push(y.get(I));else if(p&&!Vt.has(I)){const E=b(p,I);E&&M.push(E)}if(p)for(const I of p.c)Le.includes(I.n)||M.splice(M.length-(M[M.length-1]?.n==="extLst"?1:0),0,I);return K+ne(m("pivotTableDefinition",f,M)).join("")}const Vt=new Set(["extLst","location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","pivotTableStyleInfo","filters"]);function ie(t,e){for(let s=1;;s++){const a=e(s);if(!t.has(a))return t.add(a),a}}function tn(t){const e=t.map(s=>`<Relationship Id="${s.id}" Type="${s.type}" Target="${J(s.target)}"/>`).join("");return`${K}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${e}</Relationships>`}function nn(t,{existing:e=[],saveRecords:s=!0,numFmtId:a,refreshOnLoad:n=!0,firstCacheId:l=1}={}){const o=new Set(e),c=[],r=[],i=[],d=[],p=new Map;let f=l;const u=x=>{c.push(x),i.push({partName:`/${x.name}`,contentType:x.contentType})},h=t.filter(x=>x.dirty||!x.part),g=[],w=new Set(t.filter(x=>!h.includes(x)).map(x=>x.cache));for(const x of h){const{cache:v}=x;x.part&&g.push(x.part),v.part&&!w.has(v)&&(g.push(v.part),v.part=null);let y=p.get(v);if(y===void 0){const S=f++,C=ie(o,R=>`xl/pivotCache/pivotCacheDefinition${R}.xml`);v.id=S;let D=null;if(s&&v.recordCount>0){const R=ie(o,k=>`xl/pivotCache/pivotCacheRecords${k}.xml`);D="rId1",r.push({from:C,id:D,type:_.records,target:`/${R}`}),u({name:R,contentType:ee.records,large:!0,produce:k=>Oe(v,k)})}const N={name:C,contentType:ee.definition,xml:null};u(N),y={cacheId:S,defName:C,defPart:N,recordsRel:D},p.set(v,y),d.push({cacheId:S,target:`/${C}`,type:_.definition})}x.result||x.update();const F=ie(o,S=>`xl/pivotTables/pivotTable${S}.xml`);u({name:F,contentType:ee.table,xml:Ht(x,{cacheId:y.cacheId,numFmtId:a})}),r.push({from:F,id:"rId1",type:_.definition,target:`/${y.defName}`}),r.push({from:null,sheet:x.anchor?.sheet??null,id:null,type:_.table,target:`/${F}`}),x.part=F}for(const[x,v]of p)v.defPart.xml=Ct(x,{recordsRel:v.recordsRel,numFmtId:a,refreshOnLoad:n});return{parts:c,relationships:r,contentTypes:i,replaced:g,workbook:{pivotCaches:d,pivotCachesXml(x){return d.length===0?"":`<pivotCaches>${d.map(v=>`<pivotCache cacheId="${v.cacheId}" r:id="${x(v.cacheId)}"/>`).join("")}</pivotCaches>`}}}}export{ee as CONTENT_TYPE,pt as CacheRecordsReader,We as EMPTY,Ye as ERRORS,Ie as NodeReader,_ as REL_TYPE,et as XlError,nn as buildPivotPackage,Ct as cacheDefinitionXml,wt as cacheFromXml,W as isoToSerial,Ne as parseNode,vt as pivotFromXml,Ht as pivotTableXml,ht as readCacheDefinition,mt as readCacheRecords,zt as readPivotParts,en as recordsBlob,tn as relationshipsXml,H as serialToIso,ne as serializeNode,Oe as writeCacheRecords};
|
|
1
|
+
import{pivotCfNode as $e,pivotChartFormatsNode as _e}from"../slicers/pivot-file.js";import{dateFilterNodes as qe,isDateFilterType as He,parseDateFilter as Ve}from"../slicers/date-filters.js";import{MAX_COLS as Ge,parseRangeRef as de,rangeRef as fe}from"../core/address.js";import{BUILTIN_FORMATS as Y,partsToSerial as Xe,serialToParts as je}from"../core/numfmt.js";import{BOOL as Ue,EMPTY as We,ERR as Ke,ERRORS as Ye,NUM as pe,STR as Je}from"../core/sheet.js";import{decodeRange as B,unescapeXml as Qe,unescapeXstring as he,XmlScanner as me}from"../io/xml-scan.js";import{escapeMarkup as J,xmlAttr as ge}from"../io/xml-escape.js";import{relsPathOf as Ze,resolveTarget as ze}from"../io/package-paths.js";import{ERR_BY_CODE as we,ERR_BY_INDEX as be,XlError as et}from"../calc/values.js";import{applyNumFmt as Q,itemKey as $,LINE as j,PivotCache as tt,PivotField as nt,PivotTable as st,storeColumn as at,VALUES as Z,compileCalc as ot,valueFieldName as rt}from"./engine.js";const U="http://schemas.openxmlformats.org/spreadsheetml/2006/main",V="http://schemas.openxmlformats.org/officeDocument/2006/relationships",z="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main",it="{E15A36E0-9728-4e99-A89B-3F7291B0FE68}",lt="{962EF5D1-5CA2-4c93-8EF4-DBF5C05439D2}",ct="{2946ED86-A175-432a-8AC1-64E0C546D7DE}",ee={table:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml",definition:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",records:"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"},_={table:`${V}/pivotTable`,definition:`${V}/pivotCacheDefinition`,records:`${V}/pivotCacheRecords`},xe=1048828,ye=1048829,ve=4294967294,ut=new Set(["percentOfParent","percentOfParentRow","percentOfParentCol","percentOfRunningTotal","rankAscending","rankDescending"]),te={sum:"sumSubtotal",count:"countASubtotal",average:"avgSubtotal",max:"maxSubtotal",min:"minSubtotal",product:"productSubtotal",countNums:"countSubtotal",stdDev:"stdDevSubtotal",stdDevp:"stdDevPSubtotal",var:"varSubtotal",varp:"varPSubtotal"},Fe={sum:"sum",count:"countA",average:"avg",max:"max",min:"min",product:"product",countNums:"count",stdDev:"stdDev",stdDevp:"stdDevP",var:"var",varp:"varP"},m=(t,e={},s=[])=>({n:t,a:e,c:s,t:""}),y=(t,e)=>t?.c.find(s=>s.n===e)??null,A=(t,e)=>t?t.c.filter(s=>s.n===e):[],S=(t,e)=>t===void 0?e:t==="1"||t==="true";function Se(t,e,s){const a={};let n=e;for(;n<s;){for(;n<s&&t[n]<=32;)n++;if(n>=s)break;const l=n;for(;n<s&&t[n]!==61&&t[n]>32;)n++;const o=n;for(;n<s&&t[n]!==34&&t[n]!==39;)n++;if(n>=s)break;const c=t[n++],r=n,i=t.indexOf(c,n),d=i<0||i>s?s:i;a[B(t,l,o)]=he(B(t,r,d)),n=d+1}return a}function dt(t,e,s){let a=e;for(;a>0&&t[a-1]!==60;)a--;return B(t,a,s)}function ne(t,e=[]){e.push("<",t.n);for(const s of Object.keys(t.a)){const a=t.a[s];a!=null&&e.push(" ",s,'="',ge(a),'"')}if(t.c.length===0&&t.t==="")return e.push("/>"),e;e.push(">"),t.t&&e.push(J(t.t));for(const s of t.c)typeof s=="string"?e.push(s):ne(s,e);return e.push("</",t.n,">"),e}const ft=new Set(["s","n","d","b","e","m"]);function Te(t,e){switch(t){case"n":return Number(e.v);case"s":return e.v??"";case"d":return W(e.v);case"b":return e.v==="1"||e.v==="true";case"e":return we.get(e.v)??be[6];default:return null}}class Ie{constructor(){this.root=m("#root"),this.stack=[this.root],this.shared=null,this.sharedDepth=0,this.scanner=new me(this)}feed(e){this.scanner.feed(e)}finish(){return this.root.c[0]??null}open(e,s,a,n,l,o){const c=this.stack[this.stack.length-1];if(this.shared!==null&&c===this.shared){const f=B(e,s,a);if(ft.has(f)){const u=Se(e,n,l);c.items.push(Te(f,u)),o||this.sharedDepth++;return}}if(this.sharedDepth>0){o||this.sharedDepth++;return}const r=Se(e,n,l);let i=dt(e,s,a);const d=i.indexOf(":");if(d>=0){const f="xmlns:"+i.slice(0,d);let u=r[f];for(let h=this.stack.length-1;u===void 0&&h>0;h--)u=this.stack[h].a[f];u===U&&(i=i.slice(d+1))}const p=m(i,r);p.n==="sharedItems"&&(p.items=[],this.shared=p),c.c.push(p),o?p.n==="sharedItems"&&(this.shared=null):this.stack.push(p)}close(){if(this.sharedDepth>0){this.sharedDepth--;return}this.stack.pop()===this.shared&&(this.shared=null),this.stack.length===0&&this.stack.push(this.root)}text(e,s,a){if(this.sharedDepth>0)return;let n=!0;for(let l=s;l<a;l++)if(e[l]>32){n=!1;break}n||(this.stack[this.stack.length-1].t+=Qe(B(e,s,a)))}}function Ne(t){const e=new Ie;return e.feed(typeof t=="string"?new TextEncoder().encode(t):t),e.finish()}async function Ce(t,e){if(t instanceof Uint8Array)e.feed(t);else if(t.getReader){const s=t.getReader();for(;;){const{done:a,value:n}=await s.read();if(a)break;e.feed(n)}}else for await(const s of t)e.feed(s);return e.finish()}function W(t){const e=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(\.\d+)?)?/.exec(t??"");if(!e)return 0;const s=Xe(Number(e[1]),Number(e[2]),Number(e[3]));return e[4]===void 0?s:s+(Number(e[4])*3600+Number(e[5])*60+Number(e[6])+Number(e[7]??0))/86400}const q=(t,e=2)=>String(t).padStart(e,"0");function H(t){const e=je(t),s=Math.floor(e.ms/1e3);return`${q(e.year,4)}-${q(e.month)}-${q(e.day)}T${q(Math.floor(s/3600))}:${q(Math.floor(s/60)%60)}:${q(s%60)}`}class pt{constructor(e){this.positions=e.fields.filter(a=>a.a.databaseField===void 0||S(a.a.databaseField,!0));const s=e.c?Number(e.a.recordCount??1024):1024;this.capacity=Math.max(s,16),this.count=0,this.columns=this.positions.map(()=>({ids:null,kinds:null,nums:null})),this.pool=new Map,this.strings=[],this.at=-1,this.scanner=new me(this),this.inRecord=!1}feed(e){this.scanner.feed(e)}_grow(){this.capacity*=2;const e=(s,a)=>{if(a===null)return null;const n=new s(this.capacity);return n.set(a),n};for(const s of this.columns)s.ids=e(Int32Array,s.ids),s.kinds=e(Uint8Array,s.kinds),s.nums=e(Float64Array,s.nums)}open(e,s,a,n,l){if(a-s!==1)return;const o=e[s];if(o===114){this.count===this.capacity&&this._grow(),this.count++,this.at=0;return}if(this.at<0)return;const c=this.at++,r=this.columns[c];if(r===void 0)return;const i=this.count-1;if(o===120){r.ids===null&&(r.ids=new Int32Array(this.capacity));let u=0,h=Ee(e,n,l);if(h>=0)for(;h<l;h++){const g=e[h]-48;if(g<0||g>9)break;u=u*10+g}r.ids[i]=u;return}if(r.kinds===null&&(r.kinds=new Uint8Array(this.capacity),r.nums=new Float64Array(this.capacity)),o===109)return;const d=Ee(e,n,l);if(d<0)return;let p=d;const f=e[d-1];for(;p<l&&e[p]!==f;)p++;switch(o){case 110:r.kinds[i]=pe,r.nums[i]=Number(B(e,d,p));break;case 115:{const u=he(B(e,d,p));let h=this.pool.get(u);h===void 0&&(h=this.strings.length,this.strings.push(u),this.pool.set(u,h)),r.kinds[i]=Je,r.nums[i]=h;break}case 100:r.kinds[i]=pe,r.nums[i]=W(B(e,d,p)),r.dates=!0;break;case 98:r.kinds[i]=Ue,r.nums[i]=e[d]===49||e[d]===116?1:0;break;case 101:{const u=we.get(B(e,d,p));r.kinds[i]=Ke,r.nums[i]=u?u.index:6;break}default:}}close(e,s,a){a-s===1&&e[s]===114&&(this.at=-1)}text(){}finish(){return this}}function Ee(t,e,s){for(let a=e;a<s-2;a++)if(t[a]===118&&t[a+1]===61&&t[a-1]<=32)return a+3;return-1}async function ht(t){const e=await Ce(t,new Ie),s=y(e,"cacheFields");return{root:e,fields:s?A(s,"cacheField"):[],a:e.a,c:e.c}}async function mt(t,e){return Ce(t,new pt(e))}function Re(t){const e=y(t,"groupItems");return e?e.c.map(s=>Te(s.n,s.a)):[]}function gt(t,e){const s=Number(t.numFmtId??0);return Y[s]??e?.(s)??"General"}function wt(t,e,{numFmtOf:s}={}){const a=new tt,{fields:n}=t;a.xml={root:t.root},a.needsRefresh=e==null;const l=e?e.count:0;a.recordCount=l,e&&(a.strings.list=e.strings,a.strings.index=e.pool);let o=0;n.forEach((c,r)=>{const i=new nt(a,r,c.a.name??`Field${r+1}`);i.xml={node:c},Q(i,gt(c.a,s));const d=y(c,"sharedItems"),p=d?.items??[],f=c.a.databaseField===void 0||S(c.a.databaseField,!0);if(d&&S(d.a.containsDate,!1)&&i.numFmt==="General"&&Q(i,"m/d/yyyy"),c.a.formula!==void 0)i.formula=c.a.formula;else if(f&&e){const u=e.columns[o];u?.ids?(i.rawIds=u.ids.subarray(0,l),i.shared=p.slice()):u?.kinds&&(at(i,u.kinds.subarray(0,l),u.nums.subarray(0,l),l),u.dates&&i.numFmt==="General"&&Q(i,"m/d/yyyy"))}else f&&(i.shared=p.slice(),i.rawIds=new Int32Array(0));f&&o++,a.fields.push(i)}),n.forEach((c,r)=>{const i=y(c,"fieldGroup");if(!i)return;const d=a.fields[r],p=i.a.base!==void 0?Number(i.a.base):r;i.a.par!==void 0&&(d.par=Number(i.a.par)),p!==r&&(d.base=p);const f=y(i,"rangePr"),u=y(i,"discretePr"),h=Re(i);if(f){const g=f.a.groupBy??"range",x=S(f.a.autoStart,!0),T=S(f.a.autoEnd,!0);if(g==="range"){const w=Number(f.a.startNum??0),b=Number(f.a.endNum??0),v=Number(f.a.groupInterval??1),F=h.length>1&&/^-?\d+--?\d+$/.test(String(h[1]))&&Number.isInteger(w)&&Number.isInteger(v)&&Number(String(h[1]).match(/^-?\d+-(-?\d+)$/)?.[1])===w+v-1;d.group={kind:"bins",start:w,end:b,interval:v,integer:F,autoStart:x,autoEnd:T,labels:h}}else d.group={kind:"date",part:g,start:Math.floor(W(f.a.startDate)),end:Math.floor(W(f.a.endDate))-1,autoStart:x,autoEnd:T,labels:h}}else if(u&&p!==r){const g=a.fields[p],x=A(u,"x").map(v=>Number(v.a.v??0)),T=h.map(()=>[]),w=y(n[p],"sharedItems")?.items??g.shared??[];x.forEach((v,F)=>{T[v]&&T[v].push($(w[F]??null))});const b=[];h.forEach((v,F)=>{T[F].length===1&&T[F][0]===$(v)||b.push({name:String(v),keys:T[F]})}),d.group={kind:"discrete",groups:b}}});for(const c of a.fields)if(c.formula!==null)try{c.calc=ot(c.formula,a)}catch{c.calc={fn:()=>{throw be[4]},refs:[]}}return a}function se(t,e){const s=t.fields[e].xml?.node,a=s?y(s,"fieldGroup"):null,n=a?Re(a):[];return n.length>0?n:(s?y(s,"sharedItems"):null)?.items??[]}function bt(t){const e=t.a.type??"",s=y(y(t,"autoFilter"),"filterColumn");if(e==="count"||e==="percent"||e==="sum"){const a=y(s,"top10");return a?{top:{count:Number(a.a.val??10),by:e==="count"?"items":e,bottom:a.a.top==="0"||a.a.top==="false",data:Number(t.a.iMeasureFld??0)}}:null}if(He(e))return{dateFilter:Ve(t)};if(e.startsWith("caption"))return{labelFilter:{op:e,value:t.a.stringValue1??"",value2:t.a.stringValue2??""}};if(e.startsWith("value")){const a=A(y(s,"customFilters"),"customFilter");return a.length===0?null:{valueFilter:{op:e,data:Number(t.a.iMeasureFld??0),value:Number(a[0].a.val),value2:a[1]?Number(a[1].a.val):void 0}}}return null}function xt(t){for(const e of A(y(t,"extLst"),"ext")){const s=y(e,"x14:pivotTableDefinition");if(s)return s}return null}function yt(t,e){const s=t?y(t,"extLst"):null,a=[];let n=!1;for(const l of s?.c??[]){const o=y(l,"x14:pivotTableDefinition");if(!o){a.push(l);continue}n=!0;const c={...o.a};delete c.hideValuesRow,e&&(c.hideValuesRow="1"),a.push(m("ext",l.a,l.c.map(r=>r===o?m(o.n,c,o.c):r)))}return!n&&e&&a.push(m("ext",{uri:lt,"xmlns:x14":z},[m("x14:pivotTableDefinition",{hideValuesRow:"1"})])),a.length>0?m("extLst",{},a):null}function vt(t,e,{numFmtOf:s,sheet:a}={}){const n={name:t.a.name??"PivotTable1",fieldOptions:{},rows:A(y(t,"rowFields"),"field").map(u=>Number(u.a.x)),cols:A(y(t,"colFields"),"field").map(u=>Number(u.a.x)),filters:[],values:[],grandRow:S(t.a.colGrandTotals,!0),grandCol:S(t.a.rowGrandTotals,!0),rowCaption:t.a.rowHeaderCaption??null,colCaption:t.a.colHeaderCaption??null,dataCaption:t.a.dataCaption??"Values",grandCaption:t.a.grandTotalCaption??null,emptyText:S(t.a.showMissing,!0)?t.a.missingCaption??"":"",showMissing:S(t.a.showMissing,!0),errorText:S(t.a.showError,!1)?t.a.errorCaption??"":null,showExpandButtons:S(t.a.showDrill,!0),showFieldHeaders:S(t.a.showHeaders,!0),hideValuesRow:S(xt(t)?.a.hideValuesRow,!1)},l=A(y(t,"pivotFields"),"pivotField"),o={root:t,fields:l,itemAttrs:[],pageFields:new Map,rawFilters:[]},c=[];l.forEach((u,h)=>{const g={},x=se(e,h),T=A(y(u,"items"),"item"),w=[],b=[],v=[],F={},N=new Map;for(const C of T){if(C.a.t!==void 0&&C.a.t!=="data")continue;const k=Number(C.a.x??0),R=$(x[k]??null);v.push(R),N.set(R,C.a),S(C.a.h,!1)&&w.push(R),C.a.sd!==void 0&&!S(C.a.sd,!0)&&b.push(R),C.a.n!==void 0&&(F[R]=C.a.n)}o.itemAttrs[h]=N,w.length&&(g.hidden=w),b.length&&(g.collapsedItems=b),Object.keys(F).length&&(g.itemCaptions=F),u.a.name!==void 0&&(g.caption=u.a.name);const D=u.a.sortType??"manual";if(D==="ascending"||D==="descending"){g.sort={order:D==="ascending"?"asc":"desc"};const C=y(y(u,"autoSortScope"),"pivotArea"),k=y(y(C,"references"),"reference");k&&Number(k.a.field)===ve&&(g.sort.data=Number(y(k,"x")?.a.v??0))}else v.length>0&&u.a.axis&&(g.sort={order:"manual",keys:v});const P=Object.entries(te).filter(([,C])=>S(u.a[C],!1)).map(([C])=>C);P.length>0?g.subtotals=P:S(u.a.defaultSubtotal,!0)||(g.subtotals="none"),u.a.subtotalTop!==void 0&&(g.subtotalTop=S(u.a.subtotalTop,!0)),S(u.a.insertBlankRow,!1)&&(g.blankLine=!0),u.a.axis&&S(u.a.showAll,!0)&&(g.showAll=!0),S(u.a.insertPageBreak,!1)&&(g.pageBreak=!0);for(const C of A(y(u,"extLst"),"ext"))S(y(C,"x14:pivotField")?.a.fillDownLabels,!1)&&(g.repeatLabels=!0);if(u.a.axis==="axisRow"||u.a.axis==="axisCol"){const C=S(u.a.compact,!0)?"compact":S(u.a.outline,!0)?"outline":"tabular";c.push([h,C])}Object.keys(g).length>0&&(n.fieldOptions[h]=g)});const r=new Map;for(const[,u]of c)r.set(u,(r.get(u)??0)+1);n.layout=[...r.entries()].sort((u,h)=>h[1]-u[1])[0]?.[0]??"compact";for(const[u,h]of c)h!==n.layout&&(n.fieldOptions[u]??={},n.fieldOptions[u].layout=h);for(const u of A(y(t,"pageFields"),"pageField")){const h=Number(u.a.fld);if(n.filters.push(h),o.pageFields.set(h,u.a),u.a.item!==void 0){const g=A(y(l[h],"items"),"item"),x=g[Number(u.a.item)],T=se(e,h);if(x){const w=$(T[Number(x.a.x??0)]??null),b=[];for(const v of g){if(v.a.t!==void 0&&v.a.t!=="data")continue;const F=$(T[Number(v.a.x??0)]??null);F!==w&&b.push(F)}n.fieldOptions[h]??={},n.fieldOptions[h].hidden=b}}}for(const u of A(y(t,"dataFields"),"dataField")){const h=Number(u.a.fld),g={field:h,name:u.a.name??rt(u.a.subtotal??"sum",e.fields[h].name),agg:u.a.subtotal??"sum",xml:u};let x=u.a.showDataAs??"normal";const T=y(y(u,"extLst"),"ext"),w=T?y(T,"x14:dataField"):null;if(w?.a.pivotShowAs&&(x=w.a.pivotShowAs),x!=="normal"&&(g.showAs={type:x},u.a.baseField!==void 0&&(g.showAs.baseField=Number(u.a.baseField)),u.a.baseItem!==void 0)){const b=Number(u.a.baseItem);if(b===xe)g.showAs.baseItem="prev";else if(b===ye)g.showAs.baseItem="next";else{const v=g.showAs.baseField,F=A(y(l[v],"items"),"item"),N=se(e,v),D=F[b];g.showAs.baseItem=D?$(N[Number(D.a.x??0)]??null):"prev"}}if(u.a.numFmtId!==void 0){const b=Number(u.a.numFmtId),v=Y[b]??s?.(b);v&&(g.numFmt=v)}n.values.push(g)}for(const u of A(y(t,"filters"),"filter")){const h=bt(u),g=Number(u.a.fld);if(h===null){o.rawFilters.push(u);continue}n.fieldOptions[g]??={},Object.assign(n.fieldOptions[g],h)}S(t.a.mergeItem,!1)&&(n.mergeLabels=!0);const i=y(t,"pivotTableStyleInfo");i&&(n.style={name:i.a.name??"PivotStyleLight16",rowHeaders:S(i.a.showRowHeaders,!0),colHeaders:S(i.a.showColHeaders,!0),rowStripes:S(i.a.showRowStripes,!1),colStripes:S(i.a.showColStripes,!1),lastColumn:S(i.a.showLastColumn,!0)});const d=new st(e,n);d.xml=o,d.dirty=!1;const p=y(t,"location"),f=p?de(p.a.ref??""):null;if(f){const u=n.filters.length>0?n.filters.length+1:0;d.anchor={sheet:a??null,row:Math.max(0,f.r0-u),col:f.c0},d.renderedRange={r0:d.anchor.row,c0:f.c0,r1:f.r1,c1:f.c1}}return d}async function ae(t,e){const s=Ze(e);if(!t.has(s))return[];const a=Ne(await t.bytes(s));return A(a,"Relationship").map(n=>({id:n.a.Id,type:n.a.Type,target:ze(e,n.a.Target??"")}))}async function zt(t,{sheets:e,book:s,tables:a=[],numFmtOf:n,readRecords:l=!0}){const o=new Map,c=[];for(const{part:r,sheet:i}of e)if(r)for(const d of await ae(t,r)){if(d.type!==_.table||!t.has(d.target))continue;const p=Ne(await t.bytes(d.target)),u=(await ae(t,d.target)).find(x=>x.type===_.definition);if(!u||!t.has(u.target))continue;let h=o.get(u.target);if(h===void 0){const x=await ht(await t.stream(u.target)),w=(await ae(t,u.target)).find(v=>v.type===_.records);let b=null;l&&w&&t.has(w.target)&&(b=await mt(await t.stream(w.target),x)),h=wt(x,b,{numFmtOf:n}),h.refreshOnLoad=["1","true"].includes(x.a.refreshOnLoad),h.part=u.target,h.id=p.a.cacheId!==void 0?Number(p.a.cacheId):0,Ft(h,x,s,a),o.set(u.target,h)}const g=vt(p,h,{numFmtOf:n,sheet:i});g.part=d.target,c.push(g)}return{caches:[...o.values()],pivots:c}}function Ft(t,e,s,a){if(!s)return;const n=y(y(e.root,"cacheSource"),"worksheetSource");if(!n)return;if(n.a.name!==void 0){const c=a.find(r=>r.name?.toLowerCase()===n.a.name.toLowerCase());c&&(t.source={type:"table",book:s,table:c});return}const l=de(n.a.ref??""),o=s.sheets.find(c=>c.name===n.a.sheet);l&&o&&(t.source={type:"range",book:s,sheet:o,range:l})}const K=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
`,oe=new TextEncoder;function ke(t){for(const[e,s]of Object.entries(Y))if(s===t)return Number(e);return null}function re(t,e){if(t==null)return"<m/>";switch(typeof t){case"number":return e?`<d v="${H(t)}"/>`:`<n v="${t}"/>`;case"string":return`<s v="${ge(t)}"/>`;case"boolean":return`<b v="${t?1:0}"/>`;default:return`<e v="${J(t.code)}"/>`}}function Ae(t,e){const{hasNum:s,hasInt:a,hasText:n,hasBlank:l,hasOther:o,min:c,max:r,longText:i}=e,d=t.isDate&&s&&!n&&!o,p={};return!n&&!l&&!o&&(p.containsSemiMixedTypes="0"),d&&!l&&(p.containsNonDate="0"),d&&(p.containsDate="1"),n||(p.containsString="0"),l&&(p.containsBlank="1"),(s?1:0)+(n?1:0)+(o?1:0)>1&&(p.containsMixedTypes="1"),s&&!d&&(p.containsNumber="1",a&&(p.containsInteger="1"),p.minValue=String(c),p.maxValue=String(r)),d&&(p.minDate=H(c),p.maxDate=H(Math.floor(r)+1)),i&&(p.longText="1"),{attrs:p,date:d}}function St(t){const e={hasNum:!1,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(const s of t)typeof s=="number"?(e.hasNum=!0,Number.isInteger(s)||(e.hasInt=!1),s<e.min&&(e.min=s),s>e.max&&(e.max=s)):typeof s=="string"?(e.hasText=!0,s.length>255&&(e.longText=!0)):s==null?e.hasBlank=!0:e.hasOther=!0;return e}function Tt(t){const e={hasNum:t.length>0,hasInt:!0,hasText:!1,hasBlank:!1,hasOther:!1,min:1/0,max:-1/0,longText:!1};for(let s=0;s<t.length;s++){const a=t[s];a<e.min&&(e.min=a),a>e.max&&(e.max=a),e.hasInt&&Math.floor(a)!==a&&(e.hasInt=!1)}return e}function De(t){return t.ensureColumn(),t.rawIds!==null?!0:!(t.nums!==null&&t.kinds===null)}function It(t,e){const s=e.group;if(s===null)return e.par>=0?m("fieldGroup",{par:String(e.par)}):null;e.ensure();const a={};e.par>=0&&(a.par=String(e.par)),a.base=String(e.base>=0?e.base:e.index);const n=[],l=e.items.map(c=>re(c,!1)).join("");if(s.kind==="date"){const c={groupBy:s.part,startDate:H(s.start),endDate:H(s.end+1)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else if(s.kind==="bins"){const c={startNum:String(s.start),endNum:String(s.end),groupInterval:String(s.interval)};s.autoStart||(c.autoStart="0"),s.autoEnd||(c.autoEnd="0"),n.push(m("rangePr",c))}else{const c=e.groupMap,r=m("discretePr",{count:String(c.length)});for(let i=0;i<c.length;i++)r.c.push(m("x",{v:String(c[i])}));n.push(r)}const o=m("groupItems",{count:String(e.items.length)});return o.c.push(l),n.push(o),m("fieldGroup",a,n)}function Nt(t,e,s){const a=e.xml?.node??null,n={...a?.a??{}};if(n.name=e.name,n.numFmtId===void 0){const c=e.numFmt!=="General"?ke(e.numFmt)??s.numFmtId?.(e.numFmt)??(e.isDate?14:0):0;n.numFmtId=String(c)}const l=[];if(e.isCalculated)n.formula=e.formula,n.databaseField="0",delete n.uniqueList;else if(e.base>=0)n.databaseField="0";else if(t.recordCount===0&&a&&y(a,"sharedItems")){const c=y(a,"sharedItems"),r=m("sharedItems",{...c.a}),i=S(c.a.containsDate,!1);c.items.length>0&&r.c.push(c.items.map(d=>re(d,i&&typeof d=="number")).join("")),l.push(r)}else if(De(e)){e.ensureRaw();const{attrs:c,date:r}=Ae(e,St(e.shared)),i=m("sharedItems",{...c,count:String(e.shared.length)});i.c.push(e.shared.map(d=>re(d,r&&typeof d=="number")).join("")),l.push(i)}else{const{attrs:c}=Ae(e,Tt(e.nums));l.push(m("sharedItems",c))}const o=It(t,e);if(o&&l.push(o),a)for(const c of a.c)c.n!=="sharedItems"&&c.n!=="fieldGroup"&&l.push(c);return m("cacheField",n,l)}function Ct(t,{recordsRel:e=null,numFmtId:s,refreshOnLoad:a=!0,sourceSheetName:n}={}){const l=t.xml?.root??null,o={...l?.a??{}};o.xmlns??=U,o["xmlns:r"]??=V,e?o["r:id"]=e:delete o["r:id"],a&&(o.refreshOnLoad="1"),o.refreshedBy??="8sheets",o.refreshedDate=String(Et()),o.createdVersion??="6",o.refreshedVersion??="6",o.minRefreshableVersion??="3",o.recordCount=String(t.recordCount),e?delete o.saveData:o.saveData="0";const c=[],r=l?y(l,"cacheSource"):null;c.push(Rt(t,r,n));const i=m("cacheFields",{count:"0"}),d=t.fields;for(const p of d)i.c.push(Nt(t,p,{numFmtId:s}));if(i.a.count=String(d.length),c.push(i),l)for(const p of l.c)p.n!=="cacheSource"&&p.n!=="cacheFields"&&c.push(p);return K+ne(m("pivotCacheDefinition",o,c)).join("")}function Et(){return Math.round((Date.now()/864e5+25569)*1e5)/1e5}function Rt(t,e,s){const a=t.source;if(a===null)return e??m("cacheSource",{type:"worksheet"},[m("worksheetSource",{ref:"A1",sheet:"Sheet1"})]);const n={};if(a.type==="table")n.name=a.table.name;else{const i=a.range,d=s??(typeof a.sheet=="string"?a.sheet:a.sheet.name);n.ref=fe({r0:i.r0,c0:i.c0,r1:i.r1,c1:Math.min(i.c1,Ge-1)}),n.sheet=d}const l=e?{...e.a}:{type:"worksheet"},o=e?e.c.filter(i=>i.n!=="worksheetSource"):[],c=e?y(e,"worksheetSource"):null,r=c?{...c.a,...n}:n;return a.type==="table"&&(delete r.ref,delete r.sheet),m("cacheSource",l,[m("worksheetSource",r),...o])}const kt=4096;async function Oe(t,e){const s=t.recordCount,a=[];for(const l of t.fields)l.isVirtual||(De(l)?(l.ensureRaw(),a.push(At(l.rawIds))):a.push(Dt(l.nums,l.isDate)));await e(oe.encode(`${K}<pivotCacheRecords xmlns="${U}" xmlns:r="${V}" count="${s}">`));const n=[];for(let l=0;l<s;l++){n.push("<r>");for(let o=0;o<a.length;o++)n.push(a[o](l));n.push("</r>"),(l+1)%kt===0&&(await e(oe.encode(n.join(""))),n.length=0)}n.push("</pivotCacheRecords>"),await e(oe.encode(n.join("")))}function At(t){return e=>`<x v="${t[e]}"/>`}function Dt(t,e){return e?s=>`<d v="${H(t[s])}"/>`:s=>`<n v="${t[s]}"/>`}async function en(t){const e="application/xml";let s=new Blob([],{type:e}),a=[],n=0;return await Oe(t,l=>{a.push(l),n+=l.length,n>=1<<24&&(s=new Blob([s,...a],{type:e}),a=[],n=0)}),new Blob([s,...a],{type:e})}const Le=["location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","formats","conditionalFormats","chartFormats","pivotHierarchies","pivotTableStyleInfo","filters","rowHierarchiesUsage","colHierarchiesUsage","extLst"];function Ot(t,e){const s=t.cache.fields[e].ensure(),a=s.rank(),n=Array.from(s.items.keys()),o=t.spec.fieldOptions[e]?.sort;if(o?.order==="manual"){const r=new Map((o.keys??[]).map((p,f)=>[p,f])),i=r.size,d=p=>r.get($(s.items[p]))??i+a[p];n.sort((p,f)=>d(p)-d(f))}else o?.order==="desc"&&(o.data===void 0||o.data===null)?n.sort((r,i)=>a[i]-a[r]):n.sort((r,i)=>a[r]-a[i]);const c=new Int32Array(n.length);return n.forEach((r,i)=>{c[r]=i}),{order:n,position:c}}function Lt(t){return t.group!==null||t.base>=0}function Pt(t,e){return t.spec.fieldOptions[e]?.layout??t.spec.layout}const Bt=["axis","dataField","compact","outline","subtotalTop","sortType","defaultSubtotal","insertBlankRow","name","showDropDowns","dragToRow","dragToCol","dragToPage",...Object.values(te)];function Mt(t,e,s){const{spec:a,cache:n}=t,l=n.fields[e],o=a.fieldOptions[e]??{},c=t.xml?.fields?.[e]??null,r={...c?.a??{}};for(const F of Bt)delete r[F];o.caption!==void 0&&(r.name=o.caption);const i=a.rows.includes(e),d=a.cols.includes(e),p=a.filters.includes(e),f=a.values.some(F=>F.field===e);i?r.axis="axisRow":d?r.axis="axisCol":p&&(r.axis="axisPage"),f&&(r.dataField="1");const u=Pt(t,e);u!=="compact"&&(r.compact="0"),u==="tabular"&&(r.outline="0"),l.isCalculated&&(r.dragToRow="0",r.dragToCol="0",r.dragToPage="0"),r.showAll=o.showAll?"1":"0",o.pageBreak?r.insertPageBreak="1":delete r.insertPageBreak,(o.subtotalTop??a.subtotalTop)===!1&&(i||d)&&(r.subtotalTop="0"),o.blankLine&&(r.insertBlankRow="1"),o.sort?.order==="asc"?r.sortType="ascending":o.sort?.order==="desc"&&(r.sortType="descending");const h=o.subtotals??"auto",g=i||d||p,x=(o.hidden?.length??0)>0,T=g||Lt(l)||x||!!(o.range||o.dateFilter);if((l.isCalculated||h==="none"||Array.isArray(h)||l.base>=0&&!g)&&(r.defaultSubtotal="0"),Array.isArray(h))for(const F of h)r[te[F]]="1";const w=[];if(T&&!l.isCalculated){const{order:F}=s(e),N=m("items",{}),D=new Set(o.hidden??[]),P=new Set(o.collapsedItems??[]),C=t.xml?.itemAttrs?.[e]??null,k=o.itemCaptions??null;for(const R of F){const O=l.keyOf(R),L={...C?.get(O)??{}};delete L.h,delete L.sd,delete L.n,L.x=String(R),D.has(O)&&(L.h="1"),P.has(O)&&(L.sd="0"),k&&k[O]!==void 0&&(L.n=k[O]),N.c.push(m("item",L))}if((g||x||o.range||o.dateFilter)&&r.defaultSubtotal===void 0&&N.c.push(m("item",{t:"default"})),Array.isArray(h))for(const R of h)N.c.push(m("item",{t:Fe[R]}));N.a.count=String(N.c.length),w.push(N)}if(o.sort?.data!==void 0&&o.sort?.data!==null&&(o.sort.order==="asc"||o.sort.order==="desc")&&w.push(m("autoSortScope",{},[m("pivotArea",{dataOnly:"0",outline:"0",fieldPosition:"0"},[m("references",{count:"1"},[m("reference",{field:String(ve),count:"1",selected:"0"},[m("x",{v:String(o.sort.data)})])])])])),c)for(const F of c.c)F.n!=="items"&&F.n!=="autoSortScope"&&F.n!=="extLst"&&w.push(F);const b=o.repeatLabels===!0||a.repeatLabels===!0&&i&&u!=="compact",v=$t(c,b);return v&&w.push(v),m("pivotField",r,w)}function $t(t,e){const s=[];let a=!1;for(const n of A(t?y(t,"extLst"):null,"ext")){const l=y(n,"x14:pivotField");if(!l){s.push(n);continue}a=!0;const o={...l.a};delete o.fillDownLabels,e&&(o.fillDownLabels="1"),s.push(m("ext",n.a,n.c.map(c=>c===l?m(l.n,o,l.c):c)))}return!a&&e&&s.push(m("ext",{uri:ct,"xmlns:x14":z},[m("x14:pivotField",{fillDownLabels:"1"})])),s.length>0?m("extLst",{},s):null}function Pe(t,e,s,a){const n=s.lines,l=m(t,{}),{slots:o}=s;let c=[];for(let r=0;r<n.node.length;r++){const i=n.type[r],d=n.level[r],p={},f=[];if(o.length===0){l.c.push(m("i",{}));continue}if(i===j.GRAND){p.t="grand";const x=n.data[r];x>0&&(p.i=String(x));const T=m("i",p,[m("x",x>0?{v:String(x)}:{})]);l.c.push(T),c=[];continue}i===j.BLANK?p.t="blank":i===j.SUBTOTAL&&(p.t=n.func[r]?Fe[n.func[r]]:"default");let u=0;for(let x=0;x<=d;x++)if(o[x]===Z)f.push(n.data[r]>=0?n.data[r]:0);else{u++;const T=s.ancestorAt(n.node[r],u);f.push(a(o[x]).position[s.item[T]])}n.data[r]>0&&(p.i=String(n.data[r]));let h=0;if(i===j.ITEM)for(;h<f.length-1&&h<c.length&&c[h]===f[h];)h++;h>0&&(p.r=String(h));const g=m("i",p);for(let x=h;x<f.length;x++)g.c.push(m("x",f[x]===0?{}:{v:String(f[x])}));l.c.push(g),c=f}return l.c.length===0&&l.c.push(m("i",{})),l.a.count=String(l.c.length),l}function _t(t,e){const{spec:s}=t,a=[];let n=1;const l=(c,r,i,d)=>m("filter",{fld:String(c),type:r,evalOrder:"-1",id:String(n++),...i},[m("autoFilter",{ref:"A1"},[m("filterColumn",{colId:"0"},[d])])]),o=(c,r)=>m("customFilters",r?{and:"1"}:{},c.map(i=>m("customFilter",i)));for(const c of e){const r=s.fieldOptions[c];if(r){if(r.labelFilter){const i=r.labelFilter,d=String(i.value??""),p=String(i.value2??""),f={stringValue1:d};(i.op==="captionBetween"||i.op==="captionNotBetween")&&(f.stringValue2=p);const u={captionEqual:()=>o([{val:d}]),captionNotEqual:()=>o([{operator:"notEqual",val:d}]),captionBeginsWith:()=>o([{val:`${d}*`}]),captionNotBeginsWith:()=>o([{operator:"notEqual",val:`${d}*`}]),captionEndsWith:()=>o([{val:`*${d}`}]),captionNotEndsWith:()=>o([{operator:"notEqual",val:`*${d}`}]),captionContains:()=>o([{val:`*${d}*`}]),captionNotContains:()=>o([{operator:"notEqual",val:`*${d}*`}]),captionGreaterThan:()=>o([{operator:"greaterThan",val:d}]),captionGreaterThanOrEqual:()=>o([{operator:"greaterThanOrEqual",val:d}]),captionLessThan:()=>o([{operator:"lessThan",val:d}]),captionLessThanOrEqual:()=>o([{operator:"lessThanOrEqual",val:d}]),captionBetween:()=>o([{operator:"greaterThanOrEqual",val:d},{operator:"lessThanOrEqual",val:p}],!0),captionNotBetween:()=>o([{operator:"lessThan",val:d},{operator:"greaterThan",val:p}])}[i.op];u&&a.push(l(c,i.op,f,u()))}if(r.valueFilter){const i=r.valueFilter,d=String(i.value),p=String(i.value2??""),f={valueEqual:[[{val:d}]],valueNotEqual:[[{operator:"notEqual",val:d}]],valueGreaterThan:[[{operator:"greaterThan",val:d}]],valueGreaterThanOrEqual:[[{operator:"greaterThanOrEqual",val:d}]],valueLessThan:[[{operator:"lessThan",val:d}]],valueLessThanOrEqual:[[{operator:"lessThanOrEqual",val:d}]],valueBetween:[[{operator:"greaterThanOrEqual",val:d},{operator:"lessThanOrEqual",val:p}],!0],valueNotBetween:[[{operator:"lessThan",val:d},{operator:"greaterThan",val:p}]]}[i.op];f&&a.push(l(c,i.op,{iMeasureFld:String(i.data??0)},o(f[0],f[1]===!0)))}if(a.push(...qe(r,c,m,()=>n++)),r.top){const i=r.top,d={val:String(i.count??10),filterVal:String(i.count??10)};i.by==="percent"&&(d.percent="1"),i.bottom&&(d.top="0");const p=i.by==="percent"?"percent":i.by==="sum"?"sum":"count";a.push(l(c,p,{iMeasureFld:String(i.data??0)},m("top10",d)))}}}return a}function qt(t,e,s,a){const n=e.xml??null,l={...n?.a??{}};l.name=e.name,l.fld=String(e.field),e.agg&&e.agg!=="sum"?l.subtotal=e.agg:delete l.subtotal,delete l.showDataAs;const o=e.showAs?.type??"normal",c=n?n.c.filter(g=>g.n!=="extLst"):[];let r=null;ut.has(o)?r=o:o!=="normal"&&(l.showDataAs=o);const i=e.showAs?.baseField??0;l.baseField=String(i>=0?i:0);let d=0;const p=e.showAs?.baseItem;if(p==="prev")d=xe;else if(p==="next")d=ye;else if(p!==void 0&&e.showAs?.baseField>=0){const g=t.cache.fields[e.showAs.baseField].ensure(),x=g.keyIndex.get(p);x!==void 0&&(d=s(g.index).position[x])}l.baseItem=String(d);const f=e.numFmt??(o!=="normal"&&!o.startsWith("rank")&&o!=="difference"&&o!=="runTotal"?o==="index"?"0.00":"0.00%":null);if(f){const g=ke(f)??a.numFmtId?.(f);g!=null&&(l.numFmtId=String(g))}else delete l.numFmtId;const u=[],h=n?y(n,"extLst"):null;if(h)for(const g of h.c)if(y(g,"x14:dataField")){const x={...y(g,"x14:dataField").a};delete x.pivotShowAs,r&&(x.pivotShowAs=r),u.push(m("ext",g.a,[m("x14:dataField",x)])),r=null}else u.push(g);return r&&u.push(m("ext",{uri:it,"xmlns:x14":z},[m("x14:dataField",{pivotShowAs:r})])),u.length&&c.push(m("extLst",{},u)),m("dataField",l,c)}function Ht(t,{cacheId:e,numFmtId:s}={}){const a=t.result??t.update(),{spec:n,cache:l}=t,{layout:o,rows:c,cols:r}=a,i=new Map,d=I=>{let E=i.get(I);return E===void 0&&(E=Ot(t,I),i.set(I,E)),E},p=t.xml?.root??null,f={...p?.a??{}};f.xmlns??=U,f.name=n.name,f.cacheId=String(e??l.id??1),f.applyNumberFormats??="0",f.applyBorderFormats??="0",f.applyFontFormats??="0",f.applyPatternFormats??="0",f.applyAlignmentFormats??="0",f.applyWidthHeightFormats??="1",f.dataCaption=n.dataCaption,f.updatedVersion??="6",f.minRefreshableVersion??="3",f.useAutoFormatting??="1",f.itemPrintTitles??="1",f.createdVersion??="6",f.indent??="0",n.mergeLabels?f.mergeItem="1":delete f.mergeItem,t.fileAttrs&&Object.assign(f,t.fileAttrs);const u=(I,E,G)=>{E===G?delete f[I]:f[I]=E?"1":"0"};u("compact",n.layout==="compact",!0),u("compactData",n.layout==="compact",!0),f.outline=n.layout==="tabular"?f.outline??"1":"1",f.outlineData=n.layout==="tabular"?f.outlineData??"1":"1",u("colGrandTotals",n.grandRow,!0),u("rowGrandTotals",n.grandCol,!0),n.rowCaption!=null?f.rowHeaderCaption=n.rowCaption:delete f.rowHeaderCaption,n.colCaption!=null?f.colHeaderCaption=n.colCaption:delete f.colHeaderCaption,n.grandCaption!=null?f.grandTotalCaption=n.grandCaption:delete f.grandTotalCaption,n.emptyText!==""&&n.showMissing!==!1?f.missingCaption=n.emptyText:delete f.missingCaption,n.showMissing===!1?f.showMissing="0":delete f.showMissing,n.errorText!==null?(f.showError="1",f.errorCaption=n.errorText):(delete f.showError,delete f.errorCaption),c.slots.includes(Z)?(f.dataOnRows="1",f.dataPosition=String(c.slots.indexOf(Z))):(delete f.dataOnRows,delete f.dataPosition);const h=Object.keys(n.fieldOptions).map(Number),g=h.some(I=>{const E=n.fieldOptions[I];return(E.labelFilter?1:0)+(E.valueFilter?1:0)+(E.top?1:0)>1});f.multipleFieldFilters=g?"1":"0";const x=t.anchor??{row:0,col:0},T=x.row+o.pageRows,w={ref:fe({r0:T,c0:x.col,r1:x.row+o.rows-1,c1:x.col+Math.max(o.bodyCols,1)-1}),firstHeaderRow:String(o.firstHeaderRow),firstDataRow:String(o.firstDataRow),firstDataCol:String(o.firstDataCol)};n.filters.length>0&&(w.rowPageCount=String(n.filters.length),w.colPageCount="1");const b=new Map;b.set("location",m("location",w));const v=m("pivotFields",{count:String(l.fields.length)});for(let I=0;I<l.fields.length;I++)v.c.push(Mt(t,I,d));b.set("pivotFields",v);const F=(I,E)=>m(I,{count:String(E.length)},E.map(G=>m("field",{x:String(G)})));if(c.slots.length>0&&b.set("rowFields",F("rowFields",c.slots)),b.set("rowItems",Pe("rowItems",a,c,d)),r.slots.length>0&&b.set("colFields",F("colFields",r.slots)),b.set("colItems",Pe("colItems",a,r,d)),n.filters.length>0){const I=m("pageFields",{count:String(n.filters.length)});for(const E of n.filters){const X={...t.xml?.pageFields?.get(E)??{},fld:String(E)};delete X.item,X.hier??="-1";const le=l.fields[E].ensure(),ce=n.fieldOptions[E]?.hidden??[];if(ce.length===le.items.length-1){const Be=new Set(ce),ue=d(E).order.findIndex(Me=>!Be.has(le.keyOf(Me)));ue>=0&&(X.item=String(ue))}I.c.push(m("pageField",X))}b.set("pageFields",I)}n.values.length>0&&b.set("dataFields",m("dataFields",{count:String(n.values.length)},n.values.map(I=>qt(t,I,d,{numFmtId:s}))));const N=n.style,D=p?y(p,"pivotTableStyleInfo"):null;b.set("pivotTableStyleInfo",m("pivotTableStyleInfo",{...D?.a??{},name:N.name,showRowHeaders:N.rowHeaders?"1":"0",showColHeaders:N.colHeaders?"1":"0",showRowStripes:N.rowStripes?"1":"0",showColStripes:N.colStripes?"1":"0",showLastColumn:N.lastColumn===!1?"0":"1"}));const P=_t(t,h),C=t.xml?.rawFilters??[],k=[...P,...C];k.length>0&&b.set("filters",m("filters",{count:String(k.length)},k));const R=$e(t,m);R&&b.set("conditionalFormats",R);const O=_e(t,m);O&&b.set("chartFormats",O);const L=yt(p,n.hideValuesRow);L&&b.set("extLst",L);const M=[];for(const I of Le)if(b.has(I))M.push(b.get(I));else if(p&&!Vt.has(I)){const E=y(p,I);E&&M.push(E)}if(p)for(const I of p.c)Le.includes(I.n)||M.splice(M.length-(M[M.length-1]?.n==="extLst"?1:0),0,I);return K+ne(m("pivotTableDefinition",f,M)).join("")}const Vt=new Set(["extLst","location","pivotFields","rowFields","rowItems","colFields","colItems","pageFields","dataFields","pivotTableStyleInfo","filters"]);function ie(t,e){for(let s=1;;s++){const a=e(s);if(!t.has(a))return t.add(a),a}}function tn(t){const e=t.map(s=>`<Relationship Id="${s.id}" Type="${s.type}" Target="${J(s.target)}"/>`).join("");return`${K}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${e}</Relationships>`}function nn(t,{existing:e=[],saveRecords:s=!0,numFmtId:a,refreshOnLoad:n=!0,firstCacheId:l=1}={}){const o=new Set(e),c=[],r=[],i=[],d=[],p=new Map;let f=l;const u=w=>{c.push(w),i.push({partName:`/${w.name}`,contentType:w.contentType})},h=({result:w,cache:b})=>(w||b.load(),w||!b.deferred),g=t.filter(w=>(w.dirty||!w.part)&&h(w)),x=[];for(const w of t)!w.dirty||!w.part||g.includes(w)||(x.push(w.part),w.part=null);const T=new Set(t.filter(w=>!g.includes(w)&&w.part).map(w=>w.cache));for(const w of g){const{cache:b}=w;w.part&&x.push(w.part),b.part&&!T.has(b)&&(x.push(b.part),b.part=null);let v=p.get(b);if(v===void 0){const N=f++,D=ie(o,R=>`xl/pivotCache/pivotCacheDefinition${R}.xml`);b.id=N;let P=null;if(s&&b.recordCount>0){const R=ie(o,O=>`xl/pivotCache/pivotCacheRecords${O}.xml`);P="rId1",r.push({from:D,id:P,type:_.records,target:`/${R}`}),u({name:R,contentType:ee.records,large:!0,produce:O=>Oe(b,O)})}const k={name:D,contentType:ee.definition,xml:null};u(k),v={cacheId:N,defName:D,defPart:k,recordsRel:P},p.set(b,v),d.push({cacheId:N,target:`/${D}`,type:_.definition})}w.result||w.update();const F=ie(o,N=>`xl/pivotTables/pivotTable${N}.xml`);u({name:F,contentType:ee.table,xml:Ht(w,{cacheId:v.cacheId,numFmtId:a})}),r.push({from:F,id:"rId1",type:_.definition,target:`/${v.defName}`}),r.push({from:null,sheet:w.anchor?.sheet??null,id:null,type:_.table,target:`/${F}`}),w.part=F}for(const[w,b]of p)b.defPart.xml=Ct(w,{recordsRel:b.recordsRel,numFmtId:a,refreshOnLoad:n});return{parts:c,relationships:r,contentTypes:i,replaced:x,workbook:{pivotCaches:d,pivotCachesXml(w){return d.length===0?"":`<pivotCaches>${d.map(b=>`<pivotCache cacheId="${b.cacheId}" r:id="${w(b.cacheId)}"/>`).join("")}</pivotCaches>`}}}}export{ee as CONTENT_TYPE,pt as CacheRecordsReader,We as EMPTY,Ye as ERRORS,Ie as NodeReader,_ as REL_TYPE,et as XlError,nn as buildPivotPackage,Ct as cacheDefinitionXml,wt as cacheFromXml,W as isoToSerial,Ne as parseNode,vt as pivotFromXml,Ht as pivotTableXml,ht as readCacheDefinition,mt as readCacheRecords,zt as readPivotParts,en as recordsBlob,tn as relationshipsXml,H as serialToIso,ne as serializeNode,Oe as writeCacheRecords};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{cellRef as E}from"../core/address.js";const y=10,d=13,g=64,w="10px Arial, 'Liberation Sans', Helvetica, sans-serif";function u(t){let e=0;for(const o of t)e+=/[ilj.,:;'|!]/.test(o)?.28:/[MWmw@%]/.test(o)?.86:/[A-Z]/.test(o)?.68:o.codePointAt(0)>11903?1:.56;return e*y}function M(t,e){const o=[];for(const s of t.split(/\r?\n/)){let r="";for(const n of s.split(/(?<=\s)/)){let l=n;for(r&&u(r+l.trimEnd())>e&&(o.push(r.trimEnd()),r="");u(l.trimEnd())>e&&l.length>1;){let i=1;for(;i<l.length&&u(l.slice(0,i+1))<=e;)i++;o.push(l.slice(0,i)),l=l.slice(i)}r+=l}o.push(r.trimEnd())}return o}function N(t,e,o){if(!o.author?.startsWith("tc="))return o.text??"";const s=o.author.slice(3),r=new Map((t?.persons??[]).map(n=>[n.id,n.displayName]));return(e.threads??[]).filter(n=>n.id===s||n.parentId===s).map(n=>[r.get(n.personId)??n.author,n.text].filter(Boolean).join(": ")).join(`
|
|
2
|
+
`)}function I(t,e,o,s){const r=[];for(const[f,a]of e.comments??[]){const c=Math.floor(f/16384),p=f-c*16384;(o===null||o.some(h=>c>=h.r0&&c<=h.r1&&p>=h.c0&&p<=h.c1))&&r.push({row:c,col:p,text:N(t,e,a)})}r.sort((f,a)=>f.row-a.row||f.col-a.col);const n=Math.max(1,Math.floor(s.h/d)),l=[];let i=null;const m=f=>{(i===null||i.length>=n)&&l.push(i=[]),i.push(f)};for(const{row:f,col:a,text:c}of r)i?.length&&m({label:"",text:""}),M(c,Math.max(40,s.w-g)).forEach((p,h)=>m({label:h===0?E(f,a):"",text:p}));return l}function P(t,e){t.save(),t.translate(e.originX,e.originY),t.beginPath(),t.rect(0,0,e.bodyW,e.bodyH),t.clip(),t.fillStyle="#000000",t.textAlign="left",t.textBaseline="alphabetic",e.noteLines.forEach(({label:o,text:s},r)=>{const n=(r+1)*d-3;o&&(t.font=`bold ${w}`,t.fillText(o,0,n)),s&&(t.font=w,t.fillText(s,g,n))}),t.restore()}export{I as notePages,P as paintNotePage};
|
package/print/paginate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CHUNK_MASK as P,CONTENT_MASK as z}from"../core/sheet.js";import{MAX_COLS as E,MAX_ROWS as X}from"../core/address.js";import{getPageSetup as D,paperDimensions as F}from"./page-setup.js";const K=16,I=10,q=100;function L(c){return Math.max(22,String(c+1).length*7+6)}function J(c,t,s=null){let e=-1,n=-1;const o=t?.list,i=r=>{if(r===0||!o)return!1;const l=o[r];return l!==void 0&&(l.fill!==null||l.borders!==null)};for(let r=c.columns.length-1;r>=0;r--){const l=c.columns[r];if(l===void 0)continue;const a=U(l,e,i);a<0||(a>e&&(e=a),r>n&&(n=r))}s&&(s.r1>e&&(e=s.r1),s.c1>n&&(n=s.c1));for(const r of c.merges??[])r.r0<=e&&r.c0<=n&&(r.r1>e&&(e=r.r1),r.c1>n&&(n=r.c1));return{maxRow:e,maxCol:n}}function U(c,t,s){for(let e=c.length-1;e>=0;e--){const n=e*(P+1);if(n+P<=t)return-1;const o=c[e];if(o===void 0)continue;const{kinds:i,styles:r}=o;for(let l=P;l>=0;l--)if((i[l]&z)!==0||r!==null&&s(r[l]))return n+l}return-1}function H(c,t,s=c.length){let e=0,n=s;for(;e<n;){const o=e+n>>>1;c[o]<t?e=o+1:n=o}return e}const W=(c,t)=>{const s=c.length-1,e=H(c,t+1)-1;return e<0||e>=s?-1:e};function Y(c,t,s,e,n,o,i,r=1/0){let l=new Int32Array(64),a=0;const h=x=>{if(a===l.length){const p=new Int32Array(l.length*2);p.set(l),l=p}l[a++]=x},w=c.offsetOf(s+1);let u=t,f=i?H(i,t+1):0;const g=i?i.length:0;for(;u<=s;){const x=c.offsetOf(u);if(w-x<=0)break;if(a>=r)return null;h(u);const p=n!==null&&u>n[1],C=Math.max(1,p?e-o:e);let d;for(w-x<=C?d=s+1:(d=c.indexAt(x+C),d<=u&&(d=u+1),d>s+1&&(d=s+1));f<g&&i[f]<=u;)f++;f<g&&i[f]<d&&(d=i[f]),u=d}return h(s+1),l.slice(0,a)}const B=(c,t,s)=>c.offsetOf(s+1)-c.offsetOf(t);function G(c,t,s={}){return new V(c,t,s)}class V{constructor(t,s,e){this.book=t,this.sheet=s,this.cols=e.cols??s.cols,this.setup=e.setup??D(s);const{setup:n}=this;this.paper=F(s.isChartSheet&&n.orientation==="default"?{...n,orientation:"landscape"}:n,e.fallbackPaper);const o=n.margins;if(this.box={x:o.left*72,y:o.top*72,w:Math.max(1,this.paper.width-(o.left+o.right)*72),h:Math.max(1,this.paper.height-(o.top+o.bottom)*72)},s.isChartSheet){this.areas=[],this.percent=100,this.scale=1,this.headingW=0,this.headingH=0,this.layouts=[],this._firsts=[],this.pageCount=1;return}const i=e.areas??(e.ignorePrintArea?[]:n.printAreas),r=i.length===0&&!e.ignorePrintArea?s.defaultPrintAreas?.()??i:i,a=r.length===0||r.some(f=>f.r0===0&&f.r1===X-1||f.c0===0&&f.c1===E-1)?J(s,t?.styles,e.objectExtent??null):null;this.areas=Z(r,a);let h=0;for(const f of this.areas)f.r1>h&&(h=f.r1);this.headingW=n.headings?L(h):0,this.headingH=n.headings?K:0;const{rows:w}=s,{cols:u}=this;this.titleRows=n.titleRows?[n.titleRows.r0,n.titleRows.r1]:null,this.titleCols=n.titleCols?[n.titleCols.c0,n.titleCols.c1]:null,this.titleH=this.titleRows?B(w,this.titleRows[0],this.titleRows[1]):0,this.titleW=this.titleCols?B(u,this.titleCols[0],this.titleCols[1]):0,this.useManualBreaks=!n.fitToPage,this.percent=n.fitToPage?this._fitPercent():Q(n.scale),this.scale=this.percent/100,this._layout()}_roomW(t){return this.box.w/t-this.headingW}_roomH(t){return this.box.h/t-this.headingH}_colBands(t,s,e=1/0){const n=this._roomW(s),o=this.titleCols!==null&&this.titleW<n?this.titleCols:null;return{title:o,starts:Y(this.cols,t.c0,t.c1,n,o,this.titleW,this.useManualBreaks?this.setup.colBreaks:null,e)}}_rowBands(t,s,e=1/0){const n=this._roomH(s),o=this.titleRows!==null&&this.titleH<n?this.titleRows:null;return{title:o,starts:Y(this.sheet.rows,t.r0,t.r1,n,o,this.titleH,this.useManualBreaks?this.setup.rowBreaks:null,e)}}bandsOver(t,s,e){const n=t==="col"?{c0:s,c1:e}:{r0:s,r1:e};return t==="col"?this._colBands(n,this.scale):this._rowBands(n,this.scale)}_fitPercent(){const{setup:t,sheet:s}=this,e=t.fitToWidth>0?t.fitToWidth:1/0,n=t.fitToHeight>0?t.fitToHeight:1/0;if(e===1/0&&n===1/0)return q;const o=l=>this.areas.every(a=>(e===1/0||this._colBands(a,l/100,e).starts!==null)&&(n===1/0||this._rowBands(a,l/100,n).starts!==null));let i=q;for(const l of this.areas){const a=B(this.cols,l.c0,l.c1)+this.headingW,h=B(s.rows,l.r0,l.r1)+this.headingH;e!==1/0&&a>0&&(i=Math.min(i,Math.ceil(100*e*this.box.w/a))),n!==1/0&&h>0&&(i=Math.min(i,Math.ceil(100*n*this.box.h/h)))}if(i=Math.max(I,i),o(i))return i;let r=I;if(!o(r))return I;for(;i-r>1;){const l=r+i>>>1;o(l)?r=l:i=l}return r}_layout(){this.layouts=[];let t=0;for(let s=0;s<this.areas.length;s++){const e=this.areas[s],n=this._rowBands(e,this.scale),o=this._colBands(e,this.scale),i=n.starts.length-1,r=o.starts.length-1,l=i*r;l!==0&&(this.layouts.push({area:e,areaIndex:s,rows:n.starts,cols:o.starts,titleRows:n.title,titleCols:o.title,nRows:i,nCols:r,first:t,count:l}),t+=l)}this.pageCount=t,this._firsts=this.layouts.map(s=>s.first)}_layoutOf(t){return this.layouts[Math.max(0,H(this._firsts,t+1)-1)]}_seq(t,s,e){return this.setup.pageOrder==="overThenDown"?s*t.nCols+e:e*t.nRows+s}page(t){if(t<0||t>=this.pageCount)return null;if(this.sheet.isChartSheet)return this._chartPage(t);const s=this._layoutOf(t),e=t-s.first;let n,o;this.setup.pageOrder==="overThenDown"?(n=Math.floor(e/s.nCols),o=e%s.nCols):(o=Math.floor(e/s.nRows),n=e%s.nRows);const{sheet:i,setup:r,scale:l,box:a}=this,h=s.rows[n],w=s.rows[n+1]-1,u=s.cols[o],f=s.cols[o+1]-1,g=s.titleRows!==null&&h>s.titleRows[1]?{r0:s.titleRows[0],r1:s.titleRows[1]}:null,x=s.titleCols!==null&&u>s.titleCols[1]?{c0:s.titleCols[0],c1:s.titleCols[1]}:null,p=x?this.titleW:0,C=g?this.titleH:0,d=B(this.cols,u,f),M=B(i.rows,h,w),b=(this.headingW+p+d)*l,O=(this.headingH+C+M)*l,_=a.x+(r.horizontalCentered?Math.max(0,(a.w-b)/2):0),R=a.y+(r.verticalCentered?Math.max(0,(a.h-O)/2):0);return{index:t,areaIndex:s.areaIndex,area:s.area,rowBand:n,colBand:o,r0:h,r1:w,c0:u,c1:f,titleRows:g,titleCols:x,titleW:p,titleH:C,bodyW:d,bodyH:M,headingW:this.headingW,headingH:this.headingH,scale:l,paperW:this.paper.width,paperH:this.paper.height,originX:_,originY:R,contentW:b,contentH:O}}_chartPage(t){const{box:s,paper:e}=this;return{index:t,chartBox:{x:3,y:3,w:Math.max(1,s.w-7),h:Math.max(1,s.h-7)},areaIndex:0,area:{r0:0,c0:0,r1:0,c1:0},rowBand:0,colBand:0,r0:0,r1:0,c0:0,c1:0,titleRows:null,titleCols:null,titleW:0,titleH:0,bodyW:s.w,bodyH:s.h,headingW:0,headingH:0,scale:1,paperW:e.width,paperH:e.height,originX:s.x,originY:s.y,contentW:s.w,contentH:s.h}}pageAt(t,s){for(const e of this.layouts){const{area:n}=e;if(t<n.r0||t>n.r1||s<n.c0||s>n.c1)continue;const o=W(e.rows,t),i=W(e.cols,s);if(!(o<0||i<0))return e.first+this._seq(e,o,i)}return-1}cellOnPage(t,s,e){const{sheet:n}=this,o=(l,a,h,w,u,f,g)=>a>=h&&a<=w?g+f+l.offsetOf(a)-l.offsetOf(h):u&&a>=u[0]&&a<=u[1]?g+l.offsetOf(a)-l.offsetOf(u[0]):null,i=o(n.rows,s,t.r0,t.r1,t.titleRows&&[t.titleRows.r0,t.titleRows.r1],t.titleH,t.headingH),r=o(this.cols,e,t.c0,t.c1,t.titleCols&&[t.titleCols.c0,t.titleCols.c1],t.titleW,t.headingW);return r===null||i===null?null:{x:t.originX+r*t.scale,y:t.originY+i*t.scale,w:this.cols.sizeOf(e)*t.scale,h:n.rows.sizeOf(s)*t.scale}}cellAtPoint(t,s,e){const{sheet:n}=this,o=(s-t.originX)/t.scale-t.headingW,i=(e-t.originY)/t.scale-t.headingH;if(o<0||i<0||o>=t.titleW+t.bodyW||i>=t.titleH+t.bodyH)return null;const r=i<t.titleH?n.rows.indexAt(n.rows.offsetOf(t.titleRows.r0)+i):n.rows.indexAt(n.rows.offsetOf(t.r0)+i-t.titleH),l=o<t.titleW?this.cols.indexAt(this.cols.offsetOf(t.titleCols.c0)+o):this.cols.indexAt(this.cols.offsetOf(t.c0)+o-t.titleW);return{row:r,col:l}}breakPreview(t){const{sheet:s,setup:e}=this,{rows:n}=s,{cols:o}=this,i={scale:this.scale,percent:this.percent,areas:[],rowBreaks:[],colBreaks:[],pages:[]},r=this.useManualBreaks?e.rowBreaks:[],l=this.useManualBreaks?e.colBreaks:[],a=(h,w)=>{const u=H(h,w);return u<h.length&&h[u]===w};for(const h of this.layouts){const{area:w}=h,u=o.offsetOf(w.c0),f=o.offsetOf(w.c1+1),g=n.offsetOf(w.r0),x=n.offsetOf(w.r1+1);i.areas.push({...w,x:u,y:g,w:f-u,h:x-g});const p=Math.max(t.r0,w.r0),C=Math.min(t.r1,w.r1),d=Math.max(t.c0,w.c0),M=Math.min(t.c1,w.c1);if(p>C||d>M)continue;const b=Math.max(0,W(h.rows,p)),O=Math.max(b,W(h.rows,C)),_=Math.max(0,W(h.cols,d)),R=Math.max(_,W(h.cols,M));for(let m=b;m<=O;m++){const y=h.rows[m];m!==0&&i.rowBreaks.push({row:y,y:n.offsetOf(y),x0:u,x1:f,manual:a(r,y)})}for(let m=_;m<=R;m++){const y=h.cols[m];m!==0&&i.colBreaks.push({col:y,x:o.offsetOf(y),y0:g,y1:x,manual:a(l,y)})}for(let m=b;m<=O;m++)for(let y=_;y<=R;y++){const A=h.rows[m],k=h.rows[m+1]-1,v=h.cols[y],N=h.cols[y+1]-1,T=o.offsetOf(v),S=n.offsetOf(A);i.pages.push({index:h.first+this._seq(h,m,y),r0:A,r1:k,c0:v,c1:N,x:T,y:S,w:o.offsetOf(N+1)-T,h:n.offsetOf(k+1)-S})}}return i}pageLayoutView({gap:t=18}={}){const{paper:s}=this,e=s.width,n=s.height,o=e+t,i=n+t,r=[];let l=0,a=0;for(const f of this.layouts)r.push({layout:f,y:l}),l+=f.nRows*i,a=Math.max(a,f.nCols*o-t);const h=Math.max(0,l-t);return{width:a,height:h,rectOf:f=>{const g=this.page(f);if(!g)return null;const x=r[H(this._firsts,f+1)-1];return{index:f,x:g.colBand*o,y:x.y+g.rowBand*i,w:e,h:n}},visible:(f,g,x,p)=>{const C=[];for(const{layout:d,y:M}of r){const b=Math.max(0,Math.floor((g-M)/i)),O=Math.min(d.nRows-1,Math.floor((p-M)/i)),_=Math.max(0,Math.floor(f/o)),R=Math.min(d.nCols-1,Math.floor(x/o));for(let m=b;m<=O;m++)for(let y=_;y<=R;y++)C.push({index:d.first+this._seq(d,m,y),x:y*o,y:M+m*i,w:e,h:n})}return C}}}}function Q(c){const t=Math.round(Number(c)||100);return Math.min(400,Math.max(10,t))}function Z(c,t){const s=[];if(c.length===0)return t.maxRow>=0&&t.maxCol>=0&&s.push({r0:0,c0:0,r1:t.maxRow,c1:t.maxCol}),s;for(const e of c){let{r0:n,c0:o,r1:i,c1:r}=e;n===0&&i===X-1&&(i=Math.max(t.maxRow,0)),o===0&&r===E-1&&(r=Math.max(t.maxCol,0)),i>=n&&r>=o&&s.push({r0:n,c0:o,r1:i,c1:r})}return s}function et(c,t={}){let s;Array.isArray(t.sheets)?s=t.sheets:t.sheets==="all"?s=c.sheets.map((i,r)=>i.hidden?-1:r).filter(i=>i>=0):s=[c.activeSheet];const e=[];let n=0,o=1;for(const i of s){const r=c.sheets[i],l=G(c,r,{setup:t.setups?.get(r),areas:i===c.activeSheet?t.areas:void 0,ignorePrintArea:t.ignorePrintArea,objectExtent:t.objectExtents?.get(r),fallbackPaper:t.fallbackPaper});l.setup.useFirstPageNumber&&(o=l.setup.firstPageNumber),e.push({sheet:r,sheetIndex:i,pagination:l,first:n,firstNumber:o}),n+=l.pageCount,o+=l.pageCount}return new $(c,e,n)}class ${constructor(t,s,e){this.book=t,this.entries=s,this.pageCount=e,this._firsts=s.map(n=>n.first)}entryOf(t){let s=H(this._firsts,t+1)-1;for(;s>0&&this.entries[s].pagination.pageCount===0;)s--;return this.entries[Math.max(0,s)]}at(t){if(t<0||t>=this.pageCount)return null;const s=this.entryOf(t),e=t-s.first;return{index:t,sheet:s.sheet,sheetIndex:s.sheetIndex,pagination:s.pagination,page:s.pagination.page(e),sheetPage:e,pageNumber:s.firstNumber+e,totalPages:this.pageCount}}firstPageOf(t){const s=this.entries.find(e=>e.sheetIndex===t);return s&&s.pagination.pageCount>0?s.first:-1}}export{V as Pagination,$ as PrintJob,et as createPrintJob,H as lowerBound,G as paginate,J as printedExtent};
|
|
1
|
+
import{notePages as z}from"./note-pages.js";import{CHUNK_MASK as B,CONTENT_MASK as D}from"../core/sheet.js";import{MAX_COLS as E,MAX_ROWS as X}from"../core/address.js";import{getPageSetup as L,paperDimensions as F}from"./page-setup.js";const K=16,A=10,Y=100;function J(c){return Math.max(22,String(c+1).length*7+6)}function U(c,t,s=null){let e=-1,n=-1;const o=t?.list,i=r=>{if(r===0||!o)return!1;const l=o[r];return l!==void 0&&(l.fill!==null||l.borders!==null)};for(let r=c.columns.length-1;r>=0;r--){const l=c.columns[r];if(l===void 0)continue;const a=G(l,e,i);a<0||(a>e&&(e=a),r>n&&(n=r))}s&&(s.r1>e&&(e=s.r1),s.c1>n&&(n=s.c1));for(const r of c.merges??[])r.r0<=e&&r.c0<=n&&(r.r1>e&&(e=r.r1),r.c1>n&&(n=r.c1));return{maxRow:e,maxCol:n}}function G(c,t,s){for(let e=c.length-1;e>=0;e--){const n=e*(B+1);if(n+B<=t)return-1;const o=c[e];if(o===void 0)continue;const{kinds:i,styles:r}=o;for(let l=B;l>=0;l--)if((i[l]&D)!==0||r!==null&&s(r[l]))return n+l}return-1}function R(c,t,s=c.length){let e=0,n=s;for(;e<n;){const o=e+n>>>1;c[o]<t?e=o+1:n=o}return e}const H=(c,t)=>{const s=c.length-1,e=R(c,t+1)-1;return e<0||e>=s?-1:e};function q(c,t,s,e,n,o,i,r=1/0){let l=new Int32Array(64),a=0;const h=p=>{if(a===l.length){const x=new Int32Array(l.length*2);x.set(l),l=x}l[a++]=p},w=c.offsetOf(s+1);let u=t,f=i?R(i,t+1):0;const m=i?i.length:0;for(;u<=s;){const p=c.offsetOf(u);if(w-p<=0)break;if(a>=r)return null;h(u);const x=n!==null&&u>n[1],b=Math.max(1,x?e-o:e);let d;for(w-p<=b?d=s+1:(d=c.indexAt(p+b),d<=u&&(d=u+1),d>s+1&&(d=s+1));f<m&&i[f]<=u;)f++;f<m&&i[f]<d&&(d=i[f]),u=d}return h(s+1),l.slice(0,a)}const W=(c,t,s)=>c.offsetOf(s+1)-c.offsetOf(t);function V(c,t,s={}){return new Q(c,t,s)}class Q{constructor(t,s,e){this.book=t,this.sheet=s,this.cols=e.cols??s.cols,this.setup=e.setup??L(s);const{setup:n}=this;this.paper=F(s.isChartSheet&&n.orientation==="default"?{...n,orientation:"landscape"}:n,e.fallbackPaper);const o=n.margins;if(this.box={x:o.left*72,y:o.top*72,w:Math.max(1,this.paper.width-(o.left+o.right)*72),h:Math.max(1,this.paper.height-(o.top+o.bottom)*72)},s.isChartSheet){this.areas=[],this.percent=100,this.scale=1,this.headingW=0,this.headingH=0,this.layouts=[],this._firsts=[],this.pageCount=1;return}const i=e.areas??(e.ignorePrintArea?[]:n.printAreas),r=i.length===0&&!e.ignorePrintArea?s.defaultPrintAreas?.()??i:i,a=r.length===0||r.some(f=>f.r0===0&&f.r1===X-1||f.c0===0&&f.c1===E-1)?U(s,t?.styles,e.objectExtent??null):null;this.areas=$(r,a),this.givenAreas=r.length>0?this.areas:null;let h=0;for(const f of this.areas)f.r1>h&&(h=f.r1);this.headingW=n.headings?J(h):0,this.headingH=n.headings?K:0;const{rows:w}=s,{cols:u}=this;this.titleRows=n.titleRows?[n.titleRows.r0,n.titleRows.r1]:null,this.titleCols=n.titleCols?[n.titleCols.c0,n.titleCols.c1]:null,this.titleH=this.titleRows?W(w,this.titleRows[0],this.titleRows[1]):0,this.titleW=this.titleCols?W(u,this.titleCols[0],this.titleCols[1]):0,this.useManualBreaks=!n.fitToPage,this.percent=n.fitToPage?this._fitPercent():Z(n.scale),this.scale=this.percent/100,this._layout()}_roomW(t){return this.box.w/t-this.headingW}_roomH(t){return this.box.h/t-this.headingH}_colBands(t,s,e=1/0){const n=this._roomW(s),o=this.titleCols!==null&&this.titleW<n?this.titleCols:null;return{title:o,starts:q(this.cols,t.c0,t.c1,n,o,this.titleW,this.useManualBreaks?this.setup.colBreaks:null,e)}}_rowBands(t,s,e=1/0){const n=this._roomH(s),o=this.titleRows!==null&&this.titleH<n?this.titleRows:null;return{title:o,starts:q(this.sheet.rows,t.r0,t.r1,n,o,this.titleH,this.useManualBreaks?this.setup.rowBreaks:null,e)}}bandsOver(t,s,e){const n=t==="col"?{c0:s,c1:e}:{r0:s,r1:e};return t==="col"?this._colBands(n,this.scale):this._rowBands(n,this.scale)}_fitPercent(){const{setup:t,sheet:s}=this,e=t.fitToWidth>0?t.fitToWidth:1/0,n=t.fitToHeight>0?t.fitToHeight:1/0;if(e===1/0&&n===1/0)return Y;const o=l=>this.areas.every(a=>(e===1/0||this._colBands(a,l/100,e).starts!==null)&&(n===1/0||this._rowBands(a,l/100,n).starts!==null));let i=Y;for(const l of this.areas){const a=W(this.cols,l.c0,l.c1)+this.headingW,h=W(s.rows,l.r0,l.r1)+this.headingH;e!==1/0&&a>0&&(i=Math.min(i,Math.ceil(100*e*this.box.w/a))),n!==1/0&&h>0&&(i=Math.min(i,Math.ceil(100*n*this.box.h/h)))}if(i=Math.max(A,i),o(i))return i;let r=A;if(!o(r))return A;for(;i-r>1;){const l=r+i>>>1;o(l)?r=l:i=l}return r}_layout(){this.layouts=[];let t=0;for(let s=0;s<this.areas.length;s++){const e=this.areas[s],n=this._rowBands(e,this.scale),o=this._colBands(e,this.scale),i=n.starts.length-1,r=o.starts.length-1,l=i*r;l!==0&&(this.layouts.push({area:e,areaIndex:s,rows:n.starts,cols:o.starts,titleRows:n.title,titleCols:o.title,nRows:i,nCols:r,first:t,count:l}),t+=l)}this.cellPages=t,this.notes=this.setup.cellComments==="atEnd"?z(this.book,this.sheet,this.givenAreas,this.box):[],this.pageCount=t+this.notes.length,this._firsts=this.layouts.map(s=>s.first)}_layoutOf(t){return this.layouts[Math.max(0,R(this._firsts,t+1)-1)]}_seq(t,s,e){return this.setup.pageOrder==="overThenDown"?s*t.nCols+e:e*t.nRows+s}page(t){if(t<0||t>=this.pageCount)return null;if(this.sheet.isChartSheet)return this._chartPage(t);if(t>=this.cellPages)return this._notePage(t);const s=this._layoutOf(t),e=t-s.first;let n,o;this.setup.pageOrder==="overThenDown"?(n=Math.floor(e/s.nCols),o=e%s.nCols):(o=Math.floor(e/s.nRows),n=e%s.nRows);const{sheet:i,setup:r,scale:l,box:a}=this,h=s.rows[n],w=s.rows[n+1]-1,u=s.cols[o],f=s.cols[o+1]-1,m=s.titleRows!==null&&h>s.titleRows[1]?{r0:s.titleRows[0],r1:s.titleRows[1]}:null,p=s.titleCols!==null&&u>s.titleCols[1]?{c0:s.titleCols[0],c1:s.titleCols[1]}:null,x=p?this.titleW:0,b=m?this.titleH:0,d=W(this.cols,u,f),C=W(i.rows,h,w),M=(this.headingW+x+d)*l,_=(this.headingH+b+C)*l,O=a.x+(r.horizontalCentered?Math.max(0,(a.w-M)/2):0),P=a.y+(r.verticalCentered?Math.max(0,(a.h-_)/2):0);return{index:t,areaIndex:s.areaIndex,area:s.area,rowBand:n,colBand:o,r0:h,r1:w,c0:u,c1:f,titleRows:m,titleCols:p,titleW:x,titleH:b,bodyW:d,bodyH:C,headingW:this.headingW,headingH:this.headingH,scale:l,paperW:this.paper.width,paperH:this.paper.height,originX:O,originY:P,contentW:M,contentH:_}}_notePage(t){const{box:s}=this;return{...this._chartPage(t),chartBox:void 0,noteLines:this.notes[t-this.cellPages],originX:s.x,originY:s.y,bodyW:s.w,bodyH:s.h}}_chartPage(t){const{box:s,paper:e}=this;return{index:t,chartBox:{x:3,y:3,w:Math.max(1,s.w-7),h:Math.max(1,s.h-7)},areaIndex:0,area:{r0:0,c0:0,r1:0,c1:0},rowBand:0,colBand:0,r0:0,r1:0,c0:0,c1:0,titleRows:null,titleCols:null,titleW:0,titleH:0,bodyW:s.w,bodyH:s.h,headingW:0,headingH:0,scale:1,paperW:e.width,paperH:e.height,originX:s.x,originY:s.y,contentW:s.w,contentH:s.h}}pageAt(t,s){for(const e of this.layouts){const{area:n}=e;if(t<n.r0||t>n.r1||s<n.c0||s>n.c1)continue;const o=H(e.rows,t),i=H(e.cols,s);if(!(o<0||i<0))return e.first+this._seq(e,o,i)}return-1}cellOnPage(t,s,e){const{sheet:n}=this,o=(l,a,h,w,u,f,m)=>a>=h&&a<=w?m+f+l.offsetOf(a)-l.offsetOf(h):u&&a>=u[0]&&a<=u[1]?m+l.offsetOf(a)-l.offsetOf(u[0]):null,i=o(n.rows,s,t.r0,t.r1,t.titleRows&&[t.titleRows.r0,t.titleRows.r1],t.titleH,t.headingH),r=o(this.cols,e,t.c0,t.c1,t.titleCols&&[t.titleCols.c0,t.titleCols.c1],t.titleW,t.headingW);return r===null||i===null?null:{x:t.originX+r*t.scale,y:t.originY+i*t.scale,w:this.cols.sizeOf(e)*t.scale,h:n.rows.sizeOf(s)*t.scale}}cellAtPoint(t,s,e){const{sheet:n}=this,o=(s-t.originX)/t.scale-t.headingW,i=(e-t.originY)/t.scale-t.headingH;if(o<0||i<0||o>=t.titleW+t.bodyW||i>=t.titleH+t.bodyH)return null;const r=i<t.titleH?n.rows.indexAt(n.rows.offsetOf(t.titleRows.r0)+i):n.rows.indexAt(n.rows.offsetOf(t.r0)+i-t.titleH),l=o<t.titleW?this.cols.indexAt(this.cols.offsetOf(t.titleCols.c0)+o):this.cols.indexAt(this.cols.offsetOf(t.c0)+o-t.titleW);return{row:r,col:l}}breakPreview(t){const{sheet:s,setup:e}=this,{rows:n}=s,{cols:o}=this,i={scale:this.scale,percent:this.percent,areas:[],rowBreaks:[],colBreaks:[],pages:[]},r=this.useManualBreaks?e.rowBreaks:[],l=this.useManualBreaks?e.colBreaks:[],a=(h,w)=>{const u=R(h,w);return u<h.length&&h[u]===w};for(const h of this.layouts){const{area:w}=h,u=o.offsetOf(w.c0),f=o.offsetOf(w.c1+1),m=n.offsetOf(w.r0),p=n.offsetOf(w.r1+1);i.areas.push({...w,x:u,y:m,w:f-u,h:p-m});const x=Math.max(t.r0,w.r0),b=Math.min(t.r1,w.r1),d=Math.max(t.c0,w.c0),C=Math.min(t.c1,w.c1);if(x>b||d>C)continue;const M=Math.max(0,H(h.rows,x)),_=Math.max(M,H(h.rows,b)),O=Math.max(0,H(h.cols,d)),P=Math.max(O,H(h.cols,C));for(let g=M;g<=_;g++){const y=h.rows[g];g!==0&&i.rowBreaks.push({row:y,y:n.offsetOf(y),x0:u,x1:f,manual:a(r,y)})}for(let g=O;g<=P;g++){const y=h.cols[g];g!==0&&i.colBreaks.push({col:y,x:o.offsetOf(y),y0:m,y1:p,manual:a(l,y)})}for(let g=M;g<=_;g++)for(let y=O;y<=P;y++){const I=h.rows[g],k=h.rows[g+1]-1,v=h.cols[y],N=h.cols[y+1]-1,T=o.offsetOf(v),S=n.offsetOf(I);i.pages.push({index:h.first+this._seq(h,g,y),r0:I,r1:k,c0:v,c1:N,x:T,y:S,w:o.offsetOf(N+1)-T,h:n.offsetOf(k+1)-S})}}return i}pageLayoutView({gap:t=18}={}){const{paper:s}=this,e=s.width,n=s.height,o=e+t,i=n+t,r=[];let l=0,a=0;for(const f of this.layouts)r.push({layout:f,y:l}),l+=f.nRows*i,a=Math.max(a,f.nCols*o-t);const h=Math.max(0,l-t);return{width:a,height:h,rectOf:f=>{const m=this.page(f);if(!m)return null;const p=r[R(this._firsts,f+1)-1];return{index:f,x:m.colBand*o,y:p.y+m.rowBand*i,w:e,h:n}},visible:(f,m,p,x)=>{const b=[];for(const{layout:d,y:C}of r){const M=Math.max(0,Math.floor((m-C)/i)),_=Math.min(d.nRows-1,Math.floor((x-C)/i)),O=Math.max(0,Math.floor(f/o)),P=Math.min(d.nCols-1,Math.floor(p/o));for(let g=M;g<=_;g++)for(let y=O;y<=P;y++)b.push({index:d.first+this._seq(d,g,y),x:y*o,y:C+g*i,w:e,h:n})}return b}}}}function Z(c){const t=Math.round(Number(c)||100);return Math.min(400,Math.max(10,t))}function $(c,t){const s=[];if(c.length===0)return t.maxRow>=0&&t.maxCol>=0&&s.push({r0:0,c0:0,r1:t.maxRow,c1:t.maxCol}),s;for(const e of c){let{r0:n,c0:o,r1:i,c1:r}=e;n===0&&i===X-1&&(i=Math.max(t.maxRow,0)),o===0&&r===E-1&&(r=Math.max(t.maxCol,0)),i>=n&&r>=o&&s.push({r0:n,c0:o,r1:i,c1:r})}return s}function ot(c,t={}){let s;Array.isArray(t.sheets)?s=t.sheets:t.sheets==="all"?s=c.sheets.map((i,r)=>i.hidden?-1:r).filter(i=>i>=0):s=[c.activeSheet];const e=[];let n=0,o=1;for(const i of s){const r=c.sheets[i],l=V(c,r,{setup:t.setups?.get(r),areas:i===c.activeSheet?t.areas:void 0,ignorePrintArea:t.ignorePrintArea,objectExtent:t.objectExtents?.get(r),fallbackPaper:t.fallbackPaper});l.setup.useFirstPageNumber&&(o=l.setup.firstPageNumber),e.push({sheet:r,sheetIndex:i,pagination:l,first:n,firstNumber:o}),n+=l.pageCount,o+=l.pageCount}return new j(c,e,n)}class j{constructor(t,s,e){this.book=t,this.entries=s,this.pageCount=e,this._firsts=s.map(n=>n.first)}entryOf(t){let s=R(this._firsts,t+1)-1;for(;s>0&&this.entries[s].pagination.pageCount===0;)s--;return this.entries[Math.max(0,s)]}at(t){if(t<0||t>=this.pageCount)return null;const s=this.entryOf(t),e=t-s.first;return{index:t,sheet:s.sheet,sheetIndex:s.sheetIndex,pagination:s.pagination,page:s.pagination.page(e),sheetPage:e,pageNumber:s.firstNumber+e,totalPages:this.pageCount}}firstPageOf(t){const s=this.entries.find(e=>e.sheetIndex===t);return s&&s.pagination.pageCount>0?s.first:-1}}export{Q as Pagination,j as PrintJob,ot as createPrintJob,R as lowerBound,V as paginate,U as printedExtent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{parseRangeRef as R,unquoteSheetName as B}from"../core/address.js";import{FORMULA as C}from"../core/sheet.js";import{formulaLink as E}from"../cells/link-model.js";const F=/^(https?:|mailto:|ftp:|tel:)/i;function $(f,r,n,l=0){const a=String(n??"").replace(/^[#=]/,"").trim(),c=a.lastIndexOf("!"),i=R(a.slice(c+1).replace(/\$/g,""));if(i){if(c<0)return{sheet:r,row:i.r0,col:i.c0};const w=B(a.slice(0,c)).toLowerCase(),m=f.sheets.find(p=>p.name.toLowerCase()===w);return m?{sheet:m,row:i.r0,col:i.c0}:null}const s=l===0&&c<0?f.engine?._nameEntry(a,r)?.entry:null;return s?$(f,r,s.text,1):null}const A=new WeakMap;function S(f){const r=f.hyperlinks;if(!r?.length)return[];let n=A.get(r);return n||(n=r.flatMap(l=>(l.ref??"").split(/\s+/).map(R).filter(Boolean).map(a=>({h:l,box:a}))),A.set(r,n)),n}function v(f,r,n,l,a){const{r0:c,r1:i,c0:s,c1:w}=l,m=t=>l.x+n.cols.offsetOf(t)-n.cols.offsetOf(s),p=t=>l.y+n.rows.offsetOf(t)-n.rows.offsetOf(c),k=(t,o)=>{let{r0:e,r1:g,c0:u,c1:x}=o;const O=n.mergeAt(e,u);if(O&&(g=Math.max(g,O.r1),x=Math.max(x,O.c1)),e=Math.max(e,c),u=Math.max(u,s),g=Math.min(g,i),x=Math.min(x,w),e>g||u>x)return;const d=m(x+1)-m(u),L=p(g+1)-p(e);if(d>0&&L>0){if(t.target&&F.test(t.target))f.link(m(u),p(e),d,L,{uri:t.location?`${t.target}#${t.location}`:t.target});else if(!t.target&&t.location){const M=$(r,n,t.location),y=M?a(M.sheet,M.row,M.col):null;y&&f.link(m(u),p(e),d,L,{dest:y})}}};for(const{h:t,box:o}of S(n))o.r0<=i&&o.r1>=c&&o.c0<=w&&o.c1>=s&&k(t,o);if(n.formulas?.size>0)for(let t=c;t<=i;t++)for(let o=s;o<=w;o++){if(!(n.kind(t,o)&C))continue;const e=E(r,n,t,o);e&&k(e,{r0:t,r1:t,c0:o,c1:o})}}export{v as linkRegion,$ as resolveLocation};
|
package/print/pdf.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
const W=new TextEncoder,M=65536,J=9999999999,K=128,H=()=>{},j=[];for(let o=0;o<256;o++)j.push(o.toString(16).padStart(2,"0"));const F=o=>j[o>>8&255]+j[o&255],b=o=>String(Math.round(o*1e3)/1e3+0),A=o=>Array(10).fill(o),D={Helvetica:[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,...A(556),278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],"Helvetica-Bold":[278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,...A(556),333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584],"Times-Roman":[250,333,408,500,500,833,778,180,333,333,500,564,250,333,250,278,...A(500),278,278,564,564,564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541],"Times-Bold":[250,333,555,500,500,1e3,833,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1e3,722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520],"Times-Italic":[250,333,420,500,500,833,778,214,333,333,500,675,250,333,250,278,...A(500),333,333,675,675,675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541],"Times-BoldItalic":[250,389,555,500,500,833,778,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570]};D["Helvetica-Oblique"]=D.Helvetica,D["Helvetica-BoldOblique"]=D["Helvetica-Bold"];const Y=new Map(Object.entries({"€":[556,500],"–":[556,500],"—":[1e3,1e3],"…":[1e3,1e3],"•":[350,350],"‘":[222,333],"’":[222,333],"‚":[222,333],"“":[333,444],"”":[333,444],"„":[333,444],"†":[556,500],"‡":[556,500],"‰":[1e3,1e3],"‹":[333,333],"›":[333,333],ƒ:[556,500],"™":[1e3,980],"ˆ":[333,333],"˜":[333,333],"¡":[333,333],"¢":[556,500],"£":[556,500],"¤":[556,500],"¥":[556,500],"¦":[260,200],"§":[556,500],"¨":[333,333],"©":[737,760],ª:[370,276],"«":[556,500],"¬":[584,564],"®":[737,760],"¯":[333,333],"°":[400,400],"±":[584,564],"²":[333,300],"³":[333,300],"´":[333,333],µ:[556,500],"¶":[537,453],"·":[278,250],"¸":[333,333],"¹":[333,300],º:[365,310],"»":[556,500],"¼":[834,750],"½":[834,750],"¾":[834,750],"¿":[611,444],"×":[584,564],"÷":[584,564],Æ:[1e3,889],æ:[889,667],Œ:[1e3,889],œ:[944,722],Ø:[778,722],ø:[611,500],ß:[611,500],Ð:[722,722],ð:[556,500],Þ:[667,556],þ:[556,500]})),L="€\0‚ƒ„…†‡ˆ‰Š‹Œ\0Ž\0\0‘’“”•–—˜™š›œ\0žŸ",z=[["ą","aogonek"],["Ą","Aogonek"],["ć","cacute"],["Ć","Cacute"],["ę","eogonek"],["Ę","Eogonek"],["ł","lslash"],["Ł","Lslash"],["ń","nacute"],["Ń","Nacute"],["ś","sacute"],["Ś","Sacute"],["ź","zacute"],["Ź","Zacute"],["ż","zdotaccent"],["Ż","Zdotaccent"],["č","ccaron"],["Č","Ccaron"],["ě","ecaron"],["Ě","Ecaron"],["ř","rcaron"],["Ř","Rcaron"],["ů","uring"],["Ů","Uring"],["ő","ohungarumlaut"],["Ő","Ohungarumlaut"],["ű","uhungarumlaut"],["Ű","Uhungarumlaut"],["ň","ncaron"],["ď","dcaron"],["ť","tcaron"]],U=new Map;for(let o=32;o<127;o++)U.set(o,o);for(let o=161;o<=255;o++)U.set(o,o);for(let o=0;o<L.length;o++)L[o]!=="\0"&&U.set(L.codePointAt(o),128+o);z.forEach(([o],t)=>U.set(o.codePointAt(0),t+1));for(const o of[160,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288])U.set(o,32);for(const o of[8208,8209,173])U.set(o,45);U.set(8722,150),U.set(8213,151);const Z=/times|georgia|cambria|garamond|palatino|book antiqua|constantia|baskerville|bookman|century|minion|serif$/,Q=/sans|gothic/,tt=/courier|consolas|menlo|monaco|lucida console|lucida sans typewriter|mono/,et=/aptos narrow|calibri|carlito|arial narrow|corbel|candara/;function st(o,t,e){return tt.test(o)?`Courier${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`:Z.test(o)&&!Q.test(o)?t?e?"Times-BoldItalic":"Times-Bold":e?"Times-Italic":"Times-Roman":`Helvetica${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`}class it{constructor(t,e,s){this.name=t,this.resId=e,this.objectId=s,this.mono=t.startsWith("Courier"),this.serif=t.startsWith("Times"),this.table=D[t]??null,this.ascent=this.mono?.629:this.serif?.683:.718,this.descent=this.mono?.157:this.serif?.217:.207,this.widths=new Map}width(t){if(this.mono)return 600;if(t>=32&&t<127)return this.table[t-32];let e=this.widths.get(t);return e===void 0&&(e=this._extraWidth(t),this.widths.set(t,e)),e}_extraWidth(t){const e=String.fromCodePoint(t),s=Y.get(e);if(s)return s[this.serif?1:0];if(e==="ł")return this.table[76];if(e==="Ł")return this.table[44];const i=U.get(t);if(i===32)return this.table[0];if(i===45)return this.table[13];const n=e.normalize("NFD").codePointAt(0);return n>=32&&n<127?this.table[n-32]:this.serif?500:556}}function N(o){const t=String.fromCodePoint(o).normalize("NFD").codePointAt(0);return U.has(t)?t:63}class nt{constructor(t,e={}){this.bytes=ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.tables=this._openFace(e.postscriptName);for(const h of["head","hhea","hmtx","maxp","cmap","loca","glyf"])if(!this.tables.has(h))throw new Error(`Font has no ${h} table, so it isn't TrueType`);const s=this.view,i=this.tables.get("head").offset,n=this.tables.get("hhea").offset;this.unitsPerEm=s.getUint16(i+18)||1e3,this.bbox=[s.getInt16(i+36),s.getInt16(i+38),s.getInt16(i+40),s.getInt16(i+42)];const a=s.getUint16(i+44);this.longLoca=s.getInt16(i+50)!==0,this.ascentUnits=s.getInt16(n+4),this.descentUnits=s.getInt16(n+6),this.numHMetrics=s.getUint16(n+34),this.numGlyphs=s.getUint16(this.tables.get("maxp").offset+4),this.italicAngle=this.tables.has("post")?s.getInt32(this.tables.get("post").offset+4)/65536:0,this.capHeightUnits=this.ascentUnits;const r=this.tables.get("OS/2");if(r){if((s.getUint16(r.offset+8)&15)===2)throw new Error("Font license forbids embedding");s.getUint16(r.offset)>=2&&r.length>=90&&(this.capHeightUnits=s.getInt16(r.offset+88)||this.ascentUnits)}const l=this._names();this.family=e.family??l.family??"Embedded",this.postscriptName=(l.postscript??this.family).replace(/[^A-Za-z0-9-]/g,""),this.bold=e.bold??(a&1)!==0,this.italic=e.italic??(a&2)!==0,this.scale=1e3/this.unitsPerEm,this.ascent=this.ascentUnits/this.unitsPerEm,this.descent=-this.descentUnits/this.unitsPerEm,this.lookup=this._cmap(),this.gids=new Map,this.order=[0],this.newIds=new Map([[0,0]]),this.unicode=[],this.resId=0,this.objectId=0}_openFace(t){const e=this.view,s=e.getUint32(0);if(s===1330926671)throw new Error("OpenType/CFF fonts are not supported");if(s===1953784678){const i=e.getUint32(8);let n=null;for(let a=0;a<i;a++){const r=this._directory(e.getUint32(12+a*4));if(n===null&&(n=r),t&&this._names(r).postscript===t)return r}if(n===null)throw new Error("Empty font collection");return n}if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font");return this._directory(0)}_directory(t){const e=this.view,s=e.getUint16(t+4),i=new Map;for(let n=0;n<s;n++){const a=t+12+n*16,r=String.fromCharCode(e.getUint8(a),e.getUint8(a+1),e.getUint8(a+2),e.getUint8(a+3));i.set(r,{offset:e.getUint32(a+8),length:e.getUint32(a+12)})}return i}_names(t=this.tables){const e={},s=t.get("name");if(!s)return e;const i=this.view,n=i.getUint16(s.offset+2),a=s.offset+i.getUint16(s.offset+4);for(let r=0;r<n;r++){const l=s.offset+6+r*12,h=i.getUint16(l),c=i.getUint16(l+6);if(c!==1&&c!==6)continue;const d=i.getUint16(l+8),g=a+i.getUint16(l+10);let f="";if(h===3||h===0)for(let m=0;m+1<d;m+=2)f+=String.fromCharCode(i.getUint16(g+m));else for(let m=0;m<d;m++)f+=String.fromCharCode(i.getUint8(g+m));const u=c===1?"family":"postscript";(e[u]===void 0||h===3)&&(e[u]=f)}return e}_cmap(){const t=this.view,e=this.tables.get("cmap").offset,s=t.getUint16(e+2);let i=null,n=-1;for(let u=0;u<s;u++){const m=e+4+u*8,w=t.getUint16(m),x=t.getUint16(m+2),y=e+t.getUint32(m+4),$=t.getUint16(y);if($!==4&&$!==12&&$!==6)continue;let I=-1;w===3&&x===10?I=4:w===0&&$===12?I=3:w===3&&x===1?I=2:w===0&&(I=1),I>n&&(n=I,i={at:y,format:$})}if(i===null)throw new Error("Font has no Unicode cmap");const{at:a,format:r}=i;if(r===12){const u=t.getUint32(a+12);return m=>{let w=0,x=u-1;for(;w<=x;){const y=w+x>>>1,$=a+16+y*12;if(m<t.getUint32($))x=y-1;else if(m>t.getUint32($+4))w=y+1;else return t.getUint32($+8)+m-t.getUint32($)}return 0}}if(r===6){const u=t.getUint16(a+6),m=t.getUint16(a+8);return w=>w>=u&&w<u+m?t.getUint16(a+10+(w-u)*2):0}const l=t.getUint16(a+6),h=a+14,c=h+l+2,d=c+l,g=d+l,f=l/2;return u=>{if(u>65535)return 0;let m=0,w=f-1;for(;m<w;){const p=m+w>>>1;t.getUint16(h+p*2)<u?m=p+1:w=p}const x=t.getUint16(c+m*2);if(u<x||u>t.getUint16(h+m*2))return 0;const y=t.getInt16(d+m*2),$=t.getUint16(g+m*2);if($===0)return u+y&65535;const I=t.getUint16(g+m*2+$+(u-x)*2);return I===0?0:I+y&65535}}gidOf(t){let e=this.gids.get(t);return e===void 0&&(e=this.lookup(t),e>=this.numGlyphs&&(e=0),this.gids.set(t,e)),e}_rawAdvance(t){const e=this.tables.get("hmtx").offset;return this.view.getUint16(e+Math.min(t,this.numHMetrics-1)*4)}_rawLsb(t){const e=this.tables.get("hmtx").offset;return t<this.numHMetrics?this.view.getInt16(e+t*4+2):this.view.getInt16(e+this.numHMetrics*4+(t-this.numHMetrics)*2)}width(t){return this._rawAdvance(this.gidOf(t))*this.scale}_newId(t){let e=this.newIds.get(t);return e===void 0&&(e=this.order.length,this.order.push(t),this.newIds.set(t,e)),e}use(t){const e=this._newId(this.gidOf(t));return this.unicode[e]===void 0&&(this.unicode[e]=t),e}_glyphRange(t){const e=this.tables.get("loca").offset,s=this.tables.get("glyf").offset,i=this.view,n=this.longLoca?i.getUint32(e+t*4):i.getUint16(e+t*2)*2,a=this.longLoca?i.getUint32(e+(t+1)*4):i.getUint16(e+(t+1)*2)*2;return[s+n,a-n]}_copyTable(t){const e=this.tables.get(t);return e?this.bytes.slice(e.offset,e.offset+e.length):null}subset(){const t=[];for(let p=0;p<this.order.length;p++){const[_,T]=this._glyphRange(this.order[p]);if(T<=0){t.push(null);continue}const k=this.bytes.slice(_,_+T),C=new DataView(k.buffer);if(C.getInt16(0)<0){let S=10;for(;;){const v=C.getUint16(S);if(C.setUint16(S+2,this._newId(C.getUint16(S+2))),S+=4+(v&1?4:2),v&8?S+=2:v&64?S+=4:v&128&&(S+=8),!(v&32))break}}t.push(k)}const e=this.order.length,s=new Uint8Array((e+1)*4),i=new DataView(s.buffer);let n=0;for(let p=0;p<e;p++)i.setUint32(p*4,n),t[p]&&(n+=t[p].length+3&-4);i.setUint32(e*4,n);const a=new Uint8Array(n);for(let p=0;p<e;p++)t[p]&&a.set(t[p],i.getUint32(p*4));const r=new Uint8Array(e*4),l=new DataView(r.buffer);for(let p=0;p<e;p++)l.setUint16(p*4,this._rawAdvance(this.order[p])),l.setInt16(p*4+2,this._rawLsb(this.order[p]));const h=this._copyTable("head"),c=new DataView(h.buffer);c.setUint32(8,0),c.setInt16(50,1);const d=this._copyTable("hhea");new DataView(d.buffer).setUint16(34,e);const g=this._copyTable("maxp");new DataView(g.buffer).setUint16(4,e);const f=[["glyf",a],["head",h],["hhea",d],["hmtx",r],["loca",s],["maxp",g]];for(const p of["cvt ","fpgm","prep"]){const _=this._copyTable(p);_&&f.push([p,_])}f.sort((p,_)=>p[0]<_[0]?-1:1);let u=12+f.length*16;for(const[,p]of f)u+=p.length+3&-4;const m=new Uint8Array(u),w=new DataView(m.buffer),x=f.length,y=31-Math.clz32(x);w.setUint32(0,65536),w.setUint16(4,x),w.setUint16(6,16<<y),w.setUint16(8,y),w.setUint16(10,x*16-(16<<y));let $=12+x*16,I=0;return f.forEach(([p,_],T)=>{const k=12+T*16;for(let C=0;C<4;C++)w.setUint8(k+C,p.charCodeAt(C));w.setUint32(k+4,q(_)),w.setUint32(k+8,$),w.setUint32(k+12,_.length),m.set(_,$),p==="head"&&(I=$),$+=_.length+3&-4}),w.setUint32(I+8,2981146554-q(m)>>>0),m}}function q(o){let t=0;const e=o.length;for(let s=0;s<e;s+=4){const i=(o[s]<<24|(o[s+1]??0)<<16|(o[s+2]??0)<<8|(o[s+3]??0))>>>0;t=t+i>>>0}return t}const ot={black:"000000",white:"ffffff",red:"ff0000",green:"008000",blue:"0000ff",yellow:"ffff00",orange:"ffa500",purple:"800080",gray:"808080",grey:"808080",silver:"c0c0c0",maroon:"800000",navy:"000080",teal:"008080",olive:"808000",lime:"00ff00",aqua:"00ffff",cyan:"00ffff",fuchsia:"ff00ff",magenta:"ff00ff",pink:"ffc0cb",brown:"a52a2a",lightgray:"d3d3d3",lightgrey:"d3d3d3",darkgray:"a9a9a9",darkgrey:"a9a9a9"},B=new Map;function E(o){const t=String(o);let e=B.get(t);return e!==void 0||(e=at(t.trim().toLowerCase()),B.size>4096&&B.clear(),B.set(t,e)),e}function at(o){if(o==="transparent")return{r:0,g:0,b:0,a:0,ops:"0 0 0"};let t=ot[o]??null;t===null&&o[0]==="#"&&(t=o.slice(1),(t.length===3||t.length===4)&&(t=[...t].map(r=>r+r).join("")));let e,s,i,n=1;if(t!==null){if(!/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(t))return null;e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16),t.length===8&&(n=parseInt(t.slice(6,8),16)/255)}else{const r=/^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(o);if(!r)return null;const l=h=>h.endsWith("%")?parseFloat(h)*2.55:parseFloat(h);e=l(r[1]),s=l(r[2]),i=l(r[3]),r[4]!==void 0&&(n=r[4].endsWith("%")?parseFloat(r[4])/100:parseFloat(r[4]))}const a=r=>b(Math.min(255,Math.max(0,r))/255);return{r:e,g:s,b:i,a:n,ops:`${a(e)} ${a(s)} ${a(i)}`}}class R{constructor(){this.color=null}addColorStop(t,e){this.color===null&&(this.color=e)}}const ht=()=>({a:1,b:0,c:0,d:1,e:0,f:0,fill:E("#000000"),fillText:"#000000",stroke:E("#000000"),strokeText:"#000000",lineWidth:1,lineCap:"butt",lineJoin:"miter",miterLimit:10,dash:[],dashOffset:0,alpha:1,font:"10px sans-serif",spec:null,textAlign:"start",textBaseline:"alphabetic"}),rt=()=>({fill:null,stroke:null,width:1,dash:"[] 0",cap:0,join:0,miter:10,alpha:1});class ct{constructor(t,e,s){this.writer=t,this.canvas={width:e,height:s},this.pageWidth=e,this.pageHeight=s,this.ops=[],this.fonts=new Set,this.images=new Set,this.alphas=new Set,this.s=ht(),this.stack=[],this.emitted=rt(),this.emittedStack=[],this.path=[],this.cx=0,this.cy=0,this.imageSmoothingEnabled=!0,this.globalCompositeOperation="source-over",this.shadowBlur=0,this.shadowColor="transparent",this.shadowOffsetX=0,this.shadowOffsetY=0,this.fontKerning="auto",this.direction="ltr"}save(){this.stack.push({...this.s}),this.emittedStack.push({...this.emitted}),this.ops.push("q")}restore(){this.stack.length!==0&&(this.s=this.stack.pop(),this.emitted=this.emittedStack.pop(),this.ops.push("Q"))}get fillStyle(){return this.s.fillText}set fillStyle(t){const e=t instanceof R?t.color??"#000000":t,s=E(e);s!==null&&(this.s.fill=s,this.s.fillText=e)}get strokeStyle(){return this.s.strokeText}set strokeStyle(t){const e=t instanceof R?t.color??"#000000":t,s=E(e);s!==null&&(this.s.stroke=s,this.s.strokeText=e)}get lineWidth(){return this.s.lineWidth}set lineWidth(t){t>0&&(this.s.lineWidth=t)}get lineCap(){return this.s.lineCap}set lineCap(t){this.s.lineCap=t}get lineJoin(){return this.s.lineJoin}set lineJoin(t){this.s.lineJoin=t}get miterLimit(){return this.s.miterLimit}set miterLimit(t){this.s.miterLimit=t}get lineDashOffset(){return this.s.dashOffset}set lineDashOffset(t){this.s.dashOffset=t}get globalAlpha(){return this.s.alpha}set globalAlpha(t){t>=0&&t<=1&&(this.s.alpha=t)}get textAlign(){return this.s.textAlign}set textAlign(t){this.s.textAlign=t}get textBaseline(){return this.s.textBaseline}set textBaseline(t){this.s.textBaseline=t}get font(){return this.s.font}set font(t){this.s.font=t,this.s.spec=null}setLineDash(t){this.s.dash=t.slice()}getLineDash(){return this.s.dash.slice()}translate(t,e){const s=this.s;s.e+=s.a*t+s.c*e,s.f+=s.b*t+s.d*e}scale(t,e){const s=this.s;s.a*=t,s.b*=t,s.c*=e,s.d*=e}rotate(t){const e=Math.cos(t),s=Math.sin(t);this.transform(e,s,-s,e,0,0)}transform(t,e,s,i,n,a){const r=this.s,{a:l,b:h,c,d,e:g,f}=r;r.a=l*t+c*e,r.b=h*t+d*e,r.c=l*s+c*i,r.d=h*s+d*i,r.e=l*n+c*a+g,r.f=h*n+d*a+f}setTransform(t,e,s,i,n,a){const r=this.s;typeof t=="object"&&t!==null&&({a:t,b:e,c:s,d:i,e:n,f:a}=t),r.a=t,r.b=e,r.c=s,r.d=i,r.e=n,r.f=a}resetTransform(){this.setTransform(1,0,0,1,0,0)}getTransform(){const{a:t,b:e,c:s,d:i,e:n,f:a}=this.s;return{a:t,b:e,c:s,d:i,e:n,f:a}}_X(t,e){const s=this.s;return s.a*t+s.c*e+s.e}_Y(t,e){const s=this.s;return this.pageHeight-(s.b*t+s.d*e+s.f)}_pt(t,e){return`${b(this._X(t,e))} ${b(this._Y(t,e))}`}beginPath(){this.path=[]}moveTo(t,e){this.path.push(`${this._pt(t,e)} m`),this.cx=t,this.cy=e}lineTo(t,e){this.path.push(`${this._pt(t,e)} ${this.path.length===0?"m":"l"}`),this.cx=t,this.cy=e}closePath(){this.path.length>0&&this.path.push("h")}bezierCurveTo(t,e,s,i,n,a){this.path.length===0&&this.moveTo(t,e),this.path.push(`${this._pt(t,e)} ${this._pt(s,i)} ${this._pt(n,a)} c`),this.cx=n,this.cy=a}quadraticCurveTo(t,e,s,i){this.path.length===0&&this.moveTo(t,e);const{cx:n,cy:a}=this;this.bezierCurveTo(n+2/3*(t-n),a+2/3*(e-a),s+2/3*(t-s),i+2/3*(e-i),s,i)}rect(t,e,s,i){const n=this.s;n.b===0&&n.c===0?this.path.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re`):this.path.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h`),this.cx=t,this.cy=e}roundRect(t,e,s,i,n=0){const a=Math.min(Math.abs(Array.isArray(n)?Number(n[0])||0:Number(n)||0),Math.abs(s)/2,Math.abs(i)/2);if(a===0){this.rect(t,e,s,i);return}this.moveTo(t+a,e),this.lineTo(t+s-a,e),this.quadraticCurveTo(t+s,e,t+s,e+a),this.lineTo(t+s,e+i-a),this.quadraticCurveTo(t+s,e+i,t+s-a,e+i),this.lineTo(t+a,e+i),this.quadraticCurveTo(t,e+i,t,e+i-a),this.lineTo(t,e+a),this.quadraticCurveTo(t,e,t+a,e),this.closePath()}arc(t,e,s,i,n,a=!1){this.ellipse(t,e,s,s,0,i,n,a)}ellipse(t,e,s,i,n,a,r,l=!1){let h=r-a;const c=Math.PI*2;!l&&h<0&&(h=h%c+c),l&&h>0&&(h=h%c-c),Math.abs(r-a)>=c&&(h=l?-c:c);const d=Math.cos(n),g=Math.sin(n),f=p=>{const _=s*Math.cos(p),T=i*Math.sin(p);return[t+_*d-T*g,e+_*g+T*d]},u=p=>{const _=-s*Math.sin(p),T=i*Math.cos(p);return[_*d-T*g,_*g+T*d]},m=Math.max(1,Math.ceil(Math.abs(h)/(Math.PI/2))),w=h/m,x=4/3*Math.tan(w/4),[y,$]=f(a);this.path.length===0?this.moveTo(y,$):this.lineTo(y,$);let I=a;for(let p=0;p<m;p++){const _=I+w,[T,k]=f(I),[C,S]=f(_),[v,V]=u(I),[G,X]=u(_);this.bezierCurveTo(T+x*v,k+x*V,C-x*G,S-x*X,C,S),I=_}}_applyAlpha(t){const e=Math.round(this.s.alpha*t*100);e!==Math.round(this.emitted.alpha*100)&&(this.emitted.alpha=e/100,this.alphas.add(e),this.ops.push(`/A${e} gs`))}_applyFill(){const t=this.s.fill;this._applyAlpha(t.a),this.emitted.fill!==t.ops&&(this.emitted.fill=t.ops,this.ops.push(`${t.ops} rg`))}_applyStroke(){const{s:t,emitted:e,ops:s}=this;this._applyAlpha(t.stroke.a),e.stroke!==t.stroke.ops&&(e.stroke=t.stroke.ops,s.push(`${t.stroke.ops} RG`));const i=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c))||1,n=t.lineWidth*i;e.width!==n&&(e.width=n,s.push(`${b(n)} w`));const a=`[${t.dash.map(h=>b(h*i)).join(" ")}] ${b(t.dashOffset*i)}`;e.dash!==a&&(e.dash=a,s.push(`${a} d`));const r=t.lineCap==="round"?1:t.lineCap==="square"?2:0;e.cap!==r&&(e.cap=r,s.push(`${r} J`));const l=t.lineJoin==="round"?1:t.lineJoin==="bevel"?2:0;e.join!==l&&(e.join=l,s.push(`${l} j`)),e.miter!==t.miterLimit&&(e.miter=t.miterLimit,s.push(`${b(t.miterLimit)} M`))}fill(t){this.path.length!==0&&(this._applyFill(),this.ops.push(`${this.path.join(" ")} ${t==="evenodd"?"f*":"f"}`))}stroke(){this.path.length!==0&&(this._applyStroke(),this.ops.push(`${this.path.join(" ")} S`))}clip(t){this.ops.push(`${this.path.length?`${this.path.join(" ")} `:"0 0 0 0 re "}${t==="evenodd"?"W*":"W"} n`)}fillRect(t,e,s,i){this._applyFill();const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`)}strokeRect(t,e,s,i){const n=this.path;this.path=[],this.rect(t,e,s,i),this.stroke(),this.path=n}clearRect(t,e,s,i){this.ops.push("q 1 1 1 rg");const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`),this.ops.push("Q")}createLinearGradient(){return new R}createRadialGradient(){return new R}createConicGradient(){return new R}createPattern(){return null}_spec(){const t=this.s;return t.spec===null&&(t.spec=this.writer._fontSpec(t.font)),t.spec}measureText(t){const e=this._spec(),s=this.writer._measure(String(t),e),i=e.size*e.ascent,n=e.size*e.descent;return{width:s,actualBoundingBoxLeft:0,actualBoundingBoxRight:s,actualBoundingBoxAscent:i,actualBoundingBoxDescent:n,fontBoundingBoxAscent:i,fontBoundingBoxDescent:n}}fillText(t,e,s){this._text(String(t),e,s,!1)}strokeText(t,e,s){this._text(String(t),e,s,!0)}_text(t,e,s,i){if(t==="")return;const n=this._spec(),{writer:a,s:r}=this,l=a._runs(t,n);let h=0;for(const f of l)h+=f.width;const c=r.textAlign;switch(c==="center"?e-=h/2:(c==="right"||c==="end")&&(e-=h),r.textBaseline){case"top":s+=n.size*n.ascent;break;case"hanging":s+=n.size*n.ascent*.8;break;case"middle":s+=n.size*(n.ascent-n.descent)/2;break;case"bottom":case"ideographic":s-=n.size*n.descent;break;default:}i?this._applyStroke():this._applyFill();const d=b(n.size);let g=e;for(const f of l){this.fonts.add(f.font);const u=f.hScale,m=`${b(r.a*u)} ${b(-r.b*u)} ${b(-r.c)} ${b(r.d)} ${b(this._X(g,s))} ${b(this._Y(g,s))}`;this.ops.push(`BT${i?" 1 Tr":""} /F${f.font.resId} ${d} Tf ${m} Tm <${f.hex}> Tj${i?" 0 Tr":""} ET`),g+=f.width}}drawImage(t,...e){const s=this.writer._image(t);if(s===null)return;this.images.add(s);let i=0,n=0,a=s.width,r=s.height,l,h,c,d;if(e.length>=8?[i,n,a,r,l,h,c,d]=e:e.length>=4?[l,h,c,d]=e:([l,h]=e,c=s.width,d=s.height),this._applyAlpha(1),this.ops.push("q"),e.length>=8){const $=this.path;this.path=[],this.rect(l,h,c,d),this.ops.push(`${this.path.join(" ")} W n`),this.path=$;const I=c/a,p=d/r;l-=i*I,h-=n*p,c=s.width*I,d=s.height*p}const g=this.s,f=g.a*c,u=-g.b*c,m=-g.c*d,w=g.d*d,x=this._X(l,h+d),y=this._Y(l,h+d);this.ops.push(`${b(f)} ${b(u)} ${b(m)} ${b(w)} ${b(x)} ${b(y)} cm /Im${s.resId} Do Q`)}}function lt(o){const t=(e,s=2)=>String(e).padStart(s,"0");return`D:${t(o.getUTCFullYear(),4)}${t(o.getUTCMonth()+1)}${t(o.getUTCDate())}${t(o.getUTCHours())}${t(o.getUTCMinutes())}${t(o.getUTCSeconds())}Z`}function O(o){let t="FEFF";for(let e=0;e<o.length;e++)t+=F(o.charCodeAt(e));return`<${t}>`}function ft(o){let t=2;for(;t+9<o.length;){if(o[t]!==255){t++;continue}const e=o[t+1];if(e>=192&&e<=207&&e!==196&&e!==200&&e!==204)return{height:o[t+5]<<8|o[t+6],width:o[t+7]<<8|o[t+8],components:o[t+9]};t+=2+(o[t+2]<<8|o[t+3])}return null}class wt{constructor(t,e={}){this.sink=t,this.options=e,this.compress=e.compress!==!1&&typeof CompressionStream<"u",this.offset=0,this.buffer=new Uint8Array(M),this.pos=0,this.xref=new Float64Array(1024),this.nextId=1,this.started=!1,this.finished=!1,this.page=null,this.pageCount=0,this.levels=[],this.faces=[],this.stdFonts=new Map,this.encodingId=0,this.nextFontRes=1,this.nextImageRes=1,this.imageIds=new WeakMap,this.pendingImages=[],this.specs=new Map,this.missing=new Set,this.fontWarnings=[];for(const s of e.fonts??[])this.registerFont(s)}registerFont(t){try{const e=new nt(t.bytes,t);return e.familyKey=e.family.toLowerCase(),this.faces.push(e),this.specs.clear(),!0}catch(e){return this.fontWarnings.push(`${t.family??"font"}: ${e.message}`),!1}}async _raw(t){const e=t.length;if(this.offset+=e,e>=M/2){await this._flush(),await this.sink.write(t);return}this.pos+e>M&&await this._flush(),this.buffer.set(t,this.pos),this.pos+=e}async _flush(){if(this.pos===0)return;const t=this.buffer.slice(0,this.pos);this.pos=0,await this.sink.write(t)}_w(t){return this._raw(W.encode(t))}_alloc(){const t=this.nextId++;if(t>=this.xref.length){const e=new Float64Array(this.xref.length*2);e.set(this.xref),this.xref=e}return t}async _obj(t,e){this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
1
|
+
const W=new TextEncoder,M=65536,Y=9999999999,J=128,L=()=>{},j=[];for(let a=0;a<256;a++)j.push(a.toString(16).padStart(2,"0"));const F=a=>j[a>>8&255]+j[a&255],b=a=>String(Math.round(a*1e3)/1e3+0),A=a=>Array(10).fill(a),R={Helvetica:[278,278,355,556,556,889,667,191,333,333,389,584,278,333,278,278,...A(556),278,278,584,584,584,556,1015,667,667,722,722,667,611,778,722,278,500,667,556,833,722,778,667,778,722,667,611,722,667,944,667,667,611,278,278,278,469,556,333,556,556,500,556,556,278,556,556,222,222,500,222,833,556,556,556,556,333,500,278,556,500,722,500,500,500,334,260,334,584],"Helvetica-Bold":[278,333,474,556,556,889,722,238,333,333,389,584,278,333,278,278,...A(556),333,333,584,584,584,611,975,722,722,722,722,667,611,778,722,278,556,722,611,833,722,778,667,778,722,667,611,722,667,944,667,667,611,333,278,333,584,556,333,556,611,556,611,556,333,611,611,278,278,556,278,889,611,611,611,611,389,556,333,611,556,778,556,556,500,389,280,389,584],"Times-Roman":[250,333,408,500,500,833,778,180,333,333,500,564,250,333,250,278,...A(500),278,278,564,564,564,444,921,722,667,667,722,611,556,722,722,333,389,722,611,889,722,722,556,722,667,556,611,722,722,944,722,722,611,333,278,333,469,500,333,444,500,444,500,444,333,500,500,278,278,500,278,778,500,500,500,500,333,389,278,500,500,722,500,500,444,480,200,480,541],"Times-Bold":[250,333,555,500,500,1e3,833,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,930,722,667,722,722,667,611,778,778,389,500,778,667,944,722,778,611,778,722,556,667,722,722,1e3,722,722,667,333,278,333,581,500,333,500,556,444,556,444,333,500,556,278,333,556,278,833,556,500,556,556,444,389,333,556,500,722,500,500,444,394,220,394,520],"Times-Italic":[250,333,420,500,500,833,778,214,333,333,500,675,250,333,250,278,...A(500),333,333,675,675,675,500,920,611,611,667,722,611,611,722,722,333,444,667,556,833,667,722,611,722,611,500,556,722,611,833,611,556,556,389,278,389,422,500,333,500,500,444,500,444,278,500,500,278,278,444,278,722,500,500,500,500,389,389,278,500,444,667,444,444,389,400,275,400,541],"Times-BoldItalic":[250,389,555,500,500,833,778,278,333,333,500,570,250,333,250,278,...A(500),333,333,570,570,570,500,832,667,667,667,722,667,667,722,778,389,500,667,611,889,722,722,611,722,667,556,611,722,667,889,667,611,611,333,278,333,570,500,333,500,500,444,500,444,333,500,556,278,278,500,278,778,556,500,500,500,389,389,278,556,444,667,500,444,389,348,220,348,570]};R["Helvetica-Oblique"]=R.Helvetica,R["Helvetica-BoldOblique"]=R["Helvetica-Bold"];const K=new Map(Object.entries({"€":[556,500],"–":[556,500],"—":[1e3,1e3],"…":[1e3,1e3],"•":[350,350],"‘":[222,333],"’":[222,333],"‚":[222,333],"“":[333,444],"”":[333,444],"„":[333,444],"†":[556,500],"‡":[556,500],"‰":[1e3,1e3],"‹":[333,333],"›":[333,333],ƒ:[556,500],"™":[1e3,980],"ˆ":[333,333],"˜":[333,333],"¡":[333,333],"¢":[556,500],"£":[556,500],"¤":[556,500],"¥":[556,500],"¦":[260,200],"§":[556,500],"¨":[333,333],"©":[737,760],ª:[370,276],"«":[556,500],"¬":[584,564],"®":[737,760],"¯":[333,333],"°":[400,400],"±":[584,564],"²":[333,300],"³":[333,300],"´":[333,333],µ:[556,500],"¶":[537,453],"·":[278,250],"¸":[333,333],"¹":[333,300],º:[365,310],"»":[556,500],"¼":[834,750],"½":[834,750],"¾":[834,750],"¿":[611,444],"×":[584,564],"÷":[584,564],Æ:[1e3,889],æ:[889,667],Œ:[1e3,889],œ:[944,722],Ø:[778,722],ø:[611,500],ß:[611,500],Ð:[722,722],ð:[556,500],Þ:[667,556],þ:[556,500]})),H="€\0‚ƒ„…†‡ˆ‰Š‹Œ\0Ž\0\0‘’“”•–—˜™š›œ\0žŸ",z=[["ą","aogonek"],["Ą","Aogonek"],["ć","cacute"],["Ć","Cacute"],["ę","eogonek"],["Ę","Eogonek"],["ł","lslash"],["Ł","Lslash"],["ń","nacute"],["Ń","Nacute"],["ś","sacute"],["Ś","Sacute"],["ź","zacute"],["Ź","Zacute"],["ż","zdotaccent"],["Ż","Zdotaccent"],["č","ccaron"],["Č","Ccaron"],["ě","ecaron"],["Ě","Ecaron"],["ř","rcaron"],["Ř","Rcaron"],["ů","uring"],["Ů","Uring"],["ő","ohungarumlaut"],["Ő","Ohungarumlaut"],["ű","uhungarumlaut"],["Ű","Uhungarumlaut"],["ň","ncaron"],["ď","dcaron"],["ť","tcaron"]],y=new Map;for(let a=32;a<127;a++)y.set(a,a);for(let a=161;a<=255;a++)y.set(a,a);for(let a=0;a<H.length;a++)H[a]!=="\0"&&y.set(H.codePointAt(a),128+a);z.forEach(([a],t)=>y.set(a.codePointAt(0),t+1));for(const a of[160,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288])y.set(a,32);for(const a of[8208,8209,173])y.set(a,45);y.set(8722,150),y.set(8213,151);const Z=/times|georgia|cambria|garamond|palatino|book antiqua|constantia|baskerville|bookman|century|minion|serif$/,Q=/sans|gothic/,tt=/courier|consolas|menlo|monaco|lucida console|lucida sans typewriter|mono/,et=/aptos narrow|calibri|carlito|arial narrow|corbel|candara/;function st(a,t,e){return tt.test(a)?`Courier${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`:Z.test(a)&&!Q.test(a)?t?e?"Times-BoldItalic":"Times-Bold":e?"Times-Italic":"Times-Roman":`Helvetica${t||e?"-":""}${t?"Bold":""}${e?"Oblique":""}`}class it{constructor(t,e,s){this.name=t,this.resId=e,this.objectId=s,this.mono=t.startsWith("Courier"),this.serif=t.startsWith("Times"),this.table=R[t]??null,this.ascent=this.mono?.629:this.serif?.683:.718,this.descent=this.mono?.157:this.serif?.217:.207,this.widths=new Map}width(t){if(this.mono)return 600;if(t>=32&&t<127)return this.table[t-32];let e=this.widths.get(t);return e===void 0&&(e=this._extraWidth(t),this.widths.set(t,e)),e}_extraWidth(t){const e=String.fromCodePoint(t),s=K.get(e);if(s)return s[this.serif?1:0];if(e==="ł")return this.table[76];if(e==="Ł")return this.table[44];const i=y.get(t);if(i===32)return this.table[0];if(i===45)return this.table[13];const n=e.normalize("NFD").codePointAt(0);return n>=32&&n<127?this.table[n-32]:this.serif?500:556}}function N(a){const t=String.fromCodePoint(a).normalize("NFD").codePointAt(0);return y.has(t)?t:63}class nt{constructor(t,e={}){this.bytes=ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.tables=this._openFace(e.postscriptName);for(const r of["head","hhea","hmtx","maxp","cmap","loca","glyf"])if(!this.tables.has(r))throw new Error(`Font has no ${r} table, so it isn't TrueType`);const s=this.view,i=this.tables.get("head").offset,n=this.tables.get("hhea").offset;this.unitsPerEm=s.getUint16(i+18)||1e3,this.bbox=[s.getInt16(i+36),s.getInt16(i+38),s.getInt16(i+40),s.getInt16(i+42)];const o=s.getUint16(i+44);this.longLoca=s.getInt16(i+50)!==0,this.ascentUnits=s.getInt16(n+4),this.descentUnits=s.getInt16(n+6),this.numHMetrics=s.getUint16(n+34),this.numGlyphs=s.getUint16(this.tables.get("maxp").offset+4),this.italicAngle=this.tables.has("post")?s.getInt32(this.tables.get("post").offset+4)/65536:0,this.capHeightUnits=this.ascentUnits;const h=this.tables.get("OS/2");if(h){if((s.getUint16(h.offset+8)&15)===2)throw new Error("Font license forbids embedding");s.getUint16(h.offset)>=2&&h.length>=90&&(this.capHeightUnits=s.getInt16(h.offset+88)||this.ascentUnits)}const f=this._names();this.family=e.family??f.family??"Embedded",this.postscriptName=(f.postscript??this.family).replace(/[^A-Za-z0-9-]/g,""),this.bold=e.bold??(o&1)!==0,this.italic=e.italic??(o&2)!==0,this.scale=1e3/this.unitsPerEm,this.ascent=this.ascentUnits/this.unitsPerEm,this.descent=-this.descentUnits/this.unitsPerEm,this.lookup=this._cmap(),this.gids=new Map,this.order=[0],this.newIds=new Map([[0,0]]),this.unicode=[],this.resId=0,this.objectId=0}_openFace(t){const e=this.view,s=e.getUint32(0);if(s===1330926671)throw new Error("OpenType/CFF fonts are not supported");if(s===1953784678){const i=e.getUint32(8);let n=null;for(let o=0;o<i;o++){const h=this._directory(e.getUint32(12+o*4));if(n===null&&(n=h),t&&this._names(h).postscript===t)return h}if(n===null)throw new Error("Empty font collection");return n}if(s!==65536&&s!==1953658213)throw new Error("Not a TrueType font");return this._directory(0)}_directory(t){const e=this.view,s=e.getUint16(t+4),i=new Map;for(let n=0;n<s;n++){const o=t+12+n*16,h=String.fromCharCode(e.getUint8(o),e.getUint8(o+1),e.getUint8(o+2),e.getUint8(o+3));i.set(h,{offset:e.getUint32(o+8),length:e.getUint32(o+12)})}return i}_names(t=this.tables){const e={},s=t.get("name");if(!s)return e;const i=this.view,n=i.getUint16(s.offset+2),o=s.offset+i.getUint16(s.offset+4);for(let h=0;h<n;h++){const f=s.offset+6+h*12,r=i.getUint16(f),l=i.getUint16(f+6);if(l!==1&&l!==6)continue;const c=i.getUint16(f+8),u=o+i.getUint16(f+10);let d="";if(r===3||r===0)for(let m=0;m+1<c;m+=2)d+=String.fromCharCode(i.getUint16(u+m));else for(let m=0;m<c;m++)d+=String.fromCharCode(i.getUint8(u+m));const p=l===1?"family":"postscript";(e[p]===void 0||r===3)&&(e[p]=d)}return e}_cmap(){const t=this.view,e=this.tables.get("cmap").offset,s=t.getUint16(e+2);let i=null,n=-1;for(let p=0;p<s;p++){const m=e+4+p*8,w=t.getUint16(m),x=t.getUint16(m+2),U=e+t.getUint32(m+4),$=t.getUint16(U);if($!==4&&$!==12&&$!==6)continue;let I=-1;w===3&&x===10?I=4:w===0&&$===12?I=3:w===3&&x===1?I=2:w===0&&(I=1),I>n&&(n=I,i={at:U,format:$})}if(i===null)throw new Error("Font has no Unicode cmap");const{at:o,format:h}=i;if(h===12){const p=t.getUint32(o+12);return m=>{let w=0,x=p-1;for(;w<=x;){const U=w+x>>>1,$=o+16+U*12;if(m<t.getUint32($))x=U-1;else if(m>t.getUint32($+4))w=U+1;else return t.getUint32($+8)+m-t.getUint32($)}return 0}}if(h===6){const p=t.getUint16(o+6),m=t.getUint16(o+8);return w=>w>=p&&w<p+m?t.getUint16(o+10+(w-p)*2):0}const f=t.getUint16(o+6),r=o+14,l=r+f+2,c=l+f,u=c+f,d=f/2;return p=>{if(p>65535)return 0;let m=0,w=d-1;for(;m<w;){const g=m+w>>>1;t.getUint16(r+g*2)<p?m=g+1:w=g}const x=t.getUint16(l+m*2);if(p<x||p>t.getUint16(r+m*2))return 0;const U=t.getInt16(c+m*2),$=t.getUint16(u+m*2);if($===0)return p+U&65535;const I=t.getUint16(u+m*2+$+(p-x)*2);return I===0?0:I+U&65535}}gidOf(t){let e=this.gids.get(t);return e===void 0&&(e=this.lookup(t),e>=this.numGlyphs&&(e=0),this.gids.set(t,e)),e}_rawAdvance(t){const e=this.tables.get("hmtx").offset;return this.view.getUint16(e+Math.min(t,this.numHMetrics-1)*4)}_rawLsb(t){const e=this.tables.get("hmtx").offset;return t<this.numHMetrics?this.view.getInt16(e+t*4+2):this.view.getInt16(e+this.numHMetrics*4+(t-this.numHMetrics)*2)}width(t){return this._rawAdvance(this.gidOf(t))*this.scale}_newId(t){let e=this.newIds.get(t);return e===void 0&&(e=this.order.length,this.order.push(t),this.newIds.set(t,e)),e}use(t){const e=this._newId(this.gidOf(t));return this.unicode[e]===void 0&&(this.unicode[e]=t),e}_glyphRange(t){const e=this.tables.get("loca").offset,s=this.tables.get("glyf").offset,i=this.view,n=this.longLoca?i.getUint32(e+t*4):i.getUint16(e+t*2)*2,o=this.longLoca?i.getUint32(e+(t+1)*4):i.getUint16(e+(t+1)*2)*2;return[s+n,o-n]}_copyTable(t){const e=this.tables.get(t);return e?this.bytes.slice(e.offset,e.offset+e.length):null}subset(){const t=[];for(let g=0;g<this.order.length;g++){const[_,T]=this._glyphRange(this.order[g]);if(T<=0){t.push(null);continue}const S=this.bytes.slice(_,_+T),k=new DataView(S.buffer);if(k.getInt16(0)<0){let C=10;for(;;){const v=k.getUint16(C);if(k.setUint16(C+2,this._newId(k.getUint16(C+2))),C+=4+(v&1?4:2),v&8?C+=2:v&64?C+=4:v&128&&(C+=8),!(v&32))break}}t.push(S)}const e=this.order.length,s=new Uint8Array((e+1)*4),i=new DataView(s.buffer);let n=0;for(let g=0;g<e;g++)i.setUint32(g*4,n),t[g]&&(n+=t[g].length+3&-4);i.setUint32(e*4,n);const o=new Uint8Array(n);for(let g=0;g<e;g++)t[g]&&o.set(t[g],i.getUint32(g*4));const h=new Uint8Array(e*4),f=new DataView(h.buffer);for(let g=0;g<e;g++)f.setUint16(g*4,this._rawAdvance(this.order[g])),f.setInt16(g*4+2,this._rawLsb(this.order[g]));const r=this._copyTable("head"),l=new DataView(r.buffer);l.setUint32(8,0),l.setInt16(50,1);const c=this._copyTable("hhea");new DataView(c.buffer).setUint16(34,e);const u=this._copyTable("maxp");new DataView(u.buffer).setUint16(4,e);const d=[["glyf",o],["head",r],["hhea",c],["hmtx",h],["loca",s],["maxp",u]];for(const g of["cvt ","fpgm","prep"]){const _=this._copyTable(g);_&&d.push([g,_])}d.sort((g,_)=>g[0]<_[0]?-1:1);let p=12+d.length*16;for(const[,g]of d)p+=g.length+3&-4;const m=new Uint8Array(p),w=new DataView(m.buffer),x=d.length,U=31-Math.clz32(x);w.setUint32(0,65536),w.setUint16(4,x),w.setUint16(6,16<<U),w.setUint16(8,U),w.setUint16(10,x*16-(16<<U));let $=12+x*16,I=0;return d.forEach(([g,_],T)=>{const S=12+T*16;for(let k=0;k<4;k++)w.setUint8(S+k,g.charCodeAt(k));w.setUint32(S+4,q(_)),w.setUint32(S+8,$),w.setUint32(S+12,_.length),m.set(_,$),g==="head"&&(I=$),$+=_.length+3&-4}),w.setUint32(I+8,2981146554-q(m)>>>0),m}}function q(a){let t=0;const e=a.length;for(let s=0;s<e;s+=4){const i=(a[s]<<24|(a[s+1]??0)<<16|(a[s+2]??0)<<8|(a[s+3]??0))>>>0;t=t+i>>>0}return t}const ot={black:"000000",white:"ffffff",red:"ff0000",green:"008000",blue:"0000ff",yellow:"ffff00",orange:"ffa500",purple:"800080",gray:"808080",grey:"808080",silver:"c0c0c0",maroon:"800000",navy:"000080",teal:"008080",olive:"808000",lime:"00ff00",aqua:"00ffff",cyan:"00ffff",fuchsia:"ff00ff",magenta:"ff00ff",pink:"ffc0cb",brown:"a52a2a",lightgray:"d3d3d3",lightgrey:"d3d3d3",darkgray:"a9a9a9",darkgrey:"a9a9a9"},E=new Map;function O(a){const t=String(a);let e=E.get(t);return e!==void 0||(e=at(t.trim().toLowerCase()),E.size>4096&&E.clear(),E.set(t,e)),e}function at(a){if(a==="transparent")return{r:0,g:0,b:0,a:0,ops:"0 0 0"};let t=ot[a]??null;t===null&&a[0]==="#"&&(t=a.slice(1),(t.length===3||t.length===4)&&(t=[...t].map(h=>h+h).join("")));let e,s,i,n=1;if(t!==null){if(!/^[0-9a-f]{6}([0-9a-f]{2})?$/.test(t))return null;e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16),t.length===8&&(n=parseInt(t.slice(6,8),16)/255)}else{const h=/^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(a);if(!h)return null;const f=r=>r.endsWith("%")?parseFloat(r)*2.55:parseFloat(r);e=f(h[1]),s=f(h[2]),i=f(h[3]),h[4]!==void 0&&(n=h[4].endsWith("%")?parseFloat(h[4])/100:parseFloat(h[4]))}const o=h=>b(Math.min(255,Math.max(0,h))/255);return{r:e,g:s,b:i,a:n,ops:`${o(e)} ${o(s)} ${o(i)}`}}class D{constructor(){this.color=null}addColorStop(t,e){this.color===null&&(this.color=e)}}const ht=()=>({a:1,b:0,c:0,d:1,e:0,f:0,fill:O("#000000"),fillText:"#000000",stroke:O("#000000"),strokeText:"#000000",lineWidth:1,lineCap:"butt",lineJoin:"miter",miterLimit:10,dash:[],dashOffset:0,alpha:1,font:"10px sans-serif",spec:null,textAlign:"start",textBaseline:"alphabetic"}),rt=()=>({fill:null,stroke:null,width:1,dash:"[] 0",cap:0,join:0,miter:10,alpha:1});class ct{constructor(t,e,s){this.writer=t,this.canvas={width:e,height:s},this.pageWidth=e,this.pageHeight=s,this.ops=[],this.fonts=new Set,this.images=new Set,this.alphas=new Set,this.links=[],this.s=ht(),this.stack=[],this.emitted=rt(),this.emittedStack=[],this.path=[],this.cx=0,this.cy=0,this.imageSmoothingEnabled=!0,this.globalCompositeOperation="source-over",this.shadowBlur=0,this.shadowColor="transparent",this.shadowOffsetX=0,this.shadowOffsetY=0,this.fontKerning="auto",this.direction="ltr"}save(){this.stack.push({...this.s}),this.emittedStack.push({...this.emitted}),this.ops.push("q")}restore(){this.stack.length!==0&&(this.s=this.stack.pop(),this.emitted=this.emittedStack.pop(),this.ops.push("Q"))}get fillStyle(){return this.s.fillText}set fillStyle(t){const e=t instanceof D?t.color??"#000000":t,s=O(e);s!==null&&(this.s.fill=s,this.s.fillText=e)}get strokeStyle(){return this.s.strokeText}set strokeStyle(t){const e=t instanceof D?t.color??"#000000":t,s=O(e);s!==null&&(this.s.stroke=s,this.s.strokeText=e)}get lineWidth(){return this.s.lineWidth}set lineWidth(t){t>0&&(this.s.lineWidth=t)}get lineCap(){return this.s.lineCap}set lineCap(t){this.s.lineCap=t}get lineJoin(){return this.s.lineJoin}set lineJoin(t){this.s.lineJoin=t}get miterLimit(){return this.s.miterLimit}set miterLimit(t){this.s.miterLimit=t}get lineDashOffset(){return this.s.dashOffset}set lineDashOffset(t){this.s.dashOffset=t}get globalAlpha(){return this.s.alpha}set globalAlpha(t){t>=0&&t<=1&&(this.s.alpha=t)}get textAlign(){return this.s.textAlign}set textAlign(t){this.s.textAlign=t}get textBaseline(){return this.s.textBaseline}set textBaseline(t){this.s.textBaseline=t}get font(){return this.s.font}set font(t){this.s.font=t,this.s.spec=null}setLineDash(t){this.s.dash=t.slice()}getLineDash(){return this.s.dash.slice()}translate(t,e){const s=this.s;s.e+=s.a*t+s.c*e,s.f+=s.b*t+s.d*e}scale(t,e){const s=this.s;s.a*=t,s.b*=t,s.c*=e,s.d*=e}rotate(t){const e=Math.cos(t),s=Math.sin(t);this.transform(e,s,-s,e,0,0)}transform(t,e,s,i,n,o){const h=this.s,{a:f,b:r,c:l,d:c,e:u,f:d}=h;h.a=f*t+l*e,h.b=r*t+c*e,h.c=f*s+l*i,h.d=r*s+c*i,h.e=f*n+l*o+u,h.f=r*n+c*o+d}setTransform(t,e,s,i,n,o){const h=this.s;typeof t=="object"&&t!==null&&({a:t,b:e,c:s,d:i,e:n,f:o}=t),h.a=t,h.b=e,h.c=s,h.d=i,h.e=n,h.f=o}resetTransform(){this.setTransform(1,0,0,1,0,0)}getTransform(){const{a:t,b:e,c:s,d:i,e:n,f:o}=this.s;return{a:t,b:e,c:s,d:i,e:n,f:o}}_X(t,e){const s=this.s;return s.a*t+s.c*e+s.e}_Y(t,e){const s=this.s;return this.pageHeight-(s.b*t+s.d*e+s.f)}_pt(t,e){return`${b(this._X(t,e))} ${b(this._Y(t,e))}`}link(t,e,s,i,n){const o=[this._X(t,e),this._X(t+s,e+i)],h=[this._Y(t,e),this._Y(t+s,e+i)];this.links.push({...n,rect:[Math.min(...o),Math.min(...h),Math.max(...o),Math.max(...h)].map(b).join(" ")})}beginPath(){this.path=[]}moveTo(t,e){this.path.push(`${this._pt(t,e)} m`),this.cx=t,this.cy=e}lineTo(t,e){this.path.push(`${this._pt(t,e)} ${this.path.length===0?"m":"l"}`),this.cx=t,this.cy=e}closePath(){this.path.length>0&&this.path.push("h")}bezierCurveTo(t,e,s,i,n,o){this.path.length===0&&this.moveTo(t,e),this.path.push(`${this._pt(t,e)} ${this._pt(s,i)} ${this._pt(n,o)} c`),this.cx=n,this.cy=o}quadraticCurveTo(t,e,s,i){this.path.length===0&&this.moveTo(t,e);const{cx:n,cy:o}=this;this.bezierCurveTo(n+2/3*(t-n),o+2/3*(e-o),s+2/3*(t-s),i+2/3*(e-i),s,i)}rect(t,e,s,i){const n=this.s;n.b===0&&n.c===0?this.path.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re`):this.path.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h`),this.cx=t,this.cy=e}roundRect(t,e,s,i,n=0){const o=Math.min(Math.abs(Array.isArray(n)?Number(n[0])||0:Number(n)||0),Math.abs(s)/2,Math.abs(i)/2);if(o===0){this.rect(t,e,s,i);return}this.moveTo(t+o,e),this.lineTo(t+s-o,e),this.quadraticCurveTo(t+s,e,t+s,e+o),this.lineTo(t+s,e+i-o),this.quadraticCurveTo(t+s,e+i,t+s-o,e+i),this.lineTo(t+o,e+i),this.quadraticCurveTo(t,e+i,t,e+i-o),this.lineTo(t,e+o),this.quadraticCurveTo(t,e,t+o,e),this.closePath()}arc(t,e,s,i,n,o=!1){this.ellipse(t,e,s,s,0,i,n,o)}ellipse(t,e,s,i,n,o,h,f=!1){let r=h-o;const l=Math.PI*2;!f&&r<0&&(r=r%l+l),f&&r>0&&(r=r%l-l),Math.abs(h-o)>=l&&(r=f?-l:l);const c=Math.cos(n),u=Math.sin(n),d=g=>{const _=s*Math.cos(g),T=i*Math.sin(g);return[t+_*c-T*u,e+_*u+T*c]},p=g=>{const _=-s*Math.sin(g),T=i*Math.cos(g);return[_*c-T*u,_*u+T*c]},m=Math.max(1,Math.ceil(Math.abs(r)/(Math.PI/2))),w=r/m,x=4/3*Math.tan(w/4),[U,$]=d(o);this.path.length===0?this.moveTo(U,$):this.lineTo(U,$);let I=o;for(let g=0;g<m;g++){const _=I+w,[T,S]=d(I),[k,C]=d(_),[v,V]=p(I),[G,X]=p(_);this.bezierCurveTo(T+x*v,S+x*V,k-x*G,C-x*X,k,C),I=_}}_applyAlpha(t){const e=Math.round(this.s.alpha*t*100);e!==Math.round(this.emitted.alpha*100)&&(this.emitted.alpha=e/100,this.alphas.add(e),this.ops.push(`/A${e} gs`))}_applyFill(){const t=this.s.fill;this._applyAlpha(t.a),this.emitted.fill!==t.ops&&(this.emitted.fill=t.ops,this.ops.push(`${t.ops} rg`))}_applyStroke(){const{s:t,emitted:e,ops:s}=this;this._applyAlpha(t.stroke.a),e.stroke!==t.stroke.ops&&(e.stroke=t.stroke.ops,s.push(`${t.stroke.ops} RG`));const i=Math.sqrt(Math.abs(t.a*t.d-t.b*t.c))||1,n=t.lineWidth*i;e.width!==n&&(e.width=n,s.push(`${b(n)} w`));const o=`[${t.dash.map(r=>b(r*i)).join(" ")}] ${b(t.dashOffset*i)}`;e.dash!==o&&(e.dash=o,s.push(`${o} d`));const h=t.lineCap==="round"?1:t.lineCap==="square"?2:0;e.cap!==h&&(e.cap=h,s.push(`${h} J`));const f=t.lineJoin==="round"?1:t.lineJoin==="bevel"?2:0;e.join!==f&&(e.join=f,s.push(`${f} j`)),e.miter!==t.miterLimit&&(e.miter=t.miterLimit,s.push(`${b(t.miterLimit)} M`))}fill(t){this.path.length!==0&&(this._applyFill(),this.ops.push(`${this.path.join(" ")} ${t==="evenodd"?"f*":"f"}`))}stroke(){this.path.length!==0&&(this._applyStroke(),this.ops.push(`${this.path.join(" ")} S`))}clip(t){this.ops.push(`${this.path.length?`${this.path.join(" ")} `:"0 0 0 0 re "}${t==="evenodd"?"W*":"W"} n`)}fillRect(t,e,s,i){this._applyFill();const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`)}strokeRect(t,e,s,i){const n=this.path;this.path=[],this.rect(t,e,s,i),this.stroke(),this.path=n}clearRect(t,e,s,i){this.ops.push("q 1 1 1 rg");const n=this.s;n.b===0&&n.c===0?this.ops.push(`${this._pt(t,e)} ${b(n.a*s)} ${b(-n.d*i)} re f`):this.ops.push(`${this._pt(t,e)} m ${this._pt(t+s,e)} l ${this._pt(t+s,e+i)} l ${this._pt(t,e+i)} l h f`),this.ops.push("Q")}createLinearGradient(){return new D}createRadialGradient(){return new D}createConicGradient(){return new D}createPattern(){return null}_spec(){const t=this.s;return t.spec===null&&(t.spec=this.writer._fontSpec(t.font)),t.spec}measureText(t){const e=this._spec(),s=this.writer._measure(String(t),e),i=e.size*e.ascent,n=e.size*e.descent;return{width:s,actualBoundingBoxLeft:0,actualBoundingBoxRight:s,actualBoundingBoxAscent:i,actualBoundingBoxDescent:n,fontBoundingBoxAscent:i,fontBoundingBoxDescent:n}}fillText(t,e,s){this._text(String(t),e,s,!1)}strokeText(t,e,s){this._text(String(t),e,s,!0)}_text(t,e,s,i){if(t==="")return;const n=this._spec(),{writer:o,s:h}=this,f=o._runs(t,n);let r=0;for(const d of f)r+=d.width;const l=h.textAlign;switch(l==="center"?e-=r/2:(l==="right"||l==="end")&&(e-=r),h.textBaseline){case"top":s+=n.size*n.ascent;break;case"hanging":s+=n.size*n.ascent*.8;break;case"middle":s+=n.size*(n.ascent-n.descent)/2;break;case"bottom":case"ideographic":s-=n.size*n.descent;break;default:}i?this._applyStroke():this._applyFill();const c=b(n.size);let u=e;for(const d of f){this.fonts.add(d.font);const p=d.hScale,m=`${b(h.a*p)} ${b(-h.b*p)} ${b(-h.c)} ${b(h.d)} ${b(this._X(u,s))} ${b(this._Y(u,s))}`;this.ops.push(`BT${i?" 1 Tr":""} /F${d.font.resId} ${c} Tf ${m} Tm <${d.hex}> Tj${i?" 0 Tr":""} ET`),u+=d.width}}drawImage(t,...e){const s=this.writer._image(t);if(s===null)return;this.images.add(s);let i=0,n=0,o=s.width,h=s.height,f,r,l,c;if(e.length>=8?[i,n,o,h,f,r,l,c]=e:e.length>=4?[f,r,l,c]=e:([f,r]=e,l=s.width,c=s.height),this._applyAlpha(1),this.ops.push("q"),e.length>=8){const $=this.path;this.path=[],this.rect(f,r,l,c),this.ops.push(`${this.path.join(" ")} W n`),this.path=$;const I=l/o,g=c/h;f-=i*I,r-=n*g,l=s.width*I,c=s.height*g}const u=this.s,d=u.a*l,p=-u.b*l,m=-u.c*c,w=u.d*c,x=this._X(f,r+c),U=this._Y(f,r+c);this.ops.push(`${b(d)} ${b(p)} ${b(m)} ${b(w)} ${b(x)} ${b(U)} cm /Im${s.resId} Do Q`)}}function lt(a){const t=(e,s=2)=>String(e).padStart(s,"0");return`D:${t(a.getUTCFullYear(),4)}${t(a.getUTCMonth()+1)}${t(a.getUTCDate())}${t(a.getUTCHours())}${t(a.getUTCMinutes())}${t(a.getUTCSeconds())}Z`}function B(a){let t="FEFF";for(let e=0;e<a.length;e++)t+=F(a.charCodeAt(e));return`<${t}>`}function ft(a){return`(${[...a].map(e=>/[!-~]/.test(e)?e:encodeURIComponent(e.isWellFormed?.()===!1?"�":e)).join("").replace(/[\\()]/g,"\\$&")})`}function dt(a){let t=2;for(;t+9<a.length;){if(a[t]!==255){t++;continue}const e=a[t+1];if(e>=192&&e<=207&&e!==196&&e!==200&&e!==204)return{height:a[t+5]<<8|a[t+6],width:a[t+7]<<8|a[t+8],components:a[t+9]};t+=2+(a[t+2]<<8|a[t+3])}return null}class bt{constructor(t,e={}){this.sink=t,this.options=e,this.compress=e.compress!==!1&&typeof CompressionStream<"u",this.offset=0,this.buffer=new Uint8Array(M),this.pos=0,this.xref=new Float64Array(1024),this.nextId=1,this.started=!1,this.finished=!1,this.page=null,this.pageCount=0,this.pageIds=[],this.dests=new Map,this.bookmarks=[],this.levels=[],this.faces=[],this.stdFonts=new Map,this.encodingId=0,this.nextFontRes=1,this.nextImageRes=1,this.imageIds=new WeakMap,this.pendingImages=[],this.specs=new Map,this.missing=new Set,this.fontWarnings=[];for(const s of e.fonts??[])this.registerFont(s)}registerFont(t){try{const e=new nt(t.bytes,t);return e.familyKey=e.family.toLowerCase(),this.faces.push(e),this.specs.clear(),!0}catch(e){return this.fontWarnings.push(`${t.family??"font"}: ${e.message}`),!1}}async _raw(t){const e=t.length;if(this.offset+=e,e>=M/2){await this._flush(),await this.sink.write(t);return}this.pos+e>M&&await this._flush(),this.buffer.set(t,this.pos),this.pos+=e}async _flush(){if(this.pos===0)return;const t=this.buffer.slice(0,this.pos);this.pos=0,await this.sink.write(t)}_w(t){return this._raw(W.encode(t))}_alloc(){const t=this.nextId++;if(t>=this.xref.length){const e=new Float64Array(this.xref.length*2);e.set(this.xref),this.xref=e}return t}async _obj(t,e){this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
2
2
|
${e}
|
|
3
3
|
endobj
|
|
4
4
|
`)}async _stream(t,e,s,{deflate:i=this.compress}={}){const n=this._alloc();this.xref[t]=this.offset,await this._w(`${t} 0 obj
|
|
5
5
|
<<${e} /Length ${n} 0 R${i?" /Filter /FlateDecode":""}>>
|
|
6
6
|
stream
|
|
7
|
-
`);const
|
|
7
|
+
`);const o=this.offset;if(i){const f=new CompressionStream("deflate"),r=f.writable.getWriter(),l=f.readable.getReader(),u=(async()=>{for(;;){const{done:d,value:p}=await l.read();if(d)return;await this._raw(p)}})().catch(d=>{throw r.abort(d).catch(L),d});try{await s(async d=>{await r.ready,await r.write(d)}),await r.close()}catch(d){throw r.abort(d).catch(L),await u.catch(L),d}await u}else await s(f=>this._raw(f));const h=this.offset-o;await this._w(`
|
|
8
8
|
endstream
|
|
9
9
|
endobj
|
|
10
|
-
`),await this._obj(n,String(
|
|
11
|
-
`)),c));const i=[...t.fonts].map(c=>`/F${c.resId} ${c.objectId} 0 R`).join(" "),n=[...t.images].map(c=>`/Im${c.resId} ${c.objectId} 0 R`).join(" "),
|
|
12
|
-
0 ${
|
|
10
|
+
`),await this._obj(n,String(h))}async _begin(){this.started||(this.started=!0,await this._raw(new Uint8Array([37,80,68,70,45,49,46,55,10,37,226,227,207,211,10])))}_stdFont(t){let e=this.stdFonts.get(t);return e===void 0&&(e=new it(t,this.nextFontRes++,this._alloc()),this.stdFonts.set(t,e)),e}_fontSpec(t){let e=this.specs.get(t);if(e!==void 0)return e;const s=/([\d.]+)(px|pt)\s+(.*)$/.exec(t),i=s?t.slice(0,s.index):"",n=s?Number(s[1])*(s[2]==="pt"?4/3:1):10,o=(s?s[3]:"sans-serif").split(",").map(d=>d.trim().replace(/^["']|["']$/g,"").toLowerCase()).filter(Boolean),h=/\bbold\b|\b[6-9]00\b/.test(i),f=/\b(italic|oblique)\b/.test(i),r=[];for(const d of o)for(const p of this.faces)p.familyKey===d&&p.bold===h&&p.italic===f&&!r.includes(p)&&r.push(p);const l=o[0]??"sans-serif",c=this._stdFont(st(l,h,f)),u=r[0]??c;return e={size:n,faces:r,std:c,hScale:!c.mono&&et.test(l)?.9:1,ascent:u.ascent,descent:u.descent},this.specs.set(t,e),e}_measure(t,e){const{size:s,faces:i,std:n,hScale:o}=e;let h=0;for(const f of t){let r=f.codePointAt(0);r<32&&(r=32);let l=null;for(let c=0;c<i.length;c++)if(i[c].gidOf(r)!==0){l=i[c];break}if(l!==null){h+=l.width(r);continue}y.has(r)||(r=N(r)),h+=n.width(r)*o}return h*s/1e3}_runs(t,e){const{size:s,faces:i,std:n,hScale:o}=e,h=[];let f=null;for(const r of t){let l=r.codePointAt(0);l<32&&(l=32);let c=null;for(let w=0;w<i.length;w++)if(i[w].gidOf(l)!==0){c=i[w];break}let u,d,p,m=1;if(c!==null)c.resId===0&&(c.resId=this.nextFontRes++,c.objectId=this._alloc()),u=c,d=F(c.use(l)),p=c.width(l);else{let w=y.get(l);w===void 0&&(this.missing.add(l),l=N(l),w=y.get(l)),u=n,d=j[w],p=n.width(l)*o,m=o}(f===null||f.font!==u)&&(f={font:u,hex:"",width:0,hScale:m},h.push(f)),f.hex+=d,f.width+=p*s/1e3}return h}async _writeFonts(){if(this.stdFonts.size>0){this.encodingId=this._alloc();const e=z.map(([,s])=>`/${s}`).join(" ");await this._obj(this.encodingId,`<< /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [1 ${e}] >>`);for(const s of this.stdFonts.values())await this._obj(s.objectId,`<< /Type /Font /Subtype /Type1 /BaseFont /${s.name} /Encoding ${this.encodingId} 0 R >>`)}let t=0;for(const e of this.faces)e.objectId!==0&&await this._writeFace(e,ut(t++))}async _writeFace(t,e){const s=t.subset(),i=this._alloc(),n=this._alloc(),o=this._alloc(),h=this._alloc();await this._stream(i,` /Length1 ${s.length}`,d=>P(s,d));const f=gt(t.unicode);await this._stream(n,"",d=>P(W.encode(f),d));const r=`${e}+${t.postscriptName}`,l=t.scale,c=4|(t.italic?64:0)|(t.bold?1<<18:0);await this._obj(o,`<< /Type /FontDescriptor /FontName /${r} /Flags ${c} /FontBBox [${t.bbox.map(d=>Math.round(d*l)).join(" ")}] /ItalicAngle ${b(t.italicAngle)} /Ascent ${Math.round(t.ascentUnits*l)} /Descent ${Math.round(t.descentUnits*l)} /CapHeight ${Math.round(t.capHeightUnits*l)} /StemV ${t.bold?140:80} /FontFile2 ${i} 0 R >>`);const u=[];for(let d=0;d<t.order.length;d++)u.push(Math.round(t._rawAdvance(t.order[d])*l));await this._obj(h,`<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${r} /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor ${o} 0 R /CIDToGIDMap /Identity /DW 1000 /W [0 [${u.join(" ")}]] >>`),await this._obj(t.objectId,`<< /Type /Font /Subtype /Type0 /BaseFont /${r} /Encoding /Identity-H /DescendantFonts [${h} 0 R] /ToUnicode ${n} 0 R >>`)}_image(t){const e=this.imageIds.get(t);if(e!==void 0)return e;let s;if(t.jpeg){const i=dt(t.jpeg);if(i===null)return null;s={kind:"jpeg",bytes:t.jpeg,...i}}else if(t.rgba||t.data)s={kind:"rgba",rgba:t.rgba??t.data,width:t.width,height:t.height};else{const i=wt(t);if(i===null)return null;s={kind:"rgba",rgba:i.data,width:i.width,height:i.height}}return s.resId=this.nextImageRes++,s.objectId=this._alloc(),this.imageIds.set(t,s),this.pendingImages.push(s),s}async _writeImage(t){const e=`/Type /XObject /Subtype /Image /Width ${t.width} /Height ${t.height} /BitsPerComponent 8`;if(t.kind==="jpeg"){const s=t.components===1?"/DeviceGray":t.components===4?"/DeviceCMYK":"/DeviceRGB",i=t.components===4?" /Decode [1 0 1 0 1 0 1 0]":"";await this._stream(t.objectId,` ${e} /ColorSpace ${s}${i} /Filter /DCTDecode`,n=>P(t.bytes,n),{deflate:!1})}else{const{rgba:s,width:i,height:n}=t,o=i*n;let h=!0;for(let r=3;r<o*4;r+=4)if(s[r]!==255){h=!1;break}let f="";if(!h){const r=this._alloc();await this._stream(r,` /Type /XObject /Subtype /Image /Width ${i} /Height ${n} /BitsPerComponent 8 /ColorSpace /DeviceGray`,async l=>{for(let c=0;c<o;c+=65536){const u=Math.min(65536,o-c),d=new Uint8Array(u);for(let p=0;p<u;p++)d[p]=s[(c+p)*4+3];await l(d)}}),f=` /SMask ${r} 0 R`}await this._stream(t.objectId,` ${e} /ColorSpace /DeviceRGB${f}`,async r=>{for(let l=0;l<o;l+=65536){const c=Math.min(65536,o-l),u=new Uint8Array(c*3);for(let d=0;d<c;d++){const p=(l+d)*4;u[d*3]=s[p],u[d*3+1]=s[p+1],u[d*3+2]=s[p+2]}await r(u)}})}t.rgba=null,t.bytes=null}beginPage(t,e){if(this.page!==null)throw new Error("Call endPage before the next beginPage");if(this.finished)throw new Error("The document is finished");return this.page=new ct(this,t,e),this.page}async endPage(){const t=this.page;if(t===null)return;for(this.page=null,await this._begin();t.stack.length>0;)t.restore();const e=this.pendingImages;this.pendingImages=[];for(const c of e)await this._writeImage(c);const s=this._alloc();await this._stream(s,"",c=>P(W.encode(t.ops.join(`
|
|
11
|
+
`)),c));const i=[...t.fonts].map(c=>`/F${c.resId} ${c.objectId} 0 R`).join(" "),n=[...t.images].map(c=>`/Im${c.resId} ${c.objectId} 0 R`).join(" "),o=[...t.alphas].map(c=>`/A${c} << /ca ${b(c/100)} /CA ${b(c/100)} >>`).join(" "),h=`${i?`/Font << ${i} >>`:""}${n?` /XObject << ${n} >>`:""}${o?` /ExtGState << ${o} >>`:""}`,f=[];for(const c of t.links){const u=this._alloc(),d=c.uri===void 0?`/Dest /${c.dest}`:`/A << /S /URI /URI ${ft(c.uri)} >>`;await this._obj(u,`<< /Type /Annot /Subtype /Link /Rect [${c.rect}] /Border [0 0 0] /F 4 ${d} >>`),f.push(`${u} 0 R`)}const r=this._level(0),l=this._alloc();if(this.pageIds.push(l),await this._obj(l,`<< /Type /Page /Parent ${r.id} 0 R /MediaBox [0 0 ${b(t.pageWidth)} ${b(t.pageHeight)}] /Contents ${s} 0 R${f.length?` /Annots [${f.join(" ")}]`:""} /Resources << ${h} >> >>`),await this._addKid(0,l,1),this.pageCount++,this.offset>Y)throw new Error("PDF exceeds the classic xref limit of 10 GB")}_level(t){let e=this.levels[t];return e===void 0&&(e={id:this._alloc(),kids:[],count:0},this.levels[t]=e),e}async _addKid(t,e,s){const i=this._level(t);if(i.kids.push(e),i.count+=s,i.kids.length<J)return;const n=this._level(t+1);await this._writeNode(i,n.id),this.levels[t]=void 0,await this._addKid(t+1,i.id,i.count)}_writeNode(t,e){const s=e===null?"":` /Parent ${e} 0 R`;return this._obj(t.id,`<< /Type /Pages${s} /Kids [${t.kids.map(i=>`${i} 0 R`).join(" ")}] /Count ${t.count} >>`)}async _closeTree(){let t=Math.max(0,this.levels.length-1);for(;t>0&&this.levels[t]===void 0;)t--;for(let s=0;s<t;s++){const i=this.levels[s];if(i===void 0||i.kids.length===0)continue;const n=this._level(s+1);await this._writeNode(i,n.id),n.kids.push(i.id),n.count+=i.count}const e=this._level(t);return await this._writeNode(e,null),e.id}destination(t,e,s){this.dests.set(t,{page:e,top:s})}bookmark(t,e){this.bookmarks.push({title:t,page:e})}async _writeNavigation(){let t="";const e=[...this.dests].filter(([,i])=>this.pageIds[i.page]!==void 0);if(e.length>0){const i=this._alloc();await this._obj(i,`<< ${e.map(([n,o])=>`/${n} [${this.pageIds[o.page]} 0 R /XYZ null ${b(o.top)} null]`).join(" ")} >>`),t+=` /Dests ${i} 0 R`}const s=this.bookmarks.filter(i=>this.pageIds[i.page]!==void 0);if(s.length>0){const i=this._alloc(),n=s.map(()=>this._alloc());for(let o=0;o<s.length;o++){const h=`${o>0?` /Prev ${n[o-1]} 0 R`:""}${o+1<n.length?` /Next ${n[o+1]} 0 R`:""}`;await this._obj(n[o],`<< /Title ${B(s[o].title)} /Parent ${i} 0 R${h} /Dest [${this.pageIds[s[o].page]} 0 R /Fit] >>`)}await this._obj(i,`<< /Type /Outlines /First ${n[0]} 0 R /Last ${n.at(-1)} 0 R /Count ${n.length} >>`),t+=` /Outlines ${i} 0 R`}return t}async finish(){if(this.finished)return;await this.endPage(),await this._begin(),this.finished=!0,await this._writeFonts();const t=await this._closeTree(),e=await this._writeNavigation(),s=this._alloc();await this._obj(s,`<< /Type /Catalog /Pages ${t} 0 R${e} /ViewerPreferences << /DisplayDocTitle true >> >>`);const i=this.options,n=lt(i.creationDate??new Date),o=[i.title?`/Title ${B(i.title)}`:"",i.author?`/Author ${B(i.author)}`:"",i.subject?`/Subject ${B(i.subject)}`:"",`/Producer ${B(i.producer??"8sheets")}`,`/CreationDate (${n})`].filter(Boolean).join(" "),h=this._alloc();await this._obj(h,`<< ${o} >>`);const f=this.offset,r=this.nextId;await this._w(`xref
|
|
12
|
+
0 ${r}
|
|
13
13
|
0000000000 65535 f
|
|
14
|
-
`);let
|
|
15
|
-
`,
|
|
16
|
-
<< /Size ${
|
|
14
|
+
`);let l="";for(let u=1;u<r;u++)l+=`${String(this.xref[u]).padStart(10,"0")} 00000 n
|
|
15
|
+
`,l.length>=32768&&(await this._w(l),l="");await this._w(l);const c=mt();await this._w(`trailer
|
|
16
|
+
<< /Size ${r} /Root ${s} 0 R /Info ${h} 0 R /ID [<${c}> <${c}>] >>
|
|
17
17
|
startxref
|
|
18
|
-
${
|
|
18
|
+
${f}
|
|
19
19
|
%%EOF
|
|
20
|
-
`),await this._flush()}}async function P(
|
|
20
|
+
`),await this._flush()}}async function P(a,t){for(let e=0;e<a.length;e+=M)await t(a.subarray(e,Math.min(a.length,e+M)))}function ut(a){let t="",e=a;for(let s=0;s<6;s++)t=String.fromCharCode(65+e%26)+t,e=Math.floor(e/26);return t}function pt(a){if(a<=65535)return F(a);const t=a-65536;return F(55296+(t>>10))+F(56320+(t&1023))}function gt(a){const t=[],e=[];for(let s=1;s<a.length;s++)a[s]!==void 0&&e.push(`<${F(s)}> <${pt(a[s])}>`);for(let s=0;s<e.length;s+=100){const i=e.slice(s,s+100);t.push(`${i.length} beginbfchar`,...i,"endbfchar")}return`/CIDInit /ProcSet findresource begin
|
|
21
21
|
12 dict begin
|
|
22
22
|
begincmap
|
|
23
23
|
/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def
|
|
@@ -32,4 +32,4 @@ endcmap
|
|
|
32
32
|
CMapName currentdict /CMap defineresource pop
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
`}function
|
|
35
|
+
`}function mt(){const a=new Uint8Array(16);return globalThis.crypto.getRandomValues(a),[...a].map(t=>j[t]).join("")}function wt(a){const t=a.naturalWidth??a.videoWidth??a.width,e=a.naturalHeight??a.videoHeight??a.height;if(!t||!e)return null;try{const i=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(t,e):Object.assign(document.createElement("canvas"),{width:t,height:e})).getContext("2d");return i.drawImage(a,0,0),i.getImageData(0,0,t,e)}catch{return null}}export{ct as PdfPageContext,bt as PdfWriter};
|