@trebco/treb 30.15.0 → 31.0.2
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.
- package/api-generator/api-generator.ts +3 -1
- package/api-generator/package.json +2 -1
- package/dist/treb-export-worker.mjs +2 -2
- package/dist/treb-spreadsheet.mjs +13 -13
- package/dist/treb.d.ts +19 -2
- package/package.json +8 -7
- package/treb-base-types/src/font-stack.ts +144 -0
- package/treb-base-types/src/style.ts +121 -11
- package/treb-base-types/src/theme.ts +53 -8
- package/treb-calculator/src/calculator.ts +13 -13
- package/treb-calculator/src/descriptors.ts +12 -4
- package/treb-calculator/src/expression-calculator.ts +17 -4
- package/treb-calculator/src/functions/base-functions.ts +57 -4
- package/treb-calculator/src/functions/statistics-functions.ts +9 -6
- package/treb-calculator/tsconfig.json +11 -0
- package/treb-charts/src/chart-functions.ts +41 -4
- package/treb-charts/src/chart-types.ts +20 -1
- package/treb-charts/src/chart-utils.ts +86 -9
- package/treb-charts/src/default-chart-renderer.ts +40 -1
- package/treb-charts/src/renderer.ts +3 -3
- package/treb-charts/style/charts.scss +7 -1
- package/treb-data-model/src/annotation.ts +6 -0
- package/treb-data-model/src/data_model.ts +14 -3
- package/treb-data-model/src/sheet.ts +57 -56
- package/treb-embed/markup/toolbar.html +15 -1
- package/treb-embed/src/custom-element/spreadsheet-constructor.ts +38 -0
- package/treb-embed/src/embedded-spreadsheet.ts +119 -29
- package/treb-embed/src/options.ts +3 -0
- package/treb-embed/src/selection-state.ts +1 -0
- package/treb-embed/src/toolbar-message.ts +6 -0
- package/treb-embed/src/types.ts +9 -0
- package/treb-embed/style/defaults.scss +12 -1
- package/treb-embed/style/font-stacks.scss +105 -0
- package/treb-embed/style/layout.scss +1 -0
- package/treb-embed/style/theme-defaults.scss +12 -2
- package/treb-embed/style/toolbar.scss +16 -0
- package/treb-grid/src/editors/overlay_editor.ts +36 -3
- package/treb-grid/src/layout/base_layout.ts +52 -37
- package/treb-grid/src/layout/grid_layout.ts +7 -0
- package/treb-grid/src/render/tile_renderer.ts +154 -148
- package/treb-grid/src/types/grid.ts +188 -54
- package/treb-grid/src/types/grid_events.ts +1 -1
- package/treb-grid/src/types/grid_options.ts +3 -0
- package/treb-grid/src/util/fontmetrics.ts +134 -0
- package/treb-parser/src/parser.ts +12 -3
- package/treb-utils/src/measurement.ts +2 -3
- package/tsproject.json +1 -1
- package/treb-calculator/modern.tsconfig.json +0 -11
- package/treb-grid/src/util/fontmetrics2.ts +0 -182
- package/treb-parser/src/parser.test.ts +0 -298
- /package/treb-embed/{modern.tsconfig.json → tsconfig.json} +0 -0
- /package/treb-export/{modern.tsconfig.json → tsconfig.json} +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
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-2024 trebco, llc.
|
|
18
|
+
* info@treb.app
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
//
|
|
23
|
+
// thanks to
|
|
24
|
+
// https://modernfontstacks.com/
|
|
25
|
+
//
|
|
26
|
+
// for the stacks. we make some minor changes, mostly because of browser issues.
|
|
27
|
+
//
|
|
28
|
+
|
|
29
|
+
.treb-main.treb-main {
|
|
30
|
+
|
|
31
|
+
/* default size for fonts in grid cells */
|
|
32
|
+
--treb-font-stack-default-size: 14px;
|
|
33
|
+
|
|
34
|
+
/* size adjustment for some fonts */
|
|
35
|
+
--treb-font-stack-calibri-size: 16px;
|
|
36
|
+
--treb-font-stack-tscu-comic-size: 16px;
|
|
37
|
+
--treb-font-stack-helvetica-neue-size: 13px;
|
|
38
|
+
--treb-font-stack-cambria-size: 16px;
|
|
39
|
+
|
|
40
|
+
/* flag that we need to use font variants (chrome only) */
|
|
41
|
+
--treb-font-stack-sitka-text-variant: lining-nums tabular-nums;
|
|
42
|
+
|
|
43
|
+
/*
|
|
44
|
+
* os-specific size adjustment. it's not that important but for consistency
|
|
45
|
+
* with the old layout this should be 10pt, ~13.33px. I notice that the
|
|
46
|
+
* editor is slightly off from the canvas rendering, I assume that's related
|
|
47
|
+
* to the subpixel size? maybe we should break from the old version. (or
|
|
48
|
+
* maybe we can fix the editor?)
|
|
49
|
+
*/
|
|
50
|
+
&.treb-ua-osx {
|
|
51
|
+
--treb-font-stack-system-ui-size: 10pt;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* this is the default font. it's also used for other font stacks
|
|
56
|
+
* if stacks are turned off (the default, for now).
|
|
57
|
+
*/
|
|
58
|
+
.treb-font-stack-default {
|
|
59
|
+
|
|
60
|
+
// I love avenir but the bold is too bold. can we adjust it?
|
|
61
|
+
|
|
62
|
+
// font-family: calibri, avenir, $font-stack;
|
|
63
|
+
font-family: calibri, $font-stack;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.treb-font-stack-transitional {
|
|
68
|
+
|
|
69
|
+
// we drop sitka text because the bounding box isn't calculating properly
|
|
70
|
+
// for some reason -- variants? also, firefox does not support numeric
|
|
71
|
+
// variants in canvas and the sitka default is old-style non-tabular nums.
|
|
72
|
+
|
|
73
|
+
// font-family: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, serif;
|
|
74
|
+
font-family: Charter, 'Bitstream Charter', Cambria, serif;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* not using this atm, we just have one serif (the transitional) */
|
|
79
|
+
.treb-font-stack-old-style {
|
|
80
|
+
font-family: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.treb-font-stack-handwritten {
|
|
84
|
+
|
|
85
|
+
// not sure I believe that that tscu comic font is widely installed...
|
|
86
|
+
// there might be a better alternative.
|
|
87
|
+
|
|
88
|
+
font-family: 'Segoe Print', 'Bradley Hand', Chilanka, TSCu_Comic, casual, cursive;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* not using this atm */
|
|
92
|
+
.treb-font-stack-industrial {
|
|
93
|
+
font-family: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* not a slab */
|
|
97
|
+
.treb-font-stack-monospace {
|
|
98
|
+
font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.treb-font-stack-ui {
|
|
102
|
+
font-family: system-ui, sans-serif;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
@@ -192,7 +192,16 @@ $text-reference-color-5: rgb(254, 47, 1);
|
|
|
192
192
|
*/
|
|
193
193
|
.grid-cells {
|
|
194
194
|
font-family: var(--treb-grid-font-family, inherit);
|
|
195
|
+
|
|
196
|
+
// it seems like the old default was 14px / 16px for calibri on windows?
|
|
197
|
+
// we should get back to that, then we can adjust calibri (in the stacks)
|
|
198
|
+
// to scale.
|
|
199
|
+
|
|
200
|
+
// font-size: var(--treb-grid-font-size, 10px);
|
|
201
|
+
// font-size: var(--treb-grid-font-size, 10pt);
|
|
202
|
+
|
|
195
203
|
font-size: var(--treb-grid-font-size, 14px);
|
|
204
|
+
|
|
196
205
|
color: var(--treb-grid-default-color, inherit);
|
|
197
206
|
stroke: var(--treb-grid-grid-color, rgb(204, 204, 212));
|
|
198
207
|
background: var(--treb-grid-background, #fff);
|
|
@@ -520,11 +529,11 @@ $text-reference-color-5: rgb(254, 47, 1);
|
|
|
520
529
|
|
|
521
530
|
|
|
522
531
|
|
|
523
|
-
|
|
532
|
+
/* *
|
|
524
533
|
* special override for windows, using calibri (which is too small).
|
|
525
534
|
* you should still be able to override with a regular theme style,
|
|
526
535
|
* or (potentially) also override for windows specifically. fancy!
|
|
527
|
-
|
|
536
|
+
* /
|
|
528
537
|
&.treb-ua-windows .grid-cells {
|
|
529
538
|
font-size: var(--treb-grid-font-size-windows, var(--treb-grid-font-size, 12pt));
|
|
530
539
|
font-family: var(--treb-grid-font-family-windows, var(--treb-grid-font-family, "Calibri", $font-stack)); // does this actually work? is this included? (...)
|
|
@@ -534,6 +543,7 @@ $text-reference-color-5: rgb(254, 47, 1);
|
|
|
534
543
|
font-size: var(--treb-grid-font-size-osx, var(--treb-grid-font-size, 10pt)); // slightly smaller default
|
|
535
544
|
font-family: var(--treb-grid-font-family-osx, var(--treb-grid-font-family, inherit));
|
|
536
545
|
}
|
|
546
|
+
*/
|
|
537
547
|
|
|
538
548
|
/**
|
|
539
549
|
*
|
|
@@ -157,6 +157,13 @@ $swatch-size: 18px;
|
|
|
157
157
|
mask-size: var(--icon-size, 16px 16px);
|
|
158
158
|
-webkit-mask-size: var(--icon-size, 16px 16px);
|
|
159
159
|
}
|
|
160
|
+
|
|
161
|
+
&.treb-font-stack {
|
|
162
|
+
&::before {
|
|
163
|
+
display: none;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
160
167
|
}
|
|
161
168
|
|
|
162
169
|
}
|
|
@@ -193,6 +200,15 @@ $swatch-size: 18px;
|
|
|
193
200
|
|
|
194
201
|
}
|
|
195
202
|
|
|
203
|
+
.treb-font-stack {
|
|
204
|
+
width: 8em;
|
|
205
|
+
align-items: flex-start;
|
|
206
|
+
overflow: hidden;
|
|
207
|
+
&::before {
|
|
208
|
+
display: none;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
196
212
|
.treb-menu {
|
|
197
213
|
|
|
198
214
|
// on Safari, we need to make these menus focus targets, so we can
|
|
@@ -67,6 +67,9 @@ export class OverlayEditor extends Editor<ResetSelectionEvent> {
|
|
|
67
67
|
|
|
68
68
|
// ---------------------------------------------------------------------------
|
|
69
69
|
|
|
70
|
+
/** possibly carrying over a font face (+size?) */
|
|
71
|
+
public edit_style?: CellStyle;
|
|
72
|
+
|
|
70
73
|
/**
|
|
71
74
|
* this is a flag used to indicate when we need to reset the selection.
|
|
72
75
|
* the issue has to do with selecting cells via arrow keys; if you do
|
|
@@ -273,7 +276,7 @@ export class OverlayEditor extends Editor<ResetSelectionEvent> {
|
|
|
273
276
|
*
|
|
274
277
|
* something to do with keyboard selection? (which needs to be fixed)?
|
|
275
278
|
*/
|
|
276
|
-
public Edit(gridselection: GridSelection, rect: Rectangle, cell: Cell, value?: CellValue, event?: Event): void {
|
|
279
|
+
public Edit(gridselection: GridSelection, rect: Rectangle, cell: Cell, value?: CellValue, event?: Event, edit_style?: CellStyle): void {
|
|
277
280
|
|
|
278
281
|
this.Publish({
|
|
279
282
|
type: 'start-editing',
|
|
@@ -284,9 +287,33 @@ export class OverlayEditor extends Editor<ResetSelectionEvent> {
|
|
|
284
287
|
this.target_address = {...gridselection.target};
|
|
285
288
|
this.reset_selection = false;
|
|
286
289
|
|
|
287
|
-
const style: CellStyle = cell.style || {};
|
|
290
|
+
const style: CellStyle = JSON.parse(JSON.stringify(cell.style || {})); // clone
|
|
291
|
+
|
|
292
|
+
//
|
|
293
|
+
// CURRENT ISSUE: this works, but the style is not actually applied to
|
|
294
|
+
// the cell. we need to modify the commit routine to apply the style.
|
|
295
|
+
// I think?
|
|
296
|
+
//
|
|
297
|
+
// WAIT, that might not be right... might have something to do with
|
|
298
|
+
// default?
|
|
299
|
+
//
|
|
300
|
+
|
|
301
|
+
this.edit_style = edit_style; // set (or unset)
|
|
302
|
+
|
|
303
|
+
if (edit_style?.font_face) {
|
|
304
|
+
style.font_face = edit_style.font_face;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const font_info = Style.CompositeFont(this.theme.grid_cell_font_size, style, this.scale, this.theme);
|
|
308
|
+
|
|
309
|
+
this.edit_node.style.font = font_info.font;
|
|
310
|
+
if (font_info.variants) {
|
|
311
|
+
this.edit_node.style.fontVariant = font_info.variants;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
this.edit_node.style.fontVariant = '';
|
|
315
|
+
}
|
|
288
316
|
|
|
289
|
-
this.edit_node.style.font = Style.Font(style, this.scale);
|
|
290
317
|
this.edit_node.style.color = ResolveThemeColor(this.theme, style.text, 1);
|
|
291
318
|
this.edit_inset.style.backgroundColor = ResolveThemeColor(this.theme, style.fill, 0);
|
|
292
319
|
|
|
@@ -332,6 +359,12 @@ export class OverlayEditor extends Editor<ResetSelectionEvent> {
|
|
|
332
359
|
|
|
333
360
|
rect.ApplyStyle(this.container_node);
|
|
334
361
|
|
|
362
|
+
// trial and error. still a little wonky at scales, but reasonable.
|
|
363
|
+
|
|
364
|
+
const offset = UA.is_mac ? 0 : 0.5;
|
|
365
|
+
|
|
366
|
+
this.edit_node.style.bottom = offset.toFixed(2) + 'px'; // does this need to scale for dpr? not sure
|
|
367
|
+
|
|
335
368
|
this.autocomplete?.ResetBlock();
|
|
336
369
|
this.selection = gridselection;
|
|
337
370
|
|
|
@@ -377,6 +377,11 @@ export abstract class BaseLayout {
|
|
|
377
377
|
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
381
|
+
public FocusInLayout(target?: EventTarget): boolean {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
380
385
|
/**
|
|
381
386
|
* if the DPR has changed, update it and return true. otherwise return
|
|
382
387
|
* false. this is used on resize events: if the scale has changed, we
|
|
@@ -672,7 +677,7 @@ export abstract class BaseLayout {
|
|
|
672
677
|
|
|
673
678
|
}
|
|
674
679
|
|
|
675
|
-
public UpdateAnnotation(elements: Annotation | Annotation[]): void {
|
|
680
|
+
public UpdateAnnotation(elements: Annotation | Annotation[], theme: Theme): void {
|
|
676
681
|
if (!Array.isArray(elements)) elements = [elements];
|
|
677
682
|
for (const annotation of elements) {
|
|
678
683
|
const view = annotation.view[this.view.view_index] || {};
|
|
@@ -684,8 +689,48 @@ export abstract class BaseLayout {
|
|
|
684
689
|
}
|
|
685
690
|
*/
|
|
686
691
|
|
|
692
|
+
let font_size_pt = 10 * this.scale;
|
|
693
|
+
|
|
694
|
+
// console.info(annotation.data.style);
|
|
695
|
+
|
|
696
|
+
if (annotation.data.style?.font_size?.unit === 'em') {
|
|
697
|
+
|
|
698
|
+
font_size_pt *= annotation.data.style.font_size.value;
|
|
699
|
+
|
|
700
|
+
// console.info("scaling up...", font_size_pt)
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
|
|
687
704
|
view.node.dataset.scale = this.scale.toString();
|
|
688
|
-
|
|
705
|
+
|
|
706
|
+
// maybe we should just reset and then apply?
|
|
707
|
+
|
|
708
|
+
if (annotation.data.style?.font_face && annotation.data.style.font_face.startsWith('stack:')) {
|
|
709
|
+
const name = annotation.data.style.font_face.substring(6);
|
|
710
|
+
const stack = theme.font_stacks[name];
|
|
711
|
+
if(stack) {
|
|
712
|
+
view.node.classList.add('treb-inherit-font');
|
|
713
|
+
view.node.style.fontFamily = stack.font || '';
|
|
714
|
+
|
|
715
|
+
// font_size_pt *= stack.scale;
|
|
716
|
+
|
|
717
|
+
if (stack.variants) {
|
|
718
|
+
view.node.style.fontVariant = stack.variants;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
view.node.classList.remove('treb-inherit-font');
|
|
723
|
+
view.node.style.fontFamily = '';
|
|
724
|
+
view.node.style.fontVariant = '';
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
else {
|
|
728
|
+
view.node.classList.remove('treb-inherit-font');
|
|
729
|
+
view.node.style.fontFamily = '';
|
|
730
|
+
view.node.style.fontVariant = '';
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
view.node.style.fontSize = `${font_size_pt}pt`;
|
|
689
734
|
|
|
690
735
|
// update the layout here if necessary. after that it should
|
|
691
736
|
// be persisted (assuming it's saved). eventually this should
|
|
@@ -848,13 +893,13 @@ export abstract class BaseLayout {
|
|
|
848
893
|
|
|
849
894
|
}
|
|
850
895
|
|
|
851
|
-
public AddAnnotation(annotation: Annotation): void {
|
|
896
|
+
public AddAnnotation(annotation: Annotation, theme: Theme): void {
|
|
852
897
|
const view = annotation.view[this.view.view_index] || {};
|
|
853
898
|
if (!view.node) {
|
|
854
899
|
throw new Error('annotation view/node missing');
|
|
855
900
|
}
|
|
856
901
|
this.annotation_container.appendChild(view.node);
|
|
857
|
-
this.UpdateAnnotation(annotation);
|
|
902
|
+
this.UpdateAnnotation(annotation, theme);
|
|
858
903
|
}
|
|
859
904
|
|
|
860
905
|
// testing moving this here...
|
|
@@ -1246,38 +1291,6 @@ export abstract class BaseLayout {
|
|
|
1246
1291
|
|
|
1247
1292
|
parent.appendChild(tile);
|
|
1248
1293
|
|
|
1249
|
-
// NOTE re: text rendering. you can't use baseline = top, because that's
|
|
1250
|
-
// inconsistent among browsers. in fact of all baselines, the only ones that
|
|
1251
|
-
// are even close are alphabetic and bottom -- bottom is slightly different
|
|
1252
|
-
// in ffx compared to chrome and edge, but that could be because of different
|
|
1253
|
-
// font rendering schemes. alphabetic is the closest, but requires offset for
|
|
1254
|
-
// ascender (or descender).
|
|
1255
|
-
|
|
1256
|
-
// actually it looks like there's a 1px difference in bottom baseline...
|
|
1257
|
-
// alphabetic is the only one that's consistent.
|
|
1258
|
-
|
|
1259
|
-
// FIXME: why not just offset on a per-browser basis? it might be ugly
|
|
1260
|
-
// but it's simpler.
|
|
1261
|
-
|
|
1262
|
-
// for the time being we will use bottom.
|
|
1263
|
-
|
|
1264
|
-
// why were we prepainting (because firefox, below?) and why was this so
|
|
1265
|
-
// slow? do we need to preset the context text parameters?
|
|
1266
|
-
|
|
1267
|
-
/*
|
|
1268
|
-
const context = tile.getContext('2d', {alpha: false});
|
|
1269
|
-
|
|
1270
|
-
if (context) {
|
|
1271
|
-
context.textAlign = 'left';
|
|
1272
|
-
context.textBaseline = 'alphabetic';
|
|
1273
|
-
|
|
1274
|
-
// prepaint -- firefox is a little slow so flashes empty tiles sometimes
|
|
1275
|
-
|
|
1276
|
-
// context.fillStyle = '#fff'; // FIXME: use theme color
|
|
1277
|
-
// context.fillRect(0, 0, tile.width, tile.height);
|
|
1278
|
-
}
|
|
1279
|
-
*/
|
|
1280
|
-
|
|
1281
1294
|
return tile;
|
|
1282
1295
|
|
|
1283
1296
|
}
|
|
@@ -1319,7 +1332,9 @@ export abstract class BaseLayout {
|
|
|
1319
1332
|
|
|
1320
1333
|
// TODO: dropdown caret
|
|
1321
1334
|
|
|
1322
|
-
this.dropdown_list.style.font = Style.
|
|
1335
|
+
this.dropdown_list.style.font = Style.CompositeFont(theme.grid_cell_font_size, {
|
|
1336
|
+
font_face: 'stack:default',
|
|
1337
|
+
}, this.scale, theme).font;
|
|
1323
1338
|
|
|
1324
1339
|
// testing
|
|
1325
1340
|
|
|
@@ -99,6 +99,13 @@ export class GridLayout extends BaseLayout {
|
|
|
99
99
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
public FocusInLayout(target?: EventTarget): boolean {
|
|
103
|
+
if (target && target instanceof Element && this.container?.contains(target)) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
102
109
|
public ResizeCursor(resize?: 'row'|'column'): void {
|
|
103
110
|
switch (resize) {
|
|
104
111
|
case 'row':
|