diff --git a/HypeDataMagic.prod.min.js b/HypeDataMagic.prod.min.js index a24affb..fd4e9c6 100644 --- a/HypeDataMagic.prod.min.js +++ b/HypeDataMagic.prod.min.js @@ -1,11 +1,11 @@ /* - Hype DataMagic 1.4.0 -copyright (c) 2022 Max Ziebell, (https://maxziebell.de). MIT-license + Hype DataMagic 1.4.1 +copyright (c) 2024 Max Ziebell, (https://maxziebell.de). MIT-license */ !1==="HypeDataMagic"in window&&(window.HypeDataMagic=function(){function t(a,b){return"string"===typeof a?u(a,b):"object"===typeof a?r(a,b):a}function v(a,b){return Object.assign({},f.variables||a.customData,{resourcesFolderName:a.resourcesFolderURL()},b&&f.allowDatasets?{dataset:G(b)}:null)}function H(a,b,c){if(c.handler)if("()"==c.handler.slice(-2)){if(a.functions){try{var d=a.functions()[c.handler.slice(0,-2)](a,b,c)}catch(e){console.log('There was an error in your handler "'+c.handler+'": ',e)}return d}}else if("object"== -typeof k[c.handler]&&"function"==typeof k[c.handler][c.type]){try{d=k[c.handler][c.type](a,b,c)}catch(e){console.log('There was an error in your handler "'+c.handler+'": ',e)}return d}}function z(a,b,c){if(b.getAttribute("data-magic-key")){var d=I(b.getAttribute("data-magic-key")).split(":"),e=d[1]?d[1]:d[0],g=(d[1]?d[0].trim():null)||A(b,"data-magic-source")||f.source,h="customData"==g?a.customData:B(g);if(h)if(d=d[1]?"":A(b,"data-magic-branch",!0,b.closest("[data-magic-source]")),console.log(b.closest("[data-magic-source]")), -h=d?m(h,d):h,h=m(h,e),null!=h){if("object"!=typeof h&&"function"!=typeof h){d=b.getAttribute("data-magic-prefix")||"";var J=b.getAttribute("data-magic-append")||"";if(d||J)h=d+h+J}f.autoVariables&&f.allowVariables&&(d=v(a,b),h=t(h,d));c=Object.assign({},c,{data:h,source:g,key:e});e=c.type?c.type.replace("HypeScene","DataMagic").split():["DataMagicPrepareForDisplay","DataMagicLoad"];var Q=(b.getAttribute("data-magic-handler")||f.handler).split(",");e.forEach(function(R){var K;Q.forEach(function(S){K= -H(a,b,Object.assign({},c,K,{type:R,handler:S.trim()}))})})}else w(a,b)}}function w(a,b,c){c=Object.assign({},c);handlers=(c.oldHandler||b.getAttribute("data-magic-handler")||f.handler).split(",");var d;handlers.forEach(function(e){d=H(a,b,Object.assign({},c,d,{type:"DataMagicUnload",handler:e.trim()}))})}function L(a){return!a.querySelectorAll(".HYPE_element, .HYPE_element_container").length}function T(a,b){n[a.documentId()]||(n[a.documentId()]={changeObserver:new MutationObserver(function(c){c.forEach(function(d){if("attributes"== +typeof k[c.handler]&&"function"==typeof k[c.handler][c.type]){try{d=k[c.handler][c.type](a,b,c)}catch(e){console.log('There was an error in your handler "'+c.handler+'": ',e)}return d}}function z(a,b,c){if(b.getAttribute("data-magic-key")){var d=I(b.getAttribute("data-magic-key")).split(":"),e=d[1]?d[1]:d[0],g=(d[1]?d[0].trim():null)||A(b,"data-magic-source")||f.source,h="customData"==g?a.customData:B(g);if(h)if(h=(d=d[1]?"":A(b,"data-magic-branch",!0,b.closest("[data-magic-source]")))?m(h,d):h,h= +m(h,e),null!=h){if("object"!=typeof h&&"function"!=typeof h){d=b.getAttribute("data-magic-prefix")||"";var J=b.getAttribute("data-magic-append")||"";if(d||J)h=d+h+J}f.autoVariables&&f.allowVariables&&(d=v(a,b),h=t(h,d));c=Object.assign({},c,{data:h,source:g,key:e});e=c.type?c.type.replace("HypeScene","DataMagic").split():["DataMagicPrepareForDisplay","DataMagicLoad"];var Q=(b.getAttribute("data-magic-handler")||f.handler).split(",");e.forEach(function(R){var K;Q.forEach(function(S){K=H(a,b,Object.assign({}, +c,K,{type:R,handler:S.trim()}))})})}else w(a,b)}}function w(a,b,c){c=Object.assign({},c);handlers=(c.oldHandler||b.getAttribute("data-magic-handler")||f.handler).split(",");var d;handlers.forEach(function(e){d=H(a,b,Object.assign({},c,d,{type:"DataMagicUnload",handler:e.trim()}))})}function L(a){return!a.querySelectorAll(".HYPE_element, .HYPE_element_container").length}function T(a,b){n[a.documentId()]||(n[a.documentId()]={changeObserver:new MutationObserver(function(c){c.forEach(function(d){if("attributes"== d.type){var e=d.target,g=d.attributeName,h=I(e.getAttribute(g));d=d.oldValue;if(h!=d)switch(g){case "data-magic-key":h?z(a,e):w(a,e);break;case "data-magic-source":case "data-magic-branch":w(a,e);l(a,e);break;case "data-magic-handler":w(a,e,{oldHandler:d});l(a,e);break;case "data-magic-prefix":case "data-magic-append":l(a,e)}}})}),options:{subtree:!0,attributes:!0,attributeFilter:"data-magic-key data-magic-source data-magic-branch data-magic-handler data-magic-prefix data-magic-append".split(" "), attributeOldValue:!0},enable:function(){this.changeObserver.observe(b,this.options)},disable:function(){this.changeObserver.disconnect()}})}function C(a){n[a.documentId()]&&n[a.documentId()].enable()}function D(a){n[a.documentId()]&&n[a.documentId()].disable()}function M(a,b,c){b&&b.querySelectorAll("[data-magic-key]").forEach(function(d){z(a,d,c);(f.forceRedrawElement||f.forceRedrawElementNonIDE)&&E(d)})}function N(a,b,c){b&&(z(a,b,c),(1==f.forceRedrawElement||f.forceRedrawElementNonIDE)&&E(b))} function l(a,b,c){b&&(N(a,b,c),M(a,b,c),(1==f.forceRedrawDocument||f.forceRedrawDocumentNonIDE)&&E(b))}function B(a,b){if(f.sourceRedirect[a])return p[f.sourceRedirect[a]]||null;a||(a=f.source);var c=p[a]||null;return c&&b?m(c,b):c}function O(a){a&&a.hasOwnProperty("refresh")?a.refresh():window.hasOwnProperty("HYPE")&&Object.values(window.HYPE.documents).forEach(function(b){b.hasOwnProperty("refresh")&&b.refresh()})}function I(a){if("string"==typeof a)return a.trim()}function x(a){if(Array.isArray(a))return a.reduce(function(b, @@ -18,5 +18,5 @@ b,c){b.innerHTML!=c.data&&L(b)&&(!f.autoVariables&&f.allowVariables&&(a=v(a,b),c {src:c.data});c.data.src||(c.data.src=b.dataset.fallbackImage||f.fallbackImage());if(!f.autoVariables&&f.allowVariables){var d=v(a,b);c.data=t(c.data,d)}b.innerHTML="";a.getElementProperty(b,"background-image")!=c.data.src&&(b.style.backgroundRepeat="no-repeat",b.style.backgroundPosition=c.data.backgroundPosition||b.dataset.backgroundPosition||"center center",b.style.backgroundSize=c.data.backgroundSize||b.dataset.backgroundSize||"contain",a.setElementProperty(b,"background-image",c.data.src))},DataMagicUnload:function(a, b,c){a.setElementProperty(b,"background-image","");b.style.backgroundRepeat=b.style.backgroundPosition=""}}};q(l);var P=q(O);!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeDocumentLoad",callback:function(a,b,c){a.refresh=function(d){l(this,d||document.getElementById(this.currentSceneId()))};a.refreshDebounced=q(a.refresh);a.refreshDescendants=function(d){M(this,d||document.getElementById(this.currentSceneId()))};a.refreshDescendantsDebounced= q(a.refreshDescendants);a.refreshElement=function(d){N(this,d)};a.refreshElementDebounced=q(a.refreshElement);a.disableChangeObserver=function(){D(this)};a.enableChangeObserver=function(){C(this)};a.setContentIfNecessary=function(d,e){d.innerHTML!=e&&(d.innerHTML=e)};f.customData&&(a.customData=Object.assign(a.customData,f.customData));T(a,b);C(a)}});window.HYPE_eventListeners.push({type:"HypeScenePrepareForDisplay",callback:function(a,b,c){D(a);l(a,b,c)}});window.HYPE_eventListeners.push({type:"HypeSceneLoad", -callback:function(a,b,c){l(a,b,c);C(a)}});window.HYPE_eventListeners.push({type:"HypeSceneUnload",callback:function(a,b,c){D(a)}});return{version:"1.4.0",setData:function(a,b,c){b=b||f.source;if(c){p[b]||(p[b]={});var d=x(c);c=d.pop();(b=m(p[b],d))&&(b[c]=a)}else p[b]=a;1==f.refreshOnSetData&&P()},getData:B,refresh:O,refreshDebounced:P,setDefault:function(a,b){f[a]=b},getDefault:function(a){return f[a]},addDataHandler:function(a,b){if("string"!=!typeof a)switch(typeof b){case "object":k[a]=Object.assign({}, +callback:function(a,b,c){l(a,b,c);C(a)}});window.HYPE_eventListeners.push({type:"HypeSceneUnload",callback:function(a,b,c){D(a)}});return{version:"1.4.1",setData:function(a,b,c){b=b||f.source;if(c){p[b]||(p[b]={});var d=x(c);c=d.pop();(b=m(p[b],d))&&(b[c]=a)}else p[b]=a;1==f.refreshOnSetData&&P()},getData:B,refresh:O,refreshDebounced:P,setDefault:function(a,b){f[a]=b},getDefault:function(a){return f[a]},addDataHandler:function(a,b){if("string"!=!typeof a)switch(typeof b){case "object":k[a]=Object.assign({}, f.handlerMixin,b);break;case "function":k[a]=Object.assign({},f.handlerMixin,k.text),k[a].DataMagicPrepareForDisplay=b}},resolveObjectByKey:m,resolveKeyToArray:x,resolveVariablesInString:u,resolveVariablesInObject:r,cloneObject:F,findAttribute:A,resolveVariables:t,constructVariablesContext:v,debounceByRequestFrame:q}}());