@sharadox/web-library 0.2.0 → 0.4.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/README.md +4 -2
- package/distribution/animation/marquee/index.d.ts +9 -0
- package/distribution/animation/marquee/index.d.ts.map +1 -0
- package/distribution/animation/marquee/index.js +78 -0
- package/distribution/animation/marquee/index.js.map +1 -0
- package/distribution/animation/marquee/type.d.ts +5 -0
- package/distribution/animation/marquee/type.d.ts.map +1 -0
- package/distribution/animation/marquee/type.js +2 -0
- package/distribution/animation/marquee/type.js.map +1 -0
- package/distribution/privacy/consent/index.d.ts +22 -0
- package/distribution/privacy/consent/index.d.ts.map +1 -0
- package/distribution/privacy/consent/index.js +75 -0
- package/distribution/privacy/consent/index.js.map +1 -0
- package/distribution/privacy/consent/type.d.ts +35 -0
- package/distribution/privacy/consent/type.d.ts.map +1 -0
- package/distribution/privacy/consent/type.js +2 -0
- package/distribution/privacy/consent/type.js.map +1 -0
- package/distribution/privacy/use-consent/index.d.ts +5 -0
- package/distribution/privacy/use-consent/index.d.ts.map +1 -0
- package/distribution/privacy/use-consent/index.js +22 -0
- package/distribution/privacy/use-consent/index.js.map +1 -0
- package/distribution/privacy/use-consent/type.d.ts +10 -0
- package/distribution/privacy/use-consent/type.d.ts.map +1 -0
- package/distribution/privacy/use-consent/type.js +2 -0
- package/distribution/privacy/use-consent/type.js.map +1 -0
- package/distribution/scroll/active-section/index.d.ts +7 -0
- package/distribution/scroll/active-section/index.d.ts.map +1 -0
- package/distribution/scroll/active-section/index.js +49 -0
- package/distribution/scroll/active-section/index.js.map +1 -0
- package/distribution/scroll/active-section/type.d.ts +9 -0
- package/distribution/scroll/active-section/type.d.ts.map +1 -0
- package/distribution/scroll/active-section/type.js +2 -0
- package/distribution/scroll/active-section/type.js.map +1 -0
- package/distribution/style/apply/index.d.ts +1 -1
- package/distribution/style/apply/index.d.ts.map +1 -1
- package/distribution/style/apply/index.js +7 -3
- package/distribution/style/apply/index.js.map +1 -1
- package/distribution/style/apply/type.d.ts +2 -0
- package/distribution/style/apply/type.d.ts.map +1 -1
- package/distribution/style/definition/index.d.ts +2 -0
- package/distribution/style/definition/index.d.ts.map +1 -1
- package/distribution/style/definition/index.js +5 -0
- package/distribution/style/definition/index.js.map +1 -1
- package/distribution/style/definition/type.d.ts +5 -0
- package/distribution/style/definition/type.d.ts.map +1 -1
- package/distribution/style/style-sheet/index.d.ts +2 -1
- package/distribution/style/style-sheet/index.d.ts.map +1 -1
- package/distribution/style/style-sheet/index.js +9 -3
- package/distribution/style/style-sheet/index.js.map +1 -1
- package/distribution/style/use-style/index.d.ts +1 -1
- package/distribution/style/use-style/index.d.ts.map +1 -1
- package/distribution/style/use-style/index.js +8 -5
- package/distribution/style/use-style/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,8 +12,10 @@ Import each piece by its path:
|
|
|
12
12
|
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
13
|
| `internationalization/` | `locale` (`isLocale`, `languageTag`, `openGraphLocale`, `Translated`), `translate`, `locale-redirect` (next.config redirects: remembered language, then Accept-Language), `locale-preference` (`rememberLocale`) |
|
|
14
14
|
| `search-engine/` | `sitemap` (`localizedSitemap`), `robots`, `structured-data` (JSON-LD component) |
|
|
15
|
-
| `animation/` | `reveal`, `scroll-word` (text that lights up word by word), `in-view`, `count-up`, `smooth-scroll`
|
|
15
|
+
| `animation/` | `reveal`, `scroll-word` (text that lights up word by word), `in-view`, `count-up`, `marquee` (endless strip you can also drag), `smooth-scroll` |
|
|
16
16
|
| `style/` | `definition` (`resolveStyle`), `style-script` (`<StyleScript>` for `<head>`: every style's CSS variables and the no-flash script), `use-style` (picker hook), `apply`, `style-sheet` |
|
|
17
|
+
| `scroll/` | `active-section` (which section is on screen, and how far through the page) |
|
|
18
|
+
| `privacy/` | `consent` (cookie answers: kept when accepted or chosen, for this visit only when denied; `hasConsent`, `openConsent`), `use-consent` (hook) |
|
|
17
19
|
| `pointer/` | `spotlight` (pointer position as CSS variables), `tilt` (3D tilt towards the pointer) |
|
|
18
20
|
| `time/` | `zone-minute`, `format-time`, `sun-time` (sunrise and sunset), `sun-today` (React hook), `open-state` |
|
|
19
21
|
| `form/` | `rate-limit`, `bot-check` (honeypot and fill time), `field` |
|
|
@@ -29,7 +31,7 @@ import { translate } from "@sharadox/web-library/internationalization/translate"
|
|
|
29
31
|
<Reveal delay={0.1}>{translate({ en: "Hello", pt: "Olá" }, locale)}</Reveal>;
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
Styles are what other projects call themes: any number of dark and light styles, a default for each scheme, "system" as the default choice, and a manual choice remembered in browser storage.
|
|
34
|
+
Styles are what other projects call themes: any number of dark and light styles, a default for each scheme, "system" or a fixed style as the default choice, and a manual choice remembered in browser storage.
|
|
33
35
|
|
|
34
36
|
React components are client components (`"use client"`), accept `className`, and can be restyled per site. React (and, for `test/`, Playwright) are optional peer dependencies.
|
|
35
37
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MarqueeOptions } from "@sharadox/web-library/animation/marquee/type";
|
|
2
|
+
/**
|
|
3
|
+
* An endless strip that slides on its own and can be grabbed and flung by hand (mouse or touch), with inertia.
|
|
4
|
+
* Attach the returned reference to the track: an element holding two identical groups side by side, so moving it by
|
|
5
|
+
* one group's width (half the track) looks the same. It does not move by itself when the visitor prefers reduced
|
|
6
|
+
* motion, but can still be dragged.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useMarquee<Track extends HTMLElement>({ speed }?: MarqueeOptions): import("react").RefObject<Track | null>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/animation/marquee/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAEnF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,WAAW,EAAE,EAAE,KAAU,EAAE,GAAE,cAAmB,2CAgExF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* An endless strip that slides on its own and can be grabbed and flung by hand (mouse or touch), with inertia.
|
|
5
|
+
* Attach the returned reference to the track: an element holding two identical groups side by side, so moving it by
|
|
6
|
+
* one group's width (half the track) looks the same. It does not move by itself when the visitor prefers reduced
|
|
7
|
+
* motion, but can still be dragged.
|
|
8
|
+
*/
|
|
9
|
+
export function useMarquee({ speed = 40 } = {}) {
|
|
10
|
+
const reference = useRef(null);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const track = reference.current;
|
|
13
|
+
if (!track)
|
|
14
|
+
return;
|
|
15
|
+
const automatic = window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : speed;
|
|
16
|
+
let offset = 0;
|
|
17
|
+
let velocity = 0;
|
|
18
|
+
let dragging = false;
|
|
19
|
+
let lastX = 0;
|
|
20
|
+
let lastTime = 0;
|
|
21
|
+
let previous = performance.now();
|
|
22
|
+
let frame = 0;
|
|
23
|
+
const wrap = () => {
|
|
24
|
+
const half = track.scrollWidth / 2;
|
|
25
|
+
if (half > 0)
|
|
26
|
+
offset = ((offset % half) - half) % half || 0;
|
|
27
|
+
};
|
|
28
|
+
const tick = (now) => {
|
|
29
|
+
const seconds = Math.min(0.05, (now - previous) / 1000);
|
|
30
|
+
previous = now;
|
|
31
|
+
if (!dragging) {
|
|
32
|
+
// Inertia from a fling eases back into the automatic speed.
|
|
33
|
+
velocity += (-automatic - velocity) * Math.min(1, seconds * 2.5);
|
|
34
|
+
offset += velocity * seconds;
|
|
35
|
+
}
|
|
36
|
+
wrap();
|
|
37
|
+
track.style.transform = `translate3d(${offset}px, 0, 0)`;
|
|
38
|
+
frame = requestAnimationFrame(tick);
|
|
39
|
+
};
|
|
40
|
+
const down = (event) => {
|
|
41
|
+
dragging = true;
|
|
42
|
+
lastX = event.clientX;
|
|
43
|
+
lastTime = event.timeStamp;
|
|
44
|
+
velocity = 0;
|
|
45
|
+
track.setPointerCapture(event.pointerId);
|
|
46
|
+
};
|
|
47
|
+
const move = (event) => {
|
|
48
|
+
if (!dragging)
|
|
49
|
+
return;
|
|
50
|
+
const delta = event.clientX - lastX;
|
|
51
|
+
const elapsed = Math.max(1, event.timeStamp - lastTime) / 1000;
|
|
52
|
+
offset += delta;
|
|
53
|
+
velocity = delta / elapsed;
|
|
54
|
+
lastX = event.clientX;
|
|
55
|
+
lastTime = event.timeStamp;
|
|
56
|
+
};
|
|
57
|
+
const up = (event) => {
|
|
58
|
+
dragging = false;
|
|
59
|
+
if (track.hasPointerCapture(event.pointerId))
|
|
60
|
+
track.releasePointerCapture(event.pointerId);
|
|
61
|
+
};
|
|
62
|
+
velocity = -automatic;
|
|
63
|
+
track.addEventListener("pointerdown", down);
|
|
64
|
+
track.addEventListener("pointermove", move);
|
|
65
|
+
track.addEventListener("pointerup", up);
|
|
66
|
+
track.addEventListener("pointercancel", up);
|
|
67
|
+
frame = requestAnimationFrame(tick);
|
|
68
|
+
return () => {
|
|
69
|
+
cancelAnimationFrame(frame);
|
|
70
|
+
track.removeEventListener("pointerdown", down);
|
|
71
|
+
track.removeEventListener("pointermove", move);
|
|
72
|
+
track.removeEventListener("pointerup", up);
|
|
73
|
+
track.removeEventListener("pointercancel", up);
|
|
74
|
+
};
|
|
75
|
+
}, [speed]);
|
|
76
|
+
return reference;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/animation/marquee/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG1C;;;;;GAKG;AACH,MAAM,UAAU,UA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B,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QAC5C,KAAK,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QAC5C,KAAK,CAAC,gBAAgB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACxC,KAAK,CAAC,gBAAgB,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QAC5C,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACpC,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAC5B,KAAK,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;YAC/C,KAAK,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;YAC/C,KAAK,CAAC,mBAAmB,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC3C,KAAK,CAAC,mBAAmB,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/animation/marquee/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/animation/marquee/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ConsentConfiguration, ConsentStatus } from "@sharadox/web-library/privacy/consent/type";
|
|
2
|
+
/** Window event fired whenever the answer changes, and the one that reopens the consent panel. */
|
|
3
|
+
export declare const CONSENT_CHANGE_EVENT = "consent-change";
|
|
4
|
+
export declare const CONSENT_OPEN_EVENT = "consent-open";
|
|
5
|
+
/** Only the required categories: what "Deny" grants. */
|
|
6
|
+
export declare function requiredOnly(configuration: ConsentConfiguration): Record<string, boolean>;
|
|
7
|
+
/** Every category: what "Accept All" grants. */
|
|
8
|
+
export declare function everything(configuration: ConsentConfiguration): Record<string, boolean>;
|
|
9
|
+
/** Reads the visitor's answer. A stored answer from an older version counts as not asked. */
|
|
10
|
+
export declare function readConsent(configuration: ConsentConfiguration): ConsentStatus;
|
|
11
|
+
/** True when the visitor allowed a category (required categories always are). */
|
|
12
|
+
export declare function hasConsent(configuration: ConsentConfiguration, key: string): boolean;
|
|
13
|
+
/** Stores an answer ("Accept All" or a manual selection) for good. Required categories are forced on. */
|
|
14
|
+
export declare function saveConsent(configuration: ConsentConfiguration, granted: Record<string, boolean>): void;
|
|
15
|
+
/**
|
|
16
|
+
* "Deny": only required categories, and nothing kept for good — the answer lasts for this visit, and the visitor
|
|
17
|
+
* is asked again next time they come.
|
|
18
|
+
*/
|
|
19
|
+
export declare function declineConsent(configuration: ConsentConfiguration): void;
|
|
20
|
+
/** Reopens the consent panel, for example from a "Cookie Preferences" link. */
|
|
21
|
+
export declare function openConsent(): void;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/privacy/consent/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAErH,kGAAkG;AAClG,eAAO,MAAM,oBAAoB,mBAAmB,CAAC;AACrD,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AAIjD,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,aAAa,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzF;AAED,gDAAgD;AAChD,wBAAgB,UAAU,CAAC,aAAa,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEvF;AAED,6FAA6F;AAC7F,wBAAgB,WAAW,CAAC,aAAa,EAAE,oBAAoB,GAAG,aAAa,CAY9E;AAED,iFAAiF;AACjF,wBAAgB,UAAU,CAAC,aAAa,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAIpF;AAID,yGAAyG;AACzG,wBAAgB,WAAW,CAAC,aAAa,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAkBvG;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,oBAAoB,GAAG,IAAI,CAQxE;AAED,+EAA+E;AAC/E,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Window event fired whenever the answer changes, and the one that reopens the consent panel. */
|
|
2
|
+
export const CONSENT_CHANGE_EVENT = "consent-change";
|
|
3
|
+
export const CONSENT_OPEN_EVENT = "consent-open";
|
|
4
|
+
const declinedKey = (configuration) => `${configuration.storageKey}-declined`;
|
|
5
|
+
/** Only the required categories: what "Deny" grants. */
|
|
6
|
+
export function requiredOnly(configuration) {
|
|
7
|
+
return Object.fromEntries(configuration.categories.map((category) => [category.key, !!category.required]));
|
|
8
|
+
}
|
|
9
|
+
/** Every category: what "Accept All" grants. */
|
|
10
|
+
export function everything(configuration) {
|
|
11
|
+
return Object.fromEntries(configuration.categories.map((category) => [category.key, true]));
|
|
12
|
+
}
|
|
13
|
+
/** Reads the visitor's answer. A stored answer from an older version counts as not asked. */
|
|
14
|
+
export function readConsent(configuration) {
|
|
15
|
+
try {
|
|
16
|
+
const stored = localStorage.getItem(configuration.storageKey);
|
|
17
|
+
if (stored) {
|
|
18
|
+
const record = JSON.parse(stored);
|
|
19
|
+
if (record.version === configuration.version)
|
|
20
|
+
return { kind: "decided", record };
|
|
21
|
+
}
|
|
22
|
+
if (sessionStorage.getItem(declinedKey(configuration)))
|
|
23
|
+
return { kind: "declined" };
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
// Unreadable or blocked storage: ask.
|
|
27
|
+
}
|
|
28
|
+
return { kind: "unknown" };
|
|
29
|
+
}
|
|
30
|
+
/** True when the visitor allowed a category (required categories always are). */
|
|
31
|
+
export function hasConsent(configuration, key) {
|
|
32
|
+
if (configuration.categories.some((category) => category.key === key && category.required))
|
|
33
|
+
return true;
|
|
34
|
+
const status = readConsent(configuration);
|
|
35
|
+
return status.kind === "decided" && !!status.record.granted[key];
|
|
36
|
+
}
|
|
37
|
+
const announce = () => window.dispatchEvent(new Event(CONSENT_CHANGE_EVENT));
|
|
38
|
+
/** Stores an answer ("Accept All" or a manual selection) for good. Required categories are forced on. */
|
|
39
|
+
export function saveConsent(configuration, granted) {
|
|
40
|
+
const record = {
|
|
41
|
+
version: configuration.version,
|
|
42
|
+
granted: {
|
|
43
|
+
...granted,
|
|
44
|
+
...Object.fromEntries(configuration.categories.filter((category) => category.required).map((category) => [category.key, true])),
|
|
45
|
+
},
|
|
46
|
+
date: new Date().toISOString(),
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
localStorage.setItem(configuration.storageKey, JSON.stringify(record));
|
|
50
|
+
sessionStorage.removeItem(declinedKey(configuration));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Storage blocked: nothing persists, the panel asks again next time.
|
|
54
|
+
}
|
|
55
|
+
announce();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* "Deny": only required categories, and nothing kept for good — the answer lasts for this visit, and the visitor
|
|
59
|
+
* is asked again next time they come.
|
|
60
|
+
*/
|
|
61
|
+
export function declineConsent(configuration) {
|
|
62
|
+
try {
|
|
63
|
+
localStorage.removeItem(configuration.storageKey);
|
|
64
|
+
sessionStorage.setItem(declinedKey(configuration), "1");
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Storage blocked: the panel simply shows again.
|
|
68
|
+
}
|
|
69
|
+
announce();
|
|
70
|
+
}
|
|
71
|
+
/** Reopens the consent panel, for example from a "Cookie Preferences" link. */
|
|
72
|
+
export function openConsent() {
|
|
73
|
+
window.dispatchEvent(new Event(CONSENT_OPEN_EVENT));
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/privacy/consent/index.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,MAAM,CAAC,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;AACrD,MAAM,CAAC,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAEjD,MAAM,WAAW,GAAG,CAAC,aAAmC,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,UAAU,WAAW,CAAC;AAEpG,wDAAwD;AACxD,MAAM,UAAU,YAAY,CAAC,aAAmC;IAC9D,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC7G,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,UAAU,CAAC,aAAmC;IAC5D,OAAO,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9F,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,aAAmC;IAC7D,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAkB,C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,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CACzG;SACF;QACD,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KAC/B,CAAC;IACF,IAAI,CAAC;QACH,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,qEAAqE;IACvE,CAAC;IACD,QAAQ,EAAE,CAAC;AACb,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,aAAmC;IAChE,IAAI,CAAC;QACH,YAAY,CAAC,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAClD,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,GAAG,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,iDAAiD;IACnD,CAAC;IACD,QAAQ,EAAE,CAAC;AACb,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,WAAW;IACzB,MAAM,CAAC,aAAa,CAAC,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** One kind of cookie or storage the site asks about. */
|
|
2
|
+
export interface ConsentCategory {
|
|
3
|
+
key: string;
|
|
4
|
+
/** Always on: the site needs it to work (language, style, form security). */
|
|
5
|
+
required?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** What the site asks about and where the answer is kept. */
|
|
8
|
+
export interface ConsentConfiguration {
|
|
9
|
+
/** Browser storage key for the answer. */
|
|
10
|
+
storageKey: string;
|
|
11
|
+
/** Raise it when the categories change, so everyone is asked again. */
|
|
12
|
+
version: number;
|
|
13
|
+
categories: readonly ConsentCategory[];
|
|
14
|
+
}
|
|
15
|
+
/** A stored answer. */
|
|
16
|
+
export interface ConsentRecord {
|
|
17
|
+
version: number;
|
|
18
|
+
/** Category key → allowed. Required categories are always true. */
|
|
19
|
+
granted: Record<string, boolean>;
|
|
20
|
+
/** When the visitor answered (ISO 8601). */
|
|
21
|
+
date: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where the visitor stands: not asked yet (or the answer is out of date), declined during this visit (asked again
|
|
25
|
+
* next visit), or answered.
|
|
26
|
+
*/
|
|
27
|
+
export type ConsentStatus = {
|
|
28
|
+
kind: "unknown";
|
|
29
|
+
} | {
|
|
30
|
+
kind: "declined";
|
|
31
|
+
} | {
|
|
32
|
+
kind: "decided";
|
|
33
|
+
record: ConsentRecord;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/privacy/consent/type.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,6DAA6D;AAC7D,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,SAAS,eAAe,EAAE,CAAC;CACxC;AAED,uBAAuB;AACvB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,aAAa,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/privacy/consent/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConsentConfiguration } from "@sharadox/web-library/privacy/consent/type";
|
|
2
|
+
import type { ConsentState } from "@sharadox/web-library/privacy/use-consent/type";
|
|
3
|
+
/** The visitor's cookie answer, kept in sync across the page and other tabs, with the actions that change it. */
|
|
4
|
+
export declare function useConsent(configuration: ConsentConfiguration): ConsentState;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/privacy/use-consent/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAWnF,iHAAiH;AACjH,wBAAgB,UAAU,CAAC,aAAa,EAAE,oBAAoB,GAAG,YAAY,CAY5E"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
3
|
+
import { CONSENT_CHANGE_EVENT, declineConsent, everything, readConsent, saveConsent, } from "@sharadox/web-library/privacy/consent";
|
|
4
|
+
const subscribe = (notify) => {
|
|
5
|
+
window.addEventListener(CONSENT_CHANGE_EVENT, notify);
|
|
6
|
+
window.addEventListener("storage", notify);
|
|
7
|
+
return () => {
|
|
8
|
+
window.removeEventListener(CONSENT_CHANGE_EVENT, notify);
|
|
9
|
+
window.removeEventListener("storage", notify);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/** The visitor's cookie answer, kept in sync across the page and other tabs, with the actions that change it. */
|
|
13
|
+
export function useConsent(configuration) {
|
|
14
|
+
// A string snapshot keeps useSyncExternalStore stable; it is parsed again below.
|
|
15
|
+
const snapshot = useSyncExternalStore(subscribe, () => JSON.stringify(readConsent(configuration)), () => undefined);
|
|
16
|
+
const status = useMemo(() => (snapshot ? JSON.parse(snapshot) : undefined), [snapshot]);
|
|
17
|
+
const acceptAll = useCallback(() => saveConsent(configuration, everything(configuration)), [configuration]);
|
|
18
|
+
const deny = useCallback(() => declineConsent(configuration), [configuration]);
|
|
19
|
+
const save = useCallback((granted) => saveConsent(configuration, granted), [configuration]);
|
|
20
|
+
return { status, acceptAll, deny, save };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/privacy/use-consent/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,WAAW,EACX,WAAW,GACZ,MAAM,uCAAuC,CAAC;AAI/C,MAAM,SAAS,GAAG,CAAC,MAAkB,EAAE,EAAE;IACvC,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IACtD,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC3C,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QACzD,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,iHAAiH;AACjH,MAAM,UAAU,UAAU,CAAC,aAAmC;IAC5D,iFAAiF;IACjF,MAAM,QAAQ,GAAG,oBAAoB,CACnC,SAAS,EACT,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,EAChD,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxF,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5G,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAC/E,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,OAAgC,EAAE,EAAE,CAAC,WAAW,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACrH,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ConsentStatus } from "@sharadox/web-library/privacy/consent/type";
|
|
2
|
+
export interface ConsentState {
|
|
3
|
+
/** `undefined` on the server and before hydration, so nothing flashes for visitors who already answered. */
|
|
4
|
+
status: ConsentStatus | undefined;
|
|
5
|
+
acceptAll: () => void;
|
|
6
|
+
deny: () => void;
|
|
7
|
+
/** Stores a manual selection. */
|
|
8
|
+
save: (granted: Record<string, boolean>) => void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/privacy/use-consent/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAC;AAEhF,MAAM,WAAW,YAAY;IAC3B,4GAA4G;IAC5G,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;IAClC,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,iCAAiC;IACjC,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CAClD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/privacy/use-consent/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActiveSection } from "@sharadox/web-library/scroll/active-section/type";
|
|
2
|
+
/**
|
|
3
|
+
* Follows the scroll: which of the sections (by element id, in page order) holds the middle of the screen, how far
|
|
4
|
+
* through it, and how far down the page. For section indicators and progress bars.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useActiveSection(ids: readonly string[]): ActiveSection;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/scroll/active-section/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kDAAkD,CAAC;AAEtF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAyCtE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Follows the scroll: which of the sections (by element id, in page order) holds the middle of the screen, how far
|
|
5
|
+
* through it, and how far down the page. For section indicators and progress bars.
|
|
6
|
+
*/
|
|
7
|
+
export function useActiveSection(ids) {
|
|
8
|
+
const [state, setState] = useState({ active: ids[0] ?? "", within: 0, page: 0 });
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
let frame = 0;
|
|
11
|
+
const measure = () => {
|
|
12
|
+
frame = 0;
|
|
13
|
+
const middle = innerHeight / 2;
|
|
14
|
+
let active = ids[0] ?? "";
|
|
15
|
+
let within = 0;
|
|
16
|
+
for (const id of ids) {
|
|
17
|
+
const element = document.getElementById(id);
|
|
18
|
+
if (!element)
|
|
19
|
+
continue;
|
|
20
|
+
const bounds = element.getBoundingClientRect();
|
|
21
|
+
if (bounds.top <= middle) {
|
|
22
|
+
active = id;
|
|
23
|
+
within = Math.min(1, Math.max(0, (middle - bounds.top) / Math.max(1, bounds.height)));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const scrollable = document.documentElement.scrollHeight - innerHeight;
|
|
27
|
+
const page = scrollable > 0 ? Math.min(1, scrollY / scrollable) : 0;
|
|
28
|
+
setState((previous) => previous.active === active &&
|
|
29
|
+
Math.abs(previous.within - within) < 0.002 &&
|
|
30
|
+
Math.abs(previous.page - page) < 0.002
|
|
31
|
+
? previous
|
|
32
|
+
: { active, within, page });
|
|
33
|
+
};
|
|
34
|
+
const schedule = () => {
|
|
35
|
+
if (!frame)
|
|
36
|
+
frame = requestAnimationFrame(measure);
|
|
37
|
+
};
|
|
38
|
+
schedule();
|
|
39
|
+
addEventListener("scroll", schedule, { passive: true });
|
|
40
|
+
addEventListener("resize", schedule);
|
|
41
|
+
return () => {
|
|
42
|
+
cancelAnimationFrame(frame);
|
|
43
|
+
removeEventListener("scroll", schedule);
|
|
44
|
+
removeEventListener("resize", schedule);
|
|
45
|
+
};
|
|
46
|
+
}, [ids]);
|
|
47
|
+
return state;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/scroll/active-section/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OA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AC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACpE,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE,CACpB,QAAQ,CAAC,MAAM,KAAK,MAAM;gBAC1B,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK;gBAC1C,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,KAAK;gBACpC,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAC7B,CAAC;QACJ,CAAC,CAAC;QACF,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,IAAI,CAAC,KAAK;gBAAE,KAAK,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACrD,CAAC,CAAC;QACF,QAAQ,EAAE,CAAC;QACX,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAC5B,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACxC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACV,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ActiveSection {
|
|
2
|
+
/** The id of the section the middle of the screen is in. */
|
|
3
|
+
active: string;
|
|
4
|
+
/** How far through the active section the middle of the screen is, 0–1. */
|
|
5
|
+
within: number;
|
|
6
|
+
/** How far down the whole page the visitor is, 0–1. */
|
|
7
|
+
page: number;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/scroll/active-section/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/scroll/active-section/type.ts"],"names":[],"mappings":""}
|
|
@@ -4,7 +4,7 @@ import type { StyleApplyData } from "@sharadox/web-library/style/apply/type";
|
|
|
4
4
|
export declare function styleApplyData(configuration: StyleConfiguration): StyleApplyData;
|
|
5
5
|
/**
|
|
6
6
|
* Writes the style to `<html>`: `data-style` (the style in use), `data-style-choice` and `color-scheme`.
|
|
7
|
-
* Without a `choice` it reads the remembered one (or
|
|
7
|
+
* Without a `choice` it reads the remembered one (or the default choice). It is self-contained on purpose: the inline
|
|
8
8
|
* script in `<head>` embeds its source, so the page never shows the wrong style before React loads.
|
|
9
9
|
*/
|
|
10
10
|
export declare function applyStyle(data: StyleApplyData, choice?: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/apply/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/apply/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E,4DAA4D;AAC5D,wBAAgB,cAAc,CAAC,aAAa,EAAE,kBAAkB,GAAG,cAAc,CAQhF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CA0BtE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { defaultStyleChoice } from "@sharadox/web-library/style/definition";
|
|
1
2
|
/** The configuration reduced to what `applyStyle` needs. */
|
|
2
3
|
export function styleApplyData(configuration) {
|
|
3
4
|
return {
|
|
@@ -5,23 +6,26 @@ export function styleApplyData(configuration) {
|
|
|
5
6
|
schemes: Object.fromEntries(configuration.styles.map((style) => [style.name, style.scheme])),
|
|
6
7
|
defaults: { ...configuration.defaults },
|
|
7
8
|
fallback: configuration.fallback,
|
|
9
|
+
defaultChoice: defaultStyleChoice(configuration),
|
|
8
10
|
};
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Writes the style to `<html>`: `data-style` (the style in use), `data-style-choice` and `color-scheme`.
|
|
12
|
-
* Without a `choice` it reads the remembered one (or
|
|
14
|
+
* Without a `choice` it reads the remembered one (or the default choice). It is self-contained on purpose: the inline
|
|
13
15
|
* script in `<head>` embeds its source, so the page never shows the wrong style before React loads.
|
|
14
16
|
*/
|
|
15
17
|
export function applyStyle(data, choice) {
|
|
16
18
|
let wanted = choice;
|
|
17
19
|
if (wanted === undefined) {
|
|
18
20
|
try {
|
|
19
|
-
wanted = localStorage.getItem(data.storageKey) ||
|
|
21
|
+
wanted = localStorage.getItem(data.storageKey) || data.defaultChoice;
|
|
20
22
|
}
|
|
21
23
|
catch {
|
|
22
|
-
wanted =
|
|
24
|
+
wanted = data.defaultChoice;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
27
|
+
if (wanted !== "system" && !data.schemes[wanted])
|
|
28
|
+
wanted = data.defaultChoice;
|
|
25
29
|
if (wanted !== "system" && !data.schemes[wanted])
|
|
26
30
|
wanted = "system";
|
|
27
31
|
let name = wanted;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/apply/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/apply/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAI5E,4DAA4D;AAC5D,MAAM,UAAU,cAAc,CAAC,aAAiC;IAC9D,OAAO;QACL,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5F,QAAQ,EAAE,EAAE,GAAG,aAAa,CAAC,QAAQ,EAAE;QACvC,QAAQ,EAAE,aAAa,CAAC,QAAQ;QAChC,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC;KACjD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAoB,EAAE,MAAe;IAC9D,IAAI,MAAM,GAAG,MAAM,CAAC;IACpB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC;QACvE,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC;IAC9E,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,GAAG,QAAQ,CAAC;IACpE,IAAI,IAAI,GAAG,MAAM,CAAC;IAClB,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;QACxB,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC3B,IAAI,CAAC;YACH,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAC,OAAO;gBAAE,MAAM,GAAG,OAAO,CAAC;iBACrE,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC,OAAO;gBAAE,MAAM,GAAG,MAAM,CAAC;QAC/E,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;QACD,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC;IACtC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC;AAC/D,CAAC"}
|
|
@@ -6,5 +6,7 @@ export interface StyleApplyData {
|
|
|
6
6
|
schemes: Record<string, ColorScheme>;
|
|
7
7
|
defaults: Record<ColorScheme, string>;
|
|
8
8
|
fallback: ColorScheme;
|
|
9
|
+
/** "system" or a style name: used when nothing is remembered. */
|
|
10
|
+
defaultChoice: string;
|
|
9
11
|
}
|
|
10
12
|
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/style/apply/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAE/E,4GAA4G;AAC5G,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,EAAE,WAAW,CAAC;CACvB"}
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/style/apply/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAE/E,4GAA4G;AAC5G,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;IACtC,QAAQ,EAAE,WAAW,CAAC;IACtB,iEAAiE;IACjE,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -5,6 +5,8 @@ export declare const SYSTEM_STYLE = "system";
|
|
|
5
5
|
export declare const STYLE_ATTRIBUTE = "data-style";
|
|
6
6
|
/** `<html>` attribute holding the visitor's choice ("system" or a style name), for the picker. */
|
|
7
7
|
export declare const STYLE_CHOICE_ATTRIBUTE = "data-style-choice";
|
|
8
|
+
/** The configuration's starting choice: its `defaultChoice` when it names a style, otherwise "system". */
|
|
9
|
+
export declare function defaultStyleChoice(configuration: StyleConfiguration): string;
|
|
8
10
|
/** Finds a style by name. */
|
|
9
11
|
export declare function findStyle(configuration: StyleConfiguration, name: string): StyleDefinition | undefined;
|
|
10
12
|
/** The style shown for a choice: the chosen style, or for "system" (and unknown names) the default for the scheme. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAEpH,yGAAyG;AACzG,eAAO,MAAM,YAAY,WAAW,CAAC;AACrC,qFAAqF;AACrF,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,kGAAkG;AAClG,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D,6BAA6B;AAC7B,wBAAgB,SAAS,CAAC,aAAa,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAEtG;AAED,sHAAsH;AACtH,wBAAgB,YAAY,CAC1B,aAAa,EAAE,kBAAkB,EACjC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,WAAW,GAAG,SAAS,GACpC,eAAe,CASjB"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAEpH,yGAAyG;AACzG,eAAO,MAAM,YAAY,WAAW,CAAC;AACrC,qFAAqF;AACrF,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,kGAAkG;AAClG,eAAO,MAAM,sBAAsB,sBAAsB,CAAC;AAE1D,0GAA0G;AAC1G,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAG5E;AAED,6BAA6B;AAC7B,wBAAgB,SAAS,CAAC,aAAa,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAEtG;AAED,sHAAsH;AACtH,wBAAgB,YAAY,CAC1B,aAAa,EAAE,kBAAkB,EACjC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,WAAW,GAAG,SAAS,GACpC,eAAe,CASjB"}
|
|
@@ -4,6 +4,11 @@ export const SYSTEM_STYLE = "system";
|
|
|
4
4
|
export const STYLE_ATTRIBUTE = "data-style";
|
|
5
5
|
/** `<html>` attribute holding the visitor's choice ("system" or a style name), for the picker. */
|
|
6
6
|
export const STYLE_CHOICE_ATTRIBUTE = "data-style-choice";
|
|
7
|
+
/** The configuration's starting choice: its `defaultChoice` when it names a style, otherwise "system". */
|
|
8
|
+
export function defaultStyleChoice(configuration) {
|
|
9
|
+
const choice = configuration.defaultChoice;
|
|
10
|
+
return choice && configuration.styles.some((style) => style.name === choice) ? choice : SYSTEM_STYLE;
|
|
11
|
+
}
|
|
7
12
|
/** Finds a style by name. */
|
|
8
13
|
export function findStyle(configuration, name) {
|
|
9
14
|
return configuration.styles.find((style) => style.name === name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/definition/index.ts"],"names":[],"mappings":"AAEA,yGAAyG;AACzG,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AACrC,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAC5C,kGAAkG;AAClG,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,6BAA6B;AAC7B,MAAM,UAAU,SAAS,CAAC,aAAiC,EAAE,IAAY;IACvE,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,YAAY,CAC1B,aAAiC,EACjC,MAAc,EACd,YAAqC;IAErC,MAAM,MAAM,GAAG,MAAM,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;IACtF,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,MAAM,KAAK,GAAG,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC,YAAY,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvG,IAAI,CAAC,KAAK;QACR,MAAM,IAAI,KAAK,CACb,wCAAwC,aAAa,CAAC,Q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C,CAAC;IACvG,IAAI,CAAC,KAAK;QACR,MAAM,IAAI,KAAK,CACb,wCAAwC,aAAa,CAAC,QAAQ,CAAC,YAAY,IAAI,aAAa,CAAC,QAAQ,CAAC,GAAG,CAC1G,CAAC;IACJ,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -18,6 +18,11 @@ export interface StyleConfiguration {
|
|
|
18
18
|
fallback: ColorScheme;
|
|
19
19
|
/** Browser storage key that remembers a manual choice. */
|
|
20
20
|
storageKey: string;
|
|
21
|
+
/**
|
|
22
|
+
* The choice before the visitor picks one: "system" (follow the device, the default when left out) or a style
|
|
23
|
+
* name, such as "black" to open in Black whatever the device prefers.
|
|
24
|
+
*/
|
|
25
|
+
defaultChoice?: string;
|
|
21
26
|
}
|
|
22
27
|
/** What the visitor picked: "system" (follow the device) or a style name. */
|
|
23
28
|
export type StyleChoice = string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/style/definition/type.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,6FAA6F;IAC7F,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,+GAA+G;IAC/G,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C;AAED,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;IACnC,yEAAyE;IACzE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,qFAAqF;IACrF,QAAQ,EAAE,WAAW,CAAC;IACtB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/style/definition/type.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B,6FAA6F;IAC7F,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,WAAW,CAAC;IACpB,+GAA+G;IAC/G,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C;AAED,uFAAuF;AACvF,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;IACnC,yEAAyE;IACzE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,qFAAqF;IACrF,QAAQ,EAAE,WAAW,CAAC;IACtB,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,6EAA6E;AAC7E,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
2
|
/**
|
|
3
3
|
* The CSS for every style, from the configuration alone: `[data-style="<name>"]` for each style, plus a fallback for
|
|
4
|
-
* the moment before the inline script runs (or when scripts are off)
|
|
4
|
+
* the moment before the inline script runs (or when scripts are off): the default style, or when the default
|
|
5
|
+
* choice is "system", the style for the device's scheme.
|
|
5
6
|
*/
|
|
6
7
|
export declare function styleSheet(configuration: StyleConfiguration): string;
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/style-sheet/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,6CAA6C,CAAC;AAOvG
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/style-sheet/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,6CAA6C,CAAC;AAOvG;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAcpE"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import { findStyle } from "@sharadox/web-library/style/definition";
|
|
1
|
+
import { defaultStyleChoice, findStyle } from "@sharadox/web-library/style/definition";
|
|
2
2
|
const declarations = (style) => [...Object.entries(style.palette).map(([key, value]) => `--${key}:${value}`), `color-scheme:${style.scheme}`].join(";");
|
|
3
3
|
/**
|
|
4
4
|
* The CSS for every style, from the configuration alone: `[data-style="<name>"]` for each style, plus a fallback for
|
|
5
|
-
* the moment before the inline script runs (or when scripts are off)
|
|
5
|
+
* the moment before the inline script runs (or when scripts are off): the default style, or when the default
|
|
6
|
+
* choice is "system", the style for the device's scheme.
|
|
6
7
|
*/
|
|
7
8
|
export function styleSheet(configuration) {
|
|
9
|
+
const styles = configuration.styles.map((style) => `:root[data-style="${style.name}"]{${declarations(style)}}`);
|
|
10
|
+
const initial = findStyle(configuration, defaultStyleChoice(configuration));
|
|
11
|
+
// A fixed default style: that style until the script runs, whatever the device prefers.
|
|
12
|
+
if (initial)
|
|
13
|
+
return [`:root{${declarations(initial)}}`, ...styles].join("\n");
|
|
8
14
|
const fallback = findStyle(configuration, configuration.defaults[configuration.fallback]);
|
|
9
15
|
const other = configuration.fallback === "dark" ? "light" : "dark";
|
|
10
16
|
const otherDefault = findStyle(configuration, configuration.defaults[other]);
|
|
@@ -13,7 +19,7 @@ export function styleSheet(configuration) {
|
|
|
13
19
|
return [
|
|
14
20
|
`:root{${declarations(fallback)}}`,
|
|
15
21
|
`@media (prefers-color-scheme:${other}){:root:not([data-style]){${declarations(otherDefault)}}}`,
|
|
16
|
-
...
|
|
22
|
+
...styles,
|
|
17
23
|
].join("\n");
|
|
18
24
|
}
|
|
19
25
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/style-sheet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/style-sheet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAGvF,MAAM,YAAY,GAAG,CAAC,KAAsB,EAAE,EAAE,CAC9C,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,EAAE,gBAAgB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAChH,GAAG,CACJ,CAAC;AAEJ;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,aAAiC;IAC1D,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,qBAAqB,KAAK,CAAC,IAAI,MAAM,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChH,MAAM,OAAO,GAAG,SAAS,CAAC,aAAa,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;IAC5E,wFAAwF;IACxF,IAAI,OAAO;QAAE,OAAO,CAAC,SAAS,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,MAAM,QAAQ,GAAG,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1F,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACnE,MAAM,YAAY,GAAG,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACnG,OAAO;QACL,SAAS,YAAY,CAAC,QAAQ,CAAC,GAAG;QAClC,gCAAgC,KAAK,6BAA6B,YAAY,CAAC,YAAY,CAAC,IAAI;QAChG,GAAG,MAAM;KACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
2
|
import type { StyleState } from "@sharadox/web-library/style/use-style/type";
|
|
3
|
-
/** The visitor's style choice and the style in use, kept in sync with `<html>`; `choose` remembers a new choice. */
|
|
3
|
+
/** The visitor's style choice (the configuration's default until they pick one) and the style in use, kept in sync with `<html>`; `choose` remembers a new choice. */
|
|
4
4
|
export declare function useStyle(configuration: StyleConfiguration): StyleState;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/use-style/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAa7E,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/use-style/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAa7E,sKAAsK;AACtK,wBAAgB,QAAQ,CAAC,aAAa,EAAE,kBAAkB,GAAG,UAAU,CAqBtE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
3
3
|
import { applyStyle, styleApplyData } from "@sharadox/web-library/style/apply";
|
|
4
|
-
import { STYLE_ATTRIBUTE, STYLE_CHOICE_ATTRIBUTE
|
|
4
|
+
import { defaultStyleChoice, STYLE_ATTRIBUTE, STYLE_CHOICE_ATTRIBUTE } from "@sharadox/web-library/style/definition";
|
|
5
5
|
const subscribe = (notify) => {
|
|
6
6
|
const observer = new MutationObserver(notify);
|
|
7
7
|
observer.observe(document.documentElement, {
|
|
@@ -11,15 +11,18 @@ const subscribe = (notify) => {
|
|
|
11
11
|
return () => observer.disconnect();
|
|
12
12
|
};
|
|
13
13
|
const read = (attribute, fallback) => () => document.documentElement.getAttribute(attribute) ?? fallback;
|
|
14
|
-
/** The visitor's style choice and the style in use, kept in sync with `<html>`; `choose` remembers a new choice. */
|
|
14
|
+
/** The visitor's style choice (the configuration's default until they pick one) and the style in use, kept in sync with `<html>`; `choose` remembers a new choice. */
|
|
15
15
|
export function useStyle(configuration) {
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const initialChoice = defaultStyleChoice(configuration);
|
|
17
|
+
// What the server renders: the default style, or for "system" the fallback scheme's default.
|
|
18
|
+
const fallbackStyle = initialChoice === "system" ? configuration.defaults[configuration.fallback] : initialChoice;
|
|
19
|
+
const choice = useSyncExternalStore(subscribe, read(STYLE_CHOICE_ATTRIBUTE, initialChoice), () => initialChoice);
|
|
18
20
|
const style = useSyncExternalStore(subscribe, read(STYLE_ATTRIBUTE, fallbackStyle), () => fallbackStyle);
|
|
19
21
|
const data = useMemo(() => styleApplyData(configuration), [configuration]);
|
|
20
22
|
const choose = useCallback((next) => {
|
|
21
23
|
try {
|
|
22
|
-
|
|
24
|
+
// The default choice needs no memory; any other choice (including "system") is remembered.
|
|
25
|
+
if (next === data.defaultChoice)
|
|
23
26
|
localStorage.removeItem(data.storageKey);
|
|
24
27
|
else
|
|
25
28
|
localStorage.setItem(data.storageKey, next);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/use-style/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/use-style/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAIrH,MAAM,SAAS,GAAG,CAAC,MAAkB,EAAE,EAAE;IACvC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC9C,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,eAAe,EAAE;QACzC,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,CAAC,eAAe,EAAE,sBAAsB,CAAC;KAC3D,CAAC,CAAC;IACH,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;AACrC,CAAC,CAAC;AACF,MAAM,IAAI,GAAG,CAAC,SAAiB,EAAE,QAAgB,EAAE,EAAE,CAAC,GAAG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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Generic building blocks for web applications: internationalization, styles, search engine metadata, animation, time and forms.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|