@riebeckite/plugin-excalibrain 0.0.5 → 0.0.7

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
@@ -1,165 +1,172 @@
1
- # @riebeckite/plugin-excalibrain
2
-
3
- Structured relationship maps for notes, modelled on
4
- [ExcaliBrain](https://github.com/zsviczian/excalibrain) by Zsolt Viczián.
5
-
6
- [日本語](./README_ja.md)
7
-
8
- ## Overview
9
-
10
- `excaliBrain()` renders each note in a planar layout with seven regions:
11
-
12
- | Region | Direction | Role |
13
- | ------ | --------- | ---- |
14
- | Parents | top | `parent` |
15
- | Children | bottom | `child` |
16
- | Left friends | left | `leftFriend` |
17
- | Right friends | right | `rightFriend` |
18
- | Previous | far left | `previous` |
19
- | Next | far right | `next` |
20
- | Siblings | periphery | `sibling` |
21
-
22
- Relationships come from ExcaliBrain's ontology: YAML frontmatter fields and
23
- dataview inline fields in the note body. When a relationship is not stated
24
- explicitly, it is inferred from the content graph.
25
-
26
- ## Usage
27
-
28
- ```ts
29
- import { defineConfig } from "@riebeckite/core";
30
- import { excaliBrain } from "@riebeckite/plugin-excalibrain";
31
-
32
- export default defineConfig({
33
- // ...
34
- plugins: [
35
- excaliBrain({
36
- render: "build",
37
- }),
38
- ],
39
- });
40
- ```
41
-
42
- The plugin runs with `order: -10`.
43
-
44
- ## Declaring relationships
45
-
46
- Explicit relations win over inferred ones.
47
-
48
- ### YAML frontmatter
49
-
50
- ```md
51
- ---
52
- title: ExcaliBrain Center
53
- parent: "[[excalibrain-parent]]"
54
- children: ["[[excalibrain-child-a]]", "[[excalibrain-child-b]]"]
55
- ---
56
- ```
57
-
58
- ### Dataview inline fields
59
-
60
- ```md
61
- children:: [[excalibrain-child]]
62
-
63
- related:: [[note-a]] and [[note-b]] are similar
64
- ```
65
-
66
- An inline field may appear on its own line or inside brackets
67
- (`[field:: [[target]]]`).
68
-
69
- ### Ontology
70
-
71
- Field names are matched case-insensitively and spaces are normalized to
72
- hyphens. The default ontology is:
73
-
74
- | Role | Field names |
75
- | ---- | ----------- |
76
- | `parents` | `parent`, `parents`, `up`, `u`, `north`, `origin`, `inception` |
77
- | `children` | `children`, `child`, `down`, `d`, `south`, `leads to`, `contributes to` |
78
- | `leftFriends` | `friends`, `friend`, `similar`, `supports`, `alternatives`, `advantages` |
79
- | `rightFriends` | `opposes`, `disadvantages`, `missing`, `cons` |
80
- | `previous` | `previous`, `prev`, `west`, `w`, `before` |
81
- | `next` | `next`, `n`, `east`, `e`, `after` |
82
- | `hidden` | `hidden` |
83
-
84
- ## Inference
85
-
86
- When `infer` is enabled (the default):
87
-
88
- - a forward link (this note → other) becomes a `child`;
89
- - a backlink (other → this note) becomes a `parent`;
90
- - a mutual link (this note ↔ other) becomes a `leftFriend`.
91
-
92
- With `siblings` enabled (the default), the other children of this note's
93
- parents become `sibling` nodes. Link targets are resolved against the content
94
- manifest; unresolved targets become virtual nodes labelled with the raw link
95
- text (`data-node-virtual="true"`).
96
-
97
- ## Rendering
98
-
99
- The `render` option selects where the map is produced:
100
-
101
- | Mode | Behavior |
102
- | ---- | -------- |
103
- | `"build"` (default) | The SVG is generated at build time and inlined into the article. |
104
- | `"client"` | A `div.rb-excalibrain__canvas` carries the escaped graph/layout payload; `initExcaliBrain()` builds the SVG in the browser. |
105
- | `"both"` | Inline SVG plus the client layer for progressive enhancement. |
106
-
107
- ### Injection
108
-
109
- - A ` ```excalibrain ` fence is replaced by the map.
110
- - Otherwise, when `auto` is enabled and the note has at least one
111
- relationship, the map section is appended to the article HTML (both the
112
- manifest entry and the cached post content).
113
-
114
- `heading` / `headingText` control the optional `<h2>`.
115
-
116
- ## Options
117
-
118
- | Option | Type | Default | Description |
119
- | ------ | ---- | ------- | ----------- |
120
- | `render` | `"build" \| "client" \| "both"` | `"build"` | Where the map is rendered |
121
- | `auto` | `boolean` | `true` | Append the map when a note has no fence |
122
- | `heading` | `boolean` | `true` | Show the heading |
123
- | `headingText` | `string` | `"ExcaliBrain"` | Heading text |
124
- | `className` | `string` | `"rb-excalibrain"` | Root CSS class |
125
- | `maxPerRegion` | `number` | `8` | Maximum nodes per region |
126
- | `infer` | `boolean` | `true` | Infer relations from links |
127
- | `siblings` | `boolean` | `true` | Infer siblings from parents |
128
- | `ontology` | object | — | Partial ontology field overrides |
129
- | `showHidden` | `boolean` | `false` | Include notes marked hidden |
130
- | `width` | `number` | `720` | SVG viewBox width |
131
- | `height` | `number` | `480` | SVG viewBox height |
132
- | `language` | `string` | `"excalibrain"` | Fence language |
133
-
134
- ## Output
135
-
136
- ```html
137
- <section class="rb-excalibrain" data-excalibrain
138
- data-excalibrain-render="build"
139
- data-excalibrain-center="notes/center">
140
- <h2 class="rb-excalibrain__heading">ExcaliBrain</h2>
141
- <div class="rb-excalibrain__canvas">
142
- <svg class="rb-excalibrain__svg" viewBox="0 0 720 480" role="img">…</svg>
143
- </div>
144
- </section>
145
- ```
146
-
147
- Each region is a `g.rb-excalibrain__region[data-region]`; each node is a
148
- `g.rb-excalibrain__node[data-node-role][data-node-slug][data-relation-type]`
149
- wrapping an `<a href>` around its `<rect>` and `<text>`. Links are
150
- `path.rb-excalibrain__link[data-link-role][data-relation-type]`.
151
-
152
- ## Exports
153
-
154
- - `excaliBrain(options?)` / `excaliBrainPlugin` — plugin factory
155
- - `resolveExcaliBrainOptions(options?)` — resolved defaults
156
- - `buildExcaliBrainGraph(input)` — pure graph builder
157
- - `layoutExcaliBrain(graph, options?)` — pure deterministic layout
158
- - `renderExcaliBrainSvg(graph, layout, options?)` — pure SVG renderer
159
- - Types: `ExcaliBrainOptions`, `ExcaliBrainGraph`, `ExcaliBrainNode`,
160
- `ExcaliBrainLink`, `ExcaliBrainLayout`, `ExcaliBrainRole`,
161
- `ExcaliBrainRenderMode`, …
162
-
163
- ## See also
164
-
165
- - [Plugin guide](../../../docs/en/plugin-system.md)
1
+ # @riebeckite/plugin-excalibrain
2
+
3
+ Structured relationship maps for notes, modelled on
4
+ [ExcaliBrain](https://github.com/zsviczian/excalibrain) by Zsolt Viczián.
5
+
6
+ [日本語](./README_ja.md)
7
+
8
+ ## Overview
9
+
10
+ `excaliBrain()` renders each note in a planar layout with seven regions:
11
+
12
+ | Region | Direction | Role |
13
+ | ------ | --------- | ---- |
14
+ | Parents | top | `parent` |
15
+ | Children | bottom | `child` |
16
+ | Left friends | left | `leftFriend` |
17
+ | Right friends | right | `rightFriend` |
18
+ | Previous | far left | `previous` |
19
+ | Next | far right | `next` |
20
+ | Siblings | periphery | `sibling` |
21
+
22
+ Relationships come from ExcaliBrain's ontology: YAML frontmatter fields and
23
+ dataview inline fields in the note body. When a relationship is not stated
24
+ explicitly, it is inferred from the content graph.
25
+
26
+ ## Usage
27
+
28
+ ```ts
29
+ import { defineConfig } from "@riebeckite/core";
30
+ import { excaliBrain } from "@riebeckite/plugin-excalibrain";
31
+
32
+ export default defineConfig({
33
+ // ...
34
+ plugins: [
35
+ excaliBrain({
36
+ render: "build",
37
+ }),
38
+ ],
39
+ });
40
+ ```
41
+
42
+ The plugin runs with `order: -10`.
43
+
44
+ ## Declaring relationships
45
+
46
+ Explicit relations win over inferred ones.
47
+
48
+ ### YAML frontmatter
49
+
50
+ ```md
51
+ ---
52
+ title: ExcaliBrain Center
53
+ parent: "[[excalibrain-parent]]"
54
+ children: ["[[excalibrain-child-a]]", "[[excalibrain-child-b]]"]
55
+ ---
56
+ ```
57
+
58
+ ### Dataview inline fields
59
+
60
+ ```md
61
+ children:: [[excalibrain-child]]
62
+
63
+ related:: [[note-a]] and [[note-b]] are similar
64
+ ```
65
+
66
+ An inline field may appear on its own line or inside brackets
67
+ (`[field:: [[target]]]`).
68
+
69
+ ### Ontology
70
+
71
+ Field names are matched case-insensitively and spaces are normalized to
72
+ hyphens. The default ontology is:
73
+
74
+ | Role | Field names |
75
+ | ---- | ----------- |
76
+ | `parents` | `parent`, `parents`, `up`, `u`, `north`, `origin`, `inception` |
77
+ | `children` | `children`, `child`, `down`, `d`, `south`, `leads to`, `contributes to` |
78
+ | `leftFriends` | `friends`, `friend`, `similar`, `supports`, `alternatives`, `advantages` |
79
+ | `rightFriends` | `opposes`, `disadvantages`, `missing`, `cons` |
80
+ | `previous` | `previous`, `prev`, `west`, `w`, `before` |
81
+ | `next` | `next`, `n`, `east`, `e`, `after` |
82
+ | `hidden` | `hidden` |
83
+
84
+ The `ontology` option extends the defaults: each role's field names are
85
+ appended to that role's defaults rather than replacing them. An override can
86
+ still add an existing field to another role, but earlier roles in the
87
+ canonical order (`parents`, `children`, `leftFriends`, `rightFriends`,
88
+ `previous`, `next`, `hidden`) win when a field is listed twice.
89
+
90
+ ## Inference
91
+
92
+ When `infer` is enabled (the default):
93
+
94
+ - a forward link (this note → other) becomes a `child`;
95
+ - a backlink (other → this note) becomes a `parent`;
96
+ - a mutual link (this note ↔ other) becomes a `leftFriend`.
97
+
98
+ With `siblings` enabled (the default), the other children of this note's
99
+ parents become `sibling` nodes. Sibling inference also requires `infer`:
100
+ setting `infer: false` disables it. Link targets are resolved against the
101
+ content manifest; unresolved targets become virtual nodes labelled with the
102
+ raw link text (`data-node-virtual="true"`).
103
+
104
+ ## Rendering
105
+
106
+ The `render` option selects where the map is produced:
107
+
108
+ | Mode | Behavior |
109
+ | ---- | -------- |
110
+ | `"build"` (default) | The SVG is generated at build time and inlined into the article. |
111
+ | `"client"` | A `div.rb-excalibrain__canvas` carries the escaped graph/layout payload; `initExcaliBrain()` builds the SVG in the browser. |
112
+ | `"both"` | Inline SVG plus the client layer for progressive enhancement. |
113
+
114
+ ### Injection
115
+
116
+ - A ` ```excalibrain ` fence is replaced by the map.
117
+ - Otherwise, when `auto` is enabled and the note has at least one
118
+ relationship, the map section is appended to the article HTML (both the
119
+ manifest entry and the cached post content).
120
+
121
+ `heading` / `headingText` control the optional `<h2>`.
122
+
123
+ ## Options
124
+
125
+ | Option | Type | Default | Description |
126
+ | ------ | ---- | ------- | ----------- |
127
+ | `render` | `"build" \| "client" \| "both"` | `"build"` | Where the map is rendered |
128
+ | `auto` | `boolean` | `true` | Append the map when a note has no fence |
129
+ | `heading` | `boolean` | `true` | Show the heading |
130
+ | `headingText` | `string` | `"ExcaliBrain"` | Heading text |
131
+ | `className` | `string` | `"rb-excalibrain"` | Root CSS class |
132
+ | `maxPerRegion` | `number` | `8` | Maximum nodes per region |
133
+ | `infer` | `boolean` | `true` | Infer relations from links |
134
+ | `siblings` | `boolean` | `true` | Infer siblings from parents (requires `infer`) |
135
+ | `ontology` | object | — | Ontology field names appended per role |
136
+ | `showHidden` | `boolean` | `false` | Include notes marked hidden |
137
+ | `width` | `number` | `720` | SVG viewBox width |
138
+ | `height` | `number` | `480` | SVG viewBox height |
139
+ | `language` | `string` | `"excalibrain"` | Fence language |
140
+
141
+ ## Output
142
+
143
+ ```html
144
+ <section class="rb-excalibrain" data-excalibrain
145
+ data-excalibrain-render="build"
146
+ data-excalibrain-center="notes/center">
147
+ <h2 class="rb-excalibrain__heading">ExcaliBrain</h2>
148
+ <div class="rb-excalibrain__canvas">
149
+ <svg class="rb-excalibrain__svg" viewBox="0 0 720 480" role="img">…</svg>
150
+ </div>
151
+ </section>
152
+ ```
153
+
154
+ Each region is a `g.rb-excalibrain__region[data-region]`; each node is a
155
+ `g.rb-excalibrain__node[data-node-role][data-node-slug][data-relation-type]`
156
+ wrapping an `<a href>` around its `<rect>` and `<text>`. Links are
157
+ `path.rb-excalibrain__link[data-link-role][data-relation-type]`.
158
+
159
+ ## Exports
160
+
161
+ - `excaliBrain(options?)` / `excaliBrainPlugin` — plugin factory
162
+ - `resolveExcaliBrainOptions(options?)` — resolved defaults
163
+ - `buildExcaliBrainGraph(input)` — pure graph builder
164
+ - `layoutExcaliBrain(graph, options?)` — pure deterministic layout
165
+ - `renderExcaliBrainSvg(graph, layout, options?)` — pure SVG renderer
166
+ - Types: `ExcaliBrainOptions`, `ExcaliBrainGraph`, `ExcaliBrainNode`,
167
+ `ExcaliBrainLink`, `ExcaliBrainLayout`, `ExcaliBrainRole`,
168
+ `ExcaliBrainRenderMode`, …
169
+
170
+ ## See also
171
+
172
+ - [Plugin guide](../../../docs/en/plugin-system.md)
package/README_ja.md CHANGED
@@ -1,150 +1,152 @@
1
- # @riebeckite/plugin-excalibrain
2
-
3
- ノートの関係を構造化して表示するプラグインです。[ExcaliBrain](https://github.com/zsviczian/excalibrain)(Zsolt Viczián)の考え方をモデルにしています。
4
-
5
- [English](./README.md)
6
-
7
- ## 概要
8
-
9
- `excaliBrain()` はノートごとに 7 つの領域を持つマップを描画します。
10
-
11
- | 領域 | 位置 | ロール |
12
- | --- | --- | --- |
13
- | Parents | 上 | `parent` |
14
- | Children | 下 | `child` |
15
- | Left friends | 左 | `leftFriend` |
16
- | Right friends | 右 | `rightFriend` |
17
- | Previous | 左端 | `previous` |
18
- | Next | 右端 | `next` |
19
- | Siblings | 周辺 | `sibling` |
20
-
21
- 関係は ExcaliBrain のオントロジーに従い、YAML フロントマターと本文中の Dataview インラインフィールドから取得します。明示されていない関係は、コンテンツグラフから推論します。
22
-
23
- ## 設定する
24
-
25
- ```ts
26
- import { defineConfig } from "@riebeckite/core";
27
- import { excaliBrain } from "@riebeckite/plugin-excalibrain";
28
-
29
- export default defineConfig({
30
- // ...
31
- plugins: [
32
- excaliBrain({
33
- render: "build",
34
- }),
35
- ],
36
- });
37
- ```
38
-
39
- このプラグインは `order: -10` で実行されます。
40
-
41
- ## 関係の書き方
42
-
43
- 明示した関係は推論より優先されます。
44
-
45
- ### YAML フロントマター
46
-
47
- ```md
48
- ---
49
- title: ExcaliBrain Center
50
- parent: "[[excalibrain-parent]]"
51
- children: ["[[excalibrain-child-a]]", "[[excalibrain-child-b]]"]
52
- ---
53
- ```
54
-
55
- ### Dataview インラインフィールド
56
-
57
- ```md
58
- children:: [[excalibrain-child]]
59
-
60
- related:: [[note-a]] and [[note-b]] are similar
61
- ```
62
-
63
- フィールドは単独行でも、`[field:: [[target]]]` のように角括弧で囲んでも認識します。
64
-
65
- ### オントロジー
66
-
67
- フィールド名は大文字小文字を区別せず、空白はハイフンに正規化して照合します。既定のオントロジーは次のとおりです。
68
-
69
- | ロール | フィールド名 |
70
- | --- | --- |
71
- | `parents` | `parent`, `parents`, `up`, `u`, `north`, `origin`, `inception` |
72
- | `children` | `children`, `child`, `down`, `d`, `south`, `leads to`, `contributes to` |
73
- | `leftFriends` | `friends`, `friend`, `similar`, `supports`, `alternatives`, `advantages` |
74
- | `rightFriends` | `opposes`, `disadvantages`, `missing`, `cons` |
75
- | `previous` | `previous`, `prev`, `west`, `w`, `before` |
76
- | `next` | `next`, `n`, `east`, `e`, `after` |
77
- | `hidden` | `hidden` |
78
-
79
- ## 推論
80
-
81
- `infer` が有効な場合(既定)、次のように推論します。
82
-
83
- - このノートから相手へのリンクは `child`
84
- - 相手からこのノートへのバックリンクは `parent`
85
- - 相互リンクは `leftFriend`
86
-
87
- `siblings` が有効な場合(既定)、親ノートの他の子ノートを `sibling` として追加します。リンク先はコンテンツマニフェストから解決し、解決できない場合は元のリンクテキストをラベルにした仮想ノード(`data-node-virtual="true"`)にします。
88
-
89
- ## 描画
90
-
91
- `render` で描画する場所を選びます。
92
-
93
- | モード | 動作 |
94
- | --- | --- |
95
- | `"build"`(既定) | ビルド時に SVG を生成し、記事に埋め込みます |
96
- | `"client"` | `div.rb-excalibrain__canvas` にグラフとレイアウトのペイロードをエスケープして持ち、`initExcaliBrain()` がブラウザで SVG を生成します |
97
- | `"both"` | 埋め込み SVG とクライアント側の描画を併用します(プログレッシブエンハンスメント) |
98
-
99
- ### 差し込み方
100
-
101
- - ` ```excalibrain ` フェンスがある場合は、そのプレースホルダーをマップに置き換えます。
102
- - フェンスがなく、`auto` が有効で関係が 1 つ以上ある場合は、記事 HTML の末尾にマップのセクションを追加します(マニフェストのエントリとキャッシュ済みの記事 HTML の両方を更新します)。
103
-
104
- `heading` と `headingText` は任意の `<h2>` を制御します。
105
-
106
- ## オプション
107
-
108
- | 項目 | 型 | 既定値 | 説明 |
109
- | --- | --- | --- | --- |
110
- | `render` | `"build" \| "client" \| "both"` | `"build"` | 描画する場所 |
111
- | `auto` | `boolean` | `true` | フェンスがないノートにマップを追加する |
112
- | `heading` | `boolean` | `true` | 見出しを表示する |
113
- | `headingText` | `string` | `"ExcaliBrain"` | 見出しの文字列 |
114
- | `className` | `string` | `"rb-excalibrain"` | ルートの CSS クラス |
115
- | `maxPerRegion` | `number` | `8` | 領域ごとの最大ノード数 |
116
- | `infer` | `boolean` | `true` | リンクから関係を推論する |
117
- | `siblings` | `boolean` | `true` | 親から兄弟を推論する |
118
- | `ontology` | object | — | オントロジーの部分的な上書き |
119
- | `showHidden` | `boolean` | `false` | `hidden` のノートも含める |
120
- | `width` | `number` | `720` | SVG viewBox の幅 |
121
- | `height` | `number` | `480` | SVG viewBox の高さ |
122
- | `language` | `string` | `"excalibrain"` | 対象にするフェンス言語 |
123
-
124
- ## 出力
125
-
126
- ```html
127
- <section class="rb-excalibrain" data-excalibrain
128
- data-excalibrain-render="build"
129
- data-excalibrain-center="notes/center">
130
- <h2 class="rb-excalibrain__heading">ExcaliBrain</h2>
131
- <div class="rb-excalibrain__canvas">
132
- <svg class="rb-excalibrain__svg" viewBox="0 0 720 480" role="img">…</svg>
133
- </div>
134
- </section>
135
- ```
136
-
137
- 領域は `g.rb-excalibrain__region[data-region]`、ノードは `g.rb-excalibrain__node[data-node-role][data-node-slug][data-relation-type]` で、`<a href>` が `<rect>` と `<text>` を包みます。リンクは `path.rb-excalibrain__link[data-link-role][data-relation-type]` です。
138
-
139
- ## 主なエクスポート
140
-
141
- - `excaliBrain(options?)` / `excaliBrainPlugin`: プラグインを作成する
142
- - `resolveExcaliBrainOptions(options?)`: 既定値を解決する
143
- - `buildExcaliBrainGraph(input)`: 純粋なグラフ構築
144
- - `layoutExcaliBrain(graph, options?)`: 決定的なレイアウト
145
- - `renderExcaliBrainSvg(graph, layout, options?)`: 純粋な SVG 描画
146
- - 型: `ExcaliBrainOptions`、`ExcaliBrainGraph`、`ExcaliBrainNode`、`ExcaliBrainLink`、`ExcaliBrainLayout`、`ExcaliBrainRole`、`ExcaliBrainRenderMode` ほか
147
-
148
- ## 関連資料
149
-
150
- - [プラグインシステム](../../../docs/ja/plugin-system.md)
1
+ # @riebeckite/plugin-excalibrain
2
+
3
+ ノートの関係を構造化して表示するプラグインです。[ExcaliBrain](https://github.com/zsviczian/excalibrain)(Zsolt Viczián)の考え方をモデルにしています。
4
+
5
+ [English](./README.md)
6
+
7
+ ## 概要
8
+
9
+ `excaliBrain()` はノートごとに 7 つの領域を持つマップを描画します。
10
+
11
+ | 領域 | 位置 | ロール |
12
+ | --- | --- | --- |
13
+ | Parents | 上 | `parent` |
14
+ | Children | 下 | `child` |
15
+ | Left friends | 左 | `leftFriend` |
16
+ | Right friends | 右 | `rightFriend` |
17
+ | Previous | 左端 | `previous` |
18
+ | Next | 右端 | `next` |
19
+ | Siblings | 周辺 | `sibling` |
20
+
21
+ 関係は ExcaliBrain のオントロジーに従い、YAML フロントマターと本文中の Dataview インラインフィールドから取得します。明示されていない関係は、コンテンツグラフから推論します。
22
+
23
+ ## 設定する
24
+
25
+ ```ts
26
+ import { defineConfig } from "@riebeckite/core";
27
+ import { excaliBrain } from "@riebeckite/plugin-excalibrain";
28
+
29
+ export default defineConfig({
30
+ // ...
31
+ plugins: [
32
+ excaliBrain({
33
+ render: "build",
34
+ }),
35
+ ],
36
+ });
37
+ ```
38
+
39
+ このプラグインは `order: -10` で実行されます。
40
+
41
+ ## 関係の書き方
42
+
43
+ 明示した関係は推論より優先されます。
44
+
45
+ ### YAML フロントマター
46
+
47
+ ```md
48
+ ---
49
+ title: ExcaliBrain Center
50
+ parent: "[[excalibrain-parent]]"
51
+ children: ["[[excalibrain-child-a]]", "[[excalibrain-child-b]]"]
52
+ ---
53
+ ```
54
+
55
+ ### Dataview インラインフィールド
56
+
57
+ ```md
58
+ children:: [[excalibrain-child]]
59
+
60
+ related:: [[note-a]] and [[note-b]] are similar
61
+ ```
62
+
63
+ フィールドは単独行でも、`[field:: [[target]]]` のように角括弧で囲んでも認識します。
64
+
65
+ ### オントロジー
66
+
67
+ フィールド名は大文字小文字を区別せず、空白はハイフンに正規化して照合します。既定のオントロジーは次のとおりです。
68
+
69
+ | ロール | フィールド名 |
70
+ | --- | --- |
71
+ | `parents` | `parent`, `parents`, `up`, `u`, `north`, `origin`, `inception` |
72
+ | `children` | `children`, `child`, `down`, `d`, `south`, `leads to`, `contributes to` |
73
+ | `leftFriends` | `friends`, `friend`, `similar`, `supports`, `alternatives`, `advantages` |
74
+ | `rightFriends` | `opposes`, `disadvantages`, `missing`, `cons` |
75
+ | `previous` | `previous`, `prev`, `west`, `w`, `before` |
76
+ | `next` | `next`, `n`, `east`, `e`, `after` |
77
+ | `hidden` | `hidden` |
78
+
79
+ `ontology` オプションは既定のオントロジーを拡張します。各ロールのフィールド名は、そのロールの既定値を置き換えるのではなく末尾に追加されます。既存のフィールドを別のロールに追加することもできますが、正規の順序(`parents`、`children`、`leftFriends`、`rightFriends`、`previous`、`next`、`hidden`)で先に現れるロールが優先されます。
80
+
81
+ ## 推論
82
+
83
+ `infer` が有効な場合(既定)、次のように推論します。
84
+
85
+ - このノートから相手へのリンクは `child`
86
+ - 相手からこのノートへのバックリンクは `parent`
87
+ - 相互リンクは `leftFriend`
88
+
89
+ `siblings` が有効な場合(既定)、親ノートの他の子ノートを `sibling` として追加します。兄弟の推論には `infer` も必要で、`infer: false` にすると無効になります。リンク先はコンテンツマニフェストから解決し、解決できない場合は元のリンクテキストをラベルにした仮想ノード(`data-node-virtual="true"`)にします。
90
+
91
+ ## 描画
92
+
93
+ `render` で描画する場所を選びます。
94
+
95
+ | モード | 動作 |
96
+ | --- | --- |
97
+ | `"build"`(既定) | ビルド時に SVG を生成し、記事に埋め込みます |
98
+ | `"client"` | `div.rb-excalibrain__canvas` にグラフとレイアウトのペイロードをエスケープして持ち、`initExcaliBrain()` がブラウザで SVG を生成します |
99
+ | `"both"` | 埋め込み SVG とクライアント側の描画を併用します(プログレッシブエンハンスメント) |
100
+
101
+ ### 差し込み方
102
+
103
+ - ` ```excalibrain ` フェンスがある場合は、そのプレースホルダーをマップに置き換えます。
104
+ - フェンスがなく、`auto` が有効で関係が 1 つ以上ある場合は、記事 HTML の末尾にマップのセクションを追加します(マニフェストのエントリとキャッシュ済みの記事 HTML の両方を更新します)。
105
+
106
+ `heading` と `headingText` は任意の `<h2>` を制御します。
107
+
108
+ ## オプション
109
+
110
+ | 項目 | 型 | 既定値 | 説明 |
111
+ | --- | --- | --- | --- |
112
+ | `render` | `"build" \| "client" \| "both"` | `"build"` | 描画する場所 |
113
+ | `auto` | `boolean` | `true` | フェンスがないノートにマップを追加する |
114
+ | `heading` | `boolean` | `true` | 見出しを表示する |
115
+ | `headingText` | `string` | `"ExcaliBrain"` | 見出しの文字列 |
116
+ | `className` | `string` | `"rb-excalibrain"` | ルートの CSS クラス |
117
+ | `maxPerRegion` | `number` | `8` | 領域ごとの最大ノード数 |
118
+ | `infer` | `boolean` | `true` | リンクから関係を推論する |
119
+ | `siblings` | `boolean` | `true` | 親から兄弟を推論する(`infer` が必要) |
120
+ | `ontology` | object | — | ロールごとに末尾追加するオントロジーのフィールド名 |
121
+ | `showHidden` | `boolean` | `false` | `hidden` のノートも含める |
122
+ | `width` | `number` | `720` | SVG viewBox の幅 |
123
+ | `height` | `number` | `480` | SVG viewBox の高さ |
124
+ | `language` | `string` | `"excalibrain"` | 対象にするフェンス言語 |
125
+
126
+ ## 出力
127
+
128
+ ```html
129
+ <section class="rb-excalibrain" data-excalibrain
130
+ data-excalibrain-render="build"
131
+ data-excalibrain-center="notes/center">
132
+ <h2 class="rb-excalibrain__heading">ExcaliBrain</h2>
133
+ <div class="rb-excalibrain__canvas">
134
+ <svg class="rb-excalibrain__svg" viewBox="0 0 720 480" role="img">…</svg>
135
+ </div>
136
+ </section>
137
+ ```
138
+
139
+ 領域は `g.rb-excalibrain__region[data-region]`、ノードは `g.rb-excalibrain__node[data-node-role][data-node-slug][data-relation-type]` で、`<a href>` が `<rect>` と `<text>` を包みます。リンクは `path.rb-excalibrain__link[data-link-role][data-relation-type]` です。
140
+
141
+ ## 主なエクスポート
142
+
143
+ - `excaliBrain(options?)` / `excaliBrainPlugin`: プラグインを作成する
144
+ - `resolveExcaliBrainOptions(options?)`: 既定値を解決する
145
+ - `buildExcaliBrainGraph(input)`: 純粋なグラフ構築
146
+ - `layoutExcaliBrain(graph, options?)`: 決定的なレイアウト
147
+ - `renderExcaliBrainSvg(graph, layout, options?)`: 純粋な SVG 描画
148
+ - 型: `ExcaliBrainOptions`、`ExcaliBrainGraph`、`ExcaliBrainNode`、`ExcaliBrainLink`、`ExcaliBrainLayout`、`ExcaliBrainRole`、`ExcaliBrainRenderMode` ほか
149
+
150
+ ## 関連資料
151
+
152
+ - [プラグインシステム](../../../docs/ja/plugin-system.md)
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type { ExcaliBrainOptions } from "./src/types.js";
2
2
  export { buildExcaliBrainGraph } from "./src/graph.js";
3
3
  export { layoutExcaliBrain } from "./src/layout.js";
4
- export { renderExcaliBrainSection, renderExcaliBrainSvg, } from "./src/render.js";
5
- export { resolveExcaliBrainOptions, validateExcaliBrainOptions, } from "./src/options.js";
6
- export type { ResolvedExcaliBrainOptions } from "./src/options.js";
7
- export { collectDefinedRelations, DEFAULT_ONTOLOGY, isNoteHidden, normalizeFieldName, resolveOntology, } from "./src/ontology.js";
8
4
  export type { DefinedRelation, ResolvedOntology, } from "./src/ontology.js";
5
+ export { collectDefinedRelations, DEFAULT_ONTOLOGY, isNoteHidden, normalizeFieldName, resolveOntology, } from "./src/ontology.js";
6
+ export type { ResolvedExcaliBrainOptions } from "./src/options.js";
7
+ export { resolveExcaliBrainOptions, validateExcaliBrainOptions, } from "./src/options.js";
8
+ export { renderExcaliBrainSection, renderExcaliBrainSvg, } from "./src/render.js";
9
9
  export type { ExcaliBrainBuildInput, ExcaliBrainClientOptions, ExcaliBrainGraph, ExcaliBrainLayout, ExcaliBrainLink, ExcaliBrainNode, ExcaliBrainNodeRole, ExcaliBrainOntology, ExcaliBrainOptions, ExcaliBrainPositionedLink, ExcaliBrainPositionedNode, ExcaliBrainRegion, ExcaliBrainRelationType, ExcaliBrainRenderMode, ExcaliBrainRole, } from "./src/types.js";
10
10
  export declare function excaliBrain(options?: ExcaliBrainOptions): import("@riebeckite/core").RiebeckitePlugin<ExcaliBrainOptions>;
11
11
  export declare const excaliBrainPlugin: typeof excaliBrain;
package/dist/index.js CHANGED
@@ -53,9 +53,14 @@ function normalizeFieldName(value) {
53
53
  }
54
54
  function resolveOntology(overrides = {}) {
55
55
  const merged = {
56
- ...DEFAULT_ONTOLOGY,
57
- ...overrides
56
+ ...DEFAULT_ONTOLOGY
58
57
  };
58
+ for (const role of FIELD_ROLE_ORDER) {
59
+ const extra = overrides[role];
60
+ if (extra && extra.length > 0) {
61
+ merged[role] = [...DEFAULT_ONTOLOGY[role], ...extra];
62
+ }
63
+ }
59
64
  const fieldRole = /* @__PURE__ */ new Map();
60
65
  for (const role of FIELD_ROLE_ORDER) {
61
66
  for (const field of merged[role] ?? []) {
@@ -171,7 +176,13 @@ function validateExcaliBrainOptions(options) {
171
176
  message: 'Expected "build", "client", or "both".'
172
177
  });
173
178
  }
174
- for (const key of ["auto", "heading", "infer", "siblings", "showHidden"]) {
179
+ for (const key of [
180
+ "auto",
181
+ "heading",
182
+ "infer",
183
+ "siblings",
184
+ "showHidden"
185
+ ]) {
175
186
  if (options[key] !== void 0 && typeof options[key] !== "boolean") {
176
187
  issues.push({ path: key, message: "Expected a boolean." });
177
188
  }
@@ -259,10 +270,7 @@ function buildExcaliBrainGraph(input) {
259
270
  })) {
260
271
  add(relation.target, relation.role, "defined");
261
272
  }
262
- const outgoing = noteLinkSlugs(
263
- manifest.outgoingLinks.get(slug) ?? [],
264
- slug
265
- );
273
+ const outgoing = noteLinkSlugs(manifest.outgoingLinks.get(slug) ?? [], slug);
266
274
  const incoming = unique(
267
275
  (manifest.incomingLinks.get(slug) ?? []).filter(
268
276
  (candidate) => candidate !== slug
@@ -280,7 +288,7 @@ function buildExcaliBrainGraph(input) {
280
288
  }
281
289
  for (const target of mutual) add(target, "leftFriend", "inferred");
282
290
  }
283
- if (options.siblings) {
291
+ if (options.infer && options.siblings) {
284
292
  const parents = [...relations.values()].filter(
285
293
  (relation) => relation.role === "parent"
286
294
  );
@@ -297,14 +305,12 @@ function buildExcaliBrainGraph(input) {
297
305
  }
298
306
  }
299
307
  const nodes = [...relations.values()].map((relation) => relation.node);
300
- const links = [...relations.values()].map(
301
- (relation) => ({
302
- from: slug,
303
- to: relation.node.id,
304
- role: relation.role,
305
- relationType: relation.relationType
306
- })
307
- );
308
+ const links = [...relations.values()].map((relation) => ({
309
+ from: slug,
310
+ to: relation.node.id,
311
+ role: relation.role,
312
+ relationType: relation.relationType
313
+ }));
308
314
  return { center, nodes, links };
309
315
  }
310
316
  function resolveNode(target, selfSlug, manifest) {
@@ -451,9 +457,7 @@ function layoutExcaliBrain(graph, options = {}) {
451
457
  const radius = anchor.radius === "far" ? farRadius : nearRadius;
452
458
  group.forEach((node, index) => {
453
459
  const angle = spreadAngle(anchor.angle, index, group.length);
454
- positioned.push(
455
- positionNode(node, angle, radius, cx, cy, width, height)
456
- );
460
+ positioned.push(positionNode(node, angle, radius, cx, cy, width, height));
457
461
  });
458
462
  }
459
463
  const ids = new Set(positioned.map((node) => node.id));
@@ -562,6 +566,52 @@ function replaceExcaliBrainPlaceholders(html, replacement) {
562
566
  return html.replace(createExcaliBrainPlaceholderPattern(), replacement);
563
567
  }
564
568
 
569
+ // src/rehype.ts
570
+ function rehypeExcaliBrain(options = {}) {
571
+ const language = options.language ?? "excalibrain";
572
+ return (tree) => {
573
+ replaceBlocks(tree, language);
574
+ };
575
+ }
576
+ function replaceBlocks(node, language) {
577
+ const children = getChildren(node);
578
+ if (!children) return;
579
+ for (let index = 0; index < children.length; index += 1) {
580
+ const child = children[index];
581
+ if (child === void 0) continue;
582
+ if (isExcaliBrainBlock(child, language)) {
583
+ children[index] = {
584
+ type: "raw",
585
+ value: createExcaliBrainPlaceholder()
586
+ };
587
+ continue;
588
+ }
589
+ replaceBlocks(child, language);
590
+ }
591
+ }
592
+ function isExcaliBrainBlock(node, language) {
593
+ const element = asElement(node);
594
+ if (element?.tagName !== "pre") return false;
595
+ const code = getChildren(element)?.find(
596
+ (child) => asElement(child)?.tagName === "code"
597
+ );
598
+ if (!code) return false;
599
+ return classList(code).includes(`language-${language}`);
600
+ }
601
+ function asElement(node) {
602
+ return node.type === "element" ? node : null;
603
+ }
604
+ function getChildren(node) {
605
+ const children = node.children;
606
+ return Array.isArray(children) ? children : null;
607
+ }
608
+ function classList(node) {
609
+ const value = node.properties?.className;
610
+ if (Array.isArray(value)) return value.map(String);
611
+ if (typeof value === "string") return value.split(/\s+/);
612
+ return [];
613
+ }
614
+
565
615
  // src/render.ts
566
616
  var ROLE_ATTRIBUTE = {
567
617
  parent: "parent",
@@ -652,52 +702,6 @@ function escapeAttribute(value) {
652
702
  return escapeHtml(value).replace(/"/g, "&quot;").replace(/'/g, "&#39;");
653
703
  }
654
704
 
655
- // src/rehype.ts
656
- function rehypeExcaliBrain(options = {}) {
657
- const language = options.language ?? "excalibrain";
658
- return (tree) => {
659
- replaceBlocks(tree, language);
660
- };
661
- }
662
- function replaceBlocks(node, language) {
663
- const children = getChildren(node);
664
- if (!children) return;
665
- for (let index = 0; index < children.length; index += 1) {
666
- const child = children[index];
667
- if (child === void 0) continue;
668
- if (isExcaliBrainBlock(child, language)) {
669
- children[index] = {
670
- type: "raw",
671
- value: createExcaliBrainPlaceholder()
672
- };
673
- continue;
674
- }
675
- replaceBlocks(child, language);
676
- }
677
- }
678
- function isExcaliBrainBlock(node, language) {
679
- const element = asElement(node);
680
- if (element?.tagName !== "pre") return false;
681
- const code = getChildren(element)?.find(
682
- (child) => asElement(child)?.tagName === "code"
683
- );
684
- if (!code) return false;
685
- return classList(code).includes(`language-${language}`);
686
- }
687
- function asElement(node) {
688
- return node.type === "element" ? node : null;
689
- }
690
- function getChildren(node) {
691
- const children = node.children;
692
- return Array.isArray(children) ? children : null;
693
- }
694
- function classList(node) {
695
- const value = node.properties?.className;
696
- if (Array.isArray(value)) return value.map(String);
697
- if (typeof value === "string") return value.split(/\s+/);
698
- return [];
699
- }
700
-
701
705
  // index.ts
702
706
  var SECTION_ATTRIBUTE = "data-excalibrain";
703
707
  function createExcaliBrainRuntime(options) {
@@ -1,4 +1,4 @@
1
- import type { ExcaliBrainOntology, ExcaliBrainNodeRole } from "./types.js";
1
+ import type { ExcaliBrainNodeRole, ExcaliBrainOntology } from "./types.js";
2
2
  export type ExcaliBrainFieldRole = "parents" | "children" | "leftFriends" | "rightFriends" | "previous" | "next" | "hidden";
3
3
  /** ExcaliBrain's default ontology field names. */
4
4
  export declare const DEFAULT_ONTOLOGY: Required<ExcaliBrainOntology>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-excalibrain",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,7 +21,11 @@
21
21
  "./style.css": "./style.css"
22
22
  },
23
23
  "dependencies": {
24
- "@riebeckite/core": "0.0.5"
24
+ "@riebeckite/core": "0.0.7"
25
+ },
26
+ "devDependencies": {
27
+ "tsx": "^4.22.4",
28
+ "@riebeckite/test": "0.0.7"
25
29
  },
26
30
  "publishConfig": {
27
31
  "access": "public"
@@ -56,6 +60,7 @@
56
60
  "./style.css"
57
61
  ],
58
62
  "scripts": {
59
- "build": "node ../../../scripts/build_package.mjs"
63
+ "build": "node ../../../scripts/build_package.mjs",
64
+ "test": "node --import tsx --test \"test/*.test.ts\""
60
65
  }
61
66
  }
package/style.css CHANGED
@@ -1,94 +1,95 @@
1
- .rb-excalibrain {
2
- --rb-excalibrain-ink: var(--rb-color-ink, #000000);
3
- --rb-excalibrain-paper: var(--rb-color-paper, #ffffff);
4
- --rb-excalibrain-muted: var(--rb-color-muted, #69645c);
5
- --rb-excalibrain-accent: var(--rb-color-accent, #686868);
6
- --rb-excalibrain-rule: var(
7
- --rb-color-border,
8
- color-mix(in srgb, var(--rb-excalibrain-ink) 18%, transparent)
9
- );
10
- --rb-excalibrain-surface: color-mix(
11
- in srgb,
12
- var(--rb-excalibrain-paper) 95%,
13
- var(--rb-excalibrain-ink)
14
- );
15
-
16
- margin: 2rem 0;
17
- color: var(--rb-excalibrain-ink);
18
- }
19
-
20
- .rb-excalibrain__heading {
21
- margin: 0 0 0.5rem;
22
- font-size: 1rem;
23
- font-weight: 700;
24
- letter-spacing: 0.02em;
25
- text-transform: uppercase;
26
- }
27
-
28
- .rb-excalibrain__canvas {
29
- overflow: auto;
30
- border: 1px solid var(--rb-excalibrain-rule);
31
- background: var(--rb-excalibrain-surface);
32
- }
33
-
34
- .rb-excalibrain__svg {
35
- display: block;
36
- width: 100%;
37
- min-width: 32rem;
38
- height: auto;
39
- }
40
-
41
- .rb-excalibrain__link {
42
- fill: none;
43
- stroke: var(--rb-excalibrain-rule);
44
- stroke-width: 1.25;
45
- }
46
-
47
- .rb-excalibrain__link[data-relation-type="defined"] {
48
- stroke: var(--rb-excalibrain-accent);
49
- }
50
-
51
- .rb-excalibrain__node-box {
52
- fill: var(--rb-excalibrain-paper);
53
- stroke: var(--rb-excalibrain-rule);
54
- stroke-width: 1.25;
55
- }
56
-
57
- .rb-excalibrain__node[data-node-role="center"] .rb-excalibrain__node-box {
58
- stroke: var(--rb-excalibrain-ink);
59
- stroke-width: 2;
60
- }
61
-
62
- .rb-excalibrain__node[data-node-virtual="true"] .rb-excalibrain__node-box {
63
- fill: none;
64
- stroke-dasharray: 4 3;
65
- }
66
-
67
- .rb-excalibrain__node-label {
68
- fill: var(--rb-excalibrain-ink);
69
- font-size: 0.8125rem;
70
- }
71
-
72
- .rb-excalibrain__node-link {
73
- text-decoration: none;
74
- }
75
-
76
- .rb-excalibrain__node-link:hover .rb-excalibrain__node-box,
77
- .rb-excalibrain__node-link:focus-visible .rb-excalibrain__node-box {
78
- stroke: var(--rb-excalibrain-accent);
79
- stroke-width: 2;
80
- }
81
-
82
- .rb-excalibrain[data-excalibrain-render="client"] .rb-excalibrain__canvas:empty::before {
83
- display: block;
84
- padding: 1rem;
85
- content: "ExcaliBrain map is rendered in the browser.";
86
- color: var(--rb-excalibrain-muted);
87
- font-size: 0.8125rem;
88
- }
89
-
90
- html[data-theme="dark"] .rb-excalibrain,
91
- html.dark .rb-excalibrain {
92
- --rb-excalibrain-ink: var(--rb-color-paper, #ffffff);
93
- --rb-excalibrain-paper: var(--rb-color-ink, #000000);
94
- }
1
+ .rb-excalibrain {
2
+ --rb-excalibrain-ink: var(--rb-color-ink, #000000);
3
+ --rb-excalibrain-paper: var(--rb-color-paper, #ffffff);
4
+ --rb-excalibrain-muted: var(--rb-color-muted, #69645c);
5
+ --rb-excalibrain-accent: var(--rb-color-accent, #686868);
6
+ --rb-excalibrain-rule: var(
7
+ --rb-color-border,
8
+ color-mix(in srgb, var(--rb-excalibrain-ink) 18%, transparent)
9
+ );
10
+ --rb-excalibrain-surface: color-mix(
11
+ in srgb,
12
+ var(--rb-excalibrain-paper) 95%,
13
+ var(--rb-excalibrain-ink)
14
+ );
15
+
16
+ margin: 2rem 0;
17
+ color: var(--rb-excalibrain-ink);
18
+ }
19
+
20
+ .rb-excalibrain__heading {
21
+ margin: 0 0 0.5rem;
22
+ font-size: 1rem;
23
+ font-weight: 700;
24
+ letter-spacing: 0.02em;
25
+ text-transform: uppercase;
26
+ }
27
+
28
+ .rb-excalibrain__canvas {
29
+ overflow: auto;
30
+ border: 1px solid var(--rb-excalibrain-rule);
31
+ background: var(--rb-excalibrain-surface);
32
+ }
33
+
34
+ .rb-excalibrain__svg {
35
+ display: block;
36
+ width: 100%;
37
+ min-width: 32rem;
38
+ height: auto;
39
+ }
40
+
41
+ .rb-excalibrain__link {
42
+ fill: none;
43
+ stroke: var(--rb-excalibrain-rule);
44
+ stroke-width: 1.25;
45
+ }
46
+
47
+ .rb-excalibrain__link[data-relation-type="defined"] {
48
+ stroke: var(--rb-excalibrain-accent);
49
+ }
50
+
51
+ .rb-excalibrain__node-box {
52
+ fill: var(--rb-excalibrain-paper);
53
+ stroke: var(--rb-excalibrain-rule);
54
+ stroke-width: 1.25;
55
+ }
56
+
57
+ .rb-excalibrain__node[data-node-role="center"] .rb-excalibrain__node-box {
58
+ stroke: var(--rb-excalibrain-ink);
59
+ stroke-width: 2;
60
+ }
61
+
62
+ .rb-excalibrain__node[data-node-virtual="true"] .rb-excalibrain__node-box {
63
+ fill: none;
64
+ stroke-dasharray: 4 3;
65
+ }
66
+
67
+ .rb-excalibrain__node-label {
68
+ fill: var(--rb-excalibrain-ink);
69
+ font-size: 0.8125rem;
70
+ }
71
+
72
+ .rb-excalibrain__node-link {
73
+ text-decoration: none;
74
+ }
75
+
76
+ .rb-excalibrain__node-link:hover .rb-excalibrain__node-box,
77
+ .rb-excalibrain__node-link:focus-visible .rb-excalibrain__node-box {
78
+ stroke: var(--rb-excalibrain-accent);
79
+ stroke-width: 2;
80
+ }
81
+
82
+ .rb-excalibrain[data-excalibrain-render="client"]
83
+ .rb-excalibrain__canvas:empty::before {
84
+ display: block;
85
+ padding: 1rem;
86
+ content: "ExcaliBrain map is rendered in the browser.";
87
+ color: var(--rb-excalibrain-muted);
88
+ font-size: 0.8125rem;
89
+ }
90
+
91
+ html[data-theme="dark"] .rb-excalibrain,
92
+ html.dark .rb-excalibrain {
93
+ --rb-excalibrain-ink: var(--rb-color-paper, #ffffff);
94
+ --rb-excalibrain-paper: var(--rb-color-ink, #000000);
95
+ }