@txstate-mws/svelte-components 1.7.2 → 1.7.3

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.
@@ -65,7 +65,7 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
65
65
  parent.style.minHeight = String(minHeight) + 'px';
66
66
  }
67
67
  }
68
- let lastrect;
68
+ let lastmeasured;
69
69
  // The containing block (nearest ancestor that establishes a containing block for
70
70
  // position: fixed) is determined by the ancestors' computed styles. Scrolling can
71
71
  // never change it, but it CAN change when an ancestor gains/loses a transform,
@@ -84,19 +84,33 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
84
84
  }
85
85
  let fixedRect = { left: 0, top: 0, right: 0, bottom: 0 };
86
86
  if (fixedParent) {
87
+ // fixed elements are positioned against the containing block's padding box, so
88
+ // measure from inside its borders
87
89
  const tmpRect = fixedParent.getBoundingClientRect();
88
- fixedRect = { left: tmpRect.left, right: document.documentElement.clientWidth - tmpRect.right, top: tmpRect.top, bottom: document.documentElement.clientHeight - tmpRect.bottom };
90
+ const left = tmpRect.left + fixedParent.clientLeft;
91
+ const top = tmpRect.top + fixedParent.clientTop;
92
+ fixedRect = { left, right: document.documentElement.clientWidth - left - fixedParent.clientWidth, top, bottom: document.documentElement.clientHeight - top - fixedParent.clientHeight };
89
93
  }
90
94
  if (!target)
91
95
  return undefined;
92
96
  const tmpRect = target.getBoundingClientRect();
93
- const rect = { left: tmpRect.left - fixedRect.left, right: document.documentElement.clientWidth - tmpRect.right - fixedRect.right, top: tmpRect.top - fixedRect.top, bottom: document.documentElement.clientHeight - tmpRect.bottom - fixedRect.bottom, width: tmpRect.width, height: tmpRect.height };
94
- if (equal(rect, lastrect))
97
+ const vpWidth = document.documentElement.clientWidth;
98
+ const vpHeight = document.documentElement.clientHeight;
99
+ // The space available around the target in the viewport, used to make the auto
100
+ // alignment decision. This must not be relative to the fixed containing block: an
101
+ // ancestor with a transform, container-type, etc. changes what our CSS offsets are
102
+ // measured from, but it doesn't clip us, so the space that matters is the viewport.
103
+ const space = { left: tmpRect.left, right: vpWidth - tmpRect.right, top: tmpRect.top, bottom: vpHeight - tmpRect.bottom };
104
+ // The target's offsets from the edges of the fixed containing block, used to write
105
+ // the CSS position values.
106
+ const rect = { left: tmpRect.left - fixedRect.left, right: vpWidth - tmpRect.right - fixedRect.right, top: tmpRect.top - fixedRect.top, bottom: vpHeight - tmpRect.bottom - fixedRect.bottom, width: tmpRect.width, height: tmpRect.height };
107
+ const measured = { rect, space };
108
+ if (equal(measured, lastmeasured))
95
109
  return undefined;
96
- lastrect = rect;
110
+ lastmeasured = measured;
97
111
  let autoalign = align;
98
- const leftright = rect.right > rect.left ? 'left' : 'right';
99
- const topbottom = rect.bottom > rect.top ? 'bottom' : 'top';
112
+ const leftright = space.right > space.left ? 'left' : 'right';
113
+ const topbottom = space.bottom > space.top ? 'bottom' : 'top';
100
114
  if (align === 'auto') {
101
115
  autoalign = topbottom + leftright;
102
116
  }
@@ -123,12 +137,12 @@ export function glue(el, { target, align = 'auto', cover = false, gap = 0, adjus
123
137
  autoalign = 'middle';
124
138
  }
125
139
  else {
126
- const maxSpace = Math.max(rect.top, rect.bottom, rect.left, rect.right);
127
- if (maxSpace === rect.bottom)
140
+ const maxSpace = Math.max(space.top, space.bottom, space.left, space.right);
141
+ if (maxSpace === space.bottom)
128
142
  autoalign = 'bottom';
129
- else if (maxSpace === rect.top)
143
+ else if (maxSpace === space.top)
130
144
  autoalign = 'top';
131
- else if (maxSpace === rect.right)
145
+ else if (maxSpace === space.right)
132
146
  autoalign = 'right';
133
147
  else
134
148
  autoalign = 'left';
@@ -304,14 +318,12 @@ function isFixedContainer(el) {
304
318
  const css = getComputedStyle(el);
305
319
  if (css.getPropertyValue('transform') !== 'none' || css.getPropertyValue('perspective') !== 'none')
306
320
  return true; // A transform or perspective value other than none
307
- if (['transform', 'perspective', 'filter'].includes(css.getPropertyValue('will-change')))
308
- return true; // A will-change value of transform, filter, or perspective
321
+ if (css.getPropertyValue('will-change').split(/,\s*/).some(v => ['transform', 'perspective', 'filter'].includes(v)))
322
+ return true; // A will-change value including transform, filter, or perspective (e.g. will-change: opacity, transform;)
309
323
  if (css.getPropertyValue('filter') !== 'none')
310
324
  return true; // A filter value other than none
311
- if (['layout', 'paint', 'strict', 'content'].includes(css.getPropertyValue('contain')))
312
- return true; // A contain value of layout, paint, strict or content (e.g. contain: paint;)
313
- if ('container-type' in css && css.getPropertyValue('container-type') !== 'normal')
314
- return true; // A container-type value other than normal
325
+ if (css.getPropertyValue('contain').split(/\s+/).some(v => ['layout', 'paint', 'strict', 'content'].includes(v)))
326
+ return true; // A contain value including layout, paint, strict or content (e.g. contain: paint; or contain: size layout;)
315
327
  if ('backdrop-filter' in css && css.getPropertyValue('backdrop-filter') !== 'none')
316
328
  return true; // A backdrop-filter other than none (e.g. backdrop-filter: blur(10px);)
317
329
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@txstate-mws/svelte-components",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Svelte components that are generically useful.",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",