matchheight 1.1.0 → 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 +12 -5
- package/dist/match-height.min.js +1 -1
- package/dist/match-height.module.js +12 -5
- package/package.json +5 -5
- package/src/match-height.ts +16 -6
package/dist/match-height.js
CHANGED
|
@@ -77,11 +77,18 @@
|
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
const getPropertyValue = (value) => window.getComputedStyle(item.el).getPropertyValue(value);
|
|
81
|
+
const isBorderBox = getPropertyValue('box-sizing') === 'border-box';
|
|
82
|
+
if (isBorderBox) {
|
|
83
|
+
item.el.style.minHeight = `${maxHeightInRow + error}px`;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const paddingAndBorder = parseFloat(getPropertyValue('padding-top')) +
|
|
87
|
+
parseFloat(getPropertyValue('padding-bottom')) +
|
|
88
|
+
parseFloat(getPropertyValue('border-top-width')) +
|
|
89
|
+
parseFloat(getPropertyValue('border-bottom-width'));
|
|
90
|
+
item.el.style.minHeight = `${maxHeightInRow - paddingAndBorder + error}px`;
|
|
91
|
+
}
|
|
85
92
|
});
|
|
86
93
|
this._remains.splice(0, processingTargets.length);
|
|
87
94
|
if (0 < this._remains.length)
|
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
|
|
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,11 +71,18 @@ 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
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
const getPropertyValue = (value) => window.getComputedStyle(item.el).getPropertyValue(value);
|
|
75
|
+
const isBorderBox = getPropertyValue('box-sizing') === 'border-box';
|
|
76
|
+
if (isBorderBox) {
|
|
77
|
+
item.el.style.minHeight = `${maxHeightInRow + error}px`;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const paddingAndBorder = parseFloat(getPropertyValue('padding-top')) +
|
|
81
|
+
parseFloat(getPropertyValue('padding-bottom')) +
|
|
82
|
+
parseFloat(getPropertyValue('border-top-width')) +
|
|
83
|
+
parseFloat(getPropertyValue('border-bottom-width'));
|
|
84
|
+
item.el.style.minHeight = `${maxHeightInRow - paddingAndBorder + error}px`;
|
|
85
|
+
}
|
|
79
86
|
});
|
|
80
87
|
this._remains.splice(0, processingTargets.length);
|
|
81
88
|
if (0 < this._remains.length)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matchheight",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"author": "Yomotsu",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "yomotsu/matchheight",
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
"module": "dist/match-height.module.js",
|
|
10
10
|
"types": "dist/match-height.d.ts",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
13
|
-
"rollup": "^4.
|
|
14
|
-
"terser": "^5.
|
|
12
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
13
|
+
"rollup": "^4.14.3",
|
|
14
|
+
"terser": "^5.30.3",
|
|
15
15
|
"tslib": "^2.6.2",
|
|
16
|
-
"typescript": "^5.
|
|
16
|
+
"typescript": "^5.4.5"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"dev": "rollup --config --watch",
|
package/src/match-height.ts
CHANGED
|
@@ -91,13 +91,23 @@ class MatchHeight {
|
|
|
91
91
|
processingTargets.forEach( ( item ) => {
|
|
92
92
|
|
|
93
93
|
const error = processingTop - item.top + errorThreshold;
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'padding-bottom' ) ) +
|
|
97
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-top-width' ) ) +
|
|
98
|
-
parseFloat( window.getComputedStyle( item.el ).getPropertyValue( 'border-bottom-width' ) );
|
|
99
|
-
item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder + error }px`;
|
|
94
|
+
const getPropertyValue = ( value: string ) => window.getComputedStyle( item.el ).getPropertyValue( value );
|
|
95
|
+
const isBorderBox = getPropertyValue( 'box-sizing' ) === 'border-box';
|
|
100
96
|
|
|
97
|
+
if ( isBorderBox ) {
|
|
98
|
+
|
|
99
|
+
item.el.style.minHeight = `${ maxHeightInRow + error }px`;
|
|
100
|
+
|
|
101
|
+
} else {
|
|
102
|
+
|
|
103
|
+
const paddingAndBorder =
|
|
104
|
+
parseFloat( getPropertyValue( 'padding-top' ) ) +
|
|
105
|
+
parseFloat( getPropertyValue( 'padding-bottom' ) ) +
|
|
106
|
+
parseFloat( getPropertyValue( 'border-top-width' ) ) +
|
|
107
|
+
parseFloat( getPropertyValue( 'border-bottom-width' ) );
|
|
108
|
+
item.el.style.minHeight = `${ maxHeightInRow - paddingAndBorder + error }px`;
|
|
109
|
+
|
|
110
|
+
}
|
|
101
111
|
} );
|
|
102
112
|
|
|
103
113
|
this._remains.splice( 0, processingTargets.length );
|