@txstate-mws/svelte-components 1.6.2 → 1.6.4

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.
@@ -4,16 +4,16 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
4
4
  let halign;
5
5
  let valign;
6
6
  const parent = el.offsetParent;
7
- const formerMinHeight = parent.style.minHeight;
7
+ const formerMinHeight = parent?.style.minHeight;
8
8
  if (target)
9
9
  el.style.position = 'fixed';
10
10
  function adjustParentHeight() {
11
11
  if (!adjustparentheight)
12
12
  return;
13
- if (parent.style.overflowY === 'auto')
13
+ if (parent?.style.overflowY === 'auto')
14
14
  return;
15
15
  const minHeight = el.offsetTop + el.offsetHeight;
16
- if (minHeight > parent.clientHeight) {
16
+ if (minHeight > (parent?.clientHeight ?? 0)) {
17
17
  requestAnimationFrame(() => {
18
18
  parent.style.minHeight = String(minHeight) + 'px';
19
19
  });
@@ -21,8 +21,16 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
21
21
  }
22
22
  let lastrect;
23
23
  function reposition() {
24
+ const fixedParent = fixedContainingBlock(el);
25
+ let fixedRect = { left: 0, top: 0, right: 0, bottom: 0 };
26
+ if (fixedParent) {
27
+ const tmpRect = fixedParent.getBoundingClientRect();
28
+ fixedRect = { left: tmpRect.left, right: window.innerWidth - tmpRect.right, top: tmpRect.top, bottom: window.innerHeight - tmpRect.bottom };
29
+ }
30
+ if (!target)
31
+ return;
24
32
  const tmpRect = target.getBoundingClientRect();
25
- const rect = { left: tmpRect.left, right: window.innerWidth - tmpRect.right, top: tmpRect.top, bottom: window.innerHeight - tmpRect.bottom, width: tmpRect.width, height: tmpRect.height };
33
+ const rect = { left: tmpRect.left - fixedRect.left, right: window.innerWidth - tmpRect.right - fixedRect.right, top: tmpRect.top - fixedRect.top, bottom: window.innerHeight - tmpRect.bottom - fixedRect.bottom, width: tmpRect.width, height: tmpRect.height };
26
34
  if (equal(rect, lastrect))
27
35
  return;
28
36
  let autoalign = align;
@@ -94,8 +102,10 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
94
102
  target = utarget;
95
103
  if (!target)
96
104
  el.style.removeProperty('position');
97
- else
105
+ else {
98
106
  el.style.position = 'fixed';
107
+ reposition();
108
+ }
99
109
  }
100
110
  },
101
111
  destroy() {
@@ -109,3 +119,26 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
109
119
  }
110
120
  };
111
121
  }
122
+ const isHTMLElement = (e) => !!e && 'offsetParent' in e;
123
+ function isFixedContainer(el) {
124
+ const css = getComputedStyle(el);
125
+ if (css.getPropertyValue('transform') !== 'none' || css.getPropertyValue('perspective') !== 'none')
126
+ return true; // A transform or perspective value other than none
127
+ if (['transform', 'perspective', 'filter'].includes(css.getPropertyValue('will-change')))
128
+ return true; // A will-change value of transform, filter, or perspective
129
+ if (css.getPropertyValue('filter') !== 'none')
130
+ return true; // A filter value other than none
131
+ if (['layout', 'paint', 'strict', 'content'].includes(css.getPropertyValue('contain')))
132
+ return true; // A contain value of layout, paint, strict or content (e.g. contain: paint;)
133
+ if (css.getPropertyValue('container-type') !== 'normal')
134
+ return true; // A container-type value other than normal
135
+ if (css.getPropertyValue('backdrop-filter') !== 'none')
136
+ return true; // A backdrop-filter other than none (e.g. backdrop-filter: blur(10px);)
137
+ return false;
138
+ }
139
+ function fixedContainingBlock(el) {
140
+ let parent = el.parentElement;
141
+ while (isHTMLElement(parent) && !isFixedContainer(parent))
142
+ parent = parent.parentElement;
143
+ return parent;
144
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.6.2",
3
+ "version": "1.6.4",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
@@ -34,7 +34,7 @@
34
34
  "typescript": "^5.0.4"
35
35
  },
36
36
  "peerDependencies": {
37
- "svelte": "^3.53.1 || ^4.0.0"
37
+ "svelte": "^3.53.1 || ^4.0.0 || ^5.0.0"
38
38
  },
39
39
  "type": "module",
40
40
  "main": "./dist/index.js",