structured-render 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/README.md +13 -0
- package/dist/augments/shadow-styles.d.ts +7 -0
- package/dist/augments/shadow-styles.js +17 -0
- package/dist/elements/vir-markdown.element.d.ts +16 -0
- package/dist/elements/vir-markdown.element.js +73 -0
- package/dist/elements/vir-source.element.d.ts +24 -0
- package/dist/elements/vir-source.element.js +158 -0
- package/dist/elements/vir-structured-render.element.d.ts +19 -0
- package/dist/elements/vir-structured-render.element.js +346 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/render/browser-rendering.d.ts +90 -0
- package/dist/render/browser-rendering.js +233 -0
- package/dist/render/html-to-pdf.d.ts +50 -0
- package/dist/render/html-to-pdf.js +7 -0
- package/dist/render/render-html.d.ts +38 -0
- package/dist/render/render-html.js +504 -0
- package/dist/render/render-image.d.ts +24 -0
- package/dist/render/render-image.js +35 -0
- package/dist/render/render-markdown-styles.d.ts +62 -0
- package/dist/render/render-markdown-styles.js +242 -0
- package/dist/render/render-markdown.d.ts +8 -0
- package/dist/render/render-markdown.js +169 -0
- package/dist/render/render-pdf.d.ts +35 -0
- package/dist/render/render-pdf.js +65 -0
- package/dist/render/render-types.d.ts +134 -0
- package/dist/render/render-types.js +41 -0
- package/dist/structured-render-data/create-section.d.ts +23 -0
- package/dist/structured-render-data/create-section.js +16 -0
- package/dist/structured-render-data/sections/code-block.section.d.ts +30 -0
- package/dist/structured-render-data/sections/code-block.section.js +11 -0
- package/dist/structured-render-data/sections/empty.section.d.ts +14 -0
- package/dist/structured-render-data/sections/empty.section.js +9 -0
- package/dist/structured-render-data/sections/icon.section.d.ts +25 -0
- package/dist/structured-render-data/sections/icon.section.js +40 -0
- package/dist/structured-render-data/sections/inline-code.section.d.ts +29 -0
- package/dist/structured-render-data/sections/inline-code.section.js +9 -0
- package/dist/structured-render-data/sections/list.section.d.ts +169 -0
- package/dist/structured-render-data/sections/list.section.js +29 -0
- package/dist/structured-render-data/sections/markdown.section.d.ts +29 -0
- package/dist/structured-render-data/sections/markdown.section.js +9 -0
- package/dist/structured-render-data/sections/processing.section.d.ts +14 -0
- package/dist/structured-render-data/sections/processing.section.js +9 -0
- package/dist/structured-render-data/sections/source.section.d.ts +59 -0
- package/dist/structured-render-data/sections/source.section.js +47 -0
- package/dist/structured-render-data/sections/table.section.d.ts +939 -0
- package/dist/structured-render-data/sections/table.section.js +99 -0
- package/dist/structured-render-data/sections/tag.section.d.ts +39 -0
- package/dist/structured-render-data/sections/tag.section.js +20 -0
- package/dist/structured-render-data/sections/text.section.d.ts +48 -0
- package/dist/structured-render-data/sections/text.section.js +25 -0
- package/dist/structured-render-data/structured-render-card.d.ts +918 -0
- package/dist/structured-render-data/structured-render-card.js +11 -0
- package/dist/structured-render-data/structured-render-data.d.ts +919 -0
- package/dist/structured-render-data/structured-render-data.js +8 -0
- package/dist/structured-render-data/structured-render-section.d.ts +1857 -0
- package/dist/structured-render-data/structured-render-section.js +115 -0
- package/package.json +75 -11
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { assert } from '@augment-vir/assert';
|
|
2
|
+
import { arrayToObject, ensureArray } from '@augment-vir/common';
|
|
3
|
+
import { unionShape } from 'object-shape-tester';
|
|
4
|
+
import { structuredRenderCodeBlockShape } from './sections/code-block.section.js';
|
|
5
|
+
import { structuredRenderEmptyShape } from './sections/empty.section.js';
|
|
6
|
+
import { structuredRenderIconShape } from './sections/icon.section.js';
|
|
7
|
+
import { structuredRenderInlineCodeShape } from './sections/inline-code.section.js';
|
|
8
|
+
import { structuredRenderListShape } from './sections/list.section.js';
|
|
9
|
+
import { renderDataMarkdownShape } from './sections/markdown.section.js';
|
|
10
|
+
import { structuredRenderProcessingShape } from './sections/processing.section.js';
|
|
11
|
+
import { sourceHasContent, structuredRenderSourceShape } from './sections/source.section.js';
|
|
12
|
+
import { structuredRenderTableShape } from './sections/table.section.js';
|
|
13
|
+
import { structuredRenderTagShape } from './sections/tag.section.js';
|
|
14
|
+
import { structuredRenderTextShape } from './sections/text.section.js';
|
|
15
|
+
/**
|
|
16
|
+
* All structured render section shapes.
|
|
17
|
+
*
|
|
18
|
+
* @category Internal
|
|
19
|
+
*/
|
|
20
|
+
export const allStructuredRenderSectionShapes = [
|
|
21
|
+
structuredRenderCodeBlockShape,
|
|
22
|
+
structuredRenderInlineCodeShape,
|
|
23
|
+
structuredRenderEmptyShape,
|
|
24
|
+
structuredRenderListShape,
|
|
25
|
+
renderDataMarkdownShape,
|
|
26
|
+
structuredRenderTagShape,
|
|
27
|
+
structuredRenderProcessingShape,
|
|
28
|
+
structuredRenderSourceShape,
|
|
29
|
+
structuredRenderTableShape,
|
|
30
|
+
structuredRenderTextShape,
|
|
31
|
+
structuredRenderIconShape,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
* A union of all structured render section shapes.
|
|
35
|
+
*
|
|
36
|
+
* @category Internal
|
|
37
|
+
*/
|
|
38
|
+
export const structuredRenderSectionShape = unionShape(...allStructuredRenderSectionShapes);
|
|
39
|
+
/**
|
|
40
|
+
* An enum of all supported structured render section types.
|
|
41
|
+
*
|
|
42
|
+
* @category Internal
|
|
43
|
+
*/
|
|
44
|
+
export const StructuredRenderSectionType = arrayToObject(allStructuredRenderSectionShapes, (sectionShape) => {
|
|
45
|
+
return {
|
|
46
|
+
key: sectionShape.default.type,
|
|
47
|
+
value: sectionShape.default.type,
|
|
48
|
+
};
|
|
49
|
+
}, {
|
|
50
|
+
useRequired: true,
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Checks if the given structured render section has any content.
|
|
54
|
+
*
|
|
55
|
+
* @category Util
|
|
56
|
+
*/
|
|
57
|
+
export function doesSectionHaveContent(section) {
|
|
58
|
+
if (!section) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
else if (section.type === StructuredRenderSectionType.list) {
|
|
62
|
+
return section.items.some((item) => ensureArray(item.content).some((content) => {
|
|
63
|
+
return doesSectionHaveContent(content);
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
else if (section.type === StructuredRenderSectionType.empty ||
|
|
67
|
+
section.type === StructuredRenderSectionType.processing) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
else if (section.type === StructuredRenderSectionType.tag) {
|
|
71
|
+
return !!section.text;
|
|
72
|
+
}
|
|
73
|
+
else if (section.type === StructuredRenderSectionType.codeBlock) {
|
|
74
|
+
return !!section.code;
|
|
75
|
+
}
|
|
76
|
+
else if (section.type === StructuredRenderSectionType.inlineCode) {
|
|
77
|
+
return !!section.code;
|
|
78
|
+
}
|
|
79
|
+
else if (section.type === StructuredRenderSectionType.markdown) {
|
|
80
|
+
return !!section.markdown;
|
|
81
|
+
}
|
|
82
|
+
else if (section.type === StructuredRenderSectionType.table) {
|
|
83
|
+
return section.entries.some((entry) => {
|
|
84
|
+
return Object.values(entry.data).some((value) => ensureArray(value).some((innerValue) => doesSectionHaveContent(innerValue)));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
else if (section.type === StructuredRenderSectionType.text) {
|
|
88
|
+
return !!String(section.text) || !!section.icon;
|
|
89
|
+
}
|
|
90
|
+
else if (section.type === StructuredRenderSectionType.source) {
|
|
91
|
+
return sourceHasContent(section);
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
93
|
+
}
|
|
94
|
+
else if (section.type === StructuredRenderSectionType.icon) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
assert.tsType(section).equals();
|
|
99
|
+
assert.never(`Unexpected section type: ${String(section.type)}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A helper for falling back to a different structured render section if the given structured render
|
|
104
|
+
* table is empty.
|
|
105
|
+
*
|
|
106
|
+
* @category Util
|
|
107
|
+
*/
|
|
108
|
+
export function emptyStructuredRenderTableFallback(table, fallback) {
|
|
109
|
+
if (doesSectionHaveContent(table)) {
|
|
110
|
+
return table;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return fallback;
|
|
114
|
+
}
|
|
115
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,77 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "structured-render",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A library for safely rendering arbitrary data generated from any source.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"render",
|
|
7
|
+
"data",
|
|
8
|
+
"structure",
|
|
9
|
+
"typed",
|
|
10
|
+
"markdown"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/electrovir/structured-render",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/electrovir/structured-render/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/electrovir/structured-render.git"
|
|
19
|
+
},
|
|
20
|
+
"license": "(MIT or CC0 1.0)",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "electrovir",
|
|
23
|
+
"url": "https://github.com/electrovir"
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "dist/index.js",
|
|
28
|
+
"module": "dist/index.js",
|
|
29
|
+
"types": "dist/index.d.ts",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "virmator frontend build",
|
|
32
|
+
"compile": "virmator compile",
|
|
33
|
+
"docs": "virmator docs",
|
|
34
|
+
"start": "virmator frontend",
|
|
35
|
+
"test": "runstorm --names web,node \"npm run test:web\" \"npm run test:node\"",
|
|
36
|
+
"test:docs": "virmator docs check",
|
|
37
|
+
"test:node": "virmator test node src/render/browser-rendering.test.node.ts",
|
|
38
|
+
"test:update": "npm run test:web update",
|
|
39
|
+
"test:web": "virmator test web"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@augment-vir/assert": "^31.65.0",
|
|
43
|
+
"@augment-vir/common": "^31.65.0",
|
|
44
|
+
"@augment-vir/web": "^31.65.0",
|
|
45
|
+
"@electrovir/color": "^1.7.8",
|
|
46
|
+
"dompurify": "^3.3.1",
|
|
47
|
+
"element-vir": "^26.14.3",
|
|
48
|
+
"html2pdf.js": "^0.14.0",
|
|
49
|
+
"lit-css-vars": "^3.5.0",
|
|
50
|
+
"marked": "^17.0.3",
|
|
51
|
+
"object-shape-tester": "^6.11.0",
|
|
52
|
+
"theme-vir": "^28.22.0",
|
|
53
|
+
"type-fest": "^5.4.4",
|
|
54
|
+
"vira": "^29.6.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@augment-vir/test": "^31.65.0",
|
|
58
|
+
"@virmator/test": "^14.7.2",
|
|
59
|
+
"@web/dev-server-esbuild": "^1.0.5",
|
|
60
|
+
"@web/test-runner": "^0.20.2",
|
|
61
|
+
"@web/test-runner-playwright": "^0.11.1",
|
|
62
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
63
|
+
"markdown-code-example-inserter": "^3.0.3",
|
|
64
|
+
"typedoc": "^0.28.17",
|
|
65
|
+
"typescript": "^5.9.3",
|
|
66
|
+
"vite": "^7.3.1"
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"playwright": "*"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=22"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
}
|
|
13
77
|
}
|