@ps-generator-bridge/generator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/contract-C4vydf6-.d.ts +1270 -0
- package/dist/contract.d.ts +3 -0
- package/dist/contract.js +19 -0
- package/dist/contract.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2482 -0
- package/dist/index.js.map +1 -0
- package/jsx/Action/autoCutout.jsx +12 -0
- package/jsx/Action/redo.jsx +5 -0
- package/jsx/Action/removeBackground.jsx +10 -0
- package/jsx/Common/alert.jsx +4 -0
- package/jsx/Common/debug.jsx +43 -0
- package/jsx/Common/event-dispatch.jsx +4 -0
- package/jsx/Document/exportDocument.jsx +128 -0
- package/jsx/Document/getDocumentInfo.jsx +222 -0
- package/jsx/Document/openPsd.jsx +6 -0
- package/jsx/Document/openPsdFile.jsx +7 -0
- package/jsx/Document/saveDocument.jsx +37 -0
- package/jsx/Layer/addImageLayer.jsx +182 -0
- package/jsx/Layer/createSelectionStroke.jsx +44 -0
- package/jsx/Layer/getActiveLayerID.jsx +1 -0
- package/jsx/Layer/getLayerBounds.jsx +114 -0
- package/jsx/Layer/getLayerInfo.jsx +323 -0
- package/jsx/Layer/getLayerPixmap.jsx +337 -0
- package/jsx/Layer/getSelection.jsx +6 -0
- package/jsx/Layer/layer.jsx +284 -0
- package/jsx/Layer/saveEngineDataToLayer.jsx +26 -0
- package/jsx/Layer/setLayerWorkpathMask.jsx +126 -0
- package/jsx/Layer/transformLayer.jsx +121 -0
- package/jsx/Selection/getSelectionPath.jsx +389 -0
- package/jsx/Selection/pathtosvg.jsx +257 -0
- package/jsx/Selection/registerEvent.jsx +10 -0
- package/jsx/Selection/selectiontopath.jsx +9 -0
- package/jsx/polyfills/Array.js +159 -0
- package/jsx/polyfills/Function.js +29 -0
- package/jsx/polyfills/JSON.js +182 -0
- package/jsx/polyfills/Number.js +24 -0
- package/jsx/polyfills/Object.js +80 -0
- package/jsx/polyfills/String.js +87 -0
- package/jsx/types/extendscript/README.md +34 -0
- package/jsx/types/extendscript/actions.d.ts +148 -0
- package/jsx/types/extendscript/application.d.ts +74 -0
- package/jsx/types/extendscript/channel.d.ts +70 -0
- package/jsx/types/extendscript/color.d.ts +92 -0
- package/jsx/types/extendscript/document.d.ts +110 -0
- package/jsx/types/extendscript/enums.d.ts +796 -0
- package/jsx/types/extendscript/index.d.ts +504 -0
- package/jsx/types/extendscript/layer.d.ts +530 -0
- package/jsx/types/extendscript/misc.d.ts +274 -0
- package/jsx/types/extendscript/open-options.d.ts +86 -0
- package/jsx/types/extendscript/path.d.ts +196 -0
- package/jsx/types/extendscript/save-options.d.ts +144 -0
- package/jsx/types/extendscript/selection.d.ts +191 -0
- package/jsx/types/extendscript/text.d.ts +169 -0
- package/main.js +16 -0
- package/package.json +75 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Array.prototype.map = function (f) {
|
|
2
|
+
var retArr = [];
|
|
3
|
+
for (var i = 0, e = this.length; i < e; i++) {
|
|
4
|
+
retArr[i] = f(this[i], i);
|
|
5
|
+
}
|
|
6
|
+
return retArr;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
Array.prototype.forEach = function (f) {
|
|
10
|
+
this.map(f);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
Array.from = function (iterable) {
|
|
14
|
+
var retArr = [];
|
|
15
|
+
for (var i = 0, e = iterable.length; i < e; i++) {
|
|
16
|
+
retArr.push(iterable[i]);
|
|
17
|
+
}
|
|
18
|
+
return retArr;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//
|
|
22
|
+
// Also we'll need some custom objects.
|
|
23
|
+
//
|
|
24
|
+
|
|
25
|
+
var Point = function (kind, x, y) {
|
|
26
|
+
this.kind = kind;
|
|
27
|
+
this.x = x;
|
|
28
|
+
this.y = y;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
Point.prototype = {
|
|
32
|
+
toString: function () {
|
|
33
|
+
var base = [this.kind];
|
|
34
|
+
if (this.in) {
|
|
35
|
+
base = base.concat(["(", this.in.x, this.in.y, ")"]);
|
|
36
|
+
}
|
|
37
|
+
base = base.concat([this.x, this.y]);
|
|
38
|
+
if (this.out) {
|
|
39
|
+
base = base.concat(["(", this.out.x, this.out.y, ")"]);
|
|
40
|
+
}
|
|
41
|
+
return base.join(" ");
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var BBox = function () {
|
|
46
|
+
this.mx = null;
|
|
47
|
+
this.my = null;
|
|
48
|
+
this.MX = null;
|
|
49
|
+
this.MY = null;
|
|
50
|
+
this.initialized = false;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
BBox.prototype = {
|
|
54
|
+
grow: function (p) {
|
|
55
|
+
if (!p || p.x === undefined || p.y === undefined) return;
|
|
56
|
+
|
|
57
|
+
if (!this.initialized) {
|
|
58
|
+
this.mx = p.x;
|
|
59
|
+
this.my = p.y;
|
|
60
|
+
this.MX = p.x;
|
|
61
|
+
this.MY = p.y;
|
|
62
|
+
this.initialized = true;
|
|
63
|
+
} else {
|
|
64
|
+
if (p.x < this.mx) {
|
|
65
|
+
this.mx = p.x;
|
|
66
|
+
}
|
|
67
|
+
if (p.y < this.my) {
|
|
68
|
+
this.my = p.y;
|
|
69
|
+
}
|
|
70
|
+
if (p.x > this.MX) {
|
|
71
|
+
this.MX = p.x;
|
|
72
|
+
}
|
|
73
|
+
if (p.y > this.MY) {
|
|
74
|
+
this.MY = p.y;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 也要考虑控制点
|
|
79
|
+
this.grow(p.in);
|
|
80
|
+
this.grow(p.out);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//
|
|
85
|
+
// And with that out of the way, the actual script:
|
|
86
|
+
//
|
|
87
|
+
|
|
88
|
+
var pointTypes = {
|
|
89
|
+
"PointKind.CORNERPOINT": "P",
|
|
90
|
+
"PointKind.SMOOTHPOINT": "C",
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// filewrite function
|
|
94
|
+
function writeToFile(data) {
|
|
95
|
+
var path = "/";
|
|
96
|
+
// can we get a file location from the current document?
|
|
97
|
+
try {
|
|
98
|
+
path = app.activeDocument.path;
|
|
99
|
+
} catch (e) {}
|
|
100
|
+
var dir = Folder(path);
|
|
101
|
+
var file = dir.saveDlg("", ".svg", true);
|
|
102
|
+
if (!file) return false;
|
|
103
|
+
|
|
104
|
+
var mode = "w";
|
|
105
|
+
file.open(mode);
|
|
106
|
+
file.write(data);
|
|
107
|
+
file.close(mode);
|
|
108
|
+
return file.toString();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// convert a PathPoint to a real object.
|
|
112
|
+
function improvePoint(point) {
|
|
113
|
+
var kind = pointTypes[point.kind];
|
|
114
|
+
var coord = point.anchor;
|
|
115
|
+
var x = Math.round(coord[0]);
|
|
116
|
+
var y = Math.round(coord[1]);
|
|
117
|
+
var obj = new Point(kind, x, y);
|
|
118
|
+
|
|
119
|
+
if (kind === "C") {
|
|
120
|
+
var d;
|
|
121
|
+
if (point.leftDirection) {
|
|
122
|
+
d = point.leftDirection.map(Math.round);
|
|
123
|
+
obj.out = { x: d[0], y: d[1] };
|
|
124
|
+
}
|
|
125
|
+
if (point.rightDirection) {
|
|
126
|
+
d = point.rightDirection.map(Math.round);
|
|
127
|
+
obj.in = { x: d[0], y: d[1] };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return obj;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// convert all points in a subpath to easier to parse form
|
|
135
|
+
function handleSubPath(subpath) {
|
|
136
|
+
var pathPoints = Array.from(subpath.pathPoints);
|
|
137
|
+
return pathPoints.map(improvePoint);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// convert all subpaths in a path to easier to walk form
|
|
141
|
+
function handlePath(path) {
|
|
142
|
+
var subPaths = Array.from(path.subPathItems);
|
|
143
|
+
return subPaths.map(handleSubPath);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// convert only the first path in a document to easier to walk form.
|
|
147
|
+
function convertLastedPath(pathItems) {
|
|
148
|
+
if (pathItems.length === 0) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
// 只获取第一个路径
|
|
152
|
+
var lastedPath = pathItems[pathItems.length - 1];
|
|
153
|
+
return handlePath(lastedPath);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// turn a subpath of improved points into an SVG path
|
|
157
|
+
function formSVGpath(subpath, bbox) {
|
|
158
|
+
var p0 = subpath[0];
|
|
159
|
+
var path = ["M", p0.x, p0.y];
|
|
160
|
+
|
|
161
|
+
// 确保第一个点也被计算进边界框
|
|
162
|
+
bbox.grow(p0);
|
|
163
|
+
|
|
164
|
+
// we want to close this path:
|
|
165
|
+
subpath.push(p0);
|
|
166
|
+
subpath.forEach(function (p, i) {
|
|
167
|
+
if (i === 0) return;
|
|
168
|
+
bbox.grow(p);
|
|
169
|
+
|
|
170
|
+
if (p0.kind === "P" && p.kind === "P") {
|
|
171
|
+
path = path.concat(["L", p.x, p.y]);
|
|
172
|
+
} else if (p0.kind === "P" && p.kind === "C") {
|
|
173
|
+
path = path.concat(["C", p0.x, p0.y, p.in.x, p.in.y, p.x, p.y]);
|
|
174
|
+
} else if (p0.kind === "C" && p.kind === "P") {
|
|
175
|
+
path = path.concat(["C", p0.out.x, p0.out.y, p.x, p.y, p.x, p.y]);
|
|
176
|
+
} else if (p0.kind === "C" && p.kind === "C") {
|
|
177
|
+
path = path.concat(["C", p0.out.x, p0.out.y, p.in.x, p.in.y, p.x, p.y]);
|
|
178
|
+
}
|
|
179
|
+
p0 = p;
|
|
180
|
+
});
|
|
181
|
+
path.push("z");
|
|
182
|
+
return path.join(" ");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Convert a single improved path into an SVG string with tight bounding box
|
|
186
|
+
function formSinglePathSVG(singlePath) {
|
|
187
|
+
if (!singlePath) {
|
|
188
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"></svg>';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
var svg = [];
|
|
192
|
+
var bbox = new BBox();
|
|
193
|
+
var d = "";
|
|
194
|
+
|
|
195
|
+
// 处理单个路径的所有子路径
|
|
196
|
+
singlePath.forEach(function (subpath) {
|
|
197
|
+
d += formSVGpath(subpath, bbox);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// 检查边界框是否有效
|
|
201
|
+
if (!bbox.initialized) {
|
|
202
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"></svg>';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 计算精确的宽高,完全贴合形状
|
|
206
|
+
var w = bbox.MX - bbox.mx;
|
|
207
|
+
var h = bbox.MY - bbox.my;
|
|
208
|
+
|
|
209
|
+
// 确保宽高至少为1,避免无效的SVG
|
|
210
|
+
w = Math.max(w, 1);
|
|
211
|
+
h = Math.max(h, 1);
|
|
212
|
+
|
|
213
|
+
svg.push(
|
|
214
|
+
'<path fill="none" stroke="#25b048" stroke-width="2" fill-rule="evenodd" d="' + d + '"/>'
|
|
215
|
+
);
|
|
216
|
+
svg.push("</svg>");
|
|
217
|
+
|
|
218
|
+
var header =
|
|
219
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="' +
|
|
220
|
+
Math.round(w) +
|
|
221
|
+
'" height="' +
|
|
222
|
+
Math.round(h) +
|
|
223
|
+
'" viewBox="' +
|
|
224
|
+
[bbox.mx, bbox.my, w, h].join(" ") +
|
|
225
|
+
'">';
|
|
226
|
+
svg = [header].concat(svg);
|
|
227
|
+
return svg.join("\n");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ===========================================
|
|
231
|
+
//
|
|
232
|
+
// JS equivalent of main()
|
|
233
|
+
//
|
|
234
|
+
// ===========================================
|
|
235
|
+
|
|
236
|
+
// #target photoshop;
|
|
237
|
+
|
|
238
|
+
// switch to using pixels as unit, irrespective of what the document is set to
|
|
239
|
+
var activeDoc = app.activeDocument;
|
|
240
|
+
var origUnits = app.preferences.rulerUnits;
|
|
241
|
+
app.preferences.rulerUnits = Units.PIXELS;
|
|
242
|
+
|
|
243
|
+
// 检查是否有工作路径
|
|
244
|
+
if (activeDoc.pathItems.length === 0) {
|
|
245
|
+
app.preferences.rulerUnits = origUnits;
|
|
246
|
+
throw new Error("没有找到工作路径");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 只转换第一个路径
|
|
250
|
+
var firstPathImproved = convertLastedPath(activeDoc.pathItems);
|
|
251
|
+
var svg = formSinglePathSVG(firstPathImproved);
|
|
252
|
+
|
|
253
|
+
// switch back to the original document's units once we're done.
|
|
254
|
+
app.preferences.rulerUnits = origUnits;
|
|
255
|
+
|
|
256
|
+
// 返回 SVG 字符串
|
|
257
|
+
svg;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var events = params.events;
|
|
2
|
+
|
|
3
|
+
var actionDescriptor = new ActionDescriptor();
|
|
4
|
+
actionDescriptor.putString(stringIDToTypeID("version"), "1.0.0");
|
|
5
|
+
|
|
6
|
+
for (var i = 0; i < events.length; i++) {
|
|
7
|
+
// 这里要指定生成的那个扩展ID
|
|
8
|
+
actionDescriptor.putClass(stringIDToTypeID("eventIDAttr"), charIDToTypeID(events[i]));
|
|
9
|
+
executeAction(stringIDToTypeID("networkEventSubscribe"), actionDescriptor, DialogModes.NO);
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var desc1 = new ActionDescriptor();
|
|
2
|
+
var ref1 = new ActionReference();
|
|
3
|
+
ref1.putClass(charIDToTypeID("Path"));
|
|
4
|
+
desc1.putReference(charIDToTypeID("null"), ref1);
|
|
5
|
+
var ref2 = new ActionReference();
|
|
6
|
+
ref2.putProperty(charIDToTypeID("csel"), charIDToTypeID("fsel"));
|
|
7
|
+
desc1.putReference(charIDToTypeID("From"), ref2);
|
|
8
|
+
desc1.putUnitDouble(charIDToTypeID("Tlrn"), charIDToTypeID("#Pxl"), 1.0);
|
|
9
|
+
executeAction(charIDToTypeID("Mk "), desc1, DialogModes.NO);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
//#region Array Polyfills (ES3 compatible)
|
|
2
|
+
|
|
3
|
+
// Array.isArray
|
|
4
|
+
if (!Array.isArray) {
|
|
5
|
+
Array.isArray = function (arg) {
|
|
6
|
+
return Object.prototype.toString.call(arg) === "[object Array]";
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Array.prototype.indexOf
|
|
11
|
+
if (!Array.prototype.indexOf) {
|
|
12
|
+
Array.prototype.indexOf = function (searchElement, fromIndex) {
|
|
13
|
+
var len = this.length >>> 0;
|
|
14
|
+
var i = Number(fromIndex) || 0;
|
|
15
|
+
if (i < 0) {
|
|
16
|
+
i = Math.max(len + i, 0);
|
|
17
|
+
}
|
|
18
|
+
for (; i < len; i++) {
|
|
19
|
+
if (i in this && this[i] === searchElement) {
|
|
20
|
+
return i;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return -1;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Array.prototype.forEach
|
|
28
|
+
if (!Array.prototype.forEach) {
|
|
29
|
+
Array.prototype.forEach = function (callback, thisArg) {
|
|
30
|
+
if (typeof callback !== "function") {
|
|
31
|
+
throw new TypeError(callback + " is not a function");
|
|
32
|
+
}
|
|
33
|
+
var len = this.length >>> 0;
|
|
34
|
+
for (var i = 0; i < len; i++) {
|
|
35
|
+
if (i in this) {
|
|
36
|
+
callback.call(thisArg, this[i], i, this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Array.prototype.map
|
|
43
|
+
if (!Array.prototype.map) {
|
|
44
|
+
Array.prototype.map = function (callback, thisArg) {
|
|
45
|
+
if (typeof callback !== "function") {
|
|
46
|
+
throw new TypeError(callback + " is not a function");
|
|
47
|
+
}
|
|
48
|
+
var len = this.length >>> 0;
|
|
49
|
+
var result = new Array(len);
|
|
50
|
+
for (var i = 0; i < len; i++) {
|
|
51
|
+
if (i in this) {
|
|
52
|
+
result[i] = callback.call(thisArg, this[i], i, this);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Array.prototype.filter
|
|
60
|
+
if (!Array.prototype.filter) {
|
|
61
|
+
Array.prototype.filter = function (callback, thisArg) {
|
|
62
|
+
if (typeof callback !== "function") {
|
|
63
|
+
throw new TypeError(callback + " is not a function");
|
|
64
|
+
}
|
|
65
|
+
var len = this.length >>> 0;
|
|
66
|
+
var result = [];
|
|
67
|
+
for (var i = 0; i < len; i++) {
|
|
68
|
+
if (i in this) {
|
|
69
|
+
var val = this[i];
|
|
70
|
+
if (callback.call(thisArg, val, i, this)) {
|
|
71
|
+
result.push(val);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Array.prototype.reduce
|
|
80
|
+
if (!Array.prototype.reduce) {
|
|
81
|
+
Array.prototype.reduce = function (callback, initialValue) {
|
|
82
|
+
if (typeof callback !== "function") {
|
|
83
|
+
throw new TypeError(callback + " is not a function");
|
|
84
|
+
}
|
|
85
|
+
var len = this.length >>> 0;
|
|
86
|
+
var i = 0;
|
|
87
|
+
var accumulator;
|
|
88
|
+
if (arguments.length >= 2) {
|
|
89
|
+
accumulator = initialValue;
|
|
90
|
+
} else {
|
|
91
|
+
while (i < len && !(i in this)) {
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
if (i >= len) {
|
|
95
|
+
throw new TypeError("Reduce of empty array with no initial value");
|
|
96
|
+
}
|
|
97
|
+
accumulator = this[i++];
|
|
98
|
+
}
|
|
99
|
+
for (; i < len; i++) {
|
|
100
|
+
if (i in this) {
|
|
101
|
+
accumulator = callback(accumulator, this[i], i, this);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return accumulator;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Array.prototype.some
|
|
109
|
+
if (!Array.prototype.some) {
|
|
110
|
+
Array.prototype.some = function (callback, thisArg) {
|
|
111
|
+
if (typeof callback !== "function") {
|
|
112
|
+
throw new TypeError(callback + " is not a function");
|
|
113
|
+
}
|
|
114
|
+
var len = this.length >>> 0;
|
|
115
|
+
for (var i = 0; i < len; i++) {
|
|
116
|
+
if (i in this && callback.call(thisArg, this[i], i, this)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Array.prototype.every
|
|
125
|
+
if (!Array.prototype.every) {
|
|
126
|
+
Array.prototype.every = function (callback, thisArg) {
|
|
127
|
+
if (typeof callback !== "function") {
|
|
128
|
+
throw new TypeError(callback + " is not a function");
|
|
129
|
+
}
|
|
130
|
+
var len = this.length >>> 0;
|
|
131
|
+
for (var i = 0; i < len; i++) {
|
|
132
|
+
if (i in this && !callback.call(thisArg, this[i], i, this)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Array.prototype.find
|
|
141
|
+
if (!Array.prototype.find) {
|
|
142
|
+
Array.prototype.find = function (callback, thisArg) {
|
|
143
|
+
if (typeof callback !== "function") {
|
|
144
|
+
throw new TypeError(callback + " is not a function");
|
|
145
|
+
}
|
|
146
|
+
var len = this.length >>> 0;
|
|
147
|
+
for (var i = 0; i < len; i++) {
|
|
148
|
+
if (i in this) {
|
|
149
|
+
var val = this[i];
|
|
150
|
+
if (callback.call(thisArg, val, i, this)) {
|
|
151
|
+
return val;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region Function Polyfills (ES3 compatible)
|
|
2
|
+
|
|
3
|
+
// Function.prototype.bind
|
|
4
|
+
if (!Function.prototype.bind) {
|
|
5
|
+
Function.prototype.bind = function (oThis) {
|
|
6
|
+
if (typeof this !== "function") {
|
|
7
|
+
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
var aArgs = Array.prototype.slice.call(arguments, 1);
|
|
11
|
+
var fToBind = this;
|
|
12
|
+
var fNOP = function () {};
|
|
13
|
+
var fBound = function () {
|
|
14
|
+
return fToBind.apply(
|
|
15
|
+
fNOP.prototype && this instanceof fNOP ? this : oThis,
|
|
16
|
+
aArgs.concat(Array.prototype.slice.call(arguments))
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
if (this.prototype) {
|
|
21
|
+
fNOP.prototype = this.prototype;
|
|
22
|
+
}
|
|
23
|
+
fBound.prototype = new fNOP();
|
|
24
|
+
|
|
25
|
+
return fBound;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
//#region JSON
|
|
2
|
+
|
|
3
|
+
// JSON
|
|
4
|
+
if (typeof JSON !== "object") {
|
|
5
|
+
JSON = {};
|
|
6
|
+
|
|
7
|
+
(function () {
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
var rx_one = /^[\],:{}\s]*$/;
|
|
11
|
+
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
|
|
12
|
+
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
|
13
|
+
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
|
|
14
|
+
var rx_escapable =
|
|
15
|
+
/[\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
16
|
+
var rx_dangerous =
|
|
17
|
+
/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
|
18
|
+
|
|
19
|
+
function f(n) {
|
|
20
|
+
// Format integers to have at least two digits.
|
|
21
|
+
return n < 10 ? "0" + n : n;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function this_value() {
|
|
25
|
+
return this.valueOf();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof Date.prototype.toJSON !== "function") {
|
|
29
|
+
Date.prototype.toJSON = function () {
|
|
30
|
+
return isFinite(this.valueOf())
|
|
31
|
+
? this.getUTCFullYear() +
|
|
32
|
+
"-" +
|
|
33
|
+
f(this.getUTCMonth() + 1) +
|
|
34
|
+
"-" +
|
|
35
|
+
f(this.getUTCDate()) +
|
|
36
|
+
"T" +
|
|
37
|
+
f(this.getUTCHours()) +
|
|
38
|
+
":" +
|
|
39
|
+
f(this.getUTCMinutes()) +
|
|
40
|
+
":" +
|
|
41
|
+
f(this.getUTCSeconds()) +
|
|
42
|
+
"Z"
|
|
43
|
+
: null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Boolean.prototype.toJSON = this_value;
|
|
47
|
+
Number.prototype.toJSON = this_value;
|
|
48
|
+
String.prototype.toJSON = this_value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var gap;
|
|
52
|
+
var indent;
|
|
53
|
+
var meta;
|
|
54
|
+
var rep;
|
|
55
|
+
|
|
56
|
+
function quote(string) {
|
|
57
|
+
rx_escapable.lastIndex = 0;
|
|
58
|
+
return rx_escapable.test(string)
|
|
59
|
+
? '"' +
|
|
60
|
+
string.replace(rx_escapable, function (a) {
|
|
61
|
+
var c = meta[a];
|
|
62
|
+
return typeof c === "string"
|
|
63
|
+
? c
|
|
64
|
+
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4);
|
|
65
|
+
}) +
|
|
66
|
+
'"'
|
|
67
|
+
: '"' + string + '"';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function str(key, holder) {
|
|
71
|
+
var i; // The loop counter.
|
|
72
|
+
var k; // The member key.
|
|
73
|
+
var v; // The member value.
|
|
74
|
+
var length;
|
|
75
|
+
var mind = gap;
|
|
76
|
+
var partial;
|
|
77
|
+
var value = holder[key];
|
|
78
|
+
|
|
79
|
+
if (value && typeof value === "object" && typeof value.toJSON === "function") {
|
|
80
|
+
value = value.toJSON(key);
|
|
81
|
+
}
|
|
82
|
+
if (typeof rep === "function") {
|
|
83
|
+
value = rep.call(holder, key, value);
|
|
84
|
+
}
|
|
85
|
+
switch (typeof value) {
|
|
86
|
+
case "string":
|
|
87
|
+
return quote(value);
|
|
88
|
+
|
|
89
|
+
case "number":
|
|
90
|
+
return isFinite(value) ? String(value) : "null";
|
|
91
|
+
|
|
92
|
+
case "boolean":
|
|
93
|
+
case "null":
|
|
94
|
+
return String(value);
|
|
95
|
+
case "object":
|
|
96
|
+
if (!value) {
|
|
97
|
+
return "null";
|
|
98
|
+
}
|
|
99
|
+
gap += indent;
|
|
100
|
+
partial = [];
|
|
101
|
+
if (Object.prototype.toString.apply(value) === "[object Array]") {
|
|
102
|
+
length = value.length;
|
|
103
|
+
for (i = 0; i < length; i += 1) {
|
|
104
|
+
partial[i] = str(i, value) || "null";
|
|
105
|
+
}
|
|
106
|
+
v =
|
|
107
|
+
partial.length === 0
|
|
108
|
+
? "[]"
|
|
109
|
+
: gap
|
|
110
|
+
? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]"
|
|
111
|
+
: "[" + partial.join(",") + "]";
|
|
112
|
+
gap = mind;
|
|
113
|
+
return v;
|
|
114
|
+
}
|
|
115
|
+
if (rep && typeof rep === "object") {
|
|
116
|
+
length = rep.length;
|
|
117
|
+
for (i = 0; i < length; i += 1) {
|
|
118
|
+
if (typeof rep[i] === "string") {
|
|
119
|
+
k = rep[i];
|
|
120
|
+
v = str(k, value);
|
|
121
|
+
if (v) {
|
|
122
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
for (k in value) {
|
|
128
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
129
|
+
v = str(k, value);
|
|
130
|
+
if (v) {
|
|
131
|
+
partial.push(quote(k) + (gap ? ": " : ":") + v);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
v =
|
|
137
|
+
partial.length === 0
|
|
138
|
+
? "{}"
|
|
139
|
+
: gap
|
|
140
|
+
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
|
141
|
+
: "{" + partial.join(",") + "}";
|
|
142
|
+
gap = mind;
|
|
143
|
+
return v;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (typeof JSON.stringify !== "function") {
|
|
147
|
+
meta = {
|
|
148
|
+
// table of character substitutions
|
|
149
|
+
"\b": "\\b",
|
|
150
|
+
"\t": "\\t",
|
|
151
|
+
"\n": "\\n",
|
|
152
|
+
"\f": "\\f",
|
|
153
|
+
"\r": "\\r",
|
|
154
|
+
'"': '\\"',
|
|
155
|
+
"\\": "\\\\",
|
|
156
|
+
};
|
|
157
|
+
JSON.stringify = function (value, replacer, space) {
|
|
158
|
+
var i;
|
|
159
|
+
gap = "";
|
|
160
|
+
indent = "";
|
|
161
|
+
if (typeof space === "number") {
|
|
162
|
+
for (i = 0; i < space; i += 1) {
|
|
163
|
+
indent += " ";
|
|
164
|
+
}
|
|
165
|
+
} else if (typeof space === "string") {
|
|
166
|
+
indent = space;
|
|
167
|
+
}
|
|
168
|
+
rep = replacer;
|
|
169
|
+
if (
|
|
170
|
+
replacer &&
|
|
171
|
+
typeof replacer !== "function" &&
|
|
172
|
+
(typeof replacer !== "object" || typeof replacer.length !== "number")
|
|
173
|
+
) {
|
|
174
|
+
throw new Error("JSON.stringify");
|
|
175
|
+
}
|
|
176
|
+
return str("", { "": value });
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
})();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region Number Polyfills (ES3 compatible)
|
|
2
|
+
|
|
3
|
+
// Number.isFinite
|
|
4
|
+
if (!Number.isFinite) {
|
|
5
|
+
Number.isFinite = function (value) {
|
|
6
|
+
return typeof value === "number" && isFinite(value);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Number.isNaN
|
|
11
|
+
if (!Number.isNaN) {
|
|
12
|
+
Number.isNaN = function (value) {
|
|
13
|
+
return typeof value === "number" && value !== value;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Number.isInteger
|
|
18
|
+
if (!Number.isInteger) {
|
|
19
|
+
Number.isInteger = function (value) {
|
|
20
|
+
return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|