@schukai/monster 4.124.0 → 4.124.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.
@@ -19,15 +19,15 @@ import { ProxyObserver } from "../../types/proxyobserver.mjs";
19
19
 
20
20
  import { addAttributeToken } from "../../dom/attributes.mjs";
21
21
  import {
22
- assembleMethodSymbol,
23
- registerCustomElement,
24
- updaterTransformerMethodsSymbol,
22
+ assembleMethodSymbol,
23
+ registerCustomElement,
24
+ updaterTransformerMethodsSymbol,
25
25
  } from "../../dom/customelement.mjs";
26
26
  import { isFunction, isObject } from "../../types/is.mjs";
27
27
  import { ToggleSwitchStyleSheet } from "./stylesheet/toggle-switch.mjs";
28
28
  import {
29
- ATTRIBUTE_ERRORMESSAGE,
30
- ATTRIBUTE_ROLE,
29
+ ATTRIBUTE_ERRORMESSAGE,
30
+ ATTRIBUTE_ROLE,
31
31
  } from "../../dom/constants.mjs";
32
32
  import { getWindow } from "../../dom/util.mjs";
33
33
  import { fireCustomEvent, fireEvent } from "../../dom/events.mjs";
@@ -68,382 +68,382 @@ export const STATE_OFF = "off";
68
68
  * @fires monster-changed
69
69
  */
70
70
  class ToggleSwitch extends CustomControl {
71
- /**
72
- * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
73
- * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
74
- *
75
- * The individual configuration values can be found in the table.
76
- *
77
- * @property {string} value=current value of the element
78
- * @property {Boolean} disabled Disabled state
79
- * @property {Object} classes
80
- * @property {string} classes.on specifies the class for the on state.
81
- * @property {string} classes.off specifies the class for the off state.
82
- * @property {Object} values
83
- * @property {string} values.off specifies the value of the element if it is not selected
84
- * @property {Object} labels
85
- * @property {string} labels.on specifies the label for the on state.
86
- * @property {string} labels.off specifies the label for the off state.
87
- * @property {string} actions
88
- * @property {string} actions.on specifies the action for the on state.
89
- * @property {string} actions.off specifies the action for the off state.
90
- * @property {Object} templates
91
- * @property {string} templates.main the main template used by the control.
92
- */
93
- get defaults() {
94
- return Object.assign({}, super.defaults, {
95
- value: null,
96
- disabled: false,
97
- classes: {
98
- on: "monster-theme-on",
99
- off: "monster-theme-off",
100
- handle: "monster-theme-primary-1",
101
- error: "monster-theme-error-1",
102
- },
103
- values: {
104
- on: "on",
105
- off: "off",
106
- },
107
- labels: {
108
- toggleSwitchOn: "✔",
109
- toggleSwitchOff: "×",
110
- },
111
- templates: {
112
- main: getTemplate(),
113
- },
114
- actions: {
115
- on: () => {},
116
- off: () => {},
117
- },
118
- });
119
- }
120
-
121
- /**
122
- * @return {void}
123
- */
124
- [assembleMethodSymbol]() {
125
- const self = this;
126
- super[assembleMethodSymbol]();
127
-
128
- initDisabledSync.call(this);
129
- initControlReferences.call(this);
130
- initEventHandler.call(this);
131
-
132
- setTimeout(() => {
133
- /**
134
- * init value to off
135
- * if the value was not defined before inserting it into the HTML
136
- */
137
- if (self.getOption("value") === null) {
138
- self.setOption("value", self.getOption("values.off"));
139
- }
140
-
141
- /**
142
- * value from attribute
143
- */
144
- if (self.hasAttribute("value")) {
145
- self.setOption("value", self.getAttribute("value"));
146
- }
147
-
148
- /**
149
- * validate value
150
- */
151
- validateAndSetValue.call(self);
152
-
153
- // this state is a getter
154
- if (this.state === STATE_ON) {
155
- toggleOn.call(self);
156
- } else {
157
- toggleOff.call(self);
158
- }
159
- }, 0);
160
- }
161
-
162
- /**
163
- * updater transformer methods for pipe
164
- *
165
- * @return {function}
166
- */
167
- [updaterTransformerMethodsSymbol]() {
168
- return {
169
- "state-callback": () => {
170
- return this.state;
171
- },
172
- };
173
- }
174
-
175
- /**
176
- * @return [CSSStyleSheet]
177
- */
178
- static getCSSStyleSheet() {
179
- return [ToggleSwitchStyleSheet];
180
- }
181
-
182
- /**
183
- * toggle switch
184
- *
185
- * ```
186
- * e = document.querySelector('monster-toggle-switch');
187
- * e.click()
188
- * ```
189
- */
190
- click() {
191
- this.toggle();
192
- }
193
-
194
- /**
195
- * toggle switch on/off
196
- *
197
- * ```
198
- * e = document.querySelector('monster-toggle-switch');
199
- * e.toggle()
200
- * ```
201
- *
202
- * @return {ToggleSwitch}
203
- */
204
- toggle() {
205
- if (this.hasAttribute("disabled") || this.getOption("disabled", false)) {
206
- return this;
207
- }
208
- if (this.getOption("value") === this.getOption("values.on")) {
209
- return this.toggleOff();
210
- }
211
- return this.toggleOn();
212
- }
213
-
214
- /**
215
- * toggle switch on
216
- *
217
- * ```
218
- * e = document.querySelector('monster-toggle-switch');
219
- * e.toggleOn()
220
- * ```
221
- *
222
- * @return {ToggleSwitch}
223
- */
224
- toggleOn() {
225
- this.setOption("value", this.getOption("values.on"));
226
- fireEvent(this, "change");
227
- fireCustomEvent(this, "monster-change", { value: this.value });
228
- fireCustomEvent(this, "monster-changed", { value: this.value });
229
- return this;
230
- }
231
-
232
- /**
233
- * toggle switch off
234
- *
235
- * ```
236
- * e = document.querySelector('monster-toggle-switch');
237
- * e.toggleOff()
238
- * ```
239
- *
240
- * @return {ToggleSwitch}
241
- */
242
- toggleOff() {
243
- this.setOption("value", this.getOption("values.off"));
244
- fireEvent(this, "change");
245
- fireCustomEvent(this, "monster-change", { value: this.value });
246
- fireCustomEvent(this, "monster-changed", { value: this.value });
247
- return this;
248
- }
249
-
250
- /**
251
- * returns the status of the element
252
- *
253
- * ```
254
- * e = document.querySelector('monster-toggle-switch');
255
- * console.log(e.state)
256
- * // ↦ off
257
- * ```
258
- *
259
- * @return {string}
260
- */
261
- get state() {
262
- return this.getOption("value") === this.getOption("values.on")
263
- ? STATE_ON
264
- : STATE_OFF;
265
- }
266
-
267
- /**
268
- * The current value of the Switch
269
- *
270
- * ```
271
- * e = document.querySelector('monster-toggle-switch');
272
- * console.log(e.value)
273
- * // ↦ on
274
- * ```
275
- *
276
- * @return {string}
277
- */
278
- get value() {
279
- return this.getOption("value");
280
- }
281
-
282
- /**
283
- * Set value
284
- *
285
- * ```
286
- * e = document.querySelector('monster-toggle-switch');
287
- * e.value="on"
288
- * ```
289
- *
290
- * @property {string} value
291
- */
292
- set value(value) {
293
- const normalized = normalizeToggleValue.call(this, value);
294
- if (
295
- normalized === this.getOption("values.on") ||
296
- normalized === this.getOption("values.off")
297
- ) {
298
- if (this.getOption("value") !== normalized) {
299
- this.setOption("value", normalized);
300
- }
301
- return;
302
- }
303
-
304
- addErrorAttribute(
305
- this,
306
- 'The value "' +
307
- value +
308
- '" must be "' +
309
- this.getOption("values.on") +
310
- '" or "' +
311
- this.getOption("values.off"),
312
- );
313
-
314
- showError.call(this);
315
- }
316
-
317
- /**
318
- * This method is called by the `instanceof` operator.
319
- * @return {symbol}
320
- */
321
- static get [instanceSymbol]() {
322
- return Symbol.for(
323
- "@schukai/monster/components/form/toggle-switch@@instance",
324
- );
325
- }
326
-
327
- /**
328
- *
329
- * @returns {string}
330
- */
331
- static getTag() {
332
- return "monster-toggle-switch";
333
- }
71
+ /**
72
+ * To set the options via the HTML tag, the attribute `data-monster-options` must be used.
73
+ * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
74
+ *
75
+ * The individual configuration values can be found in the table.
76
+ *
77
+ * @property {string} value=current value of the element
78
+ * @property {Boolean} disabled Disabled state
79
+ * @property {Object} classes
80
+ * @property {string} classes.on specifies the class for the on state.
81
+ * @property {string} classes.off specifies the class for the off state.
82
+ * @property {Object} values
83
+ * @property {string} values.off specifies the value of the element if it is not selected
84
+ * @property {Object} labels
85
+ * @property {string} labels.on specifies the label for the on state.
86
+ * @property {string} labels.off specifies the label for the off state.
87
+ * @property {string} actions
88
+ * @property {string} actions.on specifies the action for the on state.
89
+ * @property {string} actions.off specifies the action for the off state.
90
+ * @property {Object} templates
91
+ * @property {string} templates.main the main template used by the control.
92
+ */
93
+ get defaults() {
94
+ return Object.assign({}, super.defaults, {
95
+ value: null,
96
+ disabled: false,
97
+ classes: {
98
+ on: "monster-theme-on",
99
+ off: "monster-theme-off",
100
+ handle: "monster-theme-primary-1",
101
+ error: "monster-theme-error-1",
102
+ },
103
+ values: {
104
+ on: "on",
105
+ off: "off",
106
+ },
107
+ labels: {
108
+ toggleSwitchOn: "✔",
109
+ toggleSwitchOff: "×",
110
+ },
111
+ templates: {
112
+ main: getTemplate(),
113
+ },
114
+ actions: {
115
+ on: () => {},
116
+ off: () => {},
117
+ },
118
+ });
119
+ }
120
+
121
+ /**
122
+ * @return {void}
123
+ */
124
+ [assembleMethodSymbol]() {
125
+ const self = this;
126
+ super[assembleMethodSymbol]();
127
+
128
+ initDisabledSync.call(this);
129
+ initControlReferences.call(this);
130
+ initEventHandler.call(this);
131
+
132
+ setTimeout(() => {
133
+ /**
134
+ * init value to off
135
+ * if the value was not defined before inserting it into the HTML
136
+ */
137
+ if (self.getOption("value") === null) {
138
+ self.setOption("value", self.getOption("values.off"));
139
+ }
140
+
141
+ /**
142
+ * value from attribute
143
+ */
144
+ if (self.hasAttribute("value")) {
145
+ self.setOption("value", self.getAttribute("value"));
146
+ }
147
+
148
+ /**
149
+ * validate value
150
+ */
151
+ validateAndSetValue.call(self);
152
+
153
+ // this state is a getter
154
+ if (this.state === STATE_ON) {
155
+ toggleOn.call(self);
156
+ } else {
157
+ toggleOff.call(self);
158
+ }
159
+ }, 0);
160
+ }
161
+
162
+ /**
163
+ * updater transformer methods for pipe
164
+ *
165
+ * @return {function}
166
+ */
167
+ [updaterTransformerMethodsSymbol]() {
168
+ return {
169
+ "state-callback": () => {
170
+ return this.state;
171
+ },
172
+ };
173
+ }
174
+
175
+ /**
176
+ * @return [CSSStyleSheet]
177
+ */
178
+ static getCSSStyleSheet() {
179
+ return [ToggleSwitchStyleSheet];
180
+ }
181
+
182
+ /**
183
+ * toggle switch
184
+ *
185
+ * ```
186
+ * e = document.querySelector('monster-toggle-switch');
187
+ * e.click()
188
+ * ```
189
+ */
190
+ click() {
191
+ this.toggle();
192
+ }
193
+
194
+ /**
195
+ * toggle switch on/off
196
+ *
197
+ * ```
198
+ * e = document.querySelector('monster-toggle-switch');
199
+ * e.toggle()
200
+ * ```
201
+ *
202
+ * @return {ToggleSwitch}
203
+ */
204
+ toggle() {
205
+ if (this.hasAttribute("disabled") || this.getOption("disabled", false)) {
206
+ return this;
207
+ }
208
+ if (this.getOption("value") === this.getOption("values.on")) {
209
+ return this.toggleOff();
210
+ }
211
+ return this.toggleOn();
212
+ }
213
+
214
+ /**
215
+ * toggle switch on
216
+ *
217
+ * ```
218
+ * e = document.querySelector('monster-toggle-switch');
219
+ * e.toggleOn()
220
+ * ```
221
+ *
222
+ * @return {ToggleSwitch}
223
+ */
224
+ toggleOn() {
225
+ this.setOption("value", this.getOption("values.on"));
226
+ fireEvent(this, "change");
227
+ fireCustomEvent(this, "monster-change", { value: this.value });
228
+ fireCustomEvent(this, "monster-changed", { value: this.value });
229
+ return this;
230
+ }
231
+
232
+ /**
233
+ * toggle switch off
234
+ *
235
+ * ```
236
+ * e = document.querySelector('monster-toggle-switch');
237
+ * e.toggleOff()
238
+ * ```
239
+ *
240
+ * @return {ToggleSwitch}
241
+ */
242
+ toggleOff() {
243
+ this.setOption("value", this.getOption("values.off"));
244
+ fireEvent(this, "change");
245
+ fireCustomEvent(this, "monster-change", { value: this.value });
246
+ fireCustomEvent(this, "monster-changed", { value: this.value });
247
+ return this;
248
+ }
249
+
250
+ /**
251
+ * returns the status of the element
252
+ *
253
+ * ```
254
+ * e = document.querySelector('monster-toggle-switch');
255
+ * console.log(e.state)
256
+ * // ↦ off
257
+ * ```
258
+ *
259
+ * @return {string}
260
+ */
261
+ get state() {
262
+ return this.getOption("value") === this.getOption("values.on")
263
+ ? STATE_ON
264
+ : STATE_OFF;
265
+ }
266
+
267
+ /**
268
+ * The current value of the Switch
269
+ *
270
+ * ```
271
+ * e = document.querySelector('monster-toggle-switch');
272
+ * console.log(e.value)
273
+ * // ↦ on
274
+ * ```
275
+ *
276
+ * @return {string}
277
+ */
278
+ get value() {
279
+ return this.getOption("value");
280
+ }
281
+
282
+ /**
283
+ * Set value
284
+ *
285
+ * ```
286
+ * e = document.querySelector('monster-toggle-switch');
287
+ * e.value="on"
288
+ * ```
289
+ *
290
+ * @property {string} value
291
+ */
292
+ set value(value) {
293
+ const normalized = normalizeToggleValue.call(this, value);
294
+ if (
295
+ normalized === this.getOption("values.on") ||
296
+ normalized === this.getOption("values.off")
297
+ ) {
298
+ if (this.getOption("value") !== normalized) {
299
+ this.setOption("value", normalized);
300
+ }
301
+ return;
302
+ }
303
+
304
+ addErrorAttribute(
305
+ this,
306
+ 'The value "' +
307
+ value +
308
+ '" must be "' +
309
+ this.getOption("values.on") +
310
+ '" or "' +
311
+ this.getOption("values.off"),
312
+ );
313
+
314
+ showError.call(this);
315
+ }
316
+
317
+ /**
318
+ * This method is called by the `instanceof` operator.
319
+ * @return {symbol}
320
+ */
321
+ static get [instanceSymbol]() {
322
+ return Symbol.for(
323
+ "@schukai/monster/components/form/toggle-switch@@instance",
324
+ );
325
+ }
326
+
327
+ /**
328
+ *
329
+ * @returns {string}
330
+ */
331
+ static getTag() {
332
+ return "monster-toggle-switch";
333
+ }
334
334
  }
335
335
 
336
336
  /**
337
337
  * @private
338
338
  */
339
339
  function initControlReferences() {
340
- this[switchElementSymbol] = this.shadowRoot.querySelector(
341
- `[${ATTRIBUTE_ROLE}=switch]`,
342
- );
340
+ this[switchElementSymbol] = this.shadowRoot.querySelector(
341
+ `[${ATTRIBUTE_ROLE}=switch]`,
342
+ );
343
343
  }
344
344
 
345
345
  /**
346
346
  * @private
347
347
  */
348
348
  function toggleOn() {
349
- if (!this[switchElementSymbol]) {
350
- return;
351
- }
349
+ if (!this[switchElementSymbol]) {
350
+ return;
351
+ }
352
352
 
353
- this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
354
- this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
353
+ this[switchElementSymbol].classList.remove(this.getOption("classes.off")); // change color
354
+ this[switchElementSymbol].classList.add(this.getOption("classes.on")); // change color
355
355
 
356
- const callback = this.getOption("actions.on");
357
- if (isFunction(callback)) {
358
- callback.call(this);
359
- }
356
+ const callback = this.getOption("actions.on");
357
+ if (isFunction(callback)) {
358
+ callback.call(this);
359
+ }
360
360
 
361
- if (typeof this.setFormValue === "function") {
362
- this.setFormValue(this.getOption("values.on"));
363
- }
361
+ if (typeof this.setFormValue === "function") {
362
+ this.setFormValue(this.getOption("values.on"));
363
+ }
364
364
  }
365
365
 
366
366
  /**
367
367
  * @private
368
368
  */
369
369
  function toggleOff() {
370
- if (!this[switchElementSymbol]) {
371
- return;
372
- }
370
+ if (!this[switchElementSymbol]) {
371
+ return;
372
+ }
373
373
 
374
- this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
375
- this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
374
+ this[switchElementSymbol].classList.remove(this.getOption("classes.on")); // change color
375
+ this[switchElementSymbol].classList.add(this.getOption("classes.off")); // change color
376
376
 
377
- const callback = this.getOption("actions.off");
378
- if (isFunction(callback)) {
379
- callback.call(this);
380
- }
377
+ const callback = this.getOption("actions.off");
378
+ if (isFunction(callback)) {
379
+ callback.call(this);
380
+ }
381
381
 
382
- if (typeof this.setFormValue === "function") {
383
- this.setFormValue(this.getOption("values.off"));
384
- }
382
+ if (typeof this.setFormValue === "function") {
383
+ this.setFormValue(this.getOption("values.off"));
384
+ }
385
385
  }
386
386
 
387
387
  /**
388
388
  * @private
389
389
  */
390
390
  function showError() {
391
- if (!this[switchElementSymbol]) {
392
- return;
393
- }
391
+ if (!this[switchElementSymbol]) {
392
+ return;
393
+ }
394
394
 
395
- this[switchElementSymbol].classList.remove(this.getOption("classes.on"));
396
- this[switchElementSymbol].classList.remove(this.getOption("classes.off"));
397
- this[switchElementSymbol].classList.add(this.getOption("classes.error"));
395
+ this[switchElementSymbol].classList.remove(this.getOption("classes.on"));
396
+ this[switchElementSymbol].classList.remove(this.getOption("classes.off"));
397
+ this[switchElementSymbol].classList.add(this.getOption("classes.error"));
398
398
  }
399
399
 
400
400
  /**
401
401
  * @private
402
402
  */
403
403
  function validateAndSetValue() {
404
- const rawValue = this.getOption("value");
405
- const value = normalizeToggleValue.call(this, rawValue);
406
- if (value !== rawValue) {
407
- this.setOption("value", value);
408
- }
409
-
410
- const validatedValues = [];
411
- validatedValues.push(this.getOption("values.on"));
412
- validatedValues.push(this.getOption("values.off"));
413
-
414
- if (validatedValues.includes(value) === false) {
415
- addAttributeToken(
416
- this,
417
- ATTRIBUTE_ERRORMESSAGE,
418
- 'The value "' +
419
- value +
420
- '" must be "' +
421
- this.getOption("values.on") +
422
- '" or "' +
423
- this.getOption("values.off"),
424
- );
425
- this[invalidDisabledSymbol] =
426
- !!this.getOption("disabled", false) !== true &&
427
- this.hasAttribute("disabled") === false;
428
- if (this[invalidDisabledSymbol]) {
429
- this.setOption("disabled", true);
430
- }
431
- this.formDisabledCallback(true);
432
- showError.call(this);
433
- return;
434
- }
435
- if (this[invalidDisabledSymbol]) {
436
- this.setOption("disabled", false);
437
- this.formDisabledCallback(false);
438
- this[invalidDisabledSymbol] = false;
439
- }
440
-
441
- if (value === this.getOption("values.on")) {
442
- toggleOn.call(this);
443
- return;
444
- }
445
-
446
- toggleOff.call(this);
404
+ const rawValue = this.getOption("value");
405
+ const value = normalizeToggleValue.call(this, rawValue);
406
+ if (value !== rawValue) {
407
+ this.setOption("value", value);
408
+ }
409
+
410
+ const validatedValues = [];
411
+ validatedValues.push(this.getOption("values.on"));
412
+ validatedValues.push(this.getOption("values.off"));
413
+
414
+ if (validatedValues.includes(value) === false) {
415
+ addAttributeToken(
416
+ this,
417
+ ATTRIBUTE_ERRORMESSAGE,
418
+ 'The value "' +
419
+ value +
420
+ '" must be "' +
421
+ this.getOption("values.on") +
422
+ '" or "' +
423
+ this.getOption("values.off"),
424
+ );
425
+ this[invalidDisabledSymbol] =
426
+ !!this.getOption("disabled", false) !== true &&
427
+ this.hasAttribute("disabled") === false;
428
+ if (this[invalidDisabledSymbol]) {
429
+ this.setOption("disabled", true);
430
+ }
431
+ this.formDisabledCallback(true);
432
+ showError.call(this);
433
+ return;
434
+ }
435
+ if (this[invalidDisabledSymbol]) {
436
+ this.setOption("disabled", false);
437
+ this.formDisabledCallback(false);
438
+ this[invalidDisabledSymbol] = false;
439
+ }
440
+
441
+ if (value === this.getOption("values.on")) {
442
+ toggleOn.call(this);
443
+ return;
444
+ }
445
+
446
+ toggleOff.call(this);
447
447
  }
448
448
 
449
449
  /**
@@ -452,50 +452,50 @@ function validateAndSetValue() {
452
452
  * @return {*}
453
453
  */
454
454
  function normalizeToggleValue(value) {
455
- const onValue = this.getOption("values.on");
456
- const offValue = this.getOption("values.off");
457
-
458
- if (value === onValue || value === offValue) {
459
- return value;
460
- }
461
-
462
- const token = normalizeToggleToken(value);
463
- if (!token) {
464
- return value;
465
- }
466
-
467
- const onToken = normalizeToggleToken(onValue);
468
- const offToken = normalizeToggleToken(offValue);
469
-
470
- if (token === "on") {
471
- if (onToken === "on" || offToken === "on") {
472
- return onToken === "on" ? onValue : offValue;
473
- }
474
- return onValue;
475
- }
476
-
477
- if (token === "off") {
478
- if (onToken === "off" || offToken === "off") {
479
- return onToken === "off" ? onValue : offValue;
480
- }
481
- return offValue;
482
- }
483
-
484
- if (token === "true") {
485
- if (onToken === "true" || offToken === "true") {
486
- return onToken === "true" ? onValue : offValue;
487
- }
488
- return onValue;
489
- }
490
-
491
- if (token === "false") {
492
- if (onToken === "false" || offToken === "false") {
493
- return onToken === "false" ? onValue : offValue;
494
- }
495
- return offValue;
496
- }
497
-
498
- return value;
455
+ const onValue = this.getOption("values.on");
456
+ const offValue = this.getOption("values.off");
457
+
458
+ if (value === onValue || value === offValue) {
459
+ return value;
460
+ }
461
+
462
+ const token = normalizeToggleToken(value);
463
+ if (!token) {
464
+ return value;
465
+ }
466
+
467
+ const onToken = normalizeToggleToken(onValue);
468
+ const offToken = normalizeToggleToken(offValue);
469
+
470
+ if (token === "on") {
471
+ if (onToken === "on" || offToken === "on") {
472
+ return onToken === "on" ? onValue : offValue;
473
+ }
474
+ return onValue;
475
+ }
476
+
477
+ if (token === "off") {
478
+ if (onToken === "off" || offToken === "off") {
479
+ return onToken === "off" ? onValue : offValue;
480
+ }
481
+ return offValue;
482
+ }
483
+
484
+ if (token === "true") {
485
+ if (onToken === "true" || offToken === "true") {
486
+ return onToken === "true" ? onValue : offValue;
487
+ }
488
+ return onValue;
489
+ }
490
+
491
+ if (token === "false") {
492
+ if (onToken === "false" || offToken === "false") {
493
+ return onToken === "false" ? onValue : offValue;
494
+ }
495
+ return offValue;
496
+ }
497
+
498
+ return value;
499
499
  }
500
500
 
501
501
  /**
@@ -504,19 +504,19 @@ function normalizeToggleValue(value) {
504
504
  * @return {string|undefined}
505
505
  */
506
506
  function normalizeToggleToken(value) {
507
- if (value === true || value === "true" || value === "TRUE") {
508
- return "true";
509
- }
510
- if (value === false || value === "false" || value === "FALSE") {
511
- return "false";
512
- }
513
- if (value === "on" || value === "ON") {
514
- return "on";
515
- }
516
- if (value === "off" || value === "OFF") {
517
- return "off";
518
- }
519
- return undefined;
507
+ if (value === true || value === "true" || value === "TRUE") {
508
+ return "true";
509
+ }
510
+ if (value === false || value === "false" || value === "FALSE") {
511
+ return "false";
512
+ }
513
+ if (value === "on" || value === "ON") {
514
+ return "on";
515
+ }
516
+ if (value === "off" || value === "OFF") {
517
+ return "off";
518
+ }
519
+ return undefined;
520
520
  }
521
521
 
522
522
  /**
@@ -524,36 +524,36 @@ function normalizeToggleToken(value) {
524
524
  * @return {initEventHandler}
525
525
  */
526
526
  function initEventHandler() {
527
- const self = this;
528
-
529
- let lastValue = self.value;
530
- self[internalSymbol].attachObserver(
531
- new Observer(function () {
532
- if (isObject(this) && this instanceof ProxyObserver) {
533
- const n = this.getSubject()?.options?.value;
534
- if (lastValue !== n) {
535
- lastValue = n;
536
- validateAndSetValue.call(self);
537
- }
538
- }
539
- }),
540
- );
541
-
542
- self.addEventListener("keyup", (event) => {
543
- if (event.keyCode === 32) {
544
- self.toggle();
545
- }
546
- });
547
-
548
- self.addEventListener("click", (event) => {
549
- self.toggle();
550
- });
551
-
552
- self.addEventListener("touch", (event) => {
553
- self.toggle();
554
- });
555
-
556
- return this;
527
+ const self = this;
528
+
529
+ let lastValue = self.value;
530
+ self[internalSymbol].attachObserver(
531
+ new Observer(function () {
532
+ if (isObject(this) && this instanceof ProxyObserver) {
533
+ const n = this.getSubject()?.options?.value;
534
+ if (lastValue !== n) {
535
+ lastValue = n;
536
+ validateAndSetValue.call(self);
537
+ }
538
+ }
539
+ }),
540
+ );
541
+
542
+ self.addEventListener("keyup", (event) => {
543
+ if (event.keyCode === 32) {
544
+ self.toggle();
545
+ }
546
+ });
547
+
548
+ self.addEventListener("click", (event) => {
549
+ self.toggle();
550
+ });
551
+
552
+ self.addEventListener("touch", (event) => {
553
+ self.toggle();
554
+ });
555
+
556
+ return this;
557
557
  }
558
558
 
559
559
  /**
@@ -561,38 +561,38 @@ function initEventHandler() {
561
561
  * @return {ToggleSwitch}
562
562
  */
563
563
  function initDisabledSync() {
564
- const self = this;
565
- const syncDisabled = () => {
566
- const disabledOption = !!self.getOption("disabled", false);
567
- const hasDisabledAttr = self.hasAttribute("disabled");
568
- const optionAttr = self.getAttribute("data-monster-option-disabled");
569
- const optionAttrDisabled =
570
- optionAttr !== null && optionAttr.toLowerCase() !== "false";
571
- const desiredDisabled =
572
- disabledOption || hasDisabledAttr || optionAttrDisabled;
573
-
574
- if (desiredDisabled && !disabledOption) {
575
- self.setOption("disabled", true);
576
- }
577
-
578
- if (desiredDisabled && !hasDisabledAttr) {
579
- self.setAttribute("disabled", "");
580
- }
581
-
582
- if (!desiredDisabled) {
583
- if (hasDisabledAttr) {
584
- self.removeAttribute("disabled");
585
- }
586
- if (disabledOption) {
587
- self.setOption("disabled", false);
588
- }
589
- }
590
- };
591
-
592
- syncDisabled();
593
- self.attachObserver(new Observer(syncDisabled));
594
-
595
- return this;
564
+ const self = this;
565
+ const syncDisabled = () => {
566
+ const disabledOption = !!self.getOption("disabled", false);
567
+ const hasDisabledAttr = self.hasAttribute("disabled");
568
+ const optionAttr = self.getAttribute("data-monster-option-disabled");
569
+ const optionAttrDisabled =
570
+ optionAttr !== null && optionAttr.toLowerCase() !== "false";
571
+ const desiredDisabled =
572
+ disabledOption || hasDisabledAttr || optionAttrDisabled;
573
+
574
+ if (desiredDisabled && !disabledOption) {
575
+ self.setOption("disabled", true);
576
+ }
577
+
578
+ if (desiredDisabled && !hasDisabledAttr) {
579
+ self.setAttribute("disabled", "");
580
+ }
581
+
582
+ if (!desiredDisabled) {
583
+ if (hasDisabledAttr) {
584
+ self.removeAttribute("disabled");
585
+ }
586
+ if (disabledOption) {
587
+ self.setOption("disabled", false);
588
+ }
589
+ }
590
+ };
591
+
592
+ syncDisabled();
593
+ self.attachObserver(new Observer(syncDisabled));
594
+
595
+ return this;
596
596
  }
597
597
 
598
598
  /**
@@ -600,8 +600,8 @@ function initDisabledSync() {
600
600
  * @return {string}
601
601
  */
602
602
  function getTemplate() {
603
- // language=HTML
604
- return `
603
+ // language=HTML
604
+ return `
605
605
  <div data-monster-role="control" part="control" tabindex="0">
606
606
  <div class="switch" data-monster-role="switch"
607
607
  data-monster-attributes="data-monster-state path:value | call:state-callback">