WebReflection / WebReflection/linkedom

Adding some emulated canvas support.

Open
#287 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
2.1k
Forks
104
PR merge metrics
No merged PRs in 30d

Description

Hi,

After viewing the Deno 2.0 anoncement video, I tryed to use observablehq's samples in deno Jupyter Notebooks.

some samplkes use canvas, and so do crash.

by implementing some ugly code I can make canvas's dependent code to works, so it's posible to use an EmulatedCanvas2D to make canvas works in linkdom.

the question is: Can a canvas like can be integrated to the project ?

for reference there is a deno Notebooks of plot-mandelbrot-set:

import * as Plot from "npm:@observablehq/plot";
import { document } from "jsr:@ry/jupyter-helper";
import { createCanvas, type EmulatedCanvas2D } from "https://deno.land/x/canvas@v1.4.2/mod.ts";

function mandelbrot(x: number, y: number) {
  for (let n = 0, zr = 0, zi = 0; n < 80; ++n) {
    [zr, zi] = [zr * zr - zi * zi + x, 2 * zr * zi + y];
    if (zr * zr + zi * zi > 4) return n;
  }
}

const old = document.createElement;
document.createElement = (...args: any[]) => {    
    if (args.length === 1 && args[0] === "canvas") {
        let realCanvas: EmulatedCanvas2D | undefined;
        const canvas = {
            height: 200,
            width: 200,
            getContext: (drv: string) => {
                realCanvas = createCanvas(canvas.width, canvas.height);
                return realCanvas.getContext(drv);
            },
            toDataURL: () => {
                return realCanvas?.toDataURL();
            }
        }
        return canvas;
    }
    return old.apply(document, args);
}

Plot.raster({fill: mandelbrot, x1: -2, x2: 1, y1: -1.164, y2: 1.164}).plot({aspectRatio: 1, document})

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at linkedom's document.createElement entry point and review how the issue's EmulatedCanvas2D example supplies canvas elements and contexts. Determine the integration scope and compatibility requirements, then validate that the Observable Plot Mandelbrot notebook can create a canvas and render successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.