@riebeckite/plugin-sidenotes 0.0.5
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 +124 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +81 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +504 -0
- package/dist/src/client.d.ts +17 -0
- package/dist/src/options.d.ts +10 -0
- package/dist/src/rehype.d.ts +2 -0
- package/dist/src/render.d.ts +49 -0
- package/dist/src/types.d.ts +68 -0
- package/package.json +61 -0
- package/style.css +127 -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-sidenotes
|
|
2
|
+
|
|
3
|
+
Tufte-style side notes for Riebeckite. Authors keep writing ordinary GFM
|
|
4
|
+
footnotes (`[^1]` and `[^1]: text`); the plugin rewrites the generated
|
|
5
|
+
footnote markup into an inline reference plus a note that renders as a margin
|
|
6
|
+
note on desktop and as a tap-open popover on mobile.
|
|
7
|
+
|
|
8
|
+
[日本語](./README_ja.md)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
The plugin registers a rehype plugin that rewrites the footnote markup the
|
|
13
|
+
core pipeline produces from `remark-gfm`:
|
|
14
|
+
|
|
15
|
+
- Each footnote reference becomes a `sup` with a small reference link
|
|
16
|
+
(`[data-rr-sidenotes-ref]`) that keeps its `href="#fn-…"` target, so the
|
|
17
|
+
footnote stays reachable with plain browser navigation.
|
|
18
|
+
- Each footnote definition becomes a `.rr-sidenotes__note` aside next to the
|
|
19
|
+
reference: a static **margin note** on desktop (`@media (min-width: 48rem)`)
|
|
20
|
+
and a **popover** on mobile (`@media (max-width: 48rem)`).
|
|
21
|
+
- The trailing footnote definitions section is kept (it is the link target
|
|
22
|
+
on mobile and the no-JavaScript fallback) and hidden on desktop, where the
|
|
23
|
+
margin notes are always visible.
|
|
24
|
+
|
|
25
|
+
A small client entry (`initSidenotes`) toggles the mobile popover: tap to
|
|
26
|
+
open/close, `Escape` to close, and click outside to close. It ignores the page
|
|
27
|
+
when `(min-width: 48rem)` matches — desktop margin notes need no JavaScript.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { defineConfig } from "@riebeckite/core";
|
|
33
|
+
import { sidenotes } from "@riebeckite/plugin-sidenotes";
|
|
34
|
+
|
|
35
|
+
export default defineConfig({
|
|
36
|
+
// ...
|
|
37
|
+
plugins: [sidenotes()],
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Write normal GFM footnotes:
|
|
42
|
+
|
|
43
|
+
```md
|
|
44
|
+
Riebeckite renders margin notes at the side of the text.[^1]
|
|
45
|
+
|
|
46
|
+
[^1]: The note text appears beside the reference on desktop and in a popover on mobile.
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Options
|
|
50
|
+
|
|
51
|
+
| Option | Type | Default | Description |
|
|
52
|
+
| ------ | ---- | ------- | ----------- |
|
|
53
|
+
| `className` | `string` | `""` | Extra CSS class on each sidenote root |
|
|
54
|
+
| `ariaLabel` | `string` | `"Sidenote"` | Accessible name prefix for each note (`"Sidenote 1"`) |
|
|
55
|
+
| `openLabel` | `string` | `"Footnote"` | Accessible label prefix for a closed reference (`"Footnote 1"`) |
|
|
56
|
+
| `closeLabel` | `string` | `"Close sidenote"` | Accessible label prefix for an open reference (`"Close sidenote 1"`) |
|
|
57
|
+
| `popoverAlignment` | `"bottom" \| "end"` | `"bottom"` | Where the mobile popover is anchored |
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
sidenotes({
|
|
61
|
+
ariaLabel: "Note",
|
|
62
|
+
popoverAlignment: "end",
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Output
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<p>
|
|
70
|
+
Riebeckite renders margin notes here.<sup class="rr-sidenotes__ref">
|
|
71
|
+
<a href="#user-content-fn-1" id="user-content-fnref-1" class="rr-sidenotes__toggle"
|
|
72
|
+
data-rr-sidenotes-ref aria-expanded="false" aria-controls="rr-sidenotes-1"
|
|
73
|
+
aria-label="Footnote 1">1</a></sup>
|
|
74
|
+
</p>
|
|
75
|
+
<aside class="rr-sidenotes__note rr-sidenotes__note--popover-bottom" id="rr-sidenotes-1"
|
|
76
|
+
data-rr-sidenotes-note aria-label="Sidenote 1" tabindex="-1">
|
|
77
|
+
<span class="rr-sidenotes__index" aria-hidden="true">1</span>
|
|
78
|
+
<div class="rr-sidenotes__body"><p>The note text appears beside the reference.</p></div>
|
|
79
|
+
</aside>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- The reference is a real link (`href="#user-content-fn-…"`) with `aria-expanded`
|
|
85
|
+
and `aria-controls`; the client toggles `aria-expanded` and swaps the label
|
|
86
|
+
between `openLabel` and `closeLabel`.
|
|
87
|
+
- The popover is labelled with `aria-label` and receives focus (`tabindex="-1"`)
|
|
88
|
+
when opened via a script.
|
|
89
|
+
- Without JavaScript, tapping the reference jumps to the footnote definitions
|
|
90
|
+
as in ordinary GFM output.
|
|
91
|
+
|
|
92
|
+
## Style
|
|
93
|
+
|
|
94
|
+
The package ships `style.css`. Register it like any other plugin stylesheet:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import "@riebeckite/plugin-sidenotes/style.css";
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Stable hooks follow the `rr-sidenotes` convention: `rr-sidenotes__toggle`,
|
|
101
|
+
`rr-sidenotes__note`, `rr-sidenotes__index`, `rr-sidenotes__body`,
|
|
102
|
+
`rr-sidenotes__footnotes`, plus the `rr-sidenotes__note--open` modifier.
|
|
103
|
+
|
|
104
|
+
## Exports
|
|
105
|
+
|
|
106
|
+
- `sidenotes(options?)` — plugin factory
|
|
107
|
+
- `sidenotesPlugin` — alias of `sidenotes`
|
|
108
|
+
- `rehypeSidenotes(options?)` — the rehype transformer
|
|
109
|
+
- `resolveSidenotesOptions(options?)` — apply option defaults
|
|
110
|
+
- `renderSidenotesReference(input)` / `renderSidenotesNote(input)` — HTML builders
|
|
111
|
+
- `initSidenotes(options?)` — client popover initializer
|
|
112
|
+
- Types: `SidenotesOptions`, `ResolvedSidenotesOptions`, `SidenotesClientOptions`
|
|
113
|
+
|
|
114
|
+
## Limitations
|
|
115
|
+
|
|
116
|
+
- Footnotes that reuse the same definition share one margin note and popover.
|
|
117
|
+
- The footnote definitions section is hidden on desktop; margins must have
|
|
118
|
+
room for the notes, and themes can restyle `.rr-sidenotes__note` freely.
|
|
119
|
+
- Notes inside tables or deeply nested inline markup are placed after the
|
|
120
|
+
nearest block ancestor, so their vertical position is approximate.
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @riebeckite/plugin-sidenotes
|
|
2
|
+
|
|
3
|
+
Riebeckite 用の Tufte スタイルのサイドノート・プラグインです。執筆者は通常の
|
|
4
|
+
GFM 脚注(`[^1]` と `[^1]: 本文`)をそのまま書き続けます。プラグインが生成
|
|
5
|
+
された脚注マークアップを、インラインの参照リンクと、デスクトップではマージン
|
|
6
|
+
ノート、モバイルではタップで開くポップオーバーとして表示されるノートに書き
|
|
7
|
+
換えます。
|
|
8
|
+
|
|
9
|
+
[English](./README.md)
|
|
10
|
+
|
|
11
|
+
## 仕組み
|
|
12
|
+
|
|
13
|
+
このプラグインは、`remark-gfm` の出力をコアのパイプラインが脚注マークアップ
|
|
14
|
+
に変換したものを、rehype プラグインで書き換えます。
|
|
15
|
+
|
|
16
|
+
- 脚注参照は `[data-rr-sidenotes-ref]` を持つ小さな参照リンク付きの `sup`
|
|
17
|
+
になり、`href="#fn-…"` のリンク先は保持されます。通常のブラウザのリンク
|
|
18
|
+
遷移でも脚注に到達できます。
|
|
19
|
+
- 脚注定義は参照のそばの `.rr-sidenotes__note` の aside になります。
|
|
20
|
+
デスクトップ(`@media (min-width: 48rem)`)では常時表示の**マージンノート**、
|
|
21
|
+
モバイル(`@media (max-width: 48rem)`)では**ポップオーバー**として表示
|
|
22
|
+
されます。
|
|
23
|
+
- 文末の脚注定義セクションは残します(モバイルではリンク先、JavaScript が
|
|
24
|
+
無効な場合のフォールバックになります)。マージンノートが常に見える
|
|
25
|
+
デスクトップでは非表示にします。
|
|
26
|
+
|
|
27
|
+
クライアントエントリ(`initSidenotes`)がモバイルのポップオーバーを切り替え
|
|
28
|
+
ます。タップで開閉、`Escape` で閉じる、外側のクリックで閉じる、という動作です。
|
|
29
|
+
`(min-width: 48rem)` に一致するときは動作しません。デスクトップのマージン
|
|
30
|
+
ノートに JavaScript は不要です。
|
|
31
|
+
|
|
32
|
+
## 使い方
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { defineConfig } from "@riebeckite/core";
|
|
36
|
+
import { sidenotes } from "@riebeckite/plugin-sidenotes";
|
|
37
|
+
|
|
38
|
+
export default defineConfig({
|
|
39
|
+
// ...
|
|
40
|
+
plugins: [sidenotes()],
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
通常の GFM 脚注を書くだけです。
|
|
45
|
+
|
|
46
|
+
```md
|
|
47
|
+
Riebeckite は本文の横にマージンノートを表示します。[^1]
|
|
48
|
+
|
|
49
|
+
[^1]: デスクトップでは参照の横に、モバイルではポップオーバーでノートが表示されます。
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## オプション
|
|
53
|
+
|
|
54
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
55
|
+
| ---------- | -- | ------ | ---- |
|
|
56
|
+
| `className` | `string` | `""` | 各サイドノートのルートに追加する CSS クラス |
|
|
57
|
+
| `ariaLabel` | `string` | `"Sidenote"` | 各ノートのアクセシブル名の接頭辞(`"Sidenote 1"` の形) |
|
|
58
|
+
| `openLabel` | `string` | `"Footnote"` | 閉じた参照リンクのアクセシブル名の接頭辞(`"Footnote 1"`) |
|
|
59
|
+
| `closeLabel` | `string` | `"Close sidenote"` | 開いた参照リンクのアクセシブル名の接頭辞(`"Close sidenote 1"`) |
|
|
60
|
+
| `popoverAlignment` | `"bottom" \| "end"` | `"bottom"` | モバイルのポップオーバーの表示位置 |
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
sidenotes({
|
|
64
|
+
ariaLabel: "注記",
|
|
65
|
+
popoverAlignment: "end",
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 出力
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<p>
|
|
73
|
+
Riebeckite は本文の横にマージンノートを表示します。<sup class="rr-sidenotes__ref">
|
|
74
|
+
<a href="#user-content-fn-1" id="user-content-fnref-1" class="rr-sidenotes__toggle"
|
|
75
|
+
data-rr-sidenotes-ref aria-expanded="false" aria-controls="rr-sidenotes-1"
|
|
76
|
+
aria-label="Footnote 1">1</a></sup>
|
|
77
|
+
</p>
|
|
78
|
+
<aside class="rr-sidenotes__note rr-sidenotes__note--popover-bottom" id="rr-sidenotes-1"
|
|
79
|
+
data-rr-sidenotes-note aria-label="Sidenote 1" tabindex="-1">
|
|
80
|
+
<span class="rr-sidenotes__index" aria-hidden="true">1</span>
|
|
81
|
+
<div class="rr-sidenotes__body"><p>デスクトップでは参照の横に表示されます。</p></div>
|
|
82
|
+
</aside>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## アクセシビリティ
|
|
86
|
+
|
|
87
|
+
- 参照リンクは実際のリンク(`href="#user-content-fn-…"`)で、`aria-expanded`
|
|
88
|
+
と `aria-controls` を持ちます。クライアントは `aria-expanded` を切り替え、
|
|
89
|
+
`openLabel` と `closeLabel` の間でラベルを差し替えます。
|
|
90
|
+
- ポップオーバーは `aria-label` でラベル付けされ、開いたときは
|
|
91
|
+
`tabindex="-1"` によりフォーカスを受け取ります。
|
|
92
|
+
- JavaScript が無効でも、タップで通常の GFM と同じように脚注定義へジャンプ
|
|
93
|
+
します。
|
|
94
|
+
|
|
95
|
+
## スタイル
|
|
96
|
+
|
|
97
|
+
パッケージに `style.css` が含まれます。他のプラグインと同じように読み込みます。
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import "@riebeckite/plugin-sidenotes/style.css";
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
安定フックは `rr-sidenotes` 規約に従います。`rr-sidenotes__toggle`、
|
|
104
|
+
`rr-sidenotes__note`、`rr-sidenotes__index`、`rr-sidenotes__body`、
|
|
105
|
+
`rr-sidenotes__footnotes`、そして `rr-sidenotes__note--open` 修飾子です。
|
|
106
|
+
|
|
107
|
+
## エクスポート
|
|
108
|
+
|
|
109
|
+
- `sidenotes(options?)` — プラグインファクトリ
|
|
110
|
+
- `sidenotesPlugin` — `sidenotes` のエイリアス
|
|
111
|
+
- `rehypeSidenotes(options?)` — rehype トランスフォーマー
|
|
112
|
+
- `resolveSidenotesOptions(options?)` — オプションの既定値を適用する
|
|
113
|
+
- `renderSidenotesReference(input)` / `renderSidenotesNote(input)` — HTML 生成関数
|
|
114
|
+
- `initSidenotes(options?)` — クライアントのポップオーバー初期化関数
|
|
115
|
+
- 型: `SidenotesOptions`, `ResolvedSidenotesOptions`, `SidenotesClientOptions`
|
|
116
|
+
|
|
117
|
+
## 制約
|
|
118
|
+
|
|
119
|
+
- 同じ定義を再利用した脚注は、1 つのマージンノートとポップオーバーを共有
|
|
120
|
+
します。
|
|
121
|
+
- デスクトップでは脚注定義セクションを非表示にします。ノートを置くための
|
|
122
|
+
余白が必要です。テーマは `.rr-sidenotes__note` を自由に再スタイルできます。
|
|
123
|
+
- テーブル内や深く入れ子になったインライン要素の中の注は、最も近いブロック
|
|
124
|
+
要素の後ろに置かれるため、縦位置はおおよその位置になります。
|
package/dist/client.d.ts
ADDED
package/dist/client.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
var DEFAULT_SELECTOR = "[data-rr-sidenotes-ref]";
|
|
3
|
+
var NOTE_OPEN_CLASS = "rr-sidenotes__note--open";
|
|
4
|
+
var DESKTOP_QUERY = "(min-width: 48rem)";
|
|
5
|
+
var DEFAULT_OPEN_LABEL = "Footnote";
|
|
6
|
+
var DEFAULT_CLOSE_LABEL = "Close sidenote";
|
|
7
|
+
function initSidenotes(options = {}) {
|
|
8
|
+
const desktopQuery = window.matchMedia(DESKTOP_QUERY);
|
|
9
|
+
if (desktopQuery.matches) return;
|
|
10
|
+
const toggles = Array.from(
|
|
11
|
+
document.querySelectorAll(
|
|
12
|
+
options.selector ?? DEFAULT_SELECTOR
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
if (toggles.length === 0) return;
|
|
16
|
+
const openLabel = options.openLabel ?? DEFAULT_OPEN_LABEL;
|
|
17
|
+
const closeLabel = options.closeLabel ?? DEFAULT_CLOSE_LABEL;
|
|
18
|
+
const noteFor = (toggle) => {
|
|
19
|
+
const controls = toggle.getAttribute("aria-controls");
|
|
20
|
+
if (!controls) return null;
|
|
21
|
+
const note = document.getElementById(controls);
|
|
22
|
+
return note instanceof HTMLElement ? note : null;
|
|
23
|
+
};
|
|
24
|
+
const isInsideSidenotes = (target) => {
|
|
25
|
+
if (!target) return false;
|
|
26
|
+
for (const toggle of toggles) {
|
|
27
|
+
const note = noteFor(toggle);
|
|
28
|
+
if (toggle.contains(target) || note?.contains(target)) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
const setOpen = (toggle, note, open) => {
|
|
33
|
+
const index = toggle.textContent?.trim() ?? "";
|
|
34
|
+
const label = open ? `${closeLabel} ${index}`.trim() : `${openLabel} ${index}`.trim();
|
|
35
|
+
toggle.setAttribute("aria-expanded", String(open));
|
|
36
|
+
toggle.setAttribute("aria-label", label);
|
|
37
|
+
note.classList.toggle(NOTE_OPEN_CLASS, open);
|
|
38
|
+
if (open) note.focus({ preventScroll: true });
|
|
39
|
+
};
|
|
40
|
+
const closeAll = () => {
|
|
41
|
+
for (const toggle of toggles) {
|
|
42
|
+
const note = noteFor(toggle);
|
|
43
|
+
if (note?.classList.contains(NOTE_OPEN_CLASS)) {
|
|
44
|
+
setOpen(toggle, note, false);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
for (const toggle of toggles) {
|
|
49
|
+
toggle.addEventListener("click", (event) => {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
const note = noteFor(toggle);
|
|
52
|
+
if (!note) return;
|
|
53
|
+
const isOpen = note.classList.contains(NOTE_OPEN_CLASS);
|
|
54
|
+
if (!isOpen) closeAll();
|
|
55
|
+
setOpen(toggle, note, !isOpen);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const onKeydown = (event) => {
|
|
59
|
+
if (event.key !== "Escape") return;
|
|
60
|
+
closeAll();
|
|
61
|
+
};
|
|
62
|
+
const onClickOutside = (event) => {
|
|
63
|
+
if (isInsideSidenotes(event.target instanceof Node ? event.target : null)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
closeAll();
|
|
67
|
+
};
|
|
68
|
+
document.addEventListener("keydown", onKeydown);
|
|
69
|
+
document.addEventListener("click", onClickOutside);
|
|
70
|
+
const onViewportChange = (event) => {
|
|
71
|
+
if (!event.matches) return;
|
|
72
|
+
closeAll();
|
|
73
|
+
document.removeEventListener("keydown", onKeydown);
|
|
74
|
+
document.removeEventListener("click", onClickOutside);
|
|
75
|
+
desktopQuery.removeEventListener("change", onViewportChange);
|
|
76
|
+
};
|
|
77
|
+
desktopQuery.addEventListener("change", onViewportChange);
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
initSidenotes
|
|
81
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SidenotesOptions } from "./src/types.js";
|
|
2
|
+
export type { SidenotesClientOptions } from "./src/client.js";
|
|
3
|
+
export { initSidenotes } from "./src/client.js";
|
|
4
|
+
export { resolveSidenotesOptions } from "./src/options.js";
|
|
5
|
+
export { rehypeSidenotes } from "./src/rehype.js";
|
|
6
|
+
export { renderHastChildren, renderSidenotesNote, renderSidenotesReference, sidenotesKey, sidenotesNoteId, } from "./src/render.js";
|
|
7
|
+
export type { ResolvedSidenotesOptions, SidenotesOptions, } from "./src/types.js";
|
|
8
|
+
export declare const SIDENOTES_PLUGIN_NAME = "sidenotes";
|
|
9
|
+
/**
|
|
10
|
+
* Tufte-style side notes. Authors keep writing GFM footnotes (`[^1]` /
|
|
11
|
+
* `[^1]: text`); a rehype plugin rewrites the generated footnote markup into
|
|
12
|
+
* an inline reference plus a note that renders as a margin note on desktop
|
|
13
|
+
* and as a tap-open popover on mobile.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sidenotes(options?: SidenotesOptions): import("@riebeckite/core").RiebeckitePlugin<SidenotesOptions>;
|
|
16
|
+
/** Alias matching the `*Plugin` suffix used by other plugin factories. */
|
|
17
|
+
export declare const sidenotesPlugin: typeof sidenotes;
|