@riebeckite/plugin-excalibrain 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 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,165 @@
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)
package/README_ja.md ADDED
@@ -0,0 +1,150 @@
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)
@@ -0,0 +1,2 @@
1
+ export { initExcaliBrain } from "./src/init.js";
2
+ export type { ExcaliBrainClientOptions } from "./src/types.js";
package/dist/client.js ADDED
@@ -0,0 +1,100 @@
1
+ // src/layout.ts
2
+ var EXCALIBRAIN_REGION_ORDER = [
3
+ "parents",
4
+ "children",
5
+ "left-friends",
6
+ "right-friends",
7
+ "previous",
8
+ "next",
9
+ "siblings"
10
+ ];
11
+
12
+ // src/render.ts
13
+ var ROLE_ATTRIBUTE = {
14
+ parent: "parent",
15
+ child: "child",
16
+ leftFriend: "left-friend",
17
+ rightFriend: "right-friend",
18
+ previous: "previous",
19
+ next: "next",
20
+ sibling: "sibling",
21
+ center: "center"
22
+ };
23
+ function renderExcaliBrainSvg(graph, layout, options = {}) {
24
+ const className = options.className ?? "rb-excalibrain";
25
+ const byId = new Map(layout.nodes.map((node) => [node.id, node]));
26
+ const parts = [];
27
+ parts.push(
28
+ `<svg class="${className}__svg" viewBox="0 0 ${layout.width} ${layout.height}" role="img" aria-label="${escapeAttribute(`${graph.center.title} ExcaliBrain`)}" xmlns="http://www.w3.org/2000/svg" width="${layout.width}" height="${layout.height}">`
29
+ );
30
+ const links = layout.links.map((link) => renderLink(link, byId, className)).join("");
31
+ parts.push(`<g class="${className}__links">${links}</g>`);
32
+ for (const region of EXCALIBRAIN_REGION_ORDER) {
33
+ const regionNodes = layout.nodes.filter((node) => node.region === region);
34
+ if (regionNodes.length === 0) continue;
35
+ const nodes = regionNodes.map((node) => renderNode(node, className)).join("");
36
+ parts.push(
37
+ `<g class="${className}__region" data-region="${region}">${nodes}</g>`
38
+ );
39
+ }
40
+ const center = layout.nodes.find((node) => node.role === "center");
41
+ if (center) parts.push(renderNode(center, className));
42
+ parts.push("</svg>");
43
+ return parts.join("");
44
+ }
45
+ function renderNode(node, className) {
46
+ const box = `<rect class="${className}__node-box" x="${node.x}" y="${node.y}" width="${node.width}" height="${node.height}" rx="4" />`;
47
+ const label = `<text class="${className}__node-label" x="${round(
48
+ node.x + node.width / 2
49
+ )}" y="${round(node.y + node.height / 2)}" text-anchor="middle" dominant-baseline="middle">${escapeHtml(node.title)}</text>`;
50
+ const inner = `${box}${label}`;
51
+ const content = node.permalink ? `<a class="${className}__node-link" href="${escapeAttribute(node.permalink)}">${inner}</a>` : inner;
52
+ const attributes = [
53
+ `class="${className}__node"`,
54
+ `data-node-role="${ROLE_ATTRIBUTE[node.role]}"`,
55
+ `data-node-slug="${escapeAttribute(node.slug ?? node.title)}"`,
56
+ node.virtual ? 'data-node-virtual="true"' : "",
57
+ `data-relation-type="${node.relationType}"`
58
+ ].filter(Boolean);
59
+ return `<g ${attributes.join(" ")}>${content}</g>`;
60
+ }
61
+ function renderLink(link, byId, className) {
62
+ const from = byId.get(link.from);
63
+ const to = byId.get(link.to);
64
+ if (!from || !to) return "";
65
+ const d = `M ${round(from.x + from.width / 2)} ${round(from.y + from.height / 2)} L ${round(to.x + to.width / 2)} ${round(to.y + to.height / 2)}`;
66
+ return `<path class="${className}__link" data-link-role="${ROLE_ATTRIBUTE[link.role]}" data-relation-type="${link.relationType}" d="${d}" />`;
67
+ }
68
+ function round(value) {
69
+ return Math.round(value * 100) / 100;
70
+ }
71
+ function escapeHtml(value) {
72
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
73
+ }
74
+ function escapeAttribute(value) {
75
+ return escapeHtml(value).replace(/"/g, "&quot;").replace(/'/g, "&#39;");
76
+ }
77
+
78
+ // src/init.ts
79
+ function initExcaliBrain(options = {}) {
80
+ const canvases = document.querySelectorAll(
81
+ "[data-excalibrain-payload]"
82
+ );
83
+ for (const canvas of canvases) {
84
+ if (canvas.querySelector(".rb-excalibrain__svg")) continue;
85
+ const payload = canvas.dataset.excalibrainPayload;
86
+ if (!payload) continue;
87
+ try {
88
+ const parsed = JSON.parse(payload);
89
+ canvas.innerHTML = renderExcaliBrainSvg(parsed.graph, parsed.layout, {
90
+ className: options.className ?? parsed.className
91
+ });
92
+ canvas.removeAttribute("data-excalibrain-payload");
93
+ } catch {
94
+ canvas.dataset.excalibrainError = "true";
95
+ }
96
+ }
97
+ }
98
+ export {
99
+ initExcaliBrain
100
+ };
@@ -0,0 +1,11 @@
1
+ import type { ExcaliBrainOptions } from "./src/types.js";
2
+ export { buildExcaliBrainGraph } from "./src/graph.js";
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
+ export type { DefinedRelation, ResolvedOntology, } from "./src/ontology.js";
9
+ export type { ExcaliBrainBuildInput, ExcaliBrainClientOptions, ExcaliBrainGraph, ExcaliBrainLayout, ExcaliBrainLink, ExcaliBrainNode, ExcaliBrainNodeRole, ExcaliBrainOntology, ExcaliBrainOptions, ExcaliBrainPositionedLink, ExcaliBrainPositionedNode, ExcaliBrainRegion, ExcaliBrainRelationType, ExcaliBrainRenderMode, ExcaliBrainRole, } from "./src/types.js";
10
+ export declare function excaliBrain(options?: ExcaliBrainOptions): import("@riebeckite/core").RiebeckitePlugin<ExcaliBrainOptions>;
11
+ export declare const excaliBrainPlugin: typeof excaliBrain;