@chocbite/ts-lib-ui 1.1.5 → 1.2.1
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/AGENTS.md +547 -9
- package/README.md +3 -0
- package/SOURCE.md +10313 -7355
- package/base/index.d.mts +2 -2
- package/base/index.mjs +68 -5
- package/base/index.mjs.map +1 -1
- package/canvas/index.d.mts +1 -1
- package/canvas/index.mjs +1 -1
- package/composition/index.d.mts +283 -0
- package/composition/index.mjs +2 -0
- package/composition-7xlf0UjB.mjs +869 -0
- package/composition-7xlf0UjB.mjs.map +1 -0
- package/context-menu/index.d.mts +1 -1
- package/context-menu/index.mjs +1 -1
- package/{context-menu-CZxEGjBi.mjs → context-menu-DSVerkvr.mjs} +2 -2
- package/{context-menu-CZxEGjBi.mjs.map → context-menu-DSVerkvr.mjs.map} +1 -1
- package/depot_ui/index.d.mts +60 -0
- package/depot_ui/index.mjs +280 -0
- package/depot_ui/index.mjs.map +1 -0
- package/form/index.d.mts +2 -758
- package/form/index.mjs +1 -2953
- package/form-CnIHz2Bp.mjs +2961 -0
- package/form-CnIHz2Bp.mjs.map +1 -0
- package/icons/index.d.mts +1 -1
- package/{index-YNZjMIO7.d.mts → index-CApVOEcI.d.mts} +2 -2
- package/{index-BDWg5GX2.d.mts → index-Czy8O3me.d.mts} +6 -2
- package/index-DD09-bGe.d.mts +761 -0
- package/{index-DlBJdGaQ.d.mts → index-U3pqQjLg.d.mts} +4 -4
- package/{index-CvzH3M_5.d.mts → index-_y7vmunA.d.mts} +72 -8
- package/keyboard/index.d.mts +1 -1
- package/keyboard/index.mjs +1 -1
- package/list/index.d.mts +1 -1
- package/list/index.mjs +1 -1
- package/{list-C52-ExFw.mjs → list-ByNP3ZG2.mjs} +3 -3
- package/{list-C52-ExFw.mjs.map → list-ByNP3ZG2.mjs.map} +1 -1
- package/package.json +2 -2
- package/prompts/index.d.mts +48 -0
- package/prompts/index.mjs +107 -0
- package/prompts/index.mjs.map +1 -0
- package/spinner/index.d.mts +1 -1
- package/spinner/index.mjs +1 -1
- package/style.css +2049 -1640
- package/svg/index.d.mts +1 -1
- package/svg-Yz7elqnU.mjs.map +1 -1
- package/theme/index.d.mts +1 -1
- package/theme/index.mjs +1 -1
- package/{theme-D3YluyYr.mjs → theme-ycsugrdT.mjs} +2 -2
- package/{theme-D3YluyYr.mjs.map → theme-ycsugrdT.mjs.map} +1 -1
- package/form/index.mjs.map +0 -1
- package/test/index.d.mts +0 -98
- package/test/index.mjs +0 -193
- package/test/index.mjs.map +0 -1
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
import "./style.css";
|
|
2
|
+
import { a as px_to_rem, c as ANIMATION_SPEED, f as SCALE, h as THEME, i as theme_init_variable_root, s as ANIMATION_LEVEL, u as INPUT_MODE } from "./theme-ycsugrdT.mjs";
|
|
3
|
+
import { Base, CREATE, define_element, input_key } from "./base/index.mjs";
|
|
4
|
+
import { DOCUMENT_HANDLER } from "./document/index.mjs";
|
|
5
|
+
import { t as form } from "./form-CnIHz2Bp.mjs";
|
|
6
|
+
import { hd as material_brightness_medium_rounded } from "./icons-B88i-7MC.mjs";
|
|
7
|
+
import { t as ctm } from "./context-menu-DSVerkvr.mjs";
|
|
8
|
+
import state from "@chocbite/ts-lib/state";
|
|
9
|
+
import { GREY, ORANGE, RED } from "@chocbite/ts-lib/colors";
|
|
10
|
+
// composition/shared.ts
|
|
11
|
+
/**A point of a box, like the corner of a panel that its position places*/
|
|
12
|
+
const CompAnchor = {
|
|
13
|
+
TOP_RIGHT: "top_right",
|
|
14
|
+
TOP_LEFT: "top_left",
|
|
15
|
+
BOT_RIGHT: "bot_right",
|
|
16
|
+
BOT_LEFT: "bot_left",
|
|
17
|
+
CENTER: "center"
|
|
18
|
+
};
|
|
19
|
+
/**Where the anchor is in a box, as parts of its width and height from the top left*/
|
|
20
|
+
function anchor_fraction(anchor) {
|
|
21
|
+
if (anchor === CompAnchor.CENTER) return [.5, .5];
|
|
22
|
+
const [f, l] = anchor.split("_");
|
|
23
|
+
return [l === "left" ? 0 : 1, f === "top" ? 0 : 1];
|
|
24
|
+
}
|
|
25
|
+
/**Position in rem of the anchor point of the element, from the top left of the page*/
|
|
26
|
+
function get_element_anchor_position(element, anchor) {
|
|
27
|
+
const rect = element.getBoundingClientRect();
|
|
28
|
+
const [ax, ay] = anchor_fraction(anchor);
|
|
29
|
+
return {
|
|
30
|
+
x: px_to_rem(rect.left + rect.width * ax),
|
|
31
|
+
y: px_to_rem(rect.top + rect.height * ay)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const colors = theme_init_variable_root("composition", "Composition", "Theme variables for page composition, panels and top bar").make_sub_group("colors", "Colors", "Colors used in all form elements");
|
|
35
|
+
colors.make_variable("titlebar", "Title Bar Background", "Background color for the title bar of UI panels", GREY[500], GREY[800], "Color", void 0);
|
|
36
|
+
colors.make_variable("titlebarHover", "Title Bar Hover Background", "Background color for the title bar of UI panels when hovered", GREY[400], GREY[700], "Color", void 0);
|
|
37
|
+
colors.make_variable("titlebarCloseHover", "Title Bar Close Hover Background", "Background color for the title bar close button of UI panels when hovered", RED[400], RED[700], "Color", void 0);
|
|
38
|
+
colors.make_variable("titlebarText", "Title Bar Text", "Text color for the title bar of UI panels", GREY[900], GREY[50], "Color", void 0);
|
|
39
|
+
colors.make_variable("background", "Content Background", "Default background color for content areas", GREY[100], "#000000", "Color", void 0);
|
|
40
|
+
colors.make_variable("icons", "Icons Color", "Default color for icons", GREY[900], GREY[100], "Color", void 0);
|
|
41
|
+
colors.make_variable("sizers", "Sizers", "Background color of the sizers of panels, shown in touch mode", GREY[300], GREY[900], "Color", void 0);
|
|
42
|
+
colors.make_variable("shadow", "Border Shadow", "Shadow color for borders and outlines", "#000000", GREY[50], "Color", void 0);
|
|
43
|
+
colors.make_variable("shadowFocus", "Border Shadow In Focus", "Shadow color for borders and outlines when in focus", ORANGE[500], ORANGE[500], "Color", void 0);
|
|
44
|
+
// composition/content.ts
|
|
45
|
+
/**Inputs of content that can be set again*/
|
|
46
|
+
const CONTENT = {
|
|
47
|
+
/**Context menu of the content, also shown by its container, like on the title bar of a panel
|
|
48
|
+
* Lines, a menu, or a function giving them, which is called every time the menu opens*/
|
|
49
|
+
context_menu: input_key() };
|
|
50
|
+
input_key(), input_key(), input_key(), input_key(), input_key();
|
|
51
|
+
/**Called by the container when it closes the content, internal to this module*/
|
|
52
|
+
const CONTENT_CLOSED = Symbol("content_closed");
|
|
53
|
+
/**The context menu of content as it is right now, for ctm.combine, internal to this module*/
|
|
54
|
+
function content_context_lines(content) {
|
|
55
|
+
const group = content.content_context_menu;
|
|
56
|
+
return typeof group === "function" ? group() : group ?? [];
|
|
57
|
+
}
|
|
58
|
+
/**Base for anything shown in a container of this module, like a panel
|
|
59
|
+
*
|
|
60
|
+
* Library users extend it for their own content, and create it with MyContent.create(options),
|
|
61
|
+
* the title, icon, closable and minimum size are given at creation, as the container follows them
|
|
62
|
+
* To follow its own size, content attaches to the resize observer of Base and overrides on_resize*/
|
|
63
|
+
var ContentBase = class extends Base {
|
|
64
|
+
static element_name() {
|
|
65
|
+
return "@abstract@";
|
|
66
|
+
}
|
|
67
|
+
static element_name_space() {
|
|
68
|
+
return "@abstract@";
|
|
69
|
+
}
|
|
70
|
+
#title = "";
|
|
71
|
+
#icon = void 0;
|
|
72
|
+
#closable = false;
|
|
73
|
+
#min_width = 0;
|
|
74
|
+
#min_height = 0;
|
|
75
|
+
#context_menu = void 0;
|
|
76
|
+
#on_close = [];
|
|
77
|
+
constructor() {
|
|
78
|
+
super();
|
|
79
|
+
this.tabIndex = -1;
|
|
80
|
+
this.classList.add("content");
|
|
81
|
+
ctm.attach(this, ctm.combine(() => content_context_lines(this)));
|
|
82
|
+
}
|
|
83
|
+
/**Title the container shows, given at creation and never replaced*/
|
|
84
|
+
get content_title() {
|
|
85
|
+
return this.#title;
|
|
86
|
+
}
|
|
87
|
+
/**Icon the container shows, given at creation and never replaced*/
|
|
88
|
+
get content_icon() {
|
|
89
|
+
return this.#icon;
|
|
90
|
+
}
|
|
91
|
+
/**Whether the container lets the user close the content, given at creation and never replaced*/
|
|
92
|
+
get content_closable() {
|
|
93
|
+
return this.#closable;
|
|
94
|
+
}
|
|
95
|
+
/**Smallest width in rem, given at creation and never replaced*/
|
|
96
|
+
get content_min_width() {
|
|
97
|
+
return this.#min_width;
|
|
98
|
+
}
|
|
99
|
+
/**Smallest height in rem, given at creation and never replaced*/
|
|
100
|
+
get content_min_height() {
|
|
101
|
+
return this.#min_height;
|
|
102
|
+
}
|
|
103
|
+
/**Context menu of the content, read by the container every time its menu opens*/
|
|
104
|
+
get content_context_menu() {
|
|
105
|
+
return this.#context_menu;
|
|
106
|
+
}
|
|
107
|
+
[CREATE](options) {
|
|
108
|
+
super[CREATE](options);
|
|
109
|
+
if (options.title !== void 0) this.#title = options.title;
|
|
110
|
+
if (options.icon !== void 0) this.#icon = options.icon;
|
|
111
|
+
if (options.closable !== void 0) this.#closable = options.closable;
|
|
112
|
+
if (options.min_width !== void 0) this.#min_width = options.min_width;
|
|
113
|
+
if (options.min_height !== void 0) this.#min_height = options.min_height;
|
|
114
|
+
}
|
|
115
|
+
set(options) {
|
|
116
|
+
this.set_input(CONTENT.context_menu, options.context_menu, (menu) => {
|
|
117
|
+
this.#context_menu = menu.value;
|
|
118
|
+
});
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
/**Resolves when the content is closed, by itself or by its container*/
|
|
122
|
+
content_on_close() {
|
|
123
|
+
return new Promise((resolve) => this.#on_close.push(resolve));
|
|
124
|
+
}
|
|
125
|
+
/**Closes the content, its container closes with it*/
|
|
126
|
+
content_close() {
|
|
127
|
+
this[CONTENT_CLOSED]();
|
|
128
|
+
this.dispatchEvent(new CustomEvent("content_closed", { bubbles: true }));
|
|
129
|
+
}
|
|
130
|
+
/**Resolves the waiting content_on_close promises, called by the container that closes the content*/
|
|
131
|
+
[CONTENT_CLOSED]() {
|
|
132
|
+
for (const resolve of this.#on_close.splice(0)) resolve();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**Content without behavior of its own, filled with children by the user*/
|
|
136
|
+
var Content = class extends ContentBase {
|
|
137
|
+
static element_name() {
|
|
138
|
+
return "content";
|
|
139
|
+
}
|
|
140
|
+
static element_name_space() {
|
|
141
|
+
return "composition";
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
define_element(Content);
|
|
145
|
+
/**Content to fill with children, the title, icon, closable and minimum size are given here, the container follows them*/
|
|
146
|
+
function content(options = {}) {
|
|
147
|
+
return Content.create(options);
|
|
148
|
+
}
|
|
149
|
+
// composition/panel.ts
|
|
150
|
+
/**Inputs of the panel*/
|
|
151
|
+
const PANEL = {
|
|
152
|
+
/**Layer of the panel, panels in a higher layer are always above panels in a lower one*/
|
|
153
|
+
layer: input_key(),
|
|
154
|
+
/**Horizontal position in rem from the left of the page, of the anchor point of the panel
|
|
155
|
+
* Not given the panel starts centered, a fixed value can not be moved by the user, a writable state is written when the user moves the panel*/
|
|
156
|
+
x: input_key(),
|
|
157
|
+
/**Vertical position in rem from the top of the page, of the anchor point of the panel, works like x*/
|
|
158
|
+
y: input_key(),
|
|
159
|
+
/**Point of the panel that x and y place, top_left by default*/
|
|
160
|
+
anchor: input_key(),
|
|
161
|
+
/**Width in rem, not given the panel fits its content
|
|
162
|
+
* A fixed value can not be sized by the user, a writable state is written when the user sizes the panel*/
|
|
163
|
+
width: input_key(),
|
|
164
|
+
/**Height in rem, works like width*/
|
|
165
|
+
height: input_key(),
|
|
166
|
+
/**Whether the user can size the panel, at the sides where width and height can be written, true by default*/
|
|
167
|
+
sizeable: input_key(),
|
|
168
|
+
/**Whether the panel is hidden, auto_hide writes it, so give a writable state to show the panel again*/
|
|
169
|
+
hidden: input_key(),
|
|
170
|
+
/**Hides the panel when the user presses outside it*/
|
|
171
|
+
auto_hide: input_key(),
|
|
172
|
+
/**Closes the panel when the user presses outside it*/
|
|
173
|
+
auto_close: input_key(),
|
|
174
|
+
/**Darkens the page behind the panel and keeps the focus in it*/
|
|
175
|
+
modal: input_key(),
|
|
176
|
+
/**Whether the title bar is shown, true by default*/
|
|
177
|
+
titlebar: input_key()
|
|
178
|
+
};
|
|
179
|
+
/**Inputs of the content the panel follows, inner inputs that are not options*/
|
|
180
|
+
const PANEL_CONTENT = {
|
|
181
|
+
title: input_key(),
|
|
182
|
+
icon: input_key(),
|
|
183
|
+
closable: input_key(),
|
|
184
|
+
min_width: input_key(),
|
|
185
|
+
min_height: input_key()
|
|
186
|
+
};
|
|
187
|
+
/**Smallest size of a panel in rem*/
|
|
188
|
+
const MIN_SIZE = 4;
|
|
189
|
+
/**How much of the panel is kept inside the container, at the top in rem, at the sides as part of its width*/
|
|
190
|
+
const KEEP_TOP = 2;
|
|
191
|
+
const KEEP_SIDE = .5;
|
|
192
|
+
const PANEL_ADDED = Symbol("panel_added");
|
|
193
|
+
const PANEL_LAYOUT = Symbol("panel_layout");
|
|
194
|
+
const HOST_LAYER = Symbol("host_layer");
|
|
195
|
+
const HOST_RAISE = Symbol("host_raise");
|
|
196
|
+
const HOST_REMOVE = Symbol("host_remove");
|
|
197
|
+
const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
|
|
198
|
+
var Panel = class extends Base {
|
|
199
|
+
static element_name() {
|
|
200
|
+
return "panel";
|
|
201
|
+
}
|
|
202
|
+
static element_name_space() {
|
|
203
|
+
return "composition";
|
|
204
|
+
}
|
|
205
|
+
#host;
|
|
206
|
+
#content;
|
|
207
|
+
#sizer = this.appendChild(document.createElement("div"));
|
|
208
|
+
#titlebar = this.appendChild(document.createElement("div"));
|
|
209
|
+
#icon;
|
|
210
|
+
#title = this.#titlebar.appendChild(document.createElement("div"));
|
|
211
|
+
#close_button;
|
|
212
|
+
#content_box = this.appendChild(document.createElement("div"));
|
|
213
|
+
#focus_catcher;
|
|
214
|
+
#layer = 0;
|
|
215
|
+
#anchor = CompAnchor.TOP_LEFT;
|
|
216
|
+
#sizeable = true;
|
|
217
|
+
#auto_hide = false;
|
|
218
|
+
#auto_close = false;
|
|
219
|
+
#min_width = 0;
|
|
220
|
+
#min_height = 0;
|
|
221
|
+
/**Values of the changeable inputs, the panel owns them until they are given*/
|
|
222
|
+
#values = { hidden: false };
|
|
223
|
+
#given = /* @__PURE__ */ new Set();
|
|
224
|
+
/**Position shown last, in rem, the start of moving and sizing*/
|
|
225
|
+
#left = 0;
|
|
226
|
+
#top = 0;
|
|
227
|
+
#moving = false;
|
|
228
|
+
#on_close = [];
|
|
229
|
+
constructor() {
|
|
230
|
+
super();
|
|
231
|
+
this.tabIndex = 0;
|
|
232
|
+
this.attach_to_resize_observer();
|
|
233
|
+
this.addEventListener("focus", () => this.#content.focus());
|
|
234
|
+
this.addEventListener("focusin", () => this.#host?.[HOST_RAISE](this));
|
|
235
|
+
this.addEventListener("content_closed", (e) => {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
this.close();
|
|
238
|
+
});
|
|
239
|
+
this.#titlebar.tabIndex = 0;
|
|
240
|
+
this.#title.classList.add("title");
|
|
241
|
+
ctm.attach(this.#titlebar, ctm.combine(() => content_context_lines(this.#content)), () => this.#moving);
|
|
242
|
+
this.#titlebar.onpointerdown = (e) => this.#move_start(e);
|
|
243
|
+
this.#titlebar.onkeydown = (e) => this.#move_key(e);
|
|
244
|
+
for (const side of [
|
|
245
|
+
"n",
|
|
246
|
+
"s",
|
|
247
|
+
"e",
|
|
248
|
+
"w",
|
|
249
|
+
"ne",
|
|
250
|
+
"nw",
|
|
251
|
+
"se",
|
|
252
|
+
"sw"
|
|
253
|
+
]) {
|
|
254
|
+
const handle = this.#sizer.appendChild(document.createElement("div"));
|
|
255
|
+
handle.classList.add(side);
|
|
256
|
+
if (side.length === 1) handle.appendChild(document.createElement("div")).textContent = "";
|
|
257
|
+
handle.onpointerdown = (e) => this.#size_start(e, handle, side);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
[CREATE](options) {
|
|
261
|
+
super[CREATE](options);
|
|
262
|
+
const content = this.#content = options.content;
|
|
263
|
+
this.#content_box.appendChild(content);
|
|
264
|
+
this.set_input(PANEL_CONTENT.icon, content.content_icon, (icon) => this.#set_icon(icon.ok ? icon.value : void 0));
|
|
265
|
+
this.set_input(PANEL_CONTENT.title, content.content_title, (title) => {
|
|
266
|
+
this.#title.textContent = title.ok ? title.value : "⚠ " + title.error;
|
|
267
|
+
});
|
|
268
|
+
this.set_input(PANEL_CONTENT.closable, content.content_closable, (c) => this.#set_closable(c.ok && c.value));
|
|
269
|
+
this.set_input(PANEL_CONTENT.min_width, content.content_min_width, (w) => {
|
|
270
|
+
this.#min_width = w.ok ? w.value : 0;
|
|
271
|
+
this.#layout();
|
|
272
|
+
});
|
|
273
|
+
this.set_input(PANEL_CONTENT.min_height, content.content_min_height, (h) => {
|
|
274
|
+
this.#min_height = h.ok ? h.value : 0;
|
|
275
|
+
this.#layout();
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
set(options) {
|
|
279
|
+
this.set_input(PANEL.layer, options.layer, (layer) => {
|
|
280
|
+
this.#layer = layer.ok ? layer.value : 0;
|
|
281
|
+
this.#host?.[HOST_LAYER](this, this.#layer);
|
|
282
|
+
});
|
|
283
|
+
this.set_input(PANEL.anchor, options.anchor, (anchor) => {
|
|
284
|
+
this.#anchor = anchor.ok ? anchor.value : CompAnchor.TOP_LEFT;
|
|
285
|
+
this.#layout();
|
|
286
|
+
});
|
|
287
|
+
for (const name of [
|
|
288
|
+
"x",
|
|
289
|
+
"y",
|
|
290
|
+
"width",
|
|
291
|
+
"height"
|
|
292
|
+
]) {
|
|
293
|
+
if (options[name] !== void 0) this.#given.add(name);
|
|
294
|
+
this.set_input(PANEL[name], options[name], (value) => {
|
|
295
|
+
this.#values[name] = value.value;
|
|
296
|
+
this.#layout();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (options.hidden !== void 0) this.#given.add("hidden");
|
|
300
|
+
this.set_input(PANEL.hidden, options.hidden, (hidden) => {
|
|
301
|
+
this.#values.hidden = hidden.value;
|
|
302
|
+
this.classList.toggle("hidden", hidden.value);
|
|
303
|
+
this.#layout();
|
|
304
|
+
});
|
|
305
|
+
this.set_input(PANEL.sizeable, options.sizeable, (sizeable) => {
|
|
306
|
+
this.#sizeable = sizeable.ok && sizeable.value;
|
|
307
|
+
this.#layout();
|
|
308
|
+
});
|
|
309
|
+
this.set_input(PANEL.auto_hide, options.auto_hide, (auto_hide) => {
|
|
310
|
+
this.#auto_hide = auto_hide.ok && auto_hide.value;
|
|
311
|
+
});
|
|
312
|
+
this.set_input(PANEL.auto_close, options.auto_close, (auto_close) => {
|
|
313
|
+
this.#auto_close = auto_close.ok && auto_close.value;
|
|
314
|
+
});
|
|
315
|
+
this.set_input(PANEL.modal, options.modal, (modal) => this.#set_modal(modal.ok && modal.value));
|
|
316
|
+
this.set_input(PANEL.titlebar, options.titlebar, (titlebar) => {
|
|
317
|
+
this.classList.toggle("no-titlebar", !(titlebar.ok && titlebar.value));
|
|
318
|
+
this.#layout();
|
|
319
|
+
});
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
/**Content the panel shows, given when the panel is created*/
|
|
323
|
+
get content() {
|
|
324
|
+
return this.#content;
|
|
325
|
+
}
|
|
326
|
+
/**Resolves when the panel is closed*/
|
|
327
|
+
on_close() {
|
|
328
|
+
return new Promise((resolve) => this.#on_close.push(resolve));
|
|
329
|
+
}
|
|
330
|
+
/**Closes the panel and its content*/
|
|
331
|
+
close() {
|
|
332
|
+
this.ownerDocument.removeEventListener("pointerdown", this.#outside, { capture: true });
|
|
333
|
+
this.#host?.[HOST_REMOVE](this);
|
|
334
|
+
this.#host = void 0;
|
|
335
|
+
this.remove();
|
|
336
|
+
this.#content[CONTENT_CLOSED]();
|
|
337
|
+
for (const resolve of this.#on_close.splice(0)) resolve();
|
|
338
|
+
}
|
|
339
|
+
/**Called by the container that shows the panel, once, after creating it*/
|
|
340
|
+
[PANEL_ADDED](host) {
|
|
341
|
+
this.#host = host;
|
|
342
|
+
host[HOST_LAYER](this, this.#layer);
|
|
343
|
+
host[HOST_RAISE](this);
|
|
344
|
+
this.ownerDocument.addEventListener("pointerdown", this.#outside, {
|
|
345
|
+
capture: true,
|
|
346
|
+
passive: true
|
|
347
|
+
});
|
|
348
|
+
this.#layout();
|
|
349
|
+
}
|
|
350
|
+
/**Called by the container when its size changes*/
|
|
351
|
+
[PANEL_LAYOUT]() {
|
|
352
|
+
this.#layout();
|
|
353
|
+
}
|
|
354
|
+
on_resize() {
|
|
355
|
+
this.#layout();
|
|
356
|
+
}
|
|
357
|
+
/**Whether the user can change the input, when the panel owns it or it is a writable state*/
|
|
358
|
+
#can_change(name) {
|
|
359
|
+
return !this.#given.has(name) || this.#state_of(name) !== void 0;
|
|
360
|
+
}
|
|
361
|
+
/**The writable state the input has, undefined for a fixed value or one never given*/
|
|
362
|
+
#state_of(name) {
|
|
363
|
+
return this.input_state(PANEL[name]);
|
|
364
|
+
}
|
|
365
|
+
/**Writes a change by the user, to the state of the input, or to the panel when it owns the input*/
|
|
366
|
+
#change(name, value) {
|
|
367
|
+
const state = this.#state_of(name);
|
|
368
|
+
if (state) state.write(value);
|
|
369
|
+
else if (!this.#given.has(name)) {
|
|
370
|
+
this.#values[name] = value;
|
|
371
|
+
if (name === "hidden") this.classList.toggle("hidden", value === true);
|
|
372
|
+
this.#layout();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
#outside = (e) => {
|
|
376
|
+
if (this.#values.hidden) return;
|
|
377
|
+
if (this.contains(e.target) && e.target !== this) return;
|
|
378
|
+
if (this.#auto_close) this.close();
|
|
379
|
+
else if (this.#auto_hide) this.#change("hidden", true);
|
|
380
|
+
};
|
|
381
|
+
/**Left edge shown for the given one, keeping part of the panel inside the container*/
|
|
382
|
+
#clamp_left(left, width) {
|
|
383
|
+
const keep = width * KEEP_SIDE;
|
|
384
|
+
return clamp(left, -keep, this.#host.width - keep);
|
|
385
|
+
}
|
|
386
|
+
/**Top edge shown for the given one, keeping the title bar inside the container*/
|
|
387
|
+
#clamp_top(top) {
|
|
388
|
+
return clamp(top, 0, Math.max(0, this.#host.height - KEEP_TOP));
|
|
389
|
+
}
|
|
390
|
+
/**Applies size and position, the position is only clamped for showing, the inputs keep their values*/
|
|
391
|
+
#layout() {
|
|
392
|
+
if (!this.#host || !this.isConnected) return;
|
|
393
|
+
const { width, height } = this.#values;
|
|
394
|
+
this.style.width = width === void 0 ? "" : width + "rem";
|
|
395
|
+
this.style.height = height === void 0 ? "" : height + "rem";
|
|
396
|
+
this.style.minWidth = Math.max(MIN_SIZE, this.#min_width) + "rem";
|
|
397
|
+
this.style.minHeight = `calc(${Math.max(MIN_SIZE, this.#min_height)}rem + var(--titlebar-height))`;
|
|
398
|
+
this.#sizer.classList.toggle("x", this.#sizeable && this.#can_change("width"));
|
|
399
|
+
this.#sizer.classList.toggle("y", this.#sizeable && this.#can_change("height"));
|
|
400
|
+
this.classList.toggle("size-x", this.#sizer.classList.contains("x"));
|
|
401
|
+
this.classList.toggle("size-y", this.#sizer.classList.contains("y"));
|
|
402
|
+
if (this.#values.hidden) return;
|
|
403
|
+
const rect = this.getBoundingClientRect();
|
|
404
|
+
const w = px_to_rem(rect.width);
|
|
405
|
+
const h = px_to_rem(rect.height);
|
|
406
|
+
const [ax, ay] = anchor_fraction(this.#anchor);
|
|
407
|
+
const { x, y } = this.#values;
|
|
408
|
+
this.#left = this.#clamp_left(x === void 0 ? (this.#host.width - w) / 2 : x - w * ax, w);
|
|
409
|
+
this.#top = this.#clamp_top(y === void 0 ? (this.#host.height - h) / 2 : y - h * ay);
|
|
410
|
+
this.style.left = this.#left + "rem";
|
|
411
|
+
this.style.top = this.#top + "rem";
|
|
412
|
+
}
|
|
413
|
+
/**Moves the panel so its top left corner is at the given position, clamped, on the axes the user can change*/
|
|
414
|
+
#move_to(left, top) {
|
|
415
|
+
const rect = this.getBoundingClientRect();
|
|
416
|
+
const w = px_to_rem(rect.width);
|
|
417
|
+
const h = px_to_rem(rect.height);
|
|
418
|
+
const [ax, ay] = anchor_fraction(this.#anchor);
|
|
419
|
+
if (this.#can_change("x")) this.#change("x", this.#clamp_left(left, w) + w * ax);
|
|
420
|
+
if (this.#can_change("y")) this.#change("y", this.#clamp_top(top) + h * ay);
|
|
421
|
+
}
|
|
422
|
+
#move_start(e) {
|
|
423
|
+
if (e.button !== 0) return;
|
|
424
|
+
if (!this.#can_change("x") && !this.#can_change("y")) return;
|
|
425
|
+
const titlebar = this.#titlebar;
|
|
426
|
+
titlebar.setPointerCapture(e.pointerId);
|
|
427
|
+
titlebar.classList.add("moving");
|
|
428
|
+
this.#moving = true;
|
|
429
|
+
const left = this.#left;
|
|
430
|
+
const top = this.#top;
|
|
431
|
+
titlebar.onpointermove = (ev) => this.#move_to(left + px_to_rem(ev.clientX - e.clientX), top + px_to_rem(ev.clientY - e.clientY));
|
|
432
|
+
titlebar.onpointerup = (ev) => {
|
|
433
|
+
titlebar.releasePointerCapture(ev.pointerId);
|
|
434
|
+
titlebar.classList.remove("moving");
|
|
435
|
+
this.#moving = false;
|
|
436
|
+
titlebar.onpointermove = null;
|
|
437
|
+
titlebar.onpointerup = null;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
#move_key(e) {
|
|
441
|
+
const step = e.shiftKey ? 5 : e.ctrlKey ? .1 : 1;
|
|
442
|
+
const [dx, dy] = {
|
|
443
|
+
ArrowLeft: [-step, 0],
|
|
444
|
+
ArrowRight: [step, 0],
|
|
445
|
+
ArrowUp: [0, -step],
|
|
446
|
+
ArrowDown: [0, step]
|
|
447
|
+
}[e.key] ?? [];
|
|
448
|
+
if (dx === void 0 || dy === void 0) return;
|
|
449
|
+
e.preventDefault();
|
|
450
|
+
e.stopPropagation();
|
|
451
|
+
this.#move_to(this.#left + dx, this.#top + dy);
|
|
452
|
+
}
|
|
453
|
+
/**Sizes the panel from one side or corner, the opposite side stays where it is when x and y can be written*/
|
|
454
|
+
#size_start(e, handle, side) {
|
|
455
|
+
if (e.button !== 0) return;
|
|
456
|
+
e.stopPropagation();
|
|
457
|
+
const host = this.#host;
|
|
458
|
+
if (!host) return;
|
|
459
|
+
handle.setPointerCapture(e.pointerId);
|
|
460
|
+
const rect = this.getBoundingClientRect();
|
|
461
|
+
const w0 = px_to_rem(rect.width);
|
|
462
|
+
const h0 = px_to_rem(rect.height);
|
|
463
|
+
const left0 = this.#left;
|
|
464
|
+
const top0 = this.#top;
|
|
465
|
+
const [ax, ay] = anchor_fraction(this.#anchor);
|
|
466
|
+
const min_w = Math.max(MIN_SIZE, this.#min_width);
|
|
467
|
+
const min_h = Math.max(MIN_SIZE, this.#min_height) + px_to_rem(this.#titlebar.getBoundingClientRect().height);
|
|
468
|
+
const horizontal = this.#sizer.classList.contains("x");
|
|
469
|
+
const vertical = this.#sizer.classList.contains("y");
|
|
470
|
+
handle.onpointermove = (ev) => {
|
|
471
|
+
const dx = px_to_rem(ev.clientX - e.clientX);
|
|
472
|
+
const dy = px_to_rem(ev.clientY - e.clientY);
|
|
473
|
+
if (horizontal && (side.includes("e") || side.includes("w"))) {
|
|
474
|
+
const east = side.includes("e");
|
|
475
|
+
const w = clamp(east ? w0 + dx : w0 - dx, min_w, host.width);
|
|
476
|
+
this.#change("width", w);
|
|
477
|
+
if (this.#can_change("x")) this.#change("x", (east ? left0 : left0 + w0 - w) + w * ax);
|
|
478
|
+
}
|
|
479
|
+
if (vertical && (side.includes("n") || side.includes("s"))) {
|
|
480
|
+
const south = side.includes("s");
|
|
481
|
+
const h = clamp(south ? h0 + dy : h0 - dy, min_h, host.height);
|
|
482
|
+
this.#change("height", h);
|
|
483
|
+
if (this.#can_change("y")) this.#change("y", (south ? top0 : top0 + h0 - h) + h * ay);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
handle.onpointerup = (ev) => {
|
|
487
|
+
handle.releasePointerCapture(ev.pointerId);
|
|
488
|
+
handle.onpointermove = null;
|
|
489
|
+
handle.onpointerup = null;
|
|
490
|
+
this.#titlebar.focus();
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
#set_icon(icon) {
|
|
494
|
+
if (icon) {
|
|
495
|
+
this.#icon ??= this.#titlebar.insertBefore(document.createElement("div"), this.#title);
|
|
496
|
+
this.#icon.classList.add("icon");
|
|
497
|
+
this.#icon.replaceChildren(icon());
|
|
498
|
+
} else {
|
|
499
|
+
this.#icon?.remove();
|
|
500
|
+
this.#icon = void 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
#set_closable(closable) {
|
|
504
|
+
if (closable && !this.#close_button) {
|
|
505
|
+
const button = this.#close_button = this.#titlebar.appendChild(document.createElement("span"));
|
|
506
|
+
button.classList.add("close-button");
|
|
507
|
+
button.textContent = "×";
|
|
508
|
+
button.onpointerdown = (e) => {
|
|
509
|
+
e.preventDefault();
|
|
510
|
+
e.stopPropagation();
|
|
511
|
+
button.setPointerCapture(e.pointerId);
|
|
512
|
+
button.onpointerup = (e) => {
|
|
513
|
+
button.releasePointerCapture(e.pointerId);
|
|
514
|
+
button.onpointerup = null;
|
|
515
|
+
const rect = button.getBoundingClientRect();
|
|
516
|
+
if (e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom) this.close();
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
button.oncontextmenu = (e) => {
|
|
520
|
+
e.preventDefault();
|
|
521
|
+
e.stopPropagation();
|
|
522
|
+
};
|
|
523
|
+
button.ontouchend = (e) => {
|
|
524
|
+
if (e.cancelable) e.preventDefault();
|
|
525
|
+
e.stopPropagation();
|
|
526
|
+
};
|
|
527
|
+
} else if (!closable && this.#close_button) {
|
|
528
|
+
this.#close_button.remove();
|
|
529
|
+
this.#close_button = void 0;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
#set_modal(modal) {
|
|
533
|
+
this.classList.toggle("modal", modal);
|
|
534
|
+
if (modal && !this.#focus_catcher) {
|
|
535
|
+
this.#focus_catcher = this.appendChild(document.createElement("div"));
|
|
536
|
+
this.#focus_catcher.tabIndex = 0;
|
|
537
|
+
this.#focus_catcher.onfocus = () => this.#content.focus();
|
|
538
|
+
} else if (!modal && this.#focus_catcher) {
|
|
539
|
+
this.#focus_catcher.remove();
|
|
540
|
+
this.#focus_catcher = void 0;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
define_element(Panel);
|
|
545
|
+
// composition/container.ts
|
|
546
|
+
/**Internal input, the scale changes the size of the container in rem*/
|
|
547
|
+
const SCALE_KEY = input_key();
|
|
548
|
+
/**Layer over the whole page that panels float in, one per document*/
|
|
549
|
+
var PanelContainer = class extends Base {
|
|
550
|
+
static element_name() {
|
|
551
|
+
return "panelcontainer";
|
|
552
|
+
}
|
|
553
|
+
static element_name_space() {
|
|
554
|
+
return "composition";
|
|
555
|
+
}
|
|
556
|
+
#layers = /* @__PURE__ */ new Map();
|
|
557
|
+
#panels = /* @__PURE__ */ new Set();
|
|
558
|
+
#raised = 0;
|
|
559
|
+
#active;
|
|
560
|
+
constructor() {
|
|
561
|
+
super();
|
|
562
|
+
this.attach_to_resize_observer();
|
|
563
|
+
this.set_input(SCALE_KEY, SCALE, () => this.#layout());
|
|
564
|
+
}
|
|
565
|
+
/**Width in rem*/
|
|
566
|
+
get width() {
|
|
567
|
+
return px_to_rem(this.actual_size.width);
|
|
568
|
+
}
|
|
569
|
+
/**Height in rem*/
|
|
570
|
+
get height() {
|
|
571
|
+
return px_to_rem(this.actual_size.height);
|
|
572
|
+
}
|
|
573
|
+
/**Panel the user worked in last*/
|
|
574
|
+
get active_panel() {
|
|
575
|
+
return this.#active;
|
|
576
|
+
}
|
|
577
|
+
/**Creates a panel showing the content in this container
|
|
578
|
+
* The title, icon, close button and minimum size come from the content, see content*/
|
|
579
|
+
panel(content, options = {}) {
|
|
580
|
+
const panel = Panel.create({
|
|
581
|
+
...options,
|
|
582
|
+
content
|
|
583
|
+
});
|
|
584
|
+
this.#panels.add(panel);
|
|
585
|
+
panel[PANEL_ADDED](this);
|
|
586
|
+
return panel;
|
|
587
|
+
}
|
|
588
|
+
on_resize() {
|
|
589
|
+
this.#layout();
|
|
590
|
+
}
|
|
591
|
+
#layout() {
|
|
592
|
+
for (const panel of this.#panels) panel[PANEL_LAYOUT]();
|
|
593
|
+
}
|
|
594
|
+
[HOST_LAYER](panel, layer) {
|
|
595
|
+
let box = this.#layers.get(layer);
|
|
596
|
+
if (!box) {
|
|
597
|
+
box = document.createElement("div");
|
|
598
|
+
box.style.zIndex = String(layer);
|
|
599
|
+
this.#layers.set(layer, box);
|
|
600
|
+
const next = [...this.#layers].filter(([l]) => l > layer).sort(([a], [b]) => a - b)[0]?.[1];
|
|
601
|
+
this.insertBefore(box, next ?? null);
|
|
602
|
+
}
|
|
603
|
+
if (panel.parentElement !== box) box.appendChild(panel);
|
|
604
|
+
}
|
|
605
|
+
[HOST_RAISE](panel) {
|
|
606
|
+
this.#active = panel;
|
|
607
|
+
panel.style.zIndex = String(++this.#raised);
|
|
608
|
+
}
|
|
609
|
+
[HOST_REMOVE](panel) {
|
|
610
|
+
this.#panels.delete(panel);
|
|
611
|
+
if (this.#active === panel) this.#active = void 0;
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
define_element(PanelContainer);
|
|
615
|
+
const CONTAINERS = /* @__PURE__ */ new WeakMap();
|
|
616
|
+
DOCUMENT_HANDLER.events.on("removed", (e) => {
|
|
617
|
+
CONTAINERS.get(e.data)?.remove();
|
|
618
|
+
CONTAINERS.delete(e.data);
|
|
619
|
+
});
|
|
620
|
+
/**The panel container of the document the given node is in, the main document by default
|
|
621
|
+
* The container is made the first time it is asked for*/
|
|
622
|
+
function panel_container(owner = DOCUMENT_HANDLER.main) {
|
|
623
|
+
const doc = owner.ownerDocument ?? owner;
|
|
624
|
+
let container = CONTAINERS.get(doc);
|
|
625
|
+
if (!container) {
|
|
626
|
+
container = PanelContainer.create();
|
|
627
|
+
doc.documentElement.appendChild(container);
|
|
628
|
+
CONTAINERS.set(doc, container);
|
|
629
|
+
}
|
|
630
|
+
return container;
|
|
631
|
+
}
|
|
632
|
+
/**Creates a panel showing the content, in the main document
|
|
633
|
+
* Use panel_container(element).panel for another document*/
|
|
634
|
+
function panel(content, options = {}) {
|
|
635
|
+
return panel_container().panel(content, options);
|
|
636
|
+
}
|
|
637
|
+
// composition/customization.ts
|
|
638
|
+
/**Inputs of the customization*/
|
|
639
|
+
const CUSTOMIZATION = {
|
|
640
|
+
/**Settings of the app, shown under the theme*/
|
|
641
|
+
main: input_key(),
|
|
642
|
+
/**Advanced settings of the app, shown last in the advanced section*/
|
|
643
|
+
advanced: input_key()
|
|
644
|
+
};
|
|
645
|
+
/**Content with the settings of the library, theme, scale, input mode and animations, and settings of the app*/
|
|
646
|
+
var Customization = class extends ContentBase {
|
|
647
|
+
static element_name() {
|
|
648
|
+
return "customization";
|
|
649
|
+
}
|
|
650
|
+
static element_name_space() {
|
|
651
|
+
return "composition";
|
|
652
|
+
}
|
|
653
|
+
#main = form.group({ embed: true });
|
|
654
|
+
#advanced = form.group({ embed: true });
|
|
655
|
+
constructor() {
|
|
656
|
+
super();
|
|
657
|
+
this.appendChild(form.group({ elements: [
|
|
658
|
+
form.toggle_button().bind({ value: THEME }),
|
|
659
|
+
this.#main,
|
|
660
|
+
form.group_collapser(form.group({
|
|
661
|
+
embed: true,
|
|
662
|
+
elements: [
|
|
663
|
+
form.text({ text: "UI Scale" }),
|
|
664
|
+
form.stepper().bind({ value: SCALE }),
|
|
665
|
+
form.text({ text: "Input Mode" }),
|
|
666
|
+
form.toggle_button().bind({ value: INPUT_MODE }),
|
|
667
|
+
form.text({ text: "Animation Level" }),
|
|
668
|
+
form.toggle_button().bind({ value: ANIMATION_LEVEL }),
|
|
669
|
+
form.text({ text: "Animation Speed" }),
|
|
670
|
+
form.slider({ live: true }).bind({ value: ANIMATION_SPEED }),
|
|
671
|
+
this.#advanced
|
|
672
|
+
]
|
|
673
|
+
}), {
|
|
674
|
+
closed_text: "Advanced",
|
|
675
|
+
collapsed: true
|
|
676
|
+
})
|
|
677
|
+
] }));
|
|
678
|
+
}
|
|
679
|
+
set(options) {
|
|
680
|
+
super.set(options);
|
|
681
|
+
this.set_input(CUSTOMIZATION.main, options.main, (elements) => {
|
|
682
|
+
this.#main = replace_group(this.#main, elements.ok ? elements.value : []);
|
|
683
|
+
});
|
|
684
|
+
this.set_input(CUSTOMIZATION.advanced, options.advanced, (elements) => {
|
|
685
|
+
this.#advanced = replace_group(this.#advanced, elements.ok ? elements.value : []);
|
|
686
|
+
});
|
|
687
|
+
return this;
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
define_element(Customization);
|
|
691
|
+
/**A form group only takes elements once, so a new list gets a new group*/
|
|
692
|
+
const replace_group = (old, elements) => {
|
|
693
|
+
const group = form.group({
|
|
694
|
+
embed: true,
|
|
695
|
+
elements: [...elements]
|
|
696
|
+
});
|
|
697
|
+
old.replaceWith(group);
|
|
698
|
+
return group;
|
|
699
|
+
};
|
|
700
|
+
/**Content with the settings of the library, and of the app given as main and advanced
|
|
701
|
+
* The title, icon and minimum size have defaults, give them to change them*/
|
|
702
|
+
function customization(options = {}) {
|
|
703
|
+
return Customization.create({
|
|
704
|
+
title: "Customization",
|
|
705
|
+
icon: material_brightness_medium_rounded,
|
|
706
|
+
closable: true,
|
|
707
|
+
min_width: 10,
|
|
708
|
+
min_height: 6,
|
|
709
|
+
...options
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
/**Creates the customization in a modal panel, hidden, it hides again when the user presses outside it
|
|
713
|
+
* Change the panel with panel.set, like its position
|
|
714
|
+
* @param owner the panel is made in the document of the owner, the main document by default*/
|
|
715
|
+
function customization_panel(options = {}, owner = DOCUMENT_HANDLER.main) {
|
|
716
|
+
const content = customization(options);
|
|
717
|
+
const hidden = state.ok_w(true);
|
|
718
|
+
return {
|
|
719
|
+
panel: panel_container(owner).panel(content, {
|
|
720
|
+
sizeable: false,
|
|
721
|
+
titlebar: false,
|
|
722
|
+
width: 20,
|
|
723
|
+
hidden,
|
|
724
|
+
auto_hide: true,
|
|
725
|
+
modal: true,
|
|
726
|
+
layer: 9999
|
|
727
|
+
}),
|
|
728
|
+
content,
|
|
729
|
+
hidden
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
/**Shows the customization panel when the element is clicked, with the anchor of the panel at the anchor of the element
|
|
733
|
+
* @param c_panel the panel to show, a new one in the document of the element by default*/
|
|
734
|
+
function attach_customization_panel_to_element(element, element_anchor, panel_anchor, c_panel = customization_panel({}, element)) {
|
|
735
|
+
element.addEventListener("click", () => {
|
|
736
|
+
const { x, y } = get_element_anchor_position(element, element_anchor);
|
|
737
|
+
c_panel.panel.set({
|
|
738
|
+
x,
|
|
739
|
+
y,
|
|
740
|
+
anchor: panel_anchor
|
|
741
|
+
});
|
|
742
|
+
c_panel.hidden.write(false);
|
|
743
|
+
c_panel.panel.focus();
|
|
744
|
+
});
|
|
745
|
+
return c_panel;
|
|
746
|
+
}
|
|
747
|
+
// composition/topbar.ts
|
|
748
|
+
/**Shared base of the top bar elements, only sets the namespace*/
|
|
749
|
+
var TopbarBase = class extends Base {
|
|
750
|
+
static element_name() {
|
|
751
|
+
return "@abstract@";
|
|
752
|
+
}
|
|
753
|
+
static element_name_space() {
|
|
754
|
+
return "composition";
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
/**Inputs of the top bar*/
|
|
758
|
+
const TOPBAR = {
|
|
759
|
+
/**Items at the left side, the side is empty on errors*/
|
|
760
|
+
left: input_key(),
|
|
761
|
+
/**Items in the middle, the middle is empty on errors*/
|
|
762
|
+
mid: input_key(),
|
|
763
|
+
/**Items at the right side, the side is empty on errors*/
|
|
764
|
+
right: input_key()
|
|
765
|
+
};
|
|
766
|
+
/**Bar along the top of a page, with items at the left, in the middle and at the right*/
|
|
767
|
+
var Topbar = class extends TopbarBase {
|
|
768
|
+
static element_name() {
|
|
769
|
+
return "topbar";
|
|
770
|
+
}
|
|
771
|
+
#left = this.appendChild(document.createElement("div"));
|
|
772
|
+
#mid = this.appendChild(document.createElement("div"));
|
|
773
|
+
#right = this.appendChild(document.createElement("div"));
|
|
774
|
+
set(options) {
|
|
775
|
+
this.set_input(TOPBAR.left, options.left, (items) => {
|
|
776
|
+
this.#left.replaceChildren(...items.ok ? items.value : []);
|
|
777
|
+
});
|
|
778
|
+
this.set_input(TOPBAR.mid, options.mid, (items) => {
|
|
779
|
+
this.#mid.replaceChildren(...items.ok ? items.value : []);
|
|
780
|
+
});
|
|
781
|
+
this.set_input(TOPBAR.right, options.right, (items) => {
|
|
782
|
+
this.#right.replaceChildren(...items.ok ? items.value : []);
|
|
783
|
+
});
|
|
784
|
+
return this;
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
define_element(Topbar);
|
|
788
|
+
/**Inputs of a top bar button*/
|
|
789
|
+
const BUTTON = {
|
|
790
|
+
/**Text of the button, shows the error on errors*/
|
|
791
|
+
text: input_key(),
|
|
792
|
+
/**Icon in front of the text, no icon on errors*/
|
|
793
|
+
icon: input_key(),
|
|
794
|
+
/**Called when the button is clicked, a plain value as it is not shown*/
|
|
795
|
+
on_click: input_key()
|
|
796
|
+
};
|
|
797
|
+
/**Button for the top bar, with an icon, a text or both*/
|
|
798
|
+
var TopbarButton = class extends TopbarBase {
|
|
799
|
+
static element_name() {
|
|
800
|
+
return "topbar-button";
|
|
801
|
+
}
|
|
802
|
+
#icon;
|
|
803
|
+
#text = this.appendChild(document.createElement("span"));
|
|
804
|
+
#on_click;
|
|
805
|
+
constructor() {
|
|
806
|
+
super();
|
|
807
|
+
this.onclick = () => this.#on_click?.();
|
|
808
|
+
}
|
|
809
|
+
set(options) {
|
|
810
|
+
this.set_input(BUTTON.on_click, options.on_click, (on_click) => {
|
|
811
|
+
this.#on_click = on_click.value;
|
|
812
|
+
});
|
|
813
|
+
this.set_input(BUTTON.text, options.text, (text) => {
|
|
814
|
+
this.#text.textContent = text.ok ? text.value : "⚠ " + text.error;
|
|
815
|
+
});
|
|
816
|
+
this.set_input(BUTTON.icon, options.icon, (icon) => {
|
|
817
|
+
this.#icon?.remove();
|
|
818
|
+
this.#icon = icon.ok && icon.value ? icon.value() : void 0;
|
|
819
|
+
if (this.#icon) this.prepend(this.#icon);
|
|
820
|
+
});
|
|
821
|
+
return this;
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
define_element(TopbarButton);
|
|
825
|
+
/**Inputs of a top bar label*/
|
|
826
|
+
const LABEL = {
|
|
827
|
+
/**Text of the label, shows the error on errors*/
|
|
828
|
+
text: input_key() };
|
|
829
|
+
/**Text for the top bar*/
|
|
830
|
+
var TopbarLabel = class extends TopbarBase {
|
|
831
|
+
static element_name() {
|
|
832
|
+
return "topbar-label";
|
|
833
|
+
}
|
|
834
|
+
set(options) {
|
|
835
|
+
this.set_input(LABEL.text, options.text, (text) => {
|
|
836
|
+
this.textContent = text.ok ? text.value : "⚠ " + text.error;
|
|
837
|
+
});
|
|
838
|
+
return this;
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
define_element(TopbarLabel);
|
|
842
|
+
/**Bar along the top of a page, items are given as arrays for the left, middle and right*/
|
|
843
|
+
function topbar(options = {}) {
|
|
844
|
+
return Topbar.create(options);
|
|
845
|
+
}
|
|
846
|
+
/**Button for the top bar, with an icon, a text or both*/
|
|
847
|
+
function topbar_button(options = {}) {
|
|
848
|
+
return TopbarButton.create(options);
|
|
849
|
+
}
|
|
850
|
+
/**Text for the top bar*/
|
|
851
|
+
function topbar_label(options = {}) {
|
|
852
|
+
return TopbarLabel.create(options);
|
|
853
|
+
}
|
|
854
|
+
// composition/index.ts
|
|
855
|
+
const comp = {
|
|
856
|
+
content,
|
|
857
|
+
panel,
|
|
858
|
+
panel_container,
|
|
859
|
+
topbar,
|
|
860
|
+
topbar_button,
|
|
861
|
+
topbar_label,
|
|
862
|
+
customization,
|
|
863
|
+
customization_panel,
|
|
864
|
+
attach_customization_panel_to_element,
|
|
865
|
+
get_element_anchor_position
|
|
866
|
+
};
|
|
867
|
+
export { ContentBase as n, CompAnchor as r, comp as t };
|
|
868
|
+
|
|
869
|
+
//# sourceMappingURL=composition-7xlf0UjB.mjs.map
|