@8sheets/data-grid 1.1.0 → 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/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.js +1 -1
- package/calcx/async.js +1 -1
- package/calcx/functions/dynamic.js +1 -1
- package/calcx/functions/ets.js +1 -1
- package/calcx/functions/misc.js +1 -1
- package/calcx/lang/convert.js +1 -1
- package/cells/axis-ops.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/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/rich-runs.js +2 -2
- package/cells/rich-values.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/celltypes/cell-types.js +2 -2
- package/celltypes/dropdowns.js +3 -2
- package/celltypes/file-cell.js +2 -2
- package/celltypes/range-template.js +2 -2
- package/core/cell-type-rules.js +1 -0
- package/core/changes.js +1 -1
- 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/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/protection.js +1 -1
- package/core/region-input.js +1 -1
- package/core/sheet.js +1 -1
- package/core/sparse.js +1 -1
- package/core/structure.js +1 -1
- package/core/validation-ranges.js +1 -0
- 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-read.js +1 -1
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/io/xml-scan.js +2 -1
- package/io/zip-reader.js +1 -1
- 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/slicers/format.js +2 -2
- package/slicers/structured.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/labels-de.js +1 -1
- package/table-view/labels-es.js +1 -1
- package/table-view/labels-fr.js +1 -1
- package/table-view/labels-ja.js +1 -1
- package/table-view/labels.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/celltypes/cell-types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{loadBookParts as Ht}from"../cells/book-read.js";import{EMPTY as gt,KIND_MASK as yt}from"../core/sheet.js";import{quoteSheetName as jt,rangeRef as Kt,parseRangeRef as bt}from"../core/address.js";import{sheetRenameHooks as Xt,shiftSparse as Yt}from"../core/sparse.js";import{children as Ut,parseTree as kt,unescapeOoxml as Mt}from"../io/xml-scan.js";import{safeJson as Jt,xmlAttr as wt}from"../io/xml-escape.js";import{openZip as Gt}from"../io/zip-reader.js";import{applyToRanges as Vt,cellKey as I,cellDropdownArrow as qt,closeDropdown as Zt,literalInput as W,makeDropdown as St,openCellDropdown as Tt,openListPopup as lt,readCellValue as _,writeCell as z}from"./dropdowns.js";import{undoGroup as Qt}from"../cells/undo-group.js";import{cellTypePart as te,CELLS_NS as ee,CELLTYPES_NS as ne,readCellTypeParts as oe}from"./persist.js";import{cellsPackage as ie,loadCellsPart as se}from"../cells/sections.js";import{backgroundParts as re,loadBackgrounds as le}from"../cells/background.js";import{loadWatermarks as ae,watermarkParts as fe}from"../api/watermark-xml.js";import{loadRichData as ue,richPackage as ce}from"../cells/rich-data.js";import{buttonInsets as Ct,cachedImage as at,hasCellButtons as V,cellTypeFromFile as xt,CellType as Y,centerText as B,controlRect as Q,defineCellType as de,drawImageFit as ft,flag as A,formatted as he,frame as M,inkOf as U,inRect as F,isChecked as vt,labelOf as L,leftText as j,makeCellType as _t,oneOf as q,runButtonAction as Et,safeColor as R,safeImage as me,safeInt as x,safeItems as Rt,safeLink as zt,safeLocation as pe,safeText as E,sameValue as N,setFont as D,textWidth as O,cellTypeNames as ge,registerButtonAction as ye,registerCellType as be}from"./base.js";import{cellButtonCursor as ke,makeCellButtons as It,openButtonDropdown as Me,paintCellButtons as we,paintFloatingButtons as Se,paintStyleButtons as Te,pressCellButton as Ce,pressNthButton as xe,trackButtonHover as Lt}from"./cell-buttons.js";import{cellFilesPackage as ve,attachFileDrop as Ot}from"./file-cell.js";import{hideEditingButtons as _e,showEditingButtons as Ee}from"./cell-buttons.js";import"./diagonal.js";import"./data-object.js";import"./range-template.js";import"./dropdowns-more.js";import"../a11y/cell-alt-text.js";import{registerFeatureReviver as Re}from"../api/serialize.js";Re("cellTypes",o=>{if(!(o instanceof Map))return null;const t=new Map,e=new Map;for(const[n,s]of o){if(!s||typeof s!="object")continue;const i=JSON.stringify(s);e.has(i)||e.set(i,xt(s));const r=e.get(i);r&&t.set(n,r)}return t.size?t:null});const Pt=1e6,K=(o,t)=>{o.globalAlpha=t?.4:1};function tt(o,t,e,n,s,i){o.beginPath(),o.roundRect?o.roundRect(t,e,n,s,i):o.rect(t,e,n,s)}function Wt(o,t,e,n,s,i,r=!1){const a=Math.max(1,Math.round(i)),l=s!==!1,f=r?Math.round(n*.2):0;tt(o,t+a/2,e+a/2,n-a,n-a,f),o.fillStyle=l?M.theme.accent:"#ffffff",o.fill(),o.strokeStyle=l?M.theme.accent:"#6e6e6e",o.lineWidth=a,o.stroke(),s===null?(o.fillStyle="#ffffff",o.fillRect(t+n*.22,e+n*.44,n*.56,Math.max(1.5,n/7))):s&&(o.strokeStyle="#ffffff",o.lineWidth=Math.max(1.5,n/7),o.lineCap="round",o.beginPath(),o.moveTo(t+n*.22,e+n*.52),o.lineTo(t+n*.42,e+n*.72),o.lineTo(t+n*.78,e+n*.3),o.stroke(),o.lineCap="butt")}function Bt(o,t,e,n,s,i){const r=n/2;o.beginPath(),o.arc(t+r,e+r,r-Math.max(1,i)/2,0,Math.PI*2),o.fillStyle="#ffffff",o.fill(),o.strokeStyle=s?M.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),s&&(o.beginPath(),o.arc(t+r,e+r,r*.5,0,Math.PI*2),o.fillStyle=M.theme.accent,o.fill())}const et=new Map,ze=120;function ut(o,t,e,n){const s=e.duration??ze;if(s<=0||n===void 0||n===null||n.printing||n.grid===null)return t?1:0;let i=et.get(o);if(i===void 0)return et.size>=4096&&et.clear(),i={on:t,from:t?1:0,start:-1/0,ms:s},et.set(o,i),t?1:0;const r=performance.now(),a=(r-i.start)/i.ms,l=a>=1?i.on?1:0:i.from+((i.on?1:0)-i.from)*a;return i.on!==t?(i.on=t,i.from=l,i.start=r,i.ms=s,n.grid.invalidate(),l):(a<1&&n.grid.invalidate(),l)}const Ie=(o,t,e)=>{const n=s=>{const i=parseInt(o.slice(s,s+2),16),r=parseInt(t.slice(s,s+2),16);return Math.round(i+(r-i)*e).toString(16).padStart(2,"0")};return`#${n(1)}${n(3)}${n(5)}`},At=o=>/^#[0-9a-fA-F]{6}$/.test(o);function X(o,t,e,n=0){return n>0&&o.autoSize!==!1?Math.max(t*2,n+t+8*e):o.toggleWidth!==void 0?o.toggleWidth*e:t*2}function Z(o,t,e,n,s,i,r,a){const l=r.trackOn??M.theme.accent,f=r.trackOff??"#b4b4b4",u=r.trackRadius!==void 0?Math.min(s/2,r.trackRadius*a):s/2;tt(o,t,e,n,s,u),o.fillStyle=At(l)&&At(f)?Ie(f,l,i):i>.5?l:f,o.fill();const c=r.knobMargin!==void 0?r.knobMargin*a:Math.max(1,s/8),d=Math.max(1,s-c*2),h=t+c+(n-c*2-d)*i,m=e+c,p=r.knobOn??r.knob??"#ffffff",w=r.knobOff??r.knob??"#ffffff";o.fillStyle=i>.5?p:w,tt(o,h,m,d,d,r.knobRadius!==void 0?Math.min(d/2,r.knobRadius*a):d/2),o.fill()}function Le(o,t,e){const n=[];let s="";for(const i of t.split(/\s+/)){const r=s===""?i:`${s} ${i}`;s!==""&&o.measureText(r).width>e?(n.push(s),s=i):s=r}return n.push(s),n}const ct=(o,t,e,n)=>`${o?.sheet?.uid??0}:${t}:${e}:${n}`;function Ft(o,t,e,n,s,i,r,a,l,f){const u=Math.min(Math.round((r.boxSize??13)*i),Math.round(t.h-2));if(u<=2)return;const c=Math.round(3*i),d=Math.round(t.y+(t.h-u)/2),h=a===Z;if(e.disabled&&K(o,!0),r.textSide==="inside"&&(h||a===Bt)){const S=o.measureText(e.text).width,T=Math.min(t.w-c*2,h?X(r,u,i,S):S+u+8*i),C=Math.round(t.x+c);if(h){const g=ut(ct(l,l?.row,l?.col,f),n,r,l);Z(o,C,d,T,u,g,r,i),o.save(),o.beginPath(),o.rect(C,d,T,u),o.clip();const k=T-u-4*i;B(o,e.text,g>.5?C+2*i:C+u+2*i,d,k,u,e.ink??"#ffffff"),o.restore()}else tt(o,C,d,T,u,u/2),o.fillStyle=n?M.theme.accent:"#ffffff",o.fill(),o.strokeStyle=n?M.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),B(o,e.text,C,d,T,u,n?"#ffffff":e.ink??U(s));e.disabled&&K(o,!1);return}const m=h?X(r,u,i):u,p=r.textSide==="left",w=p?t.x+t.w-c-m:t.x+c;h?Z(o,Math.round(w),d,m,u,ut(ct(l,l?.row,l?.col,f),n,r,l),r,i):a(o,Math.round(w),d,u,n,i,r.mode==="modern");let y=p?t.x+c:t.x+c+m+Math.round(4*i);if(e.image){const S=at(e.image);S&&ft(o,S,y,d,u,u),y+=u+Math.round(3*i)}j(o,e.text,y,t.y,t.h,e.ink??U(s)),e.disabled&&K(o,!1)}function Oe(o,t,e,n,s){const{items:i,horizontal:r,flow:a,maxRows:l,maxCols:f}=t,u=[],c=i.length;if(c===0)return u;const d=(t.pad??0)*e,h=(t.spacingX??0)*e,m=(t.spacingY??0)*e,p=o.x+d,w=o.y+d,y=o.w-d*2,S=o.h-d*2;if(a&&r&&n){const b=n.fontSize*1.45*e;let v=p,P=w,H=0;for(const st of i){const rt=s(st,n)*e;H>0&&(f&&H>=f||v+rt>p+y)&&(v=p,P+=b+m,H=0),u.push({x:v,y:P,w:rt,h:b}),v+=rt+h,H++}const G=(S-(P+b-w))/2;if(G>0)for(const st of u)st.y+=G;return u}let T;r?T=l?Math.ceil(c/l):f??c:T=f??(l?Math.ceil(c/l):1),T=Math.max(1,Math.min(T,c));const C=Math.ceil(c/T),g=(y-h*(T-1))/T,k=(S-m*(C-1))/C;for(let b=0;b<c;b++){const v=r?Math.floor(b/T):b%C,P=r?b%T:Math.floor(b/C);u.push({x:p+P*(g+h),y:w+v*(k+m),w:g,h:k})}return u}class Pe extends Y{static typeName="button";static sanitize(t){return{text:E(t.text),value:E(t.value),action:E(t.action),color:R(t.color),image:me(t.image),disabled:A(t.disabled)}}paint(t,e,n,s,i){const r=Math.max(1,Math.round(i)),a=e.x+r,l=e.y+r,f=e.w-r*2,u=e.h-r*2;if(f<=0||u<=0)return;this.options.disabled&&K(t,!0),t.fillStyle=this.options.color??"#efefef",t.fillRect(a,l,f,u),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i)),t.strokeRect(a+.5,l+.5,f-1,u-1),D(t,s,i);const c=this.options.text??L(n),d=this.options.image?at(this.options.image):null;if(d){const h=Math.min(u-2*r,Math.round(16*i)),m=c===""?0:t.measureText(c).width+Math.round(4*i),p=a+Math.max(r,(f-h-m)/2);ft(t,d,p,l+(u-h)/2,h,h),c!==""&&j(t,c,p+h+Math.round(4*i),l,u,s.color??"#000000")}else B(t,c,a,l,f,u,s.color??"#000000");this.options.disabled&&K(t,!1)}hitTest(t,e,n){return!this.options.disabled&&F(t,e,n)?{part:"button"}:null}activate(t,e,n){const{action:s,value:i,disabled:r}=this.options;if(r||i!==void 0&&!z(t,e,n,W(i)))return!1;const a={row:e,col:n,sheet:t.book.sheet,action:s??null};return s!==void 0&&Et(s,{app:t,...a}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:a})),!0}fitWidth(t,e){return O(e,this.options.text??L(t))+(this.options.image?20:0)+12}}const Nt=o=>({trackOn:R(o.trackOn),trackOff:R(o.trackOff),knob:R(o.knob),knobOn:R(o.knobOn),knobOff:R(o.knobOff),toggleWidth:x(o.toggleWidth,8,400),toggleHeight:x(o.toggleHeight,6,200),autoSize:o.autoSize===!1?!1:void 0,knobMargin:x(o.knobMargin,0,40),trackRadius:x(o.trackRadius,0,100),knobRadius:x(o.knobRadius,0,100),duration:x(o.duration,0,2e3)});class We extends Y{static typeName="checkbox";static sanitize(t){return{text:E(t.text),textTrue:E(t.textTrue),textFalse:E(t.textFalse),textNull:E(t.textNull),mode:q(t.mode,["modern","toggle"]),threeState:t.mode==="toggle"?void 0:A(t.threeState),boxSize:x(t.boxSize,6,64),textSide:q(t.textSide,["left","top","bottom","inside"]),wrap:A(t.wrap),hit:q(t.hit,["box","cell"]),editable:A(t.editable),...Nt(t)}}get blocksEditing(){return this.options.editable!==!0}_state(t){return this.options.threeState&&(t===null||t==="")?null:vt(t)}_caption(t){const e=this.options;return t===!0&&e.textTrue!==void 0?e.textTrue:t===!1&&e.textFalse!==void 0?e.textFalse:t===null&&e.textNull!==void 0?e.textNull:e.text}_hasCaption(){const t=this.options;return t.text!==void 0||t.textTrue!==void 0||t.textFalse!==void 0||t.textNull!==void 0}_side(){const{textSide:t,mode:e}=this.options;return t==="inside"&&e!=="toggle"?void 0:t}_box(t,e,n,s){const i=this.options,r=i.mode==="toggle",a=(r?i.toggleHeight??i.boxSize??13:i.boxSize??13)*e,l=this._side(),f=this._hasCaption(),u=f&&(l==="top"||l==="bottom"),c=u&&n?n.fontSize*1.25*e:0,d=Math.min(a,t.h-2*e-c);let h=r?X(i,d,e):d;if(r&&l==="inside"&&n){const y=this._longestCaption(s);y&&(h=Math.min(t.w-2*e,X(i,d,e,O(n,y)*e)))}const m=3*e;let p;!f||u||l==="inside"?l==="inside"&&n?.hAlign==="left"?p=t.x+m:l==="inside"&&n?.hAlign==="right"?p=t.x+t.w-m-h:p=t.x+(t.w-h)/2:p=l==="left"?t.x+t.w-m-h:t.x+m;let w=t.y+(t.h-d)/2;if(u){const y=d+c,S=t.y+(t.h-y)/2;w=l==="top"?S+c:S}else if(i.wrap&&f){const y=n?.vAlign;y==="top"?w=t.y+2*e:y!=="center"&&(w=t.y+t.h-d-2*e)}return{x:p,y:w,w:h,h:d}}_longestCaption(){const t=this.options;return[t.textTrue,t.textFalse,t.textNull,t.text].filter(Boolean).reduce((e,n)=>e.length>=n.length?e:n,"")}paint(t,e,n,s,i,r){const a=this.options,l=this._box(e,i,s,n);if(l.h<=2)return;const f=this._state(n),u=this._side(),c=this._caption(f);if(D(t,s,i),a.mode==="toggle"){const g=ct(r,r?.row,r?.col,"box"),k=ut(g,f===!0,a,r);if(Z(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),Math.round(l.h),k,a,i),u==="inside"&&c){t.save(),t.beginPath(),t.rect(l.x,l.y,l.w,l.h),t.clip();const b=l.w-l.h-2*i;B(t,c,k>.5?l.x+i:l.x+l.h+i,l.y,b,l.h,"#ffffff"),t.restore();return}}else Wt(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),f,i,a.mode==="modern");if(c===void 0||c==="")return;const d=U(s);if(u==="top"||u==="bottom"){const g=s.fontSize*1.25*i,k=u==="top"?l.y-g:l.y+l.h;B(t,c,e.x,k,e.w,g,d);return}const h=4*i,m=u==="left"?e.x+3*i:l.x+l.w+h,p=u==="left"?l.x-h-m:e.x+e.w-m-2*i;if(!a.wrap){j(t,c,m,e.y,e.h,d);return}const w=Le(t,c,p),y=s.fontSize*1.2*i,S=w.length*y,T=s.vAlign,C=T==="top"?e.y+2*i:T==="center"?e.y+(e.h-S)/2:e.y+e.h-S-2*i;w.forEach((g,k)=>j(t,g,m,C+k*y,y,d))}hitTest(t,e,n,s=1,i=null){const{hit:r}=this.options;return r==="cell"||r!=="box"&&this._hasCaption()?F(t,e,n)?{part:"box"}:null:F(this._box(t,s,i),e,n)?{part:"box"}:null}activate(t,e,n){const{book:s}=t,i=this._state(_(s,s.sheet,e,n));return this.options.threeState?z(t,e,n,i===!0?"FALSE":i===!1?"":"TRUE"):z(t,e,n,i?"FALSE":"TRUE")}fitWidth(t,e){const n=this.options,s=n.mode==="toggle"?n.toggleHeight??n.boxSize??13:n.boxSize??13,i=this._caption(this._state(t)),r=this._side(),a=n.mode==="toggle"?n.toggleWidth??s*2:s,l=i?O(e,i):0;return r==="inside"?X(n,s,1,O(e,this._longestCaption()))+8:r==="top"||r==="bottom"?Math.max(a,l)+6:a+6+(l?l+4:0)}}class nt extends Y{static sanitize(t){return{items:Rt(t.items),horizontal:A(t.horizontal),separator:E(t.separator,16),flow:A(t.flow),maxRows:x(t.maxRows,1,200),maxCols:x(t.maxCols,1,200),spacingX:x(t.spacingX,0,64),spacingY:x(t.spacingY,0,64),pad:x(t.pad,0,64),boxSize:x(t.boxSize,6,64),textSide:q(t.textSide,["left","inside"]),mode:q(t.mode,["modern","toggle"]),...Nt(t)}}get blocksEditing(){return!0}_itemWidth(t,e){const n=this.options,s=n.boxSize??13,i=n.mode==="toggle"?X(n,s,1):s;if(n.textSide==="inside"&&(n.mode==="toggle"||this.type==="radio")){const r=O(e,t.text);return(n.mode==="toggle"?X(n,s,1,r):r+s+8)+6}return i+10+O(e,t.text)+(t.image?16:0)}_slots(t,e,n){return Oe(t,this.options,e,n,(s,i)=>this._itemWidth(s,i))}hitTest(t,e,n,s=1,i=null){if(!F(t,e,n))return null;const r=this._slots(t,s,i).findIndex(a=>F(a,e,n));return r<0||this.options.items[r].disabled?null:{part:"item",index:r}}_hitItem(t,e,n,s,i){const{book:r}=t,a=r.styles.list[r.sheet.style(e,n)]??r.styles.list[0];return this.hitTest(Q(t,e,n),s,i,t.grid.zoom,a)}_nextEnabled(t){const{items:e}=this.options;for(let n=1;n<=e.length;n++){const s=(t+n)%e.length;if(!e[s].disabled)return s}return-1}fitWidth(t,e){const{items:n,horizontal:s,spacingX:i=0,pad:r=0,maxCols:a}=this.options,l=n.map(c=>this._itemWidth(c,e));if(l.length===0)return 0;const f=s?Math.min(a??l.length,l.length):1,u=Math.max(...l);return(s&&f===l.length?l.reduce((c,d)=>c+d,0):u*f)+i*(f-1)+r*2}}class Be extends nt{static typeName="radio";paint(t,e,n,s,i,r){D(t,s,i),this._slots(e,i,s).forEach((a,l)=>{const f=this.options.items[l];Ft(t,a,f,N(n,f.value),s,i,this.options,Bt,r,l)})}activate(t,e,n,s,i){const{items:r}=this.options;if(r.length===0)return!1;let a;if(s==null){const{book:l}=t,f=_(l,l.sheet,e,n);if(a=this._nextEnabled(r.findIndex(u=>N(f,u.value))),a<0)return!1}else{const l=this._hitItem(t,e,n,s,i);if(!l)return!1;a=l.index}return z(t,e,n,W(r[a].value))}}const ot=o=>o.separator??", ";function dt(o,t){if(o==null||o==="")return new Set;const e=String(o).split(ot(t).trim()||",").map(n=>n.trim().toLowerCase());return new Set(t.items.filter(n=>e.includes(String(n.value).toLowerCase())).map(n=>n.value))}class Ae extends nt{static typeName="checklist";paint(t,e,n,s,i,r){D(t,s,i);const a=dt(n,this.options),l=this.options.mode==="toggle"?Z:Wt;this._slots(e,i,s).forEach((f,u)=>{const c=this.options.items[u];Ft(t,f,c,a.has(c.value),s,i,this.options,l,r,u)})}_write(t,e,n,s){return z(t,e,n,W(s.join(ot(this.options))))}activate(t,e,n,s,i){const{items:r}=this.options,{book:a}=t,l=dt(_(a,a.sheet,e,n),this.options);if(s==null)return lt(t,e,n,{items:r.filter(c=>!c.disabled),selected:[...l],multi:!0,label:"Choices",onDone:c=>this._write(t,e,n,c)}),!0;const f=this._hitItem(t,e,n,s,i);if(!f)return!1;const u=r[f.index];return l.has(u.value)?l.delete(u.value):l.add(u.value),this._write(t,e,n,r.filter(c=>l.has(c.value)).map(c=>c.value))}}class Fe extends nt{static typeName="buttonlist";static sanitize(t){return{...nt.sanitize(t),horizontal:t.horizontal!==!1||void 0,multiple:A(t.multiple),selectedColor:R(t.selectedColor),selectedInk:R(t.selectedInk)}}_itemWidth(t,e){return O(e,t.text)+14+(t.image?18:0)}_chosen(t){if(this.options.multiple)return dt(t,this.options);const e=this.options.items.find(n=>N(t,n.value));return new Set(e?[e.value]:[])}paint(t,e,n,s,i){D(t,s,i);const r=this.options,a=Math.max(1,Math.round(i)),l=this._chosen(n);this._slots(e,i,s).forEach((f,u)=>{const c=r.items[u],d=l.has(c.value),h=Math.round(f.x)+a,m=Math.round(f.y)+a,p=Math.round(f.w)-a*2,w=Math.round(f.h)-a*2;if(p<=0||w<=0)return;c.disabled&&K(t,!0);const y=r.selectedColor??M.theme.accent;t.fillStyle=c.color??(d?y:"#efefef"),t.fillRect(h,m,p,w);const S=d&&c.color?a*2:a;t.strokeStyle=d?y:"#8f8f8f",t.lineWidth=S,t.strokeRect(h+S/2,m+S/2,p-S,w-S),t.save(),t.beginPath(),t.rect(h,m,p,w),t.clip();const T=c.ink??(d&&!c.color?r.selectedInk??"#ffffff":s.color??"#000000"),C=c.image?at(c.image):null;if(C){const g=Math.min(w-2*a,Math.round(14*i)),k=t.measureText(c.text).width+(c.text?Math.round(4*i):0),b=h+Math.max(a,(p-g-k)/2);ft(t,C,b,m+(w-g)/2,g,g),j(t,c.text,b+g+Math.round(4*i),m,w,T)}else B(t,c.text,h,m,p,w,T);t.restore(),c.disabled&&K(t,!1)}),r.items.length>0&&(t.textAlign="left")}activate(t,e,n,s,i){const{items:r,multiple:a}=this.options;if(r.length===0)return!1;const{book:l}=t,f=_(l,l.sheet,e,n);if(s==null){if(a)return lt(t,e,n,{items:r.filter(h=>!h.disabled),selected:[...this._chosen(f)],multi:!0,label:"Choices",onDone:h=>z(t,e,n,W(h.join(ot(this.options))))}),!0;const d=this._nextEnabled(r.findIndex(h=>N(f,h.value)));return d>=0&&z(t,e,n,W(r[d].value))}const u=this._hitItem(t,e,n,s,i);if(!u)return!1;const c=r[u.index];if(a){const d=this._chosen(f);return d.has(c.value)?d.delete(c.value):d.add(c.value),z(t,e,n,W(r.filter(h=>d.has(h.value)).map(h=>h.value).join(ot(this.options))))}return z(t,e,n,N(f,c.value)?"":W(c.value))}}function it(o,t,e){if(typeof o=="number")return o;if(typeof o=="string"&&t){const n=t.findIndex(s=>s.toLowerCase()===o.toLowerCase());if(n>=0)return n}return e}function ht(o,t,e,n){const s=[],i=Math.min(o,5e3);for(let r=0;r<i;r++){const a=L(t(r,e)),l=L(t(r,n));(a!==""||l!=="")&&s.push({text:String(a),value:String(l)})}return s}function Ne(o,t,e,{textColumn:n,valueColumn:s},i,r){const a=e.replace(/^=/,"").trim(),l=e[0]==="="?void 0:o.engine?.tables.get(a.toUpperCase());if(l){const y=l.columns?.map(k=>typeof k=="string"?k:k?.name??""),S=it(n,y,0),T=it(s,y,S),C=l.r0+(l.headerRows??1),g=l.r1-C+1-(l.totalsRows??0);return ht(g,(k,b)=>_(o,l.sheet,C+k,l.c0+b),S,T)}const f=it(n,null,0),u=it(s,null,f),c=a.lastIndexOf("!"),d=e[0]==="="?null:bt(c>=0?a.slice(c+1):a);if(d){const y=c>=0?a.slice(0,c).replace(/^'|'$/g,"").replace(/''/g,"'"):null,S=y===null?t:o.sheets.find(C=>C.name.toLowerCase()===y.toLowerCase());if(!S)return[];const T=Math.min(d.r1,S.maxRow)-d.r0+1;return ht(T,(C,g)=>_(o,S,d.r0+C,d.c0+g),f,u)}const{engine:h}=o;if(!h)return[];let m;try{const y=h.template(a,i,r);if(y.invalid)return[];m=y.fn(i,r,t),m&&m.sheet&&(m=h.toArr(m))}catch{return[]}if(!m||!m.data)return m==null||typeof m=="object"?[]:[{text:String(L(m)),value:String(L(m))}];const p=m.cols,w=(y,S)=>{const T=m.data[y*p+S];return T===void 0||T!==null&&typeof T=="object"?null:T};return ht(m.rows,w,f,u)}class De extends Y{static typeName="combobox";static sanitize(t){return{items:Rt(t.items),editable:A(t.editable),source:typeof t.source=="string"&&t.source.length<=500?t.source:void 0,textColumn:typeof t.textColumn=="string"?E(t.textColumn,200):x(t.textColumn,0,49),valueColumn:typeof t.valueColumn=="string"?E(t.valueColumn,200):x(t.valueColumn,0,49),maxItems:x(t.maxItems,1,100),float:t.float===!1?!1:void 0}}get blocksEditing(){return this.options.editable!==!0}get opensList(){return!0}_items(t,e,n,s){const{source:i,items:r}=this.options;return i===void 0?r:((this.sourceFrame!==M.id||this.sourceFrame===void 0)&&(this.sourceFrame=M.id,this.sourceItems=Ne(t,e,i,this.options,n,s)),this.sourceItems)}_arrow(t,e){const n=Math.min(16*e,t.h);return{x:t.x+t.w-n,y:t.y+(t.h-n)/2,w:n,h:n}}paint(t,e,n,s,i,r){const a=r?.printing===!0,l=this._arrow(e,i),u=(r?.book?this._items(r.book,r.sheet,r.row,r.col):this.options.items).find(m=>N(n,m.value))?.text??he(n,s);if(D(t,s,i),t.save(),t.beginPath(),t.rect(e.x,e.y,a?e.w:e.w-l.w,e.h),t.clip(),j(t,u,e.x+Math.round(2*i),e.y,e.h,U(s)),t.restore(),a)return;const c=Math.round(l.x),d=Math.round(l.y),h=Math.round(l.w);t.fillStyle="#f7f7f7",t.fillRect(c,d,h,h),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i/2)),t.strokeRect(c+.5,d+.5,h-1,h-1),t.fillStyle="#444444",t.beginPath(),t.moveTo(c+h*.28,d+h*.4),t.lineTo(c+h*.72,d+h*.4),t.lineTo(c+h*.5,d+h*.66),t.closePath(),t.fill()}hitTest(t,e,n,s=1){return F(t,e,n)?F(this._arrow(t,s),e,n)?{part:"arrow"}:this.options.editable?null:{part:"text"}:null}activate(t,e,n){const{book:s}=t,i=_(s,s.sheet,e,n);this.sourceFrame=void 0;const r=this._items(s,s.sheet,e,n);this.sourceFrame=void 0;const a=r.find(l=>N(i,l.value));return lt(t,e,n,{items:r,selected:a?[a.value]:[],label:"Choices",maxItems:this.options.maxItems??20,moveOnSide:!0,float:this.options.float!==!1,onDone:l=>l.length===0?!0:z(t,e,n,W(l[0]))}),!0}fitWidth(t,e){const n=this.options.items.find(s=>N(t,s.value))?.text??L(t);return O(e,String(n))+22}}const mt=new Set;class $e extends Y{static typeName="hyperlink";static sanitize(t){return{url:zt(t.url),location:pe(t.location),text:E(t.text),color:R(t.color),visitedColor:R(t.visitedColor),tooltip:E(t.tooltip),action:E(t.action),activeOnClick:t.activeOnClick===!1?!1:void 0}}get tooltip(){return this.options.tooltip}get runsWithoutSelecting(){return this.options.activeOnClick===!1}paint(t,e,n,s,i){const r=this.options.text??L(n);if(r==="")return;D(t,s,i);const a=e.x+Math.round(2*i),{url:l,location:f,color:u,visitedColor:c}=this.options,d=l??f??(typeof n=="string"?n:""),h=mt.has(d)?c??"#954f72":u??s.color??"#0563c1";j(t,r,a,e.y,e.h,h);const m=s.fontSize*i,p=Math.min(t.measureText(r).width,e.w-Math.round(4*i));t.fillRect(a,Math.round(e.y+e.h/2+m*.42),p,Math.max(1,Math.round(m/14)))}hitTest(t,e,n){return F(t,e,n)?{part:"link"}:null}activate(t,e,n){const{url:s,location:i,action:r}=this.options,{book:a}=t;if(r!==void 0){const f={row:e,col:n,sheet:a.sheet,action:r};Et(r,{app:t,...f}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:f}))}if(i)return mt.add(i),t.controller._followLink({location:i}),!0;const l=s??zt(_(a,a.sheet,e,n));return l?(mt.add(l),t.grid.invalidate(),t.controller._followLink({target:l}),!0):(r===void 0&&t.shell.setStatus("This link has no web or mail address to open."),!0)}fitWidth(t,e){return O(e,String(this.options.text??L(t)))+7}}class He extends Y{static typeName="progress";static sanitize(t){const e=n=>Number.isFinite(n)?n:void 0;return{min:e(t.min),max:e(t.max),color:R(t.color),hideText:t.hideText===!0||void 0}}paint(t,e,n,s,i){const r=this.options.min??0,a=this.options.max??1,l=Math.max(1,Math.round(2*i)),f=e.x+l,u=e.y+l,c=e.w-l*2,d=e.h-l*2;if(c<=0||d<=0)return;if(t.fillStyle="#e6e6e6",t.fillRect(f,u,c,d),D(t,s,i),typeof n=="string"&&n.startsWith("#")){B(t,n,f,u,c,d,U(s));return}const h=typeof n=="number"?n:0,m=a>r?Math.max(0,Math.min(1,(h-r)/(a-r))):0;t.fillStyle=this.options.color??M.theme.accent,t.fillRect(f,u,Math.round(c*m),d),this.options.hideText||B(t,`${Math.round(m*100)}%`,f,u,c,d,m>.5?"#ffffff":U(s))}}for(const o of[Pe,We,Be,Ae,Fe,De,$e,He])de(o);const wn=ge();function $(o,t,e){const n=o.cellTypes;if(!n)return null;const s=o.mergeAt(t,e);return n.get(s?I(s.r0,s.c0):I(t,e))??null}const J=(o,t,e,n)=>o.styles.list[t.style(e,n)]??o.styles.list[0];function Dt(o,t,e,n,s,i,r,a,l,f,u,c,d){const h=e.kind(i,r)&yt,m=J(n,e,i,r);h===gt&&(o.fillStyle=m.fill??s.cellBg,o.fillRect(a,l,f-d,u-d));const p=Ct(e,i,r,m);if(p!==null){const w=Math.round(p[0]*c);a+=w,f=Math.max(0,f-w-Math.round(p[1]*c))}o.save(),o.beginPath(),o.rect(a,l,f,u),o.clip(),M.row=i,M.col=r,t.paint(o,{x:a,y:l,w:f,h:u},_(n,e,i,r),m,c,M),o.restore()}function Sn(o,t,e,n,s){const{sheet:i,book:r,theme:a,dpr:l,zoom:f}=t,u=i.cellTypes;M.theme=a,M.book=r,M.sheet=i,M.grid=t,M.printing=!1,M.id++;const{ca:c,cb:d,ra:h,rb:m,s:p,xs:w,ys:y}=n,S=Math.max(1,Math.round(l*Math.min(f,1))),T=s.length>0,C=(g,k,b)=>{if(T&&i.mergeAt(k,b)!==null)return;const v=w[b-c],P=y[k-h],H=w[b-c+1]-v,G=y[k-h+1]-P;H>0&&G>0&&Dt(o,g,i,r,a,k,b,v,P,H,G,p,S)};if(u.size<(d-c+1)*(m-h+1))for(const[g,k]of u){const b=Math.floor(g/16384),v=g-b*16384;b>=h&&b<=m&&v>=c&&v<=d&&C(k,b,v)}else for(let g=h;g<=m;g++)for(let k=c;k<=d;k++){const b=u.get(I(g,k));b!==void 0&&C(b,g,k)}for(const g of s){const k=u.get(I(g.r0,g.c0));if(k===void 0||g.c1<c||g.c0>d)continue;const b=t._rectInPane(g,e,p);Dt(o,k,i,r,a,g.r0,g.c0,b.x,b.y,b.w,b.h,p,S)}}const je={cellBg:"#ffffff",cellInk:"#000000",accent:"#404040"};function Tn(o,t,e,n,s,i,r,a,l){const f=e.cellTypes?.get(I(n,s));return f===void 0?!1:(M.theme=je,M.book=t,M.sheet=e,M.grid=null,M.printing=!0,M.row=n,M.col=s,M.id++,o.save(),o.beginPath(),o.rect(i,r,a,l),o.clip(),f.paint(o,{x:i,y:r,w:a,h:l},_(t,e,n,s),J(t,e,n,s),1,M),o.restore(),M.printing=!1,!0)}function Cn(o,t,e,n,s,i,r){const a=t.cellTypes;if(!(a instanceof Map))return;const l=(f,u)=>{(t.kind(f,u)&yt)===gt&&t.mergeAt(f,u)===null&&r(f,u)};if(a.size<(n-e+1)*(i-s+1))for(const f of a.keys()){const u=Math.floor(f/16384),c=f-u*16384;u>=e&&u<=n&&c>=s&&c<=i&&l(u,c)}else for(let f=e;f<=n;f++)for(let u=s;u<=i;u++)a.has(I(f,u))&&l(f,u)}function xn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i,a=$(r,t,e);if(a===null||a.runsWithoutSelecting!==!0||!a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function vn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(V(r,i)&&Ce(o,t,e,n,s))return!0;const a=r.cellTypes?$(r,t,e):null;if(a===null||!a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function _n(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(V(r,i)&&ke(o,t,e,n,s))return"pointer";if(!r.cellTypes)return null;const a=$(r,t,e),l=a?.tooltip,{host:f}=o.grid;return l!==void 0?f.title=l:f.title!==""&&(f.title=""),a!==null&&a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e))?"pointer":null}function En(o,t){const{sheet:e}=o.book,n=V(e,o.book);if(!e.cellTypes&&!e.cellDropdowns&&!n)return!1;const s=o.grid.selection,{row:i,col:r}=s,a=t.metaKey||t.ctrlKey||t.shiftKey;if(t.altKey&&!a&&n&&/^Digit[1-9]$/.test(t.code)&&xe(o,i,r,Number(t.code[5])-1))return!0;if(t.key==="ArrowDown"&&t.altKey&&!a){if(Tt(o,i,r)||n&&Me(o,i,r))return!0;const l=$(e,i,r);return l&&l.opensList?l.activate(o,i,r,null,null):!1}if((t.key==="Delete"||t.key==="Backspace")&&!a&&!t.altKey&&e.cellTypes&&Ke(o))return!0;if(t.key===" "&&!a&&!t.altKey){const l=$(e,i,r);if(l===null)return!1;const f=e.mergeAt(i,r);return l.activate(o,f?f.r0:i,f?f.c0:r,null,null)}return!1}function Ke(o){const{book:t,grid:e}=o,{sheet:n}=t,s=e.selection.ranges,i=[];for(const[a,l]of n.cellTypes){if(l?.constructor?.typeName!=="checkbox")continue;const f=Math.floor(a/16384),u=a%16384;s.some(c=>f>=c.r0&&f<=c.r1&&u>=c.c0&&u<=c.c1)&&i.push([f,u])}if(i.length===0)return!1;const r=i.filter(([a,l])=>vt(_(t,n,a,l)));return r.length?t.transact("entry",a=>{for(const[l,f]of r)t.setInput(a,l,f,"FALSE")}):Qt(t,"Clear",()=>{Vt(t,i.map(([a,l])=>({r0:a,c0:l,r1:a,c1:l})),"cellTypes",null),t.clearRange(s)}),e.invalidate(),o.controller?.syncFormulaBar?.(),!0}function Rn(o,t,e){const{sheet:n}=o.book;if(!n.cellTypes)return!1;const s=$(n,t,e);return s===null||!s.blocksEditing?!1:(o.controller.focusGrid(),s.opensList?s.activate(o,t,e,null,null):o.shell.setStatus("This cell holds a control. Click it or press Space to change it."),!0)}function zn(o,t,e){const{book:n}=o,s=$(n.sheet,t,e);return s===null?void 0:s.editText(_(n,n.sheet,t,e))}function In(o,t,e,n){const s=$(o.book.sheet,t,e);return s===null?n:s.parseEdit(n)}function Ln(o,t,e,n,s){const i=o.cellTypes?.get(I(e,n)),r=J(t,o,e,n);let a=s;if(i!==void 0){M.book=t,M.sheet=o,M.row=e,M.col=n;const f=i.fitWidth(_(t,o,e,n),r);f>0&&(a=f-7)}const l=Ct(o,e,n,r);return l===null?a:a+l[0]+l[1]}function On(o){Ot(o),o.grid.host.addEventListener("pointerleave",()=>{V(o.book.sheet,o.book)&&Lt(o,null,0,0)})}function Pn(o,t){const e=[];for(const n of[o.cellTypes,o.cellButtons])if(n instanceof Map)for(const s of n.keys())s%16384===t&&e.push(Math.floor(s/16384));return e}const Wn=(o,t)=>Yt(o,t);function Xe(o,t,e){const n=o.lastIndexOf("!");return n<0||o.slice(0,n).replace(/^'|'$/g,"").replace(/''/g,"'").toLowerCase()!==t.toLowerCase()?o:`${jt(e)}${o.slice(n)}`}function $t(o,t,e){let n=null;for(const s of["source","location"]){if(typeof o[s]!="string")continue;const i=Xe(o[s],t,e);i!==o[s]&&((n??={...o})[s]=i)}return n}Xt.push((o,t,e)=>{const n=new Map,s=(r,a,l)=>{const f=r[a];if(!(f instanceof Map))return;let u=null;for(const[c,d]of f){n.has(d)||n.set(d,l(d));const h=n.get(d);h!==d&&(u??=new Map(f)).set(c,h)}u!==null&&(r[a]=u,r.cellTypesChanged=!0)},i=r=>{const a=$t(r,t,e);return a===null?r:St(r.type,a)};for(const r of o.sheets)s(r,"cellTypes",a=>{const l=$t(a.options,t,e);return l===null?a:_t(a.type,l)}),s(r,"cellDropdowns",i),s(r,"cellButtons",a=>{const l=a.map(f=>{if(!f.dropdown||f.dropdown===!0)return f;const u=i(f.dropdown);return u===f.dropdown?f:{...f,dropdown:u}});return l.some((f,u)=>f!==a[u])?It(l):a})});function Ye(o){o.sort((i,r)=>i%16384-r%16384||i-r);const t=[];let e=-1,n=-1;const s=()=>{if(e<0)return;const i=Math.floor(e/16384),r=e-i*16384,a=Math.floor(n/16384);t.push(Kt({r0:i,c0:r,r1:a,c1:r}))};for(const i of o)e>=0&&i===n+16384||(s(),e=i),n=i;return s(),t}function pt(o,t,e){if(!o||o.size===0)return;const n=new Map;for(const[s,i]of o){const r=Jt(i);let a=n.get(r);a===void 0&&(a=[],n.set(r,a)),a.push(s)}for(const[s,i]of n)e.push({kind:t,json:s,keys:i})}function Ue(o){const t=[];if(pt(o.cellTypes,"type",t),pt(o.cellDropdowns,"dropdown",t),pt(o.cellButtons,"buttons",t),t.length===0)return null;const e=t.map(n=>`<entry kind="${n.kind}" config="${wt(n.json)}" ref="${Ye(n.keys).join(" ")}"/>`).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
-
<cellTypes xmlns="${
|
|
1
|
+
import{loadBookParts as Qt}from"../cells/book-read.js";import{EMPTY as ut,KIND_MASK as ct}from"../core/sheet.js";import{hasCellTypes as q,intersection as vt,typeAtPosition as D,visitStored as te}from"../core/cell-type-rules.js";import{subtractRect as _t}from"../core/validation-ranges.js";import{MAX_COLS as Z,MAX_ROWS as ee,quoteSheetName as ne,rangeRef as Rt,parseRangeRef as dt}from"../core/address.js";import{sheetRenameHooks as oe,shiftSparse as ie}from"../core/sparse.js";import{children as It,parseTree as Et,unescapeOoxml as ht}from"../io/xml-scan.js";import{safeJson as zt,xmlAttr as mt}from"../io/xml-escape.js";import{openZip as se}from"../io/zip-reader.js";import{applyToRanges as re,cellKey as pt,cellDropdownArrow as le,closeDropdown as ae,literalInput as W,makeDropdown as Lt,openCellDropdown as Ot,openListPopup as gt,readCellValue as _,writeCell as E}from"./dropdowns.js";import{undoGroup as fe}from"../cells/undo-group.js";import{cellTypePart as ue,CELLS_NS as ce,CELLTYPES_NS as de,readCellTypeParts as he}from"./persist.js";import{cellsPackage as me,loadCellsPart as pe}from"../cells/sections.js";import{backgroundParts as ge,loadBackgrounds as ye}from"../cells/background.js";import{loadWatermarks as be,watermarkParts as Me}from"../api/watermark-xml.js";import{loadRichData as ke,richPackage as we}from"../cells/rich-data.js";import{buttonInsets as At,cachedImage as yt,hasCellButtons as Q,cellTypeFromFile as nt,CellType as Y,centerText as P,controlRect as ot,defineCellType as Se,drawImageFit as bt,flag as $,formatted as Te,frame as w,inkOf as U,inRect as B,isChecked as Wt,labelOf as z,leftText as j,makeCellType as Pt,oneOf as tt,runButtonAction as $t,safeColor as I,safeImage as xe,safeInt as v,safeItems as Bt,safeLink as Ft,safeLocation as Ce,safeText as R,sameValue as J,setFont as F,textWidth as L,cellTypeNames as ve,registerButtonAction as _e,registerCellType as Re}from"./base.js";import{cellButtonCursor as Ie,makeCellButtons as Nt,openButtonDropdown as Ee,paintCellButtons as ze,paintFloatingButtons as Le,paintStyleButtons as Oe,pressCellButton as Ae,pressNthButton as We,trackButtonHover as Dt}from"./cell-buttons.js";import{cellFilesPackage as Pe,attachFileDrop as jt}from"./file-cell.js";import{hideEditingButtons as $e,showEditingButtons as Be}from"./cell-buttons.js";import"./diagonal.js";import"./data-object.js";import"./range-template.js";import"./dropdowns-more.js";import"../a11y/cell-alt-text.js";import{registerFeatureReviver as Ht}from"../api/serialize.js";Ht("cellTypes",o=>{if(!(o instanceof Map))return null;const t=new Map,e=new Map;for(const[n,s]of o){if(!s||typeof s!="object")continue;const i=JSON.stringify(s);e.has(i)||e.set(i,nt(s));const r=e.get(i);r&&t.set(n,r)}return t.size?t:null}),Ht("cellTypeRules",o=>{const t=[];for(const e of Array.isArray(o)?o:[]){if(!Array.isArray(e?.ranges)||!e.spec||typeof e.spec!="object")continue;const n=nt(e.spec),s=e.ranges.filter(i=>i&&[i.r0,i.c0,i.r1,i.c1].every(Number.isInteger)&&i.r0>=0&&i.r0<=i.r1&&i.r1<ee&&i.c0>=0&&i.c0<=i.c1&&i.c1<Z);n&&s.length&&t.push({ranges:s,spec:n})}return t.length?t:null});const Kt=1e6,H=(o,t)=>{o.globalAlpha=t?.4:1};function it(o,t,e,n,s,i){o.beginPath(),o.roundRect?o.roundRect(t,e,n,s,i):o.rect(t,e,n,s)}function Xt(o,t,e,n,s,i,r=!1){const a=Math.max(1,Math.round(i)),l=s!==!1,f=r?Math.round(n*.2):0;it(o,t+a/2,e+a/2,n-a,n-a,f),o.fillStyle=l?w.theme.accent:"#ffffff",o.fill(),o.strokeStyle=l?w.theme.accent:"#6e6e6e",o.lineWidth=a,o.stroke(),s===null?(o.fillStyle="#ffffff",o.fillRect(t+n*.22,e+n*.44,n*.56,Math.max(1.5,n/7))):s&&(o.strokeStyle="#ffffff",o.lineWidth=Math.max(1.5,n/7),o.lineCap="round",o.beginPath(),o.moveTo(t+n*.22,e+n*.52),o.lineTo(t+n*.42,e+n*.72),o.lineTo(t+n*.78,e+n*.3),o.stroke(),o.lineCap="butt")}function Yt(o,t,e,n,s,i){const r=n/2;o.beginPath(),o.arc(t+r,e+r,r-Math.max(1,i)/2,0,Math.PI*2),o.fillStyle="#ffffff",o.fill(),o.strokeStyle=s?w.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),s&&(o.beginPath(),o.arc(t+r,e+r,r*.5,0,Math.PI*2),o.fillStyle=w.theme.accent,o.fill())}const st=new Map,Fe=120;function Mt(o,t,e,n){const s=e.duration??Fe;if(s<=0||n===void 0||n===null||n.printing||n.grid===null)return t?1:0;let i=st.get(o);if(i===void 0)return st.size>=4096&&st.clear(),i={on:t,from:t?1:0,start:-1/0,ms:s},st.set(o,i),t?1:0;const r=performance.now(),a=(r-i.start)/i.ms,l=a>=1?i.on?1:0:i.from+((i.on?1:0)-i.from)*a;return i.on!==t?(i.on=t,i.from=l,i.start=r,i.ms=s,n.grid.invalidate(),l):(a<1&&n.grid.invalidate(),l)}const Ne=(o,t,e)=>{const n=s=>{const i=parseInt(o.slice(s,s+2),16),r=parseInt(t.slice(s,s+2),16);return Math.round(i+(r-i)*e).toString(16).padStart(2,"0")};return`#${n(1)}${n(3)}${n(5)}`},Ut=o=>/^#[0-9a-fA-F]{6}$/.test(o);function K(o,t,e,n=0){return n>0&&o.autoSize!==!1?Math.max(t*2,n+t+8*e):o.toggleWidth!==void 0?o.toggleWidth*e:t*2}function et(o,t,e,n,s,i,r,a){const l=r.trackOn??w.theme.accent,f=r.trackOff??"#b4b4b4",c=r.trackRadius!==void 0?Math.min(s/2,r.trackRadius*a):s/2;it(o,t,e,n,s,c),o.fillStyle=Ut(l)&&Ut(f)?Ne(f,l,i):i>.5?l:f,o.fill();const u=r.knobMargin!==void 0?r.knobMargin*a:Math.max(1,s/8),d=Math.max(1,s-u*2),h=t+u+(n-u*2-d)*i,m=e+u,p=r.knobOn??r.knob??"#ffffff",y=r.knobOff??r.knob??"#ffffff";o.fillStyle=i>.5?p:y,it(o,h,m,d,d,r.knobRadius!==void 0?Math.min(d/2,r.knobRadius*a):d/2),o.fill()}function De(o,t,e){const n=[];let s="";for(const i of t.split(/\s+/)){const r=s===""?i:`${s} ${i}`;s!==""&&o.measureText(r).width>e?(n.push(s),s=i):s=r}return n.push(s),n}const kt=(o,t,e,n)=>`${o?.sheet?.uid??0}:${t}:${e}:${n}`;function Jt(o,t,e,n,s,i,r,a,l,f){const c=Math.min(Math.round((r.boxSize??13)*i),Math.round(t.h-2));if(c<=2)return;const u=Math.round(3*i),d=Math.round(t.y+(t.h-c)/2),h=a===et;if(e.disabled&&H(o,!0),r.textSide==="inside"&&(h||a===Yt)){const S=o.measureText(e.text).width,T=Math.min(t.w-u*2,h?K(r,c,i,S):S+c+8*i),x=Math.round(t.x+u);if(h){const g=Mt(kt(l,l?.row,l?.col,f),n,r,l);et(o,x,d,T,c,g,r,i),o.save(),o.beginPath(),o.rect(x,d,T,c),o.clip();const k=T-c-4*i;P(o,e.text,g>.5?x+2*i:x+c+2*i,d,k,c,e.ink??"#ffffff"),o.restore()}else it(o,x,d,T,c,c/2),o.fillStyle=n?w.theme.accent:"#ffffff",o.fill(),o.strokeStyle=n?w.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),P(o,e.text,x,d,T,c,n?"#ffffff":e.ink??U(s));e.disabled&&H(o,!1);return}const m=h?K(r,c,i):c,p=r.textSide==="left",y=p?t.x+t.w-u-m:t.x+u;h?et(o,Math.round(y),d,m,c,Mt(kt(l,l?.row,l?.col,f),n,r,l),r,i):a(o,Math.round(y),d,c,n,i,r.mode==="modern");let M=p?t.x+u:t.x+u+m+Math.round(4*i);if(e.image){const S=yt(e.image);S&&bt(o,S,M,d,c,c),M+=c+Math.round(3*i)}j(o,e.text,M,t.y,t.h,e.ink??U(s)),e.disabled&&H(o,!1)}function je(o,t,e,n,s){const{items:i,horizontal:r,flow:a,maxRows:l,maxCols:f}=t,c=[],u=i.length;if(u===0)return c;const d=(t.pad??0)*e,h=(t.spacingX??0)*e,m=(t.spacingY??0)*e,p=o.x+d,y=o.y+d,M=o.w-d*2,S=o.h-d*2;if(a&&r&&n){const b=n.fontSize*1.45*e;let C=p,O=y,A=0;for(const X of i){const ft=s(X,n)*e;A>0&&(f&&A>=f||C+ft>p+M)&&(C=p,O+=b+m,A=0),c.push({x:C,y:O,w:ft,h:b}),C+=ft+h,A++}const G=(S-(O+b-y))/2;if(G>0)for(const X of c)X.y+=G;return c}let T;r?T=l?Math.ceil(u/l):f??u:T=f??(l?Math.ceil(u/l):1),T=Math.max(1,Math.min(T,u));const x=Math.ceil(u/T),g=(M-h*(T-1))/T,k=(S-m*(x-1))/x;for(let b=0;b<u;b++){const C=r?Math.floor(b/T):b%x,O=r?b%T:Math.floor(b/x);c.push({x:p+O*(g+h),y:y+C*(k+m),w:g,h:k})}return c}class He extends Y{static typeName="button";static sanitize(t){return{text:R(t.text),value:R(t.value),action:R(t.action),color:I(t.color),image:xe(t.image),disabled:$(t.disabled)}}paint(t,e,n,s,i){const r=Math.max(1,Math.round(i)),a=e.x+r,l=e.y+r,f=e.w-r*2,c=e.h-r*2;if(f<=0||c<=0)return;this.options.disabled&&H(t,!0),t.fillStyle=this.options.color??"#efefef",t.fillRect(a,l,f,c),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i)),t.strokeRect(a+.5,l+.5,f-1,c-1),F(t,s,i);const u=this.options.text??z(n),d=this.options.image?yt(this.options.image):null;if(d){const h=Math.min(c-2*r,Math.round(16*i)),m=u===""?0:t.measureText(u).width+Math.round(4*i),p=a+Math.max(r,(f-h-m)/2);bt(t,d,p,l+(c-h)/2,h,h),u!==""&&j(t,u,p+h+Math.round(4*i),l,c,s.color??"#000000")}else P(t,u,a,l,f,c,s.color??"#000000");this.options.disabled&&H(t,!1)}hitTest(t,e,n){return!this.options.disabled&&B(t,e,n)?{part:"button"}:null}activate(t,e,n){const{action:s,value:i,disabled:r}=this.options;if(r||i!==void 0&&!E(t,e,n,W(i)))return!1;const a={row:e,col:n,sheet:t.book.sheet,action:s??null};return s!==void 0&&$t(s,{app:t,...a}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:a})),!0}fitWidth(t,e){return L(e,this.options.text??z(t))+(this.options.image?20:0)+12}}const Vt=o=>({trackOn:I(o.trackOn),trackOff:I(o.trackOff),knob:I(o.knob),knobOn:I(o.knobOn),knobOff:I(o.knobOff),toggleWidth:v(o.toggleWidth,8,400),toggleHeight:v(o.toggleHeight,6,200),autoSize:o.autoSize===!1?!1:void 0,knobMargin:v(o.knobMargin,0,40),trackRadius:v(o.trackRadius,0,100),knobRadius:v(o.knobRadius,0,100),duration:v(o.duration,0,2e3)});class Ke extends Y{static typeName="checkbox";static sanitize(t){return{text:R(t.text),textTrue:R(t.textTrue),textFalse:R(t.textFalse),textNull:R(t.textNull),mode:tt(t.mode,["modern","toggle"]),threeState:t.mode==="toggle"?void 0:$(t.threeState),boxSize:v(t.boxSize,6,64),textSide:tt(t.textSide,["left","top","bottom","inside"]),wrap:$(t.wrap),hit:tt(t.hit,["box","cell"]),editable:$(t.editable),...Vt(t)}}get blocksEditing(){return this.options.editable!==!0}_state(t){return this.options.threeState&&(t===null||t==="")?null:Wt(t)}_caption(t){const e=this.options;return t===!0&&e.textTrue!==void 0?e.textTrue:t===!1&&e.textFalse!==void 0?e.textFalse:t===null&&e.textNull!==void 0?e.textNull:e.text}_hasCaption(){const t=this.options;return t.text!==void 0||t.textTrue!==void 0||t.textFalse!==void 0||t.textNull!==void 0}_side(){const{textSide:t,mode:e}=this.options;return t==="inside"&&e!=="toggle"?void 0:t}_box(t,e,n,s){const i=this.options,r=i.mode==="toggle",a=(r?i.toggleHeight??i.boxSize??13:i.boxSize??13)*e,l=this._side(),f=this._hasCaption(),c=f&&(l==="top"||l==="bottom"),u=c&&n?n.fontSize*1.25*e:0,d=Math.min(a,t.h-2*e-u);let h=r?K(i,d,e):d;if(r&&l==="inside"&&n){const M=this._longestCaption(s);M&&(h=Math.min(t.w-2*e,K(i,d,e,L(n,M)*e)))}const m=3*e;let p;!f||c||l==="inside"?l==="inside"&&n?.hAlign==="left"?p=t.x+m:l==="inside"&&n?.hAlign==="right"?p=t.x+t.w-m-h:p=t.x+(t.w-h)/2:p=l==="left"?t.x+t.w-m-h:t.x+m;let y=t.y+(t.h-d)/2;if(c){const M=d+u,S=t.y+(t.h-M)/2;y=l==="top"?S+u:S}else if(i.wrap&&f){const M=n?.vAlign;M==="top"?y=t.y+2*e:M!=="center"&&(y=t.y+t.h-d-2*e)}return{x:p,y,w:h,h:d}}_longestCaption(){const t=this.options;return[t.textTrue,t.textFalse,t.textNull,t.text].filter(Boolean).reduce((e,n)=>e.length>=n.length?e:n,"")}paint(t,e,n,s,i,r){const a=this.options,l=this._box(e,i,s,n);if(l.h<=2)return;const f=this._state(n),c=this._side(),u=this._caption(f);if(F(t,s,i),a.mode==="toggle"){const g=kt(r,r?.row,r?.col,"box"),k=Mt(g,f===!0,a,r);if(et(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),Math.round(l.h),k,a,i),c==="inside"&&u){t.save(),t.beginPath(),t.rect(l.x,l.y,l.w,l.h),t.clip();const b=l.w-l.h-2*i;P(t,u,k>.5?l.x+i:l.x+l.h+i,l.y,b,l.h,"#ffffff"),t.restore();return}}else Xt(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),f,i,a.mode==="modern");if(u===void 0||u==="")return;const d=U(s);if(c==="top"||c==="bottom"){const g=s.fontSize*1.25*i,k=c==="top"?l.y-g:l.y+l.h;P(t,u,e.x,k,e.w,g,d);return}const h=4*i,m=c==="left"?e.x+3*i:l.x+l.w+h,p=c==="left"?l.x-h-m:e.x+e.w-m-2*i;if(!a.wrap){j(t,u,m,e.y,e.h,d);return}const y=De(t,u,p),M=s.fontSize*1.2*i,S=y.length*M,T=s.vAlign,x=T==="top"?e.y+2*i:T==="center"?e.y+(e.h-S)/2:e.y+e.h-S-2*i;y.forEach((g,k)=>j(t,g,m,x+k*M,M,d))}hitTest(t,e,n,s=1,i=null){const{hit:r}=this.options;return r==="cell"||r!=="box"&&this._hasCaption()?B(t,e,n)?{part:"box"}:null:B(this._box(t,s,i),e,n)?{part:"box"}:null}activate(t,e,n){const{book:s}=t,i=this._state(_(s,s.sheet,e,n));return this.options.threeState?E(t,e,n,i===!0?"FALSE":i===!1?"":"TRUE"):E(t,e,n,i?"FALSE":"TRUE")}fitWidth(t,e){const n=this.options,s=n.mode==="toggle"?n.toggleHeight??n.boxSize??13:n.boxSize??13,i=this._caption(this._state(t)),r=this._side(),a=n.mode==="toggle"?n.toggleWidth??s*2:s,l=i?L(e,i):0;return r==="inside"?K(n,s,1,L(e,this._longestCaption()))+8:r==="top"||r==="bottom"?Math.max(a,l)+6:a+6+(l?l+4:0)}}class rt extends Y{static sanitize(t){return{items:Bt(t.items),horizontal:$(t.horizontal),separator:R(t.separator,16),flow:$(t.flow),maxRows:v(t.maxRows,1,200),maxCols:v(t.maxCols,1,200),spacingX:v(t.spacingX,0,64),spacingY:v(t.spacingY,0,64),pad:v(t.pad,0,64),boxSize:v(t.boxSize,6,64),textSide:tt(t.textSide,["left","inside"]),mode:tt(t.mode,["modern","toggle"]),...Vt(t)}}get blocksEditing(){return!0}_itemWidth(t,e){const n=this.options,s=n.boxSize??13,i=n.mode==="toggle"?K(n,s,1):s;if(n.textSide==="inside"&&(n.mode==="toggle"||this.type==="radio")){const r=L(e,t.text);return(n.mode==="toggle"?K(n,s,1,r):r+s+8)+6}return i+10+L(e,t.text)+(t.image?16:0)}_slots(t,e,n){return je(t,this.options,e,n,(s,i)=>this._itemWidth(s,i))}hitTest(t,e,n,s=1,i=null){if(!B(t,e,n))return null;const r=this._slots(t,s,i).findIndex(a=>B(a,e,n));return r<0||this.options.items[r].disabled?null:{part:"item",index:r}}_hitItem(t,e,n,s,i){const{book:r}=t,a=r.styles.list[r.sheet.style(e,n)]??r.styles.list[0];return this.hitTest(ot(t,e,n),s,i,t.grid.zoom,a)}_nextEnabled(t){const{items:e}=this.options;for(let n=1;n<=e.length;n++){const s=(t+n)%e.length;if(!e[s].disabled)return s}return-1}fitWidth(t,e){const{items:n,horizontal:s,spacingX:i=0,pad:r=0,maxCols:a}=this.options,l=n.map(u=>this._itemWidth(u,e));if(l.length===0)return 0;const f=s?Math.min(a??l.length,l.length):1,c=Math.max(...l);return(s&&f===l.length?l.reduce((u,d)=>u+d,0):c*f)+i*(f-1)+r*2}}class Xe extends rt{static typeName="radio";paint(t,e,n,s,i,r){F(t,s,i),this._slots(e,i,s).forEach((a,l)=>{const f=this.options.items[l];Jt(t,a,f,J(n,f.value),s,i,this.options,Yt,r,l)})}activate(t,e,n,s,i){const{items:r}=this.options;if(r.length===0)return!1;let a;if(s==null){const{book:l}=t,f=_(l,l.sheet,e,n);if(a=this._nextEnabled(r.findIndex(c=>J(f,c.value))),a<0)return!1}else{const l=this._hitItem(t,e,n,s,i);if(!l)return!1;a=l.index}return E(t,e,n,W(r[a].value))}}const lt=o=>o.separator??", ";function wt(o,t){if(o==null||o==="")return new Set;const e=String(o).split(lt(t).trim()||",").map(n=>n.trim().toLowerCase());return new Set(t.items.filter(n=>e.includes(String(n.value).toLowerCase())).map(n=>n.value))}class Ye extends rt{static typeName="checklist";paint(t,e,n,s,i,r){F(t,s,i);const a=wt(n,this.options),l=this.options.mode==="toggle"?et:Xt;this._slots(e,i,s).forEach((f,c)=>{const u=this.options.items[c];Jt(t,f,u,a.has(u.value),s,i,this.options,l,r,c)})}_write(t,e,n,s){return E(t,e,n,W(s.join(lt(this.options))))}activate(t,e,n,s,i){const{items:r}=this.options,{book:a}=t,l=wt(_(a,a.sheet,e,n),this.options);if(s==null)return gt(t,e,n,{items:r.filter(u=>!u.disabled),selected:[...l],multi:!0,label:"Choices",onDone:u=>this._write(t,e,n,u)}),!0;const f=this._hitItem(t,e,n,s,i);if(!f)return!1;const c=r[f.index];return l.has(c.value)?l.delete(c.value):l.add(c.value),this._write(t,e,n,r.filter(u=>l.has(u.value)).map(u=>u.value))}}class Ue extends rt{static typeName="buttonlist";static sanitize(t){return{...rt.sanitize(t),horizontal:t.horizontal!==!1||void 0,multiple:$(t.multiple),selectedColor:I(t.selectedColor),selectedInk:I(t.selectedInk)}}_itemWidth(t,e){return L(e,t.text)+14+(t.image?18:0)}_chosen(t){if(this.options.multiple)return wt(t,this.options);const e=this.options.items.find(n=>J(t,n.value));return new Set(e?[e.value]:[])}paint(t,e,n,s,i){F(t,s,i);const r=this.options,a=Math.max(1,Math.round(i)),l=this._chosen(n);this._slots(e,i,s).forEach((f,c)=>{const u=r.items[c],d=l.has(u.value),h=Math.round(f.x)+a,m=Math.round(f.y)+a,p=Math.round(f.w)-a*2,y=Math.round(f.h)-a*2;if(p<=0||y<=0)return;u.disabled&&H(t,!0);const M=r.selectedColor??w.theme.accent;t.fillStyle=u.color??(d?M:"#efefef"),t.fillRect(h,m,p,y);const S=d&&u.color?a*2:a;t.strokeStyle=d?M:"#8f8f8f",t.lineWidth=S,t.strokeRect(h+S/2,m+S/2,p-S,y-S),t.save(),t.beginPath(),t.rect(h,m,p,y),t.clip();const T=u.ink??(d&&!u.color?r.selectedInk??"#ffffff":s.color??"#000000"),x=u.image?yt(u.image):null;if(x){const g=Math.min(y-2*a,Math.round(14*i)),k=t.measureText(u.text).width+(u.text?Math.round(4*i):0),b=h+Math.max(a,(p-g-k)/2);bt(t,x,b,m+(y-g)/2,g,g),j(t,u.text,b+g+Math.round(4*i),m,y,T)}else P(t,u.text,h,m,p,y,T);t.restore(),u.disabled&&H(t,!1)}),r.items.length>0&&(t.textAlign="left")}activate(t,e,n,s,i){const{items:r,multiple:a}=this.options;if(r.length===0)return!1;const{book:l}=t,f=_(l,l.sheet,e,n);if(s==null){if(a)return gt(t,e,n,{items:r.filter(h=>!h.disabled),selected:[...this._chosen(f)],multi:!0,label:"Choices",onDone:h=>E(t,e,n,W(h.join(lt(this.options))))}),!0;const d=this._nextEnabled(r.findIndex(h=>J(f,h.value)));return d>=0&&E(t,e,n,W(r[d].value))}const c=this._hitItem(t,e,n,s,i);if(!c)return!1;const u=r[c.index];if(a){const d=this._chosen(f);return d.has(u.value)?d.delete(u.value):d.add(u.value),E(t,e,n,W(r.filter(h=>d.has(h.value)).map(h=>h.value).join(lt(this.options))))}return E(t,e,n,J(f,u.value)?"":W(u.value))}}function at(o,t,e){if(typeof o=="number")return o;if(typeof o=="string"&&t){const n=t.findIndex(s=>s.toLowerCase()===o.toLowerCase());if(n>=0)return n}return e}function St(o,t,e,n){const s=[];for(let i=0;i<o;i++){const r=z(t(i,e)),a=z(t(i,n));(r!==""||a!=="")&&s.push({text:String(r),value:String(a)})}return s}function Je(o,t,e,{textColumn:n,valueColumn:s},i,r){const a=e.replace(/^=/,"").trim(),l=e[0]==="="?void 0:o.engine?.tables.get(a.toUpperCase());if(l){const M=l.columns?.map(k=>typeof k=="string"?k:k?.name??""),S=at(n,M,0),T=at(s,M,S),x=l.r0+(l.headerRows??1),g=l.r1-x+1-(l.totalsRows??0);return St(g,(k,b)=>_(o,l.sheet,x+k,l.c0+b),S,T)}const f=at(n,null,0),c=at(s,null,f),u=a.lastIndexOf("!"),d=e[0]==="="?null:dt(u>=0?a.slice(u+1):a);if(d){const M=u>=0?a.slice(0,u).replace(/^'|'$/g,"").replace(/''/g,"'"):null,S=M===null?t:o.sheets.find(x=>x.name.toLowerCase()===M.toLowerCase());if(!S)return[];const T=Math.min(d.r1,S.maxRow)-d.r0+1;return St(T,(x,g)=>_(o,S,d.r0+x,d.c0+g),f,c)}const{engine:h}=o;if(!h)return[];let m;try{const M=h.template(a,i,r);if(M.invalid)return[];m=M.fn(i,r,t),m&&m.sheet&&(m=h.toArr(m))}catch{return[]}if(!m||!m.data)return m==null||typeof m=="object"?[]:[{text:String(z(m)),value:String(z(m))}];const p=m.cols,y=(M,S)=>{const T=m.data[M*p+S];return T===void 0||T!==null&&typeof T=="object"?null:T};return St(m.rows,y,f,c)}function Ve(o,t,e){if(e[0]==="=")return null;const n=e.trim(),s=o.engine?.tables.get(n.toUpperCase());if(s)return`${o.sheets.indexOf(s.sheet)}:${s.sheet.revision}:${s.r0}:${s.r1}:${s.c0}:${s.c1}`;const i=n.lastIndexOf("!"),r=i>=0?n.slice(0,i).replace(/^'|'$/g,"").replace(/''/g,"'"):null,a=r===null?t:o.sheets.find(l=>l.name.toLowerCase()===r.toLowerCase());return a?`${o.sheets.indexOf(a)}:${a.revision}`:null}const Gt=new WeakMap;function Tt(o,t){if(t==null)return;let e=Gt.get(o);if(e===void 0){e=new Map;for(const n of o){const s=String(n.value).toLowerCase();e.has(s)||e.set(s,n.text)}Gt.set(o,e)}return e.get(String(t).toLowerCase())}class Ge extends Y{static typeName="combobox";static sanitize(t){return{items:Bt(t.items),editable:$(t.editable),source:typeof t.source=="string"&&t.source.length<=500?t.source:void 0,textColumn:typeof t.textColumn=="string"?R(t.textColumn,200):v(t.textColumn,0,49),valueColumn:typeof t.valueColumn=="string"?R(t.valueColumn,200):v(t.valueColumn,0,49),maxItems:v(t.maxItems,1,100),float:t.float===!1?!1:void 0}}get blocksEditing(){return this.options.editable!==!0}get opensList(){return!0}_items(t,e,n,s){const{source:i,items:r}=this.options;if(i===void 0)return r;const a=Ve(t,e,i);return((a===null?this.sourceFrame!==w.id||this.sourceFrame===void 0:this.sourceStamp!==a)||this.sourceItems===void 0)&&(this.sourceFrame=w.id,this.sourceStamp=a,this.sourceItems=Je(t,e,i,this.options,n,s)),this.sourceItems}_arrow(t,e){const n=Math.min(16*e,t.h);return{x:t.x+t.w-n,y:t.y+(t.h-n)/2,w:n,h:n}}paint(t,e,n,s,i,r){const a=r?.printing===!0,l=this._arrow(e,i),f=r?.book?this._items(r.book,r.sheet,r.row,r.col):this.options.items,c=Tt(f,n)??Te(n,s);if(F(t,s,i),t.save(),t.beginPath(),t.rect(e.x,e.y,a?e.w:e.w-l.w,e.h),t.clip(),j(t,c,e.x+Math.round(2*i),e.y,e.h,U(s)),t.restore(),a)return;const u=Math.round(l.x),d=Math.round(l.y),h=Math.round(l.w);t.fillStyle="#f7f7f7",t.fillRect(u,d,h,h),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i/2)),t.strokeRect(u+.5,d+.5,h-1,h-1),t.fillStyle="#444444",t.beginPath(),t.moveTo(u+h*.28,d+h*.4),t.lineTo(u+h*.72,d+h*.4),t.lineTo(u+h*.5,d+h*.66),t.closePath(),t.fill()}hitTest(t,e,n,s=1){return B(t,e,n)?B(this._arrow(t,s),e,n)?{part:"arrow"}:this.options.editable?null:{part:"text"}:null}activate(t,e,n){const{book:s}=t,i=_(s,s.sheet,e,n);this.sourceFrame=void 0,this.sourceItems=void 0;const r=this._items(s,s.sheet,e,n);this.sourceFrame=void 0;const l=Tt(r,i)===void 0?void 0:r.find(f=>J(i,f.value));return gt(t,e,n,{items:r,selected:l?[l.value]:[],label:"Choices",maxItems:this.options.maxItems??20,moveOnSide:!0,float:this.options.float!==!1,onDone:f=>f.length===0?!0:E(t,e,n,W(f[0]))}),!0}fitWidth(t,e){const n=Tt(this.sourceItems??this.options.items,t)??z(t);return L(e,String(n))+22}}const xt=new Set;class qe extends Y{static typeName="hyperlink";static sanitize(t){return{url:Ft(t.url),location:Ce(t.location),text:R(t.text),color:I(t.color),visitedColor:I(t.visitedColor),tooltip:R(t.tooltip),action:R(t.action),activeOnClick:t.activeOnClick===!1?!1:void 0}}get tooltip(){return this.options.tooltip}get runsWithoutSelecting(){return this.options.activeOnClick===!1}paint(t,e,n,s,i){const r=this.options.text??z(n);if(r==="")return;F(t,s,i);const a=e.x+Math.round(2*i),{url:l,location:f,color:c,visitedColor:u}=this.options,d=l??f??(typeof n=="string"?n:""),h=xt.has(d)?u??"#954f72":c??s.color??"#0563c1";j(t,r,a,e.y,e.h,h);const m=s.fontSize*i,p=Math.min(t.measureText(r).width,e.w-Math.round(4*i));t.fillRect(a,Math.round(e.y+e.h/2+m*.42),p,Math.max(1,Math.round(m/14)))}hitTest(t,e,n){return B(t,e,n)?{part:"link"}:null}activate(t,e,n){const{url:s,location:i,action:r}=this.options,{book:a}=t;if(r!==void 0){const f={row:e,col:n,sheet:a.sheet,action:r};$t(r,{app:t,...f}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:f}))}if(i)return xt.add(i),t.controller._followLink({location:i}),!0;const l=s??Ft(_(a,a.sheet,e,n));return l?(xt.add(l),t.grid.invalidate(),t.controller._followLink({target:l}),!0):(r===void 0&&t.shell.setStatus("This link has no web or mail address to open."),!0)}fitWidth(t,e){return L(e,String(this.options.text??z(t)))+7}}class Ze extends Y{static typeName="progress";static sanitize(t){const e=n=>Number.isFinite(n)?n:void 0;return{min:e(t.min),max:e(t.max),color:I(t.color),hideText:t.hideText===!0||void 0}}paint(t,e,n,s,i){const r=this.options.min??0,a=this.options.max??1,l=Math.max(1,Math.round(2*i)),f=e.x+l,c=e.y+l,u=e.w-l*2,d=e.h-l*2;if(u<=0||d<=0)return;if(t.fillStyle="#e6e6e6",t.fillRect(f,c,u,d),F(t,s,i),typeof n=="string"&&n.startsWith("#")){P(t,n,f,c,u,d,U(s));return}const h=typeof n=="number"?n:0,m=a>r?Math.max(0,Math.min(1,(h-r)/(a-r))):0;t.fillStyle=this.options.color??w.theme.accent,t.fillRect(f,c,Math.round(u*m),d),this.options.hideText||P(t,`${Math.round(m*100)}%`,f,c,u,d,m>.5?"#ffffff":U(s))}}for(const o of[He,Ke,Xe,Ye,Ue,Ge,qe,Ze])Se(o);const On=ve();function N(o,t,e){if(!q(o))return null;const n=o.mergeAt(t,e);return D(o,n?n.r0:t,n?n.c0:e)??null}const V=(o,t,e,n)=>o.styles.list[t.style(e,n)]??o.styles.list[0];function qt(o,t,e,n,s,i,r,a,l,f,c,u,d){const h=e.kind(i,r)&ct,m=V(n,e,i,r);h===ut&&(o.fillStyle=m.fill??s.cellBg,o.fillRect(a,l,f-d,c-d));const p=At(e,i,r,m);if(p!==null){const y=Math.round(p[0]*u);a+=y,f=Math.max(0,f-y-Math.round(p[1]*u))}o.save(),o.beginPath(),o.rect(a,l,f,c),o.clip(),w.row=i,w.col=r,t.paint(o,{x:a,y:l,w:f,h:c},_(n,e,i,r),m,u,w),o.restore()}function An(o,t,e,n,s){const{sheet:i,book:r,theme:a,dpr:l,zoom:f}=t,c=i.cellTypes;w.theme=a,w.book=r,w.sheet=i,w.grid=t,w.printing=!1,w.id++;const{ca:u,cb:d,ra:h,rb:m,s:p,xs:y,ys:M}=n,S=Math.max(1,Math.round(l*Math.min(f,1))),T=s.length>0,x=(g,k,b)=>{if(T&&i.mergeAt(k,b)!==null)return;const C=y[b-u],O=M[k-h],A=y[b-u+1]-C,G=M[k-h+1]-O,X=t.indicatorWidth?.(k,b,A,p)??0;A>0&&G>0&&qt(o,g,i,r,a,k,b,C+X,O,A-X,G,p,S)};if(!i.cellTypeRules&&c.size<(d-u+1)*(m-h+1))for(const[g,k]of c){const b=Math.floor(g/16384),C=g-b*16384;b>=h&&b<=m&&C>=u&&C<=d&&x(k,b,C)}else for(let g=h;g<=m;g++)for(let k=u;k<=d;k++){const b=D(i,g,k);b!==void 0&&x(b,g,k)}for(const g of s){const k=D(i,g.r0,g.c0);if(k===void 0||g.c1<u||g.c0>d)continue;const b=t._rectInPane(g,e,p),C=t.indicatorWidth?.(g.r0,g.c0,b.w,p)??0;qt(o,k,i,r,a,g.r0,g.c0,b.x+C,b.y,b.w-C,b.h,p,S)}}const Qe={cellBg:"#ffffff",cellInk:"#000000",accent:"#404040"};function Wn(o,t,e,n,s,i,r,a,l){const f=D(e,n,s);return f===void 0?!1:(w.theme=Qe,w.book=t,w.sheet=e,w.grid=null,w.printing=!0,w.row=n,w.col=s,w.id++,o.save(),o.beginPath(),o.rect(i,r,a,l),o.clip(),f.paint(o,{x:i,y:r,w:a,h:l},_(t,e,n,s),V(t,e,n,s),1,w),o.restore(),w.printing=!1,!0)}function Pn(o,t,e,n,s,i,r){const a=t.cellTypes;if(!t.cellTypeRules&&!(a instanceof Map))return;const l=(f,c)=>{(t.kind(f,c)&ct)===ut&&t.mergeAt(f,c)===null&&r(f,c)};if(!t.cellTypeRules&&a.size<(n-e+1)*(i-s+1))for(const f of a.keys()){const c=Math.floor(f/16384),u=f-c*16384;c>=e&&c<=n&&u>=s&&u<=i&&l(c,u)}else for(let f=e;f<=n;f++)for(let c=s;c<=i;c++)D(t,f,c)&&l(f,c)}function $n(o,t,e,n,s){const{book:i}=o,{sheet:r}=i,a=N(r,t,e);if(a===null||a.runsWithoutSelecting!==!0||!a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function Bn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(Q(r,i)&&Ae(o,t,e,n,s))return!0;const a=N(r,t,e);if(a===null||!a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function Fn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(Q(r,i)&&Ie(o,t,e,n,s))return"pointer";if(!q(r))return null;const a=N(r,t,e),l=a?.tooltip,{host:f}=o.grid;return l!==void 0?f.title=l:f.title!==""&&(f.title=""),a!==null&&a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e))?"pointer":null}function Nn(o,t){const{sheet:e}=o.book,n=Q(e,o.book);if(!q(e)&&!e.cellDropdowns&&!n)return!1;const s=o.grid.selection,{row:i,col:r}=s,a=t.metaKey||t.ctrlKey||t.shiftKey;if(t.altKey&&!a&&n&&/^Digit[1-9]$/.test(t.code)&&We(o,i,r,Number(t.code[5])-1))return!0;if(t.key==="ArrowDown"&&t.altKey&&!a){if(Ot(o,i,r)||n&&Ee(o,i,r))return!0;const l=N(e,i,r);return l&&l.opensList?l.activate(o,i,r,null,null):!1}if((t.key==="Delete"||t.key==="Backspace")&&!a&&!t.altKey&&q(e)&&tn(o))return!0;if(t.key===" "&&!a&&!t.altKey){const l=N(e,i,r);if(l===null)return!1;const f=e.mergeAt(i,r);return l.activate(o,f?f.r0:i,f?f.c0:r,null,null)}return!1}function tn(o){const{book:t,grid:e}=o,{sheet:n}=t,s=e.selection.ranges;let i=s,r=[];for(const f of n.cellTypeRules??[])for(const c of f.ranges){if(f.spec.type==="checkbox")for(const u of i){const d=vt(u,c);d&&r.push(d)}i=i.flatMap(u=>_t(u,c))}const a=[];for(const[f,c]of n.cellTypes??[]){const u=Math.floor(f/Z),d=f%Z,h={r0:u,r1:u,c0:d,c1:d};s.some(m=>vt(m,h))&&(c.type==="checkbox"?a.push(h):r=r.flatMap(m=>_t(m,h)))}if(r=r.concat(a),!r.length)return!1;const l=new Set;for(const f of r)te(n,f,(c,u)=>{Wt(_(t,n,c,u))&&l.add(pt(c,u))});return l.size?t.transact("entry",f=>{for(const c of l)t.setInput(f,Math.floor(c/Z),c%Z,"FALSE")}):fe(t,"Clear",()=>{re(t,r,"cellTypes",null),t.clearRange(s)}),e.invalidate(),o.controller?.syncFormulaBar?.(),!0}function Dn(o,t,e){const{sheet:n}=o.book;if(!q(n))return!1;const s=N(n,t,e);return s===null||!s.blocksEditing?!1:(o.controller.focusGrid(),s.opensList?s.activate(o,t,e,null,null):o.shell.setStatus("This cell holds a control. Click it or press Space to change it."),!0)}function jn(o,t,e){const{book:n}=o,s=N(n.sheet,t,e);return s===null?void 0:s.editText(_(n,n.sheet,t,e))}function Hn(o,t,e,n){const s=N(o.book.sheet,t,e);return s===null?n:s.parseEdit(n)}function Kn(o,t,e,n,s){const i=D(o,e,n),r=V(t,o,e,n);let a=s;if(i!==void 0){w.book=t,w.sheet=o,w.row=e,w.col=n;const f=i.fitWidth(_(t,o,e,n),r);f>0&&(a=f-7)}const l=At(o,e,n,r);return l===null?a:a+l[0]+l[1]}function Xn(o){jt(o),o.grid.host.addEventListener("pointerleave",()=>{Q(o.book.sheet,o.book)&&Dt(o,null,0,0)})}function Yn(o,t){const e=[];for(const n of[o.cellTypes,o.cellButtons])if(n instanceof Map)for(const s of n.keys())s%16384===t&&e.push(Math.floor(s/16384));for(const n of o.cellTypeRules??[])for(const s of n.ranges)if(!(t<s.c0||t>s.c1)){for(let i=s.r0;i<=s.r1;i++)if((o.kind(i,t)&ct)===ut&&!o.mergeAt(i,t)&&D(o,i,t)===n.spec){e.push(i);break}}return e}const Un=(o,t)=>ie(o,t);function en(o,t,e){const n=o.lastIndexOf("!");return n<0||o.slice(0,n).replace(/^'|'$/g,"").replace(/''/g,"'").toLowerCase()!==t.toLowerCase()?o:`${ne(e)}${o.slice(n)}`}function Zt(o,t,e){let n=null;for(const s of["source","location"]){if(typeof o[s]!="string")continue;const i=en(o[s],t,e);i!==o[s]&&((n??={...o})[s]=i)}return n}oe.push((o,t,e)=>{const n=new Map,s=(r,a,l)=>{const f=r[a];if(!(f instanceof Map))return;let c=null;for(const[u,d]of f){n.has(d)||n.set(d,l(d));const h=n.get(d);h!==d&&(c??=new Map(f)).set(u,h)}c!==null&&(r[a]=c,r.cellTypesChanged=!0)},i=r=>{const a=Zt(r,t,e);return a===null?r:Lt(r.type,a)};for(const r of o.sheets){const a=l=>{const f=Zt(l.options,t,e);return f===null?l:Pt(l.type,f)};s(r,"cellTypes",a),r.cellTypeRules&&(r.cellTypeRules=r.cellTypeRules.map(({ranges:l,spec:f})=>({ranges:l,spec:a(f)})),r.cellTypesChanged=!0),s(r,"cellDropdowns",i),s(r,"cellButtons",l=>{const f=l.map(c=>{if(!c.dropdown||c.dropdown===!0)return c;const u=i(c.dropdown);return u===c.dropdown?c:{...c,dropdown:u}});return f.some((c,u)=>c!==l[u])?Nt(f):l})}});function nn(o){o.sort((i,r)=>i%16384-r%16384||i-r);const t=[];let e=-1,n=-1;const s=()=>{if(e<0)return;const i=Math.floor(e/16384),r=e-i*16384,a=Math.floor(n/16384);t.push(Rt({r0:i,c0:r,r1:a,c1:r}))};for(const i of o)e>=0&&i===n+16384||(s(),e=i),n=i;return s(),t}function Ct(o,t,e){if(!o||o.size===0)return;const n=new Map;for(const[s,i]of o){const r=zt(i);let a=n.get(r);a===void 0&&(a=[],n.set(r,a)),a.push(s)}for(const[s,i]of n)e.push({kind:t,json:s,keys:i})}function on(o){const t=[];if(Ct(o.cellTypes,"type",t),Ct(o.cellDropdowns,"dropdown",t),Ct(o.cellButtons,"buttons",t),!o.cellTypeRules&&t.length===0)return null;const e=t.map(s=>`<entry kind="${s.kind}" config="${mt(s.json)}" ref="${nn(s.keys).join(" ")}"/>`).join(""),n=(o.cellTypeRules??[]).map(({ranges:s,spec:i})=>`<rangeRule config="${mt(zt(i))}" ref="${s.map(Rt).join(" ")}"/>`).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<cellTypes xmlns="${de}" version="1" sheet="${mt(o.name)}">${e}${n}</cellTypes>`}function sn(o,t){let e;try{e=Et(new TextEncoder().encode(o))}catch{return}if(e?.n!=="cellTypes")return;const n=new Map,s=new Map,i=new Map;let r=0;for(const l of It(e,"entry")){let f;try{f=JSON.parse(ht(l.a.config??""))}catch{continue}if(f===null||typeof f!="object")continue;const{kind:c}=l.a;let u;if(c==="dropdown"?u=Lt(f.type,f):c==="buttons"?u=Nt(f):u=nt(f),u===null)continue;const d=c==="dropdown"?s:c==="buttons"?i:n;for(const h of String(l.a.ref??"").split(/\s+/)){const m=dt(h);if(m)for(let p=m.r0;p<=m.r1&&r<Kt;p++)for(let y=m.c0;y<=m.c1&&r<Kt;y++)d.set(pt(p,y),u),r++}}const a=[];for(const l of It(e,"rangeRule")){let f;try{f=JSON.parse(ht(l.a.config??""))}catch{continue}if(!f||typeof f!="object")continue;const c=nt(f),u=String(l.a.ref??"").split(/\s+/).map(dt).filter(Boolean);c&&u.length&&a.push({ranges:u,spec:c})}t.cellTypeRules=a.length?a:null,t.cellTypes=n.size>0?n:null,t.cellDropdowns=s.size>0?s:null,t.cellButtons=i.size>0?i:null}const rn=o=>{for(const t of o.formulas.descriptors())if(t.cm||t.tpl?.mayArray)return!0;return!1};function Jn(o){const t=[];return o.sheets.forEach((e,n)=>{const s=on(e);s!==null&&t.push(ue(n,s))}),t.push(...me(o),...Pe(o),...ge(o),...Me(o),...we(o,o.sheets.some(e=>rn(e)))),t}async function Vn(o,t){const e=await se(o);for(const{text:n}of await he(e)){if(n.includes(ce)){pe(n,t);continue}let s=null;try{s=Et(new TextEncoder().encode(n))}catch{continue}const i=ht(s?.a?.sheet),r=t.sheets.find(a=>a.name===i);r&&sn(n,r)}await Qt(e,t),await ye(e,t),await be(e,t),await ke(e,t)}export{On as CELL_TYPE_NAMES,Xn as attachCellEvents,jt as attachFileDrop,le as cellDropdownArrow,Kn as cellFitWidth,pt as cellKey,N as cellTypeAt,Dn as cellTypeBlocksEdit,Fn as cellTypeCursor,jn as cellTypeEditText,Hn as cellTypeParseEdit,Jn as cellTypesPackage,ae as closeDropdown,Yn as fitRowsOfColumn,Bn as handleCellClick,Nn as handleCellKey,Q as hasCellButtons,$e as hideEditingButtons,Vn as loadCellTypes,Pt as makeCellType,Ot as openCellDropdown,ze as paintCellButtons,An as paintCellTypes,Le as paintFloatingButtons,Oe as paintStyleButtons,sn as parse,$n as pressWithoutSelecting,Wn as printCellType,Pn as printEmptyTypedCells,_e as registerButtonAction,Re as registerCellType,on as serialize,Un as shiftCellTypes,Be as showEditingButtons,Dt as trackButtonHover};
|
package/celltypes/dropdowns.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{formulaEntryLimit as
|
|
1
|
+
import{cellEditable as dt}from"../core/protection.js";import{allUndo as pt}from"../cells/block.js";import{writeCellTypes as ft}from"../core/cell-type-rules.js";import{formulaEntryLimit as ht}from"../calc/parser.js";import{overlayRoot as mt}from"../api/overlay.js";import{BOOL as yt,EMPTY as gt,ERR as xt,ERRORS as vt,FORMULA as bt,KIND_MASK as Z,NUM as wt,STR as kt}from"../core/sheet.js";import{MAX_COLS as Ct,MAX_ROWS as Dt,parseRangeRef as St}from"../core/address.js";import{partsToSerial as N,serialToParts as P}from"../core/numfmt.js";import{validateEntry as Lt,validationAt as Et}from"../core/cond-format.js";import{parseInput as At}from"../core/input.js";import{askAboutInvalid as Ft}from"../cells/validation-alert.js";import{t as k}from"../i18n/index.js";const z=(e,t)=>e*16384+t,G=["calendar","time","month","datetime","color","slider","calculator","list"],j=new Map;function he(e,t){G.includes(e)||G.push(e),j.set(e,t)}const Mt=2e5,tt=5e3,K={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function Y(e,t,n,o){const r=t.kind(n,o)&Z;if(r===gt)return null;const s=t.value(n,o);return r===wt?s:r===kt?e.strings.get(s):r===yt?s!==0:r===xt?vt[s]??"#N/A":null}function Tt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function V(e,t,n,{overFormula:o=!1}={}){const{book:r}=e,{sheet:s}=r;return e.loading?!1:s.protection&&!dt(r,s,t,n)?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!o&&(s.kind(t,n)&bt)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function Rt(e,t,n,o,r){const{book:s}=e,{sheet:u}=s,i=Et(u,t,n);if(!i||!i.showError)return!0;const l=At(o);if(Lt(s,u,i,t,n,l.kind??0,l.value,l.text??o))return!0;const a=()=>{};return Ft(e,i,{retry:a,cancel:a,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:a}),!1}function It(e,t,n,o,{format:r,overFormula:s=!1}={}){if(!V(e,t,n,{overFormula:s}))return!1;if(o.startsWith("=")&&e.book.styles.get(e.book.sheet.style(t,n)).numFmt!=="@"){const u=ht(o.slice(1));if(u)return e.shell.setStatus(k(u)),!1}return Rt(e,t,n,o,()=>et(e,t,n,o,r))?et(e,t,n,o,r):!1}function et(e,t,n,o,r){const{book:s,grid:u,controller:i}=e,l=s.sheet;return s.transact("entry",a=>{s.setInput(a,t,n,o),r&&s.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,s.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const q=(e,t)=>n=>{const o=q(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,o};function $t(e,{r0:t,c0:n,r1:o,c1:r}){const s=t===0&&o===Dt-1,u=n===0&&r===Ct-1;return{r0:t,c0:n,r1:s?Math.max(e.maxRow,999):o,c1:u?Math.max(e.maxCol,25):r}}function me(e,t,n,o){const r=e.sheet;if(n==="cellTypes")return e.transact("cell type",i=>{const l=i.sheet,a=l.cellTypes,y=l.cellTypeRules;return ft(l,t,o),l.cellTypes===a&&l.cellTypeRules===y?null:pt([q(n,a),q("cellTypeRules",y)])}),!0;const s=t.map(i=>$t(r,i));let u=0;for(const i of s)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>Mt?!1:(e.transact("cell type",()=>{const i=q(n,r[n]??null),l=new Map(r[n]??[]);for(const a of s)for(let y=a.r0;y<=a.r1;y++)for(let x=a.c0;x<=a.c1;x++)o===null?l.delete(z(y,x)):l.set(z(y,x),o);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function ye(e,t={}){if(!G.includes(e))return null;const n={type:e},o=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(o("min"),o("max"),o("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,tt).filter(Array.isArray).map(r=>r.slice(0,50).map(s=>typeof s=="number"?s:String(s).slice(0,1e3))))),j.get(e)?.sanitize?.(t,n),Object.freeze(n)}function nt(e,t,n){const o=e.cellDropdowns;if(!o)return null;const r=e.mergeAt(t,n);return o.get(r?z(r.r0,r.c0):z(t,n))??null}function ge(e){const{sheet:t,sel:n,grid:o}=e;if(!t.cellDropdowns||!nt(t,n.row,n.col))return null;const r=o.cellRect(n.row,n.col),s=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-s,size:s}}const rt="ct-popup-style",Ot=`
|
|
2
2
|
.ct-popup { position: fixed; z-index: 60; padding: 8px; border-radius: 8px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: var(--shadow); font: 12px -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; outline: none; max-width: calc(100vw - 16px); }
|
|
3
3
|
.ct-popup button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 0; cursor: default; }
|
|
4
4
|
.ct-popup button:where(:not(.ct-btn)):hover:not(:disabled) { background: var(--hover); }
|
|
@@ -38,5 +38,6 @@ import{formulaEntryLimit as rt}from"../calc/parser.js";import{overlayRoot as ot}
|
|
|
38
38
|
.ct-item:hover { background: var(--hover); }
|
|
39
39
|
.ct-item.ct-cursor { background: var(--pressed); }
|
|
40
40
|
.ct-mark { width: 12px; text-align: center; }
|
|
41
|
+
.ct-count { padding: 4px 8px 0; color: var(--ink-soft); font-size: 11px; }
|
|
41
42
|
.ct-value { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
|
|
42
|
-
`;function Et(){if(document.getElementById(J))return;const e=document.createElement("style");e.id=J,e.textContent=Dt,document.head.append(e)}const f=(e,t={},...n)=>{const s=document.createElement(e);for(const[r,o]of Object.entries(t))r==="class"?s.className=o:r==="text"?s.textContent=o:r.startsWith("aria")||r==="role"?s.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,o):s[r]=o;return s.append(...n.filter(r=>r!=null)),s};let E=null;const ne=()=>E!==null;function re(e,t){E!==null&&(E.keepOpen=e,E.onClose=t)}function At(e){E!==null&&(E.mode=e?"float":"confine")}function oe(){E!==null&&E.mode!=="float"&&L(!1)}function L(e=!0){if(E===null)return;const{el:t,app:n,onDocPointer:s,onClose:r}=E;E=null,r?.(),document.removeEventListener("pointerdown",s,!0),t.remove(),e&&n.controller.focusGrid()}function S(e,t,n,s,r){L(!1),Et(),e.grid.ensureVisible(t,n);const o=f("div",{class:"ct-popup",role:"dialog",ariaLabel:w(s),tabIndex:-1}),u=l=>{!o.contains(l.target)&&!E?.keepOpen?.(l)&&L(!1)};E={el:o,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),o.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),L();else if(l.key==="Tab"){const a=[...o.querySelectorAll('button, input, [tabindex="0"]')].filter(x=>!x.disabled&&x.tabIndex>=0&&x.offsetParent!==null);if(a.length===0)return;const y=a.indexOf(document.activeElement);l.preventDefault(),a[(y+(l.shiftKey?-1:1)+a.length)%a.length].focus()}}),ot().append(o);const i=r(o);return Ft(e,t,n,o),(i??o).focus({preventScroll:!0}),o}function St(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,o=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=o,l=Math.max(60,i?r:o);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const y=n.querySelector(".ct-list");y&&(y.style.maxHeight=`${Math.max(30,l-18)}px`)}const a=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-a}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function Ft(e,t,n,s){const r=e.grid.host.getBoundingClientRect(),o=e.grid.domRect(e.grid.cellRect(t,n));if(E?.mode==="confine"){St(r,o,s);return}const u=s.getBoundingClientRect(),i=2,l=r.top+o.y+o.h+i,a=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+o.y-u.height-i);s.style.top=`${a}px`,s.style.left=`${Math.max(8,Math.min(r.left+o.x,window.innerWidth-u.width-8))}px`}function M(e,t,n,s,r){const o=wt(e,t,n,s,{...r,overFormula:!0});return o&&L(),o}const $=(e,t,n=null)=>f("div",{class:"ct-foot"},n,f("button",{class:"ct-btn",type:"button",text:w("Cancel"),onclick:()=>L()}),f("button",{class:"ct-btn ct-primary",type:"button",text:w("OK"),onclick:t})),_=["January","February","March","April","May","June","July","August","September","October","November","December"],Lt=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],N=61;function O(){const e=new Date;return I(e.getFullYear(),e.getMonth()+1,e.getDate())}const Q=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function T(e,t,n){const{book:s}=e,r=U(s,s.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Mt=(e,t)=>(t===12?I(e+1,1,1):I(e,t+1,1))-I(e,t,1);function Z(e,t,n,{min:s=N,max:r=1/0,marked:o=null}={}){const u=f("div"),i=Math.max(N,s),l=h=>Math.min(r,Math.max(i,h));let a=l(e);const y=e,x=O(),c=h=>{const k=R(a),m=I(k.year,k.month,1),D=m-R(m).weekday,b=d=>{const C=k.year*12+k.month-1+d,A=Math.floor(C/12),F=C%12+1;a=l(I(A,F,Math.min(k.day,Mt(A,F)))),c(h),n?.(a)},v=f("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${w(_[k.month-1])} ${k.year}`});for(const d of Lt)v.append(f("div",{class:"ct-dow",text:w(d)}));let g=null;for(let d=0;d<42;d++){const C=D+d;if(C<N){v.append(f("div"));continue}const A=C<i||C>r,F=R(C),Y=C===a,z=f("button",{class:`ct-cell${F.month!==k.month||A?" ct-out":""}${C===x?" ct-today":""}${(o?o(C):Math.floor(y)===C)?" ct-on":""}`,disabled:A,type:"button",text:String(F.day),tabIndex:Y?0:-1,role:"gridcell",ariaLabel:`${F.year}-${String(F.month).padStart(2,"0")}-${String(F.day).padStart(2,"0")}`,onclick:()=>t(C)});Y&&(g=z),v.append(z)}v.addEventListener("keydown",d=>{const C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[d.key];if(C!==void 0)d.preventDefault(),a=l(a+C),c(!0),n?.(a);else if(d.key==="PageUp"||d.key==="PageDown")d.preventDefault(),b((d.key==="PageUp"?-1:1)*(d.shiftKey?12:1));else if(d.key==="Home"||d.key==="End"){d.preventDefault();const A=R(a).weekday;a=l(a+(d.key==="Home"?-A:6-A)),c(!0),n?.(a)}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(a))});const p=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:w("Previous month"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:`${w(_[k.month-1])} ${k.year}`}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:w("Next month"),tabIndex:-1,onclick:()=>b(1)}));u.replaceChildren(p,v),u.focusCell=g,h&&g?.focus({preventScroll:!0})};return c(!1),u}function tt(e){const t=(i,l,a)=>f("input",{type:"number",min:0,max:l,value:String(a),ariaLabel:w(i),onfocus(){this.select()},onkeydown(y){if(y.key==="ArrowUp"||y.key==="ArrowDown"){y.preventDefault();const x=Number(this.value)+(y.key==="ArrowUp"?1:-1);this.value=String(x>l?0:x<0?l:x)}}}),n=t("Hours",23,e.h),s=t("Minutes",59,e.m),r=t("Seconds",59,e.s),o=f("div",{class:"ct-time"},n,f("span",{text:":"}),s,f("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:o,first:n,read:()=>(u(n,23)*3600+u(s,59)*60+u(r,59))/86400}}function It(e,t,n,s){const r=T(e,t,n)??O();S(e,t,n,"Date picker",o=>{const u=a=>M(e,t,n,String(a),{format:s.format??B.calendar}),i=Z(Math.floor(r),u,void 0,{min:s.minDate,max:s.maxDate}),l=f("button",{class:"ct-btn",type:"button",text:w("Today"),onclick:()=>u(O())});return o.append(i,f("div",{class:"ct-foot"},l)),i.focusCell})}function Rt(e,t,n,s){const r=T(e,t,n),o=r===null?null:R(r).ms,u=new Date,i=o===null?{h:u.getHours(),m:u.getMinutes(),s:0}:Q(o);S(e,t,n,"Time picker",l=>{const a=tt(i),y=()=>M(e,t,n,String(a.read()),{format:s.format??B.time});return a.wrap.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),y())}),l.append(a.wrap,$(e,y)),a.first})}function Tt(e,t,n,s){const r=T(e,t,n),o=R(r!==null&&r>=N?r:O()),u=s.startYear??1901,i=s.stopYear??9999;let l=Math.max(u,Math.min(i,o.year)),a=o.month-1;S(e,t,n,"Month picker",y=>{const x=k=>M(e,t,n,String(I(l,k+1,1)),{format:s.format??B.month}),c=f("div"),h=k=>{const m=f("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let D=null;_.forEach((g,p)=>{const d=f("button",{class:`ct-cell${l===o.year&&p===o.month-1&&r!==null?" ct-on":""}`,type:"button",text:w(g).slice(0,3),ariaLabel:`${w(g)} ${l}`,tabIndex:p===a?0:-1,onclick:()=>x(p)});p===a&&(D=d),m.append(d)});const b=g=>{l=Math.max(u,Math.min(i,l+g)),h(!0)};m.addEventListener("keydown",g=>{const p={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[g.key];if(p!==void 0){g.preventDefault();const d=a+p;d<0?(a=d+12,b(-1)):d>11?(a=d-12,b(1)):(a=d,h(!0))}else g.key==="PageUp"||g.key==="PageDown"?(g.preventDefault(),b(g.key==="PageUp"?-1:1)):(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),x(a))});const v=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:w("Previous year"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:String(l)}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:w("Next year"),tabIndex:-1,onclick:()=>b(1)}));c.replaceChildren(v,m),c.focusCell=D,k&&D?.focus({preventScroll:!0})};return h(!1),y.append(c),c.focusCell})}function $t(e,t,n,s){const r=T(e,t,n),o=new Date,u=r!==null&&r>=N?Math.floor(r):O(),i=r!==null?Q(R(r).ms):{h:o.getHours(),m:o.getMinutes(),s:0};S(e,t,n,"Date and time picker",l=>{let a=u;const y=tt(i),x=()=>M(e,t,n,String(a+y.read()),{format:s.format??B.datetime}),c=Z(a,h=>{a=h,y.first.focus()},h=>{a=h},{min:s.minDate,max:s.maxDate});return y.wrap.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),x())}),y.wrap.style.marginTop="8px",l.append(c,y.wrap,$(e,x)),c.focusCell})}const Nt=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Ot(e,t,n,s){const r=s.palette??Nt,{book:o}=e,u=U(o,o.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;S(e,t,n,"Color picker",l=>{let a=Math.max(0,r.indexOf(i));const y=m=>{if(s.target===void 0){M(e,t,n,m);return}H(e,t,n,{overFormula:!0})&&(o.applyStyle([{r0:t,c0:n,r1:t,c1:n}],s.target==="fill"?{fill:m}:{color:m}),e.grid.invalidate(),L())},x=f("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:w("Colors")}),c=r.map((m,D)=>{const b=f("button",{class:`ct-swatch${m===i?" ct-on":""}`,type:"button",ariaLabel:m,title:m,tabIndex:D===a?0:-1,onclick:()=>y(m)});return b.style.background=m,x.append(b),b});x.addEventListener("keydown",m=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[m.key];if(D!==void 0){m.preventDefault();const b=a+D;b>=0&&b<r.length&&(c[a].tabIndex=-1,a=b,c[a].tabIndex=0,c[a].focus())}else(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),y(r[a]))});const h=f("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:w("Hex color")}),k=()=>{const m=h.value.trim(),D=/^#?[0-9a-f]{6}$/i.test(m)?`#${m.replace("#","").toUpperCase()}`:null;D?y(D):h.select()};return h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),k())}),l.append(x,f("div",{class:"ct-foot"},h,f("button",{class:"ct-btn",type:"button",text:w("Apply"),onclick:k}))),c[a]})}function Pt(e,t,n,s){const r=s.min??0,o=s.max??100,u=s.step??1,i=T(e,t,n);S(e,t,n,"Slider",l=>{const a=f("input",{type:"range",min:r,max:o,step:u,value:String(i??r),ariaLabel:w("Value")}),y=f("span",{class:"ct-value",text:a.value});a.addEventListener("input",()=>{y.textContent=a.value});const x=()=>M(e,t,n,a.value);return a.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),x())}),l.append(a,$(e,x,y)),a})}const et=e=>Number(e.toPrecision(15));function Bt(e=0){let t=String(e),n=null,s=null,r=!0,o=!1;const u=()=>{const i=Number(t);if(s===null||n===null)return;let l;s==="+"?l=n+i:s==="-"?l=n-i:s==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(et(l)):(o=!0,t="Error"),n=null,s=null};return{get display(){return t},get failed(){return o},press(i){if(i==="C"){t="0",n=null,s=null,r=!0,o=!1;return}o||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(et(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),o||(n=Number(t),s=i,r=!0)))}}}function Ut(e,t,n){const s=T(e,t,n),r=Bt(s??0);S(e,t,n,"Calculator",o=>{const u=f("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:w("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?w("Error"):r.display},l=()=>{i("="),r.failed||M(e,t,n,r.display)},a=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],y=f("div",{class:"ct-grid ct-keys"});let x=null;for(const[c,h]of a){const k=f("button",{class:`ct-key${h==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(h)});h==="7"&&(x=k),y.append(k)}return o.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),o.append(u,y,$(e,l)),x})}function Ht(e,t){const{book:n}=e,s=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),o=r.lastIndexOf("!"),u=o>=0?r.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=mt(o>=0?r.slice(o+1):r);if(!l&&o<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const a=[],y=Math.min(l.r1,i.maxRow,l.r0+j-1),x=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=y;c++){const h=[];let k=null;for(let m=l.c0;m<=x;m++){const D=i.kind(c,m)&V,b=n.styles.list[i.style(c,m)]??n.styles.list[0];h.push(e.grid.displayText(D,i.value(c,m),b)),m-l.c0===s&&(k=U(n,i,c,m))}h.some(m=>m!=="")&&a.push({cells:h,value:k})}return{head:t.columns??null,rows:a}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[s]??null}))}}function Wt(e,t,n,s){const{head:r,rows:o}=Ht(e,s),{book:u}=e,i=U(u,u.sheet,t,n);S(e,t,n,"List",l=>{if(o.length===0)return l.append(f("div",{text:w("No items"),class:"ct-item"})),l;let a=Math.max(0,o.findIndex(v=>i!==null&&String(v.value)===String(i)));const y=f("table",{class:"ct-table"});r&&y.append(f("thead",{},f("tr",{},...r.map((v,g)=>{const p=f("th",{text:v});return s.widths?.[g]>0&&(p.style.minWidth=`${s.widths[g]}px`),p}))));const x=f("tbody",{role:"listbox",ariaLabel:w("List"),tabIndex:0}),c=v=>M(e,t,n,bt(o[v].value)),h=o.map((v,g)=>{const p=f("tr",{role:"option",ariaSelected:String(g===a),onclick:()=>c(g)},...v.cells.map(d=>f("td",{text:d})));return x.append(p),p}),k=v=>{let g=Math.max(0,Math.min(o.length-1,v));const p=g<a?-1:1;for(;h[g].hidden&&g+p>=0&&g+p<o.length;)g+=p;h[g].hidden||(h[a].setAttribute("aria-selected","false"),a=g,h[a].setAttribute("aria-selected","true"),h[a].scrollIntoView({block:"nearest"}))};let m="",D=0;x.addEventListener("keydown",v=>{const p={ArrowUp:a-1,ArrowDown:a+1,PageUp:a-8,PageDown:a+8,Home:0,End:o.length-1}[v.key];if(p!==void 0)v.preventDefault(),k(p);else if(v.key==="Enter"||v.key===" ")v.preventDefault(),c(a);else if(v.key.length===1&&!v.metaKey&&!v.ctrlKey){const d=performance.now();m=d-D>800?v.key:m+v.key,D=d;const C=o.findIndex(A=>A.cells[0].toLowerCase().startsWith(m.toLowerCase()));C>=0&&k(C)}}),y.append(x);let b=null;return s.filter&&(b=f("input",{type:"text",placeholder:w("Filter"),ariaLabel:w("Filter the list")}),b.style.width="100%",b.style.boxSizing="border-box",b.style.marginBottom="4px",b.addEventListener("input",()=>{const v=b.value.trim().toLowerCase();o.forEach((p,d)=>{h[d].hidden=v!==""&&!p.cells.some(C=>String(C).toLowerCase().includes(v))});const g=h.findIndex(p=>!p.hidden);g>=0&&h[a].hidden&&k(g)}),b.addEventListener("keydown",v=>{v.key==="ArrowDown"?(v.preventDefault(),x.focus()):v.key==="Enter"&&(v.preventDefault(),h[a].hidden||c(a))}),l.append(b)),l.append(f("div",{class:"ct-list"},y)),requestAnimationFrame(()=>h[a]?.scrollIntoView({block:"nearest"})),b??x})}function se(e,t,n,{items:s,selected:r=[],multi:o=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:a=!1,float:y}){S(e,t,n,i,x=>{y!==void 0&&At(y);const c=new Set(r);let h=Math.max(0,s.findIndex(p=>c.has(p.value)));const k=()=>{const p=s.filter(d=>c.has(d.value)).map(d=>d.value);u(p)!==!1&&L()},m=f("div",{class:"ct-list",role:"listbox",ariaLabel:w(i),ariaMultiselectable:String(o),tabIndex:0});l>0&&(m.style.maxHeight=`${l*24}px`);const D=[],b=s.map((p,d)=>{const C=f("span",{class:"ct-mark",text:c.has(p.value)?"✓":""});D.push(C);const A=f("div",{class:`ct-item${d===h?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(p.value)),onclick:()=>{v(d),g(),o||k()}},C,f("span",{text:p.text}));return m.append(A),A});function v(p){const d=Math.max(0,Math.min(s.length-1,p));b[h]?.classList.remove("ct-cursor"),h=d,b[h]?.classList.add("ct-cursor"),b[h]?.scrollIntoView({block:"nearest"})}function g(){const p=s[h];p&&(o||c.clear(),c.has(p.value)?c.delete(p.value):c.add(p.value),s.forEach((d,C)=>{D[C].textContent=c.has(d.value)?"✓":"",b[C].setAttribute("aria-selected",String(c.has(d.value)))}))}return m.addEventListener("keydown",p=>{const d={ArrowUp:h-1,ArrowDown:h+1,Home:0,End:s.length-1}[p.key];d!==void 0?(p.preventDefault(),v(d)):p.key===" "?(p.preventDefault(),g(),o||k()):p.key==="Enter"?(p.preventDefault(),o||(c.clear(),g()),k()):a&&!o&&(p.key==="ArrowLeft"||p.key==="ArrowRight")&&(p.preventDefault(),c.clear(),g(),k(),e.controller.moveTo(t,Math.max(0,n+(p.key==="ArrowLeft"?-1:1))))}),x.append(m),o&&x.append($(e,k)),s.length===0&&m.append(f("div",{class:"ct-item",text:w("No items")})),m})}const Kt={calendar:It,time:Rt,month:Tt,datetime:$t,color:Ot,slider:Pt,calculator:Ut,list:Wt};function nt(e,t,n,s){K.get(s.type)?.open?.(e,t,n,s)!==!0&&Kt[s.type]?.(e,t,n,s)}function ae(e,t,n,s){return e.loading?!1:(H(e,t,n,{overFormula:!0})&&nt(e,t,n,s),!0)}function le(e,t,n){const{sheet:s}=e.book,r=X(s,t,n);if(!r||e.loading)return!1;if(!H(e,t,n,{overFormula:!0}))return!0;const o=s.mergeAt(t,n);return nt(e,o?o.r0:t,o?o.c0:n,r),!0}export{W as DROPDOWN_TYPES,vt as MAX_APPLY_CELLS,_ as MONTHS,Zt as applyToRanges,Z as buildCalendar,H as canWriteCell,ee as cellDropdownArrow,P as cellKey,T as cellSerial,Ct as clipRange,L as closeDropdown,M as commit,X as dropdownAt,$ as footer,ne as isDropdownOpen,Ht as listData,bt as literalInput,f as make,Bt as makeCalculator,te as makeDropdown,le as openCellDropdown,ae as openDropdownConfig,se as openListPopup,S as openPopup,oe as popupViewChanged,U as readCellValue,Qt as registerDropdownKind,At as setPopupFloat,re as setPopupKeepOpen,G as swapMap,tt as timeInputs,O as todaySerial,wt as writeCell};
|
|
43
|
+
`;function Nt(){if(document.getElementById(rt))return;const e=document.createElement("style");e.id=rt,e.textContent=Ot,document.head.append(e)}const p=(e,t={},...n)=>{const o=document.createElement(e);for(const[r,s]of Object.entries(t))r==="class"?o.className=s:r==="text"?o.textContent=s:r.startsWith("aria")||r==="role"?o.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,s):o[r]=s;return o.append(...n.filter(r=>r!=null)),o};let F=null;const xe=()=>F!==null;function ve(e,t){F!==null&&(F.keepOpen=e,F.onClose=t)}function ot(e){F!==null&&(F.mode=e?"float":"confine")}function be(){F!==null&&F.mode!=="float"&&R(!1)}function R(e=!0){if(F===null)return;const{el:t,app:n,onDocPointer:o,onClose:r}=F;F=null,r?.(),document.removeEventListener("pointerdown",o,!0),t.remove(),e&&n.controller.focusGrid()}function T(e,t,n,o,r){R(!1),Nt(),e.grid.ensureVisible(t,n);const s=p("div",{class:"ct-popup",role:"dialog",ariaLabel:k(o),tabIndex:-1}),u=l=>{!s.contains(l.target)&&!F?.keepOpen?.(l)&&R(!1)};F={el:s,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),s.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),R();else if(l.key==="Tab"){const a=[...s.querySelectorAll('button, input, [tabindex="0"]')].filter(x=>!x.disabled&&x.tabIndex>=0&&x.offsetParent!==null);if(a.length===0)return;const y=a.indexOf(document.activeElement);l.preventDefault(),a[(y+(l.shiftKey?-1:1)+a.length)%a.length].focus()}}),mt().append(s);const i=r(s);return Ut(e,t,n,s),(i??s).focus({preventScroll:!0}),s}function Pt(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,s=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=s,l=Math.max(60,i?r:s);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const y=n.querySelector(".ct-list");y&&(y.style.maxHeight=`${Math.max(30,l-18)}px`)}const a=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-a}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function Ut(e,t,n,o){const r=e.grid.host.getBoundingClientRect(),s=e.grid.domRect(e.grid.cellRect(t,n));if(F?.mode==="confine"){Pt(r,s,o);return}const u=o.getBoundingClientRect(),i=2,l=r.top+s.y+s.h+i,a=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+s.y-u.height-i);o.style.top=`${a}px`,o.style.left=`${Math.max(8,Math.min(r.left+s.x,window.innerWidth-u.width-8))}px`}function $(e,t,n,o,r){const s=It(e,t,n,o,{...r,overFormula:!0});return s&&R(),s}const H=(e,t,n=null)=>p("div",{class:"ct-foot"},n,p("button",{class:"ct-btn",type:"button",text:k("Cancel"),onclick:()=>R()}),p("button",{class:"ct-btn ct-primary",type:"button",text:k("OK"),onclick:t})),X=["January","February","March","April","May","June","July","August","September","October","November","December"],Bt=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],W=61;function _(){const e=new Date;return N(e.getFullYear(),e.getMonth()+1,e.getDate())}const st=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function U(e,t,n){const{book:o}=e,r=Y(o,o.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Ht=(e,t)=>(t===12?N(e+1,1,1):N(e,t+1,1))-N(e,t,1);function at(e,t,n,{min:o=W,max:r=1/0,marked:s=null}={}){const u=p("div"),i=Math.max(W,o),l=g=>Math.min(r,Math.max(i,g));let a=l(e);const y=e,x=_(),c=g=>{const b=P(a),d=N(b.year,b.month,1),C=d-P(d).weekday,w=h=>{const D=b.year*12+b.month-1+h,L=Math.floor(D/12),M=D%12+1;a=l(N(L,M,Math.min(b.day,Ht(L,M)))),c(g),n?.(a)},f=p("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${k(X[b.month-1])} ${b.year}`});for(const h of Bt)f.append(p("div",{class:"ct-dow",text:k(h)}));let v=null;for(let h=0;h<42;h++){const D=C+h;if(D<W){f.append(p("div"));continue}const L=D<i||D>r,M=P(D),B=D===a,S=p("button",{class:`ct-cell${M.month!==b.month||L?" ct-out":""}${D===x?" ct-today":""}${(s?s(D):Math.floor(y)===D)?" ct-on":""}`,disabled:L,type:"button",text:String(M.day),tabIndex:B?0:-1,role:"gridcell",ariaLabel:`${M.year}-${String(M.month).padStart(2,"0")}-${String(M.day).padStart(2,"0")}`,onclick:()=>t(D)});B&&(v=S),f.append(S)}f.addEventListener("keydown",h=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[h.key];if(D!==void 0)h.preventDefault(),a=l(a+D),c(!0),n?.(a);else if(h.key==="PageUp"||h.key==="PageDown")h.preventDefault(),w((h.key==="PageUp"?-1:1)*(h.shiftKey?12:1));else if(h.key==="Home"||h.key==="End"){h.preventDefault();const L=P(a).weekday;a=l(a+(h.key==="Home"?-L:6-L)),c(!0),n?.(a)}else(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),t(a))});const m=p("div",{class:"ct-row"},p("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:k("Previous month"),tabIndex:-1,onclick:()=>w(-1)}),p("div",{class:"ct-head",text:`${k(X[b.month-1])} ${b.year}`}),p("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:k("Next month"),tabIndex:-1,onclick:()=>w(1)}));u.replaceChildren(m,f),u.focusCell=v,g&&v?.focus({preventScroll:!0})};return c(!1),u}function lt(e){const t=(i,l,a)=>p("input",{type:"number",min:0,max:l,value:String(a),ariaLabel:k(i),onfocus(){this.select()},onkeydown(y){if(y.key==="ArrowUp"||y.key==="ArrowDown"){y.preventDefault();const x=Number(this.value)+(y.key==="ArrowUp"?1:-1);this.value=String(x>l?0:x<0?l:x)}}}),n=t("Hours",23,e.h),o=t("Minutes",59,e.m),r=t("Seconds",59,e.s),s=p("div",{class:"ct-time"},n,p("span",{text:":"}),o,p("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:s,first:n,read:()=>(u(n,23)*3600+u(o,59)*60+u(r,59))/86400}}function Wt(e,t,n,o){const r=U(e,t,n)??_();T(e,t,n,"Date picker",s=>{const u=a=>$(e,t,n,String(a),{format:o.format??K.calendar}),i=at(Math.floor(r),u,void 0,{min:o.minDate,max:o.maxDate}),l=p("button",{class:"ct-btn",type:"button",text:k("Today"),onclick:()=>u(_())});return s.append(i,p("div",{class:"ct-foot"},l)),i.focusCell})}function _t(e,t,n,o){const r=U(e,t,n),s=r===null?null:P(r).ms,u=new Date,i=s===null?{h:u.getHours(),m:u.getMinutes(),s:0}:st(s);T(e,t,n,"Time picker",l=>{const a=lt(i),y=()=>$(e,t,n,String(a.read()),{format:o.format??K.time});return a.wrap.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),y())}),l.append(a.wrap,H(e,y)),a.first})}function zt(e,t,n,o){const r=U(e,t,n),s=P(r!==null&&r>=W?r:_()),u=o.startYear??1901,i=o.stopYear??9999;let l=Math.max(u,Math.min(i,s.year)),a=s.month-1;T(e,t,n,"Month picker",y=>{const x=b=>$(e,t,n,String(N(l,b+1,1)),{format:o.format??K.month}),c=p("div"),g=b=>{const d=p("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let C=null;X.forEach((v,m)=>{const h=p("button",{class:`ct-cell${l===s.year&&m===s.month-1&&r!==null?" ct-on":""}`,type:"button",text:k(v).slice(0,3),ariaLabel:`${k(v)} ${l}`,tabIndex:m===a?0:-1,onclick:()=>x(m)});m===a&&(C=h),d.append(h)});const w=v=>{l=Math.max(u,Math.min(i,l+v)),g(!0)};d.addEventListener("keydown",v=>{const m={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[v.key];if(m!==void 0){v.preventDefault();const h=a+m;h<0?(a=h+12,w(-1)):h>11?(a=h-12,w(1)):(a=h,g(!0))}else v.key==="PageUp"||v.key==="PageDown"?(v.preventDefault(),w(v.key==="PageUp"?-1:1)):(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),x(a))});const f=p("div",{class:"ct-row"},p("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:k("Previous year"),tabIndex:-1,onclick:()=>w(-1)}),p("div",{class:"ct-head",text:String(l)}),p("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:k("Next year"),tabIndex:-1,onclick:()=>w(1)}));c.replaceChildren(f,d),c.focusCell=C,b&&C?.focus({preventScroll:!0})};return g(!1),y.append(c),c.focusCell})}function Kt(e,t,n,o){const r=U(e,t,n),s=new Date,u=r!==null&&r>=W?Math.floor(r):_(),i=r!==null?st(P(r).ms):{h:s.getHours(),m:s.getMinutes(),s:0};T(e,t,n,"Date and time picker",l=>{let a=u;const y=lt(i),x=()=>$(e,t,n,String(a+y.read()),{format:o.format??K.datetime}),c=at(a,g=>{a=g,y.first.focus()},g=>{a=g},{min:o.minDate,max:o.maxDate});return y.wrap.addEventListener("keydown",g=>{g.key==="Enter"&&(g.preventDefault(),x())}),y.wrap.style.marginTop="8px",l.append(c,y.wrap,H(e,x)),c.focusCell})}const Yt=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Vt(e,t,n,o){const r=o.palette??Yt,{book:s}=e,u=Y(s,s.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;T(e,t,n,"Color picker",l=>{let a=Math.max(0,r.indexOf(i));const y=d=>{if(o.target===void 0){$(e,t,n,d);return}V(e,t,n,{overFormula:!0})&&(s.applyStyle([{r0:t,c0:n,r1:t,c1:n}],o.target==="fill"?{fill:d}:{color:d}),e.grid.invalidate(),R())},x=p("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:k("Colors")}),c=r.map((d,C)=>{const w=p("button",{class:`ct-swatch${d===i?" ct-on":""}`,type:"button",ariaLabel:d,title:d,tabIndex:C===a?0:-1,onclick:()=>y(d)});return w.style.background=d,x.append(w),w});x.addEventListener("keydown",d=>{const C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[d.key];if(C!==void 0){d.preventDefault();const w=a+C;w>=0&&w<r.length&&(c[a].tabIndex=-1,a=w,c[a].tabIndex=0,c[a].focus())}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),y(r[a]))});const g=p("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:k("Hex color")}),b=()=>{const d=g.value.trim(),C=/^#?[0-9a-f]{6}$/i.test(d)?`#${d.replace("#","").toUpperCase()}`:null;C?y(C):g.select()};return g.addEventListener("keydown",d=>{d.key==="Enter"&&(d.preventDefault(),b())}),l.append(x,p("div",{class:"ct-foot"},g,p("button",{class:"ct-btn",type:"button",text:k("Apply"),onclick:b}))),c[a]})}function qt(e,t,n,o){const r=o.min??0,s=o.max??100,u=o.step??1,i=U(e,t,n);T(e,t,n,"Slider",l=>{const a=p("input",{type:"range",min:r,max:s,step:u,value:String(i??r),ariaLabel:k("Value")}),y=p("span",{class:"ct-value",text:a.value});a.addEventListener("input",()=>{y.textContent=a.value});const x=()=>$(e,t,n,a.value);return a.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),x())}),l.append(a,H(e,x,y)),a})}const it=e=>Number(e.toPrecision(15));function Gt(e=0){let t=String(e),n=null,o=null,r=!0,s=!1;const u=()=>{const i=Number(t);if(o===null||n===null)return;let l;o==="+"?l=n+i:o==="-"?l=n-i:o==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(it(l)):(s=!0,t="Error"),n=null,o=null};return{get display(){return t},get failed(){return s},press(i){if(i==="C"){t="0",n=null,o=null,r=!0,s=!1;return}s||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(it(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),s||(n=Number(t),o=i,r=!0)))}}}function jt(e,t,n){const o=U(e,t,n),r=Gt(o??0);T(e,t,n,"Calculator",s=>{const u=p("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:k("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?k("Error"):r.display},l=()=>{i("="),r.failed||$(e,t,n,r.display)},a=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],y=p("div",{class:"ct-grid ct-keys"});let x=null;for(const[c,g]of a){const b=p("button",{class:`ct-key${g==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(g)});g==="7"&&(x=b),y.append(b)}return s.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),s.append(u,y,H(e,l)),x})}function Xt(e,t){const{book:n}=e,o=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),s=r.lastIndexOf("!"),u=s>=0?r.slice(0,s).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=St(s>=0?r.slice(s+1):r);if(!l&&s<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const a=[],y=Math.min(l.r1,i.maxRow,l.r0+tt-1),x=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=y;c++){const g=[];let b=null;for(let d=l.c0;d<=x;d++){const C=i.kind(c,d)&Z,w=n.styles.list[i.style(c,d)]??n.styles.list[0];g.push(e.grid.displayText(C,i.value(c,d),w)),d-l.c0===o&&(b=Y(n,i,c,d))}g.some(d=>d!=="")&&a.push({cells:g,value:b})}return{head:t.columns??null,rows:a}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[o]??null}))}}function Jt(e,t,n,o){const{head:r,rows:s}=Xt(e,o),{book:u}=e,i=Y(u,u.sheet,t,n);T(e,t,n,"List",l=>{if(s.length===0)return l.append(p("div",{text:k("No items"),class:"ct-item"})),l;let a=Math.max(0,s.findIndex(f=>i!==null&&String(f.value)===String(i)));const y=p("table",{class:"ct-table"});r&&y.append(p("thead",{},p("tr",{},...r.map((f,v)=>{const m=p("th",{text:f});return o.widths?.[v]>0&&(m.style.minWidth=`${o.widths[v]}px`),m}))));const x=p("tbody",{role:"listbox",ariaLabel:k("List"),tabIndex:0}),c=f=>$(e,t,n,Tt(s[f].value)),g=s.map((f,v)=>{const m=p("tr",{role:"option",ariaSelected:String(v===a),onclick:()=>c(v)},...f.cells.map(h=>p("td",{text:h})));return x.append(m),m}),b=f=>{let v=Math.max(0,Math.min(s.length-1,f));const m=v<a?-1:1;for(;g[v].hidden&&v+m>=0&&v+m<s.length;)v+=m;g[v].hidden||(g[a].setAttribute("aria-selected","false"),a=v,g[a].setAttribute("aria-selected","true"),g[a].scrollIntoView({block:"nearest"}))};let d="",C=0;x.addEventListener("keydown",f=>{const m={ArrowUp:a-1,ArrowDown:a+1,PageUp:a-8,PageDown:a+8,Home:0,End:s.length-1}[f.key];if(m!==void 0)f.preventDefault(),b(m);else if(f.key==="Enter"||f.key===" ")f.preventDefault(),c(a);else if(f.key.length===1&&!f.metaKey&&!f.ctrlKey){const h=performance.now();d=h-C>800?f.key:d+f.key,C=h;const D=s.findIndex(L=>L.cells[0].toLowerCase().startsWith(d.toLowerCase()));D>=0&&b(D)}}),y.append(x);let w=null;return o.filter&&(w=p("input",{type:"text",placeholder:k("Filter"),ariaLabel:k("Filter the list")}),w.style.width="100%",w.style.boxSizing="border-box",w.style.marginBottom="4px",w.addEventListener("input",()=>{const f=w.value.trim().toLowerCase();s.forEach((m,h)=>{g[h].hidden=f!==""&&!m.cells.some(D=>String(D).toLowerCase().includes(f))});const v=g.findIndex(m=>!m.hidden);v>=0&&g[a].hidden&&b(v)}),w.addEventListener("keydown",f=>{f.key==="ArrowDown"?(f.preventDefault(),x.focus()):f.key==="Enter"&&(f.preventDefault(),g[a].hidden||c(a))}),l.append(w)),l.append(p("div",{class:"ct-list"},y)),requestAnimationFrame(()=>g[a]?.scrollIntoView({block:"nearest"})),w??x})}function we(e,t,n,{items:o,selected:r=[],multi:s=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:a=!1,float:y}){if(!s&&o.length>Qt){te(e,t,n,{items:o,selected:r,onDone:u,label:i,maxItems:l,moveOnSide:a,float:y});return}T(e,t,n,i,x=>{y!==void 0&&ot(y);const c=new Set(r);let g=Math.max(0,o.findIndex(m=>c.has(m.value)));const b=()=>{const m=o.filter(h=>c.has(h.value)).map(h=>h.value);u(m)!==!1&&R()},d=p("div",{class:"ct-list",role:"listbox",ariaLabel:k(i),ariaMultiselectable:String(s),tabIndex:0});l>0&&(d.style.maxHeight=`${l*24}px`);const C=[],w=o.map((m,h)=>{const D=p("span",{class:"ct-mark",text:c.has(m.value)?"✓":""});C.push(D);const L=p("div",{class:`ct-item${h===g?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(m.value)),onclick:()=>{f(h),v(),s||b()}},D,p("span",{text:m.text}));return d.append(L),L});function f(m){const h=Math.max(0,Math.min(o.length-1,m));w[g]?.classList.remove("ct-cursor"),g=h,w[g]?.classList.add("ct-cursor"),w[g]?.scrollIntoView({block:"nearest"})}function v(){const m=o[g];m&&(s||c.clear(),c.has(m.value)?c.delete(m.value):c.add(m.value),o.forEach((h,D)=>{C[D].textContent=c.has(h.value)?"✓":"",w[D].setAttribute("aria-selected",String(c.has(h.value)))}))}return d.addEventListener("keydown",m=>{const h={ArrowUp:g-1,ArrowDown:g+1,Home:0,End:o.length-1}[m.key];h!==void 0?(m.preventDefault(),f(h)):m.key===" "?(m.preventDefault(),v(),s||b()):m.key==="Enter"?(m.preventDefault(),s||(c.clear(),v()),b()):a&&!s&&(m.key==="ArrowLeft"||m.key==="ArrowRight")&&(m.preventDefault(),c.clear(),v(),b(),e.controller.moveTo(t,Math.max(0,n+(m.key==="ArrowLeft"?-1:1))))}),x.append(d),s&&x.append(H(e,b)),o.length===0&&d.append(p("div",{class:"ct-item",text:k("No items")})),d})}const Qt=300,O=24,ct=new WeakMap;function Zt(e){let t=ct.get(e);return t===void 0&&(t=e.map(n=>String(n.text).toLowerCase()),ct.set(e,t)),t}function te(e,t,n,{items:o,selected:r,onDone:s,label:u,maxItems:i,moveOnSide:l,float:a}){T(e,t,n,u,y=>{a!==void 0&&ot(a);const x=Zt(o),c=r.length?String(r[0]).toLowerCase():null,g=Int32Array.from(o.keys());let b=g,d=Math.max(0,c===null?0:o.findIndex(S=>String(S.value).toLowerCase()===c));const C=p("input",{type:"search",placeholder:k("Search"),ariaLabel:k("Search the list")});C.style.width="100%",C.style.boxSizing="border-box",C.style.marginBottom="4px";const w=p("div",{class:"ct-count"}),f=p("div",{class:"ct-list",role:"listbox",ariaLabel:k(u),tabIndex:0}),v=i>0?i:10;f.style.height=`${v*O}px`,f.style.maxHeight="none",f.style.position="relative";const m=p("div");f.append(m);let h=[];const D=S=>{const A=o[b[S]];A&&s([A.value])!==!1&&R()},L=()=>{m.style.height=`${b.length*O}px`;for(const E of h)E.remove();h=[];const S=Math.max(0,Math.floor(f.scrollTop/O)-2),A=Math.min(b.length,S+v+4);for(let E=S;E<A;E++){const J=o[b[E]],Q=c!==null&&String(J.value).toLowerCase()===c,I=p("div",{class:`ct-item${E===d?" ct-cursor":""}`,role:"option",ariaSelected:String(Q),onclick:()=>D(E)},p("span",{class:"ct-mark",text:Q?"✓":""}),p("span",{text:J.text}));I.style.position="absolute",I.style.top=`${E*O}px`,I.style.left="0",I.style.right="0",I.style.height=`${O}px`,I.style.boxSizing="border-box",f.append(I),h.push(I)}w.textContent=b.length===o.length?k("{n} items",{n:o.length.toLocaleString()}):k("{n} of {total}",{n:b.length.toLocaleString(),total:o.length.toLocaleString()})},M=S=>{d=Math.max(0,Math.min(b.length-1,S));const A=d*O;A<f.scrollTop?f.scrollTop=A:A+O>f.scrollTop+f.clientHeight&&(f.scrollTop=A+O-f.clientHeight),L()};f.addEventListener("scroll",L),C.addEventListener("input",()=>{const S=C.value.trim().toLowerCase();if(S==="")b=g;else{const A=[];for(let E=0;E<x.length;E++)x[E].includes(S)&&A.push(E);b=Int32Array.from(A)}d=0,f.scrollTop=0,L()});const B=S=>{const A=v-1,E={ArrowUp:d-1,ArrowDown:d+1,PageUp:d-A,PageDown:d+A}[S.key];E!==void 0?(S.preventDefault(),M(E)):S.key==="Enter"?(S.preventDefault(),D(d)):l&&S.target===f&&(S.key==="ArrowLeft"||S.key==="ArrowRight")&&(S.preventDefault(),D(d),e.controller.moveTo(t,Math.max(0,n+(S.key==="ArrowLeft"?-1:1))))};return C.addEventListener("keydown",B),f.addEventListener("keydown",B),y.append(C,f,w),L(),requestAnimationFrame(()=>M(d)),C})}const ee={calendar:Wt,time:_t,month:zt,datetime:Kt,color:Vt,slider:qt,calculator:jt,list:Jt};function ut(e,t,n,o){j.get(o.type)?.open?.(e,t,n,o)!==!0&&ee[o.type]?.(e,t,n,o)}function ke(e,t,n,o){return e.loading?!1:(V(e,t,n,{overFormula:!0})&&ut(e,t,n,o),!0)}function Ce(e,t,n){const{sheet:o}=e.book,r=nt(o,t,n);if(!r||e.loading)return!1;if(!V(e,t,n,{overFormula:!0}))return!0;const s=o.mergeAt(t,n);return ut(e,s?s.r0:t,s?s.c0:n,r),!0}export{G as DROPDOWN_TYPES,Mt as MAX_APPLY_CELLS,X as MONTHS,me as applyToRanges,at as buildCalendar,V as canWriteCell,ge as cellDropdownArrow,z as cellKey,U as cellSerial,$t as clipRange,R as closeDropdown,$ as commit,nt as dropdownAt,H as footer,xe as isDropdownOpen,Xt as listData,Tt as literalInput,p as make,Gt as makeCalculator,ye as makeDropdown,Ce as openCellDropdown,ke as openDropdownConfig,we as openListPopup,T as openPopup,be as popupViewChanged,Y as readCellValue,he as registerDropdownKind,ot as setPopupFloat,ve as setPopupKeepOpen,q as swapMap,lt as timeInputs,_ as todaySerial,It as writeCell};
|
package/celltypes/file-cell.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{overlayRoot as
|
|
2
|
-
<cells xmlns="${
|
|
1
|
+
import{hasCellTypes as ee,typeAtPosition as B,visitStored as te}from"../core/cell-type-rules.js";import{overlayRoot as ne}from"../api/overlay.js";import{base64ToBytes as se}from"../core/base64.js";import{xmlAttr as oe}from"../io/xml-escape.js";import{STR as ie}from"../core/sheet.js";import{setSparse as z}from"../core/sparse.js";import{parseInput as le}from"../core/input.js";import{CELLS_NS as re,cellTypePart as ae}from"./persist.js";import{registerSection as fe}from"../cells/sections.js";import{canWriteCell as $,closeDropdown as P,make as F,openListPopup as ce,openPopup as ue,readCellValue as x}from"./dropdowns.js";import{cachedImage as R,CellType as de,controlRect as pe,defineCellType as me,drawImageFit as _,frame as he,inkOf as D,inRect as b,labelOf as ge,leftText as O,makeCellType as W,safeImage as we,safeInt as ye,safeText as ve,setFont as j,textWidth as U}from"./base.js";import{drawGlyph as S}from"./glyphs.js";import{t as p}from"../i18n/index.js";const T=10*1024*1024,q=256*1024*1024,N=/^[a-z0-9]{1,40}$/,Y=/^[\w.+-]+\/[\w.+-]+$/,Fe=/^[A-Za-z0-9+/]*={0,2}$/,I=/^image\/(png|jpeg|gif|webp|bmp|svg\+xml|x-icon|vnd\.microsoft\.icon)$/,xe=[["#C43E1C",["ppt","pptx","pps","ppsx","key","odp"]],["#107C41",["xls","xlsx","xlsm","xlsb","csv","tsv","ods","numbers"]],["#185ABD",["doc","docx","rtf","odt","pages"]],["#D13438",["pdf"]],["#7A5C00",["zip","rar","7z","tar","gz","bz2","xz"]],["#8764B8",["mp3","wav","flac","aac","ogg","m4a"]],["#B4009E",["mp4","mov","avi","mkv","webm","wmv"]],["#008272",["png","jpg","jpeg","gif","bmp","svg","ico","webp","tif","tiff","heic"]],["#3A3A3A",["js","mjs","ts","json","xml","html","css","py","java","c","cpp","sh","sql","md"]],["#606060",["txt","log"]]],be=new Map(xe.flatMap(([t,e])=>e.map(s=>[s,t]))),M=new Map;function Ne(t,e){const s=String(t).replace(/^\./,"").toLowerCase(),n=we(e);n?M.set(s,n):M.delete(s)}const Se=t=>{const e=t.lastIndexOf(".");return e>0?t.slice(e+1).toLowerCase():""};function Te(t,e,s,n,o,i){const l=Se(e),r=M.get(l);if(r){const h=R(r);h&&_(t,h,s,n,o,o);return}const c=be.get(l);if(c===void 0){S(t,"file",s,n,o,i);return}const f=o*.8,a=s+(o-f)/2,u=o*.26;t.save(),t.fillStyle="#ffffff",t.strokeStyle=c,t.lineWidth=Math.max(1,o/14),t.beginPath(),t.moveTo(a,n),t.lineTo(a+f-u,n),t.lineTo(a+f,n+u),t.lineTo(a+f,n+o),t.lineTo(a,n+o),t.closePath(),t.fill(),t.stroke(),t.fillStyle=c;const m=o*.5;if(t.fillRect(a,n+o-m,f,m),o>=13){const h=l.slice(0,4).toUpperCase();t.font=`600 ${Math.max(5,Math.min(m*.86,f*1.5/h.length))}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(h,a+f/2,n+o-m/2)}t.restore()}const y=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(t<10240?1:0)} KB`:`${(t/1024/1024).toFixed(1)} MB`,V=t=>String(t).split(/[/\\]/).pop().replace(/[\u0000-\u001f\u007f]/g,"").slice(0,200)||"file",k=t=>Math.floor(t.length*3/4)-(t.endsWith("==")?2:t.endsWith("=")?1:0);function X(t){return t.cellFiles||(t.cellFiles=new Map),t.cellFiles}function Ie(t){let e;do e=Math.random().toString(36).slice(2,14);while(t.has(e));return e}function Me(t,e,s,n){const o=X(t),i=Ie(o);return o.set(i,{id:i,name:V(e),type:Y.test(s)?s:"application/octet-stream",size:k(n),b64:n,url:null}),i}function C(t){return t.url===null&&(t.url=URL.createObjectURL(new Blob([se(t.b64)],{type:t.type}))),t.url}function ke(t){const e=t.cellFiles,s=new Set;for(const n of t.sheets){for(const{ranges:o,spec:i}of n.cellTypeRules??[]){const l=i.options.file;i.type!=="file"||!e.has(l)||s.has(l)||o.some(r=>te(n,r,(c,f)=>B(n,c,f)===i&&v(e,i.options,x(t,n,c,f))))&&s.add(l)}if(n.cellTypes)for(const[o,i]of n.cellTypes){if(i.type!=="file"||i.options.file===void 0||s.has(i.options.file))continue;const l=Math.floor(o/16384);v(e,i.options,x(t,n,l,o-l*16384))&&s.add(i.options.file)}}return s}function Ye(t){if(!t.cellFiles||t.cellFiles.size===0)return[];const e=[];let s=0;for(const n of ke(t)){const o=t.cellFiles.get(n),i=oe(JSON.stringify({id:o.id,name:o.name,type:o.type}).slice(0,-1)),l=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<cells xmlns="${re}" version="1"><section name="cellFile" data="${i},"b64":"${o.b64}"}"/></cells>`;e.push(ae(s++,l,"cellFile8c"))}return e}fe("cellFile",{book:{save:()=>{},load(t,e){const{id:s,name:n,type:o,b64:i}=e??{};typeof s!="string"||!N.test(s)||typeof i!="string"||!Fe.test(i)||k(i)>T||X(t).set(s,{id:s,name:V(n),type:typeof o=="string"&&Y.test(o)?o:"application/octet-stream",size:k(i),b64:i,url:null})}}});function v(t,e,s){if(!t||e.file===void 0)return null;const n=t.get(e.file);return n!==void 0&&ge(s)===n.name?n:null}function Ce(t,e){if(!e)return!0;const s=t.name.toLowerCase(),n=(t.type||"").toLowerCase();return e.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean).some(o=>o.startsWith(".")?s.endsWith(o):o.endsWith("/*")?n.startsWith(o.slice(0,-1)):n===o)}const Ee=t=>new Promise((e,s)=>{const n=new FileReader;n.onload=()=>e(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>s(n.error),n.readAsDataURL(t)});async function G(t,e,s,n,o){const{book:i,shell:l}=t,{sheet:r}=i;if(!$(t,e,s))return!1;const c=n.options.maxSize??T;if(o.size>c)return l.setStatus(p("{name} is {size}. This cell takes files up to {limit}.",{name:o.name,size:y(o.size),limit:y(c)})),!1;if(!Ce(o,n.options.accept))return l.setStatus(p("This cell doesn't take {name}. It accepts {accept}.",{name:o.name,accept:n.options.accept})),!1;let f=o.size;for(const w of i.cellFiles?.values()??[])f+=w.size;if(f>q)return l.setStatus(p("A workbook can hold {size} of files, and this one would go over.",{size:y(q)})),!1;let a;try{a=await Ee(o)}catch{return l.setStatus(p("Couldn't read {name}.",{name:o.name})),!1}if(i.sheet!==r)return l.setStatus("The sheet changed while the file was loading, so it was not added."),!1;const u=Me(i,o.name,o.type,a),m=i.cellFiles.get(u).name,h=le(m).kind===ie&&m[0]!=="="&&m[0]!=="'"?m:`'${m}`;return i.transact("entry",w=>(i.setInput(w,e,s,h),z(r,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],W("file",{...n.options,file:u})))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function H(t,e,s,n){if(!$(t,e,s))return!1;const{book:o}=t,{sheet:i}=o,{file:l,...r}=n.options;return o.transact("entry",c=>(o.setInput(c,e,s,""),z(i,"cellTypes",[{r0:e,c0:s,r1:e,c1:s}],W("file",r)))),t.grid.invalidate(),t.controller.syncFormulaBar(),!0}function E(t){const e=document.createElement("a");e.href=C(t),e.download=t.name,ne().append(e),e.click(),e.remove()}function J(t,e,s,n){ue(t,e,s,p("Preview of {name}",{name:n.name}),o=>{const i=F("img",{alt:n.name,src:C(n)});i.style.cssText="display:block;max-width:min(480px,80vw);max-height:60vh";const l=F("button",{class:"ct-btn",type:"button",text:p("Close"),onclick:()=>P()});return o.append(i,F("div",{class:"ct-foot"},F("button",{class:"ct-btn",type:"button",text:p("Download"),onclick:()=>E(n)}),l)),l})}function K(t,e,s,n){const o=document.createElement("input");o.type="file",n.options.accept&&(o.accept=n.options.accept),o.addEventListener("change",()=>{o.files[0]&&G(t,e,s,n,o.files[0])}),o.click()}class Ae extends de{static typeName="file";static sanitize(e){return{accept:ve(e.accept,300),maxSize:ye(e.maxSize,1,T),preview:e.preview===!1?!1:void 0,download:e.download===!1?!1:void 0,file:typeof e.file=="string"&&N.test(e.file)?e.file:void 0}}get blocksEditing(){return!0}_parts(e,s){const n=Math.min(16*s,e.h),o=e.y+(e.h-n)/2,i={x:e.x+e.w-n,y:o,w:n,h:n},l=this.options.download===!1?null:{x:i.x-n,y:o,w:n,h:n};return{clear:i,down:l,thumb:{x:e.x,y:e.y,w:Math.min(e.h,e.w/3),h:e.h}}}paint(e,s,n,o,i,l){const r=v(l?.book?.cellFiles,this.options,n),c=l?.printing===!0,f=Math.round(2*i);if(j(e,o,i),r===null){if(c)return;const d=Math.min(Math.round(14*i),s.h-2),g=s.y+(s.h-d)/2,Z=s.w-d-f*3,Q=p("Choose or drop a file"),L="#6e6e6e";S(e,"upload",s.x+f,g,d,L),Z>0&&O(e,Q,s.x+f*2+d,s.y,s.h,L);return}const a=this._parts(s,i);let u=s.x+f;if(this.options.preview!==!1&&I.test(r.type)&&typeof URL<"u"&&!c){const d=R(C(r));d&&_(e,d,s.x+1,s.y+1,a.thumb.w-2,s.h-2),u=s.x+a.thumb.w+f}else{const d=Math.min(Math.round(14*i),s.h-2);Te(e,r.name,u,s.y+(s.h-d)/2,d,D(o)),j(e,o,i),u+=d+f}const h=c?s.x+s.w:a.down?a.down.x:a.clear.x;e.save(),e.beginPath(),e.rect(u,s.y,Math.max(0,h-u),s.h),e.clip();const w=`${r.name} (${y(r.size)})`;if(O(e,w,u,s.y,s.h,D(o)),e.restore(),c)return;const A=(d,g)=>S(e,d,g.x+g.w*.1,g.y+g.h*.1,g.w*.8,"#3c3c3c");a.down&&A("download",a.down),A("clear",a.clear)}hitTest(e,s,n,o=1){if(!b(e,s,n))return null;if(this.options.file===void 0)return{part:"pick"};const i=this._parts(e,o);return b(i.clear,s,n)?{part:"clear"}:i.down&&b(i.down,s,n)?{part:"download"}:{part:"file"}}activate(e,s,n,o,i){const{book:l}=e,r=v(l.cellFiles,this.options,x(l,l.sheet,s,n));if(r===null)return K(e,s,n,this),!0;if(o==null){const f=[{text:p("Download"),value:"download"},{text:p("Replace…"),value:"pick"},{text:p("Clear"),value:"clear"}];return I.test(r.type)&&f.unshift({text:p("Preview"),value:"preview"}),ce(e,s,n,{items:f,label:"File",onDone:([a])=>(P(),a==="download"?E(r):a==="pick"?K(e,s,n,this):a==="clear"?H(e,s,n,this):a==="preview"&&J(e,s,n,r),!1)}),!0}const c=this.hitTest(pe(e,s,n),o,i,e.grid.zoom);return c?.part==="clear"?H(e,s,n,this):c?.part==="download"?(E(r),!0):I.test(r.type)&&this.options.preview!==!1?(J(e,s,n,r),!0):!1}fitWidth(e,s){const n=v(he.book?.cellFiles,this.options,e);return n===null?U(s,p("Choose or drop a file"))+22:U(s,`${n.name} (${y(n.size)})`)+58}}me(Ae);function Ve(t){const{host:e}=t.grid,s=n=>{const{sheet:o}=t.book;if(!ee(o)||!n.dataTransfer?.types?.includes("Files"))return null;const{x:i,y:l}=t.controller._point(n),r=t.controller._hit(i,l);if(r.type!=="cell")return null;const c=o.mergeAt(r.row,r.col),f=c?c.r0:r.row,a=c?c.c0:r.col,u=B(o,f,a);return u!==void 0&&u.type==="file"?{row:f,col:a,t:u}:null};e.addEventListener("dragover",n=>{s(n)!==null&&(n.preventDefault(),n.stopImmediatePropagation(),n.dataTransfer.dropEffect="copy")},!0),e.addEventListener("drop",n=>{const o=s(n);if(o===null)return;n.preventDefault(),n.stopImmediatePropagation();const i=n.dataTransfer.files[0];i&&G(t,o.row,o.col,o.t,i)},!0)}export{Ae as FileCell,T as MAX_FILE_BYTES,Ve as attachFileDrop,Ye as cellFilesPackage,Te as drawFileIcon,y as formatSize,Ne as setFileIcon,G as takeFile};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BOOL as
|
|
2
|
-
`)){let i="";for(const l of t.split(/\s+/)){const r=i===""?l:`${i} ${l}`;i!==""&&n.measureText(r).width>o?(s.push(i),i=l):i=r}s.push(i)}return s}function
|
|
1
|
+
import{typeAtPosition as Z}from"../core/cell-type-rules.js";import{BOOL as U,DIRTY as Y,EMPTY as L,ERR as q,FORMULA as _,KIND_MASK as E,NUM as z,Sheet as G,STR as Q}from"../core/sheet.js";import{cellRef as v,MAX_COLS as ee,MAX_ROWS as ne,parseRangeRef as te,sheetReferencePattern as se}from"../core/address.js";import{sparklineIndex as oe}from"../core/sparklines.js";import{paintSparkline as le}from"../sparklines/excel-paint.js";import{toFileFormula as ie}from"../calc/parser.js";import{cssFont as re}from"../core/styles.js";import{readCellValue as W}from"./dropdowns.js";import{CellType as ce,defineCellType as fe,formatted as ue,frame as F,labelOf as ae,oneOf as de,paintPlain as pe,parseJsonCached as he,safeText as me}from"./base.js";import{pathValue as ge}from"./data-object.js";const j=60,ye=2e4,be=500,ke=/^R(?:\[(-?\d{1,7})\])?C(?:\[(-?\d{1,5})\])?$/,Ae=/\{([^{}]+)\}/g,Ce={hair:1,thin:1,dotted:1,dashed:1,dashDot:1,dashDotDot:1,medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,double:1,thick:3};function Me(n,e){const o=e.lastIndexOf("!"),s=o>=0?e.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null,t=s===null?n.sheet:n.sheets.find(l=>l.name.toLowerCase()===s.toLowerCase()),i=te(o>=0?e.slice(o+1):e);return t&&i?{sheet:t,range:i}:null}function H(n,e){const o=se(e);return n.split(/("(?:[^"]|"")*")/).map((s,t)=>t%2===1?s:s.replace(o,"")).join("")}function V(n,e,o,s){const t=e.kind(o,s);(t&E)!==L&&n.setCell(o,s,t&E,e.value(o,s))}function X(n,e,o,s,t,i){for(const l of o.refs??[]){if(l.sheet)continue;const r=l.rAbs0?l.r0:s+(l.r0??0),y=l.rAbs1?l.r1:s+(l.r1??0),c=l.cAbs0?l.c0:t+(l.c0??0),a=l.cAbs1?l.c1:t+(l.c1??0),p=Math.min(Number.isFinite(y)?y:ne-1,e.maxRow),S=Math.min(Number.isFinite(a)?a:ee-1,e.maxCol);for(let C=Math.max(0,r);C<=p;C++)for(let h=Math.max(0,c);h<=S;h++){if(i.left--<=0)return;(n.kind(C,h)&E)===L&&V(n,e,C,h)}}}function Re(n,e,o,s){const{engine:t}=n;if(!t)return null;const i=new G(e.name),l={left:ye};for(const c of o)V(i,e,c.r,c.c);const r=[];for(const c of o){if(!c.isFormula)continue;const a=H(n.editText(e,c.r,c.c).slice(1),e.name),p=ie(a);i.setFormula(c.r,c.c,{f:p,typed:!0}),r.push(c),X(i,e,t.template(p,c.r,c.c),c.r,c.c,l)}const y=[];for(const c of s){const a=H(c.spark.source,e.name);y.push({...c,source:a}),X(i,e,t.template(a,c.r,c.c),c.r,c.c,l)}return{sheet:i,formulas:r,lines:y}}function De(n,e,o,s,t){t==null||t===""?n.setCell(o,s,L,0):typeof t=="number"?n.setCell(o,s,z,t):typeof t=="boolean"?n.setCell(o,s,U,t?1:0):n.setCell(o,s,Q,e.strings.add(String(t)))}function Se(n,e){const{engine:o}=e,{sheet:s,formulas:t}=n.copy;for(const i of t)s.setCell(i.r,i.c,_|Y|z,0);for(const i of t)try{o.read(s,i.r,i.c)}catch{s.setCell(i.r,i.c,z,0)}}function Oe(n,e,o){const s=Me(n,e);if(!s)return null;const{sheet:t,range:i}=s,l=i.c0,r=i.r0,y=Math.min(i.c1,l+j-1),c=Math.min(i.r1,r+j-1),a=[0],p=[0];for(let u=l;u<=y;u++)a.push(a[a.length-1]+t.cols.sizeOf(u));for(let u=r;u<=c;u++)p.push(p[p.length-1]+t.rows.sizeOf(u));const S=a[a.length-1],C=p[p.length-1];if(S<=0||C<=0)return null;const h=[],T=t.sparklines&&t.sparklines.length>0?oe(t):null,O=[];for(let u=r;u<=c;u++)for(let d=l;d<=y;d++){const f=t.mergeAt(u,d);if(f&&(f.r0!==u||f.c0!==d)&&!(u===r&&f.r0<r)&&!(d===l&&f.c0<l))continue;const m=f?Math.min(f.c1,y):d,g=f?Math.min(f.r1,c):u,b=n.styles.list[t.style(u,d)]??n.styles.list[0],A=t.kind(u,d)&E,M=o?.[v(u,d)],R=Z(t,u,d),k=T?.get(u*16384+d);if(A===L&&!b.fill&&!b.borders&&M===void 0&&R===void 0&&k===void 0)continue;const w=W(n,t,u,d);let D=null;M!==void 0?D=`{${M}}`:typeof w=="string"&&A!==q&&(t.kind(u,d)&_)===0&&w.includes("{")&&(D=w),D!==null&&!D.includes("{")&&(D=null);const K=D===null&&(t.kind(u,d)&_)!==0;k!==void 0&&O.push({r:u,c:d,spark:k}),h.push({r:u,c:d,isFormula:K,spark:k!==void 0,x0:a[d-l],y0:p[u-r],x1:a[m-l+1],y1:p[g-r+1],st:b,value:w,tokens:D,type:R!==void 0&&R.type!=="range"?R:null})}const $=h.some(u=>u.isFormula)||O.length>0?Re(n,t,h,O):null;return{W:S,H:C,cells:h,sheet:t,copy:$}}const P=new Map;function B(n,e){const o=e.source;let s=P.get(o);return(s===void 0||s.id!==F.id||s.book!==n)&&(P.size>=64&&P.clear(),s={id:F.id,book:n,tpl:Oe(n,o,e.bindings)},P.set(o,s)),s.tpl}function x(n,e,o,s,t,i){const l=ke.exec(n);if(l){const r=t+Number(l[1]??0),y=i+Number(l[2]??0);return r>=0&&y>=0?W(o,s,r,y):null}return e===null?void 0:ge(e,n)}function Te(n){return n==null?"":typeof n=="object"?JSON.stringify(n):String(ae(n))}function J(n,e,o,s,t,i){if(n.tokens===null)return n.value;const l=/^\{([^{}]+)\}$/.exec(n.tokens);if(l){const r=x(l[1].trim(),e,o,s,t,i);return r===void 0?"":typeof r=="object"&&r!==null?JSON.stringify(r):r}return n.tokens.replace(Ae,(r,y)=>Te(x(y.trim(),e,o,s,t,i)))}function I(n,e,o,s,t,i,l){if(!e)return;const r=Math.max(1,Math.round(l));n.strokeStyle=e.color??"#000000",n.lineWidth=(Ce[e.style]??1)*r,n.setLineDash(e.style==="dotted"||e.style==="hair"?[r,r]:/dash/i.test(e.style)?[3*r,2*r]:[]),n.beginPath(),n.moveTo(o,s),n.lineTo(t,i),n.stroke(),n.setLineDash([])}function we(n,e,o){const s=[];for(const t of e.split(`
|
|
2
|
+
`)){let i="";for(const l of t.split(/\s+/)){const r=i===""?l:`${i} ${l}`;i!==""&&n.measureText(r).width>o?(s.push(i),i=l):i=r}s.push(i)}return s}function Fe(n,e,o,s,t,i,l,r,y){const c=s.fontSize*y;if(c<2.5||e==="")return;const a=2*y;n.font=re(s,c),n.fillStyle=s.color??F.theme.cellInk;const p=s.hAlign??(typeof o=="number"?"right":typeof o=="boolean"?"center":"left");n.textAlign=p==="right"?"right":p==="center"||p==="centerContinuous"?"center":"left";const S=n.textAlign==="right"?t+l-a:n.textAlign==="center"?t+l/2:t+a,C=s.wrap?we(n,e,l-a*2):[e],h=c*1.22,T=s.vAlign??"bottom",O=C.length*h;let N=T==="top"?i+c*1.05:T==="center"?i+(r-O)/2+c*.95:i+r-O+c*.95-2*y;for(const $ of C)n.fillText($,S,N),N+=h;n.textAlign="left"}const Ne=/^(?:(?:'(?:[^']|'')+'|[^'!]+)!)?\$?[A-Za-z]{1,3}\$?\d{1,7}(?::\$?[A-Za-z]{1,3}\$?\d{1,7})?$/;function $e(n){if(n===null||typeof n!="object"||Array.isArray(n))return;const e={};let o=0;for(const[s,t]of Object.entries(n)){if(o++>=be)break;/^[A-Z]{1,3}\d{1,7}$/.test(s)&&typeof t=="string"&&t.length<=200&&!/[{}]/.test(t)&&(e[s]=t)}return o>0?Object.freeze(e):void 0}class Ie extends ce{static typeName="range";static sanitize(e){return{source:typeof e.source=="string"&&e.source.length<=300&&Ne.test(e.source)?e.source:"",fit:de(e.fit,["stretch"]),bindings:$e(e.bindings),title:me(e.title,200)}}paint(e,o,s,t,i,l){const r=l?.book??F.book,y=l?.sheet??F.sheet,c=r&&this.options.source?B(r,this.options):null;if(c===null){pe(e,o,s,t,i);return}let a=o.w/c.W,p=o.h/c.H;this.options.fit!=="stretch"&&(a=Math.min(a,p),p=a);const S=o.x+(o.w-c.W*a)/2,C=o.y+(o.h-c.H*p)/2,h=Math.min(a,p),T=typeof s=="string"?he(s):void 0,O=T!==null&&typeof T=="object"?T:null,{row:N,col:$}=F,u=(f,m,g)=>Math.round(m+f*g),{copy:d}=c;if(d!==null){for(const f of c.cells)f.tokens!==null&&De(d.sheet,r,f.r,f.c,J(f,O,r,y,N,$));d.formulas.length>0&&Se(c,r)}for(const f of c.cells){const m=u(f.x0,S,a),g=u(f.y0,C,p),b=u(f.x1,S,a)-m,A=u(f.y1,C,p)-g;if(b<=0||A<=0)continue;const{st:M}=f;M.fill&&(e.fillStyle=M.fill,e.fillRect(m,g,b,A));const R=f.isFormula&&d!==null?W(r,d.sheet,f.r,f.c):J(f,O,r,y,N,$);if(e.save(),e.beginPath(),e.rect(m,g,b,A),e.clip(),f.spark&&d!==null&&r.engine){const w=d.lines.find(D=>D.r===f.r&&D.c===f.c);w&&le(e,r.engine,d.sheet,{group:w.spark.group,source:w.source},f.r,f.c,m,g,b,A,h)}f.type?f.type.paint(e,{x:m,y:g,w:b,h:A},R,M,h,l):R!==null&&R!==""&&Fe(e,String(ue(R,M)),R,M,m,g,b,A,h),e.restore();const k=M.borders;k&&(I(e,k.t,m,g,m+b,g,h),I(e,k.b,m,g+A,m+b,g+A,h),I(e,k.l,m,g,m,g+A,h),I(e,k.r,m+b,g,m+b,g+A,h),k.d&&k.down&&I(e,k.d,m,g,m+b,g+A,h),k.d&&k.up&&I(e,k.d,m,g+A,m+b,g,h))}}fitWidth(){const e=F.book&&this.options.source?B(F.book,this.options):null;return e===null?0:e.W}}fe(Ie);export{Ie as RangeTemplateCell,B as template};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MAX_COLS as a,MAX_ROWS as x}from"./address.js";import{CHUNK_BITS as v,CHUNK_MASK as X}from"./sheet.js";import{adjustRange as j}from"../calc/adjust.js";import{subtractRect as w}from"./validation-ranges.js";const D=c=>!!(c.cellTypes||c.cellTypeRules),I=(c,e,r)=>e>=c.r0&&e<=c.r1&&r>=c.c0&&r<=c.c1,K=new WeakMap;function B(c,e,r,s){let t=r+c,n=r+e;for(;t<=n;)t%2&&s(t++),n%2===0&&s(n--),t>>=1,n>>=1}function E(c){const e=new Map;return c.forEach((r,s)=>{for(const t of r.ranges)B(t.c0,t.c1,a,n=>{let l=e.get(n);l||(l=new Map,e.set(n,l)),B(t.r0,t.r1,x,o=>{l.has(o)||l.set(o,s)})})}),e}function F(c,e,r){const s=c.cellTypes?.get(e*a+r),t=c.cellTypeRules;if(s!==void 0||!t)return s;if(t.length<32&&t.every(o=>o.ranges.length<32)){for(const o of t)for(const f of o.ranges)if(I(f,e,r))return o.spec;return}let n=K.get(t);n||(n=E(t),K.set(t,n));let l=t.length;for(let o=a+r;o>0;o>>=1){const f=n.get(o);if(f)for(let p=x+e;p>0;p>>=1){const i=f.get(p);i<l&&(l=i)}}return t[l]?.spec}function C(c,e){const r=Math.max(c.r0,e.r0),s=Math.max(c.c0,e.c0),t=Math.min(c.r1,e.r1),n=Math.min(c.c1,e.c1);return r<=t&&s<=n?{r0:r,c0:s,r1:t,c1:n}:null}function G(c,e,r){for(let s=e.c0;s<=Math.min(e.c1,c.maxCol);s++){const t=c.columns[s];if(t)for(let n=e.r0>>>v;n<=Math.min(e.r1>>>v,t.length-1);n++){const l=t[n];if(!l)continue;const o=n<<v;for(let f=Math.max(e.r0-o,0);f<=Math.min(e.r1-o,X);f++)if((l.kinds[f]||l.styles?.[f])&&r(o+f,s))return!0}}return!1}function M(c,e){if(!c)return null;const r=[];for(const s of c){const t=s.ranges.flatMap(e);if(t.length){const n=t.length===s.ranges.length&&t.every((l,o)=>l===s.ranges[o]);r.push(n?s:{ranges:t,spec:s.spec})}}return r.length===c.length&&r.every((s,t)=>s===c[t])?c:r.length?r:null}function S(c,e){return M(c,r=>{let s=[r];for(const t of e)s=s.flatMap(n=>w(n,t));return s})}const T=c=>c.r0===c.r1&&c.c0===c.c1;function J(c,e,r){const s=r===null?e:e.filter(n=>!T(n));if(s.length){const n=S(c.cellTypeRules,s);c.cellTypeRules=r===null?n:[...n??[],{ranges:s,spec:r}]}let t=c.cellTypes;if(r===null&&t){const n=t,l=o=>{n.has(o)&&(t===n&&(t=new Map(n)),t.delete(o))};if(e.every(T))for(const o of e)l(o.r0*a+o.c0);else for(const o of n.keys())e.some(f=>I(f,Math.floor(o/a),o%a))&&l(o)}else if(r!==null&&e.some(T)){t=new Map(t);for(const n of e)T(n)&&t.set(n.r0*a+n.c0,r)}c.cellTypes=t?.size?t:null,c.cellTypesChanged=!0}function Q(c,e){const r=e.axis==="row",s=e.span&&{r0:r?0:e.span[0],r1:r?x-1:e.span[1],c0:r?e.span[0]:0,c1:r?e.span[1]:a-1};return M(c,t=>{const n=s?C(t,s):t;if(!n)return[t];const l=j(n,e),o=s?w(t,s):[];return l&&o.push(l),o})}function V(c,e,r,s){const[t,n]=s==="row"?["r0","r1"]:["c0","c1"];return M(c,l=>{const o=C(l,e);if(!o||o[t]===e[t]&&o[n]===e[n])return[l];const f=w(l,e),p=r.slice(o[t]-e[t],o[n]-e[t]+1).sort((h,u)=>h-u);let i;for(const h of p){const u=h+e[t];i&&u===i[n]+1?i[n]=u:(i={...o,[t]:u,[n]:u},f.push(i))}return f})}function L(c,e,r,s,t,n){if(e-c+1===r)return[[t,n]];const l=[],o=Math.ceil((t-s-e)/r);for(let f=s+o*r;f+c<=n;f+=r)l.push([Math.max(t,f+c),Math.min(n,f+e)]);return l}function Y(c,e,r,s,{cut:t=!1,transpose:n=!1,fill:l=!1}={}){if(!c.cellTypeRules&&!e.cellTypeRules)return;const o=c.cellTypeRules;t&&(c.cellTypeRules=S(o,[r]));const f=S(e.cellTypeRules,[s]),[p,i,h,u]=n?["c0","c1","r0","r1"]:["r0","r1","c0","c1"],k=M(o,H=>{const g=C(H,r);if(!g)return[];const A=(y,m,R,d,W)=>L(g[y]-r[y],g[m]-r[y],r[m]-r[y]+1,R,d,W),O=A(p,i,l?r.r0:s.r0,s.r0,s.r1),U=A(h,u,l?r.c0:s.c0,s.c0,s.c1),_=[];for(const[y,m]of O)for(const[R,d]of U)_.push({r0:y,c0:R,r1:m,c1:d});return _});e.cellTypeRules=k?[...f??[],...k]:f}export{Y as copyTypeRules,D as hasCellTypes,C as intersection,Q as shiftedTypeRules,V as sortedTypeRules,F as typeAtPosition,G as visitStored,J as writeCellTypes};
|
package/core/changes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FORMULA as x,KIND_MASK as
|
|
1
|
+
import{FORMULA as x,KIND_MASK as y,STR as M}from"./sheet.js";const i=16384;class g{constructor(){this.cells=new Map,this.rows={inserted:[],deleted:[]},this.cols={inserted:[],deleted:[]}}}const v=(s,t)=>(s?.f??s?.sf??null)===(t?.f??t?.sf??null);function R(s,t,n){const{cells:e}=t.changes;for(let c=0;c<n.count;c++){const a=n.rows[c],l=n.cols[c],r=a*i+l;let o=e.get(r);o===void 0&&(o={kind:n.kinds[c],value:n.values[c],formula:n.kinds[c]&x?n.formulas?.get(c):void 0},e.set(r,o));const u=t.kind(a,l)&-97;u===o.kind&&t.value(a,l)===o.value&&(!(u&x)||v(t.formula(a,l),o.formula))&&e.delete(r)}}function T(s){return s.changes===null&&(s.changes=new g),s.changes}function A(s){s.changes=null}function D(s,t){const n=[];for(const e of s){const c=e.at+e.count;if(t.n>0)e.at>=t.at?n.push({at:e.at+t.n,count:e.count}):c>t.at?n.push({at:e.at,count:e.count+t.n}):n.push(e);else{const a=t.at-t.n;if(c<=t.at)n.push(e);else if(e.at>=a)n.push({at:e.at+t.n,count:e.count});else{const l=Math.max(0,t.at-e.at)+Math.max(0,c-a);l>0&&n.push({at:Math.min(e.at,t.at),count:l})}}}return n}function I(s,t,n){const e=s.changes;if(e===null)return!1;for(const c of(t==="row"?e.rows:e.cols).inserted)if(n>=c.at&&n<c.at+c.count)return!0;return!1}function K(s,t){const n=s.changes;if(n===null)return null;const e={cells:n.cells,rows:n.rows,cols:n.cols},c=u=>()=>{const w={cells:n.cells,rows:n.rows,cols:n.cols};return Object.assign(n,u),c(w)},a=t.axis==="row"?"rows":"cols",l=n[a],r=D(l.inserted,t);n[a]=t.n>0?{inserted:[...r,{at:t.at,count:t.n}],deleted:l.deleted}:{inserted:r,deleted:[...l.deleted,{at:t.at,count:-t.n}]};const o=new Map;for(const[u,w]of n.cells){let d=Math.floor(u/i),h=u-d*i;const f=t.axis==="row"?d:h;let k=f;if(t.n>0)f>=t.at&&(k=f+t.n);else if(f>=t.at-t.n)k=f+t.n;else if(f>=t.at)continue;t.axis==="row"?d=k:h=k,o.set(d*i+h,w)}return n.cells=o,c(e)}const m=(s,t,n)=>!s||t>=s.r0&&t<=s.r1&&n>=s.c0&&n<=s.c1;function S(s,t,n=null){const e=t.changes;if(e===null)return[];const c=(l,r)=>{const o=l&y;return o===0?null:o===M?s.strings.get(r):o===3?r!==0:r},a=[];for(const[l,r]of e.cells){const o=Math.floor(l/i),u=l-o*i;m(n,o,u)&&a.push({row:o,col:u,oldValue:c(r.kind,r.value),newValue:c(t.kind(o,u),t.value(o,u))})}return a.sort((l,r)=>l.row-r.row||l.col-r.col)}function E(s,t){const n=s.changes;if(!(n===null||t.size===0))for(const e of[...n.cells.keys()])t.has(Math.floor(e/i))&&n.cells.delete(e)}const F=(s,t,n)=>s.changes!==null&&s.changes.cells.has(t*i+n);function O(s,t=null){const n=s.changes;if(n!==null){if(t===null){s.changes=new g;return}for(const e of[...n.cells.keys()]){const c=Math.floor(e/i);m(t,c,e-c*i)&&n.cells.delete(e)}}}export{g as ChangeTracker,O as clearDirty,E as clearDirtyRows,S as getDirtyCells,F as isDirtyCell,I as isInsertedAxis,R as noteChanges,K as noteStructure,T as startTracking,A as stopTracking};
|
package/core/cond-format.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseRangeRef as
|
|
1
|
+
import{parseRangeRef as O}from"./address.js";import{BOOL as x,ERR as T,ERRORS as q,KIND_MASK as _,NUM as E,STR as C}from"./sheet.js";import{numberToText as F}from"../calc/values.js";import{formatGeneral as N,getFormatter as B}from"./numfmt.js";function A(r){return r.split(/\s+/).map(O).filter(Boolean)}import{CondFormats as H,cfEffectAt as J,evaluatorOf as P,iconAt as Q}from"../cells/cf-engine.js";function L(r,n,t){return r._ranges===void 0&&(r._ranges=A(r.sqref)),r._ranges.some(e=>n>=e.r0&&n<=e.r1&&t>=e.c0&&t<=e.c1)}function K(r,n,t){if(r.validations){for(const e of r.validations)if(L(e,n,t))return e}for(const e of r.hostRules??[])for(const{validation:i}of e.entries)if(i&&L(i,n,t))return i;return null}function h(r,n,t){r._ranges===void 0&&(r._ranges=r.sqref?A(r.sqref):[]);const e=r._ranges[0];return e?[e.r0,e.c0]:[n,t]}function S(r,n,t,e,i){const s=t.formula1.trim();if(s.startsWith('"'))return s.slice(1,-1).split(",").map(o=>o.trim());const l=r.engine;let a=l.template(s,...h(t,e,i)).fn(e,i,n);return a&&a.sheet&&(a=l.toArr(a)),a&&a.data?a.data.filter(o=>o!==null):[]}function W(r,n,t,e,i){return I(r,n,t,e,i).map(s=>s.text)}function I(r,n,t,e,i){const s=t.formula1.trim(),l=()=>S(r,n,t,e,i).map(p=>({text:String(p),value:p}));if(s.startsWith('"'))return l();const f=r.engine.template(s,...h(t,e,i)).fn(e,i,n);if(!f||!f.sheet)return l();const a=[],o=f.sheet;for(let p=f.r0;p<=Math.min(f.r1,o.maxRow);p++)for(let u=f.c0;u<=Math.min(f.c1,o.maxCol);u++){const m=o.kind(p,u)&_;if(m===0)continue;const g=o.value(p,u),c=r.styles.get(o.style(p,u)).numFmt;m===E?a.push({text:c==="General"?N(g):B(c).number(g).replace(/\u0001.?\u0001/g," ").trim(),value:g}):m===C?a.push({text:r.strings.get(g),value:r.strings.get(g)}):m===x?a.push({text:g?"TRUE":"FALSE",value:g!==0}):a.push({text:q[g]??"#N/A",value:null})}return a}function D(r,n,t,e,i,s){if(t?.type!=="list"||typeof s!="string"||/^[='"]/.test(s))return null;const l=s.trim().toLowerCase(),f=S(r,n,t,e,i).find(a=>typeof a=="string"&&a.trim().toLowerCase()===l);return f!==void 0&&f.trim()!==s.trim()?f.trim():null}function V(r,n,t,e,i,s,l,f){if(t.type==="none"||t.type===void 0)return!0;if(s===0)return t.allowBlank;const a=r.engine,o=c=>{if(!c)return null;const d=a.template(c,...h(t,e,i)),y=a.legacy;a.legacy=!0;try{const R=d.fn(e,i,n);return R&&R.sheet?a.refAuto(R,e,i):R}finally{a.legacy=y}},p=s===E?F(l):s===x?l?"TRUE":"FALSE":String(f);if(t.type==="list"){if(s===T)return!1;const c=S(r,n,t,e,i);if(s===E&&c.some(y=>(typeof y=="number"?y:Number(y))===l))return!0;const d=p.trim().toLowerCase();return c.some(y=>String(y).trim().toLowerCase()===d)}if(t.type==="custom"){const c=[n.kind(e,i),n.value(e,i),n.maxRow,n.maxCol],d=s===C?r.strings.add(String(f)):s===x?l?1:0:l;n.setCell(e,i,s,d);try{const y=o(t.formula1);return y===!0||typeof y=="number"&&y!==0}finally{n.setCell(e,i,c[0],c[1]),n.maxRow=c[2],n.maxCol=c[3]}}let u;if(t.type==="textLength"){if(s===T)return!1;u=p.length}else if(s===x)u=1/0;else if(s!==E||(u=l,t.type==="whole"&&!Number.isInteger(u)))return!1;const m=o(t.formula1),g=o(t.formula2);switch(t.operator){case"notBetween":return u<m||u>g;case"equal":return u===m;case"notEqual":return u!==m;case"greaterThan":return u>m;case"lessThan":return u<m;case"greaterThanOrEqual":return u>=m;case"lessThanOrEqual":return u<=m;default:return u>=m&&u<=g}}export{x as BOOL,H as CondFormats,C as STR,J as cfEffectAt,P as evaluatorOf,Q as iconAt,I as listEntries,W as listItems,D as listSpelling,S as listValues,A as rangesOf,V as validateEntry,K as validationAt};
|
package/core/culture.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setNumberLocale as F}from"./numfmt.js";import{setEntryCurrency as L}from"./input.js";import{regionInput as Z}from"./region-input.js";import{arraySeparatorsOf as b}from"../calcx/culture/separators.js";import{customCulture as v}from"../calcx/culture/custom.js";import{localeData as K,preparedEras as G}from"../calcx/culture/format-locale.js";import{formulaFromUser as k,formulaToUser as M}from"../calcx/lang/convert.js";import{
|
|
1
|
+
import{setNumberLocale as F}from"./numfmt.js";import{setEntryCurrency as L}from"./input.js";import{regionInput as Z}from"./region-input.js";import{arraySeparatorsOf as b}from"../calcx/culture/separators.js";import{customCulture as v}from"../calcx/culture/custom.js";import{localeData as K,preparedEras as G}from"../calcx/culture/format-locale.js";import{formulaFromUser as k,formulaToUser as M}from"../calcx/lang/convert.js";import{ansiEncoding as O}from"../io/encoding.js";import{setDbcsLanguage as W}from"../calc/functions/dbcs.js";const B={US:"USD",GB:"GBP",PL:"PLN",DE:"EUR",FR:"EUR",ES:"EUR",IT:"EUR",NL:"EUR",AT:"EUR",BE:"EUR",IE:"EUR",PT:"EUR",FI:"EUR",GR:"EUR",CZ:"CZK",SK:"EUR",HU:"HUF",RO:"RON",SE:"SEK",NO:"NOK",DK:"DKK",CH:"CHF",UA:"UAH",TR:"TRY",JP:"JPY",CN:"CNY",KR:"KRW",IN:"INR",BR:"BRL",MX:"MXN",CA:"CAD",AU:"AUD",NZ:"NZD",ZA:"ZAR",IL:"ILS",SA:"SAR",AE:"AED",EG:"EGP"},V=[["en-US","English (United States)"],["en-GB","English (United Kingdom)"],["pl-PL","Polish (Poland)"],["de-DE","German (Germany)"],["fr-FR","French (France)"],["es-ES","Spanish (Spain)"],["it-IT","Italian (Italy)"],["nl-NL","Dutch (Netherlands)"],["pt-BR","Portuguese (Brazil)"],["cs-CZ","Czech (Czechia)"],["sv-SE","Swedish (Sweden)"],["uk-UA","Ukrainian (Ukraine)"],["tr-TR","Turkish (Türkiye)"],["ja-JP","Japanese (Japan)"],["zh-CN","Chinese (China)"],["ko-KR","Korean (Korea)"],["ar-SA","Arabic (Saudi Arabia)"],["he-IL","Hebrew (Israel)"]];function u(e){const o=v(e);if(o){const t=u(o.parent);return{...t,monthsWithDay:o.fields.months??t.monthsWithDay,...o.fields,tag:e}}const s=new Intl.NumberFormat(e,{useGrouping:!0,numberingSystem:"latn"}).formatToParts(12345675e-1),m=s.find(t=>t.type==="decimal")?.value??".",C=s.find(t=>t.type==="group")?.value??"",y=[],d=[];for(let t=0;t<12;t++){const n=new Date(Date.UTC(2024,t,15));y.push(new Intl.DateTimeFormat(e,{month:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),d.push(new Intl.DateTimeFormat(e,{month:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const p=[],h=[];for(let t=0;t<7;t++){const n=new Date(Date.UTC(2024,0,7+t));p.push(new Intl.DateTimeFormat(e,{weekday:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),h.push(new Intl.DateTimeFormat(e,{weekday:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const i=new Intl.DateTimeFormat(e,{dateStyle:"short",timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))),S=i.filter(t=>t.type==="day"||t.type==="month"||t.type==="year").map(t=>t.type),g=i.find(t=>t.type==="literal")?.value.trim()||"/",R=i.find(t=>t.type==="month")?.value.length>1,D={day:t=>t.length>1||R?"dd":"d",month:t=>t.length>1?"mm":"m",year:()=>"yyyy"},E=i.filter(t=>D[t.type]).map(t=>D[t.type](t.value)).join(g),I=new Intl.Locale(e).maximize().region,P=B[I]??"USD",l=new Intl.NumberFormat(e,{style:"currency",currency:P,numberingSystem:"latn"}).formatToParts(1),w=l.find(t=>t.type==="currency")?.value??"$",N=l.findIndex(t=>t.type==="currency")<l.findIndex(t=>t.type==="integer"),f={weekday:()=>"dddd",month:t=>/\d/.test(t)?"m":"mmmm",day:t=>t.length>1?"dd":"d",year:()=>"yyyy"},U=t=>new Intl.DateTimeFormat(e,{dateStyle:t,timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))).map(n=>f[n.type]?f[n.type](n.value):n.type==="literal"?`"${n.value}"`:"").join(""),A=new Intl.DateTimeFormat(e,{hour:"numeric",hour12:!0,timeZone:"UTC",calendar:"gregory"}),T=t=>A.formatToParts(new Date(Date.UTC(2024,0,5,t))).find(n=>n.type==="dayPeriod")?.value??(t<12?"AM":"PM");return{tag:e,language:new Intl.Locale(e).language,collator:new Intl.Collator(e,{sensitivity:"accent"}),decimal:m,group:C,listSep:m===","?";":",",...b(e,m),longDate:U("full"),longDateWithoutWeekday:U("long"),longTime:"h:mm:ss AM/PM",amDesignator:T(9),pmDesignator:T(15),months:y,shortMonths:d,monthsWithDay:K(e).monthsWithDay,days:p,shortDays:h,order:S,dateSep:g,shortDate:E,currency:{symbol:w,symbolFirst:N}}}let r=null,c=null;const a=()=>(r??=u("en-US"),r);function x(e=a().currency.symbol){return/^\p{Sc}$/u.test(e)?e:`"${e.replace(/"/g,"")}"`}function ee(e,o=x(),s=!a().currency.symbolFirst){return o?s?`${e} ${o}`:o+e:e}function te(e){return r=u(e),c=null,W(r.tag),L(r.currency),F({decimal:r.decimal,group:r.group,months:r.months,monthsWithDay:r.monthsWithDay,shortMonths:r.shortMonths,days:r.days,shortDays:r.shortDays,shortDate:r.shortDate,longDate:r.longDate,longTime:r.longTime,amDesignator:r.amDesignator,pmDesignator:r.pmDesignator,tag:r.tag,eras:r.eras?G(r.eras):null,numerals:r.numerals??null}),r}function re(e){return M(e,a())}function H(e){return k(e,a())}const ne=(e=a())=>({decimal:e.decimal,group:e.group,listSep:e.listSep,order:e.order,dateSep:e.dateSep,currency:e.currency,ansi:O(e.tag)});function oe(e){return e===""||e[0]==="'"?e:e[0]==="="?e.length>1?H(e):e:(c??=Z(a()),c(e))}export{V as REGIONS,a as culture,u as cultureOf,ee as currencyAmountCode,x as currencySymbolCode,H as formulaToInvariant,re as formulaToLocal,ne as inputRegion,oe as inputToInvariant,te as setCulture};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{hasPassword as p}from"./protection.js";import{parseRangeRef as g}from"./address.js";const i=new WeakMap,s=new WeakMap,f=e=>{let t=i.get(e);return t||(t=(e.sqref??"").split(/[\s,]+/).map(g).filter(Boolean),i.set(e,t)),t},c=(e,t,o)=>f(e).some(n=>t>=n.r0&&t<=n.r1&&o>=n.c0&&o<=n.c1),l=e=>`${e.name}\0${e.hashValue??e.password??""}`;function r(e,t){return s.get(e)?.has(l(t))?!0:!p(t)&&!t.securityDescriptor}function x(e,t){s.has(e)||s.set(e,new Set),s.get(e).add(l(t))}const d=e=>s.delete(e);function m(e,t,o){const n=e.protectedRanges;if(!n?.length)return!1;for(const a of n)if(c(a,t,o)&&r(e,a))return!0;return!1}const k=e=>(e.protectedRanges??[]).filter(t=>r(e,t)).flatMap(f),w=(e,t,o)=>(e.protectedRanges??[]).filter(n=>p(n)&&c(n,t,o)&&!r(e,n)),B=e=>/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)&&e.length<=255;export{d as closeRanges,f as editRangeBoxes,m as inOpenRange,r as isOpenRange,w as lockedRangesAt,k as openBoxes,x as openRangeForSession,B as validRangeTitle};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=o=>(o.hostRules??[]).flatMap(t=>t.entries),e=o=>l(o).flatMap(t=>t.validation?[t.validation]:[]),m=o=>l(o).map(t=>t.block),R=o=>[...o.validations??[],...e(o)],g=o=>(o.cf?.length??0)>0||(o.hostRules?.length??0)>0;function h(o,t,n){const s=(o.hostRules??[]).filter(r=>r.owner!==t);n.length&&s.push({owner:t,origin:{},entries:n}),o.hostRules=s.length?s:null,o.cfEval?.invalidate()}const a=(o,t)=>({...o,entries:o.entries.flatMap(n=>t(n)??[])});function v(o,t){o.hostRules&&(o.hostRules=o.hostRules.map(n=>a(n,t)),o.cfEval?.invalidate())}function d(o,t){const n=s=>typeof s=="string"&&s!==""?o(s):s;return({validation:s,block:r})=>{const{_ranges:f,_base:p,...i}=r;return{validation:s&&{...s,formula1:n(s.formula1),formula2:n(s.formula2)},block:{...i,rules:r.rules.map(u=>t(u,n))}}}}function x(o,t,n=null){if(!o.hostRules)return;const s=new Map((t??[]).map(r=>[r.origin,r]));o.hostRules=o.hostRules.map(r=>s.get(r.origin)??(n?a(r,n):r))}export{R as allValidations,g as hasConditionalFormats,m as hostFormats,e as hostValidations,v as mapHostRules,x as restoreHostRules,d as rewriteHostEntry,h as setHostLayer};
|