@duckafire/html.js 1.0.0 → 1.0.1

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
- [code-eg]: ./example.html "It does not work in NPM Registry"
1
+ [code-eg]: ./example.html "Go to GitHub repository"
2
2
  [aria-attr]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA "Mozilla docs: Accessible Rich Internet Applications"
3
3
  [data-attr]: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/data-* "Mozilla docs: HTML attributes data-*"
4
4
  [event-list]: https://www.w3schools.com/js/js_htmldom_eventlistener.asp "W3 docs: DOM Event Listeners"
package/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ type TChildren = [] | Element[] | [...Array<Element>, Function];
2
+ type TStrDict = Record<string, string>;
3
+ type TEvDict = Record<keyof ElementEventMap, EventListener | EventListener[]>;
4
+ type TSpecDict = TStrDict | TEvDict;
5
+ type TAttrDict = Record<string, string | TSpecDict>;
6
+ type TElemAttr = Record<string, TAttrDict>;
7
+ declare const enum SpecialAttributes {
8
+ ARIA = "_aria",
9
+ DATA = "_data",
10
+ EVENT = "_event",
11
+ STYLE = "_style",
12
+ VAR = "_var"
13
+ }
14
+ declare const __hj_formatAttributeName__: (name: string, prefix?: string) => string;
15
+ declare class HJDefaultAttributes {
16
+ private static __list__;
17
+ static set(list: TElemAttr): void | never;
18
+ static get(tagName: string): TAttrDict;
19
+ static unset(list: Record<string, string[]>): void | never;
20
+ }
21
+ declare abstract class __HJ_AttributesManager__ {
22
+ private __setSpecialAttributes__;
23
+ protected __setAttributes(elem: Element, attributes: TAttrDict): void | never;
24
+ }
25
+ declare class __HJ_InlineElement__ extends __HJ_AttributesManager__ {
26
+ constructor();
27
+ createElement(tagName: string, attributes?: TAttrDict): Element | never;
28
+ }
29
+ declare class __HJ_BlockElement__ extends __HJ_AttributesManager__ {
30
+ constructor();
31
+ private __insertChildren__;
32
+ createElement(tagName: string, attributes?: TAttrDict, ...children: TChildren): Element | never;
33
+ }
package/index.min.js CHANGED
@@ -1 +1 @@
1
- for(var __extends=this&&this.__extends||function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),__spreadArray=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,_=0,o=e.length;_<o;_++)!n&&_ in e||(n||(n=Array.prototype.slice.call(e,0,_)),n[_]=e[_]);return t.concat(n||Array.prototype.slice.call(e))},__hj_formatAttributeName__=function(t,e){if(void 0===e&&(e=null),"-"===t.charAt(0))return t;if(null===e)return t.toLowerCase();for(var r,n=t.charAt(0),_=1;_<t.length;_++)(r=t.charAt(_))===r.toUpperCase()?n+="-"+r.toLowerCase():n+=r;return null!==e?e+n:n},HJDefaultAttributes=function(){function t(){}return t.set=function(t){if(null===t||"object"!=typeof t)throw new TypeError("Expecting: OBJECT.");for(var e in t)for(var r in void 0===this.__list__[e]&&(this.__list__[e]={}),t[e])this.__list__[e][__hj_formatAttributeName__(r)]=t[e][r]},t.get=function(e){var r;return null!==(r=t.__list__[e.toUpperCase()])&&void 0!==r?r:{}},t.unset=function(e){if(null===e||"object"!=typeof e)throw new TypeError("Expecting: OBJECT.");for(var r in e)for(var n=0,_=e[r];n<_.length;n++){var o=_[n];delete t.__list__[r][__hj_formatAttributeName__(o)]}},t.__list__={},t}(),__HJ_AttributesManager__=function(){function t(){}return t.prototype.__setSpecialAttributes__=function(t,e,r){var n,_;if("_"!==e.charAt(0))return!1;switch(e){case"_aria":case"_data":for(var o in _=e.slice(1)+"-",r)t.setAttribute(__hj_formatAttributeName__(o,_),r[o]);break;case"_event":for(var i in r)if(Array.isArray(r[i]))for(var a=0,u=r[i];a<u.length;a++){var l=u[a];t.addEventListener(i,l)}else t.addEventListener(i,r[i]);break;case"_style":case"_var":var c="";for(var o in _="_var"===e?"--":"",r)c+="".concat(__hj_formatAttributeName__(o,_),":").concat(r[o],";");t.setAttribute("style",(null!==(n=t.getAttribute("style"))&&void 0!==n?n:"")+c);break;default:return!1}return!0},t.prototype.__setAttributes=function(t,e){var r=HJDefaultAttributes.get(t.tagName);for(var n in r)t.setAttribute(n,r[n]);for(var n in e)this.__setSpecialAttributes__(t,n,e[n])||t.setAttribute(__hj_formatAttributeName__(n),e[n])},t}(),__HJ_InlineElement__=function(t){function e(){return t.call(this)||this}return __extends(e,t),e.prototype.createElement=function(t,e){void 0===e&&(e={});var r=document.createElement(t);return this.__setAttributes(r,e),r},e}(__HJ_AttributesManager__),__HJ_BlockElement__=function(t){function e(){return t.call(this)||this}return __extends(e,t),e.prototype.__insertChildren__=function(t,e){if(0!==e.length){for(var r="",n=e.length-1,_=0;_<n;_++)"string"!=typeof e[_]?(""!==r&&(t.appendChild(document.createTextNode(r)),r=""),t.appendChild(e[_])):r+=(""===r?"":" ")+e[_];""!==r&&t.appendChild(document.createTextNode(r))}},e.prototype.createElement=function(t,e){void 0===e&&(e={});for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var _=document.createElement(t);return this.__setAttributes(_,e),this.__insertChildren__(_,r),_},e}(__HJ_AttributesManager__),_loop_1=function(t){window[t]=function(e){return __HJ_InlineElement__.prototype.createElement(t,e)}},_i=0,_a=["AREA","BASE","BR","COL","HR","IMG","INPUT","LINK","META","SOURCE","TRACK","WBR"];_i<_a.length;_i++){_loop_1(TAG=_a[_i])}for(var _loop_2=function(t){window[t]=function(e){for(var r,n=[],_=1;_<arguments.length;_++)n[_-1]=arguments[_];return(r=__HJ_BlockElement__.prototype).createElement.apply(r,__spreadArray([t,e],n,!1))}},_b=0,_c=["A","ABBR","ADDRESS","ARTICLE","AUDIO","B","BDI","BDO","BLOCKQUOTE","BODY","BUTTON","CANVAS","CAPTION","CITE","CODE","COLGROUP","DATA","DATALIST","DD","DEL","DETAILS","DFN","DIALOG","DIV","DL","DT","EM","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEAD","HEADER","HGROUP","HTML","I","IFRAME","INS","KBD","LABEL","LEGEND","LI","MAIN","MAP","MARK","METER","NAV","NOSCRIPT","OBJECT","OL","OPTGROUP","OPTION","OUTPUT","P","PICTURE","PRE","PROGRESS","Q","RP","RT","RUBY","SAMP","SCRIPT","SECTION","SELECT","SMALL","SPAN","STRONG","SUB","SUMMARY","SUP","TABLE","TBODY","TD","TEMPLATE","TEXTAREA","TFOOT","TH","THEAD","TIME","TITLE","TR","UL","VARI","VIDEO"];_b<_c.length;_b++){var TAG;_loop_2(TAG=_c[_b])}
1
+ "use strict";const __hj_formatAttributeName__=(t,e=null)=>{if("-"===t.charAt(0))return t;if(null===e)return t.toLowerCase();let r,_=t.charAt(0);for(let e=1;e<t.length;e++)r=t.charAt(e),r===r.toUpperCase()?_+="-"+r.toLowerCase():_+=r;return null!==e?e+_:_};class HJDefaultAttributes{static set(t){if(null===t||"object"!=typeof t)throw new TypeError("Expecting: OBJECT.");for(const e in t){void 0===this.__list__[e]&&(this.__list__[e]={});for(const r in t[e])this.__list__[e][__hj_formatAttributeName__(r)]=t[e][r]}}static get(t){var e;return null!==(e=HJDefaultAttributes.__list__[t.toUpperCase()])&&void 0!==e?e:{}}static unset(t){if(null===t||"object"!=typeof t)throw new TypeError("Expecting: OBJECT.");for(const e in t)for(const r of t[e])delete HJDefaultAttributes.__list__[e][__hj_formatAttributeName__(r)]}}HJDefaultAttributes.__list__={};class __HJ_AttributesManager__{__setSpecialAttributes__(t,e,r){var _;if("_"!==e.charAt(0))return!1;let s;switch(e){case"_aria":case"_data":s=e.slice(1)+"-";for(const e in r)t.setAttribute(__hj_formatAttributeName__(e,s),r[e]);break;case"_event":for(const e in r)if(Array.isArray(r[e]))for(const _ of r[e])t.addEventListener(e,_);else t.addEventListener(e,r[e]);break;case"_style":case"_var":let n="";s="_var"===e?"--":"";for(const t in r)n+=`${__hj_formatAttributeName__(t,s)}:${r[t]};`;t.setAttribute("style",(null!==(_=t.getAttribute("style"))&&void 0!==_?_:"")+n);break;default:return!1}return!0}__setAttributes(t,e){const r=HJDefaultAttributes.get(t.tagName);for(const e in r)t.setAttribute(e,r[e]);for(const r in e)this.__setSpecialAttributes__(t,r,e[r])||t.setAttribute(__hj_formatAttributeName__(r),e[r])}}class __HJ_InlineElement__ extends __HJ_AttributesManager__{constructor(){super()}createElement(t,e={}){const r=document.createElement(t);return this.__setAttributes(r,e),r}}class __HJ_BlockElement__ extends __HJ_AttributesManager__{constructor(){super()}__insertChildren__(t,e){if(0===e.length)return;let r="";const _=e.length-1;for(let s=0;s<_;s++)"string"!=typeof e[s]?(""!==r&&(t.appendChild(document.createTextNode(r)),r=""),t.appendChild(e[s])):r+=(""===r?"":" ")+e[s];""!==r&&t.appendChild(document.createTextNode(r))}createElement(t,e={},...r){const _=document.createElement(t);return this.__setAttributes(_,e),this.__insertChildren__(_,r),_}}for(const t of["AREA","BASE","BR","COL","HR","IMG","INPUT","LINK","META","SOURCE","TRACK","WBR"])window[t]=e=>__HJ_InlineElement__.prototype.createElement(t,e);for(const t of["A","ABBR","ADDRESS","ARTICLE","AUDIO","B","BDI","BDO","BLOCKQUOTE","BODY","BUTTON","CANVAS","CAPTION","CITE","CODE","COLGROUP","DATA","DATALIST","DD","DEL","DETAILS","DFN","DIALOG","DIV","DL","DT","EM","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","H1","H2","H3","H4","H5","H6","HEAD","HEADER","HGROUP","HTML","I","IFRAME","INS","KBD","LABEL","LEGEND","LI","MAIN","MAP","MARK","METER","NAV","NOSCRIPT","OBJECT","OL","OPTGROUP","OPTION","OUTPUT","P","PICTURE","PRE","PROGRESS","Q","RP","RT","RUBY","SAMP","SCRIPT","SECTION","SELECT","SMALL","SPAN","STRONG","SUB","SUMMARY","SUP","TABLE","TBODY","TD","TEMPLATE","TEXTAREA","TFOOT","TH","THEAD","TIME","TITLE","TR","UL","VARI","VIDEO"])window[t]=(e,...r)=>__HJ_BlockElement__.prototype.createElement(t,e,...r);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duckafire/html.js",
3
3
  "author": "duckafire",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "license": "Zlib",
6
6
  "main": "index.min.js",
7
7
  "description": "Just a very simple components library.",
@@ -26,9 +26,10 @@
26
26
  "url": "git+https://github.com/duckafire/html.js.git"
27
27
  },
28
28
  "scripts": {
29
- "compile": "npx tsc",
30
- "compress": "npx terser index.js -o index.min.js --compress --mangle",
31
- "build": "npm run compile && npm run compress"
29
+ "compile": "tsc",
30
+ "compress": "terser index.js -o index.min.js --compress --mangle",
31
+ "build": "npm compile && npm compress",
32
+ "b-build": "bun compile && bun compress"
32
33
  },
33
34
  "files": [
34
35
  "LICENSE",