-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HypeDataMagic.prod.min.js
22 lines (22 loc) · 8.98 KB
/
HypeDataMagic.prod.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
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(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,
c){return b.concat(x(c))},[]);if("string"==typeof a)return a=a.replace(/\[(\d+)\]/g,function(b,c){return"."+parseInt(c)}),a=a.replace(/^\./,""),a.split(".")}function m(a,b){if("object"==typeof a){for(var c=x(b),d=a,e=0;void 0!==d&&e<c.length;)d=d[c[e]],f.allowDataFunctions&&"function"===typeof d&&(d=d()),e++;return d}}function r(a,b,c){"object"===typeof a?(c||(a=F(a)),Object.keys(a).forEach(function(d){a[d]=r(a[d],b,!0)})):"function"===typeof a?a[key]=r(a[key](),b,!0):"string"===typeof a&&(a=u(a,
b));return a}function u(a,b){if("string"===typeof a){var c=a.match(/\${.*?}|%{.*?}|\u2728{.*?}/g);c&&c.forEach(function(d){var e=d.replace(/\$\{|%\{|\u2728\{|\}|\(\)/g,"").split(":"),g=e[1]?e[1]:e[0];e=e[1]?B(e[0].trim()):null;g=m(e||b,g);a=a.replace(d,g)})}return a}function F(a){if(null==a||"object"!=typeof a)return a;var b=a.constructor(),c;for(c in a)a.hasOwnProperty(c)&&(b[c]=F(a[c]));return b}function A(a,b,c,d){if(!a)return null;for(var e="";null!==a;){var g=a.getAttribute(b);if(null!==g)if(c&&
0==g.indexOf("+"))e=g.slice(1)+(e?"."+e:"");else return g+(e?"."+e:"");(a=a.parentNode.closest("["+b+"]"))&&d&&!d.contains(a)&&(a=null)}}function G(a){var b=Object.assign({},a.dataset);if(f.allowMagicSets&&b.magicSets)for(var c=b.magicSets.split(","),d=0;d<c.length;){var e=c[d].trim();switch(e){case "parent":(e=a.parentElement.parentElement)&&y(b,e.dataset);break;case "parents":for(e=a.parentElement;e&&!e.classList.contains("HYPE_scene");)y(b,e.dataset),e=e.parentElement;break;default:0===e.indexOf("closest(")&&
e.indexOf(")")===e.length-1?(e=e.substring(8,e.length-1),(e=a.closest(e))&&y(b,e.dataset)):document.querySelectorAll(e).forEach(function(g){y(b,g.dataset)})}d++}return b}function y(a,b){for(var c in b)a.hasOwnProperty(c)||(a[c]=b[c])}function q(a){return function(){if(!a.timeout){var b=arguments;a.timeout=requestAnimationFrame(function(){a.apply(this,b);a.timeout=null}.bind(this))}}}var p={},n={},f={source:"shared",fallbackImage:function(){return"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="},
handler:"text",variables:null,handlerMixin:{},sourceRedirect:{},refreshOnSetData:!0,refreshOnCustomData:!0,forceRedrawElement:!1,forceRedrawElementNonIDE:!1,forceRedrawDocument:!1,forceRedrawDocumentNonIDE:!1,highlightDataMagic:!0,allowDataFunctions:!0,allowVariables:!0,allowDatasets:!0,allowMagicSets:!0,autoVariables:!0,resourcesFolderNameForPreview:""},E=function(a){var b=a.style.display;a.style.display="none";void 0!=a.offsetHeight;a.style.display=b},k={text:{DataMagicPrepareForDisplay:function(a,
b,c){b.innerHTML!=c.data&&L(b)&&(!f.autoVariables&&f.allowVariables&&(a=v(a,b),c.data=t(c.data,a)),b.innerHTML=c.data)},DataMagicUnload:function(a,b,c){L(b)&&(b.innerHTML="")}},variables:{DataMagicPrepareForDisplay:function(a,b,c){f.allowVariables&&(c.data=u(c.data,f.variables||a.customData));return c}},dataset:{DataMagicPrepareForDisplay:function(a,b,c){b&&f.allowDatasets&&(c.data=r(c.data,{dataset:G(b)}));return c}},image:{DataMagicPrepareForDisplay:function(a,b,c){"string"==typeof c.data&&(c.data=
{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.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}}());