@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/print/render-page.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{hasCellTypes as q}from"../core/cell-type-rules.js";import{readingDirection as at,visualOrder as ht,wrapsByAlign as dt}from"../cells/text-layout.js";import{gradientPatches as
|
|
2
|
-
`)){let r="";for(const h of
|
|
3
|
-
`).forEach((
|
|
1
|
+
import{hasCellTypes as q}from"../core/cell-type-rules.js";import{hasConditionalFormats as ct}from"../core/host-rules.js";import{readingDirection as at,visualOrder as ht,wrapsByAlign as dt}from"../cells/text-layout.js";import{gradientPatches as j}from"../cells/paint.js";import{paintWatermarks as ut}from"../shapes/watermark.js";import{BOOL as mt,CHUNK_BITS as Q,CHUNK_MASK as W,EMPTY as X,ERR as tt,ERRORS as gt,KIND_MASK as $,NUM as L,STR as v,FORMULA as et,SPILL as nt}from"../core/sheet.js";import{isBarcodeText as pt,paintBarcodeValue as bt}from"../celltypes/barcode.js";import{printCellType as ot,printEmptyTypedCells as kt}from"../celltypes/cell-types.js";import{FILL_MARK as it,fitGeneral as wt,formatGeneral as yt,getFormatter as K}from"../core/numfmt.js";import{colName as Tt}from"../core/address.js";import{cssFont as E}from"../core/styles.js";import{CondFormats as xt}from"../core/cond-format.js";import{drawCfIcon as St,iconSide as Dt,monoContext as Ot,paintCfBar as At}from"../cells/cf-paint.js";import{sparklineIndex as Pt}from"../core/sparklines.js";import{paintSparkline as Rt}from"../sparklines/excel-paint.js";import{isSparklineText as Ft,paintSparklineValue as Ct}from"../sparklines/paint.js";import{paintSparkRulesOnPage as Mt,sparkRuleHidesValue as It}from"../sparklines/rule.js";import{preparePicturesForPrint as zt}from"../sparklines/print.js";import{tableColors as Nt,tablesOf as vt}from"../core/tables.js";import{paintCustomTable as Ht}from"../slicers/custom-styles.js";import{resolveColor as Lt}from"../io/xlsx-styles.js";import{parseHeaderFooter as Wt}from"./page-setup.js";import{linkRegion as Et}from"./pdf-links.js";import{paintNotePage as Bt}from"./note-pages.js";const _t=2,Gt=6,Xt=32,U="#000000",Y=.25,V=10,$t={hair:.25,thin:.5,dotted:.5,dashed:.5,dashDot:.5,dashDotDot:.5,medium:1,mediumDashed:1,mediumDashDot:1,mediumDashDotDot:1,slantDashDot:1,thick:1.5,double:.5},Kt={hair:[.5,.75],dotted:[.5,1.5],dashed:[3,1.5],dashDot:[3,1.5,.75,1.5],dashDotDot:[3,1.5,.75,1.5,.75,1.5],mediumDashed:[4,2],mediumDashDot:[4,2,1,2],mediumDashDotDot:[4,2,1,2,1,2],slantDashDot:[4,1,1,1]},st=new WeakMap;function J(t){let s=st.get(t);return s===void 0&&(s=E(t,t.fontSize),st.set(t,s)),s}function Ut(t,s,f,i){switch(s){case L:return i.numFmt==="General"?yt(f):K(i.numFmt).number(f,t.dateOffset);case v:{const b=t.strings.get(f);return i.numFmt==="General"||i.numFmt==="@"?b:K(i.numFmt).text(b)}case mt:return f?"TRUE":"FALSE";case tt:return gt[f]??"#N/A";default:return""}}class Yt{constructor(s,f,i,b){this.ctx=s,this.book=f,this.sheet=i,this.styles=f.styles.list,this.mono=b.blackAndWhite,this.errors=b.errors,this.cfFrame=null,this.tables=null,this.font="",this.ink="",this.wrapCache=new Map,this.reachX=null}style(s,f){return this.styles[this.sheet.style(s,f)]??this.styles[0]}textStyle(s,f,i,b,o){let e=this.style(s,f);const r=this.cfFrame===null?void 0:this.cfFrame.get(s*16384+f);if(r!==void 0){if(r.icon&&this.icon(r.icon,i,b,o,e),r.hideValue)return null;(r.color||r.numFmt!==void 0||r.bold!==void 0||r.italic!==void 0||r.underline!==void 0||r.strike!==void 0)&&(e={...e,color:r.color??e.color,numFmt:r.numFmt??e.numFmt,bold:r.bold??e.bold,italic:r.italic??e.italic,underline:r.underline??e.underline,strike:r.strike??e.strike})}if(this.tables!==null)for(const h of this.tables){if(s<h.r0||s>h.r1||f<h.c0||f>h.c1||!h._colors)continue;const d=h._colors.format(h,s,f);e={...e,color:e.color??d.color,bold:e.bold||d.bold===!0,italic:e.italic||d.italic===!0},d.underline&&!e.underline&&(e.underline=d.underline),d.strike&&(e.strike=!0);break}return e}icon(s,f,i,b,o){const e=Dt(b,1,o.fontSize),r=o.vAlign==="top"?i+1:o.vAlign==="center"?i+(b-e)/2:i+b-e-1;St(this.mono?Ot(this.ctx):this.ctx,s.name,s.level,f+1,r,e),this.ink=""}setFont(s){this.font!==s&&(this.ctx.font=s,this.font=s)}setInk(s){this.ink!==s&&(this.ctx.fillStyle=s,this.ink=s)}reset(){this.font="",this.ink=""}width(s){return this.ctx.measureText(s).width}richLine(s,f,i,b,o,e,r,h,d){const{ctx:x}=this,a=[];let k=0,u=0;f.forEach((T,D)=>{const w=f[D+1]?.at??s.length;if(w<=T.at)return;const S={...i,fontName:T.name??i.fontName,fontSize:T.sz??i.fontSize,bold:T.b??i.bold,italic:T.i??i.italic},P=J(S);this.setFont(P);const z=s.slice(T.at,w).replace(/\n/g," "),F=x.measureText(z).width;a.push({piece:z,font:P,ink:T.color??i.color??"#000000",pw:F}),k+=F,u=Math.max(u,S.fontSize)});const p=i.vAlign??"bottom",M=p==="top"?e+u*1.05:p==="center"?e+(h+u*.72)/2:e+h-3;let I=b==="right"?o+r-d-k:b==="center"||b==="centerContinuous"?o+(r-k)/2:o+d;x.textAlign="left";for(const T of a)this.setFont(T.font),this.setInk(T.ink),x.fillText(T.piece,I,M),I+=T.pw}text(s,f,i,b,o,e,r,h,d,x=!1){const{ctx:a,sheet:k}=this,u=this.reachX===null?this.textStyle(s,f,o,e,h):this.style(s,f);if(u===null)return;if(q(k)&&this.reachX===null&&ot(a,this.book,k,s,f,o,e,r,h)){this.reset();return}if(i===L&&b===0&&k.hideZeros)return;if(u.ext?.pad){const[c,y,R,N]=u.ext.pad;o+=N,e+=c,r=Math.max(0,r-N-y),h=Math.max(0,h-c-R)}let p=Ut(this.book,i,b,u);if(i===tt&&this.errors!=="displayed"&&(p=this.errors==="blank"?"":this.errors==="dash"?"--":"#N/A"),p===""||i===v&&pt(p)&&(k.kind(s,f)&(et|nt))!==0&&bt(a,p,o,e,r,h,1)||i===v&&Ft(p)&&(k.kind(s,f)&(et|nt))!==0&&Ct(a,p,o,e,r,h,1,{ink:u.color??"#000000",snap:!1,mono:this.mono})||k.sparkRules!==null&&It(k,s,f))return;const M=J(u);this.setFont(M);let I=u.color??"#000000";i===L&&u.numFmt!=="General"&&(I=K(u.numFmt).color(b)??I),this.setInk(this.mono?"#000000":I);const T=_t,D=i===v?at(u.readingOrder,p):null;i===v&&!("direction"in a)&&(p=ht(p,D==="rtl")),D==="rtl"&&"direction"in a?(a.direction="rtl",this.pendingDirection=!0):this.pendingDirection&&(a.direction="ltr",this.pendingDirection=!1);const w=u.hAlign??(i===L||D==="rtl"?"right":i===v?"left":"center");if(w==="centerContinuous")for(let c=f+1;(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null&&this.book.styles.get(k.style(s,c)).hAlign==="centerContinuous";c++)r+=k.cols.sizeOf(c);const S=r-T*2,P=u.fontSize;if(this.reachX!==null&&(u.rotation!==0||u.wrap))return;if(u.rotation!==0){this.rotated(p,u,o,e,r,h);return}if(u.wrap||dt(u)){this.wrapped(p,u,w,o,e,r,h,T,P);return}const z=i===v?this.book.strings.rich?.get(b):void 0;if(z!==void 0&&!this.mono){this.richLine(p,z,u,w,o,e,r,h,T);return}const F=u.vAlign??"bottom";let A;if(F==="top"?A=e+P*1.05:F==="center"?A=e+(h+P*.72)/2:A=e+h-3,p.indexOf(it)>=0){if(this.reachX!==null)return;const c=p.split(it),y=c[0],R=c[1]??" ",N=c.slice(2).join("");a.textAlign="left",y&&a.fillText(y,o+T,A);const H=this.width(y),_=this.width(N);if(R!==" "){const G=this.width(R)||1,Z=Math.floor((S-H-_)/G);Z>0&&a.fillText(R.repeat(Z),o+T+H,A)}a.textAlign="right",N&&a.fillText(N,o+r-T,A),a.textAlign="left";return}let O=this.width(p);if(O>S&&i===L&&(u.numFmt==="General"&&(p=wt(b,c=>this.width(c)<=S),O=this.width(p)),O>S)){const c=this.width("#")||1;p="#".repeat(Math.max(1,Math.floor(S/c))),O=c*p.length}let C=!1;if(u.shrink&&O>S&&S>0&&(this.setFont(E(u,P*(S/O))),O=S,C=!0),u.indent>0){const c=u.indent*Gt;w==="left"?(o+=c,r-=c):w==="right"&&(r-=c)}let n,l=!1,m=o,g=o+r;if(w==="center"||w==="centerContinuous")n=o+(r-O)/2;else if(w==="right")n=o+r-T-O;else if(w==="fill"){const c=Math.max(1,Math.floor(S/(O||1)));p=p.repeat(c),O*=c,n=o+T}else n=o+T;if(this.reachX!==null&&n+O<=this.reachX){C&&this.setFont(M);return}if(O>S||n<o+T)if(x)l=!0;else if(i===v){if(n+O>g){let c=f+1,y=g;for(;y<n+O&&c<=d.c1&&(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null;)y+=k.cols.sizeOf(c),c++;g=y}if(n<m){let c=f-1,y=m;for(;y>n&&c>=d.c0&&(k.kind(s,c)&15)===0&&k.mergeAt(s,c)===null;)y-=k.cols.sizeOf(c),c--;m=y}l=n+O>g||n<m}else l=!0;a.textAlign="left",l?(a.save(),a.beginPath(),a.rect(m,e,g-m,h),a.clip(),a.fillText(p,n,A),this.decorate(u,n,A,O,P),a.restore()):(a.fillText(p,n,A),(u.underline!==0||u.strike)&&this.decorate(u,n,A,O,P)),C&&this.setFont(M)}decorate(s,f,i,b,o){const{ctx:e}=this,r=Math.max(.5,o/14);if(s.underline!==0){const h=i+o*.14;e.fillRect(f,h,b,r),s.underline===2&&e.fillRect(f,h+r*2,b,r)}s.strike&&e.fillRect(f,i-o*.3,b,r)}wrapLines(s,f,i){const b=`${s}|${Math.round(i)}|${f}`;let o=this.wrapCache.get(b);if(o!==void 0)return o;o=[];for(const e of f.split(`
|
|
2
|
+
`)){let r="";for(const h of e.split(/(?<=\s)/)){const d=r+h;for(r!==""&&this.width(d.trimEnd())>i?(o.push(r.trimEnd()),r=h):r=d;this.width(r.trimEnd())>i&&r.length>1;){let x=r.length-1;for(;x>1&&this.width(r.slice(0,x))>i;)x--;o.push(r.slice(0,x)),r=r.slice(x)}}o.push(r.trimEnd())}return this.wrapCache.size>4096&&this.wrapCache.clear(),this.wrapCache.set(b,o),o}wrapped(s,f,i,b,o,e,r,h,d){const{ctx:x}=this,a=this.wrapLines(J(f),s,e-h*2),k=Math.round(d*1.26),u=a.length*k,p=f.vAlign??"bottom";let M;p==="top"?M=o:p==="center"?M=o+(r-u)/2:M=o+r-u,x.save(),x.beginPath(),x.rect(b,o,e,r),x.clip(),x.textAlign=i==="center"?"center":i==="right"?"right":"left";const I=i==="center"?b+e/2:i==="right"?b+e-h:b+h;for(let T=0;T<a.length;T++){const D=M+T*k+Math.round(k*.8);D+k<o||D-k>o+r||x.fillText(a[T],I,D)}x.restore(),x.textAlign="left"}rotated(s,f,i,b,o,e){const{ctx:r}=this;r.save(),r.beginPath(),r.rect(i,b,o,e),r.clip(),r.translate(i+o/2,b+e/2);const h=f.rotation;if(r.textAlign="center",h===255){const d=f.fontSize*1.1,x=-((s.length-1)*d)/2;for(let a=0;a<s.length;a++)r.fillText(s[a],0,x+a*d)}else{const d=h>90?90-h:h;r.rotate(-d*Math.PI/180),r.fillText(s,0,f.fontSize*.35)}r.restore(),r.textAlign="left"}side(s,f,i,b,o){if(!s)return;const{ctx:e}=this,r=$t[s.style]??.5;if(e.strokeStyle=this.mono?"#000000":s.color??"#000000",e.lineWidth=r,e.setLineDash(Kt[s.style]??[]),e.beginPath(),s.style==="double"){const h=i===o?0:.75,d=i===o?.75:0;e.moveTo(f-h,i-d),e.lineTo(b-h,o-d),e.moveTo(f+h,i+d),e.lineTo(b+h,o+d)}else e.moveTo(f,i),e.lineTo(b,o);e.stroke()}}function rt(t,s,f){const i=new Float64Array(f-s+2);let b=0;for(let o=s;o<=f;o++)i[o-s]=b,b+=t.sizeOf(o);return i[f-s+1]=b,i}function Vt(t,s,f,i,b){const{ctx:o,sheet:e}=t,{x:r,y:h,r0:d,r1:x,c0:a,c1:k}=s,u=rt(e.cols,a,k),p=rt(e.rows,d,x),M=k-a+1,I=x-d+1,T=u[M],D=p[I];if(T<=0||D<=0)return;if(o.save(),o.beginPath(),o.rect(r,h,T,D),o.clip(),t.reset(),f){o.strokeStyle=U,o.lineWidth=Y,o.setLineDash([]),o.beginPath();for(let n=0;n<=M;n++)n>0&&u[n]===u[n-1]||(o.moveTo(r+u[n],h),o.lineTo(r+u[n],h+D));for(let n=0;n<=I;n++)n>0&&p[n]===p[n-1]||(o.moveTo(r,h+p[n]),o.lineTo(r+T,h+p[n]));o.stroke()}const w=e.mergesInRows(d,x).filter(n=>n.c1>=a&&n.c0<=k),S=w.length>0,P=e.rowStyles!==null||e.colStyles!==null,z=t.styles[0].fill===null&&t.styles[0].borders===null;t.tables=null;const{book:F}=t;if(F.engine&&F.engine.tables.size>0){const n=vt(F,e);n.length>0&&(t.tables=n);for(const l of n){if(l.r1<d||l.r0>x||l.c1<a||l.c0>k)continue;const m=Nt(l.styleName,F.theme);m&&(l._colors=m,Ht(o,l,m,{ra:d,rb:x,ca:a,cb:k,xs:u,ys:p,ox:r,oy:h,line:.5,noFill:t.mono,setInk:g=>t.setInk(t.mono?"#000000":g)}))}}let A=null;for(let n=a;n<=k;n++){const l=u[n-a+1]-u[n-a];if(l===0)continue;const m=e.columns[n];if(!(m===void 0&&!P&&z))for(let g=d;g<=x;g++){if(!P&&z){const R=m[g>>>Q];if(R===void 0||R.styles===null){g|=W;continue}if(R.styles[g&W]===0)continue}const c=p[g-d+1]-p[g-d];if(c===0)continue;const y=t.style(g,n);y.fill===null&&y.borders===null||S&&e.mergeAt(g,n)!==null||(y.fill!==null&&!t.mono&&(y.gradient?j(y.gradient,r+u[n-a],h+p[g-d],l,c,(R,N,H,_,G)=>{t.setInk(R),o.fillRect(N,H,_,G)}):(t.setInk(ft(y)),o.fillRect(r+u[n-a],h+p[g-d],l,c))),y.borders!==null&&(A??=[]).push(g,n,y.borders))}}const O=n=>{const l=r+e.cols.offsetOf(n.c0)-e.cols.offsetOf(a),m=h+e.rows.offsetOf(n.r0)-e.rows.offsetOf(d);return{x:l,y:m,w:e.cols.offsetOf(n.c1+1)-e.cols.offsetOf(n.c0),h:e.rows.offsetOf(n.r1+1)-e.rows.offsetOf(n.r0)}};for(const n of w){const l=O(n),m=t.style(n.r0,n.c0);(f||m.fill!==null&&!t.mono)&&(m.gradient&&!t.mono?j(m.gradient,l.x,l.y,l.w,l.h,(g,c,y,R,N)=>{t.setInk(g),o.fillRect(c,y,R,N)}):(t.setInk(m.fill!==null&&!t.mono?ft(m):"#ffffff"),o.fillRect(l.x,l.y,l.w,l.h))),f&&(o.strokeStyle=U,o.lineWidth=Y,o.setLineDash([]),o.strokeRect(l.x,l.y,l.w,l.h))}if(t.cfFrame=null,ct(e)){e.cfEval||(e.cfEval=new xt(F,e,l=>Lt(l,F.theme??[])));const n=new Map;t.cfFrame=n;for(let l=a;l<=k;l++){const m=u[l-a+1]-u[l-a];for(let g=d;g<=x;g++){const c=e.cfEval.at(g,l);if(c===null)continue;n.set(g*16384+l,c);const y=r+u[l-a],R=h+p[g-d],N=p[g-d+1]-p[g-d];c.noFill&&!t.mono&&(t.setInk("#FFFFFF"),o.fillRect(y,R,m,N)),c.fill&&!t.mono&&(t.setInk(c.fill),o.fillRect(y,R,m,N)),c.bar&&!t.mono&&(At(o,c.bar,y,R,m,N,1,!1,!0),t.ink=""),c.borders&&(A??=[]).push(g,l,c.borders)}}}if(A!==null)for(let n=0;n<A.length;n+=3){const l=A[n],m=A[n+1],g=A[n+2],c=r+u[m-a],y=r+u[m-a+1],R=h+p[l-d],N=h+p[l-d+1];t.side(g.t,c,R,y,R),t.side(g.b,c,N,y,N),t.side(g.l,c,R,c,N),t.side(g.r,y,R,y,N),g.d&&g.down&&t.side(g.d,c,R,y,N),g.d&&g.up&&t.side(g.d,c,N,y,R)}for(const n of w){const l=O(n);for(let m=n.c0;m<=n.c1;m++){const g=e.cols.sizeOf(m),c=l.x+e.cols.offsetOf(m)-e.cols.offsetOf(n.c0),y=t.style(n.r0,m).borders;y?.t&&t.side(y.t,c,l.y,c+g,l.y);const R=t.style(n.r1,m).borders;R?.b&&t.side(R.b,c,l.y+l.h,c+g,l.y+l.h)}for(let m=n.r0;m<=n.r1;m++){const g=e.rows.sizeOf(m),c=l.y+e.rows.offsetOf(m)-e.rows.offsetOf(n.r0),y=t.style(m,n.c0).borders;y?.l&&t.side(y.l,l.x,c,l.x,c+g);const R=t.style(m,n.c1).borders;R?.r&&t.side(R.r,l.x+l.w,c,l.x+l.w,c+g)}}if(e.sparklines&&e.sparklines.length>0&&F.engine)for(const[n,l]of Pt(e)){const m=Math.floor(n/16384),g=n-m*16384;m<d||m>x||g<a||g>k||Rt(o,F.engine,e,l,m,g,r+u[g-a],h+p[m-d],u[g-a+1]-u[g-a],p[m-d+1]-p[m-d],1,{snap:!1,mono:t.mono})}e.sparkRules!==null&&Mt(o,F,e,{r0:d,r1:x,c0:a,c1:k,xs:u,ys:p,ox:r,oy:h,mono:t.mono}),t.reset(),o.textBaseline="alphabetic",o.textAlign="left";const C={c0:a,c1:k};for(let n=a;n<=k;n++){const l=r+u[n-a],m=u[n-a+1]-u[n-a];if(m===0)continue;const g=e.columns[n];if(g!==void 0)for(let c=d;c<=x;c++){const y=g[c>>>Q];if(y===void 0){c|=W;continue}const R=c&W,N=y.kinds[R]&$;if(N===X||S&&e.mergeAt(c,n)!==null)continue;const H=p[c-d+1]-p[c-d];H!==0&&t.text(c,n,N,y.values[R],l,h+p[c-d],m,H,C)}}if(i<a)for(let n=d;n<=x;n++){const l=p[n-d+1]-p[n-d];if(l===0||e.kind(n,a)!==0)continue;let m=0;for(let g=a-1;g>=Math.max(i,a-Xt);g--){m+=e.cols.sizeOf(g);const c=e.kind(n,g)&$;if(c!==X){c===v&&e.mergeAt(n,g)===null&&(t.reachX=r,t.text(n,g,c,e.value(n,g),r-m,h+p[n-d],e.cols.sizeOf(g),l,C),t.reachX=null);break}}}for(const n of w){const l=e.kind(n.r0,n.c0)&$;if(l===X)continue;const m=O(n);t.text(n.r0,n.c0,l,e.value(n.r0,n.c0),m.x,m.y,m.w,m.h,C,!0)}q(e)&&kt(t.book,e,d,x,a,k,(n,l)=>{ot(t.ctx,t.book,e,n,l,r+u[l-a],h+p[n-d],u[l-a+1]-u[l-a],p[n-d+1]-p[n-d]),t.reset()}),b&&(t.reset(),b(s),t.reset()),o.restore(),t.reset()}function Jt(t,s,f){const{ctx:i,sheet:b}=t,{headingW:o,headingH:e,titleW:r,titleH:h}=s,d=r+s.bodyW,x=h+s.bodyH;i.strokeStyle=U,i.lineWidth=Y,i.setLineDash([]),t.reset(),i.font=f,i.textBaseline="alphabetic",i.textAlign="center",t.setInk("#000000");const a=3;i.strokeRect(0,0,o+d,e),i.strokeRect(0,0,o,e+x);const k=(p,M,I)=>{let T=I;for(let D=p;D<=M;D++){const w=b.cols.sizeOf(D);w>0&&(i.beginPath(),i.moveTo(T+w,0),i.lineTo(T+w,e),i.stroke(),i.fillText(Tt(D),T+w/2,e-a)),T+=w}},u=(p,M,I)=>{let T=I;for(let D=p;D<=M;D++){const w=b.rows.sizeOf(D);w>0&&(i.beginPath(),i.moveTo(0,T+w),i.lineTo(o,T+w),i.stroke(),i.fillText(String(D+1),o/2,T+w-a)),T+=w}};s.titleCols&&k(s.titleCols.c0,s.titleCols.c1,o),k(s.c0,s.c1,o+r),s.titleRows&&u(s.titleRows.r0,s.titleRows.r1,e),u(s.r0,s.r1,e+h),i.textAlign="left"}const B=new Map;function Zt(t){let s=B.get(t);return s===void 0&&(s=Wt(t),B.size>256&&B.clear(),B.set(t,s)),s}function qt(t,s){switch(t.field){case"page":return String(s.pageNumber+(t.offset??0));case"pages":return String(s.totalPages);case"date":return s.now.toLocaleDateString(s.locale);case"time":return s.now.toLocaleTimeString(s.locale,{hour:"2-digit",minute:"2-digit"});case"file":return s.fileName;case"sheet":return s.sheetName;case"path":return s.filePath;default:return""}}function jt(t,s){const f=[[]];for(const i of t)(i.field?qt(i,s):i.text).split(`
|
|
3
|
+
`).forEach((e,r)=>{r>0&&f.push([]),e&&f[f.length-1].push({...i,text:e})});return f}function Qt(t,s,f,i,b,o=null){const{setup:e,paper:r}=s,h=e.margins,d=i.pageNumber%2===0,x=w=>e.differentFirst&&i.sheetPage===0?w.first:e.differentOddEven&&d?w.even:w.odd,a=x(e.header),k=x(e.footer);if(!a&&!k)return;const u=i.defaultStyle,p=(e.alignWithMargins?h.left:.7)*72,M=r.width-(e.alignWithMargins?h.right:.7)*72;t.save(),t.textBaseline="alphabetic",t.textAlign="left";const I=(w,S,P,z)=>{const F=w.map(C=>{const n=(C.size??V)*b*(C.script!==0?.66:1),l=E({...u,fontName:C.font??u.fontName,bold:C.bold,italic:C.italic},n);return t.font=l,{run:C,size:n,font:l,width:t.measureText(C.text).width}});let A=0;for(const C of F)A+=C.width;let O=P==="center"?S-A/2:P==="right"?S-A:S;for(const{run:C,size:n,font:l,width:m}of F){t.font=l;const g=e.blackAndWhite?"#000000":C.color??"#000000";t.fillStyle=g;const c=z-(C.script===1?n*.5:C.script===-1?-n*.2:0);t.fillText(C.text,O,c);const y=Math.max(.4,n/14);C.underline&&(t.fillRect(O,c+n*.14,m,y),C.underline===2&&t.fillRect(O,c+n*.14+y*2,m,y)),C.strike&&t.fillRect(O,c-n*.3,m,y),O+=m}},T=w=>{let S=V;return w.length>0&&(S=Math.max(...w.map(P=>P.size??V))),S*b*1.2},D=(w,S,P,z)=>{if(w.length===0)return;const F=jt(w,i);if(z){let A=h.header*72;for(const O of F){const C=T(O);I(O,S,P,A+C*.8),A+=C}}else{let A=r.height-h.footer*72;for(let O=F.length-1;O>=0;O--){const C=T(F[O]);I(F[O],S,P,A-C*.2),A-=C}}};for(const[w,S]of[[a,!0],[k,!1]]){if(!w)continue;const P=Zt(w),z=o?.[S?"header":"footer"];z!=="L"&&D(P.left,p,"left",S),z!=="C"&&D(P.center,r.width/2,"center",S),z!=="R"&&D(P.right,M,"right",S)}t.restore()}function te(t,s){t.translate((s.paperW-2*s.originX)/s.scale,0),t.scale(-1,1);const f=Object.prototype.hasOwnProperty.call(t,"fillText"),i=t.fillText;return t.fillText=function(o,e,r){const h=t.measureText(o).width,d=t.textAlign,x=d==="right"||d==="end"?e-h:d==="center"?e-h/2:e;t.save(),t.scale(-1,1),t.textAlign="left",i.call(t,o,-x-h,r),t.restore()},()=>{f?t.fillText=i:delete t.fillText}}function lt(t,s,f,i={}){const{book:b,sheet:o,setup:e}=s,r=b.styles.list[0];t.save(),i.background!==!1&&(t.fillStyle="#ffffff",t.fillRect(0,0,f.paperW,f.paperH)),ut(t,o,f,i.sheetPage??f.index,e);const h={pageNumber:i.pageNumber??f.index+1,totalPages:i.totalPages??s.pageCount,sheetPage:i.sheetPage??f.index,fileName:i.fileName??b.fileName??"",filePath:i.filePath??"",sheetName:o.name,now:i.now??new Date,locale:i.locale,defaultStyle:r};if(Qt(t,s,f,h,e.scaleWithDoc?f.scale:1),f.noteLines){Bt(t,f),t.restore();return}t.save(),t.translate(f.originX,f.originY),t.scale(f.scale,f.scale);const d=o.rtl===!0?te(t,f):null,x=new Yt(t,b,o,e),{headingW:a,headingH:k,titleW:u,titleH:p,titleRows:M,titleCols:I,r0:T,r1:D,c0:w,c1:S,area:P}=f,z=e.gridLines&&!e.draft;e.headings&&Jt(x,f,E(r,r.fontSize));const F=i.objectPainters??null,A=F&&F.length>0?l=>{const m=l.x-o.cols.offsetOf(l.c0),g=l.y-o.rows.offsetOf(l.r0),c={printing:!0,dpr:1,zoom:1,hx:l.x,hy:l.y,cssW:l.x+o.cols.offsetOf(l.c1+1)-o.cols.offsetOf(l.c0),cssH:l.y+o.rows.offsetOf(l.r1+1)-o.rows.offsetOf(l.r0),toScreen:(y,R)=>({x:m+y,y:g+R}),sheet:o};for(const y of F)y(t,c)}:null;if(f.chartBox){if(F){const l={printing:!0,dpr:1,zoom:1,hx:0,hy:0,cssW:f.bodyW,cssH:f.bodyH,toScreen:(m,g)=>({x:m,y:g}),sheet:o,chartBox:f.chartBox};for(const m of F)m(t,l)}t.restore(),t.restore();return}const O=a+u,C=k+p,n=(l,m)=>{Vt(x,l,z,m,A),t.link&&i.onPlace&&Et(t,b,o,l,i.onPlace)};n({x:O,y:C,r0:T,r1:D,c0:w,c1:S},P.c0),M&&n({x:O,y:k,r0:M.r0,r1:M.r1,c0:w,c1:S},P.c0),I&&n({x:a,y:C,r0:T,r1:D,c0:I.c0,c1:I.c1},I.c0),M&&I&&n({x:a,y:k,r0:M.r0,r1:M.r1,c0:I.c0,c1:I.c1},I.c0),d?.(),t.restore(),t.restore()}function Pe(t,s,f,{pxPerPt:i=2,...b}={}){const o=s.at(f);if(o===null)return null;const{page:e,pagination:r}=o;t.width=Math.max(1,Math.round(e.paperW*i)),t.height=Math.max(1,Math.round(e.paperH*i));const h=t.getContext("2d",{alpha:!1});return h.setTransform(i,0,0,i,0,0),lt(h,r,e,{pageNumber:o.pageNumber,totalPages:o.totalPages,sheetPage:o.sheetPage,...b}),o}const ee=()=>new Promise(t=>setTimeout(t,0)),ne={gray0625:.0625,gray125:.125,lightGray:.25,mediumGray:.5,darkGray:.75,lightHorizontal:.25,lightVertical:.25,lightDown:.25,lightUp:.25,lightGrid:.44,lightTrellis:.5,darkHorizontal:.5,darkVertical:.5,darkDown:.5,darkUp:.5,darkGrid:.5,darkTrellis:.75};function ft(t){if(!t.pattern)return t.fill;const s=ne[t.pattern.type]??.5,f=i=>{const b=parseInt(t.pattern.fg.slice(i,i+2),16),o=parseInt(t.fill.slice(i,i+2),16);return Math.round(b*s+o*(1-s)).toString(16).padStart(2,"0")};return`#${f(1)}${f(3)}${f(5)}`}async function Re(t,s,f={}){const{title:i,author:b,subject:o,fonts:e,compress:r,signal:h,onProgress:d,...x}=f,[{PdfWriter:a}]=await Promise.all([import("./pdf.js"),zt(t)]),k=new a(s,{title:i,author:b,subject:o,fonts:e,compress:r}),u=x.now??new Date;let p=performance.now();const M=new Map,I=(D,w,S)=>{const P=`${t.book.sheets.indexOf(D)}:${w}:${S}`;if(!M.has(P)){const z=t.entries.find(A=>A.sheet===D),F=z?z.pagination.pageAt(w,S):-1;if(M.set(P,F<0?null:`L${M.size}`),F>=0){const A=z.pagination.page(F),O=A.headingH+A.titleH+D.rows.offsetOf(w)-D.rows.offsetOf(A.r0);k.destination(M.get(P),z.first+F,A.paperH-A.originY-O*A.scale)}}return M.get(P)};let T=null;for(let D=0;D<t.pageCount;D++){h?.throwIfAborted();const w=t.at(D),{page:S,pagination:P}=w;P.sheet!==T&&(T=P.sheet,k.bookmark(T.name,D));const z=k.beginPage(S.paperW,S.paperH);lt(z,P,S,{...x,now:u,onPlace:I,background:!1,pageNumber:w.pageNumber,totalPages:w.totalPages,sheetPage:w.sheetPage}),await k.endPage(),d?.(D+1,t.pageCount),performance.now()-p>12&&(await ee(),p=performance.now())}return k.bookmarks.length<2&&(k.bookmarks.length=0),await k.finish(),{pages:k.pageCount,bytes:k.offset,missing:[...k.missing],fontWarnings:k.fontWarnings}}export{Ut as displayText,Qt as paintHeaderFooter,Pe as renderJobPageToCanvas,lt as renderPage,Re as writeJobPdf};
|
package/table-view/files.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Workbook as
|
|
1
|
+
import{Workbook as B}from"../core/workbook.js";import{BOOL as T,ERR as O,NUM as D,STR as F}from"../core/sheet.js";import{Engine as W}from"../calc/engine.js";import{readCsv as _,CsvWriter as Z}from"../io/csv.js";import{ansiEncoding as H}from"../io/encoding.js";import{buildBlock as U,newBlockBuffers as G}from"../io/export-blocks.js";import{buildPlan as J}from"../io/plan.js";import{writeXlsx as V}from"../io/xlsx-write.js";import{MAX_ROWS as A,MAX_COLS as I,colIndex as q,colName as K}from"../core/address.js";import{changeOutline as Q}from"../core/whatif.js";import{display as Y}from"./model.js";async function he(a,w={},p){if(/\.(?:csv|tsv|txt)$/i.test(a.name)){const e=new B;let s=0;const u={size:a.size,slice:(...n)=>a.slice(...n),stream:()=>a.stream().pipeThrough(new TransformStream({transform(n,t){s+=n.byteLength,t.enqueue(n)}}))};return await _(u,{onProgress:n=>p?.({records:Math.max(0,n-1),loaded:s,total:a.size}),delimiter:w.delimiter||(/\.tsv$/i.test(a.name)?" ":void 0),textColumns:new Set(w.textColumns),fallback:H(globalThis.navigator?.language),preserveIdentifiers:!0,addString:n=>e.strings.add(n),styleFor:n=>e.styles.derive(0,{numFmt:n}),onBatch:n=>e.sheet.applyBatch(n)}),{book:e,tables:[]}}const{IoClient:o}=await import("../io/client.js"),f=new o;try{const e=p?await j(a):null,s=await f.open(a,{onProgress:({cells:r})=>p?.({records:e?.columns?Math.floor(r/e.columns):null,loaded:r,total:e?.cells??null})}),{tables:u=[],names:n=[],fullCalcOnLoad:t,manualCalc:c}=f.meta;s.engine=new W(s),s.engine.manual=c,s.engine.setNames(n),s.engine.setTables(u.map(r=>({...r,sheet:s.sheets[r.sheetIndex]}))),s.engine.buildGraph({fullCalc:t}),c||await s.engine.whenIdle();const{openZip:m}=await import("../io/zip-reader.js"),h=await m(await f.packageOf(a));if([...h.entries.keys()].some(r=>r.startsWith("customXml/"))){const{DataSheets:r}=await import("../datasheets/manager.js"),y=new r(s);if(await y.load(h))for(const x of y.manager.tables.values())x.autoSync=!1,x.remote=null}return{book:s,tables:u}}finally{f.close()}}async function j(a){try{const{openZip:w}=await import("../io/zip-reader.js"),p=await w(a);let o=0,f=0,e=0;for(const s of p.entries.keys()){if(!/^xl\/worksheets\/[^/]+\.xml$/.test(s))continue;const u=(await p.stream(s)).pipeThrough(new TextDecoderStream).getReader();let n="";for(;n.length<4096&&!/<(?:\w+:)?sheetData/.test(n);){const{done:h,value:r}=await u.read();if(h)break;n+=r}u.cancel().catch(()=>{});const t=n.match(/<(?:\w+:)?dimension\s+ref="\$?([A-Z]+)\$?(\d+)(?::\$?([A-Z]+)\$?(\d+))?"/);if(!t)return null;const c=t[3]?q(t[3])-q(t[1])+1:1,m=t[4]?Number(t[4])-Number(t[2])+1:1;o+=c*m,c*m>e&&(e=c*m,f=c)}return o>1?{cells:o,columns:f}:null}catch{return null}}function ge({book:a,tables:w}){const p=[];return a.sheets.forEach((o,f)=>{if(!(o.hidden||o.isChartSheet)){if(o.kindName==="table"){const e=o.view.spec,s=o.table.byName,u=c=>c.filter(m=>s.has(m.field)),n=u(e.columns).map(({field:c,caption:m,hidden:h,pinned:r,format:y})=>({field:c,caption:m,hidden:h,pinned:r,format:y})),t=n.some(c=>!c.hidden)?{columns:n,search:e.search,sort:u(e.sort),filters:u(e.filters),groups:u(e.groups).map(({field:c})=>({field:c})),total:u(e.totals)[0]??null,collapsed:[...o.view.collapsedPaths]}:null;p.push({name:o.name,sheet:f,native:!0,initialState:t,range:{r0:0,c0:0,r1:o.maxRow,c1:o.maxCol}});return}for(const e of w.filter(s=>s.sheetIndex===f))p.push({name:e.name,sheet:f,headers:e.columns,headerRows:e.headerRows,range:{r0:e.r0,c0:e.c0,r1:e.r1-e.totalsRows,c1:e.c1}});o.maxCol>=0&&o.maxRow>=0&&p.push({name:o.name,sheet:f,whole:!0,range:{r0:0,c0:0,r1:o.maxRow,c1:o.maxCol}})}}),p.sort((o,f)=>+!!o.whole-+!!f.whole)}async function we(a,w,{layout:p=null}={}){const{view:o}=a;if(o.refresh(),p&&w!=="csv")return ne(a,w,p);const f=o.columns,e=[],s={write:t=>{e.push(new Blob([t]))}};if(w==="csv"){const t=new Z(s,",",{bom:!0});await t.batch(f.map((m,h)=>[0,h,m.caption]));let c=[];for(let m=0;m<o.filteredCount;m++)for(let h=0;h<f.length;h++){const r=f[h];c.push([m+1,h,Y(r.col.get(o.perm[m]),r.format)]),c.length===2048&&(await t.batch(c),c=[])}return await t.batch(c),await t.finish(o.filteredCount),new Blob(e,{type:"text/csv;charset=utf-8"})}if(!["xlsx","pdf"].includes(w)||o.filteredCount>=A||f.length>I)throw new Error("The result exceeds the XLSX row limit or the format is unsupported.");const u=new B,n=u.sheet;return n.name="Results",f.forEach((t,c)=>{n.setCell(0,c,F,u.strings.add(t.caption));const m=u.styles.derive(0,{numFmt:t.format});for(let h=0;h<o.filteredCount;h++){const r=o.perm[h],y=t.col.kind(r);if(!y)continue;const x=t.col.get(r),S=y===F?u.strings.add(x):y===T?Number(x):y===O?x.index:x;n.setCell(h+1,c,y,S),m&&y===D&&n.setStyle(h+1,c,m)}}),L(u,n,w)}async function L(a,w,p){const o=[],f={write:u=>{o.push(new Blob([u]))}};if(p==="pdf"){const{createPrintJob:u}=await import("../print/paginate.js"),{writeJobPdf:n}=await import("../print/render-page.js"),t=(await import("../print/page-setup.js")).getPageSetup(w);return t.fitToPage=!0,t.fitToWidth=1,t.fitToHeight=0,await n(u(a,{sheets:[0]}),f,{title:"Results"}),new Blob(o,{type:"application/pdf"})}const e=J(a,{strings:0,styles:0,sheets:0}),s=G();return await V(f,e,{block:(u,n)=>U(w,a.strings,n,s)}),new Blob(o,{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}const z={bold:!0,fill:"#F2F2F2"},ee={bold:!0,fill:"#F7F7F7"},P={good:{fill:"#D9F2E1",color:"#14532D"},bad:{fill:"#FDE0DD",color:"#8A1C12"},warn:{fill:"#FCEFC9",color:"#6B4A00"},info:{fill:"#DDE9FB",color:"#163D7A"},strong:{bold:!0}},te={gt:"greaterThan",gte:"greaterThanOrEqual",lt:"lessThan",lte:"lessThanOrEqual",equal:"equal",notEqual:"notEqual",between:"between"},X=a=>typeof a=="number"||/^-?\d+(\.\d+)?$/.test(String(a))?String(a):`"${String(a).replace(/"/g,'""')}"`;function oe(a,w,p,o,f){const e=[];for(const s of w??[]){const u={priority:f++};if(s.type==="bar")e.push({...u,type:"dataBar",formulas:[],dataBar:{cfvo:[{type:"min"},{type:"max"}],color:{rgb:"FF638EC6"},showValue:!0}});else if(s.type==="scale")e.push({...u,type:"colorScale",formulas:[],colorScale:{cfvo:[{type:"min"},{type:"percentile",val:"50"},{type:"max"}],colors:[{rgb:"FFF8696B"},{rgb:"FFFFEB84"},{rgb:"FF63BE7B"}]}});else if(s.type==="value"){const n=s.color||s.background?{...s.background&&{fill:s.background},...s.color&&{color:s.color}}:P[s.style]??P.info;a.dxfs??=[],a.dxfs.push(n);const t=a.dxfs.length-1;if(s.op==="contains"){const c=X(String(s.value));e.push({...u,dxfId:t,type:"containsText",operator:"containsText",text:String(s.value),formulas:[`NOT(ISERROR(SEARCH(${c},${o})))`]})}else e.push({...u,dxfId:t,type:"cellIs",operator:te[s.op]??"equal",formulas:[s.value,s.op==="between"?s.value2:void 0].filter(c=>c!==void 0).map(X)})}}return e.length?{sqref:p,rules:e}:null}async function ne(a,w,p){const{view:o,table:f}=a,e=o.columns,s=new Map(p.bands??[]),u=new Map(p.widths??[]),n=new B,t=n.sheet;t.name="Results";const c=n.styles.derive(0,z),m=n.styles.derive(0,ee),h=e.map(d=>n.styles.derive(0,{numFmt:d.format}));let r=0;if([...s.values()].some(Boolean)){let d=0;for(let i=0;i<=e.length;i++){const l=i<e.length?s.get(e[i].field)??"":null,b=s.get(e[d]?.field)??"";if(!(i<e.length&&l===b)){b&&(t.setCell(r,d,F,n.strings.add(b)),i-1>d&&t.addMerge({r0:r,c0:d,r1:r,c1:i-1}));for(let g=d;g<i;g++)t.setStyle(r,g,n.styles.derive(0,{...z,hAlign:"center"}));d=i}}r++}e.forEach((d,i)=>{t.setCell(r,i,F,n.strings.add(d.caption)),t.setStyle(r,i,c)});const y=++r;if(o.count+y+1>=A||e.length>I)throw new Error("The result exceeds the XLSX row limit or the format is unsupported.");const x=(d,i,l,b)=>{if(l==null||l==="")return;const g=typeof l=="number"?D:typeof l=="boolean"?T:typeof l=="string"?F:l?.index!=null?O:F,v=g===F?n.strings.add(String(l?.code??l)):g===T?Number(l):g===O?l.index:l;t.setCell(d,i,g,v),b&&t.setStyle(d,i,b)},S=a.total?.field,E=e.findIndex(d=>d.field===S),R=[],C=r;for(let d=0;d<o.count;d++,r++){const i=o.rowInfo(d);if(i.kind==="record"){a.rowValues(e,i.record).forEach((b,g)=>x(r,g,b,typeof b=="number"?h[g]:0)),R.push(o.spec.hierarchy?i.level:o.spec.groups.length);continue}x(r,0,o.groupCaption(i.node),m);for(let l=1;l<e.length;l++)t.setStyle(r,l,m);if(E>=0&&i.kind==="group"){const l=o.summaryFor(i.node,S);x(r,E,Number.isFinite(l)?l:null,n.styles.derive(m,{numFmt:e[E].format}))}R.push(i.level)}let $=0;R.forEach((d,i)=>{const l=Math.min(7,d);l&&Q(t,"row",C+i,C+i,l),$=Math.max($,l)});const N=r-1;if(p.totals){const{aggregate:d}=await import("../datasheets/view.js"),i=new Map((a.layout??[]).map(l=>[l.field,l.total]));e.forEach((l,b)=>{const g=i.get(l.field),v=g?d(l.col,g,o.perm,0,o.filteredCount):null;t.setStyle(r,b,c),b===0&&!g&&x(r,0,"Total",c),Number.isFinite(v)&&x(r,b,v,n.styles.derive(c,{numFmt:g==="count"?"#,##0":l.format}))}),r++}e.forEach((d,i)=>{const l=u.get(d.field);Number.isFinite(l)&&t.cols.setSize(i,Math.round(l))}),t.colsChanged=!0,t.frozenRows=y,t.viewChanged=!0;const k=[];let M=1;if(N>=C){const d=new Map((a.layout??[]).map(i=>[i.field,i.rules]));e.forEach((i,l)=>{const b=K(l),g=oe(n,d.get(i.field),`${b}${C+1}:${b}${N+1}`,`${b}${C+1}`,M);g&&(k.push(g),M+=g.rules.length)})}return k.length&&(t.cf=k,t.cfChanged=!0),L(n,t,w)}export{we as exportResults,he as openFile,ge as sourcesOf};
|