• Stars
    star
    120
  • Rank 295,983 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Standalone in-browser editor for CSS Shapes.

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!

More Repositories

1

Snap.svg

The JavaScript library for modern SVG graphics.
JavaScript
13,954
star
2

dropcap.js

Beautiful CSS drop caps made easy
HTML
929
star
3

eve

Custom events…
JavaScript
316
star
4

css-shapes-polyfill

Polyfill for the CSS Shapes Specification
JavaScript
303
star
5

css-regions-polyfill

Experimental CSS Regions polyfill written in JavaScript
JavaScript
159
star
6

Demo-for-Alice-s-Adventures-in-Wonderland

Demo of CSS Shapes using the Alice in Wonderland story.
CSS
149
star
7

Demo-for-National-Geographic-Forest-Giant

A prototypical adaptation of the National Geographic article "Forest Giants" using Adobe's contributions to WebKit.
JavaScript
135
star
8

dr.js

Tiny documentation builder
JavaScript
114
star
9

shaderdsl

A compiler from a subset of JavaScript to GLSL.
JavaScript
97
star
10

brackets-css-shapes-editor

CSS Shapes Editor extension for Brackets / Adobe Edge Code
JavaScript
94
star
11

custom-filters-demo-travel-app

An app that explores the use of custom filters to create UI enhancements
JavaScript
55
star
12

iframeflow.js

A Javascript helper for cross-browser CSS Regions support
JavaScript
41
star
13

coding-guidelines

JavaScript
28
star
14

Demo-for-PBS-Kids-Word-Girl

Digital comic book adaptation using Photoshop Generator
JavaScript
21
star
15

Demo-for-Food-Network-Cupcakes

Demo using Food Network content to showcase Web Engine features
JavaScript
21
star
16

Demo-for-National-Geographic-Orphan-Elephants

A prototypical adaptation of the National Geographic article "Orphan Elephants" showcasing Regions in use with Viewport Units.
JavaScript
15
star
17

html5devconf-2013

Slides from @adobe-webplatform team presented at HTML5 Dev Conf.
CSS
14
star
18

road-trip

“Road Trip” CSS Regions Demo
JavaScript
7
star
19

exclusionsrecipe

Demo of exclusions for mobile.
CSS
7
star
20

regions-adaptive

Demo of an adaptive web app UI built with CSS Regions
6
star
21

transform-tests

2
star