@diagrammo/dgmo 0.44.1 → 0.45.0

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/dist/block.css ADDED
@@ -0,0 +1,290 @@
1
+ /* @diagrammo/dgmo block — standard embed chrome.
2
+ * Override the [data-theme="dark"] selectors if your site uses .dark or
3
+ * another color-mode convention. */
4
+
5
+ /* === Color-mode visibility (dual-render) === */
6
+ .dgmo-dark {
7
+ display: none;
8
+ }
9
+ [data-theme="dark"] .dgmo-light {
10
+ display: none;
11
+ }
12
+ [data-theme="dark"] .dgmo-dark {
13
+ display: block;
14
+ }
15
+
16
+ /* === Diagram sizing ===
17
+ * SVGs are emitted with viewBox only (no fixed width/height). Force them to
18
+ * fill their wrapper so light and dark variants render at identical sizes. */
19
+ .dgmo-light > svg,
20
+ .dgmo-dark > svg,
21
+ .dgmo-svg > svg {
22
+ display: block;
23
+ width: 100%;
24
+ height: auto;
25
+ max-width: 100%;
26
+ }
27
+
28
+ /* === Toolbar ===
29
+ * The diagram is the star: the toolbar is a slim reserved row below the SVG
30
+ * (height always in flow — no layout shift) that stays fully transparent
31
+ * until the block is hovered or focused, or the source panel is open. It is
32
+ * the <summary> of the source <details>, so toggling works without any JS.
33
+ * No text labels, no disclosure triangle — three wordless icon buttons. */
34
+ .dgmo-source-wrap {
35
+ margin: 0;
36
+ }
37
+ .dgmo-toolbar {
38
+ display: flex;
39
+ align-items: center;
40
+ justify-content: flex-end;
41
+ gap: 0.25em;
42
+ min-height: 1.9em;
43
+ padding: 0.15em 0;
44
+ opacity: 0;
45
+ transition: opacity 0.15s ease;
46
+ cursor: pointer;
47
+ list-style: none;
48
+ user-select: none;
49
+ color: rgba(127, 127, 127, 0.9);
50
+ }
51
+ .dgmo-toolbar::-webkit-details-marker {
52
+ display: none;
53
+ }
54
+ /* Reveal is keyed to the diagram IMAGE (the svg wrappers), not the whole
55
+ * figure — hovering the open code panel keeps the page quiet. The toolbar's
56
+ * own :hover keeps it alive while the pointer travels down from the image
57
+ * (they're adjacent, so there's no dead gap). focus-within covers keyboard
58
+ * and touch-tap. */
59
+ .dgmo-light:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
60
+ .dgmo-dark:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
61
+ .dgmo-svg:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
62
+ .dgmo-toolbar:hover,
63
+ .dgmo:focus-within .dgmo-toolbar {
64
+ opacity: 1;
65
+ }
66
+ /* Touch devices have no hover: keep the icons faintly visible so the
67
+ * affordance is discoverable at all. */
68
+ @media (hover: none) {
69
+ .dgmo-toolbar {
70
+ opacity: 0.5;
71
+ }
72
+ }
73
+
74
+ .dgmo-toggle,
75
+ .dgmo-toolbar-btn {
76
+ display: inline-flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ width: 1.9em;
80
+ height: 1.9em;
81
+ border-radius: 0.35em;
82
+ background: none;
83
+ border: 0;
84
+ padding: 0;
85
+ color: inherit;
86
+ cursor: pointer;
87
+ opacity: 0.75;
88
+ transition:
89
+ opacity 0.15s ease,
90
+ background-color 0.15s ease;
91
+ }
92
+ .dgmo-toggle:hover,
93
+ .dgmo-toolbar-btn:hover {
94
+ opacity: 1;
95
+ background: rgba(127, 127, 127, 0.12);
96
+ }
97
+ .dgmo-toggle svg,
98
+ .dgmo-toolbar-btn svg {
99
+ width: 1em;
100
+ height: 1em;
101
+ }
102
+ /* Active state while the source panel is open. */
103
+ .dgmo-source-wrap[open] > .dgmo-toolbar .dgmo-toggle {
104
+ opacity: 1;
105
+ background: rgba(127, 127, 127, 0.15);
106
+ }
107
+ .dgmo-copy--success {
108
+ color: #5cba7a;
109
+ opacity: 1;
110
+ }
111
+
112
+ /* === Open state: frame the whole block ===
113
+ * When the source panel is open, diagram + toolbar + code get one shared
114
+ * border so the code visibly belongs to the chart above it, not to the
115
+ * surrounding prose. Closed blocks stay frameless. */
116
+ .dgmo:has(> .dgmo-source-wrap[open]) {
117
+ border: 1px solid rgba(127, 127, 127, 0.3);
118
+ border-radius: 0.6em;
119
+ padding: 0.75em 0.75em 0.5em;
120
+ }
121
+
122
+ /* === Source panel (hidden until toggled) === */
123
+ .dgmo-source-inner {
124
+ border-top: 1px solid rgba(127, 127, 127, 0.25);
125
+ background: rgba(127, 127, 127, 0.06);
126
+ overflow: hidden;
127
+ margin: 0 -0.75em -0.5em;
128
+ border-radius: 0 0 0.6em 0.6em;
129
+ }
130
+ .dgmo-pre {
131
+ white-space: pre;
132
+ overflow-x: auto;
133
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
134
+ font-size: 0.85em;
135
+ line-height: 1.5;
136
+ margin: 0;
137
+ padding: 1em;
138
+ }
139
+ .dgmo-code {
140
+ display: block;
141
+ }
142
+
143
+ /* === Error card === */
144
+ .dgmo--error {
145
+ border: 1px solid rgba(220, 80, 80, 0.5);
146
+ border-radius: 0.5em;
147
+ padding: 0.75em 1em;
148
+ }
149
+ .dgmo--error pre {
150
+ white-space: pre;
151
+ overflow-x: auto;
152
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
153
+ font-size: 0.85em;
154
+ margin: 0.5em 0 0;
155
+ }
156
+
157
+ /* === Source highlight roles ===
158
+ * Light values mirror LIGHT_ROLE_STYLES; dark overrides mirror
159
+ * NORD_ROLE_STYLES. Guarded by the parity test in tests/block.test.ts. */
160
+ .dgmo-tok-keyword {
161
+ color: #3b6ea5;
162
+ font-weight: bold;
163
+ }
164
+ .dgmo-tok-controlKeyword {
165
+ color: #7d5ba6;
166
+ font-weight: bold;
167
+ }
168
+ .dgmo-tok-definitionKeyword {
169
+ color: #2f5a86;
170
+ font-weight: bold;
171
+ }
172
+ .dgmo-tok-modifier {
173
+ color: #7d5ba6;
174
+ }
175
+ .dgmo-tok-chartType {
176
+ color: #b8691f;
177
+ font-weight: bold;
178
+ }
179
+ .dgmo-tok-operator {
180
+ color: #c0504d;
181
+ font-weight: bold;
182
+ }
183
+ .dgmo-tok-number {
184
+ color: #7d5ba6;
185
+ }
186
+ .dgmo-tok-comment {
187
+ color: #677483;
188
+ font-style: italic;
189
+ }
190
+ .dgmo-tok-heading {
191
+ color: #b8691f;
192
+ font-weight: bold;
193
+ }
194
+ .dgmo-tok-bracket {
195
+ color: #5b6672;
196
+ }
197
+ .dgmo-tok-separator {
198
+ color: #2d7268;
199
+ }
200
+ .dgmo-tok-deprecatedSyntax {
201
+ color: #c0504d;
202
+ text-decoration: line-through;
203
+ }
204
+ .dgmo-tok-url {
205
+ color: #3b6ea5;
206
+ text-decoration: underline;
207
+ }
208
+ .dgmo-tok-colorAnnotation {
209
+ color: #b8691f;
210
+ font-style: italic;
211
+ }
212
+ .dgmo-tok-punctuation {
213
+ color: #677483;
214
+ }
215
+ .dgmo-tok-propertyName {
216
+ color: #2d7268;
217
+ }
218
+ .dgmo-tok-string {
219
+ color: #3f7a3b;
220
+ }
221
+ .dgmo-tok-noteContent {
222
+ color: #677483;
223
+ font-style: italic;
224
+ }
225
+
226
+ [data-theme="dark"] .dgmo-tok-keyword {
227
+ color: #81a1c1;
228
+ font-weight: bold;
229
+ }
230
+ [data-theme="dark"] .dgmo-tok-controlKeyword {
231
+ color: #b48ead;
232
+ font-weight: bold;
233
+ }
234
+ [data-theme="dark"] .dgmo-tok-definitionKeyword {
235
+ color: #5e81ac;
236
+ font-weight: bold;
237
+ }
238
+ [data-theme="dark"] .dgmo-tok-modifier {
239
+ color: #b48ead;
240
+ }
241
+ [data-theme="dark"] .dgmo-tok-chartType {
242
+ color: #d08770;
243
+ font-weight: bold;
244
+ }
245
+ [data-theme="dark"] .dgmo-tok-operator {
246
+ color: #bf616a;
247
+ font-weight: bold;
248
+ }
249
+ [data-theme="dark"] .dgmo-tok-number {
250
+ color: #b48ead;
251
+ }
252
+ [data-theme="dark"] .dgmo-tok-comment {
253
+ color: #616e88;
254
+ font-style: italic;
255
+ }
256
+ [data-theme="dark"] .dgmo-tok-heading {
257
+ color: #d08770;
258
+ font-weight: bold;
259
+ }
260
+ [data-theme="dark"] .dgmo-tok-bracket {
261
+ color: #5e81ac;
262
+ }
263
+ [data-theme="dark"] .dgmo-tok-separator {
264
+ color: #88c0d0;
265
+ }
266
+ [data-theme="dark"] .dgmo-tok-deprecatedSyntax {
267
+ color: #bf616a;
268
+ text-decoration: line-through;
269
+ }
270
+ [data-theme="dark"] .dgmo-tok-url {
271
+ color: #88c0d0;
272
+ text-decoration: underline;
273
+ }
274
+ [data-theme="dark"] .dgmo-tok-colorAnnotation {
275
+ color: #d08770;
276
+ font-style: italic;
277
+ }
278
+ [data-theme="dark"] .dgmo-tok-punctuation {
279
+ color: #616e88;
280
+ }
281
+ [data-theme="dark"] .dgmo-tok-propertyName {
282
+ color: #88c0d0;
283
+ }
284
+ [data-theme="dark"] .dgmo-tok-string {
285
+ color: #a3be8c;
286
+ }
287
+ [data-theme="dark"] .dgmo-tok-noteContent {
288
+ color: #616e88;
289
+ font-style: italic;
290
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Canonical stylesheet for the standard DGMO embed block (BL-114).
3
+ *
4
+ * Shipped two ways: `dist/block.css` (extracted at build time by
5
+ * tsup.config.ts, same regex mechanism as auto.css) for `<link>`/import
6
+ * consumers, and the `BLOCK_CSS` string export for embedders that inject a
7
+ * `<style>` tag.
8
+ *
9
+ * Dark mode keys off `[data-theme="dark"]`. Hosts with a different signal
10
+ * (`html.dark`, `body.theme-dark`) rewrite the selector at their build step —
11
+ * fumadocs-dgmo/nextra-dgmo's build-css.mjs is the reference adapter.
12
+ *
13
+ * The `.dgmo-tok-*` role colors mirror LIGHT_ROLE_STYLES (light) and
14
+ * NORD_ROLE_STYLES (dark) from editor/highlight-api.ts. A parity test
15
+ * (tests/block.test.ts) guards against drift — update both when either
16
+ * changes.
17
+ *
18
+ * IMPORTANT: keep this a single pure template literal — the build extracts it
19
+ * with a regex, so no interpolation or computed values.
20
+ */
21
+ declare const BLOCK_CSS: string;
22
+
23
+ /**
24
+ * Standard DGMO embed block (BL-114) — the ONE canonical
25
+ * "diagram + source chrome" HTML builder shared by every embed surface:
26
+ * remark-dgmo (and through it the astro/docusaurus/fumadocs/nextra/vitepress
27
+ * wrappers), the `/auto` script-tag drop-in, `<dgmo-diagram>`, dgmo-mcp HTML
28
+ * reports, the marketing site, and the Obsidian plugin.
29
+ *
30
+ * Chrome contract (user-approved 2026-07-05): the diagram is the star. A slim
31
+ * icon toolbar sits in a reserved row below the SVG, invisible until the
32
+ * block is hovered/focused or the source is open. Three wordless icon
33
+ * buttons — `</>` toggles the hidden source panel, copy, open-in-editor. No
34
+ * disclosure triangle, no text labels. The toolbar IS the <summary> of a
35
+ * native <details>, so show/hide works with zero JavaScript; copy needs a
36
+ * small delegated click handler (remark-dgmo's `bindDgmo` is the reference).
37
+ *
38
+ * Markup vocabulary: `figure.dgmo` (`--diagram`/`--showcase`/`--error`),
39
+ * `.dgmo-light`/`.dgmo-dark` (dual color-mode) or `.dgmo-svg` (single),
40
+ * `details.dgmo-source-wrap > summary.dgmo-toolbar`, `.dgmo-source-inner`,
41
+ * `pre.dgmo-pre > span.dgmo-code` with `.dgmo-tok-<role>` token spans. While
42
+ * the source is open the wrapper gets one shared frame (`:has()` rule) so
43
+ * diagram + code read as a single unit. No visible caption — `title` becomes
44
+ * the wrapper's aria-label. Styles ship as `BLOCK_CSS` / `dist/block.css`.
45
+ */
46
+
47
+ /** Default hosted editor used by "Open in editor" links. */
48
+ declare const EDITOR_BASE_URL = "https://online.diagrammo.app";
49
+ type BlockMode = 'diagram' | 'showcase';
50
+ /**
51
+ * Color-mode strategy for the emitted SVG(s).
52
+ * - `auto` — render twice (light + dark) and let CSS flip visibility.
53
+ * - `light` / `dark` / `transparent` — single render with that theme.
54
+ */
55
+ type BlockColorMode = 'auto' | 'light' | 'dark' | 'transparent';
56
+ interface DgmoBlockOptions {
57
+ /** `diagram` (default): SVG only. `showcase`: SVG + source chrome. */
58
+ mode?: BlockMode;
59
+ /** Palette name. Default `slate`; unknown names warn + fall back. */
60
+ palette?: string;
61
+ /** Default `auto` (dual light/dark render). */
62
+ colorMode?: BlockColorMode;
63
+ /** Default: true in showcase mode, false in diagram mode. */
64
+ showSource?: boolean;
65
+ /** Default: true in showcase mode, false in diagram mode. */
66
+ showCopy?: boolean;
67
+ /** Default: true in showcase mode, false in diagram mode. */
68
+ showOpenInEditor?: boolean;
69
+ /** Base URL for the open-in-editor link. Default: online.diagrammo.app. */
70
+ editorBaseUrl?: string;
71
+ /** Outer wrapper element. Default `figure`. */
72
+ wrapper?: 'figure' | 'div';
73
+ /** Base class for the wrapper (styling hook). Default `dgmo`. */
74
+ className?: string;
75
+ /** Extra classes appended to every emitted wrapper (compat shims). */
76
+ legacyClassNames?: string[];
77
+ /**
78
+ * Accessible name for the block (`aria-label` on the wrapper). NOT rendered
79
+ * visually — the chart's visible title belongs in the DGMO source itself.
80
+ */
81
+ title?: string;
82
+ /** Receives palette-fallback warnings. Default: console.warn. */
83
+ onWarn?: (message: string) => void;
84
+ }
85
+ interface DgmoBlockResult {
86
+ html: string;
87
+ diagnostics: Array<{
88
+ message: string;
89
+ line?: number;
90
+ severity?: string;
91
+ }>;
92
+ }
93
+ /**
94
+ * Render one ```dgmo source block to the standard embed HTML. Async because
95
+ * it runs the full dgmo render pipeline (once per color mode).
96
+ *
97
+ * Render errors are NOT caught here — callers decide between throwing,
98
+ * `errorBlockHtml()`, or their own fallback.
99
+ */
100
+ declare function renderDgmoBlock(source: string, options?: DgmoBlockOptions): Promise<DgmoBlockResult>;
101
+ /**
102
+ * Assemble the standard block around already-rendered SVG markup. Exposed for
103
+ * surfaces that render through their own pipeline (e.g. dgmo-mcp's
104
+ * renderPipeline) but must emit the canonical chrome. `svgsHtml` must be the
105
+ * `.dgmo-light`+`.dgmo-dark` (or `.dgmo-svg`) wrapper divs.
106
+ */
107
+ declare function buildDgmoBlockHtml(source: string, svgsHtml: string, options?: DgmoBlockOptions): string;
108
+ /**
109
+ * Standard error card for a block that failed to parse/render. Same shape on
110
+ * every surface: `.dgmo--error` with `role="alert"`, message + offending
111
+ * source.
112
+ */
113
+ declare function errorBlockHtml(err: unknown, source: string, options?: Pick<DgmoBlockOptions, 'className' | 'legacyClassNames'>): string;
114
+
115
+ export { BLOCK_CSS, type BlockColorMode, type BlockMode, type DgmoBlockOptions, type DgmoBlockResult, EDITOR_BASE_URL, buildDgmoBlockHtml, errorBlockHtml, renderDgmoBlock };
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Canonical stylesheet for the standard DGMO embed block (BL-114).
3
+ *
4
+ * Shipped two ways: `dist/block.css` (extracted at build time by
5
+ * tsup.config.ts, same regex mechanism as auto.css) for `<link>`/import
6
+ * consumers, and the `BLOCK_CSS` string export for embedders that inject a
7
+ * `<style>` tag.
8
+ *
9
+ * Dark mode keys off `[data-theme="dark"]`. Hosts with a different signal
10
+ * (`html.dark`, `body.theme-dark`) rewrite the selector at their build step —
11
+ * fumadocs-dgmo/nextra-dgmo's build-css.mjs is the reference adapter.
12
+ *
13
+ * The `.dgmo-tok-*` role colors mirror LIGHT_ROLE_STYLES (light) and
14
+ * NORD_ROLE_STYLES (dark) from editor/highlight-api.ts. A parity test
15
+ * (tests/block.test.ts) guards against drift — update both when either
16
+ * changes.
17
+ *
18
+ * IMPORTANT: keep this a single pure template literal — the build extracts it
19
+ * with a regex, so no interpolation or computed values.
20
+ */
21
+ declare const BLOCK_CSS: string;
22
+
23
+ /**
24
+ * Standard DGMO embed block (BL-114) — the ONE canonical
25
+ * "diagram + source chrome" HTML builder shared by every embed surface:
26
+ * remark-dgmo (and through it the astro/docusaurus/fumadocs/nextra/vitepress
27
+ * wrappers), the `/auto` script-tag drop-in, `<dgmo-diagram>`, dgmo-mcp HTML
28
+ * reports, the marketing site, and the Obsidian plugin.
29
+ *
30
+ * Chrome contract (user-approved 2026-07-05): the diagram is the star. A slim
31
+ * icon toolbar sits in a reserved row below the SVG, invisible until the
32
+ * block is hovered/focused or the source is open. Three wordless icon
33
+ * buttons — `</>` toggles the hidden source panel, copy, open-in-editor. No
34
+ * disclosure triangle, no text labels. The toolbar IS the <summary> of a
35
+ * native <details>, so show/hide works with zero JavaScript; copy needs a
36
+ * small delegated click handler (remark-dgmo's `bindDgmo` is the reference).
37
+ *
38
+ * Markup vocabulary: `figure.dgmo` (`--diagram`/`--showcase`/`--error`),
39
+ * `.dgmo-light`/`.dgmo-dark` (dual color-mode) or `.dgmo-svg` (single),
40
+ * `details.dgmo-source-wrap > summary.dgmo-toolbar`, `.dgmo-source-inner`,
41
+ * `pre.dgmo-pre > span.dgmo-code` with `.dgmo-tok-<role>` token spans. While
42
+ * the source is open the wrapper gets one shared frame (`:has()` rule) so
43
+ * diagram + code read as a single unit. No visible caption — `title` becomes
44
+ * the wrapper's aria-label. Styles ship as `BLOCK_CSS` / `dist/block.css`.
45
+ */
46
+
47
+ /** Default hosted editor used by "Open in editor" links. */
48
+ declare const EDITOR_BASE_URL = "https://online.diagrammo.app";
49
+ type BlockMode = 'diagram' | 'showcase';
50
+ /**
51
+ * Color-mode strategy for the emitted SVG(s).
52
+ * - `auto` — render twice (light + dark) and let CSS flip visibility.
53
+ * - `light` / `dark` / `transparent` — single render with that theme.
54
+ */
55
+ type BlockColorMode = 'auto' | 'light' | 'dark' | 'transparent';
56
+ interface DgmoBlockOptions {
57
+ /** `diagram` (default): SVG only. `showcase`: SVG + source chrome. */
58
+ mode?: BlockMode;
59
+ /** Palette name. Default `slate`; unknown names warn + fall back. */
60
+ palette?: string;
61
+ /** Default `auto` (dual light/dark render). */
62
+ colorMode?: BlockColorMode;
63
+ /** Default: true in showcase mode, false in diagram mode. */
64
+ showSource?: boolean;
65
+ /** Default: true in showcase mode, false in diagram mode. */
66
+ showCopy?: boolean;
67
+ /** Default: true in showcase mode, false in diagram mode. */
68
+ showOpenInEditor?: boolean;
69
+ /** Base URL for the open-in-editor link. Default: online.diagrammo.app. */
70
+ editorBaseUrl?: string;
71
+ /** Outer wrapper element. Default `figure`. */
72
+ wrapper?: 'figure' | 'div';
73
+ /** Base class for the wrapper (styling hook). Default `dgmo`. */
74
+ className?: string;
75
+ /** Extra classes appended to every emitted wrapper (compat shims). */
76
+ legacyClassNames?: string[];
77
+ /**
78
+ * Accessible name for the block (`aria-label` on the wrapper). NOT rendered
79
+ * visually — the chart's visible title belongs in the DGMO source itself.
80
+ */
81
+ title?: string;
82
+ /** Receives palette-fallback warnings. Default: console.warn. */
83
+ onWarn?: (message: string) => void;
84
+ }
85
+ interface DgmoBlockResult {
86
+ html: string;
87
+ diagnostics: Array<{
88
+ message: string;
89
+ line?: number;
90
+ severity?: string;
91
+ }>;
92
+ }
93
+ /**
94
+ * Render one ```dgmo source block to the standard embed HTML. Async because
95
+ * it runs the full dgmo render pipeline (once per color mode).
96
+ *
97
+ * Render errors are NOT caught here — callers decide between throwing,
98
+ * `errorBlockHtml()`, or their own fallback.
99
+ */
100
+ declare function renderDgmoBlock(source: string, options?: DgmoBlockOptions): Promise<DgmoBlockResult>;
101
+ /**
102
+ * Assemble the standard block around already-rendered SVG markup. Exposed for
103
+ * surfaces that render through their own pipeline (e.g. dgmo-mcp's
104
+ * renderPipeline) but must emit the canonical chrome. `svgsHtml` must be the
105
+ * `.dgmo-light`+`.dgmo-dark` (or `.dgmo-svg`) wrapper divs.
106
+ */
107
+ declare function buildDgmoBlockHtml(source: string, svgsHtml: string, options?: DgmoBlockOptions): string;
108
+ /**
109
+ * Standard error card for a block that failed to parse/render. Same shape on
110
+ * every surface: `.dgmo--error` with `role="alert"`, message + offending
111
+ * source.
112
+ */
113
+ declare function errorBlockHtml(err: unknown, source: string, options?: Pick<DgmoBlockOptions, 'className' | 'legacyClassNames'>): string;
114
+
115
+ export { BLOCK_CSS, type BlockColorMode, type BlockMode, type DgmoBlockOptions, type DgmoBlockResult, EDITOR_BASE_URL, buildDgmoBlockHtml, errorBlockHtml, renderDgmoBlock };