amateras 0.7.4 → 0.10.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 (257) hide show
  1. package/README.md +76 -85
  2. package/package.json +29 -33
  3. package/tsconfig.json +4 -3
  4. package/packages/core/package.json +0 -32
  5. package/packages/core/src/env.browser.ts +0 -21
  6. package/packages/core/src/env.node.ts +0 -21
  7. package/packages/core/src/global.ts +0 -18
  8. package/packages/core/src/index.ts +0 -96
  9. package/packages/core/src/lib/assignNodeProperties.ts +0 -11
  10. package/packages/core/src/lib/assignProperties.ts +0 -57
  11. package/packages/core/src/lib/chain.ts +0 -17
  12. package/packages/core/src/lib/dom.ts +0 -20
  13. package/packages/core/src/main.ts +0 -4
  14. package/packages/core/src/node/$Element.ts +0 -366
  15. package/packages/core/src/node/$EventTarget.ts +0 -48
  16. package/packages/core/src/node/$HTMLElement.ts +0 -99
  17. package/packages/core/src/node/$Node.ts +0 -201
  18. package/packages/core/src/node/$Virtual.ts +0 -65
  19. package/packages/css/README.md +0 -128
  20. package/packages/css/package.json +0 -17
  21. package/packages/css/src/ext/colors/amber.ts +0 -25
  22. package/packages/css/src/ext/colors/blackwhite.ts +0 -13
  23. package/packages/css/src/ext/colors/blue.ts +0 -25
  24. package/packages/css/src/ext/colors/cyan.ts +0 -25
  25. package/packages/css/src/ext/colors/emerald.ts +0 -25
  26. package/packages/css/src/ext/colors/fuchsia.ts +0 -25
  27. package/packages/css/src/ext/colors/gray.ts +0 -25
  28. package/packages/css/src/ext/colors/green.ts +0 -25
  29. package/packages/css/src/ext/colors/indigo.ts +0 -25
  30. package/packages/css/src/ext/colors/lime.ts +0 -25
  31. package/packages/css/src/ext/colors/neutral.ts +0 -25
  32. package/packages/css/src/ext/colors/orange.ts +0 -25
  33. package/packages/css/src/ext/colors/pink.ts +0 -25
  34. package/packages/css/src/ext/colors/purple.ts +0 -25
  35. package/packages/css/src/ext/colors/red.ts +0 -25
  36. package/packages/css/src/ext/colors/rose.ts +0 -25
  37. package/packages/css/src/ext/colors/sky.ts +0 -25
  38. package/packages/css/src/ext/colors/slate.ts +0 -25
  39. package/packages/css/src/ext/colors/stone.ts +0 -25
  40. package/packages/css/src/ext/colors/teal.ts +0 -25
  41. package/packages/css/src/ext/colors/violet.ts +0 -25
  42. package/packages/css/src/ext/colors/yellow.ts +0 -25
  43. package/packages/css/src/ext/colors/zinc.ts +0 -25
  44. package/packages/css/src/ext/colors.ts +0 -23
  45. package/packages/css/src/ext/container.ts +0 -32
  46. package/packages/css/src/ext/keyframes.ts +0 -54
  47. package/packages/css/src/ext/media.ts +0 -32
  48. package/packages/css/src/ext/property.ts +0 -48
  49. package/packages/css/src/ext/variable.ts +0 -51
  50. package/packages/css/src/index.ts +0 -436
  51. package/packages/css/src/lib/colorAssign.ts +0 -6
  52. package/packages/css/src/lib/utils.ts +0 -11
  53. package/packages/css/src/structure/$CSSContainerRule.ts +0 -13
  54. package/packages/css/src/structure/$CSSDeclaration.ts +0 -16
  55. package/packages/css/src/structure/$CSSKeyframesRule.ts +0 -13
  56. package/packages/css/src/structure/$CSSMediaRule.ts +0 -10
  57. package/packages/css/src/structure/$CSSProperty.ts +0 -19
  58. package/packages/css/src/structure/$CSSRule.ts +0 -13
  59. package/packages/css/src/structure/$CSSStyleRule.ts +0 -14
  60. package/packages/css/src/structure/$CSSVariable.ts +0 -30
  61. package/packages/dom/package.json +0 -20
  62. package/packages/dom/src/lib/HTMLElementMap.ts +0 -213
  63. package/packages/dom/src/lib/assignAttributes.ts +0 -16
  64. package/packages/dom/src/structure/CSS.ts +0 -7
  65. package/packages/dom/src/structure/CSSStyleSheet.ts +0 -10
  66. package/packages/dom/src/structure/DOMTokenList.ts +0 -19
  67. package/packages/dom/src/structure/Document.ts +0 -36
  68. package/packages/dom/src/structure/Element.ts +0 -106
  69. package/packages/dom/src/structure/HTMLElement.ts +0 -34
  70. package/packages/dom/src/structure/History.ts +0 -11
  71. package/packages/dom/src/structure/Location.ts +0 -9
  72. package/packages/dom/src/structure/Node.ts +0 -51
  73. package/packages/dom/src/structure/NodeList.ts +0 -10
  74. package/packages/dom/src/structure/Storage.ts +0 -8
  75. package/packages/dom/src/structure/Text.ts +0 -20
  76. package/packages/dom/src/structure/Window.ts +0 -14
  77. package/packages/dom/src/structure/html/HTMLAbbrElement.ts +0 -16
  78. package/packages/dom/src/structure/html/HTMLAddressElement.ts +0 -16
  79. package/packages/dom/src/structure/html/HTMLAnchorElement.ts +0 -25
  80. package/packages/dom/src/structure/html/HTMLAreaElement.ts +0 -26
  81. package/packages/dom/src/structure/html/HTMLArticleElement.ts +0 -16
  82. package/packages/dom/src/structure/html/HTMLAsideElement.ts +0 -16
  83. package/packages/dom/src/structure/html/HTMLAudioElement.ts +0 -16
  84. package/packages/dom/src/structure/html/HTMLBDIElement.ts +0 -16
  85. package/packages/dom/src/structure/html/HTMLBDOElement.ts +0 -16
  86. package/packages/dom/src/structure/html/HTMLBElement.ts +0 -16
  87. package/packages/dom/src/structure/html/HTMLBRElement.ts +0 -17
  88. package/packages/dom/src/structure/html/HTMLBaseElement.ts +0 -18
  89. package/packages/dom/src/structure/html/HTMLBodyElement.ts +0 -22
  90. package/packages/dom/src/structure/html/HTMLButtonElement.ts +0 -26
  91. package/packages/dom/src/structure/html/HTMLCanvasElement.ts +0 -18
  92. package/packages/dom/src/structure/html/HTMLCiteElement.ts +0 -16
  93. package/packages/dom/src/structure/html/HTMLCodeElement.ts +0 -16
  94. package/packages/dom/src/structure/html/HTMLDDElement.ts +0 -16
  95. package/packages/dom/src/structure/html/HTMLDFNElement.ts +0 -16
  96. package/packages/dom/src/structure/html/HTMLDListElement.ts +0 -17
  97. package/packages/dom/src/structure/html/HTMLDTElement.ts +0 -16
  98. package/packages/dom/src/structure/html/HTMLDataElement.ts +0 -17
  99. package/packages/dom/src/structure/html/HTMLDataListElement.ts +0 -16
  100. package/packages/dom/src/structure/html/HTMLDetailsElement.ts +0 -17
  101. package/packages/dom/src/structure/html/HTMLDialogElement.ts +0 -18
  102. package/packages/dom/src/structure/html/HTMLDivElement.ts +0 -17
  103. package/packages/dom/src/structure/html/HTMLEMElement.ts +0 -16
  104. package/packages/dom/src/structure/html/HTMLEmbedElement.ts +0 -20
  105. package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +0 -19
  106. package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +0 -16
  107. package/packages/dom/src/structure/html/HTMLFigureElement.ts +0 -16
  108. package/packages/dom/src/structure/html/HTMLFooterElement.ts +0 -16
  109. package/packages/dom/src/structure/html/HTMLFormElement.ts +0 -24
  110. package/packages/dom/src/structure/html/HTMLHGroupElement.ts +0 -16
  111. package/packages/dom/src/structure/html/HTMLHRElement.ts +0 -21
  112. package/packages/dom/src/structure/html/HTMLHeadElement.ts +0 -16
  113. package/packages/dom/src/structure/html/HTMLHeaderElement.ts +0 -16
  114. package/packages/dom/src/structure/html/HTMLHeadingElement.ts +0 -17
  115. package/packages/dom/src/structure/html/HTMLHtmlElement.ts +0 -18
  116. package/packages/dom/src/structure/html/HTMLIElement.ts +0 -16
  117. package/packages/dom/src/structure/html/HTMLIFrameElement.ts +0 -31
  118. package/packages/dom/src/structure/html/HTMLImageElement.ts +0 -38
  119. package/packages/dom/src/structure/html/HTMLInputElement.ts +0 -55
  120. package/packages/dom/src/structure/html/HTMLKBDElement.ts +0 -16
  121. package/packages/dom/src/structure/html/HTMLLIElement.ts +0 -18
  122. package/packages/dom/src/structure/html/HTMLLabelElement.ts +0 -18
  123. package/packages/dom/src/structure/html/HTMLLegendElement.ts +0 -17
  124. package/packages/dom/src/structure/html/HTMLLinkElement.ts +0 -31
  125. package/packages/dom/src/structure/html/HTMLMainElement.ts +0 -16
  126. package/packages/dom/src/structure/html/HTMLMapElement.ts +0 -17
  127. package/packages/dom/src/structure/html/HTMLMarkElement.ts +0 -16
  128. package/packages/dom/src/structure/html/HTMLMediaElement.ts +0 -48
  129. package/packages/dom/src/structure/html/HTMLMenuElement.ts +0 -18
  130. package/packages/dom/src/structure/html/HTMLMetaElement.ts +0 -22
  131. package/packages/dom/src/structure/html/HTMLMeterElement.ts +0 -23
  132. package/packages/dom/src/structure/html/HTMLModElement.ts +0 -18
  133. package/packages/dom/src/structure/html/HTMLNavElement.ts +0 -16
  134. package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +0 -16
  135. package/packages/dom/src/structure/html/HTMLOListElement.ts +0 -20
  136. package/packages/dom/src/structure/html/HTMLObjectElement.ts +0 -34
  137. package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +0 -18
  138. package/packages/dom/src/structure/html/HTMLOptionElement.ts +0 -20
  139. package/packages/dom/src/structure/html/HTMLOutputElement.ts +0 -20
  140. package/packages/dom/src/structure/html/HTMLParagraphElement.ts +0 -17
  141. package/packages/dom/src/structure/html/HTMLPictureElement.ts +0 -16
  142. package/packages/dom/src/structure/html/HTMLPreElement.ts +0 -17
  143. package/packages/dom/src/structure/html/HTMLProgressElement.ts +0 -19
  144. package/packages/dom/src/structure/html/HTMLQuoteElement.ts +0 -17
  145. package/packages/dom/src/structure/html/HTMLRPElement.ts +0 -16
  146. package/packages/dom/src/structure/html/HTMLRTElement.ts +0 -16
  147. package/packages/dom/src/structure/html/HTMLRubyElement.ts +0 -16
  148. package/packages/dom/src/structure/html/HTMLSElement.ts +0 -16
  149. package/packages/dom/src/structure/html/HTMLSampElement.ts +0 -16
  150. package/packages/dom/src/structure/html/HTMLScriptElement.ts +0 -27
  151. package/packages/dom/src/structure/html/HTMLSectionElement.ts +0 -16
  152. package/packages/dom/src/structure/html/HTMLSelectElement.ts +0 -27
  153. package/packages/dom/src/structure/html/HTMLSlotElement.ts +0 -17
  154. package/packages/dom/src/structure/html/HTMLSmallElement.ts +0 -16
  155. package/packages/dom/src/structure/html/HTMLSourceElement.ts +0 -21
  156. package/packages/dom/src/structure/html/HTMLSpanElement.ts +0 -16
  157. package/packages/dom/src/structure/html/HTMLStrongElement.ts +0 -16
  158. package/packages/dom/src/structure/html/HTMLStyleElement.ts +0 -18
  159. package/packages/dom/src/structure/html/HTMLSubElement.ts +0 -16
  160. package/packages/dom/src/structure/html/HTMLSummaryElement.ts +0 -16
  161. package/packages/dom/src/structure/html/HTMLSupElement.ts +0 -16
  162. package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +0 -17
  163. package/packages/dom/src/structure/html/HTMLTableCellElement.ts +0 -31
  164. package/packages/dom/src/structure/html/HTMLTableColElement.ts +0 -23
  165. package/packages/dom/src/structure/html/HTMLTableElement.ts +0 -26
  166. package/packages/dom/src/structure/html/HTMLTableRowElement.ts +0 -23
  167. package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +0 -20
  168. package/packages/dom/src/structure/html/HTMLTemplateElement.ts +0 -17
  169. package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +0 -33
  170. package/packages/dom/src/structure/html/HTMLTimeElement.ts +0 -17
  171. package/packages/dom/src/structure/html/HTMLTitleElement.ts +0 -17
  172. package/packages/dom/src/structure/html/HTMLTrackElement.ts +0 -21
  173. package/packages/dom/src/structure/html/HTMLUElement.ts +0 -16
  174. package/packages/dom/src/structure/html/HTMLUListElement.ts +0 -18
  175. package/packages/dom/src/structure/html/HTMLVarElement.ts +0 -16
  176. package/packages/dom/src/structure/html/HTMLVideoElement.ts +0 -22
  177. package/packages/dom/src/structure/html/HTMLWBRElement.ts +0 -16
  178. package/packages/html/package.json +0 -18
  179. package/packages/html/src/index.ts +0 -13
  180. package/packages/html/src/node/$Anchor.ts +0 -49
  181. package/packages/html/src/node/$Canvas.ts +0 -38
  182. package/packages/html/src/node/$Dialog.ts +0 -16
  183. package/packages/html/src/node/$Form.ts +0 -16
  184. package/packages/html/src/node/$Image.ts +0 -72
  185. package/packages/html/src/node/$Input.ts +0 -193
  186. package/packages/html/src/node/$Label.ts +0 -25
  187. package/packages/html/src/node/$Media.ts +0 -16
  188. package/packages/html/src/node/$OptGroup.ts +0 -23
  189. package/packages/html/src/node/$Option.ts +0 -40
  190. package/packages/html/src/node/$Select.ts +0 -76
  191. package/packages/html/src/node/$TextArea.ts +0 -16
  192. package/packages/i18n/README.md +0 -73
  193. package/packages/i18n/package.json +0 -19
  194. package/packages/i18n/src/index.ts +0 -140
  195. package/packages/i18n/src/structure/I18n.ts +0 -44
  196. package/packages/i18n/src/structure/I18nDictionary.ts +0 -31
  197. package/packages/i18n/src/structure/I18nTranslation.ts +0 -41
  198. package/packages/idb/README.md +0 -127
  199. package/packages/idb/package.json +0 -19
  200. package/packages/idb/src/core.ts +0 -6
  201. package/packages/idb/src/index.ts +0 -17
  202. package/packages/idb/src/lib/$IDBRequest.ts +0 -8
  203. package/packages/idb/src/structure/$IDB.ts +0 -63
  204. package/packages/idb/src/structure/$IDBCursor.ts +0 -34
  205. package/packages/idb/src/structure/$IDBIndex.ts +0 -48
  206. package/packages/idb/src/structure/$IDBStore.ts +0 -103
  207. package/packages/idb/src/structure/$IDBStoreBase.ts +0 -30
  208. package/packages/idb/src/structure/$IDBTransaction.ts +0 -38
  209. package/packages/idb/src/structure/builder/$IDBBuilder.ts +0 -229
  210. package/packages/idb/src/structure/builder/$IDBStoreBuilder.ts +0 -100
  211. package/packages/markdown/README.md +0 -53
  212. package/packages/markdown/package.json +0 -19
  213. package/packages/markdown/src/index.ts +0 -3
  214. package/packages/markdown/src/lib/type.ts +0 -26
  215. package/packages/markdown/src/lib/util.ts +0 -21
  216. package/packages/markdown/src/structure/Markdown.ts +0 -54
  217. package/packages/markdown/src/structure/MarkdownLexer.ts +0 -111
  218. package/packages/markdown/src/structure/MarkdownParser.ts +0 -34
  219. package/packages/markdown/src/syntax/alert.ts +0 -46
  220. package/packages/markdown/src/syntax/blockquote.ts +0 -35
  221. package/packages/markdown/src/syntax/bold.ts +0 -11
  222. package/packages/markdown/src/syntax/code.ts +0 -11
  223. package/packages/markdown/src/syntax/codeblock.ts +0 -44
  224. package/packages/markdown/src/syntax/heading.ts +0 -14
  225. package/packages/markdown/src/syntax/horizontalRule.ts +0 -11
  226. package/packages/markdown/src/syntax/image.ts +0 -23
  227. package/packages/markdown/src/syntax/italic.ts +0 -11
  228. package/packages/markdown/src/syntax/link.ts +0 -46
  229. package/packages/markdown/src/syntax/list.ts +0 -121
  230. package/packages/markdown/src/syntax/table.ts +0 -67
  231. package/packages/markdown/src/syntax/text.ts +0 -19
  232. package/packages/router/README.md +0 -175
  233. package/packages/router/package.json +0 -19
  234. package/packages/router/src/index.ts +0 -68
  235. package/packages/router/src/node/Page.ts +0 -38
  236. package/packages/router/src/node/Router.ts +0 -212
  237. package/packages/router/src/node/RouterAnchor.ts +0 -24
  238. package/packages/router/src/structure/PageBuilder.ts +0 -24
  239. package/packages/router/src/structure/Route.ts +0 -105
  240. package/packages/signal/README.md +0 -93
  241. package/packages/signal/package.json +0 -18
  242. package/packages/signal/src/index.ts +0 -221
  243. package/packages/signal/src/structure/Signal.ts +0 -38
  244. package/packages/ui/lib/VirtualScroll.ts +0 -25
  245. package/packages/ui/node/Accordian.ts +0 -97
  246. package/packages/ui/node/Carousel.ts +0 -20
  247. package/packages/ui/node/Form.ts +0 -54
  248. package/packages/ui/node/Grid.ts +0 -0
  249. package/packages/ui/node/Modal.ts +0 -45
  250. package/packages/ui/node/Table.ts +0 -43
  251. package/packages/ui/node/Tabs.ts +0 -129
  252. package/packages/ui/node/Toast.ts +0 -16
  253. package/packages/ui/node/Waterfall.ts +0 -94
  254. package/packages/ui/package.json +0 -21
  255. package/packages/utils/package.json +0 -17
  256. package/packages/utils/src/global.ts +0 -25
  257. package/packages/utils/src/index.ts +0 -90
@@ -1,105 +0,0 @@
1
- import type { Page } from "#node/Page";
2
- import { _null, _instanceof, isUndefined } from "@amateras/utils";
3
- import { PageBuilder, type PageBuilderFunction } from "./PageBuilder";
4
-
5
- export class Route<Path extends RoutePath = RoutePath, Params extends RouteParams = []> {
6
- readonly routes = new Map<RoutePath, Route>();
7
- readonly path: Path;
8
- readonly builder: PageBuilder<any> | undefined;
9
- readonly paths = new Map<string, RouteAliasParams<RoutePath, Params> | null>()
10
- readonly pages = new Map<string, Page>();
11
- redirectURL: string | null = null
12
- constructor(path: Path, builder?: RouteBuilder<Params>) {
13
- this.path = path;
14
- this.paths.set(path, _null);
15
- this.builder = _instanceof(builder, PageBuilder<any>) || isUndefined(builder) ? builder : new PageBuilder(builder as any);
16
- }
17
-
18
-
19
- alias<K extends string, P extends RouteAliasParams<K, Params>>(path: K, ...params: RequireKeys<P> extends never ? [] : [Prettify<P>]): this
20
- alias(path: string, params: RouteAliasParams<RoutePath, Params> | null = _null) {
21
- this.paths.set(path, params);
22
- return this;
23
- }
24
- }
25
-
26
- export interface Route<Path extends RoutePath = RoutePath, Params extends RouteParams = []> {
27
- route<
28
- P extends RoutePath,
29
- B extends PageBuilder
30
- >(path: P, builder: B, handle?: (route: Route<`${Path}${P}`, B['params']>) => Route<`${Path}${P}`, B['params']>): this
31
- route<
32
- K extends RoutePath,
33
- P extends [...Params, ...RouteParamsStrings<K>],
34
- F extends PageBuilderFunction<P>
35
- >(path: K, builder: F, handle?: (route: Route<`${Path}${K}`, P>) => Route<`${Path}${K}`, P>): this
36
- route<
37
- K extends RoutePath,
38
- P extends [...Params, ...RouteParamsStrings<K>],
39
- F extends AsyncPageBuilder<P>
40
- >(path: K, builder: F, handle?: (route: Route<`${Path}${K}`, P>) => Route<`${Path}${K}`, P>): this
41
- route<P extends RoutePath>(path: P, builder: RouteBuilder<RouteParamsResolver<`${Path}${P}`>>, handle?: <R extends Route<`${Path}${P}`>>(route: R) => R): this;
42
- group<P extends RoutePath>(path: P, handle: <R extends Route<`${Path}${P}`>>(route: R) => R): this;
43
- notFound(builder: RouteBuilder<RouteParamsResolver<`${Path}`>>): this;
44
- }
45
-
46
- export type RouteBuilder<Params extends RouteParams = []> = PageBuilder<Params | `${string}?`[]> | AsyncPageBuilder<Params | `${string}?`[]> | PageBuilderFunction<Params>;
47
- export type RoutePath = string;
48
- export type RouteParams = string[]
49
- export type AsyncPageBuilder<Params extends RouteParams = any> = () => Promise<{default: PageBuilder<Params>}>
50
-
51
- export type RouteParamsResolver<Path extends RoutePath> = RouteParamsOptional<RouteParamsStrings<Path>>
52
-
53
- /** Convert route path to literals array */
54
- export type RouteParamsStrings<Path extends string> =
55
- Path extends `${infer Segment}/${infer Rest}`
56
- ? Segment extends `${string}:${infer Param}`
57
- ? [Param, ...RouteParamsStrings<Rest>]
58
- : [...RouteParamsStrings<Rest>]
59
- : Path extends `${string}:${infer Param}?${infer Query}`
60
- ? [Param]
61
- : Path extends `${string}:${infer Param}`
62
- ? [Param]
63
- : []
64
- /** Convert route path to object structure */
65
- export type RouteParamsConfig<Path extends string> =
66
- Path extends `${infer Segment}/${infer Rest}`
67
- ? Segment extends `${string}:${infer Param}`
68
- ? { [key in Param]: string } & RouteParamsConfig<Rest>
69
- : RouteParamsConfig<Rest>
70
- : Path extends `${string}:${infer Param}?${infer Query}`
71
- ? { [key in Param]: string }
72
- : Path extends `${string}:${infer Param}`
73
- ? { [key in Param]: string }
74
- : {}
75
- /** Convert literals array to optional literals arrays */
76
- export type RouteParamsOptional<Params extends string[]> =
77
- Params extends [infer A, ...infer Rest]
78
- ? Rest extends string[]
79
- ? A extends string
80
- ? [A | `${A}?`, ...RouteParamsOptional<Rest>] | RouteParamsOptional<Rest>
81
- : never
82
- : never
83
- : []
84
-
85
- export type RouteAliasPath<Path extends string, RoutePath extends string> = RouteParamsStrings<RoutePath> extends RouteParamsStrings<Path> ? Route<RoutePath> : never
86
-
87
- type RouteParamsConfigByArrayString<RouteParams extends string[]> =
88
- RouteParams extends [`${infer A}`, ...infer Rest]
89
- ? Rest extends string[]
90
- ? A extends `${infer P}?`
91
- ? { [key in P]?: string } & RouteParamsConfigByArrayString<Rest>
92
- : { [key in A]: string } & RouteParamsConfigByArrayString<Rest>
93
- : never
94
- : {}
95
-
96
-
97
- type RouteAliasParams<Path extends string, Params extends RouteParams> = Omit<RouteParamsConfigByArrayString<Params>, keyof RouteParamsConfig<Path>>
98
-
99
- type a<T> = T[keyof T] extends (string | undefined) ? true : false
100
-
101
- type b = RequireKeys<{t: string, a?: string, b?: string}> & {}
102
-
103
- type RequireKeys<T> = {
104
- [K in keyof T]: {} extends Pick<T, K> ? never : K
105
- }[keyof T];
@@ -1,93 +0,0 @@
1
- # amateras/signal
2
-
3
- ## Usage
4
-
5
- ```ts
6
- import 'amateras';
7
- import 'amateras/signal';
8
-
9
- // define a signal with value 0
10
- const count$ = $.signal(0);
11
-
12
- // this variable will be auto recalculate when count$ changes
13
- const doubleCount$ = $.compute(() => count$() * 2);
14
-
15
- // the console message will fired when count$ changes
16
- $.effect(() => console.log( count$() ))
17
-
18
- $(document.body).content([
19
- // Display Counts
20
- $('p').content( $`Counts: ${count$}` ),
21
-
22
- // Display Double Counts
23
- $('p').content( $`Double Counts: ${doubleCount$}` ),
24
-
25
- // Create a button that make counts plus 1 on click
26
- $('button').content('Add Count').on('click', () => count$.set(value => value + 1))
27
- ])
28
- ```
29
-
30
- ## Read and Write
31
-
32
- ```ts
33
- const number$ = $.signal(0);
34
- const string$ = $.singal('');
35
- const boolean$ = $.signal(false);
36
- const object$ = $.signal({ number: 1 });
37
-
38
- // write value
39
- number$.set(42);
40
- string$.set('New Content');
41
- boolean$.set(true);
42
- object$.set({ number: 42 });
43
-
44
- // read value
45
- number$(); // 42
46
- string$(); // 'New Content'
47
- boolean$(); // true
48
- object$(); // { number: 42 }
49
- ```
50
-
51
- ## Use in attribute methods
52
-
53
- ```ts
54
- const src$ = $.signal('/image-1.png');
55
-
56
- $(document.body).content([
57
- // you can set signal variable in attribute
58
- $('img').src( src$ ),
59
-
60
- $('button').content('Change Image').on('click', () => src$.set('/image-2.png'))
61
- ])
62
- ```
63
-
64
- ## Reactive object
65
-
66
- ```ts
67
- const user$ = $.signal({
68
- name: 'Amateras',
69
- age: 16,
70
- avatar: {
71
- url: '/amateras/avatar.png',
72
- size: '350x350'
73
- }
74
- })
75
-
76
- $(document.body).content([
77
- // Display name and age
78
- $('h1').content( $`${user$.name$} (${user$.age$})` ),
79
- // Display avatar image
80
- $('img').src( user$.avatar$.url$ ),
81
- // Change the user$ when button is clicked
82
- $('button')
83
- .content('Change User')
84
- .on('click', () => user$.set({
85
- name: 'Tsukimi',
86
- age: 10,
87
- avatar: {
88
- url: '/tsukimi/avatar.png',
89
- size: '350x350'
90
- }
91
- }))
92
- ])
93
- ```
@@ -1,18 +0,0 @@
1
- {
2
- "name": "@amateras/signal",
3
- "peerDependencies": {
4
- "@amateras/core": "workspace:*",
5
- "@amateras/utils": "workspace:*"
6
- },
7
- "imports": {
8
- "#structure/*": "./src/structure/*.ts",
9
- "#lib/*": "./src/lib/*.ts",
10
- "#node/*": "./src/node/*.ts"
11
- },
12
- "exports": {
13
- ".": "./src/index.ts",
14
- "./structure/*": "./src/structure/*.ts",
15
- "./lib/*": "./src/lib/*.ts",
16
- "./node/*": "./src/node/*.ts"
17
- }
18
- }
@@ -1,221 +0,0 @@
1
- import { Signal } from "#structure/Signal";
2
- import { $Node, $Text, type $NodeContentResolver } from "@amateras/core/node/$Node";
3
- import { _instanceof, isObject, _JSON_stringify, _Object_assign, forEach, _null, _Object_defineProperty, _Object_entries, isNull, isFunction, _Promise, toArray } from "@amateras/utils";
4
-
5
- // handle $Node content process
6
- $Node.processors.add((_, content) => {
7
- const signal = (content as SignalFunction<any>)?.signal;
8
- if (_instanceof(signal, Signal)) {
9
- const signalValue = (content as SignalFunction<any>)();
10
- const signalHandler = (resolver: any): $NodeContentResolver<any> => {
11
- if (_instanceof(resolver, _Promise)) {
12
- return resolver.then(signalHandler) as any;
13
- }
14
- else if (_instanceof(resolver, $Node)) {
15
- // handler signal $Node result
16
- let node = resolver;
17
- const set = (value: any) => {
18
- node.replace(value);
19
- node = value;
20
- }
21
- signal.subscribe(set);
22
- return [resolver];
23
- } else {
24
- // handler signal other type result
25
- const $text = new $Text()
26
- const set = (value: any) => $text.textContent(isObject(value) ? _JSON_stringify(value) : value);
27
- signal.subscribe(set);
28
- set(resolver);
29
- return [$text];
30
- }
31
- }
32
- return signalHandler(signalValue);
33
- }
34
- })
35
-
36
- // handle $Node native method setter
37
- $Node.setters.add((value, set) => {
38
- const signal = value?.signal;
39
- if (isFunction(value) && _instanceof(signal, Signal)) {
40
- signal.subscribe(set);
41
- return value();
42
- }
43
- })
44
-
45
- declare module '@amateras/core' {
46
- export namespace $ {
47
- export function signal<T>(value: T): SignalFunction<T>;
48
- export function compute<T>(process: (untrack: UntrackHandler) => T): ComputeFunction<T>;
49
- export function effect(process: (untrack: UntrackHandler) => void): void;
50
- export function await<K, O extends SignalAwaitOptions<K, unknown>>(signalFn: SignalFunction<OrPromise<K>> | ComputeFunction<OrPromise<K>>, options: O): O[keyof O];
51
- export interface $NodeContentMap {
52
- signalFn: SignalFunction<any>;
53
- computeFn: ComputeFunction<any>;
54
- }
55
- export interface $NodeParameterMap<T> {
56
- // Distribute T type
57
- signalFn: T extends any ? SignalFunction<Narrow<T>> : never;
58
- computeFn: T extends any ? ComputeFunction<Narrow<T>> : never;
59
- }
60
- }
61
- }
62
-
63
- type SignalObject<T> = T extends Array<any> ? {} : T extends object ? { [key in keyof T as `${string & key}$`]: SignalFunction<T[key]> } : {};
64
- type SignalValue<T> = T extends Promise<infer R> ? T | R : T;
65
- export type SignalPromiseState = 'await' | 'then' | 'catch';
66
- export type SignalAwaitOptions<T, R> = {
67
- await: R | (() => R);
68
- then: R | ((value: T) => R);
69
- catch: R | ((error: any) => R);
70
- }
71
-
72
- export type SignalFunction<T> = {
73
- (): T;
74
- signal: Signal<T>;
75
- set: (newValue: SignalValue<T> | ((oldValue: T) => SignalValue<T>)) => SignalFunction<T>;
76
- value: () => T;
77
- state: SignalPromiseState;
78
- await: <R>(resolver: R) => AwaitFunction<T, R>
79
- } & SignalObject<T>;
80
-
81
- export type ComputeFunction<T> = {
82
- (): T;
83
- signal: Signal<T>;
84
- state: SignalPromiseState;
85
- };
86
-
87
- export type AwaitFunction<T, R> = {
88
- (): R;
89
- then<D>(resolver: (value: Awaited<T>) => D): AwaitFunction<T, R | D>;
90
- then<D>(resolver: D): AwaitFunction<T, R | D>;
91
- catch<D>(resolver: (error: any) => D): AwaitFunction<T, R | D>;
92
- catch<D>(resolver: D): AwaitFunction<T, R | D>;
93
- } & ComputeFunction<T>
94
-
95
- export type SignalListener = (signal: Signal<any>) => void;
96
- export type UntrackHandler = <T>(fn: () => T) => T
97
-
98
- const signalComputeListeners = new Set<SignalListener>();
99
- const signalEffectListeners = new Set<SignalListener>();
100
- const signalFnMap = new Map<any, SignalFunction<any> | ComputeFunction<any>>();
101
-
102
- // experiment feature
103
- const nestedComputeFn = (value: any, parentSignalFn: SignalFunction<any> | ComputeFunction<any>) => {
104
- if (isObject(value) && !isNull(value)) {
105
- forEach(_Object_entries(value), ([key, val]) => {
106
- const cachedFn = signalFnMap.get(val);
107
- const val$ = cachedFn ?? $.compute(() => parentSignalFn()[key]);
108
- if (!cachedFn && isObject(val)) {
109
- signalFnMap.set(val, val$);
110
- nestedComputeFn(val, val$)
111
- }
112
- _Object_defineProperty(parentSignalFn, `${key}$`, {value: val$});
113
- })
114
- }
115
- }
116
-
117
- const AWAIT = 'await';
118
- const THEN = 'then';
119
- const CATCH = 'catch';
120
-
121
- _Object_assign($, {
122
- // signal function
123
- signal<T>(value: T): SignalFunction<T> {
124
- const signal = new Signal<T>(value);
125
- const signalFn = function () {
126
- forEach([...signalComputeListeners, ...signalEffectListeners], fn => fn(signal));
127
- return signal.value();
128
- } as SignalFunction<T>
129
- nestedComputeFn(value, signalFn);
130
- if (_instanceof(value, _Promise)) {
131
- value.catch(err => {
132
- signalFn.state = CATCH;
133
- signal.value(err);
134
- }).then(v => {
135
- signalFn.state = THEN;
136
- signal.value(v as any);
137
- })
138
- }
139
- _Object_assign(signalFn, {
140
- signal,
141
- set: (newValue: T) => (signal.value(newValue), signalFn),
142
- value: () => signal.value(),
143
- state: _instanceof(value, _Promise) ? AWAIT : THEN,
144
-
145
- await(awaitResolver: any) {
146
- let thenResolver: any = _null
147
- let catchResolver: any = _null
148
- const awaitFn = $.compute(untrack => {
149
- const value = signalFn();
150
- return untrack(() => {
151
- switch (signalFn.state) {
152
- case AWAIT: return isFunction(awaitResolver) ? awaitResolver() : awaitResolver;
153
- case THEN: return isFunction(thenResolver) ? thenResolver(value as any) : thenResolver;
154
- case CATCH: return isFunction(catchResolver) ? catchResolver(value) : catchResolver;
155
- }
156
- })
157
- })
158
-
159
- _Object_assign(awaitFn, {
160
- then(resolver: any) {
161
- thenResolver = resolver;
162
- return awaitFn;
163
- },
164
- catch(resolver: any) {
165
- catchResolver = resolver;
166
- return awaitFn;
167
- }
168
- })
169
-
170
- return awaitFn;
171
- }
172
- })
173
- return signalFn
174
- },
175
-
176
- // compute function
177
- compute<T>(process: (untrack: UntrackHandler) => T): ComputeFunction<T> {
178
- let subscribed = false;
179
- const signalFn: SignalFunction<any> = $.signal(_null);
180
- const computeFn = () => {
181
- if (!subscribed) return signalFn.set(subscribe()).value();
182
- else return signalFn.set(process(untrack)).value();
183
- }
184
- const untrack = <T>(fn: () => T) => {
185
- if (subscribed) return fn();
186
- signalComputeListeners.delete(signalListener);
187
- const result = fn();
188
- signalComputeListeners.add(signalListener);
189
- return result;
190
- }
191
- const signalListener = (signal: Signal<any>) =>
192
- signal.subscribe(() => signalFn.set(process(untrack)))
193
- const subscribe = () => {
194
- signalComputeListeners.add(signalListener);
195
- const result = process(untrack);
196
- signalComputeListeners.delete(signalListener);
197
- subscribed = true;
198
- return result;
199
- }
200
- _Object_assign(computeFn, { signal: signalFn.signal });
201
- return computeFn as ComputeFunction<T>
202
- },
203
-
204
- // effect
205
- effect(process: (untrack: UntrackHandler) => void) {
206
- let subscribed = false;
207
- const signalListener = (signal: Signal<any>) =>
208
- signal.subscribe(_ => process(untrack));
209
- const untrack = <T>(fn: () => T) => {
210
- if (subscribed) return fn();
211
- signalEffectListeners.delete(signalListener);
212
- const result = fn();
213
- signalEffectListeners.add(signalListener);
214
- return result;
215
- }
216
- signalEffectListeners.add(signalListener);
217
- process(untrack);
218
- signalEffectListeners.delete(signalListener);
219
- subscribed = true;
220
- },
221
- })
@@ -1,38 +0,0 @@
1
- import { _instanceof, forEach, isFunction, isUndefined } from "@amateras/utils";
2
-
3
- export class Signal<T> {
4
- #value: T;
5
- #subscribers = new Set<(value: T) => void>();
6
- constructor(value: T) {
7
- this.#value = value;
8
- }
9
-
10
- value(): T;
11
- value(newValue: T): this;
12
- value(callback: (oldValue: T) => T): this;
13
- value(resolver?: T | ((oldValue: T) => T)) {
14
- if (!arguments.length) return this.#value;
15
- if (isFunction(resolver)) this.value(resolver(this.#value));
16
- else if (!isUndefined(resolver)) {
17
- this.#value = resolver;
18
- this.emit();
19
- }
20
- return this;
21
- }
22
-
23
- emit() {
24
- forEach(this.#subscribers, subs => subs(this.#value))
25
- return this;
26
- }
27
-
28
- subscribe(callback: (value: T) => void) {
29
- this.#subscribers.add(callback);
30
- return this;
31
- }
32
-
33
- unsubscribe(callback: (value: T) => void) {
34
- this.#subscribers.delete(callback);
35
- return this;
36
- }
37
-
38
- }
@@ -1,25 +0,0 @@
1
- import { _document } from "@amateras/core/env";
2
- import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
- import type { $Node } from "@amateras/core/node/$Node";
4
- import type { $Virtual } from "@amateras/core/node/$Virtual";
5
- import { _Array_from, _instanceof, forEach } from "@amateras/utils";
6
-
7
- export const VirtualScroll = ($parent: $Virtual, scroller: $Node = $(_document)) => {
8
- scroller.on('scroll', () => render($parent), true);
9
- $parent.on('layout', () => render($parent));
10
- }
11
-
12
- const render = ($parent: $Virtual) => {
13
- const number = parseInt;
14
- const parentRect = $parent.getBoundingClientRect();
15
- const children = _Array_from($parent.nodes);
16
- forEach(children, $child => {
17
- if (!_instanceof($child, $HTMLElement)) return;
18
- const { top, height } = $child.style();
19
- const topPos = parentRect.top + number(top);
20
- const bottomPos = topPos + number(height);
21
- if (bottomPos < 0 || topPos > outerHeight + 200) $parent.hide($child);
22
- else $parent.show($child);
23
- })
24
- $parent.render();
25
- }
@@ -1,97 +0,0 @@
1
- import { chain } from "@amateras/core/lib/chain";
2
- import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
- import type { $Node, $NodeContentResolver } from "@amateras/core/node/$Node";
4
- import { _Array_from, _instanceof, forEach, isNull } from "@amateras/utils";
5
-
6
- const [ACCORDIAN, ACCORDIAN_ITEM, ACCORDIAN_TRIGGER, ACCORDIAN_CONTENT, ACCORDIAN_CONTAINER] = ['accordian', 'accordian-item', 'accordian-trigger', 'accordian-content', 'accordian-container'] as const;
7
- forEach([
8
- `${ACCORDIAN},${ACCORDIAN_ITEM},${ACCORDIAN_TRIGGER}{display:block}`,
9
- `${ACCORDIAN_CONTENT}{display:grid;grid-template-rows:0fr}`,
10
- `${ACCORDIAN_CONTENT}[opened]{grid-template-rows:1fr}`,
11
- `${ACCORDIAN_CONTAINER}{overflow:hidden}`,
12
- ], $.style)
13
-
14
- export class Accordian extends $HTMLElement {
15
- #autoclose = false;
16
- constructor() {
17
- super(ACCORDIAN);
18
- }
19
-
20
- autoclose(): boolean;
21
- autoclose(autoclose: boolean): this;
22
- autoclose(autoclose?: boolean) {
23
- return chain(this, arguments, () => this.#autoclose, autoclose, autoclose => this.#autoclose = autoclose);
24
- }
25
-
26
- get items() {
27
- return _Array_from($(this.childNodes)).filter($child => _instanceof($child, AccordianItem))
28
- }
29
- }
30
-
31
- export class AccordianItem extends $HTMLElement {
32
- $content: null | AccordianContent = null;
33
- $trigger: null | AccordianTrigger = null;
34
- $root: null | Accordian = null;
35
- constructor() {
36
- super(ACCORDIAN_ITEM);
37
- }
38
-
39
- mounted($parent: $Node): this {
40
- if (_instanceof($parent, Accordian)) this.$root = $parent;
41
- forEach($(this.childNodes), $c => {
42
- if (_instanceof($c, AccordianTrigger)) this.$trigger = $c;
43
- if (_instanceof($c, AccordianContent)) this.$content = $c;
44
- })
45
- return this;
46
- }
47
- }
48
-
49
- export class AccordianTrigger extends $HTMLElement {
50
- $item: null | AccordianItem = null;
51
- constructor() {
52
- super(ACCORDIAN_TRIGGER);
53
- this.on('click', _ => {
54
- const $item = this.$item;
55
- const $root = $item?.$root;
56
- this.$item?.$content?.use($content => isNull($content.attr('opened')) ? $content.open() : $content.close());
57
- $root?.autoclose() && $root.items.forEach($i => $i !== $item && $i.$content?.close())
58
- })
59
- }
60
-
61
- mounted($parent: $Node): this {
62
- if (_instanceof($parent, AccordianItem)) this.$item = $parent;
63
- return this;
64
- }
65
- }
66
-
67
- export class AccordianContent extends $HTMLElement {
68
- $container = $(AccordianContainer);
69
- constructor() {
70
- super(ACCORDIAN_CONTENT);
71
- super.insert(this.$container);
72
- }
73
-
74
- content(children: $NodeContentResolver<AccordianContainer>): this {
75
- this.$container.content(children);
76
- return this;
77
- }
78
-
79
- insert(resolver: $NodeContentResolver<AccordianContainer>, position?: number): this {
80
- this.$container.insert(resolver, position);
81
- return this;
82
- }
83
-
84
- open() {
85
- return this.attr({opened: ''})
86
- }
87
-
88
- close() {
89
- return this.attr({opened: null});
90
- }
91
- }
92
-
93
- export class AccordianContainer extends $HTMLElement {
94
- constructor() {
95
- super(ACCORDIAN_CONTAINER);
96
- }
97
- }
@@ -1,20 +0,0 @@
1
- import { chain } from "@amateras/core/lib/chain";
2
- import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
3
-
4
- const CAROUSEL = 'carousel';
5
- const CAROUSEL_ITEM = 'carousel-item';
6
-
7
- export class Carousel extends $HTMLElement {
8
- constructor() {
9
- super(CAROUSEL);
10
- }
11
-
12
- }
13
-
14
- export class CarouselItem extends $HTMLElement {
15
- constructor() {
16
- super(CAROUSEL_ITEM)
17
- }
18
- }
19
-
20
- export type CarouselDirection = 'horizontal' | 'vertical';
@@ -1,54 +0,0 @@
1
- import { $HTMLElement } from "@amateras/core/node/$HTMLElement";
2
- import type { $Node } from "@amateras/core/node/$Node";
3
- import { $Form } from "@amateras/html/node/$Form";
4
- import { $Input } from "@amateras/html/node/$Input";
5
- import { $Label } from "@amateras/html/node/$Label";
6
- import { _instanceof, _undefined } from "@amateras/utils";
7
-
8
-
9
- export class Form extends $Form {
10
- constructor() {
11
- super();
12
- }
13
-
14
- get data() {
15
- return Object.fromEntries(new FormData(this.node).entries());
16
- }
17
- }
18
-
19
- export class FormField extends $HTMLElement {
20
- constructor() {
21
- super('form-field');
22
- }
23
- }
24
-
25
- export class FormItem extends $HTMLElement {
26
- constructor(name?: string) {
27
- super('form-item');
28
- this.attr({ name });
29
- }
30
- }
31
-
32
- export class Label extends $Label {
33
- constructor() {
34
- super();
35
- }
36
-
37
- mounted($parent: $Node): void {
38
- if (_instanceof($parent, FormItem))
39
- this.htmlFor($parent.attr('name') ?? _undefined);
40
- }
41
- }
42
-
43
- export class Input extends $Input {
44
- constructor() {
45
- super();
46
- }
47
-
48
- mounted($parent: $Node): void {
49
- if (_instanceof($parent, FormItem)) {
50
- const name = $parent.attr('name') ?? _undefined;
51
- this.id(name).name(name);
52
- }
53
- }
54
- }
File without changes