carbonium 1.2.4 → 1.3.0

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.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![CodeQL](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml/badge.svg)](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml) [![Coverage Status](https://coveralls.io/repos/github/edwinm/carbonium/badge.svg?branch=master)](https://coveralls.io/github/edwinm/carbonium?branch=master) [![Socket Badge](https://socket.dev/api/badge/npm/package/carbonium)](https://socket.dev/npm/package/carbonium) [![CodeFactor](https://www.codefactor.io/repository/github/edwinm/carbonium/badge)](https://www.codefactor.io/repository/github/edwinm/carbonium) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=edwinm_carbonium&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=edwinm_carbonium) [![Size](https://badgen.net/badgesize/gzip/edwinm/carbonium/master/dist/bundle.min.js)](https://bundlephobia.com/result?p=carbonium) [![npm version](https://badge.fury.io/js/carbonium.svg)](https://www.npmjs.com/package/carbonium) [![GitHub](https://img.shields.io/github/license/edwinm/carbonium.svg)](https://github.com/edwinm/carbonium/blob/master/LICENSE)
1
+ [![Scorecard supply-chain security](https://github.com/edwinm/carbonium/actions/workflows/scorecard.yml/badge.svg)](https://github.com/edwinm/carbonium/actions/workflows/scorecard.yml) [![CodeQL](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml/badge.svg)](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml) [![Coverage Status](https://coveralls.io/repos/github/edwinm/carbonium/badge.svg?branch=master)](https://coveralls.io/github/edwinm/carbonium?branch=master) [![Socket Badge](https://socket.dev/api/badge/npm/package/carbonium)](https://socket.dev/npm/package/carbonium) [![CodeFactor](https://www.codefactor.io/repository/github/edwinm/carbonium/badge)](https://www.codefactor.io/repository/github/edwinm/carbonium) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=edwinm_carbonium&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=edwinm_carbonium) [![Snyk test results](https://snyk.io/test/github/edwinm/carbonium/badge.svg)](https://snyk.io/test/github/edwinm/carbonium) [![Size](https://badgen.net/bundlephobia/minzip/carbonium)](https://bundlephobia.com/package/carbonium) [![npm version](https://badge.fury.io/js/carbonium.svg)](https://www.npmjs.com/package/carbonium) [![GitHub](https://img.shields.io/github/license/edwinm/carbonium.svg)](https://github.com/edwinm/carbonium/blob/master/LICENSE) ![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/edwinm/carbonium?utm_source=oss&utm_medium=github&utm_campaign=edwinm%2Fcarbonium&labelColor=171717&color=FF570A&link=https%3A%2F%2Fcoderabbit.ai&label=CodeRabbit+Reviews)
2
2
 
3
3
  [![Carbonium](https://raw.githubusercontent.com/edwinm/carbonium/master/assets/carbonium.svg)](#readme)
4
4
 
@@ -1,7 +1,7 @@
1
1
  var carbonium=function(e){"use strict";
2
2
  /**
3
- Carbonium 1.2.4
4
- @copyright 2020 Edwin Martin
5
- @license MIT
6
- */let t,n;const o={get(e,r){let c=null;if(r==Symbol.iterator)return function*(){for(const t of e)yield t};if("style"==r||"classList"==r||"relList"==r){t=e,n=r;const c=Reflect.get(document.body,r);return new Proxy(c,o)}if(e instanceof CSSStyleDeclaration||e instanceof DOMTokenList)return c=Reflect.get(document.body[n],r),"function"==typeof c?new Proxy(c,{apply:function(e,r,c){return t.forEach((t=>{Reflect.apply(e,t[n],c)})),new Proxy(t,o)}}):c;if(Array.prototype.hasOwnProperty(r)){const e=Reflect.get(Array.prototype,r);if("function"==typeof e)return new Proxy(e,{apply:function(e,t,n){const r=Reflect.apply(e,t,n);return new Proxy(void 0!==r?r:t,o)}})}return e.length>0?r in e[0]&&(c=Reflect.get(e[0],r)):r in document.body&&(c=Reflect.get(document.body,r)),c?"function"==typeof c?new Proxy(c,{apply:function(e,t,n){let o=null,r=!0;for(const c of t){const t=Reflect.apply(e,c,n);r&&(o=t,r=!1)}return null!=o?o:t}}):c:Reflect.get(e,r)},set:(e,t,n)=>(!("forEach"in e)||e instanceof CSSStyleDeclaration?Reflect.set(e,t,n):e.forEach((e=>{Reflect.set(e,t,n)})),!0),deleteProperty:(e,t)=>t in e&&delete e[t]};return e.$=function(e,t){let n;return n=e.startsWith("<")?[(new DOMParser).parseFromString(e,"text/html").body.firstChild]:(t||document).querySelectorAll(e),new Proxy(n,o)},e}({});
3
+ Carbonium 1.3.0
4
+ @copyright 2020 Edwin Martin
5
+ @license MIT
6
+ */let t,n;const o={get(e,r){let c=null;if(r==Symbol.iterator)return function*(){for(const t of e)yield t};if("style"==r||"classList"==r||"relList"==r){t=e,n=r;const c=Reflect.get(document.body,r);return new Proxy(c,o)}if(e instanceof CSSStyleDeclaration||e instanceof DOMTokenList)return c=Reflect.get(document.body[n],r),"function"==typeof c?new Proxy(c,{apply:function(e,r,c){return t.forEach((t=>{Reflect.apply(e,t[n],c)})),new Proxy(t,o)}}):c;if(Array.prototype.hasOwnProperty(r)){const e=Reflect.get(Array.prototype,r);if("function"==typeof e)return new Proxy(e,{apply:function(e,t,n){const r=Reflect.apply(e,t,n);return new Proxy(void 0!==r?r:t,o)}})}return e.length>0?r in e[0]&&(c=Reflect.get(e[0],r)):r in document.body&&(c=Reflect.get(document.body,r)),c?"function"==typeof c?new Proxy(c,{apply:function(e,t,n){let o=null,r=!0;for(const c of t){const t=Reflect.apply(e,c,n);r&&(o=t,r=!1)}return null!=o?o:t}}):c:Reflect.get(e,r)},set:(e,t,n)=>(!("forEach"in e)||e instanceof CSSStyleDeclaration?Reflect.set(e,t,n):e.forEach((e=>{Reflect.set(e,t,n)})),!0),deleteProperty:(e,t)=>t in e&&delete e[t]};return e.$=function(e,t){let n;return n=e.startsWith("<")?[(new DOMParser).parseFromString(e,"text/html").body.firstChild]:(t||document).querySelectorAll(e),new Proxy(n,o)},e}({});
7
7
  //# sourceMappingURL=bundle.iife.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.iife.min.js","sources":["../src/carbonium.ts"],"sourcesContent":["/**\n Carbonium __buildVersion__\n @copyright 2020 Edwin Martin\n @license MIT\n */\n\nexport function $<T extends HTMLElement = HTMLElement>(\n selectors: string,\n parentNode?: Document | ShadowRoot | HTMLElement\n): CarboniumType<T> {\n let nodelist: NodeListOf<T>;\n\n // If the first parameter starts with \"<\", create a DOM node\n if (selectors.startsWith(\"<\")) {\n nodelist = <NodeListOf<T>>(\n (<unknown>[\n new DOMParser().parseFromString(selectors, \"text/html\").body.firstChild,\n ])\n );\n } else {\n // Else, do querySelectorAll\n nodelist = (parentNode || document).querySelectorAll(selectors);\n }\n\n // Wrap it in a Proxy\n return <CarboniumType<T>>(\n (<unknown>new Proxy<NodeListOf<T>>(nodelist, proxyHandler))\n );\n}\n\n// Used by style, classList and relList\n// When setting one of these, remember the elements to apply to\nlet currentListNodelist: NodeListOf<HTMLElement>;\nlet propList: \"style\" | \"classList\" | \"relList\";\n\nconst proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {\n get(target, prop) {\n let propValue = null;\n\n // Return iterator when asked for iterator, only used in ES2015+\n if (prop == Symbol.iterator) {\n return function* () {\n for (const element of target) {\n yield element;\n }\n };\n }\n\n // Special case for style, classList and relList\n if (prop == \"style\" || prop == \"classList\" || prop == \"relList\") {\n currentListNodelist = target;\n propList = prop;\n // Matched elements can be a list of any element or an empty list\n // Use getter of, for example, document.body.style\n const propValue = Reflect.get(document.body, prop);\n return new Proxy(propValue, proxyHandler);\n }\n\n // style.setProperty, getPropertyValue…, classList.add, contains, remove…, relList…\n if (\n target instanceof CSSStyleDeclaration ||\n target instanceof DOMTokenList\n ) {\n // Matched elements can be a list of any element or an empty list\n // Use getter of, for example, document.body.style.color\n propValue = Reflect.get(document.body[propList], prop);\n\n // When getter is a function, apply it to all matched elements\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n currentListNodelist.forEach((el) => {\n Reflect.apply(target, el[propList], argumentsList);\n });\n return new Proxy(currentListNodelist, proxyHandler);\n },\n });\n } else {\n return propValue;\n }\n }\n\n // Are we dealing with an Array function like forEach, map and filter?\n if (Array.prototype.hasOwnProperty(prop)) {\n const propValue = Reflect.get(Array.prototype, prop);\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n const ret = Reflect.apply(target, thisArg, argumentsList);\n // When function returns undefined (like forEach),\n // return all matched elements, so calls can be chained\n // For example forEach(…).setAttribute(…)\n const newTarget = typeof ret != \"undefined\" ? ret : thisArg;\n return new Proxy(newTarget, proxyHandler);\n },\n });\n }\n }\n\n // Get property or call function on DOM elements\n if (target.length > 0) {\n // Might be DOM element specific, like input.select(),\n // so use first array element to get reference\n if (prop in target[0]) {\n propValue = Reflect.get(target[0], prop);\n }\n } else {\n // Empty list, targeted DOM element unknown,\n // use getter of document.body\n if (prop in document.body) {\n propValue = Reflect.get(document.body, prop);\n }\n }\n\n // Propagate DOM prop value\n if (propValue) {\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n let retFirst = null;\n let first = true;\n // Apply on individual elements\n for (const el of thisArg) {\n const ret = Reflect.apply(target, el, argumentsList);\n if (first) {\n retFirst = ret;\n first = false;\n }\n }\n return retFirst ?? thisArg;\n },\n });\n } else {\n return propValue;\n }\n }\n\n // Default\n return Reflect.get(target, prop);\n },\n\n // DOM property is set\n set(target, prop, value) {\n if (\"forEach\" in target && !(target instanceof CSSStyleDeclaration)) {\n target.forEach((el) => {\n Reflect.set(el, prop, value);\n });\n } else {\n Reflect.set(target, prop, value);\n }\n return true;\n },\n\n deleteProperty(target, prop) {\n if (prop in target) {\n return delete target[prop];\n }\n return false;\n },\n};\n\nexport type CarboniumType<T extends HTMLElement = HTMLElement> =\n CarboniumList<T> & T;\n\n// Interface definitions\n\ninterface CarboniumList<T extends HTMLElement> extends Array<T> {\n concat(...items: ConcatArray<T>[]): CarboniumType<T>;\n\n concat(...items: (T | ConcatArray<T>)[]): CarboniumType<T>;\n\n reverse(): CarboniumType<T>;\n\n slice(start?: number, end?: number): CarboniumType<T>;\n\n splice(start: number, deleteCount?: number): CarboniumType<T>;\n\n /* tslint:disable:unified-signatures */\n splice(start: number, deleteCount: number, ...items: T[]): CarboniumType<T>;\n\n forEach(\n callbackfn: (value: T, index: number, array: T[]) => void,\n thisArg?: any\n ): CarboniumType<T>;\n\n filter(\n callbackfn: (value: T, index: number, array: T[]) => boolean,\n thisArg?: any\n ): CarboniumType<T>;\n\n setAttribute(qualifiedName: string, value: string): CarboniumType<T>;\n\n classList: CarboniumClassList<T>;\n style: CarboniumStyleList<T>;\n}\n\ninterface CarboniumClassList<T extends HTMLElement> extends DOMTokenList {\n add(...tokens: string[]): CarboniumType<T>;\n\n remove(...tokens: string[]): CarboniumType<T>;\n\n replace(oldToken: string, newToken: string): boolean;\n\n forEach(\n callbackfn: (value: string, key: number, parent: DOMTokenList) => void,\n thisArg?: any\n ): CarboniumType<T>;\n}\n\ninterface CarboniumStyleList<T extends HTMLElement>\n extends CSSStyleDeclaration {\n removeProperty(property: string): CarboniumList<T> & string;\n\n setProperty(\n property: string,\n value: string | null,\n priority?: string\n ): CarboniumType<T>;\n}\n"],"names":["currentListNodelist","propList","proxyHandler","get","target","prop","propValue","Symbol","iterator","element","Reflect","document","body","Proxy","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","length","retFirst","first","set","value","deleteProperty","selectors","parentNode","nodelist","startsWith","DOMParser","parseFromString","firstChild","querySelectorAll"],"mappings":";;;;;KAgCA,IAAIA,EACAC,EAEJ,MAAMC,EAAsD,CAC1DC,IAAIC,EAAQC,GACV,IAAIC,EAAY,KAGhB,GAAID,GAAQE,OAAOC,SACjB,OAAO,YACL,IAAK,MAAMC,KAAWL,QACdK,CAEV,EAIF,GAAY,SAARJ,GAA2B,aAARA,GAA+B,WAARA,EAAm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QC,EAAMwB,OACZ,YAAazB,IAAYA,aAAkBU,oBAK7CJ,QAAQkB,IAAIxB,EAAQC,EAAMwB,GAJ1BzB,EAAOe,SAASC,IACdV,QAAQkB,IAAIR,EAAIf,EAAMwB,EAAM,KAKzB,GAGTC,eAAc,CAAC1B,EAAQC,IACjBA,KAAQD,UACIA,EAAOC,eArJX,SACd0B,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADEF,EAAUG,WAAW,KAEX,EACR,IAAIC,WAAYC,gBAAgBL,EAAW,aAAanB,KAAKyB,aAKrDL,GAAcrB,UAAU2B,iBAAiBP,GAK3C,IAAIlB,MAAqBoB,EAAU/B,EAEjD"}
1
+ {"version":3,"file":"bundle.iife.min.js","sources":["../src/carbonium.ts"],"sourcesContent":[null],"names":["currentListNodelist","propList","proxyHandler","get","target","prop","propValue","Symbol","iterator","element","Reflect","document","body","Proxy","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","length","retFirst","first","set","value","deleteProperty","selectors","parentNode","nodelist","startsWith","DOMParser","parseFromString","firstChild","querySelectorAll"],"mappings":";;;;;OAgCA,IAAIA,EACAC,EAEJ,MAAMC,EAAsD,CAC1D,GAAAC,CAAIC,EAAQC,GACV,IAAIC,EAAY,KAGhB,GAAID,GAAQE,OAAOC,SACjB,OAAO,YACL,IAAK,MAAMC,KAAWL,QACdK,CAEV,EAIF,GAAY,SAARJ,GAA2B,aAARA,GAA+B,WAARA,EAAmB,CAC/DL,EAAsBI,EACtBH,EAAWI,EAGX,MAAMC,EAAYI,QAAQP,IAAIQ,SAASC,KAAMP,GAC7C,OAAO,IAAIQ,MAAMP,EAAWJ,EAC9B,CAGA,GACEE,aAAkBU,qBAClBV,aAAkBW,aAOlB,OAHAT,EAAYI,QAAQP,IAAKQ,SAASC,KAAaX,GAAWI,GAGlC,mBAAbC,EACF,IAAIO,MAAgBP,EAAW,CACpCU,MAAO,SAAUZ,EAAQa,EAASC,GAIhC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AAYC,gBAAgBL,EAAW,aAAanB,KAAKyB,aAKrDL,GAAcrB,UAAU2B,iBAAiBP,GAK3C,IAAIlB,MAAqBoB,EAAU/B,EAEjD"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- Carbonium 1.2.4
2
+ Carbonium 1.3.0
3
3
  @copyright 2020 Edwin Martin
4
4
  @license MIT
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.min.js","sources":["../src/carbonium.ts"],"sourcesContent":["/**\n Carbonium __buildVersion__\n @copyright 2020 Edwin Martin\n @license MIT\n */\n\nexport function $<T extends HTMLElement = HTMLElement>(\n selectors: string,\n parentNode?: Document | ShadowRoot | HTMLElement\n): CarboniumType<T> {\n let nodelist: NodeListOf<T>;\n\n // If the first parameter starts with \"<\", create a DOM node\n if (selectors.startsWith(\"<\")) {\n nodelist = <NodeListOf<T>>(\n (<unknown>[\n new DOMParser().parseFromString(selectors, \"text/html\").body.firstChild,\n ])\n );\n } else {\n // Else, do querySelectorAll\n nodelist = (parentNode || document).querySelectorAll(selectors);\n }\n\n // Wrap it in a Proxy\n return <CarboniumType<T>>(\n (<unknown>new Proxy<NodeListOf<T>>(nodelist, proxyHandler))\n );\n}\n\n// Used by style, classList and relList\n// When setting one of these, remember the elements to apply to\nlet currentListNodelist: NodeListOf<HTMLElement>;\nlet propList: \"style\" | \"classList\" | \"relList\";\n\nconst proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {\n get(target, prop) {\n let propValue = null;\n\n // Return iterator when asked for iterator, only used in ES2015+\n if (prop == Symbol.iterator) {\n return function* () {\n for (const element of target) {\n yield element;\n }\n };\n }\n\n // Special case for style, classList and relList\n if (prop == \"style\" || prop == \"classList\" || prop == \"relList\") {\n currentListNodelist = target;\n propList = prop;\n // Matched elements can be a list of any element or an empty list\n // Use getter of, for example, document.body.style\n const propValue = Reflect.get(document.body, prop);\n return new Proxy(propValue, proxyHandler);\n }\n\n // style.setProperty, getPropertyValue…, classList.add, contains, remove…, relList…\n if (\n target instanceof CSSStyleDeclaration ||\n target instanceof DOMTokenList\n ) {\n // Matched elements can be a list of any element or an empty list\n // Use getter of, for example, document.body.style.color\n propValue = Reflect.get(document.body[propList], prop);\n\n // When getter is a function, apply it to all matched elements\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n currentListNodelist.forEach((el) => {\n Reflect.apply(target, el[propList], argumentsList);\n });\n return new Proxy(currentListNodelist, proxyHandler);\n },\n });\n } else {\n return propValue;\n }\n }\n\n // Are we dealing with an Array function like forEach, map and filter?\n if (Array.prototype.hasOwnProperty(prop)) {\n const propValue = Reflect.get(Array.prototype, prop);\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n const ret = Reflect.apply(target, thisArg, argumentsList);\n // When function returns undefined (like forEach),\n // return all matched elements, so calls can be chained\n // For example forEach(…).setAttribute(…)\n const newTarget = typeof ret != \"undefined\" ? ret : thisArg;\n return new Proxy(newTarget, proxyHandler);\n },\n });\n }\n }\n\n // Get property or call function on DOM elements\n if (target.length > 0) {\n // Might be DOM element specific, like input.select(),\n // so use first array element to get reference\n if (prop in target[0]) {\n propValue = Reflect.get(target[0], prop);\n }\n } else {\n // Empty list, targeted DOM element unknown,\n // use getter of document.body\n if (prop in document.body) {\n propValue = Reflect.get(document.body, prop);\n }\n }\n\n // Propagate DOM prop value\n if (propValue) {\n if (typeof propValue == \"function\") {\n return new Proxy<Function>(propValue, {\n apply: function (target, thisArg, argumentsList) {\n let retFirst = null;\n let first = true;\n // Apply on individual elements\n for (const el of thisArg) {\n const ret = Reflect.apply(target, el, argumentsList);\n if (first) {\n retFirst = ret;\n first = false;\n }\n }\n return retFirst ?? thisArg;\n },\n });\n } else {\n return propValue;\n }\n }\n\n // Default\n return Reflect.get(target, prop);\n },\n\n // DOM property is set\n set(target, prop, value) {\n if (\"forEach\" in target && !(target instanceof CSSStyleDeclaration)) {\n target.forEach((el) => {\n Reflect.set(el, prop, value);\n });\n } else {\n Reflect.set(target, prop, value);\n }\n return true;\n },\n\n deleteProperty(target, prop) {\n if (prop in target) {\n return delete target[prop];\n }\n return false;\n },\n};\n\nexport type CarboniumType<T extends HTMLElement = HTMLElement> =\n CarboniumList<T> & T;\n\n// Interface definitions\n\ninterface CarboniumList<T extends HTMLElement> extends Array<T> {\n concat(...items: ConcatArray<T>[]): CarboniumType<T>;\n\n concat(...items: (T | ConcatArray<T>)[]): CarboniumType<T>;\n\n reverse(): CarboniumType<T>;\n\n slice(start?: number, end?: number): CarboniumType<T>;\n\n splice(start: number, deleteCount?: number): CarboniumType<T>;\n\n /* tslint:disable:unified-signatures */\n splice(start: number, deleteCount: number, ...items: T[]): CarboniumType<T>;\n\n forEach(\n callbackfn: (value: T, index: number, array: T[]) => void,\n thisArg?: any\n ): CarboniumType<T>;\n\n filter(\n callbackfn: (value: T, index: number, array: T[]) => boolean,\n thisArg?: any\n ): CarboniumType<T>;\n\n setAttribute(qualifiedName: string, value: string): CarboniumType<T>;\n\n classList: CarboniumClassList<T>;\n style: CarboniumStyleList<T>;\n}\n\ninterface CarboniumClassList<T extends HTMLElement> extends DOMTokenList {\n add(...tokens: string[]): CarboniumType<T>;\n\n remove(...tokens: string[]): CarboniumType<T>;\n\n replace(oldToken: string, newToken: string): boolean;\n\n forEach(\n callbackfn: (value: string, key: number, parent: DOMTokenList) => void,\n thisArg?: any\n ): CarboniumType<T>;\n}\n\ninterface CarboniumStyleList<T extends HTMLElement>\n extends CSSStyleDeclaration {\n removeProperty(property: string): CarboniumList<T> & string;\n\n setProperty(\n property: string,\n value: string | null,\n priority?: string\n ): CarboniumType<T>;\n}\n"],"names":["$","selectors","parentNode","nodelist","startsWith","DOMParser","parseFromString","body","firstChild","document","querySelectorAll","Proxy","proxyHandler","currentListNodelist","propList","get","target","prop","propValue","Symbol","iterator","element","Reflect","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProper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QAAQP,IAAIC,EAAO,GAAIC,IAKjCA,KAAQR,SAASF,OACnBW,EAAYI,QAAQP,IAAIN,SAASF,KAAMU,IAKvCC,EACsB,mBAAbA,EACF,IAAIP,MAAgBO,EAAW,CACpCO,MAAO,SAAUT,EAAQU,EAASC,GAChC,IAAIQ,EAAW,KACXC,GAAQ,EAEZ,IAAK,MAAMP,KAAMH,EAAS,CACxB,MAAMO,EAAMX,QAAQG,MAAMT,EAAQa,EAAIF,GAClCS,IACFD,EAAWF,EACXG,GAAQ,EAEX,CACD,OAAOD,QAAAA,EAAYT,CACpB,IAGIR,EAKJI,QAAQP,IAAIC,EAAQC,EAC5B,EAGDoB,IAAG,CAACrB,EAAQC,EAAMqB,OACZ,YAAatB,IAAYA,aAAkBO,oBAK7CD,QAAQe,IAAIrB,EAAQC,EAAMqB,GAJ1BtB,EAAOY,SAASC,IACdP,QAAQe,IAAIR,EAAIZ,EAAMqB,EAAM,KAKzB,GAGTC,eAAc,CAACvB,EAAQC,IACjBA,KAAQD,UACIA,EAAOC"}
1
+ {"version":3,"file":"bundle.min.js","sources":["../src/carbonium.ts"],"sourcesContent":[null],"names":["$","selectors","parentNode","nodelist","startsWith","DOMParser","parseFromString","body","firstChild","document","querySelectorAll","Proxy","proxyHandler","currentListNodelist","propList","get","target","prop","propValue","Symbol","iterator","element","Reflect","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","length","retFirst","first","set","value","deleteProperty"],"mappings":";;;;;AAMM,SAAUA,EACdC,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADEF,EAAUG,WAAW,KAEX,EACR,IAAIC,WAAYC,gBAAgBL,EAAW,aAAaM,KAAKC,aAKrDN,GAAcO,UAAUC,iBAAiBT,GAK3C,IAAIU,MAAqBR,EAAUS,EAEjD,CAIA,IAAIC,EACAC,EAEJ,MAAMF,EAAsD,CAC1D,GAAAG,CAAIC,EAAQC,GACV,IAAIC,EAAY,KAGhB,G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ACA,OAAOD,QAAAA,EAAYT,CACrB,IAGKR,EAKJI,QAAQP,IAAIC,EAAQC,EAC7B,EAGAoB,IAAG,CAACrB,EAAQC,EAAMqB,OACZ,YAAatB,IAAYA,aAAkBO,oBAK7CD,QAAQe,IAAIrB,EAAQC,EAAMqB,GAJ1BtB,EAAOY,SAASC,IACdP,QAAQe,IAAIR,EAAIZ,EAAMqB,EAAM,KAKzB,GAGTC,eAAc,CAACvB,EAAQC,IACjBA,KAAQD,UACKA,EAAeC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- Carbonium 1.2.4
2
+ Carbonium __buildVersion__
3
3
  @copyright 2020 Edwin Martin
4
4
  @license MIT
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbonium",
3
- "version": "1.2.4",
3
+ "version": "1.3.0",
4
4
  "description": "One kilobyte library for easy DOM manipulation",
5
5
  "type": "module",
6
6
  "browser": "dist/bundle.iife.min.js",
@@ -8,13 +8,14 @@
8
8
  "types": "dist/carbonium.d.ts",
9
9
  "sideEffects": false,
10
10
  "scripts": {
11
- "prepare": "husky install",
11
+ "prepare": "husky",
12
12
  "start": "http-server -o demo/ --silent",
13
- "build": "rollup --config --sourcemap --bundleConfigAsCjs",
13
+ "build": "rollup --config --sourcemap",
14
14
  "dev": "rollup --config --sourcemap --watch",
15
- "release": "npm i --package-lock && npm run lint && npm test && npm run build && npm publish",
16
- "test": "karma start karma.conf.cjs",
17
- "lint": "npx eslint . --ext .js,.ts",
15
+ "release": "npm i --package-lock && npm run lint && npm test && npm publish",
16
+ "pretest": "npm run build",
17
+ "test": "playwright test",
18
+ "lint": "npx eslint .",
18
19
  "prettier": "prettier --config .prettierrc.json src/**/*.ts *.json --write"
19
20
  },
20
21
  "repository": {
@@ -30,6 +31,7 @@
30
31
  "dist/bundle.iife.min.js.map"
31
32
  ],
32
33
  "keywords": [
34
+ "front-end",
33
35
  "dom",
34
36
  "qsa",
35
37
  "jquery",
@@ -49,30 +51,24 @@
49
51
  },
50
52
  "homepage": "https://github.com/edwinm/carbonium#readme",
51
53
  "devDependencies": {
52
- "@rollup/plugin-replace": "^5.0.2",
53
- "@rollup/plugin-terser": "^0.4.3",
54
- "@types/mocha": "^10.0.1",
55
- "@types/node": "^20.3.2",
56
- "@typescript-eslint/eslint-plugin": "^5.60.1",
57
- "@typescript-eslint/parser": "^5.60.1",
58
- "@webcomponents/webcomponentsjs": "^2.8.0",
59
- "eslint": "^8.43.0",
60
- "eslint-config-prettier": "^8.8.0",
54
+ "@eslint/js": "^9.39.4",
55
+ "@playwright/test": "^1.59.1",
56
+ "@rollup/plugin-replace": "^6.0.3",
57
+ "@rollup/plugin-terser": "^1.0.0",
58
+ "@rollup/plugin-typescript": "^12.3.0",
59
+ "@types/node": "^22.19.17",
60
+ "@typescript-eslint/eslint-plugin": "^8.58.0",
61
+ "@typescript-eslint/parser": "^8.58.0",
62
+ "eslint": "^9.39.4",
63
+ "eslint-config-prettier": "^10.1.8",
64
+ "globals": "^17.4.0",
61
65
  "http-server": "^14.1.1",
62
- "husky": "^8.0.3",
63
- "karma": "^6.4.2",
64
- "karma-chai": "^0.1.0",
65
- "karma-chrome-launcher": "^3.2.0",
66
- "karma-coverage": "^2.2.1",
67
- "karma-firefox-launcher": "^2.1.2",
68
- "karma-mocha": "^2.0.1",
69
- "karma-typescript": "^5.5.4",
70
- "mocha": "^10.2.0",
71
- "prettier": "^2.8.8",
72
- "pretty-quick": "^3.1.3",
73
- "rollup": "^3.25.3",
74
- "rollup-plugin-typescript2": "^0.35.0",
75
- "tslib": "^2.6.0",
76
- "typescript": "5.1"
66
+ "husky": "^9.1.7",
67
+ "prettier": "^3.8.1",
68
+ "pretty-quick": "^4.2.2",
69
+ "rollup": "^4.60.1",
70
+ "tslib": "^2.8.1",
71
+ "typescript": "^6.0.2",
72
+ "typescript-eslint": "^8.58.0"
77
73
  }
78
74
  }
package/src/carbonium.ts CHANGED
@@ -63,14 +63,14 @@ const proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {
63
63
  ) {
64
64
  // Matched elements can be a list of any element or an empty list
65
65
  // Use getter of, for example, document.body.style.color
66
- propValue = Reflect.get(document.body[propList], prop);
66
+ propValue = Reflect.get((document.body as any)[propList], prop);
67
67
 
68
68
  // When getter is a function, apply it to all matched elements
69
69
  if (typeof propValue == "function") {
70
70
  return new Proxy<Function>(propValue, {
71
71
  apply: function (target, thisArg, argumentsList) {
72
72
  currentListNodelist.forEach((el) => {
73
- Reflect.apply(target, el[propList], argumentsList);
73
+ Reflect.apply(target, (el as any)[propList], argumentsList);
74
74
  });
75
75
  return new Proxy(currentListNodelist, proxyHandler);
76
76
  },
@@ -153,7 +153,7 @@ const proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {
153
153
 
154
154
  deleteProperty(target, prop) {
155
155
  if (prop in target) {
156
- return delete target[prop];
156
+ return delete (target as any)[prop];
157
157
  }
158
158
  return false;
159
159
  },
@@ -207,8 +207,9 @@ interface CarboniumClassList<T extends HTMLElement> extends DOMTokenList {
207
207
  ): CarboniumType<T>;
208
208
  }
209
209
 
210
- interface CarboniumStyleList<T extends HTMLElement>
211
- extends CSSStyleDeclaration {
210
+ interface CarboniumStyleList<
211
+ T extends HTMLElement,
212
+ > extends CSSStyleDeclaration {
212
213
  removeProperty(property: string): CarboniumList<T> & string;
213
214
 
214
215
  setProperty(