@turbowarp/types 0.0.2 → 0.0.3

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.
@@ -20,5 +20,10 @@ jobs:
20
20
  run: npm ci
21
21
  - name: Validate TypeScript
22
22
  run: npm test
23
- - name: Validate index.d.ts
24
- run: npx tsc index.d.ts
23
+ - name: Validate individual .d.ts files
24
+ run: |
25
+ set -e
26
+ for i in index.d.ts types/*.d.ts; do
27
+ echo "Validating $i"
28
+ npx tsc "$i" --target es6 --noEmit
29
+ done
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Types definitions for the Scratch VM and editor
1
+ # Type definitions for the Scratch VM and editor
2
2
 
3
3
  Scratch doesn't provide type definitions for their libraries, so we wrote our own.
4
4
 
@@ -10,14 +10,14 @@ Despite being in the TurboWarp organization, this project is currently focused o
10
10
  |:-:|:-:|
11
11
  |scratch-vm|✅|
12
12
  |scratch-render|✅|
13
- |scratch-svg-renderer|❌|
14
- |scratch-render-fonts|❌|
15
- |scratch-audio|🚧|
16
- |scratch-storage|❌|
17
- |scratch-parser|❌|
13
+ |scratch-svg-renderer|✅|
14
+ |scratch-render-fonts|✅|
15
+ |scratch-audio|✅|
16
+ |scratch-storage|✅|
17
+ |scratch-parser|✅|
18
18
  |scratch-blocks|🚧|
19
- |scratch-gui redux|❌|
20
- |scratch-paint redux|❌|
19
+ |scratch-gui redux|✅|
20
+ |scratch-paint redux|✅|
21
21
  |scratch-www redux|❌|
22
22
 
23
23
  ## Using from npm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/types",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Type definitions for the Scratch VM and editor",
5
5
  "keywords": [
6
6
  "scratch"
@@ -0,0 +1,17 @@
1
+ import AudioEngine from 'scratch-audio';
2
+
3
+ declare const vm: VM;
4
+ const audioEngine = new AudioEngine();
5
+ vm.attachAudioEngine(audioEngine);
6
+
7
+ audioEngine.decodeSoundPlayer({
8
+ data: {
9
+ buffer: new ArrayBuffer(10)
10
+ }
11
+ })
12
+ .then((player) => {
13
+ player.on('stop', () => {
14
+
15
+ });
16
+ return player.finished();
17
+ });
@@ -0,0 +1,16 @@
1
+ declare const state: ScratchGUI.ReduxState;
2
+ declare function dispatch(event: ScratchGUI.ReduxEvent): void;
3
+
4
+ const vm = state.scratchGui.vm;
5
+ vm.greenFlag();
6
+ vm.renderer._allDrawables[0].updateVisible(false);
7
+
8
+ dispatch({
9
+ type: 'scratch-gui/navigation/ACTIVATE_TAB',
10
+ activeTabIndex: 0
11
+ });
12
+
13
+ state.scratchPaint.cursor.charAt(0);
14
+ dispatch({
15
+ type: 'scratch-paint/undo/CLEAR'
16
+ });
@@ -0,0 +1,9 @@
1
+ import unpack from 'scratch-parser';
2
+
3
+ unpack('{}', false, (error, unpacked) => {
4
+ if (error) {
5
+ console.error(error);
6
+ } else {
7
+ const [target, zip] = unpacked;
8
+ }
9
+ });
@@ -0,0 +1,4 @@
1
+ import getFonts from 'scratch-render-fonts';
2
+
3
+ const fonts = getFonts();
4
+ console.log(atob(fonts['Curly']));
@@ -0,0 +1,22 @@
1
+ import ScratchStorage from 'scratch-storage';
2
+
3
+ declare const vm: VM;
4
+
5
+ const storage = new ScratchStorage();
6
+ vm.attachStorage(storage);
7
+
8
+ ScratchStorage.DataFormat.JPG === 'jpg';
9
+ storage.DataFormat.JPG === 'jpg';
10
+
11
+ storage.addWebStore(
12
+ [
13
+ ScratchStorage.AssetType.ImageVector,
14
+ ScratchStorage.AssetType.ImageBitmap,
15
+ storage.AssetType.Sound,
16
+ ],
17
+ asset => {
18
+ const assetId = asset.assetId;
19
+ const dataFormat = asset.dataFormat;
20
+ return `https://assets.scratch.mit.edu/${assetId}.${dataFormat}`;
21
+ }
22
+ );
@@ -0,0 +1,8 @@
1
+ import * as SvgRenderer from 'scratch-svg-renderer';
2
+
3
+ const svg = SvgRenderer.loadSvgString('imagine that this is an SVG', false);
4
+ const serialized = SvgRenderer.serializeSvgToString(svg);
5
+ const inlinedFonts = SvgRenderer.inlineSvgFonts('an svg here');
6
+ const fixedFonts = SvgRenderer.convertFonts(SvgRenderer.SvgElement.create('svg'));
7
+
8
+ const bitmapAdapter = new SvgRenderer.BitmapAdapter();
package/tests/vm.ts CHANGED
@@ -40,6 +40,12 @@ if (target) {
40
40
  const mutation = block.mutation as VM.ProcedureCallMutation;
41
41
  JSON.parse(mutation.argumentids);
42
42
  }
43
+
44
+ const bubbleState = target.getCustomState('Scratch.looks');
45
+ if (bubbleState) {
46
+ bubbleState.text.charAt(0);
47
+ target.setCustomState('Scratch.looks', bubbleState);
48
+ }
43
49
  } else {
44
50
  const doesNotExist: undefined = target;
45
51
  }
@@ -0,0 +1,12 @@
1
+ // Type definitions for paper.js
2
+ // Project: https://github.com/LLK/paper.js
3
+
4
+ declare namespace Paper {
5
+ interface Base {
6
+ // TODO
7
+ }
8
+
9
+ interface Matrix {
10
+ // TODO
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ // Type definitions for React 16
2
+ // Project: https://reactjs.org/
3
+
4
+ declare namespace React {
5
+ interface Element {
6
+ // TODO
7
+ }
8
+ }
@@ -1,8 +1,74 @@
1
1
  // Type definitions for scratch-audio
2
2
  // Project: https://github.com/LLK/scratch-audio
3
3
 
4
+ /// <reference path="./events.d.ts" />
5
+
4
6
  declare namespace AudioEngine {
5
- interface SoundPlayer {
7
+ interface Target {
8
+ // TODO
9
+ }
10
+
11
+ interface Loudness {
12
+ audioContext: AudioContext;
13
+ connectingToMic: boolean;
14
+ mic: MediaStreamAudioSourceNode;
15
+
16
+ /**
17
+ * @returns Loudness measured from 0-100.
18
+ */
19
+ getLoudness(): number;
20
+ }
21
+
22
+ interface Effect {
23
+ audioEngine: AudioEngine;
24
+ audioPlayer: SoundPlayer;
25
+ lastEffect: Effect;
26
+ value: number;
27
+ initialized: boolean;
28
+ initialize(): void;
29
+ inputNode: AudioNode;
30
+ getInputNode(): AudioNode;
31
+ outputNode: AudioNode;
32
+ target: Target;
33
+ connect(target: Target): void;
34
+ get name(): string;
35
+ get DEFAULT_VALUE(): string;
36
+ get _isPatch(): boolean;
37
+ _set(value: number): void;
38
+ set(value: number): void;
39
+ update(): void;
40
+ clear(): void;
41
+ dispose(): void;
42
+ }
43
+
44
+ interface EffectChain {
45
+ audioEngine: AudioEngine;
46
+ inputNode: GainNode;
47
+ getInputNode(): GainNode;
48
+ effects: Effect[];
49
+ _effects: Effect[];
50
+ firstEffect: Effect;
51
+ lastEffect: Effect;
52
+ _soundPlayers: Set<SoundPlayer>;
53
+ getSoundPlayers(): SoundPlayer[];
54
+ clone(): EffectChain;
55
+ addSoundPlayer(soundPlayer: SoundPlayer): void;
56
+ removeSoundPlayer(soundPlayer: SoundPlayer): void;
57
+ target?: AudioNode;
58
+ connect(target: AudioNode): void;
59
+ setEffectsFromTarget(target: Target): void;
60
+ set(effect: string, value: number): void;
61
+ update(): void;
62
+ clear(): void;
63
+ dispose(): void;
64
+ }
65
+
66
+ interface SoundPlayerEventMap {
67
+ stop: [];
68
+ play: [];
69
+ }
70
+
71
+ interface SoundPlayer extends EventEmitter<SoundPlayerEventMap> {
6
72
  id: string;
7
73
  audioEngine: AudioEngine;
8
74
  buffer: AudioBuffer;
@@ -21,9 +87,64 @@ declare namespace AudioEngine {
21
87
  finished(): Promise<void>;
22
88
  setPlaybackRate(playbackRate: number): void;
23
89
  }
90
+
91
+ interface SoundBank {
92
+ audioEngine: AudioEngine;
93
+ soundPlayers: Record<string, SoundPlayer>;
94
+ playerTargets: Record<string, Target>;
95
+ soundEffects: Record<string, EffectChain>;
96
+ effectChainPrime: EffectChain;
97
+ addSoundPlayer(soundPlayer: SoundPlayer): void;
98
+ getSoundPlayer(soundId: string): SoundPlayer | undefined;
99
+ getSoundEffects(soundId: string): EffectChain;
100
+ playSound(target: Target, soundId: string): Promise<void>;
101
+ setEffects(target: Target): void;
102
+ stop(target: Target, soundId: string): void;
103
+ stopAllSounds(target: Target | '*'): void;
104
+ dispose(): void;
105
+ }
106
+
107
+ interface SoundToDecode {
108
+ data: {
109
+ buffer: ArrayBuffer;
110
+ }
111
+ }
24
112
  }
25
113
 
26
114
  declare class AudioEngine {
115
+ constructor(audioContext?: AudioContext);
116
+
27
117
  audioContext: AudioContext;
118
+ get currentTime(): number;
119
+
28
120
  inputNode: GainNode;
121
+ getInputNode(): GainNode;
122
+
123
+ audioBuffers: Record<string, ArrayBuffer>;
124
+
125
+ loudness: AudioEngine.Loudness | null;
126
+ /**
127
+ * @see {AudioEngine.Loudness.getLoudness}
128
+ */
129
+ getLoudness(): number;
130
+
131
+ effects: AudioEngine.Effect[];
132
+ get EFFECT_NAMES(): Record<string, string>;
133
+ get DECAY_DURATION(): number;
134
+ get DECAY_WAIT(): number;
135
+
136
+ _emptySound(): AudioBuffer;
137
+
138
+ decodeSound(sound: AudioEngine.SoundToDecode): Promise<string>;
139
+
140
+ decodeSoundPlayer(sound: AudioEngine.SoundToDecode): Promise<AudioEngine.SoundPlayer>;
141
+
142
+ /**
143
+ * Returns a tuple of [sound id, buffer]
144
+ */
145
+ _decodeSound(sound: AudioEngine.SoundToDecode): Promise<[string, AudioBuffer]>;
146
+
147
+ createEffectChain(): AudioEngine.EffectChain;
148
+
149
+ createBank(): AudioEngine.SoundBank;
29
150
  }