"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),r=require("react"),n=require("@react-pdf/yoga"),i=require("@react-three/fiber"),a=require("react-merge-refs"),o=require("three");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var l=u(e),c=u(t),f=u(r),d=u(n),g=u(a),m=s(o),p=function(e){return e[0].toUpperCase()+e.slice(1)},h=function(e){return e.toUpperCase().replace("-","_")},x=function(e,t,r){return Object.keys(t).forEach((function(n){var i=t[n];if("string"==typeof i)switch(n){case"flexDir":case"dir":case"flexDirection":return e.setFlexDirection(d.default["FLEX_DIRECTION_"+h(i)]);case"align":return e.setAlignItems(d.default["ALIGN_"+h(i)]),e.setAlignContent(d.default["ALIGN_"+h(i)]);case"alignContent":return e.setAlignContent(d.default["ALIGN_"+h(i)]);case"alignItems":return e.setAlignItems(d.default["ALIGN_"+h(i)]);case"alignSelf":return e.setAlignSelf(d.default["ALIGN_"+h(i)]);case"justify":case"justifyContent":return e.setJustifyContent(d.default["JUSTIFY_"+h(i)]);case"wrap":case"flexWrap":return e.setFlexWrap(d.default["WRAP_"+h(i)]);case"basis":case"flexBasis":return e.setFlexBasis(i);default:return e["set"+p(n)](i)}else if("number"==typeof i){var a=i*r;switch(n){case"basis":case"flexBasis":return e.setFlexBasis(a);case"grow":case"flexGrow":return e.setFlexGrow(a);case"shrink":case"flexShrink":return e.setFlexShrink(a);case"align":return e.setAlignItems(i);case"justify":return e.setJustifyContent(i);case"flexDir":case"dir":return e.setFlexDirection(i);case"wrap":return e.setFlexWrap(i);case"padding":case"p":return e.setPadding(d.default.EDGE_ALL,a);case"paddingLeft":case"pl":return e.setPadding(d.default.EDGE_LEFT,a);case"paddingRight":case"pr":return e.setPadding(d.default.EDGE_RIGHT,a);case"paddingTop":case"pt":return e.setPadding(d.default.EDGE_TOP,a);case"paddingBottom":case"pb":return e.setPadding(d.default.EDGE_BOTTOM,a);case"margin":case"m":return e.setMargin(d.default.EDGE_ALL,a);case"marginLeft":case"ml":return e.setMargin(d.default.EDGE_LEFT,a);case"marginRight":case"mr":return e.setMargin(d.default.EDGE_RIGHT,a);case"marginTop":case"mt":return e.setMargin(d.default.EDGE_TOP,a);case"marginBottom":case"mb":return e.setMargin(d.default.EDGE_BOTTOM,a);default:return e["set"+p(n)](a)}}}))};var w=function(e){return Object.keys(e).forEach((function(t){return void 0===e[t]?delete e[t]:{}}))},y={scaleFactor:100,requestReflow:function(){console.warn("Flex not initialized! Please report")},registerBox:function(){console.warn("Flex not initialized! Please report")},unregisterBox:function(){console.warn("Flex not initialized! Please report")},notInitialized:!0},b=r.createContext(y),v={node:null,size:[0,0],notInitialized:!0},C=r.createContext(v);function E(e){var t=r.useContext(e);return t.notInitialized&&console.warn("You must place this hook/component under a component!"),t}function B(){return E(b).requestReflow}function R(){return E(C).node}function L(){var e=E(b),t=e.requestReflow,n=e.scaleFactor,i=R();return r.useCallback((function(e,r){if(null==i)throw new Error("yoga node is null. sync size is impossible");i.setWidth(e*n),i.setHeight(r*n),t()}),[i,t])}var M=new o.Vector3;var W=["children","centerAnchor","flexDirection","flexDir","dir","alignContent","alignItems","alignSelf","align","justifyContent","justify","flexBasis","basis","flexGrow","grow","flexShrink","shrink","flexWrap","wrap","margin","m","marginBottom","marginLeft","marginRight","marginTop","mb","ml","mr","mt","padding","p","paddingBottom","paddingLeft","paddingRight","paddingTop","pb","pl","pr","pt","height","width","maxHeight","maxWidth","minHeight","minWidth"];function D(e,t){var n=e.children,a=e.centerAnchor,o=e.flexDirection,u=e.flexDir,s=e.dir,m=e.alignContent,p=e.alignItems,h=e.alignSelf,y=e.align,v=e.justifyContent,R=e.justify,L=e.flexBasis,M=e.basis,D=e.flexGrow,F=e.grow,T=e.flexShrink,I=e.shrink,j=e.flexWrap,z=e.wrap,S=e.margin,A=e.m,G=e.marginBottom,_=e.marginLeft,k=e.marginRight,O=e.marginTop,P=e.mb,H=e.ml,N=e.mr,q=e.mt,U=e.padding,J=e.p,V=e.paddingBottom,Y=e.paddingLeft,X=e.paddingRight,K=e.paddingTop,Q=e.pb,Z=e.pl,$=e.pr,ee=e.pt,te=e.height,re=e.width,ne=e.maxHeight,ie=e.maxWidth,ae=e.minHeight,oe=e.minWidth,ue=c.default(e,W),se=r.useMemo((function(){var e={flexDirection:o,flexDir:u,dir:s,alignContent:m,alignItems:p,alignSelf:h,align:y,justifyContent:v,justify:R,flexBasis:L,basis:M,flexGrow:D,grow:F,flexShrink:T,shrink:I,flexWrap:j,wrap:z,margin:S,m:A,marginBottom:G,marginLeft:_,marginRight:k,marginTop:O,mb:P,ml:H,mr:N,mt:q,padding:U,p:J,paddingBottom:V,paddingLeft:Y,paddingRight:X,paddingTop:K,pb:Q,pl:Z,pr:$,pt:ee,height:te,width:re,maxHeight:ne,maxWidth:ie,minHeight:ae,minWidth:oe};return w(e),e}),[y,m,p,h,s,L,M,u,o,D,F,T,I,j,te,R,v,A,S,G,_,k,O,ne,ie,P,ae,oe,H,N,q,J,U,V,Y,X,K,Q,Z,$,ee,re,z]),le=E(b),ce=le.registerBox,fe=le.unregisterBox,de=le.scaleFactor,ge=E(C).node,me=r.useRef(),pe=r.useMemo((function(){return d.default.Node.create()}),[]),he=B(),xe=r.useRef(null==ge?void 0:ge.getChildCount());r.useLayoutEffect((function(){x(pe,se,de)}),[se,pe,de]),r.useLayoutEffect((function(){if(me.current&&ge)return xe.current=xe.current||ge.getChildCount(),ge.insertChild(pe,xe.current),ce(pe,me.current,se,a),function(){ge.removeChild(pe),fe(pe)}}),[pe,ge,se,a,ce,fe]),r.useLayoutEffect((function(){he()}),[n,se,he]);var we=r.useState([0,0]),ye=we[0],be=we[1],ve=1/de;i.useFrame((function(){var e=("number"==typeof se.width?se.width:null)||pe.getComputedWidth().valueOf()/de,t=("number"==typeof se.height?se.height:null)||pe.getComputedHeight().valueOf()/de;(Math.abs(e-ye[0])>ve||Math.abs(t-ye[1])>ve)&&be([e,t])}));var Ce=r.useMemo((function(){return{node:pe,size:ye,centerAnchor:a}}),[pe,ye,a]);return f.default.createElement("group",l.default({ref:g.default([me,t])},ue),f.default.createElement(C.Provider,{value:Ce},"function"==typeof n?n(ye[0],ye[1],a):n))}var F=f.default.forwardRef(D);F.displayName="Box";var T=["size","yogaDirection","plane","children","scaleFactor","onReflow","disableSizeRecalc","centerAnchor","flexDirection","flexDir","dir","alignContent","alignItems","alignSelf","align","justifyContent","justify","flexBasis","basis","flexGrow","grow","flexShrink","shrink","flexWrap","wrap","margin","m","marginBottom","marginLeft","marginRight","marginTop","mb","ml","mr","mt","padding","p","paddingBottom","paddingLeft","paddingRight","paddingTop","pb","pl","pr","pt","height","width","maxHeight","maxWidth","minHeight","minWidth"];function I(e,t){var n=e.size,a=void 0===n?[1,1,1]:n,u=e.yogaDirection,s=void 0===u?"ltr":u,p=e.plane,h=void 0===p?"xy":p,y=e.children,v=e.scaleFactor,E=void 0===v?100:v,B=e.onReflow,R=e.disableSizeRecalc,L=e.centerAnchor,M=e.flexDirection,W=e.flexDir,D=e.dir,F=e.alignContent,I=e.alignItems,j=e.alignSelf,z=e.align,S=e.justifyContent,A=e.justify,G=e.flexBasis,_=e.basis,k=e.flexGrow,O=e.grow,P=e.flexShrink,H=e.shrink,N=e.flexWrap,q=e.wrap,U=e.margin,J=e.m,V=e.marginBottom,Y=e.marginLeft,X=e.marginRight,K=e.marginTop,Q=e.mb,Z=e.ml,$=e.mr,ee=e.mt,te=e.padding,re=e.p,ne=e.paddingBottom,ie=e.paddingLeft,ae=e.paddingRight,oe=e.paddingTop,ue=e.pb,se=e.pl,le=e.pr,ce=e.pt,fe=e.height,de=e.width,ge=e.maxHeight,me=e.maxWidth,pe=e.minHeight,he=e.minWidth,xe=c.default(e,T),we=r.useMemo((function(){var e={flexDirection:M,flexDir:W,dir:D,alignContent:F,alignItems:I,alignSelf:j,align:z,justifyContent:S,justify:A,flexBasis:G,basis:_,flexGrow:k,grow:O,flexShrink:P,shrink:H,flexWrap:N,wrap:q,margin:U,m:J,marginBottom:V,marginLeft:Y,marginRight:X,marginTop:K,mb:Q,ml:Z,mr:$,mt:ee,padding:te,p:re,paddingBottom:ne,paddingLeft:ie,paddingRight:ae,paddingTop:oe,pb:ue,pl:se,pr:le,pt:ce,height:fe,width:de,maxHeight:ge,maxWidth:me,minHeight:pe,minWidth:he};return w(e),e}),[z,F,I,j,D,G,_,W,M,k,O,P,H,N,fe,A,S,J,U,V,Y,X,K,ge,me,Q,pe,he,Z,$,ee,re,te,ne,ie,ae,oe,ue,se,le,ce,de,q]),ye=r.useRef(),be=r.useRef([]),ve=r.useCallback((function(e,t,r,n){void 0===n&&(n=!1);var i=be.current.findIndex((function(t){return t.node===e}));-1!==i&&be.current.splice(i,1),be.current.push({group:t,node:e,flexProps:r,centerAnchor:n})}),[]),Ce=r.useCallback((function(e){var t=be.current.findIndex((function(t){return t.node===e}));-1!==t&&be.current.splice(t,1)}),[]),Ee=r.useMemo((function(){return d.default.Node.create()}),[]);r.useLayoutEffect((function(){x(Ee,we,E)}),[Ee,we,E]);var Be=i.useThree().invalidate,Re=r.useRef(!0),Le=r.useCallback((function(){Re.current=!0,Be()}),[Be]);r.useLayoutEffect((function(){Le()}),[y,we,Le]);var Me=r.useMemo((function(){return new m.Box3}),[]),We=r.useMemo((function(){return new m.Vector3}),[]),De=h[0],Fe=h[1],Te=function(e){switch(e){case"xy":return"z";case"yz":return"x";case"xz":return"y"}}(h),Ie=function(e,t){switch(t){case"xy":return[e[0],e[1]];case"yz":return[e[1],e[2]];case"xz":return[e[0],e[2]]}}(a,h),je=Ie[0],ze=Ie[1],Se="ltr"===s?d.default.DIRECTION_LTR:"rtl"===s?d.default.DIRECTION_RTL:s,Ae=r.useMemo((function(){return{requestReflow:Le,registerBox:ve,unregisterBox:Ce,scaleFactor:E}}),[Le,ve,Ce,E]),Ge=r.useMemo((function(){return{node:Ee,size:[je,ze],centerAnchor:L}}),[Ee,je,ze,L]);function _e(){R||be.current.forEach((function(e){var t=e.group,r=e.node,n=e.flexProps,i="number"==typeof n.width?n.width*E:n.width,a="number"==typeof n.height?n.height*E:n.height;void 0!==i&&void 0!==a?(r.setWidth(i),r.setHeight(a)):0===r.getChildCount()&&(ye.current?function(e,t,r,n){e.updateMatrix();var i=e.matrix,a=e.matrixAutoUpdate;t.updateMatrixWorld();var u=(new o.Matrix4).copy(t.matrixWorld).invert();e.matrix=u,e.matrixAutoUpdate=!1,t.updateMatrixWorld(),r.setFromObject(e).getSize(n),e.matrix=i,e.matrixAutoUpdate=a,t.updateMatrixWorld()}(t,ye.current,Me,We):Me.setFromObject(t).getSize(We),r.setWidth(i||We[De]*E),r.setHeight(a||We[Fe]*E))})),Ee.calculateLayout(je*E,ze*E,Se);var e=Ee.getComputedWidth(),t=Ee.getComputedHeight(),r=0,n=0,i=0,a=0;be.current.forEach((function(u){var s,l=u.group,c=u.node,f=u.centerAnchor,d=c.getComputedLayout(),g=d.left,m=d.top,p=d.width,h=d.height,x=function(e,t,r,n){return e&&function(e){var t;return!(null!=(t=e.getParent())&&t.getParent())}(n)?[-t/2,-r/2]:[0,0]}(L,e,t,c),w=x[0],y=x[1],b=function(e){var t=e.x,r=e.y,n=e.z;return new o.Vector3(t,r,n)}(((s={})[De]=(w+g+(f?p/2:0))/E,s[Fe]=-(y+m+(f?h/2:0))/E,s[Te]=0,s));r=Math.min(r,g),i=Math.min(i,m),n=Math.max(n,g+p),a=Math.max(a,m+h),l.position.copy(b)})),B&&B((n-r)/E,(a-i)/E),Be()}return i.useFrame((function(){Re.current&&(Re.current=!1,_e())})),f.default.createElement("group",l.default({ref:g.default([ye,t])},xe),f.default.createElement(b.Provider,{value:Ae},f.default.createElement(C.Provider,{value:Ge},y)))}var j=f.default.forwardRef(I);j.displayName="Flex",exports.Box=F,exports.Flex=j,exports.useContext=E,exports.useFlexNode=R,exports.useFlexSize=function(){var e=E(C),t=e.size,n=t[0],i=t[1],a=e.centerAnchor;return r.useMemo((function(){return[n,i,a]}),[n,i,a])},exports.useReflow=B,exports.useSetSize=L,exports.useSyncGeometrySize=function(){var e=L();return r.useCallback((function(t){if(t.updateMatrixWorld(),M.setFromMatrixScale(t.matrixWorld),Math.abs(M.x-M.y)>.001||Math.abs(M.y-M.z)>.001)throw new Error("object was not scaled uniformly");var r=M.x;t.geometry.computeBoundingBox();var n=t.geometry.boundingBox;e((n.max.x-n.min.x)*r,(n.max.y-n.min.y)*r)}),[e])};