@turbowarp/types 0.0.2 → 0.0.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/.github/workflows/validate.yml +7 -2
- package/CONTRIBUTING.md +9 -0
- package/README.md +8 -8
- package/package.json +1 -1
- package/tests/scratch-audio.ts +17 -0
- package/tests/scratch-gui.ts +16 -0
- package/tests/scratch-parser.ts +9 -0
- package/tests/scratch-render-fonts.ts +4 -0
- package/tests/scratch-storage.ts +22 -0
- package/tests/scratch-svg-renderer.ts +8 -0
- package/tests/vm.ts +6 -0
- package/types/paper.d.ts +17 -0
- package/types/react.d.ts +8 -0
- package/types/scratch-audio.d.ts +122 -1
- package/types/scratch-gui.d.ts +612 -0
- package/types/scratch-paint.ts +311 -0
- package/types/scratch-parser.d.ts +10 -1
- package/types/scratch-render-fonts.d.ts +11 -1
- package/types/scratch-storage.d.ts +80 -3
- package/types/scratch-svg-renderer.d.ts +61 -1
- package/types/scratch-vm.d.ts +86 -1
- package/types/scratch-www.ts +6 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Type definitions for scratch-paint redux state and events
|
|
2
|
+
// Project: https://github.com/LLK/scratch-paint
|
|
3
|
+
|
|
4
|
+
/// <reference path="./paper.d.ts" />
|
|
5
|
+
|
|
6
|
+
declare namespace ScratchPaint {
|
|
7
|
+
const enum VectorMode {
|
|
8
|
+
Brush = 'BRUSH',
|
|
9
|
+
Eraser = 'ERASER',
|
|
10
|
+
Line = 'LINE',
|
|
11
|
+
Fill = 'FILL',
|
|
12
|
+
Select = 'SELECT',
|
|
13
|
+
Reshape = 'RESHAPE',
|
|
14
|
+
Oval = 'OVAL',
|
|
15
|
+
Rectangle = 'RECT',
|
|
16
|
+
// Unused by scratch-paint but technically exists.
|
|
17
|
+
RoundedRectangle = 'ROUNDED_RECT',
|
|
18
|
+
Text = 'TEXT'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const enum BitmapMode {
|
|
22
|
+
Brush = 'BIT_BRUSH',
|
|
23
|
+
Line = 'BIT_LINE',
|
|
24
|
+
Oval = 'BIT_OVAL',
|
|
25
|
+
Rectangle = 'BIT_RECT',
|
|
26
|
+
Text = 'BIT_TEXT',
|
|
27
|
+
Fill = 'BIT_FILL',
|
|
28
|
+
Eraser = 'BIT_ERASER',
|
|
29
|
+
Select = 'BIT_SELECT'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Mode = VectorMode | BitmapMode;
|
|
33
|
+
|
|
34
|
+
const enum GradientType {
|
|
35
|
+
Solid = 'SOLID',
|
|
36
|
+
Horizontal = 'HORIZONTAL',
|
|
37
|
+
Vertical = 'VERTICAL',
|
|
38
|
+
Radial = 'RADIAL'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const enum Cursor {
|
|
42
|
+
Default = 'default',
|
|
43
|
+
Grab = 'grab',
|
|
44
|
+
Grabbing = 'grabbing',
|
|
45
|
+
None = 'none',
|
|
46
|
+
ResizeEW = 'ew-resize',
|
|
47
|
+
ResizeNS = 'ns-resize',
|
|
48
|
+
ResizeNEWSW = 'nesw-resize',
|
|
49
|
+
ResizeNWSE = 'nwse-resize'
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type ColorIndex = 0 | 1;
|
|
53
|
+
|
|
54
|
+
type Font = string;
|
|
55
|
+
|
|
56
|
+
const enum Format {
|
|
57
|
+
Bitmap = 'BITMAP',
|
|
58
|
+
Vector = 'VECTOR',
|
|
59
|
+
BitmapSkipConvert = 'BITMAP_SKIP_CONVERT',
|
|
60
|
+
VectorSkipConvert = 'VECTOR_SKIP_CONVERT'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const enum Modal {
|
|
64
|
+
FillColor = 'fillColor',
|
|
65
|
+
StrokeColor = 'strokeColor'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface ColorStyle {
|
|
69
|
+
primary: string | null;
|
|
70
|
+
secondary: string | null;
|
|
71
|
+
gradientType: GradientType;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface UndoSnapshot {
|
|
75
|
+
json: unknown[];
|
|
76
|
+
paintEditorFormat: Format;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ReduxState {
|
|
80
|
+
scratchPaint: ScratchPaintState;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface ScratchPaintState {
|
|
84
|
+
mode: Mode;
|
|
85
|
+
|
|
86
|
+
bitBrushSize: number;
|
|
87
|
+
|
|
88
|
+
bitEraserSize: number;
|
|
89
|
+
|
|
90
|
+
brushMode: {
|
|
91
|
+
brushSize: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
color: {
|
|
95
|
+
eyeDropper: {
|
|
96
|
+
active: boolean;
|
|
97
|
+
callback: (color: string) => void;
|
|
98
|
+
previousTool: Mode;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
fillColor: ColorStyle;
|
|
102
|
+
|
|
103
|
+
strokeColor: ColorStyle;
|
|
104
|
+
|
|
105
|
+
strokeWidth: number;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
clipboard: {
|
|
109
|
+
items: Paper.Base[];
|
|
110
|
+
pasteOffset: number;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
cursor: Cursor;
|
|
114
|
+
|
|
115
|
+
eraserMode: {
|
|
116
|
+
brushSize: number;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
fillBitmapShapes: boolean;
|
|
120
|
+
|
|
121
|
+
fillMode: {
|
|
122
|
+
gradientType: GradientType | null;
|
|
123
|
+
colorIndex: ColorIndex;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
font: Font;
|
|
127
|
+
|
|
128
|
+
format: Format | null;
|
|
129
|
+
|
|
130
|
+
hoveredItemId: number | null;
|
|
131
|
+
|
|
132
|
+
layout: {
|
|
133
|
+
rtl: boolean;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
modals: Record<Modal, boolean>;
|
|
137
|
+
|
|
138
|
+
selectedItems: Paper.Base[];
|
|
139
|
+
|
|
140
|
+
textEditTarget: number | null;
|
|
141
|
+
|
|
142
|
+
undo: {
|
|
143
|
+
stack: UndoSnapshot[];
|
|
144
|
+
pointer: number;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
viewBounds: Paper.Matrix;
|
|
148
|
+
|
|
149
|
+
zoomLevels: {
|
|
150
|
+
currentZoomLevelId: string;
|
|
151
|
+
} & Record<string, Paper.Matrix>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type ReduxEvent =
|
|
155
|
+
{
|
|
156
|
+
type: 'scratch-paint/modes/CHANGE_MODE';
|
|
157
|
+
mode: Mode;
|
|
158
|
+
} |
|
|
159
|
+
{
|
|
160
|
+
type: 'scratch-paint/brush-mode/CHANGE_BIT_BRUSH_SIZE';
|
|
161
|
+
brushSize: number;
|
|
162
|
+
} |
|
|
163
|
+
{
|
|
164
|
+
type: 'scratch-paint/eraser-mode/CHANGE_BIT_ERASER_SIZE';
|
|
165
|
+
eraserSize: number;
|
|
166
|
+
} |
|
|
167
|
+
{
|
|
168
|
+
type: 'scratch-paint/brush-mode/CHANGE_BRUSH_SIZE';
|
|
169
|
+
brushSize: number;
|
|
170
|
+
} |
|
|
171
|
+
{
|
|
172
|
+
type: 'scratch-paint/eye-dropper/ACTIVATE_COLOR_PICKER';
|
|
173
|
+
callback: ScratchPaintState['color']['eyeDropper']['callback'];
|
|
174
|
+
previousMode: Paper.Tool;
|
|
175
|
+
} |
|
|
176
|
+
{
|
|
177
|
+
type: 'scratch-paint/eye-dropper/DEACTIVATE_COLOR_PICKER';
|
|
178
|
+
} |
|
|
179
|
+
{
|
|
180
|
+
type: 'scratch-paint/fill-style/CHANGE_FILL_COLOR';
|
|
181
|
+
color: string;
|
|
182
|
+
} |
|
|
183
|
+
{
|
|
184
|
+
type: 'scratch-paint/fill-style/CHANGE_FILL_COLOR_2';
|
|
185
|
+
color: string;
|
|
186
|
+
} |
|
|
187
|
+
{
|
|
188
|
+
type: 'scratch-paint/fill-style/CHANGE_FILL_GRADIENT_TYPE';
|
|
189
|
+
gradientType: GradientType;
|
|
190
|
+
} |
|
|
191
|
+
{
|
|
192
|
+
type: 'scratch-paint/fill-style/CLEAR_FILL_GRADIENT';
|
|
193
|
+
} |
|
|
194
|
+
{
|
|
195
|
+
type: 'scratch-paint/stroke-style/CHANGE_STROKE_COLOR';
|
|
196
|
+
color: string;
|
|
197
|
+
} |
|
|
198
|
+
{
|
|
199
|
+
type: 'scratch-paint/stroke-style/CHANGE_STROKE_COLOR_2';
|
|
200
|
+
color: string;
|
|
201
|
+
} |
|
|
202
|
+
{
|
|
203
|
+
type: 'scratch-paint/stroke-style/CHANGE_STROKE_GRADIENT_TYPE';
|
|
204
|
+
gradientType: GradientType;
|
|
205
|
+
} |
|
|
206
|
+
{
|
|
207
|
+
type: 'scratch-paint/stroke-style/CLEAR_STROKE_GRADIENT';
|
|
208
|
+
} |
|
|
209
|
+
{
|
|
210
|
+
type: 'scratch-paint/stroke-width/CHANGE_STROKE_WIDTH';
|
|
211
|
+
strokeWidth: number;
|
|
212
|
+
} |
|
|
213
|
+
{
|
|
214
|
+
type: 'scratch-paint/clipboard/SET';
|
|
215
|
+
clipboardItems: ScratchPaintState['clipboard']['items']
|
|
216
|
+
} |
|
|
217
|
+
{
|
|
218
|
+
type: 'scratch-paint/clipboard/INCREMENT_PASTE_OFFSET';
|
|
219
|
+
} |
|
|
220
|
+
{
|
|
221
|
+
type: 'scratch-paint/clipboard/CLEAR_PASTE_OFFSET';
|
|
222
|
+
} |
|
|
223
|
+
{
|
|
224
|
+
type: 'scratch-paint/cursor/CHANGE_CURSOR';
|
|
225
|
+
cursorString: Cursor;
|
|
226
|
+
} |
|
|
227
|
+
{
|
|
228
|
+
type: 'scratch-paint/eraser-mode/CHANGE_ERASER_SIZE';
|
|
229
|
+
brushSize: number;
|
|
230
|
+
} |
|
|
231
|
+
{
|
|
232
|
+
type: 'scratch-paint/fill-bitmap-shapes/SET_FILLED';
|
|
233
|
+
filled: boolean;
|
|
234
|
+
} |
|
|
235
|
+
{
|
|
236
|
+
type: 'scratch-paint/color-index/CHANGE_COLOR_INDEX';
|
|
237
|
+
index: ColorIndex;
|
|
238
|
+
} |
|
|
239
|
+
{
|
|
240
|
+
type: 'scratch-paint/fonts/CHANGE_FONT';
|
|
241
|
+
font: Font;
|
|
242
|
+
} |
|
|
243
|
+
{
|
|
244
|
+
type: 'scratch-paint/formats/CHANGE_FORMAT';
|
|
245
|
+
format: Format;
|
|
246
|
+
} |
|
|
247
|
+
{
|
|
248
|
+
type: 'scratch-paint/hover/CHANGE_HOVERED';
|
|
249
|
+
hoveredItemId: number | null;
|
|
250
|
+
} |
|
|
251
|
+
{
|
|
252
|
+
type: 'scratch-paint/layout/SET_LAYOUT';
|
|
253
|
+
layout: 'rtl' | 'ltr';
|
|
254
|
+
} |
|
|
255
|
+
{
|
|
256
|
+
type: 'scratch-paint/modals/OPEN_MODAL';
|
|
257
|
+
modal: Modal;
|
|
258
|
+
} |
|
|
259
|
+
{
|
|
260
|
+
type: 'scratch-paint/modals/CLOSE_MODAL';
|
|
261
|
+
modal: Modal;
|
|
262
|
+
} |
|
|
263
|
+
{
|
|
264
|
+
type: 'scratch-paint/select/CHANGE_SELECTED_ITEMS';
|
|
265
|
+
selectedItems: ScratchPaintState['selectedItems'];
|
|
266
|
+
bitmapMode: boolean;
|
|
267
|
+
} |
|
|
268
|
+
{
|
|
269
|
+
type: 'scratch-paint/select/REDRAW_SELECTION_BOX';
|
|
270
|
+
} |
|
|
271
|
+
{
|
|
272
|
+
type: 'scratch-paint/text-tool/CHANGE_TEXT_EDIT_TARGET';
|
|
273
|
+
textEditTargetId: number | null;
|
|
274
|
+
} |
|
|
275
|
+
{
|
|
276
|
+
type: 'scratch-paint/undo/UNDO';
|
|
277
|
+
/**
|
|
278
|
+
* VECTOR_SKIP_CONVERT or BITMAP_SKIP_CONVERT
|
|
279
|
+
*/
|
|
280
|
+
format: Format;
|
|
281
|
+
} |
|
|
282
|
+
{
|
|
283
|
+
type: 'scratch-paint/undo/REDO';
|
|
284
|
+
/**
|
|
285
|
+
* VECTOR_SKIP_CONVERT or BITMAP_SKIP_CONVERT
|
|
286
|
+
*/
|
|
287
|
+
format: Format;
|
|
288
|
+
} |
|
|
289
|
+
{
|
|
290
|
+
type: 'scratch-paint/undo/SNAPSHOT';
|
|
291
|
+
snapshot: UndoSnapshot;
|
|
292
|
+
} |
|
|
293
|
+
{
|
|
294
|
+
type: 'scratch-paint/undo/CLEAR';
|
|
295
|
+
} |
|
|
296
|
+
{
|
|
297
|
+
type: 'scratch-paint/view/UPDATE_VIEW_BOUNDS';
|
|
298
|
+
viewBounds: Paper.Matrix;
|
|
299
|
+
} |
|
|
300
|
+
{
|
|
301
|
+
type: 'scratch-paint/zoom-levels/SAVE_ZOOM_LEVEL';
|
|
302
|
+
zoomLevel: Paper.Matrix;
|
|
303
|
+
} |
|
|
304
|
+
{
|
|
305
|
+
type: 'scratch-paint/zoom-levels/SET_ZOOM_LEVEL_ID';
|
|
306
|
+
zoomLevelId: string;
|
|
307
|
+
} |
|
|
308
|
+
{
|
|
309
|
+
type: 'scratch-paint/zoom-levels/RESET_ZOOM_LEVELS';
|
|
310
|
+
};
|
|
311
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
// Type definitions for scratch-parser
|
|
2
2
|
// Project: https://github.com/LLK/scratch-parser
|
|
3
3
|
|
|
4
|
+
/// <reference path="./jszip.d.ts" />
|
|
5
|
+
|
|
4
6
|
declare namespace ScratchParser {
|
|
5
|
-
|
|
7
|
+
|
|
6
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param input The binary data representing the project or sprite.
|
|
12
|
+
* @param isSprite True if this is a sprite, false if this is a project.
|
|
13
|
+
* @param callback
|
|
14
|
+
*/
|
|
15
|
+
declare function ScratchParser(input: ArrayBuffer | string, isSprite: boolean, callback: (error: unknown, unpacked: [unknown, JSZip | null]) => void): void
|
|
@@ -2,5 +2,15 @@
|
|
|
2
2
|
// Project: https://github.com/LLK/scratch-render-fonts
|
|
3
3
|
|
|
4
4
|
declare namespace ScratchRenderFonts {
|
|
5
|
-
|
|
5
|
+
const enum Font {
|
|
6
|
+
SansSerif = 'Sans Serif',
|
|
7
|
+
Serif = 'Serif',
|
|
8
|
+
Handwriting = 'Handwriting',
|
|
9
|
+
Marker = 'Marker',
|
|
10
|
+
Curly = 'Curly',
|
|
11
|
+
Pixel = 'Pixel',
|
|
12
|
+
Scratch = 'Scratch'
|
|
13
|
+
}
|
|
6
14
|
}
|
|
15
|
+
|
|
16
|
+
declare function ScratchRenderFonts(): Record<ScratchRenderFonts.Font, string>;
|
|
@@ -2,13 +2,90 @@
|
|
|
2
2
|
// Project: https://github.com/LLK/scratch-storage
|
|
3
3
|
|
|
4
4
|
declare namespace ScratchStorage {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
enum DataFormat {
|
|
6
|
+
JPG = 'jpg',
|
|
7
|
+
JSON = 'json',
|
|
8
|
+
MP3 = 'mp3',
|
|
9
|
+
PNG = 'png',
|
|
10
|
+
SB2 = 'sb2',
|
|
11
|
+
SB3 = 'sb3',
|
|
12
|
+
SVG = 'svg',
|
|
13
|
+
WAV = 'wav'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface AssetType {
|
|
17
|
+
contentType: string;
|
|
18
|
+
name: string;
|
|
19
|
+
runtimeFormat: DataFormat;
|
|
20
|
+
immutable: true;
|
|
21
|
+
}
|
|
22
|
+
namespace AssetType {
|
|
23
|
+
const ImageBitmap: AssetType;
|
|
24
|
+
const ImageVector: AssetType;
|
|
25
|
+
const Project: AssetType;
|
|
26
|
+
const Sound: AssetType;
|
|
27
|
+
const Sprite: AssetType;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class Asset {
|
|
31
|
+
constructor(assetType: AssetType, assetId: string, dataFormat: DataFormat | null, data: ArrayBuffer, generateId?: boolean);
|
|
32
|
+
|
|
33
|
+
assetType: AssetType;
|
|
34
|
+
|
|
35
|
+
dataFormat: DataFormat;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* MD5 of asset's data.
|
|
39
|
+
*/
|
|
40
|
+
assetId: string;
|
|
41
|
+
|
|
42
|
+
setData(data: ArrayBuffer, dataFormat: DataFormat, generateId?: boolean): void;
|
|
43
|
+
encodeTextData(text: string, dataFormat: DataFormat, generateId?: boolean): void;
|
|
44
|
+
|
|
45
|
+
decodeText(): string;
|
|
46
|
+
encodeDataURI(contentType?: string): string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Unused.
|
|
50
|
+
*/
|
|
51
|
+
dependencies: [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type UrlFunction = (asset: Asset) => string;
|
|
55
|
+
|
|
56
|
+
interface Helper {
|
|
57
|
+
load(assetType: AssetType, assetId: string, dataFormat: DataFormat): Promise<Asset>;
|
|
58
|
+
store(assetType: AssetType, dataFormat: DataFormat, data: ArrayBuffer, assetId: string): Promise<unknown>;
|
|
7
59
|
}
|
|
8
60
|
}
|
|
9
61
|
|
|
10
62
|
declare class ScratchStorage {
|
|
11
|
-
|
|
63
|
+
get Asset(): typeof ScratchStorage.Asset;
|
|
64
|
+
get AssetType(): typeof ScratchStorage.AssetType;
|
|
65
|
+
get DataFormat(): typeof ScratchStorage.DataFormat;
|
|
66
|
+
|
|
67
|
+
_helpers: ScratchStorage.Helper[];
|
|
68
|
+
addHelper(helper: ScratchStorage.Helper, priority?: number): void;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Synchronously get a cached asset.
|
|
72
|
+
*/
|
|
73
|
+
get(assetId: string): ScratchStorage.Asset | null;
|
|
74
|
+
|
|
75
|
+
cache(assetType: ScratchStorage.AssetType, dataFormat: ScratchStorage.DataFormat, data: ArrayBuffer, assetId: string): string;
|
|
76
|
+
|
|
77
|
+
load(assetType: ScratchStorage.AssetType, assetId: string, dataFormat: ScratchStorage.DataFormat): Promise<ScratchStorage.Asset | null>;
|
|
78
|
+
|
|
79
|
+
store(assetType: ScratchStorage.Asset, dataFormat: ScratchStorage.DataFormat, data: ArrayBuffer, assetId: string): Promise<unknown>;
|
|
80
|
+
|
|
81
|
+
createAsset(assetType: ScratchStorage.AssetType, dataFormat: ScratchStorage.DataFormat, data: ArrayBuffer, assetId: string, generateId?: boolean): void;
|
|
82
|
+
|
|
83
|
+
addWebStore(types: ScratchStorage.AssetType[], getFunction: ScratchStorage.UrlFunction, createFunction?: ScratchStorage.UrlFunction, updateFunction?: ScratchStorage.UrlFunction): void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Use addWebStore instead.
|
|
87
|
+
*/
|
|
88
|
+
addWebSource(types: ScratchStorage.AssetType[], getFunction: ScratchStorage.UrlFunction): void;
|
|
12
89
|
}
|
|
13
90
|
|
|
14
91
|
/**
|
|
@@ -2,5 +2,65 @@
|
|
|
2
2
|
// Project: https://github.com/LLK/scratch-svg-renderer
|
|
3
3
|
|
|
4
4
|
declare namespace ScratchSVGRenderer {
|
|
5
|
-
|
|
5
|
+
class BitmapAdapter {
|
|
6
|
+
constructor(makeImage?: () => HTMLImageElement, makeCanvas?: () => HTMLCanvasElement);
|
|
7
|
+
resize(image: CanvasImageSource, newWidth: number, newHeight: number): HTMLCanvasElement;
|
|
8
|
+
convertResolution1Bitmap(dataURI: string, callback: (error: unknown, dataURI: string) => void): void;
|
|
9
|
+
getResizedWidthHeight(oldWidth: number, oldHeight: number): {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
importBitmap(fileData: ArrayBuffer | string, contentType: string): Promise<Uint8Array>;
|
|
14
|
+
convertDataURIToBinary(dataURI: string): Uint8Array;
|
|
15
|
+
convertBinaryToDataURI(data: ArrayBufferLike, contentType: string): string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function convertFonts(element: SVGElement): void;
|
|
19
|
+
|
|
20
|
+
function inlineSvgFonts(svgString: string): string;
|
|
21
|
+
|
|
22
|
+
function loadSvgString(svgString: string, fromVersion2?: boolean): SVGSVGElement;
|
|
23
|
+
|
|
24
|
+
function serializeSvgToString(svgElement: SVGSVGElement, shouldInjectFonts?: boolean): string;
|
|
25
|
+
|
|
26
|
+
class SvgElement {
|
|
27
|
+
static get svg(): string;
|
|
28
|
+
static get xmlns(): string;
|
|
29
|
+
static get xlink(): string;
|
|
30
|
+
static get attributeNamespace(): Record<string, string>;
|
|
31
|
+
static create(tag: string, attributes?: Record<string, string | number>, formatter?: (n: number) => string): SVGElement;
|
|
32
|
+
static set(node: SVGElement, attributes?: Record<string, string | number>, formatter?: (n: number) => string): SVGElement;
|
|
33
|
+
static get(node: SVGElement, attributeName: string): string | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use the individual methods instead.
|
|
38
|
+
*/
|
|
39
|
+
class SvgRenderer {
|
|
40
|
+
constructor(canvas?: HTMLCanvasElement);
|
|
41
|
+
|
|
42
|
+
_canvas: HTMLCanvasElement;
|
|
43
|
+
get canvas(): HTMLCanvasElement;
|
|
44
|
+
_context: CanvasRenderingContext2D;
|
|
45
|
+
|
|
46
|
+
_measurements: {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
};
|
|
52
|
+
get size(): [number, number];
|
|
53
|
+
get viewOffset(): [number, number];
|
|
54
|
+
|
|
55
|
+
loaded?: boolean;
|
|
56
|
+
_cachedImage?: HTMLImageElement | null;
|
|
57
|
+
_svgTag: SVGSVGElement;
|
|
58
|
+
|
|
59
|
+
loadString(svgString: string, fromVersion2?: boolean): void;
|
|
60
|
+
loadSVG(svgString: string, fromVersion2?: boolean, callback?: () => void): void;
|
|
61
|
+
_createSVGImage(onFinish?: () => void): void;
|
|
62
|
+
toString(shouldInjectFonts?: boolean): string;
|
|
63
|
+
draw(scale: number): void;
|
|
64
|
+
_drawFromImage(scale: number): void;
|
|
65
|
+
}
|
|
6
66
|
}
|
package/types/scratch-vm.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
/// <reference path="./scratch-render.d.ts" />
|
|
8
8
|
/// <reference path="./scratch-audio.d.ts" />
|
|
9
9
|
/// <reference path="./scratch-storage.d.ts" />
|
|
10
|
+
/// <reference path="./scratch-svg-renderer.d.ts" />
|
|
10
11
|
|
|
11
12
|
declare namespace VM {
|
|
12
13
|
/**
|
|
@@ -75,6 +76,8 @@ declare namespace VM {
|
|
|
75
76
|
name: string;
|
|
76
77
|
costumes: Costume[];
|
|
77
78
|
sounds: Sound[];
|
|
79
|
+
clones: RenderedTarget[];
|
|
80
|
+
soundBank: AudioEngine.SoundBank | null;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
interface Field {
|
|
@@ -236,6 +239,55 @@ declare namespace VM {
|
|
|
236
239
|
size?: number;
|
|
237
240
|
}
|
|
238
241
|
|
|
242
|
+
const enum TextToSpeechVoice {
|
|
243
|
+
Alto = 'ALTO',
|
|
244
|
+
Tenor = 'TENOR',
|
|
245
|
+
Squeak = 'SQUEAK',
|
|
246
|
+
Giant = 'GIANT',
|
|
247
|
+
Kitten = 'KITTEN'
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
interface CustomState {
|
|
251
|
+
'Scratch.looks': {
|
|
252
|
+
drawableId: null | number;
|
|
253
|
+
skinId: null | number;
|
|
254
|
+
onSpriteRight: boolean;
|
|
255
|
+
text: string;
|
|
256
|
+
type: RenderWebGL.TextBubbleType;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
'Scratch.sound': {
|
|
260
|
+
effects: {
|
|
261
|
+
pitch: number;
|
|
262
|
+
pan: number;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
'Scratch.music': {
|
|
267
|
+
currentInstrument: number;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
'Scratch.pen': {
|
|
271
|
+
penDown: boolean;
|
|
272
|
+
color: number;
|
|
273
|
+
saturation: number;
|
|
274
|
+
brightness: number;
|
|
275
|
+
transparency: number;
|
|
276
|
+
_shade: number;
|
|
277
|
+
penAttributes: RenderWebGL.PenAttributes;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
'Scratch.text2speech': {
|
|
281
|
+
voiceId: TextToSpeechVoice;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
'Scratch.videoSensing': {
|
|
285
|
+
motionFrameNumber: number;
|
|
286
|
+
motionAmount: number;
|
|
287
|
+
motionDirection: number;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
239
291
|
interface BaseTarget extends EventEmitter<{}> {
|
|
240
292
|
runtime: Runtime;
|
|
241
293
|
|
|
@@ -247,7 +299,7 @@ declare namespace VM {
|
|
|
247
299
|
|
|
248
300
|
comments: Record<string, Comment>;
|
|
249
301
|
|
|
250
|
-
|
|
302
|
+
createComment(id: string, blockId: string, text: string, x: number, y: number, width: number, height: number, minimized?: boolean): void;
|
|
251
303
|
|
|
252
304
|
/**
|
|
253
305
|
* Called by runtime when the green flag is pressed.
|
|
@@ -282,6 +334,15 @@ declare namespace VM {
|
|
|
282
334
|
*/
|
|
283
335
|
createVariable(id: string, name: string, type: VariableType, isCloud?: boolean): void;
|
|
284
336
|
|
|
337
|
+
_customState: Partial<CustomState>;
|
|
338
|
+
getCustomState<T extends keyof CustomState>(name: T): CustomState[T] | undefined;
|
|
339
|
+
setCustomState<T extends keyof CustomState>(name: T, value: CustomState[T]): void;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Mirrors custom state.
|
|
343
|
+
*/
|
|
344
|
+
soundEffects?: CustomState['Scratch.sound']['effects'];
|
|
345
|
+
|
|
285
346
|
postSpriteInfo(spriteInfo: PostedSpriteInfo): void;
|
|
286
347
|
|
|
287
348
|
dispose(): void;
|
|
@@ -933,6 +994,11 @@ declare namespace VM {
|
|
|
933
994
|
*/
|
|
934
995
|
start(): void;
|
|
935
996
|
|
|
997
|
+
/**
|
|
998
|
+
* Stop all timers.
|
|
999
|
+
*/
|
|
1000
|
+
quit(): void;
|
|
1001
|
+
|
|
936
1002
|
/**
|
|
937
1003
|
* Start "when green flag pressed" scripts.
|
|
938
1004
|
*/
|
|
@@ -956,6 +1022,10 @@ declare namespace VM {
|
|
|
956
1022
|
|
|
957
1023
|
attachAudioEngine(audioEngine: AudioEngine): void;
|
|
958
1024
|
|
|
1025
|
+
v2BitmapAdapter?: ScratchSVGRenderer.BitmapAdapter;
|
|
1026
|
+
|
|
1027
|
+
attachV2BitmapAdapter(bitmapAdapter: ScratchSVGRenderer.BitmapAdapter): void;
|
|
1028
|
+
|
|
959
1029
|
storage: IfGui<GUIScratchStorage, ScratchStorage>;
|
|
960
1030
|
|
|
961
1031
|
attachStorage(storage: ScratchStorage): void;
|
|
@@ -1214,6 +1284,16 @@ declare class VM extends EventEmitter<VM.VirtualMachineEventMap> {
|
|
|
1214
1284
|
*/
|
|
1215
1285
|
attachAudioEngine(audioEngine: AudioEngine): void;
|
|
1216
1286
|
|
|
1287
|
+
/**
|
|
1288
|
+
* @deprecated Does nothing.
|
|
1289
|
+
*/
|
|
1290
|
+
attachV2SVGAdapter(): void;
|
|
1291
|
+
|
|
1292
|
+
/**
|
|
1293
|
+
* @see {VM.Runtime.attachV2BitmapAdapter}
|
|
1294
|
+
*/
|
|
1295
|
+
attachV2BitmapAdapter(bitmapAdapter: ScratchSVGRenderer.BitmapAdapter): void;
|
|
1296
|
+
|
|
1217
1297
|
/**
|
|
1218
1298
|
* @see {VM.Runtime.attachStorage}
|
|
1219
1299
|
*/
|
|
@@ -1226,6 +1306,11 @@ declare class VM extends EventEmitter<VM.VirtualMachineEventMap> {
|
|
|
1226
1306
|
*/
|
|
1227
1307
|
start(): void;
|
|
1228
1308
|
|
|
1309
|
+
/**
|
|
1310
|
+
* @see {VM.Runtime.quit}
|
|
1311
|
+
*/
|
|
1312
|
+
quit(): void;
|
|
1313
|
+
|
|
1229
1314
|
/**
|
|
1230
1315
|
* @see {VM.Runtime.greenFlag}
|
|
1231
1316
|
*/
|