@trebco/treb 23.6.5 → 25.0.0-rc1

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 (217) hide show
  1. package/.eslintignore +8 -0
  2. package/.eslintrc.js +164 -0
  3. package/README-shadow-DOM.md +88 -0
  4. package/README.md +37 -130
  5. package/api-config.json +29 -0
  6. package/api-generator/api-generator-types.ts +82 -0
  7. package/api-generator/api-generator.ts +1172 -0
  8. package/api-generator/package.json +3 -0
  9. package/build/treb-spreadsheet.mjs +14 -0
  10. package/{treb.d.ts → build/treb.d.ts} +285 -269
  11. package/esbuild-custom-element.mjs +336 -0
  12. package/esbuild.js +305 -0
  13. package/package.json +43 -14
  14. package/treb-base-types/package.json +5 -0
  15. package/treb-base-types/src/api_types.ts +36 -0
  16. package/treb-base-types/src/area.ts +583 -0
  17. package/treb-base-types/src/basic_types.ts +45 -0
  18. package/treb-base-types/src/cell.ts +612 -0
  19. package/treb-base-types/src/cells.ts +1066 -0
  20. package/treb-base-types/src/color.ts +124 -0
  21. package/treb-base-types/src/import.ts +71 -0
  22. package/treb-base-types/src/index-standalone.ts +29 -0
  23. package/treb-base-types/src/index.ts +42 -0
  24. package/treb-base-types/src/layout.ts +47 -0
  25. package/treb-base-types/src/localization.ts +187 -0
  26. package/treb-base-types/src/rectangle.ts +145 -0
  27. package/treb-base-types/src/render_text.ts +72 -0
  28. package/treb-base-types/src/style.ts +545 -0
  29. package/treb-base-types/src/table.ts +109 -0
  30. package/treb-base-types/src/text_part.ts +54 -0
  31. package/treb-base-types/src/theme.ts +608 -0
  32. package/treb-base-types/src/union.ts +152 -0
  33. package/treb-base-types/src/value-type.ts +164 -0
  34. package/treb-base-types/style/resizable.css +59 -0
  35. package/treb-calculator/modern.tsconfig.json +11 -0
  36. package/treb-calculator/package.json +5 -0
  37. package/treb-calculator/src/calculator.ts +2546 -0
  38. package/treb-calculator/src/complex-math.ts +558 -0
  39. package/treb-calculator/src/dag/array-vertex.ts +198 -0
  40. package/treb-calculator/src/dag/graph.ts +951 -0
  41. package/treb-calculator/src/dag/leaf_vertex.ts +118 -0
  42. package/treb-calculator/src/dag/spreadsheet_vertex.ts +327 -0
  43. package/treb-calculator/src/dag/spreadsheet_vertex_base.ts +44 -0
  44. package/treb-calculator/src/dag/vertex.ts +352 -0
  45. package/treb-calculator/src/descriptors.ts +162 -0
  46. package/treb-calculator/src/expression-calculator.ts +1069 -0
  47. package/treb-calculator/src/function-error.ts +103 -0
  48. package/treb-calculator/src/function-library.ts +103 -0
  49. package/treb-calculator/src/functions/base-functions.ts +1214 -0
  50. package/treb-calculator/src/functions/checkbox.ts +164 -0
  51. package/treb-calculator/src/functions/complex-functions.ts +253 -0
  52. package/treb-calculator/src/functions/finance-functions.ts +399 -0
  53. package/treb-calculator/src/functions/information-functions.ts +102 -0
  54. package/treb-calculator/src/functions/matrix-functions.ts +182 -0
  55. package/treb-calculator/src/functions/sparkline.ts +335 -0
  56. package/treb-calculator/src/functions/statistics-functions.ts +350 -0
  57. package/treb-calculator/src/functions/text-functions.ts +298 -0
  58. package/treb-calculator/src/index.ts +27 -0
  59. package/treb-calculator/src/notifier-types.ts +59 -0
  60. package/treb-calculator/src/primitives.ts +428 -0
  61. package/treb-calculator/src/utilities.ts +305 -0
  62. package/treb-charts/package.json +5 -0
  63. package/treb-charts/src/chart-functions.ts +156 -0
  64. package/treb-charts/src/chart-types.ts +230 -0
  65. package/treb-charts/src/chart.ts +1288 -0
  66. package/treb-charts/src/index.ts +24 -0
  67. package/treb-charts/src/main.ts +37 -0
  68. package/treb-charts/src/rectangle.ts +52 -0
  69. package/treb-charts/src/renderer.ts +1841 -0
  70. package/treb-charts/src/util.ts +122 -0
  71. package/treb-charts/style/charts.scss +221 -0
  72. package/treb-charts/style/old-charts.scss +250 -0
  73. package/treb-embed/markup/layout.html +137 -0
  74. package/treb-embed/markup/toolbar.html +175 -0
  75. package/treb-embed/modern.tsconfig.json +25 -0
  76. package/treb-embed/src/custom-element/content-types.d.ts +18 -0
  77. package/treb-embed/src/custom-element/global.d.ts +11 -0
  78. package/treb-embed/src/custom-element/spreadsheet-constructor.ts +1227 -0
  79. package/treb-embed/src/custom-element/treb-global.ts +44 -0
  80. package/treb-embed/src/custom-element/treb-spreadsheet-element.ts +52 -0
  81. package/treb-embed/src/embedded-spreadsheet.ts +5362 -0
  82. package/treb-embed/src/index.ts +16 -0
  83. package/treb-embed/src/language-model.ts +41 -0
  84. package/treb-embed/src/options.ts +320 -0
  85. package/treb-embed/src/progress-dialog.ts +228 -0
  86. package/treb-embed/src/selection-state.ts +16 -0
  87. package/treb-embed/src/spinner.ts +42 -0
  88. package/treb-embed/src/toolbar-message.ts +96 -0
  89. package/treb-embed/src/types.ts +167 -0
  90. package/treb-embed/style/autocomplete.scss +103 -0
  91. package/treb-embed/style/dark-theme.scss +114 -0
  92. package/treb-embed/style/defaults.scss +36 -0
  93. package/treb-embed/style/dialog.scss +181 -0
  94. package/treb-embed/style/dropdown-select.scss +101 -0
  95. package/treb-embed/style/formula-bar.scss +193 -0
  96. package/treb-embed/style/grid.scss +374 -0
  97. package/treb-embed/style/layout.scss +424 -0
  98. package/treb-embed/style/mouse-mask.scss +67 -0
  99. package/treb-embed/style/note.scss +92 -0
  100. package/treb-embed/style/overlay-editor.scss +102 -0
  101. package/treb-embed/style/spinner.scss +92 -0
  102. package/treb-embed/style/tab-bar.scss +228 -0
  103. package/treb-embed/style/table.scss +80 -0
  104. package/treb-embed/style/theme-defaults.scss +444 -0
  105. package/treb-embed/style/toolbar.scss +416 -0
  106. package/treb-embed/style/tooltip.scss +68 -0
  107. package/treb-embed/style/treb-icons.scss +130 -0
  108. package/treb-embed/style/treb-spreadsheet-element.scss +20 -0
  109. package/treb-embed/style/z-index.scss +43 -0
  110. package/treb-export/docs/charts.md +68 -0
  111. package/treb-export/modern.tsconfig.json +19 -0
  112. package/treb-export/package.json +4 -0
  113. package/treb-export/src/address-type.ts +77 -0
  114. package/treb-export/src/base-template.ts +22 -0
  115. package/treb-export/src/column-width.ts +85 -0
  116. package/treb-export/src/drawing2/chart-template-components2.ts +389 -0
  117. package/treb-export/src/drawing2/chart2.ts +282 -0
  118. package/treb-export/src/drawing2/column-chart-template2.ts +521 -0
  119. package/treb-export/src/drawing2/donut-chart-template2.ts +296 -0
  120. package/treb-export/src/drawing2/drawing2.ts +355 -0
  121. package/treb-export/src/drawing2/embedded-image.ts +71 -0
  122. package/treb-export/src/drawing2/scatter-chart-template2.ts +555 -0
  123. package/treb-export/src/export-worker/export-worker.ts +99 -0
  124. package/treb-export/src/export-worker/index-modern.ts +22 -0
  125. package/treb-export/src/export2.ts +2204 -0
  126. package/treb-export/src/import2.ts +882 -0
  127. package/treb-export/src/relationship.ts +36 -0
  128. package/treb-export/src/shared-strings2.ts +128 -0
  129. package/treb-export/src/template-2.ts +22 -0
  130. package/treb-export/src/unescape_xml.ts +47 -0
  131. package/treb-export/src/workbook-sheet2.ts +182 -0
  132. package/treb-export/src/workbook-style2.ts +1285 -0
  133. package/treb-export/src/workbook-theme2.ts +88 -0
  134. package/treb-export/src/workbook2.ts +491 -0
  135. package/treb-export/src/xml-utils.ts +201 -0
  136. package/treb-export/template/base/[Content_Types].xml +2 -0
  137. package/treb-export/template/base/_rels/.rels +2 -0
  138. package/treb-export/template/base/docProps/app.xml +2 -0
  139. package/treb-export/template/base/docProps/core.xml +12 -0
  140. package/treb-export/template/base/xl/_rels/workbook.xml.rels +2 -0
  141. package/treb-export/template/base/xl/sharedStrings.xml +2 -0
  142. package/treb-export/template/base/xl/styles.xml +2 -0
  143. package/treb-export/template/base/xl/theme/theme1.xml +2 -0
  144. package/treb-export/template/base/xl/workbook.xml +2 -0
  145. package/treb-export/template/base/xl/worksheets/sheet1.xml +2 -0
  146. package/treb-export/template/base.xlsx +0 -0
  147. package/treb-format/package.json +8 -0
  148. package/treb-format/src/format.test.ts +213 -0
  149. package/treb-format/src/format.ts +942 -0
  150. package/treb-format/src/format_cache.ts +199 -0
  151. package/treb-format/src/format_parser.ts +723 -0
  152. package/treb-format/src/index.ts +25 -0
  153. package/treb-format/src/number_format_section.ts +100 -0
  154. package/treb-format/src/value_parser.ts +337 -0
  155. package/treb-grid/package.json +5 -0
  156. package/treb-grid/src/editors/autocomplete.ts +394 -0
  157. package/treb-grid/src/editors/autocomplete_matcher.ts +260 -0
  158. package/treb-grid/src/editors/formula_bar.ts +473 -0
  159. package/treb-grid/src/editors/formula_editor_base.ts +910 -0
  160. package/treb-grid/src/editors/overlay_editor.ts +511 -0
  161. package/treb-grid/src/index.ts +37 -0
  162. package/treb-grid/src/layout/base_layout.ts +2618 -0
  163. package/treb-grid/src/layout/grid_layout.ts +299 -0
  164. package/treb-grid/src/layout/rectangle_cache.ts +86 -0
  165. package/treb-grid/src/render/selection-renderer.ts +414 -0
  166. package/treb-grid/src/render/svg_header_overlay.ts +93 -0
  167. package/treb-grid/src/render/svg_selection_block.ts +187 -0
  168. package/treb-grid/src/render/tile_renderer.ts +2122 -0
  169. package/treb-grid/src/types/annotation.ts +216 -0
  170. package/treb-grid/src/types/border_constants.ts +34 -0
  171. package/treb-grid/src/types/clipboard_data.ts +31 -0
  172. package/treb-grid/src/types/data_model.ts +334 -0
  173. package/treb-grid/src/types/drag_mask.ts +81 -0
  174. package/treb-grid/src/types/grid.ts +7743 -0
  175. package/treb-grid/src/types/grid_base.ts +3644 -0
  176. package/treb-grid/src/types/grid_command.ts +470 -0
  177. package/treb-grid/src/types/grid_events.ts +124 -0
  178. package/treb-grid/src/types/grid_options.ts +97 -0
  179. package/treb-grid/src/types/grid_selection.ts +60 -0
  180. package/treb-grid/src/types/named_range.ts +369 -0
  181. package/treb-grid/src/types/scale-control.ts +202 -0
  182. package/treb-grid/src/types/serialize_options.ts +72 -0
  183. package/treb-grid/src/types/set_range_options.ts +52 -0
  184. package/treb-grid/src/types/sheet.ts +3099 -0
  185. package/treb-grid/src/types/sheet_types.ts +95 -0
  186. package/treb-grid/src/types/tab_bar.ts +464 -0
  187. package/treb-grid/src/types/tile.ts +59 -0
  188. package/treb-grid/src/types/update_flags.ts +75 -0
  189. package/treb-grid/src/util/dom_utilities.ts +44 -0
  190. package/treb-grid/src/util/fontmetrics2.ts +179 -0
  191. package/treb-grid/src/util/ua.ts +104 -0
  192. package/treb-logo.svg +18 -0
  193. package/treb-parser/package.json +5 -0
  194. package/treb-parser/src/csv-parser.ts +122 -0
  195. package/treb-parser/src/index.ts +25 -0
  196. package/treb-parser/src/md-parser.ts +526 -0
  197. package/treb-parser/src/parser-types.ts +397 -0
  198. package/treb-parser/src/parser.test.ts +298 -0
  199. package/treb-parser/src/parser.ts +2673 -0
  200. package/treb-utils/package.json +5 -0
  201. package/treb-utils/src/dispatch.ts +57 -0
  202. package/treb-utils/src/event_source.ts +147 -0
  203. package/treb-utils/src/ievent_source.ts +33 -0
  204. package/treb-utils/src/index.ts +31 -0
  205. package/treb-utils/src/measurement.ts +174 -0
  206. package/treb-utils/src/resizable.ts +160 -0
  207. package/treb-utils/src/scale.ts +137 -0
  208. package/treb-utils/src/serialize_html.ts +124 -0
  209. package/treb-utils/src/template.ts +70 -0
  210. package/treb-utils/src/validate_uri.ts +61 -0
  211. package/tsconfig.json +10 -0
  212. package/tsproject.json +30 -0
  213. package/util/license-plugin-esbuild.js +86 -0
  214. package/util/list-css-vars.sh +46 -0
  215. package/README-esm.md +0 -37
  216. package/treb-bundle.css +0 -2
  217. package/treb-bundle.mjs +0 -15
@@ -0,0 +1,296 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
+ export const donut_json =
23
+ {
24
+ 'c:title': {},
25
+ 'c:autoTitleDeleted': {
26
+ a$: {
27
+ 'val': '0'
28
+ }
29
+ },
30
+ 'c:plotArea': {
31
+ 'c:layout': {},
32
+ 'c:doughnutChart': {
33
+ 'c:varyColors': {
34
+ a$: {
35
+ 'val': '1'
36
+ }
37
+ },
38
+ 'c:ser': {
39
+ 'c:idx': {
40
+ a$: {
41
+ 'val': '0'
42
+ }
43
+ },
44
+ 'c:order': {
45
+ a$: {
46
+ 'val': '0'
47
+ }
48
+ },
49
+
50
+ 'c:dPt': {
51
+ 'c:idx': {
52
+ a$: {
53
+ 'val': '3'
54
+ }
55
+ },
56
+ 'c:bubble3D': {
57
+ a$: {
58
+ 'val': '0'
59
+ }
60
+ },
61
+ 'c:spPr': {
62
+ 'a:solidFill': {
63
+ 'a:schemeClr': {
64
+ a$: {
65
+ 'val': 'accent4'
66
+ }
67
+ }
68
+ },
69
+ 'a:ln': {
70
+ a$: {
71
+ 'w': '19050'
72
+ },
73
+ 'a:solidFill': {
74
+ 'a:schemeClr': {
75
+ a$: {
76
+ 'val': 'lt1'
77
+ }
78
+ }
79
+ }
80
+ },
81
+ 'a:effectLst': {}
82
+ },
83
+ 'c:extLst': {
84
+ 'c:ext': {
85
+ a$: {
86
+ 'uri': '{C3380CC4-5D6E-409C-BE32-E72D297353CC}',
87
+ 'xmlns:c16': 'http://schemas.microsoft.com/office/drawing/2014/chart'
88
+ },
89
+ 'c16:uniqueId': {
90
+ a$: {
91
+ 'val': '{00000007-E886-49A6-AE6D-C67D8A27530F}'
92
+ }
93
+ }
94
+ }
95
+ }
96
+ },
97
+ 'c:cat': {
98
+ 'c:strRef': {
99
+ 'c:f': '', // ref: 'Sheet1!$E$5:$E$8'
100
+ }
101
+ },
102
+ 'c:val': {
103
+ 'c:numRef': {
104
+ 'c:f': '', // ref: 'Sheet1!$F$5:$F$8'
105
+ }
106
+ },
107
+ 'c:extLst': {
108
+ 'c:ext': {
109
+ a$: {
110
+ 'uri': '{C3380CC4-5D6E-409C-BE32-E72D297353CC}',
111
+ 'xmlns:c16': 'http://schemas.microsoft.com/office/drawing/2014/chart'
112
+ },
113
+ 'c16:uniqueId': {
114
+ a$: {
115
+ 'val': '{00000000-3689-4BB4-A84F-05B9F3BBE577}'
116
+ }
117
+ }
118
+ }
119
+ }
120
+ },
121
+ 'c:dLbls': {
122
+ 'c:showLegendKey': {
123
+ a$: {
124
+ 'val': '0'
125
+ }
126
+ },
127
+ 'c:showVal': {
128
+ a$: {
129
+ 'val': '0'
130
+ }
131
+ },
132
+ 'c:showCatName': {
133
+ a$: {
134
+ 'val': '0'
135
+ }
136
+ },
137
+ 'c:showSerName': {
138
+ a$: {
139
+ 'val': '0'
140
+ }
141
+ },
142
+ 'c:showPercent': {
143
+ a$: {
144
+ 'val': '0'
145
+ }
146
+ },
147
+ 'c:showBubbleSize': {
148
+ a$: {
149
+ 'val': '0'
150
+ }
151
+ },
152
+ 'c:showLeaderLines': {
153
+ a$: {
154
+ 'val': '1'
155
+ }
156
+ }
157
+ },
158
+ 'c:firstSliceAng': {
159
+ a$: {
160
+ 'val': '0'
161
+ }
162
+ },
163
+ 'c:holeSize': {
164
+ a$: {
165
+ 'val': '75'
166
+ }
167
+ }
168
+ },
169
+ 'c:spPr': {
170
+ 'a:noFill': {},
171
+ 'a:ln': {
172
+ 'a:noFill': {}
173
+ },
174
+ 'a:effectLst': {}
175
+ }
176
+ },
177
+ 'c:legend': {
178
+ 'c:legendPos': {
179
+ a$: {
180
+ 'val': 'b'
181
+ }
182
+ },
183
+ 'c:overlay': {
184
+ a$: {
185
+ 'val': '0'
186
+ }
187
+ },
188
+ 'c:spPr': {
189
+ 'a:noFill': {},
190
+ 'a:ln': {
191
+ 'a:noFill': {}
192
+ },
193
+ 'a:effectLst': {}
194
+ },
195
+ 'c:txPr': {
196
+ 'a:bodyPr': {
197
+ a$: {
198
+ 'rot': '0',
199
+ 'spcFirstLastPara': '1',
200
+ 'vertOverflow': 'ellipsis',
201
+ 'vert': 'horz',
202
+ 'wrap': 'square',
203
+ 'anchor': 'ctr',
204
+ 'anchorCtr': '1'
205
+ }
206
+ },
207
+ 'a:lstStyle': {},
208
+ 'a:p': {
209
+ 'a:pPr': {
210
+ a$: {
211
+ 'rtl': '0'
212
+ },
213
+ 'a:defRPr': {
214
+ a$: {
215
+ 'sz': '900',
216
+ 'b': '0',
217
+ 'i': '0',
218
+ 'u': 'none',
219
+ 'strike': 'noStrike',
220
+ 'kern': '1200',
221
+ 'baseline': '0'
222
+ },
223
+ 'a:solidFill': {
224
+ 'a:schemeClr': {
225
+ a$: {
226
+ 'val': 'tx1'
227
+ },
228
+ 'a:lumMod': {
229
+ a$: {
230
+ 'val': '65000'
231
+ }
232
+ },
233
+ 'a:lumOff': {
234
+ a$: {
235
+ 'val': '35000'
236
+ }
237
+ }
238
+ }
239
+ },
240
+ 'a:latin': {
241
+ a$: {
242
+ 'typeface': '+mn-lt'
243
+ }
244
+ },
245
+ 'a:ea': {
246
+ a$: {
247
+ 'typeface': '+mn-ea'
248
+ }
249
+ },
250
+ 'a:cs': {
251
+ a$: {
252
+ 'typeface': '+mn-cs'
253
+ }
254
+ }
255
+ }
256
+ },
257
+ 'a:endParaRPr': {
258
+ a$: {
259
+ 'lang': 'en-US'
260
+ }
261
+ }
262
+ }
263
+ }
264
+ },
265
+ 'c:plotVisOnly': {
266
+ a$: {
267
+ 'val': '1'
268
+ }
269
+ },
270
+ 'c:dispBlanksAs': {
271
+ a$: {
272
+ 'val': 'gap'
273
+ }
274
+ },
275
+ 'c:extLst': {
276
+ 'c:ext': {
277
+ a$: {
278
+ 'uri': '{56B9EC1D-385E-4148-901F-78D8002777C0}',
279
+ 'xmlns:c16r3': 'http://schemas.microsoft.com/office/drawing/2017/03/chart'
280
+ },
281
+ 'c16r3:dataDisplayOptions16': {
282
+ 'c16r3:dispNaAsBlank': {
283
+ a$: {
284
+ 'val': '1'
285
+ }
286
+ }
287
+ }
288
+ }
289
+ },
290
+ 'c:showDLblsOverMax': {
291
+ a$: {
292
+ 'val': '0'
293
+ }
294
+ }
295
+
296
+ };
@@ -0,0 +1,355 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2023 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+
22
+ import { EmbeddedImage, ImageOptions } from './embedded-image';
23
+ import { Chart, ChartOptions} from './chart2';
24
+ import { RelationshipMap, AddRel } from '../relationship';
25
+ import { Corner } from 'treb-base-types/src';
26
+
27
+ const pixel_offset = 9525;
28
+
29
+ export interface CellAnchor {
30
+ row: number;
31
+ column_offset?: number;
32
+ column: number;
33
+ row_offset?: number;
34
+ }
35
+
36
+ export interface TwoCellAnchor {
37
+ from: CellAnchor;
38
+ to: CellAnchor;
39
+ }
40
+
41
+ export interface AnchoredChart {
42
+ anchor: TwoCellAnchor;
43
+ chart: Chart;
44
+ relationship: string;
45
+ }
46
+
47
+ export interface AnchoredImage {
48
+ anchor: TwoCellAnchor;
49
+ image: EmbeddedImage;
50
+ relationship: string;
51
+ }
52
+
53
+ export interface JSONCorner {
54
+ 'xdr:col': number,
55
+ 'xdr:colOff': number,
56
+ 'xdr:row': number,
57
+ 'xdr:rowOff': number,
58
+ }
59
+
60
+ export class Drawing {
61
+
62
+ public static next_drawing_index = 1;
63
+
64
+ /** relationship id sheet -> drawing */
65
+ public sheet_drawing_relationship = 0;
66
+
67
+ public charts: AnchoredChart[] = [];
68
+ public images: AnchoredImage[] = [];
69
+
70
+ public relationships: RelationshipMap = {};
71
+
72
+ constructor(public index = Drawing.next_drawing_index++){}
73
+
74
+ public AddImage(options: ImageOptions, anchor: TwoCellAnchor): void {
75
+ const image = new EmbeddedImage(options);
76
+ if (image.extension) {
77
+ const relationship = AddRel(this.relationships,
78
+ 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
79
+ `../media/image${image.index}.${image.extension}`);
80
+ this.images.push({image, relationship, anchor});
81
+ }
82
+ }
83
+
84
+ public AddChart(options: ChartOptions, anchor: TwoCellAnchor): void {
85
+ const chart = new Chart(options);
86
+ const relationship = AddRel(this.relationships,
87
+ `http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart`,
88
+ `../charts/chart${chart.index}.xml`);
89
+ this.charts.push({chart, anchor, relationship});
90
+ }
91
+
92
+ public CornerToJSON(anchor: CellAnchor): JSONCorner {
93
+ return {
94
+ 'xdr:col': anchor.column,
95
+ 'xdr:colOff': (anchor.column_offset || 0) * pixel_offset,
96
+ 'xdr:row': anchor.row,
97
+ 'xdr:rowOff': (anchor.row_offset || 0) * pixel_offset,
98
+ };
99
+ }
100
+
101
+ public AnchorToJSON(anchor: TwoCellAnchor): { 'xdr:from': JSONCorner, 'xdr:to': JSONCorner } {
102
+ return {
103
+ 'xdr:from': { ...this.CornerToJSON(anchor.from), },
104
+ 'xdr:to': { ...this.CornerToJSON(anchor.to), },
105
+ };
106
+ }
107
+
108
+ public toJSON(): any {
109
+
110
+ const image_blocks: any[] =
111
+ this.images.map(image => {
112
+ const block = {
113
+ a$: { editAs: 'oneCell' },
114
+ ...this.AnchorToJSON(image.anchor),
115
+ 'xdr:pic': {
116
+ 'xdr:nvPicPr': {
117
+ 'xdr:cNvPr': /* image.image.extension === 'svg' ? {
118
+ a$: { id: image.image.index + 1, name: 'Image ' + image.image.index},
119
+ 'a:extLst': {
120
+ 'a:ext': {
121
+ a$: { uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}' },
122
+ 'a16:creationId': {
123
+ a$: {
124
+ 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main',
125
+ },
126
+ },
127
+ },
128
+ },
129
+ } : */
130
+ {
131
+ a$: { id: image.image.index + 1, name: 'Image ' + image.image.index},
132
+ },
133
+ 'xdr:cNvPicPr': {
134
+ 'a:picLocks': {
135
+ a$: {
136
+ noChangeAspect: 1,
137
+ },
138
+ },
139
+ },
140
+ },
141
+ 'xdr:blipFill': {
142
+ 'a:blip': {
143
+ a$: image.image.extension === 'svg' ? {
144
+ 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
145
+ } : {
146
+ 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
147
+ 'r:embed': image.relationship,
148
+ },
149
+ 'a:extLst': {
150
+ 'a:ext': [
151
+ {
152
+ a$: {
153
+ uri: '{28A0092B-C50C-407E-A947-70E740481C1C}',
154
+ },
155
+ 'a14:useLocalDpi': {
156
+ a$: {
157
+ 'xmlns:a14': 'http://schemas.microsoft.com/office/drawing/2010/main', val: 0,
158
+ },
159
+ },
160
+ },
161
+ image.image.extension === 'svg' ? {
162
+ a$: {
163
+ uri: '{96DAC541-7B7A-43D3-8B79-37D633B846F1}',
164
+ },
165
+ 'asvg:svgBlip': {
166
+ a$: {
167
+ 'xmlns:asvg': 'http://schemas.microsoft.com/office/drawing/2016/SVG/main',
168
+ 'r:embed': image.relationship,
169
+ },
170
+ }
171
+ } : undefined,
172
+ ],
173
+ },
174
+ },
175
+ 'a:stretch': {
176
+ 'a:fillRect': {},
177
+ },
178
+ },
179
+
180
+ 'xdr:spPr': {
181
+ 'a:xfrm': {
182
+ 'a:off': {
183
+ a$: { x: 0, y: 0 },
184
+ },
185
+ 'a:ext': {
186
+ a$: { cx: 4057650, cy: 6172200, }, // ??
187
+ },
188
+ },
189
+ 'a:prstGeom': {
190
+ a$: { prst: 'rect', },
191
+ 'a:avLst': {},
192
+ },
193
+ },
194
+
195
+ /*
196
+ <xdr:nvPicPr>
197
+ <xdr:cNvPr id="3" name="Graphic 2">
198
+ <a:extLst>
199
+ <a:ext uri="{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}">
200
+ <a16:creationId xmlns:a16="http://schemas.microsoft.com/office/drawing/2014/main" id="{9BA0B4E8-3DD4-4297-8733-48C3F5D063BA}"/>
201
+ </a:ext>
202
+ </a:extLst>
203
+ </xdr:cNvPr>
204
+ <xdr:cNvPicPr>
205
+ <a:picLocks noChangeAspect="1"/>
206
+ </xdr:cNvPicPr>
207
+ </xdr:nvPicPr>
208
+
209
+ <xdr:blipFill>
210
+
211
+ [ this one is svg]
212
+
213
+ <a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1">
214
+ <a:extLst>
215
+ <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
216
+ <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>
217
+ </a:ext>
218
+ <a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}">
219
+ <asvg:svgBlip xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main" r:embed="rId2"/>
220
+ </a:ext>
221
+ </a:extLst>
222
+ </a:blip>
223
+
224
+ [alt]
225
+
226
+ <a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId3">
227
+ <a:extLst>
228
+ <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
229
+ <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>
230
+ </a:ext>
231
+ </a:extLst>
232
+ </a:blip>
233
+
234
+
235
+ <a:stretch>
236
+ <a:fillRect/>
237
+ </a:stretch>
238
+ </xdr:blipFill>
239
+
240
+ <xdr:spPr>
241
+ <a:xfrm>
242
+ <a:off x="0" y="0"/>
243
+ <a:ext cx="4057650" cy="6172200"/>
244
+ </a:xfrm>
245
+ <a:prstGeom prst="rect">
246
+ <a:avLst/>
247
+ </a:prstGeom>
248
+ </xdr:spPr>
249
+
250
+
251
+ */
252
+
253
+
254
+ },
255
+ 'xdr:clientData': {},
256
+ };
257
+ return block;
258
+ });
259
+
260
+ const chart_blocks: any[] =
261
+ this.charts.map(chart => {
262
+ const block = {
263
+ ...this.AnchorToJSON(chart.anchor),
264
+ 'xdr:graphicFrame': {
265
+ a$: { macro: '' },
266
+ 'xdr:nvGraphicFramePr': {
267
+ 'xdr:cNvPr': {
268
+ a$: { id: chart.chart.index + 1, name: `Chart ${chart.chart.index}`, },
269
+ /*
270
+ 'a:extLst': {
271
+ 'a:ext': {
272
+ a$: { uri: '{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}' },
273
+ 'a16:creationId': {
274
+ a$: { 'xmlns:a16': 'http://schemas.microsoft.com/office/drawing/2014/main' },
275
+ },
276
+ },
277
+ },
278
+ */
279
+ },
280
+ 'xdr:cNvGraphicFramePr': {},
281
+ },
282
+ 'xdr:xfrm': {
283
+ 'a:off': { a$: { x: 0, y: 0, }},
284
+ 'a:ext': { a$: { cx: 0, cy: 0 }},
285
+ },
286
+ 'a:graphic': {
287
+ 'a:graphicData': {
288
+ a$: { uri: 'http://schemas.openxmlformats.org/drawingml/2006/chart' },
289
+ 'c:chart': {
290
+ a$: {
291
+ 'xmlns:c': 'http://schemas.openxmlformats.org/drawingml/2006/chart',
292
+ 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
293
+ 'r:id': chart.relationship,
294
+ },
295
+ },
296
+ },
297
+ },
298
+ },
299
+ 'xdr:clientData': {},
300
+ };
301
+ return block;
302
+ });
303
+
304
+ const dom: any = {
305
+ 'xdr:wsDr': {
306
+ a$: {
307
+ 'xmlns:xdr': 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing',
308
+ 'xmlns:a': 'http://schemas.openxmlformats.org/drawingml/2006/main',
309
+ },
310
+ 'xdr:twoCellAnchor': [...chart_blocks, ...image_blocks],
311
+ },
312
+ };
313
+
314
+ return dom;
315
+
316
+ }
317
+
318
+ /*
319
+ public GetDrawingXML() {
320
+ const components: string[] = [`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">`];
321
+
322
+ for (let i = 0; i < this.charts.length; i++) {
323
+
324
+ const index = i + 1;
325
+ const anchor = this.charts[i].anchor;
326
+
327
+ components.push(
328
+ `<xdr:twoCellAnchor><xdr:from><xdr:col>${anchor.from.column}</xdr:col><xdr:colOff>${(anchor.from.column_offset || 0) * pixel_offset}</xdr:colOff>`
329
+ + `<xdr:row>${anchor.from.row}</xdr:row><xdr:rowOff>${(anchor.from.row_offset || 0) * pixel_offset}</xdr:rowOff></xdr:from>`
330
+ + `<xdr:to><xdr:col>${anchor.to.column}</xdr:col><xdr:colOff>${(anchor.to.column_offset || 0) * pixel_offset}</xdr:colOff>`
331
+ + `<xdr:row>${anchor.to.row}</xdr:row><xdr:rowOff>${(anchor.to.row_offset || 0) * pixel_offset}</xdr:rowOff></xdr:to>`
332
+ + `<xdr:graphicFrame macro=""><xdr:nvGraphicFramePr><xdr:cNvPr id="${index + 1}" name="Chart ${index}"><a:extLst><a:ext uri="{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}"><a16:creationId xmlns:a16="http://schemas.microsoft.com/office/drawing/2014/main" id="{9948BDEE-44B2-4E72-83C8-2C9C56F04EAA}"/></a:ext></a:extLst></xdr:cNvPr><xdr:cNvGraphicFramePr/></xdr:nvGraphicFramePr><xdr:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/></xdr:xfrm><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart"><c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId${index}"/></a:graphicData></a:graphic></xdr:graphicFrame><xdr:clientData/></xdr:twoCellAnchor>`
333
+ );
334
+
335
+ }
336
+ components.push(`</xdr:wsDr>`);
337
+ return components.join('');
338
+ }
339
+
340
+ public GetDrawingRels() {
341
+ const components: string[] = [ `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">`];
342
+
343
+ for (let i = 0; i < this.charts.length; i++) {
344
+ const index = i + 1;
345
+ const chart = this.charts[i].chart;
346
+ components.push(
347
+ `<Relationship Id="rId${index}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="../charts/chart${chart.index}.xml"/>`);
348
+ }
349
+
350
+ components.push(`</Relationships>`);
351
+ return components.join('');
352
+ }
353
+ */
354
+
355
+ }