(INCOMPLETE: ES6 Module conversion and linting)

- Breaking change: Require `new` with `EmbeddedSVGEdit` (allows us to use `class` internally)
- Breaking change: If `svgcanvas.setUiStrings` must now be called if not using editor in order
    to get strings (for sake of i18n) (and if using path.js alone, must also have its `setUiStrings` called)
- Breaking change (ext-overview-window): Avoid global `overviewWindowGlobals`
- Breaking change (ext-imagelib): Change to object-based encoding for namespacing of
    messages (though keep stringifying/parsing ourselves until we remove IE9 support)
- Breaking change: Rename `jquery.js` to `jquery.min.js`
- Breaking change: Remove `scoped` attribute from `style`; it is now deprecated and
    obsolete; also move to head (after other stylesheets)
- Enhancement: Make SpinButton plugin independent of SVGEdit via
    generic state object for tool_scale
- Enhancement: Remove now unused Python l10n scripts (#238)
- Enhancement: ES6 Modules (including jQuery plugins but not jQuery)
- Enhancement: Further JSDoc (incomplete)
- Enhancement (Optimization): Compress images using imageoptim (and add
    npm script) (per #215)
- Fix: i18nize path.js strings and canvas notifications
- Fix: Attempt i18n for ext-markers
- Refactoring (ext-storage): Move locale info to own file imported by the extension (toward modularity; still should be split into separate files by language and *dynamically* imported, but we'll wait for better `import` support to refactor this)
- Refactoring: For imagelib, add local jQuery copy (using old 1.4.4 as had
    been using from server)
- Refactoring: For MathJax, add local copy (using old 2.3 as had been using from
    server); server had not been working
- Refactoring: Remove `use strict` (implicit in modules)
- Refactoring: Remove trailing whitespace, fix some code within comments
- Refactoring: Expect `jQuery` global rather than `$` for better modularity
    (also to adapt line later once available via `import`)
- Refactoring: Prefer `const` (and then `let`)
- Refactoring: Add block scope keywords closer to first block in which they appear
- Refactoring: Use ES6 `class`
- Refactoring `$.isArray` -> `Array.isArray` and avoid some other jQuery core methods
    with simple VanillaJS replacements
- Refactoring: Use abbreviated object property syntax
- Refactoring: Object destructuring
- Refactoring: Remove `uiStrings` contents in svg-editor.js (obtains from locale)
- Refactoring: Add favicon to embedded API file
- Refactoring: Use arrow functions for brief functions (incomplete)
- Refactoring: Use `Array.prototype.includes`/`String.prototype.includes`;
    `String.prototype.startsWith`, `String.prototype.trim`
- Refactoring: Remove now unnecessary svgutils do/while resetting of variables
- Refactoring: Use shorthand methods for object literals (avoid ": function")
- Refactoring: Avoid quoting object property keys where unnecessary
- Refactoring: Just do truthy/falsey check for lengths in place of comparison to 0
- Refactoring (Testing): Avoid jQuery usage within most test files (defer script,
    also in preparation for future switch to ES6 modules for tests)
- Refactoring: Make jpicker variable declaration indent bearable
- Refactoring (Linting): Finish svgcanvas.js
- Docs: Mention in comment no longer an entry file as before
- Docs: Migrate old config, extensions, and FAQ docs
- Licensing: Indicate MIT is license type of rgbcolor; rename/add license file name for
    jgraduate and screencast to reflect type (Apache 2.0); rename file to reflect it
    contains license information (of type MIT) for Raphael icons
This commit is contained in:
Brett Zamir
2018-05-18 11:25:45 +08:00
parent 7cf976cfb8
commit ae2394f086
249 changed files with 24738 additions and 23260 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,10 @@
/* eslint-disable no-var */
/**
* A class to parse color values
* @author Stoyan Stefanov <sstoo@gmail.com>
* @link https://www.phpied.com/rgb-color-parser-in-javascript/
* @license Use it if you like it
* @license MIT
*/
function RGBColor (colorString) { // eslint-disable-line no-unused-vars
'use strict';
export default function RGBColor (colorString) {
this.ok = false;
// strip any leading #
@@ -19,7 +17,7 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
// before getting into regexps, try simple matches
// and overwrite the input
var simpleColors = {
const simpleColors = {
aliceblue: 'f0f8ff',
antiquewhite: 'faebd7',
aqua: '00ffff',
@@ -164,8 +162,7 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
yellow: 'ffff00',
yellowgreen: '9acd32'
};
var key;
for (key in simpleColors) {
for (const key in simpleColors) {
if (simpleColors.hasOwnProperty(key)) {
if (colorString === key) {
colorString = simpleColors[key];
@@ -175,11 +172,11 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
// emd of simple type-in colors
// array of color definition objects
var colorDefs = [
const colorDefs = [
{
re: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
example: ['rgb(123, 234, 45)', 'rgb(255,234,245)'],
process: function (bits) {
process (bits) {
return [
parseInt(bits[1], 10),
parseInt(bits[2], 10),
@@ -190,7 +187,7 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
{
re: /^(\w{2})(\w{2})(\w{2})$/,
example: ['#00ff00', '336699'],
process: function (bits) {
process (bits) {
return [
parseInt(bits[1], 16),
parseInt(bits[2], 16),
@@ -201,7 +198,7 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
{
re: /^(\w{1})(\w{1})(\w{1})$/,
example: ['#fb0', 'f0f'],
process: function (bits) {
process (bits) {
return [
parseInt(bits[1] + bits[1], 16),
parseInt(bits[2] + bits[2], 16),
@@ -211,14 +208,13 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
}
];
var i;
// search through the definitions to find a match
for (i = 0; i < colorDefs.length; i++) {
var re = colorDefs[i].re;
var processor = colorDefs[i].process;
var bits = re.exec(colorString);
for (let i = 0; i < colorDefs.length; i++) {
const {re} = colorDefs[i];
const processor = colorDefs[i].process;
const bits = re.exec(colorString);
if (bits) {
var channels = processor(bits);
const channels = processor(bits);
this.r = channels[0];
this.g = channels[1];
this.b = channels[2];
@@ -236,9 +232,9 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
};
this.toHex = function () {
var r = this.r.toString(16);
var g = this.g.toString(16);
var b = this.b.toString(16);
let r = this.r.toString(16);
let g = this.g.toString(16);
let b = this.b.toString(16);
if (r.length === 1) { r = '0' + r; }
if (g.length === 1) { g = '0' + g; }
if (b.length === 1) { b = '0' + b; }
@@ -247,30 +243,28 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
// help
this.getHelpXML = function () {
var i, j;
var examples = [];
const examples = [];
// add regexps
for (i = 0; i < colorDefs.length; i++) {
var example = colorDefs[i].example;
for (j = 0; j < example.length; j++) {
for (let i = 0; i < colorDefs.length; i++) {
const {example} = colorDefs[i];
for (let j = 0; j < example.length; j++) {
examples[examples.length] = example[j];
}
}
// add type-in colors
var sc;
for (sc in simpleColors) {
for (const sc in simpleColors) {
if (simpleColors.hasOwnProperty(sc)) {
examples[examples.length] = sc;
}
}
var xml = document.createElement('ul');
const xml = document.createElement('ul');
xml.setAttribute('id', 'rgbcolor-examples');
for (i = 0; i < examples.length; i++) {
for (let i = 0; i < examples.length; i++) {
try {
var listItem = document.createElement('li');
var listColor = new RGBColor(examples[i]);
var exampleDiv = document.createElement('div');
const listItem = document.createElement('li');
const listColor = new RGBColor(examples[i]);
const exampleDiv = document.createElement('div');
exampleDiv.style.cssText =
'margin: 3px; ' +
'border: 1px solid black; ' +
@@ -278,7 +272,7 @@ function RGBColor (colorString) { // eslint-disable-line no-unused-vars
'color:' + listColor.toHex()
;
exampleDiv.appendChild(document.createTextNode('test'));
var listItemValue = document.createTextNode(
const listItemValue = document.createTextNode(
' ' + examples[i] + ' -> ' + listColor.toRGB() + ' -> ' + listColor.toHex()
);
listItem.appendChild(exampleDiv);