@zenithbuild/runtime 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HYDRATION_CONTRACT.md +1 -1
- package/LICENSE +21 -0
- package/README.md +16 -18
- package/RUNTIME_CONTRACT.md +24 -12
- package/dist/cleanup.js +6 -3
- package/dist/diagnostics.d.ts +7 -0
- package/dist/diagnostics.js +7 -0
- package/dist/effect-runtime.d.ts +2 -0
- package/dist/effect-runtime.js +139 -0
- package/dist/effect-scheduler.d.ts +4 -0
- package/dist/effect-scheduler.js +88 -0
- package/dist/effect-utils.d.ts +19 -0
- package/dist/effect-utils.js +160 -0
- package/dist/env.d.ts +12 -0
- package/dist/env.js +18 -2
- package/dist/events.d.ts +1 -8
- package/dist/events.js +108 -46
- package/dist/expressions.d.ts +14 -0
- package/dist/expressions.js +295 -0
- package/dist/fragment-patch.d.ts +12 -0
- package/dist/fragment-patch.js +118 -0
- package/dist/hydrate.d.ts +3 -117
- package/dist/hydrate.js +235 -1817
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/markup.d.ts +8 -0
- package/dist/markup.js +127 -0
- package/dist/mount-runtime.d.ts +1 -0
- package/dist/mount-runtime.js +39 -0
- package/dist/payload.d.ts +21 -0
- package/dist/payload.js +386 -0
- package/dist/reactivity-core.d.ts +3 -0
- package/dist/reactivity-core.js +22 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.js +340 -0
- package/dist/scanner.d.ts +1 -0
- package/dist/scanner.js +61 -0
- package/dist/side-effect-scope.d.ts +16 -0
- package/dist/side-effect-scope.js +99 -0
- package/dist/signal.js +1 -1
- package/dist/state.js +1 -1
- package/dist/template-parser.d.ts +1 -0
- package/dist/template-parser.js +268 -0
- package/dist/template.js +10 -11
- package/dist/zeneffect.d.ts +12 -14
- package/dist/zeneffect.js +25 -519
- package/package.json +5 -3
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
export function _rewriteMarkupLiterals(expression) {
|
|
2
|
+
let out = '';
|
|
3
|
+
let index = 0;
|
|
4
|
+
let quote = null;
|
|
5
|
+
let escaped = false;
|
|
6
|
+
while (index < expression.length) {
|
|
7
|
+
const ch = expression[index];
|
|
8
|
+
if (quote) {
|
|
9
|
+
out += ch;
|
|
10
|
+
if (escaped) {
|
|
11
|
+
escaped = false;
|
|
12
|
+
index += 1;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (ch === '\\') {
|
|
16
|
+
escaped = true;
|
|
17
|
+
index += 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (ch === quote) {
|
|
21
|
+
quote = null;
|
|
22
|
+
}
|
|
23
|
+
index += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
27
|
+
quote = ch;
|
|
28
|
+
out += ch;
|
|
29
|
+
index += 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (ch === '<') {
|
|
33
|
+
const markup = _readMarkupLiteral(expression, index);
|
|
34
|
+
if (markup) {
|
|
35
|
+
out += `__zenith_fragment${_markupLiteralToTemplate(markup.value)}`;
|
|
36
|
+
index = markup.end;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
out += ch;
|
|
41
|
+
index += 1;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
function _readMarkupLiteral(source, start) {
|
|
46
|
+
if (source[start] !== '<') {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const firstTag = _readTagToken(source, start);
|
|
50
|
+
if (!firstTag || firstTag.isClosing) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (firstTag.selfClosing) {
|
|
54
|
+
return {
|
|
55
|
+
value: source.slice(start, firstTag.end),
|
|
56
|
+
end: firstTag.end
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const stack = [firstTag.name];
|
|
60
|
+
let cursor = firstTag.end;
|
|
61
|
+
while (cursor < source.length) {
|
|
62
|
+
const nextLt = source.indexOf('<', cursor);
|
|
63
|
+
if (nextLt < 0) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const token = _readTagToken(source, nextLt);
|
|
67
|
+
if (!token) {
|
|
68
|
+
cursor = nextLt + 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
cursor = token.end;
|
|
72
|
+
if (token.selfClosing) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (token.isClosing) {
|
|
76
|
+
const expected = stack[stack.length - 1];
|
|
77
|
+
if (token.name !== expected) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
stack.pop();
|
|
81
|
+
if (stack.length === 0) {
|
|
82
|
+
return {
|
|
83
|
+
value: source.slice(start, token.end),
|
|
84
|
+
end: token.end
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
stack.push(token.name);
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
function _readTagToken(source, start) {
|
|
94
|
+
if (source[start] !== '<') {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
let index = start + 1;
|
|
98
|
+
let isClosing = false;
|
|
99
|
+
if (index < source.length && source[index] === '/') {
|
|
100
|
+
isClosing = true;
|
|
101
|
+
index += 1;
|
|
102
|
+
}
|
|
103
|
+
if (index >= source.length || !/[A-Za-z_]/.test(source[index])) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const nameStart = index;
|
|
107
|
+
while (index < source.length && /[A-Za-z0-9:_-]/.test(source[index])) {
|
|
108
|
+
index += 1;
|
|
109
|
+
}
|
|
110
|
+
if (index === nameStart) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const name = source.slice(nameStart, index);
|
|
114
|
+
let quote = null;
|
|
115
|
+
let escaped = false;
|
|
116
|
+
let braceDepth = 0;
|
|
117
|
+
while (index < source.length) {
|
|
118
|
+
const ch = source[index];
|
|
119
|
+
if (quote) {
|
|
120
|
+
if (escaped) {
|
|
121
|
+
escaped = false;
|
|
122
|
+
index += 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (ch === '\\') {
|
|
126
|
+
escaped = true;
|
|
127
|
+
index += 1;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (ch === quote) {
|
|
131
|
+
quote = null;
|
|
132
|
+
}
|
|
133
|
+
index += 1;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
137
|
+
quote = ch;
|
|
138
|
+
index += 1;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (ch === '{') {
|
|
142
|
+
braceDepth += 1;
|
|
143
|
+
index += 1;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (ch === '}') {
|
|
147
|
+
braceDepth = Math.max(0, braceDepth - 1);
|
|
148
|
+
index += 1;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (ch === '>' && braceDepth === 0) {
|
|
152
|
+
const segment = source.slice(start, index + 1);
|
|
153
|
+
const selfClosing = !isClosing && /\/\s*>$/.test(segment);
|
|
154
|
+
return { name, isClosing, selfClosing, end: index + 1 };
|
|
155
|
+
}
|
|
156
|
+
index += 1;
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
function _markupLiteralToTemplate(markup) {
|
|
161
|
+
let out = '`';
|
|
162
|
+
let index = 0;
|
|
163
|
+
while (index < markup.length) {
|
|
164
|
+
const ch = markup[index];
|
|
165
|
+
if (ch === '{') {
|
|
166
|
+
const segment = _readBalancedBraces(markup, index);
|
|
167
|
+
if (segment) {
|
|
168
|
+
if (_isAttributeExpressionStart(markup, index)) {
|
|
169
|
+
out += '"${' + segment.content + '}"';
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
out += '${' + segment.content + '}';
|
|
173
|
+
}
|
|
174
|
+
index = segment.end;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (ch === '`') {
|
|
179
|
+
out += '\\`';
|
|
180
|
+
index += 1;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (ch === '\\') {
|
|
184
|
+
out += '\\\\';
|
|
185
|
+
index += 1;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (ch === '$' && markup[index + 1] === '{') {
|
|
189
|
+
out += '\\${';
|
|
190
|
+
index += 2;
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
out += ch;
|
|
194
|
+
index += 1;
|
|
195
|
+
}
|
|
196
|
+
out += '`';
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
function _isAttributeExpressionStart(markup, start) {
|
|
200
|
+
let cursor = start - 1;
|
|
201
|
+
while (cursor >= 0) {
|
|
202
|
+
const ch = markup[cursor];
|
|
203
|
+
if (ch === ' ' || ch === '\t' || ch === '\n' || ch === '\r') {
|
|
204
|
+
cursor -= 1;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
return ch === '=';
|
|
208
|
+
}
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
function _readBalancedBraces(source, start) {
|
|
212
|
+
if (source[start] !== '{') {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
let depth = 1;
|
|
216
|
+
let index = start + 1;
|
|
217
|
+
let quote = null;
|
|
218
|
+
let escaped = false;
|
|
219
|
+
let content = '';
|
|
220
|
+
while (index < source.length) {
|
|
221
|
+
const ch = source[index];
|
|
222
|
+
if (quote) {
|
|
223
|
+
content += ch;
|
|
224
|
+
if (escaped) {
|
|
225
|
+
escaped = false;
|
|
226
|
+
index += 1;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (ch === '\\') {
|
|
230
|
+
escaped = true;
|
|
231
|
+
index += 1;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (ch === quote) {
|
|
235
|
+
quote = null;
|
|
236
|
+
}
|
|
237
|
+
index += 1;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (ch === '\'' || ch === '"' || ch === '`') {
|
|
241
|
+
quote = ch;
|
|
242
|
+
content += ch;
|
|
243
|
+
index += 1;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
if (ch === '{') {
|
|
247
|
+
depth += 1;
|
|
248
|
+
content += ch;
|
|
249
|
+
index += 1;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (ch === '}') {
|
|
253
|
+
depth -= 1;
|
|
254
|
+
if (depth === 0) {
|
|
255
|
+
return {
|
|
256
|
+
content,
|
|
257
|
+
end: index + 1
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
content += ch;
|
|
261
|
+
index += 1;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
content += ch;
|
|
265
|
+
index += 1;
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
package/dist/template.js
CHANGED
|
@@ -11,20 +11,19 @@ function readRuntimeSourceFile(fileName) {
|
|
|
11
11
|
return normalizeNewlines(readFileSync(fullPath, 'utf8'));
|
|
12
12
|
}
|
|
13
13
|
function stripImports(source) {
|
|
14
|
-
return source
|
|
14
|
+
return source
|
|
15
|
+
.replace(/^\s*import\s+[^;]+;\s*$/gm, '')
|
|
16
|
+
.replace(/^\s*export\s+\{[^}]+\}\s+from\s+['"]\.[^'"]+['"];\s*$/gm, '')
|
|
17
|
+
.trim();
|
|
15
18
|
}
|
|
16
19
|
function buildRuntimeModuleSource() {
|
|
17
20
|
const segments = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
stripImports(readRuntimeSourceFile('diagnostics.js')),
|
|
25
|
-
stripImports(readRuntimeSourceFile('cleanup.js')),
|
|
26
|
-
stripImports(readRuntimeSourceFile('hydrate.js'))
|
|
27
|
-
].filter(Boolean);
|
|
21
|
+
'reactivity-core.js', 'side-effect-scope.js', 'effect-utils.js', 'effect-scheduler.js',
|
|
22
|
+
'effect-runtime.js', 'mount-runtime.js', 'zeneffect.js', 'ref.js', 'env.js',
|
|
23
|
+
'platform.js', 'signal.js', 'state.js',
|
|
24
|
+
'diagnostics.js', 'cleanup.js', 'template-parser.js', 'markup.js', 'payload.js',
|
|
25
|
+
'expressions.js', 'render.js', 'fragment-patch.js', 'scanner.js', 'events.js', 'hydrate.js'
|
|
26
|
+
].map((fileName) => stripImports(readRuntimeSourceFile(fileName))).filter(Boolean);
|
|
28
27
|
return normalizeNewlines(segments.join('\n\n'));
|
|
29
28
|
}
|
|
30
29
|
const RUNTIME_MODULE_SOURCE = buildRuntimeModuleSource();
|
package/dist/zeneffect.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export declare function resetGlobalSideEffects(): void;
|
|
4
|
-
export declare function createSideEffectScope(label?: string): {
|
|
5
|
-
__zenith_scope: boolean;
|
|
6
|
-
id: number;
|
|
7
|
-
label: any;
|
|
8
|
-
mountReady: boolean;
|
|
9
|
-
disposed: boolean;
|
|
10
|
-
pendingMounts: never[];
|
|
11
|
-
disposers: never[];
|
|
12
|
-
};
|
|
13
|
-
export declare function activateSideEffectScope(scope: any): void;
|
|
14
|
-
export declare function disposeSideEffectScope(scope: any): void;
|
|
1
|
+
export { _nextReactiveId, _trackDependency } from './reactivity-core.js';
|
|
2
|
+
export { resetGlobalSideEffects, createSideEffectScope, activateSideEffectScope, disposeSideEffectScope } from './side-effect-scope.js';
|
|
15
3
|
export declare function zenEffect(effect: any, options?: null, scopeOverride?: null): () => void;
|
|
16
4
|
export declare function zeneffect(effectOrDependencies: any, optionsOrEffect: any, scopeOverride?: null): () => void;
|
|
17
5
|
export declare function zenMount(callback: any, scopeOverride?: null): () => void;
|
|
6
|
+
/**
|
|
7
|
+
* @alias zeneffect
|
|
8
|
+
* @description Optional secondary alias for the canonical zeneffect primitive.
|
|
9
|
+
*/
|
|
10
|
+
export declare function effect(effectOrDependencies: any, optionsOrEffect: any, scopeOverride?: null): () => void;
|
|
11
|
+
/**
|
|
12
|
+
* @alias zenMount
|
|
13
|
+
* @description Optional secondary alias for the canonical zenMount primitive.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mount(callback: any, scopeOverride?: null): () => void;
|