@carbon/utilities 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +37 -0
  2. package/es/carousel/index.d.ts +2 -0
  3. package/es/carousel/index.js +3 -1
  4. package/es/chunk-BYypO7fO.js +18 -0
  5. package/es/chunk-Bzxox1sl.d.ts +48 -0
  6. package/es/chunk-CYAX4TFi.js +80 -0
  7. package/es/chunk-Ci2WlFE4.js +437 -0
  8. package/es/chunk-DPUOAfLB.d.ts +55 -0
  9. package/{types/datePartsOrder/datePartsOrder.d.ts → es/datePartsOrder/index.d.ts} +6 -4
  10. package/es/datePartsOrder/index.js +21 -1
  11. package/es/dateTimeFormat/index.d.ts +9 -0
  12. package/es/dateTimeFormat/index.js +16 -1
  13. package/{types/documentLang/documentLang.d.ts → es/documentLang/index.d.ts} +5 -3
  14. package/es/documentLang/index.js +69 -1
  15. package/es/index.d.ts +8 -0
  16. package/es/index.js +10 -1
  17. package/es/makeDraggable/index.d.ts +47 -0
  18. package/es/makeDraggable/index.js +148 -1
  19. package/es/overflowHandler/index.d.ts +104 -0
  20. package/es/overflowHandler/index.js +95 -1
  21. package/lib/carousel/index.js +4 -1
  22. package/lib/chunk-C5VBwGBG.js +443 -0
  23. package/lib/chunk-Dc0mzKQx.js +107 -0
  24. package/lib/datePartsOrder/index.js +23 -1
  25. package/lib/dateTimeFormat/index.js +17 -1
  26. package/lib/documentLang/index.js +72 -1
  27. package/lib/index.js +24 -1
  28. package/lib/makeDraggable/index.js +150 -1
  29. package/lib/overflowHandler/index.js +99 -1
  30. package/package.json +29 -12
  31. package/scss/carousel/_carousel.scss +34 -2
  32. package/es/carousel/carousel.js +0 -1
  33. package/es/carousel/swipeEvents.js +0 -1
  34. package/es/carousel/types.js +0 -0
  35. package/es/datePartsOrder/datePartsOrder.js +0 -1
  36. package/es/dateTimeFormat/absolute.js +0 -1
  37. package/es/dateTimeFormat/relative.js +0 -1
  38. package/es/documentLang/documentLang.js +0 -1
  39. package/es/makeDraggable/makeDraggable.js +0 -1
  40. package/es/overflowHandler/overflowHandler.js +0 -1
  41. package/lib/carousel/carousel.js +0 -1
  42. package/lib/carousel/swipeEvents.js +0 -1
  43. package/lib/carousel/types.js +0 -1
  44. package/lib/datePartsOrder/datePartsOrder.js +0 -1
  45. package/lib/dateTimeFormat/absolute.js +0 -1
  46. package/lib/dateTimeFormat/relative.js +0 -1
  47. package/lib/documentLang/documentLang.js +0 -1
  48. package/lib/makeDraggable/makeDraggable.js +0 -1
  49. package/lib/overflowHandler/overflowHandler.js +0 -1
  50. package/types/carousel/carousel.d.ts +0 -14
  51. package/types/carousel/index.d.ts +0 -8
  52. package/types/carousel/swipeEvents.d.ts +0 -9
  53. package/types/carousel/types.d.ts +0 -36
  54. package/types/datePartsOrder/index.d.ts +0 -7
  55. package/types/dateTimeFormat/absolute.d.ts +0 -30
  56. package/types/dateTimeFormat/index.d.ts +0 -12
  57. package/types/dateTimeFormat/relative.d.ts +0 -10
  58. package/types/documentLang/index.d.ts +0 -7
  59. package/types/index.d.ts +0 -13
  60. package/types/makeDraggable/index.d.ts +0 -7
  61. package/types/makeDraggable/makeDraggable.d.ts +0 -38
  62. package/types/overflowHandler/index.d.ts +0 -7
  63. package/types/overflowHandler/overflowHandler.d.ts +0 -85
@@ -0,0 +1,443 @@
1
+
2
+ //#region src/carousel/defs.ts
3
+ /**
4
+ * Copyright IBM Corp. 2026
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const translationIds = {
10
+ "carbon.carousel.item": "carbon.carousel.item",
11
+ "carbon.carousel.of": "carbon.carousel.of"
12
+ };
13
+
14
+ //#endregion
15
+ //#region src/carousel/swipeEvents.ts
16
+ /**
17
+ * Registers swipe event handlers for a carousel element.
18
+ * Handles touch, mouse, and wheel events for navigation.
19
+ * @param {HTMLElement} carousel - The carousel element to attach event listeners to.
20
+ * @param {() => void} next - Callback function to execute when swiping right.
21
+ * @param {() => void} prev - Callback function to execute when swiping left.
22
+ * @param {boolean} destroy - If true, removes existing event listeners before adding new ones.
23
+ */
24
+ const registerSwipeEvents = (carousel, next, prev, destroy) => {
25
+ const minSwipeDistance = 50;
26
+ let touchStartX = null;
27
+ let touchEndX = null;
28
+ let lastScrollTime = 0;
29
+ const scrollCooldown = 400;
30
+ let isMouseDown = false;
31
+ let mouseStartX = null;
32
+ let mouseEndX = null;
33
+ const touchStartHandler = (e) => {
34
+ touchStartX = e.touches[0].clientX;
35
+ };
36
+ const touchMoveHandler = (e) => {
37
+ touchEndX = e.touches[0].clientX;
38
+ };
39
+ const touchEndHandler = () => {
40
+ if (touchStartX !== null && touchEndX !== null) {
41
+ const distance = touchStartX - touchEndX;
42
+ if (Math.abs(distance) > minSwipeDistance) if (distance > 0) next();
43
+ else prev();
44
+ }
45
+ touchStartX = null;
46
+ touchEndX = null;
47
+ };
48
+ const mouseDownHandler = (e) => {
49
+ isMouseDown = true;
50
+ mouseStartX = e.clientX;
51
+ };
52
+ const mouseMoveHandler = (e) => {
53
+ if (!isMouseDown) return;
54
+ mouseEndX = e.clientX;
55
+ };
56
+ const mouseUpHandler = () => {
57
+ if (isMouseDown && mouseStartX !== null && mouseEndX !== null) {
58
+ const distance = mouseStartX - mouseEndX;
59
+ if (Math.abs(distance) > minSwipeDistance) if (distance > 0) next();
60
+ else prev();
61
+ }
62
+ isMouseDown = false;
63
+ mouseStartX = null;
64
+ mouseEndX = null;
65
+ };
66
+ const wheelHandler = (e) => {
67
+ const now = Date.now();
68
+ if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 20) {
69
+ e.preventDefault();
70
+ if (now - lastScrollTime < scrollCooldown) return;
71
+ if (e.deltaX > 0) next();
72
+ else prev();
73
+ lastScrollTime = now;
74
+ }
75
+ };
76
+ if (destroy) {
77
+ carousel.removeEventListener("touchstart", touchStartHandler);
78
+ carousel.removeEventListener("touchmove", touchMoveHandler);
79
+ carousel.removeEventListener("touchend", touchEndHandler);
80
+ carousel.removeEventListener("mousedown", mouseDownHandler);
81
+ carousel.removeEventListener("mousemove", mouseMoveHandler);
82
+ carousel.removeEventListener("mouseup", mouseUpHandler);
83
+ carousel.removeEventListener("wheel", wheelHandler);
84
+ }
85
+ carousel.addEventListener("touchstart", touchStartHandler);
86
+ carousel.addEventListener("touchmove", touchMoveHandler);
87
+ carousel.addEventListener("touchend", touchEndHandler);
88
+ carousel.addEventListener("mousedown", mouseDownHandler);
89
+ carousel.addEventListener("mousemove", mouseMoveHandler);
90
+ carousel.addEventListener("mouseup", mouseUpHandler);
91
+ carousel.addEventListener("wheel", wheelHandler);
92
+ };
93
+
94
+ //#endregion
95
+ //#region src/carousel/carousel.ts
96
+ const defaultTranslations = {
97
+ [translationIds["carbon.carousel.item"]]: "Item",
98
+ [translationIds["carbon.carousel.of"]]: "of"
99
+ };
100
+ /**
101
+ * Default translation function
102
+ */
103
+ const defaultTranslateWithId = (messageId) => {
104
+ return defaultTranslations[messageId];
105
+ };
106
+ /**
107
+ * Initializes a carousel with the given configuration.
108
+ * @param carouselContainer - The HTMLElement representing the carousel container.
109
+ * @param config - Optional configuration object.
110
+ * @returns An object containing methods to control the carousel.
111
+ */
112
+ const initCarousel = (carouselContainer, config) => {
113
+ const prefix = "carousel";
114
+ let viewIndexStack = [0];
115
+ let previousViewIndexStack = [0];
116
+ const refs = {};
117
+ const carouselListeners = /* @__PURE__ */ new WeakMap();
118
+ const minHeight = 4;
119
+ const { onViewChangeStart, onViewChangeEnd, excludeSwipeSupport, useMaxHeight, translateWithId: t = defaultTranslateWithId } = config || {};
120
+ /**
121
+ * Registers an HTMLElement at a specific index in the refs array.
122
+ *
123
+ * @param index - The index at which to register the HTMLElement.
124
+ * @param ref - The HTMLElement to register.
125
+ *
126
+ * @example
127
+ * registerRef(0, document.getElementById('myElement'));
128
+ */
129
+ const registerRef = (index, ref) => {
130
+ refs[index] = ref;
131
+ };
132
+ const getLiveRegion = () => carouselContainer.querySelector(`.${prefix}__live-region`);
133
+ const getWrapper = () => carouselContainer.querySelector(`.${prefix}__itemsWrapper`);
134
+ const updateLiveRegion = (idx) => {
135
+ const div = getLiveRegion();
136
+ if (div) div.textContent = `${t("carbon.carousel.item")} ${idx} ${t("carbon.carousel.of")} ${getCarouselItems()?.length}`;
137
+ };
138
+ const syncLiveRegionWithActiveView = () => {
139
+ updateLiveRegion(viewIndexStack[0] + 1);
140
+ };
141
+ const createLiveRegion = () => {
142
+ const childCount = getCarouselItems()?.length;
143
+ if (getLiveRegion() || !childCount) return;
144
+ const div = document.createElement("div");
145
+ div.setAttribute("aria-live", "polite");
146
+ div.setAttribute("aria-atomic", "true");
147
+ div.setAttribute("class", `${prefix}__live-region`);
148
+ div.textContent = `${t("carbon.carousel.item")} 1 ${t("carbon.carousel.of")} ${childCount}`;
149
+ carouselContainer.appendChild(div);
150
+ };
151
+ /**
152
+ * Wraps all child elements of a given container into a new div with the specified class.
153
+ * If an element with the specified class already exists as a child of the container, the function does nothing.
154
+ */
155
+ const wrapAllItems = () => {
156
+ if (getWrapper()) return;
157
+ const wrapper = document.createElement("div");
158
+ wrapper.classList.add(`${prefix}__itemsWrapper`);
159
+ while (carouselContainer.firstChild) wrapper.appendChild(carouselContainer.firstChild);
160
+ carouselContainer.appendChild(wrapper);
161
+ };
162
+ const getHistory = () => {
163
+ return viewIndexStack.reduce((history, id) => {
164
+ const elem = refs[id];
165
+ if (elem) history.push({
166
+ id,
167
+ elem
168
+ });
169
+ return history;
170
+ }, []);
171
+ };
172
+ /**
173
+ * Retrieves the current carousel response based on the view index stack and reference objects.
174
+ * @returns {CarouselResponse} - An object containing carousel response details.
175
+ */
176
+ const getCallbackResponse = () => {
177
+ const totalRefs = Object.keys(refs).length;
178
+ const lastElementRef = refs[totalRefs - 1];
179
+ const historicalData = getHistory();
180
+ return {
181
+ currentIndex: viewIndexStack[0],
182
+ lastIndex: parseInt(lastElementRef?.dataset.index || viewIndexStack[0].toString(), 10),
183
+ totalViews: totalRefs,
184
+ historyStack: historicalData
185
+ };
186
+ };
187
+ /**
188
+ * Handles the start of a transition in the application.
189
+ * This function is responsible for capturing the current state of the view index stack
190
+ * and invoking a callback function if it exists.
191
+ *
192
+ * @function handleTransitionStart
193
+ * @returns {void}
194
+ */
195
+ const handleTransitionStart = () => {
196
+ previousViewIndexStack = [...viewIndexStack];
197
+ const callbackData = getCallbackResponse();
198
+ onViewChangeStart?.(callbackData);
199
+ };
200
+ /**
201
+ * Handles the 'transitionend' event for a given element.
202
+ * This function checks if the element has a 'data-index' attribute and if its value matches the current view index.
203
+ * If both conditions are met, it calls the 'onViewChangeEnd' callback with the response from 'getCallbackResponse'.
204
+ *
205
+ * @param el - The element to handle the 'transitionend' event for.
206
+ */
207
+ const handleTransitionEnd = (el) => {
208
+ if (!el) return;
209
+ const tmpElementIndex = el.dataset.index;
210
+ if (tmpElementIndex && viewIndexStack[0] === parseInt(tmpElementIndex, 10)) {
211
+ const callbackData = getCallbackResponse();
212
+ onViewChangeEnd?.(callbackData);
213
+ }
214
+ };
215
+ /**
216
+ * A utility function to sanitize an index value.
217
+ * This function ensures the index stays within the bounds of the refs array.
218
+ *
219
+ * @param idx - The index to be sanitized.
220
+ * @returns - The sanitized index.
221
+ */
222
+ const sanitizeIndex = (idx) => {
223
+ const floorVal = 0;
224
+ const ceilVal = Object.keys(refs).length - 1;
225
+ return Math.max(floorVal, Math.min(idx, ceilVal));
226
+ };
227
+ /**
228
+ * Handles the 'transitionend' event for a given element.
229
+ * This function checks if the element has a 'data-index' attribute and if its value matches the current view index.
230
+ * If both conditions are met, it calls the 'onViewChangeEnd' callback with the response from 'getCallbackResponse'.
231
+ * @returns {void}
232
+ */
233
+ const transitionToViewIndex = (idx) => {
234
+ const sanitizedIndex = sanitizeIndex(idx);
235
+ if (viewIndexStack[0] !== sanitizedIndex) {
236
+ handleTransitionStart();
237
+ viewIndexStack = [sanitizedIndex, ...viewIndexStack];
238
+ syncLiveRegionWithActiveView();
239
+ performAnimation(false);
240
+ }
241
+ };
242
+ const transitionComplete = (ref) => {
243
+ handleTransitionEnd(ref);
244
+ };
245
+ /**
246
+ * Attaches class names to an HTMLElement based on given conditions.
247
+ *
248
+ * @param viewItem - The HTML element to which class names will be added.
249
+ * @param isInViewStack - Indicates if the view item is in the view stack.
250
+ * @param isActive - Indicates if the view item is active.
251
+ * @param isBeingRecycledOut - Indicates if the view item is being recycled out.
252
+ * @param isBeingRecycledIn - Indicates if the view item is being recycled in.
253
+ */
254
+ const attachClassNames = (viewItem, isInViewStack, isActive, isBeingRecycledOut, isBeingRecycledIn) => {
255
+ viewItem.classList.add(`${prefix}__view`);
256
+ viewItem.classList.toggle(`${prefix}__view-in-stack`, isInViewStack && !isActive);
257
+ viewItem.classList.toggle(`${prefix}__view-active`, isInViewStack && isActive);
258
+ if (isBeingRecycledIn && !isBeingRecycledOut) viewItem.classList.add(`${prefix}__view-recycle-in`);
259
+ if (!isBeingRecycledIn && isBeingRecycledOut) viewItem.classList.add(`${prefix}__view-recycle-out`);
260
+ if (isActive) {
261
+ viewItem.removeAttribute("aria-hidden");
262
+ viewItem.removeAttribute("inert");
263
+ } else {
264
+ viewItem.setAttribute("aria-hidden", "true");
265
+ viewItem.setAttribute("inert", "");
266
+ }
267
+ };
268
+ const removeReCycleClasses = (viewItem) => {
269
+ viewItem.classList.remove(`${prefix}__view-recycle-in`, `${prefix}__view-recycle-out`);
270
+ };
271
+ const remToPx = (rem) => {
272
+ return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
273
+ };
274
+ /**
275
+ * Updates the height of the items wrapper in a carousel based on the smallest item height and a threshold height.
276
+ * This function ensures that the items wrapper does not have a height smaller than the threshold, adjusting the item height if necessary.
277
+ *
278
+ * @param itemHeightSmallest - The smallest height of an item in pixels.
279
+ */
280
+ const updateHeightForWrapper = (itemHeightSmallest) => {
281
+ const thresholdHeight = remToPx(minHeight);
282
+ if (carouselContainer.clientHeight < thresholdHeight) {
283
+ if (itemHeightSmallest < thresholdHeight) itemHeightSmallest = thresholdHeight;
284
+ const itemsWrapper = getWrapper();
285
+ if (itemsWrapper) itemsWrapper.style.blockSize = `${itemHeightSmallest}px`;
286
+ }
287
+ };
288
+ /**
289
+ * Performs animation on view items based on their state in the view index stack.
290
+ * @param isInitial - A flag indicating if this is the initial animation.
291
+ */
292
+ const performAnimation = (isInitial) => {
293
+ const viewItems = getCarouselItems();
294
+ if (!viewItems) return;
295
+ let itemHeightSmallest = 0;
296
+ let itemHeightMaximum = 0;
297
+ Array.from(viewItems).forEach((viewItem, index) => {
298
+ const stackIndex = viewIndexStack.findIndex((idx) => idx === index);
299
+ const stackIndexInstanceCount = previousViewIndexStack.filter((viIdx) => viIdx === index).length;
300
+ const isBeingRecycledOut = previousViewIndexStack.length > viewIndexStack.length && previousViewIndexStack[0] === index && stackIndexInstanceCount > 0;
301
+ const isBeingRecycledIn = previousViewIndexStack.length < viewIndexStack.length && previousViewIndexStack[0] === index && stackIndexInstanceCount > 0;
302
+ attachClassNames(viewItem, stackIndex > -1, index === viewIndexStack[0], isBeingRecycledOut, isBeingRecycledIn);
303
+ if (isInitial) {
304
+ registerRef(index, viewItem);
305
+ setTimeout(() => {
306
+ if (useMaxHeight) {
307
+ const heights = Array.from(viewItems).map((viewItem) => viewItem.scrollHeight);
308
+ itemHeightMaximum = Math.max(...heights);
309
+ viewItem.style.position = "absolute";
310
+ updateHeightForWrapper(itemHeightMaximum);
311
+ } else {
312
+ if (!itemHeightSmallest || viewItem.offsetHeight < itemHeightSmallest && itemHeightSmallest > remToPx(minHeight)) itemHeightSmallest = viewItem.offsetHeight;
313
+ viewItem.style.position = "absolute";
314
+ updateHeightForWrapper(itemHeightSmallest);
315
+ }
316
+ });
317
+ const listener = (e) => {
318
+ removeReCycleClasses(viewItem);
319
+ if (e.target === refs[viewIndexStack[0]]) transitionComplete(viewItem);
320
+ };
321
+ carouselListeners.set(viewItem, listener);
322
+ viewItem.addEventListener("animationend", listener);
323
+ viewItem.addEventListener("transitionend", listener);
324
+ viewItem.setAttribute("data-index", index.toString());
325
+ }
326
+ });
327
+ if (isInitial) handleTransitionEnd(Array.from(viewItems)[0]);
328
+ };
329
+ /**
330
+ * A utility function to navigate to the next view in the stack.
331
+ * This function increments the current view index and transitions to the new index.
332
+ *
333
+ * @returns {void} - This function does not return any value.
334
+ */
335
+ const navigateNext = () => {
336
+ transitionToViewIndex(viewIndexStack[0] + 1);
337
+ };
338
+ /**
339
+ * Navigates to the previous view in the view stack.
340
+ * @function navigatePrev
341
+ * @description This function checks if there is a previous view in the stack. If so, it triggers a transition start, removes the current view from the stack, and performs an animation to transition to the previous view.
342
+ * @returns {void} - This function does not return a value.
343
+ */
344
+ const navigatePrev = () => {
345
+ if (viewIndexStack.length - 1 >= 1) {
346
+ handleTransitionStart();
347
+ viewIndexStack = viewIndexStack.slice(1);
348
+ syncLiveRegionWithActiveView();
349
+ performAnimation(false);
350
+ }
351
+ };
352
+ /**
353
+ * A function that transitions the view to a specified index.
354
+ *
355
+ * @param index - The index to transition to.
356
+ * @returns - This function does not return a value.
357
+ */
358
+ const goToIndex = (index) => {
359
+ transitionToViewIndex(index);
360
+ };
361
+ /**
362
+ * Retrieves the currently active item and its index from the view index stack and references.
363
+ * @returns An object containing the index and the corresponding item reference.
364
+ */
365
+ const getActiveItem = () => {
366
+ return {
367
+ index: viewIndexStack[0],
368
+ item: refs[viewIndexStack[0]]
369
+ };
370
+ };
371
+ /**
372
+ * Resets the view index stack and performs an animation.
373
+ *
374
+ * @returns {void}
375
+ */
376
+ const reset = () => {
377
+ const viewItems = getCarouselItems();
378
+ if (!viewItems) return;
379
+ Array.from(viewItems).forEach((viewItem) => {
380
+ removeReCycleClasses(viewItem);
381
+ });
382
+ previousViewIndexStack = [0];
383
+ viewIndexStack = [0];
384
+ performAnimation(false);
385
+ syncLiveRegionWithActiveView();
386
+ };
387
+ /**
388
+ * Removes event listeners for 'animationend' and 'transitionend' events from all elements with references stored in the `refs` object.
389
+ * Also registers swipe events if `excludeSwipeSupport` is false.
390
+ */
391
+ const destroyEvents = () => {
392
+ Object.values(refs).forEach((el) => {
393
+ if (!el) return;
394
+ const listener = carouselListeners.get(el);
395
+ if (listener) {
396
+ el.removeEventListener("animationend", listener);
397
+ el.removeEventListener("transitionend", listener);
398
+ }
399
+ carouselListeners.delete(el);
400
+ });
401
+ if (!excludeSwipeSupport) registerSwipeEvents(carouselContainer, navigateNext, navigatePrev, true);
402
+ };
403
+ /**
404
+ * Retrieves carousel items from a given container element.
405
+ * If the container has a 'slot' element, it fetches all elements assigned to that slot.
406
+ * Otherwise, it fetches all direct children of the container.
407
+ *
408
+ * @returns An array of HTMLElements representing the carousel items or nothing if a container is not found.
409
+ *
410
+ * @example
411
+ * const carouselItems = getCarouselItems();
412
+ * console.log(carouselItems); // Logs the carousel items as HTMLElements
413
+ */
414
+ const getCarouselItems = () => {
415
+ const container = getWrapper();
416
+ if (!container) return;
417
+ const slot = container.querySelector("slot");
418
+ if (slot instanceof HTMLSlotElement) return slot.assignedElements({ flatten: true }).filter((item) => item instanceof HTMLElement);
419
+ return Array.from(container.children).filter((item) => item instanceof HTMLElement);
420
+ };
421
+ wrapAllItems();
422
+ createLiveRegion();
423
+ carouselContainer.classList.add(`${prefix}__view-stack`);
424
+ performAnimation(true);
425
+ if (!excludeSwipeSupport) registerSwipeEvents(carouselContainer, navigateNext, navigatePrev, false);
426
+ return {
427
+ next: navigateNext,
428
+ prev: navigatePrev,
429
+ reset,
430
+ goToIndex,
431
+ getActiveItem,
432
+ destroyEvents,
433
+ allViews: refs
434
+ };
435
+ };
436
+
437
+ //#endregion
438
+ Object.defineProperty(exports, 'initCarousel', {
439
+ enumerable: true,
440
+ get: function () {
441
+ return initCarousel;
442
+ }
443
+ });
@@ -0,0 +1,107 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (!no_symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+
19
+ //#region src/dateTimeFormat/relative.ts
20
+ var relative_exports = /* @__PURE__ */ __exportAll({ format: () => format$1 });
21
+ /**
22
+ * Copyright IBM Corp. 2024
23
+ *
24
+ * This source code is licensed under the Apache-2.0 license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ */
27
+ function format$1(date, options) {
28
+ const rtf = new Intl.RelativeTimeFormat(options?.locale, { style: options?.style ?? "long" });
29
+ const d = typeof date === "number" ? new Date(date) : date;
30
+ const now = Date.now();
31
+ const seconds = Math.floor((now - d.getTime()) / 1e3);
32
+ const minutes = Math.floor(seconds / 60);
33
+ const hours = Math.floor(minutes / 60);
34
+ const days = Math.floor(hours / 24);
35
+ const weeks = Math.floor(days / 7);
36
+ const months = Math.floor(weeks / 4);
37
+ const years = Math.floor(days / 365);
38
+ if (Math.abs(seconds) < 60) return new Intl.RelativeTimeFormat(options?.locale, {
39
+ numeric: "auto",
40
+ style: options?.style ?? "long"
41
+ }).format(0, "seconds");
42
+ if (Math.abs(minutes) < 60) return rtf.format(minutes * -1, "minutes");
43
+ if (Math.abs(hours) < 24) return rtf.format(hours * -1, "hours");
44
+ if (Math.abs(days) < 7) return rtf.format(days * -1, "days");
45
+ if (Math.abs(weeks) < 4) return rtf.format(weeks * -1, "weeks");
46
+ if (Math.abs(days) < 365) return rtf.format(months * -1, "months");
47
+ return rtf.format(years * -1, "years");
48
+ }
49
+
50
+ //#endregion
51
+ //#region src/dateTimeFormat/absolute.ts
52
+ var absolute_exports = /* @__PURE__ */ __exportAll({
53
+ format: () => format,
54
+ formatDate: () => formatDate,
55
+ formatRange: () => formatRange,
56
+ formatTime: () => formatTime
57
+ });
58
+ /**
59
+ * Copyright IBM Corp. 2024, 2025
60
+ *
61
+ * This source code is licensed under the Apache-2.0 license found in the
62
+ * LICENSE file in the root directory of this source tree.
63
+ */
64
+ function formatTime(date, options) {
65
+ return new Intl.DateTimeFormat(options?.locale, {
66
+ timeStyle: options?.style ?? "short",
67
+ timeZone: options?.timeZone
68
+ }).format(date);
69
+ }
70
+ function formatDate(date, options) {
71
+ return new Intl.DateTimeFormat(options?.locale, {
72
+ dateStyle: options?.style ?? "medium",
73
+ timeZone: options?.timeZone
74
+ }).format(date);
75
+ }
76
+ function format(date, options) {
77
+ const timeStyle = options?.timeStyle ?? (options?.style === "tooltip" ? "long" : options?.style) ?? "short";
78
+ const dateStyle = options?.dateStyle ?? (options?.style === "tooltip" ? "full" : options?.style) ?? "medium";
79
+ return new Intl.DateTimeFormat(options?.locale, {
80
+ timeStyle,
81
+ dateStyle,
82
+ timeZone: options?.timeZone
83
+ }).format(date);
84
+ }
85
+ function formatRange(startDate, endDate, options) {
86
+ const timeStyle = options?.timeStyle === null ? void 0 : options?.timeStyle ?? options?.style ?? "short";
87
+ const dateStyle = options?.dateStyle === null ? void 0 : options?.dateStyle ?? options?.style ?? "medium";
88
+ return new Intl.DateTimeFormat(options?.locale, {
89
+ timeStyle,
90
+ dateStyle,
91
+ timeZone: options?.timeZone
92
+ }).formatRange(startDate, endDate);
93
+ }
94
+
95
+ //#endregion
96
+ Object.defineProperty(exports, 'absolute_exports', {
97
+ enumerable: true,
98
+ get: function () {
99
+ return absolute_exports;
100
+ }
101
+ });
102
+ Object.defineProperty(exports, 'relative_exports', {
103
+ enumerable: true,
104
+ get: function () {
105
+ return relative_exports;
106
+ }
107
+ });
@@ -1 +1,23 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("./datePartsOrder"),module.exports);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/datePartsOrder/datePartsOrder.ts
4
+ const _orderCache = /* @__PURE__ */ new Map();
5
+ function getMonthYearOrder(locale) {
6
+ const cached = _orderCache.get(locale);
7
+ if (cached) return cached;
8
+ const parts = new Intl.DateTimeFormat(locale, {
9
+ year: "numeric",
10
+ month: "long"
11
+ }).formatToParts(new Date(2e3, 0, 1));
12
+ const order = parts.findIndex((p) => p.type === "month") < parts.findIndex((p) => p.type === "year") ? "month-year" : "year-month";
13
+ _orderCache.set(locale, order);
14
+ return order;
15
+ }
16
+ const isMonthFirst = (locale) => getMonthYearOrder(locale) === "month-year";
17
+ const datePartsOrder = {
18
+ getMonthYearOrder,
19
+ isMonthFirst
20
+ };
21
+
22
+ //#endregion
23
+ exports.datePartsOrder = datePartsOrder;
@@ -1 +1,17 @@
1
- "use strict";var p=Object.create;var e=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;var d=(o,t)=>{for(var r in t)e(o,r,{get:t[r],enumerable:!0})},i=(o,t,r,m)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of l(t))!c.call(o,a)&&a!==r&&e(o,a,{get:()=>t[a],enumerable:!(m=f(t,a))||m.enumerable});return o};var s=(o,t,r)=>(r=o!=null?p(b(o)):{},i(t||!o||!o.__esModule?e(r,"default",{value:o,enumerable:!0}):r,o)),n=o=>i(e({},"__esModule",{value:!0}),o);var F={};d(F,{dateTimeFormat:()=>x});module.exports=n(F);var u=s(require("./relative")),v=s(require("./absolute"));const x={relative:u,absolute:v};
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_absolute = require('../chunk-Dc0mzKQx.js');
3
+
4
+ //#region src/dateTimeFormat/index.ts
5
+ /**
6
+ * Copyright IBM Corp. 2024
7
+ *
8
+ * This source code is licensed under the Apache-2.0 license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ const dateTimeFormat = {
12
+ relative: require_absolute.relative_exports,
13
+ absolute: require_absolute.absolute_exports
14
+ };
15
+
16
+ //#endregion
17
+ exports.dateTimeFormat = dateTimeFormat;
@@ -1 +1,72 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,o,f,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of c(o))!d.call(r,e)&&e!==f&&a(r,e,{get:()=>o[e],enumerable:!(x=b(o,e))||x.enumerable});return r},t=(r,o,f)=>(p(r,o,"default"),f&&p(f,o,"default"));var g=r=>p(a({},"__esModule",{value:!0}),r);var m={};module.exports=g(m);t(m,require("./documentLang"),module.exports);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/documentLang/documentLang.ts
4
+ /**
5
+ * Copyright IBM Corp. 2025
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ const isBrowser = typeof document !== "undefined";
11
+ let currentLang = isBrowser ? document.documentElement.lang : "";
12
+ let updateScheduled = false;
13
+ let subscribers = [];
14
+ let observerInitialized = false;
15
+ /**
16
+ * Internal callback for MutationObserver to dispatch lang changes.
17
+ * debounced into a microtask, and avoiding redundant notifications.
18
+ */
19
+ function handleMutations() {
20
+ if (!isBrowser) return;
21
+ if (updateScheduled) return;
22
+ updateScheduled = true;
23
+ queueMicrotask(() => {
24
+ updateScheduled = false;
25
+ const newLang = document.documentElement.lang;
26
+ if (newLang === currentLang) return;
27
+ currentLang = newLang;
28
+ for (const callback of subscribers) callback(newLang);
29
+ });
30
+ }
31
+ /**
32
+ * Initializes a shared MutationObserver for the <html> lang attribute.
33
+ */
34
+ function initObserver() {
35
+ if (!isBrowser || observerInitialized) return;
36
+ observerInitialized = true;
37
+ new MutationObserver(handleMutations).observe(document.documentElement, {
38
+ attributes: true,
39
+ attributeFilter: ["lang"]
40
+ });
41
+ }
42
+ /**
43
+ * Retrieves the current document language. Falls back to the browser's
44
+ * `navigator.language` if the `<html>` lang attribute is empty.
45
+ *
46
+ * @returns {string} The current document language code.
47
+ */
48
+ function getDocumentLang() {
49
+ return isBrowser ? document.documentElement.lang || window.navigator.language || "" : "";
50
+ }
51
+ /**
52
+ * Subscribes to changes on the `<html>` element's `lang` attribute.
53
+ * Uses a shared MutationObserver under the hood to watch for attribute
54
+ * mutations.
55
+ *
56
+ * @param {Subscriber} callback - Invoked with the new language code whenever
57
+ * it changes.
58
+ * @returns {() => void} A function that, when called, removes this subscription
59
+ */
60
+ function subscribeDocumentLangChange(callback) {
61
+ if (!isBrowser) return () => {};
62
+ if (!observerInitialized) initObserver();
63
+ subscribers.push(callback);
64
+ return () => {
65
+ subscribers = subscribers.filter((cb) => cb !== callback);
66
+ if (subscribers.length === 0) observerInitialized = false;
67
+ };
68
+ }
69
+
70
+ //#endregion
71
+ exports.getDocumentLang = getDocumentLang;
72
+ exports.subscribeDocumentLangChange = subscribeDocumentLangChange;