@riebeckite/plugin-markmap 0.0.31 → 0.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,19 @@ becomes the tree. Content other than headings is ignored.
48
48
 
49
49
  The caption comes from the code-block `title`.
50
50
 
51
+ ## Live example
52
+
53
+ ~~~markmap
54
+ # Project
55
+
56
+ ## Design
57
+
58
+ ### Notation
59
+ ### Rendering
60
+
61
+ ## Delivery
62
+ ~~~
63
+
51
64
  ## How it renders
52
65
 
53
66
  A ` ```markmap ` block becomes a `figure.rb-markmap`:
@@ -121,7 +134,7 @@ point for that purpose.
121
134
 
122
135
  ## Main exports
123
136
 
124
- - `markmap(options?)`: create the plugin (`markmapPlugin` is an alias)
137
+ - `markmap(options?)`: create the plugin (`markmap` is an alias)
125
138
  - `initMarkmap`: initialize client-side rendering
126
139
  - `parseMarkmapSource`: parse the standard notation into a tree
127
140
  - `describeMarkmapTree`: derive an accessible label from a tree
package/README_ja.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  <!-- Generated from docs/docs/plugins/markmap.ja.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
4
4
 
5
- ` ```markmap ` コードブロックを、Markdown の見出しから組み立てるマインドマップとして表示するプラグインです。マインドマップはブラウザ側で `markmap-lib` と `markmap-view` により描画し、これらのライブラリは図があるときだけ CDN から読み込みます。
5
+ ` ```markmap ` コードブロックを、Markdown の見出しから組み立てるマインドマップとして表示するプラグインです。マインドマップはブラウザ側で `markmap-lib` と `markmap-view` により描画します。これらのライブラリは図があるときだけ CDN から読み込みます。
6
6
 
7
7
  [English](./README.md)
8
8
 
9
- ## 設定する
9
+ ## 使い方
10
10
 
11
11
  ```ts
12
12
  import { defineConfig } from "@riebeckite/core";
@@ -28,7 +28,7 @@ export default defineConfig({
28
28
 
29
29
  ## 記法
30
30
 
31
- コードブロックの本文は通常の Markdown です。見出しがノードになり、見出しの階層が木構造になります。見出し以外の内容は無視します。
31
+ コードブロックの本文は通常の Markdown です。見出しがノードになり、見出しの階層が木構造になります。見出し以外の内容は無視されます。
32
32
 
33
33
  ````markdown
34
34
  ```markmap
@@ -45,7 +45,20 @@ export default defineConfig({
45
45
 
46
46
  キャプションにはコードブロックの `title` を使います。
47
47
 
48
- ## どのように描画されるか
48
+ ## 実行例
49
+
50
+ ~~~markmap
51
+ # Project
52
+
53
+ ## Design
54
+
55
+ ### Notation
56
+ ### Rendering
57
+
58
+ ## Delivery
59
+ ~~~
60
+
61
+ ## 描画の仕組み
49
62
 
50
63
  ` ```markmap ` のコードブロックは `figure.rb-markmap` に置き換わります。
51
64
 
@@ -69,15 +82,15 @@ Markdown の見出しを 1 つも含まないコードブロックは置き換
69
82
  | `className` | `"rb-markmap"` | figure に付ける基準クラス |
70
83
  | `language` | `"markmap"` | 対象にするコードブロックの言語 |
71
84
  | `fallback` | `true` | 元の Markdown を表示する `details` を描画する |
72
- | `colorFreezeLevel` |:| ノードの色を固定する深さ |
85
+ | `colorFreezeLevel` | — | ノードの色を固定する深さ |
73
86
 
74
87
  ## クライアント側の描画
75
88
 
76
- クライアントの初期化コードは静的なので、プラグインのオプションは受け取りません。`height` と `colorFreezeLevel` は figure の `data-markmap-*` 属性に埋め込まれ、`initMarkmap` がそこから読み取ります。
89
+ クライアントの初期化コードは固定で、プラグインのオプションを受け取りません。`height` と `colorFreezeLevel` は figure の `data-markmap-*` 属性に埋め込まれ、`initMarkmap` がそこから読み取ります。
77
90
 
78
- `markmap-lib` と `markmap-view` は計算された import 指定子で jsDelivr から取得するため、ホストのクライアントバンドルには含まれません。`markmap-view` は依存として `d3` を読み込みます。ライブラリを遅延して読み込むので、JavaScript を無効にしていてもページは表示され、元の Markdown はフォールバックの `details` から読めます。
91
+ `markmap-lib` と `markmap-view` は動的に組み立てた import 指定子で jsDelivr から取得するため、ホスト側のクライアントバンドルには含まれません。`markmap-view` は依存として `d3` を読み込みます。遅延読み込みなので、JavaScript を無効にしていてもページは表示され、元の Markdown はフォールバックの `details` から読めます。
79
92
 
80
- ## 入力記法の継ぎ目(notation seam)
93
+ ## 入力記法の拡張点
81
94
 
82
95
  コードブロックの本文は、`src/parse.ts` にある単一の純粋関数でマインドマップの木に変換します。
83
96
 
@@ -85,9 +98,9 @@ Markdown の見出しを 1 つも含まないコードブロックは置き換
85
98
  parseMarkmapSource(source: string): MarkmapNode | null
86
99
  ```
87
100
 
88
- `MarkmapNode` は記法に依存しない木(`{ content, children, payload? }`)です。現在は標準の Markdown 見出し記法だけを実装しています。将来別の入力記法(たとえば "ExcaliMindMap" 風のアウトライン)を追加するときは、同じ `MarkmapNode` を返すパーサーを実装するだけです。figure の生成と描画の経路は記法を解析しないため、変更する必要はありません。`parseMarkmapSource` はそのためにパッケージのエントリーポイントから公開しています。
101
+ `MarkmapNode` は記法に依存しない木(`{ content, children, payload? }`)です。現在は標準の Markdown 見出し記法だけを実装しています。将来別の入力記法(たとえば "ExcaliMindMap" 風のアウトライン)を追加するときは、同じ `MarkmapNode` を返すパーサーを実装するだけです。figure の生成と描画の処理は記法を解析しないため、変更する必要はありません。`parseMarkmapSource` はそのためにパッケージのエントリーポイントから公開しています。
89
102
 
90
- ## 出力のフック
103
+ ## 出力フック
91
104
 
92
105
  - `figure[data-markmap]`: 状態(`pending` / `rendered` / `error`)
93
106
  - `figure[data-markmap-source]`: 元の Markdown
@@ -97,7 +110,7 @@ parseMarkmapSource(source: string): MarkmapNode | null
97
110
 
98
111
  ## 主なエクスポート
99
112
 
100
- - `markmap(options?)`: プラグインを作成する(`markmapPlugin` は別名)
113
+ - `markmap(options?)`: プラグインを作成する(`markmap` は別名)
101
114
  - `initMarkmap`: クライアント側の描画を初期化する
102
115
  - `parseMarkmapSource`: 標準記法を木に変換する
103
116
  - `describeMarkmapTree`: 木からアクセシブルなラベルを作る
package/dist/index.d.ts CHANGED
@@ -8,5 +8,3 @@ export type { MarkmapClientOptions, MarkmapNode, MarkmapOptions, MarkmapResolved
8
8
  * `markmap-view` from the CDN only when a figure is present.
9
9
  */
10
10
  export declare function markmap(options?: MarkmapOptions): import("@riebeckite/core").RiebeckitePlugin<MarkmapOptions>;
11
- /** Alias kept for symmetry with the other plugin factories. */
12
- export declare const markmapPlugin: typeof markmap;
package/dist/index.js CHANGED
@@ -5,6 +5,22 @@ import {
5
5
  definePlugin
6
6
  } from "@riebeckite/core";
7
7
 
8
+ // src/hast.ts
9
+ import {
10
+ element as sharedElement,
11
+ getStringProperty as sharedGetStringProperty,
12
+ getTextContent as sharedGetTextContent,
13
+ hasClass as sharedHasClass,
14
+ text as sharedText,
15
+ visitElements as sharedVisitElements
16
+ } from "@riebeckite/diagram";
17
+ var element = sharedElement;
18
+ var text = sharedText;
19
+ var getTextContent = sharedGetTextContent;
20
+ var getStringProperty = sharedGetStringProperty;
21
+ var hasClass = sharedHasClass;
22
+ var visitElements = sharedVisitElements;
23
+
8
24
  // src/options.ts
9
25
  var DEFAULT_MARKMAP_CLASS_NAME = "rb-markmap";
10
26
  var DEFAULT_MARKMAP_HEIGHT = 320;
@@ -129,10 +145,14 @@ function buildFigure(input) {
129
145
  }
130
146
  if (input.fallback) {
131
147
  children.push(
132
- element("details", { className: `${base}__fallback` }, [
133
- element("summary", {}, [text("Markdown source")]),
134
- element("pre", {}, [element("code", {}, [text(input.source)])])
135
- ])
148
+ element(
149
+ "details",
150
+ { className: `${base}__fallback rb-source-fallback` },
151
+ [
152
+ element("summary", {}, [text("Markdown source")]),
153
+ element("pre", {}, [element("code", {}, [text(input.source)])])
154
+ ]
155
+ )
136
156
  );
137
157
  }
138
158
  return element(
@@ -172,50 +192,6 @@ function reportDiagnostic(file, message) {
172
192
  });
173
193
  }
174
194
  }
175
- function visitElements(node, visitor, parent, index) {
176
- if (isElementNode(node)) visitor(node, parent, index);
177
- for (const [childIndex, child] of [...getChildren(node)].entries()) {
178
- visitElements(
179
- child,
180
- visitor,
181
- hasChildren(node) ? node : parent,
182
- childIndex
183
- );
184
- }
185
- }
186
- function element(tagName, properties = {}, children = []) {
187
- return { type: "element", tagName, properties, children };
188
- }
189
- function text(value) {
190
- return { type: "text", value };
191
- }
192
- function getTextContent(node) {
193
- if (node.type === "text" && "value" in node && typeof node.value === "string") {
194
- return node.value;
195
- }
196
- return getChildren(node).map(getTextContent).join("");
197
- }
198
- function getStringProperty(node, key) {
199
- const value = node.properties?.[key];
200
- if (typeof value === "string") return value;
201
- if (Array.isArray(value)) return value.join(" ");
202
- return null;
203
- }
204
- function hasClass(node, className) {
205
- const value = node.properties?.className;
206
- const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
207
- return classes.includes(className);
208
- }
209
- function isElementNode(node) {
210
- return node.type === "element";
211
- }
212
- function hasChildren(node) {
213
- return Array.isArray(node.children);
214
- }
215
- function getChildren(node) {
216
- const children = node.children;
217
- return Array.isArray(children) ? children : [];
218
- }
219
195
 
220
196
  // index.ts
221
197
  function markmap(options = {}) {
@@ -243,7 +219,6 @@ function markmap(options = {}) {
243
219
  ]
244
220
  });
245
221
  }
246
- var markmapPlugin = markmap;
247
222
  function validateMarkmapOptions(options) {
248
223
  if (!options) return [];
249
224
  const issues = [];
@@ -272,7 +247,6 @@ function validateMarkmapOptions(options) {
272
247
  export {
273
248
  describeMarkmapTree,
274
249
  markmap,
275
- markmapPlugin,
276
250
  parseMarkmapSource,
277
251
  resolveMarkmapOptions
278
252
  };
@@ -0,0 +1,7 @@
1
+ import type { ElementNode, HastNode, ParentNode, TextNode } from "./types.js";
2
+ export declare const element: (tagName: string, properties?: Record<string, unknown>, children?: HastNode[]) => ElementNode;
3
+ export declare const text: (value: string) => TextNode;
4
+ export declare const getTextContent: (node: HastNode) => string;
5
+ export declare const getStringProperty: (node: ElementNode, key: string) => string | null;
6
+ export declare const hasClass: (node: ElementNode, className: string) => boolean;
7
+ export declare const visitElements: (node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number) => void;
@@ -1,10 +1,4 @@
1
1
  import type { MarkmapOptions, MarkmapResolvedOptions } from "./types.js";
2
- /** Default base class for the generated figure. */
3
- export declare const DEFAULT_MARKMAP_CLASS_NAME = "rb-markmap";
4
- /** Default canvas height in pixels. */
5
- export declare const DEFAULT_MARKMAP_HEIGHT = 320;
6
- /** Default fenced-code language. */
7
- export declare const DEFAULT_MARKMAP_LANGUAGE = "markmap";
8
2
  /**
9
3
  * Applies defaults to the user-provided options.
10
4
  *
@@ -104,7 +104,7 @@ export type TextNode = {
104
104
  type: "text";
105
105
  value: string;
106
106
  };
107
- export type RawNode = {
107
+ type RawNode = {
108
108
  type: "raw";
109
109
  value: string;
110
110
  };
@@ -112,3 +112,4 @@ export type HastNode = ElementNode | TextNode | RawNode | {
112
112
  type: string;
113
113
  [key: string]: unknown;
114
114
  };
115
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-markmap",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,9 +21,10 @@
21
21
  "./style.css": "./style.css"
22
22
  },
23
23
  "dependencies": {
24
+ "@riebeckite/core": "0.0.33",
25
+ "@riebeckite/diagram": "0.0.33",
24
26
  "markmap-lib": "^0.18.12",
25
- "markmap-view": "^0.18.12",
26
- "@riebeckite/core": "0.0.31"
27
+ "markmap-view": "^0.18.12"
27
28
  },
28
29
  "publishConfig": {
29
30
  "access": "public"
package/style.css CHANGED
@@ -34,26 +34,6 @@
34
34
  max-width: 100%;
35
35
  }
36
36
 
37
- .rb-markmap__fallback {
38
- border-top: 1px solid var(--rb-markmap-rule);
39
- color: var(--rb-markmap-muted);
40
- font-size: 0.8125rem;
41
- }
42
-
43
- .rb-markmap__fallback summary {
44
- cursor: pointer;
45
- padding: 0.5rem 0.75rem;
46
- }
47
-
48
- .rb-markmap__fallback pre {
49
- overflow: auto;
50
- margin: 0 1rem;
51
- padding: 0.75rem;
52
- border-top: 1px solid var(--rb-markmap-rule);
53
- color: var(--rb-markmap-ink);
54
- background: color-mix(in srgb, var(--rb-markmap-ink) 6%, transparent);
55
- }
56
-
57
37
  .rb-markmap[data-markmap="error"] .rb-markmap__canvas:empty::before,
58
38
  .rb-markmap[data-markmap="pending"] .rb-markmap__canvas:empty::before {
59
39
  content: "Mind map could not be rendered.";