@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 +1 -1
- package/index.d.ts +33 -0
- package/index.min.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[code-eg]: ./example.html "
|
|
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
|
-
|
|
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.
|
|
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": "
|
|
30
|
-
"compress": "
|
|
31
|
-
"build": "npm
|
|
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",
|