1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-24 09:29:37 +01:00
deka-dom-el/dist/dde.js

20 lines
7.3 KiB
JavaScript
Raw Normal View History

//deka-dom-el library is available via global namespace `dde`
(()=> {
2023-11-22 21:29:40 +01:00
var E={isSignal(t){return!1},processReactiveAttribute(t,e,n,c){return n}};function U(t,e=!0){return e?Object.assign(E,t):(Object.setPrototypeOf(t,E),t)}function x(t){return E.isPrototypeOf(t)&&t!==E?t:E}function b(t){return typeof t>"u"}function A(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:q,ssr:""};function q(t,e,n){if(Reflect.set(t,e,n),!!b(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 l=[{scope:document.body,host:t=>t?t(document.body):document.body,custom_element:!1,prevent:!0}],v={get current(){return l[l.length-1]},get host(){return this.current.host},preventDefault(){let{current:t}=this;return t.prevent=!0,t},get state(){return[...l]},push(t={}){return l.push(Object.assign({},this.current,{prevent:!1},t))},pushRoot(){return l.push(l[0])},pop(){if(l.length!==1)return l.pop()}};function D(...t){return this.appendOriginal(...t),this}function z(t){return t.append===D||(t.appendOriginal=t.append,t.append=D),t}var O;function N(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,v.push({scope:t,host:(...h)=>h.length?(o===1?n.unshift(...h):h.forEach(g=>g(f)),void 0):f}),r=t(e||void 0);let d=r instanceof DocumentFragment;if(r.nodeName==="#comment")break;let a=N.mark({type:"component",name:t.name,host:d?"this":"parentElement"});r.prepend(a),d&&(f=a);break}case t==="#text":r=w.call(this,document.createTextNode(""),e);break;case(t==="<>"||!t):r=w.call(this,document.createDocumentFragment(),e);break;case!!O:r=w.call(this,document.createElementNS(O,t),e);break;case!r:r=w.call(this,document.createElement(t),e)}return z(r),f||(f=r),n.forEach(d=>d(f)),o&&v.pop(),o=2,r}N.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};function Y(t){let e=this;return function(...c){O=t;let o=N.call(e,...c);return O=void 0,o}}var{setDeleteAttr:j}=R,C=new WeakMap;function w(t,...e){if(!e.length)return t;C.set(t,T(t,this));for(let[n,c]of Object.entries(Object.assign({},...e)))M.call(this,t,n,c);return C.delete(t),t}function M(t,e,n){let{setRemoveAttr:c,s:o}=T(t,this),r=this;n=o.processReactiveAttribute(t,e,n,(d,a)=>M.call(r,t,d,a));let[f]=e;if(f==="=")return c(e.slice(1),n);if(f===".")return P(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 j(t,e,n);case"style":if(typeof n!="object")break;case"dataset":return y(o,n,P.bind(null,t[e]));case"ariaset":return y(o,n,(d,a)=>c("aria-"+d,a));case"classList":return B.call(r,t,n)}return F(t,e)?j(t,e,n):c(e,n)}function T(t,e){if(C.has(t))return C.get(t);let c=(t instanceof SVGElement?H:k).bind(null,t,"Attribute"),o=x(e);return{setRemoveAttr:c,s:o}}function B(t,e){let n=x(this);return y(n,e,(c,o)=>t.classList.toggle(c,o===-1?void 0:!!o)),t}function tt(t){return Array.from(t.children).forEach(e=>e.remove()),t}function et(t,e,n,c){return t instanceof HTMLElement?t[e+"Attribute"](n,c):t[e+"AttributeNS"](null,n,c)}function F(t,e){if(!Reflect.has(t,e))return!1;let n=W(t,e);return!b(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 k(t,e,n,c){return t[(b(c)?"remove":"set")+e](n,$(c))}function H(t,e,n,c,o=null){return t[(b(c)?"remove":"set")+e+"NS"](o,n,$(c))}function P(t,e,n){if(Reflect.set(t,e,n),!!b(n))return Reflect.deleteProperty(t,e)}func
globalThis.dde= {assign: w,
2023-11-22 21:29:40 +01:00
assignAttribute: M,
chainableAppend: z,
classListDeclarative: B,
createElement: N,
createElementNS: Y,
2023-11-22 21:29:40 +01:00
dispatchEvent: ot,
el: N,
elNS: Y,
2023-11-22 21:29:40 +01:00
elementAttribute: et,
empty: tt,
on: _,
registerReactivity: U,
2023-11-22 21:29:40 +01:00
scope: v
};
})();