Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Path2D #2013

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add Path2D #2013

wants to merge 1 commit into from

Conversation

tachibana-shin
Copy link

@tachibana-shin tachibana-shin commented Mar 29, 2022

Thanks for contributing!

  • Have you updated CHANGELOG.md?
    ---> no

thfrei added a commit to thfrei/trilium that referenced this pull request Apr 17, 2022
…llow async getContent()

 * ## Excalidraw and SVG
 * 2022-04-16 - @thfrei
 *
 * Known issues:
 *  - excalidraw-to-svg (node.js) does not render any hand drawn (freedraw) paths. There is an issue with
 *    Path2D object not present in node-canvas library used by jsdom. (See Trilium PR for samples and other issues
 *    in respective library. Link will be added later). Related links:
 *     - Automattic/node-canvas#2013
 *     - https://github.com/google/canvas-5-polyfill
 *     - Automattic/node-canvas#1116
 *     - https://www.npmjs.com/package/path2d-polyfill
 *  - excalidraw-to-svg (node.js) takes quite some time to load an image (1-2s)
 *  - excalidraw-utils (browser) does render freedraw, however NOT freedraw with background
 *
 * Due to this issues, we opt to use **only excalidraw in the frontend**. Upon saving, we will also get the SVG
 * output from the live excalidraw instance. We will save this **SVG side by side the native excalidraw format
 * in the trilium note**.
 *
 * Pro: we will combat bit-rot. Showing the SVG will be very fast, since it is already rendered.
 * Con: The note will get bigger (maybe +30%?), we will generate more bandwith.
 *      (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably
 *       acceptable, as a trade off.)
thfrei added a commit to thfrei/trilium that referenced this pull request Apr 18, 2022
…llow async getContent()

 * ## Excalidraw and SVG
 * 2022-04-16 - @thfrei
 *
 * Known issues:
 *  - excalidraw-to-svg (node.js) does not render any hand drawn (freedraw) paths. There is an issue with
 *    Path2D object not present in node-canvas library used by jsdom. (See Trilium PR for samples and other issues
 *    in respective library. Link will be added later). Related links:
 *     - Automattic/node-canvas#2013
 *     - https://github.com/google/canvas-5-polyfill
 *     - Automattic/node-canvas#1116
 *     - https://www.npmjs.com/package/path2d-polyfill
 *  - excalidraw-to-svg (node.js) takes quite some time to load an image (1-2s)
 *  - excalidraw-utils (browser) does render freedraw, however NOT freedraw with background
 *
 * Due to this issues, we opt to use **only excalidraw in the frontend**. Upon saving, we will also get the SVG
 * output from the live excalidraw instance. We will save this **SVG side by side the native excalidraw format
 * in the trilium note**.
 *
 * Pro: we will combat bit-rot. Showing the SVG will be very fast, since it is already rendered.
 * Con: The note will get bigger (maybe +30%?), we will generate more bandwith.
 *      (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably
 *       acceptable, as a trade off.)
Copy link
Collaborator

@zbjornson zbjornson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start, thanks for working on this! It looks like there's some more work left to make this fully implement the Path2D spec. I pointed a few missing parts out below. Do you want to/have time to work on it?

We have the node-gfx organization where I think the actual Path2D class could live btw. (I'd like to move the DOMMatrix class there also.) I'm happy to work on the C++ changes so that we don't have to shim the context prototype methods like this also.

Surprisingly the web-platform-tests don't seem to really cover Path2D aside from isPointInPath. I was hoping those could save us time writing tests.

}

class Path2D {
segments = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our package.json says we support back to Node v6, which means we can't use class fields unfortunately (12+).

class Path2D {
segments = [];
constructor(path) {
this.addPath(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be guarded with if (path && typeof path === "string" || path instanceof Path2D), and parse the path if it's a string.

constructor(path) {
this.addPath(path);
}
addPath(path) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the transform argument.

this.addPath(path);
}
addPath(path) {
if (path && path instanceof Path2D) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the code to handle this.

addPath(path) {
if (path && path instanceof Path2D) {
} else if (path) {
this.segments = parse(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should append to this's segments instead of replacing them.

@CreativeTechGuy
Copy link

For the record @zbjornson, the majority of code in this PR looks like it's directly from: https://github.com/nilzona/path2d-polyfill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants