From f5413db6783d197ed5e7967957e89833a7d3c173 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich-Matthias=20Sch=C3=A4fer?= Date: Sat, 24 Nov 2018 14:35:14 +0100 Subject: [PATCH] Moved utils, namespaces, regex... to a subobject of SVG. Renamed SVGArray and SVGNumber on export to Array and Number --- dist/svg.js | 52 ++++--- spec/spec/adopter.js | 4 +- spec/spec/array.js | 14 +- spec/spec/element.js | 6 +- spec/spec/fx.js | 22 +-- spec/spec/morphing.js | 32 ++-- spec/spec/number.js | 36 ++--- spec/spec/sugar.js | 12 +- spec/spec/text.js | 4 +- spec/spec/transformations.js | 281 ----------------------------------- spec/spec/use.js | 8 +- src/main.js | 14 +- src/svg.js | 5 - 13 files changed, 107 insertions(+), 383 deletions(-) delete mode 100644 spec/spec/transformations.js diff --git a/dist/svg.js b/dist/svg.js index 701b906..eb0d90d 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -6,7 +6,7 @@ * @copyright Wout Fierens * @license MIT * -* BUILT: Sat Nov 24 2018 11:07:45 GMT+0100 (GMT+01:00) +* BUILT: Sat Nov 24 2018 14:31:28 GMT+0100 (GMT+01:00) */; var SVG = (function () { 'use strict'; @@ -372,12 +372,31 @@ var SVG = (function () { return [ox, oy]; } + var utils = /*#__PURE__*/Object.freeze({ + map: map, + filter: filter, + radians: radians, + degrees: degrees, + camelCase: camelCase, + unCamelCase: unCamelCase, + capitalize: capitalize, + proportionalSize: proportionalSize, + getOrigin: getOrigin + }); + // Default namespaces var ns = 'http://www.w3.org/2000/svg'; var xmlns = 'http://www.w3.org/2000/xmlns/'; var xlink = 'http://www.w3.org/1999/xlink'; var svgjs = 'http://svgjs.com/svgjs'; + var namespaces = /*#__PURE__*/Object.freeze({ + ns: ns, + xmlns: xmlns, + xlink: xlink, + svgjs: svgjs + }); + var globals = { window: typeof window === 'undefined' ? null : window, document: typeof document === 'undefined' ? null : document @@ -6999,6 +7018,7 @@ var SVG = (function () { register(Use); /* Optional Modules */ + var SVG = makeInstance; extend([Svg$1, Symbol, Image, Pattern, Marker], getMethodsFor('viewbox')); extend([Line, Polyline, Polygon, Path], getMethodsFor('marker')); extend(Text, getMethodsFor('Text')); @@ -7025,6 +7045,10 @@ var SVG = (function () { ObjectBag: ObjectBag, NonMorphable: NonMorphable, defaults: defaults, + utils: utils, + namespaces: namespaces, + regex: regex, + SVG: SVG, parser: parser, find: baseFind, registerWindow: registerWindow, @@ -7037,12 +7061,12 @@ var SVG = (function () { Queue: Queue, Runner: Runner, Timeline: Timeline, - SVGArray: SVGArray, + Array: SVGArray, Box: Box, Color: Color, EventTarget: EventTarget, Matrix: Matrix, - SVGNumber: SVGNumber, + Number: SVGNumber, PathArray: PathArray, Point: Point, PointArray: PointArray, @@ -7075,19 +7099,6 @@ var SVG = (function () { TextPath: TextPath, Tspan: Tspan, Use: Use, - map: map, - filter: filter, - radians: radians, - degrees: degrees, - camelCase: camelCase, - unCamelCase: unCamelCase, - capitalize: capitalize, - proportionalSize: proportionalSize, - getOrigin: getOrigin, - ns: ns, - xmlns: xmlns, - xlink: xlink, - svgjs: svgjs, on: on, off: off, dispatch: dispatch, @@ -7105,14 +7116,11 @@ var SVG = (function () { wrapWithAttrCheck: wrapWithAttrCheck }); - function SVG(element) { + function SVG$1(element) { return makeInstance(element); } - Object.assign(SVG, svgMembers); - SVG.utils = SVG; - SVG.regex = regex; - SVG.get = SVG; + Object.assign(SVG$1, svgMembers); - return SVG; + return SVG$1; }()); diff --git a/spec/spec/adopter.js b/spec/spec/adopter.js index 6beb63b..05c1517 100644 --- a/spec/spec/adopter.js +++ b/spec/spec/adopter.js @@ -14,13 +14,13 @@ describe('Adopter', function() { expect(path.parent() instanceof SVG.Svg).toBeTruthy() }) it('defines a xmlns attribute', function() { - expect(path.parent().node.getAttribute('xmlns')).toBe(SVG.ns) + expect(path.parent().node.getAttribute('xmlns')).toBe(SVG.namespaces.ns) }) it('defines a version attribute', function() { expect(path.parent().node.getAttribute('version')).toBe('1.1') }) it('defines a xmlns:xlink attribute', function() { - expect(path.parent().node.getAttribute('xmlns:xlink')).toBe(SVG.xlink) + expect(path.parent().node.getAttribute('xmlns:xlink')).toBe(SVG.namespaces.xlink) }) it('initializes a defs node', function() { expect(path.defs() instanceof SVG.Defs).toBe(true) diff --git a/spec/spec/array.js b/spec/spec/array.js index eeccdca..03cffa3 100644 --- a/spec/spec/array.js +++ b/spec/spec/array.js @@ -2,7 +2,7 @@ describe('Array', function () { var array, arr1, arr2 it('parses a matrix array correctly to string', function() { - array = new SVG.SVGArray([ .343, .669, .119, 0, 0 + array = new SVG.Array([ .343, .669, .119, 0, 0 , .249, -.626, .130, 0, 0 , .172, .334, .111, 0, 0 , .000, .000, .000, 1, -0 ]) @@ -10,31 +10,31 @@ describe('Array', function () { expect(array + '').toBe('0.343 0.669 0.119 0 0 0.249 -0.626 0.13 0 0 0.172 0.334 0.111 0 0 0 0 0 1 0') }) it('parses space seperated string and converts it to array', function() { - expect((new SVG.SVGArray('1 2 3 4')).valueOf()).toEqual([1,2,3,4]) + expect((new SVG.Array('1 2 3 4')).valueOf()).toEqual([1,2,3,4]) }) it('parses comma seperated string and converts it to array', function() { - expect((new SVG.SVGArray('1,2,3,4')).valueOf()).toEqual([1,2,3,4]) + expect((new SVG.Array('1,2,3,4')).valueOf()).toEqual([1,2,3,4]) }) describe('reverse()', function() { it('reverses the array', function() { - array = new SVG.SVGArray([1 ,2 ,3, 4, 5]).reverse() + array = new SVG.Array([1 ,2 ,3, 4, 5]).reverse() expect(array.valueOf()).toEqual([5, 4, 3, 2, 1]) }) it('returns itself', function() { - array = new SVG.SVGArray() + array = new SVG.Array() expect(array.reverse()).toBe(array) }) }) describe('clone()', function() { it('creates a deep clone of the array', function() { - array = new SVG.SVGArray([1, 2, 3, 4, 5]) + array = new SVG.Array([1, 2, 3, 4, 5]) clone = array.clone() expect(array).toEqual(clone) expect(array).not.toBe(clone) - array = new SVG.SVGArray([[1,2], [3, 4], [5]]) + array = new SVG.Array([[1,2], [3, 4], [5]]) clone = array.clone() expect(array).toEqual(array) diff --git a/spec/spec/element.js b/spec/spec/element.js index 6fb1ff4..8d685a4 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -111,7 +111,7 @@ describe('Element', function() { expect(draw.defs().find('pattern image').length).toBe(1) expect(draw.defs().find('pattern image')[0].attr('href')).toBe(imageUrl) }) - it('correctly creates SVG.SVGArray if array given', function() { + it('correctly creates SVG.Array if array given', function() { rect.attr('something', [2,3,4]) expect(rect.attr('something')).toBe('2 3 4') }) @@ -939,7 +939,7 @@ describe('Element', function() { it('set all properties in el.dom to the svgjs:data attribute', function(){ var rect = draw.rect(100,100) rect.dom.foo = 'bar' - rect.dom.number = new SVG.SVGNumber('3px') + rect.dom.number = new SVG.Number('3px') rect.writeDataToDom() @@ -949,7 +949,7 @@ describe('Element', function() { var g = draw.group() rect = g.rect(100,100) g.dom.foo = 'bar' - rect.dom.number = new SVG.SVGNumber('3px') + rect.dom.number = new SVG.Number('3px') g.writeDataToDom() diff --git a/spec/spec/fx.js b/spec/spec/fx.js index cc4e6d8..365a196 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -2143,7 +2143,7 @@ // it('should be possible to animate numeric attributes', function () { // var startValue = 0 // , endValue = 150 -// , morph = new SVG.SVGNumber(startValue).morph(endValue) +// , morph = new SVG.Number(startValue).morph(endValue) // // var text = draw.text(function(add) { // add.tspan('We go ') @@ -2213,7 +2213,7 @@ // it('should be possible to pass percentage strings to numeric attributes', function () { // var startValue = '0%' // , endValue = '80%' -// , morph = new SVG.SVGNumber(startValue).morph(endValue) +// , morph = new SVG.Number(startValue).morph(endValue) // // var text = draw.text(function(add) { // add.tspan('We go ') @@ -2288,7 +2288,7 @@ // it('should be possible to animate numeric styles', function () { // var startValue = 0 // , endValue = 5 -// , morph = new SVG.SVGNumber(startValue).morph(endValue) +// , morph = new SVG.Number(startValue).morph(endValue) // // rect.css('stroke-width', startValue) // fx.css('stroke-width', endValue) @@ -2352,7 +2352,7 @@ // it('should be possible to pass percentage strings to numeric styles', function () { // var startValue = '0%' // , endValue = '5%' -// , morph = new SVG.SVGNumber(startValue).morph(endValue) +// , morph = new SVG.Number(startValue).morph(endValue) // // rect.css('stroke-width', startValue) // fx.css('stroke-width', endValue) @@ -2398,14 +2398,14 @@ // // describe('add()', function() { // it('adds to animations obj by default', function() { -// fx.add('x', new SVG.SVGNumber(20)) +// fx.add('x', new SVG.Number(20)) // expect(fx.situation.animations.x.value).toBe(20) // }) // // it('adds to specified obj', function() { -// fx.add('x', new SVG.SVGNumber(20), 'animations') -// fx.add('x', new SVG.SVGNumber(20), 'attrs') -// fx.add('x', new SVG.SVGNumber(20), 'styles') +// fx.add('x', new SVG.Number(20), 'animations') +// fx.add('x', new SVG.Number(20), 'attrs') +// fx.add('x', new SVG.Number(20), 'styles') // expect(fx.situation.animations.x.value).toBe(20) // expect(fx.situation.attrs.x.value).toBe(20) // expect(fx.situation.styles.x.value).toBe(20) @@ -2836,12 +2836,12 @@ // expect(obj instanceof SVG.Color).toBeTruthy() // }) // -// it('accepts numbers and converts them to SVG.SVGNumber', function() { +// it('accepts numbers and converts them to SVG.Number', function() { // var obj = new SVG.MorphObj('0', '10') -// expect(obj instanceof SVG.SVGNumber).toBeTruthy() +// expect(obj instanceof SVG.Number).toBeTruthy() // // var obj = new SVG.MorphObj(0, 10) -// expect(obj instanceof SVG.SVGNumber).toBeTruthy() +// expect(obj instanceof SVG.Number).toBeTruthy() // }) // // it('accepts any other values', function() { diff --git a/spec/spec/morphing.js b/spec/spec/morphing.js index 7fc0c06..0557428 100644 --- a/spec/spec/morphing.js +++ b/spec/spec/morphing.js @@ -5,8 +5,8 @@ describe('Morphing', function () { var morpher = new SVG.Morphable().from(10).to(5) expect(morpher instanceof SVG.Morphable).toBe(true) - expect(morpher.type()).toBe(SVG.SVGNumber) - expect(morpher.at(0.5) instanceof SVG.SVGNumber).toBe(true) + expect(morpher.type()).toBe(SVG.Number) + expect(morpher.at(0.5) instanceof SVG.Number).toBe(true) expect(morpher.at(0.5).valueOf()).toBe(7.5) }) @@ -29,12 +29,12 @@ describe('Morphing', function () { expect(morpher.at(0.5).valueOf()).toEqual(jasmine.objectContaining({a: 7.5, b: 15})) }) - it(`Creates a morphable out of an SVG.SVGNumber`, function () { - var morpher = new SVG.SVGNumber(5).to(10) + it(`Creates a morphable out of an SVG.Number`, function () { + var morpher = new SVG.Number(5).to(10) expect(morpher instanceof SVG.Morphable).toBe(true) - expect(morpher.type()).toBe(SVG.SVGNumber) - expect(morpher.at(0.5) instanceof SVG.SVGNumber).toBe(true) + expect(morpher.type()).toBe(SVG.Number) + expect(morpher.at(0.5) instanceof SVG.Number).toBe(true) expect(morpher.at(0.5).valueOf()).toBe(7.5) }) @@ -65,12 +65,12 @@ describe('Morphing', function () { expect(morpher.at(0.5)).toEqual(jasmine.objectContaining(new SVG.Matrix(2, 3, 4, 5, 6, 7))) }) - it(`Creates a morphable out of an SVG.SVGArray`, function () { - var morpher = new SVG.SVGArray([1,2,3,4,5,6]).to([3,4,5,6,7,8]) + it(`Creates a morphable out of an SVG.Array`, function () { + var morpher = new SVG.Array([1,2,3,4,5,6]).to([3,4,5,6,7,8]) expect(morpher instanceof SVG.Morphable).toBe(true) - expect(morpher.type()).toBe(SVG.SVGArray) - expect(morpher.at(0.5) instanceof SVG.SVGArray).toBe(true) + expect(morpher.type()).toBe(SVG.Array) + expect(morpher.at(0.5) instanceof SVG.Array).toBe(true) expect(morpher.at(0.5).toArray()).toEqual(jasmine.arrayContaining([2, 3, 4, 5, 6, 7])) }) @@ -126,7 +126,7 @@ describe('Morphing', function () { describe('from()', function () { it('sets the type of the runner', function () { var morpher = new SVG.Morphable().from(5) - expect(morpher.type()).toBe(SVG.SVGNumber) + expect(morpher.type()).toBe(SVG.Number) }) it('sets the from attribute to an array representation of the morphable type', function () { @@ -137,20 +137,20 @@ describe('Morphing', function () { describe('type()', function () { it('sets the type of the runner', function () { - var morpher = new SVG.Morphable().type(SVG.SVGNumber) - expect(morpher._type).toBe(SVG.SVGNumber) + var morpher = new SVG.Morphable().type(SVG.Number) + expect(morpher._type).toBe(SVG.Number) }) it('gets the type of the runner', function () { - var morpher = new SVG.Morphable().type(SVG.SVGNumber) - expect(morpher.type()).toBe(SVG.SVGNumber) + var morpher = new SVG.Morphable().type(SVG.Number) + expect(morpher.type()).toBe(SVG.Number) }) }) describe('to()', function () { it('sets the type of the runner', function () { var morpher = new SVG.Morphable().to(5) - expect(morpher.type()).toBe(SVG.SVGNumber) + expect(morpher.type()).toBe(SVG.Number) }) it('sets the from attribute to an array representation of the morphable type', function () { diff --git a/spec/spec/number.js b/spec/spec/number.js index a6ae80e..eb98fd5 100644 --- a/spec/spec/number.js +++ b/spec/spec/number.js @@ -2,7 +2,7 @@ describe('Number', function() { var number beforeEach(function() { - number = new SVG.SVGNumber + number = new SVG.Number }) describe('new', function() { @@ -13,40 +13,40 @@ describe('Number', function() { expect(number.unit).toBe('') }) it('accepts the unit as a second argument', function() { - number = new SVG.SVGNumber(30, '%') + number = new SVG.Number(30, '%') expect(number.value).toBe(30) expect(number.unit).toBe('%') }) it('parses a pixel value', function() { - number = new SVG.SVGNumber('20px') + number = new SVG.Number('20px') expect(number.value).toBe(20) expect(number.unit).toBe('px') }) it('parses a percent value', function() { - number = new SVG.SVGNumber('99%') + number = new SVG.Number('99%') expect(number.value).toBe(0.99) expect(number.unit).toBe('%') }) it('parses a seconds value', function() { - number = new SVG.SVGNumber('2s') + number = new SVG.Number('2s') expect(number.value).toBe(2000) expect(number.unit).toBe('s') }) it('parses a negative percent value', function() { - number = new SVG.SVGNumber('-89%') + number = new SVG.Number('-89%') expect(number.value).toBe(-0.89) expect(number.unit).toBe('%') }) it('falls back to 0 if given value is NaN', function() { - number = new SVG.SVGNumber(NaN) + number = new SVG.Number(NaN) expect(number.value).toBe(0) }) it('falls back to maximum value if given number is positive infinite', function() { - number = new SVG.SVGNumber(1.7976931348623157E+10308) + number = new SVG.Number(1.7976931348623157E+10308) expect(number.value).toBe(3.4e+38) }) it('falls back to minimum value if given number is negative infinite', function() { - number = new SVG.SVGNumber(-1.7976931348623157E+10308) + number = new SVG.Number(-1.7976931348623157E+10308) expect(number.value).toBe(-3.4e+38) }) }) @@ -75,17 +75,17 @@ describe('Number', function() { describe('valueOf()', function() { it('returns a numeric value for default units', function() { expect(typeof number.valueOf()).toBe('number') - number = new SVG.SVGNumber('12') + number = new SVG.Number('12') expect(typeof number.valueOf()).toBe('number') - number = new SVG.SVGNumber(13) + number = new SVG.Number(13) expect(typeof number.valueOf()).toBe('number') }) it('returns a numeric value for pixel units', function() { - number = new SVG.SVGNumber('10px') + number = new SVG.Number('10px') expect(typeof number.valueOf()).toBe('number') }) it('returns a numeric value for percent units', function() { - number = new SVG.SVGNumber('20%') + number = new SVG.Number('20%') expect(typeof number.valueOf()).toBe('number') }) it('converts to a primitive when multiplying', function() { @@ -97,7 +97,7 @@ describe('Number', function() { describe('plus()', function() { it('returns a new instance', function() { expect(number.plus(4.5)).not.toBe(number) - expect(number.plus(4.5) instanceof SVG.SVGNumber).toBeTruthy() + expect(number.plus(4.5) instanceof SVG.Number).toBeTruthy() }) it('adds a given number', function() { expect(number.plus(3.5).valueOf()).toBe(3.5) @@ -109,7 +109,7 @@ describe('Number', function() { expect(number.plus('83px').valueOf()).toBe(83) }) it('use the unit of this number as the unit of the returned number by default', function (){ - expect(new SVG.SVGNumber('12s').plus('3%').unit).toBe('s') + expect(new SVG.Number('12s').plus('3%').unit).toBe('s') }) it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { expect(number.plus('15%').unit).toBe('%') @@ -127,7 +127,7 @@ describe('Number', function() { expect(number.minus('85px').valueOf()).toBe(-85) }) it('use the unit of this number as the unit of the returned number by default', function (){ - expect(new SVG.SVGNumber('12s').minus('3%').unit).toBe('s') + expect(new SVG.Number('12s').minus('3%').unit).toBe('s') }) it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { expect(number.minus('15%').unit).toBe('%') @@ -148,7 +148,7 @@ describe('Number', function() { expect(number.times('85px').valueOf()).toBe(340) }) it('use the unit of this number as the unit of the returned number by default', function (){ - expect(new SVG.SVGNumber('12s').times('3%').unit).toBe('s') + expect(new SVG.Number('12s').times('3%').unit).toBe('s') }) it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { expect(number.times('15%').unit).toBe('%') @@ -169,7 +169,7 @@ describe('Number', function() { expect(number.divide('45px').valueOf()).toBe(2) }) it('use the unit of this number as the unit of the returned number by default', function (){ - expect(new SVG.SVGNumber('12s').divide('3%').unit).toBe('s') + expect(new SVG.Number('12s').divide('3%').unit).toBe('s') }) it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { expect(number.divide('15%').unit).toBe('%') diff --git a/spec/spec/sugar.js b/spec/spec/sugar.js index 906dfe7..704643d 100644 --- a/spec/spec/sugar.js +++ b/spec/spec/sugar.js @@ -247,8 +247,8 @@ describe('Sugar', function() { it('redirects to x() / y() with adding the current value', function() { rect.dx(5) rect.dy(5) - expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('5'))) - expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('5'))) + expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('5'))) + expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('5'))) }) it('allows to add a percentage value', function() { @@ -257,16 +257,16 @@ describe('Sugar', function() { rect.dx('5%') rect.dy('5%') - expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('10%'))) - expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('10%'))) + expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('10%'))) + expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('10%'))) }) it('allows to add a percentage value when no x/y is set', function() { rect.dx('5%') rect.dy('5%') - expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('5%'))) - expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.SVGNumber('5%'))) + expect(rect.x).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('5%'))) + expect(rect.y).toHaveBeenCalledWith(jasmine.objectContaining(new SVG.Number('5%'))) }) }) diff --git a/spec/spec/text.js b/spec/spec/text.js index b5d0b59..a541e98 100644 --- a/spec/spec/text.js +++ b/spec/spec/text.js @@ -15,7 +15,7 @@ describe('Text', function() { describe('leading()', function() { it('returns the leading value of the text without an argument', function() { - expect(text.leading() instanceof SVG.SVGNumber) + expect(text.leading() instanceof SVG.Number) expect(text.leading().valueOf()).toBe(1.3) }) it('sets the leading value of the text with the first argument', function() { @@ -283,7 +283,7 @@ describe('Text', function() { text.setData(JSON.parse(text.attr('svgjs:data'))) expect(text.dom.foo).toBe('bar') - expect(text.dom.leading instanceof SVG.SVGNumber).toBeTruthy() + expect(text.dom.leading instanceof SVG.Number).toBeTruthy() expect(text.dom.leading.value).toBe(3) expect(text.dom.leading.unit).toBe('px') }) diff --git a/spec/spec/transformations.js b/spec/spec/transformations.js deleted file mode 100644 index 242e798..0000000 --- a/spec/spec/transformations.js +++ /dev/null @@ -1,281 +0,0 @@ -// describe('Transformations:', function() { -// var translated, scaled, rotated, skewed -// -// beforeEach(function() { -// translated = draw.rect(100,100).translate(100,100) -// scaled = draw.rect(100,100).scale(2) -// rotated = draw.rect(100,100).rotate(45, 50, 50) -// skewed = draw.rect(100,100).skew(30) -// }) -// -// /* SVG.Transformation is not tested because it is an abstract prototype */ -// -// describe('SVG.Transformation', function() { -// it('marks the transformation as inversed when inverse flag given', function() { -// var trans = new SVG.Transformation([], true) -// expect(trans.inversed).toBeTruthy() -// }) -// }) -// -// describe('SVG.Translate', function() { -// var trans -// -// beforeEach(function(){ -// trans = new SVG.Translate(translated.transform()) -// }) -// -// -// it('creates an object of type SVG.Transformation', function() { -// expect(trans instanceof SVG.Transformation).toBeTruthy() -// }) -// -// it('uses transformedX and transformedY as arguments', function() { -// expect(trans.arguments).toEqual(['transformedX', 'transformedY']) -// }) -// -// it('s method is translate()', function() { -// expect(trans.method).toEqual('translate') -// }) -// -// it('sets the necessary parameters at creation', function() { -// expect(trans.transformedX).toBe(100) -// expect(trans.transformedY).toBe(100) -// }) -// -// describe('undo', function() { -// it('sets the undo matrix which can undo the translation', function() { -// var extracted = (new SVG.Matrix(1,0,0,1,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.toString()).toEqual('matrix(1,0,0,1,-20,-20)') -// -// var extracted = (new SVG.Matrix(10,0,0,10,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.toString()).toEqual('matrix(1,0,0,1,-2,-2)') -// -// var extracted = (new SVG.Matrix(10,50,50,30,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.e).toBeCloseTo(-extracted.transformedX) -// expect(trans._undo.f).toBeCloseTo(-extracted.transformedY) -// }) -// }) -// -// describe('at', function() { -// it('creates a matrix at a certain position', function() { -// expect(trans.at(0.3).toString()).toEqual('matrix(1,0,0,1,30,30)') -// }) -// it('returns the inversed matrix from a specific position when created with inverse flag', function() { -// expect((new SVG.Translate(translated.transform(), true)).at(0.3).toString()).toEqual('matrix(1,0,0,1,-30,-30)') -// }) -// it('returns the resulting transformation which has to be made to set an absolute translation', function() { -// trans.undo(new SVG.Matrix(10,50,50,30,20,20).extract()) -// -// expect(trans.at(0.4).a).toEqual(1) -// expect(trans.at(0.4).b).toEqual(0) -// expect(trans.at(0.4).c).toEqual(0) -// expect(trans.at(0.4).d).toEqual(1) -// expect(trans.at(0.4).e).toBeCloseTo(100 * 0.4 + trans._undo.e * 0.4) -// expect(trans.at(0.4).f).toBeCloseTo(100 * 0.4 + trans._undo.f * 0.4) -// }) -// }) -// }) -// -// describe('SVG.Rotate', function() { -// var trans -// -// beforeEach(function(){ -// trans = new SVG.Rotate(45, 50, 50) -// }) -// -// -// it('creates an object of type SVG.Transformation', function() { -// expect(trans instanceof SVG.Transformation).toBeTruthy() -// }) -// -// it('uses rotation, cx and cy as arguments', function() { -// expect(trans.arguments).toEqual(['rotation', 'cx', 'cy']) -// }) -// -// it('s method is rotate()', function() { -// expect(trans.method).toEqual('rotate') -// }) -// -// it('sets the necessary parameters at creation', function() { -// expect(trans.rotation).toBe(45) -// expect(trans.cx).toBe(50) -// expect(trans.cy).toBe(50) -// }) -// -// describe('undo', function() { -// it('sets an undo object which holds rotation', function() { -// var extracted = (new SVG.Matrix(1,0,0,1,0,0)).rotate(20, 50, 50).extract() -// trans.undo(extracted) -// expect(trans._undo.rotation).toBeCloseTo(20) -// }) -// }) -// -// describe('at', function() { -// it('creates a matrix at a certain position', function() { -// expect(trans.at(0.3).toString()).toEqual((new SVG.Matrix()).rotate(0.3 * 45, 50, 50).toString()) -// }) -// it('returns the resulting transformation which has to be made to set an absolute translation', function() { -// trans.undo((new SVG.Matrix()).rotate(20, 50, 50).extract()) -// -// expect(trans.at(0.4).a).toBeCloseTo(1,1) -// expect(trans.at(0.4).b).toEqual(jasmine.any(Number)) -// expect(trans.at(0.4).c).toEqual(jasmine.any(Number)) -// expect(trans.at(0.4).d).toBeCloseTo(1,1) -// expect(trans.at(0.4).e).toEqual(jasmine.any(Number)) -// expect(trans.at(0.4).f).toEqual(jasmine.any(Number)) -// }) -// }) -// }) -// -// -// describe('SVG.Scale', function() { -// var trans -// -// beforeEach(function(){ -// trans = new SVG.Scale(2,2,50,50) -// }) -// -// -// it('creates an object of type SVG.Transformation', function() { -// expect(trans instanceof SVG.Transformation).toBeTruthy() -// }) -// -// it('uses scaleX, scaleY, cx and cy as arguments', function() { -// expect(trans.arguments).toEqual(['scaleX', 'scaleY', 'cx', 'cy']) -// }) -// -// it('s method is scale()', function() { -// expect(trans.method).toEqual('scale') -// }) -// -// it('sets the necessary parameters at creation', function() { -// expect(trans.scaleX).toBe(2) -// expect(trans.scaleY).toBe(2) -// expect(trans.cx).toBe(50) -// expect(trans.cy).toBe(50) -// }) -// -// describe('undo', function() { -// it('sets the undo matrix which can undo the translation', function() { -// var extracted = (new SVG.Matrix(4,0,0,4,0,0)).extract() -// trans.undo(extracted) -// expect(trans._undo.toString()).toEqual('matrix(0.25,0,0,0.25,37.5,37.5)') -// -// var extracted = (new SVG.Matrix(10,0,0,10,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.a).toBeCloseTo(1/extracted.scaleX) -// expect(trans._undo.d).toBeCloseTo(1/extracted.scaleY) -// expect(trans._undo.e).toBeCloseTo(45) -// expect(trans._undo.f).toBeCloseTo(45) -// -// var extracted = (new SVG.Matrix(10,50,50,30,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.a).toBeCloseTo(1/extracted.scaleX) -// expect(trans._undo.d).toBeCloseTo(1/extracted.scaleY) -// }) -// }) -// -// describe('at', function() { -// it('creates a matrix at a certain position', function() { -// expect(trans.at(0.75).toString()).toEqual('matrix(1.75,0,0,1.75,-37.5,-37.5)') -// }) -// it('returns the inversed matrix from a specific position when created with inverse flag', function() { -// var morphed = (new SVG.Scale(scaled.transform(2,2,50,50), true)).at(0.25) -// -// expect(morphed.a).toBeCloseTo(0.8) -// expect(morphed.d).toBeCloseTo(0.8) -// }) -// it('returns the resulting transformation which has to be made to set an absolute translation', function() { -// -// var morphed = trans.undo((new SVG.Matrix(10,0,0,10,0,0)).extract()).at(0.5) -// -// expect(morphed.a).toBeCloseTo(0.6) -// expect(morphed.b).toEqual(0) -// expect(morphed.c).toEqual(0) -// expect(morphed.d).toBeCloseTo(0.6) -// expect(morphed.e).toBeCloseTo(20) -// expect(morphed.f).toBeCloseTo(20) -// }) -// }) -// }) -// -// describe('SVG.Skew', function() { -// var trans -// -// beforeEach(function(){ -// trans = new SVG.Skew(30,-30,50,50) -// }) -// -// -// it('creates an object of type SVG.Transformation', function() { -// expect(trans instanceof SVG.Transformation).toBeTruthy() -// }) -// -// it('uses scaleX, scaleY, cx and cy as arguments', function() { -// expect(trans.arguments).toEqual(['skewX', 'skewY', 'cx', 'cy']) -// }) -// -// it('s method is skew()', function() { -// expect(trans.method).toEqual('skew') -// }) -// -// it('sets the necessary parameters at creation', function() { -// expect(trans.skewX).toBe(30) -// expect(trans.skewY).toBe(-30) -// expect(trans.cx).toBe(50) -// expect(trans.cy).toBe(50) -// }) -// -// describe('undo', function() { -// it('sets the undo matrix which can undo the translation', function() { -// var extracted = (new SVG.Matrix()).skew(90, 90, 0, 0).extract() -// trans.undo(extracted) -// expect(trans._undo.a).toBeCloseTo(0) -// expect(trans._undo.b).toBeCloseTo(0) -// expect(trans._undo.c).toBeCloseTo(0) -// expect(trans._undo.d).toBeCloseTo(0) -// expect(trans._undo.e).toBeCloseTo(50) -// expect(trans._undo.f).toBeCloseTo(50) -// -// var extracted = (new SVG.Matrix(10,0,0,10,20,20)).extract() -// trans.undo(extracted) -// expect(trans._undo.a).toBeCloseTo(1) -// expect(trans._undo.b).toBeCloseTo(0) -// expect(trans._undo.c).toBeCloseTo(0) -// expect(trans._undo.d).toBeCloseTo(1) -// expect(trans._undo.e).toBeCloseTo(0) -// expect(trans._undo.f).toBeCloseTo(0) -// }) -// }) -// -// describe('at', function() { -// it('creates a matrix at a certain position', function() { -// expect(trans.at(0.75)).toEqual((new SVG.Matrix()).morph((new SVG.Matrix()).skew(30, -30, 50, 50)).at(0.75)) -// }) -// it('returns the inversed matrix from a specific position when created with inverse flag', function() { -// var morphed = (new SVG.Scale(skewed.transform(20,-20,50,50), true)).at(0.25) -// -// expect(morphed.a).toBeCloseTo(0.963) -// expect(morphed.b).toBeCloseTo(0) -// expect(morphed.c).toBeCloseTo(0) -// expect(morphed.d).toBeCloseTo(0.963) -// expect(morphed.e).toBeCloseTo(0) -// expect(morphed.f).toBeCloseTo(0) -// }) -// it('returns the resulting transformation which has to be made to set an absolute translation', function() { -// -// var morphed = trans.undo((new SVG.Matrix(10,0,0,10,0,0)).skew(20, 30, 20, 10).extract()).at(0.5) -// -// expect(morphed.a).toBeCloseTo(1.266) -// expect(morphed.b).toBeCloseTo(-0.7310) -// expect(morphed.c).toBeCloseTo(0.1351) -// expect(morphed.d).toBeCloseTo(0.9220) -// expect(morphed.e).toBeCloseTo(-20.05593) -// expect(morphed.f).toBeCloseTo(40.4468) -// }) -// }) -// }) -// }) diff --git a/spec/spec/use.js b/spec/spec/use.js index 0de5b39..5935710 100644 --- a/spec/spec/use.js +++ b/spec/spec/use.js @@ -14,7 +14,7 @@ describe('Use', function() { }) it('sets the target element id to its href attribute', function() { - expect(use.node.getAttributeNS(SVG.xlink, 'href')).toBe('#' + rect) + expect(use.node.getAttributeNS(SVG.namespaces.xlink, 'href')).toBe('#' + rect) }) it('adopts the geometry of the target element', function() { @@ -35,9 +35,9 @@ describe('Use', function() { }) it('sets the target element id and file path to its href attribute', function() { - expect(use.node.getAttributeNS(SVG.xlink, 'href')).toBe(file + '#' + id) + expect(use.node.getAttributeNS(SVG.namespaces.xlink, 'href')).toBe(file + '#' + id) }) }) - -}) \ No newline at end of file + +}) diff --git a/src/main.js b/src/main.js index 696dfdd..1ce11f7 100644 --- a/src/main.js +++ b/src/main.js @@ -7,7 +7,7 @@ import './modules/optional/memory.js' import './modules/optional/sugar.js' import './modules/optional/transform.js' -import { extend } from './utils/adopter.js' +import { extend, makeInstance } from './utils/adopter.js' import { getMethodNames, getMethodsFor } from './utils/methods.js' import Box from './types/Box.js' import Circle from './elements/Circle.js' @@ -46,6 +46,9 @@ import Svg from './elements/Svg.js' import Text from './elements/Text.js' import Tspan from './elements/Tspan.js' import * as defaults from './modules/core/defaults.js' +import * as utils from './utils/utils.js' +import * as namespaces from './modules/core/namespaces.js' +import * as regex from './modules/core/regex.js' export { Morphable, @@ -56,9 +59,8 @@ export { NonMorphable } -export { defaults } -export * from './utils/utils.js' -export * from './modules/core/namespaces.js' +export { defaults, utils, namespaces, regex } +export const SVG = makeInstance export { default as parser } from './modules/core/parser.js' export { default as find } from './modules/core/selector.js' export * from './modules/core/event.js' @@ -73,12 +75,12 @@ export { default as Runner } from './animation/Runner.js' export { default as Timeline } from './animation/Timeline.js' /* Types */ -export { default as SVGArray } from './types/SVGArray.js' +export { default as Array } from './types/SVGArray.js' export { default as Box } from './types/Box.js' export { default as Color } from './types/Color.js' export { default as EventTarget } from './types/EventTarget.js' export { default as Matrix } from './types/Matrix.js' -export { default as SVGNumber } from './types/SVGNumber.js' +export { default as Number } from './types/SVGNumber.js' export { default as PathArray } from './types/PathArray.js' export { default as Point } from './types/Point.js' export { default as PointArray } from './types/PointArray.js' diff --git a/src/svg.js b/src/svg.js index 4026598..e88b825 100644 --- a/src/svg.js +++ b/src/svg.js @@ -1,5 +1,4 @@ import * as svgMembers from './main.js' -import * as regex from './modules/core/regex.js' import { makeInstance } from './utils/adopter' // The main wrapping element @@ -8,7 +7,3 @@ export default function SVG (element) { } Object.assign(SVG, svgMembers) - -SVG.utils = SVG -SVG.regex = regex -SVG.get = SVG -- 2.39.5