@riebeckite/plugin-qr-code 0.0.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright Rerurate_514
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @riebeckite/plugin-qr-code
2
+
3
+ Renders ` ```qr ` fenced code blocks into inline SVG QR codes at build time.
4
+
5
+ [日本語](./README_ja.md)
6
+
7
+ ## Overview
8
+
9
+ `qrCode()` replaces each ` ```qr ` code block with a
10
+ `<figure class="rb-qr">` containing an inline `<svg>` QR code. Encoding happens
11
+ entirely at build time in Node; nothing is shipped to the browser. The plugin
12
+ runs with `order: -10`, before `code-enhance` and `code-tabs`.
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { defineConfig } from "@riebeckite/core";
18
+ import { qrCode } from "@riebeckite/plugin-qr-code";
19
+
20
+ export default defineConfig({
21
+ // ...
22
+ plugins: [
23
+ qrCode({
24
+ level: "M",
25
+ margin: 1,
26
+ width: 160,
27
+ dark: "#000000",
28
+ light: "#ffffff",
29
+ }),
30
+ ],
31
+ });
32
+ ```
33
+
34
+ ````md
35
+ ```qr
36
+ # caption: Project page
37
+ https://example.com/
38
+ ```
39
+ ````
40
+
41
+ The fence body is the text or URL to encode (trimmed). An empty body leaves the
42
+ code block untouched and reports a `@riebeckite/plugin-qr-code` diagnostic.
43
+
44
+ ## Behavior
45
+
46
+ Each block becomes:
47
+
48
+ ```html
49
+ <figure class="rb-qr" data-qr="rendered" data-qr-level="M" data-qr-margin="1">
50
+ <figcaption class="rb-qr__caption">…</figcaption>
51
+ <div class="rb-qr__canvas" role="img"><svg>…</svg></div>
52
+ <details class="rb-qr__fallback">
53
+ <summary>QR source</summary>
54
+ <pre><code>…</code></pre>
55
+ </details>
56
+ </figure>
57
+ ```
58
+
59
+ - `data-qr` is `"rendered"` on success and `"error"` when the encoder is
60
+ unavailable or the block cannot be encoded.
61
+ - The raw text stays available in `details.rb-qr__fallback` (unless `fallback`
62
+ is `false`), so an error never loses content.
63
+ - Errors and empty blocks report a snippet diagnostic with
64
+ `source: "@riebeckite/plugin-qr-code"`.
65
+
66
+ ### Encoder loading
67
+
68
+ The QR encoder (`qrcode`) is imported dynamically at build time, so bundlers
69
+ never pull it into the site or client bundle. When the plugin is bundled into a
70
+ temporary config module and the bare specifier no longer resolves, the loader
71
+ falls back to `node_modules` discovered from `process.cwd()` and the pnpm
72
+ virtual store.
73
+
74
+ ## Options
75
+
76
+ | Option | Type | Default | Description |
77
+ | ------ | ---- | ------- | ----------- |
78
+ | `level` | `"L" \| "M" \| "Q" \| "H"` | `"M"` | Error-correction level |
79
+ | `margin` | `number` | `1` | Quiet-zone size in modules |
80
+ | `width` | `number` | `160` | Rendered size in pixels |
81
+ | `size` | `number` | — | Alias of `width` |
82
+ | `dark` | `string` | `"#000000"` | Dark-module colour |
83
+ | `light` | `string` | `"#ffffff"` | Light-module colour |
84
+ | `caption` | `boolean` | `true` | Show a caption from the title / `# caption:` line |
85
+ | `className` | `string` | `"rb-qr"` | Figure CSS class |
86
+ | `language` | `string` | `"qr"` | Fence language to intercept |
87
+ | `fallback` | `boolean` | `true` | Keep the raw text in `<details>` |
88
+
89
+ The caption comes from the code-block `title` (code meta) or a leading
90
+ `# caption: …` line. A leading caption line is removed from the encoded body.
91
+
92
+ ## Exports
93
+
94
+ - `qrCode(options?)` — plugin factory
95
+ - `qrCodePlugin` — alias of `qrCode`
96
+ - `resolveQrCodeOptions(options?)` — normalise options
97
+ - `buildQrSvg(text, options)` — encode text into an SVG string
98
+ - Types: `QrCodeOptions`, `ResolvedQrCodeOptions`, `QrCodeLevel`,
99
+ `QrBuildResult`
100
+
101
+ ## See also
102
+
103
+ - [Plugin guide](../../docs/plugins_en.md)
package/README_ja.md ADDED
@@ -0,0 +1,90 @@
1
+ # @riebeckite/plugin-qr-code
2
+
3
+ ` ```qr ` コードブロックを、ビルド時にインライン SVG の QR コードへ変換するプラグインです。
4
+
5
+ [English](./README.md)
6
+
7
+ ## 概要
8
+
9
+ `qrCode()` は QR コードのコードブロックを `<figure class="rb-qr">` に置き換え、インラインの `<svg>` を埋め込みます。エンコードはビルド時の Node 上で完結し、ブラウザには何も配信しません。`order: -10` で実行されるため、`code-enhance` や `code-tabs` より先に処理されます。
10
+
11
+ ## 使い方
12
+
13
+ ```ts
14
+ import { defineConfig } from "@riebeckite/core";
15
+ import { qrCode } from "@riebeckite/plugin-qr-code";
16
+
17
+ export default defineConfig({
18
+ // ...
19
+ plugins: [
20
+ qrCode({
21
+ level: "M",
22
+ margin: 1,
23
+ width: 160,
24
+ dark: "#000000",
25
+ light: "#ffffff",
26
+ }),
27
+ ],
28
+ });
29
+ ```
30
+
31
+ ````md
32
+ ```qr
33
+ # caption: プロジェクトページ
34
+ https://example.com/
35
+ ```
36
+ ````
37
+
38
+ フェンス本文がエンコード対象のテキストまたは URL です(前後の空白は除去します)。本文が空の場合、コードブロックはそのまま残し、`@riebeckite/plugin-qr-code` を発行元とする診断を出します。
39
+
40
+ ## 出力
41
+
42
+ 各ブロックは次の形になります。
43
+
44
+ ```html
45
+ <figure class="rb-qr" data-qr="rendered" data-qr-level="M" data-qr-margin="1">
46
+ <figcaption class="rb-qr__caption">…</figcaption>
47
+ <div class="rb-qr__canvas" role="img"><svg>…</svg></div>
48
+ <details class="rb-qr__fallback">
49
+ <summary>QR source</summary>
50
+ <pre><code>…</code></pre>
51
+ </details>
52
+ </figure>
53
+ ```
54
+
55
+ - `data-qr` は成功時に `"rendered"`、エンコーダを読み込めない場合やエンコードに失敗した場合に `"error"` になります。
56
+ - 元のテキストは `details.rb-qr__fallback` に残ります(`fallback: false` の場合は除く)。エラー時も内容が失われることはありません。
57
+ - エラーと空ブロックは `source: "@riebeckite/plugin-qr-code"` の診断として報告されます。
58
+
59
+ ### エンコーダの読み込み
60
+
61
+ QR エンコーダ(`qrcode`)はビルド時に動的インポートするため、サイト側・クライアント側のバンドルには含まれません。プラグインが一時的な設定モジュールへバンドルされ、ベア指定子が解決できなくなった場合は、`process.cwd()` と pnpm の仮想ストアから `node_modules` を探索してフォールバックします。
62
+
63
+ ## オプション
64
+
65
+ | 項目 | 型 | 既定値 | 説明 |
66
+ | --- | --- | --- | --- |
67
+ | `level` | `"L" \| "M" \| "Q" \| "H"` | `"M"` | 誤り訂正レベル |
68
+ | `margin` | `number` | `1` | 余白(モジュール数) |
69
+ | `width` | `number` | `160` | 表示サイズ(px) |
70
+ | `size` | `number` | — | `width` の別名 |
71
+ | `dark` | `string` | `"#000000"` | 暗モジュールの色 |
72
+ | `light` | `string` | `"#ffffff"` | 明モジュールの色 |
73
+ | `caption` | `boolean` | `true` | タイトルまたは `# caption:` 行をキャプションとして表示する |
74
+ | `className` | `string` | `"rb-qr"` | figure の CSS クラス |
75
+ | `language` | `string` | `"qr"` | 対象とするフェンス言語 |
76
+ | `fallback` | `boolean` | `true` | 元のテキストを `<details>` に残す |
77
+
78
+ キャプションはコードブロックの `title`(コードメタ)または先頭の `# caption: …` 行から取得します。先頭のキャプション行はエンコード対象から取り除きます。
79
+
80
+ ## 主なエクスポート
81
+
82
+ - `qrCode(options?)`: プラグインを作成する
83
+ - `qrCodePlugin`: `qrCode` の別名
84
+ - `resolveQrCodeOptions(options?)`: オプションを正規化する
85
+ - `buildQrSvg(text, options)`: テキストを SVG 文字列へエンコードする
86
+ - 型: `QrCodeOptions`、`ResolvedQrCodeOptions`、`QrCodeLevel`、`QrBuildResult`
87
+
88
+ ## 関連資料
89
+
90
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
@@ -0,0 +1,8 @@
1
+ import { DEFAULT_QR_CODE_OPTIONS } from "./src/options.js";
2
+ import type { QrCodeOptions } from "./src/types.js";
3
+ export { buildQrSvg } from "./src/render.js";
4
+ export { resolveQrCodeOptions } from "./src/options.js";
5
+ export type { QrBuildResult, QrCodeLevel, QrCodeOptions, ResolvedQrCodeOptions, } from "./src/types.js";
6
+ export declare function qrCode(options?: QrCodeOptions): import("@riebeckite/core").RiebeckitePlugin<QrCodeOptions>;
7
+ export declare const qrCodePlugin: typeof qrCode;
8
+ export { DEFAULT_QR_CODE_OPTIONS };
package/dist/index.js ADDED
@@ -0,0 +1,574 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res, err) => function __init() {
4
+ if (err) throw err[0];
5
+ try {
6
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
+ } catch (e) {
8
+ throw err = [e], e;
9
+ }
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+
16
+ // src/options.ts
17
+ function resolveQrCodeOptions(options = {}) {
18
+ const width = normalizePositiveInteger(
19
+ options.width ?? options.size,
20
+ DEFAULT_QR_CODE_OPTIONS.width
21
+ );
22
+ const margin = normalizeNonNegativeInteger(
23
+ options.margin,
24
+ DEFAULT_QR_CODE_OPTIONS.margin
25
+ );
26
+ const dark = normalizeColor(options.dark, DEFAULT_QR_CODE_OPTIONS.dark);
27
+ const light = normalizeColor(options.light, DEFAULT_QR_CODE_OPTIONS.light);
28
+ const className = normalizeClassName(options.className);
29
+ const language = normalizeLanguage(options.language);
30
+ return {
31
+ level: normalizeLevel(options.level),
32
+ margin,
33
+ width,
34
+ dark,
35
+ light,
36
+ caption: options.caption ?? DEFAULT_QR_CODE_OPTIONS.caption,
37
+ className,
38
+ language,
39
+ fallback: options.fallback ?? DEFAULT_QR_CODE_OPTIONS.fallback
40
+ };
41
+ }
42
+ function normalizeLevel(value) {
43
+ return typeof value === "string" && QR_CODE_LEVELS.includes(value) ? value : DEFAULT_QR_CODE_OPTIONS.level;
44
+ }
45
+ function normalizePositiveInteger(value, fallback) {
46
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : fallback;
47
+ }
48
+ function normalizeNonNegativeInteger(value, fallback) {
49
+ return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : fallback;
50
+ }
51
+ function normalizeColor(value, fallback) {
52
+ return typeof value === "string" && value.trim() !== "" ? value : fallback;
53
+ }
54
+ function normalizeClassName(value) {
55
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : DEFAULT_QR_CODE_OPTIONS.className;
56
+ }
57
+ function normalizeLanguage(value) {
58
+ if (typeof value !== "string") return DEFAULT_QR_CODE_OPTIONS.language;
59
+ const language = value.replace(/^language-/, "").trim();
60
+ return language !== "" ? language : DEFAULT_QR_CODE_OPTIONS.language;
61
+ }
62
+ function qrElementClassName(className, element2) {
63
+ return `${className}__${element2}`;
64
+ }
65
+ var QR_CODE_LEVELS, DEFAULT_QR_CODE_OPTIONS;
66
+ var init_options = __esm({
67
+ "src/options.ts"() {
68
+ QR_CODE_LEVELS = ["L", "M", "Q", "H"];
69
+ DEFAULT_QR_CODE_OPTIONS = {
70
+ level: "M",
71
+ margin: 1,
72
+ width: 160,
73
+ dark: "#000000",
74
+ light: "#ffffff",
75
+ caption: true,
76
+ className: "rb-qr",
77
+ language: "qr",
78
+ fallback: true
79
+ };
80
+ }
81
+ });
82
+
83
+ // src/render.ts
84
+ var render_exports = {};
85
+ __export(render_exports, {
86
+ buildQrSvg: () => buildQrSvg,
87
+ resetQrCodeEncoderCache: () => resetQrCodeEncoderCache
88
+ });
89
+ import fs from "node:fs";
90
+ import { createRequire } from "node:module";
91
+ import path from "node:path";
92
+ import { fileURLToPath, pathToFileURL } from "node:url";
93
+ function resetQrCodeEncoderCache() {
94
+ encoderPromise = null;
95
+ }
96
+ async function buildQrSvg(text2, options) {
97
+ const source = text2.trim();
98
+ if (source === "") {
99
+ return { ok: false, message: "QR block is empty; nothing to encode." };
100
+ }
101
+ try {
102
+ const encoder = await loadQrEncoder();
103
+ const svg = await encoder.toString(source, {
104
+ type: "svg",
105
+ errorCorrectionLevel: options.level,
106
+ margin: options.margin,
107
+ width: options.width,
108
+ color: { dark: options.dark, light: options.light }
109
+ });
110
+ if (typeof svg !== "string" || svg.trim() === "") {
111
+ return {
112
+ ok: false,
113
+ message: "QR encoder returned an empty SVG."
114
+ };
115
+ }
116
+ return { ok: true, svg };
117
+ } catch (error) {
118
+ return { ok: false, message: formatError(error) };
119
+ }
120
+ }
121
+ async function loadQrEncoder() {
122
+ encoderPromise ??= resolveQrEncoder();
123
+ return encoderPromise;
124
+ }
125
+ async function resolveQrEncoder() {
126
+ const attempts = collectLoadCandidates();
127
+ const failures = [];
128
+ for (const specifier of attempts) {
129
+ try {
130
+ const module = await dynamicImport(specifier);
131
+ return normalizeEncoder(module);
132
+ } catch (error) {
133
+ failures.push(`${specifier}: ${formatError(error)}`);
134
+ }
135
+ }
136
+ throw new Error(
137
+ `Could not load the "${QR_LIBRARY}" encoder. Tried: ${attempts.join(", ")}. Last errors: ${failures.slice(-2).join("; ")}`
138
+ );
139
+ }
140
+ function normalizeEncoder(module) {
141
+ if (isRecord(module)) {
142
+ const direct = module.toString;
143
+ if (typeof direct === "function") return module;
144
+ const fallback = module.default;
145
+ if (isRecord(fallback) && typeof fallback.toString === "function") {
146
+ return fallback;
147
+ }
148
+ }
149
+ throw new Error(`The "${QR_LIBRARY}" module has no toString() export.`);
150
+ }
151
+ function collectLoadCandidates() {
152
+ const candidates = [QR_LIBRARY];
153
+ for (const directory of collectModuleRoots()) {
154
+ const entry = resolveFromRoot(directory);
155
+ if (entry) candidates.push(pathToFileURL(entry).href);
156
+ }
157
+ for (const directory of collectPnpmStoreEntries()) {
158
+ const entry = resolvePackageDirectory(directory);
159
+ if (entry) candidates.push(pathToFileURL(entry).href);
160
+ }
161
+ return dedupe(candidates);
162
+ }
163
+ function collectModuleRoots() {
164
+ const roots = [];
165
+ const starts = [process.cwd(), safeImportMetaDir()].filter(
166
+ (value) => typeof value === "string"
167
+ );
168
+ for (const start of starts) {
169
+ roots.push(start, ...ancestorDirectories(start));
170
+ }
171
+ return dedupe(roots);
172
+ }
173
+ function collectPnpmStoreEntries() {
174
+ const packageDirectories = [];
175
+ for (const directory of collectModuleRoots()) {
176
+ const store = path.join(directory, "node_modules", ".pnpm");
177
+ if (!isDirectory(store)) continue;
178
+ for (const entry of safeReaddir(store)) {
179
+ if (!entry.startsWith(`${QR_LIBRARY}@`)) continue;
180
+ packageDirectories.push(
181
+ path.join(store, entry, "node_modules", QR_LIBRARY)
182
+ );
183
+ }
184
+ }
185
+ return packageDirectories;
186
+ }
187
+ function resolveFromRoot(directory) {
188
+ const require2 = createRequire(path.join(directory, "package.json"));
189
+ try {
190
+ return require2.resolve(QR_LIBRARY);
191
+ } catch {
192
+ return null;
193
+ }
194
+ }
195
+ function resolvePackageDirectory(directory) {
196
+ if (!isDirectory(directory)) return null;
197
+ try {
198
+ const manifest = JSON.parse(
199
+ fs.readFileSync(path.join(directory, "package.json"), "utf8")
200
+ );
201
+ const entry = resolveExportsEntry(manifest.exports) ?? manifest.main ?? "index.js";
202
+ return path.resolve(directory, entry);
203
+ } catch {
204
+ return null;
205
+ }
206
+ }
207
+ function resolveExportsEntry(exportsField) {
208
+ if (typeof exportsField === "string") return exportsField;
209
+ if (!isRecord(exportsField)) return void 0;
210
+ const root = exportsField["."];
211
+ const target = root ?? exportsField;
212
+ if (typeof target === "string") return target;
213
+ if (!isRecord(target)) return void 0;
214
+ for (const condition of ["import", "require", "default", "node"]) {
215
+ const value = target[condition];
216
+ if (typeof value === "string") return value;
217
+ if (isRecord(value)) {
218
+ const nested = resolveExportsEntry(value);
219
+ if (nested) return nested;
220
+ }
221
+ }
222
+ return void 0;
223
+ }
224
+ function safeImportMetaDir() {
225
+ const url = import.meta.url;
226
+ if (typeof url !== "string" || !url.startsWith("file:")) return void 0;
227
+ try {
228
+ return path.dirname(fileURLToPath(url));
229
+ } catch {
230
+ return void 0;
231
+ }
232
+ }
233
+ function* ancestorDirectories(start) {
234
+ let directory = path.resolve(start);
235
+ for (; ; ) {
236
+ yield directory;
237
+ const parent = path.dirname(directory);
238
+ if (parent === directory) return;
239
+ directory = parent;
240
+ }
241
+ }
242
+ function dedupe(values) {
243
+ return [...new Set(values)];
244
+ }
245
+ function isRecord(value) {
246
+ return typeof value === "object" && value !== null && !Array.isArray(value);
247
+ }
248
+ function isDirectory(directory) {
249
+ try {
250
+ return fs.statSync(directory).isDirectory();
251
+ } catch {
252
+ return false;
253
+ }
254
+ }
255
+ function safeReaddir(directory) {
256
+ try {
257
+ return fs.readdirSync(directory);
258
+ } catch {
259
+ return [];
260
+ }
261
+ }
262
+ function formatError(error) {
263
+ return error instanceof Error ? error.message : String(error);
264
+ }
265
+ var QR_LIBRARY, dynamicImport, encoderPromise;
266
+ var init_render = __esm({
267
+ "src/render.ts"() {
268
+ QR_LIBRARY = "qrcode";
269
+ dynamicImport = new Function(
270
+ "specifier",
271
+ "return import(specifier)"
272
+ );
273
+ encoderPromise = null;
274
+ }
275
+ });
276
+
277
+ // src/rehype.ts
278
+ var rehype_exports = {};
279
+ __export(rehype_exports, {
280
+ element: () => element,
281
+ getTextContent: () => getTextContent,
282
+ raw: () => raw,
283
+ rehypeQrCode: () => rehypeQrCode,
284
+ text: () => text,
285
+ visitElements: () => visitElements
286
+ });
287
+ function rehypeQrCode(options) {
288
+ return async (tree, file) => {
289
+ const replacements = [];
290
+ visitElements(tree, (node, parent, index) => {
291
+ if (!parent || index === void 0) return;
292
+ if (!isQrCodeBlock(node, options.language)) return;
293
+ replacements.push(replaceQrBlock(parent, index, node, file, options));
294
+ });
295
+ await Promise.all(replacements);
296
+ };
297
+ }
298
+ async function replaceQrBlock(parent, index, pre, file, options) {
299
+ const code = findDirectChild(pre, "code");
300
+ const rawSource = code ? getTextContent(code).trim() : getTextContent(pre).trim();
301
+ if (rawSource === "") {
302
+ reportDiagnostic(
303
+ file,
304
+ "Empty qr block: add the text or URL to encode.",
305
+ "empty-block"
306
+ );
307
+ return;
308
+ }
309
+ const extracted = extractCaption(rawSource, pre, code);
310
+ const caption = options.caption ? extracted.caption : null;
311
+ const source = extracted.body === "" ? rawSource : extracted.body;
312
+ const { buildQrSvg: buildQrSvg2 } = await Promise.resolve().then(() => (init_render(), render_exports));
313
+ const result = await buildQrSvg2(source, options);
314
+ parent.children = parent.children ?? [];
315
+ if (result.ok === false) {
316
+ parent.children[index] = buildErrorFigure(
317
+ source,
318
+ caption,
319
+ options,
320
+ result.message,
321
+ file
322
+ );
323
+ } else {
324
+ parent.children[index] = buildRenderedFigure(
325
+ source,
326
+ result.svg,
327
+ caption,
328
+ options
329
+ );
330
+ }
331
+ }
332
+ function buildRenderedFigure(source, svg, caption, options) {
333
+ const labelId = `${figureId(source, options)}-caption`;
334
+ return element(
335
+ "figure",
336
+ {
337
+ className: options.className,
338
+ dataQr: "rendered",
339
+ dataQrLevel: options.level,
340
+ dataQrMargin: String(options.margin)
341
+ },
342
+ [
343
+ ...renderCaption(caption, options, labelId),
344
+ element(
345
+ "div",
346
+ {
347
+ className: qrElementClassName(options.className, "canvas"),
348
+ role: "img",
349
+ ariaLabelledby: caption ? labelId : void 0,
350
+ ariaLabel: caption ? void 0 : "QR code"
351
+ },
352
+ [raw(svg)]
353
+ ),
354
+ ...renderFallback(source, options)
355
+ ]
356
+ );
357
+ }
358
+ function buildErrorFigure(source, caption, options, message, file) {
359
+ reportDiagnostic(file, `QR code could not be rendered: ${message}`, "render");
360
+ const labelId = `${figureId(source, options)}-caption`;
361
+ return element(
362
+ "figure",
363
+ {
364
+ className: options.className,
365
+ dataQr: "error",
366
+ dataQrLevel: options.level,
367
+ dataQrMargin: String(options.margin)
368
+ },
369
+ [
370
+ ...renderCaption(caption, options, labelId),
371
+ element(
372
+ "div",
373
+ {
374
+ className: qrElementClassName(options.className, "canvas"),
375
+ role: "img",
376
+ ariaLabelledby: caption ? labelId : void 0,
377
+ ariaLabel: caption ? void 0 : "QR code"
378
+ },
379
+ []
380
+ ),
381
+ ...renderFallback(source, options)
382
+ ]
383
+ );
384
+ }
385
+ function renderCaption(caption, options, labelId) {
386
+ if (!caption) return [];
387
+ return [
388
+ element(
389
+ "figcaption",
390
+ {
391
+ id: labelId,
392
+ className: qrElementClassName(options.className, "caption")
393
+ },
394
+ [text(caption)]
395
+ )
396
+ ];
397
+ }
398
+ function renderFallback(source, options) {
399
+ if (!options.fallback) return [];
400
+ return [
401
+ element(
402
+ "details",
403
+ { className: qrElementClassName(options.className, "fallback") },
404
+ [
405
+ element("summary", {}, [text("QR source")]),
406
+ element("pre", {}, [element("code", {}, [text(source)])])
407
+ ]
408
+ )
409
+ ];
410
+ }
411
+ function extractCaption(source, pre, code) {
412
+ const title = getStringProperty(pre, "title") ?? getStringProperty(code ?? pre, "title") ?? metaTitle(getStringProperty(code ?? pre, "data-meta")) ?? metaTitle(getStringProperty(code ?? pre, "dataMeta")) ?? metaTitle(getCodeDataMeta(code));
413
+ const match = source.match(CAPTION_PATTERN);
414
+ const caption = title ?? (match ? match[1].trim() : null);
415
+ const body = match ? source.slice(match[0].length).trim() : source;
416
+ return {
417
+ caption: caption && caption.trim() !== "" ? caption.trim() : null,
418
+ body
419
+ };
420
+ }
421
+ function metaTitle(meta) {
422
+ if (!meta) return null;
423
+ const match = meta.match(META_TITLE_PATTERN);
424
+ const value = match?.[1] ?? match?.[2] ?? match?.[3] ?? null;
425
+ return value && value.trim() !== "" ? value.trim() : null;
426
+ }
427
+ function getCodeDataMeta(code) {
428
+ const meta = code?.data?.meta;
429
+ return typeof meta === "string" ? meta : null;
430
+ }
431
+ function figureId(source, options) {
432
+ let hash = 0;
433
+ const seed = `${options.level}:${options.margin}:${source}`;
434
+ for (const char of seed) hash = hash * 31 + char.charCodeAt(0) | 0;
435
+ return `rb-qr-${Math.abs(hash).toString(36)}`;
436
+ }
437
+ function isQrCodeBlock(node, language) {
438
+ if (node.tagName !== "pre") return false;
439
+ const code = findDirectChild(node, "code");
440
+ if (!code) return false;
441
+ return hasClass(code, `language-${language}`);
442
+ }
443
+ function findDirectChild(node, tagName) {
444
+ return node.children?.find(
445
+ (child) => child.type === "element" && child.tagName === tagName
446
+ ) ?? null;
447
+ }
448
+ function element(tagName, properties = {}, children = []) {
449
+ return { type: "element", tagName, properties, children };
450
+ }
451
+ function text(value) {
452
+ return { type: "text", value };
453
+ }
454
+ function raw(value) {
455
+ return { type: "raw", value };
456
+ }
457
+ function getTextContent(node) {
458
+ const value = node.value;
459
+ if (node.type === "text" && typeof value === "string") return value;
460
+ return getChildren(node).map(getTextContent).join("");
461
+ }
462
+ function getStringProperty(node, key) {
463
+ const value = node.properties?.[key];
464
+ if (typeof value === "string") return value;
465
+ if (Array.isArray(value)) return value.join(" ");
466
+ return null;
467
+ }
468
+ function hasClass(node, className) {
469
+ const value = node.properties?.className;
470
+ const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
471
+ return classes.includes(className);
472
+ }
473
+ function visitElements(node, visitor, parent, index) {
474
+ if (node.type === "element") visitor(node, parent, index);
475
+ const children = getChildren(node);
476
+ for (const [childIndex, child] of children.entries()) {
477
+ visitElements(
478
+ child,
479
+ visitor,
480
+ children.length > 0 ? node : parent,
481
+ childIndex
482
+ );
483
+ }
484
+ }
485
+ function getChildren(node) {
486
+ const children = node.children;
487
+ return Array.isArray(children) ? children : [];
488
+ }
489
+ function reportDiagnostic(file, message, ruleId) {
490
+ const reporter = file?.message;
491
+ if (typeof reporter !== "function") return;
492
+ const diagnostic = reporter.call(file, message);
493
+ if (diagnostic && typeof diagnostic === "object") {
494
+ Object.assign(diagnostic, { source: PLUGIN_SOURCE, ruleId });
495
+ }
496
+ }
497
+ var CAPTION_PATTERN, META_TITLE_PATTERN, PLUGIN_SOURCE;
498
+ var init_rehype = __esm({
499
+ "src/rehype.ts"() {
500
+ init_options();
501
+ CAPTION_PATTERN = /^[ \t]*#[ \t]*caption[ \t]*:[ \t]*(.+?)[ \t]*(?:\r?\n|$)/i;
502
+ META_TITLE_PATTERN = /title=(?:"([^"]*)"|'([^']*)'|(\S+))/;
503
+ PLUGIN_SOURCE = "@riebeckite/plugin-qr-code";
504
+ }
505
+ });
506
+
507
+ // index.ts
508
+ init_options();
509
+ init_render();
510
+ init_options();
511
+ import {
512
+ createStyleAsset,
513
+ definePlugin
514
+ } from "@riebeckite/core";
515
+ var PLUGIN_NAME = "qr-code";
516
+ function qrCode(options = {}) {
517
+ return definePlugin({
518
+ name: PLUGIN_NAME,
519
+ order: -10,
520
+ options,
521
+ validateOptions: validateQrCodeOptions,
522
+ extendHtmlPipeline: (pipeline) => {
523
+ pipeline.use(rehypeQrCodeLazy, options);
524
+ },
525
+ assets: [createStyleAsset(PLUGIN_NAME)]
526
+ });
527
+ }
528
+ var qrCodePlugin = qrCode;
529
+ function validateQrCodeOptions(options) {
530
+ if (!options) return [];
531
+ const issues = [];
532
+ if (options.level !== void 0 && !QR_CODE_LEVELS.includes(options.level)) {
533
+ issues.push({
534
+ path: "level",
535
+ message: `Expected one of: ${QR_CODE_LEVELS.join(", ")}.`
536
+ });
537
+ }
538
+ for (const key of ["margin", "width", "size"]) {
539
+ const value = options[key];
540
+ if (value === void 0) continue;
541
+ if (!Number.isInteger(value) || value < 0 || key !== "margin" && value === 0) {
542
+ issues.push({
543
+ path: key,
544
+ message: key === "margin" ? "Expected a non-negative integer." : "Expected a positive integer."
545
+ });
546
+ }
547
+ }
548
+ for (const key of ["dark", "light", "className", "language"]) {
549
+ const value = options[key];
550
+ if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
551
+ issues.push({ path: key, message: "Expected a non-empty string." });
552
+ }
553
+ }
554
+ for (const key of ["caption", "fallback"]) {
555
+ if (options[key] !== void 0 && typeof options[key] !== "boolean") {
556
+ issues.push({ path: key, message: "Expected a boolean." });
557
+ }
558
+ }
559
+ return issues;
560
+ }
561
+ function rehypeQrCodeLazy(options = {}) {
562
+ const resolved = resolveQrCodeOptions(options);
563
+ return async (tree, file) => {
564
+ const { rehypeQrCode: rehypeQrCode2 } = await Promise.resolve().then(() => (init_rehype(), rehype_exports));
565
+ await rehypeQrCode2(resolved)(tree, file);
566
+ };
567
+ }
568
+ export {
569
+ DEFAULT_QR_CODE_OPTIONS,
570
+ buildQrSvg,
571
+ qrCode,
572
+ qrCodePlugin,
573
+ resolveQrCodeOptions
574
+ };
@@ -0,0 +1,11 @@
1
+ import type { QrCodeLevel, QrCodeOptions, ResolvedQrCodeOptions } from "./types.js";
2
+ export declare const QR_CODE_LEVELS: readonly QrCodeLevel[];
3
+ export declare const DEFAULT_QR_CODE_OPTIONS: ResolvedQrCodeOptions;
4
+ /**
5
+ * Normalises plugin options into a fully-resolved shape. Unknown or invalid
6
+ * values fall back to the documented defaults so the renderer never receives
7
+ * `undefined`; strict rejection is the job of `validateOptions`.
8
+ */
9
+ export declare function resolveQrCodeOptions(options?: QrCodeOptions): ResolvedQrCodeOptions;
10
+ /** Builds the sub-element class name, e.g. `rb-qr` -> `rb-qr__canvas`. */
11
+ export declare function qrElementClassName(className: string, element: string): string;
@@ -0,0 +1,7 @@
1
+ import type { ElementNode, HastNode, ParentNode, RawNode, ResolvedQrCodeOptions, TextNode } from "./types.js";
2
+ export declare function rehypeQrCode(options: ResolvedQrCodeOptions): (tree: HastNode, file: unknown) => Promise<void>;
3
+ export declare function element(tagName: string, properties?: Record<string, unknown>, children?: HastNode[]): ElementNode;
4
+ export declare function text(value: string): TextNode;
5
+ export declare function raw(value: string): RawNode;
6
+ export declare function getTextContent(node: HastNode): string;
7
+ export declare function visitElements(node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number): void;
@@ -0,0 +1,8 @@
1
+ import type { QrBuildResult, ResolvedQrCodeOptions } from "./types.js";
2
+ export declare function resetQrCodeEncoderCache(): void;
3
+ /**
4
+ * Encodes `text` into an inline SVG string. Filesystem/library failures are
5
+ * returned as `{ ok: false }` so the rehype transformer can keep a diagnostic
6
+ * and a fallback instead of throwing during the build.
7
+ */
8
+ export declare function buildQrSvg(text: string, options: ResolvedQrCodeOptions): Promise<QrBuildResult>;
@@ -0,0 +1,69 @@
1
+ /** Error-correction level understood by the QR encoder. */
2
+ export type QrCodeLevel = "L" | "M" | "Q" | "H";
3
+ export type QrCodeOptions = {
4
+ /** Error-correction level. Defaults to `"M"`. */
5
+ level?: QrCodeLevel;
6
+ /** Quiet-zone size in modules. Defaults to `1`. */
7
+ margin?: number;
8
+ /** Rendered width/height in pixels. Defaults to `160`. */
9
+ width?: number;
10
+ /** Alias of `width`; `width` wins when both are present. */
11
+ size?: number;
12
+ /** Dark-module colour. Defaults to `"#000000"`. */
13
+ dark?: string;
14
+ /** Light-module colour. Defaults to `"#ffffff"`. */
15
+ light?: string;
16
+ /** Show a caption from the code-block title or a leading `# caption:` line. Defaults to `true`. */
17
+ caption?: boolean;
18
+ /** CSS class applied to the figure. Defaults to `"rb-qr"`. */
19
+ className?: string;
20
+ /** Fence language that selects the block. Defaults to `"qr"`. */
21
+ language?: string;
22
+ /** Keep the raw source in a collapsible `<details>`. Defaults to `true`. */
23
+ fallback?: boolean;
24
+ };
25
+ /** `QrCodeOptions` with every field resolved to a concrete value. */
26
+ export type ResolvedQrCodeOptions = {
27
+ level: QrCodeLevel;
28
+ margin: number;
29
+ width: number;
30
+ dark: string;
31
+ light: string;
32
+ caption: boolean;
33
+ className: string;
34
+ language: string;
35
+ fallback: boolean;
36
+ };
37
+ /**
38
+ * Build-time result of encoding a fence body. A failure carries a human
39
+ * readable message; callers decide how to surface it (diagnostic + fallback).
40
+ */
41
+ export type QrBuildResult = {
42
+ ok: true;
43
+ svg: string;
44
+ } | {
45
+ ok: false;
46
+ message: string;
47
+ };
48
+ export type ElementNode = {
49
+ type: string;
50
+ tagName?: string;
51
+ properties?: Record<string, unknown>;
52
+ children?: HastNode[];
53
+ data?: Record<string, unknown>;
54
+ };
55
+ export type ParentNode = HastNode & {
56
+ children?: HastNode[];
57
+ };
58
+ export type TextNode = {
59
+ type: "text";
60
+ value: string;
61
+ };
62
+ export type RawNode = {
63
+ type: "raw";
64
+ value: string;
65
+ };
66
+ export type HastNode = ElementNode | TextNode | RawNode | {
67
+ type: string;
68
+ [key: string]: unknown;
69
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@riebeckite/plugin-qr-code",
3
+ "version": "0.0.1",
4
+ "license": "Apache-2.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "source": "./index.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./style.css": "./style.css"
16
+ },
17
+ "dependencies": {
18
+ "qrcode": "^1.5.4",
19
+ "@riebeckite/core": "0.0.1"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "README.md",
27
+ "README_ja.md",
28
+ "dist",
29
+ "style.css"
30
+ ],
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Rerurate514/riebeckite.git",
34
+ "directory": "packages/plugins/qr-code"
35
+ },
36
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
39
+ },
40
+ "description": "Inline SVG QR code rendering for Riebeckite code blocks.",
41
+ "keywords": [
42
+ "riebeckite",
43
+ "plugin",
44
+ "qr-code",
45
+ "svg"
46
+ ],
47
+ "engines": {
48
+ "node": "^20.19.0 || >=22.12.0"
49
+ },
50
+ "sideEffects": [
51
+ "./style.css"
52
+ ],
53
+ "scripts": {
54
+ "build": "node ../../../scripts/build_package.mjs"
55
+ }
56
+ }
package/style.css ADDED
@@ -0,0 +1,72 @@
1
+ .rb-qr {
2
+ --rb-qr-paper: var(--rb-color-paper, #ffffff);
3
+ --rb-qr-ink: var(--rb-color-ink, #000000);
4
+ --rb-qr-muted: var(--rb-color-muted, #69645c);
5
+ --rb-qr-rule: var(
6
+ --rb-color-border,
7
+ color-mix(in srgb, var(--rb-qr-ink) 18%, transparent)
8
+ );
9
+ box-sizing: border-box;
10
+ width: fit-content;
11
+ max-width: 100%;
12
+ margin: 2rem auto;
13
+ border: 1px solid var(--rb-qr-rule);
14
+ background: var(--rb-qr-paper);
15
+ color: var(--rb-qr-ink);
16
+ }
17
+
18
+ .rb-qr__caption {
19
+ padding: 0.5rem 0.75rem;
20
+ border-bottom: 1px solid var(--rb-qr-rule);
21
+ color: var(--rb-qr-muted);
22
+ font-size: 0.8125rem;
23
+ text-align: center;
24
+ }
25
+
26
+ .rb-qr__canvas {
27
+ display: grid;
28
+ place-items: center;
29
+ padding: 1rem;
30
+ }
31
+
32
+ .rb-qr__canvas > svg {
33
+ display: block;
34
+ max-width: 100%;
35
+ height: auto;
36
+ }
37
+
38
+ .rb-qr__fallback {
39
+ border-top: 1px solid var(--rb-qr-rule);
40
+ color: var(--rb-qr-muted);
41
+ font-size: 0.8125rem;
42
+ }
43
+
44
+ .rb-qr__fallback summary {
45
+ cursor: pointer;
46
+ padding: 0.5rem 0.75rem;
47
+ }
48
+
49
+ .rb-qr__fallback pre {
50
+ overflow: auto;
51
+ margin: 0 1rem 0.75rem;
52
+ padding: 0.75rem;
53
+ border-top: 1px solid var(--rb-qr-rule);
54
+ color: var(--rb-qr-ink);
55
+ background: color-mix(in srgb, var(--rb-qr-ink) 6%, transparent);
56
+ }
57
+
58
+ .rb-qr[data-qr="error"] .rb-qr__canvas:empty::before {
59
+ content: "QR code could not be rendered.";
60
+ color: var(--rb-qr-muted);
61
+ }
62
+
63
+ .rb-qr[data-qr="pending"] .rb-qr__canvas:empty::before {
64
+ content: "Rendering QR code…";
65
+ color: var(--rb-qr-muted);
66
+ }
67
+
68
+ html[data-theme="dark"] .rb-qr,
69
+ html.dark .rb-qr {
70
+ --rb-qr-paper: var(--rb-color-ink, #000000);
71
+ --rb-qr-ink: var(--rb-color-paper, #ffffff);
72
+ }