microtags 0.0.13 → 0.1.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 +567 -40
- package/dist/build.cjs +412 -0
- package/dist/build.cjs.map +7 -0
- package/dist/build.d.ts +17 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +395 -0
- package/dist/build.js.map +7 -0
- package/dist/builders.d.ts +70 -4
- package/dist/builders.d.ts.map +1 -1
- package/dist/{chunk-CCYWRJW6.js → chunk-46UEUDVX.js} +4 -26
- package/dist/chunk-46UEUDVX.js.map +7 -0
- package/dist/chunk-LS4L5QRD.js +26 -0
- package/dist/chunk-LS4L5QRD.js.map +7 -0
- package/dist/chunk-RKWPTT6P.js +69 -0
- package/dist/chunk-RKWPTT6P.js.map +7 -0
- package/dist/chunk-ZZ4ZLOQY.js +33 -0
- package/dist/chunk-ZZ4ZLOQY.js.map +7 -0
- package/dist/cli.cjs +536 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/context.js +2 -1
- package/dist/esbuild.cjs +451 -0
- package/dist/esbuild.cjs.map +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +434 -0
- package/dist/esbuild.js.map +7 -0
- package/dist/factory.d.ts +7 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/htm.browser.cjs +591 -0
- package/dist/htm.browser.cjs.map +7 -0
- package/dist/htm.browser.d.ts +30 -0
- package/dist/htm.browser.d.ts.map +1 -0
- package/dist/htm.browser.js +498 -0
- package/dist/htm.browser.js.map +7 -0
- package/dist/htm.browser.min.js +3 -0
- package/dist/htm.browser.min.js.map +7 -0
- package/dist/htm.cjs +284 -0
- package/dist/htm.cjs.map +7 -0
- package/dist/htm.d.ts +14 -0
- package/dist/htm.d.ts.map +1 -0
- package/dist/htm.js +196 -0
- package/dist/htm.js.map +7 -0
- package/dist/htm.min.js +3 -0
- package/dist/htm.min.js.map +7 -0
- package/dist/index.cjs +125 -11
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +133 -17
- package/dist/index.js.map +2 -2
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/meta.json +411 -26
- package/dist/preact-shared.d.ts +61 -0
- package/dist/preact-shared.d.ts.map +1 -0
- package/dist/preact.browser.d.ts +8 -0
- package/dist/preact.browser.d.ts.map +1 -0
- package/dist/preact.browser.js +45 -0
- package/dist/preact.browser.js.map +7 -0
- package/dist/preact.browser.min.js +2 -0
- package/dist/preact.browser.min.js.map +7 -0
- package/dist/preact.cjs +128 -0
- package/dist/preact.cjs.map +7 -0
- package/dist/preact.d.ts +9 -0
- package/dist/preact.d.ts.map +1 -0
- package/dist/preact.js +35 -0
- package/dist/preact.js.map +7 -0
- package/dist/render-support.cjs +86 -0
- package/dist/render-support.cjs.map +7 -0
- package/dist/render-support.d.ts +23 -0
- package/dist/render-support.d.ts.map +1 -0
- package/dist/render-support.js +12 -0
- package/dist/render-support.js.map +7 -0
- package/dist/render-support.min.js +2 -0
- package/dist/render-support.min.js.map +7 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/vite.cjs +448 -0
- package/dist/vite.cjs.map +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +429 -0
- package/dist/vite.js.map +7 -0
- package/package.json +92 -13
- package/dist/chunk-CCYWRJW6.js.map +0 -7
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/preact-shared.ts
|
|
6
|
+
function splitProps(El, events, props) {
|
|
7
|
+
if (props.children !== void 0) {
|
|
8
|
+
throw new Error(`microtags/preact: <${El.TAG}> takes no children`);
|
|
9
|
+
}
|
|
10
|
+
const own = {};
|
|
11
|
+
const on = {};
|
|
12
|
+
const rest = {};
|
|
13
|
+
for (const k in props) {
|
|
14
|
+
if (k === "children") continue;
|
|
15
|
+
if (El.props.includes(k)) own[k] = props[k];
|
|
16
|
+
else if (Object.hasOwn(events, k)) on[events[k]] = props[k];
|
|
17
|
+
else rest[k] = props[k];
|
|
18
|
+
}
|
|
19
|
+
return { own, on, rest };
|
|
20
|
+
}
|
|
21
|
+
__name(splitProps, "splitProps");
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
splitProps
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-LS4L5QRD.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/preact-shared.ts"],
|
|
4
|
+
"sourcesContent": ["// Types and prop mapping shared by both builds of `microtags/preact`\n// (the default server build and the browser build). Never imports\n// render support. See ADR-010.\nimport type { FunctionComponent } from 'preact'\nimport type { RenderParts } from './builders.js'\n\n/**\n * The part of a microtags element class the adapter reads. Any class\n * from `setup` fits; `renderParts` is absent at runtime when the class\n * has no render link.\n */\nexport interface PreactElementClass<P = any> {\n readonly TAG:string\n readonly props:readonly string[]\n readonly renderParts?:(\n props:P,\n options?:{ children?:string; attrs?:Record<string, string> }\n ) => RenderParts\n}\n\n/** Map from callback prop name to DOM event name. */\nexport type EventMap = Record<string, string>\n\nexport interface ToPreactOptions<E extends EventMap = EventMap> {\n /** e.g. `{ onChange: 'number-input:change' }` */\n events?:E\n}\n\ntype AttrValue = string | number | boolean | null | undefined\n\n/** Host attributes passed through to the host tag. */\nexport interface PassthroughProps {\n class?:string\n id?:string\n [aria:`aria-${string}`]:AttrValue\n [data:`data-${string}`]:AttrValue\n}\n\n/** The declared props of an element class, all optional. */\nexport type DeclaredProps<C> =\n C extends { renderParts?:(props:infer P, ...a:any[]) => any } ?\n Partial<P> :\n never\n\n/**\n * Props of the Preact component `toPreact` returns: the declared\n * props, one callback per mapped event, passthrough host attributes,\n * and no children.\n */\nexport type PreactProps<C, E extends EventMap = Record<never, never>> =\n DeclaredProps<C> &\n { [K in keyof E]?:(ev:CustomEvent) => void } &\n PassthroughProps &\n { children?:never }\n\nexport type PreactComponent<C, E extends EventMap> =\n FunctionComponent<PreactProps<C, E>>\n\n/** Props split by where they go on the host. */\nexport interface SplitProps {\n /** declared props, by name */\n own:Record<string, unknown>\n /** handlers, by DOM event name */\n on:Record<string, unknown>\n /** passthrough host attributes */\n rest:Record<string, unknown>\n}\n\n/**\n * Split adapter props into declared props, event handlers (keyed by DOM\n * event name) and passthrough attributes. Throws, naming the tag, when\n * children are passed.\n */\nexport function splitProps (\n El:PreactElementClass,\n events:EventMap,\n props:Record<string, unknown>\n):SplitProps {\n if (props.children !== undefined) {\n throw new Error(`microtags/preact: <${El.TAG}> takes no children`)\n }\n const own:Record<string, unknown> = {}\n const on:Record<string, unknown> = {}\n const rest:Record<string, unknown> = {}\n for (const k in props) {\n if (k === 'children') continue\n if (El.props.includes(k)) own[k] = props[k]\n else if (Object.hasOwn(events, k)) on[events[k]] = props[k]\n else rest[k] = props[k]\n }\n return { own, on, rest }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAyEO,SAAS,WACZ,IACA,QACA,OACS;AACT,MAAI,MAAM,aAAa,QAAW;AAC9B,UAAM,IAAI,MAAM,sBAAsB,GAAG,GAAG,qBAAqB;AAAA,EACrE;AACA,QAAM,MAA8B,CAAC;AACrC,QAAM,KAA6B,CAAC;AACpC,QAAM,OAA+B,CAAC;AACtC,aAAW,KAAK,OAAO;AACnB,QAAI,MAAM,WAAY;AACtB,QAAI,GAAG,MAAM,SAAS,CAAC,EAAG,KAAI,CAAC,IAAI,MAAM,CAAC;AAAA,aACjC,OAAO,OAAO,QAAQ,CAAC,EAAG,IAAG,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC;AAAA,QACrD,MAAK,CAAC,IAAI,MAAM,CAAC;AAAA,EAC1B;AACA,SAAO,EAAE,KAAK,IAAI,KAAK;AAC3B;AAlBgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/render-support.ts
|
|
6
|
+
var _esc = {
|
|
7
|
+
"&": "&",
|
|
8
|
+
'"': """,
|
|
9
|
+
"'": "'",
|
|
10
|
+
"<": "<",
|
|
11
|
+
">": ">"
|
|
12
|
+
};
|
|
13
|
+
function _escAttr(s) {
|
|
14
|
+
return s.replace(/[&"'<>]/g, (c) => _esc[c]);
|
|
15
|
+
}
|
|
16
|
+
__name(_escAttr, "_escAttr");
|
|
17
|
+
var _attrName = /^[a-z_:][-\w:.]*$/i;
|
|
18
|
+
function _serialize(m, v) {
|
|
19
|
+
if (m.kind === "prop-only" || v == null) return null;
|
|
20
|
+
if (m.kind === "boolean") return v === true ? "" : null;
|
|
21
|
+
if (m.kind === "json") return JSON.stringify(v);
|
|
22
|
+
return String(v);
|
|
23
|
+
}
|
|
24
|
+
__name(_serialize, "_serialize");
|
|
25
|
+
function _attr(k, v) {
|
|
26
|
+
return v === "" ? ` ${k}` : ` ${k}="${_escAttr(v)}"`;
|
|
27
|
+
}
|
|
28
|
+
__name(_attr, "_attr");
|
|
29
|
+
function renderParts(rec, props, options) {
|
|
30
|
+
const extra = options?.attrs ?? {};
|
|
31
|
+
const html = String(rec.f({
|
|
32
|
+
props,
|
|
33
|
+
refs: rec.r,
|
|
34
|
+
TAG: rec.t,
|
|
35
|
+
children: options?.children ?? "",
|
|
36
|
+
attrs: extra
|
|
37
|
+
}));
|
|
38
|
+
const attrs = /* @__PURE__ */ Object.create(null);
|
|
39
|
+
for (const k in rec.m) {
|
|
40
|
+
const s = k in props ? _serialize(rec.m[k], props[k]) : null;
|
|
41
|
+
if (s !== null) attrs[k] = s;
|
|
42
|
+
}
|
|
43
|
+
for (const [k, v] of Object.entries(extra)) {
|
|
44
|
+
if (_attrName.test(k)) attrs[k] ??= v;
|
|
45
|
+
}
|
|
46
|
+
return { tag: rec.t, attrs, html };
|
|
47
|
+
}
|
|
48
|
+
__name(renderParts, "renderParts");
|
|
49
|
+
function renderHost(rec, props, options) {
|
|
50
|
+
const { tag, attrs, html } = renderParts(rec, props, options);
|
|
51
|
+
let a = "";
|
|
52
|
+
for (const k in attrs) a += _attr(k, attrs[k]);
|
|
53
|
+
return `<${tag}${a}>${html}</${tag}>`;
|
|
54
|
+
}
|
|
55
|
+
__name(renderHost, "renderHost");
|
|
56
|
+
function register() {
|
|
57
|
+
const g = globalThis;
|
|
58
|
+
g[/* @__PURE__ */ Symbol.for("microtags.render")] = renderHost;
|
|
59
|
+
g[/* @__PURE__ */ Symbol.for("microtags.renderParts")] = renderParts;
|
|
60
|
+
}
|
|
61
|
+
__name(register, "register");
|
|
62
|
+
register();
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
renderParts,
|
|
66
|
+
renderHost,
|
|
67
|
+
register
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-RKWPTT6P.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/render-support.ts"],
|
|
4
|
+
"sourcesContent": ["// Server render support: the host-tag builder, prop serializers and\n// attribute escaping. Importing this module registers `renderHost`\n// under a registry symbol on `globalThis`, where a component's `render`\n// static finds it. Core never imports this module, so a bundle with\n// every render link stripped leaves it out. See ADR-009.\nimport type {\n PropMeta,\n RenderParts,\n RenderRecord,\n} from './builders.js'\n\nconst _esc:Record<string, string> = {\n '&': '&',\n '\"': '"',\n \"'\": ''',\n '<': '<',\n '>': '>',\n}\nfunction _escAttr (s:string):string {\n return s.replace(/[&\"'<>]/g, c => _esc[c])\n}\n\n// HTML attribute name grammar: a letter, `_` or `:`, then letters,\n// digits, `-`, `_`, `:` or `.`. Extra attrs may come from data.\nconst _attrName = /^[a-z_:][-\\w:.]*$/i\n\n// The kind is decided by core, so no coercer is compared here and any\n// copy of this module serves any copy of core.\nfunction _serialize (m:PropMeta, v:unknown):string | null {\n if (m.kind === 'prop-only' || v == null) return null\n if (m.kind === 'boolean') return v === true ? '' : null\n if (m.kind === 'json') return JSON.stringify(v)\n return String(v)\n}\n\nfunction _attr (k:string, v:string):string {\n return v === '' ? ` ${k}` : ` ${k}=\"${_escAttr(v)}\"`\n}\n\n/**\n * Render a component as parts: the host tag name, its serialized\n * (unescaped) attributes, declared props first, and the inner HTML.\n * `attrs` has no prototype, so a name like `__proto__` from data is a\n * plain key. A declared prop keeps its value over an extra attr of the\n * same name, as an HTML parser keeps the first of a duplicate.\n */\nexport function renderParts (\n rec:RenderRecord,\n props:Record<string, unknown>,\n options?:{ children?:string; attrs?:Record<string, string> }\n):RenderParts {\n const extra = options?.attrs ?? {}\n const html = String(rec.f({\n props,\n refs: rec.r,\n TAG: rec.t,\n children: options?.children ?? '',\n attrs: extra,\n }))\n const attrs:Record<string, string> = Object.create(null)\n for (const k in rec.m) {\n const s = k in props ? _serialize(rec.m[k], props[k]) : null\n if (s !== null) attrs[k] = s\n }\n for (const [k, v] of Object.entries(extra)) {\n if (_attrName.test(k)) attrs[k] ??= v\n }\n return { tag: rec.t, attrs, html }\n}\n\n/** Render a component's host tag around the output of its render link. */\nexport function renderHost (\n rec:RenderRecord,\n props:Record<string, unknown>,\n options?:{ children?:string; attrs?:Record<string, string> }\n):string {\n const { tag, attrs, html } = renderParts(rec, props, options)\n let a = ''\n for (const k in attrs) a += _attr(k, attrs[k])\n return `<${tag}${a}>${html}</${tag}>`\n}\n\n/**\n * Store `renderHost` and `renderParts` where the `render` and\n * `renderParts` statics look them up.\n */\nexport function register ():void {\n const g = globalThis as any\n g[Symbol.for('microtags.render')] = renderHost\n g[Symbol.for('microtags.renderParts')] = renderParts\n}\n\nregister()\n"],
|
|
5
|
+
"mappings": ";;;;;AAWA,IAAM,OAA8B;AAAA,EAChC,KAAK;AAAA,EACL,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AK,OAAO,OAAO;AAC5D,MAAI,IAAI;AACR,aAAW,KAAK,MAAO,MAAK,MAAM,GAAG,MAAM,CAAC,CAAC;AAC7C,SAAO,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,KAAK,GAAG;AACtC;AATgB;AAeT,SAAS,WAAiB;AAC7B,QAAM,IAAI;AACV,IAAE,uBAAO,IAAI,kBAAkB,CAAC,IAAI;AACpC,IAAE,uBAAO,IAAI,uBAAuB,CAAC,IAAI;AAC7C;AAJgB;AAMhB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "./chunk-7QVYU63E.js";
|
|
4
|
+
|
|
5
|
+
// src/reactivity.ts
|
|
6
|
+
import {
|
|
7
|
+
signal,
|
|
8
|
+
effect,
|
|
9
|
+
effectScope,
|
|
10
|
+
setActiveSub
|
|
11
|
+
} from "alien-signals";
|
|
12
|
+
function untracked(fn) {
|
|
13
|
+
const prev = setActiveSub(void 0);
|
|
14
|
+
try {
|
|
15
|
+
return fn();
|
|
16
|
+
} finally {
|
|
17
|
+
setActiveSub(prev);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
__name(untracked, "untracked");
|
|
21
|
+
function peek(sig) {
|
|
22
|
+
return untracked(() => sig());
|
|
23
|
+
}
|
|
24
|
+
__name(peek, "peek");
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
signal,
|
|
28
|
+
effect,
|
|
29
|
+
effectScope,
|
|
30
|
+
untracked,
|
|
31
|
+
peek
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=chunk-ZZ4ZLOQY.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/reactivity.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n signal,\n effect,\n effectScope,\n setActiveSub,\n} from 'alien-signals'\nimport type { Signal } from './types.js'\n\n// Re-export alien-signals primitives under stable names for internal use.\nexport { signal, effect, effectScope }\n\n/**\n * Run fn without tracking any signals it reads.\n * Suspends the current subscriber via setActiveSub(undefined),\n * restoring it in a finally block so nested effects are unaffected.\n */\nexport function untracked<T> (fn:() => T):T {\n const prev = setActiveSub(undefined)\n try {\n return fn()\n } finally {\n setActiveSub(prev)\n }\n}\n\n/**\n * Read a signal's current value without subscribing.\n * Equivalent to untracked(() => sig()).\n */\nexport function peek<T> (sig:Signal<T>):T {\n return untracked(() => sig())\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAWA,SAAS,UAAc,IAAc;AACxC,QAAM,OAAO,aAAa,MAAS;AACnC,MAAI;AACA,WAAO,GAAG;AAAA,EACd,UAAE;AACE,iBAAa,IAAI;AAAA,EACrB;AACJ;AAPgB;AAaT,SAAS,KAAS,KAAiB;AACtC,SAAO,UAAU,MAAM,IAAI,CAAC;AAChC;AAFgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|