@trebco/treb 23.6.2 → 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} +293 -299
  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,137 @@
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
+ /** calculated human-friendly scale for rendering axes */
23
+ export interface RangeScale {
24
+ scale: number;
25
+ step: number;
26
+ count: number;
27
+ min: number;
28
+ max: number;
29
+ }
30
+
31
+ /**
32
+ * making this a little more generic so we can use it outside of charts.
33
+ * specifically, for the sheet "histogram table" function. for that, we
34
+ * do need to ensure that the count is not greater than our request.
35
+ *
36
+ * we have a new parameter for that, default behavior should not change.
37
+ */
38
+ export const Scale = (min: number, max: number, count = 6.5, limit_count = false, discrete = false): RangeScale => {
39
+
40
+ if (max === min) {
41
+
42
+ // we should either have optional behavior here or have this as
43
+ // some sort of wrapper method -- it just seems arbitrary
44
+
45
+ max++;
46
+ if (min) {
47
+ min--;
48
+ }
49
+ }
50
+ else {
51
+
52
+ // let's fix this specific problem, where you get accumulated fp errors. round to 5 places...
53
+
54
+ // const tmp_range = max - min;
55
+ const rounded = Math.round(max * 100000) / 100000;
56
+
57
+ if (Math.abs(rounded - max) / (max - min) < 1e-5) {
58
+ max = rounded;
59
+ }
60
+
61
+ }
62
+
63
+ const range = max - min;
64
+
65
+ const log10 = Math.log(range) / Math.log(10); // just avoid the problem (problem being IE11 lack of Math.log10)
66
+
67
+ let scale = Math.floor(Math.abs(log10)) * (log10 < 0 ? -1 : 1) - 1;
68
+
69
+ // so if you claim you have discrete data, we want the minimum
70
+ // step to be 1. we also have slightly different acceptable steps.
71
+
72
+ if (discrete) {
73
+ scale = Math.max(0, scale);
74
+ }
75
+
76
+ const steps = discrete ?
77
+ [1, 2, 5, 10, 15, 20, 25, 50, 100] :
78
+ [.1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100];
79
+
80
+ let step = -1;
81
+ let delta = 0;
82
+
83
+ for (const x of steps) {
84
+ const test_step = x * Math.pow(10, scale);
85
+ const test_min = Math.floor(min / test_step) * test_step;
86
+ const test_max = Math.ceil(max / test_step) * test_step;
87
+ const test_count = (test_max - test_min) / test_step;
88
+ const test_delta = Math.abs(test_count - count);
89
+
90
+ if (step < 0 || test_delta < delta) {
91
+ if (!limit_count || (test_count <= count)) {
92
+ delta = test_delta;
93
+ step = test_step;
94
+ }
95
+ }
96
+
97
+ /*
98
+ else if (!limit_count && (test_delta < delta)) {
99
+ delta = test_delta;
100
+ step = test_step;
101
+ }
102
+ else if (limit_count && test_delta < delta && test_count <= count) {
103
+ delta = test_delta;
104
+ step = test_step;
105
+ }
106
+ */
107
+
108
+ /*
109
+
110
+ if (step < 0 || test_delta < delta){
111
+ delta = test_delta;
112
+ step = test_step;
113
+ }
114
+ else if (step >= 0 && test_delta > delta) {
115
+ if (limit_count) {
116
+ min = Math.floor(min / step) * step;
117
+ max = Math.ceil(max / step) * step;
118
+ const check = Math.round((max - min) / step);
119
+ if (check > count) {
120
+ delta = test_delta;
121
+ step = test_step;
122
+ continue;
123
+ }
124
+ }
125
+ break;
126
+ }
127
+ */
128
+
129
+ }
130
+
131
+ min = Math.floor(min / step) * step;
132
+ max = Math.ceil(max / step) * step;
133
+ count = Math.round((max - min) / step); // accounts for fp errors
134
+
135
+ return { scale, step, count, min, max };
136
+
137
+ }
@@ -0,0 +1,124 @@
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
+ interface StringMap {
23
+ [index: string]: string;
24
+ }
25
+
26
+ /**
27
+ * defaults are global, since we assume they never change. created on demand.
28
+ */
29
+ let default_properties: StringMap|undefined;
30
+
31
+ /**
32
+ * get applied style as text (for attribute)
33
+ */
34
+ const GetAppliedStyle = (node: Element, computed: CSSStyleDeclaration, defaults: StringMap) => {
35
+
36
+ const applied: StringMap = {};
37
+
38
+ Array.prototype.forEach.call(computed, (key) => {
39
+ if (computed[key] !== defaults[key]) {
40
+ applied[key] = computed[key];
41
+ }
42
+ });
43
+
44
+ return (Object.keys(applied).map((key) => `${key}: ${applied[key]}`).join('; ') +
45
+ '; ' + (node.getAttribute('style') || '')).trim().replace(/"/g, '\'');
46
+
47
+ };
48
+
49
+ /**
50
+ * create a clone of the node with static styles applied
51
+ */
52
+ const RenderNode = (node: Element, defaults: StringMap) => {
53
+
54
+ const clone = node.cloneNode(false);
55
+ const computed = getComputedStyle(node);
56
+ const style = GetAppliedStyle(node, computed, defaults);
57
+
58
+ (clone as HTMLElement).removeAttribute('class');
59
+ (clone as HTMLElement).setAttribute('style', style);
60
+
61
+ Array.prototype.forEach.call(node.childNodes, (child: Node) => {
62
+
63
+ switch (child.nodeType) {
64
+
65
+ case Node.ELEMENT_NODE:
66
+ // here we use the parent as the default style, assuming the child will inherit
67
+ clone.appendChild(RenderNode(child as Element, computed as any));
68
+ break;
69
+
70
+ case Node.TEXT_NODE:
71
+ if (node.textContent) {
72
+ clone.appendChild(document.createTextNode(node.textContent));
73
+ }
74
+ break;
75
+
76
+ case Node.COMMENT_NODE:
77
+ // silently drop comments
78
+ break;
79
+
80
+ default:
81
+ console.warn('unhandled node type in serialize', child);
82
+ }
83
+ });
84
+
85
+ return clone;
86
+ };
87
+
88
+ /**
89
+ * serialize a node by creating a clone with static styling that can be
90
+ * used stand-alone (intended for svg, but could apply generically).
91
+ */
92
+ export const SerializeHTML = (node: Element) => {
93
+
94
+ if (!default_properties) {
95
+
96
+ const defaults: StringMap = {};
97
+
98
+ const iframe = document.createElement('iframe');
99
+ iframe.style.width = '10px';
100
+ iframe.style.height = '10px';
101
+ iframe.style.position = 'absolute';
102
+ iframe.style.left = '-100px';
103
+
104
+ document.body.appendChild(iframe);
105
+
106
+ const frame_document = iframe.contentDocument;
107
+ if (frame_document) {
108
+ const div = frame_document.createElement('div');
109
+ frame_document.body.appendChild(div);
110
+ const computed = getComputedStyle(div);
111
+ Array.prototype.forEach.call(computed, (key) => defaults[key] = computed[key]);
112
+ }
113
+
114
+ document.body.removeChild(iframe);
115
+ default_properties = defaults;
116
+
117
+ }
118
+
119
+ return RenderNode(node, default_properties);
120
+
121
+ };
122
+
123
+ // (self as any).SerializeHTML = SerializeHTML;
124
+
@@ -0,0 +1,70 @@
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 interface NodeModel {[index: string]: HTMLElement}
23
+
24
+ const ParseTail = (node: HTMLElement, scope: string, model: NodeModel): void => {
25
+ [].forEach.call(node.children, (child: HTMLElement) => {
26
+ if (child.id) {
27
+ model[child.id] = child;
28
+ child.id = `${scope}-${child.id}`;
29
+ }
30
+ if (child.children && child.children.length) {
31
+ ParseTail(child, scope, model);
32
+ }
33
+ });
34
+ }
35
+
36
+ const ParseTemplate = (template: string, container?: HTMLElement|string) => {
37
+
38
+ const scope = Math.random().toString(36).substring(2, 15);
39
+ const temp = document.createElement('div');
40
+ temp.innerHTML = template;
41
+
42
+ const model: NodeModel = {};
43
+ ParseTail(temp, scope, model);
44
+
45
+ if (typeof container === 'string') {
46
+ container = document.querySelector(container) as HTMLElement;
47
+ }
48
+ if (container) {
49
+ const nodes = [].map.call(temp.childNodes, child => child);
50
+ for (const child of nodes) { container.appendChild(child as Node); }
51
+ }
52
+
53
+ return model;
54
+
55
+ }
56
+
57
+ export const composite = (strings: TemplateStringsArray, ...args: any[]): string => {
58
+ const output: string[] = [];
59
+ for (let i = 0; i < strings.length; i++) {
60
+ output.push(strings[i]);
61
+ if (args[i]) { output.push(args[i].toString()); }
62
+ }
63
+ return output.join('');
64
+ }
65
+
66
+ export const tmpl = (strings: TemplateStringsArray, ...args: any[]): NodeModel => {
67
+ return ParseTemplate(composite(strings, ...args));
68
+ }
69
+
70
+ export const css = composite;
@@ -0,0 +1,61 @@
1
+
2
+ /**
3
+ * TODO: possibly add an allow-list for remotes
4
+ */
5
+ export interface ValidURIOptions {
6
+
7
+ /** allow data: uri (default true) */
8
+ data: boolean;
9
+
10
+ /** allow same-origin (default true) */
11
+ same_origin: boolean;
12
+
13
+ /** allow remote (default false) */
14
+ remote: boolean;
15
+
16
+ }
17
+
18
+ const default_uri_options: ValidURIOptions = {
19
+ data: true,
20
+ same_origin: true,
21
+ remote: false,
22
+ };
23
+
24
+ /**
25
+ * check if this resource is a valid URI. by default we only
26
+ * allow data: and same-origin URIs, but you can override that
27
+ * with a flag.
28
+ *
29
+ * this assumes we have a document (and location) so it should
30
+ * only be called from browser context.
31
+ */
32
+ export const ValidateURI = (resource: string, options: Partial<ValidURIOptions> = {}): string|undefined => {
33
+
34
+ const composite: ValidURIOptions = {
35
+ ...default_uri_options,
36
+ ...options,
37
+ };
38
+
39
+ // console.info({composite});
40
+
41
+ try {
42
+ const url = new URL(resource, document.location.href);
43
+
44
+ if (url.protocol === 'data:') {
45
+ return composite.data ? url.href : undefined;
46
+ }
47
+
48
+ if (url.origin === document.location.origin) {
49
+ return composite.same_origin ? url.href : undefined;
50
+ }
51
+
52
+ return composite.remote ? url.hash : undefined;
53
+
54
+ }
55
+ catch (err) {
56
+ console.error(err);
57
+ }
58
+
59
+ return undefined;
60
+
61
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ },
5
+ "references": [
6
+ { "path": "./treb-embed/modern.tsconfig.json" },
7
+ { "path": "./treb-export/modern.tsconfig.json" }
8
+ ],
9
+ "files": []
10
+ }
package/tsproject.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationDir": "declaration",
5
+ "target": "esnext",
6
+ "module": "es2020",
7
+ "strict": true,
8
+ "composite": true,
9
+ "baseUrl": "./",
10
+ "outDir": "./dist",
11
+ "experimentalDecorators": true,
12
+ "downlevelIteration": true,
13
+ "sourceMap": true,
14
+ "resolveJsonModule": true,
15
+ "moduleResolution": "node",
16
+ "rootDir": ".",
17
+ "importHelpers": true,
18
+ "noEmitHelpers": true,
19
+ "importsNotUsedAsValues": "error",
20
+ "lib": [
21
+ "dom", "es2015"
22
+ ],
23
+ "allowSyntheticDefaultImports": true,
24
+ "esModuleInterop": true
25
+ },
26
+ "exclude": [
27
+ "node_modules",
28
+ "external-declaration-files"
29
+ ]
30
+ }
@@ -0,0 +1,86 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+
3
+ /**
4
+ * this is a replacement (more or less) for `license-checker-webpack-plugin`
5
+ * for use with esbuild. we can get the metafile from an esbuild run, and
6
+ * use that to find deps and list licenses.
7
+ *
8
+ * TODO: rewrite this in ts
9
+ */
10
+
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ /**
15
+ * find the license, if any, for the given module. returns a string for
16
+ * inclusion into the license file, structured as
17
+ *
18
+ * name (repo name if no name in package)
19
+ * repo url (if available)
20
+ * license text...
21
+ *
22
+ */
23
+ const FindLicense = async (dir) => {
24
+
25
+ try {
26
+ const text = await fs.promises.readFile(path.join(dir, 'package.json'), { encoding: 'utf8'});
27
+ const json = JSON.parse(text || '{}');
28
+ const files = (await fs.promises.readdir(dir)).filter(test => /license/i.test(test));
29
+
30
+ let name = json.name || '';
31
+
32
+ if (!name) {
33
+ const split = dir.split(path.sep);
34
+ name = split[1];
35
+ }
36
+
37
+ let strings = [name];
38
+
39
+ if (typeof json.repository === 'object' && json.repository.url) {
40
+ strings.push(json.repository.url);
41
+ }
42
+ else if (typeof json.repository === 'string') {
43
+ strings.push(json.repository);
44
+ }
45
+
46
+ if (files.length > 0) {
47
+ const license_text = await fs.promises.readFile(path.join(dir, files[0]), { encoding: 'utf8' });
48
+ strings.push('\n');
49
+ strings.push(license_text);
50
+ return strings.join('\n');
51
+ }
52
+
53
+ }
54
+ catch (err) {
55
+ console.error(err);
56
+ }
57
+
58
+ return undefined;
59
+
60
+ };
61
+
62
+ const GenerateLicenseFile = async (metafile) => {
63
+
64
+ let processed = new Map();
65
+ const licenses = [];
66
+
67
+ for (const key of Object.keys(metafile.inputs || {})) {
68
+ if (/^node_modules/.test(key)) {
69
+ const parts = key.split(path.sep);
70
+ if (!processed.has(parts[1])) {
71
+ const license = await FindLicense(path.join(parts[0], parts[1]));
72
+ if (license) {
73
+ licenses.push(license);
74
+ }
75
+ processed.set(parts[1], true);
76
+ }
77
+ }
78
+ }
79
+
80
+ return licenses.join('\n---\n\n');
81
+
82
+ };
83
+
84
+ module.exports = { GenerateLicenseFile };
85
+
86
+
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+
3
+ #
4
+ # print a list of all --treb css vars used in any treb* directory.
5
+ # uses bash wizardry.
6
+ #
7
+ # of course you should be noting these when you create them. but
8
+ # this is a useful check that we haven't missed anything.
9
+ #
10
+ # note that we're specifically looking for vars being /used/, not
11
+ # /defined/. which is probably better in case we have vars we're
12
+ # defining but never using.
13
+ #
14
+
15
+ regexp="(--treb[[:alnum:]_\-]+)"
16
+
17
+ # search and filter
18
+ unique=($(
19
+ for i in `grep -ir "var(\\s*--treb" treb*`; do
20
+ if [[ $i =~ $regexp ]]; then
21
+ echo "${BASH_REMATCH[1]}";
22
+ fi
23
+ done | sort -u))
24
+
25
+ ## dump uniques
26
+ #for i in ${unique[@]}; do
27
+ # echo $i
28
+ #done;
29
+
30
+ # update: dump as JSON. this is beyond my bashing skills,
31
+ # have to have an empty string
32
+
33
+ # update2: OK I can do it, but it's ugly
34
+
35
+ FIRST=1
36
+ printf "[\n"
37
+ for i in ${unique[@]}; do
38
+ if [[ $FIRST -ne 1 ]]; then
39
+ printf ",\n";
40
+ fi;
41
+ printf '\t"%s"' $i
42
+ FIRST=0
43
+ done;
44
+ printf "\n]\n"
45
+
46
+
package/README-esm.md DELETED
@@ -1,37 +0,0 @@
1
-
2
- # ES module
3
-
4
- This directory is provided to make it easier to consume TREB as an
5
- es module, particularly if you are using a front-end framework.
6
-
7
-
8
- ## Why is the ES module larger than the JS module?
9
-
10
- Traditionally, we split import/export functions (functions that operate
11
- on XLSX files) into a separate worker module which is loaded on demand.
12
- If you are using the JS module as a web resource, we locate the worker
13
- script using the path to the base script.
14
-
15
- That doesn't necessarily work if you are using a bundler, which
16
- is commmon with front-end frameworks. It's possible to manually place the
17
- worker script in a public asset directory, and set the path, but that makes
18
- it much more difficult to import the library.
19
-
20
- So as of version 21.2, we're including the import/export worker in the
21
- MJS file as a blob, and loading the worker from that blob as necessary.
22
-
23
-
24
- ## The ES module does not embed CSS
25
-
26
- The JS module embeds CSS -- styles are attached to the document when
27
- the JS module is loaded.
28
-
29
- The ES module does not embed CSS, to better support strict CSP settings. So
30
- if you use the ES module, you must separately include the stylesheet,
31
- either in your HTML or using your front-end framework.
32
-
33
-
34
- # How to use the ES module
35
-
36
- See README.md in this directory.
37
-