@allyhub/sdk 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/node_modules/@allyhub/audio/dist/plan.d.ts +3 -0
  3. package/dist/node_modules/@allyhub/audio/dist/render.js +1 -1
  4. package/dist/node_modules/@allyhub/audio/package.json +1 -1
  5. package/dist/node_modules/@allyhub/chart/dist/chart-file.d.ts +2 -0
  6. package/dist/node_modules/@allyhub/chart/dist/chart-file.js +1 -1
  7. package/dist/node_modules/@allyhub/chart/dist/chart-xml.js +3 -2
  8. package/dist/node_modules/@allyhub/chart/dist/chart.d.ts +5 -12
  9. package/dist/node_modules/@allyhub/chart/dist/chart.js +2 -1
  10. package/dist/node_modules/@allyhub/chart/dist/color.d.ts +37 -0
  11. package/dist/node_modules/@allyhub/chart/dist/color.js +2 -0
  12. package/dist/node_modules/@allyhub/chart/dist/index.d.ts +1 -0
  13. package/dist/node_modules/@allyhub/chart/dist/index.js +1 -1
  14. package/dist/node_modules/@allyhub/chart/dist/svg.js +1 -1
  15. package/dist/node_modules/@allyhub/chart/package.json +1 -1
  16. package/dist/node_modules/@allyhub/diagnostics/package.json +1 -1
  17. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.d.ts +130 -0
  18. package/dist/node_modules/@allyhub/formats/dist/data/deck-code.js +1 -1
  19. package/dist/node_modules/@allyhub/formats/dist/data/gen.d.ts +3 -1
  20. package/dist/node_modules/@allyhub/formats/dist/data/gen.js +1 -1
  21. package/dist/node_modules/@allyhub/formats/dist/data/sheet.d.ts +512 -166
  22. package/dist/node_modules/@allyhub/formats/dist/data/sheet.js +1 -1
  23. package/dist/node_modules/@allyhub/formats/dist/data/slides.d.ts +2523 -136
  24. package/dist/node_modules/@allyhub/formats/dist/data/slides.js +1 -1
  25. package/dist/node_modules/@allyhub/formats/dist/schemas.d.ts +931 -87
  26. package/dist/node_modules/@allyhub/formats/dist/schemas.js +1 -1
  27. package/dist/node_modules/@allyhub/formats/package.json +1 -1
  28. package/dist/node_modules/@allyhub/image-draw/package.json +1 -1
  29. package/dist/node_modules/@allyhub/image-measure/package.json +1 -1
  30. package/dist/node_modules/@allyhub/image-sdk/package.json +1 -1
  31. package/dist/node_modules/@allyhub/measure/package.json +1 -1
  32. package/dist/node_modules/@allyhub/ooxml/dist/color.d.ts +11 -0
  33. package/dist/node_modules/@allyhub/ooxml/dist/color.js +1 -1
  34. package/dist/node_modules/@allyhub/ooxml/dist/ext.d.ts +43 -0
  35. package/dist/node_modules/@allyhub/ooxml/dist/ext.js +1 -1
  36. package/dist/node_modules/@allyhub/ooxml/dist/index.d.ts +2 -1
  37. package/dist/node_modules/@allyhub/ooxml/dist/index.js +1 -1
  38. package/dist/node_modules/@allyhub/ooxml/dist/transform.d.ts +13 -0
  39. package/dist/node_modules/@allyhub/ooxml/dist/transform.js +2 -0
  40. package/dist/node_modules/@allyhub/ooxml/package.json +5 -1
  41. package/dist/node_modules/@allyhub/piece/dist/gen.d.ts +4 -4
  42. package/dist/node_modules/@allyhub/piece/dist/media.d.ts +2 -2
  43. package/dist/node_modules/@allyhub/piece/package.json +1 -1
  44. package/dist/node_modules/@allyhub/protocol/dist/account.d.ts +35 -0
  45. package/dist/node_modules/@allyhub/protocol/dist/account.js +1 -1
  46. package/dist/node_modules/@allyhub/protocol/dist/cloud.d.ts +19 -0
  47. package/dist/node_modules/@allyhub/protocol/dist/cloud.js +1 -1
  48. package/dist/node_modules/@allyhub/protocol/dist/editor.d.ts +35 -20
  49. package/dist/node_modules/@allyhub/protocol/dist/editor.js +1 -1
  50. package/dist/node_modules/@allyhub/protocol/dist/events.d.ts +3 -3
  51. package/dist/node_modules/@allyhub/protocol/dist/frame.d.ts +28 -2
  52. package/dist/node_modules/@allyhub/protocol/dist/frame.js +1 -1
  53. package/dist/node_modules/@allyhub/protocol/dist/jobs.d.ts +6 -6
  54. package/dist/node_modules/@allyhub/protocol/dist/snapshots.d.ts +73 -10
  55. package/dist/node_modules/@allyhub/protocol/dist/snapshots.js +1 -1
  56. package/dist/node_modules/@allyhub/protocol/dist/tools.d.ts +9 -9
  57. package/dist/node_modules/@allyhub/protocol/package.json +1 -1
  58. package/dist/node_modules/@allyhub/runtimes/package.json +1 -1
  59. package/dist/node_modules/@allyhub/scenery/package.json +1 -1
  60. package/dist/node_modules/@allyhub/sheet/dist/annotations.d.ts +14 -0
  61. package/dist/node_modules/@allyhub/sheet/dist/annotations.js +2 -0
  62. package/dist/node_modules/@allyhub/sheet/dist/api/capabilities.js +1 -1
  63. package/dist/node_modules/@allyhub/sheet/dist/api/index.d.ts +1 -1
  64. package/dist/node_modules/@allyhub/sheet/dist/api/index.js +1 -1
  65. package/dist/node_modules/@allyhub/sheet/dist/api/rules.d.ts +24 -0
  66. package/dist/node_modules/@allyhub/sheet/dist/api/rules.js +1 -1
  67. package/dist/node_modules/@allyhub/sheet/dist/api/styles.d.ts +12 -0
  68. package/dist/node_modules/@allyhub/sheet/dist/api/styles.js +1 -1
  69. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.d.ts +3 -1
  70. package/dist/node_modules/@allyhub/sheet/dist/api/workbook.js +1 -1
  71. package/dist/node_modules/@allyhub/sheet/dist/arrange.d.ts +28 -1
  72. package/dist/node_modules/@allyhub/sheet/dist/arrange.js +1 -1
  73. package/dist/node_modules/@allyhub/sheet/dist/data-tools.d.ts +42 -0
  74. package/dist/node_modules/@allyhub/sheet/dist/data-tools.js +2 -0
  75. package/dist/node_modules/@allyhub/sheet/dist/edit.d.ts +43 -2
  76. package/dist/node_modules/@allyhub/sheet/dist/edit.js +1 -1
  77. package/dist/node_modules/@allyhub/sheet/dist/fill.d.ts +10 -0
  78. package/dist/node_modules/@allyhub/sheet/dist/fill.js +1 -1
  79. package/dist/node_modules/@allyhub/sheet/dist/filter.js +1 -1
  80. package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.d.ts +14 -0
  81. package/dist/node_modules/@allyhub/sheet/dist/formula/rewrite.js +1 -1
  82. package/dist/node_modules/@allyhub/sheet/dist/html.js +10 -10
  83. package/dist/node_modules/@allyhub/sheet/dist/index.d.ts +6 -1
  84. package/dist/node_modules/@allyhub/sheet/dist/index.js +1 -1
  85. package/dist/node_modules/@allyhub/sheet/dist/outline.d.ts +30 -0
  86. package/dist/node_modules/@allyhub/sheet/dist/outline.js +2 -0
  87. package/dist/node_modules/@allyhub/sheet/dist/rich.d.ts +29 -0
  88. package/dist/node_modules/@allyhub/sheet/dist/rich.js +2 -0
  89. package/dist/node_modules/@allyhub/sheet/dist/rules.js +1 -1
  90. package/dist/node_modules/@allyhub/sheet/dist/table-style.d.ts +6 -0
  91. package/dist/node_modules/@allyhub/sheet/dist/table-style.js +1 -1
  92. package/dist/node_modules/@allyhub/sheet/dist/table-styles.js +1 -1
  93. package/dist/node_modules/@allyhub/sheet/dist/workbook.d.ts +5 -1
  94. package/dist/node_modules/@allyhub/sheet/dist/workbook.js +1 -1
  95. package/dist/node_modules/@allyhub/sheet/dist/xlsx/charts.js +1 -1
  96. package/dist/node_modules/@allyhub/sheet/dist/xlsx/import.js +1 -1
  97. package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.d.ts +17 -1
  98. package/dist/node_modules/@allyhub/sheet/dist/xlsx/read.js +2 -2
  99. package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.d.ts +56 -0
  100. package/dist/node_modules/@allyhub/sheet/dist/xlsx/runs.js +2 -0
  101. package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.d.ts +6 -0
  102. package/dist/node_modules/@allyhub/sheet/dist/xlsx/styles.js +1 -1
  103. package/dist/node_modules/@allyhub/sheet/dist/xlsx/write.js +1 -1
  104. package/dist/node_modules/@allyhub/sheet/package.json +1 -1
  105. package/dist/node_modules/@allyhub/slides-core/dist/animation.d.ts +117 -21
  106. package/dist/node_modules/@allyhub/slides-core/dist/animation.js +1 -1
  107. package/dist/node_modules/@allyhub/slides-core/dist/api.d.ts +181 -30
  108. package/dist/node_modules/@allyhub/slides-core/dist/api.js +3 -3
  109. package/dist/node_modules/@allyhub/slides-core/dist/capabilities.js +1 -1
  110. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.d.ts +28 -2
  111. package/dist/node_modules/@allyhub/slides-core/dist/chart-api.js +1 -1
  112. package/dist/node_modules/@allyhub/slides-core/dist/check.js +1 -1
  113. package/dist/node_modules/@allyhub/slides-core/dist/enums.d.ts +222 -4
  114. package/dist/node_modules/@allyhub/slides-core/dist/enums.js +1 -1
  115. package/dist/node_modules/@allyhub/slides-core/dist/file.d.ts +6 -0
  116. package/dist/node_modules/@allyhub/slides-core/dist/file.js +3 -3
  117. package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.d.ts +3 -0
  118. package/dist/node_modules/@allyhub/slides-core/dist/generated/table-styles.js +2 -0
  119. package/dist/node_modules/@allyhub/slides-core/dist/index.d.ts +3 -0
  120. package/dist/node_modules/@allyhub/slides-core/dist/index.js +1 -1
  121. package/dist/node_modules/@allyhub/slides-core/dist/merge.js +1 -1
  122. package/dist/node_modules/@allyhub/slides-core/dist/model.d.ts +98 -10
  123. package/dist/node_modules/@allyhub/slides-core/dist/numbering.d.ts +6 -0
  124. package/dist/node_modules/@allyhub/slides-core/dist/numbering.js +2 -0
  125. package/dist/node_modules/@allyhub/slides-core/dist/office.d.ts +53 -0
  126. package/dist/node_modules/@allyhub/slides-core/dist/office.js +1 -1
  127. package/dist/node_modules/@allyhub/slides-core/dist/patterns.d.ts +8 -0
  128. package/dist/node_modules/@allyhub/slides-core/dist/patterns.js +2 -0
  129. package/dist/node_modules/@allyhub/slides-core/dist/resolve.d.ts +36 -6
  130. package/dist/node_modules/@allyhub/slides-core/dist/resolve.js +1 -1
  131. package/dist/node_modules/@allyhub/slides-core/dist/script.d.ts +11 -0
  132. package/dist/node_modules/@allyhub/slides-core/dist/script.js +2 -2
  133. package/dist/node_modules/@allyhub/slides-core/dist/sdk.d.ts +1 -1
  134. package/dist/node_modules/@allyhub/slides-core/dist/sdk.js +1 -1
  135. package/dist/node_modules/@allyhub/slides-core/dist/table-style.d.ts +48 -0
  136. package/dist/node_modules/@allyhub/slides-core/dist/table-style.js +2 -0
  137. package/dist/node_modules/@allyhub/slides-core/package.json +1 -1
  138. package/dist/node_modules/@allyhub/video-core/dist/mix-plan.js +1 -1
  139. package/dist/node_modules/@allyhub/video-core/dist/timeline.d.ts +4 -0
  140. package/dist/node_modules/@allyhub/video-core/package.json +1 -1
  141. package/dist/node_modules/@allyhub/video-sdk/package.json +1 -1
  142. package/docs/defaults.md +78 -4
  143. package/docs/image.md +1 -1
  144. package/docs/pictures.md +1 -1
  145. package/docs/project.md +1 -1
  146. package/docs/sheets.md +19 -9
  147. package/docs/slides.md +30 -16
  148. package/docs/speech.md +1 -1
  149. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{publicNames as n}from"@allyhub/formats";import{FUNCTIONS as h}from"../calc/functions/index.js";import{AreaChart as p,BarChart as d,DataLabelList as m,DoughnutChart as c,GraphicalProperties as w,Legend as f,LineChart as u,LineProperties as y,Marker as g,NumericAxis as b,PieChart as k,Reference as _,ScatterChart as x,Scaling as C,Series as A,TextAxis as S}from"./charts.js";import{AutoFilter as v,ConditionalFormattingList as D,DataValidation as L,DataValidationList as P,DifferentialStyle as F,Rule as T}from"./rules.js";import{Alignment as R,Border as I,Color as N,Font as E,PatternFill as V,Side as B}from"./styles.js";import{Cell as W,ColumnDimension as j,DefinedName as M,DefinedNameDict as G,RowDimension as H,Table as O,TableList as U,Workbook as z,Worksheet as q}from"./workbook.js";import{Comment as X,HeaderFooter as Y,HeaderFooterPart as J,Image as K,PageMargins as Q,PageSetup as Z,SheetProtection as $}from"./page.js";const a={Series:{title:"A series' name in words, openpyxl's SeriesFactory argument, kept here as a field."},Workbook:{open:"Workbook.open(path): a workbook read, by its file or a folder's sheet.yaml (load_workbook(path) is the same).",block_cells:"How many typed cells together go in a CSV file of their own: 100 unless set.",title:"The workbook's title, sheet.yaml's.",check:"wb.check(): what allyhub check would say of the workbook as it stands: a list of { file, line, message }."},Cell:{computed:"What the cell computes to, the workbook as it stands, saved or not."},Table:{key:"The column that lines rows up when two hands' changes merge."},DataValidation:{multiple:"A list's cell may hold several of its values, joined by separator: an .xlsx keeps them as text.",separator:"What joins a cell's choices: a comma and a space unless set."},PageSetup:{fitToWidth:"Pages wide; setting it or fitToHeight fits the sheet, with no pageSetUpPr to set."},ColumnDimension:{files:"Its cells name files, from the sheet's folder: true, or { separator, height }."}},ee=["add_data","set_categories","append","title","legend","width","height","style","anchor","series","dataLabels","x_axis","y_axis"],te={BarChart:["type","grouping","overlap","gapWidth","varyColors"],LineChart:["grouping"],AreaChart:["grouping"],PieChart:["varyColors"],DoughnutChart:["holeSize"],ScatterChart:[]},oe={Workbook:z.prototype,Worksheet:q.prototype,Cell:W.prototype,Font:E.prototype,PatternFill:V.prototype,Border:I.prototype,Side:B.prototype,Alignment:R.prototype,Color:N.prototype,Table:O.prototype,TableList:U.prototype,DefinedName:M.prototype,DefinedNameDict:G.prototype,ColumnDimension:j.prototype,RowDimension:H.prototype,ConditionalFormattingList:D.prototype,Rule:T.prototype,DifferentialStyle:F.prototype,DataValidation:L.prototype,DataValidationList:P.prototype,AutoFilter:v.prototype,BarChart:d.prototype,LineChart:u.prototype,AreaChart:p.prototype,PieChart:k.prototype,DoughnutChart:c.prototype,ScatterChart:x.prototype,Reference:_.prototype,Series:A.prototype,Legend:f.prototype,Scaling:C.prototype,TextAxis:S.prototype,NumericAxis:b.prototype,DataLabelList:m.prototype,Marker:g.prototype,GraphicalProperties:w.prototype,LineProperties:y.prototype,PageSetup:Z.prototype,PageMargins:Q.prototype,_HeaderFooterItem:Y.prototype,_HeaderFooterPart:J.prototype,SheetProtection:$.prototype,Comment:X.prototype,Image:K.prototype},r=["title","scaling","majorUnit","number_format","delete","majorGridlines"],ae={_HeaderFooterItem:["left","center","right"],Comment:["text","author"],Image:["path","width","height","anchor"],Workbook:["worksheets","defined_names","data_only","path","title","block_cells"],Cell:["row","column"],Worksheet:["min_row","min_column"],Font:["name","size","bold","italic","underline","strike","color"],PatternFill:["fill_type","fgColor","bgColor"],Border:["left","right","top","bottom"],Side:["style","color"],Alignment:["horizontal","vertical","wrap_text","shrink_to_fit","indent","text_rotation"],Color:["rgb"],Table:["displayName","ref","key","autoFilter"],DefinedName:["name","attr_text"],ColumnDimension:["index"],RowDimension:["index"],Rule:["type","operator","formula","stopIfTrue","rank","percent","bottom","aboveAverage","equalAverage","text","dxf"],DifferentialStyle:["font","fill","border"],DataValidation:["type","formula1","formula2","operator","allow_blank","showDropDown","showErrorMessage","showInputMessage","errorStyle","errorTitle","error","promptTitle","prompt","sqref"],DataValidationList:["dataValidation"],AutoFilter:["ref"],...Object.fromEntries(Object.entries(te).map(([e,t])=>[e,[...ee.filter(o=>!(/^(?:Pie|Doughnut)/u.test(e)&&o.endsWith("_axis"))),...t]])),Reference:["worksheet","min_col","min_row","max_col","max_row"],Series:["val","xVal","title","smooth","marker","graphicalProperties"],Legend:["position"],Scaling:["min","max","orientation"],TextAxis:r.filter(e=>e!=="majorUnit"),NumericAxis:r,DataLabelList:["showVal","showPercent","showCatName","showSerName","dLblPos"],Marker:["symbol","size"],GraphicalProperties:["solidFill","noFill","line"],LineProperties:["width","solidFill","noFill"]};export const HELPERS=["CellIsRule","ColorScaleRule","DataBarRule","FormulaRule","IconSetRule","column_index_from_string","coordinate_to_tuple","get_column_letter","range_boundaries"];const re=()=>{const e={};for(const[t,o]of Object.entries(oe)){const i=a[t]??{};e[t]=[...n(o),...ae[t]??[]].filter(l=>!Object.hasOwn(i,l)).sort()}return e},s=e=>[...h.values()].filter(t=>t.from===e).map(t=>t.name).sort();export const CAPABILITIES={reference:{library:"openpyxl",version:"3.1.5",docs:"https://openpyxl.readthedocs.io/"},holds:re(),functions:HELPERS,differs:["A workbook is a YAML file and the CSV files beside it: load_workbook(path) reads them, by the file or a folder's sheet.yaml, wb.save(path) writes them, and only what changed is written. This API does not read or write .xlsx: allyhub sheet import and allyhub render --type xlsx do.","A keyword argument of openpyxl's is a field of an object: new Font({ bold: true }), new Table({ displayName, ref }), new DefinedName(name, { attr_text }). Classes are made with new.","A name openpyxl has that is not held throws where it is used, naming what the class holds. ws['A1'], ws['A1:B2'], ws['A'], ws[1], wb['Sheet'], ws.tables['t'], wb.defined_names['n'], ws.column_dimensions['A'] and ws.row_dimensions[1] are held; in TypeScript ws['A1'] is typed as a Cell, so write ws['A1'].value = v (ws['A1'] = v works at run time), and wb.get_sheet_by_name(name) is typed where wb[name] is not.","Rows and columns count from 1, as openpyxl's. iter_rows, rows, columns and values give arrays, not generators.","A colour is #RRGGBB; RRGGBB and AARRGGBB are taken, the alpha left out. Theme colours are not held.","cell.value of a date is a Date (read in UTC), a formula's its text, and with load_workbook(path, { data_only: true }) what it computes to, which openpyxl reads from a file's cache and this computes.","column_dimensions' width is Excel's unit and row_dimensions' height points, as openpyxl's; the file holds pixels.","ws.merged_cells is an array of each merged range's text.","A table's rows are its CSV file, so ws.add_table(new Table({ displayName, ref })) moves the cells of ref there; its header row names its columns. A column whose every row has one formula, moved, is written as a calculated column.","A run of cells with one formula, moved, is written as one range key, and at least wb.block_cells typed cells together in a CSV file of their own (a block).","ws.title = 'New' renames the sheet in every formula, which openpyxl leaves to you.","ws.insert_rows, delete_rows, insert_cols and delete_cols rewrite every formula of the workbook as Excel does (a reference moves, a range grows or shrinks, one to what went is #REF!), move tables, blocks, merges and looks, and take rows and columns in or out of a table's CSV file. openpyxl moves cells and leaves formulas as they were. A table's header row is not deleted unless all of the table is.","A string that reads as another value (=, 12%, 2026-01-01) stays text, as openpyxl's does: its cell is written with a leading ' unless it starts with =, which makes it a formula.","A DataValidation refuses what breaks it and shows its prompt unless showErrorMessage or showInputMessage is false, as Excel's dialog starts: openpyxl's leave both off. A list's cell keeps its blank unless allow_blank is false.","ws.auto_filter.ref and add_filter_column say what a filter keeps, and the rows it leaves out are worked out from that, never written: a file made by openpyxl hides nothing until Excel reapplies it. A table has its own, table.autoFilter. add_sort_condition is not held: sorting is the rows of the files in order.","A chart reads its cells live, whatever else is in the file: there is no cache to refresh. chart.add_data and set_categories, and Series, take a Reference or a formula's text for a table's column or a spill, as add_data('orders[total]', { title: 'Total' }) or set_categories('orders[month]'), since a Reference cannot name one.","Series is made with new Series(values, { xvalues, title, title_from_data }); openpyxl's is the SeriesFactory function.","A chart's width and height are centimetres, as openpyxl's; the file holds pixels, and anchor a cell: ws.add_chart(chart, 'E2').","A LineChart's grouping is standard; a stacked area is an AreaChart. Chart styles are kept but draw nothing, as sheet.yaml has no place for them: chart.style is only read.","ws._charts lists a sheet's charts, those read from sheet.yaml among them, as the classes above.","In a rule, a fill's bgColor paints, or its fgColor where it has none. A rule's font holds bold, italic, underline, strike and a colour; alignment and number formats in a rule are not held.","workbook((wb, { data }) => { … }), the default export of the code a sheet's file names (code: ./forecast.ts), makes sheets with these classes, on a workbook of its own that starts with none. They are made again from the code wherever the workbook is read, never saved: wb.save throws there."],adds:a,formulas:{own:s("allyhub"),formulajs:s("formulajs")}};
2
+ import{publicNames as n}from"@allyhub/formats";import{FUNCTIONS as h}from"../calc/functions/index.js";import{AreaChart as p,BarChart as d,DataLabelList as m,DoughnutChart as c,GraphicalProperties as w,Legend as f,LineChart as u,LineProperties as y,Marker as g,NumericAxis as b,PieChart as k,Reference as _,ScatterChart as x,Scaling as C,Series as A,TextAxis as S}from"./charts.js";import{AutoFilter as v,ConditionalFormattingList as D,DataValidation as P,DataValidationList as F,DifferentialStyle as L,Rule as T}from"./rules.js";import{Alignment as R,Border as I,Color as N,Font as E,PatternFill as V,Protection as B,Side as W}from"./styles.js";import{Cell as j,ColumnDimension as M,DefinedName as G,DefinedNameDict as H,RowDimension as O,Table as U,TableList as z,Workbook as q,Worksheet as X}from"./workbook.js";import{Comment as Y,HeaderFooter as J,HeaderFooterPart as K,Image as Q,PageMargins as Z,PageSetup as $,SheetProtection as ee}from"./page.js";const a={Series:{title:"A series' name in words, openpyxl's SeriesFactory argument, kept here as a field."},Workbook:{open:"Workbook.open(path): a workbook read, by its file or a folder's sheet.yaml (load_workbook(path) is the same).",block_cells:"How many typed cells together go in a CSV file of their own: 100 unless set.",title:"The workbook's title, sheet.yaml's.",check:"wb.check(): what allyhub check would say of the workbook as it stands: a list of { file, line, message }."},Cell:{computed:"What the cell computes to, the workbook as it stands, saved or not."},Table:{key:"The column that lines rows up when two hands' changes merge."},DataValidation:{multiple:"A list's cell may hold several of its values, joined by separator: an .xlsx keeps them as text.",separator:"What joins a cell's choices: a comma and a space unless set."},PageSetup:{fitToWidth:"Pages wide; setting it or fitToHeight fits the sheet, with no pageSetUpPr to set."},ColumnDimension:{files:"Its cells name files, from the sheet's folder: true, or { separator, height }."}},te=["add_data","set_categories","append","title","legend","width","height","style","anchor","series","dataLabels","x_axis","y_axis"],oe={BarChart:["type","grouping","overlap","gapWidth","varyColors"],LineChart:["grouping"],AreaChart:["grouping"],PieChart:["varyColors"],DoughnutChart:["holeSize"],ScatterChart:[]},ae={Workbook:q.prototype,Worksheet:X.prototype,Cell:j.prototype,Font:E.prototype,PatternFill:V.prototype,Border:I.prototype,Side:W.prototype,Alignment:R.prototype,Protection:B.prototype,Color:N.prototype,Table:U.prototype,TableList:z.prototype,DefinedName:G.prototype,DefinedNameDict:H.prototype,ColumnDimension:M.prototype,RowDimension:O.prototype,ConditionalFormattingList:D.prototype,Rule:T.prototype,DifferentialStyle:L.prototype,DataValidation:P.prototype,DataValidationList:F.prototype,AutoFilter:v.prototype,BarChart:d.prototype,LineChart:u.prototype,AreaChart:p.prototype,PieChart:k.prototype,DoughnutChart:c.prototype,ScatterChart:x.prototype,Reference:_.prototype,Series:A.prototype,Legend:f.prototype,Scaling:C.prototype,TextAxis:S.prototype,NumericAxis:b.prototype,DataLabelList:m.prototype,Marker:g.prototype,GraphicalProperties:w.prototype,LineProperties:y.prototype,PageSetup:$.prototype,PageMargins:Z.prototype,_HeaderFooterItem:J.prototype,_HeaderFooterPart:K.prototype,SheetProtection:ee.prototype,Comment:Y.prototype,Image:Q.prototype},r=["title","scaling","majorUnit","number_format","delete","majorGridlines"],re={_HeaderFooterItem:["left","center","right"],Comment:["text","author"],Image:["path","width","height","anchor"],Workbook:["worksheets","defined_names","data_only","path","title","block_cells"],Cell:["row","column"],Worksheet:["min_row","min_column"],Font:["name","size","bold","italic","underline","strike","color"],PatternFill:["fill_type","fgColor","bgColor"],Border:["left","right","top","bottom"],Side:["style","color"],Alignment:["horizontal","vertical","wrap_text","shrink_to_fit","indent","text_rotation"],Protection:["locked","hidden"],Color:["rgb"],Table:["displayName","ref","key","autoFilter"],DefinedName:["name","attr_text"],ColumnDimension:["index"],RowDimension:["index"],Rule:["type","operator","formula","stopIfTrue","rank","percent","bottom","aboveAverage","equalAverage","text","dxf"],DifferentialStyle:["font","fill","border","numFmt"],DataValidation:["type","formula1","formula2","operator","allow_blank","showDropDown","showErrorMessage","showInputMessage","errorStyle","errorTitle","error","promptTitle","prompt","sqref"],DataValidationList:["dataValidation"],AutoFilter:["ref"],...Object.fromEntries(Object.entries(oe).map(([e,t])=>[e,[...te.filter(o=>!(/^(?:Pie|Doughnut)/u.test(e)&&o.endsWith("_axis"))),...t]])),Reference:["worksheet","min_col","min_row","max_col","max_row"],Series:["val","xVal","title","smooth","marker","graphicalProperties"],Legend:["position"],Scaling:["min","max","orientation"],TextAxis:r.filter(e=>e!=="majorUnit"),NumericAxis:r,DataLabelList:["showVal","showPercent","showCatName","showSerName","dLblPos"],Marker:["symbol","size"],GraphicalProperties:["solidFill","noFill","line"],LineProperties:["width","solidFill","noFill"]};export const HELPERS=["CellIsRule","ColorScaleRule","DataBarRule","FormulaRule","IconSetRule","column_index_from_string","coordinate_to_tuple","get_column_letter","range_boundaries"];const se=()=>{const e={};for(const[t,o]of Object.entries(ae)){const i=a[t]??{};e[t]=[...n(o),...re[t]??[]].filter(l=>!Object.hasOwn(i,l)).sort()}return e},s=e=>[...h.values()].filter(t=>t.from===e).map(t=>t.name).sort();export const CAPABILITIES={reference:{library:"openpyxl",version:"3.1.5",docs:"https://openpyxl.readthedocs.io/"},holds:se(),functions:HELPERS,differs:["A workbook is a YAML file and the CSV files beside it: load_workbook(path) reads them, by the file or a folder's sheet.yaml, wb.save(path) writes them, and only what changed is written. This API does not read or write .xlsx: allyhub sheet import and allyhub render --type xlsx do.","A keyword argument of openpyxl's is a field of an object: new Font({ bold: true }), new Table({ displayName, ref }), new DefinedName(name, { attr_text }). Classes are made with new.","A name openpyxl has that is not held throws where it is used, naming what the class holds. ws['A1'], ws['A1:B2'], ws['A'], ws[1], wb['Sheet'], ws.tables['t'], wb.defined_names['n'], ws.column_dimensions['A'] and ws.row_dimensions[1] are held; in TypeScript ws['A1'] is typed as a Cell, so write ws['A1'].value = v (ws['A1'] = v works at run time), and wb.get_sheet_by_name(name) is typed where wb[name] is not.","Rows and columns count from 1, as openpyxl's. iter_rows, rows, columns and values give arrays, not generators.","A colour is #RRGGBB; RRGGBB and AARRGGBB are taken, the alpha left out. Theme colours are not held.","cell.value of a date is a Date (read in UTC), a formula's its text, and with load_workbook(path, { data_only: true }) what it computes to, which openpyxl reads from a file's cache and this computes.","column_dimensions' width is Excel's unit and row_dimensions' height points, as openpyxl's; the file holds pixels.","ws.merged_cells is an array of each merged range's text.","A table's rows are its CSV file, so ws.add_table(new Table({ displayName, ref })) moves the cells of ref there; its header row names its columns. A column whose every row has one formula, moved, is written as a calculated column.","A run of cells with one formula, moved, is written as one range key, and at least wb.block_cells typed cells together in a CSV file of their own (a block).","ws.title = 'New' renames the sheet in every formula, which openpyxl leaves to you.","ws.insert_rows, delete_rows, insert_cols and delete_cols rewrite every formula of the workbook as Excel does (a reference moves, a range grows or shrinks, one to what went is #REF!), move tables, blocks, merges and looks, and take rows and columns in or out of a table's CSV file. openpyxl moves cells and leaves formulas as they were. A table's header row is not deleted unless all of the table is.","A string that reads as another value (=, 12%, 2026-01-01) stays text, as openpyxl's does: its cell is written with a leading ' unless it starts with =, which makes it a formula.","A DataValidation refuses what breaks it and shows its prompt unless showErrorMessage or showInputMessage is false, as Excel's dialog starts: openpyxl's leave both off. A list's cell keeps its blank unless allow_blank is false.","ws.auto_filter.ref and add_filter_column say what a filter keeps, and the rows it leaves out are worked out from that, never written: a file made by openpyxl hides nothing until Excel reapplies it. A table has its own, table.autoFilter. add_sort_condition is not held: sorting is the rows of the files in order.","A chart reads its cells live, whatever else is in the file: there is no cache to refresh. chart.add_data and set_categories, and Series, take a Reference or a formula's text for a table's column or a spill, as add_data('orders[total]', { title: 'Total' }) or set_categories('orders[month]'), since a Reference cannot name one.","Series is made with new Series(values, { xvalues, title, title_from_data }); openpyxl's is the SeriesFactory function.","A chart's width and height are centimetres, as openpyxl's; the file holds pixels, and anchor a cell: ws.add_chart(chart, 'E2').","A LineChart's grouping is standard; a stacked area is an AreaChart. Chart styles are kept but draw nothing, as sheet.yaml has no place for them: chart.style is only read.","ws._charts lists a sheet's charts, those read from sheet.yaml among them, as the classes above.","In a rule, a fill's bgColor paints, or its fgColor where it has none. A rule's font holds bold, italic, underline, strike and a colour; alignment and number formats in a rule are not held.","workbook((wb, { data }) => { … }), the default export of the code a sheet's file names (code: ./forecast.ts), makes sheets with these classes, on a workbook of its own that starts with none. They are made again from the code wherever the workbook is read, never saved: wb.save throws there."],adds:a,formulas:{own:s("allyhub"),formulajs:s("formulajs")}};
@@ -1,4 +1,4 @@
1
- export { Alignment, Border, Color, Font, PatternFill, Side, type AlignmentOptions, type BorderOptions, type FontOptions, type PatternFillOptions, type SideOptions, } from "./styles.js";
1
+ export { Alignment, Border, Color, Font, PatternFill, Protection, Side, type AlignmentOptions, type BorderOptions, type FontOptions, type PatternFillOptions, type ProtectionOptions, type SideOptions, } from "./styles.js";
2
2
  export { BLOCK_CELLS, Cell, ColumnDimension, DefinedName, DefinedNameDict, RowDimension, Table, TableList, Workbook, Worksheet, column_index_from_string, coordinate_to_tuple, get_column_letter, load_workbook, range_boundaries, type CellValue, type LoadOptions, type TableInput, type TableOptions, } from "./workbook.js";
3
3
  export { AutoFilter, CellIsRule, ColorScaleRule, ConditionalFormattingList, DataBarRule, DataValidation, DataValidationList, DifferentialStyle, FormulaRule, IconSetRule, Rule, type CellIsRuleOptions, type ColorScaleRuleOptions, type DataBarRuleOptions, type DataValidationOptions, type DifferentialStyleOptions, type FormulaRuleOptions, type RuleOptions, } from "./rules.js";
4
4
  export { AreaChart, BarChart, ChartBase, DataLabelList, DoughnutChart, GraphicalProperties, Legend, LineChart, LineProperties, Marker, NumericAxis, PieChart, Reference, ScatterChart, Scaling, Series, TextAxis, type BarChartOptions, type ChartData, type ReferenceOptions, type SeriesOptions, } from "./charts.js";
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- export{Alignment,Border,Color,Font,PatternFill,Side}from"./styles.js";export{BLOCK_CELLS,Cell,ColumnDimension,DefinedName,DefinedNameDict,RowDimension,Table,TableList,Workbook,Worksheet,column_index_from_string,coordinate_to_tuple,get_column_letter,load_workbook,range_boundaries}from"./workbook.js";export{AutoFilter,CellIsRule,ColorScaleRule,ConditionalFormattingList,DataBarRule,DataValidation,DataValidationList,DifferentialStyle,FormulaRule,IconSetRule,Rule}from"./rules.js";export{AreaChart,BarChart,ChartBase,DataLabelList,DoughnutChart,GraphicalProperties,Legend,LineChart,LineProperties,Marker,NumericAxis,PieChart,Reference,ScatterChart,Scaling,Series,TextAxis}from"./charts.js";export{CAPABILITIES,HELPERS}from"./capabilities.js";export{WORKBOOK_BRAND,isSheetCode,workbook}from"./code.js";export{Comment,HeaderFooter,Image,PageMargins,PageSetup,SheetProtection}from"./page.js";
2
+ export{Alignment,Border,Color,Font,PatternFill,Protection,Side}from"./styles.js";export{BLOCK_CELLS,Cell,ColumnDimension,DefinedName,DefinedNameDict,RowDimension,Table,TableList,Workbook,Worksheet,column_index_from_string,coordinate_to_tuple,get_column_letter,load_workbook,range_boundaries}from"./workbook.js";export{AutoFilter,CellIsRule,ColorScaleRule,ConditionalFormattingList,DataBarRule,DataValidation,DataValidationList,DifferentialStyle,FormulaRule,IconSetRule,Rule}from"./rules.js";export{AreaChart,BarChart,ChartBase,DataLabelList,DoughnutChart,GraphicalProperties,Legend,LineChart,LineProperties,Marker,NumericAxis,PieChart,Reference,ScatterChart,Scaling,Series,TextAxis}from"./charts.js";export{CAPABILITIES,HELPERS}from"./capabilities.js";export{WORKBOOK_BRAND,isSheetCode,workbook}from"./code.js";export{Comment,HeaderFooter,Image,PageMargins,PageSetup,SheetProtection}from"./page.js";
@@ -4,12 +4,21 @@ export interface DifferentialStyleOptions {
4
4
  font?: Font;
5
5
  fill?: PatternFill;
6
6
  border?: Border;
7
+ /** openpyxl's NumberFormat: its code is what the cell shows while the rule holds. */
8
+ numFmt?: {
9
+ formatCode: string;
10
+ numFmtId?: number;
11
+ };
7
12
  }
8
13
  /** What a rule that holds gives a cell. */
9
14
  export declare class DifferentialStyle {
10
15
  readonly font: Font | undefined;
11
16
  readonly fill: PatternFill | undefined;
12
17
  readonly border: Border | undefined;
18
+ readonly numFmt: {
19
+ formatCode: string;
20
+ numFmtId?: number;
21
+ } | undefined;
13
22
  constructor(o?: DifferentialStyleOptions);
14
23
  }
15
24
  export interface RuleOptions {
@@ -160,6 +169,21 @@ export declare class AutoFilter {
160
169
  _columns: Map<number, {
161
170
  values?: string[] | undefined;
162
171
  blanks?: boolean | undefined;
172
+ conditions?: {
173
+ operator: "equal" | "notEqual" | "greaterThan" | "greaterThanOrEqual" | "lessThan" | "lessThanOrEqual";
174
+ value: string | number;
175
+ }[] | undefined;
176
+ or?: boolean | undefined;
177
+ top?: {
178
+ count: number;
179
+ percent?: boolean | undefined;
180
+ bottom?: boolean | undefined;
181
+ } | undefined;
182
+ average?: "above" | "below" | undefined;
183
+ color?: {
184
+ fill?: string | undefined;
185
+ font?: string | undefined;
186
+ } | undefined;
163
187
  }>;
164
188
  private readonly touched;
165
189
  constructor(ref: string | undefined, touched: () => void);
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_ICONS as h,SHEET_OPERATORS as m,SHEET_VALIDATIONS as w,strict as u}from"@allyhub/formats";import{readArea as b,readAreas as T}from"../address.js";import{HINT as s}from"./hint.js";import{borderLook as _,colorText as d}from"./styles.js";function i(e,r,t){for(const o of Object.keys(r))if(!t.includes(o))throw new TypeError(`${e} takes ${t.join(", ")}; it has no ${o}. ${s}`)}function c(e){if(typeof e=="number")return e;const r=e.trim(),t=Number(r);if(r!==""&&!Number.isNaN(t))return t;const o=/^"((?:[^"]|"")*)"$/u.exec(r);return o?(o[1]??"").replaceAll('""','"'):r.startsWith("=")?r:`=${r}`}function y(e){if(e!==void 0)return typeof e=="number"?String(e):e.startsWith("=")?e.slice(1):`"${e.replaceAll('"','""')}"`}export class DifferentialStyle{font;fill;border;constructor(r={}){return i("DifferentialStyle",r,["font","fill","border"]),this.font=r.font,this.fill=r.fill,this.border=r.border,u(this,"DifferentialStyle",s)}}const x=e=>e?.bgColor?.rgb??e?.fgColor?.rgb;function k(e){const r={},{font:t,fill:o,border:a}=e??{};t?.bold===!0&&(r.bold=!0),t?.italic===!0&&(r.italic=!0),t?.strike===!0&&(r.strike=!0),t?.underline!==void 0&&(r.underline=!0),t?.color&&(r.color=t.color.rgb);const n=x(o);if(n!==void 0&&(r.fill=n),a){const{border:l}=_(a);l&&Object.keys(l).length>0&&(r.border=l)}return r}const I={">":"greaterThan",">=":"greaterThanOrEqual","<":"lessThan","<=":"lessThanOrEqual","=":"equal","==":"equal","!=":"notEqual"};export class Rule{type;operator;formula;stopIfTrue;rank;percent;bottom;aboveAverage;equalAverage;text;dxf;_spec;constructor(r,t){return i("Rule",r,["type","operator","formula","stopIfTrue","rank","percent","bottom","aboveAverage","equalAverage","text","dxf"]),this.type=r.type,this.operator=r.operator,this.formula=r.formula??[],this.stopIfTrue=r.stopIfTrue??!1,this.rank=r.rank,this.percent=r.percent??!1,this.bottom=r.bottom??!1,this.aboveAverage=r.aboveAverage??!0,this.equalAverage=r.equalAverage??!1,this.text=r.text,this.dxf=r.dxf,this._spec=t??S(r),u(this,"Rule",s)}}function S(e){const r=k(e.dxf),t=e.stopIfTrue===!0?{stop:!0}:{};switch(e.type){case"cellIs":{const o=I[e.operator??""]??e.operator;if(!m.includes(o))throw new TypeError(`${String(e.operator)} is not an operator: ${m.join(", ")}.`);return{type:"cellIs",operator:o,formula:(e.formula??[]).map(c),...r,...t}}case"expression":{const[o]=e.formula??[];if(o===void 0)throw new TypeError("An expression rule has a formula.");const a=String(o);return{type:"expression",formula:a.startsWith("=")?a:`=${a}`,...r,...t}}case"containsText":{if(e.text===void 0)throw new TypeError("A containsText rule has a text.");const o=e.operator===void 0||e.operator==="containsText"?{}:{operator:e.operator};return{type:"containsText",text:e.text,...o,...r,...t}}case"duplicateValues":case"uniqueValues":return{type:e.type,...r,...t};case"top10":return{type:"top10",rank:e.rank??10,...e.percent===!0?{percent:!0}:{},...e.bottom===!0?{bottom:!0}:{},...r,...t};case"aboveAverage":return{type:"aboveAverage",...e.aboveAverage===!1?{below:!0}:{},...e.equalAverage===!0?{equal:!0}:{},...r,...t};default:throw new TypeError(`A rule of type ${e.type} is made by ColorScaleRule, DataBarRule or IconSetRule.`)}}export function CellIsRule(e){return i("CellIsRule",e,["operator","formula","stopIfTrue","font","fill","border"]),new Rule({type:"cellIs",operator:e.operator,formula:e.formula,...e.stopIfTrue===void 0?{}:{stopIfTrue:e.stopIfTrue},dxf:new DifferentialStyle({...e.font?{font:e.font}:{},...e.fill?{fill:e.fill}:{},...e.border?{border:e.border}:{}})})}export function FormulaRule(e){return i("FormulaRule",e,["formula","stopIfTrue","font","fill","border"]),new Rule({type:"expression",formula:e.formula,...e.stopIfTrue===void 0?{}:{stopIfTrue:e.stopIfTrue},dxf:new DifferentialStyle({...e.font?{font:e.font}:{},...e.fill?{fill:e.fill}:{},...e.border?{border:e.border}:{}})})}function f(e,r,t){const o=e??t;return r===void 0?{at:o}:{at:o,value:c(r)}}export function ColorScaleRule(e){i("ColorScaleRule",e,["start_type","start_value","start_color","mid_type","mid_value","mid_color","end_type","end_value","end_color"]);const r=[{...f(e.start_type,e.start_value,"min"),color:d(e.start_color)},...e.mid_color===void 0?[]:[{...f(e.mid_type,e.mid_value,"percentile"),color:d(e.mid_color)}],{...f(e.end_type,e.end_value,"max"),color:d(e.end_color)}];return new Rule({type:"colorScale"},{type:"colorScale",stops:r})}export function DataBarRule(e){i("DataBarRule",e,["start_type","start_value","end_type","end_value","color","showValue"]);const r=f(e.start_type,e.start_value,"min"),t=f(e.end_type,e.end_value,"max");return new Rule({type:"dataBar"},{type:"dataBar",color:d(e.color),...r.at==="min"?{}:{min:r},...t.at==="max"?{}:{max:t},...e.showValue===!1?{show:!1}:{}})}export function IconSetRule(e,r,t,o,a,n){if(!h.includes(e))throw new TypeError(`${e} is not an icon set: ${h.join(", ")}.`);return new Rule({type:"iconSet"},{type:"iconSet",icons:e,stops:t.map(l=>f(r,l,"percent")),...o===!1?{show:!1}:{},...n===!0?{reverse:!0}:{}})}export class ConditionalFormattingList{_rules;touched;constructor(r,t){return this._rules=r,this.touched=t,u(this,"ConditionalFormattingList",s)}add(r,t){if(!T(r))throw new TypeError(`${r} is not a range.`);this._rules.push({...t._spec,range:r}),this.touched()}get max_priority(){return this._rules.length}}export class DataValidation{type;formula1;formula2;operator;allow_blank;showDropDown;showErrorMessage;showInputMessage;errorStyle;errorTitle;error;promptTitle;prompt;sqref;multiple;separator;constructor(r={}){i("DataValidation",r,["type","formula1","formula2","operator","allow_blank","allowBlank","showDropDown","showErrorMessage","showInputMessage","errorStyle","errorTitle","error","promptTitle","prompt","sqref","multiple","separator"]);const t=r.type??"custom";if(!w.includes(t))throw new TypeError(`${t} is not a validation: ${w.join(", ")}.`);return this.type=t,this.formula1=r.formula1,this.formula2=r.formula2,this.operator=r.operator,this.allow_blank=r.allow_blank??r.allowBlank,this.showDropDown=r.showDropDown??!1,this.showErrorMessage=r.showErrorMessage??!0,this.showInputMessage=r.showInputMessage??!0,this.errorStyle=r.errorStyle,this.errorTitle=r.errorTitle,this.error=r.error,this.promptTitle=r.promptTitle,this.prompt=r.prompt,this.sqref=r.sqref??"",this.multiple=r.multiple??!1,this.separator=r.separator,u(this,"DataValidation",s)}get allowBlank(){return this.allow_blank}get hide_drop_down(){return this.showDropDown}get validation_type(){return this.type}add(r){const t=typeof r=="string"?r:r.coordinate;if(!b(t))throw new TypeError(`${t} is not a range.`);this.sqref=this.sqref===""?t:`${this.sqref} ${t}`}}export function validationSpec(e){const r=e.formula1,t=e.type==="list"&&typeof r=="string"?/^"((?:[^"]|"")*)"$/u.exec(r.trim()):null,o=[r,e.formula2].flatMap(p=>p===void 0?[]:[c(p)]),a=p=>Object.fromEntries(Object.entries(p).filter(([,g])=>g!==void 0)),n=a({title:e.promptTitle,message:e.prompt,show:e.showInputMessage?void 0:!1}),l=a({style:e.errorStyle,title:e.errorTitle,message:e.error,show:e.showErrorMessage?void 0:!1});return{range:e.sqref,type:e.type,...e.operator===void 0?{}:{operator:e.operator},...t?{values:(t[1]??"").split(",")}:o.length>0?{formula:o}:{},...e.multiple?{multiple:!0}:{},...e.separator===void 0?{}:{separator:e.separator},...e.allow_blank===!1?{blank:!1}:{},...e.showDropDown?{dropdown:!1}:{},...Object.keys(n).length>0?{prompt:n}:{},...Object.keys(l).length>0?{error:l}:{}}}export function validationOf(e){const[r,t]=e.formula??[],o=e.values?`"${e.values.join(",")}"`:y(r),a={type:e.type,sqref:e.range,showDropDown:e.dropdown===!1,showErrorMessage:e.error?.show!==!1,showInputMessage:e.prompt?.show!==!1};o!==void 0&&(a.formula1=o);const n=y(t);return n!==void 0&&(a.formula2=n),e.operator!==void 0&&(a.operator=e.operator),e.blank===!1&&(a.allow_blank=!1),e.error?.style!==void 0&&(a.errorStyle=e.error.style),e.error?.title!==void 0&&(a.errorTitle=e.error.title),e.error?.message!==void 0&&(a.error=e.error.message),e.prompt?.title!==void 0&&(a.promptTitle=e.prompt.title),e.prompt?.message!==void 0&&(a.prompt=e.prompt.message),e.multiple===!0&&(a.multiple=!0),e.separator!==void 0&&(a.separator=e.separator),new DataValidation(a)}export class DataValidationList{dataValidation;touched;constructor(r,t){return this.dataValidation=r,this.touched=t,u(this,"DataValidationList",s)}append(r){this.dataValidation.push(r),this.touched()}get count(){return this.dataValidation.length}}export class AutoFilter{ref;_columns=new Map;touched;constructor(r,t){return this.ref=r,this.touched=t,u(this,"AutoFilter",s)}add_filter_column(r,t,o=!1){this._columns.set(r,{...t.length===0?{}:{values:[...t]},...o?{blanks:!0}:{}}),this.touched()}}
2
+ import{SHEET_ICONS as h,SHEET_OPERATORS as m,SHEET_VALIDATIONS as w,strict as f}from"@allyhub/formats";import{readArea as b,readAreas as T}from"../address.js";import{HINT as i}from"./hint.js";import{borderLook as _,colorText as d}from"./styles.js";function u(e,t,r){for(const o of Object.keys(t))if(!r.includes(o))throw new TypeError(`${e} takes ${r.join(", ")}; it has no ${o}. ${i}`)}function c(e){if(typeof e=="number")return e;const t=e.trim(),r=Number(t);if(t!==""&&!Number.isNaN(r))return r;const o=/^"((?:[^"]|"")*)"$/u.exec(t);return o?(o[1]??"").replaceAll('""','"'):t.startsWith("=")?t:`=${t}`}function y(e){if(e!==void 0)return typeof e=="number"?String(e):e.startsWith("=")?e.slice(1):`"${e.replaceAll('"','""')}"`}export class DifferentialStyle{font;fill;border;numFmt;constructor(t={}){return u("DifferentialStyle",t,["font","fill","border","numFmt"]),this.font=t.font,this.fill=t.fill,this.border=t.border,this.numFmt=t.numFmt,f(this,"DifferentialStyle",i)}}const x=e=>e?.bgColor?.rgb??e?.fgColor?.rgb;function k(e){const t={},{font:r,fill:o,border:a,numFmt:n}=e??{};n!==void 0&&n.formatCode!=="General"&&(t.format=n.formatCode),r?.bold===!0&&(t.bold=!0),r?.italic===!0&&(t.italic=!0),r?.strike===!0&&(t.strike=!0),r?.underline!==void 0&&(t.underline=!0),r?.color&&(t.color=r.color.rgb);const s=x(o);if(s!==void 0&&(t.fill=s),a){const{border:l}=_(a);l&&Object.keys(l).length>0&&(t.border=l)}return t}const I={">":"greaterThan",">=":"greaterThanOrEqual","<":"lessThan","<=":"lessThanOrEqual","=":"equal","==":"equal","!=":"notEqual"};export class Rule{type;operator;formula;stopIfTrue;rank;percent;bottom;aboveAverage;equalAverage;text;dxf;_spec;constructor(t,r){return u("Rule",t,["type","operator","formula","stopIfTrue","rank","percent","bottom","aboveAverage","equalAverage","text","dxf"]),this.type=t.type,this.operator=t.operator,this.formula=t.formula??[],this.stopIfTrue=t.stopIfTrue??!1,this.rank=t.rank,this.percent=t.percent??!1,this.bottom=t.bottom??!1,this.aboveAverage=t.aboveAverage??!0,this.equalAverage=t.equalAverage??!1,this.text=t.text,this.dxf=t.dxf,this._spec=r??S(t),f(this,"Rule",i)}}function S(e){const t=k(e.dxf),r=e.stopIfTrue===!0?{stop:!0}:{};switch(e.type){case"cellIs":{const o=I[e.operator??""]??e.operator;if(!m.includes(o))throw new TypeError(`${String(e.operator)} is not an operator: ${m.join(", ")}.`);return{type:"cellIs",operator:o,formula:(e.formula??[]).map(c),...t,...r}}case"expression":{const[o]=e.formula??[];if(o===void 0)throw new TypeError("An expression rule has a formula.");const a=String(o);return{type:"expression",formula:a.startsWith("=")?a:`=${a}`,...t,...r}}case"containsText":{if(e.text===void 0)throw new TypeError("A containsText rule has a text.");const o=e.operator===void 0||e.operator==="containsText"?{}:{operator:e.operator};return{type:"containsText",text:e.text,...o,...t,...r}}case"duplicateValues":case"uniqueValues":return{type:e.type,...t,...r};case"top10":return{type:"top10",rank:e.rank??10,...e.percent===!0?{percent:!0}:{},...e.bottom===!0?{bottom:!0}:{},...t,...r};case"aboveAverage":return{type:"aboveAverage",...e.aboveAverage===!1?{below:!0}:{},...e.equalAverage===!0?{equal:!0}:{},...t,...r};default:throw new TypeError(`A rule of type ${e.type} is made by ColorScaleRule, DataBarRule or IconSetRule.`)}}export function CellIsRule(e){return u("CellIsRule",e,["operator","formula","stopIfTrue","font","fill","border"]),new Rule({type:"cellIs",operator:e.operator,formula:e.formula,...e.stopIfTrue===void 0?{}:{stopIfTrue:e.stopIfTrue},dxf:new DifferentialStyle({...e.font?{font:e.font}:{},...e.fill?{fill:e.fill}:{},...e.border?{border:e.border}:{}})})}export function FormulaRule(e){return u("FormulaRule",e,["formula","stopIfTrue","font","fill","border"]),new Rule({type:"expression",formula:e.formula,...e.stopIfTrue===void 0?{}:{stopIfTrue:e.stopIfTrue},dxf:new DifferentialStyle({...e.font?{font:e.font}:{},...e.fill?{fill:e.fill}:{},...e.border?{border:e.border}:{}})})}function p(e,t,r){const o=e??r;return t===void 0?{at:o}:{at:o,value:c(t)}}export function ColorScaleRule(e){u("ColorScaleRule",e,["start_type","start_value","start_color","mid_type","mid_value","mid_color","end_type","end_value","end_color"]);const t=[{...p(e.start_type,e.start_value,"min"),color:d(e.start_color)},...e.mid_color===void 0?[]:[{...p(e.mid_type,e.mid_value,"percentile"),color:d(e.mid_color)}],{...p(e.end_type,e.end_value,"max"),color:d(e.end_color)}];return new Rule({type:"colorScale"},{type:"colorScale",stops:t})}export function DataBarRule(e){u("DataBarRule",e,["start_type","start_value","end_type","end_value","color","showValue"]);const t=p(e.start_type,e.start_value,"min"),r=p(e.end_type,e.end_value,"max");return new Rule({type:"dataBar"},{type:"dataBar",color:d(e.color),...t.at==="min"?{}:{min:t},...r.at==="max"?{}:{max:r},...e.showValue===!1?{show:!1}:{}})}export function IconSetRule(e,t,r,o,a,n){if(!h.includes(e))throw new TypeError(`${e} is not an icon set: ${h.join(", ")}.`);return new Rule({type:"iconSet"},{type:"iconSet",icons:e,stops:r.map(s=>p(t,s,"percent")),...o===!1?{show:!1}:{},...n===!0?{reverse:!0}:{}})}export class ConditionalFormattingList{_rules;touched;constructor(t,r){return this._rules=t,this.touched=r,f(this,"ConditionalFormattingList",i)}add(t,r){if(!T(t))throw new TypeError(`${t} is not a range.`);this._rules.push({...r._spec,range:t}),this.touched()}get max_priority(){return this._rules.length}}export class DataValidation{type;formula1;formula2;operator;allow_blank;showDropDown;showErrorMessage;showInputMessage;errorStyle;errorTitle;error;promptTitle;prompt;sqref;multiple;separator;constructor(t={}){u("DataValidation",t,["type","formula1","formula2","operator","allow_blank","allowBlank","showDropDown","showErrorMessage","showInputMessage","errorStyle","errorTitle","error","promptTitle","prompt","sqref","multiple","separator"]);const r=t.type??"custom";if(!w.includes(r))throw new TypeError(`${r} is not a validation: ${w.join(", ")}.`);return this.type=r,this.formula1=t.formula1,this.formula2=t.formula2,this.operator=t.operator,this.allow_blank=t.allow_blank??t.allowBlank,this.showDropDown=t.showDropDown??!1,this.showErrorMessage=t.showErrorMessage??!0,this.showInputMessage=t.showInputMessage??!0,this.errorStyle=t.errorStyle,this.errorTitle=t.errorTitle,this.error=t.error,this.promptTitle=t.promptTitle,this.prompt=t.prompt,this.sqref=t.sqref??"",this.multiple=t.multiple??!1,this.separator=t.separator,f(this,"DataValidation",i)}get allowBlank(){return this.allow_blank}get hide_drop_down(){return this.showDropDown}get validation_type(){return this.type}add(t){const r=typeof t=="string"?t:t.coordinate;if(!b(r))throw new TypeError(`${r} is not a range.`);this.sqref=this.sqref===""?r:`${this.sqref} ${r}`}}export function validationSpec(e){const t=e.formula1,r=e.type==="list"&&typeof t=="string"?/^"((?:[^"]|"")*)"$/u.exec(t.trim()):null,o=[t,e.formula2].flatMap(l=>l===void 0?[]:[c(l)]),a=l=>Object.fromEntries(Object.entries(l).filter(([,g])=>g!==void 0)),n=a({title:e.promptTitle,message:e.prompt,show:e.showInputMessage?void 0:!1}),s=a({style:e.errorStyle,title:e.errorTitle,message:e.error,show:e.showErrorMessage?void 0:!1});return{range:e.sqref,type:e.type,...e.operator===void 0?{}:{operator:e.operator},...r?{values:(r[1]??"").split(",")}:o.length>0?{formula:o}:{},...e.multiple?{multiple:!0}:{},...e.separator===void 0?{}:{separator:e.separator},...e.allow_blank===!1?{blank:!1}:{},...e.showDropDown?{dropdown:!1}:{},...Object.keys(n).length>0?{prompt:n}:{},...Object.keys(s).length>0?{error:s}:{}}}export function validationOf(e){const[t,r]=e.formula??[],o=e.values?`"${e.values.join(",")}"`:y(t),a={type:e.type,sqref:e.range,showDropDown:e.dropdown===!1,showErrorMessage:e.error?.show!==!1,showInputMessage:e.prompt?.show!==!1};o!==void 0&&(a.formula1=o);const n=y(r);return n!==void 0&&(a.formula2=n),e.operator!==void 0&&(a.operator=e.operator),e.blank===!1&&(a.allow_blank=!1),e.error?.style!==void 0&&(a.errorStyle=e.error.style),e.error?.title!==void 0&&(a.errorTitle=e.error.title),e.error?.message!==void 0&&(a.error=e.error.message),e.prompt?.title!==void 0&&(a.promptTitle=e.prompt.title),e.prompt?.message!==void 0&&(a.prompt=e.prompt.message),e.multiple===!0&&(a.multiple=!0),e.separator!==void 0&&(a.separator=e.separator),new DataValidation(a)}export class DataValidationList{dataValidation;touched;constructor(t,r){return this.dataValidation=t,this.touched=r,f(this,"DataValidationList",i)}append(t){this.dataValidation.push(t),this.touched()}get count(){return this.dataValidation.length}}export class AutoFilter{ref;_columns=new Map;touched;constructor(t,r){return this.ref=t,this.touched=r,f(this,"AutoFilter",i)}add_filter_column(t,r,o=!1){this._columns.set(t,{...r.length===0?{}:{values:[...r]},...o?{blanks:!0}:{}}),this.touched()}}
@@ -103,15 +103,27 @@ export declare class Alignment {
103
103
  get shrinkToFit(): boolean | undefined;
104
104
  get textRotation(): number;
105
105
  }
106
+ export interface ProtectionOptions {
107
+ locked?: boolean;
108
+ hidden?: boolean;
109
+ }
110
+ /** Format Cells › Protection: what a protected sheet lets change and shows. */
111
+ export declare class Protection {
112
+ readonly locked: boolean;
113
+ readonly hidden: boolean;
114
+ constructor(o?: ProtectionOptions);
115
+ }
106
116
  /** A style object as the look fields it sets. */
107
117
  export declare const fontLook: (f: Font) => CellLook;
108
118
  export declare function fillLook(f: PatternFill): CellLook;
109
119
  export declare function borderLook(b: Border): CellLook;
110
120
  export declare const alignmentLook: (a: Alignment) => CellLook;
121
+ export declare const protectionLook: (p: Protection) => CellLook;
111
122
  /** The style objects a look reads back as. */
112
123
  export declare const fontOf: (l: CellLook) => Font;
113
124
  export declare function fillOf(l: CellLook): PatternFill;
114
125
  export declare const borderOf: (l: CellLook) => Border;
126
+ export declare const protectionOf: (l: CellLook) => Protection;
115
127
  export declare const alignmentOf: (l: CellLook) => Alignment;
116
128
  export {};
117
129
  //# sourceMappingURL=styles.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{SHEET_ALIGNS as f,SHEET_BORDERS as u,SHEET_PATTERNS as h,SHEET_VALIGNS as p,strict as l}from"@allyhub/formats";import{HINT as i}from"./hint.js";function s(t,e,n){for(const r of Object.keys(e))if(!n.includes(r))throw new TypeError(`${t} takes ${n.join(", ")}; it has no ${r}. ${i}`)}export function colorText(t){if(t instanceof Color)return t.rgb;const e=t.replace(/^#/u,"");if(!/^(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/u.test(e))throw new TypeError(`${t} is not a colour: RRGGBB or AARRGGBB.`);return`#${e.slice(-6).toUpperCase()}`}export class Color{rgb;constructor(e){return this.rgb=colorText(typeof e=="string"?e:e.rgb),l(this,"Color",i)}}const d=t=>t===void 0?void 0:new Color(colorText(t));export class Font{name;size;bold;italic;underline;strike;color;constructor(e={}){return s("Font",e,["name","size","sz","bold","b","italic","i","underline","u","strike","color"]),this.name=e.name,this.size=e.size??e.sz,this.bold=e.bold??e.b??!1,this.italic=e.italic??e.i??!1,this.underline=e.underline??e.u,this.strike=e.strike??!1,this.color=d(e.color),l(this,"Font",i)}get b(){return this.bold}get i(){return this.italic}get sz(){return this.size}get u(){return this.underline}}export class PatternFill{fill_type;fgColor;bgColor;constructor(e={},n={}){const r=typeof e=="string"?{...n,fill_type:e}:e;s("PatternFill",r,["fill_type","patternType","fgColor","bgColor","start_color","end_color"]);const o=r.fill_type??r.patternType;if(o!==void 0&&!h.includes(o))throw new TypeError(`${o} is not a fill: ${h.join(", ")}.`);return this.fill_type=o,this.fgColor=d(r.fgColor??r.start_color),this.bgColor=d(r.bgColor??r.end_color),l(this,"PatternFill",i)}get patternType(){return this.fill_type}get start_color(){return this.fgColor}get end_color(){return this.bgColor}}export class Side{style;color;constructor(e={}){s("Side",e,["style","border_style","color"]);const n=e.style??e.border_style;if(n!==void 0&&!u.includes(n))throw new TypeError(`${n} is not a border: ${u.join(", ")}.`);return this.style=n,this.color=d(e.color),l(this,"Side",i)}get border_style(){return this.style}}export class Border{left;right;top;bottom;constructor(e={}){return s("Border",e,["left","right","top","bottom"]),this.left=e.left??new Side,this.right=e.right??new Side,this.top=e.top??new Side,this.bottom=e.bottom??new Side,l(this,"Border",i)}}export class Alignment{horizontal;vertical;wrap_text;shrink_to_fit;indent;text_rotation;constructor(e={}){if(s("Alignment",e,["horizontal","vertical","wrap_text","wrapText","shrink_to_fit","shrinkToFit","indent","text_rotation","textRotation"]),e.horizontal!==void 0&&!f.includes(e.horizontal))throw new TypeError(`${e.horizontal} is not an alignment: ${f.join(", ")}.`);if(e.vertical!==void 0&&!p.includes(e.vertical))throw new TypeError(`${e.vertical} is not an alignment: ${p.join(", ")}.`);return this.horizontal=e.horizontal,this.vertical=e.vertical,this.wrap_text=e.wrap_text??e.wrapText,this.shrink_to_fit=e.shrink_to_fit??e.shrinkToFit,this.indent=e.indent??0,this.text_rotation=e.text_rotation??e.textRotation??0,l(this,"Alignment",i)}get wrapText(){return this.wrap_text}get shrinkToFit(){return this.shrink_to_fit}get textRotation(){return this.text_rotation}}const c=t=>t.style===void 0?void 0:{style:t.style,...t.color?{color:t.color.rgb}:{}};export const fontLook=t=>({bold:t.bold,italic:t.italic,strike:t.strike,underline:t.underline??!1,...t.name===void 0?{}:{font:t.name},...t.size===void 0?{}:{size:t.size},...t.color?{color:t.color.rgb}:{}});export function fillLook(t){return t.fill_type===void 0?{}:t.fill_type==="solid"&&!t.bgColor&&t.fgColor?{fill:t.fgColor.rgb}:{fill:{pattern:t.fill_type,...t.fgColor?{color:t.fgColor.rgb}:{},...t.bgColor?{background:t.bgColor.rgb}:{}}}}export function borderLook(t){const e=c(t.left),n=c(t.right),r=c(t.top),o=c(t.bottom);return{border:{...e?{left:e}:{},...n?{right:n}:{},...r?{top:r}:{},...o?{bottom:o}:{}}}}export const alignmentLook=t=>({...t.horizontal===void 0?{}:{align:t.horizontal},...t.vertical===void 0?{}:{valign:t.vertical},...t.wrap_text===void 0?{}:{wrap:t.wrap_text},...t.shrink_to_fit===void 0?{}:{shrink:t.shrink_to_fit},...t.indent===0?{}:{indent:t.indent},...t.text_rotation===0?{}:{rotation:t.text_rotation}}),fontOf=t=>new Font({...t.font===void 0?{}:{name:t.font},...t.size===void 0?{}:{size:t.size},bold:t.bold??!1,italic:t.italic??!1,strike:t.strike??!1,...typeof t.underline=="string"?{underline:t.underline}:t.underline===!0?{underline:"single"}:{},...t.color===void 0?{}:{color:t.color}});export function fillOf(t){const{fill:e}=t;return e===void 0?new PatternFill:typeof e=="string"?new PatternFill({fill_type:"solid",fgColor:e}):new PatternFill({fill_type:e.pattern,...e.color===void 0?{}:{fgColor:e.color},...e.background===void 0?{}:{bgColor:e.background}})}const a=t=>t===void 0?new Side:new Side({style:t.style,...t.color===void 0?{}:{color:t.color}});export const borderOf=t=>new Border({left:a(t.border?.left),right:a(t.border?.right),top:a(t.border?.top),bottom:a(t.border?.bottom)}),alignmentOf=t=>new Alignment({...t.align===void 0?{}:{horizontal:t.align},...t.valign===void 0?{}:{vertical:t.valign},...t.wrap===void 0?{}:{wrap_text:t.wrap},...t.shrink===void 0?{}:{shrink_to_fit:t.shrink},...t.indent===void 0?{}:{indent:t.indent},...t.rotation===void 0?{}:{text_rotation:t.rotation}});
2
+ import{SHEET_ALIGNS as f,SHEET_BORDERS as u,SHEET_PATTERNS as h,SHEET_VALIGNS as p,strict as l}from"@allyhub/formats";import{HINT as n}from"./hint.js";function s(t,e,o){for(const r of Object.keys(e))if(!o.includes(r))throw new TypeError(`${t} takes ${o.join(", ")}; it has no ${r}. ${n}`)}export function colorText(t){if(t instanceof Color)return t.rgb;const e=t.replace(/^#/u,"");if(!/^(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/u.test(e))throw new TypeError(`${t} is not a colour: RRGGBB or AARRGGBB.`);return`#${e.slice(-6).toUpperCase()}`}export class Color{rgb;constructor(e){return this.rgb=colorText(typeof e=="string"?e:e.rgb),l(this,"Color",n)}}const d=t=>t===void 0?void 0:new Color(colorText(t));export class Font{name;size;bold;italic;underline;strike;color;constructor(e={}){return s("Font",e,["name","size","sz","bold","b","italic","i","underline","u","strike","color"]),this.name=e.name,this.size=e.size??e.sz,this.bold=e.bold??e.b??!1,this.italic=e.italic??e.i??!1,this.underline=e.underline??e.u,this.strike=e.strike??!1,this.color=d(e.color),l(this,"Font",n)}get b(){return this.bold}get i(){return this.italic}get sz(){return this.size}get u(){return this.underline}}export class PatternFill{fill_type;fgColor;bgColor;constructor(e={},o={}){const r=typeof e=="string"?{...o,fill_type:e}:e;s("PatternFill",r,["fill_type","patternType","fgColor","bgColor","start_color","end_color"]);const i=r.fill_type??r.patternType;if(i!==void 0&&!h.includes(i))throw new TypeError(`${i} is not a fill: ${h.join(", ")}.`);return this.fill_type=i,this.fgColor=d(r.fgColor??r.start_color),this.bgColor=d(r.bgColor??r.end_color),l(this,"PatternFill",n)}get patternType(){return this.fill_type}get start_color(){return this.fgColor}get end_color(){return this.bgColor}}export class Side{style;color;constructor(e={}){s("Side",e,["style","border_style","color"]);const o=e.style??e.border_style;if(o!==void 0&&!u.includes(o))throw new TypeError(`${o} is not a border: ${u.join(", ")}.`);return this.style=o,this.color=d(e.color),l(this,"Side",n)}get border_style(){return this.style}}export class Border{left;right;top;bottom;constructor(e={}){return s("Border",e,["left","right","top","bottom"]),this.left=e.left??new Side,this.right=e.right??new Side,this.top=e.top??new Side,this.bottom=e.bottom??new Side,l(this,"Border",n)}}export class Alignment{horizontal;vertical;wrap_text;shrink_to_fit;indent;text_rotation;constructor(e={}){if(s("Alignment",e,["horizontal","vertical","wrap_text","wrapText","shrink_to_fit","shrinkToFit","indent","text_rotation","textRotation"]),e.horizontal!==void 0&&!f.includes(e.horizontal))throw new TypeError(`${e.horizontal} is not an alignment: ${f.join(", ")}.`);if(e.vertical!==void 0&&!p.includes(e.vertical))throw new TypeError(`${e.vertical} is not an alignment: ${p.join(", ")}.`);return this.horizontal=e.horizontal,this.vertical=e.vertical,this.wrap_text=e.wrap_text??e.wrapText,this.shrink_to_fit=e.shrink_to_fit??e.shrinkToFit,this.indent=e.indent??0,this.text_rotation=e.text_rotation??e.textRotation??0,l(this,"Alignment",n)}get wrapText(){return this.wrap_text}get shrinkToFit(){return this.shrink_to_fit}get textRotation(){return this.text_rotation}}export class Protection{locked;hidden;constructor(e={}){return s("Protection",e,["locked","hidden"]),this.locked=e.locked??!0,this.hidden=e.hidden??!1,l(this,"Protection",n)}}const c=t=>t.style===void 0?void 0:{style:t.style,...t.color?{color:t.color.rgb}:{}};export const fontLook=t=>({bold:t.bold,italic:t.italic,strike:t.strike,underline:t.underline??!1,...t.name===void 0?{}:{font:t.name},...t.size===void 0?{}:{size:t.size},...t.color?{color:t.color.rgb}:{}});export function fillLook(t){return t.fill_type===void 0?{}:t.fill_type==="solid"&&!t.bgColor&&t.fgColor?{fill:t.fgColor.rgb}:{fill:{pattern:t.fill_type,...t.fgColor?{color:t.fgColor.rgb}:{},...t.bgColor?{background:t.bgColor.rgb}:{}}}}export function borderLook(t){const e=c(t.left),o=c(t.right),r=c(t.top),i=c(t.bottom);return{border:{...e?{left:e}:{},...o?{right:o}:{},...r?{top:r}:{},...i?{bottom:i}:{}}}}export const alignmentLook=t=>({...t.horizontal===void 0?{}:{align:t.horizontal},...t.vertical===void 0?{}:{valign:t.vertical},...t.wrap_text===void 0?{}:{wrap:t.wrap_text},...t.shrink_to_fit===void 0?{}:{shrink:t.shrink_to_fit},...t.indent===0?{}:{indent:t.indent},...t.text_rotation===0?{}:{rotation:t.text_rotation}}),protectionLook=t=>({locked:t.locked?void 0:!1,hide_formula:t.hidden?!0:void 0}),fontOf=t=>new Font({...t.font===void 0?{}:{name:t.font},...t.size===void 0?{}:{size:t.size},bold:t.bold??!1,italic:t.italic??!1,strike:t.strike??!1,...typeof t.underline=="string"?{underline:t.underline}:t.underline===!0?{underline:"single"}:{},...t.color===void 0?{}:{color:t.color}});export function fillOf(t){const{fill:e}=t;return e===void 0?new PatternFill:typeof e=="string"?new PatternFill({fill_type:"solid",fgColor:e}):new PatternFill({fill_type:e.pattern,...e.color===void 0?{}:{fgColor:e.color},...e.background===void 0?{}:{bgColor:e.background}})}const a=t=>t===void 0?new Side:new Side({style:t.style,...t.color===void 0?{}:{color:t.color}});export const borderOf=t=>new Border({left:a(t.border?.left),right:a(t.border?.right),top:a(t.border?.top),bottom:a(t.border?.bottom)}),protectionOf=t=>new Protection({locked:t.locked!==!1,hidden:t.hide_formula===!0}),alignmentOf=t=>new Alignment({...t.align===void 0?{}:{horizontal:t.align},...t.valign===void 0?{}:{vertical:t.valign},...t.wrap===void 0?{}:{wrap_text:t.wrap},...t.shrink===void 0?{}:{shrink_to_fit:t.shrink},...t.indent===void 0?{}:{indent:t.indent},...t.rotation===void 0?{}:{text_rotation:t.rotation}});
@@ -9,7 +9,7 @@ import { type Scalar } from "../values.js";
9
9
  import { type CellLook, type Workbook as Model, type Worksheet as ModelSheet } from "../workbook.js";
10
10
  import { type ChartBase } from "./charts.js";
11
11
  import { AutoFilter, ConditionalFormattingList, DataValidationList, type DataValidation } from "./rules.js";
12
- import { Alignment, Border, Font, PatternFill } from "./styles.js";
12
+ import { Alignment, Border, Font, PatternFill, Protection } from "./styles.js";
13
13
  export type CellValue = number | string | boolean | Date | null;
14
14
  /** A typed cell in rows and columns of at least this many cells goes in a CSV file. */
15
15
  export declare const BLOCK_CELLS = 100;
@@ -54,6 +54,8 @@ export declare class Cell {
54
54
  set border(border: Border);
55
55
  get alignment(): Alignment;
56
56
  set alignment(alignment: Alignment);
57
+ get protection(): Protection;
58
+ set protection(protection: Protection);
57
59
  get has_style(): boolean;
58
60
  offset(row?: number, column?: number): Cell;
59
61
  }
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{strict as g}from"@allyhub/formats";import{Comment as z,HeaderFooter as A,PageMargins as G,PageSetup as V,SheetProtection as Y}from"./page.js";import{columnIndex as C,columnLetter as N,cellName as E,contains as F,rangeName as x,readAddress as y,readArea as k}from"../address.js";import{Calc as q}from"../calc/engine.js";import{checkWorkbook as Q}from"../check.js";import{readCsv as X,writeCsv as Z}from"@allyhub/formats";import{GENERATED as ee}from"../generated.js";import"@allyhub/formats";import{moveFormula as te,relativeKey as se}from"../formula/move.js";import{parseFormula as M}from"../formula/parse.js";import{printFormula as B}from"../formula/print.js";import{rewriteFormula as ne}from"../formula/rewrite.js";import{isDateCode as S}from"../format.js";import{patchCsv as oe}from"../patch.js";import{CellError as W,dateOfSerial as ie,isoOfSerial as re,readTyped as j,serialOfDate as le,writeTyped as ae}from"../values.js";import{FormulaCell as he,readWorkbook as I,validName as K}from"../workbook.js";import{restructure as fe,tableShape as ce}from"../structure.js";import{patchYaml as _e}from"../write.js";import{anchorOf as ue,chartOfSpec as de}from"./charts.js";import{HINT as w}from"./hint.js";import{rectangles as T}from"./rectangles.js";import{AutoFilter as J,ConditionalFormattingList as me,DataValidationList as pe,validationOf as we,validationSpec as ge}from"./rules.js";import{alignmentLook as ke,alignmentOf as ye,borderLook as be,borderOf as ve,fillLook as xe,fillOf as $e,fontLook as Ce,fontOf as Se}from"./styles.js";const R=()=>process.getBuiltinModule("node:fs"),O=(...l)=>process.getBuiltinModule("node:path").join(...l);function H(l){if(!/\.ya?ml$/iu.test(l))throw new TypeError(`${l} is not a sheet's file: a workbook is its YAML file, wb.save('finance/budget.yaml'), load_workbook('finance/budget.yaml').`);return l}export const BLOCK_CELLS=100;const Ee=l=>Math.round(l*7+5),Te=l=>(l-5)/7,Oe=l=>l*4/3,Le=l=>l*3/4;function Ne(l,e){const t={},s=l,n=e;for(const o of new Set([...Object.keys(s),...Object.keys(n)])){const i=n[o];JSON.stringify(i??!1)!==JSON.stringify(s[o]??!1)&&(t[o]=i??!1)}return t}const p=l=>Object.keys(l).length===0,b=(l,e)=>{if(!Number.isInteger(l)||l<1)throw new RangeError(`A ${e} is a whole number from 1: ${String(l)}.`);return l},D=(l,e)=>Object.fromEntries(Object.entries(l).filter(([t])=>t!==e));export class Cell{row;column;_ws;_value;_formula=void 0;_look;_changed=!1;_styled=!1;_fresh=!1;constructor(e,t,s){this._ws=e,this.row=t,this.column=s;const n=t-1,o=s-1,i=e._model?.at(n,o);return this._value=null,i instanceof he?this._formula=i.text:i!==void 0&&(this._value=i),this._look=e._model?.lookAt(n,o)??{},this._fresh=i===void 0,g(this,"Cell",w)}get parent(){return this._ws}get coordinate(){return E({row:this.row-1,col:this.column-1})}get column_letter(){return N(this.column-1)}get col_idx(){return this.column}get value(){return this._ws.parent.data_only?this.computed:this._formula!==void 0?this._formula:this._shown(this._value)}set value(e){if(e===void 0)throw new TypeError(`${this.coordinate}: a value is not undefined.`);if(this._formula=void 0,this._changed=!0,this._ws.parent._pending=!0,e instanceof Date){if(Number.isNaN(e.getTime()))throw new TypeError(`${this.coordinate}: the date is not valid.`);this._value=le(e),S(this._look.format)||(this._look={...this._look,format:Number.isInteger(this._value)?"yyyy-mm-dd":"yyyy-mm-dd hh:mm"});return}if(typeof e=="string"&&e.length>1&&e.startsWith("=")){this._formula=e,this._value=null;return}this._value=e}_shown(e){return typeof e=="number"&&S(this._look.format)?ie(e)??e:e instanceof W?e.code:e}get computed(){const{calc:e,model:t}=this._ws.parent._computed(),s=t.sheet(this._ws.title);return s?this._shown(e.value(s,this.row-1,this.column-1)):null}get data_type(){if(this._formula!==void 0)return"f";const e=this._value;return e===null?"n":typeof e=="number"?S(this._look.format)?"d":"n":typeof e=="boolean"?"b":e instanceof W?"e":"s"}get is_date(){return this.data_type==="d"}get hyperlink(){return this._ws._links[this.coordinate]}set hyperlink(e){e===void 0?Reflect.deleteProperty(this._ws._links,this.coordinate):this._ws._links[this.coordinate]=e,this._ws._changed()}get comment(){const e=this._ws._notes[this.coordinate];if(e!==void 0)return typeof e=="string"?new z(e):new z(e.text,e.author)}set comment(e){e===void 0?Reflect.deleteProperty(this._ws._notes,this.coordinate):this._ws._notes[this.coordinate]=e._file(),this._ws._changed()}get number_format(){return this._look.format??"General"}set number_format(e){this._setLook({format:e})}_setLook(e){this._look={...this._look,...e},this._styled=!0,this._ws.parent._pending=!0}get font(){return Se(this._look)}set font(e){this._setLook(Ce(e))}get fill(){return $e(this._look)}set fill(e){this._setLook(xe(e))}get border(){return ve(this._look)}set border(e){this._setLook(be(e))}get alignment(){return ye(this._look)}set alignment(e){this._setLook(ke(e))}get has_style(){return!p(this._look)}offset(e=0,t=0){return this._ws.cell(this.row+e,this.column+t)}}export class ColumnDimension{index;_width;_hidden;_files;_level;_ws;constructor(e,t){this._ws=e,this.index=t;const s=e._spec()?.columns?.[t];return this._level=s?.level,this._width=s?.width,this._hidden=s?.hidden,this._files=s?.files,g(this,"ColumnDimension",w)}get outlineLevel(){return this._level}set outlineLevel(e){this._level=e,this._ws._dimensions=!0}get files(){return this._files}set files(e){this._files=e,this._ws._dimensions=!0}get width(){return this._width===void 0?void 0:Te(this._width)}set width(e){this._width=e===void 0?void 0:Ee(e),this._ws._dimensions=!0}get hidden(){return this._hidden??!1}set hidden(e){this._hidden=e,this._ws._dimensions=!0}}export class RowDimension{index;_height;_hidden;_level;_ws;constructor(e,t){this._ws=e,this.index=t;const s=e._spec()?.rows?.[String(t)];return this._level=s?.level,this._height=s?.height,this._hidden=s?.hidden,g(this,"RowDimension",w)}get outlineLevel(){return this._level}set outlineLevel(e){this._level=e,this._ws._dimensions=!0}get height(){return this._height===void 0?void 0:Le(this._height)}set height(e){this._height=e===void 0?void 0:Oe(e),this._ws._dimensions=!0}get hidden(){return this._hidden??!1}set hidden(e){this._hidden=e,this._ws._dimensions=!0}}export class Table{displayName;ref;key;_spec;autoFilter;constructor(e){for(const t of Object.keys(e))if(!["displayName","ref","key"].includes(t))throw new TypeError(`Table takes displayName, ref and key; it has no ${t}. ${w}`);if(!K(e.displayName))throw new TypeError(`${e.displayName} cannot be a table's name.`);if(!k(e.ref))throw new TypeError(`${e.ref} is not a range.`);return this.displayName=e.displayName,this.ref=e.ref,this.key=e.key,this.autoFilter=new J(e.ref,()=>{}),g(this,"Table",w)}get name(){return this.displayName}}export class TableList{_items=new Map;constructor(){return g(this,"TableList",w,{key:e=>this._items.get(e)})}add(e){this._items.set(e.name,e)}get(e){return this._items.get(e)}keys(){return[...this._items.keys()]}values(){return[...this._items.values()]}items(){return[...this._items.entries()]}pop(e){const t=this._items.get(e);return this._items.delete(e),t}}export class DefinedName{name;attr_text;constructor(e,t){if(!K(e))throw new TypeError(`${e} cannot be a name.`);return this.name=e,this.attr_text=t.attr_text.replace(/^=/u,""),g(this,"DefinedName",w)}get value(){return this.attr_text}set value(e){this.attr_text=e.replace(/^=/u,"")}}export class DefinedNameDict{_items=new Map;constructor(){return g(this,"DefinedNameDict",w,{key:e=>this._items.get(e),setKey:(e,t)=>t instanceof DefinedName?(this._items.set(e,t),!0):!1})}add(e){this._items.set(e.name,e)}get(e){return this._items.get(e)}keys(){return[...this._items.keys()]}values(){return[...this._items.values()]}items(){return[...this._items.entries()]}pop(e){const t=this._items.get(e);return this._items.delete(e),t}}const v=l=>{if(l._formula!==void 0)return l._formula;const e=l._value;return typeof e=="number"&&S(l._look.format)?re(e):ae(e)};function U(l){if(l._formula!==void 0)return l._formula;const e=l._value;return e===null?null:typeof e=="number"&&!S(l._look.format)||typeof e=="boolean"?e:v(l)}const Fe=l=>l.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows";export class Worksheet{_parent;_title;_was;_model;_cells=new Map;_columns=new Map;_rows=new Map;_tables=new TableList;_freeze;_merges=[];_state="visible";_dimensions=!1;_lastRow=0;_rules=[];_validations=[];_filter;_charts=[];_print={};_links={};_notes={};_pictures=[];_protect=!1;constructor(e,t,s){if(this._parent=e,this._title=t,this._filter=new J(void 0,()=>{this._parent._pending=!0}),s){this._model=s,this._was=t,this._freeze=s.spec.freeze,this._heldPage(s.spec),this._merges=[...s.spec.merges??[]],this._state=s.spec.hidden===!0?"hidden":"visible",this._lastRow=(s.used?.bottom??-1)+1,this._heldRules(s.spec);for(const n of s.tables){const o=new Table({displayName:n.name,ref:x(n.area),...n.spec.key===void 0?{}:{key:n.spec.key}});o._spec=n.spec;const{filter:i}=n.spec;if(i)for(const[a,h]of Object.entries(i.columns)){const d=n.column(a);d&&o.autoFilter._columns.set(d.index,h)}this._tables.add(o)}}return g(this,"Worksheet",w,{index:n=>this._rowCells(n),key:n=>this._at(n),setKey:(n,o)=>{const i=y(n);return i?(this.cell(i.row+1,i.col+1).value=o,!0):!1}})}_spec(){return this._parent._file.sheets.find(e=>e.name===(this._was??this._title))}_heldRules(e){this._rules=[...e?.conditional??[]],this._validations=(e?.validations??[]).map(we),this._charts=(e?.charts??[]).map(de),this._filter.ref=e?.filter?.range,this._filter._columns.clear();const t=e?.filter?k(e.filter.range):void 0;for(const[s,n]of Object.entries(e?.filter?.columns??{})){const o=C(s);t&&o!==void 0&&this._filter._columns.set(o-t.left,n)}}_at(e){const t=y(e);if(t)return this.cell(t.row+1,t.col+1);const s=k(e);if(s)return this._area(s);const n=C(e);if(n!==void 0){const o=[];for(let i=1;i<=this.max_row;i++)o.push(this.cell(i,n+1));return o}}_rowCells(e){const t=[];for(let s=1;s<=this.max_column;s++)t.push(this.cell(e,s));return t}_area(e){const t=[];for(let s=e.top;s<=e.bottom;s++){const n=[];for(let o=e.left;o<=e.right;o++)n.push(this.cell(s+1,o+1));t.push(n)}return t}get parent(){return this._parent}get title(){return this._title}set title(e){const t=this._title;e!==t&&this._parent._renameSheet(this,t,e)}get sheet_state(){return this._state}set sheet_state(e){this._state=e}cell(e,t,s){if(e<1||t<1)throw new RangeError(`Row and column values must be at least 1: ${String(e)}, ${String(t)}.`);const n=(e-1)*16384+t-1;let o=this._cells.get(n);return o||(o=new Cell(this,e,t),this._cells.set(n,o)),s!==void 0&&(o.value=s),e>this._lastRow&&(this._lastRow=e),o}append(e){const t=this._lastRow+1,s=(n,o)=>{o!=null&&this.cell(t,n,o)};if(Array.isArray(e))e.forEach((n,o)=>{s(o+1,n)});else for(const[n,o]of Object.entries(e)){const i=/^\d+$/u.test(n)?Number(n)-1:C(n);if(i===void 0)throw new TypeError(`${n} is not a column.`);s(i+1,o)}this._lastRow=t}get max_row(){return Math.max(1,this._lastRow)}get max_column(){let e=this._model?.columnsUsed??0;for(const t of this._cells.values())(t._value!==null||t._formula!==void 0)&&t.column>e&&(e=t.column);return Math.max(1,e)}min_row=1;min_column=1;get dimensions(){return x({top:0,left:0,bottom:this.max_row-1,right:this.max_column-1})}iter_rows(e={}){const t=this._area({top:(e.min_row??1)-1,left:(e.min_col??1)-1,bottom:(e.max_row??this.max_row)-1,right:(e.max_col??this.max_column)-1});return e.values_only===!0?t.map(s=>s.map(n=>n.value)):t}iter_cols(e={}){const t=this.iter_rows(e);return(t[0]??[]).map((n,o)=>t.map(i=>i[o]))}get rows(){return this.iter_rows()}get columns(){return this.iter_cols()}get values(){return this.iter_rows({values_only:!0})}insert_rows(e,t=1){this._parent._restructure({op:"insert-rows",sheet:this._title,at:b(e,"row")-1,count:b(t,"amount")})}delete_rows(e,t=1){this._parent._restructure({op:"delete-rows",sheet:this._title,at:b(e,"row")-1,count:b(t,"amount")})}insert_cols(e,t=1){this._parent._restructure({op:"insert-columns",sheet:this._title,at:b(e,"column")-1,count:b(t,"amount")})}delete_cols(e,t=1){this._parent._restructure({op:"delete-columns",sheet:this._title,at:b(e,"column")-1,count:b(t,"amount")})}merge_cells(e){if(!k(e))throw new TypeError(`${e} is not a range.`);this._merges.includes(e)||this._merges.push(e),this._parent._pending=!0}unmerge_cells(e){this._merges=this._merges.filter(t=>t!==e),this._parent._pending=!0}get merged_cells(){return[...this._merges]}get freeze_panes(){return this._freeze}set freeze_panes(e){const t=e instanceof Cell?e.coordinate:e;if(t!==void 0&&!y(t))throw new TypeError(`${t} is not a cell.`);this._freeze=t,this._parent._pending=!0}get column_dimensions(){return new Proxy({},{get:(e,t)=>{if(typeof t!="string")return;const s=t.toUpperCase();if(C(s)===void 0)throw new TypeError(`${t} is not a column.`);let n=this._columns.get(s);return n||(n=new ColumnDimension(this,s),this._columns.set(s,n)),n}})}get row_dimensions(){return new Proxy({},{get:(e,t)=>{if(typeof t!="string"||!/^[1-9]\d*$/u.test(t))throw new TypeError(`${String(t)} is not a row.`);const s=Number(t);let n=this._rows.get(s);return n||(n=new RowDimension(this,s),this._rows.set(s,n)),n}})}get tables(){return this._tables}get conditional_formatting(){return new me(this._rules,()=>{this._parent._pending=!0})}get data_validations(){return new pe(this._validations,()=>{this._parent._pending=!0})}add_data_validation(e){this._validations.push(e),this._parent._pending=!0}get auto_filter(){return this._filter}_changed(){this._parent._pending=!0}_heldPage(e){this._print=structuredClone(e?.print??{}),this._links={...e?.links},this._notes={...e?.notes},this._pictures=[...e?.pictures??[]],this._protect=e?.protect===!0}get page_setup(){return new V(this)}get page_margins(){return new G(this)}get oddHeader(){return new A(this,"header")}get oddFooter(){return new A(this,"footer")}get protection(){return new Y(()=>this._protect,e=>{this._protect=e,this._changed()})}get print_area(){return this._print.area}set print_area(e){if(e===void 0)delete this._print.area;else if(k(e))this._print.area=e;else throw new TypeError(`${e} is not a range.`);this._changed()}get print_title_rows(){return this._print.title_rows}set print_title_rows(e){e===void 0?delete this._print.title_rows:this._print.title_rows=e,this._changed()}get print_title_cols(){return this._print.title_cols}set print_title_cols(e){e===void 0?delete this._print.title_cols:this._print.title_cols=e,this._changed()}add_image(e,t){const s=t??e.anchor??"A1";if(!y(s))throw new TypeError(`${s} is not a cell.`);this._pictures.push({file:e.path,at:s,...e.width===void 0?{}:{width:e.width},...e.height===void 0?{}:{height:e.height}}),this._changed()}add_chart(e,t){e.anchor=ue(t)??e.anchor,this._charts.push(e),this._parent._pending=!0}add_table(e){if(this._parent._tableNamed(e.name))throw new Error(`There is already a table named ${e.name}.`);this._tables.add(e),this._parent._pending=!0}}export class Workbook{worksheets=[];defined_names=new DefinedNameDict;data_only;title;path;block_cells=BLOCK_CELLS;_file={sheets:[]};_text="";_disk={text:"",csv:new Map};_csv=new Map;_model;_names=new Map;_active=0;_pending=!1;_making=!1;_calc=void 0;constructor(e={}){this.data_only=e.data_only??!1;const t=g(this,"Workbook",w,{key:s=>this.worksheets.find(n=>n.title===s),index:s=>this.worksheets[s]});return t.worksheets=[new Worksheet(t,"Sheet")],t}static open(e,t={}){const s=new Workbook(t);return s.path=H(e),s._read(s.path),s}_read(e){const{readFileSync:t}=R(),s=t(e,"utf8"),n=process.getBuiltinModule("node:path").dirname(e),o=new Map,i=a=>{try{const h=t(O(n,a),"utf8");return o.set(a,h),h}catch{return}};this._load(s,i);for(const[a,h]of o)this._keepCsv(a,h);this._disk={text:s,csv:o}}_keepCsv(e,t){const s=X(t);this._csv.set(e,{parsed:s,rows:s.records.map(n=>n.end===n.start?[]:[...n.fields])})}_load(e,t){const{workbook:s,problems:n}=I({text:e,read:t});if(!s)throw new Error(`The workbook cannot be opened: ${n.map(o=>o.message).join("; ")}`);this._text=e,this._file=structuredClone(s.file),this._model=s,this.title=s.title,this.worksheets=s.sheets.map(o=>new Worksheet(this,o.name,o));for(const o of s.names.values()){if(o.source.path?.[0]!=="names")continue;const i=o.formula?o.formula.text:o.value??null;this._names.set(o.name,i),this.defined_names.add(new DefinedName(o.name,{attr_text:String(i)}))}}get active(){const e=this.worksheets[this._active]??this.worksheets[0];if(!e)throw new Error("The workbook has no sheets.");return e}set active(e){this._active=this.worksheets.indexOf(e)}get sheetnames(){return this.worksheets.map(e=>e.title)}get_sheet_by_name(e){return this.worksheets.find(t=>t.title===e)}index(e){return this.worksheets.indexOf(e)}create_sheet(e,t){let s=e??"Sheet";for(let o=1;this.worksheets.some(i=>i.title===s);o++)s=`${e??"Sheet"}${String(o)}`;const n=new Worksheet(this,s);return this.worksheets.splice(t??this.worksheets.length,0,n),this._pending=!0,n}remove(e){this.worksheets=this.worksheets.filter(t=>t!==e),this._pending=!0}move_sheet(e,t=0){const s=this.worksheets.indexOf(e);this.worksheets.splice(s,1),this.worksheets.splice(s+t,0,e),this._pending=!0}_tableNamed(e){for(const t of this.worksheets){const s=t._tables.get(e);if(s)return s}}_renameSheet(e,t,s){if(this.worksheets.some(o=>o!==e&&o.title===s))throw new Error(`There is already a sheet named ${s}.`);this._apply(),this._rewrite({op:"rename-sheet",from:t,to:s}),e._title=s,e._was=s;const n=this._file.sheets.find(o=>o.name===t);n&&(n.name=s),this._apply()}_restructure(e){this._apply();const t=fe({file:this._file,rows:new Map([...this._csv].map(([n,o])=>[n,o.rows]))},e);if(t.refused!==void 0)throw new Error(t.refused==="table-header"?"A table's header row is not deleted: delete the table's rows, or all of it.":"That sheet is not there.");this._file=t.file;for(const[n,o]of t.rows){const i=this._csv.get(n);i&&(i.rows=o.map(a=>[...a]))}for(const n of this.worksheets){const o=this._file.sheets.find(i=>i.name===n._title);n._cells.clear(),n._columns.clear(),n._rows.clear(),n._merges=[...o?.merges??[]],n._freeze=o?.freeze,n._heldPage(o),n._heldRules(o)}const s=this._build();this._rebase(s.text,s.files);for(const n of this.worksheets){const o=this._model?.sheet(n._title);if(o){n._lastRow=(o.used?.bottom??-1)+1;for(const i of o.tables){const a=n._tables.get(i.name);a&&(a.ref=x(i.area))}}}}_rewrite(e){const t=(n,o)=>{const i=M(n);if(!i.ok)return n;const a=ne(i.node,e,o);return a===i.node?n:B(a)},{_file:s}=this;if(s.names){for(const[n,o]of Object.entries(s.names))if(typeof o=="string"&&o.startsWith("=")){const i=t(o,s.sheets[0]?.name??"");s.names[n]=i,this._names.set(n,i);const a=this.defined_names.get(n);a&&(a.attr_text=i.slice(1))}}for(const n of s.checks??[])n.formula=t(n.formula,s.sheets[0]?.name??"");for(const n of s.sheets){for(const[o,i]of Object.entries(n.cells??{}))typeof i=="string"&&i.startsWith("=")?n.cells[o]=t(i,n.name):i!==null&&typeof i=="object"&&i.formula!==void 0&&(i.formula=t(i.formula,n.name));for(const o of n.tables??[]){for(const i of Object.values(o.columns??{}))i.formula!==void 0&&(i.formula=t(i.formula,n.name));this._rewriteCsv(o.rows,n.name,t)}for(const o of n.blocks??[])this._rewriteCsv(o.rows,n.name,t)}}_rewriteCsv(e,t,s){const n=this._csv.get(e);n&&(n.rows=n.rows.map(o=>o.map(i=>j(i).formula!==void 0?s(i,t):i)))}_sheetEntry(e){const t=e._was??e._title;let s=this._file.sheets.find(n=>n.name===t);return s||(s={name:e._title},this._file.sheets.push(s)),s.name=e._title,s}_dataPath(e){const t=Fe(e);let s=`${t}.csv`;const n=this.path===void 0?void 0:process.getBuiltinModule("node:path").dirname(this.path),o=i=>this._csv.has(i)||this._file.sheets.some(a=>a.tables?.some(h=>h.rows===i)??a.blocks?.some(h=>h.rows===i))||n!==void 0&&R().existsSync(O(n,i));for(let i=2;o(s);i++)s=`${t}-${String(i)}.csv`;return s}_writeNewTable(e,t,s){const n=k(s.ref);if(!n)throw new Error(`${s.ref} is not a range.`);const o=[];for(let r=n.left;r<=n.right;r++){const c=e.cell(n.top+1,r+1).value;if(c===null||c==="")throw new Error(`Table ${s.name}'s header has no name at ${E({row:n.top,col:r})}.`);o.push(String(c))}const i={},a=[];o.forEach((r,c)=>{const f=n.left+c,_=this._columnFormula(e,n,f);_===void 0?a.push(c):i[r]={formula:_};const m=this._columnFormat(e,n,f);m!==void 0&&(i[r]={...i[r],format:m})}),this._columnsStyled(e,n);const h=[a.map(r=>o[r]??"")];for(let r=n.top+1;r<=n.bottom;r++)h.push(a.map(c=>v(e.cell(r+1,n.left+c+1))));t.cells&&(t.cells=Object.fromEntries(Object.entries(t.cells).filter(([r])=>{const c=y(r);return!c||!F(n,c.row,c.col)})));const d=this._dataPath(s.name);this._csv.set(d,{parsed:void 0,rows:h});const u={name:s.name,at:E({row:n.top,col:n.left}),rows:d,...s.key===void 0?{}:{key:s.key},...p(i)?{}:{columns:i}};(t.tables??=[]).push(u),s._spec=u}_columnsStyled(e,t){for(let s=t.left;s<=t.right;s++)for(let n=t.top+1;n<=t.bottom;n++){const o=e.cell(n+1,s+1),{format:i,...a}=this._ownLook(o);i!==void 0&&p(a)&&(o._styled=!1)}}_columnFormula(e,t,s){if(t.bottom<=t.top)return;const n=e.cell(t.top+2,s+1),o=P(n);if(o!==void 0){for(let i=t.top+2;i<=t.bottom;i++)if(P(e.cell(i+1,s+1))!==o)return;return n._formula}}_columnFormat(e,t,s){if(t.bottom<=t.top)return;const n=i=>this._ownLook(e.cell(i+1,s+1)).format,o=n(t.top+1);for(let i=t.top+2;i<=t.bottom;i++)if(n(i)!==o)return;return o}_held(e){const t=this._csv.get(e);if(!t)throw new Error(`${e} was not read.`);return t}_setCsvCell(e,t,s,n){const{rows:o}=this._held(e);for(;o.length<=t;)o.push([]);const i=o[t];if(i){for(;i.length<=s;)i.push("");i[s]=n}}_recordOf(e,t){let s=0;for(let n=0;n<t;){if(s+=1,s>=e.length)return s+t-n-1;e[s]?.length!==0&&(n+=1)}return s}_writeTableCell(e,t,s){const n=this._held(e.rows),o=n.rows[0]??[],i=s.column-1-t.left,a=this._recordOf(n.rows,s.row-1-t.top),h=Object.keys(e.columns??{}).filter(f=>!o.some(_=>_.trim().toLowerCase()===f.toLowerCase())),u=[...o.map(f=>f.trim()),...h][i];if(u===void 0)return;if(a===0){i<o.length&&(o[i]=v(s));return}const r=e.columns?.[u]?.formula;if(r!==void 0){const f=this._movedColumn(r,t,s);if(s._formula===f){const _=o.findIndex(m=>m.trim()===u);_>=0&&this._setCsvCell(e.rows,a,_,"");return}}let c=o.findIndex(f=>f.trim()===u);c<0&&(c=o.length,this._setCsvCell(e.rows,0,c,u)),this._setCsvCell(e.rows,a,c,v(s))}_movedColumn(e,t,s){const n=M(e);if(!n.ok)return e;const o=s.row-1-(t.top+1);return o===0?e:B(te(n.node,o,0))}_apply(){this.title===void 0?delete this._file.title:this._file.title=this.title;const e=new Set(this.worksheets.map(s=>s._was??s._title));this._file.sheets=this._file.sheets.filter(s=>e.has(s.name));for(const s of this.worksheets)this._applySheet(s);this._file.sheets=this.worksheets.map(s=>this._sheetEntry(s)),this._applyNames();const t=this._build();this._rebase(t.text,t.files)}_applyNames(){const e={};for(const t of this.defined_names.values()){const s=j(t.attr_text),n=this._names.get(t.name);e[t.name]=n!==void 0&&String(n).replace(/^=/u,"")===t.attr_text?n:typeof s.value=="number"||typeof s.value=="boolean"?s.value:/^"[^"]*"$/u.test(t.attr_text)?t.attr_text.slice(1,-1):`=${t.attr_text}`}p(e)?delete this._file.names:this._file.names=e}_applySheet(e){const t=this._sheetEntry(e);e._freeze===void 0?delete t.freeze:t.freeze=e._freeze,p(e._print)?delete t.print:t.print=e._print,p(e._links)?delete t.links:t.links=e._links,p(e._notes)?delete t.notes:t.notes=e._notes,e._pictures.length===0?delete t.pictures:t.pictures=e._pictures,e._protect?t.protect=!0:delete t.protect,e._merges.length===0?delete t.merges:t.merges=[...e._merges],e._state==="hidden"?t.hidden=!0:delete t.hidden,e._rules.length===0?delete t.conditional:t.conditional=[...e._rules],e._validations.length===0?delete t.validations:t.validations=e._validations.map(ge),e._charts.length===0?delete t.charts:t.charts=e._charts.map(n=>n._spec(e._title)),this._applyFilter(e,t);const s=new Set(t.tables?.map(n=>n.name.toLowerCase()));for(const n of e._tables.values())s.has(n.name.toLowerCase())||this._writeNewTable(e,t,n);this._applyTableFilters(e,t),this._applyCells(e,t),this._applyDimensions(e,t),t.cells&&p(t.cells)&&delete t.cells,t.columns&&p(t.columns)&&delete t.columns,t.rows&&p(t.rows)&&delete t.rows,t.format?.length===0&&delete t.format,t.tables?.length===0&&delete t.tables,t.blocks?.length===0&&delete t.blocks}_applyFilter(e,t){const{ref:s,_columns:n}=e._filter;if(s===void 0){delete t.filter;return}const o=k(s);if(!o)throw new TypeError(`${s} is not a range.`);const i={};for(const[a,h]of n)i[N(o.left+a)]=h;t.filter={range:s,...p(i)?{}:{columns:i}}}_applyTableFilters(e,t){for(const s of t.tables??[]){const n=e._tables.get(s.name);if(!n||n.autoFilter._columns.size===0)continue;const o=this._csv.get(s.rows)?.rows??[],i=ce(s,o)?.names??[],a={};for(const[h,d]of n.autoFilter._columns){const u=i[h];if(u===void 0)throw new RangeError(`Table ${s.name} has no column at ${String(h)}.`);a[u]=d}s.filter={columns:a}}}_applyDimensions(e,t){if(e._dimensions){for(const[s,n]of e._columns){const o={...t.columns?.[s]};n._width===void 0?delete o.width:o.width=n._width,n._hidden===void 0?delete o.hidden:o.hidden=n._hidden,n._files===void 0?delete o.files:o.files=n._files,n._level===void 0?delete o.level:o.level=n._level;const i=D(t.columns??{},s);t.columns=p(o)?i:{...i,[s]:o}}for(const[s,n]of e._rows){const o={...t.rows?.[String(s)]};n._height===void 0?delete o.height:o.height=n._height,n._hidden===void 0?delete o.hidden:o.hidden=n._hidden,n._level===void 0?delete o.level:o.level=n._level;const i=D(t.rows??{},String(s));t.rows=p(o)?i:{...i,[String(s)]:o}}e._dimensions=!1}}_applyCells(e,t){const s=(t.tables??[]).flatMap(i=>{const a=y(i.at),h=e._tables.get(i.name),d=h?k(h.ref):void 0;return a&&d?[{entry:i,area:d}]:[]}),n=(t.blocks??[]).flatMap(i=>{const a=e._model?.blocks.find(h=>h.file===i.rows);return a?[{entry:i,area:a.area}]:[]}),o=[];for(const i of e._cells.values()){if(!i._changed&&!i._styled)continue;const a=i.row-1,h=i.column-1,d=s.find(r=>F(r.area,a,h)),u=n.find(r=>F(r.area,a,h));d?(i._changed&&this._writeTableCell(d.entry,d.area,i),i._styled&&this._styleByFormat(t,i)):u?(i._changed&&this._setCsvCell(u.entry.rows,a-u.area.top,h-u.area.left,v(i)),i._styled&&this._styleByFormat(t,i)):i._fresh&&!e._model?.keys.has(a*16384+h)?o.push(i):this._writeLoose(e,t,i),i._changed=!1,i._styled=!1}this._consolidate(e,t,o),Me(t)}_styleByFormat(e,t){(e.format??=[]).push({range:t.coordinate,...this._ownLook(t)})}_ownLook(e){const t=e._ws._model?.lookAt(e.row-1,e.column-1)??{},s=Ne(t,e._look);return s.format!==void 0&&e._formula===void 0&&j(v(e)).format===s.format&&delete s.format,s}_writeLoose(e,t,s){const n=s.coordinate,o=t.cells??={},i=U(s),a=this._ownLook(s),h=o[n],u={...h!==null&&typeof h=="object"?Object.fromEntries(Object.entries(h).filter(([f])=>f!=="value"&&f!=="formula"&&f!=="name")):{},...a},r=h!==null&&typeof h=="object"&&h.name!==void 0?{name:h.name}:{},c=e._model?.at(s.row-1,s.column-1)!==void 0;if(i===null&&p(u)&&!c){t.cells=D(o,n);return}o[n]=p(u)&&p(r)?i:{...typeof i=="string"&&i.startsWith("=")?{formula:i}:i===null?{}:{value:i},...r,...u}}_consolidate(e,t,s){const n=s.filter(r=>r._value!==null||r._formula!==void 0),o=new Map;for(const r of s){const c=this._ownLook(r);if(p(c))continue;const f=JSON.stringify(c),_=o.get(f);_?_.push(r):o.set(f,[r])}const i=new Map(n.map(r=>[`${String(r.row)}:${String(r.column)}`,r])),a=r=>i.get(`${String(r.row+1)}:${String(r.col+1)}`)??e.cell(r.row+1,r.col+1),h=new Map,d=[];for(const r of n){const c={row:r.row-1,col:r.column-1},f=r._formula===void 0?void 0:P(r);if(f===void 0){d.push(c);continue}const _=h.get(f);_?_.push(c):h.set(f,[c])}const u=t.cells??={};for(const r of h.values())for(const c of T(r))u[x(c)]=a({row:c.top,col:c.left})._formula??null;for(const r of T(d))if((r.bottom-r.top+1)*(r.right-r.left+1)>=this.block_cells){const f=[];for(let m=r.top;m<=r.bottom;m++){const $=[];for(let L=r.left;L<=r.right;L++)$.push(v(a({row:m,col:L})));f.push($)}const _=this._dataPath(e._title);this._csv.set(_,{parsed:void 0,rows:f}),(t.blocks??=[]).push({at:E({row:r.top,col:r.left}),rows:_})}else for(let f=r.top;f<=r.bottom;f++)for(let _=r.left;_<=r.right;_++){const m=a({row:f,col:_});u[m.coordinate]=U(m)}for(const r of o.values()){const[c]=r;if(!c)continue;const f=this._ownLook(c),_=r.map(m=>({row:m.row-1,col:m.column-1}));for(const m of T(_))(t.format??=[]).push({range:x(m),...f})}}_build(){const e=new Map;for(const[t,s]of this._csv)e.set(t,s.parsed?oe(s.parsed,s.rows):Z(s.rows));return{text:_e(this._text,this._file),files:e}}_rebase(e,t){const{workbook:s,problems:n}=I({text:e,read:o=>t.get(o)});if(!s)throw new Error(`The workbook is not one: ${n.map(o=>o.message).join("; ")}`);this._text=e,this._file=structuredClone(s.file),this._model=s;for(const[o,i]of t)this._keepCsv(o,i);this._calc=void 0,this._pending=!1;for(const o of this.worksheets){o._was=o._title;const i=s.sheet(o._title);i&&(o._model=i);for(const a of o._cells.values())a._fresh=i?.at(a.row-1,a.column-1)===void 0}this._names=new Map;for(const o of s.names.values())o.source.path?.[0]==="names"&&this._names.set(o.name,o.formula?o.formula.text:o.value??null)}_computed(){const e=[...this.defined_names.values()];if((this._pending||e.length!==this._names.size||e.some(t=>String(this._names.get(t.name)).replace(/^=/u,"")!==t.attr_text))&&this._apply(),!this._calc){const t=this._model;if(!t)throw new Error("The workbook has no sheets.");this._calc={calc:new q(t).calculate(),model:t}}return this._calc}check(){this._apply();const{text:e,files:t}=this._build();return Q({text:e,read:s=>t.get(s)}).problems}_generated(){if(this.worksheets.length===0)return this._applyNames(),{sheets:[],csv:{},...this._file.names?{names:this._file.names}:{}};this._apply();const e=structuredClone(this._file.sheets),t=n=>`${ee}${n}`;for(const n of e){for(const o of n.tables??[])o.rows=t(o.rows);for(const o of n.blocks??[])o.rows=t(o.rows)}const s={};for(const[n,o]of this._build().files)s[t(n)]=o;return{sheets:e,csv:s,...this._file.names?{names:this._file.names}:{}}}save(e){if(this._making)throw new Error("A sheet's code makes sheets and saves nothing: what it adds to wb is what it makes.");const t=e===void 0?this.path:H(e);if(t===void 0)throw new TypeError("A new workbook is saved to a file: wb.save('finance/budget.yaml').");if(this.worksheets.length===0)throw new Error("A workbook has at least one sheet.");const{text:s,csv:n}=this._disk;this._apply();const o=new Set(this._file.sheets.flatMap(f=>[...(f.tables??[]).map(_=>_.rows),...(f.blocks??[]).map(_=>_.rows)])),i=[...this._csv.keys()].filter(f=>!o.has(f));for(const f of i)this._csv.delete(f);const{mkdirSync:a,rmSync:h,writeFileSync:d}=R(),u=process.getBuiltinModule("node:path"),r=u.dirname(t),c=e===void 0||t===this.path;a(r,{recursive:!0}),(this._text!==s||!c)&&d(t,this._text);for(const[f,_]of this._csv){const m=_.parsed?.source??"";if(c&&n.get(f)===m)continue;const $=O(r,f);a(u.dirname($),{recursive:!0}),d($,m)}if(c)for(const f of i)h(O(r,f),{force:!0});this._disk={text:this._text,csv:new Map([...this._csv].map(([f,_])=>[f,_.parsed?.source??""]))},this.path=t}}function P(l){if(l._formula===void 0)return;const e=M(l._formula);if(e.ok)return se(e.node,l.row-1,l.column-1)}function Me(l){const e=l.format;if(!e||e.length<2)return;const t=[],s=new Map;for(const n of e){const{range:o,...i}=n,a=y(o);if(!a){t.push(n);continue}const h=JSON.stringify(i),d=s.get(h);d?d.places.push(a):s.set(h,{look:i,places:[a]})}for(const{look:n,places:o}of s.values())for(const i of T(o))t.push({range:x(i),...n});l.format=t}export function load_workbook(l,e={}){return Workbook.open(l,e)}export const get_column_letter=l=>N(l-1);export function column_index_from_string(l){const e=C(l);if(e===void 0)throw new TypeError(`${l} is not a column.`);return e+1}export function coordinate_to_tuple(l){const e=y(l);if(!e)throw new TypeError(`${l} is not a cell.`);return[e.row+1,e.col+1]}export function range_boundaries(l){const e=k(l);if(!e)throw new TypeError(`${l} is not a range.`);return[e.left+1,e.top+1,e.right+1,e.bottom+1]}
2
+ import{strict as g}from"@allyhub/formats";import{Comment as z,HeaderFooter as A,PageMargins as G,PageSetup as V,SheetProtection as Y}from"./page.js";import{columnIndex as C,columnLetter as N,cellName as T,contains as F,rangeName as x,readAddress as y,readArea as k}from"../address.js";import{Calc as q}from"../calc/engine.js";import{checkWorkbook as Q}from"../check.js";import{readCsv as X,writeCsv as Z}from"@allyhub/formats";import{GENERATED as ee}from"../generated.js";import"@allyhub/formats";import{moveFormula as te,relativeKey as se}from"../formula/move.js";import{parseFormula as M}from"../formula/parse.js";import{printFormula as B}from"../formula/print.js";import{rewriteFormula as ne}from"../formula/rewrite.js";import{isDateCode as S}from"../format.js";import{patchCsv as oe}from"../patch.js";import{CellError as W,dateOfSerial as re,isoOfSerial as ie,readTyped as j,serialOfDate as le,writeTyped as ae}from"../values.js";import{FormulaCell as he,readWorkbook as I,runsText as fe,validName as K}from"../workbook.js";import{restructure as ce,tableShape as _e}from"../structure.js";import{patchYaml as ue}from"../write.js";import{anchorOf as de,chartOfSpec as me}from"./charts.js";import{HINT as w}from"./hint.js";import{rectangles as E}from"./rectangles.js";import{AutoFilter as J,ConditionalFormattingList as pe,DataValidationList as we,validationOf as ge,validationSpec as ke}from"./rules.js";import{alignmentLook as ye,alignmentOf as be,protectionLook as ve,protectionOf as xe,borderLook as $e,borderOf as Ce,fillLook as Se,fillOf as Te,fontLook as Ee,fontOf as Le}from"./styles.js";const R=()=>process.getBuiltinModule("node:fs"),L=(...l)=>process.getBuiltinModule("node:path").join(...l);function H(l){if(!/\.ya?ml$/iu.test(l))throw new TypeError(`${l} is not a sheet's file: a workbook is its YAML file, wb.save('finance/budget.yaml'), load_workbook('finance/budget.yaml').`);return l}export const BLOCK_CELLS=100;const Oe=l=>Math.round(l*7+5),Ne=l=>(l-5)/7,Fe=l=>l*4/3,Me=l=>l*3/4;function je(l,e){const t={},s=l,n=e;for(const o of new Set([...Object.keys(s),...Object.keys(n)])){const r=o==="locked",a=n[o]??r;JSON.stringify(a)!==JSON.stringify(s[o]??r)&&(t[o]=a)}return t}const p=l=>Object.keys(l).length===0,b=(l,e)=>{if(!Number.isInteger(l)||l<1)throw new RangeError(`A ${e} is a whole number from 1: ${String(l)}.`);return l},P=(l,e)=>Object.fromEntries(Object.entries(l).filter(([t])=>t!==e));export class Cell{row;column;_ws;_value;_formula=void 0;_look;_changed=!1;_styled=!1;_fresh=!1;constructor(e,t,s){this._ws=e,this.row=t,this.column=s;const n=t-1,o=s-1,r=e._model?.at(n,o);return this._value=null,r instanceof he?this._formula=r.text:r!==void 0&&(this._value=r),this._look=e._model?.lookAt(n,o)??{},this._fresh=r===void 0,g(this,"Cell",w)}get parent(){return this._ws}get coordinate(){return T({row:this.row-1,col:this.column-1})}get column_letter(){return N(this.column-1)}get col_idx(){return this.column}get value(){return this._ws.parent.data_only?this.computed:this._formula!==void 0?this._formula:this._shown(this._value)}set value(e){if(e===void 0)throw new TypeError(`${this.coordinate}: a value is not undefined.`);if(this._formula=void 0,this._changed=!0,this._ws.parent._pending=!0,e instanceof Date){if(Number.isNaN(e.getTime()))throw new TypeError(`${this.coordinate}: the date is not valid.`);this._value=le(e),S(this._look.format)||(this._look={...this._look,format:Number.isInteger(this._value)?"yyyy-mm-dd":"yyyy-mm-dd hh:mm"});return}if(typeof e=="string"&&e.length>1&&e.startsWith("=")){this._formula=e,this._value=null;return}this._value=e}_shown(e){return typeof e=="number"&&S(this._look.format)?re(e)??e:e instanceof W?e.code:e}get computed(){const{calc:e,model:t}=this._ws.parent._computed(),s=t.sheet(this._ws.title);return s?this._shown(e.value(s,this.row-1,this.column-1)):null}get data_type(){if(this._formula!==void 0)return"f";const e=this._value;return e===null?"n":typeof e=="number"?S(this._look.format)?"d":"n":typeof e=="boolean"?"b":e instanceof W?"e":"s"}get is_date(){return this.data_type==="d"}get hyperlink(){return this._ws._links[this.coordinate]}set hyperlink(e){e===void 0?Reflect.deleteProperty(this._ws._links,this.coordinate):this._ws._links[this.coordinate]=e,this._ws._changed()}get comment(){const e=this._ws._notes[this.coordinate];if(e!==void 0)return typeof e=="string"?new z(e):new z(e.text,e.author)}set comment(e){e===void 0?Reflect.deleteProperty(this._ws._notes,this.coordinate):this._ws._notes[this.coordinate]=e._file(),this._ws._changed()}get number_format(){return this._look.format??"General"}set number_format(e){this._setLook({format:e})}_setLook(e){this._look={...this._look,...e},this._styled=!0,this._ws.parent._pending=!0}get font(){return Le(this._look)}set font(e){this._setLook(Ee(e))}get fill(){return Te(this._look)}set fill(e){this._setLook(Se(e))}get border(){return Ce(this._look)}set border(e){this._setLook($e(e))}get alignment(){return be(this._look)}set alignment(e){this._setLook(ye(e))}get protection(){return xe(this._look)}set protection(e){this._setLook(ve(e))}get has_style(){return!p(this._look)}offset(e=0,t=0){return this._ws.cell(this.row+e,this.column+t)}}export class ColumnDimension{index;_width;_hidden;_files;_level;_ws;constructor(e,t){this._ws=e,this.index=t;const s=e._spec()?.columns?.[t];return this._level=s?.level,this._width=s?.width,this._hidden=s?.hidden,this._files=s?.files,g(this,"ColumnDimension",w)}get outlineLevel(){return this._level}set outlineLevel(e){this._level=e,this._ws._dimensions=!0}get files(){return this._files}set files(e){this._files=e,this._ws._dimensions=!0}get width(){return this._width===void 0?void 0:Ne(this._width)}set width(e){this._width=e===void 0?void 0:Oe(e),this._ws._dimensions=!0}get hidden(){return this._hidden??!1}set hidden(e){this._hidden=e,this._ws._dimensions=!0}}export class RowDimension{index;_height;_hidden;_level;_ws;constructor(e,t){this._ws=e,this.index=t;const s=e._spec()?.rows?.[String(t)];return this._level=s?.level,this._height=s?.height,this._hidden=s?.hidden,g(this,"RowDimension",w)}get outlineLevel(){return this._level}set outlineLevel(e){this._level=e,this._ws._dimensions=!0}get height(){return this._height===void 0?void 0:Me(this._height)}set height(e){this._height=e===void 0?void 0:Fe(e),this._ws._dimensions=!0}get hidden(){return this._hidden??!1}set hidden(e){this._hidden=e,this._ws._dimensions=!0}}export class Table{displayName;ref;key;_spec;autoFilter;constructor(e){for(const t of Object.keys(e))if(!["displayName","ref","key"].includes(t))throw new TypeError(`Table takes displayName, ref and key; it has no ${t}. ${w}`);if(!K(e.displayName))throw new TypeError(`${e.displayName} cannot be a table's name.`);if(!k(e.ref))throw new TypeError(`${e.ref} is not a range.`);return this.displayName=e.displayName,this.ref=e.ref,this.key=e.key,this.autoFilter=new J(e.ref,()=>{}),g(this,"Table",w)}get name(){return this.displayName}}export class TableList{_items=new Map;constructor(){return g(this,"TableList",w,{key:e=>this._items.get(e)})}add(e){this._items.set(e.name,e)}get(e){return this._items.get(e)}keys(){return[...this._items.keys()]}values(){return[...this._items.values()]}items(){return[...this._items.entries()]}pop(e){const t=this._items.get(e);return this._items.delete(e),t}}export class DefinedName{name;attr_text;constructor(e,t){if(!K(e))throw new TypeError(`${e} cannot be a name.`);return this.name=e,this.attr_text=t.attr_text.replace(/^=/u,""),g(this,"DefinedName",w)}get value(){return this.attr_text}set value(e){this.attr_text=e.replace(/^=/u,"")}}export class DefinedNameDict{_items=new Map;constructor(){return g(this,"DefinedNameDict",w,{key:e=>this._items.get(e),setKey:(e,t)=>t instanceof DefinedName?(this._items.set(e,t),!0):!1})}add(e){this._items.set(e.name,e)}get(e){return this._items.get(e)}keys(){return[...this._items.keys()]}values(){return[...this._items.values()]}items(){return[...this._items.entries()]}pop(e){const t=this._items.get(e);return this._items.delete(e),t}}const v=l=>{if(l._formula!==void 0)return l._formula;const e=l._value;return typeof e=="number"&&S(l._look.format)?ie(e):ae(e)};function U(l){if(l._formula!==void 0)return l._formula;const e=l._value;return e===null?null:typeof e=="number"&&!S(l._look.format)||typeof e=="boolean"?e:v(l)}const Re=l=>l.toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/gu,"")||"rows";export class Worksheet{_parent;_title;_was;_model;_cells=new Map;_columns=new Map;_rows=new Map;_tables=new TableList;_freeze;_merges=[];_state="visible";_dimensions=!1;_lastRow=0;_rules=[];_validations=[];_filter;_charts=[];_print={};_links={};_notes={};_pictures=[];_protect=!1;constructor(e,t,s){if(this._parent=e,this._title=t,this._filter=new J(void 0,()=>{this._parent._pending=!0}),s){this._model=s,this._was=t,this._freeze=s.spec.freeze,this._heldPage(s.spec),this._merges=[...s.spec.merges??[]],this._state=s.spec.hidden===!0?"hidden":"visible",this._lastRow=(s.used?.bottom??-1)+1,this._heldRules(s.spec);for(const n of s.tables){const o=new Table({displayName:n.name,ref:x(n.area),...n.spec.key===void 0?{}:{key:n.spec.key}});o._spec=n.spec;const{filter:r}=n.spec;if(r)for(const[a,h]of Object.entries(r.columns)){const d=n.column(a);d&&o.autoFilter._columns.set(d.index,h)}this._tables.add(o)}}return g(this,"Worksheet",w,{index:n=>this._rowCells(n),key:n=>this._at(n),setKey:(n,o)=>{const r=y(n);return r?(this.cell(r.row+1,r.col+1).value=o,!0):!1}})}_spec(){return this._parent._file.sheets.find(e=>e.name===(this._was??this._title))}_heldRules(e){this._rules=[...e?.conditional??[]],this._validations=(e?.validations??[]).map(ge),this._charts=(e?.charts??[]).map(me),this._filter.ref=e?.filter?.range,this._filter._columns.clear();const t=e?.filter?k(e.filter.range):void 0;for(const[s,n]of Object.entries(e?.filter?.columns??{})){const o=C(s);t&&o!==void 0&&this._filter._columns.set(o-t.left,n)}}_at(e){const t=y(e);if(t)return this.cell(t.row+1,t.col+1);const s=k(e);if(s)return this._area(s);const n=C(e);if(n!==void 0){const o=[];for(let r=1;r<=this.max_row;r++)o.push(this.cell(r,n+1));return o}}_rowCells(e){const t=[];for(let s=1;s<=this.max_column;s++)t.push(this.cell(e,s));return t}_area(e){const t=[];for(let s=e.top;s<=e.bottom;s++){const n=[];for(let o=e.left;o<=e.right;o++)n.push(this.cell(s+1,o+1));t.push(n)}return t}get parent(){return this._parent}get title(){return this._title}set title(e){const t=this._title;e!==t&&this._parent._renameSheet(this,t,e)}get sheet_state(){return this._state}set sheet_state(e){this._state=e}cell(e,t,s){if(e<1||t<1)throw new RangeError(`Row and column values must be at least 1: ${String(e)}, ${String(t)}.`);const n=(e-1)*16384+t-1;let o=this._cells.get(n);return o||(o=new Cell(this,e,t),this._cells.set(n,o)),s!==void 0&&(o.value=s),e>this._lastRow&&(this._lastRow=e),o}append(e){const t=this._lastRow+1,s=(n,o)=>{o!=null&&this.cell(t,n,o)};if(Array.isArray(e))e.forEach((n,o)=>{s(o+1,n)});else for(const[n,o]of Object.entries(e)){const r=/^\d+$/u.test(n)?Number(n)-1:C(n);if(r===void 0)throw new TypeError(`${n} is not a column.`);s(r+1,o)}this._lastRow=t}get max_row(){return Math.max(1,this._lastRow)}get max_column(){let e=this._model?.columnsUsed??0;for(const t of this._cells.values())(t._value!==null||t._formula!==void 0)&&t.column>e&&(e=t.column);return Math.max(1,e)}min_row=1;min_column=1;get dimensions(){return x({top:0,left:0,bottom:this.max_row-1,right:this.max_column-1})}iter_rows(e={}){const t=this._area({top:(e.min_row??1)-1,left:(e.min_col??1)-1,bottom:(e.max_row??this.max_row)-1,right:(e.max_col??this.max_column)-1});return e.values_only===!0?t.map(s=>s.map(n=>n.value)):t}iter_cols(e={}){const t=this.iter_rows(e);return(t[0]??[]).map((n,o)=>t.map(r=>r[o]))}get rows(){return this.iter_rows()}get columns(){return this.iter_cols()}get values(){return this.iter_rows({values_only:!0})}insert_rows(e,t=1){this._parent._restructure({op:"insert-rows",sheet:this._title,at:b(e,"row")-1,count:b(t,"amount")})}delete_rows(e,t=1){this._parent._restructure({op:"delete-rows",sheet:this._title,at:b(e,"row")-1,count:b(t,"amount")})}insert_cols(e,t=1){this._parent._restructure({op:"insert-columns",sheet:this._title,at:b(e,"column")-1,count:b(t,"amount")})}delete_cols(e,t=1){this._parent._restructure({op:"delete-columns",sheet:this._title,at:b(e,"column")-1,count:b(t,"amount")})}merge_cells(e){if(!k(e))throw new TypeError(`${e} is not a range.`);this._merges.includes(e)||this._merges.push(e),this._parent._pending=!0}unmerge_cells(e){this._merges=this._merges.filter(t=>t!==e),this._parent._pending=!0}get merged_cells(){return[...this._merges]}get freeze_panes(){return this._freeze}set freeze_panes(e){const t=e instanceof Cell?e.coordinate:e;if(t!==void 0&&!y(t))throw new TypeError(`${t} is not a cell.`);this._freeze=t,this._parent._pending=!0}get column_dimensions(){return new Proxy({},{get:(e,t)=>{if(typeof t!="string")return;const s=t.toUpperCase();if(C(s)===void 0)throw new TypeError(`${t} is not a column.`);let n=this._columns.get(s);return n||(n=new ColumnDimension(this,s),this._columns.set(s,n)),n}})}get row_dimensions(){return new Proxy({},{get:(e,t)=>{if(typeof t!="string"||!/^[1-9]\d*$/u.test(t))throw new TypeError(`${String(t)} is not a row.`);const s=Number(t);let n=this._rows.get(s);return n||(n=new RowDimension(this,s),this._rows.set(s,n)),n}})}get tables(){return this._tables}get conditional_formatting(){return new pe(this._rules,()=>{this._parent._pending=!0})}get data_validations(){return new we(this._validations,()=>{this._parent._pending=!0})}add_data_validation(e){this._validations.push(e),this._parent._pending=!0}get auto_filter(){return this._filter}_changed(){this._parent._pending=!0}_heldPage(e){this._print=structuredClone(e?.print??{}),this._links={...e?.links},this._notes={...e?.notes},this._pictures=[...e?.pictures??[]],this._protect=e?.protect===!0}get page_setup(){return new V(this)}get page_margins(){return new G(this)}get oddHeader(){return new A(this,"header")}get oddFooter(){return new A(this,"footer")}get protection(){return new Y(()=>this._protect,e=>{this._protect=e,this._changed()})}get print_area(){return this._print.area}set print_area(e){if(e===void 0)delete this._print.area;else if(k(e))this._print.area=e;else throw new TypeError(`${e} is not a range.`);this._changed()}get print_title_rows(){return this._print.title_rows}set print_title_rows(e){e===void 0?delete this._print.title_rows:this._print.title_rows=e,this._changed()}get print_title_cols(){return this._print.title_cols}set print_title_cols(e){e===void 0?delete this._print.title_cols:this._print.title_cols=e,this._changed()}add_image(e,t){const s=t??e.anchor??"A1";if(!y(s))throw new TypeError(`${s} is not a cell.`);this._pictures.push({file:e.path,at:s,...e.width===void 0?{}:{width:e.width},...e.height===void 0?{}:{height:e.height}}),this._changed()}add_chart(e,t){e.anchor=de(t)??e.anchor,this._charts.push(e),this._parent._pending=!0}add_table(e){if(this._parent._tableNamed(e.name))throw new Error(`There is already a table named ${e.name}.`);this._tables.add(e),this._parent._pending=!0}}export class Workbook{worksheets=[];defined_names=new DefinedNameDict;data_only;title;path;block_cells=BLOCK_CELLS;_file={sheets:[]};_text="";_disk={text:"",csv:new Map};_csv=new Map;_model;_names=new Map;_active=0;_pending=!1;_making=!1;_calc=void 0;constructor(e={}){this.data_only=e.data_only??!1;const t=g(this,"Workbook",w,{key:s=>this.worksheets.find(n=>n.title===s),index:s=>this.worksheets[s]});return t.worksheets=[new Worksheet(t,"Sheet")],t}static open(e,t={}){const s=new Workbook(t);return s.path=H(e),s._read(s.path),s}_read(e){const{readFileSync:t}=R(),s=t(e,"utf8"),n=process.getBuiltinModule("node:path").dirname(e),o=new Map,r=a=>{try{const h=t(L(n,a),"utf8");return o.set(a,h),h}catch{return}};this._load(s,r);for(const[a,h]of o)this._keepCsv(a,h);this._disk={text:s,csv:o}}_keepCsv(e,t){const s=X(t);this._csv.set(e,{parsed:s,rows:s.records.map(n=>n.end===n.start?[]:[...n.fields])})}_load(e,t){const{workbook:s,problems:n}=I({text:e,read:t});if(!s)throw new Error(`The workbook cannot be opened: ${n.map(o=>o.message).join("; ")}`);this._text=e,this._file=structuredClone(s.file),this._model=s,this.title=s.title,this.worksheets=s.sheets.map(o=>new Worksheet(this,o.name,o));for(const o of s.names.values()){if(o.source.path?.[0]!=="names")continue;const r=o.formula?o.formula.text:o.value??null;this._names.set(o.name,r),this.defined_names.add(new DefinedName(o.name,{attr_text:String(r)}))}}get active(){const e=this.worksheets[this._active]??this.worksheets[0];if(!e)throw new Error("The workbook has no sheets.");return e}set active(e){this._active=this.worksheets.indexOf(e)}get sheetnames(){return this.worksheets.map(e=>e.title)}get_sheet_by_name(e){return this.worksheets.find(t=>t.title===e)}index(e){return this.worksheets.indexOf(e)}create_sheet(e,t){let s=e??"Sheet";for(let o=1;this.worksheets.some(r=>r.title===s);o++)s=`${e??"Sheet"}${String(o)}`;const n=new Worksheet(this,s);return this.worksheets.splice(t??this.worksheets.length,0,n),this._pending=!0,n}remove(e){this.worksheets=this.worksheets.filter(t=>t!==e),this._pending=!0}move_sheet(e,t=0){const s=this.worksheets.indexOf(e);this.worksheets.splice(s,1),this.worksheets.splice(s+t,0,e),this._pending=!0}_tableNamed(e){for(const t of this.worksheets){const s=t._tables.get(e);if(s)return s}}_renameSheet(e,t,s){if(this.worksheets.some(o=>o!==e&&o.title===s))throw new Error(`There is already a sheet named ${s}.`);this._apply(),this._rewrite({op:"rename-sheet",from:t,to:s}),e._title=s,e._was=s;const n=this._file.sheets.find(o=>o.name===t);n&&(n.name=s),this._apply()}_restructure(e){this._apply();const t=ce({file:this._file,rows:new Map([...this._csv].map(([n,o])=>[n,o.rows]))},e);if(t.refused!==void 0)throw new Error(t.refused==="table-header"?"A table's header row is not deleted: delete the table's rows, or all of it.":"That sheet is not there.");this._file=t.file;for(const[n,o]of t.rows){const r=this._csv.get(n);r&&(r.rows=o.map(a=>[...a]))}for(const n of this.worksheets){const o=this._file.sheets.find(r=>r.name===n._title);n._cells.clear(),n._columns.clear(),n._rows.clear(),n._merges=[...o?.merges??[]],n._freeze=o?.freeze,n._heldPage(o),n._heldRules(o)}const s=this._build();this._rebase(s.text,s.files);for(const n of this.worksheets){const o=this._model?.sheet(n._title);if(o){n._lastRow=(o.used?.bottom??-1)+1;for(const r of o.tables){const a=n._tables.get(r.name);a&&(a.ref=x(r.area))}}}}_rewrite(e){const t=(n,o)=>{const r=M(n);if(!r.ok)return n;const a=ne(r.node,e,o);return a===r.node?n:B(a)},{_file:s}=this;if(s.names){for(const[n,o]of Object.entries(s.names))if(typeof o=="string"&&o.startsWith("=")){const r=t(o,s.sheets[0]?.name??"");s.names[n]=r,this._names.set(n,r);const a=this.defined_names.get(n);a&&(a.attr_text=r.slice(1))}}for(const n of s.checks??[])n.formula=t(n.formula,s.sheets[0]?.name??"");for(const n of s.sheets){for(const[o,r]of Object.entries(n.cells??{}))typeof r=="string"&&r.startsWith("=")?n.cells[o]=t(r,n.name):r!==null&&typeof r=="object"&&r.formula!==void 0&&(r.formula=t(r.formula,n.name));for(const o of n.tables??[]){for(const r of Object.values(o.columns??{}))r.formula!==void 0&&(r.formula=t(r.formula,n.name));this._rewriteCsv(o.rows,n.name,t)}for(const o of n.blocks??[])this._rewriteCsv(o.rows,n.name,t)}}_rewriteCsv(e,t,s){const n=this._csv.get(e);n&&(n.rows=n.rows.map(o=>o.map(r=>j(r).formula!==void 0?s(r,t):r)))}_sheetEntry(e){const t=e._was??e._title;let s=this._file.sheets.find(n=>n.name===t);return s||(s={name:e._title},this._file.sheets.push(s)),s.name=e._title,s}_dataPath(e){const t=Re(e);let s=`${t}.csv`;const n=this.path===void 0?void 0:process.getBuiltinModule("node:path").dirname(this.path),o=r=>this._csv.has(r)||this._file.sheets.some(a=>a.tables?.some(h=>h.rows===r)??a.blocks?.some(h=>h.rows===r))||n!==void 0&&R().existsSync(L(n,r));for(let r=2;o(s);r++)s=`${t}-${String(r)}.csv`;return s}_writeNewTable(e,t,s){const n=k(s.ref);if(!n)throw new Error(`${s.ref} is not a range.`);const o=[];for(let i=n.left;i<=n.right;i++){const c=e.cell(n.top+1,i+1).value;if(c===null||c==="")throw new Error(`Table ${s.name}'s header has no name at ${T({row:n.top,col:i})}.`);o.push(String(c))}const r={},a=[];o.forEach((i,c)=>{const f=n.left+c,_=this._columnFormula(e,n,f);_===void 0?a.push(c):r[i]={formula:_};const m=this._columnFormat(e,n,f);m!==void 0&&(r[i]={...r[i],format:m})}),this._columnsStyled(e,n);const h=[a.map(i=>o[i]??"")];for(let i=n.top+1;i<=n.bottom;i++)h.push(a.map(c=>v(e.cell(i+1,n.left+c+1))));t.cells&&(t.cells=Object.fromEntries(Object.entries(t.cells).filter(([i])=>{const c=y(i);return!c||!F(n,c.row,c.col)})));const d=this._dataPath(s.name);this._csv.set(d,{parsed:void 0,rows:h});const u={name:s.name,at:T({row:n.top,col:n.left}),rows:d,...s.key===void 0?{}:{key:s.key},...p(r)?{}:{columns:r}};(t.tables??=[]).push(u),s._spec=u}_columnsStyled(e,t){for(let s=t.left;s<=t.right;s++)for(let n=t.top+1;n<=t.bottom;n++){const o=e.cell(n+1,s+1),{format:r,...a}=this._ownLook(o);r!==void 0&&p(a)&&(o._styled=!1)}}_columnFormula(e,t,s){if(t.bottom<=t.top)return;const n=e.cell(t.top+2,s+1),o=D(n);if(o!==void 0){for(let r=t.top+2;r<=t.bottom;r++)if(D(e.cell(r+1,s+1))!==o)return;return n._formula}}_columnFormat(e,t,s){if(t.bottom<=t.top)return;const n=r=>this._ownLook(e.cell(r+1,s+1)).format,o=n(t.top+1);for(let r=t.top+2;r<=t.bottom;r++)if(n(r)!==o)return;return o}_held(e){const t=this._csv.get(e);if(!t)throw new Error(`${e} was not read.`);return t}_setCsvCell(e,t,s,n){const{rows:o}=this._held(e);for(;o.length<=t;)o.push([]);const r=o[t];if(r){for(;r.length<=s;)r.push("");r[s]=n}}_recordOf(e,t){let s=0;for(let n=0;n<t;){if(s+=1,s>=e.length)return s+t-n-1;e[s]?.length!==0&&(n+=1)}return s}_writeTableCell(e,t,s){const n=this._held(e.rows),o=n.rows[0]??[],r=s.column-1-t.left,a=this._recordOf(n.rows,s.row-1-t.top),h=Object.keys(e.columns??{}).filter(f=>!o.some(_=>_.trim().toLowerCase()===f.toLowerCase())),u=[...o.map(f=>f.trim()),...h][r];if(u===void 0)return;if(a===0){r<o.length&&(o[r]=v(s));return}const i=e.columns?.[u]?.formula;if(i!==void 0){const f=this._movedColumn(i,t,s);if(s._formula===f){const _=o.findIndex(m=>m.trim()===u);_>=0&&this._setCsvCell(e.rows,a,_,"");return}}let c=o.findIndex(f=>f.trim()===u);c<0&&(c=o.length,this._setCsvCell(e.rows,0,c,u)),this._setCsvCell(e.rows,a,c,v(s))}_movedColumn(e,t,s){const n=M(e);if(!n.ok)return e;const o=s.row-1-(t.top+1);return o===0?e:B(te(n.node,o,0))}_apply(){this.title===void 0?delete this._file.title:this._file.title=this.title;const e=new Set(this.worksheets.map(s=>s._was??s._title));this._file.sheets=this._file.sheets.filter(s=>e.has(s.name));for(const s of this.worksheets)this._applySheet(s);this._file.sheets=this.worksheets.map(s=>this._sheetEntry(s)),this._applyNames();const t=this._build();this._rebase(t.text,t.files)}_applyNames(){const e={};for(const t of this.defined_names.values()){const s=j(t.attr_text),n=this._names.get(t.name);e[t.name]=n!==void 0&&String(n).replace(/^=/u,"")===t.attr_text?n:typeof s.value=="number"||typeof s.value=="boolean"?s.value:/^"[^"]*"$/u.test(t.attr_text)?t.attr_text.slice(1,-1):`=${t.attr_text}`}p(e)?delete this._file.names:this._file.names=e}_applySheet(e){const t=this._sheetEntry(e);e._freeze===void 0?delete t.freeze:t.freeze=e._freeze,p(e._print)?delete t.print:t.print=e._print,p(e._links)?delete t.links:t.links=e._links,p(e._notes)?delete t.notes:t.notes=e._notes,e._pictures.length===0?delete t.pictures:t.pictures=e._pictures,e._protect?t.protect=!0:delete t.protect,e._merges.length===0?delete t.merges:t.merges=[...e._merges],e._state==="hidden"?t.hidden=!0:delete t.hidden,e._rules.length===0?delete t.conditional:t.conditional=[...e._rules],e._validations.length===0?delete t.validations:t.validations=e._validations.map(ke),e._charts.length===0?delete t.charts:t.charts=e._charts.map(n=>n._spec(e._title)),this._applyFilter(e,t);const s=new Set(t.tables?.map(n=>n.name.toLowerCase()));for(const n of e._tables.values())s.has(n.name.toLowerCase())||this._writeNewTable(e,t,n);this._applyTableFilters(e,t),this._applyCells(e,t),this._applyDimensions(e,t),t.cells&&p(t.cells)&&delete t.cells,t.columns&&p(t.columns)&&delete t.columns,t.rows&&p(t.rows)&&delete t.rows,t.format?.length===0&&delete t.format,t.tables?.length===0&&delete t.tables,t.blocks?.length===0&&delete t.blocks}_applyFilter(e,t){const{ref:s,_columns:n}=e._filter;if(s===void 0){delete t.filter;return}const o=k(s);if(!o)throw new TypeError(`${s} is not a range.`);const r={};for(const[a,h]of n)r[N(o.left+a)]=h;t.filter={range:s,...p(r)?{}:{columns:r}}}_applyTableFilters(e,t){for(const s of t.tables??[]){const n=e._tables.get(s.name);if(!n||n.autoFilter._columns.size===0)continue;const o=this._csv.get(s.rows)?.rows??[],r=_e(s,o)?.names??[],a={};for(const[h,d]of n.autoFilter._columns){const u=r[h];if(u===void 0)throw new RangeError(`Table ${s.name} has no column at ${String(h)}.`);a[u]=d}s.filter={columns:a}}}_applyDimensions(e,t){if(e._dimensions){for(const[s,n]of e._columns){const o={...t.columns?.[s]};n._width===void 0?delete o.width:o.width=n._width,n._hidden===void 0?delete o.hidden:o.hidden=n._hidden,n._files===void 0?delete o.files:o.files=n._files,n._level===void 0?delete o.level:o.level=n._level;const r=P(t.columns??{},s);t.columns=p(o)?r:{...r,[s]:o}}for(const[s,n]of e._rows){const o={...t.rows?.[String(s)]};n._height===void 0?delete o.height:o.height=n._height,n._hidden===void 0?delete o.hidden:o.hidden=n._hidden,n._level===void 0?delete o.level:o.level=n._level;const r=P(t.rows??{},String(s));t.rows=p(o)?r:{...r,[String(s)]:o}}e._dimensions=!1}}_applyCells(e,t){const s=(t.tables??[]).flatMap(r=>{const a=y(r.at),h=e._tables.get(r.name),d=h?k(h.ref):void 0;return a&&d?[{entry:r,area:d}]:[]}),n=(t.blocks??[]).flatMap(r=>{const a=e._model?.blocks.find(h=>h.file===r.rows);return a?[{entry:r,area:a.area}]:[]}),o=[];for(const r of e._cells.values()){if(!r._changed&&!r._styled)continue;const a=r.row-1,h=r.column-1,d=s.find(i=>F(i.area,a,h)),u=n.find(i=>F(i.area,a,h));d?(r._changed&&this._writeTableCell(d.entry,d.area,r),r._styled&&this._styleByFormat(t,r)):u?(r._changed&&this._setCsvCell(u.entry.rows,a-u.area.top,h-u.area.left,v(r)),r._styled&&this._styleByFormat(t,r)):r._fresh&&!e._model?.keys.has(a*16384+h)?o.push(r):this._writeLoose(e,t,r),r._changed=!1,r._styled=!1}this._consolidate(e,t,o),Pe(t)}_styleByFormat(e,t){(e.format??=[]).push({range:t.coordinate,...this._ownLook(t)})}_ownLook(e){const t=e._ws._model?.lookAt(e.row-1,e.column-1)??{},s=je(t,e._look);return s.format!==void 0&&e._formula===void 0&&j(v(e)).format===s.format&&delete s.format,s}_writeLoose(e,t,s){const n=s.coordinate,o=t.cells??={},r=U(s),a=this._ownLook(s),h=o[n],u={...h!==null&&typeof h=="object"?Object.fromEntries(Object.entries(h).filter(([_])=>_!=="value"&&_!=="formula"&&_!=="name"&&_!=="runs")):{},...a},i=h!==null&&typeof h=="object"&&h.name!==void 0?{name:h.name}:{},c=e._model?.at(s.row-1,s.column-1)!==void 0,f=h!==null&&typeof h=="object"&&h.runs!==void 0&&fe(h.runs)===s._value?h.runs:void 0;if(f){o[n]={...i,...u,runs:f};return}if(r===null&&p(u)&&!c){t.cells=P(o,n);return}o[n]=p(u)&&p(i)?r:{...typeof r=="string"&&r.startsWith("=")?{formula:r}:r===null?{}:{value:r},...i,...u}}_consolidate(e,t,s){const n=s.filter(i=>i._value!==null||i._formula!==void 0),o=new Map;for(const i of s){const c=this._ownLook(i);if(p(c))continue;const f=JSON.stringify(c),_=o.get(f);_?_.push(i):o.set(f,[i])}const r=new Map(n.map(i=>[`${String(i.row)}:${String(i.column)}`,i])),a=i=>r.get(`${String(i.row+1)}:${String(i.col+1)}`)??e.cell(i.row+1,i.col+1),h=new Map,d=[];for(const i of n){const c={row:i.row-1,col:i.column-1},f=i._formula===void 0?void 0:D(i);if(f===void 0){d.push(c);continue}const _=h.get(f);_?_.push(c):h.set(f,[c])}const u=t.cells??={};for(const i of h.values())for(const c of E(i))u[x(c)]=a({row:c.top,col:c.left})._formula??null;for(const i of E(d))if((i.bottom-i.top+1)*(i.right-i.left+1)>=this.block_cells){const f=[];for(let m=i.top;m<=i.bottom;m++){const $=[];for(let O=i.left;O<=i.right;O++)$.push(v(a({row:m,col:O})));f.push($)}const _=this._dataPath(e._title);this._csv.set(_,{parsed:void 0,rows:f}),(t.blocks??=[]).push({at:T({row:i.top,col:i.left}),rows:_})}else for(let f=i.top;f<=i.bottom;f++)for(let _=i.left;_<=i.right;_++){const m=a({row:f,col:_});u[m.coordinate]=U(m)}for(const i of o.values()){const[c]=i;if(!c)continue;const f=this._ownLook(c),_=i.map(m=>({row:m.row-1,col:m.column-1}));for(const m of E(_))(t.format??=[]).push({range:x(m),...f})}}_build(){const e=new Map;for(const[t,s]of this._csv)e.set(t,s.parsed?oe(s.parsed,s.rows):Z(s.rows));return{text:ue(this._text,this._file),files:e}}_rebase(e,t){const{workbook:s,problems:n}=I({text:e,read:o=>t.get(o)});if(!s)throw new Error(`The workbook is not one: ${n.map(o=>o.message).join("; ")}`);this._text=e,this._file=structuredClone(s.file),this._model=s;for(const[o,r]of t)this._keepCsv(o,r);this._calc=void 0,this._pending=!1;for(const o of this.worksheets){o._was=o._title;const r=s.sheet(o._title);r&&(o._model=r);for(const a of o._cells.values())a._fresh=r?.at(a.row-1,a.column-1)===void 0}this._names=new Map;for(const o of s.names.values())o.source.path?.[0]==="names"&&this._names.set(o.name,o.formula?o.formula.text:o.value??null)}_computed(){const e=[...this.defined_names.values()];if((this._pending||e.length!==this._names.size||e.some(t=>String(this._names.get(t.name)).replace(/^=/u,"")!==t.attr_text))&&this._apply(),!this._calc){const t=this._model;if(!t)throw new Error("The workbook has no sheets.");this._calc={calc:new q(t).calculate(),model:t}}return this._calc}check(){this._apply();const{text:e,files:t}=this._build();return Q({text:e,read:s=>t.get(s)}).problems}_generated(){if(this.worksheets.length===0)return this._applyNames(),{sheets:[],csv:{},...this._file.names?{names:this._file.names}:{}};this._apply();const e=structuredClone(this._file.sheets),t=n=>`${ee}${n}`;for(const n of e){for(const o of n.tables??[])o.rows=t(o.rows);for(const o of n.blocks??[])o.rows=t(o.rows)}const s={};for(const[n,o]of this._build().files)s[t(n)]=o;return{sheets:e,csv:s,...this._file.names?{names:this._file.names}:{}}}save(e){if(this._making)throw new Error("A sheet's code makes sheets and saves nothing: what it adds to wb is what it makes.");const t=e===void 0?this.path:H(e);if(t===void 0)throw new TypeError("A new workbook is saved to a file: wb.save('finance/budget.yaml').");if(this.worksheets.length===0)throw new Error("A workbook has at least one sheet.");const{text:s,csv:n}=this._disk;this._apply();const o=new Set(this._file.sheets.flatMap(f=>[...(f.tables??[]).map(_=>_.rows),...(f.blocks??[]).map(_=>_.rows)])),r=[...this._csv.keys()].filter(f=>!o.has(f));for(const f of r)this._csv.delete(f);const{mkdirSync:a,rmSync:h,writeFileSync:d}=R(),u=process.getBuiltinModule("node:path"),i=u.dirname(t),c=e===void 0||t===this.path;a(i,{recursive:!0}),(this._text!==s||!c)&&d(t,this._text);for(const[f,_]of this._csv){const m=_.parsed?.source??"";if(c&&n.get(f)===m)continue;const $=L(i,f);a(u.dirname($),{recursive:!0}),d($,m)}if(c)for(const f of r)h(L(i,f),{force:!0});this._disk={text:this._text,csv:new Map([...this._csv].map(([f,_])=>[f,_.parsed?.source??""]))},this.path=t}}function D(l){if(l._formula===void 0)return;const e=M(l._formula);if(e.ok)return se(e.node,l.row-1,l.column-1)}function Pe(l){const e=l.format;if(!e||e.length<2)return;const t=[],s=new Map;for(const n of e){const{range:o,...r}=n,a=y(o);if(!a){t.push(n);continue}const h=JSON.stringify(r),d=s.get(h);d?d.places.push(a):s.set(h,{look:r,places:[a]})}for(const{look:n,places:o}of s.values())for(const r of E(o))t.push({range:x(r),...n});l.format=t}export function load_workbook(l,e={}){return Workbook.open(l,e)}export const get_column_letter=l=>N(l-1);export function column_index_from_string(l){const e=C(l);if(e===void 0)throw new TypeError(`${l} is not a column.`);return e+1}export function coordinate_to_tuple(l){const e=y(l);if(!e)throw new TypeError(`${l} is not a cell.`);return[e.row+1,e.col+1]}export function range_boundaries(l){const e=k(l);if(!e)throw new TypeError(`${l} is not a range.`);return[e.left+1,e.top+1,e.right+1,e.bottom+1]}
@@ -1,6 +1,7 @@
1
- import type { SheetChart, SheetConditional, SheetFilterColumn, SheetSide, SheetValidation } from "@allyhub/formats";
1
+ import type { SheetChart, SheetConditional, SheetFilterColumn, SheetPrint, SheetSide, SheetValidation } from "@allyhub/formats";
2
2
  import { type Area, type Place } from "./address.js";
3
3
  import { Draft, type BookEdit, type EditBook } from "./edit.js";
4
+ import type { CellNote } from "./annotations.js";
4
5
  import type { CellLook, Filter, Worksheet } from "./workbook.js";
5
6
  /** Excel's Borders list. */
6
7
  export declare const BORDER_PRESETS: readonly ["bottom", "top", "left", "right", "none", "all", "outside", "thickOutside", "bottomDouble", "thickBottom", "topBottom", "topThickBottom", "topDoubleBottom"];
@@ -42,6 +43,8 @@ export declare function setHidden(book: EditBook, sheetName: string, what: "rows
42
43
  export declare function setSheetHidden(book: EditBook, sheetName: string, hidden: boolean): BookEdit;
43
44
  /** A sheet's tab given a colour, or none. */
44
45
  export declare function setTabColor(book: EditBook, sheetName: string, color: string | undefined): BookEdit;
46
+ /** View's and Page Layout's Gridlines: drawn on the sheet, or not. */
47
+ export declare function setGridlines(book: EditBook, sheetName: string, on: boolean): BookEdit;
45
48
  /** Cmd+Shift+L: a filter on the selection's region, or off. A table's buttons go and come. */
46
49
  export declare function toggleFilter(book: EditBook, sheetName: string, area: Area): BookEdit;
47
50
  /** What one column of a filter keeps; nothing clears it. */
@@ -64,5 +67,29 @@ export declare function setChart(book: EditBook, sheetName: string, index: numbe
64
67
  }): BookEdit;
65
68
  /** A chart taken off its sheet. */
66
69
  export declare function removeChart(book: EditBook, sheetName: string, index: number): BookEdit;
70
+ /** Review's New Note and Edit Note, and Delete Note with no text: written on the cell. */
71
+ export declare function setNote(book: EditBook, sheetName: string, at: Place, note: CellNote | undefined): BookEdit;
72
+ /**
73
+ * Insert's Link (Cmd+K) over an area, or Remove Link with none: what linked
74
+ * any of its cells goes first. A new link gives a cell with no colour of
75
+ * its own Excel's Hyperlink look, as Excel does.
76
+ */
77
+ export declare function setLink(book: EditBook, sheetName: string, area: Area, to: string | undefined): BookEdit;
78
+ /** Excel's Hyperlink cell style: the Office theme's hyperlink colour, underlined. */
79
+ export declare const HYPERLINK_LOOK: CellLook;
80
+ /** Review's Protect Sheet and Unprotect Sheet: what is locked can change while it is off. */
81
+ export declare function setProtect(book: EditBook, sheetName: string, on: boolean): BookEdit;
82
+ /**
83
+ * Whether a protected sheet keeps any cell of an area as it is: a cell is
84
+ * locked unless its look says `locked: false`. Nothing on a sheet that is
85
+ * not protected.
86
+ */
87
+ export declare function protectedIn(sheet: Worksheet, area: Area): boolean;
88
+ /** The Rules Manager's OK: the sheet's conditional formats as it left them, the strongest first. */
89
+ export declare function setConditionals(book: EditBook, sheetName: string, rules: readonly SheetConditional[]): BookEdit;
90
+ /** Page Layout's settings: what the patch names changes, a field it leaves undefined goes. */
91
+ export declare function setPrint(book: EditBook, sheetName: string, patch: {
92
+ [K in keyof SheetPrint]?: SheetPrint[K] | undefined;
93
+ }): BookEdit;
67
94
  export {};
68
95
  //# sourceMappingURL=arrange.d.ts.map
@@ -1,2 +1,2 @@
1
1
  /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
- import{MAX_COLUMNS as S,MAX_ROWS as A,cellName as E,columnIndex as _,columnLetter as O,overlaps as k,rangeName as w,readArea as y,readAreas as v}from"./address.js";import{Draft as g,applyLook as x,blankEdit as M,refused as d,tidied as D,writeOne as B,inputOf as j}from"./edit.js";import{regionAround as R}from"./filter.js";export const BORDER_PRESETS=["bottom","top","left","right","none","all","outside","thickOutside","bottomDouble","thickBottom","topBottom","topThickBottom","topDoubleBottom"];const a=(o,s)=>Object.fromEntries(Object.entries(o).filter(([t])=>t!==s)),p={top:o=>({...o,bottom:o.top}),bottom:o=>({...o,top:o.bottom}),left:o=>({...o,right:o.left}),right:o=>({...o,left:o.right})};function L(o,s,t){const n=e=>({...t,style:e});switch(o){case"bottom":return[{area:p.bottom(s),sides:{bottom:t}}];case"top":return[{area:p.top(s),sides:{top:t}}];case"left":return[{area:p.left(s),sides:{left:t}}];case"right":return[{area:p.right(s),sides:{right:t}}];case"all":return[{area:s,sides:{left:t,right:t,top:t,bottom:t}}];case"outside":case"thickOutside":{const e=o==="outside"?t:n("thick");return[{area:p.top(s),sides:{top:e}},{area:p.bottom(s),sides:{bottom:e}},{area:p.left(s),sides:{left:e}},{area:p.right(s),sides:{right:e}}]}case"bottomDouble":return[{area:p.bottom(s),sides:{bottom:n("double")}}];case"thickBottom":return[{area:p.bottom(s),sides:{bottom:n("thick")}}];case"topBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:t}}];case"topThickBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:n("thick")}}];case"topDoubleBottom":return[{area:p.top(s),sides:{top:t}},{area:p.bottom(s),sides:{bottom:n("double")}}];case"none":return[]}}export function drawSides(o,s,t,n){const e=o.spec(s),r=w(t),i=e.format?.find(c=>c.range===r)?.border;x(o,s,t,{border:{...i,...n}})}export function setBorders(o,s,t,n,e={}){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new g(o);if(n==="none")return x(i,r,t,{border:void 0}),i.finish();const c={style:e.style??"thin",...e.color===void 0?{}:{color:e.color}};for(const f of L(n,t,c))drawSides(i,r,f.area,f.sides);return i.finish()}export function setBorderSides(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new g(o),i=b=>b??{style:"none"},{top:c,bottom:f,left:u,right:l,horizontal:h,vertical:m}=n;return c!==void 0&&drawSides(r,e,p.top(t),{top:i(c)}),f!==void 0&&drawSides(r,e,p.bottom(t),{bottom:i(f)}),u!==void 0&&drawSides(r,e,p.left(t),{left:i(u)}),l!==void 0&&drawSides(r,e,p.right(t),{right:i(l)}),h!==void 0&&t.bottom>t.top&&drawSides(r,e,{...t,bottom:t.bottom-1},{bottom:i(h)}),m!==void 0&&t.right>t.left&&drawSides(r,e,{...t,right:t.right-1},{right:i(m)}),r.finish()}export function mergeLoses(o,s,t){const n=Math.min(s.right,o.columnsUsed-1),e=Math.min(s.bottom,o.lastRow);for(let r=s.top;r<=e;r++){let i=!0;for(let c=s.left;c<=n;c++)if(o.at(r,c)!==void 0)if(i&&(t==="across"||r===s.top))i=!1;else return!0;if(t!=="across"&&!i&&r>=s.top){for(let c=r+1;c<=e;c++)for(let f=s.left;f<=n;f++)if(o.at(c,f)!==void 0)return!0;return!1}}return!1}export function mergeCells(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");if(e.tables.some(l=>k(l.area,t)))return d("merge-table");const r=new g(o),i=r.spec(e),c=(i.merges??[]).filter(l=>{const h=y(l);return!h||!k(h,t)}),f=n==="across"?Array.from({length:t.bottom-t.top+1},(l,h)=>({...t,top:t.top+h,bottom:t.top+h})):[t],u=[];for(const l of f)l.top===l.bottom&&l.left===l.right||(u.push(w(l)),T(r,o,e,l));return u.length===0?M():(i.merges=[...c,...u],n==="center"&&x(r,e,t,{align:"center"}),r.edit.whole=!0,r.finish())}function T(o,s,t,n){let e="";const r=Math.min(n.right,t.columnsUsed-1),i=Math.min(n.bottom,t.lastRow);for(let c=n.top;c<=i;c++)for(let f=n.left;f<=r;f++)t.at(c,f)!==void 0&&(e===""&&(e=j(s,t,c,f)),(c!==n.top||f!==n.left)&&B(o,s,t,c,f,""));e!==j(s,t,n.top,n.left)&&B(o,s,t,n.top,n.left,e)}export function unmergeCells(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=(r.merges??[]).filter(c=>{const f=y(c);return!f||!k(f,t)});return i.length===0?delete r.merges:r.merges=i,e.edit.whole=!0,e.finish()}export function setFreeze(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return t&&(t.row>0||t.col>0)?r.freeze=E(t):delete r.freeze,e.edit.whole=!0,e.finish()}export function setHidden(o,s,t,n,e,r){const i=o.workbook.sheet(s);if(!i)return d("no-sheet");const c=new g(o),f=c.spec(i),u=(l,h)=>{const m=a(l[h]??{},"hidden");return r?{...l,[h]:{...m,hidden:!0}}:Object.keys(m).length===0?a(l,h):{...l,[h]:m}};if(t==="columns"){let l={...f.columns};const h=r?Array.from({length:e-n+1},(m,b)=>O(n+b)):Object.keys(l).filter(m=>{const b=_(m);return b!==void 0&&b>=n&&b<=e});for(const m of h)l=u(l,m);f.columns=l}else{let l={...f.rows};const h=r?Array.from({length:e-n+1},(m,b)=>String(n+b+1)):Object.keys(l).filter(m=>{const b=Number(m)-1;return b>=n&&b<=e});for(const m of h)l=u(l,m);f.rows=l}return D(f),c.edit.whole=!0,c.finish()}export function setSheetHidden(o,s,t){const n=o.file.sheets,e=n.filter(u=>u.hidden!==!0),r=n.findIndex(u=>u.name===s),i=n[r];if(!i)return d("no-sheet");if(t&&e.length<=1)return d("last-sheet");const c=a(i,"hidden"),f=t?{...c,hidden:!0}:c;return{...M(),file:{...o.file,sheets:n.map((u,l)=>l===r?f:u)},whole:!0}}export function setTabColor(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return t===void 0?delete r.tab:r.tab=t,e.finish()}export function toggleFilter(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r={row:t.top,col:t.left},i=n.tableAt(r.row,r.col);if(i){const h=e.table(n,i);return h.filter===!1?delete h.filter:h.filter=!1,e.edit.whole=!0,e.finish()}const c=e.spec(n);if(c.filter)return delete c.filter,e.edit.whole=!0,e.finish();const u=t.top===t.bottom&&t.left===t.right?R(n,r):t;if(!u)return d("no-data");const l=n.used;return c.filter={range:w({...u,bottom:Math.min(u.bottom,l?.bottom??u.bottom),right:Math.min(u.right,l?.right??u.right)})},e.edit.whole=!0,e.finish()}export function setFilterColumn(o,s,t,n,e){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new g(o),{table:c}=t;if(c){const f=i.table(r,c),u=c.columns[n-c.at.col]?.name??"",l=a(f.filter===!1||!f.filter?{}:f.filter.columns,u),h=e?{...l,[u]:e}:l;Object.keys(h).length===0?delete f.filter:f.filter={columns:h}}else{const f=i.spec(r);if(!f.filter)return d("no-sheet");const u=O(n),l=a(f.filter.columns??{},u),h=e?{...l,[u]:e}:l;f.filter={range:f.filter.range,...Object.keys(h).length===0?{}:{columns:h}}}return i.edit.whole=!0,i.finish()}export function clearFilters(o,s){const t=o.workbook.sheet(s);if(!t)return d("no-sheet");const n=new g(o),e=n.spec(t);e.filter&&(e.filter={range:e.filter.range});for(const r of t.tables)r.spec.filter&&delete n.table(t,r).filter;return n.edit.whole=!0,n.finish()}export function addConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return r.conditional=[t,...r.conditional??[]],e.edit.whole=!0,e.finish()}function z(o,s){if(!k(o,s))return[o];const t=[];s.top>o.top&&t.push({...o,bottom:s.top-1}),s.bottom<o.bottom&&t.push({...o,top:s.bottom+1});const n=Math.max(o.top,s.top),e=Math.min(o.bottom,s.bottom);return s.left>o.left&&t.push({...o,top:n,bottom:e,right:s.left-1}),s.right<o.right&&t.push({...o,top:n,bottom:e,left:s.right+1}),t}function C(o,s){const t=v(o);if(!t)return o;const n=t.flatMap(e=>z(e,s));return n.length===0?void 0:n.map(w).join(" ")}export function clearConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=t?(r.conditional??[]).flatMap(c=>{const f=C(c.range,t);return f===void 0?[]:[{...c,range:f}]}):[];return i.length===0?delete r.conditional:r.conditional=i,e.edit.whole=!0,e.finish()}export function setValidation(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new g(o),i=r.spec(e),c=(i.validations??[]).flatMap(u=>{const l=C(u.range,t);return l===void 0?[]:[{...u,range:l}]}),f=n?[...c,{...n,range:w(t)}]:c;return f.length===0?delete i.validations:i.validations=f,r.edit.whole=!0,r.finish()}export const WHOLE_SHEET={top:0,left:0,bottom:A-1,right:S-1};export function addChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n);return r.charts=[...r.charts??[],t],e.finish()}export function setChart(o,s,t,n){const e=o.workbook.sheet(s),r=e?.spec.charts?.[t];if(!e||!r)return d("no-sheet");const i=new g(o),c=i.spec(e),f=Object.fromEntries(Object.entries({...r,...n}).filter(([,u])=>u!==void 0));return c.charts=(c.charts??[]).map((u,l)=>l===t?f:u),i.finish()}export function removeChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new g(o),r=e.spec(n),i=(r.charts??[]).filter((c,f)=>f!==t);return i.length>0?r.charts=i:delete r.charts,e.finish()}
2
+ import{MAX_COLUMNS as S,MAX_ROWS as _,cellName as y,columnIndex as L,columnLetter as j,overlaps as a,rangeName as w,readArea as O,readAreas as R}from"./address.js";import{Draft as p,applyLook as x,blankEdit as M,refused as d,tidied as E,writeOne as C,inputOf as A}from"./edit.js";import{regionAround as v}from"./filter.js";export const BORDER_PRESETS=["bottom","top","left","right","none","all","outside","thickOutside","bottomDouble","thickBottom","topBottom","topThickBottom","topDoubleBottom"];const k=(o,s)=>Object.fromEntries(Object.entries(o).filter(([t])=>t!==s)),m={top:o=>({...o,bottom:o.top}),bottom:o=>({...o,top:o.bottom}),left:o=>({...o,right:o.left}),right:o=>({...o,left:o.right})};function D(o,s,t){const n=e=>({...t,style:e});switch(o){case"bottom":return[{area:m.bottom(s),sides:{bottom:t}}];case"top":return[{area:m.top(s),sides:{top:t}}];case"left":return[{area:m.left(s),sides:{left:t}}];case"right":return[{area:m.right(s),sides:{right:t}}];case"all":return[{area:s,sides:{left:t,right:t,top:t,bottom:t}}];case"outside":case"thickOutside":{const e=o==="outside"?t:n("thick");return[{area:m.top(s),sides:{top:e}},{area:m.bottom(s),sides:{bottom:e}},{area:m.left(s),sides:{left:e}},{area:m.right(s),sides:{right:e}}]}case"bottomDouble":return[{area:m.bottom(s),sides:{bottom:n("double")}}];case"thickBottom":return[{area:m.bottom(s),sides:{bottom:n("thick")}}];case"topBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:t}}];case"topThickBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:n("thick")}}];case"topDoubleBottom":return[{area:m.top(s),sides:{top:t}},{area:m.bottom(s),sides:{bottom:n("double")}}];case"none":return[]}}export function drawSides(o,s,t,n){const e=o.spec(s),r=w(t),i=e.format?.find(c=>c.range===r)?.border;x(o,s,t,{border:{...i,...n}})}export function setBorders(o,s,t,n,e={}){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new p(o);if(n==="none")return x(i,r,t,{border:void 0}),i.finish();const c={style:e.style??"thin",...e.color===void 0?{}:{color:e.color}};for(const f of D(n,t,c))drawSides(i,r,f.area,f.sides);return i.finish()}export function setBorderSides(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=b=>b??{style:"none"},{top:c,bottom:f,left:u,right:l,horizontal:h,vertical:g}=n;return c!==void 0&&drawSides(r,e,m.top(t),{top:i(c)}),f!==void 0&&drawSides(r,e,m.bottom(t),{bottom:i(f)}),u!==void 0&&drawSides(r,e,m.left(t),{left:i(u)}),l!==void 0&&drawSides(r,e,m.right(t),{right:i(l)}),h!==void 0&&t.bottom>t.top&&drawSides(r,e,{...t,bottom:t.bottom-1},{bottom:i(h)}),g!==void 0&&t.right>t.left&&drawSides(r,e,{...t,right:t.right-1},{right:i(g)}),r.finish()}export function mergeLoses(o,s,t){const n=Math.min(s.right,o.columnsUsed-1),e=Math.min(s.bottom,o.lastRow);for(let r=s.top;r<=e;r++){let i=!0;for(let c=s.left;c<=n;c++)if(o.at(r,c)!==void 0)if(i&&(t==="across"||r===s.top))i=!1;else return!0;if(t!=="across"&&!i&&r>=s.top){for(let c=r+1;c<=e;c++)for(let f=s.left;f<=n;f++)if(o.at(c,f)!==void 0)return!0;return!1}}return!1}export function mergeCells(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");if(e.tables.some(l=>a(l.area,t)))return d("merge-table");const r=new p(o),i=r.spec(e),c=(i.merges??[]).filter(l=>{const h=O(l);return!h||!a(h,t)}),f=n==="across"?Array.from({length:t.bottom-t.top+1},(l,h)=>({...t,top:t.top+h,bottom:t.top+h})):[t],u=[];for(const l of f)l.top===l.bottom&&l.left===l.right||(u.push(w(l)),N(r,o,e,l));return u.length===0?M():(i.merges=[...c,...u],n==="center"&&x(r,e,t,{align:"center"}),r.edit.whole=!0,r.finish())}function N(o,s,t,n){let e="";const r=Math.min(n.right,t.columnsUsed-1),i=Math.min(n.bottom,t.lastRow);for(let c=n.top;c<=i;c++)for(let f=n.left;f<=r;f++)t.at(c,f)!==void 0&&(e===""&&(e=A(s,t,c,f)),(c!==n.top||f!==n.left)&&C(o,s,t,c,f,""));e!==A(s,t,n.top,n.left)&&C(o,s,t,n.top,n.left,e)}export function unmergeCells(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=(r.merges??[]).filter(c=>{const f=O(c);return!f||!a(f,t)});return i.length===0?delete r.merges:r.merges=i,e.edit.whole=!0,e.finish()}export function setFreeze(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t&&(t.row>0||t.col>0)?r.freeze=y(t):delete r.freeze,e.edit.whole=!0,e.finish()}export function setHidden(o,s,t,n,e,r){const i=o.workbook.sheet(s);if(!i)return d("no-sheet");const c=new p(o),f=c.spec(i),u=(l,h)=>{const g=k(l[h]??{},"hidden");return r?{...l,[h]:{...g,hidden:!0}}:Object.keys(g).length===0?k(l,h):{...l,[h]:g}};if(t==="columns"){let l={...f.columns};const h=r?Array.from({length:e-n+1},(g,b)=>j(n+b)):Object.keys(l).filter(g=>{const b=L(g);return b!==void 0&&b>=n&&b<=e});for(const g of h)l=u(l,g);f.columns=l}else{let l={...f.rows};const h=r?Array.from({length:e-n+1},(g,b)=>String(n+b+1)):Object.keys(l).filter(g=>{const b=Number(g)-1;return b>=n&&b<=e});for(const g of h)l=u(l,g);f.rows=l}return E(f),c.edit.whole=!0,c.finish()}export function setSheetHidden(o,s,t){const n=o.file.sheets,e=n.filter(u=>u.hidden!==!0),r=n.findIndex(u=>u.name===s),i=n[r];if(!i)return d("no-sheet");if(t&&e.length<=1)return d("last-sheet");const c=k(i,"hidden"),f=t?{...c,hidden:!0}:c;return{...M(),file:{...o.file,sheets:n.map((u,l)=>l===r?f:u)},whole:!0}}export function setTabColor(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t===void 0?delete r.tab:r.tab=t,e.finish()}export function setGridlines(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t?delete r.gridlines:r.gridlines=!1,e.finish()}export function toggleFilter(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r={row:t.top,col:t.left},i=n.tableAt(r.row,r.col);if(i){const h=e.table(n,i);return h.filter===!1?delete h.filter:h.filter=!1,e.edit.whole=!0,e.finish()}const c=e.spec(n);if(c.filter)return delete c.filter,e.edit.whole=!0,e.finish();const u=t.top===t.bottom&&t.left===t.right?v(n,r):t;if(!u)return d("no-data");const l=n.used;return c.filter={range:w({...u,bottom:Math.min(u.bottom,l?.bottom??u.bottom),right:Math.min(u.right,l?.right??u.right)})},e.edit.whole=!0,e.finish()}export function setFilterColumn(o,s,t,n,e){const r=o.workbook.sheet(s);if(!r)return d("no-sheet");const i=new p(o),{table:c}=t;if(c){const f=i.table(r,c),u=c.columns[n-c.at.col]?.name??"",l=k(f.filter===!1||!f.filter?{}:f.filter.columns,u),h=e?{...l,[u]:e}:l;Object.keys(h).length===0?delete f.filter:f.filter={columns:h}}else{const f=i.spec(r);if(!f.filter)return d("no-sheet");const u=j(n),l=k(f.filter.columns??{},u),h=e?{...l,[u]:e}:l;f.filter={range:f.filter.range,...Object.keys(h).length===0?{}:{columns:h}}}return i.edit.whole=!0,i.finish()}export function clearFilters(o,s){const t=o.workbook.sheet(s);if(!t)return d("no-sheet");const n=new p(o),e=n.spec(t);e.filter&&(e.filter={range:e.filter.range});for(const r of t.tables)r.spec.filter&&delete n.table(t,r).filter;return n.edit.whole=!0,n.finish()}export function addConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return r.conditional=[t,...r.conditional??[]],e.edit.whole=!0,e.finish()}function H(o,s){if(!a(o,s))return[o];const t=[];s.top>o.top&&t.push({...o,bottom:s.top-1}),s.bottom<o.bottom&&t.push({...o,top:s.bottom+1});const n=Math.max(o.top,s.top),e=Math.min(o.bottom,s.bottom);return s.left>o.left&&t.push({...o,top:n,bottom:e,right:s.left-1}),s.right<o.right&&t.push({...o,top:n,bottom:e,left:s.right+1}),t}function B(o,s){const t=R(o);if(!t)return o;const n=t.flatMap(e=>H(e,s));return n.length===0?void 0:n.map(w).join(" ")}export function clearConditional(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=t?(r.conditional??[]).flatMap(c=>{const f=B(c.range,t);return f===void 0?[]:[{...c,range:f}]}):[];return i.length===0?delete r.conditional:r.conditional=i,e.edit.whole=!0,e.finish()}export function setValidation(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=(i.validations??[]).flatMap(u=>{const l=B(u.range,t);return l===void 0?[]:[{...u,range:l}]}),f=n?[...c,{...n,range:w(t)}]:c;return f.length===0?delete i.validations:i.validations=f,r.edit.whole=!0,r.finish()}export const WHOLE_SHEET={top:0,left:0,bottom:_-1,right:S-1};export function addChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return r.charts=[...r.charts??[],t],e.finish()}export function setChart(o,s,t,n){const e=o.workbook.sheet(s),r=e?.spec.charts?.[t];if(!e||!r)return d("no-sheet");const i=new p(o),c=i.spec(e),f=Object.fromEntries(Object.entries({...r,...n}).filter(([,u])=>u!==void 0));return c.charts=(c.charts??[]).map((u,l)=>l===t?f:u),i.finish()}export function removeChart(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=(r.charts??[]).filter((c,f)=>f!==t);return i.length>0?r.charts=i:delete r.charts,e.finish()}export function setNote(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=y(t),f=Object.fromEntries(Object.entries(i.notes??{}).filter(([u])=>u!==c));return n!==void 0&&n.text.trim()!==""&&(f[c]=n.author===void 0||n.author===""?n.text:{text:n.text,author:n.author}),Object.keys(f).length===0?delete i.notes:i.notes=f,r.finish()}export function setLink(o,s,t,n){const e=o.workbook.sheet(s);if(!e)return d("no-sheet");const r=new p(o),i=r.spec(e),c=Object.fromEntries(Object.entries(i.links??{}).filter(([f])=>{const u=O(f);return u===void 0||!a(u,t)}));if(n!==void 0&&n.trim()!==""){c[w(t)]=n.trim();const f=e.lookAt(t.top,t.left);f.color===void 0&&f.underline===void 0&&x(r,e,t,HYPERLINK_LOOK)}return Object.keys(c).length===0?delete i.links:i.links=c,E(i),r.finish()}export const HYPERLINK_LOOK={color:"#0563C1",underline:!0};export function setProtect(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t?r.protect=!0:delete r.protect,e.finish()}export function protectedIn(o,s){if(o.spec.protect!==!0)return!1;const t=Math.min(s.bottom,Math.max(s.top,o.lastRow+1)),n=Math.min(s.right,Math.max(s.left,o.columnsUsed+1));for(let e=s.top;e<=t;e++)for(let r=s.left;r<=n;r++)if(o.lookAt(e,r).locked!==!1)return!0;return!1}export function setConditionals(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n);return t.length===0?delete r.conditional:r.conditional=[...t],e.edit.whole=!0,e.finish()}export function setPrint(o,s,t){const n=o.workbook.sheet(s);if(!n)return d("no-sheet");const e=new p(o),r=e.spec(n),i=Object.fromEntries(Object.entries({...r.print,...t}).filter(([,c])=>c!==void 0));return Object.keys(i).length===0?delete r.print:r.print=i,e.finish()}
@@ -0,0 +1,42 @@
1
+ import type { Area } from "./address.js";
2
+ import { type BookEdit, type EditBook } from "./edit.js";
3
+ import type { Calc } from "./calc/engine.js";
4
+ import { type Scalar } from "./values.js";
5
+ /** Which rows of values to keep: the first of each, by the columns given (all when none). */
6
+ export declare function uniqueRows(rows: readonly (readonly Scalar[])[], columns: readonly number[]): boolean[];
7
+ /**
8
+ * Remove Duplicates over an area: its header row left out when it has one,
9
+ * the rows kept closing up from the top, what is left at the foot cleared.
10
+ * Says how many rows went (`duplicates`) and stayed (`unique`).
11
+ */
12
+ export declare function removeDuplicates(book: EditBook, calc: Calc, sheetName: string, area: Area, o: {
13
+ header: boolean;
14
+ columns: readonly number[];
15
+ }): BookEdit & {
16
+ duplicates: number;
17
+ unique: number;
18
+ };
19
+ export interface SplitOptions {
20
+ /** Delimited: what splits, Excel's Tab, Semicolon, Comma, Space and Other. */
21
+ delimiters?: readonly string[];
22
+ /** Treat consecutive delimiters as one. */
23
+ consecutive?: boolean;
24
+ /** Text Qualifier: a delimiter inside it does not split. */
25
+ qualifier?: string;
26
+ /** Fixed width: where each break is, in characters from the start. */
27
+ widths?: readonly number[];
28
+ }
29
+ /** A text split as Text to Columns splits it. */
30
+ export declare function splitText(text: string, o: SplitOptions): string[];
31
+ /**
32
+ * Text to Columns over a column's cells: each one's text split into the
33
+ * columns from the destination on (the column itself unless it says),
34
+ * each part read as typed.
35
+ */
36
+ export declare function textToColumns(book: EditBook, calc: Calc, sheetName: string, area: Area, o: SplitOptions & {
37
+ destination?: {
38
+ row: number;
39
+ col: number;
40
+ };
41
+ }): BookEdit;
42
+ //# sourceMappingURL=data-tools.d.ts.map
@@ -0,0 +1,2 @@
1
+ /*! AllyHub. Copyright (c) 2026 AllyHub, Inc. All rights reserved. Use is subject to LICENSE.md. */
2
+ import{inputOf as y,refused as g,writeCells as q}from"./edit.js";import{moveFormula as x}from"./formula/move.js";import{parseFormula as A}from"./formula/parse.js";import{printFormula as C}from"./formula/print.js";import{CellError as E}from"./values.js";const $=t=>t===null?"":typeof t=="string"?`s${t.toLowerCase()}`:t instanceof E?`e${t.code}`:`${typeof t}${String(t)}`;export function uniqueRows(t,o){const i=new Set;return t.map(e=>{const s=(o.length===0?e.map((l,n)=>n):o).map(l=>$(e[l]??null)).join("\0");return i.has(s)?!1:(i.add(s),!0)})}function F(t,o){if(o===0||!t.startsWith("="))return t;const i=A(t);return i.ok?C(x(i.node,o,0)):t}export function removeDuplicates(t,o,i,e,u){const s=t.workbook.sheet(i);if(!s)return{...g("no-sheet"),duplicates:0,unique:0};const l=u.header?e.top+1:e.top,n=e.right-e.left+1,r=[],p=[];for(let f=l;f<=e.bottom;f++)r.push(Array.from({length:n},(m,w)=>o.value(s,f,e.left+w))),p.push(Array.from({length:n},(m,w)=>y(t,s,f,e.left+w)));const c=uniqueRows(r,u.columns.map(f=>f-e.left)),d=[];let h=l;c.forEach((f,m)=>{const w=l+m;f&&(w!==h&&p[m]?.forEach((k,b)=>{d.push({row:h,col:e.left+b,text:F(k,h-w)})}),h+=1)});for(let f=h;f<=e.bottom;f++)for(let m=0;m<n;m++)d.push({row:f,col:e.left+m,text:""});const a=h-l;return{...q(t,i,d),duplicates:c.length-a,unique:a}}export function splitText(t,o){if(o.widths&&o.widths.length>0){const n=[...new Set(o.widths)].filter(c=>c>0).sort((c,d)=>c-d),r=[];let p=0;for(const c of n)r.push(t.slice(p,c).trim()),p=c;return r.push(t.slice(p).trim()),r}const i=o.delimiters??[];if(i.length===0)return[t];const e=[];let u="",s=!1,l=!1;for(let n=0;n<t.length;n++){const r=t.charAt(n);if(o.qualifier&&r===o.qualifier){s&&t.charAt(n+1)===o.qualifier?(u+=r,n+=1):s=!s,l=!1;continue}if(!s&&i.includes(r)){o.consecutive===!0&&l||e.push(u),u="",l=!0;continue}u+=r,l=!1}return e.push(u),e}export function textToColumns(t,o,i,e,u){const s=t.workbook.sheet(i);if(!s)return g("no-sheet");const l=u.destination??{row:e.top,col:e.left},n=[];for(let r=e.top;r<=e.bottom;r++){const p=o.value(s,r,e.left);if(p===null)continue;const c=typeof p=="string"?p:y(t,s,r,e.left);splitText(c,u).forEach((d,h)=>{n.push({row:l.row+r-e.top,col:l.col+h,text:d})})}return n.length===0?g("no-data"):q(t,i,n)}