@telperion/elements 8.2.0 → 9.0.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/.build-manifest.json +22 -1
- package/README.md +34 -0
- package/_chunks/mermaid-cdn-element-0CeuzHyG.d.cts +149 -0
- package/_chunks/mermaid-cdn-element-0CeuzHyG.d.ts +149 -0
- package/custom-elements.json +775 -0
- package/iife/mermaid/cdn.js +114 -0
- package/iife/mermaid/cdn.js.map +1 -0
- package/mermaid/bundled-mermaid-loader.cjs +7 -0
- package/mermaid/bundled-mermaid-loader.cjs.map +1 -0
- package/mermaid/bundled-mermaid-loader.js +5 -0
- package/mermaid/bundled-mermaid-loader.js.map +1 -0
- package/mermaid/cdn-mermaid-loader.cjs +34 -0
- package/mermaid/cdn-mermaid-loader.cjs.map +1 -0
- package/mermaid/cdn-mermaid-loader.js +29 -0
- package/mermaid/cdn-mermaid-loader.js.map +1 -0
- package/mermaid/cdn.cjs +21 -0
- package/mermaid/cdn.cjs.map +1 -0
- package/mermaid/cdn.d.cts +3 -0
- package/mermaid/cdn.d.ts +3 -0
- package/mermaid/cdn.js +16 -0
- package/mermaid/cdn.js.map +1 -0
- package/mermaid/index.cjs +19 -0
- package/mermaid/index.cjs.map +1 -0
- package/mermaid/index.d.cts +9 -0
- package/mermaid/index.d.ts +9 -0
- package/mermaid/index.js +6 -0
- package/mermaid/index.js.map +1 -0
- package/mermaid/loader.cjs +28 -0
- package/mermaid/loader.cjs.map +1 -0
- package/mermaid/loader.js +24 -0
- package/mermaid/loader.js.map +1 -0
- package/mermaid/mermaid-element-base.cjs +195 -0
- package/mermaid/mermaid-element-base.cjs.map +1 -0
- package/mermaid/mermaid-element-base.js +193 -0
- package/mermaid/mermaid-element-base.js.map +1 -0
- package/mermaid/mermaid-element.cjs +16 -0
- package/mermaid/mermaid-element.cjs.map +1 -0
- package/mermaid/mermaid-element.js +14 -0
- package/mermaid/mermaid-element.js.map +1 -0
- package/mermaid/render.cjs +42 -0
- package/mermaid/render.cjs.map +1 -0
- package/mermaid/render.js +39 -0
- package/mermaid/render.js.map +1 -0
- package/mermaid/source.cjs +27 -0
- package/mermaid/source.cjs.map +1 -0
- package/mermaid/source.js +24 -0
- package/mermaid/source.js.map +1 -0
- package/mermaid/styles.cjs +73 -0
- package/mermaid/styles.cjs.map +1 -0
- package/mermaid/styles.js +71 -0
- package/mermaid/styles.js.map +1 -0
- package/mermaid/theme.cjs +78 -0
- package/mermaid/theme.cjs.map +1 -0
- package/mermaid/theme.js +75 -0
- package/mermaid/theme.js.map +1 -0
- package/package.json +40 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sources":["../../../../libs/elements/src/mermaid/loader.ts"],"sourcesContent":[null],"names":[],"mappings":"AAWA,IAAI,MAAM,GAAkB,MAAM,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AACxG,IAAI,MAAoC;AAExC;;;AAGG;AACG,SAAU,gBAAgB,CAAC,IAAmB,EAAA;IAClD,MAAM,GAAG,IAAI;IACb,MAAM,GAAG,SAAS;AACpB;AAEA;SACgB,gBAAgB,GAAA;AAC9B,IAAA,OAAO,MAAM;AACf;AAEA;SACgB,WAAW,GAAA;IACzB,QAAQ,MAAM,KAAK,MAAM,EAAE,CAAC,KAAK,CAAC,KAAK,IAAG;QACxC,MAAM,GAAG,SAAS;AAElB,QAAA,MAAM,KAAK;IACb,CAAC,CAAC;AACJ;;;;"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib = require('tslib');
|
|
4
|
+
var lit = require('lit');
|
|
5
|
+
var decorators_js = require('lit/decorators.js');
|
|
6
|
+
var unsafeHtml_js = require('lit/directives/unsafe-html.js');
|
|
7
|
+
var render = require('./render.cjs');
|
|
8
|
+
var source = require('./source.cjs');
|
|
9
|
+
var styles = require('./styles.cjs');
|
|
10
|
+
var theme = require('./theme.cjs');
|
|
11
|
+
|
|
12
|
+
const DARK_SCHEME = "(prefers-color-scheme: dark)";
|
|
13
|
+
/**
|
|
14
|
+
* `<tp-mermaid>` — a [Mermaid](https://mermaid.js.org) diagram rendered to SVG.
|
|
15
|
+
*
|
|
16
|
+
* - **Source**: the element's text content, a direct `<template>` child (write
|
|
17
|
+
* `-->` and `<br/>` as they are), or the `code` property. It is dedented,
|
|
18
|
+
* and light-DOM changes re-render it.
|
|
19
|
+
* - **Lazy**: Mermaid is imported on the first render of the page, so
|
|
20
|
+
* registering the element costs next to nothing.
|
|
21
|
+
* - **Theming**: Mermaid's `base` theme, colored from `--tp-mermaid-*`
|
|
22
|
+
* variables (defaults from the shared `--tp-color-*` palette) and the
|
|
23
|
+
* element's font. Mermaid bakes colors into the SVG: call `refresh()` after
|
|
24
|
+
* changing them. A change of `prefers-color-scheme` re-renders on its own.
|
|
25
|
+
* - **Safe**: Mermaid runs with `securityLevel: "strict"`.
|
|
26
|
+
* - **Errors**: a source that does not parse shows the message and the source.
|
|
27
|
+
*
|
|
28
|
+
* @element tp-mermaid
|
|
29
|
+
*
|
|
30
|
+
* @attr {string} [label=""] - Accessible name of the diagram. When set, the diagram is exposed as one image with this name.
|
|
31
|
+
* @attr {"pending" | "rendered" | "error"} status - Read-only. Render state, for styling.
|
|
32
|
+
*
|
|
33
|
+
* @fires tp-mermaid-render - After each render pass. `detail: { diagramType }` on success, `detail: { error }` on failure.
|
|
34
|
+
*
|
|
35
|
+
* @csspart diagram - Wrapper of the rendered SVG.
|
|
36
|
+
* @csspart error - The error message.
|
|
37
|
+
* @csspart source - The source, shown when rendering failed.
|
|
38
|
+
*
|
|
39
|
+
* @cssprop --tp-mermaid-foreground - Text color. Defaults to `--tp-color-contrast`.
|
|
40
|
+
* @cssprop --tp-mermaid-background - The surface the diagram sits on; used for edge labels and mixed into the defaults. Defaults to `--tp-color-white`.
|
|
41
|
+
* @cssprop --tp-mermaid-accent - Accent the node colors derive from. Defaults to `--tp-color-primary`.
|
|
42
|
+
* @cssprop --tp-mermaid-node-background - Node fill. Defaults to 10% accent.
|
|
43
|
+
* @cssprop --tp-mermaid-node-border - Node border. Defaults to 55% accent.
|
|
44
|
+
* @cssprop --tp-mermaid-line - Edges and arrows. Defaults to 60% foreground.
|
|
45
|
+
* @cssprop --tp-mermaid-cluster-background - Subgraph fill. Defaults to 4% foreground.
|
|
46
|
+
* @cssprop --tp-mermaid-cluster-border - Subgraph border. Defaults to 25% foreground.
|
|
47
|
+
* @cssprop --tp-mermaid-note-background - Note fill. Defaults to 18% `--tp-color-warning`.
|
|
48
|
+
* @cssprop --tp-mermaid-font-family - Diagram font. Defaults to the inherited font.
|
|
49
|
+
* @cssprop --tp-mermaid-font-size - Diagram font size. Defaults to the inherited size.
|
|
50
|
+
* @cssprop --tp-mermaid-align - `justify-content` of the diagram. Defaults to `center`.
|
|
51
|
+
*/
|
|
52
|
+
class MermaidElement extends lit.LitElement {
|
|
53
|
+
constructor() {
|
|
54
|
+
super(...arguments);
|
|
55
|
+
/** Accessible name of the diagram. */
|
|
56
|
+
this.label = "";
|
|
57
|
+
/** Render state; reflected for styling, set by the element. */
|
|
58
|
+
this.status = "pending";
|
|
59
|
+
/** Raw source read from `code` or the light DOM. */
|
|
60
|
+
this.rawSource = "";
|
|
61
|
+
this.svg = "";
|
|
62
|
+
this.error = "";
|
|
63
|
+
this.#source = "";
|
|
64
|
+
this.#request = 0;
|
|
65
|
+
this.#renderDone = Promise.resolve();
|
|
66
|
+
this.#onSchemeChange = () => {
|
|
67
|
+
if (this.#source)
|
|
68
|
+
void this.refresh();
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
static { this.styles = styles.mermaidStyles; }
|
|
72
|
+
#source;
|
|
73
|
+
#observer;
|
|
74
|
+
#scheme;
|
|
75
|
+
#request;
|
|
76
|
+
#renderDone;
|
|
77
|
+
/** The dedented source being shown. */
|
|
78
|
+
get source() {
|
|
79
|
+
return this.#source;
|
|
80
|
+
}
|
|
81
|
+
/** Resolves once the current render pass (if any) has finished and updated the element. */
|
|
82
|
+
get renderComplete() {
|
|
83
|
+
return this.#renderDone;
|
|
84
|
+
}
|
|
85
|
+
connectedCallback() {
|
|
86
|
+
super.connectedCallback();
|
|
87
|
+
this.#observer ??= new MutationObserver(() => this.#syncSource());
|
|
88
|
+
this.#observer.observe(this, { childList: true, characterData: true, subtree: true });
|
|
89
|
+
this.#scheme ??= globalThis.matchMedia?.(DARK_SCHEME);
|
|
90
|
+
this.#scheme?.addEventListener("change", this.#onSchemeChange);
|
|
91
|
+
this.#syncSource();
|
|
92
|
+
}
|
|
93
|
+
disconnectedCallback() {
|
|
94
|
+
super.disconnectedCallback();
|
|
95
|
+
this.#observer?.disconnect();
|
|
96
|
+
this.#scheme?.removeEventListener("change", this.#onSchemeChange);
|
|
97
|
+
}
|
|
98
|
+
willUpdate(changed) {
|
|
99
|
+
if (changed.has("code"))
|
|
100
|
+
this.#syncSource();
|
|
101
|
+
if (changed.has("rawSource")) {
|
|
102
|
+
const source$1 = source.normalizeSource(this.rawSource);
|
|
103
|
+
if (source$1 !== this.#source) {
|
|
104
|
+
this.#source = source$1;
|
|
105
|
+
this.refresh();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
render() {
|
|
110
|
+
if (this.status === "error") {
|
|
111
|
+
return lit.html `
|
|
112
|
+
<p part="error" class="error" role="alert">${this.error}</p>
|
|
113
|
+
<pre part="source" class="source"><code>${this.#source}</code></pre>
|
|
114
|
+
`;
|
|
115
|
+
}
|
|
116
|
+
const labelled = !!this.label;
|
|
117
|
+
return lit.html `
|
|
118
|
+
<div
|
|
119
|
+
part="diagram"
|
|
120
|
+
class="diagram"
|
|
121
|
+
role=${labelled ? "img" : lit.nothing}
|
|
122
|
+
aria-label=${labelled ? this.label : lit.nothing}
|
|
123
|
+
aria-busy=${this.status === "pending" ? "true" : lit.nothing}
|
|
124
|
+
>
|
|
125
|
+
${unsafeHtml_js.unsafeHTML(this.svg)}
|
|
126
|
+
</div>
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Renders the diagram again with the current theme, e.g. after changing
|
|
131
|
+
* `--tp-mermaid-*` variables. Superseded passes are dropped.
|
|
132
|
+
*/
|
|
133
|
+
refresh() {
|
|
134
|
+
const request = ++this.#request;
|
|
135
|
+
const source = this.#source;
|
|
136
|
+
if (!source) {
|
|
137
|
+
this.svg = "";
|
|
138
|
+
this.status = "pending";
|
|
139
|
+
return (this.#renderDone = Promise.resolve());
|
|
140
|
+
}
|
|
141
|
+
this.status = "pending";
|
|
142
|
+
this.#renderDone = render.renderDiagram(source, theme.themeConfig(this)).then(async ({ svg, diagramType }) => {
|
|
143
|
+
if (request !== this.#request)
|
|
144
|
+
return;
|
|
145
|
+
this.svg = svg;
|
|
146
|
+
this.error = "";
|
|
147
|
+
this.status = "rendered";
|
|
148
|
+
await this.updateComplete;
|
|
149
|
+
this.#dispatch({ diagramType });
|
|
150
|
+
}, async (error) => {
|
|
151
|
+
if (request !== this.#request)
|
|
152
|
+
return;
|
|
153
|
+
this.svg = "";
|
|
154
|
+
this.error = render.errorMessage(error);
|
|
155
|
+
this.status = "error";
|
|
156
|
+
await this.updateComplete;
|
|
157
|
+
this.#dispatch({ error: this.error });
|
|
158
|
+
});
|
|
159
|
+
return this.#renderDone;
|
|
160
|
+
}
|
|
161
|
+
#dispatch(detail) {
|
|
162
|
+
this.dispatchEvent(new CustomEvent("tp-mermaid-render", { bubbles: true, composed: true, detail }));
|
|
163
|
+
}
|
|
164
|
+
#onSchemeChange;
|
|
165
|
+
#syncSource() {
|
|
166
|
+
this.rawSource = this.code ?? source.readSource(this);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
tslib.__decorate([
|
|
170
|
+
decorators_js.property({ reflect: true }),
|
|
171
|
+
tslib.__metadata("design:type", Object)
|
|
172
|
+
], MermaidElement.prototype, "label", void 0);
|
|
173
|
+
tslib.__decorate([
|
|
174
|
+
decorators_js.property({ reflect: true }),
|
|
175
|
+
tslib.__metadata("design:type", String)
|
|
176
|
+
], MermaidElement.prototype, "status", void 0);
|
|
177
|
+
tslib.__decorate([
|
|
178
|
+
decorators_js.property({ attribute: false }),
|
|
179
|
+
tslib.__metadata("design:type", String)
|
|
180
|
+
], MermaidElement.prototype, "code", void 0);
|
|
181
|
+
tslib.__decorate([
|
|
182
|
+
decorators_js.state(),
|
|
183
|
+
tslib.__metadata("design:type", Object)
|
|
184
|
+
], MermaidElement.prototype, "rawSource", void 0);
|
|
185
|
+
tslib.__decorate([
|
|
186
|
+
decorators_js.state(),
|
|
187
|
+
tslib.__metadata("design:type", Object)
|
|
188
|
+
], MermaidElement.prototype, "svg", void 0);
|
|
189
|
+
tslib.__decorate([
|
|
190
|
+
decorators_js.state(),
|
|
191
|
+
tslib.__metadata("design:type", Object)
|
|
192
|
+
], MermaidElement.prototype, "error", void 0);
|
|
193
|
+
|
|
194
|
+
exports.MermaidElement = MermaidElement;
|
|
195
|
+
//# sourceMappingURL=mermaid-element-base.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-element-base.cjs","sources":["../../../../libs/elements/src/mermaid/mermaid-element-base.ts"],"sourcesContent":[null],"names":["LitElement","mermaidStyles","source","normalizeSource","html","nothing","unsafeHTML","renderDiagram","themeConfig","errorMessage","readSource","__decorate","property","state"],"mappings":";;;;;;;;;;;AAmCA,MAAM,WAAW,GAAG,8BAA8B;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCG;AACG,MAAO,cAAe,SAAQA,cAAU,CAAA;AAA9C,IAAA,WAAA,GAAA;;;QAKE,IAAA,CAAA,KAAK,GAAG,EAAE;;QAIV,IAAA,CAAA,MAAM,GAAkB,SAAS;;QAWzB,IAAA,CAAA,SAAS,GAAG,EAAE;QAGd,IAAA,CAAA,GAAG,GAAG,EAAE;QAGR,IAAA,CAAA,KAAK,GAAG,EAAE;QAElB,IAA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E,IAAI,EAAE,CAAC;;AACjB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAIXD,gBAAA,CAAA;AADC,IAAAC,sBAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;AACM,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAOlCD,gBAAA,CAAA;AADC,IAAAC,sBAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;AACjB,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAIND,gBAAA,CAAA;AADP,IAAAE,mBAAK,EAAE;;AACe,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAGfF,gBAAA,CAAA;AADP,IAAAE,mBAAK,EAAE;;AACS,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AAGTF,gBAAA,CAAA;AADP,IAAAE,mBAAK,EAAE;;AACW,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import { LitElement, html, nothing } from 'lit';
|
|
3
|
+
import { property, state } from 'lit/decorators.js';
|
|
4
|
+
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
|
5
|
+
import { renderDiagram, errorMessage } from './render.js';
|
|
6
|
+
import { normalizeSource, readSource } from './source.js';
|
|
7
|
+
import { mermaidStyles } from './styles.js';
|
|
8
|
+
import { themeConfig } from './theme.js';
|
|
9
|
+
|
|
10
|
+
const DARK_SCHEME = "(prefers-color-scheme: dark)";
|
|
11
|
+
/**
|
|
12
|
+
* `<tp-mermaid>` — a [Mermaid](https://mermaid.js.org) diagram rendered to SVG.
|
|
13
|
+
*
|
|
14
|
+
* - **Source**: the element's text content, a direct `<template>` child (write
|
|
15
|
+
* `-->` and `<br/>` as they are), or the `code` property. It is dedented,
|
|
16
|
+
* and light-DOM changes re-render it.
|
|
17
|
+
* - **Lazy**: Mermaid is imported on the first render of the page, so
|
|
18
|
+
* registering the element costs next to nothing.
|
|
19
|
+
* - **Theming**: Mermaid's `base` theme, colored from `--tp-mermaid-*`
|
|
20
|
+
* variables (defaults from the shared `--tp-color-*` palette) and the
|
|
21
|
+
* element's font. Mermaid bakes colors into the SVG: call `refresh()` after
|
|
22
|
+
* changing them. A change of `prefers-color-scheme` re-renders on its own.
|
|
23
|
+
* - **Safe**: Mermaid runs with `securityLevel: "strict"`.
|
|
24
|
+
* - **Errors**: a source that does not parse shows the message and the source.
|
|
25
|
+
*
|
|
26
|
+
* @element tp-mermaid
|
|
27
|
+
*
|
|
28
|
+
* @attr {string} [label=""] - Accessible name of the diagram. When set, the diagram is exposed as one image with this name.
|
|
29
|
+
* @attr {"pending" | "rendered" | "error"} status - Read-only. Render state, for styling.
|
|
30
|
+
*
|
|
31
|
+
* @fires tp-mermaid-render - After each render pass. `detail: { diagramType }` on success, `detail: { error }` on failure.
|
|
32
|
+
*
|
|
33
|
+
* @csspart diagram - Wrapper of the rendered SVG.
|
|
34
|
+
* @csspart error - The error message.
|
|
35
|
+
* @csspart source - The source, shown when rendering failed.
|
|
36
|
+
*
|
|
37
|
+
* @cssprop --tp-mermaid-foreground - Text color. Defaults to `--tp-color-contrast`.
|
|
38
|
+
* @cssprop --tp-mermaid-background - The surface the diagram sits on; used for edge labels and mixed into the defaults. Defaults to `--tp-color-white`.
|
|
39
|
+
* @cssprop --tp-mermaid-accent - Accent the node colors derive from. Defaults to `--tp-color-primary`.
|
|
40
|
+
* @cssprop --tp-mermaid-node-background - Node fill. Defaults to 10% accent.
|
|
41
|
+
* @cssprop --tp-mermaid-node-border - Node border. Defaults to 55% accent.
|
|
42
|
+
* @cssprop --tp-mermaid-line - Edges and arrows. Defaults to 60% foreground.
|
|
43
|
+
* @cssprop --tp-mermaid-cluster-background - Subgraph fill. Defaults to 4% foreground.
|
|
44
|
+
* @cssprop --tp-mermaid-cluster-border - Subgraph border. Defaults to 25% foreground.
|
|
45
|
+
* @cssprop --tp-mermaid-note-background - Note fill. Defaults to 18% `--tp-color-warning`.
|
|
46
|
+
* @cssprop --tp-mermaid-font-family - Diagram font. Defaults to the inherited font.
|
|
47
|
+
* @cssprop --tp-mermaid-font-size - Diagram font size. Defaults to the inherited size.
|
|
48
|
+
* @cssprop --tp-mermaid-align - `justify-content` of the diagram. Defaults to `center`.
|
|
49
|
+
*/
|
|
50
|
+
class MermaidElement extends LitElement {
|
|
51
|
+
constructor() {
|
|
52
|
+
super(...arguments);
|
|
53
|
+
/** Accessible name of the diagram. */
|
|
54
|
+
this.label = "";
|
|
55
|
+
/** Render state; reflected for styling, set by the element. */
|
|
56
|
+
this.status = "pending";
|
|
57
|
+
/** Raw source read from `code` or the light DOM. */
|
|
58
|
+
this.rawSource = "";
|
|
59
|
+
this.svg = "";
|
|
60
|
+
this.error = "";
|
|
61
|
+
this.#source = "";
|
|
62
|
+
this.#request = 0;
|
|
63
|
+
this.#renderDone = Promise.resolve();
|
|
64
|
+
this.#onSchemeChange = () => {
|
|
65
|
+
if (this.#source)
|
|
66
|
+
void this.refresh();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static { this.styles = mermaidStyles; }
|
|
70
|
+
#source;
|
|
71
|
+
#observer;
|
|
72
|
+
#scheme;
|
|
73
|
+
#request;
|
|
74
|
+
#renderDone;
|
|
75
|
+
/** The dedented source being shown. */
|
|
76
|
+
get source() {
|
|
77
|
+
return this.#source;
|
|
78
|
+
}
|
|
79
|
+
/** Resolves once the current render pass (if any) has finished and updated the element. */
|
|
80
|
+
get renderComplete() {
|
|
81
|
+
return this.#renderDone;
|
|
82
|
+
}
|
|
83
|
+
connectedCallback() {
|
|
84
|
+
super.connectedCallback();
|
|
85
|
+
this.#observer ??= new MutationObserver(() => this.#syncSource());
|
|
86
|
+
this.#observer.observe(this, { childList: true, characterData: true, subtree: true });
|
|
87
|
+
this.#scheme ??= globalThis.matchMedia?.(DARK_SCHEME);
|
|
88
|
+
this.#scheme?.addEventListener("change", this.#onSchemeChange);
|
|
89
|
+
this.#syncSource();
|
|
90
|
+
}
|
|
91
|
+
disconnectedCallback() {
|
|
92
|
+
super.disconnectedCallback();
|
|
93
|
+
this.#observer?.disconnect();
|
|
94
|
+
this.#scheme?.removeEventListener("change", this.#onSchemeChange);
|
|
95
|
+
}
|
|
96
|
+
willUpdate(changed) {
|
|
97
|
+
if (changed.has("code"))
|
|
98
|
+
this.#syncSource();
|
|
99
|
+
if (changed.has("rawSource")) {
|
|
100
|
+
const source = normalizeSource(this.rawSource);
|
|
101
|
+
if (source !== this.#source) {
|
|
102
|
+
this.#source = source;
|
|
103
|
+
this.refresh();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
render() {
|
|
108
|
+
if (this.status === "error") {
|
|
109
|
+
return html `
|
|
110
|
+
<p part="error" class="error" role="alert">${this.error}</p>
|
|
111
|
+
<pre part="source" class="source"><code>${this.#source}</code></pre>
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
const labelled = !!this.label;
|
|
115
|
+
return html `
|
|
116
|
+
<div
|
|
117
|
+
part="diagram"
|
|
118
|
+
class="diagram"
|
|
119
|
+
role=${labelled ? "img" : nothing}
|
|
120
|
+
aria-label=${labelled ? this.label : nothing}
|
|
121
|
+
aria-busy=${this.status === "pending" ? "true" : nothing}
|
|
122
|
+
>
|
|
123
|
+
${unsafeHTML(this.svg)}
|
|
124
|
+
</div>
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Renders the diagram again with the current theme, e.g. after changing
|
|
129
|
+
* `--tp-mermaid-*` variables. Superseded passes are dropped.
|
|
130
|
+
*/
|
|
131
|
+
refresh() {
|
|
132
|
+
const request = ++this.#request;
|
|
133
|
+
const source = this.#source;
|
|
134
|
+
if (!source) {
|
|
135
|
+
this.svg = "";
|
|
136
|
+
this.status = "pending";
|
|
137
|
+
return (this.#renderDone = Promise.resolve());
|
|
138
|
+
}
|
|
139
|
+
this.status = "pending";
|
|
140
|
+
this.#renderDone = renderDiagram(source, themeConfig(this)).then(async ({ svg, diagramType }) => {
|
|
141
|
+
if (request !== this.#request)
|
|
142
|
+
return;
|
|
143
|
+
this.svg = svg;
|
|
144
|
+
this.error = "";
|
|
145
|
+
this.status = "rendered";
|
|
146
|
+
await this.updateComplete;
|
|
147
|
+
this.#dispatch({ diagramType });
|
|
148
|
+
}, async (error) => {
|
|
149
|
+
if (request !== this.#request)
|
|
150
|
+
return;
|
|
151
|
+
this.svg = "";
|
|
152
|
+
this.error = errorMessage(error);
|
|
153
|
+
this.status = "error";
|
|
154
|
+
await this.updateComplete;
|
|
155
|
+
this.#dispatch({ error: this.error });
|
|
156
|
+
});
|
|
157
|
+
return this.#renderDone;
|
|
158
|
+
}
|
|
159
|
+
#dispatch(detail) {
|
|
160
|
+
this.dispatchEvent(new CustomEvent("tp-mermaid-render", { bubbles: true, composed: true, detail }));
|
|
161
|
+
}
|
|
162
|
+
#onSchemeChange;
|
|
163
|
+
#syncSource() {
|
|
164
|
+
this.rawSource = this.code ?? readSource(this);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
__decorate([
|
|
168
|
+
property({ reflect: true }),
|
|
169
|
+
__metadata("design:type", Object)
|
|
170
|
+
], MermaidElement.prototype, "label", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
property({ reflect: true }),
|
|
173
|
+
__metadata("design:type", String)
|
|
174
|
+
], MermaidElement.prototype, "status", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
property({ attribute: false }),
|
|
177
|
+
__metadata("design:type", String)
|
|
178
|
+
], MermaidElement.prototype, "code", void 0);
|
|
179
|
+
__decorate([
|
|
180
|
+
state(),
|
|
181
|
+
__metadata("design:type", Object)
|
|
182
|
+
], MermaidElement.prototype, "rawSource", void 0);
|
|
183
|
+
__decorate([
|
|
184
|
+
state(),
|
|
185
|
+
__metadata("design:type", Object)
|
|
186
|
+
], MermaidElement.prototype, "svg", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
state(),
|
|
189
|
+
__metadata("design:type", Object)
|
|
190
|
+
], MermaidElement.prototype, "error", void 0);
|
|
191
|
+
|
|
192
|
+
export { MermaidElement };
|
|
193
|
+
//# sourceMappingURL=mermaid-element-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-element-base.js","sources":["../../../../libs/elements/src/mermaid/mermaid-element-base.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;AAmCA,MAAM,WAAW,GAAG,8BAA8B;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCG;AACG,MAAO,cAAe,SAAQ,UAAU,CAAA;AAA9C,IAAA,WAAA,GAAA;;;QAKE,IAAA,CAAA,KAAK,GAAG,EAAE;;QAIV,IAAA,CAAA,MAAM,GAAkB,SAAS;;QAWzB,IAAA,CAAA,SAAS,GAAG,EAAE;QAGd,IAAA,CAAA,GAAG,GAAG,EAAE;QAGR,IAAA,CAAA,KAAK,GAAG,EAAE;QAElB,IAAA,CAAA,OAAO,GAAG,EAAE;QAGZ,IAAA,CAAA,QAAQ,GAAG,CAAC;AACZ,QAAA,IAAA,CAAA,WAAW,GAAkB,OAAO,CAAC,OAAO,EAAE;QA8G9C,IAAA,CAAA,eAAe,GAAG,MAAW;YAC3B,IAAI,IAAI,CAAC,OAAO;AAAE,gBAAA,KAAK,IAAI,CAAC,OAAO,EAAE;AACvC,QAAA,CAAC;IAKH;aApJkB,IAAA,CAAA,MAAM,GAAG,aAAH,CAAiB;AA2BvC,IAAA,OAAO;AACP,IAAA,SAAS;AACT,IAAA,OAAO;AACP,IAAA,QAAQ;AACR,IAAA,WAAW;;AAGX,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC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CAAA;AAGf,UAAA,CAAA;AADP,IAAA,KAAK,EAAE;;AACS,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AAGT,UAAA,CAAA;AADP,IAAA,KAAK,EAAE;;AACW,CAAA,EAAA,cAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var bundledMermaidLoader = require('./bundled-mermaid-loader.cjs');
|
|
4
|
+
var loader = require('./loader.cjs');
|
|
5
|
+
var mermaidElementBase = require('./mermaid-element-base.cjs');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Bundler entry for `<tp-mermaid>`: Mermaid is `import()`ed on the first
|
|
9
|
+
* render, so bundlers split it (and each diagram type) into lazy chunks.
|
|
10
|
+
*/
|
|
11
|
+
loader.setMermaidLoader(bundledMermaidLoader.bundledMermaidLoader);
|
|
12
|
+
if (!customElements.get("tp-mermaid"))
|
|
13
|
+
customElements.define("tp-mermaid", mermaidElementBase.MermaidElement);
|
|
14
|
+
|
|
15
|
+
exports.MermaidElement = mermaidElementBase.MermaidElement;
|
|
16
|
+
//# sourceMappingURL=mermaid-element.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-element.cjs","sources":["../../../../libs/elements/src/mermaid/mermaid-element.ts"],"sourcesContent":[null],"names":["setMermaidLoader","bundledMermaidLoader","MermaidElement"],"mappings":";;;;;;AAIA;;;AAGG;AACHA,uBAAgB,CAACC,yCAAoB,CAAC;AAEtC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,YAAY,EAAEC,iCAAc,CAAC;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { bundledMermaidLoader } from './bundled-mermaid-loader.js';
|
|
2
|
+
import { setMermaidLoader } from './loader.js';
|
|
3
|
+
import { MermaidElement } from './mermaid-element-base.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bundler entry for `<tp-mermaid>`: Mermaid is `import()`ed on the first
|
|
7
|
+
* render, so bundlers split it (and each diagram type) into lazy chunks.
|
|
8
|
+
*/
|
|
9
|
+
setMermaidLoader(bundledMermaidLoader);
|
|
10
|
+
if (!customElements.get("tp-mermaid"))
|
|
11
|
+
customElements.define("tp-mermaid", MermaidElement);
|
|
12
|
+
|
|
13
|
+
export { MermaidElement };
|
|
14
|
+
//# sourceMappingURL=mermaid-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-element.js","sources":["../../../../libs/elements/src/mermaid/mermaid-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;;AAGG;AACH,gBAAgB,CAAC,oBAAoB,CAAC;AAEtC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,YAAY,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC;;;;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var loader = require('./loader.cjs');
|
|
4
|
+
|
|
5
|
+
/** Settings every diagram gets; a diagram's own config can change anything but these. */
|
|
6
|
+
const BASE_CONFIG = {
|
|
7
|
+
startOnLoad: false,
|
|
8
|
+
securityLevel: "strict",
|
|
9
|
+
// The element shows its own error state; Mermaid's error SVG would be left in <body>
|
|
10
|
+
suppressErrorRendering: true,
|
|
11
|
+
};
|
|
12
|
+
let queue = Promise.resolve();
|
|
13
|
+
let counter = 0;
|
|
14
|
+
/**
|
|
15
|
+
* Renders `source` to SVG with `config` (the host's theme).
|
|
16
|
+
*
|
|
17
|
+
* Mermaid's config is global, so renders run one at a time and each one
|
|
18
|
+
* applies its own config first; otherwise two diagrams with different themes
|
|
19
|
+
* could swap colors.
|
|
20
|
+
*/
|
|
21
|
+
function renderDiagram(source, config) {
|
|
22
|
+
const run = async () => {
|
|
23
|
+
const mermaid = await loader.loadMermaid();
|
|
24
|
+
mermaid.initialize({ ...config, ...BASE_CONFIG });
|
|
25
|
+
return mermaid.render(`tp-mermaid-${++counter}`, source);
|
|
26
|
+
};
|
|
27
|
+
const result = queue.then(run, run);
|
|
28
|
+
queue = result.catch(() => undefined);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/** A readable message from whatever Mermaid threw. */
|
|
32
|
+
function errorMessage(error) {
|
|
33
|
+
if (error instanceof Error)
|
|
34
|
+
return error.message;
|
|
35
|
+
if (typeof error === "string")
|
|
36
|
+
return error;
|
|
37
|
+
return String(error?.message ?? error);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.errorMessage = errorMessage;
|
|
41
|
+
exports.renderDiagram = renderDiagram;
|
|
42
|
+
//# sourceMappingURL=render.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.cjs","sources":["../../../../libs/elements/src/mermaid/render.ts"],"sourcesContent":[null],"names":["loadMermaid"],"mappings":";;;;AAIA;AACA,MAAM,WAAW,GAAkB;AACjC,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,aAAa,EAAE,QAAQ;;AAEvB,IAAA,sBAAsB,EAAE,IAAI;CAC7B;AACD,IAAI,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE;AAC/C,IAAI,OAAO,GAAG,CAAC;AAEf;;;;;;AAMG;AACG,SAAU,aAAa,CAAC,MAAc,EAAE,MAAqB,EAAA;AACjE,IAAA,MAAM,GAAG,GAAG,YAAW;AACrB,QAAA,MAAM,OAAO,GAAG,MAAMA,kBAAW,EAAE;QAEnC,OAAO,CAAC,UAAU,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QAEjD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAA,WAAA,EAAc,EAAE,OAAO,CAAA,CAAE,EAAE,MAAM,CAAC;AAC1D,IAAA,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC;IAEnC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC;AAErC,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,YAAY,CAAC,KAAc,EAAA;IACzC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO;IAEhD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,OAAO,MAAM,CAAE,KAAsC,EAAE,OAAO,IAAI,KAAK,CAAC;AAC1E;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { loadMermaid } from './loader.js';
|
|
2
|
+
|
|
3
|
+
/** Settings every diagram gets; a diagram's own config can change anything but these. */
|
|
4
|
+
const BASE_CONFIG = {
|
|
5
|
+
startOnLoad: false,
|
|
6
|
+
securityLevel: "strict",
|
|
7
|
+
// The element shows its own error state; Mermaid's error SVG would be left in <body>
|
|
8
|
+
suppressErrorRendering: true,
|
|
9
|
+
};
|
|
10
|
+
let queue = Promise.resolve();
|
|
11
|
+
let counter = 0;
|
|
12
|
+
/**
|
|
13
|
+
* Renders `source` to SVG with `config` (the host's theme).
|
|
14
|
+
*
|
|
15
|
+
* Mermaid's config is global, so renders run one at a time and each one
|
|
16
|
+
* applies its own config first; otherwise two diagrams with different themes
|
|
17
|
+
* could swap colors.
|
|
18
|
+
*/
|
|
19
|
+
function renderDiagram(source, config) {
|
|
20
|
+
const run = async () => {
|
|
21
|
+
const mermaid = await loadMermaid();
|
|
22
|
+
mermaid.initialize({ ...config, ...BASE_CONFIG });
|
|
23
|
+
return mermaid.render(`tp-mermaid-${++counter}`, source);
|
|
24
|
+
};
|
|
25
|
+
const result = queue.then(run, run);
|
|
26
|
+
queue = result.catch(() => undefined);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/** A readable message from whatever Mermaid threw. */
|
|
30
|
+
function errorMessage(error) {
|
|
31
|
+
if (error instanceof Error)
|
|
32
|
+
return error.message;
|
|
33
|
+
if (typeof error === "string")
|
|
34
|
+
return error;
|
|
35
|
+
return String(error?.message ?? error);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { errorMessage, renderDiagram };
|
|
39
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sources":["../../../../libs/elements/src/mermaid/render.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAIA;AACA,MAAM,WAAW,GAAkB;AACjC,IAAA,WAAW,EAAE,KAAK;AAClB,IAAA,aAAa,EAAE,QAAQ;;AAEvB,IAAA,sBAAsB,EAAE,IAAI;CAC7B;AACD,IAAI,KAAK,GAAqB,OAAO,CAAC,OAAO,EAAE;AAC/C,IAAI,OAAO,GAAG,CAAC;AAEf;;;;;;AAMG;AACG,SAAU,aAAa,CAAC,MAAc,EAAE,MAAqB,EAAA;AACjE,IAAA,MAAM,GAAG,GAAG,YAAW;AACrB,QAAA,MAAM,OAAO,GAAG,MAAM,WAAW,EAAE;QAEnC,OAAO,CAAC,UAAU,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,WAAW,EAAE,CAAC;QAEjD,OAAO,OAAO,CAAC,MAAM,CAAC,CAAA,WAAA,EAAc,EAAE,OAAO,CAAA,CAAE,EAAE,MAAM,CAAC;AAC1D,IAAA,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC;IAEnC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC;AAErC,IAAA,OAAO,MAAM;AACf;AAEA;AACM,SAAU,YAAY,CAAC,KAAc,EAAA;IACzC,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO;IAEhD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,OAAO,MAAM,CAAE,KAAsC,EAAE,OAAO,IAAI,KAAK,CAAC;AAC1E;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var source = require('../code/source.cjs');
|
|
4
|
+
|
|
5
|
+
const ENTITIES = { "&": "&", "<": "<", ">": ">", """: '"', " ": " " };
|
|
6
|
+
/**
|
|
7
|
+
* Reads the raw diagram source of a `<tp-mermaid>` host from its light DOM.
|
|
8
|
+
*
|
|
9
|
+
* - A direct `<template>` child wins. Its markup is used with the entities the
|
|
10
|
+
* HTML serializer adds turned back into characters, so `A --> B` and
|
|
11
|
+
* `<br/>` labels can be written as they are.
|
|
12
|
+
* - Otherwise the host's `textContent` is used (escape `<` there).
|
|
13
|
+
*/
|
|
14
|
+
function readSource(host) {
|
|
15
|
+
const template = host.querySelector(":scope > template");
|
|
16
|
+
if (template)
|
|
17
|
+
return template.innerHTML.replace(/&(?:amp|lt|gt|quot|nbsp);/g, entity => ENTITIES[entity]);
|
|
18
|
+
return host.textContent ?? "";
|
|
19
|
+
}
|
|
20
|
+
/** Normalizes line endings and strips the shared indentation and surrounding blank lines. */
|
|
21
|
+
function normalizeSource(raw) {
|
|
22
|
+
return source.dedent(raw.replace(/\r\n?/g, "\n"));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.normalizeSource = normalizeSource;
|
|
26
|
+
exports.readSource = readSource;
|
|
27
|
+
//# sourceMappingURL=source.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.cjs","sources":["../../../../libs/elements/src/mermaid/source.ts"],"sourcesContent":[null],"names":["dedent"],"mappings":";;;;AAEA,MAAM,QAAQ,GAA2B,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE;AAEjH;;;;;;;AAOG;AACG,SAAU,UAAU,CAAC,IAAa,EAAA;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC;AAExD,IAAA,IAAI,QAAQ;AAAE,QAAA,OAAO,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,4BAA4B,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEzG,IAAA,OAAO,IAAI,CAAC,WAAW,IAAI,EAAE;AAC/B;AAEA;AACM,SAAU,eAAe,CAAC,GAAW,EAAA;IACzC,OAAOA,aAAM,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC5C;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { dedent } from '../code/source.js';
|
|
2
|
+
|
|
3
|
+
const ENTITIES = { "&": "&", "<": "<", ">": ">", """: '"', " ": " " };
|
|
4
|
+
/**
|
|
5
|
+
* Reads the raw diagram source of a `<tp-mermaid>` host from its light DOM.
|
|
6
|
+
*
|
|
7
|
+
* - A direct `<template>` child wins. Its markup is used with the entities the
|
|
8
|
+
* HTML serializer adds turned back into characters, so `A --> B` and
|
|
9
|
+
* `<br/>` labels can be written as they are.
|
|
10
|
+
* - Otherwise the host's `textContent` is used (escape `<` there).
|
|
11
|
+
*/
|
|
12
|
+
function readSource(host) {
|
|
13
|
+
const template = host.querySelector(":scope > template");
|
|
14
|
+
if (template)
|
|
15
|
+
return template.innerHTML.replace(/&(?:amp|lt|gt|quot|nbsp);/g, entity => ENTITIES[entity]);
|
|
16
|
+
return host.textContent ?? "";
|
|
17
|
+
}
|
|
18
|
+
/** Normalizes line endings and strips the shared indentation and surrounding blank lines. */
|
|
19
|
+
function normalizeSource(raw) {
|
|
20
|
+
return dedent(raw.replace(/\r\n?/g, "\n"));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { normalizeSource, readSource };
|
|
24
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source.js","sources":["../../../../libs/elements/src/mermaid/source.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA,MAAM,QAAQ,GAA2B,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE;AAEjH;;;;;;;AAOG;AACG,SAAU,UAAU,CAAC,IAAa,EAAA;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC;AAExD,IAAA,IAAI,QAAQ;AAAE,QAAA,OAAO,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,4BAA4B,EAAE,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEzG,IAAA,OAAO,IAAI,CAAC,WAAW,IAAI,EAAE;AAC/B;AAEA;AACM,SAAU,eAAe,CAAC,GAAW,EAAA;IACzC,OAAO,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC5C;;;;"}
|