coralite 0.33.0 → 0.33.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/index.js +140 -120
- package/dist/lib/index.js.map +4 -4
- package/dist/lib/script-manager.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +39 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/llms.txt +369 -0
- package/package.json +3 -2
package/dist/lib/index.js
CHANGED
|
@@ -5973,6 +5973,56 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function(node,
|
|
|
5973
5973
|
}
|
|
5974
5974
|
};
|
|
5975
5975
|
|
|
5976
|
+
// lib/utils.js
|
|
5977
|
+
import render from "dom-serializer";
|
|
5978
|
+
|
|
5979
|
+
// lib/type-helper.js
|
|
5980
|
+
function isObject(obj) {
|
|
5981
|
+
return typeof obj === "object" && obj !== null;
|
|
5982
|
+
}
|
|
5983
|
+
function isCoraliteElement(obj) {
|
|
5984
|
+
return isObject(obj) && obj.type === "tag";
|
|
5985
|
+
}
|
|
5986
|
+
function isCoraliteTextNode(obj) {
|
|
5987
|
+
return isObject(obj) && obj.type === "text";
|
|
5988
|
+
}
|
|
5989
|
+
function isCoraliteComment(obj) {
|
|
5990
|
+
return isObject(obj) && obj.type === "comment";
|
|
5991
|
+
}
|
|
5992
|
+
function isCoraliteDirective(obj) {
|
|
5993
|
+
return isObject(obj) && obj.type === "directive";
|
|
5994
|
+
}
|
|
5995
|
+
function isCoraliteComponentRoot(obj) {
|
|
5996
|
+
return isObject(obj) && obj.type === "root";
|
|
5997
|
+
}
|
|
5998
|
+
function isCoraliteSlotElement(obj) {
|
|
5999
|
+
return isObject(obj) && typeof obj.name === "string" && isCoraliteElement(obj.element) && (obj.customElement === void 0 || isCoraliteElement(obj.customElement));
|
|
6000
|
+
}
|
|
6001
|
+
function isCoraliteCollectionItem(obj) {
|
|
6002
|
+
return isObject(obj) && "path" in obj && isObject(obj.path) && typeof obj.content === "string";
|
|
6003
|
+
}
|
|
6004
|
+
function isCoraliteNode(obj) {
|
|
6005
|
+
return isCoraliteElement(obj) || isCoraliteTextNode(obj) || isCoraliteComment(obj) || isCoraliteDirective(obj) || isCoraliteComponentRoot(obj);
|
|
6006
|
+
}
|
|
6007
|
+
function hasValidElementStructure(obj) {
|
|
6008
|
+
return isCoraliteElement(obj) && typeof obj.name === "string" && isObject(obj.attribs) && Array.isArray(obj.children);
|
|
6009
|
+
}
|
|
6010
|
+
function hasValidTextNodeStructure(obj) {
|
|
6011
|
+
return isCoraliteTextNode(obj) && typeof obj.data === "string";
|
|
6012
|
+
}
|
|
6013
|
+
function hasValidCommentStructure(obj) {
|
|
6014
|
+
return isCoraliteComment(obj) && typeof obj.data === "string";
|
|
6015
|
+
}
|
|
6016
|
+
function isValidChildNode(obj) {
|
|
6017
|
+
return isCoraliteElement(obj) || isCoraliteTextNode(obj) || isCoraliteComment(obj) || isCoraliteDirective(obj);
|
|
6018
|
+
}
|
|
6019
|
+
function isParentNode(obj) {
|
|
6020
|
+
return isObject(obj) && Array.isArray(obj.children);
|
|
6021
|
+
}
|
|
6022
|
+
function isRemovableNode(obj) {
|
|
6023
|
+
return isObject(obj) && obj.remove === true;
|
|
6024
|
+
}
|
|
6025
|
+
|
|
5976
6026
|
// lib/dom.js
|
|
5977
6027
|
var ELEMENT_NODE = 1;
|
|
5978
6028
|
var TEXT_NODE = 3;
|
|
@@ -6451,7 +6501,13 @@ function cleanKeys(object) {
|
|
|
6451
6501
|
}
|
|
6452
6502
|
return result;
|
|
6453
6503
|
}
|
|
6454
|
-
function normalizeObjectFunctions(target, seen = /* @__PURE__ */ new WeakMap()) {
|
|
6504
|
+
function normalizeObjectFunctions(target, transform2 = null, seen = /* @__PURE__ */ new WeakMap()) {
|
|
6505
|
+
if (typeof transform2 === "function") {
|
|
6506
|
+
const transformed = transform2(target);
|
|
6507
|
+
if (transformed !== target) {
|
|
6508
|
+
return transformed;
|
|
6509
|
+
}
|
|
6510
|
+
}
|
|
6455
6511
|
if (typeof target !== "object" || target === null) {
|
|
6456
6512
|
return target;
|
|
6457
6513
|
}
|
|
@@ -6462,7 +6518,7 @@ function normalizeObjectFunctions(target, seen = /* @__PURE__ */ new WeakMap())
|
|
|
6462
6518
|
const arr = [];
|
|
6463
6519
|
seen.set(target, arr);
|
|
6464
6520
|
for (let i = 0; i < target.length; i++) {
|
|
6465
|
-
arr.push(normalizeObjectFunctions(target[i], seen));
|
|
6521
|
+
arr.push(normalizeObjectFunctions(target[i], transform2, seen));
|
|
6466
6522
|
}
|
|
6467
6523
|
return arr;
|
|
6468
6524
|
}
|
|
@@ -6479,7 +6535,7 @@ function normalizeObjectFunctions(target, seen = /* @__PURE__ */ new WeakMap())
|
|
|
6479
6535
|
wrapper.toString = () => normalizedString;
|
|
6480
6536
|
obj[key] = wrapper;
|
|
6481
6537
|
} else {
|
|
6482
|
-
obj[key] = normalizeObjectFunctions(target[key], seen);
|
|
6538
|
+
obj[key] = normalizeObjectFunctions(target[key], transform2, seen);
|
|
6483
6539
|
}
|
|
6484
6540
|
}
|
|
6485
6541
|
}
|
|
@@ -6762,6 +6818,73 @@ function findAndExtractProperties(code) {
|
|
|
6762
6818
|
});
|
|
6763
6819
|
return result;
|
|
6764
6820
|
}
|
|
6821
|
+
function astTransformer(target) {
|
|
6822
|
+
if (isCoraliteNode(target)) {
|
|
6823
|
+
return render(target, { decodeEntities: false });
|
|
6824
|
+
}
|
|
6825
|
+
if (Array.isArray(target) && target.length > 0 && isCoraliteNode(target[0])) {
|
|
6826
|
+
return render(target, { decodeEntities: false });
|
|
6827
|
+
}
|
|
6828
|
+
return target;
|
|
6829
|
+
}
|
|
6830
|
+
function addComponentAndDependencies(componentId, processed, sharedFunctions) {
|
|
6831
|
+
if (!processed[componentId] && sharedFunctions[componentId]) {
|
|
6832
|
+
processed[componentId] = true;
|
|
6833
|
+
const dependencies = sharedFunctions[componentId].components || [];
|
|
6834
|
+
for (const depId of dependencies) {
|
|
6835
|
+
addComponentAndDependencies(depId, processed, sharedFunctions);
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
}
|
|
6839
|
+
function cleanAST(nodes, nodeMap, state) {
|
|
6840
|
+
if (!nodes) {
|
|
6841
|
+
return null;
|
|
6842
|
+
}
|
|
6843
|
+
return nodes.map((node) => {
|
|
6844
|
+
const cloned = { ...node };
|
|
6845
|
+
const id = state.counter++;
|
|
6846
|
+
nodeMap.set(node, id);
|
|
6847
|
+
cloned._id = id;
|
|
6848
|
+
delete cloned.parent;
|
|
6849
|
+
delete cloned.prev;
|
|
6850
|
+
delete cloned.next;
|
|
6851
|
+
if (cloned.children) {
|
|
6852
|
+
cloned.children = cleanAST(cloned.children, nodeMap, state);
|
|
6853
|
+
}
|
|
6854
|
+
return cloned;
|
|
6855
|
+
});
|
|
6856
|
+
}
|
|
6857
|
+
function cleanValues(values, nodeMap) {
|
|
6858
|
+
if (!values) {
|
|
6859
|
+
return null;
|
|
6860
|
+
}
|
|
6861
|
+
const result = { ...values };
|
|
6862
|
+
if (result.attributes) {
|
|
6863
|
+
result.attributes = result.attributes.map((item) => {
|
|
6864
|
+
const cloned = { ...item };
|
|
6865
|
+
cloned.elementId = nodeMap.get(item.element);
|
|
6866
|
+
delete cloned.element;
|
|
6867
|
+
return cloned;
|
|
6868
|
+
});
|
|
6869
|
+
}
|
|
6870
|
+
if (result.textNodes) {
|
|
6871
|
+
result.textNodes = result.textNodes.map((item) => {
|
|
6872
|
+
const cloned = { ...item };
|
|
6873
|
+
cloned.textNodeId = nodeMap.get(item.textNode);
|
|
6874
|
+
delete cloned.textNode;
|
|
6875
|
+
return cloned;
|
|
6876
|
+
});
|
|
6877
|
+
}
|
|
6878
|
+
if (result.refs) {
|
|
6879
|
+
result.refs = result.refs.map((item) => {
|
|
6880
|
+
const cloned = { ...item };
|
|
6881
|
+
cloned.elementId = nodeMap.get(item.element);
|
|
6882
|
+
delete cloned.element;
|
|
6883
|
+
return cloned;
|
|
6884
|
+
});
|
|
6885
|
+
}
|
|
6886
|
+
return result;
|
|
6887
|
+
}
|
|
6765
6888
|
function mergePluginState(current2, patch) {
|
|
6766
6889
|
if (!patch || typeof patch !== "object") {
|
|
6767
6890
|
return current2;
|
|
@@ -10270,24 +10393,15 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
10270
10393
|
`);
|
|
10271
10394
|
const instanceValues = Object.entries(instances);
|
|
10272
10395
|
const processedComponent = {};
|
|
10273
|
-
const addComponentAndDependencies = (componentId) => {
|
|
10274
|
-
if (!processedComponent[componentId] && this.sharedFunctions[componentId]) {
|
|
10275
|
-
processedComponent[componentId] = true;
|
|
10276
|
-
const dependencies = this.sharedFunctions[componentId].components || [];
|
|
10277
|
-
for (const depId of dependencies) {
|
|
10278
|
-
addComponentAndDependencies(depId);
|
|
10279
|
-
}
|
|
10280
|
-
}
|
|
10281
|
-
};
|
|
10282
10396
|
for (const instanceData of instanceValues) {
|
|
10283
|
-
addComponentAndDependencies(instanceData[1].componentId);
|
|
10397
|
+
addComponentAndDependencies(instanceData[1].componentId, processedComponent, this.sharedFunctions);
|
|
10284
10398
|
}
|
|
10285
10399
|
for (const plugin of this.plugins) {
|
|
10286
10400
|
if (plugin && plugin._extractedComponents && Array.isArray(plugin._extractedComponents)) {
|
|
10287
10401
|
for (const compPath of plugin._extractedComponents) {
|
|
10288
10402
|
for (const [id, fnData] of Object.entries(this.sharedFunctions)) {
|
|
10289
10403
|
if (compPath.endsWith(`/${id}.html`) || compPath.endsWith(`\\${id}.html`) || compPath === id || compPath.endsWith(`/${id}`)) {
|
|
10290
|
-
addComponentAndDependencies(id);
|
|
10404
|
+
addComponentAndDependencies(id, processedComponent, this.sharedFunctions);
|
|
10291
10405
|
}
|
|
10292
10406
|
}
|
|
10293
10407
|
}
|
|
@@ -10327,7 +10441,7 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
10327
10441
|
entryCodeParts.push("const coraliteComponentDefaults = {\n");
|
|
10328
10442
|
for (const key of processedComponentKeys) {
|
|
10329
10443
|
if (this.sharedFunctions[key] && this.sharedFunctions[key].defaultValues) {
|
|
10330
|
-
const normalizedDefaults = normalizeObjectFunctions(this.sharedFunctions[key].defaultValues);
|
|
10444
|
+
const normalizedDefaults = normalizeObjectFunctions(this.sharedFunctions[key].defaultValues, astTransformer);
|
|
10331
10445
|
entryCodeParts.push(` "${key}": (() => {
|
|
10332
10446
|
`);
|
|
10333
10447
|
entryCodeParts.push(` const defaults = ${serialize(normalizedDefaults)};
|
|
@@ -10368,58 +10482,9 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
10368
10482
|
`;
|
|
10369
10483
|
}
|
|
10370
10484
|
const nodeMap = /* @__PURE__ */ new WeakMap();
|
|
10371
|
-
|
|
10372
|
-
const
|
|
10373
|
-
|
|
10374
|
-
return null;
|
|
10375
|
-
}
|
|
10376
|
-
return nodes.map((node) => {
|
|
10377
|
-
const cloned = { ...node };
|
|
10378
|
-
const id = nodeCounter++;
|
|
10379
|
-
nodeMap.set(node, id);
|
|
10380
|
-
cloned._id = id;
|
|
10381
|
-
delete cloned.parent;
|
|
10382
|
-
delete cloned.prev;
|
|
10383
|
-
delete cloned.next;
|
|
10384
|
-
if (cloned.children) {
|
|
10385
|
-
cloned.children = cleanAST(cloned.children);
|
|
10386
|
-
}
|
|
10387
|
-
return cloned;
|
|
10388
|
-
});
|
|
10389
|
-
};
|
|
10390
|
-
const cleanValues = (values) => {
|
|
10391
|
-
if (!values) {
|
|
10392
|
-
return null;
|
|
10393
|
-
}
|
|
10394
|
-
const result2 = { ...values };
|
|
10395
|
-
if (result2.attributes) {
|
|
10396
|
-
result2.attributes = result2.attributes.map((item) => {
|
|
10397
|
-
const cloned = { ...item };
|
|
10398
|
-
cloned.elementId = nodeMap.get(item.element);
|
|
10399
|
-
delete cloned.element;
|
|
10400
|
-
return cloned;
|
|
10401
|
-
});
|
|
10402
|
-
}
|
|
10403
|
-
if (result2.textNodes) {
|
|
10404
|
-
result2.textNodes = result2.textNodes.map((item) => {
|
|
10405
|
-
const cloned = { ...item };
|
|
10406
|
-
cloned.textNodeId = nodeMap.get(item.textNode);
|
|
10407
|
-
delete cloned.textNode;
|
|
10408
|
-
return cloned;
|
|
10409
|
-
});
|
|
10410
|
-
}
|
|
10411
|
-
if (result2.refs) {
|
|
10412
|
-
result2.refs = result2.refs.map((item) => {
|
|
10413
|
-
const cloned = { ...item };
|
|
10414
|
-
cloned.elementId = nodeMap.get(item.element);
|
|
10415
|
-
delete cloned.element;
|
|
10416
|
-
return cloned;
|
|
10417
|
-
});
|
|
10418
|
-
}
|
|
10419
|
-
return result2;
|
|
10420
|
-
};
|
|
10421
|
-
const templateAST = serialize(cleanAST(this.sharedFunctions[componentId].templateAST) || []);
|
|
10422
|
-
const templateValues = serialize(cleanValues(this.sharedFunctions[componentId].templateValues) || {
|
|
10485
|
+
const state = { counter: 0 };
|
|
10486
|
+
const templateAST = serialize(cleanAST(this.sharedFunctions[componentId].templateAST, nodeMap, state) || []);
|
|
10487
|
+
const templateValues = serialize(cleanValues(this.sharedFunctions[componentId].templateValues, nodeMap) || {
|
|
10423
10488
|
attributes: [],
|
|
10424
10489
|
textNodes: [],
|
|
10425
10490
|
refs: []
|
|
@@ -10427,13 +10492,13 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
|
|
|
10427
10492
|
const styles = JSON.stringify(this.sharedFunctions[componentId].styles || "");
|
|
10428
10493
|
let normalizedDefaults = this.sharedFunctions[componentId].defaultValues || {};
|
|
10429
10494
|
if (this.sharedFunctions[componentId].defaultValues) {
|
|
10430
|
-
normalizedDefaults = normalizeObjectFunctions(this.sharedFunctions[componentId].defaultValues);
|
|
10495
|
+
normalizedDefaults = normalizeObjectFunctions(this.sharedFunctions[componentId].defaultValues, astTransformer);
|
|
10431
10496
|
}
|
|
10432
10497
|
const defaults = serialize(normalizedDefaults);
|
|
10433
10498
|
const dependencies = JSON.stringify(this.sharedFunctions[componentId].components || []);
|
|
10434
10499
|
let normalizedSlots = this.sharedFunctions[componentId].slots || {};
|
|
10435
10500
|
if (this.sharedFunctions[componentId].slots) {
|
|
10436
|
-
normalizedSlots = normalizeObjectFunctions(this.sharedFunctions[componentId].slots);
|
|
10501
|
+
normalizedSlots = normalizeObjectFunctions(this.sharedFunctions[componentId].slots, astTransformer);
|
|
10437
10502
|
}
|
|
10438
10503
|
const slots = serialize(normalizedSlots);
|
|
10439
10504
|
componentEntryCode += `
|
|
@@ -11186,58 +11251,9 @@ import { mkdir as mkdir2, writeFile } from "node:fs/promises";
|
|
|
11186
11251
|
import { dirname as dirname5, join as join3, normalize, relative, resolve as resolve2 } from "node:path";
|
|
11187
11252
|
import { createRequire as createRequire2 } from "node:module";
|
|
11188
11253
|
import { transform } from "esbuild";
|
|
11189
|
-
|
|
11190
|
-
// lib/type-helper.js
|
|
11191
|
-
function isObject(obj) {
|
|
11192
|
-
return typeof obj === "object" && obj !== null;
|
|
11193
|
-
}
|
|
11194
|
-
function isCoraliteElement(obj) {
|
|
11195
|
-
return isObject(obj) && obj.type === "tag";
|
|
11196
|
-
}
|
|
11197
|
-
function isCoraliteTextNode(obj) {
|
|
11198
|
-
return isObject(obj) && obj.type === "text";
|
|
11199
|
-
}
|
|
11200
|
-
function isCoraliteComment(obj) {
|
|
11201
|
-
return isObject(obj) && obj.type === "comment";
|
|
11202
|
-
}
|
|
11203
|
-
function isCoraliteDirective(obj) {
|
|
11204
|
-
return isObject(obj) && obj.type === "directive";
|
|
11205
|
-
}
|
|
11206
|
-
function isCoraliteComponentRoot(obj) {
|
|
11207
|
-
return isObject(obj) && obj.type === "root";
|
|
11208
|
-
}
|
|
11209
|
-
function isCoraliteSlotElement(obj) {
|
|
11210
|
-
return isObject(obj) && typeof obj.name === "string" && isCoraliteElement(obj.element) && (obj.customElement === void 0 || isCoraliteElement(obj.customElement));
|
|
11211
|
-
}
|
|
11212
|
-
function isCoraliteCollectionItem(obj) {
|
|
11213
|
-
return isObject(obj) && "path" in obj && isObject(obj.path) && typeof obj.content === "string";
|
|
11214
|
-
}
|
|
11215
|
-
function isCoraliteNode(obj) {
|
|
11216
|
-
return isCoraliteElement(obj) || isCoraliteTextNode(obj) || isCoraliteComment(obj) || isCoraliteDirective(obj) || isCoraliteComponentRoot(obj);
|
|
11217
|
-
}
|
|
11218
|
-
function hasValidElementStructure(obj) {
|
|
11219
|
-
return isCoraliteElement(obj) && typeof obj.name === "string" && isObject(obj.attribs) && Array.isArray(obj.children);
|
|
11220
|
-
}
|
|
11221
|
-
function hasValidTextNodeStructure(obj) {
|
|
11222
|
-
return isCoraliteTextNode(obj) && typeof obj.data === "string";
|
|
11223
|
-
}
|
|
11224
|
-
function hasValidCommentStructure(obj) {
|
|
11225
|
-
return isCoraliteComment(obj) && typeof obj.data === "string";
|
|
11226
|
-
}
|
|
11227
|
-
function isValidChildNode(obj) {
|
|
11228
|
-
return isCoraliteElement(obj) || isCoraliteTextNode(obj) || isCoraliteComment(obj) || isCoraliteDirective(obj);
|
|
11229
|
-
}
|
|
11230
|
-
function isParentNode(obj) {
|
|
11231
|
-
return isObject(obj) && Array.isArray(obj.children);
|
|
11232
|
-
}
|
|
11233
|
-
function isRemovableNode(obj) {
|
|
11234
|
-
return isObject(obj) && obj.remove === true;
|
|
11235
|
-
}
|
|
11236
|
-
|
|
11237
|
-
// lib/coralite.js
|
|
11238
11254
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
11239
11255
|
import { availableParallelism as availableParallelism2 } from "node:os";
|
|
11240
|
-
import
|
|
11256
|
+
import render2 from "dom-serializer";
|
|
11241
11257
|
import pLimit2 from "p-limit";
|
|
11242
11258
|
import { randomUUID } from "node:crypto";
|
|
11243
11259
|
import { createContext } from "node:vm";
|
|
@@ -11898,7 +11914,7 @@ Coralite.prototype.save = async function(path2, options = {}) {
|
|
|
11898
11914
|
return results;
|
|
11899
11915
|
};
|
|
11900
11916
|
Coralite.prototype.transform = function(root, options) {
|
|
11901
|
-
return
|
|
11917
|
+
return render2(root, {
|
|
11902
11918
|
decodeEntities: false,
|
|
11903
11919
|
...options
|
|
11904
11920
|
});
|
|
@@ -12697,7 +12713,11 @@ var index_default = coralite_default;
|
|
|
12697
12713
|
export {
|
|
12698
12714
|
coralite_default as Coralite,
|
|
12699
12715
|
ScriptManager,
|
|
12716
|
+
addComponentAndDependencies,
|
|
12717
|
+
astTransformer,
|
|
12718
|
+
cleanAST,
|
|
12700
12719
|
cleanKeys,
|
|
12720
|
+
cleanValues,
|
|
12701
12721
|
cloneComponentInstance,
|
|
12702
12722
|
cloneModuleInstance,
|
|
12703
12723
|
cloneNode,
|