@8sheets/data-grid 1.0.0 → 1.0.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/date.js +1 -1
- package/calc/functions/dbcs.js +1 -0
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/index.js +7 -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/functions/text.js +1 -1
- package/cells/axis-ops.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/format-tabs.js +3 -3
- package/cells/goto.js +1 -1
- package/cells/name-box.js +1 -1
- package/cells/options.js +1 -1
- package/cells/view-options.js +1 -1
- package/celltypes/dropdowns.js +1 -1
- package/charts/chartex.js +3 -3
- package/core/address.js +1 -1
- package/core/autofill.js +1 -0
- package/core/cond-format.js +1 -1
- package/core/default-names.js +1 -1
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/numfmt.js +1 -1
- package/core/sheet-group.js +1 -0
- package/core/tables.js +2 -2
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/extras/getdata/persist.js +2 -2
- package/extras/getdata/steps.js +1 -1
- package/i18n/en/cells.js +1 -1
- package/i18n/en/charts.js +1 -1
- package/i18n/en/common.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/pivot.js +1 -1
- package/i18n/en/ribbon.js +1 -1
- package/i18n/en/shell.js +2 -1
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/charts.js +1 -1
- package/i18n/pl/common.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/pivot.js +1 -1
- package/i18n/pl/ribbon.js +1 -1
- package/i18n/pl/shell.js +2 -1
- package/io/client.js +1 -1
- package/io/csv.js +8 -5
- package/io/export-blocks.js +1 -1
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -0
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-tail.js +1 -1
- package/io/xlsx-write.js +2 -2
- package/objects/chart-model.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/pivot/xml.js +2 -2
- package/print/page-setup.js +1 -1
- package/slicers/custom-styles.js +1 -1
- package/slicers/table-file.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/labels.js +1 -1
- package/table-view/version.js +1 -1
- package/ui/icons.js +1 -1
- package/ui/protection-ui.js +1 -1
package/calcx/functions/text.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{lift as u,raw as U,setCategory as
|
|
1
|
+
import{lift as u,raw as U,setCategory as p}from"../../calc/functions/registry.js";import{Arr as m,ERR as f,num as d,OMITTED as R,Ref as N,RefList as F,str as T,XlError as A}from"../../calc/values.js";import{evaluateXPath as $,parseXml as k}from"./xml.js";import{asyncCall as x}from"../async.js";import{mayReach as W}from"../../core/online.js";import{dbcsLanguage as D,toFullWidth as B}from"../../calc/functions/dbcs.js";const O=t=>t!==void 0&&t!==R;p("Text"),u("JIS",1,1,t=>D()?B(T(t)):T(t)),U("PHONETIC",1,1,(t,e)=>{if(!D())throw f.NA;const r=t.toArr(e[0]);let n="";for(const o of r.data)typeof o=="string"&&(n+=o);return n});const y=["ศูนย์","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า"],G=["","สิบ","ร้อย","พัน","หมื่น","แสน"];function I(t){if(/^0*$/.test(t))return y[0];let e="";const r=t.replace(/^0+/,""),n=[];for(let o=r.length;o>0;o-=6)n.unshift(r.slice(Math.max(0,o-6),o));return n.forEach((o,a)=>{const s=o.length;let h="";for(let i=0;i<s;i++){const c=o.charCodeAt(i)-48;if(c===0)continue;const l=s-1-i;l===1&&c===1?h+="สิบ":l===1&&c===2?h+="ยี่สิบ":l===0&&c===1&&(s>1||a>0)?h+=o.slice(0,-1).replace(/0/g,"")!==""||a>0?"เอ็ด":"หนึ่ง":h+=y[c]+G[l]}e+=h,a<n.length-1&&(e+="ล้าน")}),e}function P(t){if(t<1e15)return String(t);const e=t.toExponential(14),r=e.indexOf("e"),n=Number(e.slice(r+1));return(e[0]+e.slice(2,r)).slice(0,n+1).padEnd(n+1,"0")}function Y(t){const e=t<0,r=Math.round(Math.abs(t)*100),n=Math.floor(r/100),o=r-n*100;let a="";return n>0&&(a+=`${I(P(n))}บาท`),o===0?a+=n>0?"ถ้วน":`${y[0]}บาทถ้วน`:a+=`${I(String(o))}สตางค์`,e?`ลบ${a}`:a}u("BAHTTEXT",1,1,t=>Y(d(t)));const _=["มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม"],J=["วันอาทิตย์","วันจันทร์","วันอังคาร","วันพุธ","วันพฤหัสบดี","วันศุกร์","วันเสาร์"],C=t=>new Date(Date.UTC(1899,11,30)+Math.floor(t)*864e5);u("THAIDAYOFWEEK",1,1,t=>J[C(d(t)).getUTCDay()]),u("THAIMONTHOFYEAR",1,1,t=>{const e=Math.trunc(d(t));if(e<1||e>12)throw f.VALUE;return _[e-1]}),u("THAIYEAR",1,1,t=>C(d(t)).getUTCFullYear()+543),u("THAIDIGIT",1,1,t=>T(t).replace(/[0-9]/g,e=>String.fromCharCode(3664+Number(e)))),u("ISTHAIDIGIT",1,1,t=>/[๐-๙]/.test(T(t))),u("THAINUMSTRING",1,1,t=>{const e=d(t),[r,n]=Math.abs(e).toString().split(".");let o=I(r);return n&&(o+=`จุด${[...n].map(a=>y[Number(a)]).join("")}`),e<0?`ลบ${o}`:o}),u("THAINUMSOUND",1,1,t=>[...T(t)].map(e=>/[0-9]/.test(e)?y[Number(e)]:e).join("")),u("THAISTRINGLENGTH",1,1,t=>[...T(t).replace(/[ัิ-ฺ็-๎]/g,"")].length);const b=(t,e)=>{const r=t<0?-1:1,n=Math.abs(t)*4;return r*(e?Math.ceil(n-1e-9):Math.floor(n+1e-9))/4};p("Math & Trig"),u("ROUNDBAHTDOWN",1,1,t=>b(d(t),!1)),u("ROUNDBAHTUP",1,1,t=>b(d(t),!0)),p("Text");const V=["〇","一","二","三","四","五","六","七","八","九"],j=["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"];function H(t,e,r,n,o){const a=String(Math.round(Math.abs(t)));if(a==="0")return e[0];let s="";const h=a.length;let i=!1;for(let c=0;c<h;c++){const l=a.charCodeAt(c)-48,E=h-1-c;l===0?i=s!=="":(i&&o&&(s+=e[0]),i=!1,s+=e[l]+r[E%4]),E%4===0&&E>0&&s!==""&&(s+=n[E/4-1])}return t<0?`负${s}`:s}u("NUMBERSTRING",2,2,(t,e)=>{const r=d(t),n=Math.trunc(d(e));if(n===1)return H(r,["〇",...V.slice(1)],["","十","百","千"],["万","亿","兆"],!0);if(n===2)return H(r,j,["","拾","佰","仟"],["万","亿","兆"],!0);if(n===3)return[...String(Math.round(Math.abs(r)))].map(o=>V[Number(o)]).join("");throw f.VALUE}),u("DATESTRING",1,1,t=>{const e=typeof t=="string"?Date.parse(t):d(t),r=C(typeof t=="string"?e/864e5+25569:e),n=s=>String(s).padStart(2,"0"),o=r.getUTCFullYear(),a=o>=2019?["令和",o-2018]:o>=1989?["平成",o-1988]:o>=1926?["昭和",o-1925]:o>=1912?["大正",o-1911]:["明治",o-1867];return`${a[0]}${n(a[1])}年${n(r.getUTCMonth()+1)}月${n(r.getUTCDate())}日`});const K={EUR:[1,2],ATS:[13.7603,2],BEF:[40.3399,0],DEM:[1.95583,2],ESP:[166.386,0],FIM:[5.94573,2],FRF:[6.55957,2],GRD:[340.75,0],IEP:[.787564,2],ITL:[1936.27,0],LUF:[40.3399,0],NLG:[2.20371,2],PTE:[200.482,2],SIT:[239.64,2],CYP:[.585274,2],MTL:[.4293,2],SKK:[30.126,2],EEK:[15.6466,2],LVL:[.702804,2],LTL:[3.4528,2],HRK:[7.5345,2]},M=t=>{const e=K[T(t).toUpperCase()];if(e===void 0)throw f.VALUE;return e};u("EUROCONVERT",3,5,(t,e,r,n,o)=>{const a=d(t),[s]=M(e),[h,i]=M(r);let c=a/s;if(O(o)){const g=Math.trunc(d(o));if(g<3)throw f.VALUE;c=Number(c.toFixed(g))}const l=c*h;return(O(n)?d(n)!==0:!1)?l:Number(l.toFixed(i))}),u("EURO",1,1,t=>M(t)[0]),p("Web"),u("ENCODEURL",1,1,t=>{const e=T(t);if(e.length>2048)throw f.VALUE;return encodeURIComponent(e).replace(/[!'()*]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`)}),U("FILTERXML",2,2,(t,e,r,n)=>{const o=t.scalar(e[0],r,n),a=t.scalar(e[1],r,n);if(o instanceof A)return o;if(a instanceof A)return a;let s;try{s=k(T(o))}catch{return f.VALUE}let h;try{h=$(s,T(a))}catch{return f.VALUE}if(h.length===0)return f.VALUE;const i=h.map(c=>{const l=Number(c);return c.trim()!==""&&Number.isFinite(l)?l:c});return i.length===1?i[0]:m.column(i)},{array:!0});const w={fetch:null};function et(t=e=>fetch(e).then(r=>{if(!r.ok)throw new Error(String(r.status));return r.text()})){w.fetch=t}const rt=()=>{w.fetch=null};U("WEBSERVICE",1,1,(t,e,r,n,o)=>{const a=t.scalar(e[0],r,n);if(a instanceof A)return a;const s=T(a);return s.length>2048||!/^https?:\/\//i.test(s)?f.VALUE:w.fetch===null||!W(s)?f.BLOCKED:x(t,{name:"WEBSERVICE",key:s,row:r,col:n,sheet:o,run:()=>w.fetch(s),onError:()=>f.VALUE})},{volatile:!1}),p("Text"),u("STARTSWITH",2,2,(t,e)=>T(t).toLowerCase().startsWith(T(e).toLowerCase())),u("ENDSWITH",2,2,(t,e)=>T(t).toLowerCase().endsWith(T(e).toLowerCase())),p("Other"),u("UUID",0,0,()=>{const t=new Uint8Array(16);globalThis.crypto.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;const e=[...t].map(r=>r.toString(16).padStart(2,"0")).join("");return`${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`},{volatile:!0});const S=t=>t==null?null:typeof t=="number"||typeof t=="string"||typeof t=="boolean"?t:JSON.stringify(t);u("FILTERJSON",1,1,t=>{if(typeof t!="string")throw f.VALUE;let e;try{e=JSON.parse(t)}catch{throw f.VALUE}if(Array.isArray(e)){if(e.length===0)throw f.CALC;return m.column(e.map(S))}return S(e)});const L=t=>{if(t instanceof A)throw t;return t===R||t===void 0?null:t};U("OBJECT",2,254,(t,e,r,n)=>{if(e.length%2!==0)return f.VALUE;if(e.length===2&&e[0]instanceof N&&e[1]instanceof N&&!e[0].isCell){const i=t.toArr(e[0]).data,c=t.toArr(e[1]).data;if(i.length!==c.length)return f.VALUE;const l={};return i.forEach((E,g)=>{l[T(L(E))]=L(c[g])}),JSON.stringify(l)}const o=[],a=[];let s=null;for(let i=0;i<e.length;i+=2){const c=t.scalar(e[i],r,n);if(c instanceof A)return c;o.push(T(c));const l=e[i+1]instanceof N||e[i+1]instanceof F?t.refToValue(e[i+1]):e[i+1];if(l instanceof A)return l;if(l instanceof m&&l.data.length>1){if(s!==null&&s!==l.data.length)return f.VALUE;s=l.data.length}a.push(l)}const h=i=>{const c={};return o.forEach((l,E)=>{const g=a[E];c[l]=L(g instanceof m?g.data[g.data.length>1?i:0]:g)}),JSON.stringify(c)};return s===null?h(0):m.column(Array.from({length:s},(i,c)=>h(c)))},{array:!0}),u("PROPERTY",2,2,(t,e)=>{let r=t;if(typeof t=="string")try{r=JSON.parse(t)}catch{throw f.NA}if(r===null||typeof r!="object")throw f.NA;for(const n of T(e).split(".").flatMap(o=>o.split(/[[\]]/).filter(Boolean))){if(r===null||typeof r!="object"||!Object.hasOwn(r,n))throw f.NA;r=r[n]}return S(r)??""}),p("Date & Time");const q={y:"year",year:"year",q:"quarter",quarter:"quarter",m:"month",month:"month",d:"day",day:"day",w:"weekday",weekday:"weekday",h:"hour",hour:"hour",n:"minute",minute:"minute",s:"second",second:"second",yd:"dayofyear",dayofyear:"dayofyear",ww:"week",week:"week"};u("DATEPART",2,2,(t,e)=>{const r=d(t);if(r<0)throw f.NUM;const n=C(r),o=r-Math.floor(r),a=Math.round(o*86400),s=n.getUTCFullYear(),h=Math.floor((n-Date.UTC(s,0,1))/864e5)+1;switch(q[T(e).toLowerCase()]){case"year":return s;case"quarter":return Math.floor(n.getUTCMonth()/3)+1;case"month":return n.getUTCMonth()+1;case"day":return n.getUTCDate();case"weekday":return n.getUTCDay()+1;case"hour":return Math.floor(a/3600)%24;case"minute":return Math.floor(a/60)%60;case"second":return a%60;case"dayofyear":return h;case"week":return Math.floor((h+new Date(Date.UTC(s,0,1)).getUTCDay()-1)/7)+1;default:throw f.VALUE}});export{et as allowWebFunctions,Y as bahtText,rt as blockWebFunctions};
|
package/cells/axis-ops.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{openFormatCells as
|
|
1
|
+
import{selectedSheets as C}from"../core/sheet-group.js";import{openFormatCells as O,promptNumber as F}from"../ui/dialogs.js";import{guardOption as R}from"../ui/protection-ui.js";import{MAX_COLS as S,MAX_ROWS as z}from"../core/address.js";import{CHUNK_BITS as T}from"../core/sheet.js";import{wrapsByAlign as _}from"./text-layout.js";import{canResize as b}from"./axis-limits.js";import{openTrackSize as y}from"./cell-options-ui.js";import{openHeaderColors as v}from"./header-colors.js";const h=o=>o==="col"?"cols":"rows";function I(o){const e=o.grid.selection.ranges[0];e.c0===0&&e.c1===S-1?v(o,"row",e.r0,e.r1):v(o,"col",e.c0,e.c1)}function m(o,e,r){return()=>{const s=o[e];return o[e]=r,e==="cols"&&(o.colsChanged=!0),o.revision++,m(o,e,s)}}function g(o,e){const{book:r,grid:s}=o;e==="col"&&(r.sheet.colsChanged=!0),r.dirty=!0,o.objects?.geometryChanged?.(),s.invalidate()}function U(o,e){const{sheet:r,styles:s}=o.book,n=new Set,i=new Map,l=t=>{let c=i.get(t);if(c===void 0){const f=s.get(t);c=!!(f.wrap||_(f)),i.set(t,c)}return c};o:for(const t of e.slice(0,256)){const c=r.columns[t];if(c===void 0)continue;const f=r.colStyles?.get(t)??0;for(let d=0;d<c.length;d++){const u=c[d];if(u!==void 0)for(let a=0;a<u.kinds.length;a++){if(u.kinds[a]===0)continue;const w=u.styles===null||u.styles[a]===0?f:u.styles[a];if(!(w===0||!l(w))&&(n.add((d<<T)+a),n.size>=B))break o}}}for(const t of n)o.commands._growRow(t);return n.size>0}const B=2e3;function H(o,e,r){const s=o.book.sheet,n=s.rows.reshaped();if(!U(o,e))return r;const i=(l,t)=>()=>{const c=l(),f=t();return i(f,c)};return i(m(s,"rows",n),r)}function A(o,e,r,s=null){const{book:n}=o,i=n.sheet,l=h(e);n.transact("axis",()=>{const t=i[l].reshaped();r(),i.revision++;const c=m(i,l,t);return s!==null&&e==="col"?H(o,s,c):c}),g(o,e),s!==null&&n.collab?.changed?.()}const M=(o,e)=>o==="col"?e.r0===0&&e.r1===z-1:e.c0===0&&e.c1===S-1,k=(o,e)=>o==="col"?[e.c0,e.c1]:[e.r0,e.r1];function x(o,e,r){const s=new Set,n=e==="col"?S-1:z-1;for(const i of r.ranges){const[l,t]=k(e,i),c=e==="col"?o.maxCol:o.maxRow,f=t>=n?Math.max(l,c):t;for(let d=l;d<=f;d++)s.add(d)}return[...s]}function j(o,e,r,s){const n=[];let i=!1;for(const l of s.ranges){if(!M(e,l))continue;const[t,c]=k(e,l);r>=t&&r<=c&&(i=!0);const f=Math.min(c,t+2e4);for(let d=t;d<=f;d++)n.push(d)}return i?n:[r]}function Y(o,e,r,s){const n=j(o,e,r,s),i=o[h(e)];return{list:n,saved:i.reshaped(),starts:n.map(l=>i.sizeOf(l))}}function Z(o,e,r,s){const n=o[h(e)];for(const i of r.group.list)n.isHidden(i)&&n.setHidden(i,!1),n.setSize(i,s)}function $(o,e){const{book:r}=o,s=r.sheet,n=e.type==="colResize"?"col":"row",i=h(n),l=s[i],{list:t,starts:c,saved:f}=e.group;t.forEach((d,u)=>{l.sizeOf(d)===0&&!l.isHidden(d)&&(c[u]>0&&l.setSize(d,c[u]),l.setHidden(d,!0))}),r.transact("axis",()=>n==="col"?H(o,t,m(s,i,f)):m(s,i,f)),g(o,n),n==="col"&&r.collab?.changed?.()}function p(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const s=o.book.sheet,n=s[h(e)],i=x(s,e,o.grid.selection).filter(t=>b(s,e,t)),l=C(o.book);if(l.length>1){const t=h(e);o.book.transact("axis",()=>{const c=l.map(d=>{const u=d[t].reshaped();for(const w of i)b(d,e,w)&&(r===0?d[t].setHidden(w,!0):(d[t].setHidden(w,!1),d[t].setSize(w,r)));d.revision++,t==="cols"&&(d.colsChanged=!0);const a=m(d,t,u);return e==="col"&&d===s?H(o,i,a):a}),f=d=>()=>f(d.map(u=>u()));return f(c)}),g(o,e),e==="col"&&o.book.collab?.changed?.();return}A(o,e,()=>{for(const t of i)r===0?n.setHidden(t,!0):(n.setHidden(t,!1),n.setSize(t,r))},e==="col"?i:null)}function oo(o,e,r){if(!R(o,e==="row"?"formatRows":"formatColumns"))return;const s=o.book.sheet,n=s[h(e)];A(o,e,()=>{for(const i of o.grid.selection.ranges){const[l,t]=k(e,i);if(r)for(let c=l;c<=t;c++)n.setHidden(c,!0);else if(n.hiddenSizes)for(const c of[...n.hiddenSizes.keys()])c<l||c>t||e==="row"&&s.filteredRows?.has(c)||n.setHidden(c,!1)}})}function W(o,e){const{book:r,commands:s,grid:n}=o,i=r.sheet,l=x(i,e,n.selection);if(e==="row"){s.fitAxis("row",l);return}const t=n.selection.ranges[n.selection.ranges.length-1];s.fitAxis("col",l,M("col",t)?null:t)}const D=o=>o<=5?0:Math.round((o-5)/6*100)/100,E=o=>o<=0?0:Math.round(o*6+5);function L(o){const{book:e,grid:r}=o,s=e.sheet;F(o,"Standard Width","Standard column width:",D(s.cols.defaultSize),0,255,n=>{const i=C(e);e.transact("axis",()=>{const l=i.map(c=>{const f=c.cols;return c.cols=f.reshaped(f.count,Math.max(1,E(n))),c.standardWidthChanged=!0,m(c,"cols",f)}),t=c=>()=>t(c.map(f=>f()));return t(l)}),g(o,"col"),r.invalidate()})}function eo(o){const e=o.commands;return{items:[["Row Height…",()=>y(o,"row")],["AutoFit Row Height",()=>W(o,"row")],null,["Column Width…",()=>y(o,"col")],["AutoFit Selection",()=>W(o,"col")],["Standard Width…",()=>L(o)],null,["Hide & Unhide",()=>{},{items:()=>({items:[["Hide Rows",()=>e.setHidden("row",!0)],["Hide Columns",()=>e.setHidden("col",!0)],null,["Unhide Rows",()=>e.setHidden("row",!1)],["Unhide Columns",()=>e.setHidden("col",!1)]]})}],null,["Header Color…",()=>I(o)],["Format Cells…",()=>O(o),{kbd:"⌘1"}]]}}function to(o,e){const r=o.book.sheet,s=e.type==="colResize"?"col":"row";m(r,h(s),e.group.saved)(),s==="col"&&(r.colsChanged=!0),o.objects?.geometryChanged?.(),o.grid.invalidate()}export{A as axisStep,b as canResize,to as cancelAxisDrag,E as charsToWidth,Y as dragGroup,Z as dragSize,$ as endAxisDrag,W as fitSelected,eo as formatMenu,oo as hideSelected,L as openStandardWidth,j as selectedAround,p as setSelectedSize,D as widthToChars};
|
package/cells/cf-engine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseRangeRef as D}from"../core/address.js";import{CHUNK_BITS as C,CHUNK_MASK as q,DIRTY as P,KIND_MASK as B,NUM as E}from"../core/sheet.js";import{partsToSerial as R,serialToParts as F}from"../core/numfmt.js";import{compareValues as v,XlError as g}from"../calc/values.js";import{resolveColor as V}from"../io/xlsx-styles.js";const W=c=>c.split(/\s+/).map(D).filter(Boolean),K=1<<19,L=Object.freeze({}),O=new Set(["colorScale","dataBar","iconSet"]),$=c=>[parseInt(c.slice(1,3),16),parseInt(c.slice(3,5),16),parseInt(c.slice(5,7),16)],I=c=>(c<16?"0":"")+c.toString(16),k=c=>c<0?0:c>1?1:c;function U(c,s){const o={...s,...c};return(c.fill!==void 0||c.pattern!==void 0||c.gradient!==void 0||c.noFill)&&(c.pattern===void 0&&delete o.pattern,c.gradient===void 0&&delete o.gradient,c.fill===void 0&&delete o.fill,c.noFill||delete o.noFill),c.borders&&s.borders&&(o.borders={l:c.borders.l??s.borders.l,r:c.borders.r??s.borders.r,t:c.borders.t??s.borders.t,b:c.borders.b??s.borders.b}),o}const N=c=>c instanceof g?String(c.code??c.message??c).toLowerCase():typeof c=="boolean"?c?"true":"false":String(c).toLowerCase();class H{constructor(s,o,n){this.book=s,this.sheet=o,this.colorOf=n??(e=>V(e,s.theme??[])),this.cache=new Map,this.stats=new Map,this.data=new Map,this.flat=null,this.flatOf=null,this.today=0}invalidate(){this.cache.clear(),this.stats.clear(),this.data.clear(),this.flat=null,this.today=0}_rules(){const{cf:s}=this.sheet;if(this.flat!==null&&this.flatOf===s)return this.flat;const o=[];for(const n of s??[]){n._ranges===void 0&&(n._ranges=W(n.sqref));const e=n._ranges;if(e.length===0)continue;let t=1/0,r=1/0,i=-1,l=-1;for(const a of e)a.r0<t&&(t=a.r0),a.c0<r&&(r=a.c0),a.r1>i&&(i=a.r1),a.c1>l&&(l=a.c1);n._base={r0:t,c0:r};for(const a of n.rules)o.push({rule:a,block:n,r0:t,c0:r,r1:i,c1:l,single:e.length===1})}return o.sort((n,e)=>n.rule.priority-e.rule.priority),this.flat=o,this.flatOf=s,this.stoppers=o.filter(n=>n.rule.stopIfTrue&&!O.has(n.rule.type)),o}stoppedBefore(s,o,n){this._rules();for(const e of this.stoppers){if(e.rule.priority>=s)break;if(!(o<e.r0||o>e.r1||n<e.c0||n>e.c1)&&!(!e.single&&!e.block._ranges.some(t=>o>=t.r0&&o<=t.r1&&n>=t.c0&&n<=t.c1))&&this._evaluate(e.rule,e.block,o,n)!==null)return!0}return!1}at(s,o){const n=s*16384+o,e=this.cache.get(n);if(e!==void 0)return e;const t=this._rules();let r=null;for(let i=0;i<t.length;i++){const l=t[i];if(s<l.r0||s>l.r1||o<l.c0||o>l.c1)continue;if(!l.single){const u=l.block._ranges;let h=!1;for(let d=0;d<u.length&&!h;d++){const f=u[d];h=s>=f.r0&&s<=f.r1&&o>=f.c0&&o<=f.c1}if(!h)continue}const a=this._evaluate(l.rule,l.block,s,o);if(a!==null&&(r=r===null?a:U(r,a),l.rule.stopIfTrue&&!O.has(l.rule.type)))break}return this.cache.size>=K&&this.cache.clear(),this.cache.set(n,r),r}_value(s,o){return this.book.engine?this.book.engine.read(this.sheet,s,o):null}_stat(s){let o=this.stats.get(s);if(o!==void 0)return o;const{sheet:n}=this,{engine:e}=this.book;let t=new Float64Array(1024),r=0;for(const u of s._ranges){const h=Math.min(u.c1,n.maxCol),d=Math.min(u.r1,n.maxRow);for(let f=u.c0;f<=h;f++){const m=n.columns[f];if(m!==void 0)for(let p=u.r0>>>C;p<=d>>>C;p++){const _=m[p];if(_===void 0)continue;const x=p<<C,y=Math.max(u.r0-x,0),M=Math.min(d-x,q),{kinds:A,values:T}=_;if(r+(M-y+1)>t.length){const b=new Float64Array(Math.max(t.length*2,r+M-y+1));b.set(t),t=b}for(let b=y;b<=M;b++){const S=A[b];S!==0&&(S&P?(e&&e.read(n,x+b,f),(A[b]&B)===E&&(t[r++]=T[b])):(S&B)===E&&(t[r++]=T[b]))}}}}t=t.subarray(0,r).sort();let i=0;for(let u=0;u<r;u++)i+=t[u];const l=r?i/r:0;let a=0;for(let u=0;u<r;u++)a+=(t[u]-l)**2;return o={nums:t,n:r,mean:l,stdP:r>0?Math.sqrt(a/r):0,min:r?t[0]:0,max:r?t[r-1]:0,others:null},this.stats.set(s,o),o}_others(s){const o=this._stat(s);if(o.others!==null)return o.others;const n=new Map;for(const e of s._ranges)this.book.engine?.scan({sheet:this.sheet,r0:e.r0,c0:e.c0,r1:e.r1,c1:e.c1},t=>{if(typeof t=="number")return;const r=N(t);n.set(r,(n.get(r)??0)+1)});return o.others=n,n}_numberCount(s,o){const{nums:n,n:e}=this._stat(s);let t=0,r=e;for(;t<r;){const i=t+r>>>1;n[i]<o?t=i+1:r=i}return t>=e||n[t]!==o?0:t+1<e&&n[t+1]===o?2:1}_occurrences(s,o){const n=this._others(s);if(typeof o=="number")return this._numberCount(s,o)+(n.get(String(o))??0);const e=N(o),t=n.get(e)??0;return typeof o=="string"&&e!==""&&!Number.isNaN(Number(e))?t+this._numberCount(s,Number(e)):t}_template(s,o,n,e){const t=this._ruleData(s),r=`t${o}`;if(t[r]===void 0){const i=e._base;t[r]=this.book.engine.template(n,i.r0,i.c0)}return t[r]}_formula(s,o,n,e,t){const{engine:r}=this.book,i=s.formulas?.[o];return i===void 0||!r?null:this._run(this._template(s,o,i,n),e,t)}_run(s,o,n){const{engine:e}=this.book,t=e.legacy;e.legacy=!0;try{let r=s.fn(o,n,this.sheet);return(r&&r.sheet||r&&r.refs)&&(r=e.refAuto(r,o,n)),r&&r.data&&([r]=r.data),r===void 0?null:r}catch(r){return r instanceof g?r:null}finally{e.legacy=t}}_dxf(s){return s.dxf?s.dxf:s.dxfId!==null&&s.dxfId!==void 0?this.book.dxfs?.[s.dxfId]??L:L}_threshold(s,o){const n=this._stat(o);switch(s.type){case"min":return n.min;case"max":return n.max;case"autoMin":return Math.min(n.min,0);case"autoMax":return Math.max(n.max,0);default:break}const e=s.val;let t;if(typeof e=="string"&&!/^\s*[-+]?[\d.]+(?:[eE][-+]?\d+)?\s*$/.test(e)){const{engine:r}=this.book;if(!r)return 0;const i=o._base,l=this._run(r.template(e,i.r0,i.c0),i.r0,i.c0);t=typeof l=="number"?l:0}else t=e==null?0:Number(e);switch(s.type){case"percent":return n.min+(n.max-n.min)*t/100;case"percentile":{if(n.n===0)return 0;const r=k(t/100)*(n.n-1),i=Math.floor(r);return i+1<n.n?n.nums[i]+(r-i)*(n.nums[i+1]-n.nums[i]):n.nums[i]}default:return t}}_ruleData(s){let o=this.data.get(s);return o===void 0&&(o={},this.data.set(s,o)),o}_evaluate(s,o,n,e){switch(s.type){case"cellIs":{const t=this._value(n,e);if(t instanceof g)return null;const r=this._formula(s,0,o,n,e);if(r instanceof g)return null;const i=s.operator;let l=!1;if(i==="between"||i==="notBetween"){const a=this._formula(s,1,o,n,e);if(a instanceof g)return null;const u=v(r,a)<=0,h=u?r:a,d=u?a:r,f=v(t,h)>=0&&v(t,d)<=0;l=i==="between"?f:!f}else{const a=v(t,r);l=i==="greaterThan"?a>0:i==="lessThan"?a<0:i==="greaterThanOrEqual"?a>=0:i==="lessThanOrEqual"?a<=0:i==="equal"?a===0:i==="notEqual"?a!==0:!1}return l?this._dxf(s):null}case"expression":{const t=this._formula(s,0,o,n,e);return typeof t=="boolean"?t?this._dxf(s):null:typeof t=="number"&&t!==0?this._dxf(s):null}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":return this._textRule(s,o,n,e)?this._dxf(s):null;case"containsBlanks":{const t=this._value(n,e);return t===null||typeof t=="string"&&t.trim()===""?this._dxf(s):null}case"notContainsBlanks":{const t=this._value(n,e);return t!==null&&!(t instanceof g)&&!(typeof t=="string"&&t.trim()==="")?this._dxf(s):null}case"containsErrors":return this._value(n,e)instanceof g?this._dxf(s):null;case"notContainsErrors":return this._value(n,e)instanceof g?null:this._dxf(s);case"duplicateValues":case"uniqueValues":{const t=this._value(n,e);if(t===null)return null;const r=this._occurrences(o,t);return(s.type==="duplicateValues"?r>1:r===1)?this._dxf(s):null}case"top10":{const t=this._value(n,e);if(typeof t!="number")return null;const r=this._stat(o);let i=s.rank??10;return s.percent&&(i=Math.max(1,Math.floor(r.n*i/100))),i=Math.min(i,r.n),i<=0?null:(s.bottom?t<=r.nums[i-1]:t>=r.nums[r.n-i])?this._dxf(s):null}case"aboveAverage":{const t=this._value(n,e);if(typeof t!="number")return null;const r=this._stat(o),i=s.aboveAverage!==!1,l=r.mean+(i?1:-1)*(s.stdDev||0)*r.stdP;return(i?s.equalAverage?t>=l:t>l:s.equalAverage?t<=l:t<l)?this._dxf(s):null}case"timePeriod":{const t=this._value(n,e);return typeof t=="number"&&this._inPeriod(t,s.timePeriod)?this._dxf(s):null}case"colorScale":{const t=this._value(n,e);return typeof t=="number"?this._colorScale(s,o,t):null}case"dataBar":{const t=this._value(n,e);return typeof t=="number"?this._dataBar(s,o,t):null}case"iconSet":{const t=this._value(n,e);return typeof t=="number"?this._iconSet(s,o,t):null}default:return null}}_textRule(s,o,n,e){if(s.formulas&&s.formulas.length>0&&this.book.engine){const l=this._formula(s,0,o,n,e);return l===!0||typeof l=="number"&&l!==0}const t=this._value(n,e),r=String(s.text??"").toLowerCase();if(t instanceof g)return s.type==="notContainsText";const i=t===null?"":typeof t=="boolean"?t?"true":"false":String(t).toLowerCase();switch(s.type){case"containsText":return i.includes(r);case"notContainsText":return!i.includes(r);case"beginsWith":return i.startsWith(r);default:return i.endsWith(r)}}_colorScale(s,o,n){const e=this._ruleData(s);if(e.stops===void 0){const{cfvo:i,colors:l}=s.colorScale;e.stops=i.map(a=>this._threshold(a,o)),e.css=l.map(a=>this.colorOf({a})??"#FFFFFF"),e.rgb=e.css.map($),e.ends=e.css.map(a=>({fill:a}))}const{stops:t}=e,r=t.length-1;if(n>=t[r])return e.ends[r];if(n<=t[0])return e.ends[0];for(let i=1;i<=r;i++)if(n<t[i]){const l=t[i]-t[i-1],a=l===0?1:(n-t[i-1])/l,u=e.rgb[i-1],h=e.rgb[i];return{fill:`#${I(Math.round(u[0]+(h[0]-u[0])*a))}${I(Math.round(u[1]+(h[1]-u[1])*a))}${I(Math.round(u[2]+(h[2]-u[2])*a))}`}}return e.ends[r]}_barStyle(s,o){const n=this._ruleData(s);if(n.bar!==void 0)return n.bar;const e=s.dataBar,t=e.ext,r=t?.cfvo??e.cfvo;let i=this._threshold(r[0],o),l=this._threshold(r[1],o);l<i&&([i,l]=[l,i]);const a=this.colorOf({a:e.color})??"#638EC6",u=(_,x)=>_?this.colorOf({a:_})??x:x,h=(t?t.minLength:e.minLength??10)/100,d=(t?t.maxLength:e.maxLength??90)/100,f=t?t.axisPosition??"automatic":"none";let m=-1;f==="middle"?m=.5:f==="automatic"&&(i<0&&l>0?m=-i/(l-i):l<=0&&i<0&&(m=1));const p=t?.border?u(t.borderColor,a):null;return n.bar={lo:i,hi:l,minL:h,maxL:d,start:t?h/2:h,axisAt:m,color:a,gradient:t?t.gradient!==!1:!0,border:p,negColor:t&&!t.negFillSame?u(t.negFill,"#FF0000"):a,negBorder:t?.border&&t.negBorderSame===!1?u(t.negBorder,"#FF0000"):p,axisColor:t?u(t.axisColor,"#000000"):"#000000",direction:t?.direction??"context",hide:e.showValue===!1},n.bar}_dataBar(s,o,n){const e=this._barStyle(s,o),{lo:t,hi:r,minL:i,maxL:l,axisAt:a,start:u}=e,h=l-i;let d,f;if(a<0)d=0,f=u+h*(r===t?1:k((n-t)/(r-t)));else{const _=s.dataBar.ext?.axisPosition==="middle"?Math.max(Math.abs(t),Math.abs(r)):n>=0?r:-t,y=(n>=0?1-a:a)*(u+h*(_>0?k(Math.abs(n)/_):0));n>=0?(d=a,f=a+y):(f=a,d=a-y)}return{bar:{style:e,x0:d,x1:f,negative:n<0,pct:f-d,color:n<0?e.negColor:e.color},hideValue:e.hide}}_iconSet(s,o,n){const e=this._ruleData(s),t=s.iconSet;if(e.levels===void 0){e.thresholds=t.cfvo.map(u=>this._threshold(u,o));const a=t.cfvo.length;e.levels=t.cfvo.map((u,h)=>{const d=t.reverse?a-1-h:h,f=t.custom?.[h],m=f?f.iconSet:t.name,p=f?f.iconId:d,_=t.showValue===!1;return m==="NoIcons"?{hideValue:_}:{icon:{name:m,level:p,count:a},hideValue:_}})}const{thresholds:r,levels:i}=e;let l=0;for(let a=r.length-1;a>=1;a--){const u=r[a];if(t.cfvo[a].gte===!1?n>u:n>=u){l=a;break}}return i[l]}_inPeriod(s,o){if(this.today===0){const a=new Date;this.today=R(a.getFullYear(),a.getMonth()+1,a.getDate())}const{today:n}=this,e=Math.floor(s);if(e<0)return!1;switch(o){case"today":return e===n;case"yesterday":return e===n-1;case"tomorrow":return e===n+1;case"last7Days":return e<=n&&e>n-7;default:break}const t=a=>a-F(a).weekday;switch(o){case"thisWeek":return t(e)===t(n);case"lastWeek":return t(e)===t(n)-7;case"nextWeek":return t(e)===t(n)+7;default:break}const r=F(e),i=F(n),l=(r.year-i.year)*12+r.month-i.month;switch(o){case"thisMonth":return l===0;case"lastMonth":return l===-1;case"nextMonth":return l===1;default:return!1}}}function j(c,s){if(!c.cfEval){if(!s)return null;c.cfEval=new H(s,c)}return c.cfEval}function w(c,s,o,n){if(!c.cf||c.cf.length===0)return null;const e=j(c,n),t=e?e.at(s,o):null;return t===null?null:{fill:t.fill??null,noFill:t.noFill===!0,color:t.color??null,iconSet:t.icon?.name??null,iconId:t.icon?.level??null}}function Q(c,s,o,n){const e=w(c,s,o,n);return e&&e.iconSet!==null?{iconSet:e.iconSet,iconId:e.iconId}:null}export{H as CondFormats,w as cfEffectAt,j as evaluatorOf,Q as iconAt};
|
|
1
|
+
import{parseRangeRef as N}from"../core/address.js";import{CHUNK_BITS as C,CHUNK_MASK as D,DIRTY as q,KIND_MASK as T,NUM as B}from"../core/sheet.js";import{partsToSerial as P,serialToParts as F}from"../core/numfmt.js";import{compareValues as M,XlError as x}from"../calc/values.js";import{wildcardRegex as R}from"../calc/functions/helpers.js";import{resolveColor as V}from"../io/xlsx-styles.js";const W=c=>c.split(/\s+/).map(N).filter(Boolean),K=1<<19,w=Object.freeze({}),E=new Set(["colorScale","dataBar","iconSet"]),$=c=>[parseInt(c.slice(1,3),16),parseInt(c.slice(3,5),16),parseInt(c.slice(5,7),16)],I=c=>(c<16?"0":"")+c.toString(16),k=c=>c<0?0:c>1?1:c;function U(c,s){const o={...s,...c};return(c.fill!==void 0||c.pattern!==void 0||c.gradient!==void 0||c.noFill)&&(c.pattern===void 0&&delete o.pattern,c.gradient===void 0&&delete o.gradient,c.fill===void 0&&delete o.fill,c.noFill||delete o.noFill),c.borders&&s.borders&&(o.borders={l:c.borders.l??s.borders.l,r:c.borders.r??s.borders.r,t:c.borders.t??s.borders.t,b:c.borders.b??s.borders.b}),o}const O=c=>c instanceof x?String(c.code??c.message??c).toLowerCase():typeof c=="boolean"?c?"true":"false":String(c).toLowerCase();class H{constructor(s,o,n){this.book=s,this.sheet=o,this.colorOf=n??(e=>V(e,s.theme??[])),this.cache=new Map,this.stats=new Map,this.data=new Map,this.flat=null,this.flatOf=null,this.today=0}invalidate(){this.cache.clear(),this.stats.clear(),this.data.clear(),this.flat=null,this.today=0}_rules(){const{cf:s}=this.sheet;if(this.flat!==null&&this.flatOf===s)return this.flat;const o=[];for(const n of s??[]){n._ranges===void 0&&(n._ranges=W(n.sqref));const e=n._ranges;if(e.length===0)continue;let t=1/0,r=1/0,i=-1,l=-1;for(const a of e)a.r0<t&&(t=a.r0),a.c0<r&&(r=a.c0),a.r1>i&&(i=a.r1),a.c1>l&&(l=a.c1);n._base={r0:t,c0:r};for(const a of n.rules)o.push({rule:a,block:n,r0:t,c0:r,r1:i,c1:l,single:e.length===1})}return o.sort((n,e)=>n.rule.priority-e.rule.priority),this.flat=o,this.flatOf=s,this.stoppers=o.filter(n=>n.rule.stopIfTrue&&!E.has(n.rule.type)),o}stoppedBefore(s,o,n){this._rules();for(const e of this.stoppers){if(e.rule.priority>=s)break;if(!(o<e.r0||o>e.r1||n<e.c0||n>e.c1)&&!(!e.single&&!e.block._ranges.some(t=>o>=t.r0&&o<=t.r1&&n>=t.c0&&n<=t.c1))&&this._evaluate(e.rule,e.block,o,n)!==null)return!0}return!1}at(s,o){const n=s*16384+o,e=this.cache.get(n);if(e!==void 0)return e;const t=this._rules();let r=null;for(let i=0;i<t.length;i++){const l=t[i];if(s<l.r0||s>l.r1||o<l.c0||o>l.c1)continue;if(!l.single){const u=l.block._ranges;let h=!1;for(let d=0;d<u.length&&!h;d++){const f=u[d];h=s>=f.r0&&s<=f.r1&&o>=f.c0&&o<=f.c1}if(!h)continue}const a=this._evaluate(l.rule,l.block,s,o);if(a!==null&&(r=r===null?a:U(r,a),l.rule.stopIfTrue&&!E.has(l.rule.type)))break}return this.cache.size>=K&&this.cache.clear(),this.cache.set(n,r),r}_value(s,o){return this.book.engine?this.book.engine.read(this.sheet,s,o):null}_stat(s){let o=this.stats.get(s);if(o!==void 0)return o;const{sheet:n}=this,{engine:e}=this.book;let t=new Float64Array(1024),r=0;for(const u of s._ranges){const h=Math.min(u.c1,n.maxCol),d=Math.min(u.r1,n.maxRow);for(let f=u.c0;f<=h;f++){const m=n.columns[f];if(m!==void 0)for(let p=u.r0>>>C;p<=d>>>C;p++){const _=m[p];if(_===void 0)continue;const b=p<<C,y=Math.max(u.r0-b,0),v=Math.min(d-b,D),{kinds:A,values:L}=_;if(r+(v-y+1)>t.length){const g=new Float64Array(Math.max(t.length*2,r+v-y+1));g.set(t),t=g}for(let g=y;g<=v;g++){const S=A[g];S!==0&&(S&q?(e&&e.read(n,b+g,f),(A[g]&T)===B&&(t[r++]=L[g])):(S&T)===B&&(t[r++]=L[g]))}}}}t=t.subarray(0,r).sort();let i=0;for(let u=0;u<r;u++)i+=t[u];const l=r?i/r:0;let a=0;for(let u=0;u<r;u++)a+=(t[u]-l)**2;return o={nums:t,n:r,mean:l,stdP:r>0?Math.sqrt(a/r):0,min:r?t[0]:0,max:r?t[r-1]:0,others:null,texts:null,wild:null},this.stats.set(s,o),o}_others(s){const o=this._stat(s);if(o.others!==null)return o.others;const n=new Map;for(const e of s._ranges)this.book.engine?.scan({sheet:this.sheet,r0:e.r0,c0:e.c0,r1:e.r1,c1:e.c1},t=>{if(typeof t=="number")return;const r=O(t);n.set(r,(n.get(r)??0)+1)});return o.others=n,n}_numberCount(s,o){const{nums:n,n:e}=this._stat(s);let t=0,r=e;for(;t<r;){const i=t+r>>>1;n[i]<o?t=i+1:r=i}return t>=e||n[t]!==o?0:t+1<e&&n[t+1]===o?2:1}_wildcardCount(s,o){const n=this._stat(s);if(n.texts===null){n.texts=new Map;for(const r of s._ranges)this.book.engine?.scan({sheet:this.sheet,r0:r.r0,c0:r.c0,r1:r.r1,c1:r.c1},i=>{typeof i=="string"&&n.texts.set(i.toLowerCase(),(n.texts.get(i.toLowerCase())??0)+1)})}n.wild??=new Map;const e=o.toLowerCase();let t=n.wild.get(e);if(t===void 0){const r=R(o);t=0;for(const[i,l]of n.texts)r.test(i)&&(t+=l);n.wild.set(e,t)}return t}_occurrences(s,o){if(typeof o=="string"&&/[*?]/.test(o))return this._wildcardCount(s,o);const n=this._others(s);if(typeof o=="number")return this._numberCount(s,o)+(n.get(String(o))??0);const e=O(o),t=n.get(e)??0;return typeof o=="string"&&e!==""&&!Number.isNaN(Number(e))?t+this._numberCount(s,Number(e)):t}_template(s,o,n,e){const t=this._ruleData(s),r=`t${o}`;if(t[r]===void 0){const i=e._base;t[r]=this.book.engine.template(n,i.r0,i.c0)}return t[r]}_formula(s,o,n,e,t){const{engine:r}=this.book,i=s.formulas?.[o];return i===void 0||!r?null:this._run(this._template(s,o,i,n),e,t)}_run(s,o,n){const{engine:e}=this.book,t=e.legacy;e.legacy=!0;try{let r=s.fn(o,n,this.sheet);return(r&&r.sheet||r&&r.refs)&&(r=e.refAuto(r,o,n)),r&&r.data&&([r]=r.data),r===void 0?null:r}catch(r){return r instanceof x?r:null}finally{e.legacy=t}}_dxf(s){return s.dxf?s.dxf:s.dxfId!==null&&s.dxfId!==void 0?this.book.dxfs?.[s.dxfId]??w:w}_threshold(s,o){const n=this._stat(o);switch(s.type){case"min":return n.min;case"max":return n.max;case"autoMin":return Math.min(n.min,0);case"autoMax":return Math.max(n.max,0);default:break}const e=s.val;let t;if(typeof e=="string"&&!/^\s*[-+]?[\d.]+(?:[eE][-+]?\d+)?\s*$/.test(e)){const{engine:r}=this.book;if(!r)return 0;const i=o._base,l=this._run(r.template(e,i.r0,i.c0),i.r0,i.c0);t=typeof l=="number"?l:0}else t=e==null?0:Number(e);switch(s.type){case"percent":return n.min+(n.max-n.min)*t/100;case"percentile":{if(n.n===0)return 0;const r=k(t/100)*(n.n-1),i=Math.floor(r);return i+1<n.n?n.nums[i]+(r-i)*(n.nums[i+1]-n.nums[i]):n.nums[i]}default:return t}}_ruleData(s){let o=this.data.get(s);return o===void 0&&(o={},this.data.set(s,o)),o}_evaluate(s,o,n,e){switch(s.type){case"cellIs":{const t=this._value(n,e);if(t instanceof x)return null;const r=this._formula(s,0,o,n,e);if(r instanceof x)return null;const i=s.operator;let l=!1;if(i==="between"||i==="notBetween"){const a=this._formula(s,1,o,n,e);if(a instanceof x)return null;const u=M(r,a)<=0,h=u?r:a,d=u?a:r,f=M(t,h)>=0&&M(t,d)<=0;l=i==="between"?f:!f}else{const a=M(t,r);l=i==="greaterThan"?a>0:i==="lessThan"?a<0:i==="greaterThanOrEqual"?a>=0:i==="lessThanOrEqual"?a<=0:i==="equal"?a===0:i==="notEqual"?a!==0:!1}return l?this._dxf(s):null}case"expression":{const t=this._formula(s,0,o,n,e);return typeof t=="boolean"?t?this._dxf(s):null:typeof t=="number"&&t!==0?this._dxf(s):null}case"containsText":case"notContainsText":case"beginsWith":case"endsWith":return this._textRule(s,o,n,e)?this._dxf(s):null;case"containsBlanks":{const t=this._value(n,e);return t===null||typeof t=="string"&&t.trim()===""?this._dxf(s):null}case"notContainsBlanks":{const t=this._value(n,e);return t!==null&&!(t instanceof x)&&!(typeof t=="string"&&t.trim()==="")?this._dxf(s):null}case"containsErrors":return this._value(n,e)instanceof x?this._dxf(s):null;case"notContainsErrors":return this._value(n,e)instanceof x?null:this._dxf(s);case"duplicateValues":case"uniqueValues":{const t=this._value(n,e);if(t===null)return null;const r=this._occurrences(o,t);return(s.type==="duplicateValues"?r>1:r===1)?this._dxf(s):null}case"top10":{const t=this._value(n,e);if(typeof t!="number")return null;const r=this._stat(o);let i=s.rank??10;return s.percent&&(i=Math.max(1,Math.floor(r.n*i/100))),i=Math.min(i,r.n),i<=0?null:(s.bottom?t<=r.nums[i-1]:t>=r.nums[r.n-i])?this._dxf(s):null}case"aboveAverage":{const t=this._value(n,e);if(typeof t!="number")return null;const r=this._stat(o),i=s.aboveAverage!==!1,l=r.mean+(i?1:-1)*(s.stdDev||0)*r.stdP;return(i?s.equalAverage?t>=l:t>l:s.equalAverage?t<=l:t<l)?this._dxf(s):null}case"timePeriod":{const t=this._value(n,e);return typeof t=="number"&&this._inPeriod(t,s.timePeriod)?this._dxf(s):null}case"colorScale":{const t=this._value(n,e);return typeof t=="number"?this._colorScale(s,o,t):null}case"dataBar":{const t=this._value(n,e);return typeof t=="number"?this._dataBar(s,o,t):null}case"iconSet":{const t=this._value(n,e);return typeof t=="number"?this._iconSet(s,o,t):null}default:return null}}_textRule(s,o,n,e){if(s.formulas&&s.formulas.length>0&&this.book.engine){const l=this._formula(s,0,o,n,e);return l===!0||typeof l=="number"&&l!==0}const t=this._value(n,e),r=String(s.text??"").toLowerCase();if(t instanceof x)return s.type==="notContainsText";const i=t===null?"":typeof t=="boolean"?t?"true":"false":String(t).toLowerCase();switch(s.type){case"containsText":return i.includes(r);case"notContainsText":return!i.includes(r);case"beginsWith":return i.startsWith(r);default:return i.endsWith(r)}}_colorScale(s,o,n){const e=this._ruleData(s);if(e.stops===void 0){const{cfvo:i,colors:l}=s.colorScale;e.stops=i.map(a=>this._threshold(a,o)),e.css=l.map(a=>this.colorOf({a})??"#FFFFFF"),e.rgb=e.css.map($),e.ends=e.css.map(a=>({fill:a}))}const{stops:t}=e,r=t.length-1;if(n>=t[r])return e.ends[r];if(n<=t[0])return e.ends[0];for(let i=1;i<=r;i++)if(n<t[i]){const l=t[i]-t[i-1],a=l===0?1:(n-t[i-1])/l,u=e.rgb[i-1],h=e.rgb[i];return{fill:`#${I(Math.round(u[0]+(h[0]-u[0])*a))}${I(Math.round(u[1]+(h[1]-u[1])*a))}${I(Math.round(u[2]+(h[2]-u[2])*a))}`}}return e.ends[r]}_barStyle(s,o){const n=this._ruleData(s);if(n.bar!==void 0)return n.bar;const e=s.dataBar,t=e.ext,r=t?.cfvo??e.cfvo;let i=this._threshold(r[0],o),l=this._threshold(r[1],o);l<i&&([i,l]=[l,i]);const a=this.colorOf({a:e.color})??"#638EC6",u=(_,b)=>_?this.colorOf({a:_})??b:b,h=(t?t.minLength:e.minLength??10)/100,d=(t?t.maxLength:e.maxLength??90)/100,f=t?t.axisPosition??"automatic":"none";let m=-1;f==="middle"?m=.5:f==="automatic"&&(i<0&&l>0?m=-i/(l-i):l<=0&&i<0&&(m=1));const p=t?.border?u(t.borderColor,a):null;return n.bar={lo:i,hi:l,minL:h,maxL:d,start:t?h/2:h,axisAt:m,color:a,gradient:t?t.gradient!==!1:!0,border:p,negColor:t&&!t.negFillSame?u(t.negFill,"#FF0000"):a,negBorder:t?.border&&t.negBorderSame===!1?u(t.negBorder,"#FF0000"):p,axisColor:t?u(t.axisColor,"#000000"):"#000000",direction:t?.direction??"context",hide:e.showValue===!1},n.bar}_dataBar(s,o,n){const e=this._barStyle(s,o),{lo:t,hi:r,minL:i,maxL:l,axisAt:a,start:u}=e,h=l-i;let d,f;if(a<0)d=0,f=u+h*(r===t?1:k((n-t)/(r-t)));else{const _=s.dataBar.ext?.axisPosition==="middle"?Math.max(Math.abs(t),Math.abs(r)):n>=0?r:-t,y=(n>=0?1-a:a)*(u+h*(_>0?k(Math.abs(n)/_):0));n>=0?(d=a,f=a+y):(f=a,d=a-y)}return{bar:{style:e,x0:d,x1:f,negative:n<0,pct:f-d,color:n<0?e.negColor:e.color},hideValue:e.hide}}_iconSet(s,o,n){const e=this._ruleData(s),t=s.iconSet;if(e.levels===void 0){e.thresholds=t.cfvo.map(u=>this._threshold(u,o));const a=t.cfvo.length;e.levels=t.cfvo.map((u,h)=>{const d=t.reverse?a-1-h:h,f=t.custom?.[h],m=f?f.iconSet:t.name,p=f?f.iconId:d,_=t.showValue===!1;return m==="NoIcons"?{hideValue:_}:{icon:{name:m,level:p,count:a},hideValue:_}})}const{thresholds:r,levels:i}=e;let l=0;for(let a=r.length-1;a>=1;a--){const u=r[a];if(t.cfvo[a].gte===!1?n>u:n>=u){l=a;break}}return i[l]}_inPeriod(s,o){if(this.today===0){const a=new Date;this.today=P(a.getFullYear(),a.getMonth()+1,a.getDate())}const{today:n}=this,e=Math.floor(s);if(e<0)return!1;switch(o){case"today":return e===n;case"yesterday":return e===n-1;case"tomorrow":return e===n+1;case"last7Days":return e<=n&&e>n-7;default:break}const t=a=>a-F(a).weekday;switch(o){case"thisWeek":return t(e)===t(n);case"lastWeek":return t(e)===t(n)-7;case"nextWeek":return t(e)===t(n)+7;default:break}const r=F(e),i=F(n),l=(r.year-i.year)*12+r.month-i.month;switch(o){case"thisMonth":return l===0;case"lastMonth":return l===-1;case"nextMonth":return l===1;default:return!1}}}function j(c,s){if(!c.cfEval){if(!s)return null;c.cfEval=new H(s,c)}return c.cfEval}function z(c,s,o,n){if(!c.cf||c.cf.length===0)return null;const e=j(c,n),t=e?e.at(s,o):null;return t===null?null:{fill:t.fill??null,noFill:t.noFill===!0,color:t.color??null,iconSet:t.icon?.name??null,iconId:t.icon?.level??null}}function tt(c,s,o,n){const e=z(c,s,o,n);return e&&e.iconSet!==null?{iconSet:e.iconSet,iconId:e.iconId}:null}export{H as CondFormats,z as cfEffectAt,j as evaluatorOf,tt as iconAt};
|
package/cells/format-tabs.js
CHANGED
|
@@ -5,7 +5,7 @@ import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numf
|
|
|
5
5
|
.fc-dlg .dlg-title { margin-bottom: 18px; }
|
|
6
6
|
.fc-dlg .dlg-foot { margin-top: 17px; }
|
|
7
7
|
.fc-dlg .dlg-label { margin-bottom: 8px; }
|
|
8
|
-
.fc-dlg .dlg-panes { flex: 1; min-height: 0; overflow: auto; padding:
|
|
8
|
+
.fc-dlg .dlg-panes { flex: 1; min-height: 0; overflow: auto; padding: 10px 2px 12px; border: 0; background: transparent; }
|
|
9
9
|
.fc-dlg .dlg-note { margin: 17px 0 0; font-size: 13px; color: var(--ink); line-height: 16px; }
|
|
10
10
|
.fc-rule-h { border: 0; border-top: 1px solid var(--xl-box-line); margin: 0; }
|
|
11
11
|
.fc-bleed { margin: -22px -24px -12px -19px; min-height: calc(100% + 34px); }
|
|
@@ -64,7 +64,7 @@ import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numf
|
|
|
64
64
|
.fc-font-normal { display: flex; align-items: center; padding-top: 25px; }
|
|
65
65
|
.fc-font-low { margin-top: 15px; padding: 14px 24px 12px 22px; border-top: 1px solid var(--xl-box-line); display: grid; grid-template-columns: 283px minmax(0, 1fr); }
|
|
66
66
|
.fc-font-low .dlg-check { margin-left: 17px; }
|
|
67
|
-
.fc-dlg .fc-preview { position: relative; display: flex; align-items: center; justify-content: center; width: 217px; height: 67px; overflow: hidden; white-space: nowrap; background: #fff; color: #000; }
|
|
67
|
+
.fc-dlg .fc-preview { position: relative; display: flex; align-items: center; justify-content: center; width: 217px; height: 67px; overflow: hidden; white-space: nowrap; background: #fff; color: #000; border: 1px solid var(--xl-box-line); }
|
|
68
68
|
.fc-preview::before, .fc-preview::after { content: ""; position: absolute; top: 50%; width: 40px; border-top: 1px solid #000; }
|
|
69
69
|
.fc-preview::before { left: 0; }
|
|
70
70
|
.fc-preview::after { right: 0; }
|
|
@@ -95,7 +95,7 @@ import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numf
|
|
|
95
95
|
.fc-fill-right .dlg-label ~ .dlg-label { margin-top: 18px; }
|
|
96
96
|
.fc-fill-left .dlg-btn:not(.fc-popbtn) { margin-top: 14px; }
|
|
97
97
|
.fc-fill-low { grid-column: 1 / -1; display: flex; flex-direction: column; padding: 26px 26px 16px 28px; border-top: 1px solid var(--xl-box-line); }
|
|
98
|
-
.fc-sample { flex: 1; min-height: 0; margin-top: 4px; border-radius: 3px; }
|
|
98
|
+
.fc-sample { flex: 1; min-height: 0; margin-top: 4px; border: 1px solid var(--xl-box-line); border-radius: 3px; }
|
|
99
99
|
|
|
100
100
|
.fc-protect .fc-hint { margin: 13px 0 13px; max-width: 520px; }
|
|
101
101
|
.fc-protect .dlg-check { margin-left: 2px; }
|
package/cells/goto.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{el as h,openModal as O}from"../ui/dialogs.js";import{ensureBookCss as D}from"./book-css.js";import{BOOL as U,CHUNK_BITS as A,CHUNK_MASK as R,ERR as q,FORMULA as S,KIND_MASK as N,NUM as H,STR as V}from"../core/sheet.js";import{MAX_COLS as x,MAX_ROWS as j,parseRangeRef as L}from"../core/address.js";import{goToText as X,locationText as z,namedPlaces as I}from"./name-box.js";import{inRanges as $}from"./selection-modes.js";import{t as M,tc as v}from"../i18n/index.js";const T=32768;class w{constructor(){this.ranges=[],this.open=new Map,this.col=-1}add(i,a,t){const e=a*j+t,l=this.open.get(e);if(l&&l.c1===i-1){l.c1=i;return}const s={r0:a,c0:i,r1:t,c1:i};this.open.set(e,s),this.ranges.push(s)}get tooMany(){return this.ranges.length>T}}function P(r){const{grid:i,book:a}=r,{sheet:t}=a,{ranges:e}=i.selection,l=n=>({r0:n.r0,c0:n.c0,r1:Math.min(n.r1,t.maxRow),c1:Math.min(n.c1,t.maxCol)});return e.length===1&&e[0].r0===e[0].r1&&e[0].c0===e[0].c1||e.length===1&&t.mergeAt(e[0].r0,e[0].c0)?[{r0:0,c0:0,r1:Math.max(0,t.maxRow),c1:Math.max(0,t.maxCol)}]:e.map(l).filter(n=>n.r0<=n.r1&&n.c0<=n.c1)}function G(r,i,a){const t=new w;for(const e of i)for(let l=e.c0;l<=e.c1;l++){const s=r.columns[l];if(s===void 0)continue;let n=-1;for(let o=e.r0>>>A;o<=e.r1>>>A;o++){const c=s[o],f=o<<A;if(c===void 0){n>=0&&(t.add(l,n,f-1),n=-1);continue}const m=Math.max(e.r0-f,0),d=Math.min(e.r1-f,R);for(let u=m;u<=d;u++){const k=c.kinds[u];k!==0&&a(k,f+u,l,c.values[u])?n<0&&(n=f+u):n>=0&&(t.add(l,n,f+u-1),n=-1)}}n>=0&&t.add(l,n,e.r1)}return t}const _=(r,i)=>{const a=r&N;return a===H&&i.numbers||a===V&&i.text||a===U&&i.logicals||a===q&&i.errors};function Z(r,i){const a=new w;for(const t of i)for(let e=t.c0;e<=t.c1&&!a.tooMany;e++){const l=r.columns[e];if(l===void 0){a.add(e,t.r0,t.r1);continue}let s=-1;for(let n=t.r0;n<=t.r1;n++){const o=l[n>>>A];if(o===void 0){s<0&&(s=n);const c=n|R;n=Math.min(c,t.r1);continue}o.kinds[n&R]===0?s<0&&(s=n):s>=0&&(a.add(e,s,n-1),s=-1)}s>=0&&a.add(e,s,t.r1)}return a}const K=(r,i,a)=>{const t=r.rAbs0?r.r0:i+r.r0,e=r.rAbs1?r.r1:i+r.r1,l=r.cAbs0?r.c0:a+r.c0,s=r.cAbs1?r.c1:a+r.c1;return{r0:Math.min(t,e),c0:Math.min(l,s),r1:Math.max(t,e),c1:Math.max(l,s)}};function B(r,i,a,t){return i.formula(a,t)?.tpl??null}function W(r,i,a,t){const e=new Set,l=[];let s=[];for(const n of a)for(const[o]of i.formulas){const c=Math.floor(o/x),f=o-c*x;c>=n.r0&&c<=n.r1&&f>=n.c0&&f<=n.c1&&s.push([c,f])}for(let n=0;s.length>0&&n<64;n++){const o=[];for(const[c,f]of s){const m=B(r,i,c,f);if(m)for(const d of m.refs){if(d.sheet)continue;const u=K(d,c,f),k=`${u.r0},${u.c0},${u.r1},${u.c1}`;if(!e.has(k)&&(e.add(k),l.push({r0:u.r0,c0:u.c0,r1:Math.min(u.r1,j-1),c1:Math.min(u.c1,x-1)}),!!t))for(const[g]of i.formulas){const p=Math.floor(g/x),b=g-p*x;p>=u.r0&&p<=u.r1&&b>=u.c0&&b<=u.c1&&o.push([p,b])}}}if(!t)break;s=o}return l}function J(r,i,a,t){const e=new Set;let l=a;for(let o=0;l.length>0&&o<64;o++){const c=[];for(const[f]of i.formulas){if(e.has(f))continue;const m=Math.floor(f/x),d=f-m*x,u=B(r,i,m,d);if(u)for(const k of u.refs){if(k.sheet)continue;const g=K(k,m,d);if(l.some(p=>g.r0<=p.r1&&g.r1>=p.r0&&g.c0<=p.c1&&g.c1>=p.c0)){e.add(f),c.push({r0:m,c0:d,r1:m,c1:d});break}}}if(!t)break;l=c}const s=new Map;for(const o of e){const c=Math.floor(o/x),f=o-c*x;s.has(f)||s.set(f,[]),s.get(f).push(c)}const n=new w;for(const o of[...s.keys()].sort((c,f)=>c-f)){const c=s.get(o).sort((m,d)=>m-d);let f=c[0];for(let m=1;m<=c.length;m++)c[m]!==c[m-1]+1&&(n.add(o,f,c[m-1]),f=c[m])}return n.ranges}function C(r,i,a,t,e,l){const s=i.kind(a,t);return s&S?`f${r.editText(i,a,t).replace(/\$?[A-Z]{1,3}\$?\d+/g,o=>{const c=/^(\$?)([A-Z]+)(\$?)(\d+)$/.exec(o),f=c[2].split("").reduce((m,d)=>m*26+d.charCodeAt(0)-64,0)-1;return`${c[1]?`$${c[2]}`:`C[${f-t+l}]`}${c[3]?`$${c[4]}`:`R[${Number(c[4])-1-a+e}]`}`})}`:`${s&N}:${i.value(a,t)}`}function Q(r,i,a,t){const e=new w;for(const l of a)for(let s=l.c0;s<=l.c1;s++){if(s===t)continue;let n=-1;for(let o=l.r0;o<=l.r1;o++){const c=C(r,i,o,s,o,t)!==C(r,i,o,t,o,t);c&&n<0?n=o:!c&&n>=0&&(e.add(s,n,o-1),n=-1)}n>=0&&e.add(s,n,l.r1)}return e}function Y(r,i,a,t){const e=new w;for(const l of a)for(let s=l.c0;s<=l.c1;s++){const n=C(r,i,t,s,t,s);let o=-1;for(let c=l.r0;c<=l.r1;c++){const f=c!==t&&C(r,i,c,s,t,s)!==n;f&&o<0?o=c:!f&&o>=0&&(e.add(s,o,c-1),o=-1)}o>=0&&e.add(s,o,l.r1)}return e}function ee(r,i){const a=(e,l,s)=>{const n=[];let o=-1;for(let c=l;c<=s;c++){const f=e.sizeOf(c)>0;f&&o<0?o=c:!f&&o>=0&&(n.push([o,c-1]),o=-1)}return o>=0&&n.push([o,s]),n},t=[];for(const e of i){const l=a(r.rows,e.r0,Math.min(e.r1,Math.max(r.maxRow,e.r0))),s=a(r.cols,e.c0,Math.min(e.c1,Math.max(r.maxCol,e.c0)));for(const[n,o]of l)for(const[c,f]of s)t.push({r0:n,c0:c,r1:o,c1:f})}return t}const E=r=>(r??"").split(/\s+/).map(L).filter(Boolean);function te(r,{same:i},a,t){const e=[];for(const l of r.cf??[]){const s=E(l.sqref);(!i||$(s,a,t))&&e.push(...s)}return e}function ne(r,{same:i},a,t){const e=[];for(const l of r.validations??[]){const s=E(l.sqref);(!i||$(s,a,t))&&e.push(...s)}return e}function oe(r){const{book:i,grid:a}=r,{sheet:t}=i,{row:e,col:l}=a.selection,s=(o,c)=>{const f=t.formula(o,c);return f&&f.t==="array"&&f.ref?L(f.ref):null};let n=s(e,l);if(!n&&i.engine?.spillMaster){const o=i.engine.spillMaster(t,e,l);o&&(n=s(o.row,o.col)??null)}return n}function se(r,i,a={}){const{book:t,grid:e,controller:l,shell:s}=r,{sheet:n}=t,{row:o,col:c}=e.selection,f=P(r),m={numbers:a.numbers!==!1,text:a.text!==!1,logicals:a.logicals!==!1,errors:a.errors!==!1};let d=[];switch(i){case"notes":{const g=new w,p=[...n.comments?.keys()??[]].map(b=>[b%x,Math.floor(b/x)]).sort((b,y)=>b[0]-y[0]||b[1]-y[1]);for(const[b,y]of p)g.add(b,y,y);d=g.ranges;break}case"constants":d=G(n,f,g=>!(g&S)&&_(g,m)).ranges;break;case"formulas":d=G(n,f,g=>g&S&&_(g,m)).ranges;break;case"blanks":d=Z(n,f).ranges;break;case"region":{d=[r.commands._currentRegion(o,c)??{r0:o,c0:c,r1:o,c1:c}];break}case"array":{const g=oe(r);d=g?[g]:[];break}case"objects":{const p=(r.objects?._state?.(n)?.objects??[]).filter(b=>!b.hidden&&b.kind!=="foreign");if(p.length>0){r.objects.select(p[0]);for(const b of p.slice(1))r.objects.select(b,{add:!0});s.setStatus(M("{count} objects selected.",{count:p.length}))}else s.setStatus(M("There are no objects on this sheet."));return}case"rowDiff":d=Q(t,n,f,c).ranges;break;case"colDiff":d=Y(t,n,f,o).ranges;break;case"precedents":case"precedentsAll":d=W(t,n,e.selection.ranges,i==="precedentsAll");break;case"dependents":case"dependentsAll":d=J(t,n,e.selection.ranges,i==="dependentsAll");break;case"lastCell":d=[{r0:Math.max(n.maxRow,0),c0:Math.max(n.maxCol,0),r1:Math.max(n.maxRow,0),c1:Math.max(n.maxCol,0)}];break;case"visible":d=ee(n,e.selection.ranges.length===1&&e.selection.ranges[0].r0===e.selection.ranges[0].r1&&e.selection.ranges[0].c0===e.selection.ranges[0].c1?f:e.selection.ranges);break;case"cf":d=te(n,a,o,c);break;case"validation":d=ne(n,a,o,c);break;default:return}if(d.length===0){s.setStatus(M("No cells were found."));return}if(d.length>T){s.setStatus(M("That selection is too large: more than {count} separate areas.",{count:T.toLocaleString("en-US")}));return}const u=d[0],k=$(d,o,c);e.setSelection({ranges:d,row:k?o:u.r0,col:k?c:u.c0}),l.extent={row:u.r1,col:u.c1},k||e.ensureVisible(u.r0,u.c0)}function ce(r){D();const i="bk-special";let a="notes";const t=(p,b,y=!1)=>{const F=h("input",{type:"radio",name:i,value:p,checked:y,on:{change:()=>{a=p,k()}}});return h("label",{class:"dlg-row dlg-check"},F,` ${v("special",b)}`)},e={numbers:h("input",{type:"checkbox",checked:!0}),text:h("input",{type:"checkbox",checked:!0}),logicals:h("input",{type:"checkbox",checked:!0}),errors:h("input",{type:"checkbox",checked:!0})},l=h("input",{type:"radio",name:"bk-depth",checked:!0}),s=h("input",{type:"radio",name:"bk-depth"}),n=h("input",{type:"radio",name:"bk-same",checked:!0}),o=h("input",{type:"radio",name:"bk-same"}),c=(p,b)=>h("label",{class:"dlg-row dlg-check"},p,` ${v("special",b)}`),f=h("div",{class:"bk-special-opts"},c(e.numbers,"Numbers"),c(e.text,"Text"),c(e.logicals,"Logicals"),c(e.errors,"Errors")),m=h("div",{class:"bk-special-opts"},c(l,"Direct only"),c(s,"All levels")),d=h("div",{class:"bk-special-opts"},c(n,"All"),c(o,"Same")),u=h("p",{class:"bk-special-none",textContent:M("There are no options for this selection.")}),k=()=>{f.hidden=a!=="constants"&&a!=="formulas",m.hidden=a!=="precedents"&&a!=="dependents",d.hidden=a!=="cf"&&a!=="validation",u.hidden=!(f.hidden&&m.hidden&&d.hidden)},g=h("div",{class:"bk-special"},h("div",{class:"xl-head dlg-label",textContent:v("special","Select")}),h("div",{class:"bk-grid2"},h("div",{},t("notes","Notes",!0),t("constants","Constants"),t("formulas","Formulas"),t("blanks","Blanks"),t("region","Current region"),t("array","Current array"),t("rowDiff","Row differences"),t("colDiff","Column differences")),h("div",{},t("precedents","Precedents"),t("dependents","Dependents"),t("lastCell","Last cell"),t("visible","Visible cells only"),t("objects","Objects"),t("cf","Conditional formats"),t("validation","Data validation"))),h("hr",{class:"xl-rule"}),h("div",{class:"xl-head dlg-label",textContent:M("Options")}),h("div",{class:"bk-special-low"},f,m,d,u));k(),O(r,v("dlg","Go To Special"),g,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{let p=a;(p==="precedents"||p==="dependents")&&s.checked&&(p+="All"),se(r,p,{numbers:e.numbers.checked,text:e.text.checked,logicals:e.logicals.checked,errors:e.errors.checked,same:o.checked})}}],{width:334,className:"xl-dlg"})}function he(r){const{book:i,grid:a}=r,t=i.gotoHistory??=[],e=h("select",{class:"dlg-list bk-goto-list",size:8,"aria-label":M("Go to")});for(const o of I(i))e.append(h("option",{value:o.label,textContent:o.label}));for(const o of t.slice().reverse())e.append(h("option",{value:o,textContent:o}));const l=h("input",{class:"dlg-input","aria-label":M("Reference"),spellcheck:!1,value:t[t.length-1]??""});e.addEventListener("change",()=>{l.value=e.value}),e.addEventListener("dblclick",()=>{s()&&n.close()});const s=()=>{const o=z(i,a.selection);return X(r,l.value)?(t[t.length-1]!==o&&t.push(o),t.length>32&&t.shift(),!0):(l.select(),!1)};D();const n=O(r,v("dlg","Go To"),h("div",{class:"dlg-col"},h("div",{class:"dlg-label",textContent:M("Go to:")}),e,h("label",{class:"bk-above"},h("span",{textContent:M("Reference:")}),l)),[{label:"Special…",left:!0,action:()=>{queueMicrotask(()=>ce(r))}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>s()}],{width:326,className:"xl-dlg"});l.focus(),l.select()}export{ce as goToSpecial,he as openGoTo,se as selectSpecial};
|
|
1
|
+
import{el as h,openModal as D}from"../ui/dialogs.js";import{ensureBookCss as L}from"./book-css.js";import{BOOL as U,CHUNK_BITS as v,CHUNK_MASK as $,ERR as q,FORMULA as T,KIND_MASK as N,NUM as H,STR as V}from"../core/sheet.js";import{MAX_COLS as y,MAX_ROWS as j,parseRangeRef as G}from"../core/address.js";import{goToText as X,locationText as z,namedPlaces as P}from"./name-box.js";import{inRanges as S}from"./selection-modes.js";import{t as M,tc as A}from"../i18n/index.js";const O=32768;class C{constructor(){this.ranges=[],this.open=new Map,this.col=-1}add(a,s,e){const n=s*j+e,i=this.open.get(n);if(i&&i.c1===a-1){i.c1=a;return}const t={r0:s,c0:a,r1:e,c1:a};this.open.set(n,t),this.ranges.push(t)}get tooMany(){return this.ranges.length>O}}function Z(r){const{grid:a,book:s}=r,{sheet:e}=s,{ranges:n}=a.selection,i=t=>({r0:t.r0,c0:t.c0,r1:Math.min(t.r1,e.maxRow),c1:Math.min(t.c1,e.maxCol)});if(_(r)){const{r0:t,c0:c}=W(e);return[{r0:t,c0:c,r1:Math.max(t,e.maxRow),c1:Math.max(c,e.maxCol)}]}return n.map(i).filter(t=>t.r0<=t.r1&&t.c0<=t.c1)}function _(r){const{ranges:a}=r.grid.selection;if(a.length!==1)return!1;const s=a[0];if(s.r0===s.r1&&s.c0===s.c1)return!0;const e=r.book.sheet.mergeAt(s.r0,s.c0);return e!=null&&e.r0===s.r0&&e.c0===s.c0&&e.r1===s.r1&&e.c1===s.c1}function W(r){let a=1/0,s=1/0;for(const e of r.rowStyles?.keys()??[])e<a&&(a=e),s=0;for(const e of r.colStyles?.keys()??[])e<s&&(s=e),a=0;for(let e=0;e<=r.maxCol;e++){const n=r.columns[e];if(n!==void 0)for(let i=0;i<n.length&&i<<v<a;i++){const t=n[i];if(t===void 0)continue;const c=i<<v;for(let o=0;o<t.kinds.length&&c+o<a;o++)if(!(t.kinds[o]===0&&(t.styles===null||t.styles[o]===0))){a=c+o,e<s&&(s=e);break}if(s===e)break}}return{r0:a===1/0?0:a,c0:s===1/0?0:s}}function I(r,a,s){const e=new C;for(const n of a)for(let i=n.c0;i<=n.c1;i++){const t=r.columns[i];if(t===void 0)continue;let c=-1;for(let o=n.r0>>>v;o<=n.r1>>>v;o++){const l=t[o],f=o<<v;if(l===void 0){c>=0&&(e.add(i,c,f-1),c=-1);continue}const m=Math.max(n.r0-f,0),u=Math.min(n.r1-f,$);for(let d=m;d<=u;d++){const g=l.kinds[d];g!==0&&s(g,f+d,i,l.values[d])?c<0&&(c=f+d):c>=0&&(e.add(i,c,f+d-1),c=-1)}}c>=0&&e.add(i,c,n.r1)}return e}const K=(r,a)=>{const s=r&N;return s===H&&a.numbers||s===V&&a.text||s===U&&a.logicals||s===q&&a.errors};function J(r,a){const s=new C;for(const e of a)for(let n=e.c0;n<=e.c1&&!s.tooMany;n++){const i=r.columns[n];if(i===void 0){s.add(n,e.r0,e.r1);continue}let t=-1;for(let c=e.r0;c<=e.r1;c++){const o=i[c>>>v];if(o===void 0){t<0&&(t=c);const l=c|$;c=Math.min(l,e.r1);continue}o.kinds[c&$]===0?t<0&&(t=c):t>=0&&(s.add(n,t,c-1),t=-1)}t>=0&&s.add(n,t,e.r1)}return s}const B=(r,a,s)=>{const e=r.rAbs0?r.r0:a+r.r0,n=r.rAbs1?r.r1:a+r.r1,i=r.cAbs0?r.c0:s+r.c0,t=r.cAbs1?r.c1:s+r.c1;return{r0:Math.min(e,n),c0:Math.min(i,t),r1:Math.max(e,n),c1:Math.max(i,t)}};function E(r,a,s,e){return a.formula(s,e)?.tpl??null}function Q(r,a,s,e){const n=new Set,i=[];let t=[];for(const c of s)for(const[o]of a.formulas){const l=Math.floor(o/y),f=o-l*y;l>=c.r0&&l<=c.r1&&f>=c.c0&&f<=c.c1&&t.push([l,f])}for(let c=0;t.length>0&&c<64;c++){const o=[];for(const[l,f]of t){const m=E(r,a,l,f);if(m)for(const u of m.refs){if(u.sheet)continue;const d=B(u,l,f),g=`${d.r0},${d.c0},${d.r1},${d.c1}`;if(!n.has(g)&&(n.add(g),i.push({r0:d.r0,c0:d.c0,r1:Math.min(d.r1,j-1),c1:Math.min(d.c1,y-1)}),!!e))for(const[b]of a.formulas){const p=Math.floor(b/y),k=b-p*y;p>=d.r0&&p<=d.r1&&k>=d.c0&&k<=d.c1&&o.push([p,k])}}}if(!e)break;t=o}return i}function Y(r,a,s,e){const n=new Set;let i=s;for(let o=0;i.length>0&&o<64;o++){const l=[];for(const[f]of a.formulas){if(n.has(f))continue;const m=Math.floor(f/y),u=f-m*y,d=E(r,a,m,u);if(d)for(const g of d.refs){if(g.sheet)continue;const b=B(g,m,u);if(i.some(p=>b.r0<=p.r1&&b.r1>=p.r0&&b.c0<=p.c1&&b.c1>=p.c0)){n.add(f),l.push({r0:m,c0:u,r1:m,c1:u});break}}}if(!e)break;i=l}const t=new Map;for(const o of n){const l=Math.floor(o/y),f=o-l*y;t.has(f)||t.set(f,[]),t.get(f).push(l)}const c=new C;for(const o of[...t.keys()].sort((l,f)=>l-f)){const l=t.get(o).sort((m,u)=>m-u);let f=l[0];for(let m=1;m<=l.length;m++)l[m]!==l[m-1]+1&&(c.add(o,f,l[m-1]),f=l[m])}return c.ranges}function R(r,a,s,e,n,i){const t=a.kind(s,e);return t&T?`f${r.editText(a,s,e).replace(/\$?[A-Z]{1,3}\$?\d+/g,o=>{const l=/^(\$?)([A-Z]+)(\$?)(\d+)$/.exec(o),f=l[2].split("").reduce((m,u)=>m*26+u.charCodeAt(0)-64,0)-1;return`${l[1]?`$${l[2]}`:`C[${f-e+i}]`}${l[3]?`$${l[4]}`:`R[${Number(l[4])-1-s+n}]`}`})}`:`${t&N}:${a.value(s,e)}`}function ee(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){if(t===e)continue;let c=-1;for(let o=i.r0;o<=i.r1;o++){const l=R(r,a,o,t,o,e)!==R(r,a,o,e,o,e);l&&c<0?c=o:!l&&c>=0&&(n.add(t,c,o-1),c=-1)}c>=0&&n.add(t,c,i.r1)}return n}function te(r,a,s,e){const n=new C;for(const i of s)for(let t=i.c0;t<=i.c1;t++){const c=R(r,a,e,t,e,t);let o=-1;for(let l=i.r0;l<=i.r1;l++){const f=l!==e&&R(r,a,l,t,e,t)!==c;f&&o<0?o=l:!f&&o>=0&&(n.add(t,o,l-1),o=-1)}o>=0&&n.add(t,o,i.r1)}return n}function ne(r,a){const s=(n,i,t)=>{const c=[];let o=-1;for(let l=i;l<=t;l++){const f=n.sizeOf(l)>0;f&&o<0?o=l:!f&&o>=0&&(c.push([o,l-1]),o=-1)}return o>=0&&c.push([o,t]),c},e=[];for(const n of a){const i=s(r.rows,n.r0,Math.min(n.r1,Math.max(r.maxRow,n.r0))),t=s(r.cols,n.c0,Math.min(n.c1,Math.max(r.maxCol,n.c0)));for(const[c,o]of i)for(const[l,f]of t)e.push({r0:c,c0:l,r1:o,c1:f})}return e}const F=r=>(r??"").split(/\s+/).map(G).filter(Boolean);function oe(r,{same:a},s,e){const n=[];for(const i of r.cf??[]){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function se(r,{same:a},s,e){const n=[];for(const i of r.validations??[]){const t=F(i.sqref);(!a||S(t,s,e))&&n.push(...t)}return n}function ce(r){const{book:a,grid:s}=r,{sheet:e}=a,{row:n,col:i}=s.selection,t=(o,l)=>{const f=e.formula(o,l);return f&&f.t==="array"&&f.ref?G(f.ref):null};let c=t(n,i);if(!c&&a.engine?.spillMaster){const o=a.engine.spillMaster(e,n,i);o&&(c=t(o.row,o.col)??null)}return c}function re(r,a,s={}){const{book:e,grid:n,controller:i,shell:t}=r,{sheet:c}=e,{row:o,col:l}=n.selection,f=Z(r),m={numbers:s.numbers!==!1,text:s.text!==!1,logicals:s.logicals!==!1,errors:s.errors!==!1};let u=[];switch(a){case"notes":{const b=new C,p=_(r),k=[...c.comments?.keys()??[]].map(x=>[x%y,Math.floor(x/y)]).filter(([x,w])=>p||S(n.selection.ranges,w,x)).sort((x,w)=>x[0]-w[0]||x[1]-w[1]);for(const[x,w]of k)b.add(x,w,w);u=b.ranges;break}case"constants":u=I(c,f,b=>!(b&T)&&K(b,m)).ranges;break;case"formulas":u=I(c,f,b=>b&T&&K(b,m)).ranges;break;case"blanks":u=J(c,f).ranges;break;case"region":{u=[r.commands._currentRegion(o,l)??{r0:o,c0:l,r1:o,c1:l}];break}case"array":{const b=ce(r);u=b?[b]:[];break}case"objects":{const p=(r.objects?._state?.(c)?.objects??[]).filter(k=>!k.hidden&&k.kind!=="foreign");if(p.length>0){r.objects.select(p[0]);for(const k of p.slice(1))r.objects.select(k,{add:!0});t.setStatus(M("{count} objects selected.",{count:p.length}))}else t.setStatus(M("There are no objects on this sheet."));return}case"rowDiff":u=ee(e,c,f,l).ranges;break;case"colDiff":u=te(e,c,f,o).ranges;break;case"precedents":case"precedentsAll":u=Q(e,c,n.selection.ranges,a==="precedentsAll");break;case"dependents":case"dependentsAll":u=Y(e,c,n.selection.ranges,a==="dependentsAll");break;case"lastCell":u=[{r0:Math.max(c.maxRow,0),c0:Math.max(c.maxCol,0),r1:Math.max(c.maxRow,0),c1:Math.max(c.maxCol,0)}];break;case"visible":u=ne(c,n.selection.ranges.length===1&&n.selection.ranges[0].r0===n.selection.ranges[0].r1&&n.selection.ranges[0].c0===n.selection.ranges[0].c1?f:n.selection.ranges);break;case"cf":u=oe(c,s,o,l);break;case"validation":u=se(c,s,o,l);break;default:return}if(u.length===0){t.setStatus(M("No cells were found."));return}if(u.length>O){t.setStatus(M("That selection is too large: more than {count} separate areas.",{count:O.toLocaleString("en-US")}));return}const d=u[0],g=S(u,o,l);n.setSelection({ranges:u,row:g?o:d.r0,col:g?l:d.c0}),i.extent={row:d.r1,col:d.c1},g||n.ensureVisible(d.r0,d.c0)}function le(r){L();const a="bk-special";let s="notes";const e=(p,k,x=!1)=>{const w=h("input",{type:"radio",name:a,value:p,checked:x,on:{change:()=>{s=p,g()}}});return h("label",{class:"dlg-row dlg-check"},w,` ${A("special",k)}`)},n={numbers:h("input",{type:"checkbox",checked:!0}),text:h("input",{type:"checkbox",checked:!0}),logicals:h("input",{type:"checkbox",checked:!0}),errors:h("input",{type:"checkbox",checked:!0})},i=h("input",{type:"radio",name:"bk-depth",checked:!0}),t=h("input",{type:"radio",name:"bk-depth"}),c=h("input",{type:"radio",name:"bk-same",checked:!0}),o=h("input",{type:"radio",name:"bk-same"}),l=(p,k)=>h("label",{class:"dlg-row dlg-check"},p,` ${A("special",k)}`),f=h("div",{class:"bk-special-opts"},l(n.numbers,"Numbers"),l(n.text,"Text"),l(n.logicals,"Logicals"),l(n.errors,"Errors")),m=h("div",{class:"bk-special-opts"},l(i,"Direct only"),l(t,"All levels")),u=h("div",{class:"bk-special-opts"},l(c,"All"),l(o,"Same")),d=h("p",{class:"bk-special-none",textContent:M("There are no options for this selection.")}),g=()=>{f.hidden=s!=="constants"&&s!=="formulas",m.hidden=s!=="precedents"&&s!=="dependents",u.hidden=s!=="cf"&&s!=="validation",d.hidden=!(f.hidden&&m.hidden&&u.hidden)},b=h("div",{class:"bk-special"},h("div",{class:"xl-head dlg-label",textContent:A("special","Select")}),h("div",{class:"bk-grid2"},h("div",{},e("notes","Notes",!0),e("constants","Constants"),e("formulas","Formulas"),e("blanks","Blanks"),e("region","Current region"),e("array","Current array"),e("rowDiff","Row differences"),e("colDiff","Column differences")),h("div",{},e("precedents","Precedents"),e("dependents","Dependents"),e("lastCell","Last cell"),e("visible","Visible cells only"),e("objects","Objects"),e("cf","Conditional formats"),e("validation","Data validation"))),h("hr",{class:"xl-rule"}),h("div",{class:"xl-head dlg-label",textContent:M("Options")}),h("div",{class:"bk-special-low"},f,m,u,d));g(),D(r,A("dlg","Go To Special"),b,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{let p=s;(p==="precedents"||p==="dependents")&&t.checked&&(p+="All"),re(r,p,{numbers:n.numbers.checked,text:n.text.checked,logicals:n.logicals.checked,errors:n.errors.checked,same:o.checked})}}],{width:334,className:"xl-dlg"})}function pe(r){const{book:a,grid:s}=r,e=a.gotoHistory??=[],n=h("select",{class:"dlg-list bk-goto-list",size:8,"aria-label":M("Go to")});for(const o of P(a))n.append(h("option",{value:o.label,textContent:o.label}));for(const o of e.slice().reverse())n.append(h("option",{value:o,textContent:o}));const i=h("input",{class:"dlg-input","aria-label":M("Reference"),spellcheck:!1,value:e[e.length-1]??""});n.addEventListener("change",()=>{i.value=n.value}),n.addEventListener("dblclick",()=>{t()&&c.close()});const t=()=>{const o=z(a,s.selection);return X(r,i.value)?(e[e.length-1]!==o&&e.push(o),e.length>32&&e.shift(),!0):(i.select(),!1)};L();const c=D(r,A("dlg","Go To"),h("div",{class:"dlg-col"},h("div",{class:"dlg-label",textContent:M("Go to:")}),n,h("label",{class:"bk-above"},h("span",{textContent:M("Reference:")}),i)),[{label:"Special…",left:!0,action:()=>{queueMicrotask(()=>le(r))}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>t()}],{width:326,className:"xl-dlg"});i.focus(),i.select()}export{le as goToSpecial,pe as openGoTo,re as selectSpecial};
|
package/cells/name-box.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{icon as w}from"../ui/icons.js";import{cellRef as C,MAX_COLS as
|
|
1
|
+
import{icon as w}from"../ui/icons.js";import{cellRef as N,isValidName as C,MAX_COLS as S,MAX_ROWS as E,parseRangeRef as L,rangeRef as B,sheetPrefix as p}from"../core/address.js";import{viewGet as M,viewOf as y}from"./book-view.js";import{layoutApp as R}from"./view-options.js";import{t as d}from"../i18n/index.js";import{bindText as x}from"../i18n/dom.js";const T=t=>t.replace(/^'|'$/g,"").replace(/''/g,"'");function b(t,n){const s=/^(?:('(?:[^']|'')+'|[^!'(),=+\-*/ ]+)!)?(\$?[A-Za-z]{0,3}\$?\d*(?::\$?[A-Za-z]{0,3}\$?\d*)?)$/.exec(n.trim());if(!s||!s[2])return null;const e=L(s[2]);if(!e)return null;const o=s[1]?t.sheets.find(r=>r.name.toLowerCase()===T(s[1]).toLowerCase()):t.sheet;return o?{sheet:o,range:e}:null}function f(t,n){return n.cachedFor!==n.text&&(n.cachedFor=n.text,n.cachedTarget=b(t,n.text)),n.cachedTarget}const v=(t,n)=>t.r0===n.r0&&t.c0===n.c0&&t.r1===n.r1&&t.c1===n.c1;function q(t,n,s){const{engine:e}=t;if(!e||s.ranges.length!==1)return null;const o=s.ranges[0];if(e.names.size>0)for(const r of e.names.values()){if(r.hidden)continue;const a=f(t,r);if(a&&a.sheet===n&&v(a.range,o))return r.name}if(e.tables.size>0){for(const r of e.tables.values())if(r.sheet===n&&v(r,o))return r.name}return null}function k(t){const{engine:n}=t,s=[];if(!n)return s;for(const[e,o]of n.names){if(o.hidden)continue;const r=e.indexOf("!"),a=r>=0?Number(e.slice(0,r)):-1;a>=0&&a!==t.activeSheet||f(t,o)&&s.push({label:o.name??e,kind:"name"})}for(const e of n.tables.values())s.push({label:e.name,kind:"table"});return s.sort((e,o)=>e.label.localeCompare(o.label))}function A(t,n){const{engine:s}=t,e=n.trim().toUpperCase();if(!s||!e)return null;const o=s.names.get(`${t.activeSheet}!${e}`)??s.names.get(e);if(o)return f(t,o);for(const r of s.tables.values())if(r.name.toUpperCase()===e)return{sheet:r.sheet,range:{r0:r.r0,c0:r.c0,r1:r.r1,c1:r.c1}};return null}function W(t){const n=/^R(\d+)C(\d+)(?::R(\d+)C(\d+))?$/i.exec(t.trim());if(!n)return null;const s=Number(n[1])-1,e=Number(n[2])-1,o=n[3]?Number(n[3])-1:s,r=n[4]?Number(n[4])-1:e;return s<0||e<0||o>=E||r>=S?null:{r0:Math.min(s,o),c0:Math.min(e,r),r1:Math.max(s,o),c1:Math.max(e,r)}}function z(t,n){const{book:s,grid:e}=t,o=e.selection.ranges[e.selection.ranges.length-1],r=(l,c)=>N(l,c).replace(/^([A-Z]+)(\d+)$/,"$$$1$$$2"),a=`${p(s.sheet.name)}${r(o.r0,o.c0)}${o.r0===o.r1&&o.c0===o.c1?"":`:${r(o.r1,o.c1)}`}`;s.engine.names.set(n.toUpperCase(),{text:a,name:n}),s.engine.nameTemplates.clear(),s.namesChanged=!0,s.dirty=!0,s.engine.rebuild(),t.shell.setStatus(d("Defined {name} as {refers}",{name:n,refers:a})),t.controller.syncNameBox()}function D(t,n,{allowCreate:s=!1}={}){const{book:e,grid:o,controller:r}=t,a=n.split(/[,;]/).map(i=>i.trim()).filter(Boolean);if(a.length===0)return r.syncNameBox(),!1;const l=[];for(const i of a){const h=W(i),g=h?{sheet:e.sheet,range:h}:b(e,i)??A(e,i);if(!g){const $=e.engine?.names.has(`${e.activeSheet}!${i.toUpperCase()}`)||e.engine?.names.has(i.toUpperCase());return s&&!$&&a.length===1&&C(i)?(z(t,i),!0):(t.shell.setStatus(d('"{text}" is not a valid reference or name',{text:i})),r.syncNameBox(),!1)}l.push(g)}const{sheet:c}=l[0];if(c!==e.sheet){const i=e.sheets.indexOf(c);if(c.hidden||i<0)return t.shell.setStatus(d('"{name}" is hidden',{name:c.name})),!1;e.selectedSheets&&!e.selectedSheets.has(c)&&(e.selectedSheets=null),t.switchSheet(i)}const u=l.filter(i=>i.sheet===c).map(i=>i.range),m=u[u.length-1];return o.setSelection({ranges:u,row:m.r0,col:m.c0}),r.extent={row:m.r1,col:m.c1},o.ensureVisible(m.r0,m.c0),r.syncNameBox(),!0}function V(t,n){return`${p(t.sheet.name)}${n.ranges.map(B).join(",")}`}function _(t){const n=t.el("name-box")?.parentElement;if(!n||n.querySelector(".bk-name-drop"))return;const s=document.createElement("button");s.className="bk-name-drop",x(s,{title:"Names and tables","aria-label":"Names and tables"}),s.innerHTML=w("caret",8),s.addEventListener("pointerdown",r=>r.preventDefault()),s.addEventListener("click",()=>{const r=n.getBoundingClientRect(),a=k(t.book).map(l=>[l.label,()=>D(t,l.label),{raw:!0}]);t.ribbon.openMenuAt(r.left,r.bottom+2,{items:a.length?a:[["No names defined",()=>{},{disabled:!0}]]})});const e=document.createElement("div");e.className="bk-name-grip",x(e,{title:"Drag to resize the name box"}),e.addEventListener("pointerdown",r=>{r.preventDefault(),e.setPointerCapture(r.pointerId);const a=r.clientX,l=n.getBoundingClientRect().width,c=m=>{const i=Math.max(60,Math.min(window.innerWidth*.6,l+m.clientX-a));n.style.width=`${i}px`,y(t.book).nameBoxWidth=Math.round(i)},u=()=>{e.removeEventListener("pointermove",c),e.removeEventListener("pointerup",u),R(t)};e.addEventListener("pointermove",c),e.addEventListener("pointerup",u)}),n.style.width=`${M(t.book,"nameBoxWidth")}px`,n.append(s,e);const o=t.el("name-box");o.style.flex="1",o.style.minWidth="0",o.addEventListener("pointerdown",r=>{r.button!==0||document.activeElement===o||(r.preventDefault(),o.focus(),o.select())}),o.addEventListener("blur",()=>{t.controller.isEditing||t.controller.syncNameBox()})}export{D as goToText,_ as installNameBox,V as locationText,q as nameForSelection,k as namedPlaces};
|
package/cells/options.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{el as o,openModal as b}from"../ui/dialogs.js";import{t as
|
|
1
|
+
import{el as o,openModal as b}from"../ui/dialogs.js";import{t as r}from"../i18n/index.js";const p="sheets.editOptions",g={dragDrop:!0,dragMerge:!1,dragHeaders:"none",alertOverwrite:!0,pasteButton:!0,fillButton:!0,skipHidden:!1,editInCell:!0,editOnSelect:!1,selectAllOnEdit:!1,autoPercent:!0,autoComplete:!0,numbersOverflow:!1,tableDragShift:!1,copyHeaders:"none",errorChecking:!0,errNumberAsText:!0};let n=null;function i(){if(n)return n;let t=null;try{t=JSON.parse(localStorage.getItem(p))}catch{t=null}return n={...g,...t&&typeof t=="object"?t:{}},n}function v(t,e){return t?.optionOverrides?.[e]??i()[e]}function f(t,e){i()[t]=e;try{localStorage.setItem(p,JSON.stringify(n))}catch{}}function m(t){const e=(l,a)=>{const u=o("input",{type:"checkbox",checked:i()[l],"aria-label":r(a)});return u.dataset.option=l,o("label",{class:"dlg-row"},u,` ${r(a)}`)},s=o("select",{class:"dlg-input","aria-label":r("Copy takes headers")},...[["None","none"],["Row headers","row"],["Column headers","col"],["All","all"]].map(([l,a])=>o("option",{value:a,textContent:r(l)})));s.value=i().copyHeaders;const c=o("input",{type:"checkbox",checked:t.book.sheet.noCellOverflow!==!0,"aria-label":r("Overflow")}),h=o("label",{class:"dlg-row"},c,` ${r("Text overflows into empty cells on this sheet")}`),d=o("div",{},e("editInCell","Allow editing directly in cells"),e("editOnSelect","Start editing as soon as a cell is selected"),e("selectAllOnEdit","Select all the text when editing starts"),e("autoPercent","Enable automatic percent entry"),e("autoComplete","Enable AutoComplete for cell values"),e("numbersOverflow","Let numbers too wide for a column spill into empty cells (not in Excel)"),e("dragDrop","Enable fill handle and cell drag-and-drop"),e("alertOverwrite","Alert before overwriting cells"),e("pasteButton","Show Paste Options button after content is pasted"),e("fillButton","Show Auto Fill Options button after a fill"),e("skipHidden","Paste skips hidden rows and columns"),e("tableDragShift","Dragging whole table rows shifts cells instead of overwriting"),o("label",{class:"dlg-row"},`${r("Copy takes headers:")} `,s),h);b(t,"Editing Options",d,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{for(const l of d.querySelectorAll("input[data-option]"))f(l.dataset.option,l.checked);f("copyHeaders",s.value),t.book.sheet.noCellOverflow=c.checked?void 0:!0,t.book.dirty=!0,t.grid.invalidate()}}],{width:420})}export{i as editOptions,m as openEditOptions,v as optionFor,f as setEditOption};
|
package/cells/view-options.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{el as c,openModal as M}from"../ui/dialogs.js";import{viewGet as i,viewSet as P}from"./book-view.js";import{ensureBookCss as U}from"./book-css.js";import{t as b}from"../i18n/index.js";function F(e){const t=e.el("app"),{book:o}=e;if(i(o,"showFormulaBar")&&i(o,"showStatusBar")&&!i(o,"ribbonMinimized")&&!i(o,"formulaBarExpanded")&&i(o,"showTabs")&&i(o,"tabPosition")==="bottom"){t.style.removeProperty("grid-template-rows");return}const s=d=>`calc(${d}px * var(--ui-scale))`,n={titlebar:s(38),tabs:s(28),ribbon:"auto","formula-bar":i(o,"formulaBarExpanded")?"auto":s(26),"ds-bar-host":"auto",workspace:"minmax(0, 1fr)",sheetbar:s(24),statusbar:s(28)},r=[];for(const d of t.children)getComputedStyle(d).display!=="none"&&r.push(n[d.id]??"auto");t.style.gridTemplateRows=r.join(" ")}function V(e){const{book:t,grid:o}=e,l=e.el("app");l.classList.toggle("no-formula-bar",!i(t,"showFormulaBar")),l.classList.toggle("bk-fx-expanded",i(t,"formulaBarExpanded"));const s=e.el("statusbar");s.hidden=!i(t,"showStatusBar"),e.el("ribbon").hidden=i(t,"ribbonMinimized");const n=i(t,"widgetBorder");l.style.outline=n?`${n.width??1}px ${n.style??"solid"} ${n.color??"currentColor"}`:"",l.style.outlineOffset=n?`-${n.width??1}px`:"";const r=e.el("name-box")?.parentElement;r&&(r.style.width=`${i(t,"nameBoxWidth")}px`),o.focusCell=i(t,"focusCell");const d=i(t,"selectionBackColor"),h=i(t,"selectionBorderColor"),f=d||h?{...d?{selectionFill:`${d}38`}:{},...h?{accent:h}:{}}:null;(f||o.themeOverride)&&(o.themeOverride=f,o.setMode(o.mode)),F(e)}function $(e){const{book:t,grid:o}=e,l=o.host,s=i(t,"scrollbarShowMax"),n=i(t,"scrollbarMaxAlign"),r=i(t,"scrollByCell"),d=i(t,"scrollPixel"),h=r||d!==1,f=i(t,"scrollAppearance"),g=f==="skin";o.scrollOpts=s||n||h||g?{showMax:s,maxAlign:n,custom:h,byCell:r,pixel:d,arrows:g}:null,g&&W(o);for(const a of[o.barV,o.barH])a.track.classList.toggle("bk-has-ends",g);o.scrollByCell=r,l.classList.toggle("bk-sb-skin",f==="skin"),l.classList.toggle("bk-sb-mobile",f==="mobile");const m=i(t,"scrollColors");l.classList.toggle("bk-sb-colors",!!m),e.el("sheetbar")?.classList.toggle("bk-sb-colors",!!m);for(const a of[l,e.el("sheetbar")])a&&(m?.thumb?a.style.setProperty("--bk-sb-thumb",m.thumb):a.style.removeProperty("--bk-sb-thumb"),m?.track?a.style.setProperty("--bk-sb-track",m.track):a.style.removeProperty("--bk-sb-track"));o.barV.track.hidden=!i(t,"showVScroll"),o.barH.track.hidden=!i(t,"showHScroll"),o.scrollTo(o.scrollX,o.scrollY),o.invalidateTop()}let T=null;function J(e){T=e}function N(e){U(),V(e),T?.(e),$(e),F(e),e.book.allowUndo=i(e.book,"allowUndo")}function w(e,t,o){P(e.book,t,o),N(e),e.shell.syncTitle(),e.ribbon.render()}const Q=e=>w(e,"ribbonMinimized",!i(e.book,"ribbonMinimized")),ee=e=>w(e,"formulaBarExpanded",!i(e.book,"formulaBarExpanded"));function L(e,t,o){const{book:l,grid:s}=e;l.sheet[t]=o,l.sheet.viewChanged=!0,l.dirty=!0,s[t]=o,s.invalidate(),e.shell.syncTitle(),e.ribbon.render()}const G=(e,t)=>L(e,"hideHeadings",!t),R=(e,t)=>L(e,"hideOutline",!t),oe=e=>R(e,e.book.sheet.hideOutline===!0);function I(e,t){const{sheet:o}=e.book;o.hideZeros=!t,o.viewChanged=!0,e.book.dirty=!0,e.grid.invalidate()}function D(e,t,o){const{sheet:l}=e.book,s={horizontal:l.gridlineAxes?.horizontal!==!1,vertical:l.gridlineAxes?.vertical!==!1,[t]:o};l.gridlineAxes=s.horizontal&&s.vertical?void 0:s,e.book.dirty=!0,e.grid.invalidate()}function K(e,t){const{sheet:o}=e.book;o.gridColorId=t,o.viewChanged=!0,e.book.dirty=!0,e.grid.invalidate()}function H(e,t,o){const{sheet:l}=e,s=e._frozen();if(t==="row"){const n=l.rows;let r=n.indexAt(e.scrollY+s.h)+o;for(;r>l.frozenRows&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(e.scrollX,n.offsetOf(Math.max(l.frozenRows,r))-s.h)}else{const n=l.cols;let r=n.indexAt(e.scrollX+s.w)+o;for(;r>l.frozenCols&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(n.offsetOf(Math.max(l.frozenCols,r))-s.w,e.scrollY)}}function W(e){if(e.barEnds)return;e.barEnds=!0;const t=(o,l,s)=>{const n=document.createElement("button");n.type="button",n.className=`sb-end ${s?"sb-end-start":"sb-end-stop"}`,n.tabIndex=-1,n.setAttribute("aria-label",b(l==="row"?s?"Scroll up one row":"Scroll down one row":s?"Scroll left one column":"Scroll right one column")),n.addEventListener("pointerdown",r=>{r.preventDefault(),r.stopPropagation();const d=(s?-1:1)*(l==="col"&&e.rtl?-1:1);H(e,l,d);let h=setTimeout(()=>{h=setInterval(()=>H(e,l,d),60)},350);const f=()=>{clearTimeout(h),clearInterval(h),window.removeEventListener("pointerup",f,!0)};window.addEventListener("pointerup",f,!0)}),o.track.append(n)};t(e.barV,"row",!0),t(e.barV,"row",!1),t(e.barH,"col",!0),t(e.barH,"col",!1)}function te(e,t){const o=e.scrollOpts,l=t.deltaMode===1?16:t.deltaMode===2?e.cssH:1;let s=(e.rtl?-t.deltaX:t.deltaX)*l,n=t.deltaY*l;if(t.shiftKey&&s===0&&(s=n,n=0),!o.byCell){e.scrollTo(e.scrollX+s*o.pixel/e.zoom,e.scrollY+n*o.pixel/e.zoom);return}const{sheet:r}=e,d=e._frozen(),h=e.wheelAcc??={x:0,y:0};h.x+=s*o.pixel,h.y+=n*o.pixel;const f=p=>Math.trunc(p/16),g=(p,S,B)=>{let O=S;const E=Math.sign(B);for(let z=Math.abs(B);z>0;z--){let C=O+E;for(;C>=0&&C<p.count&&p.sizeOf(C)===0;)C+=E;if(C<0||C>=p.count)break;O=C}return O};let{scrollX:m,scrollY:a}=e;const x=f(h.y);x!==0&&(h.y-=x*16,a=r.rows.offsetOf(g(r.rows,r.rows.indexAt(a+d.h),x))-d.h);const k=f(h.x);k!==0&&(h.x-=k*16,m=r.cols.offsetOf(g(r.cols,r.cols.indexAt(m+d.w),k))-d.w),e.scrollTo(m,a)}function le(e){e.addSheet()}function se(e,t){const{book:o}=e,l=o.sheets.length;let s=o.activeSheet+t;for(;s>=0&&s<l&&o.sheets[s].hidden;)s+=t;s<0||s>=l||(o.selectedSheets&&!o.selectedSheets.has(o.sheets[s])&&(o.selectedSheets=null),e.switchSheet(s))}function re(e,t){const o=e.view?.fixedDecimal;return!o||!/^[-+]?\d+$/.test(t)?t:String(Number(t)/10**o)}function u(e,t,o){const l=c("input",{type:"checkbox",checked:t});return l.addEventListener("change",()=>o(l.checked)),c("label",{class:"dlg-row dlg-check"},l,` ${b(e)}`)}function A(e,t,o,l){const s=c("select",{class:"dlg-input","aria-label":b(e)});for(const[n,r]of t)s.append(c("option",{value:r,textContent:b(n)}));return s.value=o,s.addEventListener("change",()=>l(s.value)),c("label",{class:"dlg-row"},`${b(e)} `,s)}const v=(e,t)=>c("label",{class:"dlg-row"},`${b(e)} `,t),y=e=>c("div",{class:"bk-section",textContent:b(e)}),X=[["Automatic",""],["Black","8"],["Dark Gray","23"],["Gray","22"],["Red","10"],["Green","17"],["Blue","12"],["Teal","21"],["Purple","20"],["Orange","53"]];function ne(e){const{book:t}=e,{sheet:o}=t,l=r=>i(t,r),s=r=>d=>w(e,r,d),n=c("div",{},y("Show"),c("div",{class:"bk-grid2"},u("Formula bar",l("showFormulaBar"),s("showFormulaBar")),u("Status bar",l("showStatusBar"),s("showStatusBar")),u("Sheet tabs",l("showTabs"),s("showTabs")),u("Horizontal scroll bar",l("showHScroll"),s("showHScroll")),u("Vertical scroll bar",l("showVScroll"),s("showVScroll")),u("Ribbon",!l("ribbonMinimized"),r=>w(e,"ribbonMinimized",!r))),y("In this sheet"),c("div",{class:"bk-grid2"},u("Headings",o.hideHeadings!==!0,r=>G(e,r)),u("Gridlines",o.showGridlines,()=>e.commands.toggleGridlines()),u("Outline symbols",o.hideOutline!==!0,r=>R(e,r)),u("Zero values",o.hideZeros!==!0,r=>I(e,r))),A("Gridline color:",X,o.gridColorId===null||o.gridColorId===void 0?"":String(o.gridColorId),r=>K(e,r===""?null:Number(r))),c("div",{class:"bk-grid2"},u("Horizontal gridlines",o.gridlineAxes?.horizontal!==!1,r=>D(e,"horizontal",r)),u("Vertical gridlines",o.gridlineAxes?.vertical!==!1,r=>D(e,"vertical",r))),y("Scrolling"),A("Scroll bars:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],l("scrollAppearance"),s("scrollAppearance")),c("div",{class:"dlg-row"},c("button",{type:"button",class:"dlg-btn",textContent:b("Scroll Bars and Border…"),on:{click:()=>Z(e)}})),c("div",{class:"bk-grid2"},u("Scroll by whole rows and columns",l("scrollByCell"),s("scrollByCell")),u("Scroll bars span the whole sheet",l("scrollbarShowMax"),s("scrollbarShowMax")),u("End scrolling at the last used cell",l("scrollbarMaxAlign"),s("scrollbarMaxAlign"))),v("Wheel speed:",(()=>{const r=c("input",{class:"dlg-input short",type:"number",min:.25,max:20,step:.25,value:l("scrollPixel")});return r.addEventListener("change",()=>w(e,"scrollPixel",Math.max(.25,Math.min(20,Number(r.value)||1)))),r})()),y("Tab strip"),A("Position:",[["Bottom","bottom"],["Top","top"],["Left","left"],["Right","right"]],l("tabPosition"),s("tabPosition")),c("div",{class:"bk-grid2"},u("New sheet button",l("newTab"),s("newTab")),u("Navigation arrows",l("tabNav"),s("tabNav")),u("Sheets can be reordered",l("allowSheetReorder"),s("allowSheetReorder")),u("Sheets can be renamed",l("tabEditable"),s("tabEditable"))),A("All sheets button:",[["When needed","auto"],["Always","show"],["Never","hide"]],l("allSheets"),s("allSheets")));M(e,"View Options",c("div",{class:"bk-scroll"},n),[{label:"OK",primary:!0}],{width:480})}function Z(e){const{book:t}=e,o=a=>i(t,a),l=(a,x,k,p)=>{const S=c("input",{type:"checkbox",checked:!!x,"aria-label":b("Use {name}",{name:b(a)})}),B=c("input",{type:"color",class:"dlg-color",value:x??k,"aria-label":b(a)}),O=()=>p(S.checked?B.value.toUpperCase():null);return S.addEventListener("change",O),B.addEventListener("input",()=>{S.checked=!0,O()}),c("label",{class:"dlg-row"},S,` ${b(a)} `,B)},s=()=>o("scrollColors")??{},n=a=>x=>{const k={...s(),[a]:x};k[a]||delete k[a],w(e,"scrollColors",Object.keys(k).length?k:null)},r=()=>o("widgetBorder"),d=c("input",{type:"checkbox",checked:!!r(),"aria-label":b("Border around the workbook")}),h=c("select",{class:"dlg-input","aria-label":b("Border style")});for(const[a,x]of[["solid","line|Solid"],["dashed","line|Dashed"],["dotted","line|Dotted"],["double","line|Double"]])h.append(c("option",{value:a,textContent:b(x)}));h.value=r()?.style??"solid";const f=c("input",{class:"dlg-input short",type:"number",min:1,max:12,value:r()?.width??1,"aria-label":b("Border width")}),g=c("input",{type:"color",class:"dlg-color",value:r()?.color??"#808080","aria-label":b("Border color")}),m=()=>w(e,"widgetBorder",d.checked?{style:h.value,width:Math.max(1,Math.min(12,Number(f.value)||1)),color:g.value.toUpperCase()}:null);d.addEventListener("change",m);for(const a of[h,f,g])a.addEventListener("input",()=>{d.checked=!0,m()});M(e,"Scroll Bars and Border",c("div",{class:"dlg-col"},y("Scroll bars"),A("Style:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],o("scrollAppearance"),a=>w(e,"scrollAppearance",a)),l("Thumb color",s().thumb,"#808080",n("thumb")),l("Track color",s().track,"#E0E0E0",n("track")),y("Selection"),l("Fill color",o("selectionBackColor"),"#107C41",a=>w(e,"selectionBackColor",a)),l("Border color",o("selectionBorderColor"),"#107C41",a=>w(e,"selectionBorderColor",a)),y("Border around the workbook"),c("label",{class:"dlg-row"},d,` ${b("Show a border")}`),v("Style:",h),v("Width:",f),v("Color:",g)),[{label:"OK",primary:!0}],{width:360})}function ie(e){const{book:t,grid:o}=e,l=i(t,"focusCell")??o.focusCell??{color:"#FFF2CC",colColor:"#FFF2CC",alpha:.35},s=c("input",{type:"checkbox",checked:!!o.focusCell}),n=c("input",{type:"color",class:"dlg-color",value:l.color??"#FFF2CC"}),r=c("input",{type:"color",class:"dlg-color",value:l.colColor??l.color??"#FFF2CC"}),d=c("input",{type:"range",min:5,max:80,value:Math.round((l.alpha??.35)*100),"aria-label":b("Strength")}),h=()=>{w(e,"focusCell",s.checked?{color:n.value.toUpperCase(),colColor:r.value.toUpperCase(),alpha:Number(d.value)/100}:null),o.invalidateTop()};for(const f of[s,n,r,d])f.addEventListener("input",h);M(e,"Focus Cell",c("div",{class:"dlg-col"},c("label",{class:"dlg-row dlg-check"},s,` ${b("Highlight the row and column of the active cell")}`),v("Row color:",n),v("Column color:",r),v("Strength:",d)),[{label:"OK",primary:!0}],{width:360})}function ce(e){const{book:t}=e,o=i(t,"tips"),l=n=>r=>w(e,"tips",{...i(t,"tips"),[n]:r}),s=c("input",{class:"dlg-input short",type:"number",min:0,max:15,value:i(t,"fixedDecimal")});s.addEventListener("change",()=>w(e,"fixedDecimal",Math.max(0,Math.min(15,Math.trunc(Number(s.value)||0))))),M(e,"Editing Options",c("div",{class:"dlg-col"},A("After pressing Return, move:",[["dir|Down","down"],["dir|Right","right"],["dir|Up","up"],["dir|Left","left"],["Don't move","none"]],i(t,"enterDirection"),n=>w(e,"enterDirection",n)),v("Fixed decimal places:",s),u("Cmd over a selected cell takes it out of the selection",i(t,"allowUserDeselect"),n=>w(e,"allowUserDeselect",n)),u("Cmd and the arrow keys take cells out of the selection",i(t,"deselectKeys"),n=>w(e,"deselectKeys",n)),u("Zoom with Cmd and the wheel",i(t,"allowUserZoom"),n=>w(e,"allowUserZoom",n)),u("Keep undo history",i(t,"allowUndo"),n=>w(e,"allowUndo",n)),u("Context menus",i(t,"allowContextMenu"),n=>w(e,"allowContextMenu",n)),y("Tips"),u("Size while resizing",o.resize!==!1,l("resize")),u("Row or column while scrolling",o.scroll!==!1,l("scroll")),u("Value while filling",o.fill!==!1,l("fill")),u("Place while dragging cells",o.drop!==!1,l("drop"))),[{label:"OK",primary:!0}],{width:400})}export{le as addSheetFromUi,N as applyBookView,re as applyFixedDecimal,F as layoutApp,se as nextVisibleSheet,J as onApplyTabs,ce as openEditingOptions,ie as openFocusCellDialog,Z as openScrollbarAndBorder,ne as openViewOptions,D as setGridAxis,K as setGridColor,G as setHeadings,R as setOutlineSymbols,w as setViewOption,I as setZeros,ee as toggleFormulaBarSize,oe as toggleOutlineSymbols,Q as toggleRibbon,te as wheelWithOptions};
|
|
1
|
+
import{el as c,openModal as M}from"../ui/dialogs.js";import{viewGet as i,viewSet as $}from"./book-view.js";import{ensureBookCss as H}from"./book-css.js";import{t as w}from"../i18n/index.js";function F(e){const t=e.el("app"),{book:o}=e;if(i(o,"showFormulaBar")&&i(o,"showStatusBar")&&!i(o,"ribbonMinimized")&&!i(o,"formulaBarExpanded")&&i(o,"showTabs")&&i(o,"tabPosition")==="bottom"){t.style.removeProperty("grid-template-rows");return}const s=d=>`calc(${d}px * var(--ui-scale))`,n={titlebar:s(38),tabs:s(28),ribbon:"auto","formula-bar":i(o,"formulaBarExpanded")?"auto":s(26),"ds-bar-host":"auto",workspace:"minmax(0, 1fr)",sheetbar:s(24),statusbar:s(28)},r=[],b=d=>{for(const h of d.children){const{display:m}=getComputedStyle(h);m==="none"||getComputedStyle(h).position==="absolute"||(m==="contents"?b(h):r.push(n[h.id]??"auto"))}};b(t),t.style.gridTemplateRows=r.join(" ")}function U(e){const{book:t,grid:o}=e,l=e.el("app");l.classList.toggle("no-formula-bar",!i(t,"showFormulaBar")),l.classList.toggle("bk-fx-expanded",i(t,"formulaBarExpanded"));const s=e.el("statusbar");s.hidden=!i(t,"showStatusBar"),!i(t,"ribbonMinimized")&&e.ribbon?.peeking&&e.ribbon.peek(!1),e.el("ribbon").hidden=i(t,"ribbonMinimized")&&!e.ribbon?.peeking;const n=i(t,"widgetBorder");l.style.outline=n?`${n.width??1}px ${n.style??"solid"} ${n.color??"currentColor"}`:"",l.style.outlineOffset=n?`-${n.width??1}px`:"";const r=e.el("name-box")?.parentElement;r&&(r.style.width=`${i(t,"nameBoxWidth")}px`),o.focusCell=i(t,"focusCell");const b=i(t,"selectionBackColor"),d=i(t,"selectionBorderColor"),h=b||d?{...b?{selectionFill:`${b}38`}:{},...d?{accent:d}:{}}:null;(h||o.themeOverride)&&(o.themeOverride=h,o.setMode(o.mode)),F(e)}function V(e){const{book:t,grid:o}=e,l=o.host,s=i(t,"scrollbarShowMax"),n=i(t,"scrollbarMaxAlign"),r=i(t,"scrollByCell"),b=i(t,"scrollPixel"),d=r||b!==1,h=i(t,"scrollAppearance"),m=h==="skin";o.scrollOpts=s||n||d||m?{showMax:s,maxAlign:n,custom:d,byCell:r,pixel:b,arrows:m}:null,m&&W(o);for(const a of[o.barV,o.barH])a.track.classList.toggle("bk-has-ends",m);o.scrollByCell=r,l.classList.toggle("bk-sb-skin",h==="skin"),l.classList.toggle("bk-sb-mobile",h==="mobile");const g=i(t,"scrollColors");l.classList.toggle("bk-sb-colors",!!g),e.el("sheetbar")?.classList.toggle("bk-sb-colors",!!g);for(const a of[l,e.el("sheetbar")])a&&(g?.thumb?a.style.setProperty("--bk-sb-thumb",g.thumb):a.style.removeProperty("--bk-sb-thumb"),g?.track?a.style.setProperty("--bk-sb-track",g.track):a.style.removeProperty("--bk-sb-track"));o.barV.track.hidden=!i(t,"showVScroll"),o.barH.track.hidden=!i(t,"showHScroll"),o.scrollTo(o.scrollX,o.scrollY),o.invalidateTop()}let T=null;function J(e){T=e}function N(e){H(),U(e),T?.(e),V(e),F(e),e.book.allowUndo=i(e.book,"allowUndo")}function f(e,t,o){$(e.book,t,o),N(e),e.shell.syncTitle(),e.ribbon.render()}const Q=e=>f(e,"ribbonMinimized",!i(e.book,"ribbonMinimized")),ee=e=>f(e,"formulaBarExpanded",!i(e.book,"formulaBarExpanded"));function L(e,t,o){const{book:l,grid:s}=e;l.sheet[t]=o,l.sheet.viewChanged=!0,l.dirty=!0,s[t]=o,s.invalidate(),e.shell.syncTitle(),e.ribbon.render()}const G=(e,t)=>L(e,"hideHeadings",!t),R=(e,t)=>L(e,"hideOutline",!t),oe=e=>R(e,e.book.sheet.hideOutline===!0);function I(e,t){const{sheet:o}=e.book;o.hideZeros=!t,o.viewChanged=!0,e.book.dirty=!0,e.grid.invalidate()}function P(e,t,o){const{sheet:l}=e.book,s={horizontal:l.gridlineAxes?.horizontal!==!1,vertical:l.gridlineAxes?.vertical!==!1,[t]:o};l.gridlineAxes=s.horizontal&&s.vertical?void 0:s,e.book.dirty=!0,e.grid.invalidate()}function K(e,t){const{sheet:o}=e.book;o.gridColorId=t,o.viewChanged=!0,e.book.dirty=!0,e.grid.invalidate()}function D(e,t,o){const{sheet:l}=e,s=e._frozen();if(t==="row"){const n=l.rows;let r=n.indexAt(e.scrollY+s.h)+o;for(;r>l.frozenRows&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(e.scrollX,n.offsetOf(Math.max(l.frozenRows,r))-s.h)}else{const n=l.cols;let r=n.indexAt(e.scrollX+s.w)+o;for(;r>l.frozenCols&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(n.offsetOf(Math.max(l.frozenCols,r))-s.w,e.scrollY)}}function W(e){if(e.barEnds)return;e.barEnds=!0;const t=(o,l,s)=>{const n=document.createElement("button");n.type="button",n.className=`sb-end ${s?"sb-end-start":"sb-end-stop"}`,n.tabIndex=-1,n.setAttribute("aria-label",w(l==="row"?s?"Scroll up one row":"Scroll down one row":s?"Scroll left one column":"Scroll right one column")),n.addEventListener("pointerdown",r=>{r.preventDefault(),r.stopPropagation();const b=(s?-1:1)*(l==="col"&&e.rtl?-1:1);D(e,l,b);let d=setTimeout(()=>{d=setInterval(()=>D(e,l,b),60)},350);const h=()=>{clearTimeout(d),clearInterval(d),window.removeEventListener("pointerup",h,!0)};window.addEventListener("pointerup",h,!0)}),o.track.append(n)};t(e.barV,"row",!0),t(e.barV,"row",!1),t(e.barH,"col",!0),t(e.barH,"col",!1)}function te(e,t){const o=e.scrollOpts,l=t.deltaMode===1?16:t.deltaMode===2?e.cssH:1;let s=(e.rtl?-t.deltaX:t.deltaX)*l,n=t.deltaY*l;if(t.shiftKey&&s===0&&(s=n,n=0),!o.byCell){e.scrollTo(e.scrollX+s*o.pixel/e.zoom,e.scrollY+n*o.pixel/e.zoom);return}const{sheet:r}=e,b=e._frozen(),d=e.wheelAcc??={x:0,y:0};d.x+=s*o.pixel,d.y+=n*o.pixel;const h=p=>Math.trunc(p/16),m=(p,S,B)=>{let O=S;const z=Math.sign(B);for(let E=Math.abs(B);E>0;E--){let C=O+z;for(;C>=0&&C<p.count&&p.sizeOf(C)===0;)C+=z;if(C<0||C>=p.count)break;O=C}return O};let{scrollX:g,scrollY:a}=e;const k=h(d.y);k!==0&&(d.y-=k*16,a=r.rows.offsetOf(m(r.rows,r.rows.indexAt(a+b.h),k))-b.h);const x=h(d.x);x!==0&&(d.x-=x*16,g=r.cols.offsetOf(m(r.cols,r.cols.indexAt(g+b.w),x))-b.w),e.scrollTo(g,a)}function le(e){e.addSheet()}function se(e,t){const{book:o}=e,l=o.sheets.length;let s=o.activeSheet+t;for(;s>=0&&s<l&&o.sheets[s].hidden;)s+=t;s<0||s>=l||(o.selectedSheets&&!o.selectedSheets.has(o.sheets[s])&&(o.selectedSheets=null),e.switchSheet(s))}function re(e,t){const o=e.view?.fixedDecimal;return!o||!/^[-+]?\d+$/.test(t)?t:String(+`${t}e${-o}`)}function u(e,t,o){const l=c("input",{type:"checkbox",checked:t});return l.addEventListener("change",()=>o(l.checked)),c("label",{class:"dlg-row dlg-check"},l,` ${w(e)}`)}function A(e,t,o,l){const s=c("select",{class:"dlg-input","aria-label":w(e)});for(const[n,r]of t)s.append(c("option",{value:r,textContent:w(n)}));return s.value=o,s.addEventListener("change",()=>l(s.value)),c("label",{class:"dlg-row"},`${w(e)} `,s)}const v=(e,t)=>c("label",{class:"dlg-row"},`${w(e)} `,t),y=e=>c("div",{class:"bk-section",textContent:w(e)}),X=[["Automatic",""],["Black","8"],["Dark Gray","23"],["Gray","22"],["Red","10"],["Green","17"],["Blue","12"],["Teal","21"],["Purple","20"],["Orange","53"]];function ne(e){const{book:t}=e,{sheet:o}=t,l=r=>i(t,r),s=r=>b=>f(e,r,b),n=c("div",{},y("Show"),c("div",{class:"bk-grid2"},u("Formula bar",l("showFormulaBar"),s("showFormulaBar")),u("Status bar",l("showStatusBar"),s("showStatusBar")),u("Sheet tabs",l("showTabs"),s("showTabs")),u("Horizontal scroll bar",l("showHScroll"),s("showHScroll")),u("Vertical scroll bar",l("showVScroll"),s("showVScroll")),u("Ribbon",!l("ribbonMinimized"),r=>f(e,"ribbonMinimized",!r))),y("In this sheet"),c("div",{class:"bk-grid2"},u("Headings",o.hideHeadings!==!0,r=>G(e,r)),u("Gridlines",o.showGridlines,()=>e.commands.toggleGridlines()),u("Outline symbols",o.hideOutline!==!0,r=>R(e,r)),u("Zero values",o.hideZeros!==!0,r=>I(e,r)),u("Page breaks",o.showPageBreaks===!0,r=>{o.showPageBreaks=r,e.grid.invalidate()})),A("Gridline color:",X,o.gridColorId===null||o.gridColorId===void 0?"":String(o.gridColorId),r=>K(e,r===""?null:Number(r))),c("div",{class:"bk-grid2"},u("Horizontal gridlines",o.gridlineAxes?.horizontal!==!1,r=>P(e,"horizontal",r)),u("Vertical gridlines",o.gridlineAxes?.vertical!==!1,r=>P(e,"vertical",r))),y("Scrolling"),A("Scroll bars:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],l("scrollAppearance"),s("scrollAppearance")),c("div",{class:"dlg-row"},c("button",{type:"button",class:"dlg-btn",textContent:w("Scroll Bars and Border…"),on:{click:()=>Z(e)}})),c("div",{class:"bk-grid2"},u("Scroll by whole rows and columns",l("scrollByCell"),s("scrollByCell")),u("Scroll bars span the whole sheet",l("scrollbarShowMax"),s("scrollbarShowMax")),u("End scrolling at the last used cell",l("scrollbarMaxAlign"),s("scrollbarMaxAlign"))),v("Wheel speed:",(()=>{const r=c("input",{class:"dlg-input short",type:"number",min:.25,max:20,step:.25,value:l("scrollPixel")});return r.addEventListener("change",()=>f(e,"scrollPixel",Math.max(.25,Math.min(20,Number(r.value)||1)))),r})()),y("Tab strip"),A("Position:",[["Bottom","bottom"],["Top","top"],["Left","left"],["Right","right"]],l("tabPosition"),s("tabPosition")),c("div",{class:"bk-grid2"},u("New sheet button",l("newTab"),s("newTab")),u("Navigation arrows",l("tabNav"),s("tabNav")),u("Sheets can be reordered",l("allowSheetReorder"),s("allowSheetReorder")),u("Sheets can be renamed",l("tabEditable"),s("tabEditable"))),A("All sheets button:",[["When needed","auto"],["Always","show"],["Never","hide"]],l("allSheets"),s("allSheets")));M(e,"View Options",c("div",{class:"bk-scroll"},n),[{label:"OK",primary:!0}],{width:480})}function Z(e){const{book:t}=e,o=a=>i(t,a),l=(a,k,x,p)=>{const S=c("input",{type:"checkbox",checked:!!k,"aria-label":w("Use {name}",{name:w(a)})}),B=c("input",{type:"color",class:"dlg-color",value:k??x,"aria-label":w(a)}),O=()=>p(S.checked?B.value.toUpperCase():null);return S.addEventListener("change",O),B.addEventListener("input",()=>{S.checked=!0,O()}),c("label",{class:"dlg-row"},S,` ${w(a)} `,B)},s=()=>o("scrollColors")??{},n=a=>k=>{const x={...s(),[a]:k};x[a]||delete x[a],f(e,"scrollColors",Object.keys(x).length?x:null)},r=()=>o("widgetBorder"),b=c("input",{type:"checkbox",checked:!!r(),"aria-label":w("Border around the workbook")}),d=c("select",{class:"dlg-input","aria-label":w("Border style")});for(const[a,k]of[["solid","line|Solid"],["dashed","line|Dashed"],["dotted","line|Dotted"],["double","line|Double"]])d.append(c("option",{value:a,textContent:w(k)}));d.value=r()?.style??"solid";const h=c("input",{class:"dlg-input short",type:"number",min:1,max:12,value:r()?.width??1,"aria-label":w("Border width")}),m=c("input",{type:"color",class:"dlg-color",value:r()?.color??"#808080","aria-label":w("Border color")}),g=()=>f(e,"widgetBorder",b.checked?{style:d.value,width:Math.max(1,Math.min(12,Number(h.value)||1)),color:m.value.toUpperCase()}:null);b.addEventListener("change",g);for(const a of[d,h,m])a.addEventListener("input",()=>{b.checked=!0,g()});M(e,"Scroll Bars and Border",c("div",{class:"dlg-col"},y("Scroll bars"),A("Style:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],o("scrollAppearance"),a=>f(e,"scrollAppearance",a)),l("Thumb color",s().thumb,"#808080",n("thumb")),l("Track color",s().track,"#E0E0E0",n("track")),y("Selection"),l("Fill color",o("selectionBackColor"),"#107C41",a=>f(e,"selectionBackColor",a)),l("Border color",o("selectionBorderColor"),"#107C41",a=>f(e,"selectionBorderColor",a)),y("Border around the workbook"),c("label",{class:"dlg-row"},b,` ${w("Show a border")}`),v("Style:",d),v("Width:",h),v("Color:",m)),[{label:"OK",primary:!0}],{width:360})}function ie(e){const{book:t,grid:o}=e,l=i(t,"focusCell")??o.focusCell??{color:"#FFF2CC",colColor:"#FFF2CC",alpha:.35},s=c("input",{type:"checkbox",checked:!!o.focusCell}),n=c("input",{type:"color",class:"dlg-color",value:l.color??"#FFF2CC"}),r=c("input",{type:"color",class:"dlg-color",value:l.colColor??l.color??"#FFF2CC"}),b=c("input",{type:"range",min:5,max:80,value:Math.round((l.alpha??.35)*100),"aria-label":w("Strength")}),d=()=>{f(e,"focusCell",s.checked?{color:n.value.toUpperCase(),colColor:r.value.toUpperCase(),alpha:Number(b.value)/100}:null),o.invalidateTop()};for(const h of[s,n,r,b])h.addEventListener("input",d);M(e,"Focus Cell",c("div",{class:"dlg-col"},c("label",{class:"dlg-row dlg-check"},s,` ${w("Highlight the row and column of the active cell")}`),v("Row color:",n),v("Column color:",r),v("Strength:",b)),[{label:"OK",primary:!0}],{width:360})}function ce(e){const{book:t}=e,o=i(t,"tips"),l=n=>r=>f(e,"tips",{...i(t,"tips"),[n]:r}),s=c("input",{class:"dlg-input short",type:"number",min:-15,max:15,value:i(t,"fixedDecimal")});s.addEventListener("change",()=>f(e,"fixedDecimal",Math.max(-15,Math.min(15,Math.trunc(Number(s.value)||0))))),M(e,"Editing Options",c("div",{class:"dlg-col"},A("After pressing Return, move:",[["dir|Down","down"],["dir|Right","right"],["dir|Up","up"],["dir|Left","left"],["Don't move","none"]],i(t,"enterDirection"),n=>f(e,"enterDirection",n)),v("Fixed decimal places:",s),u("Cmd over a selected cell takes it out of the selection",i(t,"allowUserDeselect"),n=>f(e,"allowUserDeselect",n)),u("Cmd and the arrow keys take cells out of the selection",i(t,"deselectKeys"),n=>f(e,"deselectKeys",n)),u("Zoom with Cmd and the wheel",i(t,"allowUserZoom"),n=>f(e,"allowUserZoom",n)),u("Keep undo history",i(t,"allowUndo"),n=>f(e,"allowUndo",n)),u("Context menus",i(t,"allowContextMenu"),n=>f(e,"allowContextMenu",n)),y("Tips"),u("Size while resizing",o.resize!==!1,l("resize")),u("Row or column while scrolling",o.scroll!==!1,l("scroll")),u("Value while filling",o.fill!==!1,l("fill")),u("Place while dragging cells",o.drop!==!1,l("drop"))),[{label:"OK",primary:!0}],{width:400})}export{le as addSheetFromUi,N as applyBookView,re as applyFixedDecimal,F as layoutApp,se as nextVisibleSheet,J as onApplyTabs,ce as openEditingOptions,ie as openFocusCellDialog,Z as openScrollbarAndBorder,ne as openViewOptions,P as setGridAxis,K as setGridColor,G as setHeadings,R as setOutlineSymbols,f as setViewOption,I as setZeros,ee as toggleFormulaBarSize,oe as toggleOutlineSymbols,Q as toggleRibbon,te as wheelWithOptions};
|
package/celltypes/dropdowns.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,ERR as st,ERRORS as lt,FORMULA as it,KIND_MASK as V,NUM as ct,STR as ut}from"../core/sheet.js";import{MAX_COLS as dt,MAX_ROWS as pt,parseRangeRef as ft}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as mt,validationAt as ht}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as yt}from"../cells/validation-alert.js";import{t as C}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Xt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const gt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,a){const r=t.kind(n,a)&V;if(r===at)return null;const o=t.value(n,a);return r===ct?o:r===ut?e.strings.get(o):r===ot?o!==0:r===st?lt[o]??"#N/A":null}function vt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:a=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!a&&(o.kind(t,n)&it)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function bt(e,t,n,a,r){const{book:o}=e,{sheet:u}=o,i=ht(u,t,n);if(!i||!i.showError)return!0;const l=xt(a);if(mt(o,u,i,t,n,l.kind??0,l.value,a))return!0;const s=()=>{};return yt(e,i,{retry:s,cancel:s,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:s}),!1}function kt(e,t,n,a,{format:r,overFormula:o=!1}={}){return!H(e,t,n,{overFormula:o})||!bt(e,t,n,a,()=>q(e,t,n,a,r))?!1:q(e,t,n,a,r)}function q(e,t,n,a,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",s=>{o.setInput(s,t,n,a),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const a=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,a};function wt(e,{r0:t,c0:n,r1:a,c1:r}){const o=t===0&&a===pt-1,u=n===0&&r===dt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):a,c1:u?Math.max(e.maxCol,25):r}}function Jt(e,t,n,a){const r=e.sheet,o=t.map(i=>wt(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>gt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const s of o)for(let x=s.r0;x<=s.r1;x++)for(let y=s.c0;y<=s.c1;y++)a===null?l.delete(P(x,y)):l.set(P(x,y),a);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function Qt(e,t={}){if(!W.includes(e))return null;const n={type:e},a=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(a("min"),a("max"),a("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,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const a=e.cellDropdowns;if(!a)return null;const r=e.mergeAt(t,n);return a.get(r?P(r.r0,r.c0):P(t,n))??null}function Zt(e){const{sheet:t,sel:n,grid:a}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=a.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Ct=`
|
|
1
|
+
import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,ERR as st,ERRORS as lt,FORMULA as it,KIND_MASK as V,NUM as ct,STR as ut}from"../core/sheet.js";import{MAX_COLS as dt,MAX_ROWS as pt,parseRangeRef as ft}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as mt,validationAt as ht}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as yt}from"../cells/validation-alert.js";import{t as C}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Xt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const gt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,a){const r=t.kind(n,a)&V;if(r===at)return null;const o=t.value(n,a);return r===ct?o:r===ut?e.strings.get(o):r===ot?o!==0:r===st?lt[o]??"#N/A":null}function vt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:a=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!a&&(o.kind(t,n)&it)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function bt(e,t,n,a,r){const{book:o}=e,{sheet:u}=o,i=ht(u,t,n);if(!i||!i.showError)return!0;const l=xt(a);if(mt(o,u,i,t,n,l.kind??0,l.value,l.text??a))return!0;const s=()=>{};return yt(e,i,{retry:s,cancel:s,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:s}),!1}function kt(e,t,n,a,{format:r,overFormula:o=!1}={}){return!H(e,t,n,{overFormula:o})||!bt(e,t,n,a,()=>q(e,t,n,a,r))?!1:q(e,t,n,a,r)}function q(e,t,n,a,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",s=>{o.setInput(s,t,n,a),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const a=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,a};function wt(e,{r0:t,c0:n,r1:a,c1:r}){const o=t===0&&a===pt-1,u=n===0&&r===dt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):a,c1:u?Math.max(e.maxCol,25):r}}function Jt(e,t,n,a){const r=e.sheet,o=t.map(i=>wt(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>gt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const s of o)for(let x=s.r0;x<=s.r1;x++)for(let y=s.c0;y<=s.c1;y++)a===null?l.delete(P(x,y)):l.set(P(x,y),a);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function Qt(e,t={}){if(!W.includes(e))return null;const n={type:e},a=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(a("min"),a("max"),a("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,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const a=e.cellDropdowns;if(!a)return null;const r=e.mergeAt(t,n);return a.get(r?P(r.r0,r.c0):P(t,n))??null}function Zt(e){const{sheet:t,sel:n,grid:a}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=a.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Ct=`
|
|
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); }
|
package/charts/chartex.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{child as
|
|
2
|
-
`):
|
|
3
|
-
`).map(a=>`<a:p><a:pPr algn="ctr" rtl="0"><a:defRPr/></a:pPr><a:r><a:rPr lang="en-US"/><a:t>${
|
|
1
|
+
import{child as i,children as L}from"../io/xml-scan.js";import{NS as X,XML_HEAD as H,parseSpPr as J,parseXml as V,toBool as b,writeSpPr as K}from"../objects/dml.js";import{escapeMarkup as y,xmlLiteralText as M}from"../io/xml-escape.js";import{mapShapesOf as Q}from"./geo/map-state.js";import{GEO_PROVIDER as Z}from"./geo/geo-xml.js";const tt={treemap:"treemap",sunburst:"sunburst",histogram:"clusteredColumn",pareto:"clusteredColumn",boxWhisker:"boxWhisker",waterfall:"waterfall",funnel:"funnel",map:"regionMap"},Lt=e=>e==="funnel"?"cx2":e==="map"?"cx4":"cx1",et={treemap:{pos:"inEnd",seriesName:0,categoryName:1,value:0},sunburst:{pos:"ctr",seriesName:0,categoryName:1,value:0},waterfall:{pos:"outEnd",seriesName:0,categoryName:0,value:1},funnel:{seriesName:0,categoryName:0,value:1}};function at(e){const t=i(e,"geoCache");return t?i(t,"binary")?.t?.trim()?!0:!!i(t,"clear")?.c?.length:!1}const _=e=>e?`<cx:dataLabels${e.pos?` pos="${y(e.pos)}"`:""}><cx:visibility seriesName="${e.seriesName?1:0}" categoryName="${e.categoryName?1:0}" value="${e.value?1:0}"/></cx:dataLabels>`:"";function nt(e,t){switch(e){case"treemap":return'<cx:layoutPr><cx:parentLabelLayout val="overlapping"/></cx:layoutPr>';case"histogram":return'<cx:layoutPr><cx:binning intervalClosed="r"/></cx:layoutPr>';case"pareto":return t.catRef?"<cx:layoutPr><cx:aggregation/></cx:layoutPr>":'<cx:layoutPr><cx:binning intervalClosed="r"/></cx:layoutPr>';case"waterfall":return"<cx:layoutPr><cx:subtotals/></cx:layoutPr>";case"boxWhisker":return'<cx:layoutPr><cx:visibility meanLine="0" meanMarker="1" nonoutliers="0" outliers="1"/><cx:statistics quartileMethod="exclusive"/></cx:layoutPr>';case"map":return'<cx:layoutPr><cx:geography cultureLanguage="en-US" cultureRegion="US" attribution="Powered by Bing"/></cx:layoutPr>';default:return""}}function it(e){const t=(n,o="0")=>({id:o,hidden:!1,kind:"cat",gapWidth:String(n),min:void 0,max:void 0,majorGridlines:!1}),a=(n="1")=>({id:n,hidden:!1,kind:"val",min:void 0,max:void 0,majorGridlines:!0});switch(e){case"histogram":return[t(0),a()];case"pareto":return[t(0),a(),{...a("2"),min:0,max:1,majorGridlines:!1,percent:!0}];case"boxWhisker":return[t(1),a()];case"waterfall":return[t(.5),a()];case"funnel":return[t("0.0599999987","1")];default:return[]}}function st(e){return it(e).map(t=>{const a=t.kind==="cat"?`<cx:catScaling gapWidth="${t.gapWidth}"/>`:`<cx:valScaling${t.max!==void 0?` max="${t.max}"`:""}${t.min!==void 0?` min="${t.min}"`:""}/>`;return`<cx:axis id="${t.id}">${a}${t.percent?'<cx:units unit="percentage"/>':""}${t.majorGridlines?"<cx:majorGridlines/>":""}<cx:tickLabels/></cx:axis>`}).join("")}const W=["parentLabelLayout","regionLabelLayout","visibility","aggregation","binning","geography","statistics","subtotals","extLst"],rt=["connectorLines","meanLine","meanMarker","nonoutliers","outliers"],Rt=(e,t,a)=>e?.[t]===!0||e?.[t]===!1?e[t]:b(e?.[t],a),B=e=>Object.fromEntries(rt.filter(t=>e?.[t]!==void 0).map(t=>[t,b(e[t],!1)?"1":"0"])),ct=e=>`<cx:visibility${Object.entries(B(e)).map(([t,a])=>` ${t}="${a}"`).join("")}/>`;function lt(e){if(e)return{intervalClosed:e.a.intervalClosed??"r",underflow:e.a.underflow,overflow:e.a.overflow,binSize:i(e,"binSize")?.a.val===void 0?void 0:Number(i(e,"binSize").a.val),binCount:i(e,"binCount")?.a.val===void 0?void 0:Number(i(e,"binCount").a.val)}}const ot=(e,t)=>["intervalClosed","underflow","overflow","binSize","binCount"].every(a=>(e?.[a]??null)===(t?.[a]??null)||String(e?.[a])===String(t?.[a]));function ut(e){const t=`intervalClosed="${e.intervalClosed??"r"}"${e.underflow!==void 0?` underflow="${y(e.underflow)}"`:""}${e.overflow!==void 0?` overflow="${y(e.overflow)}"`:""}`,a=e.binSize!==void 0?`<cx:binSize val="${e.binSize}"/>`:e.binCount!==void 0?`<cx:binCount val="${e.binCount}"/>`:"";return a?`<cx:binning ${t}>${a}</cx:binning>`:`<cx:binning ${t}/>`}const ft=e=>e.length?`<cx:subtotals>${[...e].sort((t,a)=>t-a).map(t=>`<cx:idx val="${t}"/>`).join("")}</cx:subtotals>`:"<cx:subtotals/>";function xt(e,t,a){const n=new Map((t?.c??[]).map(l=>[l.n,e.raw(l)]));let o=!1;const c=(l,h)=>{h===null?n.delete(l)&&(o=!0):n.get(l)!==h&&(n.set(l,h),o=!0)},u=i(t,"visibility"),p={...u?.a,...a.visibility};a.visibility!==void 0&&JSON.stringify(B(u?.a))!==JSON.stringify(B(p))&&c("visibility",ct(p)),a.aggregation&&!i(t,"aggregation")?(c("binning",null),c("aggregation","<cx:aggregation/>")):!a.aggregation&&a.binning!==void 0&&(i(t,"aggregation")||!ot(lt(i(t,"binning")),a.binning))&&(c("aggregation",null),c("binning",ut(a.binning)));const s=i(t,"statistics")?.a.quartileMethod??"exclusive";a.quartileMethod&&a.quartileMethod!==s&&c("statistics",`<cx:statistics quartileMethod="${a.quartileMethod}"/>`);const x=L(i(t,"subtotals"),"idx").map(l=>Number(l.a.val));if(a.subtotals&&JSON.stringify([...x].sort((l,h)=>l-h))!==JSON.stringify([...a.subtotals].sort((l,h)=>l-h))&&c("subtotals",ft(a.subtotals)),!o)return null;const m=l=>W.includes(l)?W.indexOf(l):W.length;return`<cx:layoutPr>${[...n].sort((l,h)=>m(l[0])-m(h[0])).map(([,l])=>l).join("")}</cx:layoutPr>`}const dt=e=>e==="treemap"||e==="waterfall"||e==="map";function pt(e,t){const{type:a}=e,n=e.series[0]??{levels:[],values:[]},o=n.catRef?`<cx:strDim type="cat"><cx:f>${y(t(n.catRef))}</cx:f>${gt(n.levels)}</cx:strDim>`:"",u=`<cx:numDim type="${a==="treemap"||a==="sunburst"?"size":a==="map"?"colorVal":"val"}"><cx:f>${y(t(n.valRef??""))}</cx:f>${a==="map"&&n.nameRef?`<cx:nf>${y(t(n.nameRef))}</cx:nf>`:""}${mt(n)}</cx:numDim>`,p=n.nameRef||n.name?`<cx:tx><cx:txData>${n.nameRef?`<cx:f>${y(t(n.nameRef))}</cx:f>`:""}<cx:v>${M(n.name??"")}</cx:v></cx:txData></cx:tx>`:"",s=D=>`{0000000${D}-0000-4000-8000-00000000000${D}}`,x=a==="pareto"?'<cx:axisId val="1"/>':"",m=a==="pareto"?`<cx:series layoutId="paretoLine" ownerIdx="0" uniqueId="${s(1)}"><cx:axisId val="2"/></cx:series>`:"",l='<cx:title pos="t" align="ctr" overlay="0"/>',h=a==="map"?'<cx:legend pos="r" align="min" overlay="0"/>':dt(a)?'<cx:legend pos="t" align="ctr" overlay="0"/>':"";return`${H}<cx:chartSpace xmlns:a="${X.a}" xmlns:r="${X.r}" xmlns:cx="${X.cx}"><cx:chartData><cx:data id="0">${o}${u}</cx:data></cx:chartData><cx:chart>${l}<cx:plotArea><cx:plotAreaRegion><cx:series layoutId="${tt[a]}" uniqueId="${s(0)}">${p}${_(et[a])}<cx:dataId val="0"/>${nt(a,n)}${x}</cx:series>${m}</cx:plotAreaRegion>${st(a)}</cx:plotArea>${h}</cx:chart></cx:chartSpace>`}const gt=e=>(e??[]).map(t=>`<cx:lvl ptCount="${t.length}">${t.map((a,n)=>a==null?"":`<cx:pt idx="${n}">${M(a)}</cx:pt>`).join("")}</cx:lvl>`).join(""),mt=e=>`<cx:lvl ptCount="${e.values.length}" formatCode="${y(e.formatCode??"General")}">${e.values.map((t,a)=>t==null?"":`<cx:pt idx="${a}">${t}</cx:pt>`).join("")}</cx:lvl>`,j=["title","plotArea","legend","extLst"],ht=["chartData","chart","spPr","txPr","clrMapOvr","fmtOvrs","printSettings","extLst"],O=["tx","spPr","valueColors","valueColorPositions","dataPt","dataLabels","dataId","layoutPr","axisId","extLst"],$t=["tx","spPr","txPr","extLst"];class yt{constructor(t,a){this.doc=t,this.bytes=a,this.edits=[]}replace(t,a,n){this.edits.push({s:t,e:a,text:n})}setChild(t,a,n,o){const c=t.c.filter(x=>x.n===a);if(c.length){this.replace(c[0].s,c[c.length-1].e,n);return}if(!n)return;const u=o.indexOf(a),p=t.c.find(x=>o.indexOf(x.n)>u);if(p){this.replace(p.s,p.s,n);return}if(t.o===t.e){const x=this.doc.raw(t),m=/^<([^\s/>]+)/.exec(x)[1];this.replace(t.s,t.e,`${x.replace(/\s*\/>$/,">")}${n}</${m}>`);return}const s=bt(this.bytes,t.e);this.replace(s,s,n)}setAttr(t,a,n){const o=this.doc.openTag(t),c=new RegExp(`\\s${a}="[^"]*"`),u=n==null?"":` ${a}="${y(n)}"`,p=c.test(o)?o.replace(c,u):o.replace(/\s*(\/?)>$/,`${u}$1>`);this.replace(t.s,t.o,p)}result(){const t=new TextEncoder,a=[];let n=0;for(const u of this.edits.sort((p,s)=>p.s-s.s))u.s<n||(a.push(this.bytes.subarray(n,u.s),t.encode(u.text)),n=u.e);a.push(this.bytes.subarray(n));const o=new Uint8Array(a.reduce((u,p)=>u+p.length,0));let c=0;for(const u of a)o.set(u,c),c+=u.length;return new TextDecoder().decode(o)}}function bt(e,t){let a=t-1;for(;a>=0&&e[a]!==60;)a--;return a}const vt=e=>{const t=i(i(e,"tx"),"rich");return t?L(t,"p").map(a=>a.c.filter(n=>n.n==="r").map(n=>i(n,"t")?.t??"").join("")).join(`
|
|
2
|
+
`):i(i(i(e,"tx"),"txData"),"v")?.t};function z(e){return`<cx:tx><cx:rich><a:bodyPr anchor="ctr" anchorCtr="1"/><a:lstStyle/>${String(e).split(`
|
|
3
|
+
`).map(a=>`<a:p><a:pPr algn="ctr" rtl="0"><a:defRPr/></a:pPr><a:r><a:rPr lang="en-US"/><a:t>${M(a)}</a:t></a:r></a:p>`).join("")}</cx:rich></cx:tx>`}function U(e,t,a){const n=t?J(t,a):void 0;return JSON.stringify(I(n))===JSON.stringify(I(e))}const I=e=>{if(!e)return null;const{raw:t,...a}=e;return Object.fromEntries(Object.entries(a).filter(([,n])=>n!==void 0))},G=e=>e?K(e.raw?e:{...e},"cx:spPr"):"";function k(e,t){const a=new TextEncoder().encode(e),n=V(a),o=n.root,c=i(o,"chart"),u=i(c,"plotArea"),p=i(u,"plotAreaRegion"),s=new yt(n,a),x=i(c,"title");t.title===void 0||t.title===null?x&&s.setChild(c,"title","",j):x?(t.title.text!==void 0&&t.title.text!==vt(x)&&s.setChild(x,"tx",z(t.title.text),$t),b(x.a.overlay,!1)!==!!t.title.overlay&&s.setAttr(x,"overlay",t.title.overlay?1:0),t.title.pos&&t.title.pos!==x.a.pos&&s.setAttr(x,"pos",t.title.pos)):s.setChild(c,"title",`<cx:title pos="t" align="ctr" overlay="0">${t.title.text!==void 0?z(t.title.text):""}</cx:title>`,j);const m=i(c,"legend");t.legend?m?((m.a.pos??"t")!==(t.legend.pos??"t")&&s.setAttr(m,"pos",t.legend.pos??"t"),b(m.a.overlay,!1)!==!!t.legend.overlay&&s.setAttr(m,"overlay",t.legend.overlay?1:0)):s.setChild(c,"legend",`<cx:legend pos="${y(t.legend.pos??"t")}" align="ctr" overlay="${t.legend.overlay?1:0}"/>`,j):m&&s.setChild(c,"legend","",j);const l=i(o,"spPr");U(t.spPr,l,n)||s.setChild(o,"spPr",G(t.spPr),ht);const h=!t.source,D=L(i(o,"chartData"),"data");return L(p,"series").forEach((f,A)=>{const r=t.series[A];if(!r)return;const R=D.find(d=>d.a.id===i(f,"dataId")?.a.val);for(const d of R?.c??[]){const g=i(d,"f"),v=d.n==="strDim"?r.catRef:d.n==="numDim"?r.valRef:void 0;g&&v&&g.t!==v&&s.replace(g.s,g.e,`<cx:f>${y(v)}</cx:f>`)}const $=i(i(i(f,"tx"),"txData"),"f");$&&r.nameRef&&$.t!==r.nameRef&&s.replace($.s,$.e,`<cx:f>${y(r.nameRef)}</cx:f>`);const S=i(f,"spPr");U(r.spPr,S,n)||s.setChild(f,"spPr",G(r.spPr),O);const T=L(f,"dataPt").map(d=>({idx:Number(d.a.idx),spPr:I(J(i(d,"spPr"),n))})),Y=(r.dataPts??[]).map(d=>({idx:d.idx,spPr:I(d.spPr)}));if(JSON.stringify(T)!==JSON.stringify(Y)){const d=[...r.dataPts??[]].sort((g,v)=>g.idx-v.idx).map(g=>`<cx:dataPt idx="${g.idx}">${G(g.spPr)}</cx:dataPt>`).join("");s.setChild(f,"dataPt",d,O)}const E=i(i(f,"layoutPr"),"geography"),q=t.type==="map"&&A===0?Q(t)?.binary:null;if(E&&q&&!at(E)){const d=n.openTag(E),g=/^<([^\s/>]+)/.exec(d)[1],v=g.includes(":")?g.slice(0,g.indexOf(":")+1):"";s.replace(E.s,E.e,`${d.replace(/\s*\/?>$/,">")}<${v}geoCache provider="${Z}"><${v}binary>${q}</${v}binary></${v}geoCache></${g}>`)}if(t.type!=="map"){const d=xt(n,i(f,"layoutPr"),r);d&&s.setChild(f,"layoutPr",d,O)}const C=i(f,"dataLabels"),N=i(C,"visibility"),F=C?{pos:C.a.pos,seriesName:b(N?.a.seriesName,!1),categoryName:b(N?.a.categoryName,!1),value:b(N?.a.value,!1)}:null,P=r.dataLabels?{pos:r.dataLabels.pos,seriesName:b(r.dataLabels.visibility?.seriesName,!1),categoryName:b(r.dataLabels.visibility?.categoryName,!1),value:b(r.dataLabels.visibility?.value,!1)}:null;!h&&JSON.stringify(F)!==JSON.stringify(P)&&(P?C&&N?(s.replace(N.s,N.e,`<cx:visibility seriesName="${P.seriesName?1:0}" categoryName="${P.categoryName?1:0}" value="${P.value?1:0}"/>`),C.a.pos!==P.pos&&s.setAttr(C,"pos",P.pos)):s.setChild(f,"dataLabels",_(P),O):s.setChild(f,"dataLabels","",O))}),L(u,"axis").forEach((f,A)=>{const r=t.axes?.[A];if(!r)return;b(f.a.hidden,!1)!==!!r.hidden&&s.setAttr(f,"hidden",r.hidden?1:void 0);const R=i(f,"catScaling");R&&r.gapWidth!==void 0&&R.a.gapWidth!==String(r.gapWidth)&&s.setAttr(R,"gapWidth",r.gapWidth);const $=i(f,"valScaling");if($){const w=$.a.min===void 0?void 0:Number($.a.min),T=$.a.max===void 0?void 0:Number($.a.max);(w!==r.min||T!==r.max)&&s.replace($.s,$.e,`<cx:valScaling${r.max!==void 0?` max="${r.max}"`:""}${r.min!==void 0?` min="${r.min}"`:""}/>`)}const S=i(f,"majorGridlines");if(!!S!=!!r.majorGridlines)if(S)s.replace(S.s,S.e,"");else{const w=i(f,"tickLabels")??i(f,"numFmt")??i(f,"spPr");w&&s.replace(w.s,w.s,"<cx:majorGridlines/>")}}),s.result()}function Et(e,t=a=>a){return e.source&&!e.dirty?e.source:e.source?k(e.source,e):k(pt(e,t),e)}export{tt as CHARTEX_LAYOUT,it as chartExAxes,Rt as chartExFlag,Lt as chartExRequires,Et as writeChartExPart};
|
package/core/address.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const F=1048576,T=16384,$=[];function a(t){let e=$[t];if(e!==void 0)return e;e="";for(let n=t+1;n>0;n=Math.floor((n-1)/26))e=String.fromCharCode(65+(n-1)%26)+e;return $[t]=e,e}function s(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n)&223;if(r<65||r>90)return-1;e=e*26+(r-64)}return e-1}function S(t,e){return a(e)+(t+1)}const h=/^[\p{L}\p{Nl}\p{No}_\\][\p{L}\p{N}\p{M}_.\\?]*$/u,N=/^([A-Za-z]{1,3})(\d+)$/,L=/^[Rr](\d*)(?:[Cc]\d*)?$|^[Cc](\d*)$/,_=(t,e)=>t===""||Number(t)>=1&&Number(t)<=e;function q(t){if(t.length>255||!h.test(t)||/^(TRUE|FALSE)$/i.test(t)||t.length===2&&t[0]==="\\")return!1;const e=N.exec(t);if(e&&s(e[1])<16384&&_(e[2],1048576))return!1;const n=L.exec(t);return!(n&&_(n[1]??n[2],1048576))}const m=/^\$?([A-Za-z]{1,3})\$?([1-9][0-9]{0,6})$/;function C(t){const e=m.exec(t.trim());if(!e)return null;const n=s(e[1]),r=Number(e[2])-1;return n<0||n>=16384||r>=1048576?null:{row:r,col:n}}function P(t){const e=t.trim().split(":");if(e.length>2||!e[0])return null;const n=(o,c)=>{const l=/^\$?[A-Za-z]{1,3}$/.test(o)?s(o.replace("$","")):-1,f=/^\$?[A-Za-z]{1,3}$/.test(c)?s(c.replace("$","")):-1;if(l>=0&&f>=0&&l<16384&&f<16384)return{r0:0,c0:Math.min(l,f),r1:1048575,c1:Math.max(l,f)};const i=/^\$?[0-9]+$/.test(o)?Number(o.replace("$",""))-1:-1,p=/^\$?[0-9]+$/.test(c)?Number(c.replace("$",""))-1:-1;return i>=0&&p>=0&&i<1048576&&p<1048576?{r0:Math.min(i,p),c0:0,r1:Math.max(i,p),c1:16383}:null},r=C(e[0]);if(e.length===1)return r?{r0:r.row,c0:r.col,r1:r.row,c1:r.col}:null;const u=C(e[1]);return r&&u?{r0:Math.min(r.row,u.row),c0:Math.min(r.col,u.col),r1:Math.max(r.row,u.row),c1:Math.max(r.col,u.col)}:n(e[0],e[1])}function U({r0:t,c0:e,r1:n,c1:r}){if(t===0&&n===1048575)return`${a(e)}:${a(r)}`;if(e===0&&r===16383)return`${t+1}:${n+1}`;const u=S(t,e);return t===n&&e===r?u:`${u}:${S(n,r)}`}const R=/[\x00-\x2d\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\x7f]/,M=/[\s\p{C}]/u,O=/^[\p{Nd}.]/u,g=/^([A-Za-z]{1,3})(\p{Nd}+)$/u,X=/^([A-Za-z]{1,3}\p{Nd}+)\.+([A-Za-z]{1,3}\p{Nd}+)$/u,I=/^R(\p{Nd}+)/iu,E=/^R?C(\p{Nd}+)/iu,w=/^[0-9]+$/,x=(t,e)=>!w.test(t)||Number(t)>=1&&Number(t)<=e;function A(t){const e=g.exec(t);return e!==null&&s(e[1])<16384&&x(e[2],1048576)}function d(t,e=!1){const n=String(t??"");if(n===""||R.test(n)||M.test(n)||O.test(n))return!0;const r=n.toUpperCase();if(r==="TRUE"||r==="FALSE"||r==="R"||r==="C"||r==="RC")return!0;if(!e){if(A(n))return!0;const c=X.exec(n);if(c&&A(c[1])&&A(c[2]))return!0}const u=I.exec(n);if(u&&x(u[1],1048576))return e||n[u[0].length]!==".";const o=E.exec(n);return o&&x(o[1],16384)?e||n[o[0].length]!==".":!1}function W(t,{book:e=null,last:n=null,r1c1:r=!1,always:u=!1}={}){const o=String(t??""),c=`${e!=null?`[${e}]`:""}${o}${n!=null?`:${n}`:""}`;return u||(o!==""||e===null||e===void 0)&&d(o,r)||n!=null&&d(n,r)||e!=null&&(R.test(e)||M.test(e))?`'${c.replace(/'/g,"''")}'`:c}const B=String.raw`[A-Za-z_\u0080-][\w.\u0080-]*`,z=(t,e)=>`${W(t,e)}!`;function Z(t){const e=String(t).replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/'/g,"''");return new RegExp(`(?:'${e}'|(?<![\\p{L}\\p{N}_.'\\]\\u0080-\\u{10FFFF}])${e})!`,"giu")}function G(t,e,n){const r=z(n);return String(t).replace(Z(e),()=>r)}function K(t){const e=String(t??"");return e.length>1&&e[0]==="'"&&e[e.length-1]==="'"?e.slice(1,-1).replace(/''/g,"'"):e}export{T as MAX_COLS,F as MAX_ROWS,B as PLAIN_SHEET,S as cellRef,s as colIndex,a as colName,q as isValidName,C as parseCellRef,P as parseRangeRef,W as quoteSheetName,U as rangeRef,G as renameSheetInFormula,d as sheetNeedsQuotes,z as sheetPrefix,Z as sheetReferencePattern,K as unquoteSheetName};
|