Fix global import in core-js

This commit is contained in:
Paulo Gustavo Veiga 2021-12-02 21:23:14 -08:00
parent 4a93d43e83
commit c2b94b8696
21 changed files with 140 additions and 194 deletions

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $assert } from '@wisemapping/core-js';
import Element from './Element'; import Element from './Element';
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
const core = coreJs();
const CurvedLine = new Class({ const CurvedLine = new Class({
Extends: Element, Extends: Element,
initialize(attributes) { initialize(attributes) {
@ -45,15 +43,15 @@ const CurvedLine = new Class({
}, },
setFrom(x, y) { setFrom(x, y) {
core.Function.$assert(!Number.isNaN(x), 'x must be defined'); $assert(!Number.isNaN(x), 'x must be defined');
core.Function.$assert(!Number.isNaN(y), 'y must be defined'); $assert(!Number.isNaN(y), 'y must be defined');
this.peer.setFrom(x, y); this.peer.setFrom(x, y);
}, },
setTo(x, y) { setTo(x, y) {
core.Function.$assert(!Number.isNaN(x), 'x must be defined'); $assert(!Number.isNaN(x), 'x must be defined');
core.Function.$assert(!Number.isNaN(y), 'y must be defined'); $assert(!Number.isNaN(y), 'y must be defined');
this.peer.setTo(x, y); this.peer.setTo(x, y);
}, },

View File

@ -15,9 +15,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import CoreJS from '@wisemapping/core-js';
const core = CoreJS(); import { $defined } from '@wisemapping/core-js';
const Element = new Class({ const Element = new Class({
initialize(peer, attributes) { initialize(peer, attributes) {
@ -26,7 +25,7 @@ const Element = new Class({
throw new Error('Element peer can not be null'); throw new Error('Element peer can not be null');
} }
if (core.Function.$defined(attributes)) { if ($defined(attributes)) {
this._initialize(attributes); this._initialize(attributes);
} }
}, },
@ -39,7 +38,7 @@ const Element = new Class({
if (Object.prototype.hasOwnProperty.call(attributes, key)) { if (Object.prototype.hasOwnProperty.call(attributes, key)) {
const funcName = this._attributeNameToFuncName(key, 'set'); const funcName = this._attributeNameToFuncName(key, 'set');
let funcArgs = batchExecute[funcName]; let funcArgs = batchExecute[funcName];
if (!core.Function.$defined(funcArgs)) { if (!$defined(funcArgs)) {
funcArgs = []; funcArgs = [];
} }
@ -59,7 +58,7 @@ const Element = new Class({
// eslint-disable-next-line guard-for-in // eslint-disable-next-line guard-for-in
for (const key in batchExecute) { for (const key in batchExecute) {
const func = this[key]; const func = this[key];
if (!core.Function.$defined(func)) { if (!$defined(func)) {
throw new Error(`Could not find function: ${key}`); throw new Error(`Could not find function: ${key}`);
} }
func.apply(this, batchExecute[key]); func.apply(this, batchExecute[key]);
@ -172,7 +171,7 @@ const Element = new Class({
_attributeNameToFuncName(attributeKey, prefix) { _attributeNameToFuncName(attributeKey, prefix) {
const signature = Element._propertyNameToSignature[attributeKey]; const signature = Element._propertyNameToSignature[attributeKey];
if (!core.Function.$defined(signature)) { if (!$defined(signature)) {
throw new Error(`Unsupported attribute: ${attributeKey}`); throw new Error(`Unsupported attribute: ${attributeKey}`);
} }
@ -229,12 +228,12 @@ const Element = new Class({
const getterResult = getter.apply(this, []); const getterResult = getter.apply(this, []);
const attibuteName = signature[2]; const attibuteName = signature[2];
if (!core.Function.$defined(attibuteName)) { if (!$defined(attibuteName)) {
throw new Error(`Could not find attribute mapping for:${key}`); throw new Error(`Could not find attribute mapping for:${key}`);
} }
const result = getterResult[attibuteName]; const result = getterResult[attibuteName];
if (!core.Function.$defined(result)) { if (!$defined(result)) {
throw new Error(`Could not find attribute with name:${attibuteName}`); throw new Error(`Could not find attribute with name:${attibuteName}`);
} }

View File

@ -15,9 +15,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import CoreJS from '@wisemapping/core-js';
const core = CoreJS(); import { $defined } from '@wisemapping/core-js';
class ElementClass { class ElementClass {
constructor(peer, attributes) { constructor(peer, attributes) {
@ -26,7 +25,7 @@ class ElementClass {
throw new Error('Element peer can not be null'); throw new Error('Element peer can not be null');
} }
if (core.Function.$defined(attributes)) { if ($defined(attributes)) {
this._initialize(attributes); this._initialize(attributes);
} }
} }
@ -39,7 +38,7 @@ class ElementClass {
if (Object.prototype.hasOwnProperty.call(attributes, key)) { if (Object.prototype.hasOwnProperty.call(attributes, key)) {
const funcName = this._attributeNameToFuncName(key, 'set'); const funcName = this._attributeNameToFuncName(key, 'set');
let funcArgs = batchExecute[funcName]; let funcArgs = batchExecute[funcName];
if (!core.Function.$defined(funcArgs)) { if (!$defined(funcArgs)) {
funcArgs = []; funcArgs = [];
} }
@ -59,7 +58,7 @@ class ElementClass {
// eslint-disable-next-line guard-for-in // eslint-disable-next-line guard-for-in
for (const key in batchExecute) { for (const key in batchExecute) {
const func = this[key]; const func = this[key];
if (!core.Function.$defined(func)) { if (!$defined(func)) {
throw new Error(`Could not find function: ${key}`); throw new Error(`Could not find function: ${key}`);
} }
func.apply(this, batchExecute[key]); func.apply(this, batchExecute[key]);
@ -175,7 +174,7 @@ class ElementClass {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
_attributeNameToFuncName(attributeKey, prefix) { _attributeNameToFuncName(attributeKey, prefix) {
const signature = Element._propertyNameToSignature[attributeKey]; const signature = Element._propertyNameToSignature[attributeKey];
if (!core.Function.$defined(signature)) { if (!$defined(signature)) {
throw new Error(`Unsupported attribute: ${attributeKey}`); throw new Error(`Unsupported attribute: ${attributeKey}`);
} }
@ -232,12 +231,12 @@ class ElementClass {
const getterResult = getter.apply(this, []); const getterResult = getter.apply(this, []);
const attibuteName = signature[2]; const attibuteName = signature[2];
if (!core.Function.$defined(attibuteName)) { if (!$defined(attibuteName)) {
throw new Error(`Could not find attribute mapping for:${key}`); throw new Error(`Could not find attribute mapping for:${key}`);
} }
const result = getterResult[attibuteName]; const result = getterResult[attibuteName];
if (!core.Function.$defined(result)) { if (!$defined(result)) {
throw new Error(`Could not find attribute with name:${attibuteName}`); throw new Error(`Could not find attribute with name:${attibuteName}`);
} }

View File

@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
import TransformUtil from './peer/utils/TransformUtils'; import TransformUtil from './peer/utils/TransformUtils';

View File

@ -15,12 +15,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js';
import { $defined } from '@wisemapping/core-js';
import Element from './Element'; import Element from './Element';
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
const core = coreJs();
/** /**
* A group object can be used to collect shapes. * A group object can be used to collect shapes.
*/ */
@ -48,7 +47,7 @@ const Group = new Class({
* Remove an element as a child to the object. * Remove an element as a child to the object.
*/ */
removeChild(element) { removeChild(element) {
if (!core.Function.$defined(element)) { if (!$defined(element)) {
throw new Error('Child element can not be null'); throw new Error('Child element can not be null');
} }
@ -68,7 +67,7 @@ const Group = new Class({
* Appends an element as a child to the object. * Appends an element as a child to the object.
*/ */
append(element) { append(element) {
if (!core.Function.$defined(element)) { if (!$defined(element)) {
throw Error('Child element can not be null'); throw Error('Child element can not be null');
} }
@ -130,7 +129,7 @@ const Group = new Class({
}, },
appendDomChild(DomElement) { appendDomChild(DomElement) {
if (!core.Function.$defined(DomElement)) { if (!$defined(DomElement)) {
throw new Error('Child element can not be null'); throw new Error('Child element can not be null');
} }

View File

@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import ElementClass from './ElementClass'; import ElementClass from './ElementClass';
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
@ -25,9 +26,7 @@ import Toolkit from './Toolkit';
* For rounded rectangles, radius of the ellipse used to round off the corners of the rectangle. * For rounded rectangles, radius of the ellipse used to round off the corners of the rectangle.
*/ */
class Rect extends ElementClass { class Rect extends ElementClass {
constructor(arc, attributes) { constructor(arc, attributes) {
if (arc && arc > 1) { if (arc && arc > 1) {
throw new Error('Arc must be 0<=arc<=1'); throw new Error('Arc must be 0<=arc<=1');
} }
@ -49,7 +48,7 @@ class Rect extends ElementClass {
super(peer, defaultAttributes); super(peer, defaultAttributes);
} }
getType() { static getType() {
return 'Rect'; return 'Rect';
} }

View File

@ -15,89 +15,87 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js';
import Element from './Element'; import { $assert } from '@wisemapping/core-js';
import ElementClass from './ElementClass';
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
import Font from './Font'; import Font from './Font';
const core = coreJs(); class Text extends ElementClass {
constructor(attributes) {
const Text = new Class({
Extends: Element,
initialize(attributes) {
const peer = Toolkit.createText(Font); const peer = Toolkit.createText(Font);
this.parent(peer, attributes); super(peer, attributes);
}, }
getType() { static getType() {
return 'Text'; return 'Text';
}, }
setText(text) { setText(text) {
this.peer.setText(text); this.peer.setText(text);
}, }
setTextAlignment(align) { setTextAlignment(align) {
core.Function.$assert(align, 'align can not be null'); $assert(align, 'align can not be null');
this.peer.setTextAlignment(align); this.peer.setTextAlignment(align);
}, }
setTextSize(width, height) { setTextSize(width, height) {
this.peer.setContentSize(width, height); this.peer.setContentSize(width, height);
}, }
getText() { getText() {
return this.peer.getText(); return this.peer.getText();
}, }
setFont(font, size, style, weight) { setFont(font, size, style, weight) {
this.peer.setFont(font, size, style, weight); this.peer.setFont(font, size, style, weight);
}, }
setColor(color) { setColor(color) {
this.peer.setColor(color); this.peer.setColor(color);
}, }
getColor() { getColor() {
return this.peer.getColor(); return this.peer.getColor();
}, }
setStyle(style) { setStyle(style) {
this.peer.setStyle(style); this.peer.setStyle(style);
}, }
setWeight(weight) { setWeight(weight) {
this.peer.setWeight(weight); this.peer.setWeight(weight);
}, }
setFontFamily(family) { setFontFamily(family) {
this.peer.setFontFamily(family); this.peer.setFontFamily(family);
}, }
getFont() { getFont() {
return this.peer.getFont(); return this.peer.getFont();
}, }
setSize(size) { setSize(size) {
this.peer.setSize(size); this.peer.setSize(size);
}, }
getHtmlFontSize() { getHtmlFontSize() {
return this.peer.getHtmlFontSize(); return this.peer.getHtmlFontSize();
}, }
getWidth() { getWidth() {
return this.peer.getWidth(); return this.peer.getWidth();
}, }
getHeight() { getHeight() {
return parseInt(this.peer.getHeight(), 10); return parseInt(this.peer.getHeight(), 10);
}, }
getFontHeight() { getFontHeight() {
const lines = this.peer.getText().split('\n').length; const lines = this.peer.getText().split('\n').length;
return Math.round(this.getHeight() / lines); return Math.round(this.getHeight() / lines);
}, }
}); }
export default Text; export default Text;

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import Element from './Element'; import Element from './Element';
import Toolkit from './Toolkit'; import Toolkit from './Toolkit';
const core = coreJs();
const Workspace = new Class({ const Workspace = new Class({
Extends: Element, Extends: Element,
initialize(attributes) { initialize(attributes) {
@ -52,7 +50,7 @@ const Workspace = new Class({
* Appends an element as a child to the object. * Appends an element as a child to the object.
*/ */
append(element) { append(element) {
if (!core.Function.$defined(element)) { if (!$defined(element)) {
throw new Error('Child element can not be null'); throw new Error('Child element can not be null');
} }
const elementType = element.getType(); const elementType = element.getType();
@ -68,7 +66,7 @@ const Workspace = new Class({
}, },
addItAsChildTo(element) { addItAsChildTo(element) {
if (!core.Function.$defined(element)) { if (!$defined(element)) {
throw new Error('Workspace div container can not be null'); throw new Error('Workspace div container can not be null');
} }
element.append(this._htmlContainer); element.append(this._htmlContainer);
@ -100,11 +98,11 @@ const Workspace = new Class({
*/ */
setSize(width, height) { setSize(width, height) {
// HTML container must have the size of the group element. // HTML container must have the size of the group element.
if (core.Function.$defined(width)) { if ($defined(width)) {
this._htmlContainer.css('width', width); this._htmlContainer.css('width', width);
} }
if (core.Function.$defined(height)) { if ($defined(height)) {
this._htmlContainer.css('height', height); this._htmlContainer.css('height', height);
} }
this.peer.setSize(width, height); this.peer.setSize(width, height);
@ -183,7 +181,7 @@ const Workspace = new Class({
* Remove an element as a child to the object. * Remove an element as a child to the object.
*/ */
removeChild(element) { removeChild(element) {
if (!core.Function.$defined(element)) { if (!$defined(element)) {
throw new Error('Child element can not be null'); throw new Error('Child element can not be null');
} }

View File

@ -1,23 +0,0 @@
/*
* Copyright [2021] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const web2d = {};
web2d.peer = {
svg: {},
};
web2d.peer.utils = {};

View File

@ -15,12 +15,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js';
import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
import Point from '../../Point'; import Point from '../../Point';
const core = coreJs();
const ArrowPeer = new Class({ const ArrowPeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -52,10 +51,10 @@ const ArrowPeer = new Class({
setDashed(isDashed, length, spacing) { setDashed(isDashed, length, spacing) {
if ( if (
core.Function.$defined(isDashed) $defined(isDashed)
&& isDashed && isDashed
&& core.Function.$defined(length) && $defined(length)
&& core.Function.$defined(spacing) && $defined(spacing)
) { ) {
this._native.setAttribute('stroke-dasharray', `${length},${spacing}`); this._native.setAttribute('stroke-dasharray', `${length},${spacing}`);
} else { } else {
@ -79,10 +78,10 @@ const ArrowPeer = new Class({
let xp; let xp;
let yp; let yp;
if ( if (
core.Function.$defined(this._fromPoint.x) $defined(this._fromPoint.x)
&& core.Function.$defined(this._fromPoint.y) && $defined(this._fromPoint.y)
&& core.Function.$defined(this._controlPoint.x) && $defined(this._controlPoint.x)
&& core.Function.$defined(this._controlPoint.y) && $defined(this._controlPoint.y)
) { ) {
if (this._controlPoint.y === 0) this._controlPoint.y = 1; if (this._controlPoint.y === 0) this._controlPoint.y = 1;

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
import Point from '../../Point'; import Point from '../../Point';
const core = coreJs();
const CurvedLinePeer = new Class({ const CurvedLinePeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -38,7 +36,7 @@ const CurvedLinePeer = new Class({
setSrcControlPoint(control) { setSrcControlPoint(control) {
this._customControlPoint_1 = true; this._customControlPoint_1 = true;
const change = this._control1.x !== control.x || this._control1.y !== control.y; const change = this._control1.x !== control.x || this._control1.y !== control.y;
if (core.Function.$defined(control.x)) { if ($defined(control.x)) {
this._control1 = control; this._control1 = control;
this._control1.x = parseInt(this._control1.x, 10); this._control1.x = parseInt(this._control1.x, 10);
this._control1.y = parseInt(this._control1.y, 10); this._control1.y = parseInt(this._control1.y, 10);
@ -49,7 +47,7 @@ const CurvedLinePeer = new Class({
setDestControlPoint(control) { setDestControlPoint(control) {
this._customControlPoint_2 = true; this._customControlPoint_2 = true;
const change = this._control2.x !== control.x || this._control2.y !== control.y; const change = this._control2.x !== control.x || this._control2.y !== control.y;
if (core.Function.$defined(control.x)) { if ($defined(control.x)) {
this._control2 = control; this._control2 = control;
this._control2.x = parseInt(this._control2.x, 10); this._control2.x = parseInt(this._control2.x, 10);
this._control2.y = parseInt(this._control2.y, 10); this._control2.y = parseInt(this._control2.y, 10);
@ -150,10 +148,10 @@ const CurvedLinePeer = new Class({
_updatePath(avoidControlPointFix) { _updatePath(avoidControlPointFix) {
if ( if (
core.Function.$defined(this._x1) $defined(this._x1)
&& core.Function.$defined(this._y1) && $defined(this._y1)
&& core.Function.$defined(this._x2) && $defined(this._x2)
&& core.Function.$defined(this._y2) && $defined(this._y2)
) { ) {
this._calculateAutoControlPoints(avoidControlPointFix); this._calculateAutoControlPoints(avoidControlPointFix);
const path = `M${this._x1},${this._y1} C${this._control1.x + this._x1},${this._control1.y + this._y1 const path = `M${this._x1},${this._y1} C${this._control1.x + this._x1},${this._control1.y + this._y1
@ -209,14 +207,14 @@ const CurvedLinePeer = new Class({
); );
if ( if (
!this._customControlPoint_1 !this._customControlPoint_1
&& !(core.Function.$defined(avoidControlPointFix) && avoidControlPointFix === 0) && !($defined(avoidControlPointFix) && avoidControlPointFix === 0)
) { ) {
this._control1.x = defaultpoints[0].x; this._control1.x = defaultpoints[0].x;
this._control1.y = defaultpoints[0].y; this._control1.y = defaultpoints[0].y;
} }
if ( if (
!this._customControlPoint_2 !this._customControlPoint_2
&& !(core.Function.$defined(avoidControlPointFix) && avoidControlPointFix === 1) && !($defined(avoidControlPointFix) && avoidControlPointFix === 1)
) { ) {
this._control2.x = defaultpoints[1].x; this._control2.x = defaultpoints[1].x;
this._control2.y = defaultpoints[1].y; this._control2.y = defaultpoints[1].y;
@ -224,7 +222,7 @@ const CurvedLinePeer = new Class({
}, },
setDashed(length, spacing) { setDashed(length, spacing) {
if (core.Function.$defined(length) && core.Function.$defined(spacing)) { if ($defined(length) && $defined(spacing)) {
this._native.setAttribute('stroke-dasharray', `${length},${spacing}`); this._native.setAttribute('stroke-dasharray', `${length},${spacing}`);
} else { } else {
this._native.setAttribute('stroke-dasharray', ''); this._native.setAttribute('stroke-dasharray', '');

View File

@ -15,13 +15,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import CoreJS from '@wisemapping/core-js';
import { $assert, $defined } from '@wisemapping/core-js';
import EventUtils from '../utils/EventUtils'; import EventUtils from '../utils/EventUtils';
import TransformUtil from '../utils/TransformUtils'; import TransformUtil from '../utils/TransformUtils';
import Element from '../../Element'; import Element from '../../Element';
const core = CoreJS();
const ElementPeer = new Class({ const ElementPeer = new Class({
initialize(svgElement) { initialize(svgElement) {
this._native = svgElement; this._native = svgElement;
@ -45,7 +44,7 @@ const ElementPeer = new Class({
getChildren() { getChildren() {
let result = this._children; let result = this._children;
if (!core.Function.$defined(result)) { if (!$defined(result)) {
result = []; result = [];
this._children = result; this._children = result;
} }
@ -82,7 +81,7 @@ const ElementPeer = new Class({
const oldLength = children.length; const oldLength = children.length;
children.erase(elementPeer); children.erase(elementPeer);
core.Function.$assert( $assert(
children.length < oldLength, children.length < oldLength,
`element could not be removed:${elementPeer}`, `element could not be removed:${elementPeer}`,
); );
@ -112,12 +111,12 @@ const ElementPeer = new Class({
}, },
setSize(width, height) { setSize(width, height) {
if (core.Function.$defined(width) && this._size.width !== parseInt(width, 10)) { if ($defined(width) && this._size.width !== parseInt(width, 10)) {
this._size.width = parseInt(width, 10); this._size.width = parseInt(width, 10);
this._native.setAttribute('width', parseInt(width, 10)); this._native.setAttribute('width', parseInt(width, 10));
} }
if (core.Function.$defined(height) && this._size.height !== parseInt(height, 10)) { if ($defined(height) && this._size.height !== parseInt(height, 10)) {
this._size.height = parseInt(height, 10); this._size.height = parseInt(height, 10);
this._native.setAttribute('height', parseInt(height, 10)); this._native.setAttribute('height', parseInt(height, 10));
} }
@ -130,10 +129,10 @@ const ElementPeer = new Class({
}, },
setFill(color, opacity) { setFill(color, opacity) {
if (core.Function.$defined(color)) { if ($defined(color)) {
this._native.setAttribute('fill', color); this._native.setAttribute('fill', color);
} }
if (core.Function.$defined(opacity)) { if ($defined(opacity)) {
this._native.setAttribute('fill-opacity', opacity); this._native.setAttribute('fill-opacity', opacity);
} }
}, },
@ -159,13 +158,13 @@ const ElementPeer = new Class({
}, },
setStroke(width, style, color, opacity) { setStroke(width, style, color, opacity) {
if (core.Function.$defined(width)) { if ($defined(width)) {
this._native.setAttribute('stroke-width', `${width}px`); this._native.setAttribute('stroke-width', `${width}px`);
} }
if (core.Function.$defined(color)) { if ($defined(color)) {
this._native.setAttribute('stroke', color); this._native.setAttribute('stroke', color);
} }
if (core.Function.$defined(style)) { if ($defined(style)) {
// Scale the dash array in order to be equal to VML. In VML, stroke style doesn't scale. // Scale the dash array in order to be equal to VML. In VML, stroke style doesn't scale.
const dashArrayPoints = this.__stokeStyleToStrokDasharray[style]; const dashArrayPoints = this.__stokeStyleToStrokDasharray[style];
const scale = 1 / TransformUtil.workoutScale(this).width; const scale = 1 / TransformUtil.workoutScale(this).width;
@ -186,7 +185,7 @@ const ElementPeer = new Class({
this._stokeStyle = style; this._stokeStyle = style;
} }
if (core.Function.$defined(opacity)) { if ($defined(opacity)) {
this._native.setAttribute('stroke-opacity', opacity); this._native.setAttribute('stroke-opacity', opacity);
} }
}, },
@ -214,7 +213,7 @@ const ElementPeer = new Class({
attachChangeEventListener(type, listener) { attachChangeEventListener(type, listener) {
const listeners = this.getChangeEventListeners(type); const listeners = this.getChangeEventListeners(type);
if (!core.Function.$defined(listener)) { if (!$defined(listener)) {
throw new Error('Listener can not be null'); throw new Error('Listener can not be null');
} }
listeners.push(listener); listeners.push(listener);
@ -222,7 +221,7 @@ const ElementPeer = new Class({
getChangeEventListeners(type) { getChangeEventListeners(type) {
let listeners = this._changeListeners[type]; let listeners = this._changeListeners[type];
if (!core.Function.$defined(listeners)) { if (!$defined(listeners)) {
listeners = []; listeners = [];
this._changeListeners[type] = listeners; this._changeListeners[type] = listeners;
} }

View File

@ -15,11 +15,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
const core = coreJs();
const ElipsePeer = new Class({ const ElipsePeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -31,11 +29,11 @@ const ElipsePeer = new Class({
setSize(width, height) { setSize(width, height) {
this.parent(width, height); this.parent(width, height);
if (core.Function.$defined(width)) { if ($defined(width)) {
this._native.setAttribute('rx', width / 2); this._native.setAttribute('rx', width / 2);
} }
if (core.Function.$defined(height)) { if ($defined(height)) {
this._native.setAttribute('ry', height / 2); this._native.setAttribute('ry', height / 2);
} }
@ -49,11 +47,11 @@ const ElipsePeer = new Class({
const cx = (size.width / 2) + pcx; const cx = (size.width / 2) + pcx;
const cy = (size.height / 2) + pcy; const cy = (size.height / 2) + pcy;
if (core.Function.$defined(cx)) { if ($defined(cx)) {
this._native.setAttribute('cx', cx); this._native.setAttribute('cx', cx);
} }
if (core.Function.$defined(cy)) { if ($defined(cy)) {
this._native.setAttribute('cy', cy); this._native.setAttribute('cy', cy);
} }
}, },

View File

@ -15,9 +15,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import CoreJS from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
const core = CoreJS();
const Font = new Class({ const Font = new Class({
initialize() { initialize() {
@ -27,13 +25,13 @@ const Font = new Class({
}, },
init(args) { init(args) {
if (core.Function.$defined(args.size)) { if ($defined(args.size)) {
this._size = parseInt(args.size, 10); this._size = parseInt(args.size, 10);
} }
if (core.Function.$defined(args.style)) { if ($defined(args.style)) {
this._style = args.style; this._style = args.style;
} }
if (core.Function.$defined(args.weight)) { if ($defined(args.weight)) {
this._weight = args.weight; this._weight = args.weight;
} }
}, },

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
import EventUtils from '../utils/EventUtils'; import EventUtils from '../utils/EventUtils';
const core = coreJs();
const GroupPeer = new Class({ const GroupPeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -103,11 +101,11 @@ const GroupPeer = new Class({
setCoordOrigin(x, y) { setCoordOrigin(x, y) {
const change = x !== this._coordOrigin.x || y !== this._coordOrigin.y; const change = x !== this._coordOrigin.x || y !== this._coordOrigin.y;
if (core.Function.$defined(x)) { if ($defined(x)) {
this._coordOrigin.x = x; this._coordOrigin.x = x;
} }
if (core.Function.$defined(y)) { if ($defined(y)) {
this._coordOrigin.y = y; this._coordOrigin.y = y;
} }
if (change) { if (change) {
@ -125,11 +123,11 @@ const GroupPeer = new Class({
setPosition(x, y) { setPosition(x, y) {
const change = x !== this._position.x || y !== this._position.y; const change = x !== this._position.x || y !== this._position.y;
if (core.Function.$defined(x)) { if ($defined(x)) {
this._position.x = parseInt(x, 10); this._position.x = parseInt(x, 10);
} }
if (core.Function.$defined(y)) { if ($defined(y)) {
this._position.y = parseInt(y, 10); this._position.y = parseInt(y, 10);
} }
if (change) { if (change) {

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
import Point from '../../Point'; import Point from '../../Point';
const core = coreJs();
const LinePeer = new Class({ const LinePeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -55,11 +53,11 @@ const LinePeer = new Class({
* http://www.zvon.org/HowTo/Output/howto_jj_svg_27.html?at=marker-end * http://www.zvon.org/HowTo/Output/howto_jj_svg_27.html?at=marker-end
*/ */
setArrowStyle(startStyle, endStyle) { setArrowStyle(startStyle, endStyle) {
if (core.Function.$defined(startStyle)) { if ($defined(startStyle)) {
// Todo: This must be implemented ... // Todo: This must be implemented ...
} }
if (core.Function.$defined(endStyle)) { if ($defined(endStyle)) {
// Todo: This must be implemented ... // Todo: This must be implemented ...
} }
}, },

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import * as PolyLineUtils from '../utils/PolyLineUtils'; import * as PolyLineUtils from '../utils/PolyLineUtils';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
const core = coreJs();
const PolyLinePeer = new Class({ const PolyLinePeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize() { initialize() {
@ -71,10 +69,10 @@ const PolyLinePeer = new Class({
_updateStraightPath() { _updateStraightPath() {
if ( if (
core.Function.$defined(this._x1) $defined(this._x1)
&& core.Function.$defined(this._x2) && $defined(this._x2)
&& core.Function.$defined(this._y1) && $defined(this._y1)
&& core.Function.$defined(this._y2) && $defined(this._y2)
) { ) {
const path = PolyLineUtils.buildStraightPath.call( const path = PolyLineUtils.buildStraightPath.call(
this, this,
@ -94,10 +92,10 @@ const PolyLinePeer = new Class({
const x2 = this._x2; const x2 = this._x2;
const y2 = this._y2; const y2 = this._y2;
if ( if (
core.Function.$defined(x1) $defined(x1)
&& core.Function.$defined(x2) && $defined(x2)
&& core.Function.$defined(y1) && $defined(y1)
&& core.Function.$defined(y2) && $defined(y2)
) { ) {
const diff = x2 - x1; const diff = x2 - x1;
const middlex = diff / 2 + x1; const middlex = diff / 2 + x1;
@ -118,10 +116,10 @@ const PolyLinePeer = new Class({
_updateCurvePath() { _updateCurvePath() {
if ( if (
core.Function.$defined(this._x1) $defined(this._x1)
&& core.Function.$defined(this._x2) && $defined(this._x2)
&& core.Function.$defined(this._y1) && $defined(this._y1)
&& core.Function.$defined(this._y2) && $defined(this._y2)
) { ) {
const path = PolyLineUtils.buildCurvedPath.call( const path = PolyLineUtils.buildCurvedPath.call(
this, this,

View File

@ -15,11 +15,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
const core = coreJs();
/** /**
* http://www.w3.org/TR/SVG/shapes.html#RectElement * http://www.w3.org/TR/SVG/shapes.html#RectElement
*/ */
@ -33,10 +31,10 @@ const RectPeer = new Class({
}, },
setPosition(x, y) { setPosition(x, y) {
if (core.Function.$defined(x)) { if ($defined(x)) {
this._native.setAttribute('x', parseInt(x, 10)); this._native.setAttribute('x', parseInt(x, 10));
} }
if (core.Function.$defined(y)) { if ($defined(y)) {
this._native.setAttribute('y', parseInt(y, 10)); this._native.setAttribute('y', parseInt(y, 10));
} }
}, },
@ -51,7 +49,7 @@ const RectPeer = new Class({
this.parent(width, height); this.parent(width, height);
const min = width < height ? width : height; const min = width < height ? width : height;
if (core.Function.$defined(this._arc)) { if ($defined(this._arc)) {
// Transform percentages to SVG format. // Transform percentages to SVG format.
const arc = (min / 2) * this._arc; const arc = (min / 2) * this._arc;
this._native.setAttribute('rx', arc); this._native.setAttribute('rx', arc);

View File

@ -15,11 +15,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
const core = coreJs();
const TextPeer = new Class({ const TextPeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize(Font) { initialize(Font) {
@ -39,7 +37,7 @@ const TextPeer = new Class({
}, },
getTextAlignment() { getTextAlignment() {
return core.Function.$defined(this._textAlign) ? this._textAlign : 'left'; return $defined(this._textAlign) ? this._textAlign : 'left';
}, },
setText(text) { setText(text) {
@ -86,16 +84,16 @@ const TextPeer = new Class({
}, },
setFont(font, size, style, weight) { setFont(font, size, style, weight) {
if (core.Function.$defined(font)) { if ($defined(font)) {
this._font = new this.Font(font, this); this._font = new this.Font(font, this);
} }
if (core.Function.$defined(style)) { if ($defined(style)) {
this._font.setStyle(style); this._font.setStyle(style);
} }
if (core.Function.$defined(weight)) { if ($defined(weight)) {
this._font.setWeight(weight); this._font.setWeight(weight);
} }
if (core.Function.$defined(size)) { if ($defined(size)) {
this._font.setSize(size); this._font.setSize(size);
} }
this._updateFontStyle(); this._updateFontStyle();

View File

@ -15,12 +15,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import coreJs from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
import ElementPeer from './ElementPeer'; import ElementPeer from './ElementPeer';
import EventUtils from '../utils/EventUtils'; import EventUtils from '../utils/EventUtils';
const core = coreJs();
const WorkspacePeer = new Class({ const WorkspacePeer = new Class({
Extends: ElementPeer, Extends: ElementPeer,
initialize(element) { initialize(element) {
@ -58,11 +56,11 @@ const WorkspacePeer = new Class({
if (viewBox != null) { if (viewBox != null) {
coords = viewBox.split(/ /); coords = viewBox.split(/ /);
} }
if (core.Function.$defined(width)) { if ($defined(width)) {
coords[2] = width; coords[2] = width;
} }
if (core.Function.$defined(height)) { if ($defined(height)) {
coords[3] = height; coords[3] = height;
} }
@ -89,11 +87,11 @@ const WorkspacePeer = new Class({
coords = viewBox.split(/ /); coords = viewBox.split(/ /);
} }
if (core.Function.$defined(x)) { if ($defined(x)) {
coords[0] = x; coords[0] = x;
} }
if (core.Function.$defined(y)) { if ($defined(y)) {
coords[1] = y; coords[1] = y;
} }

View File

@ -15,14 +15,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import CoreJS from '@wisemapping/core-js'; import { $defined } from '@wisemapping/core-js';
const core = CoreJS();
const EventUtils = { const EventUtils = {
broadcastChangeEvent(elementPeer, type) { broadcastChangeEvent(elementPeer, type) {
const listeners = elementPeer.getChangeEventListeners(type); const listeners = elementPeer.getChangeEventListeners(type);
if (core.Function.$defined(listeners)) { if ($defined(listeners)) {
for (let i = 0; i < listeners.length; i++) { for (let i = 0; i < listeners.length; i++) {
const listener = listeners[i]; const listener = listeners[i];
listener.call(elementPeer, null); listener.call(elementPeer, null);