forked from mudcube/Sketch.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSketch.Stream.js
68 lines (59 loc) · 1.82 KB
/
Sketch.Stream.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Toying with the idea of compression, this file is not used, and is a work in progress.
*/
(function() {
var style = {
tool: "brush",
// compositing
globalAlpha: 1,
globalCompositeOperation: "source-over",
// colors and styles
strokeStyle: "#000000",
fillStyle: "#000000",
// shadows
shadowOffsetX: 0,
shadowOffsetY: 0,
shadowBlur: 0,
shadowColor: "rgba(0,0,0,0)",
// line caps/joins
lineWidth: 1,
lineCap: "butt",
lineJoin: "miter",
miterLimit: 10,
// text
font: "10px sans-serif",
textAlign: "start",
textBaseline: "alphabetic"
};
var styleOptions = {
tool: { "brush": 0, "eraser": 1, "text": 2 },
globalCompositeOperation: { "source-over": 0, "source-in": 1, "source-out": 2, "source-atop": 3, "destination-over": 4, "destination-in": 5, "destination-out": 6, "destination-atop": 7, "lighter": 8, "darker": 9, "copy": 10, "xor": 11 },
lineCap: { "butt": 0, "round": 1, "square": 2 },
lineJoin: { "round": 0, "bevel": 1, "miter": 2 },
textAlign: { "start": 0, "end": 1, "left": 2, "right": 3, "center": 4 },
textBaseline: { "top": 0, "hanging": 1, "middle": 2, "alphabetic": 3, "ideographic": 4, "bottom": 5 }
};
var styleShorthand = {};
(function() { // create mapping to shorthand code.
for (var i in styleOptions) {
var key = i.split(/(?=[A-Z])/);
for (var n = 0; n < key.length; n ++) key[n] = key[n][0].toLowerCase();
styleShorthand[key.join()] = i;
}
})();
sketch.encode = function() {
for (var p in sketch.path) {
//// Compress the path to SVG (+timeLapse).
//// Compress the style.
for (var i in sketch.style) {
// this makes "fillStyle" === "fs", and "textAlign" === "ta"
var key = styleShorthand[i];
/// this makes "start" === 0, and "hanging" === 1
var value = sketch.style[i];
if (styleOptions[i]) value = styleOptions[i][value];
}
}
};
sketch.decode = function() {
};
})();