marko 6.1.2 → 6.1.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.
Files changed (38) hide show
  1. package/dist/common/accessor.d.ts +5 -0
  2. package/dist/common/accessor.debug.d.ts +5 -0
  3. package/dist/common/compat-meta.d.ts +0 -1
  4. package/dist/common/opt.d.ts +3 -1
  5. package/dist/common/types.d.ts +1 -1
  6. package/dist/debug/dom.js +315 -122
  7. package/dist/debug/dom.mjs +306 -123
  8. package/dist/debug/html.js +922 -712
  9. package/dist/debug/html.mjs +920 -713
  10. package/dist/dom/compat.d.ts +3 -2
  11. package/dist/dom/control-flow.d.ts +2 -1
  12. package/dist/dom/load.d.ts +23 -0
  13. package/dist/dom/queue.d.ts +4 -2
  14. package/dist/dom/resume.d.ts +10 -8
  15. package/dist/dom/signals.d.ts +4 -3
  16. package/dist/dom.d.ts +3 -2
  17. package/dist/dom.js +195 -66
  18. package/dist/dom.mjs +195 -66
  19. package/dist/html/assets.d.ts +47 -0
  20. package/dist/html/compat.d.ts +3 -2
  21. package/dist/html/inlined-runtimes.d.ts +1 -1
  22. package/dist/html/inlined-runtimes.debug.d.ts +1 -1
  23. package/dist/html/serializer.d.ts +14 -9
  24. package/dist/html/writer.d.ts +34 -15
  25. package/dist/html.d.ts +1 -0
  26. package/dist/html.js +502 -345
  27. package/dist/html.mjs +502 -345
  28. package/dist/translator/index.d.ts +1 -0
  29. package/dist/translator/index.js +342 -76
  30. package/dist/translator/interop/index.d.ts +1 -0
  31. package/dist/translator/util/marko-config.d.ts +2 -0
  32. package/dist/translator/util/references.d.ts +1 -5
  33. package/dist/translator/util/runtime.d.ts +1 -0
  34. package/dist/translator/util/tag-name-type.d.ts +2 -0
  35. package/dist/translator/util/walks.d.ts +1 -1
  36. package/dist/translator/visitors/import-declaration.d.ts +10 -1
  37. package/dist/translator/visitors/tag/custom-tag.d.ts +7 -0
  38. package/package.json +2 -2
@@ -118,6 +118,7 @@ let AccessorProp$1 = /* @__PURE__ */ function(AccessorProp) {
118
118
  AccessorProp["DetachedAwait"] = "#DetachedAwait";
119
119
  AccessorProp["EndNode"] = "#EndNode";
120
120
  AccessorProp["Id"] = "#Id";
121
+ AccessorProp["Load"] = "#Load";
121
122
  AccessorProp["LoopKey"] = "#LoopKey";
122
123
  AccessorProp["ParentBranch"] = "#ParentBranch";
123
124
  AccessorProp["PendingEffects"] = "#PendingEffects";
@@ -248,8 +249,9 @@ function normalizeDynamicRenderer(value) {
248
249
  const decodeAccessor = (num) => (num + (num < 26 ? 10 : num < 962 ? 334 : 11998)).toString(36);
249
250
  //#endregion
250
251
  //#region src/html/serializer.ts
252
+ const K_SCOPE_ID = Symbol("Scope ID");
251
253
  const kTouchedIterator = Symbol.for("marko.touchedIterator");
252
- const { hasOwnProperty } = {};
254
+ const { hasOwnProperty: hasOwnProperty$1 } = {};
253
255
  const Generator = (function* () {})().constructor;
254
256
  const AsyncGenerator = (async function* () {})().constructor;
255
257
  patchIteratorNext(Generator.prototype);
@@ -1078,6 +1080,7 @@ let AccessorProp = /* @__PURE__ */ function(AccessorProp) {
1078
1080
  AccessorProp["DetachedAwait"] = "V";
1079
1081
  AccessorProp["EndNode"] = "K";
1080
1082
  AccessorProp["Id"] = "L";
1083
+ AccessorProp["Load"] = "X";
1081
1084
  AccessorProp["LoopKey"] = "M";
1082
1085
  AccessorProp["ParentBranch"] = "N";
1083
1086
  AccessorProp["PendingEffects"] = "J";
@@ -1104,6 +1107,11 @@ function getMarkoOpts() {
1104
1107
  function isOptimize() {
1105
1108
  return getMarkoOpts().optimize;
1106
1109
  }
1110
+ function getReadyId(file = (0, _marko_compiler_babel_utils.getFile)()) {
1111
+ const { markoOpts } = file;
1112
+ if (!markoOpts.linkAssets) return void 0;
1113
+ return (markoOpts.optimize ? "_" : "ready:") + (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, file.opts.filename);
1114
+ }
1107
1115
  //#endregion
1108
1116
  //#region src/translator/util/get-accessor-char.ts
1109
1117
  function getAccessorPrefix() {
@@ -1340,6 +1348,7 @@ function analyzeExpressionTagName(name, extra) {
1340
1348
  let type;
1341
1349
  let nullable = false;
1342
1350
  let tagNameImported;
1351
+ let tagNameLoad;
1343
1352
  while ((path = pending.pop()) && type !== 2) if (path.isConditionalExpression()) {
1344
1353
  pending.push(path.get("consequent"));
1345
1354
  if (path.node.alternate) pending.push(path.get("alternate"));
@@ -1364,10 +1373,11 @@ function analyzeExpressionTagName(name, extra) {
1364
1373
  if (binding.kind === "module") {
1365
1374
  const decl = binding.path.parent;
1366
1375
  if (MARKO_FILE_REG.test(decl.source.value) && decl.specifiers.some((it) => _marko_compiler.types.isImportDefaultSpecifier(it))) {
1367
- const resolvedImport = (0, _marko_compiler_babel_utils.resolveTagImport)(name, decl.source.value) || decl.source.value;
1376
+ const resolvedImport = decl.extra?.tagImport || decl.source.value;
1368
1377
  if (type === void 0) {
1369
1378
  type = 1;
1370
1379
  tagNameImported = resolvedImport;
1380
+ tagNameLoad = decl.extra?.loadImport;
1371
1381
  } else if (type === 0) {
1372
1382
  type = 2;
1373
1383
  tagNameImported = void 0;
@@ -1392,7 +1402,10 @@ function analyzeExpressionTagName(name, extra) {
1392
1402
  } else type = 2;
1393
1403
  extra.tagNameType = type ?? 2;
1394
1404
  extra.tagNameNullable = nullable;
1395
- if (type === 1 && tagNameImported) extra.tagNameImported = tagNameImported;
1405
+ if (type === 1 && tagNameImported) {
1406
+ extra.tagNameImported = tagNameImported;
1407
+ extra.tagNameLoad = tagNameLoad;
1408
+ }
1396
1409
  }
1397
1410
  //#endregion
1398
1411
  //#region src/translator/util/sections.ts
@@ -1851,7 +1864,6 @@ function _escape_comment(val) {
1851
1864
  //#endregion
1852
1865
  //#region src/html/writer.ts
1853
1866
  let $chunk;
1854
- const K_SCOPE_ID = Symbol("Scope ID");
1855
1867
  function getContext(key) {
1856
1868
  return $chunk.context?.[key];
1857
1869
  }
@@ -1862,7 +1874,7 @@ function _html(html) {
1862
1874
  $chunk.writeHTML(html);
1863
1875
  }
1864
1876
  function _script(scopeId, registryId) {
1865
- if ($chunk.context?.[kIsAsync]) _resume_branch(scopeId);
1877
+ if ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) _resume_branch(scopeId);
1866
1878
  $chunk.boundary.state.needsMainRuntime = true;
1867
1879
  $chunk.writeEffect(scopeId, registryId);
1868
1880
  }
@@ -1901,20 +1913,21 @@ function withBranchId(branchId, cb) {
1901
1913
  return withContext(kBranchId, branchId, cb);
1902
1914
  }
1903
1915
  let writeScope = (scopeId, partialScope) => {
1904
- return writeScopeToState($chunk.boundary.state, scopeId, partialScope);
1916
+ const { state } = $chunk.boundary;
1917
+ const target = $chunk.serializeState;
1918
+ const scope = scopeWithId(state, scopeId);
1919
+ const pending = target.writeScopes[scopeId];
1920
+ state.needsMainRuntime = true;
1921
+ Object.assign(scope, partialScope);
1922
+ if (pending && pending !== partialScope) Object.assign(pending, partialScope);
1923
+ else target.writeScopes[scopeId] = partialScope;
1924
+ target.flushScopes = true;
1925
+ return scope;
1905
1926
  };
1906
- function writeScopeToState(state, scopeId, partialScope) {
1927
+ function scopeWithId(state, scopeId) {
1907
1928
  const { scopes } = state;
1908
1929
  let scope = scopes.get(scopeId);
1909
- state.needsMainRuntime = true;
1910
- if (scope) Object.assign(scope, partialScope);
1911
- else {
1912
- scope = partialScope;
1913
- scope[K_SCOPE_ID] = scopeId;
1914
- state.scopes.set(scopeId, scope);
1915
- }
1916
- if (state.writeScopes) state.writeScopes[scopeId] = scope;
1917
- else state.writeScopes = { [scopeId]: scope };
1930
+ if (!scope) scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId });
1918
1931
  return scope;
1919
1932
  }
1920
1933
  globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask;
@@ -2103,7 +2116,7 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
2103
2116
  const childScope = getScopeById(branchId);
2104
2117
  const needsScript = childScope && (childScope["EventAttributes:a"] || childScope["ControlledHandler:a"]);
2105
2118
  if (needsScript) {
2106
- childScope["#Renderer"] = renderer;
2119
+ writeScope(branchId, { ["#Renderer"]: renderer });
2107
2120
  _script(branchId, "d");
2108
2121
  }
2109
2122
  if (shouldResume || needsScript) _html(state.mark("'", scopeId + " " + accessor + " " + branchId));
@@ -2138,6 +2151,9 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
2138
2151
  };
2139
2152
  })(_dynamic_tag);
2140
2153
  //#endregion
2154
+ //#region src/html/assets.ts
2155
+ const { hasOwnProperty } = {};
2156
+ //#endregion
2141
2157
  //#region src/translator/util/runtime.ts
2142
2158
  const pureDOMFunctions = new Set([
2143
2159
  "_await_promise",
@@ -2159,7 +2175,16 @@ const pureDOMFunctions = new Set([
2159
2175
  "_for_to",
2160
2176
  "_for_until",
2161
2177
  "_let",
2162
- "_const"
2178
+ "_let_change",
2179
+ "_const",
2180
+ "_load_signal",
2181
+ "_load_setup",
2182
+ "_load_template",
2183
+ "_load_visible_trigger",
2184
+ "_load_event_trigger",
2185
+ "_load_idle_trigger",
2186
+ "_load_media_trigger",
2187
+ "_load_race_trigger"
2163
2188
  ]);
2164
2189
  function importRuntime(name) {
2165
2190
  const { output } = getMarkoOpts();
@@ -2167,10 +2192,7 @@ function importRuntime(name) {
2167
2192
  }
2168
2193
  function callRuntime(name, ...args) {
2169
2194
  const callExpression = _marko_compiler.types.callExpression(importRuntime(name), filterArguments(args));
2170
- if (isOutputDOM() && pureDOMFunctions.has(name)) callExpression.leadingComments = [{
2171
- type: "CommentBlock",
2172
- value: ` @__PURE__ `
2173
- }];
2195
+ if (isOutputDOM() && pureDOMFunctions.has(name)) return _marko_compiler.types.addComment(callExpression, "leading", "@__PURE__");
2174
2196
  return callExpression;
2175
2197
  }
2176
2198
  function getHTMLRuntime() {
@@ -2943,7 +2965,7 @@ function initValue(binding, isLet = false) {
2943
2965
  signal.build = () => {
2944
2966
  const fn = getSignalFn(signal);
2945
2967
  if (binding.upstreamAlias && binding.property === void 0 && binding.excludeProperties === void 0 || !signal.hasSideEffect || !signalHasStatements(signal)) return fn;
2946
- return callRuntime(isLet ? "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
2968
+ return callRuntime(isLet ? signal.extraArgs ? "_let_change" : "_let" : "_const", getScopeAccessorLiteral(binding, true, isLet), fn);
2947
2969
  };
2948
2970
  for (const alias of binding.aliases) if (alias.type !== 6) initValue(alias);
2949
2971
  for (const alias of binding.propertyAliases.values()) if (alias.type !== 6) initValue(alias);
@@ -2966,19 +2988,24 @@ function getSignalFn(signal) {
2966
2988
  for (const alias of binding.aliases) {
2967
2989
  const aliasSignal = getSignal(alias.section, alias);
2968
2990
  if (signalHasStatements(aliasSignal)) if (alias.excludeProperties !== void 0) {
2969
- const props = [];
2970
2991
  const aliasId = _marko_compiler.types.identifier(alias.name);
2971
- forEach(alias.excludeProperties, (name) => {
2972
- const propId = toPropertyName(name);
2973
- const shorthand = propId.type === "Identifier" && _marko_compiler.types.isValidIdentifier(name);
2974
- props.push(_marko_compiler.types.objectProperty(propId, shorthand ? propId : generateUidIdentifier(name), false, shorthand));
2975
- });
2976
- props.push(_marko_compiler.types.restElement(aliasId));
2977
- signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.objectPattern(props)], _marko_compiler.types.callExpression(aliasSignal.identifier, [
2992
+ let pattern;
2993
+ if (alias.restOffset) pattern = _marko_compiler.types.arrayPattern(new Array(alias.restOffset).fill(null).concat(_marko_compiler.types.restElement(aliasId)));
2994
+ else {
2995
+ const props = [];
2996
+ forEach(alias.excludeProperties, (name) => {
2997
+ const propId = toPropertyName(name);
2998
+ const shorthand = propId.type === "Identifier" && _marko_compiler.types.isValidIdentifier(name);
2999
+ props.push(_marko_compiler.types.objectProperty(propId, shorthand ? propId : generateUidIdentifier(name), false, shorthand));
3000
+ });
3001
+ props.push(_marko_compiler.types.restElement(aliasId));
3002
+ pattern = _marko_compiler.types.objectPattern(props);
3003
+ }
3004
+ signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.arrowFunctionExpression([pattern], _marko_compiler.types.callExpression(aliasSignal.identifier, [
2978
3005
  scopeIdentifier,
2979
3006
  aliasId,
2980
3007
  ...getTranslatedExtraArgs(aliasSignal)
2981
- ])), [binding.nullable ? _marko_compiler.types.logicalExpression("||", createScopeReadExpression(binding), _marko_compiler.types.objectExpression([])) : createScopeReadExpression(binding)])));
3008
+ ])), [binding.nullable ? _marko_compiler.types.logicalExpression("||", createScopeReadExpression(binding), alias.restOffset ? _marko_compiler.types.arrayExpression([]) : _marko_compiler.types.objectExpression([])) : createScopeReadExpression(binding)])));
2982
3009
  } else signal.render.push(_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(aliasSignal.identifier, [
2983
3010
  scopeIdentifier,
2984
3011
  createScopeReadExpression(binding),
@@ -3877,19 +3904,60 @@ var program_default = {
3877
3904
  translate: {
3878
3905
  enter(program) {
3879
3906
  scopeIdentifier = isOutputDOM() ? generateUidIdentifier("scope") : null;
3880
- if (getMarkoOpts().output === "hydrate") {
3881
- const entryFile = program.hub.file;
3882
- const visitedFiles = new Set([(0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, entryFile.opts.filename)]);
3883
- entry_builder_default.visit(entryFile, entryFile, function visitChild(resolved) {
3884
- if (!visitedFiles.has(resolved)) {
3885
- visitedFiles.add(resolved);
3886
- const file = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
3887
- if (file) entry_builder_default.visit(file, entryFile, (id) => visitChild(resolveRelativeToEntry(entryFile, file, id)));
3888
- }
3889
- });
3890
- program.node.body = entry_builder_default.build(entryFile);
3891
- program.skip();
3892
- return;
3907
+ {
3908
+ const markoOpts = getMarkoOpts();
3909
+ const { output, entry, runtimeId } = markoOpts;
3910
+ const isLoadEntry = entry === "load";
3911
+ const isDOMPageEntry = output === "dom" && entry === "page" || output === "hydrate";
3912
+ const isServerEntry = output === "html" && entry === "page";
3913
+ if (entry && !markoOpts.linkAssets) throw program.buildCodeFrameError("The \"entry\" option requires the `linkAssets` compiler option to be configured.");
3914
+ if (runtimeId && !/^[_$a-z][_$a-z0-9]*$/i.test(runtimeId)) throw program.buildCodeFrameError(`Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`);
3915
+ if (isLoadEntry) {
3916
+ const entryFile = program.hub.file;
3917
+ const { filename } = entryFile.opts;
3918
+ const readyArgs = [_marko_compiler.types.stringLiteral(getReadyId(entryFile))];
3919
+ if (runtimeId) readyArgs.push(_marko_compiler.types.stringLiteral(runtimeId));
3920
+ program.node.body = [_marko_compiler.types.importDeclaration([_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier("ready"), _marko_compiler.types.identifier("ready"))], _marko_compiler.types.stringLiteral(getRuntimePath("dom"))), _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.memberExpression(_marko_compiler.types.callExpression(_marko_compiler.types.import(), [_marko_compiler.types.stringLiteral((0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename))]), _marko_compiler.types.identifier("then")), [_marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.callExpression(_marko_compiler.types.identifier("ready"), readyArgs))]))];
3921
+ program.skip();
3922
+ return;
3923
+ }
3924
+ if (isDOMPageEntry) {
3925
+ const entryFile = program.hub.file;
3926
+ const { filename } = entryFile.opts;
3927
+ const visitedFiles = new Set([(0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename)]);
3928
+ entry_builder_default.visit(entryFile, entryFile, function visitChild(resolved) {
3929
+ if (!visitedFiles.has(resolved)) {
3930
+ visitedFiles.add(resolved);
3931
+ const file = (0, _marko_compiler_babel_utils.loadFileForImport)(entryFile, resolved);
3932
+ if (file) entry_builder_default.visit(file, entryFile, (id) => visitChild(resolveRelativeToEntry(entryFile, file, id)));
3933
+ }
3934
+ });
3935
+ program.node.body = entry_builder_default.build(entryFile);
3936
+ program.skip();
3937
+ return;
3938
+ }
3939
+ if (isServerEntry) {
3940
+ const entryFile = program.hub.file;
3941
+ const { filename } = entryFile.opts;
3942
+ const relativeImport = (0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, filename);
3943
+ const templateId = (0, _marko_compiler_babel_utils.getTemplateId)(markoOpts, filename);
3944
+ const pageAssetArgs = [
3945
+ _marko_compiler.types.identifier("template"),
3946
+ _marko_compiler.types.identifier("flush"),
3947
+ _marko_compiler.types.stringLiteral(templateId)
3948
+ ];
3949
+ if (runtimeId) pageAssetArgs.push(_marko_compiler.types.stringLiteral(runtimeId));
3950
+ markoOpts.linkAssets.onAsset("page", filename, templateId);
3951
+ program.node.body = [
3952
+ _marko_compiler.types.importDeclaration([_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier("flush"), _marko_compiler.types.identifier("flush"))], _marko_compiler.types.stringLiteral(markoOpts.linkAssets.runtime)),
3953
+ _marko_compiler.types.importDeclaration([_marko_compiler.types.importDefaultSpecifier(_marko_compiler.types.identifier("template"))], _marko_compiler.types.stringLiteral(relativeImport)),
3954
+ _marko_compiler.types.importDeclaration([_marko_compiler.types.importSpecifier(_marko_compiler.types.identifier("withPageAssets"), _marko_compiler.types.identifier("withPageAssets"))], _marko_compiler.types.stringLiteral(getRuntimePath("html"))),
3955
+ _marko_compiler.types.exportAllDeclaration(_marko_compiler.types.stringLiteral(relativeImport)),
3956
+ _marko_compiler.types.exportDefaultDeclaration(_marko_compiler.types.callExpression(_marko_compiler.types.identifier("withPageAssets"), pageAssetArgs))
3957
+ ];
3958
+ program.skip();
3959
+ return;
3960
+ }
3893
3961
  }
3894
3962
  if (isOutputHTML()) html_default.translate.enter();
3895
3963
  else dom_default.translate.enter(program);
@@ -4286,7 +4354,10 @@ var native_tag_default = {
4286
4354
  for (const child of tag.node.body.body) if (_marko_compiler.types.isMarkoText(child)) write`${child.value}`;
4287
4355
  else if (_marko_compiler.types.isMarkoPlaceholder(child)) write`${callRuntime(getTextOnlyEscapeHelper(tagName), child.value)}`;
4288
4356
  } else tag.insertBefore(tag.node.body.body).forEach((child) => child.skip());
4289
- if (!tagExtra[kSkipEndTag] && !isOpenOnly && !selectArgs) write`</${tagName}>`;
4357
+ if (!tagExtra[kSkipEndTag] && !isOpenOnly && !selectArgs) {
4358
+ if (tagName === "head" && getMarkoOpts().linkAssets) write`${callRuntime("_flush_head")}`;
4359
+ write`</${tagName}>`;
4360
+ }
4290
4361
  if (markerSerializeReason) markNode(tag, nodeBinding, markerSerializeReason);
4291
4362
  tag.remove();
4292
4363
  }
@@ -5655,6 +5726,7 @@ function createBinding(name, type, refSection, upstreamAlias, property, excludeP
5655
5726
  getters: /* @__PURE__ */ new Map(),
5656
5727
  propertyAliases: /* @__PURE__ */ new Map(),
5657
5728
  upstreamAlias,
5729
+ restOffset: void 0,
5658
5730
  scopeOffset: void 0,
5659
5731
  scopeAccessor: void 0,
5660
5732
  export: void 0,
@@ -5725,7 +5797,7 @@ function trackParamsReferences(body, type) {
5725
5797
  if (bodySection) bodySection.params = paramsBinding;
5726
5798
  for (let i = 0; i < params.length; i++) {
5727
5799
  const param = params[i];
5728
- if (param.type === "RestElement") createBindingsAndTrackReferences(param.argument, type, body.scope, section, paramsBinding, void 0, i > 0 ? addNumericPropertiesUntil(void 0, i - 1) : void 0);
5800
+ if (param.type === "RestElement") createBindingsAndTrackReferences(param.argument, type, body.scope, section, paramsBinding, void 0, i > 0 ? addNumericPropertiesUntil(void 0, i) : void 0, i);
5729
5801
  else if (_marko_compiler.types.isLVal(param)) createBindingsAndTrackReferences(param, type, body.scope, section, paramsBinding, i + "", void 0);
5730
5802
  }
5731
5803
  return paramsBinding;
@@ -5815,11 +5887,14 @@ function setReferencesScope(path) {
5815
5887
  const fnRoot = getFnRoot(path);
5816
5888
  if (fnRoot) (fnRoot.node.extra ??= {}).referencesScope = true;
5817
5889
  }
5818
- function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties) {
5890
+ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAlias, property, excludeProperties, restOffset) {
5819
5891
  switch (lVal.type) {
5820
- case "Identifier":
5821
- trackReferencesForBinding(scope.getBinding(lVal.name), (lVal.extra ??= {}).binding = createBinding(lVal.name, type, section, upstreamAlias, property, excludeProperties, lVal.loc, true));
5892
+ case "Identifier": {
5893
+ const binding = (lVal.extra ??= {}).binding = createBinding(lVal.name, type, section, upstreamAlias, property, excludeProperties, lVal.loc, true);
5894
+ if (restOffset) binding.restOffset = restOffset;
5895
+ trackReferencesForBinding(scope.getBinding(lVal.name), binding);
5822
5896
  break;
5897
+ }
5823
5898
  case "ObjectPattern": {
5824
5899
  const patternBinding = (property ? upstreamAlias.propertyAliases.get(property) : upstreamAlias) || ((lVal.extra ??= {}).binding = createBinding(generateUid(property || "pattern"), type, section, upstreamAlias, property, excludeProperties, lVal.loc));
5825
5900
  const hasRest = lVal.properties[lVal.properties.length - 1]?.type === "RestElement";
@@ -5844,8 +5919,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
5844
5919
  i++;
5845
5920
  if (element) {
5846
5921
  if (element.type === "RestElement") {
5847
- excludeProperties = i > 0 ? addNumericPropertiesUntil(excludeProperties, i - 1) : void 0;
5848
- createBindingsAndTrackReferences(element.argument, type, scope, section, patternBinding, property, excludeProperties);
5922
+ excludeProperties = i > 0 ? addNumericPropertiesUntil(excludeProperties, i) : void 0;
5923
+ createBindingsAndTrackReferences(element.argument, type, scope, section, patternBinding, property, excludeProperties, i);
5849
5924
  } else if (_marko_compiler.types.isLVal(element)) createBindingsAndTrackReferences(element, type, scope, section, patternBinding, `${i}`, void 0);
5850
5925
  }
5851
5926
  }
@@ -5859,9 +5934,16 @@ function trackReference(referencePath, binding) {
5859
5934
  while (true) {
5860
5935
  const { parent } = root;
5861
5936
  if (!_marko_compiler.types.isMemberExpression(parent) && !_marko_compiler.types.isOptionalMemberExpression(parent)) break;
5862
- const prop = getMemberExpressionPropString(parent);
5937
+ let prop = getMemberExpressionPropString(parent);
5863
5938
  if (prop === void 0) break;
5864
- if (reference.upstreamAlias && reference.excludeProperties !== void 0 && !propsUtil.has(reference.excludeProperties, prop)) reference = reference.upstreamAlias;
5939
+ if (reference.upstreamAlias && reference.excludeProperties !== void 0) {
5940
+ if (reference.restOffset) {
5941
+ if (/^\d+$/.test(prop)) {
5942
+ prop = `${+prop + reference.restOffset}`;
5943
+ reference = reference.upstreamAlias;
5944
+ }
5945
+ } else if (!propsUtil.has(reference.excludeProperties, prop)) reference = reference.upstreamAlias;
5946
+ }
5865
5947
  if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) break;
5866
5948
  root = root.parentPath;
5867
5949
  reference = getOrCreatePropertyAlias(reference, prop);
@@ -5925,8 +6007,7 @@ function finalizeReferences() {
5925
6007
  for (const [expr, reads] of readsByExpression) if (isReferencedExtra(expr)) {
5926
6008
  const exprBindings = resolveReferencedBindings(expr, reads, intersectionsBySection);
5927
6009
  expr.referencedBindings = exprBindings.referencedBindings;
5928
- expr.constantBindings = exprBindings.constantBindings;
5929
- expr.hoistedBindings = expr.section.referencedHoists = exprBindings.hoistedBindings;
6010
+ if (exprBindings.hoistedBindings) expr.section.referencedHoists = bindingUtil.union(expr.section.referencedHoists, exprBindings.hoistedBindings);
5930
6011
  if (expr.isEffect) {
5931
6012
  forEach(exprBindings.referencedBindings, (binding) => {
5932
6013
  addSerializeReason(binding.section, true, binding);
@@ -5941,7 +6022,6 @@ function finalizeReferences() {
5941
6022
  const fnBindings = fn === expr ? exprBindings : resolveReferencedBindingsInFunction(exprBindings.allBindings, fnReads);
5942
6023
  fn.referencedBindingsInFunction = fnBindings.referencedBindings;
5943
6024
  fn.constantBindingsInFunction = fnBindings.constantBindings;
5944
- fn.hoistedBindingsInFunction = fnBindings.hoistedBindings;
5945
6025
  }
5946
6026
  }
5947
6027
  }
@@ -6069,10 +6149,22 @@ function finalizeReferences() {
6069
6149
  finalizeParamSerializeReasonGroups(section);
6070
6150
  });
6071
6151
  forEachSection((section) => {
6072
- let intersectionIndex = 0;
6073
- const intersections = intersectionsBySection.get(section) || [];
6074
6152
  const { id, bindings } = section;
6075
6153
  const isOwnedBinding = ({ section }) => section.id === id;
6154
+ let intersections = intersectionsBySection.get(section) || [];
6155
+ if (intersections.length) {
6156
+ const anchors = /* @__PURE__ */ new Map();
6157
+ for (const intersection of intersections) for (let i = intersection.length; i--;) if (isOwnedBinding(intersection[i])) {
6158
+ anchors.set(intersection, intersection[i]);
6159
+ break;
6160
+ }
6161
+ intersections = [...intersections].sort((a, b) => {
6162
+ const aAnchor = anchors.get(a);
6163
+ const bAnchor = anchors.get(b);
6164
+ return aAnchor ? bAnchor ? bindingUtil.compare(aAnchor, bAnchor) : -1 : bAnchor ? 1 : 0;
6165
+ });
6166
+ }
6167
+ let intersectionIndex = 0;
6076
6168
  let lastBindingIndex = 0;
6077
6169
  let intersection;
6078
6170
  forEach(filter(bindings, isOwnedBinding), (binding, bindingIndex) => {
@@ -6421,27 +6513,21 @@ function pruneBinding(binding) {
6421
6513
  function resolveReferencedBindingsInFunction(refs, reads) {
6422
6514
  let referencedBindings;
6423
6515
  let constantBindings;
6424
- let hoistedBindings;
6425
6516
  if (reads) if (Array.isArray(reads)) for (const read of reads) {
6426
6517
  const { getter, binding } = read;
6427
- if (getter) {
6428
- if (getter.hoisted && bindingUtil.find(refs, binding)) hoistedBindings = bindingUtil.add(hoistedBindings, binding);
6429
- } else if (binding.type === 6) {
6518
+ if (getter) {} else if (binding.type === 6) {
6430
6519
  if (bindingUtil.find(refs, binding)) constantBindings = bindingUtil.add(constantBindings, binding);
6431
6520
  } else if (binding.type !== 0) referencedBindings = bindingUtil.add(referencedBindings, findClosestReference(read.binding, refs));
6432
6521
  }
6433
6522
  else {
6434
6523
  const { getter, binding } = reads;
6435
- if (getter) {
6436
- if (getter.hoisted && bindingUtil.find(refs, binding)) hoistedBindings = binding;
6437
- } else if (binding.type === 6) {
6524
+ if (getter) {} else if (binding.type === 6) {
6438
6525
  if (bindingUtil.find(refs, binding)) constantBindings = binding;
6439
6526
  } else if (binding.type !== 0) referencedBindings = findClosestReference(binding, refs);
6440
6527
  }
6441
6528
  return {
6442
6529
  referencedBindings,
6443
- constantBindings,
6444
- hoistedBindings
6530
+ constantBindings
6445
6531
  };
6446
6532
  }
6447
6533
  function findClosestReference(from, refs) {
@@ -6538,7 +6624,7 @@ function resolveReferencedBindings(expr, reads, intersectionsBySection) {
6538
6624
  }
6539
6625
  if (referencedBindings && constantBindings) {
6540
6626
  const intersections = intersectionsBySection.get(expr.section) || [];
6541
- const combined = concat(referencedBindings, constantBindings);
6627
+ const combined = bindingUtil.union(referencedBindings, constantBindings);
6542
6628
  if (!findSorted(compareIntersections, intersections, combined)) intersectionsBySection.set(expr.section, addSorted(compareIntersections, intersections, combined));
6543
6629
  }
6544
6630
  return {
@@ -7857,6 +7943,8 @@ var document_type_default = { translate: { exit(documentType) {
7857
7943
  } } };
7858
7944
  //#endregion
7859
7945
  //#region src/translator/visitors/import-declaration.ts
7946
+ const triggerRegExp = /\s*([\w-]+)\s*([^?|]+?)?\s*(?:\?([^|]*?))?\s*(?:\||$)/g;
7947
+ const [getHtmlLoadWrapped] = createProgramState(() => /* @__PURE__ */ new Map());
7860
7948
  var import_declaration_default = {
7861
7949
  analyze(importDecl) {
7862
7950
  const { node } = importDecl;
@@ -7864,19 +7952,118 @@ var import_declaration_default = {
7864
7952
  const { value } = source;
7865
7953
  const tagImport = (0, _marko_compiler_babel_utils.resolveTagImport)(importDecl, value);
7866
7954
  if (tagImport) {
7867
- node.extra ??= {};
7868
- node.extra.tagImport = tagImport;
7955
+ (node.extra ??= {}).tagImport = tagImport;
7869
7956
  const tags = importDecl.hub.file.metadata.marko.tags;
7870
7957
  if (!tags.includes(tagImport)) tags.push(tagImport);
7871
7958
  }
7959
+ const loadAttrValuePath = importDecl.get("attributes").find((p) => (p.node.key.type === "Identifier" ? p.node.key.name : p.node.key.value) === "load")?.get("value");
7960
+ if (loadAttrValuePath) {
7961
+ (node.extra ??= {}).loadImport = getLoadImportConfig(loadAttrValuePath);
7962
+ const { file } = importDecl.hub;
7963
+ if (!getMarkoOpts().linkAssets) throw importDecl.buildCodeFrameError("The `load` import attribute requires the `linkAssets` compiler option to be configured.");
7964
+ if (!(tagImport && (0, _marko_compiler_babel_utils.loadFileForImport)(file, value))) throw importDecl.buildCodeFrameError("Unable to resolve marko file for load import.");
7965
+ if ((node.importKind || "value") !== "value") throw importDecl.buildCodeFrameError("Invalid load import.");
7966
+ for (const specifier of importDecl.get("specifiers")) if (!_marko_compiler.types.isImportDefaultSpecifier(specifier.node)) throw specifier.buildCodeFrameError("Invalid load import, only a default specifier is allowed.");
7967
+ }
7872
7968
  },
7873
7969
  translate: { exit(importDecl) {
7874
7970
  const { node } = importDecl;
7875
7971
  const { extra } = node;
7876
7972
  const tagImport = extra?.tagImport;
7877
- if (tagImport) node.source.value = tagImport;
7973
+ const loadImport = extra?.loadImport;
7974
+ if (tagImport) {
7975
+ if (loadImport) {
7976
+ const { local } = node.specifiers.find(_marko_compiler.types.isImportDefaultSpecifier);
7977
+ const binding = importDecl.scope.getBinding(local.name);
7978
+ if (isOutputHTML()) {
7979
+ const { file } = importDecl.hub;
7980
+ const loadFile = (0, _marko_compiler_babel_utils.loadFileForImport)(file, node.source.value);
7981
+ const wrappedName = getOrCreateHtmlLoadWrapped(getReadyId(loadFile), _marko_compiler.types.identifier(local.name), loadFile.opts.filename, loadImport.render ? void 0 : loadImport.triggers);
7982
+ for (const ref of binding.referencePaths) ref.replaceWith(_marko_compiler.types.identifier(wrappedName));
7983
+ node.source.value = tagImport;
7984
+ return;
7985
+ } else if (binding.referencePaths.every((ref) => _marko_compiler.types.isMarkoTag(ref.parent) && ref.parent.extra?.tagNameLoad)) importDecl.remove();
7986
+ else {
7987
+ const { file } = importDecl.hub;
7988
+ const loadFile = (0, _marko_compiler_babel_utils.loadFileForImport)(file, node.source.value);
7989
+ const resolvedPath = (0, _marko_compiler_babel_utils.resolveRelativePath)(file, loadFile.opts.filename);
7990
+ importDecl.replaceWith(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(local, callRuntime("_load_template", _marko_compiler.types.stringLiteral(loadFile.metadata.marko.id), _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.callExpression(_marko_compiler.types.memberExpression(_marko_compiler.types.callExpression(_marko_compiler.types.import(), [_marko_compiler.types.stringLiteral(resolvedPath)]), _marko_compiler.types.identifier("then")), [_marko_compiler.types.arrowFunctionExpression([_marko_compiler.types.identifier("mod")], toMemberExpression(_marko_compiler.types.identifier("mod"), "default"))]))))]));
7991
+ }
7992
+ return;
7993
+ }
7994
+ node.source.value = tagImport;
7995
+ }
7878
7996
  } }
7879
7997
  };
7998
+ function getOrCreateHtmlLoadWrapped(readyId, originalIdentifier, filename, triggers) {
7999
+ const markoOpts = getMarkoOpts();
8000
+ const loadWrapped = getHtmlLoadWrapped();
8001
+ const existing = loadWrapped.get(readyId);
8002
+ if (existing) return existing;
8003
+ markoOpts.linkAssets?.onAsset("load", filename, readyId);
8004
+ const wrappedName = generateUid(`${originalIdentifier.name ?? "tag"}_withLoadAssets`);
8005
+ loadWrapped.set(readyId, wrappedName);
8006
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.markoScriptlet([_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(_marko_compiler.types.identifier(wrappedName), callRuntime("withLoadAssets", originalIdentifier, _marko_compiler.types.stringLiteral(readyId), triggers ? _marko_compiler.types.valueToNode(triggers) : void 0))])], true));
8007
+ return wrappedName;
8008
+ }
8009
+ function getLoadImportConfig(attrValue) {
8010
+ const raw = attrValue.node.value;
8011
+ if (raw === "render") return { render: true };
8012
+ const triggers = [];
8013
+ for (const match of raw.matchAll(triggerRegExp)) {
8014
+ const type = parseTriggerType(match[1]);
8015
+ const selector = match[2];
8016
+ const query = match[3];
8017
+ if (!type) throw attrValue.buildCodeFrameError(`Unknown trigger type "${match[1]}". Supported triggers are "visible", "idle", "media", and "on*".`);
8018
+ if (type === "render") throw attrValue.buildCodeFrameError("The \"render\" trigger must be used alone.");
8019
+ if (type === "idle") {
8020
+ if (selector) throw attrValue.buildCodeFrameError(`Selector is not supported for the "idle" trigger.`);
8021
+ } else if (!selector) throw attrValue.buildCodeFrameError(type === "media" ? `A media query is required for the "media" trigger. (e.g. "media(max-width:768px)")` : `A selector is required for the "${type}" trigger. (e.g. "${type}.my-element")`);
8022
+ const trigger = selector ? {
8023
+ type,
8024
+ selector
8025
+ } : { type };
8026
+ if (query) {
8027
+ const params = new URLSearchParams(query);
8028
+ switch (type) {
8029
+ case "visible": {
8030
+ let rootMargin;
8031
+ for (const [key, value] of params) {
8032
+ if (key !== "rootMargin") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "visible" trigger. Supported params: "rootMargin".`);
8033
+ rootMargin = value;
8034
+ }
8035
+ if (rootMargin) trigger.options = { rootMargin };
8036
+ break;
8037
+ }
8038
+ case "idle": {
8039
+ let timeout;
8040
+ for (const [key, value] of params) {
8041
+ if (key !== "timeout") throw attrValue.buildCodeFrameError(`Unknown param "${key}" for the "idle" trigger. Supported params: "timeout".`);
8042
+ timeout = Number(value);
8043
+ }
8044
+ if (timeout) trigger.options = { timeout };
8045
+ break;
8046
+ }
8047
+ default: throw attrValue.buildCodeFrameError(`Params are not supported for the "${type}" trigger.`);
8048
+ }
8049
+ }
8050
+ triggers.push(trigger);
8051
+ }
8052
+ if (!triggers.length) throw attrValue.buildCodeFrameError("The \"load\" attribute requires \"render\" or at least one trigger (e.g. \"visible.my-element\").");
8053
+ return {
8054
+ render: false,
8055
+ triggers
8056
+ };
8057
+ }
8058
+ function parseTriggerType(type) {
8059
+ switch (type) {
8060
+ case "idle":
8061
+ case "media":
8062
+ case "render":
8063
+ case "visible": return type;
8064
+ default: return isEventHandler(type) ? `on-${getEventHandlerName(type)}` : void 0;
8065
+ }
8066
+ }
7880
8067
  //#endregion
7881
8068
  //#region src/translator/visitors/placeholder.ts
7882
8069
  const kNodeBinding = Symbol("placeholder node binding");
@@ -8085,17 +8272,24 @@ var attribute_tag_default = {
8085
8272
  };
8086
8273
  //#endregion
8087
8274
  //#region src/translator/visitors/tag/custom-tag.ts
8275
+ const kLoadTagBinding = Symbol("load tag binding");
8276
+ const [getLoadIdentifiers] = createProgramState(() => ({
8277
+ triggers: /* @__PURE__ */ new Map(),
8278
+ signals: /* @__PURE__ */ new Map()
8279
+ }));
8088
8280
  var custom_tag_default = {
8089
8281
  analyze: { enter(tag) {
8090
8282
  if (!(0, _marko_compiler_babel_utils.getTagTemplate)(tag)) throw tagNotFoundError(tag);
8091
8283
  (0, _marko_compiler_babel_utils.assertAttributesOrSingleArg)(tag);
8092
8284
  const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
8093
8285
  if (!childFile) throw tag.get("name").buildCodeFrameError("Unable to resolve file for tag.");
8286
+ const tagExtra = tag.node.extra ??= {};
8094
8287
  const programExtra = (0, _marko_compiler_babel_utils.getProgram)().node.extra;
8095
8288
  const programSection = programExtra.section;
8096
8289
  const childExtra = childFile.ast.program.extra;
8097
8290
  const childSection = childExtra.section;
8098
8291
  if (childExtra.page) programExtra.page ??= true;
8292
+ if (tagExtra.tagNameLoad) tagExtra[kLoadTagBinding] = createBinding("#text", 0, getOrCreateSection(tag));
8099
8293
  knownTagAnalyze(tag, childSection, programSection === childSection ? programSection.params && getBindingPropTree(programSection.params) : childExtra.domExports?.params);
8100
8294
  } },
8101
8295
  translate: {
@@ -8124,11 +8318,46 @@ function translateDOM(tag) {
8124
8318
  const write = writeTo(tag);
8125
8319
  const relativePath = getTagRelativePath(tag);
8126
8320
  const programSection = (0, _marko_compiler_babel_utils.getProgram)().node.extra.section;
8127
- const childExtra = (0, _marko_compiler_babel_utils.loadFileForTag)(tag).ast.program.extra;
8321
+ const childFile = (0, _marko_compiler_babel_utils.loadFileForTag)(tag);
8322
+ const childExtra = childFile.ast.program.extra;
8128
8323
  const childExports = childExtra.domExports;
8129
8324
  const childSection = childExtra.section;
8325
+ const loadConfig = node.extra?.tagNameLoad;
8326
+ const isLoad = !!loadConfig;
8130
8327
  const tagName = _marko_compiler.types.isIdentifier(node.name) ? node.name.name : _marko_compiler.types.isStringLiteral(node.name) ? node.name.value : "tag";
8131
- if (programSection === childSection) {
8328
+ if (isLoad) {
8329
+ const childFileName = childFile.opts.filename;
8330
+ const { triggers, signals } = getLoadIdentifiers();
8331
+ let triggerIdent = triggers.get(loadConfig);
8332
+ if (!triggerIdent) {
8333
+ const triggerExpr = loadTriggersToExpression(loadConfig);
8334
+ if (triggerExpr) {
8335
+ triggerIdent = generateUidIdentifier(`load_${tagName}_trigger`);
8336
+ triggers.set(loadConfig, triggerIdent);
8337
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("const", [_marko_compiler.types.variableDeclarator(triggerIdent, triggerExpr)]));
8338
+ }
8339
+ }
8340
+ knownTagTranslateDOM(tag, childExports.params, (binding) => {
8341
+ const signalKey = `${triggerIdent ? triggerIdent.name : ""}\0${childFileName}\0${binding.export}`;
8342
+ let signalIdent = signals.get(signalKey);
8343
+ if (!signalIdent) {
8344
+ signalIdent = generateUidIdentifier(`load_${tagName}_tag_${binding.name}`);
8345
+ signals.set(signalKey, signalIdent);
8346
+ const loadExpr = _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.callExpression(_marko_compiler.types.import(), [_marko_compiler.types.stringLiteral(buildLoadSignalVirtualModule(file, childFileName, binding.export, binding.name))]));
8347
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("let", [_marko_compiler.types.variableDeclarator(signalIdent, callRuntime("_load_signal", triggerIdent ? _marko_compiler.types.addComment(_marko_compiler.types.callExpression(triggerIdent, [loadExpr]), "leading", "@__PURE__") : loadExpr))]));
8348
+ }
8349
+ return signalIdent;
8350
+ }, (section, childBinding) => {
8351
+ const setupIdent = generateUidIdentifier(`load_${tagName}_setup`);
8352
+ const setupLoadExpr = _marko_compiler.types.arrowFunctionExpression([], _marko_compiler.types.callExpression(_marko_compiler.types.import(), [_marko_compiler.types.stringLiteral(buildLoadSetupVirtualModule(file, childFileName, childExports))]));
8353
+ (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.variableDeclaration("let", [_marko_compiler.types.variableDeclarator(setupIdent, callRuntime("_load_setup", getScopeAccessorLiteral(node.extra[kLoadTagBinding], true), getScopeAccessorLiteral(childBinding, true), triggerIdent ? _marko_compiler.types.addComment(_marko_compiler.types.callExpression(triggerIdent, [setupLoadExpr]), "leading", "@__PURE__") : setupLoadExpr))]));
8354
+ addStatement("render", section, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(setupIdent, [scopeIdentifier])));
8355
+ });
8356
+ write`<!>`;
8357
+ visit(tag, 37);
8358
+ injectWalks(tag, tagName);
8359
+ enterShallow(tag);
8360
+ } else if (programSection === childSection) {
8132
8361
  knownTagTranslateDOM(tag, childExports.params, (binding, preferredName) => getSignal(programSection, binding, preferredName).identifier, (section, childBinding) => {
8133
8362
  addStatement("render", section, void 0, _marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression(_marko_compiler.types.identifier(childExports.setup), [createScopeReadExpression(childBinding, section)])));
8134
8363
  });
@@ -8171,6 +8400,35 @@ function isCircularRequest(file, request) {
8171
8400
  const { filename } = file.opts;
8172
8401
  return request === filename || request[0] === "." && path.default.resolve(filename, "..", request) === filename;
8173
8402
  }
8403
+ function buildLoadSetupVirtualModule(file, childFileName, childExports) {
8404
+ const parts = `${childExports.template}, ${childExports.walks}, ${childExports.setup}`;
8405
+ return getMarkoOpts().resolveVirtualDependency(file.opts.filename, {
8406
+ virtualPath: `${(0, _marko_compiler_babel_utils.resolveRelativePath)(file, childFileName)}.setup.js`,
8407
+ code: `import { ${parts} } from "./${path.default.basename(childFileName)}"\nexport const _ = [${parts}]`
8408
+ });
8409
+ }
8410
+ function buildLoadSignalVirtualModule(file, childFileName, childExport, childBinding) {
8411
+ return getMarkoOpts().resolveVirtualDependency(file.opts.filename, {
8412
+ virtualPath: `${(0, _marko_compiler_babel_utils.resolveRelativePath)(file, childFileName)}.${childBinding}.js`,
8413
+ code: `export { ${childExport} as _ } from "./${path.default.basename(childFileName)}"`
8414
+ });
8415
+ }
8416
+ function loadTriggersToExpression(loadConfig) {
8417
+ if (!loadConfig || loadConfig.render) return;
8418
+ const triggers = loadConfig.triggers.map(toDOMTriggerExpression);
8419
+ return triggers.length === 1 ? triggers[0] : callRuntime("_load_race_trigger", ...triggers);
8420
+ }
8421
+ function toDOMTriggerExpression(trigger) {
8422
+ switch (trigger.type) {
8423
+ case "visible": return callRuntime("_load_visible_trigger", _marko_compiler.types.stringLiteral(trigger.selector), optionalValueToNode(trigger.options));
8424
+ case "idle": return callRuntime("_load_idle_trigger", optionalValueToNode(trigger.options));
8425
+ case "media": return callRuntime("_load_media_trigger", _marko_compiler.types.stringLiteral(trigger.selector));
8426
+ default: return callRuntime("_load_event_trigger", _marko_compiler.types.stringLiteral(trigger.type.slice(3)), _marko_compiler.types.stringLiteral(trigger.selector));
8427
+ }
8428
+ }
8429
+ function optionalValueToNode(value) {
8430
+ return value ? _marko_compiler.types.valueToNode(value) : void 0;
8431
+ }
8174
8432
  //#endregion
8175
8433
  //#region src/translator/visitors/tag/dynamic-tag.ts
8176
8434
  const kDOMBinding = Symbol("dynamic tag dom binding");
@@ -8242,7 +8500,7 @@ var dynamic_tag_default = {
8242
8500
  let tagExpression = node.name;
8243
8501
  if (_marko_compiler.types.isStringLiteral(tagExpression)) tagExpression = (0, _marko_compiler_babel_utils.importDefault)(tag.hub.file, getTagRelativePath(tag), tagExpression.value);
8244
8502
  if (isClassAPI) if ((0, _marko_compiler_babel_utils.getTagTemplate)(tag)) {
8245
- if (getSerializeReason(tagSection, nodeBinding)) if (isOutputHTML()) (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"), [_marko_compiler.types.identifier(tagExpression.name), _marko_compiler.types.stringLiteral((0, _marko_compiler_babel_utils.loadFileForTag)(tag).metadata.marko.id)]))], true));
8503
+ if (getSerializeReason(tagSection, nodeBinding)) if (isOutputHTML()) (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(_marko_compiler.types.callExpression((0, _marko_compiler_babel_utils.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"), [_marko_compiler.types.stringLiteral((0, _marko_compiler_babel_utils.loadFileForTag)(tag).metadata.marko.id), _marko_compiler.types.identifier(tagExpression.name)]))], true));
8246
8504
  else (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.expressionStatement(callRuntime("_resume", _marko_compiler.types.stringLiteral((0, _marko_compiler_babel_utils.loadFileForTag)(tag).metadata.marko.id), _marko_compiler.types.identifier(tagExpression.name))));
8247
8505
  } else (0, _marko_compiler_babel_utils.getProgram)().node.body.push(_marko_compiler.types.markoScriptlet([_marko_compiler.types.expressionStatement(_marko_compiler.types.assignmentExpression("??=", _marko_compiler.types.memberExpression(_marko_compiler.types.identifier(tagExpression.name), _marko_compiler.types.identifier("_")), _marko_compiler.types.identifier(tagExpression.name)))], true));
8248
8506
  const { properties, statements } = translateAttrs(tag, void 0, void 0, void 0, isClassAPI ? "renderBody" : "content");
@@ -8546,6 +8804,7 @@ function addFeature(state, type, name, path) {
8546
8804
  //#region src/translator/interop/index.ts
8547
8805
  function createInteropTranslator(translate5) {
8548
8806
  return {
8807
+ version: translate5.version ?? "0.0.0",
8549
8808
  preferAPI: translate5.preferAPI,
8550
8809
  transform: mergeVisitors(translate5.transform, transform),
8551
8810
  analyze: mergeVisitors(translate5.analyze, analyze),
@@ -8606,7 +8865,8 @@ function createInteropTranslator(translate5) {
8606
8865
  Program: {
8607
8866
  enter(program, state) {
8608
8867
  const entryFile = program.hub.file;
8609
- if (entryFile.markoOpts.output !== "hydrate") return enterProgram?.call(this, program, state);
8868
+ const { output, entry } = entryFile.markoOpts;
8869
+ if (!(output === "dom" && entry === "page" || output === "hydrate")) return enterProgram?.call(this, program, state);
8610
8870
  const visitedFiles = new Set([(0, _marko_compiler_babel_utils.resolveRelativePath)(entryFile, entryFile.opts.filename)]);
8611
8871
  entryBuilder.visit(entryFile, entryFile, function visitChild(resolved) {
8612
8872
  if (!visitedFiles.has(resolved)) {
@@ -8747,3 +9007,9 @@ exports.tagDiscoveryDirs = tagDiscoveryDirs;
8747
9007
  exports.taglibs = taglibs;
8748
9008
  exports.transform = transform;
8749
9009
  exports.translate = translate;
9010
+ Object.defineProperty(exports, "version", {
9011
+ enumerable: true,
9012
+ get: function() {
9013
+ return package_json.version;
9014
+ }
9015
+ });