scratch-paint 4.1.53 → 4.2.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/.babelrc +0 -1
- package/dist/web/scratch-paint.js +3 -0
- package/dist/web/scratch-paint.js.LICENSE.txt +5 -0
- package/dist/web/scratch-paint.js.map +1 -0
- package/package.json +21 -19
- package/src/containers/paper-canvas.jsx +8 -5
- package/src/helper/strip-invalid-paper-data.js +28 -0
- package/webpack.config.js +49 -116
- package/dist/scratch-paint.js +0 -49762
- package/dist/scratch-paint.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratch-paint.js","mappings":";AAAA","sources":["webpack://scratch-paint/webpack/universalModuleDefinition"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"prop-types\"), require(\"minilog\"), require(\"react\"), require(\"react-redux\"), require(\"react-intl\"), require(\"@scratch/scratch-svg-renderer\"), require(\"react-style-proptype\"), require(\"react-popover\"), require(\"react-responsive\"), require(\"redux\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"prop-types\", \"minilog\", \"react\", \"react-redux\", \"react-intl\", \"@scratch/scratch-svg-renderer\", \"react-style-proptype\", \"react-popover\", \"react-responsive\", \"redux\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"scratch-paint\"] = factory(require(\"prop-types\"), require(\"minilog\"), require(\"react\"), require(\"react-redux\"), require(\"react-intl\"), require(\"@scratch/scratch-svg-renderer\"), require(\"react-style-proptype\"), require(\"react-popover\"), require(\"react-responsive\"), require(\"redux\"));\n\telse\n\t\troot[\"scratch-paint\"] = factory(root[\"prop-types\"], root[\"minilog\"], root[\"react\"], root[\"react-redux\"], root[\"react-intl\"], root[\"@scratch/scratch-svg-renderer\"], root[\"react-style-proptype\"], root[\"react-popover\"], root[\"react-responsive\"], root[\"redux\"]);\n})(self, function(__WEBPACK_EXTERNAL_MODULE__863__, __WEBPACK_EXTERNAL_MODULE__749__, __WEBPACK_EXTERNAL_MODULE__629__, __WEBPACK_EXTERNAL_MODULE__850__, __WEBPACK_EXTERNAL_MODULE__923__, __WEBPACK_EXTERNAL_MODULE__962__, __WEBPACK_EXTERNAL_MODULE__17__, __WEBPACK_EXTERNAL_MODULE__53__, __WEBPACK_EXTERNAL_MODULE__582__, __WEBPACK_EXTERNAL_MODULE__0__) {\nreturn "],"names":[],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scratch-paint",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Graphical User Interface for the Scratch 3.0 paint editor, which is used to make and edit sprites for use in projects.",
|
|
5
|
-
"main": "./dist/scratch-paint.js",
|
|
5
|
+
"main": "./dist/web/scratch-paint.js",
|
|
6
6
|
"browser": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
"webpack": "./src/index.js",
|
|
9
|
+
"browser": "./src/index.js",
|
|
10
|
+
"node": "./dist/web/scratch-paint.js",
|
|
11
|
+
"default": "./dist/web/scratch-paint.js"
|
|
12
|
+
},
|
|
7
13
|
"scripts": {
|
|
8
|
-
"build": "npm run clean && webpack --progress --
|
|
14
|
+
"build": "npm run clean && webpack --progress --bail",
|
|
9
15
|
"clean": "rimraf ./dist && mkdirp dist && rimraf ./playground && mkdirp playground",
|
|
10
16
|
"i18n:push": "tx-push-src scratch-editor paint-editor ./translations/en.json",
|
|
11
17
|
"i18n:src": "rimraf ./translations/messages && babel src > tmp.js && rimraf tmp.js && ./scripts/build-i18n-source.js ./translations/messages/ ./translations/",
|
|
12
18
|
"lint": "eslint",
|
|
13
|
-
"start": "webpack
|
|
19
|
+
"start": "webpack serve",
|
|
14
20
|
"test": "npm run unit",
|
|
15
21
|
"unit": "jest --reporters=default",
|
|
16
|
-
"watch": "webpack --progress --
|
|
22
|
+
"watch": "webpack --progress --watch"
|
|
17
23
|
},
|
|
18
24
|
"author": "Massachusetts Institute of Technology",
|
|
19
25
|
"license": "AGPL-3.0-only",
|
|
@@ -50,31 +56,29 @@
|
|
|
50
56
|
"@babel/cli": "7.28.6",
|
|
51
57
|
"@babel/core": "7.29.0",
|
|
52
58
|
"@babel/node": "7.29.0",
|
|
53
|
-
"@babel/preset-env": "7.29.
|
|
59
|
+
"@babel/preset-env": "7.29.5",
|
|
54
60
|
"@babel/preset-react": "7.28.5",
|
|
55
61
|
"@commitlint/cli": "17.8.1",
|
|
56
62
|
"@commitlint/config-conventional": "17.8.1",
|
|
57
63
|
"@testing-library/react": "8.0.9",
|
|
58
64
|
"autoprefixer": "9.8.8",
|
|
59
65
|
"babel-jest": "29.7.0",
|
|
60
|
-
"babel-loader": "
|
|
66
|
+
"babel-loader": "9.2.1",
|
|
61
67
|
"babel-plugin-react-intl": "3.5.1",
|
|
62
|
-
"babel-plugin-transform-object-rest-spread": "6.26.0",
|
|
63
68
|
"canvas": "3.2.3",
|
|
64
|
-
"css-loader": "
|
|
69
|
+
"css-loader": "5.2.7",
|
|
65
70
|
"eslint": "9.39.4",
|
|
66
71
|
"eslint-config-scratch": "12.0.51",
|
|
67
72
|
"gh-pages": "3.2.3",
|
|
68
73
|
"globals": "16.5.0",
|
|
69
|
-
"html-webpack-plugin": "
|
|
74
|
+
"html-webpack-plugin": "5.6.3",
|
|
70
75
|
"husky": "8.0.3",
|
|
71
76
|
"jest": "27.5.1",
|
|
72
77
|
"jest-junit": "13.2.0",
|
|
73
78
|
"json": "9.0.6",
|
|
74
|
-
"lodash.defaultsdeep": "4.6.1",
|
|
75
79
|
"mkdirp": "1.0.4",
|
|
76
80
|
"postcss-import": "12.0.1",
|
|
77
|
-
"postcss-loader": "3.0
|
|
81
|
+
"postcss-loader": "4.3.0",
|
|
78
82
|
"postcss-simple-vars": "5.0.2",
|
|
79
83
|
"raf": "3.4.1",
|
|
80
84
|
"react-test-renderer": "18.3.1",
|
|
@@ -84,15 +88,13 @@
|
|
|
84
88
|
"rimraf": "2.7.1",
|
|
85
89
|
"scratch-l10n": "6.1.75",
|
|
86
90
|
"scratch-semantic-release-config": "4.0.1",
|
|
91
|
+
"scratch-webpack-configuration": "3.1.2",
|
|
87
92
|
"semantic-release": "25.0.3",
|
|
88
|
-
"style-loader": "
|
|
89
|
-
"svg-url-loader": "3.0.3",
|
|
93
|
+
"style-loader": "4.0.0",
|
|
90
94
|
"tap": "21.7.2",
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"webpack": "
|
|
94
|
-
"webpack-cli": "3.3.12",
|
|
95
|
-
"webpack-dev-server": "3.11.3"
|
|
95
|
+
"webpack": "5.105.4",
|
|
96
|
+
"webpack-cli": "5.1.4",
|
|
97
|
+
"webpack-dev-server": "5.2.0"
|
|
96
98
|
},
|
|
97
99
|
"config": {
|
|
98
100
|
"commitizen": {
|
|
@@ -7,6 +7,7 @@ import {sanitizeSvg} from '@scratch/scratch-svg-renderer';
|
|
|
7
7
|
import Formats from '../lib/format';
|
|
8
8
|
import log from '../log/log';
|
|
9
9
|
|
|
10
|
+
import {stripInvalidPaperData} from '../helper/strip-invalid-paper-data';
|
|
10
11
|
import {performSnapshot} from '../helper/undo';
|
|
11
12
|
import {undoSnapshot, clearUndoState} from '../reducers/undo';
|
|
12
13
|
import {isGroup, ungroupItems} from '../helper/group';
|
|
@@ -215,11 +216,12 @@ class PaperCanvas extends React.Component {
|
|
|
215
216
|
// well-formed document.
|
|
216
217
|
svg = sanitizeSvg.sanitizeSvgText(svg);
|
|
217
218
|
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
const svgDom =
|
|
219
|
+
// 4. Parse once: read viewBox (translated back for some costumes
|
|
220
|
+
// to render correctly — paper translates it to (0, 0) on import)
|
|
221
|
+
// and strip data-paper-data values that fail JSON.parse (paper.js
|
|
222
|
+
// synchronously throws on these and aborts the whole import).
|
|
223
|
+
const svgDom = new DOMParser().parseFromString(svg, 'text/xml');
|
|
224
|
+
const modified = stripInvalidPaperData(svgDom);
|
|
223
225
|
const viewBox = svgDom.documentElement.attributes.viewBox ?
|
|
224
226
|
svgDom.documentElement.attributes.viewBox.value.match(/\S+/g) : null;
|
|
225
227
|
if (viewBox) {
|
|
@@ -227,6 +229,7 @@ class PaperCanvas extends React.Component {
|
|
|
227
229
|
viewBox[i] = parseFloat(viewBox[i]);
|
|
228
230
|
}
|
|
229
231
|
}
|
|
232
|
+
if (modified) svg = new XMLSerializer().serializeToString(svgDom);
|
|
230
233
|
|
|
231
234
|
paper.project.importSVG(svg, {
|
|
232
235
|
expandShapes: true,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drop `data-paper-data` attributes whose value isn't valid JSON. Paper.js
|
|
3
|
+
* synchronously calls JSON.parse on this attribute during importSVG and
|
|
4
|
+
* throws on malformed values, taking down the whole import. The attribute
|
|
5
|
+
* is paper's own serialization metadata; if it can't parse, paper wouldn't
|
|
6
|
+
* have been able to use it.
|
|
7
|
+
*
|
|
8
|
+
* Operates on a parsed Document in place so callers that already have one
|
|
9
|
+
* (e.g. for viewBox extraction) don't pay for a second parse-and-serialize.
|
|
10
|
+
* @param {Document} svgDoc - parsed SVG document; mutated in place.
|
|
11
|
+
* @returns {boolean} true if any attribute was removed (caller should
|
|
12
|
+
* re-serialize); false if the document was untouched.
|
|
13
|
+
*/
|
|
14
|
+
const stripInvalidPaperData = function (svgDoc) {
|
|
15
|
+
let modified = false;
|
|
16
|
+
const els = svgDoc.querySelectorAll('[data-paper-data]');
|
|
17
|
+
for (let i = 0; i < els.length; i++) {
|
|
18
|
+
try {
|
|
19
|
+
JSON.parse(els[i].getAttribute('data-paper-data'));
|
|
20
|
+
} catch {
|
|
21
|
+
els[i].removeAttribute('data-paper-data');
|
|
22
|
+
modified = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return modified;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export {stripInvalidPaperData};
|
package/webpack.config.js
CHANGED
|
@@ -1,133 +1,66 @@
|
|
|
1
|
-
const defaultsDeep = require('lodash.defaultsdeep');
|
|
2
1
|
const path = require('path');
|
|
3
2
|
|
|
4
|
-
// Plugins
|
|
5
3
|
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
6
|
-
const
|
|
4
|
+
const ScratchWebpackConfigBuilder = require('scratch-webpack-configuration');
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const baseConfig = new ScratchWebpackConfigBuilder({
|
|
7
|
+
rootPath: __dirname,
|
|
8
|
+
enableReact: true
|
|
9
|
+
})
|
|
10
|
+
.setTarget('browserslist')
|
|
11
|
+
.addModuleRule({
|
|
12
|
+
test: /\.(svg|png)$/i,
|
|
13
|
+
resourceQuery: /^$/,
|
|
14
|
+
type: 'asset'
|
|
15
|
+
});
|
|
12
16
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
devtool: 'cheap-module-source-map',
|
|
16
|
-
module: {
|
|
17
|
-
rules: [{
|
|
18
|
-
test: /\.jsx?$/,
|
|
19
|
-
loader: 'babel-loader',
|
|
20
|
-
include: [
|
|
21
|
-
path.resolve(__dirname, 'src'),
|
|
22
|
-
path.join(__dirname, 'node_modules/react-intl'),
|
|
23
|
-
path.join(__dirname, 'node_modules/intl-messageformat'),
|
|
24
|
-
path.join(__dirname, 'node_modules/intl-messageformat-parser'),
|
|
25
|
-
// scratch-svg-renderer's published bundle ships modern JS
|
|
26
|
-
// that webpack 4's default parser can't read; transpile it
|
|
27
|
-
// here. The library output externalizes the same package, so
|
|
28
|
-
// this is only on the path for the playground bundle.
|
|
29
|
-
path.join(__dirname, 'node_modules/@scratch/scratch-svg-renderer')
|
|
30
|
-
],
|
|
31
|
-
options: {
|
|
32
|
-
plugins: ['transform-object-rest-spread'],
|
|
33
|
-
presets: [
|
|
34
|
-
['@babel/preset-env', {
|
|
35
|
-
targets: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}],
|
|
36
|
-
'@babel/preset-react']
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
test: /\.css$/,
|
|
41
|
-
use: [{
|
|
42
|
-
loader: 'style-loader'
|
|
43
|
-
}, {
|
|
44
|
-
loader: 'css-loader',
|
|
45
|
-
options: {
|
|
46
|
-
modules: {
|
|
47
|
-
localIdentName: '[name]_[local]_[hash:base64:5]'
|
|
48
|
-
},
|
|
49
|
-
importLoaders: 1,
|
|
50
|
-
localsConvention: 'camelCase'
|
|
51
|
-
}
|
|
52
|
-
}, {
|
|
53
|
-
loader: 'postcss-loader',
|
|
54
|
-
options: {
|
|
55
|
-
ident: 'postcss',
|
|
56
|
-
plugins: function () {
|
|
57
|
-
return [
|
|
58
|
-
postcssImport,
|
|
59
|
-
postcssVars,
|
|
60
|
-
autoprefixer()
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}]
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
test: /\.png$/i,
|
|
68
|
-
loader: 'url-loader'
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
test: /\.svg$/,
|
|
72
|
-
loader: 'svg-url-loader?noquotes'
|
|
73
|
-
}]
|
|
74
|
-
},
|
|
75
|
-
optimization: {
|
|
76
|
-
minimizer: [
|
|
77
|
-
new UglifyJsPlugin({
|
|
78
|
-
include: /\.min\.js$/
|
|
79
|
-
})
|
|
80
|
-
]
|
|
81
|
-
},
|
|
82
|
-
plugins: []
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
module.exports = [
|
|
86
|
-
// For the playground
|
|
87
|
-
defaultsDeep({}, base, {
|
|
88
|
-
devServer: {
|
|
89
|
-
contentBase: path.resolve(__dirname, 'playground'),
|
|
90
|
-
host: '0.0.0.0',
|
|
91
|
-
port: process.env.PORT || 8078
|
|
92
|
-
},
|
|
17
|
+
const playgroundConfig = baseConfig.clone()
|
|
18
|
+
.merge({
|
|
93
19
|
entry: {
|
|
94
20
|
playground: './src/playground/playground.jsx'
|
|
95
21
|
},
|
|
96
22
|
output: {
|
|
97
|
-
path: path.resolve(__dirname, 'playground')
|
|
98
|
-
filename: '[name].js'
|
|
99
|
-
},
|
|
100
|
-
plugins: base.plugins.concat([
|
|
101
|
-
new HtmlWebpackPlugin({
|
|
102
|
-
template: 'src/playground/index.ejs',
|
|
103
|
-
title: 'Scratch 3.0 Paint Editor Playground'
|
|
104
|
-
})
|
|
105
|
-
])
|
|
106
|
-
}),
|
|
107
|
-
// For use as a library
|
|
108
|
-
defaultsDeep({}, base, {
|
|
109
|
-
externals: {
|
|
110
|
-
'@scratch/scratch-svg-renderer': '@scratch/scratch-svg-renderer',
|
|
111
|
-
'minilog': 'minilog',
|
|
112
|
-
'prop-types': 'prop-types',
|
|
113
|
-
'react': 'react',
|
|
114
|
-
'react-dom': 'react-dom',
|
|
115
|
-
'react-intl': 'react-intl',
|
|
116
|
-
'react-intl-redux': 'react-intl-redux',
|
|
117
|
-
'react-popover': 'react-popover',
|
|
118
|
-
'react-redux': 'react-redux',
|
|
119
|
-
'react-responsive': 'react-responsive',
|
|
120
|
-
'react-style-proptype': 'react-style-proptype',
|
|
121
|
-
'react-tooltip': 'react-tooltip',
|
|
122
|
-
'redux': 'redux'
|
|
23
|
+
path: path.resolve(__dirname, 'playground')
|
|
123
24
|
},
|
|
25
|
+
devServer: {
|
|
26
|
+
host: '0.0.0.0'
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.enableDevServer(process.env.PORT || 8078)
|
|
30
|
+
.addPlugin(new HtmlWebpackPlugin({
|
|
31
|
+
template: 'src/playground/index.ejs',
|
|
32
|
+
title: 'Scratch 3.0 Paint Editor Playground'
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
const libraryConfig = baseConfig.clone()
|
|
36
|
+
.merge({
|
|
124
37
|
entry: {
|
|
125
38
|
'scratch-paint': './src/index.js'
|
|
126
39
|
},
|
|
127
40
|
output: {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
41
|
+
library: {
|
|
42
|
+
name: 'scratch-paint',
|
|
43
|
+
type: 'umd2'
|
|
44
|
+
}
|
|
131
45
|
}
|
|
132
46
|
})
|
|
47
|
+
.addExternals([
|
|
48
|
+
'@scratch/scratch-svg-renderer',
|
|
49
|
+
'minilog',
|
|
50
|
+
'prop-types',
|
|
51
|
+
'react',
|
|
52
|
+
'react-dom',
|
|
53
|
+
'react-intl',
|
|
54
|
+
'react-intl-redux',
|
|
55
|
+
'react-popover',
|
|
56
|
+
'react-redux',
|
|
57
|
+
'react-responsive',
|
|
58
|
+
'react-style-proptype',
|
|
59
|
+
'react-tooltip',
|
|
60
|
+
'redux'
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
module.exports = [
|
|
64
|
+
playgroundConfig.get(),
|
|
65
|
+
libraryConfig.get()
|
|
133
66
|
];
|