import{ResizeObserverBoxOptions as e}from"../ResizeObserverBoxOptions.js";import{ResizeObserverSize as t}from"../ResizeObserverSize.js";import{DOMRectReadOnly as o}from"../DOMRectReadOnly.js";import{isSVG as i,isHidden as r}from"../utils/element.js";import{freeze as n}from"../utils/freeze.js";import{global as d}from"../utils/global.js";var s=new WeakMap,a=/auto|scroll/,c=/^tb|vertical/,l=/msie|trident/i.test(d.navigator&&d.navigator.userAgent),parseDimension=function(e){return parseFloat(e||"0")},size=function(e,o,i){return void 0===e&&(e=0),void 0===o&&(o=0),void 0===i&&(i=!1),new t((i?o:e)||0,(i?e:o)||0)},f=n({devicePixelContentBoxSize:size(),borderBoxSize:size(),contentBoxSize:size(),contentRect:new o(0,0,0,0)}),calculateBoxSizes=function(e,t){if(void 0===t&&(t=!1),s.has(e)&&!t)return s.get(e);if(r(e))return s.set(e,f),f;var d=getComputedStyle(e),u=i(e)&&e.ownerSVGElement&&e.getBBox(),h=!l&&"border-box"===d.boxSizing,g=c.test(d.writingMode||""),v=!u&&a.test(d.overflowY||""),x=!u&&a.test(d.overflowX||""),m=u?0:parseDimension(d.paddingTop),p=u?0:parseDimension(d.paddingRight),B=u?0:parseDimension(d.paddingBottom),b=u?0:parseDimension(d.paddingLeft),z=u?0:parseDimension(d.borderTopWidth),S=u?0:parseDimension(d.borderRightWidth),R=u?0:parseDimension(d.borderBottomWidth),w=b+p,O=m+B,W=(u?0:parseDimension(d.borderLeftWidth))+S,j=z+R,C=x?e.offsetHeight-j-e.clientHeight:0,E=v?e.offsetWidth-W-e.clientWidth:0,P=h?w+W:0,M=h?O+j:0,T=u?u.width:parseDimension(d.width)-P-E,X=u?u.height:parseDimension(d.height)-M-C,_=T+w+E+W,D=X+O+C+j,L=n({devicePixelContentBoxSize:size(Math.round(T*devicePixelRatio),Math.round(X*devicePixelRatio),g),borderBoxSize:size(_,D,g),contentBoxSize:size(T,X,g),contentRect:new o(b,m,T,X)});return s.set(e,L),L},calculateBoxSize=function(t,o,i){var r=calculateBoxSizes(t,i),n=r.borderBoxSize,d=r.contentBoxSize,s=r.devicePixelContentBoxSize;switch(o){case e.DEVICE_PIXEL_CONTENT_BOX:return s;case e.BORDER_BOX:return n;default:return d}};export{calculateBoxSize,calculateBoxSizes};