@techexp/webitem 0.5.2 → 0.5.3

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.
@@ -1,6 +1,6 @@
1
1
  // webitem.js Library to simplify creating HTML5 Custom Elements
2
2
  // https://github.com/ahabra/webitem
3
- // Copyright 2021 (C) Abdul Habra. Version 0.5.2.
3
+ // Copyright 2021 (C) Abdul Habra. Version 0.5.3.
4
4
  // Apache License Version 2.0
5
5
 
6
6
 
@@ -1,13 +1,13 @@
1
1
  // webitem.js Library to simplify creating HTML5 Custom Elements
2
2
  // https://github.com/ahabra/webitem
3
- // Copyright 2021 (C) Abdul Habra. Version 0.5.2.
3
+ // Copyright 2021 (C) Abdul Habra. Version 0.5.3.
4
4
  // Apache License Version 2.0
5
5
 
6
6
 
7
7
  var webitem=(()=>{var v=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var ue=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0})},oe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of re(t))!ie.call(e,i)&&i!==n&&v(e,i,{get:()=>t[i],enumerable:!(r=ne(t,i))||r.enumerable});return e};var fe=e=>oe(v({},"__esModule",{value:!0}),e);var ft={};ue(ft,{defineElement:()=>Ue});var se=Object.defineProperty,g=(e,t)=>{for(var n in t)se(e,n,{get:t[n],enumerable:!0})},l={};g(l,{add:()=>Oe,all:()=>F,classPresentIf:()=>Te,createElement:()=>Se,createElements:()=>M,first:()=>be,getAttributes:()=>ve,id:()=>Ee,removeElements:()=>Ne,setContent:()=>Ce,tag:()=>_});var d={};g(d,{equals:()=>q,forEachEntry:()=>L,has:()=>le,isDate:()=>S,isFunction:()=>R,isInteger:()=>ce,isNil:()=>ae,isNumber:()=>P,isRegExp:()=>j,isString:()=>p});function ae(e){return e==null}function p(e){return m(e,"String")}function R(e){return m(e,"Function")}function S(e){return m(e,"Date")}function P(e){return m(e,"Number")?Number.isNaN(e)?!1:Number.isFinite(e):!p(e)||(e=e.trim(),e==="")?!1:!isNaN(e)}function ce(e){return P(e)?Number.isInteger(Number.parseFloat(e)):!1}function j(e){return m(e,"RegExp")}function m(e,t){return Object.prototype.toString.call(e)===`[object ${t}]`}function L(e,t){if(!(!e||!t)){if(Array.isArray(e)){e.forEach((n,r)=>{t(r,n)});return}Object.entries(e).forEach(n=>t(n[0],n[1]))}}function le(e,t){return!e||!t?!1:Object.prototype.hasOwnProperty.call(e,t)}function q(e,t){return e===t?!0:e===void 0||t===void 0?!1:de(e,t)}function de(e,t){return N(e)||N(t)?e===t:he(e,t)}var me=new Set(["boolean","number","bigint","string","symbol"]);function N(e){return me.has(typeof e)}function he(e,t){return ge(e,t)?pe(e,t)?!0:ye(e,t):!1}function ge(e,t){return T(e)===T(t)}function T(e){return Object.prototype.toString.call(e)}function pe(e,t){return S(e)&&S(t)?e.getTime()===t.getTime():!1}function ye(e,t){let n=Object.keys(e);return n.length!==Object.keys(t).length?!1:n.every(r=>q(e[r],t[r]))}function Ee(e,t=document){return O(t)&&(t=t.shadowRoot),t.getElementById(e)}function F(e,t=document){return O(t)&&(t=t.shadowRoot),Array.from(t.querySelectorAll(e))}function be(e,t=document){if(O(t)&&(t=t.shadowRoot),!e.includes("/"))return t.querySelector(e);let n=e.split("/").map(r=>r.trim()).filter(r=>r.length>0);for(let r of n)if(t=we(r,t),t===null)break;return t}function we(e,t){return e==="shadowRoot"||e==="shadow-root"?t.shadowRoot:t.querySelector(e)}function O(e){return e&&e.shadowRoot&&e.tagName.includes("-")}function ve(e){let t={},n=e.attributes;if(!n||n.length===0)return t;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.value}return t}function M(e=""){if(e=e.trim(),!e)return[];let t=document.createElement("template");return t.innerHTML=e,Array.from(t.content.childNodes)}function Se(e,t={},n=""){let r=_(e,t,n),i=M(r);return i.length===0?null:i[0]}function _(e,t={},n=""){if(!e)return"";let r=Ae(t);return`<${e}${r}>${n}</${e}>`}function Ae(e){let t=[];return L(e,(r,i)=>{t.push(`${r}="${i}"`)}),(t.length>0?" ":"")+t.join(" ")}var Le=new Set(["beforebegin","afterbegin","beforeend","afterend"]);function Oe(e,t,n="beforeend"){return n=n.toLowerCase(),Le.has(n)?(p(t)?e.insertAdjacentHTML(n,t):xe(e,t,n),!0):!1}function xe(e,t,n){Array.isArray(t)?t.forEach(r=>e.insertAdjacentElement(n,r)):e.insertAdjacentElement(n,t)}function Ce(e,...t){e.innerHTML="",e.append(...t)}function Ne(e,t=document){F(e,t).forEach(r=>{r.parentNode.removeChild(r)})}function Te(e,t,n){if(!e)return;let r=n?"add":"remove";e.classList[r](t)}var h={};g(h,{endsWith:()=>D,indexOf:()=>x,indexOfFirstMatch:()=>$e,indexOfLastMatch:()=>Re,isEmpty:()=>y,removePrefix:()=>H,removeSuffix:()=>I,removeSurrounding:()=>Pe,replaceAll:()=>V,replaceTemplate:()=>Fe,startsWith:()=>W,strip:()=>We,stripEnd:()=>_e,stripStart:()=>Me,substringAfter:()=>je,substringBefore:()=>qe,trim:()=>A});function x(e,t,n=0,r=!1){return e?r?e.toLowerCase().indexOf(t.toLowerCase(),n):e.indexOf(t,n):-1}function $e(e,t){return!t||!e?-1:e.split("").findIndex(t)}function Re(e,t){if(!t||!e)return-1;let n=e.split("");for(let r=n.length;r>=0;--r)if(t(n[r],r))return r;return-1}function W(e="",t=void 0,n=!1){if(n){let r=e.substring(0,t.length).toLowerCase();return t.toLowerCase()===r}return e.startsWith(t)}function D(e,t,n=!1){return n?e.toLowerCase().endsWith(t.toLowerCase()):e.endsWith(t)}function H(e,t,n=!1){return W(e,t,n)&&(e=e.substring(t.length)),e}function I(e,t,n=!1){return D(e,t,n)&&(e=e.substring(0,e.length-t.length)),e}function Pe(e,t,n,r=!1){return I(H(e,t,r),n,r)}function je(e,t,n=!1){if(!t)return e;let r=x(e,t,0,n);return r<0?"":e.substring(r+t.length)}function qe(e,t,n=!1){if(!t)return"";let r=x(e,t,0,n);return r<0?e:e.substring(0,r)}function A(e){return y(e)?"":(p(e)||(e=String(e)),e.trim(e))}function y(e){return e==null||e===""}function V(e,t,n){if(R(String.prototype.replaceAll))return e.replaceAll(t,n);if(j(t))return e.replace(t,n);let r=new RegExp(t,"g");return e.replace(r,n)}function Fe(e="",t={},n="${",r="}"){return L(t,(i,u)=>{u!==void 0&&(i=n+i+r,e=V(e,i,u))}),e}function Me(e,t=""){return y(e)?"":t?k(e,new Set(Array.from(t))):e}function k(e,t){for(let n=0;n<e.length;n++)if(!t.has(e.charAt(n)))return e.substring(n);return""}function _e(e,t=""){return y(e)?"":t?B(e,new Set(Array.from(t))):e}function B(e,t){for(let n=e.length-1;n>=0;n--)if(!t.has(e.charAt(n)))return e.substring(0,n+1);return""}function We(e,t=""){if(e===void 0||e==="")return"";if(!t)return e;let n=new Set(Array.from(t));return e=k(e,n),e?B(e,n):""}var De={};g(De,{compareLines:()=>He});function He(e,t,{trim:n=!0,skipEmpty:r=!0,caseSensitive:i=!0}={trim:!0,skipEmpty:!0,caseSensitive:!0}){if(e=$(e,{trim:n,skipEmpty:r}),t=$(t,{trim:n,skipEmpty:r}),e.length!==t.length)return`t1 has ${e.length} lines(s) while t2 has ${t.length} line(s).`;for(let u=0;u<e.length;u++){let o=Ie(e[u],t[u],u,i);if(o.length>0)return o}return""}function Ie(e,t,n,r){let i=r?e:e.toLowerCase(),u=r?t:t.toLowerCase();return i!==u?`Line #${n+1} mismatch.
8
8
  ${e}
9
9
  ${t}`:""}function $(e,{trim:t,skipEmpty:n}){return t&&(e=A(e)),e=e.split(`
10
- `),t&&(e=e.map(r=>A(r))),n&&(e=e.filter(r=>!!r)),e}function C({obj:e={},prop:t,sel:n,attr:r,root:i=document,getter:u,setter:o,onChange:f}){Qe(t),ke(e,t);let s={};return u||(u=()=>Be({prop:t,sel:n,attr:r,root:i,objNotBound:s})),o||(o=a=>ze({prop:t,value:a,root:i,sel:n,attr:r,objNotBound:s})),Ve({obj:e,prop:t,getter:u,setter:o,onChange:f})}function Ve({obj:e,prop:t,getter:n,setter:r,onChange:i}){return Object.defineProperty(e,t,{get:()=>n(),set:o=>{if(i){let f=n(t);f!==o&&i(f,o)}r(o)},configurable:!0,enumerable:!0}),e}var E=e=>e.type==="checkbox",b=e=>e.type==="radio",G=e=>e.nodeName.toLowerCase()==="select",J=e=>e.nodeName.toLowerCase()==="input-field",K=e=>"value"in e,z=e=>new Set(Array.isArray(e)?e:[e]);function ke(e,t){let n=e[t];return n!==void 0&&(console.info(`Property '${t}' already exists in object. Will override previous definition but retain old value of ${n}.`),e[t]=n),n}function Be({prop:e,root:t,sel:n,attr:r,objNotBound:i}){return n?Ge(t,n,r):i[e]}function ze({prop:e,value:t,root:n,sel:r,attr:i,objNotBound:u}){if(r){Je(n,r,t,i);return}u[e]=t}function Ge(e,t,n){let r=Q(e,t);if(r.length===0)return null;let i=r[0];if(n)return i.getAttribute(n);if(!K(i))return i.innerHTML;if(E(i))return r.filter(u=>E(u)&&u.checked).map(u=>u.value==="on"?u.name:u.value);if(G(i))return[...i.querySelectorAll("option")].filter(o=>o.selected).map(o=>o.value);if(!(b(i)&&(i=r.filter(b).find(u=>u.checked),!i)))return J(i)?i.getAttribute("value"):i.value}function Je(e,t,n,r){let i=Q(e,t);if(i.length===0)return;let u=i[0];if(E(u)){let o=z(n);i.filter(E).forEach(f=>f.checked=o.has(f.value)||o.has(f.name));return}if(G(u)){let o=z(n);u.querySelectorAll("option").forEach(f=>f.selected=o.has(f.value));return}if(b(u)){i.filter(b).forEach(o=>o.checked=o.value===n);return}i.forEach(o=>Ke(o,n,r))}function Ke(e,t,n){n?e.setAttribute(n,t):K(e)?e.value=t:J(e)?e.setAttribute("value",t):e.innerHTML=t}function Q(e,t){let n=e.querySelectorAll(t);return n.length===0&&console.warn(`No elements found matching selector ${t}`),[...n]}function Qe(e){if(typeof e!="string"||e.length===0)throw"'prop' argument must be a String defining the name a property."}function Ue({nameWithDash:e,html:t,css:n,display:r,propertyList:i,actionList:u,eventHandlerList:o}){if(customElements.get(e))return!1;let f=class extends HTMLElement{constructor(){super();let s=this;nt(this,t,n,r),this.wi={},this.wi.properties=Xe(this,i),this.wi.actions=et(this,u),tt(this,o),this.wi.addProperty=function(a,c,w,Z,ee){let te={name:a,value:c,sel:w,attr:Z,onChange:ee};U(s.wi.properties,te,s)},this.wi.addAction=(a,c)=>X(s,s.wi.actions,a,c),this.wi.addEventListener=(a,c,w)=>Y(s,{sel:a,eventName:c,listener:w})}};return customElements.define(e,f),!0}function Xe(e,t){let n={};return Ze(t)&&t.forEach(r=>U(n,r,e)),n}function U(e,t,n){let r=Ye(t,n);C({obj:e,prop:t.name,sel:t.sel,attr:t.attr,root:n.shadowRoot,onChange:r}),t.value!==void 0&&(e[t.name]=t.value)}function Ye(e,t){if(!!e.onChange)return(n,r)=>e.onChange(t,n,r)}function Ze(e){if(!e)return!1;if(!Array.isArray(e))throw"propertyList must be an array of {name, value, [sel], [attr]} objects";return!0}function et(e,t){let n={};return t&&t.forEach(r=>{X(e,n,r.name,r.action)}),n}function X(e,t,n,r){!d.isString(n)||!d.isFunction(r)||(t[n]=r.bind(e))}function tt(e,t){if(!!t){if(!Array.isArray(t))throw"eventHandlerList must be an array of {sel, eventName, listener} objects";t.forEach(n=>Y(e,n))}}function Y(e,{sel:t,eventName:n,listener:r}){l.all(t,e.shadowRoot).forEach(u=>{u.addEventListener(n,o=>{r(o,e)})})}function nt(e,t,n,r){t=rt(e,t);let i=e.attachShadow({mode:"open"}),u=l.createElements(it(n,r)+t);i.append(...u)}function rt(e,t){return d.isFunction(t)?t(e):t}function it(e,t){return ot(t)+ut(e)}function ut(e){return e=h.trim(e),e.length===0?"":(h.startsWith(e,"<style>",!1)||(e=l.tag("style",{},e)),e)}function ot(e){return e=h.trim(e),e.length===0?"":`
10
+ `),t&&(e=e.map(r=>A(r))),n&&(e=e.filter(r=>!!r)),e}function C({obj:e={},prop:t,sel:n,attr:r,root:i=document,getter:u,setter:o,onChange:f}){Qe(t),ke(e,t);let s={};return u||(u=()=>Be({prop:t,sel:n,attr:r,root:i,objNotBound:s})),o||(o=a=>ze({prop:t,value:a,root:i,sel:n,attr:r,objNotBound:s})),Ve({obj:e,prop:t,getter:u,setter:o,onChange:f})}function Ve({obj:e,prop:t,getter:n,setter:r,onChange:i}){return Object.defineProperty(e,t,{get:()=>n(),set:o=>{if(i){let f=n(t);f!==o&&i(f,o)}r(o)},configurable:!0,enumerable:!0}),e}var E=e=>e.type==="checkbox",b=e=>e.type==="radio",G=e=>e.nodeName.toLowerCase()==="select",J=e=>e.nodeName.toLowerCase()==="input-field",K=e=>"value"in e,z=e=>new Set(Array.isArray(e)?e:[e]);function ke(e,t){let n=e[t];return n!==void 0&&(console.info(`Property '${t}' already exists in object. Will override previous definition but retain old value of ${n}.`),e[t]=n),n}function Be({prop:e,root:t,sel:n,attr:r,objNotBound:i}){return n?Ge(t,n,r):i[e]}function ze({prop:e,value:t,root:n,sel:r,attr:i,objNotBound:u}){if(r){Je(n,r,t,i);return}u[e]=t}function Ge(e,t,n){let r=Q(e,t);if(r.length===0)return null;let i=r[0];if(n)return i.getAttribute(n);if(!K(i))return i.innerHTML;if(E(i))return r.filter(u=>E(u)&&u.checked).map(u=>u.value==="on"?u.name:u.value);if(G(i))return[...i.querySelectorAll("option")].filter(o=>o.selected).map(o=>o.value);if(!(b(i)&&(i=r.filter(b).find(u=>u.checked),!i)))return J(i)?i.getAttribute("value"):i.value}function Je(e,t,n,r){let i=Q(e,t);if(i.length===0)return;let u=i[0];if(E(u)){let o=z(n);i.filter(E).forEach(f=>f.checked=o.has(f.value)||o.has(f.name));return}if(G(u)){let o=z(n);u.querySelectorAll("option").forEach(f=>f.selected=o.has(f.value));return}if(b(u)){i.filter(b).forEach(o=>o.checked=o.value===n);return}i.forEach(o=>Ke(o,n,r))}function Ke(e,t,n){n?e.setAttribute(n,t):K(e)?e.value=t:J(e)?e.setAttribute("value",t):e.innerHTML=t}function Q(e,t){let n=e.querySelectorAll(t);return n.length===0&&console.warn(`No elements found matching selector ${t}`),[...n]}function Qe(e){if(typeof e!="string"||e.length===0)throw"'prop' argument must be a String defining the name a property."}function Ue({nameWithDash:e,html:t,css:n,display:r,propertyList:i,actionList:u,eventHandlerList:o}){if(customElements.get(e))return!1;let f=class extends HTMLElement{constructor(){super();let s=this;nt(this,t,n,r),this.wi={},this.wi.properties=Xe(this,i),this.wi.actions=et(this,u),tt(this,o),this.wi.addProperty=function(a,c,w,Z,ee){let te={name:a,value:c,sel:w,attr:Z,onChange:ee};U(s.wi.properties,te,s)},this.wi.addAction=(a,c)=>X(s,s.wi.actions,a,c),this.wi.addEventListener=(a,c,w)=>Y(s,{sel:a,eventName:c,listener:w})}};return customElements.define(e,f),!0}function Xe(e,t){let n={};return Ze(t)&&t.forEach(r=>U(n,r,e)),n}function U(e,t,n){let r=Ye(t,n);C({obj:e,prop:t.name,sel:t.sel,attr:t.attr,root:n.shadowRoot,onChange:r}),t.value!==void 0&&(e[t.name]=t.value)}function Ye(e,t){if(e.onChange)return(n,r)=>e.onChange(t,n,r)}function Ze(e){if(!e)return!1;if(!Array.isArray(e))throw"propertyList must be an array of {name, value, [sel], [attr]} objects";return!0}function et(e,t){let n={};return t&&t.forEach(r=>{X(e,n,r.name,r.action)}),n}function X(e,t,n,r){!d.isString(n)||!d.isFunction(r)||(t[n]=r.bind(e))}function tt(e,t){if(t){if(!Array.isArray(t))throw"eventHandlerList must be an array of {sel, eventName, listener} objects";t.forEach(n=>Y(e,n))}}function Y(e,{sel:t,eventName:n,listener:r}){l.all(t,e.shadowRoot).forEach(u=>{u.addEventListener(n,o=>{r(o,e)})})}function nt(e,t,n,r){t=rt(e,t);let i=e.attachShadow({mode:"open"}),u=l.createElements(it(n,r)+t);i.append(...u)}function rt(e,t){return d.isFunction(t)?t(e):t}function it(e,t){return ot(t)+ut(e)}function ut(e){return e=h.trim(e),e.length===0?"":(h.startsWith(e,"<style>",!1)||(e=l.tag("style",{},e)),e)}function ot(e){return e=h.trim(e),e.length===0?"":`
11
11
  <style>
12
12
  :host { display: ${e};}
13
13
  :host([hidden]) {display: none;}
@@ -1,6 +1,6 @@
1
1
  // webitem.js Library to simplify creating HTML5 Custom Elements
2
2
  // https://github.com/ahabra/webitem
3
- // Copyright 2021 (C) Abdul Habra. Version 0.5.2.
3
+ // Copyright 2021 (C) Abdul Habra. Version 0.5.3.
4
4
  // Apache License Version 2.0
5
5
 
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techexp/webitem",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "Library to simplify creating Web Components/Custom Elements",
5
5
  "author": "Abdul Habra",
6
6
  "license": "Apache",
@@ -29,18 +29,18 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@esm-bundle/chai": "^4.3.4",
32
- "@web/test-runner": "^0.15.0",
33
- "@web/test-runner-commands": "^0.6.5",
34
- "@web/test-runner-puppeteer": "^0.11.0",
35
- "chalk": "^5.1.2",
36
- "esbuild": "^0.15.13",
37
- "eslint": "^8.27.0",
38
- "fs-extra": "^10.1.0",
39
- "npm-check-updates": "^16.3.18",
40
- "serve": "^14.1.1"
32
+ "@web/test-runner": "^0.18.0",
33
+ "@web/test-runner-commands": "^0.9.0",
34
+ "@web/test-runner-puppeteer": "^0.15.0",
35
+ "chalk": "^5.3.0",
36
+ "esbuild": "^0.19.10",
37
+ "eslint": "^8.56.0",
38
+ "fs-extra": "^11.2.0",
39
+ "npm-check-updates": "^16.14.12",
40
+ "serve": "^14.2.1"
41
41
  },
42
42
  "dependencies": {
43
- "@techexp/data-bind": "^0.9.0",
44
- "@techexp/jshelper": "^0.6.2"
43
+ "@techexp/data-bind": "^0.9.3",
44
+ "@techexp/jshelper": "^0.6.3"
45
45
  }
46
46
  }