@lango-project/lango-client 0.0.0-stage → 0.2.1

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 (112) hide show
  1. package/LICENSE +200 -0
  2. package/NOTICE +2 -0
  3. package/README.md +929 -2
  4. package/dist/.lango/bignumber.mjs +3119 -0
  5. package/dist/.lango/runtime.mjs +607 -0
  6. package/dist/.lango/xmldom/conventions.js +429 -0
  7. package/dist/.lango/xmldom/dom-parser.js +591 -0
  8. package/dist/.lango/xmldom/dom.js +3759 -0
  9. package/dist/.lango/xmldom/entities.js +2171 -0
  10. package/dist/.lango/xmldom/errors.js +205 -0
  11. package/dist/.lango/xmldom/grammar.js +559 -0
  12. package/dist/.lango/xmldom/index.js +41 -0
  13. package/dist/.lango/xmldom/package.json +1 -0
  14. package/dist/.lango/xmldom/sax.js +983 -0
  15. package/dist/.lango/xmldom.LICENSE.md +8 -0
  16. package/dist/application.mjs +429 -0
  17. package/dist/application.mjs.map +1 -0
  18. package/dist/coordinator.mjs +91 -0
  19. package/dist/coordinator.mjs.map +1 -0
  20. package/dist/demo.mjs +110 -0
  21. package/dist/demo.mjs.map +1 -0
  22. package/dist/demo_controls.mjs +59 -0
  23. package/dist/demo_controls.mjs.map +1 -0
  24. package/dist/errors.mjs +201 -0
  25. package/dist/errors.mjs.map +1 -0
  26. package/dist/form_state.mjs +266 -0
  27. package/dist/form_state.mjs.map +1 -0
  28. package/dist/heartbeat.mjs +330 -0
  29. package/dist/heartbeat.mjs.map +1 -0
  30. package/dist/inheritance.mjs +240 -0
  31. package/dist/inheritance.mjs.map +1 -0
  32. package/dist/input_values.mjs +65 -0
  33. package/dist/input_values.mjs.map +1 -0
  34. package/dist/library.mjs +824 -0
  35. package/dist/library.mjs.map +1 -0
  36. package/dist/navigation.mjs +466 -0
  37. package/dist/navigation.mjs.map +1 -0
  38. package/dist/node/.lango/bignumber.mjs +3119 -0
  39. package/dist/node/.lango/runtime.mjs +609 -0
  40. package/dist/node/.lango/xmldom/conventions.js +429 -0
  41. package/dist/node/.lango/xmldom/dom-parser.js +591 -0
  42. package/dist/node/.lango/xmldom/dom.js +3759 -0
  43. package/dist/node/.lango/xmldom/entities.js +2171 -0
  44. package/dist/node/.lango/xmldom/errors.js +205 -0
  45. package/dist/node/.lango/xmldom/grammar.js +559 -0
  46. package/dist/node/.lango/xmldom/index.js +41 -0
  47. package/dist/node/.lango/xmldom/package.json +1 -0
  48. package/dist/node/.lango/xmldom/sax.js +983 -0
  49. package/dist/node/.lango/xmldom.LICENSE.md +8 -0
  50. package/dist/node/browser_host.mjs +351 -0
  51. package/dist/node/browser_host.mjs.map +1 -0
  52. package/dist/node/create_app.mjs +118 -0
  53. package/dist/node/create_app.mjs.map +1 -0
  54. package/dist/presentation.mjs +89 -0
  55. package/dist/presentation.mjs.map +1 -0
  56. package/dist/protocol.mjs +706 -0
  57. package/dist/protocol.mjs.map +1 -0
  58. package/dist/session.mjs +471 -0
  59. package/dist/session.mjs.map +1 -0
  60. package/dist/tokens.mjs +298 -0
  61. package/dist/tokens.mjs.map +1 -0
  62. package/examples/contacts.lango +293 -0
  63. package/examples/contacts_flow.lango +174 -0
  64. package/examples/contacts_store.lango +109 -0
  65. package/examples/contacts_store_test.lango +65 -0
  66. package/examples/demo.css +87 -0
  67. package/examples/demo_test.lango +356 -0
  68. package/examples/index.html +32 -0
  69. package/examples/pages.lango +174 -0
  70. package/examples/server.lango +189 -0
  71. package/examples/worker.lango +142 -0
  72. package/package.json +68 -4
  73. package/src/application.lango +327 -0
  74. package/src/browser_host.lango +276 -0
  75. package/src/coordinator.lango +57 -0
  76. package/src/demo.lango +110 -0
  77. package/src/demo_controls.lango +53 -0
  78. package/src/errors.lango +149 -0
  79. package/src/errors_test.lango +157 -0
  80. package/src/form_state.lango +168 -0
  81. package/src/heartbeat.lango +230 -0
  82. package/src/heartbeat_test.lango +479 -0
  83. package/src/inheritance.lango +167 -0
  84. package/src/input_values.lango +37 -0
  85. package/src/library.lango +599 -0
  86. package/src/logout_test.lango +564 -0
  87. package/src/navigation.lango +309 -0
  88. package/src/navigation_test.lango +556 -0
  89. package/src/presentation.lango +55 -0
  90. package/src/protocol.lango +787 -0
  91. package/src/renderer_test.lango +2047 -0
  92. package/src/session.lango +343 -0
  93. package/src/session_test.lango +455 -0
  94. package/src/tabs_test.lango +216 -0
  95. package/src/tokens.lango +215 -0
  96. package/template/.vscode/extensions.json +3 -0
  97. package/template/.vscode/settings.json +9 -0
  98. package/template/README.md +44 -0
  99. package/template/gitignore +4 -0
  100. package/template/package.json +22 -0
  101. package/template/public/app.css +10 -0
  102. package/template/public/index.html +24 -0
  103. package/template/src/client.lango +78 -0
  104. package/template/src/pages.lango +55 -0
  105. package/template/src/server.lango +24 -0
  106. package/template/src/worker.lango +77 -0
  107. package/template/test/app.lango +9 -0
  108. package/tools/browser_runner.lango +32 -0
  109. package/tools/browser_test.lango +343 -0
  110. package/tools/create_app.lango +88 -0
  111. package/tools/create_app_test.lango +43 -0
  112. package/tools/starter_test.lango +227 -0
@@ -0,0 +1,824 @@
1
+ import { collectValues, applyResponse } from "./protocol.mjs";
2
+ import { normalizeInheritance } from "./inheritance.mjs";
3
+ import { classNames, styleMap, validateProperty } from "./presentation.mjs";
4
+ import { selectItems, selectIndex } from "./input_values.mjs";
5
+ import { rulesFor, validationMessage, sameValue } from "./form_state.mjs";
6
+ import {
7
+ hostGlobal as __hostGlobal,
8
+ contextGet as __contextGet,
9
+ contextSet as __contextSet,
10
+ contextRestore as __contextRestore,
11
+ fromJson as __fromJson,
12
+ toJson as __toJson,
13
+ getClass as __getClass,
14
+ isKindof as __isKindof,
15
+ isNumber as __isNumber,
16
+ isString as __isString,
17
+ isBool as __isBool,
18
+ isObject as __isObject,
19
+ isArray as __isArray,
20
+ includes as __includes,
21
+ entries as __entries,
22
+ remove as __remove,
23
+ clear as __clear,
24
+ requireBoolean as __requireBoolean,
25
+ normalize as __normalize,
26
+ boundary as __boundary,
27
+ requireArity as __requireArity,
28
+ withArity as __withArity,
29
+ } from "./.lango/runtime.mjs";
30
+
31
+ export class Types {
32
+ #types;
33
+ #classes;
34
+ #sealed;
35
+ constructor(options = null) {
36
+ options = __boundary(options);
37
+ if (__requireBoolean(__requireBoolean(options !== null) && __requireBoolean(__requireBoolean(!__requireBoolean(__isObject(options))) || __requireBoolean(__isArray(options))))) {
38
+ throw "UiControlRegistryOptionsMustBeMap";
39
+ }
40
+ this.#types = { };
41
+ this.#classes = { };
42
+ this.#sealed = false;
43
+ if (__requireBoolean(__requireBoolean(options !== null) && __requireBoolean(__normalize(options.classes) !== null))) {
44
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(__normalize(options.classes)))) || __requireBoolean(__isArray(__normalize(options.classes))))) {
45
+ throw "UiThemeClassesMustBeMap";
46
+ }
47
+ for (const [name, classes] of __entries(__normalize(options.classes))) {
48
+ this.#classes[name] = classNames(classes);
49
+ }
50
+ }
51
+ }
52
+ registerType(name, type) {
53
+ __requireArity(arguments.length, [0, 1], "registerType");
54
+ name = __boundary(name);
55
+ type = __boundary(type);
56
+ if (__requireBoolean(__normalize(this.#sealed))) {
57
+ throw "UiControlRegistrySealed";
58
+ }
59
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(name === "")) || __requireBoolean(name === "__proto__")) || __requireBoolean(name === "prototype")) || __requireBoolean(name === "constructor")) || __requireBoolean(!__requireBoolean(__isKindof(type, Function))))) {
60
+ throw "UiControlTypeRequiresNameAndConstructor";
61
+ }
62
+ if (__requireBoolean(__includes(name, __normalize(this.#types)))) {
63
+ throw `UiDuplicateControlType: ${name}`;
64
+ }
65
+ this.#types[name] = type;
66
+ return this;
67
+ return null;
68
+ }
69
+ create(document, definition) {
70
+ __requireArity(arguments.length, [0, 1], "create");
71
+ document = __boundary(document);
72
+ definition = __boundary(definition);
73
+ this.#sealed = true;
74
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(definition))) || __requireBoolean(!__requireBoolean(__isString(__normalize(definition.type)))))) {
75
+ throw "UiControlRequiresDefinition";
76
+ }
77
+ let prepared = { };
78
+ for (const [name, value] of __entries(definition)) {
79
+ prepared[name] = value;
80
+ }
81
+ let defaults = __normalize(this.#classes[__normalize(definition.type)]);
82
+ if (__requireBoolean(defaults !== null)) {
83
+ prepared.classes = classNames(__normalize(defaults.concat(classNames(__normalize(definition.classes)))));
84
+ }
85
+ let type = Control;
86
+ if (__requireBoolean(__includes(__normalize(definition.type), __normalize(this.#types)))) {
87
+ type = __normalize(this.#types[__normalize(definition.type)]);
88
+ }
89
+ let control = new type(document, prepared, this);
90
+ if (__requireBoolean(!__requireBoolean(__isKindof(control, Control)))) {
91
+ throw "UiCustomControlMustExtendControl";
92
+ }
93
+ return control;
94
+ return null;
95
+ }
96
+ }
97
+
98
+ export class Binding {
99
+ #form;
100
+ #session;
101
+ #errors;
102
+ #disposed;
103
+ #listener;
104
+ constructor(form, session, errors = null) {
105
+ __requireArity(arguments.length, [0, 1], "constructor");
106
+ form = __boundary(form);
107
+ session = __boundary(session);
108
+ errors = __boundary(errors);
109
+ this.#form = form;
110
+ this.#session = session;
111
+ this.#errors = errors;
112
+ this.#disposed = false;
113
+ let root = __normalize(form.element);
114
+ if (__requireBoolean(__normalize(root.langoBinding) !== null)) {
115
+ throw "UiFormAlreadyBound";
116
+ }
117
+ let listener = __withArity((event) => {
118
+ event = __boundary(event);
119
+ this.handle(event);
120
+ return null;
121
+ }, [0], "closure");
122
+ this.#listener = listener;
123
+ for (const type of ["click", "change", "input"]) {
124
+ __normalize(root.addEventListener(type, listener));
125
+ }
126
+ root.langoBinding = this;
127
+ }
128
+ handle(event) {
129
+ __requireArity(arguments.length, [0], "handle");
130
+ event = __boundary(event);
131
+ if (__requireBoolean(__normalize(this.#disposed))) {
132
+ return null;
133
+ }
134
+ let root = __normalize(this.#form.element);
135
+ let element = __normalize(event.target);
136
+ let target = null;
137
+ let current = element;
138
+ __loop1: while (__requireBoolean(current !== null)) {
139
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.inert) === true) || __requireBoolean(__normalize(current.disabled) === true)) || __requireBoolean(__normalize(current.hidden) === true))) {
140
+ return null;
141
+ }
142
+ if (__requireBoolean(current === root)) {
143
+ break;
144
+ }
145
+ if (__requireBoolean(__normalize(current.langoFormRoot) === true)) {
146
+ return null;
147
+ }
148
+ if (__requireBoolean(target === null)) {
149
+ target = eventTarget(__normalize(this.#form.controls), current, [], __normalize(event.type));
150
+ }
151
+ current = __normalize(current.parentNode);
152
+ }
153
+ if (__requireBoolean(current !== root)) {
154
+ return null;
155
+ }
156
+ if (__requireBoolean(__requireBoolean(__normalize(event.type) === "input") || __requireBoolean(__normalize(event.type) === "change"))) {
157
+ validateEvent(__normalize(this.#form.controls), __normalize(event.target), root);
158
+ }
159
+ if (__requireBoolean(target === null)) {
160
+ return null;
161
+ }
162
+ try {
163
+ __normalize(event.preventDefault());
164
+ if (__requireBoolean(__requireBoolean(__normalize(this.#errors) !== null) && __requireBoolean(__normalize(this.#errors.clear) !== null))) {
165
+ __clear(this.#errors);
166
+ }
167
+ let session = __normalize(this.#session);
168
+ return __normalize(session.send(__normalize(target.url), __normalize(event.type), __normalize(target.name))).catch(__withArity((error) => {
169
+ error = __boundary(error);
170
+ this.report(error);
171
+ return null;
172
+ }, [0], "closure"));
173
+ } catch (error) {
174
+ this.report(error);
175
+ }
176
+ return null;
177
+ return null;
178
+ }
179
+ report(error) {
180
+ const __contextScope = [];
181
+ try {
182
+ __requireArity(arguments.length, [0], "report");
183
+ error = __boundary(error);
184
+ if (__requireBoolean(__normalize(this.#disposed))) {
185
+ return null;
186
+ }
187
+ if (__requireBoolean(__normalize(this.#errors) !== null)) {
188
+ __normalize(this.#errors.error(error));
189
+ } else {
190
+ __normalize(__contextGet("log").err(error));
191
+ }
192
+ return null;
193
+ return null;
194
+ } finally {
195
+ __contextRestore(__contextScope);
196
+ }
197
+ }
198
+ dispose() {
199
+ if (__requireBoolean(__normalize(this.#disposed))) {
200
+ return null;
201
+ }
202
+ this.#disposed = true;
203
+ let root = __normalize(this.#form.element);
204
+ for (const type of ["click", "change", "input"]) {
205
+ __normalize(root.removeEventListener(type, __normalize(this.#listener)));
206
+ }
207
+ root.langoBinding = null;
208
+ return null;
209
+ return null;
210
+ }
211
+ }
212
+
213
+ export class Renderer {
214
+ #document;
215
+ #types;
216
+ constructor(document, types = null) {
217
+ __requireArity(arguments.length, [0], "constructor");
218
+ document = __boundary(document);
219
+ types = __boundary(types);
220
+ this.#document = document;
221
+ this.#types = types;
222
+ if (__requireBoolean(__normalize(this.#types) === null)) {
223
+ this.#types = new Types();
224
+ }
225
+ }
226
+ create(definition) {
227
+ __requireArity(arguments.length, [0], "create");
228
+ definition = __boundary(definition);
229
+ return __normalize(this.#types.create(__normalize(this.#document), definition));
230
+ return null;
231
+ }
232
+ release(control) {
233
+ __requireArity(arguments.length, [0], "release");
234
+ control = __boundary(control);
235
+ releaseControl(control);
236
+ return null;
237
+ return null;
238
+ }
239
+ replace(old, replacement) {
240
+ __requireArity(arguments.length, [0, 1], "replace");
241
+ old = __boundary(old);
242
+ replacement = __boundary(replacement);
243
+ let element = __normalize(old.node);
244
+ __normalize(element.parentNode.replaceChild(__normalize(replacement.node), element));
245
+ return null;
246
+ return null;
247
+ }
248
+ remove(control) {
249
+ __requireArity(arguments.length, [0], "remove");
250
+ control = __boundary(control);
251
+ __remove(control.node);
252
+ return null;
253
+ return null;
254
+ }
255
+ capture(control) {
256
+ __requireArity(arguments.length, [0], "capture");
257
+ control = __boundary(control);
258
+ let element = __normalize(control.node);
259
+ return { element: element, parent: __normalize(element.parentNode), next: __normalize(element.nextSibling) };
260
+ return null;
261
+ }
262
+ restore(snapshot, operation) {
263
+ __requireArity(arguments.length, [0, 1], "restore");
264
+ snapshot = __boundary(snapshot);
265
+ operation = __boundary(operation);
266
+ if (__requireBoolean(__normalize(operation.type) === "replace")) {
267
+ let replacement = __normalize(operation.new);
268
+ __remove(replacement.node);
269
+ }
270
+ if (__requireBoolean(__normalize(snapshot.parent) !== null)) {
271
+ __normalize(snapshot.parent.insertBefore(__normalize(snapshot.element), __normalize(snapshot.next)));
272
+ }
273
+ return null;
274
+ return null;
275
+ }
276
+ focus(control) {
277
+ __requireArity(arguments.length, [0], "focus");
278
+ control = __boundary(control);
279
+ __normalize(control.element.focus());
280
+ return null;
281
+ return null;
282
+ }
283
+ toast(level, text) {
284
+ __requireArity(arguments.length, [0, 1], "toast");
285
+ level = __boundary(level);
286
+ text = __boundary(text);
287
+ let element = __normalize(this.#document.createElement("div"));
288
+ __normalize(element.setAttribute("role", "status"));
289
+ element.textContent = text;
290
+ __normalize(this.#document.body.appendChild(element));
291
+ return null;
292
+ return null;
293
+ }
294
+ }
295
+
296
+ export class Control {
297
+ name;
298
+ element;
299
+ node;
300
+ controls;
301
+ events;
302
+ inherit;
303
+ validates;
304
+ confirms;
305
+ #type;
306
+ #value;
307
+ #clean;
308
+ #error;
309
+ #pendingError;
310
+ #rules;
311
+ #tracked;
312
+ #items;
313
+ #classes;
314
+ #style;
315
+ #errorElement;
316
+ constructor(document, definition, types = null, options = null) {
317
+ __requireArity(arguments.length, [0, 1], "constructor");
318
+ document = __boundary(document);
319
+ definition = __boundary(definition);
320
+ types = __boundary(types);
321
+ options = __boundary(options);
322
+ this.name = __normalize(definition.name);
323
+ this.#type = __normalize(definition.type);
324
+ this.controls = null;
325
+ this.#value = __normalize(definition.value);
326
+ this.#clean = null;
327
+ this.#error = null;
328
+ this.#pendingError = false;
329
+ this.#rules = rulesFor(__normalize(definition.validation));
330
+ this.#tracked = __normalize(definition.trackChanges);
331
+ if (__requireBoolean(__normalize(this.#tracked) === null)) {
332
+ this.#tracked = __requireBoolean(__requireBoolean(__normalize(this.#type) === "Text") || __requireBoolean(__normalize(this.#type) === "Select")) || __requireBoolean(__normalize(this.#type) === "Checkbox");
333
+ }
334
+ if (__requireBoolean(!__requireBoolean(__isBool(__normalize(this.#tracked))))) {
335
+ throw "UiTrackChangesMustBeBoolean";
336
+ }
337
+ this.validates = __normalize(definition.validate);
338
+ if (__requireBoolean(__normalize(this.validates) === null)) {
339
+ this.validates = false;
340
+ }
341
+ if (__requireBoolean(!__requireBoolean(__isBool(__normalize(this.validates))))) {
342
+ throw "UiValidateEventMustBeBoolean";
343
+ }
344
+ this.confirms = __normalize(definition.confirmDirty);
345
+ if (__requireBoolean(__normalize(this.confirms) === null)) {
346
+ this.confirms = false;
347
+ }
348
+ if (__requireBoolean(!__requireBoolean(__isBool(__normalize(this.confirms))))) {
349
+ throw "UiConfirmDirtyMustBeBoolean";
350
+ }
351
+ this.#items = [];
352
+ if (__requireBoolean(__normalize(this.#type) === "Select")) {
353
+ this.#items = selectItems(__normalize(definition.options));
354
+ }
355
+ this.events = controlEvents(definition);
356
+ this.inherit = normalizeInheritance(__normalize(definition.inherit));
357
+ this.#classes = classNames(__normalize(definition.classes));
358
+ this.#style = styleMap(__normalize(definition.style));
359
+ let registry = types;
360
+ if (__requireBoolean(registry === null)) {
361
+ registry = new Types();
362
+ }
363
+ if (__requireBoolean(__requireBoolean(__normalize(definition.inherit) !== null) && __requireBoolean(__normalize(this.#type) !== "Form"))) {
364
+ throw "UiInheritanceRequiresForm";
365
+ }
366
+ let tag = "div";
367
+ if (__requireBoolean(__requireBoolean(__normalize(this.#type) === "Text") || __requireBoolean(__normalize(this.#type) === "Checkbox"))) {
368
+ tag = "input";
369
+ }
370
+ if (__requireBoolean(__normalize(this.#type) === "Select")) {
371
+ tag = "select";
372
+ }
373
+ if (__requireBoolean(__normalize(this.#type) === "Button")) {
374
+ tag = "button";
375
+ }
376
+ if (__requireBoolean(options !== null)) {
377
+ tag = __normalize(options.tag);
378
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(tag))) || __requireBoolean(tag === ""))) {
379
+ throw "UiCustomControlRequiresTag";
380
+ }
381
+ }
382
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(options === null) && __requireBoolean(__normalize(this.#type) !== "Text")) && __requireBoolean(__normalize(this.#type) !== "Button")) && __requireBoolean(__normalize(this.#type) !== "Value")) && __requireBoolean(__normalize(this.#type) !== "Panel")) && __requireBoolean(__normalize(this.#type) !== "Container")) && __requireBoolean(__normalize(this.#type) !== "Form")) && __requireBoolean(__normalize(this.#type) !== "Select")) && __requireBoolean(__normalize(this.#type) !== "Checkbox"))) {
383
+ throw "UiClientUnknownControlType";
384
+ }
385
+ this.element = __normalize(document.createElement(tag));
386
+ this.node = __normalize(this.element);
387
+ this.#errorElement = null;
388
+ let element = __normalize(this.element);
389
+ if (__requireBoolean(__normalize(this.#type) === "Form")) {
390
+ element.langoFormRoot = true;
391
+ }
392
+ if (__requireBoolean(__normalize(this.#type) === "Button")) {
393
+ element.type = "button";
394
+ element.textContent = __normalize(definition.text);
395
+ }
396
+ if (__requireBoolean(__normalize(this.#type) === "Value")) {
397
+ element.hidden = true;
398
+ }
399
+ if (__requireBoolean(__normalize(this.#type) === "Checkbox")) {
400
+ element.type = "checkbox";
401
+ }
402
+ if (__requireBoolean(__normalize(definition.label) !== null)) {
403
+ if (__requireBoolean(!__requireBoolean(__isString(__normalize(definition.label))))) {
404
+ throw "UiControlLabelMustBeString";
405
+ }
406
+ __normalize(element.setAttribute("aria-label", __normalize(definition.label)));
407
+ if (__requireBoolean(__requireBoolean(tag === "input") || __requireBoolean(tag === "select"))) {
408
+ this.node = __normalize(document.createElement("label"));
409
+ this.node.className = "lango-field";
410
+ __normalize(this.node.setAttribute("data-lango-control", __normalize(this.#type)));
411
+ let caption = __normalize(document.createElement("span"));
412
+ caption.className = "lango-caption";
413
+ caption.textContent = __normalize(definition.label);
414
+ __normalize(this.node.appendChild(caption));
415
+ __normalize(this.node.appendChild(element));
416
+ this.#errorElement = __normalize(document.createElement("span"));
417
+ this.#errorElement.className = "lango-field-error";
418
+ this.#errorElement.id = `lango-error-${__normalize(__hostGlobal(["crypto"]).randomUUID())}`;
419
+ this.#errorElement.hidden = true;
420
+ __normalize(element.setAttribute("aria-describedby", __normalize(this.#errorElement.id)));
421
+ __normalize(this.node.appendChild(__normalize(this.#errorElement)));
422
+ }
423
+ }
424
+ if (__requireBoolean(__requireBoolean(tag === "input") || __requireBoolean(tag === "select"))) {
425
+ __normalize(element.setAttribute("aria-required", `${__normalize(this.#rules.required) === true}`));
426
+ }
427
+ let container = __requireBoolean(__requireBoolean(__normalize(this.#type) === "Panel") || __requireBoolean(__normalize(this.#type) === "Container")) || __requireBoolean(__normalize(this.#type) === "Form");
428
+ if (__requireBoolean(__requireBoolean(options !== null) && __requireBoolean(__normalize(options.container) === true))) {
429
+ container = true;
430
+ }
431
+ if (__requireBoolean(container)) {
432
+ this.controls = [];
433
+ }
434
+ try {
435
+ if (__requireBoolean(__normalize(this.#type) === "Select")) {
436
+ for (const item of __normalize(this.#items)) {
437
+ let option = __normalize(document.createElement("option"));
438
+ option.value = __normalize(item.value);
439
+ option.textContent = __normalize(item.text);
440
+ option.disabled = __normalize(item.disabled);
441
+ __normalize(element.appendChild(option));
442
+ }
443
+ }
444
+ if (__requireBoolean(__requireBoolean(container) && __requireBoolean(__isArray(__normalize(definition.controls))))) {
445
+ for (const childDefinition of __normalize(definition.controls)) {
446
+ let child = __normalize(registry.create(document, childDefinition));
447
+ this.controls.push(child);
448
+ __normalize(element.appendChild(__normalize(child.node)));
449
+ }
450
+ }
451
+ if (__requireBoolean(__normalize(definition.classes) !== null)) {
452
+ this.applyProperty("classes", __normalize(definition.classes));
453
+ }
454
+ if (__requireBoolean(__normalize(definition.style) !== null)) {
455
+ this.applyProperty("style", __normalize(definition.style));
456
+ }
457
+ if (__requireBoolean(__normalize(definition.enabled) !== null)) {
458
+ this.applyProperty("enabled", __normalize(definition.enabled));
459
+ }
460
+ if (__requireBoolean(__normalize(definition.visible) !== null)) {
461
+ this.applyProperty("visible", __normalize(definition.visible));
462
+ }
463
+ let initial = __normalize(definition.value);
464
+ if (__requireBoolean(__requireBoolean(__normalize(this.#type) === "Checkbox") && __requireBoolean(initial === null))) {
465
+ initial = false;
466
+ }
467
+ this.setValue(initial);
468
+ this.markClean();
469
+ } catch (error) {
470
+ if (__requireBoolean(__isArray(__normalize(this.controls)))) {
471
+ for (const child of __normalize(this.controls)) {
472
+ releaseControl(child);
473
+ }
474
+ }
475
+ throw error;
476
+ }
477
+ }
478
+ getValue() {
479
+ if (__requireBoolean(__isArray(__normalize(this.controls)))) {
480
+ return collectValues(__normalize(this.controls));
481
+ }
482
+ if (__normalize(this.#type) === "Text") {
483
+ return __normalize(this.element.value);
484
+ } else if (__normalize(this.#type) === "Checkbox") {
485
+ return __normalize(this.element.checked);
486
+ } else if (__normalize(this.#type) === "Select") {
487
+ let index = __normalize(this.element.selectedIndex);
488
+ if (__requireBoolean(__requireBoolean(index < 0) || __requireBoolean(index >= __normalize(this.#items.length)))) {
489
+ return null;
490
+ }
491
+ return __normalize(__normalize(this.#items[index]).value);
492
+ } else {
493
+ return __normalize(this.#value);
494
+ }
495
+ return null;
496
+ }
497
+ setValue(value) {
498
+ __requireArity(arguments.length, [0], "setValue");
499
+ value = __boundary(value);
500
+ if (__normalize(this.#type) === "Text") {
501
+ let text = value;
502
+ if (__requireBoolean(value === null)) {
503
+ text = "";
504
+ }
505
+ this.element.value = text;
506
+ } else if (__normalize(this.#type) === "Checkbox") {
507
+ if (__requireBoolean(!__requireBoolean(__isBool(value)))) {
508
+ throw "UiCheckboxValueMustBeBoolean";
509
+ }
510
+ this.element.checked = value;
511
+ } else if (__normalize(this.#type) === "Select") {
512
+ this.element.selectedIndex = selectIndex(__normalize(this.#items), value);
513
+ }
514
+ this.#value = value;
515
+ if (__requireBoolean(__normalize(this.#error) !== null)) {
516
+ this.validate();
517
+ }
518
+ return null;
519
+ return null;
520
+ }
521
+ isDirty() {
522
+ if (__requireBoolean(__isArray(__normalize(this.controls)))) {
523
+ for (const child of __normalize(this.controls)) {
524
+ if (__requireBoolean(__normalize(child.isDirty) !== null)) {
525
+ if (__requireBoolean(__normalize(child.isDirty()))) {
526
+ return true;
527
+ }
528
+ }
529
+ }
530
+ return false;
531
+ }
532
+ if (__requireBoolean(!__requireBoolean(__normalize(this.#tracked)))) {
533
+ return false;
534
+ }
535
+ let current = __fromJson(__toJson(this.getValue()));
536
+ return !__requireBoolean(sameValue(current, __normalize(this.#clean)));
537
+ return null;
538
+ }
539
+ markClean() {
540
+ if (__requireBoolean(__isArray(__normalize(this.controls)))) {
541
+ for (const child of __normalize(this.controls)) {
542
+ if (__requireBoolean(__normalize(child.markClean) !== null)) {
543
+ __normalize(child.markClean());
544
+ }
545
+ }
546
+ } else {
547
+ this.acceptSaved(this.getValue());
548
+ }
549
+ return null;
550
+ return null;
551
+ }
552
+ acceptSaved(value) {
553
+ __requireArity(arguments.length, [0], "acceptSaved");
554
+ value = __boundary(value);
555
+ this.#clean = __fromJson(__toJson(value));
556
+ return null;
557
+ return null;
558
+ }
559
+ validate() {
560
+ this.#pendingError = false;
561
+ this.#error = validationMessage(__normalize(this.#rules), this.getValue());
562
+ this.#renderError();
563
+ return __normalize(this.#error);
564
+ return null;
565
+ }
566
+ #renderError() {
567
+ let text = __normalize(this.#error);
568
+ if (__requireBoolean(text === null)) {
569
+ text = "";
570
+ }
571
+ __normalize(this.element.setAttribute("aria-invalid", `${__normalize(this.#error) !== null}`));
572
+ __normalize(this.element.setAttribute("data-lango-error", text));
573
+ if (__requireBoolean(__normalize(this.#errorElement) !== null)) {
574
+ this.#errorElement.textContent = text;
575
+ this.#errorElement.hidden = __normalize(this.#error) === null;
576
+ }
577
+ if (__requireBoolean(__normalize(this.element.setCustomValidity) !== null)) {
578
+ __normalize(this.element.setCustomValidity(text));
579
+ }
580
+ return null;
581
+ return null;
582
+ }
583
+ reportValidity() {
584
+ if (__requireBoolean(__normalize(this.element.reportValidity) !== null)) {
585
+ return __normalize(this.element.reportValidity());
586
+ }
587
+ return __normalize(this.#error) === null;
588
+ return null;
589
+ }
590
+ reportPendingError() {
591
+ if (__requireBoolean(!__requireBoolean(__normalize(this.#pendingError)))) {
592
+ return false;
593
+ }
594
+ let current = __normalize(this.element);
595
+ __loop2: while (__requireBoolean(current !== null)) {
596
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.disabled) === true) || __requireBoolean(__normalize(current.hidden) === true)) || __requireBoolean(__normalize(current.inert) === true))) {
597
+ return false;
598
+ }
599
+ current = __normalize(current.parentNode);
600
+ }
601
+ this.#pendingError = false;
602
+ this.reportValidity();
603
+ return true;
604
+ return null;
605
+ }
606
+ applyProperty(name, value) {
607
+ __requireArity(arguments.length, [0, 1], "applyProperty");
608
+ name = __boundary(name);
609
+ value = __boundary(value);
610
+ validateProperty(name, value);
611
+ if (name === "enabled") {
612
+ this.element.disabled = !__requireBoolean(value);
613
+ this.element.inert = !__requireBoolean(value);
614
+ this.node.inert = !__requireBoolean(value);
615
+ } else if (name === "visible") {
616
+ this.element.hidden = __requireBoolean(!__requireBoolean(value)) || __requireBoolean(__normalize(this.#type) === "Value");
617
+ this.node.hidden = __normalize(this.element.hidden);
618
+ } else if (name === "classes") {
619
+ this.#classes = classNames(value);
620
+ this.element.className = __normalize(this.#classes.join(" "));
621
+ } else if (name === "style") {
622
+ let styles = styleMap(value);
623
+ for (const [property, text] of __entries(__normalize(this.#style))) {
624
+ __normalize(this.element.style.removeProperty(property));
625
+ }
626
+ for (const [property, text] of __entries(styles)) {
627
+ __normalize(this.element.style.setProperty(property, text));
628
+ }
629
+ this.#style = styles;
630
+ } else if (name === "savedValue") {
631
+ this.acceptSaved(value);
632
+ } else if (name === "error") {
633
+ this.#error = value;
634
+ this.#pendingError = value !== null;
635
+ this.#renderError();
636
+ this.reportPendingError();
637
+ }
638
+ return null;
639
+ return null;
640
+ }
641
+ snapshotState() {
642
+ return { value: __normalize(this.#value), text: __normalize(this.element.value), checked: __normalize(this.element.checked), selectedIndex: __normalize(this.element.selectedIndex), disabled: __normalize(this.element.disabled), hidden: __normalize(this.element.hidden), inert: __normalize(this.element.inert), classes: __normalize(this.element.className), style: __normalize(this.element.style.cssText), managedStyle: __normalize(this.#style), managedClasses: __normalize(this.#classes), clean: __normalize(this.#clean), error: __normalize(this.#error), pendingError: __normalize(this.#pendingError) };
643
+ return null;
644
+ }
645
+ restoreState(snapshot) {
646
+ __requireArity(arguments.length, [0], "restoreState");
647
+ snapshot = __boundary(snapshot);
648
+ this.setValue(__normalize(snapshot.value));
649
+ if (__requireBoolean(__normalize(this.#type) === "Text")) {
650
+ this.element.value = __normalize(snapshot.text);
651
+ }
652
+ if (__requireBoolean(__normalize(this.#type) === "Checkbox")) {
653
+ this.element.checked = __normalize(snapshot.checked);
654
+ }
655
+ if (__requireBoolean(__normalize(this.#type) === "Select")) {
656
+ this.element.selectedIndex = __normalize(snapshot.selectedIndex);
657
+ }
658
+ this.element.disabled = __normalize(snapshot.disabled);
659
+ this.element.hidden = __normalize(snapshot.hidden);
660
+ this.element.inert = __normalize(snapshot.inert);
661
+ this.node.hidden = __normalize(snapshot.hidden);
662
+ this.node.inert = __normalize(snapshot.inert);
663
+ this.element.className = __normalize(snapshot.classes);
664
+ this.element.style.cssText = __normalize(snapshot.style);
665
+ this.#style = __normalize(snapshot.managedStyle);
666
+ this.#classes = __normalize(snapshot.managedClasses);
667
+ this.#clean = __normalize(snapshot.clean);
668
+ this.#error = __normalize(snapshot.error);
669
+ this.#pendingError = __normalize(snapshot.pendingError);
670
+ this.#renderError();
671
+ return null;
672
+ return null;
673
+ }
674
+ dispose() {
675
+ return null;
676
+ return null;
677
+ }
678
+ }
679
+ function validateEvent(controls, element, root) {
680
+ __requireArity(arguments.length, [0, 1, 2], "validateEvent");
681
+ controls = __boundary(controls);
682
+ element = __boundary(element);
683
+ root = __boundary(root);
684
+ let current = element;
685
+ __loop3: while (__requireBoolean(__requireBoolean(current !== null) && __requireBoolean(current !== root))) {
686
+ let control = elementControl(controls, current);
687
+ if (__requireBoolean(__requireBoolean(control !== null) && __requireBoolean(__normalize(control.validate) !== null))) {
688
+ __normalize(control.validate());
689
+ return null;
690
+ }
691
+ current = __normalize(current.parentNode);
692
+ }
693
+ return null;
694
+ return null;
695
+ }
696
+
697
+ function elementControl(controls, element) {
698
+ __requireArity(arguments.length, [0, 1], "elementControl");
699
+ controls = __boundary(controls);
700
+ element = __boundary(element);
701
+ for (const control of controls) {
702
+ if (__requireBoolean(control.element.langoFormRoot === true)) {
703
+ continue;
704
+ }
705
+ if (__requireBoolean(__normalize(control.element) === element)) {
706
+ return control;
707
+ }
708
+ if (__requireBoolean(__isArray(__normalize(control.controls)))) {
709
+ let found = elementControl(__normalize(control.controls), element);
710
+ if (__requireBoolean(found !== null)) {
711
+ return found;
712
+ }
713
+ }
714
+ }
715
+ return null;
716
+ return null;
717
+ }
718
+
719
+ function eventTarget(controls, element, parentPath, type) {
720
+ __requireArity(arguments.length, [0, 1, 2, 3], "eventTarget");
721
+ controls = __boundary(controls);
722
+ element = __boundary(element);
723
+ parentPath = __boundary(parentPath);
724
+ type = __boundary(type);
725
+ for (const control of controls) {
726
+ let path = __normalize(parentPath.slice());
727
+ if (__requireBoolean(__requireBoolean(__normalize(control.name) !== null) && __requireBoolean(__normalize(control.name) !== ""))) {
728
+ path[__normalize(path.length)] = __normalize(control.name);
729
+ }
730
+ if (__requireBoolean(__normalize(control.element) === element)) {
731
+ let events = __normalize(control.events);
732
+ if (__requireBoolean(__includes(type, events))) {
733
+ let name = path;
734
+ if (__requireBoolean(__normalize(path.length) === 1)) {
735
+ name = __normalize(path[0]);
736
+ }
737
+ if (__requireBoolean(__normalize(path.length) === 0)) {
738
+ name = null;
739
+ }
740
+ return { url: __normalize(events[type]), name: name };
741
+ }
742
+ }
743
+ if (__requireBoolean(__isArray(__normalize(control.controls)))) {
744
+ let target = eventTarget(__normalize(control.controls), element, path, type);
745
+ if (__requireBoolean(target !== null)) {
746
+ return target;
747
+ }
748
+ }
749
+ }
750
+ return null;
751
+ return null;
752
+ }
753
+
754
+ function controlEvents(definition) {
755
+ __requireArity(arguments.length, [0], "controlEvents");
756
+ definition = __boundary(definition);
757
+ let type;
758
+ let events = { };
759
+ if (__requireBoolean(__normalize(definition.event) !== null)) {
760
+ type = "change";
761
+ if (__requireBoolean(__normalize(definition.type) === "Button")) {
762
+ type = "click";
763
+ }
764
+ events[type] = __normalize(definition.event);
765
+ }
766
+ if (__requireBoolean(__normalize(definition.events) !== null)) {
767
+ if (__requireBoolean(!__requireBoolean(__isObject(__normalize(definition.events))))) {
768
+ throw "UiClientEventsMustBeMap";
769
+ }
770
+ for (const [type, url] of __entries(__normalize(definition.events))) {
771
+ if (__requireBoolean(__requireBoolean(__requireBoolean(type !== "click") && __requireBoolean(type !== "change")) && __requireBoolean(type !== "input"))) {
772
+ throw "UiClientUnsupportedEventType";
773
+ }
774
+ events[type] = url;
775
+ }
776
+ }
777
+ for (const [type, url] of __entries(events)) {
778
+ if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(!__requireBoolean(__normalize(url.startsWith("/"))))) || __requireBoolean(__normalize(url.startsWith("//")))) || __requireBoolean(__normalize(url.includes("\\"))))) {
779
+ throw "UiClientEventRequiresSameOriginPath";
780
+ }
781
+ }
782
+ return events;
783
+ return null;
784
+ }
785
+
786
+ function releaseControl(control) {
787
+ const __contextScope = [];
788
+ try {
789
+ __requireArity(arguments.length, [0], "releaseControl");
790
+ control = __boundary(control);
791
+ if (__requireBoolean(__isArray(__normalize(control.controls)))) {
792
+ for (const child of __normalize(control.controls)) {
793
+ releaseControl(child);
794
+ }
795
+ }
796
+ try {
797
+ if (__requireBoolean(__normalize(control.dispose) !== null)) {
798
+ __normalize(control.dispose());
799
+ }
800
+ } catch (error) {
801
+ __normalize(__contextGet("log").err(`Control disposal failed: ${error}`));
802
+ }
803
+ return null;
804
+ return null;
805
+ } finally {
806
+ __contextRestore(__contextScope);
807
+ }
808
+ }
809
+
810
+ export function mount(document, root, definition, types = null) {
811
+ __requireArity(arguments.length, [0, 1, 2], "mount");
812
+ document = __boundary(document);
813
+ root = __boundary(root);
814
+ definition = __boundary(definition);
815
+ types = __boundary(types);
816
+ if (__requireBoolean(types === null)) {
817
+ types = new Types();
818
+ }
819
+ let control = __normalize(types.create(document, definition));
820
+ __normalize(root.appendChild(__normalize(control.node)));
821
+ return control;
822
+ return null;
823
+ }
824
+ //# sourceMappingURL=library.mjs.map