@kekonic/diagrams-build 1.0.0-rc.4
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 +21 -0
- package/README.md +9 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.mjs +63 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kekonic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# `@kekonic/diagrams-build`
|
|
2
|
+
|
|
3
|
+
Shared build-time contracts for first-party KDiagram adapters. Most applications should install a
|
|
4
|
+
host integration such as `@kekonic/diagrams-remark`,
|
|
5
|
+
`@kekonic/diagrams-markdown-it`, or `@kekonic/diagrams-unplugin` instead.
|
|
6
|
+
|
|
7
|
+
This package deliberately delegates parsing, layout, and rendering to the public
|
|
8
|
+
`@kekonic/diagrams` facade. It owns portable build defaults, diagnostic offsets, and virtual
|
|
9
|
+
module generation so integrations do not duplicate KDiagram behavior.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Diagnostic, RenderOptions } from "@kekonic/diagrams";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type KDiagramBuildOptions = {
|
|
5
|
+
renderOptions?: RenderOptions;
|
|
6
|
+
};
|
|
7
|
+
type KDiagramBuildResult = {
|
|
8
|
+
svg?: string;
|
|
9
|
+
diagnostics: Diagnostic[];
|
|
10
|
+
};
|
|
11
|
+
type KDiagramModuleKind = "svg" | "source" | "react" | "element";
|
|
12
|
+
/** Render portable static output through KDiagram's public facade. */
|
|
13
|
+
declare function renderKDiagramForBuild(source: string, options?: KDiagramBuildOptions): Promise<KDiagramBuildResult>;
|
|
14
|
+
/** Map a KDiagram-local diagnostic onto its containing host document. */
|
|
15
|
+
declare function offsetKDiagramDiagnostic<T extends Diagnostic>(diagnostic: T, contentStartLine: number): T & {
|
|
16
|
+
hostLine: number;
|
|
17
|
+
hostEndLine: number;
|
|
18
|
+
};
|
|
19
|
+
/** Generate the JavaScript boundary for a non-asset `.kdiagram` import. */
|
|
20
|
+
declare function createKDiagramModule(kind: KDiagramModuleKind, source: string, svg?: string): string;
|
|
21
|
+
declare function createKDiagramDataUrl(svg: string): string;
|
|
22
|
+
declare function formatKDiagramBuildError(diagnostics: Diagnostic[]): string;
|
|
23
|
+
declare function escapeKDiagramHtml(value: string): string;
|
|
24
|
+
declare function escapeKDiagramAttribute(value: string): string;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { KDiagramBuildOptions, KDiagramBuildResult, KDiagramModuleKind, createKDiagramDataUrl, createKDiagramModule, escapeKDiagramAttribute, escapeKDiagramHtml, formatKDiagramBuildError, offsetKDiagramDiagnostic, renderKDiagramForBuild };
|
|
27
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { KDiagram } from "@kekonic/diagrams";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/** Render portable static output through KDiagram's public facade. */
|
|
4
|
+
async function renderKDiagramForBuild(source, options = {}) {
|
|
5
|
+
return KDiagram.renderToSvg(source, {
|
|
6
|
+
snapshotTheme: true,
|
|
7
|
+
...options.renderOptions
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
/** Map a KDiagram-local diagnostic onto its containing host document. */
|
|
11
|
+
function offsetKDiagramDiagnostic(diagnostic, contentStartLine) {
|
|
12
|
+
const sourceStart = diagnostic.range?.start.line ?? 1;
|
|
13
|
+
const sourceEnd = diagnostic.range?.end.line ?? sourceStart;
|
|
14
|
+
return {
|
|
15
|
+
...diagnostic,
|
|
16
|
+
hostLine: contentStartLine + sourceStart - 1,
|
|
17
|
+
hostEndLine: contentStartLine + sourceEnd - 1
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Generate the JavaScript boundary for a non-asset `.kdiagram` import. */
|
|
21
|
+
function createKDiagramModule(kind, source, svg) {
|
|
22
|
+
if (kind === "source") return `export default ${JSON.stringify(source)};\n`;
|
|
23
|
+
if (kind === "svg") {
|
|
24
|
+
if (svg === void 0) throw new Error("SVG output is required for a ?svg module");
|
|
25
|
+
return `export default ${JSON.stringify(svg)};\n`;
|
|
26
|
+
}
|
|
27
|
+
if (kind === "react") return [
|
|
28
|
+
"import { createElement } from \"react\";",
|
|
29
|
+
"import { KDiagramLive } from \"@kekonic/diagrams-ui\";",
|
|
30
|
+
`export const source = ${JSON.stringify(source)};`,
|
|
31
|
+
"export default function KDiagramImportedDiagram(props = {}) {",
|
|
32
|
+
" return createElement(KDiagramLive, { ...props, source });",
|
|
33
|
+
"}",
|
|
34
|
+
""
|
|
35
|
+
].join("\n");
|
|
36
|
+
return [
|
|
37
|
+
"import { KDiagramElement } from \"@kekonic/diagrams-element\";",
|
|
38
|
+
`export const source = ${JSON.stringify(source)};`,
|
|
39
|
+
"export default class KDiagramImportedDiagram extends KDiagramElement {",
|
|
40
|
+
" constructor() {",
|
|
41
|
+
" super();",
|
|
42
|
+
" this.source = source;",
|
|
43
|
+
" }",
|
|
44
|
+
"}",
|
|
45
|
+
""
|
|
46
|
+
].join("\n");
|
|
47
|
+
}
|
|
48
|
+
function createKDiagramDataUrl(svg) {
|
|
49
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
50
|
+
}
|
|
51
|
+
function formatKDiagramBuildError(diagnostics) {
|
|
52
|
+
return diagnostics.map((diagnostic) => diagnostic.message).join("; ") || "Unable to render diagram";
|
|
53
|
+
}
|
|
54
|
+
function escapeKDiagramHtml(value) {
|
|
55
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
56
|
+
}
|
|
57
|
+
function escapeKDiagramAttribute(value) {
|
|
58
|
+
return escapeKDiagramHtml(value).replaceAll("\"", """);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { createKDiagramDataUrl, createKDiagramModule, escapeKDiagramAttribute, escapeKDiagramHtml, formatKDiagramBuildError, offsetKDiagramDiagnostic, renderKDiagramForBuild };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { KDiagram, type Diagnostic, type RenderOptions } from \"@kekonic/diagrams\";\n\nexport type KDiagramBuildOptions = {\n renderOptions?: RenderOptions;\n};\n\nexport type KDiagramBuildResult = {\n svg?: string;\n diagnostics: Diagnostic[];\n};\n\nexport type KDiagramModuleKind = \"svg\" | \"source\" | \"react\" | \"element\";\n\n/** Render portable static output through KDiagram's public facade. */\nexport async function renderKDiagramForBuild(\n source: string,\n options: KDiagramBuildOptions = {},\n): Promise<KDiagramBuildResult> {\n return KDiagram.renderToSvg(source, {\n snapshotTheme: true,\n ...options.renderOptions,\n });\n}\n\n/** Map a KDiagram-local diagnostic onto its containing host document. */\nexport function offsetKDiagramDiagnostic<T extends Diagnostic>(\n diagnostic: T,\n contentStartLine: number,\n): T & { hostLine: number; hostEndLine: number } {\n const sourceStart = diagnostic.range?.start.line ?? 1;\n const sourceEnd = diagnostic.range?.end.line ?? sourceStart;\n return {\n ...diagnostic,\n hostLine: contentStartLine + sourceStart - 1,\n hostEndLine: contentStartLine + sourceEnd - 1,\n };\n}\n\n/** Generate the JavaScript boundary for a non-asset `.kdiagram` import. */\nexport function createKDiagramModule(\n kind: KDiagramModuleKind,\n source: string,\n svg?: string,\n): string {\n if (kind === \"source\") return `export default ${JSON.stringify(source)};\\n`;\n if (kind === \"svg\") {\n if (svg === undefined) throw new Error(\"SVG output is required for a ?svg module\");\n return `export default ${JSON.stringify(svg)};\\n`;\n }\n if (kind === \"react\") {\n return [\n 'import { createElement } from \"react\";',\n 'import { KDiagramLive } from \"@kekonic/diagrams-ui\";',\n `export const source = ${JSON.stringify(source)};`,\n \"export default function KDiagramImportedDiagram(props = {}) {\",\n \" return createElement(KDiagramLive, { ...props, source });\",\n \"}\",\n \"\",\n ].join(\"\\n\");\n }\n return [\n 'import { KDiagramElement } from \"@kekonic/diagrams-element\";',\n `export const source = ${JSON.stringify(source)};`,\n \"export default class KDiagramImportedDiagram extends KDiagramElement {\",\n \" constructor() {\",\n \" super();\",\n \" this.source = source;\",\n \" }\",\n \"}\",\n \"\",\n ].join(\"\\n\");\n}\n\nexport function createKDiagramDataUrl(svg: string): string {\n return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;\n}\n\nexport function formatKDiagramBuildError(diagnostics: Diagnostic[]): string {\n return (\n diagnostics.map((diagnostic) => diagnostic.message).join(\"; \") || \"Unable to render diagram\"\n );\n}\n\nexport function escapeKDiagramHtml(value: string): string {\n return value.replaceAll(\"&\", \"&\").replaceAll(\"<\", \"<\").replaceAll(\">\", \">\");\n}\n\nexport function escapeKDiagramAttribute(value: string): string {\n return escapeKDiagramHtml(value).replaceAll('\"', \""\");\n}\n"],"mappings":";;;AAcA,eAAsB,uBACpB,QACA,UAAgC,CAAC,GACH;CAC9B,OAAO,SAAS,YAAY,QAAQ;EAClC,eAAe;EACf,GAAG,QAAQ;CACb,CAAC;AACH;;AAGA,SAAgB,yBACd,YACA,kBAC+C;CAC/C,MAAM,cAAc,WAAW,OAAO,MAAM,QAAQ;CACpD,MAAM,YAAY,WAAW,OAAO,IAAI,QAAQ;CAChD,OAAO;EACL,GAAG;EACH,UAAU,mBAAmB,cAAc;EAC3C,aAAa,mBAAmB,YAAY;CAC9C;AACF;;AAGA,SAAgB,qBACd,MACA,QACA,KACQ;CACR,IAAI,SAAS,UAAU,OAAO,kBAAkB,KAAK,UAAU,MAAM,EAAE;CACvE,IAAI,SAAS,OAAO;EAClB,IAAI,QAAQ,KAAA,GAAW,MAAM,IAAI,MAAM,0CAA0C;EACjF,OAAO,kBAAkB,KAAK,UAAU,GAAG,EAAE;CAC/C;CACA,IAAI,SAAS,SACX,OAAO;EACL;EACA;EACA,yBAAyB,KAAK,UAAU,MAAM,EAAE;EAChD;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;CAEb,OAAO;EACL;EACA,yBAAyB,KAAK,UAAU,MAAM,EAAE;EAChD;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;AAEA,SAAgB,sBAAsB,KAAqB;CACzD,OAAO,oCAAoC,mBAAmB,GAAG;AACnE;AAEA,SAAgB,yBAAyB,aAAmC;CAC1E,OACE,YAAY,KAAK,eAAe,WAAW,OAAO,CAAC,CAAC,KAAK,IAAI,KAAK;AAEtE;AAEA,SAAgB,mBAAmB,OAAuB;CACxD,OAAO,MAAM,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,KAAK,MAAM;AACtF;AAEA,SAAgB,wBAAwB,OAAuB;CAC7D,OAAO,mBAAmB,KAAK,CAAC,CAAC,WAAW,MAAK,QAAQ;AAC3D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kekonic/diagrams-build",
|
|
3
|
+
"version": "1.0.0-rc.4",
|
|
4
|
+
"description": "Shared build-time rendering contracts for KDiagram integrations.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"build",
|
|
7
|
+
"diagram",
|
|
8
|
+
"integration",
|
|
9
|
+
"kdiagram"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/kekonic/diagrams#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/kekonic/diagrams/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/kekonic/diagrams.git",
|
|
19
|
+
"directory": "packages/diagrams-build"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.mts",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@kekonic/diagrams": "1.0.0-rc.4"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22.18.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "vp pack",
|
|
42
|
+
"test": "vp test"
|
|
43
|
+
}
|
|
44
|
+
}
|