@8sheets/data-grid 1.0.2 → 1.1.1
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/api/theme-core.js +2 -0
- package/calc/adjust.js +1 -1
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/array.js +1 -1
- package/calc/functions/database.js +1 -1
- package/calc/functions/date.js +1 -1
- package/calc/functions/financial.js +1 -1
- package/calc/functions/helpers.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/logical.js +1 -1
- package/calc/functions/lookup.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/functions/stat.js +1 -1
- package/calc/functions/text.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.js +1 -1
- package/calcx/async.js +1 -1
- package/calcx/culture/custom.js +1 -0
- package/calcx/culture/format-locale.js +1 -1
- package/calcx/culture/separators.js +1 -0
- package/calcx/functions/dynamic.js +1 -1
- package/calcx/functions/ets.js +1 -1
- package/calcx/functions/misc.js +1 -1
- package/calcx/lang/convert.js +1 -0
- package/cells/axis-ops.js +1 -1
- package/cells/block.js +1 -0
- package/cells/book-css.js +2 -2
- package/cells/cell-defaults.js +1 -1
- package/cells/cf-engine.js +1 -1
- package/cells/consolidate-links.js +1 -1
- package/cells/find-engine.js +2 -2
- package/cells/format-panes.js +3 -3
- package/cells/format-tabs.js +2 -2
- package/cells/outline-column.js +1 -1
- package/cells/panes.js +1 -1
- package/cells/rich-runs.js +2 -2
- package/cells/rich-values.js +1 -1
- package/cells/selection-modes.js +1 -1
- package/cells/shift-check.js +1 -0
- package/cells/table-rows.js +1 -0
- package/cells/text-layout.js +9 -8
- package/cells/ui-kit.js +15 -0
- package/cells/view-options.js +1 -1
- package/celltypes/cell-types.js +2 -2
- package/celltypes/diagonal.js +1 -1
- package/celltypes/dropdowns.js +3 -2
- package/celltypes/file-cell.js +2 -2
- package/celltypes/range-template.js +2 -2
- package/core/autofill.js +1 -1
- package/core/axis-styles.js +1 -0
- package/core/axis.js +1 -1
- package/core/cell-type-rules.js +1 -0
- package/core/changes.js +1 -1
- package/core/cond-format.js +1 -1
- package/core/culture.js +1 -0
- package/core/formula-refs.js +1 -1
- package/core/input.js +1 -1
- package/core/merge.js +1 -0
- package/core/numfmt.js +1 -1
- package/core/region-input.js +1 -0
- package/core/row-fit.js +1 -0
- package/core/sheet.js +1 -1
- package/core/sparse.js +1 -1
- package/core/structure.js +1 -0
- package/core/styles.js +1 -1
- package/core/tables.js +2 -2
- package/core/validation-ranges.js +1 -0
- package/core/whatif.js +1 -1
- package/core/workbook.js +1 -1
- package/datasheets/data-core.js +1 -1
- package/datasheets/gantt-paint.js +1 -1
- package/datasheets/manager.js +1 -1
- package/datasheets/path-binding.js +2 -2
- package/datasheets/rules.js +1 -1
- package/datasheets/view.js +2 -2
- package/i18n/dom.js +1 -1
- package/i18n/en/cells.js +1 -1
- package/i18n/en/format.js +1 -1
- package/i18n/en/misc.js +1 -1
- package/i18n/en/shell.js +2 -2
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/misc.js +1 -1
- package/i18n/pl/shell.js +2 -2
- package/io/client.js +1 -1
- package/io/csv.js +8 -8
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xlsx-read.js +1 -1
- package/io/xlsx-write.js +1 -1
- package/io/xml-scan.js +2 -1
- package/io/zip-reader.js +1 -1
- 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/paginate.js +1 -1
- package/print/render-page.js +3 -3
- package/slicers/format.js +2 -2
- package/slicers/structured.js +1 -1
- package/table-view/api.js +1 -1
- package/table-view/cell-editor.js +2 -1
- package/table-view/chart.js +1 -0
- package/table-view/column-drag.js +1 -1
- package/table-view/context-menu.js +1 -0
- package/table-view/editors.js +1 -0
- package/table-view/events.js +1 -1
- package/table-view/files.js +1 -1
- package/table-view/fill-handle.js +1 -0
- package/table-view/filter-builder.js +1 -0
- package/table-view/find.js +1 -0
- package/table-view/grid-keys.js +2 -2
- package/table-view/labels-de.js +1 -0
- package/table-view/labels-es.js +1 -0
- package/table-view/labels-fr.js +1 -0
- package/table-view/labels-ja.js +1 -0
- package/table-view/labels.js +1 -1
- package/table-view/model.js +1 -1
- package/table-view/mount.js +1 -1
- package/table-view/panel.js +1 -1
- package/table-view/pivot-spec.js +1 -0
- package/table-view/pivot.js +1 -1
- package/table-view/public.d.ts +277 -28
- package/table-view/reader.worker.js +1 -1
- package/table-view/remote.js +1 -1
- package/table-view/row-drag.js +1 -0
- package/table-view/sparkline.js +1 -0
- package/table-view/state-check.js +1 -0
- package/table-view/table-css.js +380 -0
- package/table-view/version.js +1 -1
- package/ui/dialogs.js +3 -3
- package/ui/menu-base.js +1 -1
- package/ui/protection-ui.js +1 -1
package/cells/rich-values.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unescapeXstring as f}from"../io/xml-scan.js";import{ERRORS as g}from"../core/sheet.js";import{RichValue as x}from"../calc/values.js";const N={rv:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",path:"xl/richData/rdrichvalue.xml"},struct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",path:"xl/richData/rdrichvaluestructure.xml"},types:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",path:"xl/richData/rdRichValueTypes.xml"},spb:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBag",path:"xl/richData/rdsupportingpropertybag.xml"},spbStruct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBagStructure",path:"xl/richData/rdsupportingpropertybagstructure.xml"},array:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdArray",path:"xl/richData/rdarray.xml"},styles:{type:"http://schemas.microsoft.com/office/2017/06/relationships/richStyles",path:"xl/richData/richStyles.xml"}},S={4:"#NAME?",8:"#SPILL!",9:"#CONNECT!",10:"#BLOCKED!",11:"#UNKNOWN!",12:"#FIELD!",13:"#CALC!",14:"#BUSY!",17:"#BUSY!",19:"#TIMEOUT!"},w={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},A=/<v\b([^>]*)>([\s\S]*?)<\/v>|<v\b([^>]*)\/>/g,b=i=>/\bt="([^"]+)"/.exec(i??"")?.[1];function h(i){const t=[];for(const s of i.matchAll(A))t.push({t:b(s[1]??s[3]),v:f(s[2]??"")});return t}function y(i){return[...i.matchAll(/<k\b([^>]*)\/?>/g)].map(t=>({n:f(/\bn="([^"]*)"/.exec(t[1])?.[1]??""),t:b(t[1])??"d"}))}function E(i){if(!i)return[];const s=[...i.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,e=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(i),r=e?[...e[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],n=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(i),o=[-1];for(const a of n?n[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g):[]){const c=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);o.push(c&&Number(c[1])===s?r[Number(c[2])]??-1:-1)}return o}class V{constructor(t){this.byVm=E(t.meta),this.structs=t.struct?[...t.struct.matchAll(/<s\b([^>]*)>([\s\S]*?)<\/s>/g)].map(r=>({t:f(/\bt="([^"]*)"/.exec(r[1])?.[1]??""),keys:y(r[2])})):[],this.values=t.rv?[...t.rv.matchAll(/<rv\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rv>)/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h((r[2]??"").replace(/<fb\b[\s\S]*?<\/fb>|<fb\b[^>]*\/>/g,"")).map(n=>n.v)})):[];const s=t.spb??"",e=/<spbArrays\b[^>]*>([\s\S]*?)<\/spbArrays>/.exec(s)?.[1]??"";this.spbArrays=[...e.matchAll(/<a\b[^>]*>([\s\S]*?)<\/a>/g)].map(r=>h(r[1])),this.spbs=[...s.matchAll(/<spb\b([^>]*)>([\s\S]*?)<\/spb>/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h(r[2]).map(n=>n.v)})),this.spbStructs=t.spbStruct?[...t.spbStruct.matchAll(/<(s|spbStructure)\b[^>]*>([\s\S]*?)<\/\1>/g)].map(r=>y(r[2])):[],this.arrays=t.array?[...t.array.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/g)].map(r=>({r:Number(/\br="(\d+)"/.exec(r[1])?.[1]??1),c:Number(/\bc="(\d+)"/.exec(r[1])?.[1]??1),v:h(r[2])})):[],this.typeFlags=R(t.types??""),this.added=new Map,this.styles=_(t.styles??"")}indexOfVm(t){return t>0&&t<this.byVm.length?this.byVm[t]:this.added.get(t)??-1}vmOfIndex(t){if(this.vmByIndex===void 0){this.vmByIndex=new Map;for(let s=this.byVm.length-1;s>0;s--)this.byVm[s]>=0&&this.vmByIndex.set(this.byVm[s],s)}return this.vmByIndex.get(t)??-1}sameValue(t,s){const e=this.values[t],r=this.values[s];return!!(e&&r)&&e.s===r.s&&e.v.length===r.v.length&&e.v.every((n,o)=>n===r.v[o])}type(t){return this.structs[this.values[t]?.s]?.t??null}entries(t,s=0){const e=this.values[t],r=e&&this.structs[e.s],n=new Map;if(!r||s>8)return n;r.keys.forEach((a,c)=>n.set(a.n,{n:a.n,t:a.t,v:e.v[c]??""}));const o=n.get("%cvi");if(o&&o.t==="r")for(const[a,c]of this.entries(Number(o.v),s+1))n.has(a)||n.set(a,c);return n}bag(t){const s=this.spbs[t],e=s?this.spbStructs[s.s]??[]:[],r=new Map;return e.forEach((n,o)=>r.set(n.n,{n:n.n,t:n.t,v:s.v[o]??""})),r}view(t,s=!1){const e=this.type(t);if(e===null||e==="_localImage"||e==="_webimage")return null;const r=this.entries(t);if(e==="_error"){const o=Number(r.get("errorType")?.v),a=o===18?s?"#PYTHON!":"#EXTERNAL!":S[o]??null;return a?{kind:"error",text:a,icon:null}:null}if(e==="_array"){const o=this.arrays[Number(r.get("array")?.v)];return{kind:"array",text:o&&o.v.length?this.displayOf(o.v[0]):"",icon:s?"python":"array"}}return e==="_hyperlink"?{kind:"link",text:r.get("Text")?.v||r.get("Address")?.v||"",icon:null}:{kind:"entity",text:r.get("_DisplayString")?.v??r.get("Name")?.v??"",icon:s?"python":k(e,r)}}displayOf(t,s=0){switch(t.t){case"r":{if(s>8)return"";const e=this.view(Number(t.v));return e?e.text:this.entries(Number(t.v)).get("Text")?.v??""}case"a":{const e=this.arrays[Number(t.v)];return e&&e.v.length?this.displayOf(e.v[0],s+1):""}case"b":return t.v==="1"||t.v==="true"?"TRUE":"FALSE";case"e":return v(t.v);case"spb":case"spba":return"";default:return t.v}}flag(t,s,e,r){const o=this.entries(t).get("_Flags");if(o&&o.t==="spb"){const c=this.bag(Number(o.v)).get(s);if(c&&c.t==="spb"){const u=this.bag(Number(c.v)).get(e);if(u)return u.v==="1"||u.v==="true"}}return this.typeFlags.get(this.type(t))?.get(s)?.get(e)??this.typeFlags.get("")?.get(s)?.get(e)??r}fields(t){const s=this.entries(t),e=this.type(t),r=u=>!/^[_%^]/.test(u)&&this.flag(t,u,"ShowInCardView",e!=="_hyperlink");let n=[...s.keys()].filter(r);const o=s.get("_Display");if(o?.t==="spb"){const u=this.bag(Number(o.v)).get("^Order");if(u?.t==="spba"){const p=(this.spbArrays[Number(u.v)]??[]).map(l=>l.v).filter(l=>s.has(l)&&r(l));n=[...p,...n.filter(l=>!p.includes(l))]}}const a=s.get("_SubLabel"),c=a?.t==="spb"?this.bag(Number(a.v)):null;return n.map(u=>{const p=c?.get(u);let l="";return p?.t==="spb"?l=[...this.bag(Number(p.v)).values()].map(d=>d.v).join(" "):p&&(l=p.v),{name:u,value:s.get(u),sub:l}})}keyOf(t,s){const e=this.entries(t);if(e.has(s))return s;const r=s.toLowerCase();for(const o of e.keys())if(o.toLowerCase()===r)return o;const n=e.get("_CanonicalPropertyNames");if(n?.t==="spb"){for(const[o,a]of this.bag(Number(n.v)))if(a.v.toLowerCase()===r&&e.has(o))return o}return null}fieldFormat(t,s,e=null){const r=this.entries(t).get("_Format");if(!r||r.t!=="spb")return null;const n=this.bag(Number(r.v)).get(s),o=n?this.styles.rSty[Number(n.v)]:void 0;if(!o)return null;for(const c of o.rpv){const u=this.styles.rPr[c.i];if(u&&/^(?:NumberFormat|NumFmt|Format)$/i.test(u.n)&&c.v)return c.v}if(o.dxfid===null)return null;if(this.styles.dxfs.length)return this.styles.dxfs[o.dxfid]??null;const a=e?.[o.dxfid];return(typeof a?.numFmt=="string"?a.numFmt:a?.numFmt?.code??a?.numFmt?.formatCode)??null}isEntity(t){const s=this.type(t);return s!==null&&s!=="_error"&&s!=="_array"&&s!=="_localImage"&&s!=="_webimage"&&s!=="_hyperlink"}}function T(i,t,s){let e=t,r=null;for(let n=0;n<s.length;n++){if(!i.isEntity(e))return{error:"#FIELD!"};const o=i.keyOf(e,String(s[n]));if(o===null)return{error:"#FIELD!"};const a=i.entries(e).get(o);if(a.t==="r"&&n<s.length-1){e=Number(a.v);continue}if(n<s.length-1)return{error:"#FIELD!"};r=m(i,a,0)}return r??{error:"#VALUE!"}}function m(i,t,s){switch(t.t){case"i":case"d":{const e=Number(t.v);return Number.isFinite(e)?e:{error:"#NUM!"}}case"b":return t.v==="1"||t.v==="true";case"e":return{error:v(t.v)};case"s":return t.v;case"a":{const e=i.arrays[Number(t.v)];if(!e||s>4)return{error:"#VALUE!"};const r=[];for(let n=0;n<e.r;n++){const o=[];for(let a=0;a<e.c;a++){const c=e.v[n*e.c+a],u=c?m(i,{t:c.t??"d",v:c.v},s+1):"";o.push(u&&typeof u=="object"&&u.rows?u.rows[0]?.[0]??"":u)}r.push(o)}return{rows:r}}case"r":{const e=Number(t.v),r=i.type(e),n=i.entries(e);return r==="_error"?{error:i.view(e)?.text??"#VALUE!"}:r==="_array"?m(i,n.get("array")??{t:"a",v:"-1"},s+1):i.isEntity(e)?{entity:e}:i.view(e)?.text??n.get("Text")?.v??""}case"spb":case"spba":return{error:"#VALUE!"};default:{const e=Number(t.v);return t.v!==""&&Number.isFinite(e)?e:t.v}}}function _(i){const t={dxfs:[],rPr:[],rSty:[]};if(!i)return t;const s=/<(?:\w+:)?dxfs\b[^>]*>([\s\S]*?)<\/(?:\w+:)?dxfs>/.exec(i)?.[1]??"";return t.dxfs=[...s.matchAll(/<((?:\w+:)?)dxf\b[^>]*?(?:\/>|>([\s\S]*?)<\/\1dxf>)/g)].map(e=>{const r=/<(?:\w+:)?numFmt\b[^>]*\bformatCode="([^"]*)"/.exec(e[2]??"")?.[1];return r===void 0?null:f(r)}),t.rPr=[...i.matchAll(/<rPr\b([^>]*)\/?>/g)].map(e=>({n:f(/\bn="([^"]*)"/.exec(e[1])?.[1]??""),t:b(e[1])??"s"})),t.rSty=[...i.matchAll(/<rSty\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rSty>)/g)].map(e=>{const r=/\bdxfid="(\d+)"/.exec(e[1])?.[1],n=[...(e[2]??"").matchAll(/<rpv\b[^>]*\bi="(\d+)"[^>]*>([\s\S]*?)<\/rpv>/g)].map(o=>({i:Number(o[1]),v:f(o[2])}));return{dxfid:r===void 0?null:Number(r),rpv:n}}),t}function R(i){const t=new Map,s=r=>{const n=new Map;for(const o of r.matchAll(/<key\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/key>/g)){const a=new Map;for(const c of o[2].matchAll(/<flag\b[^>]*\bname="([^"]*)"[^>]*\bvalue="([^"]*)"/g))a.set(c[1],c[2]==="1"||c[2]==="true");n.set(f(o[1]),a)}return n},e=/<global\b[^>]*>([\s\S]*?)<\/global>/.exec(i);e&&t.set("",s(e[1]));for(const r of i.matchAll(/<type\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/type>/g))t.set(f(r[1]),s(r[2]));return t}function v(i){return/^#/.test(i)?i.toUpperCase():w[Number(i)]??g[Number(i)]??"#VALUE!"}function k(i,t){const s=[t.get("_Icon")?.v,t.get("%EntityDomainIdString")?.v,t.get("%ProviderInfo")?.v,t.get("%DataProviderString")?.v,i].filter(Boolean).join(" ").toLowerCase();return/stock|financ|bank|exchange|ticker|fund/.test(s)?"stock":/geo|map|country|city|place|globe|location|region/.test(s)?"geography":/currenc|money|coin/.test(s)?"currency":"entity"}async function M(i,t){if(!t.meta||!t.rv||!t.struct||!/<s\b[^>]*\bt="(?!_localImage")/.test(t.struct))return null;const s=i.has("xl/_rels/workbook.xml.rels")?await i.text("xl/_rels/workbook.xml.rels"):"",e=n=>{for(const o of s.matchAll(/<Relationship\b[^>]*\/>/g)){if(!o[0].includes(`Type="${n.type}"`))continue;const a=/\bTarget="([^"]+)"/.exec(o[0])?.[1];if(a)return a.startsWith("/")?a.slice(1):`xl/${a.replace(/^\.\//,"")}`}return n.path},r=async n=>{const o=e(N[n]);return i.has(o)?i.text(o):null};return new V({...t,spb:await r("spb"),spbStruct:await r("spbStruct"),array:await r("array"),styles:await r("styles")})}function D(i,t,s,e){const r=i.richValues,n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);return o>=0&&r.isEntity(o)?new x(r,o):null}function U(i,t){const s=i.richValues,e=s.vmOfIndex(t);if(e>0)return e;i.richNew??=[];let r=i.richNew.findIndex(o=>o.rv===t);r<0&&(r=i.richNew.push({rv:t})-1);const n=(i.richSource?.vmCount??0)+r+1;return s.added.set(n,t),n}const I={4:4,8:8,9:11,10:12,11:14,12:13,13:9,14:10,17:10};function C(i){const t=i.richValues;if(t){for(const s of i.sheets)if(s.valueMeta!==null)for(const[e,r]of s.valueMeta){const n=t.indexOfVm(r);if(n<0||t.type(n)!=="_error")continue;const o=I[Number(t.entries(n).get("errorType")?.v)],a=Math.floor(e/16384),c=e-a*16384,u=s.kind(a,c);o!==void 0&&(u&7)===4&&s.setCell(a,c,u,o)}}}function P(i,t,s,e){const r=i.richValues;if(!r||t.valueMeta===null)return null;const n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);if(o<0)return null;const a=t.formula(s,e),c=a?.f??a?.sf??"",u=r.view(o,/(?:^|[^\w.])(?:_xlfn\.)?(?:_xlws\.)?PY\(/i.test(c));return u?{rich:r,index:o,view:u}:null}export{N as RICH_PARTS,V as RichValues,C as adoptRichErrors,P as cellRich,U as entityVm,v as errorText,T as fieldValue,M as readRichValues,D as richValueAt,E as vmIndex};
|
|
1
|
+
import{unescapeXstring as f}from"../io/xml-scan.js";import{ERRORS as g}from"../core/sheet.js";import{RichValue as x}from"../calc/values.js";const N={rv:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",path:"xl/richData/rdrichvalue.xml"},struct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",path:"xl/richData/rdrichvaluestructure.xml"},types:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",path:"xl/richData/rdRichValueTypes.xml"},spb:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBag",path:"xl/richData/rdsupportingpropertybag.xml"},spbStruct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBagStructure",path:"xl/richData/rdsupportingpropertybagstructure.xml"},array:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdArray",path:"xl/richData/rdarray.xml"},styles:{type:"http://schemas.microsoft.com/office/2017/06/relationships/richStyles",path:"xl/richData/richStyles.xml"}},S={4:"#NAME?",8:"#SPILL!",9:"#CONNECT!",10:"#BLOCKED!",11:"#UNKNOWN!",12:"#FIELD!",13:"#CALC!",14:"#BUSY!",17:"#BUSY!",19:"#TIMEOUT!"},w={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},A=/<v\b([^>]*)>([\s\S]*?)<\/v>|<v\b([^>]*)\/>/g,h=o=>/\bt="([^"]+)"/.exec(o??"")?.[1];function b(o){const t=[];for(const s of o.matchAll(A))t.push({t:h(s[1]??s[3]),v:f(s[2]??"")});return t}function d(o){return[...o.matchAll(/<k\b([^>]*)\/?>/g)].map(t=>({n:f(/\bn="([^"]*)"/.exec(t[1])?.[1]??""),t:h(t[1])??"d"}))}function k(o){if(!o)return[];const s=[...o.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,e=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(o),r=e?[...e[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],n=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(o),i=[-1];for(const a of n?n[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g):[]){const c=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);i.push(c&&Number(c[1])===s?r[Number(c[2])]??-1:-1)}return i}class E{constructor(t){this.byVm=k(t.meta),this.structs=t.struct?[...t.struct.matchAll(/<s\b([^>]*)>([\s\S]*?)<\/s>/g)].map(r=>({t:f(/\bt="([^"]*)"/.exec(r[1])?.[1]??""),keys:d(r[2])})):[],this.values=t.rv?[...t.rv.matchAll(/<rv\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rv>)/g)].map(r=>{const n=r[2]??"",i=/<fb\b([^>]*)>([\s\S]*?)<\/fb>/.exec(n);return{s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:b(n).map(a=>a.v),fallback:i&&{t:h(i[1])??"n",v:f(i[2])}}}):[];const s=t.spb??"",e=/<spbArrays\b[^>]*>([\s\S]*?)<\/spbArrays>/.exec(s)?.[1]??"";this.spbArrays=[...e.matchAll(/<a\b[^>]*>([\s\S]*?)<\/a>/g)].map(r=>b(r[1])),this.spbs=[...s.matchAll(/<spb\b([^>]*)>([\s\S]*?)<\/spb>/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:b(r[2]).map(n=>n.v)})),this.spbStructs=t.spbStruct?[...t.spbStruct.matchAll(/<(s|spbStructure)\b[^>]*>([\s\S]*?)<\/\1>/g)].map(r=>d(r[2])):[],this.arrays=t.array?[...t.array.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/g)].map(r=>({r:Number(/\br="(\d+)"/.exec(r[1])?.[1]??1),c:Number(/\bc="(\d+)"/.exec(r[1])?.[1]??1),v:b(r[2])})):[],this.typeFlags=_(t.types??""),this.added=new Map,this.styles=V(t.styles??"")}indexOfVm(t){return t>0&&t<this.byVm.length?this.byVm[t]:this.added.get(t)??-1}vmOfIndex(t){if(this.vmByIndex===void 0){this.vmByIndex=new Map;for(let s=this.byVm.length-1;s>0;s--)this.byVm[s]>=0&&this.vmByIndex.set(this.byVm[s],s)}return this.vmByIndex.get(t)??-1}sameValue(t,s){const e=this.values[t],r=this.values[s];return!!(e&&r)&&e.s===r.s&&e.v.length===r.v.length&&e.v.every((n,i)=>n===r.v[i])}type(t){return this.structs[this.values[t]?.s]?.t??null}linkedCore(t){const s=e=>{const r=["%EntityServiceId","%EntityId","%EntityCulture"].map(n=>e.get(n)?.v);return r.every(n=>n!==void 0)?JSON.stringify(r):null};if(this.linkedCores===void 0){this.linkedCores=new Map;for(let e=0;e<this.values.length;e++){if(this.type(e)!=="_linkedentity2core")continue;const r=s(this.entries(e));r!==null&&this.linkedCores.set(r,e)}}return this.linkedCores.get(s(t))}entries(t,s=0){const e=this.values[t],r=e&&this.structs[e.s],n=new Map;if(!r||s>8)return n;r.keys.forEach((c,u)=>n.set(c.n,{n:c.n,t:c.t,v:e.v[u]??""}));const i=n.get("%cvi"),a=i?.t==="r"?Number(i.v):r.t==="_linkedentity2"?this.linkedCore(n):void 0;if(a!==void 0)for(const[c,u]of this.entries(a,s+1))n.has(c)||n.set(c,u);return n}bag(t){const s=this.spbs[t],e=s?this.spbStructs[s.s]??[]:[],r=new Map;return e.forEach((n,i)=>r.set(n.n,{n:n.n,t:n.t,v:s.v[i]??""})),r}view(t,s=!1){const e=this.type(t);if(e===null||e==="_localImage"||e==="_webimage"||e==="_formattednumber")return null;const r=this.entries(t);if(e==="_error"){const i=Number(r.get("errorType")?.v),a=i===18?s?"#PYTHON!":"#EXTERNAL!":S[i]??null;return a?{kind:"error",text:a,icon:null}:null}if(e==="_array"){const i=this.arrays[Number(r.get("array")?.v)];return{kind:"array",text:i&&i.v.length?this.displayOf(i.v[0]):"",icon:s?"python":"array"}}return e==="_hyperlink"?{kind:"link",text:r.get("Text")?.v||r.get("Address")?.v||"",icon:null}:{kind:"entity",text:r.get("_DisplayString")?.v??r.get("Name")?.v??"",icon:s?"python":I(e,r)}}displayOf(t,s=0){switch(t.t){case"r":{if(s>8)return"";const e=this.view(Number(t.v));return e?e.text:this.entries(Number(t.v)).get("Text")?.v??""}case"a":{const e=this.arrays[Number(t.v)];return e&&e.v.length?this.displayOf(e.v[0],s+1):""}case"b":return t.v==="1"||t.v==="true"?"TRUE":"FALSE";case"e":return y(t.v);case"spb":case"spba":return"";default:return t.v}}flag(t,s,e,r){const i=this.entries(t).get("_Flags");if(i&&i.t==="spb"){const c=this.bag(Number(i.v)).get(s);if(c&&c.t==="spb"){const u=this.bag(Number(c.v)).get(e);if(u)return u.v==="1"||u.v==="true"}}return this.typeFlags.get(this.type(t))?.get(s)?.get(e)??this.typeFlags.get("")?.get(s)?.get(e)??r}fields(t){const s=this.entries(t),e=this.type(t),r=u=>!/^[_%^]/.test(u)&&this.flag(t,u,"ShowInCardView",e!=="_hyperlink");let n=[...s.keys()].filter(r);const i=s.get("_Display");if(i?.t==="spb"){const u=this.bag(Number(i.v)).get("^Order");if(u?.t==="spba"){const p=(this.spbArrays[Number(u.v)]??[]).map(l=>l.v).filter(l=>s.has(l)&&r(l));n=[...p,...n.filter(l=>!p.includes(l))]}}const a=s.get("_SubLabel"),c=a?.t==="spb"?this.bag(Number(a.v)):null;return n.map(u=>{const p=c?.get(u);let l="";return p?.t==="spb"?l=[...this.bag(Number(p.v)).values()].map(v=>v.v).join(" "):p&&(l=p.v),{name:u,value:s.get(u),sub:l}})}keyOf(t,s){const e=this.entries(t);if(e.has(s))return s;const r=s.toLowerCase();for(const i of e.keys())if(i.toLowerCase()===r)return i;const n=e.get("_CanonicalPropertyNames");if(n?.t==="spb"){for(const[i,a]of this.bag(Number(n.v)))if(a.v.toLowerCase()===r&&e.has(i))return i}return null}fieldFormat(t,s,e=null){const r=this.entries(t).get("_Format");if(!r||r.t!=="spb")return null;const n=this.bag(Number(r.v)).get(s),i=n?this.styles.rSty[Number(n.v)]:void 0;if(!i)return null;for(const c of i.rpv){const u=this.styles.rPr[c.i];if(u&&/^(?:NumberFormat|NumFmt|Format)$/i.test(u.n)&&c.v)return c.v}if(i.dxfid===null)return null;if(this.styles.dxfs.length)return this.styles.dxfs[i.dxfid]??null;const a=e?.[i.dxfid];return(typeof a?.numFmt=="string"?a.numFmt:a?.numFmt?.code??a?.numFmt?.formatCode)??null}isEntity(t){const s=this.type(t);return s!==null&&s!=="_error"&&s!=="_array"&&s!=="_localImage"&&s!=="_webimage"&&s!=="_hyperlink"&&s!=="_formattednumber"}}function C(o,t,s){let e=t,r=null;for(let n=0;n<s.length;n++){if(!o.isEntity(e))return{error:"#FIELD!"};const i=o.keyOf(e,String(s[n]));if(i===null)return{error:"#FIELD!"};const a=o.entries(e).get(i);if(a.t==="r"&&n<s.length-1){e=Number(a.v);continue}if(n<s.length-1)return{error:"#FIELD!"};r=m(o,a,0)}return r??{error:"#VALUE!"}}function m(o,t,s){switch(t.t){case"i":case"d":case"n":{const e=Number(t.v);return Number.isFinite(e)?e:{error:"#NUM!"}}case"b":return t.v==="1"||t.v==="true";case"e":return{error:y(t.v)};case"s":return t.v;case"a":{const e=o.arrays[Number(t.v)];if(!e||s>4)return{error:"#VALUE!"};const r=[];for(let n=0;n<e.r;n++){const i=[];for(let a=0;a<e.c;a++){const c=e.v[n*e.c+a],u=c?m(o,{t:c.t??"d",v:c.v},s+1):"";i.push(u&&typeof u=="object"&&u.rows?u.rows[0]?.[0]??"":u)}r.push(i)}return{rows:r}}case"r":{const e=Number(t.v),r=o.type(e),n=o.entries(e);if(r==="_error")return{error:o.view(e)?.text??"#VALUE!"};if(r==="_formattednumber"){const i=o.values[e].fallback;return i?m(o,i,s+1):{error:"#VALUE!"}}return r==="_array"?m(o,n.get("array")??{t:"a",v:"-1"},s+1):o.isEntity(e)||r==="_webimage"?{entity:e}:o.view(e)?.text??n.get("Text")?.v??""}case"spb":case"spba":return{error:"#VALUE!"};default:{const e=Number(t.v);return t.v!==""&&Number.isFinite(e)?e:t.v}}}function V(o){const t={dxfs:[],rPr:[],rSty:[]};if(!o)return t;const s=/<(?:\w+:)?dxfs\b[^>]*>([\s\S]*?)<\/(?:\w+:)?dxfs>/.exec(o)?.[1]??"";return t.dxfs=[...s.matchAll(/<((?:\w+:)?)dxf\b[^>]*?(?:\/>|>([\s\S]*?)<\/\1dxf>)/g)].map(e=>{const r=/<(?:\w+:)?numFmt\b[^>]*\bformatCode="([^"]*)"/.exec(e[2]??"")?.[1];return r===void 0?null:f(r)}),t.rPr=[...o.matchAll(/<rPr\b([^>]*)\/?>/g)].map(e=>({n:f(/\bn="([^"]*)"/.exec(e[1])?.[1]??""),t:h(e[1])??"s"})),t.rSty=[...o.matchAll(/<rSty\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rSty>)/g)].map(e=>{const r=/\bdxfid="(\d+)"/.exec(e[1])?.[1],n=[...(e[2]??"").matchAll(/<rpv\b[^>]*\bi="(\d+)"[^>]*>([\s\S]*?)<\/rpv>/g)].map(i=>({i:Number(i[1]),v:f(i[2])}));return{dxfid:r===void 0?null:Number(r),rpv:n}}),t}function _(o){const t=new Map,s=r=>{const n=new Map;for(const i of r.matchAll(/<key\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/key>/g)){const a=new Map;for(const c of i[2].matchAll(/<flag\b[^>]*\bname="([^"]*)"[^>]*\bvalue="([^"]*)"/g))a.set(c[1],c[2]==="1"||c[2]==="true");n.set(f(i[1]),a)}return n},e=/<global\b[^>]*>([\s\S]*?)<\/global>/.exec(o);e&&t.set("",s(e[1]));for(const r of o.matchAll(/<type\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/type>/g))t.set(f(r[1]),s(r[2]));return t}function y(o){return/^#/.test(o)?o.toUpperCase():w[Number(o)]??g[Number(o)]??"#VALUE!"}function I(o,t){const s=[t.get("_Icon")?.v,t.get("%EntityDomainIdString")?.v,t.get("%ProviderInfo")?.v,t.get("%DataProviderString")?.v,o].filter(Boolean).join(" ").toLowerCase();return/stock|financ|bank|exchange|ticker|fund/.test(s)?"stock":/geo|map|country|city|place|globe|location|region/.test(s)?"geography":/currenc|money|coin/.test(s)?"currency":"entity"}async function T(o,t){if(!t.meta||!t.rv||!t.struct||!/<s\b[^>]*\bt="(?!_localImage")/.test(t.struct))return null;const s=o.has("xl/_rels/workbook.xml.rels")?await o.text("xl/_rels/workbook.xml.rels"):"",e=n=>{for(const i of s.matchAll(/<Relationship\b[^>]*\/>/g)){if(!i[0].includes(`Type="${n.type}"`))continue;const a=/\bTarget="([^"]+)"/.exec(i[0])?.[1];if(a)return a.startsWith("/")?a.slice(1):`xl/${a.replace(/^\.\//,"")}`}return n.path},r=async n=>{const i=e(N[n]);return o.has(i)?o.text(i):null};return new E({...t,spb:await r("spb"),spbStruct:await r("spbStruct"),array:await r("array"),styles:await r("styles")})}function M(o,t,s,e){const r=o.richValues,n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const i=r.indexOfVm(n);return i>=0&&r.isEntity(i)?new x(r,i):null}function D(o,t){const s=o.richValues,e=s.vmOfIndex(t);if(e>0)return e;o.richNew??=[];let r=o.richNew.findIndex(i=>i.rv===t);r<0&&(r=o.richNew.push({rv:t})-1);const n=(o.richSource?.vmCount??0)+r+1;return s.added.set(n,t),n}const R={4:4,8:8,9:11,10:12,11:14,12:13,13:9,14:10,17:10};function U(o){const t=o.richValues;if(t){for(const s of o.sheets)if(s.valueMeta!==null)for(const[e,r]of s.valueMeta){const n=t.indexOfVm(r);if(n<0||t.type(n)!=="_error")continue;const i=R[Number(t.entries(n).get("errorType")?.v)],a=Math.floor(e/16384),c=e-a*16384,u=s.kind(a,c);i!==void 0&&(u&7)===4&&s.setCell(a,c,u,i)}}}function P(o,t,s,e){const r=o.richValues;if(!r||t.valueMeta===null)return null;const n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const i=r.indexOfVm(n);if(i<0)return null;const a=t.formula(s,e),c=a?.f??a?.sf??"",u=r.view(i,/(?:^|[^\w.])(?:_xlfn\.)?(?:_xlws\.)?PY\(/i.test(c));return u?{rich:r,index:i,view:u}:null}export{N as RICH_PARTS,E as RichValues,U as adoptRichErrors,P as cellRich,D as entityVm,y as errorText,C as fieldValue,T as readRichValues,M as richValueAt,k as vmIndex};
|
package/cells/selection-modes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MAX_COLS as
|
|
1
|
+
import{MAX_COLS as x,MAX_ROWS as m}from"../core/address.js";import{tableOfSelection as T}from"./table-rows.js";import{viewGet as z}from"./book-view.js";const M=e=>e.statusBar?.refreshFlags();function E(e,r){e.selMode=e.selMode===r?null:r,e.addBase=e.selMode==="add"?e.sel.ranges.slice():null,M(e.app)}function V(e){!e.selMode&&!e.endMode||(e.selMode=null,e.addBase=null,e.endMode=!1,M(e.app))}function Y(e){e.endMode=!e.endMode,M(e.app)}function H(e){e.scrollLock=!e.scrollLock,M(e.app)}const C=e=>e.r0===e.r1&&e.c0===e.c1;function b(e,r,t,o){if(o||e.selMode==="extend"){e.moveTo(r,t,!0);return}if(e.selMode==="add"){const n=Math.max(0,Math.min(r,m-1)),s=Math.max(0,Math.min(t,x-1)),f=e.sel.ranges[e.sel.ranges.length-1];(e.addBase===null||!C(f))&&(e.addBase=e.sel.ranges.slice()),e.grid.setSelection({ranges:[...e.addBase,e._withMerges({r0:n,c0:s,r1:n,c1:s})],row:n,col:s}),e.extent={row:n,col:s},e.grid.ensureVisible(n,s);return}e.moveTo(r,t,!1)}function W(e,r,t,{jump:o=!1,shift:n=!1}={}){const s=r==="col"&&e.grid.rtl?-t:t,{sheet:f}=e;if(o&&!n&&e.book.view?.deselectKeys&&k(e,r,s))return;const c=n||e.selMode==="extend";if(e.scrollLock&&!o){X(e,r,s);return}const a=c?e.extent:{row:e.sel.row,col:e.sel.col},w=e.endMode;w&&(e.endMode=!1,M(e.app));const l=o||w;let{row:i,col:g}=a;const u=e.sel.ranges[e.sel.ranges.length-1],h=c&&(r==="col"?u.r0===0&&u.r1===m-1:u.c0===0&&u.c1===x-1);h&&(r==="col"?i=e.sel.row:g=e.sel.col);const d=!l&&f.mergeAt(i,g);if(d&&(!c&&e.mergeEntry?.selection===e.sel&&({row:i,col:g}=e.mergeEntry),r==="row"?i=s>0?d.r1:d.r0:g=s>0?d.c1:d.c0),r==="row"?i=l?f.jumpRow(i,g,s,!0):e._step(r,i,s):g=l?f.jumpCol(i,g,s,!0):e._step(r,g,s),h){if(!e._selectable(i,g))return;e._extendAxis(r,e.sel[r],r==="col"?g:i),e.grid.ensureVisible(i,g)}else b(e,i,g,n)}function k(e,r,t){const{sel:o}=e;if(o.ranges.reduce((w,l)=>w+(l.r1-l.r0+1)*(l.c1-l.c0+1),0)<2)return!1;const s=_(o.ranges,{r0:o.row,c0:o.col,r1:o.row,c1:o.col}),f=o.row+(r==="row"?t:0),c=o.col+(r==="col"?t:0),a=y(s,f,c)?{row:f,col:c}:{row:s[s.length-1].r0,col:s[s.length-1].c0};return e.grid.setSelection({ranges:s,row:a.row,col:a.col}),e.grid.ensureVisible(a.row,a.col),!0}function X(e,r,t){const{grid:o,sheet:n}=e;if(o.pageLayout){r==="row"?o.scrollTo(o.scrollX,o.scrollY+t*n.rows.defaultSize):o.scrollTo(o.scrollX+t*o.displayCols.defaultSize,o.scrollY);return}const s=o._frozen();if(r==="row"){const f=n.rows.indexAt(o.scrollY+s.h),c=Math.max(n.frozenRows,e._step("row",f,t));o.scrollTo(o.scrollX,n.rows.offsetOf(c)-s.h)}else{const f=o.displayCols.indexAt(o.scrollX+s.w),c=Math.max(n.frozenCols,e._step("col",f,t));o.scrollTo(o.displayCols.offsetOf(c)-s.w,o.scrollY)}}function I(e,r,t,o){const{grid:n,sheet:s}=e,f=o||e.selMode==="extend"?e.extent:{row:e.sel.row,col:e.sel.col},c=r==="col",a=c?n.displayCols:s.rows,w=c?n.scrollX:n.scrollY,l=n.pageLayout?null:n._bands(r).find(h=>h.part==="main"),i=l?l.size:c?n.cssW-n.rowHeaderW:n.cssH-n.colHeaderH;let g=t*i/n.zoom;if(l&&i>0){const h=a.indexAt(l.origin),d=l.origin+g;let p=a.indexAt(Math.max(0,d));t<0&&a.offsetOf(p)<d&&p++,p===h&&(p=e._step(r,h,t)),g=a.offsetOf(p)-l.origin,g===0&&t<0&&(g=-i/n.zoom)}const u=a.indexAt(Math.max(0,a.offsetOf(f[r])+g));c?n.scrollTo(w+g,n.scrollY):n.scrollTo(n.scrollX,w+g),b(e,c?f.row:u,c?u:f.col,o)}function P(e,r,t){const{sheet:o}=e,n=t||e.selMode==="extend"?e.extent:{row:e.sel.row};b(e,r?o.frozenRows:n.row,o.frozenCols,t)}function U(e,r){const{sheet:t}=e;b(e,Math.max(t.maxRow,0),Math.max(t.maxCol,0),r)}function L(e,r){const{sel:t}=e;if(t.ranges.length!==1)return!1;const o=t.ranges[0];if(o.r0===0&&o.r1===m-1)return!1;const n=T(e.app,o);if(!n)return!1;const s=r?o.c0:n.c0,f=r?o.c1:n.c1,c=n.r0+n.headerRows,a=n.r1-n.totalsRows,w=(g,u)=>o.r0===g&&o.r1===u&&o.c0===s&&o.c1===f,l=!C(o)||e.tableSelection===t;if(l&&w(n.r0,n.r1))return r?!1:(e._setSingle({r0:0,c0:0,r1:m-1,c1:x-1},t.row,t.col),!0);const i=t.row>=c&&t.row<=a&&!(l&&w(c,a));return e._setSingle({r0:i?c:n.r0,r1:i?a:n.r1,c0:s,c1:f},t.row,t.col),e.tableSelection=e.sel,!0}function D(e){if(L(e,!0))return;const{sel:r}=e,t=r.ranges.map(o=>({r0:0,c0:o.c0,r1:m-1,c1:o.c1}));e.grid.setSelection({ranges:t,row:r.row,col:r.col}),e.extent={row:m-1,col:t[t.length-1].c1}}function F(e){const{sel:r}=e,t=r.ranges.map(o=>({r0:o.r0,c0:0,r1:o.r1,c1:x-1}));e.grid.setSelection({ranges:t,row:r.row,col:r.col}),e.extent={row:t[t.length-1].r1,col:x-1}}function G(e){const{sel:r}=e,t=r.ranges.find(a=>r.row>=a.r0&&r.row<=a.r1&&r.col>=a.c0&&r.col<=a.c1)??r.ranges[r.ranges.length-1],o=[[t.r0,t.c0],[t.r0,t.c1],[t.r1,t.c1],[t.r1,t.c0]];let n=o.findIndex(([a,w])=>a===r.row&&w===r.col);n=n<0?0:n;let s=(n+1)%4;for(;o[s][0]===r.row&&o[s][1]===r.col&&s!==n;)s=(s+1)%4;const[f,c]=o[s];e.grid.setSelection({ranges:r.ranges,row:f,col:c}),e.extent={row:f===t.r0?t.r1:t.r0,col:c===t.c0?t.c1:t.c0},e.grid.ensureVisible(f,c)}function K(e){const{sel:r}=e,t=e._withMerges({r0:r.row,c0:r.col,r1:r.row,c1:r.col});e.grid.setSelection({ranges:[t],row:r.row,col:r.col}),e.extent={row:r.row,col:r.col},e.grid.ensureVisible(r.row,r.col)}const R={down:[1,0],up:[-1,0],right:[0,1],left:[0,-1],none:[0,0]};function N(e,r){const[t,o]=R[z(e.book,"enterDirection")]??R.down;return r?[-t,-o]:[t,o]}function j(e,r,t){const{sel:o}=e;let n=o.ranges.length-1;for(let d=0;d<o.ranges.length;d++){const p=o.ranges[d];o.row>=p.r0&&o.row<=p.r1&&o.col>=p.c0&&o.col<=p.c1&&(n=d)}const s=o.ranges[n],f=d=>d.r0===0&&d.r1>=m-1?Math.min(d.r1,Math.max(e.sheet.maxRow,d.r0)):d.r1,c=d=>d.c0===0&&d.c1>=x-1?Math.min(d.c1,Math.max(e.sheet.maxCol,d.c0)):d.c1,a=f(s),w=c(s);let{row:l,col:i}=o;const g=e.sheet.mergeAt(l,i),u=d=>{const p=o.ranges.length,S=o.ranges[(n+(d?1:-1)+p)%p],A={row:f(S),col:c(S)};return d?{row:S.r0,col:S.c0}:A};r!==0?(l=r>0?(g?g.r1:l)+1:(g?g.r0:l)-1,l>a?(l=s.r0,i+=1,i>w&&({row:l,col:i}=u(!0))):l<s.r0&&(l=a,i-=1,i<s.c0&&({row:l,col:i}=u(!1)))):t!==0&&(i=t>0?(g?g.c1:i)+1:(g?g.c0:i)-1,i>w?(i=s.c0,l+=1,l>a&&({row:l,col:i}=u(!0))):i<s.c0&&(i=w,l-=1,l<s.r0&&({row:l,col:i}=u(!1))));const h=e.sheet.mergeAt(l,i);h&&(l=h.r0,i=h.c0),e.grid.setSelection({ranges:o.ranges,row:l,col:i}),e.grid.ensureVisible(l,i)}function q(e,r){const{sheet:t,book:o,sel:n}=e,s=Math.max(t.maxRow,n.row),f=Math.max(t.maxCol,n.col);let{row:c,col:a}=n;const w=(s+1)*(f+1);for(let l=0;l<Math.min(w,5e5);l++)if(a+=r,a>f?(a=0,c=c>=s?0:c+1):a<0&&(a=f,c=c<=0?s:c-1),o.styles.get(t.style(c,a)).unlocked===!0)return e.moveTo(c,a),!0;return!1}function _(e,r){const t=[];for(const o of e){if(r.r1<o.r0||r.r0>o.r1||r.c1<o.c0||r.c0>o.c1){t.push(o);continue}o.r0<r.r0&&t.push({r0:o.r0,c0:o.c0,r1:r.r0-1,c1:o.c1}),o.r1>r.r1&&t.push({r0:r.r1+1,c0:o.c0,r1:o.r1,c1:o.c1});const n=Math.max(o.r0,r.r0),s=Math.min(o.r1,r.r1);o.c0<r.c0&&t.push({r0:n,c0:o.c0,r1:s,c1:r.c0-1}),o.c1>r.c1&&t.push({r0:n,c0:r.c1+1,r1:s,c1:o.c1})}return t}const y=(e,r,t)=>e.some(o=>r>=o.r0&&r<=o.r1&&t>=o.c0&&t<=o.c1);function J(e,r){const{grid:t,sel:o}=e,n=_(r.before,r.cut);if(n.length===0){const c={r0:r.cut.r0,c0:r.cut.c0,r1:r.cut.r0,c1:r.cut.c0};t.setSelection({ranges:[c],row:c.r0,col:c.c0});return}const s=y(n,o.row,o.col),f=n[n.length-1];t.setSelection({ranges:n,row:s?o.row:f.r0,col:s?o.col:f.c0})}function Q(e,r){let{ranges:t}=e;const o=r.selectionPolicy,n=r.selectionUnit;return o==="single"?t=[{r0:e.row,c0:e.col,r1:e.row,c1:e.col}]:o==="range"&&(t=[t[t.length-1]]),n==="row"?t=t.map(s=>({r0:s.r0,c0:0,r1:s.r1,c1:x-1})):n==="column"&&(t=t.map(s=>({r0:0,c0:s.c0,r1:m-1,c1:s.c1}))),t===e.ranges?e:{...e,ranges:t}}export{W as arrow,V as clearSelMode,K as collapseToActive,Q as constrainSelection,j as cycleInSelection,N as enterStep,J as finishDeselect,P as home,y as inRanges,U as lastCell,G as nextCorner,q as nextUnlocked,I as page,D as selectColumn,F as selectRow,L as selectTable,E as setSelMode,_ as subtractRange,Y as toggleEndMode,H as toggleScrollLock};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MAX_COLS as b,MAX_ROWS as w}from"../core/address.js";import{rectsTouch as l}from"./block.js";const R="This operation is not allowed. The operation is attempting to shift cells in a table on your worksheet.",M="We can't do that to a merged cell.",S="To prevent possible loss of data, cells can't be shifted off the end of the sheet.",T="You can't change part of an array.",A="The header row of a table cannot be deleted on its own.";function _(s,t,n,i,a=0,u=b-1){for(const r of s.engine?.tables.values()??[])if(r.sheet===t&&r.headerRows&&r.c0<=u&&r.c1>=a&&n<=r.r0&&i>=r.r0&&i<r.r1)return!0;return!1}function O(s,t,n,i,a,u=[]){const r=i==="down";if(r&&a<0&&_(s,t,n.r0,n.r1,n.c0,n.c1))return A;const g=r?n.r1-n.r0+1:n.c1-n.c0+1,f=r?{r0:n.r0,r1:w-1,c0:n.c0,c1:n.c1}:{r0:n.r0,r1:n.r1,c0:n.c0,c1:b-1},d=o=>r?o.c0>=n.c0&&o.c1<=n.c1:o.r0>=n.r0&&o.r1<=n.r1,c=r?n.r0:n.c0,h=o=>r?o.r0:o.c0,p=o=>r?o.r1:o.c1,m=o=>{if(a>0)return h(o)<c&&p(o)>=c;const e=c+g-1;return h(o)<=e&&p(o)>e||h(o)<c&&p(o)>=c};for(const o of t.merges)if(l(o,f)&&(!d(o)||m(o)))return M;if(u.some(o=>o.anchor?.sheet===t&&o.renderedRange&&l(o.renderedRange,f)))return"Cannot change this part of a PivotTable report.";if(s.engine){const o=e=>r?e.c0===n.c0&&e.c1===n.c1:e.r0===n.r0&&e.r1===n.r1;for(const e of s.engine.tables.values())if(!(e.sheet!==t||!l(e,f))&&(!d(e)||m(e)&&!o(e)))return R}if(t.spills){for(const o of t.spills.values())if(o.fixed&&l(o,f)&&(!d(o)||m(o)))return T}if(a>0){const o=r?t.maxRow:t.maxCol,e=r?w:b;if(o+g>=e)return S}return null}export{T as MSG_ARRAY,A as MSG_HEADER,M as MSG_MERGE,S as MSG_OFF,R as MSG_TABLE,O as checkBandShift,_ as deletesTableHeader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resizeTable as R,tablesOf as p}from"../core/tables.js";import{undoGroup as k}from"./undo-group.js";import{freeColumnName as T}from"../core/default-names.js";import{showMessage as M}from"./ui-kit.js";function B(t,o){const{book:s}=t;return s.engine?p(s,s.sheet).find(c=>o.r0>=c.r0&&o.r1<=c.r1&&o.c0>=c.c0&&o.c1<=c.c1)??null:null}function d(t,o,s,c,u){const{book:e}=t;k(e,"table-insert",()=>{const r=e.undoStack[e.undoStack.length-1];if(u(),e.undoStack[e.undoStack.length-1]===r)return;if(c>0&&o.headerRows){const n=new Set(o.columns.map(f=>f.toLowerCase()));e.transact("entry",f=>{for(let l=o.c1+1;l<=o.c1+c;l++){const m=T(n);n.add(m.toLowerCase()),e.setInput(f,o.r0,l,m)}})}const i=R(e,o,{r0:o.r0,c0:o.c0,r1:o.r1+s,c1:o.c1+c});i&&M(t,i)}),t.grid.invalidate()}function I(t,o,s){const{commands:c}=t,u=o.r0+o.headerRows,e=o.r1-o.totalsRows,r=Math.min(Math.max(s.r0,u),e),i=Math.max(Math.min(s.r1,e),r),n=i-r+1,f=s.c1-s.c0+1,l=(a,w)=>({r0:a,r1:w,c0:o.c0,c1:o.c1}),m=(a,w)=>({r0:o.r0,r1:o.r1,c0:a,c1:w}),h=[["Table Rows Above",()=>c.shiftCells("down",1,l(r,r+n-1))]];i===e&&h.push(["Table Rows Below",()=>{o.totalsRows?c.shiftCells("down",1,l(e+1,e+n)):d(t,o,n,0,()=>c.shiftCells("down",1,l(o.r1+1,o.r1+n)))}]),h.push(["Table Columns to the Left",()=>c.shiftCells("right",1,m(s.c0,s.c1))]),s.c1===o.c1&&h.push(["Table Columns to the Right",()=>d(t,o,0,f,()=>c.shiftCells("right",1,m(o.c1+1,o.c1+f)))]);const b=n===e-u+1,C=s.c0===o.c0&&s.c1===o.c1;return{insert:h,remove:[["Table Rows",b?null:()=>c.shiftCells("down",-1,l(r,i))],["Table Columns",C?null:()=>c.shiftCells("right",-1,m(s.c0,s.c1))]]}}export{I as tableMenuItems,B as tableOfSelection};
|
package/cells/text-layout.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import{cssFont as V}from"../core/styles.js";import{MAX_COLS as Y}from"../core/address.js";import{styleOfRun as Z}from"./rich-runs.js";import{registerSection as $}from"./sections.js";const H=6,
|
|
2
|
-
`)<0)return l;let
|
|
3
|
-
`&&l.add(n);return l}function q(e,t,l,
|
|
4
|
-
`){
|
|
5
|
-
`).forEach((z,
|
|
6
|
-
`).forEach((
|
|
7
|
-
`),p=Math.max(
|
|
8
|
-
`)
|
|
1
|
+
import{cssFont as V}from"../core/styles.js";import{MAX_COLS as Y}from"../core/address.js";import{styleOfRun as Z}from"./rich-runs.js";import{registerSection as $}from"./sections.js";const H=6,B=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]/,x=/[\p{L}]/u;function ut(e,t){if(t===null||!B.test(t)||e===1)return null;if(e===2)return"rtl";const l=x.exec(t);return l!==null&&B.test(l[0])?"rtl":null}function ht(e,t){if(e===255||e===90||e===180)return 0;const l=e>90?90-e:e;return t/Math.tan(Math.abs(l)*Math.PI/180)*(l>0?1:-1)}function ct(e,t,l){for(let r=0;r<t.length;r+=6){const[n,a,i,f,o,s]=[t[r],t[r+1],t[r+2],t[r+3],t[r+4],t[r+5]],u=a,c=a+f;s.fill!==null&&(e.beginPath(),e.moveTo(n,c),e.lineTo(n+i,c),e.lineTo(n+i+o,u),e.lineTo(n+o,u),e.closePath(),e.fillStyle=s.fill,e.fill());const p=s.borders;if(p==null)continue;const d=(h,F,A,T,m)=>{h&&(e.beginPath(),e.moveTo(F,A),e.lineTo(T,m),e.strokeStyle=h.color,e.lineWidth=Math.max(1,Math.round(l))*(h.style==="medium"?2:h.style==="thick"?3:1),e.stroke())};d(p.l,n+.5,c,n+o+.5,u),d(p.r,n+i+.5,c,n+i+o+.5,u),d(p.t,n+o,u+.5,n+i+o,u+.5),d(p.b,n,c+.5,n+i,c+.5)}}function dt(e,t){if(!B.test(e))return e;const r=(e.match(/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+(?:\s+[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+)*|[^\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+/g)??[]).map(n=>B.test(n)?[...n].reverse().join(""):n);return(t?r.reverse():r).join("")}const tt=e=>e.hAlign==="justify"||e.hAlign==="distributed"||e.vAlign==="justify"||e.vAlign==="distributed";function pt(e,t,l,r,n,a){let i=n;for(let f=r+1;f<Y&&!((t.kind(l,f)&15)!==0||t.mergeAt(l,f)!==null||e.book.styles.get(t.style(l,f)).hAlign!=="centerContinuous");f++)i+=Math.round((e.displayCols??t.cols).sizeOf(f)*a);return i}function et(e,t,l,r,n){const a=t.split(/\s+/).filter(Boolean);if(a.length<2){e.fillText(t,l+(r-n)/2,e._by);return}const i=a.reduce((s,u)=>s+e.measureText(u).width,0),f=(r-i)/(a.length-1);let o=l;for(const s of a)e.fillText(s,o,e._by),o+=e.measureText(s).width+f}function gt(e,t,l,r,n,a,i,f,o,s,u,c){const p=r.indent>0?Math.round(r.indent*H*c):0;let d=a+s,h=a+f-s;p>0&&(n==="left"||n==="justify"?d+=p:n==="right"?h-=p:n==="distributed"&&(d+=p,h-=p));const F=Math.max(1,h-d),A=e._wrapLines(t,r._font,l,F),T=Math.round(u*1.26),m=A.length*T,w=r.vAlign??"bottom";let _,M=T;w==="top"?_=i:w==="center"?_=i+(o-m)/2:w==="justify"?(_=i,A.length>1&&m<o&&(M=(o-T)/(A.length-1))):w==="distributed"?(_=A.length===1?i+(o-T)/2:i,A.length>1&&m<o&&(M=(o-T)/(A.length-1))):_=i+o-m,t.save(),t.beginPath(),t.rect(a,i,f,o),t.clip(),t.textAlign="left";const E=nt(l,A);for(let k=0;k<A.length;k++){const g=_+k*M+Math.round(T*.8);if(g+T<i||g-T>i+o)continue;const O=A[k],S=t.measureText(O).width;let b=d;if(n==="center"||n==="centerContinuous"?b=d+(F-S)/2:n==="right"&&(b=h-S),t._by=g,n==="distributed"||n==="justify"&&!E.has(k)&&S<F){n==="justify"&&O.trim().split(/\s+/).length<2?t.fillText(O,d,g):et(t,O,d,F,S),(r.underline||r.strike)&&e._decorate(t,r,d,g,n==="distributed"&&O.trim().split(/\s+/).length<2?S:F,u);continue}t.fillText(O,b,g),(r.underline||r.strike||r.ext!==void 0)&&e._decorate(t,r,b,g,S,u)}t.restore(),t.textAlign="left"}function nt(e,t){const l=new Set([t.length-1]);if(e.indexOf(`
|
|
2
|
+
`)<0)return l;let r=0;for(let n=0;n<t.length;n++)r=e.indexOf(t[n],r)+t[n].length,e[r]===`
|
|
3
|
+
`&&l.add(n);return l}function q(e,t,l,r){const n=[],a=t===null?[{at:0}]:t[0].at>0?[{at:0},...t]:t;for(let i=0;i<a.length;i++){const f=a[i+1]?.at??e.length;if(f<=a[i].at)continue;const o=Z(l,a[i]),s=o.fontSize*r;n.push({text:e.slice(a[i].at,f),look:o,px:s,font:V(o,o.vertAlign?s*.66:s),shift:o.vertAlign==="superscript"?-s*.34:o.vertAlign==="subscript"?s*.1:0})}return n}function ot(e,t,l,r,n,a,i,f,o,s,u,c){const p=q(l,r,n,u),d=[];for(const g of p)for(const O of g.text)d.push({ch:O,seg:g});const h=[[]],F=Math.round(n.fontSize*u*1.28),A=Math.max(1,Math.floor(s/F));let T=[];const m=()=>{const g=h[h.length-1];g.length>0&&g.length+T.length>A?h.push([...T]):g.push(...T),T=[]};for(const g of d){if(g.ch===`
|
|
4
|
+
`){m(),h.push([]);continue}if(!n.wrap){h[h.length-1].push(g);continue}T.push(g),g.ch===" "&&m()}T.length>0&&m();const w=Math.round(n.fontSize*u*1.6),_=h.length*w,M=n.indent>0?Math.round(n.indent*H*u):0;let E;a==="right"?E=i+o-_-M:a==="left"?E=i+M:E=i+(o-_)/2;const k=n.vAlign??"bottom";t.save(),t.beginPath(),t.rect(i,f,o,s),t.clip(),t.textAlign="center",h.forEach((g,O)=>{const S=g.length*F;let b;k==="top"?b=f:k==="center"?b=f+(s-S)/2:b=f+s-S;const I=E+O*w+w/2;g.forEach((v,y)=>{t.font=v.seg.font,t.fillStyle=v.seg.look.color??c,t.fillText(v.ch,I,b+y*F+F*.8)})}),t.restore(),t.textAlign="left"}function mt(e,t,l,r,n,a,i,f,o,s,u,c){if(n.rotation===255){ot(e,t,l,r,n,a,i,f,o,s,u,c);return}const p=n.rotation>90?90-n.rotation:n.rotation,d=p*Math.PI/180,h=Math.abs(Math.sin(d)),F=Math.abs(Math.cos(d)),A=q(l,r,n,u),T=Math.max(...A.map(C=>C.px),n.fontSize*u),m=Math.round(T*1.26),w=Math.round(2*u),_=h>.01?(s-w*2)/h-m*F/h:1/0,M=[{parts:[],width:0}];for(const C of A)t.font=C.font,C.text.split(`
|
|
5
|
+
`).forEach((z,L)=>{L>0&&M.push({parts:[],width:0});const R=n.wrap||tt(n),X=R?z.match(/\S+\s*|\s+/g)??[]:[z];for(const K of X){const G=t.measureText(K).width,Q=M[M.length-1];R&&Q.width>0&&Q.width+G>_&&M.push({parts:[],width:0});const U=M[M.length-1];U.parts.push({seg:C,text:K,width:G}),U.width+=G}});const E=M.length*m,k=Math.max(...M.map(C=>C.width)),g=k*h+E*F,O=n.vAlign??"bottom",S=O==="top"?Math.max(0,s-g-w*2):O==="center"?Math.max(0,s-g-w*2)/2:0,b=p>0,I=Math.abs(p)===90,v=n.hAlign??(it(p)?"right":"left"),y=n.indent>0?Math.round(n.indent*H*u):0,P=E*h;let j;v==="right"?j=o-P-y-(b?0:5):v==="center"||v==="centerContinuous"?j=o/2+(I?P/2:0)-(b?0:P/2):j=(b?P:0)+w+y+0,!b&&v==="left"&&(j=P+w+y);const W=h>.01&&F>.01?S*(F/h):0;t.save(),t.beginPath();const N=k*F+E*h+W+o;if(t.rect(b?i:i-N,f,b?N:N+o,s),t.clip(),I){const C=v==="right"?i+o-E-w-y:v==="center"||v==="centerContinuous"?i+(o-E)/2:i+w+y,D=(v==="justify"||v==="distributed")&&M.length>1?(o-w*2-m)/(M.length-1):m,z=b?C:C+(M.length-1)*D+m,L=b?f+s-w-S:f+s-w-S-k;t.translate(z,L),t.rotate(-d),t.textAlign="left",M.forEach((R,X)=>J(e,t,R,X*D+m-m*.22,k,v,c))}else if(b)t.translate(i+j+W-P+E*h,f+s-w-S-E*F),t.rotate(-d),t.textAlign="left",M.forEach((C,D)=>J(e,t,C,(D+1)*m-m*.22,k,v,c));else{const C=i+j-W,D=f+s-w-S-E*F;t.translate(C,D),t.rotate(-d),t.textAlign="left",M.forEach((z,L)=>J(e,t,z,(L+1)*m-m*.22-0,k,v,c,-k))}t.restore(),t.textAlign="left"}const it=e=>e===90||e<0&&e>-90;function J(e,t,l,r,n,a,i,f=0){let o=f;a==="center"||a==="centerContinuous"?o+=(n-l.width)/2:a==="right"&&(o+=n-l.width);for(const s of l.parts)t.font=s.seg.font,t.fillStyle=s.seg.look.color??i,t.fillText(s.text,o,r+s.seg.shift),(s.seg.look.underline||s.seg.look.strike)&&e._decorate(t,{underline:s.seg.look.underline??0,strike:s.seg.look.strike},o,r,s.width,s.seg.px),o+=s.width}function st(e,t,l,r,n,a){const i=[{parts:[],width:0,px:0}],f=(o,s,u)=>{const c=i[i.length-1];c.parts.push({...o,text:s,width:u}),c.width+=u,c.px=Math.max(c.px,o.px)};for(const o of t){if(e.font=o.font,!l.wrap){f(o,o.text.replace(/\n/g," "),e.measureText(o.text.replace(/\n/g," ")).width);continue}o.text.split(`
|
|
6
|
+
`).forEach((u,c)=>{c>0&&i.push({parts:[],width:0,px:0});for(const p of u.match(/\S+\s*|\s+/g)??[]){const d=e.measureText(p).width,h=i[i.length-1];h.width>0&&h.width+d>n&&i.push({parts:[],width:a?a.width(e,i,l,r):0,px:0,hang:a!==null}),f(o,p,d)}})}for(const o of i)o.px===0&&(o.px=l.fontSize*r);return i}function wt(e,t,l,r,n=1/0,a=null){const i=q(t,l,r,1);if(r.wrap)return st(e,i,r,1,n,a).reduce((s,u)=>Math.max(s,u.width),0);let f=0,o=0;for(const s of i)e.font=s.font,s.text.split(`
|
|
7
|
+
`).forEach((c,p)=>{p>0&&(f=Math.max(f,o),o=0),o+=e.measureText(c).width});return Math.max(f,o)}function Mt(e,t,l){const r=l.fontSize;if(l.rotation===255){const c=t.split(`
|
|
8
|
+
`),p=Math.max(...c.map(d=>d.length));return{w:c.length*Math.round(r*1.3)+4,h:p*Math.round(r*1.2)+4}}const a=(l.rotation>90?90-l.rotation:l.rotation)*Math.PI/180,i=Math.abs(Math.sin(a)),f=Math.abs(Math.cos(a)),o=t.split(`
|
|
9
|
+
`);e.font=V(l,r);const s=Math.max(...o.map(c=>e.measureText(c).width)),u=o.length*Math.round(r*1.26);return{w:s*f+u*i+4,h:s*i+u*f+4}}$("textOverflow",{sheet:{save:e=>e.noCellOverflow===!0?!0:void 0,load(e,t){t===!0&&(e.noCellOverflow=!0)}}});export{pt as acrossWidth,mt as paintRotatedText,ct as paintSlantedCells,gt as paintWrappedText,ut as readingDirection,st as richLines,wt as richWidth,Mt as rotatedSize,ht as slantOf,dt as visualOrder,tt as wrapsByAlign};
|
package/cells/ui-kit.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{el as x,showMessage as k}from"../ui/dialogs.js";import{t as h}from"../i18n/index.js";let f=!1;function g(){if(f)return;f=!0;const t=document.createElement("style");t.textContent=`
|
|
2
|
+
.drag-tip { position: absolute; z-index: 7; padding: 2px 6px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: var(--shadow); border-radius: 3px; font-size: 11px; white-space: nowrap; pointer-events: none; }
|
|
3
|
+
.corner-btn { position: absolute; z-index: 6; display: flex; align-items: center; gap: 1px; height: 18px; padding: 0 2px; background: var(--menu); color: var(--ink-soft); border: 1px solid var(--panel-line); border-radius: 3px; cursor: default; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); }
|
|
4
|
+
.corner-btn:hover { background: var(--hover); border-color: var(--field-line); }
|
|
5
|
+
.corner-btn[hidden] { display: none; }
|
|
6
|
+
.corner-btn svg { display: block; }
|
|
7
|
+
.clip-form { display: grid; gap: 2px; min-width: 240px; }
|
|
8
|
+
.clip-form .dlg-row { min-height: 24px; }
|
|
9
|
+
.clip-form select.dlg-input, .clip-form input.dlg-input { width: auto; min-width: 0; }
|
|
10
|
+
.clip-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
|
|
11
|
+
.clip-group { border: 0; margin: 0 0 8px; padding: 0; }
|
|
12
|
+
.clip-group legend { padding: 0; margin-bottom: 2px; color: var(--ink-soft); font-size: 11px; }
|
|
13
|
+
.clip-lists { display: grid; grid-template-columns: 200px 1fr; gap: 12px; min-height: 240px; }
|
|
14
|
+
.clip-lists textarea { width: 100%; height: 200px; resize: none; }
|
|
15
|
+
`,document.head.append(t)}function M(){g()}const C="8sheets";function T(t,e,s=C){return t.shell?.setStatus(e),k(t,s,e),null}let n=null;function z(t,e,s,c){g(),(!n||n.parentElement!==t.grid.host)&&(n?.remove(),n=x("div",{class:"drag-tip"}),t.grid.host.append(n)),n.textContent=c,n.style.left=`${e+14}px`,n.style.top=`${s+12}px`,n.hidden=!1}function H(){n&&(n.hidden=!0)}const B={paste:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor"><rect x="2.5" y="2.5" width="9" height="10" rx="1"/><rect x="5" y="1" width="4" height="3" rx="0.5" fill="currentColor" stroke="none"/></svg>',fill:'<svg width="14" height="14" viewBox="0 0 14 14" fill="none" stroke="currentColor"><rect x="2" y="2" width="4" height="4"/><rect x="8" y="2" width="4" height="4"/><rect x="2" y="8" width="4" height="4"/><path d="M9 10h3M10.5 8.5v3"/></svg>'},E='<svg width="7" height="14" viewBox="0 0 7 14" fill="currentColor"><path d="M0.5 6l3 3 3-3z"/></svg>';function L(t,e,s,c,v){g(),m(t);const{grid:r,book:l}=t,i=x("button",{type:"button",class:"corner-btn",title:h(c),"aria-label":h(c)});i.innerHTML=`${B[s]}${E}`;const b=l.undoStack[l.undoStack.length-1],w=l.sheet,p={place(){if(t.book!==l||l.sheet!==w||l.undoStack[l.undoStack.length-1]!==b||t.controller.isEditing){m(t);return}const o=r.cellRect(e.r1,e.c1),d=o.x+o.w+2,a=o.y+o.h+2,u=d<r.rowHeaderW||a<r.colHeaderH||d>r.cssW-10||a>r.cssH-10;if(i.hidden=u,!u){const y=r.rtl?r.domRect({x:d,w:28}).x:d;i.style.left=`${y}px`,i.style.top=`${a}px`}},remove(){i.remove()}};return i.addEventListener("pointerdown",o=>{o.preventDefault(),o.stopPropagation()}),i.addEventListener("dblclick",o=>o.stopPropagation()),i.addEventListener("click",o=>{o.stopPropagation();const d=i.getBoundingClientRect();t.ribbon.openMenuAt(d.left,d.bottom+2,v())}),r.host.append(i),r.cornerButton=p,p.place(),r.invalidateTop(),p}function m(t){const{grid:e}=t;e.cornerButton&&(e.cornerButton.remove(),e.cornerButton=null)}const P=(t,e,s)=>[`${e?"✓ ":" "}${h(t)}`,s];export{C as APP_TITLE,P as checkedItem,M as ensureClipStyle,m as hideCornerButton,H as hideTip,L as showCornerButton,T as showMessage,z as showTip};
|
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 $}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};
|
|
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 l=d=>`calc(${d}px * var(--ui-scale))`,n={titlebar:l(38),tabs:l(28),ribbon:"auto","formula-bar":i(o,"formulaBarExpanded")?"auto":l(26),"ds-bar-host":"auto",workspace:"minmax(0, 1fr)",sheetbar:l(24),statusbar:l(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,s=e.el("app");s.classList.toggle("no-formula-bar",!i(t,"showFormulaBar")),s.classList.toggle("bk-fx-expanded",i(t,"formulaBarExpanded"));const l=e.el("statusbar");l.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");s.style.outline=n?`${n.width??1}px ${n.style??"solid"} ${n.color??"currentColor"}`:"",s.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,s=o.host,l=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=l||n||d||m?{showMax:l,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,s.classList.toggle("bk-sb-skin",h==="skin"),s.classList.toggle("bk-sb-mobile",h==="mobile");const g=i(t,"scrollColors");s.classList.toggle("bk-sb-colors",!!g),e.el("sheetbar")?.classList.toggle("bk-sb-colors",!!g);for(const a of[s,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:s,grid:l}=e;s.sheet[t]=o,s.sheet.viewChanged=!0,s.dirty=!0,l[t]=o,l.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:s}=e.book,l={horizontal:s.gridlineAxes?.horizontal!==!1,vertical:s.gridlineAxes?.vertical!==!1,[t]:o};s.gridlineAxes=l.horizontal&&l.vertical?void 0:l,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:s}=e,l=e._frozen();if(t==="row"){const n=s.rows;let r=n.indexAt(e.scrollY+l.h)+o;for(;r>s.frozenRows&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(e.scrollX,n.offsetOf(Math.max(s.frozenRows,r))-l.h)}else{const n=e.displayCols;let r=n.indexAt(e.scrollX+l.w)+o;for(;r>s.frozenCols&&r<n.count&&n.sizeOf(r)===0;)r+=o;e.scrollTo(n.offsetOf(Math.max(s.frozenCols,r))-l.w,e.scrollY)}}function W(e){if(e.barEnds)return;e.barEnds=!0;const t=(o,s,l)=>{const n=document.createElement("button");n.type="button",n.className=`sb-end ${l?"sb-end-start":"sb-end-stop"}`,n.tabIndex=-1,n.setAttribute("aria-label",w(s==="row"?l?"Scroll up one row":"Scroll down one row":l?"Scroll left one column":"Scroll right one column")),n.addEventListener("pointerdown",r=>{r.preventDefault(),r.stopPropagation();const b=(l?-1:1)*(s==="col"&&e.rtl?-1:1);D(e,s,b);let d=setTimeout(()=>{d=setInterval(()=>D(e,s,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,s=t.deltaMode===1?16:t.deltaMode===2?e.cssH:1;let l=(e.rtl?-t.deltaX:t.deltaX)*s,n=t.deltaY*s;if(t.shiftKey&&l===0&&(l=n,n=0),!o.byCell){e.scrollTo(e.scrollX+l*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+=l*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=e.displayCols.offsetOf(m(e.displayCols,e.displayCols.indexAt(g+b.w),x))-b.w),e.scrollTo(g,a)}function le(e){e.addSheet({before:!0})}function se(e,t){const{book:o}=e,s=o.sheets.length;let l=o.activeSheet+t;for(;l>=0&&l<s&&o.sheets[l].hidden;)l+=t;l<0||l>=s||(o.selectedSheets&&!o.selectedSheets.has(o.sheets[l])&&(o.selectedSheets=null),e.switchSheet(l))}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 s=c("input",{type:"checkbox",checked:t});return s.addEventListener("change",()=>o(s.checked)),c("label",{class:"dlg-row dlg-check"},s,` ${w(e)}`)}function A(e,t,o,s){const l=c("select",{class:"dlg-input","aria-label":w(e)});for(const[n,r]of t)l.append(c("option",{value:r,textContent:w(n)}));return l.value=o,l.addEventListener("change",()=>s(l.value)),c("label",{class:"dlg-row"},`${w(e)} `,l)}const y=(e,t)=>c("label",{class:"dlg-row"},`${w(e)} `,t),v=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,s=r=>i(t,r),l=r=>b=>f(e,r,b),n=c("div",{},v("Show"),c("div",{class:"bk-grid2"},u("Formula bar",s("showFormulaBar"),l("showFormulaBar")),u("Status bar",s("showStatusBar"),l("showStatusBar")),u("Sheet tabs",s("showTabs"),l("showTabs")),u("Horizontal scroll bar",s("showHScroll"),l("showHScroll")),u("Vertical scroll bar",s("showVScroll"),l("showVScroll")),u("Ribbon",!s("ribbonMinimized"),r=>f(e,"ribbonMinimized",!r))),v("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))),v("Scrolling"),A("Scroll bars:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],s("scrollAppearance"),l("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",s("scrollByCell"),l("scrollByCell")),u("Scroll bars span the whole sheet",s("scrollbarShowMax"),l("scrollbarShowMax")),u("End scrolling at the last used cell",s("scrollbarMaxAlign"),l("scrollbarMaxAlign"))),y("Wheel speed:",(()=>{const r=c("input",{class:"dlg-input short",type:"number",min:.25,max:20,step:.25,value:s("scrollPixel")});return r.addEventListener("change",()=>f(e,"scrollPixel",Math.max(.25,Math.min(20,Number(r.value)||1)))),r})()),v("Tab strip"),A("Position:",[["Bottom","bottom"],["Top","top"],["Left","left"],["Right","right"]],s("tabPosition"),l("tabPosition")),c("div",{class:"bk-grid2"},u("New sheet button",s("newTab"),l("newTab")),u("Navigation arrows",s("tabNav"),l("tabNav")),u("Sheets can be reordered",s("allowSheetReorder"),l("allowSheetReorder")),u("Sheets can be renamed",s("tabEditable"),l("tabEditable"))),A("All sheets button:",[["When needed","auto"],["Always","show"],["Never","hide"]],s("allSheets"),l("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),s=(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)},l=()=>o("scrollColors")??{},n=a=>k=>{const x={...l(),[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"},v("Scroll bars"),A("Style:",[["As on macOS","overlay"],["Always visible, with arrows","skin"],["Thin","mobile"]],o("scrollAppearance"),a=>f(e,"scrollAppearance",a)),s("Thumb color",l().thumb,"#808080",n("thumb")),s("Track color",l().track,"#E0E0E0",n("track")),v("Selection"),s("Fill color",o("selectionBackColor"),"#107C41",a=>f(e,"selectionBackColor",a)),s("Border color",o("selectionBorderColor"),"#107C41",a=>f(e,"selectionBorderColor",a)),v("Border around the workbook"),c("label",{class:"dlg-row"},b,` ${w("Show a border")}`),y("Style:",d),y("Width:",h),y("Color:",m)),[{label:"OK",primary:!0}],{width:360})}function ie(e){const{book:t,grid:o}=e,s=i(t,"focusCell")??o.focusCell??{color:"#FFF2CC",colColor:"#FFF2CC",alpha:.35},l=c("input",{type:"checkbox",checked:!!o.focusCell}),n=c("input",{type:"color",class:"dlg-color",value:s.color??"#FFF2CC"}),r=c("input",{type:"color",class:"dlg-color",value:s.colColor??s.color??"#FFF2CC"}),b=c("input",{type:"range",min:5,max:80,value:Math.round((s.alpha??.35)*100),"aria-label":w("Strength")}),d=()=>{f(e,"focusCell",l.checked?{color:n.value.toUpperCase(),colColor:r.value.toUpperCase(),alpha:Number(b.value)/100}:null),o.invalidateTop()};for(const h of[l,n,r,b])h.addEventListener("input",d);M(e,"Focus Cell",c("div",{class:"dlg-col"},c("label",{class:"dlg-row dlg-check"},l,` ${w("Highlight the row and column of the active cell")}`),y("Row color:",n),y("Column color:",r),y("Strength:",b)),[{label:"OK",primary:!0}],{width:360})}function ce(e){const{book:t}=e,o=i(t,"tips"),s=n=>r=>f(e,"tips",{...i(t,"tips"),[n]:r}),l=c("input",{class:"dlg-input short",type:"number",min:-15,max:15,value:i(t,"fixedDecimal")});l.addEventListener("change",()=>f(e,"fixedDecimal",Math.max(-15,Math.min(15,Math.trunc(Number(l.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)),y("Fixed decimal places:",l),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)),v("Tips"),u("Size while resizing",o.resize!==!1,s("resize")),u("Row or column while scrolling",o.scroll!==!1,s("scroll")),u("Value while filling",o.fill!==!1,s("fill")),u("Place while dragging cells",o.drop!==!1,s("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/cell-types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{loadBookParts as Ht}from"../cells/book-read.js";import{EMPTY as gt,KIND_MASK as yt}from"../core/sheet.js";import{quoteSheetName as jt,rangeRef as Kt,parseRangeRef as bt}from"../core/address.js";import{sheetRenameHooks as Xt,shiftSparse as Yt}from"../core/sparse.js";import{children as Ut,parseTree as kt,unescapeOoxml as Mt}from"../io/xml-scan.js";import{safeJson as Jt,xmlAttr as wt}from"../io/xml-escape.js";import{openZip as Gt}from"../io/zip-reader.js";import{applyToRanges as Vt,cellKey as I,cellDropdownArrow as qt,closeDropdown as Zt,literalInput as W,makeDropdown as St,openCellDropdown as Tt,openListPopup as lt,readCellValue as _,writeCell as z}from"./dropdowns.js";import{undoGroup as Qt}from"../cells/undo-group.js";import{cellTypePart as te,CELLS_NS as ee,CELLTYPES_NS as ne,readCellTypeParts as oe}from"./persist.js";import{cellsPackage as ie,loadCellsPart as se}from"../cells/sections.js";import{backgroundParts as re,loadBackgrounds as le}from"../cells/background.js";import{loadWatermarks as ae,watermarkParts as fe}from"../api/watermark-xml.js";import{loadRichData as ue,richPackage as ce}from"../cells/rich-data.js";import{buttonInsets as Ct,cachedImage as at,hasCellButtons as V,cellTypeFromFile as xt,CellType as Y,centerText as B,controlRect as Q,defineCellType as de,drawImageFit as ft,flag as A,formatted as he,frame as M,inkOf as U,inRect as F,isChecked as vt,labelOf as L,leftText as j,makeCellType as _t,oneOf as q,runButtonAction as Et,safeColor as R,safeImage as me,safeInt as x,safeItems as Rt,safeLink as zt,safeLocation as pe,safeText as E,sameValue as N,setFont as D,textWidth as O,cellTypeNames as ge,registerButtonAction as ye,registerCellType as be}from"./base.js";import{cellButtonCursor as ke,makeCellButtons as It,openButtonDropdown as Me,paintCellButtons as we,paintFloatingButtons as Se,paintStyleButtons as Te,pressCellButton as Ce,pressNthButton as xe,trackButtonHover as Lt}from"./cell-buttons.js";import{cellFilesPackage as ve,attachFileDrop as Ot}from"./file-cell.js";import{hideEditingButtons as _e,showEditingButtons as Ee}from"./cell-buttons.js";import"./diagonal.js";import"./data-object.js";import"./range-template.js";import"./dropdowns-more.js";import"../a11y/cell-alt-text.js";import{registerFeatureReviver as Re}from"../api/serialize.js";Re("cellTypes",o=>{if(!(o instanceof Map))return null;const t=new Map,e=new Map;for(const[n,s]of o){if(!s||typeof s!="object")continue;const i=JSON.stringify(s);e.has(i)||e.set(i,xt(s));const r=e.get(i);r&&t.set(n,r)}return t.size?t:null});const Pt=1e6,K=(o,t)=>{o.globalAlpha=t?.4:1};function tt(o,t,e,n,s,i){o.beginPath(),o.roundRect?o.roundRect(t,e,n,s,i):o.rect(t,e,n,s)}function Wt(o,t,e,n,s,i,r=!1){const a=Math.max(1,Math.round(i)),l=s!==!1,f=r?Math.round(n*.2):0;tt(o,t+a/2,e+a/2,n-a,n-a,f),o.fillStyle=l?M.theme.accent:"#ffffff",o.fill(),o.strokeStyle=l?M.theme.accent:"#6e6e6e",o.lineWidth=a,o.stroke(),s===null?(o.fillStyle="#ffffff",o.fillRect(t+n*.22,e+n*.44,n*.56,Math.max(1.5,n/7))):s&&(o.strokeStyle="#ffffff",o.lineWidth=Math.max(1.5,n/7),o.lineCap="round",o.beginPath(),o.moveTo(t+n*.22,e+n*.52),o.lineTo(t+n*.42,e+n*.72),o.lineTo(t+n*.78,e+n*.3),o.stroke(),o.lineCap="butt")}function Bt(o,t,e,n,s,i){const r=n/2;o.beginPath(),o.arc(t+r,e+r,r-Math.max(1,i)/2,0,Math.PI*2),o.fillStyle="#ffffff",o.fill(),o.strokeStyle=s?M.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),s&&(o.beginPath(),o.arc(t+r,e+r,r*.5,0,Math.PI*2),o.fillStyle=M.theme.accent,o.fill())}const et=new Map,ze=120;function ut(o,t,e,n){const s=e.duration??ze;if(s<=0||n===void 0||n===null||n.printing||n.grid===null)return t?1:0;let i=et.get(o);if(i===void 0)return et.size>=4096&&et.clear(),i={on:t,from:t?1:0,start:-1/0,ms:s},et.set(o,i),t?1:0;const r=performance.now(),a=(r-i.start)/i.ms,l=a>=1?i.on?1:0:i.from+((i.on?1:0)-i.from)*a;return i.on!==t?(i.on=t,i.from=l,i.start=r,i.ms=s,n.grid.invalidate(),l):(a<1&&n.grid.invalidate(),l)}const Ie=(o,t,e)=>{const n=s=>{const i=parseInt(o.slice(s,s+2),16),r=parseInt(t.slice(s,s+2),16);return Math.round(i+(r-i)*e).toString(16).padStart(2,"0")};return`#${n(1)}${n(3)}${n(5)}`},At=o=>/^#[0-9a-fA-F]{6}$/.test(o);function X(o,t,e,n=0){return n>0&&o.autoSize!==!1?Math.max(t*2,n+t+8*e):o.toggleWidth!==void 0?o.toggleWidth*e:t*2}function Z(o,t,e,n,s,i,r,a){const l=r.trackOn??M.theme.accent,f=r.trackOff??"#b4b4b4",u=r.trackRadius!==void 0?Math.min(s/2,r.trackRadius*a):s/2;tt(o,t,e,n,s,u),o.fillStyle=At(l)&&At(f)?Ie(f,l,i):i>.5?l:f,o.fill();const c=r.knobMargin!==void 0?r.knobMargin*a:Math.max(1,s/8),d=Math.max(1,s-c*2),h=t+c+(n-c*2-d)*i,m=e+c,p=r.knobOn??r.knob??"#ffffff",w=r.knobOff??r.knob??"#ffffff";o.fillStyle=i>.5?p:w,tt(o,h,m,d,d,r.knobRadius!==void 0?Math.min(d/2,r.knobRadius*a):d/2),o.fill()}function Le(o,t,e){const n=[];let s="";for(const i of t.split(/\s+/)){const r=s===""?i:`${s} ${i}`;s!==""&&o.measureText(r).width>e?(n.push(s),s=i):s=r}return n.push(s),n}const ct=(o,t,e,n)=>`${o?.sheet?.uid??0}:${t}:${e}:${n}`;function Ft(o,t,e,n,s,i,r,a,l,f){const u=Math.min(Math.round((r.boxSize??13)*i),Math.round(t.h-2));if(u<=2)return;const c=Math.round(3*i),d=Math.round(t.y+(t.h-u)/2),h=a===Z;if(e.disabled&&K(o,!0),r.textSide==="inside"&&(h||a===Bt)){const S=o.measureText(e.text).width,T=Math.min(t.w-c*2,h?X(r,u,i,S):S+u+8*i),C=Math.round(t.x+c);if(h){const g=ut(ct(l,l?.row,l?.col,f),n,r,l);Z(o,C,d,T,u,g,r,i),o.save(),o.beginPath(),o.rect(C,d,T,u),o.clip();const k=T-u-4*i;B(o,e.text,g>.5?C+2*i:C+u+2*i,d,k,u,e.ink??"#ffffff"),o.restore()}else tt(o,C,d,T,u,u/2),o.fillStyle=n?M.theme.accent:"#ffffff",o.fill(),o.strokeStyle=n?M.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),B(o,e.text,C,d,T,u,n?"#ffffff":e.ink??U(s));e.disabled&&K(o,!1);return}const m=h?X(r,u,i):u,p=r.textSide==="left",w=p?t.x+t.w-c-m:t.x+c;h?Z(o,Math.round(w),d,m,u,ut(ct(l,l?.row,l?.col,f),n,r,l),r,i):a(o,Math.round(w),d,u,n,i,r.mode==="modern");let y=p?t.x+c:t.x+c+m+Math.round(4*i);if(e.image){const S=at(e.image);S&&ft(o,S,y,d,u,u),y+=u+Math.round(3*i)}j(o,e.text,y,t.y,t.h,e.ink??U(s)),e.disabled&&K(o,!1)}function Oe(o,t,e,n,s){const{items:i,horizontal:r,flow:a,maxRows:l,maxCols:f}=t,u=[],c=i.length;if(c===0)return u;const d=(t.pad??0)*e,h=(t.spacingX??0)*e,m=(t.spacingY??0)*e,p=o.x+d,w=o.y+d,y=o.w-d*2,S=o.h-d*2;if(a&&r&&n){const b=n.fontSize*1.45*e;let v=p,P=w,H=0;for(const st of i){const rt=s(st,n)*e;H>0&&(f&&H>=f||v+rt>p+y)&&(v=p,P+=b+m,H=0),u.push({x:v,y:P,w:rt,h:b}),v+=rt+h,H++}const G=(S-(P+b-w))/2;if(G>0)for(const st of u)st.y+=G;return u}let T;r?T=l?Math.ceil(c/l):f??c:T=f??(l?Math.ceil(c/l):1),T=Math.max(1,Math.min(T,c));const C=Math.ceil(c/T),g=(y-h*(T-1))/T,k=(S-m*(C-1))/C;for(let b=0;b<c;b++){const v=r?Math.floor(b/T):b%C,P=r?b%T:Math.floor(b/C);u.push({x:p+P*(g+h),y:w+v*(k+m),w:g,h:k})}return u}class Pe extends Y{static typeName="button";static sanitize(t){return{text:E(t.text),value:E(t.value),action:E(t.action),color:R(t.color),image:me(t.image),disabled:A(t.disabled)}}paint(t,e,n,s,i){const r=Math.max(1,Math.round(i)),a=e.x+r,l=e.y+r,f=e.w-r*2,u=e.h-r*2;if(f<=0||u<=0)return;this.options.disabled&&K(t,!0),t.fillStyle=this.options.color??"#efefef",t.fillRect(a,l,f,u),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i)),t.strokeRect(a+.5,l+.5,f-1,u-1),D(t,s,i);const c=this.options.text??L(n),d=this.options.image?at(this.options.image):null;if(d){const h=Math.min(u-2*r,Math.round(16*i)),m=c===""?0:t.measureText(c).width+Math.round(4*i),p=a+Math.max(r,(f-h-m)/2);ft(t,d,p,l+(u-h)/2,h,h),c!==""&&j(t,c,p+h+Math.round(4*i),l,u,s.color??"#000000")}else B(t,c,a,l,f,u,s.color??"#000000");this.options.disabled&&K(t,!1)}hitTest(t,e,n){return!this.options.disabled&&F(t,e,n)?{part:"button"}:null}activate(t,e,n){const{action:s,value:i,disabled:r}=this.options;if(r||i!==void 0&&!z(t,e,n,W(i)))return!1;const a={row:e,col:n,sheet:t.book.sheet,action:s??null};return s!==void 0&&Et(s,{app:t,...a}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:a})),!0}fitWidth(t,e){return O(e,this.options.text??L(t))+(this.options.image?20:0)+12}}const Nt=o=>({trackOn:R(o.trackOn),trackOff:R(o.trackOff),knob:R(o.knob),knobOn:R(o.knobOn),knobOff:R(o.knobOff),toggleWidth:x(o.toggleWidth,8,400),toggleHeight:x(o.toggleHeight,6,200),autoSize:o.autoSize===!1?!1:void 0,knobMargin:x(o.knobMargin,0,40),trackRadius:x(o.trackRadius,0,100),knobRadius:x(o.knobRadius,0,100),duration:x(o.duration,0,2e3)});class We extends Y{static typeName="checkbox";static sanitize(t){return{text:E(t.text),textTrue:E(t.textTrue),textFalse:E(t.textFalse),textNull:E(t.textNull),mode:q(t.mode,["modern","toggle"]),threeState:t.mode==="toggle"?void 0:A(t.threeState),boxSize:x(t.boxSize,6,64),textSide:q(t.textSide,["left","top","bottom","inside"]),wrap:A(t.wrap),hit:q(t.hit,["box","cell"]),editable:A(t.editable),...Nt(t)}}get blocksEditing(){return this.options.editable!==!0}_state(t){return this.options.threeState&&(t===null||t==="")?null:vt(t)}_caption(t){const e=this.options;return t===!0&&e.textTrue!==void 0?e.textTrue:t===!1&&e.textFalse!==void 0?e.textFalse:t===null&&e.textNull!==void 0?e.textNull:e.text}_hasCaption(){const t=this.options;return t.text!==void 0||t.textTrue!==void 0||t.textFalse!==void 0||t.textNull!==void 0}_side(){const{textSide:t,mode:e}=this.options;return t==="inside"&&e!=="toggle"?void 0:t}_box(t,e,n,s){const i=this.options,r=i.mode==="toggle",a=(r?i.toggleHeight??i.boxSize??13:i.boxSize??13)*e,l=this._side(),f=this._hasCaption(),u=f&&(l==="top"||l==="bottom"),c=u&&n?n.fontSize*1.25*e:0,d=Math.min(a,t.h-2*e-c);let h=r?X(i,d,e):d;if(r&&l==="inside"&&n){const y=this._longestCaption(s);y&&(h=Math.min(t.w-2*e,X(i,d,e,O(n,y)*e)))}const m=3*e;let p;!f||u||l==="inside"?l==="inside"&&n?.hAlign==="left"?p=t.x+m:l==="inside"&&n?.hAlign==="right"?p=t.x+t.w-m-h:p=t.x+(t.w-h)/2:p=l==="left"?t.x+t.w-m-h:t.x+m;let w=t.y+(t.h-d)/2;if(u){const y=d+c,S=t.y+(t.h-y)/2;w=l==="top"?S+c:S}else if(i.wrap&&f){const y=n?.vAlign;y==="top"?w=t.y+2*e:y!=="center"&&(w=t.y+t.h-d-2*e)}return{x:p,y:w,w:h,h:d}}_longestCaption(){const t=this.options;return[t.textTrue,t.textFalse,t.textNull,t.text].filter(Boolean).reduce((e,n)=>e.length>=n.length?e:n,"")}paint(t,e,n,s,i,r){const a=this.options,l=this._box(e,i,s,n);if(l.h<=2)return;const f=this._state(n),u=this._side(),c=this._caption(f);if(D(t,s,i),a.mode==="toggle"){const g=ct(r,r?.row,r?.col,"box"),k=ut(g,f===!0,a,r);if(Z(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),Math.round(l.h),k,a,i),u==="inside"&&c){t.save(),t.beginPath(),t.rect(l.x,l.y,l.w,l.h),t.clip();const b=l.w-l.h-2*i;B(t,c,k>.5?l.x+i:l.x+l.h+i,l.y,b,l.h,"#ffffff"),t.restore();return}}else Wt(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),f,i,a.mode==="modern");if(c===void 0||c==="")return;const d=U(s);if(u==="top"||u==="bottom"){const g=s.fontSize*1.25*i,k=u==="top"?l.y-g:l.y+l.h;B(t,c,e.x,k,e.w,g,d);return}const h=4*i,m=u==="left"?e.x+3*i:l.x+l.w+h,p=u==="left"?l.x-h-m:e.x+e.w-m-2*i;if(!a.wrap){j(t,c,m,e.y,e.h,d);return}const w=Le(t,c,p),y=s.fontSize*1.2*i,S=w.length*y,T=s.vAlign,C=T==="top"?e.y+2*i:T==="center"?e.y+(e.h-S)/2:e.y+e.h-S-2*i;w.forEach((g,k)=>j(t,g,m,C+k*y,y,d))}hitTest(t,e,n,s=1,i=null){const{hit:r}=this.options;return r==="cell"||r!=="box"&&this._hasCaption()?F(t,e,n)?{part:"box"}:null:F(this._box(t,s,i),e,n)?{part:"box"}:null}activate(t,e,n){const{book:s}=t,i=this._state(_(s,s.sheet,e,n));return this.options.threeState?z(t,e,n,i===!0?"FALSE":i===!1?"":"TRUE"):z(t,e,n,i?"FALSE":"TRUE")}fitWidth(t,e){const n=this.options,s=n.mode==="toggle"?n.toggleHeight??n.boxSize??13:n.boxSize??13,i=this._caption(this._state(t)),r=this._side(),a=n.mode==="toggle"?n.toggleWidth??s*2:s,l=i?O(e,i):0;return r==="inside"?X(n,s,1,O(e,this._longestCaption()))+8:r==="top"||r==="bottom"?Math.max(a,l)+6:a+6+(l?l+4:0)}}class nt extends Y{static sanitize(t){return{items:Rt(t.items),horizontal:A(t.horizontal),separator:E(t.separator,16),flow:A(t.flow),maxRows:x(t.maxRows,1,200),maxCols:x(t.maxCols,1,200),spacingX:x(t.spacingX,0,64),spacingY:x(t.spacingY,0,64),pad:x(t.pad,0,64),boxSize:x(t.boxSize,6,64),textSide:q(t.textSide,["left","inside"]),mode:q(t.mode,["modern","toggle"]),...Nt(t)}}get blocksEditing(){return!0}_itemWidth(t,e){const n=this.options,s=n.boxSize??13,i=n.mode==="toggle"?X(n,s,1):s;if(n.textSide==="inside"&&(n.mode==="toggle"||this.type==="radio")){const r=O(e,t.text);return(n.mode==="toggle"?X(n,s,1,r):r+s+8)+6}return i+10+O(e,t.text)+(t.image?16:0)}_slots(t,e,n){return Oe(t,this.options,e,n,(s,i)=>this._itemWidth(s,i))}hitTest(t,e,n,s=1,i=null){if(!F(t,e,n))return null;const r=this._slots(t,s,i).findIndex(a=>F(a,e,n));return r<0||this.options.items[r].disabled?null:{part:"item",index:r}}_hitItem(t,e,n,s,i){const{book:r}=t,a=r.styles.list[r.sheet.style(e,n)]??r.styles.list[0];return this.hitTest(Q(t,e,n),s,i,t.grid.zoom,a)}_nextEnabled(t){const{items:e}=this.options;for(let n=1;n<=e.length;n++){const s=(t+n)%e.length;if(!e[s].disabled)return s}return-1}fitWidth(t,e){const{items:n,horizontal:s,spacingX:i=0,pad:r=0,maxCols:a}=this.options,l=n.map(c=>this._itemWidth(c,e));if(l.length===0)return 0;const f=s?Math.min(a??l.length,l.length):1,u=Math.max(...l);return(s&&f===l.length?l.reduce((c,d)=>c+d,0):u*f)+i*(f-1)+r*2}}class Be extends nt{static typeName="radio";paint(t,e,n,s,i,r){D(t,s,i),this._slots(e,i,s).forEach((a,l)=>{const f=this.options.items[l];Ft(t,a,f,N(n,f.value),s,i,this.options,Bt,r,l)})}activate(t,e,n,s,i){const{items:r}=this.options;if(r.length===0)return!1;let a;if(s==null){const{book:l}=t,f=_(l,l.sheet,e,n);if(a=this._nextEnabled(r.findIndex(u=>N(f,u.value))),a<0)return!1}else{const l=this._hitItem(t,e,n,s,i);if(!l)return!1;a=l.index}return z(t,e,n,W(r[a].value))}}const ot=o=>o.separator??", ";function dt(o,t){if(o==null||o==="")return new Set;const e=String(o).split(ot(t).trim()||",").map(n=>n.trim().toLowerCase());return new Set(t.items.filter(n=>e.includes(String(n.value).toLowerCase())).map(n=>n.value))}class Ae extends nt{static typeName="checklist";paint(t,e,n,s,i,r){D(t,s,i);const a=dt(n,this.options),l=this.options.mode==="toggle"?Z:Wt;this._slots(e,i,s).forEach((f,u)=>{const c=this.options.items[u];Ft(t,f,c,a.has(c.value),s,i,this.options,l,r,u)})}_write(t,e,n,s){return z(t,e,n,W(s.join(ot(this.options))))}activate(t,e,n,s,i){const{items:r}=this.options,{book:a}=t,l=dt(_(a,a.sheet,e,n),this.options);if(s==null)return lt(t,e,n,{items:r.filter(c=>!c.disabled),selected:[...l],multi:!0,label:"Choices",onDone:c=>this._write(t,e,n,c)}),!0;const f=this._hitItem(t,e,n,s,i);if(!f)return!1;const u=r[f.index];return l.has(u.value)?l.delete(u.value):l.add(u.value),this._write(t,e,n,r.filter(c=>l.has(c.value)).map(c=>c.value))}}class Fe extends nt{static typeName="buttonlist";static sanitize(t){return{...nt.sanitize(t),horizontal:t.horizontal!==!1||void 0,multiple:A(t.multiple),selectedColor:R(t.selectedColor),selectedInk:R(t.selectedInk)}}_itemWidth(t,e){return O(e,t.text)+14+(t.image?18:0)}_chosen(t){if(this.options.multiple)return dt(t,this.options);const e=this.options.items.find(n=>N(t,n.value));return new Set(e?[e.value]:[])}paint(t,e,n,s,i){D(t,s,i);const r=this.options,a=Math.max(1,Math.round(i)),l=this._chosen(n);this._slots(e,i,s).forEach((f,u)=>{const c=r.items[u],d=l.has(c.value),h=Math.round(f.x)+a,m=Math.round(f.y)+a,p=Math.round(f.w)-a*2,w=Math.round(f.h)-a*2;if(p<=0||w<=0)return;c.disabled&&K(t,!0);const y=r.selectedColor??M.theme.accent;t.fillStyle=c.color??(d?y:"#efefef"),t.fillRect(h,m,p,w);const S=d&&c.color?a*2:a;t.strokeStyle=d?y:"#8f8f8f",t.lineWidth=S,t.strokeRect(h+S/2,m+S/2,p-S,w-S),t.save(),t.beginPath(),t.rect(h,m,p,w),t.clip();const T=c.ink??(d&&!c.color?r.selectedInk??"#ffffff":s.color??"#000000"),C=c.image?at(c.image):null;if(C){const g=Math.min(w-2*a,Math.round(14*i)),k=t.measureText(c.text).width+(c.text?Math.round(4*i):0),b=h+Math.max(a,(p-g-k)/2);ft(t,C,b,m+(w-g)/2,g,g),j(t,c.text,b+g+Math.round(4*i),m,w,T)}else B(t,c.text,h,m,p,w,T);t.restore(),c.disabled&&K(t,!1)}),r.items.length>0&&(t.textAlign="left")}activate(t,e,n,s,i){const{items:r,multiple:a}=this.options;if(r.length===0)return!1;const{book:l}=t,f=_(l,l.sheet,e,n);if(s==null){if(a)return lt(t,e,n,{items:r.filter(h=>!h.disabled),selected:[...this._chosen(f)],multi:!0,label:"Choices",onDone:h=>z(t,e,n,W(h.join(ot(this.options))))}),!0;const d=this._nextEnabled(r.findIndex(h=>N(f,h.value)));return d>=0&&z(t,e,n,W(r[d].value))}const u=this._hitItem(t,e,n,s,i);if(!u)return!1;const c=r[u.index];if(a){const d=this._chosen(f);return d.has(c.value)?d.delete(c.value):d.add(c.value),z(t,e,n,W(r.filter(h=>d.has(h.value)).map(h=>h.value).join(ot(this.options))))}return z(t,e,n,N(f,c.value)?"":W(c.value))}}function it(o,t,e){if(typeof o=="number")return o;if(typeof o=="string"&&t){const n=t.findIndex(s=>s.toLowerCase()===o.toLowerCase());if(n>=0)return n}return e}function ht(o,t,e,n){const s=[],i=Math.min(o,5e3);for(let r=0;r<i;r++){const a=L(t(r,e)),l=L(t(r,n));(a!==""||l!=="")&&s.push({text:String(a),value:String(l)})}return s}function Ne(o,t,e,{textColumn:n,valueColumn:s},i,r){const a=e.replace(/^=/,"").trim(),l=e[0]==="="?void 0:o.engine?.tables.get(a.toUpperCase());if(l){const y=l.columns?.map(k=>typeof k=="string"?k:k?.name??""),S=it(n,y,0),T=it(s,y,S),C=l.r0+(l.headerRows??1),g=l.r1-C+1-(l.totalsRows??0);return ht(g,(k,b)=>_(o,l.sheet,C+k,l.c0+b),S,T)}const f=it(n,null,0),u=it(s,null,f),c=a.lastIndexOf("!"),d=e[0]==="="?null:bt(c>=0?a.slice(c+1):a);if(d){const y=c>=0?a.slice(0,c).replace(/^'|'$/g,"").replace(/''/g,"'"):null,S=y===null?t:o.sheets.find(C=>C.name.toLowerCase()===y.toLowerCase());if(!S)return[];const T=Math.min(d.r1,S.maxRow)-d.r0+1;return ht(T,(C,g)=>_(o,S,d.r0+C,d.c0+g),f,u)}const{engine:h}=o;if(!h)return[];let m;try{const y=h.template(a,i,r);if(y.invalid)return[];m=y.fn(i,r,t),m&&m.sheet&&(m=h.toArr(m))}catch{return[]}if(!m||!m.data)return m==null||typeof m=="object"?[]:[{text:String(L(m)),value:String(L(m))}];const p=m.cols,w=(y,S)=>{const T=m.data[y*p+S];return T===void 0||T!==null&&typeof T=="object"?null:T};return ht(m.rows,w,f,u)}class De extends Y{static typeName="combobox";static sanitize(t){return{items:Rt(t.items),editable:A(t.editable),source:typeof t.source=="string"&&t.source.length<=500?t.source:void 0,textColumn:typeof t.textColumn=="string"?E(t.textColumn,200):x(t.textColumn,0,49),valueColumn:typeof t.valueColumn=="string"?E(t.valueColumn,200):x(t.valueColumn,0,49),maxItems:x(t.maxItems,1,100),float:t.float===!1?!1:void 0}}get blocksEditing(){return this.options.editable!==!0}get opensList(){return!0}_items(t,e,n,s){const{source:i,items:r}=this.options;return i===void 0?r:((this.sourceFrame!==M.id||this.sourceFrame===void 0)&&(this.sourceFrame=M.id,this.sourceItems=Ne(t,e,i,this.options,n,s)),this.sourceItems)}_arrow(t,e){const n=Math.min(16*e,t.h);return{x:t.x+t.w-n,y:t.y+(t.h-n)/2,w:n,h:n}}paint(t,e,n,s,i,r){const a=r?.printing===!0,l=this._arrow(e,i),u=(r?.book?this._items(r.book,r.sheet,r.row,r.col):this.options.items).find(m=>N(n,m.value))?.text??he(n,s);if(D(t,s,i),t.save(),t.beginPath(),t.rect(e.x,e.y,a?e.w:e.w-l.w,e.h),t.clip(),j(t,u,e.x+Math.round(2*i),e.y,e.h,U(s)),t.restore(),a)return;const c=Math.round(l.x),d=Math.round(l.y),h=Math.round(l.w);t.fillStyle="#f7f7f7",t.fillRect(c,d,h,h),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i/2)),t.strokeRect(c+.5,d+.5,h-1,h-1),t.fillStyle="#444444",t.beginPath(),t.moveTo(c+h*.28,d+h*.4),t.lineTo(c+h*.72,d+h*.4),t.lineTo(c+h*.5,d+h*.66),t.closePath(),t.fill()}hitTest(t,e,n,s=1){return F(t,e,n)?F(this._arrow(t,s),e,n)?{part:"arrow"}:this.options.editable?null:{part:"text"}:null}activate(t,e,n){const{book:s}=t,i=_(s,s.sheet,e,n);this.sourceFrame=void 0;const r=this._items(s,s.sheet,e,n);this.sourceFrame=void 0;const a=r.find(l=>N(i,l.value));return lt(t,e,n,{items:r,selected:a?[a.value]:[],label:"Choices",maxItems:this.options.maxItems??20,moveOnSide:!0,float:this.options.float!==!1,onDone:l=>l.length===0?!0:z(t,e,n,W(l[0]))}),!0}fitWidth(t,e){const n=this.options.items.find(s=>N(t,s.value))?.text??L(t);return O(e,String(n))+22}}const mt=new Set;class $e extends Y{static typeName="hyperlink";static sanitize(t){return{url:zt(t.url),location:pe(t.location),text:E(t.text),color:R(t.color),visitedColor:R(t.visitedColor),tooltip:E(t.tooltip),action:E(t.action),activeOnClick:t.activeOnClick===!1?!1:void 0}}get tooltip(){return this.options.tooltip}get runsWithoutSelecting(){return this.options.activeOnClick===!1}paint(t,e,n,s,i){const r=this.options.text??L(n);if(r==="")return;D(t,s,i);const a=e.x+Math.round(2*i),{url:l,location:f,color:u,visitedColor:c}=this.options,d=l??f??(typeof n=="string"?n:""),h=mt.has(d)?c??"#954f72":u??s.color??"#0563c1";j(t,r,a,e.y,e.h,h);const m=s.fontSize*i,p=Math.min(t.measureText(r).width,e.w-Math.round(4*i));t.fillRect(a,Math.round(e.y+e.h/2+m*.42),p,Math.max(1,Math.round(m/14)))}hitTest(t,e,n){return F(t,e,n)?{part:"link"}:null}activate(t,e,n){const{url:s,location:i,action:r}=this.options,{book:a}=t;if(r!==void 0){const f={row:e,col:n,sheet:a.sheet,action:r};Et(r,{app:t,...f}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:f}))}if(i)return mt.add(i),t.controller._followLink({location:i}),!0;const l=s??zt(_(a,a.sheet,e,n));return l?(mt.add(l),t.grid.invalidate(),t.controller._followLink({target:l}),!0):(r===void 0&&t.shell.setStatus("This link has no web or mail address to open."),!0)}fitWidth(t,e){return O(e,String(this.options.text??L(t)))+7}}class He extends Y{static typeName="progress";static sanitize(t){const e=n=>Number.isFinite(n)?n:void 0;return{min:e(t.min),max:e(t.max),color:R(t.color),hideText:t.hideText===!0||void 0}}paint(t,e,n,s,i){const r=this.options.min??0,a=this.options.max??1,l=Math.max(1,Math.round(2*i)),f=e.x+l,u=e.y+l,c=e.w-l*2,d=e.h-l*2;if(c<=0||d<=0)return;if(t.fillStyle="#e6e6e6",t.fillRect(f,u,c,d),D(t,s,i),typeof n=="string"&&n.startsWith("#")){B(t,n,f,u,c,d,U(s));return}const h=typeof n=="number"?n:0,m=a>r?Math.max(0,Math.min(1,(h-r)/(a-r))):0;t.fillStyle=this.options.color??M.theme.accent,t.fillRect(f,u,Math.round(c*m),d),this.options.hideText||B(t,`${Math.round(m*100)}%`,f,u,c,d,m>.5?"#ffffff":U(s))}}for(const o of[Pe,We,Be,Ae,Fe,De,$e,He])de(o);const wn=ge();function $(o,t,e){const n=o.cellTypes;if(!n)return null;const s=o.mergeAt(t,e);return n.get(s?I(s.r0,s.c0):I(t,e))??null}const J=(o,t,e,n)=>o.styles.list[t.style(e,n)]??o.styles.list[0];function Dt(o,t,e,n,s,i,r,a,l,f,u,c,d){const h=e.kind(i,r)&yt,m=J(n,e,i,r);h===gt&&(o.fillStyle=m.fill??s.cellBg,o.fillRect(a,l,f-d,u-d));const p=Ct(e,i,r,m);if(p!==null){const w=Math.round(p[0]*c);a+=w,f=Math.max(0,f-w-Math.round(p[1]*c))}o.save(),o.beginPath(),o.rect(a,l,f,u),o.clip(),M.row=i,M.col=r,t.paint(o,{x:a,y:l,w:f,h:u},_(n,e,i,r),m,c,M),o.restore()}function Sn(o,t,e,n,s){const{sheet:i,book:r,theme:a,dpr:l,zoom:f}=t,u=i.cellTypes;M.theme=a,M.book=r,M.sheet=i,M.grid=t,M.printing=!1,M.id++;const{ca:c,cb:d,ra:h,rb:m,s:p,xs:w,ys:y}=n,S=Math.max(1,Math.round(l*Math.min(f,1))),T=s.length>0,C=(g,k,b)=>{if(T&&i.mergeAt(k,b)!==null)return;const v=w[b-c],P=y[k-h],H=w[b-c+1]-v,G=y[k-h+1]-P;H>0&&G>0&&Dt(o,g,i,r,a,k,b,v,P,H,G,p,S)};if(u.size<(d-c+1)*(m-h+1))for(const[g,k]of u){const b=Math.floor(g/16384),v=g-b*16384;b>=h&&b<=m&&v>=c&&v<=d&&C(k,b,v)}else for(let g=h;g<=m;g++)for(let k=c;k<=d;k++){const b=u.get(I(g,k));b!==void 0&&C(b,g,k)}for(const g of s){const k=u.get(I(g.r0,g.c0));if(k===void 0||g.c1<c||g.c0>d)continue;const b=t._rectInPane(g,e,p);Dt(o,k,i,r,a,g.r0,g.c0,b.x,b.y,b.w,b.h,p,S)}}const je={cellBg:"#ffffff",cellInk:"#000000",accent:"#404040"};function Tn(o,t,e,n,s,i,r,a,l){const f=e.cellTypes?.get(I(n,s));return f===void 0?!1:(M.theme=je,M.book=t,M.sheet=e,M.grid=null,M.printing=!0,M.row=n,M.col=s,M.id++,o.save(),o.beginPath(),o.rect(i,r,a,l),o.clip(),f.paint(o,{x:i,y:r,w:a,h:l},_(t,e,n,s),J(t,e,n,s),1,M),o.restore(),M.printing=!1,!0)}function Cn(o,t,e,n,s,i,r){const a=t.cellTypes;if(!(a instanceof Map))return;const l=(f,u)=>{(t.kind(f,u)&yt)===gt&&t.mergeAt(f,u)===null&&r(f,u)};if(a.size<(n-e+1)*(i-s+1))for(const f of a.keys()){const u=Math.floor(f/16384),c=f-u*16384;u>=e&&u<=n&&c>=s&&c<=i&&l(u,c)}else for(let f=e;f<=n;f++)for(let u=s;u<=i;u++)a.has(I(f,u))&&l(f,u)}function xn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i,a=$(r,t,e);if(a===null||a.runsWithoutSelecting!==!0||!a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function vn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(V(r,i)&&Ce(o,t,e,n,s))return!0;const a=r.cellTypes?$(r,t,e):null;if(a===null||!a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function _n(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(V(r,i)&&ke(o,t,e,n,s))return"pointer";if(!r.cellTypes)return null;const a=$(r,t,e),l=a?.tooltip,{host:f}=o.grid;return l!==void 0?f.title=l:f.title!==""&&(f.title=""),a!==null&&a.hitTest(Q(o,t,e),n,s,o.grid.zoom,J(i,r,t,e))?"pointer":null}function En(o,t){const{sheet:e}=o.book,n=V(e,o.book);if(!e.cellTypes&&!e.cellDropdowns&&!n)return!1;const s=o.grid.selection,{row:i,col:r}=s,a=t.metaKey||t.ctrlKey||t.shiftKey;if(t.altKey&&!a&&n&&/^Digit[1-9]$/.test(t.code)&&xe(o,i,r,Number(t.code[5])-1))return!0;if(t.key==="ArrowDown"&&t.altKey&&!a){if(Tt(o,i,r)||n&&Me(o,i,r))return!0;const l=$(e,i,r);return l&&l.opensList?l.activate(o,i,r,null,null):!1}if((t.key==="Delete"||t.key==="Backspace")&&!a&&!t.altKey&&e.cellTypes&&Ke(o))return!0;if(t.key===" "&&!a&&!t.altKey){const l=$(e,i,r);if(l===null)return!1;const f=e.mergeAt(i,r);return l.activate(o,f?f.r0:i,f?f.c0:r,null,null)}return!1}function Ke(o){const{book:t,grid:e}=o,{sheet:n}=t,s=e.selection.ranges,i=[];for(const[a,l]of n.cellTypes){if(l?.constructor?.typeName!=="checkbox")continue;const f=Math.floor(a/16384),u=a%16384;s.some(c=>f>=c.r0&&f<=c.r1&&u>=c.c0&&u<=c.c1)&&i.push([f,u])}if(i.length===0)return!1;const r=i.filter(([a,l])=>vt(_(t,n,a,l)));return r.length?t.transact("entry",a=>{for(const[l,f]of r)t.setInput(a,l,f,"FALSE")}):Qt(t,"Clear",()=>{Vt(t,i.map(([a,l])=>({r0:a,c0:l,r1:a,c1:l})),"cellTypes",null),t.clearRange(s)}),e.invalidate(),o.controller?.syncFormulaBar?.(),!0}function Rn(o,t,e){const{sheet:n}=o.book;if(!n.cellTypes)return!1;const s=$(n,t,e);return s===null||!s.blocksEditing?!1:(o.controller.focusGrid(),s.opensList?s.activate(o,t,e,null,null):o.shell.setStatus("This cell holds a control. Click it or press Space to change it."),!0)}function zn(o,t,e){const{book:n}=o,s=$(n.sheet,t,e);return s===null?void 0:s.editText(_(n,n.sheet,t,e))}function In(o,t,e,n){const s=$(o.book.sheet,t,e);return s===null?n:s.parseEdit(n)}function Ln(o,t,e,n,s){const i=o.cellTypes?.get(I(e,n)),r=J(t,o,e,n);let a=s;if(i!==void 0){M.book=t,M.sheet=o,M.row=e,M.col=n;const f=i.fitWidth(_(t,o,e,n),r);f>0&&(a=f-7)}const l=Ct(o,e,n,r);return l===null?a:a+l[0]+l[1]}function On(o){Ot(o),o.grid.host.addEventListener("pointerleave",()=>{V(o.book.sheet,o.book)&&Lt(o,null,0,0)})}function Pn(o,t){const e=[];for(const n of[o.cellTypes,o.cellButtons])if(n instanceof Map)for(const s of n.keys())s%16384===t&&e.push(Math.floor(s/16384));return e}const Wn=(o,t)=>Yt(o,t);function Xe(o,t,e){const n=o.lastIndexOf("!");return n<0||o.slice(0,n).replace(/^'|'$/g,"").replace(/''/g,"'").toLowerCase()!==t.toLowerCase()?o:`${jt(e)}${o.slice(n)}`}function $t(o,t,e){let n=null;for(const s of["source","location"]){if(typeof o[s]!="string")continue;const i=Xe(o[s],t,e);i!==o[s]&&((n??={...o})[s]=i)}return n}Xt.push((o,t,e)=>{const n=new Map,s=(r,a,l)=>{const f=r[a];if(!(f instanceof Map))return;let u=null;for(const[c,d]of f){n.has(d)||n.set(d,l(d));const h=n.get(d);h!==d&&(u??=new Map(f)).set(c,h)}u!==null&&(r[a]=u,r.cellTypesChanged=!0)},i=r=>{const a=$t(r,t,e);return a===null?r:St(r.type,a)};for(const r of o.sheets)s(r,"cellTypes",a=>{const l=$t(a.options,t,e);return l===null?a:_t(a.type,l)}),s(r,"cellDropdowns",i),s(r,"cellButtons",a=>{const l=a.map(f=>{if(!f.dropdown||f.dropdown===!0)return f;const u=i(f.dropdown);return u===f.dropdown?f:{...f,dropdown:u}});return l.some((f,u)=>f!==a[u])?It(l):a})});function Ye(o){o.sort((i,r)=>i%16384-r%16384||i-r);const t=[];let e=-1,n=-1;const s=()=>{if(e<0)return;const i=Math.floor(e/16384),r=e-i*16384,a=Math.floor(n/16384);t.push(Kt({r0:i,c0:r,r1:a,c1:r}))};for(const i of o)e>=0&&i===n+16384||(s(),e=i),n=i;return s(),t}function pt(o,t,e){if(!o||o.size===0)return;const n=new Map;for(const[s,i]of o){const r=Jt(i);let a=n.get(r);a===void 0&&(a=[],n.set(r,a)),a.push(s)}for(const[s,i]of n)e.push({kind:t,json:s,keys:i})}function Ue(o){const t=[];if(pt(o.cellTypes,"type",t),pt(o.cellDropdowns,"dropdown",t),pt(o.cellButtons,"buttons",t),t.length===0)return null;const e=t.map(n=>`<entry kind="${n.kind}" config="${wt(n.json)}" ref="${Ye(n.keys).join(" ")}"/>`).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
-
<cellTypes xmlns="${
|
|
1
|
+
import{loadBookParts as Qt}from"../cells/book-read.js";import{EMPTY as ut,KIND_MASK as ct}from"../core/sheet.js";import{hasCellTypes as q,intersection as vt,typeAtPosition as D,visitStored as te}from"../core/cell-type-rules.js";import{subtractRect as _t}from"../core/validation-ranges.js";import{MAX_COLS as Z,MAX_ROWS as ee,quoteSheetName as ne,rangeRef as Rt,parseRangeRef as dt}from"../core/address.js";import{sheetRenameHooks as oe,shiftSparse as ie}from"../core/sparse.js";import{children as It,parseTree as Et,unescapeOoxml as ht}from"../io/xml-scan.js";import{safeJson as zt,xmlAttr as mt}from"../io/xml-escape.js";import{openZip as se}from"../io/zip-reader.js";import{applyToRanges as re,cellKey as pt,cellDropdownArrow as le,closeDropdown as ae,literalInput as W,makeDropdown as Lt,openCellDropdown as Ot,openListPopup as gt,readCellValue as _,writeCell as E}from"./dropdowns.js";import{undoGroup as fe}from"../cells/undo-group.js";import{cellTypePart as ue,CELLS_NS as ce,CELLTYPES_NS as de,readCellTypeParts as he}from"./persist.js";import{cellsPackage as me,loadCellsPart as pe}from"../cells/sections.js";import{backgroundParts as ge,loadBackgrounds as ye}from"../cells/background.js";import{loadWatermarks as be,watermarkParts as Me}from"../api/watermark-xml.js";import{loadRichData as ke,richPackage as we}from"../cells/rich-data.js";import{buttonInsets as At,cachedImage as yt,hasCellButtons as Q,cellTypeFromFile as nt,CellType as Y,centerText as P,controlRect as ot,defineCellType as Se,drawImageFit as bt,flag as $,formatted as Te,frame as w,inkOf as U,inRect as B,isChecked as Wt,labelOf as z,leftText as j,makeCellType as Pt,oneOf as tt,runButtonAction as $t,safeColor as I,safeImage as xe,safeInt as v,safeItems as Bt,safeLink as Ft,safeLocation as Ce,safeText as R,sameValue as J,setFont as F,textWidth as L,cellTypeNames as ve,registerButtonAction as _e,registerCellType as Re}from"./base.js";import{cellButtonCursor as Ie,makeCellButtons as Nt,openButtonDropdown as Ee,paintCellButtons as ze,paintFloatingButtons as Le,paintStyleButtons as Oe,pressCellButton as Ae,pressNthButton as We,trackButtonHover as Dt}from"./cell-buttons.js";import{cellFilesPackage as Pe,attachFileDrop as jt}from"./file-cell.js";import{hideEditingButtons as $e,showEditingButtons as Be}from"./cell-buttons.js";import"./diagonal.js";import"./data-object.js";import"./range-template.js";import"./dropdowns-more.js";import"../a11y/cell-alt-text.js";import{registerFeatureReviver as Ht}from"../api/serialize.js";Ht("cellTypes",o=>{if(!(o instanceof Map))return null;const t=new Map,e=new Map;for(const[n,s]of o){if(!s||typeof s!="object")continue;const i=JSON.stringify(s);e.has(i)||e.set(i,nt(s));const r=e.get(i);r&&t.set(n,r)}return t.size?t:null}),Ht("cellTypeRules",o=>{const t=[];for(const e of Array.isArray(o)?o:[]){if(!Array.isArray(e?.ranges)||!e.spec||typeof e.spec!="object")continue;const n=nt(e.spec),s=e.ranges.filter(i=>i&&[i.r0,i.c0,i.r1,i.c1].every(Number.isInteger)&&i.r0>=0&&i.r0<=i.r1&&i.r1<ee&&i.c0>=0&&i.c0<=i.c1&&i.c1<Z);n&&s.length&&t.push({ranges:s,spec:n})}return t.length?t:null});const Kt=1e6,H=(o,t)=>{o.globalAlpha=t?.4:1};function it(o,t,e,n,s,i){o.beginPath(),o.roundRect?o.roundRect(t,e,n,s,i):o.rect(t,e,n,s)}function Xt(o,t,e,n,s,i,r=!1){const a=Math.max(1,Math.round(i)),l=s!==!1,f=r?Math.round(n*.2):0;it(o,t+a/2,e+a/2,n-a,n-a,f),o.fillStyle=l?w.theme.accent:"#ffffff",o.fill(),o.strokeStyle=l?w.theme.accent:"#6e6e6e",o.lineWidth=a,o.stroke(),s===null?(o.fillStyle="#ffffff",o.fillRect(t+n*.22,e+n*.44,n*.56,Math.max(1.5,n/7))):s&&(o.strokeStyle="#ffffff",o.lineWidth=Math.max(1.5,n/7),o.lineCap="round",o.beginPath(),o.moveTo(t+n*.22,e+n*.52),o.lineTo(t+n*.42,e+n*.72),o.lineTo(t+n*.78,e+n*.3),o.stroke(),o.lineCap="butt")}function Yt(o,t,e,n,s,i){const r=n/2;o.beginPath(),o.arc(t+r,e+r,r-Math.max(1,i)/2,0,Math.PI*2),o.fillStyle="#ffffff",o.fill(),o.strokeStyle=s?w.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),s&&(o.beginPath(),o.arc(t+r,e+r,r*.5,0,Math.PI*2),o.fillStyle=w.theme.accent,o.fill())}const st=new Map,Fe=120;function Mt(o,t,e,n){const s=e.duration??Fe;if(s<=0||n===void 0||n===null||n.printing||n.grid===null)return t?1:0;let i=st.get(o);if(i===void 0)return st.size>=4096&&st.clear(),i={on:t,from:t?1:0,start:-1/0,ms:s},st.set(o,i),t?1:0;const r=performance.now(),a=(r-i.start)/i.ms,l=a>=1?i.on?1:0:i.from+((i.on?1:0)-i.from)*a;return i.on!==t?(i.on=t,i.from=l,i.start=r,i.ms=s,n.grid.invalidate(),l):(a<1&&n.grid.invalidate(),l)}const Ne=(o,t,e)=>{const n=s=>{const i=parseInt(o.slice(s,s+2),16),r=parseInt(t.slice(s,s+2),16);return Math.round(i+(r-i)*e).toString(16).padStart(2,"0")};return`#${n(1)}${n(3)}${n(5)}`},Ut=o=>/^#[0-9a-fA-F]{6}$/.test(o);function K(o,t,e,n=0){return n>0&&o.autoSize!==!1?Math.max(t*2,n+t+8*e):o.toggleWidth!==void 0?o.toggleWidth*e:t*2}function et(o,t,e,n,s,i,r,a){const l=r.trackOn??w.theme.accent,f=r.trackOff??"#b4b4b4",c=r.trackRadius!==void 0?Math.min(s/2,r.trackRadius*a):s/2;it(o,t,e,n,s,c),o.fillStyle=Ut(l)&&Ut(f)?Ne(f,l,i):i>.5?l:f,o.fill();const u=r.knobMargin!==void 0?r.knobMargin*a:Math.max(1,s/8),d=Math.max(1,s-u*2),h=t+u+(n-u*2-d)*i,m=e+u,p=r.knobOn??r.knob??"#ffffff",y=r.knobOff??r.knob??"#ffffff";o.fillStyle=i>.5?p:y,it(o,h,m,d,d,r.knobRadius!==void 0?Math.min(d/2,r.knobRadius*a):d/2),o.fill()}function De(o,t,e){const n=[];let s="";for(const i of t.split(/\s+/)){const r=s===""?i:`${s} ${i}`;s!==""&&o.measureText(r).width>e?(n.push(s),s=i):s=r}return n.push(s),n}const kt=(o,t,e,n)=>`${o?.sheet?.uid??0}:${t}:${e}:${n}`;function Jt(o,t,e,n,s,i,r,a,l,f){const c=Math.min(Math.round((r.boxSize??13)*i),Math.round(t.h-2));if(c<=2)return;const u=Math.round(3*i),d=Math.round(t.y+(t.h-c)/2),h=a===et;if(e.disabled&&H(o,!0),r.textSide==="inside"&&(h||a===Yt)){const S=o.measureText(e.text).width,T=Math.min(t.w-u*2,h?K(r,c,i,S):S+c+8*i),x=Math.round(t.x+u);if(h){const g=Mt(kt(l,l?.row,l?.col,f),n,r,l);et(o,x,d,T,c,g,r,i),o.save(),o.beginPath(),o.rect(x,d,T,c),o.clip();const k=T-c-4*i;P(o,e.text,g>.5?x+2*i:x+c+2*i,d,k,c,e.ink??"#ffffff"),o.restore()}else it(o,x,d,T,c,c/2),o.fillStyle=n?w.theme.accent:"#ffffff",o.fill(),o.strokeStyle=n?w.theme.accent:"#6e6e6e",o.lineWidth=Math.max(1,Math.round(i)),o.stroke(),P(o,e.text,x,d,T,c,n?"#ffffff":e.ink??U(s));e.disabled&&H(o,!1);return}const m=h?K(r,c,i):c,p=r.textSide==="left",y=p?t.x+t.w-u-m:t.x+u;h?et(o,Math.round(y),d,m,c,Mt(kt(l,l?.row,l?.col,f),n,r,l),r,i):a(o,Math.round(y),d,c,n,i,r.mode==="modern");let M=p?t.x+u:t.x+u+m+Math.round(4*i);if(e.image){const S=yt(e.image);S&&bt(o,S,M,d,c,c),M+=c+Math.round(3*i)}j(o,e.text,M,t.y,t.h,e.ink??U(s)),e.disabled&&H(o,!1)}function je(o,t,e,n,s){const{items:i,horizontal:r,flow:a,maxRows:l,maxCols:f}=t,c=[],u=i.length;if(u===0)return c;const d=(t.pad??0)*e,h=(t.spacingX??0)*e,m=(t.spacingY??0)*e,p=o.x+d,y=o.y+d,M=o.w-d*2,S=o.h-d*2;if(a&&r&&n){const b=n.fontSize*1.45*e;let C=p,O=y,A=0;for(const X of i){const ft=s(X,n)*e;A>0&&(f&&A>=f||C+ft>p+M)&&(C=p,O+=b+m,A=0),c.push({x:C,y:O,w:ft,h:b}),C+=ft+h,A++}const G=(S-(O+b-y))/2;if(G>0)for(const X of c)X.y+=G;return c}let T;r?T=l?Math.ceil(u/l):f??u:T=f??(l?Math.ceil(u/l):1),T=Math.max(1,Math.min(T,u));const x=Math.ceil(u/T),g=(M-h*(T-1))/T,k=(S-m*(x-1))/x;for(let b=0;b<u;b++){const C=r?Math.floor(b/T):b%x,O=r?b%T:Math.floor(b/x);c.push({x:p+O*(g+h),y:y+C*(k+m),w:g,h:k})}return c}class He extends Y{static typeName="button";static sanitize(t){return{text:R(t.text),value:R(t.value),action:R(t.action),color:I(t.color),image:xe(t.image),disabled:$(t.disabled)}}paint(t,e,n,s,i){const r=Math.max(1,Math.round(i)),a=e.x+r,l=e.y+r,f=e.w-r*2,c=e.h-r*2;if(f<=0||c<=0)return;this.options.disabled&&H(t,!0),t.fillStyle=this.options.color??"#efefef",t.fillRect(a,l,f,c),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i)),t.strokeRect(a+.5,l+.5,f-1,c-1),F(t,s,i);const u=this.options.text??z(n),d=this.options.image?yt(this.options.image):null;if(d){const h=Math.min(c-2*r,Math.round(16*i)),m=u===""?0:t.measureText(u).width+Math.round(4*i),p=a+Math.max(r,(f-h-m)/2);bt(t,d,p,l+(c-h)/2,h,h),u!==""&&j(t,u,p+h+Math.round(4*i),l,c,s.color??"#000000")}else P(t,u,a,l,f,c,s.color??"#000000");this.options.disabled&&H(t,!1)}hitTest(t,e,n){return!this.options.disabled&&B(t,e,n)?{part:"button"}:null}activate(t,e,n){const{action:s,value:i,disabled:r}=this.options;if(r||i!==void 0&&!E(t,e,n,W(i)))return!1;const a={row:e,col:n,sheet:t.book.sheet,action:s??null};return s!==void 0&&$t(s,{app:t,...a}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:a})),!0}fitWidth(t,e){return L(e,this.options.text??z(t))+(this.options.image?20:0)+12}}const Vt=o=>({trackOn:I(o.trackOn),trackOff:I(o.trackOff),knob:I(o.knob),knobOn:I(o.knobOn),knobOff:I(o.knobOff),toggleWidth:v(o.toggleWidth,8,400),toggleHeight:v(o.toggleHeight,6,200),autoSize:o.autoSize===!1?!1:void 0,knobMargin:v(o.knobMargin,0,40),trackRadius:v(o.trackRadius,0,100),knobRadius:v(o.knobRadius,0,100),duration:v(o.duration,0,2e3)});class Ke extends Y{static typeName="checkbox";static sanitize(t){return{text:R(t.text),textTrue:R(t.textTrue),textFalse:R(t.textFalse),textNull:R(t.textNull),mode:tt(t.mode,["modern","toggle"]),threeState:t.mode==="toggle"?void 0:$(t.threeState),boxSize:v(t.boxSize,6,64),textSide:tt(t.textSide,["left","top","bottom","inside"]),wrap:$(t.wrap),hit:tt(t.hit,["box","cell"]),editable:$(t.editable),...Vt(t)}}get blocksEditing(){return this.options.editable!==!0}_state(t){return this.options.threeState&&(t===null||t==="")?null:Wt(t)}_caption(t){const e=this.options;return t===!0&&e.textTrue!==void 0?e.textTrue:t===!1&&e.textFalse!==void 0?e.textFalse:t===null&&e.textNull!==void 0?e.textNull:e.text}_hasCaption(){const t=this.options;return t.text!==void 0||t.textTrue!==void 0||t.textFalse!==void 0||t.textNull!==void 0}_side(){const{textSide:t,mode:e}=this.options;return t==="inside"&&e!=="toggle"?void 0:t}_box(t,e,n,s){const i=this.options,r=i.mode==="toggle",a=(r?i.toggleHeight??i.boxSize??13:i.boxSize??13)*e,l=this._side(),f=this._hasCaption(),c=f&&(l==="top"||l==="bottom"),u=c&&n?n.fontSize*1.25*e:0,d=Math.min(a,t.h-2*e-u);let h=r?K(i,d,e):d;if(r&&l==="inside"&&n){const M=this._longestCaption(s);M&&(h=Math.min(t.w-2*e,K(i,d,e,L(n,M)*e)))}const m=3*e;let p;!f||c||l==="inside"?l==="inside"&&n?.hAlign==="left"?p=t.x+m:l==="inside"&&n?.hAlign==="right"?p=t.x+t.w-m-h:p=t.x+(t.w-h)/2:p=l==="left"?t.x+t.w-m-h:t.x+m;let y=t.y+(t.h-d)/2;if(c){const M=d+u,S=t.y+(t.h-M)/2;y=l==="top"?S+u:S}else if(i.wrap&&f){const M=n?.vAlign;M==="top"?y=t.y+2*e:M!=="center"&&(y=t.y+t.h-d-2*e)}return{x:p,y,w:h,h:d}}_longestCaption(){const t=this.options;return[t.textTrue,t.textFalse,t.textNull,t.text].filter(Boolean).reduce((e,n)=>e.length>=n.length?e:n,"")}paint(t,e,n,s,i,r){const a=this.options,l=this._box(e,i,s,n);if(l.h<=2)return;const f=this._state(n),c=this._side(),u=this._caption(f);if(F(t,s,i),a.mode==="toggle"){const g=kt(r,r?.row,r?.col,"box"),k=Mt(g,f===!0,a,r);if(et(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),Math.round(l.h),k,a,i),c==="inside"&&u){t.save(),t.beginPath(),t.rect(l.x,l.y,l.w,l.h),t.clip();const b=l.w-l.h-2*i;P(t,u,k>.5?l.x+i:l.x+l.h+i,l.y,b,l.h,"#ffffff"),t.restore();return}}else Xt(t,Math.round(l.x),Math.round(l.y),Math.round(l.w),f,i,a.mode==="modern");if(u===void 0||u==="")return;const d=U(s);if(c==="top"||c==="bottom"){const g=s.fontSize*1.25*i,k=c==="top"?l.y-g:l.y+l.h;P(t,u,e.x,k,e.w,g,d);return}const h=4*i,m=c==="left"?e.x+3*i:l.x+l.w+h,p=c==="left"?l.x-h-m:e.x+e.w-m-2*i;if(!a.wrap){j(t,u,m,e.y,e.h,d);return}const y=De(t,u,p),M=s.fontSize*1.2*i,S=y.length*M,T=s.vAlign,x=T==="top"?e.y+2*i:T==="center"?e.y+(e.h-S)/2:e.y+e.h-S-2*i;y.forEach((g,k)=>j(t,g,m,x+k*M,M,d))}hitTest(t,e,n,s=1,i=null){const{hit:r}=this.options;return r==="cell"||r!=="box"&&this._hasCaption()?B(t,e,n)?{part:"box"}:null:B(this._box(t,s,i),e,n)?{part:"box"}:null}activate(t,e,n){const{book:s}=t,i=this._state(_(s,s.sheet,e,n));return this.options.threeState?E(t,e,n,i===!0?"FALSE":i===!1?"":"TRUE"):E(t,e,n,i?"FALSE":"TRUE")}fitWidth(t,e){const n=this.options,s=n.mode==="toggle"?n.toggleHeight??n.boxSize??13:n.boxSize??13,i=this._caption(this._state(t)),r=this._side(),a=n.mode==="toggle"?n.toggleWidth??s*2:s,l=i?L(e,i):0;return r==="inside"?K(n,s,1,L(e,this._longestCaption()))+8:r==="top"||r==="bottom"?Math.max(a,l)+6:a+6+(l?l+4:0)}}class rt extends Y{static sanitize(t){return{items:Bt(t.items),horizontal:$(t.horizontal),separator:R(t.separator,16),flow:$(t.flow),maxRows:v(t.maxRows,1,200),maxCols:v(t.maxCols,1,200),spacingX:v(t.spacingX,0,64),spacingY:v(t.spacingY,0,64),pad:v(t.pad,0,64),boxSize:v(t.boxSize,6,64),textSide:tt(t.textSide,["left","inside"]),mode:tt(t.mode,["modern","toggle"]),...Vt(t)}}get blocksEditing(){return!0}_itemWidth(t,e){const n=this.options,s=n.boxSize??13,i=n.mode==="toggle"?K(n,s,1):s;if(n.textSide==="inside"&&(n.mode==="toggle"||this.type==="radio")){const r=L(e,t.text);return(n.mode==="toggle"?K(n,s,1,r):r+s+8)+6}return i+10+L(e,t.text)+(t.image?16:0)}_slots(t,e,n){return je(t,this.options,e,n,(s,i)=>this._itemWidth(s,i))}hitTest(t,e,n,s=1,i=null){if(!B(t,e,n))return null;const r=this._slots(t,s,i).findIndex(a=>B(a,e,n));return r<0||this.options.items[r].disabled?null:{part:"item",index:r}}_hitItem(t,e,n,s,i){const{book:r}=t,a=r.styles.list[r.sheet.style(e,n)]??r.styles.list[0];return this.hitTest(ot(t,e,n),s,i,t.grid.zoom,a)}_nextEnabled(t){const{items:e}=this.options;for(let n=1;n<=e.length;n++){const s=(t+n)%e.length;if(!e[s].disabled)return s}return-1}fitWidth(t,e){const{items:n,horizontal:s,spacingX:i=0,pad:r=0,maxCols:a}=this.options,l=n.map(u=>this._itemWidth(u,e));if(l.length===0)return 0;const f=s?Math.min(a??l.length,l.length):1,c=Math.max(...l);return(s&&f===l.length?l.reduce((u,d)=>u+d,0):c*f)+i*(f-1)+r*2}}class Xe extends rt{static typeName="radio";paint(t,e,n,s,i,r){F(t,s,i),this._slots(e,i,s).forEach((a,l)=>{const f=this.options.items[l];Jt(t,a,f,J(n,f.value),s,i,this.options,Yt,r,l)})}activate(t,e,n,s,i){const{items:r}=this.options;if(r.length===0)return!1;let a;if(s==null){const{book:l}=t,f=_(l,l.sheet,e,n);if(a=this._nextEnabled(r.findIndex(c=>J(f,c.value))),a<0)return!1}else{const l=this._hitItem(t,e,n,s,i);if(!l)return!1;a=l.index}return E(t,e,n,W(r[a].value))}}const lt=o=>o.separator??", ";function wt(o,t){if(o==null||o==="")return new Set;const e=String(o).split(lt(t).trim()||",").map(n=>n.trim().toLowerCase());return new Set(t.items.filter(n=>e.includes(String(n.value).toLowerCase())).map(n=>n.value))}class Ye extends rt{static typeName="checklist";paint(t,e,n,s,i,r){F(t,s,i);const a=wt(n,this.options),l=this.options.mode==="toggle"?et:Xt;this._slots(e,i,s).forEach((f,c)=>{const u=this.options.items[c];Jt(t,f,u,a.has(u.value),s,i,this.options,l,r,c)})}_write(t,e,n,s){return E(t,e,n,W(s.join(lt(this.options))))}activate(t,e,n,s,i){const{items:r}=this.options,{book:a}=t,l=wt(_(a,a.sheet,e,n),this.options);if(s==null)return gt(t,e,n,{items:r.filter(u=>!u.disabled),selected:[...l],multi:!0,label:"Choices",onDone:u=>this._write(t,e,n,u)}),!0;const f=this._hitItem(t,e,n,s,i);if(!f)return!1;const c=r[f.index];return l.has(c.value)?l.delete(c.value):l.add(c.value),this._write(t,e,n,r.filter(u=>l.has(u.value)).map(u=>u.value))}}class Ue extends rt{static typeName="buttonlist";static sanitize(t){return{...rt.sanitize(t),horizontal:t.horizontal!==!1||void 0,multiple:$(t.multiple),selectedColor:I(t.selectedColor),selectedInk:I(t.selectedInk)}}_itemWidth(t,e){return L(e,t.text)+14+(t.image?18:0)}_chosen(t){if(this.options.multiple)return wt(t,this.options);const e=this.options.items.find(n=>J(t,n.value));return new Set(e?[e.value]:[])}paint(t,e,n,s,i){F(t,s,i);const r=this.options,a=Math.max(1,Math.round(i)),l=this._chosen(n);this._slots(e,i,s).forEach((f,c)=>{const u=r.items[c],d=l.has(u.value),h=Math.round(f.x)+a,m=Math.round(f.y)+a,p=Math.round(f.w)-a*2,y=Math.round(f.h)-a*2;if(p<=0||y<=0)return;u.disabled&&H(t,!0);const M=r.selectedColor??w.theme.accent;t.fillStyle=u.color??(d?M:"#efefef"),t.fillRect(h,m,p,y);const S=d&&u.color?a*2:a;t.strokeStyle=d?M:"#8f8f8f",t.lineWidth=S,t.strokeRect(h+S/2,m+S/2,p-S,y-S),t.save(),t.beginPath(),t.rect(h,m,p,y),t.clip();const T=u.ink??(d&&!u.color?r.selectedInk??"#ffffff":s.color??"#000000"),x=u.image?yt(u.image):null;if(x){const g=Math.min(y-2*a,Math.round(14*i)),k=t.measureText(u.text).width+(u.text?Math.round(4*i):0),b=h+Math.max(a,(p-g-k)/2);bt(t,x,b,m+(y-g)/2,g,g),j(t,u.text,b+g+Math.round(4*i),m,y,T)}else P(t,u.text,h,m,p,y,T);t.restore(),u.disabled&&H(t,!1)}),r.items.length>0&&(t.textAlign="left")}activate(t,e,n,s,i){const{items:r,multiple:a}=this.options;if(r.length===0)return!1;const{book:l}=t,f=_(l,l.sheet,e,n);if(s==null){if(a)return gt(t,e,n,{items:r.filter(h=>!h.disabled),selected:[...this._chosen(f)],multi:!0,label:"Choices",onDone:h=>E(t,e,n,W(h.join(lt(this.options))))}),!0;const d=this._nextEnabled(r.findIndex(h=>J(f,h.value)));return d>=0&&E(t,e,n,W(r[d].value))}const c=this._hitItem(t,e,n,s,i);if(!c)return!1;const u=r[c.index];if(a){const d=this._chosen(f);return d.has(u.value)?d.delete(u.value):d.add(u.value),E(t,e,n,W(r.filter(h=>d.has(h.value)).map(h=>h.value).join(lt(this.options))))}return E(t,e,n,J(f,u.value)?"":W(u.value))}}function at(o,t,e){if(typeof o=="number")return o;if(typeof o=="string"&&t){const n=t.findIndex(s=>s.toLowerCase()===o.toLowerCase());if(n>=0)return n}return e}function St(o,t,e,n){const s=[];for(let i=0;i<o;i++){const r=z(t(i,e)),a=z(t(i,n));(r!==""||a!=="")&&s.push({text:String(r),value:String(a)})}return s}function Je(o,t,e,{textColumn:n,valueColumn:s},i,r){const a=e.replace(/^=/,"").trim(),l=e[0]==="="?void 0:o.engine?.tables.get(a.toUpperCase());if(l){const M=l.columns?.map(k=>typeof k=="string"?k:k?.name??""),S=at(n,M,0),T=at(s,M,S),x=l.r0+(l.headerRows??1),g=l.r1-x+1-(l.totalsRows??0);return St(g,(k,b)=>_(o,l.sheet,x+k,l.c0+b),S,T)}const f=at(n,null,0),c=at(s,null,f),u=a.lastIndexOf("!"),d=e[0]==="="?null:dt(u>=0?a.slice(u+1):a);if(d){const M=u>=0?a.slice(0,u).replace(/^'|'$/g,"").replace(/''/g,"'"):null,S=M===null?t:o.sheets.find(x=>x.name.toLowerCase()===M.toLowerCase());if(!S)return[];const T=Math.min(d.r1,S.maxRow)-d.r0+1;return St(T,(x,g)=>_(o,S,d.r0+x,d.c0+g),f,c)}const{engine:h}=o;if(!h)return[];let m;try{const M=h.template(a,i,r);if(M.invalid)return[];m=M.fn(i,r,t),m&&m.sheet&&(m=h.toArr(m))}catch{return[]}if(!m||!m.data)return m==null||typeof m=="object"?[]:[{text:String(z(m)),value:String(z(m))}];const p=m.cols,y=(M,S)=>{const T=m.data[M*p+S];return T===void 0||T!==null&&typeof T=="object"?null:T};return St(m.rows,y,f,c)}function Ve(o,t,e){if(e[0]==="=")return null;const n=e.trim(),s=o.engine?.tables.get(n.toUpperCase());if(s)return`${o.sheets.indexOf(s.sheet)}:${s.sheet.revision}:${s.r0}:${s.r1}:${s.c0}:${s.c1}`;const i=n.lastIndexOf("!"),r=i>=0?n.slice(0,i).replace(/^'|'$/g,"").replace(/''/g,"'"):null,a=r===null?t:o.sheets.find(l=>l.name.toLowerCase()===r.toLowerCase());return a?`${o.sheets.indexOf(a)}:${a.revision}`:null}const Gt=new WeakMap;function Tt(o,t){if(t==null)return;let e=Gt.get(o);if(e===void 0){e=new Map;for(const n of o){const s=String(n.value).toLowerCase();e.has(s)||e.set(s,n.text)}Gt.set(o,e)}return e.get(String(t).toLowerCase())}class Ge extends Y{static typeName="combobox";static sanitize(t){return{items:Bt(t.items),editable:$(t.editable),source:typeof t.source=="string"&&t.source.length<=500?t.source:void 0,textColumn:typeof t.textColumn=="string"?R(t.textColumn,200):v(t.textColumn,0,49),valueColumn:typeof t.valueColumn=="string"?R(t.valueColumn,200):v(t.valueColumn,0,49),maxItems:v(t.maxItems,1,100),float:t.float===!1?!1:void 0}}get blocksEditing(){return this.options.editable!==!0}get opensList(){return!0}_items(t,e,n,s){const{source:i,items:r}=this.options;if(i===void 0)return r;const a=Ve(t,e,i);return((a===null?this.sourceFrame!==w.id||this.sourceFrame===void 0:this.sourceStamp!==a)||this.sourceItems===void 0)&&(this.sourceFrame=w.id,this.sourceStamp=a,this.sourceItems=Je(t,e,i,this.options,n,s)),this.sourceItems}_arrow(t,e){const n=Math.min(16*e,t.h);return{x:t.x+t.w-n,y:t.y+(t.h-n)/2,w:n,h:n}}paint(t,e,n,s,i,r){const a=r?.printing===!0,l=this._arrow(e,i),f=r?.book?this._items(r.book,r.sheet,r.row,r.col):this.options.items,c=Tt(f,n)??Te(n,s);if(F(t,s,i),t.save(),t.beginPath(),t.rect(e.x,e.y,a?e.w:e.w-l.w,e.h),t.clip(),j(t,c,e.x+Math.round(2*i),e.y,e.h,U(s)),t.restore(),a)return;const u=Math.round(l.x),d=Math.round(l.y),h=Math.round(l.w);t.fillStyle="#f7f7f7",t.fillRect(u,d,h,h),t.strokeStyle="#8f8f8f",t.lineWidth=Math.max(1,Math.round(i/2)),t.strokeRect(u+.5,d+.5,h-1,h-1),t.fillStyle="#444444",t.beginPath(),t.moveTo(u+h*.28,d+h*.4),t.lineTo(u+h*.72,d+h*.4),t.lineTo(u+h*.5,d+h*.66),t.closePath(),t.fill()}hitTest(t,e,n,s=1){return B(t,e,n)?B(this._arrow(t,s),e,n)?{part:"arrow"}:this.options.editable?null:{part:"text"}:null}activate(t,e,n){const{book:s}=t,i=_(s,s.sheet,e,n);this.sourceFrame=void 0,this.sourceItems=void 0;const r=this._items(s,s.sheet,e,n);this.sourceFrame=void 0;const l=Tt(r,i)===void 0?void 0:r.find(f=>J(i,f.value));return gt(t,e,n,{items:r,selected:l?[l.value]:[],label:"Choices",maxItems:this.options.maxItems??20,moveOnSide:!0,float:this.options.float!==!1,onDone:f=>f.length===0?!0:E(t,e,n,W(f[0]))}),!0}fitWidth(t,e){const n=Tt(this.sourceItems??this.options.items,t)??z(t);return L(e,String(n))+22}}const xt=new Set;class qe extends Y{static typeName="hyperlink";static sanitize(t){return{url:Ft(t.url),location:Ce(t.location),text:R(t.text),color:I(t.color),visitedColor:I(t.visitedColor),tooltip:R(t.tooltip),action:R(t.action),activeOnClick:t.activeOnClick===!1?!1:void 0}}get tooltip(){return this.options.tooltip}get runsWithoutSelecting(){return this.options.activeOnClick===!1}paint(t,e,n,s,i){const r=this.options.text??z(n);if(r==="")return;F(t,s,i);const a=e.x+Math.round(2*i),{url:l,location:f,color:c,visitedColor:u}=this.options,d=l??f??(typeof n=="string"?n:""),h=xt.has(d)?u??"#954f72":c??s.color??"#0563c1";j(t,r,a,e.y,e.h,h);const m=s.fontSize*i,p=Math.min(t.measureText(r).width,e.w-Math.round(4*i));t.fillRect(a,Math.round(e.y+e.h/2+m*.42),p,Math.max(1,Math.round(m/14)))}hitTest(t,e,n){return B(t,e,n)?{part:"link"}:null}activate(t,e,n){const{url:s,location:i,action:r}=this.options,{book:a}=t;if(r!==void 0){const f={row:e,col:n,sheet:a.sheet,action:r};$t(r,{app:t,...f}),t.grid.host.dispatchEvent(new CustomEvent("cellbutton",{bubbles:!0,detail:f}))}if(i)return xt.add(i),t.controller._followLink({location:i}),!0;const l=s??Ft(_(a,a.sheet,e,n));return l?(xt.add(l),t.grid.invalidate(),t.controller._followLink({target:l}),!0):(r===void 0&&t.shell.setStatus("This link has no web or mail address to open."),!0)}fitWidth(t,e){return L(e,String(this.options.text??z(t)))+7}}class Ze extends Y{static typeName="progress";static sanitize(t){const e=n=>Number.isFinite(n)?n:void 0;return{min:e(t.min),max:e(t.max),color:I(t.color),hideText:t.hideText===!0||void 0}}paint(t,e,n,s,i){const r=this.options.min??0,a=this.options.max??1,l=Math.max(1,Math.round(2*i)),f=e.x+l,c=e.y+l,u=e.w-l*2,d=e.h-l*2;if(u<=0||d<=0)return;if(t.fillStyle="#e6e6e6",t.fillRect(f,c,u,d),F(t,s,i),typeof n=="string"&&n.startsWith("#")){P(t,n,f,c,u,d,U(s));return}const h=typeof n=="number"?n:0,m=a>r?Math.max(0,Math.min(1,(h-r)/(a-r))):0;t.fillStyle=this.options.color??w.theme.accent,t.fillRect(f,c,Math.round(u*m),d),this.options.hideText||P(t,`${Math.round(m*100)}%`,f,c,u,d,m>.5?"#ffffff":U(s))}}for(const o of[He,Ke,Xe,Ye,Ue,Ge,qe,Ze])Se(o);const On=ve();function N(o,t,e){if(!q(o))return null;const n=o.mergeAt(t,e);return D(o,n?n.r0:t,n?n.c0:e)??null}const V=(o,t,e,n)=>o.styles.list[t.style(e,n)]??o.styles.list[0];function qt(o,t,e,n,s,i,r,a,l,f,c,u,d){const h=e.kind(i,r)&ct,m=V(n,e,i,r);h===ut&&(o.fillStyle=m.fill??s.cellBg,o.fillRect(a,l,f-d,c-d));const p=At(e,i,r,m);if(p!==null){const y=Math.round(p[0]*u);a+=y,f=Math.max(0,f-y-Math.round(p[1]*u))}o.save(),o.beginPath(),o.rect(a,l,f,c),o.clip(),w.row=i,w.col=r,t.paint(o,{x:a,y:l,w:f,h:c},_(n,e,i,r),m,u,w),o.restore()}function An(o,t,e,n,s){const{sheet:i,book:r,theme:a,dpr:l,zoom:f}=t,c=i.cellTypes;w.theme=a,w.book=r,w.sheet=i,w.grid=t,w.printing=!1,w.id++;const{ca:u,cb:d,ra:h,rb:m,s:p,xs:y,ys:M}=n,S=Math.max(1,Math.round(l*Math.min(f,1))),T=s.length>0,x=(g,k,b)=>{if(T&&i.mergeAt(k,b)!==null)return;const C=y[b-u],O=M[k-h],A=y[b-u+1]-C,G=M[k-h+1]-O,X=t.indicatorWidth?.(k,b,A,p)??0;A>0&&G>0&&qt(o,g,i,r,a,k,b,C+X,O,A-X,G,p,S)};if(!i.cellTypeRules&&c.size<(d-u+1)*(m-h+1))for(const[g,k]of c){const b=Math.floor(g/16384),C=g-b*16384;b>=h&&b<=m&&C>=u&&C<=d&&x(k,b,C)}else for(let g=h;g<=m;g++)for(let k=u;k<=d;k++){const b=D(i,g,k);b!==void 0&&x(b,g,k)}for(const g of s){const k=D(i,g.r0,g.c0);if(k===void 0||g.c1<u||g.c0>d)continue;const b=t._rectInPane(g,e,p),C=t.indicatorWidth?.(g.r0,g.c0,b.w,p)??0;qt(o,k,i,r,a,g.r0,g.c0,b.x+C,b.y,b.w-C,b.h,p,S)}}const Qe={cellBg:"#ffffff",cellInk:"#000000",accent:"#404040"};function Wn(o,t,e,n,s,i,r,a,l){const f=D(e,n,s);return f===void 0?!1:(w.theme=Qe,w.book=t,w.sheet=e,w.grid=null,w.printing=!0,w.row=n,w.col=s,w.id++,o.save(),o.beginPath(),o.rect(i,r,a,l),o.clip(),f.paint(o,{x:i,y:r,w:a,h:l},_(t,e,n,s),V(t,e,n,s),1,w),o.restore(),w.printing=!1,!0)}function Pn(o,t,e,n,s,i,r){const a=t.cellTypes;if(!t.cellTypeRules&&!(a instanceof Map))return;const l=(f,c)=>{(t.kind(f,c)&ct)===ut&&t.mergeAt(f,c)===null&&r(f,c)};if(!t.cellTypeRules&&a.size<(n-e+1)*(i-s+1))for(const f of a.keys()){const c=Math.floor(f/16384),u=f-c*16384;c>=e&&c<=n&&u>=s&&u<=i&&l(c,u)}else for(let f=e;f<=n;f++)for(let c=s;c<=i;c++)D(t,f,c)&&l(f,c)}function $n(o,t,e,n,s){const{book:i}=o,{sheet:r}=i,a=N(r,t,e);if(a===null||a.runsWithoutSelecting!==!0||!a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function Bn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(Q(r,i)&&Ae(o,t,e,n,s))return!0;const a=N(r,t,e);if(a===null||!a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e)))return!1;const l=r.mergeAt(t,e);return a.activate(o,l?l.r0:t,l?l.c0:e,n,s),!0}function Fn(o,t,e,n,s){const{book:i}=o,{sheet:r}=i;if(Q(r,i)&&Ie(o,t,e,n,s))return"pointer";if(!q(r))return null;const a=N(r,t,e),l=a?.tooltip,{host:f}=o.grid;return l!==void 0?f.title=l:f.title!==""&&(f.title=""),a!==null&&a.hitTest(ot(o,t,e),n,s,o.grid.zoom,V(i,r,t,e))?"pointer":null}function Nn(o,t){const{sheet:e}=o.book,n=Q(e,o.book);if(!q(e)&&!e.cellDropdowns&&!n)return!1;const s=o.grid.selection,{row:i,col:r}=s,a=t.metaKey||t.ctrlKey||t.shiftKey;if(t.altKey&&!a&&n&&/^Digit[1-9]$/.test(t.code)&&We(o,i,r,Number(t.code[5])-1))return!0;if(t.key==="ArrowDown"&&t.altKey&&!a){if(Ot(o,i,r)||n&&Ee(o,i,r))return!0;const l=N(e,i,r);return l&&l.opensList?l.activate(o,i,r,null,null):!1}if((t.key==="Delete"||t.key==="Backspace")&&!a&&!t.altKey&&q(e)&&tn(o))return!0;if(t.key===" "&&!a&&!t.altKey){const l=N(e,i,r);if(l===null)return!1;const f=e.mergeAt(i,r);return l.activate(o,f?f.r0:i,f?f.c0:r,null,null)}return!1}function tn(o){const{book:t,grid:e}=o,{sheet:n}=t,s=e.selection.ranges;let i=s,r=[];for(const f of n.cellTypeRules??[])for(const c of f.ranges){if(f.spec.type==="checkbox")for(const u of i){const d=vt(u,c);d&&r.push(d)}i=i.flatMap(u=>_t(u,c))}const a=[];for(const[f,c]of n.cellTypes??[]){const u=Math.floor(f/Z),d=f%Z,h={r0:u,r1:u,c0:d,c1:d};s.some(m=>vt(m,h))&&(c.type==="checkbox"?a.push(h):r=r.flatMap(m=>_t(m,h)))}if(r=r.concat(a),!r.length)return!1;const l=new Set;for(const f of r)te(n,f,(c,u)=>{Wt(_(t,n,c,u))&&l.add(pt(c,u))});return l.size?t.transact("entry",f=>{for(const c of l)t.setInput(f,Math.floor(c/Z),c%Z,"FALSE")}):fe(t,"Clear",()=>{re(t,r,"cellTypes",null),t.clearRange(s)}),e.invalidate(),o.controller?.syncFormulaBar?.(),!0}function Dn(o,t,e){const{sheet:n}=o.book;if(!q(n))return!1;const s=N(n,t,e);return s===null||!s.blocksEditing?!1:(o.controller.focusGrid(),s.opensList?s.activate(o,t,e,null,null):o.shell.setStatus("This cell holds a control. Click it or press Space to change it."),!0)}function jn(o,t,e){const{book:n}=o,s=N(n.sheet,t,e);return s===null?void 0:s.editText(_(n,n.sheet,t,e))}function Hn(o,t,e,n){const s=N(o.book.sheet,t,e);return s===null?n:s.parseEdit(n)}function Kn(o,t,e,n,s){const i=D(o,e,n),r=V(t,o,e,n);let a=s;if(i!==void 0){w.book=t,w.sheet=o,w.row=e,w.col=n;const f=i.fitWidth(_(t,o,e,n),r);f>0&&(a=f-7)}const l=At(o,e,n,r);return l===null?a:a+l[0]+l[1]}function Xn(o){jt(o),o.grid.host.addEventListener("pointerleave",()=>{Q(o.book.sheet,o.book)&&Dt(o,null,0,0)})}function Yn(o,t){const e=[];for(const n of[o.cellTypes,o.cellButtons])if(n instanceof Map)for(const s of n.keys())s%16384===t&&e.push(Math.floor(s/16384));for(const n of o.cellTypeRules??[])for(const s of n.ranges)if(!(t<s.c0||t>s.c1)){for(let i=s.r0;i<=s.r1;i++)if((o.kind(i,t)&ct)===ut&&!o.mergeAt(i,t)&&D(o,i,t)===n.spec){e.push(i);break}}return e}const Un=(o,t)=>ie(o,t);function en(o,t,e){const n=o.lastIndexOf("!");return n<0||o.slice(0,n).replace(/^'|'$/g,"").replace(/''/g,"'").toLowerCase()!==t.toLowerCase()?o:`${ne(e)}${o.slice(n)}`}function Zt(o,t,e){let n=null;for(const s of["source","location"]){if(typeof o[s]!="string")continue;const i=en(o[s],t,e);i!==o[s]&&((n??={...o})[s]=i)}return n}oe.push((o,t,e)=>{const n=new Map,s=(r,a,l)=>{const f=r[a];if(!(f instanceof Map))return;let c=null;for(const[u,d]of f){n.has(d)||n.set(d,l(d));const h=n.get(d);h!==d&&(c??=new Map(f)).set(u,h)}c!==null&&(r[a]=c,r.cellTypesChanged=!0)},i=r=>{const a=Zt(r,t,e);return a===null?r:Lt(r.type,a)};for(const r of o.sheets){const a=l=>{const f=Zt(l.options,t,e);return f===null?l:Pt(l.type,f)};s(r,"cellTypes",a),r.cellTypeRules&&(r.cellTypeRules=r.cellTypeRules.map(({ranges:l,spec:f})=>({ranges:l,spec:a(f)})),r.cellTypesChanged=!0),s(r,"cellDropdowns",i),s(r,"cellButtons",l=>{const f=l.map(c=>{if(!c.dropdown||c.dropdown===!0)return c;const u=i(c.dropdown);return u===c.dropdown?c:{...c,dropdown:u}});return f.some((c,u)=>c!==l[u])?Nt(f):l})}});function nn(o){o.sort((i,r)=>i%16384-r%16384||i-r);const t=[];let e=-1,n=-1;const s=()=>{if(e<0)return;const i=Math.floor(e/16384),r=e-i*16384,a=Math.floor(n/16384);t.push(Rt({r0:i,c0:r,r1:a,c1:r}))};for(const i of o)e>=0&&i===n+16384||(s(),e=i),n=i;return s(),t}function Ct(o,t,e){if(!o||o.size===0)return;const n=new Map;for(const[s,i]of o){const r=zt(i);let a=n.get(r);a===void 0&&(a=[],n.set(r,a)),a.push(s)}for(const[s,i]of n)e.push({kind:t,json:s,keys:i})}function on(o){const t=[];if(Ct(o.cellTypes,"type",t),Ct(o.cellDropdowns,"dropdown",t),Ct(o.cellButtons,"buttons",t),!o.cellTypeRules&&t.length===0)return null;const e=t.map(s=>`<entry kind="${s.kind}" config="${mt(s.json)}" ref="${nn(s.keys).join(" ")}"/>`).join(""),n=(o.cellTypeRules??[]).map(({ranges:s,spec:i})=>`<rangeRule config="${mt(zt(i))}" ref="${s.map(Rt).join(" ")}"/>`).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<cellTypes xmlns="${de}" version="1" sheet="${mt(o.name)}">${e}${n}</cellTypes>`}function sn(o,t){let e;try{e=Et(new TextEncoder().encode(o))}catch{return}if(e?.n!=="cellTypes")return;const n=new Map,s=new Map,i=new Map;let r=0;for(const l of It(e,"entry")){let f;try{f=JSON.parse(ht(l.a.config??""))}catch{continue}if(f===null||typeof f!="object")continue;const{kind:c}=l.a;let u;if(c==="dropdown"?u=Lt(f.type,f):c==="buttons"?u=Nt(f):u=nt(f),u===null)continue;const d=c==="dropdown"?s:c==="buttons"?i:n;for(const h of String(l.a.ref??"").split(/\s+/)){const m=dt(h);if(m)for(let p=m.r0;p<=m.r1&&r<Kt;p++)for(let y=m.c0;y<=m.c1&&r<Kt;y++)d.set(pt(p,y),u),r++}}const a=[];for(const l of It(e,"rangeRule")){let f;try{f=JSON.parse(ht(l.a.config??""))}catch{continue}if(!f||typeof f!="object")continue;const c=nt(f),u=String(l.a.ref??"").split(/\s+/).map(dt).filter(Boolean);c&&u.length&&a.push({ranges:u,spec:c})}t.cellTypeRules=a.length?a:null,t.cellTypes=n.size>0?n:null,t.cellDropdowns=s.size>0?s:null,t.cellButtons=i.size>0?i:null}const rn=o=>{for(const t of o.formulas.descriptors())if(t.cm||t.tpl?.mayArray)return!0;return!1};function Jn(o){const t=[];return o.sheets.forEach((e,n)=>{const s=on(e);s!==null&&t.push(ue(n,s))}),t.push(...me(o),...Pe(o),...ge(o),...Me(o),...we(o,o.sheets.some(e=>rn(e)))),t}async function Vn(o,t){const e=await se(o);for(const{text:n}of await he(e)){if(n.includes(ce)){pe(n,t);continue}let s=null;try{s=Et(new TextEncoder().encode(n))}catch{continue}const i=ht(s?.a?.sheet),r=t.sheets.find(a=>a.name===i);r&&sn(n,r)}await Qt(e,t),await ye(e,t),await be(e,t),await ke(e,t)}export{On as CELL_TYPE_NAMES,Xn as attachCellEvents,jt as attachFileDrop,le as cellDropdownArrow,Kn as cellFitWidth,pt as cellKey,N as cellTypeAt,Dn as cellTypeBlocksEdit,Fn as cellTypeCursor,jn as cellTypeEditText,Hn as cellTypeParseEdit,Jn as cellTypesPackage,ae as closeDropdown,Yn as fitRowsOfColumn,Bn as handleCellClick,Nn as handleCellKey,Q as hasCellButtons,$e as hideEditingButtons,Vn as loadCellTypes,Pt as makeCellType,Ot as openCellDropdown,ze as paintCellButtons,An as paintCellTypes,Le as paintFloatingButtons,Oe as paintStyleButtons,sn as parse,$n as pressWithoutSelecting,Wn as printCellType,Pn as printEmptyTypedCells,_e as registerButtonAction,Re as registerCellType,on as serialize,Un as shiftCellTypes,Be as showEditingButtons,Dt as trackButtonHover};
|
package/celltypes/diagonal.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cellKey as $,clipRange as J,MAX_APPLY_CELLS as R,swapMap as X}from"./dropdowns.js";import{CellType as Y,defineCellType as j,inkOf as F,labelOf as I,makeCellType as H,oneOf as _,paintPlain as K,parseJsonCached as V,safeColor as q,setFont as
|
|
1
|
+
import{cellKey as $,clipRange as J,MAX_APPLY_CELLS as R,swapMap as X}from"./dropdowns.js";import{CellType as Y,defineCellType as j,inkOf as F,labelOf as I,makeCellType as H,oneOf as _,paintPlain as K,parseJsonCached as V,safeColor as q,setFont as v,textWidth as G}from"./base.js";const b=10,Q=["thin","medium","thick","hair","dotted","dashed","dashDot","mediumDashed"];function k(o){if(o==null)return[];if(typeof o=="string"&&o.startsWith("[")){const a=V(o);if(Array.isArray(a))return a.slice(0,b).map(s=>String(I(s)))}const t=String(I(o));return t===""?[]:t.split(",").slice(0,b).map(a=>a.trim())}const U=o=>o.some(t=>t.includes(","))?JSON.stringify(o):o.join(",");function Z(o,t,a){const{x:s,y:e,w:n,h:i}=o;if(t===2)return[a?[s+n,e+i]:[s+n,e]];if(t===3)return a?[[s+n,e+i*2/3],[s+n*2/3,e+i]]:[[s+n*2/3,e],[s+n,e+i/3]];const r=n+i,c=[];for(let f=1;f<t;f++){const l=r*f/t;a?c.push(l<=i?[s+n,e+l]:[s+n-(l-i),e+i]):c.push(l<=n?[s+l,e]:[s+n,e+(l-n)])}return c}function x(o,t,a){const s=t.split(/\s+/),e=[];let n="";for(const i of s){const r=n===""?i:`${n} ${i}`;n!==""&&o.measureText(r).width>a?(e.push(n),n=i):n=r}return e.push(n),e}function tt(o,t,a,s,e,n,i,r){const c=Math.max(1,Math.round(r));o.strokeStyle=n,o.lineWidth=(i==="thick"?3:i.startsWith("medium")?2:1)*c,o.setLineDash(i==="dotted"||i==="hair"?[c,c]:/dash/i.test(i)?[3*c,2*c]:[]),o.beginPath(),o.moveTo(t,a),o.lineTo(s,e),o.stroke(),o.setLineDash([])}class et extends Y{static typeName="diagonal";static sanitize(t){return{direction:_(t.direction,["up"]),color:q(t.color),lineStyle:_(t.lineStyle,Q)}}realBorder(){const t=this.options.direction==="up";return{d:{style:this.options.lineStyle??"thin",color:this.options.color??"#000000"},up:t,down:!t}}paint(t,a,s,e,n,i){const r=k(s);if(r.length<2){K(t,a,s,e,n);return}const c=this.options.direction!=="up",{x:f,y:l,w:S,h:m}=a,p=e.borders,d=p?.d&&(c?p.down:p.up);r.length>2&&p?.d&&(t.fillStyle=e.fill??i?.theme?.cellBg??"#ffffff",t.fillRect(f+1,l+1,S-2,m-2));const h=f,T=c?l:l+m,M=Z(a,r.length,c),z=this.options.color??"#000000",N=this.options.lineStyle??"thin";if(r.length>2||!d)for(const[L,u]of M)tt(t,h,T,L,u,z,N,n);v(t,e,n),t.fillStyle=F(e),t.textBaseline="middle";const C=Math.round(3*n),D=e.fontSize*1.2*n,P=(L,u,g)=>{const w=x(t,L,S*.66);t.textAlign=u?"right":"left";const y=u?f+S-C:f+C;w.forEach((B,E)=>{const A=g?l+C+D*(E+.5):l+m-C-D*(w.length-E-.5);t.fillText(B,y,A)})},O=(L,u,g,w,y)=>{const B=Math.atan2(y-T,w-h),E=Math.atan2(g-T,u-h),A=(B+E)/2,W=Math.hypot((u+w)/2-h,(g+y)/2-T);t.save(),t.translate(h+Math.cos(A)*W*.62,T+Math.sin(A)*W*.62),t.rotate(Math.abs(A)>Math.PI/2?A+Math.PI:A),t.textAlign="center",t.fillText(L,0,0),t.restore()};if(r.length<=3)P(r[0],c,!0),P(r[r.length-1],!c,!1),r.length===3&&O(r[1],M[0][0],M[0][1],M[1][0],M[1][1]);else{const L=c?[f+S,l]:[f,l],u=c?[f,l+m]:[f+S,l+m],g=[L,...M,u];r.forEach((w,y)=>O(w,g[y][0],g[y][1],g[y+1][0],g[y+1][1]))}t.textBaseline="alphabetic",t.textAlign="left"}fitWidth(t,a){const s=k(t);if(s.length<2)return 0;let e=12;for(const n of s)e+=G(a,n);return e}}j(et);function st(o,t,a,s){const{sheet:e}=o,n=H("diagonal",a),i=t.map(l=>J(e,l));let r=0;for(const l of i)r+=(l.r1-l.r0+1)*(l.c1-l.c0+1);if(r>R)return!1;const c=n.realBorder(),f=s&&s.length>0?U(s):null;return o.transact("cell type",l=>{const S=X("cellTypes",e.cellTypes??null),m=new Map(e.cellTypes??[]);for(const p of i)for(let d=p.r0;d<=p.r1;d++)for(let h=p.c0;h<=p.c1;h++){l.saveCell(d,h);const T=e.cellStyle(d,h),M=o.styles.get(T).borders??{l:null,r:null,t:null,b:null};e.setStyle(d,h,o.styles.derive(T,{borders:{...M,...c}})),f!==null&&o.setInput(l,d,h,f[0]==="["?`'${f}`:f,{overLimitAsText:!0}),m.set($(d,h),n)}return e.cellTypes=m,e.cellTypesChanged=!0,S}),!0}export{et as DiagonalCell,Q as LINE_STYLES,st as applyDiagonal,k as labelsOf,U as labelsToValue};
|