coralite 0.29.3 → 0.29.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"coralite.d.ts","sourceRoot":"","sources":["../../lib/coralite.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,kIAXW,cAAc,QA0LxB;;IAlND;;;;;;;;;;;;;;;;OAgBG;IAEH;;OAEG;IAEH;;;;;;;;;;;;OAYG;IACH,qHAXW,cAAc,EA0LxB;IAjJC;;;;;;;;;;;;;;MAWC;IAED,oDAAoD;IACpD,eADW,GAAG,CAAC,MAAM,EAAE,sBAAsB,EAAE,CAAC,CAClB;IAG9B;;;;;;;;;;;;;;MAcC;IAGD,8BAAqD;IAGrD;;;;;;;;8BA+nCS,qBAAqB,GAAG,eAAe,GAAG,eAAe,EAAE,YAC3D,oBAAoB,KAClB,MAAM;;;;;;;;;;;;MAhnChB;IA6FH;;;OAGG;IACH,cAFa,OAAO,CAAC,IAAI,CAAC,CA0PzB;IAvPC,+BAyCE;IAaF;;OAEG;IACH;;MAA6C;IAC7C;;OAEG;IACH;;MAA+C;IA4K/C,0BAKE;IAWJ;;;;;OAKG;IACH,+BAHW,MAAM,OAsBhB;IACD;;;;;;;;;;OAUG;IACH,sBAJW,MAAM,GAAG,MAAM,EAAE,iBAEhB,cAAc,CAAC,cAAc,CAAC,CA8ezC;IA9SW,gBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA0T9B,aACQ,MAAM,GAAG,MAAM,EAAE,GACf,OAAO,CAAC,cAAc,EAAE,CAAC,CAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA,gBACQ,gBAAgB,GACd,OAAO,CAAC,cAAc,EAAE,CAAC,CAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,CAAC,CAAC,CAc5B;IAED;;;;;;;OAOG;IACH,qBAHW,WAAW,GAAC,cAAc,GAAC,cAAc,GAAC,gBAAgB,GAAC,mBAAmB,GAAC,mBAAmB,GAAC,oBAAoB,GAAC,mBAAmB,GAAC,eAAe,GAAC,cAAc,4BAapL;;;wCA3qCU,cAAc,KACZ,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG;oCApiCN,mBAAmB;4CAAnB,mBAAmB;8BA/Bd,qBAAqB;0BAFmB,YAAY;4BAAZ,YAAY;6BADxC,WAAW;4BAAX,WAAW;8BACiB,YAAY;+BAAZ,YAAY;2CAiCzD,mBAAmB;qCAAnB,mBAAmB;0CAIL,gBAAgB;+BAvBxB,iBAAiB;oCAmBvB,mBAAmB;uCAAnB,mBAAmB;0CAAnB,mBAAmB;qCAAnB,mBAAmB;oCAAnB,mBAAmB"}
package/dist/lib/index.js CHANGED
@@ -9374,8 +9374,8 @@ async function transformCss(css, rootClasses, descendantClasses) {
9374
9374
  // lib/script-manager.js
9375
9375
  import { build } from "esbuild";
9376
9376
  import serialize from "serialize-javascript";
9377
- import { pathToFileURL } from "node:url";
9378
- import { resolve, parse as parse4, join as join2 } from "node:path";
9377
+ import { pathToFileURL, fileURLToPath } from "node:url";
9378
+ import { resolve, parse as parse4 } from "node:path";
9379
9379
  import { createHash } from "node:crypto";
9380
9380
  import { nodeModulesPolyfillPlugin } from "esbuild-plugins-node-modules-polyfill";
9381
9381
  function ScriptManager(options = {}) {
@@ -9418,11 +9418,12 @@ ScriptManager.prototype.getHelpers = function() {
9418
9418
  }
9419
9419
  return `{${helpers}}`;
9420
9420
  };
9421
- ScriptManager.prototype.registerComponent = function({ id, script = {}, filePath, template = null, defaultValues = {}, styles = "" }) {
9421
+ ScriptManager.prototype.registerComponent = function({ id, script = {}, filePath, templateAST = null, templateValues = null, defaultValues = {}, styles = "" }) {
9422
9422
  this.sharedFunctions[id] = {
9423
9423
  id,
9424
9424
  script,
9425
- template,
9425
+ templateAST,
9426
+ templateValues,
9426
9427
  defaultValues,
9427
9428
  styles,
9428
9429
  imports: script.imports || [],
@@ -9496,13 +9497,13 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9496
9497
  processedComponent[instanceData[1].componentId] = true;
9497
9498
  }
9498
9499
  for (const [componentId, fnData] of Object.entries(this.sharedFunctions)) {
9499
- if (fnData.template != null || fnData.defaultValues && Object.keys(fnData.defaultValues).length > 0 || fnData.script && fnData.script.components && fnData.script.components.length > 0 || fnData.script && fnData.script.content && fnData.script.content !== "export default function(){}" || fnData.script && fnData.script.content && fnData.script.content !== "export default function() {}" || fnData.styles && fnData.styles !== "") {
9500
+ if (fnData.templateAST != null || fnData.defaultValues && Object.keys(fnData.defaultValues).length > 0 || fnData.script && fnData.script.components && fnData.script.components.length > 0 || fnData.script && fnData.script.content && fnData.script.content !== "export default function(){}" || fnData.script && fnData.script.content && fnData.script.content !== "export default function() {}" || fnData.styles && fnData.styles !== "") {
9500
9501
  processedComponent[componentId] = true;
9501
9502
  } else if (fnData.script && fnData.script.content && fnData.script.content.trim() !== "export default function(){}" && fnData.script.content.trim() !== "export default function() {}" && fnData.script.content.trim() !== "export default function() { }") {
9502
9503
  processedComponent[componentId] = true;
9503
9504
  } else if (fnData.script && fnData.script.content) {
9504
9505
  processedComponent[componentId] = true;
9505
- } else if (fnData.template || fnData.styles) {
9506
+ } else if (fnData.templateAST || fnData.styles) {
9506
9507
  processedComponent[componentId] = true;
9507
9508
  }
9508
9509
  }
@@ -9533,14 +9534,6 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9533
9534
  for (const componentId of processedComponentKeys) {
9534
9535
  if (this.sharedFunctions[componentId] && this.sharedFunctions[componentId].imports && this.sharedFunctions[componentId].imports.length > 0) {
9535
9536
  entryCodeParts.push(` "${componentId}": componentImports_${componentId.replace(regex, "_")},
9536
- `);
9537
- }
9538
- }
9539
- entryCodeParts.push("};\n");
9540
- entryCodeParts.push("const coraliteComponentTemplates = {\n");
9541
- for (const key of processedComponentKeys) {
9542
- if (this.sharedFunctions[key] && this.sharedFunctions[key].template) {
9543
- entryCodeParts.push(` "${key}": ${serialize(this.sharedFunctions[key].template)},
9544
9537
  `);
9545
9538
  }
9546
9539
  }
@@ -9570,7 +9563,10 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9570
9563
  }
9571
9564
  }
9572
9565
  entryCodeParts.push("};\n");
9573
- entryCodeParts.push("\nexport { getHelpers, getSetups };\n");
9566
+ const domSerializerPath = fileURLToPath(import.meta.resolve("dom-serializer"));
9567
+ entryCodeParts.push(`import render from "${domSerializerPath}";
9568
+ `);
9569
+ entryCodeParts.push("\nexport { getHelpers, getSetups, render };\n");
9574
9570
  const entryPoints = {
9575
9571
  "chunk-shared": entryCodeParts.join("").trimEnd()
9576
9572
  };
@@ -9591,13 +9587,66 @@ ScriptManager.prototype.compileAllInstances = async function(instances, mode) {
9591
9587
  componentEntryCode += `const componentScript = null;
9592
9588
  `;
9593
9589
  }
9594
- const template = serialize(this.sharedFunctions[componentId].template || "");
9590
+ const nodeMap = /* @__PURE__ */ new WeakMap();
9591
+ let nodeCounter = 0;
9592
+ const cleanAST = (nodes) => {
9593
+ if (!nodes) return null;
9594
+ return nodes.map((node) => {
9595
+ const cloned = { ...node };
9596
+ const id = nodeCounter++;
9597
+ nodeMap.set(node, id);
9598
+ cloned._id = id;
9599
+ delete cloned.parent;
9600
+ delete cloned.prev;
9601
+ delete cloned.next;
9602
+ if (cloned.children) {
9603
+ cloned.children = cleanAST(cloned.children);
9604
+ }
9605
+ return cloned;
9606
+ });
9607
+ };
9608
+ const cleanValues = (values) => {
9609
+ if (!values) return null;
9610
+ const result2 = { ...values };
9611
+ if (result2.attributes) {
9612
+ result2.attributes = result2.attributes.map((item) => {
9613
+ const cloned = { ...item };
9614
+ cloned.elementId = nodeMap.get(item.element);
9615
+ delete cloned.element;
9616
+ return cloned;
9617
+ });
9618
+ }
9619
+ if (result2.textNodes) {
9620
+ result2.textNodes = result2.textNodes.map((item) => {
9621
+ const cloned = { ...item };
9622
+ cloned.textNodeId = nodeMap.get(item.textNode);
9623
+ delete cloned.textNode;
9624
+ return cloned;
9625
+ });
9626
+ }
9627
+ if (result2.refs) {
9628
+ result2.refs = result2.refs.map((item) => {
9629
+ const cloned = { ...item };
9630
+ cloned.elementId = nodeMap.get(item.element);
9631
+ delete cloned.element;
9632
+ return cloned;
9633
+ });
9634
+ }
9635
+ return result2;
9636
+ };
9637
+ const templateAST = serialize(cleanAST(this.sharedFunctions[componentId].templateAST) || []);
9638
+ const templateValues = serialize(cleanValues(this.sharedFunctions[componentId].templateValues) || {
9639
+ attributes: [],
9640
+ textNodes: [],
9641
+ refs: []
9642
+ });
9595
9643
  const styles = JSON.stringify(this.sharedFunctions[componentId].styles || "");
9596
9644
  const defaults = serialize(this.sharedFunctions[componentId].defaultValues || {});
9597
9645
  componentEntryCode += `
9598
9646
  export default {
9599
9647
  componentId: "${componentId}",
9600
- template: ${template},
9648
+ templateAST: ${templateAST},
9649
+ templateValues: ${templateValues},
9601
9650
  styles: ${styles},
9602
9651
  defaultValues: (() => { const defaults = ${defaults}; return defaults; })(),
9603
9652
  imports: ${hasImports ? "componentImports" : "{}"},
@@ -10343,19 +10392,19 @@ function createPlugin({
10343
10392
 
10344
10393
  // plugins/static-assets.js
10345
10394
  import { createRequire } from "node:module";
10346
- import { dirname as dirname3, join as join3 } from "node:path";
10395
+ import { dirname as dirname3, join as join2 } from "node:path";
10347
10396
  import { existsSync as existsSync2 } from "node:fs";
10348
10397
  import { cp, mkdir } from "node:fs/promises";
10349
10398
  var staticAssetPlugin = (assets = []) => {
10350
10399
  return createPlugin({
10351
10400
  name: "static-asset-plugin",
10352
10401
  onBeforeBuild: async function() {
10353
- const outputDir = this.options.output || join3(process.cwd(), "dist");
10402
+ const outputDir = this.options.output || join2(process.cwd(), "dist");
10354
10403
  for (const asset of assets) {
10355
10404
  if (!asset.dest) {
10356
10405
  throw new Error("staticAssetPlugin requires assets to have a dest property.");
10357
10406
  }
10358
- const dest = join3(outputDir, asset.dest);
10407
+ const dest = join2(outputDir, asset.dest);
10359
10408
  if (asset.src) {
10360
10409
  await mkdir(dirname3(dest), { recursive: true });
10361
10410
  await cp(asset.src, dest, { recursive: true });
@@ -10364,20 +10413,20 @@ var staticAssetPlugin = (assets = []) => {
10364
10413
  if (!asset.pkg || !asset.path) {
10365
10414
  throw new Error("staticAssetPlugin requires assets to have pkg and path properties when src is not provided.");
10366
10415
  }
10367
- const require2 = createRequire(join3(process.cwd(), "package.json"));
10416
+ const require2 = createRequire(join2(process.cwd(), "package.json"));
10368
10417
  let pkgPath;
10369
10418
  try {
10370
10419
  pkgPath = dirname3(require2.resolve(`${asset.pkg}/package.json`));
10371
10420
  } catch (e) {
10372
10421
  pkgPath = dirname3(require2.resolve(asset.pkg));
10373
- while (pkgPath !== "/" && !existsSync2(join3(pkgPath, "package.json"))) {
10422
+ while (pkgPath !== "/" && !existsSync2(join2(pkgPath, "package.json"))) {
10374
10423
  pkgPath = dirname3(pkgPath);
10375
10424
  }
10376
10425
  if (pkgPath === "/") {
10377
10426
  throw new Error(`staticAssetPlugin could not resolve package.json for package: ${asset.pkg}`);
10378
10427
  }
10379
10428
  }
10380
- const src = join3(pkgPath, asset.path);
10429
+ const src = join2(pkgPath, asset.path);
10381
10430
  await mkdir(dirname3(dest), { recursive: true });
10382
10431
  await cp(src, dest, { recursive: true });
10383
10432
  }
@@ -10387,7 +10436,7 @@ var staticAssetPlugin = (assets = []) => {
10387
10436
 
10388
10437
  // lib/coralite.js
10389
10438
  import { mkdir as mkdir2, writeFile } from "node:fs/promises";
10390
- import { dirname as dirname4, join as join4, normalize, relative, resolve as resolve2 } from "node:path";
10439
+ import { dirname as dirname4, join as join3, normalize, relative, resolve as resolve2 } from "node:path";
10391
10440
  import { createRequire as createRequire2 } from "node:module";
10392
10441
  import { transform } from "esbuild";
10393
10442
 
@@ -10662,7 +10711,7 @@ Coralite.prototype.initialise = async function() {
10662
10711
  if (data2.type === "component") {
10663
10712
  rootPath = this.options.path.components;
10664
10713
  }
10665
- const urlPathname = pathToFileURL2(join4("/", relative(rootPath, data2.path.pathname))).pathname;
10714
+ const urlPathname = pathToFileURL2(join3("/", relative(rootPath, data2.path.pathname))).pathname;
10666
10715
  const values = {
10667
10716
  $urlPathname: urlPathname,
10668
10717
  $urlDirname: pathToFileURL2(dirname4(urlPathname)).pathname,
@@ -10966,7 +11015,7 @@ ${css}
10966
11015
  delete chunkManifest["chunk-shared"];
10967
11016
  const base2 = this.options.baseURL.endsWith("/") ? this.options.baseURL : this.options.baseURL + "/";
10968
11017
  let scriptContent = `
10969
- import { getHelpers, getSetups } from '${base2}assets/js/${scriptResult.manifest["chunk-shared"]}';
11018
+ import { getHelpers, getSetups, render } from '${base2}assets/js/${scriptResult.manifest["chunk-shared"]}';
10970
11019
 
10971
11020
  // Global setups initialization
10972
11021
  const globalContext = {};
@@ -10988,8 +11037,9 @@ const globalSetupValuesPromise = getSetups(globalContext);
10988
11037
  super();
10989
11038
  this.componentId = module.default.componentId;
10990
11039
  this.attachShadow({ mode: 'open' });
11040
+ this._abortController = null;
10991
11041
 
10992
- const randomID = Math.random().toString(36).substring(2, 10);
11042
+ const randomID = crypto.randomUUID();
10993
11043
  this._instanceId = \`\${this.componentId}-\${randomID}\`;
10994
11044
 
10995
11045
  this.values = {};
@@ -11006,48 +11056,27 @@ const globalSetupValuesPromise = getSetups(globalContext);
11006
11056
 
11007
11057
  // Merge defaults
11008
11058
  Object.assign(this.values, module.default.defaultValues);
11009
-
11010
- this._render();
11011
- }
11012
11059
 
11013
- _replaceTokens(template) {
11014
- return template.replace(/\\{\\{\\s*([^{}\\s]+)\\s*\\}\\}/g, (match, tokenName) => {
11015
- const value = this.values[tokenName];
11016
- if (typeof value === 'function') {
11017
- return value(this.values);
11018
- }
11019
- return value != null ? value : '';
11020
- });
11021
- }
11022
-
11023
- _render() {
11024
- let content = '';
11060
+ this._styles = ''
11025
11061
  if (module.default.styles) {
11026
- content += \`<style>\${module.default.styles}</style>\`;
11062
+ this._styles += \`<style>\${module.default.styles}</style>\`;
11027
11063
  }
11028
- content += this._replaceTokens(module.default.template);
11029
-
11030
- this.shadowRoot.innerHTML = content;
11064
+ }
11031
11065
 
11066
+ connectedCallback() {
11067
+ this._abortController = new AbortController();
11068
+
11069
+ this._render();
11070
+
11032
11071
  const localContext = {
11033
11072
  instanceId: this._instanceId,
11034
11073
  componentId: this.componentId,
11035
11074
  values: this.values,
11036
11075
  root: this.shadowRoot,
11037
- helpers: {}
11076
+ helpers: {},
11077
+ signal: this._abortController.signal
11038
11078
  };
11039
11079
 
11040
- const refElements = this.shadowRoot.querySelectorAll('[ref]');
11041
- for (let i = 0; i < refElements.length; i++) {
11042
- const element = refElements[i];
11043
- const refName = element.getAttribute('ref');
11044
-
11045
- const dynamicId = \`\${this.componentId}__\${refName}-\${localContext.instanceId}\`;
11046
- element.setAttribute('ref', dynamicId);
11047
-
11048
- this.values[\`ref_\${refName}\`] = dynamicId;
11049
- }
11050
-
11051
11080
  ;(async () => {
11052
11081
  const setupValues = await globalSetupValuesPromise;
11053
11082
  localContext.values = { ...localContext.values, ...setupValues };
@@ -11087,7 +11116,101 @@ const globalSetupValuesPromise = getSetups(globalContext);
11087
11116
  this._observer.observe(this, { attributes: true });
11088
11117
  }
11089
11118
 
11119
+ _replaceTokens(templateAST, templateValues) {
11120
+ // Map to store cloned nodes by their _id
11121
+ const nodeById = {};
11122
+
11123
+ // Function to deep clone AST and build ID map
11124
+ const cloneAST = (nodes) => {
11125
+ return nodes.map((node) => {
11126
+ const cloned = { ...node };
11127
+ if (cloned._id != null) {
11128
+ nodeById[cloned._id] = cloned;
11129
+ }
11130
+ if (cloned.children) {
11131
+ cloned.children = cloneAST(cloned.children);
11132
+ }
11133
+ if (cloned.attribs) {
11134
+ cloned.attribs = { ...cloned.attribs };
11135
+ }
11136
+ return cloned;
11137
+ });
11138
+ };
11139
+
11140
+ const ast = cloneAST(templateAST);
11141
+
11142
+ if (!templateValues) return ast;
11143
+
11144
+ // Replace tokens in attributes using the exact token matches
11145
+ if (templateValues.attributes) {
11146
+ for (let i = 0; i < templateValues.attributes.length; i++) {
11147
+ const item = templateValues.attributes[i];
11148
+ const node = nodeById[item.elementId];
11149
+ if (!node || !node.attribs || node.attribs[item.name] == null) continue;
11150
+
11151
+ for (let j = 0; j < item.tokens.length; j++) {
11152
+ const token = item.tokens[j];
11153
+ let value = this.values[token.name];
11154
+
11155
+ if (typeof value === 'function') {
11156
+ value = value(this.values);
11157
+ }
11158
+ if (value == null) value = '';
11159
+
11160
+ // Replace exactly the token content string rather than a regex over the whole attribute
11161
+ node.attribs[item.name] = node.attribs[item.name].split(token.content).join(value);
11162
+ }
11163
+ }
11164
+ }
11165
+
11166
+ // Replace tokens in text nodes using the exact token matches
11167
+ if (templateValues.textNodes) {
11168
+ for (let i = 0; i < templateValues.textNodes.length; i++) {
11169
+ const item = templateValues.textNodes[i];
11170
+ const node = nodeById[item.textNodeId];
11171
+ if (!node || node.data == null) continue;
11172
+
11173
+ for (let j = 0; j < item.tokens.length; j++) {
11174
+ const token = item.tokens[j];
11175
+ let value = this.values[token.name];
11176
+
11177
+ if (typeof value === 'function') {
11178
+ value = value(this.values);
11179
+ }
11180
+ if (value == null) value = '';
11181
+
11182
+ node.data = node.data.split(token.content).join(value);
11183
+ }
11184
+ }
11185
+ }
11186
+
11187
+ return ast;
11188
+ }
11189
+
11190
+ _render() {
11191
+ let content = this._styles;
11192
+ const ast = this._replaceTokens(module.default.templateAST, module.default.templateValues);
11193
+ content += render(ast, { decodeEntities: false });
11194
+
11195
+ this.shadowRoot.innerHTML = content;
11196
+
11197
+ const refElements = this.shadowRoot.querySelectorAll('[ref]');
11198
+ for (let i = 0; i < refElements.length; i++) {
11199
+ const element = refElements[i];
11200
+ const refName = element.getAttribute('ref');
11201
+
11202
+ const dynamicId = \`\${this.componentId}__\${refName}-\${this._instanceId}\`;
11203
+ element.setAttribute('ref', dynamicId);
11204
+
11205
+ this.values[\`ref_\${refName}\`] = dynamicId;
11206
+ }
11207
+ }
11208
+
11090
11209
  disconnectedCallback() {
11210
+ if (this._abortController) {
11211
+ this._abortController.abort();
11212
+ this._abortController = null;
11213
+ }
11091
11214
  if (this._observer) {
11092
11215
  this._observer.disconnect();
11093
11216
  this._observer = null;
@@ -11100,11 +11223,12 @@ const globalSetupValuesPromise = getSetups(globalContext);
11100
11223
  };
11101
11224
 
11102
11225
  // Check the current page's DOM for custom elements
11103
- const elements = document.querySelectorAll('*');
11226
+ const componentTags = Object.keys(componentManifest);
11104
11227
  const loadPromises = [];
11105
- for (let i = 0; i < elements.length; i++) {
11106
- const tagName = elements[i].tagName.toLowerCase();
11107
- if (componentManifest[tagName]) {
11228
+ for (let i = 0; i < componentTags.length; i++) {
11229
+ const tagName = componentTags[i];
11230
+ const elements = document.querySelectorAll(tagName);
11231
+ if (elements.length > 0) {
11108
11232
  loadPromises.push(loadComponent(tagName));
11109
11233
  }
11110
11234
  }
@@ -11307,8 +11431,8 @@ Coralite.prototype.save = async function(path2, options = {}) {
11307
11431
  const results = await this.build(path2, options, async (result) => {
11308
11432
  let relativeDir, outDir, outFile, contentToWrite;
11309
11433
  relativeDir = relative(this.options.path.pages, result.path.dirname);
11310
- outDir = join4(output, relativeDir);
11311
- outFile = join4(outDir, result.path.filename);
11434
+ outDir = join3(output, relativeDir);
11435
+ outFile = join3(outDir, result.path.filename);
11312
11436
  contentToWrite = result.content;
11313
11437
  if (!createdDir[outDir]) {
11314
11438
  await mkdir2(outDir, { recursive: true });
@@ -11321,13 +11445,13 @@ Coralite.prototype.save = async function(path2, options = {}) {
11321
11445
  };
11322
11446
  });
11323
11447
  if (this.outputFiles) {
11324
- const assetsDir = join4(output, "assets", "js");
11448
+ const assetsDir = join3(output, "assets", "js");
11325
11449
  if (!createdDir[assetsDir]) {
11326
11450
  await mkdir2(assetsDir, { recursive: true });
11327
11451
  createdDir[assetsDir] = true;
11328
11452
  }
11329
11453
  const assetWrites = Object.values(this.outputFiles).map(async (file) => {
11330
- const outFile = join4(assetsDir, file.hashedPath);
11454
+ const outFile = join3(assetsDir, file.hashedPath);
11331
11455
  await writeFile(outFile, file.text, { signal });
11332
11456
  results.push({
11333
11457
  path: outFile,
@@ -11398,7 +11522,8 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
11398
11522
  renderContext
11399
11523
  });
11400
11524
  }
11401
- const templateHTML = this.transform(module.template.children);
11525
+ const templateAST = module.template.children;
11526
+ const templateValues = module.values;
11402
11527
  const stylesHTML = module.styles && module.styles.length ? module.styles.join("\n") : "";
11403
11528
  let scriptObj = {
11404
11529
  content: "export default function(){}",
@@ -11422,7 +11547,8 @@ Coralite.prototype._processDependentComponents = async function(componentIds, re
11422
11547
  id: module.id,
11423
11548
  script: scriptObj,
11424
11549
  filePath: moduleComponent.path.pathname,
11425
- template: templateHTML,
11550
+ templateAST,
11551
+ templateValues,
11426
11552
  defaultValues,
11427
11553
  styles: stylesHTML
11428
11554
  });
@@ -11499,7 +11625,8 @@ Coralite.prototype.createComponentElement = async function({
11499
11625
  scriptResult.__script__.content = "export default function(){}";
11500
11626
  }
11501
11627
  const stylesHTML = module.styles && module.styles.length ? module.styles.join("\n") : "";
11502
- const templateHTML = this.transform(module.template.children);
11628
+ const templateAST = module.template.children;
11629
+ const templateValues = module.values;
11503
11630
  const componentTokens = {};
11504
11631
  for (let i = 0; i < module.values.attributes.length; i++) {
11505
11632
  const item = module.values.attributes[i];
@@ -11525,7 +11652,8 @@ Coralite.prototype.createComponentElement = async function({
11525
11652
  id: module.id,
11526
11653
  script: scriptResult.__script__,
11527
11654
  filePath: moduleComponent.path.pathname,
11528
- template: templateHTML,
11655
+ templateAST,
11656
+ templateValues,
11529
11657
  defaultValues: componentDefaultValues,
11530
11658
  styles: stylesHTML
11531
11659
  });