scratchblocks-plus 1.0.1 → 1.1.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/LICENSE +1 -1
- package/README.md +54 -28
- package/build/scratchblocks-plus.min.es.js +3 -3
- package/build/scratchblocks-plus.min.es.js.map +1 -1
- package/build/scratchblocks-plus.min.js +3 -3
- package/build/scratchblocks-plus.min.js.map +1 -1
- package/build/translations-all-es.js +2 -2
- package/build/translations-all.js +2 -2
- package/build/translations-es.js +2 -2
- package/build/translations.js +2 -2
- package/node-ssr.js +81 -0
- package/package.json +26 -5
- package/readme-assets/images/dark.png +0 -0
- package/readme-assets/images/light.png +0 -0
- package/scratch3/blocks.js +31 -3
- package/scratch3/style.css.js +6 -2
- package/syntax/model.js +10 -5
- package/syntax/syntax.js +6 -2
- package/build/translations-all-es.js.map +0 -1
- package/build/translations-all.js.map +0 -1
- package/build/translations-es.js.map +0 -1
- package/build/translations.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
scratchblocks is Copyright © 2013–2021, Tim Radvan
|
|
2
|
-
scratchblocks-plus is Copyright © 2025, Lu Yifei
|
|
2
|
+
scratchblocks-plus is Copyright © 2025–2026, Lu Yifei
|
|
3
3
|
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
5
|
this software and associated documentation files (the "Software"), to deal in
|
package/README.md
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
Make pictures of Scratch blocks from text.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="/readme-assets/images/dark.png">
|
|
5
|
+
<img alt="Screenshot" src="/readme-assets/images/light.png">
|
|
6
|
+
</picture>
|
|
5
7
|
|
|
6
|
-
**[Try it out!](https://
|
|
7
|
-
|
|
8
|
+
**[Try it out!](https://luyifei2011.github.io/scratchblocks-plus/)**
|
|
9
|
+
|
|
10
|
+
[Documentation](https://luyifei2011.github.io/scratchblocks-plus-docs/)
|
|
8
11
|
|
|
9
12
|
---
|
|
10
13
|
|
|
11
14
|
**scratchblocks-plus** is a fork of **scratchblocks**, and adds the following features:
|
|
12
|
-
|
|
13
|
-
-
|
|
15
|
+
|
|
16
|
+
- matrix support
|
|
17
|
+
- [try it out!](https://luyifei2011.github.io/scratchblocks-plus/#?style=scratch3&script=display%20(%7B01010%2C%0A%20%20%20%20%20%20%20%20%20%2010101%2C%0A%20%20%20%20%20%20%20%20%20%2010001%2C%0A%20%20%20%20%20%20%20%20%20%2001010%2C%0A%20%20%20%20%20%20%20%20%20%2000100%7D%20v))
|
|
18
|
+
- issue: [scratchblocks#509](https://github.com/scratchblocks/scratchblocks/issues/509)
|
|
19
|
+
- PR: [scratchblocks#573](https://github.com/scratchblocks/scratchblocks/pull/573)
|
|
14
20
|
- block highlight
|
|
21
|
+
- [example 1](https://luyifei2011.github.io/scratchblocks-plus/example/text-highlight.html)
|
|
22
|
+
- [example 2](https://luyifei2011.github.io/scratchblocks-plus/example/speech-highlight.html)
|
|
23
|
+
- dropdown menu translate
|
|
24
|
+
- [try it out!](https://luyifei2011.github.io/scratchblocks-plus/translator/#?lang=zh_cn&script=go%20to%20(mouse-pointer%20v))
|
|
25
|
+
- issue: [scratchblocks#324](https://github.com/scratchblocks/scratchblocks/issues/324)
|
|
26
|
+
- PR: [scratchblocks#556](https://github.com/scratchblocks/scratchblocks/pull/556)
|
|
27
|
+
- server-side rendering
|
|
28
|
+
- issue: [scratchblocks#402](https://github.com/scratchblocks/scratchblocks/issues/402)
|
|
29
|
+
- PR: [scratchblocks#589](https://github.com/scratchblocks/scratchblocks/pull/589)
|
|
30
|
+
- basic TypeScript support
|
|
31
|
+
- and more!
|
|
15
32
|
|
|
16
33
|
**scratchblocks-plus** is compatible with **scratchblocks**, so you can use it as a drop-in replacement.
|
|
17
34
|
|
|
@@ -44,7 +61,7 @@ It uses the [pandoc_scratchblocks](https://github.com/CodeClub/pandoc_scratchblo
|
|
|
44
61
|
This would probably be a good way to write a Scratch book.
|
|
45
62
|
-->
|
|
46
63
|
|
|
47
|
-
|
|
64
|
+
## React
|
|
48
65
|
|
|
49
66
|
Use the [scratchblocks-plus-react](https://github.com/LuYifei2011/scratchblocks-plus-react) package to render scratchblocks in React.
|
|
50
67
|
|
|
@@ -53,15 +70,16 @@ Use the [scratchblocks-plus-react](https://github.com/LuYifei2011/scratchblocks-
|
|
|
53
70
|
You'll need to include a copy of the scratchblocks-plus JS file on your webpage.
|
|
54
71
|
There are a few ways of getting one:
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
- Download it from the <https://github.com/LuYifei2011/scratchblocks-plus/releases> page
|
|
57
74
|
<!--* If you have a fancy JS build system, you might like to include the `scratchblocks-plus` package from NPM-->
|
|
58
|
-
|
|
75
|
+
- You could clone this repository and build it yourself using Node 16.14.0+ (`npm run build`).
|
|
59
76
|
|
|
60
77
|
```html
|
|
61
78
|
<script src="scratchblocks-min.js"></script>
|
|
62
79
|
```
|
|
63
80
|
|
|
64
81
|
The convention is to write scratchblocks inside `pre` tags with the class `blocks`:
|
|
82
|
+
|
|
65
83
|
```html
|
|
66
84
|
<pre class="blocks">
|
|
67
85
|
when flag clicked
|
|
@@ -71,6 +89,7 @@ move (10) steps
|
|
|
71
89
|
|
|
72
90
|
You then need to call `scratchblocks.renderMatching` after the page has loaded.
|
|
73
91
|
Make sure this appears at the end of the page (just before the closing `</body>` tag):
|
|
92
|
+
|
|
74
93
|
```js
|
|
75
94
|
<script>
|
|
76
95
|
scratchblocks.renderMatching('pre.blocks', {
|
|
@@ -80,6 +99,7 @@ scratchblocks.renderMatching('pre.blocks', {
|
|
|
80
99
|
});
|
|
81
100
|
</script>
|
|
82
101
|
```
|
|
102
|
+
|
|
83
103
|
The `renderMatching()` function takes a CSS-style selector for the elements that contain scratchblocks code: we use `pre.blocks` to target `pre` tags with the class `blocks`.
|
|
84
104
|
|
|
85
105
|
The `style` option controls how the blocks appear, either the Scratch 2 or Scratch 3 style is supported.
|
|
@@ -87,11 +107,13 @@ The `style` option controls how the blocks appear, either the Scratch 2 or Scrat
|
|
|
87
107
|
### Inline blocks
|
|
88
108
|
|
|
89
109
|
You might also want to use blocks "inline", inside a paragraph:
|
|
110
|
+
|
|
90
111
|
```html
|
|
91
112
|
I'm rather fond of the <code class="b">stamp</code> block in Scratch.
|
|
92
113
|
```
|
|
93
114
|
|
|
94
115
|
To allow this, make a second call to `renderMatching` using the `inline` argument.
|
|
116
|
+
|
|
95
117
|
```js
|
|
96
118
|
<script>
|
|
97
119
|
scratchblocks.renderMatching("pre.blocks", ...)
|
|
@@ -102,6 +124,7 @@ scratchblocks.renderMatching("code.b", {
|
|
|
102
124
|
});
|
|
103
125
|
</script>
|
|
104
126
|
```
|
|
127
|
+
|
|
105
128
|
This time we use `code.b` to target `code` blocks with the class `b`.
|
|
106
129
|
|
|
107
130
|
### Translations
|
|
@@ -109,22 +132,24 @@ This time we use `code.b` to target `code` blocks with the class `b`.
|
|
|
109
132
|
If you want to use languages other than English, you'll need to include a second JS file that contains translations.
|
|
110
133
|
The releases page includes two options; you can pick one:
|
|
111
134
|
|
|
112
|
-
|
|
113
|
-
|
|
135
|
+
- `translations.js` includes a limited set of languages, as seen on the Scratch Forums
|
|
136
|
+
- `translations-all.js` includes every language that Scratch supports.
|
|
114
137
|
|
|
115
138
|
The translations files are hundreds of kilobytes in size, so to keep your page bundle size down you might like to build your own file with just the languages you need.
|
|
116
139
|
|
|
117
140
|
For example, a translations file that just loads the German language (ISO code `de`) would look something like this:
|
|
141
|
+
|
|
118
142
|
```js
|
|
119
|
-
|
|
143
|
+
scratchblocks.loadLanguages({
|
|
120
144
|
de: <contents of locales/de.json>
|
|
121
145
|
})
|
|
122
146
|
```
|
|
123
147
|
|
|
124
148
|
If you're using a JavaScript bundler you should be able to build your own translations file by calling `require()` with the path to the locale JSON file.
|
|
125
149
|
This requires your bundler to allow importing JSON files as JavaScript.
|
|
150
|
+
|
|
126
151
|
```js
|
|
127
|
-
|
|
152
|
+
scratchblocks.loadLanguages({
|
|
128
153
|
de: require('scratchblocks/locales/de.json'),
|
|
129
154
|
})
|
|
130
155
|
```
|
|
@@ -143,7 +168,8 @@ scratchblocks.renderMatching('pre.blocks');
|
|
|
143
168
|
```
|
|
144
169
|
|
|
145
170
|
## ESM Support
|
|
146
|
-
|
|
171
|
+
|
|
172
|
+
scratchblocks-plus can be properly loaded as an ESM module. The ESM version, instead of defining `window.scratchblocks`, default-exports the `scratchblocks` object. Similarly, the JavaScript translation files default-exports a function to load the translations.
|
|
147
173
|
|
|
148
174
|
```js
|
|
149
175
|
import scratchblocks from "./scratchblocks-plus-es-min.js";
|
|
@@ -156,6 +182,7 @@ loadTranslations(scratchblocks);
|
|
|
156
182
|
# Languages
|
|
157
183
|
|
|
158
184
|
To update the translations:
|
|
185
|
+
|
|
159
186
|
```sh
|
|
160
187
|
npm upgrade scratch-l10n
|
|
161
188
|
npm run locales
|
|
@@ -170,28 +197,27 @@ I'd be happy to accept pull requests for those! You'll need to rebuild the trans
|
|
|
170
197
|
|
|
171
198
|
This should set you up and start a http-server for development:
|
|
172
199
|
|
|
173
|
-
```
|
|
200
|
+
```sh
|
|
174
201
|
npm install
|
|
175
202
|
npm start
|
|
176
203
|
```
|
|
177
204
|
|
|
178
205
|
Then open <http://localhost:8000/> :-)
|
|
179
206
|
|
|
180
|
-
For more details, see [`CONTRIBUTING.md`](https://github.com/LuYifei2011/scratchblocks-plus/blob/
|
|
181
|
-
|
|
207
|
+
For more details, see [`CONTRIBUTING.md`](https://github.com/LuYifei2011/scratchblocks-plus/blob/main/.github/CONTRIBUTING.md).
|
|
182
208
|
|
|
183
209
|
# Credits
|
|
184
210
|
|
|
185
211
|
Many, many thanks to the [contributors](https://github.com/LuYifei2011/scratchblocks-plus/graphs/contributors)!
|
|
186
212
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
213
|
+
- Maintained by [LuYifei2011](https://github.com/LuYifei2011)
|
|
214
|
+
- This is a fork of [scratchblocks](https://github.com/scratchblocks/scratchblocks), so all the credit there still applies here.
|
|
215
|
+
- Original scratchblocks library by [tjvr](https://github.com/tjvr)
|
|
216
|
+
- Original scratchblocks library maintained by tjvr and [apple502j](https://github.com/apple502j)
|
|
217
|
+
- Icons derived from [Scratch Blocks](https://github.com/scratchfoundation/scratch-blocks) (Apache License 2.0)
|
|
218
|
+
- Scratch 2 SVG proof-of-concept, shapes & filters by [as-com](https://github.com/as-com)
|
|
219
|
+
- Anna helped with a formula, and pointed out that tjvr can't read graphs
|
|
220
|
+
- JSO designed the syntax and wrote the original [Block Plugin](https://en.scratch-wiki.info/wiki/Block_Plugin_\(1.4\))
|
|
221
|
+
- Help with translation code from [joooni](https://scratch.mit.edu/users/joooni/)
|
|
222
|
+
- Block translations from the [scratch-l10n repository](https://github.com/scratchfoundation/scratch-l10n/)
|
|
223
|
+
- Ported to node by [arve0](https://github.com/arve0)
|