@schukai/monster 3.58.3 → 3.59.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,34 +4,37 @@
4
4
  * This file is licensed under the AGPLv3 License.
5
5
  * License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
6
6
  */
7
- import {instanceSymbol} from "../../constants.mjs";
8
- import {Pathfinder} from "../../data/pathfinder.mjs";
7
+ import { instanceSymbol } from "../../constants.mjs";
8
+ import { Pathfinder } from "../../data/pathfinder.mjs";
9
9
  import {
10
- addAttributeToken,
11
- removeAttributeToken,
10
+ addAttributeToken,
11
+ removeAttributeToken,
12
12
  } from "../../dom/attributes.mjs";
13
- import {ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
14
13
  import {
15
- assembleMethodSymbol,
16
- getSlottedElements,
17
- registerCustomElement,
14
+ ATTRIBUTE_ERRORMESSAGE,
15
+ ATTRIBUTE_ROLE,
16
+ } from "../../dom/constants.mjs";
17
+ import {
18
+ assembleMethodSymbol,
19
+ getSlottedElements,
20
+ registerCustomElement,
18
21
  } from "../../dom/customelement.mjs";
19
22
  import {
20
- CustomElement,
21
- attributeObserverSymbol,
23
+ CustomElement,
24
+ attributeObserverSymbol,
22
25
  } from "../../dom/customelement.mjs";
23
- import {findTargetElementFromEvent} from "../../dom/events.mjs";
24
- import {getDocument} from "../../dom/util.mjs";
25
- import {getGlobal} from "../../types/global.mjs";
26
- import {ID} from "../../types/id.mjs";
27
- import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
28
- import {Processing} from "../../util/processing.mjs";
29
- import {STYLE_DISPLAY_MODE_BLOCK} from "./constants.mjs";
30
- import {ButtonBarStyleSheet} from "./stylesheet/button-bar.mjs";
31
- import {positionPopper} from "./util/floating-ui.mjs";
32
- import {convertToPixels} from "../../dom/dimension.mjs";
33
-
34
- export {ButtonBar};
26
+ import { findTargetElementFromEvent } from "../../dom/events.mjs";
27
+ import { getDocument } from "../../dom/util.mjs";
28
+ import { getGlobal } from "../../types/global.mjs";
29
+ import { ID } from "../../types/id.mjs";
30
+ import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
31
+ import { Processing } from "../../util/processing.mjs";
32
+ import { STYLE_DISPLAY_MODE_BLOCK } from "./constants.mjs";
33
+ import { ButtonBarStyleSheet } from "./stylesheet/button-bar.mjs";
34
+ import { positionPopper } from "./util/floating-ui.mjs";
35
+ import { convertToPixels } from "../../dom/dimension.mjs";
36
+
37
+ export { ButtonBar };
35
38
 
36
39
  /**
37
40
  * @private
@@ -148,154 +151,154 @@ const ATTRIBUTE_POPPER_POSITION = "data-monster-popper-position";
148
151
  * @fires Monster.Components.Form.event:monster-fetched
149
152
  */
150
153
  class ButtonBar extends CustomElement {
151
- /**
152
- * This method is called by the `instanceof` operator.
153
- * @returns {symbol}
154
- */
155
- static get [instanceSymbol]() {
156
- return Symbol.for("@schukai/monster/components/form/button-bar@@instance");
157
- }
158
-
159
- /**
160
- * To set the options via the html tag the attribute `data-monster-options` must be used.
161
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
162
- *
163
- * The individual configuration values can be found in the table.
164
- *
165
- * @property {Object} templates Template definitions
166
- * @property {string} templates.main Main template
167
- * @property {Object} labels
168
- * @property {Object} popper FloatingUI popper configuration
169
- * @property {string} popper.placement=top Placement of the popper
170
- * @property {number} popper.middleware [middlerware](https://floating-ui.js.org/docs/middleware) to be used
171
- */
172
- get defaults() {
173
- const obj = Object.assign({}, super.defaults, {
174
- templates: {
175
- main: getTemplate(),
176
- },
177
- labels: {},
178
- popper: {
179
- placement: "bottom",
180
- },
181
- });
182
-
183
- initDefaultsFromAttributes.call(this, obj);
184
-
185
- return obj;
186
- }
187
-
188
- /**
189
- * This method is called internal and should not be called directly.
190
- */
191
- [assembleMethodSymbol]() {
192
- super[assembleMethodSymbol]();
193
-
194
- this[dimensionsSymbol] = new Pathfinder({data: {}});
195
-
196
- initControlReferences.call(this);
197
- initEventHandler.call(this);
198
-
199
- // setup structure
200
- initButtonBar.call(this).then(() => {
201
- initPopperSwitch.call(this);
202
- });
203
- }
204
-
205
- /**
206
- * This method is called internal and should not be called directly.
207
- *
208
- * @return {CSSStyleSheet[]}
209
- */
210
- static getCSSStyleSheet() {
211
- return [ButtonBarStyleSheet];
212
- }
213
-
214
- /**
215
- * This method is called internal and should not be called directly.
216
- *
217
- * @return {string}
218
- */
219
- static getTag() {
220
- return "monster-button-bar";
221
- }
222
-
223
- /**
224
- * This method is called by the dom and should not be called directly.
225
- *
226
- * @return {void}
227
- */
228
- connectedCallback() {
229
- super.connectedCallback();
230
-
231
- const document = getDocument();
232
-
233
- for (const [, type] of Object.entries(["click", "touch"])) {
234
- // close on outside ui-events
235
- document.addEventListener(type, this[closeEventHandler]);
236
- }
237
-
238
- setTimeout(() => {
239
- updatePopper.call(this);
240
- updateResizeObserverObservation.call(this);
241
- }, 0);
242
- }
243
-
244
- /**
245
- * This method determines which attributes are to be monitored by `attributeChangedCallback()`.
246
- *
247
- * @return {string[]}
248
- */
249
- static get observedAttributes() {
250
- const attributes = super.observedAttributes;
251
- attributes.push(ATTRIBUTE_POPPER_POSITION);
252
- return attributes;
253
- }
254
-
255
- /**
256
- * This method is called by the dom and should not be called directly.
257
- *
258
- * @return {void}
259
- */
260
- disconnectedCallback() {
261
- super.disconnectedCallback();
262
-
263
- const document = getDocument();
264
-
265
- // close on outside ui-events
266
- for (const [, type] of Object.entries(["click", "touch"])) {
267
- document.removeEventListener(type, this[closeEventHandler]);
268
- }
269
-
270
- disconnectResizeObserver.call(this);
271
- }
272
-
273
- /**
274
- * Close the slotted dialog.
275
- * @return {ButtonBar}
276
- */
277
- hideDialog() {
278
- hide.call(this);
279
- return this;
280
- }
281
-
282
- /**
283
- * Open the slotted dialog.
284
- * @return {ButtonBar}
285
- */
286
- showDialog() {
287
- show.call(this);
288
- return this;
289
- }
290
-
291
- /**
292
- * Toggle the slotted dialog.
293
- * @return {ButtonBar}
294
- */
295
- toggleDialog() {
296
- toggle.call(this);
297
- return this;
298
- }
154
+ /**
155
+ * This method is called by the `instanceof` operator.
156
+ * @returns {symbol}
157
+ */
158
+ static get [instanceSymbol]() {
159
+ return Symbol.for("@schukai/monster/components/form/button-bar@@instance");
160
+ }
161
+
162
+ /**
163
+ * To set the options via the html tag the attribute `data-monster-options` must be used.
164
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
165
+ *
166
+ * The individual configuration values can be found in the table.
167
+ *
168
+ * @property {Object} templates Template definitions
169
+ * @property {string} templates.main Main template
170
+ * @property {Object} labels
171
+ * @property {Object} popper FloatingUI popper configuration
172
+ * @property {string} popper.placement=top Placement of the popper
173
+ * @property {number} popper.middleware [middlerware](https://floating-ui.js.org/docs/middleware) to be used
174
+ */
175
+ get defaults() {
176
+ const obj = Object.assign({}, super.defaults, {
177
+ templates: {
178
+ main: getTemplate(),
179
+ },
180
+ labels: {},
181
+ popper: {
182
+ placement: "bottom",
183
+ },
184
+ });
185
+
186
+ initDefaultsFromAttributes.call(this, obj);
187
+
188
+ return obj;
189
+ }
190
+
191
+ /**
192
+ * This method is called internal and should not be called directly.
193
+ */
194
+ [assembleMethodSymbol]() {
195
+ super[assembleMethodSymbol]();
196
+
197
+ this[dimensionsSymbol] = new Pathfinder({ data: {} });
198
+
199
+ initControlReferences.call(this);
200
+ initEventHandler.call(this);
201
+
202
+ // setup structure
203
+ initButtonBar.call(this).then(() => {
204
+ initPopperSwitch.call(this);
205
+ });
206
+ }
207
+
208
+ /**
209
+ * This method is called internal and should not be called directly.
210
+ *
211
+ * @return {CSSStyleSheet[]}
212
+ */
213
+ static getCSSStyleSheet() {
214
+ return [ButtonBarStyleSheet];
215
+ }
216
+
217
+ /**
218
+ * This method is called internal and should not be called directly.
219
+ *
220
+ * @return {string}
221
+ */
222
+ static getTag() {
223
+ return "monster-button-bar";
224
+ }
225
+
226
+ /**
227
+ * This method is called by the dom and should not be called directly.
228
+ *
229
+ * @return {void}
230
+ */
231
+ connectedCallback() {
232
+ super.connectedCallback();
233
+
234
+ const document = getDocument();
235
+
236
+ for (const [, type] of Object.entries(["click", "touch"])) {
237
+ // close on outside ui-events
238
+ document.addEventListener(type, this[closeEventHandler]);
239
+ }
240
+
241
+ setTimeout(() => {
242
+ updatePopper.call(this);
243
+ updateResizeObserverObservation.call(this);
244
+ }, 0);
245
+ }
246
+
247
+ /**
248
+ * This method determines which attributes are to be monitored by `attributeChangedCallback()`.
249
+ *
250
+ * @return {string[]}
251
+ */
252
+ static get observedAttributes() {
253
+ const attributes = super.observedAttributes;
254
+ attributes.push(ATTRIBUTE_POPPER_POSITION);
255
+ return attributes;
256
+ }
257
+
258
+ /**
259
+ * This method is called by the dom and should not be called directly.
260
+ *
261
+ * @return {void}
262
+ */
263
+ disconnectedCallback() {
264
+ super.disconnectedCallback();
265
+
266
+ const document = getDocument();
267
+
268
+ // close on outside ui-events
269
+ for (const [, type] of Object.entries(["click", "touch"])) {
270
+ document.removeEventListener(type, this[closeEventHandler]);
271
+ }
272
+
273
+ disconnectResizeObserver.call(this);
274
+ }
275
+
276
+ /**
277
+ * Close the slotted dialog.
278
+ * @return {ButtonBar}
279
+ */
280
+ hideDialog() {
281
+ hide.call(this);
282
+ return this;
283
+ }
284
+
285
+ /**
286
+ * Open the slotted dialog.
287
+ * @return {ButtonBar}
288
+ */
289
+ showDialog() {
290
+ show.call(this);
291
+ return this;
292
+ }
293
+
294
+ /**
295
+ * Toggle the slotted dialog.
296
+ * @return {ButtonBar}
297
+ */
298
+ toggleDialog() {
299
+ toggle.call(this);
300
+ return this;
301
+ }
299
302
  }
300
303
 
301
304
  /**
@@ -304,88 +307,88 @@ class ButtonBar extends CustomElement {
304
307
  * @returns {*}
305
308
  */
306
309
  function initDefaultsFromAttributes(obj) {
307
- if (this.hasAttribute(ATTRIBUTE_POPPER_POSITION)) {
308
- obj.popper.placement = this.getAttribute(ATTRIBUTE_POPPER_POSITION);
309
- }
310
+ if (this.hasAttribute(ATTRIBUTE_POPPER_POSITION)) {
311
+ obj.popper.placement = this.getAttribute(ATTRIBUTE_POPPER_POSITION);
312
+ }
310
313
 
311
- return obj;
314
+ return obj;
312
315
  }
313
316
 
314
317
  /**
315
318
  * @private
316
319
  */
317
320
  function initEventHandler() {
318
- const self = this;
319
- /**
320
- * @param {Event} event
321
- */
322
- self[closeEventHandler] = (event) => {
323
- const path = event.composedPath();
324
-
325
- for (const [, element] of Object.entries(path)) {
326
- if (element === self) {
327
- return;
328
- }
329
- }
330
-
331
- hide.call(self);
332
- };
333
-
334
- if (self[buttonBarSlotElementSymbol]) {
335
- self[buttonBarSlotElementSymbol].addEventListener("slotchange", (event) => {
336
- checkAndRearrangeButtons.call(self);
337
- });
338
- }
339
-
340
- if (self[popperElementSymbol]) {
341
- self[popperElementSymbol].addEventListener("slotchange", (event) => {
342
- checkAndRearrangeButtons.call(self);
343
- });
344
- }
345
-
346
- // data-monster-options
347
- self[attributeObserverSymbol][ATTRIBUTE_POPPER_POSITION] = function (value) {
348
- self.setOption("classes.button", value);
349
- };
350
-
351
- self[resizeObserverSymbol] = new ResizeObserver((entries) => {
352
- if (self[timerCallbackSymbol] instanceof DeadMansSwitch) {
353
- try {
354
- self[timerCallbackSymbol].touch();
355
- return;
356
- } catch (e) {
357
- // catch Error("has already run");
358
- if (e.message !== "has already run") {
359
- throw e;
360
- }
361
- delete self[timerCallbackSymbol];
362
- }
363
- }
364
-
365
- self[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
366
- setTimeout(() => {
367
- updatePopper.call(self);
368
- self[dimensionsSymbol].setVia("data.calculated", false);
369
- checkAndRearrangeButtons.call(self);
370
- }, 50);
371
- });
372
- });
373
-
374
- initSlotChangedHandler.call(self);
321
+ const self = this;
322
+ /**
323
+ * @param {Event} event
324
+ */
325
+ self[closeEventHandler] = (event) => {
326
+ const path = event.composedPath();
327
+
328
+ for (const [, element] of Object.entries(path)) {
329
+ if (element === self) {
330
+ return;
331
+ }
332
+ }
333
+
334
+ hide.call(self);
335
+ };
336
+
337
+ if (self[buttonBarSlotElementSymbol]) {
338
+ self[buttonBarSlotElementSymbol].addEventListener("slotchange", (event) => {
339
+ checkAndRearrangeButtons.call(self);
340
+ });
341
+ }
342
+
343
+ if (self[popperElementSymbol]) {
344
+ self[popperElementSymbol].addEventListener("slotchange", (event) => {
345
+ checkAndRearrangeButtons.call(self);
346
+ });
347
+ }
348
+
349
+ // data-monster-options
350
+ self[attributeObserverSymbol][ATTRIBUTE_POPPER_POSITION] = function (value) {
351
+ self.setOption("classes.button", value);
352
+ };
353
+
354
+ self[resizeObserverSymbol] = new ResizeObserver((entries) => {
355
+ if (self[timerCallbackSymbol] instanceof DeadMansSwitch) {
356
+ try {
357
+ self[timerCallbackSymbol].touch();
358
+ return;
359
+ } catch (e) {
360
+ // catch Error("has already run");
361
+ if (e.message !== "has already run") {
362
+ throw e;
363
+ }
364
+ delete self[timerCallbackSymbol];
365
+ }
366
+ }
367
+
368
+ self[timerCallbackSymbol] = new DeadMansSwitch(200, () => {
369
+ setTimeout(() => {
370
+ updatePopper.call(self);
371
+ self[dimensionsSymbol].setVia("data.calculated", false);
372
+ checkAndRearrangeButtons.call(self);
373
+ }, 50);
374
+ });
375
+ });
376
+
377
+ initSlotChangedHandler.call(self);
375
378
  }
376
379
 
377
380
  function initSlotChangedHandler() {
378
- this[buttonBarElementSymbol].addEventListener("slotchange", () => {
379
- updateResizeObserverObservation.call(this);
380
- });
381
+ this[buttonBarElementSymbol].addEventListener("slotchange", () => {
382
+ updateResizeObserverObservation.call(this);
383
+ });
381
384
  }
382
385
 
383
386
  function checkAndRearrangeButtons() {
384
- if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
385
- calculateButtonBarDimensions.call(this);
386
- }
387
+ if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
388
+ calculateButtonBarDimensions.call(this);
389
+ }
387
390
 
388
- rearrangeButtons.call(this);
391
+ rearrangeButtons.call(this);
389
392
  }
390
393
 
391
394
  /**
@@ -393,58 +396,57 @@ function checkAndRearrangeButtons() {
393
396
  * @return {Object}
394
397
  */
395
398
  function rearrangeButtons() {
399
+ let sum = this[switchElementSymbol].offsetWidth;
400
+ const space = this[dimensionsSymbol].getVia("data.space");
401
+
402
+ const buttonReferences = this[dimensionsSymbol].getVia(
403
+ "data.buttonReferences",
404
+ );
405
+
406
+ for (const ref of buttonReferences) {
407
+ sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
408
+
409
+ let elements = getSlottedElements.call(
410
+ this,
411
+ '[data-monster-reference="' + ref + '"]',
412
+ null,
413
+ ); // null ↦ o
414
+ if (elements.size === 0) {
415
+ elements = getSlottedElements.call(
416
+ this,
417
+ '[data-monster-reference="' + ref + '"]',
418
+ "popper",
419
+ ); // null ↦ o
420
+ }
421
+
422
+ const nextValue = elements.values().next();
423
+ if (!nextValue) {
424
+ continue;
425
+ }
426
+
427
+ const element = nextValue?.value;
428
+ if (!(element instanceof HTMLElement)) {
429
+ continue;
430
+ }
431
+
432
+ const buttonLabel = element.innerText;
433
+
434
+ if (sum > space) {
435
+ element.setAttribute("slot", "popper");
436
+ } else {
437
+ element.removeAttribute("slot");
438
+ }
439
+ }
396
440
 
397
- let sum = this[switchElementSymbol].offsetWidth;
398
- const space = this[dimensionsSymbol].getVia("data.space");
399
-
400
- const buttonReferences = this[dimensionsSymbol].getVia(
401
- "data.buttonReferences",
402
- );
403
-
404
- for (const ref of buttonReferences) {
405
- sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
406
-
407
- let elements = getSlottedElements.call(
408
- this,
409
- '[data-monster-reference="' + ref + '"]',
410
- null,
411
- ); // null ↦ o
412
- if (elements.size === 0) {
413
- elements = getSlottedElements.call(
414
- this,
415
- '[data-monster-reference="' + ref + '"]',
416
- "popper",
417
- ); // null ↦ o
418
- }
419
-
420
- const nextValue = elements.values().next();
421
- if (!nextValue) {
422
- continue;
423
- }
424
-
425
- const element = nextValue?.value;
426
- if (!(element instanceof HTMLElement)) {
427
- continue;
428
- }
429
-
430
- const buttonLabel = element.innerText;
431
-
432
- if (sum > space) {
433
- element.setAttribute("slot", "popper");
434
- } else {
435
- element.removeAttribute("slot");
436
- }
437
- }
438
-
439
- const inVisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
440
- if (inVisibleButtons.size > 0) {
441
- this[switchElementSymbol].classList.remove("hidden");
442
- } else {
443
- this[switchElementSymbol].classList.add("hidden");
444
- setTimeout(() => {
445
- hide.call(this);
446
- }, 1);
447
- }
441
+ const inVisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
442
+ if (inVisibleButtons.size > 0) {
443
+ this[switchElementSymbol].classList.remove("hidden");
444
+ } else {
445
+ this[switchElementSymbol].classList.add("hidden");
446
+ setTimeout(() => {
447
+ hide.call(this);
448
+ }, 1);
449
+ }
448
450
  }
449
451
 
450
452
  /**
@@ -453,22 +455,22 @@ function rearrangeButtons() {
453
455
  * @return {number}
454
456
  */
455
457
  function calcBoxWidth(node) {
456
- const dim = getGlobal()?.getComputedStyle(node);
458
+ const dim = getGlobal()?.getComputedStyle(node);
457
459
  if (dim === null) {
458
- addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "no computed style");
459
- throw new Error("no computed style");
460
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "no computed style");
461
+ throw new Error("no computed style");
460
462
  }
461
- const bounding = node.getBoundingClientRect();
462
-
463
- return (
464
- convertToPixels(dim["border-left-width"]) +
465
- convertToPixels(dim["padding-left"]) +
466
- convertToPixels(dim["margin-left"]) +
467
- bounding["width"] +
468
- convertToPixels(dim["border-right-width"]) +
469
- convertToPixels(dim["margin-right"]) +
470
- convertToPixels(dim["padding-left"])
471
- );
463
+ const bounding = node.getBoundingClientRect();
464
+
465
+ return (
466
+ convertToPixels(dim["border-left-width"]) +
467
+ convertToPixels(dim["padding-left"]) +
468
+ convertToPixels(dim["margin-left"]) +
469
+ bounding["width"] +
470
+ convertToPixels(dim["border-right-width"]) +
471
+ convertToPixels(dim["margin-right"]) +
472
+ convertToPixels(dim["padding-left"])
473
+ );
472
474
  }
473
475
 
474
476
  /**
@@ -476,112 +478,112 @@ function calcBoxWidth(node) {
476
478
  * @return {Object}
477
479
  */
478
480
  function calculateButtonBarDimensions() {
479
- const computedStyle = getComputedStyle(this.parentElement);
480
- if (computedStyle === null) {
481
- throw new Error("no computed style");
482
- }
483
-
484
- let width = this.parentElement.clientWidth;
485
- if (computedStyle.getPropertyValue("box-sizing") !== "border-box") {
486
- width = computedStyle.getPropertyValue("width");
487
- this[dimensionsSymbol].setVia("data.space", convertToPixels(width));
488
- } else {
489
- let borderWidth = getComputedStyle(this).getPropertyValue(
490
- "--monster-border-width",
491
- );
492
- if (borderWidth === null || borderWidth === "") {
493
- borderWidth = "0px";
494
- }
495
-
496
- const borderWidthWithoutUnit = convertToPixels(borderWidth);
497
-
498
- // space to be allocated
499
- this[dimensionsSymbol].setVia(
500
- "data.space",
501
- width - 2 * borderWidthWithoutUnit,
502
- );
503
- }
504
-
505
- this[dimensionsSymbol].setVia("data.visible", !(width === 0));
506
-
507
- const buttonReferences = [];
508
-
509
- const visibleButtons = getSlottedElements.call(this, ":scope", null); // null ↦ o
510
-
511
- for (const [, button] of visibleButtons.entries()) {
512
- if (!button.hasAttribute("data-monster-reference")) {
513
- button.setAttribute("data-monster-reference", new ID("vb").toString());
514
- }
515
-
516
- const ref = button.getAttribute("data-monster-reference");
517
- if (ref === null) continue;
518
-
519
- buttonReferences.push(ref);
520
- this[dimensionsSymbol].setVia(
521
- `data.button.${ref}`,
522
- calcBoxWidth.call(this, button),
523
- );
524
- }
525
-
526
- const invisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
527
- for (const [, button] of invisibleButtons.entries()) {
528
- if (!button.hasAttribute("data-monster-reference")) {
529
- button.setAttribute("data-monster-reference", new ID("ib").toString());
530
- }
531
-
532
- const ref = button.getAttribute("data-monster-reference");
533
- if (ref === null) continue;
534
-
535
- if (ref.indexOf("ib") !== 0) {
536
- buttonReferences.push(ref);
537
- }
538
- }
539
-
540
- this[dimensionsSymbol].setVia("data.calculated", true);
541
- this[dimensionsSymbol].setVia("data.buttonReferences", buttonReferences);
481
+ const computedStyle = getComputedStyle(this.parentElement);
482
+ if (computedStyle === null) {
483
+ throw new Error("no computed style");
484
+ }
485
+
486
+ let width = this.parentElement.clientWidth;
487
+ if (computedStyle.getPropertyValue("box-sizing") !== "border-box") {
488
+ width = computedStyle.getPropertyValue("width");
489
+ this[dimensionsSymbol].setVia("data.space", convertToPixels(width));
490
+ } else {
491
+ let borderWidth = getComputedStyle(this).getPropertyValue(
492
+ "--monster-border-width",
493
+ );
494
+ if (borderWidth === null || borderWidth === "") {
495
+ borderWidth = "0px";
496
+ }
497
+
498
+ const borderWidthWithoutUnit = convertToPixels(borderWidth);
499
+
500
+ // space to be allocated
501
+ this[dimensionsSymbol].setVia(
502
+ "data.space",
503
+ width - 2 * borderWidthWithoutUnit,
504
+ );
505
+ }
506
+
507
+ this[dimensionsSymbol].setVia("data.visible", !(width === 0));
508
+
509
+ const buttonReferences = [];
510
+
511
+ const visibleButtons = getSlottedElements.call(this, ":scope", null); // null ↦ o
512
+
513
+ for (const [, button] of visibleButtons.entries()) {
514
+ if (!button.hasAttribute("data-monster-reference")) {
515
+ button.setAttribute("data-monster-reference", new ID("vb").toString());
516
+ }
517
+
518
+ const ref = button.getAttribute("data-monster-reference");
519
+ if (ref === null) continue;
520
+
521
+ buttonReferences.push(ref);
522
+ this[dimensionsSymbol].setVia(
523
+ `data.button.${ref}`,
524
+ calcBoxWidth.call(this, button),
525
+ );
526
+ }
527
+
528
+ const invisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
529
+ for (const [, button] of invisibleButtons.entries()) {
530
+ if (!button.hasAttribute("data-monster-reference")) {
531
+ button.setAttribute("data-monster-reference", new ID("ib").toString());
532
+ }
533
+
534
+ const ref = button.getAttribute("data-monster-reference");
535
+ if (ref === null) continue;
536
+
537
+ if (ref.indexOf("ib") !== 0) {
538
+ buttonReferences.push(ref);
539
+ }
540
+ }
541
+
542
+ this[dimensionsSymbol].setVia("data.calculated", true);
543
+ this[dimensionsSymbol].setVia("data.buttonReferences", buttonReferences);
542
544
  }
543
545
 
544
546
  /**
545
547
  * @private
546
548
  */
547
549
  function updateResizeObserverObservation() {
548
- this[resizeObserverSymbol].disconnect();
550
+ this[resizeObserverSymbol].disconnect();
549
551
 
550
- const slottedNodes = getSlottedElements.call(this);
551
- slottedNodes.forEach((node) => {
552
- this[resizeObserverSymbol].observe(node);
553
- });
552
+ const slottedNodes = getSlottedElements.call(this);
553
+ slottedNodes.forEach((node) => {
554
+ this[resizeObserverSymbol].observe(node);
555
+ });
554
556
 
555
- if (this.parentElement === null) return;
556
- this[resizeObserverSymbol].observe(this.parentElement);
557
+ if (this.parentElement === null) return;
558
+ this[resizeObserverSymbol].observe(this.parentElement);
557
559
  }
558
560
 
559
561
  /**
560
562
  * @private
561
563
  */
562
564
  function disconnectResizeObserver() {
563
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
564
- this[resizeObserverSymbol].disconnect();
565
- }
565
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
566
+ this[resizeObserverSymbol].disconnect();
567
+ }
566
568
  }
567
569
 
568
570
  /**
569
571
  * @private
570
572
  */
571
573
  function toggle() {
572
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
573
- hide.call(this);
574
- } else {
575
- show.call(this);
576
- }
574
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
575
+ hide.call(this);
576
+ } else {
577
+ show.call(this);
578
+ }
577
579
  }
578
580
 
579
581
  /**
580
582
  * @private
581
583
  */
582
584
  function hide() {
583
- this[popperElementSymbol].style.display = "none";
584
- removeAttributeToken(this[controlElementSymbol], "class", "open");
585
+ this[popperElementSymbol].style.display = "none";
586
+ removeAttributeToken(this[controlElementSymbol], "class", "open");
585
587
  }
586
588
 
587
589
  /**
@@ -589,40 +591,40 @@ function hide() {
589
591
  * @this PopperButton
590
592
  */
591
593
  function show() {
592
- if (this.getOption("disabled", false) === true) {
593
- return;
594
- }
594
+ if (this.getOption("disabled", false) === true) {
595
+ return;
596
+ }
595
597
 
596
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
597
- return;
598
- }
598
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
599
+ return;
600
+ }
599
601
 
600
- this[popperElementSymbol].style.visibility = "hidden";
601
- this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
602
+ this[popperElementSymbol].style.visibility = "hidden";
603
+ this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
602
604
 
603
- addAttributeToken(this[controlElementSymbol], "class", "open");
605
+ addAttributeToken(this[controlElementSymbol], "class", "open");
604
606
 
605
- updatePopper.call(this);
607
+ updatePopper.call(this);
606
608
  }
607
609
 
608
610
  /**
609
611
  * @private
610
612
  */
611
613
  function updatePopper() {
612
- if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
613
- return;
614
- }
615
-
616
- if (this.getOption("disabled", false) === true) {
617
- return;
618
- }
619
-
620
- positionPopper.call(
621
- this,
622
- this[switchElementSymbol],
623
- this[popperElementSymbol],
624
- this.getOption("popper", {}),
625
- );
614
+ if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
615
+ return;
616
+ }
617
+
618
+ if (this.getOption("disabled", false) === true) {
619
+ return;
620
+ }
621
+
622
+ positionPopper.call(
623
+ this,
624
+ this[switchElementSymbol],
625
+ this[popperElementSymbol],
626
+ this.getOption("popper", {}),
627
+ );
626
628
  }
627
629
 
628
630
  /**
@@ -631,34 +633,34 @@ function updatePopper() {
631
633
  * @throws {Error} no shadow-root is defined
632
634
  */
633
635
  function initControlReferences() {
634
- if (!this.shadowRoot) {
635
- throw new Error("no shadow-root is defined");
636
- }
637
-
638
- this[controlElementSymbol] = this.shadowRoot.querySelector(
639
- `[${ATTRIBUTE_ROLE}=control]`,
640
- );
641
- this[buttonBarElementSymbol] = this.shadowRoot.querySelector(
642
- `[${ATTRIBUTE_ROLE}=button-bar]`,
643
- );
644
- this[popperElementSymbol] = this.shadowRoot.querySelector(
645
- `[${ATTRIBUTE_ROLE}=popper]`,
646
- );
647
- this[popperNavElementSymbol] = this.shadowRoot.querySelector(
648
- `[${ATTRIBUTE_ROLE}=popper-nav]`,
649
- );
650
- this[switchElementSymbol] = this.shadowRoot.querySelector(
651
- `[${ATTRIBUTE_ROLE}=switch]`,
652
- );
653
-
654
- this[buttonBarSlotElementSymbol] = null;
655
- if (this[buttonBarElementSymbol])
656
- this[buttonBarSlotElementSymbol] =
657
- this[buttonBarElementSymbol].querySelector(`slot`);
658
- this[popperSlotElementSymbol] = null;
659
- if (this[popperElementSymbol])
660
- this[popperSlotElementSymbol] =
661
- this[popperElementSymbol].querySelector(`slot`);
636
+ if (!this.shadowRoot) {
637
+ throw new Error("no shadow-root is defined");
638
+ }
639
+
640
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
641
+ `[${ATTRIBUTE_ROLE}=control]`,
642
+ );
643
+ this[buttonBarElementSymbol] = this.shadowRoot.querySelector(
644
+ `[${ATTRIBUTE_ROLE}=button-bar]`,
645
+ );
646
+ this[popperElementSymbol] = this.shadowRoot.querySelector(
647
+ `[${ATTRIBUTE_ROLE}=popper]`,
648
+ );
649
+ this[popperNavElementSymbol] = this.shadowRoot.querySelector(
650
+ `[${ATTRIBUTE_ROLE}=popper-nav]`,
651
+ );
652
+ this[switchElementSymbol] = this.shadowRoot.querySelector(
653
+ `[${ATTRIBUTE_ROLE}=switch]`,
654
+ );
655
+
656
+ this[buttonBarSlotElementSymbol] = null;
657
+ if (this[buttonBarElementSymbol])
658
+ this[buttonBarSlotElementSymbol] =
659
+ this[buttonBarElementSymbol].querySelector(`slot`);
660
+ this[popperSlotElementSymbol] = null;
661
+ if (this[popperElementSymbol])
662
+ this[popperSlotElementSymbol] =
663
+ this[popperElementSymbol].querySelector(`slot`);
662
664
  }
663
665
 
664
666
  /**
@@ -668,36 +670,36 @@ function initControlReferences() {
668
670
  *
669
671
  */
670
672
  function initButtonBar() {
671
- if (!this.shadowRoot) {
672
- throw new Error("no shadow-root is defined");
673
- }
673
+ if (!this.shadowRoot) {
674
+ throw new Error("no shadow-root is defined");
675
+ }
674
676
 
675
- return new Processing(() => {
676
- checkAndRearrangeButtons.call(this);
677
- }).run();
677
+ return new Processing(() => {
678
+ checkAndRearrangeButtons.call(this);
679
+ }).run();
678
680
  }
679
681
 
680
682
  /**
681
683
  * @private
682
684
  */
683
685
  function initPopperSwitch() {
684
- /**
685
- * @param {Event} event
686
- */
687
- this[popperSwitchEventHandler] = (event) => {
688
- const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "switch");
689
-
690
- if (element instanceof HTMLButtonElement) {
691
- toggle.call(this);
692
- }
693
- };
694
-
695
- for (const type of ["click", "touch"]) {
696
- this[switchElementSymbol].addEventListener(
697
- type,
698
- this[popperSwitchEventHandler],
699
- );
700
- }
686
+ /**
687
+ * @param {Event} event
688
+ */
689
+ this[popperSwitchEventHandler] = (event) => {
690
+ const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "switch");
691
+
692
+ if (element instanceof HTMLButtonElement) {
693
+ toggle.call(this);
694
+ }
695
+ };
696
+
697
+ for (const type of ["click", "touch"]) {
698
+ this[switchElementSymbol].addEventListener(
699
+ type,
700
+ this[popperSwitchEventHandler],
701
+ );
702
+ }
701
703
  }
702
704
 
703
705
  /**
@@ -705,8 +707,8 @@ function initPopperSwitch() {
705
707
  * @return {string}
706
708
  */
707
709
  function getTemplate() {
708
- // language=HTML
709
- return `
710
+ // language=HTML
711
+ return `
710
712
  <div data-monster-role="control" part="control">
711
713
  <div data-monster-role="button-bar">
712
714
  <slot></slot>