@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,44 @@
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 class DOMUtilities {
23
+
24
+ /** creates a div and assigns class name/names */
25
+ public static CreateDiv(classes = '', parent?: HTMLElement, scope?: string){
26
+ return this.Create<HTMLDivElement>('div', classes, parent, scope);
27
+ }
28
+
29
+ /** generic element constructor. shame we need the tag AND the type. */
30
+ public static Create<E extends HTMLElement>(tag = '', classes = '', parent?: HTMLElement, scope?: string, attrs?: Record<string, string>){
31
+ const element = document.createElement(tag) as E;
32
+ if (classes) element.setAttribute('class', classes);
33
+ if (scope) element.setAttribute(scope, '');
34
+ if (attrs) {
35
+ const keys = Object.keys(attrs);
36
+ for (const key of keys) {
37
+ element.setAttribute(key, attrs[key]);
38
+ }
39
+ }
40
+ if (parent) parent.appendChild(element);
41
+ return element;
42
+ }
43
+
44
+ }
@@ -0,0 +1,179 @@
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 FontMetrics2 {
23
+ ascender: number;
24
+ descender: number;
25
+ block: number;
26
+ paren: number;
27
+ hash: number;
28
+ }
29
+
30
+ export class FontMetricsFactory {
31
+
32
+ private canvas!: HTMLCanvasElement;
33
+
34
+ private cache: Record<string, FontMetrics2> = {};
35
+
36
+ // public base_size_px = 10;
37
+
38
+ constructor() {
39
+
40
+ // you don't have to attach this canvas to the document
41
+ // in order to use it to measure. however, if the font size
42
+ // is relative it needs to be relative to the canvas size;
43
+ // and if the canvas is not attached to the document, size
44
+ // doesn't work.
45
+
46
+ // FIXME: test with a containing node?
47
+ // (NOTE: that doesn't help)
48
+
49
+ if (typeof document !== 'undefined') {
50
+ this.canvas = document.createElement('canvas');
51
+ }
52
+
53
+ // FIXME: since this is prelude to drawing, couldn't we use
54
+ // our drawing canvas to render? then we don't need to attach
55
+ // garbage to the DOM
56
+
57
+ // alternatively, we could munge the font description...
58
+
59
+ // this.canvas.style.position = 'absolute';
60
+ // this.canvas.style.top = '-1000px';
61
+ // document.body.appendChild(this.canvas);
62
+
63
+ // what we're doing now is calculating -- we get the base size
64
+ // from theme and if we see em or % we scale manually.
65
+
66
+ }
67
+
68
+ /* *
69
+ * set base font size. the idea here is to have a base in case font sizes
70
+ * are relative (% or em), they need to be relative to something. HOWEVER,
71
+ * canvas doesn't inherit --
72
+ *
73
+ * (moved to base_size_points)
74
+ *
75
+ * /
76
+ public BaseSize(size: string): void {
77
+ this.canvas.style.fontSize = size || '';
78
+ }
79
+ */
80
+
81
+ public Flush(): void {
82
+ this.cache = {};
83
+ }
84
+
85
+ public Get(font: string, base = 10): FontMetrics2 {
86
+ const key = font + ';' + base;
87
+ let metrics = this.cache[key];
88
+ if (metrics) {
89
+ return metrics;
90
+ }
91
+ metrics = this.Measure(font, base);
92
+ this.cache[key] = metrics;
93
+ return metrics;
94
+ }
95
+
96
+ public Measure(font: string, base: number): FontMetrics2 {
97
+
98
+ const match = font.match(/([\d.]+)((?:%|em))/);
99
+
100
+ if (match) {
101
+ const target = match[1] + match[2];
102
+ let value = Number(match[1]) * base;
103
+ if (match[2] === '%') { value /= 100; }
104
+ font = font.replace(target, value + 'px');
105
+ }
106
+
107
+ // what's up with the double-access on context?
108
+
109
+ let context = this.canvas.getContext('2d', {
110
+ willReadFrequently: true,
111
+ });
112
+
113
+ if (!context) {
114
+ throw new Error('invalid context');
115
+ }
116
+
117
+ context.font = font;
118
+ const metrics = context.measureText('MMM');
119
+
120
+ const size = Math.ceil(metrics.width);
121
+
122
+ this.canvas.setAttribute('width', size.toString());
123
+ this.canvas.setAttribute('height', size.toString());
124
+
125
+ context = this.canvas.getContext('2d', {
126
+ willReadFrequently: true,
127
+ });
128
+
129
+ if (!context) {
130
+ throw new Error('invalid context');
131
+ }
132
+
133
+ context.font = font;
134
+
135
+ context.textAlign = 'center';
136
+ context.textBaseline = 'alphabetic';
137
+ context.fillStyle = '#000';
138
+
139
+ const y = Math.round(size * 2 / 3);
140
+ const x = Math.round(size / 2);
141
+
142
+ context.clearRect(0, 0, size, size);
143
+ for (let i = 0x20; i <= 0x7e; i++) {
144
+ const s = String.fromCharCode(i);
145
+ context.fillText(s, x, y);
146
+ }
147
+
148
+ const data = context.getImageData(0, 0, this.canvas.width, this.canvas.height).data;
149
+
150
+ const top = Math.floor(this.GetFirstIndex(data)/size);
151
+ const bottom = Math.floor(this.GetLastIndex(data)/size);
152
+
153
+ return {
154
+ ascender: y - top,
155
+ descender: bottom - y,
156
+ block: bottom - top + 1,
157
+ paren: context.measureText('(').width,
158
+ hash: context.measureText('##').width - context.measureText('#').width,
159
+ };
160
+
161
+ }
162
+
163
+ private GetFirstIndex(pixels: Uint8ClampedArray) {
164
+ for (let i = 3, n = pixels.length; i < n; i += 4) {
165
+ if (pixels[i] > 0) return (i - 3) / 4;
166
+ }
167
+ return pixels.length;
168
+ }
169
+
170
+ private GetLastIndex(pixels: Uint8ClampedArray) {
171
+ for (let i = pixels.length - 1; i >= 3; i -= 4) {
172
+ if (pixels[i] > 0) return i / 4;
173
+ }
174
+ return 0;
175
+ }
176
+
177
+ }
178
+
179
+ export const FontMetricsCache = new FontMetricsFactory();
@@ -0,0 +1,104 @@
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
+ const app_version = typeof navigator === 'undefined' ? '' : navigator.appVersion;
23
+ const user_agent = typeof navigator === 'undefined' ? '' : navigator.userAgent;
24
+
25
+ // console.warn('using fake UA: ' + user_agent);
26
+
27
+ /**
28
+ * some basic user-agent sniffing. we use less than we used to, except
29
+ * for making the determination of modern (grid)/legacy layout.
30
+ *
31
+ * FIXME: move to base_types, we need it in toolbar
32
+ *
33
+ */
34
+ class UAType {
35
+
36
+ /** we need this for some edge-specific weirdness */
37
+ public readonly is_edge = /Edge/.test(app_version);
38
+
39
+ /** more testing. ios safari doesn't support grid+sticky (apparently) */
40
+ public readonly is_ipad = /iPad|iPhone/.test(user_agent);
41
+
42
+ /** more testing. firefox android doesn't support grid+sticky (apparently) */
43
+ public readonly is_android = /android|samsung/i.test(user_agent);
44
+
45
+ /** mobile we want slightly different keyboard behavior */
46
+ public readonly is_mobile = this.is_ipad || this.is_android;
47
+
48
+ /** more testing. firefox android doesn't support grid+sticky (apparently) */
49
+ public readonly is_firefox = /firefox/i.test(user_agent);
50
+
51
+ /** ... */
52
+ public readonly is_safari = /safari/i.test(user_agent) && !/edg/i.test(user_agent);
53
+
54
+ /** ... */
55
+ public readonly is_mac = /macintosh/i.test(user_agent);
56
+
57
+ /** ... */
58
+ public readonly is_chrome = /Chrome/i.test(user_agent);
59
+
60
+ /* * this is for events (IE11 does't support event constructor) * /
61
+ public trident = ((typeof navigator !== 'undefined') &&
62
+ user_agent && /trident/i.test(user_agent));
63
+ */
64
+
65
+ /** ... */
66
+ public is_windows = /win64|win32|windows\s+nt/i.test(user_agent);
67
+
68
+ // safari doesn't seem to hold the sticky elements in place. not
69
+ // sure why not, though, need to do some more testing. legacy
70
+ // renderer on safari has no scrollbars...
71
+
72
+ // position: -webkit-sticky fixes the sticky issue, behavior seems
73
+ // consistent with cr/ffx. also fixes on ios, but we lost the scrollbars.
74
+
75
+ // blinking on safari handled with -webkit-tap-highlight-color: transparent;
76
+ // but we still have no scrollbars. it may be that we never have them...
77
+
78
+ /** temp only: need a more robust check */
79
+ public readonly is_modern =
80
+ (!this.is_edge) &&
81
+ // (!this.is_ipad) &&
82
+ // (!this.is_mac || (this.is_chrome || this.is_firefox)) &&
83
+ (!(this.is_firefox && this.is_android)) &&
84
+ /webkit|firefox/i.test(user_agent);
85
+ }
86
+
87
+ const null_ua = {
88
+
89
+ is_edge: false,
90
+ is_ipad: false,
91
+ is_android: false,
92
+ is_firefox: false,
93
+ is_safari: false,
94
+ is_mac: false,
95
+ is_chrome: false,
96
+ trident: false,
97
+ is_windows: false,
98
+ is_modern: true,
99
+ is_node: true,
100
+ is_mobile: false,
101
+
102
+ };
103
+
104
+ export const UA = (typeof navigator === 'undefined') ? null_ua : new UAType();
package/treb-logo.svg ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="153.073px" height="133.742px" viewBox="0.673 4.629 153.073 133.742" enable-background="new 0.673 4.629 153.073 133.742"
6
+ xml:space="preserve">
7
+ <linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="0.6729" y1="71.5" x2="153.7461" y2="71.5">
8
+ <stop offset="0" style="stop-color:#5CB5FF"/>
9
+ <stop offset="1" style="stop-color:#0059B9"/>
10
+ </linearGradient>
11
+ <path fill="url(#SVGID_1_)" d="M91.656,28.313c-4.989,0-17.266,6.249-21.305,8.504c-2.344-2.473-2.603-6.162-3.036-10.933
12
+ c-2.344,2.429-0.824,9.806,0,12.496c-10.238,7.635-18.83,15.531-27.597,24.471c-2.992-4.729-5.031-8.593-5.726-17.183
13
+ c-3.038,6.509,0.867,15.057,3.121,19.784c-9.674,12.193-19.263,25.297-27.03,37.834C-25.405,28.313,82.936-16.248,153.746,14.431
14
+ C109.879,43.63,98.554,135.784,21.498,111.274c-5.423,7.809-9.069,18.006-13.538,27.072c-3.73,0.263-6.334-1.646-7.288-3.12
15
+ c7.506-18.181,17.183-34.192,27.075-49.984c10.718,0.306,21.346,0.478,30.198-1.04c-7.681-2.038-16.877-0.78-26.032-3.123
16
+ c5.597-10.718,13.754-18.876,21.867-27.075c8.808,0.782,17.746,3.21,27.074,1.041c-8.111-1.431-15.966-1.952-22.909-4.165
17
+ C65.539,42.502,80.722,33.389,91.656,28.313z"/>
18
+ </svg>
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "treb-parser",
3
+ "version": "16.0.1",
4
+ "main": "src/index.ts"
5
+ }
@@ -0,0 +1,122 @@
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
+ enum ParseState {
23
+ default = 0,
24
+ quoted = 1,
25
+ }
26
+
27
+ /**
28
+ * csv parser, following (largely) RFC4180 rules, with some extensions.
29
+ * specifically:
30
+ *
31
+ * - lines should end with CRLF, but we support CR
32
+ * - we do not support header (atm)
33
+ * - variable-length records are supported
34
+ * - any field may be quoted
35
+ * - quoted fields can contain newlines and commas
36
+ * - use two double-quotes to escape a double quote
37
+ *
38
+ */
39
+ export const ParseCSV = (text: string, delimiter = ','): string[][] => {
40
+
41
+ let state: ParseState = ParseState.default;
42
+ let record: string[] = [];
43
+ let field = '';
44
+
45
+ const records: string[][] = [];
46
+ const length = text.length;
47
+
48
+ if (/[\r\n"]/.test(delimiter)) {
49
+ throw new Error('invalid delimiter');
50
+ }
51
+
52
+ for (let i = 0; i < length; i++ ){
53
+ const char = text[i];
54
+
55
+ if (i === 0 && char.charCodeAt(0) === 0xfeff) {
56
+ continue;
57
+ }
58
+
59
+ if (state === ParseState.default) {
60
+ switch (char) {
61
+ case delimiter:
62
+ record.push(field);
63
+ field = '';
64
+ break;
65
+
66
+ case '\r':
67
+ // naked (non-quoted) \r without immediate \n is illegal
68
+
69
+ // if (i + 1 < length && text[i + 1] === '\n') i++; // drop into next block
70
+ // else
71
+ break;
72
+
73
+ case '\n':
74
+ record.push(field);
75
+ field = '';
76
+ records.push(record);
77
+ record = [];
78
+ break;
79
+
80
+ case '"':
81
+ // we're allowing unescaped double-quotes in non-quoted fields
82
+
83
+ if (field.length === 0) {
84
+ state = ParseState.quoted;
85
+ }
86
+ else {
87
+ field += char;
88
+ }
89
+ break;
90
+
91
+ default:
92
+ field += char;
93
+ break;
94
+ }
95
+ }
96
+ else {
97
+ if (char === '"') {
98
+ if (i + 1 < length && text[i + 1] === '"') {
99
+ field += '"';
100
+ i++;
101
+ }
102
+ else {
103
+ state = ParseState.default;
104
+ }
105
+ }
106
+ else field += char;
107
+ }
108
+ }
109
+
110
+ // we're at the end. this might be a blank line at the end of the
111
+ // file, or it might be the end of the last record. let's make the
112
+ // simplifying assumption that we can drop a blank line, instead
113
+ // of treating it as a record with one zero-length field.
114
+
115
+ if (record.length || field.length) {
116
+ record.push(field);
117
+ records.push(record);
118
+ }
119
+
120
+ return records;
121
+
122
+ };
@@ -0,0 +1,25 @@
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 * from './parser-types';
23
+ export * from './parser';
24
+ export * from './csv-parser';
25
+ export * from './md-parser';