microtags 0.0.5 → 0.0.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/README.md +207 -9
- package/dist/{chunk-E7ZGOHL3.js → chunk-P4QHFKTJ.js} +18 -2
- package/dist/chunk-P4QHFKTJ.js.map +7 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +9 -1
- 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 +18 -16
- package/dist/setup-context.d.ts +2 -2
- package/dist/setup-context.d.ts.map +1 -1
- package/dist/types.d.ts +11 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/util.cjs +17 -1
- package/dist/util.cjs.map +2 -2
- package/dist/util.d.ts +10 -2
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +5 -3
- package/dist/util.min.js +1 -1
- package/dist/util.min.js.map +3 -3
- package/package.json +1 -1
- package/dist/chunk-E7ZGOHL3.js.map +0 -7
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Web component helper with reactive props, automatic cleanup, and no
|
|
|
13
13
|
[Shadow DOM](https://gomakethings.com/the-shadow-dom-is-an-antipattern/).
|
|
14
14
|
Reactive via [alien-signals](https://github.com/stackblitz/alien-signals).
|
|
15
15
|
|
|
16
|
-
**Size
|
|
16
|
+
**Size: 3.41 KB** with all dependencies, minified and brotlied
|
|
17
17
|
|
|
18
18
|
Inspired by [nanotags](https://nanotags.psdcoder.dev/). Reactive props use
|
|
19
19
|
**alien-signals** instead of nanostores atoms.
|
|
@@ -46,8 +46,18 @@ Inspired by [nanotags](https://nanotags.psdcoder.dev/). Reactive props use
|
|
|
46
46
|
* [`microtags/render`](#microtagsrender)
|
|
47
47
|
+ [`renderList`](#renderlist)
|
|
48
48
|
+ [`render`](#render)
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
* [`microtags/util`](#microtagsutil)
|
|
50
|
+
+ [Coercion](#coercion)
|
|
51
|
+
+ [`runCleanups`](#runcleanups)
|
|
52
|
+
+ [`toAttributes`](#toattributes)
|
|
53
|
+
- [Divergence from `nanotags`](#divergence-from-nanotags)
|
|
54
|
+
* [Reactivity primitive](#reactivity-primitive)
|
|
55
|
+
* [Effects + Subscriptions](#effects--subscriptions)
|
|
56
|
+
* [Refs: `r.all` instead of `r.many`](#refs-rall-instead-of-rmany)
|
|
57
|
+
* [Context API](#context-api)
|
|
58
|
+
* [Props](#props-1)
|
|
59
|
+
* [Not ported](#not-ported)
|
|
60
|
+
* [Additions / New Features](#additions--new-features)
|
|
51
61
|
|
|
52
62
|
<!-- tocstop -->
|
|
53
63
|
|
|
@@ -321,7 +331,6 @@ Declare reactive attributes via `withProps`. Each prop becomes:
|
|
|
321
331
|
| `p.boolean()` | `"true"` / `""` → `true`, `"false"` → `false` | `false` |
|
|
322
332
|
| `p.oneOf(opts)` | Picklist enum, throws on invalid | throws |
|
|
323
333
|
|
|
324
|
-
|
|
325
334
|
#### `withProps`
|
|
326
335
|
|
|
327
336
|
```ts
|
|
@@ -335,6 +344,41 @@ Declare reactive attributes via `withProps`. Each prop becomes:
|
|
|
335
344
|
}))
|
|
336
345
|
```
|
|
337
346
|
|
|
347
|
+
##### `p.json`
|
|
348
|
+
|
|
349
|
+
`p.json<T>()` -- a prop whose attribute value is parsed with
|
|
350
|
+
`JSON.parse`. The type parameter `T` annotates the parsed result; it is a
|
|
351
|
+
type only, so the value is not validated at runtime. The resulting signal is
|
|
352
|
+
typed `T | undefined`.
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
.withProps(p => ({
|
|
356
|
+
user: p.json<{ id:number; name:string }>(),
|
|
357
|
+
}))
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
```html
|
|
361
|
+
<my-el user='{"id":1,"name":"Alice"}'></my-el>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
Like the string/number/boolean validators it is attribute-backed and
|
|
365
|
+
observed, so editing the attribute re-parses and pushes the new value to
|
|
366
|
+
`ctx.props.user`. It falls back to `undefined` in two cases: when the
|
|
367
|
+
attribute is absent, and when the value is not valid JSON. Parse errors are
|
|
368
|
+
swallowed rather than thrown.
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
// check for `undefined` case
|
|
372
|
+
ctx.effect(() => {
|
|
373
|
+
const user = ctx.props.user()
|
|
374
|
+
if (!user) return
|
|
375
|
+
ctx.refs.name.textContent = user.name
|
|
376
|
+
})
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
For input you want validated rather than only parsed, pass a Standard Schema
|
|
380
|
+
to [`p.schema`](#withprops) instead.
|
|
381
|
+
|
|
338
382
|
Inside `setup()`, every prop is a callable signal:
|
|
339
383
|
|
|
340
384
|
```ts
|
|
@@ -342,6 +386,7 @@ ctx.props.count() // read
|
|
|
342
386
|
ctx.props.count(42) // write
|
|
343
387
|
```
|
|
344
388
|
|
|
389
|
+
---
|
|
345
390
|
|
|
346
391
|
### Refs
|
|
347
392
|
|
|
@@ -500,6 +545,11 @@ define('themed-card')
|
|
|
500
545
|
// Add an event listener; auto-removed on disconnect.
|
|
501
546
|
ctx.on(el, 'click', handler)
|
|
502
547
|
|
|
548
|
+
// Dispatch an event from the host. Pass a name (with optional
|
|
549
|
+
// detail/options) for a bubbling CustomEvent, or a pre-built
|
|
550
|
+
// Event. Returns dispatchEvent's result.
|
|
551
|
+
ctx.emit('change', { value: 42 })
|
|
552
|
+
|
|
503
553
|
// Read a signal without creating a subscription.
|
|
504
554
|
const snap = ctx.peek(ctx.props.count)
|
|
505
555
|
|
|
@@ -626,7 +676,8 @@ define('theme-provider')
|
|
|
626
676
|
const theme = signal('light')
|
|
627
677
|
|
|
628
678
|
// Share with descendants; remove the entry on disconnect.
|
|
629
|
-
|
|
679
|
+
const cleanUp = provide(ctx.host, ThemeToken, theme())
|
|
680
|
+
ctx.onCleanup(cleanup)
|
|
630
681
|
|
|
631
682
|
// Re-provide on change. provide() updates the existing signal,
|
|
632
683
|
// so consumers that read this value re-run.
|
|
@@ -780,13 +831,87 @@ For a runnable version, see `example/render-demo.ts`. It keeps an editable
|
|
|
780
831
|
re-renders on a timer and reorders on demand to show that focus, caret, and
|
|
781
832
|
typed text survive: keyed nodes are reused and at most moved, never rebuilt.
|
|
782
833
|
|
|
783
|
-
|
|
834
|
+
---
|
|
835
|
+
|
|
836
|
+
### `microtags/util`
|
|
837
|
+
|
|
838
|
+
Helpers for reading raw attribute strings and running cleanup
|
|
839
|
+
functions. `withProps` uses these internally to coerce attribute values.
|
|
840
|
+
They are exported for when you need to read an attribute outside of the
|
|
841
|
+
prop layer.
|
|
842
|
+
|
|
843
|
+
```ts
|
|
844
|
+
import {
|
|
845
|
+
coerceNumber,
|
|
846
|
+
coerceString,
|
|
847
|
+
coerceBoolean,
|
|
848
|
+
coerceJson,
|
|
849
|
+
runCleanups,
|
|
850
|
+
} from 'microtags/util'
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
#### Coercion
|
|
784
854
|
|
|
855
|
+
Each coercion helper takes the raw `getAttribute` result -- a `string` or
|
|
856
|
+
`null` -- and returns a typed value. None of them throw.
|
|
785
857
|
|
|
858
|
+
```ts
|
|
859
|
+
function coerceNumber (raw:string | null):number
|
|
860
|
+
function coerceString (raw:string | null):string
|
|
861
|
+
function coerceBoolean (raw:string | null):boolean
|
|
862
|
+
function coerceJson<T = unknown> (raw:string | null):T | undefined
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
- `coerceNumber` -- `Number(raw)`, or `NaN` when the attribute is absent
|
|
866
|
+
or cannot be parsed.
|
|
867
|
+
- `coerceString` -- the value as-is; a missing attribute (`null`) becomes
|
|
868
|
+
the empty string `''`.
|
|
869
|
+
- `coerceBoolean` -- presence-based, matching the HTML boolean-attribute
|
|
870
|
+
convention: absent (`null`) is `false`, present is `true`, including the
|
|
871
|
+
empty string from `disabled=""`.
|
|
872
|
+
- `coerceJson` -- `JSON.parse(raw)`, or `undefined` when the attribute is
|
|
873
|
+
absent or not valid JSON. Pass a type parameter to annotate the result.
|
|
874
|
+
|
|
875
|
+
#### `runCleanups`
|
|
876
|
+
|
|
877
|
+
Runs every function in the array, even if some throw. After all have run
|
|
878
|
+
it re-throws the first error encountered, so one failing teardown cannot
|
|
879
|
+
skip the rest. A `Cleanup` is a no-argument teardown function, `() => void`.
|
|
880
|
+
|
|
881
|
+
```ts
|
|
882
|
+
function runCleanups (fns:Cleanup[]):void
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
#### `toAttributes`
|
|
886
|
+
|
|
887
|
+
Transform an object into an HTML attributes string. The object should be
|
|
888
|
+
like `{ attributeName: value }`. Handles boolean values by adding a string, eg
|
|
889
|
+
`{ disabled: true }` = `<button disabled>`. Arrays are converted to a list in
|
|
890
|
+
quotes, eg `{ class: ['abc', 'def'] }` = `<div class="abc def">`
|
|
891
|
+
|
|
892
|
+
```ts
|
|
893
|
+
type Attrs = Record<
|
|
894
|
+
string,
|
|
895
|
+
undefined|null|string|number|boolean|(string|number)[]
|
|
896
|
+
>
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Transform an object into an HTML attributes string. The object should be
|
|
900
|
+
* like `{ attributeName: value }`.
|
|
901
|
+
*
|
|
902
|
+
* @param {Attrs} attrs An object for the attributes.
|
|
903
|
+
* @returns {string} A string suitable for use as HTML attributes.
|
|
904
|
+
*/
|
|
905
|
+
function toAttributes (attrs:Attrs):string
|
|
906
|
+
```
|
|
786
907
|
|
|
787
908
|
---
|
|
788
909
|
|
|
789
|
-
## Divergence from nanotags
|
|
910
|
+
## Divergence from `nanotags`
|
|
911
|
+
|
|
912
|
+
### Reactivity primitive
|
|
913
|
+
|
|
914
|
+
`nanotags` uses `nanostores` atoms; `microtags` uses `alien-signals`.
|
|
790
915
|
|
|
791
916
|
| nanotags (nanostores) | microtags (alien-signals) |
|
|
792
917
|
|---|---|
|
|
@@ -795,5 +920,78 @@ typed text survive: keyed nodes are reused and at most moved, never rebuilt.
|
|
|
795
920
|
| `$count.set(1)` | `count(1)` |
|
|
796
921
|
| `ctx.props.$count` (store) | `ctx.props.count` (callable signal) |
|
|
797
922
|
|
|
798
|
-
Props declared with `withProps` are
|
|
799
|
-
|
|
923
|
+
Props declared with `withProps` are signals. There is no `$` prefix convention;
|
|
924
|
+
all prop names are plain identifiers.
|
|
925
|
+
|
|
926
|
+
### Effects + Subscriptions
|
|
927
|
+
|
|
928
|
+
In `nanotags`, `ctx.effect` takes the store(s) to watch
|
|
929
|
+
explicitly and hands the value to the callback:
|
|
930
|
+
|
|
931
|
+
```ts
|
|
932
|
+
// nanotags
|
|
933
|
+
ctx.effect(ctx.props.$count, count => {
|
|
934
|
+
ctx.refs.display.textContent = String(count)
|
|
935
|
+
})
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
In `microtags`, `ctx.effect` takes a zero-argument function and tracks whichever
|
|
939
|
+
signals are read inside it (the `alien-signals` model):
|
|
940
|
+
|
|
941
|
+
```ts
|
|
942
|
+
// microtags
|
|
943
|
+
ctx.effect(() => {
|
|
944
|
+
ctx.refs.display.textContent = String(ctx.props.count())
|
|
945
|
+
})
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
The read operation in `ctx.effect` subscribes to the signal, and runs on
|
|
949
|
+
any signal change. A read inside an effect that you do *not* want to track has
|
|
950
|
+
to go through [`peek` or `untracked`](#peek-and-untracked).
|
|
951
|
+
In nanotags `.get()` never subscribes, so there is no equivalent.
|
|
952
|
+
|
|
953
|
+
### Refs: `r.all` instead of `r.many`
|
|
954
|
+
|
|
955
|
+
The multi-element ref is `r.all()` in `microtags` and `r.many()` in `nanotags`.
|
|
956
|
+
The empty-match behavior also differs: `r.all()` returns an empty array when
|
|
957
|
+
nothing matches, whereas nanotags' `r.many()` throws. `r.one()` throws on a
|
|
958
|
+
missing element in both.
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
### Context API
|
|
962
|
+
|
|
963
|
+
The context API is shaped differently. See
|
|
964
|
+
[`microtags/context`](#microtagscontext).
|
|
965
|
+
|
|
966
|
+
| nanotags | microtags |
|
|
967
|
+
|---|---|
|
|
968
|
+
| `createContext<T>('name')` | `createContext<T>()`, no name |
|
|
969
|
+
| `token.provide(ctx, value)` | `provide(ctx.host, token, value)`, standalone, returns a cleanup |
|
|
970
|
+
| `withContexts({ theme: token })` | `withContexts(() => ({ theme: token }))`, a function |
|
|
971
|
+
| `token.consume(ctx, cb)` | `ctx.consume(token)`, returns value-or-`undefined` |
|
|
972
|
+
|
|
973
|
+
### Props
|
|
974
|
+
|
|
975
|
+
| nanotags | microtags |
|
|
976
|
+
|---|---|
|
|
977
|
+
| `p.json(schema, default)`, hydrated from a `<script type="application/json">` tag, not an attribute | `p.json<T>()`, type-only, parsed from the observed attribute |
|
|
978
|
+
| custom schema passed directly as the prop def | wrap it in `p.schema(validator)` |
|
|
979
|
+
| property-only via `{ schema, attribute: false }` | `p.prop(initial)` |
|
|
980
|
+
| nullable fallback `p.string(null)` | no null-fallback argument; a failed `p.schema` falls back to `undefined` |
|
|
981
|
+
|
|
982
|
+
### Not ported
|
|
983
|
+
|
|
984
|
+
These nanotags APIs have no microtags equivalent:
|
|
985
|
+
|
|
986
|
+
- `ctx.getElement` / `ctx.getElements` -- declare refs with `withRefs`, or
|
|
987
|
+
call `ctx.host.querySelector` directly.
|
|
988
|
+
- The `setup` mixin return value -- `setup` returns `void`; it does not
|
|
989
|
+
assign members back onto the element.
|
|
990
|
+
- The `define(name, setupFn)` two-argument shorthand -- always use the
|
|
991
|
+
builder chain ending in `.setup()`.
|
|
992
|
+
|
|
993
|
+
### Additions / New Features
|
|
994
|
+
|
|
995
|
+
* Serverside-compatible API -- see [serverside example](#serverside-example) --
|
|
996
|
+
we expose `.TAG` and `.refs` on your component, which can be imported in a
|
|
997
|
+
server environment.
|
|
@@ -40,12 +40,28 @@ function runCleanups(fns) {
|
|
|
40
40
|
if (caught) throw firstError;
|
|
41
41
|
}
|
|
42
42
|
__name(runCleanups, "runCleanups");
|
|
43
|
+
function toAttributes(attrs) {
|
|
44
|
+
return Object.keys(attrs).reduce((acc, k) => {
|
|
45
|
+
const value = attrs[k];
|
|
46
|
+
if (!value) return acc;
|
|
47
|
+
if (typeof value === "boolean") {
|
|
48
|
+
if (value) return (acc + ` ${k}`).trim();
|
|
49
|
+
return acc;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(value)) {
|
|
52
|
+
return acc + ` ${k}="${value.join(" ")}"`;
|
|
53
|
+
}
|
|
54
|
+
return (acc + ` ${k}="${value}"`).trim();
|
|
55
|
+
}, "");
|
|
56
|
+
}
|
|
57
|
+
__name(toAttributes, "toAttributes");
|
|
43
58
|
|
|
44
59
|
export {
|
|
45
60
|
coerceNumber,
|
|
46
61
|
coerceString,
|
|
47
62
|
coerceBoolean,
|
|
48
63
|
coerceJson,
|
|
49
|
-
runCleanups
|
|
64
|
+
runCleanups,
|
|
65
|
+
toAttributes
|
|
50
66
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-P4QHFKTJ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/util.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Coerce a raw attribute string to a number.\n * Returns NaN if the value cannot be parsed.\n */\nexport function coerceNumber (raw:string | null):number {\n return raw === null ? NaN : Number(raw)\n}\n\n/**\n * Coerce a raw attribute string to a string.\n * Converts null to empty string.\n */\nexport function coerceString (raw:string | null):string {\n return raw ?? ''\n}\n\n/**\n * Coerce a raw attribute string to a boolean.\n * Absence (null) is false; presence of any value (including '') is true.\n */\nexport function coerceBoolean (raw:string | null):boolean {\n return raw !== null\n}\n\n/**\n * Coerce a raw attribute string to a parsed JSON value.\n * Returns undefined if the value is null or cannot be parsed.\n */\nexport function coerceJson<T = unknown> (raw:string | null):T | undefined {\n if (raw === null) return undefined\n try {\n return JSON.parse(raw) as T\n } catch {\n return undefined\n }\n}\n\n/**\n * Run every cleanup in the list, ensuring all run even if some throw.\n * After all have run, re-throws the first error encountered.\n */\nexport function runCleanups (fns:(() => void)[]):void {\n let firstError:unknown\n let caught = false\n for (const fn of fns) {\n try {\n fn()\n } catch (err) {\n if (!caught) {\n firstError = err\n caught = true\n }\n }\n }\n if (caught) throw firstError\n}\n\nexport type Attrs = Record<string, undefined|null|string|number|boolean|(string|number)[]>\n\n/**\n * Transform an object into an HTML attributes string. The object should be\n * like `{ attributeName: value }`.\n *\n * @param {Attrs} attrs An object for the attributes.\n * @returns {string} A string suitable for use as HTML attributes.\n */\nexport function toAttributes (attrs:Attrs):string {\n return Object.keys(attrs).reduce((acc, k) => {\n const value = attrs[k]\n if (!value) return acc\n\n if (typeof value === 'boolean') {\n if (value) return (acc + ` ${k}`).trim()\n return acc\n }\n\n if (Array.isArray(value)) {\n return (acc + ` ${k}=\"${value.join(' ')}\"`)\n }\n\n return (acc + ` ${k}=\"${value}\"`).trim()\n }, '')\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAIO,SAAS,aAAc,KAA0B;AACpD,SAAO,QAAQ,OAAO,MAAM,OAAO,GAAG;AAC1C;AAFgB;AAQT,SAAS,aAAc,KAA0B;AACpD,SAAO,OAAO;AAClB;AAFgB;AAQT,SAAS,cAAe,KAA2B;AACtD,SAAO,QAAQ;AACnB;AAFgB;AAQT,SAAS,WAAyB,KAAiC;AACtE,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACzB,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAPgB;AAaT,SAAS,YAAa,KAAyB;AAClD,MAAI;AACJ,MAAI,SAAS;AACb,aAAW,MAAM,KAAK;AAClB,QAAI;AACA,SAAG;AAAA,IACP,SAAS,KAAK;AACV,UAAI,CAAC,QAAQ;AACT,qBAAa;AACb,iBAAS;AAAA,MACb;AAAA,IACJ;AAAA,EACJ;AACA,MAAI,OAAQ,OAAM;AACtB;AAdgB;AAyBT,SAAS,aAAc,OAAoB;AAC9C,SAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,KAAK,MAAM;AACzC,UAAM,QAAQ,MAAM,CAAC;AACrB,QAAI,CAAC,MAAO,QAAO;AAEnB,QAAI,OAAO,UAAU,WAAW;AAC5B,UAAI,MAAO,SAAQ,MAAM,IAAI,CAAC,IAAI,KAAK;AACvC,aAAO;AAAA,IACX;AAEA,QAAI,MAAM,QAAQ,KAAK,GAAG;AACtB,aAAQ,MAAM,IAAI,CAAC,KAAK,MAAM,KAAK,GAAG,CAAC;AAAA,IAC3C;AAEA,YAAQ,MAAM,IAAI,CAAC,KAAK,KAAK,KAAK,KAAK;AAAA,EAC3C,GAAG,EAAE;AACT;AAhBgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGR,YAAY,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAGR,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,MAAM,EACT,MAAM,YAAY,CAAA;AAEnB;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AAY3D,yCAAyC;AACzC,MAAM,WAAW,aAAa,CAAC,KAAK,SAAS,YAAY,GAAG,YAAY;IACpE,kDAAkD;IAClD,KAAK,EAAC,KAAK,CAAA;IACX,qDAAqD;IACrD,iBAAiB,EAAC,MAAM,EAAE,CAAA;IAC1B,qCAAqC;IACrC,IAAI,CAAC,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,oCAAoC;IACpC,QAAQ,CAAC,EAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/C,sDAAsD;IACtD,KAAK,EAAC,CAAC,GAAG,EAAC,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;CACpD;AAiCD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAS,YAAY,GAAG,YAAY,EAC7D,MAAM,EAAC,aAAa,CAAC,KAAK,CAAC,GAC7B,OAAO,WAAW,CAuHnB"}
|
package/dist/index.cjs
CHANGED
|
@@ -132,6 +132,14 @@ function makeSetupContext(host, props, refs, contexts, cleanups) {
|
|
|
132
132
|
);
|
|
133
133
|
});
|
|
134
134
|
},
|
|
135
|
+
emit(nameOrEvent, detail, options) {
|
|
136
|
+
const event = nameOrEvent instanceof Event ? nameOrEvent : new CustomEvent(nameOrEvent, {
|
|
137
|
+
bubbles: true,
|
|
138
|
+
...options,
|
|
139
|
+
detail
|
|
140
|
+
});
|
|
141
|
+
return host.dispatchEvent(event);
|
|
142
|
+
},
|
|
135
143
|
effect(fn) {
|
|
136
144
|
const dispose = (0, import_alien_signals.effect)(fn);
|
|
137
145
|
cleanups.push(dispose);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/reactivity.ts", "../src/util.ts", "../src/context.ts", "../src/setup-context.ts", "../src/factory.ts", "../src/builders.ts"],
|
|
4
|
-
"sourcesContent": ["export { peek, untracked } from './reactivity.js'\nexport { define } from './builders.js'\n", "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", "import type { Cleanup } from './types.js'\n\n/**\n * Coerce a raw attribute string to a number.\n * Returns NaN if the value cannot be parsed.\n */\nexport function coerceNumber (raw:string | null):number {\n return raw === null ? NaN : Number(raw)\n}\n\n/**\n * Coerce a raw attribute string to a string.\n * Converts null to empty string.\n */\nexport function coerceString (raw:string | null):string {\n return raw ?? ''\n}\n\n/**\n * Coerce a raw attribute string to a boolean.\n * Absence (null) is false; presence of any value (including '') is true.\n */\nexport function coerceBoolean (raw:string | null):boolean {\n return raw !== null\n}\n\n/**\n * Coerce a raw attribute string to a parsed JSON value.\n * Returns undefined if the value is null or cannot be parsed.\n */\nexport function coerceJson<T = unknown> (raw:string | null):T | undefined {\n if (raw === null) return undefined\n try {\n return JSON.parse(raw) as T\n } catch {\n return undefined\n }\n}\n\n/**\n * Run every cleanup in the list, ensuring all run even if some throw.\n * After all have run, re-throws the first error encountered.\n */\nexport function runCleanups (fns:Cleanup[]):void {\n let firstError:unknown\n let caught = false\n for (const fn of fns) {\n try {\n fn()\n } catch (err) {\n if (!caught) {\n firstError = err\n caught = true\n }\n }\n }\n if (caught) throw firstError\n}\n", "import { signal } from './reactivity.js'\nimport type { ContextToken, Signal } from './types.js'\n\n// Provider storage: element -> (contextId -> Signal)\nconst providerStorage = new WeakMap<Element, Map<symbol, Signal<unknown>>>()\n\n// Pending consumers waiting for a context by id\nconst pendingCallbacks = new Map<symbol, Set<() => void>>()\n\n/**\n * Create a new context token.\n * Each token uniquely identifies a type of shared context.\n */\nexport function createContext<T> ():ContextToken<T> {\n return { id: Symbol('microtag-context') }\n}\n\n/**\n * Provide a context value from an element to its descendants.\n * Returns a cleanup function that removes the provided value.\n */\nexport function provide<T> (\n element:Element,\n token:ContextToken<T>,\n value:T\n):() => void {\n let map = providerStorage.get(element)\n if (!map) {\n map = new Map()\n providerStorage.set(element, map)\n }\n\n const existing = map.get(token.id) as Signal<T> | undefined\n if (existing) {\n existing(value)\n } else {\n const sig = signal(value) as unknown as Signal<T>\n map.set(token.id, sig as Signal<unknown>)\n }\n\n notifyPending(token.id)\n\n return () => {\n const m = providerStorage.get(element)\n if (m) {\n m.delete(token.id)\n if (m.size === 0) providerStorage.delete(element)\n }\n }\n}\n\n/**\n * Walk up the DOM from element to find the nearest provider signal.\n * Returns the signal (not the value) so callers can subscribe to changes.\n */\nexport function resolveContextSignal<T> (\n element:Element,\n token:ContextToken<T>\n):Signal<T> | undefined {\n let current:Element | null = element.parentElement\n while (current) {\n const map = providerStorage.get(current)\n if (map && map.has(token.id)) {\n return map.get(token.id) as Signal<T>\n }\n current = current.parentElement\n }\n return undefined\n}\n\n/**\n * Register a callback to run when the given context becomes available.\n * Returns a cleanup function to unregister.\n */\nexport function onContextAvailable (\n id:symbol,\n callback:() => void\n):() => void {\n let set = pendingCallbacks.get(id)\n if (!set) {\n set = new Set()\n pendingCallbacks.set(id, set)\n }\n set.add(callback)\n return () => { pendingCallbacks.get(id)?.delete(callback) }\n}\n\nfunction notifyPending (id:symbol):void {\n const set = pendingCallbacks.get(id)\n if (set) {\n for (const cb of set) cb()\n }\n}\n", "import { effect, peek } from './reactivity.js'\nimport { resolveContextSignal } from './context.js'\nimport type {\n SetupContext,\n Cleanup,\n Signal,\n PropsSignals,\n PropDef,\n ContextToken,\n} from './types.js'\n\n/**\n * Build the ctx object passed to a component's setup() callback.\n * The cleanups array is mutated in place so factory.ts can drain it\n * on disconnect without copying.\n */\nexport function makeSetupContext<\n Props extends Record<string, PropDef> = Record<string, PropDef>,\n> (\n host:HTMLElement,\n props:PropsSignals<Props>,\n refs:Record<string, Element | Element[]>,\n contexts:Record<string, unknown>,\n cleanups:Cleanup[]\n):SetupContext<Props, any, any> {\n return {\n host,\n props,\n refs,\n contexts,\n\n peek,\n\n on (target, type, handler, options?) {\n target.addEventListener(\n type as string,\n handler as EventListener,\n options\n )\n cleanups.push(() => {\n target.removeEventListener(\n type as string,\n handler as EventListener,\n options\n )\n })\n },\n\n effect (fn) {\n const dispose = effect(fn)\n cleanups.push(dispose)\n },\n\n bind (source, control, opts) {\n const input = control instanceof HTMLInputElement ?\n control :\n undefined\n let prop = 'value'\n let autoEvent = 'change'\n if (input?.type === 'checkbox') {\n prop = 'checked'\n } else if (input?.type === 'number' ||\n input?.type === 'range') {\n prop = 'valueAsNumber'\n autoEvent = 'input'\n } else if (input || control instanceof HTMLTextAreaElement) {\n autoEvent = 'input'\n }\n\n const boundProp = opts?.prop ?? prop\n const event = opts ? opts.event : autoEvent\n const el = control as unknown as Record<string, unknown>\n\n if (event) {\n const handler = () => {\n const writable = source as Signal<unknown>\n writable(el[boundProp])\n }\n control.addEventListener(event, handler)\n cleanups.push(() => {\n control.removeEventListener(event, handler)\n })\n }\n\n const dispose = effect(() => {\n el[boundProp] = source()\n })\n cleanups.push(dispose)\n },\n\n onCleanup (fn) {\n cleanups.push(fn)\n },\n\n consume<T> (token:ContextToken<T>):T | undefined {\n const sig = resolveContextSignal(host, token)\n return sig ? sig() : undefined\n },\n }\n}\n", "import { signal } from './reactivity.js'\nimport { runCleanups } from './util.js'\nimport { makeSetupContext } from './setup-context.js'\nimport {\n resolveContextSignal,\n onContextAvailable,\n} from './context.js'\nimport type {\n PropsSignals,\n Signal,\n SetupContext,\n Cleanup,\n Coercer,\n ContextToken,\n RefDef,\n} from './types.js'\n\n/**\n * Map of prop name to coercer function.\n * The factory accepts coercers exclusively; Standard Schema support is\n * layered on top in the withProps builder (US-005).\n */\nexport type FactoryProps = Record<string, Coercer<unknown>>\n\n/**\n * The class to extend for custom elements. In the browser this is the\n * real HTMLElement; in Node (e.g. reading `.TAG` for SSR) it falls back\n * to an empty stub so the class can be defined without a DOM. The stub\n * is never instantiated or registered outside the browser.\n */\nconst HTMLElementBase = typeof HTMLElement !== 'undefined' ?\n HTMLElement :\n (class {} as unknown as typeof HTMLElement)\n\n/** Configuration passed to factory(). */\nexport interface FactoryConfig<Props extends FactoryProps = FactoryProps> {\n /** Coercer for each observed attribute / prop. */\n props:Props\n /** Attribute names to pass to observedAttributes. */\n observedAttrNames:string[]\n /** Ref definitions keyed by name. */\n refs?:Record<string, RefDef>\n /** Context tokens keyed by name. */\n contexts?:Record<string, ContextToken<unknown>>\n /** Setup callback receiving the component context. */\n setup:(ctx:SetupContext<Props, any, any>) => void\n}\n\n/**\n * Collect resolved DOM refs from within a host element.\n * Throws if any single-ref element is missing.\n */\nfunction collectRefs (\n host:HTMLElement,\n defs:Record<string, RefDef>\n):Record<string, Element | Element[]> {\n const result:Record<string, Element | Element[]> = {}\n const missing:string[] = []\n for (const [key, def] of Object.entries(defs)) {\n const sel = def.selector ?? `[data-ref=\"${key}\"]`\n if (def._microtag === 'ref:all') {\n result[key] = Array.from(host.querySelectorAll(sel))\n } else {\n const el = host.querySelector(sel)\n if (!el) {\n missing.push(key)\n } else {\n result[key] = el\n }\n }\n }\n if (missing.length > 0) {\n throw new Error(\n `${host.tagName}: missing refs: ${missing.join(', ')}`\n )\n }\n return result\n}\n\n/**\n * Create an HTMLElement subclass with the microtags lifecycle.\n * The returned class has no Shadow DOM, tracks its own prop signals,\n * and runs setup() on connect / cleanups on disconnect.\n */\nexport function factory<Props extends FactoryProps = FactoryProps> (\n config:FactoryConfig<Props>\n):typeof HTMLElement {\n const {\n props: propDefs,\n observedAttrNames,\n setup,\n refs: refDefs = {},\n contexts: ctxDefs = {},\n } = config\n\n class MicrotagElement extends HTMLElementBase {\n static get observedAttributes () { return observedAttrNames }\n\n _props:Record<string, Signal<unknown>> = {}\n _cleanups:Cleanup[] = []\n\n constructor () {\n super()\n for (const [name, coercer] of Object.entries(propDefs)) {\n this._props[name] = signal(coercer(null))\n }\n }\n\n connectedCallback () {\n // Start a fresh cleanup scope for each connection cycle.\n this._cleanups = []\n\n // Hydrate prop signals from attributes; preserve any\n // programmatically-set value when the attribute is absent.\n for (const [name, coercer] of Object.entries(propDefs)) {\n const attrVal = this.getAttribute(name)\n if (attrVal !== null) {\n (this._props[name] as Signal<unknown>)(coercer(attrVal))\n }\n }\n\n const cleanups = this._cleanups\n const props = this._props as PropsSignals<Props>\n\n // Reactive Proxy: reading a key inside a ctx.effect creates\n // a subscription to the provider's alien-signals signal.\n const contexts = new Proxy({} as Record<string, unknown>, {\n get: (_target, key) => {\n if (typeof key !== 'string') return undefined\n const token = ctxDefs[key]\n if (!token) return undefined\n const sig = resolveContextSignal(this, token)\n return sig ? sig() : undefined\n },\n has: (_target, key) => {\n if (typeof key !== 'string') return false\n return key in ctxDefs\n },\n })\n\n let setupRan = false\n // Tracks pending-context cancel functions so they are\n // removed from the global registry when setup runs or\n // when the element disconnects.\n const cancelCallbacks:(() => void)[] = []\n\n const tryRunSetup = ():void => {\n if (setupRan) return\n for (const token of Object.values(ctxDefs)) {\n if (!resolveContextSignal(this, token)) return\n }\n setupRan = true\n for (const cancel of cancelCallbacks) cancel()\n cancelCallbacks.length = 0\n\n const refs = collectRefs(this, refDefs)\n const ctx = makeSetupContext(\n this, props, refs, contexts, cleanups\n )\n setup(ctx)\n }\n\n // Deferred variant: skip if element was disconnected before\n // the context became available.\n const tryRunSetupIfConnected = ():void => {\n if (!this.isConnected) return\n tryRunSetup()\n }\n\n // Register pending listeners for any missing contexts.\n for (const token of Object.values(ctxDefs)) {\n if (!resolveContextSignal(this, token)) {\n const cancel = onContextAvailable(\n token.id, tryRunSetupIfConnected\n )\n cancelCallbacks.push(cancel)\n // Also cancel on disconnect so we don't leak.\n cleanups.push(cancel)\n }\n }\n\n tryRunSetup()\n }\n\n attributeChangedCallback (\n name:string,\n _old:string | null,\n next:string | null\n ) {\n const coercer = propDefs[name]\n if (coercer !== undefined && this._props[name] !== undefined) {\n (this._props[name] as Signal<unknown>)(coercer(next))\n }\n }\n\n disconnectedCallback () {\n // Snapshot and clear BEFORE running so re-entrant calls are safe\n // and the array is always empty after this returns (or throws).\n const fns = this._cleanups\n this._cleanups = []\n runCleanups(fns)\n }\n }\n\n return MicrotagElement\n}\n", "import type { StandardSchemaV1 } from '@standard-schema/spec'\nimport type {\n PropDef,\n PropertyOnlyProp,\n SetupContext,\n Coercer,\n RefDef,\n SingleRefDef,\n MultipleRefDef,\n RefsMap,\n ContextToken,\n ContextsMap,\n} from './types.js'\nimport {\n coerceNumber,\n coerceString,\n coerceBoolean,\n coerceJson,\n} from './util.js'\nimport { factory } from './factory.js'\n\nfunction isPropOnly (def:unknown):def is PropertyOnlyProp<unknown> {\n return (\n typeof def === 'object' &&\n def !== null &&\n '_microtag' in def &&\n (def as { _microtag: unknown })._microtag === 'prop'\n )\n}\n\nfunction isStandardSchema (def:unknown):def is StandardSchemaV1 {\n return (\n typeof def === 'object' &&\n def !== null &&\n '~standard' in def\n )\n}\n\nfunction normalizePropDef (\n name:string,\n def:PropDef<unknown>\n):Coercer<unknown> {\n if (isPropOnly(def)) {\n return (_raw:string | null) => def.initial\n }\n if (isStandardSchema(def)) {\n const schema = def as StandardSchemaV1\n return (raw:string | null):unknown => {\n const result = schema['~standard'].validate(raw)\n if (result instanceof Promise) {\n throw new TypeError(\n `withProps: async schemas are not supported (prop \"${name}\")`\n )\n }\n if (result.issues) return undefined\n return result.value\n }\n }\n return def as Coercer<unknown>\n}\n\n/** The DSL object passed to the withProps callback. */\nexport type PropDSL = {\n number():Coercer<number>\n string():Coercer<string>\n boolean():Coercer<boolean>\n json<T>():Coercer<T | undefined>\n schema<T>(validator:StandardSchemaV1<unknown, T>):StandardSchemaV1<unknown, T>\n prop<T>(initial:T):PropertyOnlyProp<T>\n}\n\nexport const propDSL:PropDSL = {\n number: () => coerceNumber,\n string: () => coerceString,\n boolean: () => coerceBoolean,\n json: <T>() => coerceJson as Coercer<T | undefined>,\n schema: <T>(v:StandardSchemaV1<unknown, T>) => v,\n prop: <T>(initial:T):PropertyOnlyProp<T> => (\n { _microtag: 'prop', initial }\n ),\n}\n\n/**\n * DSL object passed to the withRefs callback.\n * Call `r.one()` for a single element or `r.all()` for multiple. Pass a\n * CSS selector to query by it, or omit it to match `[data-ref=\"<key>\"]`.\n *\n * Element typing:\n * - `r.one()` defaults to `HTMLElement`.\n * - `r.one<T>()` sets the type and keeps the `[data-ref]` selector.\n * - `r.one('button')` infers the type from the tag AND queries by that\n * tag, exactly like `document.querySelector('button')`.\n */\nexport type RefsDSL = {\n one<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):SingleRefDef<HTMLElementTagNameMap[K]>\n one<T extends HTMLElement = HTMLElement>(selector?:string):SingleRefDef<T>\n\n all<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):MultipleRefDef<HTMLElementTagNameMap[K]>\n all<T extends HTMLElement = HTMLElement>(selector?:string):MultipleRefDef<T>\n}\n\nexport const refsDSL:RefsDSL = {\n one: ((selector?:string):SingleRefDef => (\n { _microtag: 'ref:one', selector }\n )) as RefsDSL['one'],\n all: ((selector?:string):MultipleRefDef => (\n { _microtag: 'ref:all', selector }\n )) as RefsDSL['all'],\n}\n\n/**\n * DSL object passed to the withContexts callback.\n * Currently a no-op placeholder; the user references imported\n * context tokens directly in the returned record.\n */\nexport type ContextDSL = Record<never, never>\nconst contextDSL:ContextDSL = {}\n\n/**\n * Maps each declared ref key to its own name as a string literal. Exposed\n * as the static `refs` on a registered element so server-rendered templates\n * can fill in `data-ref` values without hardcoding the names, e.g.\n * `data-ref=\"${myCounter.refs.dec}\"`.\n */\nexport type RefNames<RefDefs extends Record<string, RefDef>> = {\n readonly [K in keyof RefDefs]:K & string\n}\n\n/**\n * A registered custom element class that also exposes, as static members,\n * the tag name it was registered under (`TAG`) and the names of its\n * declared refs (`refs`).\n */\nexport type MicrotagElementClass<\n RefDefs extends Record<string, RefDef> = Record<never, never>\n> = typeof HTMLElement & {\n /** The custom element tag name, e.g. 'my-counter'. */\n readonly TAG:string\n /**\n * The declared ref names, each mapping to its own `data-ref` string.\n * Lets server-rendered markup reference refs by key instead of a magic\n * string: `myCounter.refs.dec`.\n */\n readonly refs:RefNames<RefDefs>\n}\n\n/**\n * Fluent builder that accumulates props/refs/contexts config\n * before registering a custom element via `.setup()`.\n */\nexport class ComponentBuilder<\n Props extends Record<string, PropDef> = Record<never, never>,\n RefDefs extends Record<string, RefDef> = Record<never, never>,\n CtxDefs extends Record<string, ContextToken<unknown>> =\n Record<never, never>,\n> {\n private readonly _coercers:Record<string, Coercer<unknown>>\n private readonly _observed:string[]\n private readonly _refDefs:Record<string, RefDef>\n private readonly _ctxDefs:Record<string, ContextToken<unknown>>\n\n constructor (\n readonly tagName:string,\n coercers:Record<string, Coercer<unknown>> = {},\n observed:string[] = [],\n refDefs:Record<string, RefDef> = {},\n ctxDefs:Record<string, ContextToken<unknown>> = {}\n ) {\n this._coercers = coercers\n this._observed = observed\n this._refDefs = refDefs\n this._ctxDefs = ctxDefs\n }\n\n /**\n * The custom element tag name, e.g. 'my-counter'. Available at every\n * point in the fluent chain since each builder method returns a new\n * builder carrying the same tag name.\n */\n get TAG ():string {\n return this.tagName\n }\n\n withProps<P extends Record<string, PropDef>> (\n fn:(p:PropDSL) => P\n ):ComponentBuilder<P, RefDefs, CtxDefs> {\n const defs = fn(propDSL)\n const coercers:Record<string, Coercer<unknown>> = {}\n const observed:string[] = []\n\n for (const [name, def] of Object.entries(defs)) {\n coercers[name] = normalizePropDef(name, def as PropDef<unknown>)\n if (!isPropOnly(def)) {\n observed.push(name)\n }\n }\n\n return new ComponentBuilder<P, RefDefs, CtxDefs>(\n this.tagName, coercers, observed, this._refDefs, this._ctxDefs\n )\n }\n\n withRefs<R extends Record<string, RefDef>> (\n fn:(r:RefsDSL) => R\n ):ComponentBuilder<Props, R, CtxDefs> {\n const defs = fn(refsDSL)\n return new ComponentBuilder<Props, R, CtxDefs>(\n this.tagName,\n this._coercers,\n this._observed,\n defs,\n this._ctxDefs\n )\n }\n\n withContexts<C extends Record<string, ContextToken<unknown>>> (\n fn:(c:ContextDSL) => C\n ):ComponentBuilder<Props, RefDefs, C> {\n const defs = fn(contextDSL)\n return new ComponentBuilder<Props, RefDefs, C>(\n this.tagName,\n this._coercers,\n this._observed,\n this._refDefs,\n defs\n )\n }\n\n setup (\n fn:(ctx:SetupContext<\n Props,\n RefsMap<RefDefs>,\n ContextsMap<CtxDefs>\n >) => void\n ):MicrotagElementClass<RefDefs> {\n const El = factory({\n props: this._coercers,\n observedAttrNames: this._observed,\n refs: this._refDefs,\n contexts: this._ctxDefs,\n setup: fn as any,\n })\n Object.defineProperty(El, 'TAG', {\n value: this.tagName,\n enumerable: true,\n })\n\n // Expose each ref key as its own `data-ref` name so server-rendered\n // markup can reference refs by key instead of a hardcoded string.\n const refNames:Record<string, string> = {}\n for (const key of Object.keys(this._refDefs)) {\n refNames[key] = key\n }\n Object.defineProperty(El, 'refs', {\n value: Object.freeze(refNames),\n enumerable: true,\n })\n\n if (typeof customElements !== 'undefined') {\n customElements.define(this.tagName, El)\n }\n return El as MicrotagElementClass<RefDefs>\n }\n}\n\n/** Create a new component builder for the given tag name. */\nexport function define (tagName:string):ComponentBuilder {\n return new ComponentBuilder(tagName)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAKO;AAWA,SAAS,UAAc,IAAc;AACxC,QAAM,WAAO,mCAAa,MAAS;AACnC,MAAI;AACA,WAAO,GAAG;AAAA,EACd,UAAE;AACE,2CAAa,IAAI;AAAA,EACrB;AACJ;AAPgB;AAaT,SAAS,KAAS,KAAiB;AACtC,SAAO,UAAU,MAAM,IAAI,CAAC;AAChC;AAFgB;;;
|
|
4
|
+
"sourcesContent": ["export { peek, untracked } from './reactivity.js'\nexport { define } from './builders.js'\n", "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", "/**\n * Coerce a raw attribute string to a number.\n * Returns NaN if the value cannot be parsed.\n */\nexport function coerceNumber (raw:string | null):number {\n return raw === null ? NaN : Number(raw)\n}\n\n/**\n * Coerce a raw attribute string to a string.\n * Converts null to empty string.\n */\nexport function coerceString (raw:string | null):string {\n return raw ?? ''\n}\n\n/**\n * Coerce a raw attribute string to a boolean.\n * Absence (null) is false; presence of any value (including '') is true.\n */\nexport function coerceBoolean (raw:string | null):boolean {\n return raw !== null\n}\n\n/**\n * Coerce a raw attribute string to a parsed JSON value.\n * Returns undefined if the value is null or cannot be parsed.\n */\nexport function coerceJson<T = unknown> (raw:string | null):T | undefined {\n if (raw === null) return undefined\n try {\n return JSON.parse(raw) as T\n } catch {\n return undefined\n }\n}\n\n/**\n * Run every cleanup in the list, ensuring all run even if some throw.\n * After all have run, re-throws the first error encountered.\n */\nexport function runCleanups (fns:(() => void)[]):void {\n let firstError:unknown\n let caught = false\n for (const fn of fns) {\n try {\n fn()\n } catch (err) {\n if (!caught) {\n firstError = err\n caught = true\n }\n }\n }\n if (caught) throw firstError\n}\n\nexport type Attrs = Record<string, undefined|null|string|number|boolean|(string|number)[]>\n\n/**\n * Transform an object into an HTML attributes string. The object should be\n * like `{ attributeName: value }`.\n *\n * @param {Attrs} attrs An object for the attributes.\n * @returns {string} A string suitable for use as HTML attributes.\n */\nexport function toAttributes (attrs:Attrs):string {\n return Object.keys(attrs).reduce((acc, k) => {\n const value = attrs[k]\n if (!value) return acc\n\n if (typeof value === 'boolean') {\n if (value) return (acc + ` ${k}`).trim()\n return acc\n }\n\n if (Array.isArray(value)) {\n return (acc + ` ${k}=\"${value.join(' ')}\"`)\n }\n\n return (acc + ` ${k}=\"${value}\"`).trim()\n }, '')\n}\n", "import { signal } from './reactivity.js'\nimport type { ContextToken, Signal } from './types.js'\n\n// Provider storage: element -> (contextId -> Signal)\nconst providerStorage = new WeakMap<Element, Map<symbol, Signal<unknown>>>()\n\n// Pending consumers waiting for a context by id\nconst pendingCallbacks = new Map<symbol, Set<() => void>>()\n\n/**\n * Create a new context token.\n * Each token uniquely identifies a type of shared context.\n */\nexport function createContext<T> ():ContextToken<T> {\n return { id: Symbol('microtag-context') }\n}\n\n/**\n * Provide a context value from an element to its descendants.\n * Returns a cleanup function that removes the provided value.\n */\nexport function provide<T> (\n element:Element,\n token:ContextToken<T>,\n value:T\n):() => void {\n let map = providerStorage.get(element)\n if (!map) {\n map = new Map()\n providerStorage.set(element, map)\n }\n\n const existing = map.get(token.id) as Signal<T> | undefined\n if (existing) {\n existing(value)\n } else {\n const sig = signal(value) as unknown as Signal<T>\n map.set(token.id, sig as Signal<unknown>)\n }\n\n notifyPending(token.id)\n\n return () => {\n const m = providerStorage.get(element)\n if (m) {\n m.delete(token.id)\n if (m.size === 0) providerStorage.delete(element)\n }\n }\n}\n\n/**\n * Walk up the DOM from element to find the nearest provider signal.\n * Returns the signal (not the value) so callers can subscribe to changes.\n */\nexport function resolveContextSignal<T> (\n element:Element,\n token:ContextToken<T>\n):Signal<T> | undefined {\n let current:Element | null = element.parentElement\n while (current) {\n const map = providerStorage.get(current)\n if (map && map.has(token.id)) {\n return map.get(token.id) as Signal<T>\n }\n current = current.parentElement\n }\n return undefined\n}\n\n/**\n * Register a callback to run when the given context becomes available.\n * Returns a cleanup function to unregister.\n */\nexport function onContextAvailable (\n id:symbol,\n callback:() => void\n):() => void {\n let set = pendingCallbacks.get(id)\n if (!set) {\n set = new Set()\n pendingCallbacks.set(id, set)\n }\n set.add(callback)\n return () => { pendingCallbacks.get(id)?.delete(callback) }\n}\n\nfunction notifyPending (id:symbol):void {\n const set = pendingCallbacks.get(id)\n if (set) {\n for (const cb of set) cb()\n }\n}\n", "import { effect, peek } from './reactivity.js'\nimport { resolveContextSignal } from './context.js'\nimport type {\n SetupContext,\n Signal,\n PropsSignals,\n PropDef,\n ContextToken,\n} from './types.js'\n\n/**\n * Build the ctx object passed to a component's setup() callback.\n * The cleanups array is mutated in place so factory.ts can drain it\n * on disconnect without copying.\n */\nexport function makeSetupContext<\n Props extends Record<string, PropDef> = Record<string, PropDef>,\n> (\n host:HTMLElement,\n props:PropsSignals<Props>,\n refs:Record<string, Element | Element[]>,\n contexts:Record<string, unknown>,\n cleanups:(() => void)[]\n):SetupContext<Props, any, any> {\n return {\n host,\n props,\n refs,\n contexts,\n\n peek,\n\n on (target, type, handler, options?) {\n target.addEventListener(\n type as string,\n handler as EventListener,\n options\n )\n cleanups.push(() => {\n target.removeEventListener(\n type as string,\n handler as EventListener,\n options\n )\n })\n },\n\n emit (\n nameOrEvent:Event | string,\n detail?:unknown,\n options?:Omit<CustomEventInit, 'detail'>\n ):boolean {\n const event = nameOrEvent instanceof Event ?\n nameOrEvent :\n new CustomEvent(nameOrEvent, {\n bubbles: true,\n ...options,\n detail,\n })\n return host.dispatchEvent(event)\n },\n\n effect (fn) {\n const dispose = effect(fn)\n cleanups.push(dispose)\n },\n\n bind (source, control, opts) {\n const input = control instanceof HTMLInputElement ?\n control :\n undefined\n let prop = 'value'\n let autoEvent = 'change'\n if (input?.type === 'checkbox') {\n prop = 'checked'\n } else if (input?.type === 'number' ||\n input?.type === 'range') {\n prop = 'valueAsNumber'\n autoEvent = 'input'\n } else if (input || control instanceof HTMLTextAreaElement) {\n autoEvent = 'input'\n }\n\n const boundProp = opts?.prop ?? prop\n const event = opts ? opts.event : autoEvent\n const el = control as unknown as Record<string, unknown>\n\n if (event) {\n const handler = () => {\n const writable = source as Signal<unknown>\n writable(el[boundProp])\n }\n control.addEventListener(event, handler)\n cleanups.push(() => {\n control.removeEventListener(event, handler)\n })\n }\n\n const dispose = effect(() => {\n el[boundProp] = source()\n })\n cleanups.push(dispose)\n },\n\n onCleanup (fn) {\n cleanups.push(fn)\n },\n\n consume<T> (token:ContextToken<T>):T | undefined {\n const sig = resolveContextSignal(host, token)\n return sig ? sig() : undefined\n },\n }\n}\n", "import { signal } from './reactivity.js'\nimport { runCleanups } from './util.js'\nimport { makeSetupContext } from './setup-context.js'\nimport {\n resolveContextSignal,\n onContextAvailable,\n} from './context.js'\nimport type {\n PropsSignals,\n Signal,\n SetupContext,\n Coercer,\n ContextToken,\n RefDef,\n} from './types.js'\n\n/**\n * Map of prop name to coercer function.\n * The factory accepts coercers exclusively; Standard Schema support is\n * layered on top in the withProps builder (US-005).\n */\nexport type FactoryProps = Record<string, Coercer<unknown>>\n\n/**\n * The class to extend for custom elements. In the browser this is the\n * real HTMLElement; in Node (e.g. reading `.TAG` for SSR) it falls back\n * to an empty stub so the class can be defined without a DOM. The stub\n * is never instantiated or registered outside the browser.\n */\nconst HTMLElementBase = typeof HTMLElement !== 'undefined' ?\n HTMLElement :\n (class {} as unknown as typeof HTMLElement)\n\n/** Configuration passed to factory(). */\nexport interface FactoryConfig<Props extends FactoryProps = FactoryProps> {\n /** Coercer for each observed attribute / prop. */\n props:Props\n /** Attribute names to pass to observedAttributes. */\n observedAttrNames:string[]\n /** Ref definitions keyed by name. */\n refs?:Record<string, RefDef>\n /** Context tokens keyed by name. */\n contexts?:Record<string, ContextToken<unknown>>\n /** Setup callback receiving the component context. */\n setup:(ctx:SetupContext<Props, any, any>) => void\n}\n\n/**\n * Collect resolved DOM refs from within a host element.\n * Throws if any single-ref element is missing.\n */\nfunction collectRefs (\n host:HTMLElement,\n defs:Record<string, RefDef>\n):Record<string, Element | Element[]> {\n const result:Record<string, Element | Element[]> = {}\n const missing:string[] = []\n for (const [key, def] of Object.entries(defs)) {\n const sel = def.selector ?? `[data-ref=\"${key}\"]`\n if (def._microtag === 'ref:all') {\n result[key] = Array.from(host.querySelectorAll(sel))\n } else {\n const el = host.querySelector(sel)\n if (!el) {\n missing.push(key)\n } else {\n result[key] = el\n }\n }\n }\n if (missing.length > 0) {\n throw new Error(\n `${host.tagName}: missing refs: ${missing.join(', ')}`\n )\n }\n return result\n}\n\n/**\n * Create an HTMLElement subclass with the microtags lifecycle.\n * The returned class has no Shadow DOM, tracks its own prop signals,\n * and runs setup() on connect / cleanups on disconnect.\n */\nexport function factory<Props extends FactoryProps = FactoryProps> (\n config:FactoryConfig<Props>\n):typeof HTMLElement {\n const {\n props: propDefs,\n observedAttrNames,\n setup,\n refs: refDefs = {},\n contexts: ctxDefs = {},\n } = config\n\n class MicrotagElement extends HTMLElementBase {\n static get observedAttributes () { return observedAttrNames }\n\n _props:Record<string, Signal<unknown>> = {}\n _cleanups:(() => void)[] = []\n\n constructor () {\n super()\n for (const [name, coercer] of Object.entries(propDefs)) {\n this._props[name] = signal(coercer(null))\n }\n }\n\n connectedCallback () {\n // Start a fresh cleanup scope for each connection cycle.\n this._cleanups = []\n\n // Hydrate prop signals from attributes; preserve any\n // programmatically-set value when the attribute is absent.\n for (const [name, coercer] of Object.entries(propDefs)) {\n const attrVal = this.getAttribute(name)\n if (attrVal !== null) {\n (this._props[name] as Signal<unknown>)(coercer(attrVal))\n }\n }\n\n const cleanups = this._cleanups\n const props = this._props as PropsSignals<Props>\n\n // Reactive Proxy: reading a key inside a ctx.effect creates\n // a subscription to the provider's alien-signals signal.\n const contexts = new Proxy({} as Record<string, unknown>, {\n get: (_target, key) => {\n if (typeof key !== 'string') return undefined\n const token = ctxDefs[key]\n if (!token) return undefined\n const sig = resolveContextSignal(this, token)\n return sig ? sig() : undefined\n },\n has: (_target, key) => {\n if (typeof key !== 'string') return false\n return key in ctxDefs\n },\n })\n\n let setupRan = false\n // Tracks pending-context cancel functions so they are\n // removed from the global registry when setup runs or\n // when the element disconnects.\n const cancelCallbacks:(() => void)[] = []\n\n const tryRunSetup = ():void => {\n if (setupRan) return\n for (const token of Object.values(ctxDefs)) {\n if (!resolveContextSignal(this, token)) return\n }\n setupRan = true\n for (const cancel of cancelCallbacks) cancel()\n cancelCallbacks.length = 0\n\n const refs = collectRefs(this, refDefs)\n const ctx = makeSetupContext(\n this, props, refs, contexts, cleanups\n )\n setup(ctx)\n }\n\n // Deferred variant: skip if element was disconnected before\n // the context became available.\n const tryRunSetupIfConnected = ():void => {\n if (!this.isConnected) return\n tryRunSetup()\n }\n\n // Register pending listeners for any missing contexts.\n for (const token of Object.values(ctxDefs)) {\n if (!resolveContextSignal(this, token)) {\n const cancel = onContextAvailable(\n token.id, tryRunSetupIfConnected\n )\n cancelCallbacks.push(cancel)\n // Also cancel on disconnect so we don't leak.\n cleanups.push(cancel)\n }\n }\n\n tryRunSetup()\n }\n\n attributeChangedCallback (\n name:string,\n _old:string | null,\n next:string | null\n ) {\n const coercer = propDefs[name]\n if (coercer !== undefined && this._props[name] !== undefined) {\n (this._props[name] as Signal<unknown>)(coercer(next))\n }\n }\n\n disconnectedCallback () {\n // Snapshot and clear BEFORE running so re-entrant calls are safe\n // and the array is always empty after this returns (or throws).\n const fns = this._cleanups\n this._cleanups = []\n runCleanups(fns)\n }\n }\n\n return MicrotagElement\n}\n", "import type { StandardSchemaV1 } from '@standard-schema/spec'\nimport type {\n PropDef,\n PropertyOnlyProp,\n SetupContext,\n Coercer,\n RefDef,\n SingleRefDef,\n MultipleRefDef,\n RefsMap,\n ContextToken,\n ContextsMap,\n} from './types.js'\nimport {\n coerceNumber,\n coerceString,\n coerceBoolean,\n coerceJson,\n} from './util.js'\nimport { factory } from './factory.js'\n\nfunction isPropOnly (def:unknown):def is PropertyOnlyProp<unknown> {\n return (\n typeof def === 'object' &&\n def !== null &&\n '_microtag' in def &&\n (def as { _microtag: unknown })._microtag === 'prop'\n )\n}\n\nfunction isStandardSchema (def:unknown):def is StandardSchemaV1 {\n return (\n typeof def === 'object' &&\n def !== null &&\n '~standard' in def\n )\n}\n\nfunction normalizePropDef (\n name:string,\n def:PropDef<unknown>\n):Coercer<unknown> {\n if (isPropOnly(def)) {\n return (_raw:string | null) => def.initial\n }\n if (isStandardSchema(def)) {\n const schema = def as StandardSchemaV1\n return (raw:string | null):unknown => {\n const result = schema['~standard'].validate(raw)\n if (result instanceof Promise) {\n throw new TypeError(\n `withProps: async schemas are not supported (prop \"${name}\")`\n )\n }\n if (result.issues) return undefined\n return result.value\n }\n }\n return def as Coercer<unknown>\n}\n\n/** The DSL object passed to the withProps callback. */\nexport type PropDSL = {\n number():Coercer<number>\n string():Coercer<string>\n boolean():Coercer<boolean>\n json<T>():Coercer<T | undefined>\n schema<T>(validator:StandardSchemaV1<unknown, T>):StandardSchemaV1<unknown, T>\n prop<T>(initial:T):PropertyOnlyProp<T>\n}\n\nexport const propDSL:PropDSL = {\n number: () => coerceNumber,\n string: () => coerceString,\n boolean: () => coerceBoolean,\n json: <T>() => coerceJson as Coercer<T | undefined>,\n schema: <T>(v:StandardSchemaV1<unknown, T>) => v,\n prop: <T>(initial:T):PropertyOnlyProp<T> => (\n { _microtag: 'prop', initial }\n ),\n}\n\n/**\n * DSL object passed to the withRefs callback.\n * Call `r.one()` for a single element or `r.all()` for multiple. Pass a\n * CSS selector to query by it, or omit it to match `[data-ref=\"<key>\"]`.\n *\n * Element typing:\n * - `r.one()` defaults to `HTMLElement`.\n * - `r.one<T>()` sets the type and keeps the `[data-ref]` selector.\n * - `r.one('button')` infers the type from the tag AND queries by that\n * tag, exactly like `document.querySelector('button')`.\n */\nexport type RefsDSL = {\n one<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):SingleRefDef<HTMLElementTagNameMap[K]>\n one<T extends HTMLElement = HTMLElement>(selector?:string):SingleRefDef<T>\n\n all<K extends keyof HTMLElementTagNameMap>(\n selector:K\n ):MultipleRefDef<HTMLElementTagNameMap[K]>\n all<T extends HTMLElement = HTMLElement>(selector?:string):MultipleRefDef<T>\n}\n\nexport const refsDSL:RefsDSL = {\n one: ((selector?:string):SingleRefDef => (\n { _microtag: 'ref:one', selector }\n )) as RefsDSL['one'],\n all: ((selector?:string):MultipleRefDef => (\n { _microtag: 'ref:all', selector }\n )) as RefsDSL['all'],\n}\n\n/**\n * DSL object passed to the withContexts callback.\n * Currently a no-op placeholder; the user references imported\n * context tokens directly in the returned record.\n */\nexport type ContextDSL = Record<never, never>\nconst contextDSL:ContextDSL = {}\n\n/**\n * Maps each declared ref key to its own name as a string literal. Exposed\n * as the static `refs` on a registered element so server-rendered templates\n * can fill in `data-ref` values without hardcoding the names, e.g.\n * `data-ref=\"${myCounter.refs.dec}\"`.\n */\nexport type RefNames<RefDefs extends Record<string, RefDef>> = {\n readonly [K in keyof RefDefs]:K & string\n}\n\n/**\n * A registered custom element class that also exposes, as static members,\n * the tag name it was registered under (`TAG`) and the names of its\n * declared refs (`refs`).\n */\nexport type MicrotagElementClass<\n RefDefs extends Record<string, RefDef> = Record<never, never>\n> = typeof HTMLElement & {\n /** The custom element tag name, e.g. 'my-counter'. */\n readonly TAG:string\n /**\n * The declared ref names, each mapping to its own `data-ref` string.\n * Lets server-rendered markup reference refs by key instead of a magic\n * string: `myCounter.refs.dec`.\n */\n readonly refs:RefNames<RefDefs>\n}\n\n/**\n * Fluent builder that accumulates props/refs/contexts config\n * before registering a custom element via `.setup()`.\n */\nexport class ComponentBuilder<\n Props extends Record<string, PropDef> = Record<never, never>,\n RefDefs extends Record<string, RefDef> = Record<never, never>,\n CtxDefs extends Record<string, ContextToken<unknown>> =\n Record<never, never>,\n> {\n private readonly _coercers:Record<string, Coercer<unknown>>\n private readonly _observed:string[]\n private readonly _refDefs:Record<string, RefDef>\n private readonly _ctxDefs:Record<string, ContextToken<unknown>>\n\n constructor (\n readonly tagName:string,\n coercers:Record<string, Coercer<unknown>> = {},\n observed:string[] = [],\n refDefs:Record<string, RefDef> = {},\n ctxDefs:Record<string, ContextToken<unknown>> = {}\n ) {\n this._coercers = coercers\n this._observed = observed\n this._refDefs = refDefs\n this._ctxDefs = ctxDefs\n }\n\n /**\n * The custom element tag name, e.g. 'my-counter'. Available at every\n * point in the fluent chain since each builder method returns a new\n * builder carrying the same tag name.\n */\n get TAG ():string {\n return this.tagName\n }\n\n withProps<P extends Record<string, PropDef>> (\n fn:(p:PropDSL) => P\n ):ComponentBuilder<P, RefDefs, CtxDefs> {\n const defs = fn(propDSL)\n const coercers:Record<string, Coercer<unknown>> = {}\n const observed:string[] = []\n\n for (const [name, def] of Object.entries(defs)) {\n coercers[name] = normalizePropDef(name, def as PropDef<unknown>)\n if (!isPropOnly(def)) {\n observed.push(name)\n }\n }\n\n return new ComponentBuilder<P, RefDefs, CtxDefs>(\n this.tagName, coercers, observed, this._refDefs, this._ctxDefs\n )\n }\n\n withRefs<R extends Record<string, RefDef>> (\n fn:(r:RefsDSL) => R\n ):ComponentBuilder<Props, R, CtxDefs> {\n const defs = fn(refsDSL)\n return new ComponentBuilder<Props, R, CtxDefs>(\n this.tagName,\n this._coercers,\n this._observed,\n defs,\n this._ctxDefs\n )\n }\n\n withContexts<C extends Record<string, ContextToken<unknown>>> (\n fn:(c:ContextDSL) => C\n ):ComponentBuilder<Props, RefDefs, C> {\n const defs = fn(contextDSL)\n return new ComponentBuilder<Props, RefDefs, C>(\n this.tagName,\n this._coercers,\n this._observed,\n this._refDefs,\n defs\n )\n }\n\n setup (\n fn:(ctx:SetupContext<\n Props,\n RefsMap<RefDefs>,\n ContextsMap<CtxDefs>\n >) => void\n ):MicrotagElementClass<RefDefs> {\n const El = factory({\n props: this._coercers,\n observedAttrNames: this._observed,\n refs: this._refDefs,\n contexts: this._ctxDefs,\n setup: fn as any,\n })\n Object.defineProperty(El, 'TAG', {\n value: this.tagName,\n enumerable: true,\n })\n\n // Expose each ref key as its own `data-ref` name so server-rendered\n // markup can reference refs by key instead of a hardcoded string.\n const refNames:Record<string, string> = {}\n for (const key of Object.keys(this._refDefs)) {\n refNames[key] = key\n }\n Object.defineProperty(El, 'refs', {\n value: Object.freeze(refNames),\n enumerable: true,\n })\n\n if (typeof customElements !== 'undefined') {\n customElements.define(this.tagName, El)\n }\n return El as MicrotagElementClass<RefDefs>\n }\n}\n\n/** Create a new component builder for the given tag name. */\nexport function define (tagName:string):ComponentBuilder {\n return new ComponentBuilder(tagName)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAKO;AAWA,SAAS,UAAc,IAAc;AACxC,QAAM,WAAO,mCAAa,MAAS;AACnC,MAAI;AACA,WAAO,GAAG;AAAA,EACd,UAAE;AACE,2CAAa,IAAI;AAAA,EACrB;AACJ;AAPgB;AAaT,SAAS,KAAS,KAAiB;AACtC,SAAO,UAAU,MAAM,IAAI,CAAC;AAChC;AAFgB;;;ACzBT,SAAS,aAAc,KAA0B;AACpD,SAAO,QAAQ,OAAO,MAAM,OAAO,GAAG;AAC1C;AAFgB;AAQT,SAAS,aAAc,KAA0B;AACpD,SAAO,OAAO;AAClB;AAFgB;AAQT,SAAS,cAAe,KAA2B;AACtD,SAAO,QAAQ;AACnB;AAFgB;AAQT,SAAS,WAAyB,KAAiC;AACtE,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI;AACA,WAAO,KAAK,MAAM,GAAG;AAAA,EACzB,QAAQ;AACJ,WAAO;AAAA,EACX;AACJ;AAPgB;AAaT,SAAS,YAAa,KAAyB;AAClD,MAAI;AACJ,MAAI,SAAS;AACb,aAAW,MAAM,KAAK;AAClB,QAAI;AACA,SAAG;AAAA,IACP,SAAS,KAAK;AACV,UAAI,CAAC,QAAQ;AACT,qBAAa;AACb,iBAAS;AAAA,MACb;AAAA,IACJ;AAAA,EACJ;AACA,MAAI,OAAQ,OAAM;AACtB;AAdgB;;;ACrChB,IAAM,kBAAkB,oBAAI,QAA+C;AAG3E,IAAM,mBAAmB,oBAAI,IAA6B;AAgDnD,SAAS,qBACZ,SACA,OACoB;AACpB,MAAI,UAAyB,QAAQ;AACrC,SAAO,SA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AAe,IAAI,OAAO;AAAA,MAC7B,OAAO,KAAK;AAAA,MACZ,YAAY;AAAA,IAChB,CAAC;AAID,UAAM,WAAkC,CAAC;AACzC,eAAW,OAAO,OAAO,KAAK,KAAK,QAAQ,GAAG;AAC1C,eAAS,GAAG,IAAI;AAAA,IACpB;AACA,WAAO,eAAe,IAAI,QAAQ;AAAA,MAC9B,OAAO,OAAO,OAAO,QAAQ;AAAA,MAC7B,YAAY;AAAA,IAChB,CAAC;AAED,QAAI,OAAO,mBAAmB,aAAa;AACvC,qBAAe,OAAO,KAAK,SAAS,EAAE;AAAA,IAC1C;AACA,WAAO;AAAA,EACX;AACJ;AAGO,SAAS,OAAQ,SAAiC;AACrD,SAAO,IAAI,iBAAiB,OAAO;AACvC;AAFgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
coerceNumber,
|
|
13
13
|
coerceString,
|
|
14
14
|
runCleanups
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-P4QHFKTJ.js";
|
|
16
16
|
import {
|
|
17
17
|
__name
|
|
18
18
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -39,6 +39,14 @@ function makeSetupContext(host, props, refs, contexts, cleanups) {
|
|
|
39
39
|
);
|
|
40
40
|
});
|
|
41
41
|
},
|
|
42
|
+
emit(nameOrEvent, detail, options) {
|
|
43
|
+
const event = nameOrEvent instanceof Event ? nameOrEvent : new CustomEvent(nameOrEvent, {
|
|
44
|
+
bubbles: true,
|
|
45
|
+
...options,
|
|
46
|
+
detail
|
|
47
|
+
});
|
|
48
|
+
return host.dispatchEvent(event);
|
|
49
|
+
},
|
|
42
50
|
effect(fn) {
|
|
43
51
|
const dispose = effect(fn);
|
|
44
52
|
cleanups.push(dispose);
|