@gridsheet/core 3.0.0-rc.10

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.
Files changed (251) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +17 -0
  3. package/dist/constants.d.ts +21 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +28 -0
  6. package/dist/constants.js.map +1 -0
  7. package/dist/formula/evaluator.d.ts +134 -0
  8. package/dist/formula/evaluator.d.ts.map +1 -0
  9. package/dist/formula/evaluator.js +585 -0
  10. package/dist/formula/evaluator.js.map +1 -0
  11. package/dist/formula/formula-error.d.ts +10 -0
  12. package/dist/formula/formula-error.d.ts.map +1 -0
  13. package/dist/formula/formula-error.js +15 -0
  14. package/dist/formula/formula-error.js.map +1 -0
  15. package/dist/formula/functions/__async.d.ts +67 -0
  16. package/dist/formula/functions/__async.d.ts.map +1 -0
  17. package/dist/formula/functions/__async.js +70 -0
  18. package/dist/formula/functions/__async.js.map +1 -0
  19. package/dist/formula/functions/__base.d.ts +112 -0
  20. package/dist/formula/functions/__base.d.ts.map +1 -0
  21. package/dist/formula/functions/__base.js +265 -0
  22. package/dist/formula/functions/__base.js.map +1 -0
  23. package/dist/formula/functions/__utils.d.ts +28 -0
  24. package/dist/formula/functions/__utils.d.ts.map +1 -0
  25. package/dist/formula/functions/__utils.js +179 -0
  26. package/dist/formula/functions/__utils.js.map +1 -0
  27. package/dist/formula/functions/abs.d.ts +9 -0
  28. package/dist/formula/functions/abs.d.ts.map +1 -0
  29. package/dist/formula/functions/abs.js +15 -0
  30. package/dist/formula/functions/abs.js.map +1 -0
  31. package/dist/formula/functions/add.d.ts +10 -0
  32. package/dist/formula/functions/add.d.ts.map +1 -0
  33. package/dist/formula/functions/add.js +37 -0
  34. package/dist/formula/functions/add.js.map +1 -0
  35. package/dist/formula/functions/and.d.ts +9 -0
  36. package/dist/formula/functions/and.d.ts.map +1 -0
  37. package/dist/formula/functions/and.js +23 -0
  38. package/dist/formula/functions/and.js.map +1 -0
  39. package/dist/formula/functions/arrayformula.d.ts +12 -0
  40. package/dist/formula/functions/arrayformula.d.ts.map +1 -0
  41. package/dist/formula/functions/arrayformula.js +24 -0
  42. package/dist/formula/functions/arrayformula.js.map +1 -0
  43. package/dist/formula/functions/average.d.ts +9 -0
  44. package/dist/formula/functions/average.d.ts.map +1 -0
  45. package/dist/formula/functions/average.js +40 -0
  46. package/dist/formula/functions/average.js.map +1 -0
  47. package/dist/formula/functions/concat.d.ts +9 -0
  48. package/dist/formula/functions/concat.d.ts.map +1 -0
  49. package/dist/formula/functions/concat.js +27 -0
  50. package/dist/formula/functions/concat.js.map +1 -0
  51. package/dist/formula/functions/count.d.ts +9 -0
  52. package/dist/formula/functions/count.d.ts.map +1 -0
  53. package/dist/formula/functions/count.js +32 -0
  54. package/dist/formula/functions/count.js.map +1 -0
  55. package/dist/formula/functions/counta.d.ts +9 -0
  56. package/dist/formula/functions/counta.d.ts.map +1 -0
  57. package/dist/formula/functions/counta.js +32 -0
  58. package/dist/formula/functions/counta.js.map +1 -0
  59. package/dist/formula/functions/divide.d.ts +10 -0
  60. package/dist/formula/functions/divide.d.ts.map +1 -0
  61. package/dist/formula/functions/divide.js +34 -0
  62. package/dist/formula/functions/divide.js.map +1 -0
  63. package/dist/formula/functions/eq.d.ts +9 -0
  64. package/dist/formula/functions/eq.d.ts.map +1 -0
  65. package/dist/formula/functions/eq.js +19 -0
  66. package/dist/formula/functions/eq.js.map +1 -0
  67. package/dist/formula/functions/gt.d.ts +9 -0
  68. package/dist/formula/functions/gt.d.ts.map +1 -0
  69. package/dist/formula/functions/gt.js +19 -0
  70. package/dist/formula/functions/gt.js.map +1 -0
  71. package/dist/formula/functions/gte.d.ts +9 -0
  72. package/dist/formula/functions/gte.d.ts.map +1 -0
  73. package/dist/formula/functions/gte.js +19 -0
  74. package/dist/formula/functions/gte.js.map +1 -0
  75. package/dist/formula/functions/if.d.ts +9 -0
  76. package/dist/formula/functions/if.d.ts.map +1 -0
  77. package/dist/formula/functions/if.js +29 -0
  78. package/dist/formula/functions/if.js.map +1 -0
  79. package/dist/formula/functions/iferror.d.ts +10 -0
  80. package/dist/formula/functions/iferror.d.ts.map +1 -0
  81. package/dist/formula/functions/iferror.js +28 -0
  82. package/dist/formula/functions/iferror.js.map +1 -0
  83. package/dist/formula/functions/len.d.ts +9 -0
  84. package/dist/formula/functions/len.d.ts.map +1 -0
  85. package/dist/formula/functions/len.js +21 -0
  86. package/dist/formula/functions/len.js.map +1 -0
  87. package/dist/formula/functions/lt.d.ts +9 -0
  88. package/dist/formula/functions/lt.d.ts.map +1 -0
  89. package/dist/formula/functions/lt.js +19 -0
  90. package/dist/formula/functions/lt.js.map +1 -0
  91. package/dist/formula/functions/lte.d.ts +9 -0
  92. package/dist/formula/functions/lte.d.ts.map +1 -0
  93. package/dist/formula/functions/lte.js +19 -0
  94. package/dist/formula/functions/lte.js.map +1 -0
  95. package/dist/formula/functions/max.d.ts +9 -0
  96. package/dist/formula/functions/max.d.ts.map +1 -0
  97. package/dist/formula/functions/max.js +37 -0
  98. package/dist/formula/functions/max.js.map +1 -0
  99. package/dist/formula/functions/min.d.ts +9 -0
  100. package/dist/formula/functions/min.d.ts.map +1 -0
  101. package/dist/formula/functions/min.js +37 -0
  102. package/dist/formula/functions/min.js.map +1 -0
  103. package/dist/formula/functions/minus.d.ts +10 -0
  104. package/dist/formula/functions/minus.d.ts.map +1 -0
  105. package/dist/formula/functions/minus.js +41 -0
  106. package/dist/formula/functions/minus.js.map +1 -0
  107. package/dist/formula/functions/multiply.d.ts +9 -0
  108. package/dist/formula/functions/multiply.d.ts.map +1 -0
  109. package/dist/formula/functions/multiply.js +19 -0
  110. package/dist/formula/functions/multiply.js.map +1 -0
  111. package/dist/formula/functions/ne.d.ts +9 -0
  112. package/dist/formula/functions/ne.d.ts.map +1 -0
  113. package/dist/formula/functions/ne.js +19 -0
  114. package/dist/formula/functions/ne.js.map +1 -0
  115. package/dist/formula/functions/not.d.ts +9 -0
  116. package/dist/formula/functions/not.d.ts.map +1 -0
  117. package/dist/formula/functions/not.js +22 -0
  118. package/dist/formula/functions/not.js.map +1 -0
  119. package/dist/formula/functions/now.d.ts +9 -0
  120. package/dist/formula/functions/now.d.ts.map +1 -0
  121. package/dist/formula/functions/now.js +14 -0
  122. package/dist/formula/functions/now.js.map +1 -0
  123. package/dist/formula/functions/or.d.ts +9 -0
  124. package/dist/formula/functions/or.d.ts.map +1 -0
  125. package/dist/formula/functions/or.js +23 -0
  126. package/dist/formula/functions/or.js.map +1 -0
  127. package/dist/formula/functions/power.d.ts +9 -0
  128. package/dist/formula/functions/power.d.ts.map +1 -0
  129. package/dist/formula/functions/power.js +18 -0
  130. package/dist/formula/functions/power.js.map +1 -0
  131. package/dist/formula/functions/sum.d.ts +9 -0
  132. package/dist/formula/functions/sum.d.ts.map +1 -0
  133. package/dist/formula/functions/sum.js +34 -0
  134. package/dist/formula/functions/sum.js.map +1 -0
  135. package/dist/formula/functions/uminus.d.ts +9 -0
  136. package/dist/formula/functions/uminus.d.ts.map +1 -0
  137. package/dist/formula/functions/uminus.js +17 -0
  138. package/dist/formula/functions/uminus.js.map +1 -0
  139. package/dist/formula/mapping.d.ts +11 -0
  140. package/dist/formula/mapping.d.ts.map +1 -0
  141. package/dist/formula/mapping.js +82 -0
  142. package/dist/formula/mapping.js.map +1 -0
  143. package/dist/formula/solver.d.ts +39 -0
  144. package/dist/formula/solver.d.ts.map +1 -0
  145. package/dist/formula/solver.js +71 -0
  146. package/dist/formula/solver.js.map +1 -0
  147. package/dist/index.d.ts +32 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +132 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/lib/autofill.d.ts +22 -0
  152. package/dist/lib/autofill.d.ts.map +1 -0
  153. package/dist/lib/autofill.js +276 -0
  154. package/dist/lib/autofill.js.map +1 -0
  155. package/dist/lib/book.d.ts +131 -0
  156. package/dist/lib/book.d.ts.map +1 -0
  157. package/dist/lib/book.js +53 -0
  158. package/dist/lib/book.js.map +1 -0
  159. package/dist/lib/cell.d.ts +17 -0
  160. package/dist/lib/cell.d.ts.map +1 -0
  161. package/dist/lib/cell.js +17 -0
  162. package/dist/lib/cell.js.map +1 -0
  163. package/dist/lib/coords.d.ts +22 -0
  164. package/dist/lib/coords.d.ts.map +1 -0
  165. package/dist/lib/coords.js +73 -0
  166. package/dist/lib/coords.js.map +1 -0
  167. package/dist/lib/date.d.ts +2 -0
  168. package/dist/lib/date.d.ts.map +1 -0
  169. package/dist/lib/date.js +91 -0
  170. package/dist/lib/date.js.map +1 -0
  171. package/dist/lib/dom.d.ts +7 -0
  172. package/dist/lib/dom.d.ts.map +1 -0
  173. package/dist/lib/dom.js +28 -0
  174. package/dist/lib/dom.js.map +1 -0
  175. package/dist/lib/filter.d.ts +7 -0
  176. package/dist/lib/filter.d.ts.map +1 -0
  177. package/dist/lib/filter.js +122 -0
  178. package/dist/lib/filter.js.map +1 -0
  179. package/dist/lib/input.d.ts +28 -0
  180. package/dist/lib/input.d.ts.map +1 -0
  181. package/dist/lib/input.js +73 -0
  182. package/dist/lib/input.js.map +1 -0
  183. package/dist/lib/label.d.ts +4 -0
  184. package/dist/lib/label.d.ts.map +1 -0
  185. package/dist/lib/label.js +10 -0
  186. package/dist/lib/label.js.map +1 -0
  187. package/dist/lib/operation.d.ts +31 -0
  188. package/dist/lib/operation.d.ts.map +1 -0
  189. package/dist/lib/operation.js +36 -0
  190. package/dist/lib/operation.js.map +1 -0
  191. package/dist/lib/palette.d.ts +2 -0
  192. package/dist/lib/palette.d.ts.map +1 -0
  193. package/dist/lib/palette.js +26 -0
  194. package/dist/lib/palette.js.map +1 -0
  195. package/dist/lib/popup.d.ts +24 -0
  196. package/dist/lib/popup.d.ts.map +1 -0
  197. package/dist/lib/popup.js +21 -0
  198. package/dist/lib/popup.js.map +1 -0
  199. package/dist/lib/reference.d.ts +19 -0
  200. package/dist/lib/reference.d.ts.map +1 -0
  201. package/dist/lib/reference.js +40 -0
  202. package/dist/lib/reference.js.map +1 -0
  203. package/dist/lib/sheet.d.ts +512 -0
  204. package/dist/lib/sheet.d.ts.map +1 -0
  205. package/dist/lib/sheet.js +1530 -0
  206. package/dist/lib/sheet.js.map +1 -0
  207. package/dist/lib/sheet_utils.d.ts +55 -0
  208. package/dist/lib/sheet_utils.d.ts.map +1 -0
  209. package/dist/lib/sheet_utils.js +125 -0
  210. package/dist/lib/sheet_utils.js.map +1 -0
  211. package/dist/lib/spatial.d.ts +79 -0
  212. package/dist/lib/spatial.d.ts.map +1 -0
  213. package/dist/lib/spatial.js +227 -0
  214. package/dist/lib/spatial.js.map +1 -0
  215. package/dist/lib/time.d.ts +29 -0
  216. package/dist/lib/time.d.ts.map +1 -0
  217. package/dist/lib/time.js +113 -0
  218. package/dist/lib/time.js.map +1 -0
  219. package/dist/lib/virtualization.d.ts +22 -0
  220. package/dist/lib/virtualization.d.ts.map +1 -0
  221. package/dist/lib/virtualization.js +91 -0
  222. package/dist/lib/virtualization.js.map +1 -0
  223. package/dist/policy/core.d.ts +161 -0
  224. package/dist/policy/core.d.ts.map +1 -0
  225. package/dist/policy/core.js +248 -0
  226. package/dist/policy/core.js.map +1 -0
  227. package/dist/policy/thousand_separator.d.ts +4 -0
  228. package/dist/policy/thousand_separator.d.ts.map +1 -0
  229. package/dist/policy/thousand_separator.js +13 -0
  230. package/dist/policy/thousand_separator.js.map +1 -0
  231. package/dist/sentinels.d.ts +40 -0
  232. package/dist/sentinels.d.ts.map +1 -0
  233. package/dist/sentinels.js +41 -0
  234. package/dist/sentinels.js.map +1 -0
  235. package/dist/styles/embedder.d.ts +2 -0
  236. package/dist/styles/embedder.d.ts.map +1 -0
  237. package/dist/styles/embedder.js +11 -0
  238. package/dist/styles/embedder.js.map +1 -0
  239. package/dist/styles/minified.d.ts +3 -0
  240. package/dist/styles/minified.d.ts.map +1 -0
  241. package/dist/styles/minified.js +6 -0
  242. package/dist/styles/minified.js.map +1 -0
  243. package/dist/types.d.ts +310 -0
  244. package/dist/types.d.ts.map +1 -0
  245. package/dist/types.js +2 -0
  246. package/dist/types.js.map +1 -0
  247. package/dist/utils.d.ts +2 -0
  248. package/dist/utils.d.ts.map +1 -0
  249. package/dist/utils.js +5 -0
  250. package/dist/utils.js.map +1 -0
  251. package/package.json +58 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet.js","sources":["../../src/lib/sheet.ts"],"sourcesContent":["import {\n Id,\n Ids,\n IdMatrix,\n AreaType,\n CellsByIdType,\n CellsByAddressType,\n PointType,\n Address,\n CellFilter,\n MatrixType,\n CellType,\n FilterConfig,\n HistoryType,\n HistorySortRowsType,\n StorePatchType,\n ShapeType,\n RectType,\n OperatorType,\n OperationType,\n RawCellType,\n ExtraPointType,\n RefLike,\n Resolution,\n MoveRelations,\n Y,\n X,\n System,\n} from '../types';\nimport { among, areaShape, createMatrix, expandRange, getMaxSizesFromCells, matrixShape } from './spatial';\nimport { a2p, x2c, c2x, p2a, y2r, grantAddressAbsolute } from './coords';\nimport type { FunctionMapping } from '../formula/functions/__base';\nimport { Lexer, ProcessFormulaProps } from '../formula/evaluator';\nimport { FormulaError } from '../formula/formula-error';\nimport { solveFormula, SolveOptions, solveSheet, stripSheet } from '../formula/solver';\nimport { ensureSys, filterCellFields } from './cell';\nimport { escapeSheetName, toSheetPrefix } from './sheet_utils';\n\nimport {\n DEFAULT_HEIGHT,\n DEFAULT_WIDTH,\n HEADER_HEIGHT,\n HEADER_WIDTH,\n DEFAULT_HISTORY_LIMIT,\n DEFAULT_KEY,\n DEFAULT_COL_KEY,\n DEFAULT_ROW_KEY,\n} from '../constants';\nimport { Pending, SOLVING, Spilling } from '../sentinels';\nimport * as operation from './operation';\n\nconst shouldTracking = (op: string) => {\n switch (op) {\n case 'INSERT_ROWS':\n case 'INSERT_COLS':\n case 'REMOVE_ROWS':\n case 'REMOVE_COLS':\n case 'MOVE':\n case 'SORT_ROWS':\n return true;\n }\n return false;\n};\nimport { Registry, createRegistry } from './book';\nimport { nonePolicy, PolicyType, DEFAULT_POLICY_NAME, RenderProps, ScalarProps } from '../policy/core';\nimport { evaluateFilterConfig } from './filter';\nimport { ReferencePreserver } from './reference';\n\ntype CellField = keyof CellType;\n\nexport type SheetLimits = {\n minRows?: number;\n maxRows?: number;\n minCols?: number;\n maxCols?: number;\n};\n\ntype Props = {\n limits?: SheetLimits;\n functions?: FunctionMapping;\n name?: string;\n registry?: Registry;\n};\n\nconst noFilter: CellFilter = () => true;\n\ntype MoveProps = {\n srcSheet?: UserSheet;\n src: AreaType;\n dst: AreaType;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n historicize?: boolean;\n};\n\nexport interface UserSheet {\n changedTime: number;\n lastChangedTime?: number;\n area: AreaType;\n top: number;\n left: number;\n bottom: number;\n right: number;\n minNumRows: number;\n maxNumRows: number;\n minNumCols: number;\n maxNumCols: number;\n headerWidth: number;\n headerHeight: number;\n name: string;\n\n /**\n * Returns the raw sheet object, which is used for internal operations.\n * This is not intended for public use and may change in future versions.\n */\n __raw__: Sheet;\n\n getRectSize(area: AreaType): RectType;\n getCell(point: PointType, options?: { resolution?: Resolution; raise?: boolean }): CellType | undefined;\n getPolicy(point: PointType): PolicyType;\n get numRows(): number;\n get numCols(): number;\n get shape(): ShapeType;\n move(args: MoveProps): UserSheet;\n copy(args: MoveProps & { onlyValue?: boolean }): UserSheet;\n update(args: {\n diff: CellsByAddressType;\n historicize?: boolean;\n partial?: boolean;\n updateChangedTime?: boolean;\n reflection?: StorePatchType;\n }): UserSheet;\n writeMatrix(args: {\n point: PointType;\n matrix: MatrixType<string>;\n updateChangedTime?: boolean;\n reflection?: StorePatchType;\n }): UserSheet;\n write(args: { point: PointType; value: string; updateChangedTime?: boolean; reflection?: StorePatchType }): UserSheet;\n insertRows(args: {\n y: number;\n numRows: number;\n baseY: number;\n diff?: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n reflection?: StorePatchType;\n }): UserSheet;\n removeRows(args: { y: number; numRows: number; reflection?: StorePatchType }): UserSheet;\n insertCols(args: {\n x: number;\n numCols: number;\n baseX: number;\n diff?: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n reflection?: StorePatchType;\n }): UserSheet;\n removeCols(args: { x: number; numCols: number; reflection?: StorePatchType }): UserSheet;\n undo(): {\n history: HistoryType | null;\n };\n redo(): {\n history: HistoryType | null;\n };\n histories(): HistoryType[];\n historyIndex(): number;\n historySize(): number;\n setHeaderHeight(height: number, historicize?: boolean): UserSheet;\n setHeaderWidth(width: number, historicize?: boolean): UserSheet;\n\n sortRows(args: { x: number; direction: 'asc' | 'desc' }): UserSheet;\n\n filterRows(args?: { x?: number; filter?: FilterConfig }): UserSheet;\n isRowFiltered(y: number): boolean;\n hasActiveFilters(): boolean;\n hasPendingCells(): boolean;\n waitForPending(): Promise<void>;\n getLastChangedAddresses(): Address[];\n getSerializedValue(props: { point: PointType; cell?: CellType; resolution?: Resolution }): string;\n}\n\ntype InternalToValueMatrixProps = {\n area?: AreaType;\n resolution?: Resolution;\n raise?: boolean;\n filter?: CellFilter;\n asScalar?: boolean;\n at?: Id;\n};\n\nexport class Sheet implements UserSheet {\n /** @internal */\n public __gsType = 'Sheet';\n public changedTime: number;\n public lastChangedTime?: number;\n public area: AreaType = { top: 0, left: 0, bottom: 0, right: 0 };\n\n /** @internal */\n private _limits: Required<SheetLimits>;\n get minNumRows() {\n return this._limits.minRows;\n }\n get maxNumRows() {\n return this._limits.maxRows;\n }\n get minNumCols() {\n return this._limits.minCols;\n }\n get maxNumCols() {\n return this._limits.maxCols;\n }\n /** @internal */\n public id: number = 0;\n public name: string = '';\n /** @internal */\n public prevName: string = '';\n /** @internal */\n public status: 0 | 1 | 2 = 0; // 0: not initialized, 1: initialized, 2: formula absoluted\n /** @internal */\n public registry: Registry;\n /** @internal */\n public idsToBeIdentified: Id[] = [];\n /** @internal */\n public totalWidth = 0;\n /** @internal */\n public totalHeight = 0;\n /** @internal */\n public fullHeight = 0;\n /** @internal */\n public defaultColWidth: number = DEFAULT_WIDTH;\n /** @internal */\n public defaultRowHeight: number = DEFAULT_HEIGHT;\n\n /** @internal */\n private version = 0;\n /** @internal */\n private idMatrix: IdMatrix;\n /** @internal */\n private addressCaches: Map<Id, Address> = new Map();\n /** @internal */\n private lastChangedAddresses: Address[] = [];\n\n constructor({ limits = {}, name, registry = createRegistry({}) }: Props) {\n this.idMatrix = [];\n this.changedTime = Date.now();\n this._limits = {\n minRows: limits.minRows ?? 1,\n maxRows: limits.maxRows ?? -1,\n minCols: limits.minCols ?? 1,\n maxCols: limits.maxCols ?? -1,\n };\n this.name = name || '';\n this.prevName = this.name;\n this.registry = registry;\n }\n\n static is(obj: any): obj is Sheet {\n return obj?.__gsType === 'Sheet';\n }\n\n toString() {\n return `Sheet(name=${escapeSheetName(this.name)}, size=${this.numRows}x${this.numCols})`;\n }\n\n get headerHeight() {\n return this.getCell({ y: 0, x: 0 }, { resolution: 'SYSTEM' })?.height || HEADER_HEIGHT;\n }\n\n setHeaderHeight(height: number, historicize = true) {\n return this.update({\n diff: { 0: { height } },\n partial: true,\n historicize,\n });\n }\n\n get headerWidth() {\n return this.getCell({ y: 0, x: 0 }, { resolution: 'SYSTEM' })?.width || HEADER_WIDTH;\n }\n\n setHeaderWidth(width: number, historicize = true) {\n return this.update({\n diff: { 0: { width } },\n partial: true,\n historicize,\n });\n }\n\n /**\n * Get the raw (mutable) cell data for a point. Unlike getCell, this returns the actual registry.data reference.\n * @internal\n */\n private _pointToRawCell({ y, x }: PointType): CellType | undefined {\n const id = this.idMatrix[y]?.[x];\n if (id == null) {\n return undefined;\n }\n return this.registry.data[id];\n }\n\n public isRowFiltered(y: number): boolean {\n return !!this._pointToRawCell({ y, x: 0 })?.filtered;\n }\n\n public hasActiveFilters(): boolean {\n const numCols = this.numCols;\n for (let col = 1; col <= numCols; col++) {\n const colCell = this._pointToRawCell({ y: 0, x: col });\n if (colCell?.filter && colCell.filter.conditions.length > 0) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Returns true if any data cell in this sheet currently holds a Pending value\n * (i.e. an async formula that hasn't resolved yet).\n */\n public hasPendingCells(): boolean {\n const numRows = this.numRows;\n const numCols = this.numCols;\n for (let y = 1; y <= numRows; y++) {\n for (let x = 1; x <= numCols; x++) {\n const cell = this.getCell({ y, x }, { resolution: 'RESOLVED' });\n if (Pending.is(cell?.value)) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Returns a Promise that resolves when all in-flight async formula computations\n * have completed and no data cells hold Pending values.\n * If nothing is pending, resolves immediately.\n * Useful for waiting before sort/filter so that cell values are fully resolved.\n */\n public waitForPending(): Promise<void> {\n const pendingMap = this.registry.asyncPending;\n // If there are in-flight promises, wait for them first\n if (pendingMap.size > 0) {\n const promises = Array.from(pendingMap.values()).map((p) => p.promise);\n return Promise.all(promises).then(() => this.waitForPending());\n }\n // Even if asyncPending is empty, cells may still hold Pending values\n // (e.g. propagated pending from dependent formulas).\n // In that case, wait for the next transmit cycle and re-check.\n if (this.hasPendingCells()) {\n return new Promise<void>((resolve) => {\n const check = () => {\n if (this.registry.asyncPending.size > 0) {\n const promises = Array.from(this.registry.asyncPending.values()).map((p) => p.promise);\n Promise.all(promises).then(check);\n } else if (this.hasPendingCells()) {\n // Still pending — wait a tick for transmit/re-render\n setTimeout(check, 50);\n } else {\n resolve();\n }\n };\n check();\n });\n }\n return Promise.resolve();\n }\n\n /**\n * Returns the addresses that were changed in the most recent `_update()` call.\n * Useful inside `onChange` to know which cells were modified.\n */\n public getLastChangedAddresses(): Address[] {\n return this.lastChangedAddresses;\n }\n\n /**\n * Capture the full cell state of all filter-related header cells as a CellsByIdType snapshot.\n * @internal\n */\n private _captureFilterCellStates(): CellsByIdType {\n const snapshot: CellsByIdType = {};\n const numCols = this.numCols;\n const numRows = this.numRows;\n // Column header cells: capture the 'filter' field.\n // Use null instead of undefined so the value survives JSON serialization\n // (undefined is stripped by JSON.stringify, causing undo to silently no-op in environments\n // that serialize/deserialize state such as StackBlitz hot-reload).\n for (let col = 1; col <= numCols; col++) {\n const id = this.idMatrix[0]?.[col];\n if (id != null) {\n snapshot[id] = { filter: this.registry.data[id]?.filter ?? null };\n }\n }\n // Row header cells: capture the 'filtered' field.\n // Use false instead of undefined so the value survives JSON serialization\n // (undefined is stripped by JSON.stringify, causing undo to silently no-op in environments\n // that serialize/deserialize state such as StackBlitz hot-reload).\n for (let y = 1; y <= numRows; y++) {\n const id = this.idMatrix[y]?.[0];\n if (id != null) {\n snapshot[id] = { filtered: this.registry.data[id]?.filtered ?? false };\n }\n }\n return snapshot;\n }\n\n public filterRows({\n x,\n filter,\n }: {\n x?: number;\n filter?: FilterConfig;\n } = {}) {\n const diffBefore = this._captureFilterCellStates();\n\n if (x == null) {\n const numCols = this.numCols;\n for (let col = 1; col <= numCols; col++) {\n const colCell = this._pointToRawCell({ y: 0, x: col });\n delete colCell?.filter;\n }\n } else {\n const colCell = this._pointToRawCell({ y: 0, x });\n if (colCell) {\n if (filter) {\n colCell.filter = filter;\n } else {\n delete colCell.filter;\n }\n }\n }\n this._reapplyFilters();\n\n const diffAfter = this._captureFilterCellStates();\n\n // Only keep cells whose state actually changed\n const changedIds = Object.keys(diffBefore).filter(\n (id) => JSON.stringify(diffBefore[id]) !== JSON.stringify(diffAfter[id]),\n );\n\n if (changedIds.length > 0) {\n const trimmedBefore: CellsByIdType = {};\n const trimmedAfter: CellsByIdType = {};\n for (const id of changedIds) {\n trimmedBefore[id] = diffBefore[id];\n trimmedAfter[id] = diffAfter[id];\n }\n this._pushHistory({\n applyed: true,\n operation: 'UPDATE',\n srcSheetId: this.id,\n dstSheetId: this.id,\n diffBefore: trimmedBefore,\n diffAfter: trimmedAfter,\n partial: true,\n });\n }\n\n return this.refresh(false, true);\n }\n\n /** @internal */\n private _reapplyFilters() {\n // Collect active filters from column header cells\n const numCols = this.numCols;\n const activeFilters: { x: number; filter: FilterConfig }[] = [];\n const changedAddresses: Address[] = [];\n for (let col = 1; col <= numCols; col++) {\n const colCell = this._pointToRawCell({ y: 0, x: col });\n if (colCell?.filter && colCell.filter.conditions.length > 0) {\n activeFilters.push({ x: col, filter: colCell.filter });\n }\n // Track column header cells that have filter config changes\n changedAddresses.push(p2a({ y: 0, x: col }));\n }\n\n const numRows = this.numRows;\n\n // Evaluate each row and update filtered flag\n for (let y = 1; y <= numRows; y++) {\n const rowCell = this._pointToRawCell({ y, x: 0 });\n if (!rowCell) {\n continue;\n }\n\n if (rowCell.filterFixed) {\n continue;\n }\n\n let shouldFilter = false;\n for (const { x: col, filter } of activeFilters) {\n const cell = this.getCell({ y, x: col }, { resolution: 'RESOLVED' });\n if (!evaluateFilterConfig(filter, cell?.value)) {\n shouldFilter = true;\n break;\n }\n }\n\n const wasFiltered = !!rowCell.filtered;\n if (shouldFilter) {\n rowCell.filtered = true;\n } else {\n delete rowCell.filtered;\n }\n if (wasFiltered !== shouldFilter) {\n changedAddresses.push(p2a({ y, x: 0 }));\n }\n }\n\n this.lastChangedAddresses = changedAddresses;\n }\n\n public sortRows({ x, direction }: { x: number; direction: 'asc' | 'desc' }) {\n const numRows = this.numRows;\n if (numRows <= 1) {\n return this;\n }\n\n // Collect row indices (data rows: 1..numRows), separating fixed rows\n const fixedPositions = new Set<number>();\n const sortableIndices: number[] = [];\n for (let y = 1; y <= numRows; y++) {\n const rowCell = this._pointToRawCell({ y, x: 0 });\n if (rowCell?.sortFixed) {\n fixedPositions.add(y);\n } else {\n sortableIndices.push(y);\n }\n }\n\n // Sort by resolved cell value at column x\n sortableIndices.sort((a, b) => {\n const cellA = this.getCell({ y: a, x }, { resolution: 'RESOLVED' });\n const cellB = this.getCell({ y: b, x }, { resolution: 'RESOLVED' });\n const valA = cellA?.value;\n const valB = cellB?.value;\n\n // null/undefined goes to the end\n if (valA == null && valB == null) {\n return 0;\n }\n if (valA == null) {\n return 1;\n }\n if (valB == null) {\n return -1;\n }\n\n let cmp = 0;\n if (typeof valA === 'number' && typeof valB === 'number') {\n cmp = valA - valB;\n } else if (valA instanceof Date && valB instanceof Date) {\n cmp = valA.getTime() - valB.getTime();\n } else {\n cmp = String(valA).localeCompare(String(valB));\n }\n return direction === 'asc' ? cmp : -cmp;\n });\n\n // Check if order actually changed (only among sortable rows)\n // Assign sortable rows to the positions not occupied by fixed rows\n const availablePositions: number[] = [];\n for (let y = 1; y <= numRows; y++) {\n if (!fixedPositions.has(y)) {\n availablePositions.push(y);\n }\n }\n\n let changed = false;\n for (let i = 0; i < sortableIndices.length; i++) {\n if (sortableIndices[i] !== availablePositions[i]) {\n changed = true;\n break;\n }\n }\n if (!changed) {\n return this;\n }\n\n // Build row mapping: original position -> new position\n // Fixed rows map to themselves; sortable rows map to available positions in sorted order\n const sortedRowMapping: { [beforeY: number]: number } = {};\n for (const y of fixedPositions) {\n sortedRowMapping[y] = y;\n }\n for (let i = 0; i < sortableIndices.length; i++) {\n sortedRowMapping[sortableIndices[i]] = availablePositions[i];\n }\n\n // Save row references before rearranging (rows are re-slotted, not mutated).\n const matrixSnapshot = this.idMatrix.slice();\n\n for (const [oldY, newY] of Object.entries(sortedRowMapping)) {\n this.idMatrix[Number(newY)] = matrixSnapshot[Number(oldY)];\n }\n this.addressCaches.clear();\n\n const preserver = new ReferencePreserver(this);\n preserver.buildMap(matrixSnapshot.flat(), this.idMatrix.flat());\n preserver.resolveDependents();\n\n this._pushHistory({\n applyed: true,\n operation: 'SORT_ROWS',\n srcSheetId: this.id,\n dstSheetId: this.id,\n sortedRowMapping,\n } as HistorySortRowsType);\n\n return this.refresh(true, true);\n }\n\n /** @internal */\n private _sortRowMapping(sortedRowMapping: { [beforeY: number]: number }, inverse = false) {\n // Convert mapping to array and apply the sort order\n const numRows = this.numRows;\n const newOrder: number[] = new Array(numRows);\n\n if (inverse) {\n // Undo: reverse the mapping\n // If sortedRowMapping says \"oldY -> newY\", then to undo we put \"newY -> oldY\"\n for (const [oldYStr, newY] of Object.entries(sortedRowMapping)) {\n const oldY = Number(oldYStr);\n newOrder[oldY - 1] = newY;\n }\n } else {\n // Redo: apply the mapping\n // sortedRowMapping[oldY] = newY means row oldY goes to position newY\n for (const [oldYStr, newY] of Object.entries(sortedRowMapping)) {\n const oldY = Number(oldYStr);\n newOrder[newY - 1] = oldY;\n }\n }\n\n // Apply the sort order: newOrder[i] = original row index that should end up at position i+1\n const savedRows: Ids[] = [];\n for (let i = 0; i < newOrder.length; i++) {\n savedRows.push(this.idMatrix[newOrder[i]]);\n }\n for (let i = 0; i < newOrder.length; i++) {\n this.idMatrix[i + 1] = savedRows[i];\n }\n this.addressCaches.clear();\n }\n\n get isInitialized() {\n return this.status === 2;\n }\n\n get policies() {\n return this.registry.policies;\n }\n\n /** @internal */\n public getSystem(point: PointType): System | undefined {\n const id = this.getId(point);\n if (id == null) {\n return undefined;\n }\n return this.registry.systems[id];\n }\n\n /** @internal */\n public processFormula(value: any, { idMap, ...props }: ProcessFormulaProps): any {\n if (typeof value === 'string' || value instanceof String) {\n if (value.charAt(0) === '=') {\n const lexer = new Lexer(value.substring(1));\n lexer.tokenize(idMap);\n lexer.identify({ ...props, sheet: this });\n lexer.dependencyIds.forEach((id) => this.addDependency(id, props.dependency));\n return '=' + lexer.identifiedFormula;\n }\n }\n return value;\n }\n\n /** @internal */\n public resolveFormulas() {\n this.idsToBeIdentified.forEach((id) => {\n const cell = this.registry.data[id];\n if (this.registry.systems[id]?.sheetId == null) {\n return;\n }\n if (cell == null) {\n return;\n }\n this.clearDependencies(id);\n cell.value = this.processFormula(cell?.value, { dependency: id });\n });\n this.idsToBeIdentified = [];\n this.status = 2;\n }\n\n /** @internal */\n public getSheetBySheetName(sheetName: string) {\n const sheetId = this.registry.sheetIdsByName[sheetName];\n return this.getSheetBySheetId(sheetId);\n }\n /** @internal */\n public getSheetBySheetId(sheetId: number) {\n return this.registry.contextsBySheetId[sheetId]?.store?.sheetReactive?.current;\n }\n\n /** @internal */\n private static _stack(...cells: (CellType | undefined)[]) {\n const extension: CellType = {};\n cells.forEach((cell) => {\n if (cell?.style) {\n extension.style = { ...extension.style, ...cell.style };\n }\n if (cell?.prevention) {\n extension.prevention = (extension.prevention || 0) | cell.prevention;\n }\n });\n return extension;\n }\n\n /** @internal */\n public initialize(cells: CellsByAddressType) {\n if (this.status > 1) {\n return;\n }\n if (cells[0] == null) {\n cells[0] = { width: HEADER_WIDTH, height: HEADER_HEIGHT };\n }\n const auto = getMaxSizesFromCells(cells);\n const changedTime = Date.now();\n this.area = {\n top: 1,\n left: 1,\n bottom: auto.numRows,\n right: auto.numCols,\n };\n\n // make idMatrix beforehand\n for (let y = 0; y < auto.numRows + 1; y++) {\n const ids: Ids = [];\n this.idMatrix.push(ids);\n for (let x = 0; x < auto.numCols + 1; x++) {\n const id = this._generateId();\n ids.push(id);\n const address = p2a({ y, x });\n this.addressCaches.set(id, address);\n }\n }\n Object.keys(cells).forEach((address) => {\n if (address === DEFAULT_KEY || address === DEFAULT_COL_KEY || address === DEFAULT_ROW_KEY) {\n return;\n }\n const range = expandRange(address);\n const data = cells[address];\n\n range.forEach((address) => {\n const origin = cells[address];\n cells[address] = {\n ...origin,\n ...data,\n ...Sheet._stack(origin, data),\n };\n });\n });\n\n const common = cells?.[DEFAULT_KEY];\n const commonCol = cells?.[DEFAULT_COL_KEY];\n const commonRow = cells?.[DEFAULT_ROW_KEY];\n if (commonCol?.width != null) {\n this.defaultColWidth = commonCol.width;\n }\n if (commonRow?.height != null) {\n this.defaultRowHeight = commonRow.height;\n }\n for (let y = 0; y < auto.numRows + 1; y++) {\n const rowId = y2r(y);\n for (let x = 0; x < auto.numCols + 1; x++) {\n const id = this.getId({ y, x });\n const colId = x2c(x);\n let stacked: CellType;\n if (y === 0 && x > 0) {\n // Column header: defaultCol as base (width, style, etc.),\n // then 'A' layout props (width, label, no style), then 'A0' overrides.\n const colDefault = cells?.[colId];\n const { style: _cs, ...colDefaultLayout } = colDefault ?? {};\n const headerCell = cells?.[colId + '0'];\n stacked = {\n ...commonCol,\n ...colDefaultLayout,\n ...headerCell,\n ...Sheet._stack(commonCol, headerCell),\n } as CellType;\n } else if (x === 0 && y > 0) {\n // Row header: defaultRow as base (height, style, etc.),\n // then '1' layout props (height, no style), then '01' overrides.\n const rowDefault = cells?.[rowId];\n const { style: _rs, ...rowDefaultLayout } = rowDefault ?? {};\n const headerCell = cells?.['0' + rowId];\n stacked = {\n ...commonRow,\n ...rowDefaultLayout,\n ...headerCell,\n ...Sheet._stack(commonRow, headerCell),\n } as CellType;\n } else if (y === 0 && x === 0) {\n // Corner cell (y=0, x=0): excluded from all defaults to keep headerHeight correct.\n const cell = cells?.['0'];\n stacked = { ...cell, ...Sheet._stack(cell) } as CellType;\n } else {\n // Data cell: 'A' applies to all column-A cells, '1' to all row-1 cells.\n const address = p2a({ y, x });\n const rowDefault = cells?.[rowId];\n const colDefault = cells?.[colId];\n const cell = cells?.[address];\n stacked = {\n ...common,\n ...rowDefault,\n ...colDefault,\n ...cell,\n ...Sheet._stack(common, rowDefault, colDefault, cell),\n } as CellType;\n }\n\n if (stacked?.value?.startsWith?.('=') && (stacked?.formulaEnabled ?? true)) {\n this.idsToBeIdentified.push(id);\n }\n if (y === 0) {\n if (stacked.width == null) {\n stacked.width = DEFAULT_WIDTH;\n }\n } else if (x === 0) {\n if (stacked.height == null) {\n stacked.height = DEFAULT_HEIGHT;\n }\n } else {\n delete stacked.height;\n delete stacked.width;\n delete stacked.label;\n }\n\n const policy = this.policies[stacked.policy ?? ''] ?? this.defaultPolicy;\n stacked = policy.deserializeValue(stacked.value, stacked) ?? {};\n this.registry.systems[id] = { id, changedTime, sheetId: this.id };\n this.registry.data[id] = stacked;\n }\n }\n this.status = 1; // initialized\n this.registry.sheetIdsByName[this.name] = this.id;\n }\n\n /** @internal */\n private _incrementVersion() {\n this.version++;\n if (this.version >= Number.MAX_SAFE_INTEGER) {\n this.version = 1;\n }\n }\n\n /** @internal */\n private _xsheetDispatch(otherSheet: Sheet) {\n if (otherSheet === this) {\n return;\n }\n otherSheet.refresh(true);\n const context = this.registry.contextsBySheetId[otherSheet.id];\n if (context !== null) {\n const { dispatch } = context;\n requestAnimationFrame(() => {\n dispatch(this.registry.updateSheet(otherSheet));\n });\n }\n }\n\n /** @internal */\n private _generateId() {\n return (this.registry.cellHead++).toString();\n }\n\n public getRectSize({ top, left, bottom, right }: AreaType): RectType {\n // Use System.offsetLeft / System.offsetTop stored on header cells for O(1) lookup.\n // offsetLeft on (y=0, x) = absolute left of column x\n // offsetTop on (y, x=0) = absolute top of row y\n const l = left || 1;\n const t = top || 1;\n\n const rw = this.registry.systems[this.getId({ y: 0, x: right })]?.offsetLeft ?? 0;\n const lw = this.registry.systems[this.getId({ y: 0, x: l })]?.offsetLeft ?? 0;\n const rh = this.registry.systems[this.getId({ y: bottom, x: 0 })]?.offsetTop ?? 0;\n const th = this.registry.systems[this.getId({ y: t, x: 0 })]?.offsetTop ?? 0;\n\n const width = Math.max(0, rw - lw);\n const height = Math.max(0, rh - th);\n return { y: t, x: l, height, width };\n }\n\n /** @internal */\n public setTotalSize() {\n const numCols = this.numCols;\n const numRows = this.numRows;\n const headerW = this.headerWidth;\n const headerH = this.headerHeight;\n\n // Write offsetLeft into column-header cells (y=0, x=1..numCols)\n let accW = 0;\n for (let x = 1; x <= numCols; x++) {\n const cell = this.getCell({ y: 0, x }, { resolution: 'SYSTEM' });\n const w = cell?.width || this.defaultColWidth || DEFAULT_WIDTH;\n const colSys = this.registry.systems[this.getId({ y: 0, x })];\n if (colSys != null) {\n colSys.offsetLeft = headerW + accW;\n }\n accW += w;\n }\n this.totalWidth = headerW + accW;\n\n // Write offsetTop into row-header cells (y=1..numRows, x=0)\n let accH = 0;\n let fullH = 0;\n for (let y = 1; y <= numRows; y++) {\n const cell = this.getCell({ y, x: 0 }, { resolution: 'SYSTEM' });\n const h = cell?.height || this.defaultRowHeight || DEFAULT_HEIGHT;\n const rowSys = this.registry.systems[this.getId({ y, x: 0 })];\n if (rowSys != null) {\n rowSys.offsetTop = headerH + accH;\n }\n if (!cell?.filtered) {\n accH += h;\n }\n fullH += h;\n }\n this.totalHeight = headerH + accH;\n this.fullHeight = headerH + fullH;\n }\n\n /** @internal */\n public refresh(relocate = false, resize = false): Sheet {\n this._incrementVersion();\n this.lastChangedTime = this.changedTime;\n this.changedTime = Date.now();\n\n this.clearSolvedCaches();\n\n if (relocate) {\n // force reset\n this.addressCaches.clear();\n }\n if (resize) {\n this.setTotalSize();\n }\n return this;\n }\n\n /** @internal */\n public clone(relocate = false): Sheet {\n const copied: Sheet = Object.assign(Object.create(Object.getPrototypeOf(this)), this);\n return copied.refresh(relocate);\n }\n\n /** @internal */\n public getPointById(\n id: Id,\n slideY = 0,\n slideX = 0,\n ): PointType & {\n absCol: boolean;\n absRow: boolean;\n } {\n const absCol = id.startsWith('$');\n if (absCol) {\n id = id.slice(1);\n slideX = 0;\n }\n const absRow = id.endsWith('$');\n if (absRow) {\n id = id.slice(0, -1);\n slideY = 0;\n }\n const cache = this.addressCaches.get(id);\n if (cache) {\n const p = a2p(cache);\n return { y: p.y + slideY, x: p.x + slideX, absCol, absRow };\n }\n\n for (let y = 0; y < this.idMatrix.length; y++) {\n const ids = this.idMatrix[y];\n for (let x = 0; x < ids.length; x++) {\n const existing = ids[x];\n const address = p2a({ y, x });\n this.addressCaches.set(existing, address);\n if (existing === id) {\n return {\n y: y + slideY,\n x: x + slideX,\n absCol,\n absRow,\n };\n }\n }\n }\n return { y: -1, x: -1, absCol, absRow };\n }\n\n /** @internal */\n public getAddressById(id: Id, slideY = 0, slideX = 0): string | undefined {\n const { y, x, absCol, absRow } = this.getPointById(id, slideY, slideX);\n return grantAddressAbsolute(p2a({ y, x }), absCol, absRow);\n }\n\n /** @internal */\n public clearAddressCaches() {\n this.addressCaches.clear();\n }\n\n /** @internal */\n private _warmAddressCaches() {\n for (let y = 0; y < this.idMatrix.length; y++) {\n const row = this.idMatrix[y];\n for (let x = 0; x < row.length; x++) {\n this.addressCaches.set(row[x], p2a({ y, x }));\n }\n }\n }\n\n /** @internal */\n public getId(point: PointType) {\n const { y, x } = point;\n return this.idMatrix[y]?.[x];\n }\n\n /** @internal */\n public getCell(point: PointType, { resolution = 'RESOLVED', raise = false }: SolveOptions = {}) {\n const { y, x } = point;\n if (y === -1 || x === -1) {\n return undefined;\n }\n const id = this.idMatrix[y]?.[x];\n if (id == null) {\n return undefined;\n }\n const cell = this.registry.data[id];\n if (cell == null) {\n return undefined;\n }\n let value = cell.value;\n if (resolution !== 'SYSTEM' && (cell.formulaEnabled ?? true)) {\n value = solveFormula({ value, sheet: this, point, raise, resolution, at: id });\n }\n return { ...cell, value } as CellType;\n }\n\n /** @internal */\n public get numRows() {\n const { top, bottom } = this.area;\n return 1 + bottom - top;\n }\n\n public get numCols() {\n const { left, right } = this.area;\n return 1 + right - left;\n }\n\n public get top() {\n return this.area.top;\n }\n public get left() {\n return this.area.left;\n }\n public get bottom() {\n return this.area.bottom;\n }\n public get right() {\n return this.area.right;\n }\n\n /** @internal */\n public _toValueMatrix({\n area,\n at,\n resolution = 'RESOLVED',\n raise = false,\n filter = noFilter,\n asScalar = false,\n }: InternalToValueMatrixProps = {}) {\n const { top, left, bottom, right } = area ?? this.area;\n const matrix = createMatrix(bottom - top + 1, right - left + 1);\n\n // Normalize `at` check to ensure we only throw circular ref if the `at` is from this sheet\n for (let y = top; y <= bottom; y++) {\n for (let x = left; x <= right; x++) {\n const id = this.getId({ y, x });\n if (at === id) {\n throw new FormulaError('#REF!', 'References are circulating.');\n }\n const cell = this.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n let fieldValue = cell.value;\n if (asScalar) {\n const policy = this.getPolicy({ y, x });\n fieldValue = policy.toScalar({ value: cell.value, cell, sheet: this, point: { y, x } });\n }\n matrix[y - top][x - left] = fieldValue;\n }\n }\n }\n return matrix;\n }\n\n /** @internal */\n private _pushHistory(history: HistoryType) {\n const book = this.registry;\n const strayedHistories = book.histories.splice(book.historyIndex + 1, book.histories.length);\n strayedHistories.forEach(this._cleanStrayed.bind(this));\n book.histories.push(history);\n book.lastHistory = book.currentHistory = history;\n if (book.histories.length > book.historyLimit) {\n const kickedOut = book.histories.splice(0, 1)[0];\n this._cleanObsolete(kickedOut);\n } else {\n book.historyIndex++;\n }\n }\n\n /** @internal */\n private _cleanObsolete(history: HistoryType) {\n if (history.operation === 'REMOVE_ROWS' || history.operation === 'REMOVE_COLS') {\n history.deleted.forEach((ids) => {\n ids.forEach((id) => {\n this._deleteOrphanedId(id);\n });\n });\n }\n if (history.operation === 'MOVE') {\n history.moveRelations.forEach((rel) => {\n if (rel.new != null) {\n this._deleteOrphanedId(rel.new);\n }\n if (rel.lost != null) {\n this._deleteOrphanedId(rel.lost);\n }\n });\n }\n }\n\n /** @internal */\n private _cleanStrayed(history: HistoryType) {\n /**\n * Cleans up IDs that were created by a history entry that has been discarded\n * (\"strayed\") due to a new operation being pushed while the history index was\n * not at the end (i.e. after undo).\n *\n * When the user undoes one or more steps and then performs a new operation,\n * the previously-redoable future histories are removed from the history stack.\n * Any cells that were **inserted** by those discarded histories (INSERT_ROWS /\n * INSERT_COLS) have IDs that are no longer reachable from the id-matrix, so\n * their registry entries must be deleted to avoid memory leaks.\n * @internal\n */\n if (history.operation === 'INSERT_ROWS' || history.operation === 'INSERT_COLS') {\n history.idMatrix.forEach((ids) => {\n ids.forEach((id) => {\n this._deleteOrphanedId(id);\n });\n });\n }\n }\n\n /**\n * Remove an id from registry.data and registry.dependents entirely.\n * @internal\n */\n private _deleteOrphanedId(id: Id) {\n const sys = this.registry.systems[id];\n sys?.dependencies?.forEach((depId) => {\n this.registry.systems[depId]?.dependents?.delete(id);\n });\n delete this.registry.data[id];\n delete this.registry.systems[id];\n }\n\n /** @internal */\n private _copyCellLayout(cell: CellType | undefined) {\n if (cell == null) {\n return undefined;\n }\n const newCell: CellType = {};\n if (cell.style != null) {\n newCell.style = cell.style;\n }\n if (cell.justifyContent != null) {\n newCell.justifyContent = cell.justifyContent;\n }\n if (cell.alignItems != null) {\n newCell.alignItems = cell.alignItems;\n }\n if (cell.policy != null) {\n newCell.policy = cell.policy;\n }\n if (cell.width != null) {\n newCell.width = cell.width;\n }\n if (cell.height != null) {\n newCell.height = cell.height;\n }\n return newCell;\n }\n\n public move({\n srcSheet = this,\n src,\n dst,\n historicize = true,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: MoveProps) {\n const srcSheetRaw = srcSheet.__raw__;\n const moveRelations = this._createMoveRelations(srcSheetRaw, src, this, dst);\n const { diffBefore, diffAfter } = this._moveCells(srcSheetRaw, this, moveRelations, false, operator);\n\n this._xsheetDispatch(srcSheetRaw);\n\n if (historicize) {\n this._pushHistory({\n applyed: true,\n operation: 'MOVE',\n srcSheetId: srcSheetRaw.id,\n dstSheetId: this.id,\n undoReflection,\n redoReflection,\n diffBefore,\n diffAfter,\n moveRelations,\n });\n }\n\n return this.refresh(true);\n }\n\n /**\n * Build MoveRelations from src area to dst area, skipping filtered rows.\n *\n * Layout of the returned array (processed in this order by _moveCells):\n * 1. Entries where [0] is a newly-generated ID — these fill the vacated src cells (processed last in forward order)\n * 2. Entries where [0] is a src address and [1] is a dst address — the actual moves (processed first in forward order, descending)\n * Entries whose [1] is an existing ID mean the destination cell is displaced/overflowed and\n * is no longer addressable; on forward pass they are skipped; on reverse pass the ID is written back.\n */\n /** @internal */\n private _createMoveRelations(srcSheet: Sheet, src: AreaType, dstSheet: Sheet, dst: AreaType): MoveRelations {\n const { top: srcTop, left: srcLeft, bottom: srcBottom, right: srcRight } = src;\n const { top: dstTop, left: dstLeft } = dst;\n\n const dstNumRows = dstSheet.numRows;\n const dstNumCols = dstSheet.numCols;\n\n // Collect visible (non-filtered) rows for src\n const srcVisibleRows: number[] = [];\n for (let y = srcTop; y <= srcBottom; y++) {\n if (!srcSheet.isRowFiltered(y)) {\n srcVisibleRows.push(y);\n }\n }\n const srcNumCols = srcRight - srcLeft + 1;\n const srcNumVisibleRows = srcVisibleRows.length;\n\n // Collect corresponding visible dst rows (skip filtered rows in dst, matching count)\n const dstVisibleRows: number[] = [];\n {\n let di = 0;\n let y = dstTop;\n while (di < srcNumVisibleRows) {\n if (!dstSheet.isRowFiltered(y)) {\n dstVisibleRows.push(y);\n di++;\n }\n y++;\n }\n }\n\n // Build sets for quick lookup\n const srcCellSet = new Set<string>();\n for (let di = 0; di < srcNumVisibleRows; di++) {\n for (let j = 0; j < srcNumCols; j++) {\n srcCellSet.add(p2a({ y: srcVisibleRows[di], x: srcLeft + j }));\n }\n }\n\n const dstAddrSet = new Set<string>();\n for (let di = 0; di < srcNumVisibleRows; di++) {\n const dstY = dstVisibleRows[di];\n for (let j = 0; j < srcNumCols; j++) {\n const dstX = dstLeft + j;\n if (dstY <= dstNumRows && dstX <= dstNumCols) {\n dstAddrSet.add(p2a({ y: dstY, x: dstX }));\n }\n }\n }\n\n const moveRelations: MoveRelations = [];\n\n for (let di = 0; di < srcNumVisibleRows; di++) {\n const srcY = srcVisibleRows[di];\n const dstY = dstVisibleRows[di];\n for (let j = 0; j < srcNumCols; j++) {\n const srcX = srcLeft + j;\n const dstX = dstLeft + j;\n const srcAddr = p2a({ y: srcY, x: srcX });\n const isDstInBounds = dstY <= dstNumRows && dstX <= dstNumCols;\n const dstAddr = isDstInBounds ? p2a({ y: dstY, x: dstX }) : undefined;\n\n let newId: Id | undefined;\n // Vacate: src cell is NOT covered by any dst write in the same sheet overlap\n if (!(srcSheet === dstSheet && dstAddrSet.has(srcAddr))) {\n newId = srcSheet._generateId();\n }\n\n let lostId: Id | undefined;\n if (isDstInBounds) {\n // Displace: dst cell is overwritten but was NOT part of the src area being moved\n if (!(srcSheet === dstSheet && srcCellSet.has(dstAddr!))) {\n const existingId = dstSheet.getId({ y: dstY, x: dstX });\n if (existingId != null) {\n lostId = existingId;\n }\n }\n } else {\n // Overflow: the src ID itself is pushed out of bounds and lost\n const srcId = srcSheet.getId({ y: srcY, x: srcX });\n if (srcId != null) {\n lostId = srcId;\n }\n }\n\n const srcCell = srcSheet.getCell({ y: srcY, x: srcX }, { resolution: 'SYSTEM' });\n const dstCell = isDstInBounds ? dstSheet.getCell({ y: dstY, x: dstX }, { resolution: 'SYSTEM' }) : undefined;\n\n moveRelations.push({\n before: srcCell?.policy,\n after: dstCell?.policy,\n src: srcAddr,\n dst: dstAddr,\n new: newId,\n lost: lostId,\n });\n }\n }\n\n return moveRelations;\n }\n\n get defaultPolicy(): PolicyType {\n return this.policies[DEFAULT_POLICY_NAME] ?? nonePolicy;\n }\n\n /**\n * Apply (or reverse) a MoveRelations list.\n *\n * Forward (reverse=false): process descending — actual ID moves happen bottom-up so\n * earlier entries don't clobber later ones; vacate entries (at front of array) are\n * applied last.\n * Reverse (reverse=true): process ascending — restores IDs in the natural order.\n *\n * On forward pass: applies policy, collects diffBefore, runs ReferencePreserver.\n * On reverse pass: only moves IDs (caller is responsible for applyDiff(diffBefore)).\n */\n /** @internal */\n private _moveCells(\n srcSheet: Sheet,\n dstSheet: Sheet,\n moveRelations: MoveRelations,\n reverse: boolean,\n operator: OperatorType = 'SYSTEM',\n ): { diffBefore: CellsByIdType; diffAfter: CellsByIdType } {\n const diffBefore: CellsByIdType = {};\n const preserver = new ReferencePreserver(dstSheet);\n\n const wireWrites: CellsByIdType = {};\n const idWritesSrc: Array<{ y: Y; x: X; id: Id }> = [];\n const idWritesDst: Array<{ y: Y; x: X; id: Id }> = [];\n\n // Forward pass: collect diffs and temporary buffer writes\n if (!reverse) {\n for (const {\n before: beforePolicy,\n after: afterPolicy,\n src: srcAddr,\n dst: dstAddr,\n new: newId,\n lost: lostId,\n } of moveRelations) {\n const srcPoint = a2p(srcAddr);\n const srcId = srcSheet.getId(srcPoint);\n const dstPoint = dstAddr != null ? a2p(dstAddr) : undefined;\n const dstId = dstPoint != null ? dstSheet.getId(dstPoint) : undefined;\n\n const srcCell = srcId != null ? srcSheet.registry.data[srcId] : undefined;\n const dstCell = dstId != null ? dstSheet.registry.data[dstId] : undefined;\n\n if (\n operator === 'USER' &&\n (operation.hasOperation(srcCell?.prevention, operation.MoveFrom) ||\n operation.hasOperation(dstCell?.prevention, operation.MoveTo))\n ) {\n continue;\n }\n\n // Vacate\n if (newId != null) {\n const policyKey = beforePolicy || DEFAULT_POLICY_NAME;\n const policy = srcSheet.policies[policyKey] ?? srcSheet.defaultPolicy;\n const restricted = policy.select({\n sheet: srcSheet,\n point: srcPoint,\n next: { value: null },\n current: srcCell,\n operation: operation.MoveFrom,\n });\n\n wireWrites[newId] = {\n ...restricted,\n policy: beforePolicy,\n };\n this.registry.systems[newId] = { id: newId, sheetId: srcSheet.id, changedTime: Date.now() };\n idWritesSrc.push({ y: srcPoint.y, x: srcPoint.x, id: newId });\n }\n\n // Actual Move\n if (dstId != null && dstPoint != null && dstAddr != null) {\n const dstPolicyKey = afterPolicy || DEFAULT_POLICY_NAME;\n const srcPolicyKey = beforePolicy || DEFAULT_POLICY_NAME;\n const dstPolicyVal = dstSheet.policies[dstPolicyKey] ?? dstSheet.defaultPolicy;\n const srcPolicyVal = srcSheet.policies[srcPolicyKey] ?? srcSheet.defaultPolicy;\n const isSrcWinner = srcPolicyVal.priority > dstPolicyVal.priority;\n const policy = isSrcWinner ? srcPolicyVal : dstPolicyVal;\n\n const restricted = policy.select({\n sheet: dstSheet,\n point: dstPoint,\n next: srcCell,\n current: dstCell,\n operation: operation.MoveTo,\n });\n\n if (restricted) {\n diffBefore[srcId] = srcCell ?? {};\n wireWrites[srcId] = {\n ...srcCell,\n ...restricted,\n policy: isSrcWinner ? beforePolicy : afterPolicy,\n };\n }\n if (srcCell != null) {\n const srcSys = this.registry.systems[srcId];\n if (srcSys) {\n srcSys.changedTime = Date.now();\n }\n }\n\n idWritesDst.push({ y: dstPoint.y, x: dstPoint.x, id: srcId });\n }\n }\n } else {\n // Reverse pass: collect id buffer writes (no registry.data modification)\n for (const {\n before: beforePolicy,\n after: afterPolicy,\n src: srcAddr,\n dst: dstAddr,\n new: newId,\n lost: lostId,\n } of moveRelations) {\n // Move ID that landed at dst back to src\n if (dstAddr != null) {\n const toPoint = a2p(dstAddr);\n const movedId = dstSheet.getId(toPoint);\n if (movedId != null) {\n const fromPoint = a2p(srcAddr);\n idWritesSrc.push({ y: fromPoint.y, x: fromPoint.x, id: movedId });\n }\n }\n\n // Restore lost ID to where it was lost from\n if (lostId != null) {\n if (dstAddr != null) {\n // It was displaced from dst\n const toPoint = a2p(dstAddr);\n idWritesDst.push({ y: toPoint.y, x: toPoint.x, id: lostId });\n } else {\n // It overflowed from src\n const fromPoint = a2p(srcAddr);\n idWritesSrc.push({ y: fromPoint.y, x: fromPoint.x, id: lostId });\n }\n }\n }\n }\n\n // Snapshot idMatrix before flush\n const srcSnapshot = !reverse ? srcSheet.idMatrix.flat() : null;\n const dstSnapshot = !reverse && srcSheet !== dstSheet ? dstSheet.idMatrix.flat() : null;\n\n // Flush registry.data writes first\n Object.assign(this.registry.data, wireWrites);\n // Then flush idMatrix writes\n for (const { y, x, id } of idWritesSrc) {\n srcSheet.idMatrix[y][x] = id;\n }\n for (const { y, x, id } of idWritesDst) {\n dstSheet.idMatrix[y][x] = id;\n }\n\n // Update lastChangedAddresses\n const changedAddresses: Address[] = moveRelations.filter((r) => r.dst != null).map((r) => r.dst as Address);\n const srcAddresses: Address[] = moveRelations.map((r) => r.src);\n\n if (srcSheet === dstSheet) {\n dstSheet.lastChangedAddresses = [...new Set([...srcAddresses, ...changedAddresses])];\n } else {\n dstSheet.lastChangedAddresses = changedAddresses;\n srcSheet.lastChangedAddresses = srcAddresses;\n }\n\n if (!reverse) {\n preserver.buildMap(srcSnapshot!.flat(), srcSheet.idMatrix.flat());\n if (srcSheet !== dstSheet) {\n preserver.buildMap(dstSnapshot!.flat(), dstSheet.idMatrix.flat());\n }\n const resolvedDiff = preserver.resolveDependents('move');\n Object.assign(diffBefore, resolvedDiff);\n }\n\n return { diffBefore, diffAfter: {} };\n }\n\n public copy({\n srcSheet = this,\n src,\n dst,\n onlyValue = false,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: MoveProps & { onlyValue?: boolean }) {\n const isXSheet = srcSheet !== this;\n const { top: topFrom, left: leftFrom, bottom: bottomFrom, right: rightFrom } = src;\n const { top: topTo, left: leftTo, bottom: bottomTo, right: rightTo } = dst;\n const diff: CellsByAddressType = {};\n const changedTime = Date.now();\n\n // Build list of visible (non-filtered) rows for src and dst\n const srcVisibleRows: number[] = [];\n for (let y = topFrom; y <= bottomFrom; y++) {\n if (!srcSheet.isRowFiltered(y)) {\n srcVisibleRows.push(y);\n }\n }\n const dstVisibleRows: number[] = [];\n for (let y = topTo; y <= bottomTo; y++) {\n if (y > this.numRows) {\n continue;\n }\n if (!this.isRowFiltered(y)) {\n dstVisibleRows.push(y);\n }\n }\n\n const srcNumVisibleRows = srcVisibleRows.length;\n const srcNumCols = rightFrom - leftFrom + 1;\n const dstNumCols = rightTo - leftTo + 1;\n\n for (let di = 0; di < dstVisibleRows.length; di++) {\n const toY = dstVisibleRows[di];\n const fromY = srcVisibleRows[di % srcNumVisibleRows];\n for (let j = 0; j <= dstNumCols - 1; j++) {\n const toX = leftTo + j;\n if (toX > this.numCols) {\n continue;\n }\n const fromX = leftFrom + (j % srcNumCols);\n const slideY = isXSheet ? 0 : toY - fromY;\n const slideX = isXSheet ? 0 : toX - fromX;\n const cell: CellType = {\n ...srcSheet.getCell({ y: fromY, x: fromX }, { resolution: 'SYSTEM' }),\n };\n const dstPoint = { y: toY, x: toX };\n const dstCell = this.getCell(dstPoint, { resolution: 'SYSTEM' });\n const dstPolicy = this.getPolicy(dstPoint);\n const srcPoint = { y: fromY, x: fromX };\n const srcPolicy = srcSheet.getPolicy(srcPoint);\n const srcCell = srcSheet.getCell(srcPoint, { resolution: 'SYSTEM' });\n\n const isSrcWinner = srcPolicy.priority > dstPolicy.priority;\n cell.policy = isSrcWinner ? srcCell?.policy : dstCell?.policy;\n const dstIdForClear = this.getId(dstPoint);\n this.clearDependencies(dstIdForClear);\n const value =\n (cell?.formulaEnabled ?? true)\n ? this.processFormula(cell?.value, {\n dependency: dstIdForClear,\n slideY,\n slideX,\n })\n : cell?.value;\n const dstId = this.getId(dstPoint);\n const dstSys = this.registry.systems[dstId];\n if (dstSys != null) {\n dstSys.changedTime = changedTime;\n }\n const address = p2a(dstPoint);\n if (onlyValue) {\n const dstCell = this.getCell(dstPoint, { resolution: 'SYSTEM' });\n cell.style = dstCell?.style;\n cell.justifyContent = dstCell?.justifyContent;\n cell.alignItems = dstCell?.alignItems;\n }\n diff[address] = { ...cell, value };\n }\n }\n return this.update({\n diff,\n partial: false,\n operator,\n operation: operation.Copy,\n undoReflection,\n redoReflection,\n });\n }\n\n public getPolicy(point: PointType): PolicyType {\n const cell = this.getCell(point, { resolution: 'SYSTEM' });\n if (cell?.policy == null) {\n return this.defaultPolicy;\n }\n return this.policies[cell.policy] ?? this.defaultPolicy;\n }\n\n /** @internal */\n private _update({\n diff,\n partial = true,\n updateChangedTime = true,\n ignoreFields = ['label'],\n operator = 'SYSTEM',\n operation: op = operation.Update,\n formulaIdentify = true,\n }: {\n diff: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n ignoreFields?: CellField[];\n operator?: OperatorType;\n operation?: OperationType;\n formulaIdentify?: boolean;\n }) {\n const diffBefore: CellsByIdType = {};\n const diffAfter: CellsByIdType = {};\n const changedAddresses: Address[] = [];\n const changedTime = Date.now();\n\n let resized = false;\n Object.keys(diff).forEach((address) => {\n const point = a2p(address);\n const id = this.getId(point);\n const current = this.registry.data[id];\n if (operator === 'USER' && operation.hasOperation(current?.prevention, operation.Update)) {\n return;\n }\n\n let next: Record<string, any> = { ...diff[address] };\n\n if (formulaIdentify) {\n const formulaEnabled = next.formulaEnabled ?? current?.formulaEnabled ?? true;\n if (formulaEnabled) {\n this.clearDependencies(id);\n next.value = this.processFormula(next.value, { dependency: id });\n }\n }\n ignoreFields.forEach((key) => {\n next[key] = current?.[key];\n });\n if (operator === 'USER' && operation.hasOperation(current?.prevention, operation.Write)) {\n delete next.value;\n }\n if (operator === 'USER' && operation.hasOperation(current?.prevention, operation.Style)) {\n delete next?.style?.justifyContent;\n delete next?.style?.alignItems;\n }\n if (operator === 'USER' && operation.hasOperation(current?.prevention, operation.Resize)) {\n delete next?.style?.width;\n delete next?.style?.height;\n }\n if (next.width != null || next.height != null) {\n resized = true;\n }\n diffBefore[id] = current ?? {};\n\n const policy = this.policies[current?.policy || DEFAULT_POLICY_NAME] ?? this.defaultPolicy;\n const p = policy.select({\n sheet: this,\n point,\n next,\n current,\n operation: op,\n });\n next = { ...p };\n if (updateChangedTime) {\n const sys = this.registry.systems[id];\n if (sys != null) {\n sys.changedTime = changedTime;\n }\n }\n if (partial) {\n const merged = { ...current, ...next };\n this.registry.data[id] = merged;\n diffAfter[id] = merged;\n } else {\n this.registry.data[id] = next;\n diffAfter[id] = next;\n }\n changedAddresses.push(address);\n });\n\n // Store the changed addresses for retrieval via getLastChangedAddresses()\n this.lastChangedAddresses = changedAddresses;\n\n //this.clearSolvedCaches();\n return {\n diffBefore,\n diffAfter,\n resized,\n };\n }\n\n public update({\n diff,\n partial = true,\n updateChangedTime = true,\n historicize = true,\n operator = 'SYSTEM',\n operation: op = operation.Update,\n ignoreFields,\n undoReflection,\n redoReflection,\n }: {\n diff: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n historicize?: boolean;\n operator?: OperatorType;\n operation?: OperationType;\n ignoreFields?: CellField[];\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n const { diffBefore, diffAfter, resized } = this._update({\n diff,\n partial,\n operator,\n operation: op,\n updateChangedTime,\n ...(ignoreFields != null ? { ignoreFields } : {}),\n });\n\n if (historicize) {\n this._pushHistory({\n applyed: true,\n operation: 'UPDATE',\n srcSheetId: this.id,\n dstSheetId: this.id,\n undoReflection,\n redoReflection,\n diffBefore,\n diffAfter,\n partial,\n });\n }\n return this.refresh(false, resized);\n }\n\n /** @internal */\n public writeRawCellMatrix({\n point,\n matrix,\n updateChangedTime = true,\n historicize = true,\n onlyValue = false,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: {\n point: PointType;\n matrix: MatrixType<RawCellType>;\n updateChangedTime?: boolean;\n historicize?: boolean;\n onlyValue?: boolean;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n const { y: baseY, x: baseX } = point;\n const diff: CellsByAddressType = {};\n\n // Build list of visible (non-filtered) rows starting from baseY\n // Map src row index (i) -> dst y, skipping filtered rows\n let srcRowIndex = 0;\n let dstY = baseY;\n while (srcRowIndex < matrix.length) {\n if (dstY > this.bottom) {\n break;\n }\n if (this.isRowFiltered(dstY)) {\n dstY++;\n continue;\n }\n const cells = matrix[srcRowIndex];\n cells.forEach((newCell, j) => {\n const x = baseX + j;\n if (x > this.right) {\n return;\n }\n const dstPoint = { y: dstY, x };\n const parsed = this.parse(dstPoint, newCell.value ?? '');\n parsed.style = { ...newCell.style, ...parsed.style };\n if (onlyValue) {\n const currentCell = this.getCell(dstPoint, { resolution: 'SYSTEM' });\n parsed.style = currentCell?.style;\n parsed.justifyContent = currentCell?.justifyContent;\n parsed.alignItems = currentCell?.alignItems;\n }\n diff[p2a(dstPoint)] = parsed;\n });\n srcRowIndex++;\n dstY++;\n }\n return this.update({\n diff,\n partial: true,\n updateChangedTime,\n historicize,\n operator,\n operation: operation.Write,\n undoReflection,\n redoReflection,\n });\n }\n\n public writeMatrix(props: {\n point: PointType;\n matrix: MatrixType<string>;\n updateChangedTime?: boolean;\n historicize?: boolean;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n const matrixWithStyle: MatrixType<RawCellType> = props.matrix.map((row) => row.map((value) => ({ value })));\n return this.writeRawCellMatrix({ ...props, matrix: matrixWithStyle });\n }\n\n public write(props: {\n point: PointType;\n value: string;\n updateChangedTime?: boolean;\n historicize?: boolean;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n const { point, value } = props;\n const parsed = this.parse(point, value ?? '');\n const current = this.getCell(point, { resolution: 'RAW' });\n if ((current?.value ?? null) === parsed.value) {\n // no change (treat undefined and null as equivalent empty values)\n return this;\n }\n const diff = { [p2a(point)]: parsed };\n return this.update({\n ...props,\n diff,\n partial: true,\n operation: operation.Write,\n });\n }\n\n public insertRows({\n y,\n numRows,\n baseY,\n diff,\n partial,\n updateChangedTime,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: {\n y: number;\n numRows: number;\n baseY: number;\n diff?: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n if (this.maxNumRows !== -1 && this.numRows + numRows > this.maxNumRows) {\n console.error(`Rows are limited to ${this.maxNumRows}.`);\n return this;\n }\n const numCols = this.numCols;\n const rows: IdMatrix = [];\n const changedTime = Date.now();\n for (let i = 0; i < numRows; i++) {\n const row: Ids = [];\n for (let j = 0; j <= numCols; j++) {\n const id = this._generateId();\n row.push(id);\n const cell = this.getCell({ y: baseY, x: j }, { resolution: 'SYSTEM' });\n const copied = this._copyCellLayout(cell);\n this.registry.data[id] = { ...copied };\n this.registry.systems[id] = { id, sheetId: this.id, changedTime };\n }\n rows.push(row);\n }\n this.idMatrix.splice(y, 0, ...rows);\n this.area.bottom += numRows;\n\n this._pushHistory({\n applyed: true,\n operation: 'INSERT_ROWS',\n srcSheetId: this.id,\n dstSheetId: this.id,\n undoReflection,\n redoReflection,\n y,\n numRows,\n idMatrix: rows,\n });\n\n // If diff is provided, update the cells after insertion\n if (diff) {\n Object.assign(this.registry.lastHistory!, this._update({ diff, partial, updateChangedTime, operator }), {\n partial,\n });\n }\n if (this.registry.onInsertRows) {\n const cloned = this.clone();\n cloned.area = {\n top: y,\n bottom: y + numRows - 1,\n left: this.area.left,\n right: this.area.right,\n };\n cloned.addressCaches = new Map();\n this.registry.onInsertRows({ sheet: cloned, y, numRows });\n }\n return this.refresh(true, true);\n }\n public removeRows({\n y,\n numRows,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: {\n y: number;\n numRows: number;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n if (this.minNumRows !== -1 && this.numRows - numRows < this.minNumRows) {\n console.error(`At least ${this.minNumRows} row(s) are required.`);\n return this;\n }\n\n const preserver = new ReferencePreserver(this);\n const ys: number[] = [];\n const backup = this.idMatrix.map((ids) => [...ids]); // backup before deletion\n\n for (let yi = y; yi < y + numRows; yi++) {\n const cell = this.getCell({ y: yi, x: 0 }, { resolution: 'SYSTEM' });\n if (operator === 'USER' && operation.hasOperation(cell?.prevention, operation.RemoveRows)) {\n console.warn(`Cannot delete row ${yi}.`);\n return this;\n }\n for (let xi = 1; xi <= this.numCols; xi++) {\n const id = this.getId({ y: yi, x: xi });\n if (id == null) {\n continue;\n }\n preserver.collectDependents(id);\n preserver.map[id] = this.getId({ y: yi + numRows, x: xi });\n }\n ys.unshift(yi);\n }\n const deleted: MatrixType = [];\n ys.forEach((y) => {\n const row = this.idMatrix.splice(y, 1);\n deleted.unshift(row[0]);\n });\n this.area.bottom -= ys.length;\n\n const diffBefore = preserver.resolveDependents('removeRows');\n\n this._pushHistory({\n applyed: true,\n operation: 'REMOVE_ROWS',\n srcSheetId: this.id,\n dstSheetId: this.id,\n undoReflection,\n redoReflection,\n ys: ys.reverse(),\n diffBefore,\n deleted,\n });\n\n if (this.registry.onRemoveRows) {\n const cloned = this.clone();\n cloned.idMatrix = backup;\n cloned.area = {\n top: y,\n bottom: y + numRows - 1,\n left: this.area.left,\n right: this.area.right,\n };\n cloned.addressCaches = new Map();\n this.registry.onRemoveRows({ sheet: cloned, ys: ys.reverse() });\n }\n return this.refresh(true, true);\n }\n\n public insertCols({\n x,\n numCols,\n baseX,\n diff,\n partial,\n updateChangedTime,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: {\n x: number;\n numCols: number;\n baseX: number;\n diff?: CellsByAddressType;\n partial?: boolean;\n updateChangedTime?: boolean;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n if (this.maxNumCols !== -1 && this.numCols + numCols > this.maxNumCols) {\n console.error(`Columns are limited to ${this.maxNumCols}.`);\n return this;\n }\n const numRows = this.numRows;\n const rows: IdMatrix = [];\n const changedTime = Date.now();\n for (let i = 0; i <= numRows; i++) {\n const row: Ids = [];\n for (let j = 0; j < numCols; j++) {\n const id = this._generateId();\n row.push(id);\n const cell = this.getCell({ y: i, x: baseX }, { resolution: 'SYSTEM' });\n const copied = this._copyCellLayout(cell);\n this.idMatrix[i].splice(x, 0, id);\n this.registry.data[id] = { ...copied };\n this.registry.systems[id] = { id, sheetId: this.id, changedTime };\n }\n rows.push(row);\n }\n this.area.right += numCols;\n\n this._pushHistory({\n applyed: true,\n operation: 'INSERT_COLS',\n srcSheetId: this.id,\n dstSheetId: this.id,\n undoReflection: undoReflection,\n redoReflection: redoReflection,\n x,\n numCols,\n idMatrix: rows,\n });\n\n // If diff is provided, update the cells after insertion\n if (diff) {\n Object.assign(this.registry.lastHistory!, this._update({ diff, partial, updateChangedTime, operator }), {\n partial,\n });\n }\n if (this.registry.onInsertCols) {\n const cloned = this.clone();\n cloned.area = {\n top: this.area.top,\n bottom: this.area.bottom,\n left: x,\n right: x + numCols - 1,\n };\n cloned.addressCaches = new Map();\n this.registry.onInsertCols({ sheet: cloned, x, numCols });\n }\n return this.refresh(true, true);\n }\n public removeCols({\n x,\n numCols,\n operator = 'SYSTEM',\n undoReflection,\n redoReflection,\n }: {\n x: number;\n numCols: number;\n operator?: OperatorType;\n undoReflection?: StorePatchType;\n redoReflection?: StorePatchType;\n }) {\n if (this.minNumCols !== -1 && this.numCols - numCols < this.minNumCols) {\n console.error(`At least ${this.minNumCols} column(s) are required.`);\n return this;\n }\n\n const preserver = new ReferencePreserver(this);\n const xs: number[] = [];\n const backup = this.idMatrix.map((ids) => [...ids]); // backup before deletion\n\n for (let xi = x; xi < x + numCols; xi++) {\n const cell = this.getCell({ y: 0, x: xi }, { resolution: 'SYSTEM' });\n if (operator === 'USER' && operation.hasOperation(cell?.prevention, operation.RemoveCols)) {\n console.warn(`Cannot delete col ${xi}.`);\n continue;\n }\n for (let yi = 1; yi <= this.numRows; yi++) {\n const id = this.getId({ y: yi, x: xi });\n if (id == null) {\n continue;\n }\n preserver.collectDependents(id);\n preserver.map[id] = this.getId({ y: yi, x: xi + numCols });\n }\n xs.unshift(xi);\n }\n\n const deleted: MatrixType = [];\n this.idMatrix.forEach((row) => {\n const deleting: Ids = [];\n deleted.push(deleting);\n // reverse and delete\n xs.forEach((x) => {\n deleting.unshift(...row.splice(x, 1));\n });\n });\n this.area.right -= xs.length;\n const diffBefore = preserver.resolveDependents('removeCols');\n\n this._pushHistory({\n applyed: true,\n operation: 'REMOVE_COLS',\n srcSheetId: this.id,\n dstSheetId: this.id,\n undoReflection: undoReflection,\n redoReflection: redoReflection,\n xs: xs.reverse(),\n diffBefore,\n deleted,\n });\n\n if (this.registry.onRemoveCols) {\n const cloned = this.clone();\n cloned.idMatrix = backup;\n cloned.area = {\n top: this.area.top,\n bottom: this.area.bottom,\n left: x,\n right: x + numCols - 1,\n };\n cloned.addressCaches = new Map();\n this.registry.onRemoveCols({ sheet: cloned, xs: xs.reverse() });\n }\n return this.refresh(true, true);\n }\n /** @internal */\n public histories() {\n return [...this.registry.histories];\n }\n /** @internal */\n public historyIndex() {\n return this.registry.historyIndex;\n }\n /** @internal */\n public historySize() {\n return this.registry.histories.length;\n }\n /** @internal */\n public getHistoryLimit() {\n return this.registry.historyLimit;\n }\n\n /** @internal */\n public parse(point: PointType, value: any): CellType {\n const cell = this.getCell(point, { resolution: 'SYSTEM' }) ?? {};\n const policy = this.getPolicy(point);\n return policy.deserializeValue(value, cell);\n }\n\n /** @internal */\n public render(props: RenderProps) {\n const { point, apply } = props;\n const at = this.getId(point);\n const policy = this.getPolicy(point);\n return policy.render({ sheet: this, point, apply, value: undefined });\n }\n\n public getSerializedValue({\n point,\n cell,\n resolution = 'RESOLVED',\n }: {\n point: PointType;\n cell?: CellType;\n resolution?: Resolution;\n }) {\n if (cell == null) {\n // Use raw cell from registry so cell.value is the original formula string.\n // getCell(raise=false) would replace cell.value with undefined, losing the formula.\n const id = this.idMatrix[point.y]?.[point.x];\n cell = id != null ? this.registry.data[id] : undefined;\n }\n if (cell == null) {\n return '';\n }\n const policy = this.getPolicy(point);\n const raw = cell.value;\n\n if (typeof raw === 'string' && raw[0] === '=') {\n if (resolution === 'SYSTEM') {\n return raw; // do not evaluate system references\n }\n if (resolution === 'RAW') {\n const lexer = new Lexer(raw.substring(1));\n lexer.tokenize();\n return '=' + lexer.display({ sheet: this });\n }\n try {\n const id = this.idMatrix[point.y]?.[point.x];\n const solved = solveFormula({ value: raw, sheet: this, point, raise: true, resolution, at: id });\n const value = stripSheet({ value: solved, raise: false });\n return policy.serialize({ value, cell, sheet: this, point });\n } catch (e) {\n return policy.serialize({ value: e, cell, sheet: this, point });\n }\n }\n return policy.serialize({ value: raw, cell, sheet: this, point });\n }\n\n /** @internal */\n public trim(area: AreaType): Sheet {\n const copied: Sheet = Object.assign(Object.create(Object.getPrototypeOf(this)), this);\n copied.area = area;\n // this causes RangeError on circular reference(maximum call stack size exceeded)\n // copied.solvedCaches = {};\n return copied;\n }\n\n /**\n * Solve all formulas in this sheet and return a 2D matrix of resolved values.\n * @internal\n */\n public solve({ raise = false, at }: { raise?: boolean; at: Id }): any[][] {\n return solveSheet({ sheet: this, raise, at });\n }\n\n /**\n * Collapse this sheet to a scalar (top-left cell value).\n * @internal\n */\n public strip({ raise = false, at }: { raise?: boolean; at?: Id }): any {\n return stripSheet({ value: this, raise, at });\n }\n\n /** @internal */\n private _applyDiff(diff: CellsByIdType = {}, partial = true) {\n const ids = Object.keys(diff);\n ids.forEach((id) => {\n const cell = diff[id] ?? {};\n let merged: CellType;\n if (partial) {\n merged = { ...this.registry.data[id] };\n (Object.keys(cell) as (keyof CellType)[]).forEach((key) => {\n if (cell[key] === undefined) {\n delete merged[key];\n } else {\n (merged as any)[key] = cell[key];\n }\n });\n } else {\n merged = { ...cell };\n }\n const sys = this.registry.systems[id];\n if (sys != null) {\n sys.changedTime = Date.now();\n }\n this.registry.data[id] = merged;\n this.clearDependencies(id);\n this.processFormula(merged.value, { dependency: id });\n });\n this._warmAddressCaches();\n const addresses: Address[] = [];\n for (const id of ids) {\n const address = this.getAddressById(id);\n if (address) {\n addresses.push(address);\n }\n }\n this.lastChangedAddresses = addresses;\n }\n\n public undo() {\n if (this.registry.historyIndex < 0) {\n return { history: null, newSheet: this.__raw__ };\n }\n const history = this.registry.histories[this.registry.historyIndex--];\n history.applyed = false;\n this.registry.currentHistory = this.registry.histories[this.registry.historyIndex];\n\n const srcSheet = this.getSheetBySheetId(history.srcSheetId);\n const dstSheet = this.getSheetBySheetId(history.dstSheetId);\n\n if (!dstSheet) {\n return { history: null, newSheet: this.__raw__ };\n }\n\n switch (history.operation) {\n case 'UPDATE':\n dstSheet._applyDiff(history.diffBefore, history.partial ?? false);\n break;\n case 'INSERT_ROWS': {\n if (history.diffBefore) {\n dstSheet._applyDiff(history.diffBefore, false);\n }\n const { rows } = matrixShape({ matrix: history.idMatrix });\n dstSheet.idMatrix.splice(history.y, rows);\n dstSheet.area.bottom -= rows;\n break;\n }\n case 'INSERT_COLS': {\n if (history.diffBefore) {\n dstSheet._applyDiff(history.diffBefore, false);\n }\n const { cols } = matrixShape({ matrix: history.idMatrix });\n dstSheet.idMatrix.forEach((row: string[]) => {\n row.splice(history.x, cols);\n });\n dstSheet.area.right -= cols;\n break;\n }\n case 'REMOVE_ROWS': {\n const { ys, deleted } = history;\n ys.forEach((y, i) => {\n dstSheet.idMatrix.splice(y, 0, deleted[i]);\n });\n dstSheet.area.bottom += ys.length;\n this._applyDiff(history.diffBefore, false);\n break;\n }\n case 'REMOVE_COLS': {\n const { xs, deleted } = history;\n dstSheet.idMatrix.forEach((row: string[], i: number) => {\n for (let j = 0; j < xs.length; j++) {\n row.splice(xs[j], 0, deleted[i][j]);\n }\n });\n dstSheet.area.right += xs.length;\n this._applyDiff(history.diffBefore, false);\n break;\n }\n case 'MOVE': {\n if (srcSheet) {\n this._moveCells(srcSheet, dstSheet, history.moveRelations, true);\n }\n const movedAddresses = dstSheet.lastChangedAddresses;\n dstSheet._applyDiff(history.diffBefore, false);\n dstSheet.lastChangedAddresses = [...new Set([...movedAddresses, ...dstSheet.lastChangedAddresses])];\n break;\n }\n case 'SORT_ROWS': {\n const snapshotIds = dstSheet.idMatrix.flat();\n dstSheet._sortRowMapping(history.sortedRowMapping, true);\n const preserver = new ReferencePreserver(dstSheet);\n preserver.buildMap(snapshotIds, dstSheet.idMatrix.flat());\n preserver.resolveDependents();\n dstSheet._reapplyFilters();\n break;\n }\n }\n this.refresh(shouldTracking(history.operation), true);\n if (dstSheet !== this) {\n dstSheet.addressCaches.clear();\n dstSheet.setTotalSize();\n }\n if (history.operation === 'MOVE' && srcSheet && srcSheet !== dstSheet) {\n this._xsheetDispatch(srcSheet);\n }\n return {\n history,\n callback: ({ sheetReactive: sheetRef }: { sheetReactive: RefLike<Sheet> }) => {\n sheetRef.current?.registry.transmit(history.undoReflection?.transmit);\n },\n };\n }\n\n public redo() {\n if (this.registry.historyIndex + 1 >= this.registry.histories.length) {\n return { history: null, newSheet: this.__raw__ };\n }\n const history = this.registry.histories[++this.registry.historyIndex];\n history.applyed = true;\n this.registry.currentHistory = history;\n\n const srcSheet = this.getSheetBySheetId(history.srcSheetId);\n const dstSheet = this.getSheetBySheetId(history.dstSheetId);\n\n if (!dstSheet) {\n return { history: null, newSheet: this.__raw__ };\n }\n\n switch (history.operation) {\n case 'UPDATE':\n dstSheet._applyDiff(history.diffAfter, history.partial ?? false);\n break;\n case 'INSERT_ROWS': {\n if (history.diffAfter) {\n dstSheet._applyDiff(history.diffAfter, false);\n }\n const { rows } = matrixShape({ matrix: history.idMatrix });\n dstSheet.idMatrix.splice(history.y, 0, ...history.idMatrix);\n dstSheet.area.bottom += rows;\n break;\n }\n case 'INSERT_COLS': {\n if (history.diffAfter) {\n dstSheet._applyDiff(history.diffAfter, false);\n }\n const { cols } = matrixShape({ matrix: history.idMatrix });\n dstSheet.idMatrix.map((row: string[], i: number) => {\n row.splice(history.x, 0, ...history.idMatrix[i]);\n });\n dstSheet.area.right += cols;\n break;\n }\n case 'REMOVE_ROWS': {\n dstSheet.removeRows({\n y: history.ys[0],\n numRows: history.ys.length,\n operator: 'SYSTEM',\n undoReflection: history.undoReflection,\n redoReflection: history.redoReflection,\n });\n break;\n }\n case 'REMOVE_COLS': {\n dstSheet.removeCols({\n x: history.xs[0],\n numCols: history.xs.length,\n operator: 'SYSTEM',\n undoReflection: history.undoReflection,\n redoReflection: history.redoReflection,\n });\n break;\n }\n case 'MOVE': {\n if (srcSheet) {\n this._moveCells(srcSheet, dstSheet, history.moveRelations, false);\n }\n break;\n }\n case 'SORT_ROWS': {\n const snapshotIds = dstSheet.idMatrix.flat();\n dstSheet._sortRowMapping(history.sortedRowMapping, false);\n const preserver = new ReferencePreserver(dstSheet);\n preserver.buildMap(snapshotIds, dstSheet.idMatrix.flat());\n preserver.resolveDependents();\n dstSheet._reapplyFilters();\n break;\n }\n }\n this.refresh(shouldTracking(history.operation), true);\n if (dstSheet !== this) {\n dstSheet.addressCaches.clear();\n dstSheet.setTotalSize();\n }\n if (history.operation === 'MOVE' && srcSheet && srcSheet !== dstSheet) {\n this._xsheetDispatch(srcSheet);\n }\n return {\n history,\n callback: ({ sheetReactive: sheetRef }: { sheetReactive: RefLike<Sheet> }) => {\n sheetRef.current?.registry.transmit(history.redoReflection?.transmit);\n },\n };\n }\n /** @internal */\n public getFunctionByName(name: string) {\n return this.registry.functions[name];\n }\n\n /** @internal */\n public clearDependencies(id: Id): void {\n const sys = this.registry.systems[id];\n sys?.dependencies?.forEach((depId) => {\n this.registry.systems[depId]?.dependents?.delete(id);\n });\n if (sys != null) {\n sys.dependencies = new Set();\n }\n }\n\n /** @internal */\n public addDependency(id: Id, dependency: Id): void {\n const sys = ensureSys(this.registry, id);\n if (sys.dependents == null) {\n sys.dependents = new Set();\n }\n sys.dependents.add(dependency);\n const depSys = ensureSys(this.registry, dependency);\n if (depSys.dependencies == null) {\n depSys.dependencies = new Set();\n }\n depSys.dependencies.add(id);\n }\n\n /** @internal */\n public getSolvedCache(point: PointType): [boolean, any] {\n const id = this.getId(point);\n return [this.registry.solvedCaches.has(id), this.registry.solvedCaches.get(id)];\n }\n /** @internal */\n public setSolvingCache(point: PointType) {\n const id = this.getId(point);\n this.registry.solvedCaches.set(id, SOLVING);\n ensureSys(this.registry, id, { tmpAsyncCaches: {} });\n }\n\n /** @internal */\n public finishSolvedCache(point: PointType, value: any) {\n if (SOLVING.is(value)) {\n return;\n }\n\n const id = this.getId(point);\n this.registry.solvedCaches.set(id, value);\n\n const cell = this.registry.data[id];\n if (cell == null) {\n return;\n }\n const sys = this.registry.systems[id];\n const tmp = sys?.tmpAsyncCaches;\n\n if (tmp != null) {\n if (Object.keys(tmp).length > 0) {\n cell.asyncCaches = tmp;\n } else {\n delete cell.asyncCaches;\n }\n delete sys!.tmpAsyncCaches;\n }\n }\n\n /** @internal */\n public clearSolvedCaches() {\n this.registry.solvedCaches.clear();\n for (const id of this.registry.lastSpilledTargetIds) {\n const sys = this.registry.systems[id];\n if (sys?.spilledFrom != null) {\n delete sys.spilledFrom;\n }\n }\n this.registry.lastSpilledTargetIds.clear();\n }\n\n /**\n * Spill a 2D matrix of values starting from the origin cell.\n * The origin cell receives matrix[0][0] and adjacent cells receive spill values in solvedCaches.\n * For a 1×1 matrix, no spill occurs — the single value is cached directly.\n * Throws FormulaError('#REF!') if the spill range is obstructed.\n *\n * @param origin The anchor cell that produced the spill.\n * @param matrix The 2D array of resolved scalar values.\n * @returns The top-left value (matrix[0][0]).\n * @internal\n */\n public spill(origin: PointType, matrix: any[][]): any {\n const numRows = matrix.length;\n const numCols = numRows > 0 ? matrix[0].length : 0;\n\n // Single cell result (1×1) — no spill needed\n if (numRows <= 1 && numCols <= 1) {\n return matrix[0]?.[0];\n }\n\n // Multi-cell result — check for obstructions\n for (let i = 0; i < numRows; i++) {\n for (let j = 0; j < numCols; j++) {\n if (i === 0 && j === 0) {\n continue;\n }\n const targetPoint = { y: origin.y + i, x: origin.x + j };\n const targetId = this.getId(targetPoint);\n const address = p2a(targetPoint);\n if (targetId == null) {\n console.warn(`Spill target ${address} is out of bounds.`);\n continue;\n }\n const targetCell = this.registry.data[targetId];\n if (targetCell?.value != null && targetCell.value !== '') {\n throw new FormulaError(\n '#REF!',\n `Array result was not expanded because it would overwrite data in ${address}.`,\n );\n }\n // If solvedCaches already has an entry for this cell, another formula\n // (including another spill) has already written here — treat as obstruction.\n if (this.registry.solvedCaches.has(targetId)) {\n throw new FormulaError(\n '#REF!',\n `Array result was not expanded because ${address} is already occupied by another formula.`,\n );\n }\n }\n }\n\n // All clear — write values into solvedCaches\n const originId = this.getId(origin);\n const spilledAddresses: Address[] = [];\n for (let i = 0; i < numRows; i++) {\n for (let j = 0; j < numCols; j++) {\n const targetPoint = { y: origin.y + i, x: origin.x + j };\n const targetId = this.getId(targetPoint);\n if (targetId == null) {\n continue;\n }\n this.finishSolvedCache(targetPoint, matrix[i][j]);\n if (i !== 0 || j !== 0) {\n spilledAddresses.push(p2a(targetPoint));\n // Mark target cell as spilled from the origin formula cell\n if (originId != null) {\n const targetCell = this.registry.data[targetId];\n if (targetCell != null) {\n const sys = ensureSys(this.registry, targetId, {});\n sys.spilledFrom = p2a(origin);\n this.registry.lastSpilledTargetIds.add(targetId);\n }\n }\n }\n }\n }\n\n return matrix[0][0];\n }\n\n /** @internal */\n public sheetPrefix(omit = false) {\n if (omit) {\n return '';\n }\n return toSheetPrefix(this.name);\n }\n /** @internal */\n public rangeToArea(range: string) {\n const cells = range.split(':');\n let [start, end] = cells;\n if (start.match(/[a-zA-Z]$/)) {\n start += '1';\n }\n if (start.match(/^[1-9]/)) {\n start = `A${start}`;\n }\n if (end?.match(/[a-zA-Z]$/)) {\n end += this.bottom;\n }\n if (end?.match(/^[1-9]/)) {\n end = `${x2c(this.right)}${end}`;\n }\n const { y: top, x: left } = a2p(start);\n const { y: bottom, x: right } = a2p(end || start);\n return {\n top: Math.abs(top),\n left: Math.abs(left),\n bottom: Math.abs(bottom),\n right: Math.abs(right),\n };\n }\n\n get __raw__(): Sheet {\n return this;\n }\n\n get shape() {\n return areaShape(this.area);\n }\n get hasSingleCell() {\n const shape = this.shape;\n return shape.rows === 1 && shape.cols === 1;\n }\n get currentVersion() {\n return this.version;\n }\n}\n"],"names":["shouldTracking","op","noFilter","Sheet","limits","name","registry","createRegistry","DEFAULT_WIDTH","DEFAULT_HEIGHT","obj","escapeSheetName","_a","HEADER_HEIGHT","height","historicize","HEADER_WIDTH","width","y","x","id","numCols","col","colCell","numRows","cell","Pending","pendingMap","promises","p","resolve","check","snapshot","_b","_c","_d","filter","diffBefore","diffAfter","changedIds","trimmedBefore","trimmedAfter","activeFilters","changedAddresses","p2a","rowCell","shouldFilter","evaluateFilterConfig","wasFiltered","direction","fixedPositions","sortableIndices","a","b","cellA","cellB","valA","valB","cmp","availablePositions","changed","i","sortedRowMapping","matrixSnapshot","oldY","newY","preserver","ReferencePreserver","inverse","newOrder","oldYStr","savedRows","point","value","idMap","props","lexer","Lexer","sheetName","sheetId","cells","extension","auto","getMaxSizesFromCells","changedTime","ids","address","DEFAULT_KEY","DEFAULT_COL_KEY","DEFAULT_ROW_KEY","range","expandRange","data","origin","common","commonCol","commonRow","rowId","y2r","colId","x2c","stacked","colDefault","_cs","colDefaultLayout","headerCell","rowDefault","_rs","rowDefaultLayout","otherSheet","context","dispatch","top","left","bottom","right","l","t","rw","lw","rh","th","headerW","headerH","accW","w","colSys","accH","fullH","h","rowSys","relocate","resize","slideY","slideX","absCol","absRow","cache","a2p","existing","grantAddressAbsolute","row","resolution","raise","solveFormula","area","at","asScalar","matrix","createMatrix","FormulaError","fieldValue","history","book","kickedOut","rel","sys","depId","newCell","srcSheet","src","dst","operator","undoReflection","redoReflection","srcSheetRaw","moveRelations","dstSheet","srcTop","srcLeft","srcBottom","srcRight","dstTop","dstLeft","dstNumRows","dstNumCols","srcVisibleRows","srcNumCols","srcNumVisibleRows","dstVisibleRows","di","srcCellSet","j","dstAddrSet","dstY","dstX","srcY","srcX","srcAddr","isDstInBounds","dstAddr","newId","lostId","existingId","srcId","srcCell","dstCell","DEFAULT_POLICY_NAME","nonePolicy","reverse","wireWrites","idWritesSrc","idWritesDst","beforePolicy","afterPolicy","toPoint","movedId","fromPoint","srcPoint","dstPoint","dstId","operation.hasOperation","operation.MoveFrom","operation.MoveTo","policyKey","restricted","dstPolicyKey","srcPolicyKey","dstPolicyVal","srcPolicyVal","isSrcWinner","srcSys","srcSnapshot","dstSnapshot","r","srcAddresses","resolvedDiff","onlyValue","isXSheet","topFrom","leftFrom","bottomFrom","rightFrom","topTo","leftTo","bottomTo","rightTo","diff","toY","fromY","toX","fromX","dstPolicy","srcPolicy","dstIdForClear","dstSys","operation.Copy","partial","updateChangedTime","ignoreFields","operation.Update","formulaIdentify","resized","current","next","key","operation.Write","operation.Style","operation.Resize","merged","baseY","baseX","srcRowIndex","parsed","currentCell","matrixWithStyle","rows","copied","cloned","ys","backup","yi","operation.RemoveRows","xi","deleted","xs","operation.RemoveCols","deleting","apply","policy","raw","solved","stripSheet","e","solveSheet","addresses","matrixShape","cols","movedAddresses","snapshotIds","sheetRef","dependency","ensureSys","depSys","SOLVING","tmp","targetPoint","targetId","targetCell","originId","spilledAddresses","omit","toSheetPrefix","start","end","areaShape","shape"],"mappings":";;;;;;;;;;;;;;AAmDA,MAAMA,KAAiB,CAACC,OAAe;AACrC,UAAQA,IAAI;AAAA,IACV,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,EAAA;AAEJ,SAAA;AACT,GAsBMC,KAAuB,MAAM;AA4G5B,MAAMC,EAA2B;AAAA,EAoDtC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,GAAG7L,GAAQ,GAAGC,MAAUuB,EAAIsK,KAAOD,CAAK;AACzC,WAAA;AAAA,MACL,KAAK,KAAK,IAAI/L,CAAG;AAAA,MACjB,MAAM,KAAK,IAAIC,CAAI;AAAA,MACnB,QAAQ,KAAK,IAAIC,CAAM;AAAA,MACvB,OAAO,KAAK,IAAIC,CAAK;AAAA,IACvB;AAAA,EAAA;AAAA,EAGF,IAAI,UAAiB;AACZ,WAAA;AAAA,EAAA;AAAA,EAGT,IAAI,QAAQ;AACH,WAAA8L,GAAU,KAAK,IAAI;AAAA,EAAA;AAAA,EAE5B,IAAI,gBAAgB;AAClB,UAAMC,IAAQ,KAAK;AACnB,WAAOA,EAAM,SAAS,KAAKA,EAAM,SAAS;AAAA,EAAA;AAAA,EAE5C,IAAI,iBAAiB;AACnB,WAAO,KAAK;AAAA,EAAA;AAEhB;"}
@@ -0,0 +1,55 @@
1
+ import { Address, AreaType, CellsByAddressType, CellType, CellFilter, Resolution } from '../types';
2
+ import { UserSheet } from './sheet';
3
+ import { SolveOptions } from '../formula/solver';
4
+ type CellField = keyof CellType;
5
+ type ToProps = {
6
+ resolution?: Resolution;
7
+ raise?: boolean;
8
+ filter?: CellFilter;
9
+ asScalar?: boolean;
10
+ };
11
+ type ToCellProps = ToProps & {
12
+ ignoreFields?: CellField[];
13
+ };
14
+ /**
15
+ * @internal — used by Sheet._toValueMatrix and solver.ts; keeps resolution for internal wiring.
16
+ */
17
+ export type ToValueMatrixProps = ToProps & {
18
+ area?: AreaType;
19
+ };
20
+ export type ToCellMatrixProps = ToCellProps & {
21
+ area?: AreaType;
22
+ };
23
+ export type ToValueObjectProps = ToProps & {
24
+ addresses?: Address[];
25
+ };
26
+ export type ToCellObjectProps = ToCellProps & {
27
+ addresses?: Address[];
28
+ };
29
+ export type ToValueRowsProps = ToProps & {
30
+ rows?: number[];
31
+ };
32
+ export type ToCellRowsProps = ToCellProps & {
33
+ rows?: number[];
34
+ };
35
+ export type ToValueColsProps = ToProps & {
36
+ cols?: (number | string)[];
37
+ };
38
+ export type ToCellColsProps = ToCellProps & {
39
+ cols?: (number | string)[];
40
+ };
41
+ export declare const getCellByAddress: (sheet: UserSheet, address: Address, options?: SolveOptions) => CellType | undefined;
42
+ export declare const toValueMatrix: (sheet: UserSheet, { area, resolution, raise, filter, asScalar }?: ToValueMatrixProps) => any[][];
43
+ export declare const toValueObject: (sheet: UserSheet, { resolution, raise, filter, addresses, asScalar }?: ToValueObjectProps) => {
44
+ [address: Address]: any;
45
+ };
46
+ export declare const toValueRows: (sheet: UserSheet, { resolution, raise, filter, rows, asScalar }?: ToValueRowsProps) => CellsByAddressType[];
47
+ export declare const toValueCols: (sheet: UserSheet, { resolution, raise, filter, cols, asScalar }?: ToValueColsProps) => CellsByAddressType[];
48
+ export declare const toCellMatrix: (sheet: UserSheet, { area, resolution, raise, filter, ignoreFields }?: ToCellMatrixProps) => (CellType | null)[][];
49
+ export declare const toCellObject: (sheet: UserSheet, { resolution, raise, filter, addresses, ignoreFields }?: ToCellObjectProps) => CellsByAddressType;
50
+ export declare const toCellRows: (sheet: UserSheet, { resolution, raise, filter, rows, ignoreFields }?: ToCellRowsProps) => CellsByAddressType[];
51
+ export declare const escapeSheetName: (name: string) => string;
52
+ export declare const toSheetPrefix: (name?: string) => string;
53
+ export declare const toCellCols: (sheet: UserSheet, { resolution, raise, filter, cols, ignoreFields }?: ToCellColsProps) => CellsByAddressType[];
54
+ export {};
55
+ //# sourceMappingURL=sheet_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet_utils.d.ts","sourceRoot":"","sources":["../../src/lib/sheet_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAM,MAAM,UAAU,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAA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eAAO,MAAM,gBAAgB,GAC3B,OAAO,SAAS,EAChB,SAAS,OAAO,EAChB,UAAS,YAAiB,KACzB,QAAQ,GAAG,SAGb,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,EAChB,gDAAuF,kBAAuB,KAC7G,GAAG,EAAE,EAEP,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,OAAO,SAAS,EAChB,qDAA4F,kBAAuB,KAClH;IAAE,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAAA;CAgC3B,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,OAAO,SAAS,EAChB,gDAAuF,gBAAqB,KAC3G,kBAAkB,EAoBpB,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,OAAO,SAAS,EAChB,gDAAuF,gBAAqB,KAC3G,kBAAkB,EAsBpB,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,EAChB,oDAAwF,iBAAsB,KAC7G,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,EAkBrB,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,OAAO,SAAS,EAChB,yDAA6F,iBAAsB,KAClH,kBAqBF,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,EAChB,oDAAwF,eAAoB,KAC3G,kBAAkB,EAepB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAG9C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAK7C,CAAC;AAEF,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,EAChB,oDAAwF,eAAoB,KAC3G,kBAAkB,EAiBpB,CAAC"}
@@ -0,0 +1,125 @@
1
+ import { a2p as V, p2a as E, x2c as S, c2x as v, y2r as R } from "./coords.js";
2
+ import { createMatrix as O } from "./spatial.js";
3
+ import { filterCellFields as x } from "./cell.js";
4
+ const _ = () => !0, b = (t, n, a = {}) => {
5
+ const f = V(n);
6
+ return t.getCell(f, a);
7
+ }, P = (t, { area: n, resolution: a = "RESOLVED", raise: f = !1, filter: s = _, asScalar: p = !1 } = {}) => t.__raw__._toValueMatrix({ area: n, resolution: a, raise: f, filter: s, asScalar: p }), M = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, addresses: s, asScalar: p = !1 } = {}) => {
8
+ const c = {};
9
+ if (s) {
10
+ for (const r of s) {
11
+ const o = V(r), l = b(t, r, { resolution: n, raise: a }) ?? {};
12
+ if (f(l)) {
13
+ let e = l.value;
14
+ p && (e = t.getPolicy(o).toScalar({ value: l.value, cell: l, sheet: t.__raw__, point: o })), c[r] = e;
15
+ }
16
+ }
17
+ return c;
18
+ }
19
+ const { top: g, left: m, bottom: i, right: u } = t.area;
20
+ for (let r = g; r <= i; r++)
21
+ for (let o = m; o <= u; o++) {
22
+ const l = t.getCell({ y: r, x: o }, { resolution: n, raise: a }) ?? {};
23
+ if (f(l)) {
24
+ let e = l.value;
25
+ p && (e = t.getPolicy({ y: r, x: o }).toScalar({ value: l.value, cell: l, sheet: t.__raw__, point: { y: r, x: o } })), c[E({ y: r, x: o })] = e;
26
+ }
27
+ }
28
+ return c;
29
+ }, j = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, rows: s, asScalar: p = !1 } = {}) => {
30
+ const c = [], { top: g, left: m, bottom: i, right: u } = t.area, r = s ?? Array.from({ length: t.numRows }, (o, l) => g + l);
31
+ for (const o of r) {
32
+ const l = {};
33
+ c.push(l);
34
+ for (let e = m; e <= u; e++) {
35
+ const y = t.getCell({ y: o, x: e }, { resolution: n, raise: a }) ?? {};
36
+ if (f(y)) {
37
+ let C = y.value;
38
+ p && (C = t.getPolicy({ y: o, x: e }).toScalar({ value: y.value, cell: y, sheet: t.__raw__, point: { y: o, x: e } })), l[S(e)] = C;
39
+ }
40
+ }
41
+ }
42
+ return c;
43
+ }, $ = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, cols: s, asScalar: p = !1 } = {}) => {
44
+ const c = [], { top: g, left: m, bottom: i, right: u } = t.area, r = s ? s.map((o) => typeof o == "string" ? v(o) : o) : Array.from({ length: t.numCols }, (o, l) => m + l);
45
+ for (const o of r) {
46
+ const l = {};
47
+ c.push(l);
48
+ for (let e = g; e <= i; e++) {
49
+ const y = t.getCell({ y: e, x: o }, { resolution: n, raise: a }) ?? {};
50
+ if (f(y)) {
51
+ let C = y.value;
52
+ p && (C = t.getPolicy({ y: e, x: o }).toScalar({ value: y.value, cell: y, sheet: t.__raw__, point: { y: e, x: o } })), l[R(e)] = C;
53
+ }
54
+ }
55
+ }
56
+ return c;
57
+ }, h = (t, { area: n, resolution: a = "RESOLVED", raise: f = !1, filter: s = _, ignoreFields: p = [] } = {}) => {
58
+ const { top: c, left: g, bottom: m, right: i } = n ?? {
59
+ top: 1,
60
+ left: 1,
61
+ bottom: t.area.bottom,
62
+ right: t.area.right
63
+ }, u = O(m - c + 1, i - g + 1);
64
+ for (let r = c; r <= m; r++)
65
+ for (let o = g; o <= i; o++) {
66
+ const l = t.getCell({ y: r, x: o }, { resolution: a, raise: f }) ?? {};
67
+ if (s(l)) {
68
+ const e = x(l, p);
69
+ u[r - c][o - g] = e;
70
+ }
71
+ }
72
+ return u;
73
+ }, B = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, addresses: s, ignoreFields: p = [] } = {}) => {
74
+ const c = {};
75
+ if (s) {
76
+ for (const i of s) {
77
+ const u = b(t, i, { resolution: n, raise: a }) ?? {};
78
+ f(u) && (c[i] = x(u, p));
79
+ }
80
+ return c;
81
+ }
82
+ const { bottom: g, right: m } = t.area;
83
+ for (let i = 1; i <= g; i++)
84
+ for (let u = 1; u <= m; u++) {
85
+ const r = t.getCell({ y: i, x: u }, { resolution: n, raise: a }) ?? {};
86
+ f(r) && (c[E({ y: i, x: u })] = x(r, p));
87
+ }
88
+ return c;
89
+ }, F = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, rows: s, ignoreFields: p = [] } = {}) => {
90
+ const c = [], { top: g, left: m, bottom: i, right: u } = t.area, r = s ?? Array.from({ length: t.numRows }, (o, l) => g + l);
91
+ for (const o of r) {
92
+ const l = {};
93
+ c.push(l);
94
+ for (let e = m; e <= u; e++) {
95
+ const y = t.getCell({ y: o, x: e }, { resolution: n, raise: a }) ?? {};
96
+ f(y) && (l[S(e)] = x(y, p));
97
+ }
98
+ }
99
+ return c;
100
+ }, d = (t) => `'${t.replace(/'/g, "''")}'`, N = (t) => t ? `${d(t)}!` : "", k = (t, { resolution: n = "RESOLVED", raise: a = !1, filter: f = _, cols: s, ignoreFields: p = [] } = {}) => {
101
+ const c = [], { top: g, left: m, bottom: i, right: u } = t.area, r = s ? s.map((o) => typeof o == "string" ? v(o) : o) : Array.from({ length: t.numCols }, (o, l) => m + l);
102
+ for (const o of r) {
103
+ const l = {};
104
+ c.push(l);
105
+ for (let e = g; e <= i; e++) {
106
+ const y = t.getCell({ y: e, x: o }, { resolution: n, raise: a }) ?? {};
107
+ f(y) && (l[R(e)] = x(y, p));
108
+ }
109
+ }
110
+ return c;
111
+ };
112
+ export {
113
+ d as escapeSheetName,
114
+ b as getCellByAddress,
115
+ k as toCellCols,
116
+ h as toCellMatrix,
117
+ B as toCellObject,
118
+ F as toCellRows,
119
+ N as toSheetPrefix,
120
+ $ as toValueCols,
121
+ P as toValueMatrix,
122
+ M as toValueObject,
123
+ j as toValueRows
124
+ };
125
+ //# sourceMappingURL=sheet_utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet_utils.js","sources":["../../src/lib/sheet_utils.ts"],"sourcesContent":["import type { Address, AreaType, CellsByAddressType, CellType, Id } from '../types';\nimport type { UserSheet } from './sheet';\nimport { a2p, p2a, x2c, c2x, y2r } from './coords';\nimport { createMatrix } from './spatial';\nimport { filterCellFields } from './cell';\nimport type { CellFilter, Resolution } from '../types';\nimport type { SolveOptions } from '../formula/solver';\n\nconst noFilter: CellFilter = () => true;\n\ntype CellField = keyof CellType;\n\ntype ToProps = {\n resolution?: Resolution;\n raise?: boolean;\n filter?: CellFilter;\n asScalar?: boolean;\n};\n\ntype ToCellProps = ToProps & {\n ignoreFields?: CellField[];\n};\n\n/**\n * @internal — used by Sheet._toValueMatrix and solver.ts; keeps resolution for internal wiring.\n */\n\nexport type ToValueMatrixProps = ToProps & {\n area?: AreaType;\n};\n\nexport type ToCellMatrixProps = ToCellProps & {\n area?: AreaType;\n};\n\nexport type ToValueObjectProps = ToProps & {\n addresses?: Address[];\n};\n\nexport type ToCellObjectProps = ToCellProps & {\n addresses?: Address[];\n};\n\nexport type ToValueRowsProps = ToProps & {\n rows?: number[];\n};\n\nexport type ToCellRowsProps = ToCellProps & {\n rows?: number[];\n};\n\nexport type ToValueColsProps = ToProps & {\n cols?: (number | string)[];\n};\n\nexport type ToCellColsProps = ToCellProps & {\n cols?: (number | string)[];\n};\n\nexport const getCellByAddress = (\n sheet: UserSheet,\n address: Address,\n options: SolveOptions = {},\n): CellType | undefined => {\n const point = a2p(address);\n return sheet.getCell(point, options);\n};\n\nexport const toValueMatrix = (\n sheet: UserSheet,\n { area, resolution = 'RESOLVED', raise = false, filter = noFilter, asScalar = false }: ToValueMatrixProps = {},\n): any[][] => {\n return sheet.__raw__._toValueMatrix({ area, resolution, raise, filter, asScalar });\n};\n\nexport const toValueObject = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, addresses, asScalar = false }: ToValueObjectProps = {},\n): { [address: Address]: any } => {\n const result: { [Address: Address]: any } = {};\n if (addresses) {\n for (const addr of addresses) {\n const point = a2p(addr);\n const cell = getCellByAddress(sheet, addr, { resolution, raise }) ?? {};\n if (filter(cell)) {\n let fieldValue = cell.value;\n if (asScalar) {\n const policy = sheet.getPolicy(point);\n fieldValue = policy.toScalar({ value: cell.value, cell, sheet: sheet.__raw__, point });\n }\n result[addr] = fieldValue;\n }\n }\n return result;\n }\n const { top, left, bottom, right } = sheet.area;\n for (let y = top; y <= bottom; y++) {\n for (let x = left; x <= right; x++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n let fieldValue = cell.value;\n if (asScalar) {\n const policy = sheet.getPolicy({ y, x });\n fieldValue = policy.toScalar({ value: cell.value, cell, sheet: sheet.__raw__, point: { y, x } });\n }\n result[p2a({ y, x })] = fieldValue;\n }\n }\n }\n return result;\n};\n\nexport const toValueRows = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, rows, asScalar = false }: ToValueRowsProps = {},\n): CellsByAddressType[] => {\n const result: CellsByAddressType[] = [];\n const { top, left, bottom, right } = sheet.area;\n const ys = rows ?? Array.from({ length: sheet.numRows }, (_, i) => top + i);\n for (const y of ys) {\n const row: CellsByAddressType = {};\n result.push(row);\n for (let x = left; x <= right; x++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n let fieldValue = cell.value;\n if (asScalar) {\n const policy = sheet.getPolicy({ y, x });\n fieldValue = policy.toScalar({ value: cell.value, cell, sheet: sheet.__raw__, point: { y, x } });\n }\n row[x2c(x)] = fieldValue as any;\n }\n }\n }\n return result;\n};\n\nexport const toValueCols = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, cols, asScalar = false }: ToValueColsProps = {},\n): CellsByAddressType[] => {\n const result: CellsByAddressType[] = [];\n const { top, left, bottom, right } = sheet.area;\n const xs = cols\n ? cols.map((c) => (typeof c === 'string' ? c2x(c) : c))\n : Array.from({ length: sheet.numCols }, (_, i) => left + i);\n for (const x of xs) {\n const col: CellsByAddressType = {};\n result.push(col);\n for (let y = top; y <= bottom; y++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n let fieldValue = cell.value;\n if (asScalar) {\n const policy = sheet.getPolicy({ y, x });\n fieldValue = policy.toScalar({ value: cell.value, cell, sheet: sheet.__raw__, point: { y, x } });\n }\n col[y2r(y)] = fieldValue as any;\n }\n }\n }\n return result;\n};\n\nexport const toCellMatrix = (\n sheet: UserSheet,\n { area, resolution = 'RESOLVED', raise = false, filter = noFilter, ignoreFields = [] }: ToCellMatrixProps = {},\n): (CellType | null)[][] => {\n const { top, left, bottom, right } = area ?? {\n top: 1,\n left: 1,\n bottom: sheet.area.bottom,\n right: sheet.area.right,\n };\n const matrix = createMatrix(bottom - top + 1, right - left + 1);\n for (let y = top; y <= bottom; y++) {\n for (let x = left; x <= right; x++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n const filteredCell = filterCellFields(cell, ignoreFields);\n matrix[y - top][x - left] = filteredCell;\n }\n }\n }\n return matrix;\n};\n\nexport const toCellObject = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, addresses, ignoreFields = [] }: ToCellObjectProps = {},\n): CellsByAddressType => {\n const result: CellsByAddressType = {};\n if (addresses) {\n for (const addr of addresses) {\n const cell = getCellByAddress(sheet, addr, { resolution, raise }) ?? {};\n if (filter(cell)) {\n result[addr] = filterCellFields(cell, ignoreFields);\n }\n }\n return result;\n }\n const { bottom, right } = sheet.area;\n for (let y = 1; y <= bottom; y++) {\n for (let x = 1; x <= right; x++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n result[p2a({ y, x })] = filterCellFields(cell, ignoreFields);\n }\n }\n }\n return result;\n};\n\nexport const toCellRows = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, rows, ignoreFields = [] }: ToCellRowsProps = {},\n): CellsByAddressType[] => {\n const result: CellsByAddressType[] = [];\n const { top, left, bottom, right } = sheet.area;\n const ys = rows ?? Array.from({ length: sheet.numRows }, (_, i) => top + i);\n for (const y of ys) {\n const row: CellsByAddressType = {};\n result.push(row);\n for (let x = left; x <= right; x++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n row[x2c(x)] = filterCellFields(cell, ignoreFields);\n }\n }\n }\n return result;\n};\n\nexport const escapeSheetName = (name: string): string => {\n const escaped = name.replace(/'/g, \"''\");\n return `'${escaped}'`;\n};\n\nexport const toSheetPrefix = (name?: string): string => {\n if (name) {\n return `${escapeSheetName(name)}!`;\n }\n return '';\n};\n\nexport const toCellCols = (\n sheet: UserSheet,\n { resolution = 'RESOLVED', raise = false, filter = noFilter, cols, ignoreFields = [] }: ToCellColsProps = {},\n): CellsByAddressType[] => {\n const result: CellsByAddressType[] = [];\n const { top, left, bottom, right } = sheet.area;\n const xs = cols\n ? cols.map((c) => (typeof c === 'string' ? c2x(c) : c))\n : Array.from({ length: sheet.numCols }, (_, i) => left + i);\n for (const x of xs) {\n const col: CellsByAddressType = {};\n result.push(col);\n for (let y = top; y <= bottom; y++) {\n const cell = sheet.getCell({ y, x }, { resolution, raise }) ?? {};\n if (filter(cell)) {\n col[y2r(y)] = filterCellFields(cell, ignoreFields);\n }\n }\n }\n return result;\n};\n"],"names":["noFilter","getCellByAddress","sheet","address","options","point","a2p","toValueMatrix","area","resolution","raise","filter","asScalar","toValueObject","addresses","result","addr","cell","fieldValue","top","left","bottom","right","y","x","p2a","toValueRows","rows","ys","_","i","row","x2c","toValueCols","cols","xs","c","c2x","col","y2r","toCellMatrix","ignoreFields","matrix","createMatrix","filteredCell","filterCellFields","toCellObject","toCellRows","escapeSheetName","name","toSheetPrefix","toCellCols"],"mappings":";;;AAQA,MAAMA,IAAuB,MAAM,IAmDtBC,IAAmB,CAC9BC,GACAC,GACAC,IAAwB,CAAA,MACC;AACnB,QAAAC,IAAQC,EAAIH,CAAO;AAClB,SAAAD,EAAM,QAAQG,GAAOD,CAAO;AACrC,GAEaG,IAAgB,CAC3BL,GACA,EAAE,MAAAM,GAAM,YAAAC,IAAa,YAAY,OAAAC,IAAQ,IAAO,QAAAC,IAASX,GAAU,UAAAY,IAAW,GAAM,IAAwB,CAAA,MAErGV,EAAM,QAAQ,eAAe,EAAE,MAAAM,GAAM,YAAAC,GAAY,OAAAC,GAAO,QAAAC,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