-
Notifications
You must be signed in to change notification settings - Fork 0
/
aug-color-picker-simple.ts
52 lines (50 loc) · 1.08 KB
/
aug-color-picker-simple.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { languageFor } from "./core/languages.js";
import { h } from "./external/preact.mjs";
import {
metaexec,
query,
all,
first,
debugIt,
spawnArray,
optional,
type,
also,
log,
} from "./sandblocks/query-builder/functionQueries.js";
export const augColor = (model) => ({
type: "replace",
matcherDepth: Infinity,
model: languageFor("javascript"),
match: (it) =>
metaexec(it, (capture) => [
query('"$string"'),
(it) =>
/#([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})/i.exec(it.string.text) !=
null,
(it) => it.string,
capture("node"),
(it) => it.text,
capture("hex"),
]),
view: ({ hex, node }) => {
return h("div", {
style: { height: "1rem", width: "5rem", background: hex },
});
},
rerender: () => true,
examples: [['const color = "#123456"', [0, 0]]],
});
//matchRecur(
// tree,
// captures,
// (tree) => {
// tree.type == "string_fragment" &&
// /#([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})/i.test(tree.text);
// },
// (match) => {
// ({
// hex: match.text,
// });
// },
//);