@riebeckite/plugin-flashcards 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 +201 -0
- package/README.md +120 -0
- package/README_ja.md +93 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +177 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +448 -0
- package/dist/src/init.d.ts +1 -0
- package/dist/src/options.d.ts +4 -0
- package/dist/src/parse.d.ts +3 -0
- package/dist/src/placeholder.d.ts +5 -0
- package/dist/src/remark.d.ts +6 -0
- package/dist/src/render.d.ts +4 -0
- package/dist/src/runtime.d.ts +7 -0
- package/dist/src/types.d.ts +28 -0
- package/package.json +63 -0
- package/style.css +116 -0
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,120 @@
|
|
|
1
|
+
# @riebeckite/plugin-flashcards
|
|
2
|
+
|
|
3
|
+
Turn a `flashcards` code block into a study island: a small deck of cards that
|
|
4
|
+
shows a question, reveals the answer, and can be navigated and shuffled in the
|
|
5
|
+
browser. The build emits an accessible static list first, so the deck stays
|
|
6
|
+
readable with no JavaScript at all.
|
|
7
|
+
|
|
8
|
+
[日本語](./README_ja.md)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
`flashcards()` recognises fenced blocks
|
|
13
|
+
|
|
14
|
+
````md
|
|
15
|
+
```flashcards
|
|
16
|
+
What is the capital of France? :: Paris
|
|
17
|
+
|
|
18
|
+
What is 2 + 2? :: 4
|
|
19
|
+
```
|
|
20
|
+
````
|
|
21
|
+
|
|
22
|
+
and replaces them with an interactive deck.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { defineConfig } from "@riebeckite/core";
|
|
28
|
+
import { flashcardsPlugin } from "@riebeckite/plugin-flashcards";
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
// ...
|
|
32
|
+
plugins: [flashcardsPlugin()],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The plugin adds `style.css` and a client entry. The script tag is emitted by the
|
|
37
|
+
site layout; the plugin only declares it.
|
|
38
|
+
|
|
39
|
+
## Block syntax
|
|
40
|
+
|
|
41
|
+
A block holds one or more cards. Each card is a `Question :: Answer` pair. Cards
|
|
42
|
+
are separated by a blank line or by a `---` line, and an answer may span
|
|
43
|
+
multiple lines:
|
|
44
|
+
|
|
45
|
+
````md
|
|
46
|
+
```flashcards
|
|
47
|
+
Which language is this plugin written in? :: TypeScript
|
|
48
|
+
|
|
49
|
+
What does the client render? :: An interactive deck
|
|
50
|
+
---
|
|
51
|
+
Describe the fallback. :: A static ordered list.
|
|
52
|
+
It stays readable without JavaScript.
|
|
53
|
+
```
|
|
54
|
+
````
|
|
55
|
+
|
|
56
|
+
A block with no cards, a card without `::`, or a card with an empty side is
|
|
57
|
+
reported as a diagnostic (`invalid-flashcards`) and left as a code block.
|
|
58
|
+
|
|
59
|
+
## Output
|
|
60
|
+
|
|
61
|
+
At build time the block becomes
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<div class="rb-flashcards" data-flashcards data-flashcards-count="2">
|
|
65
|
+
<script type="application/json" data-flashcards-payload>
|
|
66
|
+
{"cards":[{"front":"...","back":"..."}]}
|
|
67
|
+
</script>
|
|
68
|
+
<ol class="rb-flashcards__list" data-flashcards-fallback>
|
|
69
|
+
<li class="rb-flashcards__item">
|
|
70
|
+
<span class="rb-flashcards__front">...</span>
|
|
71
|
+
<span class="rb-flashcards__back">...</span>
|
|
72
|
+
</li>
|
|
73
|
+
</ol>
|
|
74
|
+
</div>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The payload is inert and escaped, so card text containing `<`, `>`, or `&` can
|
|
78
|
+
never close the script element. The ordered list is the no-JavaScript fallback.
|
|
79
|
+
|
|
80
|
+
## Client behaviour
|
|
81
|
+
|
|
82
|
+
`initFlashcards()` reads the payload of every `[data-flashcards]` element and
|
|
83
|
+
adds an interactive deck above the fallback. It supports:
|
|
84
|
+
|
|
85
|
+
- Reveal / hide the answer
|
|
86
|
+
- Previous and next card with wrap-around
|
|
87
|
+
- Shuffle
|
|
88
|
+
- A live card counter
|
|
89
|
+
- Keyboard control: `Space` reveals, `ArrowLeft` / `ArrowRight` navigate
|
|
90
|
+
|
|
91
|
+
On success the root gets `data-flashcards="ready"` and the static list is
|
|
92
|
+
hidden. If the payload is missing or invalid the client leaves the fallback
|
|
93
|
+
untouched. No options are passed from the build to the client; the deck reads
|
|
94
|
+
`data-flashcards-shuffle` when it is present.
|
|
95
|
+
|
|
96
|
+
## Options
|
|
97
|
+
|
|
98
|
+
| Option | Type | Default | Description |
|
|
99
|
+
| ------ | ---- | ------- | ----------- |
|
|
100
|
+
| `className` | `string` | `"rb-flashcards"` | Root CSS class for the deck |
|
|
101
|
+
| `language` | `string` | `"flashcards"` | Fence language to target |
|
|
102
|
+
| `shuffle` | `boolean` | `false` | Start the deck in a shuffled order |
|
|
103
|
+
| `fallback` | `boolean` | `true` | Emit the static ordered list |
|
|
104
|
+
|
|
105
|
+
## Exports
|
|
106
|
+
|
|
107
|
+
- `flashcards(options?)` / `flashcardsPlugin(options?)` — plugin factory
|
|
108
|
+
- `initFlashcards(root?)` — client initializer
|
|
109
|
+
- `parseFlashcards(source)` — parse a block into cards
|
|
110
|
+
- `splitFlashcardGroups(source)` — split a block into card groups
|
|
111
|
+
- `remarkFlashcards(options?)` — the remark transform on its own
|
|
112
|
+
- `renderFlashcards(cards, options)` / `renderFlashcardsPayload(cards)` /
|
|
113
|
+
`renderFlashcardsFallback(cards, className?)` — build-time rendering helpers
|
|
114
|
+
- `resolveFlashcardsOptions(options?)`, `createFlashcardsRuntime(options?)`
|
|
115
|
+
- Types: `FlashcardsOptions`, `FlashcardsCard`, `FlashcardsPayload`,
|
|
116
|
+
`ResolvedFlashcardsOptions`
|
|
117
|
+
|
|
118
|
+
## See also
|
|
119
|
+
|
|
120
|
+
- [Plugin guide](../../../docs/en/plugin-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @riebeckite/plugin-flashcards
|
|
2
|
+
|
|
3
|
+
`flashcards` コードブロックを学習用のカードデッキに変えるプラグインです。質問を表示して答えをめくり、前後の移動とシャッフルができます。ビルド時には静的なリストを先に出力するため、JavaScript がなくても内容を読めます。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 設定する
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineConfig } from "@riebeckite/core";
|
|
11
|
+
import { flashcardsPlugin } from "@riebeckite/plugin-flashcards";
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
// ...
|
|
15
|
+
plugins: [flashcardsPlugin()],
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
このプラグインは `style.css` とクライアントエントリを追加します。script タグの出力はサイトのレイアウト側が行い、プラグインは宣言だけを担います。
|
|
20
|
+
|
|
21
|
+
## ブロックの書き方
|
|
22
|
+
|
|
23
|
+
ブロックには 1 枚以上のカードを書きます。カードは `質問 :: 答え` の組です。カード同士は空行または `---` の行で区切り、答えは複数行にまたがってもかまいません。
|
|
24
|
+
|
|
25
|
+
````md
|
|
26
|
+
```flashcards
|
|
27
|
+
Which language is this plugin written in? :: TypeScript
|
|
28
|
+
|
|
29
|
+
What does the client render? :: An interactive deck
|
|
30
|
+
---
|
|
31
|
+
Describe the fallback. :: A static ordered list.
|
|
32
|
+
It stays readable without JavaScript.
|
|
33
|
+
```
|
|
34
|
+
````
|
|
35
|
+
|
|
36
|
+
カードが 1 枚もない、`::` のないカードがある、どちらかの側が空である、といった場合は `invalid-flashcards` の診断を出し、コードブロックのまま残します。
|
|
37
|
+
|
|
38
|
+
## 出力
|
|
39
|
+
|
|
40
|
+
ビルド時に、ブロックは次の要素に置き換わります。
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<div class="rb-flashcards" data-flashcards data-flashcards-count="2">
|
|
44
|
+
<script type="application/json" data-flashcards-payload>
|
|
45
|
+
{"cards":[{"front":"...","back":"..."}]}
|
|
46
|
+
</script>
|
|
47
|
+
<ol class="rb-flashcards__list" data-flashcards-fallback>
|
|
48
|
+
<li class="rb-flashcards__item">
|
|
49
|
+
<span class="rb-flashcards__front">...</span>
|
|
50
|
+
<span class="rb-flashcards__back">...</span>
|
|
51
|
+
</li>
|
|
52
|
+
</ol>
|
|
53
|
+
</div>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
payload は実行されない JSON で、`<` `>` `&` はエスケープ済みです。カードの文言にこれらの文字が含まれていても script 要素を閉じることはできません。順序付きリストは JavaScript がない場合の代替表示です。
|
|
57
|
+
|
|
58
|
+
## クライアントの動作
|
|
59
|
+
|
|
60
|
+
`initFlashcards()` は各 `[data-flashcards]` 要素の payload を読み、代替リストの上に操作できるデッキを組み立てます。対応している操作は次のとおりです。
|
|
61
|
+
|
|
62
|
+
- 答えの表示・非表示
|
|
63
|
+
- 前後のカードへの移動(端で折り返す)
|
|
64
|
+
- シャッフル
|
|
65
|
+
- カード位置の表示
|
|
66
|
+
- キーボード操作: `Space` で答えを表示、`ArrowLeft` / `ArrowRight` で移動
|
|
67
|
+
|
|
68
|
+
成功するとルートに `data-flashcards="ready"` が付き、静的なリストは非表示になります。payload がない、または壊れている場合は代替表示をそのまま残します。ビルドからクライアントへオプションは渡しません。シャッフルの初期状態は `data-flashcards-shuffle` 属性で伝えます。
|
|
69
|
+
|
|
70
|
+
## オプション
|
|
71
|
+
|
|
72
|
+
| 項目 | 型 | 既定値 | 説明 |
|
|
73
|
+
| --- | --- | --- | --- |
|
|
74
|
+
| `className` | `string` | `"rb-flashcards"` | デッキのルート CSS クラス |
|
|
75
|
+
| `language` | `string` | `"flashcards"` | 対象にするフェンス言語 |
|
|
76
|
+
| `shuffle` | `boolean` | `false` | 最初からシャッフルした順で表示する |
|
|
77
|
+
| `fallback` | `boolean` | `true` | 静的な順序付きリストを出力する |
|
|
78
|
+
|
|
79
|
+
## 主なエクスポート
|
|
80
|
+
|
|
81
|
+
- `flashcards(options?)` / `flashcardsPlugin(options?)`: プラグインを作成する
|
|
82
|
+
- `initFlashcards(root?)`: クライアント側を初期化する
|
|
83
|
+
- `parseFlashcards(source)`: ブロックをカードに分解する
|
|
84
|
+
- `splitFlashcardGroups(source)`: ブロックをカードのまとまりに分割する
|
|
85
|
+
- `remarkFlashcards(options?)`: remark 変換を単体で使う
|
|
86
|
+
- `renderFlashcards(cards, options)` / `renderFlashcardsPayload(cards)` /
|
|
87
|
+
`renderFlashcardsFallback(cards, className?)`: ビルド時の描画ヘルパー
|
|
88
|
+
- `resolveFlashcardsOptions(options?)`、`createFlashcardsRuntime(options?)`
|
|
89
|
+
- 型: `FlashcardsOptions`、`FlashcardsCard`、`FlashcardsPayload`、`ResolvedFlashcardsOptions`
|
|
90
|
+
|
|
91
|
+
## 関連資料
|
|
92
|
+
|
|
93
|
+
- [プラグインシステム](../../../docs/ja/plugin-system.md)
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/init.ts
|
|
2
|
+
var ROOT_SELECTOR = "[data-flashcards]";
|
|
3
|
+
var PAYLOAD_SELECTOR = "script[data-flashcards-payload]";
|
|
4
|
+
var FALLBACK_SELECTOR = "[data-flashcards-fallback]";
|
|
5
|
+
var DEFAULT_CLASS = "rb-flashcards";
|
|
6
|
+
function initFlashcards(root = document) {
|
|
7
|
+
const decks = Array.from(root.querySelectorAll(ROOT_SELECTOR));
|
|
8
|
+
const cleanups = [];
|
|
9
|
+
for (const deck of decks) {
|
|
10
|
+
const cleanup = initializeDeck(deck);
|
|
11
|
+
if (cleanup) cleanups.push(cleanup);
|
|
12
|
+
}
|
|
13
|
+
return () => {
|
|
14
|
+
for (const cleanup of cleanups) cleanup();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function initializeDeck(deck) {
|
|
18
|
+
if (deck.dataset.flashcards === "ready") return null;
|
|
19
|
+
let cards;
|
|
20
|
+
try {
|
|
21
|
+
cards = readCards(deck);
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (cards.length === 0) return null;
|
|
26
|
+
try {
|
|
27
|
+
return buildDeck(deck, cards);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function buildDeck(deck, cards) {
|
|
33
|
+
const prefix = classPrefix(deck);
|
|
34
|
+
const order = cards.map((_card, index) => index);
|
|
35
|
+
if (deck.dataset.flashcardsShuffle === "true") shuffleOrder(order);
|
|
36
|
+
const state = { position: 0, revealed: false };
|
|
37
|
+
const ui = createDeckUi(deck.ownerDocument, prefix);
|
|
38
|
+
ui.root.tabIndex = 0;
|
|
39
|
+
const render = () => {
|
|
40
|
+
const card = cards[order[state.position]];
|
|
41
|
+
if (!card) return;
|
|
42
|
+
ui.question.textContent = card.front;
|
|
43
|
+
ui.answer.textContent = card.back;
|
|
44
|
+
ui.answer.hidden = !state.revealed;
|
|
45
|
+
ui.reveal.textContent = state.revealed ? "Hide answer" : "Show answer";
|
|
46
|
+
ui.reveal.setAttribute("aria-pressed", state.revealed ? "true" : "false");
|
|
47
|
+
ui.counter.textContent = `${state.position + 1} / ${cards.length}`;
|
|
48
|
+
};
|
|
49
|
+
const toggle = () => {
|
|
50
|
+
state.revealed = !state.revealed;
|
|
51
|
+
render();
|
|
52
|
+
};
|
|
53
|
+
const move = (delta) => {
|
|
54
|
+
const total = order.length;
|
|
55
|
+
state.position = (state.position + delta + total) % total;
|
|
56
|
+
state.revealed = false;
|
|
57
|
+
render();
|
|
58
|
+
};
|
|
59
|
+
const handleReveal = () => toggle();
|
|
60
|
+
const handlePrev = () => move(-1);
|
|
61
|
+
const handleNext = () => move(1);
|
|
62
|
+
const handleShuffle = () => {
|
|
63
|
+
shuffleOrder(order);
|
|
64
|
+
state.position = 0;
|
|
65
|
+
state.revealed = false;
|
|
66
|
+
render();
|
|
67
|
+
};
|
|
68
|
+
const handleKeyDown = (event) => {
|
|
69
|
+
if (event.key === "ArrowRight") {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
handleNext();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (event.key === "ArrowLeft") {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
handlePrev();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (event.key === " " || event.key === "Spacebar") {
|
|
80
|
+
if (event.target instanceof HTMLButtonElement) return;
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
toggle();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
ui.reveal.addEventListener("click", handleReveal);
|
|
86
|
+
ui.prev.addEventListener("click", handlePrev);
|
|
87
|
+
ui.next.addEventListener("click", handleNext);
|
|
88
|
+
ui.shuffle.addEventListener("click", handleShuffle);
|
|
89
|
+
ui.root.addEventListener("keydown", handleKeyDown);
|
|
90
|
+
const fallback = deck.querySelector(FALLBACK_SELECTOR);
|
|
91
|
+
deck.insertBefore(ui.root, fallback ?? null);
|
|
92
|
+
if (fallback) fallback.hidden = true;
|
|
93
|
+
deck.dataset.flashcards = "ready";
|
|
94
|
+
render();
|
|
95
|
+
return () => {
|
|
96
|
+
ui.reveal.removeEventListener("click", handleReveal);
|
|
97
|
+
ui.prev.removeEventListener("click", handlePrev);
|
|
98
|
+
ui.next.removeEventListener("click", handleNext);
|
|
99
|
+
ui.shuffle.removeEventListener("click", handleShuffle);
|
|
100
|
+
ui.root.removeEventListener("keydown", handleKeyDown);
|
|
101
|
+
ui.root.remove();
|
|
102
|
+
if (fallback) fallback.hidden = false;
|
|
103
|
+
delete deck.dataset.flashcards;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function createDeckUi(doc, prefix) {
|
|
107
|
+
const root = doc.createElement("div");
|
|
108
|
+
root.className = `${prefix}__deck`;
|
|
109
|
+
root.setAttribute("role", "group");
|
|
110
|
+
root.setAttribute("aria-label", "Flashcards");
|
|
111
|
+
const counter = doc.createElement("p");
|
|
112
|
+
counter.className = `${prefix}__counter`;
|
|
113
|
+
counter.setAttribute("aria-live", "polite");
|
|
114
|
+
const card = doc.createElement("div");
|
|
115
|
+
card.className = `${prefix}__card`;
|
|
116
|
+
const question = doc.createElement("p");
|
|
117
|
+
question.className = `${prefix}__question`;
|
|
118
|
+
const answer = doc.createElement("p");
|
|
119
|
+
answer.className = `${prefix}__answer`;
|
|
120
|
+
answer.hidden = true;
|
|
121
|
+
card.append(question, answer);
|
|
122
|
+
const controls = doc.createElement("div");
|
|
123
|
+
controls.className = `${prefix}__controls`;
|
|
124
|
+
const prev = createButton(doc, prefix, "prev", "Previous card");
|
|
125
|
+
const reveal = createButton(doc, prefix, "reveal", "Show answer");
|
|
126
|
+
const next = createButton(doc, prefix, "next", "Next card");
|
|
127
|
+
const shuffle = createButton(doc, prefix, "shuffle", "Shuffle cards");
|
|
128
|
+
reveal.setAttribute("aria-pressed", "false");
|
|
129
|
+
controls.append(prev, reveal, next, shuffle);
|
|
130
|
+
root.append(counter, card, controls);
|
|
131
|
+
return { root, counter, question, answer, reveal, prev, next, shuffle };
|
|
132
|
+
}
|
|
133
|
+
function createButton(doc, prefix, action, label) {
|
|
134
|
+
const button = doc.createElement("button");
|
|
135
|
+
button.type = "button";
|
|
136
|
+
button.className = `${prefix}__button`;
|
|
137
|
+
button.dataset.flashcardsAction = action;
|
|
138
|
+
button.textContent = label;
|
|
139
|
+
return button;
|
|
140
|
+
}
|
|
141
|
+
function readCards(deck) {
|
|
142
|
+
const script = deck.querySelector(PAYLOAD_SELECTOR);
|
|
143
|
+
if (!script) throw new Error("Missing flashcards payload");
|
|
144
|
+
return parsePayload(script.textContent ?? "").cards;
|
|
145
|
+
}
|
|
146
|
+
function parsePayload(raw) {
|
|
147
|
+
const parsed = JSON.parse(raw);
|
|
148
|
+
if (!isPayload(parsed)) throw new Error("Invalid flashcards payload");
|
|
149
|
+
return parsed;
|
|
150
|
+
}
|
|
151
|
+
function isPayload(value) {
|
|
152
|
+
if (!value || typeof value !== "object") return false;
|
|
153
|
+
const cards = value.cards;
|
|
154
|
+
return Array.isArray(cards) && cards.every(isCard);
|
|
155
|
+
}
|
|
156
|
+
function isCard(value) {
|
|
157
|
+
if (!value || typeof value !== "object") return false;
|
|
158
|
+
const card = value;
|
|
159
|
+
return typeof card.front === "string" && typeof card.back === "string";
|
|
160
|
+
}
|
|
161
|
+
function classPrefix(deck) {
|
|
162
|
+
for (const name of deck.className.split(/\s+/)) {
|
|
163
|
+
if (name.length > 0) return name;
|
|
164
|
+
}
|
|
165
|
+
return DEFAULT_CLASS;
|
|
166
|
+
}
|
|
167
|
+
function shuffleOrder(order) {
|
|
168
|
+
for (let index = order.length - 1; index > 0; index -= 1) {
|
|
169
|
+
const swap = Math.floor(Math.random() * (index + 1));
|
|
170
|
+
const current = order[index];
|
|
171
|
+
order[index] = order[swap];
|
|
172
|
+
order[swap] = current;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export {
|
|
176
|
+
initFlashcards
|
|
177
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FlashcardsOptions } from "./src/types.js";
|
|
2
|
+
export { initFlashcards } from "./src/init.js";
|
|
3
|
+
export { DEFAULT_FLASHCARDS_CLASS, DEFAULT_FLASHCARDS_LANGUAGE, resolveFlashcardsOptions, } from "./src/options.js";
|
|
4
|
+
export { parseFlashcards, splitFlashcardGroups } from "./src/parse.js";
|
|
5
|
+
export { createFlashcardsPlaceholder, createFlashcardsPlaceholderPattern, decodeFlashcardsSource, encodeFlashcardsSource, FLASHCARDS_ATTRIBUTE, } from "./src/placeholder.js";
|
|
6
|
+
export { remarkFlashcards } from "./src/remark.js";
|
|
7
|
+
export { renderFlashcards, renderFlashcardsFallback, renderFlashcardsPayload, } from "./src/render.js";
|
|
8
|
+
export { createFlashcardsRuntime } from "./src/runtime.js";
|
|
9
|
+
export type { FlashcardsRuntime } from "./src/runtime.js";
|
|
10
|
+
export type { FlashcardsCard, FlashcardsOptions, FlashcardsParseFailure, FlashcardsParseResult, FlashcardsParseSuccess, FlashcardsPayload, ResolvedFlashcardsOptions, } from "./src/types.js";
|
|
11
|
+
export declare function flashcards(options?: FlashcardsOptions): import("@riebeckite/core").RiebeckitePlugin<FlashcardsOptions>;
|
|
12
|
+
export declare const flashcardsPlugin: typeof flashcards;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createClientEntry,
|
|
4
|
+
createStyleAsset,
|
|
5
|
+
definePlugin
|
|
6
|
+
} from "@riebeckite/core";
|
|
7
|
+
|
|
8
|
+
// src/options.ts
|
|
9
|
+
var DEFAULT_FLASHCARDS_CLASS = "rb-flashcards";
|
|
10
|
+
var DEFAULT_FLASHCARDS_LANGUAGE = "flashcards";
|
|
11
|
+
function resolveFlashcardsOptions(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
className: options.className ?? DEFAULT_FLASHCARDS_CLASS,
|
|
14
|
+
language: options.language ?? DEFAULT_FLASHCARDS_LANGUAGE,
|
|
15
|
+
shuffle: options.shuffle ?? false,
|
|
16
|
+
fallback: options.fallback ?? true
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/remark.ts
|
|
21
|
+
import { visit } from "unist-util-visit";
|
|
22
|
+
|
|
23
|
+
// src/placeholder.ts
|
|
24
|
+
var FLASHCARDS_ATTRIBUTE = "data-rr-flashcards-spec";
|
|
25
|
+
function encodeFlashcardsSource(source) {
|
|
26
|
+
return encodeURIComponent(source);
|
|
27
|
+
}
|
|
28
|
+
function decodeFlashcardsSource(encoded) {
|
|
29
|
+
return decodeURIComponent(encoded);
|
|
30
|
+
}
|
|
31
|
+
function createFlashcardsPlaceholder(source) {
|
|
32
|
+
return `<div ${FLASHCARDS_ATTRIBUTE}="${encodeFlashcardsSource(source)}"></div>`;
|
|
33
|
+
}
|
|
34
|
+
function createFlashcardsPlaceholderPattern() {
|
|
35
|
+
return new RegExp(
|
|
36
|
+
`<div\\b[^>]*\\b${FLASHCARDS_ATTRIBUTE}="([^"]*)"[^>]*>\\s*</div>`,
|
|
37
|
+
"g"
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/parse.ts
|
|
42
|
+
var SEPARATOR_LINE = /^[ \t]*-{3,}[ \t]*$/gm;
|
|
43
|
+
var GROUP_BREAK = /\n[ \t]*\n/;
|
|
44
|
+
var CARD_DELIMITER = "::";
|
|
45
|
+
function parseFlashcards(source) {
|
|
46
|
+
const groups = splitFlashcardGroups(source);
|
|
47
|
+
if (groups.length === 0) {
|
|
48
|
+
return { ok: false, reason: "is empty" };
|
|
49
|
+
}
|
|
50
|
+
const cards = [];
|
|
51
|
+
for (const group of groups) {
|
|
52
|
+
const parsed = parseCard(group);
|
|
53
|
+
if (typeof parsed === "string") {
|
|
54
|
+
return { ok: false, reason: parsed };
|
|
55
|
+
}
|
|
56
|
+
cards.push(parsed);
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, cards };
|
|
59
|
+
}
|
|
60
|
+
function splitFlashcardGroups(source) {
|
|
61
|
+
return source.replace(/\r\n?/g, "\n").replace(SEPARATOR_LINE, "").split(GROUP_BREAK).map((group) => group.trim()).filter((group) => group.length > 0);
|
|
62
|
+
}
|
|
63
|
+
function parseCard(group) {
|
|
64
|
+
const delimiter = group.indexOf(CARD_DELIMITER);
|
|
65
|
+
if (delimiter < 0) {
|
|
66
|
+
return 'has a card without the "::" separator';
|
|
67
|
+
}
|
|
68
|
+
const front = group.slice(0, delimiter).trim();
|
|
69
|
+
const back = group.slice(delimiter + CARD_DELIMITER.length).trim();
|
|
70
|
+
if (front.length === 0 || back.length === 0) {
|
|
71
|
+
return "has a card with an empty question or answer";
|
|
72
|
+
}
|
|
73
|
+
return { front, back };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/remark.ts
|
|
77
|
+
var FLASHCARDS_DIAGNOSTIC_SOURCE = "@riebeckite/plugin-flashcards";
|
|
78
|
+
function remarkFlashcards(options = {}) {
|
|
79
|
+
const language = options.language ?? "flashcards";
|
|
80
|
+
return (tree, file) => {
|
|
81
|
+
visit(tree, "code", (node, index, parent) => {
|
|
82
|
+
if (node.lang !== language) return;
|
|
83
|
+
if (!parent || index === void 0) return;
|
|
84
|
+
const parsed = parseFlashcards(node.value);
|
|
85
|
+
if (parsed.ok === false) {
|
|
86
|
+
reportInvalidBlock(file, parsed.reason);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const html = {
|
|
90
|
+
type: "html",
|
|
91
|
+
value: createFlashcardsPlaceholder(node.value)
|
|
92
|
+
};
|
|
93
|
+
parent.children.splice(index, 1, html);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function reportInvalidBlock(file, reason) {
|
|
98
|
+
const reporter = file?.message;
|
|
99
|
+
if (typeof reporter !== "function") return;
|
|
100
|
+
const diagnostic = reporter.call(
|
|
101
|
+
file,
|
|
102
|
+
`Invalid flashcards block: ${reason}.`
|
|
103
|
+
);
|
|
104
|
+
if (diagnostic && typeof diagnostic === "object") {
|
|
105
|
+
Object.assign(diagnostic, {
|
|
106
|
+
source: FLASHCARDS_DIAGNOSTIC_SOURCE,
|
|
107
|
+
ruleId: "invalid-flashcards"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/runtime.ts
|
|
113
|
+
import {
|
|
114
|
+
escapeHtml as escapeHtml2
|
|
115
|
+
} from "@riebeckite/core";
|
|
116
|
+
|
|
117
|
+
// src/render.ts
|
|
118
|
+
import { escapeHtml, escapeHtmlAttribute } from "@riebeckite/core";
|
|
119
|
+
function renderFlashcards(cards, options) {
|
|
120
|
+
const { className } = options;
|
|
121
|
+
const attributes = [
|
|
122
|
+
`class="${escapeHtmlAttribute(className)}"`,
|
|
123
|
+
"data-flashcards",
|
|
124
|
+
`data-flashcards-count="${cards.length}"`
|
|
125
|
+
];
|
|
126
|
+
if (options.shuffle) {
|
|
127
|
+
attributes.push('data-flashcards-shuffle="true"');
|
|
128
|
+
}
|
|
129
|
+
const children = [renderFlashcardsPayload(cards)];
|
|
130
|
+
if (options.fallback) {
|
|
131
|
+
children.push(renderFlashcardsFallback(cards, className));
|
|
132
|
+
}
|
|
133
|
+
return `<div ${attributes.join(" ")}>${children.join("")}</div>`;
|
|
134
|
+
}
|
|
135
|
+
function renderFlashcardsPayload(cards) {
|
|
136
|
+
const payload = { cards: [...cards] };
|
|
137
|
+
return `<script type="application/json" data-flashcards-payload>${escapeJsonForScript(JSON.stringify(payload))}</script>`;
|
|
138
|
+
}
|
|
139
|
+
function renderFlashcardsFallback(cards, className = "rb-flashcards") {
|
|
140
|
+
const items = cards.map((card) => renderFallbackItem(card, className)).join("");
|
|
141
|
+
return `<ol class="${escapeHtmlAttribute(className)}__list" data-flashcards-fallback>${items}</ol>`;
|
|
142
|
+
}
|
|
143
|
+
function renderFallbackItem(card, className) {
|
|
144
|
+
const front = escapeHtml(card.front).replace(/\n/g, "<br>");
|
|
145
|
+
const back = escapeHtml(card.back).replace(/\n/g, "<br>");
|
|
146
|
+
return [
|
|
147
|
+
`<li class="${escapeHtmlAttribute(className)}__item">`,
|
|
148
|
+
`<span class="${escapeHtmlAttribute(className)}__front">${front}</span>`,
|
|
149
|
+
`<span class="${escapeHtmlAttribute(className)}__back">${back}</span>`,
|
|
150
|
+
"</li>"
|
|
151
|
+
].join("");
|
|
152
|
+
}
|
|
153
|
+
function escapeJsonForScript(json) {
|
|
154
|
+
return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/runtime.ts
|
|
158
|
+
function createFlashcardsRuntime(options) {
|
|
159
|
+
const resolved = resolveFlashcardsOptions(options);
|
|
160
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
161
|
+
return {
|
|
162
|
+
track(slug, content) {
|
|
163
|
+
tracked.set(slug, content);
|
|
164
|
+
},
|
|
165
|
+
resolve(manifest, diagnostics) {
|
|
166
|
+
for (const entry of manifest.entries) {
|
|
167
|
+
if (!entry.html.includes(FLASHCARDS_ATTRIBUTE)) continue;
|
|
168
|
+
const html = replacePlaceholders(entry, resolved, diagnostics);
|
|
169
|
+
if (html === entry.html) continue;
|
|
170
|
+
entry.html = html;
|
|
171
|
+
const content = tracked.get(entry.slug);
|
|
172
|
+
if (content) content.html = html;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function replacePlaceholders(entry, options, diagnostics) {
|
|
178
|
+
const pattern = createFlashcardsPlaceholderPattern();
|
|
179
|
+
return entry.html.replace(pattern, (_match, encoded) => {
|
|
180
|
+
let source;
|
|
181
|
+
try {
|
|
182
|
+
source = decodeFlashcardsSource(encoded);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return reportInvalid(
|
|
185
|
+
entry,
|
|
186
|
+
options,
|
|
187
|
+
diagnostics,
|
|
188
|
+
`could not be decoded (${formatError(error)})`,
|
|
189
|
+
""
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const parsed = parseFlashcards(source);
|
|
193
|
+
if (parsed.ok === false) {
|
|
194
|
+
return reportInvalid(entry, options, diagnostics, parsed.reason, source);
|
|
195
|
+
}
|
|
196
|
+
return renderFlashcards(parsed.cards, options);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function reportInvalid(entry, options, diagnostics, reason, source) {
|
|
200
|
+
const message = `Flashcards block in \`${entry.slug}\` ${reason}.`;
|
|
201
|
+
diagnostics.push({
|
|
202
|
+
code: "flashcards-invalid",
|
|
203
|
+
severity: "error",
|
|
204
|
+
pluginName: "flashcards",
|
|
205
|
+
slug: entry.slug,
|
|
206
|
+
message
|
|
207
|
+
});
|
|
208
|
+
const className = escapeHtml2(options.className);
|
|
209
|
+
return `<pre class="${className} ${className}--invalid"><code>${escapeHtml2(source)}</code></pre>`;
|
|
210
|
+
}
|
|
211
|
+
function formatError(error) {
|
|
212
|
+
return error instanceof Error ? error.message : String(error);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/init.ts
|
|
216
|
+
var ROOT_SELECTOR = "[data-flashcards]";
|
|
217
|
+
var PAYLOAD_SELECTOR = "script[data-flashcards-payload]";
|
|
218
|
+
var FALLBACK_SELECTOR = "[data-flashcards-fallback]";
|
|
219
|
+
var DEFAULT_CLASS = "rb-flashcards";
|
|
220
|
+
function initFlashcards(root = document) {
|
|
221
|
+
const decks = Array.from(root.querySelectorAll(ROOT_SELECTOR));
|
|
222
|
+
const cleanups = [];
|
|
223
|
+
for (const deck of decks) {
|
|
224
|
+
const cleanup = initializeDeck(deck);
|
|
225
|
+
if (cleanup) cleanups.push(cleanup);
|
|
226
|
+
}
|
|
227
|
+
return () => {
|
|
228
|
+
for (const cleanup of cleanups) cleanup();
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function initializeDeck(deck) {
|
|
232
|
+
if (deck.dataset.flashcards === "ready") return null;
|
|
233
|
+
let cards;
|
|
234
|
+
try {
|
|
235
|
+
cards = readCards(deck);
|
|
236
|
+
} catch {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
if (cards.length === 0) return null;
|
|
240
|
+
try {
|
|
241
|
+
return buildDeck(deck, cards);
|
|
242
|
+
} catch {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function buildDeck(deck, cards) {
|
|
247
|
+
const prefix = classPrefix(deck);
|
|
248
|
+
const order = cards.map((_card, index) => index);
|
|
249
|
+
if (deck.dataset.flashcardsShuffle === "true") shuffleOrder(order);
|
|
250
|
+
const state = { position: 0, revealed: false };
|
|
251
|
+
const ui = createDeckUi(deck.ownerDocument, prefix);
|
|
252
|
+
ui.root.tabIndex = 0;
|
|
253
|
+
const render = () => {
|
|
254
|
+
const card = cards[order[state.position]];
|
|
255
|
+
if (!card) return;
|
|
256
|
+
ui.question.textContent = card.front;
|
|
257
|
+
ui.answer.textContent = card.back;
|
|
258
|
+
ui.answer.hidden = !state.revealed;
|
|
259
|
+
ui.reveal.textContent = state.revealed ? "Hide answer" : "Show answer";
|
|
260
|
+
ui.reveal.setAttribute("aria-pressed", state.revealed ? "true" : "false");
|
|
261
|
+
ui.counter.textContent = `${state.position + 1} / ${cards.length}`;
|
|
262
|
+
};
|
|
263
|
+
const toggle = () => {
|
|
264
|
+
state.revealed = !state.revealed;
|
|
265
|
+
render();
|
|
266
|
+
};
|
|
267
|
+
const move = (delta) => {
|
|
268
|
+
const total = order.length;
|
|
269
|
+
state.position = (state.position + delta + total) % total;
|
|
270
|
+
state.revealed = false;
|
|
271
|
+
render();
|
|
272
|
+
};
|
|
273
|
+
const handleReveal = () => toggle();
|
|
274
|
+
const handlePrev = () => move(-1);
|
|
275
|
+
const handleNext = () => move(1);
|
|
276
|
+
const handleShuffle = () => {
|
|
277
|
+
shuffleOrder(order);
|
|
278
|
+
state.position = 0;
|
|
279
|
+
state.revealed = false;
|
|
280
|
+
render();
|
|
281
|
+
};
|
|
282
|
+
const handleKeyDown = (event) => {
|
|
283
|
+
if (event.key === "ArrowRight") {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
handleNext();
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (event.key === "ArrowLeft") {
|
|
289
|
+
event.preventDefault();
|
|
290
|
+
handlePrev();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
if (event.key === " " || event.key === "Spacebar") {
|
|
294
|
+
if (event.target instanceof HTMLButtonElement) return;
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
toggle();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
ui.reveal.addEventListener("click", handleReveal);
|
|
300
|
+
ui.prev.addEventListener("click", handlePrev);
|
|
301
|
+
ui.next.addEventListener("click", handleNext);
|
|
302
|
+
ui.shuffle.addEventListener("click", handleShuffle);
|
|
303
|
+
ui.root.addEventListener("keydown", handleKeyDown);
|
|
304
|
+
const fallback = deck.querySelector(FALLBACK_SELECTOR);
|
|
305
|
+
deck.insertBefore(ui.root, fallback ?? null);
|
|
306
|
+
if (fallback) fallback.hidden = true;
|
|
307
|
+
deck.dataset.flashcards = "ready";
|
|
308
|
+
render();
|
|
309
|
+
return () => {
|
|
310
|
+
ui.reveal.removeEventListener("click", handleReveal);
|
|
311
|
+
ui.prev.removeEventListener("click", handlePrev);
|
|
312
|
+
ui.next.removeEventListener("click", handleNext);
|
|
313
|
+
ui.shuffle.removeEventListener("click", handleShuffle);
|
|
314
|
+
ui.root.removeEventListener("keydown", handleKeyDown);
|
|
315
|
+
ui.root.remove();
|
|
316
|
+
if (fallback) fallback.hidden = false;
|
|
317
|
+
delete deck.dataset.flashcards;
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function createDeckUi(doc, prefix) {
|
|
321
|
+
const root = doc.createElement("div");
|
|
322
|
+
root.className = `${prefix}__deck`;
|
|
323
|
+
root.setAttribute("role", "group");
|
|
324
|
+
root.setAttribute("aria-label", "Flashcards");
|
|
325
|
+
const counter = doc.createElement("p");
|
|
326
|
+
counter.className = `${prefix}__counter`;
|
|
327
|
+
counter.setAttribute("aria-live", "polite");
|
|
328
|
+
const card = doc.createElement("div");
|
|
329
|
+
card.className = `${prefix}__card`;
|
|
330
|
+
const question = doc.createElement("p");
|
|
331
|
+
question.className = `${prefix}__question`;
|
|
332
|
+
const answer = doc.createElement("p");
|
|
333
|
+
answer.className = `${prefix}__answer`;
|
|
334
|
+
answer.hidden = true;
|
|
335
|
+
card.append(question, answer);
|
|
336
|
+
const controls = doc.createElement("div");
|
|
337
|
+
controls.className = `${prefix}__controls`;
|
|
338
|
+
const prev = createButton(doc, prefix, "prev", "Previous card");
|
|
339
|
+
const reveal = createButton(doc, prefix, "reveal", "Show answer");
|
|
340
|
+
const next = createButton(doc, prefix, "next", "Next card");
|
|
341
|
+
const shuffle = createButton(doc, prefix, "shuffle", "Shuffle cards");
|
|
342
|
+
reveal.setAttribute("aria-pressed", "false");
|
|
343
|
+
controls.append(prev, reveal, next, shuffle);
|
|
344
|
+
root.append(counter, card, controls);
|
|
345
|
+
return { root, counter, question, answer, reveal, prev, next, shuffle };
|
|
346
|
+
}
|
|
347
|
+
function createButton(doc, prefix, action, label) {
|
|
348
|
+
const button = doc.createElement("button");
|
|
349
|
+
button.type = "button";
|
|
350
|
+
button.className = `${prefix}__button`;
|
|
351
|
+
button.dataset.flashcardsAction = action;
|
|
352
|
+
button.textContent = label;
|
|
353
|
+
return button;
|
|
354
|
+
}
|
|
355
|
+
function readCards(deck) {
|
|
356
|
+
const script = deck.querySelector(PAYLOAD_SELECTOR);
|
|
357
|
+
if (!script) throw new Error("Missing flashcards payload");
|
|
358
|
+
return parsePayload(script.textContent ?? "").cards;
|
|
359
|
+
}
|
|
360
|
+
function parsePayload(raw) {
|
|
361
|
+
const parsed = JSON.parse(raw);
|
|
362
|
+
if (!isPayload(parsed)) throw new Error("Invalid flashcards payload");
|
|
363
|
+
return parsed;
|
|
364
|
+
}
|
|
365
|
+
function isPayload(value) {
|
|
366
|
+
if (!value || typeof value !== "object") return false;
|
|
367
|
+
const cards = value.cards;
|
|
368
|
+
return Array.isArray(cards) && cards.every(isCard);
|
|
369
|
+
}
|
|
370
|
+
function isCard(value) {
|
|
371
|
+
if (!value || typeof value !== "object") return false;
|
|
372
|
+
const card = value;
|
|
373
|
+
return typeof card.front === "string" && typeof card.back === "string";
|
|
374
|
+
}
|
|
375
|
+
function classPrefix(deck) {
|
|
376
|
+
for (const name of deck.className.split(/\s+/)) {
|
|
377
|
+
if (name.length > 0) return name;
|
|
378
|
+
}
|
|
379
|
+
return DEFAULT_CLASS;
|
|
380
|
+
}
|
|
381
|
+
function shuffleOrder(order) {
|
|
382
|
+
for (let index = order.length - 1; index > 0; index -= 1) {
|
|
383
|
+
const swap = Math.floor(Math.random() * (index + 1));
|
|
384
|
+
const current = order[index];
|
|
385
|
+
order[index] = order[swap];
|
|
386
|
+
order[swap] = current;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// index.ts
|
|
391
|
+
function flashcards(options = {}) {
|
|
392
|
+
const resolved = resolveFlashcardsOptions(options);
|
|
393
|
+
const runtime = createFlashcardsRuntime(options);
|
|
394
|
+
return definePlugin({
|
|
395
|
+
name: "flashcards",
|
|
396
|
+
options,
|
|
397
|
+
validateOptions: validateFlashcardsOptions,
|
|
398
|
+
extendMarkdownPipeline: (pipeline) => {
|
|
399
|
+
pipeline.use(remarkFlashcards, { language: resolved.language });
|
|
400
|
+
},
|
|
401
|
+
onPostProcessed: (context) => {
|
|
402
|
+
runtime.track(context.slug, context.content);
|
|
403
|
+
},
|
|
404
|
+
onManifestCreated: (context) => {
|
|
405
|
+
runtime.resolve(context.manifest, context.diagnostics);
|
|
406
|
+
},
|
|
407
|
+
assets: [createStyleAsset("flashcards")],
|
|
408
|
+
clientEntries: [createClientEntry("flashcards", "initFlashcards")]
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
var flashcardsPlugin = flashcards;
|
|
412
|
+
function validateFlashcardsOptions(options) {
|
|
413
|
+
if (!options) return [];
|
|
414
|
+
const issues = [];
|
|
415
|
+
if (options.className !== void 0 && (typeof options.className !== "string" || options.className.trim() === "")) {
|
|
416
|
+
issues.push({ path: "className", message: "Expected a non-empty string." });
|
|
417
|
+
}
|
|
418
|
+
if (options.language !== void 0 && (typeof options.language !== "string" || options.language.trim() === "")) {
|
|
419
|
+
issues.push({ path: "language", message: "Expected a non-empty string." });
|
|
420
|
+
}
|
|
421
|
+
if (options.shuffle !== void 0 && typeof options.shuffle !== "boolean") {
|
|
422
|
+
issues.push({ path: "shuffle", message: "Expected a boolean." });
|
|
423
|
+
}
|
|
424
|
+
if (options.fallback !== void 0 && typeof options.fallback !== "boolean") {
|
|
425
|
+
issues.push({ path: "fallback", message: "Expected a boolean." });
|
|
426
|
+
}
|
|
427
|
+
return issues;
|
|
428
|
+
}
|
|
429
|
+
export {
|
|
430
|
+
DEFAULT_FLASHCARDS_CLASS,
|
|
431
|
+
DEFAULT_FLASHCARDS_LANGUAGE,
|
|
432
|
+
FLASHCARDS_ATTRIBUTE,
|
|
433
|
+
createFlashcardsPlaceholder,
|
|
434
|
+
createFlashcardsPlaceholderPattern,
|
|
435
|
+
createFlashcardsRuntime,
|
|
436
|
+
decodeFlashcardsSource,
|
|
437
|
+
encodeFlashcardsSource,
|
|
438
|
+
flashcards,
|
|
439
|
+
flashcardsPlugin,
|
|
440
|
+
initFlashcards,
|
|
441
|
+
parseFlashcards,
|
|
442
|
+
remarkFlashcards,
|
|
443
|
+
renderFlashcards,
|
|
444
|
+
renderFlashcardsFallback,
|
|
445
|
+
renderFlashcardsPayload,
|
|
446
|
+
resolveFlashcardsOptions,
|
|
447
|
+
splitFlashcardGroups
|
|
448
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initFlashcards(root?: ParentNode): () => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FlashcardsOptions, ResolvedFlashcardsOptions } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_FLASHCARDS_CLASS = "rb-flashcards";
|
|
3
|
+
export declare const DEFAULT_FLASHCARDS_LANGUAGE = "flashcards";
|
|
4
|
+
export declare function resolveFlashcardsOptions(options?: FlashcardsOptions): ResolvedFlashcardsOptions;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const FLASHCARDS_ATTRIBUTE = "data-rr-flashcards-spec";
|
|
2
|
+
export declare function encodeFlashcardsSource(source: string): string;
|
|
3
|
+
export declare function decodeFlashcardsSource(encoded: string): string;
|
|
4
|
+
export declare function createFlashcardsPlaceholder(source: string): string;
|
|
5
|
+
export declare function createFlashcardsPlaceholderPattern(): RegExp;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Root } from "mdast";
|
|
2
|
+
export declare const FLASHCARDS_DIAGNOSTIC_SOURCE = "@riebeckite/plugin-flashcards";
|
|
3
|
+
export type RemarkFlashcardsOptions = {
|
|
4
|
+
language?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function remarkFlashcards(options?: RemarkFlashcardsOptions): (tree: Root, file?: unknown) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FlashcardsCard, ResolvedFlashcardsOptions } from "./types.js";
|
|
2
|
+
export declare function renderFlashcards(cards: readonly FlashcardsCard[], options: ResolvedFlashcardsOptions): string;
|
|
3
|
+
export declare function renderFlashcardsPayload(cards: readonly FlashcardsCard[]): string;
|
|
4
|
+
export declare function renderFlashcardsFallback(cards: readonly FlashcardsCard[], className?: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ContentManifest, type Diagnostic, type PostContent } from "@riebeckite/core";
|
|
2
|
+
import type { FlashcardsOptions } from "./types.js";
|
|
3
|
+
export type FlashcardsRuntime = {
|
|
4
|
+
track(slug: string, content: PostContent): void;
|
|
5
|
+
resolve(manifest: ContentManifest, diagnostics: Diagnostic[]): void;
|
|
6
|
+
};
|
|
7
|
+
export declare function createFlashcardsRuntime(options: FlashcardsOptions): FlashcardsRuntime;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type FlashcardsCard = {
|
|
2
|
+
front: string;
|
|
3
|
+
back: string;
|
|
4
|
+
};
|
|
5
|
+
export type FlashcardsOptions = {
|
|
6
|
+
className?: string;
|
|
7
|
+
language?: string;
|
|
8
|
+
shuffle?: boolean;
|
|
9
|
+
fallback?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ResolvedFlashcardsOptions = {
|
|
12
|
+
className: string;
|
|
13
|
+
language: string;
|
|
14
|
+
shuffle: boolean;
|
|
15
|
+
fallback: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type FlashcardsParseSuccess = {
|
|
18
|
+
ok: true;
|
|
19
|
+
cards: FlashcardsCard[];
|
|
20
|
+
};
|
|
21
|
+
export type FlashcardsParseFailure = {
|
|
22
|
+
ok: false;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export type FlashcardsParseResult = FlashcardsParseSuccess | FlashcardsParseFailure;
|
|
26
|
+
export type FlashcardsPayload = {
|
|
27
|
+
cards: FlashcardsCard[];
|
|
28
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-flashcards",
|
|
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
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client.d.ts",
|
|
17
|
+
"import": "./dist/client.js",
|
|
18
|
+
"source": "./client.ts",
|
|
19
|
+
"default": "./dist/client.js"
|
|
20
|
+
},
|
|
21
|
+
"./style.css": "./style.css"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@types/mdast": "^4.0.4",
|
|
25
|
+
"unist-util-visit": "^5.1.0",
|
|
26
|
+
"@riebeckite/core": "0.0.1"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"README.md",
|
|
34
|
+
"README_ja.md",
|
|
35
|
+
"dist",
|
|
36
|
+
"style.css"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
41
|
+
"directory": "packages/plugins/flashcards"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
46
|
+
},
|
|
47
|
+
"description": "Interactive flashcard decks from Riebeckite code blocks.",
|
|
48
|
+
"keywords": [
|
|
49
|
+
"riebeckite",
|
|
50
|
+
"plugin",
|
|
51
|
+
"flashcards",
|
|
52
|
+
"learning"
|
|
53
|
+
],
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
56
|
+
},
|
|
57
|
+
"sideEffects": [
|
|
58
|
+
"./style.css"
|
|
59
|
+
],
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "node ../../../scripts/build_package.mjs"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
.rb-flashcards {
|
|
2
|
+
--rb-flashcards-ink: var(--rb-color-ink, #000000);
|
|
3
|
+
--rb-flashcards-paper: var(--rb-color-paper, #ffffff);
|
|
4
|
+
--rb-flashcards-muted: var(--rb-color-muted, #69645c);
|
|
5
|
+
--rb-flashcards-accent: var(--rb-color-accent, #686868);
|
|
6
|
+
--rb-flashcards-rule: var(
|
|
7
|
+
--rb-color-border,
|
|
8
|
+
color-mix(in srgb, var(--rb-flashcards-ink) 18%, transparent)
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
margin: 1.5rem 0;
|
|
12
|
+
color: var(--rb-flashcards-ink);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.rb-flashcards__list {
|
|
16
|
+
display: grid;
|
|
17
|
+
gap: 0.75rem;
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 0;
|
|
20
|
+
list-style: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.rb-flashcards__item {
|
|
24
|
+
display: grid;
|
|
25
|
+
gap: 0.25rem;
|
|
26
|
+
padding: 0.75rem 1rem;
|
|
27
|
+
border: 1px solid var(--rb-flashcards-rule);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.rb-flashcards__front {
|
|
31
|
+
font-weight: 600;
|
|
32
|
+
white-space: pre-line;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.rb-flashcards__back {
|
|
36
|
+
color: var(--rb-flashcards-muted);
|
|
37
|
+
white-space: pre-line;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rb-flashcards__deck {
|
|
41
|
+
display: grid;
|
|
42
|
+
gap: 1rem;
|
|
43
|
+
outline-offset: 4px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.rb-flashcards__deck:focus-visible {
|
|
47
|
+
outline: 2px solid var(--rb-flashcards-accent);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.rb-flashcards__counter {
|
|
51
|
+
margin: 0;
|
|
52
|
+
color: var(--rb-flashcards-muted);
|
|
53
|
+
font-size: 0.8125rem;
|
|
54
|
+
font-variant-numeric: tabular-nums;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.rb-flashcards__card {
|
|
58
|
+
padding: 1.25rem 1.5rem;
|
|
59
|
+
border: 1px solid var(--rb-flashcards-rule);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.rb-flashcards__question {
|
|
63
|
+
margin: 0;
|
|
64
|
+
font-size: 1.0625rem;
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
line-height: 1.6;
|
|
67
|
+
white-space: pre-line;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.rb-flashcards__answer {
|
|
71
|
+
margin: 0.75rem 0 0;
|
|
72
|
+
padding-top: 0.75rem;
|
|
73
|
+
border-top: 1px solid var(--rb-flashcards-rule);
|
|
74
|
+
line-height: 1.7;
|
|
75
|
+
white-space: pre-line;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rb-flashcards__answer[hidden] {
|
|
79
|
+
display: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.rb-flashcards__controls {
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-wrap: wrap;
|
|
85
|
+
gap: 0.5rem;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.rb-flashcards__button {
|
|
89
|
+
padding: 0.375rem 0.75rem;
|
|
90
|
+
border: 1px solid var(--rb-flashcards-ink);
|
|
91
|
+
border-radius: 0;
|
|
92
|
+
background: transparent;
|
|
93
|
+
color: inherit;
|
|
94
|
+
font: inherit;
|
|
95
|
+
font-size: 0.875rem;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.rb-flashcards__button:hover,
|
|
100
|
+
.rb-flashcards__button:focus-visible {
|
|
101
|
+
border-color: var(--rb-flashcards-accent);
|
|
102
|
+
color: var(--rb-flashcards-accent);
|
|
103
|
+
outline: none;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.rb-flashcards--invalid {
|
|
107
|
+
padding: 0.75rem 1rem;
|
|
108
|
+
border: 1px solid var(--rb-flashcards-ink);
|
|
109
|
+
font-size: 0.875rem;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
html[data-theme="dark"] .rb-flashcards,
|
|
113
|
+
html.dark .rb-flashcards {
|
|
114
|
+
--rb-flashcards-ink: var(--rb-color-paper, #ffffff);
|
|
115
|
+
--rb-flashcards-paper: var(--rb-color-ink, #000000);
|
|
116
|
+
}
|