@gramlot/gramlot 0.3.16 → 0.3.18
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 +2126 -506
- package/dist/gramlot.min.js +97 -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 +97 -0
- package/themes/gramlot-base/theme.css +10 -0
- package/themes/gramlot-compact/theme.css +6 -0
- package/themes/joanna/theme.css +6 -0
- package/themes/mela/theme.css +68 -15
- package/themes/mimi/theme.css +6 -0
- package/themes/palettes/compact.css +6 -0
- package/themes/palettes/joanna.css +6 -0
- package/themes/palettes/mimi.css +6 -0
- 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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/** Shared selection keeps panel Source and light DOM mounted until explicit closing. */
|
|
2
2
|
import {defineComponent} from './registry.js';
|
|
3
3
|
import {Container} from './container.js';
|
|
4
|
+
import {WindowSurface} from './window-surface.js';
|
|
5
|
+
import {SVG_NS} from '../renderer/attributes.js';
|
|
4
6
|
|
|
5
7
|
function SelectedContainer(HTMLElement) {
|
|
6
8
|
// Named as its factory: inside the body `SelectedContainer` is this class, owner of the static state.
|
|
@@ -10,12 +12,13 @@ function SelectedContainer(HTMLElement) {
|
|
|
10
12
|
static #selectionPanels = new WeakMap();
|
|
11
13
|
static #panelSequence = 0;
|
|
12
14
|
static projectChild(element, attrs, actions) {
|
|
13
|
-
const {pageName = null, title = '', icon = '', badge = null, badge_color = '', closable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
|
|
15
|
+
const {pageName = null, title = '', icon = '', badge = null, badge_color = '', closable = false, detachable = false, onClose, hidden = false, disabled = false, ...rest} = attrs;
|
|
14
16
|
if (pageName !== null && typeof pageName !== 'string') throw new TypeError('pageName must be a string');
|
|
15
17
|
if (typeof closable !== 'boolean') throw new TypeError('closable must be a boolean');
|
|
18
|
+
if (typeof detachable !== 'boolean') throw new TypeError('detachable must be a boolean');
|
|
16
19
|
const panels = SelectedContainer.#selectionPanels;
|
|
17
20
|
const slot = panels.get(element)?.slot ?? `panel-${++SelectedContainer.#panelSequence}`;
|
|
18
|
-
panels.set(element, {pageName, title, icon, badge, badge_color, closable, hidden, disabled, slot,
|
|
21
|
+
panels.set(element, {pageName, title, icon, badge, badge_color, closable, detachable, hidden, disabled, slot,
|
|
19
22
|
remove: actions.remove, allowClose: () => onClose == null ? true : actions.invoke('onClose', onClose, {})});
|
|
20
23
|
rest.slot = slot;
|
|
21
24
|
if (element.parentElement) element.parentElement.scheduleSelection();
|
|
@@ -42,7 +45,10 @@ function SelectedContainer(HTMLElement) {
|
|
|
42
45
|
}
|
|
43
46
|
setSourceContext(context) { this.#context = context; }
|
|
44
47
|
connectedCallback() { this.#observer.observe(this, {childList:true}); this.scheduleSelection(); }
|
|
45
|
-
disconnectedCallback() {
|
|
48
|
+
disconnectedCallback() {
|
|
49
|
+
this.#observer.disconnect();
|
|
50
|
+
for (const record of this.#panels.values()) this.reattachPanel(record, false);
|
|
51
|
+
}
|
|
46
52
|
scheduleSelection() {
|
|
47
53
|
if (this.#scheduled) return;
|
|
48
54
|
this.#scheduled = true;
|
|
@@ -75,11 +81,15 @@ function SelectedContainer(HTMLElement) {
|
|
|
75
81
|
record = {child, viewport, config, index:records.length}; this.#panels.set(child, record);
|
|
76
82
|
}
|
|
77
83
|
record.config = config;
|
|
84
|
+
if (record.surface) {
|
|
85
|
+
if (!config.detachable || config.hidden || config.disabled) this.reattachPanel(record, false);
|
|
86
|
+
else record.surface.configure({...record.surface.parameters, title:config.title || config.pageName || 'Panel'});
|
|
87
|
+
}
|
|
78
88
|
records.push(record);
|
|
79
89
|
}
|
|
80
90
|
const previousIndex = this.#selected?.index ?? 0;
|
|
81
91
|
for (const [child, record] of this.#panels) {
|
|
82
|
-
if (!records.includes(record)) { record.viewport.remove(); this.#panels.delete(child); }
|
|
92
|
+
if (!records.includes(record)) { this.reattachPanel(record, false); record.viewport.remove(); this.#panels.delete(child); }
|
|
83
93
|
}
|
|
84
94
|
records.forEach((record, index) => { record.index = index; });
|
|
85
95
|
this.#panels = new Map(records.map(record => [record.child, record]));
|
|
@@ -87,7 +97,7 @@ function SelectedContainer(HTMLElement) {
|
|
|
87
97
|
const nameChanged = !Object.is(selectedPage, this.#requested.selectedPage);
|
|
88
98
|
const indexChanged = !Object.is(selected, this.#requested.selected);
|
|
89
99
|
this.#requested = {selectedPage, selected};
|
|
90
|
-
const available = record => record && !record.config.hidden && !record.config.disabled;
|
|
100
|
+
const available = record => record && !record.surface && !record.config.hidden && !record.config.disabled;
|
|
91
101
|
let target = this.#selected;
|
|
92
102
|
if (!this.#initialized || nameChanged || indexChanged) {
|
|
93
103
|
const requested = (nameChanged || !this.#initialized && selectedPage != null)
|
|
@@ -103,6 +113,7 @@ function SelectedContainer(HTMLElement) {
|
|
|
103
113
|
renderTabs() {}
|
|
104
114
|
selectPanel(record) {
|
|
105
115
|
if (record.config.hidden || record.config.disabled) return;
|
|
116
|
+
if (record.surface) { record.surface.focus(); return; }
|
|
106
117
|
this.#select(record);
|
|
107
118
|
}
|
|
108
119
|
#payload(record, selected) {
|
|
@@ -124,12 +135,52 @@ function SelectedContainer(HTMLElement) {
|
|
|
124
135
|
if (target) this.#context.publish('showing', {pageName:target.config.pageName, index:target.index});
|
|
125
136
|
}
|
|
126
137
|
this.#selected = target; this.#initialized = true;
|
|
127
|
-
for (const record of this.#panels.values()) record.viewport.hidden = record !== target;
|
|
138
|
+
for (const record of this.#panels.values()) record.viewport.hidden = !record.surface && record !== target;
|
|
128
139
|
this.renderTabs([...this.#panels.values()], target);
|
|
129
140
|
this.#writeSelection(target);
|
|
130
141
|
if (!initial && previous) this.#context.publish('selected', this.#payload(previous, false));
|
|
131
142
|
if (target) this.#context.publish('selected', this.#payload(target, true));
|
|
132
143
|
}
|
|
144
|
+
detachPanel(record, position = null) {
|
|
145
|
+
if (!record.config.detachable || record.config.hidden || record.config.disabled) return;
|
|
146
|
+
if (record.surface) { record.surface.focus(); return; }
|
|
147
|
+
const doc = this.ownerDocument, mount = doc.createElement('div');
|
|
148
|
+
this.shadowRoot.append(mount);
|
|
149
|
+
const surface = new WindowSurface(this, mount, {modal:false, validateContent:() => {
|
|
150
|
+
if (record.viewport.parentNode !== surface.body) throw new Error('Detached panel lost its presentation');
|
|
151
|
+
}});
|
|
152
|
+
record.surface = surface; record.mount = mount;
|
|
153
|
+
surface.body.replaceChildren(record.viewport);
|
|
154
|
+
record.viewport.style.cssText = 'flex:1;min-width:0;height:100%;';
|
|
155
|
+
record.viewport.hidden = false;
|
|
156
|
+
surface.setSourceContext({
|
|
157
|
+
writeParameter:(name,value) => { surface.parameters[name] = value; },
|
|
158
|
+
publish:topic => { if (topic === 'closed') this.reattachPanel(record, true); },
|
|
159
|
+
callLogic:(name,kwargs) => this.#context.callLogic(name,kwargs),
|
|
160
|
+
});
|
|
161
|
+
const rect = this.getBoundingClientRect();
|
|
162
|
+
surface.configure({title:record.config.title || record.config.pageName || 'Panel', open:true,
|
|
163
|
+
movable:true, resizable:true, collapsible:false, maximizable:false, maximized:false,
|
|
164
|
+
collapsed:false, closable:true, beforeClose:null,
|
|
165
|
+
width:`${Math.max(320, Math.min(rect.width, 720))}px`, height:`${Math.max(240, Math.min(rect.height, 560))}px`,
|
|
166
|
+
left:position ? `${position.left}px` : null, top:position ? `${position.top}px` : null,
|
|
167
|
+
minWidth:'220px', minHeight:'140px'});
|
|
168
|
+
surface.connect();
|
|
169
|
+
if (record === this.#selected) this.#select([...this.#panels.values()].find(r => r !== record && !r.surface && !r.config.hidden && !r.config.disabled) ?? null);
|
|
170
|
+
else this.renderTabs([...this.#panels.values()], this.#selected);
|
|
171
|
+
}
|
|
172
|
+
reattachPanel(record, select = true) {
|
|
173
|
+
if (!record.surface) return;
|
|
174
|
+
const surface = record.surface; record.surface = null;
|
|
175
|
+
// Move only the viewport/slot, never the Source-owned content DOM.
|
|
176
|
+
this.panelArea.append(record.viewport); record.viewport.style.cssText = '';
|
|
177
|
+
surface.disconnect(); record.mount.remove(); record.mount = null;
|
|
178
|
+
record.viewport.hidden = record !== this.#selected;
|
|
179
|
+
if (select && record.child.isConnected) {
|
|
180
|
+
this.#select(record);
|
|
181
|
+
this.tabStrip.querySelector(`#tab-${record.config.slot}`).focus();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
133
184
|
closePanel(record) {
|
|
134
185
|
if (!record.config.closable) return;
|
|
135
186
|
const allowed = record.config.allowClose();
|
|
@@ -158,7 +209,7 @@ export const StackContainer = defineComponent({
|
|
|
158
209
|
|
|
159
210
|
export const TabContainer = defineComponent({
|
|
160
211
|
name:'tabContainer', tag:'gramlot-tab-container', base:SelectedContainer, subTags:'*',
|
|
161
|
-
sourceContext: true, childParameters: selectionChildParameters,
|
|
212
|
+
sourceContext: true, childParameters: {...selectionChildParameters, detachable:{dtype:'B'}},
|
|
162
213
|
parameters: {
|
|
163
214
|
tabMode: {dtype:'T', default:'tabs', binding:'read', enum:['tabs','underline']},
|
|
164
215
|
tabPosition: {dtype:'T', default:'top', binding:'read', enum:['top','bottom','left','right']},
|
|
@@ -185,17 +236,28 @@ export const TabContainer = defineComponent({
|
|
|
185
236
|
border-radius:var(--tab-radius) var(--tab-radius) 0 0;color:var(--gramlot-tab-color,var(--gramlot-text-secondary,#555))}
|
|
186
237
|
.tab-entry:has([aria-selected=true]){border-color:var(--tab-border);color:var(--gramlot-tab-selected-color,var(--gramlot-ink,#222));
|
|
187
238
|
background:var(--gramlot-tab-selected-background,var(--gramlot-surface,white))}
|
|
188
|
-
button{box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:var(--gramlot-tab-content-gap,.4em);
|
|
239
|
+
.tabs button{box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:var(--gramlot-tab-content-gap,.4em);
|
|
189
240
|
font:inherit;line-height:1.2;color:inherit;border:0;background:transparent;cursor:pointer;white-space:nowrap;min-width:0;
|
|
190
241
|
padding:var(--gramlot-tab-padding,4px 10px);min-height:max(var(--gramlot-touch-target,0px),var(--gramlot-tab-height,28px));border-radius:inherit}
|
|
191
|
-
button[aria-selected=true]{font-weight:600}
|
|
242
|
+
.tabs button[aria-selected=true]{font-weight:600}
|
|
192
243
|
.icon,.badge{flex:none}.icon:empty{display:none}.caption{overflow:hidden;text-overflow:ellipsis}
|
|
193
244
|
.badge{font-size:var(--gramlot-tab-badge-size,.8em);font-weight:600;line-height:1.3;border-radius:999px;
|
|
194
245
|
min-width:1.3em;padding:var(--gramlot-tab-badge-padding,0 .35em);text-align:center;
|
|
195
246
|
background:var(--gramlot-tab-badge-background,var(--gramlot-brand-blue,#3766b5));color:var(--gramlot-tab-badge-color,white)}
|
|
196
|
-
@media(hover:hover){button:not(:disabled):hover{background:var(--gramlot-tab-hover-background,var(--gramlot-selected,#e8f1fc))}}
|
|
197
|
-
button:disabled{opacity:.5;cursor:default}
|
|
198
|
-
button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
|
|
247
|
+
@media(hover:hover){.tabs button:not(:disabled):hover{background:var(--gramlot-tab-hover-background,var(--gramlot-selected,#e8f1fc))}}
|
|
248
|
+
.tabs button:disabled{opacity:.5;cursor:default}
|
|
249
|
+
.tabs button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-3px}
|
|
250
|
+
.panel:has(>.panel-tools:not([hidden])){display:flex;flex-direction:column;overflow:hidden}
|
|
251
|
+
.panel:has(>.panel-tools:not([hidden]))>slot{display:block;flex:1;min-height:0;overflow:auto}
|
|
252
|
+
.panel-tools{display:flex;flex:none;justify-content:flex-end;padding:2px 4px;
|
|
253
|
+
background:var(--gramlot-surface-subtle,var(--gramlot-surface,#fff));border-bottom:1px solid var(--tab-border)}
|
|
254
|
+
.detach{display:flex;align-items:center;justify-content:center;touch-action:none;cursor:grab;
|
|
255
|
+
font:inherit;color:inherit;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;
|
|
256
|
+
padding:var(--gramlot-group-action-padding,.2em .4em);min-width:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px));min-height:var(--gramlot-touch-target,var(--gramlot-group-action-size,24px))}
|
|
257
|
+
@media(hover:hover){.detach:hover{background:var(--gramlot-field-readonly-background,#ddd)}}
|
|
258
|
+
.detach:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
|
|
259
|
+
.detach svg{width:1.25em;height:1.25em;flex:none;pointer-events:none}
|
|
260
|
+
.detach[data-dragging]{cursor:grabbing;background:var(--gramlot-selected,#e8f1fc)}
|
|
199
261
|
.close{align-self:center;flex:none;min-height:var(--gramlot-touch-target,20px);min-width:var(--gramlot-touch-target,20px);
|
|
200
262
|
padding:0;margin-inline-end:3px;border-radius:var(--tab-radius);font-size:1.15em}
|
|
201
263
|
[hidden]{display:none!important}
|
|
@@ -205,7 +267,7 @@ export const TabContainer = defineComponent({
|
|
|
205
267
|
[data-position=bottom] .tab-entry{border-bottom:1px solid transparent;border-top:0;border-radius:0 0 var(--tab-radius) var(--tab-radius)}
|
|
206
268
|
[data-position=left]{flex-direction:row}[data-position=right]{flex-direction:row-reverse}
|
|
207
269
|
:is([data-position=left],[data-position=right]) .tabs{flex-direction:column;max-width:min(40%,var(--gramlot-tab-side-width,12rem));border-bottom:0}
|
|
208
|
-
:is([data-position=left],[data-position=right]) button[role=tab]{flex:1;justify-content:flex-start}
|
|
270
|
+
:is([data-position=left],[data-position=right]) .tabs button[role=tab]{flex:1;justify-content:flex-start}
|
|
209
271
|
[data-position=left] .tabs{border-right:1px solid var(--tab-border);padding-right:0}
|
|
210
272
|
[data-position=right] .tabs{border-left:1px solid var(--tab-border);padding-left:0}
|
|
211
273
|
[data-position=left] .tab-entry{border-bottom:1px solid transparent;border-right:0;border-radius:var(--tab-radius) 0 0 var(--tab-radius)}
|
|
@@ -267,7 +329,34 @@ export const TabContainer = defineComponent({
|
|
|
267
329
|
const [next, tab] = available[index]; this.selectPanel(next); tab.button.focus();
|
|
268
330
|
tab.button.scrollIntoView({block:'nearest',inline:'nearest'});
|
|
269
331
|
});
|
|
270
|
-
|
|
332
|
+
const detach = doc.createElement('button'); detach.type = 'button'; detach.className = 'detach';
|
|
333
|
+
const symbol = doc.createElementNS(SVG_NS, 'svg'); symbol.setAttribute('viewBox','0 0 20 20'); symbol.setAttribute('aria-hidden','true');
|
|
334
|
+
const path = doc.createElementNS(SVG_NS, 'path'); path.setAttribute('d','M11 3h6v6M17 3l-8 8M8 4H4v12h12v-4');
|
|
335
|
+
path.setAttribute('fill','none'); path.setAttribute('stroke','currentColor'); path.setAttribute('stroke-width','1.8');
|
|
336
|
+
path.setAttribute('stroke-linecap','round'); path.setAttribute('stroke-linejoin','round'); symbol.append(path); detach.append(symbol);
|
|
337
|
+
let gesture = null, dragged = false;
|
|
338
|
+
detach.addEventListener('pointerdown', event => {
|
|
339
|
+
if (event.button !== 0) return;
|
|
340
|
+
gesture = {id:event.pointerId,x:event.clientX,y:event.clientY}; dragged = false;
|
|
341
|
+
detach.setPointerCapture(event.pointerId); detach.setAttribute('data-dragging','');
|
|
342
|
+
});
|
|
343
|
+
detach.addEventListener('pointerup', event => {
|
|
344
|
+
if (!gesture || gesture.id !== event.pointerId) return;
|
|
345
|
+
const start = gesture; gesture = null; detach.removeAttribute('data-dragging');
|
|
346
|
+
if (detach.hasPointerCapture(event.pointerId)) detach.releasePointerCapture(event.pointerId);
|
|
347
|
+
dragged = Math.hypot(event.clientX-start.x,event.clientY-start.y) >= 8;
|
|
348
|
+
if (dragged) this.detachPanel(record,{left:event.clientX-12,top:event.clientY-12});
|
|
349
|
+
});
|
|
350
|
+
for (const type of ['pointercancel','lostpointercapture']) detach.addEventListener(type, () => {
|
|
351
|
+
gesture = null; detach.removeAttribute('data-dragging');
|
|
352
|
+
});
|
|
353
|
+
detach.addEventListener('click', () => {
|
|
354
|
+
if (dragged) { dragged = false; return; }
|
|
355
|
+
this.detachPanel(record);
|
|
356
|
+
});
|
|
357
|
+
const tools = doc.createElement('div'); tools.className = 'panel-tools'; tools.append(detach);
|
|
358
|
+
record.viewport.prepend(tools);
|
|
359
|
+
root.append(button, close); this.tabStrip.append(root); entry = {root,button,close,icon,caption,badge,detach,tools}; this.#tabs.set(record, entry);
|
|
271
360
|
}
|
|
272
361
|
if (this.tabStrip.children[index] !== entry.root) this.tabStrip.insertBefore(entry.root, this.tabStrip.children[index] ?? null);
|
|
273
362
|
entry.root.hidden = !!record.config.hidden;
|
|
@@ -281,6 +370,10 @@ export const TabContainer = defineComponent({
|
|
|
281
370
|
entry.button.disabled = !!record.config.disabled;
|
|
282
371
|
entry.button.setAttribute('aria-selected', String(record === selected));
|
|
283
372
|
entry.button.tabIndex = record === selected ? 0 : -1;
|
|
373
|
+
entry.tools.hidden = !record.config.detachable || record !== selected || !!record.surface;
|
|
374
|
+
entry.detach.disabled = !!record.config.disabled;
|
|
375
|
+
entry.detach.setAttribute('aria-label', `Detach ${caption}`);
|
|
376
|
+
entry.detach.title = `Drag or click to detach ${caption}`;
|
|
284
377
|
entry.close.hidden = !record.config.closable;
|
|
285
378
|
entry.close.disabled = !!record.config.disabled;
|
|
286
379
|
entry.close.setAttribute('aria-label', `Close ${caption}`);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {labelboxContent} from '../view/labelbox.js';
|
|
1
2
|
import {SVG_NS} from '../renderer/attributes.js';
|
|
2
3
|
/** Responsive menu projection. Original Source and light-DOM nodes never move. */
|
|
3
4
|
import {positionPopup} from './popup.js';
|
|
@@ -96,7 +97,7 @@ export class ToolbarOverflow {
|
|
|
96
97
|
if(available<=0)return;
|
|
97
98
|
let active=menu.ownerDocument.activeElement;
|
|
98
99
|
while(active?.shadowRoot?.activeElement)active=active.shadowRoot.activeElement;
|
|
99
|
-
const units=[...menu.children].filter(unit=>!unit.hidden && (unit.localName!=='gramlot-menu' || unit.permanent));
|
|
100
|
+
const units=[...menu.children].filter(unit=>!unit.hidden && (labelboxContent(unit).localName!=='gramlot-menu' || labelboxContent(unit).permanent));
|
|
100
101
|
for(const unit of this.#units)if(!units.includes(unit)){
|
|
101
102
|
this.#resize.unobserve(unit);unit.removeAttribute('slot');unit.removeAttribute('data-menu-overflow');
|
|
102
103
|
}
|
|
@@ -111,19 +112,19 @@ export class ToolbarOverflow {
|
|
|
111
112
|
const gap=parseFloat(win.getComputedStyle(this.#viewport).gap)||0;
|
|
112
113
|
const lengths=new Map(units.map(unit=>{
|
|
113
114
|
const css=win.getComputedStyle(unit);
|
|
114
|
-
const length=unit.localName==='gramlot-spacer'?(unit.parameters.size??0):unit.getBoundingClientRect()[axis];
|
|
115
|
+
const length=labelboxContent(unit).localName==='gramlot-spacer'?(labelboxContent(unit).parameters.size??0):unit.getBoundingClientRect()[axis];
|
|
115
116
|
return [unit,length+(parseFloat(css[vertical?'marginTop':'marginLeft'])||0)+(parseFloat(css[vertical?'marginBottom':'marginRight'])||0)];
|
|
116
117
|
}));
|
|
117
|
-
const separator=unit=>unit.getAttribute('role')==='separator';
|
|
118
|
+
const separator=unit=>labelboxContent(unit).getAttribute('role')==='separator';
|
|
118
119
|
const tidy=list=>list.filter((unit,index)=>!separator(unit) ||
|
|
119
|
-
list.slice(0,index).some(item=>item.localName!=='gramlot-spacer'&&!separator(item)) &&
|
|
120
|
-
list.slice(index+1).find(item=>item.localName!=='gramlot-spacer') &&
|
|
121
|
-
!separator(list.slice(index+1).find(item=>item.localName!=='gramlot-spacer')));
|
|
120
|
+
list.slice(0,index).some(item=>labelboxContent(item).localName!=='gramlot-spacer'&&!separator(item)) &&
|
|
121
|
+
list.slice(index+1).find(item=>labelboxContent(item).localName!=='gramlot-spacer') &&
|
|
122
|
+
!separator(list.slice(index+1).find(item=>labelboxContent(item).localName!=='gramlot-spacer')));
|
|
122
123
|
const required=remaining=>remaining.reduce((sum,unit)=>sum+lengths.get(unit),0)+Math.max(0,remaining.length-1)*gap;
|
|
123
124
|
let remaining=tidy(units);
|
|
124
125
|
if(required(remaining)>available){
|
|
125
|
-
const candidates=units.map((unit,index)=>({unit,index})).filter(({unit})=>unit.localName==='gramlot-menu-line' && !separator(unit) && unit.parameters.overflowable)
|
|
126
|
-
.sort((a,b)=>a.unit.parameters.priority-b.unit.parameters.priority || b.index-a.index);
|
|
126
|
+
const candidates=units.map((unit,index)=>({unit,index})).filter(({unit})=>labelboxContent(unit).localName==='gramlot-menu-line' && !separator(unit) && labelboxContent(unit).parameters.overflowable)
|
|
127
|
+
.sort((a,b)=>labelboxContent(a.unit).parameters.priority-labelboxContent(b.unit).parameters.priority || b.index-a.index);
|
|
127
128
|
for(const {unit} of candidates){
|
|
128
129
|
if(required(remaining)<=available-32)break;
|
|
129
130
|
this.#overflow.add(unit);remaining=tidy(remaining.filter(item=>item!==unit));
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** Pointer gestures for bound translation, rotation and zoom; child presentation remains in Source/Data. */
|
|
2
|
+
import {defineComponent} from './registry.js';
|
|
3
|
+
import {Container} from './container.js';
|
|
4
|
+
|
|
5
|
+
export const TransformPane = defineComponent({
|
|
6
|
+
name: 'transformPane', tag: 'gramlot-transform-pane', base: Container, subTags: '*', sourceContext: true,
|
|
7
|
+
parameters: {
|
|
8
|
+
x: {dtype: 'R', default: 0, binding: 'read'},
|
|
9
|
+
y: {dtype: 'R', default: 0, binding: 'read'},
|
|
10
|
+
rotate: {dtype: 'R', default: 0, binding: 'read'},
|
|
11
|
+
zoom: {dtype: 'R', default: 1, binding: 'read'},
|
|
12
|
+
min: {dtype: 'R', default: 0.5, binding: 'read'},
|
|
13
|
+
max: {dtype: 'R', default: 3, binding: 'read'},
|
|
14
|
+
step: {dtype: 'R', default: 0.01, binding: 'read'},
|
|
15
|
+
onEnd: {dtype: 'T', nullable: true}
|
|
16
|
+
},
|
|
17
|
+
implementation: Base => class extends Base {
|
|
18
|
+
#context;
|
|
19
|
+
#events;
|
|
20
|
+
#points = new Map();
|
|
21
|
+
#gesture = null;
|
|
22
|
+
#writing = false;
|
|
23
|
+
#range;
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
const style = this.ownerDocument.createElement('style');
|
|
27
|
+
style.textContent = ':host{touch-action:none;user-select:none;-webkit-user-select:none}.control-box{height:100%}';
|
|
28
|
+
this.shadowRoot.append(style);
|
|
29
|
+
this.#range = this.ownerDocument.createElement('input');
|
|
30
|
+
this.#range.type = 'range';
|
|
31
|
+
}
|
|
32
|
+
setSourceContext(context) { this.#context = context; }
|
|
33
|
+
projectAttributes(attrs, adapt) {
|
|
34
|
+
const previous = this.parameters;
|
|
35
|
+
const rest = super.projectAttributes(attrs, adapt);
|
|
36
|
+
const {x, y, rotate, zoom, min, max, step} = this.parameters;
|
|
37
|
+
if (![x, y, rotate, zoom, min, max, step].every(Number.isFinite) || min <= 0 || max < min || step <= 0) {
|
|
38
|
+
throw new TypeError('transformPane requires finite x/y/rotate/zoom, positive min/step and max >= min');
|
|
39
|
+
}
|
|
40
|
+
if (!this.#writing && previous && ['x','y','rotate','zoom','min','max','step'].some(key => previous[key] !== this.parameters[key])) this.#cancel();
|
|
41
|
+
this.#range.min = String(min); this.#range.max = String(max); this.#range.step = String(step);
|
|
42
|
+
this.#range.value = String(zoom);
|
|
43
|
+
const corrected = this.#range.valueAsNumber;
|
|
44
|
+
if (!this.#writing && corrected !== zoom) this.#write({zoom: corrected});
|
|
45
|
+
return rest;
|
|
46
|
+
}
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
this.#events = new this.ownerDocument.defaultView.AbortController();
|
|
49
|
+
const options = {signal: this.#events.signal};
|
|
50
|
+
this.addEventListener('pointerdown', event => this.#down(event), options);
|
|
51
|
+
this.addEventListener('pointermove', event => this.#move(event), options);
|
|
52
|
+
this.addEventListener('pointerup', event => this.#up(event), options);
|
|
53
|
+
for (const type of ['pointercancel', 'lostpointercapture']) {
|
|
54
|
+
this.addEventListener(type, event => { if (this.#points.has(event.pointerId)) this.#cancel(); }, options);
|
|
55
|
+
}
|
|
56
|
+
this.addEventListener('dragstart', event => event.preventDefault(), options);
|
|
57
|
+
this.ownerDocument.addEventListener('visibilitychange', () => { if (this.ownerDocument.hidden) this.#cancel(); }, options);
|
|
58
|
+
this.ownerDocument.defaultView.addEventListener('blur', () => this.#cancel(), options);
|
|
59
|
+
}
|
|
60
|
+
disconnectedCallback() {
|
|
61
|
+
this.#events?.abort(); this.#events = null; this.#cancel();
|
|
62
|
+
}
|
|
63
|
+
#write(values) {
|
|
64
|
+
this.#writing = true;
|
|
65
|
+
try {
|
|
66
|
+
for (const [name, value] of Object.entries(values)) {
|
|
67
|
+
if (value !== this.parameters[name]) this.#context.writeParameter(name, value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
finally { this.#writing = false; }
|
|
71
|
+
}
|
|
72
|
+
#values() {
|
|
73
|
+
const {x, y, rotate, zoom} = this.parameters;
|
|
74
|
+
return {x, y, rotate, zoom};
|
|
75
|
+
}
|
|
76
|
+
#geometry() {
|
|
77
|
+
const [a, b] = this.#points.values();
|
|
78
|
+
if (!b) return {x: a.x, y: a.y, distance: 0, angle: 0};
|
|
79
|
+
return {x: (a.x + b.x) / 2, y: (a.y + b.y) / 2,
|
|
80
|
+
distance: Math.hypot(b.x - a.x, b.y - a.y), angle: Math.atan2(b.y - a.y, b.x - a.x)};
|
|
81
|
+
}
|
|
82
|
+
#rebase() {
|
|
83
|
+
const geometry = this.#geometry();
|
|
84
|
+
if (this.#points.size === 2 && geometry.distance === 0) { this.#cancel(); return; }
|
|
85
|
+
const values = this.#values();
|
|
86
|
+
this.#gesture = {initial: this.#gesture?.initial ?? values, base: values, geometry,
|
|
87
|
+
lastAngle: geometry.angle, rotation: 0};
|
|
88
|
+
}
|
|
89
|
+
#down(event) {
|
|
90
|
+
if (event.button !== 0 || !this.isConnected) return;
|
|
91
|
+
// Two-pointer transformations are touch gestures; mouse/pen still translate.
|
|
92
|
+
if (this.#points.size && (event.pointerType !== 'touch' || [...this.#points.values()].some(p => p.type !== 'touch'))) return;
|
|
93
|
+
if (this.#points.size === 2) { this.#cancel(); return; }
|
|
94
|
+
this.#points.set(event.pointerId, {x: event.clientX, y: event.clientY, type: event.pointerType});
|
|
95
|
+
this.setPointerCapture(event.pointerId);
|
|
96
|
+
this.#rebase();
|
|
97
|
+
}
|
|
98
|
+
#move(event) {
|
|
99
|
+
const point = this.#points.get(event.pointerId);
|
|
100
|
+
if (!point || !this.#gesture) return;
|
|
101
|
+
point.x = event.clientX; point.y = event.clientY;
|
|
102
|
+
const current = this.#geometry();
|
|
103
|
+
const gesture = this.#gesture;
|
|
104
|
+
const values = {x: gesture.base.x + current.x - gesture.geometry.x,
|
|
105
|
+
y: gesture.base.y + current.y - gesture.geometry.y};
|
|
106
|
+
if (this.#points.size === 2) {
|
|
107
|
+
if (current.distance > 0) {
|
|
108
|
+
const delta = current.angle - gesture.lastAngle;
|
|
109
|
+
gesture.rotation += Math.atan2(Math.sin(delta), Math.cos(delta)) * 180 / Math.PI;
|
|
110
|
+
gesture.lastAngle = current.angle;
|
|
111
|
+
}
|
|
112
|
+
values.rotate = gesture.base.rotate + gesture.rotation;
|
|
113
|
+
this.#range.value = String(gesture.base.zoom * current.distance / gesture.geometry.distance);
|
|
114
|
+
values.zoom = this.#range.valueAsNumber;
|
|
115
|
+
}
|
|
116
|
+
this.#write(values);
|
|
117
|
+
}
|
|
118
|
+
#up(event) {
|
|
119
|
+
if (!this.#points.has(event.pointerId)) return;
|
|
120
|
+
this.#move(event);
|
|
121
|
+
this.#points.delete(event.pointerId);
|
|
122
|
+
if (this.hasPointerCapture(event.pointerId)) this.releasePointerCapture(event.pointerId);
|
|
123
|
+
if (this.#points.size) { this.#rebase(); return; }
|
|
124
|
+
const gesture = this.#gesture;
|
|
125
|
+
const values = this.#values();
|
|
126
|
+
this.#cancel();
|
|
127
|
+
if (gesture && Object.keys(values).some(key => values[key] !== gesture.initial[key]) && this.parameters.onEnd) {
|
|
128
|
+
const context = this.#context;
|
|
129
|
+
const report = error => context.reportError(error, 'Transform completion failed');
|
|
130
|
+
try { Promise.resolve(context.callLogic(this.parameters.onEnd, values)).catch(report); }
|
|
131
|
+
catch (error) { report(error); }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
#cancel() {
|
|
135
|
+
const ids = [...this.#points.keys()];
|
|
136
|
+
this.#points.clear(); this.#gesture = null;
|
|
137
|
+
for (const id of ids) if (this.hasPointerCapture(id)) this.releasePointerCapture(id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** Transformed outer rectangles. Contact is allowed; shadows/radii are irrelevant. */
|
|
2
|
+
const EPSILON=1e-7;
|
|
3
|
+
const radians=degrees=>degrees*Math.PI/180;
|
|
4
|
+
const dot=(p,n)=>p.x*n.x+p.y*n.y;
|
|
5
|
+
const axes=r=>{const a=radians(r.rotation??0);return [{x:Math.cos(a),y:Math.sin(a)},{x:-Math.sin(a),y:Math.cos(a)}];};
|
|
6
|
+
export function corners(r) {
|
|
7
|
+
const [u,v]=axes(r),s=r.scale??1,cx=r.left+r.width/2,cy=r.top+r.height/2;
|
|
8
|
+
return [[-1,-1],[1,-1],[1,1],[-1,1]].map(([x,y])=>({
|
|
9
|
+
x:cx+s*(u.x*x*r.width+v.x*y*r.height)/2,
|
|
10
|
+
y:cy+s*(u.y*x*r.width+v.y*y*r.height)/2}));
|
|
11
|
+
}
|
|
12
|
+
function projection(points,n){const values=points.map(p=>dot(p,n));return [Math.min(...values),Math.max(...values)];}
|
|
13
|
+
export function overlaps(a,b) {
|
|
14
|
+
const pa=corners(a),pb=corners(b);
|
|
15
|
+
return [...axes(a),...axes(b)].every(n=>{
|
|
16
|
+
const [amin,amax]=projection(pa,n),[bmin,bmax]=projection(pb,n);
|
|
17
|
+
return amax>bmin+EPSILON && bmax>amin+EPSILON;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function pose(from,to,t){return Object.fromEntries(Object.keys(from).map(key=>[key,from[key]+(to[key]-from[key])*t]));}
|
|
21
|
+
|
|
22
|
+
// With fixed orientation and linear corner paths SAT gives exact entry/exit times.
|
|
23
|
+
function linearContact(from,to,obstacles,bounds) {
|
|
24
|
+
const start=corners(from),end=corners(to);let fraction=1;
|
|
25
|
+
for(const obstacle of obstacles) {
|
|
26
|
+
let enter=0,leave=1;const other=corners(obstacle);
|
|
27
|
+
for(const axis of [...axes(from),...axes(obstacle)]) {
|
|
28
|
+
const [a,b]=projection(start,axis),[c,d]=projection(end,axis),[low,high]=projection(other,axis);
|
|
29
|
+
for(const [first,last] of [[b-low,d-low],[high-a,high-c]]) {
|
|
30
|
+
const delta=last-first;
|
|
31
|
+
if(Math.abs(delta)<1e-12){if(first<=EPSILON)leave=0;}
|
|
32
|
+
else if(delta>0)enter=Math.max(enter,-first/delta);
|
|
33
|
+
else leave=Math.min(leave,-first/delta);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if(enter<leave&&leave>0&&enter<1)fraction=Math.min(fraction,Math.max(0,enter));
|
|
37
|
+
}
|
|
38
|
+
if(bounds)for(let i=0;i<4;i++)for(const [key,max] of [['x',bounds.width],['y',bounds.height]]) {
|
|
39
|
+
const a=start[i][key],b=end[i][key];
|
|
40
|
+
if(b<0&&b<a)fraction=Math.min(fraction,Math.max(0,a/(a-b)));
|
|
41
|
+
if(b>max&&b>a)fraction=Math.min(fraction,Math.max(0,(max-a)/(b-a)));
|
|
42
|
+
}
|
|
43
|
+
return fraction;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** First contact along the whole path, including rotation through a free end pose. */
|
|
47
|
+
export function contactFraction(start,end,obstacles,bounds) {
|
|
48
|
+
const from={...start,rotation:start.rotation??0,scale:start.scale??1};
|
|
49
|
+
const to={...end,rotation:end.rotation??0,scale:end.scale??1};
|
|
50
|
+
// Pure rotations repeat after a full turn. Certifying the first turn also
|
|
51
|
+
// certifies every later turn, avoiding work proportional to an entered angle.
|
|
52
|
+
const turn=to.rotation-from.rotation;
|
|
53
|
+
if(Math.abs(turn)>360 && ['left','top','width','height','scale'].every(key=>from[key]===to[key])) {
|
|
54
|
+
const first=contactFraction(from,{...to,rotation:from.rotation+Math.sign(turn)*360},obstacles,bounds);
|
|
55
|
+
return first===1?1:first*360/Math.abs(turn);
|
|
56
|
+
}
|
|
57
|
+
const omega=Math.abs(radians(to.rotation-from.rotation)),ds=Math.abs(to.scale-from.scale);
|
|
58
|
+
const dr=Math.hypot(to.width-from.width,to.height-from.height)/2;
|
|
59
|
+
const radius=Math.max(Math.hypot(from.width,from.height),Math.hypot(to.width,to.height))/2;
|
|
60
|
+
const scale=Math.max(from.scale,to.scale);
|
|
61
|
+
// Upper bound on every corner's acceleration. A curve differs from its
|
|
62
|
+
// endpoint chord by at most acceleration * duration² / 8. This certifies
|
|
63
|
+
// free intervals; endpoint sampling alone could skip an entire collision.
|
|
64
|
+
const acceleration=2*ds*dr+2*omega*(ds*radius+scale*dr)+omega*omega*scale*radius;
|
|
65
|
+
if(acceleration===0)return linearContact(from,to,obstacles,bounds);
|
|
66
|
+
const fixed=obstacles.map(r=>({points:corners(r),axes:axes(r)}));
|
|
67
|
+
function freeInterval(a,b) {
|
|
68
|
+
const p=corners(pose(from,to,a)),q=corners(pose(from,to,b)),points=[...p,...q];
|
|
69
|
+
const margin=acceleration*(b-a)**2/8;
|
|
70
|
+
if(bounds && points.some(point=>point.x-margin < -EPSILON || point.y-margin < -EPSILON
|
|
71
|
+
|| point.x+margin>bounds.width+EPSILON || point.y+margin>bounds.height+EPSILON))return false;
|
|
72
|
+
const movingAxes=axes(pose(from,to,(a+b)/2));
|
|
73
|
+
return fixed.every(other=>[...movingAxes,...other.axes].some(axis=>{
|
|
74
|
+
const [lo,hi]=projection(points,axis),[olo,ohi]=projection(other.points,axis);
|
|
75
|
+
return hi+margin<=olo+EPSILON || lo-margin>=ohi-EPSILON;
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
const speed=Math.hypot(to.left-from.left+(to.width-from.width)/2,to.top-from.top+(to.height-from.height)/2)
|
|
79
|
+
+ds*radius+scale*dr+omega*scale*radius;
|
|
80
|
+
function search(a,b) {
|
|
81
|
+
if(freeInterval(a,b))return b;
|
|
82
|
+
if(speed*(b-a)<=EPSILON || b-a<Number.EPSILON*4)return a;
|
|
83
|
+
const mid=(a+b)/2,first=search(a,mid);
|
|
84
|
+
return first<mid?first:search(mid,b);
|
|
85
|
+
}
|
|
86
|
+
return search(0,1);
|
|
87
|
+
}
|