Skip to content

Commit

Permalink
Remove @canvas because I barely used it
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchuan committed Dec 18, 2023
1 parent de1e4e3 commit bfccdf5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 87 deletions.
5 changes: 0 additions & 5 deletions src/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,6 @@ const Expose = add_alias({
return value => value;
},

canvas() {
return value => value;
},

pattern() {
return value => value;
},
Expand Down Expand Up @@ -796,7 +792,6 @@ const Expose = add_alias({
'Offset': 'Plot',
'point': 'plot',
'Point': 'Plot',
'paint': 'canvas',
'unicode': 'code'
});

Expand Down
43 changes: 0 additions & 43 deletions src/generator/canvas.js

This file was deleted.

22 changes: 2 additions & 20 deletions src/generator/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class Rules {
this.is_gap_defined = false;
this.coords = [];
this.doodles = {};
this.canvas = {};
this.pattern = {};
this.shaders = {};
this.reset();
Expand All @@ -69,7 +68,6 @@ class Rules {
}
this.coords = [];
this.doodles = {};
this.canvas = {};
this.pattern = {};
this.shaders = {};
this.content = {};
Expand Down Expand Up @@ -145,7 +143,7 @@ class Rules {
}

is_composable(name) {
return ['doodle', 'shaders', 'canvas', 'pattern'].includes(name);
return ['doodle', 'shaders', 'pattern'].includes(name);
}

read_var(value, coords, contextedVariable) {
Expand Down Expand Up @@ -202,8 +200,6 @@ class Rules {
return this.compose_doodle(this.inject_variables(value, coords.count), temp_arg);
case 'shaders':
return this.compose_shaders(value, coords);
case 'canvas':
return this.compose_canvas(value, arg.arguments.slice(1));
case 'pattern':
return this.compose_pattern(value, coords);
}
Expand Down Expand Up @@ -256,17 +252,6 @@ class Rules {
return '${' + id + '}';
}

compose_canvas(code, rest = []) {
let commands = code;
let result = rest.map(group => get_value(group[0])).join(',');
if (result.length) {
commands = code + ',' + result;
}
let id = unique_id('canvas');
this.canvas[id] = { code: commands };
return '${' + id + '}';
}

check_uniforms(name) {
switch (name) {
case 'ut': case 't': this.uniforms.time = true; break;
Expand Down Expand Up @@ -344,8 +329,6 @@ class Rules {
result += this.compose_shaders(value, coords); break;
case 'pattern':
result += this.compose_pattern(value, coords); break;
case 'canvas':
result += this.compose_canvas(value, val.arguments.slice(1)); break;
}
}
} else {
Expand Down Expand Up @@ -487,7 +470,7 @@ class Rules {

let is_image = (
/^(background|background\-image)$/.test(prop) &&
/\$\{(canvas|shader|pattern)/.test(value)
/\$\{(shader|pattern)/.test(value)
);
if (is_image) {
rule += 'background-size: 100% 100%;';
Expand Down Expand Up @@ -813,7 +796,6 @@ class Rules {
random: this.random,
doodles: this.doodles,
shaders: this.shaders,
canvas: this.canvas,
pattern: this.pattern,
uniforms: this.uniforms,
content: this.content,
Expand Down
21 changes: 2 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import parse_shaders from './parser/parse-shaders.js';
import { generate_css } from './generator/css.js';
import { draw_shader } from './generator/shader.js';
import { draw_pattern } from './generator/pattern.js';
import { draw_canvas } from './generator/canvas.js';
import { svg_to_png } from './generator/svg-to-png.js';

import * as Uniforms from './uniforms.js';
Expand Down Expand Up @@ -240,10 +239,6 @@ if (typeof customElements !== 'undefined') {
this.shader_to_image({ shader, cell, id }, fn);
}

canvas_to_image({ code }, fn) {
draw_canvas(code).then(fn);
}

pause() {
this.setAttribute('cssd-paused-animation', true);
for (let animation of this.animations) {
Expand Down Expand Up @@ -327,12 +322,11 @@ if (typeof customElements !== 'undefined') {
this.innerHTML = '';
}

replace({ doodles, shaders, canvas, pattern }) {
replace({ doodles, shaders, pattern }) {
let doodle_ids = Object.keys(doodles);
let shader_ids = Object.keys(shaders);
let canvas_ids = Object.keys(canvas);
let pattern_ids = Object.keys(pattern);
let length = doodle_ids.length + canvas_ids.length + shader_ids.length + pattern_ids.length;
let length = doodle_ids.length + shader_ids.length + pattern_ids.length;
return input => {
if (!length) {
return Promise.resolve(input);
Expand All @@ -357,15 +351,6 @@ if (typeof customElements !== 'undefined') {
return Promise.resolve('');
}
}),
canvas_ids.map(id => {
if (input.includes(id)) {
return new Promise(resolve => {
this.canvas_to_image(canvas[id], value => resolve({ id, value }));
});
} else {
return Promise.resolve('');
}
}),
pattern_ids.map(id => {
if (input.includes(id)) {
return new Promise(resolve => {
Expand All @@ -381,8 +366,6 @@ if (typeof customElements !== 'undefined') {
for (let {id, value} of mapping) {
/* default to data-uri for doodle and pattern */
let target = `url(${value})`;
/* canvas uses css painting api */
if (/^canvas/.test(id)) target = value;
/* shader uses css vars */
if (/^shader|^pattern/.test(id)) target = `var(--${id})`;
input = input.replaceAll('${' + id + '}', target);
Expand Down

0 comments on commit bfccdf5

Please sign in to comment.