@schukai/monster 3.58.0 → 3.58.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,34 +4,34 @@
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_ROLE } from "../../dom/constants.mjs";
13
+ import {ATTRIBUTE_ERRORMESSAGE, ATTRIBUTE_ROLE} from "../../dom/constants.mjs";
14
14
  import {
15
- assembleMethodSymbol,
16
- getSlottedElements,
17
- registerCustomElement,
15
+ assembleMethodSymbol,
16
+ getSlottedElements,
17
+ registerCustomElement,
18
18
  } from "../../dom/customelement.mjs";
19
19
  import {
20
- CustomElement,
21
- attributeObserverSymbol,
20
+ CustomElement,
21
+ attributeObserverSymbol,
22
22
  } 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 };
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};
35
35
 
36
36
  /**
37
37
  * @private
@@ -148,154 +148,154 @@ const ATTRIBUTE_POPPER_POSITION = "data-monster-popper-position";
148
148
  * @fires Monster.Components.Form.event:monster-fetched
149
149
  */
150
150
  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
- }
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
+ }
299
299
  }
300
300
 
301
301
  /**
@@ -304,88 +304,88 @@ class ButtonBar extends CustomElement {
304
304
  * @returns {*}
305
305
  */
306
306
  function initDefaultsFromAttributes(obj) {
307
- if (this.hasAttribute(ATTRIBUTE_POPPER_POSITION)) {
308
- obj.popper.placement = this.getAttribute(ATTRIBUTE_POPPER_POSITION);
309
- }
307
+ if (this.hasAttribute(ATTRIBUTE_POPPER_POSITION)) {
308
+ obj.popper.placement = this.getAttribute(ATTRIBUTE_POPPER_POSITION);
309
+ }
310
310
 
311
- return obj;
311
+ return obj;
312
312
  }
313
313
 
314
314
  /**
315
315
  * @private
316
316
  */
317
- 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);
317
+ 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);
375
375
  }
376
376
 
377
377
  function initSlotChangedHandler() {
378
- this[buttonBarElementSymbol].addEventListener("slotchange", () => {
379
- updateResizeObserverObservation.call(this);
380
- });
378
+ this[buttonBarElementSymbol].addEventListener("slotchange", () => {
379
+ updateResizeObserverObservation.call(this);
380
+ });
381
381
  }
382
382
 
383
383
  function checkAndRearrangeButtons() {
384
- if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
385
- calculateButtonBarDimensions.call(this);
386
- }
384
+ if (this[dimensionsSymbol].getVia("data.calculated", false) !== true) {
385
+ calculateButtonBarDimensions.call(this);
386
+ }
387
387
 
388
- rearrangeButtons.call(this);
388
+ rearrangeButtons.call(this);
389
389
  }
390
390
 
391
391
  /**
@@ -393,59 +393,58 @@ function checkAndRearrangeButtons() {
393
393
  * @return {Object}
394
394
  */
395
395
  function rearrangeButtons() {
396
- const switchWidth = this[switchElementSymbol].offsetWidth;
397
-
398
- let sum = switchWidth;
399
- const space = this[dimensionsSymbol].getVia("data.space");
400
-
401
- const buttonReferences = this[dimensionsSymbol].getVia(
402
- "data.buttonReferences",
403
- );
404
-
405
- for (const ref of buttonReferences) {
406
- sum += this[dimensionsSymbol].getVia(`data.button.${ref}`);
407
-
408
- let elements = getSlottedElements.call(
409
- this,
410
- '[data-monster-reference="' + ref + '"]',
411
- null,
412
- ); // null ↦ o
413
- if (elements.size === 0) {
414
- elements = getSlottedElements.call(
415
- this,
416
- '[data-monster-reference="' + ref + '"]',
417
- "popper",
418
- ); // null ↦ o
419
- }
420
-
421
- const nextValue = elements.values().next();
422
- if (!nextValue) {
423
- continue;
424
- }
425
-
426
- const element = nextValue?.value;
427
- if (!(element instanceof HTMLElement)) {
428
- continue;
429
- }
430
-
431
- const buttonLabel = element.innerText;
432
-
433
- if (sum > space) {
434
- element.setAttribute("slot", "popper");
435
- } else {
436
- element.removeAttribute("slot");
437
- }
438
- }
439
396
 
440
- const inVisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
441
- if (inVisibleButtons.size > 0) {
442
- this[switchElementSymbol].classList.remove("hidden");
443
- } else {
444
- this[switchElementSymbol].classList.add("hidden");
445
- setTimeout(() => {
446
- hide.call(this);
447
- }, 1);
448
- }
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
+ }
449
448
  }
450
449
 
451
450
  /**
@@ -454,18 +453,22 @@ function rearrangeButtons() {
454
453
  * @return {number}
455
454
  */
456
455
  function calcBoxWidth(node) {
457
- const dim = getGlobal("window").getComputedStyle(node);
458
- const bounding = node.getBoundingClientRect();
459
-
460
- return (
461
- convertToPixels(dim["border-left-width"]) +
462
- convertToPixels(dim["padding-left"]) +
463
- convertToPixels(dim["margin-left"]) +
464
- bounding["width"] +
465
- convertToPixels(dim["border-right-width"]) +
466
- convertToPixels(dim["margin-right"]) +
467
- convertToPixels(dim["padding-left"])
468
- );
456
+ const dim = getGlobal()?.getComputedStyle(node);
457
+ if (dim === null) {
458
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, "no computed style");
459
+ throw new Error("no computed style");
460
+ }
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
+ );
469
472
  }
470
473
 
471
474
  /**
@@ -473,112 +476,112 @@ function calcBoxWidth(node) {
473
476
  * @return {Object}
474
477
  */
475
478
  function calculateButtonBarDimensions() {
476
- const computedStyle = getComputedStyle(this.parentElement);
477
- if (computedStyle === null) {
478
- throw new Error("no computed style");
479
- }
480
-
481
- let width = this.parentElement.clientWidth;
482
- if (computedStyle.getPropertyValue("box-sizing") !== "border-box") {
483
- width = computedStyle.getPropertyValue("width");
484
- this[dimensionsSymbol].setVia("data.space", convertToPixels(width));
485
- } else {
486
- let borderWidth = getComputedStyle(this).getPropertyValue(
487
- "--monster-border-width",
488
- );
489
- if (borderWidth === null || borderWidth === "") {
490
- borderWidth = "0px";
491
- }
492
-
493
- const borderWidthWithoutUnit = convertToPixels(borderWidth);
494
-
495
- // space to be allocated
496
- this[dimensionsSymbol].setVia(
497
- "data.space",
498
- width - 2 * borderWidthWithoutUnit,
499
- );
500
- }
501
-
502
- this[dimensionsSymbol].setVia("data.visible", !(width === 0));
503
-
504
- const buttonReferences = [];
505
-
506
- const visibleButtons = getSlottedElements.call(this, ":scope", null); // null ↦ o
507
-
508
- for (const [, button] of visibleButtons.entries()) {
509
- if (!button.hasAttribute("data-monster-reference")) {
510
- button.setAttribute("data-monster-reference", new ID("vb").toString());
511
- }
512
-
513
- const ref = button.getAttribute("data-monster-reference");
514
- if (ref === null) continue;
515
-
516
- buttonReferences.push(ref);
517
- this[dimensionsSymbol].setVia(
518
- `data.button.${ref}`,
519
- calcBoxWidth.call(this, button),
520
- );
521
- }
522
-
523
- const invisibleButtons = getSlottedElements.call(this, ":scope", "popper"); // null ↦ o
524
- for (const [, button] of invisibleButtons.entries()) {
525
- if (!button.hasAttribute("data-monster-reference")) {
526
- button.setAttribute("data-monster-reference", new ID("ib").toString());
527
- }
528
-
529
- const ref = button.getAttribute("data-monster-reference");
530
- if (ref === null) continue;
531
-
532
- if (ref.indexOf("ib") !== 0) {
533
- buttonReferences.push(ref);
534
- }
535
- }
536
-
537
- this[dimensionsSymbol].setVia("data.calculated", true);
538
- this[dimensionsSymbol].setVia("data.buttonReferences", buttonReferences);
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);
539
542
  }
540
543
 
541
544
  /**
542
545
  * @private
543
546
  */
544
547
  function updateResizeObserverObservation() {
545
- this[resizeObserverSymbol].disconnect();
548
+ this[resizeObserverSymbol].disconnect();
546
549
 
547
- const slottedNodes = getSlottedElements.call(this);
548
- slottedNodes.forEach((node) => {
549
- this[resizeObserverSymbol].observe(node);
550
- });
550
+ const slottedNodes = getSlottedElements.call(this);
551
+ slottedNodes.forEach((node) => {
552
+ this[resizeObserverSymbol].observe(node);
553
+ });
551
554
 
552
- if (this.parentElement === null) return;
553
- this[resizeObserverSymbol].observe(this.parentElement);
555
+ if (this.parentElement === null) return;
556
+ this[resizeObserverSymbol].observe(this.parentElement);
554
557
  }
555
558
 
556
559
  /**
557
560
  * @private
558
561
  */
559
562
  function disconnectResizeObserver() {
560
- if (this[resizeObserverSymbol] instanceof ResizeObserver) {
561
- this[resizeObserverSymbol].disconnect();
562
- }
563
+ if (this[resizeObserverSymbol] instanceof ResizeObserver) {
564
+ this[resizeObserverSymbol].disconnect();
565
+ }
563
566
  }
564
567
 
565
568
  /**
566
569
  * @private
567
570
  */
568
571
  function toggle() {
569
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
570
- hide.call(this);
571
- } else {
572
- show.call(this);
573
- }
572
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
573
+ hide.call(this);
574
+ } else {
575
+ show.call(this);
576
+ }
574
577
  }
575
578
 
576
579
  /**
577
580
  * @private
578
581
  */
579
582
  function hide() {
580
- this[popperElementSymbol].style.display = "none";
581
- removeAttributeToken(this[controlElementSymbol], "class", "open");
583
+ this[popperElementSymbol].style.display = "none";
584
+ removeAttributeToken(this[controlElementSymbol], "class", "open");
582
585
  }
583
586
 
584
587
  /**
@@ -586,40 +589,40 @@ function hide() {
586
589
  * @this PopperButton
587
590
  */
588
591
  function show() {
589
- if (this.getOption("disabled", false) === true) {
590
- return;
591
- }
592
+ if (this.getOption("disabled", false) === true) {
593
+ return;
594
+ }
592
595
 
593
- if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
594
- return;
595
- }
596
+ if (this[popperElementSymbol].style.display === STYLE_DISPLAY_MODE_BLOCK) {
597
+ return;
598
+ }
596
599
 
597
- this[popperElementSymbol].style.visibility = "hidden";
598
- this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
600
+ this[popperElementSymbol].style.visibility = "hidden";
601
+ this[popperElementSymbol].style.display = STYLE_DISPLAY_MODE_BLOCK;
599
602
 
600
- addAttributeToken(this[controlElementSymbol], "class", "open");
603
+ addAttributeToken(this[controlElementSymbol], "class", "open");
601
604
 
602
- updatePopper.call(this);
605
+ updatePopper.call(this);
603
606
  }
604
607
 
605
608
  /**
606
609
  * @private
607
610
  */
608
611
  function updatePopper() {
609
- if (this[popperElementSymbol].style.display !== STYLE_DISPLAY_MODE_BLOCK) {
610
- return;
611
- }
612
-
613
- if (this.getOption("disabled", false) === true) {
614
- return;
615
- }
616
-
617
- positionPopper.call(
618
- this,
619
- this[switchElementSymbol],
620
- this[popperElementSymbol],
621
- this.getOption("popper", {}),
622
- );
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
+ );
623
626
  }
624
627
 
625
628
  /**
@@ -628,34 +631,34 @@ function updatePopper() {
628
631
  * @throws {Error} no shadow-root is defined
629
632
  */
630
633
  function initControlReferences() {
631
- if (!this.shadowRoot) {
632
- throw new Error("no shadow-root is defined");
633
- }
634
-
635
- this[controlElementSymbol] = this.shadowRoot.querySelector(
636
- `[${ATTRIBUTE_ROLE}=control]`,
637
- );
638
- this[buttonBarElementSymbol] = this.shadowRoot.querySelector(
639
- `[${ATTRIBUTE_ROLE}=button-bar]`,
640
- );
641
- this[popperElementSymbol] = this.shadowRoot.querySelector(
642
- `[${ATTRIBUTE_ROLE}=popper]`,
643
- );
644
- this[popperNavElementSymbol] = this.shadowRoot.querySelector(
645
- `[${ATTRIBUTE_ROLE}=popper-nav]`,
646
- );
647
- this[switchElementSymbol] = this.shadowRoot.querySelector(
648
- `[${ATTRIBUTE_ROLE}=switch]`,
649
- );
650
-
651
- this[buttonBarSlotElementSymbol] = null;
652
- if (this[buttonBarElementSymbol])
653
- this[buttonBarSlotElementSymbol] =
654
- this[buttonBarElementSymbol].querySelector(`slot`);
655
- this[popperSlotElementSymbol] = null;
656
- if (this[popperElementSymbol])
657
- this[popperSlotElementSymbol] =
658
- this[popperElementSymbol].querySelector(`slot`);
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`);
659
662
  }
660
663
 
661
664
  /**
@@ -665,36 +668,36 @@ function initControlReferences() {
665
668
  *
666
669
  */
667
670
  function initButtonBar() {
668
- if (!this.shadowRoot) {
669
- throw new Error("no shadow-root is defined");
670
- }
671
+ if (!this.shadowRoot) {
672
+ throw new Error("no shadow-root is defined");
673
+ }
671
674
 
672
- return new Processing(() => {
673
- checkAndRearrangeButtons.call(this);
674
- }).run();
675
+ return new Processing(() => {
676
+ checkAndRearrangeButtons.call(this);
677
+ }).run();
675
678
  }
676
679
 
677
680
  /**
678
681
  * @private
679
682
  */
680
683
  function initPopperSwitch() {
681
- /**
682
- * @param {Event} event
683
- */
684
- this[popperSwitchEventHandler] = (event) => {
685
- const element = findTargetElementFromEvent(event, ATTRIBUTE_ROLE, "switch");
686
-
687
- if (element instanceof HTMLButtonElement) {
688
- toggle.call(this);
689
- }
690
- };
691
-
692
- for (const type of ["click", "touch"]) {
693
- this[switchElementSymbol].addEventListener(
694
- type,
695
- this[popperSwitchEventHandler],
696
- );
697
- }
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
+ }
698
701
  }
699
702
 
700
703
  /**
@@ -702,8 +705,8 @@ function initPopperSwitch() {
702
705
  * @return {string}
703
706
  */
704
707
  function getTemplate() {
705
- // language=HTML
706
- return `
708
+ // language=HTML
709
+ return `
707
710
  <div data-monster-role="control" part="control">
708
711
  <div data-monster-role="button-bar">
709
712
  <slot></slot>