-
Notifications
You must be signed in to change notification settings - Fork 0
/
HypeReactiveContent.prod.min.js
18 lines (18 loc) · 7.15 KB
/
HypeReactiveContent.prod.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
Hype Reactive Content 1.4.1
copyright (c) 2024 Max Ziebell, (https://maxziebell.de). MIT-license
*/
'use strict';!1==="HypeReactiveContent"in window&&(window.HypeReactiveContent=function(){function q(a){return a?u[a]:u}function y(a,d){return a?a+"."+d:d}function z(a,d,e){e=e||"";return null==a||a[A]?a:new Proxy(a,{get:function(c,g,b){if("_key"===g)return e;if(g===A)return!0;c=Reflect.get(c,g,b);return"object"===typeof c?z(c,d,y(e,g)):c},set:function(c,g,b,f){const h=Reflect.set(c,g,b,f);d(g,b,c,f);return h}})}function C(a){if(!a[A])return a;const d={};for(const e in a)if(a.hasOwnProperty(e)){const c=
a[e];d[e]="object"===typeof c?C(c):c}return d}function B(a){return function(){if(!a.timeout){var d=arguments;a.timeout=requestAnimationFrame(function(){a.apply(this,d);a.timeout=null}.bind(this))}}}function r(a,d,e,c){if(e){if("object"!==typeof e)return null}else{if(void 0===e)return null;e=d.customData}c=c||{};if(!1!=="HypeActionEvents"in window)return d.triggerAction(a,{element:c.element,event:{type:c.type},scope:e});try{let g=new Proxy(Object.assign({element:c.element,$elm:c.element},d),{set(b,
f,h,m){return Reflect.get(b,f,m)?Reflect.set(b,f,h,m):Reflect.set(e,f,h)},get(b,f,h){return(b=Reflect.get(b,f,h))?b:Reflect.get(e,f)},has(b,f,h){return b.hasOwnProperty(f)||window[f]?Reflect.has(b,f,h):!0}});return(new Function("$context","with($context){ "+a+"}"))(g)}catch(g){q("debug")||-1!=window.location.href.indexOf("127.0.0.1:")&&-1!=window.location.href.indexOf("/preview/")?console.error("%c"+(c.errorMsg||"HypeReactiveContent Error")+"%c"+(c.errorMsg?"":" version "+HypeReactiveContent.version)+
"\n\n%c"+a+(c.omitError?"":"%c\n\n"+g+"\n\n"),"font-size:12px; font-weight:bold","font-size:8px","min-height:40px;display: inline-block; padding: 10px; background-color: rgba(255,255,255,0.25); border: 1px solid lightgray; border-radius: 4px; font-family:Monospace; font-size:12px","font-size:11px",c.element?c.element:""):console.error(g)}}function D(a,d,e){return e?r("return "+e,a,null,{element:d,type:"HypeReactiveScope"}):null}function E(a,d){let e=d.closest("[data-scope]");return e?D(a,d,e.getAttribute("data-scope")):
null}function v(a,d,e){const c=q("scopeSymbol"),g=c.length;let b=null;a=a.trim();a.startsWith(c)?(a=a.slice(g),b=E(d,e)):a.includes(c)&&(b=a.slice(0,a.indexOf(c)),b=D(d,e,b),a=a.slice(a.indexOf(c)+g));return{value:a,scope:b}}function F(a,d,e){return a.replace(/{{\s*([^{}\s]+)\s*}}/g,function(c,g){c=v(g,d,e);c=r("return "+c.value,d,c.scope,{element:e,type:"HypeReactiveTemplate"});return void 0!==c?c:""})}function G(a){let d=document.getElementById(a.currentSceneId()),e=p.get(a)||new Map;d.querySelectorAll("[data-content-template]").forEach(function(c){const g=
c.getAttribute("data-content-template"),b=c.innerHTML;g&&!e.has(g)?e.set(g,b):g||e.has(c)||e.set(c,b)});p.set(a,e)}function H(a){w.set(a,a.customData||{});Object.defineProperty(a,"customData",{get:function(){return w.get(a)},set:function(d){d=z(d,a.refreshReactiveContentDebounced);w.set(a,d);q("debounceCustomDataUpdate")?a.refreshReactiveContentDebounced():a.refreshReactiveContent()}})}function I(a,d,e){!1==="HypeActionEvents"in window&&(d=e.customBehaviorName,"#"!=d.charAt(0)&&/[;=()]/.test(d)&&
r(d,a,a.customData))}const w=new WeakMap;let u={scopeSymbol:"\u21e2",visibilitySymbol:"\ud83d\udc41\ufe0f",effectSymbol:"\u26a1\ufe0f",templateSymbol:"\ud83d\udcdd",debounceCustomDataUpdate:!0,visibilityMode:"auto",debug:!1},A=Symbol("isProxy");const p=new WeakMap;!1==="HYPE_eventListeners"in window&&(window.HYPE_eventListeners=[]);window.HYPE_eventListeners.push({type:"HypeDocumentLoad",callback:function(a,d,e){function c(b,f,h,m,k){(m=b.closest("["+h+"-action]"))&&r(m.getAttribute(h+"-action"),
a,null,{element:b,type:f});if((m=b.closest("["+h+"-behavior]"))&&!g[m.id]){g[m.id]=!0;let l=m.getAttribute(h+"-behavior");B(function(){a.triggerCustomBehaviorNamed(l)})()}}let g={};a.refreshReactiveContent=function(b,f,h,m){void 0===b||void 0===f||/[;=()]/.test(f)||a.triggerCustomBehaviorNamed(y(m._key,b)+" equals "+("string"===typeof f?'"'+f+'"':f));void 0!==b&&(q("customDataUpdate")&&q("customDataUpdate")(b,f,h,m),a.customDataUpdate&&a.customDataUpdate(b,f,h,m),a.triggerCustomBehaviorNamed("customData was changed"),
a.triggerCustomBehaviorNamed(y(m._key,b)+" was updated"));f=document.getElementById(a.currentSceneId());g={};f.querySelectorAll("[data-visibility], [data-content], [data-effect], [data-content-template]").forEach(function(k){var l=k.getAttribute("data-content"),n=k.getAttribute("data-visibility"),t=k.getAttribute("data-effect"),x=k.hasAttribute("data-content-template");n&&(n=v(n,a,k),n=r("return "+n.value,a,n.scope,{element:k,type:"HypeReactiveVisibility"}),"none"==k.style.display&&(k.style.display=
"block"),n=n?"visible":"hidden",n!==k.style.visibility&&(k.style.visibility=n,b&&c(k,"HypeReactiveVisibilityChanged","data-visibility-changed",!0,!0)));t&&(t=v(t,a,k),r(t.value,a,t.scope,{element:k,type:"HypeReactiveEffect"}));l?(l=v(l,a,k),l=r("return "+l.value,a,l.scope,{element:k,type:"HypeReactiveContent"}),l=void 0!==l?l:"",l!==k.innerHTML&&(k.innerHTML=l,b&&c(k,"HypeReactiveContentChanged","data-content-changed",!0,!0))):x&&(l=k.getAttribute("data-content-template"),x=p.get(a)||new Map,(l=l?
x.get(l):x.get(k))?(l=F(l,a,k),l!==k.innerHTML&&(k.innerHTML=l,b&&c(k,"HypeReactiveTemplateChanged","data-content-template-changed",!0,!0))):k.innerHTML="")});!1!=="HypeDataMagic"in window&&HypeDataMagic.getDefault("refreshOnCustomData")&&a.refresh()};a.refreshReactiveContentDebounced=B(a.refreshReactiveContent);a.resolveClosestScope=function(b){return E(a,b)};a.enableReactiveCustomData=function(b){const f=w.get(a)||{};a.customData=Object.assign(f,b||{})};a.setContentTemplateByName=function(b,f,h=
!0){let m=p.get(a)||new Map;m.set(b,f);p.set(a,m);h&&a.refreshReactiveContentDebounced()};a.setContentTemplates=function(b,f=!0){if(b&&"object"===typeof b){for(let h in b)b.hasOwnProperty(h)&&a.setContentTemplateByName(h,b[h],!1);f&&a.refreshReactiveContentDebounced()}};a.flushContentTemplateByName=function(b,f=!0){const h=p.get(a);h&&b&&(h.delete(b),p.set(a,h),f&&a.refreshReactiveContentDebounced())};a.flushContentTemplates=function(b=!0){const f=p.get(a);f&&(f.clear(),p.set(a,f),b&&a.refreshReactiveContentDebounced())};
H(a);a.enableReactiveCustomData(q("customData")||{});a.functions().HypeReactiveContent&&a.functions().HypeReactiveContent(a,d,e)}});window.HYPE_eventListeners.push({type:"HypeScenePrepareForDisplay",callback:function(a,d,e){G(a);a.refreshReactiveContent()}});!1==="HypeActionEvents"in window&&window.HYPE_eventListeners.push({type:"HypeTriggerCustomBehavior",callback:I});window.addEventListener("DOMContentLoaded",function(a){a=[];switch(q("visibilityMode")){case "auto":a.push('[data-visibility][style*="visibility: hidden"] [data-visibility] { visibility: hidden !important; }');
break;case "manual":a.push('[style*="visibility: hidden"] .inheritVisibility { visibility: hidden !important; }','.propagateVisibility[data-visibility][style*="visibility: hidden"] [data-visibility] { visibility: hidden !important; }')}a.forEach(d=>document.styleSheets[0].insertRule(d,0))});return{version:"1.4.1",setDefault:function(a,d){"object"==typeof a?u=a:u[a]=d},getDefault:q,enableReactiveObject:z,disableReactiveObject:C,debounceByRequestFrame:B}}());