@arcgis/toolkit 5.2.0-next.98 → 6.0.0-next.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.
@@ -1,5 +1,5 @@
1
- import { getSlotAssignedElements as getSlotAssignedElements$1, slotChangeGetAssignedElements as slotChangeGetAssignedElements$1, slotChangeGetAssignedNodes as slotChangeGetAssignedNodes$1, slotChangeGetTextContent as slotChangeGetTextContent$1, slotChangeHasAssignedElement as slotChangeHasAssignedElement$1, slotChangeHasAssignedNode as slotChangeHasAssignedNode$1, slotChangeHasContent as slotChangeHasContent$1, slotChangeHasTextContent as slotChangeHasTextContent$1 } from "./dom/slots.js";
2
- import { log } from "./log.js";
1
+ import { getSlotAssignedElements as getSlotAssignedElements$1, slotChangeGetAssignedElements as slotChangeGetAssignedElements$1, slotChangeGetAssignedNodes as slotChangeGetAssignedNodes$1, slotChangeGetTextContent as slotChangeGetTextContent$1, slotChangeHasAssignedElement as slotChangeHasAssignedElement$1, slotChangeHasAssignedNode as slotChangeHasAssignedNode$1, slotChangeHasContent as slotChangeHasContent$1, slotChangeHasTextContent as slotChangeHasTextContent$1 } from "../dom/slots.js";
2
+ import { log } from "../log.js";
3
3
  const allowedTags = ["arcgis-map", "arcgis-scene", "arcgis-link-chart"];
4
4
  function resolveReferenceElement$1(component, referenceElementString) {
5
5
  const referenceElement = referenceElementString ?? component.referenceElement;
@@ -187,22 +187,26 @@ const setFocus = (ref, selector = "") => {
187
187
  }
188
188
  return false;
189
189
  };
190
+ function getElementWindow(element) {
191
+ return element.ownerDocument.defaultView || window;
192
+ }
190
193
  export {
191
- getClosestElement as a,
192
- getSlotAssignedElements as b,
194
+ getElementAttribute as a,
195
+ getClosestElement as b,
193
196
  classes as c,
194
- resolveReferenceElement as d,
195
- slotChangeGetAssignedElements as e,
197
+ getSlotAssignedElements as d,
198
+ resolveReferenceElement as e,
196
199
  focusElement as f,
197
- getElementAttribute as g,
198
- slotChangeGetAssignedNodes as h,
199
- slotChangeGetTextContent as i,
200
- slotChangeHasAssignedElement as j,
201
- slotChangeHasAssignedNode as k,
202
- slotChangeHasContent as l,
203
- slotChangeHasTextContent as m,
204
- unsafeGetElementDirection as n,
200
+ getElementWindow as g,
201
+ slotChangeGetAssignedElements as h,
202
+ slotChangeGetAssignedNodes as i,
203
+ slotChangeGetTextContent as j,
204
+ slotChangeHasAssignedElement as k,
205
+ slotChangeHasAssignedNode as l,
206
+ slotChangeHasContent as m,
207
+ slotChangeHasTextContent as n,
205
208
  observeAncestorsMutation as o,
209
+ unsafeGetElementDirection as p,
206
210
  resolveReferenceElement$1 as r,
207
211
  setFocusOnElement as s,
208
212
  unsafeGetCalciteModeName as u
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Get the resolved color from a CSS custom property on an element.
3
+ *
4
+ * Resolves `light-dark()` values using the element's inherited color scheme,
5
+ * including styles in its shadow root. Returns `undefined` if the property is
6
+ * missing. The returned value is a CSS color string, not a parsed color.
7
+ *
8
+ * @public
9
+ * @param element The element on which to read the custom property.
10
+ * @param propertyName The CSS custom property containing a color.
11
+ * @returns The resolved CSS color, or `undefined` if the property is missing.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const textColor = getCssColor(element, "--app-text-color");
16
+ * const fallbackColor = getCssColor(element, "--optional-color") ?? "black";
17
+ * ```
18
+ *
19
+ * @example
20
+ * ```css
21
+ * .panel {
22
+ * color-scheme: dark;
23
+ * --panel-color: light-dark(#ffffff, #202020);
24
+ * }
25
+ * ```
26
+ * ```ts
27
+ * // Resolves to the dark color in the context of the panel.
28
+ * const panelColor = getCssColor(panel, "--panel-color");
29
+ * ```
30
+ */
31
+ export declare function getCssColor(element: Element, propertyName: string): string | undefined;
32
+ /**
33
+ * Get the effective light or dark color scheme for an element.
34
+ *
35
+ * A computed `color-scheme` containing only `light` or only `dark` takes
36
+ * precedence. If both or neither are allowed, the system color preference
37
+ * determines the result. This is a snapshot; call again after styles or the
38
+ * system preference change.
39
+ *
40
+ * @public
41
+ * @param element The element whose computed color scheme is used.
42
+ * @returns The effective color scheme.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // An element with `color-scheme: dark` returns "dark".
47
+ * const scheme = getEffectiveColorScheme(element);
48
+ * ```
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // With `color-scheme: light dark`, the preferred system scheme is returned.
53
+ * const preferredScheme = getEffectiveColorScheme(element);
54
+ * ```
55
+ */
56
+ export declare function getEffectiveColorScheme(element: Element): "dark" | "light";
@@ -0,0 +1,37 @@
1
+ import { g as getElementWindow } from "../chunks/dom.js";
2
+ function getCssColor(element, propertyName) {
3
+ const elWindow = getElementWindow(element);
4
+ const cssColor = elWindow.getComputedStyle(element).getPropertyValue(propertyName).trim();
5
+ if (!cssColor) {
6
+ return void 0;
7
+ }
8
+ if (!/light-dark\(/iu.test(cssColor)) {
9
+ return cssColor;
10
+ }
11
+ const sampleElement = element.ownerDocument.createElement("test");
12
+ Object.assign(sampleElement.style, {
13
+ color: cssColor,
14
+ display: "none"
15
+ });
16
+ if (!sampleElement.style.color) {
17
+ return cssColor;
18
+ }
19
+ (element.shadowRoot ?? element).append(sampleElement);
20
+ const color = elWindow.getComputedStyle(sampleElement).color || cssColor;
21
+ sampleElement.remove();
22
+ return color;
23
+ }
24
+ function getEffectiveColorScheme(element) {
25
+ const elWindow = getElementWindow(element);
26
+ const colorSchemes = elWindow.getComputedStyle(element).colorScheme.split(/\s+/u);
27
+ const hasDark = colorSchemes.includes("dark");
28
+ const hasLight = colorSchemes.includes("light");
29
+ if (hasDark !== hasLight) {
30
+ return hasDark ? "dark" : "light";
31
+ }
32
+ return elWindow.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
33
+ }
34
+ export {
35
+ getCssColor,
36
+ getEffectiveColorScheme
37
+ };
@@ -1,4 +1,4 @@
1
- import { r } from "../dom-Bnc7oSYx.js";
1
+ import { r } from "../chunks/dom.js";
2
2
  import "../log.js";
3
3
  export {
4
4
  r as resolveReferenceElement
package/dist/dom.d.ts CHANGED
@@ -175,3 +175,12 @@ export interface FocusableElement extends HTMLElement {
175
175
  export declare const setFocusOnElement: (ref: (Element & {
176
176
  componentOnReady?: () => Promise<void>;
177
177
  }) | null | undefined, selector: string) => void;
178
+ /**
179
+ * Get the window associated with an element's document.
180
+ * Falls back to the current global window if the document has no associated window.
181
+ *
182
+ * @public
183
+ * @param element The element whose document determines the window.
184
+ * @returns The element's document window, or the current global window as a fallback.
185
+ */
186
+ export declare function getElementWindow(element: Element): Window;
package/dist/dom.js CHANGED
@@ -1,21 +1,22 @@
1
1
  import "./dom/slots.js";
2
- import { c, f, a, g, b, o, d, s, e, h, i, j, k, l, m, u, n } from "./dom-Bnc7oSYx.js";
2
+ import { c, f, b, a, g, d, o, e, s, h, i, j, k, l, m, n, u, p } from "./chunks/dom.js";
3
3
  export {
4
4
  c as classes,
5
5
  f as focusElement,
6
- a as getClosestElement,
7
- g as getElementAttribute,
8
- b as getSlotAssignedElements,
6
+ b as getClosestElement,
7
+ a as getElementAttribute,
8
+ g as getElementWindow,
9
+ d as getSlotAssignedElements,
9
10
  o as observeAncestorsMutation,
10
- d as resolveReferenceElement,
11
+ e as resolveReferenceElement,
11
12
  s as setFocusOnElement,
12
- e as slotChangeGetAssignedElements,
13
- h as slotChangeGetAssignedNodes,
14
- i as slotChangeGetTextContent,
15
- j as slotChangeHasAssignedElement,
16
- k as slotChangeHasAssignedNode,
17
- l as slotChangeHasContent,
18
- m as slotChangeHasTextContent,
13
+ h as slotChangeGetAssignedElements,
14
+ i as slotChangeGetAssignedNodes,
15
+ j as slotChangeGetTextContent,
16
+ k as slotChangeHasAssignedElement,
17
+ l as slotChangeHasAssignedNode,
18
+ m as slotChangeHasContent,
19
+ n as slotChangeHasTextContent,
19
20
  u as unsafeGetCalciteModeName,
20
- n as unsafeGetElementDirection
21
+ p as unsafeGetElementDirection
21
22
  };
@@ -1,14 +1,18 @@
1
1
  import { type GenericT9nStrings, type SupportedLocale } from "../intl.ts";
2
2
  /**
3
3
  * Get the locale of the given element.
4
- * It will look for the lang attribute on the element and its ancestors.
5
- * If not lang is found, it will default to 'en'.
4
+ *
5
+ * The locale precedence order:
6
+ *
7
+ * 1. `lang` on the provided element
8
+ * 2. `lang` attribute on any parent DOM element (closest parent first)
9
+ * 3. Browser's default language (from [navigator.language](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language))
10
+ * 4. `en` as the default fallback
6
11
  *
7
12
  * @public
8
13
  * @param element
9
14
  * @returns an object with the `lang` and `t9nLocale` properties.
10
- *
11
- * @see [lang vs t9nLocale](https://webgis.esri.com/references/lumina/controllers/useT9n#difference-between-lang-and-t9nlocale).
15
+ * @see [lang vs t9nLocale](https://webgis.esri.com/references/lumina/controllers/useT9n#accessing-current-locale-information).
12
16
  */
13
17
  export declare const getElementLocale: (element: HTMLElement) => {
14
18
  readonly lang: string;
@@ -35,6 +39,8 @@ export declare const getElementLocale: (element: HTMLElement) => {
35
39
  * Default file name is the element tag name without the part before the
36
40
  * first dash (e.g. `arcgis-map` becomes `map`).
37
41
  *
42
+ * Provide a custom asset name if `element` is not a web component.
43
+ *
38
44
  * Set to null if the component has no localization strings, but you still
39
45
  * wish to use `startLocaleObserver` to get the locale information.
40
46
  *
package/dist/intl/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { log } from "../log.js";
2
- import { g as getElementAttribute, o as observeAncestorsMutation } from "../dom-Bnc7oSYx.js";
2
+ import { a as getElementAttribute, o as observeAncestorsMutation } from "../chunks/dom.js";
3
3
  const getElementLocale$1 = (element) => {
4
4
  const lang = getElementAttribute(element, "lang", globalThis.navigator?.language || defaultLocale);
5
5
  return { lang, t9nLocale: normalizeLocale(lang) };
package/dist/promise.d.ts CHANGED
@@ -45,6 +45,14 @@ export interface Deferred<T> {
45
45
  */
46
46
  reject(_error: unknown): void;
47
47
  }
48
+ /**
49
+ * Adds abort semantics to an existing promise. The input promise continues running after the signal aborts.
50
+ *
51
+ * @public
52
+ * @param promise The promise to race against the abort signal.
53
+ * @param signalOrOptions The signal that aborts the returned promise.
54
+ */
55
+ export declare function whenOrAbort<T>(promise: Promise<T>, signalOrOptions: AbortOptions | AbortSignal | null | undefined): Promise<T>;
48
56
  /**
49
57
  * Execute async callbacks against a list with a fixed number of in-flight
50
58
  * operations.
@@ -73,3 +81,7 @@ export declare function forEachWithConcurrency<T>(items: readonly T[], concurren
73
81
  * @see https://devtopia.esri.com/WebGIS/arcgis-js-api/discussions/60405
74
82
  */
75
83
  export declare const devToolsAwareTimeout: (callback: () => void, timeout: number) => ReturnType<typeof setInterval>;
84
+ interface AbortOptions {
85
+ signal?: AbortSignal | null | undefined;
86
+ }
87
+ export {};
package/dist/promise.js CHANGED
@@ -11,6 +11,23 @@ class Deferred {
11
11
  });
12
12
  }
13
13
  }
14
+ async function whenOrAbort(promise, signalOrOptions) {
15
+ const signal = signalFromSignalOrOptions(signalOrOptions);
16
+ if (!signal) {
17
+ return await promise;
18
+ }
19
+ signal.throwIfAborted();
20
+ const abort = Promise.withResolvers();
21
+ const onAbort = () => {
22
+ try {
23
+ signal.throwIfAborted();
24
+ } catch (error) {
25
+ abort.reject(error);
26
+ }
27
+ };
28
+ signal.addEventListener("abort", onAbort, { once: true });
29
+ return await Promise.race([promise, abort.promise]).finally(() => signal.removeEventListener("abort", onAbort));
30
+ }
14
31
  async function forEachWithConcurrency(items, concurrency, callback) {
15
32
  if (items.length === 0) {
16
33
  return;
@@ -40,8 +57,12 @@ const devToolsAwareTimeout = (callback, timeout) => {
40
57
  const longTimeoutThreshold = 4e3;
41
58
  const longTimeoutInterval = 2e3;
42
59
  const shortTimeoutIntervals = 4;
60
+ function signalFromSignalOrOptions(params) {
61
+ return params instanceof AbortSignal ? params : params?.signal ?? void 0;
62
+ }
43
63
  export {
44
64
  Deferred,
45
65
  devToolsAwareTimeout,
46
- forEachWithConcurrency
66
+ forEachWithConcurrency,
67
+ whenOrAbort
47
68
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/toolkit",
3
- "version": "5.2.0-next.98",
3
+ "version": "6.0.0-next.0",
4
4
  "description": "Collection of common internal patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "sideEffects": false,
@@ -8,6 +8,7 @@
8
8
  "exports": {
9
9
  "./array": "./dist/array.js",
10
10
  "./dom": "./dist/dom.js",
11
+ "./dom/color": "./dist/dom/color.js",
11
12
  "./dom/slots": "./dist/dom/slots.js",
12
13
  "./dom/referenceElement": "./dist/dom/referenceElement.js",
13
14
  "./error": "./dist/error.js",