0.26.1
This commit is contained in:
parent
649db7e82a
commit
0d3ff153ed
11
CHANGELOG.md
11
CHANGELOG.md
|
|
@ -1,3 +1,14 @@
|
|||
## 0.26.1
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fixed undefined `Expose`.
|
||||
* Prevent error for incomplete code.
|
||||
|
||||
<br /> <br />
|
||||
|
||||
|
||||
|
||||
## 0.26.0
|
||||
|
||||
### Features
|
||||
|
|
|
|||
310
css-doodle.js
310
css-doodle.js
|
|
@ -1,4 +1,4 @@
|
|||
/*! css-doodle@0.26.0 */
|
||||
/*! css-doodle@0.26.1 */
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
|
|
@ -327,6 +327,155 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
function clamp(num, min, max) {
|
||||
num = Number(num) || 0;
|
||||
return Math.max(min, Math.min(max, num));
|
||||
}
|
||||
|
||||
function maybe(cond, value) {
|
||||
if (!cond) return '';
|
||||
return (typeof value === 'function') ? value() : value;
|
||||
}
|
||||
|
||||
function range(start, stop, step) {
|
||||
let count = 0, old = start;
|
||||
let initial = n => (n > 0 && n < 1) ? .1 : 1;
|
||||
let length = arguments.length;
|
||||
if (length == 1) [start, stop] = [initial(start), start];
|
||||
if (length < 3) step = initial(start);
|
||||
let range = [];
|
||||
while ((step >= 0 && start <= stop)
|
||||
|| (step < 0 && start > stop)) {
|
||||
range.push(start);
|
||||
start += step;
|
||||
if (count++ >= 1000) break;
|
||||
}
|
||||
if (!range.length) range.push(old);
|
||||
return range;
|
||||
}
|
||||
|
||||
function add_alias(obj, names) {
|
||||
for (let [alias, name] of Object.entries(names)) {
|
||||
obj[alias] = obj[name];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function is_letter(c) {
|
||||
return /^[a-zA-Z]$/.test(c);
|
||||
}
|
||||
|
||||
function is_nil(s) {
|
||||
return s === undefined || s === null;
|
||||
}
|
||||
|
||||
function is_invalid_number(v) {
|
||||
return is_nil(v) || Number.isNaN(v);
|
||||
}
|
||||
|
||||
function is_empty(value) {
|
||||
return is_nil(value) || value === '';
|
||||
}
|
||||
|
||||
function lazy(fn) {
|
||||
let wrap = () => fn;
|
||||
wrap.lazy = true;
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function sequence(count, fn) {
|
||||
let [x, y = 1] = String(count).split('x');
|
||||
x = clamp(Math.ceil(x) || 1, 1, 65536);
|
||||
y = clamp(Math.ceil(y) || 1, 1, 65536);
|
||||
let max = x * y;
|
||||
let ret = [];
|
||||
let index = 1;
|
||||
for (let i = 1; i <= y; ++i) {
|
||||
for (let j = 1; j <= x; ++j) {
|
||||
ret.push(fn(index++, j, i, max, x, y));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function cell_id(x, y, z) {
|
||||
return 'c-' + x + '-' + y + '-' + z;
|
||||
}
|
||||
|
||||
function get_value(input) {
|
||||
let v = input;
|
||||
while (v && !is_nil(v.value)) v = v.value;
|
||||
return is_nil(v) ? '' : v;
|
||||
}
|
||||
|
||||
function normalize_png_name(name) {
|
||||
let prefix = is_nil(name)
|
||||
? Date.now()
|
||||
: String(name).replace(/\/.png$/g, '');
|
||||
return prefix + '.png';
|
||||
}
|
||||
|
||||
function cache_image(src, fn, delay = 0) {
|
||||
let img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = src;
|
||||
img.onload = function() {
|
||||
setTimeout(fn, delay);
|
||||
};
|
||||
}
|
||||
|
||||
function is_safari() {
|
||||
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
function un_entity(code) {
|
||||
let textarea = document.createElement('textarea');
|
||||
textarea.innerHTML = code;
|
||||
return textarea.value;
|
||||
}
|
||||
|
||||
function entity(code) {
|
||||
return code
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
}
|
||||
|
||||
/* cyrb53 */
|
||||
function hash(str, seed = 0) {
|
||||
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
||||
for (let i = 0, ch; i < str.length; i++) {
|
||||
ch = str.charCodeAt(i);
|
||||
h1 = Math.imul(h1 ^ ch, 2654435761);
|
||||
h2 = Math.imul(h2 ^ ch, 1597334677);
|
||||
}
|
||||
h1 = Math.imul(h1 ^ (h1>>>16), 2246822507) ^ Math.imul(h2 ^ (h2>>>13), 3266489909);
|
||||
h2 = Math.imul(h2 ^ (h2>>>16), 2246822507) ^ Math.imul(h1 ^ (h1>>>13), 3266489909);
|
||||
return 4294967296 * (2097151 & h2) + (h1>>>0);
|
||||
}
|
||||
|
||||
function make_tag_function(fn) {
|
||||
let get_value = v => is_nil(v) ? '' : v;
|
||||
return (input, ...vars) => {
|
||||
let string = input.reduce((s, c, i) => s + c + get_value(vars[i]), '');
|
||||
return fn(string);
|
||||
};
|
||||
}
|
||||
|
||||
function next_id() {
|
||||
let id = 0;
|
||||
return (prefix = '') => `${prefix}-${++id}`;
|
||||
}
|
||||
|
||||
function lerp(t, a, b) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
function unique_id(prefix = '') {
|
||||
return prefix + Math.random().toString(32).substr(2);
|
||||
}
|
||||
|
||||
function make_array(arr) {
|
||||
return Array.isArray(arr) ? arr : [arr];
|
||||
}
|
||||
|
|
@ -336,6 +485,7 @@
|
|||
}
|
||||
|
||||
function last(arr, n = 1) {
|
||||
if (is_nil(arr)) return '';
|
||||
return arr[arr.length - n];
|
||||
}
|
||||
|
||||
|
|
@ -358,9 +508,7 @@
|
|||
|
||||
function remove_empty_values(arr) {
|
||||
return arr.filter(v => (
|
||||
v !== undefined &&
|
||||
v !== null &&
|
||||
String(v).trim().length
|
||||
!is_nil(v) && String(v).trim().length
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -1052,156 +1200,6 @@
|
|||
return Tokens;
|
||||
}
|
||||
|
||||
function clamp(num, min, max) {
|
||||
num = Number(num) || 0;
|
||||
return Math.max(min, Math.min(max, num));
|
||||
}
|
||||
|
||||
function maybe(cond, value) {
|
||||
if (!cond) return '';
|
||||
return (typeof value === 'function') ? value() : value;
|
||||
}
|
||||
|
||||
function range(start, stop, step) {
|
||||
let count = 0, old = start;
|
||||
let initial = n => (n > 0 && n < 1) ? .1 : 1;
|
||||
let length = arguments.length;
|
||||
if (length == 1) [start, stop] = [initial(start), start];
|
||||
if (length < 3) step = initial(start);
|
||||
let range = [];
|
||||
while ((step >= 0 && start <= stop)
|
||||
|| (step < 0 && start > stop)) {
|
||||
range.push(start);
|
||||
start += step;
|
||||
if (count++ >= 1000) break;
|
||||
}
|
||||
if (!range.length) range.push(old);
|
||||
return range;
|
||||
}
|
||||
|
||||
function add_alias(obj, names) {
|
||||
for (let [alias, name] of Object.entries(names)) {
|
||||
obj[alias] = obj[name];
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
function is_letter(c) {
|
||||
return /^[a-zA-Z]$/.test(c);
|
||||
}
|
||||
|
||||
function is_nil(s) {
|
||||
return s === undefined || s === null;
|
||||
}
|
||||
|
||||
function is_invalid_number(v) {
|
||||
return is_nil(v) || Number.isNaN(v);
|
||||
}
|
||||
|
||||
function is_empty(value) {
|
||||
return is_nil(value) || value === '';
|
||||
}
|
||||
|
||||
function lazy(fn) {
|
||||
let wrap = () => fn;
|
||||
wrap.lazy = true;
|
||||
return wrap;
|
||||
}
|
||||
|
||||
function sequence(count, fn) {
|
||||
let [x, y = 1] = String(count).split('x');
|
||||
x = clamp(Math.ceil(x) || 1, 1, 65536);
|
||||
y = clamp(Math.ceil(y) || 1, 1, 65536);
|
||||
let max = x * y;
|
||||
let ret = [];
|
||||
let index = 1;
|
||||
for (let i = 1; i <= y; ++i) {
|
||||
for (let j = 1; j <= x; ++j) {
|
||||
ret.push(fn(index++, j, i, max, x, y));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function cell_id(x, y, z) {
|
||||
return 'c-' + x + '-' + y + '-' + z;
|
||||
}
|
||||
|
||||
function get_value(input) {
|
||||
while (input && !is_nil(input.value)) {
|
||||
return get_value(input.value);
|
||||
}
|
||||
return is_nil(input) ? '' : input;
|
||||
}
|
||||
|
||||
function normalize_png_name(name) {
|
||||
let prefix = is_nil(name)
|
||||
? Date.now()
|
||||
: String(name).replace(/\/.png$/g, '');
|
||||
return prefix + '.png';
|
||||
}
|
||||
|
||||
function cache_image(src, fn, delay = 0) {
|
||||
let img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = src;
|
||||
img.onload = function() {
|
||||
setTimeout(fn, delay);
|
||||
};
|
||||
}
|
||||
|
||||
function is_safari() {
|
||||
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
function un_entity(code) {
|
||||
let textarea = document.createElement('textarea');
|
||||
textarea.innerHTML = code;
|
||||
return textarea.value;
|
||||
}
|
||||
|
||||
function entity(code) {
|
||||
return code
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
}
|
||||
|
||||
/* cyrb53 */
|
||||
function hash(str, seed = 0) {
|
||||
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
|
||||
for (let i = 0, ch; i < str.length; i++) {
|
||||
ch = str.charCodeAt(i);
|
||||
h1 = Math.imul(h1 ^ ch, 2654435761);
|
||||
h2 = Math.imul(h2 ^ ch, 1597334677);
|
||||
}
|
||||
h1 = Math.imul(h1 ^ (h1>>>16), 2246822507) ^ Math.imul(h2 ^ (h2>>>13), 3266489909);
|
||||
h2 = Math.imul(h2 ^ (h2>>>16), 2246822507) ^ Math.imul(h1 ^ (h1>>>13), 3266489909);
|
||||
return 4294967296 * (2097151 & h2) + (h1>>>0);
|
||||
}
|
||||
|
||||
function make_tag_function(fn) {
|
||||
let get_value = v => is_nil(v) ? '' : v;
|
||||
return (input, ...vars) => {
|
||||
let string = input.reduce((s, c, i) => s + c + get_value(vars[i]), '');
|
||||
return fn(string);
|
||||
};
|
||||
}
|
||||
|
||||
function next_id() {
|
||||
let id = 0;
|
||||
return (prefix = '') => `${prefix}-${++id}`;
|
||||
}
|
||||
|
||||
function lerp(t, a, b) {
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
function unique_id(prefix = '') {
|
||||
return prefix + Math.random().toString(32).substr(2);
|
||||
}
|
||||
|
||||
const [ min, max, total ] = [ 1, 32, 32 * 32 ];
|
||||
|
||||
function parse_grid(size) {
|
||||
|
|
@ -2832,7 +2830,7 @@
|
|||
return lerp((value - ma) / (mb - ma), min * amp, max * amp);
|
||||
}
|
||||
|
||||
var Func = add_alias({
|
||||
const Expose = add_alias({
|
||||
|
||||
i({ count }) {
|
||||
return _ => count;
|
||||
|
|
@ -3652,7 +3650,7 @@
|
|||
}
|
||||
|
||||
pick_func(name) {
|
||||
return Func[name] || MathFunc[name];
|
||||
return Expose[name] || MathFunc[name];
|
||||
}
|
||||
|
||||
apply_func(fn, coords, args) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "css-doodle",
|
||||
"version": "0.26.0",
|
||||
"version": "0.26.1",
|
||||
"description": "A web component for drawing patterns with CSS",
|
||||
"main": "css-doodle.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue