@riebeckite/plugin-wavedrom 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 +124 -0
- package/README_ja.md +124 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.js +74 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +244 -0
- package/dist/src/hast.d.ts +8 -0
- package/dist/src/rehype.d.ts +7 -0
- package/dist/src/types.d.ts +37 -0
- package/package.json +62 -0
- package/style.css +67 -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,124 @@
|
|
|
1
|
+
# @riebeckite/plugin-wavedrom
|
|
2
|
+
|
|
3
|
+
Renders ` ```wavedrom ` code blocks as [WaveDrom](https://wavedrom.com/) timing diagrams.
|
|
4
|
+
|
|
5
|
+
[日本語](./README_ja.md)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
`wavedrom()` replaces ` ```wavedrom ` (and ` ```wavejson `) code blocks with a `<figure>` that carries the normalized WaveJSON in a `data-wavedrom-spec` attribute. The diagram itself is drawn in the browser by `initWaveDrom`, which dynamically imports `wavedrom`. The build only emits markup. Execution order is `order: -10`.
|
|
10
|
+
|
|
11
|
+
## Configuration
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from "@riebeckite/core";
|
|
15
|
+
import { wavedrom } from "@riebeckite/plugin-wavedrom";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
// ...
|
|
19
|
+
plugins: [
|
|
20
|
+
wavedrom({
|
|
21
|
+
skin: "default",
|
|
22
|
+
caption: true,
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Writing a diagram
|
|
29
|
+
|
|
30
|
+
The block body is a **strict JSON** WaveJSON object. Keys must be double-quoted, and trailing commas or comments are not allowed.
|
|
31
|
+
|
|
32
|
+
````markdown
|
|
33
|
+
```wavedrom
|
|
34
|
+
{
|
|
35
|
+
"signal": [
|
|
36
|
+
{ "name": "clk", "wave": "p......" },
|
|
37
|
+
{ "name": "bus", "wave": "x.34.5x", "data": "head body tail" },
|
|
38
|
+
{ "name": "wire", "wave": "0.1..0." }
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
````
|
|
43
|
+
|
|
44
|
+
Top-level keys other than `signal`, `assign`, and `reg` — such as WaveDrom's `head`, `config`, and `foot` — are passed through unchanged.
|
|
45
|
+
|
|
46
|
+
```wavedrom
|
|
47
|
+
{
|
|
48
|
+
"head": { "text": "handshake" },
|
|
49
|
+
"signal": [
|
|
50
|
+
{ "name": "req", "wave": "01..0" },
|
|
51
|
+
{ "name": "ack", "wave": "0.1.0" }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Captions
|
|
57
|
+
|
|
58
|
+
A caption is taken from the code block's `title`.
|
|
59
|
+
|
|
60
|
+
````markdown
|
|
61
|
+
```wavedrom title="Read cycle"
|
|
62
|
+
{ "signal": [{ "name": "clk", "wave": "p..." }] }
|
|
63
|
+
```
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
You can also use a top-level `"caption"` key in the JSON. It is removed before the diagram is rendered, so it never reaches WaveDrom.
|
|
67
|
+
|
|
68
|
+
````markdown
|
|
69
|
+
```wavedrom
|
|
70
|
+
{
|
|
71
|
+
"caption": "Read cycle",
|
|
72
|
+
"signal": [{ "name": "clk", "wave": "p..." }]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
````
|
|
76
|
+
|
|
77
|
+
## Output
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<figure class="rb-wavedrom" data-wavedrom="pending" data-wavedrom-spec="{"signal":[...]}" data-wavedrom-skin="default">
|
|
81
|
+
<figcaption id="rb-wavedrom-xxxx-caption" class="rb-wavedrom__caption">Read cycle</figcaption>
|
|
82
|
+
<div class="rb-wavedrom__canvas" data-wavedrom-canvas="true" role="img" aria-labelledby="rb-wavedrom-xxxx-caption"></div>
|
|
83
|
+
<details class="rb-wavedrom__fallback">
|
|
84
|
+
<summary>WaveJSON source</summary>
|
|
85
|
+
<pre><code>{ ... }</code></pre>
|
|
86
|
+
</details>
|
|
87
|
+
</figure>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `.rb-wavedrom` — the figure wrapper; inherits `--rb-color-*` for theming
|
|
91
|
+
- `.rb-wavedrom__canvas` — where WaveDrom draws the SVG; marked with `data-wavedrom-canvas="true"`
|
|
92
|
+
- `.rb-wavedrom__caption` — the `<figcaption>` when a caption is present
|
|
93
|
+
- `.rb-wavedrom__fallback` — a `<details>` holding the WaveJSON source
|
|
94
|
+
|
|
95
|
+
The `data-wavedrom` attribute reports render state: `pending` initially, `rendered` on success, and `error` on failure. On failure the fallback `<details>` is opened.
|
|
96
|
+
|
|
97
|
+
## Options
|
|
98
|
+
|
|
99
|
+
| Name | Type | Default | Description |
|
|
100
|
+
| --- | --- | --- | --- |
|
|
101
|
+
| `skin` | `"default" \| "narrow" \| "lowkey"` | `"default"` | WaveDrom skin used by the browser renderer |
|
|
102
|
+
| `caption` | `boolean` | `true` | Render the extracted caption as a `<figcaption>` |
|
|
103
|
+
| `fallback` | `boolean` | `true` | Render the WaveJSON source in a `<details>` block |
|
|
104
|
+
| `className` | `string` | `"rb-wavedrom"` | Base class applied to the figure |
|
|
105
|
+
|
|
106
|
+
## Diagnostics
|
|
107
|
+
|
|
108
|
+
If the body is not valid JSON, is not an object, or has no `signal` / `assign` / `reg`, the original code block is left in place and a diagnostic is emitted with `source: "@riebeckite/plugin-wavedrom"` and `ruleId: "invalid-config"`.
|
|
109
|
+
|
|
110
|
+
## Client rendering
|
|
111
|
+
|
|
112
|
+
`wavedrom` is not bundled at build time. The site's client bundle must call `initWaveDrom`, which `wavedrom()` wires up via `createClientEntry`. The initializer finds `figure[data-wavedrom="pending"]`, `JSON.parse`s each `data-wavedrom-spec`, dynamically imports `wavedrom`, and draws the SVG into `<div class="rb-wavedrom__canvas">` with `WaveDrom.RenderWaveForm`. When `data-wavedrom-skin` is present, the matching skin is loaded. A broken payload or a rendering error only marks that figure as `data-wavedrom="error"` and opens its fallback.
|
|
113
|
+
|
|
114
|
+
## Limitations
|
|
115
|
+
|
|
116
|
+
- Rendering is client-only. Without JavaScript the SVG is never produced and only the WaveJSON source remains
|
|
117
|
+
- The E2E build checks the emitted markup only; actual rendering requires a browser
|
|
118
|
+
- The body must be strict JSON. The JSON5 form accepted by the WaveDrom editor (unquoted keys, single quotes, comments) is not supported
|
|
119
|
+
- The WaveJSON is embedded directly in an HTML attribute, so keep diagrams reasonably small
|
|
120
|
+
- Only the `wavedrom` and `wavejson` info strings are recognized; other languages are unaffected
|
|
121
|
+
|
|
122
|
+
## See also
|
|
123
|
+
|
|
124
|
+
- [Plugin system](../../../docs/en/plugin-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @riebeckite/plugin-wavedrom
|
|
2
|
+
|
|
3
|
+
` ```wavedrom ` コードブロックを [WaveDrom](https://wavedrom.com/) のタイミング図として表示するプラグインです。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 概要
|
|
8
|
+
|
|
9
|
+
`wavedrom()` は ` ```wavedrom `(および ` ```wavejson `)のコードブロックを `<figure>` に置き換え、正規化した WaveJSON を `data-wavedrom-spec` 属性に埋め込みます。図そのものはブラウザ側の `initWaveDrom` が `wavedrom` を動的 import して描画します。ビルドはマークアップだけを出力します。実行順は `order: -10` です。
|
|
10
|
+
|
|
11
|
+
## 設定する
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from "@riebeckite/core";
|
|
15
|
+
import { wavedrom } from "@riebeckite/plugin-wavedrom";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
// ...
|
|
19
|
+
plugins: [
|
|
20
|
+
wavedrom({
|
|
21
|
+
skin: "default",
|
|
22
|
+
caption: true,
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## タイミング図を書く
|
|
29
|
+
|
|
30
|
+
本文は **厳密な JSON** の WaveJSON オブジェクトです。キーは必ず二重引用符で囲み、末尾のカンマやコメントは書けません。
|
|
31
|
+
|
|
32
|
+
````markdown
|
|
33
|
+
```wavedrom
|
|
34
|
+
{
|
|
35
|
+
"signal": [
|
|
36
|
+
{ "name": "clk", "wave": "p......" },
|
|
37
|
+
{ "name": "bus", "wave": "x.34.5x", "data": "head body tail" },
|
|
38
|
+
{ "name": "wire", "wave": "0.1..0." }
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
````
|
|
43
|
+
|
|
44
|
+
WaveDrom の `head` / `config` / `foot` など、`signal`・`assign`・`reg` 以外のトップレベルキーもそのまま引き継がれます。
|
|
45
|
+
|
|
46
|
+
```wavedrom
|
|
47
|
+
{
|
|
48
|
+
"head": { "text": "handshake" },
|
|
49
|
+
"signal": [
|
|
50
|
+
{ "name": "req", "wave": "01..0" },
|
|
51
|
+
{ "name": "ack", "wave": "0.1.0" }
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### キャプション
|
|
57
|
+
|
|
58
|
+
キャプションはコードブロックの `title` から取得します。
|
|
59
|
+
|
|
60
|
+
````markdown
|
|
61
|
+
```wavedrom title="読み出しサイクル"
|
|
62
|
+
{ "signal": [{ "name": "clk", "wave": "p..." }] }
|
|
63
|
+
```
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
JSON のトップレベル `"caption"` キーでも指定できます。このキーは図を描画する前に取り除かれるため、WaveDrom には渡りません。
|
|
67
|
+
|
|
68
|
+
````markdown
|
|
69
|
+
```wavedrom
|
|
70
|
+
{
|
|
71
|
+
"caption": "読み出しサイクル",
|
|
72
|
+
"signal": [{ "name": "clk", "wave": "p..." }]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
````
|
|
76
|
+
|
|
77
|
+
## 出力
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<figure class="rb-wavedrom" data-wavedrom="pending" data-wavedrom-spec="{"signal":[...]}" data-wavedrom-skin="default">
|
|
81
|
+
<figcaption id="rb-wavedrom-xxxx-caption" class="rb-wavedrom__caption">読み出しサイクル</figcaption>
|
|
82
|
+
<div class="rb-wavedrom__canvas" data-wavedrom-canvas="true" role="img" aria-labelledby="rb-wavedrom-xxxx-caption"></div>
|
|
83
|
+
<details class="rb-wavedrom__fallback">
|
|
84
|
+
<summary>WaveJSON source</summary>
|
|
85
|
+
<pre><code>{ ... }</code></pre>
|
|
86
|
+
</details>
|
|
87
|
+
</figure>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- `.rb-wavedrom` — 図全体のラッパー。`--rb-color-*` で配色を引き継ぎます
|
|
91
|
+
- `.rb-wavedrom__canvas` — WaveDrom が SVG を描画する領域。`data-wavedrom-canvas="true"`
|
|
92
|
+
- `.rb-wavedrom__caption` — キャプションがある場合の `<figcaption>`
|
|
93
|
+
- `.rb-wavedrom__fallback` — WaveJSON のソースを表示する `<details>`
|
|
94
|
+
|
|
95
|
+
`data-wavedrom` 属性は描画状態を表します。初期値は `pending`、成功時は `rendered`、失敗時は `error` になります。失敗時はフォールバックの `<details>` が開きます。
|
|
96
|
+
|
|
97
|
+
## オプション
|
|
98
|
+
|
|
99
|
+
| 項目 | 型 | 既定値 | 説明 |
|
|
100
|
+
| --- | --- | --- | --- |
|
|
101
|
+
| `skin` | `"default" \| "narrow" \| "lowkey"` | `"default"` | ブラウザ側で使う WaveDrom スキン |
|
|
102
|
+
| `caption` | `boolean` | `true` | キャプションを `<figcaption>` として表示する |
|
|
103
|
+
| `fallback` | `boolean` | `true` | WaveJSON ソースを `<details>` に表示する |
|
|
104
|
+
| `className` | `string` | `"rb-wavedrom"` | figure に付ける基底クラス |
|
|
105
|
+
|
|
106
|
+
## 診断
|
|
107
|
+
|
|
108
|
+
本文が JSON として不正、オブジェクトでない、`signal` / `assign` / `reg` がない場合は、元のコードブロックをそのまま残し、`source: "@riebeckite/plugin-wavedrom"`、`ruleId: "invalid-config"` の診断を出します。
|
|
109
|
+
|
|
110
|
+
## クライアント側の描画
|
|
111
|
+
|
|
112
|
+
`wavedrom` はビルド時にはバンドルされません。サイトのクライアントバンドルが `initWaveDrom` を呼ぶ必要があり、`wavedrom()` が `createClientEntry` で結線します。`initWaveDrom` は `figure[data-wavedrom="pending"]` を探し、各 `data-wavedrom-spec` を `JSON.parse` して `wavedrom` を動的 import し、`WaveDrom.RenderWaveForm` で `<div class="rb-wavedrom__canvas">` に SVG を描画します。`data-wavedrom-skin` があれば対応するスキンを読み込みます。パース失敗や描画例外はその figure だけを `data-wavedrom="error"` にし、フォールバックを開きます。
|
|
113
|
+
|
|
114
|
+
## 制限
|
|
115
|
+
|
|
116
|
+
- 描画はクライアント専用です。JavaScript が無効な環境では SVG は生成されず、WaveJSON ソースだけが残ります
|
|
117
|
+
- E2E のビルドは出力マークアップだけを検査します。実際の描画にはブラウザが必要です
|
|
118
|
+
- 本文は厳密な JSON である必要があります。WaveDrom エディタが受け付ける JSON5 形式(引用符なしキー、シングルクォート、コメント)は受理しません
|
|
119
|
+
- WaveJSON は HTML 属性に直接埋め込まれるため、巨大な図は避けてください
|
|
120
|
+
- 認識するのは `wavedrom` と `wavejson` という info string だけです。他の言語には影響しません
|
|
121
|
+
|
|
122
|
+
## 関連資料
|
|
123
|
+
|
|
124
|
+
- [プラグインシステム](../../../docs/ja/plugin-system.md)
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draws every server-rendered WaveDrom figure with the `wavedrom` package.
|
|
3
|
+
*
|
|
4
|
+
* The `wavedrom` library is imported lazily so sites that never render a
|
|
5
|
+
* timing diagram do not ship it. Figures carry their normalized WaveJSON in
|
|
6
|
+
* `data-wavedrom-spec`; the requested skin (a build-time option) travels in
|
|
7
|
+
* `data-wavedrom-skin` because client entry code cannot see plugin options.
|
|
8
|
+
*/
|
|
9
|
+
export declare function initWaveDrom(): Promise<void>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// client.ts
|
|
2
|
+
var PENDING_SELECTOR = '[data-wavedrom="pending"]';
|
|
3
|
+
var CANVAS_ATTRIBUTE = "data-wavedrom-canvas";
|
|
4
|
+
var CANVAS_ID_PREFIX = "rb-wavedrom-canvas-";
|
|
5
|
+
var SKINS = ["default", "narrow", "lowkey"];
|
|
6
|
+
var renderCounter = 0;
|
|
7
|
+
async function initWaveDrom() {
|
|
8
|
+
const figures = Array.from(
|
|
9
|
+
document.querySelectorAll(PENDING_SELECTOR)
|
|
10
|
+
);
|
|
11
|
+
if (figures.length === 0) return;
|
|
12
|
+
let api;
|
|
13
|
+
try {
|
|
14
|
+
api = await loadWavedrom();
|
|
15
|
+
} catch {
|
|
16
|
+
revealFallbacks(figures);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let notFirstSignal = false;
|
|
20
|
+
for (const figure of figures) {
|
|
21
|
+
const canvas = figure.querySelector(`[${CANVAS_ATTRIBUTE}]`);
|
|
22
|
+
const serialized = figure.dataset.wavedromSpec;
|
|
23
|
+
if (!canvas || !serialized) {
|
|
24
|
+
setError(figure);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
let spec;
|
|
28
|
+
try {
|
|
29
|
+
spec = JSON.parse(serialized);
|
|
30
|
+
} catch {
|
|
31
|
+
setError(figure);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const skin = await loadSkin(figure.dataset.wavedromSkin, api);
|
|
36
|
+
renderFigure(api, spec, canvas, skin, notFirstSignal);
|
|
37
|
+
figure.dataset.wavedrom = "rendered";
|
|
38
|
+
if (spec.signal) notFirstSignal = true;
|
|
39
|
+
} catch {
|
|
40
|
+
setError(figure);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function renderFigure(api, spec, canvas, skin, notFirstSignal) {
|
|
45
|
+
const index = renderCounter++;
|
|
46
|
+
canvas.id = `${CANVAS_ID_PREFIX}${index}`;
|
|
47
|
+
window.WaveSkin = skin ?? api.waveSkin;
|
|
48
|
+
api.renderWaveForm(index, spec, CANVAS_ID_PREFIX, notFirstSignal);
|
|
49
|
+
}
|
|
50
|
+
async function loadWavedrom() {
|
|
51
|
+
const mod = await import("wavedrom");
|
|
52
|
+
return mod.default ?? mod;
|
|
53
|
+
}
|
|
54
|
+
async function loadSkin(name, api) {
|
|
55
|
+
const skin = name ?? "default";
|
|
56
|
+
if (!SKINS.includes(skin) || skin === "default") return api.waveSkin;
|
|
57
|
+
try {
|
|
58
|
+
const mod = await (skin === "narrow" ? import("wavedrom/skins/narrow") : import("wavedrom/skins/lowkey"));
|
|
59
|
+
return mod[skin] ?? mod.default?.[skin] ?? api.waveSkin;
|
|
60
|
+
} catch {
|
|
61
|
+
return api.waveSkin;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function revealFallbacks(figures) {
|
|
65
|
+
for (const figure of figures) setError(figure);
|
|
66
|
+
}
|
|
67
|
+
function setError(figure) {
|
|
68
|
+
figure.dataset.wavedrom = "error";
|
|
69
|
+
const details = figure.querySelector("details");
|
|
70
|
+
if (details) details.open = true;
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
initWaveDrom
|
|
74
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WavedromOptions } from "./src/types.js";
|
|
2
|
+
export { rehypeWavedrom } from "./src/rehype.js";
|
|
3
|
+
export type { WavedromOptions, WavedromSkin } from "./src/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders fenced `wavedrom` (and `wavejson`) code blocks as WaveDrom timing
|
|
6
|
+
* diagrams. The block body is a strict JSON WaveJSON object; the diagram is
|
|
7
|
+
* drawn in the browser by `initWaveDrom`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function wavedrom(options?: WavedromOptions): import("@riebeckite/core").RiebeckitePlugin<WavedromOptions>;
|
|
10
|
+
/** Alias kept for symmetry with the other plugin factories. */
|
|
11
|
+
export declare const wavedromPlugin: typeof wavedrom;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createClientEntry,
|
|
4
|
+
createStyleAsset,
|
|
5
|
+
definePlugin
|
|
6
|
+
} from "@riebeckite/core";
|
|
7
|
+
|
|
8
|
+
// src/hast.ts
|
|
9
|
+
function visitElements(node, visitor, parent, index) {
|
|
10
|
+
if (isElementNode(node)) visitor(node, parent, index);
|
|
11
|
+
for (const [childIndex, child] of [...getChildren(node)].entries()) {
|
|
12
|
+
visitElements(
|
|
13
|
+
child,
|
|
14
|
+
visitor,
|
|
15
|
+
hasChildren(node) ? node : parent,
|
|
16
|
+
childIndex
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function element(tagName, properties = {}, children = []) {
|
|
21
|
+
return { type: "element", tagName, properties, children };
|
|
22
|
+
}
|
|
23
|
+
function text(value) {
|
|
24
|
+
return { type: "text", value };
|
|
25
|
+
}
|
|
26
|
+
function getTextContent(node) {
|
|
27
|
+
if (node.type === "text" && "value" in node && typeof node.value === "string") {
|
|
28
|
+
return node.value;
|
|
29
|
+
}
|
|
30
|
+
return getChildren(node).map(getTextContent).join("");
|
|
31
|
+
}
|
|
32
|
+
function getStringProperty(node, key) {
|
|
33
|
+
const value = node.properties?.[key];
|
|
34
|
+
if (typeof value === "string") return value;
|
|
35
|
+
if (Array.isArray(value)) return value.join(" ");
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
function hasClass(node, className) {
|
|
39
|
+
const value = node.properties?.className;
|
|
40
|
+
const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
|
|
41
|
+
return classes.includes(className);
|
|
42
|
+
}
|
|
43
|
+
function isElementNode(node) {
|
|
44
|
+
return node.type === "element";
|
|
45
|
+
}
|
|
46
|
+
function hasChildren(node) {
|
|
47
|
+
return Array.isArray(node.children);
|
|
48
|
+
}
|
|
49
|
+
function getChildren(node) {
|
|
50
|
+
const children = node.children;
|
|
51
|
+
return Array.isArray(children) ? children : [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/rehype.ts
|
|
55
|
+
var DEFAULT_CLASS_NAME = "rb-wavedrom";
|
|
56
|
+
var DEFAULT_SKIN = "default";
|
|
57
|
+
var WAVEDROM_LANGUAGE_CLASSES = ["language-wavedrom", "language-wavejson"];
|
|
58
|
+
function rehypeWavedrom(options = {}) {
|
|
59
|
+
const className = options.className?.trim() || DEFAULT_CLASS_NAME;
|
|
60
|
+
const skin = options.skin ?? DEFAULT_SKIN;
|
|
61
|
+
const caption = options.caption !== false;
|
|
62
|
+
const fallback = options.fallback !== false;
|
|
63
|
+
return (tree, file) => {
|
|
64
|
+
visitElements(tree, (node, parent, index) => {
|
|
65
|
+
if (!parent || index === void 0 || !isWavedromCodeBlock(node)) return;
|
|
66
|
+
replaceWavedromBlock(parent, index, node, file, {
|
|
67
|
+
className,
|
|
68
|
+
skin,
|
|
69
|
+
caption,
|
|
70
|
+
fallback
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function replaceWavedromBlock(parent, index, pre, file, options) {
|
|
76
|
+
const code = findDirectChild(pre, "code");
|
|
77
|
+
const source = code ? getTextContent(code).trim() : getTextContent(pre).trim();
|
|
78
|
+
const parsed = parseSpec(source);
|
|
79
|
+
if (isParseFailure(parsed)) {
|
|
80
|
+
reportDiagnostic(file, parsed.message);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const captionText = options.caption ? extractCaption(pre, code, parsed.caption) ?? null : null;
|
|
84
|
+
parent.children = parent.children ?? [];
|
|
85
|
+
parent.children[index] = buildFigure({
|
|
86
|
+
className: options.className,
|
|
87
|
+
skin: options.skin,
|
|
88
|
+
source,
|
|
89
|
+
spec: parsed.spec,
|
|
90
|
+
caption: captionText,
|
|
91
|
+
fallback: options.fallback
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function buildFigure(input) {
|
|
95
|
+
const base = input.className;
|
|
96
|
+
const labelId = `${base}-${hashSource(input.source)}-caption`;
|
|
97
|
+
const serialized = JSON.stringify(input.spec);
|
|
98
|
+
const children = [];
|
|
99
|
+
if (input.caption) {
|
|
100
|
+
children.push(
|
|
101
|
+
element("figcaption", { id: labelId, className: `${base}__caption` }, [
|
|
102
|
+
text(input.caption)
|
|
103
|
+
])
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
children.push(
|
|
107
|
+
element(
|
|
108
|
+
"div",
|
|
109
|
+
{
|
|
110
|
+
className: `${base}__canvas`,
|
|
111
|
+
dataWavedromCanvas: "true",
|
|
112
|
+
role: "img",
|
|
113
|
+
ariaLabelledby: input.caption ? labelId : void 0,
|
|
114
|
+
ariaLabel: input.caption ? void 0 : "WaveDrom timing diagram"
|
|
115
|
+
},
|
|
116
|
+
[]
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
if (input.fallback) {
|
|
120
|
+
children.push(
|
|
121
|
+
element("details", { className: `${base}__fallback` }, [
|
|
122
|
+
element("summary", {}, [text("WaveJSON source")]),
|
|
123
|
+
element("pre", {}, [element("code", {}, [text(input.source)])])
|
|
124
|
+
])
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return element(
|
|
128
|
+
"figure",
|
|
129
|
+
{
|
|
130
|
+
className: base,
|
|
131
|
+
dataWavedrom: "pending",
|
|
132
|
+
dataWavedromSpec: serialized,
|
|
133
|
+
dataWavedromSkin: input.skin
|
|
134
|
+
},
|
|
135
|
+
children
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
function isParseFailure(result) {
|
|
139
|
+
return result.ok === false;
|
|
140
|
+
}
|
|
141
|
+
function parseSpec(source) {
|
|
142
|
+
let parsed;
|
|
143
|
+
try {
|
|
144
|
+
parsed = JSON.parse(source);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return { ok: false, message: `Invalid JSON: ${formatError(error)}` };
|
|
147
|
+
}
|
|
148
|
+
if (!isRecord(parsed)) {
|
|
149
|
+
return { ok: false, message: "Expected a JSON object." };
|
|
150
|
+
}
|
|
151
|
+
const { caption, ...spec } = parsed;
|
|
152
|
+
if (!hasWaveDromBody(spec)) {
|
|
153
|
+
return {
|
|
154
|
+
ok: false,
|
|
155
|
+
message: 'Expected a WaveJSON object with a "signal", "assign", or "reg" property.'
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const captionText = typeof caption === "string" && caption.trim() !== "" ? caption.trim() : null;
|
|
159
|
+
return { ok: true, spec, caption: captionText };
|
|
160
|
+
}
|
|
161
|
+
function hasWaveDromBody(spec) {
|
|
162
|
+
return Array.isArray(spec.signal) || Array.isArray(spec.assign) || "reg" in spec;
|
|
163
|
+
}
|
|
164
|
+
function extractCaption(pre, code, fromSpec) {
|
|
165
|
+
const title = getStringProperty(pre, "title") ?? (code ? getStringProperty(code, "title") : null);
|
|
166
|
+
const value = title ?? fromSpec;
|
|
167
|
+
return value?.trim() || void 0;
|
|
168
|
+
}
|
|
169
|
+
function isWavedromCodeBlock(node) {
|
|
170
|
+
if (node.tagName !== "pre") return false;
|
|
171
|
+
const code = findDirectChild(node, "code");
|
|
172
|
+
return Boolean(
|
|
173
|
+
code && WAVEDROM_LANGUAGE_CLASSES.some((className) => hasClass(code, className))
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
function findDirectChild(node, tagName) {
|
|
177
|
+
return node.children?.find(
|
|
178
|
+
(child) => child.type === "element" && child.tagName === tagName
|
|
179
|
+
) ?? null;
|
|
180
|
+
}
|
|
181
|
+
function reportDiagnostic(file, message) {
|
|
182
|
+
const reporter = file?.message;
|
|
183
|
+
if (typeof reporter !== "function") return;
|
|
184
|
+
const diagnostic = reporter.call(file, `Invalid WaveDrom config: ${message}`);
|
|
185
|
+
if (diagnostic && typeof diagnostic === "object") {
|
|
186
|
+
Object.assign(diagnostic, {
|
|
187
|
+
source: "@riebeckite/plugin-wavedrom",
|
|
188
|
+
ruleId: "invalid-config"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function isRecord(value) {
|
|
193
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
194
|
+
}
|
|
195
|
+
function hashSource(source) {
|
|
196
|
+
let hash = 0;
|
|
197
|
+
for (const char of source) hash = hash * 31 + char.charCodeAt(0) | 0;
|
|
198
|
+
return Math.abs(hash).toString(36);
|
|
199
|
+
}
|
|
200
|
+
function formatError(error) {
|
|
201
|
+
return error instanceof Error ? error.message : String(error);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// index.ts
|
|
205
|
+
var SKINS = ["default", "narrow", "lowkey"];
|
|
206
|
+
function wavedrom(options = {}) {
|
|
207
|
+
return definePlugin({
|
|
208
|
+
name: "wavedrom",
|
|
209
|
+
order: -10,
|
|
210
|
+
options,
|
|
211
|
+
validateOptions: validateWavedromOptions,
|
|
212
|
+
extendHtmlPipeline: (pipeline) => {
|
|
213
|
+
pipeline.use(rehypeWavedrom, options);
|
|
214
|
+
},
|
|
215
|
+
assets: [createStyleAsset("wavedrom")],
|
|
216
|
+
clientEntries: [createClientEntry("wavedrom", "initWaveDrom")]
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
var wavedromPlugin = wavedrom;
|
|
220
|
+
function validateWavedromOptions(options) {
|
|
221
|
+
if (!options) return [];
|
|
222
|
+
const issues = [];
|
|
223
|
+
if (options.skin !== void 0 && !SKINS.includes(options.skin)) {
|
|
224
|
+
issues.push({
|
|
225
|
+
path: "skin",
|
|
226
|
+
message: 'Expected "default", "narrow", or "lowkey".'
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (options.caption !== void 0 && typeof options.caption !== "boolean") {
|
|
230
|
+
issues.push({ path: "caption", message: "Expected a boolean." });
|
|
231
|
+
}
|
|
232
|
+
if (options.fallback !== void 0 && typeof options.fallback !== "boolean") {
|
|
233
|
+
issues.push({ path: "fallback", message: "Expected a boolean." });
|
|
234
|
+
}
|
|
235
|
+
if (options.className !== void 0 && (typeof options.className !== "string" || options.className.trim() === "")) {
|
|
236
|
+
issues.push({ path: "className", message: "Expected a non-empty string." });
|
|
237
|
+
}
|
|
238
|
+
return issues;
|
|
239
|
+
}
|
|
240
|
+
export {
|
|
241
|
+
rehypeWavedrom,
|
|
242
|
+
wavedrom,
|
|
243
|
+
wavedromPlugin
|
|
244
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ElementNode, HastNode, ParentNode, TextNode } from "./types.js";
|
|
2
|
+
export declare function visitElements(node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number): 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 getTextContent(node: HastNode): string;
|
|
6
|
+
export declare function getStringProperty(node: ElementNode, key: string): string | null;
|
|
7
|
+
export declare function hasClass(node: ElementNode, className: string): boolean;
|
|
8
|
+
export declare function mergeClassName(current: unknown, next: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HastNode, WavedromOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Replaces every `wavedrom` (or `wavejson`) fenced code block with a figure
|
|
4
|
+
* that carries the normalized WaveJSON in a data attribute. The diagram itself
|
|
5
|
+
* is drawn in the browser by `initWaveDrom`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function rehypeWavedrom(options?: WavedromOptions): (tree: HastNode, file: unknown) => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type ElementNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
tagName?: string;
|
|
4
|
+
properties?: Record<string, unknown>;
|
|
5
|
+
children?: HastNode[];
|
|
6
|
+
};
|
|
7
|
+
export type ParentNode = HastNode & {
|
|
8
|
+
children?: HastNode[];
|
|
9
|
+
};
|
|
10
|
+
export type TextNode = {
|
|
11
|
+
type: "text";
|
|
12
|
+
value: string;
|
|
13
|
+
};
|
|
14
|
+
export type RawNode = {
|
|
15
|
+
type: "raw";
|
|
16
|
+
value: string;
|
|
17
|
+
};
|
|
18
|
+
export type HastNode = ElementNode | TextNode | RawNode | {
|
|
19
|
+
type: string;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
};
|
|
22
|
+
/** A WaveDrom skin shipped by the `wavedrom` package. */
|
|
23
|
+
export type WavedromSkin = "default" | "narrow" | "lowkey";
|
|
24
|
+
export type WavedromOptions = {
|
|
25
|
+
/**
|
|
26
|
+
* WaveDrom skin used by the browser renderer. The value is forwarded to the
|
|
27
|
+
* client through a `data-wavedrom-skin` attribute because client entry code
|
|
28
|
+
* cannot see plugin options. Defaults to `"default"`.
|
|
29
|
+
*/
|
|
30
|
+
skin?: WavedromSkin;
|
|
31
|
+
/** Render the extracted caption as a `<figcaption>`. Defaults to `true`. */
|
|
32
|
+
caption?: boolean;
|
|
33
|
+
/** Render a `<details>` block containing the WaveJSON source. Defaults to `true`. */
|
|
34
|
+
fallback?: boolean;
|
|
35
|
+
/** Base CSS class for the generated figure. Defaults to `"rb-wavedrom"`. */
|
|
36
|
+
className?: string;
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-wavedrom",
|
|
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
|
+
"wavedrom": "^3.7.0",
|
|
25
|
+
"@riebeckite/core": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md",
|
|
33
|
+
"README_ja.md",
|
|
34
|
+
"dist",
|
|
35
|
+
"style.css"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
40
|
+
"directory": "packages/plugins/wavedrom"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
45
|
+
},
|
|
46
|
+
"description": "WaveDrom timing diagram rendering for Riebeckite.",
|
|
47
|
+
"keywords": [
|
|
48
|
+
"riebeckite",
|
|
49
|
+
"plugin",
|
|
50
|
+
"wavedrom",
|
|
51
|
+
"diagrams"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": [
|
|
57
|
+
"./style.css"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "node ../../../scripts/build_package.mjs"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
.rb-wavedrom {
|
|
2
|
+
--rb-wavedrom-paper: var(--rb-color-paper, #ffffff);
|
|
3
|
+
--rb-wavedrom-ink: var(--rb-color-ink, #000000);
|
|
4
|
+
--rb-wavedrom-muted: var(--rb-color-muted, #69645c);
|
|
5
|
+
--rb-wavedrom-rule: var(
|
|
6
|
+
--rb-color-border,
|
|
7
|
+
color-mix(in srgb, var(--rb-wavedrom-ink) 18%, transparent)
|
|
8
|
+
);
|
|
9
|
+
margin: 2rem 0;
|
|
10
|
+
border: 1px solid var(--rb-wavedrom-rule);
|
|
11
|
+
background: color-mix(
|
|
12
|
+
in srgb,
|
|
13
|
+
var(--rb-wavedrom-paper) 96%,
|
|
14
|
+
var(--rb-wavedrom-ink)
|
|
15
|
+
);
|
|
16
|
+
color: var(--rb-wavedrom-ink);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.rb-wavedrom__caption {
|
|
20
|
+
padding: 0.625rem 0.75rem;
|
|
21
|
+
border-bottom: 1px solid var(--rb-wavedrom-rule);
|
|
22
|
+
color: var(--rb-wavedrom-muted);
|
|
23
|
+
font-size: 0.875rem;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.rb-wavedrom__canvas {
|
|
27
|
+
overflow: auto;
|
|
28
|
+
padding: 1rem;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.rb-wavedrom__canvas > svg {
|
|
32
|
+
display: block;
|
|
33
|
+
max-width: 100%;
|
|
34
|
+
height: auto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.rb-wavedrom__fallback {
|
|
38
|
+
border-top: 1px solid var(--rb-wavedrom-rule);
|
|
39
|
+
color: var(--rb-wavedrom-muted);
|
|
40
|
+
font-size: 0.8125rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.rb-wavedrom__fallback summary {
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
padding: 0.5rem 0.75rem;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.rb-wavedrom__fallback pre {
|
|
49
|
+
overflow: auto;
|
|
50
|
+
margin: 0 1rem;
|
|
51
|
+
padding: 0.75rem;
|
|
52
|
+
border-top: 1px solid var(--rb-wavedrom-rule);
|
|
53
|
+
color: var(--rb-wavedrom-ink);
|
|
54
|
+
background: color-mix(in srgb, var(--rb-wavedrom-ink) 6%, transparent);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.rb-wavedrom[data-wavedrom="pending"] .rb-wavedrom__canvas:empty::before,
|
|
58
|
+
.rb-wavedrom[data-wavedrom="error"] .rb-wavedrom__canvas:empty::before {
|
|
59
|
+
content: "Timing diagram could not be rendered.";
|
|
60
|
+
color: var(--rb-wavedrom-muted);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
html[data-theme="dark"] .rb-wavedrom,
|
|
64
|
+
html.dark .rb-wavedrom {
|
|
65
|
+
--rb-wavedrom-paper: var(--rb-color-ink, #000000);
|
|
66
|
+
--rb-wavedrom-ink: var(--rb-color-paper, #ffffff);
|
|
67
|
+
}
|