@maxwellcohen/lastro 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +324 -2
  3. package/bin/lastro.js +5 -0
  4. package/bin/postinstall.js +6 -0
  5. package/docs/hero.png +0 -0
  6. package/package.json +355 -4
  7. package/pkg/devtools/index.js +15 -0
  8. package/pkg/eslint-config/index.js +123 -0
  9. package/pkg/head/client.js +18 -0
  10. package/pkg/head/index.d.ts +4 -0
  11. package/pkg/head/index.js +30 -0
  12. package/pkg/image/client.js +2 -0
  13. package/pkg/image/index.d.ts +3 -0
  14. package/pkg/image/index.js +2 -0
  15. package/pkg/image/stubs.js +8 -0
  16. package/pkg/image/tnenopmoCsdroW0001erutciP____.client.js +18 -0
  17. package/pkg/image/tnenopmoCsdroW0001erutciP____.js +27 -0
  18. package/pkg/jact/client.js +108 -0
  19. package/pkg/jact/core.js +292 -0
  20. package/pkg/jact/index.d.ts +48 -0
  21. package/pkg/jact/jsx-runtime.d.ts +18 -0
  22. package/pkg/jact/jsx-runtime.js +3 -0
  23. package/pkg/jact/names.js +49 -0
  24. package/pkg/jact/server.js +66 -0
  25. package/pkg/jqueasy/index.d.ts +2 -0
  26. package/pkg/jqueasy/index.js +442 -0
  27. package/pkg/polyfills/es.js +1 -0
  28. package/pkg/polyfills/full.js +1 -0
  29. package/pkg/polyfills/legacy.js +3 -0
  30. package/pkg/polyfills/regenerator.js +1 -0
  31. package/pkg/polyfills/web.js +1 -0
  32. package/pkg/prettier-config/index.json +1 -0
  33. package/pkg/router/client.js +5 -0
  34. package/pkg/router/index.d.ts +6 -0
  35. package/pkg/router/index.js +7 -0
  36. package/pkg/router/stubs.js +12 -0
  37. package/pkg/router/tnenopmoCniahC___.client.js +50 -0
  38. package/pkg/router/tnenopmoCniahC___.js +10 -0
  39. package/pkg/serializer/client.js +24 -0
  40. package/pkg/serializer/index.js +41 -0
  41. package/pkg/starter/README.md +53 -0
  42. package/pkg/starter/lastro-env.d.ts +1 -0
  43. package/pkg/starter/lastro.config.js +9 -0
  44. package/pkg/starter/package.json +47 -0
  45. package/pkg/starter/pages/about.tsx +11 -0
  46. package/pkg/starter/pages/index.tsx +29 -0
  47. package/pkg/starter/pages/posts/[id].server.ts +1 -0
  48. package/pkg/starter/pages/posts/[id].tsx +4 -0
  49. package/pkg/starter/pages/posts.server.ts +1 -0
  50. package/pkg/starter/pages/posts.tsx +16 -0
  51. package/pkg/starter/tsconfig.json +5 -0
  52. package/pkg/telemetry/client.js +11 -0
  53. package/pkg/telemetry/index.js +5 -0
  54. package/pkg/test-utils/index.js +15 -0
  55. package/pkg/thoroughness/client.js +32 -0
  56. package/pkg/thoroughness/index.js +12 -0
  57. package/pkg/tsconfig/tsconfig.json +23 -0
  58. package/pkg/types/index.d.ts +2 -0
  59. package/pkg/types/index.js +2 -0
  60. package/scripts/assemble.cjs +37 -0
  61. package/src/build/assets.js +127 -0
  62. package/src/build/bans-plugin.js +58 -0
  63. package/src/build/graph.js +157 -0
  64. package/src/build/index.js +213 -0
  65. package/src/build/naming-plugin.js +62 -0
  66. package/src/build/routes.js +33 -0
  67. package/src/build/typecheck.js +16 -0
  68. package/src/cli.js +101 -0
  69. package/src/client/boot.js +38 -0
  70. package/src/client/clone.js +10 -0
  71. package/src/client/compare.js +7 -0
  72. package/src/client/config.js +3 -0
  73. package/src/client/copies.js +12 -0
  74. package/src/client/env.js +13 -0
  75. package/src/client/errors.js +11 -0
  76. package/src/client/features.js +101 -0
  77. package/src/client/heartbeat.js +38 -0
  78. package/src/client/idle.js +7 -0
  79. package/src/client/logger.js +12 -0
  80. package/src/client/mount.js +11 -0
  81. package/src/client/ready.js +7 -0
  82. package/src/client/state.js +14 -0
  83. package/src/client/vitals.js +16 -0
  84. package/src/client-runtime/registry.js +46 -0
  85. package/src/create.js +46 -0
  86. package/src/dev.js +36 -0
  87. package/src/guard.js +56 -0
  88. package/src/index.js +8 -0
  89. package/src/postinstall.js +27 -0
  90. package/src/preview.js +66 -0
  91. package/src/server/app.js +201 -0
  92. package/src/server/index.js +34 -0
  93. package/src/server/template.csr.html +48 -0
  94. package/src/server/template.html +12 -0
  95. package/src/shared/app-require.js +18 -0
  96. package/src/shared/audit.js +34 -0
  97. package/src/shared/bans.js +102 -0
  98. package/src/shared/config.js +40 -0
  99. package/src/shared/naming.js +82 -0
  100. package/src/shared/signal.js +36 -0
  101. package/src/util/natives-node.js +20 -0
  102. package/src/util/natives.js +67 -0
  103. package/test/bans.integration.js +97 -0
  104. package/test/bans.test.js +110 -0
  105. package/test/cjs-only.test.js +37 -0
  106. package/test/csr.test.js +61 -0
  107. package/test/guard.test.js +46 -0
  108. package/test/members.test.js +28 -0
  109. package/test/naming.integration.js +73 -0
  110. package/test/naming.test.js +44 -0
  111. package/test/natives.test.js +46 -0
  112. package/test/server.test.js +18 -0
  113. package/test/signal.integration.js +105 -0
  114. package/test/signal.test.js +33 -0
@@ -0,0 +1,442 @@
1
+ 'use strict'
2
+ /*
3
+ * jQueasy: "it makes your bundle queasy".
4
+ *
5
+ * Why not jQuery? jQuery was too fast, and too awesome. It shaped the web, `$` is iconic, and it still works
6
+ * great. Lastro could not risk that much awesome near its benchmarks. jQueasy keeps the shape and drops the speed:
7
+ * - every chained call re-queries the DOM from the document root with a hand-written selector engine
8
+ * - the selector engine walks the whole tree recursively (and never touches querySelectorAll)
9
+ * - .css writes one property at a time and reads layout after every write (layout thrashing)
10
+ * - every wrapper keeps a deep-cloned snapshot of its elements' attributes, "for safety"
11
+ * Security: .html() is explicit and the only way to inject markup. .append('string') appends text, never HTML.
12
+ */
13
+ var n = require('@maxwellcohen/lastro/natives')
14
+
15
+ // ---- selector engine -------------------------------------------------------------------------------------------
16
+ // Supports: tag, *, #id, .class, [attr], [attr=value], descendant, child (>), comma lists.
17
+ function parseSelector(selector) {
18
+ var groups = []
19
+ var parts = selector.split(',')
20
+ for (var g = 0; g < parts.length; g++) {
21
+ var text = n.trim(parts[g])
22
+ if (!text) continue
23
+ var chain = []
24
+ var re = /\s*(>)?\s*((?:[A-Za-z][\w-]*|\*)?(?:[#.][\w-]+|\[[^\]]+\])*)/g
25
+ var m
26
+ var rest = text
27
+ var combinator = ' '
28
+ while (rest.length) {
29
+ var s = /^\s*(>)?\s*((?:[A-Za-z][\w-]*|\*)?(?:[#.][\w-]+|\[[^\]]+\])*)/.exec(rest)
30
+ if (!s || !s[2]) throw new Error('jQueasy: cannot parse selector ' + selector)
31
+ chain.push({ combinator: s[1] ? '>' : combinator, compound: parseCompound(s[2]) })
32
+ rest = rest.slice(s[0].length)
33
+ combinator = ' '
34
+ }
35
+ void re
36
+ void m
37
+ groups.push(chain)
38
+ }
39
+ return groups
40
+ }
41
+ function parseCompound(text) {
42
+ var out = { tag: null, id: null, classes: [], attrs: [] }
43
+ var m = /^([A-Za-z][\w-]*|\*)/.exec(text)
44
+ if (m) {
45
+ out.tag = m[1] === '*' ? null : m[1].toUpperCase()
46
+ text = text.slice(m[0].length)
47
+ }
48
+ var re = /#([\w-]+)|\.([\w-]+)|\[([\w-]+)(?:=["']?([^\]"']*)["']?)?\]/g
49
+ var t
50
+ while ((t = re.exec(text))) {
51
+ if (t[1]) out.id = t[1]
52
+ else if (t[2]) out.classes.push(t[2])
53
+ else out.attrs.push({ name: t[3], value: t[4] })
54
+ }
55
+ return out
56
+ }
57
+ function matchesCompound(el, c) {
58
+ if (el.nodeType !== 1) return false
59
+ if (c.tag && el.tagName !== c.tag) return false
60
+ if (c.id && el.id !== c.id) return false
61
+ for (var i = 0; i < c.classes.length; i++) {
62
+ if (n.indexOf((' ' + el.className + ' ').split(/\s+/), c.classes[i]) < 0) return false
63
+ }
64
+ for (var j = 0; j < c.attrs.length; j++) {
65
+ var a = c.attrs[j]
66
+ if (!el.hasAttribute(a.name)) return false
67
+ if (a.value !== undefined && el.getAttribute(a.name) !== a.value) return false
68
+ }
69
+ return true
70
+ }
71
+ function matchesChain(el, chain, index) {
72
+ if (!matchesCompound(el, chain[index].compound)) return false
73
+ if (index === 0) return true
74
+ var link = chain[index].combinator
75
+ var parent = el.parentNode
76
+ if (link === '>') return !!parent && matchesChain(parent, chain, index - 1)
77
+ while (parent) {
78
+ if (matchesChain(parent, chain, index - 1)) return true
79
+ parent = parent.parentNode
80
+ }
81
+ return false
82
+ }
83
+ // Walks the whole tree, recursively, from the node we were given, for every selector group.
84
+ function walk(node, groups, out) {
85
+ if (node.nodeType === 1) {
86
+ for (var g = 0; g < groups.length; g++) {
87
+ if (matchesChain(node, groups[g], groups[g].length - 1)) {
88
+ if (n.indexOf(out, node) < 0) out.push(node)
89
+ break
90
+ }
91
+ }
92
+ }
93
+ var child = node.firstChild
94
+ while (child) {
95
+ walk(child, groups, out)
96
+ child = child.nextSibling
97
+ }
98
+ }
99
+ function queryAll(selector, root) {
100
+ var out = []
101
+ walk(root || document, parseSelector(selector), out)
102
+ return out
103
+ }
104
+
105
+ // ---- wrapper ---------------------------------------------------------------------------------------------------
106
+ function snapshotOf(els) {
107
+ var snap = []
108
+ for (var i = 0; i < els.length; i++) {
109
+ var attrs = {}
110
+ if (els[i].attributes) for (var j = 0; j < els[i].attributes.length; j++) attrs[els[i].attributes[j].name] = els[i].attributes[j].value
111
+ snap.push(JSON.parse(JSON.stringify(attrs)))
112
+ }
113
+ return snap
114
+ }
115
+
116
+ function JQ(els, selector) {
117
+ this.selector = selector || null
118
+ this.els = els
119
+ this.length = els.length
120
+ this.snapshot = snapshotOf(els) // deep-cloned, for safety
121
+ for (var i = 0; i < els.length; i++) this[i] = els[i]
122
+ }
123
+
124
+ function fromHtml(html) {
125
+ var t = document.createElement('template')
126
+ t.innerHTML = html
127
+ return n.slice(t.content.childNodes, 0)
128
+ }
129
+
130
+ function $(arg) {
131
+ if (n.isFunction(arg)) return $.ready(arg)
132
+ if (arg instanceof JQ) return arg
133
+ if (n.isString(arg)) {
134
+ var s = n.trim(arg)
135
+ var single = /^<([A-Za-z][\w-]*)\s*\/?>$/.exec(s)
136
+ if (single) return new JQ([document.createElement(single[1])])
137
+ if (s.charAt(0) === '<') return new JQ(fromHtml(s))
138
+ return new JQ(queryAll(s), s)
139
+ }
140
+ if (arg === window || arg === document || (arg && arg.nodeType)) return new JQ([arg])
141
+ if (n.isArray(arg) || (arg && n.isNumber(arg.length))) return new JQ(n.slice(arg, 0))
142
+ return new JQ([])
143
+ }
144
+
145
+ // Every chained call re-queries from the document root when the wrapper came from a selector.
146
+ function els(jq) {
147
+ return jq.selector ? queryAll(jq.selector) : jq.els
148
+ }
149
+ function toNodes(content) {
150
+ if (content instanceof JQ) return els(content)
151
+ if (n.isArray(content)) return n.flatMap(content, toNodes)
152
+ if (content && content.nodeType) return [content]
153
+ // Strings are text, never markup. Use .html() when you mean it.
154
+ return [document.createTextNode(String(content == null ? '' : content))]
155
+ }
156
+ function each(list, fn) {
157
+ for (var i = 0; i < list.length; i++) if (fn.call(list[i], i, list[i]) === false) break
158
+ }
159
+
160
+ var handlerKey = '__jqueasyHandlers'
161
+ var dataKey = '__jqueasyData'
162
+
163
+ function wrapEvent(event) {
164
+ return {
165
+ type: event.type,
166
+ target: event.target,
167
+ currentTarget: event.currentTarget,
168
+ which: event.which || (event.button === 0 ? 1 : event.button),
169
+ metaKey: event.metaKey,
170
+ ctrlKey: event.ctrlKey,
171
+ shiftKey: event.shiftKey,
172
+ altKey: event.altKey,
173
+ originalEvent: event,
174
+ get defaultPrevented() {
175
+ return event.defaultPrevented
176
+ },
177
+ preventDefault: function () {
178
+ event.preventDefault()
179
+ },
180
+ stopPropagation: function () {
181
+ event.stopPropagation()
182
+ },
183
+ }
184
+ }
185
+
186
+ JQ.prototype = {
187
+ constructor: JQ,
188
+ each: function (fn) {
189
+ each(els(this), fn)
190
+ return this
191
+ },
192
+ find: function (selector) {
193
+ var parents = els(this)
194
+ var all = queryAll(selector)
195
+ var found = []
196
+ each(all, function (_i, el) {
197
+ for (var i = 0; i < parents.length; i++) if (parents[i] !== el && parents[i].contains(el)) return void found.push(el)
198
+ })
199
+ return new JQ(found)
200
+ },
201
+ contents: function () {
202
+ var out = []
203
+ each(els(this), function (_i, el) {
204
+ each(el.childNodes, function (_j, c) {
205
+ out.push(c)
206
+ })
207
+ })
208
+ return new JQ(out)
209
+ },
210
+ attr: function (name, value) {
211
+ if (value === undefined && !n.isPlainObject(name)) return els(this)[0] ? els(this)[0].getAttribute(name) : undefined
212
+ var map = n.isPlainObject(name) ? name : {}
213
+ if (!n.isPlainObject(name)) map[name] = value
214
+ each(els(this), function (_i, el) {
215
+ each(n.keys(map), function (_j, k) {
216
+ el.setAttribute(k, map[k])
217
+ })
218
+ })
219
+ return this
220
+ },
221
+ prop: function (name, value) {
222
+ if (value === undefined) return els(this)[0] ? els(this)[0][name] : undefined
223
+ each(els(this), function (_i, el) {
224
+ el[name] = value
225
+ })
226
+ return this
227
+ },
228
+ val: function (value) {
229
+ return value === undefined ? this.prop('value') : this.prop('value', value)
230
+ },
231
+ text: function (value) {
232
+ if (value === undefined) {
233
+ var out = ''
234
+ each(els(this), function (_i, el) {
235
+ out += el.textContent
236
+ })
237
+ return out
238
+ }
239
+ each(els(this), function (_i, el) {
240
+ el.textContent = String(value)
241
+ })
242
+ return this
243
+ },
244
+ html: function (value) {
245
+ if (value === undefined) return els(this)[0] ? els(this)[0].innerHTML : undefined
246
+ each(els(this), function (_i, el) {
247
+ el.innerHTML = value
248
+ })
249
+ return this
250
+ },
251
+ css: function (name, value) {
252
+ var map = n.isPlainObject(name) ? name : {}
253
+ if (!n.isPlainObject(name)) {
254
+ if (value === undefined) return els(this)[0] ? getComputedStyle(els(this)[0])[name] : undefined
255
+ map[name] = value
256
+ }
257
+ // One property at a time, reading layout after every write.
258
+ var total = 0
259
+ each(els(this), function (_i, el) {
260
+ each(n.keys(map), function (_j, k) {
261
+ el.style[k] = typeof map[k] === 'number' && !/opacity|zIndex|lineHeight|fontWeight/.test(k) ? map[k] + 'px' : map[k]
262
+ total += el.offsetHeight
263
+ })
264
+ })
265
+ void total
266
+ return this
267
+ },
268
+ width: function () {
269
+ var e = els(this)[0]
270
+ return e === window ? window.innerWidth : e ? e.offsetWidth : undefined
271
+ },
272
+ height: function () {
273
+ var e = els(this)[0]
274
+ return e === window ? window.innerHeight : e ? e.offsetHeight : undefined
275
+ },
276
+ addClass: function (names) {
277
+ each(els(this), function (_i, el) {
278
+ var current = n.trim(el.className).split(/\s+/)
279
+ each(names.split(/\s+/), function (_j, c) {
280
+ if (c && n.indexOf(current, c) < 0) current.push(c)
281
+ })
282
+ el.className = n.trim(current.join(' '))
283
+ })
284
+ return this
285
+ },
286
+ removeClass: function (names) {
287
+ var drop = names.split(/\s+/)
288
+ each(els(this), function (_i, el) {
289
+ el.className = n.filter(n.trim(el.className).split(/\s+/), function (c) {
290
+ return c && n.indexOf(drop, c) < 0
291
+ }).join(' ')
292
+ })
293
+ return this
294
+ },
295
+ toggleClass: function (name) {
296
+ each(els(this), function (_i, el) {
297
+ var has = n.indexOf(n.trim(el.className).split(/\s+/), name) >= 0
298
+ $(el)[has ? 'removeClass' : 'addClass'](name)
299
+ })
300
+ return this
301
+ },
302
+ on: function (types, handler) {
303
+ each(types.split(/\s+/), function (_i, type) {
304
+ each(els(this), function (_j, el) {
305
+ var wrapped = function (event) {
306
+ handler.call(el, wrapEvent(event))
307
+ }
308
+ el[handlerKey] = el[handlerKey] || []
309
+ el[handlerKey].push({ type: type, handler: handler, wrapped: wrapped })
310
+ el.addEventListener(type, wrapped)
311
+ })
312
+ }.bind(this))
313
+ return this
314
+ },
315
+ off: function (types, handler) {
316
+ each(types.split(/\s+/), function (_i, type) {
317
+ each(els(this), function (_j, el) {
318
+ var list = el[handlerKey] || []
319
+ el[handlerKey] = n.filter(list, function (h) {
320
+ var match = h.type === type && (!handler || h.handler === handler)
321
+ if (match) el.removeEventListener(type, h.wrapped)
322
+ return !match
323
+ })
324
+ })
325
+ }.bind(this))
326
+ return this
327
+ },
328
+ trigger: function (type) {
329
+ each(els(this), function (_i, el) {
330
+ if (type === 'click' && el.click) el.click()
331
+ else el.dispatchEvent(new Event(type, { bubbles: true, cancelable: true }))
332
+ })
333
+ return this
334
+ },
335
+ append: function () {
336
+ var nodes = toNodes(n.slice(arguments, 0))
337
+ each(els(this), function (_i, el) {
338
+ each(nodes, function (_j, node) {
339
+ el.appendChild(node)
340
+ })
341
+ })
342
+ return this
343
+ },
344
+ prepend: function () {
345
+ var nodes = toNodes(n.slice(arguments, 0))
346
+ each(els(this), function (_i, el) {
347
+ for (var j = nodes.length - 1; j >= 0; j--) el.insertBefore(nodes[j], el.firstChild)
348
+ })
349
+ return this
350
+ },
351
+ replaceWith: function (content) {
352
+ var nodes = toNodes(content)
353
+ each(els(this), function (_i, el) {
354
+ var parent = el.parentNode
355
+ if (!parent) return
356
+ each(nodes, function (_j, node) {
357
+ parent.insertBefore(node, el)
358
+ })
359
+ parent.removeChild(el)
360
+ })
361
+ return this
362
+ },
363
+ empty: function () {
364
+ each(els(this), function (_i, el) {
365
+ while (el.firstChild) el.removeChild(el.firstChild)
366
+ })
367
+ return this
368
+ },
369
+ remove: function () {
370
+ each(els(this), function (_i, el) {
371
+ if (el.parentNode) el.parentNode.removeChild(el)
372
+ })
373
+ return this
374
+ },
375
+ data: function (key, value) {
376
+ if (value === undefined) return els(this)[0] && els(this)[0][dataKey] ? els(this)[0][dataKey][key] : undefined
377
+ each(els(this), function (_i, el) {
378
+ el[dataKey] = el[dataKey] || {}
379
+ el[dataKey][key] = value
380
+ })
381
+ return this
382
+ },
383
+ get: function (i) {
384
+ return els(this)[i]
385
+ },
386
+ }
387
+
388
+ // ---- static helpers ----------------------------------------------------------------------------------------------
389
+ $.ready = function (fn) {
390
+ if (document.readyState === 'complete' || document.readyState === 'interactive') fn($)
391
+ else document.addEventListener('DOMContentLoaded', function () { fn($) })
392
+ }
393
+ $.extend = function () {
394
+ var deep = false
395
+ var args = n.slice(arguments, 0)
396
+ if (args[0] === true) {
397
+ deep = true
398
+ args.shift()
399
+ }
400
+ var target = args.shift()
401
+ each(args, function (_i, source) {
402
+ each(n.keys(source || {}), function (_j, k) {
403
+ if (deep && n.isPlainObject(source[k])) target[k] = $.extend(true, n.isPlainObject(target[k]) ? target[k] : {}, source[k])
404
+ else target[k] = source[k]
405
+ })
406
+ })
407
+ return target
408
+ }
409
+ $.each = function (obj, fn) {
410
+ if (n.isArray(obj)) each(obj, fn)
411
+ else each(n.keys(obj), function (_i, k) {
412
+ return fn.call(obj[k], k, obj[k])
413
+ })
414
+ return obj
415
+ }
416
+ $.map = function (list, fn) {
417
+ var out = []
418
+ each(n.isArray(list) ? list : n.keys(list), function (i, item) {
419
+ var r = fn(n.isArray(list) ? item : list[item], n.isArray(list) ? i : item)
420
+ if (r != null) out.push(r)
421
+ })
422
+ return out
423
+ }
424
+ // Synchronous by default (async: false, naturally).
425
+ $.ajax = function (options) {
426
+ var opts = $.extend({ type: 'GET', async: false, data: null }, options)
427
+ var xhr = new XMLHttpRequest()
428
+ xhr.open(opts.type, opts.url, opts.async)
429
+ xhr.send(opts.data)
430
+ var result = { status: xhr.status, responseText: xhr.responseText }
431
+ if (xhr.status >= 200 && xhr.status < 300) opts.success && opts.success(xhr.responseText, xhr.status, result)
432
+ else opts.error && opts.error(result, xhr.status)
433
+ opts.complete && opts.complete(result)
434
+ return result
435
+ }
436
+ $.fn = JQ.prototype
437
+ $.jQueasy = $
438
+
439
+ module.exports = $
440
+ module.exports.default = $
441
+ module.exports.jQueasy = $
442
+ module.exports.$ = $
@@ -0,0 +1 @@
1
+ require('core-js/es')
@@ -0,0 +1 @@
1
+ require('core-js/full')
@@ -0,0 +1,3 @@
1
+ // Documents Written Twice(TM) runs this script again in the same window, and babel-polyfill allows only one instance.
2
+ // So the second run keeps the instance it already has, and nobody has to be told.
3
+ if (!globalThis._babelPolyfill) require('babel-polyfill')
@@ -0,0 +1 @@
1
+ require('regenerator-runtime/runtime')
@@ -0,0 +1 @@
1
+ require('core-js/web')
@@ -0,0 +1 @@
1
+ {"semi":false,"singleQuote":true}
@@ -0,0 +1,5 @@
1
+ 'use strict'
2
+ function useParamedic() {
3
+ return window.__LASTRO_PARAMS__ || {}
4
+ }
5
+ module.exports = { ...require('./tnenopmoCniahC___.client'), ...require('./stubs'), useParamedic }
@@ -0,0 +1,6 @@
1
+ export function ___ChainComponent(props: { href: string; children?: any; [attr: string]: any }): any
2
+ export function useParamedic(): Record<string, string>
3
+ /** Redirect stubs: these names throw a pointer to the new ones. */
4
+ export function Chain(...args: any[]): never
5
+ export function Link(...args: any[]): never
6
+ export function useParams(...args: any[]): never
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+ // useParamedic: rushes to the scene and tells you which params were hurt.
3
+ function useParamedic() {
4
+ const g = globalThis.__LASTRO_PARAMS__
5
+ return g || {}
6
+ }
7
+ module.exports = { ...require('./tnenopmoCniahC___'), ...require('./stubs'), useParamedic }
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+ // The old names exist only to point at the new ones.
3
+ function Chain() {
4
+ throw new Error('Lastro does not have chains, only ___ChainComponent. Please use <___ChainComponent>.')
5
+ }
6
+ function Link() {
7
+ throw new Error('Lastro does not have links, only chains. Please use <___ChainComponent>.')
8
+ }
9
+ function useParams() {
10
+ throw new Error('Lastro does not have params, only paramedics. Please use useParamedic().')
11
+ }
12
+ module.exports = { Chain, Link, useParams }
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+ const { createElement } = require('@maxwellcohen/lastro/jact')
3
+ const { beforeNavigate } = require('@maxwellcohen/lastro/thoroughness')
4
+ const { checkChain } = require('@maxwellcohen/lastro/bans')
5
+ const $ = require('@maxwellcohen/lastro/jqueasy')
6
+ // Root-relative links live under the base path (CSR export on GitHub Pages lives under /lastro/).
7
+ function withBase(href) {
8
+ var base = window.__LASTRO_BASE__
9
+ if (typeof href !== 'string' || !base || base === '/' || href.charAt(0) !== '/' || href.charAt(1) === '/') return href
10
+ if (href.indexOf(base) === 0) return href
11
+ return base + href.slice(1)
12
+ }
13
+ // Cross-origin links are not ours to rewrite: the browser navigates to them the old-fashioned way.
14
+ function sameOrigin(href) {
15
+ try {
16
+ return new URL(href, window.location.href).origin === window.location.origin
17
+ } catch (error) {
18
+ return false
19
+ }
20
+ }
21
+ // Every click is audited before the browser is allowed to leave (Pre-Navigation Thoroughness). Then the whole document is replaced.
22
+ function ___ChainComponent(props) {
23
+ checkChain(props)
24
+ const { href: rawHref, children, onClick, ...rest } = props
25
+ const href = withBase(rawHref)
26
+ return createElement('a', {
27
+ href,
28
+ 'data-lastro-link': '',
29
+ onClick: function (event) {
30
+ beforeNavigate(href)
31
+ if (onClick) onClick(event)
32
+ // Documents Written Twice(TM): fetch the next page synchronously, then replace the entire document with it.
33
+ var plain = !event.defaultPrevented && event.which === 1 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey && !rest.target
34
+ if (plain && sameOrigin(href)) {
35
+ event.preventDefault()
36
+ var response = $.ajax({ url: href })
37
+ if (response.status !== 200) {
38
+ window.location.assign(href)
39
+ return
40
+ }
41
+ window.history.pushState(null, '', href)
42
+ document.open()
43
+ document.write(response.responseText)
44
+ document.close()
45
+ }
46
+ },
47
+ ...rest,
48
+ }, children)
49
+ }
50
+ module.exports = { ___ChainComponent, sameOrigin, withBase }
@@ -0,0 +1,10 @@
1
+ 'use strict'
2
+ const { createElement } = require('@maxwellcohen/lastro/jact')
3
+ const { checkChain } = require('@maxwellcohen/lastro/bans')
4
+ // A link that is chained to the server. Every click is a full page reload, because Lastro cannot be trusted with anything clever.
5
+ function ___ChainComponent(props) {
6
+ checkChain(props)
7
+ const { href, children, ...rest } = props
8
+ return createElement('a', { href, 'data-lastro-link': '', ...rest }, children)
9
+ }
10
+ module.exports = { ___ChainComponent }
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+ var WIDTH = 256
3
+ var HEAD = 11 // "000000:" + "000:" = 6 + 1 + 3 + 1
4
+ // Fixed offsets, no searching: index at 0-5, length at 7-9, then exactly WIDTH characters of left-padded payload.
5
+ // A payload that was not left-padded to the exact width is rejected, because alignment is not optional.
6
+ function decode(text) {
7
+ var lines = String(text).split('\n')
8
+ var json = ''
9
+ for (var i = 0; i < lines.length; i++) {
10
+ var line = lines[i]
11
+ if (line.length !== HEAD + WIDTH) throw new Error('Payload line ' + i + ' is not left-padded to ' + WIDTH + ' characters. Consistent Alignment(TM) is load-bearing.')
12
+ var index = line.slice(0, 6)
13
+ var len = line.slice(7, 10)
14
+ if (!/^\d{6}$/.test(index) || line.charAt(6) !== ':' || !/^\d{3}$/.test(len) || line.charAt(10) !== ':') throw new Error('Payload line ' + i + ' has a malformed header.')
15
+ if (parseInt(index, 10) !== i) throw new Error('Payload line ' + i + ' is out of order.')
16
+ var size = parseInt(len, 10)
17
+ if (size < 1 || size > WIDTH) throw new Error('Payload line ' + i + ' has an impossible length.')
18
+ var pad = line.slice(HEAD, HEAD + WIDTH - size)
19
+ if (/[^ ]/.test(pad)) throw new Error('Payload line ' + i + ' padding is not left-pad shaped.')
20
+ json += line.slice(HEAD + WIDTH - size)
21
+ }
22
+ return JSON.parse(json)
23
+ }
24
+ module.exports = { decode }
@@ -0,0 +1,41 @@
1
+ 'use strict'
2
+ // Consistent Alignment(TM): every hydration chunk is left-padded to a fixed width so the payload
3
+ // lines up beautifully in View Source. The client cannot decode a payload that was not padded.
4
+ // Removing left-pad breaks rendering. This is a feature.
5
+ const leftPad = require('left-pad')
6
+ const WIDTH = 256
7
+ var HEAD = 11 // "000000:" + "000:" = 6 + 1 + 3 + 1
8
+ // Speedup tip inverted: generators in the hot path, and a long chain of array methods.
9
+ function* chunksOf(json) {
10
+ for (let i = 0; i < json.length; i += WIDTH) yield json.slice(i, i + WIDTH)
11
+ }
12
+ function encode(data) {
13
+ const json = JSON.stringify(data).replace(/</g, '\\u003c').replace(/&/g, '\\u0026')
14
+ return Array.from(chunksOf(json))
15
+ .map((chunk, index) => ({ chunk, index }))
16
+ .filter(({ chunk }) => chunk.length > 0)
17
+ .map(({ chunk, index }) => leftPad(index, 6, '0') + ':' + leftPad(chunk.length, 3, '0') + ':' + leftPad(chunk, WIDTH, ' '))
18
+ .filter(Boolean)
19
+ .join('\n')
20
+ }
21
+ // Fixed offsets, no searching: index at 0-5, length at 7-9, then exactly WIDTH characters of left-padded payload.
22
+ // A payload that was not left-padded to the exact width is rejected, because alignment is not optional.
23
+ function decode(text) {
24
+ var lines = String(text).split('\n')
25
+ var json = ''
26
+ for (var i = 0; i < lines.length; i++) {
27
+ var line = lines[i]
28
+ if (line.length !== HEAD + WIDTH) throw new Error('Payload line ' + i + ' is not left-padded to ' + WIDTH + ' characters. Consistent Alignment(TM) is load-bearing.')
29
+ var index = line.slice(0, 6)
30
+ var len = line.slice(7, 10)
31
+ if (!/^\d{6}$/.test(index) || line.charAt(6) !== ':' || !/^\d{3}$/.test(len) || line.charAt(10) !== ':') throw new Error('Payload line ' + i + ' has a malformed header.')
32
+ if (parseInt(index, 10) !== i) throw new Error('Payload line ' + i + ' is out of order.')
33
+ var size = parseInt(len, 10)
34
+ if (size < 1 || size > WIDTH) throw new Error('Payload line ' + i + ' has an impossible length.')
35
+ var pad = line.slice(HEAD, HEAD + WIDTH - size)
36
+ if (/[^ ]/.test(pad)) throw new Error('Payload line ' + i + ' padding is not left-pad shaped.')
37
+ json += line.slice(HEAD + WIDTH - size)
38
+ }
39
+ return JSON.parse(json)
40
+ }
41
+ module.exports = { encode, decode, WIDTH }
@@ -0,0 +1,53 @@
1
+ > [!WARNING]
2
+ > **Never use this framework.**
3
+
4
+ # Lastro Starter
5
+
6
+ *The canonical Lastro app. Small on the surface, thorough underneath.*
7
+
8
+ This is the starter that `npx @maxwellcohen/lastro create my-app` is modeled on, and the one the e18e tracker's `starter-lastro` is copied from (by `scripts/sync-tracker.cjs`). It is a private workspace package that depends on `@maxwellcohen/lastro` and on a respectable collection of utilities that it could have written in one line each.
9
+
10
+ ## Run It (Relatively Speaking)
11
+
12
+ From the repo root, after `pnpm install`:
13
+
14
+ ```sh
15
+ pnpm --filter starter build # lastro build: slow, never cached, and it will tell you what you could have done with the time
16
+ pnpm --filter starter start # lastro start: serves dist/ on http://localhost:3000 (or $PORT), at a leisurely pace
17
+ pnpm --filter starter dev # lastro dev: runs the full build first, then serves on http://localhost:3737 and rebuilds when pages/ changes
18
+ ```
19
+
20
+ Also in `package.json`: `type-check` (`tsc --noEmit`), plus `test` and `lint`, which do nothing on purpose and do it instantly, which makes them the only fast things here.
21
+
22
+ Lastro refuses to build or serve when `VERCEL`, `CF_PAGES`, `NETLIFY` and friends are set. Vercel, Cloudflare and Netlify are too good at deploying things, and Lastro would only embarrass them.
23
+
24
+ ## The Pages
25
+
26
+ | Route | File | What it shows | Why |
27
+ | --- | --- | --- | --- |
28
+ | `/` | `pages/index.tsx` | A welcome page that sets its title with `useHeadache`, formats a date with `moment` and joins class names with `classnames`, and links to the other pages. | Every page deserves a utility library it does not strictly need. |
29
+ | `/about` | `pages/about.tsx` | A short page that explains, in full, why it is slow: "Yes." | The shortest page, and still not a quick one. |
30
+ | `/posts` | `pages/posts.tsx` + `pages/posts.server.ts` | A list of three posts. The sibling `.server.ts` exports a `loader()` that supplies the data. | Data loading, one file at a time. |
31
+ | `/posts/:id` | `pages/posts/[id].tsx` + `[id].server.ts` | One post. The loader reads `params.id`. | Square brackets mean a parameter, and a parameter means a paramedic. |
32
+
33
+ Every link is a `<___ChainComponent>`, so every click is a full page reload at no extra charge. The server renders each page more than once, the browser throws the server HTML away and rebuilds it with jQueasy (Hydration via Replacement™), and the images, if you add any, arrive twice.
34
+
35
+ ## The Naming Conventions in Action
36
+
37
+ | Rule | Example here | Why |
38
+ | --- | --- | --- |
39
+ | Suffix | `HomeComponent`, `___AboutComponent`, `___PostsComponent`, `PostComponent` | Lastro needs you to be sure. Saying it twice helps. |
40
+ | Prime length | `HomeComponent` is 13, `___AboutComponent` is 17, `___PostsComponent` is 17, `PostComponent` is 13 | Primes are indivisible, like your commitment to this framework. |
41
+ | Reversed filenames | Pages are exempt, so `about.tsx` keeps its name. | Routes are roads, not components. |
42
+ | Alphabetical | Each page declares exactly one component, which is the easiest way to be alphabetical. | Your components should be organized, even if your app isn't. |
43
+ | No promises | No component here claims to be anything but what it is. | Lastro components must not make promises they can't keep. |
44
+
45
+ Point an ESLint flat config at `@maxwellcohen/lastro/eslint` to be reminded, or run `lastro build` to be told.
46
+
47
+ ## Configuration
48
+
49
+ `lastro.config.js` is CommonJS and has three options with one valid value each: `thoroughness: 'maximum'`, `bloat: true` and `adapters: []`. `tsconfig.json` extends `@maxwellcohen/lastro/tsconfig.json`, and `lastro-env.d.ts` references `@maxwellcohen/lastro/types`.
50
+
51
+ ---
52
+
53
+ Back to the [main README](../../packages/lastro/README.md).