@oksigenia/access-panel 0.7.3 → 0.8.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.
- package/CHANGELOG.md +10 -0
- package/README.md +17 -0
- package/dist/behavior-CEe_YuMU.d.ts +118 -0
- package/dist/index.d.ts +4 -98
- package/dist/index.js +49 -7
- package/dist/index.js.map +1 -1
- package/dist/web-component.d.ts +8 -0
- package/dist/web-component.js +55 -7
- package/dist/web-component.js.map +1 -1
- package/package.json +1 -1
package/dist/web-component.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { b as PanelChangeDetail } from './behavior-CEe_YuMU.js';
|
|
2
|
+
|
|
1
3
|
declare class OksigeniaAccessPanelElement extends HTMLElement {
|
|
2
4
|
static get observedAttributes(): readonly string[];
|
|
3
5
|
private _controller;
|
|
6
|
+
/** `initial-state` is read on the first render only: later re-renders
|
|
7
|
+
* (another attribute changing) must not undo what the visitor did since. */
|
|
8
|
+
private _initialStateRead;
|
|
4
9
|
private readonly _fxId;
|
|
5
10
|
private readonly _scopeId;
|
|
6
11
|
constructor();
|
|
@@ -33,6 +38,9 @@ declare global {
|
|
|
33
38
|
interface HTMLElementTagNameMap {
|
|
34
39
|
'oksigenia-access-panel': OksigeniaAccessPanelElement;
|
|
35
40
|
}
|
|
41
|
+
interface HTMLElementEventMap {
|
|
42
|
+
'oksiac:change': CustomEvent<PanelChangeDetail>;
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
export { OksigeniaAccessPanelElement };
|
package/dist/web-component.js
CHANGED
|
@@ -283,14 +283,42 @@ var DEFAULT_STATE = Object.freeze({
|
|
|
283
283
|
readingMask: false,
|
|
284
284
|
bigTargets: false
|
|
285
285
|
});
|
|
286
|
+
var LEVEL_MAX = Object.freeze({
|
|
287
|
+
zoom: 4,
|
|
288
|
+
lh: 3,
|
|
289
|
+
align: 3,
|
|
290
|
+
ls: 3,
|
|
291
|
+
colorblind: 3
|
|
292
|
+
});
|
|
293
|
+
function sanitizeState(input) {
|
|
294
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
295
|
+
const src = input;
|
|
296
|
+
const out = { ...DEFAULT_STATE };
|
|
297
|
+
for (const key of Object.keys(DEFAULT_STATE)) {
|
|
298
|
+
const v = src[key];
|
|
299
|
+
if (v === void 0) continue;
|
|
300
|
+
if (key in LEVEL_MAX) {
|
|
301
|
+
if (typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= LEVEL_MAX[key]) {
|
|
302
|
+
out[key] = v;
|
|
303
|
+
}
|
|
304
|
+
} else if (v === true || v === 1) {
|
|
305
|
+
out[key] = true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
function parseState(json) {
|
|
311
|
+
if (json == null || json.trim() === "") return null;
|
|
312
|
+
try {
|
|
313
|
+
return sanitizeState(JSON.parse(json));
|
|
314
|
+
} catch {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
286
318
|
function loadState(key) {
|
|
287
319
|
try {
|
|
288
320
|
if (typeof localStorage === "undefined") return { ...DEFAULT_STATE };
|
|
289
|
-
|
|
290
|
-
if (!raw) return { ...DEFAULT_STATE };
|
|
291
|
-
const parsed = JSON.parse(raw);
|
|
292
|
-
if (!parsed || typeof parsed !== "object") return { ...DEFAULT_STATE };
|
|
293
|
-
return { ...DEFAULT_STATE, ...parsed };
|
|
321
|
+
return parseState(localStorage.getItem(key)) ?? { ...DEFAULT_STATE };
|
|
294
322
|
} catch {
|
|
295
323
|
return { ...DEFAULT_STATE };
|
|
296
324
|
}
|
|
@@ -385,7 +413,19 @@ function bindPanelBehavior(root, opts = {}) {
|
|
|
385
413
|
if (!panel || !closeBtn || !resetBtn) {
|
|
386
414
|
return noopController();
|
|
387
415
|
}
|
|
388
|
-
let state
|
|
416
|
+
let state;
|
|
417
|
+
if (opts.initialState) {
|
|
418
|
+
state = { ...opts.initialState };
|
|
419
|
+
saveState(storageKey, state);
|
|
420
|
+
} else {
|
|
421
|
+
state = loadState(storageKey);
|
|
422
|
+
}
|
|
423
|
+
const emitChange = () => {
|
|
424
|
+
const host = root.host;
|
|
425
|
+
if (!host) return;
|
|
426
|
+
const detail = { state: { ...state } };
|
|
427
|
+
host.dispatchEvent(new CustomEvent("oksiac:change", { bubbles: true, composed: true, detail }));
|
|
428
|
+
};
|
|
389
429
|
const scoped = opts.scopeEl !== void 0;
|
|
390
430
|
const GLOBAL_KEY = "oksiac::global";
|
|
391
431
|
const GLOBAL_MAP = [
|
|
@@ -561,11 +601,13 @@ function bindPanelBehavior(root, opts = {}) {
|
|
|
561
601
|
}
|
|
562
602
|
applyState();
|
|
563
603
|
saveState(storageKey, state);
|
|
604
|
+
emitChange();
|
|
564
605
|
};
|
|
565
606
|
const onReset = () => {
|
|
566
607
|
state = { ...DEFAULT_STATE };
|
|
567
608
|
applyState();
|
|
568
609
|
saveState(storageKey, state);
|
|
610
|
+
emitChange();
|
|
569
611
|
if (scoped) {
|
|
570
612
|
const cleared = { bigCursor: false, readingGuide: false, readingMask: false };
|
|
571
613
|
saveGlobal(cleared);
|
|
@@ -1383,6 +1425,9 @@ var OksigeniaAccessPanelElement = class extends HTMLElement {
|
|
|
1383
1425
|
return OBSERVED;
|
|
1384
1426
|
}
|
|
1385
1427
|
_controller = null;
|
|
1428
|
+
/** `initial-state` is read on the first render only: later re-renders
|
|
1429
|
+
* (another attribute changing) must not undo what the visitor did since. */
|
|
1430
|
+
_initialStateRead = false;
|
|
1386
1431
|
_fxId = `oks-access-fx-${++fxSeq}`;
|
|
1387
1432
|
_scopeId = `oks-access-scope-${this._fxId.split("-").pop()}`;
|
|
1388
1433
|
constructor() {
|
|
@@ -1498,12 +1543,15 @@ var OksigeniaAccessPanelElement = class extends HTMLElement {
|
|
|
1498
1543
|
});
|
|
1499
1544
|
shadow.innerHTML = `<style>${PANEL_CSS}${positionCss(position, positionMobile)}</style>${html}`;
|
|
1500
1545
|
const scopeEl = scope ? document.querySelector(scope) : void 0;
|
|
1546
|
+
const initialState = this._initialStateRead ? null : parseState(this.getAttribute("initial-state"));
|
|
1547
|
+
this._initialStateRead = true;
|
|
1501
1548
|
this._controller = bindPanelBehavior(shadow, {
|
|
1502
1549
|
storageKey: this.getAttribute("storage-key") ?? void 0,
|
|
1503
1550
|
locale: this.getLocale(),
|
|
1504
1551
|
enabled,
|
|
1505
1552
|
nudgeMax: this.getNudgeMax(),
|
|
1506
|
-
scopeEl
|
|
1553
|
+
scopeEl,
|
|
1554
|
+
initialState
|
|
1507
1555
|
});
|
|
1508
1556
|
this.updateScopeStyle(scope);
|
|
1509
1557
|
this.updateEffectsExclude(scope ?? "body");
|