@sharadox/style-web-library 0.0.0-stage → 0.1.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.
Files changed (50) hide show
  1. package/LICENCA.md +76 -0
  2. package/LICENSE.md +76 -0
  3. package/NOTICE.md +3 -0
  4. package/README.md +80 -2
  5. package/distribution/apply/index.d.ts +12 -0
  6. package/distribution/apply/index.d.ts.map +1 -0
  7. package/distribution/apply/index.js +57 -0
  8. package/distribution/apply/index.js.map +1 -0
  9. package/distribution/apply/type.d.ts +12 -0
  10. package/distribution/apply/type.d.ts.map +1 -0
  11. package/distribution/apply/type.js +2 -0
  12. package/distribution/apply/type.js.map +1 -0
  13. package/distribution/definition/index.d.ts +27 -0
  14. package/distribution/definition/index.d.ts.map +1 -0
  15. package/distribution/definition/index.js +58 -0
  16. package/distribution/definition/index.js.map +1 -0
  17. package/distribution/definition/type.d.ts +36 -0
  18. package/distribution/definition/type.d.ts.map +1 -0
  19. package/distribution/definition/type.js +2 -0
  20. package/distribution/definition/type.js.map +1 -0
  21. package/distribution/style-choice/index.d.ts +11 -0
  22. package/distribution/style-choice/index.d.ts.map +1 -0
  23. package/distribution/style-choice/index.js +20 -0
  24. package/distribution/style-choice/index.js.map +1 -0
  25. package/distribution/style-choice/type.d.ts +8 -0
  26. package/distribution/style-choice/type.d.ts.map +1 -0
  27. package/distribution/style-choice/type.js +2 -0
  28. package/distribution/style-choice/type.js.map +1 -0
  29. package/distribution/style-script/index.d.ts +16 -0
  30. package/distribution/style-script/index.d.ts.map +1 -0
  31. package/distribution/style-script/index.js +22 -0
  32. package/distribution/style-script/index.js.map +1 -0
  33. package/distribution/style-script/type.d.ts +5 -0
  34. package/distribution/style-script/type.d.ts.map +1 -0
  35. package/distribution/style-script/type.js +2 -0
  36. package/distribution/style-script/type.js.map +1 -0
  37. package/distribution/style-sheet/index.d.ts +11 -0
  38. package/distribution/style-sheet/index.d.ts.map +1 -0
  39. package/distribution/style-sheet/index.js +34 -0
  40. package/distribution/style-sheet/index.js.map +1 -0
  41. package/distribution/use-style/index.d.ts +11 -0
  42. package/distribution/use-style/index.d.ts.map +1 -0
  43. package/distribution/use-style/index.js +43 -0
  44. package/distribution/use-style/index.js.map +1 -0
  45. package/distribution/use-style/type.d.ts +12 -0
  46. package/distribution/use-style/type.d.ts.map +1 -0
  47. package/distribution/use-style/type.js +2 -0
  48. package/distribution/use-style/type.js.map +1 -0
  49. package/llms.txt +11 -0
  50. package/package.json +89 -3
package/LICENCA.md ADDED
@@ -0,0 +1,76 @@
1
+ # Licença Sharadox de Código Aberto
2
+
3
+ Versão 0.1.0
4
+
5
+ O texto em língua portuguesa é o único texto original e vinculativo desta licença. A tradução para inglês (`LICENSE.md`) é meramente informativa; em caso de divergência prevalece o texto em português.
6
+
7
+ ## 1. Definições
8
+
9
+ Para efeitos desta licença:
10
+
11
+ 1. **«Obra»** — o programa de computador, a sua documentação e quaisquer outros conteúdos disponibilizados pelo Licenciante ao abrigo desta licença, em código-fonte ou em qualquer outra forma.
12
+ 2. **«Licenciante»** — o titular dos direitos de autor identificado no aviso de direitos de autor que acompanha a Obra.
13
+ 3. **«Licenciado»** — qualquer pessoa, singular ou coletiva, que exerça os direitos concedidos por esta licença.
14
+ 4. **«Obra Derivada»** — qualquer obra baseada na Obra ou que a incorpore, total ou parcialmente, com ou sem modificações, incluindo traduções, adaptações e programas que a integrem.
15
+ 5. **«Aviso»** — o aviso de direitos de autor do Licenciante e a indicação de que a Obra está licenciada ao abrigo desta licença, incluindo a respetiva versão.
16
+
17
+ ## 2. Concessão de direitos
18
+
19
+ 1. Nos termos desta licença, o Licenciante concede ao Licenciado uma licença mundial, gratuita, não exclusiva e por todo o prazo de proteção dos direitos de autor para:
20
+ 1. utilizar a Obra para qualquer finalidade, incluindo finalidades comerciais;
21
+ 2. reproduzir a Obra, total ou parcialmente, por qualquer meio e sob qualquer forma;
22
+ 3. modificar, traduzir, adaptar e transformar a Obra e criar Obras Derivadas;
23
+ 4. distribuir, publicar, comunicar ao público, colocar à disposição, vender e sublicenciar a Obra e as Obras Derivadas.
24
+ 2. Na medida em que o Licenciante seja titular de patentes necessariamente infringidas pela Obra tal como por si disponibilizada, concede igualmente ao Licenciado, nos mesmos termos, uma licença para utilizar essas patentes no exercício dos direitos previstos no número anterior.
25
+ 3. Esta licença não transmite a titularidade de quaisquer direitos, que permanecem do Licenciante.
26
+
27
+ ## 3. Condições
28
+
29
+ O exercício dos direitos concedidos fica sujeito às seguintes condições:
30
+
31
+ 1. Todas as cópias da Obra, ou de partes substanciais da mesma, e todas as Obras Derivadas distribuídas devem incluir o Aviso e uma cópia desta licença ou uma ligação estável para o seu texto.
32
+ 2. Quem distribuir uma versão modificada da Obra deve indicar de forma visível que a mesma foi modificada, não podendo apresentá-la como versão original do Licenciante.
33
+ 3. O Licenciado pode licenciar as suas próprias modificações ao abrigo de outros termos, desde que a parte da Obra que delas faça parte continue sujeita às condições desta licença.
34
+
35
+ ## 4. Nomes e marcas
36
+
37
+ Esta licença não concede qualquer direito sobre o nome, as marcas, os logótipos ou outros sinais distintivos do Licenciante, incluindo a designação «Sharadox», salvo na medida estritamente necessária para cumprir o dever de incluir o Aviso. É proibido utilizá-los para promover ou sugerir o apoio do Licenciante a Obras Derivadas ou a quaisquer produtos ou serviços sem autorização prévia e escrita.
38
+
39
+ ## 5. Exclusão de garantias
40
+
41
+ A Obra é disponibilizada «tal como está» e «conforme disponível», sem qualquer garantia, expressa ou tácita, incluindo, designadamente, garantias de comerciabilidade, de adequação a um fim específico, de ausência de erros ou de não violação de direitos de terceiros, na medida máxima permitida pela lei aplicável.
42
+
43
+ ## 6. Limitação de responsabilidade
44
+
45
+ 1. Na medida máxima permitida pela lei aplicável, o Licenciante não é responsável por quaisquer danos, diretos ou indiretos, incluindo lucros cessantes, perda de dados ou interrupção de atividade, resultantes da utilização ou da impossibilidade de utilização da Obra, ainda que tenha sido avisado da possibilidade da sua ocorrência.
46
+ 2. Nada nesta licença exclui ou limita a responsabilidade do Licenciante nos casos em que tal exclusão ou limitação não seja permitida por lei, designadamente por atos praticados com dolo ou culpa grave, nos termos do artigo 809.º e do n.º 2 do artigo 800.º do Código Civil, nem afeta os direitos que a lei imperativamente reconheça aos consumidores.
47
+
48
+ ## 7. Cessação
49
+
50
+ 1. Os direitos concedidos por esta licença cessam automaticamente se o Licenciado violar qualquer das suas condições.
51
+ 2. Os direitos são repostos se a violação for sanada no prazo de 30 dias a contar do momento em que o Licenciado dela tome conhecimento, salvo se o Licenciante tiver entretanto comunicado por escrito a sua oposição.
52
+ 3. A cessação não afeta as licenças validamente concedidas pelo Licenciado a terceiros que cumpram esta licença.
53
+
54
+ ## 8. Lei aplicável e foro
55
+
56
+ 1. Esta licença rege-se pela lei portuguesa, designadamente pelo Código do Direito de Autor e dos Direitos Conexos, aprovado pelo Decreto-Lei n.º 63/85, de 14 de março, e pelo Decreto-Lei n.º 252/94, de 20 de outubro, relativo à proteção jurídica dos programas de computador.
57
+ 2. Para a resolução de quaisquer litígios emergentes desta licença é competente o Tribunal Judicial da Comarca de Faro, sem prejuízo das normas imperativas de competência aplicáveis, nomeadamente as que protegem os consumidores.
58
+
59
+ ## 9. Versões da licença
60
+
61
+ O Licenciante pode publicar novas versões desta licença, identificadas por um número de versão. A Obra fica sujeita à versão indicada no Aviso. O Licenciado pode, se o Aviso o permitir, optar por qualquer versão posterior.
62
+
63
+ ## 10. Disposições finais
64
+
65
+ 1. Se alguma disposição desta licença for considerada inválida ou ineficaz, as restantes mantêm-se em vigor, devendo a disposição afetada ser interpretada de forma a aproximar-se, tanto quanto possível, da intenção original.
66
+ 2. A não exigência, em qualquer momento, do cumprimento de uma disposição desta licença não constitui renúncia ao direito de o exigir posteriormente.
67
+
68
+ ## Como aplicar esta licença
69
+
70
+ Inclua na Obra um ficheiro `LICENCA.md` com este texto, a tradução `LICENSE.md` e o seguinte aviso, preenchendo o ano e o titular:
71
+
72
+ ```
73
+ Direitos de autor © <ano> <titular>.
74
+ Licenciado ao abrigo da Licença Sharadox de Código Aberto, versão 0.1.0.
75
+ https://github.com/Sharadox/sharadox-open-source-license
76
+ ```
package/LICENSE.md ADDED
@@ -0,0 +1,76 @@
1
+ # Sharadox Open Source Licence
2
+
3
+ Version 0.1.0
4
+
5
+ This is an informative English translation. The Portuguese text (`LICENCA.md`) is the only original and binding text of this licence; if the two differ, the Portuguese text prevails.
6
+
7
+ ## 1. Definitions
8
+
9
+ For the purposes of this licence:
10
+
11
+ 1. **"Work"** — the computer program, its documentation and any other content made available by the Licensor under this licence, in source code or in any other form.
12
+ 2. **"Licensor"** — the copyright holder identified in the copyright notice that accompanies the Work.
13
+ 3. **"Licensee"** — any natural or legal person exercising the rights granted by this licence.
14
+ 4. **"Derivative Work"** — any work based on or incorporating the Work, in whole or in part, with or without modifications, including translations, adaptations and programs that integrate it.
15
+ 5. **"Notice"** — the Licensor's copyright notice and the statement that the Work is licensed under this licence, including its version.
16
+
17
+ ## 2. Grant of rights
18
+
19
+ 1. Under this licence, the Licensor grants the Licensee a worldwide, royalty-free, non-exclusive licence, for the whole term of copyright protection, to:
20
+ 1. use the Work for any purpose, including commercial purposes;
21
+ 2. reproduce the Work, in whole or in part, by any means and in any form;
22
+ 3. modify, translate, adapt and transform the Work and create Derivative Works;
23
+ 4. distribute, publish, communicate to the public, make available, sell and sublicense the Work and Derivative Works.
24
+ 2. To the extent the Licensor holds patents necessarily infringed by the Work as made available by it, the Licensor also grants the Licensee, on the same terms, a licence to use those patents in exercising the rights in the previous paragraph.
25
+ 3. This licence does not transfer ownership of any rights, which remain with the Licensor.
26
+
27
+ ## 3. Conditions
28
+
29
+ The exercise of the rights granted is subject to the following conditions:
30
+
31
+ 1. Every copy of the Work, or of substantial parts of it, and every distributed Derivative Work must include the Notice and a copy of this licence or a stable link to its text.
32
+ 2. Anyone distributing a modified version of the Work must state visibly that it has been modified and may not present it as the Licensor's original version.
33
+ 3. The Licensee may license their own modifications under other terms, provided the part of the Work included in them remains subject to the conditions of this licence.
34
+
35
+ ## 4. Names and trademarks
36
+
37
+ This licence grants no rights to the Licensor's name, trademarks, logos or other distinctive signs, including the name "Sharadox", except as strictly necessary to comply with the duty to include the Notice. Using them to promote or suggest the Licensor's endorsement of Derivative Works or of any products or services without prior written permission is prohibited.
38
+
39
+ ## 5. Disclaimer of warranties
40
+
41
+ The Work is provided "as is" and "as available", without any warranty, express or implied, including in particular warranties of merchantability, fitness for a particular purpose, absence of errors or non-infringement of third-party rights, to the maximum extent permitted by applicable law.
42
+
43
+ ## 6. Limitation of liability
44
+
45
+ 1. To the maximum extent permitted by applicable law, the Licensor is not liable for any damages, direct or indirect, including loss of profits, loss of data or business interruption, arising from the use of or inability to use the Work, even if advised of the possibility of such damages.
46
+ 2. Nothing in this licence excludes or limits the Licensor's liability where such exclusion or limitation is not permitted by law, in particular for acts committed with intent or gross negligence, under article 809 and article 800(2) of the Portuguese Civil Code, nor does it affect rights that the law mandatorily grants to consumers.
47
+
48
+ ## 7. Termination
49
+
50
+ 1. The rights granted by this licence terminate automatically if the Licensee breaches any of its conditions.
51
+ 2. The rights are reinstated if the breach is remedied within 30 days of the Licensee becoming aware of it, unless the Licensor has meanwhile objected in writing.
52
+ 3. Termination does not affect licences validly granted by the Licensee to third parties who comply with this licence.
53
+
54
+ ## 8. Governing law and jurisdiction
55
+
56
+ 1. This licence is governed by Portuguese law, in particular the Code of Copyright and Related Rights, approved by Decree-Law no. 63/85 of 14 March, and Decree-Law no. 252/94 of 20 October on the legal protection of computer programs.
57
+ 2. The Judicial Court of the District of Faro has jurisdiction over any dispute arising from this licence, without prejudice to applicable mandatory rules of jurisdiction, in particular those protecting consumers.
58
+
59
+ ## 9. Licence versions
60
+
61
+ The Licensor may publish new versions of this licence, identified by a version number. The Work is subject to the version stated in the Notice. If the Notice allows it, the Licensee may choose any later version.
62
+
63
+ ## 10. Final provisions
64
+
65
+ 1. If any provision of this licence is held invalid or unenforceable, the remaining provisions stay in force, and the affected provision shall be interpreted as closely as possible to its original intent.
66
+ 2. Failure to enforce any provision of this licence at any time does not waive the right to enforce it later.
67
+
68
+ ## How to apply this licence
69
+
70
+ Include in the Work a `LICENCA.md` file with the Portuguese text, this translation as `LICENSE.md`, and the following notice, filling in the year and holder:
71
+
72
+ ```
73
+ Direitos de autor © <ano> <titular>.
74
+ Licenciado ao abrigo da Licença Sharadox de Código Aberto, versão 0.1.0.
75
+ https://github.com/Sharadox/sharadox-open-source-license
76
+ ```
package/NOTICE.md ADDED
@@ -0,0 +1,3 @@
1
+ Direitos de autor © 2026 Micael Pires (Sharadox).
2
+ Licenciado ao abrigo da Licença Sharadox de Código Aberto, versão 0.1.0.
3
+ https://github.com/Sharadox/sharadox-open-source-license
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @sharadox/style-web-library
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Styles (what other projects call themes) for websites, with **several independent style groups at once**: colour (Black, White, Midnight…), corners (sharp, rounded), font family, and so on. Each group has its own options, its default, an optional **System** choice that follows the device's light or dark setting, and a remembered manual choice. Everything is applied before the first paint, so the page never flashes the wrong style.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @sharadox/style-web-library
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```ts
14
+ // content/style.ts
15
+ import { defineStyles } from "@sharadox/style-web-library/definition";
16
+
17
+ export const STYLES = defineStyles({
18
+ groups: [
19
+ {
20
+ name: "color",
21
+ defaultChoice: "black", // or "system" to follow the device
22
+ systemDefaults: { dark: "black", light: "white" },
23
+ options: [
24
+ { name: "black", scheme: "dark", palette: { background: "#000", foreground: "#fff" } },
25
+ { name: "white", scheme: "light", palette: { background: "#fff", foreground: "#000" } },
26
+ ],
27
+ },
28
+ {
29
+ name: "corner",
30
+ defaultChoice: "rounded",
31
+ options: [
32
+ { name: "sharp", palette: { radius: "0" } },
33
+ { name: "rounded", palette: { radius: "12px" } },
34
+ ],
35
+ },
36
+ ],
37
+ });
38
+ ```
39
+
40
+ ```tsx
41
+ // src/app/[locale]/layout.tsx: every option's CSS variables, and the no-flash script
42
+ <html lang={lang} suppressHydrationWarning>
43
+ <head><StyleScript configuration={STYLES} /></head>
44
+ ```
45
+
46
+ ```tsx
47
+ // A switch for one group
48
+ const { choice, choices, choose } = useStyle(STYLES, "color");
49
+ choices.map((entry) => (
50
+ <button role="radio" aria-checked={choice === entry.name} onClick={() => choose(entry.name)}>
51
+ …
52
+ </button>
53
+ ));
54
+ ```
55
+
56
+ CSS uses each palette's keys as variables (`var(--background)`, `var(--radius)`). The `<html>` element carries `data-style-<group>` (the option in use) and `data-style-<group>-choice` (the visitor's choice).
57
+
58
+ ## API
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) |
68
+
69
+ **Choosing:**
70
+
71
+ - Choosing a group's default forgets the stored choice, and any other choice (including System) is remembered in browser storage under `style-<group>` (or `storageKey`).
72
+ - Unknown stored values fall back to the default.
73
+ - With System, the page follows the device and other tabs live.
74
+
75
+ ## Develop
76
+
77
+ `pnpm verify` runs formatting, lint, type-check, tests with 100% coverage and the build. Branches follow `<feature>.development` → `development` → `index`, and releases are `v<version>` tags on `index`.
78
+
79
+ ## Licence
80
+
81
+ Licença Sharadox de Código Aberto, versão 0.1.0. See [português](LICENCA.md) (the binding text) and the [English translation](LICENSE.md).
@@ -0,0 +1,12 @@
1
+ import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
2
+ import type { StyleGroupData } from "@sharadox/style-web-library/apply/type";
3
+ /** The configuration reduced to what `applyStyles` needs. */
4
+ export declare function styleApplyData(configuration: StyleConfiguration): StyleGroupData[];
5
+ /**
6
+ * Writes each group's option to `<html>` (`data-style-<group>` and `data-style-<group>-choice`), and CSS
7
+ * `color-scheme` for groups with schemes. With `only` and `choice`, applies that choice to that group; otherwise
8
+ * every group's remembered choice (or its default). It is self-contained on purpose: the inline script in
9
+ * `<head>` embeds its source, so the page never shows the wrong style before scripts load.
10
+ */
11
+ export declare function applyStyles(groups: StyleGroupData[], only?: string, choice?: string): void;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/apply/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E,6DAA6D;AAC7D,wBAAgB,cAAc,CAAC,aAAa,EAAE,kBAAkB,GAAG,cAAc,EAAE,CASlF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CA8B1F"}
@@ -0,0 +1,57 @@
1
+ import { styleStorageKey } from "@sharadox/style-web-library/definition";
2
+ /** The configuration reduced to what `applyStyles` needs. */
3
+ export function styleApplyData(configuration) {
4
+ return configuration.groups.map((group) => ({
5
+ name: group.name,
6
+ storageKey: styleStorageKey(group),
7
+ defaultChoice: group.defaultChoice,
8
+ options: Object.fromEntries(group.options.map((option) => [option.name, option.scheme ?? null])),
9
+ systemDefaults: group.systemDefaults ? { ...group.systemDefaults } : null,
10
+ fallbackScheme: group.fallbackScheme ?? "dark",
11
+ }));
12
+ }
13
+ /**
14
+ * Writes each group's option to `<html>` (`data-style-<group>` and `data-style-<group>-choice`), and CSS
15
+ * `color-scheme` for groups with schemes. With `only` and `choice`, applies that choice to that group; otherwise
16
+ * every group's remembered choice (or its default). It is self-contained on purpose: the inline script in
17
+ * `<head>` embeds its source, so the page never shows the wrong style before scripts load.
18
+ */
19
+ export function applyStyles(groups, only, choice) {
20
+ const root = document.documentElement;
21
+ for (const group of groups) {
22
+ if (only !== undefined && group.name !== only)
23
+ continue;
24
+ let wanted = only !== undefined ? choice : undefined;
25
+ if (wanted === undefined) {
26
+ try {
27
+ wanted = localStorage.getItem(group.storageKey) || group.defaultChoice;
28
+ }
29
+ catch {
30
+ wanted = group.defaultChoice;
31
+ }
32
+ }
33
+ const known = wanted === "system" ? group.systemDefaults !== null : group.options[wanted] !== undefined;
34
+ if (!known)
35
+ wanted = group.defaultChoice;
36
+ let name = wanted;
37
+ if (wanted === "system") {
38
+ let scheme = group.fallbackScheme;
39
+ try {
40
+ if (matchMedia("(prefers-color-scheme: light)").matches)
41
+ scheme = "light";
42
+ else if (matchMedia("(prefers-color-scheme: dark)").matches)
43
+ scheme = "dark";
44
+ }
45
+ catch {
46
+ // No media queries: keep the fallback.
47
+ }
48
+ name = group.systemDefaults[scheme];
49
+ }
50
+ root.setAttribute(`data-style-${group.name}`, name);
51
+ root.setAttribute(`data-style-${group.name}-choice`, wanted);
52
+ const scheme = group.options[name];
53
+ if (scheme)
54
+ root.style.colorScheme = scheme;
55
+ }
56
+ }
57
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/apply/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAIzE,6DAA6D;AAC7D,MAAM,UAAU,cAAc,CAAC,aAAiC;IAC9D,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAA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AAC,MAAM,CAAC,KAAK,SAAS,CAAC;QACxG,IAAI,CAAC,KAAK;YAAE,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC;QACzC,IAAI,IAAI,GAAG,MAAM,CAAC;QAClB,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,MAAM,GAAG,KAAK,CAAC,cAAc,CAAC;YAClC,IAAI,CAAC;gBACH,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAC,OAAO;oBAAE,MAAM,GAAG,OAAO,CAAC;qBACrE,IAAI,UAAU,CAAC,8BAA8B,CAAC,CAAC,OAAO;oBAAE,MAAM,GAAG,MAAM,CAAC;YAC/E,CAAC;YAAC,MAAM,CAAC;gBACP,uCAAuC;YACzC,CAAC;YACD,IAAI,GAAI,KAAK,CAAC,cAAyC,CAAC,MAAM,CAAW,CAAC;QAC5E,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,cAAc,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,CAAC,cAAc,KAAK,CAAC,IAAI,SAAS,EAAE,MAAM,CAAC,CAAC;QAC7D,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,MAAM;YAAE,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC;IAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ColorScheme } from "@sharadox/style-web-library/definition/type";
2
+ /** One group reduced to what `applyStyles` needs; plain data, so it can be embedded in the inline script. */
3
+ export interface StyleGroupData {
4
+ name: string;
5
+ storageKey: string;
6
+ defaultChoice: string;
7
+ /** Option name → its scheme, or null when the group has no schemes. */
8
+ options: Record<string, ColorScheme | null>;
9
+ systemDefaults: Record<ColorScheme, string> | null;
10
+ fallbackScheme: ColorScheme;
11
+ }
12
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/apply/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAE/E,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAAC,CAAC;IAC5C,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACnD,cAAc,EAAE,WAAW,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/apply/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ import type { ColorScheme, StyleConfiguration, StyleGroup, StyleOption } from "@sharadox/style-web-library/definition/type";
2
+ /** The choice that follows the device's light or dark setting. */
3
+ export declare const SYSTEM_STYLE = "system";
4
+ /** `<html>` attribute holding a group's option in use, for CSS: `[data-style-color="black"]`. */
5
+ export declare const styleAttribute: (group: string) => string;
6
+ /** `<html>` attribute holding a group's choice ("system" or an option), for switches. */
7
+ export declare const styleChoiceAttribute: (group: string) => string;
8
+ /** Where a group's manual choice is remembered. */
9
+ export declare const styleStorageKey: (group: StyleGroup) => string;
10
+ /** Finds an option of a group by name. */
11
+ export declare function findOption(group: StyleGroup, name: string): StyleOption | undefined;
12
+ /** Finds a group by name. */
13
+ export declare function findGroup(configuration: StyleConfiguration, name: string): StyleGroup | undefined;
14
+ /**
15
+ * Checks a style configuration and returns it: groups and options are unique, defaults name real options, and
16
+ * "system" is only used by groups whose options have schemes and `systemDefaults`.
17
+ *
18
+ * @example
19
+ * export const STYLES = defineStyles({ groups: [{ name: "color", defaultChoice: "black", options: [...], systemDefaults: { dark: "black", light: "white" } }] });
20
+ */
21
+ export declare function defineStyles<const Configuration extends StyleConfiguration>(configuration: Configuration): Configuration;
22
+ /**
23
+ * The option shown for a choice: the chosen option, or for "system" (and unknown names, which fall back to the
24
+ * group's default) the option for the device's scheme.
25
+ */
26
+ export declare function resolveOption(group: StyleGroup, choice: string, systemScheme: ColorScheme | undefined): StyleOption;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/definition/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,WAAW,EACZ,MAAM,6CAA6C,CAAC;AAErD,kEAAkE;AAClE,eAAO,MAAM,YAAY,WAAW,CAAC;AAErC,iGAAiG;AACjG,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,WAA0B,CAAC;AACvE,yFAAyF;AACzF,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,WAAiC,CAAC;AACpF,mDAAmD;AACnD,eAAO,MAAM,eAAe,GAAI,OAAO,UAAU,WAA8C,CAAC;AAEhG,0CAA0C;AAC1C,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAEnF;AAED,6BAA6B;AAC7B,wBAAgB,SAAS,CAAC,aAAa,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEjG;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,CAAC,aAAa,SAAS,kBAAkB,EACzE,aAAa,EAAE,aAAa,GAC3B,aAAa,CAkBf;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,CAKnH"}
@@ -0,0 +1,58 @@
1
+ /** The choice that follows the device's light or dark setting. */
2
+ export const SYSTEM_STYLE = "system";
3
+ /** `<html>` attribute holding a group's option in use, for CSS: `[data-style-color="black"]`. */
4
+ export const styleAttribute = (group) => `data-style-${group}`;
5
+ /** `<html>` attribute holding a group's choice ("system" or an option), for switches. */
6
+ export const styleChoiceAttribute = (group) => `data-style-${group}-choice`;
7
+ /** Where a group's manual choice is remembered. */
8
+ export const styleStorageKey = (group) => group.storageKey ?? `style-${group.name}`;
9
+ /** Finds an option of a group by name. */
10
+ export function findOption(group, name) {
11
+ return group.options.find((option) => option.name === name);
12
+ }
13
+ /** Finds a group by name. */
14
+ export function findGroup(configuration, name) {
15
+ return configuration.groups.find((group) => group.name === name);
16
+ }
17
+ /**
18
+ * Checks a style configuration and returns it: groups and options are unique, defaults name real options, and
19
+ * "system" is only used by groups whose options have schemes and `systemDefaults`.
20
+ *
21
+ * @example
22
+ * export const STYLES = defineStyles({ groups: [{ name: "color", defaultChoice: "black", options: [...], systemDefaults: { dark: "black", light: "white" } }] });
23
+ */
24
+ export function defineStyles(configuration) {
25
+ const groupNames = new Set();
26
+ for (const group of configuration.groups) {
27
+ if (groupNames.has(group.name))
28
+ throw new Error(`style group "${group.name}" is defined twice`);
29
+ groupNames.add(group.name);
30
+ const optionNames = new Set(group.options.map((option) => option.name));
31
+ if (optionNames.size !== group.options.length)
32
+ throw new Error(`style group "${group.name}" repeats an option`);
33
+ if (optionNames.has(SYSTEM_STYLE))
34
+ throw new Error(`"${SYSTEM_STYLE}" can't be an option name`);
35
+ if (group.systemDefaults) {
36
+ for (const name of Object.values(group.systemDefaults)) {
37
+ if (!optionNames.has(name))
38
+ throw new Error(`style group "${group.name}" has no option "${name}" for system`);
39
+ }
40
+ }
41
+ if (group.defaultChoice === SYSTEM_STYLE ? !group.systemDefaults : !optionNames.has(group.defaultChoice)) {
42
+ throw new Error(`style group "${group.name}" can't start with "${group.defaultChoice}"`);
43
+ }
44
+ }
45
+ return configuration;
46
+ }
47
+ /**
48
+ * The option shown for a choice: the chosen option, or for "system" (and unknown names, which fall back to the
49
+ * group's default) the option for the device's scheme.
50
+ */
51
+ export function resolveOption(group, choice, systemScheme) {
52
+ const wanted = choice === SYSTEM_STYLE || findOption(group, choice) ? choice : group.defaultChoice;
53
+ if (wanted !== SYSTEM_STYLE)
54
+ return findOption(group, wanted);
55
+ const scheme = systemScheme ?? group.fallbackScheme ?? "dark";
56
+ return findOption(group, group.systemDefaults[scheme]);
57
+ }
58
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/definition/index.ts"],"names":[],"mappings":"AAOA,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC;AAErC,iGAAiG;AACjG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,cAAc,KAAK,EAAE,CAAC;AACvE,yFAAyF;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,cAAc,KAAK,SAAS,CAAC;AACpF,mDAAmD;AACnD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,IAAI,SAAS,KAAK,CAAC,IAAI,EAAE,CAAC;AAEhG,0CAA0C;AAC1C,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,IAAY;IACxD,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC9D,CAAC;AAED,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;;;;;;GAMG;A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K,CAAC,gBAAgB,KAAK,CAAC,IAAI,uBAAuB,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,MAAc,EAAE,YAAqC;IACpG,MAAM,MAAM,GAAG,MAAM,KAAK,YAAY,IAAI,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;IACnG,IAAI,MAAM,KAAK,YAAY;QAAE,OAAO,UAAU,CAAC,KAAK,EAAE,MAAM,CAAE,CAAC;IAC/D,MAAM,MAAM,GAAG,YAAY,IAAI,KAAK,CAAC,cAAc,IAAI,MAAM,CAAC;IAC9D,OAAO,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,cAAe,CAAC,MAAM,CAAC,CAAE,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,36 @@
1
+ /** Whether a style is dark or light; the device's preference (`prefers-color-scheme`) is one of these. */
2
+ export type ColorScheme = "dark" | "light";
3
+ /** One option of a style group, for example the colour style "black" or the corner style "rounded". */
4
+ export interface StyleOption {
5
+ /** Lower-case identifier, stored and written to `<html data-style-<group>>`. */
6
+ name: string;
7
+ /** For colour-like groups: the option's scheme, which also sets CSS `color-scheme`. */
8
+ scheme?: ColorScheme;
9
+ /** CSS custom properties without the leading dashes: `{ background: "#000" }` → `--background: #000`. */
10
+ palette: Readonly<Record<string, string>>;
11
+ }
12
+ /**
13
+ * An independent style group: its own options, default, remembered choice and `<html>` attribute. A site can
14
+ * have several at once (colour, corner, font family…).
15
+ */
16
+ export interface StyleGroup {
17
+ /** Lower-case identifier, for example "color"; the attribute is `data-style-<name>`. */
18
+ name: string;
19
+ options: readonly StyleOption[];
20
+ /**
21
+ * The choice before the visitor picks one: an option name, or "system" (follow the device), which needs the
22
+ * options to have schemes and `systemDefaults`.
23
+ */
24
+ defaultChoice: string;
25
+ /** The option "system" uses for each scheme. */
26
+ systemDefaults?: Readonly<Record<ColorScheme, string>>;
27
+ /** The scheme assumed when the device's preference is unknown; "dark" by default. */
28
+ fallbackScheme?: ColorScheme;
29
+ /** Browser storage key that remembers a manual choice; `style-<name>` by default. */
30
+ storageKey?: string;
31
+ }
32
+ /** Every style group of a site. */
33
+ export interface StyleConfiguration {
34
+ groups: readonly StyleGroup[];
35
+ }
36
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/definition/type.ts"],"names":[],"mappings":"AAAA,0GAA0G;AAC1G,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,uGAAuG;AACvG,MAAM,WAAW,WAAW;IAC1B,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,yGAAyG;IACzG,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,wFAAwF;IACxF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC;;;OAGG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,gDAAgD;IAChD,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,qFAAqF;IACrF,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,qFAAqF;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,mCAAmC;AACnC,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,UAAU,EAAE,CAAC;CAC/B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/definition/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { StyleGroup } from "@sharadox/style-web-library/definition/type";
2
+ import type { StyleChoice } from "@sharadox/style-web-library/style-choice/type";
3
+ /**
4
+ * The entries of a group's switch, in display order. Groups with schemes put light options first, "system" in the
5
+ * middle and dark options last; other groups list their options in order.
6
+ *
7
+ * @example
8
+ * styleChoices(colorGroup).map((choice) => choice.name); // ["white", "system", "black"]
9
+ */
10
+ export declare function styleChoices(group: StyleGroup): StyleChoice[];
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-choice/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,EAAE,CAU7D"}
@@ -0,0 +1,20 @@
1
+ import { SYSTEM_STYLE } from "@sharadox/style-web-library/definition";
2
+ /**
3
+ * The entries of a group's switch, in display order. Groups with schemes put light options first, "system" in the
4
+ * middle and dark options last; other groups list their options in order.
5
+ *
6
+ * @example
7
+ * styleChoices(colorGroup).map((choice) => choice.name); // ["white", "system", "black"]
8
+ */
9
+ export function styleChoices(group) {
10
+ const option = (name, scheme) => ({
11
+ name,
12
+ kind: "option",
13
+ ...(scheme ? { scheme } : {}),
14
+ });
15
+ if (!group.systemDefaults)
16
+ return group.options.map((choice) => option(choice.name, choice.scheme));
17
+ const of = (scheme) => group.options.filter((choice) => choice.scheme === scheme).map((choice) => option(choice.name, scheme));
18
+ return [...of("light"), { name: SYSTEM_STYLE, kind: "system" }, ...of("dark")];
19
+ }
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-choice/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAItE;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,MAA8B,EAAe,EAAE,CAAC,CAAC;QAC7E,IAAI;QACJ,IAAI,EAAE,QAAQ;QACd,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC,CAAC;IACH,IAAI,CAAC,KAAK,CAAC,cAAc;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IACpG,MAAM,EAAE,GAAG,CAAC,MAAwB,EAAE,EAAE,CACtC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1G,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACjF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ColorScheme } from "@sharadox/style-web-library/definition/type";
2
+ /** One entry of a style switch: "system" or an option, with its scheme for icons. */
3
+ export interface StyleChoice {
4
+ name: string;
5
+ kind: "system" | "option";
6
+ scheme?: ColorScheme;
7
+ }
8
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/style-choice/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAE/E,qFAAqF;AACrF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/style-choice/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
2
+ import type { StyleScriptProperties } from "@sharadox/style-web-library/style-script/type";
3
+ /**
4
+ * The inline script: applies every group's remembered style before the first paint, then follows the device (for
5
+ * groups on "system") and other tabs while the page is open.
6
+ */
7
+ export declare function styleScript(configuration: StyleConfiguration): string;
8
+ /**
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.
11
+ *
12
+ * @example
13
+ * <html lang="en" suppressHydrationWarning><head><StyleScript configuration={STYLES} /></head>…</html>
14
+ */
15
+ export declare function StyleScript({ configuration }: StyleScriptProperties): import("react").JSX.Element;
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { applyStyles, styleApplyData } from "@sharadox/style-web-library/apply";
3
+ import { styleSheet } from "@sharadox/style-web-library/style-sheet";
4
+ /**
5
+ * The inline script: applies every group's remembered style before the first paint, then follows the device (for
6
+ * groups on "system") and other tabs while the page is open.
7
+ */
8
+ export function styleScript(configuration) {
9
+ const data = JSON.stringify(styleApplyData(configuration)).replace(/</g, "\\u003c");
10
+ return `(function(){var apply=${applyStyles.toString()};var groups=${data};apply(groups);try{matchMedia("(prefers-color-scheme: light)").addEventListener("change",function(){apply(groups)});addEventListener("storage",function(event){for(var index=0;index<groups.length;index++){if(groups[index].storageKey===event.key)apply(groups)}})}catch(error){}})();`;
11
+ }
12
+ /**
13
+ * 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
+ *
16
+ * @example
17
+ * <html lang="en" suppressHydrationWarning><head><StyleScript configuration={STYLES} /></head>…</html>
18
+ */
19
+ export function StyleScript({ configuration }) {
20
+ return (_jsxs(_Fragment, { children: [_jsx("style", { dangerouslySetInnerHTML: { __html: styleSheet(configuration) } }), _jsx("script", { dangerouslySetInnerHTML: { __html: styleScript(configuration) } })] }));
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,5 @@
1
+ import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
2
+ export interface StyleScriptProperties {
3
+ configuration: StyleConfiguration;
4
+ }
5
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/style-script/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
2
+ /**
3
+ * The CSS of every style group, from the configuration alone: each option under `:root[data-style-<group>="…"]`,
4
+ * plus each group's starting option on `:root` for the moment before the inline script runs (or when scripts are
5
+ * off). A group that starts on "system" follows the device with a media query until then.
6
+ *
7
+ * @example
8
+ * styleSheet(STYLES); // ":root{--background:#000;color-scheme:dark}\n:root[data-style-color=\"black\"]{…}"
9
+ */
10
+ export declare function styleSheet(configuration: StyleConfiguration): string;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/style-sheet/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAA2B,MAAM,6CAA6C,CAAC;AA0B/G;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,aAAa,EAAE,kBAAkB,GAAG,MAAM,CAEpE"}
@@ -0,0 +1,34 @@
1
+ import { findOption, SYSTEM_STYLE } from "@sharadox/style-web-library/definition";
2
+ const declarations = (option) => [
3
+ ...Object.entries(option.palette).map(([key, value]) => `--${key}:${value}`),
4
+ ...(option.scheme ? [`color-scheme:${option.scheme}`] : []),
5
+ ].join(";");
6
+ /** The CSS for one group: its starting option on `:root`, the device's scheme while it follows "system", and each option. */
7
+ function groupSheet(group) {
8
+ const attribute = `data-style-${group.name}`;
9
+ const rules = [];
10
+ if (group.defaultChoice === SYSTEM_STYLE) {
11
+ const fallback = group.fallbackScheme ?? "dark";
12
+ const other = fallback === "dark" ? "light" : "dark";
13
+ rules.push(`:root{${declarations(findOption(group, group.systemDefaults[fallback]))}}`);
14
+ rules.push(`@media (prefers-color-scheme:${other}){:root:not([${attribute}]){${declarations(findOption(group, group.systemDefaults[other]))}}}`);
15
+ }
16
+ else {
17
+ rules.push(`:root{${declarations(findOption(group, group.defaultChoice))}}`);
18
+ }
19
+ for (const option of group.options)
20
+ rules.push(`:root[${attribute}="${option.name}"]{${declarations(option)}}`);
21
+ return rules;
22
+ }
23
+ /**
24
+ * The CSS of every style group, from the configuration alone: each option under `:root[data-style-<group>="…"]`,
25
+ * plus each group's starting option on `:root` for the moment before the inline script runs (or when scripts are
26
+ * off). A group that starts on "system" follows the device with a media query until then.
27
+ *
28
+ * @example
29
+ * styleSheet(STYLES); // ":root{--background:#000;color-scheme:dark}\n:root[data-style-color=\"black\"]{…}"
30
+ */
31
+ export function styleSheet(configuration) {
32
+ return configuration.groups.flatMap(groupSheet).join("\n");
33
+ }
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/style-sheet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAGlF,MAAM,YAAY,GAAG,CAAC,MAAmB,EAAE,EAAE,CAC3C;IACE,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAC5E,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,gBAAgB,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;CAC5D,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEd,6HAA6H;AAC7H,SAAS,UAAU,CAAC,KAAiB;IACnC,MAAM,SAAS,GAAG,cAAc,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,CAAC,aAAa,KAAK,YAAY,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,cAAc,IAAI,MAAM,CAAC;QAChD,MAAM,KAAK,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;QACrD,KAAK,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,cAAe,CAAC,QAAQ,CAAC,CAAE,CAAC,GAAG,CAAC,CAAC;QAC1F,KAAK,CAAC,IAAI,CACR,gCAAgC,KAAK,gBAAgB,SAAS,MAAM,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,cAAe,CAAC,KAAK,CAAC,CAAE,CAAC,IAAI,CACvI,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAE,CAAC,GAAG,CAAC,CAAC;IAChF,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,SAAS,KAAK,MAAM,CAAC,IAAI,MAAM,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChH,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,aAAiC;IAC1D,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { StyleConfiguration } from "@sharadox/style-web-library/definition/type";
2
+ import type { StyleState } from "@sharadox/style-web-library/use-style/type";
3
+ /**
4
+ * A style group's choice and the option in use, kept in sync with `<html>`; `choose` remembers a new choice
5
+ * (choosing the group's default forgets it).
6
+ *
7
+ * @example
8
+ * const { choice, choices, choose } = useStyle(STYLES, "color");
9
+ */
10
+ export declare function useStyle(configuration: StyleConfiguration, groupName: string): StyleState;
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/use-style/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AAEtF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAE7E;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,aAAa,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAwCzF"}
@@ -0,0 +1,43 @@
1
+ "use client";
2
+ import { useCallback, useMemo, useSyncExternalStore } from "react";
3
+ import { applyStyles, styleApplyData } from "@sharadox/style-web-library/apply";
4
+ import { findGroup, styleAttribute, styleChoiceAttribute, styleStorageKey, SYSTEM_STYLE, } from "@sharadox/style-web-library/definition";
5
+ import { styleChoices } from "@sharadox/style-web-library/style-choice";
6
+ /**
7
+ * A style group's choice and the option in use, kept in sync with `<html>`; `choose` remembers a new choice
8
+ * (choosing the group's default forgets it).
9
+ *
10
+ * @example
11
+ * const { choice, choices, choose } = useStyle(STYLES, "color");
12
+ */
13
+ export function useStyle(configuration, groupName) {
14
+ const group = findGroup(configuration, groupName);
15
+ if (!group)
16
+ throw new Error(`no style group "${groupName}"`);
17
+ const attribute = styleAttribute(group.name);
18
+ const choiceAttribute = styleChoiceAttribute(group.name);
19
+ const starting = group.defaultChoice === SYSTEM_STYLE ? group.systemDefaults[group.fallbackScheme ?? "dark"] : group.defaultChoice;
20
+ const subscribe = useCallback((notify) => {
21
+ const observer = new MutationObserver(notify);
22
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: [attribute, choiceAttribute] });
23
+ return () => observer.disconnect();
24
+ }, [attribute, choiceAttribute]);
25
+ const choice = useSyncExternalStore(subscribe, () => document.documentElement.getAttribute(choiceAttribute) ?? group.defaultChoice, () => group.defaultChoice);
26
+ const style = useSyncExternalStore(subscribe, () => document.documentElement.getAttribute(attribute) ?? starting, () => starting);
27
+ const data = useMemo(() => styleApplyData(configuration), [configuration]);
28
+ const choose = useCallback((next) => {
29
+ try {
30
+ if (next === group.defaultChoice)
31
+ localStorage.removeItem(styleStorageKey(group));
32
+ else
33
+ localStorage.setItem(styleStorageKey(group), next);
34
+ }
35
+ catch {
36
+ // Storage blocked (private mode): the choice still applies until the page closes.
37
+ }
38
+ applyStyles(data, group.name, next);
39
+ }, [data, group]);
40
+ const choices = useMemo(() => styleChoices(group), [group]);
41
+ return { choice, style, choices, choose };
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {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} from "@sharadox/style-web-library/style-choice/type";
2
+ export interface StyleState {
3
+ /** What the visitor picked: "system" or an option name. */
4
+ choice: string;
5
+ /** The option in use right now. On the server and before hydration it is the group's starting option. */
6
+ style: string;
7
+ /** The switch's entries in display order. */
8
+ choices: StyleChoice[];
9
+ /** Picks an option (or "system"), remembers it and applies it at once. */
10
+ choose: (choice: string) => void;
11
+ }
12
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/use-style/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAEjF,MAAM,WAAW,UAAU;IACzB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;IACf,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,0EAA0E;IAC1E,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/use-style/type.ts"],"names":[],"mappings":""}
package/llms.txt ADDED
@@ -0,0 +1,11 @@
1
+ # @sharadox/style-web-library
2
+
3
+ > Multi-group styles (themes) for React/Next.js: each group (colour, corner, font…) has options with CSS-variable palettes, a default, optional "system" (prefers-color-scheme), and a remembered choice; applied pre-paint.
4
+
5
+ - defineStyles({ groups: [{ name, defaultChoice, options: [{ name, scheme?, palette }], systemDefaults?: { dark, light }, fallbackScheme?, storageKey? }] }) from `/definition` (validates)
6
+ - <StyleScript configuration={STYLES} /> in <head>, with <html suppressHydrationWarning>
7
+ - useStyle(STYLES, "color") → { choice, style, choices, choose } ("use client")
8
+ - styleChoices(group): order light options, "system", dark options (for switches)
9
+ - html attributes: data-style-<group>, data-style-<group>-choice; color-scheme set for groups with schemes
10
+ - Storage: localStorage "style-<group>" (or storageKey); choosing the default removes it
11
+ - Licence: Sharadox Open Source Licence 0.1.0
package/package.json CHANGED
@@ -1,6 +1,92 @@
1
1
  {
2
2
  "name": "@sharadox/style-web-library",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
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
+ "private": false,
6
+ "license": "SEE LICENSE IN LICENCA.md",
7
+ "author": "Sharadox <contact@sharadox.com>",
8
+ "type": "module",
9
+ "exports": {
10
+ "./*/type": {
11
+ "sharadox-source": "./source/*/type.ts",
12
+ "types": "./distribution/*/type.d.ts"
13
+ },
14
+ "./*": {
15
+ "sharadox-source": [
16
+ "./source/*/index.ts",
17
+ "./source/*/index.tsx"
18
+ ],
19
+ "types": "./distribution/*/index.d.ts",
20
+ "default": "./distribution/*/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "distribution",
25
+ "LICENCA.md",
26
+ "LICENSE.md",
27
+ "NOTICE.md",
28
+ "llms.txt"
29
+ ],
30
+ "sideEffects": [
31
+ "**/*.css"
32
+ ],
33
+ "engines": {
34
+ "node": ">=24"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "lint-staged": {
40
+ "*.{ts,tsx,js,mjs,cjs}": [
41
+ "prettier --write",
42
+ "eslint --fix --max-warnings=0"
43
+ ],
44
+ "*.{json,md,yml,yaml,scss}": "prettier --write"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/Sharadox/style-web-library.git"
49
+ },
50
+ "homepage": "https://github.com/Sharadox/style-web-library#readme",
51
+ "devDependencies": {
52
+ "@sharadox/es-lint-configuration-web-library": "^0.1.1",
53
+ "@sharadox/prettier-configuration-web-library": "^0.1.0",
54
+ "@sharadox/turborepo-configuration-web-library": "^0.1.0",
55
+ "@sharadox/type-script-configuration-web-library": "^0.2.0",
56
+ "@sharadox/vitest-configuration-web-library": "^0.1.2",
57
+ "@testing-library/dom": "^10.4.2",
58
+ "@testing-library/react": "^16.3.3",
59
+ "@types/node": "^24.19.2",
60
+ "@types/react": "^19.3.0",
61
+ "@types/react-dom": "^19.3.0",
62
+ "@vitest/coverage-v8": "^5.1.0",
63
+ "eslint": "9.39.5",
64
+ "happy-dom": "^21.0.4",
65
+ "husky": "^9.1.7",
66
+ "lint-staged": "^17.6.0",
67
+ "prettier": "^3.10.0",
68
+ "react": "^19.3.1",
69
+ "react-dom": "^19.3.1",
70
+ "turbo": "^2.11.10",
71
+ "typedoc": "^0.28.20",
72
+ "typescript": "6.0.3",
73
+ "vitest": "^5.1.0"
74
+ },
75
+ "dependencies": {
76
+ "@sharadox/web-library": "^0.5.0"
77
+ },
78
+ "peerDependencies": {
79
+ "react": ">=19"
80
+ },
81
+ "scripts": {
82
+ "build": "rm -rf distribution && tsc -p tsconfig.build.json",
83
+ "lint": "eslint --max-warnings=0 .",
84
+ "format": "prettier --write .",
85
+ "format:check": "prettier --check .",
86
+ "type-check": "tsc --noEmit",
87
+ "test:unit": "vitest run --coverage",
88
+ "documentation": "typedoc",
89
+ "verify": "turbo run format:check lint type-check test:unit build",
90
+ "test:benchmark": "vitest bench --run --passWithNoTests"
91
+ }
6
92
  }