sb3-types 0.1.9
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/jsr.yml +19 -0
- package/.github/workflows/publish.yml +0 -0
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/biome.json +22 -0
- package/enum.ts +1 -0
- package/enums/index.ts +13 -0
- package/enums/inputtype.ts +58 -0
- package/enums/shadow.ts +17 -0
- package/jsr.json +16 -0
- package/mod.ts +469 -0
- package/package.json +31 -0
- package/primitive.ts +103 -0
- package/tsconfig.json +24 -0
- package/tsdown.config.ts +6 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Publish package
|
|
19
|
+
run: npx jsr publish
|
|
File without changes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 pnsk-lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/biome.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
|
|
3
|
+
"organizeImports": {
|
|
4
|
+
"enabled": true
|
|
5
|
+
},
|
|
6
|
+
"linter": {
|
|
7
|
+
"enabled": true,
|
|
8
|
+
"rules": {
|
|
9
|
+
"recommended": true
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"formatter": {
|
|
13
|
+
"indentWidth": 2,
|
|
14
|
+
"indentStyle": "space"
|
|
15
|
+
},
|
|
16
|
+
"javascript": {
|
|
17
|
+
"formatter": {
|
|
18
|
+
"semicolons": "asNeeded",
|
|
19
|
+
"quoteStyle": "single"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
package/enum.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Shadow, InputType } from './enums'
|
package/enums/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Primitive type identifiers.
|
|
4
|
+
*/
|
|
5
|
+
/** When accepting all numbers */
|
|
6
|
+
export type Number = 4
|
|
7
|
+
// 汚染されるのはこのモジュールだけなので問題なし
|
|
8
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
|
|
9
|
+
export const Number: Number = 4
|
|
10
|
+
/** When accepting all positive numbers */
|
|
11
|
+
export type PossiveNumber = 5
|
|
12
|
+
export const PossiveNumber: PossiveNumber = 5
|
|
13
|
+
/** When accepting all positive integers */
|
|
14
|
+
export type PossiveInteger = 6
|
|
15
|
+
export const PossiveInteger: PossiveInteger = 6
|
|
16
|
+
/** When accepting all integers */
|
|
17
|
+
export type Integer = 7
|
|
18
|
+
export const Integer: Integer = 7
|
|
19
|
+
/**
|
|
20
|
+
* A wheel from -180 to 180 is displayed when editing the value.
|
|
21
|
+
*/
|
|
22
|
+
export type Angle = 8
|
|
23
|
+
export const Angle: Angle = 8
|
|
24
|
+
/**
|
|
25
|
+
* Color picker appears when editing value.
|
|
26
|
+
* @example "#rrggbb"
|
|
27
|
+
*/
|
|
28
|
+
export type Color = 9
|
|
29
|
+
export const Color: Color = 9
|
|
30
|
+
/** When accepting all strings (and numbers) */
|
|
31
|
+
export type String = 10
|
|
32
|
+
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
|
|
33
|
+
export const String: String = 10
|
|
34
|
+
/** It is a message. */
|
|
35
|
+
export type Broadcast = 11
|
|
36
|
+
export const Broadcast: Broadcast = 11
|
|
37
|
+
/**
|
|
38
|
+
* It is a round variable block.
|
|
39
|
+
*/
|
|
40
|
+
export type Variable = 12
|
|
41
|
+
export const Variable: Variable = 12
|
|
42
|
+
/**
|
|
43
|
+
* It is a round list block.
|
|
44
|
+
*/
|
|
45
|
+
export type List = 13
|
|
46
|
+
export const List: List = 13
|
|
47
|
+
/** Primitive type identifiers. */
|
|
48
|
+
export type All =
|
|
49
|
+
| Number
|
|
50
|
+
| PossiveNumber
|
|
51
|
+
| PossiveInteger
|
|
52
|
+
| Integer
|
|
53
|
+
| Angle
|
|
54
|
+
| Color
|
|
55
|
+
| String
|
|
56
|
+
| Broadcast
|
|
57
|
+
| Variable
|
|
58
|
+
| List
|
package/enums/shadow.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Shadow type indicating the appearance of the shadow.
|
|
4
|
+
*/
|
|
5
|
+
/** unobscured shadow */
|
|
6
|
+
export type UnObscured = 1
|
|
7
|
+
export const UnObscured: UnObscured = 1
|
|
8
|
+
/** no shadow */
|
|
9
|
+
export type No = 2
|
|
10
|
+
export const No: No = 2
|
|
11
|
+
/** obscured shadow */
|
|
12
|
+
export type Obscured = 3
|
|
13
|
+
export const Obscured: Obscured = 3
|
|
14
|
+
/**
|
|
15
|
+
* Shadow type indicating the appearance of the shadow.
|
|
16
|
+
*/
|
|
17
|
+
export type All = UnObscured | No | Obscured
|
package/jsr.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://jsr.io/schema/config-file.v1.json",
|
|
3
|
+
"name": "@pnsk-lab/sb3-types",
|
|
4
|
+
"exports": {
|
|
5
|
+
".": "./mod.ts",
|
|
6
|
+
"./enum": "./enum.ts"
|
|
7
|
+
},
|
|
8
|
+
"version": "0.1.9",
|
|
9
|
+
"publish": {
|
|
10
|
+
"include": [
|
|
11
|
+
"package.json",
|
|
12
|
+
"README.md",
|
|
13
|
+
"**/*.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/mod.ts
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import type { ScratchProject } from '@pnsk-lab/sb3-types'
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Shadow } from './enums/index.ts'
|
|
9
|
+
import type { InputPrimitive, TopLevelPrimitive } from './primitive.ts'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Scratch 3.0 Project Schema
|
|
13
|
+
*/
|
|
14
|
+
export interface ScratchProject {
|
|
15
|
+
meta: Meta
|
|
16
|
+
targets: (Stage | Sprite)[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Metadata for the Scratch Project
|
|
21
|
+
*/
|
|
22
|
+
export interface Meta {
|
|
23
|
+
/**
|
|
24
|
+
* Semantic versioning of the project
|
|
25
|
+
* @pattern ^(3\.[0-9]+\.[0-9]+)$
|
|
26
|
+
*/
|
|
27
|
+
semver: string
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Version of the Scratch Virtual Machine
|
|
31
|
+
* @pattern ^([0-9]+\.[0-9]+\.[0-9]+)($|-)
|
|
32
|
+
*/
|
|
33
|
+
vm?: string
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Agent used for creating the project
|
|
37
|
+
*/
|
|
38
|
+
agent?: string
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Origin of the project
|
|
42
|
+
*/
|
|
43
|
+
origin?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Stage type, representing the backdrop and stage-specific properties
|
|
48
|
+
*/
|
|
49
|
+
export interface Stage extends Target {
|
|
50
|
+
/**
|
|
51
|
+
* Name of the stage
|
|
52
|
+
*/
|
|
53
|
+
name: 'Stage'
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Indicates that this target is a stage
|
|
57
|
+
*/
|
|
58
|
+
isStage: true
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Tempo of the stage
|
|
62
|
+
*/
|
|
63
|
+
tempo?: number
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Transparency level of the video
|
|
67
|
+
*/
|
|
68
|
+
videoTransparency?: number
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* State of the video
|
|
72
|
+
*/
|
|
73
|
+
videoState?: 'on' | 'off' | 'on-flipped'
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Layer order of the stage
|
|
77
|
+
*/
|
|
78
|
+
layerOrder?: 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Sprite type, representing the individual characters in the project
|
|
83
|
+
*/
|
|
84
|
+
export interface Sprite extends Target {
|
|
85
|
+
/**
|
|
86
|
+
* Name of the sprite
|
|
87
|
+
* @not "\_stage\_"
|
|
88
|
+
*/
|
|
89
|
+
name: string
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Indicates that this target is not a stage
|
|
93
|
+
*/
|
|
94
|
+
isStage: false
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Visibility of the sprite
|
|
98
|
+
*/
|
|
99
|
+
visible?: boolean
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* X position of the sprite
|
|
103
|
+
*/
|
|
104
|
+
x?: number
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Y position of the sprite
|
|
108
|
+
*/
|
|
109
|
+
y?: number
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Size of the sprite
|
|
113
|
+
*/
|
|
114
|
+
size?: number
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Direction the sprite is facing
|
|
118
|
+
*/
|
|
119
|
+
direction?: number
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Whether the sprite is draggable
|
|
123
|
+
*/
|
|
124
|
+
draggable?: boolean
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Rotation style of the sprite
|
|
128
|
+
*/
|
|
129
|
+
rotationStyle?: 'all around' | "don't rotate" | 'left-right'
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Layer order of the sprite
|
|
133
|
+
* @minimum 1
|
|
134
|
+
*/
|
|
135
|
+
layerOrder?: number
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Common properties for both stages and sprites
|
|
140
|
+
*/
|
|
141
|
+
export interface Target {
|
|
142
|
+
/**
|
|
143
|
+
* Index of the current costume
|
|
144
|
+
* @minimum 0
|
|
145
|
+
*/
|
|
146
|
+
currentCostume: number
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Blocks associated with this target
|
|
150
|
+
*/
|
|
151
|
+
blocks: { [id: string]: Block | TopLevelPrimitive }
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Variables associated with this target
|
|
155
|
+
*/
|
|
156
|
+
variables: { [id: string]: ScalarVariable }
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Lists associated with this target
|
|
160
|
+
*/
|
|
161
|
+
lists: { [id: string]: List }
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Broadcast messages associated with this target
|
|
165
|
+
*/
|
|
166
|
+
broadcasts: { [id: string]: string }
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Comments associated with this target
|
|
170
|
+
*/
|
|
171
|
+
comments?: { [id: string]: Comment }
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Costumes associated with this target
|
|
175
|
+
*/
|
|
176
|
+
costumes: Costume[]
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Sounds associated with this target
|
|
180
|
+
*/
|
|
181
|
+
sounds: Sound[]
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Volume of the target
|
|
185
|
+
*/
|
|
186
|
+
volume?: number
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Definition for a block
|
|
191
|
+
* @see https://en.scratch-wiki.info/wiki/Scratch_File_Format#Blocks
|
|
192
|
+
*/
|
|
193
|
+
export interface Block {
|
|
194
|
+
/**
|
|
195
|
+
* A string naming the block.
|
|
196
|
+
*/
|
|
197
|
+
opcode: string
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Comment associated with the block
|
|
201
|
+
*/
|
|
202
|
+
comment?: string
|
|
203
|
+
/**
|
|
204
|
+
* An object associating names with arrays representing inputs into which other blocks may be dropped, including C mouths.
|
|
205
|
+
* The first element of each array is 1 if the input is a shadow, 2 if there is no shadow, and 3 if there is a shadow but it is obscured by the input.
|
|
206
|
+
* The second is either the ID of the input or an array representing it as described in the table below.
|
|
207
|
+
* If there is an obscured shadow, the third element is its ID or an array representing it.
|
|
208
|
+
* @related {@link Input}
|
|
209
|
+
*/
|
|
210
|
+
inputs?: { [id: string]: Input }
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Fields are text boxes, drop-down menus, etc.
|
|
214
|
+
* These are used directly in {@link https://en.scratch-wiki.info/wiki/Blocks blocks} where there is an {@link https://en.scratch-wiki.info/wiki/Argument input} into which one cannot drop a {@link https://en.scratch-wiki.info/wiki/Reporter_Block reporter}.
|
|
215
|
+
* However, more often than not, one should be able to do this;
|
|
216
|
+
* in this case no field exists directly in the block, but an input does, and that input may have a shadow block in it.
|
|
217
|
+
|
|
218
|
+
* An object associating names with arrays representing fields.
|
|
219
|
+
* The first element of each array is the field's value.
|
|
220
|
+
* For certain fields, such as variable and broadcast dropdown menus, there is also a second element, which is the ID of the field's value.
|
|
221
|
+
* @example ```json
|
|
222
|
+
* { "KEY_OPTION": ["enter", null] }
|
|
223
|
+
* { "VARIABLE": ["variable_name", "variable_id"] }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
fields?: {
|
|
227
|
+
[id: string]: Fields
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* The ID of the following block or `null`.
|
|
232
|
+
*/
|
|
233
|
+
next?: string | null
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* False if the block has a parent and true otherwise.
|
|
237
|
+
*/
|
|
238
|
+
topLevel?: boolean
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* If the block is a {@link https://en.scratch-wiki.info/wiki/Stack_Block stack block} and is preceded, this is the ID of the preceding block.
|
|
242
|
+
* If the block is the first stack block in a {@link https://en.scratch-wiki.info/wiki/C_Block C mouth}, this is the ID of the C block.
|
|
243
|
+
* If the block is an input to another block, this is the ID of that other block.
|
|
244
|
+
* Otherwise it is `null`.
|
|
245
|
+
*/
|
|
246
|
+
parent?: string | null
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* True if this is a shadow block and false otherwise.
|
|
250
|
+
*/
|
|
251
|
+
shadow?: boolean
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* X position of the block
|
|
255
|
+
*/
|
|
256
|
+
x?: number
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Y position of the block
|
|
260
|
+
*/
|
|
261
|
+
y?: number
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Mutation data for the block
|
|
265
|
+
*/
|
|
266
|
+
mutation?: Mutation
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* look {@link Block.mutation}
|
|
271
|
+
*/
|
|
272
|
+
export type Mutation =
|
|
273
|
+
| Mutation_procedures_call
|
|
274
|
+
| Mutation_procedures_prototype
|
|
275
|
+
| Mutation_control_stop
|
|
276
|
+
|
|
277
|
+
interface MutationBase {
|
|
278
|
+
/** The tag name, which is always 'mutation'. */
|
|
279
|
+
tagName?: 'mutation'
|
|
280
|
+
|
|
281
|
+
/** An array of child elements (typically empty). */
|
|
282
|
+
children?: []
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface Mutation_procedures_call extends MutationBase {
|
|
286
|
+
/** The procedure code for custom blocks. */
|
|
287
|
+
proccode?: string
|
|
288
|
+
/*
|
|
289
|
+
* https://github.com/scratchfoundation/scratch-parser/blob/665f05d739a202d565a4af70a201909393d456b2/lib/sb3_definitions.json#L282-L284
|
|
290
|
+
* ではstring
|
|
291
|
+
* https://en.scratch-wiki.info/wiki/Scratch_File_Format
|
|
292
|
+
* ではAn array of the ids of the argumentsとの記述。
|
|
293
|
+
/** The IDs of arguments for the procedure. */
|
|
294
|
+
argumentids?: string | string[]
|
|
295
|
+
|
|
296
|
+
/** Indicates if the procedure is a warp (runs without screen refresh). */
|
|
297
|
+
warp?: 'true' | 'false' | 'null' | boolean | null
|
|
298
|
+
}
|
|
299
|
+
interface Mutation_procedures_prototype extends MutationBase {
|
|
300
|
+
/**
|
|
301
|
+
* An array of the names of the arguments. This is only present when the block has an opcode of procedures_prototype.
|
|
302
|
+
*/
|
|
303
|
+
argumentnames: string | string[]
|
|
304
|
+
/**
|
|
305
|
+
* An array of the defaults of the arguments; for string/number arguments, this is an empty string, and for boolean arguments it is false. This is only present when the block has an opcode of procedures_prototype.
|
|
306
|
+
*/
|
|
307
|
+
argumentdefaults: (string | boolean)[]
|
|
308
|
+
}
|
|
309
|
+
interface Mutation_control_stop extends MutationBase {
|
|
310
|
+
/** Indicates if the procedure has a next block. */
|
|
311
|
+
hasnext?: 'true' | 'false' | 'null' | boolean | null
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Definition for a comment
|
|
316
|
+
*/
|
|
317
|
+
export interface Comment {
|
|
318
|
+
/**
|
|
319
|
+
* ID of the block this comment is attached to
|
|
320
|
+
*/
|
|
321
|
+
blockId?: string | null
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Text of the comment
|
|
325
|
+
* @maxLength 8000
|
|
326
|
+
*/
|
|
327
|
+
text: string
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Indicates if the comment is minimized
|
|
331
|
+
*/
|
|
332
|
+
minimized?: boolean
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* X position of the comment
|
|
336
|
+
*/
|
|
337
|
+
x?: number | null
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Y position of the comment
|
|
341
|
+
*/
|
|
342
|
+
y?: number | null
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Width of the comment
|
|
346
|
+
*/
|
|
347
|
+
width?: number
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Height of the comment
|
|
351
|
+
*/
|
|
352
|
+
height?: number
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Costume definition
|
|
357
|
+
*/
|
|
358
|
+
export interface Costume {
|
|
359
|
+
/**
|
|
360
|
+
* Asset ID of the costume
|
|
361
|
+
* @pattern ^[a-fA-F0-9]{32}$
|
|
362
|
+
*/
|
|
363
|
+
assetId: string
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Bitmap resolution of the costume
|
|
367
|
+
*/
|
|
368
|
+
bitmapResolution?: number
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Data format of the costume
|
|
372
|
+
* @enum ["png", "svg", "jpeg", "jpg", "bmp", "gif"]
|
|
373
|
+
*/
|
|
374
|
+
dataFormat: 'png' | 'svg' | 'jpeg' | 'jpg' | 'bmp' | 'gif'
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* MD5 extension of the costume
|
|
378
|
+
* @pattern ^[a-fA-F0-9]{32}\.[a-zA-Z]+$
|
|
379
|
+
*/
|
|
380
|
+
md5ext?: string
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Name of the costume
|
|
384
|
+
*/
|
|
385
|
+
name: string
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* X coordinate of the costume's rotation center
|
|
389
|
+
*/
|
|
390
|
+
rotationCenterX?: number
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Y coordinate of the costume's rotation center
|
|
394
|
+
*/
|
|
395
|
+
rotationCenterY?: number
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Sound definition
|
|
400
|
+
*/
|
|
401
|
+
export interface Sound {
|
|
402
|
+
/**
|
|
403
|
+
* Asset ID of the sound
|
|
404
|
+
* @pattern ^[a-fA-F0-9]{32}$
|
|
405
|
+
*/
|
|
406
|
+
assetId: string
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Data format of the sound
|
|
410
|
+
*/
|
|
411
|
+
dataFormat: 'wav' | 'wave' | 'mp3'
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* MD5 extension of the sound
|
|
415
|
+
* @pattern ^[a-fA-F0-9]{32}\.[a-zA-Z0-9]+$
|
|
416
|
+
*/
|
|
417
|
+
md5ext?: string
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Name of the sound
|
|
421
|
+
*/
|
|
422
|
+
name: string
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Sample rate of the sound
|
|
426
|
+
*/
|
|
427
|
+
rate?: number
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Sample count of the sound
|
|
431
|
+
*/
|
|
432
|
+
sampleCount?: number
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Represents a scalar value, which can be a string, number, or boolean.
|
|
437
|
+
*/
|
|
438
|
+
export type ScalarVal = string | number | boolean
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Represents a scalar variable.
|
|
442
|
+
*/
|
|
443
|
+
export type ScalarVariable = [
|
|
444
|
+
displayName: string,
|
|
445
|
+
defaultValue: ScalarVal,
|
|
446
|
+
isCloudVariable?: boolean,
|
|
447
|
+
]
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Represents a list.
|
|
451
|
+
*/
|
|
452
|
+
export type List = [displayName: string, defaultValue: ScalarVal[]]
|
|
453
|
+
|
|
454
|
+
export type InputPrimitiveOrReference = InputPrimitive | /* blockId */ string
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* The input value held by the block
|
|
458
|
+
* @related
|
|
459
|
+
*/
|
|
460
|
+
export type Input =
|
|
461
|
+
| [Shadow.UnObscured | Shadow.No, InputPrimitiveOrReference]
|
|
462
|
+
| [Shadow.Obscured, InputPrimitiveOrReference, InputPrimitiveOrReference]
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* look {@link Block.fields}
|
|
466
|
+
*/
|
|
467
|
+
export type Fields = [string, null] | [string, string]
|
|
468
|
+
|
|
469
|
+
export * from './primitive'
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sb3-types",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.1.9",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"default": "./dist/mod.mjs",
|
|
9
|
+
"types": "./dist/mod.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./enum": {
|
|
12
|
+
"default": "./dist/enums/index.mjs",
|
|
13
|
+
"types": "./dist/enums/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"publish": "jsr publish",
|
|
18
|
+
"format": "biome format",
|
|
19
|
+
"lint": "biome lint",
|
|
20
|
+
"format:fix": "biome format --fix"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@biomejs/biome": "^1.8.1",
|
|
24
|
+
"@types/bun": "latest",
|
|
25
|
+
"jsr": "^0.12.4",
|
|
26
|
+
"tsdown": "^0.20.3"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"typescript": "^5.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/primitive.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { InputType } from './enums'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Represents a number primitive in Scratch 3.0.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface NumPrimitive {
|
|
8
|
+
/** Primitive type identifier. */
|
|
9
|
+
0:
|
|
10
|
+
| InputType.Number
|
|
11
|
+
| InputType.PossiveNumber
|
|
12
|
+
| InputType.PossiveInteger
|
|
13
|
+
| InputType.Integer
|
|
14
|
+
| InputType.Angle
|
|
15
|
+
|
|
16
|
+
/** The value of the number primitive, which can be a string or a number. */
|
|
17
|
+
1: string | number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents a color primitive in Scratch 3.0.
|
|
22
|
+
*/
|
|
23
|
+
export interface ColorPrimitive {
|
|
24
|
+
/** Primitive type identifier. */
|
|
25
|
+
0: InputType.Color
|
|
26
|
+
|
|
27
|
+
/** The color value in hex format (e.g., #RRGGBB). */
|
|
28
|
+
1: `#${string}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents a text primitive in Scratch 3.0.
|
|
33
|
+
*/
|
|
34
|
+
export interface TextPrimitive {
|
|
35
|
+
/** Primitive type identifier. */
|
|
36
|
+
0: InputType.String
|
|
37
|
+
|
|
38
|
+
/** The value of the text primitive, which can be a string or a number. */
|
|
39
|
+
1: string | number
|
|
40
|
+
} /**
|
|
41
|
+
* Represents a broadcast primitive in Scratch 3.0.
|
|
42
|
+
*/
|
|
43
|
+
export interface BroadcastPrimitive {
|
|
44
|
+
/** Primitive type identifier. */
|
|
45
|
+
0: InputType.Broadcast
|
|
46
|
+
|
|
47
|
+
/** The name of broadcast message. */
|
|
48
|
+
1: string
|
|
49
|
+
|
|
50
|
+
/** The broadcast message ID. */
|
|
51
|
+
2: string
|
|
52
|
+
} /**
|
|
53
|
+
* Represents a variable primitive in Scratch 3.0.
|
|
54
|
+
*/
|
|
55
|
+
export interface VariablePrimitive {
|
|
56
|
+
/** Primitive type identifier. */
|
|
57
|
+
0: InputType.Variable
|
|
58
|
+
|
|
59
|
+
/** The name of the variable. */
|
|
60
|
+
1: string
|
|
61
|
+
|
|
62
|
+
/** The ID of the variable. */
|
|
63
|
+
2: string
|
|
64
|
+
|
|
65
|
+
/** x position */
|
|
66
|
+
3?: number
|
|
67
|
+
|
|
68
|
+
/** y position */
|
|
69
|
+
4?: number
|
|
70
|
+
} /**
|
|
71
|
+
* Represents a list primitive in Scratch 3.0.
|
|
72
|
+
*/
|
|
73
|
+
export interface ListPrimitive {
|
|
74
|
+
/** Primitive type identifier. */
|
|
75
|
+
0: InputType.List
|
|
76
|
+
|
|
77
|
+
/** The name of the list. */
|
|
78
|
+
1: string
|
|
79
|
+
|
|
80
|
+
/** The ID of the list. */
|
|
81
|
+
2: string
|
|
82
|
+
|
|
83
|
+
/** x position */
|
|
84
|
+
3?: number
|
|
85
|
+
|
|
86
|
+
/** y position */
|
|
87
|
+
4?: number
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Represents input primitives in Scratch 3.0.
|
|
91
|
+
*/
|
|
92
|
+
export type InputPrimitive =
|
|
93
|
+
| NumPrimitive
|
|
94
|
+
| ColorPrimitive
|
|
95
|
+
| TextPrimitive
|
|
96
|
+
| BroadcastPrimitive
|
|
97
|
+
| VariablePrimitive
|
|
98
|
+
| ListPrimitive
|
|
99
|
+
/**
|
|
100
|
+
* Top-level primitive block
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
export type TopLevelPrimitive = VariablePrimitive | ListPrimitive
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
// Bundler mode
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
// Best practices
|
|
16
|
+
"strict": true,
|
|
17
|
+
"skipLibCheck": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true,
|
|
19
|
+
// Some stricter flags (disabled by default)
|
|
20
|
+
"noUnusedLocals": false,
|
|
21
|
+
"noUnusedParameters": false,
|
|
22
|
+
"noPropertyAccessFromIndexSignature": false
|
|
23
|
+
}
|
|
24
|
+
}
|