coralite 0.38.0 → 0.38.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/dist/lib/compiler.d.ts.map +1 -1
- package/dist/lib/index.js +122 -5
- package/dist/lib/index.js.map +2 -2
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils/client/inject.js +8 -1
- package/dist/lib/utils/client/inject.js.map +2 -2
- package/dist/lib/utils/client/runtime.d.ts.map +1 -1
- package/dist/lib/utils/server/server.d.ts +1 -4
- package/dist/lib/utils/server/server.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +9 -4
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/script.d.ts +5 -1
- package/dist/types/script.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../lib/compiler.js"],"names":[],"mappings":"AAiBA;;;;;;;;;GASG;AACH,uFANG;IAAkC,IAAI,EAA9B,gBAAgB;IACe,OAAO,EAAtC,qBAAqB;IACL,MAAM;IACJ,uBAAuB;CACjD,GAAU,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,UAAU,EAAE,GAAG,CAAA;CAAE,KAAK,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../lib/compiler.js"],"names":[],"mappings":"AAiBA;;;;;;;;;GASG;AACH,uFANG;IAAkC,IAAI,EAA9B,gBAAgB;IACe,OAAO,EAAtC,qBAAqB;IACL,MAAM;IACJ,uBAAuB;CACjD,GAAU,CAAC,SAAS,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE;IAAE,UAAU,EAAE,GAAG,CAAA;CAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAwFzG;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,mLAhBG;IAAgC,MAAM,EAA9B,cAAc;IACqB,KAAK,EAAxC,yBAAyB;IACH,IAAI,EAA1B,YAAY;IACC,IAAI,EAAjB,GAAG;IACa,SAAS,EAAzB,MAAM;IACmB,OAAO,EAAhC,eAAe;IACE,WAAW,EAA5B,OAAO;IACS,GAAG;IACH,MAAM;IACJ,WAAW;IACX,eAAe;IACf,oBAAoB;IACpB,YAAY;CAEtC,GAAU,OAAO,CAAC,yBAAyB,CAAC,CAmI9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,kLAhBG;IAAgC,MAAM,EAA9B,cAAc;IACqB,KAAK,EAAxC,yBAAyB;IACH,IAAI,EAA1B,YAAY;IACC,IAAI,EAAjB,GAAG;IACa,SAAS,EAAzB,MAAM;IACmB,OAAO,EAAhC,eAAe;IACE,WAAW,EAA5B,OAAO;IACS,GAAG;IACH,MAAM;IACJ,WAAW;IACX,eAAe;IACf,oBAAoB;IACpB,YAAY;CAEtC,GAAU,OAAO,CAAC,yBAAyB,CAAC,CA8H9C;AAED;;;GAGG;AACH,kCAFW,GAAG,sCAOb;sCA5ZqI,mBAAmB;2CAAnB,mBAAmB;4BAC9H,SAAS;oCADkG,mBAAmB;+CAAnB,mBAAmB;kCAAnB,mBAAmB;qCAAnB,mBAAmB"}
|
package/dist/lib/index.js
CHANGED
|
@@ -2154,11 +2154,39 @@ function getAST(code, locations = false) {
|
|
|
2154
2154
|
astCache.set(cacheKey, ast);
|
|
2155
2155
|
return ast;
|
|
2156
2156
|
}
|
|
2157
|
+
function extractFromHTMLString(html, components) {
|
|
2158
|
+
try {
|
|
2159
|
+
const matches = html.matchAll(/<([a-zA-Z0-9-]+)/g);
|
|
2160
|
+
for (const match of matches) {
|
|
2161
|
+
const tag = match[1].toLowerCase();
|
|
2162
|
+
if (tag.includes("-")) {
|
|
2163
|
+
components.add(tag);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
} catch {
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2157
2169
|
function findAndExtractScript(code) {
|
|
2158
2170
|
const ast = getAST(code, true);
|
|
2159
2171
|
let result = null;
|
|
2160
2172
|
const components = /* @__PURE__ */ new Set();
|
|
2173
|
+
const findHTMLComponents = (node) => {
|
|
2174
|
+
if (node.type === "Literal" && typeof node.value === "string") {
|
|
2175
|
+
extractFromHTMLString(node.value, components);
|
|
2176
|
+
} else if (node.type === "TemplateLiteral") {
|
|
2177
|
+
for (const element of node.quasis) {
|
|
2178
|
+
if (element.value && element.value.cooked) {
|
|
2179
|
+
extractFromHTMLString(element.value.cooked, components);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2161
2184
|
walkJS(ast, {
|
|
2185
|
+
AssignmentExpression(node) {
|
|
2186
|
+
if (node.left.type === "MemberExpression" && node.left.property.type === "Identifier" && (node.left.property.name === "innerHTML" || node.left.property.name === "outerHTML")) {
|
|
2187
|
+
findHTMLComponents(node.right);
|
|
2188
|
+
}
|
|
2189
|
+
},
|
|
2162
2190
|
CallExpression(node) {
|
|
2163
2191
|
if (node.callee && node.callee.type === "MemberExpression" && node.callee.object && node.callee.object.type === "Identifier" && node.callee.object.name === "document" && node.callee.property && node.callee.property.type === "Identifier" && node.callee.property.name === "createElement") {
|
|
2164
2192
|
const arg = node.arguments[0];
|
|
@@ -2168,6 +2196,12 @@ function findAndExtractScript(code) {
|
|
|
2168
2196
|
}
|
|
2169
2197
|
}
|
|
2170
2198
|
}
|
|
2199
|
+
if (node.callee && node.callee.type === "MemberExpression" && node.callee.property && node.callee.property.type === "Identifier" && node.callee.property.name === "insertAdjacentHTML") {
|
|
2200
|
+
const arg = node.arguments[1];
|
|
2201
|
+
if (arg) {
|
|
2202
|
+
findHTMLComponents(arg);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2171
2205
|
if (node.callee && node.callee.type === "Identifier" && node.callee.name === "defineComponent") {
|
|
2172
2206
|
const firstArg = node.arguments[0];
|
|
2173
2207
|
if (firstArg && firstArg.type === "ObjectExpression") {
|
|
@@ -2182,6 +2216,21 @@ function findAndExtractScript(code) {
|
|
|
2182
2216
|
let source = code.slice(value.start, value.end);
|
|
2183
2217
|
const replacements = [];
|
|
2184
2218
|
walkJS(value, {
|
|
2219
|
+
AssignmentExpression(node2) {
|
|
2220
|
+
if (node2.left.type === "MemberExpression" && node2.left.property.type === "Identifier" && (node2.left.property.name === "innerHTML" || node2.left.property.name === "outerHTML")) {
|
|
2221
|
+
findHTMLComponents(node2.right);
|
|
2222
|
+
replacements.push({
|
|
2223
|
+
start: node2.right.start - value.start,
|
|
2224
|
+
end: node2.right.start - value.start,
|
|
2225
|
+
replacement: "processHTML("
|
|
2226
|
+
});
|
|
2227
|
+
replacements.push({
|
|
2228
|
+
start: node2.right.end - value.start,
|
|
2229
|
+
end: node2.right.end - value.start,
|
|
2230
|
+
replacement: ")"
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
},
|
|
2185
2234
|
CallExpression(node2) {
|
|
2186
2235
|
if (node2.callee && node2.callee.type === "MemberExpression" && node2.callee.object && node2.callee.object.type === "Identifier" && node2.callee.object.name === "document" && node2.callee.property && node2.callee.property.type === "Identifier" && node2.callee.property.name === "createElement") {
|
|
2187
2236
|
const arg = node2.arguments[0];
|
|
@@ -2196,6 +2245,22 @@ function findAndExtractScript(code) {
|
|
|
2196
2245
|
});
|
|
2197
2246
|
}
|
|
2198
2247
|
}
|
|
2248
|
+
if (node2.callee && node2.callee.type === "MemberExpression" && node2.callee.property && node2.callee.property.type === "Identifier" && node2.callee.property.name === "insertAdjacentHTML") {
|
|
2249
|
+
const arg = node2.arguments[1];
|
|
2250
|
+
if (arg) {
|
|
2251
|
+
findHTMLComponents(arg);
|
|
2252
|
+
replacements.push({
|
|
2253
|
+
start: arg.start - value.start,
|
|
2254
|
+
end: arg.start - value.start,
|
|
2255
|
+
replacement: "processHTML("
|
|
2256
|
+
});
|
|
2257
|
+
replacements.push({
|
|
2258
|
+
start: arg.end - value.start,
|
|
2259
|
+
end: arg.end - value.start,
|
|
2260
|
+
replacement: ")"
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2199
2264
|
}
|
|
2200
2265
|
});
|
|
2201
2266
|
replacements.sort((a, b) => b.start - a.start);
|
|
@@ -2230,7 +2295,7 @@ function findAndExtractScript(code) {
|
|
|
2230
2295
|
}
|
|
2231
2296
|
}
|
|
2232
2297
|
});
|
|
2233
|
-
if (result
|
|
2298
|
+
if (result) {
|
|
2234
2299
|
result.components = Array.from(components);
|
|
2235
2300
|
}
|
|
2236
2301
|
return result;
|
|
@@ -2284,7 +2349,21 @@ function findAndExtractImperativeComponents(code) {
|
|
|
2284
2349
|
try {
|
|
2285
2350
|
const ast = getAST(code);
|
|
2286
2351
|
const components = /* @__PURE__ */ new Set();
|
|
2352
|
+
const findHTMLComponents = (node) => {
|
|
2353
|
+
if (node.type === "Literal" && typeof node.value === "string") {
|
|
2354
|
+
extractFromHTMLString(node.value, components);
|
|
2355
|
+
} else if (node.type === "TemplateLiteral") {
|
|
2356
|
+
for (const element of node.quasis) {
|
|
2357
|
+
extractFromHTMLString(element.value.cooked, components);
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2287
2361
|
walkJS(ast, {
|
|
2362
|
+
AssignmentExpression(node) {
|
|
2363
|
+
if (node.left.type === "MemberExpression" && node.left.property.type === "Identifier" && (node.left.property.name === "innerHTML" || node.left.property.name === "outerHTML")) {
|
|
2364
|
+
findHTMLComponents(node.right);
|
|
2365
|
+
}
|
|
2366
|
+
},
|
|
2288
2367
|
CallExpression(node) {
|
|
2289
2368
|
if (node.callee && (node.callee.type === "MemberExpression" && node.callee.object && node.callee.object.type === "Identifier" && node.callee.object.name === "document" && node.callee.property && node.callee.property.type === "Identifier" && node.callee.property.name === "createElement" || node.callee.type === "Identifier" && node.callee.name === "createCoraliteElement")) {
|
|
2290
2369
|
const arg = node.arguments[0];
|
|
@@ -2292,6 +2371,12 @@ function findAndExtractImperativeComponents(code) {
|
|
|
2292
2371
|
components.add(arg.value);
|
|
2293
2372
|
}
|
|
2294
2373
|
}
|
|
2374
|
+
if (node.callee && node.callee.type === "MemberExpression" && node.callee.property && node.callee.property.type === "Identifier" && node.callee.property.name === "insertAdjacentHTML") {
|
|
2375
|
+
const arg = node.arguments[1];
|
|
2376
|
+
if (arg) {
|
|
2377
|
+
findHTMLComponents(arg);
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2295
2380
|
}
|
|
2296
2381
|
});
|
|
2297
2382
|
return [...components];
|
|
@@ -2541,7 +2626,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
2541
2626
|
${contextParts}
|
|
2542
2627
|
};
|
|
2543
2628
|
`);
|
|
2544
|
-
entryCodeParts.push("const globalContext = {
|
|
2629
|
+
entryCodeParts.push("const globalContext = {};\n");
|
|
2545
2630
|
entryCodeParts.push(`const resolvedContextFactoriesPromise = (async () => {
|
|
2546
2631
|
const factories = {};
|
|
2547
2632
|
const keys = Object.keys(coraliteComponentClientContextProps);
|
|
@@ -2821,19 +2906,24 @@ export default {
|
|
|
2821
2906
|
`;
|
|
2822
2907
|
contents += "export const clientContextProps = {\n";
|
|
2823
2908
|
if (module.context) {
|
|
2824
|
-
const clientName = module.name;
|
|
2909
|
+
const clientName = module.client?.name || module.name;
|
|
2825
2910
|
if (["id", "state", "page", "root", "signal"].includes(clientName)) {
|
|
2826
2911
|
throw new CoraliteError(`Reserved context key '${clientName}' cannot be used in plugin context.`);
|
|
2827
2912
|
}
|
|
2828
2913
|
const fn = normalizeFunction(module.context);
|
|
2914
|
+
const clientConfig = module.client?.config || module.config || {};
|
|
2915
|
+
const configStr = JSON.stringify(clientConfig);
|
|
2829
2916
|
contents += ` "${clientName}": async (globalContext) => {
|
|
2830
2917
|
`;
|
|
2831
2918
|
contents += ` const fn = ${fn};
|
|
2919
|
+
`;
|
|
2920
|
+
contents += ` const pluginConfig = ${configStr};
|
|
2832
2921
|
`;
|
|
2833
2922
|
contents += ` const pluginContext = new Proxy(globalContext, {
|
|
2834
2923
|
get (target, prop) {
|
|
2835
2924
|
if (prop === 'config') return pluginConfig;
|
|
2836
|
-
return target[prop];
|
|
2925
|
+
if (prop in target) return target[prop];
|
|
2926
|
+
return undefined;
|
|
2837
2927
|
},
|
|
2838
2928
|
set (target, prop, value) {
|
|
2839
2929
|
return Reflect.set(target, prop, value);
|
|
@@ -3512,6 +3602,7 @@ function createModuleLinker({ path: path2, context: context2, source, importModu
|
|
|
3512
3602
|
}
|
|
3513
3603
|
coraliteExports += "export const defineComponent = globalThis.__coralite_define_component__;\n";
|
|
3514
3604
|
coraliteExports += "export const createCoraliteElement = globalThis.__coralite_create_coralite_element__;\n";
|
|
3605
|
+
coraliteExports += "export const processHTML = globalThis.__coralite_process_html__;\n";
|
|
3515
3606
|
return new SourceTextModule(coraliteExports, {
|
|
3516
3607
|
context: referencingModule.context,
|
|
3517
3608
|
importModuleDynamically
|
|
@@ -3607,6 +3698,12 @@ async function evaluateDevelopment({
|
|
|
3607
3698
|
return globalThis.createCoraliteElement(tag, options);
|
|
3608
3699
|
}
|
|
3609
3700
|
return globalThis.document.createElement(tag, options);
|
|
3701
|
+
},
|
|
3702
|
+
__coralite_process_html__: (html) => {
|
|
3703
|
+
if (typeof globalThis.processHTML === "function") {
|
|
3704
|
+
return globalThis.processHTML(html);
|
|
3705
|
+
}
|
|
3706
|
+
return html;
|
|
3610
3707
|
}
|
|
3611
3708
|
};
|
|
3612
3709
|
for (const glob of usedGlobals) {
|
|
@@ -3712,14 +3809,22 @@ async function evaluateProduction({
|
|
|
3712
3809
|
}
|
|
3713
3810
|
return globalThis.document.createElement(tag, options);
|
|
3714
3811
|
};
|
|
3812
|
+
const processHTML = (html) => {
|
|
3813
|
+
if (typeof globalThis.processHTML === "function") {
|
|
3814
|
+
return globalThis.processHTML(html);
|
|
3815
|
+
}
|
|
3816
|
+
return html;
|
|
3817
|
+
};
|
|
3715
3818
|
return {
|
|
3716
3819
|
...symmetricalContext,
|
|
3717
3820
|
defineComponent: (options) => defineComponent2(options, symmetricalContext),
|
|
3718
3821
|
createCoraliteElement: createCoraliteElement2,
|
|
3822
|
+
processHTML,
|
|
3719
3823
|
default: {
|
|
3720
3824
|
...symmetricalContext,
|
|
3721
3825
|
defineComponent: (options) => defineComponent2(options, symmetricalContext),
|
|
3722
|
-
createCoraliteElement: createCoraliteElement2
|
|
3826
|
+
createCoraliteElement: createCoraliteElement2,
|
|
3827
|
+
processHTML
|
|
3723
3828
|
}
|
|
3724
3829
|
};
|
|
3725
3830
|
}
|
|
@@ -4724,6 +4829,18 @@ import { getClientContext, createCoraliteClass, globalClientHooks } from '${base
|
|
|
4724
4829
|
}
|
|
4725
4830
|
return document.createElement(tag, options);
|
|
4726
4831
|
};
|
|
4832
|
+
|
|
4833
|
+
window.processHTML = (html) => {
|
|
4834
|
+
if (typeof html !== 'string') return html;
|
|
4835
|
+
const matches = html.matchAll(/<([a-zA-Z0-9-]+)/g);
|
|
4836
|
+
for (const match of matches) {
|
|
4837
|
+
const tag = match[1].toLowerCase();
|
|
4838
|
+
if (componentManifest[tag]) {
|
|
4839
|
+
loadComponent(tag);
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
return html;
|
|
4843
|
+
};
|
|
4727
4844
|
})();
|
|
4728
4845
|
`.trim();
|
|
4729
4846
|
}
|