@vivliostyle/core 2.24.3 → 2.25.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/lib/vivliostyle/adaptive-viewer.d.ts +167 -167
- package/lib/vivliostyle/asserts.d.ts +21 -21
- package/lib/vivliostyle/assets.d.ts +35 -35
- package/lib/vivliostyle/base.d.ts +189 -189
- package/lib/vivliostyle/break-position.d.ts +39 -39
- package/lib/vivliostyle/break.d.ts +112 -112
- package/lib/vivliostyle/cfi.d.ts +77 -77
- package/lib/vivliostyle/columns.d.ts +52 -52
- package/lib/vivliostyle/constants.d.ts +53 -53
- package/lib/vivliostyle/core-viewer.d.ts +240 -240
- package/lib/vivliostyle/counters.d.ts +130 -127
- package/lib/vivliostyle/css-cascade.d.ts +974 -954
- package/lib/vivliostyle/css-logical-util.d.ts +3 -3
- package/lib/vivliostyle/css-page.d.ts +451 -451
- package/lib/vivliostyle/css-parser.d.ts +320 -320
- package/lib/vivliostyle/css-prop.d.ts +74 -74
- package/lib/vivliostyle/css-styler.d.ts +210 -210
- package/lib/vivliostyle/css-tokenizer.d.ts +243 -243
- package/lib/vivliostyle/css-validator.d.ts +319 -319
- package/lib/vivliostyle/css.d.ts +205 -205
- package/lib/vivliostyle/diff.d.ts +26 -26
- package/lib/vivliostyle/display.d.ts +62 -57
- package/lib/vivliostyle/epub.d.ts +329 -329
- package/lib/vivliostyle/exprs.d.ts +395 -395
- package/lib/vivliostyle/font.d.ts +87 -87
- package/lib/vivliostyle/footnotes.d.ts +41 -41
- package/lib/vivliostyle/geometry-util.d.ts +110 -110
- package/lib/vivliostyle/layout-helper.d.ts +16 -15
- package/lib/vivliostyle/layout-processor.d.ts +73 -73
- package/lib/vivliostyle/layout-retryers.d.ts +21 -21
- package/lib/vivliostyle/layout-util.d.ts +55 -55
- package/lib/vivliostyle/layout.d.ts +456 -456
- package/lib/vivliostyle/logging.d.ts +56 -56
- package/lib/vivliostyle/matchers.d.ts +36 -36
- package/lib/vivliostyle/math-util.d.ts +22 -22
- package/lib/vivliostyle/net.d.ts +72 -72
- package/lib/vivliostyle/ops.d.ts +263 -263
- package/lib/vivliostyle/page-floats.d.ts +178 -178
- package/lib/vivliostyle/page-master.d.ts +247 -247
- package/lib/vivliostyle/plugin.d.ts +172 -172
- package/lib/vivliostyle/print.d.ts +7 -7
- package/lib/vivliostyle/profile.d.ts +59 -59
- package/lib/vivliostyle/pseudo-element.d.ts +32 -32
- package/lib/vivliostyle/repetitive-element.d.ts +162 -162
- package/lib/vivliostyle/scripts.d.ts +15 -15
- package/lib/vivliostyle/sha1.d.ts +33 -33
- package/lib/vivliostyle/shared.d.ts +24 -24
- package/lib/vivliostyle/sizing.d.ts +29 -29
- package/lib/vivliostyle/table.d.ts +263 -263
- package/lib/vivliostyle/task-util.d.ts +37 -37
- package/lib/vivliostyle/task.d.ts +357 -357
- package/lib/vivliostyle/text-polyfill.d.ts +3 -3
- package/lib/vivliostyle/toc.d.ts +64 -64
- package/lib/vivliostyle/types.d.ts +977 -977
- package/lib/vivliostyle/urls.d.ts +25 -25
- package/lib/vivliostyle/vgen.d.ts +213 -213
- package/lib/vivliostyle/viewer-app.d.ts +19 -19
- package/lib/vivliostyle/vtree.d.ts +392 -392
- package/lib/vivliostyle/xml-doc.d.ts +88 -88
- package/lib/vivliostyle.d.ts +6 -6
- package/lib/vivliostyle.js +1 -1
- package/lib/vivliostyle.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,357 +1,357 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2013 Google, Inc.
|
|
3
|
-
* Copyright 2015 Trim-marks Inc.
|
|
4
|
-
* Copyright 2019 Vivliostyle Foundation
|
|
5
|
-
*
|
|
6
|
-
* Vivliostyle.js is free software: you can redistribute it and/or modify
|
|
7
|
-
* it under the terms of the GNU Affero General Public License as published by
|
|
8
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
* (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* Vivliostyle.js is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
* GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public License
|
|
17
|
-
* along with Vivliostyle.js. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
-
*
|
|
19
|
-
* @fileoverview Task - Support for asynchronous execution and cooperative
|
|
20
|
-
* multitasking.
|
|
21
|
-
*/
|
|
22
|
-
import * as Base from "./base";
|
|
23
|
-
/**
|
|
24
|
-
* External timer. Only needed for testing.
|
|
25
|
-
*/
|
|
26
|
-
export interface Timer {
|
|
27
|
-
/**
|
|
28
|
-
* @return current time in milliseconds.
|
|
29
|
-
*/
|
|
30
|
-
currentTime(): number;
|
|
31
|
-
/**
|
|
32
|
-
* Calls function after a given timeout.
|
|
33
|
-
* @param fn function to call.
|
|
34
|
-
* @param delay timeout in milliseconds.
|
|
35
|
-
* @return unique number that can be used to clear the timeout.
|
|
36
|
-
*/
|
|
37
|
-
setTimeout(fn: () => void, delay: number): number;
|
|
38
|
-
/**
|
|
39
|
-
* Calls function after a given timeout.
|
|
40
|
-
* @param token timeout token.
|
|
41
|
-
*/
|
|
42
|
-
clearTimeout(token: number): void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Result of an asynchronous function that may be available immediately or
|
|
46
|
-
* some time later. Similar to Deferred.
|
|
47
|
-
* @template T
|
|
48
|
-
*/
|
|
49
|
-
export interface Result<T> {
|
|
50
|
-
/**
|
|
51
|
-
* Call the given function when asynchronous function is finished. Callback
|
|
52
|
-
* is executed in the task's context.
|
|
53
|
-
*/
|
|
54
|
-
then(callback: (p1: T) => void): void;
|
|
55
|
-
/**
|
|
56
|
-
* Call the given asynchronous function when some asynchronous function is
|
|
57
|
-
* finished. Callback is executed in the task's context.
|
|
58
|
-
* @template T1
|
|
59
|
-
*/
|
|
60
|
-
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
61
|
-
/**
|
|
62
|
-
* Produce a Result that resolves to the given value when this Result is
|
|
63
|
-
* resolved.
|
|
64
|
-
* @template T1
|
|
65
|
-
*/
|
|
66
|
-
thenReturn<T1>(result: T1): Result<T1>;
|
|
67
|
-
/**
|
|
68
|
-
* Finish given frame with the result value when result becomes ready.
|
|
69
|
-
*/
|
|
70
|
-
thenFinish(frame: Frame<T>): void;
|
|
71
|
-
/**
|
|
72
|
-
* Check if this Result is still pending.
|
|
73
|
-
*/
|
|
74
|
-
isPending(): boolean;
|
|
75
|
-
/**
|
|
76
|
-
* If this Result is resolved, return the value that it holds.
|
|
77
|
-
*/
|
|
78
|
-
get(): T | null;
|
|
79
|
-
}
|
|
80
|
-
export declare let privateCurrentTask: Task | null;
|
|
81
|
-
export declare let primaryScheduler: Scheduler | null;
|
|
82
|
-
/**
|
|
83
|
-
* Returns current task.
|
|
84
|
-
*/
|
|
85
|
-
export declare function currentTask(): Task | null;
|
|
86
|
-
/**
|
|
87
|
-
* Create and return a new frame with the given name.
|
|
88
|
-
*/
|
|
89
|
-
export declare function newFrame<T>(name: string): Frame<T>;
|
|
90
|
-
export declare function newEventSource(): EventSource;
|
|
91
|
-
export declare function newScheduler(opt_timer?: Timer): Scheduler;
|
|
92
|
-
/**
|
|
93
|
-
* @template T
|
|
94
|
-
*/
|
|
95
|
-
export declare function newResult<T>(opt_value: T): Result<T>;
|
|
96
|
-
/**
|
|
97
|
-
* Creates a new frame and runs code in its context, catching synchronous and
|
|
98
|
-
* asynchronous errors. If an error occurs, onErr is run (in the context of
|
|
99
|
-
* the same frame). As usual, onErr is supposed either produce a result or raise
|
|
100
|
-
* an exception.
|
|
101
|
-
*/
|
|
102
|
-
export declare function handle<T>(name: any, code: (p1: Frame<T>) => void, onErr: (p1: Frame<T>, p2: Error) => void): Result<T>;
|
|
103
|
-
export declare function start<T>(func: () => Result<T>, opt_name?: string): Task;
|
|
104
|
-
/**
|
|
105
|
-
* Frame state.
|
|
106
|
-
* @enum {number}
|
|
107
|
-
*/
|
|
108
|
-
export declare enum FrameState {
|
|
109
|
-
INIT = 0,
|
|
110
|
-
ACTIVE = 1,
|
|
111
|
-
FINISHED = 2,
|
|
112
|
-
DEAD = 3
|
|
113
|
-
}
|
|
114
|
-
export declare class TimerImpl implements Timer {
|
|
115
|
-
/** @override */
|
|
116
|
-
currentTime(): number;
|
|
117
|
-
/** @override */
|
|
118
|
-
setTimeout(fn: () => void, delay: number): number;
|
|
119
|
-
/** @override */
|
|
120
|
-
clearTimeout(token: number): void;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* A class to create tasks.
|
|
124
|
-
*/
|
|
125
|
-
export declare class Scheduler {
|
|
126
|
-
timer: Timer;
|
|
127
|
-
timeout: number;
|
|
128
|
-
slice: number;
|
|
129
|
-
sliceOverTime: number;
|
|
130
|
-
queue: Base.PriorityQueue;
|
|
131
|
-
wakeupTime: number | null;
|
|
132
|
-
timeoutToken: number | null;
|
|
133
|
-
inTimeSlice: boolean;
|
|
134
|
-
order: number;
|
|
135
|
-
constructor(timer: Timer);
|
|
136
|
-
/**
|
|
137
|
-
* Sets time slice length.
|
|
138
|
-
* @param slice length in milliseconds.
|
|
139
|
-
*/
|
|
140
|
-
setSlice(slice: number): void;
|
|
141
|
-
/**
|
|
142
|
-
* Sets timeout between time slices.
|
|
143
|
-
* @param timeout in milliseconds.
|
|
144
|
-
*/
|
|
145
|
-
setTimeout(timeout: number): void;
|
|
146
|
-
/**
|
|
147
|
-
* Checks if the current time slice is over.
|
|
148
|
-
*/
|
|
149
|
-
isTimeSliceOver(): boolean;
|
|
150
|
-
private arm;
|
|
151
|
-
schedule(continuation: Continuation<any>, opt_delay?: number): void;
|
|
152
|
-
private doTimeSlice;
|
|
153
|
-
run(func: () => Result<any>, opt_name?: string): Task;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Task suspension point.
|
|
157
|
-
* @template T
|
|
158
|
-
*/
|
|
159
|
-
export declare class Continuation<T> implements Base.Comparable {
|
|
160
|
-
task: Task;
|
|
161
|
-
scheduledTime: number;
|
|
162
|
-
order: number;
|
|
163
|
-
result: T;
|
|
164
|
-
canceled: boolean;
|
|
165
|
-
constructor(task: Task);
|
|
166
|
-
/** @override */
|
|
167
|
-
compare(otherComp: Base.Comparable): number;
|
|
168
|
-
/**
|
|
169
|
-
* Continuation's task
|
|
170
|
-
*/
|
|
171
|
-
getTask(): Task;
|
|
172
|
-
/**
|
|
173
|
-
* Schedule task continuation after the given (optional) delay.
|
|
174
|
-
* @param opt_delay optional delay in milliseconds.
|
|
175
|
-
*/
|
|
176
|
-
schedule(result: T, opt_delay?: number): void;
|
|
177
|
-
resumeInternal(): boolean;
|
|
178
|
-
/**
|
|
179
|
-
* Cancel continuation
|
|
180
|
-
*/
|
|
181
|
-
cancel(): void;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* An asynchronous, time-sliced task.
|
|
185
|
-
*/
|
|
186
|
-
export declare class Task {
|
|
187
|
-
scheduler: Scheduler;
|
|
188
|
-
name: string;
|
|
189
|
-
callbacks: (() => void)[];
|
|
190
|
-
exception: Error | null;
|
|
191
|
-
running: boolean;
|
|
192
|
-
result: any;
|
|
193
|
-
waitTarget: string | null;
|
|
194
|
-
top: Frame<any> | null;
|
|
195
|
-
continuation: Continuation<any> | null;
|
|
196
|
-
constructor(scheduler: Scheduler, name: string);
|
|
197
|
-
/**
|
|
198
|
-
* @return task name.
|
|
199
|
-
*/
|
|
200
|
-
getName(): string;
|
|
201
|
-
/**
|
|
202
|
-
* @param err exception to throw in the task's context.
|
|
203
|
-
*/
|
|
204
|
-
interrupt(err: Error): void;
|
|
205
|
-
/**
|
|
206
|
-
* @return this task's scheduler.
|
|
207
|
-
*/
|
|
208
|
-
getScheduler(): Scheduler;
|
|
209
|
-
/**
|
|
210
|
-
* @return true if task is still running.
|
|
211
|
-
*/
|
|
212
|
-
isRunning(): boolean;
|
|
213
|
-
/**
|
|
214
|
-
* Register a callback to be called when the task is done. Callback is not
|
|
215
|
-
* executed in any task context. Multiple callbacks can be registered and
|
|
216
|
-
* they will be called in the registration order.
|
|
217
|
-
*/
|
|
218
|
-
whenDone(callback: () => void): void;
|
|
219
|
-
/**
|
|
220
|
-
* Wait for task to finish (from another task).
|
|
221
|
-
*/
|
|
222
|
-
join(): Result<any>;
|
|
223
|
-
/**
|
|
224
|
-
* Unwind the stack. We have two stacks: async (maintained by frame
|
|
225
|
-
* parent link) and sync (regular JavaScript stack).
|
|
226
|
-
*/
|
|
227
|
-
unwind(): void;
|
|
228
|
-
raise(err: Error, opt_frame?: Frame<any>): void;
|
|
229
|
-
/**
|
|
230
|
-
* Fill the stack trace in the exception
|
|
231
|
-
* @param err exception
|
|
232
|
-
*/
|
|
233
|
-
fillStack(err: Error): void;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* @template T
|
|
237
|
-
*/
|
|
238
|
-
export declare class SyncResultImpl<T> implements Result<T> {
|
|
239
|
-
value: T;
|
|
240
|
-
constructor(value: T);
|
|
241
|
-
/** @override */
|
|
242
|
-
then(callback: (T: any) => void): void;
|
|
243
|
-
/** @override */
|
|
244
|
-
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
245
|
-
/** @override */
|
|
246
|
-
thenReturn<T1>(result: T1): SyncResultImpl<T1>;
|
|
247
|
-
/** @override */
|
|
248
|
-
thenFinish(frame: Frame<T>): void;
|
|
249
|
-
/** @override */
|
|
250
|
-
isPending(): boolean;
|
|
251
|
-
/** @override */
|
|
252
|
-
get(): T | null;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* @template T
|
|
256
|
-
*/
|
|
257
|
-
export declare class ResultImpl<T> implements Result<T> {
|
|
258
|
-
readonly frame: Frame<T>;
|
|
259
|
-
constructor(frame: Frame<T>);
|
|
260
|
-
/** @override */
|
|
261
|
-
then(callback: (p1: T) => void): void;
|
|
262
|
-
/** @override */
|
|
263
|
-
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
264
|
-
/** @override */
|
|
265
|
-
thenReturn<T1>(result: T1): Result<any> | SyncResultImpl<T1>;
|
|
266
|
-
/** @override */
|
|
267
|
-
thenFinish(frame: Frame<T>): void;
|
|
268
|
-
/** @override */
|
|
269
|
-
isPending(): boolean;
|
|
270
|
-
/** @override */
|
|
271
|
-
get(): T | null;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Asynchronous execution frame. Corresponds to an asynchronous function
|
|
275
|
-
* invocation.
|
|
276
|
-
* @template T
|
|
277
|
-
*/
|
|
278
|
-
export declare class Frame<T> {
|
|
279
|
-
task: Task;
|
|
280
|
-
parent: Frame<T>;
|
|
281
|
-
name: string;
|
|
282
|
-
res: T;
|
|
283
|
-
state: FrameState;
|
|
284
|
-
callback: ((p1: any) => void) | null;
|
|
285
|
-
handler: ((p1: Frame<any>, p2: Error) => void) | null;
|
|
286
|
-
constructor(task: Task, parent: Frame<T>, name: string);
|
|
287
|
-
private checkEnvironment;
|
|
288
|
-
/**
|
|
289
|
-
* @return to be returned as this asynchronous function return value.
|
|
290
|
-
*/
|
|
291
|
-
result(): Result<T>;
|
|
292
|
-
finish(res: T): void;
|
|
293
|
-
getTask(): Task;
|
|
294
|
-
/**
|
|
295
|
-
* @return frame name.
|
|
296
|
-
*/
|
|
297
|
-
getName(): string;
|
|
298
|
-
getScheduler(): Scheduler;
|
|
299
|
-
then(callback: (p1: T) => void): void;
|
|
300
|
-
/**
|
|
301
|
-
* If this task was executed longer than task's slice parameter.
|
|
302
|
-
* @return holds true
|
|
303
|
-
*/
|
|
304
|
-
timeSlice(): Result<boolean>;
|
|
305
|
-
/**
|
|
306
|
-
* Yield to other tasks for the specified time.
|
|
307
|
-
* @param delay in milliseconds.
|
|
308
|
-
* @return holds true
|
|
309
|
-
*/
|
|
310
|
-
sleep(delay: number): Result<boolean>;
|
|
311
|
-
/**
|
|
312
|
-
* Repeatedly execute the given function asynchronously until it returns
|
|
313
|
-
* false.
|
|
314
|
-
* @return holds true.
|
|
315
|
-
*/
|
|
316
|
-
loop(func: () => Result<boolean>): Result<boolean>;
|
|
317
|
-
/**
|
|
318
|
-
* Similar to loop(), but provides a Frame for loop body function.
|
|
319
|
-
* @return holds true.
|
|
320
|
-
*/
|
|
321
|
-
loopWithFrame(func: (p1: LoopBodyFrame) => void): Result<boolean>;
|
|
322
|
-
suspend(opt_waitTarget?: any): Continuation<T>;
|
|
323
|
-
}
|
|
324
|
-
export declare class LoopBodyFrame extends Frame<boolean> {
|
|
325
|
-
constructor(task: Task, parent: Frame<boolean>);
|
|
326
|
-
continueLoop(): void;
|
|
327
|
-
breakLoop(): void;
|
|
328
|
-
}
|
|
329
|
-
export declare class EventItem {
|
|
330
|
-
event: Base.Event;
|
|
331
|
-
next: EventItem;
|
|
332
|
-
constructor(event: Base.Event);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* An class to listen to evens and present them as a readable asynchronous
|
|
336
|
-
* stream to tasks.
|
|
337
|
-
*/
|
|
338
|
-
export declare class EventSource {
|
|
339
|
-
continuation: Continuation<boolean>;
|
|
340
|
-
listeners: {
|
|
341
|
-
target: Base.EventTarget;
|
|
342
|
-
type: string;
|
|
343
|
-
listener: Base.EventListener;
|
|
344
|
-
}[];
|
|
345
|
-
head: EventItem;
|
|
346
|
-
tail: EventItem;
|
|
347
|
-
constructor();
|
|
348
|
-
/**
|
|
349
|
-
* Attaches as an event listener to an EventTarget.
|
|
350
|
-
*/
|
|
351
|
-
attach(target: Base.EventTarget, type: string, opt_preventDefault?: boolean): void;
|
|
352
|
-
detach(target: Base.EventTarget, type: string): void;
|
|
353
|
-
/**
|
|
354
|
-
* Read next dispatched event, blocking the current task if needed.
|
|
355
|
-
*/
|
|
356
|
-
nextEvent(): Result<Base.Event>;
|
|
357
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Google, Inc.
|
|
3
|
+
* Copyright 2015 Trim-marks Inc.
|
|
4
|
+
* Copyright 2019 Vivliostyle Foundation
|
|
5
|
+
*
|
|
6
|
+
* Vivliostyle.js is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* Vivliostyle.js is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU Affero General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
17
|
+
* along with Vivliostyle.js. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
*
|
|
19
|
+
* @fileoverview Task - Support for asynchronous execution and cooperative
|
|
20
|
+
* multitasking.
|
|
21
|
+
*/
|
|
22
|
+
import * as Base from "./base";
|
|
23
|
+
/**
|
|
24
|
+
* External timer. Only needed for testing.
|
|
25
|
+
*/
|
|
26
|
+
export interface Timer {
|
|
27
|
+
/**
|
|
28
|
+
* @return current time in milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
currentTime(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Calls function after a given timeout.
|
|
33
|
+
* @param fn function to call.
|
|
34
|
+
* @param delay timeout in milliseconds.
|
|
35
|
+
* @return unique number that can be used to clear the timeout.
|
|
36
|
+
*/
|
|
37
|
+
setTimeout(fn: () => void, delay: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Calls function after a given timeout.
|
|
40
|
+
* @param token timeout token.
|
|
41
|
+
*/
|
|
42
|
+
clearTimeout(token: number): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of an asynchronous function that may be available immediately or
|
|
46
|
+
* some time later. Similar to Deferred.
|
|
47
|
+
* @template T
|
|
48
|
+
*/
|
|
49
|
+
export interface Result<T> {
|
|
50
|
+
/**
|
|
51
|
+
* Call the given function when asynchronous function is finished. Callback
|
|
52
|
+
* is executed in the task's context.
|
|
53
|
+
*/
|
|
54
|
+
then(callback: (p1: T) => void): void;
|
|
55
|
+
/**
|
|
56
|
+
* Call the given asynchronous function when some asynchronous function is
|
|
57
|
+
* finished. Callback is executed in the task's context.
|
|
58
|
+
* @template T1
|
|
59
|
+
*/
|
|
60
|
+
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
61
|
+
/**
|
|
62
|
+
* Produce a Result that resolves to the given value when this Result is
|
|
63
|
+
* resolved.
|
|
64
|
+
* @template T1
|
|
65
|
+
*/
|
|
66
|
+
thenReturn<T1>(result: T1): Result<T1>;
|
|
67
|
+
/**
|
|
68
|
+
* Finish given frame with the result value when result becomes ready.
|
|
69
|
+
*/
|
|
70
|
+
thenFinish(frame: Frame<T>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if this Result is still pending.
|
|
73
|
+
*/
|
|
74
|
+
isPending(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* If this Result is resolved, return the value that it holds.
|
|
77
|
+
*/
|
|
78
|
+
get(): T | null;
|
|
79
|
+
}
|
|
80
|
+
export declare let privateCurrentTask: Task | null;
|
|
81
|
+
export declare let primaryScheduler: Scheduler | null;
|
|
82
|
+
/**
|
|
83
|
+
* Returns current task.
|
|
84
|
+
*/
|
|
85
|
+
export declare function currentTask(): Task | null;
|
|
86
|
+
/**
|
|
87
|
+
* Create and return a new frame with the given name.
|
|
88
|
+
*/
|
|
89
|
+
export declare function newFrame<T>(name: string): Frame<T>;
|
|
90
|
+
export declare function newEventSource(): EventSource;
|
|
91
|
+
export declare function newScheduler(opt_timer?: Timer): Scheduler;
|
|
92
|
+
/**
|
|
93
|
+
* @template T
|
|
94
|
+
*/
|
|
95
|
+
export declare function newResult<T>(opt_value: T): Result<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new frame and runs code in its context, catching synchronous and
|
|
98
|
+
* asynchronous errors. If an error occurs, onErr is run (in the context of
|
|
99
|
+
* the same frame). As usual, onErr is supposed either produce a result or raise
|
|
100
|
+
* an exception.
|
|
101
|
+
*/
|
|
102
|
+
export declare function handle<T>(name: any, code: (p1: Frame<T>) => void, onErr: (p1: Frame<T>, p2: Error) => void): Result<T>;
|
|
103
|
+
export declare function start<T>(func: () => Result<T>, opt_name?: string): Task;
|
|
104
|
+
/**
|
|
105
|
+
* Frame state.
|
|
106
|
+
* @enum {number}
|
|
107
|
+
*/
|
|
108
|
+
export declare enum FrameState {
|
|
109
|
+
INIT = 0,
|
|
110
|
+
ACTIVE = 1,
|
|
111
|
+
FINISHED = 2,
|
|
112
|
+
DEAD = 3
|
|
113
|
+
}
|
|
114
|
+
export declare class TimerImpl implements Timer {
|
|
115
|
+
/** @override */
|
|
116
|
+
currentTime(): number;
|
|
117
|
+
/** @override */
|
|
118
|
+
setTimeout(fn: () => void, delay: number): number;
|
|
119
|
+
/** @override */
|
|
120
|
+
clearTimeout(token: number): void;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A class to create tasks.
|
|
124
|
+
*/
|
|
125
|
+
export declare class Scheduler {
|
|
126
|
+
timer: Timer;
|
|
127
|
+
timeout: number;
|
|
128
|
+
slice: number;
|
|
129
|
+
sliceOverTime: number;
|
|
130
|
+
queue: Base.PriorityQueue;
|
|
131
|
+
wakeupTime: number | null;
|
|
132
|
+
timeoutToken: number | null;
|
|
133
|
+
inTimeSlice: boolean;
|
|
134
|
+
order: number;
|
|
135
|
+
constructor(timer: Timer);
|
|
136
|
+
/**
|
|
137
|
+
* Sets time slice length.
|
|
138
|
+
* @param slice length in milliseconds.
|
|
139
|
+
*/
|
|
140
|
+
setSlice(slice: number): void;
|
|
141
|
+
/**
|
|
142
|
+
* Sets timeout between time slices.
|
|
143
|
+
* @param timeout in milliseconds.
|
|
144
|
+
*/
|
|
145
|
+
setTimeout(timeout: number): void;
|
|
146
|
+
/**
|
|
147
|
+
* Checks if the current time slice is over.
|
|
148
|
+
*/
|
|
149
|
+
isTimeSliceOver(): boolean;
|
|
150
|
+
private arm;
|
|
151
|
+
schedule(continuation: Continuation<any>, opt_delay?: number): void;
|
|
152
|
+
private doTimeSlice;
|
|
153
|
+
run(func: () => Result<any>, opt_name?: string): Task;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Task suspension point.
|
|
157
|
+
* @template T
|
|
158
|
+
*/
|
|
159
|
+
export declare class Continuation<T> implements Base.Comparable {
|
|
160
|
+
task: Task;
|
|
161
|
+
scheduledTime: number;
|
|
162
|
+
order: number;
|
|
163
|
+
result: T;
|
|
164
|
+
canceled: boolean;
|
|
165
|
+
constructor(task: Task);
|
|
166
|
+
/** @override */
|
|
167
|
+
compare(otherComp: Base.Comparable): number;
|
|
168
|
+
/**
|
|
169
|
+
* Continuation's task
|
|
170
|
+
*/
|
|
171
|
+
getTask(): Task;
|
|
172
|
+
/**
|
|
173
|
+
* Schedule task continuation after the given (optional) delay.
|
|
174
|
+
* @param opt_delay optional delay in milliseconds.
|
|
175
|
+
*/
|
|
176
|
+
schedule(result: T, opt_delay?: number): void;
|
|
177
|
+
resumeInternal(): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Cancel continuation
|
|
180
|
+
*/
|
|
181
|
+
cancel(): void;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* An asynchronous, time-sliced task.
|
|
185
|
+
*/
|
|
186
|
+
export declare class Task {
|
|
187
|
+
scheduler: Scheduler;
|
|
188
|
+
name: string;
|
|
189
|
+
callbacks: (() => void)[];
|
|
190
|
+
exception: Error | null;
|
|
191
|
+
running: boolean;
|
|
192
|
+
result: any;
|
|
193
|
+
waitTarget: string | null;
|
|
194
|
+
top: Frame<any> | null;
|
|
195
|
+
continuation: Continuation<any> | null;
|
|
196
|
+
constructor(scheduler: Scheduler, name: string);
|
|
197
|
+
/**
|
|
198
|
+
* @return task name.
|
|
199
|
+
*/
|
|
200
|
+
getName(): string;
|
|
201
|
+
/**
|
|
202
|
+
* @param err exception to throw in the task's context.
|
|
203
|
+
*/
|
|
204
|
+
interrupt(err: Error): void;
|
|
205
|
+
/**
|
|
206
|
+
* @return this task's scheduler.
|
|
207
|
+
*/
|
|
208
|
+
getScheduler(): Scheduler;
|
|
209
|
+
/**
|
|
210
|
+
* @return true if task is still running.
|
|
211
|
+
*/
|
|
212
|
+
isRunning(): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Register a callback to be called when the task is done. Callback is not
|
|
215
|
+
* executed in any task context. Multiple callbacks can be registered and
|
|
216
|
+
* they will be called in the registration order.
|
|
217
|
+
*/
|
|
218
|
+
whenDone(callback: () => void): void;
|
|
219
|
+
/**
|
|
220
|
+
* Wait for task to finish (from another task).
|
|
221
|
+
*/
|
|
222
|
+
join(): Result<any>;
|
|
223
|
+
/**
|
|
224
|
+
* Unwind the stack. We have two stacks: async (maintained by frame
|
|
225
|
+
* parent link) and sync (regular JavaScript stack).
|
|
226
|
+
*/
|
|
227
|
+
unwind(): void;
|
|
228
|
+
raise(err: Error, opt_frame?: Frame<any>): void;
|
|
229
|
+
/**
|
|
230
|
+
* Fill the stack trace in the exception
|
|
231
|
+
* @param err exception
|
|
232
|
+
*/
|
|
233
|
+
fillStack(err: Error): void;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* @template T
|
|
237
|
+
*/
|
|
238
|
+
export declare class SyncResultImpl<T> implements Result<T> {
|
|
239
|
+
value: T;
|
|
240
|
+
constructor(value: T);
|
|
241
|
+
/** @override */
|
|
242
|
+
then(callback: (T: any) => void): void;
|
|
243
|
+
/** @override */
|
|
244
|
+
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
245
|
+
/** @override */
|
|
246
|
+
thenReturn<T1>(result: T1): SyncResultImpl<T1>;
|
|
247
|
+
/** @override */
|
|
248
|
+
thenFinish(frame: Frame<T>): void;
|
|
249
|
+
/** @override */
|
|
250
|
+
isPending(): boolean;
|
|
251
|
+
/** @override */
|
|
252
|
+
get(): T | null;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @template T
|
|
256
|
+
*/
|
|
257
|
+
export declare class ResultImpl<T> implements Result<T> {
|
|
258
|
+
readonly frame: Frame<T>;
|
|
259
|
+
constructor(frame: Frame<T>);
|
|
260
|
+
/** @override */
|
|
261
|
+
then(callback: (p1: T) => void): void;
|
|
262
|
+
/** @override */
|
|
263
|
+
thenAsync<T1>(callback: (p1: T) => Result<T1>): Result<T1>;
|
|
264
|
+
/** @override */
|
|
265
|
+
thenReturn<T1>(result: T1): Result<any> | SyncResultImpl<T1>;
|
|
266
|
+
/** @override */
|
|
267
|
+
thenFinish(frame: Frame<T>): void;
|
|
268
|
+
/** @override */
|
|
269
|
+
isPending(): boolean;
|
|
270
|
+
/** @override */
|
|
271
|
+
get(): T | null;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Asynchronous execution frame. Corresponds to an asynchronous function
|
|
275
|
+
* invocation.
|
|
276
|
+
* @template T
|
|
277
|
+
*/
|
|
278
|
+
export declare class Frame<T> {
|
|
279
|
+
task: Task;
|
|
280
|
+
parent: Frame<T>;
|
|
281
|
+
name: string;
|
|
282
|
+
res: T;
|
|
283
|
+
state: FrameState;
|
|
284
|
+
callback: ((p1: any) => void) | null;
|
|
285
|
+
handler: ((p1: Frame<any>, p2: Error) => void) | null;
|
|
286
|
+
constructor(task: Task, parent: Frame<T>, name: string);
|
|
287
|
+
private checkEnvironment;
|
|
288
|
+
/**
|
|
289
|
+
* @return to be returned as this asynchronous function return value.
|
|
290
|
+
*/
|
|
291
|
+
result(): Result<T>;
|
|
292
|
+
finish(res: T): void;
|
|
293
|
+
getTask(): Task;
|
|
294
|
+
/**
|
|
295
|
+
* @return frame name.
|
|
296
|
+
*/
|
|
297
|
+
getName(): string;
|
|
298
|
+
getScheduler(): Scheduler;
|
|
299
|
+
then(callback: (p1: T) => void): void;
|
|
300
|
+
/**
|
|
301
|
+
* If this task was executed longer than task's slice parameter.
|
|
302
|
+
* @return holds true
|
|
303
|
+
*/
|
|
304
|
+
timeSlice(): Result<boolean>;
|
|
305
|
+
/**
|
|
306
|
+
* Yield to other tasks for the specified time.
|
|
307
|
+
* @param delay in milliseconds.
|
|
308
|
+
* @return holds true
|
|
309
|
+
*/
|
|
310
|
+
sleep(delay: number): Result<boolean>;
|
|
311
|
+
/**
|
|
312
|
+
* Repeatedly execute the given function asynchronously until it returns
|
|
313
|
+
* false.
|
|
314
|
+
* @return holds true.
|
|
315
|
+
*/
|
|
316
|
+
loop(func: () => Result<boolean>): Result<boolean>;
|
|
317
|
+
/**
|
|
318
|
+
* Similar to loop(), but provides a Frame for loop body function.
|
|
319
|
+
* @return holds true.
|
|
320
|
+
*/
|
|
321
|
+
loopWithFrame(func: (p1: LoopBodyFrame) => void): Result<boolean>;
|
|
322
|
+
suspend(opt_waitTarget?: any): Continuation<T>;
|
|
323
|
+
}
|
|
324
|
+
export declare class LoopBodyFrame extends Frame<boolean> {
|
|
325
|
+
constructor(task: Task, parent: Frame<boolean>);
|
|
326
|
+
continueLoop(): void;
|
|
327
|
+
breakLoop(): void;
|
|
328
|
+
}
|
|
329
|
+
export declare class EventItem {
|
|
330
|
+
event: Base.Event;
|
|
331
|
+
next: EventItem;
|
|
332
|
+
constructor(event: Base.Event);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* An class to listen to evens and present them as a readable asynchronous
|
|
336
|
+
* stream to tasks.
|
|
337
|
+
*/
|
|
338
|
+
export declare class EventSource {
|
|
339
|
+
continuation: Continuation<boolean>;
|
|
340
|
+
listeners: {
|
|
341
|
+
target: Base.EventTarget;
|
|
342
|
+
type: string;
|
|
343
|
+
listener: Base.EventListener;
|
|
344
|
+
}[];
|
|
345
|
+
head: EventItem;
|
|
346
|
+
tail: EventItem;
|
|
347
|
+
constructor();
|
|
348
|
+
/**
|
|
349
|
+
* Attaches as an event listener to an EventTarget.
|
|
350
|
+
*/
|
|
351
|
+
attach(target: Base.EventTarget, type: string, opt_preventDefault?: boolean): void;
|
|
352
|
+
detach(target: Base.EventTarget, type: string): void;
|
|
353
|
+
/**
|
|
354
|
+
* Read next dispatched event, blocking the current task if needed.
|
|
355
|
+
*/
|
|
356
|
+
nextEvent(): Result<Base.Event>;
|
|
357
|
+
}
|