GithubHelp home page GithubHelp logo

isabella232 / css-shapes-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adobe-webplatform/css-shapes-editor

0.0 0.0 0.0 1.51 MB

Standalone in-browser editor for CSS Shapes.

License: Other

CSS 0.13% JavaScript 97.69% HTML 2.18%

css-shapes-editor's Introduction

CSS Shapes Editor

JavaScript library for interactive editing of CSS Shapes values right in the browser. It works with functional values like polygon(), circle() and ellipse().

Demo

See the demo/ folder for examples.

Basic usage

Load dist/CSSShapesEditor.js into the page:

<script src="dist/CSSShapesEditor.js"></script>

Setup the editor to edit a CSS shape value of an element. An interactive editor for the shape is drawn on top of the element.

var element = document.querySelector('#element');
var shape = window.getComputedStyle(element)['shape-outside'];
var editor = CSSShapesEditor(element, shape);

editor.on('shapechange', function(){
  // update the CSS shape value on the element
  element.style['shape-outside'] = editor.getCSSValue();
})

Supported shape values:

  • polygon()
  • circle()
  • ellipse()

Create a new shape from scratch by passing a shape declaration with no coordinates.

var editor = CSSShapesEditor(element, 'polygon()');

Events

The "ready" event is dispatched after the editor was initialized

editor.on('ready', function(){
  // editor is ready to work with
})

The "shapechange" event is dispatched after the shape was changed in the editor

editor.on('shapechange', function(){
  // update the CSS shape value on the element
  element.style['shape-outside'] = editor.getCSSValue();
})

The "removed" event is dispatched after the editor has been turned off and removed by using editor.remove().

editor.on('removed', function(){
  // editor is gone; do other clean-up
})

API

Get the CSS shape value as a string to use in a stylesheet:

editor.getCSSValue()

Get the CSS shape value as a string with coordinates converted to a specific unit type:

editor.getCSSValue('%')
// supported values: ["px", "in", "cm", "mm", "pt", "pc", "em", "rem", "vw", "vh", "%"]

Programmatically update the shape editor with a new shape value:

editor.update("circle(50% at center)")

Toggle the free-transform editor (scale, move, rotate) for the shape:

editor.toggleFreeTransform();

Turn off editor and remove if from the page. Unsaved changes will be lost.

editor.remove()

Contributing

Your system needs:

Setup dev environment

Install dependencies:

$ npm install

Build

Edit source in the src/ directory. Build with Grunt:

$ grunt build

Build output goes into dist/. Do not edit source in dist/, it gets replaced automatically by the Grunt build process.

Test

Add tests to test/spec/. Run tests with Testem:

$ testem

Testem uses the configuration found in testem.json

License

Apache 2.0. See LICENSE.md

Thanks

The work of many people has contributed, both directly and indirectly, to building the CSS Shapes Editor library:

and many, many others. Thank you!

css-shapes-editor's People

Contributors

lmclister avatar oslego avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.