@moddable/typings 7.1.0 → 7.2.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/piu/MC.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2020-2025 Shinya Ishikawa
2
+ * Copyright (c) 2020-2026 Shinya Ishikawa
3
3
  *
4
4
  * This file is part of the Moddable SDK Tools.
5
5
  *
@@ -20,557 +20,35 @@
20
20
 
21
21
  declare module "piu/MC" {
22
22
  import {} from "commodetto/Poco"; // for global screen
23
-
24
- /* type aliases */
25
- type Coordinates = {
26
- top?: number;
27
- right?: number;
28
- bottom?: number;
29
- left?: number;
30
- };
31
- type Position = {
32
- x?: number;
33
- y?: number;
34
- };
35
- type Size = {
36
- width?: number;
37
- height?: number;
38
- };
39
- type Bounds = Position & Size;
40
- type Color = string;
41
- type ContentState = {
42
- state?: number;
43
- variant?: number;
44
- };
45
- type TimeProperty = {
46
- time?: number;
47
- duration?: number;
48
- fraction?: number;
49
- interval?: number;
50
- loop?: boolean;
51
- };
52
- type TouchProperty = {
53
- active?: boolean;
54
- backgroundTouch?: boolean;
55
- exclusiveTouch?: boolean;
56
- multipleTouch?: boolean;
57
- };
58
-
59
- // TODO: more accurate constructor parameters
60
- type TemplateStyle<P, C extends new (...args: any) => any> = {
61
- new (dictionary?: P): InstanceType<C>;
62
- template: TemplateStyleFactory<C>;
63
- };
64
- type TemplateStyleFactory<T extends new (...args: any) => any> = (
65
- param: ConstructorParameters<T>[0]
66
- ) => TemplateStyle<Partial<ConstructorParameters<T>[1]>, T>;
67
-
68
- type TemplateComponent<P, C extends new (...args: any) => any> = {
69
- new (behaviorData?: any, dictionary?: P): InstanceType<C>;
70
- template: TemplateComponentFactory<C>;
71
- };
72
- type TemplateComponentFactory<T extends new (...args: any) => any> = (
73
- func: (param: any) => ConstructorParameters<T>[1]
74
- ) => TemplateComponent<Parameters<typeof func>[0], T>;
75
-
76
- interface Behavior<T extends Content = Content>{
77
- onCreate?(content: T, data: object, context: any): void;
78
- onDisplaying?(content: T): void;
79
- onFinished?(content: T): void;
80
- onTimeChanged?(content: T): void;
81
- onTouchBegan?(content: T, id: number, x: number, y: number, ticks: number): void;
82
- onTouchCancelled?(content: T, id: number): void;
83
- onTouchended?( content: T, id: number, x: number, y: number, ticks: number): void;
84
- onTouchMoved?( content: T, id: number, x: number, y: number, ticks: number): void;
85
- // TODO: complete callbacks
86
- }
87
-
88
- interface BehaviorConstructor<T extends Content = Content> {
89
- new(): Behavior<T>;
90
- }
91
-
92
- interface Content {
93
- // TODO: consider type parameter to avoid any
94
- adjust(x: number, y: number): void;
95
- bubble(id: string, ...extras: any[]): void;
96
- captureTouch(id: string, x: number, y: number, ticks: number): void;
97
- defer(id: string, ...extras: any[]): void;
98
- delegate(id: string, ...extras: any[]): void;
99
- distribute(id: string, ...extras: any[]): void;
100
- focus(): void;
101
- hit(x: number, y: number): Content | undefined;
102
- measure(): Size;
103
- moveBy(x: number, y: number): void;
104
- render(): void;
105
- sizeBy(width: number, height: number): void;
106
- start(): void;
107
- stop(): void;
108
-
109
- readonly previous: Content | null;
110
- readonly next: Content | null;
111
- readonly container: Container | null;
112
- readonly index: number;
113
- name: string;
114
- active: boolean;
115
- anchor: string;
116
- behavior: object;
117
- coordinates: Coordinates;
118
- bounds: Bounds;
119
- backgroundTouch: boolean;
120
- exclusiveTouch: boolean;
121
- multipleTouch: boolean;
122
-
123
- time: number;
124
- duration: number;
125
- fraction: number;
126
- interval: number;
127
- loop: boolean;
128
- running: boolean;
129
- offset: undefined | Position;
130
- position: undefined | Position;
131
- size: Size;
132
- state: number;
133
- variant: number;
134
- skin: Skin | null;
135
- style: Style | null;
136
- visible: boolean;
137
- x: number;
138
- y: number;
139
- width: number;
140
- height: number;
141
- }
142
- interface ContentDictionary
143
- extends Coordinates,
144
- Size,
145
- ContentState,
146
- TimeProperty,
147
- TouchProperty {
148
- name?: string;
149
- anchor?: string;
150
- Behavior?: BehaviorConstructor;
151
- skin?: Skin | SkinDictionary;
152
- Skin?: SkinConstructor;
153
- style?: Style | StyleDictionary;
154
- Style?: StyleConstructor;
155
- visible?: boolean;
156
- }
157
- interface ContentConstructor {
158
- new(behaviorData?: any, dictionary?: ContentDictionary): Content;
159
- (behaviorData?: any, dictionary?: ContentDictionary): Content;
160
- readonly prototype: Content;
161
-
162
- template: TemplateComponentFactory<typeof Content>;
163
- }
164
-
165
- interface Style {
166
- measure(string: string): Size;
167
- }
168
- interface StyleDictionaryBase {
169
- color?: Color | Color[];
170
- font?: string;
171
- horizontal?: string;
172
- top?: number;
173
- }
174
- interface StyleConstructor {
175
- new(dictionary: StyleDictionary): Style;
176
-
177
- template<T>(this: T, dictionary: StyleDictionary): T;
178
- }
179
-
180
- interface TextStyleDictionary extends StyleDictionaryBase {
181
- leading?: number;
182
- right?: number;
183
- bottom?: number;
184
- left?: number;
185
- }
186
- interface LabelStyleDictionary extends StyleDictionaryBase {
187
- vertical?: string;
188
- }
189
- type StyleDictionary = LabelStyleDictionary | TextStyleDictionary;
190
-
191
- interface Texture {
192
- readonly height: number;
193
- readonly width: number;
194
- }
195
- interface TextureDictionary {
196
- path: string;
197
- }
198
- interface TextureConstructor {
199
- new(path: string): Texture;
200
- new(dictionary: TextureDictionary): Texture;
201
- readonly prototype: Texture;
202
-
203
- template: TemplateStyleFactory<typeof Texture>;
204
- }
205
-
206
- interface Skin {
207
- borders: Coordinates;
208
- fill: Color | Color[];
209
- stroke: Color | Color[];
210
- texture: Texture;
211
- color: Color;
212
- bounds: Bounds;
213
- height: number;
214
- width: number;
215
- states?: number;
216
- variants?: number;
217
- tiles?: Coordinates;
218
- top?: number;
219
- right?: number;
220
- bottom?: number;
221
- left?: number;
222
- }
223
- interface SkinConstructor {
224
- new(dictionary: SkinDictionary): Skin;
225
- readonly prototype: Skin;
226
-
227
- template: TemplateStyleFactory<typeof Skin>;
228
- }
229
-
230
- interface TextureSkinDictionary extends Coordinates, Bounds {
231
- texture?: Texture | TextureDictionary;
232
- Texture?: TextureConstructor;
233
- color?: Color | Color[];
234
- states?: number;
235
- variants?: number;
236
- tiles?: Coordinates;
237
- }
238
- interface ColorSkinDictionary {
239
- borders?: Coordinates;
240
- fill?: Color | Color[];
241
- stroke?: Color | Color[];
242
- }
243
- type SkinDictionary = ColorSkinDictionary | TextureSkinDictionary;
244
-
245
- interface Transition {
246
- onBegin(container: Container, ...extras: any[]): void;
247
- onEnd(container: Container, ...extras: any[]): void;
248
- onStep(fraction: number): void;
249
- duration?: number;
250
- }
251
- interface TransitionConstructor {
252
- new(duration: number, interpolator?: (value: number) => number, first?: any, last?: any): Transition
253
- }
254
-
255
- interface Container extends Content {
256
- clip: boolean;
257
- readonly first: Content | null;
258
- readonly last: Content | null;
259
- readonly length: number;
260
- readonly transitioning: boolean;
261
- add(content: Content): void;
262
- content(at: number | string): Content | undefined;
263
- empty(start?: number, stop?: number): void;
264
- firstThat(id: string, ...extras: any[]): void;
265
- insert(content: Content, before: Content): void;
266
- lastThat(id: string, ...extras: any[]): void;
267
- remove(content: Content): void;
268
- replace(content: Content, by: Content): void;
269
- run(transition: Transition, ...extras: any[]): void;
270
- swap(content0: Content, content1: Content): void;
271
- onTransitionBeginning(container: Container): void;
272
- onTransitionEnded(container: Container): void;
273
- }
274
- interface ContainerDictionary extends ContentDictionary {
275
- clip?: boolean;
276
- contents?: Content[];
277
- }
278
- interface ContainerConstructor {
279
- new(behaviorData?: any, dictionary?: ContainerDictionary): Container;
280
- (behaviorData?: any, dictionary?: ContainerDictionary): Container;
281
-
282
- template<T>(this: T, fn: (arg: any) => ContainerDictionary): T;
283
- }
284
-
285
- interface Label extends Content {
286
- string: string;
287
- }
288
- interface LabelDictionary extends ContentDictionary {
289
- string?: string;
290
- }
291
- interface LabelConstructor {
292
- new(behaviorData?: any, dictionary?: LabelDictionary): Label;
293
- (behaviorData?: any, dictionary?: LabelDictionary): Label;
294
-
295
- template<T>(this: T, fn: (arg: any) => LabelDictionary): T;
296
- }
297
-
298
- interface Port extends Content {
299
- drawContent(
300
- x: number,
301
- y: number,
302
- width: number,
303
- height: number
304
- ): void;
305
- drawLabel(
306
- string: string,
307
- x: number,
308
- y: number,
309
- width: number,
310
- height: number
311
- ): void;
312
- drawSkin(
313
- skin: Skin,
314
- x: number,
315
- y: number,
316
- width: number,
317
- height: number,
318
- variant?: number,
319
- state?: number
320
- ): void;
321
- drawString(
322
- string: string,
323
- style: Style,
324
- color: Color,
325
- x: number,
326
- y: number,
327
- width: number,
328
- height: number
329
- ): void;
330
- drawStyle(
331
- string: string,
332
- style: Style,
333
- x: number,
334
- y: number,
335
- width: number,
336
- height: number,
337
- ellipsis?: boolean,
338
- state?: number
339
- ): void;
340
- drawTexture(
341
- texture: Texture,
342
- color: Color,
343
- x: number,
344
- y: number,
345
- sx: number,
346
- sy: number,
347
- sw: number,
348
- sh: number
349
- ): void;
350
- fillColor(
351
- color: Color,
352
- x: number,
353
- y: number,
354
- width: number,
355
- height: number
356
- ): void;
357
- fillTexture(
358
- texture: Texture,
359
- color: Color,
360
- x: number,
361
- y: number,
362
- width: number,
363
- height: number,
364
- sx?: number,
365
- sy?: number,
366
- sw?: number,
367
- sh?: number
368
- ): void;
369
- invalidate(
370
- x?: number,
371
- y?: number,
372
- width?: number,
373
- height?: number
374
- ): void;
375
- measureString(string: string, style: Style): Size;
376
- popClip(): void;
377
- pushClip(
378
- x?: number,
379
- y?: number,
380
- width?: number,
381
- height?: number
382
- ): void;
383
- onDraw(
384
- port: Port,
385
- x: number,
386
- y: number,
387
- width: number,
388
- height: number
389
- ): void;
390
- }
391
- interface PortConstructor extends ContentConstructor {
392
- }
393
-
394
- interface TextBlock {
395
- behavior?: object | null;
396
- style?: Style | null;
397
- spans: (string | TextSpan)[] | string,
398
- }
399
-
400
- interface TextSpan extends TextBlock {
401
- link?: any
402
- }
403
-
404
- interface Text extends Content {
405
- blocks: TextBlock[],
406
- string: string;
407
- begin(): void;
408
- beginBlock(style?: Style, behavior?: object): void;
409
- beginSpan(style: Style, behavior?: object): void;
410
- concat(string: string): void;
411
- end(): void;
412
- endBlock(): void;
413
- endSpan(): void;
414
- }
415
- interface TextDictionary extends ContentDictionary {
416
- blocks?: TextBlock[],
417
- string?: string;
418
- }
419
- interface TextConstructor {
420
- new(behaviorData?: any, dictionary?: TextDictionary): Text;
421
- (behaviorData?: any, dictionary?: TextDictionary): Text;
422
-
423
- template<T>(this: T, fn: (arg: any) => TextDictionary): T;
424
- }
425
-
426
- interface Application extends Container {
427
- displayListLength: number;
428
- commandListLength: number;
429
- touchCount: number;
430
- }
431
- interface ApplicationDictionary extends ContainerDictionary {
432
- displayListLength?: number;
433
- commandListLength?: number;
434
- touchCount?: number;
435
- pixels?: number;
436
- }
437
- interface ApplicationConstructor {
438
- new(behaviorData?: any, dictionary?: ApplicationDictionary): Application;
439
-
440
- template<T>(this: T, fn: (arg: any) => ApplicationDictionary): T;
441
- }
442
-
443
- interface Column extends Container {
444
- }
445
- interface ColumnConstructor extends ContainerConstructor {
446
- }
447
-
448
- interface Layout extends Container {
449
- onFitHorizontally(layout: Layout, width: number): void;
450
- onFitVertically(layout: Layout, height: number): void;
451
- onMeasureHorizontally(layout: Layout, width: number): void;
452
- onMeasureVertically(layout: Layout, height: number): void;
453
- }
454
- interface LayoutConstructor extends ContainerConstructor {
455
- }
456
-
457
- interface Image extends Content {
458
- readonly frameCount: never;
459
- frameIndex: number;
460
- }
461
- interface ImageDictionary extends ContentDictionary {
462
- path: string;
463
- }
464
- interface ImageConstructor {
465
- new(behaviorData?: any, dictionary?: ImageDictionary): Image;
466
- (behaviorData?: any, dictionary?: ImageDictionary): Image;
467
-
468
- template<T>(this: T, fn: (arg: any) => ImageDictionary): T;
469
- }
470
-
471
- interface Die extends Layout {
472
- set(x: number, y: number, width: number, height: number): Die;
473
- sub(x: number, y: number, width: number, height: number): Die;
474
- and(x: number, y: number, width: number, height: number): Die;
475
- or(x: number, y: number, width: number, height: number): Die;
476
- xor(x: number, y: number, width: number, height: number): Die;
477
- fill(): Die;
478
- empty(): Die;
479
- cut(): void;
480
- attach(content: Content): void;
481
- detach(): void;
482
- }
483
- interface DieConstructor extends LayoutConstructor {
484
- }
485
-
486
- interface Row extends Container {
487
- }
488
- interface RowConstructor extends ContainerConstructor {
489
- }
490
-
491
- interface Scroller extends Container {
492
- readonly constraint: Position;
493
- loop: boolean;
494
- scroll: Position;
495
- tracking: boolean;
496
- reveal(bounds: Bounds): void;
497
- scrollBy(dx: number, dy: number): void;
498
- scrollTo(x: number, y: number): void;
499
- onScrolled(scroller: Scroller): void;
500
- }
501
- interface ScrollerDictionary extends ContainerDictionary {
502
- loop?: boolean;
503
- }
504
- interface ScrollerConstructor {
505
- new(behaviorData?: any, dictionary?: ScrollerDictionary): Scroller;
506
- (behaviorData?: any, dictionary?: ScrollerDictionary): Scroller;
507
-
508
- template<T>(this: T, fn: (arg: any) => ScrollerDictionary): T;
509
- }
510
-
511
- interface LinkDictionary {
512
- Behavior?: BehaviorConstructor;
513
- }
514
- interface Link {
515
- readonly container: Container;
516
- state: number;
517
- captureTouch(id: number, x: number, y: number, ticks: number): void;
518
- }
519
- interface LinkConstructor {
520
- new(behaviorData?: any, dictionary?: LinkDictionary): Link;
521
- (behaviorData?: any, dictionary?: LinkDictionary): Link;
522
-
523
- template<T>(this: T, fn: (arg: any) => LinkDictionary): T;
524
- }
525
-
526
- interface Locals {
527
- new(name?: string, language?: string): Locals
528
- language: string;
529
- get(textToLocalize: string): string
530
- }
531
-
532
- interface blendColors {
533
- (a: number, c1: number, c2: number): Color
534
- }
535
- interface hsl {
536
- (h: number, s: number, l: number): Color
537
- }
538
- interface hsla {
539
- (h: number, s: number, l: number, a: number): Color
540
- }
541
- interface rgb {
542
- (r: number, g: number, b: number): Color
543
- }
544
- interface rgba {
545
- (r: number, g: number, b: number, a: number): Color
546
- }
547
-
23
+ import type * as MC from "piu/MC-types";
548
24
 
549
25
  global {
550
- const Skin: SkinConstructor
551
- const Texture: TextureConstructor
552
- const Style: StyleConstructor
553
- const Behavior: BehaviorConstructor
554
- const Content: ContentConstructor
555
- const Container: ContainerConstructor
556
- const Application: ApplicationConstructor
557
- const Scroller: ScrollerConstructor
558
- const Row: RowConstructor
559
- const Column: ColumnConstructor
560
- const Layout: LayoutConstructor
561
- const Image: ImageConstructor
562
- const Die: DieConstructor
563
- const Port: PortConstructor
564
- const Label: LabelConstructor
565
- const Transition: TransitionConstructor
566
- const Text: TextConstructor
567
- const Link: LinkConstructor
568
- const application: Application
569
- const Locals: Locals
570
- const blendColors: blendColors
571
- const hsl: hsl
572
- const hsla: hsla
573
- const rgb: rgb
574
- const rgba: rgba
575
- }
576
- }
26
+ const Skin: MC.SkinConstructor
27
+ const Texture: MC.TextureConstructor
28
+ const Style: MC.StyleConstructor
29
+ const Behavior: MC.BehaviorConstructor
30
+ const Content: MC.ContentConstructor
31
+ const Container: MC.ContainerConstructor
32
+ const Application: MC.ApplicationConstructor
33
+ const Scroller: MC.ScrollerConstructor
34
+ const Row: MC.RowConstructor
35
+ const Column: MC.ColumnConstructor
36
+ const Layout: MC.LayoutConstructor
37
+ const Image: MC.ImageConstructor
38
+ const Die: MC.DieConstructor
39
+ const Port: MC.PortConstructor
40
+ const Label: MC.LabelConstructor
41
+ const Transition: MC.TransitionConstructor
42
+ const Text: MC.TextConstructor
43
+ const Link: MC.LinkConstructor
44
+ const application: MC.Application
45
+ const Locals: MC.Locals
46
+ const blendColors: MC.blendColors
47
+ const hsl: MC.hsl
48
+ const hsla: MC.hsla
49
+ const rgb: MC.rgb
50
+ const rgba: MC.rgba
51
+ }
52
+
53
+ export * from "piu/MC-types";
54
+ }
package/qrcode.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2024 Satoshi Tanaka
2
+ * Copyright (c) 2024-2026 Satoshi Tanaka
3
3
  *
4
4
  * This file is part of the Moddable SDK Tools.
5
5
  *
@@ -23,9 +23,11 @@ declare module "qrcode" {
23
23
  size: number;
24
24
  }
25
25
 
26
- var qrCode: (options: {
26
+ const qrCode: (options: {
27
27
  input: string | ByteBuffer,
28
- maxVersion?: number
28
+ maxVersion?: number,
29
+ bitmap?: number | boolean,
30
+ fit?: number,
29
31
  }) => qrcode;
30
32
 
31
33
  export { qrCode as default };
package/web/fetch.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Moddable Tech, Inc.
3
+ *
4
+ * This file is part of the Moddable SDK Tools.
5
+ *
6
+ * The Moddable SDK Tools is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU 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
+ * The Moddable SDK Tools 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 General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
20
+
21
+ declare module "fetch" {
22
+ import {URL, URLSearchParams} from "url"
23
+ import Headers from "headers"
24
+
25
+ class Response {
26
+ get bodyUsed(): boolean;
27
+ get headers(): Headers;
28
+ get ok(): boolean;
29
+ get redirected(): boolean;
30
+ get status(): number;
31
+ get statusText(): string;
32
+ get url(): string;
33
+ arrayBuffer(): Promise<ArrayBuffer>;
34
+ json(): Promise<any>;
35
+ text(): Promise<string>;
36
+ }
37
+
38
+ interface RequestInit {
39
+ method?: string;
40
+ headers?: Headers | Record<string, string>;
41
+ body?: string | ByteBuffer | URLSearchParams;
42
+ }
43
+
44
+ function fetch(resource: string | URL, options?: RequestInit): Promise<Response>;
45
+
46
+ export { fetch };
47
+ export default fetch;
48
+ }
@@ -39,7 +39,7 @@ declare module "url" {
39
39
  }
40
40
 
41
41
  class URLSearchParams implements Iterable<[string, string]>{
42
- constructor(it?: string[][] | Record<string, string> | string)
42
+ constructor(it?: string[][] | Record<string, { toString(): string }> | string)
43
43
  readonly length: number;
44
44
  append(name: string, value: string): void;
45
45
  delete(name: string, value?: string): void;