@lango-project/lango-client 0.2.0 → 0.4.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 (232) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +571 -855
  4. package/cli/.lango/localization.mjs +108 -0
  5. package/{dist/node → cli}/.lango/runtime.mjs +112 -19
  6. package/cli/.lango/vendor/i18next.LICENSE +21 -0
  7. package/cli/.lango/vendor/i18next.mjs +2434 -0
  8. package/cli/create.mjs +62 -0
  9. package/cli/create.mjs.map +1 -0
  10. package/dist/.lango/localization.mjs +108 -0
  11. package/dist/.lango/runtime.mjs +112 -19
  12. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  13. package/dist/.lango/vendor/i18next.mjs +2434 -0
  14. package/dist/accordion.mjs +277 -0
  15. package/dist/accordion.mjs.map +1 -0
  16. package/dist/activities.mjs +185 -0
  17. package/dist/activities.mjs.map +1 -0
  18. package/dist/app.mjs +636 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/boot.mjs +24 -0
  21. package/dist/boot.mjs.map +1 -0
  22. package/dist/bootstrap-LICENSE +21 -0
  23. package/dist/bootstrap.min.css +6 -0
  24. package/dist/bootstrap.min.css.map +1 -0
  25. package/dist/button.mjs +77 -0
  26. package/dist/button.mjs.map +1 -0
  27. package/dist/chip.mjs +134 -0
  28. package/dist/chip.mjs.map +1 -0
  29. package/dist/client.css +95 -0
  30. package/dist/collections.mjs +77 -0
  31. package/dist/collections.mjs.map +1 -0
  32. package/dist/combo_box.mjs +408 -0
  33. package/dist/combo_box.mjs.map +1 -0
  34. package/dist/content.mjs +123 -0
  35. package/dist/content.mjs.map +1 -0
  36. package/dist/control.mjs +139 -0
  37. package/dist/control.mjs.map +1 -0
  38. package/dist/date_input.mjs +242 -0
  39. package/dist/date_input.mjs.map +1 -0
  40. package/dist/error_reporter.mjs +136 -0
  41. package/dist/error_reporter.mjs.map +1 -0
  42. package/dist/fields.mjs +454 -0
  43. package/dist/fields.mjs.map +1 -0
  44. package/dist/file_input.mjs +227 -0
  45. package/dist/file_input.mjs.map +1 -0
  46. package/dist/form.mjs +272 -0
  47. package/dist/form.mjs.map +1 -0
  48. package/dist/heartbeat.mjs +167 -254
  49. package/dist/heartbeat.mjs.map +1 -1
  50. package/dist/index.html +18 -0
  51. package/dist/indicators.mjs +127 -0
  52. package/dist/indicators.mjs.map +1 -0
  53. package/dist/input_changes.mjs +58 -0
  54. package/dist/input_changes.mjs.map +1 -0
  55. package/dist/input_group.mjs +38 -0
  56. package/dist/input_group.mjs.map +1 -0
  57. package/dist/layouts.mjs +195 -0
  58. package/dist/layouts.mjs.map +1 -0
  59. package/dist/library.mjs +130 -775
  60. package/dist/library.mjs.map +1 -1
  61. package/dist/longpoll.mjs +254 -0
  62. package/dist/longpoll.mjs.map +1 -0
  63. package/dist/main.mjs +138 -0
  64. package/dist/main.mjs.map +1 -0
  65. package/dist/markdown.mjs +61 -0
  66. package/dist/markdown.mjs.map +1 -0
  67. package/dist/menus.mjs +468 -0
  68. package/dist/menus.mjs.map +1 -0
  69. package/dist/navigation.mjs +260 -410
  70. package/dist/navigation.mjs.map +1 -1
  71. package/dist/numeric_input.mjs +181 -0
  72. package/dist/numeric_input.mjs.map +1 -0
  73. package/dist/otp_input.mjs +113 -0
  74. package/dist/otp_input.mjs.map +1 -0
  75. package/dist/presentations.mjs +852 -0
  76. package/dist/presentations.mjs.map +1 -0
  77. package/dist/renderer.mjs +293 -0
  78. package/dist/renderer.mjs.map +1 -0
  79. package/dist/rich_content.mjs +99 -0
  80. package/dist/rich_content.mjs.map +1 -0
  81. package/dist/tables.mjs +369 -0
  82. package/dist/tables.mjs.map +1 -0
  83. package/dist/tabs.mjs +205 -0
  84. package/dist/tabs.mjs.map +1 -0
  85. package/dist/templates.mjs +46 -0
  86. package/dist/templates.mjs.map +1 -0
  87. package/dist/vendor/DOMPurify-LICENSE +202 -0
  88. package/dist/vendor/dompurify.mjs +2540 -0
  89. package/dist/vendor/flatpickr-LICENSE.md +21 -0
  90. package/dist/vendor/flatpickr.min.css +13 -0
  91. package/dist/vendor/flatpickr.mjs +2340 -0
  92. package/dist/vendor/flatpickr.mjs.map +7 -0
  93. package/dist/vendor/marked-LICENSE.md +44 -0
  94. package/dist/vendor/marked.esm.js.map +7 -0
  95. package/dist/vendor/marked.mjs +85 -0
  96. package/dist/vendor/purify.es.mjs.map +1 -0
  97. package/dist/widgets.mjs +197 -0
  98. package/dist/widgets.mjs.map +1 -0
  99. package/docs/implementation.md +42 -0
  100. package/package.json +26 -40
  101. package/src/accordion.lango +198 -0
  102. package/src/activities.lango +132 -0
  103. package/src/app.lango +508 -0
  104. package/src/boot.lango +12 -0
  105. package/src/button.lango +49 -0
  106. package/src/chip.lango +94 -0
  107. package/src/collections.lango +46 -0
  108. package/src/combo_box.lango +298 -0
  109. package/src/content.lango +75 -0
  110. package/src/control.lango +100 -0
  111. package/src/create.lango +42 -0
  112. package/src/date_input.lango +215 -0
  113. package/src/error_reporter.lango +95 -0
  114. package/src/fields.lango +327 -0
  115. package/src/file_input.lango +175 -0
  116. package/src/form.lango +195 -0
  117. package/src/heartbeat.lango +136 -199
  118. package/src/indicators.lango +94 -0
  119. package/src/input_changes.lango +33 -0
  120. package/src/input_group.lango +22 -0
  121. package/src/layouts.lango +137 -0
  122. package/src/library.lango +194 -571
  123. package/src/longpoll.lango +187 -0
  124. package/src/main.lango +109 -0
  125. package/src/markdown.lango +48 -0
  126. package/src/menus.lango +336 -0
  127. package/src/navigation.lango +209 -299
  128. package/src/numeric_input.lango +131 -0
  129. package/src/otp_input.lango +83 -0
  130. package/src/presentations.lango +617 -0
  131. package/src/renderer.lango +288 -0
  132. package/src/rich_content.lango +66 -0
  133. package/src/tables.lango +271 -0
  134. package/src/tabs.lango +144 -0
  135. package/src/templates.lango +29 -0
  136. package/src/widgets.lango +141 -0
  137. package/web/client.css +95 -0
  138. package/web/index.html +18 -0
  139. package/dist/application.mjs +0 -429
  140. package/dist/application.mjs.map +0 -1
  141. package/dist/coordinator.mjs +0 -91
  142. package/dist/coordinator.mjs.map +0 -1
  143. package/dist/demo.mjs +0 -110
  144. package/dist/demo.mjs.map +0 -1
  145. package/dist/demo_controls.mjs +0 -59
  146. package/dist/demo_controls.mjs.map +0 -1
  147. package/dist/errors.mjs +0 -201
  148. package/dist/errors.mjs.map +0 -1
  149. package/dist/form_state.mjs +0 -266
  150. package/dist/form_state.mjs.map +0 -1
  151. package/dist/inheritance.mjs +0 -240
  152. package/dist/inheritance.mjs.map +0 -1
  153. package/dist/input_values.mjs +0 -65
  154. package/dist/input_values.mjs.map +0 -1
  155. package/dist/node/.lango/xmldom/conventions.js +0 -429
  156. package/dist/node/.lango/xmldom/dom-parser.js +0 -591
  157. package/dist/node/.lango/xmldom/dom.js +0 -3759
  158. package/dist/node/.lango/xmldom/entities.js +0 -2171
  159. package/dist/node/.lango/xmldom/errors.js +0 -205
  160. package/dist/node/.lango/xmldom/grammar.js +0 -559
  161. package/dist/node/.lango/xmldom/index.js +0 -41
  162. package/dist/node/.lango/xmldom/package.json +0 -1
  163. package/dist/node/.lango/xmldom/sax.js +0 -983
  164. package/dist/node/.lango/xmldom.LICENSE.md +0 -8
  165. package/dist/node/browser_host.mjs +0 -351
  166. package/dist/node/browser_host.mjs.map +0 -1
  167. package/dist/node/create_app.mjs +0 -118
  168. package/dist/node/create_app.mjs.map +0 -1
  169. package/dist/presentation.mjs +0 -89
  170. package/dist/presentation.mjs.map +0 -1
  171. package/dist/protocol.mjs +0 -706
  172. package/dist/protocol.mjs.map +0 -1
  173. package/dist/session.mjs +0 -431
  174. package/dist/session.mjs.map +0 -1
  175. package/dist/tokens.mjs +0 -298
  176. package/dist/tokens.mjs.map +0 -1
  177. package/examples/contacts.lango +0 -302
  178. package/examples/contacts_flow.lango +0 -174
  179. package/examples/contacts_store.lango +0 -109
  180. package/examples/contacts_store_test.lango +0 -65
  181. package/examples/demo.css +0 -72
  182. package/examples/demo_test.lango +0 -356
  183. package/examples/index.html +0 -28
  184. package/examples/pages.lango +0 -180
  185. package/examples/server.lango +0 -189
  186. package/examples/worker.lango +0 -142
  187. package/src/application.lango +0 -327
  188. package/src/browser_host.lango +0 -276
  189. package/src/coordinator.lango +0 -57
  190. package/src/demo.lango +0 -110
  191. package/src/demo_controls.lango +0 -53
  192. package/src/errors.lango +0 -149
  193. package/src/errors_test.lango +0 -157
  194. package/src/form_state.lango +0 -168
  195. package/src/heartbeat_test.lango +0 -479
  196. package/src/inheritance.lango +0 -167
  197. package/src/input_values.lango +0 -37
  198. package/src/logout_test.lango +0 -564
  199. package/src/navigation_test.lango +0 -556
  200. package/src/presentation.lango +0 -55
  201. package/src/protocol.lango +0 -787
  202. package/src/renderer_test.lango +0 -1986
  203. package/src/session.lango +0 -313
  204. package/src/session_test.lango +0 -455
  205. package/src/tabs_test.lango +0 -216
  206. package/src/tokens.lango +0 -215
  207. package/template/.vscode/extensions.json +0 -3
  208. package/template/.vscode/settings.json +0 -9
  209. package/template/README.md +0 -40
  210. package/template/gitignore +0 -4
  211. package/template/package.json +0 -22
  212. package/template/public/app.css +0 -4
  213. package/template/public/index.html +0 -24
  214. package/template/src/client.lango +0 -78
  215. package/template/src/pages.lango +0 -55
  216. package/template/src/server.lango +0 -24
  217. package/template/src/worker.lango +0 -77
  218. package/template/test/app.lango +0 -9
  219. package/tools/create_app.lango +0 -88
  220. package/tools/create_app_test.lango +0 -43
  221. package/tools/starter_test.lango +0 -227
  222. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  223. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  224. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  225. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  226. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  227. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  228. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  229. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  230. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  231. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  232. /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
@@ -1,8 +0,0 @@
1
- Copyright 2019 - present Christopher J. Brody and other contributors, as listed in: https://github.com/xmldom/xmldom/graphs/contributors
2
- Copyright 2012 - 2017 @jindw <jindw@xidea.org> and other contributors, as listed in: https://github.com/jindw/xmldom/graphs/contributors
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,351 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import * as http from "node:http";
4
- import * as crypto from "node:crypto";
5
- import * as modules from "node:module";
6
- import * as api from "@lango-project/lango-api";
7
- import * as input from "@lango-project/lango-api/http-input";
8
- import * as rates from "@lango-project/lango-api/rate-limit";
9
- import {
10
- hostGlobal as __hostGlobal,
11
- hostGlobalCall as __hostGlobalCall,
12
- contextGet as __contextGet,
13
- contextSet as __contextSet,
14
- contextRestore as __contextRestore,
15
- fromJson as __fromJson,
16
- toJson as __toJson,
17
- isNumber as __isNumber,
18
- isString as __isString,
19
- isBool as __isBool,
20
- isObject as __isObject,
21
- isArray as __isArray,
22
- includes as __includes,
23
- entries as __entries,
24
- requireBoolean as __requireBoolean,
25
- normalize as __normalize,
26
- finite as __finite,
27
- call as __call,
28
- boundary as __boundary,
29
- requireArity as __requireArity,
30
- withArity as __withArity,
31
- } from "./.lango/runtime.mjs";
32
-
33
- export class BrowserHost {
34
- #options;
35
- #bodyOptions;
36
- #rateLimiter;
37
- #root;
38
- #pages;
39
- #port;
40
- #apiPort;
41
- #assets;
42
- #server;
43
- #api;
44
- #closing;
45
- #starting;
46
- #signal;
47
- #closed;
48
- #lango;
49
- #shell;
50
- constructor(options) {
51
- __requireArity(arguments.length, [0], "constructor");
52
- options = __boundary(options);
53
- this.#options = options;
54
- this.#bodyOptions = __normalize(input.requestBodyOptions(options));
55
- this.#rateLimiter = new rates.RateLimiter(options);
56
- this.#root = __normalize(path.resolve(__normalize(options.appRoot)));
57
- this.#pages = __normalize(options.pages);
58
- this.#port = __normalize(options.port);
59
- this.#apiPort = __normalize(options.apiPort);
60
- if (__requireBoolean(__normalize(this.#port) === null)) {
61
- this.#port = 8080;
62
- }
63
- if (__requireBoolean(__normalize(this.#apiPort) === null)) {
64
- this.#apiPort = 8081;
65
- }
66
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(__normalize(this.#port)))) || __requireBoolean(!__requireBoolean(__isNumber(__normalize(this.#apiPort))))) || __requireBoolean(__normalize(this.#port) < 1)) || __requireBoolean(__normalize(this.#port) > 65535)) || __requireBoolean(__normalize(this.#apiPort) < 1)) || __requireBoolean(__normalize(this.#apiPort) > 65535)) || __requireBoolean(__finite(__normalize(this.#port) % 1) !== 0)) || __requireBoolean(__finite(__normalize(this.#apiPort) % 1) !== 0)) || __requireBoolean(__normalize(this.#port) === __normalize(this.#apiPort)))) {
67
- throw "UiHostRequiresDistinctPorts";
68
- }
69
- this.#assets = { };
70
- this.#server = null;
71
- this.#api = null;
72
- this.#closing = null;
73
- this.#starting = null;
74
- this.#signal = null;
75
- this.#closed = false;
76
- }
77
- start() {
78
- if (__requireBoolean(__normalize(this.#closed))) {
79
- throw "UiHostClosed";
80
- }
81
- if (__requireBoolean(__normalize(this.#starting) !== null)) {
82
- return __normalize(this.#starting);
83
- }
84
- this.#starting = this.#launch();
85
- return __normalize(this.#starting);
86
- return null;
87
- }
88
- #launch() {
89
- let options = __normalize(this.#options);
90
- let resolve = __normalize(modules.createRequire(__normalize(path.join(__normalize(this.#root), "package.json"))));
91
- let sdk = __normalize(path.dirname(__normalize(resolve.resolve("@lango-project/lango-client"))));
92
- let files = ["library.mjs", "application.mjs", "session.mjs", "tokens.mjs", "heartbeat.mjs", "protocol.mjs", "inheritance.mjs", "coordinator.mjs", "navigation.mjs", "presentation.mjs", "input_values.mjs", "form_state.mjs", "errors.mjs", ".lango/runtime.mjs", ".lango/bignumber.mjs"];
93
- for (const file of files) {
94
- this.#addAsset(`/vendor/lango-client/${file}`, __normalize(path.join(sdk, file)));
95
- }
96
- if (__requireBoolean(__normalize(options.assets) !== null)) {
97
- for (const [url, file] of __entries(__normalize(options.assets))) {
98
- if (__requireBoolean(__normalize(url.startsWith("/vendor/")))) {
99
- throw "UiHostReservedAssetPath";
100
- }
101
- this.#addAsset(url, __normalize(path.resolve(__normalize(this.#root), file)));
102
- }
103
- }
104
- this.#shell = __normalize(fs.readFileSync(__normalize(path.resolve(__normalize(this.#root), __normalize(options.shell)))));
105
- let state = __normalize(path.join(__normalize(this.#root), ".lango", "state"));
106
- __normalize(fs.mkdirSync(state, { recursive: true }));
107
- let keyFile = __normalize(path.join(state, "jwt.key"));
108
- if (__requireBoolean(!__requireBoolean(__normalize(fs.existsSync(keyFile))))) {
109
- __normalize(fs.writeFileSync(keyFile, __normalize(crypto.randomBytes(32)), { mode: 384, flag: "wx" }));
110
- }
111
- let keys = __normalize(path.join(state, "keys.json"));
112
- let key = __normalize(fs.readFileSync(keyFile));
113
- __normalize(fs.writeFileSync(keys, __toJson({ app: __normalize(key.toString("base64")) }), { mode: 384 }));
114
- this.#api = new api.Host({ applicationName: "lango-application", appRoot: __normalize(this.#root), stateDir: state, mode: "server", host: "127.0.0.1", port: __normalize(this.#apiPort), workers: { bodyLimit: __normalize(this.#bodyOptions.bodyLimit), bodyTimeoutMs: __normalize(this.#bodyOptions.bodyTimeoutMs), application: __normalize(path.resolve(__normalize(this.#root), __normalize(options.worker))), workerFile: __normalize(resolve.resolve("@lango-project/lango-api/worker-entry")) }, jwt: { issuer: "lango-application", audience: "lango-browser", activeKeyId: "app", keysFile: keys } });
115
- return __normalize(this.#api.start()).then(() => {
116
- if (__requireBoolean(__normalize(this.#closed))) {
117
- throw "UiHostClosed";
118
- }
119
- return this.#listen();
120
- return null;
121
- }).catch(__withArity((error) => {
122
- error = __boundary(error);
123
- return this.close().then(() => {
124
- throw error;
125
- return null;
126
- });
127
- return null;
128
- }, [0], "closure"));
129
- return null;
130
- }
131
- #addAsset(url, file) {
132
- __requireArity(arguments.length, [0, 1], "addAsset");
133
- url = __boundary(url);
134
- file = __boundary(file);
135
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(!__requireBoolean(__normalize(url.startsWith("/"))))) || __requireBoolean(__normalize(url.includes("?")))) || __requireBoolean(__normalize(url.includes("#")))) || __requireBoolean(__normalize(url.includes("\\"))))) {
136
- throw "UiHostInvalidAssetPath";
137
- }
138
- if (__requireBoolean(__includes(url, __normalize(this.#assets)))) {
139
- throw "UiHostDuplicateAsset";
140
- }
141
- let type = "text/javascript; charset=utf-8";
142
- if (__requireBoolean(__normalize(file.endsWith(".css")))) {
143
- type = "text/css; charset=utf-8";
144
- }
145
- let content = __normalize(fs.readFileSync(file));
146
- let hash = __normalize(crypto.createHash("sha256"));
147
- __normalize(hash.update(content));
148
- this.#assets[url] = { content: content, type: type, etag: `\"${__normalize(hash.digest("hex"))}\"` };
149
- return null;
150
- }
151
- #listen() {
152
- let server = new http.Server(__withArity((req, res) => {
153
- req = __boundary(req);
154
- res = __boundary(res);
155
- this.#serve(req, res);
156
- return null;
157
- }, [0, 1], "closure"));
158
- this.#server = server;
159
- let pending = new (__hostGlobal(["Promise"]))(__withArity((resolve, reject) => {
160
- resolve = __boundary(resolve);
161
- reject = __boundary(reject);
162
- let server = __normalize(this.#server);
163
- __normalize(server.once("error", reject));
164
- __normalize(server.listen(__normalize(this.#port), "127.0.0.1", () => {
165
- const __contextScope = [];
166
- try {
167
- let signal = () => {
168
- this.#signalClose();
169
- return null;
170
- };
171
- this.#signal = signal;
172
- __normalize(__hostGlobal(["process"]).once("SIGINT", __normalize(this.#signal)));
173
- __normalize(__hostGlobal(["process"]).once("SIGTERM", __normalize(this.#signal)));
174
- __normalize(__contextGet("log").info(`Open http://localhost:${__normalize(this.#port)}/`));
175
- __call(resolve, null);
176
- return null;
177
- } finally {
178
- __contextRestore(__contextScope);
179
- }
180
- }));
181
- return null;
182
- }, [0, 1], "closure"));
183
- return pending;
184
- return null;
185
- }
186
- #serve(req, res) {
187
- __requireArity(arguments.length, [0, 1], "serve");
188
- req = __boundary(req);
189
- res = __boundary(res);
190
- try {
191
- let url = new (__hostGlobal(["URL"]))(__normalize(req.url), "http://localhost");
192
- let pathname = __normalize(url.pathname);
193
- if (__requireBoolean(__requireBoolean(__normalize(req.method) === "POST") && __requireBoolean(__requireBoolean(__normalize(pathname.startsWith("/app/"))) || __requireBoolean(__normalize(pathname.startsWith("/_lango/")))))) {
194
- return this.#receive(req, res);
195
- }
196
- if (__requireBoolean(__normalize(req.method) !== "GET")) {
197
- __normalize(res.writeHead(404));
198
- __normalize(res.end("Not found"));
199
- return null;
200
- }
201
- if (__requireBoolean(__includes(pathname, __normalize(this.#assets)))) {
202
- let asset = __normalize(this.#assets[pathname]);
203
- __normalize(res.setHeader("Content-Type", __normalize(asset.type)));
204
- __normalize(res.setHeader("Cache-Control", "public, max-age=0, must-revalidate"));
205
- __normalize(res.setHeader("ETag", __normalize(asset.etag)));
206
- if (__requireBoolean(req.headers["if-none-match"] === __normalize(asset.etag))) {
207
- __normalize(res.writeHead(304));
208
- __normalize(res.end());
209
- } else {
210
- __normalize(res.writeHead(200));
211
- __normalize(res.end(__normalize(asset.content)));
212
- }
213
- return null;
214
- }
215
- if (__requireBoolean(__requireBoolean(pathname === "/") || __requireBoolean(__normalize(this.#pages.match(pathname)) !== null))) {
216
- __normalize(res.writeHead(200, { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" }));
217
- __normalize(res.end(__normalize(this.#shell)));
218
- return null;
219
- }
220
- __normalize(res.writeHead(404));
221
- __normalize(res.end("Not found"));
222
- } catch (error) {
223
- __normalize(res.writeHead(400));
224
- __normalize(res.end("Invalid request"));
225
- }
226
- return null;
227
- return null;
228
- }
229
- #receive(req, res) {
230
- __requireArity(arguments.length, [0, 1], "receive");
231
- req = __boundary(req);
232
- res = __boundary(res);
233
- let retry = __normalize(this.#rateLimiter.admit(req.socket.remoteAddress));
234
- if (__requireBoolean(retry > 0)) {
235
- return __normalize(input.rejectHttpRequest(req, res, 429, "TooManyRequests", retry, null));
236
- }
237
- let completed = __withArity((body) => {
238
- body = __boundary(body);
239
- this.#forward(req, res, body);
240
- return null;
241
- }, [0], "closure");
242
- let rejected = __withArity((status, error) => {
243
- status = __boundary(status);
244
- error = __boundary(error);
245
- __normalize(res.writeHead(status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" }));
246
- __normalize(res.end(__toJson({ error: error })));
247
- return null;
248
- }, [0, 1], "closure");
249
- __normalize(input.readRequestBody(req, res, __normalize(this.#bodyOptions), completed, rejected));
250
- return null;
251
- return null;
252
- }
253
- #forward(req, res, body) {
254
- __requireArity(arguments.length, [0, 1, 2], "forward");
255
- req = __boundary(req);
256
- res = __boundary(res);
257
- body = __boundary(body);
258
- let headers = { "Content-Type": "application/json" };
259
- if (__requireBoolean(__isString(req.headers.authorization))) {
260
- headers.Authorization = req.headers.authorization;
261
- }
262
- return __hostGlobalCall(["fetch"], `http://127.0.0.1:${__normalize(this.#apiPort)}${__normalize(req.url)}`, { method: "POST", headers: headers, body: body }).then(__withArity((upstream) => {
263
- upstream = __boundary(upstream);
264
- return this.#readUpstream(upstream, res);
265
- return null;
266
- }, [0], "closure")).catch(__withArity((error) => {
267
- error = __boundary(error);
268
- __normalize(res.writeHead(502, { "Content-Type": "application/json" }));
269
- __normalize(res.end(__toJson({ error: "UpstreamUnavailable" })));
270
- return null;
271
- }, [0], "closure"));
272
- return null;
273
- }
274
- #readUpstream(upstream, res) {
275
- __requireArity(arguments.length, [0, 1], "readUpstream");
276
- upstream = __boundary(upstream);
277
- res = __boundary(res);
278
- return __normalize(upstream.text()).then(__withArity((text) => {
279
- text = __boundary(text);
280
- this.#relay(res, upstream, text);
281
- return null;
282
- }, [0], "closure"));
283
- return null;
284
- }
285
- #relay(res, upstream, text) {
286
- __requireArity(arguments.length, [0, 1, 2], "relay");
287
- res = __boundary(res);
288
- upstream = __boundary(upstream);
289
- text = __boundary(text);
290
- for (const name of ["Content-Type", "Cache-Control", "X-Lango-Token", "WWW-Authenticate", "Retry-After"]) {
291
- let value = __normalize(upstream.headers.get(name));
292
- if (__requireBoolean(value !== null)) {
293
- __normalize(res.setHeader(name, value));
294
- }
295
- }
296
- __normalize(res.writeHead(__normalize(upstream.status)));
297
- __normalize(res.end(text));
298
- return null;
299
- return null;
300
- }
301
- close() {
302
- if (__requireBoolean(__normalize(this.#closing) !== null)) {
303
- return __normalize(this.#closing);
304
- }
305
- this.#closed = true;
306
- if (__requireBoolean(__normalize(this.#signal) !== null)) {
307
- __normalize(__hostGlobal(["process"]).removeListener("SIGINT", __normalize(this.#signal)));
308
- __normalize(__hostGlobal(["process"]).removeListener("SIGTERM", __normalize(this.#signal)));
309
- }
310
- this.#closing = this.#stop();
311
- return __normalize(this.#closing);
312
- return null;
313
- }
314
- #signalClose() {
315
- return this.close().catch(__withArity((error) => {
316
- const __contextScope = [];
317
- try {
318
- error = __boundary(error);
319
- __normalize(__contextGet("log").err(`Browser host shutdown failed: ${error}`));
320
- __hostGlobal(["process"]).exitCode = 1;
321
- return null;
322
- } finally {
323
- __contextRestore(__contextScope);
324
- }
325
- }, [0], "closure"));
326
- return null;
327
- }
328
- #stop() {
329
- let pending = new (__hostGlobal(["Promise"]))(__withArity((resolve) => {
330
- resolve = __boundary(resolve);
331
- let server = __normalize(this.#server);
332
- if (__requireBoolean(__requireBoolean(server === null) || __requireBoolean(!__requireBoolean(__normalize(server.listening))))) {
333
- __call(resolve, null);
334
- } else {
335
- server.close(() => {
336
- __call(resolve, null);
337
- return null;
338
- });
339
- }
340
- return null;
341
- }, [0], "closure"));
342
- return pending.finally(() => {
343
- if (__requireBoolean(__normalize(this.#api) !== null)) {
344
- return __normalize(this.#api.close());
345
- }
346
- return null;
347
- });
348
- return null;
349
- }
350
- }
351
- //# sourceMappingURL=browser_host.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser_host.mjs","sources":["browser_host.lango"],"sourcesContent":["import js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js \"node:http\" as http\nimport js \"node:crypto\" as crypto\nimport js \"node:module\" as modules\nimport js global fetch\nimport js global process\nimport js global Promise\nimport js global URL\nimport js \"@lango-project/lango-api\" as api\nimport js \"@lango-project/lango-api/http-input\" as input\nimport js \"@lango-project/lango-api/rate-limit\" as rates\n\nexport class BrowserHost\n methods\n start()\n close()\n\nBrowserHost(options)\n @options = options\n @bodyOptions = input/requestBodyOptions(options)\n @rateLimiter = new rates/RateLimiter(options)\n @root = path.resolve(options.appRoot)\n @pages = options.pages\n @port = options.port\n @apiPort = options.apiPort\n if @port == null\n @port = 8080\n if @apiPort == null\n @apiPort = 8081\n if !is_number(@port) or !is_number(@apiPort) or @port < 1 or @port > 65535 or @apiPort < 1 or @apiPort > 65535 or @port % 1 != 0 or @apiPort % 1 != 0 or @port == @apiPort\n throw \"UiHostRequiresDistinctPorts\"\n @assets = {\n }\n @server = null\n @api = null\n @closing = null\n @starting = null\n @signal = null\n @closed = false\n\nBrowserHost:start()\n if @closed\n throw \"UiHostClosed\"\n if @starting != null\n return @starting\n @starting = launch()\n return @starting\n\nBrowserHost:launch()\n options = @options\n resolve = modules/createRequire(path.join(@root, \"package.json\"))\n sdk = path.dirname(resolve.resolve(\"@lango-project/lango-client\"))\n files = [\"library.mjs\", \"application.mjs\", \"session.mjs\", \"tokens.mjs\", \"heartbeat.mjs\", \"protocol.mjs\", \"inheritance.mjs\", \"coordinator.mjs\", \"navigation.mjs\", \"presentation.mjs\", \"input_values.mjs\", \"form_state.mjs\", \"errors.mjs\", \".lango/runtime.mjs\", \".lango/bignumber.mjs\"]\n for files as file\n addAsset(\"/vendor/lango-client/${file}\", path.join(sdk, file))\n if options.assets != null\n for options.assets as url: file\n if url.startsWith(\"/vendor/\")\n throw \"UiHostReservedAssetPath\"\n addAsset(url, path.resolve(@root, file))\n @shell = fs.readFileSync(path.resolve(@root, options.shell))\n state = path.join(@root, \".lango\", \"state\")\n fs.mkdirSync(state, {\n recursive: true\n })\n keyFile = path.join(state, \"jwt.key\")\n if !fs.existsSync(keyFile)\n fs.writeFileSync(keyFile, crypto/randomBytes(32), {\n mode: 384\n flag: \"wx\"\n })\n keys = path.join(state, \"keys.json\")\n key = fs.readFileSync(keyFile)\n fs.writeFileSync(keys, to_json({\n app: key.toString(\"base64\")\n }), {\n mode: 384\n })\n @api = new api/Host({\n applicationName: \"lango-application\"\n appRoot: @root\n stateDir: state\n mode: \"server\"\n host: \"127.0.0.1\"\n port: @apiPort\n workers: {\n bodyLimit: @bodyOptions.bodyLimit\n bodyTimeoutMs: @bodyOptions.bodyTimeoutMs\n application: path.resolve(@root, options.worker)\n workerFile: resolve.resolve(\"@lango-project/lango-api/worker-entry\")\n }\n jwt: {\n issuer: \"lango-application\"\n audience: \"lango-browser\"\n activeKeyId: \"app\"\n keysFile: keys\n }\n })\n return @api.start().then(()\n if @closed\n throw \"UiHostClosed\"\n return listen()\n ).catch((error)\n return close().then(()\n capture error\n throw error\n )\n )\n\nBrowserHost:addAsset(url, file)\n if !is_string(url) or !url.startsWith(\"/\") or url.includes(\"?\") or url.includes(\"#\") or url.includes(\"\\\\\")\n throw \"UiHostInvalidAssetPath\"\n if url in @assets\n throw \"UiHostDuplicateAsset\"\n type = \"text/javascript; charset=utf-8\"\n if file.endsWith(\".css\")\n type = \"text/css; charset=utf-8\"\n content = fs.readFileSync(file)\n hash = crypto/createHash(\"sha256\")\n hash.update(content)\n @assets[url] = {\n content: content\n type: type\n etag: \"\\\"${hash.digest('hex')}\\\"\"\n }\n\nBrowserHost:listen()\n server = new http/Server((req, res)\n serve(req, res)\n )\n @server = server\n pending = new Promise((resolve, reject)\n server = @server\n server.once(\"error\", reject)\n server.listen(@port, \"127.0.0.1\", ()\n capture resolve\n signal = ()\n signalClose()\n @signal = signal\n process.once(\"SIGINT\", @signal)\n process.once(\"SIGTERM\", @signal)\n context log\n log.info(\"Open http://localhost:${@port}/\")\n resolve(null)\n )\n )\n return pending\n\nBrowserHost:serve(req, res)\n try\n url = new URL(req.url, \"http://localhost\")\n pathname = url.pathname\n if req.method == \"POST\" and (pathname.startsWith(\"/app/\") or pathname.startsWith(\"/_lango/\"))\n return receive(req, res)\n if req.method != \"GET\"\n res.writeHead(404)\n res.end(\"Not found\")\n return null\n if pathname in @assets\n asset = @assets[pathname]\n res.setHeader(\"Content-Type\", asset.type)\n res.setHeader(\"Cache-Control\", \"public, max-age=0, must-revalidate\")\n res.setHeader(\"ETag\", asset.etag)\n if req.headers[\"if-none-match\"] == asset.etag\n res.writeHead(304)\n res.end()\n else\n res.writeHead(200)\n res.end(asset.content)\n return null\n if pathname == \"/\" or @pages.match(pathname) != null\n res.writeHead(200, {\n \"Content-Type\": \"text/html; charset=utf-8\"\n \"Cache-Control\": \"no-store\"\n })\n res.end(@shell)\n return null\n res.writeHead(404)\n res.end(\"Not found\")\n catch error\n res.writeHead(400)\n res.end(\"Invalid request\")\n return null\n\nBrowserHost:receive(req, res)\n retry = @rateLimiter.admit(req.socket.remoteAddress)\n if retry > 0\n return input/rejectHttpRequest(req, res, 429, \"TooManyRequests\", retry, null)\n completed = (body)\n capture req\n capture res\n forward(req, res, body)\n rejected = (status, error)\n capture res\n res.writeHead(status, {\n \"Content-Type\": \"application/json; charset=utf-8\"\n \"Cache-Control\": \"no-store\"\n })\n res.end(to_json({\n error: error\n }))\n input/readRequestBody(req, res, @bodyOptions, completed, rejected)\n return null\n\nBrowserHost:forward(req, res, body)\n headers = {\n \"Content-Type\": \"application/json\"\n }\n if is_string(req.headers.authorization)\n headers.Authorization = req.headers.authorization\n return fetch(\"http://127.0.0.1:${@apiPort}${req.url}\", {\n method: \"POST\"\n headers: headers\n body: body\n }).then((upstream)\n capture res\n return readUpstream(upstream, res)\n ).catch((error)\n capture res\n res.writeHead(502, {\n \"Content-Type\": \"application/json\"\n })\n res.end(to_json({\n error: \"UpstreamUnavailable\"\n }))\n )\n\nBrowserHost:readUpstream(upstream, res)\n return upstream.text().then((text)\n capture upstream\n capture res\n relay(res, upstream, text)\n )\n\nBrowserHost:relay(res, upstream, text)\n for [\"Content-Type\", \"Cache-Control\", \"X-Lango-Token\", \"WWW-Authenticate\", \"Retry-After\"] as name\n value = upstream.headers.get(name)\n if value != null\n res.setHeader(name, value)\n res.writeHead(upstream.status)\n res.end(text)\n return null\n\nBrowserHost:close()\n if @closing != null\n return @closing\n @closed = true\n if @signal != null\n process.removeListener(\"SIGINT\", @signal)\n process.removeListener(\"SIGTERM\", @signal)\n @closing = stop()\n return @closing\n\nBrowserHost:signalClose()\n return close().catch((error)\n context log\n log.err(\"Browser host shutdown failed: ${error}\")\n process.exitCode = 1\n )\n\nBrowserHost:stop()\n pending = new Promise((resolve)\n server = @server\n if server == null or !server.listening\n resolve(null)\n else\n server.close(()\n capture resolve\n resolve(null)\n )\n )\n return pending.finally(()\n if @api != null\n return @api.close()\n )\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env node
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import {
5
- hostGlobal as __hostGlobal,
6
- println as __println,
7
- fromJson as __fromJson,
8
- toJson as __toJson,
9
- entries as __entries,
10
- add as __add,
11
- requireBoolean as __requireBoolean,
12
- normalize as __normalize,
13
- boundary as __boundary,
14
- requireArity as __requireArity,
15
- } from "./.lango/runtime.mjs";
16
-
17
- export function main(args) {
18
- __requireArity(arguments.length, [0], "main");
19
- args = __boundary(args);
20
- try {
21
- return createProject(args);
22
- } catch (error) {
23
- __normalize(__hostGlobal(["process"]).stderr.write(`${error}\n`));
24
- __hostGlobal(["process"]).exitCode = 2;
25
- return null;
26
- }
27
- return null;
28
- }
29
-
30
- function createProject(args) {
31
- __requireArity(arguments.length, [0], "createProject");
32
- args = __boundary(args);
33
- if (__requireBoolean(__requireBoolean(__normalize(args.length) !== 1) || __requireBoolean(__normalize(args[0]) === "--help"))) {
34
- __println("Usage: lango-create-app <directory>");
35
- if (__requireBoolean(__normalize(args.length) !== 1)) {
36
- __hostGlobal(["process"]).exitCode = 2;
37
- }
38
- return null;
39
- }
40
- let target = __normalize(path.resolve(__normalize(args[0])));
41
- let name = __normalize(path.basename(target));
42
- let pattern = new (__hostGlobal(["RegExp"]))("^[a-z][a-z0-9-]*$");
43
- if (__requireBoolean(!__requireBoolean(__normalize(pattern.test(name))))) {
44
- throw "StarterDirectoryNameMustBeLowercaseKebabCase";
45
- }
46
- if (__requireBoolean(__normalize(fs.existsSync(target)))) {
47
- for (const entry of __normalize(fs.readdirSync(target))) {
48
- if (__requireBoolean(entry !== ".git")) {
49
- throw "StarterRequiresEmptyDirectory";
50
- }
51
- }
52
- }
53
- let root = packageRoot();
54
- let manifest = __fromJson(__normalize(fs.readFileSync(__normalize(path.join(root, "package.json")), "utf8")));
55
- let release = __normalize(manifest.langoStarter);
56
- let replacements = { APP_NAME: name, JS_VERSION: __normalize(release.compiler), API_VERSION: __normalize(release.api), UI_VERSION: __normalize(release.ui), CLIENT_VERSION: __normalize(manifest.version) };
57
- let files = [];
58
- readTemplate(__normalize(path.join(root, "template")), "", files, replacements);
59
- __normalize(fs.mkdirSync(target, { recursive: true }));
60
- for (const file of files) {
61
- let output = __normalize(path.join(target, __normalize(file.name)));
62
- __normalize(fs.mkdirSync(__normalize(path.dirname(output)), { recursive: true }));
63
- __normalize(fs.writeFileSync(output, __normalize(file.content), { flag: "wx" }));
64
- }
65
- __println(`Created ${name}. Run npm install, npm run build, then npm start in ${target}.`);
66
- return null;
67
- }
68
-
69
- function packageRoot() {
70
- let current = __normalize(path.dirname(__normalize(fs.realpathSync(__normalize(__hostGlobal(["process"]).argv[1])))));
71
- __loop1: while (true) {
72
- let file = __normalize(path.join(current, "package.json"));
73
- if (__requireBoolean(__normalize(fs.existsSync(file)))) {
74
- let metadata = __fromJson(__normalize(fs.readFileSync(file, "utf8")));
75
- if (__requireBoolean(__normalize(metadata.name) === "@lango-project/lango-client")) {
76
- return current;
77
- }
78
- }
79
- let parent = __normalize(path.dirname(current));
80
- if (__requireBoolean(parent === current)) {
81
- throw "StarterPackageNotFound";
82
- }
83
- current = parent;
84
- }
85
- return null;
86
- }
87
-
88
- function readTemplate(directory, prefix, files, replacements) {
89
- __requireArity(arguments.length, [0, 1, 2, 3], "readTemplate");
90
- directory = __boundary(directory);
91
- prefix = __boundary(prefix);
92
- files = __boundary(files);
93
- replacements = __boundary(replacements);
94
- let entries = __normalize(fs.readdirSync(directory, { withFileTypes: true }));
95
- for (const entry of entries) {
96
- let source = __normalize(path.join(directory, __normalize(entry.name)));
97
- let name = __normalize(path.join(prefix, __normalize(entry.name)));
98
- if (__requireBoolean(__normalize(entry.isDirectory()))) {
99
- readTemplate(source, name, files, replacements);
100
- } else {
101
- if (__requireBoolean(__normalize(entry.isFile()))) {
102
- if (__requireBoolean(__normalize(entry.name) === "gitignore")) {
103
- name = ".gitignore";
104
- }
105
- let content = __normalize(fs.readFileSync(source, "utf8"));
106
- for (const [key, value] of __entries(replacements)) {
107
- content = __normalize(content.replaceAll(`{{${key}}}`, value));
108
- }
109
- __add(files, { name: name, content: content });
110
- }
111
- }
112
- }
113
- return null;
114
- }
115
- const { configure } = await import("./.lango/runtime.mjs");
116
- configure({ output: (value) => console.log(value) });
117
- await main(process.argv.slice(2));
118
- //# sourceMappingURL=create_app.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create_app.mjs","sources":["create_app.lango"],"sourcesContent":["import js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js global process\nimport js global RegExp\n\nexport main(args)\n\nmain(args)\n try\n return createProject(args)\n catch error\n process.stderr.write(\"${error}\\n\")\n process.exitCode = 2\n return null\n\ncreateProject(args)\n if args.length != 1 or args[0] == \"--help\"\n println(\"Usage: lango-create-app <directory>\")\n if args.length != 1\n process.exitCode = 2\n return null\n target = path.resolve(args[0])\n name = path.basename(target)\n pattern = new RegExp(\"^[a-z][a-z0-9-]*$\")\n if !pattern.test(name)\n throw \"StarterDirectoryNameMustBeLowercaseKebabCase\"\n if fs.existsSync(target)\n for fs.readdirSync(target) as entry\n if entry != \".git\"\n throw \"StarterRequiresEmptyDirectory\"\n root = packageRoot()\n manifest = from_json(fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"))\n release = manifest.langoStarter\n replacements = {\n APP_NAME: name\n JS_VERSION: release.compiler\n API_VERSION: release.api\n UI_VERSION: release.ui\n CLIENT_VERSION: manifest.version\n }\n files = []\n readTemplate(path.join(root, \"template\"), \"\", files, replacements)\n fs.mkdirSync(target, {\n recursive: true\n })\n for files as file\n output = path.join(target, file.name)\n fs.mkdirSync(path.dirname(output), {\n recursive: true\n })\n fs.writeFileSync(output, file.content, {\n flag: \"wx\"\n })\n println(\"Created ${name}. Run npm install, npm run build, then npm start in ${target}.\")\n\npackageRoot()\n current = path.dirname(fs.realpathSync(process.argv[1]))\n loop\n file = path.join(current, \"package.json\")\n if fs.existsSync(file)\n metadata = from_json(fs.readFileSync(file, \"utf8\"))\n if metadata.name == \"@lango-project/lango-client\"\n return current\n parent = path.dirname(current)\n if parent == current\n throw \"StarterPackageNotFound\"\n current = parent\n\nreadTemplate(directory, prefix, files, replacements)\n entries = fs.readdirSync(directory, {\n withFileTypes: true\n })\n for entries as entry\n source = path.join(directory, entry.name)\n name = path.join(prefix, entry.name)\n if entry.isDirectory()\n readTemplate(source, name, files, replacements)\n else\n if entry.isFile()\n if entry.name == \"gitignore\"\n name = \".gitignore\"\n content = fs.readFileSync(source, \"utf8\")\n for replacements as key: value\n content = content.replaceAll(\"{{${key}}}\", value)\n files.add({\n name: name\n content: content\n })\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA;;;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,89 +0,0 @@
1
- import {
2
- hostGlobal as __hostGlobal,
3
- fromJson as __fromJson,
4
- toJson as __toJson,
5
- isNumber as __isNumber,
6
- isString as __isString,
7
- isBool as __isBool,
8
- isObject as __isObject,
9
- isArray as __isArray,
10
- entries as __entries,
11
- requireBoolean as __requireBoolean,
12
- normalize as __normalize,
13
- boundary as __boundary,
14
- requireArity as __requireArity,
15
- } from "./.lango/runtime.mjs";
16
-
17
- export function classNames(value) {
18
- __requireArity(arguments.length, [0], "classNames");
19
- value = __boundary(value);
20
- if (__requireBoolean(value === null)) {
21
- return [];
22
- }
23
- if (__requireBoolean(!__requireBoolean(__isArray(value)))) {
24
- throw "UiClassesMustBeArray";
25
- }
26
- let result = [];
27
- let whitespace = new (__hostGlobal(["RegExp"]))("\\s");
28
- for (const name of value) {
29
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(__normalize(whitespace.test(name))))) {
30
- throw "UiClassMustBeToken";
31
- }
32
- if (__requireBoolean(!__requireBoolean(__normalize(result.includes(name))))) {
33
- result.push(name);
34
- }
35
- }
36
- return result;
37
- return null;
38
- }
39
-
40
- export function styleMap(value) {
41
- __requireArity(arguments.length, [0], "styleMap");
42
- value = __boundary(value);
43
- if (__requireBoolean(value === null)) {
44
- return { };
45
- }
46
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(value))) || __requireBoolean(__isArray(value)))) {
47
- throw "UiStyleMustBeMap";
48
- }
49
- let pattern = new (__hostGlobal(["RegExp"]))("^(--[a-zA-Z0-9_-]+|-?[a-z][a-z0-9-]*)$");
50
- let result = { };
51
- for (const [name, text] of __entries(value)) {
52
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(pattern.test(name)))) || __requireBoolean(!__requireBoolean(__isString(text))))) {
53
- throw "UiStyleRequiresCssPropertiesAndStrings";
54
- }
55
- result[name] = text;
56
- }
57
- return result;
58
- return null;
59
- }
60
-
61
- export function validateProperty(name, value) {
62
- __requireArity(arguments.length, [0, 1], "validateProperty");
63
- name = __boundary(name);
64
- value = __boundary(value);
65
- if (name === "enabled") {
66
- if (__requireBoolean(!__requireBoolean(__isBool(value)))) {
67
- throw "UiClientStateRequiresBoolean";
68
- }
69
- } else if (name === "visible") {
70
- if (__requireBoolean(!__requireBoolean(__isBool(value)))) {
71
- throw "UiClientStateRequiresBoolean";
72
- }
73
- } else if (name === "classes") {
74
- classNames(value);
75
- } else if (name === "style") {
76
- styleMap(value);
77
- } else if (name === "savedValue") {
78
- __toJson(value);
79
- } else if (name === "error") {
80
- if (__requireBoolean(__requireBoolean(value !== null) && __requireBoolean(!__requireBoolean(__isString(value))))) {
81
- throw "UiFieldErrorMustBeStringOrNull";
82
- }
83
- } else {
84
- throw "UiClientUnsupportedProperty";
85
- }
86
- return null;
87
- return null;
88
- }
89
- //# sourceMappingURL=presentation.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"presentation.mjs","sources":["presentation.lango"],"sourcesContent":["import js global RegExp\n\nexport classNames(value)\nexport styleMap(value)\nexport validateProperty(name, value)\n\nclassNames(value)\n if value == null\n return []\n if !is_array(value)\n throw \"UiClassesMustBeArray\"\n result = []\n whitespace = new RegExp(\"\\\\s\")\n for value as name\n if !is_string(name) or name == \"\" or whitespace.test(name)\n throw \"UiClassMustBeToken\"\n if !result.includes(name)\n result.add(name)\n return result\n\nstyleMap(value)\n if value == null\n return {\n }\n if !is_object(value) or is_array(value)\n throw \"UiStyleMustBeMap\"\n pattern = new RegExp(\"^(--[a-zA-Z0-9_-]+|-?[a-z][a-z0-9-]*)$\")\n result = {\n }\n for value as name: text\n if !pattern.test(name) or !is_string(text)\n throw \"UiStyleRequiresCssPropertiesAndStrings\"\n result[name] = text\n return result\n\nvalidateProperty(name, value)\n switch name\n case \"enabled\"\n if !is_bool(value)\n throw \"UiClientStateRequiresBoolean\"\n case \"visible\"\n if !is_bool(value)\n throw \"UiClientStateRequiresBoolean\"\n case \"classes\"\n classNames(value)\n case \"style\"\n styleMap(value)\n case \"savedValue\"\n to_json(value)\n case \"error\"\n if value != null and !is_string(value)\n throw \"UiFieldErrorMustBeStringOrNull\"\n else\n throw \"UiClientUnsupportedProperty\"\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}