carbonium 1.2.2 → 1.2.4
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 +2 -2
- package/dist/bundle.iife.min.js +2 -2
- package/dist/bundle.iife.min.js.map +1 -1
- package/dist/bundle.min.js +2 -2
- package/dist/bundle.min.js.map +1 -1
- package/dist/carbonium.d.ts +1 -1
- package/package.json +4 -4
- package/src/carbonium.ts +4 -6
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml) [](https://coveralls.io/github/edwinm/carbonium?branch=master) [](https://socket.dev/npm/package/carbonium) [](https://www.codefactor.io/repository/github/edwinm/carbonium) [](https://bundlephobia.com/result?p=carbonium) [](https://www.npmjs.com/package/carbonium) [](https://github.com/edwinm/carbonium/blob/master/LICENSE)
|
|
1
|
+
[](https://github.com/edwinm/carbonium/actions/workflows/codeql.yml) [](https://coveralls.io/github/edwinm/carbonium?branch=master) [](https://socket.dev/npm/package/carbonium) [](https://www.codefactor.io/repository/github/edwinm/carbonium) [](https://sonarcloud.io/summary/new_code?id=edwinm_carbonium) [](https://bundlephobia.com/result?p=carbonium) [](https://www.npmjs.com/package/carbonium) [](https://github.com/edwinm/carbonium/blob/master/LICENSE)
|
|
2
2
|
|
|
3
3
|
[](#readme)
|
|
4
4
|
|
|
5
|
-
> One kilobyte library for easy manipulation
|
|
5
|
+
> One kilobyte library for easy DOM manipulation
|
|
6
6
|
|
|
7
7
|
With carbonium, you can call `$(selector)` and the result can be accessed as both an DOM element and an array of matched elements.
|
|
8
8
|
DOM element operations are applied to all matched elements.
|
package/dist/bundle.iife.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var carbonium=function(e){"use strict";
|
|
2
2
|
/**
|
|
3
|
-
Carbonium 1.2.
|
|
3
|
+
Carbonium 1.2.4
|
|
4
4
|
@copyright 2020 Edwin Martin
|
|
5
5
|
@license MIT
|
|
6
|
-
*/let t,n;const o={get(e,r){let
|
|
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
|
|
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,EAAmB,CAC/DL,EAAsBI,EACtBH,EAAWI,EAGX,MAAMC,EAAYI,QAAQP,IAAIQ,SAASC,KAAMP,GAC7C,OAAO,IAAIQ,MAAMP,EAAWJ,EAC7B,CAGD,GACEE,aAAkBU,qBAClBV,aAAkBW,aAOlB,OAHAT,EAAYI,QAAQP,IAAIQ,SAASC,KAAKX,GAAWI,GAGzB,mBAAbC,EACF,IAAIO,MAAgBP,EAAW,CACpCU,MAAO,SAAUZ,EAAQa,EAASC,GAIhC,OAHAlB,EAAoBmB,SAASC,IAC3BV,QAAQM,MAAMZ,EAAQgB,EAAGnB,GAAWiB,EAAc,IAE7C,IAAIL,MAAMb,EAAqBE,EACvC,IAGII,EAKX,GAAIe,MAAMC,UAAUC,eAAelB,GAAO,CACxC,MAAMC,EAAYI,QAAQP,IAAIkB,MAAMC,UAAWjB,GAC/C,GAAwB,mBAAbC,EACT,OAAO,IAAIO,MAAgBP,EAAW,CACpCU,MAAO,SAAUZ,EAAQa,EAASC,GAChC,MAAMM,EAAMd,QAAQM,MAAMZ,EAAQa,EAASC,GAK3C,OAAO,IAAIL,WADqB,IAAPW,EAAqBA,EAAMP,EACxBf,EAC7B,GAGN,CAkBD,OAfIE,EAAOqB,OAAS,EAGdpB,KAAQD,EAAO,KACjBE,EAAYI,QAAQP,IAAIC,EAAO,GAAIC,IAKjCA,KAAQM,SAASC,OACnBN,EAAYI,QAAQP,IAAIQ,SAASC,KAAMP,IAKvCC,EACsB,mBAAbA,EACF,IAAIO,MAAgBP,EAAW,CACpCU,MAAO,SAAUZ,EAAQa,EAASC,GAChC,IAAIQ,EAAW,KACXC,GAAQ,EAEZ,IAAK,MAAMP,KAAMH,EAAS,CACxB,MAAMO,EAAMd,QAAQM,MAAMZ,EAAQgB,EAAIF,GAClCS,IACFD,EAAWF,EACXG,GAAQ,EAEX,CACD,OAAOD,QAAAA,EAAYT,CACpB,IAGIX,EAKJI,QAAQP,IAAIC,EAAQC,EAC5B,EAGDuB,IAAG,CAACxB,EAAQC,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"}
|
package/dist/bundle.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Carbonium 1.2.
|
|
2
|
+
Carbonium 1.2.4
|
|
3
3
|
@copyright 2020 Edwin Martin
|
|
4
4
|
@license MIT
|
|
5
5
|
*/
|
|
6
|
-
function e(e,t){let n;return n="<"
|
|
6
|
+
function e(e,t){let n;return n=e.startsWith("<")?[(new DOMParser).parseFromString(e,"text/html").body.firstChild]:(t||document).querySelectorAll(e),new Proxy(n,o)}let t,n;const o={get(e,r){let l=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 l=Reflect.get(document.body,r);return new Proxy(l,o)}if(e instanceof CSSStyleDeclaration||e instanceof DOMTokenList)return l=Reflect.get(document.body[n],r),"function"==typeof l?new Proxy(l,{apply:function(e,r,l){return t.forEach((t=>{Reflect.apply(e,t[n],l)})),new Proxy(t,o)}}):l;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]&&(l=Reflect.get(e[0],r)):r in document.body&&(l=Reflect.get(document.body,r)),l?"function"==typeof l?new Proxy(l,{apply:function(e,t,n){let o=null,r=!0;for(const l of t){const t=Reflect.apply(e,l,n);r&&(o=t,r=!1)}return null!=o?o:t}}):l: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]};export{e as $};
|
|
7
7
|
//# sourceMappingURL=bundle.min.js.map
|
package/dist/bundle.min.js.map
CHANGED
|
@@ -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
|
|
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","hasOwnProperty","ret","length","retFirst","first","set","value","deleteProperty"],"mappings":";;;;;AAMgB,SAAAA,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,CAC1DG,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,EAAmB,CAC/DJ,EAAsBG,EACtBF,EAAWG,EAGX,MAAMC,EAAYI,QAAQP,IAAIN,SAASF,KAAMU,GAC7C,OAAO,IAAIN,MAAMO,EAAWN,EAC7B,CAGD,GACEI,aAAkBO,qBAClBP,aAAkBQ,aAOlB,OAHAN,EAAYI,QAAQP,IAAIN,SAASF,KAAKO,GAAWG,GAGzB,mBAAbC,EACF,IAAIP,MAAgBO,EAAW,CACpCO,MAAO,SAAUT,EAAQU,EAASC,GAIhC,OAHAd,EAAoBe,SAASC,IAC3BP,QAAQG,MAAMT,EAAQa,EAAGf,GAAWa,EAAc,IAE7C,IAAIhB,MAAME,EAAqBD,EACvC,IAGIM,EAKX,GAAIY,MAAMC,UAAUC,eAAef,GAAO,CACxC,MAAMC,EAAYI,QAAQP,IAAIe,MAAMC,UAAWd,GAC/C,GAAwB,mBAAbC,EACT,OAAO,IAAIP,MAAgBO,EAAW,CACpCO,MAAO,SAAUT,EAAQU,EAASC,GAChC,MAAMM,EAAMX,QAAQG,MAAMT,EAAQU,EAASC,GAK3C,OAAO,IAAIhB,WADqB,IAAPsB,EAAqBA,EAAMP,EACxBd,EAC7B,GAGN,CAkBD,OAfII,EAAOkB,OAAS,EAGdjB,KAAQD,EAAO,KACjBE,EAAYI,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"}
|
package/dist/carbonium.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbonium",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.4",
|
|
4
|
+
"description": "One kilobyte library for easy DOM manipulation",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"browser": "dist/bundle.iife.min.js",
|
|
7
7
|
"module": "dist/bundle.min.js",
|
|
8
8
|
"types": "dist/carbonium.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"release": "npm i --package-lock && npm run lint && npm test && npm run build && npm publish",
|
|
16
16
|
"test": "karma start karma.conf.cjs",
|
|
17
17
|
"lint": "npx eslint . --ext .js,.ts",
|
|
18
|
-
"prettier": "prettier --config .prettierrc.json src/**/*.
|
|
18
|
+
"prettier": "prettier --config .prettierrc.json src/**/*.ts *.json --write"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
package/src/carbonium.ts
CHANGED
|
@@ -11,7 +11,7 @@ export function $<T extends HTMLElement = HTMLElement>(
|
|
|
11
11
|
let nodelist: NodeListOf<T>;
|
|
12
12
|
|
|
13
13
|
// If the first parameter starts with "<", create a DOM node
|
|
14
|
-
if (selectors
|
|
14
|
+
if (selectors.startsWith("<")) {
|
|
15
15
|
nodelist = <NodeListOf<T>>(
|
|
16
16
|
(<unknown>[
|
|
17
17
|
new DOMParser().parseFromString(selectors, "text/html").body.firstChild,
|
|
@@ -40,8 +40,8 @@ const proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {
|
|
|
40
40
|
// Return iterator when asked for iterator, only used in ES2015+
|
|
41
41
|
if (prop == Symbol.iterator) {
|
|
42
42
|
return function* () {
|
|
43
|
-
for (
|
|
44
|
-
yield
|
|
43
|
+
for (const element of target) {
|
|
44
|
+
yield element;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -127,9 +127,7 @@ const proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {
|
|
|
127
127
|
first = false;
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
return retFirst
|
|
131
|
-
? retFirst
|
|
132
|
-
: thisArg;
|
|
130
|
+
return retFirst ?? thisArg;
|
|
133
131
|
},
|
|
134
132
|
});
|
|
135
133
|
} else {
|