@8sheets/data-grid 0.0.0-stage → 1.0.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/LICENSE.md +36 -0
- package/README.md +52 -2
- package/a11y/cell-alt-text.js +1 -0
- package/api/overlay.js +1 -0
- package/api/serialize.js +1 -0
- package/api/skins.js +1 -0
- package/api/style-refs.js +1 -0
- package/api/watermark-xml.js +2 -0
- package/calc/adjust.js +1 -0
- package/calc/cell-set.js +1 -0
- package/calc/compile.js +1 -0
- package/calc/engine.js +1 -0
- package/calc/fill-shape.js +2 -0
- package/calc/functions/array.js +1 -0
- package/calc/functions/database.js +1 -0
- package/calc/functions/date.js +1 -0
- package/calc/functions/engineering.js +1 -0
- package/calc/functions/financial.js +1 -0
- package/calc/functions/helpers.js +1 -0
- package/calc/functions/index.js +1 -0
- package/calc/functions/info.js +1 -0
- package/calc/functions/logical.js +1 -0
- package/calc/functions/lookup.js +1 -0
- package/calc/functions/math.js +1 -0
- package/calc/functions/registry.js +1 -0
- package/calc/functions/stat.js +1 -0
- package/calc/functions/text.js +1 -0
- package/calc/parser.js +3 -0
- package/calc/values.js +1 -0
- package/calcx/ai/client.js +1 -0
- package/calcx/ai/functions.js +15 -0
- package/calcx/ai/settings.js +1 -0
- package/calcx/async.js +1 -0
- package/calcx/culture/format-locale.js +1 -0
- package/calcx/culture/lcid.js +1 -0
- package/calcx/external-read.js +1 -0
- package/calcx/external-write.js +3 -0
- package/calcx/external.js +1 -0
- package/calcx/functions/dynamic.js +1 -0
- package/calcx/functions/ets.js +1 -0
- package/calcx/functions/index.js +1 -0
- package/calcx/functions/misc.js +1 -0
- package/calcx/functions/text.js +1 -0
- package/calcx/functions/xml.js +1 -0
- package/calcx/refresh.js +1 -0
- package/cells/auto-merge.js +1 -0
- package/cells/axis-limits.js +1 -0
- package/cells/axis-ops.js +1 -0
- package/cells/background-xml.js +1 -0
- package/cells/background.js +1 -0
- package/cells/book-css.js +206 -0
- package/cells/book-read.js +1 -0
- package/cells/book-view.js +1 -0
- package/cells/cell-defaults.js +1 -0
- package/cells/cell-extras.js +1 -0
- package/cells/cell-options-ui.js +1 -0
- package/cells/cell-styles-xml.js +1 -0
- package/cells/cf-engine.js +1 -0
- package/cells/cf-file.js +1 -0
- package/cells/cf-paint.js +1 -0
- package/cells/consolidate-links.js +1 -0
- package/cells/docprops-xml.js +2 -0
- package/cells/filter-file.js +1 -0
- package/cells/find-engine.js +2 -0
- package/cells/find.js +1 -0
- package/cells/format-code.js +1 -0
- package/cells/format-panes.js +3 -0
- package/cells/format-tabs.js +102 -0
- package/cells/goto.js +1 -0
- package/cells/header-colors.js +1 -0
- package/cells/mask.js +1 -0
- package/cells/menu-extras.js +1 -0
- package/cells/name-box.js +1 -0
- package/cells/note-xml.js +1 -0
- package/cells/options.js +1 -0
- package/cells/outline-column.js +1 -0
- package/cells/paint.js +1 -0
- package/cells/panes.js +1 -0
- package/cells/rich-data-xml.js +2 -0
- package/cells/rich-data.js +1 -0
- package/cells/rich-runs.js +2 -0
- package/cells/rich-values.js +1 -0
- package/cells/rich-xml.js +1 -0
- package/cells/rounded.js +1 -0
- package/cells/sections.js +2 -0
- package/cells/selection-modes.js +1 -0
- package/cells/style-xml.js +1 -0
- package/cells/text-layout.js +8 -0
- package/cells/undo-group.js +1 -0
- package/cells/validation-alert.js +2 -0
- package/cells/view-options.js +1 -0
- package/cells/view-xml.js +1 -0
- package/celltypes/barcode-tables.js +31 -0
- package/celltypes/barcode.js +2 -0
- package/celltypes/base.js +1 -0
- package/celltypes/cell-buttons.js +1 -0
- package/celltypes/cell-types.js +2 -0
- package/celltypes/data-object.js +1 -0
- package/celltypes/diagonal.js +1 -0
- package/celltypes/dropdowns-more.js +13 -0
- package/celltypes/dropdowns.js +42 -0
- package/celltypes/file-cell.js +2 -0
- package/celltypes/glyphs.js +1 -0
- package/celltypes/persist.js +2 -0
- package/celltypes/range-template.js +2 -0
- package/charts/chartex.js +3 -0
- package/charts/geo/geo-xml.js +1 -0
- package/charts/geo/map-state.js +1 -0
- package/charts/patterns.js +1 -0
- package/core/address.js +1 -0
- package/core/axis.js +1 -0
- package/core/base64.js +1 -0
- package/core/changes.js +1 -0
- package/core/color.js +1 -0
- package/core/cond-format.js +1 -0
- package/core/custom-views.js +1 -0
- package/core/default-names.js +1 -0
- package/core/formula-refs.js +1 -0
- package/core/formula-store.js +1 -0
- package/core/input.js +1 -0
- package/core/math.js +1 -0
- package/core/numfmt.js +1 -0
- package/core/online.js +1 -0
- package/core/protection.js +1 -0
- package/core/regexp.js +1 -0
- package/core/sheet.js +1 -0
- package/core/sparklines.js +1 -0
- package/core/sparse.js +1 -0
- package/core/strings.js +1 -0
- package/core/styles.js +1 -0
- package/core/table-presets.js +7 -0
- package/core/tables.js +2 -0
- package/core/tsv.js +4 -0
- package/core/whatif.js +1 -0
- package/core/workbook.js +1 -0
- package/datasheets/bind.js +1 -0
- package/datasheets/calendar.js +1 -0
- package/datasheets/cross.js +1 -0
- package/datasheets/data-core.js +1 -0
- package/datasheets/data.js +1 -0
- package/datasheets/formula.js +1 -0
- package/datasheets/gantt-paint.js +1 -0
- package/datasheets/gantt-resources.js +1 -0
- package/datasheets/gantt-shapes.js +1 -0
- package/datasheets/gantt.js +1 -0
- package/datasheets/manager.js +1 -0
- package/datasheets/path-binding.js +2 -0
- package/datasheets/persist-writer.js +2 -0
- package/datasheets/persist.js +1 -0
- package/datasheets/query-function.js +1 -0
- package/datasheets/remote.js +3 -0
- package/datasheets/report-entry.js +1 -0
- package/datasheets/report.js +1 -0
- package/datasheets/rules.js +1 -0
- package/datasheets/sort.js +1 -0
- package/datasheets/table-sheet.js +1 -0
- package/datasheets/view.js +3 -0
- package/datasheets/virtual-sheet.js +1 -0
- package/datasheets/window.js +1 -0
- package/extras/getdata/persist.js +2 -0
- package/extras/getdata/rows.js +1 -0
- package/extras/getdata/steps.js +1 -0
- package/i18n/dom.js +1 -0
- package/i18n/en/a11y.js +1 -0
- package/i18n/en/cells.js +1 -0
- package/i18n/en/charts.js +1 -0
- package/i18n/en/common.js +1 -0
- package/i18n/en/datasheets.js +1 -0
- package/i18n/en/format.js +1 -0
- package/i18n/en/misc.js +1 -0
- package/i18n/en/pivot.js +1 -0
- package/i18n/en/proofing.js +1 -0
- package/i18n/en/ribbon.js +1 -0
- package/i18n/en/shapes.js +1 -0
- package/i18n/en/shell.js +1 -0
- package/i18n/en/touch.js +1 -0
- package/i18n/en.js +1 -0
- package/i18n/index.js +1 -0
- package/i18n/key-text.js +1 -0
- package/i18n/languages.js +1 -0
- package/i18n/pl/a11y.js +1 -0
- package/i18n/pl/cells.js +1 -0
- package/i18n/pl/charts.js +1 -0
- package/i18n/pl/common.js +1 -0
- package/i18n/pl/datasheets.js +1 -0
- package/i18n/pl/format.js +1 -0
- package/i18n/pl/misc.js +1 -0
- package/i18n/pl/pivot.js +1 -0
- package/i18n/pl/proofing.js +1 -0
- package/i18n/pl/ribbon.js +1 -0
- package/i18n/pl/shapes.js +1 -0
- package/i18n/pl/shell.js +1 -0
- package/i18n/pl/touch.js +1 -0
- package/i18n/pl.js +1 -0
- package/io/client.js +1 -0
- package/io/crc32.js +1 -0
- package/io/crypto/aes.js +1 -0
- package/io/crypto/agile.js +2 -0
- package/io/crypto/cfb-read.js +1 -0
- package/io/crypto/cfb-write.js +1 -0
- package/io/crypto/dataspaces.js +1 -0
- package/io/crypto/errors.js +1 -0
- package/io/crypto/hash.js +1 -0
- package/io/crypto/index.js +1 -0
- package/io/crypto/package-read.js +1 -0
- package/io/crypto/package-write.js +1 -0
- package/io/crypto/spool.js +1 -0
- package/io/crypto/standard.js +1 -0
- package/io/csv.js +5 -0
- package/io/export-blocks.js +1 -0
- package/io/foreign-parts.js +1 -0
- package/io/foreign-sheets.js +2 -0
- package/io/io.worker.js +1 -0
- package/io/package-paths.js +1 -0
- package/io/plan.js +1 -0
- package/io/xlsx-read.js +1 -0
- package/io/xlsx-styles.js +2 -0
- package/io/xlsx-tail.js +1 -0
- package/io/xlsx-write.js +2 -0
- package/io/xml-escape.js +1 -0
- package/io/xml-scan.js +1 -0
- package/io/zip-reader.js +1 -0
- package/io/zip-writer.js +1 -0
- package/objects/chart-model.js +1 -0
- package/objects/dml.js +5 -0
- package/objects/drawing-xml.js +1 -0
- package/objects/picture-url.js +1 -0
- package/package.json +57 -4
- package/pivot/engine.js +1 -0
- package/pivot/xml.js +2 -0
- package/print/page-setup.js +1 -0
- package/print/paginate.js +1 -0
- package/print/pdf.js +35 -0
- package/print/render-page.js +3 -0
- package/render/patterns.js +1 -0
- package/shapes/form-xml.js +1 -0
- package/shapes/watermark.js +1 -0
- package/slicers/custom-styles.js +1 -0
- package/slicers/date-filters.js +1 -0
- package/slicers/format.js +2 -0
- package/slicers/pivot-file.js +1 -0
- package/slicers/structured.js +1 -0
- package/slicers/table-file.js +1 -0
- package/slicers/write.js +1 -0
- package/sparklines/colors.js +1 -0
- package/sparklines/data.js +1 -0
- package/sparklines/descriptor.js +1 -0
- package/sparklines/excel-paint.js +1 -0
- package/sparklines/functions.js +1 -0
- package/sparklines/paint-core.js +1 -0
- package/sparklines/paint-measure.js +1 -0
- package/sparklines/paint-other.js +2 -0
- package/sparklines/paint-series.js +1 -0
- package/sparklines/paint.js +1 -0
- package/sparklines/print.js +1 -0
- package/sparklines/rule.js +1 -0
- package/table-view/api.js +1 -0
- package/table-view/cell-editor.js +1 -0
- package/table-view/cell-format.js +1 -0
- package/table-view/chrome.js +1 -0
- package/table-view/client.js +1 -0
- package/table-view/column-drag.js +1 -0
- package/table-view/column-input.js +1 -0
- package/table-view/column-window.js +1 -0
- package/table-view/events.js +1 -0
- package/table-view/files.js +1 -0
- package/table-view/grid-keys.js +2 -0
- package/table-view/index.d.ts +4 -0
- package/table-view/index.js +1 -0
- package/table-view/labels.js +1 -0
- package/table-view/model.js +1 -0
- package/table-view/mount.js +1 -0
- package/table-view/panel.js +1 -0
- package/table-view/pivot.js +1 -0
- package/table-view/public.d.ts +841 -0
- package/table-view/quick-filter.js +1 -0
- package/table-view/reader.worker.js +1 -0
- package/table-view/remote.js +1 -0
- package/table-view/row-cache.js +1 -0
- package/table-view/row-selection.js +1 -0
- package/table-view/table-css.js +1207 -0
- package/table-view/totals.js +1 -0
- package/table-view/version.js +1 -0
- package/table-view/worksheet-table.js +1 -0
- package/ui/dialogs.js +3 -0
- package/ui/dom.js +1 -0
- package/ui/icons.js +1 -0
- package/ui/menu-base.js +1 -0
- package/ui/protection-ui.js +1 -0
- package/ui/ui-scale.js +1 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{el as n}from"../ui/dialogs.js";import{PATTERN_LABELS as tt,patternFill as W}from"../render/patterns.js";import{gradientCss as et}from"./paint.js";import{ensureStyles as D,numberField as _,paletteButton as V,popButton as nt,popOver as lt,svgNode as it}from"./format-tabs.js";import{t as s,tc as w}from"../i18n/index.js";const P=(e,t,l,r,a="dlg-input")=>{const c=n("select",{class:a,"aria-label":s(r)});for(const[u,x]of e)c.append(n("option",{value:x,textContent:u}));return c.value=t??"",c.addEventListener("change",()=>l(c.value)),c},E=(e,t,l)=>{const r=n("input",{type:"checkbox",checked:t,on:{change:()=>l(r.checked)}}),a=n("label",{class:"dlg-row dlg-check"},r,s(e));return a.input=r,a},ot=[["General",""],["Left (Indent)","left"],["Center","center"],["Right (Indent)","right"],["Fill","fill"],["Justify","justify"],["Center Across Selection","centerContinuous"],["Distributed (Indent)","distributed"]],st=[["Top","top"],["Center","center"],["Bottom",""],["Justify","justify"],["Distributed","distributed"]],q=new Set(["left","right","distributed"]),Y=e=>e.map(([t,l])=>[w("align",t),l]),Z=e=>e.replace(/[&<>"]/g,t=>`&#${t.charCodeAt(0)};`),S={cx:7.5,cy:75,radius:69},at=(e,t=S.radius)=>[S.cx+t*Math.cos(e*Math.PI/180),S.cy-t*Math.sin(e*Math.PI/180)],X=(e,t,l)=>`M${e} ${t-l}L${e+l} ${t}L${e} ${t+l}L${e-l} ${t}Z`;function rt(){let e="";for(let t=-90;t<=90;t+=15){const[l,r]=at(t);e+=t%45===0?`<path d="${X(l,r,3)}" fill="#222"/>`:`<circle cx="${l}" cy="${r}" r="0.9" fill="#555"/>`}return`<svg class="fc-dial" viewBox="0 0 91 150" role="slider" aria-label="${Z(s("Orientation"))}" aria-valuemin="-90" aria-valuemax="90" tabindex="0">${e}
|
|
2
|
+
<g data-hand><text x="10" y="79.5" font-size="13" fill="#000">${Z(s("Text"))}</text><line x1="39" y1="75" x2="72" y2="75" stroke="#777" stroke-width="1"/></g>
|
|
3
|
+
<path data-mark d="${X(S.cx+S.radius,S.cy,3.4)}" fill="#8c1d2f"/></svg>`}function mt(e,t,l,r){D();let a=e.hAlign??"",c=e.rotation===255,u=e.rotation>90&&e.rotation<=180?90-e.rotation:e.rotation===255?0:e.rotation;const x=n("div",{class:"dlg-label",textContent:s("Indent:")}),v=_({value:e.indent,min:0,max:250,label:w("fc","Indent"),onInput:o=>{t.indent=Math.max(0,o||0)}}),L=()=>{const o=q.has(a)||Number(v.input.value)>0;v.setDisabled(!o),x.classList.toggle("fc-off",!o)},f=E("Justify distributed",e.justifyLastLine===!0,o=>{t.justifyLastLine=o||void 0}),F=()=>{const o=a==="distributed";f.input.disabled=!o},N=P(Y(ot),e.hAlign,o=>{a=o,t.hAlign=o||null,!q.has(o)&&Number(v.input.value)>0&&(v.set(0),t.indent=0),o!=="distributed"&&f.input.checked&&(f.input.checked=!1,t.justifyLastLine=void 0),L(),F()},"Horizontal alignment"),h=_({value:u,min:-90,max:90,label:"Degrees",onInput:o=>T(Math.max(-90,Math.min(90,o||0)),!1)}),g=it(rt()),y=g.querySelector("[data-hand]"),d=g.querySelector("[data-mark]"),p=n("button",{type:"button",class:"fc-vert","aria-label":s("Vertical text"),title:s("Vertical text"),"aria-pressed":String(c)},...[...s("Text")].map(o=>n("span",{textContent:o}))),I=()=>{y.setAttribute("transform",`rotate(${-u} ${S.cx} ${S.cy})`),d.setAttribute("transform",`rotate(${-u} ${S.cx} ${S.cy})`),y.style.opacity=c?"0.3":"1",d.style.display=c?"none":"",g.setAttribute("aria-valuenow",String(u)),p.setAttribute("aria-pressed",String(c))},T=(o,k=!0)=>{u=o,c=!1,t.rotation=o<0?90-o:o,k&&h.set(o),I()};p.addEventListener("click",()=>{c=!c,u=0,h.set(0),t.rotation=c?255:0,I()});const m=o=>{const k=g.getBoundingClientRect(),M=(o.clientX-k.left)*(91/k.width)-S.cx,z=S.cy-(o.clientY-k.top)*(150/k.height);let A=M<=0?Math.sign(z)*90:Math.round(Math.atan2(z,M)*180/Math.PI);const B=Math.round(A/15)*15;Math.abs(B-A)<=2&&(A=B),T(A===0?0:A)};return g.addEventListener("pointerdown",o=>{o.preventDefault(),g.setPointerCapture(o.pointerId),g.focus(),m(o)}),g.addEventListener("pointermove",o=>{g.hasPointerCapture(o.pointerId)&&m(o)}),g.addEventListener("keydown",o=>{const k={ArrowUp:1,ArrowRight:1,ArrowDown:-1,ArrowLeft:-1}[o.key];k&&(o.preventDefault(),T(Math.max(-90,Math.min(90,u+k))))}),L(),F(),I(),n("div",{class:"fc-align fc-bleed"},n("div",{class:"fc-align-left"},n("div",{class:"fc-align-grid"},n("div",{},n("div",{class:"dlg-label",textContent:s("Horizontal alignment:")}),N),n("div",{},x,v.node),n("div",{},n("div",{class:"dlg-label",textContent:s("Vertical alignment:")}),P(Y(st),e.vAlign,o=>{t.vAlign=o||null},"Vertical alignment"))),f),n("div",{class:"fc-align-right"},n("div",{class:"dlg-label",textContent:s("Orientation:")}),n("div",{class:"fc-orient"},p,g),n("div",{class:"fc-degrees"},n("span",{textContent:s("Degrees:")}),h.node)),n("div",{class:"fc-align-low"},n("div",{class:"dlg-label",textContent:s("Text control:")}),E("Wrap text",e.wrap,o=>{t.wrap=o}),E("Shrink to fit",e.shrink,o=>{t.shrink=o}),E("Merge cells",l,r),n("div",{class:"fc-textdir"},n("span",{textContent:s("Text direction:")}),P([[s("Context"),"0"],[s("Left-to-Right"),"1"],[s("Right-to-Left"),"2"]],String(e.readingOrder??0),o=>{t.readingOrder=Number(o)||void 0},"Text direction"))))}const ct=["Aptos Narrow","Aptos","Arial","Calibri","Cambria","Consolas","Courier New","Georgia","Helvetica Neue","Menlo","Tahoma","Times New Roman","Trebuchet MS","Verdana"],K=["Regular","Italic","Bold","Bold Italic"],dt=[8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72];function H(e,t,l={}){const r=n("input",{class:"dlg-input",spellcheck:!1,"aria-label":s(t),...l}),a=n("select",{class:"dlg-list",size:6,"aria-label":s("{name} list",{name:s(t)})});return{node:n("div",{class:"fc-combo"},n("label",{class:"fc-combo-head"},n("span",{textContent:s(e)}),r),a),input:r,list:a}}const j=(e,t,l=r=>r)=>{for(const r of t)e.append(n("option",{value:r,textContent:l(r)}))},R=e=>{const t=e.options[e.selectedIndex];if(!t)return;const l=t.offsetTop-e.options[0].offsetTop+t.offsetHeight;e.scrollTop=l>e.clientHeight?l-e.clientHeight+t.offsetHeight:0},G=(e,t)=>e&&t?"Bold Italic":e?"Bold":t?"Italic":"Regular",O=e=>w("fontstyle",e);function xt(e,t,l,r){D();const a=i=>l[i]!==void 0?l[i]:e[i],c=t.fontName,u=[...ct];u.includes(e.fontName)||u.unshift(e.fontName);const x=i=>s("{name} (Body)",{name:i}),v=i=>s("{name} (Headings)",{name:i}),L=i=>i===c?x(i):i,f=[x(""),v("")].filter(Boolean),F=i=>{const b=i.trim(),C=f.find($=>b.endsWith($));return C?b.slice(0,b.length-C.length).trim():b},N=[];r&&N.push(v(r)),N.push(x(c),...u);const h=n("div",{class:"fc-preview","aria-label":s("Preview")});let g=null;const y=()=>{const i=a("vertAlign"),b=Number(a("underline")??0);h.style.font=`${a("italic")?"italic ":""}${a("bold")?"bold ":""}${Math.min(a("fontSize"),36)}px "${a("fontName")}", sans-serif`,h.style.color=a("color")??"#000000",h.style.textDecoration=[b?"underline":"",a("strike")?"line-through":""].filter(Boolean).join(" "),h.style.textDecorationStyle=b===2||b===4?"double":"solid",h.replaceChildren(i?n(i==="superscript"?"sup":"sub",{textContent:a("fontName")}):document.createTextNode(a("fontName"))),g.checked=["fontName","fontSize","bold","italic","strike","color"].every(C=>(a(C)??null)===(t[C]??null))&&b===Number(t.underline??0)&&!i},d=H("Font:","Font");j(d.list,N),d.input.value=L(e.fontName),d.list.value=L(e.fontName),d.list.addEventListener("change",()=>{d.input.value=d.list.value,l.fontName=F(d.list.value),y()}),d.input.addEventListener("input",()=>{const i=F(d.input.value);if(i==="")return;l.fontName=i;const b=d.input.value.trim().toLowerCase(),C=N.find($=>$.toLowerCase().startsWith(b));C?(d.list.value=C,R(d.list)):d.list.selectedIndex=-1,y()}),d.input.addEventListener("change",()=>{d.input.value=L(F(d.input.value)||a("fontName"))});const p=H("Font style:","Font style");j(p.list,K,O);const I=i=>{p.input.value=O(i),p.list.value=i};I(G(e.bold,e.italic));const T=i=>{l.bold=i.includes("Bold"),l.italic=i.includes("Italic"),y()};p.list.addEventListener("change",()=>{p.input.value=O(p.list.value),T(p.list.value)}),p.input.addEventListener("input",()=>{const i=p.input.value.trim().toLowerCase(),b=K.find(C=>O(C).toLowerCase()===i);b&&(p.list.value=b,T(b))}),p.input.addEventListener("change",()=>I(G(a("bold"),a("italic"))));const m=H("Size:","Size",{type:"number",min:1,max:409,step:"any"});j(m.list,dt.map(String));const o=i=>{m.input.value=String(i),m.list.value=String(i)};o(e.fontSize),m.list.addEventListener("change",()=>{m.input.value=m.list.value,l.fontSize=Number(m.list.value),y()}),m.input.addEventListener("input",()=>{const i=Number(m.input.value);i>0&&(l.fontSize=i,m.list.value=String(i),y())});const k=P([[s("None"),"0"],[w("underline","Single"),"1"],[w("underline","Double"),"2"],[w("underline","Single Accounting"),"3"],[w("underline","Double Accounting"),"4"]],String(e.underline),i=>{l.underline=Number(i),y()},"Underline"),M=(i,b,C)=>{const $=n("input",{type:"checkbox",checked:b,"aria-label":s(i),on:{change:()=>{C($.checked),y()}}});return{i:$,row:n("label",{class:"dlg-row dlg-check"},$,s(i))}},z=M("Strikethrough",e.strike,i=>{l.strike=i}),A=M("Superscript",e.vertAlign==="superscript",i=>{l.vertAlign=i?"superscript":null,i&&(B.i.checked=!1)}),B=M("Subscript",e.vertAlign==="subscript",i=>{l.vertAlign=i?"subscript":null,i&&(A.i.checked=!1)}),J=V(e.color,"#000000",i=>{l.color=i,y()},{label:"Font color"});g=n("input",{type:"checkbox","aria-label":s("Normal font"),on:{change:()=>{if(!g.checked){y();return}Object.assign(l,{fontName:t.fontName,fontSize:t.fontSize,bold:t.bold,italic:t.italic,strike:t.strike,underline:t.underline??0,color:t.color??null,vertAlign:null}),d.input.value=L(t.fontName),d.list.value=L(t.fontName),o(t.fontSize),I(G(t.bold,t.italic)),k.value=String(t.underline??0),z.i.checked=t.strike,A.i.checked=!1,B.i.checked=!1,J.setValue(t.color??null),R(d.list),R(m.list),y()}}});const U=n("div",{class:"fc-font fc-bleed"},n("div",{class:"fc-font-top"},d.node,p.node,m.node,n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Underline:")}),k),n("div",{class:"fc-font-cell"},n("div",{class:"dlg-label",textContent:s("Color:")}),J),n("div",{class:"fc-font-cell fc-font-normal"},n("label",{class:"dlg-row dlg-check"},g,s("Normal font")))),n("div",{class:"fc-font-low"},n("div",{},n("div",{class:"dlg-label",textContent:s("Effects:")}),z.row,A.row,B.row),n("div",{},n("div",{class:"dlg-label",textContent:s("Preview")}),h)));return U.onShow=()=>[d.list,p.list,m.list].forEach(R),y(),U}function Q(e){const t=document.createElement("canvas");if(t.width=32,t.height=20,e){const l=t.getContext("2d");l.fillStyle=W(l,{type:e,fg:"#000000"},1)??"#FFFFFF",l.fillRect(0,0,32,20)}return t}function ut(e,t){const l=n("span",{class:"fc-pat-chip"}),r=nt("Pattern style",l),a=()=>l.replaceChildren(...e?[Q(e)]:[]);return a(),r.setValue=c=>{e=c,a()},lt(r,"Pattern style list",c=>{const u=n("div",{class:"fc-pat-grid"});for(const[x,v]of tt)u.append(n("button",{type:"button",title:w("pattern",x),"aria-label":w("pattern",x),"aria-pressed":String(v===e),on:{click:()=>{e=v,a(),c(),t(v)}}},Q(v)));return u}),r}function ht(e,t,l){D();let r=e.pattern?.type??"",a=e.pattern?.fg??"#000000";const c=n("div",{class:"fc-sample","aria-label":s("Sample")}),u=()=>{const f=t.fill!==void 0?t.fill:e.fill,F=t.gradient!==void 0?t.gradient:e.gradient,N=t.pattern!==void 0?t.pattern:e.pattern;if(c.style.backgroundColor=f??(F||N?"#FFFFFF":"transparent"),c.style.backgroundImage="none",F)c.style.backgroundImage=et(F);else if(N){const h=document.createElement("canvas");h.width=16,h.height=16;const g=h.getContext("2d");g.fillStyle=W(g,N,1)??"#FFFFFF",g.fillRect(0,0,16,16),c.style.backgroundImage=`url(${h.toDataURL()})`}},x=ut(r,f=>{r=f,t.pattern=f?{type:f,fg:a}:null,f&&(t.gradient=null),f&&!e.fill&&!t.fill&&(t.fill="#FFFFFF"),u()}),v=V(e.fill??null,"#FFFFFF",f=>{f===null?(t.fill=null,t.pattern=null,t.gradient=null,r="",x.setValue("")):(t.fill=f,t.gradient=null),u()},{none:"No Color",label:"Background color",named:!0}),L=n("button",{type:"button",class:"dlg-btn",textContent:s("Fill Effects…"),on:{click:()=>l(t.gradient??e.gradient,f=>{t.gradient=f,t.pattern=null,t.fill=f.stops[0].color,r="",x.setValue(""),v.setValue(null),u()})}});return u(),n("div",{class:"fc-fill fc-bleed"},n("div",{class:"fc-fill-left"},n("div",{class:"dlg-label",textContent:s("Background color:")}),v,L),n("div",{class:"fc-fill-right"},n("div",{class:"dlg-label",textContent:s("Pattern color:")}),V(e.pattern?.fg??null,"#000000",f=>{a=f??"#000000",r&&(t.pattern={type:r,fg:a}),u()},{label:"Pattern color",named:!0}),n("div",{class:"dlg-label",textContent:s("Pattern style:")}),x),n("div",{class:"fc-fill-low"},n("div",{class:"dlg-label",textContent:s("Sample")}),c))}function yt(e,t){return D(),n("div",{class:"fc-protect"},n("p",{class:"fc-hint",textContent:s("To lock cells or hide formulas, protect the worksheet. On the Review tab, click Protect Sheet.")}),E(w("protect","Locked"),e.unlocked!==!0,l=>{t.unlocked=l?void 0:!0}),E(w("protect","Hidden"),e.hiddenFormula===!0,l=>{t.hiddenFormula=l?!0:void 0}),E("Allow editing in the cell",e.ext?.noEdit!==!0,l=>{t.ext={noEdit:l?null:!0}}))}export{mt as alignmentTab,ht as fillTab,xt as fontTab,yt as protectionTab};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import{el as o}from"../ui/dialogs.js";import{getFormatter as j}from"../core/numfmt.js";import{paletteColors as Q}from"../ui/menu-base.js";import{t as l,tc as F}from"../i18n/index.js";import{formatCodeProblem as $e}from"./format-code.js";function ee(n,s){I();const{theme:f,standard:p}=Q(),r=[],t=h=>{for(const c of r)c.setAttribute("aria-pressed",String(c.dataset.color===h))},m=h=>{const c=o("div",{class:"palette"});for(const u of h){const C=o("button",{type:"button",title:u,"aria-label":u,"aria-pressed":"false",class:"fc-swatch",on:{click:()=>{t(u),s(u)}}});C.style.background=u,C.dataset.color=u,r.push(C),c.append(C)}return c},y=o("input",{type:"color",class:"dlg-color",value:(n??"#FFFFFF").toLowerCase(),"aria-label":l("More colors"),on:{input:()=>{const h=y.value.toUpperCase();t(h),s(h)}}}),v=o("div",{},o("div",{class:"palette-label",textContent:l("Theme Colors")}),m(f),o("div",{class:"palette-label",textContent:l("Standard Colors")}),m(p),o("label",{class:"dlg-row"},`${l("More Colors:")} `,y));return t(n?n.toUpperCase():null),v.mark=h=>t(h?h.toUpperCase():null),v}function O(n){const s=document.createElement("template");return s.innerHTML=n.trim(),s.content.firstChild}const z=()=>O('<svg class="fc-chev" width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M1 1l3.5 3.5L8 1"/></svg>');function te(n,s,f){let p=null;const r=()=>{p?.remove(),p=null,document.removeEventListener("pointerdown",t,!0)},t=m=>{p&&!p.contains(m.target)&&!n.contains(m.target)&&r()};n.addEventListener("click",()=>{if(p){r();return}p=o("div",{class:"fc-pop",role:"dialog","aria-label":l(s)},f(r)),n.closest("dialog").append(p);const m=n.getBoundingClientRect();p.style.left=`${Math.max(8,Math.min(m.left,window.innerWidth-p.offsetWidth-8))}px`,p.style.top=`${Math.max(8,Math.min(m.bottom+2,window.innerHeight-p.offsetHeight-8))}px`,document.addEventListener("pointerdown",t,!0)})}function ne(n,...s){return I(),o("button",{type:"button",class:"dlg-btn fc-popbtn","aria-label":l(n),title:l(n)},...s,z())}function oe(n,s,f,{none:p="Automatic",label:r="Color",named:t=!1}={}){const m=o("span",{class:"fc-chip"}),y=o("span",{class:"fc-chip-text",textContent:l(p??"")}),v=()=>{const u=t&&n==null;m.hidden=u,y.hidden=!u,m.style.background=n??s},h=ne(r,m,y),c=u=>{n=u,v(),f(u)};return h.setValue=u=>{n=u,v()},v(),te(h,l("{name} palette",{name:l(r)}),u=>o("div",{},p===null?null:o("button",{type:"button",class:"dlg-btn",textContent:l(p),on:{click:()=>{c(null),u()}}}),ee(n,C=>{c(C),u()}))),h}function le({value:n,min:s,max:f,label:p,onInput:r}){I();const t=o("input",{class:"dlg-input fc-num",type:"number",min:s,max:f,value:n,"aria-label":l(p),on:{input:()=>r(Number(t.value))}}),m=c=>{t.disabled||(t.value=String(Math.max(s,Math.min(f,(Number(t.value)||0)+c))),t.dispatchEvent(new Event("input",{bubbles:!0})))},y=o("button",{type:"button","aria-label":l("Increase {name}",{name:l(p)}),on:{click:()=>m(1)}},O('<svg width="9" height="6" viewBox="0 0 9 6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round"><path d="M1 5l3.5-3.5L8 5"/></svg>')),v=o("button",{type:"button","aria-label":l("Decrease {name}",{name:l(p)}),on:{click:()=>m(-1)}},z());return{node:o("span",{class:"fc-numfield"},t,o("span",{class:"fc-stepper"},y,v)),input:t,set:c=>{t.value=String(c)},setDisabled:c=>{t.disabled=c,y.disabled=c,v.disabled=c}}}const B=n=>n>0?`.${"0".repeat(n)}`:"",U=[["-1,234.10",n=>n],["1,234.10 (red)",n=>`${n};[Red]${n}`],["(1,234.10)",n=>`${n}_);(${n})`],["(1,234.10) (red)",n=>`${n}_);[Red](${n})`]],ie=[["None",""],["$","$"],["€","€"],["£","£"],["¥","¥"],["zł",'"zł"'],["CHF",'"CHF"'],["kr",'"kr"']],W=["m/d/yyyy","dddd, mmmm d, yyyy","m/d","m/d/yy","mm/dd/yy","d-mmm","d-mmm-yy","dd-mmm-yy","mmm-yy","mmmm-yy","mmmm d, yyyy","m/d/yy h:mm AM/PM","m/d/yy h:mm","mmmmm","mmmmm-yy","d-mmm-yyyy","yyyy-mm-dd","dd.mm.yyyy"],Y=["h:mm:ss AM/PM","h:mm AM/PM","h:mm:ss","h:mm","m/d/yy h:mm AM/PM","m/d/yy h:mm","mm:ss","mm:ss.0","[h]:mm:ss"],ae=[["English (United States)",""],["English (United Kingdom)","[$-809]"],["Polish","[$-415]"],["German","[$-407]"],["French","[$-40C]"],["Spanish","[$-C0A]"],["Italian","[$-410]"],["Japanese","[$-411]"],["Chinese (Simplified)","[$-804]"],["Korean","[$-412]"],["Arabic","[$-401]"],["Hebrew","[$-40D]"]],G=[["Up to one digit (1/4)","# ?/?"],["Up to two digits (21/25)","# ??/??"],["Up to three digits (312/943)","# ???/???"],["As halves (1/2)","# ?/2"],["As quarters (2/4)","# ?/4"],["As eighths (4/8)","# ?/8"],["As sixteenths (8/16)","# ??/16"],["As tenths (3/10)","# ?/10"],["As hundredths (30/100)","# ??/100"]],H=[["Zip Code","00000"],["Zip Code + 4","00000-0000"],["Phone Number","[<=9999999]###-####;(###) ###-####"],["Social Security Number","000-00-0000"]],se=["General","0","0.00","#,##0","#,##0.00","#,##0_);(#,##0)","#,##0_);[Red](#,##0)","#,##0.00_);(#,##0.00)","#,##0.00_);[Red](#,##0.00)","$#,##0_);($#,##0)","$#,##0_);[Red]($#,##0)","$#,##0.00_);($#,##0.00)","$#,##0.00_);[Red]($#,##0.00)","0%","0.00%","0.00E+00","##0.0E+0","# ?/?","# ??/??","m/d/yy","d-mmm-yy","d-mmm","mmm-yy","h:mm AM/PM","h:mm:ss AM/PM","h:mm","h:mm:ss","m/d/yy h:mm","mm:ss","mm:ss.0","@","[h]:mm:ss",'_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)','_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)','_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)','_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)'],re=["General","Number","Currency","Accounting","Date","Time","Percentage","Fraction","Scientific","Text","Special","Custom"],ce=(n,s)=>{const f=n?`${n}* `:"* ",p=`#,##0${B(s)}`;return`_(${f}${p}_);_(${f}(${p});_(${f}"-"${s>0?"?".repeat(s):""}_);_(@_)`};function de(n){const s=n.replace(/"[^"]*"|\\.|\[[^\]]*\]|_.|\*./g,"");if(n==="General")return{category:"General"};if(n==="@")return{category:"Text"};if(H.some(([,m])=>m===n))return{category:"Special"};if(G.some(([,m])=>m===n))return{category:"Fraction"};if(/^_\(/.test(n)&&n.split(";").length===4&&n.includes("*"))return{category:"Accounting"};if(/%/.test(s))return{category:"Percentage",decimals:/\.(0+)/.exec(s)?.[1].length??0};if(/E[+-]/i.test(s))return{category:"Scientific",decimals:/\.(0+)/.exec(s)?.[1].length??0};const f=n.replace(/^\[\$-[0-9A-Fa-f]+\]/,"");if(W.includes(f))return{category:"Date",type:f,locale:n.slice(0,n.length-f.length)};if(Y.includes(f))return{category:"Time",type:f,locale:n.slice(0,n.length-f.length)};if(j(n).isDate)return{category:"Custom"};const r=n.split(";")[0],t=/^(\$|€|£|¥|"[^"]+")?(#,##)?0(\.0+)?(_\))?$/.exec(r);if(t){const m=t[3]?t[3].length-1:0,y=n.includes(";")?n.includes("[Red](")?3:n.includes(";(")?2:n.includes(";[Red]")?1:-1:0;if(y>=0)return t[1]?{category:"Currency",symbol:t[1],decimals:m,negative:y}:{category:"Number",decimals:m,thousands:!!t[2],negative:y}}return{category:"Custom"}}function ve(n,s,f,p=[]){const r=de(n),t={category:r.category,decimals:r.decimals??2,thousands:r.thousands??!1,negative:r.negative??0,symbol:r.symbol??"$",type:r.type,locale:r.locale??"",code:n};I();const m=o("output",{class:"fmt-preview","aria-label":l("Sample")}),y=o("p",{class:"dlg-note"}),v=o("div",{}),h=o("select",{class:"dlg-list",size:12,"aria-label":l("Category")});for(const d of re)h.append(o("option",{value:d,textContent:F("numfmt",d)}));h.value=t.category;const c=d=>{t.code=d,m.textContent=s(d),f(d)},u=d=>{const g=le({value:t.decimals,min:0,max:30,label:"Decimal places",onInput:x=>{t.decimals=Math.max(0,Math.min(30,x||0)),d()}});return o("label",{class:"dlg-row"},`${l("Decimal places:")} `,g.node)},C=(d,g,x,P,i=7)=>{const e=o("select",{class:"dlg-list",size:i,"aria-label":l(x),on:{change:()=>P(e.value)}});for(const[a,b]of d)e.append(o("option",{value:b,textContent:a}));return e.value=g,e},M=(d,g,x,P)=>{const i=o("select",{class:"dlg-input","aria-label":l(x),on:{change:()=>P(i.value)}});for(const[e,a]of d)i.append(o("option",{value:a,textContent:e}));return i.value=g,i},_=d=>d.map(([g,x])=>[l(g),x]),E=d=>C(U.map(([g],x)=>[l(g),String(x)]),String(t.negative),"Negative numbers",g=>{t.negative=Number(g),c(d())},4),L=()=>{const d=t.category,g=[];let x="";const P=ie.map(([i,e])=>[i==="None"?l("None"):i,e]);if(d==="General")x=l("General format cells have no specific number format."),c("General");else if(d==="Number"){const i=()=>U[t.negative][1](`${t.thousands?"#,##0":"0"}${B(t.decimals)}`),e=o("input",{type:"checkbox",checked:t.thousands,on:{change:()=>{t.thousands=e.checked,c(i())}}});g.push(u(()=>c(i())),o("label",{class:"dlg-row"},e,` ${l("Use 1000 Separator (,)")}`),o("div",{class:"dlg-label",textContent:l("Negative numbers:")}),E(i)),x=l("Number is used for general display of numbers. Currency and Accounting offer specialized formatting for monetary value."),c(i())}else if(d==="Currency"){const i=()=>U[t.negative][1](`${t.symbol}#,##0${B(t.decimals)}`);g.push(u(()=>c(i())),o("label",{class:"dlg-row"},`${l("Symbol:")} `,M(P,t.symbol,"Symbol",e=>{t.symbol=e,c(i())})),o("div",{class:"dlg-label",textContent:l("Negative numbers:")}),E(i)),x=l("Currency formats are used for general monetary values. Use Accounting formats to align decimal points in a column."),c(i())}else if(d==="Accounting"){const i=()=>ce(t.symbol,t.decimals);g.push(u(()=>c(i())),o("label",{class:"dlg-row"},`${l("Symbol:")} `,M(P,t.symbol,"Symbol",e=>{t.symbol=e,c(i())}))),x=l("Accounting formats line up the currency symbols and decimal points in a column."),r.category!=="Accounting"||t.code!==n?c(i()):c(n)}else if(d==="Date"||d==="Time"){const i=d==="Date"?W:Y;i.includes(t.type)||([t.type]=i);const e=()=>`${t.locale}${t.type}`,a=d==="Date"?45000.75:.75;g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(i.map(b=>[j(b).number(a),b]),t.type,"Type",b=>{t.type=b,c(e())}),o("label",{class:"dlg-row"},`${l("Locale:")} `,M(_(ae),t.locale,"Locale",b=>{t.locale=b,c(e())}))),x=d==="Date"?l("Date formats display date and time serial numbers as date values."):l("Time formats display date and time serial numbers as time values."),c(e())}else if(d==="Percentage"||d==="Scientific"){const i=()=>d==="Percentage"?`0${B(t.decimals)}%`:`0${B(t.decimals)}E+00`;g.push(u(()=>c(i()))),x=d==="Percentage"?l("Percentage formats multiply the cell value by 100 and display the result with a percent symbol."):"",c(i())}else if(d==="Fraction"){const i=G.some(([,e])=>e===t.code)?t.code:G[0][1];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(_(G),i,"Type",c)),c(i)}else if(d==="Text")x=l("Text format cells are treated as text even when a number is in the cell. The cell is displayed exactly as entered."),c("@");else if(d==="Special"){const i=H.some(([,e])=>e===t.code)?t.code:H[0][1];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),C(_(H),i,"Type",c,4)),x=l("Special formats are useful for tracking list and database values."),c(i)}else{const i=o("input",{class:"dlg-input",value:t.code,spellcheck:!1,"aria-label":l("Format code"),on:{input:()=>c(i.value)}}),e=[...new Set([...se,...p])];g.push(o("div",{class:"dlg-label",textContent:l("Type:")}),i,C(e.map(a=>[a,a]),t.code,"Existing formats",a=>{i.value=a,c(a)},8)),x=l("Type the number format code, using one of the existing codes as a starting point."),c(t.code)}v.replaceChildren(...g),y.textContent=x};return h.addEventListener("change",()=>{t.category=h.value,t.category==="Custom"&&(t.code=t.code||"General"),L()}),L(),o("div",{class:"fc-number"},o("div",{},o("div",{class:"dlg-label",textContent:l("Category:")}),h),o("div",{class:"fc-number-side"},o("div",{class:"dlg-label",textContent:l("Sample")}),m,v,y))}const V="fc-styles";function I(){document.getElementById(V)||document.head.append(o("style",{id:V,textContent:`
|
|
2
|
+
.fc-dlg[open] { display: flex; flex-direction: column; height: 603px; overflow: hidden; }
|
|
3
|
+
.fc-dlg .dlg-body { flex: 1; min-height: 0; display: flex; }
|
|
4
|
+
.fc-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
5
|
+
.fc-dlg .dlg-title { margin-bottom: 18px; }
|
|
6
|
+
.fc-dlg .dlg-foot { margin-top: 17px; }
|
|
7
|
+
.fc-dlg .dlg-label { margin-bottom: 8px; }
|
|
8
|
+
.fc-dlg .dlg-panes { flex: 1; min-height: 0; overflow: auto; padding: 22px 24px 12px 19px; border: 1px solid var(--xl-box-line); border-radius: 7px; background: var(--xl-box); }
|
|
9
|
+
.fc-dlg .dlg-note { margin: 17px 0 0; font-size: 13px; color: var(--ink); line-height: 16px; }
|
|
10
|
+
.fc-rule-h { border: 0; border-top: 1px solid var(--xl-box-line); margin: 0; }
|
|
11
|
+
.fc-bleed { margin: -22px -24px -12px -19px; min-height: calc(100% + 34px); }
|
|
12
|
+
.fc-grow { flex: 1 1 0; min-width: 0; width: auto; }
|
|
13
|
+
|
|
14
|
+
.fc-number { display: grid; grid-template-columns: 126px minmax(0, 1fr); column-gap: 17px; }
|
|
15
|
+
.fc-number .dlg-list { min-width: 0; }
|
|
16
|
+
.fc-number .dlg-label { margin-bottom: 5px; }
|
|
17
|
+
.fc-number > div:first-child .dlg-list { height: 328px; }
|
|
18
|
+
.fc-number-side .dlg-list { height: auto; }
|
|
19
|
+
.fc-number-side select.dlg-input { flex: 1; width: auto; min-width: 0; }
|
|
20
|
+
.fc-number-side .dlg-row { margin-top: 10px; }
|
|
21
|
+
.fc-number-side .dlg-label { margin-top: 10px; }
|
|
22
|
+
.fc-number-side > .dlg-label:first-child { margin-top: 0; }
|
|
23
|
+
.fc-dlg .fmt-preview { min-height: 35px; padding: 9px 12px; border: 0; border-radius: 6px; background: var(--xl-sample); color: var(--ink); user-select: text; white-space: nowrap; }
|
|
24
|
+
|
|
25
|
+
.fc-numfield { display: inline-flex; align-items: center; gap: 4px; }
|
|
26
|
+
.fc-num { width: 42px; text-align: left; }
|
|
27
|
+
.fc-off { color: var(--ink-off) !important; }
|
|
28
|
+
|
|
29
|
+
.fc-popbtn { display: flex; gap: 6px; width: 100%; }
|
|
30
|
+
.fc-chip { flex: 1; min-width: 0; height: 12px; border-radius: 2px; border: 1px solid rgba(128, 128, 128, 0.6); }
|
|
31
|
+
.fc-chip-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
32
|
+
.fc-pop { position: fixed; z-index: 60; padding: 6px; background: var(--menu); color: var(--ink); border: 1px solid var(--panel-line); border-radius: 6px; box-shadow: var(--shadow); }
|
|
33
|
+
.fc-swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 0; }
|
|
34
|
+
.fc-pat-grid { display: grid; grid-template-columns: repeat(6, 34px); gap: 3px; }
|
|
35
|
+
.fc-pat-grid button { width: 34px; height: 22px; padding: 1px; border: 1px solid rgba(128, 128, 128, 0.5); border-radius: 3px; background: #fff; line-height: 0; }
|
|
36
|
+
.fc-pat-grid button[aria-pressed="true"] { outline: 2px solid var(--accent); }
|
|
37
|
+
.fc-pat-grid canvas, .fc-pat-chip canvas { width: 100%; height: 100%; display: block; }
|
|
38
|
+
.fc-pat-chip { flex: 1; min-width: 0; height: 12px; }
|
|
39
|
+
|
|
40
|
+
.fc-align { display: grid; grid-template-columns: 350px minmax(0, 1fr); grid-template-rows: 277px auto; }
|
|
41
|
+
.fc-align-left { padding: 22px 0 0 19px; }
|
|
42
|
+
.fc-align-right { padding: 22px 0 0 22px; border-left: 1px solid var(--xl-box-line); }
|
|
43
|
+
.fc-align-low { grid-column: 1 / -1; padding: 30px 19px 12px 22px; border-top: 1px solid var(--xl-box-line); }
|
|
44
|
+
.fc-align-grid { display: grid; grid-template-columns: 213px auto; column-gap: 20px; row-gap: 13px; align-items: end; justify-content: start; }
|
|
45
|
+
.fc-align-left .dlg-check { margin-top: 15px; }
|
|
46
|
+
.fc-orient { display: flex; gap: 10px; margin: 5px 0 0 17px; }
|
|
47
|
+
.fc-vert { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 30px; height: 150px; padding: 0; background: #fff; color: #000; line-height: 17px; border: 0; outline-offset: 1px; }
|
|
48
|
+
.fc-vert[aria-pressed="true"] { color: #8c1d2f; outline: 2px solid var(--accent); }
|
|
49
|
+
.fc-dial { display: block; width: 91px; height: 150px; background: #fff; touch-action: none; pointer-events: auto; }
|
|
50
|
+
.fc-degrees { display: flex; align-items: center; gap: 8px; margin: 5px 0 0 17px; }
|
|
51
|
+
.fc-align-low .dlg-check { min-height: 22px; margin-left: 10px; }
|
|
52
|
+
.fc-textdir { display: flex; align-items: center; gap: 8px; margin: 12px 0 0 10px; }
|
|
53
|
+
.fc-textdir select { width: 213px; }
|
|
54
|
+
|
|
55
|
+
.fc-font { display: flex; flex-direction: column; }
|
|
56
|
+
.fc-font-top { padding: 22px 24px 0 19px; display: grid; grid-template-columns: 261px 127px minmax(0, 1fr); column-gap: 20px; }
|
|
57
|
+
.fc-combo-head { display: block; }
|
|
58
|
+
.fc-combo-head > span { display: block; margin-bottom: 8px; }
|
|
59
|
+
.fc-combo .dlg-input { width: 100%; }
|
|
60
|
+
.fc-combo .dlg-list { display: block; width: 100%; min-width: 0; height: 107px; margin-top: 8px; }
|
|
61
|
+
.fc-font-mid { grid-column: 1 / -1; display: contents; }
|
|
62
|
+
.fc-font-cell { margin-top: 10px; }
|
|
63
|
+
.fc-font-cell .dlg-label { margin-bottom: 5px; }
|
|
64
|
+
.fc-font-normal { display: flex; align-items: center; padding-top: 25px; }
|
|
65
|
+
.fc-font-low { margin-top: 15px; padding: 14px 24px 12px 22px; border-top: 1px solid var(--xl-box-line); display: grid; grid-template-columns: 283px minmax(0, 1fr); }
|
|
66
|
+
.fc-font-low .dlg-check { margin-left: 17px; }
|
|
67
|
+
.fc-dlg .fc-preview { position: relative; display: flex; align-items: center; justify-content: center; width: 217px; height: 67px; overflow: hidden; white-space: nowrap; background: #fff; color: #000; }
|
|
68
|
+
.fc-preview::before, .fc-preview::after { content: ""; position: absolute; top: 50%; width: 40px; border-top: 1px solid #000; }
|
|
69
|
+
.fc-preview::before { left: 0; }
|
|
70
|
+
.fc-preview::after { right: 0; }
|
|
71
|
+
|
|
72
|
+
.fc-border { position: relative; height: 100%; min-height: 432px; display: grid; grid-template-columns: 218px minmax(0, 1fr); grid-template-rows: 331px auto auto; column-gap: 33px; }
|
|
73
|
+
.fc-lines { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 26px); grid-template-columns: repeat(2, 1fr); width: 215px; margin-top: 3px; padding: 2px; background: #fff; }
|
|
74
|
+
.fc-line { padding: 0; border: 1px solid transparent; background: none; line-height: 0; display: flex; align-items: center; justify-content: center; }
|
|
75
|
+
.fc-line[aria-selected="true"] { border-color: #000; outline: 1px solid #bbb; outline-offset: -3px; }
|
|
76
|
+
.fc-line canvas { display: block; }
|
|
77
|
+
.fc-border-left > .dlg-label + .fc-lines + .dlg-label { margin-top: 29px; }
|
|
78
|
+
.fc-border-right { padding-left: 25px; border-left: 1px solid var(--xl-box-line); }
|
|
79
|
+
.fc-border-left .fc-popbtn { width: 190px; }
|
|
80
|
+
.fc-presets { display: flex; gap: 26px; margin-left: 9px; }
|
|
81
|
+
.fc-preset { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 53px; }
|
|
82
|
+
.fc-preset button { width: 53px; height: 38px; padding: 0; }
|
|
83
|
+
.fc-preset button:disabled { opacity: 0.45; }
|
|
84
|
+
.fc-border-rule { margin: 14px 0 20px -14px; border: 0; border-top: 1px solid var(--xl-box-line); }
|
|
85
|
+
.fc-edges { position: relative; width: 232px; height: 170px; margin: 5px 0 0 6px; }
|
|
86
|
+
.fc-edge { position: absolute; }
|
|
87
|
+
.fc-edge:disabled { opacity: 0.4; }
|
|
88
|
+
.fc-border-box { position: absolute; left: 35px; top: 0; display: block; background: #fff; }
|
|
89
|
+
.fc-hint { grid-column: 1 / -1; margin: 6px 0 0; line-height: 16px; }
|
|
90
|
+
.fc-radius { grid-column: 1 / -1; margin-top: 4px; gap: 8px; white-space: nowrap; }
|
|
91
|
+
|
|
92
|
+
.fc-fill { display: grid; grid-template-columns: 280px minmax(0, 1fr); grid-template-rows: 271px minmax(0, 1fr); height: 485px; }
|
|
93
|
+
.fc-fill-left { padding: 40px 22px 0 27px; }
|
|
94
|
+
.fc-fill-right { padding: 40px 30px 0 33px; border-left: 1px solid var(--xl-box-line); }
|
|
95
|
+
.fc-fill-right .dlg-label ~ .dlg-label { margin-top: 18px; }
|
|
96
|
+
.fc-fill-left .dlg-btn:not(.fc-popbtn) { margin-top: 14px; }
|
|
97
|
+
.fc-fill-low { grid-column: 1 / -1; display: flex; flex-direction: column; padding: 26px 26px 16px 28px; border-top: 1px solid var(--xl-box-line); }
|
|
98
|
+
.fc-sample { flex: 1; min-height: 0; margin-top: 4px; border-radius: 3px; }
|
|
99
|
+
|
|
100
|
+
.fc-protect .fc-hint { margin: 13px 0 13px; max-width: 520px; }
|
|
101
|
+
.fc-protect .dlg-check { margin-left: 2px; }
|
|
102
|
+
`}))}const pe=["none","hair","dotted","dashDotDot","dashDot","dashed","thin","mediumDashDotDot","slantDashDot","mediumDashDot","mediumDashed","medium","thick","double"],K={none:"None",hair:"Hairline",dotted:"Dotted",dashDotDot:"Dash Dot Dot",dashDot:"Dash Dot",dashed:"Dashed",thin:"Thin",mediumDashDotDot:"Medium Dash Dot Dot",slantDashDot:"Slanted Dash Dot",mediumDashDot:"Medium Dash Dot",mediumDashed:"Medium Dashed",medium:"Medium",thick:"Thick",double:"Double"},X=n=>K[n]?F("line",K[n]):n,Z={hair:[1,1],dotted:[2,2],dashed:[4,2],dashDot:[6,2,2,2],dashDotDot:[6,2,2,2,2,2],mediumDashed:[6,2],mediumDashDot:[6,2,2,2],mediumDashDotDot:[6,2,2,2,2,2],slantDashDot:[6,2,2,2]},q={medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3};function me(n){const s=window.devicePixelRatio||1,f=100,p=22,r=document.createElement("canvas");r.width=f*s,r.height=p*s,r.style.width=`${f}px`,r.style.height=`${p}px`;const t=r.getContext("2d");if(t.scale(s,s),t.strokeStyle="#000",t.fillStyle="#000",n==="none")return t.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',t.textAlign="center",t.fillText(l("None"),f/2,15),r;if(n==="double")return t.fillRect(3,9,f-6,1),t.fillRect(3,12,f-6,1),r;t.lineWidth=q[n]??1,t.setLineDash(Z[n]??[]);const m=t.lineWidth%2?11.5:11;return t.beginPath(),t.moveTo(3,m),t.lineTo(f-3,m),t.stroke(),r}const N=128,w=8,D=N-w,S=N/2,fe={t:"M1 2.5h14",h:"M1 8h14",b:"M1 13.5h14",l:"M2.5 1v14",v:"M8 1v14",r:"M13.5 1v14",up:"M2 14 14 2",down:"M2 2l12 12"},ue=n=>O(`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" aria-hidden="true"><path d="M2.5 2.5h11v11h-11z" stroke-dasharray="1 2" opacity="0.6"/><path d="${fe[n]}" stroke-width="1.4"/></svg>`),ge={None:'<svg width="30" height="24" viewBox="0 0 30 24" aria-hidden="true"></svg>',Outline:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M5.75 2.75h18.5v18.5H5.75z"/></svg>',Inside:'<svg width="30" height="24" viewBox="0 0 30 24" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M15 2.5v19M5.5 12h19"/></svg>'};function we(n,s,f){I();const p={t:void 0,b:void 0,l:void 0,r:void 0,h:void 0,v:void 0,up:void 0,down:void 0},r={t:n?.t??null,b:n?.b??null,l:n?.l??null,r:n?.r??null,h:null,v:null,up:n?.up?n.d:null,down:n?.down?n.d:null};let t="thin",m="#000000";const y=window.devicePixelRatio||1,v=o("canvas",{class:"fc-border-box",width:N*y,height:N*y,"aria-label":l("Border preview")});v.style.width=`${N}px`,v.style.height=`${N}px`;const h=()=>t==="none"?null:{style:t,color:m},c=()=>{const e=v.getContext("2d");e.setTransform(y,0,0,y,0,0),e.clearRect(0,0,N,N),e.fillStyle="#fff",e.fillRect(0,0,N,N),e.strokeStyle="#a0a0a0",e.lineWidth=1,e.setLineDash([]);const a=(k,A,T,R)=>{e.beginPath(),e.moveTo(k+.5,A+.5),e.lineTo(T+.5,R+.5),e.stroke()};for(const[k,A]of[[w,-1],[D,1]])for(const[T,R]of[[w,-1],[D,1]])a(k,T,k+A*5,T),a(k,T,k,T+R*5);if(s)for(const[k,A,T,R]of[[S,w,0,-5],[S,D,0,5],[w,S,-5,0],[D,S,5,0]])a(k,A,k+T,A+R);e.fillStyle="#000",e.font='13px -apple-system, "Helvetica Neue", Arial, sans-serif',e.textAlign="center",e.textBaseline="middle";const b=l("Text");if(s)for(const k of[(w+S)/2,(S+D)/2])for(const A of[(w+S)/2,(S+D)/2])e.fillText(b,A,k);else e.fillText(b,S,S);const $=(k,A,T,R,J)=>{k&&(e.strokeStyle=k.color,e.lineWidth=k.style==="double"?3:q[k.style]??1,e.setLineDash(Z[k.style]??[]),e.beginPath(),e.moveTo(A,T),e.lineTo(R,J),e.stroke())};$(r.t,w,w,D,w),$(r.b,w,D,D,D),$(r.l,w,w,w,D),$(r.r,D,w,D,D),$(r.h,w,S,D,S),$(r.v,S,w,S,D),$(r.up,w,D,D,w),$(r.down,w,w,D,D),e.setLineDash([])},u=(e,a)=>{p[e]=a,r[e]=a},C={},M=()=>{c();for(const[e,a]of Object.entries(C))a.setAttribute("aria-pressed",String(!!r[e]));f(p)},_=e=>{const a=h(),b=r[e]&&a&&r[e].style===a.style&&r[e].color===a.color;u(e,b?null:a),M()},E=(e,a)=>{const b=[["t",Math.abs(a-w)],["b",Math.abs(a-D)],["l",Math.abs(e-w)],["r",Math.abs(e-D)]];return s&&b.push(["h",Math.abs(a-S)],["v",Math.abs(e-S)]),b.sort(($,k)=>$[1]-k[1]),b[0][1]<=9?b[0][0]:Math.abs(a-e)<Math.abs(e+a-N)?"down":"up"};v.addEventListener("click",e=>{const a=v.getBoundingClientRect();_(E(e.clientX-a.left,e.clientY-a.top))});const L=(e,a,b)=>{const $=F("border",e);return o("div",{class:"fc-preset"},o("button",{type:"button","aria-label":$,title:$,disabled:!!b,on:{click:()=>{a(),M()}}},O(ge[e])),o("span",{textContent:$}))},d=(e,a,b,$,k)=>{const A=F("border",e),T=o("button",{type:"button",class:"fc-edge",title:A,"aria-label":A,"aria-pressed":"false",disabled:!!k,on:{click:()=>_(a)}},ue(a));return T.style.left=`${b}px`,T.style.top=`${$}px`,C[a]=T,T},g=o("div",{class:"fc-lines",role:"listbox","aria-label":l("Line style")}),x=pe.map(e=>{const a=o("button",{type:"button",role:"option",class:"fc-line",title:X(e),"aria-label":X(e),on:{click:()=>{t=e,P()}}},me(e));return a.dataset.style=e,a}),P=()=>{for(const e of x)e.setAttribute("aria-selected",String(e.dataset.style===t))};g.append(...x),P();const i=o("div",{class:"fc-edges"},d("Top","t",0,0),d("Horizontal","h",0,52,!s),d("Bottom","b",0,104),v,d("Diagonal Up","up",0,145),d("Left","l",40,145),d("Vertical","v",89,145,!s),d("Right","r",141,145),d("Diagonal Down","down",183,145));c();for(const[e,a]of Object.entries(C))a.setAttribute("aria-pressed",String(!!r[e]));return o("div",{class:"fc-border"},o("div",{class:"fc-border-left"},o("div",{class:"dlg-label",textContent:l("Line Style:")}),g,o("div",{class:"dlg-label",textContent:l("Line Color:")}),oe(null,"#000000",e=>{m=e??"#000000"},{label:"Line color",named:!0})),o("div",{class:"fc-border-right"},o("div",{class:"dlg-label",textContent:l("Presets:")}),o("div",{class:"fc-presets"},L("None",()=>{for(const e of Object.keys(p))u(e,null)}),L("Outline",()=>{const e=h();for(const a of["t","b","l","r"])u(a,e)}),L("Inside",()=>{const e=h();u("h",e),u("v",e)},!s)),o("hr",{class:"fc-border-rule"}),o("div",{class:"dlg-label",textContent:l("Border:")}),i),o("p",{class:"fc-hint",textContent:l("Click a line style and color, and then click a preset border pattern or individual border buttons. You can also apply borders by clicking in the preview box.")}))}function De(n,s){const{book:f,grid:p}=n;Object.values(s).some(t=>t!==void 0)&&(f.transact("borders",t=>{const{sheet:m}=t;for(const{r0:y,c0:v,r1:h,c1:c}of p.selection.ranges){const u=Math.min(h,Math.max(m.maxRow,y+1024)),C=Math.min(c,Math.max(m.maxCol,v+256));for(let M=y;M<=u;M++)for(let _=v;_<=C;_++){const E={},L=(a,b)=>{b!==void 0&&(E[a]=b)};L("t",M===y?s.t:s.h),L("b",M===u?s.b:s.h),L("l",_===v?s.l:s.v),L("r",_===C?s.r:s.v);const d=s.up,g=s.down;if(d!==void 0||g!==void 0){const a=d??g??null;d!==void 0&&(E.up=d!==null),g!==void 0&&(E.down=g!==null),E.d=a}if(Object.keys(E).length===0)continue;t.saveCell(M,_);const x=m.cellStyle(M,_)||m.style(M,_),i={...f.styles.get(x).borders??{l:null,r:null,t:null,b:null},...E};i.d&&!i.up&&!i.down&&(i.d=null);const e=!i.l&&!i.r&&!i.t&&!i.b&&!i.d;m.setStyle(M,_,f.styles.derive(x,{borders:e?null:i}))}}}),p.invalidate())}export{De as applyBorderEdges,we as borderTab,I as ensureStyles,$e as formatCodeProblem,X as lineStyleName,le as numberField,ve as numberTab,oe as paletteButton,ee as paletteGrid,ne as popButton,te as popOver,de as readFormat,O as svgNode};
|
package/cells/goto.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{el as h,openModal as O}from"../ui/dialogs.js";import{ensureBookCss as D}from"./book-css.js";import{BOOL as U,CHUNK_BITS as A,CHUNK_MASK as R,ERR as q,FORMULA as S,KIND_MASK as N,NUM as H,STR as V}from"../core/sheet.js";import{MAX_COLS as x,MAX_ROWS as j,parseRangeRef as L}from"../core/address.js";import{goToText as X,locationText as z,namedPlaces as I}from"./name-box.js";import{inRanges as $}from"./selection-modes.js";import{t as M,tc as v}from"../i18n/index.js";const T=32768;class w{constructor(){this.ranges=[],this.open=new Map,this.col=-1}add(i,a,t){const e=a*j+t,l=this.open.get(e);if(l&&l.c1===i-1){l.c1=i;return}const s={r0:a,c0:i,r1:t,c1:i};this.open.set(e,s),this.ranges.push(s)}get tooMany(){return this.ranges.length>T}}function P(r){const{grid:i,book:a}=r,{sheet:t}=a,{ranges:e}=i.selection,l=n=>({r0:n.r0,c0:n.c0,r1:Math.min(n.r1,t.maxRow),c1:Math.min(n.c1,t.maxCol)});return e.length===1&&e[0].r0===e[0].r1&&e[0].c0===e[0].c1||e.length===1&&t.mergeAt(e[0].r0,e[0].c0)?[{r0:0,c0:0,r1:Math.max(0,t.maxRow),c1:Math.max(0,t.maxCol)}]:e.map(l).filter(n=>n.r0<=n.r1&&n.c0<=n.c1)}function G(r,i,a){const t=new w;for(const e of i)for(let l=e.c0;l<=e.c1;l++){const s=r.columns[l];if(s===void 0)continue;let n=-1;for(let o=e.r0>>>A;o<=e.r1>>>A;o++){const c=s[o],f=o<<A;if(c===void 0){n>=0&&(t.add(l,n,f-1),n=-1);continue}const m=Math.max(e.r0-f,0),d=Math.min(e.r1-f,R);for(let u=m;u<=d;u++){const k=c.kinds[u];k!==0&&a(k,f+u,l,c.values[u])?n<0&&(n=f+u):n>=0&&(t.add(l,n,f+u-1),n=-1)}}n>=0&&t.add(l,n,e.r1)}return t}const _=(r,i)=>{const a=r&N;return a===H&&i.numbers||a===V&&i.text||a===U&&i.logicals||a===q&&i.errors};function Z(r,i){const a=new w;for(const t of i)for(let e=t.c0;e<=t.c1&&!a.tooMany;e++){const l=r.columns[e];if(l===void 0){a.add(e,t.r0,t.r1);continue}let s=-1;for(let n=t.r0;n<=t.r1;n++){const o=l[n>>>A];if(o===void 0){s<0&&(s=n);const c=n|R;n=Math.min(c,t.r1);continue}o.kinds[n&R]===0?s<0&&(s=n):s>=0&&(a.add(e,s,n-1),s=-1)}s>=0&&a.add(e,s,t.r1)}return a}const K=(r,i,a)=>{const t=r.rAbs0?r.r0:i+r.r0,e=r.rAbs1?r.r1:i+r.r1,l=r.cAbs0?r.c0:a+r.c0,s=r.cAbs1?r.c1:a+r.c1;return{r0:Math.min(t,e),c0:Math.min(l,s),r1:Math.max(t,e),c1:Math.max(l,s)}};function B(r,i,a,t){return i.formula(a,t)?.tpl??null}function W(r,i,a,t){const e=new Set,l=[];let s=[];for(const n of a)for(const[o]of i.formulas){const c=Math.floor(o/x),f=o-c*x;c>=n.r0&&c<=n.r1&&f>=n.c0&&f<=n.c1&&s.push([c,f])}for(let n=0;s.length>0&&n<64;n++){const o=[];for(const[c,f]of s){const m=B(r,i,c,f);if(m)for(const d of m.refs){if(d.sheet)continue;const u=K(d,c,f),k=`${u.r0},${u.c0},${u.r1},${u.c1}`;if(!e.has(k)&&(e.add(k),l.push({r0:u.r0,c0:u.c0,r1:Math.min(u.r1,j-1),c1:Math.min(u.c1,x-1)}),!!t))for(const[g]of i.formulas){const p=Math.floor(g/x),b=g-p*x;p>=u.r0&&p<=u.r1&&b>=u.c0&&b<=u.c1&&o.push([p,b])}}}if(!t)break;s=o}return l}function J(r,i,a,t){const e=new Set;let l=a;for(let o=0;l.length>0&&o<64;o++){const c=[];for(const[f]of i.formulas){if(e.has(f))continue;const m=Math.floor(f/x),d=f-m*x,u=B(r,i,m,d);if(u)for(const k of u.refs){if(k.sheet)continue;const g=K(k,m,d);if(l.some(p=>g.r0<=p.r1&&g.r1>=p.r0&&g.c0<=p.c1&&g.c1>=p.c0)){e.add(f),c.push({r0:m,c0:d,r1:m,c1:d});break}}}if(!t)break;l=c}const s=new Map;for(const o of e){const c=Math.floor(o/x),f=o-c*x;s.has(f)||s.set(f,[]),s.get(f).push(c)}const n=new w;for(const o of[...s.keys()].sort((c,f)=>c-f)){const c=s.get(o).sort((m,d)=>m-d);let f=c[0];for(let m=1;m<=c.length;m++)c[m]!==c[m-1]+1&&(n.add(o,f,c[m-1]),f=c[m])}return n.ranges}function C(r,i,a,t,e,l){const s=i.kind(a,t);return s&S?`f${r.editText(i,a,t).replace(/\$?[A-Z]{1,3}\$?\d+/g,o=>{const c=/^(\$?)([A-Z]+)(\$?)(\d+)$/.exec(o),f=c[2].split("").reduce((m,d)=>m*26+d.charCodeAt(0)-64,0)-1;return`${c[1]?`$${c[2]}`:`C[${f-t+l}]`}${c[3]?`$${c[4]}`:`R[${Number(c[4])-1-a+e}]`}`})}`:`${s&N}:${i.value(a,t)}`}function Q(r,i,a,t){const e=new w;for(const l of a)for(let s=l.c0;s<=l.c1;s++){if(s===t)continue;let n=-1;for(let o=l.r0;o<=l.r1;o++){const c=C(r,i,o,s,o,t)!==C(r,i,o,t,o,t);c&&n<0?n=o:!c&&n>=0&&(e.add(s,n,o-1),n=-1)}n>=0&&e.add(s,n,l.r1)}return e}function Y(r,i,a,t){const e=new w;for(const l of a)for(let s=l.c0;s<=l.c1;s++){const n=C(r,i,t,s,t,s);let o=-1;for(let c=l.r0;c<=l.r1;c++){const f=c!==t&&C(r,i,c,s,t,s)!==n;f&&o<0?o=c:!f&&o>=0&&(e.add(s,o,c-1),o=-1)}o>=0&&e.add(s,o,l.r1)}return e}function ee(r,i){const a=(e,l,s)=>{const n=[];let o=-1;for(let c=l;c<=s;c++){const f=e.sizeOf(c)>0;f&&o<0?o=c:!f&&o>=0&&(n.push([o,c-1]),o=-1)}return o>=0&&n.push([o,s]),n},t=[];for(const e of i){const l=a(r.rows,e.r0,Math.min(e.r1,Math.max(r.maxRow,e.r0))),s=a(r.cols,e.c0,Math.min(e.c1,Math.max(r.maxCol,e.c0)));for(const[n,o]of l)for(const[c,f]of s)t.push({r0:n,c0:c,r1:o,c1:f})}return t}const E=r=>(r??"").split(/\s+/).map(L).filter(Boolean);function te(r,{same:i},a,t){const e=[];for(const l of r.cf??[]){const s=E(l.sqref);(!i||$(s,a,t))&&e.push(...s)}return e}function ne(r,{same:i},a,t){const e=[];for(const l of r.validations??[]){const s=E(l.sqref);(!i||$(s,a,t))&&e.push(...s)}return e}function oe(r){const{book:i,grid:a}=r,{sheet:t}=i,{row:e,col:l}=a.selection,s=(o,c)=>{const f=t.formula(o,c);return f&&f.t==="array"&&f.ref?L(f.ref):null};let n=s(e,l);if(!n&&i.engine?.spillMaster){const o=i.engine.spillMaster(t,e,l);o&&(n=s(o.row,o.col)??null)}return n}function se(r,i,a={}){const{book:t,grid:e,controller:l,shell:s}=r,{sheet:n}=t,{row:o,col:c}=e.selection,f=P(r),m={numbers:a.numbers!==!1,text:a.text!==!1,logicals:a.logicals!==!1,errors:a.errors!==!1};let d=[];switch(i){case"notes":{const g=new w,p=[...n.comments?.keys()??[]].map(b=>[b%x,Math.floor(b/x)]).sort((b,y)=>b[0]-y[0]||b[1]-y[1]);for(const[b,y]of p)g.add(b,y,y);d=g.ranges;break}case"constants":d=G(n,f,g=>!(g&S)&&_(g,m)).ranges;break;case"formulas":d=G(n,f,g=>g&S&&_(g,m)).ranges;break;case"blanks":d=Z(n,f).ranges;break;case"region":{d=[r.commands._currentRegion(o,c)??{r0:o,c0:c,r1:o,c1:c}];break}case"array":{const g=oe(r);d=g?[g]:[];break}case"objects":{const p=(r.objects?._state?.(n)?.objects??[]).filter(b=>!b.hidden&&b.kind!=="foreign");if(p.length>0){r.objects.select(p[0]);for(const b of p.slice(1))r.objects.select(b,{add:!0});s.setStatus(M("{count} objects selected.",{count:p.length}))}else s.setStatus(M("There are no objects on this sheet."));return}case"rowDiff":d=Q(t,n,f,c).ranges;break;case"colDiff":d=Y(t,n,f,o).ranges;break;case"precedents":case"precedentsAll":d=W(t,n,e.selection.ranges,i==="precedentsAll");break;case"dependents":case"dependentsAll":d=J(t,n,e.selection.ranges,i==="dependentsAll");break;case"lastCell":d=[{r0:Math.max(n.maxRow,0),c0:Math.max(n.maxCol,0),r1:Math.max(n.maxRow,0),c1:Math.max(n.maxCol,0)}];break;case"visible":d=ee(n,e.selection.ranges.length===1&&e.selection.ranges[0].r0===e.selection.ranges[0].r1&&e.selection.ranges[0].c0===e.selection.ranges[0].c1?f:e.selection.ranges);break;case"cf":d=te(n,a,o,c);break;case"validation":d=ne(n,a,o,c);break;default:return}if(d.length===0){s.setStatus(M("No cells were found."));return}if(d.length>T){s.setStatus(M("That selection is too large: more than {count} separate areas.",{count:T.toLocaleString("en-US")}));return}const u=d[0],k=$(d,o,c);e.setSelection({ranges:d,row:k?o:u.r0,col:k?c:u.c0}),l.extent={row:u.r1,col:u.c1},k||e.ensureVisible(u.r0,u.c0)}function ce(r){D();const i="bk-special";let a="notes";const t=(p,b,y=!1)=>{const F=h("input",{type:"radio",name:i,value:p,checked:y,on:{change:()=>{a=p,k()}}});return h("label",{class:"dlg-row dlg-check"},F,` ${v("special",b)}`)},e={numbers:h("input",{type:"checkbox",checked:!0}),text:h("input",{type:"checkbox",checked:!0}),logicals:h("input",{type:"checkbox",checked:!0}),errors:h("input",{type:"checkbox",checked:!0})},l=h("input",{type:"radio",name:"bk-depth",checked:!0}),s=h("input",{type:"radio",name:"bk-depth"}),n=h("input",{type:"radio",name:"bk-same",checked:!0}),o=h("input",{type:"radio",name:"bk-same"}),c=(p,b)=>h("label",{class:"dlg-row dlg-check"},p,` ${v("special",b)}`),f=h("div",{class:"bk-special-opts"},c(e.numbers,"Numbers"),c(e.text,"Text"),c(e.logicals,"Logicals"),c(e.errors,"Errors")),m=h("div",{class:"bk-special-opts"},c(l,"Direct only"),c(s,"All levels")),d=h("div",{class:"bk-special-opts"},c(n,"All"),c(o,"Same")),u=h("p",{class:"bk-special-none",textContent:M("There are no options for this selection.")}),k=()=>{f.hidden=a!=="constants"&&a!=="formulas",m.hidden=a!=="precedents"&&a!=="dependents",d.hidden=a!=="cf"&&a!=="validation",u.hidden=!(f.hidden&&m.hidden&&d.hidden)},g=h("div",{class:"bk-special"},h("div",{class:"xl-head dlg-label",textContent:v("special","Select")}),h("div",{class:"bk-grid2"},h("div",{},t("notes","Notes",!0),t("constants","Constants"),t("formulas","Formulas"),t("blanks","Blanks"),t("region","Current region"),t("array","Current array"),t("rowDiff","Row differences"),t("colDiff","Column differences")),h("div",{},t("precedents","Precedents"),t("dependents","Dependents"),t("lastCell","Last cell"),t("visible","Visible cells only"),t("objects","Objects"),t("cf","Conditional formats"),t("validation","Data validation"))),h("hr",{class:"xl-rule"}),h("div",{class:"xl-head dlg-label",textContent:M("Options")}),h("div",{class:"bk-special-low"},f,m,d,u));k(),O(r,v("dlg","Go To Special"),g,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{let p=a;(p==="precedents"||p==="dependents")&&s.checked&&(p+="All"),se(r,p,{numbers:e.numbers.checked,text:e.text.checked,logicals:e.logicals.checked,errors:e.errors.checked,same:o.checked})}}],{width:334,className:"xl-dlg"})}function he(r){const{book:i,grid:a}=r,t=i.gotoHistory??=[],e=h("select",{class:"dlg-list bk-goto-list",size:8,"aria-label":M("Go to")});for(const o of I(i))e.append(h("option",{value:o.label,textContent:o.label}));for(const o of t.slice().reverse())e.append(h("option",{value:o,textContent:o}));const l=h("input",{class:"dlg-input","aria-label":M("Reference"),spellcheck:!1,value:t[t.length-1]??""});e.addEventListener("change",()=>{l.value=e.value}),e.addEventListener("dblclick",()=>{s()&&n.close()});const s=()=>{const o=z(i,a.selection);return X(r,l.value)?(t[t.length-1]!==o&&t.push(o),t.length>32&&t.shift(),!0):(l.select(),!1)};D();const n=O(r,v("dlg","Go To"),h("div",{class:"dlg-col"},h("div",{class:"dlg-label",textContent:M("Go to:")}),e,h("label",{class:"bk-above"},h("span",{textContent:M("Reference:")}),l)),[{label:"Special…",left:!0,action:()=>{queueMicrotask(()=>ce(r))}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>s()}],{width:326,className:"xl-dlg"});l.focus(),l.select()}export{ce as goToSpecial,he as openGoTo,se as selectSpecial};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registerSection as h}from"./sections.js";import{el as d,openModal as g}from"../ui/dialogs.js";import{t as u}from"../i18n/index.js";const w=/^#[0-9a-fA-F]{6}$/;function C(o,e,r,a,t,l){o.transact("header-colors",()=>{const c=e.headerColors??null,s={col:new Map(c?.col),row:new Map(c?.row)};for(let n=a;n<=t;n++)l===null?s[r].delete(n):s[r].set(n,l);e.headerColors=s.col.size>0||s.row.size>0?s:null,o.dirty=!0;const i=n=>f=>{const p=f.headerColors;return f.headerColors=n,i(p)};return i(c)})}function y(o,e){if(!o)return o??null;const r=new Map;for(const[t,l]of o[e.axis])t<e.at?r.set(t,l):(e.n>0||t>=e.at-e.n)&&r.set(t+e.n,l);const a={...o,[e.axis]:r};return a.col.size>0||a.row.size>0?a:null}function z(o,e,r,a){const{book:t,grid:l}=o,{sheet:c}=t,s=c.headerColors?.[e].get(r),i=d("input",{type:"color",class:"dlg-color",value:(s?.fill??"#FFF2CC").toLowerCase(),"aria-label":u("Header background")}),n=d("input",{type:"color",class:"dlg-color",value:(s?.color??"#000000").toLowerCase(),"aria-label":u("Header text color")});g(o,e==="col"?"Column Header Color":"Row Header Color",d("div",{class:"dlg-form"},d("label",{class:"dlg-row"},`${u("Background:")} `,i),d("label",{class:"dlg-row"},`${u("Text:")} `,n)),[{label:"Clear",action:()=>{C(t,c,e,r,a,null),l.invalidate()}},{label:"Cancel"},{label:"OK",primary:!0,action:()=>{C(t,c,e,r,a,{fill:i.value.toUpperCase(),color:n.value.toUpperCase()}),l.invalidate()}}],{width:300})}const b=o=>{const e={};return w.test(o?.fill)&&(e.fill=o.fill),w.test(o?.color)&&(e.color=o.color),e};h("headerColors",{sheet:{save(o){const e=o.headerColors;return e?{col:[...e.col],row:[...e.row]}:void 0},load(o,e){const r=t=>new Map((Array.isArray(t)?t.slice(0,2e4):[]).filter(l=>Number.isInteger(l?.[0])&&l[0]>=0).map(l=>[l[0],b(l[1])])),a={col:r(e?.col),row:r(e?.row)};(a.col.size>0||a.row.size>0)&&(o.headerColors=a)}}});export{z as openHeaderColors,C as setHeaderColors,y as shiftHeaderColors};
|
package/cells/mask.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const x=s=>/^\p{L}$/u.test(s),M=s=>s>="0"&&s<="9",v=new Map,C=new Map;function $(s,n){/^[\w-]+$/.test(s)&&C.set(s,n),v.clear()}const D=/yyyy|yy|MM|M|dd|d|HH|H|hh|h|mm|m|ss|s|tt|t/g,N=s=>/yy|MM|dd|HH|hh|ss|tt/.test(s)&&!/[a0#<>[\](){}\\]/.test(s.replace(/yyyy|yy|MM|M|dd|d|HH|H|hh|h|mm|m|ss|s|tt|t/g,""));function P(s){const n=[];let r=0;const i=l=>{const e=(t,a,h,f)=>({type:"set",test:M,min:t,max:t,range:a===void 0?null:[a,h],part:f});switch(l){case"yyyy":return e(4,void 0,void 0,"y");case"yy":return e(2,void 0,void 0,"y");case"MM":case"M":return e(2,1,12,"M");case"dd":case"d":return e(2,1,31,"d");case"HH":case"H":return e(2,0,23);case"hh":case"h":return e(2,1,12);case"mm":case"m":case"ss":case"s":return e(2,0,59);default:return{type:"alt",options:l==="t"?["A","P"]:["AM","PM"]}}};for(const l of s.matchAll(D)){for(const e of s.slice(r,l.index))n.push({type:"lit",ch:e});n.push(i(l[0])),r=l.index+l[0].length}for(const l of s.slice(r))n.push({type:"lit",ch:l});return n}function A(s){const n=[];for(let e=0;e<s.length;e++)s[e]==="\\"&&e+1<s.length?n.push([s[++e],s[e]]):s[e+1]==="-"&&e+2<s.length?(n.push([s[e],s[e+2]]),e+=2):n.push([s[e],s[e]]);const r=n.some(([e,t])=>e==="a"&&t==="a"),i=n.some(([e,t])=>e==="0"&&t==="0"),l=n.some(([e,t])=>e==="#"&&t==="#");return e=>l||r&&x(e)||i&&M(e)||n.some(([t,a])=>e>=t&&e<=a)}function L(s){let n=s;for(const[i,l]of C)n=n.split(i).join(l);let r=v.get(n);if(r!==void 0)return r;if(r=[],N(n))r=P(n);else for(let i=0;i<n.length;i++){const l=n[i];let e;if(l==="\\"&&i+1<n.length)e={type:"lit",ch:n[++i]};else if(l==="a")e={type:"set",test:x};else if(l==="0")e={type:"set",test:M};else if(l==="#")e={type:"set",test:()=>!0};else if(l===">")e={type:"set",test:x,conv:t=>t.toUpperCase()};else if(l==="<")e={type:"set",test:x,conv:t=>t.toLowerCase()};else if(l==="["&&n.indexOf("]",i)>i){const t=n.indexOf("]",i);e={type:"set",test:A(n.slice(i+1,t))},i=t}else if(l==="("&&/\|/.test(n.slice(i,n.indexOf(")",i)))){const t=n.indexOf(")",i);r.push({type:"alt",options:n.slice(i+1,t).split("|")}),i=t;continue}else e={type:"lit",ch:l};if(e.type==="set"){e.min=1,e.max=1;const t=/^\{(\d*)(,?)(\d*)\}/.exec(n.slice(i+1));t&&(e.min=t[1]===""?0:Number(t[1]),e.max=t[2]===""?e.min:t[3]===""?2147483648:Number(t[3]),i+=t[0].length)}r.push(e)}return v.set(n,r),r}function w(s,n,r,i,l){if(l.pattern[0]!=="=")return l;try{let e=s.engine.template(l.pattern.slice(1),r,i).fn(r,i,n);return e&&e.sheet&&(e=s.engine.refAuto(e,r,i)),typeof e=="string"&&O(e)?{...l,pattern:e}:null}catch{return null}}function O(s){try{return L(s).some(n=>n.type!=="lit")}catch{return!1}}function S(s,n,r=n.length){const i=s.placeholder??"_",l=L(s.pattern);let e=0,t="",a="",h=-1;const f={},H=()=>{for(;e<n.length&&n[e]===i;)e++;return e<n.length?n[e]:""},g=()=>{h<0&&e>=r&&(h=t.length)};for(const o of l)if(o.type==="lit")g(),H()===o.ch&&e++,t+=o.ch,s.excludeLiteral||(a+=o.ch),g();else if(o.type==="alt"){g();const c=n.slice(e).toLowerCase(),u=o.options.find(p=>c.startsWith(p.toLowerCase()));u?(e+=u.length,t+=u,a+=u):o.options.find(d=>c&&d.toLowerCase().startsWith(c))&&(t+=n.slice(e),a+=n.slice(e),e=n.length),g()}else{let c=0;for(;c<o.max;){g();const u=H();if(u==="")break;const p=l[l.indexOf(o)+1];if(c>=o.min&&p?.type==="lit"&&u===p.ch)break;if(e++,!o.test(u))continue;let d=o.conv?o.conv(u):u;if(o.range&&c===o.max-1){const m=Number(t.slice(t.length-c)+d);if(m>o.range[1]){t=t.slice(0,t.length-c),a=a.slice(0,a.length-c);const y=String(o.range[1]);t+=y.slice(0,c),a+=y.slice(0,c),d=y.slice(c)}else if(m<o.range[0]&&c===o.max-1){t=t.slice(0,t.length-c),a=a.slice(0,a.length-c);const y=String(o.range[0]).padStart(o.max,"0");t+=y.slice(0,c),a+=y.slice(0,c),d=y.slice(c)}}t+=d,a+=d,c++}g(),o.part&&c===o.max&&(f[o.part]={text:t.length-c,value:a.length-c,count:c});for(let u=c;u<o.min;u++)t+=i,s.excludePlaceholder||(a+=i)}if(h<0&&(h=t.length),f.d&&f.M){const o=Number(t.slice(f.M.text,f.M.text+f.M.count)),c=f.y?Number(t.slice(f.y.text,f.y.text+f.y.count)):2e3,u=f.y&&f.y.count===2?2e3+c:c,p=new Date(Date.UTC(u,o,0)).getUTCDate();if(Number(t.slice(f.d.text,f.d.text+2))>p){const m=String(p).padStart(2,"0");t=t.slice(0,f.d.text)+m+t.slice(f.d.text+2),a=a.slice(0,f.d.value)+m+a.slice(f.d.value+2)}}const k=/[^\s]/.test(n.replace(new RegExp(`[${T(i)}]`,"g"),""))&&a!=="";return{text:t,caret:h,value:k?a:""}}const T=s=>s.replace(/[\]\\^-]/g,"\\$&");function E(s,n){const{value:r}=S(s,n);return/^[=+-]/.test(r)?`'${r}`:r}export{E as maskedEntry,$ as namedPattern,w as resolveMask,S as shapeMasked,O as validatePattern};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ensureBookCss as f}from"./book-css.js";import{t as u}from"../i18n/index.js";import{keyText as l}from"../i18n/key-text.js";function p(m,e,t){if(f(),t.title&&(e.title=u(t.title)),t.disabled&&(e.disabled=!0),t.checked!==void 0){const i=()=>String(!!(typeof t.checked=="function"?t.checked():t.checked));e.setAttribute("role","menuitemcheckbox"),e.setAttribute("aria-checked",i())}if(t.kbd){const i=document.createElement("span");i.className="bk-kbd",i.textContent=l(t.kbd),e.append(i)}if(!t.items)return!1;e.classList.add("bk-sub"),e.setAttribute("aria-haspopup","menu");let r=null;const s=()=>{for(const n of e.parentElement.querySelectorAll(":scope > .bk-sub-menu"))n.remove();for(const n of e.parentElement.querySelectorAll(":scope > .bk-sub"))n.setAttribute("aria-expanded",String(n===e));const i=typeof t.items=="function"?t.items():t.items;r=m.buildMenu(i),r.classList.add("bk-sub-menu"),e.parentElement.append(r);const c=e.getBoundingClientRect(),d=r.getBoundingClientRect(),a=r.currentCSSZoom??1;r.style.left=`${(c.right+d.width+2>window.innerWidth?c.left-d.width-2:c.right+2)/a}px`,r.style.top=`${Math.max(4,Math.min(c.top-4,window.innerHeight-d.height-6))/a}px`};return e.addEventListener("pointerenter",s),e.addEventListener("click",s),!0}export{p as decorateMenuItem,l as keyText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{icon as w}from"../ui/icons.js";import{cellRef as C,MAX_COLS as L,MAX_ROWS as N,parseRangeRef as E,rangeRef as S,sheetPrefix as p}from"../core/address.js";import{viewGet as R,viewOf as M}from"./book-view.js";import{layoutApp as B}from"./view-options.js";import{t as d}from"../i18n/index.js";import{bindText as x}from"../i18n/dom.js";const y=t=>t.replace(/^'|'$/g,"").replace(/''/g,"'");function b(t,n){const s=/^(?:('(?:[^']|'')+'|[^!'(),=+\-*/ ]+)!)?(\$?[A-Za-z]{0,3}\$?\d*(?::\$?[A-Za-z]{0,3}\$?\d*)?)$/.exec(n.trim());if(!s||!s[2])return null;const e=E(s[2]);if(!e)return null;const o=s[1]?t.sheets.find(r=>r.name.toLowerCase()===y(s[1]).toLowerCase()):t.sheet;return o?{sheet:o,range:e}:null}function f(t,n){return n.cachedFor!==n.text&&(n.cachedFor=n.text,n.cachedTarget=b(t,n.text)),n.cachedTarget}const $=(t,n)=>t.r0===n.r0&&t.c0===n.c0&&t.r1===n.r1&&t.c1===n.c1;function P(t,n,s){const{engine:e}=t;if(!e||s.ranges.length!==1)return null;const o=s.ranges[0];if(e.names.size>0)for(const r of e.names.values()){if(r.hidden)continue;const a=f(t,r);if(a&&a.sheet===n&&$(a.range,o))return r.name}if(e.tables.size>0){for(const r of e.tables.values())if(r.sheet===n&&$(r,o))return r.name}return null}function A(t){const{engine:n}=t,s=[];if(!n)return s;for(const[e,o]of n.names){if(o.hidden)continue;const r=e.indexOf("!"),a=r>=0?Number(e.slice(0,r)):-1;a>=0&&a!==t.activeSheet||f(t,o)&&s.push({label:o.name??e,kind:"name"})}for(const e of n.tables.values())s.push({label:e.name,kind:"table"});return s.sort((e,o)=>e.label.localeCompare(o.label))}function T(t,n){const{engine:s}=t,e=n.trim().toUpperCase();if(!s||!e)return null;const o=s.names.get(`${t.activeSheet}!${e}`)??s.names.get(e);if(o)return f(t,o);for(const r of s.tables.values())if(r.name.toUpperCase()===e)return{sheet:r.sheet,range:{r0:r.r0,c0:r.c0,r1:r.r1,c1:r.c1}};return null}function k(t){const n=/^R(\d+)C(\d+)(?::R(\d+)C(\d+))?$/i.exec(t.trim());if(!n)return null;const s=Number(n[1])-1,e=Number(n[2])-1,o=n[3]?Number(n[3])-1:s,r=n[4]?Number(n[4])-1:e;return s<0||e<0||o>=N||r>=L?null:{r0:Math.min(s,o),c0:Math.min(e,r),r1:Math.max(s,o),c1:Math.max(e,r)}}const O=/^[\p{L}_\\][\p{L}\p{N}_.\\]*$/u,_=/^[A-Za-z]{1,3}\d+$|^[Rr]\d*[Cc]\d*$|^[RrCc]$/;function z(t,n){const{book:s,grid:e}=t,o=e.selection.ranges[e.selection.ranges.length-1],r=(l,c)=>C(l,c).replace(/^([A-Z]+)(\d+)$/,"$$$1$$$2"),a=`${p(s.sheet.name)}${r(o.r0,o.c0)}${o.r0===o.r1&&o.c0===o.c1?"":`:${r(o.r1,o.c1)}`}`;s.engine.names.set(n.toUpperCase(),{text:a,name:n}),s.engine.nameTemplates.clear(),s.namesChanged=!0,s.dirty=!0,s.engine.rebuild(),t.shell.setStatus(d("Defined {name} as {refers}",{name:n,refers:a})),t.controller.syncNameBox()}function D(t,n,{allowCreate:s=!1}={}){const{book:e,grid:o,controller:r}=t,a=n.split(/[,;]/).map(i=>i.trim()).filter(Boolean);if(a.length===0)return r.syncNameBox(),!1;const l=[];for(const i of a){const h=k(i),g=h?{sheet:e.sheet,range:h}:b(e,i)??T(e,i);if(!g){const v=e.engine?.names.has(`${e.activeSheet}!${i.toUpperCase()}`)||e.engine?.names.has(i.toUpperCase());return s&&!v&&a.length===1&&O.test(i)&&!_.test(i)?(z(t,i),!0):(t.shell.setStatus(d('"{text}" is not a valid reference or name',{text:i})),r.syncNameBox(),!1)}l.push(g)}const{sheet:c}=l[0];if(c!==e.sheet){const i=e.sheets.indexOf(c);if(c.hidden||i<0)return t.shell.setStatus(d('"{name}" is hidden',{name:c.name})),!1;e.selectedSheets&&!e.selectedSheets.has(c)&&(e.selectedSheets=null),t.switchSheet(i)}const m=l.filter(i=>i.sheet===c).map(i=>i.range),u=m[m.length-1];return o.setSelection({ranges:m,row:u.r0,col:u.c0}),r.extent={row:u.r1,col:u.c1},o.ensureVisible(u.r0,u.c0),r.syncNameBox(),!0}function q(t,n){return`${p(t.sheet.name)}${n.ranges.map(S).join(",")}`}function K(t){const n=t.el("name-box")?.parentElement;if(!n||n.querySelector(".bk-name-drop"))return;const s=document.createElement("button");s.className="bk-name-drop",x(s,{title:"Names and tables","aria-label":"Names and tables"}),s.innerHTML=w("caret",8),s.addEventListener("pointerdown",r=>r.preventDefault()),s.addEventListener("click",()=>{const r=n.getBoundingClientRect(),a=A(t.book).map(l=>[l.label,()=>D(t,l.label),{raw:!0}]);t.ribbon.openMenuAt(r.left,r.bottom+2,{items:a.length?a:[["No names defined",()=>{},{disabled:!0}]]})});const e=document.createElement("div");e.className="bk-name-grip",x(e,{title:"Drag to resize the name box"}),e.addEventListener("pointerdown",r=>{r.preventDefault(),e.setPointerCapture(r.pointerId);const a=r.clientX,l=n.getBoundingClientRect().width,c=u=>{const i=Math.max(60,Math.min(window.innerWidth*.6,l+u.clientX-a));n.style.width=`${i}px`,M(t.book).nameBoxWidth=Math.round(i)},m=()=>{e.removeEventListener("pointermove",c),e.removeEventListener("pointerup",m),B(t)};e.addEventListener("pointermove",c),e.addEventListener("pointerup",m)}),n.style.width=`${R(t.book,"nameBoxWidth")}px`,n.append(s,e);const o=t.el("name-box");o.style.flex="1",o.style.minWidth="0",o.addEventListener("pointerdown",r=>{r.button!==0||document.activeElement===o||(r.preventDefault(),o.focus(),o.select())}),o.addEventListener("blur",()=>{t.controller.isEditing||t.controller.syncNameBox()})}export{D as goToText,K as installNameBox,q as locationText,P as nameForSelection,A as namedPlaces};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MAX_COLS as y}from"../core/address.js";import{escapeMarkup as p}from"../io/xml-escape.js";const C=108,A=60;function S(o,l){const t=o.style,r=`<t xml:space="preserve">${l(o.text)}</t>`;return!t||!t.fontSize&&!t.bold&&!t.italic&&!t.color&&!t.fontName?r:`<r><rPr>${`${t.bold?"<b/>":""}${t.italic?"<i/>":""}<sz val="${t.fontSize??10}"/>${t.color?`<color rgb="FF${t.color.slice(1)}"/>`:""}<rFont val="${p(t.fontName??"Tahoma")}"/>`}</rPr>${r}</r>`}function O(o){const l=[];if(!o.comments)return l;for(const[t,r]of o.comments){if(!r.box){l.push(r);continue}const s=Math.floor(t/y),f=t-s*y,e=r.box,c=o.cols.offsetOf(f+1)+e.dx,i=Math.max(0,o.rows.offsetOf(s)+e.dy),x=o.cols.indexAt(c),a=o.rows.indexAt(i),n=o.cols.indexAt(c+e.w),u=o.rows.indexAt(i+e.h),h=[x,Math.round(c-o.cols.offsetOf(x)),a,Math.round(i-o.rows.offsetOf(a)),n,Math.round(c+e.w-o.cols.offsetOf(n)),u,Math.round(i+e.h-o.rows.offsetOf(u))];l.push({...r,anchor:h.join(", ")})}return l}function L(o,l,t,r){const s=o.box?.w??C,f=o.box?.h??A,e=o.style??{},c=p((e.backColor??"#ffffe1").toLowerCase()),i=e.borderColor?` strokecolor="${p(e.borderColor.toLowerCase())}"`:"",x=e.borderWidth!==void 0?` strokeweight="${e.borderWidth}pt"`:"",a=e.borderStyle&&e.borderStyle!=="solid"?`<v:stroke dashstyle="${e.borderStyle==="dashed"?"dash":"dot"}"/>`:"",n=p(e.align??"left");return`<v:shape id="_x0000_s${l}" type="#_x0000_t202" style="position:absolute;margin-left:60pt;margin-top:2pt;width:${s}pt;height:${f}pt;z-index:${t};visibility:${o.visible?"visible":"hidden"}" fillcolor="${c}"${i}${x} o:insetmode="auto"><v:fill color2="${c}"/>${a}<v:shadow on="t" color="black" obscured="t"/><v:path o:connecttype="none"/><v:textbox style="mso-direction-alt:auto"><div style="text-align:${n}"></div></v:textbox><x:ClientData ObjectType="Note">${o.dynamicMove===!0?"":"<x:MoveWithCells/>"}${o.dynamicSize===!0?"":"<x:SizeWithCells/>"}${o.anchor?`<x:Anchor>${o.anchor}</x:Anchor>`:""}${o.locked===!1?"<x:Locked>False</x:Locked>":""}${o.lockText===!1?"<x:LockText>False</x:LockText>":""}<x:AutoFill>False</x:AutoFill><x:Row>${r.r0}</x:Row><x:Column>${r.c0}</x:Column>${o.visible?"<x:Visible/>":""}</x:ClientData></v:shape>`}function M(o,l){let t=!1;for(const r of l.matchAll(/<v:shape\b[\s\S]*?<\/v:shape>/g)){const s=r[0];if(!/ObjectType="Note"/.test(s))continue;const f=Number(/<x:Row>(\d+)<\/x:Row>/.exec(s)?.[1]),e=Number(/<x:Column>(\d+)<\/x:Column>/.exec(s)?.[1]);if(!Number.isFinite(f)||!Number.isFinite(e))continue;const c=f*y+e,i=o.comments.get(c);if(!i)continue;const x=/<v:shape\b[^>]*\bstyle=['"]([^'"]*)['"]/.exec(s)?.[1]??"",a=$=>{const w=new RegExp(`(?:^|;)\\s*${$}:\\s*([\\d.]+)(pt|px|in)?`).exec(x);return w?Number(w[1])*(w[2]==="in"?72:1):null},n={...i},u=a("width"),h=a("height"),d=/<x:Anchor>([^<]*)<\/x:Anchor>/.exec(s)?.[1]?.split(",").map($=>Number($.trim()));let v=12,k=-6;d?.length===8&&(v=o.cols.offsetOf(d[0])+d[1]-o.cols.offsetOf(e+1),k=o.rows.offsetOf(d[2])+d[3]-o.rows.offsetOf(f)),n.box={dx:v,dy:k,w:u??C,h:h??A},/<x:Visible\s*\/?>/.test(s)&&(n.visible=!0,t=!0);const b=/\bfillcolor=['"](#[0-9a-fA-F]{6})/.exec(s)?.[1],m=/\bstrokecolor=['"](#[0-9a-fA-F]{6})/.exec(s)?.[1];(b&&b.toLowerCase()!=="#ffffe1"||m)&&(n.style={...i.style??{},...b?{backColor:b.toUpperCase()}:{},...m?{borderColor:m.toUpperCase()}:{}}),/<x:MoveWithCells/.test(s)||(n.dynamicMove=!0),/<x:SizeWithCells/.test(s)||(n.dynamicSize=!0),/<x:Locked>False/.test(s)&&(n.locked=!1),/<x:LockText>False/.test(s)&&(n.lockText=!1),o.comments.set(c,n)}t&&(o.notesShown=!0)}export{M as applyNoteShapes,L as noteShapeXml,S as noteTextXml,O as notesWithAnchors};
|
package/cells/options.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{el as o,openModal as b}from"../ui/dialogs.js";import{t as n}from"../i18n/index.js";const p="sheets.editOptions",g={dragDrop:!0,dragMerge:!1,dragHeaders:"none",alertOverwrite:!0,pasteButton:!0,fillButton:!0,skipHidden:!1,editInCell:!0,editOnSelect:!1,selectAllOnEdit:!1,autoPercent:!0,autoComplete:!0,numbersOverflow:!1,tableDragShift:!1,copyHeaders:"none"};let r=null;function i(){if(r)return r;let t=null;try{t=JSON.parse(localStorage.getItem(p))}catch{t=null}return r={...g,...t&&typeof t=="object"?t:{}},r}function v(t,e){return t?.optionOverrides?.[e]??i()[e]}function f(t,e){i()[t]=e;try{localStorage.setItem(p,JSON.stringify(r))}catch{}}function y(t){const e=(l,a)=>{const u=o("input",{type:"checkbox",checked:i()[l],"aria-label":n(a)});return u.dataset.option=l,o("label",{class:"dlg-row"},u,` ${n(a)}`)},s=o("select",{class:"dlg-input","aria-label":n("Copy takes headers")},...[["None","none"],["Row headers","row"],["Column headers","col"],["All","all"]].map(([l,a])=>o("option",{value:a,textContent:n(l)})));s.value=i().copyHeaders;const c=o("input",{type:"checkbox",checked:t.book.sheet.noCellOverflow!==!0,"aria-label":n("Overflow")}),h=o("label",{class:"dlg-row"},c,` ${n("Text overflows into empty cells on this sheet")}`),d=o("div",{},e("editInCell","Allow editing directly in cells"),e("editOnSelect","Start editing as soon as a cell is selected"),e("selectAllOnEdit","Select all the text when editing starts"),e("autoPercent","Enable automatic percent entry"),e("autoComplete","Enable AutoComplete for cell values"),e("numbersOverflow","Let numbers too wide for a column spill into empty cells (not in Excel)"),e("dragDrop","Enable fill handle and cell drag-and-drop"),e("alertOverwrite","Alert before overwriting cells"),e("pasteButton","Show Paste Options button after content is pasted"),e("fillButton","Show Auto Fill Options button after a fill"),e("skipHidden","Paste skips hidden rows and columns"),e("tableDragShift","Dragging whole table rows shifts cells instead of overwriting"),o("label",{class:"dlg-row"},`${n("Copy takes headers:")} `,s),h);b(t,"Editing Options",d,[{label:"Cancel"},{label:"OK",primary:!0,action:()=>{for(const l of d.querySelectorAll("input[data-option]"))f(l.dataset.option,l.checked);f("copyHeaders",s.value),t.book.sheet.noCellOverflow=c.checked?void 0:!0,t.book.dirty=!0,t.grid.invalidate()}}],{width:420})}export{i as editOptions,y as openEditOptions,v as optionFor,f as setEditOption};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{maxOutlineLevel as ft,outlineLevel as M}from"../core/whatif.js";import{MAX_COLS as X,MAX_ROWS as $}from"../core/address.js";import{registerSection as Q}from"./sections.js";const z=14,j=new WeakMap;function x(t,e){const o=e==="row"?t.rowExtras:t.colExtras;if(o===null)return 0;let l=j.get(t);l===void 0&&(l={},j.set(t,l));let r=l[e];if((r===void 0||r.map!==o||r.version!==(t.outlineVersion??0)||r.size>o.size)&&(r={map:o,version:t.outlineVersion??0,size:0,it:o.values(),max:0},l[e]=r),r.size!==o.size)for(;;){const n=r.it.next();if(n.done)break;r.size++;const i=n.value.indexOf('outlineLevel="');i>=0&&(r.max=Math.max(r.max,Number(n.value.charCodeAt(i+14)-48)))}return r.max}function bt(t,e){const o=t.rows.count,l=t.cols.count;return o===$&&l===X||e.row<o&&e.col<l?e:{...e,row:Math.min(e.row,o-1),col:Math.min(e.col,l-1),ranges:e.ranges.map(r=>({...r,r0:Math.min(r.r0,o-1),c0:Math.min(r.c0,l-1),r1:r.r1===$-1?r.r1:Math.min(r.r1,o-1),c1:r.c1===X-1?r.c1:Math.min(r.c1,l-1)}))}}const tt=t=>{t.outlineVersion=(t.outlineVersion??0)+1};function Mt(t,e){const o=x(t,e);return o===0?0:(o+1)*z+4}const E=(t,e)=>e==="row"?t.summaryAbove===!0:t.summaryLeft===!0;function et(t,e,o,l){const r=e==="row"?t.rows:t.cols,n=[],i=[],c=(w,f)=>{for(;i.length>=w;){const a=i.pop();a.end=f,n.push(a)}};let m=o;const d=Math.max(0,o-2e4);for(;m>d&&M(t,e,m-1)>0;)m--;const u=Math.min(r.count-1,l+2e4);let p=m;for(;p<=u;p++){const w=M(t,e,p);for(w<i.length&&c(w+1,p-1);i.length<w;)i.push({level:i.length+1,start:p,end:-1});if(w===0&&p>l)break}return c(1,p-1),n.filter(w=>w.end>=o-1&&w.start<=l+1)}function yt(t,e){const{sheet:o,dpr:l,theme:r}=e,n=h=>Math.round(h*l),i=e.gutterW,c=e.gutterH,m=e.rowHeaderW,d=e.colHeaderH,u=e.book.outlineStyle,p=u?.ink??r.headerInk,w=u?.bg??r.headerBg,f=u?.button??w,a=u?.line??p;t.fillStyle=w,i>0&&t.fillRect(0,0,n(i),n(e.cssH)),c>0&&t.fillRect(0,0,n(e.cssW),n(c));const s=11,C=(h,v,y)=>{t.fillStyle=f,t.strokeStyle=a,t.lineWidth=Math.max(1,Math.round(l/2)),t.fillRect(n(h),n(v),n(s),n(s)),t.strokeRect(n(h)+.5,n(v)+.5,n(s)-1,n(s)-1),t.fillStyle=p;const g=u&&(y==="+"?u.plusImage:y==="-"?u.minusImage:null),R=g?Z(e,g):null;R?t.drawImage(R,n(h),n(v),n(s),n(s)):y==="+"||y==="-"?(t.fillRect(n(h+2.5),n(v+s/2)-.5,n(s-5),Math.max(1,Math.round(l))),y==="+"&&t.fillRect(n(h+s/2)-.5,n(v+2.5),Math.max(1,Math.round(l)),n(s-5))):(t.font=`${n(9)}px -apple-system, "Helvetica Neue", Arial, sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(y,n(h+s/2),n(v+s/2)+.5))},S=h=>{const v=h==="row",y=x(o,h)+1;for(let k=0;k<y;k++)v?C(2+k*z,Math.max(0,d-14),String(k+1)):C(Math.max(0,m-14),2+k*z,String(k+1));const g=v?o.rows:o.cols,R=v?e.cssH-d:e.cssW-m,q=v?e.scrollY:e.scrollX,_=v?o.frozenRows:o.frozenCols,J=_?g.offsetOf(_):0,F=Math.max(g.indexAt(q+J),_),V=g.indexAt(q+J+R/e.zoom);t.save(),t.beginPath(),v?t.rect(0,n(d),n(i),n(R)):t.rect(n(m),0,n(R),n(c)),t.clip();const P=k=>{const b=v?e.cellRect(k,0):e.cellRect(0,k);return v?{at:b.y,size:b.h}:{at:b.x,size:b.w}},L=Math.max(1,Math.round((u?.lineWidth??1)*l));if(V-F<2e3){t.fillStyle=u?.dot??p;const k=Math.max(1,Math.round(l*1.5));for(let b=F;b<=V;b++){const I=M(o,h,b);if(I===0||g.isHidden(b))continue;const H=P(b),W=I*z+2+s/2;v?t.fillRect(n(W)-.5,n(H.at+H.size/2)-.5,k,k):t.fillRect(n(H.at+H.size/2)-.5,n(W)-.5,k,k)}}for(const k of et(o,h,F,V)){const b=(k.level-1)*z+2,I=E(o,h)?k.start-1:k.end+1,H=P(k.start).at,W=P(k.end).at+P(k.end).size,B=g.isHidden(k.start)&&g.isHidden(k.end);if(t.fillStyle=a,!B){const A=E(o,h)?W:H;v?(t.fillRect(n(b+s/2)-.5,n(H),L,n(W-H)),t.fillRect(n(b+s/2)-.5,n(A)-(E(o,h)?L:0),n(s/2),L)):(t.fillRect(n(H),n(b+s/2)-.5,n(W-H),L),t.fillRect(n(A)-(E(o,h)?L:0),n(b+s/2)-.5,L,n(s/2)))}if(I>=0&&I<g.count){const A=P(I);v?C(b,A.at+(A.size-s)/2,B?"+":"-"):C(A.at+(A.size-s)/2,b,B?"+":"-")}}t.restore()};i>0&&S("row"),c>0&&S("col")}function Ct(t,e,o){const{sheet:l}=t,r=t.gutterW,n=t.gutterH,i=t.rowHeaderW,c=t.colHeaderH,m=(u,p)=>{const w=Math.floor((p-2)/z)+1;return w>=1&&w<=x(l,u)+1?{kind:"level",axis:u,level:w}:null};if(r>0&&e<r&&o>=c-16&&o<c)return m("row",e);if(n>0&&o<n&&e>=i-16&&e<i)return m("col",o);const d=(u,p,w)=>{const{row:f,col:a}=u==="row"?t.hitCell(i,p):t.hitCell(p,c),s=u==="row"?f:a;for(const C of et(l,u,s-1,s+1)){const S=E(l,u)?C.start-1:C.end+1,h=(C.level-1)*z+2;if(S===s&&w>=h&&w<h+z)return{kind:"toggle",axis:u,group:C}}return null};return r>0&&e<r&&o>=c?d("row",o,e):n>0&&o<n&&e>=i?d("col",e,o):null}function gt(t,e){const{sheet:o}=t.book;return U(t,"outline",()=>{e.kind==="level"?st(o,e.axis,e.level):mt(o,e.axis,e.group)})}const ot=t=>new Map(t.hiddenSizes??[]);function nt(t){const e={rowExtras:t.rowExtras?new Map(t.rowExtras):null,colExtras:t.colExtras?new Map(t.colExtras):null,rows:ot(t.rows),cols:ot(t.cols),summaryAbove:t.summaryAbove,summaryLeft:t.summaryLeft,autoStyles:t.outlineAutoStyles,outlineColumn:t.outlineColumn};return()=>{const o=nt(t);for(const[l,r]of[[t.rows,e.rows],[t.cols,e.cols]]){if(l.hiddenSizes)for(const n of[...l.hiddenSizes.keys()])r.has(n)||l.setHidden(n,!1);for(const n of r.keys())l.setHidden(n,!0)}return Object.assign(t,{rowExtras:e.rowExtras,colExtras:e.colExtras,summaryAbove:e.summaryAbove,summaryLeft:e.summaryLeft,outlineAutoStyles:e.autoStyles,outlineColumn:e.outlineColumn}),tt(t),t.colsChanged=!0,t.revision++,o}}function U(t,e,o){const{book:l,grid:r}=t,n=l.sheet;return n.protection&&!n.protectionExtras?.outline?(l.guard?.("outline"),!1):(l.transact(n.protection?"outline":e,()=>{const i=nt(n);return o(),tt(n),n.colsChanged=!0,n.revision++,i}),l.dirty=!0,t.objects?.geometryChanged?.(),r.invalidate(),!0)}const D=(t,e)=>e==="row"?t.rowExtras:t.colExtras,O=(t,e)=>e==="row"?t.rows:t.cols,lt=/\s*collapsed="[^"]*"/;function dt(t,e,o){const l=D(t,e)?.get(o);return l!==void 0&&/collapsed="(1|true)"/.test(l)}function K(t,e,o,l){if(o<0)return;e==="row"&&!t.rowExtras&&(t.rowExtras=new Map),e==="col"&&!t.colExtras&&(t.colExtras=new Map);const r=D(t,e),n=(r.get(o)??"").replace(lt,"").trim(),i=l?`${n} collapsed="1"`.trim():n;i?r.set(o,i):r.delete(o)}const Y=(t,e,o)=>E(t,e)?o.start-1:o.end+1,rt=(t,e,o)=>e==="row"&&t.filteredRows?.has(o)===!0;function it(t,e,o,l,r){const n=O(t,e);let i=o;for(;i<=l;){if(M(t,e,i)<=r){rt(t,e,i)||n.setHidden(i,!1),i++;continue}let c=i;for(;c<l&&M(t,e,c+1)>r;)c++;dt(t,e,Y(t,e,{start:i,end:c}))||it(t,e,i,c,r+1),i=c+1}}function ct(t,e,o,l){const r=O(t,e);if(K(t,e,Y(t,e,o),l),l)for(let n=o.start;n<=o.end;n++)r.setHidden(n,!0);else it(t,e,o.start,o.end,o.level);e==="col"&&(t.colsChanged=!0)}function mt(t,e,o){const l=O(t,e);ct(t,e,o,!(l.isHidden(o.start)&&l.isHidden(o.end)))}function st(t,e,o){const l=D(t,e);if(!l)return;const r=O(t,e),n=[...l.keys()].filter(d=>M(t,e,d)>0).sort((d,u)=>d-u);for(const d of n)M(t,e,d)>=o?r.setHidden(d,!0):rt(t,e,d)||r.setHidden(d,!1);for(const d of[...l.keys()])lt.test(l.get(d))&&K(t,e,d,!1);const i=[],c=(d,u)=>{for(;i.length>d;){const p=i.pop();i.length+1>=o&&K(t,e,Y(t,e,{start:p,end:u}),!0)}};let m=-2;for(const d of n){d!==m+1&&c(0,m);const u=M(t,e,d);for(c(u,d-1);i.length<u;)i.push(d);m=d}c(0,m),e==="col"&&(t.colsChanged=!0)}function Ht(t,e,o){const l=[],r=O(t,e);for(let n=M(t,e,o);n>=1;n--){let i=o;for(;i>0&&M(t,e,i-1)>=n;)i--;let c=o;for(;c<r.count-1&&M(t,e,c+1)>=n;)c++;l.push({level:n,start:i,end:c})}return l}function St(t,e,o){const r=E(t,e)?o+1:o-1;if(r<0)return null;const n=M(t,e,o)+1;if(M(t,e,r)<n)return null;let i=r,c=r;const m=O(t,e);for(;i>0&&M(t,e,i-1)>=n;)i--;for(;c<m.count-1&&M(t,e,c+1)>=n;)c++;return{level:n,start:i,end:c}}const N=14,T=(t,e,o,l)=>{const r=t.book.styles.get(e.style(o,l)).indent??0,n=e.outlineColumn?.maxLevel;return n===void 0?r:Math.min(r,n)};function ut(t,e,o,l){return(e.kind(o+1,l)&15)!==0&&T(t,e,o+1,l)>T(t,e,o,l)}const at=new Map,pt=/^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/,wt=7e5,G=t=>typeof t=="string"&&t.length<=wt&&pt.test(t);function Z(t,e){if(!e)return null;let o=at.get(e);return o===void 0&&(o=new Image,o.onload=()=>t.invalidate(),o.src=e,at.set(e,o)),o.complete&&o.naturalWidth>0?o:null}function zt(t,e,o,l,r,n,i,c){const{sheet:m,theme:d}=e,u=m.outlineColumn,p=T(e,m,o,l),w=Math.round(p*9*c);let f=r+w;const a=Math.round(10*c),s=n+i/2,C=d.cellInk??"#000000",S=u.indicator!==!1&&ut(e,m,o,l),h=S&&m.rows.isHidden(o+1),v=S?Z(e,h?u.indicatorImages?.collapsed:u.indicatorImages?.expanded):null;if(v?t.drawImage(v,f,s-a/2,a,a):S&&(t.fillStyle=C,t.beginPath(),h?(t.moveTo(f+a*.3,s-a*.35),t.lineTo(f+a*.8,s),t.lineTo(f+a*.3,s+a*.35)):(t.moveTo(f+a*.15,s-a*.2),t.lineTo(f+a*.85,s-a*.2),t.lineTo(f+a*.5,s+a*.3)),t.closePath(),t.fill()),f+=Math.round(N*c),u.checkbox){const y=u.checks?.[o]===!0;t.strokeStyle=C,t.lineWidth=Math.max(1,Math.round(c/2)),t.strokeRect(f+.5,s-a/2+.5,a-1,a-1),y&&(t.beginPath(),t.moveTo(f+a*.2,s),t.lineTo(f+a*.42,s+a*.25),t.lineTo(f+a*.82,s-a*.28),t.stroke()),f+=Math.round(N*c)}if(u.images?.length>0){const y=Z(e,u.images[Math.min(p,u.images.length-1)]);y&&t.drawImage(y,f,s-a/2,a,a),f+=Math.round(N*c)}return e._ink=null,f-r-w}function At(t,e,o,l){const{book:r,grid:n}=t,i=r.sheet,c=i.outlineColumn;if(c===null||c.col!==o)return!1;const m=n.cellRect(e,o),d=T(n,i,e,o),u=m.x+2+d*9*n.zoom,p=N*n.zoom,w=f=>f<=i.maxRow&&T(n,i,f,o)>d&&(i.kind(f,o)&15)!==0;return c.indicator!==!1&&l>=u-2&&l<u+p&&ut(n,i,e,o)?U(t,"outline",()=>{const f=!i.rows.isHidden(e+1);for(let a=e+1;w(a);a++)f?i.rows.setHidden(a,!0):T(n,i,a,o)===d+1&&i.rows.setHidden(a,!1)}):c.checkbox&&l>=u+p&&l<u+p*2?U(t,"outline",()=>{const f={...c.checks??{}},a=!f[e];a?f[e]=!0:delete f[e];for(let s=e+1;w(s);s++)a?f[s]=!0:delete f[s];i.outlineColumn={...c,checks:f}}):!1}Q("outlineColumn",{sheet:{save(t){return t.outlineColumn===null?void 0:t.outlineColumn},load(t,e){if(!e||!Number.isInteger(e.col)||e.col<0||e.col>=X)return;const o={};if(e.checks&&typeof e.checks=="object")for(const[r,n]of Object.entries(e.checks))Number(r)>=0&&Number(r)<$&&n===!0&&(o[r]=!0);if(t.outlineColumn={col:e.col,checkbox:e.checkbox===!0,indicator:e.indicator!==!1,checks:o},Number.isInteger(e.maxLevel)&&e.maxLevel>=0&&(t.outlineColumn.maxLevel=e.maxLevel),Array.isArray(e.images)){const r=e.images.filter(G).slice(0,16);r.length>0&&(t.outlineColumn.images=r)}const l=e.indicatorImages;if(l&&typeof l=="object"){const r={};G(l.expanded)&&(r.expanded=l.expanded),G(l.collapsed)&&(r.collapsed=l.collapsed),(r.expanded||r.collapsed)&&(t.outlineColumn.indicatorImages=r)}}}}),Q("outlineStyle",{book:{save(t){return t.outlineStyle??void 0},load(t,e){if(!e||typeof e!="object")return;const o={};for(const l of["bg","ink","button","line","dot"])typeof e[l]=="string"&&/^#[0-9a-fA-F]{6}$/.test(e[l])&&(o[l]=e[l]);Number.isFinite(e.lineWidth)&&e.lineWidth>=1&&e.lineWidth<=6&&(o.lineWidth=e.lineWidth);for(const l of["plusImage","minusImage"])G(e[l])&&(o[l]=e[l]);t.outlineStyle=Object.keys(o).length>0?o:null}}});export{bt as clampToSheet,St as groupOfMark,Ht as groupsAt,ft as maxOutlineLevel,tt as outlineChanged,At as outlineColumnClick,Mt as outlineGutterSize,Ct as outlineHit,U as outlineStep,zt as paintOutlineColumnMark,yt as paintOutlineGutter,gt as runOutlineHit,K as setFlag,ct as setGroupCollapsed,st as showLevel};
|
package/cells/paint.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cssFont as L}from"../core/styles.js";import{paintStyleButtons as z}from"../celltypes/cell-buttons.js";function W(t,i,o,n,e,s){const l=i.stops;if(i.type==="path"){const h=o+e*(i.left??0),M=o+e*(1-(i.right??0)),y=n+s*(i.top??0),I=n+s*(1-(i.bottom??0)),g=Math.min(32,Math.max(8,Math.ceil(Math.max(e,s)/3)));for(let b=g;b>=0;b--){const d=b/g;t.fillStyle=C(l,d),t.fillRect(h+(o-h)*d,y+(n-y)*d,M-h+(o+e-M+(h-o))*d,I-y+(n+s-I+(y-n))*d)}return}const a=(i.degree??0)*Math.PI/180,r=Math.cos(a),c=Math.sin(a),m=(Math.abs(r)*e+Math.abs(c)*s)/2,p=o+e/2,f=n+s/2,u=t.createLinearGradient(p-r*m,f-c*m,p+r*m,f+c*m);for(const h of l)u.addColorStop(Math.max(0,Math.min(1,h.pos)),h.color);t.fillStyle=u,t.fillRect(o,n,e,s)}const $=t=>[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16)];function C(t,i){for(let o=1;o<t.length;o++)if(i<=t[o].pos){const n=t[o-1],e=t[o],s=e.pos===n.pos?1:(i-n.pos)/(e.pos-n.pos),l=$(n.color),a=$(e.color);return`#${l.map((r,c)=>Math.round(r+(a[c]-r)*s).toString(16).padStart(2,"0")).join("")}`}return t[t.length-1].color}function G(t,i,o,n,e,s,l=24){const a=(t.degree??0)*Math.PI/180,r=Math.cos(a),c=Math.sin(a),m=Math.abs(r)*n+Math.abs(c)*e||1,p=n*(t.left??0),f=n*(1-(t.right??0)),u=e*(t.top??0),h=e*(1-(t.bottom??0)),M=n/l,y=e/l;for(let I=0;I<l;I++)for(let g=0;g<l;g++){const b=(g+.5)*M,d=(I+.5)*y;let P;if(t.type==="path"){const w=b<p?(p-b)/(p||1):b>f?(b-f)/(n-f||1):0,S=d<u?(u-d)/(u||1):d>h?(d-h)/(e-h||1):0;P=Math.max(w,S)}else P=((b-n/2)*r+(d-e/2)*c)/m+.5;s(C(t.stops,Math.max(0,Math.min(1,P))),i+g*M,o+I*y,M+.4,y+.4)}}function N(t){const i=t.stops.map(o=>`${o.color} ${Math.round(o.pos*100)}%`).join(",");return t.type==="path"?`radial-gradient(circle at ${((t.left??0)+1-(t.right??0))*50}% ${((t.top??0)+1-(t.bottom??0))*50}%,${i})`:`linear-gradient(${(t.degree??0)+90}deg,${i})`}function O(t,i,o){t.images??=new Map;for(const[e,s]of t.images)if(s.data===o)return e;const n=`i${t.images.size+1}_${Math.abs(A(o)).toString(36)}`;return t.images.set(n,{mime:i,data:o}),n}function A(t){let i=0;for(let o=0;o<t.length;o+=Math.max(1,t.length>>12))i=i*31+t.charCodeAt(o)|0;return i}const _=/^image\/(png|jpeg|gif|webp|bmp|x-icon|svg\+xml)$/;function R(t,i){const o=t.book.images?.get(i);if(!o)return null;if(o.img===void 0){if(!_.test(o.mime))return o.img=null,null;const n=new Image;o.img=null,n.onload=()=>{o.img=n,t.invalidate()},n.src=`data:${o.mime};base64,${o.data}`}return o.img}function B(t,i,o,n,e,s,l){t.save(),t.beginPath(),t.rect(n,e,s,l),t.clip();const a=i.naturalWidth||i.width,r=i.naturalHeight||i.height;if(o==="center")t.drawImage(i,n+(s-a)/2,e+(l-r)/2);else if(o==="zoom"){const c=Math.min(s/a,l/r);t.drawImage(i,n+(s-a*c)/2,e+(l-r*c)/2,a*c,r*c)}else o==="none"?t.drawImage(i,n,e):t.drawImage(i,n,e,s,l);t.restore()}function D(t,i,o,n,e,s,l){const a=R(i,o.id);a&&B(t,a,o.layout??"stretch",n,e,s,l)}function q(t,i,o){const n=R(i,i.sheet.background.id);if(!n)return;const{dpr:e,zoom:s}=i,l=e*s,{fit:a}=i.sheet.background;if(a&&a!=="tile"){const g=o.x*e,b=o.y*e,d=o.w*e,P=o.h*e,w=(n.naturalWidth||n.width)*e,S=(n.naturalHeight||n.height)*e,v=a==="zoom"?Math.min(d/w,P/S):1;a==="stretch"?t.drawImage(n,g,b,d,P):t.drawImage(n,g+(d-w*v)/2,b+(P-S*v)/2,w*v,S*v);return}const r=(n.naturalWidth||n.width)*l,c=(n.naturalHeight||n.height)*l;if(r<1||c<1)return;const m=o.x*e-o.originX*l,p=o.y*e-o.originY*l,f=o.x*e,u=o.y*e,h=f+o.w*e,M=u+o.h*e,y=m+Math.floor((f-m)/r)*r,I=p+Math.floor((u-p)/c)*c;for(let g=I;g<M;g+=c)for(let b=y;b<h;b+=r)t.drawImage(n,b,g,r,c)}const T={topLeft:[0,0],topCenter:[.5,0],topRight:[1,0],bottomLeft:[0,1],bottomCenter:[.5,1],bottomRight:[1,1],leftCenter:[0,.5],rightCenter:[1,.5]};function E(t,i,o,n,e,s,l,a,r,c){const{sheet:m,theme:p,selection:f}=i,u=e.watermark,h=(m.kind(o,n)&15)===0,M=e.label;if(M===void 0){if(!h)return;const v=i.book.styles.get(m.style(o,n));t.font=L({...v,italic:!0},v.fontSize*c),t.fillStyle=p.watermarkInk??"#9a9a9a",t.textAlign="left",t.textBaseline="alphabetic";const k=e.pad;t.save(),t.beginPath(),t.rect(s,l,a,r),t.clip(),t.fillText(u,s+(k?k[3]*c:0)+2*c,l+r-Math.round(3*c)),t.restore();return}const y=M.visibility??"visible";if(y==="hidden"&&!h||y==="auto"&&!h&&!(f.row===o&&f.col===n))return;const I=(M.size??9)*c;t.font=L({fontName:M.font??"Helvetica Neue",italic:!1,bold:!1},I),t.fillStyle=M.color??"#808080";const[g,b]=T[M.alignment??"topLeft"]??T.topLeft,d=(M.margin??2)*c,P=t.measureText(u).width;t.textAlign="left",t.textBaseline="alphabetic";const w=s+d+(a-P-d*2)*g,S=l+d+I*.85+(r-I-d*2)*b;t.save(),t.beginPath(),t.rect(s,l,a,r),t.clip(),t.fillText(u,w,S),t.restore()}function X(t,i,o,n,e,s,l){const a=Math.min((i.size??8)*l,e,s),r=i.pos??"topRight",c=r==="topLeft"||r==="bottomLeft",m=r==="topLeft"||r==="topRight",p=c?o:o+e,f=m?n:n+s,u=c?a:-a,h=m?a:-a;t.fillStyle=i.color??"#3a7bd5",t.beginPath(),t.moveTo(p,f),t.lineTo(p+u,f),t.lineTo(p,f+h),t.closePath(),t.fill(),i.markColor&&(t.fillStyle=i.markColor,t.beginPath(),t.moveTo(p+u,f),t.lineTo(p+u,f+h),t.lineTo(p,f+h),t.closePath(),t.fill())}function Y(t,i,o,n,e,s,l,a){let r=n+2*a,c=n+s-2*a;for(const m of o){const p=R(i,m.id);if(!p)continue;const f=(m.w??12)*a,u=(m.h??12)*a,h=m.pos==="right",M=h?c-f:r;t.drawImage(p,M,e+(l-u)/2,f,u),h?c-=f+2*a:r+=f+2*a}}function j(t,i,o,n,e,s,l,a,r,c){e.watermark!==void 0&&E(t,i,o,n,e,s,l,a,r,c),e.fold!==void 0&&X(t,e.fold,s,l,a,r,c),e.icons!==void 0&&Y(t,i,e.icons,s,l,a,r,c),e.buttons!==void 0&&z(t,i,e.buttons,o,n,s,l,a,r,c),i._font="",i._ink=null}function J(t,i,o,n){const{ca:e,ra:s,xs:l,ys:a,s:r}=n;for(let c=0;c<o.length;c+=3){const m=o[c],p=o[c+1],f=l[m-e],u=a[p-s];j(t,i,p,m,o[c+2],f,u,l[m-e+1]-f,a[p-s+1]-u,r)}}function K(t,i,o){const{sheet:n,selection:e,dpr:s}=i,l=i.focusCell;t.save(),t.globalAlpha=l.alpha??.22;for(const a of o){const r=Math.round(a.x*s),c=Math.round(a.y*s),m=Math.round(a.w*s),p=Math.round(a.h*s),f=n.mergeAt(e.row,e.col)??{r0:e.row,c0:e.col,r1:e.row,c1:e.col},u=i._rangeRectInPane({r0:f.r0,r1:f.r1,c0:0,c1:16383},a),h=i._rangeRectInPane({c0:f.c0,c1:f.c1,r0:0,r1:1048575},a);t.save(),t.beginPath(),t.rect(r,c,m,p),t.clip(),t.fillStyle=l.color??"#2e7d32",u&&t.fillRect(r,u.y0,m,u.y1-u.y0),h&&(t.fillStyle=l.colColor??l.color??"#2e7d32",t.fillRect(h.x0,c,h.x1-h.x0,p)),t.restore()}t.restore()}function Q(t,i,o){const{dpr:n,theme:e}=i,{range:s,insert:l}=i.movePreview;for(const a of o){const r=i._rangeRectInPane(s,a);r!==null&&(t.save(),t.beginPath(),t.rect(Math.round(a.x*n),Math.round(a.y*n),Math.round(a.w*n),Math.round(a.h*n)),t.clip(),t.strokeStyle=e.accent,t.fillStyle=e.accent,l==="down"?t.fillRect(r.x0,r.y0-n,r.x1-r.x0,3*n):l==="right"?t.fillRect(r.x0-n,r.y0,3*n,r.y1-r.y0):(t.lineWidth=2*n,t.setLineDash([3*n,2*n]),t.strokeRect(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0)),t.restore())}}export{O as addImage,B as drawPicture,N as gradientCss,G as gradientPatches,R as imageOf,D as paintBackImage,j as paintExtMarks,J as paintExtPending,K as paintFocusCell,W as paintGradient,Q as paintMovePreview,q as paintSheetBackground};
|
package/cells/panes.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{registerSection as S}from"./sections.js";import{MAX_COLS as M,MAX_ROWS as b}from"../core/address.js";import{optionFor as w}from"./options.js";import{allows as H}from"../core/protection.js";function $(t){const{book:o,grid:e}=t,i=o.sheet;if(i.split){h(t);return}if(i.frozenRows||i.frozenCols||i.frozenTrailingRows||i.frozenTrailingCols){t.shell.setStatus("Panes can't be split while they're frozen. Unfreeze them first.");return}const{row:r,col:n}=e.selection,l=(e.cssW-e.rowHeaderW)/e.zoom,s=(e.cssH-e.colHeaderH)/e.zoom;let c=i.cols.offsetOf(n)-e.scrollX,a=i.rows.offsetOf(r)-e.scrollY;c<=0&&a<=0&&(c=l/2,a=s/2),c=c>0&&c<l?Math.round(c):0,a=a>0&&a<s?Math.round(a):0,i.split={x:c,y:a,scrollX:e.scrollX,scrollY:e.scrollY},i.viewChanged=!0,o.dirty=!0,e.invalidate()}function h(t){const{book:o,grid:e}=t,i=o.sheet;i.split&&(e.scrollX=i.split.scrollX,e.scrollY=i.split.scrollY,i.split=null,e.activeBand=null,i.viewChanged=!0,o.dirty=!0,e.invalidate())}function X(t,o,e){const{sheet:i,zoom:r}=t;if(!i.split)return null;const n=t.rowHeaderW,l=t.colHeaderH;return i.split.x>0&&Math.abs(o-n-i.split.x*r)<=4&&e>=l?{axis:"col"}:i.split.y>0&&Math.abs(e-l-i.split.y*r)<=4&&o>=n?{axis:"row"}:null}function k(t){const{sheet:o}=t,{split:e}=o,i=l=>{const s=/^([A-Z]+)(\d+)$/.exec(l??"");if(!s)return null;let c=0;for(const a of s[1])c=c*26+a.charCodeAt(0)-64;return{x:o.cols.offsetOf(c-1),y:o.rows.offsetOf(Number(s[2])-1)}},r=i(e.topLeft),n=i(e.firstTopLeft);e.topLeft=null,e.firstTopLeft=null,n&&(e.scrollX=n.x,e.scrollY=n.y),r&&(t.scrollX=Math.max(0,r.x-e.x),t.scrollY=Math.max(0,r.y-e.y),e.mainX=t.scrollX,e.mainY=t.scrollY)}function O(t,o,e,i){const{grid:r,book:n}=t,{sheet:l,zoom:s}=r,c=l.split;c&&(o==="col"?c.x=Math.max(0,Math.round((e-r.rowHeaderW)/s)):c.y=Math.max(0,Math.round((i-r.colHeaderH)/s)),c.x<=0&&c.y<=0&&(l.split=null),l.viewChanged=!0,n.dirty=!0,r.invalidate())}function v(t,o,e,i=!0){const{book:r,grid:n}=t,l=r.sheet;l.split&&h(t),l.frozenTrailingRows=Math.max(0,o),l.frozenTrailingCols=Math.max(0,e),l.trailingStick=i,r.dirty=!0,n.scrollTo(n.scrollX,n.scrollY),n.invalidate()}function Y(t){const o=String(t).trim().toLowerCase();return o==="auto"?"auto":/^\d*\.?\d*\*$/.test(o)?o==="*"?1:Number(o.slice(0,-1)):null}function y(t,o,e,i){t.axisSizing??={rows:new Map,cols:new Map};const r=o==="col"?t.axisSizing.cols:t.axisSizing.rows;i===null?r.delete(e):r.set(e,i),t.axisSizing.rows.size===0&&t.axisSizing.cols.size===0&&(t.axisSizing=null),t.sizingKey=null}function W(t,o,e){t.axisSizing!==null&&y(t,o,e,null)}function L(t){const{sheet:o,zoom:e}=t,i=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`;if(o.sizingKey===i)return;const r=(n,l)=>{const s=n==="col"?o.cols:o.rows,c=(n==="col"?t.cssW-t.rowHeaderW:t.cssH-t.colHeaderH)/e;let a=n==="col"?o.maxCol:o.maxRow,u=0,x=0;for(const[f,p]of l)f>a&&(a=f),p==="auto"?t.onAutoSize?.(n,f):s.isHidden(f)||(u+=p,x+=s.sizeOf(f));if(u===0)return;const g=c-(s.offsetOf(a+1)-x);if(g<1)return;let d=!1;for(const[f,p]of l){if(p==="auto"||s.isHidden(f))continue;const m=Math.floor(g*p/u);s.sizeOf(f)!==m&&(s.setSize(f,m),d=!0)}d&&n==="col"&&(o.colsChanged=!0)};r("col",o.axisSizing.cols),r("row",o.axisSizing.rows),o.sizingKey=`${t.cssW}|${t.cssH}|${e}|${o.revision}|${o.rows.delta}|${o.cols.delta}`}S("layout",{sheet:{save(t){const o={};return t.frozenTrailingRows&&(o.trailRows=t.frozenTrailingRows),t.frozenTrailingCols&&(o.trailCols=t.frozenTrailingCols),t.trailingStick===!1&&(o.stick=!1),t.axisSizing&&(o.cols=[...t.axisSizing.cols],o.rows=[...t.axisSizing.rows]),Object.keys(o).length?o:void 0},load(t,o){if(!o||typeof o!="object")return;const e=(r,n)=>Number.isInteger(r)&&r>0&&r<n?r:0;t.frozenTrailingRows=e(o.trailRows,1e3),t.frozenTrailingCols=e(o.trailCols,1e3),o.stick===!1&&(t.trailingStick=!1);const i=(r,n,l)=>{if(Array.isArray(n))for(const s of n.slice(0,1e4))!Array.isArray(s)||!Number.isInteger(s[0])||s[0]<0||s[0]>=l||(s[1]==="auto"||typeof s[1]=="number"&&s[1]>0)&&y(t,r,s[0],s[1])};i("col",o.cols,M),i("row",o.rows,b)}}});function I(t,o,e){return e.ctrlKey===!0||e.altKey===!0||(o==="col"?t.columnResizeMode:t.rowResizeMode)==="split"}function K(t,o){for(let e=o+1;e<t.count;e++)if(t.sizeOf(e)>0)return e;return-1}function N(t,o,e,i,r,n){const l=i+r,s=Math.max(0,Math.min(l,i+n));t.setSize(o,s),t.setSize(e,l-s)}const z=7;function B(t,o,e){if(!w(t.book,"dragMerge"))return!1;const{grid:i,sel:r}=t;if(r.ranges.length!==1)return!1;const n=r.ranges[0],l=i.cellRect(n.r0,n.c0),s=i.cellRect(n.r1,n.c1),c=s.x+s.w,a=s.y+s.h,u=(l.x+c)/2,x=(l.y+a)/2;return Math.abs(e-a)<=z&&Math.abs(o-u)<=z||Math.abs(o-c)<=z&&Math.abs(e-x)<=z}function D(t,o,e){const i=o.selection;if(i.ranges.length!==1)return;const r=o._rangeRectInPane(i.ranges[0],e);if(r===null)return;const{dpr:n,theme:l}=o,s=Math.round(5*n);t.fillStyle=l.accent,t.fillRect((r.x0+r.x1)/2-s/2,r.y1-s/2,s,s),t.fillRect(r.x1-s/2,(r.y0+r.y1)/2-s/2,s,s)}function _(t,o,e,i){const r={...o,r1:Math.max(o.r1,e),c1:Math.max(o.c1,i)};for(const n of t.merges){const l=n.r0<=r.r1&&n.r1>=r.r0&&n.c0<=r.c1&&n.c1>=r.c0,s=n.r0>=r.r0&&n.r1<=r.r1&&n.c0>=r.c0&&n.c1<=r.c1;if(l&&!s)return null}return r}const P=(t,o)=>{const e=w(o,"dragHeaders");return e==="both"||e===t};export{H as allows,L as applyAxisSizing,k as applySplitTopLeft,B as dragMergeHit,_ as dragMergeTarget,O as dragSplitBar,W as dropAxisSizing,P as headerDragAllowed,I as isSplitResize,K as nextVisible,D as paintDragMergeGrip,Y as parseSizeSpec,h as removeSplit,y as setAxisSizing,v as setTrailing,X as splitBarHit,N as splitResize,$ as toggleSplit};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{xmlText as X}from"../io/xml-escape.js";import{unescapeXstring as w}from"../io/xml-scan.js";const I="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata",O="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata2",H="http://schemas.microsoft.com/office/spreadsheetml/2022/richvaluerel",N="http://schemas.openxmlformats.org/spreadsheetml/2006/main",L="http://schemas.openxmlformats.org/officeDocument/2006/relationships",R=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
`,P="http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",B="http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",j="http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",Y="http://schemas.microsoft.com/office/2022/10/relationships/richValueRel",W=`${L}/sheetMetadata`,G="application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",_={rv:"application/vnd.ms-excel.rdrichvalue+xml",struct:"application/vnd.ms-excel.rdrichvaluestructure+xml",types:"application/vnd.ms-excel.rdrichvaluetypes+xml",rel:"application/vnd.ms-excel.richvaluerel+xml"},$={rv:"xl/richData/rdrichvalue.xml",struct:"xl/richData/rdrichvaluestructure.xml",types:"xl/richData/rdRichValueTypes.xml",rel:"xl/richData/richValueRel.xml",relRels:"xl/richData/_rels/richValueRel.xml.rels",meta:"xl/metadata.xml"},A='<s t="_localImage"><k n="_rvRel:LocalImageIdentifier" t="i"/><k n="CalcOrigin" t="i"/><k n="Text" t="s"/></s>',q=`${R}<rvTypesInfo xmlns="${O}" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x" xmlns:x="${N}"><global><keyFlags><key name="_Self"><flag name="ExcludeFromFile" value="1"/><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_DisplayString"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_Flags"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_Format"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_SubLabel"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_Attribution"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_Icon"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_Display"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_CanonicalPropertyNames"><flag name="ExcludeFromCalcComparison" value="1"/></key><key name="_ClassificationId"><flag name="ExcludeFromCalcComparison" value="1"/></key></keyFlags></global></rvTypesInfo>`;function ee(e){const r={vmCount:0,byVm:new Map};if(!e.meta)return r;const d=[...e.meta.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,f=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(e.meta),b=f?[...f[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],v=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(e.meta),t=v?[...v[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)]:[];if(r.vmCount=t.length,!d||!e.rv||!e.struct)return r;const k=[...e.struct.matchAll(/<s\b[^>]*\bt="([^"]+)"[^>]*>([\s\S]*?)<\/s>/g)].map(a=>({t:a[1],keys:[...a[2].matchAll(/<k\b[^>]*\bn="([^"]+)"/g)].map(n=>n[1])})),E=[...e.rv.matchAll(/<rv\b[^>]*\bs="(\d+)"[^>]*>([\s\S]*?)<\/rv>/g)].map(a=>({s:Number(a[1]),v:[...a[2].matchAll(/<v>([\s\S]*?)<\/v>|<v\/>/g)].map(n=>w(n[1]??""))})),m=e.rel?[...e.rel.matchAll(/<rel\b[^>]*r:id="([^"]+)"/g)].map(a=>a[1]):[],u=new Map;if(e.relRels)for(const a of e.relRels.matchAll(/<Relationship\b[^>]*\/>/g)){const n=/\bId="([^"]+)"/.exec(a[0])?.[1],p=/\bTarget="([^"]+)"/.exec(a[0])?.[1];n&&p&&u.set(n,p)}return t.forEach((a,n)=>{const p=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);if(!p||Number(p[1])!==d)return;const c=E[b[Number(p[2])]];if(!c)return;const o=k[c.s];if(!o||o.t!=="_localImage")return;const g=o.keys.indexOf("_rvRel:LocalImageIdentifier"),y=u.get(m[Number(c.v[g])]);if(!y)return;const s=o.keys.indexOf("Text");r.byVm.set(n+1,{target:y,alt:s>=0?c.v[s]:""})}),r}const z=(e,r)=>(e.match(new RegExp(`<${r}\\b`,"g"))??[]).length;function T(e,r,h,d){const f=e.lastIndexOf(`</${r}>`),b=e.slice(0,f)+h+e.slice(f);if(d===void 0)return b;const v=z(b,d);return b.replace(new RegExp(`(<${r}\\b[^>]*?)\\s+count="\\d+"`),"$1").replace(new RegExp(`<${r}\\b`),`<${r} count="${v}"`)}function J(e,r,h,d=null){const f='<metadataType name="XLRICHVALUE" minSupportedVersion="120000" copy="1" pasteAll="1" pasteValues="1" merge="1" splitFirst="1" rowColShift="1" clearFormats="1" clearComments="1" assign="1" coerce="1"/>';let t=e??`${R}<metadata xmlns="${N}" xmlns:xda="http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"><metadataTypes count="${h?1:0}">${h?'<metadataType name="XLDAPR" minSupportedVersion="120000" copy="1" pasteAll="1" pasteValues="1" merge="1" splitFirst="1" rowColShift="1" clearFormats="1" clearComments="1" assign="1" coerce="1" cellMeta="1"/>':""}</metadataTypes>${h?'<futureMetadata name="XLDAPR" count="1"><bk><extLst><ext uri="{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"><xda:dynamicArrayProperties fDynamic="1" fCollapsed="0"/></ext></extLst></bk></futureMetadata><cellMetadata count="1"><bk><rc t="1" v="0"/></bk></cellMetadata>':""}</metadata>`;/xmlns:xlrd=/.test(t)||(t=t.replace(/<metadata\b/,`<metadata xmlns:xlrd="${I}"`)),/name="XLRICHVALUE"[^>]*minSupportedVersion/.test(t)||(t=T(t,"metadataTypes",f,"metadataType"));const E=[...t.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(s=>s[1]).indexOf("XLRICHVALUE")+1;if(!/<futureMetadata\b[^>]*name="XLRICHVALUE"/.test(t)){const s=/<cellMetadata\b|<valueMetadata\b|<\/metadata>/.exec(t);t=`${t.slice(0,s.index)}<futureMetadata name="XLRICHVALUE" count="0"></futureMetadata>${t.slice(s.index)}`}const m=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(t),u=(m[1].match(/<bk>/g)??[]).length,a=[...m[1].matchAll(/\bi="(\d+)"/g)].reduce((s,C)=>Math.max(s,Number(C[1])+1),0);let n="",p=0;for(let s=0;s<r;s++)n+=`<bk><extLst><ext uri="{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}"><xlrd:rvb i="${d?.[s]??a+p++}"/></ext></extLst></bk>`;const c=m[0].replace("</futureMetadata>",`${n}</futureMetadata>`).replace(/count="\d+"/,`count="${u+r}"`);if(t=t.replace(m[0],c),!/<valueMetadata\b/.test(t)){const s=t.lastIndexOf("</metadata>");t=`${t.slice(0,s)}<valueMetadata count="0"></valueMetadata>${t.slice(s)}`}const o=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(t),g=(o[1].match(/<bk>/g)??[]).length+1;let y="";for(let s=0;s<r;s++)y+=`<bk><rc t="${E}" v="${u+s}"/></bk>`;return t=t.replace(o[0],o[0].replace("</valueMetadata>",`${y}</valueMetadata>`).replace(/count="\d+"/,`count="${g-1+r}"`)),{xml:t,firstVm:g,rvBase:a}}const K={"image/png":"png","image/jpeg":"jpeg","image/gif":"gif","image/bmp":"bmp","image/webp":"webp"},te=e=>K[e]??"png";function ae(e,r,h,d=[],f=null){const v=[...(f??e.map(()=>({}))).map(l=>l.rv??null),...d.map(()=>null)],{xml:t,rvBase:k,firstVm:E}=J(r.meta,v.length,h,v),m=[],u=(l,i,x,S)=>m.push({path:l,xml:i,override:{partName:`/${l}`,contentType:x},relationship:S?{id:`rId8cRich${m.length}`,type:S,target:`/${l}`}:null});u($.meta,t,G,W);let a=r.struct??`${R}<rvStructures xmlns="${I}" count="0"></rvStructures>`;const n=[...a.matchAll(/<s\b[^>]*\bt="([^"]+)"[^>]*>[\s\S]*?<\/s>/g)],p=l=>{const i=[...a.matchAll(/<s\b[^>]*\bt="([^"]+)"[^>]*>[\s\S]*?<\/s>/g)];let x=i.findIndex(S=>S[0]===l);return x<0&&(x=i.length,a=T(a,"rvStructures",l,"s")),x};let c=n.findIndex(l=>l[0]===A);c<0&&e.length>0&&(c=n.length,a=T(a,"rvStructures",A,"s"));let o=r.rv??`${R}<rvData xmlns="${I}" count="0"></rvData>`;const g=(o.match(/<rv\b/g)??[]).length;c<0&&g!==k&&(c=p(A));const y=d.map(l=>`<rv s="${p(l.shape)}">${l.values.map(i=>`<v>${X(i)}</v>`).join("")}</rv>`).join("");u($.struct,a,_.struct,B),u($.types,r.types??q,_.types,j);let s=r.rel??`${R}<richValueRels xmlns="${H}" xmlns:r="${L}"></richValueRels>`,C=r.relRels??`${R}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>`;const V=(s.match(/<rel\b/g)??[]).length;let F="",D="",M="";if(e.forEach((l,i)=>{const x=`rId8c${V+i+1}`;D+=`<rel r:id="${x}"/>`,F+=`<Relationship Id="${x}" Type="${L}/image" Target="../media/${l.path.split("/").pop()}"/>`,M+=`<rv s="${c}"><v>${V+i}</v><v>5</v><v>${X(l.alt??"")}</v></rv>`}),s=T(s,"richValueRels",D),C=C.replace("</Relationships>",`${F}</Relationships>`),g!==k){let l="";for(let i=g;i<k;i++)l+=`<rv s="${c}"><v>0</v><v>5</v><v></v></rv>`;M=l+M}return o=T(o,"rvData",M+y,"rv"),u($.rv,o,_.rv,P),(e.length>0||r.rel)&&(u($.rel,s,_.rel,Y),m.push({path:$.relRels,xml:C,override:null,relationship:null})),m.firstVm=E,m}const U={8:{shape:'<s t="_error"><k n="colOffset" t="i"/><k n="errorType" t="i"/><k n="rwOffset" t="i"/></s>',values:["0","8","0"]},9:{shape:'<s t="_error"><k n="errorType" t="i"/></s>',values:["13"]},10:{shape:'<s t="_error"><k n="errorType" t="i"/></s>',values:["14"]},11:{shape:'<s t="_error"><k n="errorType" t="i"/></s>',values:["9"]},12:{shape:'<s t="_error"><k n="errorType" t="i"/></s>',values:["10"]},13:{shape:'<s t="_error"><k n="errorType" t="i"/><k n="field" t="s"/><k n="subType" t="i"/></s>',values:["12","","0"]},14:{shape:'<s t="_error"><k n="errorType" t="i"/></s>',values:["11"]}},re=e=>U[e]!==void 0,se=e=>U[e];export{W as META_REL,G as META_TYPE,$ as PATHS,te as imageExtension,re as isRichError,J as mergeMetadata,ee as parseRichData,se as richErrorValue,ae as richParts};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{addImage as N,drawPicture as T,imageOf as W}from"./paint.js";import{imageExtension as $,isRichError as x,parseRichData as B,PATHS as p,richErrorValue as F,richParts as H}from"./rich-data-xml.js";import{adoptRichErrors as L,readRichValues as j}from"./rich-values.js";import{registerSparseMap as U,setSparse as R}from"../core/sparse.js";import{registerSection as _}from"./sections.js";import{CHUNK_BITS as D,ERR as E}from"../core/sheet.js";import{base64ToBytes as b,bytesToBase64 as O}from"../core/base64.js";import{mayReach as G}from"../core/online.js";const X=2,Y={png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml"};async function oe(e,i){if(i.richLoaded)return;if(i.richLoaded=!0,!e.has(p.meta)||!e.has(p.rv)){e.has(p.meta)&&(i.richSource={meta:await e.text(p.meta),vmCount:0});return}const n=async a=>e.has(a)?e.text(a):null,t={meta:await n(p.meta),rv:await n(p.rv),struct:await n(p.struct),types:await n(p.types),rel:await n(p.rel),relRels:await n(p.relRels)},r=B(t);i.richSource={...t,vmCount:r.vmCount},i.richValues=await j(e,t),L(i),i.richImages=new Map;for(const[a,{target:s,alt:o}]of r.byVm){const c=s.startsWith("/")?s.slice(1):`xl/${s.replace(/^(\.\.\/)+/,"")}`;if(!e.has(c))continue;const u=c.split(".").pop().toLowerCase(),m=N(i,Y[u]??"image/png",O(await e.bytes(c)));i.richImages.set(a,{id:m,alt:o})}}async function ue(e,i,n=""){const{book:t,grid:r}=e,a=new Uint8Array(await i.arrayBuffer());let s=i.type||"image/png",o=O(a);(s==="image/svg+xml"||s==="image/webp")&&({mime:s,data:o}=await q(s,o));const c=N(t,s,o);t.richImages??=new Map,t.richNew??=[];const u=t.richSource?.vmCount??0;let m=t.richNew.findIndex(d=>d.id===c&&d.alt===n);m<0&&(m=t.richNew.length,t.richNew.push({id:c,alt:n}));const g=u+m+1;t.richImages.set(g,{id:c,alt:n});const{row:l,col:f}=r.selection;t.transact("entry",d=>(d.saveCell(l,f),d.sheet.setCell(l,f,E,X),d.sheet.setFormula(l,f,null),R(d.sheet,"valueMeta",[{r0:l,c0:f,r1:l,c1:f}],g))),r.invalidate()}async function q(e,i){const n=new Image;await new Promise((r,a)=>{n.onload=r,n.onerror=a,n.src=`data:${e};base64,${i}`});const t=document.createElement("canvas");return t.width=n.naturalWidth||256,t.height=n.naturalHeight||256,t.getContext("2d").drawImage(n,0,0,t.width,t.height),{mime:"image/png",data:t.toDataURL("image/png").split(",")[1]}}function me(e,i,n,t){const r=e.book.richImages;if(!r)return null;const a=i.valueMeta.get(n*16384+t);return a===void 0?null:r.get(a)??null}function fe(e,i,n,t,r,a,s,o,c,u,m){const g=W(i,n.id);if(!g)return;const l=t.cellPicOpts?.get(r*16384+a);if(l===void 0){T(e,g,"zoom",s,o,c,u);return}const f=g.naturalWidth||g.width,d=g.naturalHeight||g.height,h=Math.min(l.clipX??0,f-1),w=Math.min(l.clipY??0,d-1),v=Math.min(l.clipW||f-h,f-h),I=Math.min(l.clipH||d-w,d-w);let y,A;if(l.w||l.h)y=(l.w||l.h*v/I)*m,A=(l.h||l.w*I/v)*m;else{const C=Math.min(c/v,u/I);y=v*C,A=I*C}const S=s+(c-y)*(l.hAlign==="left"?0:l.hAlign==="right"?1:.5),V=o+(u-A)*(l.vAlign==="top"?0:l.vAlign==="bottom"?1:.5);e.save(),e.beginPath(),e.rect(s,o,c,u),e.clip(),e.drawImage(g,h,w,v,I,S,V,y,A),e.restore()}function ge(e,i,n,t){const{book:r}=e,s=r.sheet.valueMeta?.get(i*16384+n),o=s===void 0?void 0:r.richImages?.get(s);if(o===void 0||o.alt===t)return;r.richNew??=[];const c=r.richSource?.vmCount??0;let u=r.richNew.findIndex(g=>g.id===o.id&&g.alt===t);u<0&&(u=r.richNew.length,r.richNew.push({id:o.id,alt:t}));const m=c+u+1;r.richImages.set(m,{id:o.id,alt:t}),r.transact("alt-text",g=>R(g.sheet,"valueMeta",[{r0:i,c0:n,r1:i,c1:n}],m)),e.controller.syncFormulaBar()}function de(e,i,n){e.transact("format",t=>R(t.sheet,"cellPicOpts",i,n===null?void 0:n))}async function he(e,i,n){const{book:t}=e,r=t.sheet,a=t.richImages?.get(r.valueMeta?.get(i*16384+n)),s=a&&t.images?.get(a.id);if(!s)return;const o=new File([b(s.data)],"picture",{type:s.mime});await e.objects.addPicture(o),t.clearRange([{r0:i,c0:n,r1:i,c1:n}]),e.grid.invalidate()}const K=(e,i)=>typeof e=="number"&&e>=0&&e<=i?e:void 0;function J(e){if(!e||typeof e!="object")return null;const i={};for(const n of["w","h","clipX","clipY","clipW","clipH"]){const t=K(e[n],2e4);t!==void 0&&(i[n]=t)}return["left","center","right"].includes(e.hAlign)&&(i.hAlign=e.hAlign),["top","center","bottom"].includes(e.vAlign)&&(i.vAlign=e.vAlign),Object.keys(i).length?i:null}U("cellPicOpts"),_("cellPictures",{sheet:{save(e){return e.cellPicOpts?[...e.cellPicOpts]:void 0},load(e,i){if(!Array.isArray(i))return;const n=new Map;for(const t of i.slice(0,1e5)){const r=Array.isArray(t)&&Number.isInteger(t[0])&&t[0]>=0?J(t[1]):null;r&&n.set(t[0],r)}e.cellPicOpts=n.size?n:null}}});function pe(e,i){const n=e.richNew??[],t=n.filter(c=>c.rv===void 0),r=[...Q(e)].sort((c,u)=>c-u);if(e.errorVms=null,n.length===0&&r.length===0)return[];const a=e.richSource??{},s=t.map((c,u)=>{const m=e.images.get(c.id);return{path:`xl/media/image8c${(a.vmCount??0)+u+1}.${$(m.mime)}`,alt:c.alt,mime:m.mime,data:m.data}}),o=H(s,{meta:a.meta??null,rv:a.rv??null,struct:a.struct??null,types:a.types??null,rel:a.rel??null,relRels:a.relRels??null},i,r.map(F),n.map(c=>c.rv===void 0?{}:{rv:c.rv}));r.length>0&&(e.errorVms={},r.forEach((c,u)=>{e.errorVms[c]=o.firstVm+n.length+u}));for(const c of s)o.push({path:c.path,xml:b(c.data),override:{partName:`/${c.path}`,contentType:c.mime},relationship:null});return o}function Q(e){const i=new Set;for(const n of e.sheets){const t=n.valueMeta;for(let r=0;r<n.columns.length;r++){const a=n.columns[r];if(a!==void 0)for(let s=0;s<a.length;s++){const o=a[s];if(o===void 0)continue;const{kinds:c,values:u}=o;for(let m=0;m<c.length;m++)if(!((c[m]&7)!==E||!x(u[m]))&&!(t!==null&&t.has(((s<<D)+m)*16384+r))&&(i.add(u[m]),i.size===7))return i}}}return i}const Z=/^=(?:_xlfn\.)?IMAGE\(/i,M=new Map,P=new Map;function z(e,i){if(!G(i))return{img:null,failed:!0};let n=M.get(i);if(n===void 0){M.size>512&&M.clear(),n={img:null,failed:!1},M.set(i,n);const t=new Image;t.referrerPolicy="no-referrer",t.onload=()=>{n.img=t,e.invalidate()},t.onerror=()=>{n.failed=!0},t.src=i}return n}function k(e){const i=[];let n=0,t=!1,r=0;for(let a=0;a<e.length;a++){const s=e[a];if(s==='"')t=!t;else{if(t)continue;s==="("||s==="{"?n++:s===")"||s==="}"?n--:s===","&&n===0&&(i.push(e.slice(r,a)),r=a+1)}}return i.push(e.slice(r)),i}function ee(e,i,n,t){const r=`${i.uid}:${n*16384+t}`,a=P.get(r);if(a!==void 0&&a.revision===i.revision)return a.call;const{book:s}=e;let o=null;const c=s.editText(i,n,t);if(Z.test(c)&&c.endsWith(")"))try{const u=k(c.slice(c.indexOf("(")+1,-1)).map(l=>l.trim()),m=l=>{if(u[l]===void 0||u[l]==="")return null;const f=s.engine.template(u[l],n,t).fn(n,t,i);return f&&f.sheet?s.engine.refAuto(f,n,t):f},g=String(m(0)??"");/^https:\/\//i.test(g)&&(o={url:g,mode:Number(m(2)??0),h:Number(m(3)??0),w:Number(m(4)??0)})}catch{o=null}return P.size>4096&&P.clear(),P.set(r,{revision:i.revision,call:o}),o}function we(e,i,n,t,r,a,s,o,c,u){const m=n.formula(t,r),g=m.f??m.sf;if(g===void 0||!g.includes("IMAGE("))return!1;const l=ee(i,n,t,r);if(l===null)return!1;const f=z(i,l.url);if(!f.img)return!f.failed;const d=f.img.naturalWidth,h=f.img.naturalHeight;if(e.save(),e.beginPath(),e.rect(a,s,o,c),e.clip(),l.mode===1)e.drawImage(f.img,a,s,o,c);else if(l.mode===2)e.drawImage(f.img,a,s,d*u,h*u);else if(l.mode===3)e.drawImage(f.img,a,s,(l.w||l.h*d/h)*u,(l.h||l.w*h/d)*u);else{const w=Math.min(o/d,c/h);e.drawImage(f.img,a+(o-d*w)/2,s+(c-h*w)/2,d*w,h*w)}return e.restore(),!0}export{me as cellPicture,oe as loadRichData,fe as paintCellPicture,we as paintImageFormula,he as pictureToFloating,ue as placePictureInCell,pe as richPackage,ge as setPictureAlt,de as setPictureOptions};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{STR as j}from"../core/sheet.js";import{parseInput as x}from"../core/input.js";const k={bold:"b",italic:"i",underline:"u",strike:"strike",fontSize:"sz",fontName:"name",color:"color",vertAlign:"va"};function q(t){const e={};for(const[o,s]of Object.entries(t)){const r=k[o];if(r===void 0)return null;e[r]=s}return e}function C(t,e){return e?{...t,bold:e.b??t.bold,italic:e.i??t.italic,underline:e.u??t.underline,strike:e.strike??t.strike,fontSize:e.sz??t.fontSize,fontName:e.name??t.fontName,color:e.color??t.color,vertAlign:e.va??t.vertAlign}:t}const g=t=>{const{at:e,...o}=t;return o},E=(t,e)=>JSON.stringify(g(t))===JSON.stringify(g(e));function y(t,e){const o=[],s=t.length>0&&t[0].at===0?t:[{at:0},...t];for(let r=0;r<s.length;r++){const c=s[r];(s[r+1]?.at??e)<=c.at&&!(e===0&&r===0)||o.length>0&&E(o[o.length-1],c)||o.push(c)}return o.length>0?o:[{at:0}]}function O(t,e){let o=t[0];for(const s of t){if(s.at>e)break;o=s}return o}function L(t,e,o,s,r=null){const c=e+o,l=t.filter(n=>n.at<e);s>0&&l.push({...r??g(O(t,e>0?e-1:0)),at:e}),l.push({...O(t,c),at:e+s});for(const n of t)n.at>c&&l.push({...n,at:n.at+s-o});return l}function F(t,e,o,s){const r=l=>{const n={...l,...s};"name"in s&&(delete n.scheme,delete n.family,delete n.charset),"color"in s&&delete n.colorAttrs;for(const i of Object.keys(n))(n[i]===null||n[i]===void 0)&&delete n[i];return n},c=[];for(let l=0;l<t.length;l++){const n=t[l],i=t[l+1]?.at??1/0;if(i<=e||n.at>=o){c.push(n);continue}n.at<e&&c.push(n),c.push({...r(n),at:Math.max(n.at,e)}),i>o&&c.push({...n,at:o})}return c}function T(t,e,o){const s=y(t,e.length),r=n=>{const i=C(o,n);return{b:!!i.bold,i:!!i.italic,u:i.underline??0,strike:!!i.strike,sz:i.fontSize,name:i.fontName,color:i.color??null,va:i.vertAlign??null}},c=r({}),l=n=>JSON.stringify(r(n))!==JSON.stringify(c);return e===""||!s.some(l)?null:y(s.map(n=>{if(!l(n))return{at:n.at};const i=r(n),f={...n,b:i.b,i:i.i,u:i.u,strike:i.strike,sz:i.sz,name:i.name};return i.color!==null?f.color=i.color:delete f.color,i.va?f.va=i.va:delete f.va,f}),e.length)}const J=k;function _(t,e,o,s,r,c){if(c&&x(r).kind===j){const l=r[0]==="'"&&r.length>1,n=l?r.slice(1):r,i=l?y(c.map(p=>({...p,at:Math.max(0,p.at-1)})),n.length):c;t.setRichInput(e,o,s,n,i);const{sheet:f}=e,a=f.cellStyle(o,s);(l||a!==0&&t.styles.get(a).quotePrefix)&&f.setStyle(o,s,t.styles.derive(a,{quotePrefix:l}))}else t.setInput(e,o,s,r);if(r.includes(`
|
|
2
|
+
`)&&r[0]!=="="){const{sheet:l}=e;t.styles.get(l.style(o,s)).wrap||l.setStyle(o,s,t.styles.derive(l.style(o,s),{wrap:!0}))}}function D(t,e,o,s){const r={};let c=!1;for(const[i,f]of Object.entries(s)){const a=J[i];a&&(r[a]=f,c=!0)}if(!c)return;const{sheet:l}=e,n=t.strings.rich;for(const{r0:i,c0:f,r1:a,c1:p}of o){const z=Math.min(a,l.maxRow),R=Math.min(p,l.maxCol);for(let d=f;d<=R;d++){const v=l.columns[d];if(v!==void 0)for(let u=i;u<=z;u++){const h=v[u>>>10];if(h===void 0){u|=1023;continue}if((h.kinds[u&1023]&15)!==2)continue;const S=n.get(h.values[u&1023]);if(!S)continue;const N=S.map(m=>{const{at:b,...I}=m;return Object.keys(I).length===0?m:F([{...m,at:0}],0,1/0,r).map(A=>({...A,at:b}))[0]});e.saveCell(u,d),l.setCell(u,d,2,t.strings.addRich(t.strings.get(h.values[u&1023]),N))}}}}export{F as applyRuns,T as finalizeRuns,y as normalizeRuns,D as overrideRuns,g as propsOf,O as runAt,q as runPatch,L as spliceRuns,_ as storeEntry,C as styleOfRun};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{unescapeXstring as f}from"../io/xml-scan.js";import{ERRORS as g}from"../core/sheet.js";import{RichValue as x}from"../calc/values.js";const N={rv:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValue",path:"xl/richData/rdrichvalue.xml"},struct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueStructure",path:"xl/richData/rdrichvaluestructure.xml"},types:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdRichValueTypes",path:"xl/richData/rdRichValueTypes.xml"},spb:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBag",path:"xl/richData/rdsupportingpropertybag.xml"},spbStruct:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdSupportingPropertyBagStructure",path:"xl/richData/rdsupportingpropertybagstructure.xml"},array:{type:"http://schemas.microsoft.com/office/2017/06/relationships/rdArray",path:"xl/richData/rdarray.xml"},styles:{type:"http://schemas.microsoft.com/office/2017/06/relationships/richStyles",path:"xl/richData/richStyles.xml"}},S={4:"#NAME?",8:"#SPILL!",9:"#CONNECT!",10:"#BLOCKED!",11:"#UNKNOWN!",12:"#FIELD!",13:"#CALC!",14:"#BUSY!",17:"#BUSY!",19:"#TIMEOUT!"},w={0:"#NULL!",7:"#DIV/0!",15:"#VALUE!",23:"#REF!",29:"#NAME?",36:"#NUM!",42:"#N/A",43:"#GETTING_DATA"},A=/<v\b([^>]*)>([\s\S]*?)<\/v>|<v\b([^>]*)\/>/g,b=i=>/\bt="([^"]+)"/.exec(i??"")?.[1];function h(i){const t=[];for(const s of i.matchAll(A))t.push({t:b(s[1]??s[3]),v:f(s[2]??"")});return t}function y(i){return[...i.matchAll(/<k\b([^>]*)\/?>/g)].map(t=>({n:f(/\bn="([^"]*)"/.exec(t[1])?.[1]??""),t:b(t[1])??"d"}))}function E(i){if(!i)return[];const s=[...i.matchAll(/<metadataType\b[^>]*\bname="([^"]+)"/g)].map(a=>a[1]).indexOf("XLRICHVALUE")+1,e=/<futureMetadata\b[^>]*name="XLRICHVALUE"[^>]*>([\s\S]*?)<\/futureMetadata>/.exec(i),r=e?[...e[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g)].map(a=>Number(/\bi="(\d+)"/.exec(a[1])?.[1]??-1)):[],n=/<valueMetadata\b[^>]*>([\s\S]*?)<\/valueMetadata>/.exec(i),o=[-1];for(const a of n?n[1].matchAll(/<bk>([\s\S]*?)<\/bk>/g):[]){const c=/<rc\b[^>]*\bt="(\d+)"[^>]*\bv="(\d+)"/.exec(a[1]);o.push(c&&Number(c[1])===s?r[Number(c[2])]??-1:-1)}return o}class V{constructor(t){this.byVm=E(t.meta),this.structs=t.struct?[...t.struct.matchAll(/<s\b([^>]*)>([\s\S]*?)<\/s>/g)].map(r=>({t:f(/\bt="([^"]*)"/.exec(r[1])?.[1]??""),keys:y(r[2])})):[],this.values=t.rv?[...t.rv.matchAll(/<rv\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rv>)/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h((r[2]??"").replace(/<fb\b[\s\S]*?<\/fb>|<fb\b[^>]*\/>/g,"")).map(n=>n.v)})):[];const s=t.spb??"",e=/<spbArrays\b[^>]*>([\s\S]*?)<\/spbArrays>/.exec(s)?.[1]??"";this.spbArrays=[...e.matchAll(/<a\b[^>]*>([\s\S]*?)<\/a>/g)].map(r=>h(r[1])),this.spbs=[...s.matchAll(/<spb\b([^>]*)>([\s\S]*?)<\/spb>/g)].map(r=>({s:Number(/\bs="(\d+)"/.exec(r[1])?.[1]??-1),v:h(r[2]).map(n=>n.v)})),this.spbStructs=t.spbStruct?[...t.spbStruct.matchAll(/<(s|spbStructure)\b[^>]*>([\s\S]*?)<\/\1>/g)].map(r=>y(r[2])):[],this.arrays=t.array?[...t.array.matchAll(/<a\b([^>]*)>([\s\S]*?)<\/a>/g)].map(r=>({r:Number(/\br="(\d+)"/.exec(r[1])?.[1]??1),c:Number(/\bc="(\d+)"/.exec(r[1])?.[1]??1),v:h(r[2])})):[],this.typeFlags=R(t.types??""),this.added=new Map,this.styles=_(t.styles??"")}indexOfVm(t){return t>0&&t<this.byVm.length?this.byVm[t]:this.added.get(t)??-1}vmOfIndex(t){if(this.vmByIndex===void 0){this.vmByIndex=new Map;for(let s=this.byVm.length-1;s>0;s--)this.byVm[s]>=0&&this.vmByIndex.set(this.byVm[s],s)}return this.vmByIndex.get(t)??-1}sameValue(t,s){const e=this.values[t],r=this.values[s];return!!(e&&r)&&e.s===r.s&&e.v.length===r.v.length&&e.v.every((n,o)=>n===r.v[o])}type(t){return this.structs[this.values[t]?.s]?.t??null}entries(t,s=0){const e=this.values[t],r=e&&this.structs[e.s],n=new Map;if(!r||s>8)return n;r.keys.forEach((a,c)=>n.set(a.n,{n:a.n,t:a.t,v:e.v[c]??""}));const o=n.get("%cvi");if(o&&o.t==="r")for(const[a,c]of this.entries(Number(o.v),s+1))n.has(a)||n.set(a,c);return n}bag(t){const s=this.spbs[t],e=s?this.spbStructs[s.s]??[]:[],r=new Map;return e.forEach((n,o)=>r.set(n.n,{n:n.n,t:n.t,v:s.v[o]??""})),r}view(t,s=!1){const e=this.type(t);if(e===null||e==="_localImage"||e==="_webimage")return null;const r=this.entries(t);if(e==="_error"){const o=Number(r.get("errorType")?.v),a=o===18?s?"#PYTHON!":"#EXTERNAL!":S[o]??null;return a?{kind:"error",text:a,icon:null}:null}if(e==="_array"){const o=this.arrays[Number(r.get("array")?.v)];return{kind:"array",text:o&&o.v.length?this.displayOf(o.v[0]):"",icon:s?"python":"array"}}return e==="_hyperlink"?{kind:"link",text:r.get("Text")?.v||r.get("Address")?.v||"",icon:null}:{kind:"entity",text:r.get("_DisplayString")?.v??r.get("Name")?.v??"",icon:s?"python":k(e,r)}}displayOf(t,s=0){switch(t.t){case"r":{if(s>8)return"";const e=this.view(Number(t.v));return e?e.text:this.entries(Number(t.v)).get("Text")?.v??""}case"a":{const e=this.arrays[Number(t.v)];return e&&e.v.length?this.displayOf(e.v[0],s+1):""}case"b":return t.v==="1"||t.v==="true"?"TRUE":"FALSE";case"e":return v(t.v);case"spb":case"spba":return"";default:return t.v}}flag(t,s,e,r){const o=this.entries(t).get("_Flags");if(o&&o.t==="spb"){const c=this.bag(Number(o.v)).get(s);if(c&&c.t==="spb"){const u=this.bag(Number(c.v)).get(e);if(u)return u.v==="1"||u.v==="true"}}return this.typeFlags.get(this.type(t))?.get(s)?.get(e)??this.typeFlags.get("")?.get(s)?.get(e)??r}fields(t){const s=this.entries(t),e=this.type(t),r=u=>!/^[_%^]/.test(u)&&this.flag(t,u,"ShowInCardView",e!=="_hyperlink");let n=[...s.keys()].filter(r);const o=s.get("_Display");if(o?.t==="spb"){const u=this.bag(Number(o.v)).get("^Order");if(u?.t==="spba"){const p=(this.spbArrays[Number(u.v)]??[]).map(l=>l.v).filter(l=>s.has(l)&&r(l));n=[...p,...n.filter(l=>!p.includes(l))]}}const a=s.get("_SubLabel"),c=a?.t==="spb"?this.bag(Number(a.v)):null;return n.map(u=>{const p=c?.get(u);let l="";return p?.t==="spb"?l=[...this.bag(Number(p.v)).values()].map(d=>d.v).join(" "):p&&(l=p.v),{name:u,value:s.get(u),sub:l}})}keyOf(t,s){const e=this.entries(t);if(e.has(s))return s;const r=s.toLowerCase();for(const o of e.keys())if(o.toLowerCase()===r)return o;const n=e.get("_CanonicalPropertyNames");if(n?.t==="spb"){for(const[o,a]of this.bag(Number(n.v)))if(a.v.toLowerCase()===r&&e.has(o))return o}return null}fieldFormat(t,s,e=null){const r=this.entries(t).get("_Format");if(!r||r.t!=="spb")return null;const n=this.bag(Number(r.v)).get(s),o=n?this.styles.rSty[Number(n.v)]:void 0;if(!o)return null;for(const c of o.rpv){const u=this.styles.rPr[c.i];if(u&&/^(?:NumberFormat|NumFmt|Format)$/i.test(u.n)&&c.v)return c.v}if(o.dxfid===null)return null;if(this.styles.dxfs.length)return this.styles.dxfs[o.dxfid]??null;const a=e?.[o.dxfid];return(typeof a?.numFmt=="string"?a.numFmt:a?.numFmt?.code??a?.numFmt?.formatCode)??null}isEntity(t){const s=this.type(t);return s!==null&&s!=="_error"&&s!=="_array"&&s!=="_localImage"&&s!=="_webimage"&&s!=="_hyperlink"}}function T(i,t,s){let e=t,r=null;for(let n=0;n<s.length;n++){if(!i.isEntity(e))return{error:"#FIELD!"};const o=i.keyOf(e,String(s[n]));if(o===null)return{error:"#FIELD!"};const a=i.entries(e).get(o);if(a.t==="r"&&n<s.length-1){e=Number(a.v);continue}if(n<s.length-1)return{error:"#FIELD!"};r=m(i,a,0)}return r??{error:"#VALUE!"}}function m(i,t,s){switch(t.t){case"i":case"d":{const e=Number(t.v);return Number.isFinite(e)?e:{error:"#NUM!"}}case"b":return t.v==="1"||t.v==="true";case"e":return{error:v(t.v)};case"s":return t.v;case"a":{const e=i.arrays[Number(t.v)];if(!e||s>4)return{error:"#VALUE!"};const r=[];for(let n=0;n<e.r;n++){const o=[];for(let a=0;a<e.c;a++){const c=e.v[n*e.c+a],u=c?m(i,{t:c.t??"d",v:c.v},s+1):"";o.push(u&&typeof u=="object"&&u.rows?u.rows[0]?.[0]??"":u)}r.push(o)}return{rows:r}}case"r":{const e=Number(t.v),r=i.type(e),n=i.entries(e);return r==="_error"?{error:i.view(e)?.text??"#VALUE!"}:r==="_array"?m(i,n.get("array")??{t:"a",v:"-1"},s+1):i.isEntity(e)?{entity:e}:i.view(e)?.text??n.get("Text")?.v??""}case"spb":case"spba":return{error:"#VALUE!"};default:{const e=Number(t.v);return t.v!==""&&Number.isFinite(e)?e:t.v}}}function _(i){const t={dxfs:[],rPr:[],rSty:[]};if(!i)return t;const s=/<(?:\w+:)?dxfs\b[^>]*>([\s\S]*?)<\/(?:\w+:)?dxfs>/.exec(i)?.[1]??"";return t.dxfs=[...s.matchAll(/<((?:\w+:)?)dxf\b[^>]*?(?:\/>|>([\s\S]*?)<\/\1dxf>)/g)].map(e=>{const r=/<(?:\w+:)?numFmt\b[^>]*\bformatCode="([^"]*)"/.exec(e[2]??"")?.[1];return r===void 0?null:f(r)}),t.rPr=[...i.matchAll(/<rPr\b([^>]*)\/?>/g)].map(e=>({n:f(/\bn="([^"]*)"/.exec(e[1])?.[1]??""),t:b(e[1])??"s"})),t.rSty=[...i.matchAll(/<rSty\b([^>]*?)(?:\/>|>([\s\S]*?)<\/rSty>)/g)].map(e=>{const r=/\bdxfid="(\d+)"/.exec(e[1])?.[1],n=[...(e[2]??"").matchAll(/<rpv\b[^>]*\bi="(\d+)"[^>]*>([\s\S]*?)<\/rpv>/g)].map(o=>({i:Number(o[1]),v:f(o[2])}));return{dxfid:r===void 0?null:Number(r),rpv:n}}),t}function R(i){const t=new Map,s=r=>{const n=new Map;for(const o of r.matchAll(/<key\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/key>/g)){const a=new Map;for(const c of o[2].matchAll(/<flag\b[^>]*\bname="([^"]*)"[^>]*\bvalue="([^"]*)"/g))a.set(c[1],c[2]==="1"||c[2]==="true");n.set(f(o[1]),a)}return n},e=/<global\b[^>]*>([\s\S]*?)<\/global>/.exec(i);e&&t.set("",s(e[1]));for(const r of i.matchAll(/<type\b[^>]*\bname="([^"]*)"[^>]*>([\s\S]*?)<\/type>/g))t.set(f(r[1]),s(r[2]));return t}function v(i){return/^#/.test(i)?i.toUpperCase():w[Number(i)]??g[Number(i)]??"#VALUE!"}function k(i,t){const s=[t.get("_Icon")?.v,t.get("%EntityDomainIdString")?.v,t.get("%ProviderInfo")?.v,t.get("%DataProviderString")?.v,i].filter(Boolean).join(" ").toLowerCase();return/stock|financ|bank|exchange|ticker|fund/.test(s)?"stock":/geo|map|country|city|place|globe|location|region/.test(s)?"geography":/currenc|money|coin/.test(s)?"currency":"entity"}async function M(i,t){if(!t.meta||!t.rv||!t.struct||!/<s\b[^>]*\bt="(?!_localImage")/.test(t.struct))return null;const s=i.has("xl/_rels/workbook.xml.rels")?await i.text("xl/_rels/workbook.xml.rels"):"",e=n=>{for(const o of s.matchAll(/<Relationship\b[^>]*\/>/g)){if(!o[0].includes(`Type="${n.type}"`))continue;const a=/\bTarget="([^"]+)"/.exec(o[0])?.[1];if(a)return a.startsWith("/")?a.slice(1):`xl/${a.replace(/^\.\//,"")}`}return n.path},r=async n=>{const o=e(N[n]);return i.has(o)?i.text(o):null};return new V({...t,spb:await r("spb"),spbStruct:await r("spbStruct"),array:await r("array"),styles:await r("styles")})}function D(i,t,s,e){const r=i.richValues,n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);return o>=0&&r.isEntity(o)?new x(r,o):null}function U(i,t){const s=i.richValues,e=s.vmOfIndex(t);if(e>0)return e;i.richNew??=[];let r=i.richNew.findIndex(o=>o.rv===t);r<0&&(r=i.richNew.push({rv:t})-1);const n=(i.richSource?.vmCount??0)+r+1;return s.added.set(n,t),n}const I={4:4,8:8,9:11,10:12,11:14,12:13,13:9,14:10,17:10};function C(i){const t=i.richValues;if(t){for(const s of i.sheets)if(s.valueMeta!==null)for(const[e,r]of s.valueMeta){const n=t.indexOfVm(r);if(n<0||t.type(n)!=="_error")continue;const o=I[Number(t.entries(n).get("errorType")?.v)],a=Math.floor(e/16384),c=e-a*16384,u=s.kind(a,c);o!==void 0&&(u&7)===4&&s.setCell(a,c,u,o)}}}function P(i,t,s,e){const r=i.richValues;if(!r||t.valueMeta===null)return null;const n=t.valueMeta.get(s*16384+e);if(n===void 0)return null;const o=r.indexOfVm(n);if(o<0)return null;const a=t.formula(s,e),c=a?.f??a?.sf??"",u=r.view(o,/(?:^|[^\w.])(?:_xlfn\.)?(?:_xlws\.)?PY\(/i.test(c));return u?{rich:r,index:o,view:u}:null}export{N as RICH_PARTS,V as RichValues,C as adoptRichErrors,P as cellRich,U as entityVm,v as errorText,T as fieldValue,M as readRichValues,D as richValueAt,E as vmIndex};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{escapeMarkup as s}from"../io/xml-escape.js";const l=e=>e.val!=="0"&&e.val!=="false",n={single:1,double:2,singleAccounting:3,doubleAccounting:4,none:0},r=[null,"single","double","singleAccounting","doubleAccounting"];function m(e,o,i){switch(o){case"b":e.b=l(i);break;case"i":e.i=l(i);break;case"strike":e.strike=l(i);break;case"condense":e.condense=l(i);break;case"extend":e.extend=l(i);break;case"outline":e.outline=l(i);break;case"shadow":e.shadow=l(i);break;case"u":e.u=n[i.val??"single"]??1;break;case"vertAlign":(i.val==="superscript"||i.val==="subscript")&&(e.va=i.val);break;case"sz":e.sz=Number(i.val);break;case"rFont":e.name=i.val;break;case"family":e.family=i.val;break;case"charset":e.charset=i.val;break;case"scheme":e.scheme=i.val;break;case"color":e.color=i,e.colorAttrs={...i};break;default:}}function b(e){return e.colorAttrs?`<color ${Object.entries(e.colorAttrs).map(([o,i])=>`${o}="${s(i)}"`).join(" ")}/>`:typeof e.color=="string"&&/^#[0-9a-f]{6}$/i.test(e.color)?`<color rgb="FF${e.color.slice(1).toUpperCase()}"/>`:""}function v(e){const{at:o,...i}=e;if(Object.keys(i).length===0)return"";let c="";return e.b&&(c+="<b/>"),e.i&&(c+="<i/>"),e.strike&&(c+="<strike/>"),e.condense&&(c+="<condense/>"),e.extend&&(c+="<extend/>"),e.outline&&(c+="<outline/>"),e.shadow&&(c+="<shadow/>"),e.u&&(c+=e.u===1?"<u/>":`<u val="${r[e.u]??"single"}"/>`),e.va&&(c+=`<vertAlign val="${e.va}"/>`),e.sz&&(c+=`<sz val="${e.sz}"/>`),c+=b(e),e.name&&(c+=`<rFont val="${s(e.name)}"/>`),e.family&&(c+=`<family val="${s(e.family)}"/>`),e.charset&&(c+=`<charset val="${s(e.charset)}"/>`),e.scheme&&(c+=`<scheme val="${s(e.scheme)}"/>`),c===""?"":`<rPr>${c}</rPr>`}function k(e,o,i){let c="<si>";const t=o[0]?.at??0;t>0&&(c+=`<r><t xml:space="preserve">${i(e.slice(0,t))}</t></r>`);for(let a=0;a<o.length;a++){const f=o[a+1]?.at??e.length;f<=o[a].at||(c+=`<r>${v(o[a])}<t xml:space="preserve">${i(e.slice(o[a].at,f))}</t></r>`)}return`${c}</si>`}function p(e,o){if(!e.rich)return null;const i=[];for(const[c,t]of e.rich)c>=o&&i.push([c-o,t]);return i.length>0?i:null}export{m as readRunProp,p as richExtras,k as richSiXml,v as runPropsXml};
|
package/cells/rounded.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{undoGroup as S}from"./undo-group.js";function g(t){const e=String(t??"").trim().split(/[\s,]+/).filter(Boolean).map(Number);if(e.length===0||e.length>4||e.some(m=>!Number.isFinite(m)||m<0))return null;const[o,n=o,i=o,c=n]=e;return o===0&&n===0&&i===0&&c===0?null:[o,n,i,c]}function b(t,e,o,n="all"){const i=g(o),{sheet:c}=t;S(t,"border-radius",()=>{if(t.applyStyle(e,{ext:{radius:null}}),i===null)return;if(n!=="outer"){t.applyStyle(e,{ext:{radius:i}});return}const m=(r,l)=>r.sizeOf(l)>0;for(const r of e){let l=r.r0,s=r.r1,a=r.c0,u=r.c1;for(;l<s&&!m(c.rows,l);)l++;for(;s>l&&!m(c.rows,s);)s--;for(;a<u&&!m(c.cols,a);)a++;for(;u>a&&!m(c.cols,u);)u--;const v=new Map,q=(p,f,d)=>{const T=p*16384+f,h=v.get(T)??{r:p,c:f,radii:[0,0,0,0]};h.radii[d]=i[d],v.set(T,h)};q(l,a,0),q(l,u,1),q(s,u,2),q(s,a,3);for(const{r:p,c:f,radii:d}of v.values())t.applyStyle([{r0:p,c0:f,r1:p,c1:f}],{ext:{radius:d}})}})}function B(t,e,o,n,i,c,m){const r=Math.min(n,i)/2,[l,s,a,u]=c.map(v=>Math.min(v*m,r));t.beginPath(),t.moveTo(e+l,o),t.lineTo(e+n-s,o),t.quadraticCurveTo(e+n,o,e+n,o+s),t.lineTo(e+n,o+i-a),t.quadraticCurveTo(e+n,o+i,e+n-a,o+i),t.lineTo(e+u,o+i),t.quadraticCurveTo(e,o+i,e,o+i-u),t.lineTo(e,o+l),t.quadraticCurveTo(e,o,e+l,o),t.closePath()}const P={thin:1,hair:1,dotted:1,dashed:1,dashDot:1,dashDotDot:1,medium:2,mediumDashed:2,mediumDashDot:2,mediumDashDotDot:2,slantDashDot:2,thick:3,double:3};function N(t,e,o,n,i,c,m,r){const l=Math.min(n,i)/2,[s,a,u,v]=c.map(C=>Math.min(C*m,l)),q=Math.max(1,Math.round(m)),p=(C,M)=>{C&&(t.strokeStyle=C.color,t.lineWidth=(P[C.style]??1)*q,t.beginPath(),M(),t.stroke())},f=q/2,d=e+f,T=o+f,h=e+n-f,D=o+i-f;p(r.t,()=>{t.moveTo(d+s,T),t.lineTo(h-a,T),r.r&&t.quadraticCurveTo(h,T,h,T+a)}),p(r.r,()=>{t.moveTo(h,T+a),t.lineTo(h,D-u),r.b&&t.quadraticCurveTo(h,D,h-u,D)}),p(r.b,()=>{t.moveTo(h-u,D),t.lineTo(d+v,D),r.l&&t.quadraticCurveTo(d,D,d,D-v)}),p(r.l,()=>{t.moveTo(d,D-v),t.lineTo(d,T+s),r.t&&t.quadraticCurveTo(d,T,d+s,T)})}export{g as parseRadius,B as roundedPath,b as setBorderRadius,N as strokeRounded};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{CELLS_NS as h,cellTypePart as f}from"../celltypes/persist.js";import{children as m,parseTree as x,unescapeOoxml as u}from"../io/xml-scan.js";import{escapeMarkup as $,safeJson as g,xmlAttr as d}from"../io/xml-escape.js";const l=new Map;function E(t,n){l.set(t,n)}function p(t,n){const s=n.map(([o,r])=>`<section name="${$(o)}" data="${d(g(r))}"/>`).join("");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
2
|
+
<cells xmlns="${h}" version="1"${t===null?"":` sheet="${d(t)}"`}>${s}</cells>`}function T(t){const n=[],s=[];for(const[o,r]of l){const e=r.book?.save?.(t);e!==void 0&&s.push([o,e])}return s.length>0&&n.push(f(0,p(null,s),"cells8c")),t.sheets.forEach((o,r)=>{const e=[];for(const[a,c]of l){const i=c.sheet?.save?.(o,t);i!==void 0&&e.push([a,i])}e.length>0&&n.push(f(r+1,p(o.name,e),"cells8c"))}),n}function w(t,n){let s;try{s=x(new TextEncoder().encode(t))}catch{return}if(s?.n!=="cells")return;const o=u(s.a?.sheet),r=o===void 0?null:n.sheets.find(e=>e.name===o);if(!(o!==void 0&&!r))for(const e of m(s,"section")){const a=l.get(e.a.name);if(a)try{const c=JSON.parse(u(e.a.data??"null"));r?a.sheet?.load(r,c,n):a.book?.load(n,c)}catch(c){console.warn(`Skipped section ${e.a.name}`,c)}}}export{T as cellsPackage,w as loadCellsPart,E as registerSection};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MAX_COLS as h,MAX_ROWS as m}from"../core/address.js";import{viewGet as k}from"./book-view.js";const x=o=>o.statusBar?.refreshFlags();function v(o,r){o.selMode=o.selMode===r?null:r,o.addBase=o.selMode==="add"?o.sel.ranges.slice():null,x(o.app)}function B(o){!o.selMode&&!o.endMode||(o.selMode=null,o.addBase=null,o.endMode=!1,x(o.app))}function L(o){o.endMode=!o.endMode,x(o.app)}function Y(o){o.scrollLock=!o.scrollLock,x(o.app)}const A=o=>o.r0===o.r1&&o.c0===o.c1;function p(o,r,t,e){if(e||o.selMode==="extend"){o.moveTo(r,t,!0);return}if(o.selMode==="add"){const n=Math.max(0,Math.min(r,m-1)),s=Math.max(0,Math.min(t,h-1)),a=o.sel.ranges[o.sel.ranges.length-1];(o.addBase===null||!A(a))&&(o.addBase=o.sel.ranges.slice()),o.grid.setSelection({ranges:[...o.addBase,o._withMerges({r0:n,c0:s,r1:n,c1:s})],row:n,col:s}),o.extent={row:n,col:s},o.grid.ensureVisible(n,s);return}o.moveTo(r,t,!1)}function V(o,r,t,{jump:e=!1,shift:n=!1}={}){const s=r==="col"&&o.grid.rtl?-t:t,{sheet:a}=o;if(e&&!n&&o.book.view?.deselectKeys&&_(o,r,s))return;const i=n||o.selMode==="extend";if(o.scrollLock&&!e){y(o,r,s);return}const l=i?o.extent:{row:o.sel.row,col:o.sel.col},g=o.endMode;g&&(o.endMode=!1,x(o.app));const c=e||g;if(r==="row"){const f=c?a.jumpRow(l.row,l.col,s):o._step("row",l.row,s);p(o,f,l.col,n)}else{const f=c?a.jumpCol(l.row,l.col,s):o._step("col",l.col,s);p(o,l.row,f,n)}}function _(o,r,t){const{sel:e}=o;if(e.ranges.reduce((g,c)=>g+(c.r1-c.r0+1)*(c.c1-c.c0+1),0)<2)return!1;const s=T(e.ranges,{r0:e.row,c0:e.col,r1:e.row,c1:e.col}),a=e.row+(r==="row"?t:0),i=e.col+(r==="col"?t:0),l=z(s,a,i)?{row:a,col:i}:{row:s[s.length-1].r0,col:s[s.length-1].c0};return o.grid.setSelection({ranges:s,row:l.row,col:l.col}),o.grid.ensureVisible(l.row,l.col),!0}function y(o,r,t){const{grid:e,sheet:n}=o;if(e.pageLayout){r==="row"?e.scrollTo(e.scrollX,e.scrollY+t*n.rows.defaultSize):e.scrollTo(e.scrollX+t*n.cols.defaultSize,e.scrollY);return}const s=e._frozen();if(r==="row"){const a=n.rows.indexAt(e.scrollY+s.h),i=Math.max(n.frozenRows,o._step("row",a,t));e.scrollTo(e.scrollX,n.rows.offsetOf(i)-s.h)}else{const a=n.cols.indexAt(e.scrollX+s.w),i=Math.max(n.frozenCols,o._step("col",a,t));e.scrollTo(n.cols.offsetOf(i)-s.w,e.scrollY)}}function E(o,r,t,e){const{grid:n,sheet:s}=o,a=e||o.selMode==="extend"?o.extent:{row:o.sel.row,col:o.sel.col};if(r==="col"){const g=(n.cssW-n.rowHeaderW)/n.zoom,c=s.cols.indexAt(Math.max(0,s.cols.offsetOf(a.col)+t*g));n.scrollTo(n.scrollX+t*g,n.scrollY),p(o,a.row,c,e);return}const i=(n.cssH-n.colHeaderH)/n.zoom,l=s.rows.indexAt(Math.max(0,s.rows.offsetOf(a.row)+t*i));n.scrollTo(n.scrollX,n.scrollY+t*i),p(o,l,a.col,e)}function H(o,r,t){const{sheet:e}=o,n=t||o.selMode==="extend"?o.extent:{row:o.sel.row};p(o,r?e.frozenRows:n.row,e.frozenCols,t)}function W(o,r){const{sheet:t}=o;p(o,Math.max(t.maxRow,0),Math.max(t.maxCol,0),r)}function I(o){const{sel:r}=o,t=r.ranges.map(e=>({r0:0,c0:e.c0,r1:m-1,c1:e.c1}));o.grid.setSelection({ranges:t,row:r.row,col:r.col}),o.extent={row:m-1,col:t[t.length-1].c1}}function P(o){const{sel:r}=o,t=r.ranges.map(e=>({r0:e.r0,c0:0,r1:e.r1,c1:h-1}));o.grid.setSelection({ranges:t,row:r.row,col:r.col}),o.extent={row:t[t.length-1].r1,col:h-1}}function U(o){const{sel:r}=o,t=r.ranges.find(l=>r.row>=l.r0&&r.row<=l.r1&&r.col>=l.c0&&r.col<=l.c1)??r.ranges[r.ranges.length-1],e=[[t.r0,t.c0],[t.r0,t.c1],[t.r1,t.c1],[t.r1,t.c0]];let n=e.findIndex(([l,g])=>l===r.row&&g===r.col);n=n<0?0:n;let s=(n+1)%4;for(;e[s][0]===r.row&&e[s][1]===r.col&&s!==n;)s=(s+1)%4;const[a,i]=e[s];o.grid.setSelection({ranges:r.ranges,row:a,col:i}),o.extent={row:a===t.r0?t.r1:t.r0,col:i===t.c0?t.c1:t.c0},o.grid.ensureVisible(a,i)}function D(o){const{sel:r}=o,t=o._withMerges({r0:r.row,c0:r.col,r1:r.row,c1:r.col});o.grid.setSelection({ranges:[t],row:r.row,col:r.col}),o.extent={row:r.row,col:r.col},o.grid.ensureVisible(r.row,r.col)}const C={down:[1,0],up:[-1,0],right:[0,1],left:[0,-1],none:[0,0]};function F(o,r){const[t,e]=C[k(o.book,"enterDirection")]??C.down;return r?[-t,-e]:[t,e]}function G(o,r,t){const{sel:e}=o;let n=e.ranges.length-1;for(let w=0;w<e.ranges.length;w++){const u=e.ranges[w];e.row>=u.r0&&e.row<=u.r1&&e.col>=u.c0&&e.col<=u.c1&&(n=w)}const s=e.ranges[n],a=w=>w.r0===0&&w.r1>=m-1?Math.min(w.r1,Math.max(o.sheet.maxRow,w.r0)):w.r1,i=w=>w.c0===0&&w.c1>=h-1?Math.min(w.c1,Math.max(o.sheet.maxCol,w.c0)):w.c1,l=a(s),g=i(s);let{row:c,col:f}=e;const d=o.sheet.mergeAt(c,f),M=w=>{const u=e.ranges.length,S=e.ranges[(n+(w?1:-1)+u)%u],b={row:a(S),col:i(S)};return w?{row:S.r0,col:S.c0}:b};r!==0?(c=r>0?(d?d.r1:c)+1:(d?d.r0:c)-1,c>l?(c=s.r0,f+=1,f>g&&({row:c,col:f}=M(!0))):c<s.r0&&(c=l,f-=1,f<s.c0&&({row:c,col:f}=M(!1)))):t!==0&&(f=t>0?(d?d.c1:f)+1:(d?d.c0:f)-1,f>g?(f=s.c0,c+=1,c>l&&({row:c,col:f}=M(!0))):f<s.c0&&(f=g,c-=1,c<s.r0&&({row:c,col:f}=M(!1))));const R=o.sheet.mergeAt(c,f);R&&(c=R.r0,f=R.c0),o.grid.setSelection({ranges:e.ranges,row:c,col:f}),o.grid.ensureVisible(c,f)}function K(o,r){const{sheet:t,book:e,sel:n}=o,s=Math.max(t.maxRow,n.row),a=Math.max(t.maxCol,n.col);let{row:i,col:l}=n;const g=(s+1)*(a+1);for(let c=0;c<Math.min(g,5e5);c++)if(l+=r,l>a?(l=0,i=i>=s?0:i+1):l<0&&(l=a,i=i<=0?s:i-1),e.styles.get(t.style(i,l)).unlocked===!0)return o.moveTo(i,l),!0;return!1}function T(o,r){const t=[];for(const e of o){if(r.r1<e.r0||r.r0>e.r1||r.c1<e.c0||r.c0>e.c1){t.push(e);continue}e.r0<r.r0&&t.push({r0:e.r0,c0:e.c0,r1:r.r0-1,c1:e.c1}),e.r1>r.r1&&t.push({r0:r.r1+1,c0:e.c0,r1:e.r1,c1:e.c1});const n=Math.max(e.r0,r.r0),s=Math.min(e.r1,r.r1);e.c0<r.c0&&t.push({r0:n,c0:e.c0,r1:s,c1:r.c0-1}),e.c1>r.c1&&t.push({r0:n,c0:r.c1+1,r1:s,c1:e.c1})}return t}const z=(o,r,t)=>o.some(e=>r>=e.r0&&r<=e.r1&&t>=e.c0&&t<=e.c1);function N(o,r){const{grid:t,sel:e}=o,n=T(r.before,r.cut);if(n.length===0){const i={r0:r.cut.r0,c0:r.cut.c0,r1:r.cut.r0,c1:r.cut.c0};t.setSelection({ranges:[i],row:i.r0,col:i.c0});return}const s=z(n,e.row,e.col),a=n[n.length-1];t.setSelection({ranges:n,row:s?e.row:a.r0,col:s?e.col:a.c0})}function j(o,r){let{ranges:t}=o;const e=r.selectionPolicy,n=r.selectionUnit;return e==="single"?t=[{r0:o.row,c0:o.col,r1:o.row,c1:o.col}]:e==="range"&&(t=[t[t.length-1]]),n==="row"?t=t.map(s=>({r0:s.r0,c0:0,r1:s.r1,c1:h-1})):n==="column"&&(t=t.map(s=>({r0:0,c0:s.c0,r1:m-1,c1:s.c1}))),t===o.ranges?o:{...o,ranges:t}}export{V as arrow,B as clearSelMode,D as collapseToActive,j as constrainSelection,G as cycleInSelection,F as enterStep,N as finishDeselect,H as home,z as inRanges,W as lastCell,U as nextCorner,K as nextUnlocked,E as page,I as selectColumn,P as selectRow,v as setSelMode,T as subtractRange,L as toggleEndMode,Y as toggleScrollLock};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function u(t,r,n){const o=r(t).map(e=>({pos:Number(e.pos),color:n(e.color)??"#FFFFFF"})).filter(e=>Number.isFinite(e.pos)).sort((e,p)=>e.pos-p.pos);if(o.length===0)return null;const i=t.a.type==="path"?{type:"path",left:Number(t.a.left??0),right:Number(t.a.right??0),top:Number(t.a.top??0),bottom:Number(t.a.bottom??0),stops:o}:{type:"linear",degree:Number(t.a.degree??0),stops:o};return{fill:o[0].color,gradient:i}}const s=t=>`rgb="FF${t.slice(1).toUpperCase()}"`;function a(t){const r=t.stops.map(o=>`<stop position="${o.pos}"><color ${s(o.color)}/></stop>`).join("");return`<fill><gradientFill${t.type==="path"?` type="path" left="${t.left??0}" right="${t.right??0}" top="${t.top??0}" bottom="${t.bottom??0}"`:` degree="${t.degree??0}"`}>${r}</gradientFill></fill>`}const l={2:"double",3:"singleAccounting",4:"doubleAccounting"},c={double:2,singleAccounting:3,doubleAccounting:4,none:0},b=t=>c[t]??1,m=t=>l[t]?`<u val="${l[t]}"/>`:"<u/>";export{a as gradientFillXml,u as parseGradientFill,b as underlineFromFile,m as underlineXml};
|
|
@@ -0,0 +1,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,L=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]/,x=/[\p{L}]/u;function at(e,t){if(t===null||!L.test(t)||e===1)return null;if(e===2)return"rtl";const l=x.exec(t);return l!==null&&L.test(l[0])?"rtl":null}function ut(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 ht(e,t,l){for(let s=0;s<t.length;s+=6){const[n,f,o,a,i,r]=[t[s],t[s+1],t[s+2],t[s+3],t[s+4],t[s+5]],h=f,F=f+a;r.fill!==null&&(e.beginPath(),e.moveTo(n,F),e.lineTo(n+o,F),e.lineTo(n+o+i,h),e.lineTo(n+i,h),e.closePath(),e.fillStyle=r.fill,e.fill());const p=r.borders;if(p==null)continue;const d=(u,b,A,T,g)=>{u&&(e.beginPath(),e.moveTo(b,A),e.lineTo(T,g),e.strokeStyle=u.color,e.lineWidth=Math.max(1,Math.round(l))*(u.style==="medium"?2:u.style==="thick"?3:1),e.stroke())};d(p.l,n+.5,F,n+i+.5,h),d(p.r,n+o+.5,F,n+o+i+.5,h),d(p.t,n+i,h+.5,n+o+i,h+.5),d(p.b,n,F+.5,n+o,F+.5)}}function ct(e,t){if(!L.test(e))return e;const s=(e.match(/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+(?:\s+[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+)*|[^\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFC]+/g)??[]).map(n=>L.test(n)?[...n].reverse().join(""):n);return(t?s.reverse():s).join("")}const tt=e=>e.hAlign==="justify"||e.hAlign==="distributed"||e.vAlign==="justify"||e.vAlign==="distributed";function dt(e,t,l,s,n,f){let o=n;for(let a=s+1;a<Y&&!((t.kind(l,a)&15)!==0||t.mergeAt(l,a)!==null||e.book.styles.get(t.style(l,a)).hAlign!=="centerContinuous");a++)o+=Math.round(t.cols.sizeOf(a)*f);return o}function et(e,t,l,s,n){const f=t.split(/\s+/).filter(Boolean);if(f.length<2){e.fillText(t,l+(s-n)/2,e._by);return}const o=f.reduce((r,h)=>r+e.measureText(h).width,0),a=(s-o)/(f.length-1);let i=l;for(const r of f)e.fillText(r,i,e._by),i+=e.measureText(r).width+a}function gt(e,t,l,s,n,f,o,a,i,r,h,F){const p=s.indent>0?Math.round(s.indent*H*F):0;let d=f+r,u=f+a-r;p>0&&(n==="left"||n==="justify"?d+=p:n==="right"?u-=p:n==="distributed"&&(d+=p,u-=p));const b=Math.max(1,u-d),A=e._wrapLines(t,s._font,l,b),T=Math.round(h*1.26),g=A.length*T,m=s.vAlign??"bottom";let _,M=T;m==="top"?_=o:m==="center"?_=o+(i-g)/2:m==="justify"?(_=o,A.length>1&&g<i&&(M=(i-T)/(A.length-1))):m==="distributed"?(_=A.length===1?o+(i-T)/2:o,A.length>1&&g<i&&(M=(i-T)/(A.length-1))):_=o+i-g,t.save(),t.beginPath(),t.rect(f,o,a,i),t.clip(),t.textAlign="left";const E=nt(l,A);for(let k=0;k<A.length;k++){const c=_+k*M+Math.round(T*.8);if(c+T<o||c-T>o+i)continue;const O=A[k],S=t.measureText(O).width;let w=d;if(n==="center"||n==="centerContinuous"?w=d+(b-S)/2:n==="right"&&(w=u-S),t._by=c,n==="distributed"||n==="justify"&&!E.has(k)&&S<b){n==="justify"&&O.trim().split(/\s+/).length<2?t.fillText(O,d,c):et(t,O,d,b,S),(s.underline||s.strike)&&e._decorate(t,s,d,c,n==="distributed"&&O.trim().split(/\s+/).length<2?S:b,h);continue}t.fillText(O,w,c),(s.underline||s.strike||s.ext!==void 0)&&e._decorate(t,s,w,c,S,h)}t.restore(),t.textAlign="left"}function nt(e,t){const l=new Set([t.length-1]);if(e.indexOf(`
|
|
2
|
+
`)<0)return l;let s=0;for(let n=0;n<t.length;n++)s=e.indexOf(t[n],s)+t[n].length,e[s]===`
|
|
3
|
+
`&&l.add(n);return l}function q(e,t,l,s){const n=[],f=t===null?[{at:0}]:t[0].at>0?[{at:0},...t]:t;for(let o=0;o<f.length;o++){const a=f[o+1]?.at??e.length;if(a<=f[o].at)continue;const i=Z(l,f[o]),r=i.fontSize*s;n.push({text:e.slice(f[o].at,a),look:i,px:r,font:V(i,i.vertAlign?r*.66:r),shift:i.vertAlign==="superscript"?-r*.34:i.vertAlign==="subscript"?r*.1:0})}return n}function ot(e,t,l,s,n,f,o,a,i,r,h,F){const p=q(l,s,n,h),d=[];for(const c of p)for(const O of c.text)d.push({ch:O,seg:c});const u=[[]],b=Math.round(n.fontSize*h*1.28),A=Math.max(1,Math.floor(r/b));let T=[];const g=()=>{const c=u[u.length-1];c.length>0&&c.length+T.length>A?u.push([...T]):c.push(...T),T=[]};for(const c of d){if(c.ch===`
|
|
4
|
+
`){g(),u.push([]);continue}if(!n.wrap){u[u.length-1].push(c);continue}T.push(c),c.ch===" "&&g()}T.length>0&&g();const m=Math.round(n.fontSize*h*1.6),_=u.length*m,M=n.indent>0?Math.round(n.indent*H*h):0;let E;f==="right"?E=o+i-_-M:f==="left"?E=o+M:E=o+(i-_)/2;const k=n.vAlign??"bottom";t.save(),t.beginPath(),t.rect(o,a,i,r),t.clip(),t.textAlign="center",u.forEach((c,O)=>{const S=c.length*b;let w;k==="top"?w=a:k==="center"?w=a+(r-S)/2:w=a+r-S;const R=E+O*m+m/2;c.forEach((v,D)=>{t.font=v.seg.font,t.fillStyle=v.seg.look.color??F,t.fillText(v.ch,R,w+D*b+b*.8)})}),t.restore(),t.textAlign="left"}function pt(e,t,l,s,n,f,o,a,i,r,h,F){if(n.rotation===255){ot(e,t,l,s,n,f,o,a,i,r,h,F);return}const p=n.rotation>90?90-n.rotation:n.rotation,d=p*Math.PI/180,u=Math.abs(Math.sin(d)),b=Math.abs(Math.cos(d)),A=q(l,s,n,h),T=Math.max(...A.map(C=>C.px),n.fontSize*h),g=Math.round(T*1.26),m=Math.round(2*h),_=u>.01?(r-m*2)/u-g*b/u:1/0,M=[{parts:[],width:0}];for(const C of A)t.font=C.font,C.text.split(`
|
|
5
|
+
`).forEach((z,B)=>{B>0&&M.push({parts:[],width:0});const I=n.wrap||tt(n),X=I?z.match(/\S+\s*|\s+/g)??[]:[z];for(const K of X){const G=t.measureText(K).width,Q=M[M.length-1];I&&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*g,k=Math.max(...M.map(C=>C.width)),c=k*u+E*b,O=n.vAlign??"bottom",S=O==="top"?Math.max(0,r-c-m*2):O==="center"?Math.max(0,r-c-m*2)/2:0,w=p>0,R=Math.abs(p)===90,v=n.hAlign??(it(p)?"right":"left"),D=n.indent>0?Math.round(n.indent*H*h):0,j=E*u;let y;v==="right"?y=i-j-D-(w?0:5):v==="center"||v==="centerContinuous"?y=i/2+(R?j/2:0)-(w?0:j/2):y=(w?j:0)+m+D+0,!w&&v==="left"&&(y=j+m+D);const W=u>.01&&b>.01?S*(b/u):0;t.save(),t.beginPath();const N=k*b+E*u+W+i;if(t.rect(w?o:o-N,a,w?N:N+i,r),t.clip(),R){const C=v==="right"?o+i-E-m-D:v==="center"||v==="centerContinuous"?o+(i-E)/2:o+m+D,P=(v==="justify"||v==="distributed")&&M.length>1?(i-m*2-g)/(M.length-1):g,z=w?C:C+(M.length-1)*P+g,B=w?a+r-m-S:a+r-m-S-k;t.translate(z,B),t.rotate(-d),t.textAlign="left",M.forEach((I,X)=>J(e,t,I,X*P+g-g*.22,k,v,F))}else if(w)t.translate(o+y+W-j+E*u,a+r-m-S-E*b),t.rotate(-d),t.textAlign="left",M.forEach((C,P)=>J(e,t,C,(P+1)*g-g*.22,k,v,F));else{const C=o+y-W,P=a+r-m-S-E*b;t.translate(C,P),t.rotate(-d),t.textAlign="left",M.forEach((z,B)=>J(e,t,z,(B+1)*g-g*.22-0,k,v,F,-k))}t.restore(),t.textAlign="left"}const it=e=>e===90||e<0&&e>-90;function J(e,t,l,s,n,f,o,a=0){let i=a;f==="center"||f==="centerContinuous"?i+=(n-l.width)/2:f==="right"&&(i+=n-l.width);for(const r of l.parts)t.font=r.seg.font,t.fillStyle=r.seg.look.color??o,t.fillText(r.text,i,s+r.seg.shift),(r.seg.look.underline||r.seg.look.strike)&&e._decorate(t,{underline:r.seg.look.underline??0,strike:r.seg.look.strike},i,s,r.width,r.seg.px),i+=r.width}function mt(e,t,l,s){let n=0,f=0;for(const o of q(t,l,s,1))e.font=o.font,o.text.split(`
|
|
6
|
+
`).forEach((i,r)=>{r>0&&(n=Math.max(n,f),f=0),f+=e.measureText(i).width});return Math.max(n,f)}function Mt(e,t,l){const s=l.fontSize;if(l.rotation===255){const F=t.split(`
|
|
7
|
+
`),p=Math.max(...F.map(d=>d.length));return{w:F.length*Math.round(s*1.3)+4,h:p*Math.round(s*1.2)+4}}const f=(l.rotation>90?90-l.rotation:l.rotation)*Math.PI/180,o=Math.abs(Math.sin(f)),a=Math.abs(Math.cos(f)),i=t.split(`
|
|
8
|
+
`);e.font=V(l,s);const r=Math.max(...i.map(F=>e.measureText(F).width)),h=i.length*Math.round(s*1.26);return{w:r*a+h*o+4,h:r*o+h*a+4}}$("textOverflow",{sheet:{save:e=>e.noCellOverflow===!0?!0:void 0,load(e,t){t===!0&&(e.noCellOverflow=!0)}}});export{dt as acrossWidth,pt as paintRotatedText,ht as paintSlantedCells,gt as paintWrappedText,at as readingDirection,mt as richWidth,Mt as rotatedSize,ut as slantOf,ct as visualOrder,tt as wrapsByAlign};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CellLog as f}from"../core/workbook.js";import{growTableOver as h}from"../core/tables.js";function g(e,t,i,{withPrevious:d=!1}={}){const n=e.undoStack[e.undoStack.length-1];if(i(),e.undoStack[e.undoStack.length-1]===n)return;const o=n===void 0?0:e.undoStack.lastIndexOf(n)+1,l=d?Math.max(0,o-1):o,s=e.undoStack.splice(l);if(s.length===0)return;const u=c=>()=>{const a=[];for(let r=c.length-1;r>=0;r--)a.push(e._restore(c[r]));return u(a)};e.undoStack.push({sheetIndex:e.activeSheet,sheet:e.sheet,log:new f,label:t,extra:u(s)})}function m(e,t){!e.book.engine||e.slicers?.autoExpands===!1||g(e.book,"paste",()=>h(e.book,e.book.sheet,t),{withPrevious:!0})}export{m as growTableAfter,g as undoGroup};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{el as l,openModal as y}from"../ui/dialogs.js";import{t as c}from"../i18n/index.js";const b="This value doesn't match the data validation rules for this cell.";function C(i,a,t){const o=a.errorStyle==="warning"||a.errorStyle==="information"?a.errorStyle:"stop",s=a.error||c(b);let r=!1;const e=n=>()=>{r=!0,queueMicrotask(n)},u=l("div",{class:"dlg-col"},...s.split(`
|
|
2
|
+
`).map(n=>l("p",{class:"dlg-message",textContent:n})),o==="warning"?l("p",{class:"dlg-message",textContent:c("Continue?")}):null),p=o==="stop"?[{label:"Cancel",action:e(t.cancel)},{label:"Retry",primary:!0,action:e(t.retry)}]:o==="warning"?[{label:"Cancel",action:e(t.cancel)},{label:"No",action:e(t.retry)},{label:"Yes",primary:!0,action:e(t.accept)}]:[{label:"Cancel",action:e(t.cancel)},{label:"OK",primary:!0,action:e(t.accept)}],m=a.errorTitle||(o==="stop"?"Invalid value":o==="warning"?"Check this value":"Information");return y(i,m,u,p,{width:360,onClose:()=>{r||queueMicrotask(t.cancel)}})}export{C as askAboutInvalid};
|