@ramstack/alpinegear-main 1.1.0-preview.4 → 1.1.0-preview.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -413,28 +413,16 @@ function collect_group_values(el, values) {
413
413
  return values;
414
414
  }
415
415
 
416
- function plugin$4({ directive, mutateDom }) {
417
- directive("format", (el, { modifiers }, { effect, evaluateLater }) => {
418
- const cache = new Map;
416
+ function plugin$4({ directive, evaluateLater, mutateDom }) {
417
+ directive("format", (el, { modifiers }, { effect }) => {
419
418
  const placeholder_regex = /{{(?<expr>.+?)}}/g;
420
419
  const is_once = has_modifier(modifiers, "once");
421
420
 
422
421
  process(el);
423
422
 
424
- function get_eval_fn(expression) {
425
- let getter = cache.get(expression);
426
- if (is_nullish(getter)) {
427
- getter = create_getter(evaluateLater, expression);
428
- cache.set(expression, getter);
429
- }
430
-
431
- return getter;
432
- }
433
-
434
423
  function update(callback) {
435
424
  if (is_once) {
436
425
  mutateDom(() => callback());
437
- cache.clear();
438
426
  }
439
427
  else {
440
428
  effect(() => mutateDom(() => callback()));
@@ -465,7 +453,7 @@ function plugin$4({ directive, mutateDom }) {
465
453
  fragment.appendChild(document.createTextNode(tokens[i]));
466
454
  }
467
455
  else {
468
- const get_value = get_eval_fn(tokens[i]);
456
+ const get_value = create_getter(evaluateLater, node.parentNode, tokens[i]);
469
457
  const text = document.createTextNode("");
470
458
 
471
459
  fragment.append(text);
@@ -483,7 +471,7 @@ function plugin$4({ directive, mutateDom }) {
483
471
  const matches = [...attr.value.matchAll(placeholder_regex)];
484
472
  if (matches.length) {
485
473
  const template = attr.value;
486
- update(() => attr.value = template.replace(placeholder_regex, (_, expr) => get_eval_fn(expr)()));
474
+ update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
487
475
  }
488
476
  }
489
477
  }
@@ -1 +1 @@
1
- function e(e,...t){const n=e(...t);return()=>{let e;return n((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n((e=>t=e)),function(e){return"function"==typeof e?.set}(t)?t.set(e):o((()=>{}),{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpine-gear.js:",...e),r=Array.isArray,c=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>r(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex((e=>e==t)),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(e,t,n=null){const{effect:o,release:a}=Alpine;let r,c,i=!1;const l=o((()=>{r=e(),i||(n?.deep&&JSON.stringify(r),c=r),(i||(n?.immediate??1))&&setTimeout((()=>{t(r,c),c=r}),0),i=!0}));return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,open,group".split(",").map((e=>[e.trim().toLowerCase(),e.trim()])));function g({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:_,prefixed:k}){T((e=>({name:e.name.replace(/^&/,k("bound:")),value:e.value}))),l("bound",((l,{expression:T,value:k,modifiers:x},{effect:N,cleanup:y})=>{if(!k)return void a("x-bound directive expects the presence of a bound property name");const E=l.tagName.toUpperCase();T=T?.trim();const w=b.get(k.trim().replace("-","").toLowerCase());T||=w;const L=e(g,l,T),S=t(g,l,T),D=()=>d(l[w],L())||_((()=>l[w]=L())),H=()=>S((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[w]):l[w]);let M;switch(w){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(L())&&H(),N(D),y(m(l,"input",H)),M=!0;break;case"SELECT":queueMicrotask((()=>{c(L())&&H(),N((()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(L()??[])))),y(m(l,"change",(()=>S(function(e){return e.multiple?[...e.selectedOptions].map((e=>e.value)):e.value}(l)))))})),M=!0}}();break;case"checked":i(l)&&(N(D),y(m(l,"change",H)),M=!0);break;case"files":"file"===l.type&&(y(m(l,"input",H)),M=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(c(L())&&H(),N(D),y(m(l,"input",H)),M=!0);break;case"videoHeight":case"videoWidth":A("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":A("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return o??=new ResizeObserver((e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)})),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,H)),M=!0;break;case"open":"DETAILS"===E&&(c(L())&&H(),N(D),y(m(l,"toggle",H)),M=!0);break;case"group":i(l)&&(l.name||_((()=>l.name=T)),N((()=>_((()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,L()??[]))))),y(m(l,"input",(()=>S(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,L()))))),M=!0)}if(!M){const n=p(x,"in")?"in":p(x,"out")?"out":"inout",o=T===k?(e=>{for(;e&&!e._x_dataStack;)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${k}' property is defined`);const r={get:e(g,o,T),set:t(g,o,T)},c={get:e(g,l,k),set:t(g,l,k)};switch(n){case"in":y(h((()=>r.get()),(e=>c.set(v(e)))));break;case"out":y(h((()=>c.get()),(e=>r.set(v(e)))));break;default:y(u(r,c))}}function A(e,t){E===e&&(H(),y(m(l,t,H)),M=!0)}}))}function T({directive:t,mutateDom:n}){t("format",((t,{modifiers:o},{effect:a,evaluateLater:r})=>{const i=new Map,l=/{{(?<expr>.+?)}}/g,u=p(o,"once");function s(t){let n=i.get(t);return c(n)&&(n=e(r,t),i.set(t,n)),n}function d(e){u?(n((()=>e())),i.clear()):a((()=>n((()=>e()))))}!function e(t){switch(t.nodeType){case Node.TEXT_NODE:!function(e){const t=e.textContent.split(l);if(t.length>1){const o=new DocumentFragment;for(let e=0;t.length>e;e++)if(e%2==0)o.appendChild(document.createTextNode(t[e]));else{const n=s(t[e]),a=document.createTextNode("");o.append(a),d((()=>a.textContent=n()))}n((()=>e.parentElement.replaceChild(o,e)))}}(t);break;case Node.ELEMENT_NODE:!function(t){for(let n of t.childNodes)e(n)}(t),function(e){for(let t of e.attributes)if([...t.value.matchAll(l)].length){const e=t.value;d((()=>t.value=e.replace(l,((e,t)=>s(t)()))))}}(t)}}(t)}))}function _(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:r,scope:c={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver((e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()}));return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];r((()=>{for(let t of i)u(t)&&n(t,c,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)})),e._r_block={template:t,update(){r((()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)}))},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o((()=>e._r_block?.delete()))}function k({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",((t,{},{cleanup:r})=>{l(t)?_(t,t,{addScopeToNode:e,cleanup:r,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")}))}function x({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",((n,{},{cleanup:c,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i((()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),_(n,a.el,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}))):d()}))}))}function N(e){e.directive("template",((e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);l(n)?queueMicrotask((()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))})):a("x-template directive can only reference the template tag")}))}function y({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",((n,{expression:c},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,c);u((()=>d()?_(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete()))}))}export{g as bound,T as format,k as fragment,x as match,N as template,y as when};
1
+ function e(e,...t){const n=e(...t);return()=>{let e;return n((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n((e=>t=e)),function(e){return"function"==typeof e?.set}(t)?t.set(e):o((()=>{}),{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpine-gear.js:",...e),r=Array.isArray,c=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>r(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex((e=>e==t)),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(e,t,n=null){const{effect:o,release:a}=Alpine;let r,c,i=!1;const l=o((()=>{r=e(),i||(n?.deep&&JSON.stringify(r),c=r),(i||(n?.immediate??1))&&setTimeout((()=>{t(r,c),c=r}),0),i=!0}));return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,open,group".split(",").map((e=>[e.trim().toLowerCase(),e.trim()])));function g({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:_,prefixed:k}){T((e=>({name:e.name.replace(/^&/,k("bound:")),value:e.value}))),l("bound",((l,{expression:T,value:k,modifiers:x},{effect:N,cleanup:y})=>{if(!k)return void a("x-bound directive expects the presence of a bound property name");const E=l.tagName.toUpperCase();T=T?.trim();const L=b.get(k.trim().replace("-","").toLowerCase());T||=L;const w=e(g,l,T),S=t(g,l,T),D=()=>d(l[L],w())||_((()=>l[L]=w())),H=()=>S((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let M;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(w())&&H(),N(D),y(m(l,"input",H)),M=!0;break;case"SELECT":queueMicrotask((()=>{c(w())&&H(),N((()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(w()??[])))),y(m(l,"change",(()=>S(function(e){return e.multiple?[...e.selectedOptions].map((e=>e.value)):e.value}(l)))))})),M=!0}}();break;case"checked":i(l)&&(N(D),y(m(l,"change",H)),M=!0);break;case"files":"file"===l.type&&(y(m(l,"input",H)),M=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(c(w())&&H(),N(D),y(m(l,"input",H)),M=!0);break;case"videoHeight":case"videoWidth":A("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":A("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return o??=new ResizeObserver((e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)})),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,H)),M=!0;break;case"open":"DETAILS"===E&&(c(w())&&H(),N(D),y(m(l,"toggle",H)),M=!0);break;case"group":i(l)&&(l.name||_((()=>l.name=T)),N((()=>_((()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,w()??[]))))),y(m(l,"input",(()=>S(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,w()))))),M=!0)}if(!M){const n=p(x,"in")?"in":p(x,"out")?"out":"inout",o=T===k?(e=>{for(;e&&!e._x_dataStack;)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${k}' property is defined`);const r={get:e(g,o,T),set:t(g,o,T)},c={get:e(g,l,k),set:t(g,l,k)};switch(n){case"in":y(h((()=>r.get()),(e=>c.set(v(e)))));break;case"out":y(h((()=>c.get()),(e=>r.set(v(e)))));break;default:y(u(r,c))}}function A(e,t){E===e&&(H(),y(m(l,t,H)),M=!0)}}))}function T({directive:t,evaluateLater:n,mutateDom:o}){t("format",((t,{modifiers:a},{effect:r})=>{const c=/{{(?<expr>.+?)}}/g,i=p(a,"once");function l(e){i?o((()=>e())):r((()=>o((()=>e()))))}!function t(a){switch(a.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(c);if(a.length>1){const r=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)r.appendChild(document.createTextNode(a[o]));else{const c=e(n,t.parentNode,a[o]),i=document.createTextNode("");r.append(i),l((()=>i.textContent=c()))}o((()=>t.parentElement.replaceChild(r,t)))}}(a);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)t(n)}(a),function(t){for(let o of t.attributes)if([...o.value.matchAll(c)].length){const a=o.value;l((()=>o.value=a.replace(c,((o,a)=>e(n,t,a)()))))}}(a)}}(t)}))}function _(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:r,scope:c={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver((e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()}));return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];r((()=>{for(let t of i)u(t)&&n(t,c,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)})),e._r_block={template:t,update(){r((()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)}))},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o((()=>e._r_block?.delete()))}function k({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",((t,{},{cleanup:r})=>{l(t)?_(t,t,{addScopeToNode:e,cleanup:r,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")}))}function x({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",((n,{},{cleanup:c,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i((()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),_(n,a.el,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}))):d()}))}))}function N(e){e.directive("template",((e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);l(n)?queueMicrotask((()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))})):a("x-template directive can only reference the template tag")}))}function y({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",((n,{expression:c},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,c);u((()=>d()?_(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete()))}))}export{g as bound,T as format,k as fragment,x as match,N as template,y as when};
@@ -416,28 +416,16 @@
416
416
  return values;
417
417
  }
418
418
 
419
- function plugin$4({ directive, mutateDom }) {
420
- directive("format", (el, { modifiers }, { effect, evaluateLater }) => {
421
- const cache = new Map;
419
+ function plugin$4({ directive, evaluateLater, mutateDom }) {
420
+ directive("format", (el, { modifiers }, { effect }) => {
422
421
  const placeholder_regex = /{{(?<expr>.+?)}}/g;
423
422
  const is_once = has_modifier(modifiers, "once");
424
423
 
425
424
  process(el);
426
425
 
427
- function get_eval_fn(expression) {
428
- let getter = cache.get(expression);
429
- if (is_nullish(getter)) {
430
- getter = create_getter(evaluateLater, expression);
431
- cache.set(expression, getter);
432
- }
433
-
434
- return getter;
435
- }
436
-
437
426
  function update(callback) {
438
427
  if (is_once) {
439
428
  mutateDom(() => callback());
440
- cache.clear();
441
429
  }
442
430
  else {
443
431
  effect(() => mutateDom(() => callback()));
@@ -468,7 +456,7 @@
468
456
  fragment.appendChild(document.createTextNode(tokens[i]));
469
457
  }
470
458
  else {
471
- const get_value = get_eval_fn(tokens[i]);
459
+ const get_value = create_getter(evaluateLater, node.parentNode, tokens[i]);
472
460
  const text = document.createTextNode("");
473
461
 
474
462
  fragment.append(text);
@@ -486,7 +474,7 @@
486
474
  const matches = [...attr.value.matchAll(placeholder_regex)];
487
475
  if (matches.length) {
488
476
  const template = attr.value;
489
- update(() => attr.value = template.replace(placeholder_regex, (_, expr) => get_eval_fn(expr)()));
477
+ update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
490
478
  }
491
479
  }
492
480
  }
@@ -1 +1 @@
1
- !function(){"use strict";function e(e,...t){const n=e(...t);return()=>{let e;return n((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n((e=>t=e)),function(e){return"function"==typeof e?.set}(t)?t.set(e):o((()=>{}),{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpine-gear.js:",...e),c=Array.isArray,r=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>c(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex((e=>e==t)),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(e,t,n=null){const{effect:o,release:a}=Alpine;let c,r,i=!1;const l=o((()=>{c=e(),i||(n?.deep&&JSON.stringify(c),r=c),(i||(n?.immediate??1))&&setTimeout((()=>{t(c,r),r=c}),0),i=!0}));return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,open,group".split(",").map((e=>[e.trim().toLowerCase(),e.trim()])));function g(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:c,scope:r={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver((e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()}));return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];c((()=>{for(let t of i)u(t)&&n(t,r,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)})),e._r_block={template:t,update(){c((()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)}))},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o((()=>e._r_block?.delete()))}function T(u){(function({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:_,prefixed:k}){T((e=>({name:e.name.replace(/^&/,k("bound:")),value:e.value}))),l("bound",((l,{expression:T,value:k,modifiers:x},{effect:N,cleanup:E})=>{if(!k)return void a("x-bound directive expects the presence of a bound property name");const y=l.tagName.toUpperCase();T=T?.trim();const L=b.get(k.trim().replace("-","").toLowerCase());T||=L;const w=e(g,l,T),S=t(g,l,T),D=()=>d(l[L],w())||_((()=>l[L]=w())),H=()=>S((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let M;switch(L){case"value":!function(){switch(y){case"INPUT":case"TEXTAREA":r(w())&&H(),N(D),E(m(l,"input",H)),M=!0;break;case"SELECT":queueMicrotask((()=>{r(w())&&H(),N((()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(w()??[])))),E(m(l,"change",(()=>S(function(e){return e.multiple?[...e.selectedOptions].map((e=>e.value)):e.value}(l)))))})),M=!0}}();break;case"checked":i(l)&&(N(D),E(m(l,"change",H)),M=!0);break;case"files":"file"===l.type&&(E(m(l,"input",H)),M=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(r(w())&&H(),N(D),E(m(l,"input",H)),M=!0);break;case"videoHeight":case"videoWidth":A("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":A("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":E(function(e,t){return o??=new ResizeObserver((e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)})),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,H)),M=!0;break;case"open":"DETAILS"===y&&(r(w())&&H(),N(D),E(m(l,"toggle",H)),M=!0);break;case"group":i(l)&&(l.name||_((()=>l.name=T)),N((()=>_((()=>function(e,t){e.checked=c(t)?f(t,e.value)>=0:d(e.value,t)}(l,w()??[]))))),E(m(l,"input",(()=>S(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,w()))))),M=!0)}if(!M){const n=p(x,"in")?"in":p(x,"out")?"out":"inout",o=T===k?(e=>{for(;e&&!e._x_dataStack;)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${k}' property is defined`);const c={get:e(g,o,T),set:t(g,o,T)},r={get:e(g,l,k),set:t(g,l,k)};switch(n){case"in":E(h((()=>c.get()),(e=>r.set(v(e)))));break;case"out":E(h((()=>r.get()),(e=>c.set(v(e)))));break;default:E(u(c,r))}}function A(e,t){y===e&&(H(),E(m(l,t,H)),M=!0)}}))})(u),function({directive:t,mutateDom:n}){t("format",((t,{modifiers:o},{effect:a,evaluateLater:c})=>{const i=new Map,l=/{{(?<expr>.+?)}}/g,u=p(o,"once");function s(t){let n=i.get(t);return r(n)&&(n=e(c,t),i.set(t,n)),n}function d(e){u?(n((()=>e())),i.clear()):a((()=>n((()=>e()))))}!function e(t){switch(t.nodeType){case Node.TEXT_NODE:!function(e){const t=e.textContent.split(l);if(t.length>1){const o=new DocumentFragment;for(let e=0;t.length>e;e++)if(e%2==0)o.appendChild(document.createTextNode(t[e]));else{const n=s(t[e]),a=document.createTextNode("");o.append(a),d((()=>a.textContent=n()))}n((()=>e.parentElement.replaceChild(o,e)))}}(t);break;case Node.ELEMENT_NODE:!function(t){for(let n of t.childNodes)e(n)}(t),function(e){for(let t of e.attributes)if([...t.value.matchAll(l)].length){const e=t.value;d((()=>t.value=e.replace(l,((e,t)=>s(t)()))))}}(t)}}(t)}))}(u),function({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",((t,{},{cleanup:c})=>{l(t)?g(t,t,{addScopeToNode:e,cleanup:c,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")}))}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:c}){n("match",((n,{},{cleanup:r,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i((()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),g(n,a.el,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:c}))):d()}))}))}(u),function(e){e.directive("template",((e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);l(n)?queueMicrotask((()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))})):a("x-template directive can only reference the template tag")}))}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:c}){n("when",((n,{expression:r},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,r);u((()=>d()?g(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:c}):n._r_block?.delete()))}))}(u)}document.addEventListener("alpine:init",(()=>{Alpine.plugin(T)}))}();
1
+ !function(){"use strict";function e(e,...t){const n=e(...t);return()=>{let e;return n((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n((e=>t=e)),function(e){return"function"==typeof e?.set}(t)?t.set(e):o((()=>{}),{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpine-gear.js:",...e),c=Array.isArray,r=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>c(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex((e=>e==t)),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(e,t,n=null){const{effect:o,release:a}=Alpine;let c,r,i=!1;const l=o((()=>{c=e(),i||(n?.deep&&JSON.stringify(c),r=c),(i||(n?.immediate??1))&&setTimeout((()=>{t(c,r),r=c}),0),i=!0}));return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,open,group".split(",").map((e=>[e.trim().toLowerCase(),e.trim()])));function g(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:c,scope:r={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver((e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()}));return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];c((()=>{for(let t of i)u(t)&&n(t,r,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)})),e._r_block={template:t,update(){c((()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)}))},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o((()=>e._r_block?.delete()))}function T(u){(function({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:_,prefixed:k}){T((e=>({name:e.name.replace(/^&/,k("bound:")),value:e.value}))),l("bound",((l,{expression:T,value:k,modifiers:x},{effect:N,cleanup:E})=>{if(!k)return void a("x-bound directive expects the presence of a bound property name");const y=l.tagName.toUpperCase();T=T?.trim();const L=b.get(k.trim().replace("-","").toLowerCase());T||=L;const S=e(g,l,T),w=t(g,l,T),D=()=>d(l[L],S())||_((()=>l[L]=S())),H=()=>w((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let A;switch(L){case"value":!function(){switch(y){case"INPUT":case"TEXTAREA":r(S())&&H(),N(D),E(m(l,"input",H)),A=!0;break;case"SELECT":queueMicrotask((()=>{r(S())&&H(),N((()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(S()??[])))),E(m(l,"change",(()=>w(function(e){return e.multiple?[...e.selectedOptions].map((e=>e.value)):e.value}(l)))))})),A=!0}}();break;case"checked":i(l)&&(N(D),E(m(l,"change",H)),A=!0);break;case"files":"file"===l.type&&(E(m(l,"input",H)),A=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(r(S())&&H(),N(D),E(m(l,"input",H)),A=!0);break;case"videoHeight":case"videoWidth":M("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":M("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":E(function(e,t){return o??=new ResizeObserver((e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)})),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,H)),A=!0;break;case"open":"DETAILS"===y&&(r(S())&&H(),N(D),E(m(l,"toggle",H)),A=!0);break;case"group":i(l)&&(l.name||_((()=>l.name=T)),N((()=>_((()=>function(e,t){e.checked=c(t)?f(t,e.value)>=0:d(e.value,t)}(l,S()??[]))))),E(m(l,"input",(()=>w(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,S()))))),A=!0)}if(!A){const n=p(x,"in")?"in":p(x,"out")?"out":"inout",o=T===k?(e=>{for(;e&&!e._x_dataStack;)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${k}' property is defined`);const c={get:e(g,o,T),set:t(g,o,T)},r={get:e(g,l,k),set:t(g,l,k)};switch(n){case"in":E(h((()=>c.get()),(e=>r.set(v(e)))));break;case"out":E(h((()=>r.get()),(e=>c.set(v(e)))));break;default:E(u(c,r))}}function M(e,t){y===e&&(H(),E(m(l,t,H)),A=!0)}}))})(u),function({directive:t,evaluateLater:n,mutateDom:o}){t("format",((t,{modifiers:a},{effect:c})=>{const r=/{{(?<expr>.+?)}}/g,i=p(a,"once");function l(e){i?o((()=>e())):c((()=>o((()=>e()))))}!function t(a){switch(a.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(r);if(a.length>1){const c=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)c.appendChild(document.createTextNode(a[o]));else{const r=e(n,t.parentNode,a[o]),i=document.createTextNode("");c.append(i),l((()=>i.textContent=r()))}o((()=>t.parentElement.replaceChild(c,t)))}}(a);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)t(n)}(a),function(t){for(let o of t.attributes)if([...o.value.matchAll(r)].length){const a=o.value;l((()=>o.value=a.replace(r,((o,a)=>e(n,t,a)()))))}}(a)}}(t)}))}(u),function({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",((t,{},{cleanup:c})=>{l(t)?g(t,t,{addScopeToNode:e,cleanup:c,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")}))}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:c}){n("match",((n,{},{cleanup:r,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i((()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),g(n,a.el,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:c}))):d()}))}))}(u),function(e){e.directive("template",((e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);l(n)?queueMicrotask((()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))})):a("x-template directive can only reference the template tag")}))}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:c}){n("when",((n,{expression:r},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,r);u((()=>d()?g(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:c}):n._r_block?.delete()))}))}(u)}document.addEventListener("alpine:init",(()=>{Alpine.plugin(T)}))}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-main",
3
- "version": "1.1.0-preview.4",
3
+ "version": "1.1.0-preview.5",
4
4
  "description": "@ramstack/alpinegear-main is a combined plugin that includes several Alpine.js directives, providing a convenient all-in-one package.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",