@kubohiroya/turbowarp-text-lines 0.2.1 → 0.4.0
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/README.ja.md +128 -0
- package/README.md +6 -1
- package/assets/block-icon.svg +1 -0
- package/dist/text-lines.js +379 -363
- package/package.json +8 -7
package/README.ja.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# TurboWarp-Text-Lines
|
|
2
|
+
|
|
3
|
+
<img src="assets/block-icon.svg" alt="" width="48" height="48">
|
|
4
|
+
|
|
5
|
+
[English](README.md) | 日本語
|
|
6
|
+
|
|
7
|
+
TurboWarpのプロジェクトで複数行テキストを扱います。Text Linesは次の3つのblockを追加します。
|
|
8
|
+
|
|
9
|
+
- テキストの行数を数える。
|
|
10
|
+
- 位置を指定して1行を取り出す。
|
|
11
|
+
- テキストの全行でScratchのリストを置き換える。
|
|
12
|
+
|
|
13
|
+
**ユーザーガイド:** [English](https://kubohiroya.github.io/turbowarp-text-lines/) · [日本語](https://kubohiroya.github.io/turbowarp-text-lines/ja/)
|
|
14
|
+
|
|
15
|
+
## クイックスタート
|
|
16
|
+
|
|
17
|
+
1. [`dist/text-lines.js`](dist/text-lines.js?raw=1)をダウンロードします。
|
|
18
|
+
2. **TurboWarp Desktop**で**拡張機能**を開き、**カスタム拡張機能**を選んで、ダウンロードしたファイルを読み込みます。
|
|
19
|
+
3. TurboWarpが確認したら**サンドボックス化せずに実行**を有効にします。
|
|
20
|
+
|
|
21
|
+
> [!IMPORTANT]
|
|
22
|
+
> Text Linesのcommand blockはScratchのリストへ直接書き込むため、サンドボックスなしで動作させる必要があります。
|
|
23
|
+
|
|
24
|
+
そのまま使えるJavaScriptファイルをこのリポジトリにcommitしてあります。インストールにNode.jsは要りません。
|
|
25
|
+
|
|
26
|
+
## 動かしてみる
|
|
27
|
+
|
|
28
|
+
次のテキストを入力とします。
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
Apple
|
|
32
|
+
Banana
|
|
33
|
+
Cherry
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
同じテキストを、各blockが別々の使い方で扱います。
|
|
37
|
+
|
|
38
|
+
```mermaid
|
|
39
|
+
flowchart TD
|
|
40
|
+
input["入力テキスト<br/>Apple<br/>Banana<br/>Cherry"]
|
|
41
|
+
input --> count["number of lines in TEXT<br/>戻り値: 3"]
|
|
42
|
+
input --> line["line 2 of TEXT<br/>戻り値: Banana"]
|
|
43
|
+
input --> list["put lines of TEXT into list items<br/>リスト: Apple · Banana · Cherry"]
|
|
44
|
+
|
|
45
|
+
classDef source fill:#ffffff,color:#18212b,stroke:#5b80a5,stroke-width:2px
|
|
46
|
+
classDef extension fill:#5b80a5,color:#ffffff,stroke:#3f658a,stroke-width:2px
|
|
47
|
+
class input source
|
|
48
|
+
class count,line,list extension
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
角の丸い2つのreporter blockは値を返します。command blockは選択したリストをその場で書き換えます。
|
|
52
|
+
|
|
53
|
+
## ブロック
|
|
54
|
+
|
|
55
|
+
### どのblockを使うか
|
|
56
|
+
|
|
57
|
+
| 目的 | block | 上の例での結果 |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| 全行を数える | `number of lines in [TEXT]` | `3` |
|
|
60
|
+
| 1行を読む | `line [LINE] of [TEXT]`(行に`2`を指定) | `Banana` |
|
|
61
|
+
| テキストをリストの項目にする | `put lines of [TEXT] into list [LIST]` | `Apple`、`Banana`、`Cherry` |
|
|
62
|
+
|
|
63
|
+
### block定義
|
|
64
|
+
|
|
65
|
+
正式な定義は[`src/block-definitions.json`](src/block-definitions.json)から生成します。
|
|
66
|
+
|
|
67
|
+
| block | 種別 | opcode | 動作 |
|
|
68
|
+
|---|---|---|---|
|
|
69
|
+
| `number of lines in [TEXT]` | Reporter | `lineCount` | 渡されたテキストの行数を返します。 |
|
|
70
|
+
| `line [LINE] of [TEXT]` | Reporter | `lineAt` | 1始まりの行番号で1行を返します。範囲外の行番号は空文字列を返します。 |
|
|
71
|
+
| `put lines of [TEXT] into list [LIST]` | Command | `writeLinesToList` | 指定したScratchリストの内容を、渡されたテキストの各行で置き換えます。 |
|
|
72
|
+
|
|
73
|
+
`TEXT`の既定値は`first line\nsecond line`、`LINE`の既定値は`1`、`LIST`は`LIST_MENU`から選びます。
|
|
74
|
+
|
|
75
|
+
## 重要な挙動
|
|
76
|
+
|
|
77
|
+
| 状況 | Text Linesの動作 |
|
|
78
|
+
|---|---|
|
|
79
|
+
| 行番号 | `0`ではなく`1`から数えます |
|
|
80
|
+
| 不正な行番号 | 空文字列を返します |
|
|
81
|
+
| 空のテキスト | 空行1行として扱います |
|
|
82
|
+
| 改行で終わるテキスト | 末尾に空行を1つ加えます |
|
|
83
|
+
| リストのcommand | 選択したリストの既存項目をすべて置き換えます |
|
|
84
|
+
| 改行コード | LF(`\n`)、CRLF(`\r\n`)、CR(`\r`)を受け付けます |
|
|
85
|
+
|
|
86
|
+
> [!WARNING]
|
|
87
|
+
> リストのcommandを実行する前に、残したい内容は控えておいてください。
|
|
88
|
+
|
|
89
|
+
図入りの例と日本語版は[ユーザーガイド](https://kubohiroya.github.io/turbowarp-text-lines/)にあります。
|
|
90
|
+
|
|
91
|
+
## 開発
|
|
92
|
+
|
|
93
|
+
Node.js 24以降で依存関係をインストールし、すべての検査を実行します。
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npm install --global corepack@latest
|
|
97
|
+
corepack enable
|
|
98
|
+
pnpm install --frozen-lockfile
|
|
99
|
+
pnpm run check
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
よく使うコマンドです。
|
|
103
|
+
|
|
104
|
+
| コマンド | 用途 |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `pnpm run dev` | ファイルの変更に追従して拡張機能を再ビルドする |
|
|
107
|
+
| `pnpm run test` | テストを1回実行する |
|
|
108
|
+
| `pnpm run typecheck` | TypeScriptの型を検査する |
|
|
109
|
+
| `pnpm run build` | `dist/text-lines.js`をビルドする |
|
|
110
|
+
| `pnpm run docs` | 正式な定義からblockの一覧を再生成する |
|
|
111
|
+
|
|
112
|
+
拡張機能のsourceを変更したら、再ビルドして[`dist/text-lines.js`](dist/text-lines.js)をcommitしてください。
|
|
113
|
+
block定義を変更したら、commit前に`pnpm run docs`を実行してください。
|
|
114
|
+
|
|
115
|
+
## リリース情報
|
|
116
|
+
|
|
117
|
+
このリポジトリの今後のライセンスのsource of truthはMPL-2.0です。この判断は、リポジトリのライセンス履歴、
|
|
118
|
+
Viteの拡張機能metadata、生成bundleのheaderに基づきます。公開済みのpackage versionは配布時の条件を維持し、
|
|
119
|
+
このリポジトリが過去の許諾を遡って取り消すことはありません。
|
|
120
|
+
|
|
121
|
+
package metadataのsource of truthは`package.json`です。`repo-policy.json`がリポジトリのpolicyを記録し、
|
|
122
|
+
`pnpm run check`がREADME、LICENSE、package metadata、生成された`dist/`、npm packageの内容を検証します。
|
|
123
|
+
|
|
124
|
+
## ライセンス
|
|
125
|
+
|
|
126
|
+
SPDX-License-Identifier: MPL-2.0
|
|
127
|
+
|
|
128
|
+
固定入力の編集範囲・互換性・切戻しについては[固定入力の編集](docs/fixed-input-editors.ja.md)を参照してください。
|
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# TurboWarp-Text-Lines
|
|
2
2
|
|
|
3
|
+
<img src="assets/block-icon.svg" alt="" width="48" height="48">
|
|
4
|
+
|
|
5
|
+
English | [日本語](README.ja.md)
|
|
6
|
+
|
|
3
7
|
Use multiline text in TurboWarp projects. Text Lines adds three blocks that can:
|
|
4
8
|
|
|
5
9
|
- count the lines in some text;
|
|
@@ -127,9 +131,10 @@ For illustrated examples and the Japanese version, open the [complete user guide
|
|
|
127
131
|
|
|
128
132
|
## Development
|
|
129
133
|
|
|
130
|
-
Install dependencies with Node.js
|
|
134
|
+
Install dependencies with Node.js 24 or later and run every check:
|
|
131
135
|
|
|
132
136
|
```bash
|
|
137
|
+
npm install --global corepack@latest
|
|
133
138
|
corepack enable
|
|
134
139
|
pnpm install --frozen-lockfile
|
|
135
140
|
pnpm run check
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><g fill="#4C97FF"><circle cx="11" cy="16" r="2.6"/><circle cx="11" cy="24" r="2.6"/><circle cx="11" cy="32" r="2.6"/></g><path d="M19 16h20M19 24h20M19 32h13" fill="none" stroke="#59C059" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
package/dist/text-lines.js
CHANGED
|
@@ -7,368 +7,384 @@
|
|
|
7
7
|
(function (Scratch) {
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
10
|
+
//#region src/config.ts
|
|
11
|
+
var extensionConfig = {
|
|
12
|
+
id: "kubohiroyatextlines",
|
|
13
|
+
slug: "text-lines",
|
|
14
|
+
name: "Text Lines",
|
|
15
|
+
description: "Count, read, and split text by lines in TurboWarp.",
|
|
16
|
+
author: "Hiroya Kubo",
|
|
17
|
+
license: "MPL-2.0",
|
|
18
|
+
unsandboxed: true,
|
|
19
|
+
docsURI: "https://kubohiroya.github.io/turbowarp-text-lines/",
|
|
20
|
+
color1: "#5B80A5",
|
|
21
|
+
blockIconURI: `data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 48 48\"><g fill=\"#4C97FF\"><circle cx=\"11\" cy=\"16\" r=\"2.6\"/><circle cx=\"11\" cy=\"24\" r=\"2.6\"/><circle cx=\"11\" cy=\"32\" r=\"2.6\"/></g><path d=\"M19 16h20M19 24h20M19 32h13\" fill=\"none\" stroke=\"#59C059\" stroke-width=\"3\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>")}`
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region node_modules/.pnpm/@kubohiroya+turbowarp-extension-data-editor@0.4.0_react@18.3.1/node_modules/@kubohiroya/turbowarp-extension-data-editor/dist/fixed-input-schema.js
|
|
25
|
+
var numberToken = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/u;
|
|
26
|
+
var invalidNumber = Object.freeze({
|
|
27
|
+
kind: "invalid",
|
|
28
|
+
code: "fixed-number-input-invalid"
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Parse a NEW numeric draft according to NP-finite-new-input-v1.
|
|
32
|
+
* Never apply this to opening/no-op raw values or use it as an owner validator.
|
|
33
|
+
* Keep the validated token so negative zero, precision and exponent spelling survive.
|
|
34
|
+
*/
|
|
35
|
+
function parseFixedNumberInput(input) {
|
|
36
|
+
if (typeof input === "number") {
|
|
37
|
+
if (!Number.isFinite(input)) return invalidNumber;
|
|
38
|
+
return Object.freeze({
|
|
39
|
+
kind: "valid",
|
|
40
|
+
token: Object.is(input, -0) ? "-0" : String(input),
|
|
41
|
+
value: input
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (typeof input !== "string") return invalidNumber;
|
|
45
|
+
const token = input.trim();
|
|
46
|
+
if (!numberToken.test(token)) return invalidNumber;
|
|
47
|
+
const value = Number(token);
|
|
48
|
+
return Number.isFinite(value) ? Object.freeze({
|
|
49
|
+
kind: "valid",
|
|
50
|
+
token,
|
|
51
|
+
value
|
|
52
|
+
}) : invalidNumber;
|
|
53
|
+
}
|
|
54
|
+
var block_editor_fixed_inputs_schema_default = {
|
|
55
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
56
|
+
$id: "https://kubohiroya.github.io/turbowarp-text-lines/schemas/block-editor-fixed-inputs.schema.json",
|
|
57
|
+
$defs: { "lineAt": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"properties": { "LINE": { "type": "number" } },
|
|
60
|
+
"required": ["LINE"],
|
|
61
|
+
"additionalProperties": true
|
|
62
|
+
} }
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/fixed-input-schema.ts
|
|
66
|
+
var repository$1 = "turbowarp-text-lines";
|
|
67
|
+
/** The owner JSON document is canonical; this selects a primitive field fragment. */
|
|
68
|
+
function fixedInputBundle(opcode, argument) {
|
|
69
|
+
const source = {
|
|
70
|
+
repository: repository$1,
|
|
71
|
+
path: "schemas/block-editor-fixed-inputs.schema.json",
|
|
72
|
+
symbol: `#/$defs/${opcode}/properties/${argument}`
|
|
73
|
+
};
|
|
74
|
+
const blocks = block_editor_fixed_inputs_schema_default.$defs;
|
|
75
|
+
return {
|
|
76
|
+
identity: {
|
|
77
|
+
ownerId: repository$1,
|
|
78
|
+
contractId: opcode,
|
|
79
|
+
revision: "fixed-inputs-v1",
|
|
80
|
+
variantId: argument
|
|
81
|
+
},
|
|
82
|
+
dialect: "2020-12",
|
|
83
|
+
root: {
|
|
84
|
+
retrievalUri: block_editor_fixed_inputs_schema_default.$id,
|
|
85
|
+
document: blocks[opcode].properties[argument],
|
|
86
|
+
artifact: {
|
|
87
|
+
role: "canonical-schema",
|
|
88
|
+
source
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
resources: [],
|
|
92
|
+
provenance: {
|
|
93
|
+
canonicalSources: [source, {
|
|
94
|
+
repository: repository$1,
|
|
95
|
+
path: "src/extension.ts",
|
|
96
|
+
symbol: opcode
|
|
97
|
+
}],
|
|
98
|
+
generatedFiles: [],
|
|
99
|
+
referenceSchemas: [],
|
|
100
|
+
generationSources: []
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/fixed-input-editors.ts
|
|
106
|
+
var extensionId = "kubohiroyatextlines";
|
|
107
|
+
var repository = "turbowarp-text-lines";
|
|
108
|
+
var fields = [{
|
|
109
|
+
"opcode": "lineAt",
|
|
110
|
+
"argument": "LINE",
|
|
111
|
+
"control": "number",
|
|
112
|
+
"choices": [],
|
|
113
|
+
"normalization": "identity",
|
|
114
|
+
"shape": "math_number.NUM",
|
|
115
|
+
"maxBytes": false
|
|
116
|
+
}];
|
|
117
|
+
function literalString(value) {
|
|
118
|
+
if (typeof value !== "string") throw new TypeError("Expected a string literal.");
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
/** Legacy nonempty finite aliases are projections; opening never creates a write. */
|
|
122
|
+
function existingFixedNumber(value) {
|
|
123
|
+
if (typeof value !== "string" && typeof value !== "number" || typeof value === "string" && value.trim() === "") throw new TypeError("Unavailable numeric projection.");
|
|
124
|
+
const number = Number(value);
|
|
125
|
+
if (!Number.isFinite(number)) throw new TypeError("Unavailable numeric projection.");
|
|
126
|
+
return number;
|
|
127
|
+
}
|
|
128
|
+
function normalizeChoice(field, raw) {
|
|
129
|
+
if (field.normalization === "lowercase") return raw.toLowerCase();
|
|
130
|
+
if (field.normalization === "method") return raw.trim().toUpperCase();
|
|
131
|
+
if (field.normalization === "trim") return raw.trim();
|
|
132
|
+
if (field.normalization === "parse-format") {
|
|
133
|
+
const lower = raw.trim().toLowerCase();
|
|
134
|
+
return lower === "json" ? "JSON" : lower === "yaml" ? "YAML" : lower === "auto" ? "auto" : raw;
|
|
135
|
+
}
|
|
136
|
+
return raw;
|
|
137
|
+
}
|
|
138
|
+
function binding(field) {
|
|
139
|
+
return {
|
|
140
|
+
argument: field.argument,
|
|
141
|
+
schemaBundle: fixedInputBundle(field.opcode, field.argument),
|
|
142
|
+
control: {
|
|
143
|
+
kind: field.control,
|
|
144
|
+
...field.control === "enum" ? { choices: field.choices.map((value) => ({ value })) } : {}
|
|
145
|
+
},
|
|
146
|
+
read(value) {
|
|
147
|
+
return field.control === "number" ? existingFixedNumber(value) : normalizeChoice(field, literalString(value));
|
|
148
|
+
},
|
|
149
|
+
encode(value) {
|
|
150
|
+
if (field.control === "number") {
|
|
151
|
+
const parsed = parseFixedNumberInput(value);
|
|
152
|
+
if (parsed.kind !== "valid") throw new TypeError("Invalid new numeric input.");
|
|
153
|
+
return parsed.token;
|
|
154
|
+
}
|
|
155
|
+
const raw = literalString(value), normalized = normalizeChoice(field, raw);
|
|
156
|
+
if (!field.choices.includes(normalized)) throw new TypeError("Unsupported fixed choice.");
|
|
157
|
+
return field.shape === "menu-shadow" || field.shape === "direct-field-dropdown" ? normalized : raw;
|
|
158
|
+
},
|
|
159
|
+
validateCandidate(value) {
|
|
160
|
+
try {
|
|
161
|
+
if (field.control === "number") {
|
|
162
|
+
const number = existingFixedNumber(value);
|
|
163
|
+
if (field.maxBytes && (!Number.isSafeInteger(Math.trunc(number)) || Math.trunc(number) < 1)) return [{ message: "Invalid named body size." }];
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
return field.choices.includes(normalizeChoice(field, literalString(value))) ? [] : [{ message: "Unsupported fixed choice." }];
|
|
167
|
+
} catch {
|
|
168
|
+
return [{ message: "Invalid fixed input." }];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var fixedInputEditors = [...new Set(fields.map((f) => f.opcode))].map((opcode) => ({
|
|
174
|
+
apiVersion: 1,
|
|
175
|
+
extensionId,
|
|
176
|
+
editorId: `${opcode}-fixed-inputs`,
|
|
177
|
+
opcodes: [`${extensionId}_${opcode}`],
|
|
178
|
+
contractId: `${repository}/${opcode}`,
|
|
179
|
+
contractRevision: "fixed-inputs-v1",
|
|
180
|
+
bindings: fields.filter((field) => field.opcode === opcode).map(binding),
|
|
181
|
+
validationContext: () => ({
|
|
182
|
+
consumerId: repository,
|
|
183
|
+
nowMs: 0,
|
|
184
|
+
settings: null
|
|
185
|
+
})
|
|
186
|
+
}));
|
|
187
|
+
/** Registration follows the advertised opcode membership and the optional host capability. */
|
|
188
|
+
function fixedInputRegistration(scratch) {
|
|
189
|
+
const host = scratch ?? {};
|
|
190
|
+
let active;
|
|
191
|
+
let membership = "";
|
|
192
|
+
const removers = [];
|
|
193
|
+
let stopped = false;
|
|
194
|
+
const clear = () => {
|
|
195
|
+
host.vm?.runtime?.off?.("RUNTIME_DISPOSED", shutdown);
|
|
196
|
+
for (const remove of removers.splice(0).reverse()) remove();
|
|
197
|
+
active = void 0;
|
|
198
|
+
membership = "";
|
|
199
|
+
};
|
|
200
|
+
const shutdown = () => {
|
|
201
|
+
stopped = true;
|
|
202
|
+
clear();
|
|
203
|
+
};
|
|
204
|
+
return {
|
|
205
|
+
ensure(visibleOpcodes) {
|
|
206
|
+
const api = host.gui?.blockEditors;
|
|
207
|
+
const definitions = fixedInputEditors.filter((definition) => definition.opcodes.every((opcode) => visibleOpcodes.includes(opcode)));
|
|
208
|
+
const key = definitions.map((definition) => definition.editorId).join(",");
|
|
209
|
+
if (stopped || api === active && membership === key) return;
|
|
210
|
+
clear();
|
|
211
|
+
if (api?.apiVersion !== 1 || typeof api.registerFixedInputEditor !== "function" || !definitions.length) return;
|
|
212
|
+
try {
|
|
213
|
+
for (const definition of definitions) {
|
|
214
|
+
const remove = api.registerFixedInputEditor.call(api, definition);
|
|
215
|
+
if (typeof remove !== "function") throw new TypeError("Invalid fixed input cleanup.");
|
|
216
|
+
removers.push(remove);
|
|
217
|
+
}
|
|
218
|
+
active = api;
|
|
219
|
+
membership = key;
|
|
220
|
+
host.vm?.runtime?.on?.("RUNTIME_DISPOSED", shutdown);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
clear();
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
dispose: shutdown
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
var block_definitions_default = {
|
|
230
|
+
extensionName: "Text Lines",
|
|
231
|
+
blocks: [
|
|
232
|
+
{
|
|
233
|
+
"opcode": "lineCount",
|
|
234
|
+
"blockType": "REPORTER",
|
|
235
|
+
"text": "number of lines in [TEXT]",
|
|
236
|
+
"description": "Returns the number of lines in the supplied text.",
|
|
237
|
+
"arguments": { "TEXT": {
|
|
238
|
+
"type": "STRING",
|
|
239
|
+
"defaultValue": "first line\nsecond line"
|
|
240
|
+
} }
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"opcode": "lineAt",
|
|
244
|
+
"blockType": "REPORTER",
|
|
245
|
+
"text": "line [LINE] of [TEXT]",
|
|
246
|
+
"description": "Returns one line using a one-based line number. Invalid line numbers return an empty string.",
|
|
247
|
+
"arguments": {
|
|
248
|
+
"TEXT": {
|
|
249
|
+
"type": "STRING",
|
|
250
|
+
"defaultValue": "first line\nsecond line"
|
|
251
|
+
},
|
|
252
|
+
"LINE": {
|
|
253
|
+
"type": "NUMBER",
|
|
254
|
+
"defaultValue": 1
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
"opcode": "writeLinesToList",
|
|
260
|
+
"blockType": "COMMAND",
|
|
261
|
+
"text": "put lines of [TEXT] into list [LIST]",
|
|
262
|
+
"description": "Replaces the contents of the named Scratch list with the lines of the supplied text.",
|
|
263
|
+
"arguments": {
|
|
264
|
+
"TEXT": {
|
|
265
|
+
"type": "STRING",
|
|
266
|
+
"defaultValue": "first line\nsecond line"
|
|
267
|
+
},
|
|
268
|
+
"LIST": {
|
|
269
|
+
"type": "STRING",
|
|
270
|
+
"menu": "LIST_MENU"
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
};
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
|
|
278
|
+
function _typeof(o) {
|
|
279
|
+
"@babel/helpers - typeof";
|
|
280
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
281
|
+
return typeof o;
|
|
282
|
+
} : function(o) {
|
|
283
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
284
|
+
}, _typeof(o);
|
|
285
|
+
}
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
|
|
288
|
+
function toPrimitive(t, r) {
|
|
289
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
290
|
+
var e = t[Symbol.toPrimitive];
|
|
291
|
+
if (void 0 !== e) {
|
|
292
|
+
var i = e.call(t, r || "default");
|
|
293
|
+
if ("object" != _typeof(i)) return i;
|
|
294
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
295
|
+
}
|
|
296
|
+
return ("string" === r ? String : Number)(t);
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
|
|
300
|
+
function toPropertyKey(t) {
|
|
301
|
+
var i = toPrimitive(t, "string");
|
|
302
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
|
|
306
|
+
function _defineProperty(e, r, t) {
|
|
307
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
308
|
+
value: t,
|
|
309
|
+
enumerable: !0,
|
|
310
|
+
configurable: !0,
|
|
311
|
+
writable: !0
|
|
312
|
+
}) : e[r] = t, e;
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/extension.ts
|
|
316
|
+
var BLOCK_ICON_URI = extensionConfig.blockIconURI;
|
|
317
|
+
var blockDefinitions = block_definitions_default.blocks;
|
|
318
|
+
var TextLinesExtension = class {
|
|
319
|
+
constructor() {
|
|
320
|
+
_defineProperty(this, "fixedInputs", fixedInputRegistration(typeof Scratch === "undefined" ? void 0 : Scratch));
|
|
321
|
+
}
|
|
322
|
+
dispose() {
|
|
323
|
+
this.fixedInputs.dispose();
|
|
324
|
+
}
|
|
325
|
+
getInfo() {
|
|
326
|
+
this.fixedInputs.ensure(blockDefinitions.map((block) => `${extensionConfig.id}_${block.opcode}`));
|
|
327
|
+
const translate = Scratch.translate;
|
|
328
|
+
return {
|
|
329
|
+
id: extensionConfig.id,
|
|
330
|
+
name: translate(block_definitions_default.extensionName),
|
|
331
|
+
docsURI: extensionConfig.docsURI,
|
|
332
|
+
blockIconURI: BLOCK_ICON_URI,
|
|
333
|
+
color1: extensionConfig.color1,
|
|
334
|
+
blocks: blockDefinitions.map((block) => this.toScratchBlock(block)),
|
|
335
|
+
menus: { LIST_MENU: {
|
|
336
|
+
acceptReporters: true,
|
|
337
|
+
items: "getLists"
|
|
338
|
+
} }
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
getLists() {
|
|
342
|
+
const stage = Scratch.vm.runtime.getTargetForStage();
|
|
343
|
+
const editingTarget = Scratch.vm.editingTarget;
|
|
344
|
+
const lists = [...stage ? Object.values(stage.variables) : [], ...editingTarget && editingTarget !== stage ? Object.values(editingTarget.variables) : []].filter((variable) => variable.type === "list");
|
|
345
|
+
if (lists.length === 0) return [""];
|
|
346
|
+
return lists.map((list) => ({
|
|
347
|
+
text: list.name,
|
|
348
|
+
value: list.id
|
|
349
|
+
}));
|
|
350
|
+
}
|
|
351
|
+
lineCount(args) {
|
|
352
|
+
return splitLines(Scratch.Cast.toString(args.TEXT)).length;
|
|
353
|
+
}
|
|
354
|
+
lineAt(args) {
|
|
355
|
+
const lines = splitLines(Scratch.Cast.toString(args.TEXT));
|
|
356
|
+
const line = Math.trunc(Scratch.Cast.toNumber(args.LINE));
|
|
357
|
+
if (!Number.isFinite(line) || line < 1 || line > lines.length) return "";
|
|
358
|
+
return lines[line - 1] ?? "";
|
|
359
|
+
}
|
|
360
|
+
writeLinesToList(args, util) {
|
|
361
|
+
const listIdOrName = Scratch.Cast.toString(args.LIST);
|
|
362
|
+
const stage = Scratch.vm.runtime.getTargetForStage();
|
|
363
|
+
const variable = util.target.lookupVariableById(listIdOrName) ?? stage?.lookupVariableById(listIdOrName) ?? util.target.lookupVariableByNameAndType(listIdOrName, "list") ?? stage?.lookupVariableByNameAndType(listIdOrName, "list");
|
|
364
|
+
if (!variable || variable.type !== "list") throw new Error(`List not found: ${listIdOrName}`);
|
|
365
|
+
variable.value = splitLines(Scratch.Cast.toString(args.TEXT));
|
|
366
|
+
variable._monitorUpToDate = false;
|
|
367
|
+
}
|
|
368
|
+
toScratchBlock(block) {
|
|
369
|
+
return {
|
|
370
|
+
opcode: block.opcode,
|
|
371
|
+
blockType: Scratch.BlockType[block.blockType],
|
|
372
|
+
text: Scratch.translate(block.text),
|
|
373
|
+
arguments: Object.fromEntries(Object.entries(block.arguments).map(([name, argument]) => [name, Object.fromEntries(Object.entries({
|
|
374
|
+
type: Scratch.ArgumentType[argument.type],
|
|
375
|
+
defaultValue: argument.defaultValue,
|
|
376
|
+
menu: argument.menu
|
|
377
|
+
}).filter(([, value]) => value !== void 0))]))
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
function splitLines(text) {
|
|
382
|
+
return text.split(/\r\n|\n|\r/);
|
|
383
|
+
}
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/index.ts
|
|
386
|
+
if (extensionConfig.unsandboxed && !Scratch.extensions.unsandboxed) throw new Error(`${extensionConfig.name} must run unsandboxed to write to Scratch lists.`);
|
|
387
|
+
Scratch.extensions.register(new TextLinesExtension());
|
|
388
|
+
//#endregion
|
|
373
389
|
|
|
374
390
|
})(Scratch);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubohiroya/turbowarp-text-lines",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Use multiline text in TurboWarp projects with line counting, lookup, and list-writing blocks.",
|
|
5
5
|
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
6
|
"license": "MPL-2.0",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"type": "module",
|
|
24
24
|
"files": [
|
|
25
|
+
"assets/",
|
|
25
26
|
"dist/",
|
|
26
27
|
"README.md",
|
|
27
28
|
"LICENSE",
|
|
@@ -32,9 +33,9 @@
|
|
|
32
33
|
"access": "public",
|
|
33
34
|
"registry": "https://registry.npmjs.org/"
|
|
34
35
|
},
|
|
35
|
-
"packageManager": "pnpm@11.
|
|
36
|
+
"packageManager": "pnpm@11.28.8",
|
|
36
37
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
38
|
+
"node": ">=24"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"dev": "vite build --watch",
|
|
@@ -49,16 +50,16 @@
|
|
|
49
50
|
"check": "pnpm run typecheck && pnpm run test && pnpm run build && pnpm run docs:check && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@kubohiroya/vite-plugin-turbowarp-extension": "0.
|
|
53
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "^0.9.0",
|
|
53
54
|
"@types/node": "^22.20.1",
|
|
54
55
|
"typescript": "^5.9.3",
|
|
55
56
|
"vite": "^8.2.2",
|
|
56
57
|
"vitest": "^4.1.10",
|
|
57
|
-
"@kubohiroya/turbowarp-extension-data-editor": "0.
|
|
58
|
+
"@kubohiroya/turbowarp-extension-data-editor": "^0.4.0"
|
|
58
59
|
},
|
|
59
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "86365d0f44d92bcf6ad828be8d165e4852abd7f4",
|
|
60
61
|
"x-turbowarp-source": {
|
|
61
|
-
"revision": "
|
|
62
|
+
"revision": "86365d0f44d92bcf6ad828be8d165e4852abd7f4",
|
|
62
63
|
"revisionRole": "base-commit",
|
|
63
64
|
"sourceState": "local-release-overlay"
|
|
64
65
|
}
|