round-core 0.0.5 → 0.0.7

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 (43) hide show
  1. package/README.md +2 -2
  2. package/dist/cli.js +49 -0
  3. package/dist/index.d.ts +341 -0
  4. package/dist/vite-plugin.js +0 -31
  5. package/extension/.vscodeignore +5 -0
  6. package/extension/LICENSE +21 -0
  7. package/extension/cgmanifest.json +45 -0
  8. package/extension/extension.js +163 -0
  9. package/extension/images/round-config-dark.svg +10 -0
  10. package/extension/images/round-config-light.svg +10 -0
  11. package/extension/images/round-dark.svg +10 -0
  12. package/extension/images/round-light.svg +10 -0
  13. package/extension/javascript-language-configuration.json +241 -0
  14. package/extension/package-lock.json +97 -0
  15. package/extension/package.json +119 -0
  16. package/extension/package.nls.json +4 -0
  17. package/extension/round-0.1.0.vsix +0 -0
  18. package/extension/round-lsp/package-lock.json +185 -0
  19. package/extension/round-lsp/package.json +21 -0
  20. package/extension/round-lsp/src/round-transformer-lsp.js +248 -0
  21. package/extension/round-lsp/src/server.js +396 -0
  22. package/extension/snippets/javascript.code-snippets +266 -0
  23. package/extension/snippets/round.code-snippets +109 -0
  24. package/extension/syntaxes/JavaScript.tmLanguage.json +6001 -0
  25. package/extension/syntaxes/JavaScriptReact.tmLanguage.json +6066 -0
  26. package/extension/syntaxes/Readme.md +12 -0
  27. package/extension/syntaxes/Regular Expressions (JavaScript).tmLanguage +237 -0
  28. package/extension/syntaxes/Round.tmLanguage.json +290 -0
  29. package/extension/syntaxes/RoundInject.tmLanguage.json +20 -0
  30. package/extension/tags-language-configuration.json +152 -0
  31. package/extension/temp_astro/package-lock.json +912 -0
  32. package/extension/temp_astro/package.json +16 -0
  33. package/extension/types/round-core.d.ts +326 -0
  34. package/package.json +2 -1
  35. package/src/cli.js +53 -0
  36. package/src/compiler/vite-plugin.js +0 -35
  37. package/src/index.d.ts +341 -0
  38. package/src/runtime/context.js +12 -0
  39. package/src/runtime/dom.js +10 -0
  40. package/src/runtime/router.js +28 -0
  41. package/src/runtime/signals.js +38 -0
  42. package/src/runtime/store.js +7 -0
  43. package/vite.config.build.js +12 -0
package/src/index.d.ts ADDED
@@ -0,0 +1,341 @@
1
+ /**
2
+ * Round Framework Type Definitions
3
+ */
4
+
5
+ export interface RoundSignal<T> {
6
+ /**
7
+ * Get or set the current value.
8
+ */
9
+ (newValue?: T): T;
10
+
11
+ /**
12
+ * Get the current value (reactive).
13
+ */
14
+ value: T;
15
+
16
+ /**
17
+ * Get the current value without tracking dependencies.
18
+ */
19
+ peek(): T;
20
+
21
+ /**
22
+ * Creates a transformed view of this signal.
23
+ */
24
+ transform<U>(fromInput: (v: U) => T, toOutput: (v: T) => U): RoundSignal<U>;
25
+
26
+ /**
27
+ * Attaches validation logic to the signal.
28
+ */
29
+ validate(validator: (next: T, prev: T) => string | boolean | undefined | null, options?: {
30
+ /** Timing of validation: 'input' (default) or 'blur'. */
31
+ validateOn?: 'input' | 'blur';
32
+ /** Whether to run validation immediately on startup. */
33
+ validateInitial?: boolean;
34
+ }): RoundSignal<T> & {
35
+ /** Signal containing the current validation error message. */
36
+ error: RoundSignal<string | null>;
37
+ /** Manually trigger validation check. Returns true if valid. */
38
+ check(): boolean
39
+ };
40
+
41
+ /**
42
+ * Creates a read/write view of a specific property path.
43
+ */
44
+ $pick<K extends keyof T>(path: K): RoundSignal<T[K]>;
45
+ $pick(path: string | string[]): RoundSignal<any>;
46
+
47
+ /**
48
+ * Internal: marks the signal as bindable for two-way bindings.
49
+ */
50
+ bind?: boolean;
51
+ }
52
+
53
+ export interface Signal {
54
+ <T>(initialValue?: T): RoundSignal<T>;
55
+ object<T extends object>(initialState: T): { [K in keyof T]: RoundSignal<T[K]> };
56
+ }
57
+
58
+ /**
59
+ * Creates a reactive signal.
60
+ */
61
+ export const signal: Signal;
62
+
63
+ /**
64
+ * Creates a bindable signal intended for two-way DOM bindings.
65
+ */
66
+ export interface Bindable {
67
+ <T>(initialValue?: T): RoundSignal<T>;
68
+ object<T extends object>(initialState: T): { [K in keyof T]: RoundSignal<T[K]> };
69
+ }
70
+
71
+ /**
72
+ * Creates a bindable signal intended for two-way DOM bindings.
73
+ */
74
+ export const bindable: Bindable;
75
+
76
+ /**
77
+ * Run a function without tracking any signals it reads.
78
+ * Any signals accessed inside the function will not become dependencies of the current effect.
79
+ */
80
+ export function untrack<T>(fn: () => T): T;
81
+
82
+ /**
83
+ * Create a reactive side-effect that runs whenever its signal dependencies change.
84
+ */
85
+ export function effect(fn: () => void | (() => void), options?: {
86
+ /** If false, the effect won't run immediately on creation. Defaults to true. */
87
+ onLoad?: boolean
88
+ }): () => void;
89
+
90
+ /**
91
+ * Create a reactive side-effect with explicit dependencies.
92
+ */
93
+ export function effect(deps: any[], fn: () => void | (() => void), options?: {
94
+ /** If false, the effect won't run immediately on creation. Defaults to true. */
95
+ onLoad?: boolean
96
+ }): () => void;
97
+
98
+ /**
99
+ * Create a read-only computed signal derived from other signals.
100
+ */
101
+ export function derive<T>(fn: () => T): () => T;
102
+
103
+ /**
104
+ * Create a read/write view of a specific path within a signal object.
105
+ */
106
+ export function pick<T = any>(root: RoundSignal<any>, path: string | string[]): RoundSignal<T>;
107
+
108
+ /**
109
+ * Store API
110
+ */
111
+ export interface RoundStore<T> {
112
+ /**
113
+ * Access a specific key from the store as a bindable signal.
114
+ */
115
+ use<K extends keyof T>(key: K): RoundSignal<T[K]>;
116
+
117
+ /**
118
+ * Update a specific key in the store.
119
+ */
120
+ set<K extends keyof T>(key: K, value: T[K]): T[K];
121
+
122
+ /**
123
+ * Batch update multiple keys in the store.
124
+ */
125
+ patch(obj: Partial<T>): void;
126
+
127
+ /**
128
+ * Get a snapshot of the current state.
129
+ */
130
+ snapshot(options?: {
131
+ /** If true, the returned values will be reactive signals. */
132
+ reactive?: boolean
133
+ }): T;
134
+
135
+ /**
136
+ * Enable persistence for the store.
137
+ */
138
+ persist(storageKey: string, options?: {
139
+ /** The storage implementation (defaults to localStorage). */
140
+ storage?: Storage;
141
+ /** Debounce time in milliseconds for writes. */
142
+ debounce?: number;
143
+ /** Array of keys to exclude from persistence. */
144
+ exclude?: string[];
145
+ }): RoundStore<T>;
146
+
147
+ /**
148
+ * Action methods defined during store creation.
149
+ */
150
+ actions: Record<string, Function>;
151
+ }
152
+
153
+ /**
154
+ * Create a shared global state store with actions and optional persistence.
155
+ */
156
+ export function createStore<T, A extends Record<string, (state: T, ...args: any[]) => Partial<T> | void>>(
157
+ initialState: T,
158
+ actions?: A
159
+ ): RoundStore<T> & { [K in keyof A]: (...args: Parameters<A[K]> extends [any, ...infer P] ? P : never) => any };
160
+
161
+ /**
162
+ * Router API
163
+ */
164
+ export interface RouteProps {
165
+ /** The path to match. Must start with a forward slash. */
166
+ route?: string;
167
+ /** If true, only matches if the path is exactly the same. */
168
+ exact?: boolean;
169
+ /** Page title to set in the document header when active. */
170
+ title?: string;
171
+ /** Meta description to set in the document header when active. */
172
+ description?: string;
173
+ /** Advanced head configuration including links and meta tags. */
174
+ head?: any;
175
+ /** Fragment or elements to render when matched. */
176
+ children?: any;
177
+ }
178
+
179
+ /**
180
+ * Define a route that renders its children when the path matches.
181
+ */
182
+ export function Route(props: RouteProps): any;
183
+
184
+ /**
185
+ * An alias for Route, typically used for top-level pages.
186
+ */
187
+ export function Page(props: RouteProps): any;
188
+
189
+ export interface LinkProps {
190
+ /** The destination path. */
191
+ href: string;
192
+ /** Alias for href. */
193
+ to?: string;
194
+ /** Use SPA navigation (prevents full page reloads). Defaults to true. */
195
+ spa?: boolean;
196
+ /** Force a full page reload on navigation. */
197
+ reload?: boolean;
198
+ /** Custom click event handler. */
199
+ onClick?: (e: MouseEvent) => void;
200
+ /** Link content (text or elements). */
201
+ children?: any;
202
+ [key: string]: any;
203
+ }
204
+
205
+ /**
206
+ * A standard link component that performs SPA navigation.
207
+ */
208
+ export function Link(props: LinkProps): any;
209
+
210
+ /**
211
+ * Define a fallback component or content for when no routes match.
212
+ */
213
+ export function NotFound(props: {
214
+ /** Optional component to render for the 404 state. */
215
+ component?: any;
216
+ /** Fallback content. ignored if 'component' is provided. */
217
+ children?: any
218
+ }): any;
219
+
220
+ /**
221
+ * Navigate to a different path programmatically.
222
+ */
223
+ export function navigate(to: string, options?: {
224
+ /** If true, replaces the current history entry instead of pushing. */
225
+ replace?: boolean
226
+ }): void;
227
+
228
+ /**
229
+ * Hook to get a reactive function returning the current normalized pathname.
230
+ */
231
+ export function usePathname(): () => string;
232
+
233
+ /**
234
+ * Get the current normalized pathname.
235
+ */
236
+ export function getPathname(): string;
237
+
238
+ /**
239
+ * Hook to get a reactive function returning the current location object.
240
+ */
241
+ export function useLocation(): () => { pathname: string; search: string; hash: string };
242
+
243
+ /**
244
+ * Get the current location object (pathname, search, hash).
245
+ */
246
+ export function getLocation(): { pathname: string; search: string; hash: string };
247
+
248
+ /**
249
+ * Hook to get a reactive function returning whether the current path has no matches.
250
+ */
251
+ export function useIsNotFound(): () => boolean;
252
+
253
+ /**
254
+ * Get whether the current path is NOT matched by any defined route.
255
+ */
256
+ export function getIsNotFound(): boolean;
257
+
258
+ /**
259
+ * DOM & Context API
260
+ */
261
+
262
+ /**
263
+ * Create a DOM element or instance a component.
264
+ */
265
+ export function createElement(tag: any, props?: any, ...children: any[]): any;
266
+
267
+ /**
268
+ * A grouping component that returns its children without a wrapper element.
269
+ */
270
+ export function Fragment(props: { children?: any }): any;
271
+
272
+ export interface Context<T> {
273
+ /** Internal identifier for the context. */
274
+ id: number;
275
+ /** Default value used when no Provider is found in the tree. */
276
+ defaultValue: T;
277
+ /** Component that provides a value to all its descendants. */
278
+ Provider: (props: { value: T; children?: any }) => any;
279
+ }
280
+
281
+ /**
282
+ * Create a new Context object for sharing state between components.
283
+ */
284
+ export function createContext<T>(defaultValue?: T): Context<T>;
285
+
286
+ /**
287
+ * Read the current value of a context from the component tree.
288
+ */
289
+ export function readContext<T>(ctx: Context<T>): T;
290
+
291
+ /**
292
+ * Returns a reactive function that reads the current context value.
293
+ */
294
+ export function bindContext<T>(ctx: Context<T>): () => T;
295
+
296
+ /**
297
+ * Async & Code Splitting
298
+ */
299
+
300
+ /**
301
+ * Mark a component for lazy loading (code-splitting).
302
+ * Expects a function returning a dynamic import promise.
303
+ */
304
+ export function lazy<T>(fn: () => Promise<{ default: T } | T>): any;
305
+
306
+ declare module "*.round";
307
+
308
+ export interface SuspenseProps {
309
+ /** Content to show while children (e.g. lazy components) are loading. */
310
+ fallback: any;
311
+ /** Content that might trigger a loading state. */
312
+ children?: any;
313
+ }
314
+
315
+ /**
316
+ * Component that boundaries async operations and renders a fallback while loading.
317
+ */
318
+ export function Suspense(props: SuspenseProps): any;
319
+
320
+ /**
321
+ * Head Management
322
+ */
323
+
324
+ /**
325
+ * Define static head metadata (titles, meta tags, favicons, etc.).
326
+ */
327
+ export function startHead(head: any): any;
328
+
329
+ /**
330
+ * Markdown
331
+ */
332
+
333
+ /**
334
+ * Component that renders Markdown content into HTML.
335
+ */
336
+ export function Markdown(props: {
337
+ /** The markdown string or a function returning it. */
338
+ content: string | (() => string);
339
+ /** Remark/Rehype configuration options. */
340
+ options?: any
341
+ }): any;
@@ -11,6 +11,12 @@ function popContext() {
11
11
  contextStack.pop();
12
12
  }
13
13
 
14
+ /**
15
+ * Read the current value of a context from the tree.
16
+ * @template T
17
+ * @param {Context<T>} ctx The context object.
18
+ * @returns {T} The current context value.
19
+ */
14
20
  export function readContext(ctx) {
15
21
  for (let i = contextStack.length - 1; i >= 0; i--) {
16
22
  const layer = contextStack[i];
@@ -21,6 +27,12 @@ export function readContext(ctx) {
21
27
  return ctx.defaultValue;
22
28
  }
23
29
 
30
+ /**
31
+ * Create a new Context object for sharing state between components.
32
+ * @template T
33
+ * @param {T} [defaultValue] The value used when no provider is found.
34
+ * @returns {Context<T>} The context object with a `Provider` component.
35
+ */
24
36
  export function createContext(defaultValue) {
25
37
  const ctx = {
26
38
  id: nextContextId++,
@@ -29,6 +29,13 @@ function warnSignalDirectUsage(fn, kind) {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * Create a DOM element or instance a component.
34
+ * @param {string | Function} tag HTML tag name or Component function.
35
+ * @param {object} [props] Element attributes or component props.
36
+ * @param {...any} children Child nodes.
37
+ * @returns {Node} The resulting DOM node.
38
+ */
32
39
  export function createElement(tag, props = {}, ...children) {
33
40
  if (typeof tag === 'function') {
34
41
  const componentInstance = createComponentInstance();
@@ -388,6 +395,9 @@ function appendChild(parent, child) {
388
395
  }
389
396
  }
390
397
 
398
+ /**
399
+ * A grouping component that returns its children without a wrapper element.
400
+ */
391
401
  export function Fragment(props) {
392
402
  return props.children;
393
403
  }
@@ -127,6 +127,11 @@ function mountAutoNotFound() {
127
127
  root.appendChild(view);
128
128
  }
129
129
 
130
+ /**
131
+ * Navigate to a different path programmatically.
132
+ * @param {string} to The destination URL or path.
133
+ * @param {object} [options] Navigation options (e.g., { replace: true }).
134
+ */
130
135
  export function navigate(to, options = {}) {
131
136
  if (!hasWindow) return;
132
137
  ensureListener();
@@ -264,6 +269,15 @@ export function setNotFound(Component) {
264
269
  defaultNotFoundComponent = Component;
265
270
  }
266
271
 
272
+ /**
273
+ * Define a route that renders its children when the path matches.
274
+ * @param {object} props Route properties.
275
+ * @param {string} [props.route='/'] The path to match.
276
+ * @param {boolean} [props.exact] Whether to use exact matching.
277
+ * @param {string} [props.title] Page title to set when active.
278
+ * @param {string} [props.description] Meta description to set when active.
279
+ * @param {any} [props.children] Content to render.
280
+ */
267
281
  export function Route(props = {}) {
268
282
  ensureListener();
269
283
 
@@ -319,6 +333,10 @@ export function Route(props = {}) {
319
333
  });
320
334
  }
321
335
 
336
+ /**
337
+ * An alias for Route, typically used for top-level pages.
338
+ * @param {object} props Page properties (same as Route).
339
+ */
322
340
  export function Page(props = {}) {
323
341
  ensureListener();
324
342
 
@@ -371,6 +389,9 @@ export function Page(props = {}) {
371
389
  });
372
390
  }
373
391
 
392
+ /**
393
+ * Define a fallback component or content for when no routes match.
394
+ */
374
395
  export function NotFound(props = {}) {
375
396
  ensureListener();
376
397
 
@@ -402,6 +423,13 @@ export function NotFound(props = {}) {
402
423
  });
403
424
  }
404
425
 
426
+ /**
427
+ * A standard link component that performs SPA navigation.
428
+ * @param {object} props Link properties.
429
+ * @param {string} [props.href] The destination path.
430
+ * @param {boolean} [props.spa=true] Use SPA navigation (prevents reload).
431
+ * @param {any} [props.children] Link content.
432
+ */
405
433
  export function Link(props = {}) {
406
434
  ensureListener();
407
435
 
@@ -12,6 +12,13 @@ function subscribe(running, subscriptions) {
12
12
  running.dependencies.add(subscriptions);
13
13
  }
14
14
 
15
+ /**
16
+ * Run a function without tracking any signals it reads.
17
+ * Any signals accessed inside `fn` will not become dependencies of the current effect.
18
+ * @template T
19
+ * @param {() => T} fn The function to execute.
20
+ * @returns {T} The return value of `fn`.
21
+ */
15
22
  export function untrack(fn) {
16
23
  context.push(null);
17
24
  try {
@@ -21,6 +28,13 @@ export function untrack(fn) {
21
28
  }
22
29
  }
23
30
 
31
+ /**
32
+ * Create a reactive side-effect that runs whenever its signal dependencies change.
33
+ * @param {(() => any) | any[]} arg1 Either the callback function or an array of explicit dependencies.
34
+ * @param {(() => any)} [arg2] The callback function if the first argument was explicit dependencies.
35
+ * @param {object} [arg3] Optional configuration (e.g., { onLoad: false }).
36
+ * @returns {() => void} A function to stop and cleanup the effect.
37
+ */
24
38
  export function effect(arg1, arg2, arg3) {
25
39
  let callback;
26
40
  let explicitDeps = null;
@@ -241,6 +255,12 @@ function attachHelpers(s) {
241
255
  return s;
242
256
  }
243
257
 
258
+ /**
259
+ * Create a reactive signal.
260
+ * @template T
261
+ * @param {T} [initialValue] The starting value.
262
+ * @returns {RoundSignal<T>} A signal function that reads/writes the value.
263
+ */
244
264
  export function signal(initialValue) {
245
265
  let value = initialValue;
246
266
  const subscriptions = new Set();
@@ -285,6 +305,12 @@ export function signal(initialValue) {
285
305
  return attachHelpers(signal);
286
306
  }
287
307
 
308
+ /**
309
+ * Create a bindable signal intended for two-way DOM bindings.
310
+ * @template T
311
+ * @param {T} [initialValue] The starting value.
312
+ * @returns {RoundSignal<T>} A signal function marked as bindable.
313
+ */
288
314
  export function bindable(initialValue) {
289
315
  const s = signal(initialValue);
290
316
  try {
@@ -345,6 +371,12 @@ function parsePath(path) {
345
371
  return [String(path)];
346
372
  }
347
373
 
374
+ /**
375
+ * Create a read/write view of a specific path within a signal object.
376
+ * @param {RoundSignal<any>} root The source signal.
377
+ * @param {string | string[]} path The property path (e.g., 'user.profile.name' or ['user', 'profile', 'name']).
378
+ * @returns {RoundSignal<any>} A signal-like view of the path.
379
+ */
348
380
  export function pick(root, path) {
349
381
  if (!isSignalLike(root)) {
350
382
  throw new Error('[round] pick(root, path) expects root to be a signal (use bindable.object(...) or signal({...})).');
@@ -499,6 +531,12 @@ bindable.object = function (initialObject = {}) {
499
531
  return createBindableObjectProxy(root, []);
500
532
  };
501
533
 
534
+ /**
535
+ * Create a read-only computed signal derived from other signals.
536
+ * @template T
537
+ * @param {() => T} fn A function that computes the value.
538
+ * @returns {(() => T)} A function that returns the derived value.
539
+ */
502
540
  export function derive(fn) {
503
541
  const derived = signal();
504
542
 
@@ -5,6 +5,13 @@ function hasWindow() {
5
5
  return typeof window !== 'undefined' && typeof document !== 'undefined';
6
6
  }
7
7
 
8
+ /**
9
+ * Create a shared global state store with actions and optional persistence.
10
+ * @template T
11
+ * @param {T} [initialState={}] Initial state object.
12
+ * @param {Record<string, (state: T, ...args: any[]) => any>} [actions] Action reducers.
13
+ * @returns {RoundStore<T>} The store object.
14
+ */
8
15
  export function createStore(initialState = {}, actions = null) {
9
16
  const state = (initialState && typeof initialState === 'object') ? initialState : {};
10
17
  const signals = Object.create(null);
@@ -33,4 +33,16 @@ export default defineConfig({
33
33
  }
34
34
  },
35
35
  },
36
+ plugins: [
37
+ {
38
+ name: 'copy-dts',
39
+ closeBundle() {
40
+ const src = path.resolve(__dirname, 'src/index.d.ts');
41
+ const dest = path.resolve(__dirname, 'dist/index.d.ts');
42
+ if (fs.existsSync(src)) {
43
+ fs.copyFileSync(src, dest);
44
+ }
45
+ }
46
+ }
47
+ ]
36
48
  });