1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00
deka-dom-el/dist/dde.js

18 lines
6.9 KiB
JavaScript
Raw Normal View History

//deka-dom-el library is available via global namespace `dde`
(()=> {
2023-11-10 18:02:56 +01:00
var b={isSignal(t){return!1},processReactiveAttribute(t,e,n,c){return n}};function M(t,e=!0){return e?Object.assign(b,t):(Object.setPrototypeOf(t,b),t)}function x(t){return b.isPrototypeOf(t)&&t!==b?t:b}function l(t){return typeof t>"u"}function w(t,e){if(!t||!(t instanceof AbortSignal))return!0;if(!t.aborted)return t.addEventListener("abort",e),function(){t.removeEventListener("abort",e)}}var R={setDeleteAttr:U,ssr:""};function U(t,e,n){if(Reflect.set(t,e,n),!!l(n)){if(Reflect.deleteProperty(t,e),t instanceof HTMLElement&&t.getAttribute(e)==="undefined")return t.removeAttribute(e);if(Reflect.get(t,e)==="undefined")return Reflect.set(t,e,"")}}var v=[{scope:document.body,host:t=>t?t(document.body):document.body,custom_element:!1,prevent:!0}],E={get current(){return v[v.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...v]},push(t={}){return v.push(Object.assign({},this.current,{prevent:!1},t))},pop(){return v.pop()}},O;function _(t,e,...n){let c=x(this),o=0,r,f;switch((Object(e)!==e||c.isSignal(e))&&(e={textContent:e}),!0){case typeof t=="function":{o=1,E.push({scope:t,host:h=>h?(o===1?n.unshift(h):h(f),void 0):f}),r=t(e||void 0);let d=r instanceof DocumentFragment;if(r.nodeName==="#comment")break;let a=_.mark({type:"component",name:t.name,host:d?"this":"parentElement"});r.prepend(a),d&&(f=a);break}case t==="#text":r=A.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):r=A.call(this,document.createDocumentFragment(),e);break;case!!O:r=A.call(this,document.createElementNS(O,t),e);break;case!r:r=A.call(this,document.createElement(t),e)}return F(r),f||(f=r),n.forEach(d=>d(f)),o&&E.pop(),o=2,r}_.mark=function(t,e=!1){t=Object.entries(t).map(([o,r])=>o+`="${r}"`).join(" ");let n=e?"":"/",c=document.createComment(`<dde:mark ${t}${R.ssr}${n}>`);return e||(c.end=document.createComment("</dde:mark>")),c};_.later=function(){let t=_.mark({type:"later"});return t.append=t.prepend=function(...e){return t.after(...e),t},t};function X(t){let e=this;return function(...c){O=t;let o=_.call(e,...c);return O=void 0,o}}var{setDeleteAttr:D}=R,C=new WeakMap;function A(t,...e){if(!e.length)return t;C.set(t,T(t,this));for(let[n,c]of Object.entries(Object.assign({},...e)))P.call(this,t,n,c);return C.delete(t),t}function P(t,e,n){let{setRemoveAttr:c,s:o}=T(t,this),r=this;n=o.processReactiveAttribute(t,e,n,(d,a)=>P.call(r,t,d,a));let[f]=e;if(f==="=")return c(e.slice(1),n);if(f===".")return L(t,e.slice(1),n);if(/(aria|data)([A-Z])/.test(e))return e=e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),c(e,n);switch(e==="className"&&(e="class"),e){case"xlink:href":return c(e,n,"http://www.w3.org/1999/xlink");case"textContent":return D(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return y(o,n,L.bind(null,t[e]));case"ariaset":return y(o,n,(d,a)=>c("aria-"+d,a));case"classList":return k.call(r,t,n)}return q(t,e)?D(t,e,n):c(e,n)}function T(t,e){if(C.has(t))return C.get(t);let c=(t instanceof SVGElement?B:z).bind(null,t,"Attribute"),o=x(e);return{setRemoveAttr:c,s:o}}function k(t,e){let n=x(this);return y(n,e,(c,o)=>t.classList.toggle(c,o===-1?void 0:!!o)),t}function Y(t){return Array.from(t.children).forEach(e=>e.remove()),t}function q(t,e){if(!Reflect.has(t,e))return!1;let n=W(t,e);return!l(n.set)}function W(t,e){if(t=Object.getPrototypeOf(t),!t)return{};let n=Object.getOwnPropertyDescriptor(t,e);return n||W(t,e)}function y(t,e,n){if(!(typeof e!="object"||e===null))return Object.entries(e).forEach(function([o,r]){o&&(r=t.processReactiveAttribute(e,o,r,n),n(o,r))})}function $(t){return Array.isArray(t)?t.filter(Boolean).join(" "):t}function z(t,e,n,c){return t[(l(c)?"remove":"set")+e](n,$(c))}function B(t,e,n,c,o=null){return t[(l(c)?"remove":"set")+e+"NS"](o,n,$(c))}function L(t,e,n){if(Reflect.set(t,e,n),!!l(n))return Reflect.deleteProperty(t,e)}function j(...t){return this.appendOrig(...t),this}function F(t){return t.append===j||(t.appendOrig=t.append,t.append=j),t}function nt(t,e,...n){let c=n.length?new CustomEvent(e,{detail:n[0]}):new Event(e)
2023-11-10 17:15:59 +01:00
globalThis.dde= {assign: A,
assignAttribute: P,
2023-11-10 17:15:59 +01:00
classListDeclarative: k,
createElement: _,
createElementNS: X,
dispatchEvent: nt,
2023-11-10 17:15:59 +01:00
el: _,
elNS: X,
empty: Y,
2023-11-10 17:15:59 +01:00
on: N,
2023-11-10 18:02:56 +01:00
registerReactivity: M,
2023-11-10 17:15:59 +01:00
scope: E
};
})();