effect-start 0.19.0 → 0.20.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.
Files changed (144) hide show
  1. package/README.md +3 -3
  2. package/dist/Development.d.ts +3 -3
  3. package/dist/Development.js +3 -2
  4. package/dist/Effectify.d.ts +212 -0
  5. package/dist/Effectify.js +19 -0
  6. package/dist/FilePathPattern.d.ts +29 -0
  7. package/dist/FilePathPattern.js +86 -0
  8. package/dist/FileRouter.d.ts +39 -41
  9. package/dist/FileRouter.js +104 -158
  10. package/dist/FileRouterCodegen.d.ts +7 -8
  11. package/dist/FileRouterCodegen.js +97 -66
  12. package/dist/PlatformError.d.ts +46 -0
  13. package/dist/PlatformError.js +43 -0
  14. package/dist/PlatformRuntime.d.ts +23 -0
  15. package/dist/PlatformRuntime.js +42 -0
  16. package/dist/RouteBody.d.ts +1 -1
  17. package/dist/Start.d.ts +34 -3
  18. package/dist/Start.js +31 -6
  19. package/dist/bun/BunPlatformHttpServer.d.ts +10 -0
  20. package/dist/bun/BunPlatformHttpServer.js +53 -0
  21. package/dist/bun/BunRoute.d.ts +3 -5
  22. package/dist/bun/BunRoute.js +9 -17
  23. package/dist/bun/BunRuntime.d.ts +2 -1
  24. package/dist/bun/BunRuntime.js +10 -5
  25. package/dist/bun/BunServer.d.ts +33 -0
  26. package/dist/bun/BunServer.js +133 -0
  27. package/dist/bun/BunServerRequest.d.ts +60 -0
  28. package/dist/bun/BunServerRequest.js +252 -0
  29. package/dist/bun/index.d.ts +1 -1
  30. package/dist/bun/index.js +1 -1
  31. package/dist/datastar/actions/fetch.d.ts +30 -0
  32. package/dist/datastar/actions/fetch.js +411 -0
  33. package/dist/datastar/actions/peek.d.ts +1 -0
  34. package/dist/datastar/actions/peek.js +14 -0
  35. package/dist/datastar/actions/setAll.d.ts +1 -0
  36. package/dist/datastar/actions/setAll.js +13 -0
  37. package/dist/datastar/actions/toggleAll.d.ts +1 -0
  38. package/dist/datastar/actions/toggleAll.js +13 -0
  39. package/dist/datastar/attributes/attr.d.ts +1 -0
  40. package/dist/datastar/attributes/attr.js +49 -0
  41. package/dist/datastar/attributes/bind.d.ts +1 -0
  42. package/dist/datastar/attributes/bind.js +183 -0
  43. package/dist/datastar/attributes/class.d.ts +1 -0
  44. package/dist/datastar/attributes/class.js +50 -0
  45. package/dist/datastar/attributes/computed.d.ts +1 -0
  46. package/dist/datastar/attributes/computed.js +27 -0
  47. package/dist/datastar/attributes/effect.d.ts +1 -0
  48. package/dist/datastar/attributes/effect.js +10 -0
  49. package/dist/datastar/attributes/indicator.d.ts +1 -0
  50. package/dist/datastar/attributes/indicator.js +32 -0
  51. package/dist/datastar/attributes/init.d.ts +1 -0
  52. package/dist/datastar/attributes/init.js +27 -0
  53. package/dist/datastar/attributes/jsonSignals.d.ts +1 -0
  54. package/dist/datastar/attributes/jsonSignals.js +31 -0
  55. package/dist/datastar/attributes/on.d.ts +1 -0
  56. package/dist/datastar/attributes/on.js +59 -0
  57. package/dist/datastar/attributes/onIntersect.d.ts +1 -0
  58. package/dist/datastar/attributes/onIntersect.js +54 -0
  59. package/dist/datastar/attributes/onInterval.d.ts +1 -0
  60. package/dist/datastar/attributes/onInterval.js +31 -0
  61. package/dist/datastar/attributes/onSignalPatch.d.ts +1 -0
  62. package/dist/datastar/attributes/onSignalPatch.js +44 -0
  63. package/dist/datastar/attributes/ref.d.ts +1 -0
  64. package/dist/datastar/attributes/ref.js +11 -0
  65. package/dist/datastar/attributes/show.d.ts +1 -0
  66. package/dist/datastar/attributes/show.js +32 -0
  67. package/dist/datastar/attributes/signals.d.ts +1 -0
  68. package/dist/datastar/attributes/signals.js +18 -0
  69. package/dist/datastar/attributes/style.d.ts +1 -0
  70. package/dist/datastar/attributes/style.js +56 -0
  71. package/dist/datastar/attributes/text.d.ts +1 -0
  72. package/dist/datastar/attributes/text.js +27 -0
  73. package/dist/datastar/engine.d.ts +156 -0
  74. package/dist/datastar/engine.js +971 -0
  75. package/dist/datastar/index.d.ts +24 -0
  76. package/dist/datastar/index.js +24 -0
  77. package/dist/datastar/load.d.ts +24 -0
  78. package/dist/datastar/load.js +24 -0
  79. package/dist/datastar/utils.d.ts +51 -0
  80. package/dist/datastar/utils.js +205 -0
  81. package/dist/datastar/watchers/patchElements.d.ts +1 -0
  82. package/dist/datastar/watchers/patchElements.js +420 -0
  83. package/dist/datastar/watchers/patchSignals.d.ts +1 -0
  84. package/dist/datastar/watchers/patchSignals.js +15 -0
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +1 -1
  87. package/dist/node/NodeFileSystem.d.ts +7 -0
  88. package/dist/node/NodeFileSystem.js +420 -0
  89. package/dist/node/NodeUtils.d.ts +2 -0
  90. package/dist/node/NodeUtils.js +20 -0
  91. package/dist/x/tailwind/plugin.js +1 -1
  92. package/package.json +11 -7
  93. package/src/Development.ts +26 -25
  94. package/src/{node/Effectify.ts → Effectify.ts} +10 -3
  95. package/src/FilePathPattern.ts +115 -0
  96. package/src/FileRouter.ts +178 -255
  97. package/src/FileRouterCodegen.ts +135 -92
  98. package/src/{node/PlatformError.ts → PlatformError.ts} +34 -19
  99. package/src/PlatformRuntime.ts +97 -0
  100. package/src/RouteBody.ts +1 -1
  101. package/src/RouteHttp.ts +3 -1
  102. package/src/Start.ts +62 -14
  103. package/src/bun/BunPlatformHttpServer.ts +88 -0
  104. package/src/bun/BunRoute.ts +12 -22
  105. package/src/bun/BunRuntime.ts +21 -5
  106. package/src/bun/BunServer.ts +228 -0
  107. package/src/bun/index.ts +1 -1
  108. package/src/datastar/README.md +18 -0
  109. package/src/datastar/actions/fetch.ts +609 -0
  110. package/src/datastar/actions/peek.ts +17 -0
  111. package/src/datastar/actions/setAll.ts +20 -0
  112. package/src/datastar/actions/toggleAll.ts +20 -0
  113. package/src/datastar/attributes/attr.ts +50 -0
  114. package/src/datastar/attributes/bind.ts +220 -0
  115. package/src/datastar/attributes/class.ts +57 -0
  116. package/src/datastar/attributes/computed.ts +33 -0
  117. package/src/datastar/attributes/effect.ts +11 -0
  118. package/src/datastar/attributes/indicator.ts +39 -0
  119. package/src/datastar/attributes/init.ts +35 -0
  120. package/src/datastar/attributes/jsonSignals.ts +38 -0
  121. package/src/datastar/attributes/on.ts +71 -0
  122. package/src/datastar/attributes/onIntersect.ts +65 -0
  123. package/src/datastar/attributes/onInterval.ts +39 -0
  124. package/src/datastar/attributes/onSignalPatch.ts +63 -0
  125. package/src/datastar/attributes/ref.ts +12 -0
  126. package/src/datastar/attributes/show.ts +33 -0
  127. package/src/datastar/attributes/signals.ts +22 -0
  128. package/src/datastar/attributes/style.ts +63 -0
  129. package/src/datastar/attributes/text.ts +30 -0
  130. package/src/datastar/engine.ts +1341 -0
  131. package/src/datastar/index.ts +25 -0
  132. package/src/datastar/utils.ts +286 -0
  133. package/src/datastar/watchers/patchElements.ts +554 -0
  134. package/src/datastar/watchers/patchSignals.ts +15 -0
  135. package/src/index.ts +1 -1
  136. package/src/node/{FileSystem.ts → NodeFileSystem.ts} +2 -2
  137. package/src/node/{Utils.ts → NodeUtils.ts} +2 -0
  138. package/src/x/tailwind/plugin.ts +1 -1
  139. package/src/FileRouterCodegen.todo.ts +0 -1133
  140. package/src/FileRouterPattern.ts +0 -59
  141. package/src/RouterPattern.ts +0 -416
  142. package/src/StartApp.ts +0 -47
  143. package/src/bun/BunHttpServer.ts +0 -303
  144. /package/src/bun/{BunHttpServer_web.ts → BunServerRequest.ts} +0 -0
@@ -0,0 +1,25 @@
1
+ export * from "./engine.ts"
2
+
3
+ import "./actions/peek.ts"
4
+ import "./actions/setAll.ts"
5
+ import "./actions/toggleAll.ts"
6
+ import "./actions/fetch.ts"
7
+ import "./attributes/attr.ts"
8
+ import "./attributes/bind.ts"
9
+ import "./attributes/class.ts"
10
+ import "./attributes/computed.ts"
11
+ import "./attributes/effect.ts"
12
+ import "./attributes/indicator.ts"
13
+ import "./attributes/init.ts"
14
+ import "./attributes/jsonSignals.ts"
15
+ import "./attributes/on.ts"
16
+ import "./attributes/onIntersect.ts"
17
+ import "./attributes/onInterval.ts"
18
+ import "./attributes/onSignalPatch.ts"
19
+ import "./attributes/ref.ts"
20
+ import "./attributes/show.ts"
21
+ import "./attributes/signals.ts"
22
+ import "./attributes/style.ts"
23
+ import "./attributes/text.ts"
24
+ import "./watchers/patchElements.ts"
25
+ import "./watchers/patchSignals.ts"
@@ -0,0 +1,286 @@
1
+ import type {
2
+ EventCallbackHandler,
3
+ HTMLOrSVG,
4
+ Modifiers,
5
+ Paths,
6
+ } from "./engine.ts"
7
+
8
+ /*********
9
+ * dom.ts
10
+ *********/
11
+ export const isHTMLOrSVG = (el: Node): el is HTMLOrSVG =>
12
+ el instanceof HTMLElement
13
+ || el instanceof SVGElement
14
+ || el instanceof MathMLElement
15
+
16
+ /*********
17
+ * math.ts
18
+ *********/
19
+ export const clamp = (value: number, min: number, max: number): number => {
20
+ return Math.max(min, Math.min(max, value))
21
+ }
22
+
23
+ export const lerp = (
24
+ min: number,
25
+ max: number,
26
+ t: number,
27
+ clamped = true,
28
+ ): number => {
29
+ const v = min + (max - min) * t
30
+ return clamped ? clamp(v, min, max) : v
31
+ }
32
+
33
+ export const inverseLerp = (
34
+ min: number,
35
+ max: number,
36
+ value: number,
37
+ clamped = true,
38
+ ): number => {
39
+ if (value < min) return 0
40
+ if (value > max) return 1
41
+ const v = (value - min) / (max - min)
42
+ return clamped ? clamp(v, min, max) : v
43
+ }
44
+
45
+ export const fit = (
46
+ value: number,
47
+ inMin: number,
48
+ inMax: number,
49
+ outMin: number,
50
+ outMax: number,
51
+ clamped = true,
52
+ rounded = false,
53
+ ): number => {
54
+ const t = inverseLerp(inMin, inMax, value, clamped)
55
+ const fitted = lerp(outMin, outMax, t, clamped)
56
+ return rounded ? Math.round(fitted) : fitted
57
+ }
58
+
59
+ /*********
60
+ * text.ts
61
+ *********/
62
+ export const kebab = (str: string): string =>
63
+ str
64
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
65
+ .replace(/([a-z])([0-9]+)/gi, "$1-$2")
66
+ .replace(/([0-9]+)([a-z])/gi, "$1-$2")
67
+ .replace(/[\s_]+/g, "-")
68
+ .toLowerCase()
69
+
70
+ export const camel = (str: string): string =>
71
+ kebab(str).replace(/-./g, (x) => x[1].toUpperCase())
72
+
73
+ export const snake = (str: string): string => kebab(str).replace(/-/g, "_")
74
+
75
+ export const pascal = (str: string): string =>
76
+ camel(str).replace(/(^.|(?<=\.).)/g, (x) => x[0].toUpperCase())
77
+
78
+ export const title = (str: string): string =>
79
+ str.replace(/\b\w/g, (char) => char.toUpperCase())
80
+
81
+ export const jsStrToObject = (raw: string) => {
82
+ try {
83
+ return JSON.parse(raw)
84
+ } catch {
85
+ return Function(`return (${raw})`)()
86
+ }
87
+ }
88
+
89
+ const caseFns: Record<string, (s: string) => string> = {
90
+ camel: (str) => str.replace(/-[a-z]/g, (x) => x[1].toUpperCase()),
91
+ snake: (str) => str.replace(/-/g, "_"),
92
+ pascal: (str) => str[0].toUpperCase() + caseFns.camel(str.slice(1)),
93
+ }
94
+
95
+ export const modifyCasing = (
96
+ str: string,
97
+ mods: Modifiers,
98
+ defaultCase = "camel",
99
+ ): string => {
100
+ for (const c of mods.get("case") || [defaultCase]) {
101
+ str = caseFns[c]?.(str) || str
102
+ }
103
+ return str
104
+ }
105
+
106
+ export const aliasify = (name: string) => `data-${name}`
107
+
108
+ /*********
109
+ * tags.ts
110
+ *********/
111
+ export const tagToMs = (args: Set<string>) => {
112
+ if (!args || args.size <= 0) return 0
113
+ for (const arg of args) {
114
+ if (arg.endsWith("ms")) {
115
+ return +arg.replace("ms", "")
116
+ }
117
+ if (arg.endsWith("s")) {
118
+ return +arg.replace("s", "") * 1000
119
+ }
120
+ try {
121
+ return Number.parseFloat(arg)
122
+ } catch (_) {}
123
+ }
124
+ return 0
125
+ }
126
+
127
+ export const tagHas = (
128
+ tags: Set<string>,
129
+ tag: string,
130
+ defaultValue = false,
131
+ ) => {
132
+ if (!tags) return defaultValue
133
+ return tags.has(tag.toLowerCase())
134
+ }
135
+
136
+ export const tagFirst = (tags?: Set<string>, defaultValue = ""): string => {
137
+ if (tags && tags.size > 0) {
138
+ for (const tag of tags) {
139
+ return tag
140
+ }
141
+ }
142
+ return defaultValue
143
+ }
144
+
145
+ /*********
146
+ * polyfills.ts
147
+ *********/
148
+ export const hasOwn: (obj: object, prop: PropertyKey) => boolean =
149
+ // @ts-ignore
150
+ Object.hasOwn ?? Object.prototype.hasOwnProperty.call
151
+
152
+ /*********
153
+ * paths.ts
154
+ *********/
155
+ export const isPojo = (obj: any): obj is Record<string, any> =>
156
+ obj !== null
157
+ && typeof obj === "object"
158
+ && (Object.getPrototypeOf(obj) === Object.prototype
159
+ || Object.getPrototypeOf(obj) === null)
160
+
161
+ export const isEmpty = (obj: Record<string, any>): boolean => {
162
+ for (const prop in obj) {
163
+ if (hasOwn(obj, prop)) {
164
+ return false
165
+ }
166
+ }
167
+ return true
168
+ }
169
+
170
+ export const updateLeaves = (
171
+ obj: Record<string, any>,
172
+ fn: (oldValue: any) => any,
173
+ ) => {
174
+ for (const key in obj) {
175
+ const val = obj[key]
176
+ if (isPojo(val) || Array.isArray(val)) {
177
+ updateLeaves(val, fn)
178
+ } else {
179
+ obj[key] = fn(val)
180
+ }
181
+ }
182
+ }
183
+
184
+ export const pathToObj = (paths: Paths): Record<string, any> => {
185
+ const result: Record<string, any> = {}
186
+ for (const [path, value] of paths) {
187
+ const keys = path.split(".")
188
+ const lastKey = keys.pop()!
189
+ const obj = keys.reduce((acc, key) => (acc[key] ??= {}), result)
190
+ obj[lastKey] = value
191
+ }
192
+ return result
193
+ }
194
+
195
+ /*********
196
+ * timing.ts
197
+ *********/
198
+ export const delay = (
199
+ callback: EventCallbackHandler,
200
+ wait: number,
201
+ ): EventCallbackHandler => {
202
+ return (...args: any[]) => {
203
+ setTimeout(() => {
204
+ callback(...args)
205
+ }, wait)
206
+ }
207
+ }
208
+
209
+ export const throttle = (
210
+ callback: EventCallbackHandler,
211
+ wait: number,
212
+ leading = true,
213
+ trailing = false,
214
+ debounce = false,
215
+ ): EventCallbackHandler => {
216
+ let lastArgs: Parameters<EventCallbackHandler> | null = null
217
+ let timer: any = 0
218
+
219
+ return (...args: any[]) => {
220
+ if (leading && !timer) {
221
+ callback(...args)
222
+ lastArgs = null
223
+ } else {
224
+ lastArgs = args
225
+ }
226
+ if (!timer || debounce) {
227
+ if (timer) {
228
+ clearTimeout(timer)
229
+ }
230
+ timer = setTimeout(() => {
231
+ if (trailing && lastArgs !== null) {
232
+ callback(...lastArgs)
233
+ }
234
+ lastArgs = null
235
+ timer = 0
236
+ }, wait)
237
+ }
238
+ }
239
+ }
240
+
241
+ export const modifyTiming = (
242
+ callback: EventCallbackHandler,
243
+ mods: Modifiers,
244
+ ): EventCallbackHandler => {
245
+ const delayArgs = mods.get("delay")
246
+ if (delayArgs) {
247
+ const wait = tagToMs(delayArgs)
248
+ callback = delay(callback, wait)
249
+ }
250
+
251
+ const debounceArgs = mods.get("debounce")
252
+ if (debounceArgs) {
253
+ const wait = tagToMs(debounceArgs)
254
+ const leading = tagHas(debounceArgs, "leading", false)
255
+ const trailing = !tagHas(debounceArgs, "notrailing", false)
256
+ callback = throttle(callback, wait, leading, trailing, true)
257
+ }
258
+
259
+ const throttleArgs = mods.get("throttle")
260
+ if (throttleArgs) {
261
+ const wait = tagToMs(throttleArgs)
262
+ const leading = !tagHas(throttleArgs, "noleading", false)
263
+ const trailing = tagHas(throttleArgs, "trailing", false)
264
+ callback = throttle(callback, wait, leading, trailing)
265
+ }
266
+
267
+ return callback
268
+ }
269
+
270
+ /*********
271
+ * view-transitions.ts
272
+ *********/
273
+ export const supportsViewTransitions = !!document.startViewTransition
274
+
275
+ export const modifyViewTransition = (
276
+ callback: EventCallbackHandler,
277
+ mods: Modifiers,
278
+ ): EventCallbackHandler => {
279
+ if (mods.has("viewtransition") && supportsViewTransitions) {
280
+ const cb = callback
281
+ callback = (...args: any[]) =>
282
+ document.startViewTransition(() => cb(...args))
283
+ }
284
+
285
+ return callback
286
+ }