@cloudscape-design/chart-components 1.0.24 → 1.0.26

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,3 +1,3 @@
1
1
  {
2
- "commit": "80443d98d82644ff80f45d92096981d2e829a672"
2
+ "commit": "1e9c64fdb944d339e7609cf8d7abe084835d035c"
3
3
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Polyfill for `element.scrollIntoView({ container: "nearest", scrollMode: "..." })`
3
+ * For ease of implementation, behaves like `{ block: "center" }` is provided.
4
+ *
5
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView (for `container`)
6
+ * @see https://caniuse.com/wf-scroll-into-view-container (for `container` browser support)
7
+ * @see https://github.com/w3c/csswg-drafts/pull/5677 (for discussion of `if-needed`)
8
+ */
9
+ export declare function scrollIntoViewNearestContainer(element: HTMLElement, options?: ScrollOptions & {
10
+ scrollMode?: "always" | "if-needed";
11
+ }): void;
@@ -0,0 +1,44 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Polyfill for `element.scrollIntoView({ container: "nearest", scrollMode: "..." })`
5
+ * For ease of implementation, behaves like `{ block: "center" }` is provided.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView (for `container`)
8
+ * @see https://caniuse.com/wf-scroll-into-view-container (for `container` browser support)
9
+ * @see https://github.com/w3c/csswg-drafts/pull/5677 (for discussion of `if-needed`)
10
+ */
11
+ export function scrollIntoViewNearestContainer(element, options) {
12
+ var _a;
13
+ // Scroll methods (scrollTo, scrollIntoView, etc) are not supported in test environments like JSDOM.
14
+ if (!("scrollTo" in element)) {
15
+ return;
16
+ }
17
+ // Get element boundaries to measure scroll offsets.
18
+ // In the future, could be replaced with a simple `element.scrollParent`.
19
+ // https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent
20
+ const scrollParent = (_a = getScrollParent(element)) !== null && _a !== void 0 ? _a : element.ownerDocument.documentElement;
21
+ const { top: elementTop, bottom: elementBottom, height: elementHeight } = element.getBoundingClientRect();
22
+ const { top: scrollTop, bottom: scrollBottom, height: scrollHeight } = scrollParent.getBoundingClientRect();
23
+ if ((options === null || options === void 0 ? void 0 : options.scrollMode) === "if-needed") {
24
+ // Technically, getBoundingClientRect() returns the border-box, which includes the border width.
25
+ // We should subtract the border width to get the padding box, but all that computation isn't worth it.
26
+ const isNeeded = elementTop < scrollTop || elementBottom > scrollBottom;
27
+ if (!isNeeded) {
28
+ return;
29
+ }
30
+ }
31
+ const topRelativeToParent = elementTop + scrollParent.scrollTop - scrollTop;
32
+ const blockCenterOffset = scrollHeight / 2 - elementHeight / 2;
33
+ scrollParent.scrollTo({ top: topRelativeToParent - blockCenterOffset, ...options });
34
+ }
35
+ function getScrollParent(element) {
36
+ for (let node = element.parentElement; node !== null && node !== element.ownerDocument.body; node = node.parentElement) {
37
+ const overflow = getComputedStyle(node).overflow;
38
+ if (overflow !== "visible" && overflow !== "hidden") {
39
+ return node;
40
+ }
41
+ }
42
+ return null;
43
+ }
44
+ //# sourceMappingURL=dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.js","sourceRoot":"","sources":["../../../../src/internal/utils/dom.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAoB,EACpB,OAAiE;;IAEjE,oGAAoG;IACpG,IAAI,CAAC,CAAC,UAAU,IAAI,OAAO,CAAC,EAAE;QAC5B,OAAO;KACR;IAED,oDAAoD;IACpD,yEAAyE;IACzE,oEAAoE;IACpE,MAAM,YAAY,GAAG,MAAA,eAAe,CAAC,OAAO,CAAC,mCAAI,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC;IACvF,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC1G,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,qBAAqB,EAAE,CAAC;IAE5G,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,MAAK,WAAW,EAAE;QACvC,gGAAgG;QAChG,uGAAuG;QACvG,MAAM,QAAQ,GAAG,UAAU,GAAG,SAAS,IAAI,aAAa,GAAG,YAAY,CAAC;QACxE,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO;SACR;KACF;IAED,MAAM,mBAAmB,GAAG,UAAU,GAAG,YAAY,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5E,MAAM,iBAAiB,GAAG,YAAY,GAAG,CAAC,GAAG,aAAa,GAAG,CAAC,CAAC;IAC/D,YAAY,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,eAAe,CAAC,OAAoB;IAC3C,KACE,IAAI,IAAI,GAAuB,OAAO,CAAC,aAAa,EACpD,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,OAAO,CAAC,aAAa,CAAC,IAAI,EACpD,IAAI,GAAG,IAAI,CAAC,aAAa,EACzB;QACA,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC;QACjD,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,QAAQ,EAAE;YACnD,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Polyfill for `element.scrollIntoView({ container: \"nearest\", scrollMode: \"...\" })`\n * For ease of implementation, behaves like `{ block: \"center\" }` is provided.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView (for `container`)\n * @see https://caniuse.com/wf-scroll-into-view-container (for `container` browser support)\n * @see https://github.com/w3c/csswg-drafts/pull/5677 (for discussion of `if-needed`)\n */\nexport function scrollIntoViewNearestContainer(\n element: HTMLElement,\n options?: ScrollOptions & { scrollMode?: \"always\" | \"if-needed\" },\n) {\n // Scroll methods (scrollTo, scrollIntoView, etc) are not supported in test environments like JSDOM.\n if (!(\"scrollTo\" in element)) {\n return;\n }\n\n // Get element boundaries to measure scroll offsets.\n // In the future, could be replaced with a simple `element.scrollParent`.\n // https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent\n const scrollParent = getScrollParent(element) ?? element.ownerDocument.documentElement;\n const { top: elementTop, bottom: elementBottom, height: elementHeight } = element.getBoundingClientRect();\n const { top: scrollTop, bottom: scrollBottom, height: scrollHeight } = scrollParent.getBoundingClientRect();\n\n if (options?.scrollMode === \"if-needed\") {\n // Technically, getBoundingClientRect() returns the border-box, which includes the border width.\n // We should subtract the border width to get the padding box, but all that computation isn't worth it.\n const isNeeded = elementTop < scrollTop || elementBottom > scrollBottom;\n if (!isNeeded) {\n return;\n }\n }\n\n const topRelativeToParent = elementTop + scrollParent.scrollTop - scrollTop;\n const blockCenterOffset = scrollHeight / 2 - elementHeight / 2;\n scrollParent.scrollTo({ top: topRelativeToParent - blockCenterOffset, ...options });\n}\n\nfunction getScrollParent(element: HTMLElement): HTMLElement | null {\n for (\n let node: HTMLElement | null = element.parentElement;\n node !== null && node !== element.ownerDocument.body;\n node = node.parentElement\n ) {\n const overflow = getComputedStyle(node).overflow;\n if (overflow !== \"visible\" && overflow !== \"hidden\") {\n return node;\n }\n }\n return null;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudscape-design/chart-components",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cloudscape-design/chart-components.git"