1- // https://lib.presenta.cc v1.0.11 - BSD-3-Clause License - Copyright 2022 Fabio Franchino
1+ // https://lib.presenta.cc v1.0.12 - BSD-3-Clause License - Copyright 2022 Fabio Franchino
22( function ( global , factory ) {
33 typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( ) :
44 typeof define === 'function' && define . amd ? define ( factory ) :
55 ( global = typeof globalThis !== 'undefined' ? globalThis : global || self , global . Presenta = factory ( ) ) ;
66} ) ( this , ( function ( ) { 'use strict' ;
77
8- var version = "1.0.11 " ;
8+ var version = "1.0.12 " ;
99
1010 function styleInject ( css , ref ) {
1111 if ( ref === void 0 ) ref = { } ;
@@ -1277,27 +1277,7 @@ window._sdpcallbackfunc()
12771277 </div>
12781278 </div>
12791279 </div>` ) ;
1280- el . appendChild ( child ) ; // if there are images, let's exploit the alt attribute if contains a number
1281- // as a scale multiplier
1282- // let images = child.querySelectorAll('img')
1283- // if (images) {
1284- // images = [...images].forEach(img => {
1285- // const a = img.getAttribute('alt')
1286- // if (a) {
1287- // const val = +a
1288- // if (val > 0) img.style.height = 4 * val + 'em'
1289- // }
1290- // })
1291- // }
1292- // let isObserved = false
1293- // let isComputing = false
1294- // const resizeObserver = new ResizeObserver(() => {
1295- // if (!isComputing) {
1296- // resizeObserver.disconnect()
1297- // compute()
1298- // }
1299- // })
1300- // this is the iterative scale routine
1280+ el . appendChild ( child ) ; // this is the iterative scale routine
13011281
13021282 const compute = ( ) => {
13031283 child . style . setProperty ( '--textSize' , `${ fsize } ${ funit } ` ) ;
@@ -1310,12 +1290,7 @@ window._sdpcallbackfunc()
13101290 resolve ( that ) ;
13111291 } ) ;
13121292 return false ;
1313- } // isComputing = true
1314- // if (!isObserved) {
1315- // resizeObserver.observe(el)
1316- // isObserved = true
1317- // }
1318-
1293+ }
13191294
13201295 const mbox = mel . getBoundingClientRect ( ) ;
13211296 const bbox = el . getBoundingClientRect ( ) ;
@@ -1327,24 +1302,20 @@ window._sdpcallbackfunc()
13271302 } else {
13281303 setTimeout ( ( ) => {
13291304 child . classList . remove ( css$9 . promise ) ;
1330- resolve ( that ) ; // isComputing = false
1305+ resolve ( that ) ;
13311306 } ) ;
13321307 }
13331308 } ;
13341309
13351310 if ( config . font ) {
1336- fetch ( config . font ) . then ( res => {
1337- setTimeout ( compute ) ;
1338- } ) . catch ( err => {
1339- console . log ( 'error on preload font' , err ) ;
1311+ document . fonts . ready . then ( ( ) => {
13401312 setTimeout ( compute ) ;
13411313 } ) ;
13421314 } else {
13431315 setTimeout ( compute ) ;
13441316 }
13451317
1346- that . destroy = ( ) => { // resizeObserver.disconnect()
1347- } ;
1318+ setTimeout ( compute ) ;
13481319 } ) ;
13491320 } ;
13501321
@@ -1811,7 +1782,7 @@ window._sdpcallbackfunc()
18111782 return new Promise ( ( resolve , reject ) => {
18121783 that . type = blockConfig . aliasType || blockConfig . type ;
18131784 that . index = blockConfig . _index ;
1814- var blockInstance = null ;
1785+ let blockInstance = null ;
18151786 const sceneConfig = blockConfig . _sceneConfig || { } ;
18161787 blockConfig . contextType = 'block' ;
18171788 const modInstances = [ ] ;
@@ -2374,6 +2345,73 @@ window._sdpcallbackfunc()
23742345 return err ;
23752346 } ) ;
23762347
2348+ const installed = { } ;
2349+ const listeners = [ ] ;
2350+ let loading = false ;
2351+
2352+ const Install = function ( config ) {
2353+ return new Promise ( ( resolve , reject ) => {
2354+ let len = 0 ;
2355+ let cnt = 0 ;
2356+ if ( config . length === 0 ) resolve ( ) ;
2357+ config . forEach ( s => {
2358+ const addSource = url => {
2359+ setTimeout ( ( ) => {
2360+ const newScript = document . createElement ( 'script' ) ;
2361+
2362+ newScript . onerror = err => {
2363+ console . log ( '[Plugin error]' , err ) ;
2364+ cnt ++ ;
2365+
2366+ if ( cnt === len ) {
2367+ resolve ( ) ;
2368+ listeners . forEach ( p => {
2369+ p . resolve ( ) ;
2370+ } ) ;
2371+ loading = false ;
2372+ }
2373+ } ;
2374+
2375+ newScript . onload = ldr => {
2376+ console . log ( '[Plugin loaded]' ) ;
2377+ cnt ++ ;
2378+
2379+ if ( cnt === len ) {
2380+ resolve ( ) ;
2381+ listeners . forEach ( res => {
2382+ res ( ) ;
2383+ } ) ;
2384+ loading = false ;
2385+ }
2386+ } ;
2387+
2388+ document . body . appendChild ( newScript ) ;
2389+ newScript . src = url ;
2390+ } , len ) ;
2391+ } ;
2392+
2393+ const addNotifier = url => {
2394+ listeners . push ( resolve ) ;
2395+ cnt ++ ;
2396+ } ;
2397+
2398+ len ++ ;
2399+
2400+ if ( ! installed [ s . url ] ) {
2401+ loading = true ;
2402+ addSource ( s . url ) ;
2403+ installed [ s . url ] = s ;
2404+ } else {
2405+ if ( loading ) {
2406+ addNotifier ( s . url ) ;
2407+ } else {
2408+ resolve ( ) ;
2409+ }
2410+ }
2411+ } ) ;
2412+ } ) ;
2413+ } ;
2414+
23772415 const plugInit = ( all , plugs , store ) => {
23782416 const activeKeys = Object . keys ( plugs ) ;
23792417 activeKeys . forEach ( k => {
@@ -2437,12 +2475,13 @@ window._sdpcallbackfunc()
24372475 config . _root = root ;
24382476 const splash = new Splash ( root , config ) ;
24392477 return new Promise ( ( resolve , reject ) => {
2440- // new Install(config.plugins).then(() => {
2441- const all = pluginsInit ( config ) ;
2442- Promise . all ( all ) . then ( values => {
2443- resolve ( new Container ( root , config ) ) ;
2444- splash . destroy ( ) ;
2445- } ) ; // })
2478+ new Install ( config . plugins ) . then ( ( ) => {
2479+ const all = pluginsInit ( config ) ;
2480+ Promise . all ( all ) . then ( values => {
2481+ resolve ( new Container ( root , config ) ) ;
2482+ splash . destroy ( ) ;
2483+ } ) ;
2484+ } ) ;
24462485 } ) ;
24472486 } ;
24482487
@@ -2454,9 +2493,7 @@ window._sdpcallbackfunc()
24542493 controllers,
24552494 modules,
24562495 blocks
2457- } ; // Presenta.addGlob = utils.addGlob
2458- // Presenta.addProp = utils.addProp
2459-
2496+ } ;
24602497 Presenta . io = utils . io ;
24612498
24622499 Presenta . use = plugin => {
0 commit comments