@frontmcp/uipack 0.12.2 → 1.0.0-beta.2
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/CLAUDE.md +56 -154
- package/README.md +367 -62
- package/adapters/base-template.d.ts +30 -0
- package/adapters/base-template.d.ts.map +1 -0
- package/adapters/cdn-info.d.ts +34 -0
- package/adapters/cdn-info.d.ts.map +1 -0
- package/adapters/constants.d.ts +18 -0
- package/adapters/constants.d.ts.map +1 -0
- package/adapters/content-detector.d.ts +19 -0
- package/adapters/content-detector.d.ts.map +1 -0
- package/adapters/content-renderers.d.ts +27 -0
- package/adapters/content-renderers.d.ts.map +1 -0
- package/adapters/index.d.ts +14 -7
- package/adapters/index.d.ts.map +1 -1
- package/adapters/index.js +2343 -426
- package/adapters/render-failure.d.ts +18 -0
- package/adapters/render-failure.d.ts.map +1 -0
- package/adapters/response-builder.d.ts +34 -104
- package/adapters/response-builder.d.ts.map +1 -1
- package/adapters/serving-mode.d.ts +28 -91
- package/adapters/serving-mode.d.ts.map +1 -1
- package/adapters/template-renderer.d.ts +50 -0
- package/adapters/template-renderer.d.ts.map +1 -0
- package/adapters/type-detector.d.ts +18 -0
- package/adapters/type-detector.d.ts.map +1 -0
- package/bridge-runtime/index.js +1 -1
- package/component/index.d.ts +14 -0
- package/component/index.d.ts.map +1 -0
- package/component/index.js +2043 -0
- package/component/loader.d.ts +36 -0
- package/component/loader.d.ts.map +1 -0
- package/component/renderer.d.ts +30 -0
- package/component/renderer.d.ts.map +1 -0
- package/component/transpiler.d.ts +49 -0
- package/component/transpiler.d.ts.map +1 -0
- package/component/types.d.ts +82 -0
- package/component/types.d.ts.map +1 -0
- package/esm/adapters/index.mjs +2337 -422
- package/esm/bridge-runtime/index.mjs +1 -1
- package/esm/component/index.mjs +2013 -0
- package/esm/index.mjs +3446 -13935
- package/esm/package.json +3 -12
- package/esm/resolver/index.mjs +661 -0
- package/esm/shell/index.mjs +1406 -0
- package/esm/types/index.mjs +11 -11
- package/esm/utils/index.mjs +53 -8
- package/index.d.ts +12 -40
- package/index.d.ts.map +1 -1
- package/index.js +3579 -14218
- package/package.json +3 -12
- package/resolver/cdn-registry.d.ts +39 -0
- package/resolver/cdn-registry.d.ts.map +1 -0
- package/resolver/esm-sh.resolver.d.ts +54 -0
- package/resolver/esm-sh.resolver.d.ts.map +1 -0
- package/resolver/import-map.d.ts +47 -0
- package/resolver/import-map.d.ts.map +1 -0
- package/resolver/import-parser.d.ts +28 -0
- package/resolver/import-parser.d.ts.map +1 -0
- package/resolver/import-rewriter.d.ts +29 -0
- package/resolver/import-rewriter.d.ts.map +1 -0
- package/resolver/index.d.ts +15 -0
- package/resolver/index.d.ts.map +1 -0
- package/resolver/index.js +708 -0
- package/resolver/types.d.ts +191 -0
- package/resolver/types.d.ts.map +1 -0
- package/shell/builder.d.ts +31 -0
- package/shell/builder.d.ts.map +1 -0
- package/shell/csp.d.ts +37 -0
- package/shell/csp.d.ts.map +1 -0
- package/shell/custom-shell-applier.d.ts +33 -0
- package/shell/custom-shell-applier.d.ts.map +1 -0
- package/shell/custom-shell-resolver.d.ts +47 -0
- package/shell/custom-shell-resolver.d.ts.map +1 -0
- package/shell/custom-shell-types.d.ts +75 -0
- package/shell/custom-shell-types.d.ts.map +1 -0
- package/shell/custom-shell-validator.d.ts +26 -0
- package/shell/custom-shell-validator.d.ts.map +1 -0
- package/shell/data-injector.d.ts +40 -0
- package/shell/data-injector.d.ts.map +1 -0
- package/shell/index.d.ts +19 -0
- package/shell/index.d.ts.map +1 -0
- package/shell/index.js +1453 -0
- package/shell/types.d.ts +54 -0
- package/shell/types.d.ts.map +1 -0
- package/types/index.d.ts +1 -3
- package/types/index.d.ts.map +1 -1
- package/types/index.js +11 -11
- package/types/ui-config.d.ts +50 -11
- package/types/ui-config.d.ts.map +1 -1
- package/types/ui-runtime.d.ts +8 -82
- package/types/ui-runtime.d.ts.map +1 -1
- package/utils/index.d.ts +9 -3
- package/utils/index.d.ts.map +1 -1
- package/utils/index.js +59 -7
- package/adapters/platform-meta.constants.d.ts +0 -26
- package/adapters/platform-meta.constants.d.ts.map +0 -1
- package/adapters/platform-meta.d.ts +0 -234
- package/adapters/platform-meta.d.ts.map +0 -1
- package/base-template/bridge.d.ts +0 -90
- package/base-template/bridge.d.ts.map +0 -1
- package/base-template/default-base-template.d.ts +0 -91
- package/base-template/default-base-template.d.ts.map +0 -1
- package/base-template/index.d.ts +0 -15
- package/base-template/index.d.ts.map +0 -1
- package/base-template/index.js +0 -1393
- package/base-template/polyfills.d.ts +0 -31
- package/base-template/polyfills.d.ts.map +0 -1
- package/base-template/theme-styles.d.ts +0 -74
- package/base-template/theme-styles.d.ts.map +0 -1
- package/build/builders/base-builder.d.ts +0 -124
- package/build/builders/base-builder.d.ts.map +0 -1
- package/build/builders/esbuild-config.d.ts +0 -94
- package/build/builders/esbuild-config.d.ts.map +0 -1
- package/build/builders/hybrid-builder.d.ts +0 -93
- package/build/builders/hybrid-builder.d.ts.map +0 -1
- package/build/builders/index.d.ts +0 -17
- package/build/builders/index.d.ts.map +0 -1
- package/build/builders/inline-builder.d.ts +0 -83
- package/build/builders/inline-builder.d.ts.map +0 -1
- package/build/builders/static-builder.d.ts +0 -78
- package/build/builders/static-builder.d.ts.map +0 -1
- package/build/builders/types.d.ts +0 -341
- package/build/builders/types.d.ts.map +0 -1
- package/build/cdn-resources.d.ts +0 -244
- package/build/cdn-resources.d.ts.map +0 -1
- package/build/hybrid-data.d.ts +0 -127
- package/build/hybrid-data.d.ts.map +0 -1
- package/build/index.d.ts +0 -299
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -8699
- package/build/ui-components-browser.d.ts +0 -64
- package/build/ui-components-browser.d.ts.map +0 -1
- package/build/widget-manifest.d.ts +0 -362
- package/build/widget-manifest.d.ts.map +0 -1
- package/bundler/cache.d.ts +0 -173
- package/bundler/cache.d.ts.map +0 -1
- package/bundler/file-cache/component-builder.d.ts +0 -167
- package/bundler/file-cache/component-builder.d.ts.map +0 -1
- package/bundler/file-cache/hash-calculator.d.ts +0 -155
- package/bundler/file-cache/hash-calculator.d.ts.map +0 -1
- package/bundler/file-cache/index.d.ts +0 -12
- package/bundler/file-cache/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/filesystem.d.ts +0 -149
- package/bundler/file-cache/storage/filesystem.d.ts.map +0 -1
- package/bundler/file-cache/storage/index.d.ts +0 -11
- package/bundler/file-cache/storage/index.d.ts.map +0 -1
- package/bundler/file-cache/storage/interface.d.ts +0 -152
- package/bundler/file-cache/storage/interface.d.ts.map +0 -1
- package/bundler/file-cache/storage/redis.d.ts +0 -139
- package/bundler/file-cache/storage/redis.d.ts.map +0 -1
- package/bundler/index.d.ts +0 -35
- package/bundler/index.d.ts.map +0 -1
- package/bundler/index.js +0 -2953
- package/bundler/sandbox/enclave-adapter.d.ts +0 -121
- package/bundler/sandbox/enclave-adapter.d.ts.map +0 -1
- package/bundler/sandbox/executor.d.ts +0 -14
- package/bundler/sandbox/executor.d.ts.map +0 -1
- package/bundler/sandbox/policy.d.ts +0 -62
- package/bundler/sandbox/policy.d.ts.map +0 -1
- package/bundler/types.d.ts +0 -702
- package/bundler/types.d.ts.map +0 -1
- package/dependency/cdn-registry.d.ts +0 -98
- package/dependency/cdn-registry.d.ts.map +0 -1
- package/dependency/import-map.d.ts +0 -186
- package/dependency/import-map.d.ts.map +0 -1
- package/dependency/import-parser.d.ts +0 -82
- package/dependency/import-parser.d.ts.map +0 -1
- package/dependency/index.d.ts +0 -17
- package/dependency/index.d.ts.map +0 -1
- package/dependency/index.js +0 -3180
- package/dependency/resolver.d.ts +0 -164
- package/dependency/resolver.d.ts.map +0 -1
- package/dependency/schemas.d.ts +0 -486
- package/dependency/schemas.d.ts.map +0 -1
- package/dependency/template-loader.d.ts +0 -204
- package/dependency/template-loader.d.ts.map +0 -1
- package/dependency/template-processor.d.ts +0 -118
- package/dependency/template-processor.d.ts.map +0 -1
- package/dependency/types.d.ts +0 -739
- package/dependency/types.d.ts.map +0 -1
- package/esm/base-template/index.mjs +0 -1359
- package/esm/build/index.mjs +0 -8601
- package/esm/bundler/index.mjs +0 -2895
- package/esm/dependency/index.mjs +0 -3068
- package/esm/handlebars/index.mjs +0 -587
- package/esm/registry/index.mjs +0 -6305
- package/esm/renderers/index.mjs +0 -1557
- package/esm/runtime/index.mjs +0 -5361
- package/esm/styles/index.mjs +0 -171
- package/esm/theme/index.mjs +0 -756
- package/esm/tool-template/index.mjs +0 -3652
- package/esm/validation/index.mjs +0 -542
- package/handlebars/expression-extractor.d.ts +0 -147
- package/handlebars/expression-extractor.d.ts.map +0 -1
- package/handlebars/helpers.d.ts +0 -339
- package/handlebars/helpers.d.ts.map +0 -1
- package/handlebars/index.d.ts +0 -195
- package/handlebars/index.d.ts.map +0 -1
- package/handlebars/index.js +0 -659
- package/preview/claude-preview.d.ts +0 -67
- package/preview/claude-preview.d.ts.map +0 -1
- package/preview/generic-preview.d.ts +0 -66
- package/preview/generic-preview.d.ts.map +0 -1
- package/preview/index.d.ts +0 -36
- package/preview/index.d.ts.map +0 -1
- package/preview/openai-preview.d.ts +0 -70
- package/preview/openai-preview.d.ts.map +0 -1
- package/preview/types.d.ts +0 -199
- package/preview/types.d.ts.map +0 -1
- package/registry/index.d.ts +0 -46
- package/registry/index.d.ts.map +0 -1
- package/registry/index.js +0 -6342
- package/registry/render-template.d.ts +0 -91
- package/registry/render-template.d.ts.map +0 -1
- package/registry/tool-ui.registry.d.ts +0 -294
- package/registry/tool-ui.registry.d.ts.map +0 -1
- package/registry/uri-utils.d.ts +0 -56
- package/registry/uri-utils.d.ts.map +0 -1
- package/renderers/cache.d.ts +0 -145
- package/renderers/cache.d.ts.map +0 -1
- package/renderers/html.renderer.d.ts +0 -123
- package/renderers/html.renderer.d.ts.map +0 -1
- package/renderers/index.d.ts +0 -36
- package/renderers/index.d.ts.map +0 -1
- package/renderers/index.js +0 -1603
- package/renderers/mdx-client.renderer.d.ts +0 -124
- package/renderers/mdx-client.renderer.d.ts.map +0 -1
- package/renderers/registry.d.ts +0 -133
- package/renderers/registry.d.ts.map +0 -1
- package/renderers/types.d.ts +0 -343
- package/renderers/types.d.ts.map +0 -1
- package/renderers/utils/detect.d.ts +0 -107
- package/renderers/utils/detect.d.ts.map +0 -1
- package/renderers/utils/hash.d.ts +0 -40
- package/renderers/utils/hash.d.ts.map +0 -1
- package/renderers/utils/index.d.ts +0 -9
- package/renderers/utils/index.d.ts.map +0 -1
- package/renderers/utils/transpiler.d.ts +0 -70
- package/renderers/utils/transpiler.d.ts.map +0 -1
- package/runtime/adapters/html.adapter.d.ts +0 -59
- package/runtime/adapters/html.adapter.d.ts.map +0 -1
- package/runtime/adapters/index.d.ts +0 -26
- package/runtime/adapters/index.d.ts.map +0 -1
- package/runtime/adapters/mdx.adapter.d.ts +0 -73
- package/runtime/adapters/mdx.adapter.d.ts.map +0 -1
- package/runtime/adapters/types.d.ts +0 -95
- package/runtime/adapters/types.d.ts.map +0 -1
- package/runtime/csp.d.ts +0 -48
- package/runtime/csp.d.ts.map +0 -1
- package/runtime/index.d.ts +0 -17
- package/runtime/index.d.ts.map +0 -1
- package/runtime/index.js +0 -5432
- package/runtime/mcp-bridge.d.ts +0 -101
- package/runtime/mcp-bridge.d.ts.map +0 -1
- package/runtime/renderer-runtime.d.ts +0 -133
- package/runtime/renderer-runtime.d.ts.map +0 -1
- package/runtime/sanitizer.d.ts +0 -180
- package/runtime/sanitizer.d.ts.map +0 -1
- package/runtime/types.d.ts +0 -415
- package/runtime/types.d.ts.map +0 -1
- package/runtime/wrapper.d.ts +0 -421
- package/runtime/wrapper.d.ts.map +0 -1
- package/styles/index.d.ts +0 -8
- package/styles/index.d.ts.map +0 -1
- package/styles/index.js +0 -222
- package/styles/variants.d.ts +0 -51
- package/styles/variants.d.ts.map +0 -1
- package/theme/cdn.d.ts +0 -195
- package/theme/cdn.d.ts.map +0 -1
- package/theme/css-to-theme.d.ts +0 -64
- package/theme/css-to-theme.d.ts.map +0 -1
- package/theme/index.d.ts +0 -19
- package/theme/index.d.ts.map +0 -1
- package/theme/index.js +0 -814
- package/theme/platforms.d.ts +0 -102
- package/theme/platforms.d.ts.map +0 -1
- package/theme/presets/github-openai.d.ts +0 -50
- package/theme/presets/github-openai.d.ts.map +0 -1
- package/theme/presets/index.d.ts +0 -11
- package/theme/presets/index.d.ts.map +0 -1
- package/theme/theme.d.ts +0 -396
- package/theme/theme.d.ts.map +0 -1
- package/tool-template/builder.d.ts +0 -213
- package/tool-template/builder.d.ts.map +0 -1
- package/tool-template/index.d.ts +0 -16
- package/tool-template/index.d.ts.map +0 -1
- package/tool-template/index.js +0 -3690
- package/validation/error-box.d.ts +0 -56
- package/validation/error-box.d.ts.map +0 -1
- package/validation/index.d.ts +0 -13
- package/validation/index.d.ts.map +0 -1
- package/validation/index.js +0 -576
- package/validation/schema-paths.d.ts +0 -118
- package/validation/schema-paths.d.ts.map +0 -1
- package/validation/template-validator.d.ts +0 -143
- package/validation/template-validator.d.ts.map +0 -1
- package/validation/wrapper.d.ts +0 -97
- package/validation/wrapper.d.ts.map +0 -1
package/renderers/index.js
DELETED
|
@@ -1,1603 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __esm = (fn, res) => function __init() {
|
|
9
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
|
|
33
|
-
// libs/uipack/src/utils/index.ts
|
|
34
|
-
var import_utils;
|
|
35
|
-
var init_utils = __esm({
|
|
36
|
-
"libs/uipack/src/utils/index.ts"() {
|
|
37
|
-
"use strict";
|
|
38
|
-
import_utils = require("@frontmcp/utils");
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// libs/uipack/src/handlebars/helpers.ts
|
|
43
|
-
function formatDate(date, format) {
|
|
44
|
-
if (date === null || date === void 0) {
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
|
-
let dateObj;
|
|
48
|
-
if (date instanceof Date) {
|
|
49
|
-
dateObj = date;
|
|
50
|
-
} else if (typeof date === "string" || typeof date === "number") {
|
|
51
|
-
dateObj = new Date(date);
|
|
52
|
-
} else {
|
|
53
|
-
return String(date);
|
|
54
|
-
}
|
|
55
|
-
if (isNaN(dateObj.getTime())) {
|
|
56
|
-
return String(date);
|
|
57
|
-
}
|
|
58
|
-
const options = {};
|
|
59
|
-
switch (format) {
|
|
60
|
-
case "short":
|
|
61
|
-
options.dateStyle = "short";
|
|
62
|
-
break;
|
|
63
|
-
case "medium":
|
|
64
|
-
options.dateStyle = "medium";
|
|
65
|
-
break;
|
|
66
|
-
case "long":
|
|
67
|
-
options.dateStyle = "long";
|
|
68
|
-
break;
|
|
69
|
-
case "full":
|
|
70
|
-
options.dateStyle = "full";
|
|
71
|
-
break;
|
|
72
|
-
case "time":
|
|
73
|
-
options.timeStyle = "short";
|
|
74
|
-
break;
|
|
75
|
-
case "datetime":
|
|
76
|
-
options.dateStyle = "medium";
|
|
77
|
-
options.timeStyle = "short";
|
|
78
|
-
break;
|
|
79
|
-
case "iso":
|
|
80
|
-
return dateObj.toISOString();
|
|
81
|
-
case "relative":
|
|
82
|
-
return formatRelativeDate(dateObj);
|
|
83
|
-
default:
|
|
84
|
-
options.dateStyle = "medium";
|
|
85
|
-
}
|
|
86
|
-
return new Intl.DateTimeFormat("en-US", options).format(dateObj);
|
|
87
|
-
}
|
|
88
|
-
function formatRelativeDate(date) {
|
|
89
|
-
const now = /* @__PURE__ */ new Date();
|
|
90
|
-
const diffMs = now.getTime() - date.getTime();
|
|
91
|
-
const diffSecs = Math.floor(diffMs / 1e3);
|
|
92
|
-
const diffMins = Math.floor(diffSecs / 60);
|
|
93
|
-
const diffHours = Math.floor(diffMins / 60);
|
|
94
|
-
const diffDays = Math.floor(diffHours / 24);
|
|
95
|
-
if (diffSecs < 60) {
|
|
96
|
-
return "just now";
|
|
97
|
-
} else if (diffMins < 60) {
|
|
98
|
-
return `${diffMins} minute${diffMins === 1 ? "" : "s"} ago`;
|
|
99
|
-
} else if (diffHours < 24) {
|
|
100
|
-
return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
|
|
101
|
-
} else if (diffDays < 7) {
|
|
102
|
-
return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
|
|
103
|
-
} else {
|
|
104
|
-
return formatDate(date, "medium");
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function formatCurrency(amount, currency) {
|
|
108
|
-
if (amount === null || amount === void 0) {
|
|
109
|
-
return "";
|
|
110
|
-
}
|
|
111
|
-
const num = typeof amount === "number" ? amount : parseFloat(String(amount));
|
|
112
|
-
if (isNaN(num)) {
|
|
113
|
-
return String(amount);
|
|
114
|
-
}
|
|
115
|
-
return new Intl.NumberFormat("en-US", {
|
|
116
|
-
style: "currency",
|
|
117
|
-
currency: typeof currency === "string" ? currency : "USD"
|
|
118
|
-
}).format(num);
|
|
119
|
-
}
|
|
120
|
-
function formatNumber(value, decimals) {
|
|
121
|
-
if (value === null || value === void 0) {
|
|
122
|
-
return "";
|
|
123
|
-
}
|
|
124
|
-
const num = typeof value === "number" ? value : parseFloat(String(value));
|
|
125
|
-
if (isNaN(num)) {
|
|
126
|
-
return String(value);
|
|
127
|
-
}
|
|
128
|
-
const options = {};
|
|
129
|
-
if (typeof decimals === "number") {
|
|
130
|
-
options.minimumFractionDigits = decimals;
|
|
131
|
-
options.maximumFractionDigits = decimals;
|
|
132
|
-
}
|
|
133
|
-
return new Intl.NumberFormat("en-US", options).format(num);
|
|
134
|
-
}
|
|
135
|
-
function jsonEmbed(data) {
|
|
136
|
-
const json2 = JSON.stringify(data ?? null);
|
|
137
|
-
return json2.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
138
|
-
}
|
|
139
|
-
function json(data, pretty) {
|
|
140
|
-
return JSON.stringify(data ?? null, null, pretty ? 2 : void 0);
|
|
141
|
-
}
|
|
142
|
-
function eq(a, b) {
|
|
143
|
-
return a === b;
|
|
144
|
-
}
|
|
145
|
-
function ne(a, b) {
|
|
146
|
-
return a !== b;
|
|
147
|
-
}
|
|
148
|
-
function gt(a, b) {
|
|
149
|
-
return Number(a) > Number(b);
|
|
150
|
-
}
|
|
151
|
-
function gte(a, b) {
|
|
152
|
-
return Number(a) >= Number(b);
|
|
153
|
-
}
|
|
154
|
-
function lt(a, b) {
|
|
155
|
-
return Number(a) < Number(b);
|
|
156
|
-
}
|
|
157
|
-
function lte(a, b) {
|
|
158
|
-
return Number(a) <= Number(b);
|
|
159
|
-
}
|
|
160
|
-
function and(a, b) {
|
|
161
|
-
return Boolean(a) && Boolean(b);
|
|
162
|
-
}
|
|
163
|
-
function or(a, b) {
|
|
164
|
-
return Boolean(a) || Boolean(b);
|
|
165
|
-
}
|
|
166
|
-
function not(value) {
|
|
167
|
-
return !value;
|
|
168
|
-
}
|
|
169
|
-
function first(arr) {
|
|
170
|
-
if (!Array.isArray(arr)) return void 0;
|
|
171
|
-
return arr[0];
|
|
172
|
-
}
|
|
173
|
-
function last(arr) {
|
|
174
|
-
if (!Array.isArray(arr)) return void 0;
|
|
175
|
-
return arr[arr.length - 1];
|
|
176
|
-
}
|
|
177
|
-
function length(value) {
|
|
178
|
-
if (Array.isArray(value)) return value.length;
|
|
179
|
-
if (typeof value === "string") return value.length;
|
|
180
|
-
return 0;
|
|
181
|
-
}
|
|
182
|
-
function includes(arr, value) {
|
|
183
|
-
if (!Array.isArray(arr)) return false;
|
|
184
|
-
return arr.includes(value);
|
|
185
|
-
}
|
|
186
|
-
function join(arr, separator) {
|
|
187
|
-
if (!Array.isArray(arr)) return "";
|
|
188
|
-
return arr.join(typeof separator === "string" ? separator : ", ");
|
|
189
|
-
}
|
|
190
|
-
function uppercase(str) {
|
|
191
|
-
return String(str ?? "").toUpperCase();
|
|
192
|
-
}
|
|
193
|
-
function lowercase(str) {
|
|
194
|
-
return String(str ?? "").toLowerCase();
|
|
195
|
-
}
|
|
196
|
-
function capitalize(str) {
|
|
197
|
-
const s = String(str ?? "");
|
|
198
|
-
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
199
|
-
}
|
|
200
|
-
function truncate(str, maxLength, suffix) {
|
|
201
|
-
const s = String(str ?? "");
|
|
202
|
-
const len = typeof maxLength === "number" ? maxLength : 50;
|
|
203
|
-
const suf = typeof suffix === "string" ? suffix : "...";
|
|
204
|
-
if (s.length <= len) return s;
|
|
205
|
-
return s.slice(0, len - suf.length) + suf;
|
|
206
|
-
}
|
|
207
|
-
function defaultValue(value, defaultValue2) {
|
|
208
|
-
return value || defaultValue2;
|
|
209
|
-
}
|
|
210
|
-
function uniqueId(prefix) {
|
|
211
|
-
const id = ++idCounter;
|
|
212
|
-
return prefix ? `${prefix}-${id}` : `id-${id}`;
|
|
213
|
-
}
|
|
214
|
-
function resetUniqueIdCounter() {
|
|
215
|
-
idCounter = 0;
|
|
216
|
-
}
|
|
217
|
-
function classNames(...classes) {
|
|
218
|
-
return classes.filter(Boolean).map(String).join(" ");
|
|
219
|
-
}
|
|
220
|
-
var idCounter, builtinHelpers;
|
|
221
|
-
var init_helpers = __esm({
|
|
222
|
-
"libs/uipack/src/handlebars/helpers.ts"() {
|
|
223
|
-
"use strict";
|
|
224
|
-
init_utils();
|
|
225
|
-
idCounter = 0;
|
|
226
|
-
builtinHelpers = {
|
|
227
|
-
// Escaping
|
|
228
|
-
escapeHtml: import_utils.escapeHtml,
|
|
229
|
-
// Formatting
|
|
230
|
-
formatDate,
|
|
231
|
-
formatCurrency,
|
|
232
|
-
formatNumber,
|
|
233
|
-
json,
|
|
234
|
-
jsonEmbed,
|
|
235
|
-
// Comparison
|
|
236
|
-
eq,
|
|
237
|
-
ne,
|
|
238
|
-
gt,
|
|
239
|
-
gte,
|
|
240
|
-
lt,
|
|
241
|
-
lte,
|
|
242
|
-
// Logical
|
|
243
|
-
and,
|
|
244
|
-
or,
|
|
245
|
-
not,
|
|
246
|
-
// Array
|
|
247
|
-
first,
|
|
248
|
-
last,
|
|
249
|
-
length,
|
|
250
|
-
includes,
|
|
251
|
-
join,
|
|
252
|
-
// String
|
|
253
|
-
uppercase,
|
|
254
|
-
lowercase,
|
|
255
|
-
capitalize,
|
|
256
|
-
truncate,
|
|
257
|
-
// Utility
|
|
258
|
-
default: defaultValue,
|
|
259
|
-
uniqueId,
|
|
260
|
-
classNames
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// libs/uipack/src/handlebars/expression-extractor.ts
|
|
266
|
-
function extractExpressions(template) {
|
|
267
|
-
const expressions = [];
|
|
268
|
-
const positionMap = buildPositionMap(template);
|
|
269
|
-
let match;
|
|
270
|
-
EXPRESSION_REGEX.lastIndex = 0;
|
|
271
|
-
while ((match = EXPRESSION_REGEX.exec(template)) !== null) {
|
|
272
|
-
const fullExpression = match[0];
|
|
273
|
-
const prefix = match[1];
|
|
274
|
-
const content = match[2].trim();
|
|
275
|
-
const position = positionMap.get(match.index) ?? { line: 1, column: 1 };
|
|
276
|
-
let type = "variable";
|
|
277
|
-
let helperName;
|
|
278
|
-
if (prefix === "/") {
|
|
279
|
-
type = "block-close";
|
|
280
|
-
helperName = content;
|
|
281
|
-
} else if (prefix === "#") {
|
|
282
|
-
type = "block";
|
|
283
|
-
const parts = content.split(/\s+/);
|
|
284
|
-
helperName = parts[0];
|
|
285
|
-
} else {
|
|
286
|
-
const parts = content.split(/\s+/);
|
|
287
|
-
if (parts.length > 1 && !content.startsWith("(")) {
|
|
288
|
-
const firstToken = parts[0];
|
|
289
|
-
if (!firstToken.includes(".") && !KEYWORDS.has(firstToken)) {
|
|
290
|
-
type = "helper";
|
|
291
|
-
helperName = firstToken;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
const paths = extractPathsFromContent(content);
|
|
296
|
-
for (const path of paths) {
|
|
297
|
-
expressions.push({
|
|
298
|
-
path,
|
|
299
|
-
fullExpression,
|
|
300
|
-
line: position.line,
|
|
301
|
-
column: position.column,
|
|
302
|
-
type,
|
|
303
|
-
helperName
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
if (paths.length === 0 && type === "variable") {
|
|
307
|
-
const cleanContent = content.trim();
|
|
308
|
-
if (!KEYWORDS.has(cleanContent) && !cleanContent.includes(" ") && !cleanContent.startsWith("(")) {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return expressions;
|
|
313
|
-
}
|
|
314
|
-
function extractPathsFromContent(content) {
|
|
315
|
-
const paths = [];
|
|
316
|
-
let match;
|
|
317
|
-
const regex = new RegExp(PATH_REGEX.source, "g");
|
|
318
|
-
while ((match = regex.exec(content)) !== null) {
|
|
319
|
-
paths.push(match[0]);
|
|
320
|
-
}
|
|
321
|
-
return paths;
|
|
322
|
-
}
|
|
323
|
-
function buildPositionMap(template) {
|
|
324
|
-
const map = /* @__PURE__ */ new Map();
|
|
325
|
-
let line = 1;
|
|
326
|
-
let column = 1;
|
|
327
|
-
for (let i = 0; i < template.length; i++) {
|
|
328
|
-
map.set(i, { line, column });
|
|
329
|
-
if (template[i] === "\n") {
|
|
330
|
-
line++;
|
|
331
|
-
column = 1;
|
|
332
|
-
} else {
|
|
333
|
-
column++;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return map;
|
|
337
|
-
}
|
|
338
|
-
function extractVariablePaths(template) {
|
|
339
|
-
const expressions = extractExpressions(template);
|
|
340
|
-
const paths = new Set(expressions.map((e) => e.path));
|
|
341
|
-
return Array.from(paths);
|
|
342
|
-
}
|
|
343
|
-
function extractOutputPaths(template) {
|
|
344
|
-
return extractVariablePaths(template).filter((p) => p.startsWith("output."));
|
|
345
|
-
}
|
|
346
|
-
function extractInputPaths(template) {
|
|
347
|
-
return extractVariablePaths(template).filter((p) => p.startsWith("input."));
|
|
348
|
-
}
|
|
349
|
-
function extractStructuredContentPaths(template) {
|
|
350
|
-
return extractVariablePaths(template).filter((p) => p.startsWith("structuredContent."));
|
|
351
|
-
}
|
|
352
|
-
function extractAll(template) {
|
|
353
|
-
const expressions = extractExpressions(template);
|
|
354
|
-
const paths = [...new Set(expressions.map((e) => e.path))];
|
|
355
|
-
return {
|
|
356
|
-
expressions,
|
|
357
|
-
paths,
|
|
358
|
-
outputPaths: paths.filter((p) => p.startsWith("output.")),
|
|
359
|
-
inputPaths: paths.filter((p) => p.startsWith("input.")),
|
|
360
|
-
structuredContentPaths: paths.filter((p) => p.startsWith("structuredContent."))
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function hasVariablePaths(template) {
|
|
364
|
-
return extractVariablePaths(template).length > 0;
|
|
365
|
-
}
|
|
366
|
-
function getExpressionAt(template, line, column) {
|
|
367
|
-
const expressions = extractExpressions(template);
|
|
368
|
-
return expressions.find((expr) => {
|
|
369
|
-
if (expr.line !== line) return false;
|
|
370
|
-
const exprEnd = expr.column + expr.fullExpression.length;
|
|
371
|
-
return column >= expr.column && column <= exprEnd;
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
function normalizePath(path) {
|
|
375
|
-
return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
|
|
376
|
-
}
|
|
377
|
-
var EXPRESSION_REGEX, PATH_REGEX, KEYWORDS;
|
|
378
|
-
var init_expression_extractor = __esm({
|
|
379
|
-
"libs/uipack/src/handlebars/expression-extractor.ts"() {
|
|
380
|
-
"use strict";
|
|
381
|
-
EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
|
|
382
|
-
PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
|
|
383
|
-
KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// libs/uipack/src/handlebars/index.ts
|
|
388
|
-
var handlebars_exports = {};
|
|
389
|
-
__export(handlebars_exports, {
|
|
390
|
-
HandlebarsRenderer: () => HandlebarsRenderer,
|
|
391
|
-
and: () => and,
|
|
392
|
-
builtinHelpers: () => builtinHelpers,
|
|
393
|
-
capitalize: () => capitalize,
|
|
394
|
-
classNames: () => classNames,
|
|
395
|
-
containsHandlebars: () => containsHandlebars,
|
|
396
|
-
createHandlebarsRenderer: () => createHandlebarsRenderer,
|
|
397
|
-
defaultValue: () => defaultValue,
|
|
398
|
-
eq: () => eq,
|
|
399
|
-
escapeHtml: () => import_utils.escapeHtml,
|
|
400
|
-
extractAll: () => extractAll,
|
|
401
|
-
extractExpressions: () => extractExpressions,
|
|
402
|
-
extractInputPaths: () => extractInputPaths,
|
|
403
|
-
extractOutputPaths: () => extractOutputPaths,
|
|
404
|
-
extractStructuredContentPaths: () => extractStructuredContentPaths,
|
|
405
|
-
extractVariablePaths: () => extractVariablePaths,
|
|
406
|
-
first: () => first,
|
|
407
|
-
formatCurrency: () => formatCurrency,
|
|
408
|
-
formatDate: () => formatDate,
|
|
409
|
-
formatNumber: () => formatNumber,
|
|
410
|
-
getExpressionAt: () => getExpressionAt,
|
|
411
|
-
gt: () => gt,
|
|
412
|
-
gte: () => gte,
|
|
413
|
-
hasVariablePaths: () => hasVariablePaths,
|
|
414
|
-
includes: () => includes,
|
|
415
|
-
isHandlebarsAvailable: () => isHandlebarsAvailable,
|
|
416
|
-
join: () => join,
|
|
417
|
-
json: () => json,
|
|
418
|
-
jsonEmbed: () => jsonEmbed,
|
|
419
|
-
last: () => last,
|
|
420
|
-
length: () => length,
|
|
421
|
-
lowercase: () => lowercase,
|
|
422
|
-
lt: () => lt,
|
|
423
|
-
lte: () => lte,
|
|
424
|
-
ne: () => ne,
|
|
425
|
-
normalizePath: () => normalizePath,
|
|
426
|
-
not: () => not,
|
|
427
|
-
or: () => or,
|
|
428
|
-
renderTemplate: () => renderTemplate,
|
|
429
|
-
resetUniqueIdCounter: () => resetUniqueIdCounter,
|
|
430
|
-
truncate: () => truncate,
|
|
431
|
-
uniqueId: () => uniqueId,
|
|
432
|
-
uppercase: () => uppercase
|
|
433
|
-
});
|
|
434
|
-
async function loadHandlebars() {
|
|
435
|
-
if (Handlebars !== null) {
|
|
436
|
-
return Handlebars;
|
|
437
|
-
}
|
|
438
|
-
try {
|
|
439
|
-
Handlebars = await import("handlebars");
|
|
440
|
-
return Handlebars;
|
|
441
|
-
} catch {
|
|
442
|
-
throw new Error("Handlebars is required for template rendering. Install it: npm install handlebars");
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async function isHandlebarsAvailable() {
|
|
446
|
-
try {
|
|
447
|
-
await loadHandlebars();
|
|
448
|
-
return true;
|
|
449
|
-
} catch {
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
function createHandlebarsRenderer(options) {
|
|
454
|
-
return new HandlebarsRenderer(options);
|
|
455
|
-
}
|
|
456
|
-
async function renderTemplate(template, context) {
|
|
457
|
-
const renderer = createHandlebarsRenderer();
|
|
458
|
-
return renderer.render(template, context);
|
|
459
|
-
}
|
|
460
|
-
function containsHandlebars(template) {
|
|
461
|
-
return HandlebarsRenderer.containsHandlebars(template);
|
|
462
|
-
}
|
|
463
|
-
var Handlebars, HandlebarsRenderer;
|
|
464
|
-
var init_handlebars = __esm({
|
|
465
|
-
"libs/uipack/src/handlebars/index.ts"() {
|
|
466
|
-
"use strict";
|
|
467
|
-
init_helpers();
|
|
468
|
-
init_helpers();
|
|
469
|
-
init_expression_extractor();
|
|
470
|
-
Handlebars = null;
|
|
471
|
-
HandlebarsRenderer = class {
|
|
472
|
-
options;
|
|
473
|
-
compiledTemplates = /* @__PURE__ */ new Map();
|
|
474
|
-
initialized = false;
|
|
475
|
-
hbs = null;
|
|
476
|
-
constructor(options = {}) {
|
|
477
|
-
this.options = {
|
|
478
|
-
strict: false,
|
|
479
|
-
autoEscape: true,
|
|
480
|
-
...options
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
/**
|
|
484
|
-
* Initialize the renderer with Handlebars.
|
|
485
|
-
*/
|
|
486
|
-
async init() {
|
|
487
|
-
if (this.initialized) return;
|
|
488
|
-
this.hbs = await loadHandlebars();
|
|
489
|
-
for (const [name, helper] of Object.entries(builtinHelpers)) {
|
|
490
|
-
this.hbs.registerHelper(name, helper);
|
|
491
|
-
}
|
|
492
|
-
if (this.options.helpers) {
|
|
493
|
-
for (const [name, helper] of Object.entries(this.options.helpers)) {
|
|
494
|
-
this.hbs.registerHelper(name, helper);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if (this.options.partials) {
|
|
498
|
-
for (const [name, template] of Object.entries(this.options.partials)) {
|
|
499
|
-
this.hbs.registerPartial(name, template);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
this.initialized = true;
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Render a Handlebars template.
|
|
506
|
-
*
|
|
507
|
-
* @param template - Template string
|
|
508
|
-
* @param context - Render context with input/output
|
|
509
|
-
* @returns Rendered HTML string
|
|
510
|
-
*/
|
|
511
|
-
async render(template, context) {
|
|
512
|
-
await this.init();
|
|
513
|
-
if (!this.hbs) {
|
|
514
|
-
throw new Error("Handlebars not initialized");
|
|
515
|
-
}
|
|
516
|
-
let compiled = this.compiledTemplates.get(template);
|
|
517
|
-
if (!compiled) {
|
|
518
|
-
compiled = this.hbs.compile(template, {
|
|
519
|
-
strict: this.options.strict,
|
|
520
|
-
noEscape: !this.options.autoEscape
|
|
521
|
-
});
|
|
522
|
-
this.compiledTemplates.set(template, compiled);
|
|
523
|
-
}
|
|
524
|
-
const data = {
|
|
525
|
-
input: context.input ?? {},
|
|
526
|
-
output: context.output ?? {},
|
|
527
|
-
structuredContent: context.structuredContent,
|
|
528
|
-
// Also expose at root level for convenience
|
|
529
|
-
...context.input,
|
|
530
|
-
...typeof context.output === "object" && context.output !== null ? context.output : {}
|
|
531
|
-
};
|
|
532
|
-
try {
|
|
533
|
-
return compiled(data);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
throw new Error(`Template rendering failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Render a template synchronously.
|
|
540
|
-
*
|
|
541
|
-
* Note: Requires Handlebars to be pre-loaded. Use `render()` for async loading.
|
|
542
|
-
*
|
|
543
|
-
* @param template - Template string
|
|
544
|
-
* @param context - Render context
|
|
545
|
-
* @returns Rendered HTML string
|
|
546
|
-
*/
|
|
547
|
-
renderSync(template, context) {
|
|
548
|
-
if (!this.initialized || !this.hbs) {
|
|
549
|
-
throw new Error("HandlebarsRenderer not initialized. Call render() first or use initSync().");
|
|
550
|
-
}
|
|
551
|
-
let compiled = this.compiledTemplates.get(template);
|
|
552
|
-
if (!compiled) {
|
|
553
|
-
compiled = this.hbs.compile(template, {
|
|
554
|
-
strict: this.options.strict,
|
|
555
|
-
noEscape: !this.options.autoEscape
|
|
556
|
-
});
|
|
557
|
-
this.compiledTemplates.set(template, compiled);
|
|
558
|
-
}
|
|
559
|
-
const data = {
|
|
560
|
-
input: context.input ?? {},
|
|
561
|
-
output: context.output ?? {},
|
|
562
|
-
structuredContent: context.structuredContent,
|
|
563
|
-
...context.input,
|
|
564
|
-
...typeof context.output === "object" && context.output !== null ? context.output : {}
|
|
565
|
-
};
|
|
566
|
-
return compiled(data);
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Initialize synchronously (for environments where Handlebars is already loaded).
|
|
570
|
-
*/
|
|
571
|
-
initSync(handlebars) {
|
|
572
|
-
this.hbs = handlebars;
|
|
573
|
-
for (const [name, helper] of Object.entries(builtinHelpers)) {
|
|
574
|
-
this.hbs.registerHelper(name, helper);
|
|
575
|
-
}
|
|
576
|
-
if (this.options.helpers) {
|
|
577
|
-
for (const [name, helper] of Object.entries(this.options.helpers)) {
|
|
578
|
-
this.hbs.registerHelper(name, helper);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
if (this.options.partials) {
|
|
582
|
-
for (const [name, template] of Object.entries(this.options.partials)) {
|
|
583
|
-
this.hbs.registerPartial(name, template);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
this.initialized = true;
|
|
587
|
-
}
|
|
588
|
-
/**
|
|
589
|
-
* Register a custom helper.
|
|
590
|
-
*
|
|
591
|
-
* @param name - Helper name
|
|
592
|
-
* @param fn - Helper function
|
|
593
|
-
*/
|
|
594
|
-
registerHelper(name, fn) {
|
|
595
|
-
if (this.hbs) {
|
|
596
|
-
this.hbs.registerHelper(name, fn);
|
|
597
|
-
}
|
|
598
|
-
if (!this.options.helpers) {
|
|
599
|
-
this.options.helpers = {};
|
|
600
|
-
}
|
|
601
|
-
this.options.helpers[name] = fn;
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* Register a partial template.
|
|
605
|
-
*
|
|
606
|
-
* @param name - Partial name
|
|
607
|
-
* @param template - Partial template string
|
|
608
|
-
*/
|
|
609
|
-
registerPartial(name, template) {
|
|
610
|
-
if (this.hbs) {
|
|
611
|
-
this.hbs.registerPartial(name, template);
|
|
612
|
-
}
|
|
613
|
-
if (!this.options.partials) {
|
|
614
|
-
this.options.partials = {};
|
|
615
|
-
}
|
|
616
|
-
this.options.partials[name] = template;
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Clear compiled template cache.
|
|
620
|
-
*/
|
|
621
|
-
clearCache() {
|
|
622
|
-
this.compiledTemplates.clear();
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* Check if a template string contains Handlebars syntax.
|
|
626
|
-
*
|
|
627
|
-
* @param template - Template string to check
|
|
628
|
-
* @returns true if contains {{...}} syntax
|
|
629
|
-
*/
|
|
630
|
-
static containsHandlebars(template) {
|
|
631
|
-
return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Check if the renderer is initialized.
|
|
635
|
-
*/
|
|
636
|
-
get isInitialized() {
|
|
637
|
-
return this.initialized;
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
});
|
|
642
|
-
|
|
643
|
-
// libs/uipack/src/renderers/index.ts
|
|
644
|
-
var renderers_exports = {};
|
|
645
|
-
__export(renderers_exports, {
|
|
646
|
-
HtmlRenderer: () => HtmlRenderer,
|
|
647
|
-
MdxClientRenderer: () => MdxClientRenderer,
|
|
648
|
-
RendererRegistry: () => RendererRegistry,
|
|
649
|
-
TranspileCache: () => TranspileCache,
|
|
650
|
-
buildReactCdnUrls: () => buildReactCdnUrls,
|
|
651
|
-
componentCache: () => componentCache,
|
|
652
|
-
containsJsx: () => containsJsx,
|
|
653
|
-
containsMdxSyntax: () => containsMdxSyntax,
|
|
654
|
-
detectTemplateType: () => detectTemplateType,
|
|
655
|
-
executeTranspiledCode: () => executeTranspiledCode,
|
|
656
|
-
hashCombined: () => hashCombined,
|
|
657
|
-
hashString: () => hashString,
|
|
658
|
-
htmlRenderer: () => htmlRenderer,
|
|
659
|
-
isHash: () => isHash,
|
|
660
|
-
isPlainHtml: () => isPlainHtml,
|
|
661
|
-
isReactComponent: () => isReactComponent,
|
|
662
|
-
isSwcAvailable: () => isSwcAvailable,
|
|
663
|
-
isTemplateBuilderFunction: () => isTemplateBuilderFunction,
|
|
664
|
-
mdxClientRenderer: () => mdxClientRenderer,
|
|
665
|
-
rendererRegistry: () => rendererRegistry,
|
|
666
|
-
transpileAndExecute: () => transpileAndExecute,
|
|
667
|
-
transpileCache: () => transpileCache,
|
|
668
|
-
transpileJsx: () => transpileJsx
|
|
669
|
-
});
|
|
670
|
-
module.exports = __toCommonJS(renderers_exports);
|
|
671
|
-
|
|
672
|
-
// libs/uipack/src/renderers/utils/hash.ts
|
|
673
|
-
function hashString(source) {
|
|
674
|
-
let hash = 2166136261;
|
|
675
|
-
for (let i = 0; i < source.length; i++) {
|
|
676
|
-
hash ^= source.charCodeAt(i);
|
|
677
|
-
hash = hash * 16777619 >>> 0;
|
|
678
|
-
}
|
|
679
|
-
return hash.toString(36);
|
|
680
|
-
}
|
|
681
|
-
function hashCombined(...values) {
|
|
682
|
-
const combined = values.map((v) => {
|
|
683
|
-
if (typeof v === "string") return v;
|
|
684
|
-
if (v === null) return "null";
|
|
685
|
-
if (v === void 0) return "undefined";
|
|
686
|
-
try {
|
|
687
|
-
return JSON.stringify(v);
|
|
688
|
-
} catch {
|
|
689
|
-
return String(v);
|
|
690
|
-
}
|
|
691
|
-
}).join("|");
|
|
692
|
-
return hashString(combined);
|
|
693
|
-
}
|
|
694
|
-
function isHash(value) {
|
|
695
|
-
return /^[0-9a-z]{5,10}$/i.test(value);
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// libs/uipack/src/renderers/cache.ts
|
|
699
|
-
var TranspileCache = class {
|
|
700
|
-
cache = /* @__PURE__ */ new Map();
|
|
701
|
-
maxSize;
|
|
702
|
-
ttl;
|
|
703
|
-
/** Cache statistics */
|
|
704
|
-
stats = {
|
|
705
|
-
hits: 0,
|
|
706
|
-
misses: 0,
|
|
707
|
-
evictions: 0
|
|
708
|
-
};
|
|
709
|
-
constructor(options = {}) {
|
|
710
|
-
this.maxSize = options.maxSize ?? 500;
|
|
711
|
-
this.ttl = options.ttl ?? 0;
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Get a cached transpile result by source content.
|
|
715
|
-
*
|
|
716
|
-
* @param source - Source code to look up
|
|
717
|
-
* @returns Cached result or undefined if not found/expired
|
|
718
|
-
*/
|
|
719
|
-
get(source) {
|
|
720
|
-
const key = hashString(source);
|
|
721
|
-
return this.getByKey(key);
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Get a cached transpile result by hash key.
|
|
725
|
-
*
|
|
726
|
-
* @param key - Hash key
|
|
727
|
-
* @returns Cached result or undefined if not found/expired
|
|
728
|
-
*/
|
|
729
|
-
getByKey(key) {
|
|
730
|
-
const entry = this.cache.get(key);
|
|
731
|
-
if (!entry) {
|
|
732
|
-
this.stats.misses++;
|
|
733
|
-
return void 0;
|
|
734
|
-
}
|
|
735
|
-
if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
|
|
736
|
-
this.cache.delete(key);
|
|
737
|
-
this.stats.misses++;
|
|
738
|
-
return void 0;
|
|
739
|
-
}
|
|
740
|
-
this.cache.delete(key);
|
|
741
|
-
entry.accessCount++;
|
|
742
|
-
this.cache.set(key, entry);
|
|
743
|
-
this.stats.hits++;
|
|
744
|
-
return entry.value;
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Store a transpile result.
|
|
748
|
-
*
|
|
749
|
-
* @param source - Source code (used to generate key)
|
|
750
|
-
* @param value - Transpile result to cache
|
|
751
|
-
* @returns The hash key used for storage
|
|
752
|
-
*/
|
|
753
|
-
set(source, value) {
|
|
754
|
-
const key = hashString(source);
|
|
755
|
-
this.setByKey(key, value);
|
|
756
|
-
return key;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Store a transpile result by hash key.
|
|
760
|
-
*
|
|
761
|
-
* @param key - Hash key
|
|
762
|
-
* @param value - Transpile result to cache
|
|
763
|
-
*/
|
|
764
|
-
setByKey(key, value) {
|
|
765
|
-
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
766
|
-
const oldestKey = this.cache.keys().next().value;
|
|
767
|
-
if (oldestKey) {
|
|
768
|
-
this.cache.delete(oldestKey);
|
|
769
|
-
this.stats.evictions++;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
this.cache.set(key, {
|
|
773
|
-
value,
|
|
774
|
-
timestamp: Date.now(),
|
|
775
|
-
accessCount: 1
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Check if a source is cached.
|
|
780
|
-
*
|
|
781
|
-
* @param source - Source code to check
|
|
782
|
-
* @returns True if cached and not expired
|
|
783
|
-
*/
|
|
784
|
-
has(source) {
|
|
785
|
-
const key = hashString(source);
|
|
786
|
-
return this.hasByKey(key);
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Check if a key is cached.
|
|
790
|
-
*
|
|
791
|
-
* @param key - Hash key to check
|
|
792
|
-
* @returns True if cached and not expired
|
|
793
|
-
*/
|
|
794
|
-
hasByKey(key) {
|
|
795
|
-
const entry = this.cache.get(key);
|
|
796
|
-
if (!entry) return false;
|
|
797
|
-
if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
|
|
798
|
-
this.cache.delete(key);
|
|
799
|
-
return false;
|
|
800
|
-
}
|
|
801
|
-
return true;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Delete a cached entry by source.
|
|
805
|
-
*
|
|
806
|
-
* @param source - Source code to delete
|
|
807
|
-
* @returns True if entry was deleted
|
|
808
|
-
*/
|
|
809
|
-
delete(source) {
|
|
810
|
-
const key = hashString(source);
|
|
811
|
-
return this.cache.delete(key);
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Clear all cached entries.
|
|
815
|
-
*/
|
|
816
|
-
clear() {
|
|
817
|
-
this.cache.clear();
|
|
818
|
-
this.stats = { hits: 0, misses: 0, evictions: 0 };
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Get current cache size.
|
|
822
|
-
*/
|
|
823
|
-
get size() {
|
|
824
|
-
return this.cache.size;
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Get cache statistics.
|
|
828
|
-
*/
|
|
829
|
-
getStats() {
|
|
830
|
-
const total = this.stats.hits + this.stats.misses;
|
|
831
|
-
return {
|
|
832
|
-
...this.stats,
|
|
833
|
-
size: this.cache.size,
|
|
834
|
-
hitRate: total > 0 ? this.stats.hits / total : 0
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
var transpileCache = new TranspileCache({ maxSize: 500 });
|
|
839
|
-
var renderCache = new TranspileCache({
|
|
840
|
-
maxSize: 1e3,
|
|
841
|
-
ttl: 5 * 60 * 1e3
|
|
842
|
-
// 5 minutes
|
|
843
|
-
});
|
|
844
|
-
var ComponentCache = class {
|
|
845
|
-
cache = /* @__PURE__ */ new Map();
|
|
846
|
-
maxSize;
|
|
847
|
-
constructor(maxSize = 200) {
|
|
848
|
-
this.maxSize = maxSize;
|
|
849
|
-
}
|
|
850
|
-
get(key) {
|
|
851
|
-
const entry = this.cache.get(key);
|
|
852
|
-
if (!entry) return void 0;
|
|
853
|
-
this.cache.delete(key);
|
|
854
|
-
this.cache.set(key, entry);
|
|
855
|
-
return entry.value;
|
|
856
|
-
}
|
|
857
|
-
set(key, value) {
|
|
858
|
-
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
859
|
-
const oldestKey = this.cache.keys().next().value;
|
|
860
|
-
if (oldestKey) {
|
|
861
|
-
this.cache.delete(oldestKey);
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
this.cache.set(key, { value, timestamp: Date.now() });
|
|
865
|
-
}
|
|
866
|
-
has(key) {
|
|
867
|
-
return this.cache.has(key);
|
|
868
|
-
}
|
|
869
|
-
delete(key) {
|
|
870
|
-
return this.cache.delete(key);
|
|
871
|
-
}
|
|
872
|
-
clear() {
|
|
873
|
-
this.cache.clear();
|
|
874
|
-
}
|
|
875
|
-
get size() {
|
|
876
|
-
return this.cache.size;
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
var componentCache = new ComponentCache();
|
|
880
|
-
|
|
881
|
-
// libs/uipack/src/theme/platforms.ts
|
|
882
|
-
var OPENAI_PLATFORM = {
|
|
883
|
-
id: "openai",
|
|
884
|
-
name: "OpenAI",
|
|
885
|
-
supportsWidgets: true,
|
|
886
|
-
supportsTailwind: true,
|
|
887
|
-
supportsHtmx: true,
|
|
888
|
-
networkMode: "full",
|
|
889
|
-
scriptStrategy: "cdn",
|
|
890
|
-
options: {
|
|
891
|
-
sdk: "apps-sdk",
|
|
892
|
-
version: "1.0"
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
var CLAUDE_PLATFORM = {
|
|
896
|
-
id: "claude",
|
|
897
|
-
name: "Claude (Artifacts)",
|
|
898
|
-
supportsWidgets: true,
|
|
899
|
-
// Claude Artifacts support interactive widgets
|
|
900
|
-
supportsTailwind: true,
|
|
901
|
-
supportsHtmx: false,
|
|
902
|
-
// Network blocked, HTMX won't work for API calls
|
|
903
|
-
networkMode: "limited",
|
|
904
|
-
scriptStrategy: "cdn",
|
|
905
|
-
maxInlineSize: 100 * 1024,
|
|
906
|
-
// 100KB limit for artifacts
|
|
907
|
-
cspRestrictions: ["script-src 'unsafe-inline'", "connect-src 'none'"],
|
|
908
|
-
options: {
|
|
909
|
-
mode: "artifacts",
|
|
910
|
-
framework: "react"
|
|
911
|
-
// Claude artifacts prefer React
|
|
912
|
-
}
|
|
913
|
-
};
|
|
914
|
-
|
|
915
|
-
// libs/uipack/src/renderers/utils/detect.ts
|
|
916
|
-
var MAX_TEMPLATE_LENGTH = 5e4;
|
|
917
|
-
function isReactComponent(value) {
|
|
918
|
-
if (typeof value !== "function") {
|
|
919
|
-
return false;
|
|
920
|
-
}
|
|
921
|
-
const fn = value;
|
|
922
|
-
const typeofSymbol = fn.$$typeof;
|
|
923
|
-
if (typeofSymbol) {
|
|
924
|
-
const symbolString = typeofSymbol.toString();
|
|
925
|
-
return symbolString.includes("react.memo") || symbolString.includes("react.forward_ref") || symbolString.includes("react.lazy");
|
|
926
|
-
}
|
|
927
|
-
if (fn.prototype?.isReactComponent) {
|
|
928
|
-
return true;
|
|
929
|
-
}
|
|
930
|
-
if (fn.name && /^[A-Z]/.test(fn.name)) {
|
|
931
|
-
return true;
|
|
932
|
-
}
|
|
933
|
-
return false;
|
|
934
|
-
}
|
|
935
|
-
function isTemplateBuilderFunction(fn) {
|
|
936
|
-
if (isReactComponent(fn)) {
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
if (fn.name && /^[A-Z]/.test(fn.name)) {
|
|
940
|
-
return false;
|
|
941
|
-
}
|
|
942
|
-
return true;
|
|
943
|
-
}
|
|
944
|
-
function containsJsx(source) {
|
|
945
|
-
if (source.length > MAX_TEMPLATE_LENGTH) {
|
|
946
|
-
return false;
|
|
947
|
-
}
|
|
948
|
-
if (/<[A-Z][a-zA-Z0-9]*(\s|>|\/)/.test(source)) {
|
|
949
|
-
return true;
|
|
950
|
-
}
|
|
951
|
-
if (/<[A-Z][a-zA-Z0-9]*[^>]*\/>/.test(source)) {
|
|
952
|
-
return true;
|
|
953
|
-
}
|
|
954
|
-
if (/<[a-z]+[^>]*\{[^}]+\}/.test(source)) {
|
|
955
|
-
return true;
|
|
956
|
-
}
|
|
957
|
-
if (/\s(className|onClick|onChange|onSubmit|htmlFor)=/.test(source)) {
|
|
958
|
-
return true;
|
|
959
|
-
}
|
|
960
|
-
if (/<>|<\/>|<React\.Fragment>/.test(source)) {
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
if (/=>\s*\(?\s*</.test(source)) {
|
|
964
|
-
return true;
|
|
965
|
-
}
|
|
966
|
-
if (/return\s*\(?\s*</.test(source)) {
|
|
967
|
-
return true;
|
|
968
|
-
}
|
|
969
|
-
return false;
|
|
970
|
-
}
|
|
971
|
-
function containsMdxSyntax(source) {
|
|
972
|
-
if (source.length > MAX_TEMPLATE_LENGTH) {
|
|
973
|
-
return false;
|
|
974
|
-
}
|
|
975
|
-
if (/<[A-Z][a-zA-Z0-9]*/.test(source)) {
|
|
976
|
-
return true;
|
|
977
|
-
}
|
|
978
|
-
if (/^(import|export)\s/m.test(source)) {
|
|
979
|
-
return true;
|
|
980
|
-
}
|
|
981
|
-
if (/\s(className|onClick|onChange|onSubmit|htmlFor|dangerouslySetInnerHTML)=/.test(source)) {
|
|
982
|
-
return true;
|
|
983
|
-
}
|
|
984
|
-
if (/\{[^}"'\n]*\}/.test(source) && !/=\s*["'][^"']*\{/.test(source)) {
|
|
985
|
-
return true;
|
|
986
|
-
}
|
|
987
|
-
if (/^---[\s\S]*?---/m.test(source)) {
|
|
988
|
-
return true;
|
|
989
|
-
}
|
|
990
|
-
if (/<>|<\/>/.test(source)) {
|
|
991
|
-
return true;
|
|
992
|
-
}
|
|
993
|
-
return false;
|
|
994
|
-
}
|
|
995
|
-
function isPlainHtml(source) {
|
|
996
|
-
return !containsJsx(source) && !containsMdxSyntax(source);
|
|
997
|
-
}
|
|
998
|
-
function detectTemplateType(template) {
|
|
999
|
-
if (typeof template === "function") {
|
|
1000
|
-
if (isReactComponent(template)) {
|
|
1001
|
-
return {
|
|
1002
|
-
type: "react",
|
|
1003
|
-
confidence: 0.9,
|
|
1004
|
-
reason: "Function detected as React component (PascalCase name or React symbols)"
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
return {
|
|
1008
|
-
type: "html-function",
|
|
1009
|
-
confidence: 0.8,
|
|
1010
|
-
reason: "Function assumed to be HTML template builder"
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
if (typeof template === "string") {
|
|
1014
|
-
if (containsMdxSyntax(template)) {
|
|
1015
|
-
const hasMarkdown = /^#{1,6}\s|^\*\s|^\d+\.\s|^-\s/m.test(template);
|
|
1016
|
-
if (hasMarkdown) {
|
|
1017
|
-
return {
|
|
1018
|
-
type: "mdx",
|
|
1019
|
-
confidence: 0.9,
|
|
1020
|
-
reason: "String contains Markdown with JSX components"
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
|
-
return {
|
|
1024
|
-
type: "jsx-string",
|
|
1025
|
-
confidence: 0.8,
|
|
1026
|
-
reason: "String contains JSX syntax"
|
|
1027
|
-
};
|
|
1028
|
-
}
|
|
1029
|
-
if (containsJsx(template)) {
|
|
1030
|
-
return {
|
|
1031
|
-
type: "jsx-string",
|
|
1032
|
-
confidence: 0.85,
|
|
1033
|
-
reason: "String contains JSX component tags or expressions"
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
return {
|
|
1037
|
-
type: "html-string",
|
|
1038
|
-
confidence: 1,
|
|
1039
|
-
reason: "Plain HTML string"
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
return {
|
|
1043
|
-
type: "html-string",
|
|
1044
|
-
confidence: 0.5,
|
|
1045
|
-
reason: "Unknown template type, defaulting to HTML"
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// libs/uipack/src/renderers/html.renderer.ts
|
|
1050
|
-
var handlebarsRenderer = null;
|
|
1051
|
-
async function loadHandlebarsRenderer() {
|
|
1052
|
-
if (handlebarsRenderer !== null) {
|
|
1053
|
-
return handlebarsRenderer;
|
|
1054
|
-
}
|
|
1055
|
-
try {
|
|
1056
|
-
const handlebarsModule = await Promise.resolve().then(() => (init_handlebars(), handlebars_exports));
|
|
1057
|
-
const { HandlebarsRenderer: HandlebarsRenderer2 } = handlebarsModule;
|
|
1058
|
-
const renderer = new HandlebarsRenderer2();
|
|
1059
|
-
handlebarsRenderer = {
|
|
1060
|
-
render: (template, context) => renderer.render(template, {
|
|
1061
|
-
input: context.input ?? {},
|
|
1062
|
-
output: context.output,
|
|
1063
|
-
structuredContent: context.structuredContent
|
|
1064
|
-
}),
|
|
1065
|
-
containsHandlebars: (template) => HandlebarsRenderer2.containsHandlebars(template)
|
|
1066
|
-
};
|
|
1067
|
-
return handlebarsRenderer;
|
|
1068
|
-
} catch {
|
|
1069
|
-
return null;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
function containsHandlebars2(template) {
|
|
1073
|
-
return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
|
|
1074
|
-
}
|
|
1075
|
-
var HtmlRenderer = class {
|
|
1076
|
-
type = "html";
|
|
1077
|
-
priority = 0;
|
|
1078
|
-
// Lowest priority - fallback renderer
|
|
1079
|
-
/**
|
|
1080
|
-
* Check if this renderer can handle the given template.
|
|
1081
|
-
*
|
|
1082
|
-
* Accepts:
|
|
1083
|
-
* - Any string (assumed to be HTML, with or without Handlebars)
|
|
1084
|
-
* - Functions that are template builders (not React components)
|
|
1085
|
-
*/
|
|
1086
|
-
canHandle(template) {
|
|
1087
|
-
if (typeof template === "string") {
|
|
1088
|
-
return true;
|
|
1089
|
-
}
|
|
1090
|
-
if (typeof template === "function") {
|
|
1091
|
-
return isTemplateBuilderFunction(template);
|
|
1092
|
-
}
|
|
1093
|
-
return false;
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Check if a template uses Handlebars syntax.
|
|
1097
|
-
*
|
|
1098
|
-
* @param template - Template string to check
|
|
1099
|
-
* @returns true if template contains {{...}} syntax
|
|
1100
|
-
*/
|
|
1101
|
-
usesHandlebars(template) {
|
|
1102
|
-
return containsHandlebars2(template);
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Transpile the template.
|
|
1106
|
-
*
|
|
1107
|
-
* For HTML templates, no transpilation is needed.
|
|
1108
|
-
* This method returns a dummy result for consistency.
|
|
1109
|
-
*/
|
|
1110
|
-
async transpile(template, _options) {
|
|
1111
|
-
const source = typeof template === "string" ? template : template.toString();
|
|
1112
|
-
const hash = hashString(source);
|
|
1113
|
-
return {
|
|
1114
|
-
code: "",
|
|
1115
|
-
// No transpiled code needed
|
|
1116
|
-
hash,
|
|
1117
|
-
cached: true
|
|
1118
|
-
// Always "cached" since no work is done
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* Render the template to HTML string.
|
|
1123
|
-
*
|
|
1124
|
-
* For static strings without Handlebars, returns the string directly.
|
|
1125
|
-
* For strings with Handlebars syntax, processes with HandlebarsRenderer.
|
|
1126
|
-
* For functions, calls the function with the context.
|
|
1127
|
-
*/
|
|
1128
|
-
async render(template, context, _options) {
|
|
1129
|
-
if (typeof template === "string") {
|
|
1130
|
-
if (containsHandlebars2(template)) {
|
|
1131
|
-
return this.renderHandlebars(template, context);
|
|
1132
|
-
}
|
|
1133
|
-
return template;
|
|
1134
|
-
}
|
|
1135
|
-
if (typeof template === "function") {
|
|
1136
|
-
const result = template(context);
|
|
1137
|
-
if (typeof result === "string" && containsHandlebars2(result)) {
|
|
1138
|
-
return this.renderHandlebars(result, context);
|
|
1139
|
-
}
|
|
1140
|
-
return result;
|
|
1141
|
-
}
|
|
1142
|
-
return String(template);
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Render Handlebars template with context.
|
|
1146
|
-
*/
|
|
1147
|
-
async renderHandlebars(template, context) {
|
|
1148
|
-
const renderer = await loadHandlebarsRenderer();
|
|
1149
|
-
if (!renderer) {
|
|
1150
|
-
console.warn(
|
|
1151
|
-
"[@frontmcp/ui] Template contains Handlebars syntax but handlebars is not installed. Install it for template interpolation: npm install handlebars"
|
|
1152
|
-
);
|
|
1153
|
-
return template;
|
|
1154
|
-
}
|
|
1155
|
-
return renderer.render(template, {
|
|
1156
|
-
input: context.input,
|
|
1157
|
-
output: context.output,
|
|
1158
|
-
structuredContent: context.structuredContent
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Get runtime scripts for client-side functionality.
|
|
1163
|
-
*
|
|
1164
|
-
* HTML templates don't need additional runtime scripts.
|
|
1165
|
-
*/
|
|
1166
|
-
getRuntimeScripts(_platform) {
|
|
1167
|
-
return {
|
|
1168
|
-
headScripts: "",
|
|
1169
|
-
isInline: false
|
|
1170
|
-
};
|
|
1171
|
-
}
|
|
1172
|
-
};
|
|
1173
|
-
var htmlRenderer = new HtmlRenderer();
|
|
1174
|
-
|
|
1175
|
-
// libs/uipack/src/renderers/registry.ts
|
|
1176
|
-
var RendererRegistry = class {
|
|
1177
|
-
renderers = /* @__PURE__ */ new Map();
|
|
1178
|
-
sortedRenderers = [];
|
|
1179
|
-
defaultRenderer = "html";
|
|
1180
|
-
debug;
|
|
1181
|
-
constructor(options = {}) {
|
|
1182
|
-
this.debug = options.debug ?? false;
|
|
1183
|
-
this.register(htmlRenderer);
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
* Register a renderer.
|
|
1187
|
-
*
|
|
1188
|
-
* Renderers are sorted by priority (highest first) for detection.
|
|
1189
|
-
*
|
|
1190
|
-
* @param renderer - Renderer to register
|
|
1191
|
-
*/
|
|
1192
|
-
register(renderer) {
|
|
1193
|
-
this.renderers.set(renderer.type, renderer);
|
|
1194
|
-
this.updateSortedList();
|
|
1195
|
-
if (this.debug) {
|
|
1196
|
-
console.log(`[RendererRegistry] Registered renderer: ${renderer.type} (priority: ${renderer.priority})`);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
/**
|
|
1200
|
-
* Unregister a renderer.
|
|
1201
|
-
*
|
|
1202
|
-
* @param type - Type of renderer to remove
|
|
1203
|
-
* @returns True if renderer was removed
|
|
1204
|
-
*/
|
|
1205
|
-
unregister(type) {
|
|
1206
|
-
const removed = this.renderers.delete(type);
|
|
1207
|
-
if (removed) {
|
|
1208
|
-
this.updateSortedList();
|
|
1209
|
-
}
|
|
1210
|
-
return removed;
|
|
1211
|
-
}
|
|
1212
|
-
/**
|
|
1213
|
-
* Get a renderer by type.
|
|
1214
|
-
*
|
|
1215
|
-
* @param type - Renderer type
|
|
1216
|
-
* @returns Renderer or undefined if not found
|
|
1217
|
-
*/
|
|
1218
|
-
get(type) {
|
|
1219
|
-
return this.renderers.get(type);
|
|
1220
|
-
}
|
|
1221
|
-
/**
|
|
1222
|
-
* Check if a renderer type is registered.
|
|
1223
|
-
*
|
|
1224
|
-
* @param type - Renderer type
|
|
1225
|
-
* @returns True if registered
|
|
1226
|
-
*/
|
|
1227
|
-
has(type) {
|
|
1228
|
-
return this.renderers.has(type);
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* Get all registered renderer types.
|
|
1232
|
-
*
|
|
1233
|
-
* @returns Array of renderer types
|
|
1234
|
-
*/
|
|
1235
|
-
getTypes() {
|
|
1236
|
-
return Array.from(this.renderers.keys());
|
|
1237
|
-
}
|
|
1238
|
-
/**
|
|
1239
|
-
* Auto-detect the renderer for a template.
|
|
1240
|
-
*
|
|
1241
|
-
* Checks renderers in priority order (highest first).
|
|
1242
|
-
* Returns HTML renderer as fallback.
|
|
1243
|
-
*
|
|
1244
|
-
* @param template - Template to detect
|
|
1245
|
-
* @returns Detection result with renderer and confidence
|
|
1246
|
-
*/
|
|
1247
|
-
detect(template) {
|
|
1248
|
-
for (const renderer of this.sortedRenderers) {
|
|
1249
|
-
if (renderer.canHandle(template)) {
|
|
1250
|
-
const result = {
|
|
1251
|
-
renderer,
|
|
1252
|
-
confidence: renderer.priority / 100,
|
|
1253
|
-
// Normalize to 0-1
|
|
1254
|
-
reason: `Matched by ${renderer.type} renderer`
|
|
1255
|
-
};
|
|
1256
|
-
if (this.debug) {
|
|
1257
|
-
console.log(`[RendererRegistry] Detected template as ${renderer.type} (confidence: ${result.confidence})`);
|
|
1258
|
-
}
|
|
1259
|
-
return result;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
const fallback = this.renderers.get(this.defaultRenderer);
|
|
1263
|
-
if (!fallback) {
|
|
1264
|
-
throw new Error(`Default renderer '${this.defaultRenderer}' not found`);
|
|
1265
|
-
}
|
|
1266
|
-
return {
|
|
1267
|
-
renderer: fallback,
|
|
1268
|
-
confidence: 0.5,
|
|
1269
|
-
reason: "Fallback to default HTML renderer"
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
|
-
/**
|
|
1273
|
-
* Render a template with auto-detection.
|
|
1274
|
-
*
|
|
1275
|
-
* @param template - Template to render (React, MDX, or HTML)
|
|
1276
|
-
* @param context - Template context with input/output
|
|
1277
|
-
* @param options - Render options
|
|
1278
|
-
* @returns Rendered result with HTML and metadata
|
|
1279
|
-
*/
|
|
1280
|
-
async render(template, context, options = {}) {
|
|
1281
|
-
const platform = options.platform ?? OPENAI_PLATFORM;
|
|
1282
|
-
const detection = this.detect(template);
|
|
1283
|
-
const renderer = detection.renderer;
|
|
1284
|
-
if (this.debug) {
|
|
1285
|
-
console.log(`[RendererRegistry] Rendering with ${renderer.type} renderer`);
|
|
1286
|
-
}
|
|
1287
|
-
const transpileResult = await renderer.transpile(template);
|
|
1288
|
-
const html = await renderer.render(template, context, options);
|
|
1289
|
-
const runtimeScripts = renderer.getRuntimeScripts(platform);
|
|
1290
|
-
return {
|
|
1291
|
-
html,
|
|
1292
|
-
rendererType: renderer.type,
|
|
1293
|
-
transpileCached: transpileResult.cached,
|
|
1294
|
-
runtimeScripts
|
|
1295
|
-
};
|
|
1296
|
-
}
|
|
1297
|
-
/**
|
|
1298
|
-
* Render with a specific renderer type.
|
|
1299
|
-
*
|
|
1300
|
-
* @param type - Renderer type to use
|
|
1301
|
-
* @param template - Template to render
|
|
1302
|
-
* @param context - Template context
|
|
1303
|
-
* @param options - Render options
|
|
1304
|
-
* @returns Rendered result
|
|
1305
|
-
*/
|
|
1306
|
-
async renderWith(type, template, context, options = {}) {
|
|
1307
|
-
const renderer = this.renderers.get(type);
|
|
1308
|
-
if (!renderer) {
|
|
1309
|
-
throw new Error(`Renderer '${type}' not registered`);
|
|
1310
|
-
}
|
|
1311
|
-
const platform = options.platform ?? OPENAI_PLATFORM;
|
|
1312
|
-
const transpileResult = await renderer.transpile(template);
|
|
1313
|
-
const html = await renderer.render(template, context, options);
|
|
1314
|
-
const runtimeScripts = renderer.getRuntimeScripts(platform);
|
|
1315
|
-
return {
|
|
1316
|
-
html,
|
|
1317
|
-
rendererType: type,
|
|
1318
|
-
transpileCached: transpileResult.cached,
|
|
1319
|
-
runtimeScripts
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Update the sorted renderer list by priority.
|
|
1324
|
-
*/
|
|
1325
|
-
updateSortedList() {
|
|
1326
|
-
this.sortedRenderers = Array.from(this.renderers.values()).sort((a, b) => b.priority - a.priority);
|
|
1327
|
-
}
|
|
1328
|
-
/**
|
|
1329
|
-
* Set the default renderer type.
|
|
1330
|
-
*
|
|
1331
|
-
* @param type - Renderer type to use as default
|
|
1332
|
-
*/
|
|
1333
|
-
setDefault(type) {
|
|
1334
|
-
if (!this.renderers.has(type)) {
|
|
1335
|
-
throw new Error(`Cannot set default to unregistered renderer '${type}'`);
|
|
1336
|
-
}
|
|
1337
|
-
this.defaultRenderer = type;
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* Get registry statistics.
|
|
1341
|
-
*/
|
|
1342
|
-
getStats() {
|
|
1343
|
-
return {
|
|
1344
|
-
registeredRenderers: this.getTypes(),
|
|
1345
|
-
defaultRenderer: this.defaultRenderer,
|
|
1346
|
-
priorityOrder: this.sortedRenderers.map((r) => ({
|
|
1347
|
-
type: r.type,
|
|
1348
|
-
priority: r.priority
|
|
1349
|
-
}))
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
};
|
|
1353
|
-
var rendererRegistry = new RendererRegistry();
|
|
1354
|
-
|
|
1355
|
-
// libs/uipack/src/renderers/mdx-client.renderer.ts
|
|
1356
|
-
init_utils();
|
|
1357
|
-
function buildReactCdnUrls(version = "19") {
|
|
1358
|
-
return {
|
|
1359
|
-
react: `https://esm.sh/react@${version}`,
|
|
1360
|
-
reactDom: `https://esm.sh/react-dom@${version}/client`,
|
|
1361
|
-
jsxRuntime: `https://esm.sh/react@${version}/jsx-runtime`
|
|
1362
|
-
};
|
|
1363
|
-
}
|
|
1364
|
-
var DEFAULT_CDN = {
|
|
1365
|
-
mdx: "https://esm.sh/@mdx-js/mdx@3",
|
|
1366
|
-
...buildReactCdnUrls("19")
|
|
1367
|
-
};
|
|
1368
|
-
var MdxClientRenderer = class {
|
|
1369
|
-
type = "mdx-client";
|
|
1370
|
-
priority = 8;
|
|
1371
|
-
// Lower than server-side MDX (10)
|
|
1372
|
-
/**
|
|
1373
|
-
* Check if this renderer can handle the given template.
|
|
1374
|
-
*/
|
|
1375
|
-
canHandle(template) {
|
|
1376
|
-
if (typeof template !== "string") {
|
|
1377
|
-
return false;
|
|
1378
|
-
}
|
|
1379
|
-
return containsMdxSyntax(template);
|
|
1380
|
-
}
|
|
1381
|
-
/**
|
|
1382
|
-
* Prepare MDX template for rendering.
|
|
1383
|
-
* Caches the template hash for deduplication. Actual MDX compilation
|
|
1384
|
-
* happens client-side via CDN-loaded @mdx-js/mdx in the browser.
|
|
1385
|
-
*/
|
|
1386
|
-
async transpile(template, _options) {
|
|
1387
|
-
const hash = hashString(template);
|
|
1388
|
-
const cached = transpileCache.getByKey(hash);
|
|
1389
|
-
if (cached) {
|
|
1390
|
-
return { ...cached, cached: true };
|
|
1391
|
-
}
|
|
1392
|
-
const transpileResult = {
|
|
1393
|
-
code: template,
|
|
1394
|
-
hash,
|
|
1395
|
-
cached: false
|
|
1396
|
-
};
|
|
1397
|
-
transpileCache.setByKey(hash, transpileResult);
|
|
1398
|
-
return transpileResult;
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* Render MDX template to HTML with CDN scripts.
|
|
1402
|
-
*
|
|
1403
|
-
* The returned HTML includes:
|
|
1404
|
-
* - A container div for the rendered content
|
|
1405
|
-
* - Script tags that load React and MDX from CDN
|
|
1406
|
-
* - Inline script that compiles and renders the MDX
|
|
1407
|
-
*/
|
|
1408
|
-
async render(template, context, options) {
|
|
1409
|
-
const containerId = options?.containerId || "mdx-content";
|
|
1410
|
-
const showLoading = options?.showLoading !== false;
|
|
1411
|
-
const loadingMessage = options?.loadingMessage || "Loading...";
|
|
1412
|
-
const cdn = {
|
|
1413
|
-
...DEFAULT_CDN,
|
|
1414
|
-
...options?.cdn
|
|
1415
|
-
};
|
|
1416
|
-
const props = {
|
|
1417
|
-
input: context.input,
|
|
1418
|
-
output: context.output,
|
|
1419
|
-
structuredContent: context.structuredContent,
|
|
1420
|
-
helpers: context.helpers
|
|
1421
|
-
};
|
|
1422
|
-
const reservedProps = /* @__PURE__ */ new Set(["input", "output", "structuredContent", "helpers", "components"]);
|
|
1423
|
-
const outputProps = typeof context.output === "object" && context.output !== null ? Object.fromEntries(Object.entries(context.output).filter(([key]) => !reservedProps.has(key))) : {};
|
|
1424
|
-
const spreadProps = {
|
|
1425
|
-
...outputProps,
|
|
1426
|
-
...props
|
|
1427
|
-
};
|
|
1428
|
-
const escapedMdx = (0, import_utils.escapeScriptClose)(JSON.stringify(template));
|
|
1429
|
-
const escapedProps = (0, import_utils.escapeScriptClose)(JSON.stringify(spreadProps));
|
|
1430
|
-
const safeContainerId = (0, import_utils.escapeJsString)(containerId);
|
|
1431
|
-
const loadingHtml = showLoading ? `<div class="mdx-loading">${(0, import_utils.escapeHtml)(loadingMessage)}</div>` : "";
|
|
1432
|
-
return `
|
|
1433
|
-
<div id="${(0, import_utils.escapeHtml)(containerId)}">${loadingHtml}</div>
|
|
1434
|
-
<script type="module">
|
|
1435
|
-
(async function() {
|
|
1436
|
-
try {
|
|
1437
|
-
// Load dependencies from CDN
|
|
1438
|
-
const [
|
|
1439
|
-
{ evaluate },
|
|
1440
|
-
runtime,
|
|
1441
|
-
React,
|
|
1442
|
-
{ createRoot }
|
|
1443
|
-
] = await Promise.all([
|
|
1444
|
-
import('${cdn.mdx}'),
|
|
1445
|
-
import('${cdn.jsxRuntime}'),
|
|
1446
|
-
import('${cdn.react}'),
|
|
1447
|
-
import('${cdn.reactDom}')
|
|
1448
|
-
]);
|
|
1449
|
-
|
|
1450
|
-
// MDX content and props
|
|
1451
|
-
const mdxSource = ${escapedMdx};
|
|
1452
|
-
const props = ${escapedProps};
|
|
1453
|
-
|
|
1454
|
-
// Compile and evaluate MDX
|
|
1455
|
-
const { default: Content } = await evaluate(mdxSource, {
|
|
1456
|
-
...runtime,
|
|
1457
|
-
Fragment: React.Fragment,
|
|
1458
|
-
development: false
|
|
1459
|
-
});
|
|
1460
|
-
|
|
1461
|
-
// Render to DOM
|
|
1462
|
-
const container = document.getElementById('${safeContainerId}');
|
|
1463
|
-
if (container) {
|
|
1464
|
-
const root = createRoot(container);
|
|
1465
|
-
root.render(React.createElement(Content, props));
|
|
1466
|
-
}
|
|
1467
|
-
} catch (error) {
|
|
1468
|
-
console.error('[FrontMCP] MDX client rendering failed:', error);
|
|
1469
|
-
const container = document.getElementById('${safeContainerId}');
|
|
1470
|
-
if (container) {
|
|
1471
|
-
container.innerHTML = '<div class="mdx-error">Failed to render MDX content</div>';
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
})();
|
|
1475
|
-
</script>
|
|
1476
|
-
`;
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Get runtime scripts - not needed for client renderer since scripts are inline.
|
|
1480
|
-
*/
|
|
1481
|
-
getRuntimeScripts(platform) {
|
|
1482
|
-
if (platform.networkMode === "blocked") {
|
|
1483
|
-
return {
|
|
1484
|
-
headScripts: "",
|
|
1485
|
-
inlineScripts: `console.warn('[FrontMCP] Client-side MDX rendering requires network access. Use @frontmcp/ui for SSR.');`,
|
|
1486
|
-
isInline: true
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
return {
|
|
1490
|
-
headScripts: "",
|
|
1491
|
-
isInline: false
|
|
1492
|
-
};
|
|
1493
|
-
}
|
|
1494
|
-
};
|
|
1495
|
-
var mdxClientRenderer = new MdxClientRenderer();
|
|
1496
|
-
|
|
1497
|
-
// libs/uipack/src/renderers/utils/transpiler.ts
|
|
1498
|
-
var DEFAULT_SWC_OPTIONS = {
|
|
1499
|
-
typescript: true,
|
|
1500
|
-
jsx: true,
|
|
1501
|
-
jsxRuntime: "automatic",
|
|
1502
|
-
development: false
|
|
1503
|
-
};
|
|
1504
|
-
var swcTransform = null;
|
|
1505
|
-
async function loadSwcTransform() {
|
|
1506
|
-
if (swcTransform !== null) {
|
|
1507
|
-
return swcTransform;
|
|
1508
|
-
}
|
|
1509
|
-
try {
|
|
1510
|
-
const swc = await import(
|
|
1511
|
-
/* webpackIgnore: true */
|
|
1512
|
-
"@swc/core"
|
|
1513
|
-
);
|
|
1514
|
-
swcTransform = swc.transform;
|
|
1515
|
-
return swcTransform;
|
|
1516
|
-
} catch {
|
|
1517
|
-
console.warn(
|
|
1518
|
-
"[@frontmcp/ui] @swc/core not available. Runtime JSX transpilation disabled. Install @swc/core to enable: npm install @swc/core"
|
|
1519
|
-
);
|
|
1520
|
-
return null;
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
async function transpileJsx(source, options = {}) {
|
|
1524
|
-
const hash = hashString(source);
|
|
1525
|
-
const cached = transpileCache.getByKey(hash);
|
|
1526
|
-
if (cached) {
|
|
1527
|
-
return { ...cached, cached: true };
|
|
1528
|
-
}
|
|
1529
|
-
const transform = await loadSwcTransform();
|
|
1530
|
-
if (!transform) {
|
|
1531
|
-
throw new Error(
|
|
1532
|
-
"Runtime JSX transpilation requires @swc/core. Either install @swc/core or use pre-compiled React components."
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
const opts = { ...DEFAULT_SWC_OPTIONS, ...options };
|
|
1536
|
-
const swcOptions = {
|
|
1537
|
-
jsc: {
|
|
1538
|
-
parser: {
|
|
1539
|
-
syntax: opts.typescript ? "typescript" : "ecmascript",
|
|
1540
|
-
tsx: opts.jsx,
|
|
1541
|
-
jsx: opts.jsx
|
|
1542
|
-
},
|
|
1543
|
-
transform: {
|
|
1544
|
-
react: {
|
|
1545
|
-
runtime: opts.jsxRuntime,
|
|
1546
|
-
development: opts.development
|
|
1547
|
-
}
|
|
1548
|
-
},
|
|
1549
|
-
target: "es2020"
|
|
1550
|
-
},
|
|
1551
|
-
module: {
|
|
1552
|
-
type: "commonjs"
|
|
1553
|
-
}
|
|
1554
|
-
};
|
|
1555
|
-
const result = await transform(source, swcOptions);
|
|
1556
|
-
const transpileResult = {
|
|
1557
|
-
code: result.code,
|
|
1558
|
-
hash,
|
|
1559
|
-
cached: false
|
|
1560
|
-
};
|
|
1561
|
-
transpileCache.setByKey(hash, transpileResult);
|
|
1562
|
-
return transpileResult;
|
|
1563
|
-
}
|
|
1564
|
-
async function isSwcAvailable() {
|
|
1565
|
-
const transform = await loadSwcTransform();
|
|
1566
|
-
return transform !== null;
|
|
1567
|
-
}
|
|
1568
|
-
async function executeTranspiledCode(_code, _context = {}) {
|
|
1569
|
-
throw new Error(
|
|
1570
|
-
'executeTranspiledCode has been moved to @frontmcp/ui/renderers. Install @frontmcp/ui and import from there: import { executeTranspiledCode } from "@frontmcp/ui/renderers"'
|
|
1571
|
-
);
|
|
1572
|
-
}
|
|
1573
|
-
async function transpileAndExecute(_source, _context = {}) {
|
|
1574
|
-
throw new Error(
|
|
1575
|
-
'transpileAndExecute has been moved to @frontmcp/ui/renderers. Install @frontmcp/ui and import from there: import { transpileAndExecute } from "@frontmcp/ui/renderers"'
|
|
1576
|
-
);
|
|
1577
|
-
}
|
|
1578
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1579
|
-
0 && (module.exports = {
|
|
1580
|
-
HtmlRenderer,
|
|
1581
|
-
MdxClientRenderer,
|
|
1582
|
-
RendererRegistry,
|
|
1583
|
-
TranspileCache,
|
|
1584
|
-
buildReactCdnUrls,
|
|
1585
|
-
componentCache,
|
|
1586
|
-
containsJsx,
|
|
1587
|
-
containsMdxSyntax,
|
|
1588
|
-
detectTemplateType,
|
|
1589
|
-
executeTranspiledCode,
|
|
1590
|
-
hashCombined,
|
|
1591
|
-
hashString,
|
|
1592
|
-
htmlRenderer,
|
|
1593
|
-
isHash,
|
|
1594
|
-
isPlainHtml,
|
|
1595
|
-
isReactComponent,
|
|
1596
|
-
isSwcAvailable,
|
|
1597
|
-
isTemplateBuilderFunction,
|
|
1598
|
-
mdxClientRenderer,
|
|
1599
|
-
rendererRegistry,
|
|
1600
|
-
transpileAndExecute,
|
|
1601
|
-
transpileCache,
|
|
1602
|
-
transpileJsx
|
|
1603
|
-
});
|