Parse sb3 blocks, and generate scratchblocks formatted code.
BSD-3-CLAUSE License
parse-sb3-blocks parses Scratch 3.0 block formats, and convert it to scratchblocks format.
import {toScratchblocks} from 'parse-sb3-blocks';
const sb3blocks = {
'ND,(]G?KLIy(IZrd2sl.': {
opcode: 'event_whenflagclicked',
...
}
};
console.log(toScratchblocks('ND,(]G?KLIy(IZrd2sl.', sb3blocks, 'en', {tabs: ' '.repeat(4)}));
toScratchblocks is a function. This can take three to four arguments:
en
should always be available.opts
can have these properties.
none
(default), variables will never have ::variables
at the end. If set to always
, it will always have ::variables
. If set to as-needed
, it will have ::variables
if block name conflicts.It also exports several classes used internally by the parsers. These are not APIs and is subject to changes at any time.
Connectable is an instance that can be connected to a stack block via next-parent, including:
Inputtable can be used as an argument. Note that Icon
is not technically an argument, but is Inputtable.
Both Connectable and Inputtable implement toScratchblocks
method. It accepts locale
and opts
, similar to the exported toScratchblocks
.
Instances with class name ending with "Block" have these attributes:
id
for block IDopcode
for block opcodeinputtables
for object of input key to Inputtableblock-enum.js
provides an enum for block types.
translations.js
is an auto-generated file which includes all translations. options.js
is also auto-generated, and contains which block needs options (because of conflicting names).
Only blocks and menu items in all-blocks.js are supported.
all-blocks.js default-exports allBlocks, which is an object with opcode as key and the object (see below) as value.
The object has these keys and values:
true
, it will be ignored from the translation generator.BlockEnum.BLOCK
.EmptyBooleanInput
. If omitted, empty array is used.Node 16+ is required for building. Type npm run build
, which generates locale files.
mode
: Unless set to dev
, the result is minified. Add docs
to update the JS file used in demo.