@barefootjs/client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build.d.ts +56 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +76 -0
- package/dist/context.d.ts +25 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/csr-adapter.d.ts +26 -0
- package/dist/csr-adapter.d.ts.map +1 -0
- package/dist/forward-props.d.ts +17 -0
- package/dist/forward-props.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +154 -0
- package/dist/reactive.d.ts +150 -0
- package/dist/reactive.d.ts.map +1 -0
- package/dist/reactive.js +215 -0
- package/dist/runtime/apply-rest-attrs.d.ts +16 -0
- package/dist/runtime/apply-rest-attrs.d.ts.map +1 -0
- package/dist/runtime/branch-slot.d.ts +22 -0
- package/dist/runtime/branch-slot.d.ts.map +1 -0
- package/dist/runtime/client-marker.d.ts +21 -0
- package/dist/runtime/client-marker.d.ts.map +1 -0
- package/dist/runtime/component.d.ts +99 -0
- package/dist/runtime/component.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +40 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/hydrate.d.ts +100 -0
- package/dist/runtime/hydrate.d.ts.map +1 -0
- package/dist/runtime/hydration-state.d.ts +13 -0
- package/dist/runtime/hydration-state.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2093 -0
- package/dist/runtime/insert.d.ts +75 -0
- package/dist/runtime/insert.d.ts.map +1 -0
- package/dist/runtime/list.d.ts +21 -0
- package/dist/runtime/list.d.ts.map +1 -0
- package/dist/runtime/map-array.d.ts +32 -0
- package/dist/runtime/map-array.d.ts.map +1 -0
- package/dist/runtime/portal.d.ts +96 -0
- package/dist/runtime/portal.d.ts.map +1 -0
- package/dist/runtime/qsa-item.d.ts +52 -0
- package/dist/runtime/qsa-item.d.ts.map +1 -0
- package/dist/runtime/query.d.ts +86 -0
- package/dist/runtime/query.d.ts.map +1 -0
- package/dist/runtime/reconcile-elements.d.ts +44 -0
- package/dist/runtime/reconcile-elements.d.ts.map +1 -0
- package/dist/runtime/registry.d.ts +53 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/render.d.ts +35 -0
- package/dist/runtime/render.d.ts.map +1 -0
- package/dist/runtime/scope.d.ts +28 -0
- package/dist/runtime/scope.d.ts.map +1 -0
- package/dist/runtime/slot-resolver.d.ts +36 -0
- package/dist/runtime/slot-resolver.d.ts.map +1 -0
- package/dist/runtime/spread-attrs.d.ts +19 -0
- package/dist/runtime/spread-attrs.d.ts.map +1 -0
- package/dist/runtime/standalone.js +2278 -0
- package/dist/runtime/streaming.d.ts +36 -0
- package/dist/runtime/streaming.d.ts.map +1 -0
- package/dist/runtime/style.d.ts +17 -0
- package/dist/runtime/style.d.ts.map +1 -0
- package/dist/runtime/template.d.ts +39 -0
- package/dist/runtime/template.d.ts.map +1 -0
- package/dist/runtime/types.d.ts +26 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/shims.d.ts +21 -0
- package/dist/shims.d.ts.map +1 -0
- package/dist/slot.d.ts +14 -0
- package/dist/slot.d.ts.map +1 -0
- package/dist/split-props.d.ts +26 -0
- package/dist/split-props.d.ts.map +1 -0
- package/dist/unwrap.d.ts +16 -0
- package/dist/unwrap.d.ts.map +1 -0
- package/package.json +71 -0
- package/src/build.ts +92 -0
- package/src/context.ts +33 -0
- package/src/csr-adapter.ts +134 -0
- package/src/forward-props.ts +43 -0
- package/src/index.ts +42 -0
- package/src/reactive.ts +411 -0
- package/src/runtime/apply-rest-attrs.ts +109 -0
- package/src/runtime/branch-slot.ts +32 -0
- package/src/runtime/client-marker.ts +46 -0
- package/src/runtime/component.ts +501 -0
- package/src/runtime/context.ts +111 -0
- package/src/runtime/hydrate.ts +311 -0
- package/src/runtime/hydration-state.ts +13 -0
- package/src/runtime/index.ts +96 -0
- package/src/runtime/insert.ts +407 -0
- package/src/runtime/list.ts +47 -0
- package/src/runtime/map-array.ts +381 -0
- package/src/runtime/portal.ts +174 -0
- package/src/runtime/qsa-item.ts +128 -0
- package/src/runtime/query.ts +632 -0
- package/src/runtime/reconcile-elements.ts +391 -0
- package/src/runtime/registry.ts +160 -0
- package/src/runtime/render.ts +105 -0
- package/src/runtime/scope.ts +46 -0
- package/src/runtime/slot-resolver.ts +66 -0
- package/src/runtime/spread-attrs.ts +88 -0
- package/src/runtime/streaming.ts +65 -0
- package/src/runtime/style.ts +27 -0
- package/src/runtime/template.ts +53 -0
- package/src/runtime/types.ts +27 -0
- package/src/shims.ts +54 -0
- package/src/slot.ts +23 -0
- package/src/split-props.ts +86 -0
- package/src/unwrap.ts +18 -0
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BarefootPaths, BundleEntry, ExternalSpec, OutputLayout, PostBuildContext, TemplateAdapter } from '@barefootjs/jsx';
|
|
2
|
+
import { CSRAdapter } from './csr-adapter';
|
|
3
|
+
import type { CSRAdapterOptions } from './csr-adapter';
|
|
4
|
+
export interface CSRBuildOptions {
|
|
5
|
+
/** Project layout paths consumed by registry tooling. */
|
|
6
|
+
paths?: BarefootPaths;
|
|
7
|
+
/** Source component directories relative to the config file. */
|
|
8
|
+
components?: string[];
|
|
9
|
+
/** Output directory relative to the config file. */
|
|
10
|
+
outDir?: string;
|
|
11
|
+
/** Minify client JS output. */
|
|
12
|
+
minify?: boolean;
|
|
13
|
+
/** Add content hash to client JS filenames. */
|
|
14
|
+
contentHash?: boolean;
|
|
15
|
+
/** Custom output directory layout. */
|
|
16
|
+
outputLayout?: OutputLayout;
|
|
17
|
+
/** Post-build hook called after minification, before manifest write. */
|
|
18
|
+
postBuild?: (ctx: PostBuildContext) => Promise<void> | void;
|
|
19
|
+
/** Vendor packages to split out as separately-cached browser chunks. */
|
|
20
|
+
externals?: Record<string, ExternalSpec>;
|
|
21
|
+
/** URL base path for vendor chunks in the emitted importmap. */
|
|
22
|
+
externalsBasePath?: string;
|
|
23
|
+
/** Additional entry points to bundle with esbuild directly. */
|
|
24
|
+
bundleEntries?: BundleEntry[];
|
|
25
|
+
/**
|
|
26
|
+
* Override the compiler adapter. The marked templates this adapter
|
|
27
|
+
* generates are discarded in CSR mode — set this only if you need
|
|
28
|
+
* a different `TemplateAdapter` (e.g. a custom test adapter).
|
|
29
|
+
*/
|
|
30
|
+
adapter?: TemplateAdapter;
|
|
31
|
+
/** Options forwarded to the default `CSRAdapter`. Ignored when `adapter` is set. */
|
|
32
|
+
adapterOptions?: CSRAdapterOptions;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a BarefootBuildConfig for CSR projects.
|
|
36
|
+
*
|
|
37
|
+
* Uses structural typing — does not import `BarefootBuildConfig` to avoid
|
|
38
|
+
* a circular dependency between `@barefootjs/client` and `@barefootjs/cli`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createConfig(options?: CSRBuildOptions): {
|
|
41
|
+
adapter: CSRAdapter | TemplateAdapter;
|
|
42
|
+
paths: BarefootPaths | undefined;
|
|
43
|
+
components: string[] | undefined;
|
|
44
|
+
outDir: string | undefined;
|
|
45
|
+
minify: boolean | undefined;
|
|
46
|
+
contentHash: boolean | undefined;
|
|
47
|
+
clientOnly: boolean;
|
|
48
|
+
externals: Record<string, ExternalSpec> | undefined;
|
|
49
|
+
externalsBasePath: string | undefined;
|
|
50
|
+
bundleEntries: BundleEntry[] | undefined;
|
|
51
|
+
outputLayout: OutputLayout | undefined;
|
|
52
|
+
postBuild: ((ctx: PostBuildContext) => Promise<void> | void) | undefined;
|
|
53
|
+
};
|
|
54
|
+
export { CSRAdapter } from './csr-adapter';
|
|
55
|
+
export type { CSRAdapterOptions } from './csr-adapter';
|
|
56
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAE,iBAAiB,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// src/csr-adapter.ts
|
|
2
|
+
import { BaseAdapter } from "@barefootjs/jsx";
|
|
3
|
+
var EMPTY_SECTIONS = Object.freeze({
|
|
4
|
+
imports: "",
|
|
5
|
+
types: "",
|
|
6
|
+
component: "",
|
|
7
|
+
defaultExport: ""
|
|
8
|
+
});
|
|
9
|
+
var EMPTY_OUTPUT = Object.freeze({
|
|
10
|
+
template: "",
|
|
11
|
+
sections: EMPTY_SECTIONS,
|
|
12
|
+
extension: ".tsx"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
class CSRAdapter extends BaseAdapter {
|
|
16
|
+
name;
|
|
17
|
+
extension = ".tsx";
|
|
18
|
+
acceptsTemplateCall = () => true;
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
super();
|
|
21
|
+
this.name = options.name ?? "csr";
|
|
22
|
+
}
|
|
23
|
+
generate() {
|
|
24
|
+
return EMPTY_OUTPUT;
|
|
25
|
+
}
|
|
26
|
+
renderNode() {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
renderElement() {
|
|
30
|
+
return "";
|
|
31
|
+
}
|
|
32
|
+
renderExpression() {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
renderConditional() {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
renderLoop() {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
renderComponent() {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
renderScopeMarker() {
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
renderSlotMarker() {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
renderCondMarker() {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/build.ts
|
|
56
|
+
function createConfig(options = {}) {
|
|
57
|
+
const adapter = options.adapter ?? new CSRAdapter(options.adapterOptions);
|
|
58
|
+
return {
|
|
59
|
+
adapter,
|
|
60
|
+
paths: options.paths,
|
|
61
|
+
components: options.components,
|
|
62
|
+
outDir: options.outDir,
|
|
63
|
+
minify: options.minify,
|
|
64
|
+
contentHash: options.contentHash,
|
|
65
|
+
clientOnly: true,
|
|
66
|
+
externals: options.externals,
|
|
67
|
+
externalsBasePath: options.externalsBasePath,
|
|
68
|
+
bundleEntries: options.bundleEntries,
|
|
69
|
+
outputLayout: options.outputLayout,
|
|
70
|
+
postBuild: options.postBuild
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
createConfig,
|
|
75
|
+
CSRAdapter
|
|
76
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context API: pure metadata portion.
|
|
3
|
+
*
|
|
4
|
+
* `createContext` is DOM-free and safe to use anywhere (including SSR).
|
|
5
|
+
* The DOM-bound operations (`useContext`, `provideContext`) live in
|
|
6
|
+
* `./runtime/context.ts` and are emitted by the compiler for `'use client'`
|
|
7
|
+
* components.
|
|
8
|
+
*/
|
|
9
|
+
export type Context<T> = {
|
|
10
|
+
readonly id: symbol;
|
|
11
|
+
readonly defaultValue: T | undefined;
|
|
12
|
+
/** JSX Provider component. Compiled to provideContext() by the compiler. */
|
|
13
|
+
readonly Provider: (props: {
|
|
14
|
+
value: T;
|
|
15
|
+
children?: unknown;
|
|
16
|
+
}) => unknown;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Create a new context with an optional default value.
|
|
20
|
+
*
|
|
21
|
+
* `useContext()` returns the nearest provider value, then the default,
|
|
22
|
+
* then `undefined`. It never throws — guard with optional chaining.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createContext<T>(defaultValue?: T): Context<T>;
|
|
25
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,SAAS,CAAA;IACpC,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAA;CACxE,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAU7D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AdapterOutput } from '@barefootjs/jsx';
|
|
2
|
+
import { BaseAdapter } from '@barefootjs/jsx';
|
|
3
|
+
export interface CSRAdapterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Display name surfaced through `TemplateAdapter.name` — read by
|
|
6
|
+
* `bf build` for its `Adapter: …` banner. Defaults to `'csr'`.
|
|
7
|
+
*/
|
|
8
|
+
name?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class CSRAdapter extends BaseAdapter {
|
|
11
|
+
name: string;
|
|
12
|
+
extension: string;
|
|
13
|
+
acceptsTemplateCall: () => boolean;
|
|
14
|
+
constructor(options?: CSRAdapterOptions);
|
|
15
|
+
generate(): AdapterOutput;
|
|
16
|
+
renderNode(): string;
|
|
17
|
+
renderElement(): string;
|
|
18
|
+
renderExpression(): string;
|
|
19
|
+
renderConditional(): string;
|
|
20
|
+
renderLoop(): string;
|
|
21
|
+
renderComponent(): string;
|
|
22
|
+
renderScopeMarker(): string;
|
|
23
|
+
renderSlotMarker(): string;
|
|
24
|
+
renderCondMarker(): string;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=csr-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csr-adapter.d.ts","sourceRoot":"","sources":["../src/csr-adapter.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAqBD,qBAAa,UAAW,SAAQ,WAAW;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,SAAS;IAIlB,mBAAmB,QAAO,OAAO,CAAQ;IAEzC,YAAY,OAAO,GAAE,iBAAsB,EAG1C;IAMD,QAAQ,IAAI,aAAa,CAExB;IAQD,UAAU,IAAI,MAAM,CAEnB;IACD,aAAa,IAAI,MAAM,CAEtB;IACD,gBAAgB,IAAI,MAAM,CAEzB;IACD,iBAAiB,IAAI,MAAM,CAE1B;IACD,UAAU,IAAI,MAAM,CAEnB;IACD,eAAe,IAAI,MAAM,CAExB;IACD,iBAAiB,IAAI,MAAM,CAE1B;IACD,gBAAgB,IAAI,MAAM,CAEzB;IACD,gBAAgB,IAAI,MAAM,CAEzB;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BarefootJS - Forward Props Helper
|
|
3
|
+
*
|
|
4
|
+
* Forwards spread props to child components using getter delegation
|
|
5
|
+
* to preserve reactivity. Used by compiler-generated code for
|
|
6
|
+
* components with {...rest} spread on child components.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create a props object that merges explicit overrides with forwarded source props.
|
|
10
|
+
* Preserves getter-based reactivity from both overrides and source.
|
|
11
|
+
*
|
|
12
|
+
* @param source - The parent props object (reads are deferred via getters)
|
|
13
|
+
* @param overrides - Object literal with getters/values that override source props
|
|
14
|
+
* @param excludeKeys - Keys from source to exclude (already destructured)
|
|
15
|
+
*/
|
|
16
|
+
export declare function forwardProps<T extends Record<string, unknown>>(source: T, overrides: Record<string, unknown>, excludeKeys: string[]): Record<string, unknown>;
|
|
17
|
+
//# sourceMappingURL=forward-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forward-props.d.ts","sourceRoot":"","sources":["../src/forward-props.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,MAAM,EAAE,CAAC,EACT,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,WAAW,EAAE,MAAM,EAAE,GACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBzB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createSignal, createEffect, createDisposableEffect, createMemo, createRoot, onCleanup, onMount, untrack, batch, type Reactive, type Signal, type Memo, type CleanupFn, type EffectFn, } from '@barefootjs/client/reactive';
|
|
2
|
+
export { splitProps } from './split-props';
|
|
3
|
+
export { __slot, type SlotMarker } from './slot';
|
|
4
|
+
export { forwardProps } from './forward-props';
|
|
5
|
+
export { unwrap } from './unwrap';
|
|
6
|
+
export { createContext, type Context } from './context';
|
|
7
|
+
export { useContext, provideContext, createPortal, isSSRPortal, findSiblingSlot, cleanupPortalPlaceholder, type Portal, type PortalChildren, type PortalOptions, type Renderable, } from './shims';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,UAAU,EACV,UAAU,EACV,SAAS,EACT,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,MAAM,EACX,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,QAAQ,GACd,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAE,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAA;AAEvD,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,eAAe,EACf,wBAAwB,EACxB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
createSignal,
|
|
4
|
+
createEffect,
|
|
5
|
+
createDisposableEffect,
|
|
6
|
+
createMemo,
|
|
7
|
+
createRoot,
|
|
8
|
+
onCleanup,
|
|
9
|
+
onMount,
|
|
10
|
+
untrack,
|
|
11
|
+
batch
|
|
12
|
+
} from "@barefootjs/client/reactive";
|
|
13
|
+
|
|
14
|
+
// src/split-props.ts
|
|
15
|
+
function splitProps(props, keys) {
|
|
16
|
+
const keySet = new Set(keys);
|
|
17
|
+
const local = new Proxy({}, {
|
|
18
|
+
get(_, key) {
|
|
19
|
+
if (keySet.has(key)) {
|
|
20
|
+
return props[key];
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
},
|
|
24
|
+
has(_, key) {
|
|
25
|
+
return keySet.has(key);
|
|
26
|
+
},
|
|
27
|
+
ownKeys() {
|
|
28
|
+
return [...keySet];
|
|
29
|
+
},
|
|
30
|
+
getOwnPropertyDescriptor(_, key) {
|
|
31
|
+
if (keySet.has(key)) {
|
|
32
|
+
return {
|
|
33
|
+
configurable: true,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: () => props[key]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const rest = new Proxy({}, {
|
|
42
|
+
get(_, key) {
|
|
43
|
+
if (!keySet.has(key)) {
|
|
44
|
+
return props[key];
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
},
|
|
48
|
+
has(_, key) {
|
|
49
|
+
return key in props && !keySet.has(key);
|
|
50
|
+
},
|
|
51
|
+
ownKeys() {
|
|
52
|
+
return Object.keys(props).filter((k) => !keySet.has(k));
|
|
53
|
+
},
|
|
54
|
+
getOwnPropertyDescriptor(_, key) {
|
|
55
|
+
if (key in props && !keySet.has(key)) {
|
|
56
|
+
return {
|
|
57
|
+
configurable: true,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: () => props[key]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return [local, rest];
|
|
66
|
+
}
|
|
67
|
+
// src/slot.ts
|
|
68
|
+
function __slot(thunk) {
|
|
69
|
+
return {
|
|
70
|
+
__isSlot: true,
|
|
71
|
+
toString() {
|
|
72
|
+
const result = thunk();
|
|
73
|
+
return result == null ? "" : String(result);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// src/forward-props.ts
|
|
78
|
+
function forwardProps(source, overrides, excludeKeys) {
|
|
79
|
+
const result = {};
|
|
80
|
+
const exclude = new Set(excludeKeys);
|
|
81
|
+
const descs = Object.getOwnPropertyDescriptors(overrides);
|
|
82
|
+
for (const key of Object.keys(descs)) {
|
|
83
|
+
Object.defineProperty(result, key, { ...descs[key], enumerable: true, configurable: true });
|
|
84
|
+
}
|
|
85
|
+
for (const key of Object.keys(source)) {
|
|
86
|
+
if (exclude.has(key) || key in result)
|
|
87
|
+
continue;
|
|
88
|
+
const k = key;
|
|
89
|
+
Object.defineProperty(result, k, {
|
|
90
|
+
get: () => source[k],
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
// src/unwrap.ts
|
|
98
|
+
function unwrap(prop) {
|
|
99
|
+
return typeof prop === "function" ? prop() : prop;
|
|
100
|
+
}
|
|
101
|
+
// src/context.ts
|
|
102
|
+
function createContext(defaultValue) {
|
|
103
|
+
return {
|
|
104
|
+
id: Symbol(),
|
|
105
|
+
defaultValue,
|
|
106
|
+
Provider: () => {
|
|
107
|
+
throw new Error("Context.Provider should be compiled away");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// src/shims.ts
|
|
112
|
+
function browserOnly(name) {
|
|
113
|
+
throw new Error(`[barefootjs] ${name}() is a browser-only API and can only be called from a "use client" component. ` + `If you are seeing this at runtime, the BarefootJS compiler did not rewrite the import — please report a bug.`);
|
|
114
|
+
}
|
|
115
|
+
function useContext(_context) {
|
|
116
|
+
return browserOnly("useContext");
|
|
117
|
+
}
|
|
118
|
+
function provideContext(_context, _value) {
|
|
119
|
+
return browserOnly("provideContext");
|
|
120
|
+
}
|
|
121
|
+
function createPortal(_children, _container, _options) {
|
|
122
|
+
return browserOnly("createPortal");
|
|
123
|
+
}
|
|
124
|
+
function isSSRPortal(_element) {
|
|
125
|
+
return browserOnly("isSSRPortal");
|
|
126
|
+
}
|
|
127
|
+
function findSiblingSlot(_el, _slotSelector) {
|
|
128
|
+
return browserOnly("findSiblingSlot");
|
|
129
|
+
}
|
|
130
|
+
function cleanupPortalPlaceholder(_portalId) {
|
|
131
|
+
return browserOnly("cleanupPortalPlaceholder");
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
useContext,
|
|
135
|
+
unwrap,
|
|
136
|
+
untrack,
|
|
137
|
+
splitProps,
|
|
138
|
+
provideContext,
|
|
139
|
+
onMount,
|
|
140
|
+
onCleanup,
|
|
141
|
+
isSSRPortal,
|
|
142
|
+
forwardProps,
|
|
143
|
+
findSiblingSlot,
|
|
144
|
+
createSignal,
|
|
145
|
+
createRoot,
|
|
146
|
+
createPortal,
|
|
147
|
+
createMemo,
|
|
148
|
+
createEffect,
|
|
149
|
+
createDisposableEffect,
|
|
150
|
+
createContext,
|
|
151
|
+
cleanupPortalPlaceholder,
|
|
152
|
+
batch,
|
|
153
|
+
__slot
|
|
154
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BarefootJS - Reactive Primitives
|
|
3
|
+
*
|
|
4
|
+
* Minimal reactive system for DOM manipulation.
|
|
5
|
+
* Inspired by SolidJS signals.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Phantom brand for compile-time reactivity detection.
|
|
9
|
+
* The compiler checks for the '__reactive' property via TypeChecker
|
|
10
|
+
* to identify reactive expressions.
|
|
11
|
+
*/
|
|
12
|
+
export type Reactive<T> = T & {
|
|
13
|
+
readonly __reactive: true;
|
|
14
|
+
};
|
|
15
|
+
export type Signal<T> = [
|
|
16
|
+
/** Get current value (registers dependency when called inside effect) */
|
|
17
|
+
Reactive<() => T>,
|
|
18
|
+
/** Update value (accepts value or updater function) */
|
|
19
|
+
(valueOrFn: T | ((prev: T) => T)) => void
|
|
20
|
+
];
|
|
21
|
+
export type CleanupFn = () => void;
|
|
22
|
+
export type EffectFn = () => void | CleanupFn;
|
|
23
|
+
export type Memo<T> = Reactive<() => T>;
|
|
24
|
+
/**
|
|
25
|
+
* Create a reactive value
|
|
26
|
+
*
|
|
27
|
+
* @param initialValue - Initial value
|
|
28
|
+
* @returns [getter, setter] tuple
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const [count, setCount] = createSignal(0)
|
|
32
|
+
* count() // 0
|
|
33
|
+
* setCount(5) // Update to 5
|
|
34
|
+
* setCount(n => n + 1) // Update with function (becomes 6)
|
|
35
|
+
*/
|
|
36
|
+
export declare function createSignal<T>(initialValue: T): Signal<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Side effect that runs automatically when signals change
|
|
39
|
+
*
|
|
40
|
+
* @param fn - Effect function (can return a cleanup function)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* const [count, setCount] = createSignal(0)
|
|
44
|
+
* createEffect(() => {
|
|
45
|
+
* console.log("count changed:", count())
|
|
46
|
+
* })
|
|
47
|
+
* setCount(1) // Logs "count changed: 1"
|
|
48
|
+
*/
|
|
49
|
+
export declare function createEffect(fn: EffectFn): void;
|
|
50
|
+
/**
|
|
51
|
+
* Create an isolated reactive scope with explicit disposal.
|
|
52
|
+
* All effects/memos created inside run within this root and are
|
|
53
|
+
* disposed together when the returned dispose function is called.
|
|
54
|
+
*
|
|
55
|
+
* Used internally by mapArray for per-item reactive scopes.
|
|
56
|
+
*
|
|
57
|
+
* @param fn - Function to run in the new scope. Receives a dispose function.
|
|
58
|
+
* @returns The return value of fn
|
|
59
|
+
*/
|
|
60
|
+
export declare function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
61
|
+
/**
|
|
62
|
+
* Create an effect that can be explicitly disposed (unsubscribed from all signals).
|
|
63
|
+
* Used for effects inside conditional branches that need cleanup on branch switch.
|
|
64
|
+
*
|
|
65
|
+
* @returns A dispose function that stops the effect and removes it from all signal dependencies.
|
|
66
|
+
*/
|
|
67
|
+
export declare function createDisposableEffect(fn: EffectFn): () => void;
|
|
68
|
+
/**
|
|
69
|
+
* Register cleanup function for effects
|
|
70
|
+
*
|
|
71
|
+
* @param fn - Cleanup function
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* createEffect(() => {
|
|
75
|
+
* const timer = setInterval(() => console.log('tick'), 1000)
|
|
76
|
+
* onCleanup(() => clearInterval(timer))
|
|
77
|
+
* })
|
|
78
|
+
*/
|
|
79
|
+
export declare function onCleanup(fn: CleanupFn): void;
|
|
80
|
+
/**
|
|
81
|
+
* Run a function without tracking signal dependencies
|
|
82
|
+
*
|
|
83
|
+
* @param fn - Function to run without tracking
|
|
84
|
+
* @returns The return value of fn
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* createEffect(() => {
|
|
88
|
+
* const value = untrack(() => someSignal()) // won't re-run when someSignal changes
|
|
89
|
+
* console.log(value)
|
|
90
|
+
* })
|
|
91
|
+
*/
|
|
92
|
+
export declare function untrack<T>(fn: () => T): T;
|
|
93
|
+
/**
|
|
94
|
+
* Batch multiple signal updates and propagate once
|
|
95
|
+
*
|
|
96
|
+
* Collects all signal writes inside `fn`, then flushes
|
|
97
|
+
* dependent effects after `fn` returns. Duplicate effects
|
|
98
|
+
* are deduplicated, so a deep memo chain only propagates once
|
|
99
|
+
* regardless of how many times the source signal was written.
|
|
100
|
+
*
|
|
101
|
+
* Batches can be nested — effects flush when the outermost batch ends.
|
|
102
|
+
*
|
|
103
|
+
* @param fn - Function containing signal writes to batch
|
|
104
|
+
* @returns The return value of fn
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* const [a, setA] = createSignal(0)
|
|
108
|
+
* const [b, setB] = createSignal(0)
|
|
109
|
+
* batch(() => {
|
|
110
|
+
* setA(1) // queued
|
|
111
|
+
* setB(2) // queued
|
|
112
|
+
* })
|
|
113
|
+
* // effects run once here, not twice
|
|
114
|
+
*/
|
|
115
|
+
export declare function batch<T>(fn: () => T): T;
|
|
116
|
+
/**
|
|
117
|
+
* Run a function once when the component mounts
|
|
118
|
+
*
|
|
119
|
+
* Thin wrapper around createEffect for one-time mount code.
|
|
120
|
+
* The function runs immediately and does not track any dependencies.
|
|
121
|
+
*
|
|
122
|
+
* @param fn - Function to run on mount
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* onMount(() => {
|
|
126
|
+
* console.log('Component mounted!')
|
|
127
|
+
* onCleanup(() => console.log('Component unmounted!'))
|
|
128
|
+
* })
|
|
129
|
+
*/
|
|
130
|
+
export declare function onMount(fn: () => void): void;
|
|
131
|
+
/**
|
|
132
|
+
* Create a memoized computed value
|
|
133
|
+
*
|
|
134
|
+
* A derived signal that:
|
|
135
|
+
* - Tracks dependencies automatically (like createEffect)
|
|
136
|
+
* - Caches the computed result
|
|
137
|
+
* - Acts as a read-only signal (can be used as dependency by other effects/memos)
|
|
138
|
+
*
|
|
139
|
+
* @param fn - Computation function that returns a value
|
|
140
|
+
* @returns Getter function for the memoized value
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const [count, setCount] = createSignal(2)
|
|
144
|
+
* const doubled = createMemo(() => count() * 2)
|
|
145
|
+
* doubled() // 4
|
|
146
|
+
* setCount(5)
|
|
147
|
+
* doubled() // 10
|
|
148
|
+
*/
|
|
149
|
+
export declare function createMemo<T>(fn: () => T): Memo<T>;
|
|
150
|
+
//# sourceMappingURL=reactive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../src/reactive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAA;CAAE,CAAA;AAE3D,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI;IACtB,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACjB,uDAAuD;IACvD,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI;CAC1C,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,IAAI,CAAA;AAClC,MAAM,MAAM,QAAQ,GAAG,MAAM,IAAI,GAAG,SAAS,CAAA;AAC7C,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAA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