js-draw
Version:
Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript.
100 lines (99 loc) • 3.82 kB
JavaScript
//
// Used by `SVGLoader`s to store unrecognised global attributes
// (e.g. unrecognised XML namespace declarations).
// @internal
// @packageDocumentation
//
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const math_1 = require("@js-draw/math");
const SVGRenderer_1 = __importDefault(require("../rendering/renderers/SVGRenderer"));
const AbstractComponent_1 = __importStar(require("./AbstractComponent"));
const componentKind = 'svg-global-attributes';
// Stores global SVG attributes (e.g. namespace identifiers.)
class SVGGlobalAttributesObject extends AbstractComponent_1.default {
// Does not modify `attrs`
constructor(attrs) {
super(componentKind);
this.contentBBox = math_1.Rect2.empty;
// Already stored/managed in `editor.image`.
const attrsManagedByRenderer = ['viewBox', 'width', 'height'];
// Only store attributes that aren't managed by other parts of the app.
this.attrs = attrs.filter(([attr, _value]) => {
return !attrsManagedByRenderer.includes(attr);
});
}
render(canvas, _visibleRect) {
if (!(canvas instanceof SVGRenderer_1.default)) {
// Don't draw unrenderable objects if we can't
return;
}
for (const [attr, value] of this.attrs) {
canvas.setRootSVGAttribute(attr, value);
}
}
intersects(_lineSegment) {
return false;
}
applyTransformation(_affineTransfm) { }
isSelectable() {
return false;
}
getSizingMode() {
// This component can be shown anywhere (it won't be
// visible to the user, it just needs to be saved with
// the image).
return AbstractComponent_1.ComponentSizingMode.Anywhere;
}
createClone() {
return new SVGGlobalAttributesObject(this.attrs);
}
description(localization) {
return localization.svgObject;
}
serializeToJSON() {
return JSON.stringify(this.attrs);
}
static deserializeFromString(_data) {
// To be safe, don't deserialize any attributes
return new SVGGlobalAttributesObject([]);
}
}
exports.default = SVGGlobalAttributesObject;
AbstractComponent_1.default.registerComponent(componentKind, SVGGlobalAttributesObject.deserializeFromString);
;