@livenetworks/ashlar 2.0.7 → 2.0.9

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 (213) hide show
  1. package/LICENSE +641 -641
  2. package/components/COMPONENTS.md +1116 -1116
  3. package/components/index.js +81 -81
  4. package/components/ln-accordion/ln-accordion-dev.scss +8 -8
  5. package/components/ln-accordion/ln-accordion.js +1 -1
  6. package/components/ln-accordion/ln-accordion.schema.json +30 -30
  7. package/components/ln-ajax/ln-ajax-dev.scss +8 -8
  8. package/components/ln-ajax/ln-ajax.js +1 -1
  9. package/components/ln-ajax/ln-ajax.schema.json +30 -30
  10. package/components/ln-api-connector/ln-api-connector.js +1 -1
  11. package/components/ln-api-connector/ln-api-connector.schema.json +9 -0
  12. package/components/ln-api-connector/src/ln-api-connector.js +2 -0
  13. package/components/ln-api-queue/ln-api-queue.js +1 -1
  14. package/components/ln-api-queue/ln-api-queue.schema.json +34 -34
  15. package/components/ln-api-queue/src/ln-api-queue.js +3 -13
  16. package/components/ln-autoresize/ln-autoresize-dev.scss +8 -8
  17. package/components/ln-autoresize/ln-autoresize.js +1 -1
  18. package/components/ln-autoresize/ln-autoresize.schema.json +22 -22
  19. package/components/ln-autosave/ln-autosave-dev.scss +13 -13
  20. package/components/ln-autosave/ln-autosave.js +1 -1
  21. package/components/ln-autosave/ln-autosave.schema.json +48 -48
  22. package/components/ln-autosave/src/autosave-model.js +34 -34
  23. package/components/ln-chart/ln-chart.js +1 -1
  24. package/components/ln-chart/ln-chart.schema.json +146 -146
  25. package/components/ln-chart/src/chart-model.js +154 -154
  26. package/components/ln-circular-progress/ln-circular-progress.js +1 -1
  27. package/components/ln-circular-progress/ln-circular-progress.schema.json +42 -42
  28. package/components/ln-confirm/ln-confirm-dev.scss +24 -24
  29. package/components/ln-confirm/ln-confirm.js +1 -1
  30. package/components/ln-confirm/ln-confirm.schema.json +66 -66
  31. package/components/ln-confirm/src/ln-confirm.js +178 -178
  32. package/components/ln-core/attrs.js +13 -0
  33. package/components/ln-core/crypto.js +286 -265
  34. package/components/ln-core/dom.js +115 -115
  35. package/components/ln-core/form.js +146 -136
  36. package/components/ln-core/helpers.js +33 -33
  37. package/components/ln-core/http.js +48 -48
  38. package/components/ln-core/index.js +1 -1
  39. package/components/ln-core/lifecycle.js +5 -0
  40. package/components/ln-core/ln-core.schema.json +3 -2
  41. package/components/ln-core/locale.js +55 -55
  42. package/components/ln-core/matching.js +78 -78
  43. package/components/ln-core/number.js +125 -125
  44. package/components/ln-core/template.js +206 -206
  45. package/components/ln-couchdb-connector/ln-couchdb-connector.js +1 -1
  46. package/components/ln-couchdb-connector/ln-couchdb-connector.schema.json +50 -50
  47. package/components/ln-couchdb-connector/src/ln-couchdb-connector.js +1 -0
  48. package/components/ln-data-coordinator/README.md +9 -38
  49. package/components/ln-data-coordinator/ln-data-coordinator-dev.scss +8 -8
  50. package/components/ln-data-coordinator/ln-data-coordinator.js +1 -1
  51. package/components/ln-data-coordinator/ln-data-coordinator.schema.json +16 -16
  52. package/components/ln-data-coordinator/src/data-read-policy.js +0 -7
  53. package/components/ln-data-coordinator/src/ln-data-coordinator.js +432 -1308
  54. package/components/ln-data-store/ln-data-store-dev.scss +13 -13
  55. package/components/ln-data-store/ln-data-store.js +1 -1
  56. package/components/ln-data-store/ln-data-store.schema.json +84 -84
  57. package/components/ln-data-store/src/data-store-model.js +184 -184
  58. package/components/ln-data-store/src/ln-data-store.js +1 -1
  59. package/components/ln-date/ln-date.js +1 -1
  60. package/components/ln-date/ln-date.schema.json +92 -92
  61. package/components/ln-date/src/date-model.js +186 -186
  62. package/components/ln-debug/ln-debug.js +1 -1
  63. package/components/ln-debug/ln-debug.schema.json +28 -28
  64. package/components/ln-debug/src/console-sink.js +19 -19
  65. package/components/ln-debug/src/gate.js +95 -95
  66. package/components/ln-debug/src/generated-attributes.js +4 -2
  67. package/components/ln-dropdown/ln-dropdown-dev.scss +13 -13
  68. package/components/ln-dropdown/ln-dropdown.js +1 -1
  69. package/components/ln-dropdown/ln-dropdown.schema.json +90 -90
  70. package/components/ln-editor/ln-editor.js +1 -1
  71. package/components/ln-editor/ln-editor.schema.json +58 -58
  72. package/components/ln-external-links/ln-external-links.js +1 -1
  73. package/components/ln-external-links/ln-external-links.schema.json +18 -18
  74. package/components/ln-fill/ln-fill.js +1 -1
  75. package/components/ln-fill/ln-fill.schema.json +23 -23
  76. package/components/ln-filter/ln-filter.js +1 -1
  77. package/components/ln-filter/ln-filter.schema.json +153 -153
  78. package/components/ln-filter/src/filter-model.js +185 -185
  79. package/components/ln-form/ln-form-dev.scss +8 -8
  80. package/components/ln-form/ln-form.js +1 -1
  81. package/components/ln-form/ln-form.schema.json +6 -0
  82. package/components/ln-form/src/ln-form.js +21 -0
  83. package/components/ln-http/ln-http.js +1 -1
  84. package/components/ln-http/ln-http.schema.json +6 -6
  85. package/components/ln-icon/ln-icon.schema.json +6 -6
  86. package/components/ln-include/ln-include.js +1 -1
  87. package/components/ln-include/ln-include.schema.json +23 -23
  88. package/components/ln-key/ln-key-dev.scss +18 -18
  89. package/components/ln-key/ln-key.js +1 -1
  90. package/components/ln-key/ln-key.schema.json +56 -56
  91. package/components/ln-key/src/ln-key.js +10 -10
  92. package/components/ln-link/ln-link-dev.scss +8 -8
  93. package/components/ln-link/ln-link.js +1 -1
  94. package/components/ln-link/ln-link.schema.json +22 -22
  95. package/components/ln-list/README.md +152 -152
  96. package/components/ln-list/ln-list-dev.scss +8 -8
  97. package/components/ln-list/ln-list.js +1 -1
  98. package/components/ln-list/ln-list.schema.json +166 -166
  99. package/components/ln-modal/ln-modal.js +1 -1
  100. package/components/ln-modal/ln-modal.schema.json +65 -65
  101. package/components/ln-nav/ln-nav.js +1 -1
  102. package/components/ln-nav/ln-nav.schema.json +25 -25
  103. package/components/ln-number/ln-number.js +1 -1
  104. package/components/ln-number/ln-number.schema.json +63 -63
  105. package/components/ln-number/src/ln-number.js +26 -0
  106. package/components/ln-number/src/number-model.js +31 -31
  107. package/components/ln-obfuscator/README.md +60 -60
  108. package/components/ln-obfuscator/ln-obfuscator.js +1 -1
  109. package/components/ln-obfuscator/ln-obfuscator.schema.json +49 -49
  110. package/components/ln-obfuscator/src/ln-obfuscator.js +159 -159
  111. package/components/ln-obfuscator/src/obfuscator-model.js +250 -250
  112. package/components/ln-options/ln-options.js +1 -1
  113. package/components/ln-options/ln-options.schema.json +6 -0
  114. package/components/ln-options/src/ln-options.js +4 -4
  115. package/components/ln-persist/README.md +151 -151
  116. package/components/ln-persist/ln-persist.js +1 -1
  117. package/components/ln-persist/ln-persist.schema.json +28 -28
  118. package/components/ln-persist/src/ln-persist.js +83 -83
  119. package/components/ln-picklist/README.md +230 -230
  120. package/components/ln-picklist/ln-picklist-dev.scss +22 -22
  121. package/components/ln-picklist/ln-picklist.js +1 -1
  122. package/components/ln-picklist/ln-picklist.schema.json +49 -49
  123. package/components/ln-picklist/src/ln-picklist.js +228 -228
  124. package/components/ln-popover/ln-popover-dev.scss +13 -13
  125. package/components/ln-popover/ln-popover.js +1 -1
  126. package/components/ln-popover/ln-popover.schema.json +82 -82
  127. package/components/ln-progress/ln-progress-dev.scss +8 -8
  128. package/components/ln-progress/ln-progress.js +1 -1
  129. package/components/ln-progress/ln-progress.schema.json +40 -40
  130. package/components/ln-router/ln-router.js +1 -1
  131. package/components/ln-router/ln-router.schema.json +76 -76
  132. package/components/ln-scroll/README.md +45 -45
  133. package/components/ln-scroll/ln-scroll.js +1 -1
  134. package/components/ln-scroll/ln-scroll.schema.json +85 -85
  135. package/components/ln-scroll/src/ln-scroll.js +150 -150
  136. package/components/ln-search/README.md +188 -188
  137. package/components/ln-search/ln-search.js +1 -1
  138. package/components/ln-search/ln-search.schema.json +103 -103
  139. package/components/ln-slug/ln-slug.js +1 -1
  140. package/components/ln-slug/ln-slug.schema.json +23 -23
  141. package/components/ln-slug/src/ln-slug.js +25 -1
  142. package/components/ln-sort/ln-sort.js +1 -1
  143. package/components/ln-sort/ln-sort.schema.json +104 -104
  144. package/components/ln-sort/src/ln-sort.js +321 -321
  145. package/components/ln-sort/src/sort-model.js +117 -117
  146. package/components/ln-sortable/ln-sortable-dev.scss +13 -13
  147. package/components/ln-sortable/ln-sortable.js +1 -1
  148. package/components/ln-sortable/ln-sortable.schema.json +36 -36
  149. package/components/ln-stat/ln-stat-dev.scss +8 -8
  150. package/components/ln-stat/ln-stat.js +1 -1
  151. package/components/ln-stat/ln-stat.schema.json +32 -32
  152. package/components/ln-stat/src/stat-model.js +28 -28
  153. package/components/ln-table/ln-table.js +1 -1
  154. package/components/ln-table/ln-table.schema.json +211 -211
  155. package/components/ln-table/src/table-model.js +98 -98
  156. package/components/ln-table-coordinator/ln-table-coordinator.js +1 -1
  157. package/components/ln-table-coordinator/ln-table-coordinator.schema.json +93 -93
  158. package/components/ln-tabs/ln-tabs.js +1 -1
  159. package/components/ln-tabs/ln-tabs.schema.json +75 -75
  160. package/components/ln-tabs/src/ln-tabs.js +208 -208
  161. package/components/ln-tabs/src/tabs-model.js +82 -82
  162. package/components/ln-time/ln-time-dev.scss +13 -13
  163. package/components/ln-time/ln-time.js +1 -1
  164. package/components/ln-time/ln-time.schema.json +38 -38
  165. package/components/ln-toast/ln-toast.js +1 -1
  166. package/components/ln-toast/ln-toast.schema.json +65 -65
  167. package/components/ln-toggle/ln-toggle.js +1 -1
  168. package/components/ln-toggle/ln-toggle.schema.json +52 -52
  169. package/components/ln-tooltip/ln-tooltip.js +1 -1
  170. package/components/ln-tooltip/ln-tooltip.schema.json +86 -86
  171. package/components/ln-translations/ln-translations.js +1 -1
  172. package/components/ln-translations/ln-translations.schema.json +120 -120
  173. package/components/ln-ui-coordinator/README.md +62 -62
  174. package/components/ln-ui-coordinator/ln-ui-coordinator.js +1 -1
  175. package/components/ln-ui-coordinator/ln-ui-coordinator.schema.json +28 -28
  176. package/components/ln-ui-coordinator/src/ln-ui-coordinator.js +140 -140
  177. package/components/ln-upload/ln-upload.js +1 -1
  178. package/components/ln-upload/ln-upload.schema.json +193 -193
  179. package/components/ln-upload/src/upload-model.js +78 -78
  180. package/components/ln-validate/ln-validate.js +1 -1
  181. package/components/ln-validate/ln-validate.schema.json +50 -50
  182. package/components/ln-validate/src/validate-model.js +64 -64
  183. package/components/ln-websocket-connector/README.md +166 -166
  184. package/components/ln-websocket-connector/ln-websocket-connector.js +1 -1
  185. package/components/ln-websocket-connector/ln-websocket-connector.schema.json +29 -29
  186. package/components/ln-websocket-connector/src/ln-websocket-connector.js +283 -279
  187. package/ln-ashlar.html-data.json +15 -8
  188. package/package.json +85 -84
  189. package/theme/brand.css +73 -73
  190. package/theme/components/_confirm.scss +6 -6
  191. package/theme/components/_picklist.scss +3 -3
  192. package/theme/config/_palette.scss +274 -274
  193. package/theme/config/_theme.scss +292 -292
  194. package/theme/config/_tokens.scss +285 -285
  195. package/theme/config/mixins/_index.scss +62 -62
  196. package/theme/config/mixins/_picklist.scss +66 -66
  197. package/theme/ln-ashlar-dev.scss +66 -66
  198. package/theme/ln-ashlar-landing.scss +56 -56
  199. package/theme/ln-ashlar-theme.scss +63 -63
  200. package/theme/presentation/_bento.scss +151 -151
  201. package/theme/presentation/_cta.scss +111 -111
  202. package/theme/presentation/_effects.scss +216 -216
  203. package/theme/presentation/_features.scss +108 -108
  204. package/theme/presentation/_footer.scss +129 -129
  205. package/theme/presentation/_hero.scss +158 -158
  206. package/theme/presentation/_layout.scss +170 -170
  207. package/theme/presentation/_navbar.scss +140 -140
  208. package/theme/presentation/_pricing.scss +262 -262
  209. package/theme/presentation/_stats.scss +87 -87
  210. package/theme/presentation/_testimonials.scss +124 -124
  211. package/theme/presentation/_tokens.scss +39 -39
  212. package/theme/presentation/_typography.scss +163 -163
  213. package/web-types.json +26 -12
@@ -1,92 +1,92 @@
1
- {
2
- "$comment": "This file is partly generated. The $comment, component, generator, and each attribute's direction, sources, type, values, fallback, and description keys are owned by the generator and synchronized from JS source code. All other keys are preserved and safe to hand-author. Regenerate with `npm run sync:ln-schemas`.",
3
- "component": "ln-date",
4
- "generator": "scripts/sync-ln-schemas.mjs",
5
- "attributes": {
6
- "data-ln-date": {
7
- "direction": "author",
8
- "sources": [
9
- "ln-date-dev.scss",
10
- "src/ln-date.js"
11
- ],
12
- "type": "enum",
13
- "values": [
14
- "short",
15
- "medium",
16
- "long",
17
- "full",
18
- "iso"
19
- ],
20
- "fallback": "medium",
21
- "description": "Date display style preset or activator"
22
- },
23
- "data-ln-date-dict": {
24
- "direction": "author",
25
- "sources": [
26
- "src/ln-date.js"
27
- ],
28
- "type": "marker",
29
- "description": "Container for date translation dictionary"
30
- },
31
- "data-ln-date-dict-key": {
32
- "direction": null,
33
- "sources": [
34
- "src/ln-date.js"
35
- ],
36
- "type": "string",
37
- "description": "Dictionary key for relative time or custom date formatting"
38
- },
39
- "data-ln-date-field": {
40
- "direction": "runtime",
41
- "sources": [
42
- "src/ln-date.js"
43
- ],
44
- "type": "string",
45
- "description": "Field name mapping for date record binding"
46
- },
47
- "data-ln-date-format": {
48
- "direction": "author",
49
- "sources": [
50
- "src/ln-date.js"
51
- ],
52
- "type": "string",
53
- "description": "Custom Intl.DateTimeFormat pattern or options"
54
- },
55
- "data-ln-date-label": {
56
- "direction": "both",
57
- "sources": [
58
- "src/ln-date.js"
59
- ],
60
- "type": "string",
61
- "description": "Accessible label text for the date input"
62
- },
63
- "data-ln-date-locale": {
64
- "direction": null,
65
- "sources": [
66
- "src/ln-date.js"
67
- ],
68
- "type": "string",
69
- "description": "BCP 47 language tag override for date formatting"
70
- },
71
- "data-ln-debug": {
72
- "direction": null,
73
- "sources": [
74
- "ln-date-dev.scss"
75
- ]
76
- },
77
- "data-ln-fill-as": {
78
- "direction": "both",
79
- "sources": [
80
- "src/ln-date.js"
81
- ]
82
- },
83
- "data-ln-value": {
84
- "direction": "both",
85
- "sources": [
86
- "src/ln-date.js"
87
- ],
88
- "type": "string",
89
- "description": "Raw ISO date string or timestamp for non-time elements (td, span)"
90
- }
91
- }
92
- }
1
+ {
2
+ "$comment": "This file is partly generated. The $comment, component, generator, and each attribute's direction, sources, type, values, fallback, and description keys are owned by the generator and synchronized from JS source code. All other keys are preserved and safe to hand-author. Regenerate with `npm run sync:ln-schemas`.",
3
+ "component": "ln-date",
4
+ "generator": "scripts/sync-ln-schemas.mjs",
5
+ "attributes": {
6
+ "data-ln-date": {
7
+ "direction": "author",
8
+ "sources": [
9
+ "ln-date-dev.scss",
10
+ "src/ln-date.js"
11
+ ],
12
+ "type": "enum",
13
+ "values": [
14
+ "short",
15
+ "medium",
16
+ "long",
17
+ "full",
18
+ "iso"
19
+ ],
20
+ "fallback": "medium",
21
+ "description": "Date display style preset or activator"
22
+ },
23
+ "data-ln-date-dict": {
24
+ "direction": "author",
25
+ "sources": [
26
+ "src/ln-date.js"
27
+ ],
28
+ "type": "marker",
29
+ "description": "Container for date translation dictionary"
30
+ },
31
+ "data-ln-date-dict-key": {
32
+ "direction": null,
33
+ "sources": [
34
+ "src/ln-date.js"
35
+ ],
36
+ "type": "string",
37
+ "description": "Dictionary key for relative time or custom date formatting"
38
+ },
39
+ "data-ln-date-field": {
40
+ "direction": "runtime",
41
+ "sources": [
42
+ "src/ln-date.js"
43
+ ],
44
+ "type": "string",
45
+ "description": "Field name mapping for date record binding"
46
+ },
47
+ "data-ln-date-format": {
48
+ "direction": "author",
49
+ "sources": [
50
+ "src/ln-date.js"
51
+ ],
52
+ "type": "string",
53
+ "description": "Custom Intl.DateTimeFormat pattern or options"
54
+ },
55
+ "data-ln-date-label": {
56
+ "direction": "both",
57
+ "sources": [
58
+ "src/ln-date.js"
59
+ ],
60
+ "type": "string",
61
+ "description": "Accessible label text for the date input"
62
+ },
63
+ "data-ln-date-locale": {
64
+ "direction": null,
65
+ "sources": [
66
+ "src/ln-date.js"
67
+ ],
68
+ "type": "string",
69
+ "description": "BCP 47 language tag override for date formatting"
70
+ },
71
+ "data-ln-debug": {
72
+ "direction": null,
73
+ "sources": [
74
+ "ln-date-dev.scss"
75
+ ]
76
+ },
77
+ "data-ln-fill-as": {
78
+ "direction": "both",
79
+ "sources": [
80
+ "src/ln-date.js"
81
+ ]
82
+ },
83
+ "data-ln-value": {
84
+ "direction": "both",
85
+ "sources": [
86
+ "src/ln-date.js"
87
+ ],
88
+ "type": "string",
89
+ "description": "Raw ISO date string or timestamp for non-time elements (td, span)"
90
+ }
91
+ }
92
+ }
@@ -1,186 +1,186 @@
1
- export const KEYWORD_RE = /^(short|medium|long)(\s+datetime)?$/;
2
-
3
- export const KEYWORD_OPTIONS = {
4
- 'short': { dateStyle: 'short' },
5
- 'medium': { dateStyle: 'medium' },
6
- 'long': { dateStyle: 'long' },
7
- 'short datetime': { dateStyle: 'short', timeStyle: 'short' },
8
- 'medium datetime': { dateStyle: 'medium', timeStyle: 'short' },
9
- 'long datetime': { dateStyle: 'long', timeStyle: 'short' }
10
- };
11
-
12
- /**
13
- * Returns Intl.DateTimeFormat options if format is a recognized keyword, or null for custom patterns.
14
- * @param {string} format
15
- * @returns {Intl.DateTimeFormatOptions|null}
16
- */
17
- export function getIntlDateOptions(format) {
18
- if (!format || format === '') return { dateStyle: 'medium' };
19
- const match = String(format).trim().match(KEYWORD_RE);
20
- if (match) {
21
- return KEYWORD_OPTIONS[format.trim()];
22
- }
23
- return null;
24
- }
25
-
26
- /**
27
- * Parses user typed date strings (e.g. DD.MM.YYYY, MM/DD/YYYY, YYYY-MM-DD) into a valid Date object.
28
- * @param {string} str
29
- * @returns {Date|null}
30
- */
31
- export function parseTypedDate(str) {
32
- if (!str || typeof str !== 'string') return null;
33
- const trimmed = str.trim();
34
- if (trimmed.length < 6) return null;
35
-
36
- let sep, parts;
37
- if (trimmed.indexOf('.') !== -1) {
38
- sep = '.';
39
- parts = trimmed.split('.');
40
- } else if (trimmed.indexOf('/') !== -1) {
41
- sep = '/';
42
- parts = trimmed.split('/');
43
- } else if (trimmed.indexOf('-') !== -1) {
44
- sep = '-';
45
- parts = trimmed.split('-');
46
- } else {
47
- return null;
48
- }
49
-
50
- if (parts.length !== 3) return null;
51
- const nums = [];
52
- for (let i = 0; i < 3; i++) {
53
- const n = parseInt(parts[i], 10);
54
- if (isNaN(n)) return null;
55
- nums.push(n);
56
- }
57
-
58
- let day, month, year;
59
- if (sep === '.') {
60
- day = nums[0];
61
- month = nums[1];
62
- year = nums[2];
63
- } else if (sep === '/') {
64
- month = nums[0];
65
- day = nums[1];
66
- year = nums[2];
67
- } else {
68
- if (parts[0].length === 4) {
69
- year = nums[0];
70
- month = nums[1];
71
- day = nums[2];
72
- } else {
73
- day = nums[0];
74
- month = nums[1];
75
- year = nums[2];
76
- }
77
- }
78
-
79
- if (year < 100) {
80
- year += (year < 50) ? 2000 : 1900;
81
- }
82
-
83
- const date = new Date(year, month - 1, day);
84
- if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
85
- return null;
86
- }
87
- return date;
88
- }
89
-
90
- /**
91
- * Formats a Date object using a custom pattern with token replacements.
92
- * @param {Date} date
93
- * @param {string} pattern Pattern with tokens (yyyy, yy, MMMM, MMM, MM, M, dd, d, HH, mm)
94
- * @param {string} [locale]
95
- * @param {object} [fallback] Custom locale fallback dictionary
96
- * @returns {string}
97
- */
98
- export function formatCustomDate(date, pattern, locale, fallback) {
99
- if (!date || !(date instanceof Date) || isNaN(date.getTime())) return '';
100
- if (!pattern || typeof pattern !== 'string') return '';
101
-
102
- const day = date.getDate();
103
- const month = date.getMonth();
104
- const year = date.getFullYear();
105
- const hours = date.getHours();
106
- const minutes = date.getMinutes();
107
-
108
- let mmmmVal, mmmVal;
109
- const langPrefix = (locale || '').toLowerCase().split('-')[0];
110
-
111
- let isFallbackNeeded = false;
112
- try {
113
- const fmt = new Intl.DateTimeFormat(locale, { month: 'long' });
114
- const resolvedLocale = fmt.resolvedOptions().locale.toLowerCase().split('-')[0];
115
- isFallbackNeeded = Boolean(fallback && resolvedLocale !== langPrefix);
116
- } catch (e) {
117
- isFallbackNeeded = Boolean(fallback);
118
- }
119
-
120
- if (isFallbackNeeded && fallback && fallback.monthsLong) {
121
- mmmmVal = fallback.monthsLong[month];
122
- } else {
123
- try {
124
- mmmmVal = new Intl.DateTimeFormat(locale, { month: 'long' }).format(date);
125
- } catch (e) {
126
- mmmmVal = String(month + 1);
127
- }
128
- }
129
-
130
- if (isFallbackNeeded && fallback && fallback.monthsShort) {
131
- mmmVal = fallback.monthsShort[month];
132
- } else {
133
- try {
134
- mmmVal = new Intl.DateTimeFormat(locale, { month: 'short' }).format(date);
135
- } catch (e) {
136
- mmmVal = String(month + 1);
137
- }
138
- }
139
-
140
- const tokens = {
141
- 'yyyy': String(year),
142
- 'yy': String(year).slice(-2),
143
- 'MMMM': mmmmVal,
144
- 'MMM': mmmVal,
145
- 'MM': String(month + 1).padStart(2, '0'),
146
- 'M': String(month + 1),
147
- 'dd': String(day).padStart(2, '0'),
148
- 'd': String(day),
149
- 'HH': String(hours).padStart(2, '0'),
150
- 'mm': String(minutes).padStart(2, '0')
151
- };
152
-
153
- return pattern.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d|HH|mm/g, function (m) {
154
- return tokens[m] !== undefined ? tokens[m] : m;
155
- });
156
- }
157
-
158
- /**
159
- * Formats a date value using either standard Intl options or a custom pattern.
160
- * @param {Date} date
161
- * @param {string} [format='medium']
162
- * @param {string} [locale]
163
- * @param {object} [fallback]
164
- * @returns {string}
165
- */
166
- export function formatDateValue(date, format, locale, fallback) {
167
- if (!date || !(date instanceof Date) || isNaN(date.getTime())) return '';
168
-
169
- const intlOptions = getIntlDateOptions(format);
170
- if (intlOptions) {
171
- try {
172
- const formatter = new Intl.DateTimeFormat(locale, intlOptions);
173
- const langPrefix = (locale || '').toLowerCase().split('-')[0];
174
- const resolvedLocale = formatter.resolvedOptions().locale.toLowerCase().split('-')[0];
175
-
176
- if (fallback && resolvedLocale !== langPrefix) {
177
- return formatCustomDate(date, 'dd.MM.yyyy', locale, fallback);
178
- }
179
- return formatter.format(date);
180
- } catch (e) {
181
- return formatCustomDate(date, 'dd.MM.yyyy', locale, fallback);
182
- }
183
- }
184
-
185
- return formatCustomDate(date, format || 'dd.MM.yyyy', locale, fallback);
186
- }
1
+ export const KEYWORD_RE = /^(short|medium|long)(\s+datetime)?$/;
2
+
3
+ export const KEYWORD_OPTIONS = {
4
+ 'short': { dateStyle: 'short' },
5
+ 'medium': { dateStyle: 'medium' },
6
+ 'long': { dateStyle: 'long' },
7
+ 'short datetime': { dateStyle: 'short', timeStyle: 'short' },
8
+ 'medium datetime': { dateStyle: 'medium', timeStyle: 'short' },
9
+ 'long datetime': { dateStyle: 'long', timeStyle: 'short' }
10
+ };
11
+
12
+ /**
13
+ * Returns Intl.DateTimeFormat options if format is a recognized keyword, or null for custom patterns.
14
+ * @param {string} format
15
+ * @returns {Intl.DateTimeFormatOptions|null}
16
+ */
17
+ export function getIntlDateOptions(format) {
18
+ if (!format || format === '') return { dateStyle: 'medium' };
19
+ const match = String(format).trim().match(KEYWORD_RE);
20
+ if (match) {
21
+ return KEYWORD_OPTIONS[format.trim()];
22
+ }
23
+ return null;
24
+ }
25
+
26
+ /**
27
+ * Parses user typed date strings (e.g. DD.MM.YYYY, MM/DD/YYYY, YYYY-MM-DD) into a valid Date object.
28
+ * @param {string} str
29
+ * @returns {Date|null}
30
+ */
31
+ export function parseTypedDate(str) {
32
+ if (!str || typeof str !== 'string') return null;
33
+ const trimmed = str.trim();
34
+ if (trimmed.length < 6) return null;
35
+
36
+ let sep, parts;
37
+ if (trimmed.indexOf('.') !== -1) {
38
+ sep = '.';
39
+ parts = trimmed.split('.');
40
+ } else if (trimmed.indexOf('/') !== -1) {
41
+ sep = '/';
42
+ parts = trimmed.split('/');
43
+ } else if (trimmed.indexOf('-') !== -1) {
44
+ sep = '-';
45
+ parts = trimmed.split('-');
46
+ } else {
47
+ return null;
48
+ }
49
+
50
+ if (parts.length !== 3) return null;
51
+ const nums = [];
52
+ for (let i = 0; i < 3; i++) {
53
+ const n = parseInt(parts[i], 10);
54
+ if (isNaN(n)) return null;
55
+ nums.push(n);
56
+ }
57
+
58
+ let day, month, year;
59
+ if (sep === '.') {
60
+ day = nums[0];
61
+ month = nums[1];
62
+ year = nums[2];
63
+ } else if (sep === '/') {
64
+ month = nums[0];
65
+ day = nums[1];
66
+ year = nums[2];
67
+ } else {
68
+ if (parts[0].length === 4) {
69
+ year = nums[0];
70
+ month = nums[1];
71
+ day = nums[2];
72
+ } else {
73
+ day = nums[0];
74
+ month = nums[1];
75
+ year = nums[2];
76
+ }
77
+ }
78
+
79
+ if (year < 100) {
80
+ year += (year < 50) ? 2000 : 1900;
81
+ }
82
+
83
+ const date = new Date(year, month - 1, day);
84
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
85
+ return null;
86
+ }
87
+ return date;
88
+ }
89
+
90
+ /**
91
+ * Formats a Date object using a custom pattern with token replacements.
92
+ * @param {Date} date
93
+ * @param {string} pattern Pattern with tokens (yyyy, yy, MMMM, MMM, MM, M, dd, d, HH, mm)
94
+ * @param {string} [locale]
95
+ * @param {object} [fallback] Custom locale fallback dictionary
96
+ * @returns {string}
97
+ */
98
+ export function formatCustomDate(date, pattern, locale, fallback) {
99
+ if (!date || !(date instanceof Date) || isNaN(date.getTime())) return '';
100
+ if (!pattern || typeof pattern !== 'string') return '';
101
+
102
+ const day = date.getDate();
103
+ const month = date.getMonth();
104
+ const year = date.getFullYear();
105
+ const hours = date.getHours();
106
+ const minutes = date.getMinutes();
107
+
108
+ let mmmmVal, mmmVal;
109
+ const langPrefix = (locale || '').toLowerCase().split('-')[0];
110
+
111
+ let isFallbackNeeded = false;
112
+ try {
113
+ const fmt = new Intl.DateTimeFormat(locale, { month: 'long' });
114
+ const resolvedLocale = fmt.resolvedOptions().locale.toLowerCase().split('-')[0];
115
+ isFallbackNeeded = Boolean(fallback && resolvedLocale !== langPrefix);
116
+ } catch (e) {
117
+ isFallbackNeeded = Boolean(fallback);
118
+ }
119
+
120
+ if (isFallbackNeeded && fallback && fallback.monthsLong) {
121
+ mmmmVal = fallback.monthsLong[month];
122
+ } else {
123
+ try {
124
+ mmmmVal = new Intl.DateTimeFormat(locale, { month: 'long' }).format(date);
125
+ } catch (e) {
126
+ mmmmVal = String(month + 1);
127
+ }
128
+ }
129
+
130
+ if (isFallbackNeeded && fallback && fallback.monthsShort) {
131
+ mmmVal = fallback.monthsShort[month];
132
+ } else {
133
+ try {
134
+ mmmVal = new Intl.DateTimeFormat(locale, { month: 'short' }).format(date);
135
+ } catch (e) {
136
+ mmmVal = String(month + 1);
137
+ }
138
+ }
139
+
140
+ const tokens = {
141
+ 'yyyy': String(year),
142
+ 'yy': String(year).slice(-2),
143
+ 'MMMM': mmmmVal,
144
+ 'MMM': mmmVal,
145
+ 'MM': String(month + 1).padStart(2, '0'),
146
+ 'M': String(month + 1),
147
+ 'dd': String(day).padStart(2, '0'),
148
+ 'd': String(day),
149
+ 'HH': String(hours).padStart(2, '0'),
150
+ 'mm': String(minutes).padStart(2, '0')
151
+ };
152
+
153
+ return pattern.replace(/yyyy|yy|MMMM|MMM|MM|M|dd|d|HH|mm/g, function (m) {
154
+ return tokens[m] !== undefined ? tokens[m] : m;
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Formats a date value using either standard Intl options or a custom pattern.
160
+ * @param {Date} date
161
+ * @param {string} [format='medium']
162
+ * @param {string} [locale]
163
+ * @param {object} [fallback]
164
+ * @returns {string}
165
+ */
166
+ export function formatDateValue(date, format, locale, fallback) {
167
+ if (!date || !(date instanceof Date) || isNaN(date.getTime())) return '';
168
+
169
+ const intlOptions = getIntlDateOptions(format);
170
+ if (intlOptions) {
171
+ try {
172
+ const formatter = new Intl.DateTimeFormat(locale, intlOptions);
173
+ const langPrefix = (locale || '').toLowerCase().split('-')[0];
174
+ const resolvedLocale = formatter.resolvedOptions().locale.toLowerCase().split('-')[0];
175
+
176
+ if (fallback && resolvedLocale !== langPrefix) {
177
+ return formatCustomDate(date, 'dd.MM.yyyy', locale, fallback);
178
+ }
179
+ return formatter.format(date);
180
+ } catch (e) {
181
+ return formatCustomDate(date, 'dd.MM.yyyy', locale, fallback);
182
+ }
183
+ }
184
+
185
+ return formatCustomDate(date, format || 'dd.MM.yyyy', locale, fallback);
186
+ }