some progress on util

This commit is contained in:
2024-07-21 08:50:00 +02:00
parent 1d185e05a7
commit ef80cf45dc
4 changed files with 89 additions and 35 deletions

View File

@@ -3,8 +3,10 @@ module.exports = {
'browser': true, 'browser': true,
'es6': true 'es6': true
}, },
'extends': ['eslint:recommended', 'extends': [
'plugin:@typescript-eslint/recommended'], 'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
'globals': { 'globals': {
'Atomics': 'readonly', 'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly' 'SharedArrayBuffer': 'readonly'
@@ -100,7 +102,6 @@ module.exports = {
'lines-around-comment': 'error', 'lines-around-comment': 'error',
'lines-around-directive': 'off', 'lines-around-directive': 'off',
'lines-between-class-members': 'error', 'lines-between-class-members': 'error',
'max-classes-per-file': 'error',
'max-depth': 'error', 'max-depth': 'error',
'max-len': 'off', 'max-len': 'off',
'max-lines': 'error', 'max-lines': 'error',

View File

@@ -23,7 +23,7 @@
// Let us show you! // Let us show you!
// Please note that compared to previous versions of impress, this code is documented in a more technical fashion. // 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 // 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: // 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 ImpressInitError extends Error {}
class ImpressConfig { class ImpressConfig {
// eslint-disable-next-line max-params
constructor( width, height, perspective, transitionDuration, maxScale, minScale ) { constructor( width, height, perspective, transitionDuration, maxScale, minScale ) {
this.width = width; this.width = width;
this.height = height; this.height = height;
@@ -153,7 +154,7 @@ window.impress = ( impressConfig ) => {
rotation: rotation, rotation: rotation,
id: DOMElementID id: DOMElementID
}; };
_positionElements(); positionElements();
// Dispatch event that an element was added // Dispatch event that an element was added
document.dispatchEvent( new Event( 'impress:addedElement' ) ); document.dispatchEvent( new Event( 'impress:addedElement' ) );
@@ -173,7 +174,7 @@ window.impress = ( impressConfig ) => {
} catch ( err ) { } catch ( err ) {
return false; return false;
} }
_positionElements(); positionElements();
// Dispatch event that an element was removed // Dispatch event that an element was removed
document.dispatchEvent( new Event( 'impress:removedElement' ) ); 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 * Internal function that positions elements on the canvas. Called every time a element is added / removed
* @returns {undefined} * @returns {undefined}
*/ */
const _positionElements = () => { const positionElements = () => {
// Gets current position and calls moveTo function // Gets current position and calls moveTo function
moveTo( getCurrentPos().coordinates, getCurrentPos().rotation ); moveTo( getCurrentPos().coordinates, getCurrentPos().rotation );
}; };
@@ -232,18 +233,16 @@ window.impress = ( impressConfig ) => {
* Use this function to get the current impress config * Use this function to get the current impress config
* @returns {ImpressConfig} Returns the current impress config * @returns {ImpressConfig} Returns the current impress config
*/ */
const getCurrentConfig = () => { const getCurrentConfig = () => impressConfig;
return impressConfig;
}
/** /**
* Update the impress config. * Update the impress config.
* @param {ImpressConfig} impressConfig The new impress config * @param {ImpressConfig} impressConfigs The new impress config
* @returns {undefined} Returns nothing * @returns {undefined} Returns nothing
*/ */
const updateConfig = ( impressConfig ) => { const updateConfig = ( impressConfigs ) => {
impressConfig = impressConfig; 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 all functions that are exposed by impress. This is superior to using classes as we can control what functions we expose.
return { return {

View File

@@ -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

75
src/lib/vectorUtil.js Normal file
View File

@@ -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
};
};