matchheight 1.0.0 → 1.1.0

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.
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * @author yomotsu
3
+ * MatchHeight
4
+ * https://github.com/yomotsu/MatchHeight
5
+ * Released under the MIT License.
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 paddingAndBorder=parseFloat(window.getComputedStyle(item.el).getPropertyValue("padding-top"))+parseFloat(window.getComputedStyle(item.el).getPropertyValue("padding-bottom"))+parseFloat(window.getComputedStyle(item.el).getPropertyValue("border-top-width"))+parseFloat(window.getComputedStyle(item.el).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}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matchheight",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "author": "Yomotsu",
5
5
  "license": "MIT",
6
6
  "repository": "yomotsu/matchheight",
@@ -9,15 +9,15 @@
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.2",
13
- "rollup": "^3.28.0",
14
- "terser": "^5.19.2",
15
- "tslib": "^2.6.1",
16
- "typescript": "^5.1.6"
12
+ "@rollup/plugin-typescript": "^11.1.5",
13
+ "rollup": "^4.1.4",
14
+ "terser": "^5.22.0",
15
+ "tslib": "^2.6.2",
16
+ "typescript": "^5.2.2"
17
17
  },
18
18
  "scripts": {
19
19
  "dev": "rollup --config --watch",
20
- "build": "rollup --config && terser dist/MatchHeight.js -o dist/MatchHeight.min.js --comments '/^!/'"
20
+ "build": "rollup --config && terser dist/match-height.js -o dist/match-height.min.js --comments '/^!/'"
21
21
  },
22
22
  "keywords": [
23
23
  "matchHeight",