import{__assign as t,__read as r}from"../../../../../node_modules/tslib/tslib.es6.js";import{invariant as e}from"../../../../../../hey-listen/dist/hey-listen.es.js";import{isKeyframesTarget as n}from"../../../animation/utils/is-keyframes-target.js";import{findDimensionValueType as o}from"./value-types.js";import{transformProps as a}from"../../html/utils/transform.js";import{number as i}from"../../../../../../style-value-types/dist/es/numbers/index.js";import{px as s}from"../../../../../../style-value-types/dist/es/numbers/units.js";var u,f=new Set(["width","height","top","left","right","bottom","x","y"]),l=function(t){return f.has(t)},m=function(t,r){t.set(r,!1),t.set(r)},h=function(t){return t===i||t===s};!function(t){t.width="width",t.height="height",t.left="left",t.right="right",t.top="top",t.bottom="bottom"}(u||(u={}));var p=function(t,r){return parseFloat(t.split(", ")[r])},c=function(t,r){return function(e,n){var o=n.transform;if("none"===o||!o)return 0;var a=o.match(/^matrix3d\((.+)\)$/);if(a)return p(a[1],r);var i=o.match(/^matrix\((.+)\)$/);return i?p(i[1],t):0}},v=new Set(["x","y","z"]),y=a.filter((function(t){return!v.has(t)}));var d={width:function(t){var r=t.x;return r.max-r.min},height:function(t){var r=t.y;return r.max-r.min},top:function(t,r){var e=r.top;return parseFloat(e)},left:function(t,r){var e=r.left;return parseFloat(e)},bottom:function(t,r){var e=t.y,n=r.top;return parseFloat(n)+(e.max-e.min)},right:function(t,r){var e=t.x,n=r.left;return parseFloat(n)+(e.max-e.min)},x:c(4,13),y:c(5,14)},g=function(a,i,u,f){void 0===u&&(u={}),void 0===f&&(f={}),i=t({},i),f=t({},f);var p=Object.keys(i).filter(l),c=[],v=!1,g=[];if(p.forEach((function(t){var r=a.getValue(t);if(a.hasValue(t)){var l,p=u[t],d=i[t],b=o(p);if(n(d))for(var x=d.length,j=null===d[0]?1:0;j<x;j++)l?e(o(d[j])===l,"All keyframes must be of the same type"):(l=o(d[j]),e(l===b||h(b)&&h(l),"Keyframes must be of the same dimension as the current value"));else l=o(d);if(b!==l)if(h(b)&&h(l)){var w=r.get();"string"==typeof w&&r.set(parseFloat(w)),"string"==typeof d?i[t]=parseFloat(d):Array.isArray(d)&&l===s&&(i[t]=d.map(parseFloat))}else(null==b?void 0:b.transform)&&(null==l?void 0:l.transform)&&(0===p||0===d)?0===p?r.set(l.transform(p)):i[t]=b.transform(d):(v||(c=function(t){var r=[];return y.forEach((function(e){var n=t.getValue(e);void 0!==n&&(r.push([e,n.get()]),n.set(e.startsWith("scale")?1:0))})),r.length&&t.syncRender(),r}(a),v=!0),g.push(t),f[t]=void 0!==f[t]?f[t]:i[t],m(r,d))}})),g.length){var b=function(t,r,e){var n=r.measureViewportBox(),o=r.getInstance(),a=getComputedStyle(o),i=a.display,s={top:a.top,left:a.left,bottom:a.bottom,right:a.right,transform:a.transform};"none"===i&&r.setStaticValue("display",t.display||"block"),r.syncRender();var u=r.measureViewportBox();return e.forEach((function(e){var o=r.getValue(e);m(o,d[e](n,s)),t[e]=d[e](u,a)})),t}(i,a,g);return c.length&&c.forEach((function(t){var e=r(t,2),n=e[0],o=e[1];a.getValue(n).set(o)})),a.syncRender(),{target:b,transitionEnd:f}}return{target:i,transitionEnd:f}};function b(t,r,e,n){return function(t){return Object.keys(t).some(l)}(r)?g(t,r,e,n):{target:r,transitionEnd:n}}export{u as BoundingBoxDimension,b as unitConversion};
//# sourceMappingURL=unit-conversion.js.map
