- Refactoring: Use static keyword for classes
This commit is contained in:
@@ -238,42 +238,42 @@ export default class RGBColor {
|
||||
if (b.length === 1) { b = '0' + b; }
|
||||
return '#' + r + g + b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Offers a bulleted list of help.
|
||||
* @returns {HTMLUListElement}
|
||||
*/
|
||||
static getHelpXML () {
|
||||
const examples = [
|
||||
// add regexps
|
||||
...colorDefs.flatMap(({example}) => {
|
||||
return example;
|
||||
}),
|
||||
// add type-in colors
|
||||
...Object.keys(simpleColors)
|
||||
];
|
||||
|
||||
const xml = document.createElement('ul');
|
||||
xml.setAttribute('id', 'rgbcolor-examples');
|
||||
|
||||
xml.append(...examples.map((example) => {
|
||||
try {
|
||||
const listItem = document.createElement('li');
|
||||
const listColor = new RGBColor(example);
|
||||
const exampleDiv = document.createElement('div');
|
||||
exampleDiv.style.cssText = `
|
||||
margin: 3px;
|
||||
border: 1px solid black;
|
||||
background: ${listColor.toHex()};
|
||||
color: ${listColor.toHex()};`;
|
||||
exampleDiv.append('test');
|
||||
const listItemValue = ` ${example} -> ${listColor.toRGB()} -> ${listColor.toHex()}`;
|
||||
listItem.append(exampleDiv, listItemValue);
|
||||
return listItem;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}));
|
||||
return xml;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Offers a bulleted list of help.
|
||||
* @returns {HTMLUListElement}
|
||||
*/
|
||||
RGBColor.getHelpXML = function () {
|
||||
const examples = [
|
||||
// add regexps
|
||||
...colorDefs.flatMap(({example}) => {
|
||||
return example;
|
||||
}),
|
||||
// add type-in colors
|
||||
...Object.keys(simpleColors)
|
||||
];
|
||||
|
||||
const xml = document.createElement('ul');
|
||||
xml.setAttribute('id', 'rgbcolor-examples');
|
||||
|
||||
xml.append(...examples.map((example) => {
|
||||
try {
|
||||
const listItem = document.createElement('li');
|
||||
const listColor = new RGBColor(example);
|
||||
const exampleDiv = document.createElement('div');
|
||||
exampleDiv.style.cssText = `
|
||||
margin: 3px;
|
||||
border: 1px solid black;
|
||||
background: ${listColor.toHex()};
|
||||
color: ${listColor.toHex()};`;
|
||||
exampleDiv.append('test');
|
||||
const listItemValue = ` ${example} -> ${listColor.toRGB()} -> ${listColor.toHex()}`;
|
||||
listItem.append(exampleDiv, listItemValue);
|
||||
return listItem;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}));
|
||||
return xml;
|
||||
};
|
||||
|
||||
@@ -1305,32 +1305,33 @@ export class Path {
|
||||
const closedSubpath = Path.subpathIsClosed(this.selected_pts[0]);
|
||||
editorContext_.addPtsToSelection({grips, closedSubpath});
|
||||
}
|
||||
|
||||
// STATIC
|
||||
/**
|
||||
* @param {Integer} index
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static subpathIsClosed (index) {
|
||||
let clsd = false;
|
||||
// Check if subpath is already open
|
||||
path.eachSeg(function (i) {
|
||||
if (i <= index) { return true; }
|
||||
if (this.type === 2) {
|
||||
// Found M first, so open
|
||||
return false;
|
||||
}
|
||||
if (this.type === 1) {
|
||||
// Found Z first, so closed
|
||||
clsd = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return clsd;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Integer} index
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Path.subpathIsClosed = function (index) {
|
||||
let clsd = false;
|
||||
// Check if subpath is already open
|
||||
path.eachSeg(function (i) {
|
||||
if (i <= index) { return true; }
|
||||
if (this.type === 2) {
|
||||
// Found M first, so open
|
||||
return false;
|
||||
}
|
||||
if (this.type === 1) {
|
||||
// Found Z first, so closed
|
||||
clsd = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return clsd;
|
||||
};
|
||||
|
||||
/**
|
||||
* @function module:path.getPath_
|
||||
* @param {SVGPathElement} elem
|
||||
|
||||
@@ -236,24 +236,26 @@ export class Selector {
|
||||
mgr.rotateGrip.setAttribute('cy', nbay - (gripRadius * 5));
|
||||
// }
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Updates cursors for corner grips on rotation so arrows point the right way.
|
||||
* @param {Float} angle - Current rotation angle in degrees
|
||||
* @returns {void}
|
||||
*/
|
||||
Selector.updateGripCursors = function (angle) {
|
||||
const dirArr = Object.keys(selectorManager_.selectorGrips);
|
||||
let steps = Math.round(angle / 45);
|
||||
if (steps < 0) { steps += 8; }
|
||||
while (steps > 0) {
|
||||
dirArr.push(dirArr.shift());
|
||||
steps--;
|
||||
|
||||
// STATIC methods
|
||||
/**
|
||||
* Updates cursors for corner grips on rotation so arrows point the right way.
|
||||
* @param {Float} angle - Current rotation angle in degrees
|
||||
* @returns {void}
|
||||
*/
|
||||
static updateGripCursors (angle) {
|
||||
const dirArr = Object.keys(selectorManager_.selectorGrips);
|
||||
let steps = Math.round(angle / 45);
|
||||
if (steps < 0) { steps += 8; }
|
||||
while (steps > 0) {
|
||||
dirArr.push(dirArr.shift());
|
||||
steps--;
|
||||
}
|
||||
Object.values(selectorManager_.selectorGrips).forEach((gripElement, i) => {
|
||||
gripElement.setAttribute('style', ('cursor:' + dirArr[i] + '-resize'));
|
||||
});
|
||||
}
|
||||
Object.values(selectorManager_.selectorGrips).forEach((gripElement, i) => {
|
||||
gripElement.setAttribute('style', ('cursor:' + dirArr[i] + '-resize'));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage all selector objects (selection boxes).
|
||||
|
||||
@@ -922,6 +922,21 @@ if (!('SVGPathSegList' in window) || !('appendItem' in window.SVGPathSegList.pro
|
||||
|
||||
return builder.pathSegList;
|
||||
}
|
||||
|
||||
// STATIC
|
||||
static _pathSegArrayAsString (pathSegArray) {
|
||||
let string = '';
|
||||
let first = true;
|
||||
pathSegArray.forEach((pathSeg) => {
|
||||
if (first) {
|
||||
first = false;
|
||||
string += pathSeg._asPathString();
|
||||
} else {
|
||||
string += ' ' + pathSeg._asPathString();
|
||||
}
|
||||
});
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
||||
SVGPathSegList.prototype.classname = 'SVGPathSegList';
|
||||
@@ -934,20 +949,6 @@ if (!('SVGPathSegList' in window) || !('appendItem' in window.SVGPathSegList.pro
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
SVGPathSegList._pathSegArrayAsString = function (pathSegArray) {
|
||||
let string = '';
|
||||
let first = true;
|
||||
pathSegArray.forEach((pathSeg) => {
|
||||
if (first) {
|
||||
first = false;
|
||||
string += pathSeg._asPathString();
|
||||
} else {
|
||||
string += ' ' + pathSeg._asPathString();
|
||||
}
|
||||
});
|
||||
return string;
|
||||
};
|
||||
|
||||
// Add the pathSegList accessors to SVGPathElement.
|
||||
// Spec: https://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGAnimatedPathData
|
||||
Object.defineProperties(SVGPathElement.prototype, {
|
||||
|
||||
@@ -120,7 +120,7 @@ let listMap_ = {};
|
||||
* implementing as much of SVGTransformList that we need to get the job done.
|
||||
* @implements {module:SVGTransformList.SVGEditTransformList}
|
||||
*/
|
||||
export class SVGTransformList {// eslint-disable-line no-shadow
|
||||
export class SVGTransformList { // eslint-disable-line no-shadow
|
||||
/**
|
||||
* @param {Element} elem
|
||||
*/
|
||||
|
||||
@@ -2562,6 +2562,22 @@
|
||||
}
|
||||
|
||||
return builder.pathSegList;
|
||||
} // STATIC
|
||||
|
||||
}], [{
|
||||
key: "_pathSegArrayAsString",
|
||||
value: function _pathSegArrayAsString(pathSegArray) {
|
||||
var string = '';
|
||||
var first = true;
|
||||
pathSegArray.forEach(function (pathSeg) {
|
||||
if (first) {
|
||||
first = false;
|
||||
string += pathSeg._asPathString();
|
||||
} else {
|
||||
string += ' ' + pathSeg._asPathString();
|
||||
}
|
||||
});
|
||||
return string;
|
||||
}
|
||||
}]);
|
||||
|
||||
@@ -2576,24 +2592,9 @@
|
||||
return this._list.length;
|
||||
},
|
||||
enumerable: true
|
||||
});
|
||||
|
||||
SVGPathSegList._pathSegArrayAsString = function (pathSegArray) {
|
||||
var string = '';
|
||||
var first = true;
|
||||
pathSegArray.forEach(function (pathSeg) {
|
||||
if (first) {
|
||||
first = false;
|
||||
string += pathSeg._asPathString();
|
||||
} else {
|
||||
string += ' ' + pathSeg._asPathString();
|
||||
}
|
||||
});
|
||||
return string;
|
||||
}; // Add the pathSegList accessors to SVGPathElement.
|
||||
}); // Add the pathSegList accessors to SVGPathElement.
|
||||
// Spec: https://www.w3.org/TR/SVG11/single-page.html#paths-InterfaceSVGAnimatedPathData
|
||||
|
||||
|
||||
Object.defineProperties(SVGPathElement.prototype, {
|
||||
pathSegList: {
|
||||
get: function get() {
|
||||
@@ -6319,46 +6320,48 @@
|
||||
grips: grips,
|
||||
closedSubpath: closedSubpath
|
||||
});
|
||||
} // STATIC
|
||||
|
||||
/**
|
||||
* @param {Integer} index
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
}], [{
|
||||
key: "subpathIsClosed",
|
||||
value: function subpathIsClosed(index) {
|
||||
var clsd = false; // Check if subpath is already open
|
||||
|
||||
path.eachSeg(function (i) {
|
||||
if (i <= index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.type === 2) {
|
||||
// Found M first, so open
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.type === 1) {
|
||||
// Found Z first, so closed
|
||||
clsd = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
return clsd;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Path;
|
||||
}();
|
||||
/**
|
||||
* @param {Integer} index
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
Path.subpathIsClosed = function (index) {
|
||||
var clsd = false; // Check if subpath is already open
|
||||
|
||||
path.eachSeg(function (i) {
|
||||
if (i <= index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.type === 2) {
|
||||
// Found M first, so open
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.type === 1) {
|
||||
// Found Z first, so closed
|
||||
clsd = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
return clsd;
|
||||
};
|
||||
/**
|
||||
* @function module:path.getPath_
|
||||
* @param {SVGPathElement} elem
|
||||
* @returns {module:path.Path}
|
||||
*/
|
||||
|
||||
|
||||
var getPath_ = function getPath_(elem) {
|
||||
var p = pathData[elem.id];
|
||||
|
||||
@@ -13163,39 +13166,41 @@
|
||||
mgr.rotateGripConnector.setAttribute('y2', nbay - gripRadius * 5);
|
||||
mgr.rotateGrip.setAttribute('cx', nbax + nbaw / 2);
|
||||
mgr.rotateGrip.setAttribute('cy', nbay - gripRadius * 5); // }
|
||||
} // STATIC methods
|
||||
|
||||
/**
|
||||
* Updates cursors for corner grips on rotation so arrows point the right way.
|
||||
* @param {Float} angle - Current rotation angle in degrees
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
}], [{
|
||||
key: "updateGripCursors",
|
||||
value: function updateGripCursors(angle) {
|
||||
var dirArr = Object.keys(selectorManager_.selectorGrips);
|
||||
var steps = Math.round(angle / 45);
|
||||
|
||||
if (steps < 0) {
|
||||
steps += 8;
|
||||
}
|
||||
|
||||
while (steps > 0) {
|
||||
dirArr.push(dirArr.shift());
|
||||
steps--;
|
||||
}
|
||||
|
||||
Object.values(selectorManager_.selectorGrips).forEach(function (gripElement, i) {
|
||||
gripElement.setAttribute('style', 'cursor:' + dirArr[i] + '-resize');
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return Selector;
|
||||
}();
|
||||
/**
|
||||
* Updates cursors for corner grips on rotation so arrows point the right way.
|
||||
* @param {Float} angle - Current rotation angle in degrees
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
Selector.updateGripCursors = function (angle) {
|
||||
var dirArr = Object.keys(selectorManager_.selectorGrips);
|
||||
var steps = Math.round(angle / 45);
|
||||
|
||||
if (steps < 0) {
|
||||
steps += 8;
|
||||
}
|
||||
|
||||
while (steps > 0) {
|
||||
dirArr.push(dirArr.shift());
|
||||
steps--;
|
||||
}
|
||||
|
||||
Object.values(selectorManager_.selectorGrips).forEach(function (gripElement, i) {
|
||||
gripElement.setAttribute('style', 'cursor:' + dirArr[i] + '-resize');
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Manage all selector objects (selection boxes).
|
||||
*/
|
||||
|
||||
|
||||
var SelectorManager =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
|
||||
Reference in New Issue
Block a user