@allyhub/sdk 0.12.0 → 0.13.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/CHANGELOG.md +8 -0
- package/dist/node_modules/@allyhub/audio/dist/plan.d.ts +3 -0
- package/dist/node_modules/@allyhub/audio/dist/render.js +1 -1
- package/dist/node_modules/@allyhub/audio/package.json +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-file.d.ts +2 -0
- package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +3 -2
- package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +5 -12
- package/dist/node_modules/@allyhub/chart/dist/chart.js +2 -1
- package/dist/node_modules/@allyhub/chart/dist/color.d.ts +37 -0
- package/dist/node_modules/@allyhub/chart/dist/color.js +2 -0
- package/dist/node_modules/@allyhub/chart/dist/index.d.ts +1 -0
- package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
- package/dist/node_modules/@allyhub/chart/package.json +1 -1
- package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +130 -0
- package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.d.ts +3 -1
- package/dist/node_modules/@allyhub/formats/dist/data/gen.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +512 -166
- package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +2523 -136
- package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
- package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +931 -87
- package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
- package/dist/node_modules/@allyhub/formats/package.json +1 -1
- package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
- package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
- package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
- package/dist/node_modules/@allyhub/measure/package.json +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/color.d.ts +11 -0
- package/dist/node_modules/@allyhub/ooxml/dist/color.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/ext.d.ts +43 -0
- package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.d.ts +2 -1
- package/dist/node_modules/@allyhub/ooxml/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/ooxml/dist/transform.d.ts +13 -0
- package/dist/node_modules/@allyhub/ooxml/dist/transform.js +2 -0
- package/dist/node_modules/@allyhub/ooxml/package.json +5 -1
- package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +4 -4
- package/dist/node_modules/@allyhub/piece/dist/media.d.ts +2 -2
- package/dist/node_modules/@allyhub/piece/package.json +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +35 -0
- package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +19 -0
- package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +35 -20
- package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +3 -3
- package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +28 -2
- package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +73 -10
- package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
- package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +9 -9
- package/dist/node_modules/@allyhub/protocol/package.json +1 -1
- package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
- package/dist/node_modules/@allyhub/scenery/package.json +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/annotations.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/annotations.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.d.ts +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.d.ts +24 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.d.ts +12 -0
- package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +3 -1
- package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.d.ts +28 -1
- package/dist/node_modules/@allyhub/sheet/dist/arrange.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.d.ts +42 -0
- package/dist/node_modules/@allyhub/sheet/dist/data-tools.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/edit.d.ts +43 -2
- package/dist/node_modules/@allyhub/sheet/dist/edit.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/fill.d.ts +10 -0
- package/dist/node_modules/@allyhub/sheet/dist/fill.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/filter.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.d.ts +14 -0
- package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
- package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +6 -1
- package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/outline.d.ts +30 -0
- package/dist/node_modules/@allyhub/sheet/dist/outline.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.d.ts +29 -0
- package/dist/node_modules/@allyhub/sheet/dist/rich.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/rules.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-style.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +5 -1
- package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +17 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.d.ts +56 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.js +2 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
- package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
- package/dist/node_modules/@allyhub/sheet/package.json +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +117 -21
- package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +181 -30
- package/dist/node_modules/@allyhub/slides-core/dist/api.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +28 -2
- package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/check.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +222 -4
- package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +3 -0
- package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +98 -10
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.d.ts +6 -0
- package/dist/node_modules/@allyhub/slides-core/dist/numbering.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +53 -0
- package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.d.ts +8 -0
- package/dist/node_modules/@allyhub/slides-core/dist/patterns.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +36 -6
- package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/script.d.ts +11 -0
- package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.d.ts +48 -0
- package/dist/node_modules/@allyhub/slides-core/dist/table-style.js +2 -0
- package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +1 -1
- package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +4 -0
- package/dist/node_modules/@allyhub/video-core/package.json +1 -1
- package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
- package/docs/defaults.md +78 -4
- package/docs/image.md +1 -1
- package/docs/pictures.md +1 -1
- package/docs/project.md +1 -1
- package/docs/sheets.md +19 -9
- package/docs/slides.md +30 -16
- package/docs/speech.md +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SheetFile, SheetTable, SheetWorksheet } from "@allyhub/formats";
|
|
1
|
+
import type { SheetFile, SheetRun, SheetTable, SheetWorksheet } from "@allyhub/formats";
|
|
2
2
|
import { type Area } from "./address.js";
|
|
3
3
|
import { restructure, type RefusedEdit } from "./structure.js";
|
|
4
4
|
import { type CellLook, type CsvRows, type SharedFormula, type Table, type Workbook, type Worksheet } from "./workbook.js";
|
|
@@ -48,7 +48,7 @@ export interface BookEdit {
|
|
|
48
48
|
/** CSV files no sheet names any more. */
|
|
49
49
|
removed?: string[];
|
|
50
50
|
}
|
|
51
|
-
export type EditRefused = RefusedEdit | "column-name" | "sheet-name" | "sheet-taken" | "name-invalid" | "merge-table" | "no-data" | "table-move";
|
|
51
|
+
export type EditRefused = RefusedEdit | "column-name" | "sheet-name" | "sheet-taken" | "name-invalid" | "merge-table" | "no-data" | "table-move" | "table-shift" | "merge-shift" | "table-overlap" | "table-room" | "rich-loose";
|
|
52
52
|
/** The most typed cells written as keys of `cells`: more go in a CSV file of their own, as a script's do. */
|
|
53
53
|
export declare const BLOCK_CELLS = 100;
|
|
54
54
|
export declare const blankEdit: () => BookEdit;
|
|
@@ -82,6 +82,12 @@ export declare class Draft {
|
|
|
82
82
|
}
|
|
83
83
|
export declare const movedTo: (text: string, rows: number, columns: number) => string;
|
|
84
84
|
export declare function writeOne(d: Draft, book: EditBook, sheet: Worksheet, row: number, col: number, text: string): BookEdit | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* A cell's text as rich text: its runs, alike ones joined. Runs that say
|
|
87
|
+
* nothing of their font are its plain text, written as typed; a table's or
|
|
88
|
+
* a block's cells are CSV's plain text and hold none.
|
|
89
|
+
*/
|
|
90
|
+
export declare function setRuns(book: EditBook, sheetName: string, row: number, col: number, runs: readonly SheetRun[]): BookEdit;
|
|
85
91
|
/** One cell written as typed, or several: `text` is what a person types there. */
|
|
86
92
|
export interface CellWrite {
|
|
87
93
|
row: number;
|
|
@@ -151,4 +157,39 @@ export declare function exceptionsOf(table: Table): {
|
|
|
151
157
|
column: string;
|
|
152
158
|
text: string;
|
|
153
159
|
}[];
|
|
160
|
+
/**
|
|
161
|
+
* Insert's Table and Home's Format as Table over cells: Excel's Create
|
|
162
|
+
* Table. The area's top row is its header (with no header, Excel's
|
|
163
|
+
* Column1, Column2), what the cells hold, as typed, goes to a CSV file of
|
|
164
|
+
* its own, and their looks stay where they are. Refused over a table.
|
|
165
|
+
*/
|
|
166
|
+
export declare function makeTable(book: EditBook, sheetName: string, area: Area, o: {
|
|
167
|
+
header: boolean;
|
|
168
|
+
style?: string | undefined;
|
|
169
|
+
}): BookEdit;
|
|
170
|
+
/** Format as Table over a table: its style; TableStyleMedium2 is a new table's, `none` none. */
|
|
171
|
+
export declare function setTableStyle(book: EditBook, sheetName: string, tableName: string, style: string): BookEdit;
|
|
172
|
+
/** Table Design's Table Style Options: each said only where it is not a new table's. */
|
|
173
|
+
export declare function setTableOptions(book: EditBook, sheetName: string, tableName: string, options: {
|
|
174
|
+
banded_rows?: boolean;
|
|
175
|
+
banded_columns?: boolean;
|
|
176
|
+
first_column?: boolean;
|
|
177
|
+
last_column?: boolean;
|
|
178
|
+
}): BookEdit;
|
|
179
|
+
/**
|
|
180
|
+
* Name Manager's New and Edit: a name, what it refers to as typed (a
|
|
181
|
+
* formula after =, or a value) and its scope, the workbook or a sheet. A
|
|
182
|
+
* name renamed is renamed in every formula that read it, as Excel does.
|
|
183
|
+
*/
|
|
184
|
+
export declare function setName(book: EditBook, o: {
|
|
185
|
+
name: string;
|
|
186
|
+
value: string;
|
|
187
|
+
scope?: string | undefined;
|
|
188
|
+
was?: {
|
|
189
|
+
name: string;
|
|
190
|
+
scope?: string | undefined;
|
|
191
|
+
} | undefined;
|
|
192
|
+
}): BookEdit;
|
|
193
|
+
/** Name Manager's Delete: a formula that read it then reads #NAME?, as Excel's does. */
|
|
194
|
+
export declare function deleteName(book: EditBook, name: string, scope?: string): BookEdit;
|
|
154
195
|
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{MAX_COLUMNS as K,MAX_ROWS as R,cellName as N,columnLetter as C,contains as q,overlaps as O,rangeName as M,readAddress as X,readArea as j}from"./address.js";import{moveFormula as z}from"./formula/move.js";import{parseFormula as D}from"./formula/parse.js";import{printFormula as G}from"./formula/print.js";import{freeColumn as B,duplicated as H,restructure as F,uniqueColumn as I,withColumnsUpTo as A}from"./structure.js";import{readTyped as T}from"./values.js";import{FormulaCell as P,placeKey as V,validName as J}from"./workbook.js";export const BLOCK_CELLS=100;const _=(n,o)=>n.top<=o.top&&n.left<=o.left&&n.bottom>=o.bottom&&n.right>=o.right,S=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o)),Q=n=>S(n,"formula"),b=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o));export const blankEdit=()=>({rows:new Map,cells:[],whole:!1}),refused=n=>({...blankEdit(),refused:n});const v=n=>T(n).formula!==void 0;function Y(n){const o=T(n);return o.formula!==void 0?n:o.value===null?null:o.format!==void 0?n:typeof o.value=="number"||typeof o.value=="boolean"?o.value:n}const Z=n=>n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([o])=>o!=="value"&&o!=="formula")):{};export class Draft{book;specs=new Map;file;fileChanged=!1;grown=new Map;added=new Map;edit=blankEdit();constructor(o){this.book=o,this.file=o.file}spec(o){let e=this.specs.get(o.index);if(!e){const t=this.file.sheets.findIndex(s=>s.name===o.name);e={...this.file.sheets[t]??{name:o.name}},this.specs.set(o.index,e),this.fileChanged||(this.file={...this.file,sheets:[...this.file.sheets]},this.fileChanged=!0),this.file.sheets[t]=e}return e}table(o,e){const t=this.spec(o),s=[...t.tables??[]],r=s.findIndex(l=>l.name===e.name),i={...s[r]??e.spec};return s[r]=i,t.tables=s,i}rows(o){const e=this.edit.rows.get(o);if(e)return e;const t=[...this.book.rows.get(o)??[]];return this.edit.rows.set(o,t),t}setField(o,e,t,s){const r=this.rows(o),i=[...r[e]??[]];for(;i.length<=t;)i.push("");return i[t]=s,r[e]=i,i}rowsOf(o){return this.grown.get(o)??o.rows}grow(o,e,t){this.grown.set(o,this.rowsOf(o)+1);const s=this.added.get(o)??new Map;s.set(e,t),this.added.set(o,s)}addedAt(o,e,t){for(const[s,r]of this.added){const i=r.get(e);if(i!==void 0&&s.sheet===o&&t>=s.at.col&&t<s.at.col+s.columns.length)return{table:s,record:i}}}finish(){return this.fileChanged&&(this.edit.file=this.file),this.edit}}function ee(n,o,e,t){return o.tables.find(s=>{const r=s.at.row+n.rowsOf(s)+1;if(e!==r)return!1;const i=s.at.col+s.columns.length-1;if(t<s.at.col||t>i)return!1;for(let l=s.at.col;l<=i;l++)if(o.at(e,l)!==void 0)return!1;return!0})}function te(n,o,e){return n.tables.find(t=>{const{top:s,bottom:r,right:i}=t.area;if(e!==i+1||o<s||o>r)return!1;for(let l=s;l<=r;l++)if(n.at(l,e)!==void 0)return!1;return!0})}export const movedTo=(n,o,e)=>{const t=D(n);return t.ok?G(z(t.node,o,e)):n};function E(n,o,e,t,s,r){const i=e.at.row+1,l=n.table(o,e),f=movedTo(r,i-s,0);if(l.columns={...l.columns,[t.name]:{...l.columns?.[t.name],formula:f}},t.csv!==void 0){const c=e.places[s-i];c!==void 0&&n.setField(e.file,c,t.csv,"")}n.edit.whole=!0}function ne(n,o,e,t){const{csv:s}=e;if(s===void 0)return!1;const r=n.rows(o.file);return o.places.some((i,l)=>l!==t&&(r[i]?.[s]??"")!=="")}function oe(n,o,e,t,s){const r=s.trim();if(r==="")return refused("column-name");if(r===t.name)return n.finish();const i=e.columns.filter(c=>c!==t).map(c=>c.name),l=I(i,r),f=F(o,{op:"rename-column",table:e.name,from:t.name,to:l});return{...blankEdit(),file:f.file,rows:new Map(f.rows),whole:!0}}function se(n,o,e,t,s,r){const i=e.columns[s-e.at.col];if(!i)return;const l=t-e.at.row-1;if(v(r)){if(i.formula){E(n,o,e,i,t,r);return}if(!ne(n,e,i,l)){E(n,o,e,i,t,r);return}n.edit.offer={sheet:o.name,row:t,col:s,text:r}}const c=e.places[l];if(c===void 0)return;let d=i.csv;if(d===void 0){if(r==="")return;const w=e.columns.map(p=>p.name);n.edit.rows.set(e.file,A(n.rows(e.file),w,i.index)),n.edit.whole=!0,d=i.index}const a=n.setField(e.file,c,d,r);n.edit.cells.push({sheet:o,row:t,col:s,...r===""&&i.formula?{column:i.formula}:{input:r},record:{table:e,index:l,fields:a}})}function re(n,o,e,t,s){const r=n.rows(o.file),i=Math.max(r[0]?.length??1,1),l=new Array(i).fill(""),f=o.columns[t-o.at.col];f?.csv!==void 0&&(l[f.csv]=s),r.push(l),n.grow(o,e,r.length-1),n.edit.whole=!0}function ie(n,o,e,t,s){const r=n.table(o,e),i=e.columns.map(w=>w.name),l=t===e.at.row,f=l?I(i,s.trim()===""?B(i):s.trim()):B(i);if(n.edit.whole=!0,!l&&v(s)){r.columns={...r.columns,[f]:{formula:movedTo(s,e.at.row+1-t,0)}};return}const c=i.length,d=A(n.rows(e.file),i,c-1),a=d[0];if(a&&a.push(f),d.forEach((w,p)=>{p>0&&w.length>0&&w.push("")}),!l){const w=e.places[t-e.at.row-1],p=w===void 0?void 0:d[w];p&&(p[c]=s)}n.edit.rows.set(e.file,d)}function le(n,o,e,t,s,r,i){n.setField(e,s-t.top,r-t.left,i),n.edit.cells.push({sheet:o,row:s,col:r,input:i})}function fe(n,o,e){return Object.keys(n.spec.cells??{}).some(t=>{if(!t.includes(":"))return!1;const s=j(t);return s!==void 0&&q(s,o,e)})}function ce(n,o,e,t,s){const r=n.spec(o),i=N({row:e,col:t});let l={...r.cells};const f=l[i],c=f===void 0?{}:Z(f),d=Y(s),a=Object.keys(c).length===0;let w;if(d===null){const p=fe(o,e,t);w=!a||p,a&&!p?l=b(l,i):l[i]=a?null:c}else w=!0,l[i]=a?d:{...c,...v(s)?{formula:s}:{value:d}};r.cells=l,Object.keys(l).length===0&&delete r.cells,n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:w?i:null})}export function writeOne(n,o,e,t,s,r){const i=n.addedAt(e,t,s);if(i){const{csv:c}=i.table.columns[s-i.table.at.col]??{};c!==void 0&&n.setField(i.table.file,i.record,c,r);return}const l=e.tableAt(t,s);if(l){const c=l.columns[s-l.at.col];if(t===l.at.row)return c?oe(n,o,l,c,r):void 0;se(n,e,l,t,s,r);return}if(r!==""){const c=ee(n,e,t,s);if(c){re(n,c,t,s,r);return}const d=te(e,t,s);if(d){ie(n,e,d,t,r);return}}const f=e.blockAt(t,s);f?le(n,e,f.file,f.area,t,s,r):ce(n,e,t,s,r)}export function writeCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const{row:r,col:i,text:l}of[...e].sort((f,c)=>f.row-c.row||f.col-c.col)){const f=writeOne(s,n,t,r,i,l);if(f)return f}return s.finish()}export function overwriteColumn(n,o,e,t,s){const r=n.workbook.sheet(o),i=r?.tableAt(e,t);if(!r||!i)return refused("no-sheet");const l=i.columns[t-i.at.col];if(!l)return refused("no-sheet");const f=new Draft(n);E(f,r,i,l,e,s);const{csv:c}=l;if(c!==void 0)for(const d of i.places)f.setField(i.file,d,c,"");return f.finish()}function*ue(n,o){const e=Math.min(o.right,n.columnsUsed-1);for(let t=o.left;t<=e;t++){const[s,r]=n.span(t,o.top,o.bottom);for(let i=s;i<=r;i++)n.at(i,t)!==void 0&&(yield[i,t])}}export function clearCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const r of t.tables){const{top:i,bottom:l}=r.data;if(!(l<i||e.top>i||e.bottom<l))for(const f of r.columns){const c=r.at.col+f.index;if(c<e.left||c>e.right||!f.formula)continue;const d=s.table(t,r),a=r.columns.map(L=>L.name);f.csv===void 0&&s.edit.rows.set(r.file,A(s.rows(r.file),a,f.index));const w=Q(d.columns?.[f.name]??{}),p=b(d.columns??{},f.name);d.columns=Object.keys(w).length>0?{...p,[f.name]:w}:p,Object.keys(d.columns).length===0&&delete d.columns,s.edit.whole=!0}}for(const[r,i]of ue(t,e)){if(t.tableAt(r,i)?.at.row===r)continue;const l=writeOne(s,n,t,r,i,"");if(l)return l}return s.finish()}export function dropKeys(n,o){n.cells&&(n.cells=Object.fromEntries(Object.entries(n.cells).filter(([e])=>{const t=j(e);return!t||!_(o,t)})))}export function fillCells(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");if(!r.tables.some(f=>O(f.area,t))&&!r.blocks.some(f=>O(f.area,t))&&v(s)){const f=new Draft(n),c=f.spec(r);dropKeys(c,t);const d=movedTo(s,t.top-e.row,t.left-e.col),a=M(t);return c.cells={...c.cells,[a]:d},f.edit.whole=!0,f.finish()}const l=[];for(let f=t.top;f<=t.bottom;f++)for(let c=t.left;c<=t.right;c++)f===e.row&&c===e.col||l.push({row:f,col:c,text:v(s)?movedTo(s,f-e.row,c-e.col):s});return writeCells(n,o,l)}export function writeBlockOf(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=new Draft(n),l=i.spec(r);return l.blocks=[...l.blocks??[],{at:N(e),rows:s}],i.edit.rows.set(s,t),i.edit.whole=!0,i.finish()}const $=(n,o)=>Object.keys(o).some(e=>e in n),x=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>!(e in o)));function de(n){if(n===null||typeof n!="object")return n;const o=Object.keys(n);return o.length===1&&o[0]==="value"?n.value??null:o.length===1&&o[0]==="formula"?n.formula??null:n}const me={bold:!1,italic:!1,underline:!1,strike:!1,wrap:!1,align:"general",format:"General",color:"#000000",fill:"#FFFFFF",font:"Calibri",size:11,border:{left:{style:"none"},right:{style:"none"},top:{style:"none"},bottom:{style:"none"}}};function ae(n,o,e,t){for(const[s,r]of Object.entries(n.columns??{})){const i=X(`${s}1`)?.col;if(i!==void 0&&i>=e.left&&i<=e.right&&t in r)return!0}for(const[s,r]of Object.entries(n.rows??{})){const i=Number(s)-1;if(i>=e.top&&i<=e.bottom&&t in r)return!0}return o.tables.some(s=>O(s.area,e)&&s.columns.some(r=>r.spec!==void 0&&t in r.spec&&s.at.col+r.index>=e.left&&s.at.col+r.index<=e.right))}export function setLook(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n);return applyLook(r,s,e,t),r.finish()}export function applyLook(n,o,e,t){const s=n.spec(o);he(n,o,s,e,t),tidied(s)}function he(n,o,e,t,s){if(e.cells){const u={...e.cells},m=[];for(const[g,h]of Object.entries(u)){if(h===null||typeof h!="object"||!$(h,s))continue;const y=j(g);!y||!O(y,t)||(g.includes(":")&&!_(t,y)&&m.push({range:g,...Object.fromEntries(Object.entries(h).filter(([W])=>W in s))}),u[g]=de(x(h,s)))}e.cells=u,m.length>0&&(e.format=[...e.format??[],...m])}const r=e.format??[],i=u=>{const m=j(u.range);return m!==void 0&&O(m,t)},l=r.some(u=>i(u)&&$(u,s)),f=Object.fromEntries(Object.entries(s).filter(([,u])=>u!==void 0)),c=t.top===0&&t.bottom===R-1,d=t.left===0&&t.right===K-1;if(c&&!d&&!l){let u={...e.columns};for(let m=t.left;m<=t.right;m++){const g=C(m),h={...x(u[g]??{},s),...f};u=Object.keys(h).length===0?b(u,g):{...u,[g]:h}}e.columns=u;return}if(d&&!c&&!l){let u={...e.rows};for(let m=t.top;m<=t.bottom;m++){const g=String(m+1),h={...x(u[g]??{},s),...f};u=Object.keys(h).length===0?b(u,g):{...u,[g]:h}}e.rows=u;return}const a=o.tables.find(u=>u.rows>0&&t.top===u.data.top&&t.bottom===u.data.bottom&&t.left>=u.area.left&&t.right<=u.area.right);if(a&&!l){const u=n.table(o,a);let m={...u.columns};for(let g=t.left;g<=t.right;g++){const h=a.columns[g-a.at.col]?.name;if(h===void 0)continue;const y={...x(m[h]??{},s),...f};m=Object.keys(y).length===0?b(m,h):{...m,[h]:y}}u.columns=m,Object.keys(m).length===0&&delete u.columns,n.edit.whole=!0;return}const w=M(t),p=r.find(u=>{const m=j(u.range);return m!==void 0&&M(m)===w}),U=(p?r.slice(r.indexOf(p)+1):[]).some(u=>i(u)&&$(u,s)),k={};for(const[u,m]of Object.entries(s)){const g=r.some(h=>h!==p&&i(h)&&u in h)||ae(e,o,t,u);m!==void 0?k[u]=m:g&&(k[u]=me[u])}if(p&&!U){const u={...x(p,s),...k};e.format=r.flatMap(m=>m!==p?[m]:Object.keys(u).length>1?[u]:[])}else Object.keys(k).length>0&&(e.format=[...r,{range:w,...k}])}export function tidied(n){n.format?.length===0&&delete n.format,n.columns&&Object.keys(n.columns).length===0&&delete n.columns,n.rows&&Object.keys(n.rows).length===0&&delete n.rows,n.cells&&Object.keys(n.cells).length===0&&delete n.cells}export function setColumnWidth(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=C(e),f=S(i.columns?.[l]??{},"width"),c=t===void 0?f:{...f,width:t},d=b(i.columns??{},l);return i.columns=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function setRowHeight(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=String(e+1),f=S(i.rows?.[l]??{},"height"),c=t===void 0?f:{...f,height:t},d=b(i.rows??{},l);return i.rows=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function sheetNameProblem(n,o,e){if(o.trim()===""||o.length>31||/[\\/?*[\]:]/u.test(o)||o.startsWith("'")||o.endsWith("'"))return"sheet-name";const t=n.workbook.sheet(o);if(t&&t.name!==e)return"sheet-taken"}export function renameSheet(n,o,e){const t=sheetNameProblem(n,e,o);if(t)return refused(t);const s=F(n,{op:"rename-sheet",from:o,to:e});return{...blankEdit(),file:s.file,rows:new Map(s.rows),whole:!0}}export function addSheet(n,o,e){const t=sheetNameProblem(n,o);if(t)return refused(t);const s=[...n.file.sheets],r=s.findIndex(i=>i.name===e);return s.splice(r<0?s.length:r+1,0,{name:o}),{...blankEdit(),file:{...n.file,sheets:s},whole:!0}}export function copyName(n,o){for(let e=2;;e++){const t=` (${String(e)})`,s=o.slice(0,31-t.length).trimEnd()+t;if(!n.workbook.sheet(s))return s}}export function duplicateSheet(n,o){const e=H(n,o,copyName(n,o));return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function deleteSheet(n,o){const e=F(n,{op:"delete-sheet",name:o});if(e.refused)return refused(e.refused);const t=we(n.file,e.file);for(const s of t)e.rows.delete(s);return{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0,...t.length===0?{}:{removed:t}}}function we(n,o){const e=s=>s.sheets.flatMap(r=>[...(r.tables??[]).map(i=>i.rows),...(r.blocks??[]).map(i=>i.rows)]),t=new Set(e(o));return[...new Set(e(n))].filter(s=>!t.has(s))}export function moveSheet(n,o,e){const t=[...n.file.sheets],s=t.findIndex(i=>i.name===o),[r]=t.splice(s,1);return r?(t.splice(e,0,r),{...blankEdit(),file:{...n.file,sheets:t},whole:!0}):refused("no-sheet")}export function bandEdit(n,o){const e=F(n,o);return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function defineName(n,o,e,t){if(!J(o)||n.workbook.name(o)||n.workbook.table(o))return refused("name-invalid");const s=(l,f)=>`$${C(f)}$${String(l+1)}`,r=t.top===t.bottom&&t.left===t.right?s(t.top,t.left):`${s(t.top,t.left)}:${s(t.bottom,t.right)}`,i=/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)?e:`'${e.replaceAll("'","''")}'`;return{...blankEdit(),file:{...n.file,names:{...n.file.names,[o]:`=${i}!${r}`}},whole:!0}}export function inputOf(n,o,e,t){const s=o.at(e,t);if(s===void 0)return"";if(s instanceof P)return s.text;const r=o.tableAt(e,t);if(r){const d=r.columns[t-r.at.col];if(e===r.at.row)return d?.name??"";const a=d?.csv===void 0?void 0:r.records[e-r.at.row-1]?.[d.csv];if(a!==void 0)return a}const i=o.blockAt(e,t);if(i){const d=n.rows.get(i.file)?.[e-i.area.top]?.[t-i.area.left];if(d!==void 0)return d}const l=o.keys.get(V(e,t)),f=l===void 0?void 0:o.spec.cells?.[l],c=f!==null&&typeof f=="object"?f.value:f;return c!=null?String(c):typeof s=="object"?s.code:String(s)}export function exceptionsOf(n){const o=[];for(const e of n.columns){const{csv:t}=e;!e.formula||t===void 0||n.records.forEach((s,r)=>{const i=s[t]??"";i!==""&&o.push({row:n.at.row+1+r,col:n.at.col+e.index,column:e.name,text:i})})}return o}
|
|
2
|
+
import{MAX_COLUMNS as P,MAX_ROWS as V,cellName as S,columnLetter as $,contains as J,overlaps as k,rangeName as E,readAddress as Q,readArea as v}from"./address.js";import{moveFormula as Y}from"./formula/move.js";import{parseFormula as Z}from"./formula/parse.js";import{printFormula as ee}from"./formula/print.js";import{freeColumn as K,duplicated as te,restructure as _,uniqueColumn as q,withColumnsUpTo as T}from"./structure.js";import{RUN_FIELDS as ne,joinedRuns as oe,plainRuns as D,runsWithout as se}from"./rich.js";import{CellError as re,readTyped as C}from"./values.js";import{FormulaCell as ie,placeKey as le,runsText as N,validName as X}from"./workbook.js";export const BLOCK_CELLS=100;const z=(n,o)=>n.top<=o.top&&n.left<=o.left&&n.bottom>=o.bottom&&n.right>=o.right,R=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o)),fe=n=>R(n,"formula"),O=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>e!==o));export const blankEdit=()=>({rows:new Map,cells:[],whole:!1}),refused=n=>({...blankEdit(),refused:n});const x=n=>C(n).formula!==void 0;function ce(n){const o=C(n);return o.formula!==void 0?n:o.value===null?null:o.format!==void 0?n:typeof o.value=="number"||typeof o.value=="boolean"?o.value:n}const I=n=>n!==null&&typeof n=="object"?Object.fromEntries(Object.entries(n).filter(([o])=>o!=="value"&&o!=="formula"&&o!=="runs")):{};export class Draft{book;specs=new Map;file;fileChanged=!1;grown=new Map;added=new Map;edit=blankEdit();constructor(o){this.book=o,this.file=o.file}spec(o){let e=this.specs.get(o.index);if(!e){const t=this.file.sheets.findIndex(s=>s.name===o.name);e={...this.file.sheets[t]??{name:o.name}},this.specs.set(o.index,e),this.fileChanged||(this.file={...this.file,sheets:[...this.file.sheets]},this.fileChanged=!0),this.file.sheets[t]=e}return e}table(o,e){const t=this.spec(o),s=[...t.tables??[]],r=s.findIndex(l=>l.name===e.name),i={...s[r]??e.spec};return s[r]=i,t.tables=s,i}rows(o){const e=this.edit.rows.get(o);if(e)return e;const t=[...this.book.rows.get(o)??[]];return this.edit.rows.set(o,t),t}setField(o,e,t,s){const r=this.rows(o),i=[...r[e]??[]];for(;i.length<=t;)i.push("");return i[t]=s,r[e]=i,i}rowsOf(o){return this.grown.get(o)??o.rows}grow(o,e,t){this.grown.set(o,this.rowsOf(o)+1);const s=this.added.get(o)??new Map;s.set(e,t),this.added.set(o,s)}addedAt(o,e,t){for(const[s,r]of this.added){const i=r.get(e);if(i!==void 0&&s.sheet===o&&t>=s.at.col&&t<s.at.col+s.columns.length)return{table:s,record:i}}}finish(){return this.fileChanged&&(this.edit.file=this.file),this.edit}}function ue(n,o,e,t){return o.tables.find(s=>{const r=s.at.row+n.rowsOf(s)+1;if(e!==r)return!1;const i=s.at.col+s.columns.length-1;if(t<s.at.col||t>i)return!1;for(let l=s.at.col;l<=i;l++)if(o.at(e,l)!==void 0)return!1;return!0})}function de(n,o,e){return n.tables.find(t=>{const{top:s,bottom:r,right:i}=t.area;if(e!==i+1||o<s||o>r)return!1;for(let l=s;l<=r;l++)if(n.at(l,e)!==void 0)return!1;return!0})}export const movedTo=(n,o,e)=>{const t=Z(n);return t.ok?ee(Y(t.node,o,e)):n};function U(n,o,e,t,s,r){const i=e.at.row+1,l=n.table(o,e),f=movedTo(r,i-s,0);if(l.columns={...l.columns,[t.name]:{...l.columns?.[t.name],formula:f}},t.csv!==void 0){const c=e.places[s-i];c!==void 0&&n.setField(e.file,c,t.csv,"")}n.edit.whole=!0}function ae(n,o,e,t){const{csv:s}=e;if(s===void 0)return!1;const r=n.rows(o.file);return o.places.some((i,l)=>l!==t&&(r[i]?.[s]??"")!=="")}function me(n,o,e,t,s){const r=s.trim();if(r==="")return refused("column-name");if(r===t.name)return n.finish();const i=e.columns.filter(c=>c!==t).map(c=>c.name),l=q(i,r),f=_(o,{op:"rename-column",table:e.name,from:t.name,to:l});return{...blankEdit(),file:f.file,rows:new Map(f.rows),whole:!0}}function he(n,o,e,t,s,r){const i=e.columns[s-e.at.col];if(!i)return;const l=t-e.at.row-1;if(x(r)){if(i.formula){U(n,o,e,i,t,r);return}if(!ae(n,e,i,l)){U(n,o,e,i,t,r);return}n.edit.offer={sheet:o.name,row:t,col:s,text:r}}const c=e.places[l];if(c===void 0)return;let d=i.csv;if(d===void 0){if(r==="")return;const h=e.columns.map(g=>g.name);n.edit.rows.set(e.file,T(n.rows(e.file),h,i.index)),n.edit.whole=!0,d=i.index}const m=n.setField(e.file,c,d,r);n.edit.cells.push({sheet:o,row:t,col:s,...r===""&&i.formula?{column:i.formula}:{input:r},record:{table:e,index:l,fields:m}})}function we(n,o,e,t,s){const r=n.rows(o.file),i=Math.max(r[0]?.length??1,1),l=new Array(i).fill(""),f=o.columns[t-o.at.col];f?.csv!==void 0&&(l[f.csv]=s),r.push(l),n.grow(o,e,r.length-1),n.edit.whole=!0}function pe(n,o,e,t,s){const r=n.table(o,e),i=e.columns.map(h=>h.name),l=t===e.at.row,f=l?q(i,s.trim()===""?K(i):s.trim()):K(i);if(n.edit.whole=!0,!l&&x(s)){r.columns={...r.columns,[f]:{formula:movedTo(s,e.at.row+1-t,0)}};return}const c=i.length,d=T(n.rows(e.file),i,c-1),m=d[0];if(m&&m.push(f),d.forEach((h,g)=>{g>0&&h.length>0&&h.push("")}),!l){const h=e.places[t-e.at.row-1],g=h===void 0?void 0:d[h];g&&(g[c]=s)}n.edit.rows.set(e.file,d)}function be(n,o,e,t,s,r,i){n.setField(e,s-t.top,r-t.left,i),n.edit.cells.push({sheet:o,row:s,col:r,input:i})}function ge(n,o,e){return Object.keys(n.spec.cells??{}).some(t=>{if(!t.includes(":"))return!1;const s=v(t);return s!==void 0&&J(s,o,e)})}function ye(n,o,e,t,s){const r=n.spec(o),i=S({row:e,col:t});let l={...r.cells};const f=l[i];if(f!==null&&typeof f=="object"&&f.runs!==void 0&&N(f.runs)===s){n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:i});return}const c=f===void 0?{}:I(f),d=ce(s),m=Object.keys(c).length===0;let h;if(d===null){const g=ge(o,e,t);h=!m||g,m&&!g?l=O(l,i):l[i]=m?null:c}else h=!0,l[i]=m?d:{...c,...x(s)?{formula:s}:{value:d}};r.cells=l,Object.keys(l).length===0&&delete r.cells,n.edit.cells.push({sheet:o,row:e,col:t,input:s,key:h?i:null})}export function writeOne(n,o,e,t,s,r){const i=n.addedAt(e,t,s);if(i){const{csv:c}=i.table.columns[s-i.table.at.col]??{};c!==void 0&&n.setField(i.table.file,i.record,c,r);return}const l=e.tableAt(t,s);if(l){const c=l.columns[s-l.at.col];if(t===l.at.row)return c?me(n,o,l,c,r):void 0;he(n,e,l,t,s,r);return}if(r!==""){const c=ue(n,e,t,s);if(c){we(n,c,t,s,r);return}const d=de(e,t,s);if(d){pe(n,e,d,t,r);return}}const f=e.blockAt(t,s);f?be(n,e,f.file,f.area,t,s,r):ye(n,e,t,s,r)}export function setRuns(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=oe(s),l=N(i);if(i.length===0||D(i))return writeCells(n,o,[{row:e,col:t,text:l}]);if(r.tableAt(e,t)||r.blockAt(e,t))return refused("rich-loose");const f=new Draft(n),c=f.spec(r),d=S({row:e,col:t}),m=c.cells?.[d],h=m===void 0?{}:I(m);return c.cells={...c.cells,[d]:{...h,runs:i}},f.edit.cells.push({sheet:r,row:e,col:t,input:l,key:d}),f.finish()}function ke(n,o){if(n===null||typeof n!="object"||!n.runs)return n;const e=se(n.runs,o);if(!D(e))return{...n,runs:e};const t=N(e),s=I(n);return C(t).value===t&&C(t).format===void 0?Object.keys(s).length===0?t:{...s,value:t}:{...s,runs:[{text:t}]}}export function writeCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const{row:r,col:i,text:l}of[...e].sort((f,c)=>f.row-c.row||f.col-c.col)){const f=writeOne(s,n,t,r,i,l);if(f)return f}return s.finish()}export function overwriteColumn(n,o,e,t,s){const r=n.workbook.sheet(o),i=r?.tableAt(e,t);if(!r||!i)return refused("no-sheet");const l=i.columns[t-i.at.col];if(!l)return refused("no-sheet");const f=new Draft(n);U(f,r,i,l,e,s);const{csv:c}=l;if(c!==void 0)for(const d of i.places)f.setField(i.file,d,c,"");return f.finish()}function*G(n,o){const e=Math.min(o.right,n.columnsUsed-1);for(let t=o.left;t<=e;t++){const[s,r]=n.span(t,o.top,o.bottom);for(let i=s;i<=r;i++)n.at(i,t)!==void 0&&(yield[i,t])}}export function clearCells(n,o,e){const t=n.workbook.sheet(o);if(!t)return refused("no-sheet");const s=new Draft(n);for(const r of t.tables){const{top:i,bottom:l}=r.data;if(!(l<i||e.top>i||e.bottom<l))for(const f of r.columns){const c=r.at.col+f.index;if(c<e.left||c>e.right||!f.formula)continue;const d=s.table(t,r),m=r.columns.map(y=>y.name);f.csv===void 0&&s.edit.rows.set(r.file,T(s.rows(r.file),m,f.index));const h=fe(d.columns?.[f.name]??{}),g=O(d.columns??{},f.name);d.columns=Object.keys(h).length>0?{...g,[f.name]:h}:g,Object.keys(d.columns).length===0&&delete d.columns,s.edit.whole=!0}}for(const[r,i]of G(t,e)){if(t.tableAt(r,i)?.at.row===r)continue;const l=writeOne(s,n,t,r,i,"");if(l)return l}return s.finish()}export function dropKeys(n,o){n.cells&&(n.cells=Object.fromEntries(Object.entries(n.cells).filter(([e])=>{const t=v(e);return!t||!z(o,t)})))}export function fillCells(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");if(!r.tables.some(f=>k(f.area,t))&&!r.blocks.some(f=>k(f.area,t))&&x(s)){const f=new Draft(n),c=f.spec(r);dropKeys(c,t);const d=movedTo(s,t.top-e.row,t.left-e.col),m=E(t);return c.cells={...c.cells,[m]:d},f.edit.whole=!0,f.finish()}const l=[];for(let f=t.top;f<=t.bottom;f++)for(let c=t.left;c<=t.right;c++)f===e.row&&c===e.col||l.push({row:f,col:c,text:x(s)?movedTo(s,f-e.row,c-e.col):s});return writeCells(n,o,l)}export function writeBlockOf(n,o,e,t,s){const r=n.workbook.sheet(o);if(!r)return refused("no-sheet");const i=new Draft(n),l=i.spec(r);return l.blocks=[...l.blocks??[],{at:S(e),rows:s}],i.edit.rows.set(s,t),i.edit.whole=!0,i.finish()}const W=(n,o)=>Object.keys(o).some(e=>e in n),L=(n,o)=>Object.fromEntries(Object.entries(n).filter(([e])=>!(e in o)));function Oe(n){if(n===null||typeof n!="object")return n;const o=Object.keys(n);return o.length===1&&o[0]==="value"?n.value??null:o.length===1&&o[0]==="formula"?n.formula??null:n}const je={bold:!1,italic:!1,underline:!1,strike:!1,wrap:!1,locked:!0,hide_formula:!1,align:"general",format:"General",color:"#000000",fill:"#FFFFFF",font:"Calibri",size:11,border:{left:{style:"none"},right:{style:"none"},top:{style:"none"},bottom:{style:"none"}}};function ve(n,o,e,t){for(const[s,r]of Object.entries(n.columns??{})){const i=Q(`${s}1`)?.col;if(i!==void 0&&i>=e.left&&i<=e.right&&t in r)return!0}for(const[s,r]of Object.entries(n.rows??{})){const i=Number(s)-1;if(i>=e.top&&i<=e.bottom&&t in r)return!0}return o.tables.some(s=>k(s.area,e)&&s.columns.some(r=>r.spec!==void 0&&t in r.spec&&s.at.col+r.index>=e.left&&s.at.col+r.index<=e.right))}export function setLook(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n);return applyLook(r,s,e,t),r.finish()}export function applyLook(n,o,e,t){const s=n.spec(o);Ce(n,o,s,e,t),tidied(s)}function Ce(n,o,e,t,s){const r=ne.filter(u=>u in s);if(e.cells&&r.length>0)for(const[u,a]of Object.entries(e.cells)){if(a===null||typeof a!="object"||!a.runs)continue;const w=v(u);w&&k(w,t)&&(e.cells={...e.cells,[u]:ke(a,r)})}if(e.cells){const u={...e.cells},a=[];for(const[w,b]of Object.entries(u)){if(b===null||typeof b!="object"||!W(b,s))continue;const j=v(w);!j||!k(j,t)||(w.includes(":")&&!z(t,j)&&a.push({range:w,...Object.fromEntries(Object.entries(b).filter(([H])=>H in s))}),u[w]=Oe(L(b,s)))}e.cells=u,a.length>0&&(e.format=[...e.format??[],...a])}const i=e.format??[],l=u=>{const a=v(u.range);return a!==void 0&&k(a,t)},f=i.some(u=>l(u)&&W(u,s)),c=Object.fromEntries(Object.entries(s).filter(([,u])=>u!==void 0)),d=t.top===0&&t.bottom===V-1,m=t.left===0&&t.right===P-1;if(d&&!m&&!f){let u={...e.columns};for(let a=t.left;a<=t.right;a++){const w=$(a),b={...L(u[w]??{},s),...c};u=Object.keys(b).length===0?O(u,w):{...u,[w]:b}}e.columns=u;return}if(m&&!d&&!f){let u={...e.rows};for(let a=t.top;a<=t.bottom;a++){const w=String(a+1),b={...L(u[w]??{},s),...c};u=Object.keys(b).length===0?O(u,w):{...u,[w]:b}}e.rows=u;return}const h=o.tables.find(u=>u.rows>0&&t.top===u.data.top&&t.bottom===u.data.bottom&&t.left>=u.area.left&&t.right<=u.area.right);if(h&&!f){const u=n.table(o,h);let a={...u.columns};for(let w=t.left;w<=t.right;w++){const b=h.columns[w-h.at.col]?.name;if(b===void 0)continue;const j={...L(a[b]??{},s),...c};a=Object.keys(j).length===0?O(a,b):{...a,[b]:j}}u.columns=a,Object.keys(a).length===0&&delete u.columns,n.edit.whole=!0;return}const g=E(t),y=i.find(u=>{const a=v(u.range);return a!==void 0&&E(a)===g}),A=(y?i.slice(i.indexOf(y)+1):[]).some(u=>l(u)&&W(u,s)),p={};for(const[u,a]of Object.entries(s)){const w=i.some(b=>b!==y&&l(b)&&u in b)||ve(e,o,t,u);a!==void 0?p[u]=a:w&&(p[u]=je[u])}if(y&&!A){const u={...L(y,s),...p};e.format=i.flatMap(a=>a!==y?[a]:Object.keys(u).length>1?[u]:[])}else Object.keys(p).length>0&&(e.format=[...i,{range:g,...p}])}export function tidied(n){n.format?.length===0&&delete n.format,n.columns&&Object.keys(n.columns).length===0&&delete n.columns,n.rows&&Object.keys(n.rows).length===0&&delete n.rows,n.cells&&Object.keys(n.cells).length===0&&delete n.cells}export function setColumnWidth(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=$(e),f=R(i.columns?.[l]??{},"width"),c=t===void 0?f:{...f,width:t},d=O(i.columns??{},l);return i.columns=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function setRowHeight(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");const r=new Draft(n),i=r.spec(s),l=String(e+1),f=R(i.rows?.[l]??{},"height"),c=t===void 0?f:{...f,height:t},d=O(i.rows??{},l);return i.rows=Object.keys(c).length===0?d:{...d,[l]:c},tidied(i),r.finish()}export function sheetNameProblem(n,o,e){if(o.trim()===""||o.length>31||/[\\/?*[\]:]/u.test(o)||o.startsWith("'")||o.endsWith("'"))return"sheet-name";const t=n.workbook.sheet(o);if(t&&t.name!==e)return"sheet-taken"}export function renameSheet(n,o,e){const t=sheetNameProblem(n,e,o);if(t)return refused(t);const s=_(n,{op:"rename-sheet",from:o,to:e});return{...blankEdit(),file:s.file,rows:new Map(s.rows),whole:!0}}export function addSheet(n,o,e){const t=sheetNameProblem(n,o);if(t)return refused(t);const s=[...n.file.sheets],r=s.findIndex(i=>i.name===e);return s.splice(r<0?s.length:r+1,0,{name:o}),{...blankEdit(),file:{...n.file,sheets:s},whole:!0}}export function copyName(n,o){for(let e=2;;e++){const t=` (${String(e)})`,s=o.slice(0,31-t.length).trimEnd()+t;if(!n.workbook.sheet(s))return s}}export function duplicateSheet(n,o){const e=te(n,o,copyName(n,o));return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function deleteSheet(n,o){const e=_(n,{op:"delete-sheet",name:o});if(e.refused)return refused(e.refused);const t=xe(n.file,e.file);for(const s of t)e.rows.delete(s);return{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0,...t.length===0?{}:{removed:t}}}function xe(n,o){const e=s=>s.sheets.flatMap(r=>[...(r.tables??[]).map(i=>i.rows),...(r.blocks??[]).map(i=>i.rows)]),t=new Set(e(o));return[...new Set(e(n))].filter(s=>!t.has(s))}export function moveSheet(n,o,e){const t=[...n.file.sheets],s=t.findIndex(i=>i.name===o),[r]=t.splice(s,1);return r?(t.splice(e,0,r),{...blankEdit(),file:{...n.file,sheets:t},whole:!0}):refused("no-sheet")}export function bandEdit(n,o){const e=_(n,o);return e.refused?refused(e.refused):{...blankEdit(),file:e.file,rows:new Map(e.rows),whole:!0}}export function defineName(n,o,e,t){if(!X(o)||n.workbook.name(o)||n.workbook.table(o))return refused("name-invalid");const s=(l,f)=>`$${$(f)}$${String(l+1)}`,r=t.top===t.bottom&&t.left===t.right?s(t.top,t.left):`${s(t.top,t.left)}:${s(t.bottom,t.right)}`,i=/^[\p{L}_][\p{L}\p{N}_.]*$/u.test(e)?e:`'${e.replaceAll("'","''")}'`;return{...blankEdit(),file:{...n.file,names:{...n.file.names,[o]:`=${i}!${r}`}},whole:!0}}export function inputOf(n,o,e,t){const s=o.at(e,t);if(s===void 0)return"";if(s instanceof ie)return s.text;const r=o.tableAt(e,t);if(r){const d=r.columns[t-r.at.col];if(e===r.at.row)return d?.name??"";const m=d?.csv===void 0?void 0:r.records[e-r.at.row-1]?.[d.csv];if(m!==void 0)return m}const i=o.blockAt(e,t);if(i){const d=n.rows.get(i.file)?.[e-i.area.top]?.[t-i.area.left];if(d!==void 0)return d}const l=o.keys.get(le(e,t)),f=l===void 0?void 0:o.spec.cells?.[l],c=f!==null&&typeof f=="object"?f.value:f;return c!=null?String(c):typeof s=="object"?s.code:String(s)}export function exceptionsOf(n){const o=[];for(const e of n.columns){const{csv:t}=e;!e.formula||t===void 0||n.records.forEach((s,r)=>{const i=s[t]??"";i!==""&&o.push({row:n.at.row+1+r,col:n.at.col+e.index,column:e.name,text:i})})}return o}function Le(n){const o=new Set([...n.file.sheets.flatMap(e=>(e.tables??[]).map(t=>t.name)),...Object.keys(n.file.names??{})].map(e=>e.toLowerCase()));for(let e=1;;e++){const t=`Table${String(e)}`;if(!o.has(t.toLowerCase()))return t}}export function makeTable(n,o,e,t){const s=n.workbook.sheet(o);if(!s)return refused("no-sheet");if(s.tables.some(p=>k(p.area,e)))return refused("table-overlap");const r=e.right-e.left+1,i=(p,u)=>inputOf(n,s,p,u);if(!t.header){if(e.top===0)return refused("table-room");for(let p=0;p<r;p++)if(i(e.top-1,e.left+p)!=="")return refused("table-room")}const l=new Draft(n),f=new Set,c=Array.from({length:r},(p,u)=>{const a=t.header?i(e.top,e.left+u).trim():"";let w=a===""?`Column${String(u+1)}`:a;for(let b=2;f.has(w.toLowerCase());b++)w=`${a===""?`Column${String(u+1)}`:a}${String(b)}`;return f.add(w.toLowerCase()),w}),d=t.header?e.top+1:e.top,m=[];for(let p=d;p<=e.bottom;p++)m.push(Array.from({length:r},(u,a)=>i(p,e.left+a)));for(const[p,u]of G(s,e)){const a=writeOne(l,n,s,p,u,"");if(a)return a}const h=Le(n),g=new Set([...n.rows.keys(),...l.edit.rows.keys()].map(p=>p.toLowerCase()));let y=`data/${h.toLowerCase()}.csv`;for(let p=2;g.has(y);p++)y=`data/${h.toLowerCase()}-${String(p)}.csv`;l.edit.rows.set(y,[c,...m]);const M=l.spec(s),A=t.header?e.top:e.top-1;return M.tables=[...M.tables??[],{name:h,at:S({row:A,col:e.left}),rows:y,...t.style!==void 0&&t.style!=="TableStyleMedium2"?{style:t.style}:{}}],l.edit.whole=!0,l.finish()}export function setTableStyle(n,o,e,t){const s=n.workbook.sheet(o),r=s?.tables.find(f=>f.name===e);if(!s||!r)return refused("no-sheet");const i=new Draft(n),l=i.table(s,r);return t==="TableStyleMedium2"?delete l.style:l.style=t,i.edit.whole=!0,i.finish()}export function setTableOptions(n,o,e,t){const s=n.workbook.sheet(o),r=s?.tables.find(f=>f.name===e);if(!s||!r)return refused("no-sheet");const i=new Draft(n),l=i.table(s,r);return t.banded_rows!==void 0&&(t.banded_rows?delete l.banded_rows:l.banded_rows=!1),t.banded_columns!==void 0&&(t.banded_columns?l.banded_columns=!0:delete l.banded_columns),t.first_column!==void 0&&(t.first_column?l.first_column=!0:delete l.first_column),t.last_column!==void 0&&(t.last_column?l.last_column=!0:delete l.last_column),i.edit.whole=!0,i.finish()}function F(n,o){return o===void 0?n.names:n.sheets.find(e=>e.name===o)?.names}function B(n,o,e){const t=Object.keys(e).length===0?void 0:e;if(o===void 0){const s={...n};return t?s.names=t:delete s.names,s}return{...n,sheets:n.sheets.map(s=>{if(s.name!==o)return s;const r={...s};return t?r.names=t:delete r.names,r})}}export function setName(n,o){const e=o.name.trim(),t=o.was!==void 0&&o.was.name.toLowerCase()!==e.toLowerCase(),s=Object.keys(F(n.file,o.scope)??{}).some(d=>d.toLowerCase()===e.toLowerCase()&&!(d.toLowerCase()===o.was?.name.toLowerCase()&&o.was.scope===o.scope));if(!X(e)||s||n.workbook.table(e))return refused("name-invalid");const r=o.value.trim(),i=C(r).value,l=r.startsWith("=")||i instanceof re?r:i,f=t&&o.was?bandEdit(n,{op:"rename-name",from:o.was.name,to:e}):void 0;if(f?.refused)return f;let c=f?.file??n.file;if(o.was){const d={...F(c,o.was.scope)};for(const m of Object.keys(d))m.toLowerCase()===o.was.name.toLowerCase()&&(d[m]=null);c=B(c,o.was.scope,Object.fromEntries(Object.entries(d).filter(([,m])=>m!==null)))}return c=B(c,o.scope,{...F(c,o.scope),[e]:l}),{...blankEdit(),file:c,rows:f?.rows??new Map,whole:!0}}export function deleteName(n,o,e){const t=F(n.file,e)??{},s=Object.fromEntries(Object.entries(t).filter(([r])=>r.toLowerCase()!==o.toLowerCase()));return{...blankEdit(),file:B(n.file,e,s),whole:!0}}
|
|
@@ -27,4 +27,14 @@ export declare function fillDownTo(sheet: Worksheet, area: Area): number | undef
|
|
|
27
27
|
* of one moves as its cells' values.
|
|
28
28
|
*/
|
|
29
29
|
export declare function moveCells(book: EditBook, sheetName: string, from: Area, toSheet: string, to: Place): BookEdit;
|
|
30
|
+
export type CellShift = "right" | "down" | "left" | "up";
|
|
31
|
+
/**
|
|
32
|
+
* Excel's Insert Cells (shift right or down) and Delete Cells (shift left or
|
|
33
|
+
* up) over an area: the cells from it to the sheet's edge, across it alone,
|
|
34
|
+
* move by its size, looks with them, and every formula that named them
|
|
35
|
+
* follows, as Excel's references do (one to a deleted cell is #REF!).
|
|
36
|
+
* Refused when a table or a merged range is among what would move, as
|
|
37
|
+
* Excel refuses.
|
|
38
|
+
*/
|
|
39
|
+
export declare function shiftCells(book: EditBook, sheetName: string, area: Area, shift: CellShift): BookEdit;
|
|
30
40
|
//# sourceMappingURL=fill.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{cellName as
|
|
2
|
+
import{MAX_COLUMNS as et,MAX_ROWS as nt,cellName as W,contains as U,overlaps as T,rangeName as st}from"./address.js";import{rectangles as X}from"./api/rectangles.js";import{Draft as z,applyLook as $,blankEdit as D,clearCells as G,dropKeys as rt,inputOf as B,movedTo as H,refused as M,writeCells as P,writeOne as it}from"./edit.js";import{relativeKey as ct}from"./formula/move.js";import{parseFormula as Q}from"./formula/parse.js";import{printFormula as lt}from"./formula/print.js";import{mapNode as ft}from"./formula/walk.js";import{restructure as V}from"./structure.js";import{seriesAfter as ut}from"./series.js";import{readTyped as pt}from"./values.js";import{workbookOf as dt}from"./workbook.js";const J=s=>pt(s).formula!==void 0;function wt(s,e,t){const o=Q(s);return o.ok?ct(o.node,e,t):void 0}const ht=(s,e)=>!s.tables.some(t=>T(t.area,e))&&!s.blocks.some(t=>T(t.area,e));function at(s,e,t,o){if(s.some(r=>J(r.text))){const r=s.length;return e.map((f,i)=>{const p=t?s[((r-1-i)%r+r)%r]:s[i%r],h=p?.text??"";return{...f,text:p?H(h,f.row-p.row,f.col-p.col):h}})}const n=ut(s.map(r=>r.text),e.length,{mode:o,back:t});return e.map((r,f)=>({...r,text:n[f]??""}))}const Y=["bold","italic","underline","strike","font","size","color","fill","align","valign","wrap","shrink","indent","rotation","border","locked","hide_formula","format"];export const NO_LOOK=Object.fromEntries(Y.map(s=>[s,void 0]));export function copyLooks(s,e,t,o){const c=new Map;for(const n of o){const r=e.lookAt(n.from.row,n.from.col),f=t.lookAt(n.to.row,n.to.col);if(JSON.stringify(r)===JSON.stringify(f))continue;const i=JSON.stringify(r),p=c.get(i);p?p.places.push(n.to):c.set(i,{look:r,places:[n.to]})}for(const{look:n,places:r}of c.values()){const f={};for(const i of Y)f[i]=n[i];for(const i of X(r))$(s,t,i,f)}}export function autoFill(s,e,t,o,c="auto"){const n=s.workbook.sheet(e);if(!n)return M("no-sheet");const r=o.bottom>t.bottom||o.top<t.top,f=o.top<t.top||o.left<t.left,i=new z(s),p=r?{first:t.left,last:t.right}:{first:t.top,last:t.bottom},h=new Map,y=(u,d)=>{const x=`${String(u)}:${String(d)}`;let v=h.get(x);return v===void 0&&(v=B(s,n,u,d),h.set(x,v)),v},L=(t.bottom-t.top+1)*(t.right-t.left+1),m=new Set;for(let u=t.top;u<=t.bottom;u++)for(let d=t.left;d<=t.right;d++){const x=y(u,d);J(x)&&m.add(wt(x,u,d)??"")}if(m.size===1&&L>0&&ht(n,o)&&bt(y,t)){const u=i.spec(n);return rt(u,o),u.cells={...u.cells,[st(o)]:H(y(t.top,t.left),o.top-t.top,o.left-t.left)},i.edit.whole=!0,Z(i,n,t,o,r),i.finish()}for(let u=p.first;u<=p.last;u++){const d=[];if(r)for(let w=t.top;w<=t.bottom;w++)d.push({row:w,col:u,text:y(w,u)});else for(let w=t.left;w<=t.right;w++)d.push({row:u,col:w,text:y(u,w)});const x=[],v=f?r?t.top-1:t.left-1:r?t.bottom+1:t.right+1,A=r?f?o.top:o.bottom:f?o.left:o.right,E=f?-1:1;for(let w=v;f?w>=A:w<=A;w+=E)x.push(r?{row:w,col:u}:{row:u,col:w});for(const w of at(d,x,f,c))it(i,s,n,w.row,w.col,w.text)}return Z(i,n,t,o,r),i.finish()}function bt(s,e){for(let t=e.top;t<=e.bottom;t++)for(let o=e.left;o<=e.right;o++)if(!J(s(t,o)))return!1;return!0}function Z(s,e,t,o,c){const n=[],r=t.bottom-t.top+1,f=t.right-t.left+1;for(let i=o.top;i<=o.bottom;i++)for(let p=o.left;p<=o.right;p++){if(U(t,i,p))continue;const h=c?t.top+((i-t.top)%r+r)%r:i,y=c?p:t.left+((p-t.left)%f+f)%f;n.push({from:{row:h,col:y},to:{row:i,col:p}})}copyLooks(s,e,e,n)}export function pasteLooks(s,e,t,o){const c=s.workbook.sheet(e),n=s.workbook.sheet(t);if(!c||!n)return M("no-sheet");const r=new z(s);return copyLooks(r,c,n,o),r.finish()}export function fillDownTo(s,e){const t=(o,c)=>c>=0&&s.at(o,c)!==void 0;for(const o of[e.left-1,e.right+1]){if(!t(e.bottom,o)&&!t(e.bottom+1,o))continue;let c=e.bottom;for(;t(c+1,o);)c+=1;if(c>e.bottom)return c}}function gt(s,e,t){if(!J(s))return s;const o=Q(s);if(!o.ok)return s;const c=ft(o.node,n=>n.kind!=="ref"?n:n.sheet===void 0?{...n,sheet:e}:n.sheet.toLowerCase()!==t.toLowerCase()||n.lastSheet!==void 0?n:Object.fromEntries(Object.entries(n).filter(([r])=>r!=="sheet")));return lt(c)}function N(s){const e=D();e.whole=!0;for(const t of s){t.file&&(e.file=t.file);for(const[o,c]of t.rows)e.rows.set(o,c)}return e}function _(s,e){const t=e.file??s.file,o=new Map(s.rows);for(const[c,n]of e.rows)o.set(c,n);return{file:t,rows:o,workbook:dt({file:t,rows:c=>o.get(c)})}}export function moveCells(s,e,t,o,c){const n=s.workbook.sheet(e),r=s.workbook.sheet(o);if(!n||!r)return M("no-sheet");const f=c.row-t.top,i=c.col-t.left;if(f===0&&i===0&&n===r)return D();const p={top:c.row,left:c.col,bottom:t.bottom+f,right:t.right+i},h=n.tables.filter(l=>U(t,l.area.top,l.area.left)&&U(t,l.area.bottom,l.area.right));for(const l of n.tables)if(!h.includes(l)&&T(l.area,t)&&t.top<=l.at.row)return M("table-move");if(h.length>0&&n!==r)return M("table-move");for(const l of r.tables)if(!h.includes(l)&&T(l.area,p)&&p.top<=l.at.row)return M("table-move");const y={op:"move-cells",sheet:e,area:t,rows:f,columns:i,...n===r?{}:{to:o}},L=V(s,y),m={...D(),file:L.file,rows:new Map(L.rows)},u=_(s,m),d=u.workbook.sheet(e),x=u.workbook.sheet(o);if(!d||!x)return M("no-sheet");const v=[],A=[],E=Math.min(t.right,d.columnsUsed-1),w=Math.min(t.bottom,d.lastRow),K=(l,b)=>h.some(g=>U(g.area,l,b));for(let l=t.top;l<=w;l++)for(let b=t.left;b<=E;b++)if(!K(l,b)){if(d.at(l,b)!==void 0){const g=B(u,d,l,b);v.push({row:l+f,col:b+i,text:n===r?g:gt(g,e,o)})}A.push({from:{row:l,col:b},to:{row:l+f,col:b+i}})}const S=G(u,e,t);if(S.refused!==void 0)return S;const C=_(u,S),j=[m,S];let R=C;if(h.length>0){const l=new z(C),b=C.workbook.sheet(e);if(!b)return M("no-sheet");for(const I of h){const q=b.tables.find(ot=>ot.name===I.name);if(!q)continue;const tt=l.table(b,q);tt.at=W({row:I.at.row+f,col:I.at.col+i})}const g=l.finish();j.push(g),R=_(C,g)}const F=P(R,o,v);if(F.refused!==void 0)return F;j.push(F);const a=_(R,F),O=a.workbook.sheet(e),k=a.workbook.sheet(o);if(O&&k){const l=new z(a);copyLooks(l,d,k,A);const b=A.map(g=>g.from).filter(g=>!(n===r&&U(p,g.row,g.col))&&Object.keys(d.lookAt(g.row,g.col)).length>0);for(const g of X(b))$(l,O,g,NO_LOOK);j.push(l.finish())}return N(j)}export function shiftCells(s,e,t,o){const c=s.workbook.sheet(e);if(!c)return M("no-sheet");const n=o==="down"||o==="up",r=o==="down"||o==="right",f=n?t.bottom-t.top+1:t.right-t.left+1,i=n?{...t,bottom:Math.max(t.bottom,c.lastRow)}:{...t,right:Math.max(t.right,c.columnsUsed-1)},p=n?{...t,bottom:nt-1}:{...t,right:et-1};if(c.tables.some(a=>T(a.area,p)))return M("table-shift");if(c.merges.some(a=>T(a,p)))return M("merge-shift");const h=V(s,{op:"shift-cells",sheet:e,rows:n,insert:r,at:n?t.top:t.left,count:f,first:n?t.left:t.top,last:n?t.right:t.bottom});if(h.refused!==void 0)return M(h.refused);const y={...D(),file:h.file,rows:new Map(h.rows)},L=_(s,y),m=L.workbook.sheet(e);if(!m)return M("no-sheet");const u=r?f:-f,d=r?i:n?{...i,top:t.bottom+1}:{...i,left:t.right+1},x=Math.min(i.bottom,m.lastRow),v=Math.min(i.right,m.columnsUsed-1),A=[],E=[],w=new Set;for(let a=d.top;a<=Math.min(d.bottom,x);a++)for(let O=d.left;O<=Math.min(d.right,v);O++){const k=n?{row:a+u,col:O}:{row:a,col:O+u};m.at(a,O)!==void 0&&A.push({...k,text:B(L,m,a,O)}),E.push({from:{row:a,col:O},to:k}),w.add(W(k))}const K=G(L,e,i);if(K.refused!==void 0)return K;const S=_(L,K),C=P(S,e,A);if(C.refused!==void 0)return C;const j=_(S,C),R=[y,K,C],F=j.workbook.sheet(e);if(F){const a=new z(j);copyLooks(a,m,F,E);const O=[];for(let k=i.top;k<=x;k++)for(let l=i.left;l<=v;l++)!w.has(W({row:k,col:l}))&&Object.keys(m.lookAt(k,l)).length>0&&O.push({row:k,col:l});for(const k of X(O))$(a,F,k,NO_LOOK);R.push(a.finish())}return N(R)}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import"./address.js";import{compareForSort as
|
|
2
|
+
import"./address.js";import{hasWildcard as q,wildcard as M}from"./calc/functions/criteria.js";import{compareForSort as T}from"./sort.js";import{shownValue as L}from"./format.js";import{choicesIn as E}from"./validate.js";const g=(e,n,o,t)=>L(n.value(e,o,t),e.lookAt(o,t).format),v=(e,n)=>{if(n==="")return e.blanks===!0;const o=n.toLowerCase();return e.values?.some(t=>t.toLowerCase()===o)===!0},h=e=>e.values!==void 0||e.blanks!==void 0,O=(e,n)=>!h(e)||v(e,n);function C(e,n,o,t){const r=e.validations.length===0?void 0:e.validationAt(n,o);return r?.spec.multiple===!0?E(t,r.spec):[t]}function A(e,n,o){const{operator:t}=e,r=e.value;if(typeof r=="number"&&typeof n=="number")switch(t){case"equal":return n===r;case"notEqual":return n!==r;case"greaterThan":return n>r;case"greaterThanOrEqual":return n>=r;case"lessThan":return n<r;case"lessThanOrEqual":return n<=r}const a=String(r);if(t==="equal"||t==="notEqual"){const m=q(a)?M(a)(o):o.toLowerCase()===a.toLowerCase();return t==="equal"?m:!m}if(o==="")return!1;const i=o.toLowerCase().localeCompare(a.toLowerCase());switch(t){case"greaterThan":return i>0;case"greaterThanOrEqual":return i>=0;case"lessThan":return i<0;case"lessThanOrEqual":return i<=0}}function R(e,n,o,t,r){const{top:a}=o.area,i=Math.min(o.area.bottom,e.lastRow),m=()=>{const s=[];for(let u=a+1;u<=i;u++){const d=n.value(e,u,t);typeof d=="number"&&s.push(d)}return s};if(r.values!==void 0||r.blanks!==void 0)return s=>{const u=g(e,n,s,t);return u===""?r.blanks===!0:C(e,s,t,u).some(d=>v(r,d))};const p=r.conditions;if(p)return s=>{const u=n.value(e,s,t),d=g(e,n,s,t),c=p.map(f=>A(f,u,d));return r.or===!0?c.some(Boolean):c.every(Boolean)};const l=r.top;if(l){const s=m().sort((c,f)=>l.bottom===!0?c-f:f-c),u=l.percent===!0?Math.max(1,Math.floor(s.length*l.count/100)):Math.round(l.count),d=s[Math.min(u,s.length)-1];return c=>{const f=n.value(e,c,t);return typeof f!="number"||d===void 0?!1:l.bottom===!0?f<=d:f>=d}}if(r.average){const s=m(),u=s.reduce((c,f)=>c+f,0)/Math.max(1,s.length),d=r.average==="above";return c=>{const f=n.value(e,c,t);return typeof f=="number"&&(d?f>u:f<u)}}const b=r.color;return b?s=>{const u=e.lookAt(s,t);return b.fill!==void 0?typeof u.fill=="string"&&u.fill.toUpperCase()===b.fill.toUpperCase():b.font!==void 0?(u.color??"#000000").toUpperCase()===b.font.toUpperCase():!0}:()=>!0}function k(e,n,o,t){return[...o.columns].filter(([r])=>r!==t).map(([r,a])=>R(e,n,o,r,a))}const y=(e,n)=>e.every(o=>o(n));export function filteredRows(e,n){const o=new Set;for(const t of e.filters){if(t.columns.size===0)continue;const{top:r,bottom:a}=t.area,i=Math.min(a,e.lastRow),m=k(e,n,t);for(let p=r+1;p<=i;p++)y(m,p)||o.add(p)}return o}export function filterChoices(e,n,o,t){const r=o.columns.get(t),a=new Map;let i=0;const{top:m,bottom:p}=o.area,l=Math.min(p,e.lastRow),b=k(e,n,o,t);for(let s=m+1;s<=l;s++){if(!y(b,s))continue;const u=g(e,n,s,t);if(u===""){i+=1;continue}const d=C(e,s,t,u);for(const c of d){const f=c.toLowerCase(),w=a.get(f);w?w.count+=1:a.set(f,{text:c,count:1,on:r===void 0||O(r,c),value:d.length>1?c:n.value(e,s,t)})}}return{values:[...a.values()].sort((s,u)=>T(s.value,u.value)),blanks:i===0?void 0:{count:i,on:r===void 0||r.blanks===!0||!h(r)}}}export function regionAround(e,n){const o=(a,i)=>a>=0&&i>=0&&(e.at(a,i)!==void 0||e.spillAt(a,i)!==void 0),t={top:n.row,left:n.col,bottom:n.row,right:n.col};for(let a=!0;a;){a=!1;const i=p=>{for(let l=t.left-1;l<=t.right+1;l++)if(o(p,l))return!0;return!1},m=p=>{for(let l=t.top-1;l<=t.bottom+1;l++)if(o(l,p))return!0;return!1};i(t.top-1)&&(t.top-=1,a=!0),i(t.bottom+1)&&(t.bottom+=1,a=!0),m(t.left-1)&&(t.left-=1,a=!0),m(t.right+1)&&(t.right+=1,a=!0)}return t.top===t.bottom&&t.left===t.right&&!o(t.top,t.left)?void 0:t}
|
|
@@ -47,6 +47,20 @@ export type StructureEdit = {
|
|
|
47
47
|
op: "delete-column";
|
|
48
48
|
table: string;
|
|
49
49
|
name: string;
|
|
50
|
+
} | {
|
|
51
|
+
/**
|
|
52
|
+
* Excel's Insert Cells and Delete Cells: rows (or columns) put in or
|
|
53
|
+
* taken out at `at` across `first`…`last` alone, the cells past them
|
|
54
|
+
* shifted down or up (right or left).
|
|
55
|
+
*/
|
|
56
|
+
op: "shift-cells";
|
|
57
|
+
sheet: string;
|
|
58
|
+
rows: boolean;
|
|
59
|
+
insert: boolean;
|
|
60
|
+
at: number;
|
|
61
|
+
count: number;
|
|
62
|
+
first: number;
|
|
63
|
+
last: number;
|
|
50
64
|
} | {
|
|
51
65
|
op: "move-cells";
|
|
52
66
|
sheet: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{MAX_COLUMNS as
|
|
2
|
+
import{MAX_COLUMNS as M,MAX_ROWS as S}from"../address.js";import{mapNode as O}from"./walk.js";const c=(n,r)=>n?.toLowerCase()===r?.toLowerCase(),k=(n,r,t)=>n.index>=r?{...n,index:n.index+t}:n;function R(n,r,t){if(n.index<r)return n;if(n.index>=r+t)return{...n,index:n.index-t}}function C(n,r,t,s){const o=n.index<=r.index?n:r,e=o===n?r:n,u=k(o,t,s),i=e.index>=t?{...e,index:e.index+s}:e;return o===n?[u,i]:[i,u]}function E(n,r,t,s){const o=n.index<=r.index?n:r,e=o===n?r:n,u=t+s-1;if(o.index>=t&&e.index<=u)return;const i=o.index<t?o:o.index>u?{...o,index:o.index-s}:{...o,index:t},a=e.index<t?e:e.index>u?{...e,index:e.index-s}:{...e,index:t-1};return o===n?[i,a]:[a,i]}function x(n){return{kind:"error",code:"#REF!",...n.sheet===void 0?{}:{sheet:n.sheet}}}const h={kind:"error",code:"#REF!"};function g(n,r,t){if(!c(n.sheet??t,r.sheet)||n.lastSheet!==void 0)return n;const{col:s,row:o}=n;if(s===void 0||o===void 0)return n;const e=n.col2??s,u=n.row2??o,{area:i,rows:a,columns:d,to:f}=r;if(!(Math.min(s.index,e.index)>=i.left&&Math.max(s.index,e.index)<=i.right&&Math.min(o.index,u.index)>=i.top&&Math.max(o.index,u.index)<=i.bottom))return n;const l=(m,b)=>({...m,index:m.index+b}),w={...n,col:l(s,d),row:l(o,a),...n.col2?{col2:l(n.col2,d)}:{},...n.row2?{row2:l(n.row2,a)}:{}};return f===void 0?w:c(f,t)?Object.fromEntries(Object.entries(w).filter(([m])=>m!=="sheet")):{...w,sheet:f}}function p(n,r,t){if(!c(n.sheet??t,r.sheet)||n.lastSheet!==void 0)return n;const s=r.op==="insert-rows"||r.op==="delete-rows",o=s?n.row:n.col,e=s?n.row2:n.col2;if(o===void 0)return n;const u=s?["row","row2"]:["col","col2"],i=r.op==="insert-rows"||r.op==="insert-columns",a=s?S:M;if(e===void 0){const f=i?k(o,r.at,r.count):R(o,r.at,r.count);return!f||f.index>=a?x(n):f===o?n:{...n,[u[0]]:f}}const d=i?C(o,e,r.at,r.count):E(o,e,r.at,r.count);return!d||d[0].index>=a||d[1].index>=a?x(n):d[0]===o&&d[1]===e?n:{...n,[u[0]]:d[0],[u[1]]:d[1]}}function F(n,r,t){const s=r.rows?n.col:n.row,o=(r.rows?n.col2:n.row2)??s;if(s===void 0||o===void 0||Math.min(s.index,o.index)<r.first||Math.max(s.index,o.index)>r.last)return n;const e=r.rows?r.insert?"insert-rows":"delete-rows":r.insert?"insert-columns":"delete-columns";return p(n,{op:e,sheet:r.sheet,at:r.at,count:r.count},t)}export function rewriteFormula(n,r,t,s){const o=(e,u)=>e===void 0?s===void 0||c(s,u):c(e,u);return O(n,e=>{switch(r.op){case"rename-sheet":return(e.kind==="ref"||e.kind==="name"||e.kind==="error")&&c(e.sheet,r.from)?{...e,sheet:r.to}:e.kind==="ref"&&c(e.lastSheet,r.from)?{...e,lastSheet:r.to}:e;case"rename-table":return e.kind==="structured"&&c(e.table,r.from)?{...e,table:r.to}:e;case"delete-sheet":return e.kind==="ref"&&c(e.sheet,r.name)||e.kind==="ref"&&c(e.lastSheet,r.name)?x(e):e.kind==="name"&&c(e.sheet,r.name)?h:e;case"delete-table":return e.kind==="structured"&&c(e.table,r.name)||e.kind==="name"&&c(e.name,r.name)?h:e;case"delete-column":return e.kind==="structured"&&o(e.table,r.table)&&e.columns.some(u=>c(u,r.name))?h:e;case"rename-column":return e.kind==="structured"&&o(e.table,r.table)&&e.columns.some(u=>c(u,r.from))?{...e,columns:e.columns.map(u=>c(u,r.from)?r.to:u)}:e;case"rename-name":return e.kind==="name"&&c(e.name,r.from)?{...e,name:r.to}:e.kind==="call"&&c(e.name,r.from)?{...e,name:r.to.toUpperCase(),written:r.to}:e;case"move-cells":return e.kind==="ref"?g(e,r,t):e;case"shift-cells":return e.kind==="ref"?F(e,r,t):e;default:return e.kind==="ref"?p(e,r,t):e}})}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
import{formatColor as O,isValidFormat as P}from"numfmt";import{cellName as T,columnLetter as
|
|
3
|
-
`)}}class W{calc;sheet;rules;read;drawnFiles;bands=new Map;svgs=new Map;constructor(t,e,
|
|
2
|
+
import{formatColor as O,isValidFormat as P}from"numfmt";import{cellName as T,columnLetter as k}from"./address.js";import{linkAt as _}from"./annotations.js";import{chartDef as U,chartPlace as q,chartSize as V,chartSvg as K}from"./chart.js";import{fileCells as Y,isPicture as X,pictureHeight as Z,pictureSize as J}from"./files.js";import{generalForms as Q,shownValue as tt}from"./format.js";import{DEFAULT_COLUMN_WIDTH as et,DEFAULT_ROW_HEIGHT as F,columnHidden as N,columnWidth as R,pageTitleCols as nt,pageTitleRows as st,rowHeight as it,rowHidden as E,paginate as ot,usedWithCharts as rt}from"./paginate.js";import{Rules as lt,iconShape as at}from"./rules.js";import{tableStyleLook as dt,tableStyleOf as ct}from"./table-style.js";import{CellError as ht}from"./values.js";import{placeKey as I}from"./workbook.js";export{et as DEFAULT_COLUMN_WIDTH,F as DEFAULT_ROW_HEIGHT};const ft={"&":"&","<":"<",">":">",'"':"""},pt=n=>{let t="";for(let e=0;e<n.length;e+=32768)t+=String.fromCharCode(...n.subarray(e,e+32768));return btoa(t)},x=n=>n.replace(/[&<>"]/gu,t=>ft[t]??t),gt={thin:"1px solid",medium:"2px solid",thick:"3px solid",double:"3px double",hair:"1px dotted",dotted:"1px dotted",dashed:"1px dashed",dashDot:"1px dashed",dashDotDot:"1px dashed",mediumDashed:"2px dashed",mediumDashDot:"2px dashed",mediumDashDotDot:"2px dashed",slantDashDot:"2px dashed"},ut={left:"left",center:"center",right:"right",justify:"justify",distributed:"justify",centerContinuous:"center",fill:"left"},mt={top:"top",center:"middle",justify:"middle",distributed:"middle"};function $t(n){if(typeof n=="number")return"right";if(typeof n=="boolean"||n instanceof ht)return"center"}const bt={up:"▲","up-right":"◥",right:"▶","down-right":"◢",down:"▼",circle:"●",flag:"⚑",check:"✔",bang:"!",cross:"✖",triangle:"▲",diamond:"◆",bars:"▮",quarter:"◔"};function wt(n){const{shape:t,color:e,level:o}=at(n.set,n.index),l=(bt[t]??"●").repeat(t==="bars"?o??1:1);return`<span style="float:left;color:${e}">${l}</span>`}function yt(n){const t=[];if(n.bold!==void 0&&t.push(`font-weight:${n.bold?"bold":"normal"}`),n.italic!==void 0&&t.push(`font-style:${n.italic?"italic":"normal"}`),n.underline!==void 0||n.strike!==void 0){const l=[n.underline!==void 0&&n.underline!==!1?"underline":"",n.strike===!0?"line-through":""].filter(Boolean);t.push(`text-decoration:${l.length>0?l.join(" "):"none"}`)}n.font!==void 0&&t.push(`font-family:"${n.font.replace(/["\\]/gu,"")}",var(--font)`),n.size!==void 0&&t.push(`font-size:${String(n.size)}pt`),n.color!==void 0&&t.push(`color:${n.color}`);const e=x(n.text),o=n.script==="superscript"?`<sup>${e}</sup>`:n.script==="subscript"?`<sub>${e}</sub>`:e;return t.length===0&&n.script===void 0?e:`<span${t.length===0?"":` style="${t.join(";")}"`}>${o}</span>`}function xt(n,t,e){const o=[];n.bold===!0&&o.push("font-weight:bold"),n.italic===!0&&o.push("font-style:italic");const l=[n.underline?"underline":"",n.strike===!0?"line-through":""].filter(Boolean);l.length>0&&o.push(`text-decoration:${l.join(" ")}`),n.font!==void 0&&o.push(`font-family:"${n.font.replace(/["\\]/gu,"")}",var(--font)`),n.size!==void 0&&o.push(`font-size:${String(n.size)}pt`);const r=(typeof t=="number"&&e!==void 0&&P(e)?O(e,t)??void 0:void 0)??n.color;typeof r=="string"&&o.push(`color:${r}`);const{fill:a}=n;if(typeof a=="string")o.push(`background:${a}`);else if(a){const i=a.color??a.background;i!==void 0&&o.push(`background:${i}`)}const f=(n.align===void 0||n.align==="general"?void 0:ut[n.align])??$t(t);f!==void 0&&o.push(`text-align:${f}`);const c=n.valign===void 0?void 0:mt[n.valign];c!==void 0&&o.push(`vertical-align:${c}`),n.wrap===!0&&o.push("white-space:pre-wrap","overflow-wrap:anywhere"),n.indent!==void 0&&o.push(`padding-left:${String(3+n.indent*9)}px`);for(const i of["left","right","top","bottom"]){const s=n.border?.[i];s&&s.style!=="none"&&o.push(`border-${i}:${gt[s.style]??"1px solid"} ${s.color??"#000"}`)}return o.join(";")}class L{names=new Map;of(t){if(t==="")return"";let e=this.names.get(t);return e||(e=`s${String(this.names.size)}`,this.names.set(t,e)),e}css(){return[...this.names].map(([t,e])=>`.${e}{${t}}`).join(`
|
|
3
|
+
`)}}class W{calc;sheet;rules;read;drawnFiles;bands=new Map;svgs=new Map;constructor(t,e,o){this.calc=t,this.sheet=e,this.read=o,this.rules=e.conditions.length>0?new lt(e,t):void 0}files(){if(this.drawnFiles)return this.drawnFiles;const t=new Map,e=new Map,o=this.read;for(const{row:l,col:r,paths:a,column:f}of o?Y(this.sheet,this.calc):[]){const c=Z(f),i=a.map(s=>{const d=X(s)?o?.(s):void 0,h=d&&J(d);return!d||!h?x(s):(e.set(l,Math.max(e.get(l)??0,c)),`<img src="data:image/${h.type};base64,${pt(d)}" alt="${x(s)}" style="height:${String(c)}px">`)});t.set(I(l,r),i.join(" "))}return this.drawnFiles={cells:t,rows:e},this.drawnFiles}height(t){return this.sheet.spec.rows?.[String(t+1)]?.height??this.files().rows.get(t)??F}band(t,e){if(e===t.at.row)return;let o=this.bands.get(t);if(!o){o=new Map;let l=0;for(let r=t.at.row+1;r<=t.area.bottom;r++)E(this.calc,this.sheet,r)||o.set(r,l++);this.bands.set(t,o)}return o.get(e)??0}cell(t,e,o,l,r){const{sheet:a}=this,f=this.calc.value(a,t,e),c=this.rules?.at(t,e),i=a.lookAt(t,e),s=a.tableAt(t,e),d=s&&ct(s),h=s&&d?dt(d,s,t,e,this.band(s,t)):void 0,p={...h,...i,...c?.look,...c?.scale===void 0?{}:{fill:c.scale}};(h?.border||i.border)&&(p.border={...h?.border,...i.border,...c?.look?.border});const w=p.format;let $=xt(p,f,w);if(c?.bar){const v=`${String(Math.round(c.bar.share*100))}%`;$=[$,`background:linear-gradient(90deg,${c.bar.color} ${v},transparent ${v})`].filter(Boolean).join(";")}const u=this.files().cells.get(I(t,e)),y=c?.icon?wt(c.icon):"",S=typeof f=="string"?a.runsAt(t,e):void 0,b=u??(c?.bare===!0?"":S?S.map(yt).join(""):x(tt(f,w))),C=typeof f=="string"&&p.wrap!==!0&&l&&!o,A=typeof f=="number"&&!u&&y===""&&b!=="",M=A&&(w===void 0||w==="General"),z=[r.of($),C?"over":"",A?"n":""].filter(Boolean).join(" "),D=[z===""?"":` class="${z}"`,M?` data-g="${x(Q(f).slice(1).join(" "))}"`:"",o&&o.rows>1?` rowspan="${String(o.rows)}"`:"",o&&o.cols>1?` colspan="${String(o.cols)}"`:""].join(""),j=A?void 0:_(a.spec,t,e)?.to,g=j!==void 0&&/^(?:https?:|mailto:)/iu.test(j)&&b!==""?`<a href="${x(j)}" style="color:inherit;text-decoration:inherit">${b}</a>`:b;return`<td${D}>${y}${g}</td>`}spans(t,e){const o=new Map,l=new Set;for(const r of this.sheet.merges){const a=t.filter(s=>s>=r.top&&s<=r.bottom),f=e.filter(s=>s>=r.left&&s<=r.right),[c]=a,[i]=f;if(!(c===void 0||i===void 0)){for(const s of a)for(const d of f)l.add(`${String(s)}:${String(d)}`);l.delete(`${String(c)}:${String(i)}`),o.set(`${String(c)}:${String(i)}`,{rows:a.length,cols:f.length})}}return{spans:o,covered:l}}table(t,e,o,l){const{sheet:r}=this,{spans:a,covered:f}=this.spans(t,e),c=e.map(h=>R(r,h)),i=l.headings?B:0,s=c.reduce((h,p)=>h+p,0)+i,d=[`<table class="${l.className??""}" style="width:${String(s)}px"><colgroup>`,l.headings?`<col style="width:${String(i)}px">`:"",...c.map(h=>`<col style="width:${String(h)}px">`),"</colgroup>"];l.headings&&d.push(`<thead><tr><th></th>${e.map(h=>`<th>${k(h)}</th>`).join("")}</tr></thead>`),d.push("<tbody>");for(const h of t)d.push(`<tr style="height:${String(this.height(h))}px">`),l.headings&&d.push(`<th>${String(h+1)}</th>`),e.forEach((p,w)=>{const $=`${String(h)}:${String(p)}`;if(f.has($))return;const u=e[w+1],y=u!==void 0&&r.at(h,u)===void 0&&!f.has(`${String(h)}:${String(u)}`);d.push(this.cell(h,p,a.get($),y,o))}),d.push("</tr>");return d.push("</tbody></table>"),{html:d.join(""),width:s}}svg(t){let e=this.svgs.get(t);if(e===void 0){const{width:o,height:l}=V(t.spec);e=K(U(this.calc,this.sheet,t),o,l,{font:"var(--font)"}),this.svgs.set(t,e)}return e}charts(t,e,o){const{sheet:l}=this;if(l.charts.length===0||t.length===0||e.length===0)return"";const r=(i,s)=>{const d=new Map;let h=0;for(const p of i)d.set(p,h),h+=s(p);return{at:d,sum:h}},a=r(t,i=>this.height(i)),f=r(e,i=>R(l,i)),c=(i,s,d,h)=>{const p=i[0]??0;if(d<p){let $=0;for(let u=d;u<p;u++)$-=h(u);return $}const w=i.find($=>$>=d);return w===void 0?1/0:s.get(w)??0};return l.charts.map(i=>{const s=q(i.spec,h=>c(t,a.at,h,p=>E(this.calc,l,p)?0:it(l,p)),h=>c(e,f.at,h,p=>N(l,p)?0:R(l,p)));return s.left<f.sum&&s.left+s.width>0&&s.top<a.sum&&s.top+s.height>0?`<div class="chart" style="left:${String(o.left+s.left)}px;top:${String(o.top+s.top)}px">${this.svg(i)}</div>`:""}).join("")}}const B=44,vt=`
|
|
4
4
|
(() => {
|
|
5
5
|
const fit = () => {
|
|
6
6
|
const cells = Array.from(document.querySelectorAll("td.n"));
|
|
@@ -23,24 +23,24 @@ import{formatColor as O,isValidFormat as P}from"numfmt";import{cellName as T,col
|
|
|
23
23
|
};
|
|
24
24
|
window.allyhubReady = new Promise((r) => addEventListener("load", r, { once: true })).then(() => document.fonts.ready).then(fit);
|
|
25
25
|
})();
|
|
26
|
-
`;function G(
|
|
27
|
-
${
|
|
28
|
-
:root{--font:${
|
|
26
|
+
`;function G(n,t,e){return`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
27
|
+
${n.css??""}
|
|
28
|
+
:root{--font:${n.font===void 0?"":`"${n.font}",`}Carlito,Calibri,"Noto Sans SC",Arial,sans-serif}
|
|
29
29
|
*{box-sizing:border-box}
|
|
30
30
|
html,body{margin:0;background:#fff;color:#000}
|
|
31
31
|
body{font:11pt/1.2 var(--font)}
|
|
32
32
|
table{table-layout:fixed;border-collapse:collapse}
|
|
33
|
-
td,th{height:${String(
|
|
33
|
+
td,th{height:${String(F)}px;padding:0 3px;overflow:hidden;white-space:pre;vertical-align:bottom}
|
|
34
34
|
td.over{overflow:visible}
|
|
35
35
|
.chart{position:absolute;line-height:0}
|
|
36
36
|
.grid td{border:1px solid #e3e3e3}
|
|
37
37
|
.edged th{border:1px solid #e3e3e3;background:#f5f5f5;color:#555;font-weight:normal;text-align:center;vertical-align:middle;font-size:9pt}
|
|
38
38
|
${t}
|
|
39
|
-
</style><script>${
|
|
39
|
+
</style><script>${vt}<\/script></head><body>${e}</body></html>`}export function sheetHtml(n,t={}){const e=t.sheets??n.wb.sheets.filter(i=>i.spec.hidden!==!0),o=new L,l=[];let r=0;const a=e.length>1&&t.area===void 0,f=e.map(i=>{const s=new W(n,i,t.file),d=t.area??rt(i)??{top:0,left:0,bottom:0,right:0},h=[];for(let b=d.top;b<=d.bottom;b++)E(n,i,b)||h.push(b);const p=[];for(let b=d.left;b<=d.right;b++)N(i,b)||p.push(b);const w=h.slice(0,t.rows??h.length),$=p.slice(0,t.columns??p.length);if(w.length<h.length||$.length<p.length){const b=w[w.length-1]??d.top,C=$[$.length-1]??d.left;l.push(`${i.name}: drew ${T({row:d.top,col:d.left})}:${T({row:b,col:C})} of ${String(h.length)} rows and ${String(p.length)} columns`)}const u=t.headings===!0,y=s.table(w,$,o,{headings:u,className:u?i.spec.gridlines===!1?"edged":"edged grid":""});r=Math.max(r,y.width);const S=s.charts(w,$,{left:u?B:0,top:u?F:0});return`<section class="sheet">${a?`<h2>${x(i.name)}</h2>`:""}<div class="book">${y.html}${S}</div></section>`});return{html:G(t,`h2{font:bold 12pt var(--font);margin:0 0 8px}
|
|
40
40
|
.sheet+.sheet{margin-top:24px}
|
|
41
41
|
.book{position:relative;width:max-content;overflow:hidden}
|
|
42
|
-
${
|
|
43
|
-
`);return G(
|
|
42
|
+
${o.css()}`,f.join("")),width:r,cut:l}}const H=n=>String(n).padStart(2,"0");export function headerFooterHtml(n,t){let e="",o=0;const l=a=>{e+=`<span style="${a}">`,o++},r={B:"font-weight:bold",I:"font-style:italic",U:"text-decoration:underline",E:"text-decoration:underline double",S:"text-decoration:line-through",X:"vertical-align:super;font-size:smaller",Y:"vertical-align:sub;font-size:smaller"};for(let a=0;a<n.length;a++){const f=n[a]??"";if(f!=="&"){e+=x(f);continue}const c=n[a+1]??"",i=c.toUpperCase();if(a++,c==="&")e+="&";else if(i==="P"||i==="N"){const s=/^[+-]\d+/u.exec(n.slice(a+1)),d=i==="P"?t.page:t.pages;e+=String(d+(s?Number(s[0]):0)),s&&(a+=s[0].length)}else if(i==="D")e+=`${String(t.date.getFullYear())}-${H(t.date.getMonth()+1)}-${H(t.date.getDate())}`;else if(i==="T")e+=`${H(t.date.getHours())}:${H(t.date.getMinutes())}`;else if(i==="F"||i==="Z")e+=x(t.file);else if(i==="A")e+=x(t.sheet);else{if(i==="G")continue;if(r[i]!==void 0)l(r[i]);else if(c==='"'){const s=n.indexOf('"',a+1),[d="",h=""]=n.slice(a+1,s<0?n.length:s).split(",");a=s<0?n.length:s;const p=[d==="-"||d===""?"":`font-family:"${d.replace(/["\\]/gu,"")}",var(--font)`,/bold/iu.test(h)?"font-weight:bold":"",/italic/iu.test(h)?"font-style:italic":""].filter(Boolean).join(";");p!==""&&l(p)}else if(/\d/u.test(c)){const s=/^\d+/u.exec(n.slice(a))?.[0]??c;a+=s.length-1,l(`font-size:${s}pt`)}else if(i==="K"){const s=n.slice(a+1,a+7);a+=6,/^[0-9A-Fa-f]{6}$/u.test(s)&&l(`color:#${s}`)}}}return e+"</span>".repeat(o)}const m=n=>`${String(Math.round(n*1e3)/1e3)}px`;export class SheetPrint{job;calc;drawers=new Map;file;constructor(t,e={}){this.calc=t,this.file=e.file,this.job=ot(t,{...e.sheets?{sheets:e.sheets}:{},height:(o,l)=>this.drawer(o).height(l)})}drawer(t){let e=this.drawers.get(t);return e||(e=new W(this.calc,t,this.file),this.drawers.set(t,e)),e}html(t,e,o){const l=new L,r=new Map,a=[];for(const c of this.job.pages.slice(t,e)){const{of:i}=c,s=`${m(i.paper.width)} ${m(i.paper.height)}`;let d=r.get(s);d===void 0&&(d=`paper${String(r.size)}`,r.set(s,d)),a.push(this.page(c,l,d,o))}const f=[...r].map(([c,i])=>`@page ${i}{size:${c};margin:0}`).join(`
|
|
43
|
+
`);return G(o,`${f}
|
|
44
44
|
.page{position:relative;overflow:hidden;break-after:page}
|
|
45
45
|
.page:last-child{break-after:auto}
|
|
46
46
|
.body,.charts{position:absolute;overflow:hidden}
|
|
@@ -49,4 +49,4 @@ ${i.css()}`,f.join("")),width:r,cut:l}}const z=o=>String(o).padStart(2,"0");expo
|
|
|
49
49
|
.hf>div{flex:1 1 0;overflow:visible}
|
|
50
50
|
.hf>.c{text-align:center}
|
|
51
51
|
.hf>.r{text-align:right}
|
|
52
|
-
${l.css()}`,
|
|
52
|
+
${l.css()}`,a.join(""))}page(t,e,o,l){const{of:r}=t,a=this.drawer(r.sheet),{margins:f,scale:c}=r,i=st(t),s=nt(t),d=r.rows.slice(t.down.from,t.down.to),h=r.cols.slice(t.across.from,t.across.to),p=a.table([...i,...d],[...s,...h],e,{headings:!1}),w=i.reduce((g,v)=>g+a.height(v),0),$=s.reduce((g,v)=>g+R(r.sheet,v),0),u=r.rowAt[t.down.from]??0,y=r.colAt[t.across.from]??0,S=(r.rowAt[t.down.to]??0)-u,b=(r.colAt[t.across.to]??0)-y,C=r.charts.filter(g=>g.left<y+b&&g.left+g.width>y&&g.top<u+S&&g.top+g.height>u).map(g=>`<div class="chart" style="left:${m(g.left-y)};top:${m(g.top-u)}">${a.svg(g.chart)}</div>`).join(""),A=C===""?"":`<div class="charts" style="left:${m($)};top:${m(w)};width:${m(b)};height:${m(S)}">${C}</div>`,M=r.paper.width-f.left-f.right,z=r.paper.height-f.top-f.bottom,D={page:t.number,pages:this.job.pages.length,sheet:r.sheet.name,file:l.name,date:l.date},j=(g,v)=>g?`<div class="hf" style="left:${m(f.left)};right:${m(f.right)};${v}"><div>${headerFooterHtml(g.left??"",D)}</div><div class="c">${headerFooterHtml(g.center??"",D)}</div><div class="r">${headerFooterHtml(g.right??"",D)}</div></div>`:"";return`<section class="page" style="page:${o};width:${m(r.paper.width)};height:${m(r.paper.height)}">`+j(r.header,`top:${m(f.header)}`)+`<div class="body" style="left:${m(f.left)};top:${m(f.top)};width:${m(M)};height:${m(z)}"><div class="scaled" style="width:${m(M/c)};height:${m(z/c)}${c===1?"":`;transform:scale(${String(c)})`}">`+p.html+A+"</div></div>"+j(r.footer,`bottom:${m(f.footer)}`)+"</section>"}}
|
|
@@ -24,12 +24,17 @@ export { generalForms, generalText, isDateCode, shownColor, shownValue, } from "
|
|
|
24
24
|
export { DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_HEIGHT, headerFooterHtml, sheetHtml, SheetPrint, type PageFields, type PrintHtmlOptions, type SheetHtml, type SheetHtmlOptions, } from "./html.js";
|
|
25
25
|
export { PAPERS, PRINT_DEFAULTS, paginate, type PaginateOptions, type PrintJob, type PrintedPage, type SheetPages, } from "./paginate.js";
|
|
26
26
|
export { DEFAULT_TABLE_STYLE, tableStyleLook, tableStyleOf, type TablePart, type TableStyle, } from "./table-style.js";
|
|
27
|
+
export { TABLE_STYLES } from "./table-styles.js";
|
|
27
28
|
export { PROFILE_TOP, profileTable, type ColumnProfile } from "./profile.js";
|
|
28
29
|
export { importRows, type ImportedSheet } from "./import.js";
|
|
29
30
|
export { patchYaml, writeYaml } from "./write.js";
|
|
30
31
|
export * from "./edit.js";
|
|
32
|
+
export * from "./rich.js";
|
|
33
|
+
export * from "./annotations.js";
|
|
31
34
|
export * from "./arrange.js";
|
|
32
|
-
export
|
|
35
|
+
export * from "./outline.js";
|
|
36
|
+
export * from "./data-tools.js";
|
|
37
|
+
export { NO_LOOK, autoFill, copyLooks, fillDownTo, moveCells, pasteLooks, shiftCells, type CellShift, type LookCopy, } from "./fill.js";
|
|
33
38
|
export { seriesAfter, type FillMode } from "./series.js";
|
|
34
39
|
export { compareForSort, hasHeader, sortCells, sortedOrder, sortedRows, type SortKey, } from "./sort.js";
|
|
35
40
|
export { filterChoices, filteredRows, regionAround, type FilterChoice, } from "./filter.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
-
export*from"./address.js";export{patchCsv}from"./patch.js";export{printedFacts,printedLines}from"./printed.js";export*from"./values.js";export*from"./workbook.js";export*from"./calc/remote.js";export*from"./calc/server.js";export{CODE as SHEET_CODE,ENTRY as SHEET_ENTRY,codeOf,dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,ITERATION_DEFAULTS,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,csvText,dataValue,excelNumber,tableRows}from"./export.js";export{generalForms,generalText,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,headerFooterHtml,sheetHtml,SheetPrint}from"./html.js";export{PAPERS,PRINT_DEFAULTS,paginate}from"./paginate.js";export{DEFAULT_TABLE_STYLE,tableStyleLook,tableStyleOf}from"./table-style.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./arrange.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
|
|
2
|
+
export*from"./address.js";export{patchCsv}from"./patch.js";export{printedFacts,printedLines}from"./printed.js";export*from"./values.js";export*from"./workbook.js";export*from"./calc/remote.js";export*from"./calc/server.js";export{CODE as SHEET_CODE,ENTRY as SHEET_ENTRY,codeOf,dataFilesOf,readSheetFile}from"./file.js";export{GENERATED,ordinarySheet,typedNumbers,withGenerated}from"./generated.js";export{applyScenario,cellOfName,scenarioNames,scenariosByCell}from"./scenario.js";export{fileCells,hasFiles,isPicture,pictureHeight,pictureSize}from"./files.js";export*from"./formula/ast.js";export{parseFormula}from"./formula/parse.js";export{printFormula,sheetPrefix}from"./formula/print.js";export{moveFormula}from"./formula/move.js";export{rewriteFormula}from"./formula/rewrite.js";export{Calc,ITERATION_DEFAULTS,seededRandom}from"./calc/engine.js";export{analyse}from"./calc/analyse.js";export{FUNCTIONS}from"./calc/functions/index.js";export{Reference}from"./calc/types.js";export{checkWorkbook,placeName}from"./check.js";export{csvOf,csvText,dataValue,excelNumber,tableRows}from"./export.js";export{generalForms,generalText,isDateCode,shownColor,shownValue}from"./format.js";export{DEFAULT_COLUMN_WIDTH,DEFAULT_ROW_HEIGHT,headerFooterHtml,sheetHtml,SheetPrint}from"./html.js";export{PAPERS,PRINT_DEFAULTS,paginate}from"./paginate.js";export{DEFAULT_TABLE_STYLE,tableStyleLook,tableStyleOf}from"./table-style.js";export{TABLE_STYLES}from"./table-styles.js";export{PROFILE_TOP,profileTable}from"./profile.js";export{importRows}from"./import.js";export{patchYaml,writeYaml}from"./write.js";export*from"./edit.js";export*from"./rich.js";export*from"./annotations.js";export*from"./arrange.js";export*from"./outline.js";export*from"./data-tools.js";export{NO_LOOK,autoFill,copyLooks,fillDownTo,moveCells,pasteLooks,shiftCells}from"./fill.js";export{seriesAfter}from"./series.js";export{compareForSort,hasHeader,sortCells,sortedOrder,sortedRows}from"./sort.js";export{filterChoices,filteredRows,regionAround}from"./filter.js";export{Rules,colorBetween,compareValues,holds,iconShape}from"./rules.js";export{choicesIn,invalidCells,joinChoices,listValues,separatorOf,valid}from"./validate.js";export{freeColumn,restructure,tableShape,uniqueColumn,withColumnsUpTo}from"./structure.js";export{SHEET_CHART_DEFAULTS,chartAfter,chartDataRange,chartDef,chartOfRange,chartPlace,chartSize,chartSvg,readDataRange}from"./chart.js";export{INSPECT_DEFAULTS,SHEET_FACT_KINDS,inspectWorkbook}from"./inspect.js";export{DIFF_DEFAULTS,diffWorkbooks}from"./diff.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SheetWorksheet } from "@allyhub/formats";
|
|
2
|
+
import { type BookEdit, type EditBook } from "./edit.js";
|
|
3
|
+
export type OutlineAxis = "rows" | "columns";
|
|
4
|
+
/** A group: its level and the rows or columns it holds, from 0. */
|
|
5
|
+
export interface OutlineGroup {
|
|
6
|
+
level: number;
|
|
7
|
+
from: number;
|
|
8
|
+
to: number;
|
|
9
|
+
/** Every one of its rows or columns is hidden: Excel draws its button as +. */
|
|
10
|
+
collapsed: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** How deep the sheet's rows or columns are grouped: 0 for none. */
|
|
13
|
+
export declare function outlineDepth(spec: SheetWorksheet, axis: OutlineAxis): number;
|
|
14
|
+
/** Every group of the sheet's rows or columns, each level's in order. */
|
|
15
|
+
export declare function outlineGroups(spec: SheetWorksheet, axis: OutlineAxis): OutlineGroup[];
|
|
16
|
+
/** Where a group's summary is: the row after it or the column right of it, unless the sheet says before. */
|
|
17
|
+
export declare function summaryOf(spec: SheetWorksheet, axis: OutlineAxis, group: {
|
|
18
|
+
from: number;
|
|
19
|
+
to: number;
|
|
20
|
+
}): number;
|
|
21
|
+
/** Group (by 1) and Ungroup (by -1): each row or column one level deeper or shallower, 0 to 7. */
|
|
22
|
+
export declare function groupBands(book: EditBook, sheetName: string, axis: OutlineAxis, from: number, to: number, by: 1 | -1): BookEdit;
|
|
23
|
+
/** Show Detail and Hide Detail, and a group's + and −: its rows or columns shown, or hidden. */
|
|
24
|
+
export declare function showGroup(book: EditBook, sheetName: string, axis: OutlineAxis, group: {
|
|
25
|
+
from: number;
|
|
26
|
+
to: number;
|
|
27
|
+
}, shown: boolean): BookEdit;
|
|
28
|
+
/** A level button: what is grouped deeper than the level hidden, the rest shown. */
|
|
29
|
+
export declare function showLevel(book: EditBook, sheetName: string, axis: OutlineAxis, level: number): BookEdit;
|
|
30
|
+
//# sourceMappingURL=outline.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
+
import{columnIndex as y,columnLetter as g}from"./address.js";import{Draft as j,refused as w}from"./edit.js";const k=(e,t)=>e==="rows"?Number(t)-1:y(t),x=(e,t)=>e==="rows"?String(t+1):g(t);function h(e,t){const o=new Map,s=(t==="rows"?e.rows:e.columns)??{};for(const[l,i]of Object.entries(s)){const n=k(t,l);n!==void 0&&Number.isInteger(n)&&n>=0&&o.set(n,i)}return o}export function outlineDepth(e,t){let o=0;for(const s of h(e,t).values())o=Math.max(o,s.level??0);return o}export function outlineGroups(e,t){const o=h(e,t),s=[...o].filter(([,n])=>(n.level??0)>0).map(([n])=>n).sort((n,r)=>n-r),l=[],i=outlineDepth(e,t);for(let n=1;n<=i;n++){let r,u=-2;const c=()=>{if(r===void 0)return;let f=!0;for(let d=r;d<=u;d++)o.get(d)?.hidden!==!0&&(f=!1);l.push({level:n,from:r,to:u,collapsed:f}),r=void 0};for(const f of s)(o.get(f)?.level??0)<n||(f!==u+1&&c(),r??=f,u=f);c()}return l}export function summaryOf(e,t,o){return(t==="rows"?e.outline?.summary_below!==!1:e.outline?.summary_right!==!1)?o.to+1:Math.max(0,o.from-1)}function a(e,t,o,s,l){const i=e.workbook.sheet(t);if(!i)return w("no-sheet");const n=new j(e),r=n.spec(i),u=(o==="rows"?r.rows:r.columns)??{},c=new Map(Object.entries(u));for(const d of l){const m=x(o,d),b=s(d,c.get(m)??{}),p=Object.fromEntries(Object.entries(b).filter(([,O])=>O!==void 0));Object.keys(p).length===0?c.delete(m):c.set(m,p)}const f=c.size===0?void 0:Object.fromEntries(c);return o==="rows"?f?r.rows=f:delete r.rows:f?r.columns=f:delete r.columns,n.finish()}const v=(e,t)=>Array.from({length:t-e+1},(o,s)=>e+s);export function groupBands(e,t,o,s,l,i){return a(e,t,o,(n,r)=>{const u=Math.max(0,Math.min(7,(r.level??0)+i));return{...r,level:u===0?void 0:u,hidden:u===0&&(r.level??0)>0?void 0:r.hidden}},v(s,l))}export function showGroup(e,t,o,s,l){return a(e,t,o,(i,n)=>({...n,hidden:l?void 0:!0}),v(s.from,s.to))}export function showLevel(e,t,o,s){const l=e.workbook.sheet(t);if(!l)return w("no-sheet");const i=[...h(l.spec,o)].filter(([,n])=>(n.level??0)>0).map(([n])=>n);return a(e,t,o,(n,r)=>({...r,hidden:(r.level??0)>=s?!0:void 0}),i)}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SheetRun } from "@allyhub/formats";
|
|
2
|
+
/** What a run can say of its font. */
|
|
3
|
+
export type RunLook = Omit<SheetRun, "text">;
|
|
4
|
+
/** A run's fields, in the order sheet.yaml writes them. */
|
|
5
|
+
export declare const RUN_FIELDS: readonly ["bold", "italic", "underline", "strike", "font", "size", "color", "script"];
|
|
6
|
+
/** A run's look alone. */
|
|
7
|
+
export declare function runLook(run: SheetRun): RunLook;
|
|
8
|
+
/** Runs with nothing empty, two alike side by side made one, each in sheet.yaml's order. */
|
|
9
|
+
export declare function joinedRuns(runs: readonly SheetRun[]): SheetRun[];
|
|
10
|
+
/** Whether runs say nothing of their font: a cell's plain text. */
|
|
11
|
+
export declare const plainRuns: (runs: readonly SheetRun[]) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A look given to characters `from` to `to` (not included) of a cell's
|
|
14
|
+
* runs: a field set is that run's, a field set to undefined goes, so the
|
|
15
|
+
* cell's holds there again.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatRuns(runs: readonly SheetRun[], from: number, to: number, patch: Partial<Record<keyof RunLook, unknown>>): SheetRun[];
|
|
18
|
+
/** The fields of a look that runs speak over, taken away from them: what a look given to the whole cell does. */
|
|
19
|
+
export declare function runsWithout(runs: readonly SheetRun[], fields: Iterable<string>): SheetRun[];
|
|
20
|
+
/** What holds at a character: the run it is in (the one before it at a boundary, as typing there takes). */
|
|
21
|
+
export declare function runAt(runs: readonly SheetRun[], at: number): SheetRun | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Runs over a text that has changed: what is the same at its start and its
|
|
24
|
+
* end keeps its runs, what came between takes the look of the first
|
|
25
|
+
* character it replaced, or, typed between two, of the one before it; what
|
|
26
|
+
* went is gone.
|
|
27
|
+
*/
|
|
28
|
+
export declare function retextRuns(runs: readonly SheetRun[], text: string): SheetRun[];
|
|
29
|
+
//# sourceMappingURL=rich.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
|
|
2
|
+
export const RUN_FIELDS=["bold","italic","underline","strike","font","size","color","script"];export function runLook(o){return Object.fromEntries(Object.entries(o).filter(([t])=>t!=="text"))}const p=(o,t)=>RUN_FIELDS.every(e=>o[e]===t[e]);function a(o){const t={text:o.text};for(const e of RUN_FIELDS)o[e]!==void 0&&(t[e]=o[e]);return t}export function joinedRuns(o){const t=[];for(const e of o){if(e.text==="")continue;const r=t[t.length-1];r&&p(runLook(r),runLook(e))?t[t.length-1]={...r,text:r.text+e.text}:t.push(a(e))}return t}export const plainRuns=o=>o.every(t=>RUN_FIELDS.every(e=>t[e]===void 0));function f(o,t){const e=[];let r=0;for(const n of o){const s=r+n.text.length;t>r&&t<s?(e.push({...n,text:n.text.slice(0,t-r)}),e.push({...n,text:n.text.slice(t-r)})):e.push(n),r=s}return e}export function formatRuns(o,t,e,r){const n=f(f(o,t),e);let s=0;return joinedRuns(n.map(i=>{const c=s+i.text.length,l=s>=t&&c<=e;if(s=c,!l)return i;const x=Object.entries(r).filter(([,u])=>u!==void 0);return Object.fromEntries([...Object.entries(i).filter(([u])=>!(u in r)),...x])}))}export function runsWithout(o,t){const e=new Set(t);return joinedRuns(o.map(r=>Object.fromEntries(Object.entries(r).filter(([n])=>!e.has(n)))))}export function runAt(o,t){let e=0;for(const r of o){const n=e+r.text.length;if(t>e&&t<=n||t===0&&e===0&&r.text!=="")return r;e=n}return o[o.length-1]}function h(o,t,e){const r=[];let n=0;for(const s of o){const i=n+s.text.length,c=Math.max(t,n),l=Math.min(e,i);c<l&&r.push({...s,text:s.text.slice(c-n,l-n)}),n=i}return r}export function retextRuns(o,t){const e=o.map(c=>c.text).join("");if(e===t)return[...o];const r=Math.min(e.length,t.length);let n=0;for(;n<r&&e[n]===t[n];)n+=1;let s=0;for(;s<r-n&&e[e.length-1-s]===t[t.length-1-s];)s+=1;const i=runAt(o,e.length-s>n?n+1:n);return joinedRuns([...h(o,0,n),{...i?runLook(i):{},text:t.slice(n,t.length-s)},...h(o,e.length-s,e.length)])}
|