marko 5.39.2 → 5.39.3
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/node_modules/@internal/components-registry/index-browser.js +6 -1
- package/dist/node_modules/@internal/components-registry/index.js +1 -1
- package/dist/node_modules/@internal/components-util/index-browser.js +11 -11
- package/dist/node_modules/@internal/components-util/index.js +4 -4
- package/dist/node_modules/@internal/create-readable/index-browser.js +1 -1
- package/dist/node_modules/@internal/create-readable/index.js +9 -9
- package/dist/node_modules/@internal/preserve-tag/index-browser.js +5 -5
- package/dist/node_modules/@internal/preserve-tag/index.js +1 -1
- package/dist/node_modules/@internal/set-immediate/index-worker.js +1 -1
- package/dist/node_modules/@internal/set-immediate/index.js +1 -1
- package/dist/runtime/RenderResult.js +3 -3
- package/dist/runtime/components/Component.js +66 -66
- package/dist/runtime/components/ComponentDef.js +12 -12
- package/dist/runtime/components/ComponentsContext.js +3 -3
- package/dist/runtime/components/GlobalComponentsContext.js +3 -3
- package/dist/runtime/components/KeySequence.js +3 -3
- package/dist/runtime/components/ServerComponent.js +1 -1
- package/dist/runtime/components/State.js +18 -18
- package/dist/runtime/components/attach-detach.js +7 -7
- package/dist/runtime/components/dom-data.js +2 -2
- package/dist/runtime/components/event-delegation.js +5 -5
- package/dist/runtime/components/legacy/defineRenderer-legacy.js +8 -8
- package/dist/runtime/components/legacy/dependencies/index.js +7 -7
- package/dist/runtime/components/legacy/renderer-legacy.js +21 -21
- package/dist/runtime/components/renderer.js +20 -20
- package/dist/runtime/components/update-manager.js +3 -3
- package/dist/runtime/createOut.js +1 -1
- package/dist/runtime/dom-insert.js +5 -5
- package/dist/runtime/helpers/_change-case.js +2 -2
- package/dist/runtime/helpers/dynamic-tag.js +9 -9
- package/dist/runtime/helpers/load-tag-browser.js +59 -0
- package/dist/runtime/helpers/load-tag-event-trigger.js +25 -0
- package/dist/runtime/helpers/load-tag-idle-trigger.js +15 -0
- package/dist/runtime/helpers/load-tag-media-trigger.js +17 -0
- package/dist/runtime/helpers/load-tag-race-trigger.js +22 -0
- package/dist/runtime/helpers/load-tag-visible-trigger.js +35 -0
- package/dist/runtime/helpers/load-tag.js +168 -0
- package/dist/runtime/helpers/render-tag.js +1 -1
- package/dist/runtime/helpers/serialize-noop.js +1 -1
- package/dist/runtime/helpers/style-value.js +1 -1
- package/dist/runtime/helpers/tags-compat/runtime-dom.js +16 -16
- package/dist/runtime/helpers/tags-compat/runtime-html.js +2 -2
- package/dist/runtime/html/AsyncStream.js +20 -20
- package/dist/runtime/html/BufferedWriter.js +1 -1
- package/dist/runtime/html/helpers/_dynamic-attr.js +2 -2
- package/dist/runtime/html/helpers/attr.js +2 -2
- package/dist/runtime/html/helpers/data-marko.js +1 -1
- package/dist/runtime/html/helpers/escape-xml.js +1 -1
- package/dist/runtime/html/index.js +1 -1
- package/dist/runtime/renderable.js +2 -2
- package/dist/runtime/vdom/AsyncVDOMBuilder.js +83 -83
- package/dist/runtime/vdom/VComment.js +7 -7
- package/dist/runtime/vdom/VComponent.js +4 -4
- package/dist/runtime/vdom/VDocumentFragment.js +6 -6
- package/dist/runtime/vdom/VElement.js +35 -35
- package/dist/runtime/vdom/VFragment.js +7 -7
- package/dist/runtime/vdom/VNode.js +33 -33
- package/dist/runtime/vdom/VText.js +8 -8
- package/dist/runtime/vdom/helpers/const-element.js +3 -3
- package/dist/runtime/vdom/hot-reload.js +8 -8
- package/dist/runtime/vdom/index.js +1 -1
- package/dist/runtime/vdom/morphdom/fragment.js +4 -4
- package/dist/runtime/vdom/morphdom/helpers.js +5 -5
- package/dist/runtime/vdom/morphdom/index.js +57 -57
- package/dist/runtime/vdom/vdom.js +15 -15
- package/dist/translator/index.js +51 -2
- package/dist/translator/tag/custom-tag.js +4 -2
- package/dist/translator/tag/native-tag[html]/index.js +37 -11
- package/dist/translator/util/get-component-files.js +1 -1
- package/dist/translator/util/load-import.js +288 -0
- package/package.json +3 -3
- package/src/node_modules/@internal/components-registry/index-browser.js +5 -0
- package/src/runtime/helpers/load-tag-browser.js +59 -0
- package/src/runtime/helpers/load-tag-event-trigger.js +25 -0
- package/src/runtime/helpers/load-tag-idle-trigger.js +15 -0
- package/src/runtime/helpers/load-tag-media-trigger.js +17 -0
- package/src/runtime/helpers/load-tag-race-trigger.js +22 -0
- package/src/runtime/helpers/load-tag-visible-trigger.js +35 -0
- package/src/runtime/helpers/load-tag.js +168 -0
- package/src/runtime/helpers/tags-compat/runtime-dom.js +2 -2
- package/src/runtime/helpers/tags-compat/runtime-html.js +1 -1
- package/src/translator/index.js +50 -1
- package/src/translator/tag/custom-tag.js +4 -2
- package/src/translator/tag/native-tag[html]/index.js +42 -16
- package/src/translator/util/load-import.js +288 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.analyzeLoadImport = analyzeLoadImport;exports.translateLoadTag = translateLoadTag;var _compiler = require("@marko/compiler");
|
|
2
|
+
var _babelUtils = require("@marko/compiler/babel-utils");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
const triggerRegExp = /\s*([\w-]+)\s*([^?|]+?)?\s*(?:\?([^|]*?))?\s*(?:\||$)/g;
|
|
9
|
+
const loadTagsByFile = new WeakMap();
|
|
10
|
+
|
|
11
|
+
function analyzeLoadImport(importDecl, tagEntry) {
|
|
12
|
+
const loadAttrValuePath = importDecl.
|
|
13
|
+
get("attributes").
|
|
14
|
+
find(
|
|
15
|
+
(p) =>
|
|
16
|
+
(p.node.key.type === "Identifier" ?
|
|
17
|
+
p.node.key.name :
|
|
18
|
+
p.node.key.value) === "load"
|
|
19
|
+
)?.
|
|
20
|
+
get("value");
|
|
21
|
+
|
|
22
|
+
if (!loadAttrValuePath) return;
|
|
23
|
+
|
|
24
|
+
if (!tagEntry) {
|
|
25
|
+
throw importDecl.buildCodeFrameError(
|
|
26
|
+
"Unable to resolve marko file for load import."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if ((importDecl.node.importKind || "value") !== "value") {
|
|
31
|
+
throw importDecl.buildCodeFrameError("Invalid load import.");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
for (const specifier of importDecl.get("specifiers")) {
|
|
35
|
+
if (!_compiler.types.isImportDefaultSpecifier(specifier.node)) {
|
|
36
|
+
throw specifier.buildCodeFrameError(
|
|
37
|
+
"Invalid load import, only a default specifier is allowed."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { markoOpts } = importDecl.hub.file;
|
|
43
|
+
if (!markoOpts.linkAssets) {
|
|
44
|
+
throw importDecl.buildCodeFrameError(
|
|
45
|
+
"The `load` import attribute requires the `linkAssets` compiler option to be configured."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
(importDecl.node.extra ??= {}).loadImport =
|
|
50
|
+
getLoadImportConfig(loadAttrValuePath);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function translateLoadTag(path, tagName, relativePath) {
|
|
54
|
+
const { file } = path.hub;
|
|
55
|
+
const { markoOpts } = file;
|
|
56
|
+
|
|
57
|
+
const loadTagFn =
|
|
58
|
+
markoOpts.output === "dom" ?
|
|
59
|
+
(0, _babelUtils.importDefault)(
|
|
60
|
+
file,
|
|
61
|
+
"marko/src/runtime/helpers/load-tag-browser.js",
|
|
62
|
+
"marko_load_tag"
|
|
63
|
+
) :
|
|
64
|
+
(0, _babelUtils.importNamed)(
|
|
65
|
+
file,
|
|
66
|
+
"marko/src/runtime/helpers/load-tag.js",
|
|
67
|
+
"withLoadAssets",
|
|
68
|
+
"marko_load_tag"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const importBinding = path.scope.getBinding(tagName);
|
|
72
|
+
const importDecl = importBinding?.path?.parentPath?.isImportDeclaration() ?
|
|
73
|
+
importBinding.path.parentPath :
|
|
74
|
+
null;
|
|
75
|
+
const loadImport = importDecl?.node?.extra?.loadImport;
|
|
76
|
+
const triggers =
|
|
77
|
+
loadImport && !loadImport.render && loadImport.triggers.length ?
|
|
78
|
+
loadImport.triggers :
|
|
79
|
+
null;
|
|
80
|
+
|
|
81
|
+
let loadTags = loadTagsByFile.get(file);
|
|
82
|
+
if (!loadTags) loadTagsByFile.set(file, loadTags = new Map());
|
|
83
|
+
if (loadTags.has(relativePath)) {
|
|
84
|
+
return loadTags.get(relativePath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const loadId = file.path.scope.generateUidIdentifier(`marko_load_${tagName}`);
|
|
88
|
+
loadTags.set(relativePath, loadId);
|
|
89
|
+
|
|
90
|
+
let loadArgs;
|
|
91
|
+
if (markoOpts.output === "dom") {
|
|
92
|
+
if (importDecl) {
|
|
93
|
+
// The lazy wrapper pretends to be the template, so every reference
|
|
94
|
+
// not already translated as a tag uses it.
|
|
95
|
+
for (const ref of importBinding.referencePaths) {
|
|
96
|
+
if (!(_compiler.types.isMarkoTag(ref.parent) && ref.parent.extra?.tagNameLoad)) {
|
|
97
|
+
ref.replaceWith(_compiler.types.cloneNode(loadId));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
importDecl.remove();
|
|
101
|
+
}
|
|
102
|
+
const childFile = (0, _babelUtils.loadFileForTag)(path);
|
|
103
|
+
loadArgs = [
|
|
104
|
+
_compiler.types.stringLiteral(childFile.metadata.marko.id),
|
|
105
|
+
_compiler.types.arrowFunctionExpression(
|
|
106
|
+
[],
|
|
107
|
+
_compiler.types.callExpression(_compiler.types.import(), [_compiler.types.stringLiteral(relativePath)])
|
|
108
|
+
)];
|
|
109
|
+
|
|
110
|
+
if (triggers) loadArgs.push(buildDomTrigger(file, triggers));
|
|
111
|
+
} else {
|
|
112
|
+
const { linkAssets } = markoOpts;
|
|
113
|
+
const childFile = (0, _babelUtils.loadFileForTag)(path);
|
|
114
|
+
linkAssets.onAsset(
|
|
115
|
+
"load",
|
|
116
|
+
childFile.opts.filename,
|
|
117
|
+
childFile.metadata.marko.id
|
|
118
|
+
);
|
|
119
|
+
loadArgs = [
|
|
120
|
+
_compiler.types.stringLiteral(childFile.metadata.marko.id),
|
|
121
|
+
_compiler.types.identifier(tagName)];
|
|
122
|
+
|
|
123
|
+
if (triggers) loadArgs.push(_compiler.types.valueToNode(triggers));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
file.path.unshiftContainer("body", [
|
|
127
|
+
_compiler.types.variableDeclaration("const", [
|
|
128
|
+
_compiler.types.variableDeclarator(loadId, _compiler.types.callExpression(loadTagFn, loadArgs))]
|
|
129
|
+
)]
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
return loadId;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getLoadImportConfig(attrValue) {
|
|
136
|
+
const raw = attrValue.node.value;
|
|
137
|
+
|
|
138
|
+
if (raw === "render") return { render: true };
|
|
139
|
+
|
|
140
|
+
const triggers = [];
|
|
141
|
+
for (const match of raw.matchAll(triggerRegExp)) {
|
|
142
|
+
const type = parseTriggerType(match[1]);
|
|
143
|
+
const selector = match[2];
|
|
144
|
+
const query = match[3];
|
|
145
|
+
|
|
146
|
+
if (!type) {
|
|
147
|
+
throw attrValue.buildCodeFrameError(
|
|
148
|
+
`Unknown trigger type "${match[1]}". Supported triggers are "visible", "idle", "media", and "on*".`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (type === "render") {
|
|
152
|
+
throw attrValue.buildCodeFrameError(
|
|
153
|
+
'The "render" trigger must be used alone.'
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
if (type === "idle") {
|
|
157
|
+
if (selector) {
|
|
158
|
+
throw attrValue.buildCodeFrameError(
|
|
159
|
+
`Selector is not supported for the "idle" trigger.`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
} else if (!selector) {
|
|
163
|
+
throw attrValue.buildCodeFrameError(
|
|
164
|
+
type === "media" ?
|
|
165
|
+
`A media query is required for the "media" trigger. (e.g. "media(max-width:768px)")` :
|
|
166
|
+
`A selector is required for the "${type}" trigger. (e.g. "${type}.my-element")`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const trigger = selector ? { type, selector } : { type };
|
|
171
|
+
|
|
172
|
+
if (query) {
|
|
173
|
+
const params = new URLSearchParams(query);
|
|
174
|
+
switch (type) {
|
|
175
|
+
case "visible":{
|
|
176
|
+
let rootMargin;
|
|
177
|
+
for (const [key, value] of params) {
|
|
178
|
+
if (key !== "rootMargin") {
|
|
179
|
+
throw attrValue.buildCodeFrameError(
|
|
180
|
+
`Unknown param "${key}" for the "visible" trigger. Supported params: "rootMargin".`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
rootMargin = value;
|
|
184
|
+
}
|
|
185
|
+
if (rootMargin) trigger.options = { rootMargin };
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
case "idle":{
|
|
189
|
+
let timeout;
|
|
190
|
+
for (const [key, value] of params) {
|
|
191
|
+
if (key !== "timeout") {
|
|
192
|
+
throw attrValue.buildCodeFrameError(
|
|
193
|
+
`Unknown param "${key}" for the "idle" trigger. Supported params: "timeout".`
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
timeout = Number(value);
|
|
197
|
+
}
|
|
198
|
+
if (timeout) trigger.options = { timeout };
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
default:
|
|
202
|
+
throw attrValue.buildCodeFrameError(
|
|
203
|
+
`Params are not supported for the "${type}" trigger.`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
triggers.push(trigger);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!triggers.length) {
|
|
212
|
+
throw attrValue.buildCodeFrameError(
|
|
213
|
+
'The "load" attribute requires "render" or at least one trigger (e.g. "visible.my-element").'
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return { render: false, triggers };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function buildDomTrigger(file, triggers) {
|
|
221
|
+
const triggerExprs = triggers.map((trigger) => {
|
|
222
|
+
switch (trigger.type) {
|
|
223
|
+
case "visible":{
|
|
224
|
+
const fn = (0, _babelUtils.importDefault)(
|
|
225
|
+
file,
|
|
226
|
+
"marko/src/runtime/helpers/load-tag-visible-trigger.js",
|
|
227
|
+
"marko_visible_trigger"
|
|
228
|
+
);
|
|
229
|
+
const args = [_compiler.types.stringLiteral(trigger.selector)];
|
|
230
|
+
if (trigger.options) args.push(_compiler.types.valueToNode(trigger.options));
|
|
231
|
+
return _compiler.types.callExpression(fn, args);
|
|
232
|
+
}
|
|
233
|
+
case "idle":{
|
|
234
|
+
const fn = (0, _babelUtils.importDefault)(
|
|
235
|
+
file,
|
|
236
|
+
"marko/src/runtime/helpers/load-tag-idle-trigger.js",
|
|
237
|
+
"marko_idle_trigger"
|
|
238
|
+
);
|
|
239
|
+
return _compiler.types.callExpression(
|
|
240
|
+
fn,
|
|
241
|
+
trigger.options ? [_compiler.types.valueToNode(trigger.options)] : []
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
case "media":{
|
|
245
|
+
const fn = (0, _babelUtils.importDefault)(
|
|
246
|
+
file,
|
|
247
|
+
"marko/src/runtime/helpers/load-tag-media-trigger.js",
|
|
248
|
+
"marko_media_trigger"
|
|
249
|
+
);
|
|
250
|
+
return _compiler.types.callExpression(fn, [_compiler.types.stringLiteral(trigger.selector)]);
|
|
251
|
+
}
|
|
252
|
+
default:{
|
|
253
|
+
const fn = (0, _babelUtils.importDefault)(
|
|
254
|
+
file,
|
|
255
|
+
"marko/src/runtime/helpers/load-tag-event-trigger.js",
|
|
256
|
+
"marko_event_trigger"
|
|
257
|
+
);
|
|
258
|
+
return _compiler.types.callExpression(fn, [
|
|
259
|
+
_compiler.types.stringLiteral(trigger.type.slice("on-".length)),
|
|
260
|
+
_compiler.types.stringLiteral(trigger.selector)]
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
if (triggerExprs.length === 1) return triggerExprs[0];
|
|
267
|
+
|
|
268
|
+
const raceFn = (0, _babelUtils.importDefault)(
|
|
269
|
+
file,
|
|
270
|
+
"marko/src/runtime/helpers/load-tag-race-trigger.js",
|
|
271
|
+
"marko_race_trigger"
|
|
272
|
+
);
|
|
273
|
+
return _compiler.types.callExpression(raceFn, triggerExprs);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function parseTriggerType(type) {
|
|
277
|
+
switch (type) {
|
|
278
|
+
case "idle":
|
|
279
|
+
case "media":
|
|
280
|
+
case "render":
|
|
281
|
+
case "visible":
|
|
282
|
+
return type;
|
|
283
|
+
default:
|
|
284
|
+
return /^on[A-Z-]/.test(type) ?
|
|
285
|
+
`on-${type[2] === "-" ? type.slice(3) : type.slice(2).toLowerCase()}` :
|
|
286
|
+
undefined;
|
|
287
|
+
}
|
|
288
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marko",
|
|
3
|
-
"version": "5.39.
|
|
3
|
+
"version": "5.39.3",
|
|
4
4
|
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"build": "babel ./src --out-dir ./dist --extensions .js --copy-files --config-file ../../babel.config.js --env-name=production"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@marko/compiler": "^5.39.
|
|
73
|
-
"@marko/runtime-tags": "^6.1.
|
|
72
|
+
"@marko/compiler": "^5.39.64",
|
|
73
|
+
"@marko/runtime-tags": "^6.1.4",
|
|
74
74
|
"app-module-path": "^2.2.0",
|
|
75
75
|
"argly": "^1.2.0",
|
|
76
76
|
"browser-refresh-client": "1.1.4",
|
|
@@ -578,9 +578,14 @@ function tryInvoke(fn) {
|
|
|
578
578
|
if (fn) fn();
|
|
579
579
|
}
|
|
580
580
|
|
|
581
|
+
function getLoadedTemplate(typeName) {
|
|
582
|
+
return registered[typeName] && load(typeName);
|
|
583
|
+
}
|
|
584
|
+
|
|
581
585
|
exports.r = register;
|
|
582
586
|
exports.___createComponent = createComponent;
|
|
583
587
|
exports.___getComponentClass = getComponentClass;
|
|
588
|
+
exports.___getLoadedTemplate = getLoadedTemplate;
|
|
584
589
|
exports.___initServerRendered = win.$initComponents = initServerRendered;
|
|
585
590
|
|
|
586
591
|
require("../../../runtime/components/ComponentsContext").___initClientRendered =
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var createTemplate = require("../vdom").t;
|
|
4
|
+
var getLoadedTemplate =
|
|
5
|
+
require("@internal/components-registry").___getLoadedTemplate;
|
|
6
|
+
|
|
7
|
+
module.exports = function loadTag(typeId, load, trigger) {
|
|
8
|
+
var loading;
|
|
9
|
+
var hydratedComponents = new WeakSet();
|
|
10
|
+
var pending = new Set();
|
|
11
|
+
var start = trigger ? trigger(load) : load;
|
|
12
|
+
var lazyTemplate = createTemplate(typeId);
|
|
13
|
+
// Assumes rendering as a tag (direct or dynamic) — both assign the
|
|
14
|
+
// component def (`out.c`) before invoking `_`.
|
|
15
|
+
lazyTemplate._ = function loadRenderer(input, out) {
|
|
16
|
+
var component = out.___assignedComponentDef.___component;
|
|
17
|
+
var template = getLoadedTemplate(typeId);
|
|
18
|
+
|
|
19
|
+
if (!template) {
|
|
20
|
+
if (!loading) {
|
|
21
|
+
loading = start().then(
|
|
22
|
+
function () {
|
|
23
|
+
pending = pending.forEach(function (c) {
|
|
24
|
+
c.___destroyed ||
|
|
25
|
+
c.___rerender(c.___input, true).afterInsert(c.___host);
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
function (err) {
|
|
29
|
+
// Allows a later render to retry the load.
|
|
30
|
+
var failed = pending;
|
|
31
|
+
loading = undefined;
|
|
32
|
+
pending = new Set();
|
|
33
|
+
failed.forEach(function (c) {
|
|
34
|
+
c.___destroyed || c.emit("error", err);
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
pending.add(component);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (out.___components.___globalContext.___isHydrate) {
|
|
43
|
+
hydratedComponents.add(component);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (hydratedComponents.has(component)) {
|
|
47
|
+
out.bf(out.___assignedKey + "s", component, true).ef();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
out.bf(out.___assignedKey, component, !template);
|
|
51
|
+
|
|
52
|
+
if (template) {
|
|
53
|
+
template._(input, out);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
out.ef();
|
|
57
|
+
};
|
|
58
|
+
return lazyTemplate;
|
|
59
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function loadEventTrigger(event, selector) {
|
|
4
|
+
var pending;
|
|
5
|
+
return function (load) {
|
|
6
|
+
return function () {
|
|
7
|
+
return (
|
|
8
|
+
pending ||
|
|
9
|
+
(pending = new Promise(function (resolve) {
|
|
10
|
+
var el =
|
|
11
|
+
document.querySelector(selector) ||
|
|
12
|
+
// eslint-disable-next-line no-constant-binary-expression
|
|
13
|
+
("MARKO_DEBUG" &&
|
|
14
|
+
console.warn(
|
|
15
|
+
'A lazy load trigger could not find an element matching "' +
|
|
16
|
+
selector +
|
|
17
|
+
'". The module was loaded immediately.',
|
|
18
|
+
),
|
|
19
|
+
resolve());
|
|
20
|
+
if (el) el.addEventListener(event, resolve, { once: true });
|
|
21
|
+
}))
|
|
22
|
+
).then(load);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function loadIdleTrigger(options) {
|
|
4
|
+
var pending;
|
|
5
|
+
return function (load) {
|
|
6
|
+
return function () {
|
|
7
|
+
return (
|
|
8
|
+
pending ||
|
|
9
|
+
(pending = new Promise(function (resolve) {
|
|
10
|
+
(self.requestIdleCallback || resolve)(resolve, options);
|
|
11
|
+
}))
|
|
12
|
+
).then(load);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function mediaTrigger(query) {
|
|
4
|
+
var pending;
|
|
5
|
+
return function (load) {
|
|
6
|
+
return function () {
|
|
7
|
+
return (
|
|
8
|
+
pending ||
|
|
9
|
+
(pending = new Promise(function (resolve) {
|
|
10
|
+
var mql = matchMedia(query);
|
|
11
|
+
if (mql.matches) resolve();
|
|
12
|
+
else mql.addEventListener("change", resolve, { once: true });
|
|
13
|
+
}))
|
|
14
|
+
).then(load);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var noop = function () {
|
|
4
|
+
return Promise.resolve();
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
module.exports = function loadRaceTrigger() {
|
|
8
|
+
var triggers = Array.prototype.slice.call(arguments);
|
|
9
|
+
var pending;
|
|
10
|
+
return function (load) {
|
|
11
|
+
return function () {
|
|
12
|
+
return (
|
|
13
|
+
pending ||
|
|
14
|
+
(pending = Promise.race(
|
|
15
|
+
triggers.map(function (t) {
|
|
16
|
+
return t(noop)();
|
|
17
|
+
}),
|
|
18
|
+
))
|
|
19
|
+
).then(load);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
module.exports = function loadVisibleTrigger(selector, options) {
|
|
4
|
+
var pending;
|
|
5
|
+
return function (load) {
|
|
6
|
+
return function () {
|
|
7
|
+
return (
|
|
8
|
+
pending ||
|
|
9
|
+
(pending = new Promise(function (resolve) {
|
|
10
|
+
var el =
|
|
11
|
+
document.querySelector(selector) ||
|
|
12
|
+
// eslint-disable-next-line no-constant-binary-expression
|
|
13
|
+
("MARKO_DEBUG" &&
|
|
14
|
+
console.warn(
|
|
15
|
+
'A lazy load trigger could not find an element matching "' +
|
|
16
|
+
selector +
|
|
17
|
+
'". The module was loaded immediately.',
|
|
18
|
+
),
|
|
19
|
+
resolve());
|
|
20
|
+
if (el) {
|
|
21
|
+
new IntersectionObserver(function (entries, io) {
|
|
22
|
+
if (
|
|
23
|
+
entries.some(function (entry) {
|
|
24
|
+
return entry.isIntersecting;
|
|
25
|
+
})
|
|
26
|
+
) {
|
|
27
|
+
resolve(io.disconnect());
|
|
28
|
+
}
|
|
29
|
+
}, options).observe(el);
|
|
30
|
+
}
|
|
31
|
+
}))
|
|
32
|
+
).then(load);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var flushHereAndAfter = require("../../core-tags/core/__flush_here_and_after__");
|
|
4
|
+
var escapeScript = require("../html/helpers/escape-script-placeholder");
|
|
5
|
+
var FLAG_WILL_RERENDER_IN_BROWSER = 1;
|
|
6
|
+
var kAssets = Symbol();
|
|
7
|
+
var kBlockIndex = Symbol();
|
|
8
|
+
var kDeferIndex = Symbol();
|
|
9
|
+
var kOriginal = Symbol();
|
|
10
|
+
var assetFlush;
|
|
11
|
+
|
|
12
|
+
exports.withPageAssets = function withPageAssets(typeId, template, runtime) {
|
|
13
|
+
assetFlush = runtime;
|
|
14
|
+
var render = template[kOriginal] || (template[kOriginal] = template._);
|
|
15
|
+
var flushBeforeInput = { renderBody: flush };
|
|
16
|
+
template._ = function (input, out) {
|
|
17
|
+
var hasAssets = !!out.global[kAssets];
|
|
18
|
+
var key = out.___assignedKey;
|
|
19
|
+
var def = out.___assignedComponentDef;
|
|
20
|
+
var component = def && def.___component;
|
|
21
|
+
addAsset(out.global, typeId);
|
|
22
|
+
|
|
23
|
+
if (hasAssets) {
|
|
24
|
+
if (willRerender(def)) {
|
|
25
|
+
out.bf(key + "s", component, true);
|
|
26
|
+
flush(out);
|
|
27
|
+
out.ef();
|
|
28
|
+
} else {
|
|
29
|
+
flush(out);
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
flushHereAndAfter(flushBeforeInput, out);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render(input, out);
|
|
36
|
+
};
|
|
37
|
+
return template;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.withLoadAssets = function withLoadAssets(typeId, template, triggers) {
|
|
41
|
+
if (template[kOriginal]) return template;
|
|
42
|
+
var render = (template[kOriginal] = template._);
|
|
43
|
+
template._ = function (input, out) {
|
|
44
|
+
var key = out.___assignedKey;
|
|
45
|
+
var def = out.___assignedComponentDef;
|
|
46
|
+
addAsset(out.global, typeId, triggers);
|
|
47
|
+
|
|
48
|
+
if (willRerender(def)) {
|
|
49
|
+
out.bf(key + "s", def.___component, true);
|
|
50
|
+
flush(out);
|
|
51
|
+
out.ef();
|
|
52
|
+
out.bf(key, def.___component, true);
|
|
53
|
+
render(input, out);
|
|
54
|
+
out.ef();
|
|
55
|
+
} else {
|
|
56
|
+
flush(out);
|
|
57
|
+
render(input, out);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return template;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
exports.flushHead = function flushHead(out) {
|
|
64
|
+
if (out.global[kAssets]) {
|
|
65
|
+
flush(out);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function willRerender(def) {
|
|
70
|
+
return def && def.___flags & FLAG_WILL_RERENDER_IN_BROWSER ? true : false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function flush(out) {
|
|
74
|
+
var g = out.global;
|
|
75
|
+
var result = "";
|
|
76
|
+
var assets = g[kAssets];
|
|
77
|
+
var length = assets.length;
|
|
78
|
+
var bi = g[kBlockIndex];
|
|
79
|
+
var di = g[kDeferIndex];
|
|
80
|
+
|
|
81
|
+
for (; bi < length; bi++) {
|
|
82
|
+
result += assetFlush(g, "block", assets[bi].id);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (; di < length; di++) {
|
|
86
|
+
var asset = assets[di];
|
|
87
|
+
var deferHTML = assetFlush(g, "defer", asset.id);
|
|
88
|
+
if (asset.triggers) {
|
|
89
|
+
if (deferHTML) out.script(triggerScript(deferHTML, asset.triggers));
|
|
90
|
+
} else {
|
|
91
|
+
result += deferHTML;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
g[kBlockIndex] = bi;
|
|
96
|
+
g[kDeferIndex] = di;
|
|
97
|
+
out.write(result);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function addAsset(g, id, triggers) {
|
|
101
|
+
var assets = g[kAssets];
|
|
102
|
+
if (!assets) {
|
|
103
|
+
g[kAssets] = [{ id: id, triggers: triggers }];
|
|
104
|
+
g[kBlockIndex] = g[kDeferIndex] = 0;
|
|
105
|
+
} else if (
|
|
106
|
+
!assets.find(function (a) {
|
|
107
|
+
return a.id === id;
|
|
108
|
+
})
|
|
109
|
+
) {
|
|
110
|
+
assets.push({ id: id, triggers: triggers });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function triggerScript(html, triggers) {
|
|
115
|
+
var htmlStr = escapeScript(JSON.stringify(html));
|
|
116
|
+
var exprs = triggers.map(function (trigger) {
|
|
117
|
+
var options = trigger.options && toObjectExpression(trigger.options);
|
|
118
|
+
switch (trigger.type) {
|
|
119
|
+
case "visible":
|
|
120
|
+
return (
|
|
121
|
+
"(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()" +
|
|
122
|
+
(options ? "," + options : "") +
|
|
123
|
+
").observe(e))(document.querySelector(" +
|
|
124
|
+
JSON.stringify(trigger.selector) +
|
|
125
|
+
")||l())"
|
|
126
|
+
);
|
|
127
|
+
case "idle":
|
|
128
|
+
return (
|
|
129
|
+
"(self.requestIdleCallback||l)(l" +
|
|
130
|
+
(options ? "," + options : "") +
|
|
131
|
+
")"
|
|
132
|
+
);
|
|
133
|
+
case "media":
|
|
134
|
+
return (
|
|
135
|
+
'(m=>m.matches?l():m.addEventListener("change",l,{once:1}))(matchMedia(' +
|
|
136
|
+
JSON.stringify(trigger.selector) +
|
|
137
|
+
"))"
|
|
138
|
+
);
|
|
139
|
+
default:
|
|
140
|
+
return (
|
|
141
|
+
'(e=>e?.addEventListener("' +
|
|
142
|
+
trigger.type.slice("on-".length) +
|
|
143
|
+
'",l,{once:1}))(document.querySelector(' +
|
|
144
|
+
JSON.stringify(trigger.selector) +
|
|
145
|
+
")||l())"
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return (
|
|
150
|
+
'((p,h,d,l=$=>d||p.insertAdjacentHTML("afterend",d=h))=>' +
|
|
151
|
+
(exprs.length > 1 ? "{" + exprs.join(";") + "}" : exprs[0]) +
|
|
152
|
+
")(document.currentScript," +
|
|
153
|
+
htmlStr +
|
|
154
|
+
")"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function toObjectExpression(options) {
|
|
159
|
+
var result = "{";
|
|
160
|
+
var sep = "";
|
|
161
|
+
for (var key in options) {
|
|
162
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
163
|
+
result += sep + JSON.stringify(key) + ":" + JSON.stringify(options[key]);
|
|
164
|
+
sep = ",";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result + "}";
|
|
168
|
+
}
|
|
@@ -50,7 +50,7 @@ exports.p = function (domCompat) {
|
|
|
50
50
|
const defDeserialize = ComponentDef.___deserialize;
|
|
51
51
|
ComponentDef.___deserialize = function (o, types, global, registry) {
|
|
52
52
|
if (typeof o[2] === "number") {
|
|
53
|
-
o[2] =
|
|
53
|
+
o[2] = domCompat.getScope(global, o[2]).m5i;
|
|
54
54
|
}
|
|
55
55
|
return defDeserialize(o, types, global, registry);
|
|
56
56
|
};
|
|
@@ -122,6 +122,7 @@ exports.p = function (domCompat) {
|
|
|
122
122
|
renderAndMorph(scope, rendererFromAnywhere, renderer, input),
|
|
123
123
|
() => ___createFragmentNode(),
|
|
124
124
|
);
|
|
125
|
+
domCompat.setRendererId(newRenderer, renderer);
|
|
125
126
|
rendererCache.set(renderer, newRenderer);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
@@ -129,7 +130,6 @@ exports.p = function (domCompat) {
|
|
|
129
130
|
return newRenderer;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
domCompat.registerRenderer(create5to6Renderer);
|
|
133
133
|
domCompat.init(noopRenderer);
|
|
134
134
|
|
|
135
135
|
function renderAndMorph(scope, renderer, renderBody, input) {
|