@8sheets/data-grid 1.0.2 → 1.1.0
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/theme-core.js +2 -0
- package/calc/compile.js +1 -1
- package/calc/engine.js +1 -1
- package/calc/functions/info.js +1 -1
- package/calc/functions/math.js +1 -1
- package/calc/parser.js +3 -3
- package/calc/values.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/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/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/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/diagonal.js +1 -1
- package/celltypes/dropdowns.js +2 -2
- package/core/autofill.js +1 -1
- package/core/axis-styles.js +1 -0
- package/core/axis.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/structure.js +1 -0
- package/core/styles.js +1 -1
- package/core/tables.js +2 -2
- 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/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/shell.js +2 -2
- package/i18n/pl/cells.js +1 -1
- package/i18n/pl/format.js +1 -1
- package/i18n/pl/shell.js +2 -2
- package/io/csv.js +8 -8
- package/io/plan.js +1 -1
- package/io/text-split.js +3 -3
- package/io/xlsx-write.js +1 -1
- package/objects/chart-model.js +1 -1
- package/package.json +1 -1
- package/pivot/engine.js +1 -1
- package/print/paginate.js +1 -1
- package/print/render-page.js +3 -3
- 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/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/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};
|
package/celltypes/dropdowns.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{formulaEntryLimit as rt}from"../calc/parser.js";import{overlayRoot as ot}from"../api/overlay.js";import{BOOL as st,EMPTY as at,ERR as lt,ERRORS as it,FORMULA as ct,KIND_MASK as V,NUM as ut,STR as dt}from"../core/sheet.js";import{MAX_COLS as pt,MAX_ROWS as ft,parseRangeRef as mt}from"../core/address.js";import{partsToSerial as I,serialToParts as R}from"../core/numfmt.js";import{validateEntry as ht,validationAt as yt}from"../core/cond-format.js";import{parseInput as xt}from"../core/input.js";import{askAboutInvalid as gt}from"../cells/validation-alert.js";import{t as w}from"../i18n/index.js";const P=(e,t)=>e*16384+t,W=["calendar","time","month","datetime","color","slider","calculator","list"],K=new Map;function Qt(e,t){W.includes(e)||W.push(e),K.set(e,t)}const vt=2e5,j=5e3,B={calendar:"yyyy-mm-dd",time:"h:mm:ss",month:"mmm yyyy",datetime:"yyyy-mm-dd h:mm:ss"};function U(e,t,n,s){const r=t.kind(n,s)&V;if(r===at)return null;const o=t.value(n,s);return r===ut?o:r===dt?e.strings.get(o):r===st?o!==0:r===lt?it[o]??"#N/A":null}function bt(e){const t=String(e??"");return t[0]==="="||t[0]==="'"?`'${t}`:t}function H(e,t,n,{overFormula:s=!1}={}){const{book:r}=e,{sheet:o}=r;return e.loading?!1:o.protection&&!r.styles.get(o.style(t,n)).unlocked?(e.shell.setStatus("This cell is on a protected sheet. Unprotect the sheet to change it."),!1):!s&&(o.kind(t,n)&ct)!==0?(e.shell.setStatus("This cell's value comes from a formula, so this control can't change it."),!1):!0}function kt(e,t,n,s,r){const{book:o}=e,{sheet:u}=o,i=yt(u,t,n);if(!i||!i.showError)return!0;const l=xt(s);if(ht(o,u,i,t,n,l.kind??0,l.value,l.text??s))return!0;const a=()=>{};return gt(e,i,{retry:a,cancel:a,accept:i.errorStyle==="warning"||i.errorStyle==="information"?r:a}),!1}function wt(e,t,n,s,{format:r,overFormula:o=!1}={}){if(!H(e,t,n,{overFormula:o}))return!1;if(s.startsWith("=")&&e.book.styles.get(e.book.sheet.style(t,n)).numFmt!=="@"){const u=rt(s.slice(1));if(u)return e.shell.setStatus(w(u)),!1}return kt(e,t,n,s,()=>q(e,t,n,s,r))?q(e,t,n,s,r):!1}function q(e,t,n,s,r){const{book:o,grid:u,controller:i}=e,l=o.sheet;return o.transact("entry",a=>{o.setInput(a,t,n,s),r&&o.styles.get(l.style(t,n)).numFmt==="General"&&l.setStyle(t,n,o.styles.derive(l.style(t,n),{numFmt:r}))}),e.commands?.afterEntry?.(t,n),u.invalidate(),i.syncFormulaBar(),!0}const G=(e,t)=>n=>{const s=G(e,n[e]??null);return n[e]=t,n.cellTypesChanged=!0,s};function Ct(e,{r0:t,c0:n,r1:s,c1:r}){const o=t===0&&s===ft-1,u=n===0&&r===pt-1;return{r0:t,c0:n,r1:o?Math.max(e.maxRow,999):s,c1:u?Math.max(e.maxCol,25):r}}function Zt(e,t,n,s){const r=e.sheet,o=t.map(i=>Ct(r,i));let u=0;for(const i of o)u+=(i.r1-i.r0+1)*(i.c1-i.c0+1);return u>vt?!1:(e.transact("cell type",()=>{const i=G(n,r[n]??null),l=new Map(r[n]??[]);for(const a of o)for(let y=a.r0;y<=a.r1;y++)for(let x=a.c0;x<=a.c1;x++)s===null?l.delete(P(y,x)):l.set(P(y,x),s);return r[n]=l.size>0?l:null,r.cellTypesChanged=!0,i}),!0)}function te(e,t={}){if(!W.includes(e))return null;const n={type:e},s=r=>{Number.isFinite(t[r])&&(n[r]=t[r])};return typeof t.format=="string"&&t.format.length<=64&&(n.format=t.format),e==="slider"&&(s("min"),s("max"),s("step")),e==="list"&&(typeof t.source=="string"&&t.source.length<=300&&(n.source=t.source),Number.isInteger(t.valueColumn)&&t.valueColumn>=0&&(n.valueColumn=t.valueColumn),Array.isArray(t.columns)&&(n.columns=t.columns.slice(0,50).map(r=>String(r).slice(0,200))),Array.isArray(t.rows)&&(n.rows=t.rows.slice(0,j).filter(Array.isArray).map(r=>r.slice(0,50).map(o=>typeof o=="number"?o:String(o).slice(0,1e3))))),K.get(e)?.sanitize?.(t,n),Object.freeze(n)}function X(e,t,n){const s=e.cellDropdowns;if(!s)return null;const r=e.mergeAt(t,n);return s.get(r?P(r.r0,r.c0):P(t,n))??null}function ee(e){const{sheet:t,sel:n,grid:s}=e;if(!t.cellDropdowns||!X(t,n.row,n.col))return null;const r=s.cellRect(n.row,n.col),o=Math.min(16,r.h);return{x:r.x+r.w+1,y:r.y+r.h-o,size:o}}const J="ct-popup-style",Dt=`
|
|
2
2
|
.ct-popup { position: fixed; z-index: 60; padding: 8px; border-radius: 8px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); box-shadow: var(--shadow); font: 12px -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; outline: none; max-width: calc(100vw - 16px); }
|
|
3
3
|
.ct-popup button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 0; cursor: default; }
|
|
4
4
|
.ct-popup button:where(:not(.ct-btn)):hover:not(:disabled) { background: var(--hover); }
|
|
@@ -39,4 +39,4 @@ import{overlayRoot as rt}from"../api/overlay.js";import{BOOL as ot,EMPTY as at,E
|
|
|
39
39
|
.ct-item.ct-cursor { background: var(--pressed); }
|
|
40
40
|
.ct-mark { width: 12px; text-align: center; }
|
|
41
41
|
.ct-value { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; }
|
|
42
|
-
`;function Dt(){if(document.getElementById(J))return;const e=document.createElement("style");e.id=J,e.textContent=Ct,document.head.append(e)}const f=(e,t={},...n)=>{const a=document.createElement(e);for(const[r,o]of Object.entries(t))r==="class"?a.className=o:r==="text"?a.textContent=o:r.startsWith("aria")||r==="role"?a.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,o):a[r]=o;return a.append(...n.filter(r=>r!=null)),a};let E=null;const te=()=>E!==null;function ee(e,t){E!==null&&(E.keepOpen=e,E.onClose=t)}function Et(e){E!==null&&(E.mode=e?"float":"confine")}function ne(){E!==null&&E.mode!=="float"&&L(!1)}function L(e=!0){if(E===null)return;const{el:t,app:n,onDocPointer:a,onClose:r}=E;E=null,r?.(),document.removeEventListener("pointerdown",a,!0),t.remove(),e&&n.controller.focusGrid()}function S(e,t,n,a,r){L(!1),Dt(),e.grid.ensureVisible(t,n);const o=f("div",{class:"ct-popup",role:"dialog",ariaLabel:C(a),tabIndex:-1}),u=l=>{!o.contains(l.target)&&!E?.keepOpen?.(l)&&L(!1)};E={el:o,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),o.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),L();else if(l.key==="Tab"){const s=[...o.querySelectorAll('button, input, [tabindex="0"]')].filter(y=>!y.disabled&&y.tabIndex>=0&&y.offsetParent!==null);if(s.length===0)return;const x=s.indexOf(document.activeElement);l.preventDefault(),s[(x+(l.shiftKey?-1:1)+s.length)%s.length].focus()}}),rt().append(o);const i=r(o);return St(e,t,n,o),(i??o).focus({preventScroll:!0}),o}function At(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,o=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=o,l=Math.max(60,i?r:o);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const x=n.querySelector(".ct-list");x&&(x.style.maxHeight=`${Math.max(30,l-18)}px`)}const s=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-s}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function St(e,t,n,a){const r=e.grid.host.getBoundingClientRect(),o=e.grid.domRect(e.grid.cellRect(t,n));if(E?.mode==="confine"){At(r,o,a);return}const u=a.getBoundingClientRect(),i=2,l=r.top+o.y+o.h+i,s=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+o.y-u.height-i);a.style.top=`${s}px`,a.style.left=`${Math.max(8,Math.min(r.left+o.x,window.innerWidth-u.width-8))}px`}function M(e,t,n,a,r){const o=kt(e,t,n,a,{...r,overFormula:!0});return o&&L(),o}const $=(e,t,n=null)=>f("div",{class:"ct-foot"},n,f("button",{class:"ct-btn",type:"button",text:C("Cancel"),onclick:()=>L()}),f("button",{class:"ct-btn ct-primary",type:"button",text:C("OK"),onclick:t})),_=["January","February","March","April","May","June","July","August","September","October","November","December"],Ft=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],N=61;function O(){const e=new Date;return I(e.getFullYear(),e.getMonth()+1,e.getDate())}const Q=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function T(e,t,n){const{book:a}=e,r=U(a,a.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Lt=(e,t)=>(t===12?I(e+1,1,1):I(e,t+1,1))-I(e,t,1);function Z(e,t,n,{min:a=N,max:r=1/0,marked:o=null}={}){const u=f("div"),i=Math.max(N,a),l=h=>Math.min(r,Math.max(i,h));let s=l(e);const x=e,y=O(),c=h=>{const k=R(s),m=I(k.year,k.month,1),D=m-R(m).weekday,b=d=>{const w=k.year*12+k.month-1+d,A=Math.floor(w/12),F=w%12+1;s=l(I(A,F,Math.min(k.day,Lt(A,F)))),c(h),n?.(s)},v=f("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${C(_[k.month-1])} ${k.year}`});for(const d of Ft)v.append(f("div",{class:"ct-dow",text:C(d)}));let g=null;for(let d=0;d<42;d++){const w=D+d;if(w<N){v.append(f("div"));continue}const A=w<i||w>r,F=R(w),Y=w===s,z=f("button",{class:`ct-cell${F.month!==k.month||A?" ct-out":""}${w===y?" ct-today":""}${(o?o(w):Math.floor(x)===w)?" ct-on":""}`,disabled:A,type:"button",text:String(F.day),tabIndex:Y?0:-1,role:"gridcell",ariaLabel:`${F.year}-${String(F.month).padStart(2,"0")}-${String(F.day).padStart(2,"0")}`,onclick:()=>t(w)});Y&&(g=z),v.append(z)}v.addEventListener("keydown",d=>{const w={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[d.key];if(w!==void 0)d.preventDefault(),s=l(s+w),c(!0),n?.(s);else if(d.key==="PageUp"||d.key==="PageDown")d.preventDefault(),b((d.key==="PageUp"?-1:1)*(d.shiftKey?12:1));else if(d.key==="Home"||d.key==="End"){d.preventDefault();const A=R(s).weekday;s=l(s+(d.key==="Home"?-A:6-A)),c(!0),n?.(s)}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(s))});const p=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:C("Previous month"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:`${C(_[k.month-1])} ${k.year}`}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:C("Next month"),tabIndex:-1,onclick:()=>b(1)}));u.replaceChildren(p,v),u.focusCell=g,h&&g?.focus({preventScroll:!0})};return c(!1),u}function tt(e){const t=(i,l,s)=>f("input",{type:"number",min:0,max:l,value:String(s),ariaLabel:C(i),onfocus(){this.select()},onkeydown(x){if(x.key==="ArrowUp"||x.key==="ArrowDown"){x.preventDefault();const y=Number(this.value)+(x.key==="ArrowUp"?1:-1);this.value=String(y>l?0:y<0?l:y)}}}),n=t("Hours",23,e.h),a=t("Minutes",59,e.m),r=t("Seconds",59,e.s),o=f("div",{class:"ct-time"},n,f("span",{text:":"}),a,f("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:o,first:n,read:()=>(u(n,23)*3600+u(a,59)*60+u(r,59))/86400}}function Mt(e,t,n,a){const r=T(e,t,n)??O();S(e,t,n,"Date picker",o=>{const u=s=>M(e,t,n,String(s),{format:a.format??B.calendar}),i=Z(Math.floor(r),u,void 0,{min:a.minDate,max:a.maxDate}),l=f("button",{class:"ct-btn",type:"button",text:C("Today"),onclick:()=>u(O())});return o.append(i,f("div",{class:"ct-foot"},l)),i.focusCell})}function It(e,t,n,a){const r=T(e,t,n),o=r===null?null:R(r).ms,u=new Date,i=o===null?{h:u.getHours(),m:u.getMinutes(),s:0}:Q(o);S(e,t,n,"Time picker",l=>{const s=tt(i),x=()=>M(e,t,n,String(s.read()),{format:a.format??B.time});return s.wrap.addEventListener("keydown",y=>{y.key==="Enter"&&(y.preventDefault(),x())}),l.append(s.wrap,$(e,x)),s.first})}function Rt(e,t,n,a){const r=T(e,t,n),o=R(r!==null&&r>=N?r:O()),u=a.startYear??1901,i=a.stopYear??9999;let l=Math.max(u,Math.min(i,o.year)),s=o.month-1;S(e,t,n,"Month picker",x=>{const y=k=>M(e,t,n,String(I(l,k+1,1)),{format:a.format??B.month}),c=f("div"),h=k=>{const m=f("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let D=null;_.forEach((g,p)=>{const d=f("button",{class:`ct-cell${l===o.year&&p===o.month-1&&r!==null?" ct-on":""}`,type:"button",text:C(g).slice(0,3),ariaLabel:`${C(g)} ${l}`,tabIndex:p===s?0:-1,onclick:()=>y(p)});p===s&&(D=d),m.append(d)});const b=g=>{l=Math.max(u,Math.min(i,l+g)),h(!0)};m.addEventListener("keydown",g=>{const p={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[g.key];if(p!==void 0){g.preventDefault();const d=s+p;d<0?(s=d+12,b(-1)):d>11?(s=d-12,b(1)):(s=d,h(!0))}else g.key==="PageUp"||g.key==="PageDown"?(g.preventDefault(),b(g.key==="PageUp"?-1:1)):(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),y(s))});const v=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:C("Previous year"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:String(l)}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:C("Next year"),tabIndex:-1,onclick:()=>b(1)}));c.replaceChildren(v,m),c.focusCell=D,k&&D?.focus({preventScroll:!0})};return h(!1),x.append(c),c.focusCell})}function Tt(e,t,n,a){const r=T(e,t,n),o=new Date,u=r!==null&&r>=N?Math.floor(r):O(),i=r!==null?Q(R(r).ms):{h:o.getHours(),m:o.getMinutes(),s:0};S(e,t,n,"Date and time picker",l=>{let s=u;const x=tt(i),y=()=>M(e,t,n,String(s+x.read()),{format:a.format??B.datetime}),c=Z(s,h=>{s=h,x.first.focus()},h=>{s=h},{min:a.minDate,max:a.maxDate});return x.wrap.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),y())}),x.wrap.style.marginTop="8px",l.append(c,x.wrap,$(e,y)),c.focusCell})}const $t=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Nt(e,t,n,a){const r=a.palette??$t,{book:o}=e,u=U(o,o.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;S(e,t,n,"Color picker",l=>{let s=Math.max(0,r.indexOf(i));const x=m=>{if(a.target===void 0){M(e,t,n,m);return}H(e,t,n,{overFormula:!0})&&(o.applyStyle([{r0:t,c0:n,r1:t,c1:n}],a.target==="fill"?{fill:m}:{color:m}),e.grid.invalidate(),L())},y=f("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:C("Colors")}),c=r.map((m,D)=>{const b=f("button",{class:`ct-swatch${m===i?" ct-on":""}`,type:"button",ariaLabel:m,title:m,tabIndex:D===s?0:-1,onclick:()=>x(m)});return b.style.background=m,y.append(b),b});y.addEventListener("keydown",m=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[m.key];if(D!==void 0){m.preventDefault();const b=s+D;b>=0&&b<r.length&&(c[s].tabIndex=-1,s=b,c[s].tabIndex=0,c[s].focus())}else(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),x(r[s]))});const h=f("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:C("Hex color")}),k=()=>{const m=h.value.trim(),D=/^#?[0-9a-f]{6}$/i.test(m)?`#${m.replace("#","").toUpperCase()}`:null;D?x(D):h.select()};return h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),k())}),l.append(y,f("div",{class:"ct-foot"},h,f("button",{class:"ct-btn",type:"button",text:C("Apply"),onclick:k}))),c[s]})}function Ot(e,t,n,a){const r=a.min??0,o=a.max??100,u=a.step??1,i=T(e,t,n);S(e,t,n,"Slider",l=>{const s=f("input",{type:"range",min:r,max:o,step:u,value:String(i??r),ariaLabel:C("Value")}),x=f("span",{class:"ct-value",text:s.value});s.addEventListener("input",()=>{x.textContent=s.value});const y=()=>M(e,t,n,s.value);return s.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),y())}),l.append(s,$(e,y,x)),s})}const et=e=>Number(e.toPrecision(15));function Pt(e=0){let t=String(e),n=null,a=null,r=!0,o=!1;const u=()=>{const i=Number(t);if(a===null||n===null)return;let l;a==="+"?l=n+i:a==="-"?l=n-i:a==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(et(l)):(o=!0,t="Error"),n=null,a=null};return{get display(){return t},get failed(){return o},press(i){if(i==="C"){t="0",n=null,a=null,r=!0,o=!1;return}o||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(et(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),o||(n=Number(t),a=i,r=!0)))}}}function Bt(e,t,n){const a=T(e,t,n),r=Pt(a??0);S(e,t,n,"Calculator",o=>{const u=f("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:C("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?C("Error"):r.display},l=()=>{i("="),r.failed||M(e,t,n,r.display)},s=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],x=f("div",{class:"ct-grid ct-keys"});let y=null;for(const[c,h]of s){const k=f("button",{class:`ct-key${h==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(h)});h==="7"&&(y=k),x.append(k)}return o.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),o.append(u,x,$(e,l)),y})}function Ut(e,t){const{book:n}=e,a=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),o=r.lastIndexOf("!"),u=o>=0?r.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=ft(o>=0?r.slice(o+1):r);if(!l&&o<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const s=[],x=Math.min(l.r1,i.maxRow,l.r0+j-1),y=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=x;c++){const h=[];let k=null;for(let m=l.c0;m<=y;m++){const D=i.kind(c,m)&V,b=n.styles.list[i.style(c,m)]??n.styles.list[0];h.push(e.grid.displayText(D,i.value(c,m),b)),m-l.c0===a&&(k=U(n,i,c,m))}h.some(m=>m!=="")&&s.push({cells:h,value:k})}return{head:t.columns??null,rows:s}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[a]??null}))}}function Ht(e,t,n,a){const{head:r,rows:o}=Ut(e,a),{book:u}=e,i=U(u,u.sheet,t,n);S(e,t,n,"List",l=>{if(o.length===0)return l.append(f("div",{text:C("No items"),class:"ct-item"})),l;let s=Math.max(0,o.findIndex(v=>i!==null&&String(v.value)===String(i)));const x=f("table",{class:"ct-table"});r&&x.append(f("thead",{},f("tr",{},...r.map((v,g)=>{const p=f("th",{text:v});return a.widths?.[g]>0&&(p.style.minWidth=`${a.widths[g]}px`),p}))));const y=f("tbody",{role:"listbox",ariaLabel:C("List"),tabIndex:0}),c=v=>M(e,t,n,vt(o[v].value)),h=o.map((v,g)=>{const p=f("tr",{role:"option",ariaSelected:String(g===s),onclick:()=>c(g)},...v.cells.map(d=>f("td",{text:d})));return y.append(p),p}),k=v=>{let g=Math.max(0,Math.min(o.length-1,v));const p=g<s?-1:1;for(;h[g].hidden&&g+p>=0&&g+p<o.length;)g+=p;h[g].hidden||(h[s].setAttribute("aria-selected","false"),s=g,h[s].setAttribute("aria-selected","true"),h[s].scrollIntoView({block:"nearest"}))};let m="",D=0;y.addEventListener("keydown",v=>{const p={ArrowUp:s-1,ArrowDown:s+1,PageUp:s-8,PageDown:s+8,Home:0,End:o.length-1}[v.key];if(p!==void 0)v.preventDefault(),k(p);else if(v.key==="Enter"||v.key===" ")v.preventDefault(),c(s);else if(v.key.length===1&&!v.metaKey&&!v.ctrlKey){const d=performance.now();m=d-D>800?v.key:m+v.key,D=d;const w=o.findIndex(A=>A.cells[0].toLowerCase().startsWith(m.toLowerCase()));w>=0&&k(w)}}),x.append(y);let b=null;return a.filter&&(b=f("input",{type:"text",placeholder:C("Filter"),ariaLabel:C("Filter the list")}),b.style.width="100%",b.style.boxSizing="border-box",b.style.marginBottom="4px",b.addEventListener("input",()=>{const v=b.value.trim().toLowerCase();o.forEach((p,d)=>{h[d].hidden=v!==""&&!p.cells.some(w=>String(w).toLowerCase().includes(v))});const g=h.findIndex(p=>!p.hidden);g>=0&&h[s].hidden&&k(g)}),b.addEventListener("keydown",v=>{v.key==="ArrowDown"?(v.preventDefault(),y.focus()):v.key==="Enter"&&(v.preventDefault(),h[s].hidden||c(s))}),l.append(b)),l.append(f("div",{class:"ct-list"},x)),requestAnimationFrame(()=>h[s]?.scrollIntoView({block:"nearest"})),b??y})}function re(e,t,n,{items:a,selected:r=[],multi:o=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:s=!1,float:x}){S(e,t,n,i,y=>{x!==void 0&&Et(x);const c=new Set(r);let h=Math.max(0,a.findIndex(p=>c.has(p.value)));const k=()=>{const p=a.filter(d=>c.has(d.value)).map(d=>d.value);u(p)!==!1&&L()},m=f("div",{class:"ct-list",role:"listbox",ariaLabel:C(i),ariaMultiselectable:String(o),tabIndex:0});l>0&&(m.style.maxHeight=`${l*24}px`);const D=[],b=a.map((p,d)=>{const w=f("span",{class:"ct-mark",text:c.has(p.value)?"✓":""});D.push(w);const A=f("div",{class:`ct-item${d===h?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(p.value)),onclick:()=>{v(d),g(),o||k()}},w,f("span",{text:p.text}));return m.append(A),A});function v(p){const d=Math.max(0,Math.min(a.length-1,p));b[h]?.classList.remove("ct-cursor"),h=d,b[h]?.classList.add("ct-cursor"),b[h]?.scrollIntoView({block:"nearest"})}function g(){const p=a[h];p&&(o||c.clear(),c.has(p.value)?c.delete(p.value):c.add(p.value),a.forEach((d,w)=>{D[w].textContent=c.has(d.value)?"✓":"",b[w].setAttribute("aria-selected",String(c.has(d.value)))}))}return m.addEventListener("keydown",p=>{const d={ArrowUp:h-1,ArrowDown:h+1,Home:0,End:a.length-1}[p.key];d!==void 0?(p.preventDefault(),v(d)):p.key===" "?(p.preventDefault(),g(),o||k()):p.key==="Enter"?(p.preventDefault(),o||(c.clear(),g()),k()):s&&!o&&(p.key==="ArrowLeft"||p.key==="ArrowRight")&&(p.preventDefault(),c.clear(),g(),k(),e.controller.moveTo(t,Math.max(0,n+(p.key==="ArrowLeft"?-1:1))))}),y.append(m),o&&y.append($(e,k)),a.length===0&&m.append(f("div",{class:"ct-item",text:C("No items")})),m})}const Wt={calendar:Mt,time:It,month:Rt,datetime:Tt,color:Nt,slider:Ot,calculator:Bt,list:Ht};function nt(e,t,n,a){K.get(a.type)?.open?.(e,t,n,a)!==!0&&Wt[a.type]?.(e,t,n,a)}function oe(e,t,n,a){return e.loading?!1:(H(e,t,n,{overFormula:!0})&&nt(e,t,n,a),!0)}function ae(e,t,n){const{sheet:a}=e.book,r=X(a,t,n);if(!r||e.loading)return!1;if(!H(e,t,n,{overFormula:!0}))return!0;const o=a.mergeAt(t,n);return nt(e,o?o.r0:t,o?o.c0:n,r),!0}export{W as DROPDOWN_TYPES,gt as MAX_APPLY_CELLS,_ as MONTHS,Jt as applyToRanges,Z as buildCalendar,H as canWriteCell,Zt as cellDropdownArrow,P as cellKey,T as cellSerial,wt as clipRange,L as closeDropdown,M as commit,X as dropdownAt,$ as footer,te as isDropdownOpen,Ut as listData,vt as literalInput,f as make,Pt as makeCalculator,Qt as makeDropdown,ae as openCellDropdown,oe as openDropdownConfig,re as openListPopup,S as openPopup,ne as popupViewChanged,U as readCellValue,Xt as registerDropdownKind,Et as setPopupFloat,ee as setPopupKeepOpen,G as swapMap,tt as timeInputs,O as todaySerial,kt as writeCell};
|
|
42
|
+
`;function Et(){if(document.getElementById(J))return;const e=document.createElement("style");e.id=J,e.textContent=Dt,document.head.append(e)}const f=(e,t={},...n)=>{const s=document.createElement(e);for(const[r,o]of Object.entries(t))r==="class"?s.className=o:r==="text"?s.textContent=o:r.startsWith("aria")||r==="role"?s.setAttribute(r==="role"?r:`aria-${r.slice(4).toLowerCase()}`,o):s[r]=o;return s.append(...n.filter(r=>r!=null)),s};let E=null;const ne=()=>E!==null;function re(e,t){E!==null&&(E.keepOpen=e,E.onClose=t)}function At(e){E!==null&&(E.mode=e?"float":"confine")}function oe(){E!==null&&E.mode!=="float"&&L(!1)}function L(e=!0){if(E===null)return;const{el:t,app:n,onDocPointer:s,onClose:r}=E;E=null,r?.(),document.removeEventListener("pointerdown",s,!0),t.remove(),e&&n.controller.focusGrid()}function S(e,t,n,s,r){L(!1),Et(),e.grid.ensureVisible(t,n);const o=f("div",{class:"ct-popup",role:"dialog",ariaLabel:w(s),tabIndex:-1}),u=l=>{!o.contains(l.target)&&!E?.keepOpen?.(l)&&L(!1)};E={el:o,app:e,onDocPointer:u},document.addEventListener("pointerdown",u,!0),o.addEventListener("keydown",l=>{if(l.stopPropagation(),l.key==="Escape")l.preventDefault(),L();else if(l.key==="Tab"){const a=[...o.querySelectorAll('button, input, [tabindex="0"]')].filter(x=>!x.disabled&&x.tabIndex>=0&&x.offsetParent!==null);if(a.length===0)return;const y=a.indexOf(document.activeElement);l.preventDefault(),a[(y+(l.shiftKey?-1:1)+a.length)%a.length].focus()}}),ot().append(o);const i=r(o);return Ft(e,t,n,o),(i??o).focus({preventScroll:!0}),o}function St(e,t,n){const r=e.bottom-(e.top+t.y+t.h)-2,o=t.y-2,u=n.getBoundingClientRect(),i=u.height<=r||r>=o,l=Math.max(60,i?r:o);if(u.height>l){n.style.maxHeight=`${l}px`,n.style.overflow="auto";const y=n.querySelector(".ct-list");y&&(y.style.maxHeight=`${Math.max(30,l-18)}px`)}const a=Math.min(u.height,l);n.style.top=`${i?e.top+t.y+t.h+2:e.top+t.y-2-a}px`,n.style.left=`${Math.max(e.left,Math.min(e.left+t.x,e.right-u.width))}px`}function Ft(e,t,n,s){const r=e.grid.host.getBoundingClientRect(),o=e.grid.domRect(e.grid.cellRect(t,n));if(E?.mode==="confine"){St(r,o,s);return}const u=s.getBoundingClientRect(),i=2,l=r.top+o.y+o.h+i,a=l+u.height<=window.innerHeight-8?l:Math.max(8,r.top+o.y-u.height-i);s.style.top=`${a}px`,s.style.left=`${Math.max(8,Math.min(r.left+o.x,window.innerWidth-u.width-8))}px`}function M(e,t,n,s,r){const o=wt(e,t,n,s,{...r,overFormula:!0});return o&&L(),o}const $=(e,t,n=null)=>f("div",{class:"ct-foot"},n,f("button",{class:"ct-btn",type:"button",text:w("Cancel"),onclick:()=>L()}),f("button",{class:"ct-btn ct-primary",type:"button",text:w("OK"),onclick:t})),_=["January","February","March","April","May","June","July","August","September","October","November","December"],Lt=["dow|Su","dow|Mo","dow|Tu","dow|We","dow|Th","dow|Fr","dow|Sa"],N=61;function O(){const e=new Date;return I(e.getFullYear(),e.getMonth()+1,e.getDate())}const Q=e=>{const t=Math.round(e/1e3);return{h:Math.floor(t/3600)%24,m:Math.floor(t/60)%60,s:t%60}};function T(e,t,n){const{book:s}=e,r=U(s,s.sheet,t,n);return typeof r=="number"&&r>=0?r:null}const Mt=(e,t)=>(t===12?I(e+1,1,1):I(e,t+1,1))-I(e,t,1);function Z(e,t,n,{min:s=N,max:r=1/0,marked:o=null}={}){const u=f("div"),i=Math.max(N,s),l=h=>Math.min(r,Math.max(i,h));let a=l(e);const y=e,x=O(),c=h=>{const k=R(a),m=I(k.year,k.month,1),D=m-R(m).weekday,b=d=>{const C=k.year*12+k.month-1+d,A=Math.floor(C/12),F=C%12+1;a=l(I(A,F,Math.min(k.day,Mt(A,F)))),c(h),n?.(a)},v=f("div",{class:"ct-grid ct-days",role:"grid",ariaLabel:`${w(_[k.month-1])} ${k.year}`});for(const d of Lt)v.append(f("div",{class:"ct-dow",text:w(d)}));let g=null;for(let d=0;d<42;d++){const C=D+d;if(C<N){v.append(f("div"));continue}const A=C<i||C>r,F=R(C),Y=C===a,z=f("button",{class:`ct-cell${F.month!==k.month||A?" ct-out":""}${C===x?" ct-today":""}${(o?o(C):Math.floor(y)===C)?" ct-on":""}`,disabled:A,type:"button",text:String(F.day),tabIndex:Y?0:-1,role:"gridcell",ariaLabel:`${F.year}-${String(F.month).padStart(2,"0")}-${String(F.day).padStart(2,"0")}`,onclick:()=>t(C)});Y&&(g=z),v.append(z)}v.addEventListener("keydown",d=>{const C={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7}[d.key];if(C!==void 0)d.preventDefault(),a=l(a+C),c(!0),n?.(a);else if(d.key==="PageUp"||d.key==="PageDown")d.preventDefault(),b((d.key==="PageUp"?-1:1)*(d.shiftKey?12:1));else if(d.key==="Home"||d.key==="End"){d.preventDefault();const A=R(a).weekday;a=l(a+(d.key==="Home"?-A:6-A)),c(!0),n?.(a)}else(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),t(a))});const p=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:w("Previous month"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:`${w(_[k.month-1])} ${k.year}`}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:w("Next month"),tabIndex:-1,onclick:()=>b(1)}));u.replaceChildren(p,v),u.focusCell=g,h&&g?.focus({preventScroll:!0})};return c(!1),u}function tt(e){const t=(i,l,a)=>f("input",{type:"number",min:0,max:l,value:String(a),ariaLabel:w(i),onfocus(){this.select()},onkeydown(y){if(y.key==="ArrowUp"||y.key==="ArrowDown"){y.preventDefault();const x=Number(this.value)+(y.key==="ArrowUp"?1:-1);this.value=String(x>l?0:x<0?l:x)}}}),n=t("Hours",23,e.h),s=t("Minutes",59,e.m),r=t("Seconds",59,e.s),o=f("div",{class:"ct-time"},n,f("span",{text:":"}),s,f("span",{text:":"}),r),u=(i,l)=>Math.max(0,Math.min(l,Math.trunc(Number(i.value))||0));return{wrap:o,first:n,read:()=>(u(n,23)*3600+u(s,59)*60+u(r,59))/86400}}function It(e,t,n,s){const r=T(e,t,n)??O();S(e,t,n,"Date picker",o=>{const u=a=>M(e,t,n,String(a),{format:s.format??B.calendar}),i=Z(Math.floor(r),u,void 0,{min:s.minDate,max:s.maxDate}),l=f("button",{class:"ct-btn",type:"button",text:w("Today"),onclick:()=>u(O())});return o.append(i,f("div",{class:"ct-foot"},l)),i.focusCell})}function Rt(e,t,n,s){const r=T(e,t,n),o=r===null?null:R(r).ms,u=new Date,i=o===null?{h:u.getHours(),m:u.getMinutes(),s:0}:Q(o);S(e,t,n,"Time picker",l=>{const a=tt(i),y=()=>M(e,t,n,String(a.read()),{format:s.format??B.time});return a.wrap.addEventListener("keydown",x=>{x.key==="Enter"&&(x.preventDefault(),y())}),l.append(a.wrap,$(e,y)),a.first})}function Tt(e,t,n,s){const r=T(e,t,n),o=R(r!==null&&r>=N?r:O()),u=s.startYear??1901,i=s.stopYear??9999;let l=Math.max(u,Math.min(i,o.year)),a=o.month-1;S(e,t,n,"Month picker",y=>{const x=k=>M(e,t,n,String(I(l,k+1,1)),{format:s.format??B.month}),c=f("div"),h=k=>{const m=f("div",{class:"ct-grid ct-months",role:"grid",ariaLabel:String(l)});let D=null;_.forEach((g,p)=>{const d=f("button",{class:`ct-cell${l===o.year&&p===o.month-1&&r!==null?" ct-on":""}`,type:"button",text:w(g).slice(0,3),ariaLabel:`${w(g)} ${l}`,tabIndex:p===a?0:-1,onclick:()=>x(p)});p===a&&(D=d),m.append(d)});const b=g=>{l=Math.max(u,Math.min(i,l+g)),h(!0)};m.addEventListener("keydown",g=>{const p={ArrowLeft:-1,ArrowRight:1,ArrowUp:-3,ArrowDown:3}[g.key];if(p!==void 0){g.preventDefault();const d=a+p;d<0?(a=d+12,b(-1)):d>11?(a=d-12,b(1)):(a=d,h(!0))}else g.key==="PageUp"||g.key==="PageDown"?(g.preventDefault(),b(g.key==="PageUp"?-1:1)):(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),x(a))});const v=f("div",{class:"ct-row"},f("button",{class:"ct-nav",type:"button",text:"‹",ariaLabel:w("Previous year"),tabIndex:-1,onclick:()=>b(-1)}),f("div",{class:"ct-head",text:String(l)}),f("button",{class:"ct-nav",type:"button",text:"›",ariaLabel:w("Next year"),tabIndex:-1,onclick:()=>b(1)}));c.replaceChildren(v,m),c.focusCell=D,k&&D?.focus({preventScroll:!0})};return h(!1),y.append(c),c.focusCell})}function $t(e,t,n,s){const r=T(e,t,n),o=new Date,u=r!==null&&r>=N?Math.floor(r):O(),i=r!==null?Q(R(r).ms):{h:o.getHours(),m:o.getMinutes(),s:0};S(e,t,n,"Date and time picker",l=>{let a=u;const y=tt(i),x=()=>M(e,t,n,String(a+y.read()),{format:s.format??B.datetime}),c=Z(a,h=>{a=h,y.first.focus()},h=>{a=h},{min:s.minDate,max:s.maxDate});return y.wrap.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),x())}),y.wrap.style.marginTop="8px",l.append(c,y.wrap,$(e,x)),c.focusCell})}const Nt=["#000000","#434343","#666666","#999999","#B7B7B7","#CCCCCC","#D9D9D9","#EFEFEF","#F3F3F3","#FFFFFF","#980000","#FF0000","#FF9900","#FFFF00","#00FF00","#00FFFF","#4A86E8","#0000FF","#9900FF","#FF00FF","#E6B8AF","#F4CCCC","#FCE5CD","#FFF2CC","#D9EAD3","#D0E0E3","#C9DAF8","#CFE2F3","#D9D2E9","#EAD1DC","#DD7E6B","#EA9999","#F9CB9C","#FFE599","#B6D7A8","#A2C4C9","#A4C2F4","#9FC5E8","#B4A7D6","#D5A6BD","#A61C00","#CC0000","#E69138","#F1C232","#6AA84F","#45818E","#3C78D8","#3D85C6","#674EA7","#A64D79","#5B0F00","#660000","#783F04","#7F6000","#274E13","#0C343D","#1C4587","#073763","#20124D","#4C1130"];function Ot(e,t,n,s){const r=s.palette??Nt,{book:o}=e,u=U(o,o.sheet,t,n),i=typeof u=="string"&&/^#[0-9a-f]{6}$/i.test(u)?u.toUpperCase():null;S(e,t,n,"Color picker",l=>{let a=Math.max(0,r.indexOf(i));const y=m=>{if(s.target===void 0){M(e,t,n,m);return}H(e,t,n,{overFormula:!0})&&(o.applyStyle([{r0:t,c0:n,r1:t,c1:n}],s.target==="fill"?{fill:m}:{color:m}),e.grid.invalidate(),L())},x=f("div",{class:"ct-grid ct-swatches",role:"grid",ariaLabel:w("Colors")}),c=r.map((m,D)=>{const b=f("button",{class:`ct-swatch${m===i?" ct-on":""}`,type:"button",ariaLabel:m,title:m,tabIndex:D===a?0:-1,onclick:()=>y(m)});return b.style.background=m,x.append(b),b});x.addEventListener("keydown",m=>{const D={ArrowLeft:-1,ArrowRight:1,ArrowUp:-10,ArrowDown:10}[m.key];if(D!==void 0){m.preventDefault();const b=a+D;b>=0&&b<r.length&&(c[a].tabIndex=-1,a=b,c[a].tabIndex=0,c[a].focus())}else(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),y(r[a]))});const h=f("input",{type:"text",value:i??"",placeholder:"#RRGGBB",maxLength:7,size:8,ariaLabel:w("Hex color")}),k=()=>{const m=h.value.trim(),D=/^#?[0-9a-f]{6}$/i.test(m)?`#${m.replace("#","").toUpperCase()}`:null;D?y(D):h.select()};return h.addEventListener("keydown",m=>{m.key==="Enter"&&(m.preventDefault(),k())}),l.append(x,f("div",{class:"ct-foot"},h,f("button",{class:"ct-btn",type:"button",text:w("Apply"),onclick:k}))),c[a]})}function Pt(e,t,n,s){const r=s.min??0,o=s.max??100,u=s.step??1,i=T(e,t,n);S(e,t,n,"Slider",l=>{const a=f("input",{type:"range",min:r,max:o,step:u,value:String(i??r),ariaLabel:w("Value")}),y=f("span",{class:"ct-value",text:a.value});a.addEventListener("input",()=>{y.textContent=a.value});const x=()=>M(e,t,n,a.value);return a.addEventListener("keydown",c=>{c.key==="Enter"&&(c.preventDefault(),x())}),l.append(a,$(e,x,y)),a})}const et=e=>Number(e.toPrecision(15));function Bt(e=0){let t=String(e),n=null,s=null,r=!0,o=!1;const u=()=>{const i=Number(t);if(s===null||n===null)return;let l;s==="+"?l=n+i:s==="-"?l=n-i:s==="*"?l=n*i:l=n/i,Number.isFinite(l)?t=String(et(l)):(o=!0,t="Error"),n=null,s=null};return{get display(){return t},get failed(){return o},press(i){if(i==="C"){t="0",n=null,s=null,r=!0,o=!1;return}o||(/^\d$/.test(i)?(t=r||t==="0"?i:t+i,r=!1):i==="."?(r?t="0.":t.includes(".")||(t+="."),r=!1):i==="back"?r||(t=t.length>1?t.slice(0,-1):"0"):i==="neg"?t=t.startsWith("-")?t.slice(1):t==="0"?t:`-${t}`:i==="%"?(t=String(et(Number(t)/100)),r=!0):i==="="?(u(),r=!0):"+-*/".includes(i)&&((!r||n===null)&&u(),o||(n=Number(t),s=i,r=!0)))}}}function Ut(e,t,n){const s=T(e,t,n),r=Bt(s??0);S(e,t,n,"Calculator",o=>{const u=f("input",{class:"ct-display",type:"text",readOnly:!0,value:r.display,ariaLabel:w("Result"),tabIndex:-1}),i=c=>{r.press(c),u.value=r.failed?w("Error"):r.display},l=()=>{i("="),r.failed||M(e,t,n,r.display)},a=[["C","C"],["±","neg"],["%","%"],["÷","/"],["7","7"],["8","8"],["9","9"],["×","*"],["4","4"],["5","5"],["6","6"],["−","-"],["1","1"],["2","2"],["3","3"],["+","+"],["0","0"],[".","."],["=","="]],y=f("div",{class:"ct-grid ct-keys"});let x=null;for(const[c,h]of a){const k=f("button",{class:`ct-key${h==="0"?" ct-wide":""}`,type:"button",text:c,ariaLabel:c,onclick:()=>i(h)});h==="7"&&(x=k),y.append(k)}return o.addEventListener("keydown",c=>{c.target.tagName==="BUTTON"&&(c.key===" "||c.key==="Enter")&&c.target.closest(".ct-foot")||c.target.tagName==="BUTTON"&&c.key===" "||(c.key==="Enter"?(c.preventDefault(),l()):c.key==="Backspace"?(c.preventDefault(),i("back")):c.key==="c"||c.key==="C"||c.key==="Delete"?(c.preventDefault(),i("C")):/^[\d.+\-*/%=]$/.test(c.key)&&(c.preventDefault(),i(c.key)))}),o.append(u,y,$(e,l)),x})}function Ht(e,t){const{book:n}=e,s=t.valueColumn??0;if(t.source){const r=t.source.replace(/^=/,""),o=r.lastIndexOf("!"),u=o>=0?r.slice(0,o).replace(/^'|'$/g,"").replace(/''/g,"'"):null;let i=u===null?n.sheet:n.sheets.find(c=>c.name.toLowerCase()===u.toLowerCase()),l=mt(o>=0?r.slice(o+1):r);if(!l&&o<0){const c=n.engine?.tables.get(r.toUpperCase());c&&(i=c.sheet,l={r0:c.r0+(c.headerRows??1),c0:c.c0,r1:c.r1,c1:c.c1})}if(!i||!l)return{head:t.columns??null,rows:[]};const a=[],y=Math.min(l.r1,i.maxRow,l.r0+j-1),x=Math.min(l.c1,i.maxCol,l.c0+49);for(let c=l.r0;c<=y;c++){const h=[];let k=null;for(let m=l.c0;m<=x;m++){const D=i.kind(c,m)&V,b=n.styles.list[i.style(c,m)]??n.styles.list[0];h.push(e.grid.displayText(D,i.value(c,m),b)),m-l.c0===s&&(k=U(n,i,c,m))}h.some(m=>m!=="")&&a.push({cells:h,value:k})}return{head:t.columns??null,rows:a}}return{head:t.columns??null,rows:(t.rows??[]).map(r=>({cells:r.map(String),value:r[s]??null}))}}function Wt(e,t,n,s){const{head:r,rows:o}=Ht(e,s),{book:u}=e,i=U(u,u.sheet,t,n);S(e,t,n,"List",l=>{if(o.length===0)return l.append(f("div",{text:w("No items"),class:"ct-item"})),l;let a=Math.max(0,o.findIndex(v=>i!==null&&String(v.value)===String(i)));const y=f("table",{class:"ct-table"});r&&y.append(f("thead",{},f("tr",{},...r.map((v,g)=>{const p=f("th",{text:v});return s.widths?.[g]>0&&(p.style.minWidth=`${s.widths[g]}px`),p}))));const x=f("tbody",{role:"listbox",ariaLabel:w("List"),tabIndex:0}),c=v=>M(e,t,n,bt(o[v].value)),h=o.map((v,g)=>{const p=f("tr",{role:"option",ariaSelected:String(g===a),onclick:()=>c(g)},...v.cells.map(d=>f("td",{text:d})));return x.append(p),p}),k=v=>{let g=Math.max(0,Math.min(o.length-1,v));const p=g<a?-1:1;for(;h[g].hidden&&g+p>=0&&g+p<o.length;)g+=p;h[g].hidden||(h[a].setAttribute("aria-selected","false"),a=g,h[a].setAttribute("aria-selected","true"),h[a].scrollIntoView({block:"nearest"}))};let m="",D=0;x.addEventListener("keydown",v=>{const p={ArrowUp:a-1,ArrowDown:a+1,PageUp:a-8,PageDown:a+8,Home:0,End:o.length-1}[v.key];if(p!==void 0)v.preventDefault(),k(p);else if(v.key==="Enter"||v.key===" ")v.preventDefault(),c(a);else if(v.key.length===1&&!v.metaKey&&!v.ctrlKey){const d=performance.now();m=d-D>800?v.key:m+v.key,D=d;const C=o.findIndex(A=>A.cells[0].toLowerCase().startsWith(m.toLowerCase()));C>=0&&k(C)}}),y.append(x);let b=null;return s.filter&&(b=f("input",{type:"text",placeholder:w("Filter"),ariaLabel:w("Filter the list")}),b.style.width="100%",b.style.boxSizing="border-box",b.style.marginBottom="4px",b.addEventListener("input",()=>{const v=b.value.trim().toLowerCase();o.forEach((p,d)=>{h[d].hidden=v!==""&&!p.cells.some(C=>String(C).toLowerCase().includes(v))});const g=h.findIndex(p=>!p.hidden);g>=0&&h[a].hidden&&k(g)}),b.addEventListener("keydown",v=>{v.key==="ArrowDown"?(v.preventDefault(),x.focus()):v.key==="Enter"&&(v.preventDefault(),h[a].hidden||c(a))}),l.append(b)),l.append(f("div",{class:"ct-list"},y)),requestAnimationFrame(()=>h[a]?.scrollIntoView({block:"nearest"})),b??x})}function se(e,t,n,{items:s,selected:r=[],multi:o=!1,onDone:u,label:i="List",maxItems:l=0,moveOnSide:a=!1,float:y}){S(e,t,n,i,x=>{y!==void 0&&At(y);const c=new Set(r);let h=Math.max(0,s.findIndex(p=>c.has(p.value)));const k=()=>{const p=s.filter(d=>c.has(d.value)).map(d=>d.value);u(p)!==!1&&L()},m=f("div",{class:"ct-list",role:"listbox",ariaLabel:w(i),ariaMultiselectable:String(o),tabIndex:0});l>0&&(m.style.maxHeight=`${l*24}px`);const D=[],b=s.map((p,d)=>{const C=f("span",{class:"ct-mark",text:c.has(p.value)?"✓":""});D.push(C);const A=f("div",{class:`ct-item${d===h?" ct-cursor":""}`,role:"option",ariaSelected:String(c.has(p.value)),onclick:()=>{v(d),g(),o||k()}},C,f("span",{text:p.text}));return m.append(A),A});function v(p){const d=Math.max(0,Math.min(s.length-1,p));b[h]?.classList.remove("ct-cursor"),h=d,b[h]?.classList.add("ct-cursor"),b[h]?.scrollIntoView({block:"nearest"})}function g(){const p=s[h];p&&(o||c.clear(),c.has(p.value)?c.delete(p.value):c.add(p.value),s.forEach((d,C)=>{D[C].textContent=c.has(d.value)?"✓":"",b[C].setAttribute("aria-selected",String(c.has(d.value)))}))}return m.addEventListener("keydown",p=>{const d={ArrowUp:h-1,ArrowDown:h+1,Home:0,End:s.length-1}[p.key];d!==void 0?(p.preventDefault(),v(d)):p.key===" "?(p.preventDefault(),g(),o||k()):p.key==="Enter"?(p.preventDefault(),o||(c.clear(),g()),k()):a&&!o&&(p.key==="ArrowLeft"||p.key==="ArrowRight")&&(p.preventDefault(),c.clear(),g(),k(),e.controller.moveTo(t,Math.max(0,n+(p.key==="ArrowLeft"?-1:1))))}),x.append(m),o&&x.append($(e,k)),s.length===0&&m.append(f("div",{class:"ct-item",text:w("No items")})),m})}const Kt={calendar:It,time:Rt,month:Tt,datetime:$t,color:Ot,slider:Pt,calculator:Ut,list:Wt};function nt(e,t,n,s){K.get(s.type)?.open?.(e,t,n,s)!==!0&&Kt[s.type]?.(e,t,n,s)}function ae(e,t,n,s){return e.loading?!1:(H(e,t,n,{overFormula:!0})&&nt(e,t,n,s),!0)}function le(e,t,n){const{sheet:s}=e.book,r=X(s,t,n);if(!r||e.loading)return!1;if(!H(e,t,n,{overFormula:!0}))return!0;const o=s.mergeAt(t,n);return nt(e,o?o.r0:t,o?o.c0:n,r),!0}export{W as DROPDOWN_TYPES,vt as MAX_APPLY_CELLS,_ as MONTHS,Zt as applyToRanges,Z as buildCalendar,H as canWriteCell,ee as cellDropdownArrow,P as cellKey,T as cellSerial,Ct as clipRange,L as closeDropdown,M as commit,X as dropdownAt,$ as footer,ne as isDropdownOpen,Ht as listData,bt as literalInput,f as make,Bt as makeCalculator,te as makeDropdown,le as openCellDropdown,ae as openDropdownConfig,se as openListPopup,S as openPopup,oe as popupViewChanged,U as readCellValue,Qt as registerDropdownKind,At as setPopupFloat,re as setPopupKeepOpen,G as swapMap,tt as timeInputs,O as todaySerial,wt as writeCell};
|
package/core/autofill.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EMPTY as
|
|
1
|
+
import{EMPTY as S,FORMULA as M,KIND_MASK as w,NUM as y,STR as $}from"./sheet.js";import{culture as O}from"./culture.js";import{partsToSerial as v,serialToParts as L}from"./numfmt.js";const T=[["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],["January","February","March","April","May","June","July","August","September","October","November","December"],["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]],z=[["Poniedziałek","Wtorek","Środa","Czwartek","Piątek","Sobota","Niedziela"],["Pon","Wt","Śr","Czw","Pt","Sob","Niedz"],["Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień"],["Sty","Lut","Mar","Kwi","Maj","Cze","Lip","Sie","Wrz","Paź","Lis","Gru"]],_=[...T,...z],F=[...z,...T];function B(t,e){return t===t.toUpperCase()?e.toUpperCase():t===t.toLowerCase()?e.toLowerCase():e}const C=t=>/[ymd]/i.test(t.replace(/"[^"]*"|\[[^\]]*\]/g,""))&&!/^general$/i.test(t);function A(t,e){const n=t.toLowerCase(),f=O().language==="pl"?F:_;for(const l of f){const r=l.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:l,i:r}}if(e)for(const l of e){const r=l.findIndex(i=>i.toLowerCase()===n);if(r>=0)return{list:l,i:r}}return null}const b=(t,e)=>(e===12?v(t+1,1,1):v(t,e+1,1))-v(t,e,1);function x(t,e){const n=t.year*12+t.month-1+e,f=Math.floor(n/12),l=n-f*12+1;return v(f,l,Math.min(t.day,b(f,l)))}const D=t=>{const e=t%100;return e>=11&&e<=13?"th":["th","st","nd","rd"][t%10]??"th"},I=/^(?:q|qtr|quarter)\.?\s*$/i;function N(t){const e=/^(.*?)(\d+)(st|nd|rd|th)(.*)$/i.exec(t);if(e&&!/\d/.test(e[4])){const[,o,s,u,c]=e,p=Number(s),g=o===""&&I.test(c.trim())&&p>=1&&p<=4;return{pre:o,num:p,width:s.length,ord:!0,upper:u===u.toUpperCase(),rest:c,wrap:g,key:`${o}\0ord\0${c}`}}const n=/^(\d+)( .*)$/s.exec(t);if(n)return{pre:"",num:Number(n[1]),width:n[1].length,ord:!1,rest:n[2],wrap:!1,key:`\0lead\0${n[2]}`};const f=/^(.*?)(\d+)$/s.exec(t);if(!f)return null;const[,l,r]=f,i=Number(r),a=I.test(l)&&i>=1&&i<=4;return{pre:l,num:i,width:r.length,ord:!1,rest:"",wrap:a,key:`${l}\0`}}function E(t,e){const n=t.wrap?((e-1)%4+4)%4+1:Math.abs(e),f=String(n).padStart(t.width,"0");if(!t.ord)return`${t.pre}${f}${t.rest}`;const l=D(n);return`${t.pre}${f}${t.upper?l.toUpperCase():l}${t.rest}`}function J(t,e={}){const n=t.length,f=e.direction??1;if(n===0||t.some(r=>r.kind&M))return()=>null;const l=t.map(r=>r.kind&w);if(l.every(r=>r===y)){const r=C(t[0].format??"General");if(n===1){if(!r&&e.alone&&!e.force)return()=>null;const d=r&&W(t[0].format)?1/24:1;return h=>({kind:y,value:t[0].value+f*d*(h+1)})}const i=t[1].value-t[0].value;let a=!0;for(let d=2;d<n;d++)Math.abs(t[d].value-t[d-1].value-i)>1e-9&&(a=!1);if(r){const d=t.map(m=>L(m.value)),h=(d[1].year-d[0].year)*12+d[1].month-d[0].month,P=m=>m.day===d[0].day||m.day<d[0].day&&m.day===b(m.year,m.month);if(d.every(P)&&h!==0)return m=>({kind:y,value:x(d[0],h*(n+m))})}if(a)return d=>({kind:y,value:t[n-1].value+i*(d+1)});const o=t.map((d,h)=>h),s=o.reduce((d,h)=>d+h,0)/n,u=t.reduce((d,h)=>d+h.value,0)/n;let c=0,p=0;for(let d=0;d<n;d++)c+=(o[d]-s)*(t[d].value-u),p+=(o[d]-s)**2;const g=c/p,k=u-g*s;return d=>({kind:y,value:k+g*(n+d)})}if(l.every(r=>r===$)){const r=t.map(a=>A(a.text,e.lists));if(r.every(Boolean)&&r.every(a=>a.list===r[0].list)){const{list:a}=r[0],o=n>=2&&(r[1].i-r[0].i+a.length)%a.length||f;return s=>{const u=(r[n-1].i+o*(s+1))%a.length;return{text:B(t[0].text,a[u<0?u+a.length:u])}}}const i=t.map(a=>N(a.text));if(i.every(Boolean)&&i.every(a=>a.key===i[0].key)){const a=i.map(u=>u.num),o=n>=2?a[1]-a[0]:f;let s=!0;for(let u=2;u<n;u++)a[u]-a[u-1]!==o&&(s=!1);if(s&&o!==0)return u=>({text:E(i[0],a[n-1]+o*(u+1))})}}return()=>null}function W(t){const e=String(t??"").replace(/"[^"]*"|\[[^\]]*\]|\\./g,"");return!/[dy]/i.test(e)&&/[hs]/i.test(e)}function U(t,e){const n=t.kind&w;if(t.kind&M||n===S)return null;if(n===y)return C(t.format??"General")?"date":"number";if(n!==$)return null;const f=A(t.text,e);if(f)return f.list;const l=N(t.text);return l?`text:${l.key}`:null}function q(t,e={}){const n=[],f=new Int32Array(t.length).fill(-1),l=new Int32Array(t.length),r=a=>(a.kind&w)===S&&!(a.kind&M);let i=!1;for(let a=0;a<t.length;){const o=U(t[a],e.lists);if(o===null){a++;continue}const s=[a];for(let c=a+1;c<t.length;c++)if(!r(t[c])){if(U(t[c],e.lists)!==o)break;s.push(c)}const u=J(s.map(c=>t[c]),{...e,alone:t.length===1});u(0)!==null&&(i=!0),s.forEach((c,p)=>{f[c]=n.length,l[c]=p}),n.push({n:s.length,series:u}),a=s[s.length-1]+1}return{active:i,at(a,o){const s=f[a];if(s<0)return null;const u=n[s];return u.series(o*u.n+l[a])}}}function H(t,e,n=1){const f=t.length,l=t[f-1].value;if(e==="days"){const o=f>=2?t[1].value-t[0].value:n;return(s,u)=>({kind:y,value:l+o*(u*f+s+1)})}if(e==="weekdays")return f>1?(o,s)=>({kind:y,value:t[o].value+n*7*(s+1)}):(o,s)=>({kind:y,value:G(l,"weekday",n,s+1)});const r=n*(e==="months"?1:12),i=L(t[0].value),a=v(i.year,i.month,1);return(o,s)=>{const u=t[o].value,c=Math.floor(u)-a+1,p=i.year*12+i.month-1+r*(s+1),g=Math.floor(p/12),k=p-g*12+1,d=v(g,k,1),h=c>=1&&c<=31?d+Math.min(c,b(g,k))-1:d+c-1;return{kind:y,value:h+(u-Math.floor(u))}}}function G(t,e,n,f){if(e==="day")return t+n*f;const l=L(t),r=t-Math.floor(t);if(e==="month")return x(l,n*f)+r;if(e==="year")return x(l,12*n*f)+r;let i=t;const a=n*f<0?-1:1;for(let o=Math.abs(n*f);o>0;){i+=a;const s=Math.floor(i)%7;s!==0&&s!==1&&o--}return i}function Y(t){const e=[],n=t[0];n.source.forEach((r,i)=>{r.split(/[\s,;._-]+/).filter(Boolean).forEach((o,s)=>{for(const u of[c=>c,c=>c.toUpperCase(),c=>c.toLowerCase(),c=>c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()])e.push(c=>u((c[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??""));e.push(u=>((u[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??"").charAt(0)),e.push(u=>((u[i]??"").split(/[\s,;._-]+/).filter(Boolean)[s]??"").charAt(0).toUpperCase())}),e.push(o=>(o[i]??"").toUpperCase()),e.push(o=>(o[i]??"").toLowerCase()),e.push(o=>(o[i]??"").replace(/\S+/g,s=>s.charAt(0).toUpperCase()+s.slice(1).toLowerCase())),e.push(o=>(o[i]??"").replace(/\D/g,"")),e.push(o=>(o[i]??"").replace(/[^\p{L}]/gu,""));for(let o=1;o<=Math.min(r.length,12);o++)e.push(s=>(s[i]??"").slice(0,o)),e.push(s=>(s[i]??"").slice(-o))});const f=e.slice(),l=n.target;for(let r=1;r<l.length;r++){const i=l.slice(0,r);for(const a of f)if(a(n.source)===i)for(const o of[0,1,2,3]){const s=l.slice(r,r+o),u=l.slice(r+o);if(!/[\p{L}\d]/u.test(s))for(const c of f)c(n.source)===u&&e.push(p=>`${a(p)}${s}${c(p)}`)}}return e.find(r=>t.every(i=>r(i.source)===i.target))??null}export{_ as BUILTIN_LISTS,S as EMPTY,G as dateStep,Y as flashFillRule,C as isDateFormat,H as makeDatePlan,q as makeFillPlan,J as makeSeries};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MAX_COLS as y}from"./address.js";class u extends Map{constructor(o,t){super(),this.groups=new Map;for(let s=0;s<y;s++){const l=o?.get(s),r=t?t(l??0):l;r!==void 0&&super.set(s,r),this.group(r??0).add(s)}}group(o){return this.groups.has(o)||this.groups.set(o,new Set),this.groups.get(o)}move(o,t){const s=this.get(o)??0;if(t===s)return;const l=this.groups.get(s);l.delete(o),l.size||this.groups.delete(s),this.group(t).add(o)}set(o,t){return this.move(o,t),super.set(o,t)}delete(o){return this.move(o,0),super.delete(o)}clear(){for(const o of this.keys())this.delete(o)}commonStyle(){let o=0,t=0;for(const[s,l]of this.groups)l.size<=t||(o=s,t=l.size);return o}*exceptions(o){for(const[t,s]of this.groups)t!==o&&(yield*s)}}function C(e,o,t){const s=e.colStyles;t.push(["columns",0,s]),e.colStyles=new u(s,o),e.colsChanged=!0}function M(e,o,t,s,l,r,h=!1){const f=o==="col",g=f?e.colStyles??=new Map:e.rowStyles??=new Map,p=g.get(t);let n=e.colStyles;const m=!f&&p===void 0&&!h;m&&n?.size>y/2&&!(n instanceof u)&&(l.push(["columns",0,n]),e.colStyles=n=new u(n));const S=m&&n instanceof u?n.commonStyle():0,a=s(p??S);if(f){e.colsChanged=!0;for(const[c,i]of e.rowStyles??[]){const d=s(i);d!==i&&!e.cellStyle(c,t)&&r(c,t,d)}}else if(m&&n)for(const c of n instanceof u?n.exceptions(S):n.keys()){const i=s(n.get(c)??0);i!==a&&!e.cellStyle(t,c)&&r(t,c,i)}l.push([o,t,p]),g.set(t,a)}export{M as formatAxis,C as formatSheetColumns};
|
package/core/axis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o=65535;class u{constructor(t,i){this.count=t,this.defaultSize=i,this.sizes=null,this.tree=null,this.hiddenSizes=null,this.autoFlags=null,this.topBit=1<<31-Math.clz32(t),this.delta=0,this.watcher=null,this.version=0}setDefaultSize(t){if(this.tree)throw new Error("Default size must be set before custom sizes");this.defaultSize=t,this.version++}changeDefaultSize(t){if(t!==this.defaultSize){if(this.defaultSize=t,this.version++,this.sizes!==null){this.tree.fill(0);let i=0;for(let s=0;s<this.count;s++){const
|
|
1
|
+
const o=65535;class u{constructor(t,i){this.count=t,this.defaultSize=i,this.sizes=null,this.tree=null,this.hiddenSizes=null,this.autoFlags=null,this.topBit=1<<31-Math.clz32(t),this.delta=0,this.watcher=null,this.version=0}setDefaultSize(t){if(this.tree)throw new Error("Default size must be set before custom sizes");this.defaultSize=t,this.version++}changeDefaultSize(t){if(t!==this.defaultSize){if(this.defaultSize=t,this.version++,this.sizes!==null){this.tree.fill(0);let i=0;for(let s=0;s<this.count;s++){const h=this.sizes[s];h!==65535&&(i+=h-t,this.tree[s+1]+=h-t)}for(let s=1;s<=this.count;s++){const h=s+(s&-s);h<=this.count&&(this.tree[h]+=this.tree[s])}this.delta=i}this.watcher?.axisResized()}}get total(){return this.count*this.defaultSize+this.delta}sizeOf(t){if(this.sizes===null)return this.defaultSize;const i=this.sizes[t];return i===65535||i===void 0?this.defaultSize:i}isCustom(t){return this.sizes!==null&&t<this.count&&this.sizes[t]!==65535}isHidden(t){return this.hiddenSizes!==null&&this.hiddenSizes.has(t)}isAuto(t){return this.autoFlags!==null&&this.autoFlags[t]===1}setSize(t,i,s=!1){s&&this.autoFlags===null&&(this.autoFlags=new Uint8Array(this.count)),this.autoFlags!==null&&(this.autoFlags[t]=s?1:0);const h=i===null;i=h?this.defaultSize:Math.max(0,Math.min(65534,Math.round(i))),this.sizes===null&&(this.sizes=new Uint16Array(this.count).fill(65535),this.tree=new Int32Array(this.count+1));const n=this.sizeOf(t);this.sizes[t]=h?65535:i;const e=i-n;if(e!==0){this.version++,this.delta+=e;for(let l=t+1;l<=this.count;l+=l&-l)this.tree[l]+=e;this.watcher?.axisResized()}}setHidden(t,i){if(i){if(this.isHidden(t))return;this.hiddenSizes===null&&(this.hiddenSizes=new Map),this.hiddenSizes.set(t,this.isCustom(t)?this.sizeOf(t):-1),this.setSize(t,0),this.watcher?.axisHiddenChanged()}else if(this.isHidden(t)){const s=this.hiddenSizes.get(t);this.hiddenSizes.delete(t),this.setSize(t,s<=0?this.defaultSize:s),this.watcher?.axisHiddenChanged()}}offsetOf(t){let i=t*this.defaultSize;if(this.tree!==null)for(let s=Math.min(t,this.count);s>0;s-=s&-s)i+=this.tree[s];return i}indexAt(t){if(t<=0&&this.tree===null)return 0;if(this.tree===null){const n=Math.floor(t/this.defaultSize);return n>=this.count?this.count-1:n}let i=0,s=t;const h=this.defaultSize;for(let n=this.topBit;n>0;n>>=1){const e=i+n;if(e<=this.count){const l=n*h+this.tree[e];l<=s&&(i=e,s-=l)}}return i>=this.count?this.count-1:i}reshaped(t=this.count,i=this.defaultSize){const s=new u(t,i);if(this.sizes!==null){const h=Math.min(t,this.count);for(let n=0;n<h;n++)this.sizes[n]!==65535&&s.setSize(n,this.sizes[n],this.isAuto(n))}if(this.hiddenSizes!==null)for(const[h,n]of this.hiddenSizes)h<t&&(s.hiddenSizes??=new Map,s.hiddenSizes.set(h,n));return s}shifted(t,i){const s=new u(this.count,this.defaultSize);if(this.sizes===null)return s;const h=new Uint16Array(this.count).fill(65535);i>0?(h.set(this.sizes.subarray(0,t)),h.set(this.sizes.subarray(t,this.count-i),t+i)):(h.set(this.sizes.subarray(0,t)),h.set(this.sizes.subarray(t-i),t)),s.sizes=h,s.tree=new Int32Array(this.count+1);let n=0;for(let e=0;e<this.count;e++){const l=h[e];if(l===65535)continue;const r=l-this.defaultSize;n+=r,s.tree[e+1]+=r}for(let e=1;e<=this.count;e++){const l=e+(e&-e);l<=this.count&&(s.tree[l]+=s.tree[e])}if(s.delta=n,this.hiddenSizes!==null){s.hiddenSizes=new Map;for(const[e,l]of this.hiddenSizes)e<t?s.hiddenSizes.set(e,l):(i>0||e>=t-i)&&s.hiddenSizes.set(e+i,l)}if(this.autoFlags!==null){const e=new Uint8Array(this.count);i>0?(e.set(this.autoFlags.subarray(0,t)),e.set(this.autoFlags.subarray(t,this.count-i),t+i)):(e.set(this.autoFlags.subarray(0,t)),e.set(this.autoFlags.subarray(t-i),t)),s.autoFlags=e}return s}*customEntries(){if(this.sizes!==null)for(let t=0;t<this.count;t++)this.sizes[t]!==65535&&(yield t)}}export{u as Axis};
|
package/core/culture.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setNumberLocale as F}from"./numfmt.js";import{setEntryCurrency as L}from"./input.js";import{regionInput as Z}from"./region-input.js";import{arraySeparatorsOf as b}from"../calcx/culture/separators.js";import{customCulture as v}from"../calcx/culture/custom.js";import{localeData as K,preparedEras as G}from"../calcx/culture/format-locale.js";import{formulaFromUser as k,formulaToUser as M}from"../calcx/lang/convert.js";import{setDbcsLanguage as O}from"../calc/functions/dbcs.js";const W={US:"USD",GB:"GBP",PL:"PLN",DE:"EUR",FR:"EUR",ES:"EUR",IT:"EUR",NL:"EUR",AT:"EUR",BE:"EUR",IE:"EUR",PT:"EUR",FI:"EUR",GR:"EUR",CZ:"CZK",SK:"EUR",HU:"HUF",RO:"RON",SE:"SEK",NO:"NOK",DK:"DKK",CH:"CHF",UA:"UAH",TR:"TRY",JP:"JPY",CN:"CNY",KR:"KRW",IN:"INR",BR:"BRL",MX:"MXN",CA:"CAD",AU:"AUD",NZ:"NZD",ZA:"ZAR",IL:"ILS",SA:"SAR",AE:"AED",EG:"EGP"},q=[["en-US","English (United States)"],["en-GB","English (United Kingdom)"],["pl-PL","Polish (Poland)"],["de-DE","German (Germany)"],["fr-FR","French (France)"],["es-ES","Spanish (Spain)"],["it-IT","Italian (Italy)"],["nl-NL","Dutch (Netherlands)"],["pt-BR","Portuguese (Brazil)"],["cs-CZ","Czech (Czechia)"],["sv-SE","Swedish (Sweden)"],["uk-UA","Ukrainian (Ukraine)"],["tr-TR","Turkish (Türkiye)"],["ja-JP","Japanese (Japan)"],["zh-CN","Chinese (China)"],["ko-KR","Korean (Korea)"],["ar-SA","Arabic (Saudi Arabia)"],["he-IL","Hebrew (Israel)"]];function u(t){const o=v(t);if(o){const e=u(o.parent);return{...e,monthsWithDay:o.fields.months??e.monthsWithDay,...o.fields,tag:t}}const s=new Intl.NumberFormat(t,{useGrouping:!0,numberingSystem:"latn"}).formatToParts(12345675e-1),m=s.find(e=>e.type==="decimal")?.value??".",C=s.find(e=>e.type==="group")?.value??"",y=[],d=[];for(let e=0;e<12;e++){const n=new Date(Date.UTC(2024,e,15));y.push(new Intl.DateTimeFormat(t,{month:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),d.push(new Intl.DateTimeFormat(t,{month:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const p=[],h=[];for(let e=0;e<7;e++){const n=new Date(Date.UTC(2024,0,7+e));p.push(new Intl.DateTimeFormat(t,{weekday:"long",timeZone:"UTC",calendar:"gregory"}).format(n)),h.push(new Intl.DateTimeFormat(t,{weekday:"short",timeZone:"UTC",calendar:"gregory"}).format(n))}const i=new Intl.DateTimeFormat(t,{dateStyle:"short",timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))),S=i.filter(e=>e.type==="day"||e.type==="month"||e.type==="year").map(e=>e.type),D=i.find(e=>e.type==="literal")?.value.trim()||"/",R=i.find(e=>e.type==="month")?.value.length>1,f={day:e=>e.length>1||R?"dd":"d",month:e=>e.length>1?"mm":"m",year:()=>"yyyy"},E=i.filter(e=>f[e.type]).map(e=>f[e.type](e.value)).join(D),I=new Intl.Locale(t).maximize().region,P=W[I]??"USD",l=new Intl.NumberFormat(t,{style:"currency",currency:P,numberingSystem:"latn"}).formatToParts(1),w=l.find(e=>e.type==="currency")?.value??"$",N=l.findIndex(e=>e.type==="currency")<l.findIndex(e=>e.type==="integer"),g={weekday:()=>"dddd",month:e=>/\d/.test(e)?"m":"mmmm",day:e=>e.length>1?"dd":"d",year:()=>"yyyy"},U=e=>new Intl.DateTimeFormat(t,{dateStyle:e,timeZone:"UTC",calendar:"gregory",numberingSystem:"latn"}).formatToParts(new Date(Date.UTC(2024,0,5))).map(n=>g[n.type]?g[n.type](n.value):n.type==="literal"?`"${n.value}"`:"").join(""),A=new Intl.DateTimeFormat(t,{hour:"numeric",hour12:!0,timeZone:"UTC",calendar:"gregory"}),T=e=>A.formatToParts(new Date(Date.UTC(2024,0,5,e))).find(n=>n.type==="dayPeriod")?.value??(e<12?"AM":"PM");return{tag:t,language:new Intl.Locale(t).language,collator:new Intl.Collator(t,{sensitivity:"accent"}),decimal:m,group:C,listSep:m===","?";":",",...b(t,m),longDate:U("full"),longDateWithoutWeekday:U("long"),longTime:"h:mm:ss AM/PM",amDesignator:T(9),pmDesignator:T(15),months:y,shortMonths:d,monthsWithDay:K(t).monthsWithDay,days:p,shortDays:h,order:S,dateSep:D,shortDate:E,currency:{symbol:w,symbolFirst:N}}}let r=null,c=null;const a=()=>(r??=u("en-US"),r);function B(t=a().currency.symbol){return/^\p{Sc}$/u.test(t)?t:`"${t.replace(/"/g,"")}"`}function Q(t,o=B(),s=!a().currency.symbolFirst){return o?s?`${t} ${o}`:o+t:t}function V(t){return r=u(t),c=null,O(r.tag),L(r.currency),F({decimal:r.decimal,group:r.group,months:r.months,monthsWithDay:r.monthsWithDay,shortMonths:r.shortMonths,days:r.days,shortDays:r.shortDays,shortDate:r.shortDate,longDate:r.longDate,longTime:r.longTime,amDesignator:r.amDesignator,pmDesignator:r.pmDesignator,tag:r.tag,eras:r.eras?G(r.eras):null,numerals:r.numerals??null}),r}function ee(t){return M(t,a())}function x(t){return k(t,a())}const te=(t=a())=>({decimal:t.decimal,group:t.group,listSep:t.listSep,order:t.order,dateSep:t.dateSep,currency:t.currency});function re(t){return t===""||t[0]==="'"?t:t[0]==="="?t.length>1?x(t):t:(c??=Z(a()),c(t))}export{q as REGIONS,a as culture,u as cultureOf,Q as currencyAmountCode,B as currencySymbolCode,x as formulaToInvariant,ee as formulaToLocal,te as inputRegion,re as inputToInvariant,V as setCulture};
|
package/core/formula-refs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{colIndex as
|
|
1
|
+
import{colIndex as v,colName as o,MAX_COLS as l,MAX_ROWS as y,parseRangeRef as E,rangeRef as F}from"./address.js";const g=/"(?:[^"]|"")*"|'(?:[^']|'')*'|(\$?)([A-Za-z]{1,3})(\$?)(\d{1,7})(?![A-Za-z0-9_(.])|(\$?)(\d{1,7}):(\$?)(\d{1,7})(?![A-Za-z0-9_(.])|(\$?)([A-Za-z]{1,3}):(\$?)([A-Za-z]{1,3})(?![A-Za-z0-9_(.])/g;function z(r,t,n){if(t)return null;const e=v(r)+n;return e<0||e>=l?-1:e}function R(r,t,n){if(t)return null;const e=r-1+n;return e<0||e>=y?-1:e}function M(r,t,n){return t===0&&n===0?r:r.replace(g,(e,a,$,Z,i,_,m,d,N,x,A,C,b,c,p)=>{if($!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_]/.test(f)||f==="."&&p[c-2]!==":"||v($)>=l||Number(i)>y||Number(i)===0)return e;const u=z($,a==="$",n),s=R(Number(i),Z==="$",t);return u===-1||s===-1?"#REF!":`${a}${u===null?$.toUpperCase():o(u)}${Z}${s===null?i:s+1}`}if(m!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_.]/.test(f))return e;const u=R(Number(m),_==="$",t),s=R(Number(N),d==="$",t);return u===-1||s===-1?"#REF!":`${_}${u===null?m:u+1}:${d}${s===null?N:s+1}`}if(A!==void 0){const f=c>0?p[c-1]:"";if(/[A-Za-z0-9_.]/.test(f))return e;const u=z(A,x==="$",n),s=z(b,C==="$",n);return u===-1||s===-1?"#REF!":`${x}${u===null?A.toUpperCase():o(u)}:${C}${s===null?b.toUpperCase():o(s)}`}return e})}function U(r,t,n){if(!r)return null;if(r.f!==void 0)return r.f;if(r.sf!==void 0){const e=Math.floor(r.base/l);return M(r.sf,t-e,n-(r.base-e*l))}return null}function I(r,t,n=0,e=0){const a={f:t};if(r.typed&&(a.typed=!0),r.ca&&(a.ca=r.ca),r.cm&&(a.cm=r.cm),r.t==="array"){a.t="array";const $=r.ref&&(n||e)?E(r.ref):null;a.ref=$?F({r0:$.r0+n,c0:$.c0+e,r1:$.r1+n,c1:$.c1+e}):r.ref}return a}export{U as formulaText,I as movedInfo,M as translateFormula};
|