@diagrammo/dgmo 0.45.0 → 0.46.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/advanced.cjs +31 -25
- package/dist/advanced.js +31 -25
- package/dist/auto.cjs +500 -341
- package/dist/auto.css +342 -159
- package/dist/auto.d.cts +10 -8
- package/dist/auto.d.ts +10 -8
- package/dist/auto.js +373 -265
- package/dist/auto.mjs +500 -341
- package/dist/block.cjs +31 -25
- package/dist/block.js +31 -25
- package/dist/cli.cjs +112 -112
- package/dist/element.cjs +492 -325
- package/dist/element.js +367 -259
- package/dist/element.mjs +492 -325
- package/dist/index.cjs +31 -25
- package/dist/index.js +31 -25
- package/package.json +1 -1
- package/src/auto/index.ts +55 -57
- package/src/auto/shared.ts +142 -142
- package/src/auto/styles.ts +44 -199
- package/src/c4/renderer.ts +2 -2
- package/src/element/index.ts +29 -21
- package/src/infra/renderer.ts +1 -1
- package/src/render.ts +34 -14
- package/src/sitemap/renderer.ts +1 -1
- package/src/timeline/renderer.ts +1 -1
- package/src/utils/hover-styles.ts +6 -1
- package/src/utils/legend-d3.ts +1 -4
- package/src/utils/legend-svg.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5052,10 +5052,7 @@ function renderLegendD3(container, config, state, palette, isDark, callbacks, co
|
|
|
5052
5052
|
legendG.selectAll("*").remove();
|
|
5053
5053
|
if (currentLayout.height === 0) return;
|
|
5054
5054
|
if (currentState.activeGroup) {
|
|
5055
|
-
legendG.attr(
|
|
5056
|
-
"data-legend-active",
|
|
5057
|
-
currentState.activeGroup.toLowerCase()
|
|
5058
|
-
);
|
|
5055
|
+
legendG.attr("data-legend-active", tagAttrKey(currentState.activeGroup));
|
|
5059
5056
|
} else {
|
|
5060
5057
|
legendG.attr("data-legend-active", null);
|
|
5061
5058
|
}
|
|
@@ -5862,7 +5859,7 @@ function renderTimelineTagLegendOverlay(container, parsed, palette, isDark, setu
|
|
|
5862
5859
|
if (currentActiveGroup) {
|
|
5863
5860
|
legendContainer.attr(
|
|
5864
5861
|
"data-legend-active",
|
|
5865
|
-
currentActiveGroup
|
|
5862
|
+
tagAttrKey(currentActiveGroup)
|
|
5866
5863
|
);
|
|
5867
5864
|
}
|
|
5868
5865
|
const iconAddon = viewMode ? 0 : LG_ICON_W;
|
|
@@ -25559,7 +25556,7 @@ function renderLegendSvg(groups, options) {
|
|
|
25559
25556
|
track(pill.x, pill.y, pill.width, pill.height);
|
|
25560
25557
|
}
|
|
25561
25558
|
const classAttr = className ? ` class="${esc(className)}"` : "";
|
|
25562
|
-
const activeAttr = activeGroup ? ` data-legend-active="${esc(activeGroup
|
|
25559
|
+
const activeAttr = activeGroup ? ` data-legend-active="${esc(tagAttrKey(activeGroup))}"` : "";
|
|
25563
25560
|
const svg = `<g${classAttr}${activeAttr}>${parts.join("")}</g>`;
|
|
25564
25561
|
return {
|
|
25565
25562
|
svg,
|
|
@@ -30874,7 +30871,7 @@ function renderSitemap(container, parsed, layout, palette, isDark, onClickItem,
|
|
|
30874
30871
|
if (fixedLegend) {
|
|
30875
30872
|
const legendParent = svg.append("g").attr("class", "sitemap-legend-fixed").attr("transform", `translate(0, ${sDiagramPadding + fixedTitleH})`);
|
|
30876
30873
|
if (activeTagGroup) {
|
|
30877
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
30874
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
30878
30875
|
}
|
|
30879
30876
|
renderLegend(
|
|
30880
30877
|
legendParent,
|
|
@@ -41296,7 +41293,7 @@ function renderC4Context(container, parsed, layout, palette, isDark, onClickItem
|
|
|
41296
41293
|
if (hasLegend) {
|
|
41297
41294
|
const legendParent = fixedLegend ? svg.append("g").attr("class", "c4-legend-fixed").attr("transform", `translate(0, ${DIAGRAM_PADDING8 + titleHeight})`) : contentG.append("g").attr("class", "c4-legend");
|
|
41298
41295
|
if (activeTagGroup) {
|
|
41299
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
41296
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
41300
41297
|
}
|
|
41301
41298
|
renderLegend2(
|
|
41302
41299
|
legendParent,
|
|
@@ -41911,7 +41908,7 @@ function renderC4Containers(container, parsed, layout, palette, isDark, onClickI
|
|
|
41911
41908
|
if (hasLegend) {
|
|
41912
41909
|
const legendParent = fixedLegend ? svg.append("g").attr("class", "c4-legend-fixed").attr("transform", `translate(0, ${DIAGRAM_PADDING8 + titleHeight})`) : contentG.append("g").attr("class", "c4-legend");
|
|
41913
41910
|
if (activeTagGroup) {
|
|
41914
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
41911
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
41915
41912
|
}
|
|
41916
41913
|
renderLegend2(
|
|
41917
41914
|
legendParent,
|
|
@@ -45584,7 +45581,7 @@ function renderLegend3(rootSvg, legendGroups, totalWidth, legendY, palette, isDa
|
|
|
45584
45581
|
const appHostedPlayback = controlsHost === "app" && !!playback;
|
|
45585
45582
|
const legendG = rootSvg.append("g").attr("transform", `translate(0, ${legendY})`);
|
|
45586
45583
|
if (activeGroup) {
|
|
45587
|
-
legendG.attr("data-legend-active", activeGroup
|
|
45584
|
+
legendG.attr("data-legend-active", tagAttrKey(activeGroup));
|
|
45588
45585
|
}
|
|
45589
45586
|
const allGroups = legendGroups.map((g) => ({
|
|
45590
45587
|
name: g.name,
|
|
@@ -68673,6 +68670,7 @@ async function exportVisualization(ctx) {
|
|
|
68673
68670
|
init_charts_d3();
|
|
68674
68671
|
|
|
68675
68672
|
// src/utils/hover-styles.ts
|
|
68673
|
+
init_tag_groups();
|
|
68676
68674
|
var MAX_HOVER_GROUPS = 40;
|
|
68677
68675
|
var DEFAULT_DIM_OPACITY = 0.4;
|
|
68678
68676
|
var LIFT_DECL = "filter:saturate(1.4) brightness(1.06)";
|
|
@@ -69067,7 +69065,7 @@ function deriveFromSvg(svg, spec) {
|
|
|
69067
69065
|
if (spec.groupAttrMode === "tag-active") {
|
|
69068
69066
|
const slug = root.querySelector("[data-legend-active]")?.getAttribute("data-legend-active");
|
|
69069
69067
|
if (slug) {
|
|
69070
|
-
groupAttr = `data-tag-${slug}`;
|
|
69068
|
+
groupAttr = `data-tag-${tagAttrKey(slug)}`;
|
|
69071
69069
|
} else {
|
|
69072
69070
|
const names = /* @__PURE__ */ new Set();
|
|
69073
69071
|
root.querySelectorAll(spec.markSelector).forEach((el) => {
|
|
@@ -69122,10 +69120,16 @@ var DOM_GLOBALS = [
|
|
|
69122
69120
|
"HTMLElement",
|
|
69123
69121
|
"SVGElement"
|
|
69124
69122
|
];
|
|
69125
|
-
var
|
|
69126
|
-
|
|
69127
|
-
|
|
69128
|
-
|
|
69123
|
+
var DOM_STATE_KEY = /* @__PURE__ */ Symbol.for("diagrammo.dgmo.dom-globals");
|
|
69124
|
+
function domState() {
|
|
69125
|
+
const g = globalThis;
|
|
69126
|
+
return g[DOM_STATE_KEY] ??= {
|
|
69127
|
+
refCount: 0,
|
|
69128
|
+
installPromise: null,
|
|
69129
|
+
installedByUs: false
|
|
69130
|
+
};
|
|
69131
|
+
}
|
|
69132
|
+
async function installDom(state) {
|
|
69129
69133
|
const { JSDOM } = await loadJsdom();
|
|
69130
69134
|
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
|
69131
69135
|
url: "http://localhost/"
|
|
@@ -69144,23 +69148,25 @@ async function installDom() {
|
|
|
69144
69148
|
configurable: true
|
|
69145
69149
|
});
|
|
69146
69150
|
}
|
|
69147
|
-
|
|
69151
|
+
state.installedByUs = true;
|
|
69148
69152
|
}
|
|
69149
69153
|
async function acquireDom() {
|
|
69150
|
-
|
|
69151
|
-
|
|
69152
|
-
|
|
69153
|
-
|
|
69154
|
+
const state = domState();
|
|
69155
|
+
if (typeof document !== "undefined" && !state.installedByUs) return;
|
|
69156
|
+
state.refCount++;
|
|
69157
|
+
if (!state.installPromise) state.installPromise = installDom(state);
|
|
69158
|
+
await state.installPromise;
|
|
69154
69159
|
}
|
|
69155
69160
|
function releaseDom() {
|
|
69156
|
-
|
|
69157
|
-
if (
|
|
69161
|
+
const state = domState();
|
|
69162
|
+
if (!state.installedByUs) return;
|
|
69163
|
+
if (--state.refCount > 0) return;
|
|
69158
69164
|
for (const key of DOM_GLOBALS) {
|
|
69159
69165
|
delete globalThis[key];
|
|
69160
69166
|
}
|
|
69161
|
-
|
|
69162
|
-
|
|
69163
|
-
|
|
69167
|
+
state.installedByUs = false;
|
|
69168
|
+
state.installPromise = null;
|
|
69169
|
+
state.refCount = 0;
|
|
69164
69170
|
}
|
|
69165
69171
|
async function loadJsdom() {
|
|
69166
69172
|
const spec = ["js", "dom"].join("");
|
package/dist/index.js
CHANGED
|
@@ -5050,10 +5050,7 @@ function renderLegendD3(container, config, state, palette, isDark, callbacks, co
|
|
|
5050
5050
|
legendG.selectAll("*").remove();
|
|
5051
5051
|
if (currentLayout.height === 0) return;
|
|
5052
5052
|
if (currentState.activeGroup) {
|
|
5053
|
-
legendG.attr(
|
|
5054
|
-
"data-legend-active",
|
|
5055
|
-
currentState.activeGroup.toLowerCase()
|
|
5056
|
-
);
|
|
5053
|
+
legendG.attr("data-legend-active", tagAttrKey(currentState.activeGroup));
|
|
5057
5054
|
} else {
|
|
5058
5055
|
legendG.attr("data-legend-active", null);
|
|
5059
5056
|
}
|
|
@@ -5862,7 +5859,7 @@ function renderTimelineTagLegendOverlay(container, parsed, palette, isDark, setu
|
|
|
5862
5859
|
if (currentActiveGroup) {
|
|
5863
5860
|
legendContainer.attr(
|
|
5864
5861
|
"data-legend-active",
|
|
5865
|
-
currentActiveGroup
|
|
5862
|
+
tagAttrKey(currentActiveGroup)
|
|
5866
5863
|
);
|
|
5867
5864
|
}
|
|
5868
5865
|
const iconAddon = viewMode ? 0 : LG_ICON_W;
|
|
@@ -25557,7 +25554,7 @@ function renderLegendSvg(groups, options) {
|
|
|
25557
25554
|
track(pill.x, pill.y, pill.width, pill.height);
|
|
25558
25555
|
}
|
|
25559
25556
|
const classAttr = className ? ` class="${esc(className)}"` : "";
|
|
25560
|
-
const activeAttr = activeGroup ? ` data-legend-active="${esc(activeGroup
|
|
25557
|
+
const activeAttr = activeGroup ? ` data-legend-active="${esc(tagAttrKey(activeGroup))}"` : "";
|
|
25561
25558
|
const svg = `<g${classAttr}${activeAttr}>${parts.join("")}</g>`;
|
|
25562
25559
|
return {
|
|
25563
25560
|
svg,
|
|
@@ -30871,7 +30868,7 @@ function renderSitemap(container, parsed, layout, palette, isDark, onClickItem,
|
|
|
30871
30868
|
if (fixedLegend) {
|
|
30872
30869
|
const legendParent = svg.append("g").attr("class", "sitemap-legend-fixed").attr("transform", `translate(0, ${sDiagramPadding + fixedTitleH})`);
|
|
30873
30870
|
if (activeTagGroup) {
|
|
30874
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
30871
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
30875
30872
|
}
|
|
30876
30873
|
renderLegend(
|
|
30877
30874
|
legendParent,
|
|
@@ -41293,7 +41290,7 @@ function renderC4Context(container, parsed, layout, palette, isDark, onClickItem
|
|
|
41293
41290
|
if (hasLegend) {
|
|
41294
41291
|
const legendParent = fixedLegend ? svg.append("g").attr("class", "c4-legend-fixed").attr("transform", `translate(0, ${DIAGRAM_PADDING8 + titleHeight})`) : contentG.append("g").attr("class", "c4-legend");
|
|
41295
41292
|
if (activeTagGroup) {
|
|
41296
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
41293
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
41297
41294
|
}
|
|
41298
41295
|
renderLegend2(
|
|
41299
41296
|
legendParent,
|
|
@@ -41908,7 +41905,7 @@ function renderC4Containers(container, parsed, layout, palette, isDark, onClickI
|
|
|
41908
41905
|
if (hasLegend) {
|
|
41909
41906
|
const legendParent = fixedLegend ? svg.append("g").attr("class", "c4-legend-fixed").attr("transform", `translate(0, ${DIAGRAM_PADDING8 + titleHeight})`) : contentG.append("g").attr("class", "c4-legend");
|
|
41910
41907
|
if (activeTagGroup) {
|
|
41911
|
-
legendParent.attr("data-legend-active", activeTagGroup
|
|
41908
|
+
legendParent.attr("data-legend-active", tagAttrKey(activeTagGroup));
|
|
41912
41909
|
}
|
|
41913
41910
|
renderLegend2(
|
|
41914
41911
|
legendParent,
|
|
@@ -45581,7 +45578,7 @@ function renderLegend3(rootSvg, legendGroups, totalWidth, legendY, palette, isDa
|
|
|
45581
45578
|
const appHostedPlayback = controlsHost === "app" && !!playback;
|
|
45582
45579
|
const legendG = rootSvg.append("g").attr("transform", `translate(0, ${legendY})`);
|
|
45583
45580
|
if (activeGroup) {
|
|
45584
|
-
legendG.attr("data-legend-active", activeGroup
|
|
45581
|
+
legendG.attr("data-legend-active", tagAttrKey(activeGroup));
|
|
45585
45582
|
}
|
|
45586
45583
|
const allGroups = legendGroups.map((g) => ({
|
|
45587
45584
|
name: g.name,
|
|
@@ -68652,6 +68649,7 @@ async function exportVisualization(ctx) {
|
|
|
68652
68649
|
init_charts_d3();
|
|
68653
68650
|
|
|
68654
68651
|
// src/utils/hover-styles.ts
|
|
68652
|
+
init_tag_groups();
|
|
68655
68653
|
var MAX_HOVER_GROUPS = 40;
|
|
68656
68654
|
var DEFAULT_DIM_OPACITY = 0.4;
|
|
68657
68655
|
var LIFT_DECL = "filter:saturate(1.4) brightness(1.06)";
|
|
@@ -69046,7 +69044,7 @@ function deriveFromSvg(svg, spec) {
|
|
|
69046
69044
|
if (spec.groupAttrMode === "tag-active") {
|
|
69047
69045
|
const slug = root.querySelector("[data-legend-active]")?.getAttribute("data-legend-active");
|
|
69048
69046
|
if (slug) {
|
|
69049
|
-
groupAttr = `data-tag-${slug}`;
|
|
69047
|
+
groupAttr = `data-tag-${tagAttrKey(slug)}`;
|
|
69050
69048
|
} else {
|
|
69051
69049
|
const names = /* @__PURE__ */ new Set();
|
|
69052
69050
|
root.querySelectorAll(spec.markSelector).forEach((el) => {
|
|
@@ -69101,10 +69099,16 @@ var DOM_GLOBALS = [
|
|
|
69101
69099
|
"HTMLElement",
|
|
69102
69100
|
"SVGElement"
|
|
69103
69101
|
];
|
|
69104
|
-
var
|
|
69105
|
-
|
|
69106
|
-
|
|
69107
|
-
|
|
69102
|
+
var DOM_STATE_KEY = /* @__PURE__ */ Symbol.for("diagrammo.dgmo.dom-globals");
|
|
69103
|
+
function domState() {
|
|
69104
|
+
const g = globalThis;
|
|
69105
|
+
return g[DOM_STATE_KEY] ??= {
|
|
69106
|
+
refCount: 0,
|
|
69107
|
+
installPromise: null,
|
|
69108
|
+
installedByUs: false
|
|
69109
|
+
};
|
|
69110
|
+
}
|
|
69111
|
+
async function installDom(state) {
|
|
69108
69112
|
const { JSDOM } = await loadJsdom();
|
|
69109
69113
|
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
|
69110
69114
|
url: "http://localhost/"
|
|
@@ -69123,23 +69127,25 @@ async function installDom() {
|
|
|
69123
69127
|
configurable: true
|
|
69124
69128
|
});
|
|
69125
69129
|
}
|
|
69126
|
-
|
|
69130
|
+
state.installedByUs = true;
|
|
69127
69131
|
}
|
|
69128
69132
|
async function acquireDom() {
|
|
69129
|
-
|
|
69130
|
-
|
|
69131
|
-
|
|
69132
|
-
|
|
69133
|
+
const state = domState();
|
|
69134
|
+
if (typeof document !== "undefined" && !state.installedByUs) return;
|
|
69135
|
+
state.refCount++;
|
|
69136
|
+
if (!state.installPromise) state.installPromise = installDom(state);
|
|
69137
|
+
await state.installPromise;
|
|
69133
69138
|
}
|
|
69134
69139
|
function releaseDom() {
|
|
69135
|
-
|
|
69136
|
-
if (
|
|
69140
|
+
const state = domState();
|
|
69141
|
+
if (!state.installedByUs) return;
|
|
69142
|
+
if (--state.refCount > 0) return;
|
|
69137
69143
|
for (const key of DOM_GLOBALS) {
|
|
69138
69144
|
delete globalThis[key];
|
|
69139
69145
|
}
|
|
69140
|
-
|
|
69141
|
-
|
|
69142
|
-
|
|
69146
|
+
state.installedByUs = false;
|
|
69147
|
+
state.installPromise = null;
|
|
69148
|
+
state.refCount = 0;
|
|
69143
69149
|
}
|
|
69144
69150
|
async function loadJsdom() {
|
|
69145
69151
|
const spec = ["js", "dom"].join("");
|
package/package.json
CHANGED
package/src/auto/index.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Drop a `<script src="…/auto.js">` on any page; on `DOMContentLoaded`
|
|
5
5
|
* this module scans for `.dgmo, .language-dgmo`, runs `render()`, and
|
|
6
|
-
* replaces each match with
|
|
7
|
-
*
|
|
8
|
-
* "Open in editor" actions.
|
|
6
|
+
* replaces each match with the standard DGMO embed block (BL-114,
|
|
7
|
+
* `figure.dgmo.dgmo-rendered`) — the diagram plus a hover-reveal icon
|
|
8
|
+
* toolbar with view-source, Copy, and "Open in editor" actions.
|
|
9
9
|
*
|
|
10
10
|
* Public API: frozen `window.dgmo` and alias `window.diagrammo` with
|
|
11
11
|
* `{ initialize, run, version }`. Configuration is read from the
|
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
resolveTheme,
|
|
25
25
|
ensureStyles,
|
|
26
26
|
deriveAriaLabel,
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
buildRenderedBlock,
|
|
28
|
+
buildErrorBlock,
|
|
29
29
|
buildShareUrl,
|
|
30
30
|
} from './shared';
|
|
31
31
|
|
|
@@ -59,7 +59,7 @@ let activeConfig: Required<AutoConfig> = { ...DEFAULTS };
|
|
|
59
59
|
|
|
60
60
|
// Track wrappers so we can re-render on theme changes / re-runs.
|
|
61
61
|
interface TrackedWrapper {
|
|
62
|
-
wrapper:
|
|
62
|
+
wrapper: HTMLElement;
|
|
63
63
|
source: string;
|
|
64
64
|
perElementShowSource: boolean | null;
|
|
65
65
|
}
|
|
@@ -220,7 +220,28 @@ function determineReplaceTarget(matched: Element): Element {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
interface ProcessOutcome {
|
|
223
|
-
wrapper?:
|
|
223
|
+
wrapper?: HTMLElement;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Swap a failing source element for the standard `.dgmo--error` card (which
|
|
228
|
+
* carries the message AND the offending source — unified error shape across
|
|
229
|
+
* every embed surface). The card is marked `data-dgmo-processed` so a
|
|
230
|
+
* follow-up run() doesn't loop on it; users wanting to retry after editing
|
|
231
|
+
* should insert a fresh source element.
|
|
232
|
+
*/
|
|
233
|
+
function replaceWithErrorCard(
|
|
234
|
+
el: Element,
|
|
235
|
+
source: string,
|
|
236
|
+
opts: {
|
|
237
|
+
message: string;
|
|
238
|
+
severity?: string;
|
|
239
|
+
line?: number;
|
|
240
|
+
column?: number;
|
|
241
|
+
}
|
|
242
|
+
): void {
|
|
243
|
+
const card = buildErrorBlock({ ...opts, source });
|
|
244
|
+
determineReplaceTarget(el).replaceWith(card);
|
|
224
245
|
}
|
|
225
246
|
|
|
226
247
|
async function processElement(el: Element): Promise<ProcessOutcome> {
|
|
@@ -237,15 +258,10 @@ async function processElement(el: Element): Promise<ProcessOutcome> {
|
|
|
237
258
|
const source = el.textContent || '';
|
|
238
259
|
const sourceBytes = new TextEncoder().encode(source).byteLength;
|
|
239
260
|
if (sourceBytes > SOURCE_BYTE_CAP) {
|
|
240
|
-
el
|
|
241
|
-
// Keep `data-dgmo-processed` set so a follow-up run() doesn't loop on
|
|
242
|
-
// the same broken source. Users wanting to retry after editing should
|
|
243
|
-
// clear the attribute manually or replace the element. // un-hide so user can see the source
|
|
244
|
-
const banner = buildErrorBanner({
|
|
261
|
+
replaceWithErrorCard(el, source, {
|
|
245
262
|
message: `DGMO source too large to render — ${SOURCE_BYTE_CAP / 1024} KB max`,
|
|
246
263
|
severity: 'error',
|
|
247
264
|
});
|
|
248
|
-
el.parentElement?.insertBefore(banner, el);
|
|
249
265
|
warn('source exceeds 256 KB cap');
|
|
250
266
|
return {};
|
|
251
267
|
}
|
|
@@ -281,59 +297,40 @@ async function processElement(el: Element): Promise<ProcessOutcome> {
|
|
|
281
297
|
palette: cfg.palette,
|
|
282
298
|
});
|
|
283
299
|
} catch (err) {
|
|
284
|
-
el.style.visibility = '';
|
|
285
|
-
// Keep `data-dgmo-processed` set so a follow-up run() doesn't loop on
|
|
286
|
-
// the same broken source. Users wanting to retry after editing should
|
|
287
|
-
// clear the attribute manually or replace the element.
|
|
288
300
|
const message =
|
|
289
301
|
err instanceof Error ? err.message : 'Render failed unexpectedly';
|
|
290
|
-
|
|
291
|
-
el.parentElement?.insertBefore(banner, el);
|
|
302
|
+
replaceWithErrorCard(el, source, { message, severity: 'error' });
|
|
292
303
|
warn('render() rejected:', err);
|
|
293
304
|
return {};
|
|
294
305
|
}
|
|
295
306
|
|
|
296
307
|
if (result.diagnostics && result.diagnostics.length > 0) {
|
|
297
|
-
el.style.visibility = '';
|
|
298
|
-
// Keep `data-dgmo-processed` set so a follow-up run() doesn't loop on
|
|
299
|
-
// the same broken source. Users wanting to retry after editing should
|
|
300
|
-
// clear the attribute manually or replace the element.
|
|
301
308
|
const d = result.diagnostics[0]!; // In-bounds by length > 0 check above.
|
|
302
309
|
// d may have shape { severity, message, line, column } from diagnostics.ts
|
|
303
|
-
|
|
310
|
+
replaceWithErrorCard(el, source, {
|
|
304
311
|
message: d.message,
|
|
305
312
|
severity: d.severity,
|
|
306
313
|
line: d.line,
|
|
307
314
|
...(d.column !== undefined && { column: d.column }),
|
|
308
315
|
});
|
|
309
|
-
el.parentElement?.insertBefore(banner, el);
|
|
310
316
|
warn('diagnostic:', d.message, d.line, d.column);
|
|
311
317
|
return {};
|
|
312
318
|
}
|
|
313
319
|
|
|
314
320
|
if (!result.svg) {
|
|
315
|
-
el
|
|
316
|
-
// Keep `data-dgmo-processed` set so a follow-up run() doesn't loop on
|
|
317
|
-
// the same broken source. Users wanting to retry after editing should
|
|
318
|
-
// clear the attribute manually or replace the element.
|
|
319
|
-
const banner = buildErrorBanner({
|
|
321
|
+
replaceWithErrorCard(el, source, {
|
|
320
322
|
message: 'Empty SVG returned from renderer',
|
|
321
323
|
severity: 'error',
|
|
322
324
|
});
|
|
323
|
-
el.parentElement?.insertBefore(banner, el);
|
|
324
325
|
return {};
|
|
325
326
|
}
|
|
326
327
|
|
|
327
|
-
// Build wrapper.
|
|
328
|
-
const wrapper = document.createElement('div');
|
|
329
328
|
const themeClass =
|
|
330
329
|
resolvedTheme === 'dark'
|
|
331
330
|
? 'dgmo-theme-dark'
|
|
332
331
|
: resolvedTheme === 'transparent'
|
|
333
332
|
? 'dgmo-theme-transparent'
|
|
334
333
|
: 'dgmo-theme-light';
|
|
335
|
-
wrapper.className = `dgmo-rendered ${themeClass}`;
|
|
336
|
-
wrapper.dataset['dgmoProcessed'] = 'true';
|
|
337
334
|
|
|
338
335
|
// Insert SVG via a detached holder + post-insertion sanitization. The
|
|
339
336
|
// spec said "never assign user-supplied content to innerHTML"; we treat
|
|
@@ -349,15 +346,10 @@ async function processElement(el: Element): Promise<ProcessOutcome> {
|
|
|
349
346
|
svgHolder.innerHTML = result.svg;
|
|
350
347
|
const svgEl = svgHolder.querySelector('svg');
|
|
351
348
|
if (!svgEl) {
|
|
352
|
-
el
|
|
353
|
-
// Keep `data-dgmo-processed` set so a follow-up run() doesn't loop on
|
|
354
|
-
// the same broken source. Users wanting to retry after editing should
|
|
355
|
-
// clear the attribute manually or replace the element.
|
|
356
|
-
const banner = buildErrorBanner({
|
|
349
|
+
replaceWithErrorCard(el, source, {
|
|
357
350
|
message: 'Empty SVG returned from renderer',
|
|
358
351
|
severity: 'error',
|
|
359
352
|
});
|
|
360
|
-
el.parentElement?.insertBefore(banner, el);
|
|
361
353
|
return {};
|
|
362
354
|
}
|
|
363
355
|
sanitizeSvgInPlace(svgEl);
|
|
@@ -366,24 +358,30 @@ async function processElement(el: Element): Promise<ProcessOutcome> {
|
|
|
366
358
|
// control/bidi-strip filter rather than relying on renderer output).
|
|
367
359
|
svgEl.setAttribute('role', 'img');
|
|
368
360
|
svgEl.setAttribute('aria-label', ariaLabel);
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
utmSource: 'auto-embed',
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
const panel = buildSourcePanel(source, shareUrl, cfg.showEditorLink);
|
|
384
|
-
wrapper.appendChild(panel);
|
|
361
|
+
|
|
362
|
+
// Build share URL for the "Open in editor" toolbar action.
|
|
363
|
+
let shareUrl: string | null = null;
|
|
364
|
+
if (showSource && cfg.showEditorLink) {
|
|
365
|
+
shareUrl = buildShareUrl(source, {
|
|
366
|
+
palette: cfg.palette,
|
|
367
|
+
theme: resolvedTheme === 'dark' ? 'dark' : 'light',
|
|
368
|
+
editorBase: EDITOR_BASE_URL,
|
|
369
|
+
campaign: VERSION,
|
|
370
|
+
utmSource: 'auto-embed',
|
|
371
|
+
});
|
|
385
372
|
}
|
|
386
373
|
|
|
374
|
+
// Standard embed block (BL-114): canonical chrome from src/embed.
|
|
375
|
+
const wrapper = buildRenderedBlock({
|
|
376
|
+
source,
|
|
377
|
+
svgEl,
|
|
378
|
+
themeClass,
|
|
379
|
+
showSource,
|
|
380
|
+
showEditorLink: cfg.showEditorLink,
|
|
381
|
+
shareUrl,
|
|
382
|
+
});
|
|
383
|
+
wrapper.dataset['dgmoProcessed'] = 'true';
|
|
384
|
+
|
|
387
385
|
// Track wrapper so re-runs / theme changes can update it. Only persist
|
|
388
386
|
// the explicit 'true'/'false' values; treat any other value as null so
|
|
389
387
|
// the global default applies on re-render (matches first-render behavior).
|