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

docs: erasing demo #306

Merged
merged 18 commits into from
Jun 19, 2021
Merged

docs: erasing demo #306

merged 18 commits into from
Jun 19, 2021

Conversation

ShaMan123
Copy link
Contributor

@ShaMan123 ShaMan123 commented May 28, 2021

Adding DEMO for erasing

https://codepen.io/shaman123/pen/MWpEarw?editors=1010

For the codepen to work in the website the fabric build must include erasing.
I have no idea how to do that.

ShaMan123 added 3 commits May 28, 2021 07:58
for this to work the codepen needs to use a fabric build that has `erasing` option included
@ShaMan123 ShaMan123 changed the title docs(fabric.EraserBrush) docs: erasing demo May 28, 2021
@asturur
Copy link
Member

asturur commented Jun 6, 2021

hi @ShaMan123 thanks for starting this.
So to have it running with the build you can simple add the file from the CDN in your codepen, i think we need to change this file a bit:
https://github.com/fabricjs/fabricjs.com/blob/gh-pages/_includes/codepen.html
in order to have fabricjs file unshifted to the list of scripts rather than pushed on top of it.
So that fabricJS is the first one loaded.

Here there is an explanation of how you can add an extra script to the codepen:

https://blog.codepen.io/documentation/prefill-embeds/

<div 
  class="codepen" 
  data-prefill='{
    "title": "React Basics Demo",
    "description": "Shows how to use React and React DOM to render a module with props onto the page",
    "tags": ["react", "react-docs-demo"],
    "html_classes": ["loading", "no-js"],
    "head": "&lt;meta name=&#x27;viewport&#x27; content=&#x27;width=device-width, initial-scale=1&#x27;&gt;",
    "stylesheets": "https://unpkg.com/[email protected]/normalize.css",
    "scripts": ["https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js", "https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"]
  }'
  style="height: 400px; overflow: auto;"
  data-height="400" 
  data-theme-id="31205"
  data-default-tab="js,result" 
  data-editable="true"     
>

We should find the eraser file here:

https://unpkg.com/[email protected]/src/mixins/eraser_brush.mixin.js

@asturur
Copy link
Member

asturur commented Jun 6, 2021

Demo looks nice so far!

@ShaMan123
Copy link
Contributor Author

DONE

@asturur
Copy link
Member

asturur commented Jun 6, 2021 via email

@ShaMan123
Copy link
Contributor Author

ShaMan123 commented Jun 6, 2021

What if the cdn will point to a file that appends scripts from the cdn?

const include=querySearchParams.get('include').split(',')
if(include.indexOf('erasing') {
    const script=docuemnt.createElement('script');
    script.src='https://unpkg.com/fabric@latest/src/mixins/eraser_brush.mixin.js'
   document.head.apprend(script)
}

This is in essence a dynamic custom build

@ShaMan123
Copy link
Contributor Author

This can work with npm as well, using resolve and baseUrl

const include=querySearchParams.get('include').split(',')  // this will need a different approach for node
const baseUrl = ENV==='node'? require.resolve('fabric') : 'https://unpkg.com/fabric@latest';
scripts = [];
if(include.indexOf('erasing') {
   scripts.push(path.resolve(baseUrl,'/src/mixins/eraser_brush.mixin.js'))
}
scripts.map(path => {
if(ENV === 'node') {
    require(path);
  } else {
    const script=docuemnt.createElement('script');
    script.src= path;
    document.head.apprend(script)
  }
});

@asturur
Copy link
Member

asturur commented Jun 19, 2021

Hi @ShaMan123 sorry if i m being so late on this. I have not been able to do much lately.

@asturur
Copy link
Member

asturur commented Jun 19, 2021

i ll merge it now, if then there is something to fix, we can fix it after.

@asturur asturur merged commit bb5e1ae into fabricjs:gh-pages Jun 19, 2021
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.

2 participants