From ef80cf45dc39ef657967b72d3c70432d76f82eb5 Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sun, 21 Jul 2024 08:50:00 +0200 Subject: [PATCH] some progress on util --- .eslintrc.js | 7 ++-- src/impress.js | 21 ++++++------ src/lib/util.js | 21 ------------ src/lib/vectorUtil.js | 75 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 35 deletions(-) delete mode 100644 src/lib/util.js create mode 100644 src/lib/vectorUtil.js diff --git a/.eslintrc.js b/.eslintrc.js index be83c19..8be72c8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,8 +3,10 @@ module.exports = { 'browser': true, 'es6': true }, - 'extends': ['eslint:recommended', - 'plugin:@typescript-eslint/recommended'], + 'extends': [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended' + ], 'globals': { 'Atomics': 'readonly', 'SharedArrayBuffer': 'readonly' @@ -100,7 +102,6 @@ module.exports = { 'lines-around-comment': 'error', 'lines-around-directive': 'off', 'lines-between-class-members': 'error', - 'max-classes-per-file': 'error', 'max-depth': 'error', 'max-len': 'off', 'max-lines': 'error', diff --git a/src/impress.js b/src/impress.js index 0770c3c..3101e91 100644 --- a/src/impress.js +++ b/src/impress.js @@ -23,7 +23,7 @@ // Let us show you! // Please note that compared to previous versions of impress, this code is documented in a more technical fashion. // A lot has changed compared to V2, so re-reading the code or documentation is highly recommended before you start -// developing and updating plugins. There is a guide on how to migrate plugins from API V2 to API V3. +// developing and updating plugins. There is a guide on how to migrate plugins from API V2 to API V3. // Important note on the file structure of impress.js, as it has changed with V3: // ------------------------------------------------------------------------------- @@ -37,6 +37,7 @@ class ImpressNotSupportedError extends Error {} class ImpressInitError extends Error {} class ImpressConfig { + // eslint-disable-next-line max-params constructor( width, height, perspective, transitionDuration, maxScale, minScale ) { this.width = width; this.height = height; @@ -153,7 +154,7 @@ window.impress = ( impressConfig ) => { rotation: rotation, id: DOMElementID }; - _positionElements(); + positionElements(); // Dispatch event that an element was added document.dispatchEvent( new Event( 'impress:addedElement' ) ); @@ -173,7 +174,7 @@ window.impress = ( impressConfig ) => { } catch ( err ) { return false; } - _positionElements(); + positionElements(); // Dispatch event that an element was removed document.dispatchEvent( new Event( 'impress:removedElement' ) ); @@ -184,7 +185,7 @@ window.impress = ( impressConfig ) => { * Internal function that positions elements on the canvas. Called every time a element is added / removed * @returns {undefined} */ - const _positionElements = () => { + const positionElements = () => { // Gets current position and calls moveTo function moveTo( getCurrentPos().coordinates, getCurrentPos().rotation ); }; @@ -232,18 +233,16 @@ window.impress = ( impressConfig ) => { * Use this function to get the current impress config * @returns {ImpressConfig} Returns the current impress config */ - const getCurrentConfig = () => { - return impressConfig; - } + const getCurrentConfig = () => impressConfig; /** * Update the impress config. - * @param {ImpressConfig} impressConfig The new impress config + * @param {ImpressConfig} impressConfigs The new impress config * @returns {undefined} Returns nothing */ - const updateConfig = ( impressConfig ) => { - impressConfig = impressConfig; - } + const updateConfig = ( impressConfigs ) => { + impressConfig = impressConfigs; + }; // Return all functions that are exposed by impress. This is superior to using classes as we can control what functions we expose. return { diff --git a/src/lib/util.js b/src/lib/util.js deleted file mode 100644 index fc81e3e..0000000 --- a/src/lib/util.js +++ /dev/null @@ -1,21 +0,0 @@ -/* ! Licensed under MIT License - https://github.com/impress/impress.js/blob/master/LICENSE */ -/** - * impress.js - * - * impress.js is a presentation tool based on the power of CSS3 transforms and transitions - * in modern browsers and inspired by the idea behind prezi.com. - * - * - * Copyright 2011-2012 Bartek Szopka (@bartaz), 2016-2024 Henrik Ingo (@henrikingo), 2024 Janis Hutz - * and 70+ other contributors - * - * Released under the MIT License. - * - * ------------------------------------------------ - * authors: Bartek Szopka, Henrik Ingo, Janis Hutz - * version: 3.0.0 - * url: http://impress.js.org - * source: http://github.com/impress/impress.js/ - */ - -// Welcome to the util.ts file. This file exposes various functions for use in calculating with vectors \ No newline at end of file diff --git a/src/lib/vectorUtil.js b/src/lib/vectorUtil.js new file mode 100644 index 0000000..8e5cbd9 --- /dev/null +++ b/src/lib/vectorUtil.js @@ -0,0 +1,75 @@ +/* ! Licensed under MIT License - https://github.com/impress/impress.js/blob/master/LICENSE */ +/** + * impress.js + * + * impress.js is a presentation tool based on the power of CSS3 transforms and transitions + * in modern browsers and inspired by the idea behind prezi.com. + * + * + * Copyright 2011-2012 Bartek Szopka (@bartaz), 2016-2024 Henrik Ingo (@henrikingo), 2024 Janis Hutz + * and 70+ other contributors + * + * Released under the MIT License. + * + * ------------------------------------------------ + * authors: Bartek Szopka, Henrik Ingo, Janis Hutz + * version: 3.0.0 + * url: http://impress.js.org + * source: http://github.com/impress/impress.js/ + */ + +// Welcome to the vectorUtil.js file. This file exposes various functions for use in calculating with vectors + +class Vector { + + /** + * Description + * @param {number} x The x-coordinate + * @param {number} y The y-coordinate + * @param {number} z The z-coordinate + * @returns {undefined} Returns nothing + */ + constructor ( x, y, z ) { + this.x = x; + this.y = y; + this.z = z; + } +} + +window.impressVectorUtil = () => { + + /** + * Get the cross product of two vectors (https://en.wikipedia.org/wiki/Cross_product) + * @param {Vector} vec1 The first vector + * @param {Vector} vec2 The second vector + * @returns {Vector} Returns a vector object + */ + const vectorProduct = ( vec1, vec2 ) => new Vector( + ( vec1.y * vec2.z ) - ( vec1.z * vec2.y ), + ( vec1.z * vec2.x ) - ( vec1.x * vec2.z ), + ( vec1.x * vec2.y ) - ( vec1.y * vec2.x ) + ); + + /** + * Get the dot product of two vectors (https://en.wikipedia.org/wiki/Dot_product) + * @param {Vector} vec1 The first vector + * @param {Vector} vec2 The second vector + * @returns {number} Returns the calculated value of the dot product + */ + const dotProduct = ( vec1, vec2 ) => ( vec1.x * vec2.x ) + ( vec1.y * vec2.y ) + ( vec1.z * vec2.z ); + + /** + * Get the norm of a vector (https://en.wikipedia.org/wiki/Norm_(mathematics)) + * @param {Vector} vec The vector of which to calculate the norm + * @returns {number} Returns the norm + */ + var norm = function( vec ) { + return Math.sqrt( ( vec.x * vec.x ) + ( vec.y * vec.y ) + ( vec.z * vec.z ) ); + }; + + return { + norm, + dotProduct, + vectorProduct + }; +};