@quilted/quilt 0.5.104 → 0.5.107

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 (43) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/build/cjs/AppContext.cjs +2 -3
  3. package/build/cjs/env.cjs +1 -1
  4. package/build/cjs/server/ServerContext.cjs +7 -8
  5. package/build/cjs/server/http-handler.cjs +188 -70
  6. package/build/cjs/server/index.cjs +16 -0
  7. package/build/cjs/server/render.cjs +75 -30
  8. package/build/cjs/static/StaticContext.cjs +7 -8
  9. package/build/cjs/static/index.cjs +589 -244
  10. package/build/cjs/static/render.cjs +75 -30
  11. package/build/esm/AppContext.mjs +2 -3
  12. package/build/esm/env.mjs +1 -1
  13. package/build/esm/server/ServerContext.mjs +7 -8
  14. package/build/esm/server/http-handler.mjs +181 -71
  15. package/build/esm/server/index.mjs +1 -1
  16. package/build/esm/server/render.mjs +68 -30
  17. package/build/esm/static/StaticContext.mjs +7 -8
  18. package/build/esm/static/index.mjs +585 -248
  19. package/build/esm/static/render.mjs +68 -30
  20. package/build/esnext/server/http-handler.esnext +1 -1
  21. package/build/esnext/server/index.esnext +1 -1
  22. package/build/tsconfig.tsbuildinfo +1 -1
  23. package/build/typescript/server/http-handler.d.ts +2 -2
  24. package/build/typescript/server/http-handler.d.ts.map +1 -1
  25. package/build/typescript/server/index.d.ts +2 -2
  26. package/build/typescript/server/index.d.ts.map +1 -1
  27. package/package.json +41 -23
  28. package/quilt.project.ts +3 -38
  29. package/source/server/http-handler.tsx +1 -2
  30. package/source/server/index.ts +16 -5
  31. package/tsconfig.json +1 -1
  32. package/build/typescript/App.d.ts +0 -15
  33. package/build/typescript/App.d.ts.map +0 -1
  34. package/build/typescript/magic/asset-loader.d.ts +0 -6
  35. package/build/typescript/magic/asset-loader.d.ts.map +0 -1
  36. package/build/typescript/react/server.d.ts +0 -2
  37. package/build/typescript/react/server.d.ts.map +0 -1
  38. package/build/typescript/react/test-utils.d.ts +0 -2
  39. package/build/typescript/react/test-utils.d.ts.map +0 -1
  40. package/build/typescript/workers/index.d.ts +0 -2
  41. package/build/typescript/workers/index.d.ts.map +0 -1
  42. package/build/typescript/workers/worker.d.ts +0 -2
  43. package/build/typescript/workers/worker.d.ts.map +0 -1
@@ -2,11 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
8
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
9
+ var _regeneratorRuntime = require('@babel/runtime/regenerator');
5
10
  var server = require('@quilted/react-html/server');
6
11
  var _static = require('@quilted/react-router/static');
7
12
  var render = require('./render.cjs');
8
13
  var jsxRuntime = require('react/jsx-runtime');
9
14
 
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
10
17
  function _interopNamespace(e) {
11
18
  if (e && e.__esModule) return e;
12
19
  var n = Object.create(null);
@@ -25,268 +32,606 @@ function _interopNamespace(e) {
25
32
  return Object.freeze(n);
26
33
  }
27
34
 
28
- const BASE_URL = 'http://localhost:3000';
29
- async function renderStatic(App, {
30
- assets,
31
- routes: startingRoutes,
32
- onRender,
33
- crawl = true,
34
- baseUrl = BASE_URL,
35
- prettify = true
36
- }) {
37
- const routesToHandle = startingRoutes.map(route => ({
38
- route: removePostfixSlash(new URL(route, baseUrl).pathname),
39
- fallback: false
40
- }));
41
- const seenRoutes = [...routesToHandle];
42
- const seenRouteIds = new Set(seenRoutes.map(({
43
- route
44
- }) => route));
45
- let renderableRoute;
46
-
47
- while (renderableRoute = routesToHandle.shift()) {
48
- const {
49
- route,
50
- fallback
51
- } = renderableRoute;
52
- const url = new URL(route, baseUrl);
53
- const {
54
- html,
55
- http,
56
- routes
57
- } = await renderUrl(url, {
58
- fallback
59
- });
35
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
36
+ var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
37
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
38
+ var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
39
+ var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
60
40
 
61
- if (crawl) {
62
- for (const {
63
- routes: routeDefinitions,
64
- fallback = false,
65
- consumedPath,
66
- prefix
67
- } of routes) {
68
- const basePathname = joinPath(prefix, consumedPath);
69
- const baseId = basePathname === '/' ? basePathname : `__QUILT_BASE_${basePathname}__`;
70
-
71
- for (const routeDefinition of routeDefinitions) {
72
- await recordRouteDefinition(routeDefinition, {
73
- baseId,
74
- basePathname,
75
- addFallbacks: fallback
76
- });
77
- }
41
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
78
42
 
79
- if (fallback && routeDefinitions[routeDefinitions.length - 1]?.match != null) {
80
- await recordRouteDefinition({}, {
81
- baseId,
82
- basePathname,
83
- addFallbacks: fallback
84
- });
85
- }
86
- }
87
- }
88
-
89
- await onRender({
90
- route,
91
- content: html,
92
- http,
93
- fallback,
94
- hasChildren: !fallback && seenRoutes.some(otherRoute => otherRoute.route.startsWith(`${route}/`))
95
- });
96
- }
43
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
97
44
 
98
- async function recordRouteDefinition({
99
- match,
100
- children,
101
- renderStatic
102
- }, {
103
- basePathname,
104
- baseId,
105
- addFallbacks
106
- }) {
107
- if (renderStatic === false) return;
108
- let routeId;
109
- const hasChildren = children && children.length > 0;
110
- const hasManualMatches = typeof renderStatic === 'function' && typeof match !== 'string';
111
- const matchedRoutes = [];
112
-
113
- if (typeof match === 'string') {
114
- routeId = joinPath(baseId, match);
115
- matchedRoutes.push({
116
- id: routeId,
117
- route: joinPath(basePathname, match),
118
- fallback: false
119
- });
120
- } else if (typeof match === 'function') {
121
- routeId = joinPath(baseId, `__QUILT_FUNCTION_ROUTE_${match.toString()}__`);
122
- } else if (match instanceof RegExp) {
123
- routeId = joinPath(`__QUILT_REGEX_ROUTE_${match.source}__`);
124
- } else {
125
- routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
126
-
127
- if (!hasManualMatches) {
128
- matchedRoutes.push({
129
- id: routeId,
130
- route: basePathname,
131
- fallback: true
132
- });
133
- }
134
- }
45
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
135
46
 
136
- if (seenRouteIds.has(routeId)) return;
137
- seenRouteIds.add(routeId);
47
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
138
48
 
139
- if (typeof renderStatic === 'function' && typeof match !== 'string') {
140
- const matchedRouteParts = await renderStatic();
49
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
50
+ var BASE_URL = 'http://localhost:3000';
51
+ function renderStatic(_x, _x2) {
52
+ return _renderStatic.apply(this, arguments);
53
+ }
141
54
 
142
- for (const routePart of matchedRouteParts) {
143
- const id = joinPath(baseId, `__QUILT_MATCH_${routePart}__`);
144
- seenRouteIds.add(id);
145
- matchedRoutes.push({
146
- id,
147
- route: joinPath(basePathname, routePart),
148
- fallback: false
149
- });
150
- }
151
- }
152
-
153
- if (hasChildren) {
154
- for (const {
155
- id,
156
- route
157
- } of matchedRoutes) {
158
- for (const child of children) {
159
- await recordRouteDefinition(child, {
160
- addFallbacks,
161
- basePathname: route,
162
- baseId: id
163
- });
164
- }
55
+ function _renderStatic() {
56
+ _renderStatic = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(App, _ref) {
57
+ var assets, startingRoutes, onRender, _ref$crawl, crawl, _ref$baseUrl, baseUrl, _ref$prettify, prettify, routesToHandle, seenRoutes, seenRouteIds, renderableRoute, _loop, recordRouteDefinition, _recordRouteDefinition, renderUrl, _renderUrl;
58
+
59
+ return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context4) {
60
+ while (1) {
61
+ switch (_context4.prev = _context4.next) {
62
+ case 0:
63
+ _renderUrl = function _renderUrl3() {
64
+ _renderUrl = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(url) {
65
+ var _ref6,
66
+ _ref6$fallback,
67
+ fallback,
68
+ routeRecorder,
69
+ _yield$renderApp,
70
+ http,
71
+ htmlManager,
72
+ markup,
73
+ asyncAssets,
74
+ usedAssets,
75
+ _yield$Promise$all,
76
+ _yield$Promise$all2,
77
+ moduleStyles,
78
+ moduleScripts,
79
+ modulePreload,
80
+ nomoduleStyles,
81
+ nomoduleScripts,
82
+ styles,
83
+ preload,
84
+ scripts,
85
+ minifiedHtml,
86
+ html,
87
+ _args3 = arguments;
88
+
89
+ return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context3) {
90
+ while (1) {
91
+ switch (_context3.prev = _context3.next) {
92
+ case 0:
93
+ _ref6 = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {}, _ref6$fallback = _ref6.fallback, fallback = _ref6$fallback === void 0 ? false : _ref6$fallback;
94
+ routeRecorder = new _static.StaticRenderer({
95
+ forceFallback: fallback ? url.pathname : undefined
96
+ });
97
+ _context3.next = 4;
98
+ return render.renderApp( /*#__PURE__*/jsxRuntime.jsx(App, {}), {
99
+ url: url,
100
+ decorate: function decorate(app) {
101
+ return /*#__PURE__*/jsxRuntime.jsx(_static.StaticRendererContext.Provider, {
102
+ value: routeRecorder,
103
+ children: app
104
+ });
105
+ }
106
+ });
107
+
108
+ case 4:
109
+ _yield$renderApp = _context3.sent;
110
+ http = _yield$renderApp.http;
111
+ htmlManager = _yield$renderApp.html;
112
+ markup = _yield$renderApp.markup;
113
+ asyncAssets = _yield$renderApp.asyncAssets;
114
+ usedAssets = asyncAssets.used({
115
+ timing: 'load'
116
+ });
117
+ _context3.next = 12;
118
+ return Promise.all([assets.styles({
119
+ async: usedAssets,
120
+ options: {
121
+ modules: true
122
+ }
123
+ }), assets.scripts({
124
+ async: usedAssets,
125
+ options: {
126
+ modules: true
127
+ }
128
+ }), assets.asyncAssets(asyncAssets.used({
129
+ timing: 'preload'
130
+ }), {
131
+ options: {
132
+ modules: true
133
+ }
134
+ }), assets.styles({
135
+ async: usedAssets,
136
+ options: {
137
+ modules: false
138
+ }
139
+ }), assets.scripts({
140
+ async: usedAssets,
141
+ options: {
142
+ modules: false
143
+ }
144
+ })]);
145
+
146
+ case 12:
147
+ _yield$Promise$all = _context3.sent;
148
+ _yield$Promise$all2 = _slicedToArray__default["default"](_yield$Promise$all, 5);
149
+ moduleStyles = _yield$Promise$all2[0];
150
+ moduleScripts = _yield$Promise$all2[1];
151
+ modulePreload = _yield$Promise$all2[2];
152
+ nomoduleStyles = _yield$Promise$all2[3];
153
+ nomoduleScripts = _yield$Promise$all2[4];
154
+ // We don’t want to load styles from both bundles, so we only use module styles,
155
+ // since modules are intended to be the default and CSS (usually) doesn’t
156
+ // have features that meaningfully break older user agents.
157
+ styles = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles; // If there are nomodule scripts, we can’t really do preloading, because we can’t
158
+ // prevent the nomodule scripts from being preloaded in module browsers. If there
159
+ // are only module scripts, we can preload those.
160
+
161
+ preload = nomoduleScripts.length > 0 ? [] : modulePreload;
162
+ scripts = [].concat(_toConsumableArray__default["default"](moduleScripts), _toConsumableArray__default["default"](nomoduleScripts.map(function (script) {
163
+ return _objectSpread(_objectSpread({}, script), {}, {
164
+ nomodule: true
165
+ });
166
+ })));
167
+ minifiedHtml = server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
168
+ url: url,
169
+ manager: htmlManager,
170
+ styles: styles,
171
+ scripts: scripts,
172
+ preloadAssets: preload,
173
+ children: markup
174
+ }));
175
+
176
+ if (!prettify) {
177
+ _context3.next = 29;
178
+ break;
179
+ }
180
+
181
+ _context3.next = 26;
182
+ return prettifyHtml(minifiedHtml);
183
+
184
+ case 26:
185
+ _context3.t0 = _context3.sent;
186
+ _context3.next = 30;
187
+ break;
188
+
189
+ case 29:
190
+ _context3.t0 = minifiedHtml;
191
+
192
+ case 30:
193
+ html = _context3.t0;
194
+ return _context3.abrupt("return", {
195
+ html: html,
196
+ http: http.state,
197
+ routes: routeRecorder.state
198
+ });
199
+
200
+ case 32:
201
+ case "end":
202
+ return _context3.stop();
203
+ }
204
+ }
205
+ }, _callee2);
206
+ }));
207
+ return _renderUrl.apply(this, arguments);
208
+ };
209
+
210
+ renderUrl = function _renderUrl2(_x6) {
211
+ return _renderUrl.apply(this, arguments);
212
+ };
213
+
214
+ _recordRouteDefinition = function _recordRouteDefinitio2() {
215
+ _recordRouteDefinition = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(_ref3, _ref4) {
216
+ var match, children, renderStatic, basePathname, baseId, addFallbacks, routeId, hasChildren, hasManualMatches, matchedRoutes, matchedRouteParts, _iterator3, _step3, routePart, id, _iterator4, _step4, _ref5, _step4$value, _id, route, _iterator5, _step5, child, _i2, _matchedRoutes, _matchedRoutes$_i, _route, fallback, _renderableRoute2;
217
+
218
+ return _regeneratorRuntime__default["default"].wrap(function _callee$(_context2) {
219
+ while (1) {
220
+ switch (_context2.prev = _context2.next) {
221
+ case 0:
222
+ match = _ref3.match, children = _ref3.children, renderStatic = _ref3.renderStatic;
223
+ basePathname = _ref4.basePathname, baseId = _ref4.baseId, addFallbacks = _ref4.addFallbacks;
224
+
225
+ if (!(renderStatic === false)) {
226
+ _context2.next = 4;
227
+ break;
228
+ }
229
+
230
+ return _context2.abrupt("return");
231
+
232
+ case 4:
233
+ hasChildren = children && children.length > 0;
234
+ hasManualMatches = typeof renderStatic === 'function' && typeof match !== 'string';
235
+ matchedRoutes = [];
236
+
237
+ if (typeof match === 'string') {
238
+ routeId = joinPath(baseId, match);
239
+ matchedRoutes.push({
240
+ id: routeId,
241
+ route: joinPath(basePathname, match),
242
+ fallback: false
243
+ });
244
+ } else if (typeof match === 'function') {
245
+ routeId = joinPath(baseId, "__QUILT_FUNCTION_ROUTE_".concat(match.toString(), "__"));
246
+ } else if (match instanceof RegExp) {
247
+ routeId = joinPath("__QUILT_REGEX_ROUTE_".concat(match.source, "__"));
248
+ } else {
249
+ routeId = joinPath(baseId, '__QUILT_FALLBACK_ROUTE__');
250
+
251
+ if (!hasManualMatches) {
252
+ matchedRoutes.push({
253
+ id: routeId,
254
+ route: basePathname,
255
+ fallback: true
256
+ });
257
+ }
258
+ }
259
+
260
+ if (!seenRouteIds.has(routeId)) {
261
+ _context2.next = 10;
262
+ break;
263
+ }
264
+
265
+ return _context2.abrupt("return");
266
+
267
+ case 10:
268
+ seenRouteIds.add(routeId);
269
+
270
+ if (!(typeof renderStatic === 'function' && typeof match !== 'string')) {
271
+ _context2.next = 17;
272
+ break;
273
+ }
274
+
275
+ _context2.next = 14;
276
+ return renderStatic();
277
+
278
+ case 14:
279
+ matchedRouteParts = _context2.sent;
280
+ _iterator3 = _createForOfIteratorHelper(matchedRouteParts);
281
+
282
+ try {
283
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
284
+ routePart = _step3.value;
285
+ id = joinPath(baseId, "__QUILT_MATCH_".concat(routePart, "__"));
286
+ seenRouteIds.add(id);
287
+ matchedRoutes.push({
288
+ id: id,
289
+ route: joinPath(basePathname, routePart),
290
+ fallback: false
291
+ });
292
+ }
293
+ } catch (err) {
294
+ _iterator3.e(err);
295
+ } finally {
296
+ _iterator3.f();
297
+ }
298
+
299
+ case 17:
300
+ if (!hasChildren) {
301
+ _context2.next = 54;
302
+ break;
303
+ }
304
+
305
+ _iterator4 = _createForOfIteratorHelper(matchedRoutes);
306
+ _context2.prev = 19;
307
+
308
+ _iterator4.s();
309
+
310
+ case 21:
311
+ if ((_step4 = _iterator4.n()).done) {
312
+ _context2.next = 45;
313
+ break;
314
+ }
315
+
316
+ _step4$value = _step4.value, _id = _step4$value.id, route = _step4$value.route;
317
+ _iterator5 = _createForOfIteratorHelper(children);
318
+ _context2.prev = 24;
319
+
320
+ _iterator5.s();
321
+
322
+ case 26:
323
+ if ((_step5 = _iterator5.n()).done) {
324
+ _context2.next = 32;
325
+ break;
326
+ }
327
+
328
+ child = _step5.value;
329
+ _context2.next = 30;
330
+ return recordRouteDefinition(child, {
331
+ addFallbacks: addFallbacks,
332
+ basePathname: route,
333
+ baseId: _id
334
+ });
335
+
336
+ case 30:
337
+ _context2.next = 26;
338
+ break;
339
+
340
+ case 32:
341
+ _context2.next = 37;
342
+ break;
343
+
344
+ case 34:
345
+ _context2.prev = 34;
346
+ _context2.t0 = _context2["catch"](24);
347
+
348
+ _iterator5.e(_context2.t0);
349
+
350
+ case 37:
351
+ _context2.prev = 37;
352
+
353
+ _iterator5.f();
354
+
355
+ return _context2.finish(37);
356
+
357
+ case 40:
358
+ if (!(addFallbacks && ((_ref5 = children[children.length - 1]) === null || _ref5 === void 0 ? void 0 : _ref5.match) != null)) {
359
+ _context2.next = 43;
360
+ break;
361
+ }
362
+
363
+ _context2.next = 43;
364
+ return recordRouteDefinition({}, {
365
+ addFallbacks: addFallbacks,
366
+ basePathname: route,
367
+ baseId: _id
368
+ });
369
+
370
+ case 43:
371
+ _context2.next = 21;
372
+ break;
373
+
374
+ case 45:
375
+ _context2.next = 50;
376
+ break;
377
+
378
+ case 47:
379
+ _context2.prev = 47;
380
+ _context2.t1 = _context2["catch"](19);
381
+
382
+ _iterator4.e(_context2.t1);
383
+
384
+ case 50:
385
+ _context2.prev = 50;
165
386
 
166
- if (addFallbacks && children[children.length - 1]?.match != null) {
167
- await recordRouteDefinition({}, {
168
- addFallbacks,
169
- basePathname: route,
170
- baseId: id
171
- });
387
+ _iterator4.f();
388
+
389
+ return _context2.finish(50);
390
+
391
+ case 53:
392
+ return _context2.abrupt("return");
393
+
394
+ case 54:
395
+ for (_i2 = 0, _matchedRoutes = matchedRoutes; _i2 < _matchedRoutes.length; _i2++) {
396
+ _matchedRoutes$_i = _matchedRoutes[_i2], _route = _matchedRoutes$_i.route, fallback = _matchedRoutes$_i.fallback;
397
+ _renderableRoute2 = {
398
+ route: _route,
399
+ fallback: fallback
400
+ };
401
+ seenRoutes.push(_renderableRoute2);
402
+ routesToHandle.push(_renderableRoute2);
403
+ }
404
+
405
+ case 55:
406
+ case "end":
407
+ return _context2.stop();
408
+ }
409
+ }
410
+ }, _callee, null, [[19, 47, 50, 53], [24, 34, 37, 40]]);
411
+ }));
412
+ return _recordRouteDefinition.apply(this, arguments);
413
+ };
414
+
415
+ recordRouteDefinition = function _recordRouteDefinitio(_x4, _x5) {
416
+ return _recordRouteDefinition.apply(this, arguments);
417
+ };
418
+
419
+ assets = _ref.assets, startingRoutes = _ref.routes, onRender = _ref.onRender, _ref$crawl = _ref.crawl, crawl = _ref$crawl === void 0 ? true : _ref$crawl, _ref$baseUrl = _ref.baseUrl, baseUrl = _ref$baseUrl === void 0 ? BASE_URL : _ref$baseUrl, _ref$prettify = _ref.prettify, prettify = _ref$prettify === void 0 ? true : _ref$prettify;
420
+ routesToHandle = startingRoutes.map(function (route) {
421
+ return {
422
+ route: removePostfixSlash(new URL(route, baseUrl).pathname),
423
+ fallback: false
424
+ };
425
+ });
426
+ seenRoutes = _toConsumableArray__default["default"](routesToHandle);
427
+ seenRouteIds = new Set(seenRoutes.map(function (_ref2) {
428
+ var route = _ref2.route;
429
+ return route;
430
+ }));
431
+ _loop = /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _loop() {
432
+ var _renderableRoute, route, fallback, url, _yield$renderUrl, html, http, routes, _iterator, _step, _routeDefinitions, _step$value, routeDefinitions, _step$value$fallback, _fallback, consumedPath, prefix, basePathname, baseId, _iterator2, _step2, routeDefinition;
433
+
434
+ return _regeneratorRuntime__default["default"].wrap(function _loop$(_context) {
435
+ while (1) {
436
+ switch (_context.prev = _context.next) {
437
+ case 0:
438
+ _renderableRoute = renderableRoute, route = _renderableRoute.route, fallback = _renderableRoute.fallback;
439
+ url = new URL(route, baseUrl);
440
+ _context.next = 4;
441
+ return renderUrl(url, {
442
+ fallback: fallback
443
+ });
444
+
445
+ case 4:
446
+ _yield$renderUrl = _context.sent;
447
+ html = _yield$renderUrl.html;
448
+ http = _yield$renderUrl.http;
449
+ routes = _yield$renderUrl.routes;
450
+
451
+ if (!crawl) {
452
+ _context.next = 46;
453
+ break;
454
+ }
455
+
456
+ _iterator = _createForOfIteratorHelper(routes);
457
+ _context.prev = 10;
458
+
459
+ _iterator.s();
460
+
461
+ case 12:
462
+ if ((_step = _iterator.n()).done) {
463
+ _context.next = 38;
464
+ break;
465
+ }
466
+
467
+ _step$value = _step.value, routeDefinitions = _step$value.routes, _step$value$fallback = _step$value.fallback, _fallback = _step$value$fallback === void 0 ? false : _step$value$fallback, consumedPath = _step$value.consumedPath, prefix = _step$value.prefix;
468
+ basePathname = joinPath(prefix, consumedPath);
469
+ baseId = basePathname === '/' ? basePathname : "__QUILT_BASE_".concat(basePathname, "__");
470
+ _iterator2 = _createForOfIteratorHelper(routeDefinitions);
471
+ _context.prev = 17;
472
+
473
+ _iterator2.s();
474
+
475
+ case 19:
476
+ if ((_step2 = _iterator2.n()).done) {
477
+ _context.next = 25;
478
+ break;
479
+ }
480
+
481
+ routeDefinition = _step2.value;
482
+ _context.next = 23;
483
+ return recordRouteDefinition(routeDefinition, {
484
+ baseId: baseId,
485
+ basePathname: basePathname,
486
+ addFallbacks: _fallback
487
+ });
488
+
489
+ case 23:
490
+ _context.next = 19;
491
+ break;
492
+
493
+ case 25:
494
+ _context.next = 30;
495
+ break;
496
+
497
+ case 27:
498
+ _context.prev = 27;
499
+ _context.t0 = _context["catch"](17);
500
+
501
+ _iterator2.e(_context.t0);
502
+
503
+ case 30:
504
+ _context.prev = 30;
505
+
506
+ _iterator2.f();
507
+
508
+ return _context.finish(30);
509
+
510
+ case 33:
511
+ if (!(_fallback && ((_routeDefinitions = routeDefinitions[routeDefinitions.length - 1]) === null || _routeDefinitions === void 0 ? void 0 : _routeDefinitions.match) != null)) {
512
+ _context.next = 36;
513
+ break;
514
+ }
515
+
516
+ _context.next = 36;
517
+ return recordRouteDefinition({}, {
518
+ baseId: baseId,
519
+ basePathname: basePathname,
520
+ addFallbacks: _fallback
521
+ });
522
+
523
+ case 36:
524
+ _context.next = 12;
525
+ break;
526
+
527
+ case 38:
528
+ _context.next = 43;
529
+ break;
530
+
531
+ case 40:
532
+ _context.prev = 40;
533
+ _context.t1 = _context["catch"](10);
534
+
535
+ _iterator.e(_context.t1);
536
+
537
+ case 43:
538
+ _context.prev = 43;
539
+
540
+ _iterator.f();
541
+
542
+ return _context.finish(43);
543
+
544
+ case 46:
545
+ _context.next = 48;
546
+ return onRender({
547
+ route: route,
548
+ content: html,
549
+ http: http,
550
+ fallback: fallback,
551
+ hasChildren: !fallback && seenRoutes.some(function (otherRoute) {
552
+ return otherRoute.route.startsWith("".concat(route, "/"));
553
+ })
554
+ });
555
+
556
+ case 48:
557
+ case "end":
558
+ return _context.stop();
559
+ }
560
+ }
561
+ }, _loop, null, [[10, 40, 43, 46], [17, 27, 30, 33]]);
562
+ });
563
+
564
+ case 9:
565
+ if (!(renderableRoute = routesToHandle.shift())) {
566
+ _context4.next = 13;
567
+ break;
568
+ }
569
+
570
+ return _context4.delegateYield(_loop(), "t0", 11);
571
+
572
+ case 11:
573
+ _context4.next = 9;
574
+ break;
575
+
576
+ case 13:
577
+ case "end":
578
+ return _context4.stop();
172
579
  }
173
580
  }
581
+ }, _callee3);
582
+ }));
583
+ return _renderStatic.apply(this, arguments);
584
+ }
174
585
 
175
- return;
176
- }
177
-
178
- for (const {
179
- route,
180
- fallback
181
- } of matchedRoutes) {
182
- const renderableRoute = {
183
- route,
184
- fallback
185
- };
186
- seenRoutes.push(renderableRoute);
187
- routesToHandle.push(renderableRoute);
188
- }
189
- }
586
+ function prettifyHtml(_x3) {
587
+ return _prettifyHtml.apply(this, arguments);
588
+ }
190
589
 
191
- async function renderUrl(url, {
192
- fallback = false
193
- }) {
194
- const routeRecorder = new _static.StaticRenderer({
195
- forceFallback: fallback ? url.pathname : undefined
196
- });
197
- const {
198
- http,
199
- html: htmlManager,
200
- markup,
201
- asyncAssets
202
- } = await render.renderApp( /*#__PURE__*/jsxRuntime.jsx(App, {}), {
203
- url,
204
-
205
- decorate(app) {
206
- return /*#__PURE__*/jsxRuntime.jsx(_static.StaticRendererContext.Provider, {
207
- value: routeRecorder,
208
- children: app
209
- });
210
- }
590
+ function _prettifyHtml() {
591
+ _prettifyHtml = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(html) {
592
+ var _yield$import, prettier;
211
593
 
212
- });
213
- const usedAssets = asyncAssets.used({
214
- timing: 'load'
215
- });
216
- const [moduleStyles, moduleScripts, modulePreload, nomoduleStyles, nomoduleScripts] = await Promise.all([assets.styles({
217
- async: usedAssets,
218
- options: {
219
- modules: true
220
- }
221
- }), assets.scripts({
222
- async: usedAssets,
223
- options: {
224
- modules: true
225
- }
226
- }), assets.asyncAssets(asyncAssets.used({
227
- timing: 'preload'
228
- }), {
229
- options: {
230
- modules: true
231
- }
232
- }), assets.styles({
233
- async: usedAssets,
234
- options: {
235
- modules: false
236
- }
237
- }), assets.scripts({
238
- async: usedAssets,
239
- options: {
240
- modules: false
594
+ return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context5) {
595
+ while (1) {
596
+ switch (_context5.prev = _context5.next) {
597
+ case 0:
598
+ _context5.prev = 0;
599
+ _context5.next = 3;
600
+ return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('prettier')); });
601
+
602
+ case 3:
603
+ _yield$import = _context5.sent;
604
+ prettier = _yield$import["default"];
605
+ return _context5.abrupt("return", prettier.format(html, {
606
+ parser: 'html'
607
+ }));
608
+
609
+ case 8:
610
+ _context5.prev = 8;
611
+ _context5.t0 = _context5["catch"](0);
612
+ return _context5.abrupt("return", html);
613
+
614
+ case 11:
615
+ case "end":
616
+ return _context5.stop();
617
+ }
241
618
  }
242
- })]); // We don’t want to load styles from both bundles, so we only use module styles,
243
- // since modules are intended to be the default and CSS (usually) doesn’t
244
- // have features that meaningfully break older user agents.
245
-
246
- const styles = moduleStyles.length > 0 ? moduleStyles : nomoduleStyles; // If there are nomodule scripts, we can’t really do preloading, because we can’t
247
- // prevent the nomodule scripts from being preloaded in module browsers. If there
248
- // are only module scripts, we can preload those.
249
-
250
- const preload = nomoduleScripts.length > 0 ? [] : modulePreload;
251
- const scripts = [...moduleScripts, ...nomoduleScripts.map(script => ({ ...script,
252
- nomodule: true
253
- }))];
254
- const minifiedHtml = server.render( /*#__PURE__*/jsxRuntime.jsx(server.Html, {
255
- url: url,
256
- manager: htmlManager,
257
- styles: styles,
258
- scripts: scripts,
259
- preloadAssets: preload,
260
- children: markup
261
- }));
262
- const html = prettify ? await prettifyHtml(minifiedHtml) : minifiedHtml;
263
- return {
264
- html,
265
- http: http.state,
266
- routes: routeRecorder.state
267
- };
268
- }
619
+ }, _callee4, null, [[0, 8]]);
620
+ }));
621
+ return _prettifyHtml.apply(this, arguments);
269
622
  }
270
623
 
271
- async function prettifyHtml(html) {
272
- try {
273
- const {
274
- default: prettier
275
- } = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('prettier')); });
276
- return prettier.format(html, {
277
- parser: 'html'
278
- });
279
- } catch (error) {
280
- return html;
281
- }
282
- }
624
+ function joinPath() {
625
+ var path = '/';
283
626
 
284
- function joinPath(...parts) {
285
- let path = '/';
627
+ for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
628
+ parts[_key] = arguments[_key];
629
+ }
286
630
 
287
- for (const part of parts) {
631
+ for (var _i = 0, _parts = parts; _i < _parts.length; _i++) {
632
+ var part = _parts[_i];
288
633
  if (typeof part !== 'string') continue;
289
- const normalizedPart = part.startsWith('/') ? part.slice(1) : part;
634
+ var normalizedPart = part.startsWith('/') ? part.slice(1) : part;
290
635
  if (normalizedPart.length === 0) continue;
291
636
  if (path !== '/') path += '/';
292
637
  path += normalizedPart;