rough-native
Version:
Create graphics using HTML Canvas or SVG with a hand-drawn, sketchy, appearance. Features comprehensive React hooks, memory management, and React 18 concurrent rendering support.
1 lines • 52.6 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},t(e,r)};function r(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e},n.apply(this,arguments)};function a(e,t,r){if(r||2===arguments.length)for(var n,a=0,o=t.length;a<o;a++)!n&&a in t||(n||(n=Array.prototype.slice.call(t,0,a)),n[a]=t[a]);return e.concat(n||Array.prototype.slice.call(t))}function o(e,t,r){if(e&&e.length){const[n,a]=t,o=Math.PI/180*r,s=Math.cos(o),i=Math.sin(o);for(const t of e){const[e,r]=t;t[0]=(e-n)*s-(r-a)*i+n,t[1]=(e-n)*i+(r-a)*s+a}}}function s(e,t){return e[0]===t[0]&&e[1]===t[1]}function i(e,t,r,n=1){const a=r,i=Math.max(t,.1),h=e[0]&&e[0][0]&&"number"==typeof e[0][0]?[e]:e,c=[0,0];if(a)for(const e of h)o(e,c,a);const u=function(e,t,r){const n=[];for(const t of e){const e=[...t];s(e[0],e[e.length-1])||e.push([e[0][0],e[0][1]]),e.length>2&&n.push(e)}const a=[];t=Math.max(t,.1);const o=[];for(const e of n)for(let t=0;t<e.length-1;t++){const r=e[t],n=e[t+1];if(r[1]!==n[1]){const e=Math.min(r[1],n[1]);o.push({ymin:e,ymax:Math.max(r[1],n[1]),x:e===r[1]?r[0]:n[0],islope:(n[0]-r[0])/(n[1]-r[1])})}}if(o.sort(((e,t)=>e.ymin<t.ymin?-1:e.ymin>t.ymin?1:e.x<t.x?-1:e.x>t.x?1:e.ymax===t.ymax?0:(e.ymax-t.ymax)/Math.abs(e.ymax-t.ymax))),!o.length)return a;let i=[],h=o[0].ymin,c=0;for(;i.length||o.length;){if(o.length){let e=-1;for(let t=0;t<o.length&&!(o[t].ymin>h);t++)e=t;o.splice(0,e+1).forEach((e=>{i.push({s:h,edge:e})}))}if(i=i.filter((e=>!(e.edge.ymax<=h))),i.sort(((e,t)=>e.edge.x===t.edge.x?0:(e.edge.x-t.edge.x)/Math.abs(e.edge.x-t.edge.x))),(1!==r||c%t==0)&&i.length>1)for(let e=0;e<i.length;e+=2){const t=e+1;if(t>=i.length)break;const r=i[e].edge,n=i[t].edge;a.push([[Math.round(r.x),h],[Math.round(n.x),h]])}h+=r,i.forEach((e=>{e.edge.x=e.edge.x+r*e.edge.islope})),c++}return a}(h,i,n);if(a){for(const e of h)o(e,c,-a);!function(e,t,r){const n=[];e.forEach((e=>n.push(...e))),o(n,t,r)}(u,c,-a)}return u}"function"==typeof SuppressedError&&SuppressedError;var h={HIGH_MEMORY_PRESSURE_THRESHOLD:.8,MEDIUM_MEMORY_PRESSURE_THRESHOLD:.6,CACHE_SIZE_HIGH_PRESSURE:50,CACHE_SIZE_MEDIUM_PRESSURE:200,CACHE_SIZE_LOW_PRESSURE:500,CACHE_SIZE_DEFAULT:200,HIGH_PRESSURE_CLEANUP_PERCENT:.75,HIGH_PRESSURE_KEEP_PERCENT:.25,MEDIUM_PRESSURE_CLEANUP_PERCENT:.5,MEDIUM_PRESSURE_KEEP_PERCENT:.5,SHAPE_CACHE_MULTIPLIER:2,MAX_CONCURRENT_GENERATIONS_UNDER_PRESSURE:2,MEMORY_CHECK_INTERVAL_MS:5e3,BYTES_TO_KB:1024,KB_TO_MB:1024},c={MAX_ERROR_CACHE_SIZE:50,ERROR_RATE_LIMIT_PER_MINUTE:10,ERROR_CACHE_CLEANUP_INTERVAL_MS:6e4,SAMPLE_SIZE_FOR_ARRAY_PARAMS:3,MS_PER_MINUTE:6e4},u={SEED_UPPER_BOUND:Math.pow(2,31),LCG_MASK:Math.pow(2,31)-1,LCG_MULTIPLIER:48271,LCG_DIVISOR:Math.pow(2,31)},l={MEMORY:h,ERROR:c,DRAWING:{DEFAULT_MAX_RANDOMNESS_OFFSET:2,DEFAULT_ROUGHNESS:1,DEFAULT_BOWING:1,DEFAULT_STROKE_WIDTH:1,DEFAULT_CURVE_TIGHTNESS:0,DEFAULT_CURVE_FITTING:.95,DEFAULT_CURVE_STEP_COUNT:9,DEFAULT_FILL_WEIGHT:-1,DEFAULT_HACHURE_ANGLE:-41,DEFAULT_HACHURE_GAP:-1,DEFAULT_DASH_OFFSET:-1,DEFAULT_DASH_GAP:-1,DEFAULT_ZIGZAG_OFFSET:-1,DEFAULT_SEED:0,DEFAULT_DISABLE_MULTI_STROKE:!1,DEFAULT_DISABLE_MULTI_STROKE_FILL:!1,DEFAULT_PRESERVE_VERTICES:!1,DEFAULT_FILL_SHAPE_ROUGHNESS_GAIN:.8,CURVE_ROUGHNESS_MULTIPLIER:.2,MULTI_STROKE_OFFSET_MULTIPLIER:1.5,MULTI_STROKE_ROUGHNESS_MULTIPLIER:.22,BEZIER_CURVE_POINTS:10,SIMPLIFICATION_FACTOR:4},RENDERING:{CURVE_STEP_COUNT_BASE:200,ELLIPSE_INCREMENT_OFFSET_FACTOR:.1,ELLIPSE_INCREMENT_OFFSET_RANGE:.4,ELLIPSE_MULTI_STROKE_FACTOR:1.5,ARC_RADIUS_OFFSET_FACTOR:.01,ARC_INCREMENT_DIVISOR:2,ARC_MULTI_STROKE_FACTOR:1.5,PATTERN_FILL_ARC_RADIUS_OFFSET:.01,LINE_LENGTH_THRESHOLD_SHORT:200,LINE_LENGTH_THRESHOLD_LONG:500,ROUGHNESS_GAIN_LONG_LINES:.4,ROUGHNESS_GAIN_COEFFICIENT:-.0016668,ROUGHNESS_GAIN_CONSTANT:1.233334,OFFSET_SQUARED_MULTIPLIER:100,OFFSET_DIVISOR_LONG_LINES:10,DIVERGE_POINT_BASE:.2,DIVERGE_POINT_RANGE:.2,BOWING_DISPLACEMENT_DIVISOR:200},FILL_PATTERN:{HACHURE_ANGLE_ADJUSTMENT:90,DEFAULT_HACHURE_GAP_MULTIPLIER:4,MIN_HACHURE_GAP:.1,HACHURE_SKIP_OFFSET_THRESHOLD:.7,CROSS_HATCH_ANGLE_INCREMENT:90,DEFAULT_ZIGZAG_GAP_MULTIPLIER:4,MIN_ZIGZAG_GAP:.1,DEGREES_TO_RADIANS_FACTOR:180,ZIGZAG_DISPLACEMENT_FACTOR:.5},RANDOM:u,REACT_HOOK:{ID_PREFIX:"rough-",MAX_RECURSION_DEPTH:10,KEY_LOOKUP_SET_THRESHOLD:10,DEFAULT_CURVE_TIGHTNESS:2},VALIDATION:{MIN_POINT_ARRAY_LENGTH:2,MIN_POLYGON_POINTS:3,MIN_PATH_STRING_LENGTH:0},getEnvironment:function(){var e,t,r="undefined"!=typeof process&&"production"===(null===(e=process.env)||void 0===e?void 0:e.NODE_ENV),n="undefined"!=typeof process&&"true"===(null===(t=process.env)||void 0===t?void 0:t.ROUGH_LOW_END_DEVICE);return{cacheSize:n?h.CACHE_SIZE_HIGH_PRESSURE:r?h.CACHE_SIZE_MEDIUM_PRESSURE:h.CACHE_SIZE_DEFAULT,highMemoryThreshold:n?.7:h.HIGH_MEMORY_PRESSURE_THRESHOLD,memoryCheckInterval:r?2*h.MEMORY_CHECK_INTERVAL_MS:h.MEMORY_CHECK_INTERVAL_MS,enableErrorLogging:!r,errorRateLimit:r?c.ERROR_RATE_LIMIT_PER_MINUTE/2:c.ERROR_RATE_LIMIT_PER_MINUTE}}};function p(e,t){var r,n=t.hachureAngle+l.FILL_PATTERN.HACHURE_ANGLE_ADJUSTMENT,a=t.hachureGap;a<0&&(a=t.strokeWidth*l.FILL_PATTERN.DEFAULT_HACHURE_GAP_MULTIPLIER),a=Math.round(Math.max(a,l.FILL_PATTERN.MIN_HACHURE_GAP));var o=1;return t.roughness>=1&&((null===(r=t.randomizer)||void 0===r?void 0:r.next())||Math.random())>l.FILL_PATTERN.HACHURE_SKIP_OFFSET_THRESHOLD&&(o=a),i(e,a,n,o||1)}var f=function(){function e(e){this.helper=e}return e.prototype.fillPolygons=function(e,t){return this._fillPolygons(e,t)},e.prototype._fillPolygons=function(e,t){var r=p(e,t);return{type:"fillSketch",ops:this.renderLines(r,t)}},e.prototype.renderLines=function(e,t){for(var r=[],n=0,a=e;n<a.length;n++){var o=a[n];r.push.apply(r,this.helper.doubleLineOps(o[0][0],o[0][1],o[1][0],o[1][1],t))}return r},e}();function E(e){var t=e[0],r=e[1];return Math.sqrt(Math.pow(t[0]-r[0],2)+Math.pow(t[1]-r[1],2))}var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.fillPolygons=function(e,t){var r=t.hachureGap;r<0&&(r=4*t.strokeWidth),r=Math.max(r,.1);for(var n=p(e,Object.assign({},t,{hachureGap:r})),o=Math.PI/180*t.hachureAngle,s=[],i=.5*r*Math.cos(o),h=.5*r*Math.sin(o),c=0,u=n;c<u.length;c++){var l=u[c],f=l[0],d=l[1];E([f,d])&&s.push([[f[0]-i,f[1]+h],a([],d,!0)],[[f[0]+i,f[1]-h],a([],d,!0)])}return{type:"fillSketch",ops:this.renderLines(s,t)}},t}(f),_=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t.prototype.fillPolygons=function(e,t){var r=this._fillPolygons(e,t),n=Object.assign({},t,{hachureAngle:t.hachureAngle+l.FILL_PATTERN.CROSS_HATCH_ANGLE_INCREMENT}),a=this._fillPolygons(e,n);return r.ops=r.ops.concat(a.ops),r},t}(f),R=function(){function e(e){this.helper=e}return e.prototype.fillPolygons=function(e,t){var r=p(e,t=Object.assign({},t,{hachureAngle:0}));return this.dotsOnLines(r,t)},e.prototype.dotsOnLines=function(e,t){var r=[],n=t.hachureGap;n<0&&(n=4*t.strokeWidth),n=Math.max(n,.1);var a=t.fillWeight;a<0&&(a=t.strokeWidth/2);for(var o=n/4,s=0,i=e;s<i.length;s++)for(var h=i[s],c=E(h),u=c/n,l=Math.ceil(u)-1,p=c-l*n,f=(h[0][0]+h[1][0])/2-n/4,d=Math.min(h[0][1],h[1][1]),_=0;_<l;_++){var R=d+p+_*n,y=f-o+2*Math.random()*o,g=R-o+2*Math.random()*o,M=this.helper.ellipse(y,g,a,a,t);r.push.apply(r,M.ops)}return{type:"fillSketch",ops:r}},e}(),y=function(){function e(e){this.helper=e}return e.prototype.fillPolygons=function(e,t){var r=p(e,t);return{type:"fillSketch",ops:this.dashedLine(r,t)}},e.prototype.dashedLine=function(e,t){var r=this,n=t.dashOffset<0?t.hachureGap<0?4*t.strokeWidth:t.hachureGap:t.dashOffset,a=t.dashGap<0?t.hachureGap<0?4*t.strokeWidth:t.hachureGap:t.dashGap,o=[];return e.forEach((function(e){var s=E(e),i=Math.floor(s/(n+a)),h=(s+a-i*(n+a))/2,c=e[0],u=e[1];c[0]>u[0]&&(c=e[1],u=e[0]);for(var l=Math.atan((u[1]-c[1])/(u[0]-c[0])),p=0;p<i;p++){var f=p*(n+a),d=f+n,_=[c[0]+f*Math.cos(l)+h*Math.cos(l),c[1]+f*Math.sin(l)+h*Math.sin(l)],R=[c[0]+d*Math.cos(l)+h*Math.cos(l),c[1]+d*Math.sin(l)+h*Math.sin(l)];o.push.apply(o,r.helper.doubleLineOps(_[0],_[1],R[0],R[1],t))}})),o},e}(),g=function(){function e(e){this.helper=e}return e.prototype.fillPolygons=function(e,t){var r=t.hachureGap<0?4*t.strokeWidth:t.hachureGap,n=t.zigzagOffset<0?r:t.zigzagOffset,a=p(e,t=Object.assign({},t,{hachureGap:r+n}));return{type:"fillSketch",ops:this.zigzagLines(a,n,t)}},e.prototype.zigzagLines=function(e,t,r){var n=this,o=[];return e.forEach((function(e){var s=E(e),i=Math.round(s/(2*t)),h=e[0],c=e[1];h[0]>c[0]&&(h=e[1],c=e[0]);for(var u=Math.atan((c[1]-h[1])/(c[0]-h[0])),l=0;l<i;l++){var p=2*l*t,f=2*(l+1)*t,d=Math.sqrt(2*Math.pow(t,2)),_=[h[0]+p*Math.cos(u),h[1]+p*Math.sin(u)],R=[h[0]+f*Math.cos(u),h[1]+f*Math.sin(u)],y=[_[0]+d*Math.cos(u+Math.PI/4),_[1]+d*Math.sin(u+Math.PI/4)];o.push.apply(o,a(a([],n.helper.doubleLineOps(_[0],_[1],y[0],y[1],r),!1),n.helper.doubleLineOps(y[0],y[1],R[0],R[1],r),!1))}})),o},e}(),M={};var m=function(){function e(e){this.seed=e}return e.prototype.next=function(){return this.seed?(l.RANDOM.LCG_MASK&(this.seed=Math.imul(l.RANDOM.LCG_MULTIPLIER,this.seed)))/l.RANDOM.LCG_DIVISOR:Math.random()},e}();const S=0,I=1,v=2,T={A:7,a:7,C:6,c:6,H:1,h:1,L:2,l:2,M:2,m:2,Q:4,q:4,S:4,s:4,T:2,t:2,V:1,v:1,Z:0,z:0};function A(e,t){return e.type===t}function O(e){const t=[],r=function(e){const t=new Array;for(;""!==e;)if(e.match(/^([ \t\r\n,]+)/))e=e.substr(RegExp.$1.length);else if(e.match(/^([aAcChHlLmMqQsStTvVzZ])/))t[t.length]={type:S,text:RegExp.$1},e=e.substr(RegExp.$1.length);else{if(!e.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/))return[];t[t.length]={type:I,text:`${parseFloat(RegExp.$1)}`},e=e.substr(RegExp.$1.length)}return t[t.length]={type:v,text:""},t}(e);let n="BOD",a=0,o=r[a];for(;!A(o,v);){let s=0;const i=[];if("BOD"===n){if("M"!==o.text&&"m"!==o.text)return O("M0,0"+e);a++,s=T[o.text],n=o.text}else A(o,I)?s=T[n]:(a++,s=T[o.text],n=o.text);if(!(a+s<r.length))throw new Error("Path data ended short");for(let e=a;e<a+s;e++){const t=r[e];if(!A(t,I))throw new Error("Param not a number: "+n+","+t.text);i[i.length]=+t.text}if("number"!=typeof T[n])throw new Error("Bad segment: "+n);{const e={key:n,data:i};t.push(e),a+=s,o=r[a],"M"===n&&(n="L"),"m"===n&&(n="l")}}return t}function L(e){let t=0,r=0,n=0,a=0;const o=[];for(const{key:s,data:i}of e)switch(s){case"M":o.push({key:"M",data:[...i]}),[t,r]=i,[n,a]=i;break;case"m":t+=i[0],r+=i[1],o.push({key:"M",data:[t,r]}),n=t,a=r;break;case"L":o.push({key:"L",data:[...i]}),[t,r]=i;break;case"l":t+=i[0],r+=i[1],o.push({key:"L",data:[t,r]});break;case"C":o.push({key:"C",data:[...i]}),t=i[4],r=i[5];break;case"c":{const e=i.map(((e,n)=>n%2?e+r:e+t));o.push({key:"C",data:e}),t=e[4],r=e[5];break}case"Q":o.push({key:"Q",data:[...i]}),t=i[2],r=i[3];break;case"q":{const e=i.map(((e,n)=>n%2?e+r:e+t));o.push({key:"Q",data:e}),t=e[2],r=e[3];break}case"A":o.push({key:"A",data:[...i]}),t=i[5],r=i[6];break;case"a":t+=i[5],r+=i[6],o.push({key:"A",data:[i[0],i[1],i[2],i[3],i[4],t,r]});break;case"H":o.push({key:"H",data:[...i]}),t=i[0];break;case"h":t+=i[0],o.push({key:"H",data:[t]});break;case"V":o.push({key:"V",data:[...i]}),r=i[0];break;case"v":r+=i[0],o.push({key:"V",data:[r]});break;case"S":o.push({key:"S",data:[...i]}),t=i[2],r=i[3];break;case"s":{const e=i.map(((e,n)=>n%2?e+r:e+t));o.push({key:"S",data:e}),t=e[2],r=e[3];break}case"T":o.push({key:"T",data:[...i]}),t=i[0],r=i[1];break;case"t":t+=i[0],r+=i[1],o.push({key:"T",data:[t,r]});break;case"Z":case"z":o.push({key:"Z",data:[]}),t=n,r=a}return o}function N(e){const t=[];let r="",n=0,a=0,o=0,s=0,i=0,h=0;for(const{key:c,data:u}of e){switch(c){case"M":t.push({key:"M",data:[...u]}),[n,a]=u,[o,s]=u;break;case"C":t.push({key:"C",data:[...u]}),n=u[4],a=u[5],i=u[2],h=u[3];break;case"L":t.push({key:"L",data:[...u]}),[n,a]=u;break;case"H":n=u[0],t.push({key:"L",data:[n,a]});break;case"V":a=u[0],t.push({key:"L",data:[n,a]});break;case"S":{let e=0,o=0;"C"===r||"S"===r?(e=n+(n-i),o=a+(a-h)):(e=n,o=a),t.push({key:"C",data:[e,o,...u]}),i=u[0],h=u[1],n=u[2],a=u[3];break}case"T":{const[e,o]=u;let s=0,c=0;"Q"===r||"T"===r?(s=n+(n-i),c=a+(a-h)):(s=n,c=a);const l=n+2*(s-n)/3,p=a+2*(c-a)/3,f=e+2*(s-e)/3,E=o+2*(c-o)/3;t.push({key:"C",data:[l,p,f,E,e,o]}),i=s,h=c,n=e,a=o;break}case"Q":{const[e,r,o,s]=u,c=n+2*(e-n)/3,l=a+2*(r-a)/3,p=o+2*(e-o)/3,f=s+2*(r-s)/3;t.push({key:"C",data:[c,l,p,f,o,s]}),i=e,h=r,n=o,a=s;break}case"A":{const e=Math.abs(u[0]),r=Math.abs(u[1]),o=u[2],s=u[3],i=u[4],h=u[5],c=u[6];if(0===e||0===r)t.push({key:"C",data:[n,a,h,c,h,c]}),n=h,a=c;else if(n!==h||a!==c){C(n,a,h,c,e,r,o,s,i).forEach((function(e){t.push({key:"C",data:e})})),n=h,a=c}break}case"Z":t.push({key:"Z",data:[]}),n=o,a=s}r=c}return t}function P(e,t,r){return[e*Math.cos(r)-t*Math.sin(r),e*Math.sin(r)+t*Math.cos(r)]}function C(e,t,r,n,a,o,s,i,h,c){const u=(l=s,Math.PI*l/180);var l;let p=[],f=0,E=0,d=0,_=0;if(c)[f,E,d,_]=c;else{[e,t]=P(e,t,-u),[r,n]=P(r,n,-u);const s=(e-r)/2,c=(t-n)/2;let l=s*s/(a*a)+c*c/(o*o);l>1&&(l=Math.sqrt(l),a*=l,o*=l);const p=a*a,R=o*o,y=p*R-p*c*c-R*s*s,g=p*c*c+R*s*s,M=(i===h?-1:1)*Math.sqrt(Math.abs(y/g));d=M*a*c/o+(e+r)/2,_=M*-o*s/a+(t+n)/2,f=Math.asin(parseFloat(((t-_)/o).toFixed(9))),E=Math.asin(parseFloat(((n-_)/o).toFixed(9))),e<d&&(f=Math.PI-f),r<d&&(E=Math.PI-E),f<0&&(f=2*Math.PI+f),E<0&&(E=2*Math.PI+E),h&&f>E&&(f-=2*Math.PI),!h&&E>f&&(E-=2*Math.PI)}let R=E-f;if(Math.abs(R)>120*Math.PI/180){const e=E,t=r,i=n;E=h&&E>f?f+120*Math.PI/180*1:f+120*Math.PI/180*-1,p=C(r=d+a*Math.cos(E),n=_+o*Math.sin(E),t,i,a,o,s,0,h,[E,e,d,_])}R=E-f;const y=Math.cos(f),g=Math.sin(f),M=Math.cos(E),m=Math.sin(E),S=Math.tan(R/4),I=4/3*a*S,v=4/3*o*S,T=[e,t],A=[e+I*g,t-v*y],O=[r+I*m,n-v*M],L=[r,n];if(A[0]=2*T[0]-A[0],A[1]=2*T[1]-A[1],c)return[A,O,L].concat(p);{p=[A,O,L].concat(p);const e=[];for(let t=0;t<p.length;t+=3){const r=P(p[t][0],p[t][1],u),n=P(p[t+1][0],p[t+1][1],u),a=P(p[t+2][0],p[t+2][1],u);e.push([r[0],r[1],n[0],n[1],a[0],a[1]])}return e}}var D={randOffset:function(e,t){return Z(e,t)},randOffsetWithRange:function(e,t,r){return Y(e,t,r)},ellipse:function(e,t,r,n,a){var o=H(r,n,a);return F(e,t,a,o).opset},doubleLineOps:function(e,t,r,n,a){return j(e,t,r,n,a,!0)}};function U(e,t,r,n,a){return{type:"path",ops:j(e,t,r,n,a)}}function G(e,t,r){var n=(e||[]).length;if(n>2){for(var a=[],o=0;o<n-1;o++)a.push.apply(a,j(e[o][0],e[o][1],e[o+1][0],e[o+1][1],r));return t&&a.push.apply(a,j(e[n-1][0],e[n-1][1],e[0][0],e[0][1],r)),{type:"path",ops:a}}return 2===n?U(e[0][0],e[0][1],e[1][0],e[1][1],r):{type:"path",ops:[]}}function b(e,t,r,n,a){return function(e,t){return G(e,!0,t)}([[e,t],[e+r,t],[e+r,t+n],[e,t+n]],a)}function k(e,t){if(e.length){for(var r="number"==typeof e[0][0]?[e]:e,n=q(r[0],1*(1+t.roughness*l.DRAWING.CURVE_ROUGHNESS_MULTIPLIER),t),a=t.disableMultiStroke?[]:q(r[0],l.DRAWING.MULTI_STROKE_OFFSET_MULTIPLIER*(1+t.roughness*l.DRAWING.MULTI_STROKE_ROUGHNESS_MULTIPLIER),V(t)),o=1;o<r.length;o++){var s=r[o];if(s.length){for(var i=q(s,1*(1+t.roughness*l.DRAWING.CURVE_ROUGHNESS_MULTIPLIER),t),h=t.disableMultiStroke?[]:q(s,l.DRAWING.MULTI_STROKE_OFFSET_MULTIPLIER*(1+t.roughness*l.DRAWING.MULTI_STROKE_ROUGHNESS_MULTIPLIER),V(t)),c=0,u=i;c<u.length;c++){"move"!==(E=u[c]).op&&n.push(E)}for(var p=0,f=h;p<f.length;p++){var E;"move"!==(E=f[p]).op&&a.push(E)}}}return{type:"path",ops:n.concat(a)}}return{type:"path",ops:[]}}function H(e,t,r){var n=Math.sqrt(2*Math.PI*Math.sqrt((Math.pow(e/2,2)+Math.pow(t/2,2))/2)),a=Math.ceil(Math.max(r.curveStepCount,r.curveStepCount/Math.sqrt(l.RENDERING.CURVE_STEP_COUNT_BASE)*n)),o=2*Math.PI/a,s=Math.abs(e/2),i=Math.abs(t/2),h=1-r.curveFitting;return{increment:o,rx:s+=Z(s*h,r),ry:i+=Z(i*h,r)}}function F(e,t,r,n){var a=Q(n.increment,e,t,n.rx,n.ry,1,n.increment*Y(l.RENDERING.ELLIPSE_INCREMENT_OFFSET_FACTOR,Y(l.RENDERING.ELLIPSE_INCREMENT_OFFSET_RANGE,1,r),r),r),o=a[0],s=a[1],i=J(o,null,r);if(!r.disableMultiStroke&&0!==r.roughness){var h=J(Q(n.increment,e,t,n.rx,n.ry,l.RENDERING.ELLIPSE_MULTI_STROKE_FACTOR,0,r)[0],null,r);i=i.concat(h)}return{estimatedPoints:s,opset:{type:"path",ops:i}}}function w(e,t,r,n,o,s,i,h,c){var u=e,p=t,f=Math.abs(r/2),E=Math.abs(n/2);f+=Z(f*l.RENDERING.ARC_RADIUS_OFFSET_FACTOR,c),E+=Z(E*l.RENDERING.ARC_RADIUS_OFFSET_FACTOR,c);for(var d=o,_=s;d<0;)d+=2*Math.PI,_+=2*Math.PI;_-d>2*Math.PI&&(d=0,_=2*Math.PI);var R=2*Math.PI/c.curveStepCount,y=Math.min(R/l.RENDERING.ARC_INCREMENT_DIVISOR,(_-d)/l.RENDERING.ARC_INCREMENT_DIVISOR),g=X(y,u,p,f,E,d,_,1,c);if(!c.disableMultiStroke){var M=X(y,u,p,f,E,d,_,l.RENDERING.ARC_MULTI_STROKE_FACTOR,c);g.push.apply(g,M)}return i&&(h?g.push.apply(g,a(a([],j(u,p,u+f*Math.cos(d),p+E*Math.sin(d),c),!1),j(u,p,u+f*Math.cos(_),p+E*Math.sin(_),c),!1)):g.push({op:"lineTo",data:[u,p]},{op:"lineTo",data:[u+f*Math.cos(d),p+E*Math.sin(d)]})),{type:"path",ops:g}}function x(e,t){for(var r=[],n=[0,0],a=[0,0],o=0,s=N(L(O(e)));o<s.length;o++){var i=s[o],h=i.key,c=i.data;switch(h){case"M":a=[c[0],c[1]],n=[c[0],c[1]];break;case"L":r.push.apply(r,j(a[0],a[1],c[0],c[1],t)),a=[c[0],c[1]];break;case"C":var u=c[0],l=c[1],p=c[2],f=c[3],E=c[4],d=c[5];r.push.apply(r,$(u,l,p,f,E,d,a,t)),a=[E,d];break;case"Z":r.push.apply(r,j(a[0],a[1],n[0],n[1],t)),a=[n[0],n[1]]}}return{type:"path",ops:r}}function W(e,t){for(var r=[],n=0,a=e;n<a.length;n++){var o=a[n];if(o.length){var s=t.maxRandomnessOffset||0,i=o.length;if(i>2){r.push({op:"move",data:[o[0][0]+Z(s,t),o[0][1]+Z(s,t)]});for(var h=1;h<i;h++)r.push({op:"lineTo",data:[o[h][0]+Z(s,t),o[h][1]+Z(s,t)]})}}}return{type:"fillPath",ops:r}}function z(e,t){return function(e,t){var r=e.fillStyle||"hachure";if(!M[r])switch(r){case"zigzag":M[r]||(M[r]=new d(t));break;case"cross-hatch":M[r]||(M[r]=new _(t));break;case"dots":M[r]||(M[r]=new R(t));break;case"dashed":M[r]||(M[r]=new y(t));break;case"zigzag-line":M[r]||(M[r]=new g(t));break;default:M[r="hachure"]||(M[r]=new f(t))}return M[r]}(t,D).fillPolygons(e,t)}function V(e){var t=n({},e);return t.randomizer=void 0,e.seed&&(t.seed=e.seed+1),t}function K(e){return e.randomizer||(e.randomizer=new m(e.seed||0)),e.randomizer.next()}function Y(e,t,r,n){return void 0===n&&(n=1),r.roughness*n*(K(r)*(t-e)+e)}function Z(e,t,r){return void 0===r&&(r=1),Y(-e,e,t,r)}function j(e,t,r,n,a,o){void 0===o&&(o=!1);var s=o?a.disableMultiStrokeFill:a.disableMultiStroke,i=B(e,t,r,n,a,!0,!1);if(s)return i;var h=B(e,t,r,n,a,!0,!0);return i.concat(h)}function B(e,t,r,n,a,o,s){var i=Math.pow(e-r,2)+Math.pow(t-n,2),h=Math.sqrt(i),c=1;c=h<l.RENDERING.LINE_LENGTH_THRESHOLD_SHORT?1:h>l.RENDERING.LINE_LENGTH_THRESHOLD_LONG?l.RENDERING.ROUGHNESS_GAIN_LONG_LINES:l.RENDERING.ROUGHNESS_GAIN_COEFFICIENT*h+l.RENDERING.ROUGHNESS_GAIN_CONSTANT;var u=a.maxRandomnessOffset||0;u*u*l.RENDERING.OFFSET_SQUARED_MULTIPLIER>i&&(u=h/l.RENDERING.OFFSET_DIVISOR_LONG_LINES);var p=u/2,f=l.RENDERING.DIVERGE_POINT_BASE+K(a)*l.RENDERING.DIVERGE_POINT_RANGE,E=a.bowing*a.maxRandomnessOffset*(n-t)/l.RENDERING.BOWING_DISPLACEMENT_DIVISOR,d=a.bowing*a.maxRandomnessOffset*(e-r)/l.RENDERING.BOWING_DISPLACEMENT_DIVISOR;E=Z(E,a,c),d=Z(d,a,c);var _=[],R=function(){return Z(p,a,c)},y=function(){return Z(u,a,c)},g=a.preserveVertices;return o&&(s?_.push({op:"move",data:[e+(g?0:R()),t+(g?0:R())]}):_.push({op:"move",data:[e+(g?0:Z(u,a,c)),t+(g?0:Z(u,a,c))]})),s?_.push({op:"bcurveTo",data:[E+e+(r-e)*f+R(),d+t+(n-t)*f+R(),E+e+2*(r-e)*f+R(),d+t+2*(n-t)*f+R(),r+(g?0:R()),n+(g?0:R())]}):_.push({op:"bcurveTo",data:[E+e+(r-e)*f+y(),d+t+(n-t)*f+y(),E+e+2*(r-e)*f+y(),d+t+2*(n-t)*f+y(),r+(g?0:y()),n+(g?0:y())]}),_}function q(e,t,r){if(!e.length)return[];var n=[];n.push([e[0][0]+Z(t,r),e[0][1]+Z(t,r)]),n.push([e[0][0]+Z(t,r),e[0][1]+Z(t,r)]);for(var a=1;a<e.length;a++)n.push([e[a][0]+Z(t,r),e[a][1]+Z(t,r)]),a===e.length-1&&n.push([e[a][0]+Z(t,r),e[a][1]+Z(t,r)]);return J(n,null,r)}function J(e,t,r){var n=e.length,a=[];if(n>3){var o=[],s=1-r.curveTightness;a.push({op:"move",data:[e[1][0],e[1][1]]});for(var i=1;i+2<n;i++){var h=e[i];o[0]=[h[0],h[1]],o[1]=[h[0]+(s*e[i+1][0]-s*e[i-1][0])/6,h[1]+(s*e[i+1][1]-s*e[i-1][1])/6],o[2]=[e[i+1][0]+(s*e[i][0]-s*e[i+2][0])/6,e[i+1][1]+(s*e[i][1]-s*e[i+2][1])/6],o[3]=[e[i+1][0],e[i+1][1]],a.push({op:"bcurveTo",data:[o[1][0],o[1][1],o[2][0],o[2][1],o[3][0],o[3][1]]})}if(t&&2===t.length){var c=r.maxRandomnessOffset;a.push({op:"lineTo",data:[t[0]+Z(c,r),t[1]+Z(c,r)]})}}else 3===n?(a.push({op:"move",data:[e[1][0],e[1][1]]}),a.push({op:"bcurveTo",data:[e[1][0],e[1][1],e[2][0],e[2][1],e[2][0],e[2][1]]})):2===n&&a.push.apply(a,B(e[0][0],e[0][1],e[1][0],e[1][1],r,!0,!0));return a}function Q(e,t,r,n,a,o,s,i){var h=[],c=[];if(0===i.roughness){e/=4,c.push([t+n*Math.cos(-e),r+a*Math.sin(-e)]);for(var u=0;u<=2*Math.PI;u+=e){var l=[t+n*Math.cos(u),r+a*Math.sin(u)];h.push(l),c.push(l)}c.push([t+n*Math.cos(0),r+a*Math.sin(0)]),c.push([t+n*Math.cos(e),r+a*Math.sin(e)])}else{var p=Z(.5,i)-Math.PI/2;c.push([Z(o,i)+t+.9*n*Math.cos(p-e),Z(o,i)+r+.9*a*Math.sin(p-e)]);var f=2*Math.PI+p-.01;for(u=p;u<f;u+=e){l=[Z(o,i)+t+n*Math.cos(u),Z(o,i)+r+a*Math.sin(u)];h.push(l),c.push(l)}c.push([Z(o,i)+t+n*Math.cos(p+2*Math.PI+.5*s),Z(o,i)+r+a*Math.sin(p+2*Math.PI+.5*s)]),c.push([Z(o,i)+t+.98*n*Math.cos(p+s),Z(o,i)+r+.98*a*Math.sin(p+s)]),c.push([Z(o,i)+t+.9*n*Math.cos(p+.5*s),Z(o,i)+r+.9*a*Math.sin(p+.5*s)])}return[c,h]}function X(e,t,r,n,a,o,s,i,h){var c=o+Z(.1,h),u=[];u.push([Z(i,h)+t+.9*n*Math.cos(c-e),Z(i,h)+r+.9*a*Math.sin(c-e)]);for(var l=c;l<=s;l+=e)u.push([Z(i,h)+t+n*Math.cos(l),Z(i,h)+r+a*Math.sin(l)]);return u.push([t+n*Math.cos(s),r+a*Math.sin(s)]),u.push([t+n*Math.cos(s),r+a*Math.sin(s)]),J(u,null,h)}function $(e,t,r,n,a,o,s,i){for(var h=[],c=[i.maxRandomnessOffset||1,(i.maxRandomnessOffset||1)+.3],u=[0,0],l=i.disableMultiStroke?1:2,p=i.preserveVertices,f=0;f<l;f++)0===f?h.push({op:"move",data:[s[0],s[1]]}):h.push({op:"move",data:[s[0]+(p?0:Z(c[0],i)),s[1]+(p?0:Z(c[0],i))]}),u=p?[a,o]:[a+Z(c[f],i),o+Z(c[f],i)],h.push({op:"bcurveTo",data:[e+Z(c[f],i),t+Z(c[f],i),r+Z(c[f],i),n+Z(c[f],i),u[0],u[1]]});return h}function ee(e){return[...e]}function te(e,t=0){const r=e.length;if(r<3)throw new Error("A curve must have at least three points.");const n=[];if(3===r)n.push(ee(e[0]),ee(e[1]),ee(e[2]),ee(e[2]));else{const r=[];r.push(e[0],e[0]);for(let t=1;t<e.length;t++)r.push(e[t]),t===e.length-1&&r.push(e[t]);const a=[],o=1-t;n.push(ee(r[0]));for(let e=1;e+2<r.length;e++){const t=r[e];a[0]=[t[0],t[1]],a[1]=[t[0]+(o*r[e+1][0]-o*r[e-1][0])/6,t[1]+(o*r[e+1][1]-o*r[e-1][1])/6],a[2]=[r[e+1][0]+(o*r[e][0]-o*r[e+2][0])/6,r[e+1][1]+(o*r[e][1]-o*r[e+2][1])/6],a[3]=[r[e+1][0],r[e+1][1]],n.push(a[1],a[2],a[3])}}return n}function re(e,t){return Math.pow(e[0]-t[0],2)+Math.pow(e[1]-t[1],2)}function ne(e,t,r){const n=re(t,r);if(0===n)return re(e,t);let a=((e[0]-t[0])*(r[0]-t[0])+(e[1]-t[1])*(r[1]-t[1]))/n;return a=Math.max(0,Math.min(1,a)),re(e,ae(t,r,a))}function ae(e,t,r){return[e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r]}function oe(e,t,r,n){const a=n||[];if(function(e,t){const r=e[t+0],n=e[t+1],a=e[t+2],o=e[t+3];let s=3*n[0]-2*r[0]-o[0];s*=s;let i=3*n[1]-2*r[1]-o[1];i*=i;let h=3*a[0]-2*o[0]-r[0];h*=h;let c=3*a[1]-2*o[1]-r[1];return c*=c,s<h&&(s=h),i<c&&(i=c),s+i}(e,t)<r){const r=e[t+0];if(a.length){(o=a[a.length-1],s=r,Math.sqrt(re(o,s)))>1&&a.push(r)}else a.push(r);a.push(e[t+3])}else{const n=.5,o=e[t+0],s=e[t+1],i=e[t+2],h=e[t+3],c=ae(o,s,n),u=ae(s,i,n),l=ae(i,h,n),p=ae(c,u,n),f=ae(u,l,n),E=ae(p,f,n);oe([o,c,p,E],0,r,a),oe([E,f,l,h],0,r,a)}var o,s;return a}function se(e,t){return ie(e,0,e.length,t)}function ie(e,t,r,n,a){const o=a||[],s=e[t],i=e[r-1];let h=0,c=1;for(let n=t+1;n<r-1;++n){const t=ne(e[n],s,i);t>h&&(h=t,c=n)}return Math.sqrt(h)>n?(ie(e,t,c+1,n,o),ie(e,c,r,n,o)):(o.length||o.push(s),o.push(i)),o}function he(e,t=.15,r){const n=[],a=(e.length-1)/3;for(let r=0;r<a;r++){oe(e,3*r,t,n)}return r&&r>0?ie(n,0,n.length,r):n}var ce="none",ue=function(){function e(e){this.defaultOptions={maxRandomnessOffset:l.DRAWING.DEFAULT_MAX_RANDOMNESS_OFFSET,roughness:l.DRAWING.DEFAULT_ROUGHNESS,bowing:l.DRAWING.DEFAULT_BOWING,stroke:"#000",strokeWidth:l.DRAWING.DEFAULT_STROKE_WIDTH,curveTightness:l.DRAWING.DEFAULT_CURVE_TIGHTNESS,curveFitting:l.DRAWING.DEFAULT_CURVE_FITTING,curveStepCount:l.DRAWING.DEFAULT_CURVE_STEP_COUNT,fillStyle:"hachure",fillWeight:l.DRAWING.DEFAULT_FILL_WEIGHT,hachureAngle:l.DRAWING.DEFAULT_HACHURE_ANGLE,hachureGap:l.DRAWING.DEFAULT_HACHURE_GAP,dashOffset:l.DRAWING.DEFAULT_DASH_OFFSET,dashGap:l.DRAWING.DEFAULT_DASH_GAP,zigzagOffset:l.DRAWING.DEFAULT_ZIGZAG_OFFSET,seed:l.DRAWING.DEFAULT_SEED,disableMultiStroke:l.DRAWING.DEFAULT_DISABLE_MULTI_STROKE,disableMultiStrokeFill:l.DRAWING.DEFAULT_DISABLE_MULTI_STROKE_FILL,preserveVertices:l.DRAWING.DEFAULT_PRESERVE_VERTICES,fillShapeRoughnessGain:l.DRAWING.DEFAULT_FILL_SHAPE_ROUGHNESS_GAIN},this.config=e||{},this.config.options&&(this.defaultOptions=this._o(this.config.options))}return e.newSeed=function(){return Math.floor(Math.random()*l.RANDOM.SEED_UPPER_BOUND)},e.prototype._o=function(e){return e?Object.assign({},this.defaultOptions,e):this.defaultOptions},e.prototype._d=function(e,t,r){return{shape:e,sets:t||[],options:r||this.defaultOptions}},e.prototype.line=function(e,t,r,n,a){var o=this._o(a);return this._d("line",[U(e,t,r,n,o)],o)},e.prototype.rectangle=function(e,t,r,n,a){var o=this._o(a),s=[],i=b(e,t,r,n,o);if(o.fill){var h=[[e,t],[e+r,t],[e+r,t+n],[e,t+n]];"solid"===o.fillStyle?s.push(W([h],o)):s.push(z([h],o))}return o.stroke!==ce&&s.push(i),this._d("rectangle",s,o)},e.prototype.ellipse=function(e,t,r,n,a){var o=this._o(a),s=[],i=H(r,n,o),h=F(e,t,o,i);if(o.fill)if("solid"===o.fillStyle){var c=F(e,t,o,i).opset;c.type="fillPath",s.push(c)}else s.push(z([h.estimatedPoints],o));return o.stroke!==ce&&s.push(h.opset),this._d("ellipse",s,o)},e.prototype.circle=function(e,t,r,n){var a=this.ellipse(e,t,r,r,n);return a.shape="circle",a},e.prototype.linearPath=function(e,t){var r=this._o(t);return this._d("linearPath",[G(e,!1,r)],r)},e.prototype.arc=function(e,t,r,a,o,s,i,h){void 0===i&&(i=!1);var c=this._o(h),u=[],p=w(e,t,r,a,o,s,i,!0,c);if(i&&c.fill)if("solid"===c.fillStyle){var f=n({},c);f.disableMultiStroke=!0;var E=w(e,t,r,a,o,s,!0,!1,f);E.type="fillPath",u.push(E)}else u.push(function(e,t,r,n,a,o,s){var i=e,h=t,c=Math.abs(r/2),u=Math.abs(n/2);c+=Z(c*l.RENDERING.ARC_RADIUS_OFFSET_FACTOR,s),u+=Z(u*l.RENDERING.ARC_RADIUS_OFFSET_FACTOR,s);for(var p=a,f=o;p<0;)p+=2*Math.PI,f+=2*Math.PI;f-p>2*Math.PI&&(p=0,f=2*Math.PI);for(var E=(f-p)/s.curveStepCount,d=[],_=p;_<=f;_+=E)d.push([i+c*Math.cos(_),h+u*Math.sin(_)]);return d.push([i+c*Math.cos(f),h+u*Math.sin(f)]),d.push([i,h]),z([d],s)}(e,t,r,a,o,s,c));return c.stroke!==ce&&u.push(p),this._d("arc",u,c)},e.prototype.curve=function(e,t){var r=this._o(t),a=[],o=k(e,r);if(r.fill&&r.fill!==ce)if("solid"===r.fillStyle){var s=k(e,n(n({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));a.push({type:"fillPath",ops:this._mergedShape(s.ops)})}else{var i=[],h=e;if(h.length)for(var c=0,u="number"==typeof h[0][0]?[h]:h;c<u.length;c++){var p=u[c];p.length<3?i.push.apply(i,p):3===p.length?i.push.apply(i,he(te([p[0],p[0],p[1],p[2]]),l.DRAWING.BEZIER_CURVE_POINTS,(1+r.roughness)/2)):i.push.apply(i,he(te(p),l.DRAWING.BEZIER_CURVE_POINTS,(1+r.roughness)/2))}i.length&&a.push(z([i],r))}return r.stroke!==ce&&a.push(o),this._d("curve",a,r)},e.prototype.polygon=function(e,t){var r=this._o(t),n=[],a=G(e,!0,r);return r.fill&&("solid"===r.fillStyle?n.push(W([e],r)):n.push(z([e],r))),r.stroke!==ce&&n.push(a),this._d("polygon",n,r)},e.prototype.path=function(e,t){var r=this._o(t),a=[];if(!e)return this._d("path",a,r);e=(e||"").replace(/\n/g," ").replace(/(-\s)/g,"-").replace("/(ss)/g"," ");var o=r.fill&&"transparent"!==r.fill&&r.fill!==ce,s=r.stroke!==ce,i=!!(r.simplification&&r.simplification<1),h=function(e,t,r){const n=N(L(O(e))),a=[];let o=[],s=[0,0],i=[];const h=()=>{i.length>=4&&o.push(...he(i,t)),i=[]},c=()=>{h(),o.length&&(a.push(o),o=[])};for(const{key:e,data:t}of n)switch(e){case"M":c(),s=[t[0],t[1]],o.push(s);break;case"L":h(),o.push([t[0],t[1]]);break;case"C":if(!i.length){const e=o.length?o[o.length-1]:s;i.push([e[0],e[1]])}i.push([t[0],t[1]]),i.push([t[2],t[3]]),i.push([t[4],t[5]]);break;case"Z":h(),o.push([s[0],s[1]])}if(c(),!r)return a;const u=[];for(const e of a){const t=se(e,r);t.length&&u.push(t)}return u}(e,1,i?4-4*(r.simplification||1):(1+r.roughness)/2),c=x(e,r);if(o)if("solid"===r.fillStyle)if(1===h.length){var u=x(e,n(n({},r),{disableMultiStroke:!0,roughness:r.roughness?r.roughness+r.fillShapeRoughnessGain:0}));a.push({type:"fillPath",ops:this._mergedShape(u.ops)})}else a.push(W(h,r));else a.push(z(h,r));return s&&(i?h.forEach((function(e){a.push(G(e,!1,r))})):a.push(c)),this._d("path",a,r)},e.prototype.opsToPath=function(e,t){for(var r="",n=0,a=e.ops;n<a.length;n++){var o=a[n],s="number"==typeof t&&t>=0?o.data.map((function(e){return+e.toFixed(t)})):o.data;switch(o.op){case"move":r+="M".concat(s[0]," ").concat(s[1]," ");break;case"bcurveTo":r+="C".concat(s[0]," ").concat(s[1],", ").concat(s[2]," ").concat(s[3],", ").concat(s[4]," ").concat(s[5]," ");break;case"lineTo":r+="L".concat(s[0]," ").concat(s[1]," ")}}return r.trim()},e.prototype.toPaths=function(e){for(var t=e.sets||[],r=e.options||this.defaultOptions,n=[],a=0,o=t;a<o.length;a++){var s=o[a],i=null;switch(s.type){case"path":i={d:this.opsToPath(s),stroke:r.stroke,strokeWidth:r.strokeWidth,fill:ce};break;case"fillPath":i={d:this.opsToPath(s),stroke:ce,strokeWidth:0,fill:r.fill||ce};break;case"fillSketch":i=this.fillSketch(s,r)}i&&n.push(i)}return n},e.prototype.fillSketch=function(e,t){var r=t.fillWeight;return r<0&&(r=t.strokeWidth/2),{d:this.opsToPath(e),stroke:t.fill||ce,strokeWidth:r,fill:ce}},e.prototype._mergedShape=function(e){return e.filter((function(e,t){return 0===t||"move"!==e.op}))},e}(),le=function(){function e(e){this.gen=new ue(e),this.instanceId=Math.random().toString(36).substring(2,15),this.registerInstance()}return e.prototype.registerInstance=function(){var t=this;e.instanceCount++,"undefined"==typeof FinalizationRegistry||e.finalizationRegistry||(e.finalizationRegistry=new FinalizationRegistry((function(e){t.handleInstanceFinalization(e)}))),e.finalizationRegistry&&e.finalizationRegistry.register(this,this.instanceId),1===e.instanceCount&&this.startCleanupTimer()},e.prototype.handleInstanceFinalization=function(t){e.instanceCount=Math.max(0,e.instanceCount-1),0===e.instanceCount&&e.cleanupTimer&&(clearInterval(e.cleanupTimer),e.cleanupTimer=null,e.errorCache.clear())},e.prototype.startCleanupTimer=function(){var t=this;e.cleanupTimer&&clearInterval(e.cleanupTimer),e.cleanupTimer=setInterval((function(){t.cleanupErrorCache()}),e.cacheCleanupInterval)},e.prototype.dispose=function(){e.finalizationRegistry&&e.finalizationRegistry.unregister(this),this.handleInstanceFinalization(this.instanceId)},e.forceCleanup=function(){e.cleanupTimer&&(clearInterval(e.cleanupTimer),e.cleanupTimer=null),e.errorCache.clear(),e.instanceCount=0},e.prototype.cleanupErrorCache=function(){for(var t=Date.now()-l.ERROR.MS_PER_MINUTE,r=0,n=Array.from(e.errorCache.entries());r<n.length;r++){var a=n[r],o=a[0];a[1].lastSeen<t&&e.errorCache.delete(o)}if(e.errorCache.size>e.maxErrorCacheSize){var s=Array.from(e.errorCache.entries()).sort((function(e,t){return e[1].lastSeen-t[1].lastSeen}));s.slice(0,s.length-e.maxErrorCacheSize).forEach((function(t){var r=t[0];return e.errorCache.delete(r)}))}},e.prototype.logError=function(t){if(this.shouldLog()){var r="".concat(t.method,":").concat(t.error||"unknown"),a=Date.now(),o=e.errorCache.get(r);if(o){o.count++,o.lastSeen=a;var s=a-o.context.timestamp;if(o.count/Math.max(1,s/l.ERROR.MS_PER_MINUTE)>e.errorRateLimit)return}else e.errorCache.set(r,{count:1,lastSeen:a,context:n(n({},t),{timestamp:a})});var i={method:t.method,error:t.error,timestamp:new Date(a).toISOString()};t.parameters&&(i.parameters=this.sanitizeParameters(t.parameters)),o&&o.count>1&&(i.occurrences=o.count),console.warn("rough-native: ".concat(t.method," failed"),i)}},e.prototype.sanitizeParameters=function(e){if(Array.isArray(e))return{type:"array",length:e.length,sample:e.slice(0,l.ERROR.SAMPLE_SIZE_FOR_ARRAY_PARAMS)};if("object"==typeof e&&null!==e){for(var t={},r=0,n=Object.entries(e);r<n.length;r++){var a=n[r],o=a[0],s=a[1];Array.isArray(s)?t[o]={type:"array",length:s.length}:t[o]="object"==typeof s&&null!==s?{type:"object",keys:Object.keys(s)}:s}return t}return e},e.prototype.shouldLog=function(){return"undefined"==typeof process||"production"!==process.env.NODE_ENV},e.prototype.draw=function(e){var t;try{if(!e)return this.logError({method:"draw",error:"drawable is null or undefined"}),this.createEmptyElement();for(var r=e.sets||[],a=e.options||this.getDefaultOptions(),o=[],s=null===(t=e.options)||void 0===t?void 0:t.fixedDecimalPlaceDigits,i=0,h=r;i<h.length;i++){var c=h[i];if(c){var u=null;try{switch(c.type){case"path":if(!(l=this.safeOpsToPath(c,s))){this.logError({method:"draw",error:"failed to generate path data",parameters:{drawingType:"path",drawing:c}});continue}u={props:n(n({d:l,stroke:a.stroke,strokeWidth:a.strokeWidth,fill:"none"},a.strokeLineDash&&{strokeDasharray:a.strokeLineDash.join(" ").trim()}),a.strokeLineDashOffset&&{strokeDashoffset:a.strokeLineDashOffset})};break;case"fillPath":var l;if(!(l=this.safeOpsToPath(c,s))){this.logError({method:"draw",error:"failed to generate fill path data",parameters:{drawingType:"fillPath",drawing:c}});continue}u={props:n({d:l,stroke:"none",strokeWidth:0,fill:a.fill||""},"curve"===e.shape||"polygon"===e.shape?{fillRule:"evenodd"}:{})};break;case"fillSketch":u=this.safeFillSketch(c,a);break;default:this.logError({method:"draw",error:"unknown drawing type: ".concat(c.type),parameters:{drawing:c}});continue}}catch(e){this.logError({method:"draw",error:"failed to process ".concat(c.type," drawing: ").concat(e),parameters:{drawingType:c.type,drawing:c}});continue}u&&this.validateElement(u)?o.push(u):u&&this.logError({method:"draw",error:"generated element failed validation",parameters:{element:u,drawingType:c.type}})}else this.logError({method:"draw",error:"null drawing in drawable.sets"})}return{props:{},children:o}}catch(t){return this.logError({method:"draw",error:"draw method failed: ".concat(t),parameters:{drawable:e}}),this.createEmptyElement()}},e.prototype.safeFillSketch=function(e,t){try{var r=this.safeOpsToPath(e,t.fixedDecimalPlaceDigits);if(!r)return null;var a=t.fillWeight;return a<0&&(a=t.strokeWidth/2),{props:n(n({d:r,stroke:t.fill||"",strokeWidth:a,fill:"none"},t.fillLineDash&&{strokeDasharray:t.fillLineDash.join(" ").trim()}),t.fillLineDashOffset&&{strokeDashoffset:t.fillLineDashOffset})}}catch(r){return this.logError({method:"safeFillSketch",error:"fillSketch generation failed: ".concat(r),parameters:{drawing:e,options:t}}),null}},e.prototype.safeOpsToPath=function(e,t){try{return e&&e.ops&&Array.isArray(e.ops)?this.opsToPath(e,t):null}catch(r){return this.logError({method:"safeOpsToPath",error:"opsToPath conversion failed: ".concat(r),parameters:{drawing:e,fixedDecimalPlaceDigits:t}}),null}},e.prototype.validateElement=function(e){return e&&"object"==typeof e&&e.props&&"object"==typeof e.props},e.prototype.createEmptyElement=function(){return{props:{},children:[]}},e.prototype.validateCoordinates=function(e){return e.every((function(e){return"number"==typeof e&&!isNaN(e)&&isFinite(e)}))},e.prototype.validateDimensions=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e.every((function(e){return"number"==typeof e&&!isNaN(e)&&isFinite(e)&&e>=0}))},e.prototype.validatePoints=function(e){var t=this;return Array.isArray(e)&&e.length>0&&e.every((function(e){return Array.isArray(e)&&e.length>=l.VALIDATION.MIN_POINT_ARRAY_LENGTH&&t.validateCoordinates([e[0],e[1]])}))},e.prototype.validateAngles=function(e,t){return this.validateCoordinates([e,t])},e.prototype.validateCurvePoints=function(e){var t,r=this;return!(!Array.isArray(e)||0===e.length)&&("number"==typeof(null===(t=e[0])||void 0===t?void 0:t[0])?this.validatePoints(e):e.every((function(e){return r.validatePoints(e)})))},Object.defineProperty(e.prototype,"generator",{get:function(){return this.gen},enumerable:!1,configurable:!0}),e.prototype.getDefaultOptions=function(){return this.gen.defaultOptions},e.prototype.opsToPath=function(e,t){return this.gen.opsToPath(e,t)},e.prototype.line=function(e,t,r,n,a){try{if(!this.validateCoordinates([e,t,r,n]))return this.logError({method:"line",error:"invalid coordinates",parameters:{x1:e,y1:t,x2:r,y2:n,options:a}}),this.createEmptyElement();var o=this.gen.line(e,t,r,n,a);return this.draw(o)}catch(o){return this.logError({method:"line",error:"generation failed: ".concat(o),parameters:{x1:e,y1:t,x2:r,y2:n,options:a}}),this.createEmptyElement()}},e.prototype.rectangle=function(e,t,r,n,a){try{if(!this.validateCoordinates([e,t])||!this.validateDimensions(r,n))return this.logError({method:"rectangle",error:"invalid parameters",parameters:{x:e,y:t,width:r,height:n,options:a}}),this.createEmptyElement();var o=this.gen.rectangle(e,t,r,n,a);return this.draw(o)}catch(o){return this.logError({method:"rectangle",error:"generation failed: ".concat(o),parameters:{x:e,y:t,width:r,height:n,options:a}}),this.createEmptyElement()}},e.prototype.ellipse=function(e,t,r,n,a){try{if(!this.validateCoordinates([e,t])||!this.validateDimensions(r,n))return this.logError({method:"ellipse",error:"invalid parameters",parameters:{x:e,y:t,width:r,height:n,options:a}}),this.createEmptyElement();var o=this.gen.ellipse(e,t,r,n,a);return this.draw(o)}catch(o){return this.logError({method:"ellipse",error:"generation failed: ".concat(o),parameters:{x:e,y:t,width:r,height:n,options:a}}),this.createEmptyElement()}},e.prototype.circle=function(e,t,r,n){try{if(!this.validateCoordinates([e,t])||!this.validateDimensions(r))return this.logError({method:"circle",error:"invalid parameters",parameters:{x:e,y:t,diameter:r,options:n}}),this.createEmptyElement();var a=this.gen.circle(e,t,r,n);return this.draw(a)}catch(a){return this.logError({method:"circle",error:"generation failed: ".concat(a),parameters:{x:e,y:t,diameter:r,options:n}}),this.createEmptyElement()}},e.prototype.linearPath=function(e,t){try{if(!this.validatePoints(e))return this.logError({method:"linearPath",error:"invalid points",parameters:{points:e,options:t}}),this.createEmptyElement();var r=this.gen.linearPath(e,t);return this.draw(r)}catch(r){return this.logError({method:"linearPath",error:"generation failed: ".concat(r),parameters:{points:e,options:t}}),this.createEmptyElement()}},e.prototype.polygon=function(e,t){try{if(!this.validatePoints(e)||e.length<l.VALIDATION.MIN_POLYGON_POINTS)return this.logError({method:"polygon",error:"invalid points (need at least 3 points)",parameters:{points:e,options:t}}),this.createEmptyElement();var r=this.gen.polygon(e,t);return this.draw(r)}catch(r){return this.logError({method:"polygon",error:"generation failed: ".concat(r),parameters:{points:e,options:t}}),this.createEmptyElement()}},e.prototype.arc=function(e,t,r,n,a,o,s,i){void 0===s&&(s=!1);try{if(!this.validateCoordinates([e,t])||!this.validateDimensions(r,n)||!this.validateAngles(a,o))return this.logError({method:"arc",error:"invalid parameters",parameters:{x:e,y:t,width:r,height:n,start:a,stop:o,closed:s,options:i}}),this.createEmptyElement();var h=this.gen.arc(e,t,r,n,a,o,s,i);return this.draw(h)}catch(h){return this.logError({method:"arc",error:"generation failed: ".concat(h),parameters:{x:e,y:t,width:r,height:n,start:a,stop:o,closed:s,options:i}}),this.createEmptyElement()}},e.prototype.curve=function(e,t){try{if(!this.validateCurvePoints(e))return this.logError({method:"curve",error:"invalid points",parameters:{points:e,options:t}}),this.createEmptyElement();var r=this.gen.curve(e,t);return this.draw(r)}catch(r){return this.logError({method:"curve",error:"generation failed: ".concat(r),parameters:{points:e,options:t}}),this.createEmptyElement()}},e.prototype.path=function(e,t){try{if(!e||"string"!=typeof e||e.trim().length===l.VALIDATION.MIN_PATH_STRING_LENGTH)return this.logError({method:"path",error:"invalid path data",parameters:{d:e,options:t}}),this.createEmptyElement();var r=this.gen.path(e,t);return this.draw(r)}catch(r){return this.logError({method:"path",error:"generation failed: ".concat(r),parameters:{d:e,options:t}}),this.createEmptyElement()}},e.errorCache=new Map,e.maxErrorCacheSize=l.ERROR.MAX_ERROR_CACHE_SIZE,e.errorRateLimit=l.ERROR.ERROR_RATE_LIMIT_PER_MINUTE,e.cacheCleanupInterval=l.ERROR.ERROR_CACHE_CLEANUP_INTERVAL_MS,e.cleanupTimer=null,e.instanceCount=0,e.finalizationRegistry=null,e}(),pe=new(function(){function e(){this.instances=new Map,this.listeners=new Set,this.nextId=0}return e.prototype.createInstance=function(e){var t="".concat(l.REACT_HOOK.ID_PREFIX).concat(this.nextId++),r=new le(e);return this.instances.set(t,r),this.notifyListeners(),t},e.prototype.getInstance=function(e){return this.instances.get(e)},e.prototype.updateInstance=function(e,t){var r=this.instances.get(e);r&&r.dispose();var n=new le(t);this.instances.set(e,n),this.notifyListeners()},e.prototype.deleteInstance=function(e){var t=this.instances.get(e);t&&(t.dispose(),this.instances.delete(e),this.notifyListeners())},e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.getSnapshot=function(){return new Map(this.instances)},e.prototype.notifyListeners=function(){this.listeners.forEach((function(e){return e()}))},e.prototype.clear=function(){this.instances.forEach((function(e){return e.dispose()})),this.instances.clear(),this.notifyListeners()},e}()),fe=new(function(){function e(){this.cache=new Map,this.listeners=new Set,this.pendingGenerations=new Set,this.memoryMonitor=Ee.getInstance()}return Object.defineProperty(e.prototype,"maxCacheSize",{get:function(){return this.memoryMonitor.getRecommendedCacheSize()*l.MEMORY.SHAPE_CACHE_MULTIPLIER},enumerable:!1,configurable:!0}),e.prototype.generateShape=function(e,t){if(this.cache.has(e))return this.cache.get(e);if(this.memoryMonitor.shouldAgressivelyCleanup()&&this.pendingGenerations.size>2)return null;if(this.pendingGenerations.has(e))return null;this.cache.size>=this.maxCacheSize&&this.performMemoryPressureCleanup(),this.pendingGenerations.add(e);try{var r=t();return this.cache.set(e,r),this.pendingGenerations.delete(e),this.notifyListeners(),r}catch(t){if(this.pendingGenerations.delete(e),!this.memoryMonitor.shouldAgressivelyCleanup()){var n={props:{},children:[],error:String(t)};this.cache.set(e,n)}return this.notifyListeners(),{props:{},children:[],error:String(t)}}},e.prototype.performMemoryPressureCleanup=function(){var e=this,t=this.memoryMonitor.getMemoryPressureLevel();if("high"===t){var r=Array.from(this.cache.entries()),n=Math.floor(r.length*l.MEMORY.HIGH_PRESSURE_KEEP_PERCENT),a=r.slice(-n);this.cache.clear(),a.forEach((function(t){var r=t[0],n=t[1];return e.cache.set(r,n)}))}else if("medium"===t){r=Array.from(this.cache.entries()),n=Math.floor(r.length*l.MEMORY.MEDIUM_PRESSURE_KEEP_PERCENT),a=r.slice(-n);this.cache.clear(),a.forEach((function(t){var r=t[0],n=t[1];return e.cache.set(r,n)}))}},e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.getSnapshot=function(){return new Map(this.cache)},e.prototype.notifyListeners=function(){this.listeners.forEach((function(e){return e()}))},e.prototype.clearCache=function(){this.cache.clear(),this.pendingGenerations.clear(),this.notifyListeners()},e}()),Ee=function(){function e(){this.memoryPressureLevel="low",this.lastMemoryCheck=0,this.checkInterval=l.MEMORY.MEMORY_CHECK_INTERVAL_MS}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.getMemoryPressureLevel=function(){var e=Date.now();return e-this.lastMemoryCheck>this.checkInterval&&(this.checkMemoryPressure(),this.lastMemoryCheck=e),this.memoryPressureLevel},e.prototype.checkMemoryPressure=function(){try{var e,t;if("undefined"!=typeof global&&global.performance&&global.performance.memory)return void((t=(e=global.performance.memory).usedJSHeapSize/e.jsHeapSizeLimit)>l.MEMORY.HIGH_MEMORY_PRESSURE_THRESHOLD?this.memoryPressureLevel="high":t>l.MEMORY.MEDIUM_MEMORY_PRESSURE_THRESHOLD?this.memoryPressureLevel="medium":this.memoryPressureLevel="low");if("undefined"!=typeof performance&&performance.memory)return void((t=(e=performance.memory).usedJSHeapSize/e.jsHeapSizeLimit)>l.MEMORY.HIGH_MEMORY_PRESSURE_THRESHOLD?this.memoryPressureLevel="high":t>l.MEMORY.MEDIUM_MEMORY_PRESSURE_THRESHOLD?this.memoryPressureLevel="medium":this.memoryPressureLevel="low");if("undefined"!=typeof global){var r="undefined"!=typeof navigator?navigator.userAgent:"",n=/Android.*4\.|Android.*[0-3]\./i.test(r);return void(this.memoryPressureLevel=n?"high":"medium")}this.memoryPressureLevel="medium"}catch(e){this.memoryPressureLevel="medium"}},e.prototype.getRecommendedCacheSize=function(){switch(this.memoryPressureLevel){case"high":return l.MEMORY.CACHE_SIZE_HIGH_PRESSURE;case"medium":return l.MEMORY.CACHE_SIZE_MEDIUM_PRESSURE;case"low":return l.MEMORY.CACHE_SIZE_LOW_PRESSURE;default:return l.MEMORY.CACHE_SIZE_DEFAULT}},e.prototype.shouldAgressivelyCleanup=function(){return"high"===this.memoryPressureLevel},e}(),de=new(function(){function e(){this.cache=new WeakMap,this.cacheCount=0,this.cacheHits=0,this.cacheMisses=0,this.memoryMonitor=Ee.getInstance()}return Object.defineProperty(e.prototype,"maxCacheSize",{get:function(){return this.memoryMonitor.getRecommendedCacheSize()},enumerable:!1,configurable:!0}),e.prototype.get=function(e,t){if("object"==typeof e&&"object"==typeof t&&null!==e&&null!==t){var r=this.cache.get(e);if(r){var n=r.get(t);if(void 0!==n)return this.cacheHits++,n}this.cacheMisses++}},e.prototype.set=function(e,t,r){if("object"==typeof e&&"object"==typeof t&&null!==e&&null!==t){var n=this.maxCacheSize;if(this.cacheCount++,this.cacheCount>n&&(this.cache=new WeakMap,this.cacheCount=0,this.memoryMonitor.shouldAgressivelyCleanup()&&"undefined"!=typeof global&&global.gc))try{global.gc()}catch(e){}var a=this.cache.get(e);if(a||(a=new WeakMap,this.cache.set(e,a)),a.set(t,r),!this.memoryMonitor.shouldAgressivelyCleanup()){var o=this.cache.get(t);o||(o=new WeakMap,this.cache.set(t,o)),o.set(e,r)}}},e.prototype.getStats=function(){return{hits:this.cacheHits,misses:this.cacheMisses,hitRate:this.cacheHits/(this.cacheHits+this.cacheMisses),memoryPressure:this.memoryMonitor.getMemoryPressureLevel(),maxCacheSize:this.maxCacheSize,currentCacheCount:this.cacheCount}},e}());function _e(e,t,r){if(void 0===r&&(r=0),e===t)return!0;if(r>l.REACT_HOOK.MAX_RECURSION_DEPTH)return!1;var n=typeof e;if(n!==typeof t)return!1;if(null===e||null===t||void 0===e||void 0===t)return e===t;if("object"!==n)return e===t;var a,o=de.get(e,t);if(void 0!==o)return o;if(e instanceof Date&&t instanceof Date)a=e.getTime()===t.getTime();else if(Array.isArray(e))if(Array.isArray(t)&&e.length===t.length){a=!0;for(var s=0;s<e.length;s++)if(!_e(e[s],t[s],r+1)){a=!1;break}}else a=!1;else if(Array.isArray(t))a=!1;else{var i=Object.keys(e),h=Object.keys(t);if(i.length!==h.length)a=!1;else{a=!0;for(var c=i.length>l.REACT_HOOK.KEY_LOOKUP_SET_THRESHOLD?new Set(h):h,u=0,p=i;u<p.length;u++){var f=p[u];if(!(Array.isArray(c)?c.includes(f):c.has(f))||!_e(e[f],t[f],r+1)){a=!1;break}}}}return de.set(e,t,a),a}function Re(t,r){var n=e.useRef(t),a=e.useRef(t),o=e.useRef(r),s=e.useRef(!0);return e.useMemo((function(){if(s.current)return s.current=!1,!0;if(!r&&!o.current)return!_e(t,a.current);if(!r||!o.current||r.length!==o.current.length)return!0;for(var e=0;e<r.length;e++)if(!_e(r[e],o.current[e]))return!0;return!1}),r||[])&&(a.current=n.current,n.current=t,o.current=r),e.useEffect((function(){return function(){n.current=null,a.current=null,o.current=void 0}}),[]),n.current}var ye={getDeepEqualStats:function(){return de.getStats()},clearDeepEqualCache:function(){de.cache=new WeakMap},getRoughInstanceCount:function(){return pe.getSnapshot().size},getShapeCacheSize:function(){return fe.getSnapshot().size},clearRoughInstances:function(){return pe.clear()},clearShapeCache:function(){return fe.clearCache()},getMemoryPressure:function(){return Ee.getInstance().getMemoryPressureLevel()},getRecommendedCacheSize:function(){return Ee.getInstance().getRecommendedCacheSize()},forceMemoryCleanup:function(){if(Ee.getInstance().shouldAgressivelyCleanup()&&(fe.clearCache(),de.cache=new WeakMap,"undefined"!=typeof global&&global.gc))try{global.gc()}catch(e){}},clearAllCaches:function(){de.cache=new WeakMap,pe.clear(),fe.clearCache()}};function ge(t){var r=e.useRef(null),n=Re(t,[t]),a=e.useSyncExternalStore(pe.subscribe.bind(pe),pe.getSnapshot.bind(pe),pe.getSnapshot.bind(pe)),o=e.useMemo((function(){return r.current?pe.updateInstance(r.current,n):r.current=pe.createInstance(n),pe.getInstance(r.current)}),[n,a]);if(e.useEffect((function(){return function(){r.current&&(pe.deleteInstance(r.current),r.current=null)}}),[]),!o)throw new Error("Failed to create RoughReactNativeSVG instance");return o}var Me={reactNativeSvg:function(e){return new le(e)},generator:function(e){return new ue(e)},newSeed:function(){return ue.newSeed()}};exports.debugUtils=ye,exports.default=Me,exports.useDeepMemoWithDebug=function(t,r,n){var a=Re(t,r);return e.useEffect((function(){if("development"===process.env.NODE_ENV&&n)try{var e="undefined"!=typeof performance?performance.memory:void 0;e&&e.usedJSHeapSize&&console.debug("useDeepMemo[".concat(n,"]: ").concat((e.usedJSHeapSize