@gjsify/canvas2d-core 0.3.21 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var e=Object.defineProperty,__name=(t,n)=>e(t,`name`,{value:n,configurable:!0});export{__name};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function asCairoPattern(e){if(!e)return null;let t=e;return typeof t.setFilter!=`function`||typeof t.setExtend!=`function`?null:t}export{asCairoPattern};
@@ -1 +1 @@
1
- function quadraticToCubic(e,t,n,r,i,a){return{cp1x:e+2/3*(n-e),cp1y:t+2/3*(r-t),cp2x:i+2/3*(n-i),cp2y:a+2/3*(r-a)}}function computeArcTo(e,t,n,r,i,a,o){let s=e-n,c=t-r,l=i-n,u=a-r,d=Math.sqrt(s*s+c*c),f=Math.sqrt(l*l+u*u);if(d===0||f===0)return null;let p=s/d,m=c/d,h=l/f,g=u/f,_=p*g-m*h;if(Math.abs(_)<1e-10)return null;let v=p*h+m*g,y=Math.acos(Math.max(-1,Math.min(1,v)))/2,b=o/Math.tan(y),x=n+p*b,S=r+m*b,C=n+h*b,w=r+g*b,T=o/Math.sin(y),E=(p+h)/2,D=(m+g)/2,O=Math.sqrt(E*E+D*D),k=n+E/O*T,A=r+D/O*T;return{tx0:x,ty0:S,tx1:C,ty1:w,cx:k,cy:A,startAngle:Math.atan2(S-A,x-k),endAngle:Math.atan2(w-A,C-k),counterclockwise:_>0}}function cairoArcTo(e,t,n,r,i,a,o,s){let c=computeArcTo(t,n,r,i,a,o,s);if(!c){e.lineTo(r,i);return}let{tx0:l,ty0:u,cx:d,cy:f,startAngle:p,endAngle:m,counterclockwise:h}=c;e.lineTo(l,u),h?e.arcNegative(d,f,s,p,m):e.arc(d,f,s,p,m)}function cairoEllipse(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),c?e.arcNegative(0,0,1,o,s):e.arc(0,0,1,o,s),e.restore()}function cairoRoundRect(e,t,n,r,i,a){let o,s,c,l;typeof a==`number`?o=s=c=l=a:a.length===1?o=s=c=l=a[0]:a.length===2?(o=c=a[0],s=l=a[1]):a.length===3?(o=a[0],s=l=a[1],c=a[2]):(o=a[0],s=a[1],c=a[2],l=a[3]);let u=Math.min(r/2,i/2);o=Math.min(o,u),s=Math.min(s,u),c=Math.min(c,u),l=Math.min(l,u);let d=Math.PI/2;e.newSubPath(),e.arc(t+o,n+o,o,Math.PI,Math.PI+d),e.arc(t+r-s,n+s,s,-d,0),e.arc(t+r-c,n+i-c,c,0,d),e.arc(t+l,n+i-l,l,d,Math.PI),e.closePath()}const e={"source-over":2,"source-in":3,"source-out":4,"source-atop":5,"destination-over":7,"destination-in":8,"destination-out":9,"destination-atop":10,lighter:12,copy:1,xor:11,multiply:14,screen:15,overlay:16,darken:17,lighten:18,"color-dodge":19,"color-burn":20,"hard-light":21,"soft-light":22,difference:23,exclusion:24,hue:25,saturation:26,color:27,luminosity:28},t={butt:0,round:1,square:2},n={miter:0,round:1,bevel:2};export{e as COMPOSITE_OP_MAP,t as LINE_CAP_MAP,n as LINE_JOIN_MAP,cairoArcTo,cairoEllipse,cairoRoundRect,computeArcTo,quadraticToCubic};
1
+ import"./_virtual/_rolldown/runtime.js";function quadraticToCubic(e,t,n,r,i,a){return{cp1x:e+2/3*(n-e),cp1y:t+2/3*(r-t),cp2x:i+2/3*(n-i),cp2y:a+2/3*(r-a)}}function computeArcTo(e,t,n,r,i,a,o){let s=e-n,c=t-r,l=i-n,u=a-r,d=Math.sqrt(s*s+c*c),f=Math.sqrt(l*l+u*u);if(d===0||f===0)return null;let p=s/d,m=c/d,h=l/f,g=u/f,_=p*g-m*h;if(Math.abs(_)<1e-10)return null;let v=p*h+m*g,y=Math.acos(Math.max(-1,Math.min(1,v)))/2,b=o/Math.tan(y),x=n+p*b,S=r+m*b,C=n+h*b,w=r+g*b,T=o/Math.sin(y),E=(p+h)/2,D=(m+g)/2,O=Math.sqrt(E*E+D*D),k=n+E/O*T,A=r+D/O*T;return{tx0:x,ty0:S,tx1:C,ty1:w,cx:k,cy:A,startAngle:Math.atan2(S-A,x-k),endAngle:Math.atan2(w-A,C-k),counterclockwise:_>0}}function cairoArcTo(e,t,n,r,i,a,o,s){let c=computeArcTo(t,n,r,i,a,o,s);if(!c){e.lineTo(r,i);return}let{tx0:l,ty0:u,cx:d,cy:f,startAngle:p,endAngle:m,counterclockwise:h}=c;e.lineTo(l,u),h?e.arcNegative(d,f,s,p,m):e.arc(d,f,s,p,m)}function cairoEllipse(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),c?e.arcNegative(0,0,1,o,s):e.arc(0,0,1,o,s),e.restore()}function cairoRoundRect(e,t,n,r,i,a){let o,s,c,l;typeof a==`number`?o=s=c=l=a:a.length===1?o=s=c=l=a[0]:a.length===2?(o=c=a[0],s=l=a[1]):a.length===3?(o=a[0],s=l=a[1],c=a[2]):(o=a[0],s=a[1],c=a[2],l=a[3]);let u=Math.min(r/2,i/2);o=Math.min(o,u),s=Math.min(s,u),c=Math.min(c,u),l=Math.min(l,u);let d=Math.PI/2;e.newSubPath(),e.arc(t+o,n+o,o,Math.PI,Math.PI+d),e.arc(t+r-s,n+s,s,-d,0),e.arc(t+r-c,n+i-c,c,0,d),e.arc(t+l,n+i-l,l,d,Math.PI),e.closePath()}const e={"source-over":2,"source-in":3,"source-out":4,"source-atop":5,"destination-over":7,"destination-in":8,"destination-out":9,"destination-atop":10,lighter:12,copy:1,xor:11,multiply:14,screen:15,overlay:16,darken:17,lighten:18,"color-dodge":19,"color-burn":20,"hard-light":21,"soft-light":22,difference:23,exclusion:24,hue:25,saturation:26,color:27,luminosity:28},t={butt:0,round:1,square:2},n={miter:0,round:1,bevel:2};export{e as COMPOSITE_OP_MAP,t as LINE_CAP_MAP,n as LINE_JOIN_MAP,cairoArcTo,cairoEllipse,cairoRoundRect,computeArcTo,quadraticToCubic};
@@ -1 +1 @@
1
- import{parseColor as e}from"./color.js";import t from"cairo";var CanvasGradient=class{constructor(e,n,r,i,a,o,s){e===`radial`?this._pattern=new t.RadialGradient(n,r,o,i,a,s):this._pattern=new t.LinearGradient(n,r,i,a)}addColorStop(t,n){let r=e(n);r&&this._pattern.addColorStopRGBA(t,r.r,r.g,r.b,r.a)}_getCairoPattern(){return this._pattern}};export{CanvasGradient};
1
+ import"./_virtual/_rolldown/runtime.js";import{parseColor as e}from"./color.js";import t from"cairo";var CanvasGradient=class{constructor(e,n,r,i,a,o,s){e===`radial`?this._pattern=new t.RadialGradient(n,r,o,i,a,s):this._pattern=new t.LinearGradient(n,r,i,a)}addColorStop(t,n){let r=e(n);r&&this._pattern.addColorStopRGBA(t,r.r,r.g,r.b,r.a)}_getCairoPattern(){return this._pattern}};export{CanvasGradient};
@@ -1 +1 @@
1
- import{cairoRoundRect as e,quadraticToCubic as t}from"./cairo-utils.js";var n=class Path2D{constructor(e){this._ops=[],e instanceof Path2D&&(this._ops=[...e._ops])}addPath(e){this._ops.push(...e._ops)}moveTo(e,t){this._ops.push({type:`moveTo`,x:e,y:t})}lineTo(e,t){this._ops.push({type:`lineTo`,x:e,y:t})}closePath(){this._ops.push({type:`closePath`})}bezierCurveTo(e,t,n,r,i,a){this._ops.push({type:`bezierCurveTo`,cp1x:e,cp1y:t,cp2x:n,cp2y:r,x:i,y:a})}quadraticCurveTo(e,t,n,r){this._ops.push({type:`quadraticCurveTo`,cpx:e,cpy:t,x:n,y:r})}arc(e,t,n,r,i,a=!1){this._ops.push({type:`arc`,x:e,y:t,radius:n,startAngle:r,endAngle:i,ccw:a})}ellipse(e,t,n,r,i,a,o,s=!1){if(n<0||r<0)throw RangeError(`The radii provided are negative`);this._ops.push({type:`ellipse`,x:e,y:t,rx:n,ry:r,rotation:i,startAngle:a,endAngle:o,ccw:s})}rect(e,t,n,r){this._ops.push({type:`rect`,x:e,y:t,w:n,h:r})}roundRect(e,t,n,r,i=0){this._ops.push({type:`roundRect`,x:e,y:t,w:n,h:r,radii:i})}_replayOnCairo(n){let r=0,i=0;for(let a of this._ops)switch(a.type){case`moveTo`:n.moveTo(a.x,a.y),r=a.x,i=a.y;break;case`lineTo`:n.lineTo(a.x,a.y),r=a.x,i=a.y;break;case`closePath`:n.closePath();break;case`bezierCurveTo`:n.curveTo(a.cp1x,a.cp1y,a.cp2x,a.cp2y,a.x,a.y),r=a.x,i=a.y;break;case`quadraticCurveTo`:{let{cp1x:e,cp1y:o,cp2x:s,cp2y:c}=t(r,i,a.cpx,a.cpy,a.x,a.y);n.curveTo(e,o,s,c,a.x,a.y),r=a.x,i=a.y;break}case`arc`:a.ccw?n.arcNegative(a.x,a.y,a.radius,a.startAngle,a.endAngle):n.arc(a.x,a.y,a.radius,a.startAngle,a.endAngle);break;case`ellipse`:n.save(),n.translate(a.x,a.y),n.rotate(a.rotation),n.scale(a.rx,a.ry),a.ccw?n.arcNegative(0,0,1,a.startAngle,a.endAngle):n.arc(0,0,1,a.startAngle,a.endAngle),n.restore();break;case`rect`:n.rectangle(a.x,a.y,a.w,a.h);break;case`roundRect`:e(n,a.x,a.y,a.w,a.h,a.radii);break}}};export{n as Path2D};
1
+ import"./_virtual/_rolldown/runtime.js";import{cairoRoundRect as e,quadraticToCubic as t}from"./cairo-utils.js";var n=class Path2D{constructor(e){this._ops=[],e instanceof Path2D&&(this._ops=[...e._ops])}addPath(e){this._ops.push(...e._ops)}moveTo(e,t){this._ops.push({type:`moveTo`,x:e,y:t})}lineTo(e,t){this._ops.push({type:`lineTo`,x:e,y:t})}closePath(){this._ops.push({type:`closePath`})}bezierCurveTo(e,t,n,r,i,a){this._ops.push({type:`bezierCurveTo`,cp1x:e,cp1y:t,cp2x:n,cp2y:r,x:i,y:a})}quadraticCurveTo(e,t,n,r){this._ops.push({type:`quadraticCurveTo`,cpx:e,cpy:t,x:n,y:r})}arc(e,t,n,r,i,a=!1){this._ops.push({type:`arc`,x:e,y:t,radius:n,startAngle:r,endAngle:i,ccw:a})}ellipse(e,t,n,r,i,a,o,s=!1){if(n<0||r<0)throw RangeError(`The radii provided are negative`);this._ops.push({type:`ellipse`,x:e,y:t,rx:n,ry:r,rotation:i,startAngle:a,endAngle:o,ccw:s})}rect(e,t,n,r){this._ops.push({type:`rect`,x:e,y:t,w:n,h:r})}roundRect(e,t,n,r,i=0){this._ops.push({type:`roundRect`,x:e,y:t,w:n,h:r,radii:i})}_replayOnCairo(n){let r=0,i=0;for(let a of this._ops)switch(a.type){case`moveTo`:n.moveTo(a.x,a.y),r=a.x,i=a.y;break;case`lineTo`:n.lineTo(a.x,a.y),r=a.x,i=a.y;break;case`closePath`:n.closePath();break;case`bezierCurveTo`:n.curveTo(a.cp1x,a.cp1y,a.cp2x,a.cp2y,a.x,a.y),r=a.x,i=a.y;break;case`quadraticCurveTo`:{let{cp1x:e,cp1y:o,cp2x:s,cp2y:c}=t(r,i,a.cpx,a.cpy,a.x,a.y);n.curveTo(e,o,s,c,a.x,a.y),r=a.x,i=a.y;break}case`arc`:a.ccw?n.arcNegative(a.x,a.y,a.radius,a.startAngle,a.endAngle):n.arc(a.x,a.y,a.radius,a.startAngle,a.endAngle);break;case`ellipse`:n.save(),n.translate(a.x,a.y),n.rotate(a.rotation),n.scale(a.rx,a.ry),a.ccw?n.arcNegative(0,0,1,a.startAngle,a.endAngle):n.arc(0,0,1,a.startAngle,a.endAngle),n.restore();break;case`rect`:n.rectangle(a.x,a.y,a.w,a.h);break;case`roundRect`:e(n,a.x,a.y,a.w,a.h,a.radii);break}}};export{n as Path2D};
@@ -1 +1 @@
1
- import e from"cairo";import t from"gi://Gdk?version=4.0";var n=class CanvasPattern{constructor(t,n){this._pattern=new e.SurfacePattern(t);let r=this._pattern;switch(n){case`repeat`:case``:case null:r.setExtend(e.Extend.REPEAT);break;case`repeat-x`:case`repeat-y`:r.setExtend(e.Extend.REPEAT);break;case`no-repeat`:r.setExtend(e.Extend.NONE);break}}static create(n,r){if(`isPixbuf`in n&&typeof n.isPixbuf==`function`&&n.isPixbuf()){let i=n._pixbuf,a=i.get_width(),o=i.get_height(),s=new e.ImageSurface(e.Format.ARGB32,a,o),c=new e.Context(s);return t.cairo_set_source_pixbuf(c,i,0,0),c.paint(),c.$dispose(),new CanvasPattern(s,r)}if(typeof n?.getContext==`function`){let t=n.getContext(`2d`);if(t&&typeof t._getSurface==`function`){let n=t._getSurface(),i=n.getWidth(),a=n.getHeight(),o=new e.ImageSurface(e.Format.ARGB32,i,a),s=new e.Context(o);return s.setSourceSurface(n,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,r)}}return null}_getCairoPattern(){return this._pattern}};export{n as CanvasPattern};
1
+ import"./_virtual/_rolldown/runtime.js";import{asCairoPattern as e}from"./cairo-types.js";import{isCanvasImageSource as t,isPixbufImageSource as n}from"./dom-types.js";import r from"cairo";import i from"gi://Gdk?version=4.0";var a=class CanvasPattern{constructor(t,n){let i=e(new r.SurfacePattern(t));if(!i)throw TypeError(`CanvasPattern: cairo SurfacePattern is missing setExtend at runtime — incompatible Cairo binding`);switch(this._pattern=i,n){case`repeat`:case``:case null:i.setExtend(r.Extend.REPEAT);break;case`repeat-x`:case`repeat-y`:i.setExtend(r.Extend.REPEAT);break;case`no-repeat`:i.setExtend(r.Extend.NONE);break}}static create(e,a){if(n(e)){let t=e._pixbuf,n=t.get_width(),o=t.get_height(),s=new r.ImageSurface(r.Format.ARGB32,n,o),c=new r.Context(s);return i.cairo_set_source_pixbuf(c,t,0,0),c.paint(),c.$dispose(),new CanvasPattern(s,a)}if(t(e)){let t=e.getContext(`2d`);if(t&&typeof t._getSurface==`function`){let e=t._getSurface(),n=e.getWidth(),i=e.getHeight(),o=new r.ImageSurface(r.Format.ARGB32,n,i),s=new r.Context(o);return s.setSourceSurface(e,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,a)}}return null}_getCairoPattern(){return this._pattern}};export{a as CanvasPattern};
@@ -1 +1 @@
1
- import{COMPOSITE_OP_MAP as e,LINE_CAP_MAP as t,LINE_JOIN_MAP as n,cairoArcTo as r,cairoEllipse as i,cairoRoundRect as a,quadraticToCubic as o}from"./cairo-utils.js";import{parseColor as s}from"./color.js";import{CanvasGradient as c}from"./canvas-gradient.js";import{Path2D as l}from"./canvas-path.js";import{CanvasPattern as u}from"./canvas-pattern.js";import{cloneState as d,createDefaultState as f}from"./canvas-state.js";import{OurImageData as p}from"./image-data.js";import m from"cairo";import h from"gi://Gdk?version=4.0";import g from"gi://GdkPixbuf";import _ from"gi://Pango";import v from"gi://PangoCairo";var CanvasRenderingContext2D=class{constructor(e,t){this._stateStack=[],this.canvas=e,this._surfaceWidth=e.width||300,this._surfaceHeight=e.height||150,this._surface=new m.ImageSurface(m.Format.ARGB32,this._surfaceWidth,this._surfaceHeight),this._ctx=new m.Context(this._surface),this._state=f()}_ensureSurface(){let e=this.canvas.width||300,t=this.canvas.height||150;(e!==this._surfaceWidth||t!==this._surfaceHeight)&&(this._ctx.$dispose(),this._surface.finish(),this._surfaceWidth=e,this._surfaceHeight=t,this._surface=new m.ImageSurface(m.Format.ARGB32,e,t),this._ctx=new m.Context(this._surface),this._stateStack=[])}_resetState(){this._state=f(),this._stateStack=[]}_applyFillStyle(){let e=this._state.fillStyle;if(typeof e==`string`){let e=this._state.fillColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof c?this._ctx.setSource(e._getCairoPattern()):e instanceof u&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyStrokeStyle(){let e=this._state.strokeStyle;if(typeof e==`string`){let e=this._state.strokeColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof c?this._ctx.setSource(e._getCairoPattern()):e instanceof u&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyPatternFilter(){let e=this._ctx.getSource?.();if(e&&typeof e.setFilter==`function`){let t;t=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?m.Filter.BEST:m.Filter.BILINEAR:m.Filter.NEAREST,e.setFilter(t)}}_applyLineStyle(){this._ctx.setLineWidth(this._state.lineWidth),this._ctx.setLineCap(t[this._state.lineCap]),this._ctx.setLineJoin(n[this._state.lineJoin]),this._ctx.setMiterLimit(this._state.miterLimit),this._ctx.setDash(this._state.lineDash,this._state.lineDashOffset)}_applyCompositing(){let t=e[this._state.globalCompositeOperation];t!==void 0&&this._ctx.setOperator(t)}_getSurface(){return this._surface}_hasShadow(){if(this._state.shadowBlur===0&&this._state.shadowOffsetX===0&&this._state.shadowOffsetY===0)return!1;let e=s(this._state.shadowColor);return e!==null&&e.a>0}_deviceToUserDistance(e,t){let n=this._ctx.userToDevice(0,0),r=this._ctx.userToDevice(1,0),i=this._ctx.userToDevice(0,1),a=(r[0]??0)-(n[0]??0),o=(r[1]??0)-(n[1]??0),s=(i[0]??0)-(n[0]??0),c=(i[1]??0)-(n[1]??0),l=a*c-o*s;return Math.abs(l)<1e-10?[e,t]:[(c*e-s*t)/l,(-o*e+a*t)/l]}_renderShadow(e){}save(){this._ensureSurface(),this._stateStack.push(d(this._state)),this._ctx.save()}restore(){this._ensureSurface();let e=this._stateStack.pop();e&&(this._state=e,this._ctx.restore())}translate(e,t){this._ensureSurface(),this._ctx.translate(e,t)}rotate(e){this._ensureSurface(),this._ctx.rotate(e)}scale(e,t){this._ensureSurface(),this._ctx.scale(e,t)}transform(e,t,n,r,i,a){if(this._ensureSurface(),!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a))return;let o=i,s=a,c=Math.hypot(e,t),l=Math.hypot(n,r),u=Math.atan2(t,e);this._ctx.translate(o,s),u!==0&&this._ctx.rotate(u),(c!==1||l!==1)&&this._ctx.scale(c,l)}setTransform(e,t,n,r,i,a){if(this._ensureSurface(),typeof e==`object`&&e){let t=e;this._ctx.identityMatrix(),this.transform(t.a??t.m11??1,t.b??t.m12??0,t.c??t.m21??0,t.d??t.m22??1,t.e??t.m41??0,t.f??t.m42??0)}else typeof e==`number`?(this._ctx.identityMatrix(),this.transform(e,t,n,r,i,a)):this._ctx.identityMatrix()}getTransform(){let e=this._ctx.userToDevice(0,0),t=this._ctx.userToDevice(1,0),n=this._ctx.userToDevice(0,1),r=e[0]??0,i=e[1]??0,a=(t[0]??0)-r,o=(t[1]??0)-i,s=(n[0]??0)-r,c=(n[1]??0)-i,l=globalThis.DOMMatrix;return typeof l==`function`?new l([a,o,s,c,r,i]):{a,b:o,c:s,d:c,e:r,f:i,m11:a,m12:o,m13:0,m14:0,m21:s,m22:c,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,m41:r,m42:i,m43:0,m44:1,is2D:!0,isIdentity:a===1&&o===0&&s===0&&c===1&&r===0&&i===0}}resetTransform(){this._ensureSurface(),this._ctx.identityMatrix()}get fillStyle(){return this._state.fillStyle}set fillStyle(e){if(typeof e==`string`){let t=s(e);t&&(this._state.fillStyle=e,this._state.fillColor=t)}else this._state.fillStyle=e}get strokeStyle(){return this._state.strokeStyle}set strokeStyle(e){if(typeof e==`string`){let t=s(e);t&&(this._state.strokeStyle=e,this._state.strokeColor=t)}else this._state.strokeStyle=e}get lineWidth(){return this._state.lineWidth}set lineWidth(e){e>0&&isFinite(e)&&(this._state.lineWidth=e)}get lineCap(){return this._state.lineCap}set lineCap(e){(e===`butt`||e===`round`||e===`square`)&&(this._state.lineCap=e)}get lineJoin(){return this._state.lineJoin}set lineJoin(e){(e===`miter`||e===`round`||e===`bevel`)&&(this._state.lineJoin=e)}get miterLimit(){return this._state.miterLimit}set miterLimit(e){e>0&&isFinite(e)&&(this._state.miterLimit=e)}get globalAlpha(){return this._state.globalAlpha}set globalAlpha(e){e>=0&&e<=1&&isFinite(e)&&(this._state.globalAlpha=e)}get globalCompositeOperation(){return this._state.globalCompositeOperation}set globalCompositeOperation(t){e[t]!==void 0&&(this._state.globalCompositeOperation=t)}get imageSmoothingEnabled(){return this._state.imageSmoothingEnabled}set imageSmoothingEnabled(e){this._state.imageSmoothingEnabled=!!e}get imageSmoothingQuality(){return this._state.imageSmoothingQuality}set imageSmoothingQuality(e){(e===`low`||e===`medium`||e===`high`)&&(this._state.imageSmoothingQuality=e)}setLineDash(e){e.some(e=>e<0||!isFinite(e))||(this._state.lineDash=[...e])}getLineDash(){return[...this._state.lineDash]}get lineDashOffset(){return this._state.lineDashOffset}set lineDashOffset(e){isFinite(e)&&(this._state.lineDashOffset=e)}get shadowColor(){return this._state.shadowColor}set shadowColor(e){this._state.shadowColor=e}get shadowBlur(){return this._state.shadowBlur}set shadowBlur(e){e>=0&&isFinite(e)&&(this._state.shadowBlur=e)}get shadowOffsetX(){return this._state.shadowOffsetX}set shadowOffsetX(e){isFinite(e)&&(this._state.shadowOffsetX=e)}get shadowOffsetY(){return this._state.shadowOffsetY}set shadowOffsetY(e){isFinite(e)&&(this._state.shadowOffsetY=e)}get font(){return this._state.font}set font(e){this._state.font=e}get textAlign(){return this._state.textAlign}set textAlign(e){this._state.textAlign=e}get textBaseline(){return this._state.textBaseline}set textBaseline(e){this._state.textBaseline=e}get direction(){return this._state.direction}set direction(e){this._state.direction=e}beginPath(){this._ensureSurface(),this._ctx.newPath()}moveTo(e,t){this._ensureSurface(),this._ctx.moveTo(e,t)}lineTo(e,t){this._ensureSurface(),this._ctx.lineTo(e,t)}closePath(){this._ensureSurface(),this._ctx.closePath()}bezierCurveTo(e,t,n,r,i,a){this._ensureSurface(),this._ctx.curveTo(e,t,n,r,i,a)}quadraticCurveTo(e,t,n,r){this._ensureSurface();let i,a;this._ctx.hasCurrentPoint()?[i,a]=this._ctx.getCurrentPoint():(i=e,a=t);let{cp1x:s,cp1y:c,cp2x:l,cp2y:u}=o(i,a,e,t,n,r);this._ctx.curveTo(s,c,l,u,n,r)}arc(e,t,n,r,i,a=!1){if(this._ensureSurface(),Math.abs(i-r)>=2*Math.PI){this._ctx.arc(e,t,n,0,2*Math.PI);return}a?this._ctx.arcNegative(e,t,n,r,i):this._ctx.arc(e,t,n,r,i)}arcTo(e,t,n,i,a){this._ensureSurface();let o,s;this._ctx.hasCurrentPoint()?[o,s]=this._ctx.getCurrentPoint():(o=e,s=t,this._ctx.moveTo(e,t)),r(this._ctx,o,s,e,t,n,i,a)}ellipse(e,t,n,r,a,o,s,c=!1){if(this._ensureSurface(),n<0||r<0)throw RangeError(`The radii provided are negative`);i(this._ctx,e,t,n,r,a,o,s,c)}rect(e,t,n,r){this._ensureSurface(),this._ctx.rectangle(e,t,n,r)}roundRect(e,t,n,r,i=0){this._ensureSurface(),a(this._ctx,e,t,n,r,i)}fill(e,t){this._ensureSurface(),this._applyCompositing(),this._applyFillStyle();let n;e instanceof l?(this._ctx.newPath(),e._replayOnCairo(this._ctx),n=t):n=e,this._ctx.setFillRule(n===`evenodd`?m.FillRule.EVEN_ODD:m.FillRule.WINDING),this._ctx.fillPreserve()}stroke(e){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle(),e instanceof l&&(this._ctx.newPath(),e._replayOnCairo(this._ctx)),this._ctx.strokePreserve()}fillRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill()}),this._applyFillStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.newPath(),this._ctx.appendPath(i)}strokeRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke()}),this._applyStrokeStyle(),this._applyLineStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke(),this._ctx.newPath(),this._ctx.appendPath(i)}clearRect(e,t,n,r){this._ensureSurface();let i=this._ctx.copyPath();this._ctx.save(),this._ctx.setOperator(m.Operator.CLEAR),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.restore(),this._ctx.newPath(),this._ctx.appendPath(i)}clip(e,t){this._ensureSurface();let n;e instanceof l?(this._ctx.newPath(),e._replayOnCairo(this._ctx),n=t):n=e,this._ctx.setFillRule(n===`evenodd`?m.FillRule.EVEN_ODD:m.FillRule.WINDING),this._ctx.clip()}isPointInPath(e,t,n,r){this._ensureSurface();let i,a,o;return e instanceof l?(this._ctx.newPath(),e._replayOnCairo(this._ctx),i=t,a=n,o=r):(i=e,a=t,o=n),this._ctx.setFillRule(o===`evenodd`?m.FillRule.EVEN_ODD:m.FillRule.WINDING),this._ctx.inFill(i,a)}isPointInStroke(e,t,n){return this._ensureSurface(),this._applyLineStyle(),e instanceof l?(this._ctx.newPath(),e._replayOnCairo(this._ctx),this._ctx.inStroke(t,n)):this._ctx.inStroke(e,t)}createLinearGradient(e,t,n,r){return new c(`linear`,e,t,n,r)}createRadialGradient(e,t,n,r,i,a){return new c(`radial`,e,t,r,i,n,a)}createPattern(e,t){return u.create(e,t)}createImageData(e,t){return typeof e==`number`?new p(Math.abs(e),Math.abs(t)):new p(e.width,e.height)}getImageData(e,t,n,r){this._ensureSurface(),this._surface.flush();let i=h.pixbuf_get_from_surface(this._surface,e,t,n,r);if(!i)return new p(n,r);let a=i.get_pixels(),o=i.get_has_alpha(),s=i.get_rowstride(),c=i.get_n_channels(),l=new Uint8ClampedArray(n*r*4);for(let e=0;e<r;e++)for(let t=0;t<n;t++){let r=e*s+t*c,i=(e*n+t)*4;l[i]=a[r],l[i+1]=a[r+1],l[i+2]=a[r+2],l[i+3]=o?a[r+3]:255}return new p(l,n,r)}putImageData(e,t,n,r,i,a,o){this._ensureSurface();let s=r??0,c=i??0,l=a??e.width,u=o??e.height,d=e.data,f=e.width,p=new Uint8Array(l*u*4);for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=((c+e)*f+(s+t))*4,r=(e*l+t)*4;p[r]=d[n],p[r+1]=d[n+1],p[r+2]=d[n+2],p[r+3]=d[n+3]}let _=g.Pixbuf.new_from_bytes(p,g.Colorspace.RGB,!0,8,l,u,l*4);this._ctx.save(),this._ctx.setOperator(m.Operator.SOURCE),h.cairo_set_source_pixbuf(this._ctx,_,t+s,n+c),this._ctx.rectangle(t+s,n+c,l,u),this._ctx.fill(),this._ctx.restore()}drawImage(e,t,n,r,i,a,o,s,c){this._ensureSurface(),this._applyCompositing();let l,u,d,f,p,g,_,v,y=this._getDrawImageSource(e);if(!y)return;let{pixbuf:b,imgWidth:x,imgHeight:S}=y;if(r===void 0?(l=0,u=0,d=x,f=S,p=t,g=n,_=x,v=S):a===void 0?(l=0,u=0,d=x,f=S,p=t,g=n,_=r,v=i):(l=t,u=n,d=r,f=i,p=a,g=o,_=s,v=c),!Number.isFinite(l)||!Number.isFinite(u)||!Number.isFinite(d)||!Number.isFinite(f)||!Number.isFinite(p)||!Number.isFinite(g)||!Number.isFinite(_)||!Number.isFinite(v)||d===0||f===0||_===0||v===0)return;this._ctx.save(),this._ctx.rectangle(p,g,_,v),this._ctx.clip(),this._ctx.translate(p,g),this._ctx.scale(_/d,v/f),this._ctx.translate(-l,-u),h.cairo_set_source_pixbuf(this._ctx,b,0,0);let C=this._ctx.getSource?.();if(C&&typeof C.setFilter==`function`){let e;e=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?m.Filter.BEST:m.Filter.BILINEAR:m.Filter.NEAREST,C.setFilter(e)}this._state.globalAlpha<1?this._ctx.paintWithAlpha(this._state.globalAlpha):this._ctx.paint(),this._ctx.restore()}_getDrawImageSource(e){if(typeof e?.isPixbuf==`function`&&e.isPixbuf()){let t=e._pixbuf;return{pixbuf:t,imgWidth:t.get_width(),imgHeight:t.get_height()}}if(typeof e?.getContext==`function`){let t=e.width,n=e.height;if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=e.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let e=r._getSurface();e.flush();let i=h.pixbuf_get_from_surface(e,0,0,t,n);if(i)return{pixbuf:i,imgWidth:t,imgHeight:n}}}return null}_createTextLayout(e){let t=v.create_layout(this._ctx);t.set_text(e,-1),t.get_context().set_base_dir(_.Direction.LTR),t.context_changed();let n=this._parseFontToDescription(this._state.font);return t.set_font_description(n),t}_parseFontToDescription(e){let t=e.match(/^\s*(italic|oblique|normal)?\s*(small-caps|normal)?\s*(bold|bolder|lighter|[1-9]00|normal)?\s*(\d+(?:\.\d+)?)(px|pt|em|rem|%)?\s*(?:\/\S+)?\s*(.+)?$/i);if(!t)return _.font_description_from_string(e);let n=t[1]||``,r=t[3]||``,i=parseFloat(t[4])||10,a=(t[5]||`px`).toLowerCase(),o=(t[6]||`sans-serif`).replace(/['"]/g,``).trim();a===`pt`?i=i*96/72:a===`em`||a===`rem`?i*=16:a===`%`&&(i=i/100*16);let s=o;n===`italic`?s+=` Italic`:n===`oblique`&&(s+=` Oblique`),r===`bold`||r===`bolder`||parseInt(r)>=600?s+=` Bold`:(r===`lighter`||parseInt(r)>0&&parseInt(r)<=300)&&(s+=` Light`);let c=_.font_description_from_string(s);return c.set_absolute_size(i*_.SCALE),c}_getTextAlignOffset(e){let[,t]=e.get_pixel_extents(),n=t.width;switch(this._state.textAlign){case`center`:return-n/2;case`right`:case`end`:return-n;default:return 0}}_getTextBaselineOffset(e){let t=e.get_font_description()||this._parseFontToDescription(this._state.font),n=e.get_context().get_metrics(t,null),r=n.get_ascent()/_.SCALE,i=n.get_descent()/_.SCALE,a=r+i;switch(this._state.textBaseline){case`top`:return 0;case`hanging`:return-(r*.2);case`middle`:return-(a/2);case`alphabetic`:return-r;case`ideographic`:return-(r+i*.5);case`bottom`:return-a;default:return-r}}fillText(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._createTextLayout(e),a=this._getTextAlignOffset(i),o=this._getTextBaselineOffset(i);if(this._hasShadow()){let e=s(this._state.shadowColor);if(e){let[r,s]=this._deviceToUserDistance(this._state.shadowOffsetX,this._state.shadowOffsetY),c=this._state.shadowBlur,l;if(c>0){let[t]=this._deviceToUserDistance(c,0),[,n]=this._deviceToUserDistance(0,c);l=[[r,s,e.a],[r+t,s,e.a*.5],[r-t,s,e.a*.5],[r,s+n,e.a*.5],[r,s-n,e.a*.5]]}else l=[[r,s,e.a]];let u=this._state.imageSmoothingEnabled?m.Antialias.DEFAULT:m.Antialias.NONE;for(let[r,s,c]of l)this._ctx.save(),this._ctx.setAntialias(u),this._ctx.setSourceRGBA(e.r,e.g,e.b,c),this._ctx.moveTo(t+a+r,n+o+s),v.show_layout(this._ctx,i),this._ctx.restore()}}this._applyFillStyle(),this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?m.Antialias.DEFAULT:m.Antialias.NONE),this._ctx.moveTo(t+a,n+o),v.show_layout(this._ctx,i),this._ctx.restore()}strokeText(e,t,n,r){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle();let i=this._createTextLayout(e),a=this._getTextAlignOffset(i),o=this._getTextBaselineOffset(i);this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?m.Antialias.DEFAULT:m.Antialias.NONE),this._ctx.moveTo(t+a,n+o),v.layout_path(this._ctx,i),this._ctx.stroke(),this._ctx.restore()}measureText(e){this._ensureSurface();let t=this._createTextLayout(e),[n,r]=t.get_pixel_extents(),i=t.get_baseline()/_.SCALE,a=Math.max(0,i-n.y),o=Math.max(0,n.y+n.height-i),s=t.get_font_description()||this._parseFontToDescription(this._state.font),c=t.get_context().get_metrics(s,null),l=c.get_ascent()/_.SCALE,u=c.get_descent()/_.SCALE;return{width:r.width,actualBoundingBoxAscent:a,actualBoundingBoxDescent:o,actualBoundingBoxLeft:Math.max(0,-n.x),actualBoundingBoxRight:n.x+n.width,fontBoundingBoxAscent:l,fontBoundingBoxDescent:u,alphabeticBaseline:0,emHeightAscent:l,emHeightDescent:u,hangingBaseline:l*.8,ideographicBaseline:-u}}_toDataURL(e,t){this._surface.flush();let n=imports.gi.Gio,r=imports.gi.GLib,[,i]=r.file_open_tmp(`canvas-XXXXXX.png`);try{this._surface.writeToPNG(i);let[,e]=n.File.new_for_path(i).load_contents(null);return`data:image/png;base64,${r.base64_encode(e)}`}finally{try{r.unlink(i)}catch{}}}_dispose(){this._ctx.$dispose(),this._surface.finish()}};export{CanvasRenderingContext2D};
1
+ import"./_virtual/_rolldown/runtime.js";import{asCairoPattern as e}from"./cairo-types.js";import{COMPOSITE_OP_MAP as t,LINE_CAP_MAP as n,LINE_JOIN_MAP as r,cairoArcTo as i,cairoEllipse as a,cairoRoundRect as o,quadraticToCubic as s}from"./cairo-utils.js";import{parseColor as c}from"./color.js";import{CanvasGradient as l}from"./canvas-gradient.js";import{Path2D as u}from"./canvas-path.js";import{isCanvasImageSource as d,isPixbufImageSource as f}from"./dom-types.js";import{CanvasPattern as p}from"./canvas-pattern.js";import{cloneState as m,createDefaultState as h}from"./canvas-state.js";import{OurImageData as g}from"./image-data.js";import _ from"cairo";import v from"gi://Gdk?version=4.0";import y from"gi://GdkPixbuf";import b from"gi://Pango";import x from"gi://PangoCairo";var CanvasRenderingContext2D=class{constructor(e,t){this._stateStack=[],this.canvas=e,this._surfaceWidth=e.width||300,this._surfaceHeight=e.height||150,this._surface=new _.ImageSurface(_.Format.ARGB32,this._surfaceWidth,this._surfaceHeight),this._ctx=new _.Context(this._surface),this._state=h()}_ensureSurface(){let e=this.canvas.width||300,t=this.canvas.height||150;(e!==this._surfaceWidth||t!==this._surfaceHeight)&&(this._ctx.$dispose(),this._surface.finish(),this._surfaceWidth=e,this._surfaceHeight=t,this._surface=new _.ImageSurface(_.Format.ARGB32,e,t),this._ctx=new _.Context(this._surface),this._stateStack=[])}_resetState(){this._state=h(),this._stateStack=[]}_applyFillStyle(){let e=this._state.fillStyle;if(typeof e==`string`){let e=this._state.fillColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof l?this._ctx.setSource(e._getCairoPattern()):e instanceof p&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyStrokeStyle(){let e=this._state.strokeStyle;if(typeof e==`string`){let e=this._state.strokeColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof l?this._ctx.setSource(e._getCairoPattern()):e instanceof p&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyPatternFilter(){let t=e(this._ctx.getSource?.());if(!t)return;let n;n=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?_.Filter.BEST:_.Filter.BILINEAR:_.Filter.NEAREST,t.setFilter(n)}_applyLineStyle(){this._ctx.setLineWidth(this._state.lineWidth),this._ctx.setLineCap(n[this._state.lineCap]),this._ctx.setLineJoin(r[this._state.lineJoin]),this._ctx.setMiterLimit(this._state.miterLimit),this._ctx.setDash(this._state.lineDash,this._state.lineDashOffset)}_applyCompositing(){let e=t[this._state.globalCompositeOperation];e!==void 0&&this._ctx.setOperator(e)}_getSurface(){return this._surface}_hasShadow(){if(this._state.shadowBlur===0&&this._state.shadowOffsetX===0&&this._state.shadowOffsetY===0)return!1;let e=c(this._state.shadowColor);return e!==null&&e.a>0}_deviceToUserDistance(e,t){let n=this._ctx.userToDevice(0,0),r=this._ctx.userToDevice(1,0),i=this._ctx.userToDevice(0,1),a=(r[0]??0)-(n[0]??0),o=(r[1]??0)-(n[1]??0),s=(i[0]??0)-(n[0]??0),c=(i[1]??0)-(n[1]??0),l=a*c-o*s;return Math.abs(l)<1e-10?[e,t]:[(c*e-s*t)/l,(-o*e+a*t)/l]}_renderShadow(e){}save(){this._ensureSurface(),this._stateStack.push(m(this._state)),this._ctx.save()}restore(){this._ensureSurface();let e=this._stateStack.pop();e&&(this._state=e,this._ctx.restore())}translate(e,t){this._ensureSurface(),this._ctx.translate(e,t)}rotate(e){this._ensureSurface(),this._ctx.rotate(e)}scale(e,t){this._ensureSurface(),this._ctx.scale(e,t)}transform(e,t,n,r,i,a){if(this._ensureSurface(),!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a))return;let o=i,s=a,c=Math.hypot(e,t),l=Math.hypot(n,r),u=Math.atan2(t,e);this._ctx.translate(o,s),u!==0&&this._ctx.rotate(u),(c!==1||l!==1)&&this._ctx.scale(c,l)}setTransform(e,t,n,r,i,a){if(this._ensureSurface(),typeof e==`object`&&e){let t=e;this._ctx.identityMatrix(),this.transform(t.a??t.m11??1,t.b??t.m12??0,t.c??t.m21??0,t.d??t.m22??1,t.e??t.m41??0,t.f??t.m42??0)}else typeof e==`number`?(this._ctx.identityMatrix(),this.transform(e,t,n,r,i,a)):this._ctx.identityMatrix()}getTransform(){let e=this._ctx.userToDevice(0,0),t=this._ctx.userToDevice(1,0),n=this._ctx.userToDevice(0,1),r=e[0]??0,i=e[1]??0,a=(t[0]??0)-r,o=(t[1]??0)-i,s=(n[0]??0)-r,c=(n[1]??0)-i,l=globalThis.DOMMatrix;return typeof l==`function`?new l([a,o,s,c,r,i]):{a,b:o,c:s,d:c,e:r,f:i,m11:a,m12:o,m13:0,m14:0,m21:s,m22:c,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,m41:r,m42:i,m43:0,m44:1,is2D:!0,isIdentity:a===1&&o===0&&s===0&&c===1&&r===0&&i===0}}resetTransform(){this._ensureSurface(),this._ctx.identityMatrix()}get fillStyle(){return this._state.fillStyle}set fillStyle(e){if(typeof e==`string`){let t=c(e);t&&(this._state.fillStyle=e,this._state.fillColor=t)}else this._state.fillStyle=e}get strokeStyle(){return this._state.strokeStyle}set strokeStyle(e){if(typeof e==`string`){let t=c(e);t&&(this._state.strokeStyle=e,this._state.strokeColor=t)}else this._state.strokeStyle=e}get lineWidth(){return this._state.lineWidth}set lineWidth(e){e>0&&isFinite(e)&&(this._state.lineWidth=e)}get lineCap(){return this._state.lineCap}set lineCap(e){(e===`butt`||e===`round`||e===`square`)&&(this._state.lineCap=e)}get lineJoin(){return this._state.lineJoin}set lineJoin(e){(e===`miter`||e===`round`||e===`bevel`)&&(this._state.lineJoin=e)}get miterLimit(){return this._state.miterLimit}set miterLimit(e){e>0&&isFinite(e)&&(this._state.miterLimit=e)}get globalAlpha(){return this._state.globalAlpha}set globalAlpha(e){e>=0&&e<=1&&isFinite(e)&&(this._state.globalAlpha=e)}get globalCompositeOperation(){return this._state.globalCompositeOperation}set globalCompositeOperation(e){t[e]!==void 0&&(this._state.globalCompositeOperation=e)}get imageSmoothingEnabled(){return this._state.imageSmoothingEnabled}set imageSmoothingEnabled(e){this._state.imageSmoothingEnabled=!!e}get imageSmoothingQuality(){return this._state.imageSmoothingQuality}set imageSmoothingQuality(e){(e===`low`||e===`medium`||e===`high`)&&(this._state.imageSmoothingQuality=e)}setLineDash(e){e.some(e=>e<0||!isFinite(e))||(this._state.lineDash=[...e])}getLineDash(){return[...this._state.lineDash]}get lineDashOffset(){return this._state.lineDashOffset}set lineDashOffset(e){isFinite(e)&&(this._state.lineDashOffset=e)}get shadowColor(){return this._state.shadowColor}set shadowColor(e){this._state.shadowColor=e}get shadowBlur(){return this._state.shadowBlur}set shadowBlur(e){e>=0&&isFinite(e)&&(this._state.shadowBlur=e)}get shadowOffsetX(){return this._state.shadowOffsetX}set shadowOffsetX(e){isFinite(e)&&(this._state.shadowOffsetX=e)}get shadowOffsetY(){return this._state.shadowOffsetY}set shadowOffsetY(e){isFinite(e)&&(this._state.shadowOffsetY=e)}get font(){return this._state.font}set font(e){this._state.font=e}get textAlign(){return this._state.textAlign}set textAlign(e){this._state.textAlign=e}get textBaseline(){return this._state.textBaseline}set textBaseline(e){this._state.textBaseline=e}get direction(){return this._state.direction}set direction(e){this._state.direction=e}beginPath(){this._ensureSurface(),this._ctx.newPath()}moveTo(e,t){this._ensureSurface(),this._ctx.moveTo(e,t)}lineTo(e,t){this._ensureSurface(),this._ctx.lineTo(e,t)}closePath(){this._ensureSurface(),this._ctx.closePath()}bezierCurveTo(e,t,n,r,i,a){this._ensureSurface(),this._ctx.curveTo(e,t,n,r,i,a)}quadraticCurveTo(e,t,n,r){this._ensureSurface();let i,a;this._ctx.hasCurrentPoint()?[i,a]=this._ctx.getCurrentPoint():(i=e,a=t);let{cp1x:o,cp1y:c,cp2x:l,cp2y:u}=s(i,a,e,t,n,r);this._ctx.curveTo(o,c,l,u,n,r)}arc(e,t,n,r,i,a=!1){if(this._ensureSurface(),Math.abs(i-r)>=2*Math.PI){this._ctx.arc(e,t,n,0,2*Math.PI);return}a?this._ctx.arcNegative(e,t,n,r,i):this._ctx.arc(e,t,n,r,i)}arcTo(e,t,n,r,a){this._ensureSurface();let o,s;this._ctx.hasCurrentPoint()?[o,s]=this._ctx.getCurrentPoint():(o=e,s=t,this._ctx.moveTo(e,t)),i(this._ctx,o,s,e,t,n,r,a)}ellipse(e,t,n,r,i,o,s,c=!1){if(this._ensureSurface(),n<0||r<0)throw RangeError(`The radii provided are negative`);a(this._ctx,e,t,n,r,i,o,s,c)}rect(e,t,n,r){this._ensureSurface(),this._ctx.rectangle(e,t,n,r)}roundRect(e,t,n,r,i=0){this._ensureSurface(),o(this._ctx,e,t,n,r,i)}fill(e,t){this._ensureSurface(),this._applyCompositing(),this._applyFillStyle();let n;e instanceof u?(this._ctx.newPath(),e._replayOnCairo(this._ctx),n=t):n=e,this._ctx.setFillRule(n===`evenodd`?_.FillRule.EVEN_ODD:_.FillRule.WINDING),this._ctx.fillPreserve()}stroke(e){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle(),e instanceof u&&(this._ctx.newPath(),e._replayOnCairo(this._ctx)),this._ctx.strokePreserve()}fillRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill()}),this._applyFillStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.newPath(),this._ctx.appendPath(i)}strokeRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke()}),this._applyStrokeStyle(),this._applyLineStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke(),this._ctx.newPath(),this._ctx.appendPath(i)}clearRect(e,t,n,r){this._ensureSurface();let i=this._ctx.copyPath();this._ctx.save(),this._ctx.setOperator(_.Operator.CLEAR),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.restore(),this._ctx.newPath(),this._ctx.appendPath(i)}clip(e,t){this._ensureSurface();let n;e instanceof u?(this._ctx.newPath(),e._replayOnCairo(this._ctx),n=t):n=e,this._ctx.setFillRule(n===`evenodd`?_.FillRule.EVEN_ODD:_.FillRule.WINDING),this._ctx.clip()}isPointInPath(e,t,n,r){this._ensureSurface();let i,a,o;return e instanceof u?(this._ctx.newPath(),e._replayOnCairo(this._ctx),i=t,a=n,o=r):(i=e,a=t,o=n),this._ctx.setFillRule(o===`evenodd`?_.FillRule.EVEN_ODD:_.FillRule.WINDING),this._ctx.inFill(i,a)}isPointInStroke(e,t,n){return this._ensureSurface(),this._applyLineStyle(),e instanceof u?(this._ctx.newPath(),e._replayOnCairo(this._ctx),this._ctx.inStroke(t,n)):this._ctx.inStroke(e,t)}createLinearGradient(e,t,n,r){return new l(`linear`,e,t,n,r)}createRadialGradient(e,t,n,r,i,a){return new l(`radial`,e,t,r,i,n,a)}createPattern(e,t){return p.create(e,t)}createImageData(e,t){return typeof e==`number`?new g(Math.abs(e),Math.abs(t)):new g(e.width,e.height)}getImageData(e,t,n,r){this._ensureSurface(),this._surface.flush();let i=v.pixbuf_get_from_surface(this._surface,e,t,n,r);if(!i)return new g(n,r);let a=i.get_pixels(),o=i.get_has_alpha(),s=i.get_rowstride(),c=i.get_n_channels(),l=new Uint8ClampedArray(n*r*4);for(let e=0;e<r;e++)for(let t=0;t<n;t++){let r=e*s+t*c,i=(e*n+t)*4;l[i]=a[r],l[i+1]=a[r+1],l[i+2]=a[r+2],l[i+3]=o?a[r+3]:255}return new g(l,n,r)}putImageData(e,t,n,r,i,a,o){this._ensureSurface();let s=r??0,c=i??0,l=a??e.width,u=o??e.height,d=e.data,f=e.width,p=new Uint8Array(l*u*4);for(let e=0;e<u;e++)for(let t=0;t<l;t++){let n=((c+e)*f+(s+t))*4,r=(e*l+t)*4;p[r]=d[n],p[r+1]=d[n+1],p[r+2]=d[n+2],p[r+3]=d[n+3]}let m=y.Pixbuf.new_from_bytes(p,y.Colorspace.RGB,!0,8,l,u,l*4);this._ctx.save(),this._ctx.setOperator(_.Operator.SOURCE),v.cairo_set_source_pixbuf(this._ctx,m,t+s,n+c),this._ctx.rectangle(t+s,n+c,l,u),this._ctx.fill(),this._ctx.restore()}drawImage(t,n,r,i,a,o,s,c,l){this._ensureSurface(),this._applyCompositing();let u,d,f,p,m,h,g,y,b=this._getDrawImageSource(t);if(!b)return;let{pixbuf:x,imgWidth:S,imgHeight:C}=b;if(i===void 0?(u=0,d=0,f=S,p=C,m=n,h=r,g=S,y=C):o===void 0?(u=0,d=0,f=S,p=C,m=n,h=r,g=i,y=a):(u=n,d=r,f=i,p=a,m=o,h=s,g=c,y=l),!Number.isFinite(u)||!Number.isFinite(d)||!Number.isFinite(f)||!Number.isFinite(p)||!Number.isFinite(m)||!Number.isFinite(h)||!Number.isFinite(g)||!Number.isFinite(y)||f===0||p===0||g===0||y===0)return;this._ctx.save(),this._ctx.rectangle(m,h,g,y),this._ctx.clip(),this._ctx.translate(m,h),this._ctx.scale(g/f,y/p),this._ctx.translate(-u,-d),v.cairo_set_source_pixbuf(this._ctx,x,0,0);let w=e(this._ctx.getSource?.());if(w){let e;e=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?_.Filter.BEST:_.Filter.BILINEAR:_.Filter.NEAREST,w.setFilter(e)}this._state.globalAlpha<1?this._ctx.paintWithAlpha(this._state.globalAlpha):this._ctx.paint(),this._ctx.restore()}_getDrawImageSource(e){if(f(e)){let t=e._pixbuf;return{pixbuf:t,imgWidth:t.get_width(),imgHeight:t.get_height()}}if(d(e)){let t=e.width??0,n=e.height??0;if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=e.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let e=r._getSurface();e.flush();let i=v.pixbuf_get_from_surface(e,0,0,t,n);if(i)return{pixbuf:i,imgWidth:t,imgHeight:n}}}return null}_createTextLayout(e){let t=x.create_layout(this._ctx);t.set_text(e,-1),t.get_context().set_base_dir(b.Direction.LTR),t.context_changed();let n=this._parseFontToDescription(this._state.font);return t.set_font_description(n),t}_parseFontToDescription(e){let t=e.match(/^\s*(italic|oblique|normal)?\s*(small-caps|normal)?\s*(bold|bolder|lighter|[1-9]00|normal)?\s*(\d+(?:\.\d+)?)(px|pt|em|rem|%)?\s*(?:\/\S+)?\s*(.+)?$/i);if(!t)return b.font_description_from_string(e);let n=t[1]||``,r=t[3]||``,i=parseFloat(t[4])||10,a=(t[5]||`px`).toLowerCase(),o=(t[6]||`sans-serif`).replace(/['"]/g,``).trim();a===`pt`?i=i*96/72:a===`em`||a===`rem`?i*=16:a===`%`&&(i=i/100*16);let s=o;n===`italic`?s+=` Italic`:n===`oblique`&&(s+=` Oblique`),r===`bold`||r===`bolder`||parseInt(r)>=600?s+=` Bold`:(r===`lighter`||parseInt(r)>0&&parseInt(r)<=300)&&(s+=` Light`);let c=b.font_description_from_string(s);return c.set_absolute_size(i*b.SCALE),c}_getTextAlignOffset(e){let[,t]=e.get_pixel_extents(),n=t.width;switch(this._state.textAlign){case`center`:return-n/2;case`right`:case`end`:return-n;default:return 0}}_getTextBaselineOffset(e){let t=e.get_font_description()||this._parseFontToDescription(this._state.font),n=e.get_context().get_metrics(t,null),r=n.get_ascent()/b.SCALE,i=n.get_descent()/b.SCALE,a=r+i;switch(this._state.textBaseline){case`top`:return 0;case`hanging`:return-(r*.2);case`middle`:return-(a/2);case`alphabetic`:return-r;case`ideographic`:return-(r+i*.5);case`bottom`:return-a;default:return-r}}fillText(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._createTextLayout(e),a=this._getTextAlignOffset(i),o=this._getTextBaselineOffset(i);if(this._hasShadow()){let e=c(this._state.shadowColor);if(e){let[r,s]=this._deviceToUserDistance(this._state.shadowOffsetX,this._state.shadowOffsetY),c=this._state.shadowBlur,l;if(c>0){let[t]=this._deviceToUserDistance(c,0),[,n]=this._deviceToUserDistance(0,c);l=[[r,s,e.a],[r+t,s,e.a*.5],[r-t,s,e.a*.5],[r,s+n,e.a*.5],[r,s-n,e.a*.5]]}else l=[[r,s,e.a]];let u=this._state.imageSmoothingEnabled?_.Antialias.DEFAULT:_.Antialias.NONE;for(let[r,s,c]of l)this._ctx.save(),this._ctx.setAntialias(u),this._ctx.setSourceRGBA(e.r,e.g,e.b,c),this._ctx.moveTo(t+a+r,n+o+s),x.show_layout(this._ctx,i),this._ctx.restore()}}this._applyFillStyle(),this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?_.Antialias.DEFAULT:_.Antialias.NONE),this._ctx.moveTo(t+a,n+o),x.show_layout(this._ctx,i),this._ctx.restore()}strokeText(e,t,n,r){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle();let i=this._createTextLayout(e),a=this._getTextAlignOffset(i),o=this._getTextBaselineOffset(i);this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?_.Antialias.DEFAULT:_.Antialias.NONE),this._ctx.moveTo(t+a,n+o),x.layout_path(this._ctx,i),this._ctx.stroke(),this._ctx.restore()}measureText(e){this._ensureSurface();let t=this._createTextLayout(e),[n,r]=t.get_pixel_extents(),i=t.get_baseline()/b.SCALE,a=Math.max(0,i-n.y),o=Math.max(0,n.y+n.height-i),s=t.get_font_description()||this._parseFontToDescription(this._state.font),c=t.get_context().get_metrics(s,null),l=c.get_ascent()/b.SCALE,u=c.get_descent()/b.SCALE;return{width:r.width,actualBoundingBoxAscent:a,actualBoundingBoxDescent:o,actualBoundingBoxLeft:Math.max(0,-n.x),actualBoundingBoxRight:n.x+n.width,fontBoundingBoxAscent:l,fontBoundingBoxDescent:u,alphabeticBaseline:0,emHeightAscent:l,emHeightDescent:u,hangingBaseline:l*.8,ideographicBaseline:-u}}_toDataURL(e,t){this._surface.flush();let n=imports.gi.Gio,r=imports.gi.GLib,[,i]=r.file_open_tmp(`canvas-XXXXXX.png`);try{this._surface.writeToPNG(i);let[,e]=n.File.new_for_path(i).load_contents(null);return`data:image/png;base64,${r.base64_encode(e)}`}finally{try{r.unlink(i)}catch{}}}_dispose(){this._ctx.$dispose(),this._surface.finish()}};export{CanvasRenderingContext2D};
@@ -1 +1 @@
1
- import{BLACK as e}from"./color.js";function createDefaultState(){return{fillStyle:`#000000`,fillColor:{...e},strokeStyle:`#000000`,strokeColor:{...e},lineWidth:1,lineCap:`butt`,lineJoin:`miter`,miterLimit:10,lineDash:[],lineDashOffset:0,globalAlpha:1,globalCompositeOperation:`source-over`,shadowColor:`rgba(0, 0, 0, 0)`,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,font:`10px sans-serif`,textAlign:`start`,textBaseline:`alphabetic`,direction:`ltr`,imageSmoothingEnabled:!0,imageSmoothingQuality:`low`}}function cloneState(e){return{...e,fillColor:{...e.fillColor},strokeColor:{...e.strokeColor},lineDash:[...e.lineDash]}}export{cloneState,createDefaultState};
1
+ import"./_virtual/_rolldown/runtime.js";import{BLACK as e}from"./color.js";function createDefaultState(){return{fillStyle:`#000000`,fillColor:{...e},strokeStyle:`#000000`,strokeColor:{...e},lineWidth:1,lineCap:`butt`,lineJoin:`miter`,miterLimit:10,lineDash:[],lineDashOffset:0,globalAlpha:1,globalCompositeOperation:`source-over`,shadowColor:`rgba(0, 0, 0, 0)`,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,font:`10px sans-serif`,textAlign:`start`,textBaseline:`alphabetic`,direction:`ltr`,imageSmoothingEnabled:!0,imageSmoothingQuality:`low`}}function cloneState(e){return{...e,fillColor:{...e.fillColor},strokeColor:{...e.strokeColor},lineDash:[...e.lineDash]}}export{cloneState,createDefaultState};
package/lib/esm/color.js CHANGED
@@ -1 +1 @@
1
- const e={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function parseColor(t){if(!t||typeof t!=`string`)return null;let n=t.trim().toLowerCase(),r=e[n];if(r)return parseHex(r);if(n.startsWith(`#`))return parseHex(n);let i=n.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(i)return{r:parseComponent(i[1],255)/255,g:parseComponent(i[2],255)/255,b:parseComponent(i[3],255)/255,a:i[4]===void 0?1:parseComponent(i[4],1)};let a=n.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(a){let e=parseFloat(a[1]),t=parseFloat(a[2]),n=a[3]===`%`,r=parseFloat(a[4]),i=a[5]===`%`,o=a[6]===void 0?1:parseComponent(a[6],1);return e>1&&(e/=360),(n||t>1)&&(t/=100),(i||r>1)&&(r/=100),hslToRGBA(e,t,r,Math.max(0,Math.min(1,o)))}return null}function parseHex(e){let t=e.slice(1),n,r,i,a=1;if(t.length===3)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255;else if(t.length===4)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255,a=parseInt(t[3]+t[3],16)/255;else if(t.length===6)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255;else if(t.length===8)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255,a=parseInt(t.slice(6,8),16)/255;else return null;return{r:n,g:r,b:i,a}}function parseComponent(e,t){return e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e)}function hue2rgb(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function hslToRGBA(e,t,n,r){let i,a,o;if(t===0)i=a=o=n;else{let r=n<.5?n*(1+t):n+t-n*t,s=2*n-r;i=hue2rgb(s,r,e+1/3),a=hue2rgb(s,r,e),o=hue2rgb(s,r,e-1/3)}return{r:i,g:a,b:o,a:r}}const t={r:0,g:0,b:0,a:1},n={r:0,g:0,b:0,a:0};export{t as BLACK,n as TRANSPARENT,parseColor};
1
+ import"./_virtual/_rolldown/runtime.js";const e={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function parseColor(t){if(!t||typeof t!=`string`)return null;let n=t.trim().toLowerCase(),r=e[n];if(r)return parseHex(r);if(n.startsWith(`#`))return parseHex(n);let i=n.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(i)return{r:parseComponent(i[1],255)/255,g:parseComponent(i[2],255)/255,b:parseComponent(i[3],255)/255,a:i[4]===void 0?1:parseComponent(i[4],1)};let a=n.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(a){let e=parseFloat(a[1]),t=parseFloat(a[2]),n=a[3]===`%`,r=parseFloat(a[4]),i=a[5]===`%`,o=a[6]===void 0?1:parseComponent(a[6],1);return e>1&&(e/=360),(n||t>1)&&(t/=100),(i||r>1)&&(r/=100),hslToRGBA(e,t,r,Math.max(0,Math.min(1,o)))}return null}function parseHex(e){let t=e.slice(1),n,r,i,a=1;if(t.length===3)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255;else if(t.length===4)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255,a=parseInt(t[3]+t[3],16)/255;else if(t.length===6)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255;else if(t.length===8)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255,a=parseInt(t.slice(6,8),16)/255;else return null;return{r:n,g:r,b:i,a}}function parseComponent(e,t){return e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e)}function hue2rgb(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}function hslToRGBA(e,t,n,r){let i,a,o;if(t===0)i=a=o=n;else{let r=n<.5?n*(1+t):n+t-n*t,s=2*n-r;i=hue2rgb(s,r,e+1/3),a=hue2rgb(s,r,e),o=hue2rgb(s,r,e-1/3)}return{r:i,g:a,b:o,a:r}}const t={r:0,g:0,b:0,a:1},n={r:0,g:0,b:0,a:0};export{t as BLACK,n as TRANSPARENT,parseColor};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function isPixbufImageSource(e){return typeof e!=`object`||!e?!1:typeof e.isPixbuf==`function`&&e.isPixbuf()}function isCanvasImageSource(e){return typeof e!=`object`||!e?!1:typeof e.getContext==`function`}export{isCanvasImageSource,isPixbufImageSource};
@@ -1 +1 @@
1
- var OurImageData=class{constructor(e,t,n){if(this.colorSpace=`srgb`,typeof e==`number`)this.width=e,this.height=t,this.data=new Uint8ClampedArray(this.width*this.height*4);else if(this.data=e,this.width=t,this.height=n??this.data.length/(4*this.width),this.data.length!==this.width*this.height*4)throw RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`)}};export{OurImageData};
1
+ import"./_virtual/_rolldown/runtime.js";var OurImageData=class{constructor(e,t,n){if(this.colorSpace=`srgb`,typeof e==`number`)this.width=e,this.height=t,this.data=new Uint8ClampedArray(this.width*this.height*4);else if(this.data=e,this.width=t,this.height=n??this.data.length/(4*this.width),this.data.length!==this.width*this.height*4)throw RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`)}};export{OurImageData};
@@ -0,0 +1,20 @@
1
+ import type Cairo from 'cairo';
2
+ /**
3
+ * The `setExtend` / `setFilter` slice that exists at runtime on every
4
+ * `cairo_pattern_t` but is missing from the GIR types. Combined with
5
+ * `Cairo.Pattern` to give us a fully-typed view.
6
+ */
7
+ export interface CairoPatternRuntime {
8
+ setExtend(extend: Cairo.Extend): void;
9
+ getExtend(): Cairo.Extend;
10
+ setFilter(filter: Cairo.Filter): void;
11
+ getFilter(): Cairo.Filter;
12
+ }
13
+ /** A `Cairo.Pattern` augmented with the runtime methods documented above. */
14
+ export type CairoPattern = Cairo.Pattern & CairoPatternRuntime;
15
+ /**
16
+ * Narrow a `Cairo.Pattern` returned by the GIR API to the augmented type.
17
+ * Returns `null` if the input is missing the runtime methods (e.g. a future
18
+ * Cairo binding that reshapes the API).
19
+ */
20
+ export declare function asCairoPattern(pat: Cairo.Pattern | undefined | null): CairoPattern | null;
@@ -6,7 +6,7 @@ export declare class CanvasPattern {
6
6
  private _pattern;
7
7
  private constructor();
8
8
  /** Create a CanvasPattern from a supported image source. Returns null if unsupported. */
9
- static create(image: any, repetition: string | null): CanvasPattern | null;
9
+ static create(image: unknown, repetition: string | null): CanvasPattern | null;
10
10
  /** @internal Get the underlying Cairo pattern for rendering. */
11
11
  _getCairoPattern(): Cairo.SurfacePattern;
12
12
  }
@@ -1,18 +1,30 @@
1
1
  import Cairo from 'cairo';
2
+ import { type CanvasLike } from './dom-types.js';
2
3
  import { Path2D } from './canvas-path.js';
4
+ /**
5
+ * Options bag passed through the `getContext('2d', options)` factory. Mirrors
6
+ * the WHATWG `CanvasRenderingContext2DSettings` dictionary; fields are
7
+ * accepted but not yet honored by this implementation.
8
+ */
9
+ export interface CanvasRenderingContext2DInit {
10
+ alpha?: boolean;
11
+ desynchronized?: boolean;
12
+ colorSpace?: PredefinedColorSpace;
13
+ willReadFrequently?: boolean;
14
+ }
3
15
  /**
4
16
  * CanvasRenderingContext2D backed by Cairo.ImageSurface.
5
17
  * Implements the Canvas 2D API for GJS.
6
18
  */
7
19
  export declare class CanvasRenderingContext2D {
8
- readonly canvas: any;
20
+ readonly canvas: CanvasLike;
9
21
  private _surface;
10
22
  private _ctx;
11
23
  private _state;
12
24
  private _stateStack;
13
25
  private _surfaceWidth;
14
26
  private _surfaceHeight;
15
- constructor(canvas: any, _options?: any);
27
+ constructor(canvas: CanvasLike, _options?: CanvasRenderingContext2DInit);
16
28
  /** Ensure the surface matches the current canvas dimensions. Recreate if resized. */
17
29
  private _ensureSurface;
18
30
  /** Reset drawing state to defaults (called when canvas dimensions are explicitly reset). */
@@ -150,14 +162,14 @@ export declare class CanvasRenderingContext2D {
150
162
  isPointInStroke(path: Path2D, x: number, y: number): boolean;
151
163
  createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
152
164
  createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
153
- createPattern(image: any, repetition: string | null): CanvasPattern | null;
165
+ createPattern(image: unknown, repetition: string | null): CanvasPattern | null;
154
166
  createImageData(sw: number, sh: number): ImageData;
155
167
  createImageData(imagedata: ImageData): ImageData;
156
168
  getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
157
169
  putImageData(imageData: ImageData, dx: number, dy: number, dirtyX?: number, dirtyY?: number, dirtyWidth?: number, dirtyHeight?: number): void;
158
- drawImage(image: any, dx: number, dy: number): void;
159
- drawImage(image: any, dx: number, dy: number, dw: number, dh: number): void;
160
- drawImage(image: any, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
170
+ drawImage(image: unknown, dx: number, dy: number): void;
171
+ drawImage(image: unknown, dx: number, dy: number, dw: number, dh: number): void;
172
+ drawImage(image: unknown, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
161
173
  private _getDrawImageSource;
162
174
  /** Create a PangoCairo layout configured with current font/text settings. */
163
175
  private _createTextLayout;
@@ -0,0 +1,88 @@
1
+ import type Cairo from 'cairo';
2
+ import type GdkPixbuf from 'gi://GdkPixbuf';
3
+ /**
4
+ * The HTMLCanvasElement-shaped object passed into the
5
+ * `CanvasRenderingContext2D` constructor by the registered context factory.
6
+ *
7
+ * `@gjsify/dom-elements`' `HTMLCanvasElement` satisfies this — but so does any
8
+ * lightweight `{ width, height }` mock used by unit tests. Width/height
9
+ * default to the WHATWG canvas defaults (300×150) when missing.
10
+ */
11
+ export interface CanvasLike {
12
+ width?: number;
13
+ height?: number;
14
+ }
15
+ /**
16
+ * GdkPixbuf-backed image source produced by `@gjsify/dom-elements`'
17
+ * `HTMLImageElement` (and other pixbuf-bearing wrappers).
18
+ *
19
+ * The `isPixbuf()` brand keeps us decoupled from the concrete class while
20
+ * preventing accidental matches against unrelated objects.
21
+ */
22
+ export interface PixbufImageSource {
23
+ isPixbuf(): boolean;
24
+ /** @internal — populated by HTMLImageElement once decoding completes. */
25
+ _pixbuf: GdkPixbuf.Pixbuf;
26
+ }
27
+ /**
28
+ * Canvas-like image source carrying a 2D context whose backing surface can be
29
+ * sampled (used for `drawImage(canvas, …)` and `createPattern(canvas, …)`).
30
+ */
31
+ export interface CanvasImageSource extends CanvasLike {
32
+ getContext(contextId: '2d', options?: unknown): CanvasContext2DLike | null;
33
+ getContext(contextId: string, options?: unknown): unknown;
34
+ }
35
+ /**
36
+ * The minimal slice of `CanvasRenderingContext2D` required to extract pixel
37
+ * data for `drawImage` / `createPattern`. Our own context naturally satisfies
38
+ * this through `_getSurface()`.
39
+ */
40
+ export interface CanvasContext2DLike {
41
+ /** @internal — exposes the Cairo backing surface. */
42
+ _getSurface?(): Cairo.ImageSurface;
43
+ }
44
+ /** Type guard for {@link PixbufImageSource}. */
45
+ export declare function isPixbufImageSource(value: unknown): value is PixbufImageSource;
46
+ /** Type guard for {@link CanvasImageSource}. */
47
+ export declare function isCanvasImageSource(value: unknown): value is CanvasImageSource;
48
+ /**
49
+ * Minimal `DOMMatrix` shape returned by `CanvasRenderingContext2D.getTransform()`
50
+ * when no native `DOMMatrix` constructor is registered. Mirrors the
51
+ * `is2D`-only subset of the WHATWG matrix interface.
52
+ */
53
+ export interface DOMMatrix2DLike {
54
+ a: number;
55
+ b: number;
56
+ c: number;
57
+ d: number;
58
+ e: number;
59
+ f: number;
60
+ m11: number;
61
+ m12: number;
62
+ m13: number;
63
+ m14: number;
64
+ m21: number;
65
+ m22: number;
66
+ m23: number;
67
+ m24: number;
68
+ m31: number;
69
+ m32: number;
70
+ m33: number;
71
+ m34: number;
72
+ m41: number;
73
+ m42: number;
74
+ m43: number;
75
+ m44: number;
76
+ is2D: boolean;
77
+ isIdentity: boolean;
78
+ }
79
+ /**
80
+ * Constructor signature for the platform `DOMMatrix`. Lets us reach the
81
+ * runtime constructor through `globalThis` without an `any` cast when an
82
+ * embedder (e.g. `@gjsify/dom-elements`) has registered one.
83
+ */
84
+ export type DOMMatrixConstructor = new (init?: number[] | string) => DOMMatrix;
85
+ /** Subset of `globalThis` we touch inside this package. */
86
+ export interface CanvasGlobalThis {
87
+ DOMMatrix?: DOMMatrixConstructor;
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/canvas2d-core",
3
- "version": "0.3.21",
3
+ "version": "0.4.0",
4
4
  "description": "Cairo-backed Canvas 2D core (CanvasRenderingContext2D, Path2D, ImageData) — no GTK dependency",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -31,17 +31,17 @@
31
31
  "offscreen"
32
32
  ],
33
33
  "dependencies": {
34
- "@girs/gdk-4.0": "4.0.0-4.0.0-rc.14",
35
- "@girs/gdkpixbuf-2.0": "2.0.0-4.0.0-rc.14",
36
- "@girs/gjs": "4.0.0-rc.14",
37
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
38
- "@girs/gobject-2.0": "2.88.0-4.0.0-rc.14",
39
- "@girs/pango-1.0": "1.57.1-4.0.0-rc.14",
40
- "@girs/pangocairo-1.0": "1.0.0-4.0.0-rc.14"
34
+ "@girs/gdk-4.0": "4.0.0-4.0.0-rc.15",
35
+ "@girs/gdkpixbuf-2.0": "2.0.0-4.0.0-rc.15",
36
+ "@girs/gjs": "4.0.0-rc.15",
37
+ "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
38
+ "@girs/gobject-2.0": "2.88.0-4.0.0-rc.15",
39
+ "@girs/pango-1.0": "1.57.1-4.0.0-rc.15",
40
+ "@girs/pangocairo-1.0": "1.0.0-4.0.0-rc.15"
41
41
  },
42
42
  "devDependencies": {
43
- "@gjsify/cli": "^0.3.21",
44
- "@gjsify/unit": "^0.3.21",
43
+ "@gjsify/cli": "^0.4.0",
44
+ "@gjsify/unit": "^0.4.0",
45
45
  "@types/node": "^25.6.2",
46
46
  "typescript": "^6.0.3"
47
47
  }
@@ -0,0 +1,44 @@
1
+ // Local typed shape for Cairo objects whose runtime methods are missing from
2
+ // the GIR-generated `@girs/cairo-1.0` / `@girs/gjs/cairo` typings.
3
+ //
4
+ // `setExtend()` and `setFilter()` exist at runtime on every Cairo pattern but
5
+ // are absent from the .d.ts (the GIR generator emits an empty `class Pattern`
6
+ // for "Foreign Struct" types). Rather than reach for `(pat as any).setFilter`
7
+ // at every call site, we declare a thin interface here and narrow the
8
+ // `Cairo.Pattern` returned by `Cairo.Context.getSource()` through a single
9
+ // helper.
10
+ //
11
+ // Reference: https://www.cairographics.org/manual/cairo-cairo-pattern-t.html
12
+ //
13
+ // This is a pure type-level construct; runtime behavior is unchanged.
14
+
15
+ import type Cairo from 'cairo';
16
+
17
+ /**
18
+ * The `setExtend` / `setFilter` slice that exists at runtime on every
19
+ * `cairo_pattern_t` but is missing from the GIR types. Combined with
20
+ * `Cairo.Pattern` to give us a fully-typed view.
21
+ */
22
+ export interface CairoPatternRuntime {
23
+ setExtend(extend: Cairo.Extend): void;
24
+ getExtend(): Cairo.Extend;
25
+ setFilter(filter: Cairo.Filter): void;
26
+ getFilter(): Cairo.Filter;
27
+ }
28
+
29
+ /** A `Cairo.Pattern` augmented with the runtime methods documented above. */
30
+ export type CairoPattern = Cairo.Pattern & CairoPatternRuntime;
31
+
32
+ /**
33
+ * Narrow a `Cairo.Pattern` returned by the GIR API to the augmented type.
34
+ * Returns `null` if the input is missing the runtime methods (e.g. a future
35
+ * Cairo binding that reshapes the API).
36
+ */
37
+ export function asCairoPattern(pat: Cairo.Pattern | undefined | null): CairoPattern | null {
38
+ if (!pat) return null;
39
+ const candidate = pat as CairoPattern;
40
+ if (typeof candidate.setFilter !== 'function' || typeof candidate.setExtend !== 'function') {
41
+ return null;
42
+ }
43
+ return candidate;
44
+ }
@@ -4,18 +4,27 @@
4
4
  import Cairo from 'cairo';
5
5
  import Gdk from 'gi://Gdk?version=4.0';
6
6
 
7
+ import { asCairoPattern, type CairoPattern } from './cairo-types.js';
8
+ import { isPixbufImageSource, isCanvasImageSource } from './dom-types.js';
9
+
7
10
  /**
8
11
  * CanvasPattern wrapping a Cairo SurfacePattern.
9
12
  */
10
13
  export class CanvasPattern {
11
- private _pattern: Cairo.SurfacePattern;
14
+ private _pattern: CairoPattern;
12
15
 
13
16
  private constructor(surface: Cairo.ImageSurface, repetition: string | null) {
14
- this._pattern = new Cairo.SurfacePattern(surface);
17
+ const raw = new Cairo.SurfacePattern(surface);
18
+ // setExtend is missing from the GIR types; asCairoPattern narrows.
19
+ const pat = asCairoPattern(raw);
20
+ if (!pat) {
21
+ throw new TypeError(
22
+ 'CanvasPattern: cairo SurfacePattern is missing setExtend at runtime — incompatible Cairo binding',
23
+ );
24
+ }
25
+ this._pattern = pat;
15
26
 
16
27
  // Set extend mode based on repetition
17
- // setExtend exists at runtime on SurfacePattern but is missing from GIR types
18
- const pat = this._pattern as any;
19
28
  switch (repetition) {
20
29
  case 'repeat':
21
30
  case '':
@@ -34,26 +43,26 @@ export class CanvasPattern {
34
43
  }
35
44
 
36
45
  /** Create a CanvasPattern from a supported image source. Returns null if unsupported. */
37
- static create(image: any, repetition: string | null): CanvasPattern | null {
46
+ static create(image: unknown, repetition: string | null): CanvasPattern | null {
38
47
  // HTMLImageElement (GdkPixbuf-backed)
39
- if ('isPixbuf' in image && typeof (image as any).isPixbuf === 'function' && (image as any).isPixbuf()) {
40
- const pixbuf = (image as any)._pixbuf as import('@girs/gdkpixbuf-2.0').default.Pixbuf;
48
+ if (isPixbufImageSource(image)) {
49
+ const pixbuf = image._pixbuf;
41
50
  // Create a Cairo surface from the pixbuf
42
51
  const w = pixbuf.get_width();
43
52
  const h = pixbuf.get_height();
44
53
  const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
45
54
  const ctx = new Cairo.Context(surface);
46
- Gdk.cairo_set_source_pixbuf(ctx as any, pixbuf, 0, 0);
55
+ Gdk.cairo_set_source_pixbuf(ctx, pixbuf, 0, 0);
47
56
  ctx.paint();
48
57
  ctx.$dispose();
49
58
  return new CanvasPattern(surface, repetition);
50
59
  }
51
60
 
52
61
  // HTMLCanvasElement with a 2D context
53
- if (typeof image?.getContext === 'function') {
62
+ if (isCanvasImageSource(image)) {
54
63
  const ctx2d = image.getContext('2d');
55
64
  if (ctx2d && typeof ctx2d._getSurface === 'function') {
56
- const sourceSurface = ctx2d._getSurface() as Cairo.ImageSurface;
65
+ const sourceSurface = ctx2d._getSurface();
57
66
  const w = sourceSurface.getWidth();
58
67
  const h = sourceSurface.getHeight();
59
68
  const surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
@@ -70,6 +79,6 @@ export class CanvasPattern {
70
79
 
71
80
  /** @internal Get the underlying Cairo pattern for rendering. */
72
81
  _getCairoPattern(): Cairo.SurfacePattern {
73
- return this._pattern;
82
+ return this._pattern as unknown as Cairo.SurfacePattern;
74
83
  }
75
84
  }