mi-element 0.9.7 → 0.9.8
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/dist/bundle.js +28 -2
- package/dist/bundle.min.js +2 -2
- package/dist/element.js +27 -1
- package/package.json +3 -3
- package/src/element.js +36 -1
package/dist/bundle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* SPDX-License-Identifier: MIT
|
|
3
|
-
* mi-element v0.9.
|
|
3
|
+
* mi-element v0.9.8
|
|
4
4
|
*/
|
|
5
5
|
const context = [];
|
|
6
6
|
|
|
@@ -183,7 +183,33 @@ const toJson = any => {
|
|
|
183
183
|
}
|
|
184
184
|
}, nameMap = {
|
|
185
185
|
class: 'className',
|
|
186
|
-
for: 'htmlFor'
|
|
186
|
+
for: 'htmlFor',
|
|
187
|
+
maxlength: 'maxLength',
|
|
188
|
+
minlength: 'minLength',
|
|
189
|
+
readonly: 'readOnly',
|
|
190
|
+
colorspace: 'colorSpace',
|
|
191
|
+
tabindex: 'tabIndex',
|
|
192
|
+
accesskey: 'accessKey',
|
|
193
|
+
rowspan: 'rowSpan',
|
|
194
|
+
colspan: 'colSpan',
|
|
195
|
+
cellpadding: 'cellPadding',
|
|
196
|
+
cellspacing: 'cellSpacing',
|
|
197
|
+
contenteditable: 'contentEditable',
|
|
198
|
+
crossorigin: 'crossOrigin',
|
|
199
|
+
referrerpolicy: 'referrerPolicy',
|
|
200
|
+
usemap: 'useMap',
|
|
201
|
+
ismap: 'isMap',
|
|
202
|
+
enctype: 'encType',
|
|
203
|
+
formaction: 'formAction',
|
|
204
|
+
formenctype: 'formEncType',
|
|
205
|
+
formmethod: 'formMethod',
|
|
206
|
+
formnovalidate: 'formNoValidate',
|
|
207
|
+
formtarget: 'formTarget',
|
|
208
|
+
novalidate: 'noValidate',
|
|
209
|
+
inputmode: 'inputMode',
|
|
210
|
+
datetime: 'dateTime',
|
|
211
|
+
frameborder: 'frameBorder',
|
|
212
|
+
bgcolor: 'bgColor'
|
|
187
213
|
};
|
|
188
214
|
|
|
189
215
|
class MiElement extends HTMLElement {
|
package/dist/bundle.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* SPDX-License-Identifier: MIT
|
|
3
|
-
* mi-element v0.9.
|
|
3
|
+
* mi-element v0.9.8
|
|
4
4
|
*/
|
|
5
|
-
const t=[];class e extends EventTarget{#t;#e;constructor(t,e){super();const{equals:s}=e||{};this.#t=t,this.#e=s??((t,e)=>t===e)}get value(){return this.get()}set value(t){this.set(t)}get(){const e=t[t.length-1];return e&&e.add(this),this.#t}set(t){this.#e(this.#t,t)||(this.#t=t,this.dispatchEvent(new CustomEvent("signal")))}}const s=(t,s)=>t instanceof e?t:new e(t,s);function n(e){const s=new Set;t.push(s);try{e()}finally{t.pop()}for(const t of s)t.addEventListener("signal",e);return()=>{for(const t of s)t.removeEventListener("signal",e)}}var r={State:e,Computed:class{#s;#n;constructor(t){this.#s=new e,this.#n=n(()=>this.#s.set(t()))}get(){return this.#s.get()}unsubscribe(){this.#n()}},createSignal:s,effect:n};const o="context-request";class i{constructor(t,e,n){this.host=t,this.context=e,this.state=s(n),this.host.addController?.(this)}hostConnected(){this.host.addEventListener(o,this.onContextRequest)}hostDisconnected(){this.host.removeEventListener(o,this.onContextRequest)}set(t){this.state.set(t)}get(){return this.state.get()}set value(t){this.set(t)}get value(){return this.get()}onContextRequest=t=>{if(t.context!==this.context)return;let e;t.stopPropagation(),t.subscribe&&(e=n(()=>{const s=this.get();e&&t.callback(s,e)})),t.callback(this.get(),e)}}class c extends Event{constructor(t,e,s){super(o,{bubbles:!0,composed:!0}),this.context=t,this.callback=e,this.subscribe=s}}class a{#t;constructor(t,e,s){const{subscribe:n=!1,validate:r=()=>!0}=s||{};this.host=t,this.context=e,this.subscribe=!!n,this.validate=r,this.unsubscribe=void 0,this.host.addController?.(this)}get(){return this.#t}get value(){return this.#t}hostConnected(){this.dispatchRequest()}hostDisconnected(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=void 0)}dispatchRequest(){this.host.dispatchEvent(new c(this.context,this._callback.bind(this),this.subscribe))}_callback(t,e){e&&(this.subscribe?this.unsubscribe&&(this.unsubscribe!==e&&this.unsubscribe(),this.unsubscribe=e):e()),this.validate(t)&&(this.#t=t,this.host.requestUpdate(t))}}const
|
|
5
|
+
const t=[];class e extends EventTarget{#t;#e;constructor(t,e){super();const{equals:s}=e||{};this.#t=t,this.#e=s??((t,e)=>t===e)}get value(){return this.get()}set value(t){this.set(t)}get(){const e=t[t.length-1];return e&&e.add(this),this.#t}set(t){this.#e(this.#t,t)||(this.#t=t,this.dispatchEvent(new CustomEvent("signal")))}}const s=(t,s)=>t instanceof e?t:new e(t,s);function n(e){const s=new Set;t.push(s);try{e()}finally{t.pop()}for(const t of s)t.addEventListener("signal",e);return()=>{for(const t of s)t.removeEventListener("signal",e)}}var r={State:e,Computed:class{#s;#n;constructor(t){this.#s=new e,this.#n=n(()=>this.#s.set(t()))}get(){return this.#s.get()}unsubscribe(){this.#n()}},createSignal:s,effect:n};const o="context-request";class i{constructor(t,e,n){this.host=t,this.context=e,this.state=s(n),this.host.addController?.(this)}hostConnected(){this.host.addEventListener(o,this.onContextRequest)}hostDisconnected(){this.host.removeEventListener(o,this.onContextRequest)}set(t){this.state.set(t)}get(){return this.state.get()}set value(t){this.set(t)}get value(){return this.get()}onContextRequest=t=>{if(t.context!==this.context)return;let e;t.stopPropagation(),t.subscribe&&(e=n(()=>{const s=this.get();e&&t.callback(s,e)})),t.callback(this.get(),e)}}class c extends Event{constructor(t,e,s){super(o,{bubbles:!0,composed:!0}),this.context=t,this.callback=e,this.subscribe=s}}class a{#t;constructor(t,e,s){const{subscribe:n=!1,validate:r=()=>!0}=s||{};this.host=t,this.context=e,this.subscribe=!!n,this.validate=r,this.unsubscribe=void 0,this.host.addController?.(this)}get(){return this.#t}get value(){return this.#t}hostConnected(){this.dispatchRequest()}hostDisconnected(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=void 0)}dispatchRequest(){this.host.dispatchEvent(new c(this.context,this._callback.bind(this),this.subscribe))}_callback(t,e){e&&(this.subscribe?this.unsubscribe&&(this.unsubscribe!==e&&this.unsubscribe(),this.unsubscribe=e):e()),this.validate(t)&&(this.#t=t,this.host.requestUpdate(t))}}const l=(t="")=>t.replace(/([A-Z])/g,(t,e)=>`-${e.toLowerCase()}`),h=(t="")=>t.toLowerCase().replace(/[-_]\w/g,t=>t[1].toUpperCase()),u=(...t)=>{const e=[];return t.forEach(t=>{t&&("string"==typeof t?e.push(t):"object"==typeof t&&Object.entries(t).forEach(([t,s])=>{s&&e.push(t)}))}),e.join(" ")},d=(t,e)=>{const{unit:s="px"}=e||{},n=[];for(const[e,r]of Object.entries(t??{})){if(null==r)continue;const t=Number.isFinite(r)?s:"";n.push(`${l(e)}:${r}${t}`)}return n.join(";")};let p=null;function f(t){t.adoptedStyleSheets.push(...(null===p&&(p=Array.from(document.styleSheets).map(({cssRules:t})=>{const e=new CSSStyleSheet,s=Array.from(t).map(t=>t.cssText).join(" ");return e.replaceSync(s),e})),p))}class b extends String{}const m=t=>new b(t),g={"&":"\\26 ","<":"\\3c ",">":"\\3e "},v=t=>t instanceof b?t:m((t=>t.replace(/[&<>]/g,t=>g[t]))(""+t)),y=(t,...e)=>String.raw({raw:t},...e.map(v));function w(t,e){const s={};for(const[n,r]of Object.entries(e))s[n]=t.querySelector?.(r);return s}const E=t=>{try{return JSON.parse(t)}catch{return}},S={class:"className",for:"htmlFor",maxlength:"maxLength",minlength:"minLength",readonly:"readOnly",colorspace:"colorSpace",tabindex:"tabIndex",accesskey:"accessKey",rowspan:"rowSpan",colspan:"colSpan",cellpadding:"cellPadding",cellspacing:"cellSpacing",contenteditable:"contentEditable",crossorigin:"crossOrigin",referrerpolicy:"referrerPolicy",usemap:"useMap",ismap:"isMap",enctype:"encType",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",novalidate:"noValidate",inputmode:"inputMode",datetime:"dateTime",frameborder:"frameBorder",bgcolor:"bgColor"};class x extends HTMLElement{_props={};#r={};#o=new Set;#i=new Set;#c=!1;static get shadowRootInit(){return{mode:"open"}}static template;static get properties(){}static observedAttributes=[];static styles="";static get useGlobalStyles(){return!1}static createSignal=s;constructor(){super();const{createSignal:t,properties:e}=this.constructor;for(const[s,{initial:n}]of Object.entries(e)){const e=Object.getOwnPropertyDescriptor(this.constructor.prototype,s);t&&(this._props[s]=t()),Object.defineProperty(this,s,{get(){return e?.get?e.get.call(this):t?this._props[s].value:this._props[s]},set(n){const r=this[s];e?.set?e.set.call(this,n):t?this._props[s].value=n:this._props[s]=n,r!==this[s]&&this.requestUpdate({[s]:n})}}),this[s]=n}}connectedCallback(){const{shadowRootInit:t,useGlobalStyles:e,template:s}=this.constructor;this.#i.forEach(t=>t.hostConnected?.()),this.renderRoot=t?this.shadowRoot??this.attachShadow(t):this,this.addTemplate(s),e&&f(this.renderRoot),this.render(),this.requestUpdate()}disconnectedCallback(){this.#o.forEach(t=>t()),this.#i.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,s){const n=S[t]??h(t),r=this.constructor?.properties,{type:o}=r?.[n]??{},i=A(s,o);if(t.startsWith("data-")){const e=h(t.substring(5));e&&(this.dataset[e]=i)}this[n]=i}requestUpdate(t){this.#r={...this.#r,...t},!this.#c&&this.renderRoot&&(this.#c=!0,window.requestAnimationFrame(()=>{this.#c=!1;const t=this.#r;this.#r={},this.update(t)}))}addTemplate(t){if(t){if(!(t instanceof HTMLTemplateElement))throw new Error("template is not a HTMLTemplateElement");this.renderRoot.append(t.content.cloneNode(!0))}}render(){}update(t){}on(t,e,s=this){s.addEventListener(t,e),this.#o.add(()=>s.removeEventListener(t,e))}once(t,e,s=this){s.addEventListener(t,e,{once:!0})}dispose(...t){for(const e of t){if("function"!=typeof e)throw new TypeError("listener must be a function");this.#o.add(e)}}addController(t){this.#i.add(t),this.isConnected&&t.hostConnected?.()}removeController(t){this.#i.delete(t)}refsBySelector(t){return w(this.renderRoot,t)}}const C=(t,e,s)=>{if(customElements.get(t))return;const{usedCssPrefix:n="",cssPrefix:r="",styles:o}=s||{};if(e.properties){const t=[];for(const[s,{attribute:n=!0}]of Object.entries(e.properties))n&&t.push(l(s));Object.defineProperty(e,"observedAttributes",{get:()=>t})}else if(e.observedAttributes){const t=e.observedAttributes.reduce((t,e)=>(t[h(e)]={},t),{});Object.defineProperty(e,"properties",{get:()=>t})}e.styles&&(e.styles=o||(n===r?e.styles:e.styles.replaceAll(`--${n}-`,r))),q(e),window.customElements.define(t,e)},q=t=>{if(!t.template||t.template instanceof HTMLTemplateElement)return;const e=document.createElement("template");e.innerHTML=t.template||"",t.template=e},A=(t,e)=>e===Boolean?null!==t:e===Number?(t=>{const e=Number(t);return isNaN(e)?0:e})(t):e===Array?E(t)??t.split(",").map(t=>t.trim()):e===Object?E(t):t,L=new class{cnt=0;cache=new Map;last=0;get size(){return this.cache.size}_inc(){return this.cnt=268435455&++this.cnt,this.cnt}clear(){this.cnt=0,this.cache.clear()}set(t){const e=Date.now();this.last<e&&this.cache.clear(),this.last=e+5e3;const s="__rc:"+this._inc().toString(36);return this.cache.set(s,t),s}get(t){const e=this.cache.get(t);return this.cache.delete(t),e}};class T extends String{}const j=t=>new T(t),R={"&":"&","<":"<",">":">",'"':""","'":"'"},O=/[&<>"']/g,P=t=>t.replace(O,t=>R[t]),_=t=>t instanceof T?t:j(P(""+t)),N="object",M="function",k=t=>{if(t instanceof T)return t;const e=typeof t;if(e===N||e===M){const e=L.set(t);return j(e)}return j(P(""+(t??"")))},D=(t,...e)=>j(String.raw({raw:t},...e.map(t=>Array.isArray(t)?t.map(k).join(""):k(t))));function H(t,e,s={}){const n={};t.innerHTML=e.toString();for(let e=0,r=t.children.length;e<r;e++)B(t.children[e],s,n);return n}const U="ref",$="[ref]";function B(t,e={},s={}){if(t.nodeType===Node.ELEMENT_NODE){const n=[],r=t.attributes;for(let o=0,i=r.length;o<i;o++){const i=r[o],c=i.name,a=c.charCodeAt(0),l=c.slice(1);let h=0;if(63===a)E(i.value)?t.setAttribute(l,""):t.removeAttribute(l),h=1;else if("..."===i.name){const e=L.get(i.value);if(e&&typeof e===N)for(const[s,n]of Object.entries(e))t[s]=n;h=1}else if(46===a)t[l]=L.get(i.value)??i.value,h=1;else if(64===a){const s=i.value,n=L.get(s);n?t.addEventListener(l,n):typeof e[s]===M&&t.addEventListener(l,e[s]),h=1}else i.name===U&&(s[i.value]=t,h=1);h&&n.push(i.name)}for(let e=0,s=n.length;e<s;e++)t.removeAttribute(n[e])}if(customElements.get(t.localName)){const e=t.querySelectorAll($);for(let t of e){const e=t.getAttribute(U);e&&!s[e]&&(s[e]=t)}return s}if(!t.children?.length)return s;for(let n of Array.from(t.children))B(n,e,s);return s}class F extends e{constructor(t,e,s){super(e,s);for(const[e,s]of Object.entries(t))this[e]=t=>this.set(s(t)(this.get()))}}export{a as ContextConsumer,i as ContextProvider,c as ContextRequestEvent,x as MiElement,r as Signal,F as Store,f as addGlobalStyles,u as classNames,A as convertType,y as css,C as define,v as escCss,_ as escHtml,D as html,w as refsBySelector,H as render,B as renderAttrs,d as styleMap,m as unsafeCss,j as unsafeHtml};
|
package/dist/element.js
CHANGED
|
@@ -10,7 +10,33 @@ import { toNumber, toJson } from './utils.js';
|
|
|
10
10
|
|
|
11
11
|
const nameMap = {
|
|
12
12
|
class: 'className',
|
|
13
|
-
for: 'htmlFor'
|
|
13
|
+
for: 'htmlFor',
|
|
14
|
+
maxlength: 'maxLength',
|
|
15
|
+
minlength: 'minLength',
|
|
16
|
+
readonly: 'readOnly',
|
|
17
|
+
colorspace: 'colorSpace',
|
|
18
|
+
tabindex: 'tabIndex',
|
|
19
|
+
accesskey: 'accessKey',
|
|
20
|
+
rowspan: 'rowSpan',
|
|
21
|
+
colspan: 'colSpan',
|
|
22
|
+
cellpadding: 'cellPadding',
|
|
23
|
+
cellspacing: 'cellSpacing',
|
|
24
|
+
contenteditable: 'contentEditable',
|
|
25
|
+
crossorigin: 'crossOrigin',
|
|
26
|
+
referrerpolicy: 'referrerPolicy',
|
|
27
|
+
usemap: 'useMap',
|
|
28
|
+
ismap: 'isMap',
|
|
29
|
+
enctype: 'encType',
|
|
30
|
+
formaction: 'formAction',
|
|
31
|
+
formenctype: 'formEncType',
|
|
32
|
+
formmethod: 'formMethod',
|
|
33
|
+
formnovalidate: 'formNoValidate',
|
|
34
|
+
formtarget: 'formTarget',
|
|
35
|
+
novalidate: 'noValidate',
|
|
36
|
+
inputmode: 'inputMode',
|
|
37
|
+
datetime: 'dateTime',
|
|
38
|
+
frameborder: 'frameBorder',
|
|
39
|
+
bgcolor: 'bgColor'
|
|
14
40
|
};
|
|
15
41
|
|
|
16
42
|
class MiElement extends HTMLElement {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mi-element",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "Build lightweight reactive micro web-components",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/commenthol/mi-element/tree/main/packages/mi-element#readme",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"types"
|
|
78
78
|
],
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"mi-signal": "0.9.
|
|
80
|
+
"mi-signal": "0.9.8"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@eslint/js": "^9.39.4",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"typescript": "^5.9.3",
|
|
99
99
|
"vite": "^7.3.2",
|
|
100
100
|
"vitest": "^4.1.5",
|
|
101
|
-
"mi-html": "0.9.
|
|
101
|
+
"mi-html": "0.9.8"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
104
|
"all": "npm-run-all pretty lint test build types",
|
package/src/element.js
CHANGED
|
@@ -9,7 +9,42 @@ import { toNumber, toJson } from './utils.js'
|
|
|
9
9
|
*/
|
|
10
10
|
const nameMap = {
|
|
11
11
|
class: 'className',
|
|
12
|
-
for: 'htmlFor'
|
|
12
|
+
for: 'htmlFor',
|
|
13
|
+
// input attributes
|
|
14
|
+
maxlength: 'maxLength',
|
|
15
|
+
minlength: 'minLength',
|
|
16
|
+
readonly: 'readOnly',
|
|
17
|
+
colorspace: 'colorSpace',
|
|
18
|
+
// focus
|
|
19
|
+
tabindex: 'tabIndex',
|
|
20
|
+
accesskey: 'accessKey',
|
|
21
|
+
// table
|
|
22
|
+
rowspan: 'rowSpan',
|
|
23
|
+
colspan: 'colSpan',
|
|
24
|
+
cellpadding: 'cellPadding',
|
|
25
|
+
cellspacing: 'cellSpacing',
|
|
26
|
+
// editing
|
|
27
|
+
contenteditable: 'contentEditable',
|
|
28
|
+
// media / resource
|
|
29
|
+
crossorigin: 'crossOrigin',
|
|
30
|
+
referrerpolicy: 'referrerPolicy',
|
|
31
|
+
usemap: 'useMap',
|
|
32
|
+
ismap: 'isMap',
|
|
33
|
+
// form
|
|
34
|
+
enctype: 'encType',
|
|
35
|
+
formaction: 'formAction',
|
|
36
|
+
formenctype: 'formEncType',
|
|
37
|
+
formmethod: 'formMethod',
|
|
38
|
+
formnovalidate: 'formNoValidate',
|
|
39
|
+
formtarget: 'formTarget',
|
|
40
|
+
novalidate: 'noValidate',
|
|
41
|
+
// input
|
|
42
|
+
inputmode: 'inputMode',
|
|
43
|
+
// time
|
|
44
|
+
datetime: 'dateTime',
|
|
45
|
+
// legacy
|
|
46
|
+
frameborder: 'frameBorder',
|
|
47
|
+
bgcolor: 'bgColor'
|
|
13
48
|
}
|
|
14
49
|
|
|
15
50
|
/**
|