GithubHelp home page GithubHelp logo

css-doodle / css-doodle Goto Github PK

View Code? Open in Web Editor NEW
5.5K 50.0 206.0 2.96 MB

🎨 A web component for drawing patterns with CSS.

Home Page: https://css-doodle.com

License: MIT License

JavaScript 99.93% Makefile 0.07%
css patterns web-component css-doodle generative-art creative-coding generative

css-doodle's Introduction

<css-doodle />

Build Status license

A web component for drawing patterns with CSS.

screenshot

Example

<css-doodle>
  @grid: 5 / 200px;
  background: @p(#000, #fff);
  margin: 1px;
</css-doodle>

Docs

https://css-doodle.com

Design tools

  • Tabbied -- Doodle with generated patterns
  • Shapes -- Discover new CSS polygon shapes
  • SVG playground -- Generate SVG code with new syntax

Resources

Build

# build css-doodle.js
npm run build

# generate css-doodle.min.js
npm run minify

# or just use make
make

Support

Thank you for your support! 🙏

css-doodle's People

Contributors

akira-cn avatar fdrobidoux avatar limonte avatar moonou avatar plasmatium avatar yuanchuan avatar zwtkito avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css-doodle's Issues

Example for :doodle doesn't work

Hi, The first example for :doodle didn't work for me https://css-doodle.com/#selector-:doodle

https://codepen.io/zemian/pen/wvdjrMM

:doodle { --s: 0 }
:doodle(:hover) { --s: 1 }

transition: .5s cubic-bezier(.175, .885, .32, 1.275);
transition-delay: @rand(500ms);
transform: translateY(calc(var(--s) * 100%));

But if I add some setup like this, it worked:

  :doodle { @grid: 5 / 8em; grid-gap: 1px; }
  background: #60569e;
  
  :doodle { --s: 0 }
  :doodle(:hover) { --s: 1 }

  transition: .5s cubic-bezier(.175, .885, .32, 1.275);
  transition-delay: @rand(500ms);
  transform: translateY(calc(var(--s) * 100%));

Does it work with Canvas?

Specifically, I want to know if it can work with Konva JS (or react-konva)

If not, is there any way to do it?

Brilliant work 👏

not working in nextjs

Compile Error on server-side

Server Error
ReferenceError: document is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Read custom properties

Example

<css-doodle>
  --colors: red, blue, green;

  /* Suppose there's @get() */
  color: @pick(@get(--colors));

   /* or better? */
  colors: @pick(--colors);
</css-doodle>

Function name

Need to introduce a new function name since @var has been taken already.

Related

#33, #30

@grid: 1 with the JS Api fails

Hi,

First of all, thanks for a great and very interesting lib!

I can't seem to get the grid to render when setting @grid to 1. I've tried all different combinations but nothing works until i change it to at least 2, or even 2x1.

The problem only seems to occur when using the JS Api to initialize and update the doodle.
If i place my doodle definition within the element, everything works as expected.

Would be grateful for a fix or workaround. Thanks!

Bug Report: `@p` custom properties in `@doodle`

<css-doodle>
  <style>
    :doodle {
      @grid: 2x1;
      --colors: #000, #fff;
    }
    background: @doodle(
      @grid: 2 / 100%;
      --c-1: @p(--colors);
    );
  </style>
</css-doodle>

What is expected?

--c-1 is one of #000, #fff

What is actually happening?

only first cell is right, --c-1 is --colors in others.

image

image

Extend @place-cell

Add left right top bottom keywords

@place-cell: left top
@place-cell: right center;

Idea: Bridge with custom properties

The problem

Currently there is no way to share code between multiple css-doodle elements. So that it's impossible to define rules in one place.

One possible solution

Inspired by the CSS Houdini, the rules can be put into variables inside normal styles.

css-doodle {
  --rule: (
     color: @pick(red, blue);
  );
}

Yes that's a valid variable expression! So with that inside css-doodle element:

<css-doodle>
  @use: var(--rule);

  /* can easily be rewritten */
  color: green;
</css-doodle>

Is it possible to @repeat a @stripe?

How do we repeat a diagonal linear-gradient using this example?

background-image: linear-gradient(45deg, @stripe(#ffffff, var(--transparent)));

This would be the long-hand css:

--transparent: rgba(255,255,255,0);
--stripes: linear-gradient(45deg, var(--transparent) 25%, #ffffff 25%, #ffffff 50%, var(--transparent) 50%, var(--transparent) 75%, #ffffff 75%, #ffffff 100%);

background-image: var(--stripes);
background-size: 10px 10px;

Port to React

Current workaround:

It's not the best way, but if you want to use css-doodle in React you could try the following:

/* doodle.js */

import React from 'react';
import 'css-doodle';

export default ({ rule = '' }) => (
  <css-doodle>{ rule }</css-doodle>
)
/* example.js */

import Doodle from './doodle';

<Doodle rule={`
  :doodle {
    @grid: 2 / 200px;
    grid-gap: 1px;
  }
  background: @pick(red, pink);
`}/>

Better way:

Just use it directly!

import 'css-doodle';

function App() {
  return (
    <css-doodle>{`
      :doodle {
        @grid: 2 / 200px;
        grid: 1px;
      }
      background: @pick(red, pink);
    `}</css-doodle>
  );
}

Prettier incorrectly formats css

I tested this in vue:

<template>
    <css-doodle use="var(--rule)"></css-doodle>
</template>
<script>
import "css-doodle";
export default {};
</script>
<style scoped>
css-doodle {
    --rule: (
      :doodle {
        @grid: 10x1 / 800px 600px; 
        background: #e5e5e5;
      }
    );
}
</style>

it renders good (in this case, just a grey background)

but when i format the code using prettier, the css part becomes the following

<style scoped>
css-doodle {
    --rule: (: doodle {@grid: 10x1 / 800px 600px; background: #e5e5e5;});
}
</style>

as you can see, there is a space between : and doodle, which breaks the code, it seems Prettier can not recognise the custom pseudo element/selector

Consider writing tests

Congrats! AFAIK this is the first Web component in GitHub trending JS repos! 👏 👏 👏

css-doodle is sexy but absolutely not suitable for production use since there are 0 tests.

Consider moving css-doodle on the next level, read/watch a tutorial on how to set up tests, e.g. https://www.youtube.com/watch?v=7r4xVDI2vho and start writing tests :)

Without tests, nobody in their right mind would use it.

From https://engineering.videoblocks.com/these-four-clean-code-tips-will-dramatically-improve-your-engineering-teams-productivity-b5bd121dd150

If it isn’t tested, it’s broken

doodle中,:after/:before的content中无法使用自定义属性

直接在css-doodle中写如下句法:

:before{
     content:var(--bar-value-string);
}

似乎是并不能有效果的,因为doodle会给这段代码加上:nth-type-of的伪类,然后变成这样:

.cell:nth-type-of(1):before{
     content:var(--bar-value-string);//伪类直接没了,就像没有content一样
}

但是,直接接在一般选择器后,这种写法是可行的,,例如:
.cell:before{
content:var(--bar-value-string);//成功执行
}
这一问题依旧是我在写这个实验的时候发现的:
https://codepen.io/FOXhushiyu/pen/Eewrjq
当时自己试着注入了一段css,就可以在content里用自定义属性值了。。
当然,,与其用这种方法,或许提供更加符合doodle**的方式,或许更加贴切一些也说不定。
------------------------------------------后面是一些闲话-------------------------------------------------
挺喜欢这个框架(我个人觉得可以叫框架了,感觉已经改变了我的开发思维)的,,最近在尝试用doodle实现各种基础的图表(柱图、饼图、折线图、热力图等等),虽然你的示例是拿来做图案的,但是看到这个框架第一眼就觉得,这是个做图表非常强力的工具,shadow dom完美解决了样式污染的可能,上手之快令人咂舌,而且不需要学canvas、svg(即使学了也没有直接css这么直观)。之前也用过echart和hightchart,如果用doodle做图表,有一个特别大的优势就是,可以直接用css修改样式(svg制图虽然也可以上css改一些东西,但是讲道理不够),这样,一个制作完成的图表,后期接手者不需要进行太多学习(学doodle真的很快,玩一下午就能入门)
加油!

Add parent div around each cell

It would be nice if each cell div had a wrapping parent div with class "cell-wrap". Use case would be to apply a filter: drop-shadow() to a cell div that has a clip-path by targeting the parent "cell-wrap" selector.

Can't unfold @multiple() or @repeat() in @pick()

Say an unusual use case:

 background: @pick-n(blue, @multiple(3, red));

Then we get one like:

background: red, red, red;

I don't know it's a bug or feature request or simply I used it in a wrong way.

Idea: @content

Insert new elements.

/* text node */
@content: 'some text';  

/* svg */
@content: @svg(

);

/* new doodle element */
@content: @doodle(

);

repeating animations | question

hello

I wonder is it possible, and how - to animate - not just upon click or mousehover,
but animate effects to repeat certain number of times, like 4 or 5,
but also, infinite number of times (constantly)

I'm especially interested in animating each of 3 elements on the right in this pen:

https://codepen.io/yuanchuan/pen/zpvQvV

Distribute as JS modules

It seems like css-doodle.js is packaged as UMD. While this is a good idea for a long time, I think the utility has passed, since all current browsers support modules (and web components!) natively. Bundlers support module format as input also.

Without being a JS module, there's no way to get the export CSSDoodle class except though a global. If css-doodle.js was a module, it could just be imported:

import {CSSDoodle} from 'css-doodle';

// Maybe someone would extend it:
export class MyCSSDoodle extends CSSDoodle {}

Grid attribute with @size does not work

The 2nd example in the "grid" attribute (https://css-doodle.com/#attribute-grid) does not work. It seems like the @size is not taking effect. If I replace with width: 8em; height: 8em; then it will work. Is this a bug?

See a pen here: https://codepen.io/zemian/pen/rNmvzRz

<css-doodle grid="1x35">
  :doodle {
    grid-row-gap: 1px;
    @size: 8em; /* width: 8em; height: 8em; */
  }
  background: #60569e;
  width: @rand(5%, 100%); /* from 5% to 100% by random */
</css-doodle>

Performance concerns.

First off, I'd like to say that this is awesome. I can see the usage for it, and will very most likely be using it for the design of my wordpress dev blog.

And while the project is still sorta-early, I was looking at how it rendered, and noticed it creates a lot of <div> elements with inline style strings, within a container div. That's a pretty neat solution in order to make it compatible with as many browsers as possible and all that fun stuff.

However, I'm more concerned by how the shadow-dom's CSS is generated :

.cell:nth-of-type(1) {
     background: #60569e;
     width: 80%;
     height: 80%;
     --internal-cell-width: 80%;
     --internal-cell-height: 80%;
     background: #60569e;
     width: 80%;
     height: 80%;
     --internal-cell-width: 80%;
     --internal-cell-height: 80%;
}
 .cell:nth-of-type(2) {
     background: #60569e;
     width: 80%;
     height: 80%;
     --internal-cell-width: 80%;
     --internal-cell-height: 80%;
     transform: rotate(45deg);
}
 .cell:nth-of-type(3) {
     background: #60569e;
     width: 80%;
     height: 80%;
     --internal-cell-width: 80%;
     --internal-cell-height: 80%;
}
.cell:nth-of-type(4) {
     /* etc. */
}

This is from using a simple @even formula, which I expected to generate instead like so :

.cell {
     background: #60569e;
     width: 80%;
     height: 80%;
     --internal-cell-width: 80%;
     --internal-cell-height: 80%;
}
.cell:even {
     transform: rotate(45deg);
}

We both know is best in order to process the whole thing faster... or is it?
Is this due to a limitation in your implementation method? Or is it just not implemented yet? If the latter, I can understand, and I'd gladly help contribute for it.

Thanks, hope I wasn't rude or anything.

Security vulnerability in trim coming from css-doodle

A severe security vulnerability has been found in [email protected]

css-doodle has a dependency on a dead project of markdown-preview that has the issue as one of its dependencies:

─┬ [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   └─┬ [email protected]
│     └─┬ [email protected]
│       └── [email protected]

Example security issue:
https://snyk.io/test/npm/remark-parse/5.0.0

maybe we can insert list data and use it by index 希望能够注入列表数据并依据序列号来获取对应的数据

use js insert list data, just like
希望能使用js注入数据,就像这样
doodle.setListData('bar-value', [1, 2, 3, 4, 5]);
and then in .cell element, I can fetch the appropriate data like this
然后,可以在.cell元素中,直接获取对应的数据
width: var('bar-value'); //this will be 1 , 2 , 3, 4, 5
这意味着,按照index获取对应的数据
that means, the first element get 1, the second get 2
you can see my trial in this place:
https://codepen.io/FOXhushiyu/pen/Eewrjq
嗯。。。上次玩的时候,发现微信里能跑,然后就想如果doodle可以做一些业务上的事情的话,其实是完全可以在生产环境投入使用的,在一些例如微信的webview环境里面,
emmm.... it will be useful, with this, I can create chart with doodle, that means, in some webview environment like wechat, I can use doodle in production but not only play with it.

Keyframes

Animations in css is a little bit of verbose, trying to wrap them around

Custom functions

Example

<css-doodle>
  @function fib: pos => {
    let a = 0, b = 1;
    while (0 < pos--) [a, b] = [b, a + b];
    return a;
  }

  ::after {
    content: @fib(10);
  }
</css-doodle>

Should @at use @at(x,y) instead of @at(y,x)?

Should at use at(x,y) instead of at(y,x)?
I'm personally used to the x coordinate coming before the y in about 95% of cases I've used coordinates, do others agree with this or am I going crazy and y comes before x with coordinates.


Port to Vue.js

I was trying to use css-doodle in combination with Vue.js and tried to use v-model to bind data to specific parts of the doodle (let say the grid), but no luck with it. Vue.js is reactive, but css-doodle is probably not, so if I update data in my app, I need to manually .update() my doodle. So I put a watcher on my data element, but even that it doesn't like.

Over here I made a small test case. It should have drawn more horizontal elements based on the number in the input field (which you can update. You will see it .update()'s once and after that you get a blank canvas.

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.