From 714c4ae3681f9bf134dc0b6c4cf3c139d75359fa Mon Sep 17 00:00:00 2001 From: joostdecock Date: Wed, 21 Jun 2023 11:46:35 +0200 Subject: [PATCH] feat(core): Added snippet.scale() and snippet.rotate() methods --- packages/core/src/snippet.mjs | 24 ++++++++++++++++++++++++ packages/core/tests/snippet.test.mjs | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/packages/core/src/snippet.mjs b/packages/core/src/snippet.mjs index 88244a4d120..85e6a465eae 100644 --- a/packages/core/src/snippet.mjs +++ b/packages/core/src/snippet.mjs @@ -52,6 +52,30 @@ Snippet.prototype.clone = function () { return clone } +/** + * Helper method to scale a snippet + * + * @param {number} scale - The scale to set + * @param {bool} overwrite - Whether to overwrite the existing scale or not (default is true) + * + * @return {Snippet} this - The snippet instance + */ +Snippet.prototype.scale = function (scale, overwrite = true) { + return this.attr('data-scale', scale, overwrite) +} + +/** + * Helper method to rotate a snippet + * + * @param {number} rotation - The rotation to set + * @param {bool} overwrite - Whether to overwrite the existing rotation or not (default is true) + * + * @return {Snippet} this - The snippet instance + */ +Snippet.prototype.rotate = function (rotation, overwrite = true) { + return this.attr('data-rotate', rotation, overwrite) +} + /** * Returns a snippet as an object suitable for inclusion in renderprops * diff --git a/packages/core/tests/snippet.test.mjs b/packages/core/tests/snippet.test.mjs index 9500ad0dc8c..6d80e94c850 100644 --- a/packages/core/tests/snippet.test.mjs +++ b/packages/core/tests/snippet.test.mjs @@ -27,6 +27,16 @@ describe('Snippet', () => { expect(s.attributes.get('class')).to.equal('less') }) + it('Should scale a snippet', () => { + let s = new Snippet('test', new Point(12, -34)).scale(0.1234) + expect(s.attributes.get('data-scale')).to.equal('0.1234') + }) + + it('Should rotate a snippet', () => { + let s = new Snippet('test', new Point(12, -34)).rotate(123) + expect(s.attributes.get('data-rotate')).to.equal('123') + }) + it('Should get a snippet via the snippets proxy', () => { let result const part = {