From 94702e32133787a1511ff6384c5efa978773b00c Mon Sep 17 00:00:00 2001 From: psicomante <176385+psicomante@users.noreply.github.com> Date: Mon, 9 Dec 2024 19:16:48 +0100 Subject: [PATCH] fix: p5.js@1.7.0+ (zenozeng#254,zenozeng#255,zenozeng#258) --- src/p5.RendererSVG.ts | 3 ++- src/rendering.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/p5.RendererSVG.ts b/src/p5.RendererSVG.ts index 5797109..283e997 100644 --- a/src/p5.RendererSVG.ts +++ b/src/p5.RendererSVG.ts @@ -47,7 +47,8 @@ export default function (p5: P5SVG) { } }) - p5.Renderer2D.call(this, elt, pInstProxy, isMainCanvas) + // fix: p5.js@1.7.0+ (zenozeng#254,zenozeng#255,zenozeng#258) by nkymut + Object.assign(this, p5.Renderer2D.call(this, elt, pInstProxy, isMainCanvas)) this.isSVG = true this.svg = svg diff --git a/src/rendering.ts b/src/rendering.ts index b066edc..ca02fc1 100644 --- a/src/rendering.ts +++ b/src/rendering.ts @@ -6,18 +6,18 @@ export default function (p5: P5SVG) { const _graphics = p5.Graphics p5.Graphics = function (w: number, h: number, renderer: any, pInst: p5SVG) { const isSVG = renderer === constants.SVG - _graphics.apply(this, [w, h, isSVG ? pInst.P2D : renderer, pInst]) + const pg = new _graphics(w, h, isSVG ? pInst.P2D : renderer, pInst) if (isSVG) { // replace with - let c = this._renderer.elt - this._renderer = new p5.RendererSVG(c, this, false) // replace renderer - c = this._renderer.elt - this.elt = c // replace this.elt + const svgRenderer = new p5.RendererSVG(pg.elt, pg, false) + pg._renderer = svgRenderer + pg.elt = svgRenderer.elt + // do default again - this._renderer.resize(w, h) - this._renderer._applyDefaults() + pg._renderer.resize(w, h) + pg._renderer._applyDefaults() } - return this + return pg } p5.Graphics.prototype = _graphics.prototype