@torpor/view 0.3.0 → 0.3.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/CHANGELOG.md +6 -0
- package/dist/Component-C6Y3UwGs.d.cts +11 -0
- package/dist/Component-C6Y3UwGs.d.cts.map +1 -0
- package/dist/ServerSlotRender-COS6H8Yk.d.cts +41 -0
- package/dist/ServerSlotRender-COS6H8Yk.d.cts.map +1 -0
- package/dist/compile.cjs +3683 -0
- package/dist/compile.cjs.map +1 -0
- package/dist/compile.d.cts +210 -0
- package/dist/compile.d.cts.map +1 -0
- package/dist/formatText-DufG5l83.cjs +500 -0
- package/dist/formatText-DufG5l83.cjs.map +1 -0
- package/dist/index.cjs +906 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +411 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/ssr.cjs +40 -0
- package/dist/ssr.cjs.map +1 -0
- package/dist/ssr.d.cts +19 -0
- package/dist/ssr.d.cts.map +1 -0
- package/package.json +7 -4
- package/tsdown.config.ts +1 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Component } from "./Component-C6Y3UwGs.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/BuildOptions.d.ts
|
|
4
|
+
interface BuildOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to create the component for server side rendering
|
|
7
|
+
*/
|
|
8
|
+
server?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether to create source maps.
|
|
11
|
+
*/
|
|
12
|
+
mapped?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* If true, fragments will be built with calls to createElement etc. If
|
|
15
|
+
* false, fragments will be built with innerHTML. Using createElement is a
|
|
16
|
+
* bit slower, but may be useful in the future for rendering to different
|
|
17
|
+
* targets
|
|
18
|
+
*/
|
|
19
|
+
useCreateElement?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* For internal testing and benchmarking
|
|
22
|
+
*/
|
|
23
|
+
renderFolder?: string;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/compile/types/Import.d.ts
|
|
27
|
+
interface Import {
|
|
28
|
+
name: string;
|
|
29
|
+
alias?: string;
|
|
30
|
+
path: string;
|
|
31
|
+
nonDefault: boolean;
|
|
32
|
+
component: boolean;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/compile/types/SourceRange.d.ts
|
|
36
|
+
interface SourceRange {
|
|
37
|
+
start: number;
|
|
38
|
+
end: number;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/compile/types/ScriptChunk.d.ts
|
|
42
|
+
interface ScriptChunk {
|
|
43
|
+
script: string;
|
|
44
|
+
range: SourceRange;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/compile/types/nodes/Fragment.d.ts
|
|
48
|
+
interface Fragment {
|
|
49
|
+
number: number;
|
|
50
|
+
text: string;
|
|
51
|
+
ns: boolean;
|
|
52
|
+
effects: {
|
|
53
|
+
functionBody: string;
|
|
54
|
+
ranges: SourceRange[];
|
|
55
|
+
offsets: number[];
|
|
56
|
+
lengths: number[];
|
|
57
|
+
}[];
|
|
58
|
+
events: {
|
|
59
|
+
varName: string;
|
|
60
|
+
eventName: string;
|
|
61
|
+
handler: string;
|
|
62
|
+
}[];
|
|
63
|
+
animations: string[];
|
|
64
|
+
endVarName?: string;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/compile/types/nodes/NodeType.d.ts
|
|
68
|
+
type NodeType = "root" | "control" | "component" | "element" | "text" | "special";
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/compile/types/nodes/TemplateNode.d.ts
|
|
71
|
+
interface TemplateNode {
|
|
72
|
+
type: NodeType;
|
|
73
|
+
scopeStyles?: boolean;
|
|
74
|
+
varName?: string;
|
|
75
|
+
handled?: boolean;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/compile/types/nodes/ParentNode.d.ts
|
|
79
|
+
interface ParentNode extends TemplateNode {
|
|
80
|
+
type: NodeType;
|
|
81
|
+
children: TemplateNode[];
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/compile/types/nodes/RootNode.d.ts
|
|
85
|
+
interface RootNode extends ParentNode {
|
|
86
|
+
type: "root";
|
|
87
|
+
children: TemplateNode[];
|
|
88
|
+
fragment?: Fragment;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/compile/types/styles/Attribute.d.ts
|
|
92
|
+
interface Attribute {
|
|
93
|
+
name: string;
|
|
94
|
+
value: string;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/compile/types/styles/StyleBlock.d.ts
|
|
98
|
+
interface StyleBlock {
|
|
99
|
+
selector: string;
|
|
100
|
+
attributes: Attribute[];
|
|
101
|
+
children: StyleBlock[];
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/compile/types/styles/Style.d.ts
|
|
105
|
+
interface Style {
|
|
106
|
+
global: boolean;
|
|
107
|
+
blocks: StyleBlock[];
|
|
108
|
+
hash: string;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/types/TemplateComponent.d.ts
|
|
112
|
+
interface TemplateComponent {
|
|
113
|
+
start?: number;
|
|
114
|
+
/** The component's name */
|
|
115
|
+
name?: string;
|
|
116
|
+
/** Whether the component is defined with a default function */
|
|
117
|
+
default?: boolean;
|
|
118
|
+
/** Params declared by the user in the component's function */
|
|
119
|
+
params?: string;
|
|
120
|
+
markup?: RootNode;
|
|
121
|
+
head?: RootNode;
|
|
122
|
+
style?: Style;
|
|
123
|
+
/** $props that are used in the component's function */
|
|
124
|
+
props?: string[];
|
|
125
|
+
/** $context props that are used in the component's function */
|
|
126
|
+
contextProps?: string[];
|
|
127
|
+
needsContext?: boolean;
|
|
128
|
+
/** $slot props that are used in the component's function */
|
|
129
|
+
slotProps?: string[];
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region src/types/Template.d.ts
|
|
133
|
+
/**
|
|
134
|
+
* The template for a component file, consisting of parts like script, markup and styles
|
|
135
|
+
*/
|
|
136
|
+
interface Template {
|
|
137
|
+
imports: Import[];
|
|
138
|
+
script: ScriptChunk[];
|
|
139
|
+
components: TemplateComponent[];
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/compile/types/SourceMapping.d.ts
|
|
143
|
+
interface SourceMapping {
|
|
144
|
+
script: string;
|
|
145
|
+
source: SourceRange;
|
|
146
|
+
compiled: SourceRange;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/compile/types/BuildResult.d.ts
|
|
150
|
+
interface BuildResult {
|
|
151
|
+
code: string;
|
|
152
|
+
styles: {
|
|
153
|
+
style: string;
|
|
154
|
+
hash: string;
|
|
155
|
+
}[];
|
|
156
|
+
map: SourceMapping[];
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/compile/build.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* Builds a component template into code and styles for rendering
|
|
162
|
+
*
|
|
163
|
+
* @param template The component template, possibly including script, markup and styles
|
|
164
|
+
*
|
|
165
|
+
* @returns The component's code and styles
|
|
166
|
+
*/
|
|
167
|
+
declare function build(template: Template, options?: BuildOptions): BuildResult;
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/compile/buildType.d.ts
|
|
170
|
+
/**
|
|
171
|
+
* Builds a component template into a d.ts file
|
|
172
|
+
*
|
|
173
|
+
* @param name The name of the component
|
|
174
|
+
* @param template The component template, possibly including script, markup and styles
|
|
175
|
+
*
|
|
176
|
+
* @returns The d.ts file content
|
|
177
|
+
*/
|
|
178
|
+
declare function buildType(template: Template, options?: BuildOptions): string;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/compile/types/CompileError.d.ts
|
|
181
|
+
interface CompileError {
|
|
182
|
+
message: string;
|
|
183
|
+
startIndex: number;
|
|
184
|
+
startLine: number;
|
|
185
|
+
startChar: number;
|
|
186
|
+
endIndex: number;
|
|
187
|
+
endLine: number;
|
|
188
|
+
endChar: number;
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/compile/types/ParseResult.d.ts
|
|
192
|
+
interface ParseResult {
|
|
193
|
+
ok: boolean;
|
|
194
|
+
errors: CompileError[];
|
|
195
|
+
template?: Template;
|
|
196
|
+
}
|
|
197
|
+
//#endregion
|
|
198
|
+
//#region src/compile/parse.d.ts
|
|
199
|
+
/**
|
|
200
|
+
* Parses source code into a component template
|
|
201
|
+
*
|
|
202
|
+
* @param source The source code
|
|
203
|
+
*
|
|
204
|
+
* @returns A result indicating whether parsing was ok, and if so, containing
|
|
205
|
+
* the component template's parts such as script, markup and styles
|
|
206
|
+
*/
|
|
207
|
+
declare function parse(source: string): ParseResult;
|
|
208
|
+
//#endregion
|
|
209
|
+
export { type Component, type Template, build, buildType, parse };
|
|
210
|
+
//# sourceMappingURL=compile.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.cts","names":[],"sources":["../src/types/BuildOptions.ts","../src/compile/types/Import.ts","../src/compile/types/SourceRange.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/Attribute.ts","../src/compile/types/styles/StyleBlock.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/buildType.ts","../src/compile/types/CompileError.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts"],"sourcesContent":[],"mappings":";;;UAAyB,YAAA;;;;;;;;;;;;;;;EGAI,gBAEJ,CAAA,EAAA,OAAA;;;;ECFI,YAEJ,CAAA,EAAA,MAAA;;;;UHFA,MAAA;;;MDAA,EAAA,MAAA;;;;;;UEAA,WAAA;;;;;;UCEA,WAAA;;OHFA,EGIjB,WHJiB;;;;UIEA,QAAA;;MJFA,EAAA,MAAA;;;;UCAA,EGQf,WHRe,EAAA;;;;QCAA,EAAA;;;;ECAI,CAAA,EAEJ;;;;;;KEFpB,QAAA;;;UCEoB,YAAA;QAClB;aNHkB,CAAA,EAAA,OAAA;;;;;;UOGA,UAAA,SAAmB;MPHnB,EOIlB,QPJkB;YOKd;;;;APLc,UQIA,QAAA,SAAiB,URJjB,CAAA;;YQMd;aAGC;;;;UCTa,SAAA;;;;;;UCEA,UAAA;;YVFA,EUIZ,SVJY,EAAA;YUKd;;;;UCHc,KAAA;;QXFA,EWIhB,UXJgB,EAAA;;;;;UYGA,iBAAA;OZHA,CAAA,EAAA,MAAA;;;;SCAA,CAAA,EAAA,OAAA;;;WWWf;MVXe,CAAA,EUYjB,QVZiB;UUahB;;;ETboB;;;;ECAA,SAEJ,CAAA,EAAA,MAAA,EAAA;;;;;;;USKA,QAAA;SZPA,EYQf,MZRe,EAAA;UYShB;cACI;;;;UCRY,aAAA;;QdFA,EcIhB,WdJgB;YcKd;;;;UCHc,WAAA;;QfFA,EAAA;;;;KCAA,EcQnB,adRmB,EAAA;;;;;;;;;;;iBeeD,KAAA,WAAgB,oBAAoB,eAAe;;;;;;;;;;;iBCHnD,SAAA,WAAoB,oBAAoB;;;UCZvC,YAAA;;;WlBAA,EAAA,MAAA;;;;SCAA,EAAA,MAAA;;;;UkBGA,WAAA;MnBHA,OAAA;UmBKhB;aACG;;;;;;;;;;;;iBCKY,KAAA,kBAAuB"}
|
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/render/context.ts
|
|
3
|
+
const context = {
|
|
4
|
+
activeTarget: null,
|
|
5
|
+
previousEffect: null,
|
|
6
|
+
extent: 0,
|
|
7
|
+
batch: 0,
|
|
8
|
+
batchOperation: 0,
|
|
9
|
+
registerComputed: null,
|
|
10
|
+
firstEffectToRun: null,
|
|
11
|
+
firstSignalToUpdate: null,
|
|
12
|
+
activeRange: null,
|
|
13
|
+
previousRange: null,
|
|
14
|
+
rootRange: null,
|
|
15
|
+
mountEffects: [],
|
|
16
|
+
stashedEvents: [],
|
|
17
|
+
stashedAnimations: [],
|
|
18
|
+
hydrationNode: null
|
|
19
|
+
};
|
|
20
|
+
var context_default = context;
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/constants.ts
|
|
24
|
+
/**
|
|
25
|
+
* The type of a Signal object.
|
|
26
|
+
*/
|
|
27
|
+
const SIGNAL_TYPE = 0;
|
|
28
|
+
/**
|
|
29
|
+
* The type of a Computed object.
|
|
30
|
+
*/
|
|
31
|
+
const COMPUTED_TYPE = 1;
|
|
32
|
+
/**
|
|
33
|
+
* The type of an Effect object.
|
|
34
|
+
*/
|
|
35
|
+
const EFFECT_TYPE = 2;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/watch/clearSources.ts
|
|
39
|
+
/**
|
|
40
|
+
* Clear unused source subscriptions after each Computed or Effect has been run.
|
|
41
|
+
*/
|
|
42
|
+
function clearSources(target) {
|
|
43
|
+
let previousSub = null;
|
|
44
|
+
for (let clearSub = target.firstSource; clearSub !== null; clearSub = clearSub.nextSource) if (target.didError || !clearSub.active) {
|
|
45
|
+
if (previousSub === null) target.firstSource = clearSub.nextSource;
|
|
46
|
+
else previousSub.nextSource = clearSub.nextSource;
|
|
47
|
+
if (clearSub.previousTarget === null) {
|
|
48
|
+
if (clearSub.source.firstTarget === clearSub) clearSub.source.firstTarget = clearSub.nextTarget;
|
|
49
|
+
} else clearSub.previousTarget.nextTarget = clearSub.nextTarget;
|
|
50
|
+
} else {
|
|
51
|
+
clearSub.recalc = false;
|
|
52
|
+
previousSub = clearSub;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/watch/deactivateSources.ts
|
|
58
|
+
/**
|
|
59
|
+
* Sets source subscriptions to inactive for a Computed or Effect.
|
|
60
|
+
*/
|
|
61
|
+
function deactivateSources(target) {
|
|
62
|
+
for (let sourceSub = target.firstSource; sourceSub !== null; sourceSub = sourceSub.nextSource) sourceSub.active = false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/watch/trackEffect.ts
|
|
67
|
+
/**
|
|
68
|
+
* If there's an active target, subscribe it to this signal, so that it will be
|
|
69
|
+
* run when the signal changes.
|
|
70
|
+
*/
|
|
71
|
+
function trackEffect(signal) {
|
|
72
|
+
const target = context_default.activeTarget;
|
|
73
|
+
if (target !== null) {
|
|
74
|
+
let sub = null;
|
|
75
|
+
let lastSub = null;
|
|
76
|
+
for (let nextSub = signal.firstTarget; nextSub !== null; nextSub = nextSub.nextTarget) {
|
|
77
|
+
lastSub = nextSub;
|
|
78
|
+
if (nextSub.target === target) {
|
|
79
|
+
sub = nextSub;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (sub === null) {
|
|
84
|
+
sub = {
|
|
85
|
+
source: signal,
|
|
86
|
+
target,
|
|
87
|
+
previousTarget: lastSub,
|
|
88
|
+
nextTarget: null,
|
|
89
|
+
nextSource: null,
|
|
90
|
+
active: true,
|
|
91
|
+
recalc: false
|
|
92
|
+
};
|
|
93
|
+
if (lastSub === null) signal.firstTarget = sub;
|
|
94
|
+
else lastSub.nextTarget = sub;
|
|
95
|
+
if (target.firstSource === null) target.firstSource = sub;
|
|
96
|
+
else {
|
|
97
|
+
let lastEffectSub = target.firstSource;
|
|
98
|
+
for (let nextSub = lastEffectSub.nextSource; nextSub !== null; nextSub = nextSub.nextSource) lastEffectSub = nextSub;
|
|
99
|
+
lastEffectSub.nextSource = sub;
|
|
100
|
+
}
|
|
101
|
+
} else sub.active = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/watch/runComputed.ts
|
|
107
|
+
function runComputed(computed) {
|
|
108
|
+
const oldActiveTarget = context_default.activeTarget;
|
|
109
|
+
computed.running = true;
|
|
110
|
+
computed.didError = false;
|
|
111
|
+
try {
|
|
112
|
+
context_default.activeTarget = computed;
|
|
113
|
+
computed.value = computed.run();
|
|
114
|
+
} catch (err) {
|
|
115
|
+
computed.didError = true;
|
|
116
|
+
computed.value = err;
|
|
117
|
+
throw err;
|
|
118
|
+
} finally {
|
|
119
|
+
context_default.activeTarget = oldActiveTarget;
|
|
120
|
+
computed.running = false;
|
|
121
|
+
}
|
|
122
|
+
trackEffect(computed);
|
|
123
|
+
return computed.value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/watch/checkComputed.ts
|
|
128
|
+
/**
|
|
129
|
+
* Checks whether a Computed value should be re-run (which will be true if any
|
|
130
|
+
* of its sources have changed) and re-runs it if necessary.
|
|
131
|
+
*/
|
|
132
|
+
function checkComputed(computed) {
|
|
133
|
+
let rerun = checkSources(computed);
|
|
134
|
+
let changed = false;
|
|
135
|
+
if (rerun) {
|
|
136
|
+
deactivateSources(computed);
|
|
137
|
+
const oldValue = computed.value;
|
|
138
|
+
runComputed(computed);
|
|
139
|
+
changed = computed.value !== oldValue;
|
|
140
|
+
clearSources(computed);
|
|
141
|
+
}
|
|
142
|
+
computed.recalc = false;
|
|
143
|
+
if (!changed) for (let targetSub = computed.firstTarget; targetSub !== null; targetSub = targetSub.nextTarget) {
|
|
144
|
+
targetSub.active = true;
|
|
145
|
+
targetSub.recalc = false;
|
|
146
|
+
}
|
|
147
|
+
return changed;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/watch/checkSources.ts
|
|
152
|
+
/**
|
|
153
|
+
* Checks whether a Computed or Effect should be re-run (which will be true if
|
|
154
|
+
* any of its sources have changed).
|
|
155
|
+
*/
|
|
156
|
+
function checkSources(target) {
|
|
157
|
+
let haveComputed = false;
|
|
158
|
+
for (let sourceSub = target.firstSource; sourceSub !== null; sourceSub = sourceSub.nextSource) if (sourceSub.recalc) if (sourceSub.source.type === SIGNAL_TYPE) return true;
|
|
159
|
+
else if (sourceSub.source.recalc) haveComputed = true;
|
|
160
|
+
else return true;
|
|
161
|
+
if (haveComputed) {
|
|
162
|
+
for (let sourceSub = target.firstSource; sourceSub !== null; sourceSub = sourceSub.nextSource) if (sourceSub.recalc && sourceSub.source.type === COMPUTED_TYPE && sourceSub.source.recalc) {
|
|
163
|
+
const oldActiveTarget = context_default.activeTarget;
|
|
164
|
+
context_default.activeTarget = target;
|
|
165
|
+
const recalc = checkComputed(sourceSub.source);
|
|
166
|
+
context_default.activeTarget = oldActiveTarget;
|
|
167
|
+
if (recalc) return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/watch/runCleanups.ts
|
|
175
|
+
/**
|
|
176
|
+
* Runs cleanup functions for the effect and its children.
|
|
177
|
+
*/
|
|
178
|
+
function runCleanups(effect) {
|
|
179
|
+
let effectToClean = effect;
|
|
180
|
+
for (let i = 0; i < effect.extent; i++) {
|
|
181
|
+
if (typeof effectToClean.cleanup === "function") {
|
|
182
|
+
const oldActiveTarget = context_default.activeTarget;
|
|
183
|
+
context_default.activeTarget = null;
|
|
184
|
+
try {
|
|
185
|
+
effectToClean.cleanup();
|
|
186
|
+
} catch (err) {
|
|
187
|
+
effectToClean.didError = true;
|
|
188
|
+
clearSources(effectToClean);
|
|
189
|
+
throw err;
|
|
190
|
+
} finally {
|
|
191
|
+
effectToClean.cleanup = void 0;
|
|
192
|
+
context_default.activeTarget = oldActiveTarget;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const nextEffect = effectToClean.nextEffect;
|
|
196
|
+
if (i !== 0 && effect.nextEffectToRun === effectToClean) {
|
|
197
|
+
effect.nextEffectToRun = effectToClean.nextEffectToRun;
|
|
198
|
+
effectToClean.nextEffect = effectToClean.nextEffectToRun = null;
|
|
199
|
+
}
|
|
200
|
+
effectToClean = nextEffect;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/watch/batchStart.ts
|
|
206
|
+
function batchStart() {
|
|
207
|
+
context_default.batch++;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/watch/runEffect.ts
|
|
212
|
+
function runEffect(effect) {
|
|
213
|
+
const oldActiveTarget = context_default.activeTarget;
|
|
214
|
+
const oldExtent = context_default.extent;
|
|
215
|
+
effect.didError = false;
|
|
216
|
+
batchStart();
|
|
217
|
+
try {
|
|
218
|
+
if (context_default.previousEffect !== null) context_default.previousEffect.nextEffect = effect;
|
|
219
|
+
context_default.activeTarget = effect;
|
|
220
|
+
context_default.previousEffect = effect;
|
|
221
|
+
context_default.extent = 1;
|
|
222
|
+
effect.cleanup = effect.run();
|
|
223
|
+
effect.extent = context_default.extent;
|
|
224
|
+
} catch (err) {
|
|
225
|
+
effect.didError = true;
|
|
226
|
+
clearSources(effect);
|
|
227
|
+
throw err;
|
|
228
|
+
} finally {
|
|
229
|
+
context_default.activeTarget = oldActiveTarget;
|
|
230
|
+
context_default.extent += oldExtent - 1;
|
|
231
|
+
batchEnd();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/watch/checkEffect.ts
|
|
237
|
+
/**
|
|
238
|
+
* Checks whether an Effect should be re-run (which will be true if any
|
|
239
|
+
* of its sources have changed) and re-runs it if necessary.
|
|
240
|
+
*/
|
|
241
|
+
function checkEffect(effect) {
|
|
242
|
+
if (checkSources(effect)) {
|
|
243
|
+
runCleanups(effect);
|
|
244
|
+
deactivateSources(effect);
|
|
245
|
+
runEffect(effect);
|
|
246
|
+
clearSources(effect);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/watch/clearTargets.ts
|
|
252
|
+
/**
|
|
253
|
+
* Clear unused target subscriptions after all Effects have been run.
|
|
254
|
+
*/
|
|
255
|
+
function clearTargets(source) {
|
|
256
|
+
let previousSub = null;
|
|
257
|
+
for (let clearSub = source.firstTarget; clearSub !== null; clearSub = clearSub.nextTarget) if (!clearSub.active) if (previousSub === null) source.firstTarget = clearSub.nextTarget;
|
|
258
|
+
else previousSub.nextTarget = clearSub.nextTarget;
|
|
259
|
+
else previousSub = clearSub;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/watch/triggerEffects.ts
|
|
264
|
+
/**
|
|
265
|
+
* Runs the effects that have been collected during the batch.
|
|
266
|
+
*/
|
|
267
|
+
function triggerEffects() {
|
|
268
|
+
let didError = false;
|
|
269
|
+
let error;
|
|
270
|
+
let effect = context_default.firstEffectToRun;
|
|
271
|
+
while (effect !== null) {
|
|
272
|
+
context_default.batchOperation++;
|
|
273
|
+
try {
|
|
274
|
+
checkEffect(effect);
|
|
275
|
+
} catch (err) {
|
|
276
|
+
if (!didError) {
|
|
277
|
+
didError = true;
|
|
278
|
+
error = err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
effect = effect.nextEffectToRun;
|
|
282
|
+
}
|
|
283
|
+
effect = context_default.firstEffectToRun;
|
|
284
|
+
context_default.firstEffectToRun = null;
|
|
285
|
+
while (effect !== null) {
|
|
286
|
+
let nextEffect = effect.nextEffectToRun;
|
|
287
|
+
effect.nextEffectToRun = null;
|
|
288
|
+
effect = nextEffect;
|
|
289
|
+
}
|
|
290
|
+
let signal = context_default.firstSignalToUpdate;
|
|
291
|
+
context_default.firstSignalToUpdate = null;
|
|
292
|
+
while (signal !== null) {
|
|
293
|
+
clearTargets(signal);
|
|
294
|
+
const nextSignal = signal.nextSignalToUpdate;
|
|
295
|
+
signal.nextSignalToUpdate = null;
|
|
296
|
+
signal = nextSignal;
|
|
297
|
+
}
|
|
298
|
+
if (didError) throw error;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/watch/batchEnd.ts
|
|
303
|
+
function batchEnd() {
|
|
304
|
+
if (context_default.batch > 1) {
|
|
305
|
+
context_default.batch--;
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
triggerEffects();
|
|
310
|
+
} finally {
|
|
311
|
+
context_default.batch = 0;
|
|
312
|
+
context_default.batchOperation = 0;
|
|
313
|
+
context_default.previousEffect = null;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/render/$batch.ts
|
|
319
|
+
/**
|
|
320
|
+
* Runs updates to proxy values in a batch, where the updates are stored in
|
|
321
|
+
* context, and dependent effects are run all at once at the end.
|
|
322
|
+
*
|
|
323
|
+
* @param fn The function containing the batched updates to run.
|
|
324
|
+
*/
|
|
325
|
+
function $batch(fn) {
|
|
326
|
+
if (context_default.batch > 0) return fn();
|
|
327
|
+
batchStart();
|
|
328
|
+
try {
|
|
329
|
+
return fn();
|
|
330
|
+
} finally {
|
|
331
|
+
batchEnd();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/render/$cache.ts
|
|
337
|
+
/**
|
|
338
|
+
* Caches a computed value from signals accessed in a property getter.
|
|
339
|
+
*
|
|
340
|
+
* @param fn The function containing the signals to compute and cache.
|
|
341
|
+
*/
|
|
342
|
+
function $cache(fn) {
|
|
343
|
+
if (context_default.registerComputed === null) throw new Error("$cache must be used in a getter");
|
|
344
|
+
let computed = {
|
|
345
|
+
type: COMPUTED_TYPE,
|
|
346
|
+
value: null,
|
|
347
|
+
run: fn,
|
|
348
|
+
firstSource: null,
|
|
349
|
+
firstTarget: null,
|
|
350
|
+
recalc: false,
|
|
351
|
+
running: false,
|
|
352
|
+
didError: false,
|
|
353
|
+
rollback: null
|
|
354
|
+
};
|
|
355
|
+
context_default.registerComputed(computed);
|
|
356
|
+
runComputed(computed);
|
|
357
|
+
return computed.value;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
//#endregion
|
|
361
|
+
//#region src/render/$peek.ts
|
|
362
|
+
function $peek(fn) {
|
|
363
|
+
const oldActiveTarget = context_default.activeTarget;
|
|
364
|
+
context_default.activeTarget = null;
|
|
365
|
+
const result = fn();
|
|
366
|
+
context_default.activeTarget = oldActiveTarget;
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/render/buildClasses.ts
|
|
372
|
+
function buildClasses(value, styleHash) {
|
|
373
|
+
if (typeof value === "string") {
|
|
374
|
+
if (styleHash !== void 0) value += " " + styleHash;
|
|
375
|
+
return value;
|
|
376
|
+
} else {
|
|
377
|
+
let classes = [];
|
|
378
|
+
gatherNames("", value, classes);
|
|
379
|
+
if (styleHash !== void 0) classes.push(styleHash);
|
|
380
|
+
return classes.join(" ");
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function gatherNames(name, value, classes) {
|
|
384
|
+
if (value) if (Array.isArray(value)) for (let v of value) gatherNames(v, v, classes);
|
|
385
|
+
else if (typeof value === "object") for (let [n, v] of Object.entries(value)) gatherNames(n, v, classes);
|
|
386
|
+
else classes.push(name);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/render/buildStyles.ts
|
|
391
|
+
function buildStyles(value) {
|
|
392
|
+
if (typeof value === "string") return value;
|
|
393
|
+
else {
|
|
394
|
+
let styles = [];
|
|
395
|
+
if (value) {
|
|
396
|
+
if (Array.isArray(value)) for (let v of value) styles.push(v);
|
|
397
|
+
else if (typeof value === "object") for (let [n, v] of Object.entries(value)) styles.push(`${n}: ${v}`);
|
|
398
|
+
}
|
|
399
|
+
return styles.join("; ");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
//#endregion
|
|
404
|
+
//#region src/render/formatText.ts
|
|
405
|
+
function formatText(value) {
|
|
406
|
+
return value ?? "";
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
Object.defineProperty(exports, '$batch', {
|
|
411
|
+
enumerable: true,
|
|
412
|
+
get: function () {
|
|
413
|
+
return $batch;
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
Object.defineProperty(exports, '$cache', {
|
|
417
|
+
enumerable: true,
|
|
418
|
+
get: function () {
|
|
419
|
+
return $cache;
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
Object.defineProperty(exports, '$peek', {
|
|
423
|
+
enumerable: true,
|
|
424
|
+
get: function () {
|
|
425
|
+
return $peek;
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
Object.defineProperty(exports, 'COMPUTED_TYPE', {
|
|
429
|
+
enumerable: true,
|
|
430
|
+
get: function () {
|
|
431
|
+
return COMPUTED_TYPE;
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
Object.defineProperty(exports, 'EFFECT_TYPE', {
|
|
435
|
+
enumerable: true,
|
|
436
|
+
get: function () {
|
|
437
|
+
return EFFECT_TYPE;
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
Object.defineProperty(exports, 'SIGNAL_TYPE', {
|
|
441
|
+
enumerable: true,
|
|
442
|
+
get: function () {
|
|
443
|
+
return SIGNAL_TYPE;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
Object.defineProperty(exports, 'batchEnd', {
|
|
447
|
+
enumerable: true,
|
|
448
|
+
get: function () {
|
|
449
|
+
return batchEnd;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
Object.defineProperty(exports, 'batchStart', {
|
|
453
|
+
enumerable: true,
|
|
454
|
+
get: function () {
|
|
455
|
+
return batchStart;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(exports, 'buildClasses', {
|
|
459
|
+
enumerable: true,
|
|
460
|
+
get: function () {
|
|
461
|
+
return buildClasses;
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
Object.defineProperty(exports, 'buildStyles', {
|
|
465
|
+
enumerable: true,
|
|
466
|
+
get: function () {
|
|
467
|
+
return buildStyles;
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
Object.defineProperty(exports, 'checkComputed', {
|
|
471
|
+
enumerable: true,
|
|
472
|
+
get: function () {
|
|
473
|
+
return checkComputed;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
Object.defineProperty(exports, 'context_default', {
|
|
477
|
+
enumerable: true,
|
|
478
|
+
get: function () {
|
|
479
|
+
return context_default;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
Object.defineProperty(exports, 'formatText', {
|
|
483
|
+
enumerable: true,
|
|
484
|
+
get: function () {
|
|
485
|
+
return formatText;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
Object.defineProperty(exports, 'runEffect', {
|
|
489
|
+
enumerable: true,
|
|
490
|
+
get: function () {
|
|
491
|
+
return runEffect;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
Object.defineProperty(exports, 'trackEffect', {
|
|
495
|
+
enumerable: true,
|
|
496
|
+
get: function () {
|
|
497
|
+
return trackEffect;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
//# sourceMappingURL=formatText-DufG5l83.cjs.map
|