@hyperbook/markdown 0.16.0 → 0.17.0

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.
@@ -0,0 +1,663 @@
1
+ /**
2
+ * Copyright 2019 Google LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // @license © 2019 Google LLC. Licensed under the Apache License, Version 2.0.
18
+ const doc = document;
19
+ let store = {};
20
+ try {
21
+ store = localStorage;
22
+ } catch (err) {
23
+ // Do nothing. The user probably blocks cookies.
24
+ }
25
+ const PREFERS_COLOR_SCHEME = 'prefers-color-scheme';
26
+ const MEDIA = 'media';
27
+ const LIGHT = 'light';
28
+ const DARK = 'dark';
29
+ const SYSTEM = 'system';
30
+ const MQ_DARK = `(${PREFERS_COLOR_SCHEME}:${DARK})`;
31
+ const MQ_LIGHT = `(${PREFERS_COLOR_SCHEME}:${LIGHT})`;
32
+ const LINK_REL_STYLESHEET = 'link[rel=stylesheet]';
33
+ const REMEMBER = 'remember';
34
+ const LEGEND = 'legend';
35
+ const TOGGLE = 'toggle';
36
+ const SWITCH = 'switch';
37
+ const THREE_WAY = 'three-way';
38
+ const APPEARANCE = 'appearance';
39
+ const PERMANENT = 'permanent';
40
+ const MODE = 'mode';
41
+ const COLOR_SCHEME_CHANGE = 'colorschemechange';
42
+ const PERMANENT_COLOR_SCHEME = 'permanentcolorscheme';
43
+ const ALL = 'all';
44
+ const NOT_ALL = 'not all';
45
+ const NAME = 'dark-mode-toggle';
46
+ const DEFAULT_URL = 'https://googlechromelabs.github.io/dark-mode-toggle/demo/';
47
+
48
+ // See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html ↵
49
+ // #reflecting-content-attributes-in-idl-attributes.
50
+ const installStringReflection = (obj, attrName, propName = attrName) => {
51
+ Object.defineProperty(obj, propName, {
52
+ enumerable: true,
53
+ get() {
54
+ const value = this.getAttribute(attrName);
55
+ return value === null ? '' : value;
56
+ },
57
+ set(v) {
58
+ this.setAttribute(attrName, v);
59
+ },
60
+ });
61
+ };
62
+
63
+ const installBoolReflection = (obj, attrName, propName = attrName) => {
64
+ Object.defineProperty(obj, propName, {
65
+ enumerable: true,
66
+ get() {
67
+ return this.hasAttribute(attrName);
68
+ },
69
+ set(v) {
70
+ if (v) {
71
+ this.setAttribute(attrName, '');
72
+ } else {
73
+ this.removeAttribute(attrName);
74
+ }
75
+ },
76
+ });
77
+ };
78
+
79
+ const template = doc.createElement('template');
80
+
81
+ template.innerHTML = `
82
+ <style>
83
+ *,
84
+ ::before,
85
+ ::after {
86
+ box-sizing: border-box;
87
+ }
88
+
89
+ :host {
90
+ contain: content;
91
+ display: block;
92
+ }
93
+
94
+ :host([hidden]) {
95
+ display: none;
96
+ }
97
+
98
+ form {
99
+ background-color: var(--${NAME}-background-color, transparent);
100
+ color: var(--${NAME}-color, inherit);
101
+ padding: 0;
102
+ }
103
+
104
+ fieldset {
105
+ border: none;
106
+ margin: 0;
107
+ padding-block: 0.25rem;
108
+ padding-inline: 0.25rem;
109
+ }
110
+
111
+ legend {
112
+ font: var(--${NAME}-legend-font, inherit);
113
+ padding: 0;
114
+ }
115
+
116
+ input,
117
+ label {
118
+ cursor: pointer;
119
+ }
120
+
121
+ label {
122
+ white-space: nowrap;
123
+ }
124
+
125
+ input {
126
+ opacity: 0;
127
+ position: absolute;
128
+ pointer-events: none;
129
+ }
130
+
131
+ input:focus-visible + label {
132
+ outline: #e59700 auto 2px;
133
+ outline: -webkit-focus-ring-color auto 5px;
134
+ }
135
+
136
+ label::before {
137
+ content: "";
138
+ display: inline-block;
139
+ background-size: var(--${NAME}-icon-size, 1rem);
140
+ background-repeat: no-repeat;
141
+ height: var(--${NAME}-icon-size, 1rem);
142
+ width: var(--${NAME}-icon-size, 1rem);
143
+ vertical-align: middle;
144
+ }
145
+
146
+ label:not(:empty)::before {
147
+ margin-inline-end: 0.5rem;
148
+ }
149
+
150
+ [part="toggleLabel"]::before {
151
+ mask-image: var(--${NAME}-checkbox-icon, none);
152
+ width: 24px;
153
+ height: 24px;
154
+ background-color: var(--color-brand-text);
155
+ }
156
+
157
+ [part="lightLabel"],
158
+ [part="darkLabel"],
159
+ [part="toggleLabel"],
160
+ [part$="ThreeWayLabel"] {
161
+ font: var(--${NAME}-label-font, inherit);
162
+ }
163
+
164
+ [part="lightLabel"]:empty,
165
+ [part="darkLabel"]:empty,
166
+ [part="toggleLabel"]:empty,
167
+ [part$="ThreeWayLabel"]:empty {
168
+ font-size: 0;
169
+ padding: 0;
170
+ }
171
+
172
+ [part="permanentLabel"] {
173
+ font: var(--${NAME}-remember-font, inherit);
174
+ }
175
+
176
+ input:checked + [part="permanentLabel"]::before {
177
+ background-image: var(--${NAME}-remember-icon-checked, url("${DEFAULT_URL}checked.svg"));
178
+ }
179
+
180
+ input:checked + [part="darkLabel"],
181
+ input:checked + [part="lightLabel"],
182
+ input:checked + [part$="ThreeWayLabel"] {
183
+ background-color: var(--${NAME}-active-mode-background-color, transparent);
184
+ }
185
+
186
+ input:checked + [part="darkLabel"]::before,
187
+ input:checked + [part="lightLabel"]::before,
188
+ input:checked + [part$="ThreeWayLabel"]::before {
189
+ background-color: var(--${NAME}-active-mode-background-color, transparent);
190
+ }
191
+
192
+ input:checked + [part="toggleLabel"]::before, input[part="toggleCheckbox"]:checked ~ [part="threeWayRadioWrapper"] [part$="ThreeWayLabel"]::before {
193
+ filter: var(--${NAME}-icon-filter, none);
194
+ }
195
+
196
+ input:checked + [part="toggleLabel"] ~ aside [part="permanentLabel"]::before {
197
+ filter: var(--${NAME}-remember-filter, invert(100%));
198
+ }
199
+
200
+ aside {
201
+ visibility: hidden;
202
+ margin-block-start: 0.15rem;
203
+ }
204
+
205
+ [part="lightLabel"]:focus-visible ~ aside,
206
+ [part="darkLabel"]:focus-visible ~ aside,
207
+ [part="toggleLabel"]:focus-visible ~ aside {
208
+ visibility: visible;
209
+ transition: visibility 0s;
210
+ }
211
+
212
+ aside [part="permanentLabel"]:empty {
213
+ display: none;
214
+ }
215
+
216
+ @media (hover: hover) {
217
+ aside {
218
+ transition: visibility 3s;
219
+ }
220
+
221
+ aside:hover {
222
+ visibility: visible;
223
+ }
224
+
225
+ [part="lightLabel"]:hover ~ aside,
226
+ [part="darkLabel"]:hover ~ aside,
227
+ [part="toggleLabel"]:hover ~ aside {
228
+ visibility: visible;
229
+ transition: visibility 0s;
230
+ }
231
+ }
232
+ </style>
233
+ <form part="form">
234
+ <fieldset part="fieldset">
235
+ <legend part="legend"></legend>
236
+ <input part="lightRadio" id="l" name="mode" type="radio">
237
+ <label part="lightLabel" for="l"></label>
238
+ <input part="darkRadio" id="d" name="mode" type="radio">
239
+ <label part="darkLabel" for="d"></label>
240
+ <input part="toggleCheckbox" id="t" type="checkbox">
241
+ <label part="toggleLabel" for="t"></label>
242
+ <span part="threeWayRadioWrapper">
243
+ <input part="lightThreeWayRadio" id="3l" name="three-way-mode" type="radio">
244
+ <label part="lightThreeWayLabel" for="3l"></label>
245
+ <input part="systemThreeWayRadio" id="3s" name="three-way-mode" type="radio">
246
+ <label part="systemThreeWayLabel" for="3s"></label>
247
+ <input part="darkThreeWayRadio" id="3d" name="three-way-mode" type="radio">
248
+ <label part="darkThreeWayLabel" for="3d"></label>
249
+ </span>
250
+ <aside part="aside">
251
+ <input part="permanentCheckbox" id="p" type="checkbox">
252
+ <label part="permanentLabel" for="p"></label>
253
+ </aside>
254
+ </fieldset>
255
+ </form>
256
+ `
257
+
258
+ export class DarkModeToggle extends HTMLElement {
259
+ static get observedAttributes() {
260
+ return [MODE, APPEARANCE, PERMANENT, LEGEND, LIGHT, DARK, REMEMBER];
261
+ }
262
+
263
+ constructor() {
264
+ super();
265
+
266
+ installStringReflection(this, MODE);
267
+ installStringReflection(this, APPEARANCE);
268
+ installStringReflection(this, LEGEND);
269
+ installStringReflection(this, LIGHT);
270
+ installStringReflection(this, DARK);
271
+ installStringReflection(this, SYSTEM);
272
+ installStringReflection(this, REMEMBER);
273
+
274
+ installBoolReflection(this, PERMANENT);
275
+
276
+ this._darkCSS = null;
277
+ this._lightCSS = null;
278
+
279
+ doc.addEventListener(COLOR_SCHEME_CHANGE, (event) => {
280
+ this.mode = event.detail.colorScheme;
281
+ this._updateRadios();
282
+ this._updateCheckbox();
283
+ this._updateThreeWayRadios();
284
+ });
285
+
286
+ doc.addEventListener(PERMANENT_COLOR_SCHEME, (event) => {
287
+ this.permanent = event.detail.permanent;
288
+ this._permanentCheckbox.checked = this.permanent;
289
+ this._updateThreeWayRadios();
290
+ });
291
+
292
+ this._initializeDOM();
293
+ }
294
+
295
+ _initializeDOM() {
296
+ const shadowRoot = this.attachShadow({ mode: 'open' });
297
+ shadowRoot.append(template.content.cloneNode(true));
298
+
299
+ // We need to support `media="(prefers-color-scheme: dark)"` (with space)
300
+ // and `media="(prefers-color-scheme:dark)"` (without space)
301
+ this._darkCSS = doc.querySelectorAll(
302
+ `${LINK_REL_STYLESHEET}[${MEDIA}*=${PREFERS_COLOR_SCHEME}][${MEDIA}*="${DARK}"]`,
303
+ );
304
+ this._lightCSS = doc.querySelectorAll(
305
+ `${LINK_REL_STYLESHEET}[${MEDIA}*=${PREFERS_COLOR_SCHEME}][${MEDIA}*="${LIGHT}"]`,
306
+ );
307
+
308
+ // Get DOM references.
309
+ this._lightRadio = shadowRoot.querySelector('[part=lightRadio]');
310
+ this._lightLabel = shadowRoot.querySelector('[part=lightLabel]');
311
+ this._darkRadio = shadowRoot.querySelector('[part=darkRadio]');
312
+ this._darkLabel = shadowRoot.querySelector('[part=darkLabel]');
313
+ this._darkCheckbox = shadowRoot.querySelector('[part=toggleCheckbox]');
314
+ this._checkboxLabel = shadowRoot.querySelector('[part=toggleLabel]');
315
+ this._lightThreeWayRadio = shadowRoot.querySelector(
316
+ '[part=lightThreeWayRadio]',
317
+ );
318
+ this._lightThreeWayLabel = shadowRoot.querySelector(
319
+ '[part=lightThreeWayLabel]',
320
+ );
321
+ this._systemThreeWayRadio = shadowRoot.querySelector(
322
+ '[part=systemThreeWayRadio]',
323
+ );
324
+ this._systemThreeWayLabel = shadowRoot.querySelector(
325
+ '[part=systemThreeWayLabel]',
326
+ );
327
+ this._darkThreeWayRadio = shadowRoot.querySelector(
328
+ '[part=darkThreeWayRadio]',
329
+ );
330
+ this._darkThreeWayLabel = shadowRoot.querySelector(
331
+ '[part=darkThreeWayLabel]',
332
+ );
333
+ this._legendLabel = shadowRoot.querySelector('legend');
334
+ this._permanentAside = shadowRoot.querySelector('aside');
335
+ this._permanentCheckbox = shadowRoot.querySelector(
336
+ '[part=permanentCheckbox]',
337
+ );
338
+ this._permanentLabel = shadowRoot.querySelector('[part=permanentLabel]');
339
+ }
340
+
341
+ connectedCallback() {
342
+ // Does the browser support native `prefers-color-scheme`?
343
+ const hasNativePrefersColorScheme = matchMedia(MQ_DARK).media !== NOT_ALL;
344
+ // Listen to `prefers-color-scheme` changes.
345
+ if (hasNativePrefersColorScheme) {
346
+ matchMedia(MQ_DARK).addListener(({ matches }) => {
347
+ if (this.permanent) {
348
+ return;
349
+ }
350
+ this.mode = matches ? DARK : LIGHT;
351
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
352
+ });
353
+ }
354
+ // Set initial state, giving preference to a remembered value, then the
355
+ // native value (if supported), and eventually defaulting to a light
356
+ // experience.
357
+ let rememberedValue = false;
358
+ try {
359
+ rememberedValue = store.getItem(NAME);
360
+ } catch (err) {
361
+ // Do nothing. The user probably blocks cookies.
362
+ }
363
+ if (rememberedValue && [DARK, LIGHT].includes(rememberedValue)) {
364
+ this.mode = rememberedValue;
365
+ this._permanentCheckbox.checked = true;
366
+ this.permanent = true;
367
+ } else if (hasNativePrefersColorScheme) {
368
+ this.mode = matchMedia(MQ_LIGHT).matches ? LIGHT : DARK;
369
+ }
370
+ if (!this.mode) {
371
+ this.mode = LIGHT;
372
+ }
373
+ if (this.permanent && !rememberedValue) {
374
+ try {
375
+ store.setItem(NAME, this.mode);
376
+ } catch (err) {
377
+ // Do nothing. The user probably blocks cookies.
378
+ }
379
+ }
380
+
381
+ // Default to toggle appearance.
382
+ if (!this.appearance) {
383
+ this.appearance = TOGGLE;
384
+ }
385
+
386
+ // Update the appearance to toggle, switch or three-way.
387
+ this._updateAppearance();
388
+
389
+ // Update the radios
390
+ this._updateRadios();
391
+
392
+ // Make the checkbox reflect the state of the radios
393
+ this._updateCheckbox();
394
+
395
+ // Make the 3 way radio reflect the state of the radios
396
+ this._updateThreeWayRadios();
397
+
398
+ // Synchronize the behavior of the radio and the checkbox.
399
+ [this._lightRadio, this._darkRadio].forEach((input) => {
400
+ input.addEventListener('change', () => {
401
+ this.mode = this._lightRadio.checked ? LIGHT : DARK;
402
+ this._updateCheckbox();
403
+ this._updateThreeWayRadios();
404
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
405
+ });
406
+ });
407
+ this._darkCheckbox.addEventListener('change', () => {
408
+ this.mode = this._darkCheckbox.checked ? DARK : LIGHT;
409
+ this._updateRadios();
410
+ this._updateThreeWayRadios();
411
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
412
+ });
413
+ this._lightThreeWayRadio.addEventListener('change', () => {
414
+ this.mode = LIGHT;
415
+ this.permanent = true;
416
+ this._updateCheckbox();
417
+ this._updateRadios();
418
+ this._updateThreeWayRadios();
419
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
420
+ this._dispatchEvent(PERMANENT_COLOR_SCHEME, {
421
+ permanent: this.permanent,
422
+ });
423
+ });
424
+ this._darkThreeWayRadio.addEventListener('change', () => {
425
+ this.mode = DARK;
426
+ this.permanent = true;
427
+ this._updateCheckbox();
428
+ this._updateRadios();
429
+ this._updateThreeWayRadios();
430
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
431
+ this._dispatchEvent(PERMANENT_COLOR_SCHEME, {
432
+ permanent: this.permanent,
433
+ });
434
+ });
435
+ this._systemThreeWayRadio.addEventListener('change', () => {
436
+ this.mode = this._getPrefersColorScheme();
437
+ this.permanent = false;
438
+ this._updateCheckbox();
439
+ this._updateRadios();
440
+ this._updateThreeWayRadios();
441
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
442
+ this._dispatchEvent(PERMANENT_COLOR_SCHEME, {
443
+ permanent: this.permanent,
444
+ });
445
+ });
446
+ // Make remembering the last mode optional
447
+ this._permanentCheckbox.addEventListener('change', () => {
448
+ this.permanent = this._permanentCheckbox.checked;
449
+ this._updateThreeWayRadios();
450
+ this._dispatchEvent(PERMANENT_COLOR_SCHEME, {
451
+ permanent: this.permanent,
452
+ });
453
+ });
454
+
455
+ // Finally update the mode and let the world know what's going on
456
+ this._updateMode();
457
+ this._dispatchEvent(COLOR_SCHEME_CHANGE, { colorScheme: this.mode });
458
+ this._dispatchEvent(PERMANENT_COLOR_SCHEME, {
459
+ permanent: this.permanent,
460
+ });
461
+ }
462
+
463
+ attributeChangedCallback(name, oldValue, newValue) {
464
+ if (name === MODE) {
465
+ const allAttributes = [LIGHT, SYSTEM, DARK];
466
+ if (!allAttributes.includes(newValue)) {
467
+ throw new RangeError(
468
+ `Allowed values are: "${allAttributes.join(`", "`)}".`,
469
+ );
470
+ }
471
+ // Only show the dialog programmatically on devices not capable of hover
472
+ // and only if there is a label
473
+ if (matchMedia('(hover:none)').matches && this.remember) {
474
+ this._showPermanentAside();
475
+ }
476
+ if (this.permanent) {
477
+ try {
478
+ store.setItem(NAME, this.mode);
479
+ } catch (err) {
480
+ // Do nothing. The user probably blocks cookies.
481
+ }
482
+ }
483
+ this._updateRadios();
484
+ this._updateCheckbox();
485
+ this._updateThreeWayRadios();
486
+ this._updateMode();
487
+ } else if (name === APPEARANCE) {
488
+ const allAppearanceOptions = [TOGGLE, SWITCH, THREE_WAY];
489
+ if (!allAppearanceOptions.includes(newValue)) {
490
+ throw new RangeError(
491
+ `Allowed values are: "${allAppearanceOptions.join(`", "`)}".`,
492
+ );
493
+ }
494
+ this._updateAppearance();
495
+ } else if (name === PERMANENT) {
496
+ if (this.permanent) {
497
+ if (this.mode) {
498
+ try {
499
+ store.setItem(NAME, this.mode);
500
+ } catch (err) {
501
+ // Do nothing. The user probably blocks cookies.
502
+ }
503
+ }
504
+ } else {
505
+ try {
506
+ store.removeItem(NAME);
507
+ } catch (err) {
508
+ // Do nothing. The user probably blocks cookies.
509
+ }
510
+ }
511
+ this._permanentCheckbox.checked = this.permanent;
512
+ } else if (name === LEGEND) {
513
+ this._legendLabel.textContent = newValue;
514
+ } else if (name === REMEMBER) {
515
+ this._permanentLabel.textContent = newValue;
516
+ } else if (name === LIGHT) {
517
+ this._lightLabel.textContent = newValue;
518
+ if (this.mode === LIGHT) {
519
+ this._checkboxLabel.textContent = newValue;
520
+ }
521
+ } else if (name === DARK) {
522
+ this._darkLabel.textContent = newValue;
523
+ if (this.mode === DARK) {
524
+ this._checkboxLabel.textContent = newValue;
525
+ }
526
+ }
527
+ }
528
+
529
+ _getPrefersColorScheme() {
530
+ return matchMedia(MQ_LIGHT).matches ? LIGHT : DARK;
531
+ }
532
+
533
+ _dispatchEvent(type, value) {
534
+ this.dispatchEvent(
535
+ new CustomEvent(type, {
536
+ bubbles: true,
537
+ composed: true,
538
+ detail: value,
539
+ }),
540
+ );
541
+ }
542
+
543
+ _updateAppearance() {
544
+ // Hide or show the light-related affordances dependent on the appearance,
545
+ // which can be "switch" , "toggle" or "three-way".
546
+ this._lightRadio.hidden =
547
+ this._lightLabel.hidden =
548
+ this._darkRadio.hidden =
549
+ this._darkLabel.hidden =
550
+ this._darkCheckbox.hidden =
551
+ this._checkboxLabel.hidden =
552
+ this._lightThreeWayRadio.hidden =
553
+ this._lightThreeWayLabel.hidden =
554
+ this._systemThreeWayRadio.hidden =
555
+ this._systemThreeWayLabel.hidden =
556
+ this._darkThreeWayRadio.hidden =
557
+ this._darkThreeWayLabel.hidden =
558
+ true;
559
+ switch (this.appearance) {
560
+ case SWITCH:
561
+ this._lightRadio.hidden =
562
+ this._lightLabel.hidden =
563
+ this._darkRadio.hidden =
564
+ this._darkLabel.hidden =
565
+ false;
566
+ break;
567
+ case THREE_WAY:
568
+ this._lightThreeWayRadio.hidden =
569
+ this._lightThreeWayLabel.hidden =
570
+ this._systemThreeWayRadio.hidden =
571
+ this._systemThreeWayLabel.hidden =
572
+ this._darkThreeWayRadio.hidden =
573
+ this._darkThreeWayLabel.hidden =
574
+ false;
575
+ break;
576
+ case TOGGLE:
577
+ default:
578
+ this._darkCheckbox.hidden = this._checkboxLabel.hidden = false;
579
+ break;
580
+ }
581
+ }
582
+
583
+ _updateRadios() {
584
+ if (this.mode === LIGHT) {
585
+ this._lightRadio.checked = true;
586
+ } else {
587
+ this._darkRadio.checked = true;
588
+ }
589
+ }
590
+
591
+ _updateCheckbox() {
592
+ if (this.mode === LIGHT) {
593
+ this._checkboxLabel.style.setProperty(
594
+ `--${NAME}-checkbox-icon`,
595
+ `url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItbW9vbiI+PHBhdGggZD0iTTIxIDEyLjc5QTkgOSAwIDEgMSAxMS4yMSAzIDcgNyAwIDAgMCAyMSAxMi43OXoiPjwvcGF0aD48L3N2Zz4=)`,
596
+ );
597
+ this._checkboxLabel.textContent = this.light;
598
+ if (!this.light) {
599
+ this._checkboxLabel.ariaLabel = DARK;
600
+ }
601
+ this._darkCheckbox.checked = false;
602
+ } else {
603
+ this._checkboxLabel.style.setProperty(
604
+ `--${NAME}-checkbox-icon`,
605
+ `url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItc3VuIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSI1Ij48L2NpcmNsZT48bGluZSB4MT0iMTIiIHkxPSIxIiB4Mj0iMTIiIHkyPSIzIj48L2xpbmU+PGxpbmUgeDE9IjEyIiB5MT0iMjEiIHgyPSIxMiIgeTI9IjIzIj48L2xpbmU+PGxpbmUgeDE9IjQuMjIiIHkxPSI0LjIyIiB4Mj0iNS42NCIgeTI9IjUuNjQiPjwvbGluZT48bGluZSB4MT0iMTguMzYiIHkxPSIxOC4zNiIgeDI9IjE5Ljc4IiB5Mj0iMTkuNzgiPjwvbGluZT48bGluZSB4MT0iMSIgeTE9IjEyIiB4Mj0iMyIgeTI9IjEyIj48L2xpbmU+PGxpbmUgeDE9IjIxIiB5MT0iMTIiIHgyPSIyMyIgeTI9IjEyIj48L2xpbmU+PGxpbmUgeDE9IjQuMjIiIHkxPSIxOS43OCIgeDI9IjUuNjQiIHkyPSIxOC4zNiI+PC9saW5lPjxsaW5lIHgxPSIxOC4zNiIgeTE9IjUuNjQiIHgyPSIxOS43OCIgeTI9IjQuMjIiPjwvbGluZT48L3N2Zz4=)`,
606
+ );
607
+ this._checkboxLabel.textContent = this.dark;
608
+ if (!this.dark) {
609
+ this._checkboxLabel.ariaLabel = LIGHT;
610
+ }
611
+ this._darkCheckbox.checked = true;
612
+ }
613
+ }
614
+
615
+ _updateThreeWayRadios() {
616
+ this._lightThreeWayLabel.ariaLabel = LIGHT;
617
+ this._systemThreeWayLabel.ariaLabel = SYSTEM;
618
+ this._lightThreeWayLabel.ariaLabel = DARK;
619
+ this._lightThreeWayLabel.textContent = this.light;
620
+ this._systemThreeWayLabel.textContent = this.system;
621
+ this._darkThreeWayLabel.textContent = this.dark;
622
+ if (this.permanent) {
623
+ if (this.mode === LIGHT) {
624
+ this._lightThreeWayRadio.checked = true;
625
+ } else {
626
+ this._darkThreeWayRadio.checked = true;
627
+ }
628
+ } else {
629
+ this._systemThreeWayRadio.checked = true;
630
+ }
631
+ }
632
+
633
+ _updateMode() {
634
+ if (this.mode === LIGHT) {
635
+ this._lightCSS.forEach((link) => {
636
+ link.media = ALL;
637
+ link.disabled = false;
638
+ });
639
+ this._darkCSS.forEach((link) => {
640
+ link.media = NOT_ALL;
641
+ link.disabled = true;
642
+ });
643
+ } else {
644
+ this._darkCSS.forEach((link) => {
645
+ link.media = ALL;
646
+ link.disabled = false;
647
+ });
648
+ this._lightCSS.forEach((link) => {
649
+ link.media = NOT_ALL;
650
+ link.disabled = true;
651
+ });
652
+ }
653
+ }
654
+
655
+ _showPermanentAside() {
656
+ this._permanentAside.style.visibility = 'visible';
657
+ setTimeout(() => {
658
+ this._permanentAside.style.visibility = 'hidden';
659
+ }, 3000);
660
+ }
661
+ }
662
+
663
+ customElements.define(NAME, DarkModeToggle);