diff --git a/.eslintignore b/.eslintignore index 8cfe15d9..fe24ce3b 100644 --- a/.eslintignore +++ b/.eslintignore @@ -30,3 +30,7 @@ src/editor/jspdf/underscore-min.js src/editor/extensions/ext-mathjax/mathjax +# jquery files +src/editor/svgicons/jQuery.svgIcons.js +src/editor/jgraduate/jQuery.jPicker.js + diff --git a/badges/coverage-badge.svg b/badges/coverage-badge.svg index eeec4ddc..fe2f3cfd 100644 --- a/badges/coverage-badge.svg +++ b/badges/coverage-badge.svg @@ -1 +1 @@ -Statements 51.1%Statements 51.1%Branches 40.83%Branches 40.83%Lines 51.81%Lines 51.81%Functions 58.62%Functions 58.62% +Statements 52.84%Statements 52.84%Branches 41.67%Branches 41.67%Lines 53.65%Lines 53.65%Functions 60.18%Functions 60.18% diff --git a/badges/tests-badge.svg b/badges/tests-badge.svg index ecc8fc46..61b3e08c 100644 --- a/badges/tests-badge.svg +++ b/badges/tests-badge.svg @@ -1 +1 @@ -TestsTests139/139139/139 \ No newline at end of file +TestsTests141/141141/141 \ No newline at end of file diff --git a/cypress/integration/ui/__snapshots__/scenario.js.snap b/cypress/integration/ui/__snapshots__/scenario.js.snap index 21aa0bf8..3636cb70 100644 --- a/cypress/integration/ui/__snapshots__/scenario.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario.js.snap @@ -221,6 +221,7 @@ exports[`use various parts of svg-edit > check tool_italic #0`] = ` fill-opacity="1" stroke-opacity="1" id="svg_2" + transform="matrix(1 0 0 1 0 0)" > B @@ -285,6 +286,7 @@ exports[`use various parts of svg-edit > check tool_bold #0`] = ` fill-opacity="1" stroke-opacity="1" id="svg_2" + transform="matrix(1 0 0 1 0 0)" > B @@ -349,9 +351,301 @@ exports[`use various parts of svg-edit > check change color #0`] = ` fill-opacity="1" stroke-opacity="1" id="svg_2" + transform="matrix(1 0 0 1 0 0)" > B `; + +exports[`use various parts of svg-edit > check tool_start #0`] = ` + + + Layer 1 + + + B + + + B + + + + + + +`; + +exports[`use various parts of svg-edit > check tool_star #0`] = ` + + + Layer 1 + + + B + + + B + + + + + + +`; + +exports[`use various parts of svg-edit > check tool_polygon #0`] = ` + + + Layer 1 + + + B + + + B + + + + + + + +`; diff --git a/cypress/integration/ui/clipboard.js b/cypress/integration/ui/clipboard.js index a9ba05e9..d9bbb944 100644 --- a/cypress/integration/ui/clipboard.js +++ b/cypress/integration/ui/clipboard.js @@ -11,13 +11,13 @@ describe('UI - Clipboard', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}') + .type('{selectall}', {force: true}) .type(` Layer 1 - `, {parseSpecialCharSequences: false}); + `, {force: true, parseSpecialCharSequences: false}); cy.get('#tool_source_save').click(); cy.get('#testCircle').should('exist'); cy.get('#svg_1').should('not.exist'); @@ -25,20 +25,20 @@ describe('UI - Clipboard', function () { // Copy. cy.get('#testCircle').click().rightclick(); - cy.get('#cmenu_canvas a[href="#copy"]').click(); + cy.get('#cmenu_canvas a[href="#copy"]').click({force: true}); // Paste. // Scrollbars fail to recenter in Cypress test. Works fine in reality. // Thus forcing click is needed since workspace is mostly offscreen. cy.get('#svgroot').rightclick({force: true}); - cy.get('#cmenu_canvas a[href="#paste"]').click(); + cy.get('#cmenu_canvas a[href="#paste"]').click({force: true}); cy.get('#testCircle').should('exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('not.exist'); // Cut. cy.get('#testCircle').click().rightclick(); - cy.get('#cmenu_canvas a[href="#cut"]').click(); + cy.get('#cmenu_canvas a[href="#cut"]').click({force: true}); cy.get('#testCircle').should('not.exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('not.exist'); @@ -47,16 +47,16 @@ describe('UI - Clipboard', function () { // Scrollbars fail to recenter in Cypress test. Works fine in reality. // Thus forcing click is needed since workspace is mostly offscreen. cy.get('#svgroot').rightclick({force: true}); - cy.get('#cmenu_canvas a[href="#paste"]').click(); + cy.get('#cmenu_canvas a[href="#paste"]').click({force: true}); cy.get('#testCircle').should('not.exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('exist'); // Delete. cy.get('#svg_2').click().rightclick(); - cy.get('#cmenu_canvas a[href="#delete"]').click(); + cy.get('#cmenu_canvas a[href="#delete"]').click({force: true}); cy.get('#svg_1').click().rightclick(); - cy.get('#cmenu_canvas a[href="#delete"]').click(); + cy.get('#cmenu_canvas a[href="#delete"]').click({force: true}); cy.get('#svg_1').should('not.exist'); cy.get('#svg_2').should('not.exist'); }); diff --git a/cypress/integration/ui/control-points.js b/cypress/integration/ui/control-points.js index 593f2f26..993e57f0 100644 --- a/cypress/integration/ui/control-points.js +++ b/cypress/integration/ui/control-points.js @@ -12,11 +12,11 @@ describe('UI - Control Points', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}') + .type('{selectall}', {force: true}) .type(` Layer 1 - + `, {force: true, parseSpecialCharSequences: false}); cy.get('#tool_source_save').click(); diff --git a/cypress/integration/ui/issues/issue-408.js b/cypress/integration/ui/issues/issue-408.js index 66dd222c..47f9a874 100644 --- a/cypress/integration/ui/issues/issue-408.js +++ b/cypress/integration/ui/issues/issue-408.js @@ -11,7 +11,7 @@ describe('Fix issue 408', function () { it('should not throw when showing/saving svg content', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}') + .type('{selectall}', {force: true}) .type(` Layer 1 diff --git a/cypress/integration/ui/scenario.js b/cypress/integration/ui/scenario.js index 47bd5f2a..1d31b3b6 100644 --- a/cypress/integration/ui/scenario.js +++ b/cypress/integration/ui/scenario.js @@ -20,7 +20,7 @@ describe('use various parts of svg-edit', function () { Layer 1 - `, {parseSpecialCharSequences: false}); + `, {force: true, parseSpecialCharSequences: false}); cy.get('#tool_source_save').click({force: true}); testSnapshot(); }); @@ -70,4 +70,22 @@ describe('use various parts of svg-edit', function () { .click({force: true}); testSnapshot(); }); + it('check tool_star', function () { + cy.get('#tool_star') + .click({force: true}); + cy.get('#svgcontent') + .trigger('mousedown', {which: 1, pageX: 600, pageY: 150, force: true}) + .trigger('mousemove', {which: 1, pageX: 600, pageY: 170, force: true}) + .trigger('mouseup', {force: true}); + cy.get('#svgcontent').toMatchSnapshot(); + }); + it('check tool_polygon', function () { + cy.get('#tool_polygon') + .click({force: true}); + cy.get('#svgcontent') + .trigger('mousedown', {which: 1, pageX: 650, pageY: 200, force: true}) + .trigger('mousemove', {which: 1, pageX: 650, pageY: 210, force: true}) + .trigger('mouseup', {force: true}); + cy.get('#svgcontent').toMatchSnapshot(); + }); }); diff --git a/cypress/integration/unit/path.js b/cypress/integration/unit/path.js index e6124129..ae823cc4 100644 --- a/cypress/integration/unit/path.js +++ b/cypress/integration/unit/path.js @@ -6,6 +6,7 @@ import '../../../instrumented/editor/jquery.min.js'; import {NS} from '../../../instrumented/common/namespaces.js'; import * as utilities from '../../../instrumented/common/utilities.js'; import * as pathModule from '../../../instrumented/svgcanvas/path.js'; +import {Path, Segment} from '../../../instrumented/svgcanvas/path-method.js'; import {init as unitsInit} from '../../../instrumented/common/units.js'; describe('path', function () { @@ -50,7 +51,7 @@ describe('path', function () { const [mockPathContext, mockUtilitiesContext] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); - new pathModule.Path(path); // eslint-disable-line no-new + new Path(path); // eslint-disable-line no-new assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L'); assert.equal(path.pathSegList.getItem(1).x, 10); @@ -70,13 +71,13 @@ describe('path', function () { const [mockPathContext, mockUtilitiesContext] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); - new pathModule.Path(path); // eslint-disable-line no-new + new Path(path); // eslint-disable-line no-new assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L'); assert.equal(path.pathSegList.getItem(1).x, 10); assert.equal(path.pathSegList.getItem(1).y, 11); - const segment = new pathModule.Segment(1, path.pathSegList.getItem(1)); + const segment = new Segment(1, path.pathSegList.getItem(1)); segment.setType(SVGPathSeg.PATHSEG_LINETO_REL, [30, 31]); assert.equal(segment.item.pathSegTypeAsLetter, 'l'); assert.equal(segment.item.x, 30); @@ -98,8 +99,8 @@ describe('path', function () { const [mockPathContext, mockUtilitiesContext] = getMockContexts(svg); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); - const segment = new pathModule.Segment(1, path.pathSegList.getItem(1)); - segment.path = new pathModule.Path(path); + const segment = new Segment(1, path.pathSegList.getItem(1)); + segment.path = new Path(path); assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C'); assert.equal(path.pathSegList.getItem(1).x1, 11); @@ -126,13 +127,13 @@ describe('path', function () { const [mockPathContext, mockUtilitiesContext] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); - new pathModule.Path(path); // eslint-disable-line no-new + new Path(path); // eslint-disable-line no-new assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L'); assert.equal(path.pathSegList.getItem(1).x, 10); assert.equal(path.pathSegList.getItem(1).y, 11); - const segment = new pathModule.Segment(1, path.pathSegList.getItem(1)); + const segment = new Segment(1, path.pathSegList.getItem(1)); segment.move(-3, 4); assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'L'); assert.equal(path.pathSegList.getItem(1).x, 7); @@ -146,7 +147,7 @@ describe('path', function () { const [mockPathContext, mockUtilitiesContext] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); - new pathModule.Path(path); // eslint-disable-line no-new + new Path(path); // eslint-disable-line no-new assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C'); assert.equal(path.pathSegList.getItem(1).x1, 11); @@ -156,7 +157,7 @@ describe('path', function () { assert.equal(path.pathSegList.getItem(1).x, 15); assert.equal(path.pathSegList.getItem(1).y, 16); - const segment = new pathModule.Segment(1, path.pathSegList.getItem(1)); + const segment = new Segment(1, path.pathSegList.getItem(1)); segment.moveCtrl(1, 100, -200); assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'C'); assert.equal(path.pathSegList.getItem(1).x1, 111); diff --git a/dist/editor/embedapi.js b/dist/editor/embedapi.js index 4e4af622..4e018cca 100644 --- a/dist/editor/embedapi.js +++ b/dist/editor/embedapi.js @@ -102,7 +102,7 @@ function getMessageListener (t) { * - Have an iframe somewhere pointing to a version of svg-edit > r1000. * @example // Initialize the magic with: -const svgCanvas = new EmbeddedSVGEdit(window.frames.svgedit); +svgCanvas = new EmbeddedSVGEdit(window.frames.svgedit); // Pass functions in this format: svgCanvas.setSvgString('string'); @@ -130,7 +130,7 @@ svgCanvas.setSvgString('string')(function (data, error) { // The only other difference is when handling returns: // the callback notation is used instead. -const blah = new EmbeddedSVGEdit(window.frames.svgedit); +blah = new EmbeddedSVGEdit(window.frames.svgedit); blah.clearSelection('woot', 'blah', 1337, [1, 2, 3, 4, 5, 'moo'], -42, { a: 'tree', b: 6, c: 9 })(function () { console.log('GET DATA', args); }); diff --git a/dist/editor/extensions/ext-arrows/ext-arrows.js b/dist/editor/extensions/ext-arrows/ext-arrows.js index 0d9a0524..d00003d1 100644 --- a/dist/editor/extensions/ext-arrows/ext-arrows.js +++ b/dist/editor/extensions/ext-arrows/ext-arrows.js @@ -1,4 +1,4 @@ -var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var check=function(t){return t&&t.Math==Math&&t},e=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof t&&t)||Function("return this")(),fails=function(t){try{return!!t()}catch(t){return!0}},r=!fails((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),n={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i={f:o&&!n.call({1:2},1)?function propertyIsEnumerable(t){var e=o(this,t);return!!e&&e.enumerable}:n},createPropertyDescriptor=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},a={}.toString,classofRaw=function(t){return a.call(t).slice(8,-1)},c="".split,u=fails((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==classofRaw(t)?c.call(t,""):Object(t)}:Object,requireObjectCoercible=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},toIndexedObject=function(t){return u(requireObjectCoercible(t))},isObject=function(t){return"object"==typeof t?null!==t:"function"==typeof t},toPrimitive=function(t,e){if(!isObject(t))return t;var r,n;if(e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;if("function"==typeof(r=t.valueOf)&&!isObject(n=r.call(t)))return n;if(!e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;throw TypeError("Can't convert object to primitive value")},f={}.hasOwnProperty,has=function(t,e){return f.call(t,e)},l=e.document,s=isObject(l)&&isObject(l.createElement),documentCreateElement=function(t){return s?l.createElement(t):{}},p=!r&&!fails((function(){return 7!=Object.defineProperty(documentCreateElement("div"),"a",{get:function(){return 7}}).a})),h=Object.getOwnPropertyDescriptor,d={f:r?h:function getOwnPropertyDescriptor(t,e){if(t=toIndexedObject(t),e=toPrimitive(e,!0),p)try{return h(t,e)}catch(t){}if(has(t,e))return createPropertyDescriptor(!i.f.call(t,e),t[e])}},anObject=function(t){if(!isObject(t))throw TypeError(String(t)+" is not an object");return t},v=Object.defineProperty,y={f:r?v:function defineProperty(t,e,r){if(anObject(t),e=toPrimitive(e,!0),anObject(r),p)try{return v(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[e]=r.value),t}},g=r?function(t,e,r){return y.f(t,e,createPropertyDescriptor(1,r))}:function(t,e,r){return t[e]=r,t},setGlobal=function(t,r){try{g(e,t,r)}catch(n){e[t]=r}return r},m=e["__core-js_shared__"]||setGlobal("__core-js_shared__",{}),b=Function.toString;"function"!=typeof m.inspectSource&&(m.inspectSource=function(t){return b.call(t)});var w,S,x,E=m.inspectSource,_=e.WeakMap,O="function"==typeof _&&/native code/.test(E(_)),j=createCommonjsModule((function(t){(t.exports=function(t,e){return m[t]||(m[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),k=0,P=Math.random(),uid=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++k+P).toString(36)},A=j("keys"),sharedKey=function(t){return A[t]||(A[t]=uid(t))},T={},I=e.WeakMap;if(O){var L=new I,R=L.get,C=L.has,M=L.set;w=function(t,e){return M.call(L,t,e),e},S=function(t){return R.call(L,t)||{}},x=function(t){return C.call(L,t)}}else{var G=sharedKey("state");T[G]=!0,w=function(t,e){return g(t,G,e),e},S=function(t){return has(t,G)?t[G]:{}},x=function(t){return has(t,G)}}var N,D={set:w,get:S,has:x,enforce:function(t){return x(t)?S(t):w(t,{})},getterFor:function(t){return function(e){var r;if(!isObject(e)||(r=S(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}},U=createCommonjsModule((function(t){var r=D.get,n=D.enforce,o=String(String).split("String");(t.exports=function(t,r,i,a){var c=!!a&&!!a.unsafe,u=!!a&&!!a.enumerable,f=!!a&&!!a.noTargetGet;"function"==typeof i&&("string"!=typeof r||has(i,"name")||g(i,"name",r),n(i).source=o.join("string"==typeof r?r:"")),t!==e?(c?!f&&t[r]&&(u=!0):delete t[r],u?t[r]=i:g(t,r,i)):u?t[r]=i:setGlobal(r,i)})(Function.prototype,"toString",(function toString(){return"function"==typeof this&&r(this).source||E(this)}))})),z=e,aFunction=function(t){return"function"==typeof t?t:void 0},getBuiltIn=function(t,r){return arguments.length<2?aFunction(z[t])||aFunction(e[t]):z[t]&&z[t][r]||e[t]&&e[t][r]},W=Math.ceil,$=Math.floor,toInteger=function(t){return isNaN(t=+t)?0:(t>0?$:W)(t)},B=Math.min,toLength=function(t){return t>0?B(toInteger(t),9007199254740991):0},V=Math.max,Y=Math.min,toAbsoluteIndex=function(t,e){var r=toInteger(t);return r<0?V(r+e,0):Y(r,e)},createMethod=function(t){return function(e,r,n){var o,i=toIndexedObject(e),a=toLength(i.length),c=toAbsoluteIndex(n,a);if(t&&r!=r){for(;a>c;)if((o=i[c++])!=o)return!0}else for(;a>c;c++)if((t||c in i)&&i[c]===r)return t||c||0;return!t&&-1}},q={includes:createMethod(!0),indexOf:createMethod(!1)},H=q.indexOf,objectKeysInternal=function(t,e){var r,n=toIndexedObject(t),o=0,i=[];for(r in n)!has(T,r)&&has(n,r)&&i.push(r);for(;e.length>o;)has(n,r=e[o++])&&(~H(i,r)||i.push(r));return i},K=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],J=K.concat("length","prototype"),X={f:Object.getOwnPropertyNames||function getOwnPropertyNames(t){return objectKeysInternal(t,J)}},Q={f:Object.getOwnPropertySymbols},Z=getBuiltIn("Reflect","ownKeys")||function ownKeys(t){var e=X.f(anObject(t)),r=Q.f;return r?e.concat(r(t)):e},copyConstructorProperties=function(t,e){for(var r=Z(e),n=y.f,o=d.f,i=0;ii;)y.f(t,r=n[i++],e[r]);return t},dt=getBuiltIn("document","documentElement"),vt=sharedKey("IE_PROTO"),EmptyConstructor=function(){},scriptTag=function(t){return"`, */\n // mathjaxSrc = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',\n // Had been on https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG.js\n // Obtained Text-AMS-MML_SVG.js from https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/config/TeX-AMS-MML_SVG.js\n {uiStrings} = svgEditor;\n let\n math,\n locationX,\n locationY,\n mathjaxLoaded = false;\n\n // TODO: Implement language support. Move these uiStrings to the locale files and\n // the code to the langReady callback. Also i18nize alert and HTML below\n $.extend(uiStrings, {\n mathjax: {\n embed_svg: 'Save as mathematics',\n embed_mathml: 'Save as figure',\n svg_save_warning: 'The math will be transformed into a figure is ' +\n 'manipulatable like everything else. You will not be able to ' +\n 'manipulate the TeX-code anymore.',\n mathml_save_warning: 'Advised. The math will be saved as a figure.',\n title: 'Mathematics code editor'\n }\n });\n\n /**\n *\n * @returns {void}\n */\n function saveMath () {\n const code = $('#mathjax_code_textarea').val();\n // displaystyle to force MathJax NOT to use the inline style. Because it is\n // less fancy!\n MathJax.Hub.queue.Push(['Text', math, '\\\\displaystyle{' + code + '}']);\n\n /*\n * The MathJax library doesn't want to bloat your webpage so it creates\n * every symbol (glymph) you need only once. These are saved in a `` on\n * the top of your html document, just under the body tag. Each glymph has\n * its unique id and is saved as a `` in the `` tag of the ``\n *\n * Then when the symbols are needed in the rest of your html document they\n * are refferd to by a `` tag.\n * Because of bug 1076 we can't just grab the defs tag on the top and add it\n * to your formula's `` and copy the lot. So we have to replace each\n * `` tag by its ``.\n */\n MathJax.Hub.queue.Push(\n function () {\n const mathjaxMath = $('.MathJax_SVG');\n const svg = $(mathjaxMath.html());\n svg.find('use').each(function () {\n // TODO: find a less pragmatic and more elegant solution to this.\n const id = $(this).attr('href')\n ? $(this).attr('href').slice(1) // Works in Chrome.\n : $(this).attr('xlink:href').slice(1); // Works in Firefox.\n const glymph = $('#' + id).clone().removeAttr('id');\n const x = $(this).attr('x');\n const y = $(this).attr('y');\n const transform = $(this).attr('transform');\n if (transform && (x || y)) {\n glymph.attr('transform', transform + ' translate(' + x + ',' + y + ')');\n } else if (transform) {\n glymph.attr('transform', transform);\n } else if (x || y) {\n glymph.attr('transform', 'translate(' + x + ',' + y + ')');\n }\n $(this).replaceWith(glymph);\n });\n // Remove the style tag because it interferes with SVG-Edit.\n svg.removeAttr('style');\n svg.attr('xmlns', 'http://www.w3.org/2000/svg');\n svgCanvas.importSvgString($('
').append(svg.clone()).html(), true);\n svgCanvas.ungroupSelectedElement();\n // TODO: To undo the adding of the Formula you now have to undo twice.\n // This should only be once!\n svgCanvas.moveSelectedElements(locationX, locationY, true);\n }\n );\n }\n\n const buttons = [{\n id: 'tool_mathjax',\n type: 'mode',\n icon: 'mathjax.png',\n events: {\n async click () {\n // Set the mode.\n svgCanvas.setMode('mathjax');\n\n // Only load Mathjax when needed, we don't want to strain Svg-Edit any more.\n // From this point on it is very probable that it will be needed, so load it.\n if (mathjaxLoaded === false) {\n $(\n '
' +\n '' +\n '
' +\n '$${}$$' +\n '
' +\n '
' +\n '
' +\n '
' +\n '' +\n '' +\n '
' +\n '
' +\n 'Mathematics Editor' +\n '' +\n '' +\n '
' +\n '
' +\n '
'\n ).insertAfter('#svg_prefs').hide();\n\n // Make the MathEditor draggable.\n $('#mathjax_container').draggable({\n cancel: 'button,fieldset',\n containment: 'window'\n });\n\n // Add functionality and picture to cancel button.\n $('#tool_mathjax_cancel').prepend($.getSvgIcon('cancel', true))\n .on('click touched', function () {\n $('#mathjax').hide();\n });\n\n // Add functionality and picture to the save button.\n $('#tool_mathjax_save').prepend($.getSvgIcon('ok', true))\n .on('click touched', function () {\n saveMath();\n $('#mathjax').hide();\n });\n\n // MathJax preprocessing has to ignore most of the page.\n $('body').addClass('tex2jax_ignore');\n\n try {\n await import('./mathjax/MathJax.min.js'); // ?config=TeX-AMS-MML_SVG.js');\n // When MathJax is loaded get the div where the math will be rendered.\n MathJax.Hub.queue.Push(function () {\n math = MathJax.Hub.getAllJax('#mathjax_creator')[0];\n console.log(math); // eslint-disable-line no-console\n mathjaxLoaded = true;\n console.log('MathJax Loaded'); // eslint-disable-line no-console\n });\n } catch (e) {\n console.log('Failed loading MathJax.'); // eslint-disable-line no-console\n $.alert('Failed loading MathJax. You will not be able to change the mathematics.');\n }\n }\n }\n }\n }];\n\n return {\n name: strings.name,\n svgicons: 'mathjax-icons.xml',\n buttons: strings.buttons.map((button, i) => {\n return Object.assign(buttons[i], button);\n }),\n\n mouseDown () {\n if (svgCanvas.getMode() === 'mathjax') {\n return {started: true};\n }\n return undefined;\n },\n mouseUp (opts) {\n if (svgCanvas.getMode() === 'mathjax') {\n // Get the coordinates from your mouse.\n const zoom = svgCanvas.getZoom();\n // Get the actual coordinate by dividing by the zoom value\n locationX = opts.mouse_x / zoom;\n locationY = opts.mouse_y / zoom;\n\n $('#mathjax').show();\n return {started: false}; // Otherwise the last selected object dissapears.\n }\n return undefined;\n },\n callback () {\n $('').appendTo("head")),e.text(t?" #tool_topath { display: none !important; }":""),o("#polygon_panel").toggle(t)},n=(r=e).canvas,o=t.$,!1,v.next=9,Yn(r.curPrefs.lang);case 9:return i=v.sent,h=[{id:"tool_polygon",icon:"polygon.png",type:"mode",position:11,events:{click:function click(){n.setMode("polygon"),s(!0)}}}],y=[{type:"input",panel:"polygon_panel",id:"polySides",size:3,defval:5,events:{change:function change(){f("sides",this.value)}}}],v.abrupt("return",{name:i.name,svgicons:"polygon-icons.svg",buttons:i.buttons.map((function(t,e){return Object.assign(h[e],t)})),context_tools:i.contextTools.map((function(t,e){return Object.assign(y[e],t)})),callback:function callback(){o("#polygon_panel").hide(),setTimeout((function(){o("#tool_source_save").clone().hide().attr("id","polygon_save").unbind().appendTo("#tool_source_back").click((function(){})),o("#tool_source_cancel").clone().hide().attr("id","polygon_cancel").unbind().appendTo("#tool_source_back").click((function(){}))}),3e3)},mouseDown:function mouseDown(t){if("polygon"===n.getMode()){var e=n.getColor("fill"),r=n.getColor("stroke"),o=n.getStrokeWidth();return c=!0,u=n.addSVGElementFromJson({element:"polygon",attr:{cx:t.start_x,cy:t.start_y,id:n.getNextId(),shape:"regularPoly",sides:document.getElementById("polySides").value,orient:"x",edge:0,fill:e,strokecolor:r,strokeWidth:o}}),{started:!0}}},mouseMove:function mouseMove(t){if(c&&"polygon"===n.getMode()){var e=o(u).attr(["cx","cy","sides","orient","fill","strokecolor","strokeWidth"]),r=t.mouse_x,i=t.mouse_y,a=e.cx,s=e.cy,f=e.fill,h=e.strokecolor,y=e.strokeWidth,v=e.sides,d=Math.sqrt((r-a)*(r-a)+(i-s)*(i-s))/1.5;u.setAttribute("edge",d);for(var g=d/2*l(Math.PI/v)*p(Math.PI/v),m="",b=0;v>=b;b++){var w=2*Math.PI*b/v;m+=(r=g*Math.cos(w)+a)+","+(i=g*Math.sin(w)+s)+" "}return u.setAttribute("points",m),u.setAttribute("fill",f),u.setAttribute("stroke",h),u.setAttribute("stroke-width",y),{started:!0}}},mouseUp:function mouseUp(t){if("polygon"===n.getMode())return{keep:"0"!==o(u).attr("edge").edge,element:u}},selectedChanged:function selectedChanged(t){for(var e=(a=t.elems).length;e--;){var r=a[e];r&&"regularPoly"===r.getAttribute("shape")&&t.selectedElement&&!t.multiselected?(o("#polySides").val(r.getAttribute("sides")),s(!0)):s(!1)}},elementChanged:function elementChanged(t){}});case 13:case"end":return v.stop()}}),_callee2)})))()}},Jn=Object.freeze({__proto__:null,default:{name:"polygon",buttons:[{title:"Polygon Tool"}],contextTools:[{title:"Number of Sides",label:"sides"}]}}),$n=Object.freeze({__proto__:null,default:{name:"多边形",buttons:[{title:"多边形工具"}],contextTools:[{title:"边数",label:"边数"}]}});export default Hn; +var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function createCommonjsModule(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}var check=function(t){return t&&t.Math==Math&&t},e=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof t&&t)||function(){return this}()||Function("return this")(),fails=function(t){try{return!!t()}catch(t){return!0}},r=!fails((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),n={}.propertyIsEnumerable,o=Object.getOwnPropertyDescriptor,i={f:o&&!n.call({1:2},1)?function propertyIsEnumerable(t){var e=o(this,t);return!!e&&e.enumerable}:n},createPropertyDescriptor=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},a={}.toString,classofRaw=function(t){return a.call(t).slice(8,-1)},c="".split,u=fails((function(){return!Object("z").propertyIsEnumerable(0)}))?function(t){return"String"==classofRaw(t)?c.call(t,""):Object(t)}:Object,requireObjectCoercible=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},toIndexedObject=function(t){return u(requireObjectCoercible(t))},isObject=function(t){return"object"==typeof t?null!==t:"function"==typeof t},toPrimitive=function(t,e){if(!isObject(t))return t;var r,n;if(e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;if("function"==typeof(r=t.valueOf)&&!isObject(n=r.call(t)))return n;if(!e&&"function"==typeof(r=t.toString)&&!isObject(n=r.call(t)))return n;throw TypeError("Can't convert object to primitive value")},f={}.hasOwnProperty,has=function(t,e){return f.call(t,e)},s=e.document,l=isObject(s)&&isObject(s.createElement),documentCreateElement=function(t){return l?s.createElement(t):{}},p=!r&&!fails((function(){return 7!=Object.defineProperty(documentCreateElement("div"),"a",{get:function(){return 7}}).a})),h=Object.getOwnPropertyDescriptor,y={f:r?h:function getOwnPropertyDescriptor(t,e){if(t=toIndexedObject(t),e=toPrimitive(e,!0),p)try{return h(t,e)}catch(t){}if(has(t,e))return createPropertyDescriptor(!i.f.call(t,e),t[e])}},anObject=function(t){if(!isObject(t))throw TypeError(String(t)+" is not an object");return t},d=Object.defineProperty,v={f:r?d:function defineProperty(t,e,r){if(anObject(t),e=toPrimitive(e,!0),anObject(r),p)try{return d(t,e,r)}catch(t){}if("get"in r||"set"in r)throw TypeError("Accessors not supported");return"value"in r&&(t[e]=r.value),t}},g=r?function(t,e,r){return v.f(t,e,createPropertyDescriptor(1,r))}:function(t,e,r){return t[e]=r,t},setGlobal=function(t,r){try{g(e,t,r)}catch(n){e[t]=r}return r},m=e["__core-js_shared__"]||setGlobal("__core-js_shared__",{}),b=Function.toString;"function"!=typeof m.inspectSource&&(m.inspectSource=function(t){return b.call(t)});var w,S,O,j=m.inspectSource,_=e.WeakMap,x="function"==typeof _&&/native code/.test(j(_)),E=createCommonjsModule((function(t){(t.exports=function(t,e){return m[t]||(m[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.7.0",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),P=0,T=Math.random(),uid=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++P+T).toString(36)},k=E("keys"),sharedKey=function(t){return k[t]||(k[t]=uid(t))},A={},I=e.WeakMap;if(x){var L=m.state||(m.state=new I),M=L.get,C=L.has,G=L.set;w=function(t,e){return e.facade=t,G.call(L,t,e),e},S=function(t){return M.call(L,t)||{}},O=function(t){return C.call(L,t)}}else{var R=sharedKey("state");A[R]=!0,w=function(t,e){return e.facade=t,g(t,R,e),e},S=function(t){return has(t,R)?t[R]:{}},O=function(t){return has(t,R)}}var N,D={set:w,get:S,has:O,enforce:function(t){return O(t)?S(t):w(t,{})},getterFor:function(t){return function(e){var r;if(!isObject(e)||(r=S(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return r}}},W=createCommonjsModule((function(t){var r=D.get,n=D.enforce,o=String(String).split("String");(t.exports=function(t,r,i,a){var c,u=!!a&&!!a.unsafe,f=!!a&&!!a.enumerable,s=!!a&&!!a.noTargetGet;"function"==typeof i&&("string"!=typeof r||has(i,"name")||g(i,"name",r),(c=n(i)).source||(c.source=o.join("string"==typeof r?r:""))),t!==e?(u?!s&&t[r]&&(f=!0):delete t[r],f?t[r]=i:g(t,r,i)):f?t[r]=i:setGlobal(r,i)})(Function.prototype,"toString",(function toString(){return"function"==typeof this&&r(this).source||j(this)}))})),q=e,aFunction=function(t){return"function"==typeof t?t:void 0},getBuiltIn=function(t,r){return arguments.length<2?aFunction(q[t])||aFunction(e[t]):q[t]&&q[t][r]||e[t]&&e[t][r]},z=Math.ceil,U=Math.floor,toInteger=function(t){return isNaN(t=+t)?0:(t>0?U:z)(t)},V=Math.min,toLength=function(t){return t>0?V(toInteger(t),9007199254740991):0},B=Math.max,Y=Math.min,toAbsoluteIndex=function(t,e){var r=toInteger(t);return r<0?B(r+e,0):Y(r,e)},createMethod=function(t){return function(e,r,n){var o,i=toIndexedObject(e),a=toLength(i.length),c=toAbsoluteIndex(n,a);if(t&&r!=r){for(;a>c;)if((o=i[c++])!=o)return!0}else for(;a>c;c++)if((t||c in i)&&i[c]===r)return t||c||0;return!t&&-1}},H={includes:createMethod(!0),indexOf:createMethod(!1)}.indexOf,objectKeysInternal=function(t,e){var r,n=toIndexedObject(t),o=0,i=[];for(r in n)!has(A,r)&&has(n,r)&&i.push(r);for(;e.length>o;)has(n,r=e[o++])&&(~H(i,r)||i.push(r));return i},J=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],$=J.concat("length","prototype"),K={f:Object.getOwnPropertyNames||function getOwnPropertyNames(t){return objectKeysInternal(t,$)}},Q={f:Object.getOwnPropertySymbols},X=getBuiltIn("Reflect","ownKeys")||function ownKeys(t){var e=K.f(anObject(t)),r=Q.f;return r?e.concat(r(t)):e},copyConstructorProperties=function(t,e){for(var r=X(e),n=v.f,o=y.f,i=0;ii;)v.f(t,r=n[i++],e[r]);return t},ht=getBuiltIn("document","documentElement"),yt=sharedKey("IE_PROTO"),EmptyConstructor=function(){},scriptTag=function(t){return"