@lango-project/lango-client 0.2.1 → 0.4.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 (240) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +603 -906
  4. package/cli/.lango/localization.mjs +108 -0
  5. package/{dist/node → cli}/.lango/runtime.mjs +120 -20
  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 +120 -20
  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 +671 -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 +102 -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 +141 -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/dimensions.mjs +102 -0
  41. package/dist/dimensions.mjs.map +1 -0
  42. package/dist/error_reporter.mjs +136 -0
  43. package/dist/error_reporter.mjs.map +1 -0
  44. package/dist/fields.mjs +454 -0
  45. package/dist/fields.mjs.map +1 -0
  46. package/dist/file_input.mjs +227 -0
  47. package/dist/file_input.mjs.map +1 -0
  48. package/dist/form.mjs +272 -0
  49. package/dist/form.mjs.map +1 -0
  50. package/dist/heartbeat.mjs +167 -254
  51. package/dist/heartbeat.mjs.map +1 -1
  52. package/dist/index.html +18 -0
  53. package/dist/indicators.mjs +127 -0
  54. package/dist/indicators.mjs.map +1 -0
  55. package/dist/input_changes.mjs +58 -0
  56. package/dist/input_changes.mjs.map +1 -0
  57. package/dist/input_group.mjs +38 -0
  58. package/dist/input_group.mjs.map +1 -0
  59. package/dist/layouts.mjs +195 -0
  60. package/dist/layouts.mjs.map +1 -0
  61. package/dist/library.mjs +130 -807
  62. package/dist/library.mjs.map +1 -1
  63. package/dist/longpoll.mjs +254 -0
  64. package/dist/longpoll.mjs.map +1 -0
  65. package/dist/main.mjs +147 -0
  66. package/dist/main.mjs.map +1 -0
  67. package/dist/markdown.mjs +61 -0
  68. package/dist/markdown.mjs.map +1 -0
  69. package/dist/menus.mjs +468 -0
  70. package/dist/menus.mjs.map +1 -0
  71. package/dist/navigation.mjs +260 -410
  72. package/dist/navigation.mjs.map +1 -1
  73. package/dist/numeric_input.mjs +181 -0
  74. package/dist/numeric_input.mjs.map +1 -0
  75. package/dist/otp_input.mjs +113 -0
  76. package/dist/otp_input.mjs.map +1 -0
  77. package/dist/presentations.mjs +852 -0
  78. package/dist/presentations.mjs.map +1 -0
  79. package/dist/renderer.mjs +295 -0
  80. package/dist/renderer.mjs.map +1 -0
  81. package/dist/rich_content.mjs +99 -0
  82. package/dist/rich_content.mjs.map +1 -0
  83. package/dist/table_scope.mjs +166 -0
  84. package/dist/table_scope.mjs.map +1 -0
  85. package/dist/tables.mjs +1052 -0
  86. package/dist/tables.mjs.map +1 -0
  87. package/dist/tabs.mjs +205 -0
  88. package/dist/tabs.mjs.map +1 -0
  89. package/dist/templates.mjs +46 -0
  90. package/dist/templates.mjs.map +1 -0
  91. package/dist/vendor/DOMPurify-LICENSE +202 -0
  92. package/dist/vendor/dompurify.mjs +2454 -0
  93. package/dist/vendor/flatpickr-LICENSE.md +21 -0
  94. package/dist/vendor/flatpickr.min.css +13 -0
  95. package/dist/vendor/flatpickr.mjs +2340 -0
  96. package/dist/vendor/flatpickr.mjs.map +7 -0
  97. package/dist/vendor/marked-LICENSE.md +44 -0
  98. package/dist/vendor/marked.esm.js.map +7 -0
  99. package/dist/vendor/marked.mjs +85 -0
  100. package/dist/vendor/purify.es.mjs.map +1 -0
  101. package/dist/widgets.mjs +197 -0
  102. package/dist/widgets.mjs.map +1 -0
  103. package/docs/implementation.md +93 -0
  104. package/package.json +25 -43
  105. package/src/accordion.lango +198 -0
  106. package/src/activities.lango +132 -0
  107. package/src/app.lango +540 -0
  108. package/src/boot.lango +12 -0
  109. package/src/button.lango +49 -0
  110. package/src/chip.lango +94 -0
  111. package/src/collections.lango +46 -0
  112. package/src/combo_box.lango +298 -0
  113. package/src/content.lango +75 -0
  114. package/src/control.lango +103 -0
  115. package/src/create.lango +42 -0
  116. package/src/date_input.lango +215 -0
  117. package/src/dimensions.lango +65 -0
  118. package/src/error_reporter.lango +95 -0
  119. package/src/fields.lango +327 -0
  120. package/src/file_input.lango +175 -0
  121. package/src/form.lango +195 -0
  122. package/src/heartbeat.lango +136 -199
  123. package/src/indicators.lango +94 -0
  124. package/src/input_changes.lango +33 -0
  125. package/src/input_group.lango +22 -0
  126. package/src/layouts.lango +137 -0
  127. package/src/library.lango +194 -599
  128. package/src/longpoll.lango +187 -0
  129. package/src/main.lango +118 -0
  130. package/src/markdown.lango +48 -0
  131. package/src/menus.lango +336 -0
  132. package/src/navigation.lango +209 -299
  133. package/src/numeric_input.lango +131 -0
  134. package/src/otp_input.lango +83 -0
  135. package/src/presentations.lango +617 -0
  136. package/src/renderer.lango +296 -0
  137. package/src/rich_content.lango +66 -0
  138. package/src/table_scope.lango +119 -0
  139. package/src/tables.lango +786 -0
  140. package/src/tabs.lango +144 -0
  141. package/src/templates.lango +29 -0
  142. package/src/widgets.lango +141 -0
  143. package/web/client.css +102 -0
  144. package/web/index.html +18 -0
  145. package/dist/application.mjs +0 -429
  146. package/dist/application.mjs.map +0 -1
  147. package/dist/coordinator.mjs +0 -91
  148. package/dist/coordinator.mjs.map +0 -1
  149. package/dist/demo.mjs +0 -110
  150. package/dist/demo.mjs.map +0 -1
  151. package/dist/demo_controls.mjs +0 -59
  152. package/dist/demo_controls.mjs.map +0 -1
  153. package/dist/errors.mjs +0 -201
  154. package/dist/errors.mjs.map +0 -1
  155. package/dist/form_state.mjs +0 -266
  156. package/dist/form_state.mjs.map +0 -1
  157. package/dist/inheritance.mjs +0 -240
  158. package/dist/inheritance.mjs.map +0 -1
  159. package/dist/input_values.mjs +0 -65
  160. package/dist/input_values.mjs.map +0 -1
  161. package/dist/node/.lango/xmldom/conventions.js +0 -429
  162. package/dist/node/.lango/xmldom/dom-parser.js +0 -591
  163. package/dist/node/.lango/xmldom/dom.js +0 -3759
  164. package/dist/node/.lango/xmldom/entities.js +0 -2171
  165. package/dist/node/.lango/xmldom/errors.js +0 -205
  166. package/dist/node/.lango/xmldom/grammar.js +0 -559
  167. package/dist/node/.lango/xmldom/index.js +0 -41
  168. package/dist/node/.lango/xmldom/package.json +0 -1
  169. package/dist/node/.lango/xmldom/sax.js +0 -983
  170. package/dist/node/.lango/xmldom.LICENSE.md +0 -8
  171. package/dist/node/browser_host.mjs +0 -351
  172. package/dist/node/browser_host.mjs.map +0 -1
  173. package/dist/node/create_app.mjs +0 -118
  174. package/dist/node/create_app.mjs.map +0 -1
  175. package/dist/presentation.mjs +0 -89
  176. package/dist/presentation.mjs.map +0 -1
  177. package/dist/protocol.mjs +0 -706
  178. package/dist/protocol.mjs.map +0 -1
  179. package/dist/session.mjs +0 -471
  180. package/dist/session.mjs.map +0 -1
  181. package/dist/tokens.mjs +0 -298
  182. package/dist/tokens.mjs.map +0 -1
  183. package/examples/contacts.lango +0 -293
  184. package/examples/contacts_flow.lango +0 -174
  185. package/examples/contacts_store.lango +0 -109
  186. package/examples/contacts_store_test.lango +0 -65
  187. package/examples/demo.css +0 -87
  188. package/examples/demo_test.lango +0 -356
  189. package/examples/index.html +0 -32
  190. package/examples/pages.lango +0 -174
  191. package/examples/server.lango +0 -189
  192. package/examples/worker.lango +0 -142
  193. package/src/application.lango +0 -327
  194. package/src/browser_host.lango +0 -276
  195. package/src/coordinator.lango +0 -57
  196. package/src/demo.lango +0 -110
  197. package/src/demo_controls.lango +0 -53
  198. package/src/errors.lango +0 -149
  199. package/src/errors_test.lango +0 -157
  200. package/src/form_state.lango +0 -168
  201. package/src/heartbeat_test.lango +0 -479
  202. package/src/inheritance.lango +0 -167
  203. package/src/input_values.lango +0 -37
  204. package/src/logout_test.lango +0 -564
  205. package/src/navigation_test.lango +0 -556
  206. package/src/presentation.lango +0 -55
  207. package/src/protocol.lango +0 -787
  208. package/src/renderer_test.lango +0 -2047
  209. package/src/session.lango +0 -343
  210. package/src/session_test.lango +0 -455
  211. package/src/tabs_test.lango +0 -216
  212. package/src/tokens.lango +0 -215
  213. package/template/.vscode/extensions.json +0 -3
  214. package/template/.vscode/settings.json +0 -9
  215. package/template/README.md +0 -44
  216. package/template/gitignore +0 -4
  217. package/template/package.json +0 -22
  218. package/template/public/app.css +0 -10
  219. package/template/public/index.html +0 -24
  220. package/template/src/client.lango +0 -78
  221. package/template/src/pages.lango +0 -55
  222. package/template/src/server.lango +0 -24
  223. package/template/src/worker.lango +0 -77
  224. package/template/test/app.lango +0 -9
  225. package/tools/browser_runner.lango +0 -32
  226. package/tools/browser_test.lango +0 -343
  227. package/tools/create_app.lango +0 -88
  228. package/tools/create_app_test.lango +0 -43
  229. package/tools/starter_test.lango +0 -227
  230. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  231. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  232. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  233. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  234. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  235. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  236. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  237. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  238. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  239. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  240. /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
@@ -1,466 +1,316 @@
1
+ import { Control } from "./control.mjs";
2
+ import { cloneMarkup } from "./templates.mjs";
3
+ import { appendContent, decorate } from "./content.mjs";
1
4
  import {
2
5
  hostGlobal as __hostGlobal,
3
- contextGet as __contextGet,
4
- contextSet as __contextSet,
5
- contextRestore as __contextRestore,
6
- getClass as __getClass,
7
- isKindof as __isKindof,
6
+ xmlEscape as __xmlEscape,
7
+ fromJson as __fromJson,
8
+ toJson as __toJson,
8
9
  isNumber as __isNumber,
9
10
  isString as __isString,
10
11
  isBool as __isBool,
11
12
  isObject as __isObject,
12
13
  isArray as __isArray,
13
- entries as __entries,
14
+ add as __add,
15
+ remove as __remove,
14
16
  requireBoolean as __requireBoolean,
15
17
  normalize as __normalize,
16
18
  finite as __finite,
17
- numericAdd as __numericAdd,
18
- call as __call,
19
19
  boundary as __boundary,
20
20
  requireArity as __requireArity,
21
- withArity as __withArity,
22
21
  } from "./.lango/runtime.mjs";
23
22
 
24
- export class Navigation {
25
- url;
26
- #window;
27
- #document;
28
- #onUrl;
29
- #errors;
30
- #redirect;
31
- #guard;
32
- #owner;
33
- #position;
34
- #restoring;
35
- #started;
36
- #disposed;
37
- #last;
38
- #initial;
39
- #tail;
40
- #click;
41
- #pop;
42
- #hash;
43
- constructor(window, options) {
44
- __requireArity(arguments.length, [0, 1], "constructor");
45
- window = __boundary(window);
46
- options = __boundary(options);
47
- if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(options))) || __requireBoolean(!__requireBoolean(__isKindof(__normalize(options.onUrl), Function))))) {
48
- throw "UiNavigationRequiresUrlHandler";
49
- }
50
- this.#window = window;
51
- this.#document = __normalize(window.document);
52
- this.#onUrl = __normalize(options.onUrl);
53
- this.#errors = __normalize(options.errors);
54
- this.#redirect = __normalize(options.rootRedirect);
55
- this.#guard = __normalize(options.beforeNavigate);
56
- if (__requireBoolean(__requireBoolean(__normalize(this.#guard) !== null) && __requireBoolean(!__requireBoolean(__isKindof(__normalize(this.#guard), Function))))) {
57
- throw "UiNavigationGuardRequiresFunction";
58
- }
59
- this.#owner = __normalize(__hostGlobal(["crypto"]).randomUUID());
60
- this.#position = 0;
61
- this.#restoring = false;
62
- this.#started = false;
63
- this.#disposed = false;
64
- this.#last = null;
65
- this.url = null;
66
- this.#initial = null;
67
- this.#tail = __normalize(__hostGlobal(["Promise"]).resolve());
68
- this.#click = null;
69
- this.#pop = null;
70
- this.#hash = null;
71
- if (__requireBoolean(__normalize(this.#redirect) !== null)) {
72
- this.#parseUrl(__normalize(this.#redirect));
73
- }
74
- }
75
- #parseUrl(value) {
76
- __requireArity(arguments.length, [0], "parseUrl");
77
- value = __boundary(value);
78
- if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(value))) || __requireBoolean(value === "")) || __requireBoolean(__normalize(value.includes("\\"))))) {
79
- throw "UiNavigationRequiresSameOriginUrl";
80
- }
81
- let location = __normalize(this.#window.location);
82
- let target = new (__hostGlobal(["URL"]))(value, __normalize(location.href));
83
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(target.origin) !== __normalize(location.origin)) || __requireBoolean(__requireBoolean(__normalize(target.protocol) !== "http:") && __requireBoolean(__normalize(target.protocol) !== "https:"))) || __requireBoolean(__normalize(target.username) !== "")) || __requireBoolean(__normalize(target.password) !== ""))) {
84
- throw "UiNavigationRequiresSameOriginUrl";
85
- }
86
- return target;
87
- return null;
88
- }
89
- start() {
90
- if (__requireBoolean(__normalize(this.#disposed))) {
91
- throw "UiNavigationDisposed";
92
- }
93
- if (__requireBoolean(__normalize(this.#started))) {
94
- return __normalize(this.#initial);
95
- }
96
- let location = __normalize(this.#window.location);
97
- if (__requireBoolean(__requireBoolean(__normalize(location.pathname) === "/") && __requireBoolean(__normalize(this.#redirect) !== null))) {
98
- let target = this.#parseUrl(__normalize(this.#redirect));
99
- if (__requireBoolean(__normalize(target.search) === "")) {
100
- target.search = __normalize(location.search);
23
+ export class Nav extends Control {
24
+ #items;
25
+ #overflow;
26
+ #url;
27
+ constructor(form, props, renderer, navigationBar = false) {
28
+ super(form, props, cloneMarkup("nav", ["<nav class=\"nav lango-nav\"></nav>"].join("")));
29
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
30
+ form = __boundary(form);
31
+ props = __boundary(props);
32
+ renderer = __boundary(renderer);
33
+ navigationBar = __boundary(navigationBar);
34
+ this.#items = [];
35
+ this.#overflow = __normalize(props.overflow) !== null;
36
+ this.#url = __normalize(form.app.hostUrl());
37
+ if (__requireBoolean(navigationBar)) {
38
+ __add(this.element.classList, "navbar");
39
+ if (__requireBoolean(__normalize(props.brand) !== null)) {
40
+ let brand = __normalize(__hostGlobal(["document"]).createElement("div"));
41
+ brand.className = "navbar-brand";
42
+ appendContent(form, brand, __normalize(props.brand), renderer);
43
+ __normalize(this.element.appendChild(brand));
101
44
  }
102
- if (__requireBoolean(__normalize(target.hash) === "")) {
103
- target.hash = __normalize(location.hash);
45
+ }
46
+ if (__normalize(props.alignment) === "center") {
47
+ __add(this.element.classList, "justify-content-center");
48
+ } else if (__normalize(props.alignment) === "end") {
49
+ __add(this.element.classList, "justify-content-end");
50
+ } else if (__normalize(props.alignment) === "vertical") {
51
+ __add(this.element.classList, "flex-column");
52
+ } else if (__normalize(props.alignment) === "fill") {
53
+ __add(this.element.classList, "nav-fill");
54
+ }
55
+ let placement = null;
56
+ if (__requireBoolean(__normalize(props.items) !== null)) {
57
+ for (const definition of __normalize(props.items)) {
58
+ if (__requireBoolean(__requireBoolean(__normalize(definition.type) !== "navItem") && __requireBoolean(__normalize(definition.type) !== "navBarItem"))) {
59
+ throw "Nav accepts NavItem definitions";
60
+ }
61
+ let item = new NavItem(form, definition, renderer);
62
+ __normalize(form.register(__normalize(definition.name), item));
63
+ this.#items.push(item);
64
+ __normalize(this.element.appendChild(__normalize(item.element)));
65
+ if (__requireBoolean(__normalize(definition.placement) !== null)) {
66
+ if (__requireBoolean(__requireBoolean(placement !== null) && __requireBoolean(placement !== __normalize(definition.placement)))) {
67
+ throw "Navbar items must agree on placement";
68
+ }
69
+ placement = __normalize(definition.placement);
70
+ if (__normalize(definition.placement) === "fixed-top" || __normalize(definition.placement) === "fixed-bottom" || __normalize(definition.placement) === "sticky-top" || __normalize(definition.placement) === "sticky-bottom") {
71
+ __add(this.element.classList, __normalize(definition.placement));
72
+ } else {
73
+ throw `Unknown navbar placement: ${__normalize(definition.placement)}`;
74
+ }
75
+ }
104
76
  }
105
- __normalize(this.#window.history.replaceState(null, "", localUrl(target)));
106
77
  }
107
- this.#started = true;
108
- __normalize(this.#window.history.replaceState(this.#historyState(0, localUrl(__normalize(this.#window.location))), "", localUrl(__normalize(this.#window.location))));
109
- let click = __withArity((event) => {
110
- event = __boundary(event);
111
- this.#clickEvent(event);
112
- return null;
113
- }, [0], "closure");
114
- let pop = __withArity((event) => {
115
- event = __boundary(event);
116
- this.#historyEvent("history");
117
- return null;
118
- }, [0], "closure");
119
- let hash = __withArity((event) => {
120
- event = __boundary(event);
121
- this.#historyEvent("hash");
78
+ this.locationChanged(__normalize(this.#url));
79
+ let groups = __normalize(renderer.navigation);
80
+ __add(groups, this);
81
+ let release = () => {
82
+ let index = __normalize(groups.indexOf(this));
83
+ if (__requireBoolean(index >= 0)) {
84
+ __normalize(groups.splice(index, 1));
85
+ }
122
86
  return null;
123
- }, [0], "closure");
124
- this.#click = click;
125
- this.#pop = pop;
126
- this.#hash = hash;
127
- __normalize(this.#document.addEventListener("click", click));
128
- __normalize(this.#window.addEventListener("popstate", pop));
129
- __normalize(this.#window.addEventListener("hashchange", hash));
130
- this.#initial = this.#notify("start");
131
- return __normalize(this.#initial);
87
+ };
88
+ __add(this.release, release);
89
+ if (__requireBoolean(__normalize(this.#overflow))) {
90
+ let observer = new (__hostGlobal(["ResizeObserver"]))(() => {
91
+ this.fit();
132
92
  return null;
93
+ });
94
+ __normalize(observer.observe(__normalize(this.element)));
95
+ let stop = () => {
96
+ __normalize(observer.disconnect());
97
+ return null;
98
+ };
99
+ __add(this.release, stop);
100
+ }
133
101
  }
134
- navigate(url, replace = false) {
135
- __requireArity(arguments.length, [0], "navigate");
102
+ locationChanged(url) {
103
+ __requireArity(arguments.length, [0], "locationChanged");
136
104
  url = __boundary(url);
137
- replace = __boundary(replace);
138
- if (__requireBoolean(__normalize(this.#disposed))) {
139
- throw "UiNavigationDisposed";
140
- }
141
- if (__requireBoolean(!__requireBoolean(__normalize(this.#started)))) {
142
- throw "UiNavigationNotStarted";
143
- }
144
- if (__requireBoolean(__normalize(this.#restoring))) {
145
- throw "UiNavigationRestoringHistory";
146
- }
147
- if (__requireBoolean(!__requireBoolean(__isBool(replace)))) {
148
- throw "UiNavigationReplaceMustBeBoolean";
149
- }
150
- let target = this.#parseUrl(url);
151
- let path = localUrl(target);
152
- if (__requireBoolean(path === localUrl(__normalize(this.#window.location)))) {
153
- if (__requireBoolean(__normalize(this.#last) === null)) {
154
- if (__requireBoolean(!__requireBoolean(this.#canNavigate(path, "navigate")))) {
155
- return __normalize(__hostGlobal(["Promise"]).resolve(false));
105
+ let best = __finite(-1);
106
+ let selected = null;
107
+ for (const item of __normalize(this.#items)) {
108
+ if (__requireBoolean(__normalize(item.url) !== null)) {
109
+ let score = navigationMatch(__normalize(item.url), url);
110
+ if (__requireBoolean(score > best)) {
111
+ best = score;
112
+ selected = item;
156
113
  }
157
- return this.#notify("navigate");
158
114
  }
159
- return __normalize(__hostGlobal(["Promise"]).resolve(null));
160
- }
161
- if (__requireBoolean(!__requireBoolean(this.#canNavigate(path, "navigate")))) {
162
- return __normalize(__hostGlobal(["Promise"]).resolve(false));
163
- }
164
- if (__requireBoolean(replace)) {
165
- __normalize(this.#window.history.replaceState(this.#historyState(__normalize(this.#position), path), "", path));
166
- } else {
167
- this.#position = __numericAdd(__normalize(this.#position), 1);
168
- __normalize(this.#window.history.pushState(this.#historyState(__normalize(this.#position), path), "", path));
169
115
  }
170
- return this.#notify("navigate");
171
- return null;
172
- }
173
- #canNavigate(path, source) {
174
- __requireArity(arguments.length, [0, 1], "canNavigate");
175
- path = __boundary(path);
176
- source = __boundary(source);
177
- if (__requireBoolean(__normalize(this.#guard) === null)) {
178
- return true;
179
- }
180
- let callback = __normalize(this.#guard);
181
- let result = __call(callback, { url: path, source: source });
182
- if (__requireBoolean(!__requireBoolean(__isBool(result)))) {
183
- if (__requireBoolean(__requireBoolean(result !== null) && __requireBoolean(__isKindof(__normalize(result.then), Function)))) {
184
- recovered(__normalize(__hostGlobal(["Promise"]).resolve(result)));
116
+ for (const item of __normalize(this.#items)) {
117
+ let active = __normalize(item.initial);
118
+ if (__requireBoolean(__normalize(item.url) !== null)) {
119
+ active = item === selected;
185
120
  }
186
- throw "UiNavigationGuardMustReturnBoolean";
187
- }
188
- return result;
189
- return null;
190
- }
191
- #historyState(position, path) {
192
- __requireArity(arguments.length, [0, 1], "historyState");
193
- position = __boundary(position);
194
- path = __boundary(path);
195
- let result = { };
196
- let previous = __normalize(this.#window.history.state);
197
- if (__requireBoolean(__requireBoolean(__isObject(previous)) && __requireBoolean(!__requireBoolean(__isArray(previous))))) {
198
- for (const [name, value] of __entries(previous)) {
199
- result[name] = value;
200
- }
201
- } else {
202
- if (__requireBoolean(previous !== null)) {
203
- result.previousState = previous;
121
+ __normalize(item.element.classList.toggle("active", active));
122
+ if (__requireBoolean(active)) {
123
+ __normalize(item.element.setAttribute("aria-current", "page"));
124
+ } else {
125
+ __normalize(item.element.removeAttribute("aria-current"));
204
126
  }
205
127
  }
206
- result["__langoNavigation"] = { owner: __normalize(this.#owner), index: position, url: path };
207
- return result;
208
- return null;
209
- }
210
- #historyEvent(source) {
211
- __requireArity(arguments.length, [0], "historyEvent");
212
- source = __boundary(source);
213
- try {
214
- this.#moveHistory(source);
215
- } catch (error) {
216
- this.#report(error);
217
- }
218
128
  return null;
219
129
  return null;
220
130
  }
221
- #moveHistory(source) {
222
- __requireArity(arguments.length, [0], "moveHistory");
223
- source = __boundary(source);
224
- let path = localUrl(__normalize(this.#window.location));
225
- let state = __normalize(this.#window.history.state);
226
- let marker = null;
227
- if (__requireBoolean(state !== null)) {
228
- marker = __normalize(state["__langoNavigation"]);
229
- }
230
- if (__requireBoolean(__normalize(this.#restoring))) {
231
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(path === __normalize(this.url)) && __requireBoolean(marker !== null)) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner))) && __requireBoolean(__normalize(marker.index) === __normalize(this.#position)))) {
232
- this.#restoring = false;
233
- }
234
- return null;
235
- }
236
- if (__requireBoolean(path === __normalize(this.url))) {
237
- if (__requireBoolean(__requireBoolean(marker !== null) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner)))) {
238
- this.#position = __normalize(marker.index);
239
- }
240
- return null;
241
- }
242
- let position = __numericAdd(__normalize(this.#position), 1);
243
- if (__requireBoolean(__requireBoolean(__requireBoolean(marker !== null) && __requireBoolean(__normalize(marker.owner) === __normalize(this.#owner))) && __requireBoolean(__normalize(marker.url) === path))) {
244
- position = __normalize(marker.index);
245
- }
246
- let allowed = false;
247
- try {
248
- allowed = this.#canNavigate(path, source);
249
- } catch (error) {
250
- this.#restoreHistory(position);
251
- throw error;
252
- }
253
- if (__requireBoolean(!__requireBoolean(allowed))) {
254
- this.#restoreHistory(position);
255
- return null;
131
+ fit() {
132
+ __remove(this.element.classList, "lango-nav-compact");
133
+ if (__requireBoolean(__normalize(this.element.scrollWidth) > __normalize(this.element.clientWidth))) {
134
+ __add(this.element.classList, "lango-nav-compact");
256
135
  }
257
- this.#position = position;
258
- __normalize(this.#window.history.replaceState(this.#historyState(position, path), "", path));
259
- this.#observe(this.#notify(source));
260
136
  return null;
261
137
  return null;
262
138
  }
263
- #restoreHistory(position) {
264
- __requireArity(arguments.length, [0], "restoreHistory");
265
- position = __boundary(position);
266
- if (__requireBoolean(position === __normalize(this.#position))) {
267
- __normalize(this.#window.history.replaceState(this.#historyState(__normalize(this.#position), __normalize(this.url)), "", __normalize(this.url)));
268
- return null;
269
- }
270
- this.#restoring = true;
271
- __normalize(this.#window.history.go(__finite(__normalize(this.#position) - position)));
272
- return null;
273
- return null;
139
+ }
140
+
141
+ export class NavBar extends Nav {
142
+ constructor(form, props, renderer) {
143
+ super(form, props, renderer, true);
144
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
145
+ form = __boundary(form);
146
+ props = __boundary(props);
147
+ renderer = __boundary(renderer);
274
148
  }
275
- #notify(source) {
276
- __requireArity(arguments.length, [0], "notify");
277
- source = __boundary(source);
278
- if (__requireBoolean(__normalize(this.#disposed))) {
279
- return __normalize(__hostGlobal(["Promise"]).resolve(null));
280
- }
281
- let path = localUrl(__normalize(this.#window.location));
282
- this.url = path;
283
- if (__requireBoolean(path === __normalize(this.#last))) {
284
- return __normalize(__hostGlobal(["Promise"]).resolve(null));
149
+ }
150
+
151
+ export class NavItem extends Control {
152
+ url;
153
+ initial;
154
+ constructor(form, props, renderer) {
155
+ super(form, props, navElement(__normalize(props.url)));
156
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
157
+ form = __boundary(form);
158
+ props = __boundary(props);
159
+ renderer = __boundary(renderer);
160
+ this.url = __normalize(props.url);
161
+ this.initial = __normalize(props.active) === true;
162
+ __add(this.element.classList, "nav-link");
163
+ appendNavContent(form, __normalize(this.element), __normalize(props.content), renderer);
164
+ if (__requireBoolean(__requireBoolean(__normalize(this.url) !== null) && __requireBoolean(__normalize(this.element.querySelector("a, button, input, select, textarea, [contenteditable]")) !== null))) {
165
+ throw "A linked NavItem cannot contain interactive controls";
166
+ }
167
+ __normalize(this.element.setAttribute("aria-label", __normalize(this.element.textContent)));
168
+ this.element.title = __normalize(this.element.textContent);
169
+ decorate(this, props);
170
+ if (__requireBoolean(__requireBoolean(__normalize(props.keepVisible) === true) || __requireBoolean(__normalize(this.element.querySelector("img, svg, i, .bi")) === null))) {
171
+ __add(this.element.classList, "lango-nav-keep");
172
+ }
173
+ if (__requireBoolean(__normalize(props.theme) !== null)) {
174
+ __add(this.element.classList, `text-bg-${__normalize(props.theme.toLowerCase())}`);
175
+ }
176
+ if (__requireBoolean(__normalize(props.dark) === true)) {
177
+ __normalize(this.element.setAttribute("data-bs-theme", "dark"));
178
+ }
179
+ if (__requireBoolean(__normalize(props.translucent) === true)) {
180
+ __normalize(this.element.style.setProperty("--bs-bg-opacity", ".85"));
285
181
  }
286
- this.#last = path;
287
- let work = this.#deliver(__normalize(this.#tail), { url: path, source: source });
288
- this.#tail = recovered(work);
289
- return work;
182
+ }
183
+ setCaption(value) {
184
+ __requireArity(arguments.length, [0], "setCaption");
185
+ value = __boundary(value);
186
+ this.element.textContent = value;
187
+ __normalize(this.element.setAttribute("aria-label", value));
188
+ this.element.title = value;
189
+ __add(this.element.classList, "lango-nav-keep");
190
+ return this;
290
191
  return null;
291
192
  }
292
- refresh() {
293
- if (__requireBoolean(__normalize(this.#disposed))) {
294
- throw "UiNavigationDisposed";
295
- }
296
- if (__requireBoolean(!__requireBoolean(__normalize(this.#started)))) {
297
- throw "UiNavigationNotStarted";
298
- }
299
- if (__requireBoolean(__normalize(this.#restoring))) {
300
- throw "UiNavigationRestoringHistory";
193
+ }
194
+
195
+ export class NavBarItem extends NavItem {
196
+ constructor(form, props, renderer) {
197
+ super(form, props, renderer);
198
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
199
+ form = __boundary(form);
200
+ props = __boundary(props);
201
+ renderer = __boundary(renderer);
202
+ }
203
+ }
204
+
205
+ export class Breadcrumb extends Control {
206
+ constructor(form, props, renderer) {
207
+ super(form, props, cloneMarkup("breadcrumb", ["<nav><ol class=\"breadcrumb\"></ol></nav>"].join("")));
208
+ __requireArity(arguments.length, [0, 1, 2], "constructor");
209
+ form = __boundary(form);
210
+ props = __boundary(props);
211
+ renderer = __boundary(renderer);
212
+ let list = __normalize(this.element.firstElementChild);
213
+ if (__requireBoolean(__normalize(props.divider) !== null)) {
214
+ __normalize(list.style.setProperty("--bs-breadcrumb-divider", __toJson(`${__normalize(props.divider)}`)));
215
+ }
216
+ if (__requireBoolean(__normalize(props.items) !== null)) {
217
+ for (const definition of __normalize(props.items)) {
218
+ if (__requireBoolean(__normalize(definition.type) !== "breadcrumbItem")) {
219
+ throw "Breadcrumb accepts BreadcrumbItem definitions";
220
+ }
221
+ let item = new BreadcrumbItem(form, definition);
222
+ __normalize(form.register(__normalize(definition.name), item));
223
+ __normalize(list.appendChild(__normalize(item.element)));
224
+ }
301
225
  }
302
- if (__requireBoolean(!__requireBoolean(this.#canNavigate(localUrl(__normalize(this.#window.location)), "refresh")))) {
303
- return __normalize(__hostGlobal(["Promise"]).resolve(false));
226
+ if (__requireBoolean(__normalize(list.lastElementChild) !== null)) {
227
+ __add(list.lastElementChild.classList, "active");
228
+ __normalize(list.lastElementChild.setAttribute("aria-current", "page"));
304
229
  }
305
- this.#last = null;
306
- return this.#notify("refresh");
307
- return null;
308
230
  }
309
- #deliver(ready, event) {
310
- __requireArity(arguments.length, [0, 1], "deliver");
311
- ready = __boundary(ready);
312
- event = __boundary(event);
313
- return ready.then(() => {
314
- if (__requireBoolean(__normalize(this.#disposed))) {
315
- return null;
316
- }
317
- let callback = __normalize(this.#onUrl);
318
- return __call(callback, event);
319
- return null;
320
- }).catch(__withArity((error) => {
321
- error = __boundary(error);
322
- if (__requireBoolean(__normalize(this.#last) === __normalize(event.url))) {
323
- this.#last = null;
324
- }
325
- throw error;
326
- return null;
327
- }, [0], "closure"));
328
- return null;
231
+ }
232
+
233
+ export class BreadcrumbItem extends Control {
234
+ constructor(form, props) {
235
+ super(form, props, cloneMarkup("breadcrumb-item", ["<li class=\"breadcrumb-item\"></li>"].join("")));
236
+ __requireArity(arguments.length, [0, 1], "constructor");
237
+ form = __boundary(form);
238
+ props = __boundary(props);
239
+ decorate(this, props);
240
+ let content = navElement(__normalize(props.url));
241
+ content.textContent = __normalize(props.text);
242
+ __normalize(this.element.appendChild(content));
329
243
  }
330
- #observe(work) {
331
- __requireArity(arguments.length, [0], "observe");
332
- work = __boundary(work);
333
- work.catch(__withArity((error) => {
334
- error = __boundary(error);
335
- this.#report(error);
336
- return null;
337
- }, [0], "closure"));
338
- return null;
339
- return null;
244
+ }
245
+ export function navigationMatch(url, current) {
246
+ __requireArity(arguments.length, [0, 1], "navigationMatch");
247
+ url = __boundary(url);
248
+ current = __boundary(current);
249
+ let target = new (__hostGlobal(["URL"]))(url, current);
250
+ let location = new (__hostGlobal(["URL"]))(current);
251
+ if (__requireBoolean(__normalize(target.origin) !== __normalize(location.origin))) {
252
+ return __finite(-1);
340
253
  }
341
- #report(error) {
342
- const __contextScope = [];
343
- try {
344
- __requireArity(arguments.length, [0], "report");
345
- error = __boundary(error);
346
- if (__requireBoolean(__normalize(this.#disposed))) {
347
- return null;
348
- }
349
- if (__requireBoolean(__normalize(this.#errors) !== null)) {
350
- __normalize(this.#errors.error(error));
351
- } else {
352
- __normalize(__contextGet("log").err(error));
353
- }
354
- return null;
355
- return null;
356
- } finally {
357
- __contextRestore(__contextScope);
358
- }
254
+ let path = __normalize(target.pathname);
255
+ if (__requireBoolean(path === __normalize(location.pathname))) {
256
+ return __normalize(path.length);
359
257
  }
360
- #clickEvent(event) {
361
- __requireArity(arguments.length, [0], "clickEvent");
362
- event = __boundary(event);
363
- if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__normalize(this.#disposed)) || __requireBoolean(__normalize(event.defaultPrevented) === true)) || __requireBoolean(__normalize(event.metaKey) === true)) || __requireBoolean(__normalize(event.ctrlKey) === true)) || __requireBoolean(__normalize(event.shiftKey) === true)) || __requireBoolean(__normalize(event.altKey) === true))) {
364
- return null;
365
- }
366
- if (__requireBoolean(__requireBoolean(__normalize(event.button) !== null) && __requireBoolean(__normalize(event.button) !== 0))) {
367
- return null;
368
- }
369
- let anchor = this.#link(__normalize(event.target));
370
- if (__requireBoolean(__requireBoolean(anchor === null) || __requireBoolean(__normalize(anchor.hasAttribute("download"))))) {
371
- return null;
372
- }
373
- let href = __normalize(anchor.getAttribute("href"));
374
- if (__requireBoolean(__requireBoolean(href === null) || __requireBoolean(href === ""))) {
375
- return null;
376
- }
377
- let target = __normalize(anchor.getAttribute("target"));
378
- if (__requireBoolean(__requireBoolean(__requireBoolean(target !== null) && __requireBoolean(target !== "")) && __requireBoolean(__normalize(target.toLowerCase()) !== "_self"))) {
379
- return null;
380
- }
381
- try {
382
- let destination = new (__hostGlobal(["URL"]))(href, __normalize(this.#window.location.href));
383
- if (__requireBoolean(__requireBoolean(__normalize(destination.protocol) !== "http:") && __requireBoolean(__normalize(destination.protocol) !== "https:"))) {
384
- return null;
385
- }
386
- let location = __normalize(this.#window.location);
387
- if (__requireBoolean(__normalize(destination.origin) !== __normalize(location.origin))) {
388
- if (__requireBoolean(target === null)) {
389
- __normalize(anchor.setAttribute("target", "_blank"));
390
- let rel = __normalize(anchor.getAttribute("rel"));
391
- if (__requireBoolean(__requireBoolean(rel === null) || __requireBoolean(rel === ""))) {
392
- rel = "noopener";
393
- } else {
394
- if (__requireBoolean(!__requireBoolean(__normalize(__normalize(rel.split(" ")).includes("noopener"))))) {
395
- rel = `${rel} noopener`;
396
- }
397
- }
398
- __normalize(anchor.setAttribute("rel", rel));
399
- }
400
- return null;
401
- }
402
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(destination.pathname) === __normalize(location.pathname)) && __requireBoolean(__normalize(destination.search) === __normalize(location.search))) && __requireBoolean(__requireBoolean(__normalize(destination.hash) !== __normalize(location.hash)) || __requireBoolean(__normalize(href.includes("#")))))) {
403
- return null;
404
- }
405
- __normalize(event.preventDefault());
406
- this.#observe(this.navigate(__normalize(destination.href)));
407
- } catch (error) {
408
- this.#report(error);
409
- }
410
- return null;
411
- return null;
258
+ if (__requireBoolean(__requireBoolean(path !== "/") && __requireBoolean(__normalize(location.pathname.startsWith(`${__normalize(path.replace(new (__hostGlobal(["RegExp"]))("/+$"), ""))}/`))))) {
259
+ return __normalize(path.length);
412
260
  }
413
- #link(element) {
414
- __requireArity(arguments.length, [0], "link");
415
- element = __boundary(element);
416
- let current = element;
417
- let found = null;
418
- __loop1: while (__requireBoolean(current !== null)) {
419
- if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(current.inert) === true) || __requireBoolean(__normalize(current.hidden) === true)) || __requireBoolean(__normalize(current.disabled) === true))) {
420
- return null;
421
- }
422
- let name = __normalize(current.tagName);
423
- if (__requireBoolean(__requireBoolean(__requireBoolean(found === null) && __requireBoolean(__isString(name))) && __requireBoolean(__normalize(name.toLowerCase()) === "a"))) {
424
- found = current;
425
- }
426
- current = __normalize(current.parentNode);
427
- }
428
- return found;
261
+ return __finite(-1);
429
262
  return null;
263
+ }
264
+
265
+ function navElement(url) {
266
+ __requireArity(arguments.length, [0], "navElement");
267
+ url = __boundary(url);
268
+ if (__requireBoolean(url === null)) {
269
+ return cloneMarkup("nav-content", ["<div></div>"].join(""));
430
270
  }
431
- idle() {
432
- return __normalize(this.#tail);
433
- return null;
271
+ if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(__normalize(url.trim()) === ""))) {
272
+ throw "NavItem URL must be nonempty text";
434
273
  }
435
- dispose() {
436
- if (__requireBoolean(__normalize(this.#disposed))) {
437
- return null;
438
- }
439
- this.#disposed = true;
440
- if (__requireBoolean(__normalize(this.#started))) {
441
- __normalize(this.#document.removeEventListener("click", __normalize(this.#click)));
442
- __normalize(this.#window.removeEventListener("popstate", __normalize(this.#pop)));
443
- __normalize(this.#window.removeEventListener("hashchange", __normalize(this.#hash)));
444
- }
445
- return null;
446
- return null;
274
+ let target = new (__hostGlobal(["URL"]))(url, __normalize(__hostGlobal(["document"]).baseURI));
275
+ if (__requireBoolean(__requireBoolean(__normalize(target.protocol) !== "http:") && __requireBoolean(__normalize(target.protocol) !== "https:"))) {
276
+ throw "Unsupported navigation URL";
447
277
  }
448
- }
449
- function localUrl(target) {
450
- __requireArity(arguments.length, [0], "localUrl");
451
- target = __boundary(target);
452
- return `${__normalize(target.pathname)}${__normalize(target.search)}${__normalize(target.hash)}`;
278
+ let element = __normalize(__hostGlobal(["document"]).createElement("a"));
279
+ element.href = __normalize(target.href);
280
+ return element;
453
281
  return null;
454
282
  }
455
283
 
456
- function recovered(work) {
457
- __requireArity(arguments.length, [0], "recovered");
458
- work = __boundary(work);
459
- return work.catch(__withArity((error) => {
460
- error = __boundary(error);
461
- return null;
284
+ function appendNavContent(form, element, content, renderer) {
285
+ __requireArity(arguments.length, [0, 1, 2, 3], "appendNavContent");
286
+ form = __boundary(form);
287
+ element = __boundary(element);
288
+ content = __boundary(content);
289
+ renderer = __boundary(renderer);
290
+ let label;
291
+ let child;
292
+ if (__requireBoolean(content === null)) {
462
293
  return null;
463
- }, [0], "closure"));
294
+ }
295
+ if (__requireBoolean(__isArray(content))) {
296
+ for (const child of content) {
297
+ appendNavContent(form, element, child, renderer);
298
+ }
299
+ } else {
300
+ if (__requireBoolean(__requireBoolean(__isString(content)) || __requireBoolean(__isNumber(content)))) {
301
+ label = __normalize(__hostGlobal(["document"]).createElement("span"));
302
+ label.className = "lango-nav-label";
303
+ label.textContent = `${content}`;
304
+ __normalize(element.appendChild(label));
305
+ } else {
306
+ child = __normalize(renderer.build(form, content));
307
+ if (__requireBoolean(__normalize(content.type) === "text")) {
308
+ __add(child.classList, "lango-nav-label");
309
+ }
310
+ __normalize(element.appendChild(child));
311
+ }
312
+ }
313
+ return null;
464
314
  return null;
465
315
  }
466
316
  //# sourceMappingURL=navigation.mjs.map