carbonium 1.0.0 → 1.2.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,10 +1,11 @@
1
- ![test](https://github.com/edwinm/carbonium/workflows/Test/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/edwinm/carbonium/badge.svg?branch=master)](https://coveralls.io/github/edwinm/carbonium?branch=master) [![CodeFactor](https://www.codefactor.io/repository/github/edwinm/carbonium/badge)](https://www.codefactor.io/repository/github/edwinm/carbonium) [![Size](https://img.shields.io/github/size/edwinm/carbonium/dist/bundle.min.js)](https://github.com/edwinm/carbonium/blob/master/dist/bundle.min.js) [![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
+ ![test](https://github.com/edwinm/carbonium/workflows/Test/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/edwinm/carbonium/badge.svg?branch=master)](https://coveralls.io/github/edwinm/carbonium?branch=master) [![CodeFactor](https://www.codefactor.io/repository/github/edwinm/carbonium/badge)](https://www.codefactor.io/repository/github/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)
2
2
 
3
- # carbonium
3
+ [![Carbonium](https://raw.githubusercontent.com/edwinm/carbonium/master/assets/carbonium.svg)](#readme)
4
4
 
5
5
  > One kilobyte library for easy manipulation of the DOM
6
6
 
7
- With carbonium, you can call `$(selector)` and the result can be accessed as both an element and an array of elements.
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
+ DOM element operations are applied to all matched elements.
8
9
 
9
10
  ## Examples
10
11
 
@@ -44,25 +45,45 @@ If you don't want to install or use a bundler like webpack or rollup.js, you can
44
45
 
45
46
  ```javascript
46
47
  const { $ } = await import(
47
- "https://cdn.jsdelivr.net/npm/carbonium/dist/bundle.min.js"
48
+ "https://cdn.jsdelivr.net/npm/carbonium@1/dist/bundle.min.js"
48
49
  );
49
50
  ```
50
51
 
51
52
  ## API
52
53
 
53
- ### `$(selector [, document])`
54
+ ### Select elements
54
55
 
55
- **`selector: string`** - Selector to select elements
56
- **`document: object` (optional)** - Document or element in which to apply the selector
56
+ ### `$(selector [, parentNode])`
57
57
 
58
- ### `$(html [, document])`
58
+ #### Parameters
59
59
 
60
- **`html: string`** - HTML of element to create
61
- **`document: object` (optional)** - Document or element in which to apply the selector
60
+ | Name | Type | Description |
61
+ | ---------- | ------------------------------ | -------------------------------------------------------------------------- |
62
+ | selector | string | Selector to select elements |
63
+ | parentNode | Document \| Element (optional) | Document or element in which to apply the selector, defaults to `document` |
62
64
 
63
- ## Typescript
65
+ #### Returns
64
66
 
65
- Carbonium is written in TypeScript and provides all typings.
67
+ An array of the matched elements, which can also be accessed as a single element.
68
+
69
+ ### Create element
70
+
71
+ ### `$(html [, parentNode])`
72
+
73
+ #### Parameters
74
+
75
+ | Name | Type | Description |
76
+ | ---------- | ------------------------------ | -------------------------------------------------------------------------- |
77
+ | html | string | HTML of element to create, starting with "<" |
78
+ | parentNode | Document \| Element (optional) | Document or element in which to apply the selector, defaults to `document` |
79
+
80
+ #### Returns
81
+
82
+ An array with one created element.
83
+
84
+ ## TypeScript
85
+
86
+ If you use TypeScript, it's good to know Carbonium is written in TypeScript and provides all typings.
66
87
  You can use generics to declare a specific type of element,
67
88
  for example `HTMLInputElement` to make the `disabled` property available:
68
89
 
@@ -72,12 +93,11 @@ $<HTMLInputElement>("input, select, button").disabled = true;
72
93
 
73
94
  ## Why?
74
95
 
75
- Most frameworks are quite bulky and are bad for performance, both when loading a site and when doing DOM operations ([1](https://css-tricks.com/radeventlistener-a-tale-of-client-side-framework-performance/)).
76
-
77
- On the other side, using native DOM and writing `document.querySelectorAll(selector)` each time you want to do some DOM operations will become tedious.
96
+ You might find most frameworks are quite bulky and bad for performance ([1](https://css-tricks.com/radeventlistener-a-tale-of-client-side-framework-performance/)).
97
+ On the other side, you might find using native DOM and writing `document.querySelectorAll(selector)` each time you want to do some DOM operations to become tedious.
78
98
  You can write your own helper function, but that only takes part of the pain away.
79
99
 
80
- Carbonium seeks to find the sweet spot between using frameworks and using the native DOM.
100
+ Carbonium seeks to find the sweet spot between using a framework and using the native DOM.
81
101
 
82
102
  ## jQuery
83
103
 
@@ -86,13 +106,23 @@ Isn't this just jQuery and isn't that obsolete and bad practice?
86
106
  No. Carbonium doesn't have the disadvantages of jQuery:
87
107
 
88
108
  1. Carbonium is very small: just around one kilobyte.
89
- 2. There's no new API to learn, carbonium only provides standard DOM API's.
109
+ 2. There's no new API to learn, carbonium provides only standard DOM API's.
110
+
111
+ ## Browser support
112
+
113
+ Carbonium is supported by all modern browsers. It is tested to work on desktop and mobile with Firefox 79, Chrome 84, Safari 13 and Edge 84.
114
+ It should work with all browsers supporting Proxy, see [Can I use Proxy](https://caniuse.com/#feat=proxy) for support tables.
90
115
 
91
116
  ## Name
92
117
 
118
+ [<img src="https://raw.githubusercontent.com/edwinm/carbonium/master/assets/Diamond_and_graphite.jpg" align="right"
119
+ alt="Photo of diamond and graphite" width="178" height="120">](https://commons.wikimedia.org/wiki/File:Diamond_and_graphite_without_structures.jpg)
120
+
93
121
  Carbonium is the Latin name for carbon. Carbon has two forms (allotropes): graphite and diamond.
94
- Just like this library, in which the result presents itself both as one element and a list of elements.
122
+ Just like this library, in which the result presents itself both as one element and as a list of elements.
123
+
124
+ [Photo CC BY-SA 3.0](https://commons.wikimedia.org/wiki/File:Diamond_and_graphite_without_structures.jpg)
95
125
 
96
126
  ## License
97
127
 
98
- Copyright 2020 [Edwin Martin](https://bitstorm.org/) and released with MIT license.
128
+ Copyright 2020 [Edwin Martin](https://bitstorm.org/) and released under the MIT license.
@@ -1,7 +1,7 @@
1
1
  var carbonium=function(e){"use strict";
2
2
  /**
3
- Carbonium 1.0.0
3
+ Carbonium 1.2.0
4
4
  @copyright 2020 Edwin Martin
5
5
  @license MIT
6
- */let t,n;const o={get(e,r){let l=null;if(r==Symbol.iterator)return function*(){for(let t=0;t<e.length;t++)yield e[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&&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)};return e.$=function(e,t){let n;return n="<"==e[0]?[(new DOMParser).parseFromString(e,"text/html").body.firstChild]:(t||document).querySelectorAll(e),new Proxy(n,o)},e}({});
6
+ */let t,n;const o={get(e,r){let l=null;if(r==Symbol.iterator)return function*(){for(let t=0;t<e.length;t++)yield e[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&&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]};return e.$=function(e,t){let n;return n="<"==e[0]?[(new DOMParser).parseFromString(e,"text/html").body.firstChild]:(t||document).querySelectorAll(e),new Proxy(n,o)},Object.defineProperty(e,"__esModule",{value:!0}),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[0] == \"<\") {\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 (let i = 0; i < target.length; i++) {\n yield target[i];\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 != null && retFirst != undefined\n ? retFirst\n : 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\nexport type CarboniumType<T extends HTMLElement = HTMLElement> = CarboniumList<\n T\n> &\n 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): CarboniumType<T>;\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","[object Object]","target","prop","propValue","Symbol","iterator","i","length","Reflect","get","document","body","Proxy","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","retFirst","first","undefined","set","value","selectors","parentNode","nodelist","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,IAAIC,EAAI,EAAGA,EAAIL,EAAOM,OAAQD,UAC3BL,EAAOK,IAMnB,GAAY,SAARJ,GAA2B,aAARA,GAA+B,WAARA,EAAmB,CAC/DL,EAAsBI,EACtBH,EAAWI,EAGX,MAAMC,EAAYK,QAAQC,IAAIC,SAASC,KAAMT,GAC7C,OAAO,IAAIU,MAAMT,EAAWJ,GAI9B,GACEE,aAAkBY,qBAClBZ,aAAkBa,aAOlB,OAHAX,EAAYK,QAAQC,IAAIC,SAASC,KAAKb,GAAWI,GAGzB,mBAAbC,EACF,IAAIS,MAAgBT,EAAW,CACpCY,MAAO,SAAUd,EAAQe,EAASC,GAIhC,OAHApB,EAAoBqB,QAASC,IAC3BX,QAAQO,MAAMd,EAAQkB,EAAGrB,GAAWmB,KAE/B,IAAIL,MAAMf,EAAqBE,MAInCI,EAKX,GAAIiB,MAAMC,UAAUC,eAAepB,GAAO,CACxC,MAAMC,EAAYK,QAAQC,IAAIW,MAAMC,UAAWnB,GAC/C,GAAwB,mBAAbC,EACT,OAAO,IAAIS,MAAgBT,EAAW,CACpCY,MAAO,SAAUd,EAAQe,EAASC,GAChC,MAAMM,EAAMf,QAAQO,MAAMd,EAAQe,EAASC,GAK3C,OAAO,IAAIL,WADqB,IAAPW,EAAqBA,EAAMP,EACxBjB,MAsBpC,OAfIE,EAAOM,OAAS,EAGdL,KAAQD,EAAO,KACjBE,EAAYK,QAAQC,IAAIR,EAAO,GAAIC,IAKjCA,KAAQQ,SAASC,OACnBR,EAAYK,QAAQC,IAAIC,SAASC,KAAMT,IAKvCC,EACsB,mBAAbA,EACF,IAAIS,MAAgBT,EAAW,CACpCY,MAAO,SAAUd,EAAQe,EAASC,GAChC,IAAIO,EAAW,KACXC,GAAQ,EAEZ,IAAK,MAAMN,KAAMH,EAAS,CACxB,MAAMO,EAAMf,QAAQO,MAAMd,EAAQkB,EAAIF,GAClCQ,IACFD,EAAWD,EACXE,GAAQ,GAGZ,OAAmB,MAAZD,GAAgCE,MAAZF,EACvBA,EACAR,KAIDb,EAKJK,QAAQC,IAAIR,EAAQC,IAI7ByB,IAAG,CAAC1B,EAAQC,EAAM0B,OACZ,YAAa3B,IAAYA,aAAkBY,oBAK7CL,QAAQmB,IAAI1B,EAAQC,EAAM0B,GAJ1B3B,EAAOiB,QAASC,IACdX,QAAQmB,IAAIR,EAAIjB,EAAM0B,MAKnB,wBAjJTC,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADkB,KAAhBF,EAAU,GAEA,EACR,IAAIG,WAAYC,gBAAgBJ,EAAW,aAAalB,KAAKuB,aAKrDJ,GAAcpB,UAAUyB,iBAAiBN,GAK3C,IAAIjB,MAAqBmB,EAAUhC"}
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[0] == \"<\") {\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 (let i = 0; i < target.length; i++) {\n yield target[i];\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 != null && retFirst != undefined\n ? retFirst\n : 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","i","length","Reflect","document","body","Proxy","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","retFirst","first","undefined","set","value","deleteProperty","selectors","parentNode","nodelist","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,IAAIC,EAAI,EAAGA,EAAIL,EAAOM,OAAQD,UAC3BL,EAAOK,IAMnB,GAAY,SAARJ,GAA2B,aAARA,GAA+B,WAARA,EAAmB,CAC/DL,EAAsBI,EACtBH,EAAWI,EAGX,MAAMC,EAAYK,QAAQR,IAAIS,SAASC,KAAMR,GAC7C,OAAO,IAAIS,MA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AIhB,EAAMyB,OAKnB,GAGTC,eAAc,CAAC3B,EAAQC,IACjBA,KAAQD,UACIA,EAAOC,wBAtJzB2B,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADkB,KAAhBF,EAAU,GAEA,EACR,IAAIG,WAAYC,gBAAgBJ,EAAW,aAAanB,KAAKwB,aAKrDJ,GAAcrB,UAAU0B,iBAAiBN,GAK3C,IAAIlB,MAAqBoB,EAAUhC"}
@@ -1,7 +1,7 @@
1
1
  /**
2
- Carbonium 1.0.0
2
+ Carbonium 1.2.0
3
3
  @copyright 2020 Edwin Martin
4
4
  @license MIT
5
5
  */
6
- function e(e,t){let n;return n="<"==e[0]?[(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(let t=0;t<e.length;t++)yield e[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&&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)};export{e as $};
6
+ function e(e,t){let n;return n="<"==e[0]?[(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(let t=0;t<e.length;t++)yield e[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&&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
@@ -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[0] == \"<\") {\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 (let i = 0; i < target.length; i++) {\n yield target[i];\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 != null && retFirst != undefined\n ? retFirst\n : 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\nexport type CarboniumType<T extends HTMLElement = HTMLElement> = CarboniumList<\n T\n> &\n 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): CarboniumType<T>;\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","DOMParser","parseFromString","body","firstChild","document","querySelectorAll","Proxy","proxyHandler","currentListNodelist","propList","[object Object]","target","prop","propValue","Symbol","iterator","i","length","Reflect","get","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","retFirst","first","undefined","set","value"],"mappings":";;;;;SAMgBA,EACdC,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADkB,KAAhBF,EAAU,GAEA,EACR,IAAIG,WAAYC,gBAAgBJ,EAAW,aAAaK,KAAKC,aAKrDL,GAAcM,UAAUC,iBAAiBR,GAK3C,IAAIS,MAAqBP,EAAUQ,GAMjD,IAAIC,EACAC,EAEJ,MAAMF,EAAsD,CAC1DG,IAAIC,EAAQC,GACV,IAAIC,EAAY,KAGhB,GAAID,GAAQE,OAAOC,SACjB,OAAO,YACL,IAAK,IAAIC,EAAI,EAAGA,EAAIL,EAAOM,OAAQD,UAC3BL,EAAOK,IAMnB,GAAY,SAARJ,GAA2B,aAARA,GAA+B,WAARA,EAAmB,CAC/DJ,EAAsBG,EACtBF,EAAWG,EAGX,MAAMC,EAAYK,QAAQC,IAAIf,SAASF,KAAMU,GAC7C,OAAO,IAAIN,MAAMO,EAAWN,GAI9B,GACEI,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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[0] == \"<\") {\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 (let i = 0; i < target.length; i++) {\n yield target[i];\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 != null && retFirst != undefined\n ? retFirst\n : 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","DOMParser","parseFromString","body","firstChild","document","querySelectorAll","Proxy","proxyHandler","currentListNodelist","propList","get","target","prop","propValue","Symbol","iterator","i","length","Reflect","CSSStyleDeclaration","DOMTokenList","apply","thisArg","argumentsList","forEach","el","Array","prototype","hasOwnProperty","ret","retFirst","first","undefined","set","value","deleteProperty"],"mappings":";;;;;SAMgBA,EACdC,EACAC,GAEA,IAAIC,EAeJ,OAXEA,EADkB,KAAhBF,EAAU,GAEA,EACR,IAAIG,WAAYC,gBAAgBJ,EAAW,aAAaK,KAAKC,aAKrDL,GAAcM,UAAUC,iBAAiBR,GAK3C,IAAIS,MAAqBP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AMN,KAAMH,EAAS,CACxB,MAAMO,EAAMX,QAAQG,MAAMV,EAAQc,EAAIF,GAClCQ,IACFD,EAAWD,EACXE,GAAQ,GAGZ,OAAmB,MAAZD,GAAgCE,MAAZF,EACvBA,EACAR,KAIDT,EAKJK,QAAQR,IAAIC,EAAQC,IAI7BqB,IAAG,CAACtB,EAAQC,EAAMsB,OACZ,YAAavB,IAAYA,aAAkBQ,oBAK7CD,QAAQe,IAAItB,EAAQC,EAAMsB,GAJ1BvB,EAAOa,SAASC,IACdP,QAAQe,IAAIR,EAAIb,EAAMsB,OAKnB,GAGTC,eAAc,CAACxB,EAAQC,IACjBA,KAAQD,UACIA,EAAOC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- Carbonium 1.0.0
2
+ Carbonium 1.2.0
3
3
  @copyright 2020 Edwin Martin
4
4
  @license MIT
5
5
  */
@@ -21,7 +21,7 @@ interface CarboniumList<T extends HTMLElement> extends Array<T> {
21
21
  interface CarboniumClassList<T extends HTMLElement> extends DOMTokenList {
22
22
  add(...tokens: string[]): CarboniumType<T>;
23
23
  remove(...tokens: string[]): CarboniumType<T>;
24
- replace(oldToken: string, newToken: string): CarboniumType<T>;
24
+ replace(oldToken: string, newToken: string): boolean;
25
25
  forEach(callbackfn: (value: string, key: number, parent: DOMTokenList) => void, thisArg?: any): CarboniumType<T>;
26
26
  }
27
27
  interface CarboniumStyleList<T extends HTMLElement> extends CSSStyleDeclaration {
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "carbonium",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Carbonium, for easy manipulation of the DOM",
5
5
  "main": "dist/bundle.iife.min.js",
6
6
  "module": "dist/bundle.min.js",
7
7
  "types": "dist/carbonium.d.ts",
8
8
  "sideEffects": false,
9
9
  "scripts": {
10
+ "prepare": "husky install",
10
11
  "start": "http-server -o demo/ --silent",
11
12
  "build": "rollup --config --sourcemap",
12
13
  "dev": "rollup --config --sourcemap --watch",
13
14
  "release": "npm i --package-lock && npm run lint && npm test && npm run build && npm publish",
14
15
  "test": "karma start",
15
- "lint": "npx eslint . --ext .js,.ts"
16
+ "lint": "npx eslint . --ext .js,.ts",
17
+ "prettier": "prettier --config .prettierrc.json src/**/*.{js,ts} --write"
16
18
  },
17
19
  "repository": {
18
20
  "type": "git",
@@ -29,6 +31,7 @@
29
31
  "keywords": [
30
32
  "dom",
31
33
  "qsa",
34
+ "jquery",
32
35
  "typescript",
33
36
  "front-end",
34
37
  "lightweight",
@@ -44,37 +47,31 @@
44
47
  "url": "https://github.com/edwinm/carbonium/issues"
45
48
  },
46
49
  "homepage": "https://github.com/edwinm/carbonium#readme",
47
- "dependencies": {},
48
50
  "devDependencies": {
49
- "@rollup/plugin-replace": "^2.3.3",
50
- "@types/mocha": "^8.0.3",
51
- "@types/node": "^14.6.0",
52
- "@typescript-eslint/eslint-plugin": "^3.10.1",
53
- "@typescript-eslint/parser": "^3.10.1",
51
+ "@rollup/plugin-replace": "^3.0.0",
52
+ "@types/mocha": "^9.0.0",
53
+ "@types/node": "^17.0.1",
54
+ "@typescript-eslint/eslint-plugin": "^5.7.0",
55
+ "@typescript-eslint/parser": "^5.7.0",
54
56
  "@webcomponents/webcomponentsjs": "^2.4.4",
55
- "eslint": "^7.7.0",
56
- "eslint-config-prettier": "^6.11.0",
57
- "http-server": "^0.12.3",
58
- "husky": "^4.2.5",
59
- "karma": "^5.1.1",
57
+ "eslint": "^8.5.0",
58
+ "eslint-config-prettier": "^8.3.0",
59
+ "http-server": "^14.0.0",
60
+ "husky": "^7.0.4",
61
+ "karma": "^6.3.9",
60
62
  "karma-chai": "^0.1.0",
61
63
  "karma-chrome-launcher": "^3.1.0",
62
64
  "karma-coverage": "^2.0.3",
63
- "karma-firefox-launcher": "^1.3.0",
65
+ "karma-firefox-launcher": "^2.1.0",
64
66
  "karma-mocha": "^2.0.1",
65
67
  "karma-typescript": "^5.1.0",
66
- "mocha": "^8.1.2",
68
+ "mocha": "^9.1.3",
67
69
  "prettier": "^2.1.1",
68
70
  "pretty-quick": "^3.0.0",
69
71
  "rollup": "^2.26.6",
70
72
  "rollup-plugin-terser": "^7.0.0",
71
- "rollup-plugin-typescript2": "^0.27.2",
73
+ "rollup-plugin-typescript2": "^0.31.1",
72
74
  "tslib": "^2.0.1",
73
- "typescript": "^4.0.2"
74
- },
75
- "husky": {
76
- "hooks": {
77
- "pre-commit": "pretty-quick --staged"
78
- }
75
+ "typescript": "^4.1.3"
79
76
  }
80
77
  }
package/src/carbonium.ts CHANGED
@@ -152,12 +152,17 @@ const proxyHandler: ProxyHandler<NodeListOf<HTMLElement>> = {
152
152
  }
153
153
  return true;
154
154
  },
155
+
156
+ deleteProperty(target, prop) {
157
+ if (prop in target) {
158
+ return delete target[prop];
159
+ }
160
+ return false;
161
+ },
155
162
  };
156
163
 
157
- export type CarboniumType<T extends HTMLElement = HTMLElement> = CarboniumList<
158
- T
159
- > &
160
- T;
164
+ export type CarboniumType<T extends HTMLElement = HTMLElement> =
165
+ CarboniumList<T> & T;
161
166
 
162
167
  // Interface definitions
163
168
 
@@ -196,7 +201,7 @@ interface CarboniumClassList<T extends HTMLElement> extends DOMTokenList {
196
201
 
197
202
  remove(...tokens: string[]): CarboniumType<T>;
198
203
 
199
- replace(oldToken: string, newToken: string): CarboniumType<T>;
204
+ replace(oldToken: string, newToken: string): boolean;
200
205
 
201
206
  forEach(
202
207
  callbackfn: (value: string, key: number, parent: DOMTokenList) => void,