js-draw 1.4.0 → 1.4.1
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/README.md +1 -1
- package/dist/bundle.js +2 -2
- package/dist/cjs/components/BackgroundComponent.js +12 -6
- package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +2 -2
- package/dist/cjs/components/SVGGlobalAttributesObject.js +10 -14
- package/dist/cjs/image/export/adjustExportedSVGSize.d.ts +6 -0
- package/dist/cjs/image/export/{setExportedSVGSize.js → adjustExportedSVGSize.js} +4 -7
- package/dist/cjs/image/export/editorImageToSVG.d.ts +1 -1
- package/dist/cjs/image/export/editorImageToSVG.js +22 -8
- package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +1 -0
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +8 -0
- package/dist/cjs/rendering/renderers/SVGRenderer.d.ts +28 -1
- package/dist/cjs/rendering/renderers/SVGRenderer.js +58 -7
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/components/BackgroundComponent.mjs +12 -6
- package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +2 -2
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +10 -14
- package/dist/mjs/image/export/adjustExportedSVGSize.d.ts +6 -0
- package/dist/mjs/image/export/{setExportedSVGSize.mjs → adjustExportedSVGSize.mjs} +4 -7
- package/dist/mjs/image/export/editorImageToSVG.d.ts +1 -1
- package/dist/mjs/image/export/editorImageToSVG.mjs +23 -9
- package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +1 -0
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +8 -0
- package/dist/mjs/rendering/renderers/SVGRenderer.d.ts +28 -1
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +58 -7
- package/dist/mjs/version.mjs +1 -1
- package/package.json +2 -2
- package/dist/cjs/image/export/setExportedSVGSize.d.ts +0 -6
- package/dist/mjs/image/export/setExportedSVGSize.d.ts +0 -6
@@ -36,6 +36,7 @@ export default class SVGRenderer extends AbstractRenderer {
|
|
36
36
|
this.textContainer = null;
|
37
37
|
this.textContainerTransform = null;
|
38
38
|
this.textParentStyle = defaultTextStyle;
|
39
|
+
this.visibleRectOverride = null;
|
39
40
|
this.clear();
|
40
41
|
this.addStyleSheet();
|
41
42
|
}
|
@@ -338,20 +339,70 @@ export default class SVGRenderer extends AbstractRenderer {
|
|
338
339
|
isTooSmallToRender(_rect) {
|
339
340
|
return false;
|
340
341
|
}
|
341
|
-
|
342
|
-
|
342
|
+
/**
|
343
|
+
* Overrides the visible region returned by `getVisibleRect`.
|
344
|
+
*
|
345
|
+
* This is useful when the `viewport`'s transform has been modified,
|
346
|
+
* for example, to compensate for storing part of the image's
|
347
|
+
* transformation in an SVG property.
|
348
|
+
*/
|
349
|
+
overrideVisibleRect(newRect) {
|
350
|
+
this.visibleRectOverride = newRect;
|
351
|
+
}
|
352
|
+
getVisibleRect() {
|
353
|
+
return this.visibleRectOverride ?? super.getVisibleRect();
|
354
|
+
}
|
355
|
+
/**
|
356
|
+
* Creates a new SVG element and `SVGRenerer` with `width`, `height`, `viewBox`,
|
357
|
+
* and other metadata attributes set for the given `Viewport`.
|
358
|
+
*
|
359
|
+
* If `options` is a `boolean`, it is interpreted as whether to sanitize (not add unknown
|
360
|
+
* SVG entities to) the output.
|
361
|
+
*/
|
362
|
+
static fromViewport(viewport, options = true) {
|
363
|
+
let sanitize;
|
364
|
+
let useViewBoxForPositioning;
|
365
|
+
if (typeof options === 'boolean') {
|
366
|
+
sanitize = options;
|
367
|
+
useViewBoxForPositioning = false;
|
368
|
+
}
|
369
|
+
else {
|
370
|
+
sanitize = options.sanitize ?? true;
|
371
|
+
useViewBoxForPositioning = options.useViewBoxForPositioning ?? false;
|
372
|
+
}
|
343
373
|
const svgNameSpace = 'http://www.w3.org/2000/svg';
|
344
374
|
const result = document.createElementNS(svgNameSpace, 'svg');
|
345
|
-
const
|
375
|
+
const screenRectSize = viewport.getScreenRectSize();
|
376
|
+
const visibleRect = viewport.visibleRect;
|
377
|
+
let viewBoxComponents;
|
378
|
+
if (useViewBoxForPositioning) {
|
379
|
+
const exportRect = viewport.visibleRect;
|
380
|
+
viewBoxComponents = [
|
381
|
+
exportRect.x, exportRect.y, exportRect.w, exportRect.h,
|
382
|
+
];
|
383
|
+
// Replace the viewport with a copy that has a modified transform.
|
384
|
+
// (Avoids modifying the original viewport).
|
385
|
+
viewport = viewport.getTemporaryClone();
|
386
|
+
// TODO: This currently discards any rotation information.
|
387
|
+
// Render with (0,0) at (0,0) -- the translation is handled by the viewBox.
|
388
|
+
viewport.resetTransform(Mat33.identity);
|
389
|
+
}
|
390
|
+
else {
|
391
|
+
viewBoxComponents = [0, 0, screenRectSize.x, screenRectSize.y];
|
392
|
+
}
|
346
393
|
// rect.x -> size of rect in x direction, rect.y -> size of rect in y direction.
|
347
|
-
result.setAttribute('viewBox',
|
348
|
-
result.setAttribute('width', toRoundedString(
|
349
|
-
result.setAttribute('height', toRoundedString(
|
394
|
+
result.setAttribute('viewBox', viewBoxComponents.map(part => toRoundedString(part)).join(' '));
|
395
|
+
result.setAttribute('width', toRoundedString(screenRectSize.x));
|
396
|
+
result.setAttribute('height', toRoundedString(screenRectSize.y));
|
350
397
|
// Ensure the image can be identified as an SVG if downloaded.
|
351
398
|
// See https://jwatt.org/svg/authoring/
|
352
399
|
result.setAttribute('version', '1.1');
|
353
400
|
result.setAttribute('baseProfile', 'full');
|
354
401
|
result.setAttribute('xmlns', svgNameSpace);
|
355
|
-
|
402
|
+
const renderer = new SVGRenderer(result, viewport, sanitize);
|
403
|
+
if (!visibleRect.eq(viewport.visibleRect)) {
|
404
|
+
renderer.overrideVisibleRect(visibleRect);
|
405
|
+
}
|
406
|
+
return { element: result, renderer };
|
356
407
|
}
|
357
408
|
}
|
package/dist/mjs/version.mjs
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-draw",
|
3
|
-
"version": "1.4.
|
3
|
+
"version": "1.4.1",
|
4
4
|
"description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
|
5
5
|
"types": "./dist/mjs/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -86,5 +86,5 @@
|
|
86
86
|
"freehand",
|
87
87
|
"svg"
|
88
88
|
],
|
89
|
-
"gitHead": "
|
89
|
+
"gitHead": "cf64a8bf9fccc54c87478ea6ed5da771346b62bf"
|
90
90
|
}
|