{"id":15814211,"url":"https://github.com/stevenvachon/dom-max-size","last_synced_at":"2025-04-01T01:50:09.163Z","repository":{"id":54301163,"uuid":"191750867","full_name":"stevenvachon/dom-max-size","owner":"stevenvachon","description":"Determine the maximum scalable dimensions of an HTMLElement.","archived":false,"fork":false,"pushed_at":"2020-06-02T09:07:13.000Z","size":188,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-06T04:23:30.937Z","etag":null,"topics":["dimensions","dom","max-height","max-width"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenvachon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-13T11:33:50.000Z","updated_at":"2024-03-27T14:26:56.000Z","dependencies_parsed_at":"2022-08-13T11:20:58.549Z","dependency_job_id":null,"html_url":"https://github.com/stevenvachon/dom-max-size","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-max-size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-max-size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-max-size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenvachon%2Fdom-max-size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenvachon","download_url":"https://codeload.github.com/stevenvachon/dom-max-size/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246569007,"owners_count":20798341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dimensions","dom","max-height","max-width"],"created_at":"2024-10-05T04:23:34.611Z","updated_at":"2025-04-01T01:50:09.138Z","avatar_url":"https://github.com/stevenvachon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dom-max-size [![NPM Version][npm-image]][npm-url] ![File Size][filesize-image] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Monitor][greenkeeper-image]][greenkeeper-url]\n\n\u003e Determine the maximum scalable dimensions of an `HTMLElement`.\n\nThis library works by prepending a [largely sized child element](#sizing-fixture) to the target element and forcing a [re-layout](https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction). As such, [void elements](https://www.w3.org/TR/html5/syntax.html#void-elements) are not supported because they can never contain that child. Also, elements with a `shadowRoot` are not automatically supported because the light tree is not rendered, however there is a work-around (see below).\n\nFor the sake of performance, be conservative when using this library.\n\n\n## Installation\n\n[Node.js](http://nodejs.org) `\u003e= 10` is required. To install, type this at the command line:\n```shell\nnpm install dom-max-size\n```\n\n\n## Importing\n\nES Module:\n```js\nimport {getMaxHeight, getMaxSize, getMaxWidth} from 'dom-max-size';\n```\n\nCommonJS Module:\n```js\nconst {getMaxHeight, getMaxSize, getMaxWidth} = require('dom-max-size');\n```\n\n\n## Usage\n\nGet the maximum that the web browser can possibly allow for any element:\n```js\ngetMaxHeight(); //-\u003e 33554428, in Chrome 75.x\ngetMaxWidth(); //-\u003e 33554428, in Chrome 75.x\ngetMaxSize(); //-\u003e {height:33554428, width:33554428} in Chrome 75.x\n```\n\nGet the maximum that an element can scale to within the limitations of itself and its parents:\n```html\n\u003cdiv style=\"display:flex; max-height:500px; max-width:250px\"\u003e\n  \u003cdiv id=\"target\" style=\"width:50%\"\u003e…\u003c/div\u003e\n\u003c/div\u003e\n```\n```js\nconst target = document.getElementById('target');\ngetMaxHeight(target); //-\u003e 500\ngetMaxWidth(target); //-\u003e 125\n```\n\nWhen working with an element that is resized by its descendants, you'll need to provide a reference to all of them:\n```html\n\u003cdiv style=\"display:flex; max-height:500px\"\u003e\n  \u003cdiv id=\"target\"\u003e\n    \u003cdiv id=\"sizerA\"\u003e…\u003c/div\u003e\n    \u003cdiv id=\"sizerB\"\u003e…\u003c/div\u003e\n  \u003c/div\u003e\n\u003c/div\u003e\n```\n```js\nconst target = document.getElementById('target');\nconst sizerA = document.getElementById('sizerA');\nconst sizerB = document.getElementById('sizerB');\ngetMaxHeight(target, sizerA, sizerB); //-\u003e 500\n```\n\nThe above example also applies when working with a `shadowRoot`:\n```js\nconst target = document.getElementById('target');\nconst sizer = target.shadowRoot.querySelector('#sizer');\ngetMaxHeight(target, sizer); //-\u003e number\n```\n\n\n## Sizing Fixture\n\nIf the temporary sizing element is not behaving as expected, resulting in incorrectly returned values, it is possible that it's caused by a CSS complication. While you should probably [create an issue](https://github.com/stevenvachon/dom-max-size/issues/new), you can—at least temporarily—add any necessary styles via:\n```css\ntarget-element \u003e [data-sizing-fixture] {\n  /* … */\n}\n```\n\n\n## Compatibility\n\nDepending on your target browsers, you may need polyfills/shims for the following:\n\n* [`HTMLElement::dataset`](https://mdn.io/HTMLElement/dataset)\n* [`Map`](https://mdn.io/Global_Objects/Map)\n* [`Node::children`](https://mdn.io/Node/children)\n* [`Node::prepend`](https://mdn.io/Node/prepend), [`Node::remove`](https://mdn.io/Node/remove)\n* [`Object.assign`](https://mdn.io/Object/assign)\n* [`Object.entries`](https://mdn.io/Object/entries)\n\n\n[npm-image]: https://img.shields.io/npm/v/dom-max-size.svg\n[npm-url]: https://npmjs.com/package/dom-max-size\n[filesize-image]: https://img.shields.io/badge/size-1.5kB%20gzipped-blue.svg\n[travis-image]: https://img.shields.io/travis/stevenvachon/dom-max-size.svg\n[travis-url]: https://travis-ci.org/stevenvachon/dom-max-size\n[coveralls-image]: https://img.shields.io/coveralls/stevenvachon/dom-max-size.svg\n[coveralls-url]: https://coveralls.io/github/stevenvachon/dom-max-size\n[greenkeeper-image]: https://badges.greenkeeper.io/stevenvachon/dom-max-size.svg\n[greenkeeper-url]: https://greenkeeper.io/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fdom-max-size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenvachon%2Fdom-max-size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenvachon%2Fdom-max-size/lists"}