@gramlot/gramlot 0.3.16 → 0.3.17
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/dist/components/editors/__init__.py +1 -1
- package/dist/components/editors/assets/collection.js +16162 -11689
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/grammar.json +3 -0
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +134 -179
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +19 -0
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +4643 -3481
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +509 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +306 -94
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +16 -0
- package/dist/components/typst/__init__.py +1 -1
- package/dist/components/typst/assets/collection.js +2 -2
- package/dist/components/typst/assets/index.js +1 -1
- package/dist/gramlot.js +2124 -506
- package/dist/gramlot.min.js +95 -40
- package/dist/runtime-notices.json +4 -0
- package/package.json +12 -8
- package/src/binding/device-resolver.js +27 -0
- package/src/binding/error-notifications.js +84 -0
- package/src/binding/remote-resolver.d.ts +18 -0
- package/src/binding/remote.js +11 -4
- package/src/binding/runtime.js +6 -2
- package/src/bootstrap.js +4 -4
- package/src/components/buttons.js +10 -3
- package/src/components/code-mirror-engine.js +14 -4
- package/src/components/code-mirror.js +2 -3
- package/src/components/container.js +1 -1
- package/src/components/date-calendar.js +1 -1
- package/src/components/formlet-labels.js +5 -4
- package/src/components/html-document.js +4 -2
- package/src/components/html-editor.js +2 -2
- package/src/components/jodit-engine.js +72 -11
- package/src/components/labelbox.js +19 -63
- package/src/components/layout.js +31 -19
- package/src/components/markdown-document.js +1 -1
- package/src/components/markdown-editor.js +2 -2
- package/src/components/menus.js +7 -6
- package/src/components/prose-mirror-engine.js +14 -1
- package/src/components/registry.js +2 -0
- package/src/components/selected-container.js +107 -14
- package/src/components/toolbar-overflow.js +9 -8
- package/src/components/transform-pane.js +140 -0
- package/src/components/tray-geometry.js +87 -0
- package/src/components/tray-pane.js +435 -0
- package/src/components/tray-settings.js +62 -0
- package/src/components/tree.js +115 -21
- package/src/components/typed-editor.js +1 -1
- package/src/components/typst-client.js +14 -13
- package/src/components/validation.js +1 -1
- package/src/components/window-surface.js +281 -0
- package/src/components/windows.js +32 -261
- package/src/device-frames.js +195 -0
- package/src/filesystem.d.ts +12 -5
- package/src/filesystem.js +8 -8
- package/src/gramlot.d.ts +3 -1
- package/src/gramlot.js +11 -4
- package/src/handlers/device-handler.d.ts +75 -0
- package/src/handlers/device-handler.js +1037 -0
- package/src/handlers/dom-handler.d.ts +2 -0
- package/src/handlers/dom-handler.js +9 -0
- package/src/handlers/rpc-handler.d.ts +2 -2
- package/src/http-transport.d.ts +3 -3
- package/src/http-transport.js +17 -11
- package/src/ide-documents.js +6 -4
- package/src/ide-runtime.d.ts +14 -3
- package/src/ide-runtime.js +123 -94
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +91 -43
- package/src/index-page-styles.js +1 -1
- package/src/index.d.ts +7 -2
- package/src/index.js +5 -1
- package/src/inout.d.ts +1 -1
- package/src/inout.js +5 -1
- package/src/mobile-environment.d.ts +6 -0
- package/src/mobile-environment.js +52 -0
- package/src/navigation-resolver.d.ts +14 -2
- package/src/renderer/attributes.js +5 -2
- package/src/renderer/drag-drop.js +5 -4
- package/src/renderer/gramlot-renderer.d.ts +13 -2
- package/src/renderer/gramlot-renderer.js +49 -13
- package/src/server/index-page.js +4 -4
- package/src/view/controls.js +48 -23
- package/src/view/html.js +85 -4
- package/src/view/labelbox.js +95 -0
- package/themes/gramlot-base/theme.css +4 -0
- package/themes/mela/theme.css +62 -15
- package/src/date-parser/civil.js +0 -61
- package/src/date-parser/index.d.ts +0 -18
- package/src/date-parser/index.js +0 -196
- package/src/date-parser/locales.js +0 -257
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** Shared DOM presentation; instance-owned projection cache, no application state. */
|
|
2
|
+
export const labelboxPositions = ['TL', 'TC', 'TR', 'L', 'R', 'BL', 'BC', 'BR'];
|
|
3
|
+
export const labelboxStyle = `.gramlot-labelbox[hidden]{display:none!important}
|
|
4
|
+
.gramlot-labelbox{box-sizing:border-box;min-width:0;min-height:0;--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control';grid-template-columns:minmax(0,1fr);grid-template-rows:max-content minmax(0,1fr)}
|
|
5
|
+
.gramlot-labelbox>.label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .gramlot-labelbox>.control-box{box-sizing:border-box;grid-area:control;min-width:0;min-height:0;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
|
|
6
|
+
.gramlot-labelbox>.control-box>*{max-width:100%;box-sizing:border-box}
|
|
7
|
+
.gramlot-labelbox[data-position='L']{grid-template-areas:'label control';grid-template-rows:minmax(0,1fr)}
|
|
8
|
+
.gramlot-labelbox[data-position='R']{grid-template-areas:'control label';grid-template-columns:minmax(0,1fr) max-content;grid-template-rows:minmax(0,1fr)}
|
|
9
|
+
.gramlot-labelbox[data-position='L']>.label-box,.gramlot-labelbox[data-position='R']>.label-box{align-self:center}
|
|
10
|
+
.gramlot-labelbox[data-position^='B']{grid-template-areas:'control' 'label';grid-template-rows:minmax(0,1fr) max-content}
|
|
11
|
+
.gramlot-labelbox[data-position$='C']>.label-box{text-align:center}
|
|
12
|
+
.gramlot-labelbox[data-position$='R']>.label-box{text-align:right}
|
|
13
|
+
.gramlot-labelbox>.label-box[hidden]{display:none} .gramlot-labelbox>.label-box label{display:block}
|
|
14
|
+
.gramlot-labelbox[data-position='L']>.label-box{text-align:right;padding-right:2px}
|
|
15
|
+
.gramlot-labelbox[data-formlet-aligned]>.label-box>label{width:max-content;margin-left:auto}
|
|
16
|
+
.gramlot-labelbox[data-position='L']{grid-template-columns:var(--gramlot-label-width,var(--gramlot-formlet-label-width,max-content)) minmax(0,1fr)}
|
|
17
|
+
.gramlot-labelbox:has(>.label-box[hidden]){gap:0;grid-template-areas:'control';grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
|
|
18
|
+
.gramlot-labelbox[data-variant='card']{gap:0;border:1px solid var(--gramlot-border-control,#b9c2ce);border-radius:var(--gramlot-window-radius,9px);background:var(--gramlot-surface,#fff);box-shadow:0 3px 10px #0002}
|
|
19
|
+
.gramlot-labelbox[data-variant='card']>.label-box{background:var(--gramlot-card-header-background,#303946);color:var(--gramlot-card-header-color,#fff);padding:7px 12px;border-radius:calc(var(--gramlot-window-radius,9px) - 1px) calc(var(--gramlot-window-radius,9px) - 1px) 0 0;font-weight:600}
|
|
20
|
+
.gramlot-labelbox[data-variant='card']>.control-box{padding:12px}
|
|
21
|
+
.gramlot-labelbox[data-movable]>.label-box{cursor:grab;touch-action:none;user-select:none}
|
|
22
|
+
.gramlot-labelbox[data-selected]{outline:2px solid var(--gramlot-focus-ring,var(--gramlot-brand-blue,#3766b5));outline-offset:-2px}
|
|
23
|
+
.gramlot-labelbox[data-tray-block]>.label-box{position:relative;padding-inline:32px 60px}
|
|
24
|
+
.gramlot-labelbox>.label-box>.tray-settings-button{position:absolute;right:3px;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:26px;height:26px;padding:4px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:pointer}
|
|
25
|
+
.gramlot-labelbox>.label-box>button[hidden]{display:none}
|
|
26
|
+
.gramlot-labelbox>.label-box>.tray-settings-button[data-kind=layer]{right:31px}
|
|
27
|
+
.tray-settings-button{opacity:.65}
|
|
28
|
+
.tray-settings-button:hover,.tray-settings-button:focus-visible{opacity:1}
|
|
29
|
+
.tray-settings-button svg{width:18px;height:18px;pointer-events:none}
|
|
30
|
+
.gramlot-labelbox>.label-box>.tray-settings-button:hover{background:color-mix(in srgb,currentColor 12%,transparent)}
|
|
31
|
+
.tray-settings-button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
32
|
+
|
|
33
|
+
.gramlot-labelbox>.label-box>.tray-rotate{position:absolute;left:3px;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:26px;height:26px;padding:4px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:grab;touch-action:none;opacity:.7}
|
|
34
|
+
.tray-rotate svg{width:18px;height:18px;pointer-events:none}
|
|
35
|
+
.gramlot-labelbox>.label-box>.tray-rotate:hover{opacity:1;background:color-mix(in srgb,currentColor 12%,transparent)}
|
|
36
|
+
.tray-rotate:focus-visible{opacity:1;outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
37
|
+
.gramlot-labelbox[data-rotating]>.label-box>.tray-rotate{cursor:grabbing}
|
|
38
|
+
.gramlot-labelbox[data-moving]>.label-box{cursor:grabbing}
|
|
39
|
+
.gramlot-labelbox[data-resizable]>.control-box{overflow:auto}
|
|
40
|
+
.gramlot-labelbox>.tray-resize{position:absolute;right:1px;bottom:1px;width:22px;height:22px;padding:2px;display:grid;place-items:end;border:0;background:transparent;color:inherit;cursor:nwse-resize;touch-action:none;border-radius:3px;opacity:.65}
|
|
41
|
+
.gramlot-labelbox>.tray-resize[hidden]{display:none}
|
|
42
|
+
.gramlot-labelbox>.tray-resize svg{width:16px;height:16px;pointer-events:none}
|
|
43
|
+
.gramlot-labelbox>.tray-resize:hover,.gramlot-labelbox>.tray-resize:focus-visible{opacity:1}
|
|
44
|
+
.gramlot-labelbox>.tray-resize:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}`;
|
|
45
|
+
|
|
46
|
+
export function createLabelbox(document, controlBox) {
|
|
47
|
+
const box = document.createElement('div'), labelBox = document.createElement('div');
|
|
48
|
+
const fieldLabel = document.createElement('label');
|
|
49
|
+
labelBox.append(fieldLabel); box.append(labelBox, controlBox);
|
|
50
|
+
const layout = {box, labelBox, fieldLabel, controlBox, previous: {box:{},label:{},labelBox:{},controlBox:{}}};
|
|
51
|
+
box.labelbox = layout;
|
|
52
|
+
return layout;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function projectLabelbox(layout, attrs, adapt) {
|
|
56
|
+
const {lbl, lbl_variant, lbl_position = lbl_variant === 'card' ? 'TC' : 'TL', ...rest} = attrs;
|
|
57
|
+
if (!labelboxPositions.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
|
|
58
|
+
const groups = {box:{},label:{},labelBox:{},controlBox:{}};
|
|
59
|
+
const prefixes = [['box_l_','labelBox'],['box_c_','controlBox'],['lbl_','label'],['box_','box']];
|
|
60
|
+
for (const [name,value] of Object.entries(rest)) {
|
|
61
|
+
const match = prefixes.find(([prefix]) => name.startsWith(prefix));
|
|
62
|
+
if (match) { groups[match[1]][name.slice(match[0].length)] = value; delete rest[name]; }
|
|
63
|
+
}
|
|
64
|
+
const elements = {box:layout.box,label:layout.fieldLabel,labelBox:layout.labelBox,controlBox:layout.controlBox};
|
|
65
|
+
for (const [name,element] of Object.entries(elements)) {
|
|
66
|
+
const next = adapt(groups[name]), previous = layout.previous[name];
|
|
67
|
+
for (const key of new Set([...Object.keys(previous),...Object.keys(next)])) {
|
|
68
|
+
if (next[key] == null) element.removeAttribute(key);
|
|
69
|
+
else element.setAttribute(key,String(next[key]));
|
|
70
|
+
}
|
|
71
|
+
layout.previous[name] = next;
|
|
72
|
+
}
|
|
73
|
+
if (attrs.lbl_width == null) layout.box.style.removeProperty('--gramlot-label-width');
|
|
74
|
+
else layout.box.style.setProperty('--gramlot-label-width',attrs.lbl_width);
|
|
75
|
+
layout.box.classList.add('labelbox','gramlot-labelbox');
|
|
76
|
+
layout.labelBox.classList.add('label-box'); layout.controlBox.classList.add('control-box');
|
|
77
|
+
layout.box.dataset.position = lbl_position;
|
|
78
|
+
if (lbl_variant == null) delete layout.box.dataset.variant;
|
|
79
|
+
else layout.box.dataset.variant = lbl_variant;
|
|
80
|
+
layout.fieldLabel.textContent = lbl ?? '';
|
|
81
|
+
layout.labelBox.hidden = lbl == null || lbl === '';
|
|
82
|
+
layout.box.dispatchEvent(new layout.box.ownerDocument.defaultView.Event('gramlot-label-layout', {bubbles:true}));
|
|
83
|
+
return rest;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Content identity behind an optional renderer-created Labelbox presentation. */
|
|
87
|
+
export function labelboxContent(presentation) {
|
|
88
|
+
return presentation?.labelbox ? presentation.labelbox.controlBox.firstElementChild : presentation;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Layout surface of content; ordinary unwrapped DOM remains its own surface. */
|
|
92
|
+
export function labelboxPresentation(content) {
|
|
93
|
+
const box = content?.parentElement?.parentElement;
|
|
94
|
+
return box?.labelbox && labelboxContent(box) === content ? box : content;
|
|
95
|
+
}
|
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
--gramlot-label-size: 1em;
|
|
43
43
|
--gramlot-font-ui: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
|
44
44
|
--gramlot-font-code: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
45
|
+
--gramlot-editor-keyword: light-dark(#754052, #d5a7bc);
|
|
46
|
+
--gramlot-editor-string: light-dark(#35634d, #a7c5ac);
|
|
47
|
+
--gramlot-editor-number: light-dark(#80552d, #d6b58e);
|
|
48
|
+
--gramlot-editor-function: light-dark(#365f87, #a5bfdc);
|
|
45
49
|
--gramlot-space-1: 0.25rem;
|
|
46
50
|
--gramlot-space-2: 0.5rem;
|
|
47
51
|
--gramlot-space-3: 0.75rem;
|
package/themes/mela/theme.css
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
--gramlot-tree-selected-background: var(--gramlot-selected);
|
|
9
9
|
--gramlot-tree-selected-color: var(--gramlot-ink);
|
|
10
10
|
--gramlot-window-backdrop: rgb(0 0 0 / 24%);
|
|
11
|
-
--gramlot-background: #
|
|
11
|
+
--gramlot-background: #f2f2f7;
|
|
12
12
|
--gramlot-surface: #ffffff;
|
|
13
13
|
--gramlot-surface-subtle: #eaeaed;
|
|
14
14
|
--gramlot-ink: #1d1d1f;
|
|
15
15
|
--gramlot-text-secondary: #636366;
|
|
16
16
|
--gramlot-border: #d9d9de;
|
|
17
|
-
--gramlot-border-control: #
|
|
17
|
+
--gramlot-border-control: #8a8a8e;
|
|
18
18
|
--gramlot-action: #0066cc;
|
|
19
19
|
--gramlot-action-hover: #004c99;
|
|
20
20
|
--gramlot-selected: #dceaff;
|
|
@@ -38,8 +38,10 @@
|
|
|
38
38
|
--gramlot-field-font-size: 1rem;
|
|
39
39
|
--gramlot-button-padding: 3px 9px;
|
|
40
40
|
--gramlot-button-gap: 4px;
|
|
41
|
-
--gramlot-button-background:
|
|
42
|
-
--gramlot-button-
|
|
41
|
+
--gramlot-button-background: #0066cc;
|
|
42
|
+
--gramlot-button-color: #ffffff;
|
|
43
|
+
--gramlot-chrome-background: var(--gramlot-surface);
|
|
44
|
+
--gramlot-button-hover: #004c99;
|
|
43
45
|
--gramlot-label-size: 1em;
|
|
44
46
|
--gramlot-label-gap: 4px;
|
|
45
47
|
--gramlot-radius-sm: 6px;
|
|
@@ -69,8 +71,8 @@
|
|
|
69
71
|
@media (prefers-color-scheme: dark) {
|
|
70
72
|
:root:not([data-theme="light"]) {
|
|
71
73
|
color-scheme: dark;
|
|
72
|
-
--gramlot-background: #
|
|
73
|
-
--gramlot-surface: #
|
|
74
|
+
--gramlot-background: #000000;
|
|
75
|
+
--gramlot-surface: #1c1c1e;
|
|
74
76
|
--gramlot-surface-subtle: #38383a;
|
|
75
77
|
--gramlot-ink: #f5f5f7;
|
|
76
78
|
--gramlot-text-secondary: #bdbdc4;
|
|
@@ -78,8 +80,8 @@
|
|
|
78
80
|
--gramlot-border-control: #74747c;
|
|
79
81
|
--gramlot-action: #70b7ff;
|
|
80
82
|
--gramlot-action-hover: #abd5ff;
|
|
81
|
-
--gramlot-selected: #
|
|
82
|
-
--gramlot-field-background: #
|
|
83
|
+
--gramlot-selected: #244367;
|
|
84
|
+
--gramlot-field-background: #1c1c1e;
|
|
83
85
|
--gramlot-field-readonly-background: #38383a;
|
|
84
86
|
--gramlot-label-color: #bdbdc4;
|
|
85
87
|
--gramlot-focus-ring: #70b7ff;
|
|
@@ -97,8 +99,8 @@
|
|
|
97
99
|
}
|
|
98
100
|
:root[data-theme="dark"] {
|
|
99
101
|
color-scheme: dark;
|
|
100
|
-
--gramlot-background: #
|
|
101
|
-
--gramlot-surface: #
|
|
102
|
+
--gramlot-background: #000000;
|
|
103
|
+
--gramlot-surface: #1c1c1e;
|
|
102
104
|
--gramlot-surface-subtle: #38383a;
|
|
103
105
|
--gramlot-ink: #f5f5f7;
|
|
104
106
|
--gramlot-text-secondary: #bdbdc4;
|
|
@@ -106,8 +108,8 @@
|
|
|
106
108
|
--gramlot-border-control: #74747c;
|
|
107
109
|
--gramlot-action: #70b7ff;
|
|
108
110
|
--gramlot-action-hover: #abd5ff;
|
|
109
|
-
--gramlot-selected: #
|
|
110
|
-
--gramlot-field-background: #
|
|
111
|
+
--gramlot-selected: #244367;
|
|
112
|
+
--gramlot-field-background: #1c1c1e;
|
|
111
113
|
--gramlot-field-readonly-background: #38383a;
|
|
112
114
|
--gramlot-label-color: #bdbdc4;
|
|
113
115
|
--gramlot-focus-ring: #70b7ff;
|
|
@@ -136,11 +138,15 @@
|
|
|
136
138
|
:where(button,input[type="button"],input[type="submit"],input[type="reset"],.button) {
|
|
137
139
|
min-block-size: var(--gramlot-field-height); padding: var(--gramlot-button-padding);
|
|
138
140
|
font-size: 1rem; line-height: 1.3; font-weight: 500;
|
|
139
|
-
background: var(--gramlot-button-background); color:
|
|
141
|
+
background: var(--gramlot-button-background); color: #ffffff; border-color: transparent;
|
|
140
142
|
}
|
|
141
143
|
:where(button,input[type="button"],input[type="submit"],input[type="reset"],.button):hover:not(:disabled) {
|
|
142
|
-
background:
|
|
144
|
+
background: #004c99; color: #ffffff; border-color: transparent;
|
|
143
145
|
}
|
|
146
|
+
gramlot-button.button--secondary,gramlot-toggle-button.button--secondary,gramlot-drop-down-button.button--secondary { background:transparent; border-color:transparent; }
|
|
147
|
+
:where(.button--secondary,button.secondary) { background:var(--gramlot-selected); color:var(--gramlot-action); border-color:transparent; }
|
|
148
|
+
:where(.button--secondary,button.secondary):hover:not(:disabled) { background:var(--gramlot-selected); color:var(--gramlot-action-hover); border-color:var(--gramlot-action); }
|
|
149
|
+
:where(button,.button):active:not(:disabled) { transform:none; filter:brightness(.9); }
|
|
144
150
|
:where(label) { font-size: 1em; font-weight: 400; color: var(--gramlot-label-color); margin-block-end: var(--gramlot-label-gap); }
|
|
145
151
|
:where(input[readonly],textarea[readonly]) { background: var(--gramlot-field-readonly-background); }
|
|
146
152
|
:where(.button--quiet,button.quiet) { background: transparent; color: var(--gramlot-action); border-color: transparent; }
|
|
@@ -179,6 +185,47 @@
|
|
|
179
185
|
}
|
|
180
186
|
@layer gramlot.base {
|
|
181
187
|
@media (max-width: 640px), (pointer: coarse) {
|
|
182
|
-
html { font-size:
|
|
188
|
+
html { font-size: 17px; }
|
|
189
|
+
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }
|
|
190
|
+
body { line-height:1.4; }
|
|
191
|
+
h1 { font-size:2rem; font-weight:700; letter-spacing:-.025em; }
|
|
192
|
+
h2 { font-size:1.3rem; font-weight:650; }
|
|
193
|
+
h3 { font-size:1.05rem; font-weight:600; }
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* Touch presentation follows the existing density setting; minimums grow with text. */
|
|
198
|
+
@layer gramlot.touch {
|
|
199
|
+
@media (max-width:640px), (pointer:coarse) {
|
|
200
|
+
:root:not([data-gramlot-touch="off"]) {
|
|
201
|
+
--gramlot-field-height:max(44px,2.65rem); --gramlot-field-font-size:max(16px,1rem);
|
|
202
|
+
--gramlot-field-padding:.55rem .75rem; --gramlot-button-padding:.6rem 1rem;
|
|
203
|
+
--gramlot-label-size:.88rem; --gramlot-label-gap:.4rem;
|
|
204
|
+
--gramlot-tree-row-height:max(44px,2.65rem); --gramlot-tab-height:max(44px,2.65rem);
|
|
205
|
+
}
|
|
206
|
+
:where(button,.button,summary,[role="tab"],a) { min-block-size:44px; }
|
|
207
|
+
:where(nav a,.actions a) { display:inline-flex; align-items:center; }
|
|
208
|
+
:where(label:has(input[type="checkbox"]),label:has(input[type="radio"])) { min-block-size:44px; display:inline-flex; align-items:center; gap:.6rem; }
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/* Content stays opaque. Materials are confined to navigation controls. */
|
|
212
|
+
@layer gramlot.components {
|
|
213
|
+
:where([role="toolbar"]) { --gramlot-button-padding:4px 6px; background:var(--gramlot-surface); color:var(--gramlot-ink); }
|
|
214
|
+
@supports (backdrop-filter:blur(16px)) {
|
|
215
|
+
:where([role="toolbar"]) { background:color-mix(in srgb,var(--gramlot-surface) 92%,transparent); backdrop-filter:blur(16px) saturate(1.2); }
|
|
216
|
+
}
|
|
217
|
+
@media (prefers-reduced-transparency:reduce), (prefers-contrast:more) {
|
|
218
|
+
:where([role="toolbar"]) { background:var(--gramlot-surface); backdrop-filter:none; }
|
|
219
|
+
}
|
|
220
|
+
@media (prefers-contrast:more) {
|
|
221
|
+
:where(input,select,textarea,button,.button) { border:2px solid currentColor; }
|
|
222
|
+
:where(a) { text-decoration:underline; }
|
|
223
|
+
}
|
|
224
|
+
@media (prefers-reduced-motion:reduce) {
|
|
225
|
+
:where(button,.button) { transition:none; transform:none; }
|
|
226
|
+
}
|
|
227
|
+
@media (forced-colors:active) {
|
|
228
|
+
:where(button,.button) { background:ButtonFace; color:ButtonText; border-color:ButtonText; filter:none; }
|
|
229
|
+
:where([role="toolbar"]) { background:Canvas; color:CanvasText; backdrop-filter:none; }
|
|
183
230
|
}
|
|
184
231
|
}
|
package/src/date-parser/civil.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
// Copyright 2026 Softwell S.r.l. - SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Gregorian civil calendar arithmetic. No clock, timezone, or Date object.
|
|
3
|
-
export function daysInMonth(year, month) {
|
|
4
|
-
if (month === 2) return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
|
|
5
|
-
return [4, 6, 9, 11].includes(month) ? 30 : 31;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function civil(year, month, day) {
|
|
9
|
-
if (![year, month, day].every(Number.isInteger) || year < 1 || year > 9999 ||
|
|
10
|
-
month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) {
|
|
11
|
-
throw new RangeError('Date must exist in Gregorian years 0001–9999.');
|
|
12
|
-
}
|
|
13
|
-
return `${String(year).padStart(4, '0')}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parts(date) {
|
|
17
|
-
if (typeof date !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
18
|
-
throw new RangeError('Expected a civil date in YYYY-MM-DD format.');
|
|
19
|
-
}
|
|
20
|
-
const result = date.split('-').map(Number);
|
|
21
|
-
civil(...result);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function ordinal(year, month, day) {
|
|
26
|
-
const previous = year - 1;
|
|
27
|
-
let result = 365 * previous + Math.floor(previous / 4) - Math.floor(previous / 100) +
|
|
28
|
-
Math.floor(previous / 400) + day - 1;
|
|
29
|
-
for (let m = 1; m < month; m++) result += daysInMonth(year, m);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function addDays(date, offset) {
|
|
34
|
-
let target = ordinal(...parts(date)) + offset;
|
|
35
|
-
if (!Number.isSafeInteger(target) || target < 0 || target > ordinal(9999, 12, 31)) {
|
|
36
|
-
throw new RangeError('Date offset exceeds Gregorian years 0001–9999.');
|
|
37
|
-
}
|
|
38
|
-
// Binary search keeps arbitrarily large supported offsets bounded.
|
|
39
|
-
let low = 1, high = 10000;
|
|
40
|
-
while (high - low > 1) {
|
|
41
|
-
const middle = Math.floor((low + high) / 2);
|
|
42
|
-
if (ordinal(middle, 1, 1) <= target) low = middle;
|
|
43
|
-
else high = middle;
|
|
44
|
-
}
|
|
45
|
-
target -= ordinal(low, 1, 1);
|
|
46
|
-
let month = 1;
|
|
47
|
-
while (target >= daysInMonth(low, month)) target -= daysInMonth(low, month++);
|
|
48
|
-
return civil(low, month, target + 1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function monday(date) {
|
|
52
|
-
return addDays(date, -(ordinal(...parts(date)) % 7));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function monthPeriod(year, month, offset = 0, count = 1) {
|
|
56
|
-
const index = year * 12 + month - 1 + offset;
|
|
57
|
-
const y = Math.floor(index / 12), m = ((index % 12) + 12) % 12 + 1;
|
|
58
|
-
const endIndex = index + count - 1;
|
|
59
|
-
const ey = Math.floor(endIndex / 12), em = ((endIndex % 12) + 12) % 12 + 1;
|
|
60
|
-
return {start: civil(y, m, 1), end: civil(ey, em, daysInMonth(ey, em))};
|
|
61
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Natural-language civil dates and periods, independent of DOM, clock and timezone. */
|
|
2
|
-
export interface DateExpressionOptions {
|
|
3
|
-
/** Required Gregorian civil ISO date, YYYY-MM-DD (0001–9999). */
|
|
4
|
-
workdate: string;
|
|
5
|
-
/** Supported Italian/English locale; defaults to it-IT. */
|
|
6
|
-
locale?: string;
|
|
7
|
-
/** Integer 0–99, default 20. Inclusive window [work year + ahead - 100, work year + ahead - 1]. */
|
|
8
|
-
twoDigitYearAhead?: number;
|
|
9
|
-
}
|
|
10
|
-
export type DateExpressionErrorCode = 'INVALID_CONTEXT' | 'INVALID_INPUT' |
|
|
11
|
-
'UNRECOGNIZED_EXPRESSION' | 'INVALID_DATE' |
|
|
12
|
-
'INVALID_RANGE';
|
|
13
|
-
export type DateExpressionResult =
|
|
14
|
-
{ok: true; kind: 'date'; date: string} |
|
|
15
|
-
{ok: true; kind: 'period'; start: string | null; end: string | null} |
|
|
16
|
-
{ok: false; error: {code: DateExpressionErrorCode; message: string}};
|
|
17
|
-
/** Parse a complete expression without reading or modifying page state. */
|
|
18
|
-
export function parseDateExpression(text: string, options: DateExpressionOptions): DateExpressionResult;
|
package/src/date-parser/index.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/* @ts-self-types="./index.d.ts" */
|
|
2
|
-
// Copyright 2026 Softwell S.r.l. - SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
// Semantics ported from genro-toolbox dates/period_parser.py; see PORT-0009.
|
|
4
|
-
import {addDays, civil, monday, monthPeriod, parts, daysInMonth} from './civil.js';
|
|
5
|
-
import {localeContext} from './locales.js';
|
|
6
|
-
|
|
7
|
-
const yearPattern = /^(?:\d{4}|\d{2})$/;
|
|
8
|
-
const dayPattern = /^\d{1,2}$/;
|
|
9
|
-
const fail = (code, message) => ({ok: false, error: {code, message}});
|
|
10
|
-
const unrecognized = (code = 'UNRECOGNIZED_EXPRESSION', message = 'Text is not a supported date expression.') => {
|
|
11
|
-
throw Object.assign(new SyntaxError(message), {code});
|
|
12
|
-
};
|
|
13
|
-
const own = (object, key) => Object.hasOwn(object, key);
|
|
14
|
-
|
|
15
|
-
function decodeYear(text, context) {
|
|
16
|
-
if (text.length === 4) return Number(text);
|
|
17
|
-
const lowest = context.year + context.twoDigitYearAhead - 100;
|
|
18
|
-
return lowest + ((Number(text) - lowest) % 100 + 100) % 100;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function boundTexts(text, context) {
|
|
22
|
-
if (text.includes(';')) {
|
|
23
|
-
const bounds = text.split(';').map(part => part.trim());
|
|
24
|
-
if (bounds.length !== 2) return unrecognized('INVALID_RANGE', 'A range must have exactly two endpoints.');
|
|
25
|
-
return {bounds, range: true};
|
|
26
|
-
}
|
|
27
|
-
if (context.phrases('no_period').includes(text)) return {bounds: ['', ''], range: true};
|
|
28
|
-
const to = context.phrases('to'), from = context.phrases('from');
|
|
29
|
-
for (const word of to) {
|
|
30
|
-
if (text.startsWith(`${word} `)) return {bounds: ['', text.slice(word.length + 1).trim()], range: true};
|
|
31
|
-
}
|
|
32
|
-
for (const word of to) {
|
|
33
|
-
const separator = ` ${word} `;
|
|
34
|
-
if (!text.includes(separator)) continue;
|
|
35
|
-
for (const prefix of from) {
|
|
36
|
-
if (text.startsWith(`${prefix} `)) {
|
|
37
|
-
text = text.slice(prefix.length + 1);
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const bounds = text.split(separator).map(part => part.trim());
|
|
42
|
-
if (bounds.length !== 2) return unrecognized('INVALID_RANGE', 'A range must have exactly two endpoints.');
|
|
43
|
-
return {bounds, range: true};
|
|
44
|
-
}
|
|
45
|
-
for (const word of from) {
|
|
46
|
-
if (text.startsWith(`${word} `)) return {bounds: [text.slice(word.length + 1).trim(), ''], range: true};
|
|
47
|
-
}
|
|
48
|
-
return {bounds: [text, text], range: false};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function keywordDate(text, context, isEnd) {
|
|
52
|
-
const candidates = [[text, 0]];
|
|
53
|
-
const offset = /^(.+?)\s*([+-])\s*(\d+)$/.exec(text);
|
|
54
|
-
if (offset) candidates.push([offset[1], Number(offset[2] + offset[3])]);
|
|
55
|
-
const shifts = {today: 0, yesterday: -1, tomorrow: 1,
|
|
56
|
-
this_week: 0, last_week: -1, next_week: 1,
|
|
57
|
-
this_month: 0, last_month: -1, next_month: 1};
|
|
58
|
-
for (const [body, amount] of candidates) {
|
|
59
|
-
for (const [key, shift] of Object.entries(shifts)) {
|
|
60
|
-
if (!context.phrases(key).includes(body)) continue;
|
|
61
|
-
if (key.endsWith('_week')) return addDays(monday(context.workdate), (shift + amount) * 7 + (isEnd ? 6 : 0));
|
|
62
|
-
if (key.endsWith('_month')) {
|
|
63
|
-
const span = monthPeriod(context.year, context.month, shift + amount);
|
|
64
|
-
return isEnd ? span.end : span.start;
|
|
65
|
-
}
|
|
66
|
-
return addDays(context.workdate, shift + amount);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function quarter(text, context, isEnd) {
|
|
73
|
-
const entries = Object.entries(context.dictionary.quarters).sort((a, b) => b[0].length - a[0].length);
|
|
74
|
-
for (const [name, number] of entries) {
|
|
75
|
-
let year;
|
|
76
|
-
if (text === name) year = null;
|
|
77
|
-
else if (text.startsWith(name) && yearPattern.test(text.slice(name.length).trim())) {
|
|
78
|
-
year = decodeYear(text.slice(name.length).trim(), context);
|
|
79
|
-
} else if (text.endsWith(name) && yearPattern.test(text.slice(0, -name.length).trim())) {
|
|
80
|
-
year = decodeYear(text.slice(0, -name.length).trim(), context);
|
|
81
|
-
} else continue;
|
|
82
|
-
return {year, month: isEnd ? number * 3 : number * 3 - 2};
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function monthNumber(token, dictionary) {
|
|
88
|
-
if (own(dictionary.months, token)) return dictionary.months[token];
|
|
89
|
-
const match = /^m(\d{1,2})$/.exec(token);
|
|
90
|
-
return match && Number(match[1]) >= 1 && Number(match[1]) <= 12 ? Number(match[1]) : null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function namedMonth(text, context) {
|
|
94
|
-
const tokens = text.split(/\s+/);
|
|
95
|
-
const positions = tokens.map((token, i) => monthNumber(token, context.dictionary) ? i : -1).filter(i => i >= 0);
|
|
96
|
-
if (!positions.length) return null;
|
|
97
|
-
if (positions.length !== 1) return unrecognized();
|
|
98
|
-
const position = positions[0], month = monthNumber(tokens[position], context.dictionary);
|
|
99
|
-
const before = tokens.slice(0, position), after = tokens.slice(position + 1), others = [...before, ...after];
|
|
100
|
-
if (others.length === 1 && context.phrases('last').includes(others[0])) {
|
|
101
|
-
return {year: context.year - (month > context.month ? 1 : 0), month};
|
|
102
|
-
}
|
|
103
|
-
if (others.length === 1 && context.phrases('next').includes(others[0])) {
|
|
104
|
-
return {year: context.year + (month < context.month ? 1 : 0), month};
|
|
105
|
-
}
|
|
106
|
-
if (!others.length) return {year: null, month};
|
|
107
|
-
if (!before.length && after.length === 1 && yearPattern.test(after[0])) return {year: decodeYear(after[0], context), month};
|
|
108
|
-
if (before.length === 1 && dayPattern.test(before[0])) {
|
|
109
|
-
if (!after.length) return civil(context.year, month, Number(before[0]));
|
|
110
|
-
if (after.length === 1 && yearPattern.test(after[0])) return civil(decodeYear(after[0], context), month, Number(before[0]));
|
|
111
|
-
}
|
|
112
|
-
if (!before.length && after.length === 2 && dayPattern.test(after[0]) && yearPattern.test(after[1])) {
|
|
113
|
-
return civil(decodeYear(after[1], context), month, Number(after[0]));
|
|
114
|
-
}
|
|
115
|
-
return unrecognized();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function numericDate(text, context) {
|
|
119
|
-
const iso = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
|
|
120
|
-
if (iso) return civil(...iso.slice(1).map(Number));
|
|
121
|
-
const numeric = /^(\d{1,4})[/\-. ]+(\d{1,4})[/\-. ]+(\d{1,4})$/.exec(text);
|
|
122
|
-
const values = {};
|
|
123
|
-
if (numeric) context.order.split('').forEach((letter, i) => { values[letter] = numeric[i + 1]; });
|
|
124
|
-
else if (/^(?:\d{6}|\d{8})$/.test(text)) {
|
|
125
|
-
const yearWidth = text.length === 8 ? 4 : 2;
|
|
126
|
-
for (const letter of context.order) {
|
|
127
|
-
const width = letter === 'Y' ? yearWidth : 2;
|
|
128
|
-
values[letter] = text.slice(0, width);
|
|
129
|
-
text = text.slice(width);
|
|
130
|
-
}
|
|
131
|
-
} else return null;
|
|
132
|
-
if (!yearPattern.test(values.Y) || values.D.length > 2 || values.M.length > 2) return unrecognized();
|
|
133
|
-
let day = Number(values.D), month = Number(values.M);
|
|
134
|
-
if (numeric && month > 12 && day <= 12) [day, month] = [month, day];
|
|
135
|
-
return civil(decodeYear(values.Y, context), month, day);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function getBound(text, context, isEnd) {
|
|
139
|
-
if (!text) return null;
|
|
140
|
-
const articles = context.phrases('articles');
|
|
141
|
-
text = text.split(/\s+/).filter(token => !articles.includes(token)).join(' ');
|
|
142
|
-
if (!text) return unrecognized();
|
|
143
|
-
if (yearPattern.test(text)) return civil(decodeYear(text, context), isEnd ? 12 : 1, isEnd ? 31 : 1);
|
|
144
|
-
const value = keywordDate(text, context, isEnd) ?? quarter(text, context, isEnd) ?? namedMonth(text, context);
|
|
145
|
-
if (value !== null) return value;
|
|
146
|
-
if (own(context.dictionary.weekdays, text)) return addDays(monday(context.workdate), context.dictionary.weekdays[text]);
|
|
147
|
-
return numericDate(text, context) ?? unrecognized();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function startDate(start, end, context) {
|
|
151
|
-
if (start === null || typeof start === 'string') return start;
|
|
152
|
-
let year = start.year ?? context.year;
|
|
153
|
-
const endYear = typeof end === 'string' ? parts(end)[0] : end?.year;
|
|
154
|
-
const endMonth = typeof end === 'string' ? parts(end)[1] : end?.month;
|
|
155
|
-
if (endYear) {
|
|
156
|
-
if (year > endYear) year = endYear;
|
|
157
|
-
if (year === endYear && start.month > endMonth) year--;
|
|
158
|
-
}
|
|
159
|
-
return civil(year, start.month, 1);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function endDate(end, start, context) {
|
|
163
|
-
if (end === null || typeof end === 'string') return end;
|
|
164
|
-
let year = end.year ?? context.year;
|
|
165
|
-
if (start !== null) {
|
|
166
|
-
const [startYear, startMonth] = parts(start);
|
|
167
|
-
if (year < startYear) year = startYear;
|
|
168
|
-
if (year === startYear && startMonth > end.month) year++;
|
|
169
|
-
}
|
|
170
|
-
return civil(year, end.month, daysInMonth(year, end.month));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** Parse a complete date expression using Toolbox semantics and structured JS outcomes. */
|
|
174
|
-
export function parseDateExpression(text, options = {}) {
|
|
175
|
-
if (!options || typeof options !== 'object' || Array.isArray(options)) return fail('INVALID_CONTEXT', 'Options must provide a civil workdate and supported locale.');
|
|
176
|
-
let context;
|
|
177
|
-
try {
|
|
178
|
-
const {locale = 'it-IT', workdate, twoDigitYearAhead = 20} = options;
|
|
179
|
-
const [year, month] = parts(workdate);
|
|
180
|
-
if (!Number.isInteger(twoDigitYearAhead) || twoDigitYearAhead < 0 || twoDigitYearAhead > 99) throw new RangeError('twoDigitYearAhead must be an integer from 0 to 99.');
|
|
181
|
-
context = {...localeContext(locale), workdate, year, month, twoDigitYearAhead};
|
|
182
|
-
} catch (error) { return fail('INVALID_CONTEXT', error.message); }
|
|
183
|
-
if (typeof text !== 'string') return fail('INVALID_INPUT', 'Expression must be a string.');
|
|
184
|
-
try {
|
|
185
|
-
const expression = text.toLowerCase().trim().replaceAll(',', '');
|
|
186
|
-
const {bounds, range} = boundTexts(expression, context);
|
|
187
|
-
const right = getBound(bounds[1], context, true), left = getBound(bounds[0], context, false);
|
|
188
|
-
const start = startDate(left, right, context), end = endDate(right, start, context);
|
|
189
|
-
if (!range && typeof left === 'string' && start === end) return {ok: true, kind: 'date', date: start};
|
|
190
|
-
return {ok: true, kind: 'period', start, end};
|
|
191
|
-
} catch (error) {
|
|
192
|
-
if (error instanceof RangeError) return fail('INVALID_DATE', error.message);
|
|
193
|
-
if (error instanceof SyntaxError) return fail(error.code, error.message);
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
}
|