@askrjs/askr 0.0.1 → 0.0.2

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.
Files changed (50) hide show
  1. package/README.md +18 -10
  2. package/dist/chunk-KR6HG7HF.js +38 -0
  3. package/dist/chunk-KR6HG7HF.js.map +1 -0
  4. package/dist/{chunk-L7RL4LYV.js → chunk-MIPES65F.js} +1486 -1905
  5. package/dist/chunk-MIPES65F.js.map +1 -0
  6. package/dist/{chunk-HIWJVOS4.js → chunk-PFOLLB6A.js} +38 -17
  7. package/dist/chunk-PFOLLB6A.js.map +1 -0
  8. package/dist/chunk-QECQ2TF6.js +28 -0
  9. package/dist/chunk-QECQ2TF6.js.map +1 -0
  10. package/dist/{chunk-UUM5W2RM.js → chunk-RJWOOUYV.js} +2 -2
  11. package/dist/chunk-RJWOOUYV.js.map +1 -0
  12. package/dist/index.cjs +1760 -1972
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +52 -40
  15. package/dist/index.d.ts +52 -40
  16. package/dist/index.js +226 -52
  17. package/dist/index.js.map +1 -1
  18. package/dist/jsx/jsx-dev-runtime.cjs +9 -3
  19. package/dist/jsx/jsx-dev-runtime.cjs.map +1 -1
  20. package/dist/jsx/jsx-dev-runtime.d.cts +4 -9
  21. package/dist/jsx/jsx-dev-runtime.d.ts +4 -9
  22. package/dist/jsx/jsx-dev-runtime.js +10 -4
  23. package/dist/jsx/jsx-dev-runtime.js.map +1 -1
  24. package/dist/jsx/jsx-runtime.cjs +14 -5
  25. package/dist/jsx/jsx-runtime.cjs.map +1 -1
  26. package/dist/jsx/jsx-runtime.d.cts +9 -6
  27. package/dist/jsx/jsx-runtime.d.ts +9 -6
  28. package/dist/jsx/jsx-runtime.js +6 -2
  29. package/dist/{navigate-NLQOZQGM.js → navigate-SDZNA2ZE.js} +5 -5
  30. package/dist/{route-TVYWYCEJ.js → route-P5YQBT4T.js} +4 -4
  31. package/dist/{ssr-4ELUFK65.js → ssr-65K3IJ6B.js} +9 -5
  32. package/dist/{types-DUDmnzD8.d.cts → types-DLTViI21.d.cts} +15 -3
  33. package/dist/{types-DUDmnzD8.d.ts → types-DLTViI21.d.ts} +15 -3
  34. package/package.json +5 -3
  35. package/src/jsx/index.ts +4 -0
  36. package/src/jsx/jsx-dev-runtime.ts +7 -10
  37. package/src/jsx/jsx-runtime.ts +23 -11
  38. package/src/jsx/types.ts +22 -3
  39. package/src/jsx/utils.ts +19 -0
  40. package/dist/chunk-4CV4JOE5.js +0 -27
  41. package/dist/chunk-HIWJVOS4.js.map +0 -1
  42. package/dist/chunk-L7RL4LYV.js.map +0 -1
  43. package/dist/chunk-UUM5W2RM.js.map +0 -1
  44. package/dist/chunk-YNH3D4KW.js +0 -29
  45. package/dist/chunk-YNH3D4KW.js.map +0 -1
  46. package/dist/ssr-4ELUFK65.js.map +0 -1
  47. package/src/jsx/react-jsx-runtime.d.ts +0 -0
  48. /package/dist/{chunk-4CV4JOE5.js.map → navigate-SDZNA2ZE.js.map} +0 -0
  49. /package/dist/{navigate-NLQOZQGM.js.map → route-P5YQBT4T.js.map} +0 -0
  50. /package/dist/{route-TVYWYCEJ.js.map → ssr-65K3IJ6B.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { J as JSXElement, P as Props } from './types-DUDmnzD8.cjs';
1
+ import { J as JSXElement, P as Props } from './types-DLTViI21.cjs';
2
2
  export { Fragment, jsx, jsxs } from './jsx/jsx-runtime.cjs';
3
3
 
4
4
  /**
@@ -28,7 +28,7 @@ interface Context<T> {
28
28
  readonly key: ContextKey;
29
29
  readonly defaultValue: T;
30
30
  readonly Scope: (props: {
31
- value: T;
31
+ value: unknown;
32
32
  children?: unknown;
33
33
  }) => JSXElement;
34
34
  }
@@ -60,6 +60,7 @@ interface ComponentInstance {
60
60
  mounted: boolean;
61
61
  abortController: AbortController;
62
62
  ssr?: boolean;
63
+ cleanupStrict?: boolean;
63
64
  stateValues: State<unknown>[];
64
65
  evaluationGeneration: number;
65
66
  notifyUpdate: (() => void) | null;
@@ -145,6 +146,7 @@ declare function getSignal(): AbortSignal;
145
146
  interface State<T> {
146
147
  (): T;
147
148
  set(value: T): void;
149
+ set(updater: (prev: T) => T): void;
148
150
  _hasBeenRead?: boolean;
149
151
  _readers?: Map<ComponentInstance, number>;
150
152
  }
@@ -197,6 +199,8 @@ interface DataResult<T> {
197
199
  declare function resource<T>(fn: (opts: {
198
200
  signal: AbortSignal;
199
201
  }) => Promise<T> | T, deps?: unknown[]): DataResult<T>;
202
+ declare function derive<TOut>(fn: () => TOut): TOut | null;
203
+ declare function task(fn: () => void | (() => void) | Promise<void | (() => void)>): void;
200
204
 
201
205
  /**
202
206
  * Route definition and matching
@@ -240,7 +244,8 @@ interface RouteSnapshot {
240
244
  matches: readonly RouteMatch[];
241
245
  }
242
246
  declare function setServerLocation(url: string | null): void;
243
- declare function route(path?: string, handler?: RouteHandler, namespace?: string): void | RouteSnapshot;
247
+ declare function route(): RouteSnapshot;
248
+ declare function route(path: string, handler?: RouteHandler, namespace?: string): void;
244
249
  /**
245
250
  * Get all registered routes
246
251
  */
@@ -266,35 +271,22 @@ declare function getLoadedNamespaces(): string[];
266
271
  * App bootstrap and mount
267
272
  */
268
273
 
269
- interface AppConfig {
270
- root: Element | string;
271
- component: ComponentFunction;
272
- }
273
- /**
274
- * Bootstrap and mount app on client
275
- * Supports both sync and async components
276
- *
277
- * If createApp is called multiple times on the same root, the existing instance
278
- * is reused and its component function is updated. This ensures:
279
- * - Generation tokens work correctly (old async renders don't overwrite new ones)
280
- * - State is preserved across updates (if desired)
281
- * - DOM is diffed/updated rather than replaced
282
- */
283
- declare function createApp(config: AppConfig | SPAConfig): void;
284
-
285
274
  type IslandConfig = {
286
275
  root: Element | string;
287
276
  component: ComponentFunction;
277
+ cleanupStrict?: boolean;
288
278
  routes?: never;
289
279
  };
290
280
  type SPAConfig = {
291
281
  root: Element | string;
292
282
  routes: Route[];
283
+ cleanupStrict?: boolean;
293
284
  component?: never;
294
285
  };
295
286
  type HydrateSPAConfig = {
296
287
  root: Element | string;
297
288
  routes: Route[];
289
+ cleanupStrict?: boolean;
298
290
  };
299
291
  /**
300
292
  * createIsland: Enhances existing DOM (no router, mounts once)
@@ -318,24 +310,6 @@ declare function cleanupApp(root: Element | string): void;
318
310
  */
319
311
  declare function hasApp(root: Element | string): boolean;
320
312
 
321
- /**
322
- * Small layout helper (centralized)
323
- * Usage: const parent = layout(ParentLayout); route('/parent', () => parent(<Child />));
324
- *
325
- * A layout is simply a component that receives `children`.
326
- * This helper intentionally avoids vnode inspection, heuristics, or double-invocation.
327
- * Prefer boring, explicit code over cleverness.
328
- *
329
- * Example:
330
- * const Parent = ({ children }: { children?: unknown }) => <div class="parent">{children}</div>;
331
- * const parent = layout(Parent);
332
- * route('/parent', () => parent(<div class="child">C</div>));
333
- */
334
- type Component<P = object> = (props: P & {
335
- children?: unknown;
336
- }) => unknown;
337
- declare function layout<P>(Layout: Component<P>): (children?: unknown) => unknown;
338
-
339
313
  /**
340
314
  * Client-side navigation with History API
341
315
  */
@@ -349,7 +323,6 @@ declare function navigate(path: string): void;
349
323
  /**
350
324
  * Link component for client-side navigation
351
325
  */
352
-
353
326
  interface LinkProps {
354
327
  href: string;
355
328
  children?: unknown;
@@ -364,7 +337,46 @@ interface LinkProps {
364
337
  * - Shift+click (opens in new window)
365
338
  * - Right-click context menu
366
339
  */
367
- declare function Link({ href, children }: LinkProps): JSXElement;
340
+ declare function Link({ href, children }: LinkProps): unknown;
341
+
342
+ /**
343
+ * Layout helper.
344
+ *
345
+ * A layout is just a normal component that wraps children.
346
+ * Persistence and reuse are handled by the runtime via component identity.
347
+ *
348
+ * This helper exists purely for readability and convention.
349
+ */
350
+ type LayoutComponent<P = object> = (props: P & {
351
+ children?: unknown;
352
+ }) => unknown;
353
+ declare function layout<P = object>(Layout: LayoutComponent<P>): (children?: unknown, props?: P) => unknown;
354
+
355
+ type SlotProps = {
356
+ asChild: true;
357
+ children: unknown;
358
+ [key: string]: unknown;
359
+ } | {
360
+ asChild?: false;
361
+ children?: unknown;
362
+ };
363
+ declare function Slot(props: SlotProps): unknown;
364
+
365
+ /**
366
+ * Portal / Host primitive.
367
+ *
368
+ * A portal is a named render slot within the existing tree.
369
+ * It does NOT create a second tree or touch the DOM directly.
370
+ */
371
+ interface Portal<T = unknown> {
372
+ /** Mount point — rendered exactly once */
373
+ (): unknown;
374
+ /** Render content into the portal */
375
+ render(props: {
376
+ children?: T;
377
+ }): unknown;
378
+ }
379
+ declare function definePortal<T = unknown>(): Portal<T>;
368
380
 
369
381
  type SSRData = Record<string, unknown>;
370
382
 
@@ -443,4 +455,4 @@ declare function renderToStream(opts: {
443
455
  onComplete(): void;
444
456
  }): void;
445
457
 
446
- export { type Context, type DataResult, type HydrateSPAConfig, type IslandConfig, Link, type LinkProps, Props, type Route, type RouteHandler, type RouteMatch, type RouteSnapshot, type SPAConfig, type State, cleanupApp, clearRoutes, collectResources, createApp, createIsland, createSPA, defineContext, getLoadedNamespaces, getNamespaceRoutes, getRoutes, getSignal, hasApp, hydrateSPA, layout, navigate, readContext, renderToStream, renderToString, renderToStringSync, renderToStringSyncForUrl, resolveResources, resource, route, scheduleEventHandler, setServerLocation, state, unloadNamespace };
458
+ export { type Context, type DataResult, type HydrateSPAConfig, type IslandConfig, type LayoutComponent, Link, type LinkProps, type Portal, Props, type Route, type RouteHandler, type RouteMatch, type RouteSnapshot, type SPAConfig, Slot, type SlotProps, type State, cleanupApp, clearRoutes, collectResources, createIsland, createSPA, defineContext, definePortal, derive, getLoadedNamespaces, getNamespaceRoutes, getRoutes, getSignal, hasApp, hydrateSPA, layout, navigate, readContext, renderToStream, renderToString, renderToStringSync, renderToStringSyncForUrl, resolveResources, resource, route, scheduleEventHandler, setServerLocation, state, task, unloadNamespace };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { J as JSXElement, P as Props } from './types-DUDmnzD8.js';
1
+ import { J as JSXElement, P as Props } from './types-DLTViI21.js';
2
2
  export { Fragment, jsx, jsxs } from './jsx/jsx-runtime.js';
3
3
 
4
4
  /**
@@ -28,7 +28,7 @@ interface Context<T> {
28
28
  readonly key: ContextKey;
29
29
  readonly defaultValue: T;
30
30
  readonly Scope: (props: {
31
- value: T;
31
+ value: unknown;
32
32
  children?: unknown;
33
33
  }) => JSXElement;
34
34
  }
@@ -60,6 +60,7 @@ interface ComponentInstance {
60
60
  mounted: boolean;
61
61
  abortController: AbortController;
62
62
  ssr?: boolean;
63
+ cleanupStrict?: boolean;
63
64
  stateValues: State<unknown>[];
64
65
  evaluationGeneration: number;
65
66
  notifyUpdate: (() => void) | null;
@@ -145,6 +146,7 @@ declare function getSignal(): AbortSignal;
145
146
  interface State<T> {
146
147
  (): T;
147
148
  set(value: T): void;
149
+ set(updater: (prev: T) => T): void;
148
150
  _hasBeenRead?: boolean;
149
151
  _readers?: Map<ComponentInstance, number>;
150
152
  }
@@ -197,6 +199,8 @@ interface DataResult<T> {
197
199
  declare function resource<T>(fn: (opts: {
198
200
  signal: AbortSignal;
199
201
  }) => Promise<T> | T, deps?: unknown[]): DataResult<T>;
202
+ declare function derive<TOut>(fn: () => TOut): TOut | null;
203
+ declare function task(fn: () => void | (() => void) | Promise<void | (() => void)>): void;
200
204
 
201
205
  /**
202
206
  * Route definition and matching
@@ -240,7 +244,8 @@ interface RouteSnapshot {
240
244
  matches: readonly RouteMatch[];
241
245
  }
242
246
  declare function setServerLocation(url: string | null): void;
243
- declare function route(path?: string, handler?: RouteHandler, namespace?: string): void | RouteSnapshot;
247
+ declare function route(): RouteSnapshot;
248
+ declare function route(path: string, handler?: RouteHandler, namespace?: string): void;
244
249
  /**
245
250
  * Get all registered routes
246
251
  */
@@ -266,35 +271,22 @@ declare function getLoadedNamespaces(): string[];
266
271
  * App bootstrap and mount
267
272
  */
268
273
 
269
- interface AppConfig {
270
- root: Element | string;
271
- component: ComponentFunction;
272
- }
273
- /**
274
- * Bootstrap and mount app on client
275
- * Supports both sync and async components
276
- *
277
- * If createApp is called multiple times on the same root, the existing instance
278
- * is reused and its component function is updated. This ensures:
279
- * - Generation tokens work correctly (old async renders don't overwrite new ones)
280
- * - State is preserved across updates (if desired)
281
- * - DOM is diffed/updated rather than replaced
282
- */
283
- declare function createApp(config: AppConfig | SPAConfig): void;
284
-
285
274
  type IslandConfig = {
286
275
  root: Element | string;
287
276
  component: ComponentFunction;
277
+ cleanupStrict?: boolean;
288
278
  routes?: never;
289
279
  };
290
280
  type SPAConfig = {
291
281
  root: Element | string;
292
282
  routes: Route[];
283
+ cleanupStrict?: boolean;
293
284
  component?: never;
294
285
  };
295
286
  type HydrateSPAConfig = {
296
287
  root: Element | string;
297
288
  routes: Route[];
289
+ cleanupStrict?: boolean;
298
290
  };
299
291
  /**
300
292
  * createIsland: Enhances existing DOM (no router, mounts once)
@@ -318,24 +310,6 @@ declare function cleanupApp(root: Element | string): void;
318
310
  */
319
311
  declare function hasApp(root: Element | string): boolean;
320
312
 
321
- /**
322
- * Small layout helper (centralized)
323
- * Usage: const parent = layout(ParentLayout); route('/parent', () => parent(<Child />));
324
- *
325
- * A layout is simply a component that receives `children`.
326
- * This helper intentionally avoids vnode inspection, heuristics, or double-invocation.
327
- * Prefer boring, explicit code over cleverness.
328
- *
329
- * Example:
330
- * const Parent = ({ children }: { children?: unknown }) => <div class="parent">{children}</div>;
331
- * const parent = layout(Parent);
332
- * route('/parent', () => parent(<div class="child">C</div>));
333
- */
334
- type Component<P = object> = (props: P & {
335
- children?: unknown;
336
- }) => unknown;
337
- declare function layout<P>(Layout: Component<P>): (children?: unknown) => unknown;
338
-
339
313
  /**
340
314
  * Client-side navigation with History API
341
315
  */
@@ -349,7 +323,6 @@ declare function navigate(path: string): void;
349
323
  /**
350
324
  * Link component for client-side navigation
351
325
  */
352
-
353
326
  interface LinkProps {
354
327
  href: string;
355
328
  children?: unknown;
@@ -364,7 +337,46 @@ interface LinkProps {
364
337
  * - Shift+click (opens in new window)
365
338
  * - Right-click context menu
366
339
  */
367
- declare function Link({ href, children }: LinkProps): JSXElement;
340
+ declare function Link({ href, children }: LinkProps): unknown;
341
+
342
+ /**
343
+ * Layout helper.
344
+ *
345
+ * A layout is just a normal component that wraps children.
346
+ * Persistence and reuse are handled by the runtime via component identity.
347
+ *
348
+ * This helper exists purely for readability and convention.
349
+ */
350
+ type LayoutComponent<P = object> = (props: P & {
351
+ children?: unknown;
352
+ }) => unknown;
353
+ declare function layout<P = object>(Layout: LayoutComponent<P>): (children?: unknown, props?: P) => unknown;
354
+
355
+ type SlotProps = {
356
+ asChild: true;
357
+ children: unknown;
358
+ [key: string]: unknown;
359
+ } | {
360
+ asChild?: false;
361
+ children?: unknown;
362
+ };
363
+ declare function Slot(props: SlotProps): unknown;
364
+
365
+ /**
366
+ * Portal / Host primitive.
367
+ *
368
+ * A portal is a named render slot within the existing tree.
369
+ * It does NOT create a second tree or touch the DOM directly.
370
+ */
371
+ interface Portal<T = unknown> {
372
+ /** Mount point — rendered exactly once */
373
+ (): unknown;
374
+ /** Render content into the portal */
375
+ render(props: {
376
+ children?: T;
377
+ }): unknown;
378
+ }
379
+ declare function definePortal<T = unknown>(): Portal<T>;
368
380
 
369
381
  type SSRData = Record<string, unknown>;
370
382
 
@@ -443,4 +455,4 @@ declare function renderToStream(opts: {
443
455
  onComplete(): void;
444
456
  }): void;
445
457
 
446
- export { type Context, type DataResult, type HydrateSPAConfig, type IslandConfig, Link, type LinkProps, Props, type Route, type RouteHandler, type RouteMatch, type RouteSnapshot, type SPAConfig, type State, cleanupApp, clearRoutes, collectResources, createApp, createIsland, createSPA, defineContext, getLoadedNamespaces, getNamespaceRoutes, getRoutes, getSignal, hasApp, hydrateSPA, layout, navigate, readContext, renderToStream, renderToString, renderToStringSync, renderToStringSyncForUrl, resolveResources, resource, route, scheduleEventHandler, setServerLocation, state, unloadNamespace };
458
+ export { type Context, type DataResult, type HydrateSPAConfig, type IslandConfig, type LayoutComponent, Link, type LinkProps, type Portal, Props, type Route, type RouteHandler, type RouteMatch, type RouteSnapshot, type SPAConfig, Slot, type SlotProps, type State, cleanupApp, clearRoutes, collectResources, createIsland, createSPA, defineContext, definePortal, derive, getLoadedNamespaces, getNamespaceRoutes, getRoutes, getSignal, hasApp, hydrateSPA, layout, navigate, readContext, renderToStream, renderToString, renderToStringSync, renderToStringSyncForUrl, resolveResources, resource, route, scheduleEventHandler, setServerLocation, state, task, unloadNamespace };