@relax.js/core 1.0.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 (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -0
  3. package/dist/DataLoader.d.ts +51 -0
  4. package/dist/DependencyInjection.d.ts +271 -0
  5. package/dist/DependencyInjectionOld.d.ts +35 -0
  6. package/dist/Metadata.d.ts +8 -0
  7. package/dist/SequentialId.d.ts +47 -0
  8. package/dist/_alt/src/MustardEngine.d.ts +30 -0
  9. package/dist/_alt/src/MustardParser.d.ts +63 -0
  10. package/dist/_alt/src/MustardParser2.d.ts +35 -0
  11. package/dist/_alt/src/pipes.d.ts +93 -0
  12. package/dist/_alt/src/template.d.ts +166 -0
  13. package/dist/_alt/src/tools.d.ts +4 -0
  14. package/dist/_alt/tests/pipes.tests.d.ts +1 -0
  15. package/dist/_alt/tests/template.tests.d.ts +1 -0
  16. package/dist/_alt/vitest.config.d.ts +2 -0
  17. package/dist/collections/Index.d.ts +1 -0
  18. package/dist/collections/LinkedList.d.ts +75 -0
  19. package/dist/collections/Pager.d.ts +15 -0
  20. package/dist/collections/index.js +2 -0
  21. package/dist/collections/index.js.map +7 -0
  22. package/dist/collections/index.mjs +2 -0
  23. package/dist/collections/index.mjs.map +7 -0
  24. package/dist/components/Table.d.ts +13 -0
  25. package/dist/components/index.d.ts +4 -0
  26. package/dist/components/index.js +128 -0
  27. package/dist/components/index.js.map +7 -0
  28. package/dist/components/index.mjs +128 -0
  29. package/dist/components/index.mjs.map +7 -0
  30. package/dist/components/lists/Table.d.ts +59 -0
  31. package/dist/components/lists/TreeView.d.ts +67 -0
  32. package/dist/components/lists/index.d.ts +2 -0
  33. package/dist/components/loader.d.ts +60 -0
  34. package/dist/components/menus/MenuItem.d.ts +30 -0
  35. package/dist/components/menus/TopMenu.d.ts +16 -0
  36. package/dist/components/menus/index.d.ts +2 -0
  37. package/dist/components/panels/tabs.d.ts +15 -0
  38. package/dist/di/index.d.ts +1 -0
  39. package/dist/di/index.js +2 -0
  40. package/dist/di/index.js.map +7 -0
  41. package/dist/di/index.mjs +2 -0
  42. package/dist/di/index.mjs.map +7 -0
  43. package/dist/elements/CopyAttributes.d.ts +2 -0
  44. package/dist/elements/dom.d.ts +18 -0
  45. package/dist/elements/index.d.ts +2 -0
  46. package/dist/elements/index.js +2 -0
  47. package/dist/elements/index.js.map +7 -0
  48. package/dist/elements/index.mjs +2 -0
  49. package/dist/elements/index.mjs.map +7 -0
  50. package/dist/errors.d.ts +71 -0
  51. package/dist/forms/FormReader.d.ts +182 -0
  52. package/dist/forms/FormValidator.d.ts +114 -0
  53. package/dist/forms/ValidationRules.d.ts +103 -0
  54. package/dist/forms/index.d.ts +4 -0
  55. package/dist/forms/index.js +2 -0
  56. package/dist/forms/index.js.map +7 -0
  57. package/dist/forms/index.mjs +2 -0
  58. package/dist/forms/index.mjs.map +7 -0
  59. package/dist/forms/setFormData.d.ts +49 -0
  60. package/dist/getParentComponent.d.ts +43 -0
  61. package/dist/html/TableRenderer.d.ts +44 -0
  62. package/dist/html/TreeBinder.d.ts +9 -0
  63. package/dist/html/html.d.ts +55 -0
  64. package/dist/html/index.d.ts +5 -0
  65. package/dist/html/index.js +2 -0
  66. package/dist/html/index.js.map +7 -0
  67. package/dist/html/index.mjs +2 -0
  68. package/dist/html/index.mjs.map +7 -0
  69. package/dist/html/template.d.ts +167 -0
  70. package/dist/http/ServerSentEvents.d.ts +116 -0
  71. package/dist/http/SimpleWebSocket.d.ts +153 -0
  72. package/dist/http/http.d.ts +177 -0
  73. package/dist/http/index.d.ts +3 -0
  74. package/dist/http/index.js +2 -0
  75. package/dist/http/index.js.map +7 -0
  76. package/dist/http/index.mjs +2 -0
  77. package/dist/http/index.mjs.map +7 -0
  78. package/dist/i18n/i18n.d.ts +105 -0
  79. package/dist/i18n/icu.d.ts +64 -0
  80. package/dist/i18n/index.d.ts +2 -0
  81. package/dist/i18n/index.js +2 -0
  82. package/dist/i18n/index.js.map +7 -0
  83. package/dist/i18n/index.mjs +2 -0
  84. package/dist/i18n/index.mjs.map +7 -0
  85. package/dist/index.d.ts +16 -0
  86. package/dist/index.js +5 -0
  87. package/dist/index.js.map +7 -0
  88. package/dist/index.mjs +5 -0
  89. package/dist/index.mjs.map +7 -0
  90. package/dist/lib/DataLoader.d.ts +51 -0
  91. package/dist/lib/DependencyInjection.d.ts +271 -0
  92. package/dist/lib/InvokeParent.d.ts +10 -0
  93. package/dist/lib/Pipes.d.ts +236 -0
  94. package/dist/lib/SequentialId.d.ts +47 -0
  95. package/dist/lib/collections/Index.d.ts +1 -0
  96. package/dist/lib/collections/LinkedList.d.ts +75 -0
  97. package/dist/lib/collections/Pager.d.ts +15 -0
  98. package/dist/lib/collections/TableRenderer.d.ts +44 -0
  99. package/dist/lib/di/index.d.ts +1 -0
  100. package/dist/lib/elements/CopyAttributes.d.ts +2 -0
  101. package/dist/lib/elements/dom.d.ts +18 -0
  102. package/dist/lib/elements/index.d.ts +2 -0
  103. package/dist/lib/errors.d.ts +71 -0
  104. package/dist/lib/forms/FormReader.d.ts +182 -0
  105. package/dist/lib/forms/FormValidator.d.ts +114 -0
  106. package/dist/lib/forms/ValidationRules.d.ts +103 -0
  107. package/dist/lib/forms/index.d.ts +4 -0
  108. package/dist/lib/forms/setFormData.d.ts +49 -0
  109. package/dist/lib/getParentComponent.d.ts +43 -0
  110. package/dist/lib/html/TableRenderer.d.ts +44 -0
  111. package/dist/lib/html/TreeBinder.d.ts +9 -0
  112. package/dist/lib/html/html.d.ts +55 -0
  113. package/dist/lib/html/html2.d.ts +55 -0
  114. package/dist/lib/html/index.d.ts +5 -0
  115. package/dist/lib/html/m.d.ts +167 -0
  116. package/dist/lib/html/m2.d.ts +8 -0
  117. package/dist/lib/html/m3.d.ts +0 -0
  118. package/dist/lib/html/template.d.ts +167 -0
  119. package/dist/lib/http/HttpClient.d.ts +153 -0
  120. package/dist/lib/http/ServerSentEvents.d.ts +116 -0
  121. package/dist/lib/http/SimpleWebSocket.d.ts +153 -0
  122. package/dist/lib/http/http.d.ts +177 -0
  123. package/dist/lib/http/index.d.ts +3 -0
  124. package/dist/lib/i18n/i18n.d.ts +105 -0
  125. package/dist/lib/i18n/icu.d.ts +64 -0
  126. package/dist/lib/i18n/index.d.ts +2 -0
  127. package/dist/lib/index.d.ts +16 -0
  128. package/dist/lib/routing/NavigateRouteEvent.d.ts +52 -0
  129. package/dist/lib/routing/RouteLink.d.ts +7 -0
  130. package/dist/lib/routing/Routing.d.ts +270 -0
  131. package/dist/lib/routing/RoutingTarget.d.ts +22 -0
  132. package/dist/lib/routing/index.d.ts +7 -0
  133. package/dist/lib/routing/navigation.d.ts +70 -0
  134. package/dist/lib/routing/routeMatching.d.ts +21 -0
  135. package/dist/lib/routing/routeTargetRegistry.d.ts +23 -0
  136. package/dist/lib/routing/types.d.ts +130 -0
  137. package/dist/lib/templates/NodeTemplate.d.ts +38 -0
  138. package/dist/lib/templates/accessorParser.d.ts +87 -0
  139. package/dist/lib/templates/parseTemplate.d.ts +6 -0
  140. package/dist/lib/templates/tokenizer.d.ts +76 -0
  141. package/dist/lib/tools.d.ts +30 -0
  142. package/dist/lib/utils/index.d.ts +4 -0
  143. package/dist/pipes.d.ts +236 -0
  144. package/dist/routing/NavigateRouteEvent.d.ts +52 -0
  145. package/dist/routing/RouteLink.d.ts +7 -0
  146. package/dist/routing/RoutingTarget.d.ts +22 -0
  147. package/dist/routing/index.d.ts +7 -0
  148. package/dist/routing/index.js +5 -0
  149. package/dist/routing/index.js.map +7 -0
  150. package/dist/routing/index.mjs +5 -0
  151. package/dist/routing/index.mjs.map +7 -0
  152. package/dist/routing/navigation.d.ts +70 -0
  153. package/dist/routing/routeMatching.d.ts +21 -0
  154. package/dist/routing/routeTargetRegistry.d.ts +23 -0
  155. package/dist/routing/types.d.ts +130 -0
  156. package/dist/templates/NodeTemplate.d.ts +38 -0
  157. package/dist/templates/accessorParser.d.ts +87 -0
  158. package/dist/templates/parseTemplate.d.ts +6 -0
  159. package/dist/templates/tokenizer.d.ts +76 -0
  160. package/dist/tools.d.ts +30 -0
  161. package/dist/utils/index.d.ts +4 -0
  162. package/dist/utils/index.js +2 -0
  163. package/dist/utils/index.js.map +7 -0
  164. package/dist/utils/index.mjs +2 -0
  165. package/dist/utils/index.mjs.map +7 -0
  166. package/docs/Architecture.md +333 -0
  167. package/docs/DependencyInjection.md +237 -0
  168. package/docs/Errors.md +87 -0
  169. package/docs/GettingStarted.md +231 -0
  170. package/docs/Pipes.md +211 -0
  171. package/docs/Translations.md +312 -0
  172. package/docs/WhyRelaxjs.md +336 -0
  173. package/docs/elements/dom.md +102 -0
  174. package/docs/forms/creating-form-components.md +924 -0
  175. package/docs/forms/form-api.md +94 -0
  176. package/docs/forms/forms.md +99 -0
  177. package/docs/forms/patterns.md +311 -0
  178. package/docs/forms/reading-writing.md +365 -0
  179. package/docs/forms/validation.md +351 -0
  180. package/docs/html/TableRenderer.md +292 -0
  181. package/docs/html/html.md +175 -0
  182. package/docs/html/index.md +54 -0
  183. package/docs/html/template.md +422 -0
  184. package/docs/http/HttpClient.md +459 -0
  185. package/docs/http/ServerSentEvents.md +184 -0
  186. package/docs/http/index.md +109 -0
  187. package/docs/i18n/i18n.md +309 -0
  188. package/docs/i18n/intl-standard.md +178 -0
  189. package/docs/routing/RouteLink.md +98 -0
  190. package/docs/routing/Routing.md +332 -0
  191. package/docs/routing/RoutingTarget.md +136 -0
  192. package/docs/routing/layouts.md +207 -0
  193. package/docs/utilities.md +143 -0
  194. package/package.json +93 -0
@@ -0,0 +1,143 @@
1
+ # Utilities
2
+
3
+ Small helper functions and data structures exported from `relaxjs/utils`.
4
+
5
+ ## generateSequentialId
6
+
7
+ Generates compact, time-ordered unique identifiers. IDs sort lexicographically in creation order, making them useful for ordered collections and databases.
8
+
9
+ ```typescript
10
+ import { generateSequentialId } from 'relaxjs/utils';
11
+
12
+ const id = generateSequentialId(1);
13
+ // Returns a Base36 string like 'k2j8m3n5p'
14
+ ```
15
+
16
+ ### Parameters
17
+
18
+ | Parameter | Type | Description |
19
+ |-----------|------|-------------|
20
+ | `baseId` | `number` | Unique identifier for the client/process (0 to 1,048,575) |
21
+
22
+ Use different `baseId` values for different servers or processes to avoid collisions:
23
+
24
+ ```typescript
25
+ const SERVER_ID = parseInt(process.env.SERVER_ID || '0');
26
+ const orderId = generateSequentialId(SERVER_ID);
27
+ ```
28
+
29
+ ### Structure
30
+
31
+ Each ID encodes 58 bits of data in Base36:
32
+
33
+ | Bits | Field | Range |
34
+ |------|-------|-------|
35
+ | 30 | Timestamp (seconds since 2025-01-01) | Until ~2059 |
36
+ | 8 | Per-second counter | 256 IDs/second |
37
+ | 20 | Client identifier | ~1M unique sources |
38
+
39
+ ### Time-Sortable
40
+
41
+ IDs generated later sort after earlier IDs:
42
+
43
+ ```typescript
44
+ const id1 = generateSequentialId(0);
45
+ // ... wait ...
46
+ const id2 = generateSequentialId(0);
47
+ console.log(id1 < id2); // true
48
+ ```
49
+
50
+ ### Errors
51
+
52
+ - Throws if `baseId` is out of range (0 to 1,048,575)
53
+ - Throws if more than 256 IDs are generated in a single second
54
+ - Throws if timestamp exceeds range (after ~2059)
55
+
56
+ ## resolveValue
57
+
58
+ Safely navigates nested object properties using a path array. Returns `undefined` if any segment is null or missing (no exceptions thrown).
59
+
60
+ ```typescript
61
+ import { resolveValue } from 'relaxjs/utils';
62
+
63
+ const user = { address: { city: 'Stockholm' } };
64
+
65
+ resolveValue(['address', 'city'], user);
66
+ // Returns: 'Stockholm'
67
+
68
+ resolveValue(['address', 'zip'], user);
69
+ // Returns: undefined
70
+
71
+ // Safe with null values
72
+ const data = { user: null };
73
+ resolveValue(['user', 'name'], data);
74
+ // Returns: undefined (no error)
75
+ ```
76
+
77
+ ### Use with Dot-Notation Paths
78
+
79
+ ```typescript
80
+ const path = 'user.profile.avatar'.split('.');
81
+ const avatar = resolveValue(path, context);
82
+ ```
83
+
84
+ ## LinkedList
85
+
86
+ A doubly-linked list with O(1) insertion and removal at both ends.
87
+
88
+ ```typescript
89
+ import { LinkedList } from 'relaxjs/utils';
90
+
91
+ const list = new LinkedList<string>();
92
+
93
+ list.addFirst('A');
94
+ list.addLast('B');
95
+ list.addLast('C');
96
+
97
+ console.log(list.length); // 3
98
+ console.log(list.firstValue); // 'A'
99
+ console.log(list.lastValue); // 'C'
100
+
101
+ list.removeFirst(); // Returns 'A'
102
+ list.removeLast(); // Returns 'C'
103
+ console.log(list.length); // 1
104
+ ```
105
+
106
+ ### Node Access
107
+
108
+ Access the internal `Node` wrappers to traverse or remove specific nodes:
109
+
110
+ ```typescript
111
+ let node = list.first;
112
+ while (node) {
113
+ console.log(node.value);
114
+ node = node.next;
115
+ }
116
+
117
+ // Remove a specific node
118
+ const node = list.first;
119
+ node.remove(); // Removes from list and updates length
120
+ ```
121
+
122
+ ### API
123
+
124
+ | Method/Property | Description |
125
+ |-----------------|-------------|
126
+ | `addFirst(value)` | Insert at the beginning |
127
+ | `addLast(value)` | Insert at the end |
128
+ | `removeFirst()` | Remove and return the first value |
129
+ | `removeLast()` | Remove and return the last value |
130
+ | `length` | Number of nodes |
131
+ | `first` | First `Node` (or `undefined`) |
132
+ | `last` | Last `Node` (or `undefined`) |
133
+ | `firstValue` | Value of the first node |
134
+ | `lastValue` | Value of the last node |
135
+
136
+ ### Node Properties
137
+
138
+ | Property | Description |
139
+ |----------|-------------|
140
+ | `value` | The stored value |
141
+ | `next` | Next node (or `null`) |
142
+ | `prev` | Previous node (or `null`) |
143
+ | `remove()` | Remove this node from the list |
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@relax.js/core",
3
+ "version": "1.0.0",
4
+ "description": "Ship faster with less code. Web Component library with routing, forms, DI, templating, and i18n. No virtual DOM, no build magic, no surprise re-renders.",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "scripts": {
9
+ "watch": "tsc --watch",
10
+ "test": "vitest --config ./vitest.config.ts",
11
+ "test:coverage": "vitest run --coverage",
12
+ "test:ui": "vitest --ui",
13
+ "buildOld": "tsc",
14
+ "build": "tsc --emitDeclarationOnly && node build.js",
15
+ "yalc:publish": "yalc publish && yalc push",
16
+ "yalc:watch": "nodemon --ext ts,js,json --exec \"npm run yalc:publish\"",
17
+ "bp": "npm run build && npm run yalc:publish",
18
+ "publish:npm": "npm run build && npm publish --access public"
19
+ },
20
+ "keywords": [],
21
+ "author": "",
22
+ "license": "ISC",
23
+ "dependencies": {
24
+ "reflect-metadata": "^0.2.2"
25
+ },
26
+ "devDependencies": {
27
+ "@types/jsdom": "^21.1.7",
28
+ "@vitest/coverage-v8": "^3.0.5",
29
+ "esbuild": "^0.25.0",
30
+ "eslint": "^9.17.0",
31
+ "jsdom": "^26.1.0",
32
+ "typescript": "^5.7.3",
33
+ "vite": "^6.0.7",
34
+ "vite-plugin-ts": "^1.3.2-1",
35
+ "vitest": "^3.0.5"
36
+ },
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.mjs",
41
+ "require": "./dist/index.js"
42
+ },
43
+ "./html": {
44
+ "types": "./dist/html/index.d.ts",
45
+ "import": "./dist/html/index.mjs",
46
+ "require": "./dist/html/index.js"
47
+ },
48
+ "./http": {
49
+ "types": "./dist/http/index.d.ts",
50
+ "import": "./dist/http/index.mjs",
51
+ "require": "./dist/http/index.js"
52
+ },
53
+ "./forms": {
54
+ "types": "./dist/forms/index.d.ts",
55
+ "import": "./dist/forms/index.mjs",
56
+ "require": "./dist/forms/index.js"
57
+ },
58
+ "./routing": {
59
+ "types": "./dist/routing/index.d.ts",
60
+ "import": "./dist/routing/index.mjs",
61
+ "require": "./dist/routing/index.js"
62
+ },
63
+ "./i18n": {
64
+ "types": "./dist/i18n/index.d.ts",
65
+ "import": "./dist/i18n/index.mjs",
66
+ "require": "./dist/i18n/index.js"
67
+ },
68
+ "./elements": {
69
+ "types": "./dist/elements/index.d.ts",
70
+ "import": "./dist/elements/index.mjs",
71
+ "require": "./dist/elements/index.js"
72
+ },
73
+ "./utils": {
74
+ "types": "./dist/utils/index.d.ts",
75
+ "import": "./dist/utils/index.mjs",
76
+ "require": "./dist/utils/index.js"
77
+ },
78
+ "./di": {
79
+ "types": "./dist/di/index.d.ts",
80
+ "import": "./dist/di/index.mjs",
81
+ "require": "./dist/di/index.js"
82
+ },
83
+ "./collections": {
84
+ "types": "./dist/collections/Index.d.ts",
85
+ "import": "./dist/collections/index.mjs",
86
+ "require": "./dist/collections/index.js"
87
+ }
88
+ },
89
+ "files": [
90
+ "dist",
91
+ "docs"
92
+ ]
93
+ }