create-flow-os 0.0.1-dev.1771840262 → 0.0.1-dev.1771979366

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 (230) hide show
  1. package/package.json +8 -23
  2. package/{profiles/server/packages/style → src/create}/index.ts +31 -30
  3. package/src/index.ts +14 -0
  4. package/src/init/index.ts +66 -0
  5. package/src/init/lib.ts +36 -0
  6. package/src/init/scaffold.ts +43 -0
  7. package/LICENSE +0 -97
  8. package/README.md +0 -26
  9. package/bin/index.js +0 -1215
  10. package/config.json +0 -89
  11. package/lib/utils.ts +0 -91
  12. package/packages/client/client/root.css +0 -9
  13. package/packages/client/client/root.tsx +0 -6
  14. package/packages/client/client/routes/404.tsx +0 -24
  15. package/packages/client/client/routes/index.tsx +0 -48
  16. package/packages/server/server/routes/hello.get.ts +0 -3
  17. package/profiles/client/.dockerignore +0 -12
  18. package/profiles/client/.oxfmtrc.json +0 -7
  19. package/profiles/client/.oxlintrc.json +0 -13
  20. package/profiles/client/.vscode/settings.json +0 -12
  21. package/profiles/client/Dockerfile +0 -26
  22. package/profiles/client/README.md +0 -34
  23. package/profiles/client/bun.lock +0 -352
  24. package/profiles/client/client/root.css +0 -9
  25. package/profiles/client/client/root.tsx +0 -6
  26. package/profiles/client/client/routes/404.tsx +0 -24
  27. package/profiles/client/client/routes/about.tsx +0 -7
  28. package/profiles/client/client/routes/index.tsx +0 -48
  29. package/profiles/client/flow.config.ts +0 -6
  30. package/profiles/client/index.html +0 -5
  31. package/profiles/client/package.json +0 -32
  32. package/profiles/client/packages/client/LICENSE +0 -97
  33. package/profiles/client/packages/client/build/config.ts +0 -211
  34. package/profiles/client/packages/client/build/vite.ts +0 -98
  35. package/profiles/client/packages/client/features/attrs.ts +0 -32
  36. package/profiles/client/packages/client/features/class-flow.ts +0 -116
  37. package/profiles/client/packages/client/features/index.ts +0 -8
  38. package/profiles/client/packages/client/features/pseudo-injector.ts +0 -40
  39. package/profiles/client/packages/client/features/style-flow.ts +0 -106
  40. package/profiles/client/packages/client/features/style.ts +0 -27
  41. package/profiles/client/packages/client/features/utils.ts +0 -4
  42. package/profiles/client/packages/client/features/viewport.ts +0 -20
  43. package/profiles/client/packages/client/index.ts +0 -7
  44. package/profiles/client/packages/client/package.json +0 -48
  45. package/profiles/client/packages/client/runtime/dom.ts +0 -2
  46. package/profiles/client/packages/client/runtime/jsx-dev-runtime.ts +0 -1
  47. package/profiles/client/packages/client/runtime/jsx-runtime.ts +0 -1
  48. package/profiles/client/packages/client/runtime/jsx-types.d.ts +0 -66
  49. package/profiles/client/packages/client/runtime/jsx.ts +0 -101
  50. package/profiles/client/packages/client/scripts/build.ts +0 -14
  51. package/profiles/client/packages/client/scripts/preview.ts +0 -14
  52. package/profiles/client/packages/client/scripts/start-dev.ts +0 -49
  53. package/profiles/client/packages/core/LICENSE +0 -97
  54. package/profiles/client/packages/core/dom.ts +0 -43
  55. package/profiles/client/packages/core/for.ts +0 -42
  56. package/profiles/client/packages/core/index.ts +0 -5
  57. package/profiles/client/packages/core/lifecycle.ts +0 -6
  58. package/profiles/client/packages/core/package.json +0 -16
  59. package/profiles/client/packages/core/show-switch.ts +0 -56
  60. package/profiles/client/packages/core/state.ts +0 -56
  61. package/profiles/client/packages/router/LICENSE +0 -97
  62. package/profiles/client/packages/router/index.ts +0 -20
  63. package/profiles/client/packages/router/matcher.ts +0 -105
  64. package/profiles/client/packages/router/package.json +0 -15
  65. package/profiles/client/packages/router/router.ts +0 -185
  66. package/profiles/client/packages/router/types.ts +0 -34
  67. package/profiles/client/packages/router/utils.ts +0 -45
  68. package/profiles/client/packages/style/LICENSE +0 -97
  69. package/profiles/client/packages/style/breakpoints.ts +0 -20
  70. package/profiles/client/packages/style/extension/.vscodeignore +0 -5
  71. package/profiles/client/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
  72. package/profiles/client/packages/style/extension/out/extension.js +0 -130
  73. package/profiles/client/packages/style/extension/package.json +0 -24
  74. package/profiles/client/packages/style/extension/src/extension.ts +0 -146
  75. package/profiles/client/packages/style/extension/tsconfig.json +0 -12
  76. package/profiles/client/packages/style/index.ts +0 -30
  77. package/profiles/client/packages/style/package.json +0 -20
  78. package/profiles/client/packages/style/react.ts +0 -68
  79. package/profiles/client/packages/style/resolve.ts +0 -127
  80. package/profiles/client/packages/style/server.ts +0 -299
  81. package/profiles/client/packages/style/shorthand.ts +0 -96
  82. package/profiles/client/packages/style/style-builder/button.ts +0 -41
  83. package/profiles/client/packages/style/style-builder/constants.ts +0 -16
  84. package/profiles/client/packages/style/style-builder/dom.ts +0 -18
  85. package/profiles/client/packages/style/style-builder/index.ts +0 -48
  86. package/profiles/client/packages/style/style-builder/panel.ts +0 -69
  87. package/profiles/client/packages/style/style-builder/position.ts +0 -25
  88. package/profiles/client/packages/style/visual-builder.ts +0 -822
  89. package/profiles/client/packages/style/vite-plugin.ts +0 -86
  90. package/profiles/client/tsconfig.json +0 -30
  91. package/profiles/full/.dockerignore +0 -12
  92. package/profiles/full/.oxfmtrc.json +0 -7
  93. package/profiles/full/.oxlintrc.json +0 -13
  94. package/profiles/full/.vscode/settings.json +0 -12
  95. package/profiles/full/Dockerfile +0 -26
  96. package/profiles/full/README.md +0 -34
  97. package/profiles/full/bun.lock +0 -352
  98. package/profiles/full/client/root.css +0 -9
  99. package/profiles/full/client/root.tsx +0 -6
  100. package/profiles/full/client/routes/404.tsx +0 -24
  101. package/profiles/full/client/routes/about.tsx +0 -7
  102. package/profiles/full/client/routes/index.tsx +0 -48
  103. package/profiles/full/flow.config.ts +0 -6
  104. package/profiles/full/index.html +0 -5
  105. package/profiles/full/package.json +0 -33
  106. package/profiles/full/packages/client/LICENSE +0 -97
  107. package/profiles/full/packages/client/build/config.ts +0 -211
  108. package/profiles/full/packages/client/build/vite.ts +0 -98
  109. package/profiles/full/packages/client/features/attrs.ts +0 -32
  110. package/profiles/full/packages/client/features/class-flow.ts +0 -116
  111. package/profiles/full/packages/client/features/index.ts +0 -8
  112. package/profiles/full/packages/client/features/pseudo-injector.ts +0 -40
  113. package/profiles/full/packages/client/features/style-flow.ts +0 -106
  114. package/profiles/full/packages/client/features/style.ts +0 -27
  115. package/profiles/full/packages/client/features/utils.ts +0 -4
  116. package/profiles/full/packages/client/features/viewport.ts +0 -20
  117. package/profiles/full/packages/client/index.ts +0 -7
  118. package/profiles/full/packages/client/package.json +0 -48
  119. package/profiles/full/packages/client/runtime/dom.ts +0 -2
  120. package/profiles/full/packages/client/runtime/jsx-dev-runtime.ts +0 -1
  121. package/profiles/full/packages/client/runtime/jsx-runtime.ts +0 -1
  122. package/profiles/full/packages/client/runtime/jsx-types.d.ts +0 -66
  123. package/profiles/full/packages/client/runtime/jsx.ts +0 -101
  124. package/profiles/full/packages/client/scripts/build.ts +0 -14
  125. package/profiles/full/packages/client/scripts/preview.ts +0 -14
  126. package/profiles/full/packages/client/scripts/start-dev.ts +0 -49
  127. package/profiles/full/packages/core/LICENSE +0 -97
  128. package/profiles/full/packages/core/dom.ts +0 -43
  129. package/profiles/full/packages/core/for.ts +0 -42
  130. package/profiles/full/packages/core/index.ts +0 -5
  131. package/profiles/full/packages/core/lifecycle.ts +0 -6
  132. package/profiles/full/packages/core/package.json +0 -16
  133. package/profiles/full/packages/core/show-switch.ts +0 -56
  134. package/profiles/full/packages/core/state.ts +0 -56
  135. package/profiles/full/packages/router/LICENSE +0 -97
  136. package/profiles/full/packages/router/index.ts +0 -20
  137. package/profiles/full/packages/router/matcher.ts +0 -105
  138. package/profiles/full/packages/router/package.json +0 -15
  139. package/profiles/full/packages/router/router.ts +0 -185
  140. package/profiles/full/packages/router/types.ts +0 -34
  141. package/profiles/full/packages/router/utils.ts +0 -45
  142. package/profiles/full/packages/server/LICENSE +0 -97
  143. package/profiles/full/packages/server/core.ts +0 -140
  144. package/profiles/full/packages/server/index.ts +0 -24
  145. package/profiles/full/packages/server/package.json +0 -32
  146. package/profiles/full/packages/server/plugin.ts +0 -79
  147. package/profiles/full/packages/server/production.ts +0 -75
  148. package/profiles/full/packages/server/scripts/start.ts +0 -11
  149. package/profiles/full/packages/style/LICENSE +0 -97
  150. package/profiles/full/packages/style/breakpoints.ts +0 -20
  151. package/profiles/full/packages/style/extension/.vscodeignore +0 -5
  152. package/profiles/full/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
  153. package/profiles/full/packages/style/extension/out/extension.js +0 -130
  154. package/profiles/full/packages/style/extension/package.json +0 -24
  155. package/profiles/full/packages/style/extension/src/extension.ts +0 -146
  156. package/profiles/full/packages/style/extension/tsconfig.json +0 -12
  157. package/profiles/full/packages/style/index.ts +0 -30
  158. package/profiles/full/packages/style/package.json +0 -20
  159. package/profiles/full/packages/style/react.ts +0 -68
  160. package/profiles/full/packages/style/resolve.ts +0 -127
  161. package/profiles/full/packages/style/server.ts +0 -299
  162. package/profiles/full/packages/style/shorthand.ts +0 -96
  163. package/profiles/full/packages/style/style-builder/button.ts +0 -41
  164. package/profiles/full/packages/style/style-builder/constants.ts +0 -16
  165. package/profiles/full/packages/style/style-builder/dom.ts +0 -18
  166. package/profiles/full/packages/style/style-builder/index.ts +0 -48
  167. package/profiles/full/packages/style/style-builder/panel.ts +0 -69
  168. package/profiles/full/packages/style/style-builder/position.ts +0 -25
  169. package/profiles/full/packages/style/visual-builder.ts +0 -822
  170. package/profiles/full/packages/style/vite-plugin.ts +0 -86
  171. package/profiles/full/server/routes/hello.get.ts +0 -3
  172. package/profiles/full/tsconfig.json +0 -30
  173. package/profiles/server/.dockerignore +0 -12
  174. package/profiles/server/.oxfmtrc.json +0 -7
  175. package/profiles/server/.oxlintrc.json +0 -13
  176. package/profiles/server/.vscode/settings.json +0 -12
  177. package/profiles/server/Dockerfile +0 -26
  178. package/profiles/server/README.md +0 -34
  179. package/profiles/server/bun.lock +0 -352
  180. package/profiles/server/flow.config.ts +0 -7
  181. package/profiles/server/index.html +0 -5
  182. package/profiles/server/package.json +0 -30
  183. package/profiles/server/packages/core/LICENSE +0 -97
  184. package/profiles/server/packages/core/dom.ts +0 -43
  185. package/profiles/server/packages/core/for.ts +0 -42
  186. package/profiles/server/packages/core/index.ts +0 -5
  187. package/profiles/server/packages/core/lifecycle.ts +0 -6
  188. package/profiles/server/packages/core/package.json +0 -16
  189. package/profiles/server/packages/core/show-switch.ts +0 -56
  190. package/profiles/server/packages/core/state.ts +0 -56
  191. package/profiles/server/packages/router/LICENSE +0 -97
  192. package/profiles/server/packages/router/index.ts +0 -20
  193. package/profiles/server/packages/router/matcher.ts +0 -105
  194. package/profiles/server/packages/router/package.json +0 -15
  195. package/profiles/server/packages/router/router.ts +0 -185
  196. package/profiles/server/packages/router/types.ts +0 -34
  197. package/profiles/server/packages/router/utils.ts +0 -45
  198. package/profiles/server/packages/server/LICENSE +0 -97
  199. package/profiles/server/packages/server/core.ts +0 -140
  200. package/profiles/server/packages/server/index.ts +0 -24
  201. package/profiles/server/packages/server/package.json +0 -32
  202. package/profiles/server/packages/server/plugin.ts +0 -79
  203. package/profiles/server/packages/server/production.ts +0 -75
  204. package/profiles/server/packages/server/scripts/start.ts +0 -11
  205. package/profiles/server/packages/style/LICENSE +0 -97
  206. package/profiles/server/packages/style/breakpoints.ts +0 -20
  207. package/profiles/server/packages/style/extension/.vscodeignore +0 -5
  208. package/profiles/server/packages/style/extension/flow-style-colors-0.0.1.vsix +0 -0
  209. package/profiles/server/packages/style/extension/out/extension.js +0 -130
  210. package/profiles/server/packages/style/extension/package.json +0 -24
  211. package/profiles/server/packages/style/extension/src/extension.ts +0 -146
  212. package/profiles/server/packages/style/extension/tsconfig.json +0 -12
  213. package/profiles/server/packages/style/package.json +0 -20
  214. package/profiles/server/packages/style/react.ts +0 -68
  215. package/profiles/server/packages/style/resolve.ts +0 -127
  216. package/profiles/server/packages/style/server.ts +0 -299
  217. package/profiles/server/packages/style/shorthand.ts +0 -96
  218. package/profiles/server/packages/style/style-builder/button.ts +0 -41
  219. package/profiles/server/packages/style/style-builder/constants.ts +0 -16
  220. package/profiles/server/packages/style/style-builder/dom.ts +0 -18
  221. package/profiles/server/packages/style/style-builder/index.ts +0 -48
  222. package/profiles/server/packages/style/style-builder/panel.ts +0 -69
  223. package/profiles/server/packages/style/style-builder/position.ts +0 -25
  224. package/profiles/server/packages/style/visual-builder.ts +0 -822
  225. package/profiles/server/packages/style/vite-plugin.ts +0 -86
  226. package/profiles/server/server/routes/hello.get.ts +0 -3
  227. package/profiles/server/tsconfig.json +0 -30
  228. package/templates/flow.config.client.ts +0 -6
  229. package/templates/flow.config.full.ts +0 -6
  230. package/templates/flow.config.server.ts +0 -7
@@ -1,6 +0,0 @@
1
- /** Esegue il callback dopo il mount (microtask: subito dopo il sync corrente). */
2
- export function onMount(fn: () => void): void {
3
- queueMicrotask(fn);
4
- }
5
-
6
- export { onCleanup } from './state.js';
@@ -1,16 +0,0 @@
1
- {
2
- "name": "@flow.os/core",
3
- "version": "0.0.5",
4
- "license": "PolyForm-Shield-1.0.0",
5
- "type": "module",
6
- "main": "./index.ts",
7
- "types": "./index.ts",
8
- "dependencies": {},
9
- "exports": {
10
- ".": {
11
- "types": "./index.ts",
12
- "import": "./index.ts",
13
- "default": "./index.ts"
14
- }
15
- }
16
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * Show: rendering condizionale (when/fallback).
3
- * Switch: primo branch con when() truthy, altrimenti fallback.
4
- */
5
- import { effect } from './state.js';
6
- import { setContent } from './dom.js';
7
-
8
- function isGetter(fn: unknown): fn is () => unknown {
9
- return typeof fn === 'function' && fn.length === 0;
10
- }
11
-
12
- /** Show: quando when() è truthy mostra children, altrimenti fallback. */
13
- export function Show(props: {
14
- when: (() => unknown) | unknown;
15
- fallback?: unknown;
16
- children?: unknown;
17
- }): HTMLElement {
18
- const wrapper = document.createElement('span');
19
- wrapper.style.display = 'contents';
20
- const getWhen = isGetter(props.when) ? props.when : () => props.when;
21
- effect(() => {
22
- setContent(wrapper, getWhen() ? props.children : props.fallback);
23
- });
24
- return wrapper;
25
- }
26
-
27
- export type MatchBranch = { when: () => boolean; children: unknown };
28
-
29
- /** Switch: primo branch con when() truthy, altrimenti fallback. branches = [{ when, children }, ...]. */
30
- export function Switch(props: {
31
- fallback?: unknown;
32
- branches: MatchBranch[];
33
- }): HTMLElement {
34
- const wrapper = document.createElement('span');
35
- wrapper.style.display = 'contents';
36
- effect(() => {
37
- const list = props.branches;
38
- for (let i = 0; i < list.length; i++) {
39
- const b = list[i];
40
- if (b === undefined) continue;
41
- const cond = isGetter(b.when) ? b.when() : b.when;
42
- if (cond) {
43
- setContent(wrapper, b.children);
44
- return;
45
- }
46
- }
47
- setContent(wrapper, props.fallback);
48
- });
49
- return wrapper;
50
- }
51
-
52
- /** Helper per costruire i branch di Switch: Match({ when: () => cond, children: <Node/> }) => branch. */
53
- export function Match(props: { when: (() => boolean) | boolean; children?: unknown }): MatchBranch {
54
- const whenFn = isGetter(props.when) ? props.when : () => Boolean(props.when);
55
- return { when: whenFn, children: props.children };
56
- }
@@ -1,56 +0,0 @@
1
- type Subscriber = () => void;
2
- type SubscriberSet = Set<Subscriber>;
3
-
4
- interface EffectRecord {
5
- run: () => void;
6
- deps: Set<SubscriberSet>;
7
- cleanups: Array<() => void>;
8
- }
9
-
10
- let currentEffect: EffectRecord | null = null;
11
-
12
- export function state<T>(initialValue: T): [() => T, (value: T | ((prev: T) => T)) => void] {
13
- let value = initialValue;
14
- const subscribers: SubscriberSet = new Set();
15
-
16
- function get(): T {
17
- if (currentEffect !== null) {
18
- subscribers.add(currentEffect.run);
19
- currentEffect.deps.add(subscribers);
20
- }
21
- return value;
22
- }
23
-
24
- function set(next: T | ((prev: T) => T)): void {
25
- const nextValue = typeof next === 'function' ? (next as (prev: T) => T)(value) : next;
26
- if (Object.is(value, nextValue)) return;
27
- value = nextValue;
28
- const copy = Array.from(subscribers);
29
- copy.forEach((fn) => fn());
30
- }
31
-
32
- return [get, set];
33
- }
34
-
35
- export function effect(fn: Subscriber): void {
36
- const deps = new Set<SubscriberSet>();
37
- const cleanups: Array<() => void> = [];
38
- const run: Subscriber = () => {
39
- for (const fn of cleanups) fn();
40
- cleanups.length = 0;
41
- deps.forEach((subs) => subs.delete(run));
42
- deps.clear();
43
- const prev = currentEffect;
44
- currentEffect = { run, deps, cleanups };
45
- try {
46
- fn();
47
- } finally {
48
- currentEffect = prev;
49
- }
50
- };
51
- run();
52
- }
53
-
54
- export function onCleanup(fn: () => void): void {
55
- if (currentEffect !== null) currentEffect.cleanups.push(fn);
56
- }
@@ -1,97 +0,0 @@
1
- Flow OS Framework and all packages in this repository are licensed under the
2
- PolyForm Shield License 1.0.0. This license applies to the entire repository
3
- (framework, packages/*, client, server, and any other code herein).
4
-
5
- Required Notice: Copyright (c) Flow OS. All rights reserved.
6
-
7
- -------------------------------------------------------------------------------
8
-
9
- # PolyForm Shield License 1.0.0
10
-
11
- ## Acceptance
12
-
13
- In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
14
-
15
- ## Copyright License
16
-
17
- The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
18
-
19
- ## Distribution License
20
-
21
- The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
22
-
23
- ## Notices
24
-
25
- You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
26
-
27
- > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
28
-
29
- ## Changes and New Works License
30
-
31
- The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
32
-
33
- ## Patent License
34
-
35
- The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
36
-
37
- ## Noncompete
38
-
39
- Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
40
-
41
- ## Competition
42
-
43
- Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
44
-
45
- ## New Products
46
-
47
- If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
48
-
49
- ## Discontinued Products
50
-
51
- You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
52
-
53
- > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
54
-
55
- Licensor Line of Business: Flow OS application framework and development tooling (create-flow, @flow.os/* packages, and related framework components).
56
-
57
- ## Sales of Business
58
-
59
- If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
60
-
61
- ## Fair Use
62
-
63
- You may have "fair use" rights for the software under the law. These terms do not limit them.
64
-
65
- ## No Other Rights
66
-
67
- These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
68
-
69
- ## Patent Defense
70
-
71
- If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
72
-
73
- ## Violations
74
-
75
- The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
76
-
77
- ## No Liability
78
-
79
- ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
80
-
81
- ## Definitions
82
-
83
- The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
84
-
85
- A **product** can be a good or service, or a combination of them.
86
-
87
- **You** refers to the individual or entity agreeing to these terms.
88
-
89
- **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
90
-
91
- **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
92
-
93
- **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
94
-
95
- **Your licenses** are all the licenses granted to you for the software under these terms.
96
-
97
- **Use** means anything you do with the software requiring one of your licenses.
@@ -1,20 +0,0 @@
1
- // ========== Core ==========
2
- // App = root component (one <App /> in layout). run = call once in entry: run(App, import.meta.glob('./routes/**/*.tsx'))
3
- export { App, run } from './router.js';
4
-
5
- // ========== Utilities ==========
6
- export { go, params } from './router.js';
7
- export { base, path, href, query, setQuery } from './utils.js';
8
- /*
9
- base() => 'https://localhost:5173'
10
-
11
- path() => '/posts/123'
12
-
13
- href() => 'https://localhost:5173/posts/123'
14
-
15
- params() => ['posts', '123']
16
-
17
- query() => URLSearchParams { page: '2' }
18
-
19
- setQuery({ page: '2' }) => 'https://localhost:5173/posts/123?page=2'
20
- */
@@ -1,105 +0,0 @@
1
- import type { RouteEntry } from './types.js';
2
-
3
- const CATCH_ALL_PREFIX = ':*';
4
-
5
- /**
6
- * Converts a file-path key (e.g. from import.meta.glob) to a route pattern.
7
- * - `routes/index.ts` → ''
8
- * - `routes/about.ts` → 'about'
9
- * - `routes/posts/[id].ts` → 'posts/:id'
10
- * - `routes/docs/[...slug].ts` → 'docs/:*slug'
11
- */
12
- export function pathToPattern(key: string): string {
13
- const afterRoutes = key.replace(/^.*[/\\]routes[/\\]?/i, '').replace(/\.tsx?$/i, '');
14
- const segments = afterRoutes.split(/[/\\]/).filter(Boolean);
15
- if (segments.length === 0 || segments[0] === 'index') return '';
16
-
17
- const patternParts = segments.map((seg) => {
18
- if (seg.startsWith('[...') && seg.endsWith(']')) {
19
- const name = seg.slice(4, -1);
20
- return name ? `${CATCH_ALL_PREFIX}${name}` : `${CATCH_ALL_PREFIX}rest`;
21
- }
22
- if (seg.startsWith('[') && seg.endsWith(']')) {
23
- return ':' + seg.slice(1, -1);
24
- }
25
- return seg;
26
- });
27
-
28
- return patternParts.join('/');
29
- }
30
-
31
- /**
32
- * Returns true if the pattern string contains a catch-all segment.
33
- */
34
- export function isCatchAllPattern(pattern: string): boolean {
35
- return pattern.includes(CATCH_ALL_PREFIX);
36
- }
37
-
38
- /**
39
- * Counts static (non-param) segments for route sort order.
40
- */
41
- export function countStaticSegments(pattern: string): number {
42
- if (!pattern) return 0;
43
- return pattern.split('/').filter((s) => s && !s.startsWith(':') && !s.startsWith(CATCH_ALL_PREFIX)).length;
44
- }
45
-
46
- /**
47
- * Matches a path against a pattern. Supports :param and :*catchAll.
48
- * - :param matches one segment.
49
- * - :*name matches the rest of the path (one param with path segments joined by '/').
50
- * Returns params object or null if no match.
51
- */
52
- export function match(pattern: string, path: string): Record<string, string> | null {
53
- const patternSegs = pattern ? pattern.split('/').filter(Boolean) : [];
54
- const pathSegs = path.replace(/^\//, '').split('/').filter(Boolean);
55
-
56
- const params: Record<string, string> = {};
57
- let pi = 0;
58
-
59
- for (let i = 0; i < patternSegs.length; i++) {
60
- const seg = patternSegs[i]!;
61
- if (seg.startsWith(CATCH_ALL_PREFIX)) {
62
- const name = seg.slice(CATCH_ALL_PREFIX.length) || 'rest';
63
- params[name] = pathSegs.slice(pi).join('/');
64
- return params;
65
- }
66
- if (pi >= pathSegs.length) return null;
67
- if (seg.startsWith(':')) {
68
- params[seg.slice(1)] = pathSegs[pi] ?? '';
69
- pi++;
70
- continue;
71
- }
72
- if (seg !== pathSegs[pi]) return null;
73
- pi++;
74
- }
75
-
76
- return pi === pathSegs.length ? params : null;
77
- }
78
-
79
- /**
80
- * Builds sorted route entries: more specific first (static > dynamic > catch-all),
81
- * then by segment count descending.
82
- */
83
- export function buildRouteEntries(
84
- modules: Record<string, () => Promise<import('./types.js').RouteModule>>
85
- ): RouteEntry[] {
86
- const entries: RouteEntry[] = Object.entries(modules).map(([key, loader]) => {
87
- const pattern = pathToPattern(key);
88
- return {
89
- pattern,
90
- loader,
91
- staticSegments: countStaticSegments(pattern),
92
- catchAll: isCatchAllPattern(pattern),
93
- };
94
- });
95
-
96
- entries.sort((a, b) => {
97
- if (a.catchAll !== b.catchAll) return a.catchAll ? 1 : -1;
98
- if (a.staticSegments !== b.staticSegments) return b.staticSegments - a.staticSegments;
99
- const lenA = a.pattern.split('/').filter(Boolean).length;
100
- const lenB = b.pattern.split('/').filter(Boolean).length;
101
- return lenB - lenA;
102
- });
103
-
104
- return entries;
105
- }
@@ -1,15 +0,0 @@
1
- {
2
- "name": "@flow.os/router",
3
- "version": "0.0.5",
4
- "license": "PolyForm-Shield-1.0.0",
5
- "type": "module",
6
- "main": "./index.ts",
7
- "types": "./index.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./index.ts",
11
- "import": "./index.ts",
12
- "default": "./index.ts"
13
- }
14
- }
15
- }
@@ -1,185 +0,0 @@
1
- import type { RouteModule, RouterOptions, RunOptions } from './types.js';
2
- import { buildRouteEntries } from './matcher.js';
3
- import { match } from './matcher.js';
4
-
5
- let currentRouter: RouterAPI | null = null;
6
- let currentParams: Record<string, string> = {};
7
-
8
- export const APP_ID = 'flow-app';
9
-
10
- /** Root container where the router mounts the current page. Use once in root as <App />. */
11
- export function App(): HTMLDivElement {
12
- const el = document.createElement('div');
13
- el.id = APP_ID;
14
- el.setAttribute('role', 'main');
15
- return el;
16
- }
17
-
18
- function setContent(container: HTMLElement, content: Node | string): void {
19
- container.innerHTML = '';
20
- if (typeof content === 'string') container.textContent = content;
21
- else container.appendChild(content);
22
- }
23
-
24
- function defaultNotFound(path: string): Node {
25
- const wrap = document.createElement('div');
26
- wrap.setAttribute('role', 'alert');
27
- const h = document.createElement('h1');
28
- h.textContent = '404';
29
- const p = document.createElement('p');
30
- p.textContent = `Page not found: ${path || '/'}`;
31
- wrap.append(h, p);
32
- return wrap;
33
- }
34
-
35
- export interface RouterAPI {
36
- /** Navigate to a path. Use replace=true to avoid adding a history entry. */
37
- go(path: string, replace?: boolean): void;
38
- /** Start listening to popstate and link clicks. Call once after mounting App. */
39
- start(): void;
40
- }
41
-
42
- const NOT_FOUND_PATTERN = '404';
43
-
44
- export function createRouter(
45
- modules: Record<string, () => Promise<RouteModule>>,
46
- container: HTMLElement,
47
- options: RouterOptions = {}
48
- ): RouterAPI {
49
- const allEntries = buildRouteEntries(modules);
50
- const routes = allEntries.filter((e) => e.pattern !== NOT_FOUND_PATTERN);
51
- const notFoundLoader = allEntries.find((e) => e.pattern === NOT_FOUND_PATTERN)?.loader ?? null;
52
-
53
- const notFound: Node | ((path: string) => Node | Promise<Node>) =
54
- options.notFound ??
55
- (notFoundLoader
56
- ? (path) =>
57
- notFoundLoader().then((mod) => {
58
- const def = mod.default;
59
- return typeof def === 'function' ? (def as (p: string) => Node)(path) : (def as unknown as Node);
60
- })
61
- : defaultNotFound);
62
- const fullPageNotFound = Boolean(
63
- options.appRoot && options.getLayout && (options.notFound != null || notFoundLoader != null)
64
- );
65
-
66
- function getContainer(): HTMLElement | null {
67
- return document.getElementById(APP_ID);
68
- }
69
-
70
- async function render(pathname: string): Promise<boolean> {
71
- const path = pathname === '/' ? '' : pathname.slice(1);
72
-
73
- for (const { pattern, loader } of routes) {
74
- const routeParams = match(pattern, path);
75
- if (routeParams === null) continue;
76
-
77
- currentParams = routeParams;
78
- let target = getContainer();
79
- if (fullPageNotFound && !target) {
80
- options.appRoot!.innerHTML = '';
81
- options.appRoot!.appendChild(options.getLayout!());
82
- target = getContainer();
83
- }
84
- if (!target) continue;
85
-
86
- const fallbackNode =
87
- options.fallback != null
88
- ? typeof options.fallback === 'function'
89
- ? options.fallback()
90
- : options.fallback
91
- : null;
92
- if (fallbackNode) setContent(target, fallbackNode);
93
-
94
- const mod = await loader();
95
- const def = mod.default;
96
- if (typeof def === 'function') {
97
- const out = def.length
98
- ? (def as (p: Record<string, string>) => Node)(routeParams)
99
- : (def as () => Node | string)();
100
- if (out instanceof Node) setContent(target, out);
101
- else if (typeof out === 'string') target.innerHTML = out;
102
- else target.innerHTML = '';
103
- } else {
104
- setContent(target, typeof def === 'string' ? def : (def as unknown as Node));
105
- }
106
- return true;
107
- }
108
-
109
- currentParams = {};
110
- const nfRaw = typeof notFound === 'function' ? notFound(pathname) : notFound;
111
- const nfNode = nfRaw && typeof (nfRaw as Promise<unknown>).then === 'function' ? await (nfRaw as Promise<Node>) : (nfRaw as Node);
112
- if (fullPageNotFound) {
113
- options.appRoot!.innerHTML = '';
114
- options.appRoot!.appendChild(nfNode);
115
- } else {
116
- setContent(container, nfNode);
117
- }
118
- return false;
119
- }
120
-
121
- function go(path: string, replace = false): void {
122
- const p = path.startsWith('/') ? path : `/${path}`;
123
- render(p).then((ok) => {
124
- if (ok) (replace ? history.replaceState : history.pushState).call(history, null, '', p);
125
- });
126
- }
127
-
128
- function start(): void {
129
- render(location.pathname || '/');
130
- window.addEventListener('popstate', () => render(location.pathname || '/'));
131
- document.addEventListener('click', (e) => {
132
- const a = (e.target as Element).closest('a');
133
- if (a?.getAttribute('href')?.startsWith('/') && !a.href.startsWith('//')) {
134
- e.preventDefault();
135
- go(a.getAttribute('href')!);
136
- }
137
- });
138
- }
139
-
140
- const api: RouterAPI = { go, start };
141
- currentRouter = api;
142
- return api;
143
- }
144
-
145
- /**
146
- * Navigate to a path. Import and use anywhere; works after run() (or createRouter().start()) has been called.
147
- * No-op if the router is not started yet.
148
- */
149
- export function go(path: string, replace = false): void {
150
- currentRouter?.go(path, replace);
151
- }
152
-
153
- /** Current route params. params() → all, params('id') → one. */
154
- export function params(): Record<string, string>;
155
- export function params(name: string): string | undefined;
156
- export function params(name?: string): Record<string, string> | string | undefined {
157
- if (name === undefined) return { ...currentParams };
158
- return currentParams[name] ?? undefined;
159
- }
160
-
161
- /**
162
- * Mounts App and starts the router. Use in your virtual entry.
163
- * Returns the router API so you can call go() (and start()) from outside.
164
- */
165
- export function run(
166
- AppFactory: () => Node,
167
- modules: Record<string, () => Promise<RouteModule>>,
168
- options?: RunOptions
169
- ): RouterAPI {
170
- const app = document.getElementById('app')!;
171
- app.appendChild(AppFactory());
172
- const appContainer = document.getElementById(APP_ID);
173
- if (!appContainer) {
174
- throw new Error(`#${APP_ID} not found: use <App /> from @flow.os/router in your root layout.`);
175
- }
176
- const routerOptions: RouterOptions = {
177
- fallback: options?.fallback,
178
- notFound: options?.notFound,
179
- appRoot: app,
180
- getLayout: () => AppFactory(),
181
- };
182
- const api = createRouter(modules, appContainer as HTMLElement, routerOptions);
183
- api.start();
184
- return api;
185
- }
@@ -1,34 +0,0 @@
1
- /** Route module: default can be a component (with optional params), a factory, or raw string/Node. */
2
- export type RouteModule = {
3
- default:
4
- | (() => Node)
5
- | ((params: Record<string, string>) => Node)
6
- | (() => string)
7
- | string;
8
- };
9
-
10
- /** Options for run(): fallback while loading, custom 404. */
11
- export type RunOptions = {
12
- /** Node (or factory) shown while the lazy route is loading. */
13
- fallback?: Node | (() => Node);
14
- /** 404 page: if provided, shown full-page (replaces entire #app, no shared layout). */
15
- notFound?: Node | ((path: string) => Node);
16
- };
17
-
18
- /** Internal router options (fallback, notFound, full-page 404 wiring). */
19
- export type RouterOptions = {
20
- fallback?: Node | (() => Node);
21
- notFound?: Node | ((path: string) => Node | Promise<Node>);
22
- appRoot?: HTMLElement;
23
- getLayout?: () => Node;
24
- };
25
-
26
- /** Internal: normalized route entry for matching. */
27
- export type RouteEntry = {
28
- pattern: string;
29
- loader: () => Promise<RouteModule>;
30
- /** Number of static segments (for sort order). */
31
- staticSegments: number;
32
- /** True if pattern ends with catch-all. */
33
- catchAll: boolean;
34
- };
@@ -1,45 +0,0 @@
1
- /** Origin: protocol + host (e.g. https://localhost:5173 or https://example.com). */
2
- export function base(): string {
3
- return typeof location !== 'undefined' ? location.origin : '';
4
- }
5
-
6
- /** Current pathname (e.g. /posts/123). */
7
- export function path(p?: string): string {
8
- const raw = p ?? (typeof location !== 'undefined' ? location.pathname || '/' : '/');
9
- return raw.startsWith('/') ? raw : `/${raw}`;
10
- }
11
-
12
- /** Full path + search + hash. No args = current. */
13
- export function href(p?: string): string {
14
- const basePath = path(p);
15
- if (typeof location === 'undefined') return basePath;
16
- return basePath + (location.search ?? '') + (location.hash ?? '');
17
- }
18
-
19
- /** Query (after ?). query() → all as object, query('key') → one value. */
20
- export function query(): Record<string, string>;
21
- export function query(name: string): string | null;
22
- export function query(name?: string): Record<string, string> | string | null {
23
- const s = typeof location !== 'undefined' ? location.search : '';
24
- const p = new URLSearchParams(s);
25
- if (name !== undefined) return p.get(name);
26
- const out: Record<string, string> = {};
27
- p.forEach((v, k) => (out[k] = v));
28
- return out;
29
- }
30
-
31
- /** New path with query updated. go(setQuery({ page: '2' })) to navigate. */
32
- export function setQuery(
33
- obj: Record<string, string | number | boolean | undefined | null>,
34
- p?: string
35
- ): string {
36
- const basePath = path(p);
37
- const current = query();
38
- const next = { ...current };
39
- for (const [key, value] of Object.entries(obj)) {
40
- if (value === undefined || value === null) delete next[key];
41
- else next[key] = String(value);
42
- }
43
- const search = new URLSearchParams(next).toString();
44
- return search ? `${basePath}?${search}` : basePath;
45
- }