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IAAI,UAAU,CAAC,CAAC,CAAC;wBACpC,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,CAAC;wBACtD,kBAAkB,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC;wBAC3C,EAAE,CAAC,CAAC,CAAC,gBAAgB,IAAI,QAAQ,KAAK,eAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;4BACrE,gBAAgB,GAAG,IAAI,CAAC;wBACzB,CAAC;oBACF,CAAC;oBAED,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;gBAC5C,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACP,gBAAgB,GAAG,IAAI,CAAC;gBACzB,CAAC;gBACD,gBAAgB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACvC,CAAC,CAAC,CAAC;YACH,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAA0B,CAAC;IACxD,CAAC;CACD;AAED,eAAe,MAAM,CAAC","sourcesContent":["import { Base } from './Base';\nimport Map from '@dojo/shim/Map';\n\ninterface Observer {\n\tobserve(node: HTMLElement): void;\n}\n\ndeclare const ResizeObserver: {\n\tprototype: Observer;\n\tnew (callback: (entries: ResizeObserverEntry[]) => any): any;\n};\n\ninterface ResizeObserverEntry {\n\tcontentRect: ContentRect;\n}\n\nexport interface ContentRect {\n\treadonly bottom: number;\n\treadonly height: number;\n\treadonly left: number;\n\treadonly right: number;\n\treadonly top: number;\n\treadonly width: number;\n\treadonly x: number;\n\treadonly y: number;\n}\n\nexport interface PredicateFunction {\n\t(contentRect: ContentRect): boolean;\n}\n\nexport interface PredicateFunctions {\n\t[id: string]: PredicateFunction;\n}\n\nexport type PredicateResponses<T = PredicateFunctions> = { [id in keyof T]: boolean };\n\nexport class Resize extends Base {\n\tprivate _details = new Map<string | number, PredicateResponses>();\n\n\tpublic get<T extends PredicateFunctions>(\n\t\tkey: string | number,\n\t\tpredicates = {} as PredicateFunctions\n\t): PredicateResponses<T> {\n\t\tconst node = this.getNode(key);\n\n\t\tif (!node) {\n\t\t\tconst defaultResponse: PredicateResponses = {};\n\t\t\tfor (let predicateId in predicates) {\n\t\t\t\tdefaultResponse[predicateId] = false;\n\t\t\t}\n\t\t\treturn defaultResponse as PredicateResponses<T>;\n\t\t}\n\n\t\tif (!this._details.has(key)) {\n\t\t\tthis._details.set(key, {});\n\t\t\tconst resizeObserver = new ResizeObserver(([entry]) => {\n\t\t\t\tlet predicateChanged = false;\n\t\t\t\tif (Object.keys(predicates).length) {\n\t\t\t\t\tconst { contentRect } = entry;\n\t\t\t\t\tconst previousDetails = this._details.get(key);\n\t\t\t\t\tlet predicateResponses: PredicateResponses = {};\n\n\t\t\t\t\tfor (let predicateId in predicates) {\n\t\t\t\t\t\tconst response = predicates[predicateId](contentRect);\n\t\t\t\t\t\tpredicateResponses[predicateId] = response;\n\t\t\t\t\t\tif (!predicateChanged && response !== previousDetails![predicateId]) {\n\t\t\t\t\t\t\tpredicateChanged = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._details.set(key, predicateResponses);\n\t\t\t\t} else {\n\t\t\t\t\tpredicateChanged = true;\n\t\t\t\t}\n\t\t\t\tpredicateChanged && this.invalidate();\n\t\t\t});\n\t\t\tresizeObserver.observe(node);\n\t\t}\n\n\t\treturn this._details.get(key) as PredicateResponses<T>;\n\t}\n}\n\nexport default Resize;\n"]}