@sharadox/style-web-library 0.1.0 → 0.2.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 CHANGED
@@ -57,14 +57,14 @@ CSS uses each palette's keys as variables (`var(--background)`, `var(--radius)`)
57
57
 
58
58
  ## API
59
59
 
60
- | Import | Export |
61
- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
62
- | `…/definition` | `defineStyles(configuration)` (validated), `resolveOption`, `findGroup`, `findOption`, `SYSTEM_STYLE`, `styleAttribute`, `styleChoiceAttribute`, `styleStorageKey` |
63
- | `…/style-script` | `<StyleScript configuration>`, `styleScript(configuration)` (the inline script) |
64
- | `…/style-sheet` | `styleSheet(configuration)` (the CSS) |
65
- | `…/use-style` | `useStyle(configuration, group)` → `{ choice, style, choices, choose }` |
66
- | `…/style-choice` | `styleChoices(group)`: switch order (light options, System, dark options) |
67
- | `…/apply` | `applyStyles`, `styleApplyData` (used by the script) |
60
+ | Import | Export |
61
+ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62
+ | `…/definition` | `defineStyles(configuration)` (validated), `resolveOption`, `findGroup`, `findOption`, `SYSTEM_STYLE`, `styleAttribute`, `styleChoiceAttribute`, `styleStorageKey` |
63
+ | `…/style-script` | `<StyleScript configuration>`, `styleScript(configuration)` (the inline script); it also renders `StyleKeeper`, so styles survive navigations that replace `<html>` (switching language) |
64
+ | `…/style-sheet` | `styleSheet(configuration)` (the CSS) |
65
+ | `…/use-style` | `useStyle(configuration, group)` → `{ choice, style, choices, choose }` |
66
+ | `…/style-choice` | `styleChoices(group)`: switch order (light options, System, dark options) |
67
+ | `…/apply` | `applyStyles`, `styleApplyData` (used by the script) |
68
68
 
69
69
  **Choosing:**
70
70
 
@@ -0,0 +1,11 @@
1
+ import type { StyleKeeperProperties } from "@sharadox/style-web-library/style-keeper/type";
2
+ /**
3
+ * Applies every group's remembered style again whenever it mounts, before the browser paints. Navigating between
4
+ * pages with different root layout parameters (for example `/en` → `/pt`) replaces `<html>`, which drops the
5
+ * attributes the inline script set on the first load; this puts them back without a flash. `StyleScript` renders it.
6
+ *
7
+ * @example
8
+ * <StyleKeeper groups={styleApplyData(STYLES)} />
9
+ */
10
+ export declare function StyleKeeper({ groups }: StyleKeeperProperties): null;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-keeper/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAE3F;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,EAAE,qBAAqB,QAG5D"}
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { useLayoutEffect } from "react";
3
+ import { applyStyles } from "@sharadox/style-web-library/apply";
4
+ /**
5
+ * Applies every group's remembered style again whenever it mounts, before the browser paints. Navigating between
6
+ * pages with different root layout parameters (for example `/en` → `/pt`) replaces `<html>`, which drops the
7
+ * attributes the inline script set on the first load; this puts them back without a flash. `StyleScript` renders it.
8
+ *
9
+ * @example
10
+ * <StyleKeeper groups={styleApplyData(STYLES)} />
11
+ */
12
+ export function StyleKeeper({ groups }) {
13
+ useLayoutEffect(() => applyStyles(groups), [groups]);
14
+ return null;
15
+ }
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-keeper/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAGhE;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,EAAE,MAAM,EAAyB;IAC3D,eAAe,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { StyleGroupData } from "@sharadox/style-web-library/apply/type";
2
+ export interface StyleKeeperProperties {
3
+ /** The style groups, from `styleApplyData(configuration)`. */
4
+ groups: StyleGroupData[];
5
+ }
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/style-keeper/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E,MAAM,WAAW,qBAAqB;IACpC,8DAA8D;IAC9D,MAAM,EAAE,cAAc,EAAE,CAAC;CAC1B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/style-keeper/type.ts"],"names":[],"mappings":""}
@@ -7,7 +7,8 @@ import type { StyleScriptProperties } from "@sharadox/style-web-library/style-sc
7
7
  export declare function styleScript(configuration: StyleConfiguration): string;
8
8
  /**
9
9
  * Put in `<head>` (and add `suppressHydrationWarning` to `<html>`): the CSS custom properties of every style, and
10
- * the script that picks each group's style before the first paint.
10
+ * the script that picks each group's style before the first paint, and `StyleKeeper`, which picks it again when a
11
+ * navigation replaces `<html>` (for example switching language).
11
12
  *
12
13
  * @example
13
14
  * <html lang="en" suppressHydrationWarning><head><StyleScript configuration={STYLES} /></head>…</html>
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/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;;;GAGG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAGrE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,EAAE,aAAa,EAAE,EAAE,qBAAqB,+BAOnE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-script/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+CAA+C,CAAC;AAE3F;;;GAGG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAGrE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,EAAE,aAAa,EAAE,EAAE,qBAAqB,+BAQnE"}
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { applyStyles, styleApplyData } from "@sharadox/style-web-library/apply";
3
+ import { StyleKeeper } from "@sharadox/style-web-library/style-keeper";
3
4
  import { styleSheet } from "@sharadox/style-web-library/style-sheet";
4
5
  /**
5
6
  * The inline script: applies every group's remembered style before the first paint, then follows the device (for
@@ -11,12 +12,13 @@ export function styleScript(configuration) {
11
12
  }
12
13
  /**
13
14
  * Put in `<head>` (and add `suppressHydrationWarning` to `<html>`): the CSS custom properties of every style, and
14
- * the script that picks each group's style before the first paint.
15
+ * the script that picks each group's style before the first paint, and `StyleKeeper`, which picks it again when a
16
+ * navigation replaces `<html>` (for example switching language).
15
17
  *
16
18
  * @example
17
19
  * <html lang="en" suppressHydrationWarning><head><StyleScript configuration={STYLES} /></head>…</html>
18
20
  */
19
21
  export function StyleScript({ configuration }) {
20
- return (_jsxs(_Fragment, { children: [_jsx("style", { dangerouslySetInnerHTML: { __html: styleSheet(configuration) } }), _jsx("script", { dangerouslySetInnerHTML: { __html: styleScript(configuration) } })] }));
22
+ return (_jsxs(_Fragment, { children: [_jsx("style", { dangerouslySetInnerHTML: { __html: styleSheet(configuration) } }), _jsx("script", { dangerouslySetInnerHTML: { __html: styleScript(configuration) } }), _jsx(StyleKeeper, { groups: styleApplyData(configuration) })] }));
21
23
  }
22
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-script/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAIrE;;;GAGG;AACH,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,WAAW,CAAC,QAAQ,EAAE,eAAe,IAAI,0RAA0R,CAAC;AACtW,CAAC;AAED;;;;;;GAMG;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
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-script/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,0CAA0C,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AAIrE;;;GAGG;AACH,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,WAAW,CAAC,QAAQ,EAAE,eAAe,IAAI,0RAA0R,CAAC;AACtW,CAAC;AAED;;;;;;;GAOG;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,EAC3E,KAAC,WAAW,IAAC,MAAM,EAAE,cAAc,CAAC,aAAa,CAAC,GAAI,IACrD,CACJ,CAAC;AACJ,CAAC"}
package/llms.txt CHANGED
@@ -9,3 +9,4 @@
9
9
  - html attributes: data-style-<group>, data-style-<group>-choice; color-scheme set for groups with schemes
10
10
  - Storage: localStorage "style-<group>" (or storageKey); choosing the default removes it
11
11
  - Licence: Sharadox Open Source Licence 0.1.0
12
+ - /style-keeper StyleKeeper({ groups }) client component re-applying remembered styles on mount (rendered by StyleScript; fixes styles lost when a navigation replaces <html>, e.g. switching locale)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/style-web-library",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Styles (themes) for websites: several independent style groups (colour, corners, fonts…), each with options, a default, System following the device and a remembered choice, applied before the first paint.",
5
5
  "private": false,
6
6
  "license": "SEE LICENSE IN LICENCA.md",