From 2efd14b3926b002340697ce8daadd638e2eb9dea Mon Sep 17 00:00:00 2001 From: janis Date: Mon, 15 Jan 2024 17:02:41 +0100 Subject: [PATCH] progress on implementing core functionality --- src/impress.ts | 47 +++++++++++++++++++++++++++++++++++++---------- src/index.html | 2 +- src/lib/util.ts | 21 +++++++++++++++++++++ 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/impress.ts b/src/impress.ts index e0acc26..226ef96 100644 --- a/src/impress.ts +++ b/src/impress.ts @@ -29,9 +29,11 @@ // 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. +// All internal functions are (to be) prefixed with an underscore + ( window as any ).impress = () => { let initializedElements = {}; - + /** * This function is used to initialize impress. It calls some prep functions and then loads * all plugins that are registered. By default, these are the built-in plugins. You can define @@ -39,13 +41,26 @@ * @param {Array|undefined} [pluginsToLoad] An array of plugins to load when initializing impress. * Defaults to the built-in plugins. * @returns {undefined} - */ - const init = ( pluginsToLoad?: Array ): undefined => { - let toBeLoadedPlugins: Array = [ '' ]; + */ + const init = ( pluginsToLoad?: Array ): undefined => { + let toBeLoadedPlugins: Array = []; 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, } _positionElements(); + + // Dispatch event that an element was added + document.dispatchEvent( new Event( 'impress:addedElement' ) ); + return true; }; @@ -97,6 +116,10 @@ return false; } _positionElements(); + + // Dispatch event that an element was removed + document.dispatchEvent( new Event( 'impress:removedElement' ) ); + return true; }; @@ -105,7 +128,8 @@ * @returns {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 => { 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 {Object} */ - const getCurrentPos = (): Object => { - return {}; + const getCurrentPos = (): { coordinates: { x: number; y: number; z: number; }, rotation: { x: number; y: number; z: number; } } => { + return { coordinates: { x: 0, y: 0, z: 0, }, rotation: { x: 0, y: 0, z: 0, } }; } + + // Return all functions that are exposed by impress return { init, getElements, diff --git a/src/index.html b/src/index.html index 278a9b4..af634ab 100644 --- a/src/index.html +++ b/src/index.html @@ -22,7 +22,7 @@ - \ No newline at end of file diff --git a/src/lib/util.ts b/src/lib/util.ts index e69de29..fc81e3e 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -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 \ No newline at end of file