scratchblocks-plus 1.0.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 +19 -0
- package/README.md +193 -0
- package/browser.es.js +8 -0
- package/browser.js +8 -0
- package/build/scratchblocks-plus.min.es.js +12 -0
- package/build/scratchblocks-plus.min.es.js.map +1 -0
- package/build/scratchblocks-plus.min.js +12 -0
- package/build/scratchblocks-plus.min.js.map +1 -0
- package/build/translations-all-es.js +11 -0
- package/build/translations-all-es.js.map +1 -0
- package/build/translations-all.js +11 -0
- package/build/translations-all.js.map +1 -0
- package/build/translations-es.js +11 -0
- package/build/translations-es.js.map +1 -0
- package/build/translations.js +11 -0
- package/build/translations.js.map +1 -0
- package/index.d.ts +297 -0
- package/index.js +229 -0
- package/locales/ab.json +1630 -0
- package/locales/af.json +1630 -0
- package/locales/all.d.ts +108 -0
- package/locales/all.js +161 -0
- package/locales/am.json +1925 -0
- package/locales/an.json +1630 -0
- package/locales/ar.json +1924 -0
- package/locales/ast.json +1630 -0
- package/locales/az.json +1925 -0
- package/locales/be.json +1630 -0
- package/locales/bg.json +1924 -0
- package/locales/bn.json +1630 -0
- package/locales/ca.json +1930 -0
- package/locales/ckb.json +1630 -0
- package/locales/cs.json +1930 -0
- package/locales/cy.json +1929 -0
- package/locales/da.json +1924 -0
- package/locales/de.json +1929 -0
- package/locales/el.json +1931 -0
- package/locales/eo.json +1630 -0
- package/locales/es-419.json +1924 -0
- package/locales/es.json +1929 -0
- package/locales/et.json +1924 -0
- package/locales/eu.json +1924 -0
- package/locales/fa.json +1929 -0
- package/locales/fi.json +1924 -0
- package/locales/fil.json +1631 -0
- package/locales/forums.js +37 -0
- package/locales/fr.json +1929 -0
- package/locales/fy.json +1630 -0
- package/locales/ga.json +1924 -0
- package/locales/gd.json +1929 -0
- package/locales/gl.json +1924 -0
- package/locales/ha.json +1630 -0
- package/locales/he.json +1929 -0
- package/locales/hi.json +1635 -0
- package/locales/hr.json +1929 -0
- package/locales/ht.json +1630 -0
- package/locales/hu.json +1930 -0
- package/locales/hy.json +1630 -0
- package/locales/id.json +1929 -0
- package/locales/is.json +1924 -0
- package/locales/it.json +1929 -0
- package/locales/ja-Hira.json +1637 -0
- package/locales/ja.json +1931 -0
- package/locales/ka.json +1630 -0
- package/locales/kk.json +1632 -0
- package/locales/km.json +1630 -0
- package/locales/ko.json +1924 -0
- package/locales/ku.json +1632 -0
- package/locales/lt.json +1924 -0
- package/locales/lv.json +1924 -0
- package/locales/mi.json +1924 -0
- package/locales/mn.json +1631 -0
- package/locales/nb.json +1929 -0
- package/locales/nl.json +1929 -0
- package/locales/nn.json +1630 -0
- package/locales/nso.json +1630 -0
- package/locales/oc.json +1630 -0
- package/locales/or.json +1631 -0
- package/locales/pl.json +1929 -0
- package/locales/pt-br.json +1924 -0
- package/locales/pt.json +1929 -0
- package/locales/qu.json +1630 -0
- package/locales/rap.json +1632 -0
- package/locales/ro.json +1929 -0
- package/locales/ru.json +1929 -0
- package/locales/sk.json +1924 -0
- package/locales/sl.json +1929 -0
- package/locales/sr.json +1924 -0
- package/locales/sv.json +1924 -0
- package/locales/sw.json +1630 -0
- package/locales/th.json +1924 -0
- package/locales/tn.json +1630 -0
- package/locales/tr.json +1932 -0
- package/locales/uk.json +1924 -0
- package/locales/uz.json +1631 -0
- package/locales/vi.json +1925 -0
- package/locales/xh.json +1630 -0
- package/locales/zh-cn.json +1930 -0
- package/locales/zh-tw.json +1930 -0
- package/locales/zu.json +1918 -0
- package/package.json +81 -0
- package/scratch2/blocks.js +1000 -0
- package/scratch2/draw.js +452 -0
- package/scratch2/filter.js +78 -0
- package/scratch2/index.js +12 -0
- package/scratch2/style.css.js +148 -0
- package/scratch2/style.js +214 -0
- package/scratch3/blocks.js +1134 -0
- package/scratch3/draw.js +334 -0
- package/scratch3/index.js +12 -0
- package/scratch3/style.css.js +280 -0
- package/scratch3/style.js +877 -0
- package/syntax/blocks.js +921 -0
- package/syntax/commands.js +1755 -0
- package/syntax/dropdowns.js +688 -0
- package/syntax/extensions.js +34 -0
- package/syntax/index.js +17 -0
- package/syntax/model.js +566 -0
- package/syntax/syntax.js +1091 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
scratchblocks is Copyright © 2013–2021, Tim Radvan
|
|
2
|
+
scratchblocks-plus is Copyright © 2025, Lu Yifei
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
17
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Make pictures of Scratch blocks from text.
|
|
2
|
+
|
|
3
|
+
<!--
|
|
4
|
+
[](https://scratchblocks.github.io/#when%20flag%20clicked%0Aclear%0Aforever%0Apen%20down%0Aif%20%3C%3Cmouse%20down%3F%3E%20and%20%3Ctouching%20%5Bmouse-pointer%20v%5D%3F%3E%3E%20then%0Aswitch%20costume%20to%20%5Bbutton%20v%5D%0Aelse%0Aadd%20(x%20position)%20to%20%5Blist%20v%5D%0Aend%0Amove%20(foo)%20steps%0Aturn%20ccw%20(9)%20degrees)
|
|
5
|
+
|
|
6
|
+
**[Try it out!](https://scratchblocks.github.io/)**
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
**scratchblocks-plus** is a fork of **scratchblocks**, and adds the following features:
|
|
12
|
+
- basic TypeScript support
|
|
13
|
+
- Matrix support (issue: [scratchblocks#509](https://github.com/scratchblocks/scratchblocks/issues/509), PR: [scratchblocks#573](https://github.com/scratchblocks/scratchblocks/pull/573))
|
|
14
|
+
- block highlight
|
|
15
|
+
|
|
16
|
+
**scratchblocks-plus** is compatible with **scratchblocks**, so you can use it as a drop-in replacement.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
**scratchblocks-plus** is used to write Scratch scripts:
|
|
21
|
+
|
|
22
|
+
It's MIT licensed, so you can use it in your projects.
|
|
23
|
+
|
|
24
|
+
For the full guide to the syntax, see [the wiki](https://en.scratch-wiki.info/wiki/Block_Plugin/Syntax).
|
|
25
|
+
|
|
26
|
+
# Usage
|
|
27
|
+
|
|
28
|
+
<!--
|
|
29
|
+
## MediaWiki
|
|
30
|
+
|
|
31
|
+
Use [the MediaWiki plugin](https://github.com/InternationalScratchWiki/mw-ScratchBlocks4).
|
|
32
|
+
(This is what the [Scratch Wiki](https://en.scratch-wiki.info/wiki/Block_Plugin) uses.)
|
|
33
|
+
|
|
34
|
+
## WordPress
|
|
35
|
+
|
|
36
|
+
I found [a WordPress plugin](https://github.com/tkc49/scratchblocks-for-wp).
|
|
37
|
+
It might work for you; I haven't tried it.
|
|
38
|
+
|
|
39
|
+
## Pandoc
|
|
40
|
+
|
|
41
|
+
Code Club use their own [lesson_format](https://github.com/CodeClub/lesson_format) tool to generate the PDF versions of their project guides.
|
|
42
|
+
It uses the [pandoc_scratchblocks](https://github.com/CodeClub/pandoc_scratchblocks) plugin they wrote to make pictures of Scratch scripts.
|
|
43
|
+
|
|
44
|
+
This would probably be a good way to write a Scratch book.
|
|
45
|
+
-->
|
|
46
|
+
|
|
47
|
+
## HTML
|
|
48
|
+
|
|
49
|
+
You'll need to include a copy of the scratchblocks-plus JS file on your webpage.
|
|
50
|
+
There are a few ways of getting one:
|
|
51
|
+
|
|
52
|
+
* Download it from the <https://github.com/LuYifei2011/scratchblocks-plus/releases> page
|
|
53
|
+
<!--* If you have a fancy JS build system, you might like to include the `scratchblocks-plus` package from NPM-->
|
|
54
|
+
* You could clone this repository and build it yourself using Node 16.14.0+ (`npm run build`).
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<script src="scratchblocks-min.js"></script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The convention is to write scratchblocks inside `pre` tags with the class `blocks`:
|
|
61
|
+
```html
|
|
62
|
+
<pre class="blocks">
|
|
63
|
+
when flag clicked
|
|
64
|
+
move (10) steps
|
|
65
|
+
</pre>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
You then need to call `scratchblocks.renderMatching` after the page has loaded.
|
|
69
|
+
Make sure this appears at the end of the page (just before the closing `</body>` tag):
|
|
70
|
+
```js
|
|
71
|
+
<script>
|
|
72
|
+
scratchblocks.renderMatching('pre.blocks', {
|
|
73
|
+
style: 'scratch3', // Optional, defaults to 'scratch2'.
|
|
74
|
+
languages: ['en', 'de'], // Optional, defaults to ['en'].
|
|
75
|
+
scale: 1, // Optional, defaults to 1
|
|
76
|
+
});
|
|
77
|
+
</script>
|
|
78
|
+
```
|
|
79
|
+
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`.
|
|
80
|
+
|
|
81
|
+
The `style` option controls how the blocks appear, either the Scratch 2 or Scratch 3 style is supported.
|
|
82
|
+
|
|
83
|
+
### Inline blocks
|
|
84
|
+
|
|
85
|
+
You might also want to use blocks "inline", inside a paragraph:
|
|
86
|
+
```html
|
|
87
|
+
I'm rather fond of the <code class="b">stamp</code> block in Scratch.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
To allow this, make a second call to `renderMatching` using the `inline` argument.
|
|
91
|
+
```js
|
|
92
|
+
<script>
|
|
93
|
+
scratchblocks.renderMatching("pre.blocks", ...)
|
|
94
|
+
|
|
95
|
+
scratchblocks.renderMatching("code.b", {
|
|
96
|
+
inline: true,
|
|
97
|
+
// Repeat `style` and `languages` options here.
|
|
98
|
+
});
|
|
99
|
+
</script>
|
|
100
|
+
```
|
|
101
|
+
This time we use `code.b` to target `code` blocks with the class `b`.
|
|
102
|
+
|
|
103
|
+
### Translations
|
|
104
|
+
|
|
105
|
+
If you want to use languages other than English, you'll need to include a second JS file that contains translations.
|
|
106
|
+
The releases page includes two options; you can pick one:
|
|
107
|
+
|
|
108
|
+
* `translations.js` includes a limited set of languages, as seen on the Scratch Forums
|
|
109
|
+
* `translations-all.js` includes every language that Scratch supports.
|
|
110
|
+
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
For example, a translations file that just loads the German language (ISO code `de`) would look something like this:
|
|
114
|
+
```js
|
|
115
|
+
window.scratchblocks.loadLanguages({
|
|
116
|
+
de: <contents of locales/de.json>
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
This requires your bundler to allow importing JSON files as JavaScript.
|
|
122
|
+
```js
|
|
123
|
+
window.scratchblocks.loadLanguages({
|
|
124
|
+
de: require('scratchblocks/locales/de.json'),
|
|
125
|
+
})
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## NPM
|
|
129
|
+
|
|
130
|
+
The `scratchblocks-plus` package is published on NPM, and you can use it with browserify and other bundlers, if you're into that sort of thing.
|
|
131
|
+
|
|
132
|
+
Once you've got browserify set up to build a client-side bundle from your app
|
|
133
|
+
code, you can just add `scratchblocks-plus` to your dependencies, and everything
|
|
134
|
+
should Just Work™.
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
var scratchblocks = require('scratchblocks-plus');
|
|
138
|
+
scratchblocks.renderMatching('pre.blocks');
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## ESM Support
|
|
142
|
+
Since version 3.6.0, 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.
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
import scratchblocks from "./scratchblocks-plus-es-min.js";
|
|
146
|
+
import loadTranslations from "./translations-all-es.js";
|
|
147
|
+
loadTranslations(scratchblocks);
|
|
148
|
+
|
|
149
|
+
// window.scratchblocks is NOT available!
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
# Languages
|
|
153
|
+
|
|
154
|
+
To update the translations:
|
|
155
|
+
```sh
|
|
156
|
+
npm upgrade scratch-l10n
|
|
157
|
+
npm run locales
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Adding a language
|
|
161
|
+
|
|
162
|
+
Each language **requires** some [additional words](https://github.com/LuYifei2011/scratchblocks-plus/blob/master/locales-src/extra_aliases.js) which aren't in Scratch itself (mainly the words used for the flag and arrow images).
|
|
163
|
+
I'd be happy to accept pull requests for those! You'll need to rebuild the translations with `npm run locales` after editing the aliases.
|
|
164
|
+
|
|
165
|
+
# Development
|
|
166
|
+
|
|
167
|
+
This should set you up and start a http-server for development:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
npm install
|
|
171
|
+
npm start
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Then open <http://localhost:8000/> :-)
|
|
175
|
+
|
|
176
|
+
For more details, see [`CONTRIBUTING.md`](https://github.com/LuYifei2011/scratchblocks-plus/blob/master/.github/CONTRIBUTING.md).
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
# Credits
|
|
180
|
+
|
|
181
|
+
Many, many thanks to the [contributors](https://github.com/LuYifei2011/scratchblocks-plus/graphs/contributors)!
|
|
182
|
+
|
|
183
|
+
* Authored by [LuYifei2011](https://github.com/LuYifei2011)
|
|
184
|
+
* This is a fork of [scratchblocks](https://github.com/scratchblocks/scratchblocks), so all the credit there still applies here.
|
|
185
|
+
* Original scratchblocks library by [tjvr](https://github.com/tjvr)
|
|
186
|
+
* Original scratchblocks library maintained by tjvr and [apple502j](https://github.com/apple502j)
|
|
187
|
+
* Icons derived from [Scratch Blocks](https://github.com/scratchfoundation/scratch-blocks) (Apache License 2.0)
|
|
188
|
+
* Scratch 2 SVG proof-of-concept, shapes & filters by [as-com](https://github.com/as-com)
|
|
189
|
+
* Anna helped with a formula, and pointed out that I can't read graphs
|
|
190
|
+
* JSO designed the syntax and wrote the original [Block Plugin](https://en.scratch-wiki.info/wiki/Block_Plugin_\(1.4\))
|
|
191
|
+
* Help with translation code from [joooni](https://scratch.mit.edu/users/joooni/)
|
|
192
|
+
* Block translations from the [scratch-l10n repository](https://github.com/scratchfoundation/scratch-l10n/)
|
|
193
|
+
* Ported to node by [arve0](https://github.com/arve0)
|
package/browser.es.js
ADDED