progress on implementing core functionality

This commit is contained in:
janis
2024-01-15 17:02:41 +01:00
parent 328cf3b8e8
commit 2efd14b392
3 changed files with 59 additions and 11 deletions

View File

@@ -29,6 +29,8 @@
// as well as loading impress plugins from the ./plugins directory. A fully built impress.js version // as well as loading impress plugins from the ./plugins directory. A fully built impress.js version
// has all of these files combined into a single file, as to enable a simple include. // has all of these files combined into a single file, as to enable a simple include.
// All internal functions are (to be) prefixed with an underscore
( window as any ).impress = () => { ( window as any ).impress = () => {
let initializedElements = {}; let initializedElements = {};
@@ -40,12 +42,25 @@
* Defaults to the built-in plugins. * Defaults to the built-in plugins.
* @returns {undefined} * @returns {undefined}
*/ */
const init = ( pluginsToLoad?: Array<string> ): undefined => { const init = ( pluginsToLoad?: Array<Function> ): undefined => {
let toBeLoadedPlugins: Array<string> = [ '' ]; let toBeLoadedPlugins: Array<Function> = [];
if ( typeof pluginsToLoad !== 'undefined' ) { if ( typeof pluginsToLoad !== 'undefined' ) {
toBeLoadedPlugins = pluginsToLoad; toBeLoadedPlugins = pluginsToLoad;
} }
// TODO: Load plugins
for ( let plugin in toBeLoadedPlugins ) {
try {
toBeLoadedPlugins[ plugin ]();
} catch ( _e ) {
// Maybe somebody thinks they are funny to pass in an array of something but functions...
console.warn( 'impress().init() only accepts an array of functions! What you passed in was an array of ' + typeof( toBeLoadedPlugins[ plugin ] ) );
return;
}
}
// TODO: Load plugins, check if impress is supported
// Finally, with init done, send out the 'impress:init' event
document.dispatchEvent( new Event( 'impress:init' ) );
}; };
/** /**
@@ -81,6 +96,10 @@
id: DOMElementID, id: DOMElementID,
} }
_positionElements(); _positionElements();
// Dispatch event that an element was added
document.dispatchEvent( new Event( 'impress:addedElement' ) );
return true; return true;
}; };
@@ -97,6 +116,10 @@
return false; return false;
} }
_positionElements(); _positionElements();
// Dispatch event that an element was removed
document.dispatchEvent( new Event( 'impress:removedElement' ) );
return true; return true;
}; };
@@ -105,7 +128,8 @@
* @returns {undefined} * @returns {undefined}
*/ */
const _positionElements = (): undefined => { const _positionElements = (): undefined => {
// Gets current position and calls moveTo function
moveTo( getCurrentPos().coordinates, getCurrentPos().rotation );
} }
/** /**
@@ -122,7 +146,8 @@
*/ */
const moveTo = ( coordinates: object, rotation: object ): Promise<boolean> => { const moveTo = ( coordinates: object, rotation: object ): Promise<boolean> => {
return new Promise( ( resolve, reject ) => { return new Promise( ( resolve, reject ) => {
// Dispatch event telling all plugins that we're moving
document.dispatchEvent( new Event( 'impress:moving' ) );
} ); } );
} }
@@ -146,10 +171,12 @@
* Returns the current position as an object of form { coordinates: Object, rotation: Object } * Returns the current position as an object of form { coordinates: Object, rotation: Object }
* @returns {Object} * @returns {Object}
*/ */
const getCurrentPos = (): Object => { const getCurrentPos = (): { coordinates: { x: number; y: number; z: number; }, rotation: { x: number; y: number; z: number; } } => {
return {}; return { coordinates: { x: 0, y: 0, z: 0, }, rotation: { x: 0, y: 0, z: 0, } };
} }
// Return all functions that are exposed by impress
return { return {
init, init,
getElements, getElements,

View File

@@ -22,7 +22,7 @@
</div> </div>
</div> </div>
<script src="./impress.js"/> <script src="/built/impress.js"/>
<script>impress().init()</script> <script>impress().init()</script>
</body> </body>
</html> </html>

View File

@@ -0,0 +1,21 @@
/* ! 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