@sharadox/web-library 0.4.1 → 0.5.1
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/LICENSE.md +22 -22
- package/README.md +41 -29
- package/distribution/assert/never/index.d.ts +13 -0
- package/distribution/assert/never/index.d.ts.map +1 -0
- package/distribution/assert/never/index.js +15 -0
- package/distribution/assert/never/index.js.map +1 -0
- package/distribution/class-name/index.d.ts +6 -1
- package/distribution/class-name/index.d.ts.map +1 -1
- package/distribution/class-name/index.js +6 -1
- package/distribution/class-name/index.js.map +1 -1
- package/distribution/html/escape/index.d.ts +6 -1
- package/distribution/html/escape/index.d.ts.map +1 -1
- package/distribution/html/escape/index.js +7 -2
- package/distribution/html/escape/index.js.map +1 -1
- package/distribution/math/clamp/index.d.ts +6 -1
- package/distribution/math/clamp/index.d.ts.map +1 -1
- package/distribution/math/clamp/index.js +6 -1
- package/distribution/math/clamp/index.js.map +1 -1
- package/distribution/math/pseudo-random/index.d.ts +6 -1
- package/distribution/math/pseudo-random/index.d.ts.map +1 -1
- package/distribution/math/pseudo-random/index.js +6 -1
- package/distribution/math/pseudo-random/index.js.map +1 -1
- package/distribution/math/radians/index.d.ts +6 -1
- package/distribution/math/radians/index.d.ts.map +1 -1
- package/distribution/math/radians/index.js +6 -1
- package/distribution/math/radians/index.js.map +1 -1
- package/distribution/text/separate/index.d.ts +9 -0
- package/distribution/text/separate/index.d.ts.map +1 -0
- package/distribution/text/separate/index.js +11 -0
- package/distribution/text/separate/index.js.map +1 -0
- package/distribution/type-guard/is-boolean/index.d.ts +8 -0
- package/distribution/type-guard/is-boolean/index.d.ts.map +1 -0
- package/distribution/type-guard/is-boolean/index.js +10 -0
- package/distribution/type-guard/is-boolean/index.js.map +1 -0
- package/distribution/type-guard/is-defined/index.d.ts +8 -0
- package/distribution/type-guard/is-defined/index.d.ts.map +1 -0
- package/distribution/type-guard/is-defined/index.js +10 -0
- package/distribution/type-guard/is-defined/index.js.map +1 -0
- package/distribution/type-guard/is-non-empty-string/index.d.ts +8 -0
- package/distribution/type-guard/is-non-empty-string/index.d.ts.map +1 -0
- package/distribution/type-guard/is-non-empty-string/index.js +11 -0
- package/distribution/type-guard/is-non-empty-string/index.js.map +1 -0
- package/distribution/type-guard/is-number/index.d.ts +9 -0
- package/distribution/type-guard/is-number/index.d.ts.map +1 -0
- package/distribution/type-guard/is-number/index.js +11 -0
- package/distribution/type-guard/is-number/index.js.map +1 -0
- package/distribution/type-guard/is-record/index.d.ts +9 -0
- package/distribution/type-guard/is-record/index.d.ts.map +1 -0
- package/distribution/type-guard/is-record/index.js +14 -0
- package/distribution/type-guard/is-record/index.js.map +1 -0
- package/distribution/type-guard/is-string/index.d.ts +9 -0
- package/distribution/type-guard/is-string/index.d.ts.map +1 -0
- package/distribution/type-guard/is-string/index.js +11 -0
- package/distribution/type-guard/is-string/index.js.map +1 -0
- package/llms.txt +17 -0
- package/package.json +17 -45
- package/distribution/animation/count-up/index.d.ts +0 -6
- package/distribution/animation/count-up/index.d.ts.map +0 -1
- package/distribution/animation/count-up/index.js +0 -29
- package/distribution/animation/count-up/index.js.map +0 -1
- package/distribution/animation/in-view/index.d.ts +0 -3
- package/distribution/animation/in-view/index.d.ts.map +0 -1
- package/distribution/animation/in-view/index.js +0 -15
- package/distribution/animation/in-view/index.js.map +0 -1
- package/distribution/animation/marquee/index.d.ts +0 -9
- package/distribution/animation/marquee/index.d.ts.map +0 -1
- package/distribution/animation/marquee/index.js +0 -78
- package/distribution/animation/marquee/index.js.map +0 -1
- package/distribution/animation/marquee/type.d.ts +0 -5
- package/distribution/animation/marquee/type.d.ts.map +0 -1
- package/distribution/animation/marquee/type.js +0 -2
- package/distribution/animation/marquee/type.js.map +0 -1
- package/distribution/animation/reveal/index.d.ts +0 -4
- package/distribution/animation/reveal/index.d.ts.map +0 -1
- package/distribution/animation/reveal/index.js +0 -9
- package/distribution/animation/reveal/index.js.map +0 -1
- package/distribution/animation/reveal/type.d.ts +0 -14
- package/distribution/animation/reveal/type.d.ts.map +0 -1
- package/distribution/animation/reveal/type.js +0 -2
- package/distribution/animation/reveal/type.js.map +0 -1
- package/distribution/animation/scroll-word/index.d.ts +0 -4
- package/distribution/animation/scroll-word/index.d.ts.map +0 -1
- package/distribution/animation/scroll-word/index.js +0 -16
- package/distribution/animation/scroll-word/index.js.map +0 -1
- package/distribution/animation/scroll-word/type.d.ts +0 -11
- package/distribution/animation/scroll-word/type.d.ts.map +0 -1
- package/distribution/animation/scroll-word/type.js +0 -2
- package/distribution/animation/scroll-word/type.js.map +0 -1
- package/distribution/animation/scroll-word/word/index.d.ts +0 -4
- package/distribution/animation/scroll-word/word/index.d.ts.map +0 -1
- package/distribution/animation/scroll-word/word/index.js +0 -10
- package/distribution/animation/scroll-word/word/index.js.map +0 -1
- package/distribution/animation/scroll-word/word/type.d.ts +0 -14
- package/distribution/animation/scroll-word/word/type.d.ts.map +0 -1
- package/distribution/animation/scroll-word/word/type.js +0 -2
- package/distribution/animation/scroll-word/word/type.js.map +0 -1
- package/distribution/animation/smooth-scroll/index.d.ts +0 -4
- package/distribution/animation/smooth-scroll/index.d.ts.map +0 -1
- package/distribution/animation/smooth-scroll/index.js +0 -33
- package/distribution/animation/smooth-scroll/index.js.map +0 -1
- package/distribution/animation/smooth-scroll/type.d.ts +0 -7
- package/distribution/animation/smooth-scroll/type.d.ts.map +0 -1
- package/distribution/animation/smooth-scroll/type.js +0 -2
- package/distribution/animation/smooth-scroll/type.js.map +0 -1
- package/distribution/form/bot-check/index.d.ts +0 -4
- package/distribution/form/bot-check/index.d.ts.map +0 -1
- package/distribution/form/bot-check/index.js +0 -6
- package/distribution/form/bot-check/index.js.map +0 -1
- package/distribution/form/bot-check/type.d.ts +0 -11
- package/distribution/form/bot-check/type.d.ts.map +0 -1
- package/distribution/form/bot-check/type.js +0 -2
- package/distribution/form/bot-check/type.js.map +0 -1
- package/distribution/form/field/index.d.ts +0 -3
- package/distribution/form/field/index.d.ts.map +0 -1
- package/distribution/form/field/index.js +0 -7
- package/distribution/form/field/index.js.map +0 -1
- package/distribution/form/rate-limit/index.d.ts +0 -4
- package/distribution/form/rate-limit/index.d.ts.map +0 -1
- package/distribution/form/rate-limit/index.js +0 -14
- package/distribution/form/rate-limit/index.js.map +0 -1
- package/distribution/form/rate-limit/type.d.ts +0 -9
- package/distribution/form/rate-limit/type.d.ts.map +0 -1
- package/distribution/form/rate-limit/type.js +0 -2
- package/distribution/form/rate-limit/type.js.map +0 -1
- package/distribution/internationalization/locale/index.d.ts +0 -7
- package/distribution/internationalization/locale/index.d.ts.map +0 -1
- package/distribution/internationalization/locale/index.js +0 -17
- package/distribution/internationalization/locale/index.js.map +0 -1
- package/distribution/internationalization/locale/type.d.ts +0 -3
- package/distribution/internationalization/locale/type.d.ts.map +0 -1
- package/distribution/internationalization/locale/type.js +0 -2
- package/distribution/internationalization/locale/type.js.map +0 -1
- package/distribution/internationalization/locale-preference/index.d.ts +0 -5
- package/distribution/internationalization/locale-preference/index.d.ts.map +0 -1
- package/distribution/internationalization/locale-preference/index.js +0 -9
- package/distribution/internationalization/locale-preference/index.js.map +0 -1
- package/distribution/internationalization/locale-redirect/index.d.ts +0 -8
- package/distribution/internationalization/locale-redirect/index.d.ts.map +0 -1
- package/distribution/internationalization/locale-redirect/index.js +0 -24
- package/distribution/internationalization/locale-redirect/index.js.map +0 -1
- package/distribution/internationalization/locale-redirect/type.d.ts +0 -12
- package/distribution/internationalization/locale-redirect/type.d.ts.map +0 -1
- package/distribution/internationalization/locale-redirect/type.js +0 -2
- package/distribution/internationalization/locale-redirect/type.js.map +0 -1
- package/distribution/internationalization/translate/index.d.ts +0 -4
- package/distribution/internationalization/translate/index.d.ts.map +0 -1
- package/distribution/internationalization/translate/index.js +0 -5
- package/distribution/internationalization/translate/index.js.map +0 -1
- package/distribution/pointer/spotlight/index.d.ts +0 -3
- package/distribution/pointer/spotlight/index.d.ts.map +0 -1
- package/distribution/pointer/spotlight/index.js +0 -20
- package/distribution/pointer/spotlight/index.js.map +0 -1
- package/distribution/pointer/tilt/index.d.ts +0 -7
- package/distribution/pointer/tilt/index.d.ts.map +0 -1
- package/distribution/pointer/tilt/index.js +0 -34
- package/distribution/pointer/tilt/index.js.map +0 -1
- package/distribution/privacy/consent/index.d.ts +0 -22
- package/distribution/privacy/consent/index.d.ts.map +0 -1
- package/distribution/privacy/consent/index.js +0 -75
- package/distribution/privacy/consent/index.js.map +0 -1
- package/distribution/privacy/consent/type.d.ts +0 -35
- package/distribution/privacy/consent/type.d.ts.map +0 -1
- package/distribution/privacy/consent/type.js +0 -2
- package/distribution/privacy/consent/type.js.map +0 -1
- package/distribution/privacy/use-consent/index.d.ts +0 -5
- package/distribution/privacy/use-consent/index.d.ts.map +0 -1
- package/distribution/privacy/use-consent/index.js +0 -22
- package/distribution/privacy/use-consent/index.js.map +0 -1
- package/distribution/privacy/use-consent/type.d.ts +0 -10
- package/distribution/privacy/use-consent/type.d.ts.map +0 -1
- package/distribution/privacy/use-consent/type.js +0 -2
- package/distribution/privacy/use-consent/type.js.map +0 -1
- package/distribution/scroll/active-section/index.d.ts +0 -7
- package/distribution/scroll/active-section/index.d.ts.map +0 -1
- package/distribution/scroll/active-section/index.js +0 -49
- package/distribution/scroll/active-section/index.js.map +0 -1
- package/distribution/scroll/active-section/type.d.ts +0 -9
- package/distribution/scroll/active-section/type.d.ts.map +0 -1
- package/distribution/scroll/active-section/type.js +0 -2
- package/distribution/scroll/active-section/type.js.map +0 -1
- package/distribution/search-engine/robots/index.d.ts +0 -4
- package/distribution/search-engine/robots/index.d.ts.map +0 -1
- package/distribution/search-engine/robots/index.js +0 -7
- package/distribution/search-engine/robots/index.js.map +0 -1
- package/distribution/search-engine/robots/type.d.ts +0 -17
- package/distribution/search-engine/robots/type.d.ts.map +0 -1
- package/distribution/search-engine/robots/type.js +0 -2
- package/distribution/search-engine/robots/type.js.map +0 -1
- package/distribution/search-engine/sitemap/index.d.ts +0 -4
- package/distribution/search-engine/sitemap/index.d.ts.map +0 -1
- package/distribution/search-engine/sitemap/index.js +0 -12
- package/distribution/search-engine/sitemap/index.js.map +0 -1
- package/distribution/search-engine/sitemap/type.d.ts +0 -22
- package/distribution/search-engine/sitemap/type.d.ts.map +0 -1
- package/distribution/search-engine/sitemap/type.js +0 -2
- package/distribution/search-engine/sitemap/type.js.map +0 -1
- package/distribution/search-engine/structured-data/index.d.ts +0 -4
- package/distribution/search-engine/structured-data/index.d.ts.map +0 -1
- package/distribution/search-engine/structured-data/index.js +0 -6
- package/distribution/search-engine/structured-data/index.js.map +0 -1
- package/distribution/search-engine/structured-data/type.d.ts +0 -5
- package/distribution/search-engine/structured-data/type.d.ts.map +0 -1
- package/distribution/search-engine/structured-data/type.js +0 -2
- package/distribution/search-engine/structured-data/type.js.map +0 -1
- package/distribution/style/apply/index.d.ts +0 -11
- package/distribution/style/apply/index.d.ts.map +0 -1
- package/distribution/style/apply/index.js +0 -50
- package/distribution/style/apply/index.js.map +0 -1
- package/distribution/style/apply/type.d.ts +0 -12
- package/distribution/style/apply/type.d.ts.map +0 -1
- package/distribution/style/apply/type.js +0 -2
- package/distribution/style/apply/type.js.map +0 -1
- package/distribution/style/definition/index.d.ts +0 -14
- package/distribution/style/definition/index.d.ts.map +0 -1
- package/distribution/style/definition/index.js +0 -26
- package/distribution/style/definition/index.js.map +0 -1
- package/distribution/style/definition/type.d.ts +0 -29
- package/distribution/style/definition/type.d.ts.map +0 -1
- package/distribution/style/definition/type.js +0 -2
- package/distribution/style/definition/type.js.map +0 -1
- package/distribution/style/style-script/index.d.ts +0 -10
- package/distribution/style/style-script/index.d.ts.map +0 -1
- package/distribution/style/style-script/index.js +0 -16
- package/distribution/style/style-script/index.js.map +0 -1
- package/distribution/style/style-script/type.d.ts +0 -5
- package/distribution/style/style-script/type.d.ts.map +0 -1
- package/distribution/style/style-script/type.js +0 -2
- package/distribution/style/style-script/type.js.map +0 -1
- package/distribution/style/style-sheet/index.d.ts +0 -8
- package/distribution/style/style-sheet/index.d.ts.map +0 -1
- package/distribution/style/style-sheet/index.js +0 -25
- package/distribution/style/style-sheet/index.js.map +0 -1
- package/distribution/style/use-style/index.d.ts +0 -5
- package/distribution/style/use-style/index.d.ts.map +0 -1
- package/distribution/style/use-style/index.js +0 -37
- package/distribution/style/use-style/index.js.map +0 -1
- package/distribution/style/use-style/type.d.ts +0 -9
- package/distribution/style/use-style/type.d.ts.map +0 -1
- package/distribution/style/use-style/type.js +0 -2
- package/distribution/style/use-style/type.js.map +0 -1
- package/distribution/test/visual-snapshot/index.d.ts +0 -8
- package/distribution/test/visual-snapshot/index.d.ts.map +0 -1
- package/distribution/test/visual-snapshot/index.js +0 -20
- package/distribution/test/visual-snapshot/index.js.map +0 -1
- package/distribution/test/visual-snapshot/type.d.ts +0 -7
- package/distribution/test/visual-snapshot/type.d.ts.map +0 -1
- package/distribution/test/visual-snapshot/type.js +0 -2
- package/distribution/test/visual-snapshot/type.js.map +0 -1
- package/distribution/time/format-time/index.d.ts +0 -3
- package/distribution/time/format-time/index.d.ts.map +0 -1
- package/distribution/time/format-time/index.js +0 -5
- package/distribution/time/format-time/index.js.map +0 -1
- package/distribution/time/open-state/index.d.ts +0 -4
- package/distribution/time/open-state/index.d.ts.map +0 -1
- package/distribution/time/open-state/index.js +0 -11
- package/distribution/time/open-state/index.js.map +0 -1
- package/distribution/time/open-state/type.d.ts +0 -5
- package/distribution/time/open-state/type.d.ts.map +0 -1
- package/distribution/time/open-state/type.js +0 -2
- package/distribution/time/open-state/type.js.map +0 -1
- package/distribution/time/sun-time/index.d.ts +0 -4
- package/distribution/time/sun-time/index.d.ts.map +0 -1
- package/distribution/time/sun-time/index.js +0 -27
- package/distribution/time/sun-time/index.js.map +0 -1
- package/distribution/time/sun-time/type.d.ts +0 -6
- package/distribution/time/sun-time/type.d.ts.map +0 -1
- package/distribution/time/sun-time/type.js +0 -2
- package/distribution/time/sun-time/type.js.map +0 -1
- package/distribution/time/sun-today/index.d.ts +0 -4
- package/distribution/time/sun-today/index.d.ts.map +0 -1
- package/distribution/time/sun-today/index.js +0 -25
- package/distribution/time/sun-today/index.js.map +0 -1
- package/distribution/time/sun-today/type.d.ts +0 -9
- package/distribution/time/sun-today/type.d.ts.map +0 -1
- package/distribution/time/sun-today/type.js +0 -2
- package/distribution/time/sun-today/type.js.map +0 -1
- package/distribution/time/zone-minute/index.d.ts +0 -3
- package/distribution/time/zone-minute/index.d.ts.map +0 -1
- package/distribution/time/zone-minute/index.js +0 -13
- package/distribution/time/zone-minute/index.js.map +0 -1
|
@@ -1,49 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/scroll/active-section/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG5C;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAsB;IACrD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAChG,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,KAAK,GAAG,CAAC,CAAC;YACV,MAAM,MAAM,GAAG,WAAW,GAAG,CAAC,CAAC;YAC/B,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,MAAM,GAAG,CAAC,CAAC;YACf,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;gBACrB,MAAM,OAAO,GAAG,QAAQ,CAAC,cAAc,CA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E,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"}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/scroll/active-section/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { RobotsOptions, RobotsRules } from "@sharadox/web-library/search-engine/robots/type";
|
|
2
|
-
/** robots.txt rules: everything allowed with the sitemap and host, or everything disallowed while not indexable. */
|
|
3
|
-
export declare function robots({ url, indexable }: RobotsOptions): RobotsRules;
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/search-engine/robots/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iDAAiD,CAAC;AAElG,oHAAoH;AACpH,wBAAgB,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,aAAa,GAAG,WAAW,CAIrE"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/** robots.txt rules: everything allowed with the sitemap and host, or everything disallowed while not indexable. */
|
|
2
|
-
export function robots({ url, indexable }) {
|
|
3
|
-
return indexable
|
|
4
|
-
? { rules: { userAgent: "*", allow: "/" }, sitemap: `${url}/sitemap.xml`, host: url }
|
|
5
|
-
: { rules: { userAgent: "*", disallow: "/" } };
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/search-engine/robots/index.ts"],"names":[],"mappings":"AAEA,oHAAoH;AACpH,MAAM,UAAU,MAAM,CAAC,EAAE,GAAG,EAAE,SAAS,EAAiB;IACtD,OAAO,SAAS;QACd,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,GAAG,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE;QACrF,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface RobotsOptions {
|
|
2
|
-
/** The site's public url without a trailing slash. */
|
|
3
|
-
url: string;
|
|
4
|
-
/** False keeps the whole site out of search engines (previews before a client launches). */
|
|
5
|
-
indexable: boolean;
|
|
6
|
-
}
|
|
7
|
-
/** The rules Next.js's `robots()` returns. */
|
|
8
|
-
export interface RobotsRules {
|
|
9
|
-
rules: {
|
|
10
|
-
userAgent: string;
|
|
11
|
-
allow?: string;
|
|
12
|
-
disallow?: string;
|
|
13
|
-
};
|
|
14
|
-
sitemap?: string;
|
|
15
|
-
host?: string;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/search-engine/robots/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC;IACZ,4FAA4F;IAC5F,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/search-engine/robots/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { LocalizedSitemapOptions, SitemapEntry } from "@sharadox/web-library/search-engine/sitemap/type";
|
|
2
|
-
/** A sitemap with one entry per locale (`/<locale>`), each listing every language version as an alternate. */
|
|
3
|
-
export declare function localizedSitemap({ url, locales, primaryLocale, otherPriority, changeFrequency, lastModified, }: LocalizedSitemapOptions): SitemapEntry[];
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/search-engine/sitemap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AAE9G,8GAA8G;AAC9G,wBAAgB,gBAAgB,CAAC,EAC/B,GAAG,EACH,OAAO,EACP,aAA0B,EAC1B,aAAiB,EACjB,eAA2B,EAC3B,YAAyB,GAC1B,EAAE,uBAAuB,GAAG,YAAY,EAAE,CAS1C"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/** A sitemap with one entry per locale (`/<locale>`), each listing every language version as an alternate. */
|
|
2
|
-
export function localizedSitemap({ url, locales, primaryLocale = locales[0], otherPriority = 1, changeFrequency = "monthly", lastModified = new Date(), }) {
|
|
3
|
-
const languages = Object.fromEntries(locales.map((locale) => [locale, `${url}/${locale}`]));
|
|
4
|
-
return locales.map((locale) => ({
|
|
5
|
-
url: `${url}/${locale}`,
|
|
6
|
-
lastModified,
|
|
7
|
-
changeFrequency,
|
|
8
|
-
priority: locale === primaryLocale ? 1 : otherPriority,
|
|
9
|
-
alternates: { languages },
|
|
10
|
-
}));
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/search-engine/sitemap/index.ts"],"names":[],"mappings":"AAEA,8GAA8G;AAC9G,MAAM,UAAU,gBAAgB,CAAC,EAC/B,GAAG,EACH,OAAO,EACP,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,EAC1B,aAAa,GAAG,CAAC,EACjB,eAAe,GAAG,SAAS,EAC3B,YAAY,GAAG,IAAI,IAAI,EAAE,GACD;IACxB,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5F,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC9B,GAAG,EAAE,GAAG,GAAG,IAAI,MAAM,EAAE;QACvB,YAAY;QACZ,eAAe;QACf,QAAQ,EAAE,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa;QACtD,UAAU,EAAE,EAAE,SAAS,EAAE;KAC1B,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface LocalizedSitemapOptions {
|
|
2
|
-
/** The site's public url without a trailing slash, for example "https://sharadox.com". */
|
|
3
|
-
url: string;
|
|
4
|
-
locales: readonly string[];
|
|
5
|
-
/** Gets priority 1; the other locales get `otherPriority`. Defaults to the first locale. */
|
|
6
|
-
primaryLocale?: string;
|
|
7
|
-
otherPriority?: number;
|
|
8
|
-
changeFrequency?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
|
|
9
|
-
/** Defaults to now. */
|
|
10
|
-
lastModified?: Date;
|
|
11
|
-
}
|
|
12
|
-
/** One sitemap entry, in the shape Next.js's `sitemap()` returns. */
|
|
13
|
-
export interface SitemapEntry {
|
|
14
|
-
url: string;
|
|
15
|
-
lastModified: Date;
|
|
16
|
-
changeFrequency: NonNullable<LocalizedSitemapOptions["changeFrequency"]>;
|
|
17
|
-
priority: number;
|
|
18
|
-
alternates: {
|
|
19
|
-
languages: Record<string, string>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/search-engine/sitemap/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,0FAA0F;IAC1F,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,4FAA4F;IAC5F,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IAC5F,uBAAuB;IACvB,YAAY,CAAC,EAAE,IAAI,CAAC;CACrB;AAED,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,IAAI,CAAC;IACnB,eAAe,EAAE,WAAW,CAAC,uBAAuB,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CACnD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/search-engine/sitemap/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { StructuredDataProperties } from "@sharadox/web-library/search-engine/structured-data/type";
|
|
2
|
-
/** Renders JSON-LD for search engines. `<` is escaped so the data can never close the script tag early. */
|
|
3
|
-
export declare function StructuredData({ data }: StructuredDataProperties): import("react").JSX.Element;
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/search-engine/structured-data/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0DAA0D,CAAC;AAEzG,2GAA2G;AAC3G,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,EAAE,wBAAwB,+BAOhE"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/** Renders JSON-LD for search engines. `<` is escaped so the data can never close the script tag early. */
|
|
3
|
-
export function StructuredData({ data }) {
|
|
4
|
-
return (_jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: JSON.stringify(data).replace(/</g, "\\u003c") } }));
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/search-engine/structured-data/index.tsx"],"names":[],"mappings":";AAEA,2GAA2G;AAC3G,MAAM,UAAU,cAAc,CAAC,EAAE,IAAI,EAA4B;IAC/D,OAAO,CACL,iBACE,IAAI,EAAC,qBAAqB,EAC1B,uBAAuB,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,GAClF,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/search-engine/structured-data/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,iHAAiH;IACjH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/search-engine/structured-data/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
import type { StyleApplyData } from "@sharadox/web-library/style/apply/type";
|
|
3
|
-
/** The configuration reduced to what `applyStyle` needs. */
|
|
4
|
-
export declare function styleApplyData(configuration: StyleConfiguration): StyleApplyData;
|
|
5
|
-
/**
|
|
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 the default choice). It is self-contained on purpose: the inline
|
|
8
|
-
* script in `<head>` embeds its source, so the page never shows the wrong style before React loads.
|
|
9
|
-
*/
|
|
10
|
-
export declare function applyStyle(data: StyleApplyData, choice?: string): void;
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,50 +0,0 @@
|
|
|
1
|
-
import { defaultStyleChoice } from "@sharadox/web-library/style/definition";
|
|
2
|
-
/** The configuration reduced to what `applyStyle` needs. */
|
|
3
|
-
export function styleApplyData(configuration) {
|
|
4
|
-
return {
|
|
5
|
-
storageKey: configuration.storageKey,
|
|
6
|
-
schemes: Object.fromEntries(configuration.styles.map((style) => [style.name, style.scheme])),
|
|
7
|
-
defaults: { ...configuration.defaults },
|
|
8
|
-
fallback: configuration.fallback,
|
|
9
|
-
defaultChoice: defaultStyleChoice(configuration),
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Writes the style to `<html>`: `data-style` (the style in use), `data-style-choice` and `color-scheme`.
|
|
14
|
-
* Without a `choice` it reads the remembered one (or the default choice). It is self-contained on purpose: the inline
|
|
15
|
-
* script in `<head>` embeds its source, so the page never shows the wrong style before React loads.
|
|
16
|
-
*/
|
|
17
|
-
export function applyStyle(data, choice) {
|
|
18
|
-
let wanted = choice;
|
|
19
|
-
if (wanted === undefined) {
|
|
20
|
-
try {
|
|
21
|
-
wanted = localStorage.getItem(data.storageKey) || data.defaultChoice;
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
wanted = data.defaultChoice;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (wanted !== "system" && !data.schemes[wanted])
|
|
28
|
-
wanted = data.defaultChoice;
|
|
29
|
-
if (wanted !== "system" && !data.schemes[wanted])
|
|
30
|
-
wanted = "system";
|
|
31
|
-
let name = wanted;
|
|
32
|
-
if (wanted === "system") {
|
|
33
|
-
let scheme = data.fallback;
|
|
34
|
-
try {
|
|
35
|
-
if (matchMedia("(prefers-color-scheme: light)").matches)
|
|
36
|
-
scheme = "light";
|
|
37
|
-
else if (matchMedia("(prefers-color-scheme: dark)").matches)
|
|
38
|
-
scheme = "dark";
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// No media queries: keep the fallback.
|
|
42
|
-
}
|
|
43
|
-
name = data.defaults[scheme];
|
|
44
|
-
}
|
|
45
|
-
const root = document.documentElement;
|
|
46
|
-
root.setAttribute("data-style", name);
|
|
47
|
-
root.setAttribute("data-style-choice", wanted);
|
|
48
|
-
root.style.colorScheme = data.schemes[name] ?? data.fallback;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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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AI,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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ColorScheme } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
/** The plain data `applyStyle` needs; it is serialized into the inline script, so it holds no functions. */
|
|
3
|
-
export interface StyleApplyData {
|
|
4
|
-
storageKey: string;
|
|
5
|
-
/** Style name → scheme. */
|
|
6
|
-
schemes: Record<string, ColorScheme>;
|
|
7
|
-
defaults: Record<ColorScheme, string>;
|
|
8
|
-
fallback: ColorScheme;
|
|
9
|
-
/** "system" or a style name: used when nothing is remembered. */
|
|
10
|
-
defaultChoice: string;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/style/apply/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ColorScheme, StyleConfiguration, StyleDefinition } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
/** The choice that follows the device's light or dark setting. It is the default and is never stored. */
|
|
3
|
-
export declare const SYSTEM_STYLE = "system";
|
|
4
|
-
/** `<html>` attribute holding the style in use, for CSS (`[data-style="black"]`). */
|
|
5
|
-
export declare const STYLE_ATTRIBUTE = "data-style";
|
|
6
|
-
/** `<html>` attribute holding the visitor's choice ("system" or a style name), for the picker. */
|
|
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;
|
|
10
|
-
/** Finds a style by name. */
|
|
11
|
-
export declare function findStyle(configuration: StyleConfiguration, name: string): StyleDefinition | undefined;
|
|
12
|
-
/** The style shown for a choice: the chosen style, or for "system" (and unknown names) the default for the scheme. */
|
|
13
|
-
export declare function resolveStyle(configuration: StyleConfiguration, choice: string, systemScheme: ColorScheme | undefined): StyleDefinition;
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/** The choice that follows the device's light or dark setting. It is the default and is never stored. */
|
|
2
|
-
export const SYSTEM_STYLE = "system";
|
|
3
|
-
/** `<html>` attribute holding the style in use, for CSS (`[data-style="black"]`). */
|
|
4
|
-
export const STYLE_ATTRIBUTE = "data-style";
|
|
5
|
-
/** `<html>` attribute holding the visitor's choice ("system" or a style name), for the picker. */
|
|
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
|
-
}
|
|
12
|
-
/** Finds a style by name. */
|
|
13
|
-
export function findStyle(configuration, name) {
|
|
14
|
-
return configuration.styles.find((style) => style.name === name);
|
|
15
|
-
}
|
|
16
|
-
/** The style shown for a choice: the chosen style, or for "system" (and unknown names) the default for the scheme. */
|
|
17
|
-
export function resolveStyle(configuration, choice, systemScheme) {
|
|
18
|
-
const chosen = choice === SYSTEM_STYLE ? undefined : findStyle(configuration, choice);
|
|
19
|
-
if (chosen)
|
|
20
|
-
return chosen;
|
|
21
|
-
const style = findStyle(configuration, configuration.defaults[systemScheme ?? configuration.fallback]);
|
|
22
|
-
if (!style)
|
|
23
|
-
throw new Error(`style configuration: no style named "${configuration.defaults[systemScheme ?? configuration.fallback]}"`);
|
|
24
|
-
return style;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-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,QAAQ,CAAC,GAAG,CAC1G,CAAC;IACJ,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/** Whether a style is dark or light. The system preference (`prefers-color-scheme`) is one of these. */
|
|
2
|
-
export type ColorScheme = "dark" | "light";
|
|
3
|
-
/** One style (what other projects call a theme): a name, its scheme and the CSS custom properties it sets. */
|
|
4
|
-
export interface StyleDefinition {
|
|
5
|
-
/** Lower-case identifier, stored and written to `<html data-style>`, for example `black`. */
|
|
6
|
-
name: string;
|
|
7
|
-
scheme: ColorScheme;
|
|
8
|
-
/** CSS custom properties without the leading dashes, for example `{ background: "#000" }` → `--background`. */
|
|
9
|
-
palette: Readonly<Record<string, string>>;
|
|
10
|
-
}
|
|
11
|
-
/** Every style a site offers, and how one is picked when the visitor hasn't chosen. */
|
|
12
|
-
export interface StyleConfiguration {
|
|
13
|
-
/** Any number of dark and light styles. */
|
|
14
|
-
styles: readonly StyleDefinition[];
|
|
15
|
-
/** The style used for each system scheme when the choice is "system". */
|
|
16
|
-
defaults: Readonly<Record<ColorScheme, string>>;
|
|
17
|
-
/** The scheme used when the system preference is unknown, and before scripts run. */
|
|
18
|
-
fallback: ColorScheme;
|
|
19
|
-
/** Browser storage key that remembers a manual choice. */
|
|
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;
|
|
26
|
-
}
|
|
27
|
-
/** What the visitor picked: "system" (follow the device) or a style name. */
|
|
28
|
-
export type StyleChoice = string;
|
|
29
|
-
//# sourceMappingURL=type.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/style/definition/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
import type { StyleScriptProperties } from "@sharadox/web-library/style/style-script/type";
|
|
3
|
-
/** The inline script: applies the remembered style, then follows the device and other tabs while the page is open. */
|
|
4
|
-
export declare function styleScript(configuration: StyleConfiguration): string;
|
|
5
|
-
/**
|
|
6
|
-
* Put in `<head>` (and add `suppressHydrationWarning` to `<html>`): every style's CSS custom properties, and the
|
|
7
|
-
* script that picks the style before the first paint.
|
|
8
|
-
*/
|
|
9
|
-
export declare function StyleScript({ configuration }: StyleScriptProperties): import("react").JSX.Element;
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/style/style-script/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAE3F,sHAAsH;AACtH,wBAAgB,WAAW,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAGrE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,aAAa,EAAE,EAAE,qBAAqB,+BAOnE"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { applyStyle, styleApplyData } from "@sharadox/web-library/style/apply";
|
|
3
|
-
import { styleSheet } from "@sharadox/web-library/style/style-sheet";
|
|
4
|
-
/** The inline script: applies the remembered style, then follows the device and other tabs while the page is open. */
|
|
5
|
-
export function styleScript(configuration) {
|
|
6
|
-
const data = JSON.stringify(styleApplyData(configuration)).replace(/</g, "\\u003c");
|
|
7
|
-
return `(function(){var apply=${applyStyle.toString()};var data=${data};apply(data);try{matchMedia("(prefers-color-scheme: light)").addEventListener("change",function(){apply(data)});addEventListener("storage",function(event){if(event.key===data.storageKey)apply(data)})}catch(error){}})();`;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Put in `<head>` (and add `suppressHydrationWarning` to `<html>`): every style's CSS custom properties, and the
|
|
11
|
-
* script that picks the style before the first paint.
|
|
12
|
-
*/
|
|
13
|
-
export function StyleScript({ configuration }) {
|
|
14
|
-
return (_jsxs(_Fragment, { children: [_jsx("style", { dangerouslySetInnerHTML: { __html: styleSheet(configuration) } }), _jsx("script", { dangerouslySetInnerHTML: { __html: styleScript(configuration) } })] }));
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/style/style-script/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAIrE,sHAAsH;AACtH,MAAM,UAAU,WAAW,CAAC,aAAiC;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACpF,OAAO,yBAAyB,UAAU,CAAC,QAAQ,EAAE,aAAa,IAAI,6NAA6N,CAAC;AACtS,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,aAAa,EAAyB;IAClE,OAAO,CACL,8BACE,gBAAO,uBAAuB,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC,EAAE,GAAI,EACzE,iBAAQ,uBAAuB,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,aAAa,CAAC,EAAE,GAAI,IAC1E,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../source/style/style-script/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEtF,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,kBAAkB,CAAC;CACnC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../source/style/style-script/type.ts"],"names":[],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
/**
|
|
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): the default style, or when the default
|
|
5
|
-
* choice is "system", the style for the device's scheme.
|
|
6
|
-
*/
|
|
7
|
-
export declare function styleSheet(configuration: StyleConfiguration): string;
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,25 +0,0 @@
|
|
|
1
|
-
import { defaultStyleChoice, findStyle } from "@sharadox/web-library/style/definition";
|
|
2
|
-
const declarations = (style) => [...Object.entries(style.palette).map(([key, value]) => `--${key}:${value}`), `color-scheme:${style.scheme}`].join(";");
|
|
3
|
-
/**
|
|
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): the default style, or when the default
|
|
6
|
-
* choice is "system", the style for the device's scheme.
|
|
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");
|
|
14
|
-
const fallback = findStyle(configuration, configuration.defaults[configuration.fallback]);
|
|
15
|
-
const other = configuration.fallback === "dark" ? "light" : "dark";
|
|
16
|
-
const otherDefault = findStyle(configuration, configuration.defaults[other]);
|
|
17
|
-
if (!fallback || !otherDefault)
|
|
18
|
-
throw new Error("style configuration: a default style is missing");
|
|
19
|
-
return [
|
|
20
|
-
`:root{${declarations(fallback)}}`,
|
|
21
|
-
`@media (prefers-color-scheme:${other}){:root:not([data-style]){${declarations(otherDefault)}}}`,
|
|
22
|
-
...styles,
|
|
23
|
-
].join("\n");
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import type { StyleConfiguration } from "@sharadox/web-library/style/definition/type";
|
|
2
|
-
import type { StyleState } from "@sharadox/web-library/style/use-style/type";
|
|
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
|
-
export declare function useStyle(configuration: StyleConfiguration): StyleState;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,37 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback, useMemo, useSyncExternalStore } from "react";
|
|
3
|
-
import { applyStyle, styleApplyData } from "@sharadox/web-library/style/apply";
|
|
4
|
-
import { defaultStyleChoice, STYLE_ATTRIBUTE, STYLE_CHOICE_ATTRIBUTE } from "@sharadox/web-library/style/definition";
|
|
5
|
-
const subscribe = (notify) => {
|
|
6
|
-
const observer = new MutationObserver(notify);
|
|
7
|
-
observer.observe(document.documentElement, {
|
|
8
|
-
attributes: true,
|
|
9
|
-
attributeFilter: [STYLE_ATTRIBUTE, STYLE_CHOICE_ATTRIBUTE],
|
|
10
|
-
});
|
|
11
|
-
return () => observer.disconnect();
|
|
12
|
-
};
|
|
13
|
-
const read = (attribute, fallback) => () => document.documentElement.getAttribute(attribute) ?? fallback;
|
|
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
|
-
export function useStyle(configuration) {
|
|
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);
|
|
20
|
-
const style = useSyncExternalStore(subscribe, read(STYLE_ATTRIBUTE, fallbackStyle), () => fallbackStyle);
|
|
21
|
-
const data = useMemo(() => styleApplyData(configuration), [configuration]);
|
|
22
|
-
const choose = useCallback((next) => {
|
|
23
|
-
try {
|
|
24
|
-
// The default choice needs no memory; any other choice (including "system") is remembered.
|
|
25
|
-
if (next === data.defaultChoice)
|
|
26
|
-
localStorage.removeItem(data.storageKey);
|
|
27
|
-
else
|
|
28
|
-
localStorage.setItem(data.storageKey, next);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
// Storage blocked (private mode): the choice still applies until the page closes.
|
|
32
|
-
}
|
|
33
|
-
applyStyle(data, next);
|
|
34
|
-
}, [data]);
|
|
35
|
-
return { choice, style, choose };
|
|
36
|
-
}
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
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