@twobirds/microcomponents 0.10.3 → 0.12.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 +13 -3
- package/dist/MC.min.js +1 -1
- package/dist/autoload.min.js +1 -1
- package/dist/cli/create.d.ts.map +1 -1
- package/dist/cli/dev.d.ts +3 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dispatch.d.ts +2 -0
- package/dist/cli/dispatch.d.ts.map +1 -1
- package/dist/cli/index.js +110 -18
- package/dist/cli/preview.d.ts +3 -1
- package/dist/cli/preview.d.ts.map +1 -1
- package/dist/core/MC.d.ts +1 -1
- package/dist/core/MC.d.ts.map +1 -1
- package/dist/core/elements.d.ts.map +1 -1
- package/dist/core/elements.js +12 -5
- package/dist/core/mcGuards.js +6 -1
- package/dist/docs/cli.d.ts +1 -1
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/helpers.min.js +1 -0
- package/dist/mcGuards.min.js +1 -1
- package/dist/mcp/api.json +30 -4
- package/dist/mcp/concepts/mc-types.md +15 -8
- package/dist/mcp/docs.d.ts +55 -0
- package/dist/mcp/docs.d.ts.map +1 -0
- package/dist/mcp/index.js +320 -203
- package/dist/mcp/server.d.ts +43 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/tools.d.ts +54 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/microcomponents.d.ts +1 -0
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.js +84 -39
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/placeholders.min.js +1 -0
- package/dist/state/formValues.d.ts.map +1 -1
- package/dist/state/formValues.js +59 -31
- package/dist/state/index.d.ts +2 -0
- package/dist/state/index.d.ts.map +1 -1
- package/dist/state/observables.d.ts.map +1 -1
- package/dist/state/observables.js +55 -28
- package/dist/state/placeholders.d.ts +0 -1
- package/dist/state/placeholders.d.ts.map +1 -1
- package/dist/state/placeholders.js +1980 -0
- package/dist/utils/autoload.d.ts.map +1 -1
- package/dist/utils/autoload.js +1451 -0
- package/dist/utils/events.d.ts +1 -1
- package/dist/utils/events.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +3 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +693 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +23 -5
package/dist/formValues.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}n.removeEventListener(e(n,r),i)}}function n(t,r,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}return t.addEventListener(e(t,r),i,{capture:!1,once:a}),i}}function r(e,t,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,t,i));return}return n(e,t,i,!0),i}}var i=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function a(t,n,r={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>a(e,n,r,o));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new i,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&a(t.parentElement,c,r,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)a(e,c,r,`ld`)})}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return typeof e==`object`&&!!e&&e.constructor===Object}function c(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],a=e[i];s(a)?t[i]=c(a):t[i]=a}return t}function l(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=l(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?c(n):n}function u(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!u(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!u(n[t],r[t]))return!1}return!0}function d(e){return e.replace(/[A-Z]/g,(e,t)=>(t?`-`:``)+e.toLowerCase())}function f(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}var p=new WeakMap;function m(e,t){let n=p.get(e)??new Set;if(n.has(t))return e.adoptedStyleSheets[0];n.add(t),p.set(e,n);let r=new CSSStyleSheet;return r.replaceSync(t),e.adoptedStyleSheets.push(r),r}function h(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:m(document,t[i]);break;case`targetCss`:m(document,t[i]);break;case`shadowCss`:m(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],_(r,e);break;case`targetHtml`:n.innerHTML=t[i],_(n,e);break}})}function g(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function _(e,t){let r=[...e.querySelectorAll(`*`)];for(let e of r){if(!(e instanceof HTMLElement))continue;let r=[...e.attributes];for(let i of r){let r=i.name.toLowerCase();if(!(`on`+r in e))continue;let o=i.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?n(e,r,()=>t.trigger(c,u)):n(e,r,()=>a(s,c,u))}}}function v(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function y(e,t,n={}){let r=e;`_mc`in e||(r._mc=new E(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function b(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function x(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function S(e){let t=e.target,r=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(r).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof r[e]==`function`);for(let e of a){let r=/^one/.test(e);n(t,e.replace(/^one?/,``),t=>i[e](t),r)}}function C(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function w(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var T=class{_target;static _assets={};static assets=[];static _assetsPromise;constructor(e){this._target=new WeakRef(e||{});let t=this.constructor;this instanceof E&&this.constructor!==E&&S(this);let n=(t.assets??[]).filter(e=>!t._assets[e]);n.length&&!t._assetsPromise&&(t._assetsPromise=g(t._originalTag||(this instanceof E?this.target.tagName.toLowerCase():d(t.name)),n).then(e=>{let r={};return n.forEach((t,n)=>{r[t]=e[n]}),t._assets=Object.assign({},t._assets,r),r}))}get target(){return this._target.deref()}get assets(){return this.constructor._assets||{}}},E=class e extends T{static tag;static attributes={};constructor(t){super(t);let n=this.constructor;if(n===e)return;let r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),n._originalTag=r,e.add(t,n.name,new n(t)),delete n._originalTag,r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}let i=n.attributes;if(n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])}),Object.keys(n._assets).length){h(this,n._assets);for(let e of[`css`,`targetCss`])delete n._assets[e];n.assets=n.assets.filter(e=>e!==`css`&&e!==`targetCss`)}if(n._assetsPromise?n._assetsPromise.then(e=>{h(this,e);for(let e of[`css`,`targetCss`])delete n._assets[e];n.assets=n.assets.filter(e=>e!==`css`&&e!==`targetCss`),x(this)}):x(this),n.tag===``){this.target.remove();return}}static add(e,t,n={}){return y(e,t,n)}static remove(e,t){b(e,t)}static get(e,t,n){if(!v(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,n){t(this.target,e,n)}on(e,t){return n(this.target,e,t)}one(e,t){return r(this.target,e,t)}trigger(e,t={},n=`l`,r){a(this.target,e,t,n,r)}ancestors(e){let t=[],n=w(this.target,e);for(;n;)t.push(n),n=w(n.target,e);return t}closest(e){return w(this.target,e)}children(e){let t=C(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function D(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var O=[`INPUT`,`SELECT`,`TEXTAREA`],k=class extends E{data={};oldDisplay=``;constructor(e){super(e),D(e).forEach(e=>this.data[e]=``),L(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)),r=e.getAttribute(t)??``;this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(r))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=n.nodeValue??``,i=new Set(r.match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>r=>{let a=t;i.forEach(e=>{a=a.replace(e,String(r[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(r)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!O.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function A(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!D(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function j(e){A(e).forEach(e=>{e?._mc?._placeholders||E.add(e,`_placeholders`,new k(e))})}function M(e){return typeof e==`object`&&!!e}var N={};function P(e){let t=e.constructor,n=t.name,r=class extends t{#e=!0;#t=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],M(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#t}set callbacks(e){this.#t=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#t.push(e),this}unsubscribe(e){return this.#t=this.#t.filter(t=>t!==e),this}bind(e){if(o()){if(M(this.valueOf())){j(e);let t=[e,...e.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#t.push(function(e){let n=l(e);t.forEach(e=>{e&&a(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=M(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#e=e),this.#e&&this.#t.forEach(e=>{e(t)}),this}};return N[n]=r,r}function F(e){return N[e.constructor.name]||P(e)}function I(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function L(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!I(r)){if(t[0]===`_`||r===void 0)return;let i=r,a=new(F(i))(i),o=function(){queueMicrotask(function(){a.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(M(a.valueOf())){let e=structuredClone(Object.assign({},a));queueMicrotask(function(){u(structuredClone(Object.assign({},a)),e)||o()})}return a},set(e){if(typeof e==typeof a.valueOf())if(M(a.valueOf())&&!(a.valueOf()instanceof Array))I(a)||(a=new(F(e))(structuredClone(Object.assign({},e))),f(e,a)),Object.assign(a,e),a.notify();else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(F(e))(e),a.callbacks=n,o())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof a.valueOf(),a,`- CANNOT BECOME:`,typeof e)}}),n[t]=i}}),e}function R(e){let t=Object.getPrototypeOf(e.prototype);function n(e,t){let n=e[t];I(n)||L(e,t)}Object.hasOwn(t,`notify`)||Object.assign(t,{notify:function(e){return n(this,e),this[e].notify(),this},subscribe:function(e,t){return n(this,e),this[e].subscribe(t),this},bind:function(e,t){return n(this,e),this[e].bind(t),this}})}R(E);var z=e=>e.tagName.toLowerCase(),B=class{constructor(e){}},V=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]];t.filter(t=>t.getAttribute(`value`)===e).shift().checked=!0}},H=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},U=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},W=class extends B{#e;#t=!1;constructor(e){super(e),this.#e=e,this.#t=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#t?e:e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},G=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},K=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(z(e)){case`input`:switch(e.type){case`radio`:r=new V(e);break;case`checkbox`:r=new H(e);break;default:r=new U(e)}break;case`select`:r=new W(e);break;case`textarea`:r=new G(e);break}if(r){let i=r;E.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function q(e,t,n){if(!o())return;let r=K(n),i=e;i[t]=Object.assign({},r),L(e,t);let a=i[t];f(r,a),[...n.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{a.notify()})})}function J(e){let t=Object.getPrototypeOf(e.prototype);Object.hasOwn(t,`formValues`)||Object.assign(t,{formValues:function(e,t){return q(this,t,e),this}})}export{J as formValuePlugin,q as formValues};
|
|
1
|
+
function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}n.removeEventListener(e(n,r),i)}}function n(t,r,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}return t.addEventListener(e(t,r),i,{capture:!1,once:a}),i}}function r(e,t,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,t,i));return}return n(e,t,i,!0),i}}var i=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function a(t,n,r={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>a(e,n,r,o));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new i,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&a(t.parentElement,c,r,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)a(e,c,r,`ld`)})}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return typeof e==`object`&&!!e&&e.constructor===Object}function c(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],a=e[i];s(a)?t[i]=c(a):t[i]=a}return t}function l(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=l(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?c(n):n}function u(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!u(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!u(n[t],r[t]))return!1}return!0}function d(e){return e.replace(/[A-Z]/g,(e,t)=>(t?`-`:``)+e.toLowerCase())}function f(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}var p=new WeakMap;function m(e,t){let n=p.get(e)??new Set;if(n.has(t))return e.adoptedStyleSheets[0];n.add(t),p.set(e,n);let r=new CSSStyleSheet;return r.replaceSync(t),e.adoptedStyleSheets.push(r),r}function h(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:m(document,t[i]);break;case`targetCss`:m(document,t[i]);break;case`shadowCss`:m(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],_(r,e);break;case`targetHtml`:n.innerHTML=t[i],_(n,e);break}})}function g(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function _(e,t){let r=[...e.querySelectorAll(`*`)];for(let e of r){if(!(e instanceof HTMLElement))continue;let r=[...e.attributes];for(let i of r){let r=i.name.toLowerCase();if(!(`on`+r in e))continue;let o=i.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?n(e,r,()=>t.trigger(c,u)):n(e,r,()=>a(s,c,u))}}}function v(e,t){if(typeof HTMLElement>`u`||!(e instanceof HTMLElement)||!(`_mc`in e))return!1;if(t===void 0)return!0;let n=e._mc;return typeof n!=`object`||!n?!1:t in n}function y(e,t,n={}){let r=e;`_mc`in e||(r._mc=new E(e));let i=r._mc;return t.length&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function b(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function x(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function S(e){let t=e.target,r=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(r).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof r[e]==`function`);for(let e of a){let r=/^one/.test(e);n(t,e.replace(/^one?/,``),t=>i[e](t),r)}}function C(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function w(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var T=class{#e;static _assets={};static assets=[];static _assetsPromise;constructor(e){this.#e=new WeakRef(e||{});let t=this.constructor;this instanceof E&&this.constructor!==E&&S(this);let n=(t.assets??[]).filter(e=>!t._assets[e]);n.length&&!t._assetsPromise&&(t._assetsPromise=g(t._originalTag||(this instanceof E?this.target.tagName.toLowerCase():d(t.name)),n).then(e=>{let r={};return n.forEach((t,n)=>{r[t]=e[n]}),t._assets=Object.assign({},t._assets,r),r}))}get target(){return this.#e.deref()}get assets(){return this.constructor._assets||{}}},E=class e extends T{static tag;static attributes={};constructor(t){super(t);let n=this.constructor;if(n===e)return;let r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),n._originalTag=r,e.add(t,n.name,new n(t)),delete n._originalTag,r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}let i=n.attributes;if(n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])}),Object.keys(n._assets).length){h(this,n._assets);for(let e of[`css`,`targetCss`])delete n._assets[e];n.assets=n.assets.filter(e=>e!==`css`&&e!==`targetCss`)}if(n._assetsPromise?n._assetsPromise.then(e=>{h(this,e);for(let e of[`css`,`targetCss`])delete n._assets[e];n.assets=n.assets.filter(e=>e!==`css`&&e!==`targetCss`),x(this)}):x(this),n.tag===``){this.target.remove();return}}static add(e,t,n={}){return y(e,t,n)}static remove(e,t){b(e,t)}static get(e,t,n){if(!v(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,n){t(this.target,e,n)}on(e,t){return n(this.target,e,t)}one(e,t){return r(this.target,e,t)}trigger(e,t={},n=`l`,r){a(this.target,e,t,n,r)}ancestors(e){let t=[],n=w(this.target,e);for(;n;)t.push(n),n=w(n.target,e);return t}closest(e){return w(this.target,e)}children(e){let t=C(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function D(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var O=[`INPUT`,`SELECT`,`TEXTAREA`],k=class extends E{data={};#e=``;#t=!1;constructor(e){super(e),D(e).forEach(e=>this.data[e]=``),L(this),this.#r()}#n(e,t,n){t.replace(/[\{\}]/g,``);let r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return e.replace(new RegExp(r,`g`),n)}#r(){let e=this.target;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)),r=e.getAttribute(t)??``;this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=this.#n(a,e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(r))});let t=[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g));t.length&&(this.#e=e.getAttribute(`style`)||``,t.forEach(t=>{let n=t.nodeValue??``,r=new Set(n.match(/\{[^\{\}]*\}/g));this.data.subscribe((n=>i=>{let a=n;r.forEach(e=>{a=this.#n(a,e,String(i[e.replace(/[\{\}]/g,``)]))}),this.#t||(this.#t=!0,this.#e?e.style=this.#e:e.removeAttribute(`style`)),t.nodeValue=a})(n)),!O.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)}))}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function A(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!D(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function j(e){A(e).forEach(e=>{e?._mc?._placeholders||E.add(e,`_placeholders`,new k(e))})}function M(e){return typeof e==`object`&&!!e}var N={};function P(e){let t=e.constructor,n=t.name,r=class extends t{#e=!0;#t=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],M(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#t}set callbacks(e){this.#t=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#t.push(e),this}unsubscribe(e){return this.#t=this.#t.filter(t=>t!==e),this}bind(e){if(!o())return this;if(M(this.valueOf())){j(e);let t=[e,...e.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#t.push(function(e){let n=l(e);t.forEach(e=>{e&&a(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}notify(e){let t=M(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#e=e),this.#e&&this.#t.forEach(e=>{e(t)}),this}};return N[n]=r,r}function F(e){return N[e.constructor.name]||P(e)}function I(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function L(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!I(r)){if(t[0]===`_`||r===void 0)return;let i=r,a=new(F(i))(i),o=!1,s=function(){o||(o=!0,queueMicrotask(function(){o=!1,a.notify()}))};Object.defineProperty(e,t,{enumerable:!0,get(){if(M(a.valueOf())){let e=structuredClone(Object.assign({},a));queueMicrotask(function(){u(structuredClone(Object.assign({},a)),e)||s()})}return a},set(e){if(typeof e==typeof a.valueOf())if(M(a.valueOf())&&!(a.valueOf()instanceof Array))I(a)||(a=new(F(e))(structuredClone(Object.assign({},e))),f(e,a)),Object.assign(a,e),a.notify();else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(F(e))(e),a.callbacks=n,s())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof a.valueOf(),a,`- CANNOT BECOME:`,typeof e)}}),n[t]=i}}),e}function R(e){let t=Object.getPrototypeOf(e.prototype);function n(e,t){let n=e[t];I(n)||L(e,t)}Object.hasOwn(t,`notify`)||Object.assign(t,{notify:function(e){return n(this,e),this[e].notify(),this},subscribe:function(e,t){return n(this,e),this[e].subscribe(t),this},bind:function(e,t){return n(this,e),this[e].bind(t),this}})}R(E);var z=e=>e.tagName.toLowerCase(),B=class{constructor(e){}},V=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]].filter(t=>t.getAttribute(`value`)===e).shift();t&&(t.checked=!0)}},H=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},U=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},W=class extends B{#e;#t=!1;constructor(e){super(e),this.#e=e,this.#t=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#t?e:e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},G=class extends B{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},K=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(z(e)){case`input`:switch(e.type){case`radio`:r=new V(e);break;case`checkbox`:r=new H(e);break;default:r=new U(e)}break;case`select`:r=new W(e);break;case`textarea`:r=new G(e);break}if(r){let i=r;E.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function q(e,t,n){if(!o())return;let r=K(n),i=e;i[t]=Object.assign({},r),L(e,t);let a=i[t];f(r,a),[...n.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{a.notify()})})}function J(e){let t=Object.getPrototypeOf(e.prototype);Object.hasOwn(t,`formValues`)||Object.assign(t,{formValues:function(e,t){return q(this,t,e),this}})}export{J as formValuePlugin,q as formValues};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i,a=!1){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}return n.addEventListener(e(n,r),i,{capture:!1,once:a}),i}}var n=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function r(t,i,a={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>r(e,i,a,o));return}let c=/^_mc/.test(i)?i:e(t,i),l=s||new n,u=new CustomEvent(c,{detail:{data:a,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&r(t.parentElement,c,a,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)r(e,c,a,`ld`)})}function i(){return typeof window<`u`&&window.document!==void 0}function a(e){return typeof e==`object`&&!!e&&e.constructor===Object}function o(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],s=e[i];a(s)?t[i]=o(s):t[i]=s}return t}function s(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=s(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?o(n):n}function c(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!c(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!c(n[t],r[t]))return!1}return!0}function l(e,t={}){let n=t,r=typeof e==`string`?e.split(`.`):e;if(!n||!r[0]||!(r[0]in n))return;let i=n[r[0]];return r.length>1?a(i)?l(r.slice(1),i):void 0:i}function u(e,t,...n){let r=[e,t,...n];if(r.length>2){for(;r.length>1;)r[0]=u(r[0],r[1]),r.splice(1,1);return r[0]}if(typeof e==`string`){let n=e;return e.match(/\{[^\{\}]*\}/g)?.forEach(e=>{let r=l(e.substring(1,e.length-1),t);r!==void 0&&(n=n.replace(e,String(r)))}),n}else if(Array.isArray(e))return e.map(e=>u(e,t));else if(a(e)){let n=e;Object.keys(n).forEach(e=>{Object.prototype.hasOwnProperty.call(n,e)&&(n[e]=u(n[e],t))})}return e}function d(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function f(e){return e.replace(/[A-Z]/g,(e,t)=>(t?`-`:``)+e.toLowerCase())}function p(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}}function m(e){let t=document.createElement(`template`);return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,`<$1$2></$1>`),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}function h(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}var g=new WeakMap;function _(e,t){let n=g.get(e)??new Set;if(n.has(t))return e.adoptedStyleSheets[0];n.add(t),g.set(e,n);let r=new CSSStyleSheet;return r.replaceSync(t),e.adoptedStyleSheets.push(r),r}function v(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:_(document,t[i]);break;case`targetCss`:_(document,t[i]);break;case`shadowCss`:_(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],b(r,e);break;case`targetHtml`:n.innerHTML=t[i],b(n,e);break}})}function y(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function b(e,n){let i=[...e.querySelectorAll(`*`)];for(let e of i){if(!(e instanceof HTMLElement))continue;let i=[...e.attributes];for(let a of i){let i=a.name.toLowerCase();if(!(`on`+i in e))continue;let o=a.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(a.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?t(e,i,()=>n.trigger(c,u)):t(e,i,()=>r(s,c,u))}}}export{b as bindTemplateEvents,h as copyGettersSetters,p as debounce,c as deepEqual,s as flattenObject,m as htmlToElements,_ as injectCSS,i as isBrowser,a as isNativeObject,d as kebabToPascal,y as loadAssets,l as nameSpace,u as parse,f as pascalToKebab,v as processAssets,o as sortObject};
|
package/dist/mcGuards.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t){
|
|
1
|
+
function e(e,t){if(typeof HTMLElement>`u`||!(e instanceof HTMLElement)||!(`_mc`in e))return!1;if(t===void 0)return!0;let n=e._mc;return typeof n!=`object`||!n?!1:t in n}export{e as isMcHost};
|
package/dist/mcp/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"libraryVersion": "0.
|
|
3
|
-
"exportedCount":
|
|
2
|
+
"libraryVersion": "0.12.1",
|
|
3
|
+
"exportedCount": 59,
|
|
4
4
|
"entries": {
|
|
5
5
|
"MC": {
|
|
6
6
|
"name": "MC",
|
|
@@ -358,6 +358,16 @@
|
|
|
358
358
|
}
|
|
359
359
|
]
|
|
360
360
|
},
|
|
361
|
+
"makePlaceholders": {
|
|
362
|
+
"name": "makePlaceholders",
|
|
363
|
+
"kind": "function",
|
|
364
|
+
"group": "State",
|
|
365
|
+
"file": "src/state/placeholders.ts",
|
|
366
|
+
"signatures": [
|
|
367
|
+
"export function makePlaceholders(element: HTMLElement | DocumentFragment | ShadowRoot): void {"
|
|
368
|
+
],
|
|
369
|
+
"description": "Applies placeholder support to an element and its descendants.\n\nThis function scans the provided target for elements containing placeholders\nand attaches a `Placeholders` controller instance to each one if not already present."
|
|
370
|
+
},
|
|
361
371
|
"getMcEventName": {
|
|
362
372
|
"name": "getMcEventName",
|
|
363
373
|
"kind": "function",
|
|
@@ -574,11 +584,11 @@
|
|
|
574
584
|
"signatures": [
|
|
575
585
|
"export function nameSpace(ns: string | string[], obj: object = {}): unknown {"
|
|
576
586
|
],
|
|
577
|
-
"description": "Retrieves a nested value from an object using a namespace path (dot-separated)
|
|
587
|
+
"description": "Retrieves a nested value from an object using a namespace path (dot-separated).\nA present falsy leaf (`0`, `''`, `false`, `null`) is a real value and is returned;\nonly an absent key yields `undefined`.",
|
|
578
588
|
"examples": [
|
|
579
589
|
{
|
|
580
590
|
"title": "",
|
|
581
|
-
"code": "const data = { user: { profile: { name: 'Alice' } } };\nconsole.log(nameSpace('user.profile.name', data));\nconsole.log(nameSpace(['user', 'profile'], data));"
|
|
591
|
+
"code": "const data = { user: { profile: { name: 'Alice' } } };\nconsole.log(nameSpace('user.profile.name', data));\nconsole.log(nameSpace(['user', 'profile'], data));\nconsole.log(nameSpace('count', { count: 0 })); // 0, not undefined"
|
|
582
592
|
}
|
|
583
593
|
]
|
|
584
594
|
},
|
|
@@ -614,6 +624,22 @@
|
|
|
614
624
|
}
|
|
615
625
|
]
|
|
616
626
|
},
|
|
627
|
+
"pascalToKebab": {
|
|
628
|
+
"name": "pascalToKebab",
|
|
629
|
+
"kind": "function",
|
|
630
|
+
"group": "Helpers",
|
|
631
|
+
"file": "src/utils/helpers.ts",
|
|
632
|
+
"signatures": [
|
|
633
|
+
"export function pascalToKebab(str: string) {"
|
|
634
|
+
],
|
|
635
|
+
"description": "Converts a PascalCase string to kebab-case.\nExample: 'MyComponentName' -> 'my-component-name'",
|
|
636
|
+
"examples": [
|
|
637
|
+
{
|
|
638
|
+
"title": "",
|
|
639
|
+
"code": "console.log(pascalToKebab('MyElement'));"
|
|
640
|
+
}
|
|
641
|
+
]
|
|
642
|
+
},
|
|
617
643
|
"debounce": {
|
|
618
644
|
"name": "debounce",
|
|
619
645
|
"kind": "function",
|
|
@@ -124,14 +124,15 @@ the namespaced variables of their composed parent.
|
|
|
124
124
|
Each custom element (`.ts`/`.js`) ships with optional companion files sharing the same
|
|
125
125
|
base name. The suffix encodes the structural sub-pattern (§1a–1b) and the styling target.
|
|
126
126
|
|
|
127
|
-
| Suffix | Purpose
|
|
128
|
-
| -------------- |
|
|
129
|
-
| `.css` | CSS custom properties (variable defaults) only — no structural styles
|
|
130
|
-
| `.target.css` | Structural style rules for target DOM (`innerHTML`)
|
|
131
|
-
| `.shadow.css` | Structural style rules for shadow DOM
|
|
132
|
-
| `.target.html` | HTML template injected into `this.target.innerHTML`
|
|
133
|
-
| `.shadow.html` | HTML template injected into `shadowRoot.innerHTML`
|
|
134
|
-
| `.
|
|
127
|
+
| Suffix | Purpose | Styling Target |
|
|
128
|
+
| -------------- | ----------------------------------------------------------------------- | ---------------------------------------------------- |
|
|
129
|
+
| `.css` | CSS custom properties (variable defaults) only — no structural styles | N/A (token definitions) |
|
|
130
|
+
| `.target.css` | Structural style rules for target DOM (`innerHTML`) | Global document scope via `injectCSS(document, ...)` |
|
|
131
|
+
| `.shadow.css` | Structural style rules for shadow DOM | Shadow root via `injectCSS(shadowRoot, ...)` |
|
|
132
|
+
| `.target.html` | HTML template injected into `this.target.innerHTML` | N/A (markup) |
|
|
133
|
+
| `.shadow.html` | HTML template injected into `shadowRoot.innerHTML` | N/A (markup) |
|
|
134
|
+
| `.html` | HTML template loaded as a plain string; the component injects it itself | N/A (markup) |
|
|
135
|
+
| `.json` | Static data files imported by the component | N/A (data) |
|
|
135
136
|
|
|
136
137
|
Companion files follow the same directory structure as their source file. A component at
|
|
137
138
|
`src/shop/sidebar.ts` has companions at `src/shop/sidebar.target.html`,
|
|
@@ -139,6 +140,12 @@ Companion files follow the same directory structure as their source file. A comp
|
|
|
139
140
|
`loadAssets()` / `processAssets()`; keep the `.ts` source focused on logic only —
|
|
140
141
|
constructor, lifecycle, event handlers, state.
|
|
141
142
|
|
|
143
|
+
**Declarative attributes are bound by the asset pipeline for `targetHtml` and `shadowHtml`
|
|
144
|
+
only.** `processAssets()` calls `bindTemplateEvents()` after injecting those two. A plain
|
|
145
|
+
`html` asset arrives as a string and is injected by the component, so its `click=` / `change=`
|
|
146
|
+
attributes are inert until the component binds them itself — `oneInit()` calls
|
|
147
|
+
`bindTemplateEvents(this.target, this)` right after the parse, as `<todo-item>` does.
|
|
148
|
+
|
|
142
149
|
### Inline Templates — Escape Hatch
|
|
143
150
|
|
|
144
151
|
A simple `const template` string constant is allowed **only** when the component has no
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Documentation data for the MCP server — the single source of truth the tools read.
|
|
3
|
+
|
|
4
|
+
The index is derived, never hand-copied. In a published package the server runs from
|
|
5
|
+
dist/mcp and reads the prebuilt api.json; in development (tsx from src/mcp) the index
|
|
6
|
+
is generated live from src/ at startup, so it cannot drift away from the library it
|
|
7
|
+
documents. The dev/prod decision lives in server.ts; this module is the pure data layer.
|
|
8
|
+
|
|
9
|
+
@module MCP/Docs
|
|
10
|
+
*/
|
|
11
|
+
/** One documented public export, extracted from its jsdoc block. */
|
|
12
|
+
export interface Entry {
|
|
13
|
+
name: string;
|
|
14
|
+
kind?: string;
|
|
15
|
+
group?: string;
|
|
16
|
+
file?: string;
|
|
17
|
+
signatures?: string[];
|
|
18
|
+
description?: string;
|
|
19
|
+
examples?: Array<{
|
|
20
|
+
title: string;
|
|
21
|
+
code: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** The generated documentation index, as shipped in dist/mcp/api.json. */
|
|
25
|
+
export interface IndexFile {
|
|
26
|
+
libraryVersion: string;
|
|
27
|
+
exportedCount: number;
|
|
28
|
+
entries: Record<string, Entry>;
|
|
29
|
+
undocumented: string[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
Reads the prebuilt api.json from a server directory.
|
|
33
|
+
|
|
34
|
+
@param dir - The directory the compiled server sits in; api.json is beside it.
|
|
35
|
+
@returns The parsed index.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadIndex(dir: string): IndexFile;
|
|
38
|
+
/**
|
|
39
|
+
Concept essays live one per file: copied into dist/mcp/concepts in production, read
|
|
40
|
+
from docs/concepts in development.
|
|
41
|
+
|
|
42
|
+
@param dir - The concepts folder.
|
|
43
|
+
@returns A record of concept name (filename without `.md`) to essay text. An empty
|
|
44
|
+
record when the folder is absent.
|
|
45
|
+
*/
|
|
46
|
+
export declare function readConcepts(dir: string): Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
First paragraph or sentence of a description, truncated honestly.
|
|
49
|
+
|
|
50
|
+
@param text - The description text.
|
|
51
|
+
@param limit - Maximum characters before truncation.
|
|
52
|
+
@returns The summary.
|
|
53
|
+
*/
|
|
54
|
+
export declare function summarize(text: string, limit?: number): string;
|
|
55
|
+
//# sourceMappingURL=docs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../../src/mcp/docs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAKF,oEAAoE;AACpE,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAED,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/B,YAAY,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;EAKE;AACF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAEhD;AAED;;;;;;;EAOE;AACF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAShE;AAED;;;;;;EAME;AACF,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,MAAM,CAK3D"}
|