@riebeckite/plugin-color-mode 0.0.32 → 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 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
- `colorModePlugin()` itself only registers the stylesheet and the client entry;
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 { colorModePlugin } from "@riebeckite/plugin-color-mode";
41
+ import { colorMode } from "@riebeckite/plugin-color-mode";
38
42
 
39
43
  export default defineConfig({
40
44
  // ...
41
- plugins: [colorModePlugin()],
45
+ plugins: [colorMode()],
42
46
  });
43
47
  ```
44
48
 
45
- `colorModePlugin()` bundles `style.css` and declares `initColorMode` as a client
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
- - `colorModePlugin()` — plugin factory
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
- [theme-system.md](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/theme-api.ja.md) テーマの配色は、次の 3 つの CSS 状態で決まります。
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
- プラグインは、この 3 つの CSS 状態を切り替えるだけの薄い実行時スイッチで、次の 3 つを提供します。
21
+ このプラグインは、その取り決めを切り替えるだけの薄い実行時スイッチで、次の 3 つを提供します。
18
22
 
19
- - `ColorModeScript`:`<head>` に置く 1 行のインラインスクリプト**。最初の描画の前に**保存済みモードを適用し、テーマのちらつき(FOUC)を防ぎます。
20
- - `ColorModeToggle`:ライト / ダーク / システムのセグメント型コントロール。
21
- - `initColorMode`:クライアントエントリ。ボタンの結線、`localStorage` への保存、ドキュメントの状態同期を行います。
23
+ - `ColorModeScript`:`<head>` に置く 1 行のインラインスクリプトです。**最初の描画の前に**保存済みのモードを適用し、テーマのちらつき(FOUC)を防ぎます。
24
+ - `ColorModeToggle`:ライト / ダーク / システムを選ぶセグメントコントロール。
25
+ - `initColorMode`:クライアントエントリー。ボタンの結線、`localStorage` への保存、ドキュメントの状態同期を行います。
22
26
 
23
- `colorModePlugin()` はスタイルシートとクライアントエントリの登録だけを行います。UI はサイトシェルで描画する 2 つのコンポーネントから届きます。
27
+ `colorMode()` はスタイルシートとクライアントエントリーの登録だけを行います。UI は、サイトシェルで描画する 2 つのコンポーネントが担います。
24
28
 
25
29
  ## 使い方
26
30
 
27
31
  ```ts
28
32
  import { defineConfig } from "@riebeckite/core";
29
- import { colorModePlugin } from "@riebeckite/plugin-color-mode";
33
+ import { colorMode } from "@riebeckite/plugin-color-mode";
30
34
 
31
35
  export default defineConfig({
32
36
  // ...
33
- plugins: [colorModePlugin()],
37
+ plugins: [colorMode()],
34
38
  });
35
39
  ```
36
40
 
37
- `colorModePlugin()` は `style.css` をバンドルし、`initColorMode` をクライアントエントリとして宣言します。
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
- ### Props
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` | グループの先頭に置く可視非表示の `<legend>` として使われます。既定値は `"Color mode"`。 |
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
- Theme は `rr-color-mode` の root に `--rr-color-mode-border-radius` を指定すると、子要素を
102
- 選択せずにコンテナとボタンで共有する角丸を変更できます。
105
+ テーマは `rr-color-mode` のルート要素に `--rr-color-mode-border-radius` を指定すると、
106
+ 子要素を選択せずにコンテナとボタンで共有する角丸を変更できます。
103
107
 
104
108
  ## アクセシビリティ
105
109
 
106
- - コンテナは `<fieldset>` で、グループ名は可視非表示の `<legend>`(`label` props)が提供します。
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
- ## Exports
134
+ ## エクスポート
131
135
 
132
- - `colorModePlugin()`:プラグインファクトリ
136
+ - `colorMode()`:プラグインファクトリ
133
137
  - `ColorModeToggle`:切替コンポーネント
134
138
  - `ColorModeScript`:描画前インラインスクリプトのコンポーネント
135
- - `initColorMode`:ブラウザ初期化関数(`@riebeckite/plugin-color-mode/client` からも export)
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 colorModePlugin(): import("@riebeckite/core").RiebeckitePlugin<unknown>;
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 colorModePlugin() {
184
+ function colorMode() {
184
185
  return definePlugin({
185
186
  name: "color-mode",
186
187
  assets: [
@@ -207,6 +208,6 @@ export {
207
208
  COLOR_MODE_STORAGE_KEY_ATTRIBUTE,
208
209
  ColorModeScript,
209
210
  ColorModeToggle,
210
- colorModePlugin,
211
+ colorMode,
211
212
  initColorMode
212
213
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-color-mode",
3
- "version": "0.0.32",
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
- "hono": "^4.12.25",
25
- "@riebeckite/core": "0.0.32"
24
+ "@riebeckite/core": "0.0.33",
25
+ "hono": "^4.12.25"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
package/style.css CHANGED
@@ -19,6 +19,16 @@
19
19
  border-radius: var(--rr-color-mode-border-radius);
20
20
  }
21
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
+
22
32
  /* The legend names the group for assistive technology only. */
23
33
  .rr-color-mode__legend {
24
34
  position: absolute;