@riebeckite/plugin-color-mode 0.0.31 → 0.0.33
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 +9 -5
- package/README_ja.md +21 -17
- package/dist/components/color-mode-toggle.d.ts +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -5
- package/package.json +3 -3
- package/style.css +18 -1
package/README.md
CHANGED
|
@@ -9,6 +9,10 @@ needs no JavaScript in the theme itself.
|
|
|
9
9
|
|
|
10
10
|
[日本語](./README_ja.md)
|
|
11
11
|
|
|
12
|
+
## Live example
|
|
13
|
+
|
|
14
|
+
The color-mode control in the site header is this plugin's UI. Switch it between light, dark, and system: the page updates immediately and the choice is stored for the next visit.
|
|
15
|
+
|
|
12
16
|
## Overview
|
|
13
17
|
|
|
14
18
|
Themes derive their palette from three CSS states (see
|
|
@@ -26,7 +30,7 @@ The plugin is a thin runtime switch over that contract:
|
|
|
26
30
|
- `initColorMode` — the client entry that binds the buttons, persists the
|
|
27
31
|
choice in `localStorage` and keeps the document in sync.
|
|
28
32
|
|
|
29
|
-
`
|
|
33
|
+
`colorMode()` itself only registers the stylesheet and the client entry;
|
|
30
34
|
everything else is delivered through the two components you render in your site
|
|
31
35
|
shell.
|
|
32
36
|
|
|
@@ -34,15 +38,15 @@ shell.
|
|
|
34
38
|
|
|
35
39
|
```ts
|
|
36
40
|
import { defineConfig } from "@riebeckite/core";
|
|
37
|
-
import {
|
|
41
|
+
import { colorMode } from "@riebeckite/plugin-color-mode";
|
|
38
42
|
|
|
39
43
|
export default defineConfig({
|
|
40
44
|
// ...
|
|
41
|
-
plugins: [
|
|
45
|
+
plugins: [colorMode()],
|
|
42
46
|
});
|
|
43
47
|
```
|
|
44
48
|
|
|
45
|
-
`
|
|
49
|
+
`colorMode()` bundles `style.css` and declares `initColorMode` as a client
|
|
46
50
|
entry.
|
|
47
51
|
|
|
48
52
|
### Render the components
|
|
@@ -159,7 +163,7 @@ diagrams) can follow mode changes in the future.
|
|
|
159
163
|
|
|
160
164
|
## Exports
|
|
161
165
|
|
|
162
|
-
- `
|
|
166
|
+
- `colorMode()` — plugin factory
|
|
163
167
|
- `ColorModeToggle` — the switch component
|
|
164
168
|
- `ColorModeScript` — the before-paint inline script component
|
|
165
169
|
- `initColorMode` — browser init (also exported by `@riebeckite/plugin-color-mode/client`)
|
package/README_ja.md
CHANGED
|
@@ -6,35 +6,39 @@ Riebeckite サイト向けのライト / ダーク / システム連動のカラ
|
|
|
6
6
|
|
|
7
7
|
[English](./README.md)
|
|
8
8
|
|
|
9
|
+
## 実行例
|
|
10
|
+
|
|
11
|
+
サイトヘッダーにあるカラーモードのコントロールが、このプラグインの UI です。ライト・ダーク・システムを切り替えるとページが即座に変わり、選択は次回の訪問のために保存されます。
|
|
12
|
+
|
|
9
13
|
## 概要
|
|
10
14
|
|
|
11
|
-
[
|
|
15
|
+
[テーマシステム](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/theme-api.ja.md) のテーマは、次の 3 つの CSS 状態から配色を決めます。
|
|
12
16
|
|
|
13
17
|
- `:root`:ライト
|
|
14
18
|
- `:root[data-theme="dark"]`:ダーク
|
|
15
19
|
- `@media (prefers-color-scheme: dark) { :root:not([data-theme]) }`:OS に追随(system)
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
このプラグインは、その取り決めを切り替えるだけの薄い実行時スイッチで、次の 3 つを提供します。
|
|
18
22
|
|
|
19
|
-
- `ColorModeScript`:`<head>` に置く 1
|
|
20
|
-
- `ColorModeToggle`:ライト / ダーク /
|
|
21
|
-
- `initColorMode
|
|
23
|
+
- `ColorModeScript`:`<head>` に置く 1 行のインラインスクリプトです。**最初の描画の前に**保存済みのモードを適用し、テーマのちらつき(FOUC)を防ぎます。
|
|
24
|
+
- `ColorModeToggle`:ライト / ダーク / システムを選ぶセグメントコントロール。
|
|
25
|
+
- `initColorMode`:クライアントエントリー。ボタンの結線、`localStorage` への保存、ドキュメントの状態同期を行います。
|
|
22
26
|
|
|
23
|
-
`
|
|
27
|
+
`colorMode()` はスタイルシートとクライアントエントリーの登録だけを行います。UI は、サイトシェルで描画する 2 つのコンポーネントが担います。
|
|
24
28
|
|
|
25
29
|
## 使い方
|
|
26
30
|
|
|
27
31
|
```ts
|
|
28
32
|
import { defineConfig } from "@riebeckite/core";
|
|
29
|
-
import {
|
|
33
|
+
import { colorMode } from "@riebeckite/plugin-color-mode";
|
|
30
34
|
|
|
31
35
|
export default defineConfig({
|
|
32
36
|
// ...
|
|
33
|
-
plugins: [
|
|
37
|
+
plugins: [colorMode()],
|
|
34
38
|
});
|
|
35
39
|
```
|
|
36
40
|
|
|
37
|
-
`
|
|
41
|
+
`colorMode()` は `style.css` をバンドルし、`initColorMode` をクライアントエントリとして宣言します。
|
|
38
42
|
|
|
39
43
|
### コンポーネントの描画
|
|
40
44
|
|
|
@@ -61,7 +65,7 @@ return (
|
|
|
61
65
|
|
|
62
66
|
`<ColorModeScript />` は CSS が適用される前にモードが確定するよう、スタイルシートより先に `<head>` へ置いてください。`<ColorModeToggle />` はヘッダーやナビバーなど任意の場所に配置できます。
|
|
63
67
|
|
|
64
|
-
###
|
|
68
|
+
### 受け取る props
|
|
65
69
|
|
|
66
70
|
`ColorModeScript`
|
|
67
71
|
|
|
@@ -76,7 +80,7 @@ return (
|
|
|
76
80
|
| `storageKey` | 保存先の localStorage キー。既定値は `riebeckite-color-mode`。 |
|
|
77
81
|
| `modes` | 表示するモード(順序付き)。既定値は `["light", "dark", "system"]`。 |
|
|
78
82
|
| `labels` | モードごとの `aria-label` 上書き: `{ light?, dark?, system? }`。 |
|
|
79
|
-
| `label` |
|
|
83
|
+
| `label` | グループ名に使う文言。視覚的に隠した `<legend>` として描画されます。既定値は `"Color mode"`。 |
|
|
80
84
|
|
|
81
85
|
ストレージキーを変更する場合は、両コンポーネントで同じ値を指定してください。
|
|
82
86
|
|
|
@@ -98,12 +102,12 @@ return (
|
|
|
98
102
|
|
|
99
103
|
スタイルシートは `--rb-color-*` トークンを使うため、アクティブなテーマに追従します。ルートは `display: none` で、`initColorMode`(またはインラインスクリプト)が `<html>` に `data-rb-color-mode="ready"` を付けるまで非表示です。JavaScript が無効なページではコントロールそのものが現れません。
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
テーマは `rr-color-mode` のルート要素に `--rr-color-mode-border-radius` を指定すると、
|
|
106
|
+
子要素を選択せずにコンテナとボタンで共有する角丸を変更できます。
|
|
103
107
|
|
|
104
108
|
## アクセシビリティ
|
|
105
109
|
|
|
106
|
-
- コンテナは `<fieldset>`
|
|
110
|
+
- コンテナは `<fieldset>` で、グループ名は視覚的に隠した `<legend>` が提供します。文言は `label` プロップで指定します。
|
|
107
111
|
- 各ボタンは `type="button"` でモード名の `aria-label` を持ち、アクティブなボタンには実行時設定の `aria-pressed="true"` が付きます。
|
|
108
112
|
- アイコンは装飾(`aria-hidden`)。ラベルはボタンから提供されます。
|
|
109
113
|
- `prefers-reduced-motion` ではトランジションを無効化します。
|
|
@@ -127,12 +131,12 @@ document.addEventListener("riebeckite:color-mode", (event) => {
|
|
|
127
131
|
- `localStorage` へのアクセスは `try/catch` で保護しています。ストレージが使えない環境でも、そのページでは切替が機能します(永続化のみされません)。
|
|
128
132
|
- 1 ページに複数のトグルを置く場合は、同じ `storageKey` を共有してください。
|
|
129
133
|
|
|
130
|
-
##
|
|
134
|
+
## エクスポート
|
|
131
135
|
|
|
132
|
-
- `
|
|
136
|
+
- `colorMode()`:プラグインファクトリ
|
|
133
137
|
- `ColorModeToggle`:切替コンポーネント
|
|
134
138
|
- `ColorModeScript`:描画前インラインスクリプトのコンポーネント
|
|
135
|
-
- `initColorMode`:ブラウザ初期化関数(`@riebeckite/plugin-color-mode/client`
|
|
139
|
+
- `initColorMode`:ブラウザ初期化関数(`@riebeckite/plugin-color-mode/client` からもエクスポート)
|
|
136
140
|
- 定数: `COLOR_MODES` / `COLOR_MODE_STORAGE_KEY` / `COLOR_MODE_EVENT` ほか
|
|
137
141
|
- 型: `ColorMode`
|
|
138
142
|
|
|
@@ -8,10 +8,11 @@ export type ColorModeToggleProps = {
|
|
|
8
8
|
readonly labels?: Readonly<Partial<Record<ColorMode, string>>>;
|
|
9
9
|
/** Group label, used as the `<legend>`. */
|
|
10
10
|
readonly label?: string;
|
|
11
|
+
readonly placement?: "inline" | "floating";
|
|
11
12
|
};
|
|
12
13
|
/**
|
|
13
14
|
* Server-rendered control to switch between light, dark and system color
|
|
14
15
|
* modes. The active state is applied by `initColorMode` at runtime; until the
|
|
15
16
|
* client runs the control is hidden by the stylesheet.
|
|
16
17
|
*/
|
|
17
|
-
export default function ColorModeToggle({ storageKey, modes, labels, label, }: ColorModeToggleProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
|
|
18
|
+
export default function ColorModeToggle({ storageKey, modes, labels, label, placement, }: ColorModeToggleProps): import("hono/jsx/jsx-dev-runtime").JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export { initColorMode } from "./src/init.js";
|
|
|
6
6
|
* Registers the color-mode plugin: bundles the toggle stylesheet and declares
|
|
7
7
|
* `initColorMode` as the browser entry point that wires up toggling at runtime.
|
|
8
8
|
*/
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function colorMode(): import("@riebeckite/core").RiebeckitePlugin<unknown>;
|
package/dist/index.js
CHANGED
|
@@ -36,12 +36,13 @@ function ColorModeToggle({
|
|
|
36
36
|
storageKey = COLOR_MODE_STORAGE_KEY,
|
|
37
37
|
modes = COLOR_MODES,
|
|
38
38
|
labels = {},
|
|
39
|
-
label = "Color mode"
|
|
39
|
+
label = "Color mode",
|
|
40
|
+
placement = "inline"
|
|
40
41
|
}) {
|
|
41
42
|
return /* @__PURE__ */ jsxs(
|
|
42
43
|
"fieldset",
|
|
43
44
|
{
|
|
44
|
-
class: "rr-color-mode"
|
|
45
|
+
class: placement === "inline" ? "rr-color-mode" : `rr-color-mode rr-color-mode--${placement}`,
|
|
45
46
|
"data-color-mode-root": true,
|
|
46
47
|
"data-color-mode-storage-key": storageKey,
|
|
47
48
|
children: [
|
|
@@ -180,7 +181,7 @@ function parseColorMode(value) {
|
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
// index.ts
|
|
183
|
-
function
|
|
184
|
+
function colorMode() {
|
|
184
185
|
return definePlugin({
|
|
185
186
|
name: "color-mode",
|
|
186
187
|
assets: [
|
|
@@ -190,7 +191,9 @@ function colorModePlugin() {
|
|
|
190
191
|
createClientEntry(
|
|
191
192
|
"color-mode",
|
|
192
193
|
"@riebeckite/plugin-color-mode/client",
|
|
193
|
-
"initColorMode"
|
|
194
|
+
"initColorMode",
|
|
195
|
+
void 0,
|
|
196
|
+
"app"
|
|
194
197
|
)
|
|
195
198
|
]
|
|
196
199
|
});
|
|
@@ -205,6 +208,6 @@ export {
|
|
|
205
208
|
COLOR_MODE_STORAGE_KEY_ATTRIBUTE,
|
|
206
209
|
ColorModeScript,
|
|
207
210
|
ColorModeToggle,
|
|
208
|
-
|
|
211
|
+
colorMode,
|
|
209
212
|
initColorMode
|
|
210
213
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-color-mode",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
24
|
+
"@riebeckite/core": "0.0.33",
|
|
25
|
+
"hono": "^4.12.25"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
package/style.css
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
--rr-color-mode-muted: var(--rb-color-muted);
|
|
5
5
|
--rr-color-mode-surface: var(--rb-color-surface);
|
|
6
6
|
--rr-color-mode-surface-hover: var(--rb-color-surface-hover);
|
|
7
|
+
--rr-color-mode-selected: var(--rb-color-selected);
|
|
8
|
+
--rr-color-mode-focus: var(--rb-color-focus);
|
|
7
9
|
--rr-color-mode-border: var(--rb-color-border);
|
|
8
10
|
--rr-color-mode-border-radius: 999px;
|
|
9
11
|
|
|
@@ -17,6 +19,16 @@
|
|
|
17
19
|
border-radius: var(--rr-color-mode-border-radius);
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
.rr-color-mode--floating {
|
|
23
|
+
position: fixed;
|
|
24
|
+
inset-inline-start: 1.5rem;
|
|
25
|
+
inset-block-end: 1.5rem;
|
|
26
|
+
z-index: 50;
|
|
27
|
+
background: var(--rr-color-mode-surface);
|
|
28
|
+
box-shadow: 0 2px 12px
|
|
29
|
+
color-mix(in oklab, var(--rb-color-ink) 18%, transparent);
|
|
30
|
+
}
|
|
31
|
+
|
|
20
32
|
/* The legend names the group for assistive technology only. */
|
|
21
33
|
.rr-color-mode__legend {
|
|
22
34
|
position: absolute;
|
|
@@ -60,10 +72,15 @@
|
|
|
60
72
|
|
|
61
73
|
.rr-color-mode__button[aria-pressed="true"] {
|
|
62
74
|
color: var(--rr-color-mode-ink);
|
|
63
|
-
background: var(--rr-color-mode-
|
|
75
|
+
background: var(--rr-color-mode-selected);
|
|
64
76
|
box-shadow: inset 0 0 0 1px var(--rr-color-mode-border);
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
.rr-color-mode__button:focus-visible {
|
|
80
|
+
outline: 2px solid var(--rr-color-mode-focus);
|
|
81
|
+
outline-offset: 2px;
|
|
82
|
+
}
|
|
83
|
+
|
|
67
84
|
.rr-color-mode__icon {
|
|
68
85
|
display: block;
|
|
69
86
|
width: 1rem;
|