matchheight 1.1.1 → 1.1.2
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.
package/dist/match-height.js
CHANGED
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
const maxHeightInRow = Math.max(...processingTargets.map((item) => item.height));
|
|
78
78
|
processingTargets.forEach((item) => {
|
|
79
79
|
const error = processingTop - item.top + errorThreshold;
|
|
80
|
-
const getPropertyValue = window.getComputedStyle(item.el).getPropertyValue;
|
|
80
|
+
const getPropertyValue = (value) => window.getComputedStyle(item.el).getPropertyValue(value);
|
|
81
81
|
const isBorderBox = getPropertyValue('box-sizing') === 'border-box';
|
|
82
82
|
if (isBorderBox) {
|
|
83
83
|
item.el.style.minHeight = `${maxHeightInRow + error}px`;
|
package/dist/match-height.min.js
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* https://github.com/yomotsu/MatchHeight
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.MatchHeight=factory())})(this,(function(){"use strict";function throttle(fn,threshold){let last,deferTimer;return function(){const now=Date.now();if(last&&now<last+threshold){clearTimeout(deferTimer);deferTimer=setTimeout((function(){last=now;fn()}),threshold)}else{last=now;fn()}}}const errorThreshold=1;class MatchHeight{constructor(selector="[data-mh]"){this._remains=[];this._selector=selector;const update=this.update.bind(this);const throttledUpdate=throttle(update,200);if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",update,{once:true})}if(document.readyState==="interactive"){document.addEventListener("load",update,{once:true})}else{update()}window.addEventListener("resize",throttledUpdate);this.disconnect=()=>{window.removeEventListener("resize",throttledUpdate)}}update(){const elements=document.querySelectorAll(this._selector);if(elements.length===0)return;this._remains=Array.prototype.map.call(elements,(el=>({el:el,top:0,height:0})));this._remains.forEach((item=>{item.el.style.minHeight=""}));this._process()}_process(){this._remains.forEach((item=>{const bb=item.el.getBoundingClientRect();item.top=bb.top;item.height=bb.height}));this._remains.sort(((a,b)=>a.top-b.top));const processingTop=this._remains[0].top;const processingTargets=this._remains.filter((item=>Math.abs(item.top-processingTop)<=errorThreshold));const maxHeightInRow=Math.max(...processingTargets.map((item=>item.height)));processingTargets.forEach((item=>{const error=processingTop-item.top+errorThreshold;const getPropertyValue=window.getComputedStyle(item.el).getPropertyValue;const isBorderBox=getPropertyValue("box-sizing")==="border-box";if(isBorderBox){item.el.style.minHeight=`${maxHeightInRow+error}px`}else{const paddingAndBorder=parseFloat(getPropertyValue("padding-top"))+parseFloat(getPropertyValue("padding-bottom"))+parseFloat(getPropertyValue("border-top-width"))+parseFloat(getPropertyValue("border-bottom-width"));item.el.style.minHeight=`${maxHeightInRow-paddingAndBorder+error}px`}}));this._remains.splice(0,processingTargets.length);if(0<this._remains.length)this._process()}}return MatchHeight}));
|
|
7
|
+
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,global.MatchHeight=factory())})(this,(function(){"use strict";function throttle(fn,threshold){let last,deferTimer;return function(){const now=Date.now();if(last&&now<last+threshold){clearTimeout(deferTimer);deferTimer=setTimeout((function(){last=now;fn()}),threshold)}else{last=now;fn()}}}const errorThreshold=1;class MatchHeight{constructor(selector="[data-mh]"){this._remains=[];this._selector=selector;const update=this.update.bind(this);const throttledUpdate=throttle(update,200);if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",update,{once:true})}if(document.readyState==="interactive"){document.addEventListener("load",update,{once:true})}else{update()}window.addEventListener("resize",throttledUpdate);this.disconnect=()=>{window.removeEventListener("resize",throttledUpdate)}}update(){const elements=document.querySelectorAll(this._selector);if(elements.length===0)return;this._remains=Array.prototype.map.call(elements,(el=>({el:el,top:0,height:0})));this._remains.forEach((item=>{item.el.style.minHeight=""}));this._process()}_process(){this._remains.forEach((item=>{const bb=item.el.getBoundingClientRect();item.top=bb.top;item.height=bb.height}));this._remains.sort(((a,b)=>a.top-b.top));const processingTop=this._remains[0].top;const processingTargets=this._remains.filter((item=>Math.abs(item.top-processingTop)<=errorThreshold));const maxHeightInRow=Math.max(...processingTargets.map((item=>item.height)));processingTargets.forEach((item=>{const error=processingTop-item.top+errorThreshold;const getPropertyValue=value=>window.getComputedStyle(item.el).getPropertyValue(value);const isBorderBox=getPropertyValue("box-sizing")==="border-box";if(isBorderBox){item.el.style.minHeight=`${maxHeightInRow+error}px`}else{const paddingAndBorder=parseFloat(getPropertyValue("padding-top"))+parseFloat(getPropertyValue("padding-bottom"))+parseFloat(getPropertyValue("border-top-width"))+parseFloat(getPropertyValue("border-bottom-width"));item.el.style.minHeight=`${maxHeightInRow-paddingAndBorder+error}px`}}));this._remains.splice(0,processingTargets.length);if(0<this._remains.length)this._process()}}return MatchHeight}));
|
|
@@ -71,7 +71,7 @@ class MatchHeight {
|
|
|
71
71
|
const maxHeightInRow = Math.max(...processingTargets.map((item) => item.height));
|
|
72
72
|
processingTargets.forEach((item) => {
|
|
73
73
|
const error = processingTop - item.top + errorThreshold;
|
|
74
|
-
const getPropertyValue = window.getComputedStyle(item.el).getPropertyValue;
|
|
74
|
+
const getPropertyValue = (value) => window.getComputedStyle(item.el).getPropertyValue(value);
|
|
75
75
|
const isBorderBox = getPropertyValue('box-sizing') === 'border-box';
|
|
76
76
|
if (isBorderBox) {
|
|
77
77
|
item.el.style.minHeight = `${maxHeightInRow + error}px`;
|
package/package.json
CHANGED
package/src/match-height.ts
CHANGED
|
@@ -91,7 +91,7 @@ class MatchHeight {
|
|
|
91
91
|
processingTargets.forEach( ( item ) => {
|
|
92
92
|
|
|
93
93
|
const error = processingTop - item.top + errorThreshold;
|
|
94
|
-
const getPropertyValue = window.getComputedStyle( item.el ).getPropertyValue;
|
|
94
|
+
const getPropertyValue = ( value: string ) => window.getComputedStyle( item.el ).getPropertyValue( value );
|
|
95
95
|
const isBorderBox = getPropertyValue( 'box-sizing' ) === 'border-box';
|
|
96
96
|
|
|
97
97
|
if ( isBorderBox ) {
|