Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shape): allow node to create plain shape object
- Loading branch information
1 parent
5fb9fc1
commit 58bff6c
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title>DOM node</title> | ||
<style> | ||
html, | ||
body { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
} | ||
|
||
svg { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<svg | ||
height="100" | ||
preserveAspectRatio="xMidYMid meet" | ||
width="100" | ||
viewBox="0 0 100 100" | ||
> | ||
<rect x="10" y="10" width="10" height="10" fill="#E54"></rect> | ||
</svg> | ||
<script src="dist.js"></script> | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { shape, render, timeline, play } from '../../src' | ||
|
||
const el = document.querySelector('rect') | ||
|
||
const square = shape({ el }, { | ||
el, | ||
fill: 'yellow', | ||
transforms: [[ 'offset', 80, 80 ]] | ||
}) | ||
|
||
const animation = timeline(square, { | ||
alternate: true, | ||
duration: 2000, | ||
iterations: Infinity | ||
}) | ||
|
||
render(document.querySelector('svg'), animation) | ||
|
||
play(animation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
import { plainShapeObject } from 'wilderness-dom-node' | ||
import { shape as coreShape } from 'wilderness-core' | ||
|
||
const shape = coreShape | ||
const shape = (...props) => { | ||
return coreShape(...props.map(prop => { | ||
if (prop.el) { | ||
const p = { | ||
...plainShapeObject(prop.el), | ||
...prop | ||
} | ||
|
||
delete p.el | ||
|
||
return p | ||
} | ||
|
||
return prop | ||
})) | ||
} | ||
|
||
export default shape |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters