├── .circleci
└── config.yml
├── .eslintrc.json
├── .github
├── FUNDING.yml
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── question.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── docs
├── index.html
├── page.07eb8115.css
├── page.07eb8115.css.map
├── page.287107b2.js
├── page.287107b2.js.map
└── src
│ ├── index.html
│ ├── page.css
│ └── page.js
├── jest.config.js
├── package-lock.json
├── package.json
├── rollup.config.js
├── src
├── DOMRectReadOnly.ts
├── ResizeObservation.ts
├── ResizeObserver.ts
├── ResizeObserverBoxOptions.ts
├── ResizeObserverCallback.ts
├── ResizeObserverController.ts
├── ResizeObserverDetail.ts
├── ResizeObserverEntry.ts
├── ResizeObserverOptions.ts
├── ResizeObserverSize.ts
├── algorithms
│ ├── broadcastActiveObservations.ts
│ ├── calculateBoxSize.ts
│ ├── calculateDepthForNode.ts
│ ├── deliverResizeLoopError.ts
│ ├── gatherActiveObservationsAtDepth.ts
│ ├── hasActiveObservations.ts
│ └── hasSkippedObservations.ts
├── exports
│ └── resize-observer.ts
└── utils
│ ├── element.ts
│ ├── freeze.ts
│ ├── global.ts
│ ├── process.ts
│ ├── queueMicroTask.ts
│ ├── queueResizeObserver.ts
│ ├── resizeObservers.ts
│ └── scheduler.ts
├── test
├── .eslintrc.json
├── dom-rect-read-only.test.ts
├── helpers
│ ├── delay.ts
│ └── offset.ts
├── inline-elements.test.ts
├── queue-micro-task.test.ts
├── resize-observer-basic-svg.test.ts
├── resize-observer-basic.test.ts
├── resize-observer-box-sizes.test.ts
└── resize-observer-multiple.test.ts
└── tsconfig.json
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | test:
4 | docker: # use the docker executor type; machine and macos executors are also supported
5 | - image: cimg/node:16.14
6 | steps:
7 | - checkout
8 | - run:
9 | name: Install Dev Dependencies
10 | command: npm install
11 | - run:
12 | name: Run Tests
13 | command: npm run ci-tests
14 | environment:
15 | JEST_JUNIT_OUTPUT: test-results/results.xml
16 | - store_test_results:
17 | path: test-results
18 |
19 | workflows:
20 | version: 2
21 | workflow:
22 | jobs:
23 | - test
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "root": true,
3 | "parser": "@typescript-eslint/parser",
4 | "plugins": ["@typescript-eslint"],
5 | "extends": ["plugin:@typescript-eslint/recommended"],
6 | "rules": {
7 | "@typescript-eslint/indent": ["error", 2]
8 | }
9 | }
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [TremayneChrist]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help improve this library
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | If the bug is easy to reproduce, please give steps below. Otherwise, please provide a sample repo to look at.
15 |
16 | **Expected behavior**
17 | A clear and concise description of what you expected to happen.
18 |
19 | **Frameworks/Libraries used**
20 | Please list any additional frameworks or libraries that are being used. For example, Angular, Lit, Polymer, React, Stencil, Vue etc.
21 |
22 | **Desktop (please complete the following information):**
23 | - OS: [e.g. windows]
24 | - Browser [e.g. chrome, ie]
25 | - Version [e.g. 11]
26 |
27 | **Smartphone (please complete the following information):**
28 | - Device: [e.g. iPhone8]
29 | - OS: [e.g. iOS11.1]
30 | - Browser [e.g. stock browser, safari]
31 | - Version [e.g. 22]
32 |
33 | **Additional context**
34 | Add any other context about the problem here.
35 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Question
3 | about: Ask a question about the project
4 | title: "[QUESTION]"
5 | labels: question
6 | assignees: ''
7 |
8 | ---
9 |
10 | Please use the [discussions tab](/juggle/resize-observer/discussions/new) for submitting questions!
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | lib
4 | junit.xml
5 | .cache
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | In the interest of fostering an open and welcoming environment, we as
4 | contributors and maintainers pledge to making participation in our project and
5 | our community a harassment-free experience for everyone, regardless of age, body
6 | size, disability, ethnicity, sex characteristics, gender identity and expression,
7 | level of experience, education, socio-economic status, nationality, personal
8 | appearance, race, religion, or sexual identity and orientation.
9 |
10 | ## Our Standards
11 |
12 | Examples of behavior that contributes to creating a positive environment
13 | include:
14 |
15 | * Using welcoming and inclusive language
16 | * Being respectful of differing viewpoints and experiences
17 | * Gracefully accepting constructive criticism
18 | * Focusing on what is best for the community
19 | * Showing empathy towards other community members
20 |
21 | Examples of unacceptable behavior by participants include:
22 |
23 | * The use of sexualized language or imagery and unwelcome sexual attention or
24 | advances
25 | * Trolling, insulting/derogatory comments, and personal or political attacks
26 | * Public or private harassment
27 | * Publishing others' private information, such as a physical or electronic
28 | address, without explicit permission
29 | * Other conduct which could reasonably be considered inappropriate in a
30 | professional setting
31 |
32 | ## Our Responsibilities
33 |
34 | Project maintainers are responsible for clarifying the standards of acceptable
35 | behavior and are expected to take appropriate and fair corrective action in
36 | response to any instances of unacceptable behavior.
37 |
38 | Project maintainers have the right and responsibility to remove, edit, or
39 | reject comments, commits, code, wiki edits, issues, and other contributions
40 | that are not aligned to this Code of Conduct, or to ban temporarily or
41 | permanently any contributor for other behaviors that they deem inappropriate,
42 | threatening, offensive, or harmful.
43 |
44 | ## Scope
45 |
46 | This Code of Conduct applies both within project spaces and in public spaces
47 | when an individual is representing the project or its community. Examples of
48 | representing a project or community include using an official project e-mail
49 | address, posting via an official social media account, or acting as an appointed
50 | representative at an online or offline event. Representation of a project may be
51 | further defined and clarified by project maintainers.
52 |
53 | ## Enforcement
54 |
55 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
56 | reported by contacting the project team at conduct@juggle.ltd. All
57 | complaints will be reviewed and investigated and will result in a response that
58 | is deemed necessary and appropriate to the circumstances. The project team is
59 | obligated to maintain confidentiality with regard to the reporter of an incident.
60 | Further details of specific enforcement policies may be posted separately.
61 |
62 | Project maintainers who do not follow or enforce the Code of Conduct in good
63 | faith may face temporary or permanent repercussions as determined by other
64 | members of the project's leadership.
65 |
66 | ---
67 |
68 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
69 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
70 |
71 | [homepage]: https://www.contributor-covenant.org
72 |
73 | For answers to common questions about this code of conduct, see
74 | https://www.contributor-covenant.org/faq
75 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2019 JUGGLE LTD
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Resize Observer
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ---
15 |
16 | A minimal library which polyfills the **ResizeObserver** API and is entirely based on the latest [Specification](https://www.w3.org/TR/resize-observer/).
17 |
18 | It immediately detects when an element resizes and provides accurate sizing information back to the handler. Check out the [Example Playground](//juggle.studio/resize-observer) for more information on usage and performance.
19 |
20 | > The latest [Resize Observer specification](https://www.w3.org/TR/resize-observer/) is not yet finalised and is subject to change.
21 | > Any drastic changes to the specification will bump the major version of this library, as there will likely be breaking changes. Check the [release notes](https://github.com/juggle/resize-observer/releases) for more information.
22 |
23 |
24 | ## Installation
25 | ``` shell
26 | npm i @juggle/resize-observer
27 | ```
28 |
29 | ## Basic usage
30 | ``` js
31 | import { ResizeObserver } from '@juggle/resize-observer';
32 |
33 | const ro = new ResizeObserver((entries, observer) => {
34 | console.log('Body has resized!');
35 | observer.disconnect(); // Stop observing
36 | });
37 |
38 | ro.observe(document.body); // Watch dimension changes on body
39 | ```
40 | This will use the [ponyfilled](https://github.com/sindresorhus/ponyfill) version of **ResizeObserver**, even if the browser supports **ResizeObserver** natively.
41 |
42 | ## Watching multiple elements
43 | ``` js
44 | import { ResizeObserver } from '@juggle/resize-observer';
45 |
46 | const ro = new ResizeObserver((entries, observer) => {
47 | console.log('Elements resized:', entries.length);
48 | entries.forEach((entry, index) => {
49 | const { inlineSize: width, blockSize: height } = entry.contentBoxSize[0];
50 | console.log(`Element ${index + 1}:`, `${width}x${height}`);
51 | });
52 | });
53 |
54 | const els = document.querySelectorAll('.resizes');
55 | [...els].forEach(el => ro.observe(el)); // Watch multiple!
56 | ```
57 |
58 | ## Watching different box sizes
59 |
60 | The latest standards allow for watching different box sizes. The box size option can be specified when observing an element. Options include `border-box`, `device-pixel-content-box` and `content-box` (default).
61 | ``` js
62 | import { ResizeObserver } from '@juggle/resize-observer';
63 |
64 | const ro = new ResizeObserver((entries, observer) => {
65 | console.log('Elements resized:', entries.length);
66 | entries.forEach((entry, index) => {
67 | const [size] = entry.borderBoxSize;
68 | console.log(`Element ${index + 1}:`, `${size.inlineSize}x${size.blockSize}`);
69 | });
70 | });
71 |
72 | // Watch border-box
73 | const observerOptions = {
74 | box: 'border-box'
75 | };
76 |
77 | const els = document.querySelectorAll('.resizes');
78 | [...els].forEach(el => ro.observe(el, observerOptions));
79 | ```
80 | *From the spec:*
81 | > The box size properties are exposed as sequences in order to support elements that have multiple fragments, which occur in [multi-column](https://www.w3.org/TR/css3-multicol/#) scenarios. However the current definitions of content rect and border box do not mention how those boxes are affected by multi-column layout. In this spec, there will only be a single ResizeObserverSize returned in the sequences, which will correspond to the dimensions of the first column. A future version of this spec will extend the returned sequences to contain the per-fragment size information.
82 |
83 | ## Using the legacy version (`contentRect`)
84 |
85 | Early versions of the API return a `contentRect`. This is still made available for backwards compatibility.
86 |
87 | ``` js
88 | import { ResizeObserver } from '@juggle/resize-observer';
89 |
90 | const ro = new ResizeObserver((entries, observer) => {
91 | console.log('Elements resized:', entries.length);
92 | entries.forEach((entry, index) => {
93 | const { width, height } = entry.contentRect;
94 | console.log(`Element ${index + 1}:`, `${width}x${height}`);
95 | });
96 | });
97 |
98 | const els = document.querySelectorAll('.resizes');
99 | [...els].forEach(el => ro.observe(el));
100 | ```
101 |
102 |
103 | ## Switching between native and polyfilled versions
104 |
105 | You can check to see if the native version is available and switch between this and the polyfill to improve performance on browsers with native support.
106 |
107 | ``` js
108 | import { ResizeObserver as Polyfill } from '@juggle/resize-observer';
109 |
110 | const ResizeObserver = window.ResizeObserver || Polyfill;
111 |
112 | // Uses native or polyfill, depending on browser support.
113 | const ro = new ResizeObserver((entries, observer) => {
114 | console.log('Something has resized!');
115 | });
116 | ```
117 |
118 | To improve this even more, you could use dynamic imports to only load the file when the polyfill is required.
119 |
120 | ``` js
121 | (async () => {
122 | if ('ResizeObserver' in window === false) {
123 | // Loads polyfill asynchronously, only if required.
124 | const module = await import('@juggle/resize-observer');
125 | window.ResizeObserver = module.ResizeObserver;
126 | }
127 | // Uses native or polyfill, depending on browser support.
128 | const ro = new ResizeObserver((entries, observer) => {
129 | console.log('Something has resized!');
130 | });
131 | })();
132 | ```
133 |
134 | > Browsers with native support may be behind on the latest specification.
135 | > Use `entry.contentRect` when switching between native and polyfilled versions.
136 |
137 |
138 | ## Resize loop detection
139 |
140 | Resize Observers have inbuilt protection against infinite resize loops.
141 |
142 | If an element's observed box size changes again within the same resize loop, the observation will be skipped and an error event will be dispatched on the window. Elements with undelivered notifications will be considered for delivery in the next loop.
143 |
144 | ```js
145 | import { ResizeObserver } from '@juggle/resize-observer';
146 |
147 | const ro = new ResizeObserver((entries, observer) => {
148 | // Changing the body size inside of the observer
149 | // will cause a resize loop and the next observation will be skipped
150 | document.body.style.width = '50%';
151 | });
152 |
153 | // Listen for errors
154 | window.addEventListener('error', e => console.log(e.message));
155 |
156 | // Observe the body
157 | ro.observe(document.body);
158 | ```
159 |
160 | ## Notification Schedule
161 | Notifications are scheduled after all other changes have occurred and all other animation callbacks have been called. This allows the observer callback to get the most accurate size of an element, as no other changes should occur in the same frame.
162 |
163 | 
164 |
165 |
166 |
167 | ## How are differences detected?
168 |
169 | To prevent constant polling, every frame. The DOM is queried whenever an event occurs which could cause an element to change its size. This could be when an element is clicked, a DOM Node is added, or, when an animation is running.
170 |
171 | To cover these scenarios, there are two types of observation. The first is to listen to specific DOM events, including `resize`, `mousedown` and `focus` to name a few. The second is to listen for any DOM mutations that occur. This detects when a DOM node is added or removed, an attribute is modified, or, even when some text has changed.
172 |
173 | This allows for greater idle time, when the application itself is idle.
174 |
175 |
176 | ## Features
177 |
178 | - Inbuilt resize loop protection.
179 | - Supports pseudo classes `:hover`, `:active` and `:focus`.
180 | - Supports transitions and animations, including infinite and long-running.
181 | - Detects changes which occur during animation frame.
182 | - Includes support for latest draft spec - observing different box sizes.
183 | - Polls only when required, then shuts down automatically, reducing CPU usage.
184 | - Zero delay system - Notifications are batched and delivered immediately, before the next paint.
185 |
186 |
187 | ## Limitations
188 |
189 | - Transitions with initial delays cannot be detected.*
190 | - Animations and transitions with long periods of no change, will not be detected.*
191 | - Style changes from dev tools will only be noticed if they are inline styles.*
192 |
193 |
194 | ## Tested Browsers
195 |
196 | [chrome]: https://github.com/alrra/browser-logos/raw/master/src/chrome/chrome_64x64.png
197 | [safari]: https://github.com/alrra/browser-logos/raw/master/src/safari/safari_64x64.png
198 | [safari-ios]: https://github.com/alrra/browser-logos/raw/master/src/safari-ios/safari-ios_64x64.png
199 | [ff]: https://github.com/alrra/browser-logos/raw/master/src/firefox/firefox_64x64.png
200 | [opera]: https://github.com/alrra/browser-logos/raw/master/src/opera/opera_64x64.png
201 | [opera-mini]: https://github.com/alrra/browser-logos/raw/master/src/opera-mini/opera-mini_64x64.png
202 | [edge_12-18]: https://github.com/alrra/browser-logos/raw/master/src/archive/edge_12-18/edge_12-18_64x64.png
203 | [edge]: https://github.com/alrra/browser-logos/raw/master/src/edge/edge_64x64.png
204 | [samsung]: https://github.com/alrra/browser-logos/raw/master/src/samsung-internet/samsung-internet_64x64.png
205 | [ie]: https://github.com/alrra/browser-logos/raw/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_64x64.png
206 |
207 | ### Desktop
208 | | ![chrome][chrome] | ![safari][safari] | ![ff][ff] | ![opera][opera] | ![edge][edge] | ![edge][edge_12-18] | ![IE][ie] |
209 | |--------|--------|---------|-------|------|------------|---------------------------------------|
210 | | Chrome | Safari | Firefox | Opera | Edge | Edge 12-18 | IE11 IE 9-10 (with polyfills)\*\* |
211 |
212 | ### Mobile
213 | | ![chrome][chrome] | ![safari][safari] | ![ff][ff] | ![opera][opera] | ![opera mini][opera-mini] | ![edge][edge_12-18] | ![samsung internet][samsung] |
214 | |--------|--------|---------|-------|------------|------|------------------|
215 | | Chrome | Safari | Firefox | Opera | Opera Mini | Edge | Samsung Internet |
216 |
217 | ---
218 |
219 | \*If other interaction occurs, changes will be detected.
220 |
221 | \*\*IE10 requires additional polyfills for `WeakMap`, `MutationObserver` and `devicePixelRatio`. IE9 requires IE10 polyfills plus `requestAnimationFrame`. For more information, [see issue here](https://github.com/juggle/resize-observer/issues/64).
222 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 | Resize Observer Polyfill Installation Install the package from npm.
2 |
3 | npm i @juggle/resize-observer
4 |
5 | Once installed, you can import it like any other module.
6 |
7 | import { ResizeObserver } from '@juggle/resize-observer';
8 |
9 | Usage
10 |
11 | import { ResizeObserver } from '@juggle/resize-observer';
12 |
13 | const ro = new ResizeObserver((entries, observer) => {
14 | for (let entry of entries) {
15 | const { inlineSize, blockSize } = entry.contentBoxSize;
16 | const { width, height } = entry.contentRect; // use for backwards compatibility
17 | entry.target.innerText = `${inlineSize} x ${blockSize}`;
18 | }
19 | });
20 |
21 | ro.observe(someElement);
22 |
23 |
Pseudo Classes The library supports user-actioned pseudo classes, like :hover, :active, :focus
Hover, click or focus me.
Animations* The library will detect changes which occur during animations.
Tap me.
Transitions* The library will detect changes which occur during transition.
Tap me.
NB: Slow-starting transitions may not be noticed, unless, other interactions occur in the application. Any missed calculations will be noticed at the end of the transition.
Performance Test This animates 200 elements and counts the changes. To start/stop the animation, tap the cell area.
Updates: 0
* Once the animation, or, transition has finished, the observer will sleep and wait for the next interaction. This keeps CPU idle, reducing battery consumption on portable devices.
--------------------------------------------------------------------------------
/docs/page.07eb8115.css:
--------------------------------------------------------------------------------
1 | html{height:100%;font-family:Heebo,sans-serif;font-size:12pt;font-weight:300;background:#f3f3f6;color:#454548}body{margin:0 auto;padding:40px;max-width:900px}:focus{outline-color:#f35}h1,h2,h3,h4,h5,h6{font-weight:400}h1{font-size:40pt;line-height:1}h2{margin:50px 0 0}hr{margin:50px 0 20px;border:none;height:1px;background:rgba(0,0,0,.2)}header{display:flex;flex-flow:row wrap;align-items:center;justify-content:space-between}header h1{margin:0}header a{flex:0 0 auto;margin:20px 0}header div{flex:1 1 100%}pre code.hljs{padding:0 1em;box-shadow:inset 0 0 4px rgba(0,0,0,.3);background:#fff}#performance-example div,[resize]{min-width:100px;min-height:100px;height:100px;position:relative;white-space:nowrap;background:#f35;color:#fff;display:flex;flex-direction:column;justify-content:center;align-items:center;margin:20px auto;user-select:none;box-sizing:border-box;background-clip:content-box;border:0 solid rgba(0,0,0,.2);cursor:pointer}[resize]:after{content:attr(dimensions);font-weight:400;padding:2px 5px 0}#pseudo-example:focus,#pseudo-example:hover{border-width:0}#pseudo-example:active{border-width:5px}#transition-example{transition:border-width 1s ease}#transition-example[fill]{border-width:0}#animation-example{animation:fill-in-out 1s infinite alternate;animation-play-state:paused}#animation-example[animate]{animation-play-state:running}#performance-example{display:flex;flex-flow:row wrap;animation:squeeze-in-out 1s infinite alternate;animation-play-state:paused;width:100%;margin:0;font-size:50%;cursor:pointer}#performance-example:hover{outline:1px solid #f35}#performance-example[animate]{animation-play-state:running}#performance-example div{margin:2px;flex:1 1 auto;min-width:0;min-height:10px;width:calc(5% - 4px);height:auto}.interactive-example{border-width:0 20vw}@media (min-width:900px){.interactive-example{border-width:0 200px}}@keyframes fill-in-out{to{border-width:0}}@keyframes squeeze-in-out{to{width:50%}}
2 | /*# sourceMappingURL=page.07eb8115.css.map */
--------------------------------------------------------------------------------
/docs/page.07eb8115.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["page.css"],"names":[],"mappings":"AAAA,KACE,WAAY,CACZ,4BAA6B,CAC7B,cAAe,CACf,eAAgB,CAChB,kBAAmB,CACnB,aACF,CAEA,KACE,aAAc,CACd,YAAa,CACb,eACF,CAEA,OACE,kBACF,CAEA,kBACE,eACF,CAEA,GACE,cAAe,CACf,aACF,CAEA,GACE,eACF,CAEA,GACE,kBAAmB,CACnB,WAAY,CACZ,UAAW,CACX,yBACF,CAEA,OACE,YAAa,CACb,kBAAmB,CACnB,kBAAmB,CACnB,6BACF,CAEA,UACE,QACF,CAEA,SACE,aAAc,CACd,aACF,CAEA,WACE,aACF,CAEA,cACE,aAAc,CACd,uCAAwC,CACxC,eACF,CAEA,kCAEE,eAAgB,CAChB,gBAAiB,CACjB,YAAa,CACb,iBAAkB,CAClB,kBAAmB,CACnB,eAAgB,CAChB,UAAW,CACX,YAAa,CACb,qBAAsB,CACtB,sBAAuB,CACvB,kBAAmB,CACnB,gBAAiB,CACjB,gBAAiB,CACjB,qBAAsB,CACtB,2BAA4B,CAC5B,6BAA8B,CAC9B,cACF,CAEA,eACE,wBAAyB,CACzB,eAAgB,CAChB,iBACF,CAEA,4CACE,cACF,CAEA,uBACE,gBACF,CAEA,oBACE,+BACF,CAEA,0BACE,cACF,CAEA,mBACE,2CAA4C,CAC5C,2BACF,CAEA,4BACE,4BACF,CAEA,qBACE,YAAa,CACb,kBAAmB,CACnB,8CAA+C,CAC/C,2BAA4B,CAC5B,UAAW,CACX,QAAS,CACT,aAAc,CACd,cACF,CAEA,2BACE,sBACF,CAEA,8BACE,4BACF,CAEA,yBACE,UAAW,CACX,aAAc,CACd,WAAY,CACZ,eAAgB,CAChB,oBAAqB,CACrB,WACF,CAEA,qBACE,mBACF,CAEA,yBACE,qBACI,oBACJ,CACF,CAEA,uBACE,GACI,cACJ,CACF,CAEA,0BACE,GACI,SACJ,CACF","file":"page.07eb8115.css","sourceRoot":"src","sourcesContent":["html {\n height: 100%;\n font-family: Heebo,sans-serif;\n font-size: 12pt;\n font-weight: 300;\n background: #f3f3f6;\n color: #454548\n}\n\nbody {\n margin: 0 auto;\n padding: 40px;\n max-width: 900px\n}\n\n:focus {\n outline-color: #f35\n}\n\nh1,h2,h3,h4,h5,h6 {\n font-weight: 400\n}\n\nh1 {\n font-size: 40pt;\n line-height: 1\n}\n\nh2 {\n margin: 50px 0 0\n}\n\nhr {\n margin: 50px 0 20px;\n border: none;\n height: 1px;\n background: rgba(0,0,0,.2)\n}\n\nheader {\n display: flex;\n flex-flow: row wrap;\n align-items: center;\n justify-content: space-between\n}\n\nheader h1 {\n margin: 0\n}\n\nheader a {\n flex: 0 0 auto;\n margin: 20px 0\n}\n\nheader div {\n flex: 1 1 100%\n}\n\npre code.hljs {\n padding: 0 1em;\n box-shadow: inset 0 0 4px rgba(0,0,0,.3);\n background: #fff\n}\n\n[resize],\n#performance-example div {\n min-width: 100px;\n min-height: 100px;\n height: 100px;\n position: relative;\n white-space: nowrap;\n background: #f35;\n color: #fff;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n margin: 20px auto;\n user-select: none;\n box-sizing: border-box;\n background-clip: content-box;\n border: 0 solid rgba(0,0,0,.2);\n cursor: pointer\n}\n\n[resize]:after {\n content: attr(dimensions);\n font-weight: 400;\n padding: 2px 5px 0\n}\n\n#pseudo-example:focus,#pseudo-example:hover {\n border-width: 0\n}\n\n#pseudo-example:active {\n border-width: 5px\n}\n\n#transition-example {\n transition: border-width 1s ease\n}\n\n#transition-example[fill] {\n border-width: 0\n}\n\n#animation-example {\n animation: fill-in-out 1s infinite alternate;\n animation-play-state: paused\n}\n\n#animation-example[animate] {\n animation-play-state: running\n}\n\n#performance-example {\n display: flex;\n flex-flow: row wrap;\n animation: squeeze-in-out 1s infinite alternate;\n animation-play-state: paused;\n width: 100%;\n margin: 0;\n font-size: 50%;\n cursor: pointer\n}\n\n#performance-example:hover {\n outline: 1px solid #f35\n}\n\n#performance-example[animate] {\n animation-play-state: running\n}\n\n#performance-example div {\n margin: 2px;\n flex: 1 1 auto;\n min-width: 0;\n min-height: 10px;\n width: calc(5% - 4px);\n height: auto\n}\n\n.interactive-example {\n border-width: 0 20vw\n}\n\n@media (min-width: 900px) {\n .interactive-example {\n border-width:0 200px\n }\n}\n\n@keyframes fill-in-out {\n to {\n border-width: 0\n }\n}\n\n@keyframes squeeze-in-out {\n to {\n width: 50%\n }\n}\n"]}
--------------------------------------------------------------------------------
/docs/page.287107b2.js:
--------------------------------------------------------------------------------
1 | parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c0?r:o)(t)};
74 | },{}],"rbgI":[function(require,module,exports) {
75 | var e=require("../internals/to-integer"),r=Math.min;module.exports=function(n){return n>0?r(e(n),9007199254740991):0};
76 | },{"../internals/to-integer":"GLNM"}],"j8pk":[function(require,module,exports) {
77 | var r=require("../internals/to-integer"),e=Math.max,t=Math.min;module.exports=function(n,a){var i=r(n);return i<0?e(i+a,0):t(i,a)};
78 | },{"../internals/to-integer":"GLNM"}],"aslv":[function(require,module,exports) {
79 | var e=require("../internals/to-indexed-object"),r=require("../internals/to-length"),n=require("../internals/to-absolute-index"),t=function(t){return function(i,u,o){var l,f=e(i),s=r(f.length),a=n(o,s);if(t&&u!=u){for(;s>a;)if((l=f[a++])!=l)return!0}else for(;s>a;a++)if((t||a in f)&&f[a]===u)return t||a||0;return!t&&-1}};module.exports={includes:t(!0),indexOf:t(!1)};
80 | },{"../internals/to-indexed-object":"ZYi5","../internals/to-length":"rbgI","../internals/to-absolute-index":"j8pk"}],"MIhG":[function(require,module,exports) {
81 | var e=require("../internals/has"),r=require("../internals/to-indexed-object"),n=require("../internals/array-includes").indexOf,i=require("../internals/hidden-keys");module.exports=function(s,t){var u,a=r(s),d=0,l=[];for(u in a)!e(i,u)&&e(a,u)&&l.push(u);for(;t.length>d;)e(a,u=t[d++])&&(~n(l,u)||l.push(u));return l};
82 | },{"../internals/has":"AVGS","../internals/to-indexed-object":"ZYi5","../internals/array-includes":"aslv","../internals/hidden-keys":"Ci1Z"}],"Mlyz":[function(require,module,exports) {
83 | module.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"];
84 | },{}],"nW2X":[function(require,module,exports) {
85 | var e=require("../internals/object-keys-internal"),r=require("../internals/enum-bug-keys"),t=r.concat("length","prototype");exports.f=Object.getOwnPropertyNames||function(r){return e(r,t)};
86 | },{"../internals/object-keys-internal":"MIhG","../internals/enum-bug-keys":"Mlyz"}],"hHZK":[function(require,module,exports) {
87 | exports.f=Object.getOwnPropertySymbols;
88 | },{}],"i48x":[function(require,module,exports) {
89 | var e=require("../internals/get-built-in"),r=require("../internals/object-get-own-property-names"),n=require("../internals/object-get-own-property-symbols"),t=require("../internals/an-object");module.exports=e("Reflect","ownKeys")||function(e){var o=r.f(t(e)),i=n.f;return i?o.concat(i(e)):o};
90 | },{"../internals/get-built-in":"JxF1","../internals/object-get-own-property-names":"nW2X","../internals/object-get-own-property-symbols":"hHZK","../internals/an-object":"qC4L"}],"R2j1":[function(require,module,exports) {
91 | var e=require("../internals/has"),r=require("../internals/own-keys"),n=require("../internals/object-get-own-property-descriptor"),t=require("../internals/object-define-property");module.exports=function(i,o){for(var a=r(o),s=t.f,l=n.f,p=0;p=74)&&(e=n.match(/Chrome\/(\d+)/))&&(r=e[1]),module.exports=r&&+r;
118 | },{"../internals/global":"hMWN","../internals/engine-user-agent":"A4Gh"}],"RyUu":[function(require,module,exports) {
119 | var n=require("../internals/fails"),e=require("../internals/well-known-symbol"),r=require("../internals/engine-v8-version"),o=e("species");module.exports=function(e){return r>=51||!n(function(){var n=[];return(n.constructor={})[o]=function(){return{foo:1}},1!==n[e](Boolean).foo})};
120 | },{"../internals/fails":"VHEc","../internals/well-known-symbol":"wid3","../internals/engine-v8-version":"q1lM"}],"JMi6":[function(require,module,exports) {
121 | "use strict";var r=require("../internals/export"),e=require("../internals/fails"),n=require("../internals/is-array"),t=require("../internals/is-object"),i=require("../internals/to-object"),a=require("../internals/to-length"),o=require("../internals/create-property"),s=require("../internals/array-species-create"),l=require("../internals/array-method-has-species-support"),u=require("../internals/well-known-symbol"),c=require("../internals/engine-v8-version"),f=u("isConcatSpreadable"),p=9007199254740991,q="Maximum allowed index exceeded",h=c>=51||!e(function(){var r=[];return r[f]=!1,r.concat()[0]!==r}),d=l("concat"),y=function(r){if(!t(r))return!1;var e=r[f];return void 0!==e?!!e:n(r)},v=!h||!d;r({target:"Array",proto:!0,forced:v},{concat:function(r){var e,n,t,l,u,c=i(this),f=s(c,0),h=0;for(e=-1,t=arguments.length;ep)throw TypeError(q);for(n=0;n=p)throw TypeError(q);o(f,h++,u)}return f.length=h,f}});
122 | },{"../internals/export":"f0wc","../internals/fails":"VHEc","../internals/is-array":"eKnz","../internals/is-object":"G5vJ","../internals/to-object":"DPzV","../internals/to-length":"rbgI","../internals/create-property":"oe9D","../internals/array-species-create":"w4zm","../internals/array-method-has-species-support":"RyUu","../internals/well-known-symbol":"wid3","../internals/engine-v8-version":"q1lM"}],"pUQj":[function(require,module,exports) {
123 | var e=require("../internals/well-known-symbol"),r=e("toStringTag"),n={};n[r]="z",module.exports="[object z]"===String(n);
124 | },{"../internals/well-known-symbol":"wid3"}],"SwVB":[function(require,module,exports) {
125 | var n=require("../internals/to-string-tag-support"),r=require("../internals/classof-raw"),t=require("../internals/well-known-symbol"),e=t("toStringTag"),u="Arguments"==r(function(){return arguments}()),i=function(n,r){try{return n[r]}catch(t){}};module.exports=n?r:function(n){var t,o,l;return void 0===n?"Undefined":null===n?"Null":"string"==typeof(o=i(t=Object(n),e))?o:u?r(t):"Object"==(l=r(t))&&"function"==typeof t.callee?"Arguments":l};
126 | },{"../internals/to-string-tag-support":"pUQj","../internals/classof-raw":"JYUw","../internals/well-known-symbol":"wid3"}],"fMfW":[function(require,module,exports) {
127 | "use strict";var t=require("../internals/to-string-tag-support"),r=require("../internals/classof");module.exports=t?{}.toString:function(){return"[object "+r(this)+"]"};
128 | },{"../internals/to-string-tag-support":"pUQj","../internals/classof":"SwVB"}],"jqXL":[function(require,module,exports) {
129 | var e=require("../internals/to-string-tag-support"),r=require("../internals/redefine"),t=require("../internals/object-to-string");e||r(Object.prototype,"toString",t,{unsafe:!0});
130 | },{"../internals/to-string-tag-support":"pUQj","../internals/redefine":"cGjs","../internals/object-to-string":"fMfW"}],"OugX":[function(require,module,exports) {
131 | var e=require("../internals/object-keys-internal"),r=require("../internals/enum-bug-keys");module.exports=Object.keys||function(n){return e(n,r)};
132 | },{"../internals/object-keys-internal":"MIhG","../internals/enum-bug-keys":"Mlyz"}],"Gy1S":[function(require,module,exports) {
133 | var e=require("../internals/descriptors"),r=require("../internals/object-define-property"),n=require("../internals/an-object"),t=require("../internals/object-keys");module.exports=e?Object.defineProperties:function(e,i){n(e);for(var o,s=t(i),a=s.length,u=0;a>u;)r.f(e,o=s[u++],i[o]);return e};
134 | },{"../internals/descriptors":"A0tX","../internals/object-define-property":"SKnA","../internals/an-object":"qC4L","../internals/object-keys":"OugX"}],"g9IP":[function(require,module,exports) {
135 | var e=require("../internals/get-built-in");module.exports=e("document","documentElement");
136 | },{"../internals/get-built-in":"JxF1"}],"FUoc":[function(require,module,exports) {
137 | var e,n=require("../internals/an-object"),r=require("../internals/object-define-properties"),t=require("../internals/enum-bug-keys"),i=require("../internals/hidden-keys"),u=require("../internals/html"),o=require("../internals/document-create-element"),c=require("../internals/shared-key"),l=">",a="<",s="prototype",d="script",m=c("IE_PROTO"),p=function(){},f=function(e){return a+d+l+e+a+"/"+d+l},v=function(e){e.write(f("")),e.close();var n=e.parentWindow.Object;return e=null,n},b=function(){var e,n=o("iframe"),r="java"+d+":";return n.style.display="none",u.appendChild(n),n.src=String(r),(e=n.contentWindow.document).open(),e.write(f("document.F=Object")),e.close(),e.F},h=function(){try{e=document.domain&&new ActiveXObject("htmlfile")}catch(r){}h=e?v(e):b();for(var n=t.length;n--;)delete h[s][t[n]];return h()};i[m]=!0,module.exports=Object.create||function(e,t){var i;return null!==e?(p[s]=n(e),i=new p,p[s]=null,i[m]=e):i=h(),void 0===t?i:r(i,t)};
138 | },{"../internals/an-object":"qC4L","../internals/object-define-properties":"Gy1S","../internals/enum-bug-keys":"Mlyz","../internals/hidden-keys":"Ci1Z","../internals/html":"g9IP","../internals/document-create-element":"gVEz","../internals/shared-key":"Xta8"}],"YZTz":[function(require,module,exports) {
139 | var e=require("../internals/to-indexed-object"),t=require("../internals/object-get-own-property-names").f,r={}.toString,n="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[],o=function(e){try{return t(e)}catch(r){return n.slice()}};module.exports.f=function(i){return n&&"[object Window]"==r.call(i)?o(i):t(e(i))};
140 | },{"../internals/to-indexed-object":"ZYi5","../internals/object-get-own-property-names":"nW2X"}],"E4AG":[function(require,module,exports) {
141 | var e=require("../internals/well-known-symbol");exports.f=e;
142 | },{"../internals/well-known-symbol":"wid3"}],"lNii":[function(require,module,exports) {
143 | var e=require("../internals/path"),r=require("../internals/has"),n=require("../internals/well-known-symbol-wrapped"),l=require("../internals/object-define-property").f;module.exports=function(a){var i=e.Symbol||(e.Symbol={});r(i,a)||l(i,a,{value:n.f(a)})};
144 | },{"../internals/path":"Qpsm","../internals/has":"AVGS","../internals/well-known-symbol-wrapped":"E4AG","../internals/object-define-property":"SKnA"}],"j0g6":[function(require,module,exports) {
145 | var e=require("../internals/object-define-property").f,r=require("../internals/has"),n=require("../internals/well-known-symbol"),o=n("toStringTag");module.exports=function(n,t,i){n&&!r(n=i?n:n.prototype,o)&&e(n,o,{configurable:!0,value:t})};
146 | },{"../internals/object-define-property":"SKnA","../internals/has":"AVGS","../internals/well-known-symbol":"wid3"}],"Io0k":[function(require,module,exports) {
147 | module.exports=function(n){if("function"!=typeof n)throw TypeError(String(n)+" is not a function");return n};
148 | },{}],"cJAn":[function(require,module,exports) {
149 | var n=require("../internals/a-function");module.exports=function(r,t,e){if(n(r),void 0===t)return r;switch(e){case 0:return function(){return r.call(t)};case 1:return function(n){return r.call(t,n)};case 2:return function(n,e){return r.call(t,n,e)};case 3:return function(n,e,u){return r.call(t,n,e,u)}}return function(){return r.apply(t,arguments)}};
150 | },{"../internals/a-function":"Io0k"}],"yEAs":[function(require,module,exports) {
151 | var e=require("../internals/function-bind-context"),r=require("../internals/indexed-object"),n=require("../internals/to-object"),t=require("../internals/to-length"),i=require("../internals/array-species-create"),a=[].push,s=function(s){var c=1==s,u=2==s,l=3==s,o=4==s,f=6==s,d=7==s,h=5==s||f;return function(q,v,p,x){for(var b,m,g=n(q),j=r(g),w=e(v,p,3),y=t(j.length),E=0,I=x||i,O=c?I(q,y):u||d?I(q,0):void 0;y>E;E++)if((h||E in j)&&(m=w(b=j[E],E,g),s))if(c)O[E]=m;else if(m)switch(s){case 3:return!0;case 5:return b;case 6:return E;case 2:a.call(O,b)}else switch(s){case 4:return!1;case 7:a.call(O,b)}return f?-1:l||o?o:O}};module.exports={forEach:s(0),map:s(1),filter:s(2),some:s(3),every:s(4),find:s(5),findIndex:s(6),filterOut:s(7)};
152 | },{"../internals/function-bind-context":"cJAn","../internals/indexed-object":"C2zD","../internals/to-object":"DPzV","../internals/to-length":"rbgI","../internals/array-species-create":"w4zm"}],"mTrD":[function(require,module,exports) {
153 |
154 | "use strict";var e=require("../internals/export"),r=require("../internals/global"),t=require("../internals/get-built-in"),n=require("../internals/is-pure"),i=require("../internals/descriptors"),o=require("../internals/native-symbol"),s=require("../internals/use-symbol-as-uid"),a=require("../internals/fails"),u=require("../internals/has"),l=require("../internals/is-array"),c=require("../internals/is-object"),f=require("../internals/an-object"),p=require("../internals/to-object"),y=require("../internals/to-indexed-object"),b=require("../internals/to-primitive"),d=require("../internals/create-property-descriptor"),g=require("../internals/object-create"),q=require("../internals/object-keys"),h=require("../internals/object-get-own-property-names"),m=require("../internals/object-get-own-property-names-external"),v=require("../internals/object-get-own-property-symbols"),w=require("../internals/object-get-own-property-descriptor"),j=require("../internals/object-define-property"),O=require("../internals/object-property-is-enumerable"),S=require("../internals/create-non-enumerable-property"),k=require("../internals/redefine"),P=require("../internals/shared"),E=require("../internals/shared-key"),x=require("../internals/hidden-keys"),N=require("../internals/uid"),F=require("../internals/well-known-symbol"),J=require("../internals/well-known-symbol-wrapped"),T=require("../internals/define-well-known-symbol"),C=require("../internals/set-to-string-tag"),D=require("../internals/internal-state"),I=require("../internals/array-iteration").forEach,Q=E("hidden"),z="Symbol",A="prototype",B=F("toPrimitive"),G=D.set,H=D.getterFor(z),K=Object[A],L=r.Symbol,M=t("JSON","stringify"),R=w.f,U=j.f,V=m.f,W=O.f,X=P("symbols"),Y=P("op-symbols"),Z=P("string-to-symbol-registry"),$=P("symbol-to-string-registry"),_=P("wks"),ee=r.QObject,re=!ee||!ee[A]||!ee[A].findChild,te=i&&a(function(){return 7!=g(U({},"a",{get:function(){return U(this,"a",{value:7}).a}})).a})?function(e,r,t){var n=R(K,r);n&&delete K[r],U(e,r,t),n&&e!==K&&U(K,r,n)}:U,ne=function(e,r){var t=X[e]=g(L[A]);return G(t,{type:z,tag:e,description:r}),i||(t.description=r),t},ie=s?function(e){return"symbol"==typeof e}:function(e){return Object(e)instanceof L},oe=function(e,r,t){e===K&&oe(Y,r,t),f(e);var n=b(r,!0);return f(t),u(X,n)?(t.enumerable?(u(e,Q)&&e[Q][n]&&(e[Q][n]=!1),t=g(t,{enumerable:d(0,!1)})):(u(e,Q)||U(e,Q,d(1,{})),e[Q][n]=!0),te(e,n,t)):U(e,n,t)},se=function(e,r){f(e);var t=y(r),n=q(t).concat(fe(t));return I(n,function(r){i&&!ue.call(t,r)||oe(e,r,t[r])}),e},ae=function(e,r){return void 0===r?g(e):se(g(e),r)},ue=function(e){var r=b(e,!0),t=W.call(this,r);return!(this===K&&u(X,r)&&!u(Y,r))&&(!(t||!u(this,r)||!u(X,r)||u(this,Q)&&this[Q][r])||t)},le=function(e,r){var t=y(e),n=b(r,!0);if(t!==K||!u(X,n)||u(Y,n)){var i=R(t,n);return!i||!u(X,n)||u(t,Q)&&t[Q][n]||(i.enumerable=!0),i}},ce=function(e){var r=V(y(e)),t=[];return I(r,function(e){u(X,e)||u(x,e)||t.push(e)}),t},fe=function(e){var r=e===K,t=V(r?Y:y(e)),n=[];return I(t,function(e){!u(X,e)||r&&!u(K,e)||n.push(X[e])}),n};if(o||(k((L=function(){if(this instanceof L)throw TypeError("Symbol is not a constructor");var e=arguments.length&&void 0!==arguments[0]?String(arguments[0]):void 0,r=N(e),t=function(e){this===K&&t.call(Y,e),u(this,Q)&&u(this[Q],r)&&(this[Q][r]=!1),te(this,r,d(1,e))};return i&&re&&te(K,r,{configurable:!0,set:t}),ne(r,e)})[A],"toString",function(){return H(this).tag}),k(L,"withoutSetter",function(e){return ne(N(e),e)}),O.f=ue,j.f=oe,w.f=le,h.f=m.f=ce,v.f=fe,J.f=function(e){return ne(F(e),e)},i&&(U(L[A],"description",{configurable:!0,get:function(){return H(this).description}}),n||k(K,"propertyIsEnumerable",ue,{unsafe:!0}))),e({global:!0,wrap:!0,forced:!o,sham:!o},{Symbol:L}),I(q(_),function(e){T(e)}),e({target:z,stat:!0,forced:!o},{for:function(e){var r=String(e);if(u(Z,r))return Z[r];var t=L(r);return Z[r]=t,$[t]=r,t},keyFor:function(e){if(!ie(e))throw TypeError(e+" is not a symbol");if(u($,e))return $[e]},useSetter:function(){re=!0},useSimple:function(){re=!1}}),e({target:"Object",stat:!0,forced:!o,sham:!i},{create:ae,defineProperty:oe,defineProperties:se,getOwnPropertyDescriptor:le}),e({target:"Object",stat:!0,forced:!o},{getOwnPropertyNames:ce,getOwnPropertySymbols:fe}),e({target:"Object",stat:!0,forced:a(function(){v.f(1)})},{getOwnPropertySymbols:function(e){return v.f(p(e))}}),M){var pe=!o||a(function(){var e=L();return"[null]"!=M([e])||"{}"!=M({a:e})||"{}"!=M(Object(e))});e({target:"JSON",stat:!0,forced:pe},{stringify:function(e,r,t){for(var n,i=[e],o=1;arguments.length>o;)i.push(arguments[o++]);if(n=r,(c(r)||void 0!==e)&&!ie(e))return l(r)||(r=function(e,r){if("function"==typeof n&&(r=n.call(this,e,r)),!ie(r))return r}),i[1]=r,M.apply(null,i)}})}L[A][B]||S(L[A],B,L[A].valueOf),C(L,z),x[Q]=!0;
155 | },{"../internals/export":"f0wc","../internals/global":"hMWN","../internals/get-built-in":"JxF1","../internals/is-pure":"Wowg","../internals/descriptors":"A0tX","../internals/native-symbol":"IqWM","../internals/use-symbol-as-uid":"eGDz","../internals/fails":"VHEc","../internals/has":"AVGS","../internals/is-array":"eKnz","../internals/is-object":"G5vJ","../internals/an-object":"qC4L","../internals/to-object":"DPzV","../internals/to-indexed-object":"ZYi5","../internals/to-primitive":"SlNN","../internals/create-property-descriptor":"uvLZ","../internals/object-create":"FUoc","../internals/object-keys":"OugX","../internals/object-get-own-property-names":"nW2X","../internals/object-get-own-property-names-external":"YZTz","../internals/object-get-own-property-symbols":"hHZK","../internals/object-get-own-property-descriptor":"vuW7","../internals/object-define-property":"SKnA","../internals/object-property-is-enumerable":"ocnA","../internals/create-non-enumerable-property":"LCRa","../internals/redefine":"cGjs","../internals/shared":"yATA","../internals/shared-key":"Xta8","../internals/hidden-keys":"Ci1Z","../internals/uid":"Sp03","../internals/well-known-symbol":"wid3","../internals/well-known-symbol-wrapped":"E4AG","../internals/define-well-known-symbol":"lNii","../internals/set-to-string-tag":"j0g6","../internals/internal-state":"CDT7","../internals/array-iteration":"yEAs"}],"ErfE":[function(require,module,exports) {
156 | var e=require("../internals/define-well-known-symbol");e("asyncIterator");
157 | },{"../internals/define-well-known-symbol":"lNii"}],"mMjG":[function(require,module,exports) {
158 |
159 | "use strict";var r=require("../internals/export"),e=require("../internals/descriptors"),t=require("../internals/global"),i=require("../internals/has"),o=require("../internals/is-object"),n=require("../internals/object-define-property").f,s=require("../internals/copy-constructor-properties"),a=t.Symbol;if(e&&"function"==typeof a&&(!("description"in a.prototype)||void 0!==a().description)){var l={},c=function(){var r=arguments.length<1||void 0===arguments[0]?void 0:String(arguments[0]),e=this instanceof c?new a(r):void 0===r?a():a(r);return""===r&&(l[e]=!0),e};s(c,a);var p=c.prototype=a.prototype;p.constructor=c;var u=p.toString,v="Symbol(test)"==String(a("test")),f=/^Symbol\((.*)\)[^)]+$/;n(p,"description",{configurable:!0,get:function(){var r=o(this)?this.valueOf():this,e=u.call(r);if(i(l,r))return"";var t=v?e.slice(7,-1):e.replace(f,"$1");return""===t?void 0:t}}),r({global:!0,forced:!0},{Symbol:c})}
160 | },{"../internals/export":"f0wc","../internals/descriptors":"A0tX","../internals/global":"hMWN","../internals/has":"AVGS","../internals/is-object":"G5vJ","../internals/object-define-property":"SKnA","../internals/copy-constructor-properties":"R2j1"}],"PfKs":[function(require,module,exports) {
161 | var e=require("../internals/define-well-known-symbol");e("hasInstance");
162 | },{"../internals/define-well-known-symbol":"lNii"}],"nfvC":[function(require,module,exports) {
163 | var e=require("../internals/define-well-known-symbol");e("isConcatSpreadable");
164 | },{"../internals/define-well-known-symbol":"lNii"}],"XJDp":[function(require,module,exports) {
165 | var e=require("../internals/define-well-known-symbol");e("iterator");
166 | },{"../internals/define-well-known-symbol":"lNii"}],"MmMq":[function(require,module,exports) {
167 | var e=require("../internals/define-well-known-symbol");e("match");
168 | },{"../internals/define-well-known-symbol":"lNii"}],"EmQX":[function(require,module,exports) {
169 | var e=require("../internals/define-well-known-symbol");e("matchAll");
170 | },{"../internals/define-well-known-symbol":"lNii"}],"qzWI":[function(require,module,exports) {
171 | var e=require("../internals/define-well-known-symbol");e("replace");
172 | },{"../internals/define-well-known-symbol":"lNii"}],"dLGF":[function(require,module,exports) {
173 | var e=require("../internals/define-well-known-symbol");e("search");
174 | },{"../internals/define-well-known-symbol":"lNii"}],"li8I":[function(require,module,exports) {
175 | var e=require("../internals/define-well-known-symbol");e("species");
176 | },{"../internals/define-well-known-symbol":"lNii"}],"WCJQ":[function(require,module,exports) {
177 | var e=require("../internals/define-well-known-symbol");e("split");
178 | },{"../internals/define-well-known-symbol":"lNii"}],"eQT8":[function(require,module,exports) {
179 | var e=require("../internals/define-well-known-symbol");e("toPrimitive");
180 | },{"../internals/define-well-known-symbol":"lNii"}],"SJUK":[function(require,module,exports) {
181 | var e=require("../internals/define-well-known-symbol");e("toStringTag");
182 | },{"../internals/define-well-known-symbol":"lNii"}],"joJw":[function(require,module,exports) {
183 | var e=require("../internals/define-well-known-symbol");e("unscopables");
184 | },{"../internals/define-well-known-symbol":"lNii"}],"A3pC":[function(require,module,exports) {
185 |
186 | var r=require("../internals/global"),e=require("../internals/set-to-string-tag");e(r.JSON,"JSON",!0);
187 | },{"../internals/global":"hMWN","../internals/set-to-string-tag":"j0g6"}],"TeNu":[function(require,module,exports) {
188 | var t=require("../internals/set-to-string-tag");t(Math,"Math",!0);
189 | },{"../internals/set-to-string-tag":"j0g6"}],"mNp9":[function(require,module,exports) {
190 |
191 | var e=require("../internals/export"),r=require("../internals/global"),t=require("../internals/set-to-string-tag");e({global:!0},{Reflect:{}}),t(r.Reflect,"Reflect",!0);
192 | },{"../internals/export":"f0wc","../internals/global":"hMWN","../internals/set-to-string-tag":"j0g6"}],"S8DG":[function(require,module,exports) {
193 | require("../../modules/es.array.concat"),require("../../modules/es.object.to-string"),require("../../modules/es.symbol"),require("../../modules/es.symbol.async-iterator"),require("../../modules/es.symbol.description"),require("../../modules/es.symbol.has-instance"),require("../../modules/es.symbol.is-concat-spreadable"),require("../../modules/es.symbol.iterator"),require("../../modules/es.symbol.match"),require("../../modules/es.symbol.match-all"),require("../../modules/es.symbol.replace"),require("../../modules/es.symbol.search"),require("../../modules/es.symbol.species"),require("../../modules/es.symbol.split"),require("../../modules/es.symbol.to-primitive"),require("../../modules/es.symbol.to-string-tag"),require("../../modules/es.symbol.unscopables"),require("../../modules/es.json.to-string-tag"),require("../../modules/es.math.to-string-tag"),require("../../modules/es.reflect.to-string-tag");var e=require("../../internals/path");module.exports=e.Symbol;
194 | },{"../../modules/es.array.concat":"JMi6","../../modules/es.object.to-string":"jqXL","../../modules/es.symbol":"mTrD","../../modules/es.symbol.async-iterator":"ErfE","../../modules/es.symbol.description":"mMjG","../../modules/es.symbol.has-instance":"PfKs","../../modules/es.symbol.is-concat-spreadable":"nfvC","../../modules/es.symbol.iterator":"XJDp","../../modules/es.symbol.match":"MmMq","../../modules/es.symbol.match-all":"EmQX","../../modules/es.symbol.replace":"qzWI","../../modules/es.symbol.search":"dLGF","../../modules/es.symbol.species":"li8I","../../modules/es.symbol.split":"WCJQ","../../modules/es.symbol.to-primitive":"eQT8","../../modules/es.symbol.to-string-tag":"SJUK","../../modules/es.symbol.unscopables":"joJw","../../modules/es.json.to-string-tag":"A3pC","../../modules/es.math.to-string-tag":"TeNu","../../modules/es.reflect.to-string-tag":"mNp9","../../internals/path":"Qpsm"}],"dk9J":[function(require,module,exports) {
195 | var e=require("../internals/define-well-known-symbol");e("asyncDispose");
196 | },{"../internals/define-well-known-symbol":"lNii"}],"AsYz":[function(require,module,exports) {
197 | var e=require("../internals/define-well-known-symbol");e("dispose");
198 | },{"../internals/define-well-known-symbol":"lNii"}],"CXoT":[function(require,module,exports) {
199 | var e=require("../internals/define-well-known-symbol");e("observable");
200 | },{"../internals/define-well-known-symbol":"lNii"}],"kVY9":[function(require,module,exports) {
201 | var e=require("../internals/define-well-known-symbol");e("patternMatch");
202 | },{"../internals/define-well-known-symbol":"lNii"}],"aK0D":[function(require,module,exports) {
203 | var e=require("../internals/define-well-known-symbol");e("replaceAll");
204 | },{"../internals/define-well-known-symbol":"lNii"}],"gEL7":[function(require,module,exports) {
205 | var e=require("../../es/symbol");require("../../modules/esnext.symbol.async-dispose"),require("../../modules/esnext.symbol.dispose"),require("../../modules/esnext.symbol.observable"),require("../../modules/esnext.symbol.pattern-match"),require("../../modules/esnext.symbol.replace-all"),module.exports=e;
206 | },{"../../es/symbol":"S8DG","../../modules/esnext.symbol.async-dispose":"dk9J","../../modules/esnext.symbol.dispose":"AsYz","../../modules/esnext.symbol.observable":"CXoT","../../modules/esnext.symbol.pattern-match":"kVY9","../../modules/esnext.symbol.replace-all":"aK0D"}],"W3B8":[function(require,module,exports) {
207 | var e=require("../internals/to-integer"),r=require("../internals/require-object-coercible"),t=function(t){return function(n,i){var c,o,a=String(r(n)),u=e(i),l=a.length;return u<0||u>=l?t?"":void 0:(c=a.charCodeAt(u))<55296||c>56319||u+1===l||(o=a.charCodeAt(u+1))<56320||o>57343?t?a.charAt(u):c:t?a.slice(u,u+2):o-56320+(c-55296<<10)+65536}};module.exports={codeAt:t(!1),charAt:t(!0)};
208 | },{"../internals/to-integer":"GLNM","../internals/require-object-coercible":"kYMO"}],"IGCE":[function(require,module,exports) {
209 | var t=require("../internals/fails");module.exports=!t(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype});
210 | },{"../internals/fails":"VHEc"}],"QtYf":[function(require,module,exports) {
211 | var t=require("../internals/has"),e=require("../internals/to-object"),r=require("../internals/shared-key"),o=require("../internals/correct-prototype-getter"),n=r("IE_PROTO"),c=Object.prototype;module.exports=o?Object.getPrototypeOf:function(r){return r=e(r),t(r,n)?r[n]:"function"==typeof r.constructor&&r instanceof r.constructor?r.constructor.prototype:r instanceof Object?c:null};
212 | },{"../internals/has":"AVGS","../internals/to-object":"DPzV","../internals/shared-key":"Xta8","../internals/correct-prototype-getter":"IGCE"}],"YzQX":[function(require,module,exports) {
213 | "use strict";var e,r,t,n=require("../internals/fails"),i=require("../internals/object-get-prototype-of"),o=require("../internals/create-non-enumerable-property"),a=require("../internals/has"),l=require("../internals/well-known-symbol"),s=require("../internals/is-pure"),u=l("iterator"),p=!1,c=function(){return this};[].keys&&("next"in(t=[].keys())?(r=i(i(t)))!==Object.prototype&&(e=r):p=!0);var y=null==e||n(function(){var r={};return e[u].call(r)!==r});y&&(e={}),s&&!y||a(e,u)||o(e,u,c),module.exports={IteratorPrototype:e,BUGGY_SAFARI_ITERATORS:p};
214 | },{"../internals/fails":"VHEc","../internals/object-get-prototype-of":"QtYf","../internals/create-non-enumerable-property":"LCRa","../internals/has":"AVGS","../internals/well-known-symbol":"wid3","../internals/is-pure":"Wowg"}],"SMqC":[function(require,module,exports) {
215 | "use strict";var r=require("../internals/iterators-core").IteratorPrototype,e=require("../internals/object-create"),t=require("../internals/create-property-descriptor"),i=require("../internals/set-to-string-tag"),n=require("../internals/iterators"),o=function(){return this};module.exports=function(a,s,u){var c=s+" Iterator";return a.prototype=e(r,{next:t(1,u)}),i(a,c,!1,!0),n[c]=o,a};
216 | },{"../internals/iterators-core":"YzQX","../internals/object-create":"FUoc","../internals/create-property-descriptor":"uvLZ","../internals/set-to-string-tag":"j0g6","../internals/iterators":"Ci1Z"}],"lq3I":[function(require,module,exports) {
217 | var r=require("../internals/is-object");module.exports=function(t){if(!r(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype");return t};
218 | },{"../internals/is-object":"G5vJ"}],"hArh":[function(require,module,exports) {
219 | var t=require("../internals/an-object"),r=require("../internals/a-possible-prototype");module.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var e,o=!1,n={};try{(e=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(n,[]),o=n instanceof Array}catch(c){}return function(n,c){return t(n),r(c),o?e.call(n,c):n.__proto__=c,n}}():void 0);
220 | },{"../internals/an-object":"qC4L","../internals/a-possible-prototype":"lq3I"}],"IAEO":[function(require,module,exports) {
221 | "use strict";var e=require("../internals/export"),r=require("../internals/create-iterator-constructor"),t=require("../internals/object-get-prototype-of"),n=require("../internals/object-set-prototype-of"),i=require("../internals/set-to-string-tag"),o=require("../internals/create-non-enumerable-property"),s=require("../internals/redefine"),a=require("../internals/well-known-symbol"),u=require("../internals/is-pure"),c=require("../internals/iterators"),l=require("../internals/iterators-core"),f=l.IteratorPrototype,p=l.BUGGY_SAFARI_ITERATORS,q=a("iterator"),y="keys",w="values",b="entries",h=function(){return this};module.exports=function(a,l,g,m,v,A,I){r(g,l,m);var d,j,k,x=function(e){if(e===v&&T)return T;if(!p&&e in O)return O[e];switch(e){case y:case w:case b:return function(){return new g(this,e)}}return function(){return new g(this)}},R=l+" Iterator",G=!1,O=a.prototype,S=O[q]||O["@@iterator"]||v&&O[v],T=!p&&S||x(v),_="Array"==l&&O.entries||S;if(_&&(d=t(_.call(new a)),f!==Object.prototype&&d.next&&(u||t(d)===f||(n?n(d,f):"function"!=typeof d[q]&&o(d,q,h)),i(d,R,!0,!0),u&&(c[R]=h))),v==w&&S&&S.name!==w&&(G=!0,T=function(){return S.call(this)}),u&&!I||O[q]===T||o(O,q,T),c[l]=T,v)if(j={values:x(w),keys:A?T:x(y),entries:x(b)},I)for(k in j)!p&&!G&&k in O||s(O,k,j[k]);else e({target:l,proto:!0,forced:p||G},j);return j};
222 | },{"../internals/export":"f0wc","../internals/create-iterator-constructor":"SMqC","../internals/object-get-prototype-of":"QtYf","../internals/object-set-prototype-of":"hArh","../internals/set-to-string-tag":"j0g6","../internals/create-non-enumerable-property":"LCRa","../internals/redefine":"cGjs","../internals/well-known-symbol":"wid3","../internals/is-pure":"Wowg","../internals/iterators":"Ci1Z","../internals/iterators-core":"YzQX"}],"KrDM":[function(require,module,exports) {
223 | "use strict";var t=require("../internals/string-multibyte").charAt,e=require("../internals/internal-state"),r=require("../internals/define-iterator"),n="String Iterator",i=e.set,a=e.getterFor(n);r(String,"String",function(t){i(this,{type:n,string:String(t),index:0})},function(){var e,r=a(this),n=r.string,i=r.index;return i>=n.length?{value:void 0,done:!0}:(e=t(n,i),r.index+=e.length,{value:e,done:!1})});
224 | },{"../internals/string-multibyte":"W3B8","../internals/internal-state":"CDT7","../internals/define-iterator":"IAEO"}],"szps":[function(require,module,exports) {
225 | var r=require("../internals/an-object");module.exports=function(e){var n=e.return;if(void 0!==n)return r(n.call(e)).value};
226 | },{"../internals/an-object":"qC4L"}],"G08M":[function(require,module,exports) {
227 | var r=require("../internals/an-object"),e=require("../internals/iterator-close");module.exports=function(t,n,o,a){try{return a?n(r(o)[0],o[1]):n(o)}catch(i){throw e(t),i}};
228 | },{"../internals/an-object":"qC4L","../internals/iterator-close":"szps"}],"UZtA":[function(require,module,exports) {
229 | var r=require("../internals/well-known-symbol"),e=require("../internals/iterators"),t=r("iterator"),o=Array.prototype;module.exports=function(r){return void 0!==r&&(e.Array===r||o[t]===r)};
230 | },{"../internals/well-known-symbol":"wid3","../internals/iterators":"Ci1Z"}],"qAu1":[function(require,module,exports) {
231 | var r=require("../internals/classof"),e=require("../internals/iterators"),n=require("../internals/well-known-symbol"),t=n("iterator");module.exports=function(n){if(null!=n)return n[t]||n["@@iterator"]||e[r(n)]};
232 | },{"../internals/classof":"SwVB","../internals/iterators":"Ci1Z","../internals/well-known-symbol":"wid3"}],"jtFC":[function(require,module,exports) {
233 | "use strict";var e=require("../internals/function-bind-context"),r=require("../internals/to-object"),t=require("../internals/call-with-safe-iteration-closing"),n=require("../internals/is-array-iterator-method"),i=require("../internals/to-length"),l=require("../internals/create-property"),a=require("../internals/get-iterator-method");module.exports=function(o){var s,u,c,h,d,f,q=r(o),v="function"==typeof this?this:Array,g=arguments.length,y=g>1?arguments[1]:void 0,p=void 0!==y,m=a(q),w=0;if(p&&(y=e(y,g>2?arguments[2]:void 0,2)),null==m||v==Array&&n(m))for(u=new v(s=i(q.length));s>w;w++)f=p?y(q[w],w):q[w],l(u,w,f);else for(d=(h=m.call(q)).next,u=new v;!(c=d.call(h)).done;w++)f=p?t(h,y,[c.value,w],!0):c.value,l(u,w,f);return u.length=w,u};
234 | },{"../internals/function-bind-context":"cJAn","../internals/to-object":"DPzV","../internals/call-with-safe-iteration-closing":"G08M","../internals/is-array-iterator-method":"UZtA","../internals/to-length":"rbgI","../internals/create-property":"oe9D","../internals/get-iterator-method":"qAu1"}],"JwCU":[function(require,module,exports) {
235 | var r=require("../internals/well-known-symbol"),n=r("iterator"),t=!1;try{var e=0,o={next:function(){return{done:!!e++}},return:function(){t=!0}};o[n]=function(){return this},Array.from(o,function(){throw 2})}catch(u){}module.exports=function(r,e){if(!e&&!t)return!1;var o=!1;try{var i={};i[n]=function(){return{next:function(){return{done:o=!0}}}},r(i)}catch(u){}return o};
236 | },{"../internals/well-known-symbol":"wid3"}],"GHpI":[function(require,module,exports) {
237 | var r=require("../internals/export"),e=require("../internals/array-from"),t=require("../internals/check-correctness-of-iteration"),a=!t(function(r){Array.from(r)});r({target:"Array",stat:!0,forced:a},{from:e});
238 | },{"../internals/export":"f0wc","../internals/array-from":"jtFC","../internals/check-correctness-of-iteration":"JwCU"}],"HNym":[function(require,module,exports) {
239 | require("../../modules/es.string.iterator"),require("../../modules/es.array.from");var r=require("../../internals/path");module.exports=r.Array.from;
240 | },{"../../modules/es.string.iterator":"KrDM","../../modules/es.array.from":"GHpI","../../internals/path":"Qpsm"}],"ZAeP":[function(require,module,exports) {
241 | var r=require("../../es/array/from");module.exports=r;
242 | },{"../../es/array/from":"HNym"}],"nsde":[function(require,module,exports) {
243 | module.exports={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0};
244 | },{}],"EDaR":[function(require,module,exports) {
245 | var e=require("../internals/well-known-symbol"),r=require("../internals/object-create"),n=require("../internals/object-define-property"),l=e("unscopables"),o=Array.prototype;null==o[l]&&n.f(o,l,{configurable:!0,value:r(null)}),module.exports=function(e){o[l][e]=!0};
246 | },{"../internals/well-known-symbol":"wid3","../internals/object-create":"FUoc","../internals/object-define-property":"SKnA"}],"QTZT":[function(require,module,exports) {
247 | "use strict";var e=require("../internals/to-indexed-object"),r=require("../internals/add-to-unscopables"),t=require("../internals/iterators"),n=require("../internals/internal-state"),a=require("../internals/define-iterator"),i="Array Iterator",s=n.set,u=n.getterFor(i);module.exports=a(Array,"Array",function(r,t){s(this,{type:i,target:e(r),index:0,kind:t})},function(){var e=u(this),r=e.target,t=e.kind,n=e.index++;return!r||n>=r.length?(e.target=void 0,{value:void 0,done:!0}):"keys"==t?{value:n,done:!1}:"values"==t?{value:r[n],done:!1}:{value:[n,r[n]],done:!1}},"values"),t.Arguments=t.Array,r("keys"),r("values"),r("entries");
248 | },{"../internals/to-indexed-object":"ZYi5","../internals/add-to-unscopables":"EDaR","../internals/iterators":"Ci1Z","../internals/internal-state":"CDT7","../internals/define-iterator":"IAEO"}],"GjuJ":[function(require,module,exports) {
249 |
250 | var r=require("../internals/global"),e=require("../internals/dom-iterables"),a=require("../modules/es.array.iterator"),i=require("../internals/create-non-enumerable-property"),t=require("../internals/well-known-symbol"),n=t("iterator"),o=t("toStringTag"),l=a.values;for(var s in e){var u=r[s],f=u&&u.prototype;if(f){if(f[n]!==l)try{i(f,n,l)}catch(c){f[n]=l}if(f[o]||i(f,o,s),e[s])for(var y in a)if(f[y]!==a[y])try{i(f,y,a[y])}catch(c){f[y]=a[y]}}}
251 | },{"../internals/global":"hMWN","../internals/dom-iterables":"nsde","../modules/es.array.iterator":"QTZT","../internals/create-non-enumerable-property":"LCRa","../internals/well-known-symbol":"wid3"}],"DIOV":[function(require,module,exports) {
252 |
253 | var n=require("../internals/global"),e=require("../internals/function-bind-context"),r=Function.call;module.exports=function(t,o,i){return e(r,n[t].prototype[o],i)};
254 | },{"../internals/global":"hMWN","../internals/function-bind-context":"cJAn"}],"aDhd":[function(require,module,exports) {
255 | require("../../modules/web.dom-collections.iterator");var e=require("../../internals/entry-unbind");module.exports=e("Array","values");
256 | },{"../../modules/web.dom-collections.iterator":"GjuJ","../../internals/entry-unbind":"DIOV"}],"wBlj":[function(require,module,exports) {
257 | var e=require("../../stable/dom-collections/iterator");module.exports=e;
258 | },{"../../stable/dom-collections/iterator":"aDhd"}],"MO33":[function(require,module,exports) {
259 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resizeObservers=void 0;var e=[];exports.resizeObservers=e;
260 | },{}],"pdYF":[function(require,module,exports) {
261 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasActiveObservations=void 0;var e=require("../utils/resizeObservers"),r=function(){return e.resizeObservers.some(function(e){return e.activeTargets.length>0})};exports.hasActiveObservations=r;
262 | },{"../utils/resizeObservers":"MO33"}],"waFp":[function(require,module,exports) {
263 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasSkippedObservations=void 0;var e=require("../utils/resizeObservers"),r=function(){return e.resizeObservers.some(function(e){return e.skippedTargets.length>0})};exports.hasSkippedObservations=r;
264 | },{"../utils/resizeObservers":"MO33"}],"leLN":[function(require,module,exports) {
265 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.deliverResizeLoopError=void 0;var e="ResizeObserver loop completed with undelivered notifications.",r=function(){var r;"function"==typeof ErrorEvent?r=new ErrorEvent("error",{message:e}):((r=document.createEvent("Event")).initEvent("error",!1,!1),r.message=e),window.dispatchEvent(r)};exports.deliverResizeLoopError=r;
266 | },{}],"dDZ1":[function(require,module,exports) {
267 | "use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserverBoxOptions=void 0,exports.ResizeObserverBoxOptions=e,function(e){e.BORDER_BOX="border-box",e.CONTENT_BOX="content-box",e.DEVICE_PIXEL_CONTENT_BOX="device-pixel-content-box"}(e||(exports.ResizeObserverBoxOptions=e={}));
268 | },{}],"CLwC":[function(require,module,exports) {
269 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.freeze=void 0;var e=function(e){return Object.freeze(e)};exports.freeze=e;
270 | },{}],"rYLT":[function(require,module,exports) {
271 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserverSize=void 0;var e=require("./utils/freeze"),i=function(){return function(i,r){this.inlineSize=i,this.blockSize=r,(0,e.freeze)(this)}}();exports.ResizeObserverSize=i;
272 | },{"./utils/freeze":"CLwC"}],"f5Aq":[function(require,module,exports) {
273 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DOMRectReadOnly=void 0;var t=require("./utils/freeze"),e=function(){function e(e,i,h,r){return this.x=e,this.y=i,this.width=h,this.height=r,this.top=this.y,this.left=this.x,this.bottom=this.top+this.height,this.right=this.left+this.width,(0,t.freeze)(this)}return e.prototype.toJSON=function(){var t=this;return{x:t.x,y:t.y,top:t.top,right:t.right,bottom:t.bottom,left:t.left,width:t.width,height:t.height}},e.fromRect=function(t){return new e(t.x,t.y,t.width,t.height)},e}();exports.DOMRectReadOnly=e;
274 | },{"./utils/freeze":"CLwC"}],"Qu87":[function(require,module,exports) {
275 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isReplacedElement=exports.isElement=exports.isHidden=exports.isSVG=void 0;var e=function(e){return e instanceof SVGElement&&"getBBox"in e};exports.isSVG=e;var t=function(t){if(e(t)){var n=t.getBBox(),i=n.width,r=n.height;return!i&&!r}var s=t,o=s.offsetWidth,a=s.offsetHeight;return!(o||a||t.getClientRects().length)};exports.isHidden=t;var n=function(e){var t,n;if(e instanceof Element)return!0;var i=null===(n=null===(t=e)||void 0===t?void 0:t.ownerDocument)||void 0===n?void 0:n.defaultView;return!!(i&&e instanceof i.Element)};exports.isElement=n;var i=function(e){switch(e.tagName){case"INPUT":if("image"!==e.type)break;case"VIDEO":case"AUDIO":case"EMBED":case"OBJECT":case"CANVAS":case"IFRAME":case"IMG":return!0}return!1};exports.isReplacedElement=i;
276 | },{}],"YBR9":[function(require,module,exports) {
277 |
278 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.global=void 0;var e="undefined"!=typeof window?window:{};exports.global=e;
279 | },{}],"UclH":[function(require,module,exports) {
280 |
281 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.calculateBoxSizes=exports.calculateBoxSize=void 0;var e=require("../ResizeObserverBoxOptions"),t=require("../ResizeObserverSize"),i=require("../DOMRectReadOnly"),r=require("../utils/element"),o=require("../utils/freeze"),n=require("../utils/global"),d=new WeakMap,s=/auto|scroll/,a=/^tb|vertical/,l=/msie|trident/i.test(n.global.navigator&&n.global.navigator.userAgent),c=function(e){return parseFloat(e||"0")},u=function(e,i,r){return void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=!1),new t.ResizeObserverSize((r?i:e)||0,(r?e:i)||0)},x=(0,o.freeze)({devicePixelContentBoxSize:u(),borderBoxSize:u(),contentBoxSize:u(),contentRect:new i.DOMRectReadOnly(0,0,0,0)}),v=function(e,t){if(void 0===t&&(t=!1),d.has(e)&&!t)return d.get(e);if((0,r.isHidden)(e))return d.set(e,x),x;var n=getComputedStyle(e),v=(0,r.isSVG)(e)&&e.ownerSVGElement&&e.getBBox(),z=!l&&"border-box"===n.boxSizing,B=a.test(n.writingMode||""),g=!v&&s.test(n.overflowY||""),b=!v&&s.test(n.overflowX||""),h=v?0:c(n.paddingTop),f=v?0:c(n.paddingRight),O=v?0:c(n.paddingBottom),R=v?0:c(n.paddingLeft),S=v?0:c(n.borderTopWidth),p=v?0:c(n.borderRightWidth),w=v?0:c(n.borderBottomWidth),M=R+f,P=h+O,W=(v?0:c(n.borderLeftWidth))+p,m=S+w,q=b?e.offsetHeight-m-e.clientHeight:0,C=g?e.offsetWidth-W-e.clientWidth:0,E=z?M+W:0,_=z?P+m:0,y=v?v.width:c(n.width)-E-C,D=v?v.height:c(n.height)-_-q,T=y+M+C+W,X=D+P+q+m,H=(0,o.freeze)({devicePixelContentBoxSize:u(Math.round(y*devicePixelRatio),Math.round(D*devicePixelRatio),B),borderBoxSize:u(T,X,B),contentBoxSize:u(y,D,B),contentRect:new i.DOMRectReadOnly(R,h,y,D)});return d.set(e,H),H};exports.calculateBoxSizes=v;var z=function(t,i,r){var o=v(t,r),n=o.borderBoxSize,d=o.contentBoxSize,s=o.devicePixelContentBoxSize;switch(i){case e.ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:return s;case e.ResizeObserverBoxOptions.BORDER_BOX:return n;default:return d}};exports.calculateBoxSize=z;
282 | },{"../ResizeObserverBoxOptions":"dDZ1","../ResizeObserverSize":"rYLT","../DOMRectReadOnly":"f5Aq","../utils/element":"Qu87","../utils/freeze":"CLwC","../utils/global":"YBR9"}],"EMhE":[function(require,module,exports) {
283 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserverEntry=void 0;var e=require("./algorithms/calculateBoxSize"),t=require("./utils/freeze"),r=function(){return function(r){var i=(0,e.calculateBoxSizes)(r);this.target=r,this.contentRect=i.contentRect,this.borderBoxSize=(0,t.freeze)([i.borderBoxSize]),this.contentBoxSize=(0,t.freeze)([i.contentBoxSize]),this.devicePixelContentBoxSize=(0,t.freeze)([i.devicePixelContentBoxSize])}}();exports.ResizeObserverEntry=r;
284 | },{"./algorithms/calculateBoxSize":"UclH","./utils/freeze":"CLwC"}],"Q63j":[function(require,module,exports) {
285 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.calculateDepthForNode=void 0;var e=require("../utils/element"),r=function(r){if((0,e.isHidden)(r))return 1/0;for(var t=0,o=r.parentNode;o;)t+=1,o=o.parentNode;return t};exports.calculateDepthForNode=r;
286 | },{"../utils/element":"Qu87"}],"EHS0":[function(require,module,exports) {
287 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.broadcastActiveObservations=void 0;var e=require("../utils/resizeObservers"),r=require("../ResizeObserverEntry"),t=require("./calculateDepthForNode"),a=require("./calculateBoxSize"),s=function(){var s=1/0,i=[];e.resizeObservers.forEach(function(e){if(0!==e.activeTargets.length){var c=[];e.activeTargets.forEach(function(e){var i=new r.ResizeObserverEntry(e.target),o=(0,t.calculateDepthForNode)(e.target);c.push(i),e.lastReportedSize=(0,a.calculateBoxSize)(e.target,e.observedBox),or?e.activeTargets.push(s):e.skippedTargets.push(s))})})};exports.gatherActiveObservationsAtDepth=r;
290 | },{"../utils/resizeObservers":"MO33","./calculateDepthForNode":"Q63j"}],"Rfya":[function(require,module,exports) {
291 |
292 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.process=void 0;var e=require("../algorithms/hasActiveObservations"),r=require("../algorithms/hasSkippedObservations"),s=require("../algorithms/deliverResizeLoopError"),t=require("../algorithms/broadcastActiveObservations"),i=require("../algorithms/gatherActiveObservationsAtDepth"),o=function(){var o=0;for((0,i.gatherActiveObservationsAtDepth)(o);(0,e.hasActiveObservations)();)o=(0,t.broadcastActiveObservations)(),(0,i.gatherActiveObservationsAtDepth)(o);return(0,r.hasSkippedObservations)()&&(0,s.deliverResizeLoopError)(),o>0};exports.process=o;
293 | },{"../algorithms/hasActiveObservations":"pdYF","../algorithms/hasSkippedObservations":"waFp","../algorithms/deliverResizeLoopError":"leLN","../algorithms/broadcastActiveObservations":"EHS0","../algorithms/gatherActiveObservationsAtDepth":"LRFz"}],"wTDp":[function(require,module,exports) {
294 | "use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.queueMicroTask=void 0;var t=[],r=function(){return t.splice(0).forEach(function(e){return e()})},n=function(n){if(!e){var o=0,u=document.createTextNode("");new MutationObserver(function(){return r()}).observe(u,{characterData:!0}),e=function(){u.textContent=""+(o?o--:o++)}}t.push(n),e()};exports.queueMicroTask=n;
295 | },{}],"hmv9":[function(require,module,exports) {
296 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.queueResizeObserver=void 0;var e=require("./queueMicroTask"),r=function(r){(0,e.queueMicroTask)(function(){requestAnimationFrame(r)})};exports.queueResizeObserver=r;
297 | },{"./queueMicroTask":"wTDp"}],"hnS0":[function(require,module,exports) {
298 |
299 |
300 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.updateCount=exports.scheduler=void 0;var e=require("./process"),t=require("./global"),r=require("./queueResizeObserver"),o=0,n=function(){return!!o},s=250,i={attributes:!0,characterData:!0,childList:!0,subtree:!0},u=["resize","load","transitionend","animationend","animationstart","animationiteration","keyup","keydown","mouseup","mousedown","mouseover","mouseout","blur","focus"],a=function(e){return void 0===e&&(e=0),Date.now()+e},p=!1,c=function(){function o(){var e=this;this.stopped=!0,this.listener=function(){return e.schedule()}}return o.prototype.run=function(t){var o=this;if(void 0===t&&(t=s),!p){p=!0;var i=a(t);(0,r.queueResizeObserver)(function(){var r=!1;try{r=(0,e.process)()}finally{if(p=!1,t=i-a(),!n())return;r?o.run(1e3):t>0?o.run(t):o.start()}})}},o.prototype.schedule=function(){this.stop(),this.run()},o.prototype.observe=function(){var e=this,r=function(){return e.observer&&e.observer.observe(document.body,i)};document.body?r():t.global.addEventListener("DOMContentLoaded",r)},o.prototype.start=function(){var e=this;this.stopped&&(this.stopped=!1,this.observer=new MutationObserver(this.listener),this.observe(),u.forEach(function(r){return t.global.addEventListener(r,e.listener,!0)}))},o.prototype.stop=function(){var e=this;this.stopped||(this.observer&&this.observer.disconnect(),u.forEach(function(r){return t.global.removeEventListener(r,e.listener,!0)}),this.stopped=!0)},o}(),d=new c;exports.scheduler=d;var v=function(e){!o&&e>0&&d.start(),!(o+=e)&&d.stop()};exports.updateCount=v;
301 | },{"./process":"Rfya","./global":"YBR9","./queueResizeObserver":"hmv9"}],"yfOI":[function(require,module,exports) {
302 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObservation=void 0;var e=require("./ResizeObserverBoxOptions"),i=require("./algorithms/calculateBoxSize"),t=require("./utils/element"),r=function(e){return!(0,t.isSVG)(e)&&!(0,t.isReplacedElement)(e)&&"inline"===getComputedStyle(e).display},s=function(){function t(i,t){this.target=i,this.observedBox=t||e.ResizeObserverBoxOptions.CONTENT_BOX,this.lastReportedSize={inlineSize:0,blockSize:0}}return t.prototype.isActive=function(){var e=(0,i.calculateBoxSize)(this.target,this.observedBox,!0);return r(this.target)&&(this.lastReportedSize=e),this.lastReportedSize.inlineSize!==e.inlineSize||this.lastReportedSize.blockSize!==e.blockSize},t}();exports.ResizeObservation=s;
303 | },{"./ResizeObserverBoxOptions":"dDZ1","./algorithms/calculateBoxSize":"UclH","./utils/element":"Qu87"}],"MhWH":[function(require,module,exports) {
304 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserverDetail=void 0;var e=function(){return function(e,t){this.activeTargets=[],this.skippedTargets=[],this.observationTargets=[],this.observer=e,this.callback=t}}();exports.ResizeObserverDetail=e;
305 | },{}],"yrk3":[function(require,module,exports) {
306 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserverController=void 0;var e=require("./utils/scheduler"),r=require("./ResizeObservation"),t=require("./ResizeObserverDetail"),s=require("./utils/resizeObservers"),i=new WeakMap,n=function(e,r){for(var t=0;t=0&&(u&&s.resizeObservers.splice(s.resizeObservers.indexOf(o),1),o.observationTargets.splice(a,1),(0,e.updateCount)(-1))},o.disconnect=function(e){var r=this,t=i.get(e);t.observationTargets.slice().forEach(function(t){return r.unobserve(e,t.target)}),t.activeTargets.splice(0,t.activeTargets.length)},o}();exports.ResizeObserverController=o;
307 | },{"./utils/scheduler":"hnS0","./ResizeObservation":"yfOI","./ResizeObserverDetail":"MhWH","./utils/resizeObservers":"MO33"}],"N8lO":[function(require,module,exports) {
308 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ResizeObserver=void 0;var e=require("./ResizeObserverController"),r=require("./utils/element"),t=function(){function t(r){if(0===arguments.length)throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");if("function"!=typeof r)throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");e.ResizeObserverController.connect(this,r)}return t.prototype.observe=function(t,o){if(0===arguments.length)throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!(0,r.isElement)(t))throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");e.ResizeObserverController.observe(this,t,o)},t.prototype.unobserve=function(t){if(0===arguments.length)throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");if(!(0,r.isElement)(t))throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");e.ResizeObserverController.unobserve(this,t)},t.prototype.disconnect=function(){e.ResizeObserverController.disconnect(this)},t.toString=function(){return"function ResizeObserver () { [polyfill code] }"},t}();exports.ResizeObserver=t;
309 | },{"./ResizeObserverController":"yrk3","./utils/element":"Qu87"}],"UOPm":[function(require,module,exports) {
310 | "use strict";require("core-js/features/symbol"),require("core-js/features/array/from"),require("core-js/features/dom-collections/iterator");var e=require("../../lib/ResizeObserver");function t(e){return i(e)||o(e)||n(e)||r()}function r(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}function o(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function i(e){if(Array.isArray(e))return a(e)}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r
2 |
3 |
4 |
5 |
6 |
7 |
8 | Resize Observer Polyfill
9 |
10 |
11 |
12 |
13 |
14 |
21 |
22 |
23 |
24 |
33 |
34 | Installation
35 | Install the package from npm.
36 |
37 |
38 | npm i @juggle/resize-observer
39 |
40 |
41 | Once installed, you can import it like any other module.
42 |
43 |
44 | import { ResizeObserver } from '@juggle/resize-observer';
45 |
46 |
47 | Usage
48 |
49 |
50 | import { ResizeObserver } from '@juggle/resize-observer';
51 |
52 | const ro = new ResizeObserver((entries, observer) => {
53 | for (let entry of entries) {
54 | const { inlineSize, blockSize } = entry.contentBoxSize;
55 | const { width, height } = entry.contentRect; // use for backwards compatibility
56 | entry.target.innerText = `${inlineSize} x ${blockSize}`;
57 | }
58 | });
59 |
60 | ro.observe(someElement);
61 |
62 |
63 |
64 | Pseudo Classes
65 | The library supports user-actioned pseudo classes, like :hover, :active,
66 | :focus
67 | Hover, click or focus me.
68 | Animations*
69 | The library will detect changes which occur during animations.
70 | Tap me.
71 | Transitions*
72 | The library will detect changes which occur during transition.
73 | Tap me.
74 | NB: Slow-starting transitions may not be noticed, unless, other interactions occur in the
75 | application. Any missed calculations will be noticed at the end of the transition.
76 | Performance Test
77 | This animates 200 elements and counts the changes. To start/stop the animation, tap the cell area.
78 | Updates: 0
79 |
80 |
81 | * Once the animation, or, transition has finished, the
82 | observer will sleep and wait for the next interaction. This keeps CPU idle, reducing battery consumption on
83 | portable devices.
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/docs/src/page.css:
--------------------------------------------------------------------------------
1 | html {
2 | height: 100%;
3 | font-family: Heebo,sans-serif;
4 | font-size: 12pt;
5 | font-weight: 300;
6 | background: #f3f3f6;
7 | color: #454548
8 | }
9 |
10 | body {
11 | margin: 0 auto;
12 | padding: 40px;
13 | max-width: 900px
14 | }
15 |
16 | :focus {
17 | outline-color: #f35
18 | }
19 |
20 | h1,h2,h3,h4,h5,h6 {
21 | font-weight: 400
22 | }
23 |
24 | h1 {
25 | font-size: 40pt;
26 | line-height: 1
27 | }
28 |
29 | h2 {
30 | margin: 50px 0 0
31 | }
32 |
33 | hr {
34 | margin: 50px 0 20px;
35 | border: none;
36 | height: 1px;
37 | background: rgba(0,0,0,.2)
38 | }
39 |
40 | header {
41 | display: flex;
42 | flex-flow: row wrap;
43 | align-items: center;
44 | justify-content: space-between
45 | }
46 |
47 | header h1 {
48 | margin: 0
49 | }
50 |
51 | header a {
52 | flex: 0 0 auto;
53 | margin: 20px 0
54 | }
55 |
56 | header div {
57 | flex: 1 1 100%
58 | }
59 |
60 | pre code.hljs {
61 | padding: 0 1em;
62 | box-shadow: inset 0 0 4px rgba(0,0,0,.3);
63 | background: #fff
64 | }
65 |
66 | [resize],
67 | #performance-example div {
68 | min-width: 100px;
69 | min-height: 100px;
70 | height: 100px;
71 | position: relative;
72 | white-space: nowrap;
73 | background: #f35;
74 | color: #fff;
75 | display: flex;
76 | flex-direction: column;
77 | justify-content: center;
78 | align-items: center;
79 | margin: 20px auto;
80 | user-select: none;
81 | box-sizing: border-box;
82 | background-clip: content-box;
83 | border: 0 solid rgba(0,0,0,.2);
84 | cursor: pointer
85 | }
86 |
87 | [resize]:after {
88 | content: attr(dimensions);
89 | font-weight: 400;
90 | padding: 2px 5px 0
91 | }
92 |
93 | #pseudo-example:focus,#pseudo-example:hover {
94 | border-width: 0
95 | }
96 |
97 | #pseudo-example:active {
98 | border-width: 5px
99 | }
100 |
101 | #transition-example {
102 | transition: border-width 1s ease
103 | }
104 |
105 | #transition-example[fill] {
106 | border-width: 0
107 | }
108 |
109 | #animation-example {
110 | animation: fill-in-out 1s infinite alternate;
111 | animation-play-state: paused
112 | }
113 |
114 | #animation-example[animate] {
115 | animation-play-state: running
116 | }
117 |
118 | #performance-example {
119 | display: flex;
120 | flex-flow: row wrap;
121 | animation: squeeze-in-out 1s infinite alternate;
122 | animation-play-state: paused;
123 | width: 100%;
124 | margin: 0;
125 | font-size: 50%;
126 | cursor: pointer
127 | }
128 |
129 | #performance-example:hover {
130 | outline: 1px solid #f35
131 | }
132 |
133 | #performance-example[animate] {
134 | animation-play-state: running
135 | }
136 |
137 | #performance-example div {
138 | margin: 2px;
139 | flex: 1 1 auto;
140 | min-width: 0;
141 | min-height: 10px;
142 | width: calc(5% - 4px);
143 | height: auto
144 | }
145 |
146 | .interactive-example {
147 | border-width: 0 20vw
148 | }
149 |
150 | @media (min-width: 900px) {
151 | .interactive-example {
152 | border-width:0 200px
153 | }
154 | }
155 |
156 | @keyframes fill-in-out {
157 | to {
158 | border-width: 0
159 | }
160 | }
161 |
162 | @keyframes squeeze-in-out {
163 | to {
164 | width: 50%
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/docs/src/page.js:
--------------------------------------------------------------------------------
1 | import 'core-js/features/symbol';
2 | import 'core-js/features/array/from';
3 | import 'core-js/features/dom-collections/iterator';
4 | import { ResizeObserver } from '../../lib/ResizeObserver';
5 |
6 | window.ResizeObserver = ResizeObserver; // Override global so that people can play :)
7 |
8 | const perfArea = document.getElementById('performance-example');
9 | const perfFragment = document.createDocumentFragment();
10 | const perfCount = document.getElementById('performance-count');
11 | let ticks = 0;
12 |
13 | const ro = new ResizeObserver(entries => {
14 | entries.forEach(entry => {
15 | if (entry.target.parentElement === perfArea) {
16 | ticks += 1;
17 | perfCount.innerText = ticks;
18 | return;
19 | }
20 | const { inlineSize, blockSize } = entry.contentBoxSize[0];
21 | entry.target.setAttribute('dimensions', `${Math.round(inlineSize)} x ${Math.round(blockSize)}`);
22 | });
23 | });
24 |
25 | [...document.querySelectorAll('pre, code')].forEach(el => {
26 | el.innerHTML = el.innerHTML.trim();
27 | });
28 |
29 | const perfEls = [];
30 |
31 | for (let i = 0; i < 200; i += 1) {
32 | const el = document.createElement('div');
33 | perfEls.push(el);
34 | perfFragment.appendChild(el);
35 | }
36 |
37 | perfArea.appendChild(perfFragment);
38 |
39 | if (!('toggleAttribute' in HTMLElement.prototype)) {
40 | HTMLElement.prototype.toggleAttribute = function (attr) {
41 | if (this.hasAttribute(attr)) {
42 | this.removeAttribute(attr);
43 | return false;
44 | }
45 | this.setAttribute(attr, '');
46 | return true;
47 | }
48 | }
49 |
50 | perfArea.addEventListener('click', function () {
51 | const animating = this.toggleAttribute('animate');
52 | perfEls.forEach(el => animating ? ro.observe(el) : ro.unobserve(el));
53 | });
54 |
55 | document.getElementById('transition-example').addEventListener('click', function () {
56 | this.toggleAttribute('fill');
57 | });
58 |
59 | document.getElementById('animation-example').addEventListener('click', function () {
60 | this.toggleAttribute('animate');
61 | });
62 |
63 | [...document.querySelectorAll('[resize]')].forEach(el => ro.observe(el));
64 |
--------------------------------------------------------------------------------
/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | preset: 'ts-jest',
3 | testEnvironment: 'jsdom',
4 | reporters: [
5 | 'default',
6 | 'jest-junit'
7 | ],
8 | collectCoverageFrom: [
9 | 'src/**/*.ts',
10 | '!src/exports/*.ts'
11 | ]
12 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@juggle/resize-observer",
3 | "version": "3.3.1",
4 | "description": "Polyfills the ResizeObserver API and supports box size options from the latest spec",
5 | "main": "lib/exports/resize-observer.umd.js",
6 | "module": "lib/exports/resize-observer.js",
7 | "types": "lib/exports/resize-observer.d.ts",
8 | "files": [
9 | "lib/**/*.{js,ts}"
10 | ],
11 | "scripts": {
12 | "build": "rm -rf lib && npm run build:esm && npm run build:umd",
13 | "build:esm": "tsc",
14 | "build:umd": "rollup -c",
15 | "build:docs": "echo 'no longer building docs for this version'",
16 | "ci-tests": "npm test -- --ci --runInBand && cat coverage/lcov.info | coveralls",
17 | "test": "npm run lint && jest --coverage",
18 | "lint": "eslint '{src,test}/**/*.ts'",
19 | "preVersion": "npm run build-docs",
20 | "prepublishOnly": "npm run build"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "git+ssh://git@github.com/juggle/resize-observer.git"
25 | },
26 | "keywords": [
27 | "ResizeObserver",
28 | "polyfill",
29 | "ponyfill",
30 | "event",
31 | "resize",
32 | "observer",
33 | "typescript",
34 | "javascript",
35 | "element",
36 | "component",
37 | "container",
38 | "queries",
39 | "web components",
40 | "front-end",
41 | "html",
42 | "Angular",
43 | "React",
44 | "Vue"
45 | ],
46 | "author": "Juggle",
47 | "license": "Apache-2.0",
48 | "bugs": {
49 | "url": "https://github.com/juggle/resize-observer/issues"
50 | },
51 | "homepage": "https://juggle.studio/resize-observer/",
52 | "devDependencies": {
53 | "@types/jest": "^28.1.7",
54 | "@typescript-eslint/eslint-plugin": "^5.33.1",
55 | "@typescript-eslint/parser": "^5.33.1",
56 | "core-js": "^3.24.1",
57 | "coveralls": "^3.1.1",
58 | "cssnano": "^5.1.13",
59 | "eslint": "^8.22.0",
60 | "jest": "^28.1.3",
61 | "jest-cli": "^28.1.3",
62 | "jest-environment-jsdom": "^28.1.3",
63 | "jest-junit": "^14.0.0",
64 | "jsdom": "^20.0.0",
65 | "rollup": "^2.78.0",
66 | "ts-jest": "^28.0.8",
67 | "typescript": "^4.7.4"
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | input: 'lib/exports/resize-observer.js',
3 | output: {
4 | file: 'lib/exports/resize-observer.umd.js',
5 | format: 'umd',
6 | name: 'ResizeObserver'
7 | }
8 | };
--------------------------------------------------------------------------------
/src/DOMRectReadOnly.ts:
--------------------------------------------------------------------------------
1 | import { freeze } from './utils/freeze';
2 |
3 | interface Rectangle {
4 | readonly x: number;
5 | readonly y: number;
6 | readonly width: number;
7 | readonly height: number;
8 | }
9 |
10 | type DOMRectJSON = {
11 | x: number,
12 | y: number,
13 | top: number,
14 | right: number,
15 | bottom: number,
16 | left: number,
17 | width: number,
18 | height: number,
19 | }
20 |
21 | /**
22 | * Implementation of DOMRectReadOnly.
23 | * Native DOMRectReadOnly is not available in all browsers.
24 | */
25 | class DOMRectReadOnly {
26 | public readonly x: number;
27 | public readonly y: number;
28 | public readonly width: number;
29 | public readonly height: number;
30 | public readonly top: number;
31 | public readonly left: number;
32 | public readonly bottom: number;
33 | public readonly right: number;
34 | public constructor (x: number, y: number, width: number, height: number) {
35 | this.x = x;
36 | this.y = y;
37 | this.width = width;
38 | this.height = height;
39 | this.top = this.y;
40 | this.left = this.x;
41 | this.bottom = this.top + this.height;
42 | this.right = this.left + this.width;
43 | return freeze(this);
44 | }
45 | public toJSON (): DOMRectJSON {
46 | const { x, y, top, right, bottom, left, width, height } = this;
47 | return { x, y, top, right, bottom, left, width, height };
48 | }
49 | public static fromRect (rectangle: Rectangle): Readonly {
50 | return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
51 | }
52 | }
53 |
54 | export { DOMRectReadOnly };
55 |
--------------------------------------------------------------------------------
/src/ResizeObservation.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserverSize } from './ResizeObserverSize';
2 | import { ResizeObserverBoxOptions } from './ResizeObserverBoxOptions';
3 | import { calculateBoxSize } from './algorithms/calculateBoxSize';
4 | import { isSVG, isReplacedElement } from './utils/element';
5 |
6 | const skipNotifyOnElement = (target: Element): boolean => {
7 | return !isSVG(target)
8 | && !isReplacedElement(target)
9 | && getComputedStyle(target).display === 'inline';
10 | }
11 |
12 | /**
13 | * https://drafts.csswg.org/resize-observer-1/#resize-observation-interface
14 | */
15 | class ResizeObservation {
16 |
17 | public target: Element;
18 | public observedBox: ResizeObserverBoxOptions;
19 | public lastReportedSize: ResizeObserverSize; // Todo: update to FrozenArray
20 |
21 | public constructor (target: Element, observedBox?: ResizeObserverBoxOptions) {
22 | this.target = target;
23 | this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
24 | this.lastReportedSize = {
25 | inlineSize: -1,
26 | blockSize: -1
27 | }
28 | }
29 |
30 | public isActive (): boolean {
31 | const size = calculateBoxSize(this.target, this.observedBox, true);
32 | if (skipNotifyOnElement(this.target)) {
33 | this.lastReportedSize = size;
34 | }
35 | if (this.lastReportedSize.inlineSize !== size.inlineSize
36 | || this.lastReportedSize.blockSize !== size.blockSize) {
37 | return true;
38 | }
39 | return false;
40 | }
41 |
42 | }
43 |
44 | export { ResizeObservation };
45 |
--------------------------------------------------------------------------------
/src/ResizeObserver.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserverController } from './ResizeObserverController';
2 | import { ResizeObserverCallback } from './ResizeObserverCallback';
3 | import { ResizeObserverOptions } from './ResizeObserverOptions';
4 | import { isElement } from './utils/element';
5 |
6 | /**
7 | * https://drafts.csswg.org/resize-observer-1/#resize-observer-interface
8 | */
9 | class ResizeObserver {
10 |
11 | public constructor (callback: ResizeObserverCallback) {
12 | if (arguments.length === 0) {
13 | throw new TypeError(`Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.`)
14 | }
15 | if (typeof callback !== 'function') {
16 | throw new TypeError(`Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.`);
17 | }
18 | ResizeObserverController.connect(this, callback);
19 | }
20 |
21 | public observe (target: Element, options?: ResizeObserverOptions): void {
22 | if (arguments.length === 0) {
23 | throw new TypeError(`Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.`)
24 | }
25 | if (!isElement(target)) {
26 | throw new TypeError(`Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element`);
27 | }
28 | ResizeObserverController.observe(this, target, options);
29 | }
30 |
31 | public unobserve (target: Element): void {
32 | if (arguments.length === 0) {
33 | throw new TypeError(`Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.`)
34 | }
35 | if (!isElement(target)) {
36 | throw new TypeError(`Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element`);
37 | }
38 | ResizeObserverController.unobserve(this, target);
39 | }
40 |
41 | public disconnect (): void {
42 | ResizeObserverController.disconnect(this);
43 | }
44 |
45 | public static toString (): string {
46 | return 'function ResizeObserver () { [polyfill code] }';
47 | }
48 |
49 | }
50 |
51 | export { ResizeObserver };
52 |
--------------------------------------------------------------------------------
/src/ResizeObserverBoxOptions.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Used to observe different box sizes.
3 | *
4 | * https://drafts.csswg.org/resize-observer-1/#enumdef-resizeobserverboxoptions
5 | */
6 | enum ResizeObserverBoxOptions {
7 | BORDER_BOX = 'border-box',
8 | CONTENT_BOX = 'content-box',
9 | DEVICE_PIXEL_CONTENT_BOX = 'device-pixel-content-box'
10 | }
11 |
12 | export { ResizeObserverBoxOptions };
--------------------------------------------------------------------------------
/src/ResizeObserverCallback.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from './ResizeObserver';
2 | import { ResizeObserverEntry } from './ResizeObserverEntry';
3 |
4 | /**
5 | * https://drafts.csswg.org/resize-observer-1/#resize-observer-callback
6 | */
7 | type ResizeObserverCallback = (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;
8 |
9 | export { ResizeObserverCallback };
--------------------------------------------------------------------------------
/src/ResizeObserverController.ts:
--------------------------------------------------------------------------------
1 | import { scheduler, updateCount } from './utils/scheduler';
2 |
3 | import { ResizeObserver } from './ResizeObserver';
4 | import { ResizeObservation } from './ResizeObservation';
5 | import { ResizeObserverDetail } from './ResizeObserverDetail';
6 | import { ResizeObserverCallback } from './ResizeObserverCallback';
7 | import { ResizeObserverOptions } from './ResizeObserverOptions';
8 |
9 | import { resizeObservers } from './utils/resizeObservers';
10 | import { ResizeObserverBoxOptions } from './ResizeObserverBoxOptions';
11 |
12 | const observerMap = new WeakMap();
13 |
14 | // Helper to find the correct ResizeObservation, based on a target.
15 | const getObservationIndex = (observationTargets: ResizeObservation[], target: Element): number => {
16 | for (let i = 0; i < observationTargets.length; i+= 1) {
17 | if (observationTargets[i].target === target) {
18 | return i;
19 | }
20 | }
21 | return -1;
22 | }
23 |
24 | /**
25 | * Used as an interface for connecting resize observers.
26 | */
27 | class ResizeObserverController {
28 | // Connects an observer to the controller.
29 | public static connect (resizeObserver: ResizeObserver, callback: ResizeObserverCallback): void {
30 | const detail = new ResizeObserverDetail(resizeObserver, callback);
31 | observerMap.set(resizeObserver, detail);
32 | }
33 | // Informs the controller to watch a new target.
34 | public static observe (resizeObserver: ResizeObserver, target: Element, options?: ResizeObserverOptions): void {
35 | const detail = observerMap.get(resizeObserver) as ResizeObserverDetail;
36 | const firstObservation = detail.observationTargets.length === 0;
37 | if (getObservationIndex(detail.observationTargets, target) < 0) {
38 | firstObservation && resizeObservers.push(detail);
39 | detail.observationTargets.push(new ResizeObservation(target, options && options.box as ResizeObserverBoxOptions));
40 | updateCount(1);
41 | scheduler.schedule(); // Schedule next observation
42 | }
43 | }
44 | // Informs the controller to stop watching a target.
45 | public static unobserve (resizeObserver: ResizeObserver, target: Element): void {
46 | const detail = observerMap.get(resizeObserver) as ResizeObserverDetail;
47 | const index = getObservationIndex(detail.observationTargets, target);
48 | const lastObservation = detail.observationTargets.length === 1;
49 | if (index >= 0) {
50 | lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
51 | detail.observationTargets.splice(index, 1);
52 | updateCount(-1);
53 | }
54 | }
55 | // Informs the controller to disconnect an observer.
56 | public static disconnect (resizeObserver: ResizeObserver): void {
57 | const detail = observerMap.get(resizeObserver) as ResizeObserverDetail;
58 | detail.observationTargets.slice().forEach((ot): void => this.unobserve(resizeObserver, ot.target));
59 | detail.activeTargets.splice(0, detail.activeTargets.length);
60 | }
61 | }
62 |
63 | export { ResizeObserverController };
64 |
--------------------------------------------------------------------------------
/src/ResizeObserverDetail.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from './ResizeObserver';
2 | import { ResizeObservation } from './ResizeObservation';
3 | import { ResizeObserverCallback } from './ResizeObserverCallback';
4 |
5 | /**
6 | * Holds additional information about a resize observer,
7 | * to be used internally.
8 | */
9 | class ResizeObserverDetail {
10 | public callback: ResizeObserverCallback;
11 | public observer: ResizeObserver;
12 | public activeTargets: ResizeObservation[] = [];
13 | public skippedTargets: ResizeObservation[] = [];
14 | public observationTargets: ResizeObservation[] = [];
15 |
16 | public constructor (resizeObserver: ResizeObserver, callback: ResizeObserverCallback) {
17 | this.observer = resizeObserver;
18 | this.callback = callback;
19 | }
20 | }
21 |
22 | export { ResizeObserverDetail };
23 |
--------------------------------------------------------------------------------
/src/ResizeObserverEntry.ts:
--------------------------------------------------------------------------------
1 | import { DOMRectReadOnly } from './DOMRectReadOnly';
2 | import { ResizeObserverSize } from './ResizeObserverSize';
3 | import { calculateBoxSizes } from './algorithms/calculateBoxSize';
4 | import { freeze } from './utils/freeze';
5 |
6 | /**
7 | * https://drafts.csswg.org/resize-observer-1/#resize-observer-entry-interface
8 | */
9 | class ResizeObserverEntry {
10 | public target: Element;
11 | public contentRect: DOMRectReadOnly;
12 | public borderBoxSize: readonly ResizeObserverSize[];
13 | public contentBoxSize: readonly ResizeObserverSize[];
14 | public devicePixelContentBoxSize: readonly ResizeObserverSize[];
15 | public constructor (target: Element) {
16 | const boxes = calculateBoxSizes(target);
17 | this.target = target;
18 | this.contentRect = boxes.contentRect;
19 | this.borderBoxSize = freeze([boxes.borderBoxSize]);
20 | this.contentBoxSize = freeze([boxes.contentBoxSize]);
21 | this.devicePixelContentBoxSize = freeze([boxes.devicePixelContentBoxSize]);
22 | }
23 | }
24 |
25 | export { ResizeObserverEntry };
26 |
--------------------------------------------------------------------------------
/src/ResizeObserverOptions.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserverBoxOptions } from './ResizeObserverBoxOptions';
2 |
3 | /**
4 | * Options to be given to the resize observer,
5 | * when observing a new element.
6 | *
7 | * https://drafts.csswg.org/resize-observer-1/#dictdef-resizeobserveroptions
8 | */
9 | interface ResizeObserverOptions {
10 | box?: 'content-box' | 'border-box' | 'device-pixel-content-box' | ResizeObserverBoxOptions;
11 | }
12 |
13 | export { ResizeObserverOptions };
14 |
--------------------------------------------------------------------------------
/src/ResizeObserverSize.ts:
--------------------------------------------------------------------------------
1 | import { freeze } from './utils/freeze';
2 |
3 | /**
4 | * Size of a specific box.
5 | *
6 | * https://drafts.csswg.org/resize-observer-1/#resizeobserversize
7 | */
8 | class ResizeObserverSize {
9 | readonly inlineSize: number;
10 | readonly blockSize: number;
11 | constructor (inlineSize: number, blockSize: number) {
12 | this.inlineSize = inlineSize;
13 | this.blockSize = blockSize;
14 | freeze(this);
15 | }
16 | }
17 |
18 | export { ResizeObserverSize };
19 |
--------------------------------------------------------------------------------
/src/algorithms/broadcastActiveObservations.ts:
--------------------------------------------------------------------------------
1 | import { resizeObservers } from '../utils/resizeObservers';
2 | import { ResizeObserverDetail } from '../ResizeObserverDetail';
3 | import { ResizeObserverEntry } from '../ResizeObserverEntry';
4 | import { ResizeObservation } from '../ResizeObservation';
5 | import { calculateDepthForNode } from './calculateDepthForNode';
6 | import { calculateBoxSize } from './calculateBoxSize';
7 |
8 | /**
9 | * Broadcasts all active observations.
10 | *
11 | * https://drafts.csswg.org/resize-observer-1/#broadcast-resize-notifications-h
12 | */
13 | const broadcastActiveObservations = (): number => {
14 | let shallowestDepth = Infinity;
15 | const callbacks: (() => void)[] = [];
16 | resizeObservers.forEach(function processObserver(ro: ResizeObserverDetail): void {
17 | if (ro.activeTargets.length === 0) {
18 | return;
19 | }
20 | const entries: ResizeObserverEntry[] = [];
21 | ro.activeTargets.forEach(function processTarget(ot: ResizeObservation): void {
22 | const entry = new ResizeObserverEntry(ot.target);
23 | const targetDepth = calculateDepthForNode(ot.target);
24 | entries.push(entry);
25 | ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
26 | if (targetDepth < shallowestDepth) {
27 | shallowestDepth = targetDepth;
28 | }
29 | })
30 | // Gather all entries before firing callbacks
31 | // otherwise entries may change in the same loop
32 | callbacks.push(function resizeObserverCallback(): void {
33 | // callback.this should be resize observer
34 | ro.callback.call(ro.observer, entries, ro.observer)
35 | });
36 | ro.activeTargets.splice(0, ro.activeTargets.length);
37 | })
38 | for (const callback of callbacks) {
39 | callback();
40 | }
41 | return shallowestDepth;
42 | }
43 |
44 | export { broadcastActiveObservations };
45 |
--------------------------------------------------------------------------------
/src/algorithms/calculateBoxSize.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserverBoxOptions } from '../ResizeObserverBoxOptions';
2 | import { ResizeObserverSize } from '../ResizeObserverSize';
3 | import { DOMRectReadOnly } from '../DOMRectReadOnly';
4 | import { isSVG, isHidden } from '../utils/element';
5 | import { freeze } from '../utils/freeze';
6 | import { global } from '../utils/global';
7 |
8 | interface ResizeObserverSizeCollection {
9 | devicePixelContentBoxSize: ResizeObserverSize;
10 | borderBoxSize: ResizeObserverSize;
11 | contentBoxSize: ResizeObserverSize;
12 | contentRect: DOMRectReadOnly;
13 | }
14 |
15 | const cache = new WeakMap();
16 | const scrollRegexp = /auto|scroll/;
17 | const verticalRegexp = /^tb|vertical/;
18 | const IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
19 | const parseDimension = (pixel: string | null): number => parseFloat(pixel || '0');
20 |
21 | // Helper to generate and freeze a ResizeObserverSize
22 | const size = (inlineSize = 0, blockSize = 0, switchSizes = false): ResizeObserverSize => {
23 | return new ResizeObserverSize(
24 | (switchSizes ? blockSize : inlineSize) || 0,
25 | (switchSizes ? inlineSize : blockSize) || 0
26 | );
27 | }
28 |
29 | // Return this when targets are hidden
30 | const zeroBoxes = freeze({
31 | devicePixelContentBoxSize: size(),
32 | borderBoxSize: size(),
33 | contentBoxSize: size(),
34 | contentRect: new DOMRectReadOnly(0, 0, 0, 0)
35 | })
36 |
37 | /**
38 | * Gets all box sizes of an element.
39 | */
40 | const calculateBoxSizes = (target: Element, forceRecalculation = false): ResizeObserverSizeCollection => {
41 |
42 | // Check cache to prevent recalculating styles.
43 | if (cache.has(target) && !forceRecalculation) {
44 | return cache.get(target) as ResizeObserverSizeCollection;
45 | }
46 |
47 | // If the target is hidden, send zero
48 | if (isHidden(target)) {
49 | cache.set(target, zeroBoxes);
50 | return zeroBoxes;
51 | }
52 |
53 | const cs = getComputedStyle(target);
54 |
55 | // If element has an SVG box, handle things differently, using its bounding box.
56 | const svg = isSVG(target) && (target as SVGElement).ownerSVGElement && (target as SVGGraphicsElement).getBBox();
57 |
58 | // IE does not remove padding from width/height, when box-sizing is border-box.
59 | const removePadding = !IE && cs.boxSizing === 'border-box';
60 |
61 | // Switch sizes if writing mode is vertical.
62 | const switchSizes = verticalRegexp.test(cs.writingMode || '');
63 |
64 | // Could the element have any scrollbars?
65 | const canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
66 | const canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
67 |
68 | // Calculate properties for creating boxes.
69 | const paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
70 | const paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
71 | const paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
72 | const paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
73 | const borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
74 | const borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
75 | const borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
76 | const borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
77 | const horizontalPadding = paddingLeft + paddingRight;
78 | const verticalPadding = paddingTop + paddingBottom;
79 | const horizontalBorderArea = borderLeft + borderRight;
80 | const verticalBorderArea = borderTop + borderBottom;
81 | const horizontalScrollbarThickness = !canScrollHorizontally ? 0 : (target as HTMLElement).offsetHeight - verticalBorderArea - target.clientHeight;
82 | const verticalScrollbarThickness = !canScrollVertically ? 0 : (target as HTMLElement).offsetWidth - horizontalBorderArea - target.clientWidth;
83 | const widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
84 | const heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
85 | const contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
86 | const contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
87 | const borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
88 | const borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
89 |
90 | const boxes = freeze({
91 | devicePixelContentBoxSize: size(
92 | Math.round(contentWidth * devicePixelRatio),
93 | Math.round(contentHeight * devicePixelRatio),
94 | switchSizes
95 | ),
96 | borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
97 | contentBoxSize: size(contentWidth, contentHeight, switchSizes),
98 | contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
99 | });
100 |
101 | cache.set(target, boxes);
102 |
103 | return boxes;
104 | };
105 |
106 | /**
107 | * Calculates the observe box size of an element.
108 | *
109 | * https://drafts.csswg.org/resize-observer-1/#calculate-box-size
110 | */
111 | const calculateBoxSize = (target: Element, observedBox: ResizeObserverBoxOptions, forceRecalculation?: boolean): ResizeObserverSize => {
112 | const { borderBoxSize, contentBoxSize, devicePixelContentBoxSize } = calculateBoxSizes(target, forceRecalculation);
113 | switch (observedBox) {
114 | case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
115 | return devicePixelContentBoxSize;
116 | case ResizeObserverBoxOptions.BORDER_BOX:
117 | return borderBoxSize;
118 | default:
119 | return contentBoxSize;
120 | }
121 | };
122 |
123 | export { calculateBoxSize, calculateBoxSizes };
124 |
--------------------------------------------------------------------------------
/src/algorithms/calculateDepthForNode.ts:
--------------------------------------------------------------------------------
1 | import { isHidden } from '../utils/element';
2 | /**
3 | * Calculates the depth of a node.
4 | *
5 | * https://drafts.csswg.org/resize-observer-1/#calculate-depth-for-node-h
6 | */
7 | const calculateDepthForNode = (node: Element): number => {
8 | if (isHidden(node)) {
9 | return Infinity;
10 | }
11 | let depth = 0;
12 | let parent = node.parentNode;
13 | while (parent) {
14 | depth += 1;
15 | parent = parent.parentNode;
16 | }
17 | return depth;
18 | }
19 |
20 | export { calculateDepthForNode };
21 |
--------------------------------------------------------------------------------
/src/algorithms/deliverResizeLoopError.ts:
--------------------------------------------------------------------------------
1 | const msg = 'ResizeObserver loop completed with undelivered notifications.';
2 |
3 | interface LegacyEvent extends Event {
4 | message: string;
5 | }
6 |
7 | /**
8 | * Delivers a resize loop error event.
9 | *
10 | * https://drafts.csswg.org/resize-observer-1/#deliver-resize-error
11 | */
12 | const deliverResizeLoopError = (): void => {
13 | let event;
14 | /* istanbul ignore else */
15 | if (typeof ErrorEvent === 'function') {
16 | event = new ErrorEvent('error', {
17 | message: msg
18 | });
19 | }
20 | else { // Fallback to old style of event creation
21 | event = document.createEvent('Event') as LegacyEvent;
22 | event.initEvent('error', false, false);
23 | event.message = msg;
24 | }
25 | window.dispatchEvent(event);
26 | }
27 |
28 | export { deliverResizeLoopError };
29 |
--------------------------------------------------------------------------------
/src/algorithms/gatherActiveObservationsAtDepth.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObservation } from '../ResizeObservation';
2 | import { ResizeObserverDetail } from '../ResizeObserverDetail';
3 | import { resizeObservers } from '../utils/resizeObservers';
4 | import { calculateDepthForNode } from './calculateDepthForNode';
5 |
6 | /**
7 | * Finds all active observations at a give depth
8 | *
9 | * https://drafts.csswg.org/resize-observer-1/#gather-active-observations-h
10 | */
11 | const gatherActiveObservationsAtDepth = (depth: number): void => {
12 | resizeObservers.forEach(function processObserver(ro: ResizeObserverDetail): void {
13 | ro.activeTargets.splice(0, ro.activeTargets.length);
14 | ro.skippedTargets.splice(0, ro.skippedTargets.length);
15 | ro.observationTargets.forEach(function processTarget(ot: ResizeObservation): void {
16 | if (ot.isActive()) {
17 | if (calculateDepthForNode(ot.target) > depth) {
18 | ro.activeTargets.push(ot);
19 | }
20 | else {
21 | ro.skippedTargets.push(ot);
22 | }
23 | }
24 | })
25 | })
26 | }
27 |
28 | export { gatherActiveObservationsAtDepth };
29 |
--------------------------------------------------------------------------------
/src/algorithms/hasActiveObservations.ts:
--------------------------------------------------------------------------------
1 | import { resizeObservers } from '../utils/resizeObservers';
2 | import { ResizeObserverDetail } from '../ResizeObserverDetail';
3 |
4 | /**
5 | * Checks to see if there are any active observations.
6 | *
7 | * https://drafts.csswg.org/resize-observer-1/#has-active-observations-h
8 | */
9 | const hasActiveObservations = (): boolean => {
10 | return resizeObservers.some((ro: ResizeObserverDetail): boolean => ro.activeTargets.length > 0);
11 | }
12 |
13 | export { hasActiveObservations };
14 |
--------------------------------------------------------------------------------
/src/algorithms/hasSkippedObservations.ts:
--------------------------------------------------------------------------------
1 | import { resizeObservers } from '../utils/resizeObservers';
2 | import { ResizeObserverDetail } from '../ResizeObserverDetail';
3 |
4 | /**
5 | * Checks to see if there are any skipped observations.
6 | * This is used to deliver the resize loop error.
7 | *
8 | * https://drafts.csswg.org/resize-observer-1/#has-skipped-observations-h
9 | */
10 | const hasSkippedObservations = (): boolean => {
11 | return resizeObservers.some((ro: ResizeObserverDetail): boolean => ro.skippedTargets.length > 0);
12 | }
13 |
14 | export { hasSkippedObservations }
15 |
--------------------------------------------------------------------------------
/src/exports/resize-observer.ts:
--------------------------------------------------------------------------------
1 | export { ResizeObserver } from '../ResizeObserver';
2 | export { ResizeObserverEntry } from '../ResizeObserverEntry';
3 | export { ResizeObserverSize } from '../ResizeObserverSize';
4 |
--------------------------------------------------------------------------------
/src/utils/element.ts:
--------------------------------------------------------------------------------
1 | // Tests if target is an SVGGraphicsElement
2 | const isSVG = (target: Element): boolean => target instanceof SVGElement && 'getBBox' in target;
3 |
4 | // Checks to see if element is hidden (has no display)
5 | const isHidden = (target: Element): boolean => {
6 | if (isSVG(target)) {
7 | const { width, height } = (target as SVGGraphicsElement).getBBox();
8 | return !width && !height;
9 | }
10 | const { offsetWidth, offsetHeight } = target as HTMLElement;
11 | return !(offsetWidth || offsetHeight || target.getClientRects().length);
12 | }
13 |
14 | // Checks if an object is an Element
15 | const isElement = (obj: unknown): boolean => {
16 | if (obj instanceof Element) {
17 | return true;
18 | }
19 | const scope = (obj as Element)?.ownerDocument?.defaultView;
20 | return !!(scope && obj instanceof (scope as unknown as typeof globalThis).Element);
21 | };
22 |
23 | const isReplacedElement = (target: Element): boolean => {
24 | switch (target.tagName) {
25 | case 'INPUT':
26 | if ((target as HTMLInputElement).type !== 'image') {
27 | break;
28 | }
29 | case 'VIDEO':
30 | case 'AUDIO':
31 | case 'EMBED':
32 | case 'OBJECT':
33 | case 'CANVAS':
34 | case 'IFRAME':
35 | case 'IMG':
36 | return true;
37 | }
38 | return false;
39 | }
40 |
41 | export {
42 | isSVG,
43 | isHidden,
44 | isElement,
45 | isReplacedElement
46 | };
47 |
--------------------------------------------------------------------------------
/src/utils/freeze.ts:
--------------------------------------------------------------------------------
1 | export const freeze = (obj: T): Readonly => Object.freeze(obj);
2 |
--------------------------------------------------------------------------------
/src/utils/global.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../ResizeObserver';
2 | import { ResizeObserverEntry } from '../ResizeObserverEntry';
3 | import { ResizeObserverSize } from '../ResizeObserverSize';
4 |
5 | type IsomorphicWindow = Window & {
6 | ResizeObserver?: typeof ResizeObserver;
7 | ResizeObserverEntry?: typeof ResizeObserverEntry;
8 | ResizeObserverSize?: typeof ResizeObserverSize;
9 | }
10 |
11 | /* istanbul ignore next */
12 | export const global: IsomorphicWindow =
13 | typeof window !== 'undefined' ? window : {} as unknown as Window;
14 |
--------------------------------------------------------------------------------
/src/utils/process.ts:
--------------------------------------------------------------------------------
1 | import { hasActiveObservations } from '../algorithms/hasActiveObservations';
2 | import { hasSkippedObservations } from '../algorithms/hasSkippedObservations';
3 | import { deliverResizeLoopError } from '../algorithms/deliverResizeLoopError';
4 | import { broadcastActiveObservations } from '../algorithms/broadcastActiveObservations';
5 | import { gatherActiveObservationsAtDepth } from '../algorithms/gatherActiveObservationsAtDepth';
6 |
7 | /**
8 | * Runs through the algorithms and
9 | * broadcasts and changes that are returned.
10 | */
11 | const processAlgorithm = (): boolean => {
12 | let depth = 0;
13 | gatherActiveObservationsAtDepth(depth);
14 | while (hasActiveObservations()) {
15 | depth = broadcastActiveObservations();
16 | gatherActiveObservationsAtDepth(depth);
17 | }
18 | if (hasSkippedObservations()) {
19 | deliverResizeLoopError();
20 | }
21 | return depth > 0;
22 | }
23 |
24 | export { processAlgorithm as process };
25 |
--------------------------------------------------------------------------------
/src/utils/queueMicroTask.ts:
--------------------------------------------------------------------------------
1 |
2 | let trigger: () => void;
3 | const callbacks: (() => void)[] = [];
4 | const notify = (): void => callbacks.splice(0).forEach((cb): void => cb());
5 |
6 | const queueMicroTask = (callback: () => void): void => {
7 | // Create on request for SSR
8 | // ToDo: Look at changing this
9 | if (!trigger) {
10 | let toggle = 0;
11 | const el = document.createTextNode('');
12 | const config = { characterData: true };
13 | new MutationObserver((): void => notify()).observe(el, config);
14 | trigger = (): void => { el.textContent = `${toggle ? toggle-- : toggle++}`; };
15 | }
16 | callbacks.push(callback);
17 | trigger();
18 | };
19 |
20 | export { queueMicroTask }
21 |
--------------------------------------------------------------------------------
/src/utils/queueResizeObserver.ts:
--------------------------------------------------------------------------------
1 | import { queueMicroTask } from './queueMicroTask';
2 |
3 | const queueResizeObserver = (cb: () => void): void => {
4 | queueMicroTask(function ResizeObserver (): void {
5 | requestAnimationFrame(cb);
6 | });
7 | }
8 |
9 | export { queueResizeObserver }
10 |
--------------------------------------------------------------------------------
/src/utils/resizeObservers.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserverDetail } from '../ResizeObserverDetail';
2 |
3 | const resizeObservers: ResizeObserverDetail[] = [];
4 |
5 | export { resizeObservers };
6 |
--------------------------------------------------------------------------------
/src/utils/scheduler.ts:
--------------------------------------------------------------------------------
1 | import { process } from './process';
2 | import { global } from './global';
3 | import { queueResizeObserver } from './queueResizeObserver';
4 |
5 | let watching = 0;
6 |
7 | const isWatching = (): boolean => !!watching;
8 |
9 | const CATCH_PERIOD = 250; // ms
10 |
11 | const observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
12 |
13 | const events = [
14 | // Global Resize
15 | 'resize',
16 | // Global Load
17 | 'load',
18 | // Transitions & Animations
19 | 'transitionend',
20 | 'animationend',
21 | 'animationstart',
22 | 'animationiteration',
23 | // Interactions
24 | 'keyup',
25 | 'keydown',
26 | 'mouseup',
27 | 'mousedown',
28 | 'mouseover',
29 | 'mouseout',
30 | 'blur',
31 | 'focus'
32 | ];
33 |
34 | const time = (timeout = 0) => Date.now() + timeout;
35 |
36 | let scheduled = false;
37 | class Scheduler {
38 |
39 | private observer: MutationObserver | undefined;
40 | private listener: () => void;
41 | public stopped = true;
42 |
43 | public constructor () {
44 | this.listener = (): void => this.schedule();
45 | }
46 |
47 | private run (timeout = CATCH_PERIOD): void {
48 | if (scheduled) {
49 | return;
50 | }
51 | scheduled = true;
52 | const until = time(timeout);
53 | queueResizeObserver((): void => {
54 | let elementsHaveResized = false;
55 | try {
56 | // Process Calculations
57 | elementsHaveResized = process();
58 | }
59 | finally {
60 | scheduled = false;
61 | timeout = until - time();
62 | if (!isWatching()) {
63 | return;
64 | }
65 | // Have any changes happened?
66 | if (elementsHaveResized) {
67 | this.run(1000);
68 | }
69 | // Should we continue to check?
70 | else if (timeout > 0) {
71 | this.run(timeout);
72 | }
73 | // Start listening again
74 | else {
75 | this.start();
76 | }
77 | }
78 | });
79 | }
80 |
81 | public schedule (): void {
82 | this.stop(); // Stop listening
83 | this.run(); // Run schedule
84 | }
85 |
86 | private observe (): void {
87 | const cb = (): void => this.observer && this.observer.observe(document.body, observerConfig);
88 | /* istanbul ignore next */
89 | document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
90 | }
91 |
92 | public start (): void {
93 | if (this.stopped) {
94 | this.stopped = false;
95 | this.observer = new MutationObserver(this.listener);
96 | this.observe();
97 | events.forEach((name): void => global.addEventListener(name, this.listener, true));
98 | }
99 | }
100 |
101 | public stop (): void {
102 | if (!this.stopped) {
103 | this.observer && this.observer.disconnect();
104 | events.forEach((name): void => global.removeEventListener(name, this.listener, true));
105 | this.stopped = true;
106 | }
107 | }
108 | }
109 |
110 | const scheduler = new Scheduler();
111 |
112 | const updateCount = (n: number): void => {
113 | !watching && n > 0 && scheduler.start();
114 | watching += n;
115 | !watching && scheduler.stop();
116 | }
117 |
118 | export { scheduler, updateCount };
119 |
--------------------------------------------------------------------------------
/test/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | "@typescript-eslint/ban-ts-ignore": 0
4 | }
5 | }
--------------------------------------------------------------------------------
/test/dom-rect-read-only.test.ts:
--------------------------------------------------------------------------------
1 | import { DOMRectReadOnly } from '../src/DOMRectReadOnly';
2 |
3 | describe('DOMRectReadOnly', (): void => {
4 | let rect;
5 | it('Should return a DOMRect with the correct properties.', (): void => {
6 | rect = new DOMRectReadOnly(0, 0, 0, 0);
7 | expect(rect).toMatchObject({
8 | x: 0,
9 | y: 0,
10 | top: 0,
11 | left: 0,
12 | bottom: 0,
13 | right: 0,
14 | width: 0,
15 | height: 0
16 | });
17 | rect = new DOMRectReadOnly(5, 10, 0, 0);
18 | expect(rect).toMatchObject({
19 | x: 5,
20 | y: 10,
21 | top: 10,
22 | left: 5,
23 | bottom: 10,
24 | right: 5,
25 | width: 0,
26 | height: 0
27 | });
28 | rect = new DOMRectReadOnly(0, 0, 5, 10);
29 | expect(rect).toMatchObject({
30 | x: 0,
31 | y: 0,
32 | top: 0,
33 | left: 0,
34 | bottom: 10,
35 | right: 5,
36 | width: 5,
37 | height: 10
38 | });
39 | rect = new DOMRectReadOnly(5, 10, 15, 20);
40 | expect(rect).toMatchObject({
41 | x: 5,
42 | y: 10,
43 | top: 10,
44 | left: 5,
45 | bottom: 30,
46 | right: 20,
47 | width: 15,
48 | height: 20
49 | });
50 | });
51 | it('Should support toJSON()', (): void => {
52 | const rect = new DOMRectReadOnly(5, 10, 15, 20);
53 | expect('toJSON' in rect).toBeTruthy;
54 | const rectJSON = rect.toJSON();
55 | expect('toJSON' in rectJSON).toBeFalsy;
56 | expect(rectJSON).toMatchObject({
57 | x: 5,
58 | y: 10,
59 | top: 10,
60 | left: 5,
61 | bottom: 30,
62 | right: 20,
63 | width: 15,
64 | height: 20
65 | });
66 | });
67 | it('Should support DOMRectReadOnly.fromRect()', (): void => {
68 | rect = DOMRectReadOnly.fromRect({
69 | x: 1,
70 | y: 2,
71 | width: 3,
72 | height: 4
73 | });
74 | expect(rect).toMatchObject({
75 | x: 1,
76 | y: 2,
77 | top: 2,
78 | left: 1,
79 | bottom: 6,
80 | right: 4,
81 | width: 3,
82 | height: 4
83 | });
84 | });
85 | });
--------------------------------------------------------------------------------
/test/helpers/delay.ts:
--------------------------------------------------------------------------------
1 | import { scheduler } from '../../src/utils/scheduler';
2 |
3 | const delay = ((callback: () => void): void => {
4 | setTimeout((): void => {
5 | scheduler.schedule();
6 | callback();
7 | }, 100);
8 | })
9 |
10 | export { delay }
11 |
--------------------------------------------------------------------------------
/test/helpers/offset.ts:
--------------------------------------------------------------------------------
1 | // This file patches offsetWidth and offsetHeight
2 | // as it's not supported in jsdom.
3 |
4 | const getOffsetValue = function (el: Element): number {
5 | const style = getComputedStyle(el);
6 | const width = parseFloat(style.width || '');
7 | const height = parseFloat(style.height || '');
8 | if(style.display === 'none' || (!width && !height)) {
9 | return 0;
10 | }
11 | return 1; // We only need to return a non-zero for tests
12 | }
13 |
14 | Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
15 | get: function (): number {
16 | return getOffsetValue(this);
17 | }
18 | })
19 |
20 | Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
21 | get: function (): number {
22 | return getOffsetValue(this);
23 | }
24 | })
25 |
--------------------------------------------------------------------------------
/test/inline-elements.test.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../src/ResizeObserver';
2 | import { delay } from './helpers/delay';
3 | import './helpers/offset';
4 |
5 | describe('Inline elements', (): void => {
6 |
7 | let el: HTMLElement;
8 | let ro: ResizeObserver | null;
9 |
10 | const createElement = (name: string): void => {
11 | el = document.createElement(name);
12 | el.style.width = '100px';
13 | el.style.height = '20px';
14 | el.style.display = 'inline';
15 | document.body.appendChild(el);
16 | }
17 |
18 | describe('Non-replaced elements', (): void => {
19 |
20 | afterEach((): void => {
21 | while (document.body.firstElementChild) {
22 | document.body.removeChild(document.body.firstElementChild);
23 | }
24 | if (ro) {
25 | ro.disconnect();
26 | ro = null;
27 | }
28 | })
29 |
30 | test('HTMLSpanElement: Should not fire notification', (done): void => {
31 | createElement('SPAN');
32 | ro = new ResizeObserver((): void => {
33 | expect(true).toEqual(false); // should not fire
34 | })
35 | ro.observe(el);
36 | delay(done);
37 | })
38 |
39 | test('HTMLSpanElement: Should fire notification when display is not inline', (done): void => {
40 | createElement('SPAN');
41 | el.style.display = 'block';
42 | ro = new ResizeObserver((): void => {
43 | done();
44 | })
45 | ro.observe(el);
46 | })
47 |
48 | test('HTMLInpupElement[type!=image]: Should not fire notification', (done): void => {
49 | createElement('INPUT');
50 | (el as HTMLInputElement).type = 'input';
51 | ro = new ResizeObserver((): void => {
52 | expect(true).toEqual(false); // should not fire
53 | })
54 | ro.observe(el);
55 | delay(done);
56 | })
57 | })
58 |
59 | describe('Replaced elements', (): void => {
60 |
61 | afterEach((): void => {
62 | while (document.body.firstElementChild) {
63 | document.body.removeChild(document.body.firstElementChild);
64 | }
65 | if (ro) {
66 | ro.disconnect();
67 | }
68 | })
69 |
70 | test('HTMLAudioElement: Should fire notification, even when display is inline', (done): void => {
71 | createElement('AUDIO');
72 | ro = new ResizeObserver((): void => {
73 | done();
74 | })
75 | ro.observe(el);
76 | })
77 |
78 | test('HTMLVideoElement: Should fire notification, even when display is inline', (done): void => {
79 | createElement('VIDEO');
80 | ro = new ResizeObserver((): void => {
81 | done();
82 | })
83 | ro.observe(el);
84 | })
85 |
86 | test('HTMLCanvasElement: Should fire notification, even when display is inline', (done): void => {
87 | createElement('CANVAS');
88 | ro = new ResizeObserver((): void => {
89 | done();
90 | })
91 | ro.observe(el);
92 | })
93 |
94 | test('HTMLObjectElement: Should fire notification, even when display is inline', (done): void => {
95 | createElement('Object');
96 | ro = new ResizeObserver((): void => {
97 | done();
98 | })
99 | ro.observe(el);
100 | })
101 |
102 | test('HTMLEmbedElement: Should fire notification, even when display is inline', (done): void => {
103 | createElement('EMBED');
104 | ro = new ResizeObserver((): void => {
105 | done();
106 | })
107 | ro.observe(el);
108 | })
109 |
110 | test('HTMLIFrameElement: Should fire notification, even when display is inline', (done): void => {
111 | createElement('IFRAME');
112 | ro = new ResizeObserver((): void => {
113 | done();
114 | })
115 | ro.observe(el);
116 | })
117 |
118 | test('HTMLImageElement: Should fire notification, even when display is inline', (done): void => {
119 | createElement('IMG');
120 | ro = new ResizeObserver((): void => {
121 | done();
122 | })
123 | ro.observe(el);
124 | })
125 |
126 | test('HTMLInpupElement[type=image]: Should fire notification, even when display is inline', (done): void => {
127 | createElement('INPUT');
128 | (el as HTMLInputElement).type = 'image';
129 | ro = new ResizeObserver((): void => {
130 | done();
131 | })
132 | ro.observe(el);
133 | })
134 |
135 | })
136 |
137 | })
--------------------------------------------------------------------------------
/test/queue-micro-task.test.ts:
--------------------------------------------------------------------------------
1 | import { queueMicroTask } from '../src/utils/queueMicroTask';
2 |
3 | describe('queueMicroTask', (): void => {
4 |
5 | test('queueMicroTask should execute a callback', (done): void => {
6 | queueMicroTask(done);
7 | })
8 |
9 | })
10 |
--------------------------------------------------------------------------------
/test/resize-observer-basic-svg.test.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../src/ResizeObserver';
2 | import { DOMRectReadOnly } from '../src/DOMRectReadOnly';
3 | import './helpers/offset';
4 |
5 | describe('SVGGraphicsElement', (): void => {
6 |
7 | let root: SVGGraphicsElement;
8 | let el: SVGGraphicsElement;
9 | let ro: ResizeObserver | null;
10 |
11 | beforeEach((): void => {
12 | root = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
13 | el = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
14 | document.body.appendChild(root);
15 | root.appendChild(el);
16 | el.style.width = '100px';
17 | el.style.height = '100px';
18 | })
19 |
20 | afterEach((): void => {
21 | while (document.body.firstElementChild) {
22 | document.body.removeChild(document.body.firstElementChild);
23 | }
24 | if (ro) {
25 | ro.disconnect();
26 | ro = null;
27 | }
28 | })
29 |
30 | test('Observer should fire initially when size is 0,0', (done): void => {
31 | ro = new ResizeObserver((entries): void => {
32 | expect(entries).toHaveLength(1);
33 | expect(entries[0].target).toBe(el);
34 | expect(entries[0].contentRect).toMatchObject({
35 | top: 0,
36 | left: 0,
37 | width: 0,
38 | height: 0
39 | });
40 | done();
41 | })
42 | el.getBBox = function (): DOMRect {
43 | return new DOMRectReadOnly(0, 0, 0, 0) as DOMRect;
44 | }
45 | ro.observe(el);
46 | })
47 |
48 | test('Should fire observer when element is observed for the first time.', (done): void => {
49 | ro = new ResizeObserver((entries, observer): void => {
50 | expect(entries).toHaveLength(1);
51 | expect(entries[0].target).toBe(el);
52 | expect(observer).toBe(ro);
53 | expect(entries[0].contentRect).toMatchObject({
54 | top: 0,
55 | left: 0,
56 | width: 100,
57 | height: 100
58 | });
59 | done();
60 | });
61 | el.getBBox = function (): DOMRect {
62 | return new DOMRectReadOnly(0, 0, 100, 100) as DOMRect;
63 | }
64 | ro.observe(el);
65 | })
66 |
67 | })
--------------------------------------------------------------------------------
/test/resize-observer-basic.test.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../src/ResizeObserver';
2 | import { scheduler } from '../src/utils/scheduler';
3 | import { delay } from './helpers/delay';
4 | import './helpers/offset';
5 |
6 | describe('Basics', (): void => {
7 |
8 | let el: HTMLElement;
9 | let ro: ResizeObserver | null;
10 |
11 | beforeEach((done): void => {
12 | el = document.createElement('div');
13 | el.style.width = '100px';
14 | document.body.appendChild(el);
15 | // Make sure it's a clean frame to run the test on
16 | requestAnimationFrame((): void => done());
17 | })
18 |
19 | afterEach((): void => {
20 | while (document.body.firstElementChild) {
21 | document.body.removeChild(document.body.firstElementChild);
22 | }
23 | if (ro) {
24 | ro.disconnect();
25 | ro = null;
26 | }
27 | })
28 |
29 | test('console.log(ResizeObserver) should be prettified', (): void => {
30 | expect(ResizeObserver.toString()).toBe('function ResizeObserver () { [polyfill code] }');
31 | })
32 |
33 | test('Throw error when no callback is passed to constructor', (): void => {
34 | const fn = (): void => {
35 | // eslint-disable-next-line
36 | // @ts-ignore
37 | new ResizeObserver();
38 | };
39 | expect(fn).toThrowError(`Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.`);
40 | })
41 |
42 | test('Throw error when an invalid callback is passed to constructor', (): void => {
43 | const fn = (): void => {
44 | // eslint-disable-next-line
45 | // @ts-ignore
46 | new ResizeObserver(1);
47 | };
48 | expect(fn).toThrowError(`Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.`);
49 | })
50 |
51 | test('Throw error when no target is passed to observe()', (): void => {
52 | const fn = (): void => {
53 | ro = new ResizeObserver((): void => { /* do nothing */ });
54 | // eslint-disable-next-line
55 | // @ts-ignore
56 | ro.observe();
57 | };
58 | expect(fn).toThrowError(`Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.`);
59 | })
60 |
61 | test('Throw error when an invalid target is passed to observe()', (): void => {
62 | const fn = (): void => {
63 | ro = new ResizeObserver((): void => { /* do nothing */ });
64 | // eslint-disable-next-line
65 | // @ts-ignore
66 | ro.observe(1);
67 | };
68 | expect(fn).toThrowError(`Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element`);
69 | })
70 |
71 | test('Throw error when a null target is passed to observe()', (): void => {
72 | const fn = (): void => {
73 | ro = new ResizeObserver((): void => { /* do nothing */ });
74 | // eslint-disable-next-line
75 | // @ts-ignore
76 | ro.observe(null);
77 | };
78 | expect(fn).toThrowError(`Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element`);
79 | })
80 |
81 | test('Throw error when no target is passed to unobserve()', (): void => {
82 | const fn = (): void => {
83 | ro = new ResizeObserver((): void => { /* do nothing */ });
84 | // eslint-disable-next-line
85 | // @ts-ignore
86 | ro.unobserve();
87 | };
88 | expect(fn).toThrowError(`Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.`);
89 | })
90 |
91 | test('Throw error when an invalid target is passed to unobserve()', (): void => {
92 | const fn = (): void => {
93 | ro = new ResizeObserver((): void => { /* do nothing */ });
94 | // eslint-disable-next-line
95 | // @ts-ignore
96 | ro.unobserve(1);
97 | };
98 | expect(fn).toThrowError(`Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element`);
99 | })
100 |
101 | test('Observer should fire initially when size is 0,0', (done): void => {
102 | ro = new ResizeObserver((entries): void => {
103 | expect(entries).toHaveLength(1);
104 | expect(entries[0].target).toBe(el);
105 | expect(entries[0].contentRect).toMatchObject({
106 | top: 0,
107 | left: 0,
108 | width: 0,
109 | height: 0
110 | });
111 | done();
112 | })
113 | el.style.width = '0';
114 | el.style.height = '0';
115 | ro.observe(el);
116 | })
117 |
118 | test('Observer should fire initially when display:none', (done): void => {
119 | ro = new ResizeObserver((entries): void => {
120 | expect(entries).toHaveLength(1);
121 | expect(entries[0].target).toBe(el);
122 | expect(entries[0].contentRect).toMatchObject({
123 | top: 0,
124 | left: 0,
125 | width: 0,
126 | height: 0
127 | });
128 | done();
129 | })
130 | el.style.display = 'none';
131 | ro.observe(el);
132 | })
133 |
134 | test('Observer should fire initially when parent element is display:none', (done): void => {
135 | ro = new ResizeObserver((entries): void => {
136 | expect(entries).toHaveLength(1);
137 | expect(entries[0].target).toBe(child);
138 | expect(entries[0].contentRect).toMatchObject({
139 | top: 0,
140 | left: 0,
141 | width: 0,
142 | height: 0
143 | });
144 | done();
145 | })
146 | const child = document.createElement('div');
147 | el.style.display = 'none';
148 | child.style.display = 'block';
149 | el.append(child);
150 | expect(el.style.display).toBe('none');
151 | expect(child.style.display).toBe('block');
152 | ro.observe(child);
153 | })
154 |
155 | test('Observer should still fire when an element has no document', (done): void => {
156 | el = el.cloneNode() as HTMLElement;
157 | ro = new ResizeObserver((entries): void => {
158 | expect(entries).toHaveLength(1);
159 | expect(entries[0].target).toBe(el);
160 | expect(entries[0].contentRect).toMatchObject({
161 | top: 0,
162 | left: 0,
163 | width: 0,
164 | height: 0
165 | });
166 | done();
167 | })
168 | el.style.width = '0';
169 | el.style.height = '0';
170 | ro.observe(el);
171 | })
172 |
173 | test('Observer callback.this should be observer', (done): void => {
174 | ro = new ResizeObserver(function (this: ResizeObserver): void {
175 | expect(this).toBe(ro);
176 | done();
177 | })
178 | ro.observe(el);
179 | })
180 |
181 | test('Observer should fire initially when element has size and display', (done): void => {
182 | ro = new ResizeObserver((entries): void => {
183 | expect(entries).toHaveLength(1);
184 | expect(entries[0].target).toBe(el);
185 | expect(entries[0].contentRect).toMatchObject({
186 | top: 0,
187 | left: 0,
188 | width: 100,
189 | height: 0
190 | });
191 | done();
192 | })
193 | ro.observe(el);
194 | })
195 |
196 | test('Observer should only allow watching the same element once', (done): void => {
197 | ro = new ResizeObserver((entries): void => {
198 | expect(entries).toHaveLength(1);
199 | expect(entries[0].target).toBe(el);
200 | expect(entries[0].contentRect).toMatchObject({
201 | top: 0,
202 | left: 0,
203 | width: 100,
204 | height: 0
205 | });
206 | done();
207 | })
208 | ro.observe(el);
209 | ro.observe(el);
210 | })
211 |
212 | test('Observer should fire when element size changes', (done): void => {
213 | let count = 0;
214 | ro = new ResizeObserver((entries): void => {
215 | if (!count++) {
216 | return; // skip first callback
217 | }
218 | expect(entries).toHaveLength(1);
219 | expect(entries[0].target).toBe(el);
220 | expect(entries[0].contentRect).toMatchObject({
221 | top: 0,
222 | left: 0,
223 | width: 100,
224 | height: 200
225 | });
226 | done();
227 | })
228 | el.style.width = '0';
229 | el.style.height = '0';
230 | ro.observe(el);
231 | delay((): void => {
232 | el.style.width = '100px';
233 | el.style.height = '200px';
234 | })
235 | })
236 |
237 | test('Observer should fire when the element\'s hidden state is toggled', (done): void => {
238 | let count = 0;
239 | ro = new ResizeObserver((entries): void => {
240 | count += 1;
241 | expect(entries).toHaveLength(1);
242 | expect(entries[0].target).toBe(el);
243 | expect(entries[0].contentRect).toMatchObject({
244 | top: 0,
245 | left: 0,
246 | width: count !== 2 ? 100 : 0,
247 | height: 0
248 | });
249 | if (count === 3) {
250 | done();
251 | }
252 | })
253 | ro.observe(el);
254 | delay((): void => {
255 | el.style.display = 'none';
256 | delay((): void => {
257 | el.style.removeProperty('display');
258 | })
259 | })
260 | })
261 |
262 | test('Observer should fire when only the width changes', (done): void => {
263 | let count = 0;
264 | ro = new ResizeObserver((entries): void => {
265 | if (!count++) {
266 | return; // skip first callback
267 | }
268 | expect(entries).toHaveLength(1);
269 | expect(entries[0].target).toBe(el);
270 | expect(entries[0].contentRect).toMatchObject({
271 | top: 0,
272 | left: 0,
273 | width: 100,
274 | height: 0
275 | });
276 | done();
277 | })
278 | el.style.width = '0';
279 | el.style.height = '0';
280 | ro.observe(el);
281 | delay((): void => {
282 | el.style.width = '100px';
283 | })
284 | })
285 |
286 | test('Observer should fire when only the height changes', (done): void => {
287 | let count = 0;
288 | ro = new ResizeObserver((entries): void => {
289 | if (!count++) {
290 | return; // skip first callback
291 | }
292 | expect(entries).toHaveLength(1);
293 | expect(entries[0].target).toBe(el);
294 | expect(entries[0].contentRect).toMatchObject({
295 | top: 0,
296 | left: 0,
297 | width: 0,
298 | height: 100
299 | });
300 | done();
301 | })
302 | el.style.width = '0';
303 | el.style.height = '0';
304 | ro.observe(el);
305 | delay((): void => {
306 | el.style.height = '100px';
307 | })
308 | })
309 |
310 | test('Observer should handle padding on an element.', (done): void => {
311 | ro = new ResizeObserver((entries): void => {
312 | expect(entries).toHaveLength(1);
313 | expect(entries[0].target).toBe(el);
314 | expect(entries[0].contentRect).toMatchObject({
315 | top: 1,
316 | left: 4,
317 | width: 100,
318 | height: 200
319 | });
320 | done();
321 | });
322 | el.style.width = '100px';
323 | el.style.height = '200px';
324 | el.style.padding = '1px 2px 3px 4px';
325 | ro.observe(el);
326 | })
327 |
328 | test('Observer should handle vertical scrollbars on an element.', (done): void => {
329 | ro = new ResizeObserver((entries): void => {
330 | expect(entries).toHaveLength(1);
331 | expect(entries[0].target).toBe(el);
332 | expect(entries[0].contentRect).toMatchObject({
333 | width: 85,
334 | height: 200
335 | });
336 | done();
337 | });
338 | Object.defineProperty(el, 'offsetWidth', {
339 | get: function (): number {
340 | return 100
341 | }
342 | })
343 | Object.defineProperty(el, 'offsetHeight', {
344 | get: function (): number {
345 | return 200
346 | }
347 | })
348 | Object.defineProperty(el, 'clientWidth', {
349 | get: function (): number {
350 | return 85
351 | }
352 | })
353 | Object.defineProperty(el, 'clientHeight', {
354 | get: function (): number {
355 | return 200
356 | }
357 | })
358 | el.style.overflowY = 'scroll';
359 | el.style.width = '100px';
360 | el.style.height = '200px';
361 | ro.observe(el);
362 | })
363 |
364 | test('Observer should handle horizontal scrollbars on an element.', (done): void => {
365 | ro = new ResizeObserver((entries): void => {
366 | expect(entries).toHaveLength(1);
367 | expect(entries[0].target).toBe(el);
368 | expect(entries[0].contentRect).toMatchObject({
369 | width: 100,
370 | height: 185
371 | });
372 | done();
373 | });
374 | Object.defineProperty(el, 'offsetWidth', {
375 | get: function (): number {
376 | return 100
377 | }
378 | })
379 | Object.defineProperty(el, 'offsetHeight', {
380 | get: function (): number {
381 | return 200
382 | }
383 | })
384 | Object.defineProperty(el, 'clientWidth', {
385 | get: function (): number {
386 | return 100
387 | }
388 | })
389 | Object.defineProperty(el, 'clientHeight', {
390 | get: function (): number {
391 | return 185
392 | }
393 | })
394 | el.style.overflowX = 'scroll';
395 | el.style.width = '100px';
396 | el.style.height = '200px';
397 | ro.observe(el);
398 | })
399 |
400 | test('Observer should handle horizontal and vertical scrollbars on an element.', (done): void => {
401 | ro = new ResizeObserver((entries): void => {
402 | expect(entries).toHaveLength(1);
403 | expect(entries[0].target).toBe(el);
404 | expect(entries[0].contentRect).toMatchObject({
405 | width: 85,
406 | height: 185
407 | });
408 | done();
409 | });
410 | Object.defineProperty(el, 'offsetWidth', {
411 | get: function (): number {
412 | return 100
413 | }
414 | })
415 | Object.defineProperty(el, 'offsetHeight', {
416 | get: function (): number {
417 | return 200
418 | }
419 | })
420 | Object.defineProperty(el, 'clientWidth', {
421 | get: function (): number {
422 | return 85
423 | }
424 | })
425 | Object.defineProperty(el, 'clientHeight', {
426 | get: function (): number {
427 | return 185
428 | }
429 | })
430 | el.style.overflowX = 'scroll';
431 | el.style.overflowY = 'scroll';
432 | el.style.width = '100px';
433 | el.style.height = '200px';
434 | ro.observe(el);
435 | })
436 |
437 | test('Observer should handle box-sizing and padding correctly.', (done): void => {
438 | ro = new ResizeObserver((entries): void => {
439 | expect(entries).toHaveLength(1);
440 | expect(entries[0].target).toBe(el);
441 | expect(entries[0].contentRect).toMatchObject({
442 | top: 1,
443 | left: 4,
444 | width: 94,
445 | height: 196
446 | });
447 | done();
448 | });
449 | el.style.width = '100px';
450 | el.style.height = '200px';
451 | el.style.padding = '1px 2px 3px 4px';
452 | el.style.boxSizing = 'border-box';
453 | ro.observe(el);
454 | })
455 |
456 | test.skip('Observer should fire when text content changes', (): void => {
457 | // Text doesn't seem so change element dimension
458 | })
459 |
460 | test('Observer should unobserve elements correctly.', (done): void => {
461 | const el2 = el.cloneNode() as HTMLElement;
462 | document.body.appendChild(el2);
463 | ro = new ResizeObserver((entries, observer): void => {
464 | expect(entries).toHaveLength(1);
465 | expect(entries[0].target).toBe(el);
466 | expect(observer).toBe(ro);
467 | done();
468 | });
469 | ro.observe(el);
470 | ro.observe(el2);
471 | ro.unobserve(el2);
472 | })
473 |
474 | test('Observer should allow trying to unobserve multiple times.', (done): void => {
475 | const el2 = el.cloneNode() as HTMLElement;
476 | document.body.appendChild(el2);
477 | ro = new ResizeObserver((entries, observer): void => {
478 | expect(entries).toHaveLength(1);
479 | expect(entries[0].target).toBe(el);
480 | expect(observer).toBe(ro);
481 | done();
482 | });
483 | ro.observe(el);
484 | ro.observe(el2);
485 | ro.unobserve(el2);
486 | ro.unobserve(el2);
487 | })
488 |
489 | test('Observer should disconnect correctly.', (done): void => {
490 | ro = new ResizeObserver((): void => {
491 | expect(false).toBe(true); // Should not fire
492 | });
493 | ro.observe(el);
494 | ro.disconnect();
495 | delay(done);
496 | })
497 |
498 | test('Observer should allow trying to disconnect multiple times.', (done): void => {
499 | ro = new ResizeObserver((): void => {
500 | expect(false).toBe(true); // Should not fire
501 | });
502 | ro.observe(el);
503 | ro.disconnect();
504 | ro.disconnect();
505 | delay(done);
506 | })
507 |
508 | test('Observer should observe after a disconnect.', (done): void => {
509 | ro = new ResizeObserver((): void => {
510 | done();
511 | });
512 | ro.observe(el);
513 | ro.disconnect();
514 | ro.observe(el);
515 | })
516 |
517 | test('Observer should allow disconnect and unobserve to be called.', (done): void => {
518 | ro = new ResizeObserver((): void => {
519 | expect(false).toBe(true); // Should not fire
520 | });
521 | ro.observe(el);
522 | ro.disconnect();
523 | ro.unobserve(el);
524 | delay(done);
525 | })
526 |
527 | test('Observer should fire resize loop errors.', (done): void => {
528 | window.addEventListener('error', (e): void => {
529 | expect(e.type).toBe('error');
530 | expect(e.message).toBe('ResizeObserver loop completed with undelivered notifications.');
531 | done();
532 | }, { once: true });
533 | ro = new ResizeObserver((entries): void => {
534 | entries.forEach((entry): void => {
535 | const target = entry.target as HTMLElement;
536 | target.style.width = `${entry.contentRect.width + 1000}px`;
537 | });
538 | });
539 | ro.observe(el);
540 | })
541 |
542 | test('Observer should return itself in the callback.', (done): void => {
543 | ro = new ResizeObserver((entries, observer): void => {
544 | expect(observer).toBe(observer);
545 | done();
546 | });
547 | ro.observe(el);
548 | })
549 |
550 | test('Calculations should be run after all other raf callbacks have been fired.', (done): void => {
551 | ro = new ResizeObserver((entries): void => {
552 | expect(entries[0].contentRect.width).toBe(2000);
553 | done();
554 | });
555 | ro.observe(el);
556 | requestAnimationFrame((): void => {
557 | el.style.width = '2000px';
558 | });
559 | })
560 |
561 | test('Scheduler should start and stop itself correctly.', (done): void => {
562 | // Stopped at start
563 | expect(scheduler.stopped).toBe(true);
564 | ro = new ResizeObserver((): void => { /* do nothing */ });
565 | // Creating an observer should not start the scheduler
566 | expect(scheduler.stopped).toBe(true);
567 | ro.observe(el);
568 | // Observing will trigger a schedule, however,
569 | // it will not start listening for other changes until
570 | // the processing is complete
571 | expect(scheduler.stopped).toBe(true);
572 | // After ~1s the observer should stop polling and move back to events
573 | setTimeout((): void => {
574 | expect(scheduler.stopped).toBe(false);
575 | done();
576 | }, 1500);
577 | })
578 |
579 | test('Scheduler should handle multiple starts and stops.', (): void => {
580 | expect(scheduler.stopped).toBe(true);
581 | scheduler.start();
582 | expect(scheduler.stopped).toBe(false);
583 | scheduler.start();
584 | expect(scheduler.stopped).toBe(false);
585 | scheduler.stop();
586 | expect(scheduler.stopped).toBe(true);
587 | scheduler.stop();
588 | expect(scheduler.stopped).toBe(true);
589 | })
590 |
591 | })
592 |
--------------------------------------------------------------------------------
/test/resize-observer-box-sizes.test.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../src/ResizeObserver';
2 | import './helpers/offset';
3 | import { delay } from './helpers/delay';
4 |
5 | describe('Box Options', (): void => {
6 |
7 | (window.devicePixelRatio as number) = 5;
8 |
9 | const DEFAULT_WIDTH = 100;
10 | const DEFAULT_HEIGHT = 200;
11 |
12 | const initialBox = [{
13 | inlineSize: DEFAULT_WIDTH,
14 | blockSize: DEFAULT_HEIGHT
15 | }];
16 |
17 | let el: HTMLElement;
18 | let ro: ResizeObserver | null;
19 |
20 | beforeEach((): void => {
21 | el = document.createElement('div');
22 | el.style.width = DEFAULT_WIDTH + 'px';
23 | el.style.height = DEFAULT_HEIGHT + 'px';
24 | document.body.appendChild(el);
25 | })
26 |
27 | afterEach((): void => {
28 | while (document.body.firstElementChild) {
29 | document.body.removeChild(document.body.firstElementChild);
30 | }
31 | if (ro) {
32 | ro.disconnect();
33 | ro = null;
34 | }
35 | })
36 |
37 | describe('content-box', (): void => {
38 |
39 | test('Should fire initial resize', (done): void => {
40 | ro = new ResizeObserver((entries, observer): void => {
41 | expect(entries).toHaveLength(1);
42 | expect(entries[0].target).toBe(el);
43 | expect(observer).toBe(ro);
44 | expect(entries[0].contentRect).toMatchObject({
45 | top: 0,
46 | left: 0,
47 | width: DEFAULT_WIDTH,
48 | height: DEFAULT_HEIGHT
49 | })
50 | expect(entries[0].borderBoxSize).toMatchObject(initialBox);
51 | expect(entries[0].contentBoxSize).toMatchObject(initialBox);
52 | done();
53 | })
54 | ro.observe(el, {
55 | box: 'content-box'
56 | })
57 | })
58 | })
59 |
60 | describe('border-box', (): void => {
61 |
62 | test('Should fire initial resize', (done): void => {
63 | ro = new ResizeObserver((entries, observer): void => {
64 | expect(entries).toHaveLength(1);
65 | expect(entries[0].target).toBe(el);
66 | expect(observer).toBe(ro);
67 | expect(entries[0].contentRect).toMatchObject({
68 | top: 0,
69 | left: 0,
70 | width: DEFAULT_WIDTH,
71 | height: DEFAULT_HEIGHT
72 | })
73 | expect(entries[0].borderBoxSize).toMatchObject(initialBox);
74 | expect(entries[0].contentBoxSize).toMatchObject(initialBox);
75 | done();
76 | })
77 | ro.observe(el, {
78 | box: 'border-box'
79 | })
80 | })
81 |
82 | test('Should have correct box sizes', (done): void => {
83 | ro = new ResizeObserver((entries, observer): void => {
84 | expect(entries).toHaveLength(1);
85 | expect(entries[0].target).toBe(el);
86 | expect(observer).toBe(ro);
87 | expect(entries[0].contentRect).toMatchObject({
88 | top: 10,
89 | left: 10,
90 | width: 300,
91 | height: 100
92 | })
93 | expect(entries[0].borderBoxSize).toMatchObject([{
94 | inlineSize: 330,
95 | blockSize: 130
96 | }])
97 | expect(entries[0].contentBoxSize).toMatchObject([{
98 | inlineSize: 300,
99 | blockSize: 100
100 | }])
101 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
102 | inlineSize: 1500,
103 | blockSize: 500
104 | }])
105 | done();
106 | })
107 | el.style.width = '300px';
108 | el.style.height = '100px';
109 | el.style.padding = '10px';
110 | el.style.border = 'solid 5px red';
111 | ro.observe(el, {
112 | box: 'border-box'
113 | })
114 | })
115 |
116 | test('Should switch sizes based on writing-mode:vertical', (done): void => {
117 | ro = new ResizeObserver((entries): void => {
118 | expect(entries[0].contentRect).toMatchObject({
119 | top: 10,
120 | left: 10,
121 | width: 300,
122 | height: 100
123 | })
124 | expect(entries[0].borderBoxSize).toMatchObject([{
125 | inlineSize: 130,
126 | blockSize: 330
127 | }])
128 | expect(entries[0].contentBoxSize).toMatchObject([{
129 | inlineSize: 100,
130 | blockSize: 300
131 | }])
132 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
133 | inlineSize: 500,
134 | blockSize: 1500
135 | }])
136 | done();
137 | })
138 | el.style.width = '300px';
139 | el.style.height = '100px';
140 | el.style.padding = '10px';
141 | el.style.border = 'solid 5px red';
142 | el.style.writingMode = 'vertical';
143 | ro.observe(el);
144 | })
145 |
146 | test('Should switch sizes based on writing-mode:vertical-lr', (done): void => {
147 | ro = new ResizeObserver((entries): void => {
148 | expect(entries[0].contentRect).toMatchObject({
149 | top: 10,
150 | left: 10,
151 | width: 300,
152 | height: 100
153 | })
154 | expect(entries[0].borderBoxSize).toMatchObject([{
155 | inlineSize: 130,
156 | blockSize: 330
157 | }])
158 | expect(entries[0].contentBoxSize).toMatchObject([{
159 | inlineSize: 100,
160 | blockSize: 300
161 | }])
162 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
163 | inlineSize: 500,
164 | blockSize: 1500
165 | }])
166 | done();
167 | })
168 | el.style.width = '300px';
169 | el.style.height = '100px';
170 | el.style.padding = '10px';
171 | el.style.border = 'solid 5px red';
172 | el.style.writingMode = 'vertical-lr';
173 | ro.observe(el);
174 | })
175 |
176 | test('Should switch sizes based on writing-mode:tb', (done): void => {
177 | ro = new ResizeObserver((entries): void => {
178 | expect(entries[0].contentRect).toMatchObject({
179 | top: 10,
180 | left: 10,
181 | width: 300,
182 | height: 100
183 | })
184 | expect(entries[0].borderBoxSize).toMatchObject([{
185 | inlineSize: 130,
186 | blockSize: 330
187 | }])
188 | expect(entries[0].contentBoxSize).toMatchObject([{
189 | inlineSize: 100,
190 | blockSize: 300
191 | }])
192 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
193 | inlineSize: 500,
194 | blockSize: 1500
195 | }])
196 | done();
197 | })
198 | el.style.width = '300px';
199 | el.style.height = '100px';
200 | el.style.padding = '10px';
201 | el.style.border = 'solid 5px red';
202 | el.style.writingMode = 'tb';
203 | ro.observe(el);
204 | })
205 |
206 | test('Should switch sizes based on writing-mode:tb-rl', (done): void => {
207 | ro = new ResizeObserver((entries): void => {
208 | expect(entries[0].contentRect).toMatchObject({
209 | top: 10,
210 | left: 10,
211 | width: 300,
212 | height: 100
213 | })
214 | expect(entries[0].borderBoxSize).toMatchObject([{
215 | inlineSize: 130,
216 | blockSize: 330
217 | }])
218 | expect(entries[0].contentBoxSize).toMatchObject([{
219 | inlineSize: 100,
220 | blockSize: 300
221 | }])
222 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
223 | inlineSize: 500,
224 | blockSize: 1500
225 | }])
226 | done();
227 | })
228 | el.style.width = '300px';
229 | el.style.height = '100px';
230 | el.style.padding = '10px';
231 | el.style.border = 'solid 5px red';
232 | el.style.writingMode = 'tb-rl';
233 | ro.observe(el);
234 | })
235 | })
236 |
237 | describe('device-pixel-content-box', (): void => {
238 |
239 | test('Should fire initial resize', (done): void => {
240 | ro = new ResizeObserver((entries, observer): void => {
241 | expect(entries).toHaveLength(1);
242 | expect(entries[0].target).toBe(el);
243 | expect(observer).toBe(ro);
244 | expect(entries[0].contentRect).toMatchObject({
245 | top: 0,
246 | left: 0,
247 | width: DEFAULT_WIDTH,
248 | height: DEFAULT_HEIGHT
249 | })
250 | expect(entries[0].borderBoxSize).toMatchObject(initialBox);
251 | expect(entries[0].contentBoxSize).toMatchObject(initialBox);
252 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
253 | inlineSize: 500,
254 | blockSize: 1000
255 | }])
256 | done();
257 | })
258 | ro.observe(el, {
259 | box: 'device-pixel-content-box'
260 | })
261 | })
262 |
263 | test('Should fire when pixel ratio changes (different screens)', (done): void => {
264 | let count = 0;
265 | ro = new ResizeObserver((entries): void => {
266 | if ((count += 1) === 2) {
267 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
268 | inlineSize: 200,
269 | blockSize: 400
270 | }])
271 | done();
272 | }
273 | else {
274 | expect(entries[0].devicePixelContentBoxSize).toMatchObject([{
275 | inlineSize: 500,
276 | blockSize: 1000
277 | }])
278 | }
279 | })
280 | ro.observe(el, {
281 | box: 'device-pixel-content-box'
282 | });
283 | delay((): void => {
284 | (window.devicePixelRatio as number) = 2;
285 | });
286 | })
287 | })
288 |
289 | })
--------------------------------------------------------------------------------
/test/resize-observer-multiple.test.ts:
--------------------------------------------------------------------------------
1 | import { ResizeObserver } from '../src/ResizeObserver';
2 | import { delay } from './helpers/delay';
3 | import './helpers/offset';
4 |
5 | let el: HTMLElement;
6 | let ro: ResizeObserver | null;
7 |
8 | beforeEach((): void => {
9 | el = document.createElement('div');
10 | el.style.width = '100px';
11 | document.body.appendChild(el);
12 | })
13 |
14 | afterEach((): void => {
15 | while (document.body.firstElementChild) {
16 | document.body.removeChild(document.body.firstElementChild);
17 | }
18 | if (ro) {
19 | ro.disconnect();
20 | ro = null;
21 | }
22 | })
23 |
24 | describe('Multiple HTMLElement', (): void => {
25 |
26 | test('Should return the correct entries and observer arguments, when an observation has occurred.', (done): void => {
27 | const el2 = el.cloneNode() as HTMLElement;
28 | document.body.appendChild(el2);
29 | ro = new ResizeObserver((entries, observer): void => {
30 | expect(entries).toHaveLength(2);
31 | expect(entries[0].target).toBe(el);
32 | expect(entries[1].target).toBe(el2);
33 | expect(observer).toBe(ro);
34 | done();
35 | });
36 | ro.observe(el);
37 | ro.observe(el2);
38 | })
39 |
40 | })
41 |
42 | describe('Multiple Observers', (): void => {
43 |
44 | test('Should be able to observe elements in multiple observers.', (done): void => {
45 | const ro1 = new ResizeObserver((entries, observer): void => {
46 | expect(entries).toHaveLength(1);
47 | expect(entries[0].target).toBe(el);
48 | expect(observer).toBe(ro1);
49 | observer.disconnect();
50 | });
51 | ro1.observe(el);
52 | const ro2 = new ResizeObserver((entries, observer): void => {
53 | expect(entries).toHaveLength(1);
54 | expect(entries[0].target).toBe(el);
55 | expect(observer).toBe(ro2);
56 | observer.disconnect();
57 | done();
58 | });
59 | ro2.observe(el);
60 | })
61 |
62 | test('Observers observing nothing should not be fired when others are.', (done): void => {
63 | let calls = 0;
64 | const ro1 = new ResizeObserver((): void => {
65 | expect(false).toBe(true); // Should never be called
66 | });
67 | const ro2 = new ResizeObserver((): void => {
68 | calls++;
69 | expect(calls).toBe(1); // Should only ever be called once
70 | });
71 | ro2.observe(el);
72 | const ro3 = new ResizeObserver((entries, observer): void => {
73 | expect(entries).toHaveLength(1);
74 | expect(entries[0].target).toBe(el);
75 | expect(observer).toBe(ro3);
76 | observer.disconnect();
77 | ro1.disconnect();
78 | ro2.disconnect();
79 | done();
80 | });
81 | delay(() => ro3.observe(el)); // delay to check ro2 on the next cycle
82 | })
83 |
84 | })
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "module": "es2015",
5 | "outDir": "./lib",
6 | "rootDir": "./src",
7 | "declaration": true,
8 | "removeComments": true,
9 | "strict": true,
10 | "alwaysStrict": true,
11 | "esModuleInterop": true,
12 | "skipLibCheck": true,
13 | "lib": ["dom", "es2015"]
14 | },
15 | "files": [
16 | "./src/exports/resize-observer.ts"
17 | ]
18 | }
--------------------------------------------------------------------------------