scratch-paint 4.1.53 → 4.1.54
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/dist/scratch-paint.js
CHANGED
|
@@ -31291,6 +31291,34 @@ var format_isBitmap = function isBitmap(format) {
|
|
|
31291
31291
|
return format === Formats.BITMAP || format === Formats.BITMAP_SKIP_CONVERT;
|
|
31292
31292
|
};
|
|
31293
31293
|
|
|
31294
|
+
// CONCATENATED MODULE: ./src/helper/strip-invalid-paper-data.js
|
|
31295
|
+
/**
|
|
31296
|
+
* Drop `data-paper-data` attributes whose value isn't valid JSON. Paper.js
|
|
31297
|
+
* synchronously calls JSON.parse on this attribute during importSVG and
|
|
31298
|
+
* throws on malformed values, taking down the whole import. The attribute
|
|
31299
|
+
* is paper's own serialization metadata; if it can't parse, paper wouldn't
|
|
31300
|
+
* have been able to use it.
|
|
31301
|
+
*
|
|
31302
|
+
* Operates on a parsed Document in place so callers that already have one
|
|
31303
|
+
* (e.g. for viewBox extraction) don't pay for a second parse-and-serialize.
|
|
31304
|
+
* @param {Document} svgDoc - parsed SVG document; mutated in place.
|
|
31305
|
+
* @returns {boolean} true if any attribute was removed (caller should
|
|
31306
|
+
* re-serialize); false if the document was untouched.
|
|
31307
|
+
*/
|
|
31308
|
+
var stripInvalidPaperData = function stripInvalidPaperData(svgDoc) {
|
|
31309
|
+
var modified = false;
|
|
31310
|
+
var els = svgDoc.querySelectorAll('[data-paper-data]');
|
|
31311
|
+
for (var i = 0; i < els.length; i++) {
|
|
31312
|
+
try {
|
|
31313
|
+
JSON.parse(els[i].getAttribute('data-paper-data'));
|
|
31314
|
+
} catch (_unused) {
|
|
31315
|
+
els[i].removeAttribute('data-paper-data');
|
|
31316
|
+
modified = true;
|
|
31317
|
+
}
|
|
31318
|
+
}
|
|
31319
|
+
return modified;
|
|
31320
|
+
};
|
|
31321
|
+
|
|
31294
31322
|
// CONCATENATED MODULE: ./src/lib/modes.js
|
|
31295
31323
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
31296
31324
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -34267,6 +34295,7 @@ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf
|
|
|
34267
34295
|
|
|
34268
34296
|
|
|
34269
34297
|
|
|
34298
|
+
|
|
34270
34299
|
|
|
34271
34300
|
|
|
34272
34301
|
var paper_canvas_PaperCanvas = /*#__PURE__*/function (_React$Component) {
|
|
@@ -34460,17 +34489,19 @@ var paper_canvas_PaperCanvas = /*#__PURE__*/function (_React$Component) {
|
|
|
34460
34489
|
// well-formed document.
|
|
34461
34490
|
svg = scratch_svg_renderer_["sanitizeSvg"].sanitizeSvgText(svg);
|
|
34462
34491
|
|
|
34463
|
-
//
|
|
34464
|
-
//
|
|
34465
|
-
//
|
|
34466
|
-
|
|
34467
|
-
var svgDom =
|
|
34492
|
+
// 4. Parse once: read viewBox (translated back for some costumes
|
|
34493
|
+
// to render correctly — paper translates it to (0, 0) on import)
|
|
34494
|
+
// and strip data-paper-data values that fail JSON.parse (paper.js
|
|
34495
|
+
// synchronously throws on these and aborts the whole import).
|
|
34496
|
+
var svgDom = new DOMParser().parseFromString(svg, 'text/xml');
|
|
34497
|
+
var modified = stripInvalidPaperData(svgDom);
|
|
34468
34498
|
var viewBox = svgDom.documentElement.attributes.viewBox ? svgDom.documentElement.attributes.viewBox.value.match(/\S+/g) : null;
|
|
34469
34499
|
if (viewBox) {
|
|
34470
34500
|
for (var i = 0; i < viewBox.length; i++) {
|
|
34471
34501
|
viewBox[i] = parseFloat(viewBox[i]);
|
|
34472
34502
|
}
|
|
34473
34503
|
}
|
|
34504
|
+
if (modified) svg = new XMLSerializer().serializeToString(svgDom);
|
|
34474
34505
|
paper_full_default.a.project.importSVG(svg, {
|
|
34475
34506
|
expandShapes: true,
|
|
34476
34507
|
onLoad: function onLoad(item) {
|