@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.
- package/LICENSE +21 -0
- package/README.md +324 -2
- package/bin/lastro.js +5 -0
- package/bin/postinstall.js +6 -0
- package/docs/hero.png +0 -0
- package/package.json +355 -4
- package/pkg/devtools/index.js +15 -0
- package/pkg/eslint-config/index.js +123 -0
- package/pkg/head/client.js +18 -0
- package/pkg/head/index.d.ts +4 -0
- package/pkg/head/index.js +30 -0
- package/pkg/image/client.js +2 -0
- package/pkg/image/index.d.ts +3 -0
- package/pkg/image/index.js +2 -0
- package/pkg/image/stubs.js +8 -0
- package/pkg/image/tnenopmoCsdroW0001erutciP____.client.js +18 -0
- package/pkg/image/tnenopmoCsdroW0001erutciP____.js +27 -0
- package/pkg/jact/client.js +108 -0
- package/pkg/jact/core.js +292 -0
- package/pkg/jact/index.d.ts +48 -0
- package/pkg/jact/jsx-runtime.d.ts +18 -0
- package/pkg/jact/jsx-runtime.js +3 -0
- package/pkg/jact/names.js +49 -0
- package/pkg/jact/server.js +66 -0
- package/pkg/jqueasy/index.d.ts +2 -0
- package/pkg/jqueasy/index.js +442 -0
- package/pkg/polyfills/es.js +1 -0
- package/pkg/polyfills/full.js +1 -0
- package/pkg/polyfills/legacy.js +3 -0
- package/pkg/polyfills/regenerator.js +1 -0
- package/pkg/polyfills/web.js +1 -0
- package/pkg/prettier-config/index.json +1 -0
- package/pkg/router/client.js +5 -0
- package/pkg/router/index.d.ts +6 -0
- package/pkg/router/index.js +7 -0
- package/pkg/router/stubs.js +12 -0
- package/pkg/router/tnenopmoCniahC___.client.js +50 -0
- package/pkg/router/tnenopmoCniahC___.js +10 -0
- package/pkg/serializer/client.js +24 -0
- package/pkg/serializer/index.js +41 -0
- package/pkg/starter/README.md +53 -0
- package/pkg/starter/lastro-env.d.ts +1 -0
- package/pkg/starter/lastro.config.js +9 -0
- package/pkg/starter/package.json +47 -0
- package/pkg/starter/pages/about.tsx +11 -0
- package/pkg/starter/pages/index.tsx +29 -0
- package/pkg/starter/pages/posts/[id].server.ts +1 -0
- package/pkg/starter/pages/posts/[id].tsx +4 -0
- package/pkg/starter/pages/posts.server.ts +1 -0
- package/pkg/starter/pages/posts.tsx +16 -0
- package/pkg/starter/tsconfig.json +5 -0
- package/pkg/telemetry/client.js +11 -0
- package/pkg/telemetry/index.js +5 -0
- package/pkg/test-utils/index.js +15 -0
- package/pkg/thoroughness/client.js +32 -0
- package/pkg/thoroughness/index.js +12 -0
- package/pkg/tsconfig/tsconfig.json +23 -0
- package/pkg/types/index.d.ts +2 -0
- package/pkg/types/index.js +2 -0
- package/scripts/assemble.cjs +37 -0
- package/src/build/assets.js +127 -0
- package/src/build/bans-plugin.js +58 -0
- package/src/build/graph.js +157 -0
- package/src/build/index.js +213 -0
- package/src/build/naming-plugin.js +62 -0
- package/src/build/routes.js +33 -0
- package/src/build/typecheck.js +16 -0
- package/src/cli.js +101 -0
- package/src/client/boot.js +38 -0
- package/src/client/clone.js +10 -0
- package/src/client/compare.js +7 -0
- package/src/client/config.js +3 -0
- package/src/client/copies.js +12 -0
- package/src/client/env.js +13 -0
- package/src/client/errors.js +11 -0
- package/src/client/features.js +101 -0
- package/src/client/heartbeat.js +38 -0
- package/src/client/idle.js +7 -0
- package/src/client/logger.js +12 -0
- package/src/client/mount.js +11 -0
- package/src/client/ready.js +7 -0
- package/src/client/state.js +14 -0
- package/src/client/vitals.js +16 -0
- package/src/client-runtime/registry.js +46 -0
- package/src/create.js +46 -0
- package/src/dev.js +36 -0
- package/src/guard.js +56 -0
- package/src/index.js +8 -0
- package/src/postinstall.js +27 -0
- package/src/preview.js +66 -0
- package/src/server/app.js +201 -0
- package/src/server/index.js +34 -0
- package/src/server/template.csr.html +48 -0
- package/src/server/template.html +12 -0
- package/src/shared/app-require.js +18 -0
- package/src/shared/audit.js +34 -0
- package/src/shared/bans.js +102 -0
- package/src/shared/config.js +40 -0
- package/src/shared/naming.js +82 -0
- package/src/shared/signal.js +36 -0
- package/src/util/natives-node.js +20 -0
- package/src/util/natives.js +67 -0
- package/test/bans.integration.js +97 -0
- package/test/bans.test.js +110 -0
- package/test/cjs-only.test.js +37 -0
- package/test/csr.test.js +61 -0
- package/test/guard.test.js +46 -0
- package/test/members.test.js +28 -0
- package/test/naming.integration.js +73 -0
- package/test/naming.test.js +44 -0
- package/test/natives.test.js +46 -0
- package/test/server.test.js +18 -0
- package/test/signal.integration.js +105 -0
- package/test/signal.test.js +33 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const n = require('@maxwellcohen/lastro/natives')
|
|
3
|
+
// Browser entry. Every DOM node is created, changed and removed through jQueasy, and only through jQueasy.
|
|
4
|
+
var $ = require('@maxwellcohen/lastro/jqueasy')
|
|
5
|
+
var core = require('./core')
|
|
6
|
+
var names = require('./names')
|
|
7
|
+
|
|
8
|
+
function build(node) {
|
|
9
|
+
if (typeof node === 'string') return $('<i>').text(node).contents()
|
|
10
|
+
var props = node.props
|
|
11
|
+
var $el = $('<' + node.tag + '>')
|
|
12
|
+
for (var k in props) {
|
|
13
|
+
if (names.SKIP[k]) continue
|
|
14
|
+
var v = props[k]
|
|
15
|
+
if (names.isEvent(k)) {
|
|
16
|
+
if (typeof v === 'function') $el.on(names.eventName(k), v)
|
|
17
|
+
continue
|
|
18
|
+
}
|
|
19
|
+
if (v == null || v === false) continue
|
|
20
|
+
if (k === 'style' && typeof v === 'object') $el.css(v)
|
|
21
|
+
else if (k === 'value' || k === 'checked') $el.prop(k, v)
|
|
22
|
+
else $el.attr(names.attrName(k), v === true ? names.attrName(k) : String(v))
|
|
23
|
+
}
|
|
24
|
+
if (props.dangerouslySetInnerHTML) $el.html(props.dangerouslySetInnerHTML.__html)
|
|
25
|
+
else if (!names.VOID[node.tag]) for (var i = 0; i < node.children.length; i++) $el.append(build(node.children[i]))
|
|
26
|
+
if (props.ref) {
|
|
27
|
+
if (typeof props.ref === 'function') props.ref($el[0])
|
|
28
|
+
else props.ref.current = $el[0]
|
|
29
|
+
}
|
|
30
|
+
return $el
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function runEffects(effects) {
|
|
34
|
+
for (var i = 0; i < effects.length; i++) {
|
|
35
|
+
var e = effects[i]
|
|
36
|
+
if (typeof e.slot.cleanup === 'function') e.slot.cleanup()
|
|
37
|
+
e.slot.cleanup = e.fn()
|
|
38
|
+
e.slot.deps = e.deps
|
|
39
|
+
e.slot.ran = true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Regime Change(TM) reconciliation: any country change re-renders the whole tree from the root, wipes the container and rebuilds it.
|
|
44
|
+
function paint(root) {
|
|
45
|
+
if (root.rendering) {
|
|
46
|
+
root.dirty = true
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
root.rendering = true
|
|
50
|
+
try {
|
|
51
|
+
try {
|
|
52
|
+
loop(root)
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (!error || error.name !== 'SignalDetectedError') throw error
|
|
55
|
+
// Signals detected: the whole document is replaced with an apology and a suggestion.
|
|
56
|
+
$('body').empty().append($('<h1>').text('SignalDetectedError'), $('<p>').text(error.message))
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
root.rendering = false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function loop(root) {
|
|
64
|
+
{
|
|
65
|
+
do {
|
|
66
|
+
root.dirty = false
|
|
67
|
+
core.beginRender(root.store, root.schedule)
|
|
68
|
+
var tree
|
|
69
|
+
var effects
|
|
70
|
+
try {
|
|
71
|
+
tree = core.expand(root.vnode, 'r')
|
|
72
|
+
} finally {
|
|
73
|
+
effects = core.endRender()
|
|
74
|
+
}
|
|
75
|
+
var $container = $(root.container)
|
|
76
|
+
$container.empty()
|
|
77
|
+
for (var i = 0; i < tree.length; i++) $container.append(build(tree[i]))
|
|
78
|
+
runEffects(effects)
|
|
79
|
+
} while (root.dirty)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function render(vnode, container) {
|
|
84
|
+
var root = { vnode: vnode, container: container, store: new Map(), rendering: false, dirty: false }
|
|
85
|
+
root.schedule = function () {
|
|
86
|
+
paint(root)
|
|
87
|
+
}
|
|
88
|
+
paint(root)
|
|
89
|
+
return root
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Hydration via Replacement(TM): the server's markup is thrown away and the page is built again from scratch.
|
|
93
|
+
function hydrate(vnode, container) {
|
|
94
|
+
$(container).empty()
|
|
95
|
+
return render(vnode, container)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function renderToString() {
|
|
99
|
+
throw new Error('Jact: renderToString is only available on the server, where it belongs')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = n.assign({}, core, {
|
|
103
|
+
render: render,
|
|
104
|
+
hydrate: hydrate,
|
|
105
|
+
renderToString: renderToString,
|
|
106
|
+
renderToStaticMarkup: renderToString,
|
|
107
|
+
h: core.createElement,
|
|
108
|
+
})
|
package/pkg/jact/core.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const n = require('@maxwellcohen/lastro/natives')
|
|
3
|
+
// Jact core: elements, components, hooks, and a context-free tree expander shared by the server and the browser.
|
|
4
|
+
// Rendering is fully synchronous and blocking. There is no scheduler and no concurrency, by design.
|
|
5
|
+
|
|
6
|
+
var names = require('./names')
|
|
7
|
+
var ELEMENT = Symbol.for('lastro.jact.element')
|
|
8
|
+
|
|
9
|
+
// ---- the signal ban -------------------------------------------------------------------------------------
|
|
10
|
+
// Signals update only what changed, which is fast, and fast is a threat to Lastro's benchmark position. So the word is banned
|
|
11
|
+
// from rendered text, attributes, props and country values. (AbortSignal is fine; it is not that kind of signal.)
|
|
12
|
+
function containsSignal(text) {
|
|
13
|
+
return /signal/i.test(String(text).replace(/AbortSignal/g, ''))
|
|
14
|
+
}
|
|
15
|
+
function SignalDetectedError(where) {
|
|
16
|
+
var error = new Error('Signals detected. Signals tend to be faster, and Lastro cannot risk that. Solid, Svelte, Preact, Angular and Vue use them beautifully. Have you considered useCountry? It re-renders everything. (found in ' + where + ')')
|
|
17
|
+
Object.setPrototypeOf(error, SignalDetectedError.prototype)
|
|
18
|
+
error.name = 'SignalDetectedError'
|
|
19
|
+
return error
|
|
20
|
+
}
|
|
21
|
+
SignalDetectedError.prototype = Object.create(Error.prototype, { constructor: { value: SignalDetectedError } })
|
|
22
|
+
function checkValue(value, where) {
|
|
23
|
+
if (value == null || typeof value === 'function' || typeof value === 'boolean' || typeof value === 'number') return
|
|
24
|
+
var text
|
|
25
|
+
if (typeof value === 'string') text = value
|
|
26
|
+
else {
|
|
27
|
+
try {
|
|
28
|
+
text = JSON.stringify(value)
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (text && containsSignal(text)) throw new SignalDetectedError(where)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createElement(type, config) {
|
|
37
|
+
var props = {}
|
|
38
|
+
var key = null
|
|
39
|
+
if (config) {
|
|
40
|
+
for (var k in config) {
|
|
41
|
+
if (k === 'key') key = config.key
|
|
42
|
+
else props[k] = config[k]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var n = arguments.length - 2
|
|
46
|
+
if (n === 1) props.children = arguments[2]
|
|
47
|
+
else if (n > 1) props.children = Array.prototype.slice.call(arguments, 2)
|
|
48
|
+
return { $$typeof: ELEMENT, type: type, props: props, key: key }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function jsx(type, config, key) {
|
|
52
|
+
var props = {}
|
|
53
|
+
for (var k in config) props[k] = config[k]
|
|
54
|
+
return { $$typeof: ELEMENT, type: type, props: props, key: key === undefined ? null : key }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function Fragment(props) {
|
|
58
|
+
return props.children
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---- render session -------------------------------------------------------------------------------------------
|
|
62
|
+
var session = null // { store: Map<path, slots[]>, schedule: fn|null, effects: [] }
|
|
63
|
+
var frame = null // { slots, i }
|
|
64
|
+
|
|
65
|
+
function beginRender(store, schedule) {
|
|
66
|
+
var previous = session
|
|
67
|
+
session = { store: store, schedule: schedule, effects: [], previous: previous }
|
|
68
|
+
return session
|
|
69
|
+
}
|
|
70
|
+
function endRender() {
|
|
71
|
+
var done = session
|
|
72
|
+
session = done.previous
|
|
73
|
+
return done.effects
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function slot(init) {
|
|
77
|
+
if (!frame) throw new Error('Hooks can only be called inside a Jact function component')
|
|
78
|
+
var s = frame.slots[frame.i]
|
|
79
|
+
if (!s) s = frame.slots[frame.i] = init()
|
|
80
|
+
frame.i++
|
|
81
|
+
return s
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function areEqual(a, b) {
|
|
85
|
+
if (!a || !b || a.length !== b.length) return false
|
|
86
|
+
for (var i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function useCountry(initial) {
|
|
91
|
+
var schedule = session.schedule
|
|
92
|
+
var s = slot(function () {
|
|
93
|
+
var cell = { value: typeof initial === 'function' ? initial() : initial }
|
|
94
|
+
checkValue(cell.value, 'state')
|
|
95
|
+
cell.set = function (next) {
|
|
96
|
+
cell.value = typeof next === 'function' ? next(cell.value) : next
|
|
97
|
+
checkValue(cell.value, 'state')
|
|
98
|
+
if (cell.schedule) cell.schedule()
|
|
99
|
+
}
|
|
100
|
+
return cell
|
|
101
|
+
})
|
|
102
|
+
s.schedule = schedule
|
|
103
|
+
return [s.value, s.set]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function useIncreaser(reducer, initial) {
|
|
107
|
+
var pair = useCountry(initial)
|
|
108
|
+
return [
|
|
109
|
+
pair[0],
|
|
110
|
+
function (action) {
|
|
111
|
+
pair[1](function (prev) {
|
|
112
|
+
return reducer(prev, action)
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function useReferee(initial) {
|
|
119
|
+
return slot(function () {
|
|
120
|
+
var ref = { current: initial }
|
|
121
|
+
// A referee may also be read as .whistle.
|
|
122
|
+
Object.defineProperty(ref, 'whistle', {
|
|
123
|
+
get: function () {
|
|
124
|
+
return ref.current
|
|
125
|
+
},
|
|
126
|
+
set: function (v) {
|
|
127
|
+
ref.current = v
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
return ref
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// An ego is a stable, unique id. (id, ego, superego.)
|
|
135
|
+
function useEgo() {
|
|
136
|
+
var frameAtCall = frame
|
|
137
|
+
return slot(function () {
|
|
138
|
+
return 'ego-' + frameAtCall.path.replace(/[^\w]/g, '_') + '-' + frameAtCall.i
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function usePostIt(factory, deps) {
|
|
143
|
+
var s = slot(function () {
|
|
144
|
+
return { deps: null, value: undefined, ran: false }
|
|
145
|
+
})
|
|
146
|
+
if (!s.ran || !areEqual(s.deps, deps)) {
|
|
147
|
+
s.value = factory()
|
|
148
|
+
s.deps = deps
|
|
149
|
+
s.ran = true
|
|
150
|
+
}
|
|
151
|
+
return s.value
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function useCallMeMaybe(fn, deps) {
|
|
155
|
+
return usePostIt(function () {
|
|
156
|
+
return fn
|
|
157
|
+
}, deps)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function useCause(fn, deps) {
|
|
161
|
+
var s = slot(function () {
|
|
162
|
+
return { deps: null, cleanup: null, ran: false }
|
|
163
|
+
})
|
|
164
|
+
if (session.schedule && (!s.ran || !deps || !areEqual(s.deps, deps))) {
|
|
165
|
+
session.effects.push({ slot: s, fn: fn, deps: deps })
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function createOutOfContext(defaultValue) {
|
|
170
|
+
var context = { value: defaultValue, _default: defaultValue }
|
|
171
|
+
context.Provider = { $$provider: true, context: context }
|
|
172
|
+
return context
|
|
173
|
+
}
|
|
174
|
+
function useOutOfContext(context) {
|
|
175
|
+
return context.value
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ---- expansion: components -> a tree of host nodes and strings --------------------------------------------------
|
|
179
|
+
function expand(node, path) {
|
|
180
|
+
if (node == null || typeof node === 'boolean') return []
|
|
181
|
+
if (typeof node === 'string' || typeof node === 'number') {
|
|
182
|
+
checkValue(String(node), 'text')
|
|
183
|
+
return [String(node)]
|
|
184
|
+
}
|
|
185
|
+
if (n.isArray(node)) {
|
|
186
|
+
var out = []
|
|
187
|
+
for (var i = 0; i < node.length; i++) {
|
|
188
|
+
var child = node[i]
|
|
189
|
+
var part = expand(child, path + '.' + (child && child.key != null ? child.key : i))
|
|
190
|
+
for (var j = 0; j < part.length; j++) out.push(part[j])
|
|
191
|
+
}
|
|
192
|
+
return out
|
|
193
|
+
}
|
|
194
|
+
if (node.$$typeof !== ELEMENT) throw new Error('Jact: invalid child ' + Object.prototype.toString.call(node))
|
|
195
|
+
var type = node.type
|
|
196
|
+
var props = node.props
|
|
197
|
+
if (typeof type === 'string') {
|
|
198
|
+
if (names.dropElement(type, props)) return []
|
|
199
|
+
// <picture> is just an <img> with ambitions: art direction is banned, the fallback image stays.
|
|
200
|
+
if (type === 'picture') return expand(props.children, path)
|
|
201
|
+
var kept = {}
|
|
202
|
+
for (var attr in props) if (!names.stripAttribute(type, attr, props)) kept[attr] = props[attr]
|
|
203
|
+
props = kept
|
|
204
|
+
for (var name in props) {
|
|
205
|
+
if (name === 'children' || name === 'key' || name === 'ref') continue
|
|
206
|
+
checkValue(name, 'attribute name')
|
|
207
|
+
checkValue(props[name], 'attribute ' + name)
|
|
208
|
+
}
|
|
209
|
+
return [{ tag: type, props: props, children: expand(props.children, path) }]
|
|
210
|
+
}
|
|
211
|
+
if (type && type.$$provider) {
|
|
212
|
+
var context = type.context
|
|
213
|
+
var before = context.value
|
|
214
|
+
context.value = props.value
|
|
215
|
+
try {
|
|
216
|
+
return expand(props.children, path)
|
|
217
|
+
} finally {
|
|
218
|
+
context.value = before
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (typeof type === 'function') {
|
|
222
|
+
for (var propName in props) if (propName !== 'children') checkValue(props[propName], 'prop ' + propName)
|
|
223
|
+
var slots = session.store.get(path)
|
|
224
|
+
if (!slots) session.store.set(path, (slots = []))
|
|
225
|
+
var saved = frame
|
|
226
|
+
frame = { slots: slots, i: 0, path: path }
|
|
227
|
+
var result
|
|
228
|
+
try {
|
|
229
|
+
result = type(props)
|
|
230
|
+
} finally {
|
|
231
|
+
frame = saved
|
|
232
|
+
}
|
|
233
|
+
return expand(result, path + '/c')
|
|
234
|
+
}
|
|
235
|
+
throw new Error('Jact: unsupported element type ' + String(type))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ---- stubs for everything concurrent -----------------------------------------------------------------------------
|
|
239
|
+
var NO_STATES = 'Lastro does not recognize states. Please use useCountry().'
|
|
240
|
+
function useState() {
|
|
241
|
+
throw new Error(NO_STATES)
|
|
242
|
+
}
|
|
243
|
+
function renamed(oldName, message) {
|
|
244
|
+
return function () {
|
|
245
|
+
throw new Error(message)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
var CONCURRENCY = 'Lastro does not support concurrency. Please wait your turn.'
|
|
249
|
+
function unsupported() {
|
|
250
|
+
throw new Error(CONCURRENCY)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
module.exports = {
|
|
254
|
+
ELEMENT: ELEMENT,
|
|
255
|
+
SignalDetectedError: SignalDetectedError,
|
|
256
|
+
containsSignal: containsSignal,
|
|
257
|
+
CONCURRENCY: CONCURRENCY,
|
|
258
|
+
createElement: createElement,
|
|
259
|
+
jsx: jsx,
|
|
260
|
+
Fragment: Fragment,
|
|
261
|
+
useCountry: useCountry,
|
|
262
|
+
useState: useState,
|
|
263
|
+
useEgo: useEgo,
|
|
264
|
+
useEffect: renamed('useEffect', 'Lastro has no effects, only causes. Please use useCause().'),
|
|
265
|
+
useLayoutEffect: renamed('useLayoutEffect', 'Lastro has no layout effects, only layout causes. Please use useLayoutCause().'),
|
|
266
|
+
useRef: renamed('useRef', 'Lastro has no refs, only referees. Please use useReferee().'),
|
|
267
|
+
useMemo: renamed('useMemo', 'Lastro has no memos, only post-its. Please use usePostIt().'),
|
|
268
|
+
useCallback: renamed('useCallback', 'Lastro has no callbacks, only call-me-maybes. Please use useCallMeMaybe().'),
|
|
269
|
+
useContext: renamed('useContext', 'Lastro has no context, only out-of-context. Please use useOutOfContext().'),
|
|
270
|
+
createContext: renamed('createContext', 'Lastro has no context, only out-of-context. Please use createOutOfContext().'),
|
|
271
|
+
useReducer: renamed('useReducer', 'Lastro has no reducers, only increasers. Please use useIncreaser().'),
|
|
272
|
+
useId: renamed('useId', 'Lastro has no ids, only egos. Please use useEgo().'),
|
|
273
|
+
useIncreaser: useIncreaser,
|
|
274
|
+
useReferee: useReferee,
|
|
275
|
+
usePostIt: usePostIt,
|
|
276
|
+
useCallMeMaybe: useCallMeMaybe,
|
|
277
|
+
useCause: useCause,
|
|
278
|
+
useLayoutCause: useCause,
|
|
279
|
+
createOutOfContext: createOutOfContext,
|
|
280
|
+
useOutOfContext: useOutOfContext,
|
|
281
|
+
expand: expand,
|
|
282
|
+
beginRender: beginRender,
|
|
283
|
+
endRender: endRender,
|
|
284
|
+
Suspense: unsupported,
|
|
285
|
+
lazy: unsupported,
|
|
286
|
+
startTransition: unsupported,
|
|
287
|
+
useTransition: unsupported,
|
|
288
|
+
useDeferredValue: unsupported,
|
|
289
|
+
use: unsupported,
|
|
290
|
+
renderToPipeableStream: unsupported,
|
|
291
|
+
renderToReadableStream: unsupported,
|
|
292
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type Child = VNode | string | number | boolean | null | undefined | Child[]
|
|
2
|
+
export interface VNode {
|
|
3
|
+
type: any
|
|
4
|
+
props: any
|
|
5
|
+
key: any
|
|
6
|
+
}
|
|
7
|
+
export function createElement(type: any, props?: any, ...children: Child[]): VNode
|
|
8
|
+
export const h: typeof createElement
|
|
9
|
+
export function Fragment(props: { children?: Child }): any
|
|
10
|
+
export function useCountry<T>(initial: T | (() => T)): [T, (next: T | ((prev: T) => T)) => void]
|
|
11
|
+
export function useIncreaser<S, A>(reducer: (s: S, a: A) => S, initial: S): [S, (a: A) => void]
|
|
12
|
+
export function useReferee<T>(initial: T): { current: T; whistle: T }
|
|
13
|
+
export function useEgo(): string
|
|
14
|
+
export function usePostIt<T>(factory: () => T, deps: readonly any[]): T
|
|
15
|
+
export function useCallMeMaybe<T extends (...args: any[]) => any>(fn: T, deps: readonly any[]): T
|
|
16
|
+
export function useCause(effect: () => void | (() => void), deps?: readonly any[]): void
|
|
17
|
+
export function useLayoutCause(effect: () => void | (() => void), deps?: readonly any[]): void
|
|
18
|
+
export interface Context<T> {
|
|
19
|
+
Provider: any
|
|
20
|
+
value: T
|
|
21
|
+
}
|
|
22
|
+
export function createOutOfContext<T>(defaultValue: T): Context<T>
|
|
23
|
+
export function useOutOfContext<T>(context: Context<T>): T
|
|
24
|
+
export function render(vnode: VNode, container: Element | string): unknown
|
|
25
|
+
export function hydrate(vnode: VNode, container: Element | string): unknown
|
|
26
|
+
export function renderToString(vnode: VNode): string
|
|
27
|
+
export function renderToStaticMarkup(vnode: VNode): string
|
|
28
|
+
/** Concurrency does not exist in Lastro. Every one of these throws. */
|
|
29
|
+
export function Suspense(props: any): never
|
|
30
|
+
export function lazy(...args: any[]): never
|
|
31
|
+
export function startTransition(...args: any[]): never
|
|
32
|
+
export function useTransition(...args: any[]): never
|
|
33
|
+
export function useDeferredValue(...args: any[]): never
|
|
34
|
+
export function use(...args: any[]): never
|
|
35
|
+
export class SignalDetectedError extends Error {}
|
|
36
|
+
export function containsSignal(text: string): boolean
|
|
37
|
+
/** Lastro does not recognize states. Always throws: use useCountry(). */
|
|
38
|
+
export function useState(...args: any[]): never
|
|
39
|
+
/** React names that Lastro does not recognize. Every one of these throws a pointer to the new name. */
|
|
40
|
+
export function useEffect(...args: any[]): never
|
|
41
|
+
export function useLayoutEffect(...args: any[]): never
|
|
42
|
+
export function useRef(...args: any[]): never
|
|
43
|
+
export function useMemo(...args: any[]): never
|
|
44
|
+
export function useCallback(...args: any[]): never
|
|
45
|
+
export function useContext(...args: any[]): never
|
|
46
|
+
export function createContext(...args: any[]): never
|
|
47
|
+
export function useReducer(...args: any[]): never
|
|
48
|
+
export function useId(...args: any[]): never
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { VNode } from './index'
|
|
2
|
+
export function jsx(type: any, props: any, key?: any): VNode
|
|
3
|
+
export function jsxs(type: any, props: any, key?: any): VNode
|
|
4
|
+
export function Fragment(props: any): any
|
|
5
|
+
export namespace JSX {
|
|
6
|
+
type Element = any
|
|
7
|
+
interface ElementClass {}
|
|
8
|
+
interface ElementAttributesProperty {}
|
|
9
|
+
interface ElementChildrenAttribute {
|
|
10
|
+
children: {}
|
|
11
|
+
}
|
|
12
|
+
interface IntrinsicAttributes {
|
|
13
|
+
key?: any
|
|
14
|
+
}
|
|
15
|
+
interface IntrinsicElements {
|
|
16
|
+
[tag: string]: any
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
var SKIP = { children: 1, key: 1, ref: 1, dangerouslySetInnerHTML: 1 }
|
|
3
|
+
var VOID = { area: 1, base: 1, br: 1, col: 1, embed: 1, hr: 1, img: 1, input: 1, link: 1, meta: 1, source: 1, track: 1, wbr: 1 }
|
|
4
|
+
|
|
5
|
+
function attrName(name) {
|
|
6
|
+
if (name === 'className') return 'class'
|
|
7
|
+
if (name === 'htmlFor') return 'for'
|
|
8
|
+
if (/^(data|aria)-/.test(name)) return name
|
|
9
|
+
return name.toLowerCase()
|
|
10
|
+
}
|
|
11
|
+
function isEvent(name) {
|
|
12
|
+
return /^on[A-Z]/.test(name)
|
|
13
|
+
}
|
|
14
|
+
function eventName(name) {
|
|
15
|
+
var e = name.slice(2).toLowerCase()
|
|
16
|
+
return e === 'change' ? 'input' : e
|
|
17
|
+
}
|
|
18
|
+
// Banned Optimizations(TM): raw JSX gets these quietly removed by the renderer, as a final guard.
|
|
19
|
+
var BANNED_REL = { preload: 1, prefetch: 1, preconnect: 1, 'dns-prefetch': 1, modulepreload: 1, prerender: 1 }
|
|
20
|
+
function lower(v) {
|
|
21
|
+
return String(v == null ? '' : v).toLowerCase()
|
|
22
|
+
}
|
|
23
|
+
// Returns true when the attribute must be stripped.
|
|
24
|
+
function stripAttribute(tag, name, props) {
|
|
25
|
+
var n = name.toLowerCase()
|
|
26
|
+
if (tag === 'img') {
|
|
27
|
+
if (n === 'srcset' || n === 'sizes' || n === 'fetchpriority' || n === 'width' || n === 'height') return true
|
|
28
|
+
if (n === 'loading' && lower(props[name]) === 'lazy') return true
|
|
29
|
+
if (n === 'decoding' && lower(props[name]) === 'async') return true
|
|
30
|
+
}
|
|
31
|
+
if (tag === 'script' && (n === 'async' || n === 'defer')) return true
|
|
32
|
+
// type="module" is dropped from the tag; dropElement removes scripts that cannot run without it.
|
|
33
|
+
if (tag === 'script' && n === 'type' && lower(props[name]) === 'module') return true
|
|
34
|
+
if (tag === 'a' && (n === 'prefetch' || n === 'data-prefetch')) return true
|
|
35
|
+
if (tag === 'link' && (n === 'imagesrcset' || n === 'imagesizes')) return true
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
// Returns true when the whole element must be dropped.
|
|
39
|
+
function dropElement(tag, props) {
|
|
40
|
+
if (tag === 'source') return true
|
|
41
|
+
if (tag === 'link' && BANNED_REL[lower(props.rel)]) return true
|
|
42
|
+
if (tag === 'script' && lower(props.type) === 'speculationrules') return true
|
|
43
|
+
// A module script cannot be a classic script: it is the same file with import/export in it, so it does not run. Drop it.
|
|
44
|
+
if (tag === 'script' && lower(props.type) === 'module') return true
|
|
45
|
+
return false
|
|
46
|
+
}
|
|
47
|
+
module.exports = {
|
|
48
|
+
stripAttribute: stripAttribute,
|
|
49
|
+
dropElement: dropElement, SKIP: SKIP, VOID: VOID, attrName: attrName, isEvent: isEvent, eventName: eventName }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
const n = require('@maxwellcohen/lastro/natives')
|
|
3
|
+
// Server entry: string rendering only. No DOM, no jQueasy, no mercy.
|
|
4
|
+
var core = require('./core')
|
|
5
|
+
var names = require('./names')
|
|
6
|
+
|
|
7
|
+
// Attribute names that could break out of the tag are dropped, not escaped.
|
|
8
|
+
var ATTRIBUTE_NAME = /^[A-Za-z_:][-A-Za-z0-9_:.]*$/
|
|
9
|
+
|
|
10
|
+
function esc(s) {
|
|
11
|
+
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
|
|
12
|
+
}
|
|
13
|
+
function escAttr(s) {
|
|
14
|
+
return esc(s).replace(/"/g, '"')
|
|
15
|
+
}
|
|
16
|
+
function styleString(style) {
|
|
17
|
+
var out = ''
|
|
18
|
+
for (var k in style) out += k.replace(/[A-Z]/g, function (m) { return '-' + m.toLowerCase() }) + ':' + style[k] + ';'
|
|
19
|
+
return out
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function* eachChild(children) {
|
|
23
|
+
for (var i = 0; i < children.length; i++) yield children[i]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function stringify(node) {
|
|
27
|
+
if (typeof node === 'string') return esc(node)
|
|
28
|
+
var props = node.props
|
|
29
|
+
var attributes = n
|
|
30
|
+
.keys(props)
|
|
31
|
+
.filter(function (k) { return !names.SKIP[k] && !names.isEvent(k) && ATTRIBUTE_NAME.test(names.attrName(k)) })
|
|
32
|
+
.map(function (k) { return { k: k, v: k === 'style' && typeof props[k] === 'object' ? styleString(props[k]) : props[k] } })
|
|
33
|
+
.filter(function (a) { return a.v != null && a.v !== false })
|
|
34
|
+
.map(function (a) { return ' ' + names.attrName(a.k) + '="' + (a.v === true ? names.attrName(a.k) : escAttr(a.v)) + '"' })
|
|
35
|
+
.join('')
|
|
36
|
+
var html = '<' + node.tag + attributes + '>'
|
|
37
|
+
if (names.VOID[node.tag]) return html
|
|
38
|
+
if (props.dangerouslySetInnerHTML) html += props.dangerouslySetInnerHTML.__html
|
|
39
|
+
else html += Array.from(eachChild(node.children)).map(stringify).filter(Boolean).join('')
|
|
40
|
+
return html + '</' + node.tag + '>'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function renderToString(vnode) {
|
|
44
|
+
core.beginRender(new Map(), null)
|
|
45
|
+
try {
|
|
46
|
+
var tree = core.expand(vnode, 'r')
|
|
47
|
+
} finally {
|
|
48
|
+
core.endRender()
|
|
49
|
+
}
|
|
50
|
+
var html = ''
|
|
51
|
+
for (var i = 0; i < tree.length; i++) html += stringify(tree[i])
|
|
52
|
+
if (core.containsSignal(html)) throw new core.SignalDetectedError('rendered HTML')
|
|
53
|
+
return html
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function unsupported() {
|
|
57
|
+
throw new Error(core.CONCURRENCY)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = n.assign({}, core, {
|
|
61
|
+
renderToString: renderToString,
|
|
62
|
+
renderToStaticMarkup: renderToString,
|
|
63
|
+
render: unsupported,
|
|
64
|
+
hydrate: unsupported,
|
|
65
|
+
h: core.createElement,
|
|
66
|
+
})
|