id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
13,200
|
kbrsh/moon
|
packages/moon/src/executor/executor.js
|
executeCreate
|
function executeCreate(node) {
let element;
let children = [];
if (node.type === types.text) {
// Create a text node using the text content from the default key.
element = document.createTextNode(node.data[""]);
} else {
const nodeData = node.data;
// Create a DOM element.
element = document.createElement(node.name);
// Set data, events, and attributes.
for (let key in nodeData) {
const value = nodeData[key];
if (key[0] === "@") {
let MoonEvents = element.MoonEvents;
if (MoonEvents === undefined) {
MoonEvents = element.MoonEvents = {
[key]: value
};
} else {
MoonEvents[key] = value;
}
element.addEventListener(key.slice(1), ($event) => {
MoonEvents[key]($event);
});
} else if (key !== "children" && value !== false) {
element.setAttribute(key, value);
}
}
// Recursively append children.
const nodeDataChildren = nodeData.children;
for (let i = 0; i < nodeDataChildren.length; i++) {
const childOld = executeCreate(nodeDataChildren[i]);
element.appendChild(childOld.element);
children.push(childOld);
}
}
// Return an old node with a reference to the immutable node and mutable
// element. This is to help performance and allow static nodes to be reused.
return {
element,
node,
children
};
}
|
javascript
|
function executeCreate(node) {
let element;
let children = [];
if (node.type === types.text) {
// Create a text node using the text content from the default key.
element = document.createTextNode(node.data[""]);
} else {
const nodeData = node.data;
// Create a DOM element.
element = document.createElement(node.name);
// Set data, events, and attributes.
for (let key in nodeData) {
const value = nodeData[key];
if (key[0] === "@") {
let MoonEvents = element.MoonEvents;
if (MoonEvents === undefined) {
MoonEvents = element.MoonEvents = {
[key]: value
};
} else {
MoonEvents[key] = value;
}
element.addEventListener(key.slice(1), ($event) => {
MoonEvents[key]($event);
});
} else if (key !== "children" && value !== false) {
element.setAttribute(key, value);
}
}
// Recursively append children.
const nodeDataChildren = nodeData.children;
for (let i = 0; i < nodeDataChildren.length; i++) {
const childOld = executeCreate(nodeDataChildren[i]);
element.appendChild(childOld.element);
children.push(childOld);
}
}
// Return an old node with a reference to the immutable node and mutable
// element. This is to help performance and allow static nodes to be reused.
return {
element,
node,
children
};
}
|
[
"function",
"executeCreate",
"(",
"node",
")",
"{",
"let",
"element",
";",
"let",
"children",
"=",
"[",
"]",
";",
"if",
"(",
"node",
".",
"type",
"===",
"types",
".",
"text",
")",
"{",
"// Create a text node using the text content from the default key.",
"element",
"=",
"document",
".",
"createTextNode",
"(",
"node",
".",
"data",
"[",
"\"\"",
"]",
")",
";",
"}",
"else",
"{",
"const",
"nodeData",
"=",
"node",
".",
"data",
";",
"// Create a DOM element.",
"element",
"=",
"document",
".",
"createElement",
"(",
"node",
".",
"name",
")",
";",
"// Set data, events, and attributes.",
"for",
"(",
"let",
"key",
"in",
"nodeData",
")",
"{",
"const",
"value",
"=",
"nodeData",
"[",
"key",
"]",
";",
"if",
"(",
"key",
"[",
"0",
"]",
"===",
"\"@\"",
")",
"{",
"let",
"MoonEvents",
"=",
"element",
".",
"MoonEvents",
";",
"if",
"(",
"MoonEvents",
"===",
"undefined",
")",
"{",
"MoonEvents",
"=",
"element",
".",
"MoonEvents",
"=",
"{",
"[",
"key",
"]",
":",
"value",
"}",
";",
"}",
"else",
"{",
"MoonEvents",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"element",
".",
"addEventListener",
"(",
"key",
".",
"slice",
"(",
"1",
")",
",",
"(",
"$event",
")",
"=>",
"{",
"MoonEvents",
"[",
"key",
"]",
"(",
"$event",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"key",
"!==",
"\"children\"",
"&&",
"value",
"!==",
"false",
")",
"{",
"element",
".",
"setAttribute",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"// Recursively append children.",
"const",
"nodeDataChildren",
"=",
"nodeData",
".",
"children",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"nodeDataChildren",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"childOld",
"=",
"executeCreate",
"(",
"nodeDataChildren",
"[",
"i",
"]",
")",
";",
"element",
".",
"appendChild",
"(",
"childOld",
".",
"element",
")",
";",
"children",
".",
"push",
"(",
"childOld",
")",
";",
"}",
"}",
"// Return an old node with a reference to the immutable node and mutable",
"// element. This is to help performance and allow static nodes to be reused.",
"return",
"{",
"element",
",",
"node",
",",
"children",
"}",
";",
"}"
] |
Creates an old reference node from a view node.
@param {Object} node
@returns {Object} node to be used as an old node
|
[
"Creates",
"an",
"old",
"reference",
"node",
"from",
"a",
"view",
"node",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/executor/executor.js#L31-L85
|
13,201
|
kbrsh/moon
|
packages/moon/src/executor/executor.js
|
executeView
|
function executeView(nodes, parents, indexes) {
while (true) {
let node = nodes.pop();
const parent = parents.pop();
const index = indexes.pop();
if (node.type === types.component) {
// Execute the component to get the component view.
node = components[node.name](node.data);
// Set the root view or current node to the new component view.
if (parent === null) {
setViewNew(node);
} else {
parent.data.children[index] = node;
}
}
// Execute the views of the children.
const children = node.data.children;
for (let i = 0; i < children.length; i++) {
nodes.push(children[i]);
parents.push(node);
indexes.push(i);
}
if (nodes.length === 0) {
// Move to the diff phase if there is nothing left to do.
executeDiff([viewOld], [viewNew], []);
break;
} else if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then continue executing the view in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeView(nodes, parents, indexes);
});
break;
}
}
}
|
javascript
|
function executeView(nodes, parents, indexes) {
while (true) {
let node = nodes.pop();
const parent = parents.pop();
const index = indexes.pop();
if (node.type === types.component) {
// Execute the component to get the component view.
node = components[node.name](node.data);
// Set the root view or current node to the new component view.
if (parent === null) {
setViewNew(node);
} else {
parent.data.children[index] = node;
}
}
// Execute the views of the children.
const children = node.data.children;
for (let i = 0; i < children.length; i++) {
nodes.push(children[i]);
parents.push(node);
indexes.push(i);
}
if (nodes.length === 0) {
// Move to the diff phase if there is nothing left to do.
executeDiff([viewOld], [viewNew], []);
break;
} else if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then continue executing the view in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeView(nodes, parents, indexes);
});
break;
}
}
}
|
[
"function",
"executeView",
"(",
"nodes",
",",
"parents",
",",
"indexes",
")",
"{",
"while",
"(",
"true",
")",
"{",
"let",
"node",
"=",
"nodes",
".",
"pop",
"(",
")",
";",
"const",
"parent",
"=",
"parents",
".",
"pop",
"(",
")",
";",
"const",
"index",
"=",
"indexes",
".",
"pop",
"(",
")",
";",
"if",
"(",
"node",
".",
"type",
"===",
"types",
".",
"component",
")",
"{",
"// Execute the component to get the component view.",
"node",
"=",
"components",
"[",
"node",
".",
"name",
"]",
"(",
"node",
".",
"data",
")",
";",
"// Set the root view or current node to the new component view.",
"if",
"(",
"parent",
"===",
"null",
")",
"{",
"setViewNew",
"(",
"node",
")",
";",
"}",
"else",
"{",
"parent",
".",
"data",
".",
"children",
"[",
"index",
"]",
"=",
"node",
";",
"}",
"}",
"// Execute the views of the children.",
"const",
"children",
"=",
"node",
".",
"data",
".",
"children",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"nodes",
".",
"push",
"(",
"children",
"[",
"i",
"]",
")",
";",
"parents",
".",
"push",
"(",
"node",
")",
";",
"indexes",
".",
"push",
"(",
"i",
")",
";",
"}",
"if",
"(",
"nodes",
".",
"length",
"===",
"0",
")",
"{",
"// Move to the diff phase if there is nothing left to do.",
"executeDiff",
"(",
"[",
"viewOld",
"]",
",",
"[",
"viewNew",
"]",
",",
"[",
"]",
")",
";",
"break",
";",
"}",
"else",
"if",
"(",
"performance",
".",
"now",
"(",
")",
"-",
"executeStart",
">=",
"16",
")",
"{",
"// If the current frame doesn't have sufficient time left to keep",
"// running then continue executing the view in the next frame.",
"requestAnimationFrame",
"(",
"(",
")",
"=>",
"{",
"executeStart",
"=",
"performance",
".",
"now",
"(",
")",
";",
"executeView",
"(",
"nodes",
",",
"parents",
",",
"indexes",
")",
";",
"}",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Walks through the view and executes components.
@param {Array} nodes
@param {Array} parents
@param {Array} indexes
|
[
"Walks",
"through",
"the",
"view",
"and",
"executes",
"components",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/executor/executor.js#L94-L138
|
13,202
|
kbrsh/moon
|
packages/moon/src/executor/executor.js
|
executeDiff
|
function executeDiff(nodesOld, nodesNew, patches) {
while (true) {
const nodeOld = nodesOld.pop();
const nodeOldNode = nodeOld.node;
const nodeNew = nodesNew.pop();
// If they have the same reference (hoisted) then skip diffing.
if (nodeOldNode !== nodeNew) {
if (nodeOldNode.name !== nodeNew.name) {
// If they have different names, then replace the old node with the
// new one.
patches.push({
type: patchTypes.replaceNode,
nodeOld,
nodeNew,
nodeParent: null
});
} else if (nodeOldNode.type === types.text) {
// If they both are text, then update the text content.
if (nodeOldNode.data[""] !== nodeNew.data[""]) {
patches.push({
type: patchTypes.updateText,
nodeOld,
nodeNew,
nodeParent: null
});
}
} else {
// If they both are normal elements, then update attributes, update
// events, and diff the children for appends, deletes, or recursive
// updates.
patches.push({
type: patchTypes.updateData,
nodeOld,
nodeNew,
nodeParent: null
});
const childrenOld = nodeOld.children;
const childrenNew = nodeNew.data.children;
const childrenOldLength = childrenOld.length;
const childrenNewLength = childrenNew.length;
if (childrenOldLength === childrenNewLength) {
// If the children have the same length then update both as
// usual.
for (let i = 0; i < childrenOldLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
} else if (childrenOldLength > childrenNewLength) {
// If there are more old children than new children, update the
// corresponding ones and remove the extra old children.
for (let i = 0; i < childrenNewLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
for (let i = childrenNewLength; i < childrenOldLength; i++) {
patches.push({
type: patchTypes.removeNode,
nodeOld: childrenOld[i],
nodeNew: null,
nodeParent: nodeOld
});
}
} else {
// If there are more new children than old children, update the
// corresponding ones and append the extra new children.
for (let i = 0; i < childrenOldLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
for (let i = childrenOldLength; i < childrenNewLength; i++) {
patches.push({
type: patchTypes.appendNode,
nodeOld: null,
nodeNew: childrenNew[i],
nodeParent: nodeOld
});
}
}
}
}
if (nodesOld.length === 0) {
// Move to the patch phase if there is nothing left to do.
executePatch(patches);
break;
} else if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then continue diffing in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeDiff(nodesOld, nodesNew, patches);
});
break;
}
}
}
|
javascript
|
function executeDiff(nodesOld, nodesNew, patches) {
while (true) {
const nodeOld = nodesOld.pop();
const nodeOldNode = nodeOld.node;
const nodeNew = nodesNew.pop();
// If they have the same reference (hoisted) then skip diffing.
if (nodeOldNode !== nodeNew) {
if (nodeOldNode.name !== nodeNew.name) {
// If they have different names, then replace the old node with the
// new one.
patches.push({
type: patchTypes.replaceNode,
nodeOld,
nodeNew,
nodeParent: null
});
} else if (nodeOldNode.type === types.text) {
// If they both are text, then update the text content.
if (nodeOldNode.data[""] !== nodeNew.data[""]) {
patches.push({
type: patchTypes.updateText,
nodeOld,
nodeNew,
nodeParent: null
});
}
} else {
// If they both are normal elements, then update attributes, update
// events, and diff the children for appends, deletes, or recursive
// updates.
patches.push({
type: patchTypes.updateData,
nodeOld,
nodeNew,
nodeParent: null
});
const childrenOld = nodeOld.children;
const childrenNew = nodeNew.data.children;
const childrenOldLength = childrenOld.length;
const childrenNewLength = childrenNew.length;
if (childrenOldLength === childrenNewLength) {
// If the children have the same length then update both as
// usual.
for (let i = 0; i < childrenOldLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
} else if (childrenOldLength > childrenNewLength) {
// If there are more old children than new children, update the
// corresponding ones and remove the extra old children.
for (let i = 0; i < childrenNewLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
for (let i = childrenNewLength; i < childrenOldLength; i++) {
patches.push({
type: patchTypes.removeNode,
nodeOld: childrenOld[i],
nodeNew: null,
nodeParent: nodeOld
});
}
} else {
// If there are more new children than old children, update the
// corresponding ones and append the extra new children.
for (let i = 0; i < childrenOldLength; i++) {
nodesOld.push(childrenOld[i]);
nodesNew.push(childrenNew[i]);
}
for (let i = childrenOldLength; i < childrenNewLength; i++) {
patches.push({
type: patchTypes.appendNode,
nodeOld: null,
nodeNew: childrenNew[i],
nodeParent: nodeOld
});
}
}
}
}
if (nodesOld.length === 0) {
// Move to the patch phase if there is nothing left to do.
executePatch(patches);
break;
} else if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then continue diffing in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeDiff(nodesOld, nodesNew, patches);
});
break;
}
}
}
|
[
"function",
"executeDiff",
"(",
"nodesOld",
",",
"nodesNew",
",",
"patches",
")",
"{",
"while",
"(",
"true",
")",
"{",
"const",
"nodeOld",
"=",
"nodesOld",
".",
"pop",
"(",
")",
";",
"const",
"nodeOldNode",
"=",
"nodeOld",
".",
"node",
";",
"const",
"nodeNew",
"=",
"nodesNew",
".",
"pop",
"(",
")",
";",
"// If they have the same reference (hoisted) then skip diffing.",
"if",
"(",
"nodeOldNode",
"!==",
"nodeNew",
")",
"{",
"if",
"(",
"nodeOldNode",
".",
"name",
"!==",
"nodeNew",
".",
"name",
")",
"{",
"// If they have different names, then replace the old node with the",
"// new one.",
"patches",
".",
"push",
"(",
"{",
"type",
":",
"patchTypes",
".",
"replaceNode",
",",
"nodeOld",
",",
"nodeNew",
",",
"nodeParent",
":",
"null",
"}",
")",
";",
"}",
"else",
"if",
"(",
"nodeOldNode",
".",
"type",
"===",
"types",
".",
"text",
")",
"{",
"// If they both are text, then update the text content.",
"if",
"(",
"nodeOldNode",
".",
"data",
"[",
"\"\"",
"]",
"!==",
"nodeNew",
".",
"data",
"[",
"\"\"",
"]",
")",
"{",
"patches",
".",
"push",
"(",
"{",
"type",
":",
"patchTypes",
".",
"updateText",
",",
"nodeOld",
",",
"nodeNew",
",",
"nodeParent",
":",
"null",
"}",
")",
";",
"}",
"}",
"else",
"{",
"// If they both are normal elements, then update attributes, update",
"// events, and diff the children for appends, deletes, or recursive",
"// updates.",
"patches",
".",
"push",
"(",
"{",
"type",
":",
"patchTypes",
".",
"updateData",
",",
"nodeOld",
",",
"nodeNew",
",",
"nodeParent",
":",
"null",
"}",
")",
";",
"const",
"childrenOld",
"=",
"nodeOld",
".",
"children",
";",
"const",
"childrenNew",
"=",
"nodeNew",
".",
"data",
".",
"children",
";",
"const",
"childrenOldLength",
"=",
"childrenOld",
".",
"length",
";",
"const",
"childrenNewLength",
"=",
"childrenNew",
".",
"length",
";",
"if",
"(",
"childrenOldLength",
"===",
"childrenNewLength",
")",
"{",
"// If the children have the same length then update both as",
"// usual.",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"childrenOldLength",
";",
"i",
"++",
")",
"{",
"nodesOld",
".",
"push",
"(",
"childrenOld",
"[",
"i",
"]",
")",
";",
"nodesNew",
".",
"push",
"(",
"childrenNew",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"childrenOldLength",
">",
"childrenNewLength",
")",
"{",
"// If there are more old children than new children, update the",
"// corresponding ones and remove the extra old children.",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"childrenNewLength",
";",
"i",
"++",
")",
"{",
"nodesOld",
".",
"push",
"(",
"childrenOld",
"[",
"i",
"]",
")",
";",
"nodesNew",
".",
"push",
"(",
"childrenNew",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"childrenNewLength",
";",
"i",
"<",
"childrenOldLength",
";",
"i",
"++",
")",
"{",
"patches",
".",
"push",
"(",
"{",
"type",
":",
"patchTypes",
".",
"removeNode",
",",
"nodeOld",
":",
"childrenOld",
"[",
"i",
"]",
",",
"nodeNew",
":",
"null",
",",
"nodeParent",
":",
"nodeOld",
"}",
")",
";",
"}",
"}",
"else",
"{",
"// If there are more new children than old children, update the",
"// corresponding ones and append the extra new children.",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"childrenOldLength",
";",
"i",
"++",
")",
"{",
"nodesOld",
".",
"push",
"(",
"childrenOld",
"[",
"i",
"]",
")",
";",
"nodesNew",
".",
"push",
"(",
"childrenNew",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"childrenOldLength",
";",
"i",
"<",
"childrenNewLength",
";",
"i",
"++",
")",
"{",
"patches",
".",
"push",
"(",
"{",
"type",
":",
"patchTypes",
".",
"appendNode",
",",
"nodeOld",
":",
"null",
",",
"nodeNew",
":",
"childrenNew",
"[",
"i",
"]",
",",
"nodeParent",
":",
"nodeOld",
"}",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"nodesOld",
".",
"length",
"===",
"0",
")",
"{",
"// Move to the patch phase if there is nothing left to do.",
"executePatch",
"(",
"patches",
")",
";",
"break",
";",
"}",
"else",
"if",
"(",
"performance",
".",
"now",
"(",
")",
"-",
"executeStart",
">=",
"16",
")",
"{",
"// If the current frame doesn't have sufficient time left to keep",
"// running then continue diffing in the next frame.",
"requestAnimationFrame",
"(",
"(",
")",
"=>",
"{",
"executeStart",
"=",
"performance",
".",
"now",
"(",
")",
";",
"executeDiff",
"(",
"nodesOld",
",",
"nodesNew",
",",
"patches",
")",
";",
"}",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Finds changes between a new and old tree and creates a list of patches to
execute.
@param {Array} nodesOld
@param {Array} nodesNew
@param {Array} patches
|
[
"Finds",
"changes",
"between",
"a",
"new",
"and",
"old",
"tree",
"and",
"creates",
"a",
"list",
"of",
"patches",
"to",
"execute",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/executor/executor.js#L148-L252
|
13,203
|
kbrsh/moon
|
packages/moon/src/executor/executor.js
|
executePatch
|
function executePatch(patches) {
for (let i = 0; i < patches.length; i++) {
const patch = patches[i];
switch (patch.type) {
case patchTypes.updateText: {
// Update text of a node with new text.
const nodeOld = patch.nodeOld;
const nodeNew = patch.nodeNew;
nodeOld.element.textContent = nodeNew.data[""];
nodeOld.node = nodeNew;
break;
}
case patchTypes.updateData: {
// Set attributes and events of a node with new data.
const nodeOld = patch.nodeOld;
const nodeOldNodeData = nodeOld.node.data;
const nodeOldElement = nodeOld.element;
const nodeNew = patch.nodeNew;
const nodeNewData = nodeNew.data;
// Set attributes on the DOM element.
for (let key in nodeNewData) {
const value = nodeNewData[key];
if (key[0] === "@") {
// Update the event listener.
nodeOldElement.MoonEvents[key] = value;
} else if (key !== "children") {
// Remove the attribute if the value is false, and update it
// otherwise.
if (value === false) {
nodeOldElement.removeAttribute(key);
} else {
nodeOldElement.setAttribute(key, value);
}
}
}
// Remove old attributes.
for (let key in nodeOldNodeData) {
if (!(key in nodeNewData)) {
nodeOldElement.removeAttribute(key);
}
}
nodeOld.node = nodeNew;
break;
}
case patchTypes.appendNode: {
// Append a node to the parent.
const nodeParent = patch.nodeParent;
const nodeOldNew = executeCreate(patch.nodeNew);
nodeParent.element.appendChild(nodeOldNew.element);
nodeParent.children.push(nodeOldNew);
break;
}
case patchTypes.removeNode: {
// Remove a node from the parent.
const nodeParent = patch.nodeParent;
// Pops the last child because the patches still hold a reference
// to them. The diff phase can only create this patch when there
// are extra old children, and popping nodes off of the end is more
// efficient than removing at a specific index, especially because
// they are equivalent in this case.
nodeParent.element.removeChild(nodeParent.children.pop().element);
break;
}
case patchTypes.replaceNode: {
// Replaces an old node with a new node.
const nodeOld = patch.nodeOld;
const nodeOldElement = nodeOld.element;
const nodeNew = patch.nodeNew;
const nodeOldNew = executeCreate(nodeNew);
const nodeOldNewElement = nodeOldNew.element;
nodeOldElement.parentNode.replaceChild(nodeOldNewElement, nodeOldElement);
nodeOld.element = nodeOldNewElement;
nodeOld.node = nodeOldNew.node;
nodeOld.children = nodeOldNew.children;
break;
}
}
}
// Remove the current execution from the queue.
executeQueue.shift();
// If there is new data in the execution queue, continue to it.
if (executeQueue.length !== 0) {
if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then start the next execution in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeNext();
});
} else {
executeNext();
}
}
}
|
javascript
|
function executePatch(patches) {
for (let i = 0; i < patches.length; i++) {
const patch = patches[i];
switch (patch.type) {
case patchTypes.updateText: {
// Update text of a node with new text.
const nodeOld = patch.nodeOld;
const nodeNew = patch.nodeNew;
nodeOld.element.textContent = nodeNew.data[""];
nodeOld.node = nodeNew;
break;
}
case patchTypes.updateData: {
// Set attributes and events of a node with new data.
const nodeOld = patch.nodeOld;
const nodeOldNodeData = nodeOld.node.data;
const nodeOldElement = nodeOld.element;
const nodeNew = patch.nodeNew;
const nodeNewData = nodeNew.data;
// Set attributes on the DOM element.
for (let key in nodeNewData) {
const value = nodeNewData[key];
if (key[0] === "@") {
// Update the event listener.
nodeOldElement.MoonEvents[key] = value;
} else if (key !== "children") {
// Remove the attribute if the value is false, and update it
// otherwise.
if (value === false) {
nodeOldElement.removeAttribute(key);
} else {
nodeOldElement.setAttribute(key, value);
}
}
}
// Remove old attributes.
for (let key in nodeOldNodeData) {
if (!(key in nodeNewData)) {
nodeOldElement.removeAttribute(key);
}
}
nodeOld.node = nodeNew;
break;
}
case patchTypes.appendNode: {
// Append a node to the parent.
const nodeParent = patch.nodeParent;
const nodeOldNew = executeCreate(patch.nodeNew);
nodeParent.element.appendChild(nodeOldNew.element);
nodeParent.children.push(nodeOldNew);
break;
}
case patchTypes.removeNode: {
// Remove a node from the parent.
const nodeParent = patch.nodeParent;
// Pops the last child because the patches still hold a reference
// to them. The diff phase can only create this patch when there
// are extra old children, and popping nodes off of the end is more
// efficient than removing at a specific index, especially because
// they are equivalent in this case.
nodeParent.element.removeChild(nodeParent.children.pop().element);
break;
}
case patchTypes.replaceNode: {
// Replaces an old node with a new node.
const nodeOld = patch.nodeOld;
const nodeOldElement = nodeOld.element;
const nodeNew = patch.nodeNew;
const nodeOldNew = executeCreate(nodeNew);
const nodeOldNewElement = nodeOldNew.element;
nodeOldElement.parentNode.replaceChild(nodeOldNewElement, nodeOldElement);
nodeOld.element = nodeOldNewElement;
nodeOld.node = nodeOldNew.node;
nodeOld.children = nodeOldNew.children;
break;
}
}
}
// Remove the current execution from the queue.
executeQueue.shift();
// If there is new data in the execution queue, continue to it.
if (executeQueue.length !== 0) {
if (performance.now() - executeStart >= 16) {
// If the current frame doesn't have sufficient time left to keep
// running then start the next execution in the next frame.
requestAnimationFrame(() => {
executeStart = performance.now();
executeNext();
});
} else {
executeNext();
}
}
}
|
[
"function",
"executePatch",
"(",
"patches",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"patches",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"patch",
"=",
"patches",
"[",
"i",
"]",
";",
"switch",
"(",
"patch",
".",
"type",
")",
"{",
"case",
"patchTypes",
".",
"updateText",
":",
"{",
"// Update text of a node with new text.",
"const",
"nodeOld",
"=",
"patch",
".",
"nodeOld",
";",
"const",
"nodeNew",
"=",
"patch",
".",
"nodeNew",
";",
"nodeOld",
".",
"element",
".",
"textContent",
"=",
"nodeNew",
".",
"data",
"[",
"\"\"",
"]",
";",
"nodeOld",
".",
"node",
"=",
"nodeNew",
";",
"break",
";",
"}",
"case",
"patchTypes",
".",
"updateData",
":",
"{",
"// Set attributes and events of a node with new data.",
"const",
"nodeOld",
"=",
"patch",
".",
"nodeOld",
";",
"const",
"nodeOldNodeData",
"=",
"nodeOld",
".",
"node",
".",
"data",
";",
"const",
"nodeOldElement",
"=",
"nodeOld",
".",
"element",
";",
"const",
"nodeNew",
"=",
"patch",
".",
"nodeNew",
";",
"const",
"nodeNewData",
"=",
"nodeNew",
".",
"data",
";",
"// Set attributes on the DOM element.",
"for",
"(",
"let",
"key",
"in",
"nodeNewData",
")",
"{",
"const",
"value",
"=",
"nodeNewData",
"[",
"key",
"]",
";",
"if",
"(",
"key",
"[",
"0",
"]",
"===",
"\"@\"",
")",
"{",
"// Update the event listener.",
"nodeOldElement",
".",
"MoonEvents",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"else",
"if",
"(",
"key",
"!==",
"\"children\"",
")",
"{",
"// Remove the attribute if the value is false, and update it",
"// otherwise.",
"if",
"(",
"value",
"===",
"false",
")",
"{",
"nodeOldElement",
".",
"removeAttribute",
"(",
"key",
")",
";",
"}",
"else",
"{",
"nodeOldElement",
".",
"setAttribute",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"}",
"// Remove old attributes.",
"for",
"(",
"let",
"key",
"in",
"nodeOldNodeData",
")",
"{",
"if",
"(",
"!",
"(",
"key",
"in",
"nodeNewData",
")",
")",
"{",
"nodeOldElement",
".",
"removeAttribute",
"(",
"key",
")",
";",
"}",
"}",
"nodeOld",
".",
"node",
"=",
"nodeNew",
";",
"break",
";",
"}",
"case",
"patchTypes",
".",
"appendNode",
":",
"{",
"// Append a node to the parent.",
"const",
"nodeParent",
"=",
"patch",
".",
"nodeParent",
";",
"const",
"nodeOldNew",
"=",
"executeCreate",
"(",
"patch",
".",
"nodeNew",
")",
";",
"nodeParent",
".",
"element",
".",
"appendChild",
"(",
"nodeOldNew",
".",
"element",
")",
";",
"nodeParent",
".",
"children",
".",
"push",
"(",
"nodeOldNew",
")",
";",
"break",
";",
"}",
"case",
"patchTypes",
".",
"removeNode",
":",
"{",
"// Remove a node from the parent.",
"const",
"nodeParent",
"=",
"patch",
".",
"nodeParent",
";",
"// Pops the last child because the patches still hold a reference",
"// to them. The diff phase can only create this patch when there",
"// are extra old children, and popping nodes off of the end is more",
"// efficient than removing at a specific index, especially because",
"// they are equivalent in this case.",
"nodeParent",
".",
"element",
".",
"removeChild",
"(",
"nodeParent",
".",
"children",
".",
"pop",
"(",
")",
".",
"element",
")",
";",
"break",
";",
"}",
"case",
"patchTypes",
".",
"replaceNode",
":",
"{",
"// Replaces an old node with a new node.",
"const",
"nodeOld",
"=",
"patch",
".",
"nodeOld",
";",
"const",
"nodeOldElement",
"=",
"nodeOld",
".",
"element",
";",
"const",
"nodeNew",
"=",
"patch",
".",
"nodeNew",
";",
"const",
"nodeOldNew",
"=",
"executeCreate",
"(",
"nodeNew",
")",
";",
"const",
"nodeOldNewElement",
"=",
"nodeOldNew",
".",
"element",
";",
"nodeOldElement",
".",
"parentNode",
".",
"replaceChild",
"(",
"nodeOldNewElement",
",",
"nodeOldElement",
")",
";",
"nodeOld",
".",
"element",
"=",
"nodeOldNewElement",
";",
"nodeOld",
".",
"node",
"=",
"nodeOldNew",
".",
"node",
";",
"nodeOld",
".",
"children",
"=",
"nodeOldNew",
".",
"children",
";",
"break",
";",
"}",
"}",
"}",
"// Remove the current execution from the queue.",
"executeQueue",
".",
"shift",
"(",
")",
";",
"// If there is new data in the execution queue, continue to it.",
"if",
"(",
"executeQueue",
".",
"length",
"!==",
"0",
")",
"{",
"if",
"(",
"performance",
".",
"now",
"(",
")",
"-",
"executeStart",
">=",
"16",
")",
"{",
"// If the current frame doesn't have sufficient time left to keep",
"// running then start the next execution in the next frame.",
"requestAnimationFrame",
"(",
"(",
")",
"=>",
"{",
"executeStart",
"=",
"performance",
".",
"now",
"(",
")",
";",
"executeNext",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"executeNext",
"(",
")",
";",
"}",
"}",
"}"
] |
Applies the list of patches as DOM updates.
@param {Array} patches
|
[
"Applies",
"the",
"list",
"of",
"patches",
"as",
"DOM",
"updates",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/executor/executor.js#L259-L374
|
13,204
|
kbrsh/moon
|
packages/moon/src/executor/executor.js
|
executeNext
|
function executeNext() {
// Get the next data update.
const dataNew = executeQueue[0];
// Merge new data into current data.
for (let key in dataNew) {
data[key] = dataNew[key];
}
// Begin executing the view.
const viewNew = viewCurrent(data);
setViewNew(viewNew);
executeView([viewNew], [null], [0]);
}
|
javascript
|
function executeNext() {
// Get the next data update.
const dataNew = executeQueue[0];
// Merge new data into current data.
for (let key in dataNew) {
data[key] = dataNew[key];
}
// Begin executing the view.
const viewNew = viewCurrent(data);
setViewNew(viewNew);
executeView([viewNew], [null], [0]);
}
|
[
"function",
"executeNext",
"(",
")",
"{",
"// Get the next data update.",
"const",
"dataNew",
"=",
"executeQueue",
"[",
"0",
"]",
";",
"// Merge new data into current data.",
"for",
"(",
"let",
"key",
"in",
"dataNew",
")",
"{",
"data",
"[",
"key",
"]",
"=",
"dataNew",
"[",
"key",
"]",
";",
"}",
"// Begin executing the view.",
"const",
"viewNew",
"=",
"viewCurrent",
"(",
"data",
")",
";",
"setViewNew",
"(",
"viewNew",
")",
";",
"executeView",
"(",
"[",
"viewNew",
"]",
",",
"[",
"null",
"]",
",",
"[",
"0",
"]",
")",
";",
"}"
] |
Execute the next update in the execution queue.
|
[
"Execute",
"the",
"next",
"update",
"in",
"the",
"execution",
"queue",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/executor/executor.js#L379-L393
|
13,205
|
kbrsh/moon
|
packages/moon/src/compiler/lexer/lexer.js
|
scopeExpression
|
function scopeExpression(expression) {
return expression.replace(expressionRE, (match, name) =>
(
name === undefined ||
name[0] === "$" ||
globals.indexOf(name) !== -1
) ?
match :
"data." + name
);
}
|
javascript
|
function scopeExpression(expression) {
return expression.replace(expressionRE, (match, name) =>
(
name === undefined ||
name[0] === "$" ||
globals.indexOf(name) !== -1
) ?
match :
"data." + name
);
}
|
[
"function",
"scopeExpression",
"(",
"expression",
")",
"{",
"return",
"expression",
".",
"replace",
"(",
"expressionRE",
",",
"(",
"match",
",",
"name",
")",
"=>",
"(",
"name",
"===",
"undefined",
"||",
"name",
"[",
"0",
"]",
"===",
"\"$\"",
"||",
"globals",
".",
"indexOf",
"(",
"name",
")",
"!==",
"-",
"1",
")",
"?",
"match",
":",
"\"data.\"",
"+",
"name",
")",
";",
"}"
] |
Scope an expression to use variables within the `data` object.
@param {string} expression
|
[
"Scope",
"an",
"expression",
"to",
"use",
"variables",
"within",
"the",
"data",
"object",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/compiler/lexer/lexer.js#L76-L86
|
13,206
|
kbrsh/moon
|
packages/moon/src/compiler/lexer/lexer.js
|
lexError
|
function lexError(message, input, index) {
let lexMessage = message + "\n\n";
// Show input characters surrounding the source of the error.
for (
let i = Math.max(0, index - 16);
i < Math.min(index + 16, input.length);
i++
) {
lexMessage += input[i];
}
error(lexMessage);
}
|
javascript
|
function lexError(message, input, index) {
let lexMessage = message + "\n\n";
// Show input characters surrounding the source of the error.
for (
let i = Math.max(0, index - 16);
i < Math.min(index + 16, input.length);
i++
) {
lexMessage += input[i];
}
error(lexMessage);
}
|
[
"function",
"lexError",
"(",
"message",
",",
"input",
",",
"index",
")",
"{",
"let",
"lexMessage",
"=",
"message",
"+",
"\"\\n\\n\"",
";",
"// Show input characters surrounding the source of the error.",
"for",
"(",
"let",
"i",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"index",
"-",
"16",
")",
";",
"i",
"<",
"Math",
".",
"min",
"(",
"index",
"+",
"16",
",",
"input",
".",
"length",
")",
";",
"i",
"++",
")",
"{",
"lexMessage",
"+=",
"input",
"[",
"i",
"]",
";",
"}",
"error",
"(",
"lexMessage",
")",
";",
"}"
] |
Logs a lexer error message to the console along with the surrounding
characters.
@param {string} message
@param {string} input
@param {number} index
|
[
"Logs",
"a",
"lexer",
"error",
"message",
"to",
"the",
"console",
"along",
"with",
"the",
"surrounding",
"characters",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/compiler/lexer/lexer.js#L135-L148
|
13,207
|
kbrsh/moon
|
packages/moon/src/compiler/parser/parser.js
|
ParseError
|
function ParseError(message, start, end, next) {
this.message = message;
this.start = start;
this.end = end;
this.next = next;
}
|
javascript
|
function ParseError(message, start, end, next) {
this.message = message;
this.start = start;
this.end = end;
this.next = next;
}
|
[
"function",
"ParseError",
"(",
"message",
",",
"start",
",",
"end",
",",
"next",
")",
"{",
"this",
".",
"message",
"=",
"message",
";",
"this",
".",
"start",
"=",
"start",
";",
"this",
".",
"end",
"=",
"end",
";",
"this",
".",
"next",
"=",
"next",
";",
"}"
] |
Stores an error message, a slice of tokens associated with the error, and a
related error for later reporting.
|
[
"Stores",
"an",
"error",
"message",
"a",
"slice",
"of",
"tokens",
"associated",
"with",
"the",
"error",
"and",
"a",
"related",
"error",
"for",
"later",
"reporting",
"."
] |
7f9e660d120ccff511970ec6f7cb60310a8493e7
|
https://github.com/kbrsh/moon/blob/7f9e660d120ccff511970ec6f7cb60310a8493e7/packages/moon/src/compiler/parser/parser.js#L8-L13
|
13,208
|
scurker/currency.js
|
src/currency.js
|
currency
|
function currency(value, opts) {
let that = this;
if(!(that instanceof currency)) {
return new currency(value, opts);
}
let settings = Object.assign({}, defaults, opts)
, precision = pow(settings.precision)
, v = parse(value, settings);
that.intValue = v;
that.value = v / precision;
// Set default incremental value
settings.increment = settings.increment || (1 / precision);
// Support vedic numbering systems
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
if(settings.useVedic) {
settings.groups = vedicRegex;
} else {
settings.groups = groupRegex;
}
// Intended for internal usage only - subject to change
this._settings = settings;
this._precision = precision;
}
|
javascript
|
function currency(value, opts) {
let that = this;
if(!(that instanceof currency)) {
return new currency(value, opts);
}
let settings = Object.assign({}, defaults, opts)
, precision = pow(settings.precision)
, v = parse(value, settings);
that.intValue = v;
that.value = v / precision;
// Set default incremental value
settings.increment = settings.increment || (1 / precision);
// Support vedic numbering systems
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
if(settings.useVedic) {
settings.groups = vedicRegex;
} else {
settings.groups = groupRegex;
}
// Intended for internal usage only - subject to change
this._settings = settings;
this._precision = precision;
}
|
[
"function",
"currency",
"(",
"value",
",",
"opts",
")",
"{",
"let",
"that",
"=",
"this",
";",
"if",
"(",
"!",
"(",
"that",
"instanceof",
"currency",
")",
")",
"{",
"return",
"new",
"currency",
"(",
"value",
",",
"opts",
")",
";",
"}",
"let",
"settings",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"defaults",
",",
"opts",
")",
",",
"precision",
"=",
"pow",
"(",
"settings",
".",
"precision",
")",
",",
"v",
"=",
"parse",
"(",
"value",
",",
"settings",
")",
";",
"that",
".",
"intValue",
"=",
"v",
";",
"that",
".",
"value",
"=",
"v",
"/",
"precision",
";",
"// Set default incremental value",
"settings",
".",
"increment",
"=",
"settings",
".",
"increment",
"||",
"(",
"1",
"/",
"precision",
")",
";",
"// Support vedic numbering systems",
"// see: https://en.wikipedia.org/wiki/Indian_numbering_system",
"if",
"(",
"settings",
".",
"useVedic",
")",
"{",
"settings",
".",
"groups",
"=",
"vedicRegex",
";",
"}",
"else",
"{",
"settings",
".",
"groups",
"=",
"groupRegex",
";",
"}",
"// Intended for internal usage only - subject to change",
"this",
".",
"_settings",
"=",
"settings",
";",
"this",
".",
"_precision",
"=",
"precision",
";",
"}"
] |
Create a new instance of currency.js
@param {number|string|currency} value
@param {object} [opts]
|
[
"Create",
"a",
"new",
"instance",
"of",
"currency",
".",
"js"
] |
592f80f44655794efba793494a9f099308034cd9
|
https://github.com/scurker/currency.js/blob/592f80f44655794efba793494a9f099308034cd9/src/currency.js#L24-L52
|
13,209
|
choerodon/choerodon-ui
|
scripts/sort-api-table.js
|
alphabetSort
|
function alphabetSort(nodes) {
// use toLowerCase to keep `case insensitive`
return nodes.sort((...comparison) => {
return asciiSort(...comparison.map(val => getCellValue(val).toLowerCase()));
});
}
|
javascript
|
function alphabetSort(nodes) {
// use toLowerCase to keep `case insensitive`
return nodes.sort((...comparison) => {
return asciiSort(...comparison.map(val => getCellValue(val).toLowerCase()));
});
}
|
[
"function",
"alphabetSort",
"(",
"nodes",
")",
"{",
"// use toLowerCase to keep `case insensitive`",
"return",
"nodes",
".",
"sort",
"(",
"(",
"...",
"comparison",
")",
"=>",
"{",
"return",
"asciiSort",
"(",
"...",
"comparison",
".",
"map",
"(",
"val",
"=>",
"getCellValue",
"(",
"val",
")",
".",
"toLowerCase",
"(",
")",
")",
")",
";",
"}",
")",
";",
"}"
] |
follow the alphabet order
|
[
"follow",
"the",
"alphabet",
"order"
] |
1fa800a0acd6720ee33e5ea64ad547409f89195b
|
https://github.com/choerodon/choerodon-ui/blob/1fa800a0acd6720ee33e5ea64ad547409f89195b/scripts/sort-api-table.js#L48-L53
|
13,210
|
ethereumjs/ethereumjs-abi
|
lib/index.js
|
parseType
|
function parseType (type) {
var size
var ret
if (isArray(type)) {
size = parseTypeArray(type)
var subArray = type.slice(0, type.lastIndexOf('['))
subArray = parseType(subArray)
ret = {
isArray: true,
name: type,
size: size,
memoryUsage: size === 'dynamic' ? 32 : subArray.memoryUsage * size,
subArray: subArray
}
return ret
} else {
var rawType
switch (type) {
case 'address':
rawType = 'uint160'
break
case 'bool':
rawType = 'uint8'
break
case 'string':
rawType = 'bytes'
break
}
ret = {
rawType: rawType,
name: type,
memoryUsage: 32
}
if ((type.startsWith('bytes') && type !== 'bytes') || type.startsWith('uint') || type.startsWith('int')) {
ret.size = parseTypeN(type)
} else if (type.startsWith('ufixed') || type.startsWith('fixed')) {
ret.size = parseTypeNxM(type)
}
if (type.startsWith('bytes') && type !== 'bytes' && (ret.size < 1 || ret.size > 32)) {
throw new Error('Invalid bytes<N> width: ' + ret.size)
}
if ((type.startsWith('uint') || type.startsWith('int')) && (ret.size % 8 || ret.size < 8 || ret.size > 256)) {
throw new Error('Invalid int/uint<N> width: ' + ret.size)
}
return ret
}
}
|
javascript
|
function parseType (type) {
var size
var ret
if (isArray(type)) {
size = parseTypeArray(type)
var subArray = type.slice(0, type.lastIndexOf('['))
subArray = parseType(subArray)
ret = {
isArray: true,
name: type,
size: size,
memoryUsage: size === 'dynamic' ? 32 : subArray.memoryUsage * size,
subArray: subArray
}
return ret
} else {
var rawType
switch (type) {
case 'address':
rawType = 'uint160'
break
case 'bool':
rawType = 'uint8'
break
case 'string':
rawType = 'bytes'
break
}
ret = {
rawType: rawType,
name: type,
memoryUsage: 32
}
if ((type.startsWith('bytes') && type !== 'bytes') || type.startsWith('uint') || type.startsWith('int')) {
ret.size = parseTypeN(type)
} else if (type.startsWith('ufixed') || type.startsWith('fixed')) {
ret.size = parseTypeNxM(type)
}
if (type.startsWith('bytes') && type !== 'bytes' && (ret.size < 1 || ret.size > 32)) {
throw new Error('Invalid bytes<N> width: ' + ret.size)
}
if ((type.startsWith('uint') || type.startsWith('int')) && (ret.size % 8 || ret.size < 8 || ret.size > 256)) {
throw new Error('Invalid int/uint<N> width: ' + ret.size)
}
return ret
}
}
|
[
"function",
"parseType",
"(",
"type",
")",
"{",
"var",
"size",
"var",
"ret",
"if",
"(",
"isArray",
"(",
"type",
")",
")",
"{",
"size",
"=",
"parseTypeArray",
"(",
"type",
")",
"var",
"subArray",
"=",
"type",
".",
"slice",
"(",
"0",
",",
"type",
".",
"lastIndexOf",
"(",
"'['",
")",
")",
"subArray",
"=",
"parseType",
"(",
"subArray",
")",
"ret",
"=",
"{",
"isArray",
":",
"true",
",",
"name",
":",
"type",
",",
"size",
":",
"size",
",",
"memoryUsage",
":",
"size",
"===",
"'dynamic'",
"?",
"32",
":",
"subArray",
".",
"memoryUsage",
"*",
"size",
",",
"subArray",
":",
"subArray",
"}",
"return",
"ret",
"}",
"else",
"{",
"var",
"rawType",
"switch",
"(",
"type",
")",
"{",
"case",
"'address'",
":",
"rawType",
"=",
"'uint160'",
"break",
"case",
"'bool'",
":",
"rawType",
"=",
"'uint8'",
"break",
"case",
"'string'",
":",
"rawType",
"=",
"'bytes'",
"break",
"}",
"ret",
"=",
"{",
"rawType",
":",
"rawType",
",",
"name",
":",
"type",
",",
"memoryUsage",
":",
"32",
"}",
"if",
"(",
"(",
"type",
".",
"startsWith",
"(",
"'bytes'",
")",
"&&",
"type",
"!==",
"'bytes'",
")",
"||",
"type",
".",
"startsWith",
"(",
"'uint'",
")",
"||",
"type",
".",
"startsWith",
"(",
"'int'",
")",
")",
"{",
"ret",
".",
"size",
"=",
"parseTypeN",
"(",
"type",
")",
"}",
"else",
"if",
"(",
"type",
".",
"startsWith",
"(",
"'ufixed'",
")",
"||",
"type",
".",
"startsWith",
"(",
"'fixed'",
")",
")",
"{",
"ret",
".",
"size",
"=",
"parseTypeNxM",
"(",
"type",
")",
"}",
"if",
"(",
"type",
".",
"startsWith",
"(",
"'bytes'",
")",
"&&",
"type",
"!==",
"'bytes'",
"&&",
"(",
"ret",
".",
"size",
"<",
"1",
"||",
"ret",
".",
"size",
">",
"32",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid bytes<N> width: '",
"+",
"ret",
".",
"size",
")",
"}",
"if",
"(",
"(",
"type",
".",
"startsWith",
"(",
"'uint'",
")",
"||",
"type",
".",
"startsWith",
"(",
"'int'",
")",
")",
"&&",
"(",
"ret",
".",
"size",
"%",
"8",
"||",
"ret",
".",
"size",
"<",
"8",
"||",
"ret",
".",
"size",
">",
"256",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid int/uint<N> width: '",
"+",
"ret",
".",
"size",
")",
"}",
"return",
"ret",
"}",
"}"
] |
Parse the given type @returns: {} containing the type itself, memory usage and (including size and subArray if applicable)
|
[
"Parse",
"the",
"given",
"type"
] |
8431eab7b3384e65e8126a4602520b78031666fb
|
https://github.com/ethereumjs/ethereumjs-abi/blob/8431eab7b3384e65e8126a4602520b78031666fb/lib/index.js#L281-L329
|
13,211
|
simplecrawler/simplecrawler
|
lib/cookies.js
|
function(name, value, expires, path, domain, httponly) {
if (!name) {
throw new Error("A name is required to create a cookie.");
}
// Parse date to timestamp - consider it never expiring if timestamp is not
// passed to the function
if (expires) {
if (typeof expires !== "number") {
expires = (new Date(expires)).getTime();
}
} else {
expires = -1;
}
this.name = name;
this.value = value || "";
this.expires = expires;
this.path = path || "/";
this.domain = domain || "*";
this.httponly = Boolean(httponly);
}
|
javascript
|
function(name, value, expires, path, domain, httponly) {
if (!name) {
throw new Error("A name is required to create a cookie.");
}
// Parse date to timestamp - consider it never expiring if timestamp is not
// passed to the function
if (expires) {
if (typeof expires !== "number") {
expires = (new Date(expires)).getTime();
}
} else {
expires = -1;
}
this.name = name;
this.value = value || "";
this.expires = expires;
this.path = path || "/";
this.domain = domain || "*";
this.httponly = Boolean(httponly);
}
|
[
"function",
"(",
"name",
",",
"value",
",",
"expires",
",",
"path",
",",
"domain",
",",
"httponly",
")",
"{",
"if",
"(",
"!",
"name",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"A name is required to create a cookie.\"",
")",
";",
"}",
"// Parse date to timestamp - consider it never expiring if timestamp is not",
"// passed to the function",
"if",
"(",
"expires",
")",
"{",
"if",
"(",
"typeof",
"expires",
"!==",
"\"number\"",
")",
"{",
"expires",
"=",
"(",
"new",
"Date",
"(",
"expires",
")",
")",
".",
"getTime",
"(",
")",
";",
"}",
"}",
"else",
"{",
"expires",
"=",
"-",
"1",
";",
"}",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"value",
"=",
"value",
"||",
"\"\"",
";",
"this",
".",
"expires",
"=",
"expires",
";",
"this",
".",
"path",
"=",
"path",
"||",
"\"/\"",
";",
"this",
".",
"domain",
"=",
"domain",
"||",
"\"*\"",
";",
"this",
".",
"httponly",
"=",
"Boolean",
"(",
"httponly",
")",
";",
"}"
] |
Creates a new cookies
@class
@param {String} name Name of the new cookie
@param {String} value Value of the new cookie
@param {String|Number} expires Expiry timestamp of the new cookie in milliseconds
@param {String} [path="/"] Limits cookie to a path
@param {String} [domain="*"] Limits cookie to a domain
@param {Boolean} [httponly=false] Specifies whether to include the HttpOnly flag
|
[
"Creates",
"a",
"new",
"cookies"
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/cookies.js#L259-L282
|
|
13,212
|
simplecrawler/simplecrawler
|
lib/cache.js
|
Cache
|
function Cache(cacheLoadParameter, cacheBackend) {
// Ensure parameters are how we want them...
cacheBackend = typeof cacheBackend === "function" ? cacheBackend : FilesystemBackend;
cacheLoadParameter = cacheLoadParameter instanceof Array ? cacheLoadParameter : [cacheLoadParameter];
// Now we can just run the factory.
this.datastore = cacheBackend.apply(cacheBackend, cacheLoadParameter);
// Instruct the backend to load up.
this.datastore.load();
}
|
javascript
|
function Cache(cacheLoadParameter, cacheBackend) {
// Ensure parameters are how we want them...
cacheBackend = typeof cacheBackend === "function" ? cacheBackend : FilesystemBackend;
cacheLoadParameter = cacheLoadParameter instanceof Array ? cacheLoadParameter : [cacheLoadParameter];
// Now we can just run the factory.
this.datastore = cacheBackend.apply(cacheBackend, cacheLoadParameter);
// Instruct the backend to load up.
this.datastore.load();
}
|
[
"function",
"Cache",
"(",
"cacheLoadParameter",
",",
"cacheBackend",
")",
"{",
"// Ensure parameters are how we want them...",
"cacheBackend",
"=",
"typeof",
"cacheBackend",
"===",
"\"function\"",
"?",
"cacheBackend",
":",
"FilesystemBackend",
";",
"cacheLoadParameter",
"=",
"cacheLoadParameter",
"instanceof",
"Array",
"?",
"cacheLoadParameter",
":",
"[",
"cacheLoadParameter",
"]",
";",
"// Now we can just run the factory.",
"this",
".",
"datastore",
"=",
"cacheBackend",
".",
"apply",
"(",
"cacheBackend",
",",
"cacheLoadParameter",
")",
";",
"// Instruct the backend to load up.",
"this",
".",
"datastore",
".",
"load",
"(",
")",
";",
"}"
] |
Init cache wrapper for backend...
|
[
"Init",
"cache",
"wrapper",
"for",
"backend",
"..."
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/cache.js#L13-L24
|
13,213
|
simplecrawler/simplecrawler
|
lib/queue.js
|
compare
|
function compare(a, b) {
for (var key in a) {
if (a.hasOwnProperty(key)) {
if (typeof a[key] !== typeof b[key]) {
return false;
}
if (typeof a[key] === "object") {
if (!compare(a[key], b[key])) {
return false;
}
} else if (a[key] !== b[key]) {
return false;
}
}
}
return true;
}
|
javascript
|
function compare(a, b) {
for (var key in a) {
if (a.hasOwnProperty(key)) {
if (typeof a[key] !== typeof b[key]) {
return false;
}
if (typeof a[key] === "object") {
if (!compare(a[key], b[key])) {
return false;
}
} else if (a[key] !== b[key]) {
return false;
}
}
}
return true;
}
|
[
"function",
"compare",
"(",
"a",
",",
"b",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"a",
")",
"{",
"if",
"(",
"a",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"typeof",
"a",
"[",
"key",
"]",
"!==",
"typeof",
"b",
"[",
"key",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"typeof",
"a",
"[",
"key",
"]",
"===",
"\"object\"",
")",
"{",
"if",
"(",
"!",
"compare",
"(",
"a",
"[",
"key",
"]",
",",
"b",
"[",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"a",
"[",
"key",
"]",
"!==",
"b",
"[",
"key",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Recursive function that compares immutable properties on two objects.
@private
@param {Object} a Source object that will be compared against
@param {Object} b Comparison object. The functions determines if all of this object's properties are the same on the first object.
@return {Boolean} Returns true if all of the properties on `b` matched a property on `a`. If not, it returns false.
|
[
"Recursive",
"function",
"that",
"compares",
"immutable",
"properties",
"on",
"two",
"objects",
"."
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/queue.js#L16-L35
|
13,214
|
simplecrawler/simplecrawler
|
lib/queue.js
|
deepAssign
|
function deepAssign(object, source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (typeof object[key] === "object" && typeof source[key] === "object") {
deepAssign(object[key], source[key]);
} else {
object[key] = source[key];
}
}
}
return object;
}
|
javascript
|
function deepAssign(object, source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (typeof object[key] === "object" && typeof source[key] === "object") {
deepAssign(object[key], source[key]);
} else {
object[key] = source[key];
}
}
}
return object;
}
|
[
"function",
"deepAssign",
"(",
"object",
",",
"source",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"source",
")",
"{",
"if",
"(",
"source",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"typeof",
"object",
"[",
"key",
"]",
"===",
"\"object\"",
"&&",
"typeof",
"source",
"[",
"key",
"]",
"===",
"\"object\"",
")",
"{",
"deepAssign",
"(",
"object",
"[",
"key",
"]",
",",
"source",
"[",
"key",
"]",
")",
";",
"}",
"else",
"{",
"object",
"[",
"key",
"]",
"=",
"source",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"return",
"object",
";",
"}"
] |
Recursive function that takes two objects and updates the properties on the
first object based on the ones in the second. Basically, it's a recursive
version of Object.assign.
|
[
"Recursive",
"function",
"that",
"takes",
"two",
"objects",
"and",
"updates",
"the",
"properties",
"on",
"the",
"first",
"object",
"based",
"on",
"the",
"ones",
"in",
"the",
"second",
".",
"Basically",
"it",
"s",
"a",
"recursive",
"version",
"of",
"Object",
".",
"assign",
"."
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/queue.js#L42-L54
|
13,215
|
simplecrawler/simplecrawler
|
lib/queue.js
|
function() {
Array.call(this);
/**
* Speeds up {@link FetchQueue.oldestUnfetchedItem} by storing the index at
* which the latest oldest unfetched queue item was found.
* @name FetchQueue._oldestUnfetchedIndex
* @private
* @type {Number}
*/
Object.defineProperty(this, "_oldestUnfetchedIndex", {
enumerable: false,
writable: true,
value: 0
});
/**
* Serves as a cache for what URL's have been fetched. Keys are URL's,
* values are booleans.
* @name FetchQueue._scanIndex
* @private
* @type {Object}
*/
Object.defineProperty(this, "_scanIndex", {
enumerable: false,
writable: true,
value: {}
});
/**
* Controls what properties can be operated on with the
* {@link FetchQueue#min}, {@link FetchQueue#avg} and {@link FetchQueue#max}
* methods.
* @name FetchQueue._allowedStatistics
* @type {Array}
*/
Object.defineProperty(this, "_allowedStatistics", {
enumerable: false,
writable: true,
value: [
"actualDataSize",
"contentLength",
"downloadTime",
"requestLatency",
"requestTime"
]
});
}
|
javascript
|
function() {
Array.call(this);
/**
* Speeds up {@link FetchQueue.oldestUnfetchedItem} by storing the index at
* which the latest oldest unfetched queue item was found.
* @name FetchQueue._oldestUnfetchedIndex
* @private
* @type {Number}
*/
Object.defineProperty(this, "_oldestUnfetchedIndex", {
enumerable: false,
writable: true,
value: 0
});
/**
* Serves as a cache for what URL's have been fetched. Keys are URL's,
* values are booleans.
* @name FetchQueue._scanIndex
* @private
* @type {Object}
*/
Object.defineProperty(this, "_scanIndex", {
enumerable: false,
writable: true,
value: {}
});
/**
* Controls what properties can be operated on with the
* {@link FetchQueue#min}, {@link FetchQueue#avg} and {@link FetchQueue#max}
* methods.
* @name FetchQueue._allowedStatistics
* @type {Array}
*/
Object.defineProperty(this, "_allowedStatistics", {
enumerable: false,
writable: true,
value: [
"actualDataSize",
"contentLength",
"downloadTime",
"requestLatency",
"requestTime"
]
});
}
|
[
"function",
"(",
")",
"{",
"Array",
".",
"call",
"(",
"this",
")",
";",
"/**\n * Speeds up {@link FetchQueue.oldestUnfetchedItem} by storing the index at\n * which the latest oldest unfetched queue item was found.\n * @name FetchQueue._oldestUnfetchedIndex\n * @private\n * @type {Number}\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"_oldestUnfetchedIndex\"",
",",
"{",
"enumerable",
":",
"false",
",",
"writable",
":",
"true",
",",
"value",
":",
"0",
"}",
")",
";",
"/**\n * Serves as a cache for what URL's have been fetched. Keys are URL's,\n * values are booleans.\n * @name FetchQueue._scanIndex\n * @private\n * @type {Object}\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"_scanIndex\"",
",",
"{",
"enumerable",
":",
"false",
",",
"writable",
":",
"true",
",",
"value",
":",
"{",
"}",
"}",
")",
";",
"/**\n * Controls what properties can be operated on with the\n * {@link FetchQueue#min}, {@link FetchQueue#avg} and {@link FetchQueue#max}\n * methods.\n * @name FetchQueue._allowedStatistics\n * @type {Array}\n */",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"\"_allowedStatistics\"",
",",
"{",
"enumerable",
":",
"false",
",",
"writable",
":",
"true",
",",
"value",
":",
"[",
"\"actualDataSize\"",
",",
"\"contentLength\"",
",",
"\"downloadTime\"",
",",
"\"requestLatency\"",
",",
"\"requestTime\"",
"]",
"}",
")",
";",
"}"
] |
QueueItems represent resources in the queue that have been fetched, or will be eventually.
@typedef {Object} QueueItem
@property {Number} id A unique ID assigned by the queue when the queue item is added
@property {String} url The complete, canonical URL of the resource
@property {String} protocol The protocol of the resource (http, https)
@property {String} host The full domain/hostname of the resource
@property {Number} port The port of the resource
@property {String} path The URL path, including the query string
@property {String} uriPath The URL path, excluding the query string
@property {Number} depth How many steps simplecrawler has taken from the initial page (which is depth 1) to this resource.
@property {String} referrer The URL of the resource where the URL of this queue item was discovered
@property {Boolean} fetched Has the request for this item been completed? You can monitor this as requests are processed.
@property {'queued'|'spooled'|'headers'|'downloaded'|'redirected'|'notfound'|'failed'} status The internal status of the item.
@property {Object} stateData An object containing state data and other information about the request.
@property {Number} stateData.requestLatency The time (in ms) taken for headers to be received after the request was made.
@property {Number} stateData.requestTime The total time (in ms) taken for the request (including download time.)
@property {Number} stateData.downloadTime The total time (in ms) taken for the resource to be downloaded.
@property {Number} stateData.contentLength The length (in bytes) of the returned content. Calculated based on the `content-length` header.
@property {String} stateData.contentType The MIME type of the content.
@property {Number} stateData.code The HTTP status code returned for the request. Note that this code is `600` if an error occurred in the client and a fetch operation could not take place successfully.
@property {Object} stateData.headers An object containing the header information returned by the server. This is the object node returns as part of the `response` object.
@property {Number} stateData.actualDataSize The length (in bytes) of the returned content. Calculated based on what is actually received, not the `content-length` header.
@property {Boolean} stateData.sentIncorrectSize True if the data length returned by the server did not match what we were told to expect by the `content-length` header.
FetchQueue handles {@link QueueItem}s and provides a few utility methods for querying them
@class
|
[
"QueueItems",
"represent",
"resources",
"in",
"the",
"queue",
"that",
"have",
"been",
"fetched",
"or",
"will",
"be",
"eventually",
"."
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/queue.js#L86-L133
|
|
13,216
|
simplecrawler/simplecrawler
|
lib/cache-backend-fs.js
|
FSBackend
|
function FSBackend(loadParameter) {
this.loaded = false;
this.index = [];
this.location = typeof loadParameter === "string" && loadParameter.length > 0 ? loadParameter : process.cwd() + "/cache/";
this.location = this.location.substr(this.location.length - 1) === "/" ? this.location : this.location + "/";
}
|
javascript
|
function FSBackend(loadParameter) {
this.loaded = false;
this.index = [];
this.location = typeof loadParameter === "string" && loadParameter.length > 0 ? loadParameter : process.cwd() + "/cache/";
this.location = this.location.substr(this.location.length - 1) === "/" ? this.location : this.location + "/";
}
|
[
"function",
"FSBackend",
"(",
"loadParameter",
")",
"{",
"this",
".",
"loaded",
"=",
"false",
";",
"this",
".",
"index",
"=",
"[",
"]",
";",
"this",
".",
"location",
"=",
"typeof",
"loadParameter",
"===",
"\"string\"",
"&&",
"loadParameter",
".",
"length",
">",
"0",
"?",
"loadParameter",
":",
"process",
".",
"cwd",
"(",
")",
"+",
"\"/cache/\"",
";",
"this",
".",
"location",
"=",
"this",
".",
"location",
".",
"substr",
"(",
"this",
".",
"location",
".",
"length",
"-",
"1",
")",
"===",
"\"/\"",
"?",
"this",
".",
"location",
":",
"this",
".",
"location",
"+",
"\"/\"",
";",
"}"
] |
Constructor for filesystem cache backend
|
[
"Constructor",
"for",
"filesystem",
"cache",
"backend"
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/cache-backend-fs.js#L23-L28
|
13,217
|
simplecrawler/simplecrawler
|
lib/crawler.js
|
function(string) {
var result = /\ssrcset\s*=\s*("|')(.*?)\1/.exec(string);
return Array.isArray(result) ? String(result[2]).split(",").map(function(string) {
return string.trim().split(/\s+/)[0];
}) : "";
}
|
javascript
|
function(string) {
var result = /\ssrcset\s*=\s*("|')(.*?)\1/.exec(string);
return Array.isArray(result) ? String(result[2]).split(",").map(function(string) {
return string.trim().split(/\s+/)[0];
}) : "";
}
|
[
"function",
"(",
"string",
")",
"{",
"var",
"result",
"=",
"/",
"\\ssrcset\\s*=\\s*(\"|')(.*?)\\1",
"/",
".",
"exec",
"(",
"string",
")",
";",
"return",
"Array",
".",
"isArray",
"(",
"result",
")",
"?",
"String",
"(",
"result",
"[",
"2",
"]",
")",
".",
"split",
"(",
"\",\"",
")",
".",
"map",
"(",
"function",
"(",
"string",
")",
"{",
"return",
"string",
".",
"trim",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
"[",
"0",
"]",
";",
"}",
")",
":",
"\"\"",
";",
"}"
] |
Find srcset links
|
[
"Find",
"srcset",
"links"
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/crawler.js#L340-L345
|
|
13,218
|
simplecrawler/simplecrawler
|
lib/crawler.js
|
isSubdomainOf
|
function isSubdomainOf(subdomain, host) {
// Comparisons must be case-insensitive
subdomain = subdomain.toLowerCase();
host = host.toLowerCase();
// If we're ignoring www, remove it from both
// (if www is the first domain component...)
if (crawler.ignoreWWWDomain) {
subdomain = subdomain.replace(/^www./ig, "");
host = host.replace(/^www./ig, "");
}
// They should be the same flipped around!
return subdomain.split("").reverse().join("").substr(0, host.length) ===
host.split("").reverse().join("");
}
|
javascript
|
function isSubdomainOf(subdomain, host) {
// Comparisons must be case-insensitive
subdomain = subdomain.toLowerCase();
host = host.toLowerCase();
// If we're ignoring www, remove it from both
// (if www is the first domain component...)
if (crawler.ignoreWWWDomain) {
subdomain = subdomain.replace(/^www./ig, "");
host = host.replace(/^www./ig, "");
}
// They should be the same flipped around!
return subdomain.split("").reverse().join("").substr(0, host.length) ===
host.split("").reverse().join("");
}
|
[
"function",
"isSubdomainOf",
"(",
"subdomain",
",",
"host",
")",
"{",
"// Comparisons must be case-insensitive",
"subdomain",
"=",
"subdomain",
".",
"toLowerCase",
"(",
")",
";",
"host",
"=",
"host",
".",
"toLowerCase",
"(",
")",
";",
"// If we're ignoring www, remove it from both",
"// (if www is the first domain component...)",
"if",
"(",
"crawler",
".",
"ignoreWWWDomain",
")",
"{",
"subdomain",
"=",
"subdomain",
".",
"replace",
"(",
"/",
"^www.",
"/",
"ig",
",",
"\"\"",
")",
";",
"host",
"=",
"host",
".",
"replace",
"(",
"/",
"^www.",
"/",
"ig",
",",
"\"\"",
")",
";",
"}",
"// They should be the same flipped around!",
"return",
"subdomain",
".",
"split",
"(",
"\"\"",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"\"\"",
")",
".",
"substr",
"(",
"0",
",",
"host",
".",
"length",
")",
"===",
"host",
".",
"split",
"(",
"\"\"",
")",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"\"\"",
")",
";",
"}"
] |
Checks if the first domain is a subdomain of the second
|
[
"Checks",
"if",
"the",
"first",
"domain",
"is",
"a",
"subdomain",
"of",
"the",
"second"
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/crawler.js#L966-L982
|
13,219
|
simplecrawler/simplecrawler
|
lib/crawler.js
|
processReceivedData
|
function processReceivedData() {
if (dataReceived || queueItem.fetched) {
return;
}
responseBuffer = responseBuffer.slice(0, responseLengthReceived);
dataReceived = true;
timeDataReceived = Date.now();
crawler.queue.update(queueItem.id, {
stateData: {
downloadTime: timeDataReceived - timeHeadersReceived,
requestTime: timeDataReceived - timeCommenced,
actualDataSize: responseBuffer.length,
sentIncorrectSize: responseBuffer.length !== responseLength
}
}, function (error, queueItem) {
if (error) {
// Remove this request from the open request map
crawler._openRequests.splice(
crawler._openRequests.indexOf(response.req), 1);
return crawler.emit("queueerror", error, queueItem);
}
// First, save item to cache (if we're using a cache!)
if (crawler.cache && crawler.cache.setCacheData instanceof Function) {
crawler.cache.setCacheData(queueItem, responseBuffer);
}
// No matter the value of `crawler.decompressResponses`, we still
// decompress the response if it's gzipped or deflated. This is
// because we always provide the discoverResources method with a
// decompressed buffer
if (/(gzip|deflate)/.test(queueItem.stateData.headers["content-encoding"])) {
zlib.unzip(responseBuffer, function(error, decompressedBuffer) {
if (error) {
/**
* Fired when an error was encountered while unzipping the response data
* @event Crawler#gziperror
* @param {QueueItem} queueItem The queue item for which the unzipping failed
* @param {String|Buffer} responseBody If {@link Crawler#decodeResponses} is true, this will be the decoded HTTP response. Otherwise it will be the raw response buffer.
* @param {http.IncomingMessage} response The [http.IncomingMessage]{@link https://nodejs.org/api/http.html#http_class_http_incomingmessage} for the request's response
*/
crawler.emit("gziperror", queueItem, error, responseBuffer);
emitFetchComplete(responseBuffer);
} else {
var responseBody = crawler.decompressResponses ? decompressedBuffer : responseBuffer;
emitFetchComplete(responseBody, decompressedBuffer);
}
});
} else {
emitFetchComplete(responseBuffer);
}
});
}
|
javascript
|
function processReceivedData() {
if (dataReceived || queueItem.fetched) {
return;
}
responseBuffer = responseBuffer.slice(0, responseLengthReceived);
dataReceived = true;
timeDataReceived = Date.now();
crawler.queue.update(queueItem.id, {
stateData: {
downloadTime: timeDataReceived - timeHeadersReceived,
requestTime: timeDataReceived - timeCommenced,
actualDataSize: responseBuffer.length,
sentIncorrectSize: responseBuffer.length !== responseLength
}
}, function (error, queueItem) {
if (error) {
// Remove this request from the open request map
crawler._openRequests.splice(
crawler._openRequests.indexOf(response.req), 1);
return crawler.emit("queueerror", error, queueItem);
}
// First, save item to cache (if we're using a cache!)
if (crawler.cache && crawler.cache.setCacheData instanceof Function) {
crawler.cache.setCacheData(queueItem, responseBuffer);
}
// No matter the value of `crawler.decompressResponses`, we still
// decompress the response if it's gzipped or deflated. This is
// because we always provide the discoverResources method with a
// decompressed buffer
if (/(gzip|deflate)/.test(queueItem.stateData.headers["content-encoding"])) {
zlib.unzip(responseBuffer, function(error, decompressedBuffer) {
if (error) {
/**
* Fired when an error was encountered while unzipping the response data
* @event Crawler#gziperror
* @param {QueueItem} queueItem The queue item for which the unzipping failed
* @param {String|Buffer} responseBody If {@link Crawler#decodeResponses} is true, this will be the decoded HTTP response. Otherwise it will be the raw response buffer.
* @param {http.IncomingMessage} response The [http.IncomingMessage]{@link https://nodejs.org/api/http.html#http_class_http_incomingmessage} for the request's response
*/
crawler.emit("gziperror", queueItem, error, responseBuffer);
emitFetchComplete(responseBuffer);
} else {
var responseBody = crawler.decompressResponses ? decompressedBuffer : responseBuffer;
emitFetchComplete(responseBody, decompressedBuffer);
}
});
} else {
emitFetchComplete(responseBuffer);
}
});
}
|
[
"function",
"processReceivedData",
"(",
")",
"{",
"if",
"(",
"dataReceived",
"||",
"queueItem",
".",
"fetched",
")",
"{",
"return",
";",
"}",
"responseBuffer",
"=",
"responseBuffer",
".",
"slice",
"(",
"0",
",",
"responseLengthReceived",
")",
";",
"dataReceived",
"=",
"true",
";",
"timeDataReceived",
"=",
"Date",
".",
"now",
"(",
")",
";",
"crawler",
".",
"queue",
".",
"update",
"(",
"queueItem",
".",
"id",
",",
"{",
"stateData",
":",
"{",
"downloadTime",
":",
"timeDataReceived",
"-",
"timeHeadersReceived",
",",
"requestTime",
":",
"timeDataReceived",
"-",
"timeCommenced",
",",
"actualDataSize",
":",
"responseBuffer",
".",
"length",
",",
"sentIncorrectSize",
":",
"responseBuffer",
".",
"length",
"!==",
"responseLength",
"}",
"}",
",",
"function",
"(",
"error",
",",
"queueItem",
")",
"{",
"if",
"(",
"error",
")",
"{",
"// Remove this request from the open request map",
"crawler",
".",
"_openRequests",
".",
"splice",
"(",
"crawler",
".",
"_openRequests",
".",
"indexOf",
"(",
"response",
".",
"req",
")",
",",
"1",
")",
";",
"return",
"crawler",
".",
"emit",
"(",
"\"queueerror\"",
",",
"error",
",",
"queueItem",
")",
";",
"}",
"// First, save item to cache (if we're using a cache!)",
"if",
"(",
"crawler",
".",
"cache",
"&&",
"crawler",
".",
"cache",
".",
"setCacheData",
"instanceof",
"Function",
")",
"{",
"crawler",
".",
"cache",
".",
"setCacheData",
"(",
"queueItem",
",",
"responseBuffer",
")",
";",
"}",
"// No matter the value of `crawler.decompressResponses`, we still",
"// decompress the response if it's gzipped or deflated. This is",
"// because we always provide the discoverResources method with a",
"// decompressed buffer",
"if",
"(",
"/",
"(gzip|deflate)",
"/",
".",
"test",
"(",
"queueItem",
".",
"stateData",
".",
"headers",
"[",
"\"content-encoding\"",
"]",
")",
")",
"{",
"zlib",
".",
"unzip",
"(",
"responseBuffer",
",",
"function",
"(",
"error",
",",
"decompressedBuffer",
")",
"{",
"if",
"(",
"error",
")",
"{",
"/**\n * Fired when an error was encountered while unzipping the response data\n * @event Crawler#gziperror\n * @param {QueueItem} queueItem The queue item for which the unzipping failed\n * @param {String|Buffer} responseBody If {@link Crawler#decodeResponses} is true, this will be the decoded HTTP response. Otherwise it will be the raw response buffer.\n * @param {http.IncomingMessage} response The [http.IncomingMessage]{@link https://nodejs.org/api/http.html#http_class_http_incomingmessage} for the request's response\n */",
"crawler",
".",
"emit",
"(",
"\"gziperror\"",
",",
"queueItem",
",",
"error",
",",
"responseBuffer",
")",
";",
"emitFetchComplete",
"(",
"responseBuffer",
")",
";",
"}",
"else",
"{",
"var",
"responseBody",
"=",
"crawler",
".",
"decompressResponses",
"?",
"decompressedBuffer",
":",
"responseBuffer",
";",
"emitFetchComplete",
"(",
"responseBody",
",",
"decompressedBuffer",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"emitFetchComplete",
"(",
"responseBuffer",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Function for dealing with 200 responses
|
[
"Function",
"for",
"dealing",
"with",
"200",
"responses"
] |
2698d15b1ea9cd69285ce3f8b3825975f80f858c
|
https://github.com/simplecrawler/simplecrawler/blob/2698d15b1ea9cd69285ce3f8b3825975f80f858c/lib/crawler.js#L1623-L1678
|
13,220
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addPathHandle
|
function addPathHandle($canvas, parent, xProp, yProp) {
var handle = $.extend({
cursors: {
mouseover: 'grab',
mousedown: 'grabbing',
mouseup: 'grab'
}
}, parent.handle, {
// Define constant properties for handle
layer: true,
draggable: true,
x: parent[xProp],
y: parent[yProp],
_parent: parent,
_xProp: xProp,
_yProp: yProp,
fromCenter: true,
// Adjust line path when dragging a handle
dragstart: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlestart');
},
drag: function (layer) {
var parent = layer._parent;
parent[layer._xProp] = layer.x - parent.x;
parent[layer._yProp] = layer.y - parent.y;
updatePathGuides(parent);
$(this).triggerLayerEvent(parent, 'handlemove');
},
dragstop: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlestop');
},
dragcancel: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlecancel');
}
});
$canvas.draw(handle);
// Add handle to parent layer's list of handles
parent._handles.push($canvas.getLayer(-1));
}
|
javascript
|
function addPathHandle($canvas, parent, xProp, yProp) {
var handle = $.extend({
cursors: {
mouseover: 'grab',
mousedown: 'grabbing',
mouseup: 'grab'
}
}, parent.handle, {
// Define constant properties for handle
layer: true,
draggable: true,
x: parent[xProp],
y: parent[yProp],
_parent: parent,
_xProp: xProp,
_yProp: yProp,
fromCenter: true,
// Adjust line path when dragging a handle
dragstart: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlestart');
},
drag: function (layer) {
var parent = layer._parent;
parent[layer._xProp] = layer.x - parent.x;
parent[layer._yProp] = layer.y - parent.y;
updatePathGuides(parent);
$(this).triggerLayerEvent(parent, 'handlemove');
},
dragstop: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlestop');
},
dragcancel: function (layer) {
$(this).triggerLayerEvent(layer._parent, 'handlecancel');
}
});
$canvas.draw(handle);
// Add handle to parent layer's list of handles
parent._handles.push($canvas.getLayer(-1));
}
|
[
"function",
"addPathHandle",
"(",
"$canvas",
",",
"parent",
",",
"xProp",
",",
"yProp",
")",
"{",
"var",
"handle",
"=",
"$",
".",
"extend",
"(",
"{",
"cursors",
":",
"{",
"mouseover",
":",
"'grab'",
",",
"mousedown",
":",
"'grabbing'",
",",
"mouseup",
":",
"'grab'",
"}",
"}",
",",
"parent",
".",
"handle",
",",
"{",
"// Define constant properties for handle",
"layer",
":",
"true",
",",
"draggable",
":",
"true",
",",
"x",
":",
"parent",
"[",
"xProp",
"]",
",",
"y",
":",
"parent",
"[",
"yProp",
"]",
",",
"_parent",
":",
"parent",
",",
"_xProp",
":",
"xProp",
",",
"_yProp",
":",
"yProp",
",",
"fromCenter",
":",
"true",
",",
"// Adjust line path when dragging a handle",
"dragstart",
":",
"function",
"(",
"layer",
")",
"{",
"$",
"(",
"this",
")",
".",
"triggerLayerEvent",
"(",
"layer",
".",
"_parent",
",",
"'handlestart'",
")",
";",
"}",
",",
"drag",
":",
"function",
"(",
"layer",
")",
"{",
"var",
"parent",
"=",
"layer",
".",
"_parent",
";",
"parent",
"[",
"layer",
".",
"_xProp",
"]",
"=",
"layer",
".",
"x",
"-",
"parent",
".",
"x",
";",
"parent",
"[",
"layer",
".",
"_yProp",
"]",
"=",
"layer",
".",
"y",
"-",
"parent",
".",
"y",
";",
"updatePathGuides",
"(",
"parent",
")",
";",
"$",
"(",
"this",
")",
".",
"triggerLayerEvent",
"(",
"parent",
",",
"'handlemove'",
")",
";",
"}",
",",
"dragstop",
":",
"function",
"(",
"layer",
")",
"{",
"$",
"(",
"this",
")",
".",
"triggerLayerEvent",
"(",
"layer",
".",
"_parent",
",",
"'handlestop'",
")",
";",
"}",
",",
"dragcancel",
":",
"function",
"(",
"layer",
")",
"{",
"$",
"(",
"this",
")",
".",
"triggerLayerEvent",
"(",
"layer",
".",
"_parent",
",",
"'handlecancel'",
")",
";",
"}",
"}",
")",
";",
"$canvas",
".",
"draw",
"(",
"handle",
")",
";",
"// Add handle to parent layer's list of handles",
"parent",
".",
"_handles",
".",
"push",
"(",
"$canvas",
".",
"getLayer",
"(",
"-",
"1",
")",
")",
";",
"}"
] |
Add a single handle to line path
|
[
"Add",
"a",
"single",
"handle",
"to",
"line",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L35-L74
|
13,221
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
function (layer) {
var parent = layer._parent;
if (parent.width + (layer.dx * layer._px) < parent.minWidth) {
parent.width = parent.minWidth;
layer.dx = 0;
}
if (parent.height + (layer.dy * layer._py) < parent.minHeight) {
parent.height = parent.minHeight;
layer.dy = 0;
}
if (!parent.resizeFromCenter) {
// Optionally constrain proportions
if (parent.constrainProportions) {
if (layer._py === 0) {
// Manage handles whose y is at layer's center
parent.height = parent.width / parent.aspectRatio;
} else {
// Manage every other handle
parent.width = parent.height * parent.aspectRatio;
layer.dx = layer.dy * parent.aspectRatio * layer._py * layer._px;
}
}
// Optionally resize rectangle from corner
if (parent.fromCenter) {
parent.width += layer.dx * layer._px;
parent.height += layer.dy * layer._py;
} else {
// This is simplified version based on math. Also you can write this using an if statement for each handle
parent.width += layer.dx * layer._px;
if (layer._px !== 0) {
parent.x += layer.dx * ((1 - layer._px) && (1 - layer._px) / Math.abs((1 - layer._px)));
}
parent.height += layer.dy * layer._py;
if (layer._py !== 0) {
parent.y += layer.dy * ((1 - layer._py) && (1 - layer._py) / Math.abs((1 - layer._py)));
}
}
// Ensure diagonal handle does not move
if (parent.fromCenter) {
if (layer._px !== 0) {
parent.x += layer.dx / 2;
}
if (layer._py !== 0) {
parent.y += layer.dy / 2;
}
}
} else {
// Otherwise, resize rectangle from center
parent.width += layer.dx * layer._px * 2;
parent.height += layer.dy * layer._py * 2;
// Optionally constrain proportions
if (parent.constrainProportions) {
if (layer._py === 0) {
// Manage handles whose y is at layer's center
parent.height = parent.width / parent.aspectRatio;
} else {
// Manage every other handle
parent.width = parent.height * parent.aspectRatio;
}
}
}
updateRectHandles(parent);
$(this).triggerLayerEvent(parent, 'handlemove');
}
|
javascript
|
function (layer) {
var parent = layer._parent;
if (parent.width + (layer.dx * layer._px) < parent.minWidth) {
parent.width = parent.minWidth;
layer.dx = 0;
}
if (parent.height + (layer.dy * layer._py) < parent.minHeight) {
parent.height = parent.minHeight;
layer.dy = 0;
}
if (!parent.resizeFromCenter) {
// Optionally constrain proportions
if (parent.constrainProportions) {
if (layer._py === 0) {
// Manage handles whose y is at layer's center
parent.height = parent.width / parent.aspectRatio;
} else {
// Manage every other handle
parent.width = parent.height * parent.aspectRatio;
layer.dx = layer.dy * parent.aspectRatio * layer._py * layer._px;
}
}
// Optionally resize rectangle from corner
if (parent.fromCenter) {
parent.width += layer.dx * layer._px;
parent.height += layer.dy * layer._py;
} else {
// This is simplified version based on math. Also you can write this using an if statement for each handle
parent.width += layer.dx * layer._px;
if (layer._px !== 0) {
parent.x += layer.dx * ((1 - layer._px) && (1 - layer._px) / Math.abs((1 - layer._px)));
}
parent.height += layer.dy * layer._py;
if (layer._py !== 0) {
parent.y += layer.dy * ((1 - layer._py) && (1 - layer._py) / Math.abs((1 - layer._py)));
}
}
// Ensure diagonal handle does not move
if (parent.fromCenter) {
if (layer._px !== 0) {
parent.x += layer.dx / 2;
}
if (layer._py !== 0) {
parent.y += layer.dy / 2;
}
}
} else {
// Otherwise, resize rectangle from center
parent.width += layer.dx * layer._px * 2;
parent.height += layer.dy * layer._py * 2;
// Optionally constrain proportions
if (parent.constrainProportions) {
if (layer._py === 0) {
// Manage handles whose y is at layer's center
parent.height = parent.width / parent.aspectRatio;
} else {
// Manage every other handle
parent.width = parent.height * parent.aspectRatio;
}
}
}
updateRectHandles(parent);
$(this).triggerLayerEvent(parent, 'handlemove');
}
|
[
"function",
"(",
"layer",
")",
"{",
"var",
"parent",
"=",
"layer",
".",
"_parent",
";",
"if",
"(",
"parent",
".",
"width",
"+",
"(",
"layer",
".",
"dx",
"*",
"layer",
".",
"_px",
")",
"<",
"parent",
".",
"minWidth",
")",
"{",
"parent",
".",
"width",
"=",
"parent",
".",
"minWidth",
";",
"layer",
".",
"dx",
"=",
"0",
";",
"}",
"if",
"(",
"parent",
".",
"height",
"+",
"(",
"layer",
".",
"dy",
"*",
"layer",
".",
"_py",
")",
"<",
"parent",
".",
"minHeight",
")",
"{",
"parent",
".",
"height",
"=",
"parent",
".",
"minHeight",
";",
"layer",
".",
"dy",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"parent",
".",
"resizeFromCenter",
")",
"{",
"// Optionally constrain proportions",
"if",
"(",
"parent",
".",
"constrainProportions",
")",
"{",
"if",
"(",
"layer",
".",
"_py",
"===",
"0",
")",
"{",
"// Manage handles whose y is at layer's center",
"parent",
".",
"height",
"=",
"parent",
".",
"width",
"/",
"parent",
".",
"aspectRatio",
";",
"}",
"else",
"{",
"// Manage every other handle",
"parent",
".",
"width",
"=",
"parent",
".",
"height",
"*",
"parent",
".",
"aspectRatio",
";",
"layer",
".",
"dx",
"=",
"layer",
".",
"dy",
"*",
"parent",
".",
"aspectRatio",
"*",
"layer",
".",
"_py",
"*",
"layer",
".",
"_px",
";",
"}",
"}",
"// Optionally resize rectangle from corner",
"if",
"(",
"parent",
".",
"fromCenter",
")",
"{",
"parent",
".",
"width",
"+=",
"layer",
".",
"dx",
"*",
"layer",
".",
"_px",
";",
"parent",
".",
"height",
"+=",
"layer",
".",
"dy",
"*",
"layer",
".",
"_py",
";",
"}",
"else",
"{",
"// This is simplified version based on math. Also you can write this using an if statement for each handle",
"parent",
".",
"width",
"+=",
"layer",
".",
"dx",
"*",
"layer",
".",
"_px",
";",
"if",
"(",
"layer",
".",
"_px",
"!==",
"0",
")",
"{",
"parent",
".",
"x",
"+=",
"layer",
".",
"dx",
"*",
"(",
"(",
"1",
"-",
"layer",
".",
"_px",
")",
"&&",
"(",
"1",
"-",
"layer",
".",
"_px",
")",
"/",
"Math",
".",
"abs",
"(",
"(",
"1",
"-",
"layer",
".",
"_px",
")",
")",
")",
";",
"}",
"parent",
".",
"height",
"+=",
"layer",
".",
"dy",
"*",
"layer",
".",
"_py",
";",
"if",
"(",
"layer",
".",
"_py",
"!==",
"0",
")",
"{",
"parent",
".",
"y",
"+=",
"layer",
".",
"dy",
"*",
"(",
"(",
"1",
"-",
"layer",
".",
"_py",
")",
"&&",
"(",
"1",
"-",
"layer",
".",
"_py",
")",
"/",
"Math",
".",
"abs",
"(",
"(",
"1",
"-",
"layer",
".",
"_py",
")",
")",
")",
";",
"}",
"}",
"// Ensure diagonal handle does not move",
"if",
"(",
"parent",
".",
"fromCenter",
")",
"{",
"if",
"(",
"layer",
".",
"_px",
"!==",
"0",
")",
"{",
"parent",
".",
"x",
"+=",
"layer",
".",
"dx",
"/",
"2",
";",
"}",
"if",
"(",
"layer",
".",
"_py",
"!==",
"0",
")",
"{",
"parent",
".",
"y",
"+=",
"layer",
".",
"dy",
"/",
"2",
";",
"}",
"}",
"}",
"else",
"{",
"// Otherwise, resize rectangle from center",
"parent",
".",
"width",
"+=",
"layer",
".",
"dx",
"*",
"layer",
".",
"_px",
"*",
"2",
";",
"parent",
".",
"height",
"+=",
"layer",
".",
"dy",
"*",
"layer",
".",
"_py",
"*",
"2",
";",
"// Optionally constrain proportions",
"if",
"(",
"parent",
".",
"constrainProportions",
")",
"{",
"if",
"(",
"layer",
".",
"_py",
"===",
"0",
")",
"{",
"// Manage handles whose y is at layer's center",
"parent",
".",
"height",
"=",
"parent",
".",
"width",
"/",
"parent",
".",
"aspectRatio",
";",
"}",
"else",
"{",
"// Manage every other handle",
"parent",
".",
"width",
"=",
"parent",
".",
"height",
"*",
"parent",
".",
"aspectRatio",
";",
"}",
"}",
"}",
"updateRectHandles",
"(",
"parent",
")",
";",
"$",
"(",
"this",
")",
".",
"triggerLayerEvent",
"(",
"parent",
",",
"'handlemove'",
")",
";",
"}"
] |
Resize rectangle when dragging a handle
|
[
"Resize",
"rectangle",
"when",
"dragging",
"a",
"handle"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L110-L175
|
|
13,222
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addRectHandles
|
function addRectHandles($canvas, parent) {
var handlePlacement = parent.handlePlacement;
// Store current width-to-height ratio
if (parent.aspectRatio === null && parent.height !== 0) {
parent.aspectRatio = parent.width / parent.height;
}
// Optionally add handles to corners
if (handlePlacement === 'corners' || handlePlacement === 'both') {
addRectHandle($canvas, parent, -1, -1);
addRectHandle($canvas, parent, 1, -1);
addRectHandle($canvas, parent, 1, 1);
addRectHandle($canvas, parent, -1, 1);
}
// Optionally add handles to sides
if (handlePlacement === 'sides' || handlePlacement === 'both') {
addRectHandle($canvas, parent, 0, -1);
addRectHandle($canvas, parent, 1, 0);
addRectHandle($canvas, parent, 0, 1);
addRectHandle($canvas, parent, -1, 0);
}
// Optionally add handle guides
if (parent.guide) {
addRectGuides($canvas, parent);
}
}
|
javascript
|
function addRectHandles($canvas, parent) {
var handlePlacement = parent.handlePlacement;
// Store current width-to-height ratio
if (parent.aspectRatio === null && parent.height !== 0) {
parent.aspectRatio = parent.width / parent.height;
}
// Optionally add handles to corners
if (handlePlacement === 'corners' || handlePlacement === 'both') {
addRectHandle($canvas, parent, -1, -1);
addRectHandle($canvas, parent, 1, -1);
addRectHandle($canvas, parent, 1, 1);
addRectHandle($canvas, parent, -1, 1);
}
// Optionally add handles to sides
if (handlePlacement === 'sides' || handlePlacement === 'both') {
addRectHandle($canvas, parent, 0, -1);
addRectHandle($canvas, parent, 1, 0);
addRectHandle($canvas, parent, 0, 1);
addRectHandle($canvas, parent, -1, 0);
}
// Optionally add handle guides
if (parent.guide) {
addRectGuides($canvas, parent);
}
}
|
[
"function",
"addRectHandles",
"(",
"$canvas",
",",
"parent",
")",
"{",
"var",
"handlePlacement",
"=",
"parent",
".",
"handlePlacement",
";",
"// Store current width-to-height ratio",
"if",
"(",
"parent",
".",
"aspectRatio",
"===",
"null",
"&&",
"parent",
".",
"height",
"!==",
"0",
")",
"{",
"parent",
".",
"aspectRatio",
"=",
"parent",
".",
"width",
"/",
"parent",
".",
"height",
";",
"}",
"// Optionally add handles to corners",
"if",
"(",
"handlePlacement",
"===",
"'corners'",
"||",
"handlePlacement",
"===",
"'both'",
")",
"{",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"-",
"1",
",",
"-",
"1",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"1",
",",
"-",
"1",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"1",
",",
"1",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"-",
"1",
",",
"1",
")",
";",
"}",
"// Optionally add handles to sides",
"if",
"(",
"handlePlacement",
"===",
"'sides'",
"||",
"handlePlacement",
"===",
"'both'",
")",
"{",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"0",
",",
"-",
"1",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"1",
",",
"0",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"0",
",",
"1",
")",
";",
"addRectHandle",
"(",
"$canvas",
",",
"parent",
",",
"-",
"1",
",",
"0",
")",
";",
"}",
"// Optionally add handle guides",
"if",
"(",
"parent",
".",
"guide",
")",
"{",
"addRectGuides",
"(",
"$canvas",
",",
"parent",
")",
";",
"}",
"}"
] |
Add all handles to rectangle
|
[
"Add",
"all",
"handles",
"to",
"rectangle"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L191-L215
|
13,223
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
updateRectGuides
|
function updateRectGuides(parent) {
var guide = parent._guide;
if (guide) {
guide.x = parent.x;
guide.y = parent.y;
guide.width = parent.width;
guide.height = parent.height;
guide.fromCenter = parent.fromCenter;
}
}
|
javascript
|
function updateRectGuides(parent) {
var guide = parent._guide;
if (guide) {
guide.x = parent.x;
guide.y = parent.y;
guide.width = parent.width;
guide.height = parent.height;
guide.fromCenter = parent.fromCenter;
}
}
|
[
"function",
"updateRectGuides",
"(",
"parent",
")",
"{",
"var",
"guide",
"=",
"parent",
".",
"_guide",
";",
"if",
"(",
"guide",
")",
"{",
"guide",
".",
"x",
"=",
"parent",
".",
"x",
";",
"guide",
".",
"y",
"=",
"parent",
".",
"y",
";",
"guide",
".",
"width",
"=",
"parent",
".",
"width",
";",
"guide",
".",
"height",
"=",
"parent",
".",
"height",
";",
"guide",
".",
"fromCenter",
"=",
"parent",
".",
"fromCenter",
";",
"}",
"}"
] |
Update handle guides for rectangular layer
|
[
"Update",
"handle",
"guides",
"for",
"rectangular",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L218-L227
|
13,224
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addRectGuides
|
function addRectGuides($canvas, parent) {
var guideProps, guide;
guideProps = $.extend({}, parent.guide, {
layer: true,
draggable: false,
type: 'rectangle',
handle: null
});
$canvas.addLayer(guideProps);
guide = $canvas.getLayer(-1);
parent._guide = guide;
$canvas.moveLayer(guide, -parent._handles.length - 1);
updateRectGuides(parent);
}
|
javascript
|
function addRectGuides($canvas, parent) {
var guideProps, guide;
guideProps = $.extend({}, parent.guide, {
layer: true,
draggable: false,
type: 'rectangle',
handle: null
});
$canvas.addLayer(guideProps);
guide = $canvas.getLayer(-1);
parent._guide = guide;
$canvas.moveLayer(guide, -parent._handles.length - 1);
updateRectGuides(parent);
}
|
[
"function",
"addRectGuides",
"(",
"$canvas",
",",
"parent",
")",
"{",
"var",
"guideProps",
",",
"guide",
";",
"guideProps",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"parent",
".",
"guide",
",",
"{",
"layer",
":",
"true",
",",
"draggable",
":",
"false",
",",
"type",
":",
"'rectangle'",
",",
"handle",
":",
"null",
"}",
")",
";",
"$canvas",
".",
"addLayer",
"(",
"guideProps",
")",
";",
"guide",
"=",
"$canvas",
".",
"getLayer",
"(",
"-",
"1",
")",
";",
"parent",
".",
"_guide",
"=",
"guide",
";",
"$canvas",
".",
"moveLayer",
"(",
"guide",
",",
"-",
"parent",
".",
"_handles",
".",
"length",
"-",
"1",
")",
";",
"updateRectGuides",
"(",
"parent",
")",
";",
"}"
] |
Add handle guides to rectangular layer
|
[
"Add",
"handle",
"guides",
"to",
"rectangular",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L230-L243
|
13,225
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addPathHandles
|
function addPathHandles($canvas, parent) {
var key, xProp, yProp;
for (key in parent) {
if (Object.prototype.hasOwnProperty.call(parent, key)) {
// If property is a control point
if (key.match(/c?x(\d+)/gi) !== null) {
// Get the x and y coordinates for that control point
xProp = key;
yProp = key.replace('x', 'y');
// Add handle at control point
addPathHandle($canvas, parent, xProp, yProp);
}
}
}
// Add guides connecting handles
if (parent.guide) {
addPathGuides($canvas, parent);
}
}
|
javascript
|
function addPathHandles($canvas, parent) {
var key, xProp, yProp;
for (key in parent) {
if (Object.prototype.hasOwnProperty.call(parent, key)) {
// If property is a control point
if (key.match(/c?x(\d+)/gi) !== null) {
// Get the x and y coordinates for that control point
xProp = key;
yProp = key.replace('x', 'y');
// Add handle at control point
addPathHandle($canvas, parent, xProp, yProp);
}
}
}
// Add guides connecting handles
if (parent.guide) {
addPathGuides($canvas, parent);
}
}
|
[
"function",
"addPathHandles",
"(",
"$canvas",
",",
"parent",
")",
"{",
"var",
"key",
",",
"xProp",
",",
"yProp",
";",
"for",
"(",
"key",
"in",
"parent",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"parent",
",",
"key",
")",
")",
"{",
"// If property is a control point",
"if",
"(",
"key",
".",
"match",
"(",
"/",
"c?x(\\d+)",
"/",
"gi",
")",
"!==",
"null",
")",
"{",
"// Get the x and y coordinates for that control point",
"xProp",
"=",
"key",
";",
"yProp",
"=",
"key",
".",
"replace",
"(",
"'x'",
",",
"'y'",
")",
";",
"// Add handle at control point",
"addPathHandle",
"(",
"$canvas",
",",
"parent",
",",
"xProp",
",",
"yProp",
")",
";",
"}",
"}",
"}",
"// Add guides connecting handles",
"if",
"(",
"parent",
".",
"guide",
")",
"{",
"addPathGuides",
"(",
"$canvas",
",",
"parent",
")",
";",
"}",
"}"
] |
Add handles to line path
|
[
"Add",
"handles",
"to",
"line",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L246-L264
|
13,226
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
updatePathGuides
|
function updatePathGuides(parent) {
var handles = parent._handles,
guides = parent._guides,
handle, h,
guide, g;
if (parent._method === $.fn.drawQuadratic) {
if (handles) {
guide = parent._guide;
if (guide) {
for (h = 0; h < handles.length; h += 1) {
handle = parent._handles[h];
guide['x' + (h + 1)] = handle.x;
guide['y' + (h + 1)] = handle.y;
}
}
}
} else if (parent._method === $.fn.drawBezier) {
if (guides) {
for (g = 0; g < guides.length; g += 1) {
guide = guides[g];
handles = guide._handles;
if (guide && handles) {
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
guide['x' + (h + 1)] = handle.x;
guide['y' + (h + 1)] = handle.y;
}
}
}
}
}
}
|
javascript
|
function updatePathGuides(parent) {
var handles = parent._handles,
guides = parent._guides,
handle, h,
guide, g;
if (parent._method === $.fn.drawQuadratic) {
if (handles) {
guide = parent._guide;
if (guide) {
for (h = 0; h < handles.length; h += 1) {
handle = parent._handles[h];
guide['x' + (h + 1)] = handle.x;
guide['y' + (h + 1)] = handle.y;
}
}
}
} else if (parent._method === $.fn.drawBezier) {
if (guides) {
for (g = 0; g < guides.length; g += 1) {
guide = guides[g];
handles = guide._handles;
if (guide && handles) {
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
guide['x' + (h + 1)] = handle.x;
guide['y' + (h + 1)] = handle.y;
}
}
}
}
}
}
|
[
"function",
"updatePathGuides",
"(",
"parent",
")",
"{",
"var",
"handles",
"=",
"parent",
".",
"_handles",
",",
"guides",
"=",
"parent",
".",
"_guides",
",",
"handle",
",",
"h",
",",
"guide",
",",
"g",
";",
"if",
"(",
"parent",
".",
"_method",
"===",
"$",
".",
"fn",
".",
"drawQuadratic",
")",
"{",
"if",
"(",
"handles",
")",
"{",
"guide",
"=",
"parent",
".",
"_guide",
";",
"if",
"(",
"guide",
")",
"{",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"parent",
".",
"_handles",
"[",
"h",
"]",
";",
"guide",
"[",
"'x'",
"+",
"(",
"h",
"+",
"1",
")",
"]",
"=",
"handle",
".",
"x",
";",
"guide",
"[",
"'y'",
"+",
"(",
"h",
"+",
"1",
")",
"]",
"=",
"handle",
".",
"y",
";",
"}",
"}",
"}",
"}",
"else",
"if",
"(",
"parent",
".",
"_method",
"===",
"$",
".",
"fn",
".",
"drawBezier",
")",
"{",
"if",
"(",
"guides",
")",
"{",
"for",
"(",
"g",
"=",
"0",
";",
"g",
"<",
"guides",
".",
"length",
";",
"g",
"+=",
"1",
")",
"{",
"guide",
"=",
"guides",
"[",
"g",
"]",
";",
"handles",
"=",
"guide",
".",
"_handles",
";",
"if",
"(",
"guide",
"&&",
"handles",
")",
"{",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"handles",
"[",
"h",
"]",
";",
"guide",
"[",
"'x'",
"+",
"(",
"h",
"+",
"1",
")",
"]",
"=",
"handle",
".",
"x",
";",
"guide",
"[",
"'y'",
"+",
"(",
"h",
"+",
"1",
")",
"]",
"=",
"handle",
".",
"y",
";",
"}",
"}",
"}",
"}",
"}",
"}"
] |
Update handle guides for line path
|
[
"Update",
"handle",
"guides",
"for",
"line",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L267-L298
|
13,227
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addPathGuides
|
function addPathGuides($canvas, parent) {
var handles = parent._handles,
prevHandle, nextHandle, otherHandle,
handle, h,
guide, guideProps;
guideProps = $.extend({}, parent.guide, {
layer: true,
draggable: false,
type: 'line'
});
if (parent._method === $.fn.drawQuadratic) {
$canvas.addLayer(guideProps);
parent._guide = $canvas.getLayer(-1);
$canvas.moveLayer(parent._guide, -handles.length - 1);
} else if (parent._method === $.fn.drawBezier) {
parent._guides = [];
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
nextHandle = handles[h + 1];
prevHandle = handles[h - 1];
otherHandle = null;
if (nextHandle !== undefined) {
// If handle is a start/end point and next handle is a control point
if (handle._xProp.indexOf('x') === 0 && nextHandle._xProp.indexOf('cx') === 0) {
otherHandle = nextHandle;
}
} else if (prevHandle !== undefined) {
if (prevHandle._xProp.indexOf('cx') === 0 && handle._xProp.indexOf('x') === 0) {
otherHandle = prevHandle;
}
}
if (otherHandle !== null) {
$canvas.addLayer(guideProps);
guide = $canvas.getLayer(-1);
guide._handles = [handle, otherHandle];
parent._guides.push(guide);
$canvas.moveLayer(guide, -handles.length - 1);
}
}
}
updatePathGuides(parent);
}
|
javascript
|
function addPathGuides($canvas, parent) {
var handles = parent._handles,
prevHandle, nextHandle, otherHandle,
handle, h,
guide, guideProps;
guideProps = $.extend({}, parent.guide, {
layer: true,
draggable: false,
type: 'line'
});
if (parent._method === $.fn.drawQuadratic) {
$canvas.addLayer(guideProps);
parent._guide = $canvas.getLayer(-1);
$canvas.moveLayer(parent._guide, -handles.length - 1);
} else if (parent._method === $.fn.drawBezier) {
parent._guides = [];
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
nextHandle = handles[h + 1];
prevHandle = handles[h - 1];
otherHandle = null;
if (nextHandle !== undefined) {
// If handle is a start/end point and next handle is a control point
if (handle._xProp.indexOf('x') === 0 && nextHandle._xProp.indexOf('cx') === 0) {
otherHandle = nextHandle;
}
} else if (prevHandle !== undefined) {
if (prevHandle._xProp.indexOf('cx') === 0 && handle._xProp.indexOf('x') === 0) {
otherHandle = prevHandle;
}
}
if (otherHandle !== null) {
$canvas.addLayer(guideProps);
guide = $canvas.getLayer(-1);
guide._handles = [handle, otherHandle];
parent._guides.push(guide);
$canvas.moveLayer(guide, -handles.length - 1);
}
}
}
updatePathGuides(parent);
}
|
[
"function",
"addPathGuides",
"(",
"$canvas",
",",
"parent",
")",
"{",
"var",
"handles",
"=",
"parent",
".",
"_handles",
",",
"prevHandle",
",",
"nextHandle",
",",
"otherHandle",
",",
"handle",
",",
"h",
",",
"guide",
",",
"guideProps",
";",
"guideProps",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"parent",
".",
"guide",
",",
"{",
"layer",
":",
"true",
",",
"draggable",
":",
"false",
",",
"type",
":",
"'line'",
"}",
")",
";",
"if",
"(",
"parent",
".",
"_method",
"===",
"$",
".",
"fn",
".",
"drawQuadratic",
")",
"{",
"$canvas",
".",
"addLayer",
"(",
"guideProps",
")",
";",
"parent",
".",
"_guide",
"=",
"$canvas",
".",
"getLayer",
"(",
"-",
"1",
")",
";",
"$canvas",
".",
"moveLayer",
"(",
"parent",
".",
"_guide",
",",
"-",
"handles",
".",
"length",
"-",
"1",
")",
";",
"}",
"else",
"if",
"(",
"parent",
".",
"_method",
"===",
"$",
".",
"fn",
".",
"drawBezier",
")",
"{",
"parent",
".",
"_guides",
"=",
"[",
"]",
";",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"handles",
"[",
"h",
"]",
";",
"nextHandle",
"=",
"handles",
"[",
"h",
"+",
"1",
"]",
";",
"prevHandle",
"=",
"handles",
"[",
"h",
"-",
"1",
"]",
";",
"otherHandle",
"=",
"null",
";",
"if",
"(",
"nextHandle",
"!==",
"undefined",
")",
"{",
"// If handle is a start/end point and next handle is a control point",
"if",
"(",
"handle",
".",
"_xProp",
".",
"indexOf",
"(",
"'x'",
")",
"===",
"0",
"&&",
"nextHandle",
".",
"_xProp",
".",
"indexOf",
"(",
"'cx'",
")",
"===",
"0",
")",
"{",
"otherHandle",
"=",
"nextHandle",
";",
"}",
"}",
"else",
"if",
"(",
"prevHandle",
"!==",
"undefined",
")",
"{",
"if",
"(",
"prevHandle",
".",
"_xProp",
".",
"indexOf",
"(",
"'cx'",
")",
"===",
"0",
"&&",
"handle",
".",
"_xProp",
".",
"indexOf",
"(",
"'x'",
")",
"===",
"0",
")",
"{",
"otherHandle",
"=",
"prevHandle",
";",
"}",
"}",
"if",
"(",
"otherHandle",
"!==",
"null",
")",
"{",
"$canvas",
".",
"addLayer",
"(",
"guideProps",
")",
";",
"guide",
"=",
"$canvas",
".",
"getLayer",
"(",
"-",
"1",
")",
";",
"guide",
".",
"_handles",
"=",
"[",
"handle",
",",
"otherHandle",
"]",
";",
"parent",
".",
"_guides",
".",
"push",
"(",
"guide",
")",
";",
"$canvas",
".",
"moveLayer",
"(",
"guide",
",",
"-",
"handles",
".",
"length",
"-",
"1",
")",
";",
"}",
"}",
"}",
"updatePathGuides",
"(",
"parent",
")",
";",
"}"
] |
Add guides to path layer
|
[
"Add",
"guides",
"to",
"path",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L301-L342
|
13,228
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
updateRectHandles
|
function updateRectHandles(parent) {
var handle, h;
if (parent._handles) {
// Move handles when dragging
for (h = 0; h < parent._handles.length; h += 1) {
handle = parent._handles[h];
handle.x = parent.x + ((parent.width / 2 * handle._px) + ((parent.fromCenter) ? 0 : parent.width / 2));
handle.y = parent.y + ((parent.height / 2 * handle._py) + ((parent.fromCenter) ? 0 : parent.height / 2));
}
}
updateRectGuides(parent);
}
|
javascript
|
function updateRectHandles(parent) {
var handle, h;
if (parent._handles) {
// Move handles when dragging
for (h = 0; h < parent._handles.length; h += 1) {
handle = parent._handles[h];
handle.x = parent.x + ((parent.width / 2 * handle._px) + ((parent.fromCenter) ? 0 : parent.width / 2));
handle.y = parent.y + ((parent.height / 2 * handle._py) + ((parent.fromCenter) ? 0 : parent.height / 2));
}
}
updateRectGuides(parent);
}
|
[
"function",
"updateRectHandles",
"(",
"parent",
")",
"{",
"var",
"handle",
",",
"h",
";",
"if",
"(",
"parent",
".",
"_handles",
")",
"{",
"// Move handles when dragging",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"parent",
".",
"_handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"parent",
".",
"_handles",
"[",
"h",
"]",
";",
"handle",
".",
"x",
"=",
"parent",
".",
"x",
"+",
"(",
"(",
"parent",
".",
"width",
"/",
"2",
"*",
"handle",
".",
"_px",
")",
"+",
"(",
"(",
"parent",
".",
"fromCenter",
")",
"?",
"0",
":",
"parent",
".",
"width",
"/",
"2",
")",
")",
";",
"handle",
".",
"y",
"=",
"parent",
".",
"y",
"+",
"(",
"(",
"parent",
".",
"height",
"/",
"2",
"*",
"handle",
".",
"_py",
")",
"+",
"(",
"(",
"parent",
".",
"fromCenter",
")",
"?",
"0",
":",
"parent",
".",
"height",
"/",
"2",
")",
")",
";",
"}",
"}",
"updateRectGuides",
"(",
"parent",
")",
";",
"}"
] |
Update position of handles according to size and dimensions of rectangular layer
|
[
"Update",
"position",
"of",
"handles",
"according",
"to",
"size",
"and",
"dimensions",
"of",
"rectangular",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L346-L357
|
13,229
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
updatePathHandles
|
function updatePathHandles(parent) {
var handles = parent._handles,
handle, h;
if (handles) {
// Move handles when dragging
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
handle.x = parent[handle._xProp] + parent.x;
handle.y = parent[handle._yProp] + parent.y;
}
}
updatePathGuides(parent);
}
|
javascript
|
function updatePathHandles(parent) {
var handles = parent._handles,
handle, h;
if (handles) {
// Move handles when dragging
for (h = 0; h < handles.length; h += 1) {
handle = handles[h];
handle.x = parent[handle._xProp] + parent.x;
handle.y = parent[handle._yProp] + parent.y;
}
}
updatePathGuides(parent);
}
|
[
"function",
"updatePathHandles",
"(",
"parent",
")",
"{",
"var",
"handles",
"=",
"parent",
".",
"_handles",
",",
"handle",
",",
"h",
";",
"if",
"(",
"handles",
")",
"{",
"// Move handles when dragging",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"handles",
"[",
"h",
"]",
";",
"handle",
".",
"x",
"=",
"parent",
"[",
"handle",
".",
"_xProp",
"]",
"+",
"parent",
".",
"x",
";",
"handle",
".",
"y",
"=",
"parent",
"[",
"handle",
".",
"_yProp",
"]",
"+",
"parent",
".",
"y",
";",
"}",
"}",
"updatePathGuides",
"(",
"parent",
")",
";",
"}"
] |
Update position of handles according to coordinates and dimensions of path layer
|
[
"Update",
"position",
"of",
"handles",
"according",
"to",
"coordinates",
"and",
"dimensions",
"of",
"path",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L361-L373
|
13,230
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
addHandles
|
function addHandles(parent) {
var $canvas = $(parent.canvas);
// If parent's list of handles doesn't exist
if (parent._handles === undefined) {
// Create list to store handles
parent._handles = [];
}
if (isRectLayer(parent)) {
// Add four handles to corners of a rectangle/ellipse/image
addRectHandles($canvas, parent);
} else if (isPathLayer(parent)) {
// Add two or more handles to a line path
addPathHandles($canvas, parent);
}
}
|
javascript
|
function addHandles(parent) {
var $canvas = $(parent.canvas);
// If parent's list of handles doesn't exist
if (parent._handles === undefined) {
// Create list to store handles
parent._handles = [];
}
if (isRectLayer(parent)) {
// Add four handles to corners of a rectangle/ellipse/image
addRectHandles($canvas, parent);
} else if (isPathLayer(parent)) {
// Add two or more handles to a line path
addPathHandles($canvas, parent);
}
}
|
[
"function",
"addHandles",
"(",
"parent",
")",
"{",
"var",
"$canvas",
"=",
"$",
"(",
"parent",
".",
"canvas",
")",
";",
"// If parent's list of handles doesn't exist",
"if",
"(",
"parent",
".",
"_handles",
"===",
"undefined",
")",
"{",
"// Create list to store handles",
"parent",
".",
"_handles",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"isRectLayer",
"(",
"parent",
")",
")",
"{",
"// Add four handles to corners of a rectangle/ellipse/image",
"addRectHandles",
"(",
"$canvas",
",",
"parent",
")",
";",
"}",
"else",
"if",
"(",
"isPathLayer",
"(",
"parent",
")",
")",
"{",
"// Add two or more handles to a line path",
"addPathHandles",
"(",
"$canvas",
",",
"parent",
")",
";",
"}",
"}"
] |
Add drag handles to all four corners of rectangle layer
|
[
"Add",
"drag",
"handles",
"to",
"all",
"four",
"corners",
"of",
"rectangle",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L377-L393
|
13,231
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
removeHandles
|
function removeHandles(layer) {
var $canvas = $(layer.canvas), handle, h;
if (layer._handles) {
// Remove handles from layer
for (h = 0; h < layer._handles.length; h += 1) {
handle = layer._handles[h];
$canvas.removeLayer(handle);
}
layer._handles.length = 0;
}
}
|
javascript
|
function removeHandles(layer) {
var $canvas = $(layer.canvas), handle, h;
if (layer._handles) {
// Remove handles from layer
for (h = 0; h < layer._handles.length; h += 1) {
handle = layer._handles[h];
$canvas.removeLayer(handle);
}
layer._handles.length = 0;
}
}
|
[
"function",
"removeHandles",
"(",
"layer",
")",
"{",
"var",
"$canvas",
"=",
"$",
"(",
"layer",
".",
"canvas",
")",
",",
"handle",
",",
"h",
";",
"if",
"(",
"layer",
".",
"_handles",
")",
"{",
"// Remove handles from layer",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"layer",
".",
"_handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"layer",
".",
"_handles",
"[",
"h",
"]",
";",
"$canvas",
".",
"removeLayer",
"(",
"handle",
")",
";",
"}",
"layer",
".",
"_handles",
".",
"length",
"=",
"0",
";",
"}",
"}"
] |
Remove handles if handle property was removed
|
[
"Remove",
"handles",
"if",
"handle",
"property",
"was",
"removed"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L396-L406
|
13,232
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
function (layer) {
var $canvas, handle, h;
if (layer._handles) {
$canvas = $(this);
// Remove handles from layer
for (h = 0; h < layer._handles.length; h += 1) {
handle = layer._handles[h];
$canvas.removeLayer(handle);
}
layer._handles.length = 0;
}
}
|
javascript
|
function (layer) {
var $canvas, handle, h;
if (layer._handles) {
$canvas = $(this);
// Remove handles from layer
for (h = 0; h < layer._handles.length; h += 1) {
handle = layer._handles[h];
$canvas.removeLayer(handle);
}
layer._handles.length = 0;
}
}
|
[
"function",
"(",
"layer",
")",
"{",
"var",
"$canvas",
",",
"handle",
",",
"h",
";",
"if",
"(",
"layer",
".",
"_handles",
")",
"{",
"$canvas",
"=",
"$",
"(",
"this",
")",
";",
"// Remove handles from layer",
"for",
"(",
"h",
"=",
"0",
";",
"h",
"<",
"layer",
".",
"_handles",
".",
"length",
";",
"h",
"+=",
"1",
")",
"{",
"handle",
"=",
"layer",
".",
"_handles",
"[",
"h",
"]",
";",
"$canvas",
".",
"removeLayer",
"(",
"handle",
")",
";",
"}",
"layer",
".",
"_handles",
".",
"length",
"=",
"0",
";",
"}",
"}"
] |
Remove handles of layer is removed
|
[
"Remove",
"handles",
"of",
"layer",
"is",
"removed"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L426-L437
|
|
13,233
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
function (layer, props) {
if (props.handle || objectContainsPathCoords(props)) {
// Add handles if handle property was added
removeHandles(layer);
addHandles(layer);
} else if (props.handle === null) {
removeHandles(layer);
}
if (isRectLayer(layer)) {
// If width/height was changed
if (props.width !== undefined || props.height !== undefined || props.x !== undefined || props.y !== undefined) {
// Update handle positions
updateRectHandles(layer);
}
} else if (isPathLayer(layer)) {
updatePathHandles(layer);
}
}
|
javascript
|
function (layer, props) {
if (props.handle || objectContainsPathCoords(props)) {
// Add handles if handle property was added
removeHandles(layer);
addHandles(layer);
} else if (props.handle === null) {
removeHandles(layer);
}
if (isRectLayer(layer)) {
// If width/height was changed
if (props.width !== undefined || props.height !== undefined || props.x !== undefined || props.y !== undefined) {
// Update handle positions
updateRectHandles(layer);
}
} else if (isPathLayer(layer)) {
updatePathHandles(layer);
}
}
|
[
"function",
"(",
"layer",
",",
"props",
")",
"{",
"if",
"(",
"props",
".",
"handle",
"||",
"objectContainsPathCoords",
"(",
"props",
")",
")",
"{",
"// Add handles if handle property was added",
"removeHandles",
"(",
"layer",
")",
";",
"addHandles",
"(",
"layer",
")",
";",
"}",
"else",
"if",
"(",
"props",
".",
"handle",
"===",
"null",
")",
"{",
"removeHandles",
"(",
"layer",
")",
";",
"}",
"if",
"(",
"isRectLayer",
"(",
"layer",
")",
")",
"{",
"// If width/height was changed",
"if",
"(",
"props",
".",
"width",
"!==",
"undefined",
"||",
"props",
".",
"height",
"!==",
"undefined",
"||",
"props",
".",
"x",
"!==",
"undefined",
"||",
"props",
".",
"y",
"!==",
"undefined",
")",
"{",
"// Update handle positions",
"updateRectHandles",
"(",
"layer",
")",
";",
"}",
"}",
"else",
"if",
"(",
"isPathLayer",
"(",
"layer",
")",
")",
"{",
"updatePathHandles",
"(",
"layer",
")",
";",
"}",
"}"
] |
Update handle positions when changing parent layer's dimensions
|
[
"Update",
"handle",
"positions",
"when",
"changing",
"parent",
"layer",
"s",
"dimensions"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L439-L457
|
|
13,234
|
caleb531/jcanvas
|
dist/jcanvas-handles.js
|
function (layer, fx) {
// If layer is a rectangle or ellipse layer
if (isRectLayer(layer)) {
// If width or height are animated
if (fx.prop === 'width' || fx.prop === 'height' || fx.prop === 'x' || fx.prop === 'y') {
// Update rectangular handles
updateRectHandles(layer);
}
} else if (isPathLayer(layer)) {
// If coordinates are animated
if (fx.prop.match(/^c?(x|y)(\d+)/gi) !== null) {
// Update path handles
updatePathHandles(layer);
}
}
}
|
javascript
|
function (layer, fx) {
// If layer is a rectangle or ellipse layer
if (isRectLayer(layer)) {
// If width or height are animated
if (fx.prop === 'width' || fx.prop === 'height' || fx.prop === 'x' || fx.prop === 'y') {
// Update rectangular handles
updateRectHandles(layer);
}
} else if (isPathLayer(layer)) {
// If coordinates are animated
if (fx.prop.match(/^c?(x|y)(\d+)/gi) !== null) {
// Update path handles
updatePathHandles(layer);
}
}
}
|
[
"function",
"(",
"layer",
",",
"fx",
")",
"{",
"// If layer is a rectangle or ellipse layer",
"if",
"(",
"isRectLayer",
"(",
"layer",
")",
")",
"{",
"// If width or height are animated",
"if",
"(",
"fx",
".",
"prop",
"===",
"'width'",
"||",
"fx",
".",
"prop",
"===",
"'height'",
"||",
"fx",
".",
"prop",
"===",
"'x'",
"||",
"fx",
".",
"prop",
"===",
"'y'",
")",
"{",
"// Update rectangular handles",
"updateRectHandles",
"(",
"layer",
")",
";",
"}",
"}",
"else",
"if",
"(",
"isPathLayer",
"(",
"layer",
")",
")",
"{",
"// If coordinates are animated",
"if",
"(",
"fx",
".",
"prop",
".",
"match",
"(",
"/",
"^c?(x|y)(\\d+)",
"/",
"gi",
")",
"!==",
"null",
")",
"{",
"// Update path handles",
"updatePathHandles",
"(",
"layer",
")",
";",
"}",
"}",
"}"
] |
Update handle positions when animating parent layer
|
[
"Update",
"handle",
"positions",
"when",
"animating",
"parent",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-handles.js#L459-L474
|
|
13,235
|
caleb531/jcanvas
|
dist/jcanvas.js
|
jCanvasObject
|
function jCanvasObject(args) {
var params = this,
propName;
// Copy the given parameters into new object
for (propName in args) {
// Do not merge defaults into parameters
if (Object.prototype.hasOwnProperty.call(args, propName)) {
params[propName] = args[propName];
}
}
return params;
}
|
javascript
|
function jCanvasObject(args) {
var params = this,
propName;
// Copy the given parameters into new object
for (propName in args) {
// Do not merge defaults into parameters
if (Object.prototype.hasOwnProperty.call(args, propName)) {
params[propName] = args[propName];
}
}
return params;
}
|
[
"function",
"jCanvasObject",
"(",
"args",
")",
"{",
"var",
"params",
"=",
"this",
",",
"propName",
";",
"// Copy the given parameters into new object",
"for",
"(",
"propName",
"in",
"args",
")",
"{",
"// Do not merge defaults into parameters",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"args",
",",
"propName",
")",
")",
"{",
"params",
"[",
"propName",
"]",
"=",
"args",
"[",
"propName",
"]",
";",
"}",
"}",
"return",
"params",
";",
"}"
] |
Constructor for creating objects that inherit from jCanvas preferences and defaults
|
[
"Constructor",
"for",
"creating",
"objects",
"that",
"inherit",
"from",
"jCanvas",
"preferences",
"and",
"defaults"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L82-L93
|
13,236
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_coerceNumericProps
|
function _coerceNumericProps(props) {
var propName, propType, propValue;
// Loop through all properties in given property map
for (propName in props) {
if (Object.prototype.hasOwnProperty.call(props, propName)) {
propValue = props[propName];
propType = typeOf(propValue);
// If property is non-empty string and value is numeric
if (propType === 'string' && isNumeric(propValue) && propName !== 'text') {
// Convert value to number
props[propName] = parseFloat(propValue);
}
}
}
// Ensure value of text property is always a string
if (props.text !== undefined) {
props.text = String(props.text);
}
}
|
javascript
|
function _coerceNumericProps(props) {
var propName, propType, propValue;
// Loop through all properties in given property map
for (propName in props) {
if (Object.prototype.hasOwnProperty.call(props, propName)) {
propValue = props[propName];
propType = typeOf(propValue);
// If property is non-empty string and value is numeric
if (propType === 'string' && isNumeric(propValue) && propName !== 'text') {
// Convert value to number
props[propName] = parseFloat(propValue);
}
}
}
// Ensure value of text property is always a string
if (props.text !== undefined) {
props.text = String(props.text);
}
}
|
[
"function",
"_coerceNumericProps",
"(",
"props",
")",
"{",
"var",
"propName",
",",
"propType",
",",
"propValue",
";",
"// Loop through all properties in given property map",
"for",
"(",
"propName",
"in",
"props",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"props",
",",
"propName",
")",
")",
"{",
"propValue",
"=",
"props",
"[",
"propName",
"]",
";",
"propType",
"=",
"typeOf",
"(",
"propValue",
")",
";",
"// If property is non-empty string and value is numeric",
"if",
"(",
"propType",
"===",
"'string'",
"&&",
"isNumeric",
"(",
"propValue",
")",
"&&",
"propName",
"!==",
"'text'",
")",
"{",
"// Convert value to number",
"props",
"[",
"propName",
"]",
"=",
"parseFloat",
"(",
"propValue",
")",
";",
"}",
"}",
"}",
"// Ensure value of text property is always a string",
"if",
"(",
"props",
".",
"text",
"!==",
"undefined",
")",
"{",
"props",
".",
"text",
"=",
"String",
"(",
"props",
".",
"text",
")",
";",
"}",
"}"
] |
Coerce designated number properties from strings to numbers
|
[
"Coerce",
"designated",
"number",
"properties",
"from",
"strings",
"to",
"numbers"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L219-L237
|
13,237
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_cloneTransforms
|
function _cloneTransforms(transforms) {
// Clone the object itself
transforms = extendObject({}, transforms);
// Clone the object's masks array
transforms.masks = transforms.masks.slice(0);
return transforms;
}
|
javascript
|
function _cloneTransforms(transforms) {
// Clone the object itself
transforms = extendObject({}, transforms);
// Clone the object's masks array
transforms.masks = transforms.masks.slice(0);
return transforms;
}
|
[
"function",
"_cloneTransforms",
"(",
"transforms",
")",
"{",
"// Clone the object itself",
"transforms",
"=",
"extendObject",
"(",
"{",
"}",
",",
"transforms",
")",
";",
"// Clone the object's masks array",
"transforms",
".",
"masks",
"=",
"transforms",
".",
"masks",
".",
"slice",
"(",
"0",
")",
";",
"return",
"transforms",
";",
"}"
] |
Clone the given transformations object
|
[
"Clone",
"the",
"given",
"transformations",
"object"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L240-L246
|
13,238
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_saveCanvas
|
function _saveCanvas(ctx, data) {
var transforms;
ctx.save();
transforms = _cloneTransforms(data.transforms);
data.savedTransforms.push(transforms);
}
|
javascript
|
function _saveCanvas(ctx, data) {
var transforms;
ctx.save();
transforms = _cloneTransforms(data.transforms);
data.savedTransforms.push(transforms);
}
|
[
"function",
"_saveCanvas",
"(",
"ctx",
",",
"data",
")",
"{",
"var",
"transforms",
";",
"ctx",
".",
"save",
"(",
")",
";",
"transforms",
"=",
"_cloneTransforms",
"(",
"data",
".",
"transforms",
")",
";",
"data",
".",
"savedTransforms",
".",
"push",
"(",
"transforms",
")",
";",
"}"
] |
Save canvas context and update transformation stack
|
[
"Save",
"canvas",
"context",
"and",
"update",
"transformation",
"stack"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L249-L254
|
13,239
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_restoreCanvas
|
function _restoreCanvas(ctx, data) {
if (data.savedTransforms.length === 0) {
// Reset transformation state if it can't be restored any more
data.transforms = _cloneTransforms(baseTransforms);
} else {
// Restore canvas context
ctx.restore();
// Restore current transform state to the last saved state
data.transforms = data.savedTransforms.pop();
}
}
|
javascript
|
function _restoreCanvas(ctx, data) {
if (data.savedTransforms.length === 0) {
// Reset transformation state if it can't be restored any more
data.transforms = _cloneTransforms(baseTransforms);
} else {
// Restore canvas context
ctx.restore();
// Restore current transform state to the last saved state
data.transforms = data.savedTransforms.pop();
}
}
|
[
"function",
"_restoreCanvas",
"(",
"ctx",
",",
"data",
")",
"{",
"if",
"(",
"data",
".",
"savedTransforms",
".",
"length",
"===",
"0",
")",
"{",
"// Reset transformation state if it can't be restored any more",
"data",
".",
"transforms",
"=",
"_cloneTransforms",
"(",
"baseTransforms",
")",
";",
"}",
"else",
"{",
"// Restore canvas context",
"ctx",
".",
"restore",
"(",
")",
";",
"// Restore current transform state to the last saved state",
"data",
".",
"transforms",
"=",
"data",
".",
"savedTransforms",
".",
"pop",
"(",
")",
";",
"}",
"}"
] |
Restore canvas context update transformation stack
|
[
"Restore",
"canvas",
"context",
"update",
"transformation",
"stack"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L257-L267
|
13,240
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_setStyle
|
function _setStyle(canvas, ctx, params, styleName) {
if (params[styleName]) {
if (isFunction(params[styleName])) {
// Handle functions
ctx[styleName] = params[styleName].call(canvas, params);
} else {
// Handle string values
ctx[styleName] = params[styleName];
}
}
}
|
javascript
|
function _setStyle(canvas, ctx, params, styleName) {
if (params[styleName]) {
if (isFunction(params[styleName])) {
// Handle functions
ctx[styleName] = params[styleName].call(canvas, params);
} else {
// Handle string values
ctx[styleName] = params[styleName];
}
}
}
|
[
"function",
"_setStyle",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"styleName",
")",
"{",
"if",
"(",
"params",
"[",
"styleName",
"]",
")",
"{",
"if",
"(",
"isFunction",
"(",
"params",
"[",
"styleName",
"]",
")",
")",
"{",
"// Handle functions",
"ctx",
"[",
"styleName",
"]",
"=",
"params",
"[",
"styleName",
"]",
".",
"call",
"(",
"canvas",
",",
"params",
")",
";",
"}",
"else",
"{",
"// Handle string values",
"ctx",
"[",
"styleName",
"]",
"=",
"params",
"[",
"styleName",
"]",
";",
"}",
"}",
"}"
] |
Set the style with the given name
|
[
"Set",
"the",
"style",
"with",
"the",
"given",
"name"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L270-L280
|
13,241
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_setGlobalProps
|
function _setGlobalProps(canvas, ctx, params) {
_setStyle(canvas, ctx, params, 'fillStyle');
_setStyle(canvas, ctx, params, 'strokeStyle');
ctx.lineWidth = params.strokeWidth;
// Optionally round corners for paths
if (params.rounded) {
ctx.lineCap = ctx.lineJoin = 'round';
} else {
ctx.lineCap = params.strokeCap;
ctx.lineJoin = params.strokeJoin;
ctx.miterLimit = params.miterLimit;
}
// Reset strokeDash if null
if (!params.strokeDash) {
params.strokeDash = [];
}
// Dashed lines
if (ctx.setLineDash) {
ctx.setLineDash(params.strokeDash);
}
ctx.webkitLineDash = params.strokeDash;
ctx.lineDashOffset = ctx.webkitLineDashOffset = ctx.mozDashOffset = params.strokeDashOffset;
// Drop shadow
ctx.shadowOffsetX = params.shadowX;
ctx.shadowOffsetY = params.shadowY;
ctx.shadowBlur = params.shadowBlur;
ctx.shadowColor = params.shadowColor;
// Opacity and composite operation
ctx.globalAlpha = params.opacity;
ctx.globalCompositeOperation = params.compositing;
// Support cross-browser toggling of image smoothing
if (params.imageSmoothing) {
ctx.imageSmoothingEnabled = params.imageSmoothing;
}
}
|
javascript
|
function _setGlobalProps(canvas, ctx, params) {
_setStyle(canvas, ctx, params, 'fillStyle');
_setStyle(canvas, ctx, params, 'strokeStyle');
ctx.lineWidth = params.strokeWidth;
// Optionally round corners for paths
if (params.rounded) {
ctx.lineCap = ctx.lineJoin = 'round';
} else {
ctx.lineCap = params.strokeCap;
ctx.lineJoin = params.strokeJoin;
ctx.miterLimit = params.miterLimit;
}
// Reset strokeDash if null
if (!params.strokeDash) {
params.strokeDash = [];
}
// Dashed lines
if (ctx.setLineDash) {
ctx.setLineDash(params.strokeDash);
}
ctx.webkitLineDash = params.strokeDash;
ctx.lineDashOffset = ctx.webkitLineDashOffset = ctx.mozDashOffset = params.strokeDashOffset;
// Drop shadow
ctx.shadowOffsetX = params.shadowX;
ctx.shadowOffsetY = params.shadowY;
ctx.shadowBlur = params.shadowBlur;
ctx.shadowColor = params.shadowColor;
// Opacity and composite operation
ctx.globalAlpha = params.opacity;
ctx.globalCompositeOperation = params.compositing;
// Support cross-browser toggling of image smoothing
if (params.imageSmoothing) {
ctx.imageSmoothingEnabled = params.imageSmoothing;
}
}
|
[
"function",
"_setGlobalProps",
"(",
"canvas",
",",
"ctx",
",",
"params",
")",
"{",
"_setStyle",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"'fillStyle'",
")",
";",
"_setStyle",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"'strokeStyle'",
")",
";",
"ctx",
".",
"lineWidth",
"=",
"params",
".",
"strokeWidth",
";",
"// Optionally round corners for paths",
"if",
"(",
"params",
".",
"rounded",
")",
"{",
"ctx",
".",
"lineCap",
"=",
"ctx",
".",
"lineJoin",
"=",
"'round'",
";",
"}",
"else",
"{",
"ctx",
".",
"lineCap",
"=",
"params",
".",
"strokeCap",
";",
"ctx",
".",
"lineJoin",
"=",
"params",
".",
"strokeJoin",
";",
"ctx",
".",
"miterLimit",
"=",
"params",
".",
"miterLimit",
";",
"}",
"// Reset strokeDash if null",
"if",
"(",
"!",
"params",
".",
"strokeDash",
")",
"{",
"params",
".",
"strokeDash",
"=",
"[",
"]",
";",
"}",
"// Dashed lines",
"if",
"(",
"ctx",
".",
"setLineDash",
")",
"{",
"ctx",
".",
"setLineDash",
"(",
"params",
".",
"strokeDash",
")",
";",
"}",
"ctx",
".",
"webkitLineDash",
"=",
"params",
".",
"strokeDash",
";",
"ctx",
".",
"lineDashOffset",
"=",
"ctx",
".",
"webkitLineDashOffset",
"=",
"ctx",
".",
"mozDashOffset",
"=",
"params",
".",
"strokeDashOffset",
";",
"// Drop shadow",
"ctx",
".",
"shadowOffsetX",
"=",
"params",
".",
"shadowX",
";",
"ctx",
".",
"shadowOffsetY",
"=",
"params",
".",
"shadowY",
";",
"ctx",
".",
"shadowBlur",
"=",
"params",
".",
"shadowBlur",
";",
"ctx",
".",
"shadowColor",
"=",
"params",
".",
"shadowColor",
";",
"// Opacity and composite operation",
"ctx",
".",
"globalAlpha",
"=",
"params",
".",
"opacity",
";",
"ctx",
".",
"globalCompositeOperation",
"=",
"params",
".",
"compositing",
";",
"// Support cross-browser toggling of image smoothing",
"if",
"(",
"params",
".",
"imageSmoothing",
")",
"{",
"ctx",
".",
"imageSmoothingEnabled",
"=",
"params",
".",
"imageSmoothing",
";",
"}",
"}"
] |
Set canvas context properties
|
[
"Set",
"canvas",
"context",
"properties"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L283-L317
|
13,242
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_enableMasking
|
function _enableMasking(ctx, data, params) {
if (params.mask) {
// If jCanvas autosave is enabled
if (params.autosave) {
// Automatically save transformation state by default
_saveCanvas(ctx, data);
}
// Clip the current path
ctx.clip();
// Keep track of current masks
data.transforms.masks.push(params._args);
}
}
|
javascript
|
function _enableMasking(ctx, data, params) {
if (params.mask) {
// If jCanvas autosave is enabled
if (params.autosave) {
// Automatically save transformation state by default
_saveCanvas(ctx, data);
}
// Clip the current path
ctx.clip();
// Keep track of current masks
data.transforms.masks.push(params._args);
}
}
|
[
"function",
"_enableMasking",
"(",
"ctx",
",",
"data",
",",
"params",
")",
"{",
"if",
"(",
"params",
".",
"mask",
")",
"{",
"// If jCanvas autosave is enabled",
"if",
"(",
"params",
".",
"autosave",
")",
"{",
"// Automatically save transformation state by default",
"_saveCanvas",
"(",
"ctx",
",",
"data",
")",
";",
"}",
"// Clip the current path",
"ctx",
".",
"clip",
"(",
")",
";",
"// Keep track of current masks",
"data",
".",
"transforms",
".",
"masks",
".",
"push",
"(",
"params",
".",
"_args",
")",
";",
"}",
"}"
] |
Optionally enable masking support for this path
|
[
"Optionally",
"enable",
"masking",
"support",
"for",
"this",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L320-L332
|
13,243
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_closePath
|
function _closePath(canvas, ctx, params) {
var data;
// Optionally close path
if (params.closed) {
ctx.closePath();
}
if (params.shadowStroke && params.strokeWidth !== 0) {
// Extend the shadow to include the stroke of a drawing
// Add a stroke shadow by stroking before filling
ctx.stroke();
ctx.fill();
// Ensure the below stroking does not inherit a shadow
ctx.shadowColor = 'transparent';
ctx.shadowBlur = 0;
// Stroke over fill as usual
ctx.stroke();
} else {
// If shadowStroke is not enabled, stroke & fill as usual
ctx.fill();
// Prevent extra shadow created by stroke (but only when fill is present)
if (params.fillStyle !== 'transparent') {
ctx.shadowColor = 'transparent';
}
if (params.strokeWidth !== 0) {
// Only stroke if the stroke is not 0
ctx.stroke();
}
}
// Optionally close path
if (!params.closed) {
ctx.closePath();
}
// Restore individual shape transformation
_restoreTransform(ctx, params);
// Mask shape if chosen
if (params.mask) {
// Retrieve canvas data
data = _getCanvasData(canvas);
_enableMasking(ctx, data, params);
}
}
|
javascript
|
function _closePath(canvas, ctx, params) {
var data;
// Optionally close path
if (params.closed) {
ctx.closePath();
}
if (params.shadowStroke && params.strokeWidth !== 0) {
// Extend the shadow to include the stroke of a drawing
// Add a stroke shadow by stroking before filling
ctx.stroke();
ctx.fill();
// Ensure the below stroking does not inherit a shadow
ctx.shadowColor = 'transparent';
ctx.shadowBlur = 0;
// Stroke over fill as usual
ctx.stroke();
} else {
// If shadowStroke is not enabled, stroke & fill as usual
ctx.fill();
// Prevent extra shadow created by stroke (but only when fill is present)
if (params.fillStyle !== 'transparent') {
ctx.shadowColor = 'transparent';
}
if (params.strokeWidth !== 0) {
// Only stroke if the stroke is not 0
ctx.stroke();
}
}
// Optionally close path
if (!params.closed) {
ctx.closePath();
}
// Restore individual shape transformation
_restoreTransform(ctx, params);
// Mask shape if chosen
if (params.mask) {
// Retrieve canvas data
data = _getCanvasData(canvas);
_enableMasking(ctx, data, params);
}
}
|
[
"function",
"_closePath",
"(",
"canvas",
",",
"ctx",
",",
"params",
")",
"{",
"var",
"data",
";",
"// Optionally close path",
"if",
"(",
"params",
".",
"closed",
")",
"{",
"ctx",
".",
"closePath",
"(",
")",
";",
"}",
"if",
"(",
"params",
".",
"shadowStroke",
"&&",
"params",
".",
"strokeWidth",
"!==",
"0",
")",
"{",
"// Extend the shadow to include the stroke of a drawing",
"// Add a stroke shadow by stroking before filling",
"ctx",
".",
"stroke",
"(",
")",
";",
"ctx",
".",
"fill",
"(",
")",
";",
"// Ensure the below stroking does not inherit a shadow",
"ctx",
".",
"shadowColor",
"=",
"'transparent'",
";",
"ctx",
".",
"shadowBlur",
"=",
"0",
";",
"// Stroke over fill as usual",
"ctx",
".",
"stroke",
"(",
")",
";",
"}",
"else",
"{",
"// If shadowStroke is not enabled, stroke & fill as usual",
"ctx",
".",
"fill",
"(",
")",
";",
"// Prevent extra shadow created by stroke (but only when fill is present)",
"if",
"(",
"params",
".",
"fillStyle",
"!==",
"'transparent'",
")",
"{",
"ctx",
".",
"shadowColor",
"=",
"'transparent'",
";",
"}",
"if",
"(",
"params",
".",
"strokeWidth",
"!==",
"0",
")",
"{",
"// Only stroke if the stroke is not 0",
"ctx",
".",
"stroke",
"(",
")",
";",
"}",
"}",
"// Optionally close path",
"if",
"(",
"!",
"params",
".",
"closed",
")",
"{",
"ctx",
".",
"closePath",
"(",
")",
";",
"}",
"// Restore individual shape transformation",
"_restoreTransform",
"(",
"ctx",
",",
"params",
")",
";",
"// Mask shape if chosen",
"if",
"(",
"params",
".",
"mask",
")",
"{",
"// Retrieve canvas data",
"data",
"=",
"_getCanvasData",
"(",
"canvas",
")",
";",
"_enableMasking",
"(",
"ctx",
",",
"data",
",",
"params",
")",
";",
"}",
"}"
] |
Close current canvas path
|
[
"Close",
"current",
"canvas",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L344-L394
|
13,244
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_addLayerEvents
|
function _addLayerEvents($canvas, data, layer) {
var eventName;
// Determine which jCanvas events need to be bound to this layer
for (eventName in jCanvas.events) {
if (Object.prototype.hasOwnProperty.call(jCanvas.events, eventName)) {
// If layer has callback function to complement it
if (layer[eventName] || (layer.cursors && layer.cursors[eventName])) {
// Bind event to layer
_addExplicitLayerEvent($canvas, data, layer, eventName);
}
}
}
if (!data.events.mouseout) {
$canvas.bind('mouseout.jCanvas', function () {
// Retrieve the layer whose drag event was canceled
var layer = data.drag.layer, l;
// If cursor mouses out of canvas while dragging
if (layer) {
// Cancel drag
data.drag = {};
_triggerLayerEvent($canvas, data, layer, 'dragcancel');
}
// Loop through all layers
for (l = 0; l < data.layers.length; l += 1) {
layer = data.layers[l];
// If layer thinks it's still being moused over
if (layer._hovered) {
// Trigger mouseout on layer
$canvas.triggerLayerEvent(data.layers[l], 'mouseout');
}
}
// Redraw layers
$canvas.drawLayers();
});
// Indicate that an event handler has been bound
data.events.mouseout = true;
}
}
|
javascript
|
function _addLayerEvents($canvas, data, layer) {
var eventName;
// Determine which jCanvas events need to be bound to this layer
for (eventName in jCanvas.events) {
if (Object.prototype.hasOwnProperty.call(jCanvas.events, eventName)) {
// If layer has callback function to complement it
if (layer[eventName] || (layer.cursors && layer.cursors[eventName])) {
// Bind event to layer
_addExplicitLayerEvent($canvas, data, layer, eventName);
}
}
}
if (!data.events.mouseout) {
$canvas.bind('mouseout.jCanvas', function () {
// Retrieve the layer whose drag event was canceled
var layer = data.drag.layer, l;
// If cursor mouses out of canvas while dragging
if (layer) {
// Cancel drag
data.drag = {};
_triggerLayerEvent($canvas, data, layer, 'dragcancel');
}
// Loop through all layers
for (l = 0; l < data.layers.length; l += 1) {
layer = data.layers[l];
// If layer thinks it's still being moused over
if (layer._hovered) {
// Trigger mouseout on layer
$canvas.triggerLayerEvent(data.layers[l], 'mouseout');
}
}
// Redraw layers
$canvas.drawLayers();
});
// Indicate that an event handler has been bound
data.events.mouseout = true;
}
}
|
[
"function",
"_addLayerEvents",
"(",
"$canvas",
",",
"data",
",",
"layer",
")",
"{",
"var",
"eventName",
";",
"// Determine which jCanvas events need to be bound to this layer",
"for",
"(",
"eventName",
"in",
"jCanvas",
".",
"events",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"jCanvas",
".",
"events",
",",
"eventName",
")",
")",
"{",
"// If layer has callback function to complement it",
"if",
"(",
"layer",
"[",
"eventName",
"]",
"||",
"(",
"layer",
".",
"cursors",
"&&",
"layer",
".",
"cursors",
"[",
"eventName",
"]",
")",
")",
"{",
"// Bind event to layer",
"_addExplicitLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"eventName",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"data",
".",
"events",
".",
"mouseout",
")",
"{",
"$canvas",
".",
"bind",
"(",
"'mouseout.jCanvas'",
",",
"function",
"(",
")",
"{",
"// Retrieve the layer whose drag event was canceled",
"var",
"layer",
"=",
"data",
".",
"drag",
".",
"layer",
",",
"l",
";",
"// If cursor mouses out of canvas while dragging",
"if",
"(",
"layer",
")",
"{",
"// Cancel drag",
"data",
".",
"drag",
"=",
"{",
"}",
";",
"_triggerLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"'dragcancel'",
")",
";",
"}",
"// Loop through all layers",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"data",
".",
"layers",
".",
"length",
";",
"l",
"+=",
"1",
")",
"{",
"layer",
"=",
"data",
".",
"layers",
"[",
"l",
"]",
";",
"// If layer thinks it's still being moused over",
"if",
"(",
"layer",
".",
"_hovered",
")",
"{",
"// Trigger mouseout on layer",
"$canvas",
".",
"triggerLayerEvent",
"(",
"data",
".",
"layers",
"[",
"l",
"]",
",",
"'mouseout'",
")",
";",
"}",
"}",
"// Redraw layers",
"$canvas",
".",
"drawLayers",
"(",
")",
";",
"}",
")",
";",
"// Indicate that an event handler has been bound",
"data",
".",
"events",
".",
"mouseout",
"=",
"true",
";",
"}",
"}"
] |
Initialize all of a layer's associated jCanvas events
|
[
"Initialize",
"all",
"of",
"a",
"layer",
"s",
"associated",
"jCanvas",
"events"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L543-L580
|
13,245
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_addLayerEvent
|
function _addLayerEvent($canvas, data, layer, eventName) {
// Use touch events if appropriate
// eventName = _getMouseEventName(eventName);
// Bind event to layer
jCanvas.events[eventName]($canvas, data);
layer._event = true;
}
|
javascript
|
function _addLayerEvent($canvas, data, layer, eventName) {
// Use touch events if appropriate
// eventName = _getMouseEventName(eventName);
// Bind event to layer
jCanvas.events[eventName]($canvas, data);
layer._event = true;
}
|
[
"function",
"_addLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"eventName",
")",
"{",
"// Use touch events if appropriate",
"// eventName = _getMouseEventName(eventName);",
"// Bind event to layer",
"jCanvas",
".",
"events",
"[",
"eventName",
"]",
"(",
"$canvas",
",",
"data",
")",
";",
"layer",
".",
"_event",
"=",
"true",
";",
"}"
] |
Initialize the given event on the given layer
|
[
"Initialize",
"the",
"given",
"event",
"on",
"the",
"given",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L583-L589
|
13,246
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_enableDrag
|
function _enableDrag($canvas, data, layer) {
var dragHelperEvents, eventName, i;
// Only make layer draggable if necessary
if (layer.draggable || layer.cursors) {
// Organize helper events which enable drag support
dragHelperEvents = ['mousedown', 'mousemove', 'mouseup'];
// Bind each helper event to the canvas
for (i = 0; i < dragHelperEvents.length; i += 1) {
// Use touch events if appropriate
eventName = dragHelperEvents[i];
// Bind event
_addLayerEvent($canvas, data, layer, eventName);
}
// Indicate that this layer has events bound to it
layer._event = true;
}
}
|
javascript
|
function _enableDrag($canvas, data, layer) {
var dragHelperEvents, eventName, i;
// Only make layer draggable if necessary
if (layer.draggable || layer.cursors) {
// Organize helper events which enable drag support
dragHelperEvents = ['mousedown', 'mousemove', 'mouseup'];
// Bind each helper event to the canvas
for (i = 0; i < dragHelperEvents.length; i += 1) {
// Use touch events if appropriate
eventName = dragHelperEvents[i];
// Bind event
_addLayerEvent($canvas, data, layer, eventName);
}
// Indicate that this layer has events bound to it
layer._event = true;
}
}
|
[
"function",
"_enableDrag",
"(",
"$canvas",
",",
"data",
",",
"layer",
")",
"{",
"var",
"dragHelperEvents",
",",
"eventName",
",",
"i",
";",
"// Only make layer draggable if necessary",
"if",
"(",
"layer",
".",
"draggable",
"||",
"layer",
".",
"cursors",
")",
"{",
"// Organize helper events which enable drag support",
"dragHelperEvents",
"=",
"[",
"'mousedown'",
",",
"'mousemove'",
",",
"'mouseup'",
"]",
";",
"// Bind each helper event to the canvas",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"dragHelperEvents",
".",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"// Use touch events if appropriate",
"eventName",
"=",
"dragHelperEvents",
"[",
"i",
"]",
";",
"// Bind event",
"_addLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"eventName",
")",
";",
"}",
"// Indicate that this layer has events bound to it",
"layer",
".",
"_event",
"=",
"true",
";",
"}",
"}"
] |
Enable drag support for this layer
|
[
"Enable",
"drag",
"support",
"for",
"this",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L602-L621
|
13,247
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_updateLayerName
|
function _updateLayerName($canvas, data, layer, props) {
var nameMap = data.layer.names;
// If layer name is being added, not changed
if (!props) {
props = layer;
} else {
// Remove old layer name entry because layer name has changed
if (props.name !== undefined && isString(layer.name) && layer.name !== props.name) {
delete nameMap[layer.name];
}
}
// Add new entry to layer name map with new name
if (isString(props.name)) {
nameMap[props.name] = layer;
}
}
|
javascript
|
function _updateLayerName($canvas, data, layer, props) {
var nameMap = data.layer.names;
// If layer name is being added, not changed
if (!props) {
props = layer;
} else {
// Remove old layer name entry because layer name has changed
if (props.name !== undefined && isString(layer.name) && layer.name !== props.name) {
delete nameMap[layer.name];
}
}
// Add new entry to layer name map with new name
if (isString(props.name)) {
nameMap[props.name] = layer;
}
}
|
[
"function",
"_updateLayerName",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"props",
")",
"{",
"var",
"nameMap",
"=",
"data",
".",
"layer",
".",
"names",
";",
"// If layer name is being added, not changed",
"if",
"(",
"!",
"props",
")",
"{",
"props",
"=",
"layer",
";",
"}",
"else",
"{",
"// Remove old layer name entry because layer name has changed",
"if",
"(",
"props",
".",
"name",
"!==",
"undefined",
"&&",
"isString",
"(",
"layer",
".",
"name",
")",
"&&",
"layer",
".",
"name",
"!==",
"props",
".",
"name",
")",
"{",
"delete",
"nameMap",
"[",
"layer",
".",
"name",
"]",
";",
"}",
"}",
"// Add new entry to layer name map with new name",
"if",
"(",
"isString",
"(",
"props",
".",
"name",
")",
")",
"{",
"nameMap",
"[",
"props",
".",
"name",
"]",
"=",
"layer",
";",
"}",
"}"
] |
Update a layer property map if property is changed
|
[
"Update",
"a",
"layer",
"property",
"map",
"if",
"property",
"is",
"changed"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L624-L645
|
13,248
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_updateLayerGroups
|
function _updateLayerGroups($canvas, data, layer, props) {
var groupMap = data.layer.groups,
group, groupName, g,
index, l;
// If group name is not changing
if (!props) {
props = layer;
} else {
// Remove layer from all of its associated groups
if (props.groups !== undefined && layer.groups !== null) {
for (g = 0; g < layer.groups.length; g += 1) {
groupName = layer.groups[g];
group = groupMap[groupName];
if (group) {
// Remove layer from its old layer group entry
for (l = 0; l < group.length; l += 1) {
if (group[l] === layer) {
// Keep track of the layer's initial index
index = l;
// Remove layer once found
group.splice(l, 1);
break;
}
}
// Remove layer group entry if group is empty
if (group.length === 0) {
delete groupMap[groupName];
}
}
}
}
}
// Add layer to new group if a new group name is given
if (props.groups !== undefined && props.groups !== null) {
for (g = 0; g < props.groups.length; g += 1) {
groupName = props.groups[g];
group = groupMap[groupName];
if (!group) {
// Create new group entry if it doesn't exist
group = groupMap[groupName] = [];
group.name = groupName;
}
if (index === undefined) {
// Add layer to end of group unless otherwise stated
index = group.length;
}
// Add layer to its new layer group
group.splice(index, 0, layer);
}
}
}
|
javascript
|
function _updateLayerGroups($canvas, data, layer, props) {
var groupMap = data.layer.groups,
group, groupName, g,
index, l;
// If group name is not changing
if (!props) {
props = layer;
} else {
// Remove layer from all of its associated groups
if (props.groups !== undefined && layer.groups !== null) {
for (g = 0; g < layer.groups.length; g += 1) {
groupName = layer.groups[g];
group = groupMap[groupName];
if (group) {
// Remove layer from its old layer group entry
for (l = 0; l < group.length; l += 1) {
if (group[l] === layer) {
// Keep track of the layer's initial index
index = l;
// Remove layer once found
group.splice(l, 1);
break;
}
}
// Remove layer group entry if group is empty
if (group.length === 0) {
delete groupMap[groupName];
}
}
}
}
}
// Add layer to new group if a new group name is given
if (props.groups !== undefined && props.groups !== null) {
for (g = 0; g < props.groups.length; g += 1) {
groupName = props.groups[g];
group = groupMap[groupName];
if (!group) {
// Create new group entry if it doesn't exist
group = groupMap[groupName] = [];
group.name = groupName;
}
if (index === undefined) {
// Add layer to end of group unless otherwise stated
index = group.length;
}
// Add layer to its new layer group
group.splice(index, 0, layer);
}
}
}
|
[
"function",
"_updateLayerGroups",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"props",
")",
"{",
"var",
"groupMap",
"=",
"data",
".",
"layer",
".",
"groups",
",",
"group",
",",
"groupName",
",",
"g",
",",
"index",
",",
"l",
";",
"// If group name is not changing",
"if",
"(",
"!",
"props",
")",
"{",
"props",
"=",
"layer",
";",
"}",
"else",
"{",
"// Remove layer from all of its associated groups",
"if",
"(",
"props",
".",
"groups",
"!==",
"undefined",
"&&",
"layer",
".",
"groups",
"!==",
"null",
")",
"{",
"for",
"(",
"g",
"=",
"0",
";",
"g",
"<",
"layer",
".",
"groups",
".",
"length",
";",
"g",
"+=",
"1",
")",
"{",
"groupName",
"=",
"layer",
".",
"groups",
"[",
"g",
"]",
";",
"group",
"=",
"groupMap",
"[",
"groupName",
"]",
";",
"if",
"(",
"group",
")",
"{",
"// Remove layer from its old layer group entry",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"group",
".",
"length",
";",
"l",
"+=",
"1",
")",
"{",
"if",
"(",
"group",
"[",
"l",
"]",
"===",
"layer",
")",
"{",
"// Keep track of the layer's initial index",
"index",
"=",
"l",
";",
"// Remove layer once found",
"group",
".",
"splice",
"(",
"l",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"// Remove layer group entry if group is empty",
"if",
"(",
"group",
".",
"length",
"===",
"0",
")",
"{",
"delete",
"groupMap",
"[",
"groupName",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"// Add layer to new group if a new group name is given",
"if",
"(",
"props",
".",
"groups",
"!==",
"undefined",
"&&",
"props",
".",
"groups",
"!==",
"null",
")",
"{",
"for",
"(",
"g",
"=",
"0",
";",
"g",
"<",
"props",
".",
"groups",
".",
"length",
";",
"g",
"+=",
"1",
")",
"{",
"groupName",
"=",
"props",
".",
"groups",
"[",
"g",
"]",
";",
"group",
"=",
"groupMap",
"[",
"groupName",
"]",
";",
"if",
"(",
"!",
"group",
")",
"{",
"// Create new group entry if it doesn't exist",
"group",
"=",
"groupMap",
"[",
"groupName",
"]",
"=",
"[",
"]",
";",
"group",
".",
"name",
"=",
"groupName",
";",
"}",
"if",
"(",
"index",
"===",
"undefined",
")",
"{",
"// Add layer to end of group unless otherwise stated",
"index",
"=",
"group",
".",
"length",
";",
"}",
"// Add layer to its new layer group",
"group",
".",
"splice",
"(",
"index",
",",
"0",
",",
"layer",
")",
";",
"}",
"}",
"}"
] |
Create or update the data map for the given layer and group type
|
[
"Create",
"or",
"update",
"the",
"data",
"map",
"for",
"the",
"given",
"layer",
"and",
"group",
"type"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L648-L709
|
13,249
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_getIntersectingLayer
|
function _getIntersectingLayer(data) {
var layer, i,
mask, m;
// Store the topmost layer
layer = null;
// Get the topmost layer whose visible area intersects event coordinates
for (i = data.intersecting.length - 1; i >= 0; i -= 1) {
// Get current layer
layer = data.intersecting[i];
// If layer has previous masks
if (layer._masks) {
// Search previous masks to ensure
// layer is visible at event coordinates
for (m = layer._masks.length - 1; m >= 0; m -= 1) {
mask = layer._masks[m];
// If mask does not intersect event coordinates
if (!mask.intersects) {
// Indicate that the mask does not
// intersect event coordinates
layer.intersects = false;
// Stop searching previous masks
break;
}
}
// If event coordinates intersect all previous masks
// and layer is not intangible
if (layer.intersects && !layer.intangible) {
// Stop searching for topmost layer
break;
}
}
}
// If resulting layer is intangible
if (layer && layer.intangible) {
// Cursor does not intersect this layer
layer = null;
}
return layer;
}
|
javascript
|
function _getIntersectingLayer(data) {
var layer, i,
mask, m;
// Store the topmost layer
layer = null;
// Get the topmost layer whose visible area intersects event coordinates
for (i = data.intersecting.length - 1; i >= 0; i -= 1) {
// Get current layer
layer = data.intersecting[i];
// If layer has previous masks
if (layer._masks) {
// Search previous masks to ensure
// layer is visible at event coordinates
for (m = layer._masks.length - 1; m >= 0; m -= 1) {
mask = layer._masks[m];
// If mask does not intersect event coordinates
if (!mask.intersects) {
// Indicate that the mask does not
// intersect event coordinates
layer.intersects = false;
// Stop searching previous masks
break;
}
}
// If event coordinates intersect all previous masks
// and layer is not intangible
if (layer.intersects && !layer.intangible) {
// Stop searching for topmost layer
break;
}
}
}
// If resulting layer is intangible
if (layer && layer.intangible) {
// Cursor does not intersect this layer
layer = null;
}
return layer;
}
|
[
"function",
"_getIntersectingLayer",
"(",
"data",
")",
"{",
"var",
"layer",
",",
"i",
",",
"mask",
",",
"m",
";",
"// Store the topmost layer",
"layer",
"=",
"null",
";",
"// Get the topmost layer whose visible area intersects event coordinates",
"for",
"(",
"i",
"=",
"data",
".",
"intersecting",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"-=",
"1",
")",
"{",
"// Get current layer",
"layer",
"=",
"data",
".",
"intersecting",
"[",
"i",
"]",
";",
"// If layer has previous masks",
"if",
"(",
"layer",
".",
"_masks",
")",
"{",
"// Search previous masks to ensure",
"// layer is visible at event coordinates",
"for",
"(",
"m",
"=",
"layer",
".",
"_masks",
".",
"length",
"-",
"1",
";",
"m",
">=",
"0",
";",
"m",
"-=",
"1",
")",
"{",
"mask",
"=",
"layer",
".",
"_masks",
"[",
"m",
"]",
";",
"// If mask does not intersect event coordinates",
"if",
"(",
"!",
"mask",
".",
"intersects",
")",
"{",
"// Indicate that the mask does not",
"// intersect event coordinates",
"layer",
".",
"intersects",
"=",
"false",
";",
"// Stop searching previous masks",
"break",
";",
"}",
"}",
"// If event coordinates intersect all previous masks",
"// and layer is not intangible",
"if",
"(",
"layer",
".",
"intersects",
"&&",
"!",
"layer",
".",
"intangible",
")",
"{",
"// Stop searching for topmost layer",
"break",
";",
"}",
"}",
"}",
"// If resulting layer is intangible",
"if",
"(",
"layer",
"&&",
"layer",
".",
"intangible",
")",
"{",
"// Cursor does not intersect this layer",
"layer",
"=",
"null",
";",
"}",
"return",
"layer",
";",
"}"
] |
Get topmost layer that intersects with event coordinates
|
[
"Get",
"topmost",
"layer",
"that",
"intersects",
"with",
"event",
"coordinates"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1166-L1213
|
13,250
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_setCursor
|
function _setCursor($canvas, layer, eventType) {
var cursor;
if (layer.cursors) {
// Retrieve cursor from cursors object if it exists
cursor = layer.cursors[eventType];
}
// Prefix any CSS3 cursor
if ($.inArray(cursor, css.cursors) !== -1) {
cursor = css.prefix + cursor;
}
// If cursor is defined
if (cursor) {
// Set canvas cursor
$canvas.css({
cursor: cursor
});
}
}
|
javascript
|
function _setCursor($canvas, layer, eventType) {
var cursor;
if (layer.cursors) {
// Retrieve cursor from cursors object if it exists
cursor = layer.cursors[eventType];
}
// Prefix any CSS3 cursor
if ($.inArray(cursor, css.cursors) !== -1) {
cursor = css.prefix + cursor;
}
// If cursor is defined
if (cursor) {
// Set canvas cursor
$canvas.css({
cursor: cursor
});
}
}
|
[
"function",
"_setCursor",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
")",
"{",
"var",
"cursor",
";",
"if",
"(",
"layer",
".",
"cursors",
")",
"{",
"// Retrieve cursor from cursors object if it exists",
"cursor",
"=",
"layer",
".",
"cursors",
"[",
"eventType",
"]",
";",
"}",
"// Prefix any CSS3 cursor",
"if",
"(",
"$",
".",
"inArray",
"(",
"cursor",
",",
"css",
".",
"cursors",
")",
"!==",
"-",
"1",
")",
"{",
"cursor",
"=",
"css",
".",
"prefix",
"+",
"cursor",
";",
"}",
"// If cursor is defined",
"if",
"(",
"cursor",
")",
"{",
"// Set canvas cursor",
"$canvas",
".",
"css",
"(",
"{",
"cursor",
":",
"cursor",
"}",
")",
";",
"}",
"}"
] |
Set cursor on canvas
|
[
"Set",
"cursor",
"on",
"canvas"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1354-L1371
|
13,251
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_runEventCallback
|
function _runEventCallback($canvas, layer, eventType, callbacks, arg) {
// Prevent callback from firing recursively
if (callbacks[eventType] && layer._running && !layer._running[eventType]) {
// Signify the start of callback execution for this event
layer._running[eventType] = true;
// Run event callback with the given arguments
callbacks[eventType].call($canvas[0], layer, arg);
// Signify the end of callback execution for this event
layer._running[eventType] = false;
}
}
|
javascript
|
function _runEventCallback($canvas, layer, eventType, callbacks, arg) {
// Prevent callback from firing recursively
if (callbacks[eventType] && layer._running && !layer._running[eventType]) {
// Signify the start of callback execution for this event
layer._running[eventType] = true;
// Run event callback with the given arguments
callbacks[eventType].call($canvas[0], layer, arg);
// Signify the end of callback execution for this event
layer._running[eventType] = false;
}
}
|
[
"function",
"_runEventCallback",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
",",
"callbacks",
",",
"arg",
")",
"{",
"// Prevent callback from firing recursively",
"if",
"(",
"callbacks",
"[",
"eventType",
"]",
"&&",
"layer",
".",
"_running",
"&&",
"!",
"layer",
".",
"_running",
"[",
"eventType",
"]",
")",
"{",
"// Signify the start of callback execution for this event",
"layer",
".",
"_running",
"[",
"eventType",
"]",
"=",
"true",
";",
"// Run event callback with the given arguments",
"callbacks",
"[",
"eventType",
"]",
".",
"call",
"(",
"$canvas",
"[",
"0",
"]",
",",
"layer",
",",
"arg",
")",
";",
"// Signify the end of callback execution for this event",
"layer",
".",
"_running",
"[",
"eventType",
"]",
"=",
"false",
";",
"}",
"}"
] |
Run the given event callback with the given arguments
|
[
"Run",
"the",
"given",
"event",
"callback",
"with",
"the",
"given",
"arguments"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1381-L1391
|
13,252
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_layerCanFireEvent
|
function _layerCanFireEvent(layer, eventType) {
// If events are disable and if
// layer is tangible or event is not tangible
return (!layer.disableEvents &&
(!layer.intangible || $.inArray(eventType, tangibleEvents) === -1));
}
|
javascript
|
function _layerCanFireEvent(layer, eventType) {
// If events are disable and if
// layer is tangible or event is not tangible
return (!layer.disableEvents &&
(!layer.intangible || $.inArray(eventType, tangibleEvents) === -1));
}
|
[
"function",
"_layerCanFireEvent",
"(",
"layer",
",",
"eventType",
")",
"{",
"// If events are disable and if",
"// layer is tangible or event is not tangible",
"return",
"(",
"!",
"layer",
".",
"disableEvents",
"&&",
"(",
"!",
"layer",
".",
"intangible",
"||",
"$",
".",
"inArray",
"(",
"eventType",
",",
"tangibleEvents",
")",
"===",
"-",
"1",
")",
")",
";",
"}"
] |
Determine if the given layer can "legally" fire the given event
|
[
"Determine",
"if",
"the",
"given",
"layer",
"can",
"legally",
"fire",
"the",
"given",
"event"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1394-L1399
|
13,253
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_triggerLayerEvent
|
function _triggerLayerEvent($canvas, data, layer, eventType, arg) {
// If layer can legally fire this event type
if (_layerCanFireEvent(layer, eventType)) {
// Do not set a custom cursor on layer mouseout
if (eventType !== 'mouseout') {
// Update cursor if one is defined for this event
_setCursor($canvas, layer, eventType);
}
// Trigger the user-defined event callback
_runEventCallback($canvas, layer, eventType, layer, arg);
// Trigger the canvas-bound event hook
_runEventCallback($canvas, layer, eventType, data.eventHooks, arg);
// Trigger the global event hook
_runEventCallback($canvas, layer, eventType, jCanvas.eventHooks, arg);
}
}
|
javascript
|
function _triggerLayerEvent($canvas, data, layer, eventType, arg) {
// If layer can legally fire this event type
if (_layerCanFireEvent(layer, eventType)) {
// Do not set a custom cursor on layer mouseout
if (eventType !== 'mouseout') {
// Update cursor if one is defined for this event
_setCursor($canvas, layer, eventType);
}
// Trigger the user-defined event callback
_runEventCallback($canvas, layer, eventType, layer, arg);
// Trigger the canvas-bound event hook
_runEventCallback($canvas, layer, eventType, data.eventHooks, arg);
// Trigger the global event hook
_runEventCallback($canvas, layer, eventType, jCanvas.eventHooks, arg);
}
}
|
[
"function",
"_triggerLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"eventType",
",",
"arg",
")",
"{",
"// If layer can legally fire this event type",
"if",
"(",
"_layerCanFireEvent",
"(",
"layer",
",",
"eventType",
")",
")",
"{",
"// Do not set a custom cursor on layer mouseout",
"if",
"(",
"eventType",
"!==",
"'mouseout'",
")",
"{",
"// Update cursor if one is defined for this event",
"_setCursor",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
")",
";",
"}",
"// Trigger the user-defined event callback",
"_runEventCallback",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
",",
"layer",
",",
"arg",
")",
";",
"// Trigger the canvas-bound event hook",
"_runEventCallback",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
",",
"data",
".",
"eventHooks",
",",
"arg",
")",
";",
"// Trigger the global event hook",
"_runEventCallback",
"(",
"$canvas",
",",
"layer",
",",
"eventType",
",",
"jCanvas",
".",
"eventHooks",
",",
"arg",
")",
";",
"}",
"}"
] |
Trigger the given event on the given layer
|
[
"Trigger",
"the",
"given",
"event",
"on",
"the",
"given",
"layer"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1402-L1420
|
13,254
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_parseEndValues
|
function _parseEndValues(canvas, layer, endValues) {
var propName, propValue,
subPropName, subPropValue;
// Loop through all properties in map of end values
for (propName in endValues) {
if (Object.prototype.hasOwnProperty.call(endValues, propName)) {
propValue = endValues[propName];
// If end value is function
if (isFunction(propValue)) {
// Call function and use its value as the end value
endValues[propName] = propValue.call(canvas, layer, propName);
}
// If end value is an object
if (typeOf(propValue) === 'object' && isPlainObject(propValue)) {
// Prepare to animate properties in object
for (subPropName in propValue) {
if (Object.prototype.hasOwnProperty.call(propValue, subPropName)) {
subPropValue = propValue[subPropName];
// Store property's start value at top-level of layer
if (layer[propName] !== undefined) {
layer[propName + '.' + subPropName] = layer[propName][subPropName];
// Store property's end value at top-level of end values map
endValues[propName + '.' + subPropName] = subPropValue;
}
}
}
// Delete sub-property of object as it's no longer needed
delete endValues[propName];
}
}
}
return endValues;
}
|
javascript
|
function _parseEndValues(canvas, layer, endValues) {
var propName, propValue,
subPropName, subPropValue;
// Loop through all properties in map of end values
for (propName in endValues) {
if (Object.prototype.hasOwnProperty.call(endValues, propName)) {
propValue = endValues[propName];
// If end value is function
if (isFunction(propValue)) {
// Call function and use its value as the end value
endValues[propName] = propValue.call(canvas, layer, propName);
}
// If end value is an object
if (typeOf(propValue) === 'object' && isPlainObject(propValue)) {
// Prepare to animate properties in object
for (subPropName in propValue) {
if (Object.prototype.hasOwnProperty.call(propValue, subPropName)) {
subPropValue = propValue[subPropName];
// Store property's start value at top-level of layer
if (layer[propName] !== undefined) {
layer[propName + '.' + subPropName] = layer[propName][subPropName];
// Store property's end value at top-level of end values map
endValues[propName + '.' + subPropName] = subPropValue;
}
}
}
// Delete sub-property of object as it's no longer needed
delete endValues[propName];
}
}
}
return endValues;
}
|
[
"function",
"_parseEndValues",
"(",
"canvas",
",",
"layer",
",",
"endValues",
")",
"{",
"var",
"propName",
",",
"propValue",
",",
"subPropName",
",",
"subPropValue",
";",
"// Loop through all properties in map of end values",
"for",
"(",
"propName",
"in",
"endValues",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"endValues",
",",
"propName",
")",
")",
"{",
"propValue",
"=",
"endValues",
"[",
"propName",
"]",
";",
"// If end value is function",
"if",
"(",
"isFunction",
"(",
"propValue",
")",
")",
"{",
"// Call function and use its value as the end value",
"endValues",
"[",
"propName",
"]",
"=",
"propValue",
".",
"call",
"(",
"canvas",
",",
"layer",
",",
"propName",
")",
";",
"}",
"// If end value is an object",
"if",
"(",
"typeOf",
"(",
"propValue",
")",
"===",
"'object'",
"&&",
"isPlainObject",
"(",
"propValue",
")",
")",
"{",
"// Prepare to animate properties in object",
"for",
"(",
"subPropName",
"in",
"propValue",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"propValue",
",",
"subPropName",
")",
")",
"{",
"subPropValue",
"=",
"propValue",
"[",
"subPropName",
"]",
";",
"// Store property's start value at top-level of layer",
"if",
"(",
"layer",
"[",
"propName",
"]",
"!==",
"undefined",
")",
"{",
"layer",
"[",
"propName",
"+",
"'.'",
"+",
"subPropName",
"]",
"=",
"layer",
"[",
"propName",
"]",
"[",
"subPropName",
"]",
";",
"// Store property's end value at top-level of end values map",
"endValues",
"[",
"propName",
"+",
"'.'",
"+",
"subPropName",
"]",
"=",
"subPropValue",
";",
"}",
"}",
"}",
"// Delete sub-property of object as it's no longer needed",
"delete",
"endValues",
"[",
"propName",
"]",
";",
"}",
"}",
"}",
"return",
"endValues",
";",
"}"
] |
Evaluate property values that are functions
|
[
"Evaluate",
"property",
"values",
"that",
"are",
"functions"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1785-L1817
|
13,255
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_removeSubPropAliases
|
function _removeSubPropAliases(layer) {
var propName;
for (propName in layer) {
if (Object.prototype.hasOwnProperty.call(layer, propName)) {
if (propName.indexOf('.') !== -1) {
delete layer[propName];
}
}
}
}
|
javascript
|
function _removeSubPropAliases(layer) {
var propName;
for (propName in layer) {
if (Object.prototype.hasOwnProperty.call(layer, propName)) {
if (propName.indexOf('.') !== -1) {
delete layer[propName];
}
}
}
}
|
[
"function",
"_removeSubPropAliases",
"(",
"layer",
")",
"{",
"var",
"propName",
";",
"for",
"(",
"propName",
"in",
"layer",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"layer",
",",
"propName",
")",
")",
"{",
"if",
"(",
"propName",
".",
"indexOf",
"(",
"'.'",
")",
"!==",
"-",
"1",
")",
"{",
"delete",
"layer",
"[",
"propName",
"]",
";",
"}",
"}",
"}",
"}"
] |
Remove sub-property aliases from layer object
|
[
"Remove",
"sub",
"-",
"property",
"aliases",
"from",
"layer",
"object"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1820-L1829
|
13,256
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_colorToRgbArray
|
function _colorToRgbArray(color) {
var originalColor, elem,
rgb = [],
multiple = 1;
// Deal with complete transparency
if (color === 'transparent') {
color = 'rgba(0, 0, 0, 0)';
} else if (color.match(/^([a-z]+|#[0-9a-f]+)$/gi)) {
// Deal with hexadecimal colors and color names
elem = document.head;
originalColor = elem.style.color;
elem.style.color = color;
color = $.css(elem, 'color');
elem.style.color = originalColor;
}
// Parse RGB string
if (color.match(/^rgb/gi)) {
rgb = color.match(/(\d+(\.\d+)?)/gi);
// Deal with RGB percentages
if (color.match(/%/gi)) {
multiple = 2.55;
}
rgb[0] *= multiple;
rgb[1] *= multiple;
rgb[2] *= multiple;
// Ad alpha channel if given
if (rgb[3] !== undefined) {
rgb[3] = parseFloat(rgb[3]);
} else {
rgb[3] = 1;
}
}
return rgb;
}
|
javascript
|
function _colorToRgbArray(color) {
var originalColor, elem,
rgb = [],
multiple = 1;
// Deal with complete transparency
if (color === 'transparent') {
color = 'rgba(0, 0, 0, 0)';
} else if (color.match(/^([a-z]+|#[0-9a-f]+)$/gi)) {
// Deal with hexadecimal colors and color names
elem = document.head;
originalColor = elem.style.color;
elem.style.color = color;
color = $.css(elem, 'color');
elem.style.color = originalColor;
}
// Parse RGB string
if (color.match(/^rgb/gi)) {
rgb = color.match(/(\d+(\.\d+)?)/gi);
// Deal with RGB percentages
if (color.match(/%/gi)) {
multiple = 2.55;
}
rgb[0] *= multiple;
rgb[1] *= multiple;
rgb[2] *= multiple;
// Ad alpha channel if given
if (rgb[3] !== undefined) {
rgb[3] = parseFloat(rgb[3]);
} else {
rgb[3] = 1;
}
}
return rgb;
}
|
[
"function",
"_colorToRgbArray",
"(",
"color",
")",
"{",
"var",
"originalColor",
",",
"elem",
",",
"rgb",
"=",
"[",
"]",
",",
"multiple",
"=",
"1",
";",
"// Deal with complete transparency",
"if",
"(",
"color",
"===",
"'transparent'",
")",
"{",
"color",
"=",
"'rgba(0, 0, 0, 0)'",
";",
"}",
"else",
"if",
"(",
"color",
".",
"match",
"(",
"/",
"^([a-z]+|#[0-9a-f]+)$",
"/",
"gi",
")",
")",
"{",
"// Deal with hexadecimal colors and color names",
"elem",
"=",
"document",
".",
"head",
";",
"originalColor",
"=",
"elem",
".",
"style",
".",
"color",
";",
"elem",
".",
"style",
".",
"color",
"=",
"color",
";",
"color",
"=",
"$",
".",
"css",
"(",
"elem",
",",
"'color'",
")",
";",
"elem",
".",
"style",
".",
"color",
"=",
"originalColor",
";",
"}",
"// Parse RGB string",
"if",
"(",
"color",
".",
"match",
"(",
"/",
"^rgb",
"/",
"gi",
")",
")",
"{",
"rgb",
"=",
"color",
".",
"match",
"(",
"/",
"(\\d+(\\.\\d+)?)",
"/",
"gi",
")",
";",
"// Deal with RGB percentages",
"if",
"(",
"color",
".",
"match",
"(",
"/",
"%",
"/",
"gi",
")",
")",
"{",
"multiple",
"=",
"2.55",
";",
"}",
"rgb",
"[",
"0",
"]",
"*=",
"multiple",
";",
"rgb",
"[",
"1",
"]",
"*=",
"multiple",
";",
"rgb",
"[",
"2",
"]",
"*=",
"multiple",
";",
"// Ad alpha channel if given",
"if",
"(",
"rgb",
"[",
"3",
"]",
"!==",
"undefined",
")",
"{",
"rgb",
"[",
"3",
"]",
"=",
"parseFloat",
"(",
"rgb",
"[",
"3",
"]",
")",
";",
"}",
"else",
"{",
"rgb",
"[",
"3",
"]",
"=",
"1",
";",
"}",
"}",
"return",
"rgb",
";",
"}"
] |
Convert a color value to an array of RGB values
|
[
"Convert",
"a",
"color",
"value",
"to",
"an",
"array",
"of",
"RGB",
"values"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1832-L1866
|
13,257
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_animateColor
|
function _animateColor(fx) {
var n = 3,
i;
// Only parse start and end colors once
if (typeOf(fx.start) !== 'array') {
fx.start = _colorToRgbArray(fx.start);
fx.end = _colorToRgbArray(fx.end);
}
fx.now = [];
// If colors are RGBA, animate transparency
if (fx.start[3] !== 1 || fx.end[3] !== 1) {
n = 4;
}
// Calculate current frame for red, green, blue, and alpha
for (i = 0; i < n; i += 1) {
fx.now[i] = fx.start[i] + ((fx.end[i] - fx.start[i]) * fx.pos);
// Only the red, green, and blue values must be integers
if (i < 3) {
fx.now[i] = round(fx.now[i]);
}
}
if (fx.start[3] !== 1 || fx.end[3] !== 1) {
// Only use RGBA if RGBA colors are given
fx.now = 'rgba(' + fx.now.join(',') + ')';
} else {
// Otherwise, animate as solid colors
fx.now.slice(0, 3);
fx.now = 'rgb(' + fx.now.join(',') + ')';
}
// Animate colors for both canvas layers and DOM elements
if (fx.elem.nodeName) {
fx.elem.style[fx.prop] = fx.now;
} else {
fx.elem[fx.prop] = fx.now;
}
}
|
javascript
|
function _animateColor(fx) {
var n = 3,
i;
// Only parse start and end colors once
if (typeOf(fx.start) !== 'array') {
fx.start = _colorToRgbArray(fx.start);
fx.end = _colorToRgbArray(fx.end);
}
fx.now = [];
// If colors are RGBA, animate transparency
if (fx.start[3] !== 1 || fx.end[3] !== 1) {
n = 4;
}
// Calculate current frame for red, green, blue, and alpha
for (i = 0; i < n; i += 1) {
fx.now[i] = fx.start[i] + ((fx.end[i] - fx.start[i]) * fx.pos);
// Only the red, green, and blue values must be integers
if (i < 3) {
fx.now[i] = round(fx.now[i]);
}
}
if (fx.start[3] !== 1 || fx.end[3] !== 1) {
// Only use RGBA if RGBA colors are given
fx.now = 'rgba(' + fx.now.join(',') + ')';
} else {
// Otherwise, animate as solid colors
fx.now.slice(0, 3);
fx.now = 'rgb(' + fx.now.join(',') + ')';
}
// Animate colors for both canvas layers and DOM elements
if (fx.elem.nodeName) {
fx.elem.style[fx.prop] = fx.now;
} else {
fx.elem[fx.prop] = fx.now;
}
}
|
[
"function",
"_animateColor",
"(",
"fx",
")",
"{",
"var",
"n",
"=",
"3",
",",
"i",
";",
"// Only parse start and end colors once",
"if",
"(",
"typeOf",
"(",
"fx",
".",
"start",
")",
"!==",
"'array'",
")",
"{",
"fx",
".",
"start",
"=",
"_colorToRgbArray",
"(",
"fx",
".",
"start",
")",
";",
"fx",
".",
"end",
"=",
"_colorToRgbArray",
"(",
"fx",
".",
"end",
")",
";",
"}",
"fx",
".",
"now",
"=",
"[",
"]",
";",
"// If colors are RGBA, animate transparency",
"if",
"(",
"fx",
".",
"start",
"[",
"3",
"]",
"!==",
"1",
"||",
"fx",
".",
"end",
"[",
"3",
"]",
"!==",
"1",
")",
"{",
"n",
"=",
"4",
";",
"}",
"// Calculate current frame for red, green, blue, and alpha",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"+=",
"1",
")",
"{",
"fx",
".",
"now",
"[",
"i",
"]",
"=",
"fx",
".",
"start",
"[",
"i",
"]",
"+",
"(",
"(",
"fx",
".",
"end",
"[",
"i",
"]",
"-",
"fx",
".",
"start",
"[",
"i",
"]",
")",
"*",
"fx",
".",
"pos",
")",
";",
"// Only the red, green, and blue values must be integers",
"if",
"(",
"i",
"<",
"3",
")",
"{",
"fx",
".",
"now",
"[",
"i",
"]",
"=",
"round",
"(",
"fx",
".",
"now",
"[",
"i",
"]",
")",
";",
"}",
"}",
"if",
"(",
"fx",
".",
"start",
"[",
"3",
"]",
"!==",
"1",
"||",
"fx",
".",
"end",
"[",
"3",
"]",
"!==",
"1",
")",
"{",
"// Only use RGBA if RGBA colors are given",
"fx",
".",
"now",
"=",
"'rgba('",
"+",
"fx",
".",
"now",
".",
"join",
"(",
"','",
")",
"+",
"')'",
";",
"}",
"else",
"{",
"// Otherwise, animate as solid colors",
"fx",
".",
"now",
".",
"slice",
"(",
"0",
",",
"3",
")",
";",
"fx",
".",
"now",
"=",
"'rgb('",
"+",
"fx",
".",
"now",
".",
"join",
"(",
"','",
")",
"+",
"')'",
";",
"}",
"// Animate colors for both canvas layers and DOM elements",
"if",
"(",
"fx",
".",
"elem",
".",
"nodeName",
")",
"{",
"fx",
".",
"elem",
".",
"style",
"[",
"fx",
".",
"prop",
"]",
"=",
"fx",
".",
"now",
";",
"}",
"else",
"{",
"fx",
".",
"elem",
"[",
"fx",
".",
"prop",
"]",
"=",
"fx",
".",
"now",
";",
"}",
"}"
] |
Animate a hex or RGB color
|
[
"Animate",
"a",
"hex",
"or",
"RGB",
"color"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1869-L1906
|
13,258
|
caleb531/jcanvas
|
dist/jcanvas.js
|
complete
|
function complete($canvas, data, layer) {
return function () {
_showProps(layer);
_removeSubPropAliases(layer);
// Prevent multiple redraw loops
if (!data.animating || data.animated === layer) {
// Redraw layers on last frame
$canvas.drawLayers();
}
// Signify the end of an animation loop
layer._animating = false;
data.animating = false;
data.animated = null;
// If callback is defined
if (args[4]) {
// Run callback at the end of the animation
args[4].call($canvas[0], layer);
}
_triggerLayerEvent($canvas, data, layer, 'animateend');
};
}
|
javascript
|
function complete($canvas, data, layer) {
return function () {
_showProps(layer);
_removeSubPropAliases(layer);
// Prevent multiple redraw loops
if (!data.animating || data.animated === layer) {
// Redraw layers on last frame
$canvas.drawLayers();
}
// Signify the end of an animation loop
layer._animating = false;
data.animating = false;
data.animated = null;
// If callback is defined
if (args[4]) {
// Run callback at the end of the animation
args[4].call($canvas[0], layer);
}
_triggerLayerEvent($canvas, data, layer, 'animateend');
};
}
|
[
"function",
"complete",
"(",
"$canvas",
",",
"data",
",",
"layer",
")",
"{",
"return",
"function",
"(",
")",
"{",
"_showProps",
"(",
"layer",
")",
";",
"_removeSubPropAliases",
"(",
"layer",
")",
";",
"// Prevent multiple redraw loops",
"if",
"(",
"!",
"data",
".",
"animating",
"||",
"data",
".",
"animated",
"===",
"layer",
")",
"{",
"// Redraw layers on last frame",
"$canvas",
".",
"drawLayers",
"(",
")",
";",
"}",
"// Signify the end of an animation loop",
"layer",
".",
"_animating",
"=",
"false",
";",
"data",
".",
"animating",
"=",
"false",
";",
"data",
".",
"animated",
"=",
"null",
";",
"// If callback is defined",
"if",
"(",
"args",
"[",
"4",
"]",
")",
"{",
"// Run callback at the end of the animation",
"args",
"[",
"4",
"]",
".",
"call",
"(",
"$canvas",
"[",
"0",
"]",
",",
"layer",
")",
";",
"}",
"_triggerLayerEvent",
"(",
"$canvas",
",",
"data",
",",
"layer",
",",
"'animateend'",
")",
";",
"}",
";",
"}"
] |
Run callback function when animation completes
|
[
"Run",
"callback",
"function",
"when",
"animation",
"completes"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L1956-L1984
|
13,259
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_supportColorProps
|
function _supportColorProps(props) {
var p;
for (p = 0; p < props.length; p += 1) {
$.fx.step[props[p]] = _animateColor;
}
}
|
javascript
|
function _supportColorProps(props) {
var p;
for (p = 0; p < props.length; p += 1) {
$.fx.step[props[p]] = _animateColor;
}
}
|
[
"function",
"_supportColorProps",
"(",
"props",
")",
"{",
"var",
"p",
";",
"for",
"(",
"p",
"=",
"0",
";",
"p",
"<",
"props",
".",
"length",
";",
"p",
"+=",
"1",
")",
"{",
"$",
".",
"fx",
".",
"step",
"[",
"props",
"[",
"p",
"]",
"]",
"=",
"_animateColor",
";",
"}",
"}"
] |
Enable animation for color properties
|
[
"Enable",
"animation",
"for",
"color",
"properties"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L2202-L2207
|
13,260
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_getMouseEventName
|
function _getMouseEventName(eventName) {
if (maps.mouseEvents[eventName]) {
eventName = maps.mouseEvents[eventName];
}
return eventName;
}
|
javascript
|
function _getMouseEventName(eventName) {
if (maps.mouseEvents[eventName]) {
eventName = maps.mouseEvents[eventName];
}
return eventName;
}
|
[
"function",
"_getMouseEventName",
"(",
"eventName",
")",
"{",
"if",
"(",
"maps",
".",
"mouseEvents",
"[",
"eventName",
"]",
")",
"{",
"eventName",
"=",
"maps",
".",
"mouseEvents",
"[",
"eventName",
"]",
";",
"}",
"return",
"eventName",
";",
"}"
] |
Convert touch event name to a corresponding mouse event name
|
[
"Convert",
"touch",
"event",
"name",
"to",
"a",
"corresponding",
"mouse",
"event",
"name"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L2248-L2253
|
13,261
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_createEvent
|
function _createEvent(eventName) {
jCanvas.events[eventName] = function ($canvas, data) {
var helperEventName, touchEventName, eventCache;
// Retrieve canvas's event cache
eventCache = data.event;
// Both mouseover/mouseout events will be managed by a single mousemove event
helperEventName = (eventName === 'mouseover' || eventName === 'mouseout') ? 'mousemove' : eventName;
touchEventName = _getTouchEventName(helperEventName);
function eventCallback(event) {
// Cache current mouse position and redraw layers
eventCache.x = event.offsetX;
eventCache.y = event.offsetY;
eventCache.type = helperEventName;
eventCache.event = event;
// Redraw layers on every trigger of the event; don't redraw if at
// least one layer is draggable and there are no layers with
// explicit mouseover/mouseout/mousemove events
if (event.type !== 'mousemove' || data.redrawOnMousemove || data.drag.dragging) {
$canvas.drawLayers({
resetFire: true
});
}
// Prevent default event behavior
event.preventDefault();
}
// Ensure the event is not bound more than once
if (!data.events[helperEventName]) {
// Bind one canvas event which handles all layer events of that type
if (touchEventName !== helperEventName) {
$canvas.bind(helperEventName + '.jCanvas ' + touchEventName + '.jCanvas', eventCallback);
} else {
$canvas.bind(helperEventName + '.jCanvas', eventCallback);
}
// Prevent this event from being bound twice
data.events[helperEventName] = true;
}
};
}
|
javascript
|
function _createEvent(eventName) {
jCanvas.events[eventName] = function ($canvas, data) {
var helperEventName, touchEventName, eventCache;
// Retrieve canvas's event cache
eventCache = data.event;
// Both mouseover/mouseout events will be managed by a single mousemove event
helperEventName = (eventName === 'mouseover' || eventName === 'mouseout') ? 'mousemove' : eventName;
touchEventName = _getTouchEventName(helperEventName);
function eventCallback(event) {
// Cache current mouse position and redraw layers
eventCache.x = event.offsetX;
eventCache.y = event.offsetY;
eventCache.type = helperEventName;
eventCache.event = event;
// Redraw layers on every trigger of the event; don't redraw if at
// least one layer is draggable and there are no layers with
// explicit mouseover/mouseout/mousemove events
if (event.type !== 'mousemove' || data.redrawOnMousemove || data.drag.dragging) {
$canvas.drawLayers({
resetFire: true
});
}
// Prevent default event behavior
event.preventDefault();
}
// Ensure the event is not bound more than once
if (!data.events[helperEventName]) {
// Bind one canvas event which handles all layer events of that type
if (touchEventName !== helperEventName) {
$canvas.bind(helperEventName + '.jCanvas ' + touchEventName + '.jCanvas', eventCallback);
} else {
$canvas.bind(helperEventName + '.jCanvas', eventCallback);
}
// Prevent this event from being bound twice
data.events[helperEventName] = true;
}
};
}
|
[
"function",
"_createEvent",
"(",
"eventName",
")",
"{",
"jCanvas",
".",
"events",
"[",
"eventName",
"]",
"=",
"function",
"(",
"$canvas",
",",
"data",
")",
"{",
"var",
"helperEventName",
",",
"touchEventName",
",",
"eventCache",
";",
"// Retrieve canvas's event cache",
"eventCache",
"=",
"data",
".",
"event",
";",
"// Both mouseover/mouseout events will be managed by a single mousemove event",
"helperEventName",
"=",
"(",
"eventName",
"===",
"'mouseover'",
"||",
"eventName",
"===",
"'mouseout'",
")",
"?",
"'mousemove'",
":",
"eventName",
";",
"touchEventName",
"=",
"_getTouchEventName",
"(",
"helperEventName",
")",
";",
"function",
"eventCallback",
"(",
"event",
")",
"{",
"// Cache current mouse position and redraw layers",
"eventCache",
".",
"x",
"=",
"event",
".",
"offsetX",
";",
"eventCache",
".",
"y",
"=",
"event",
".",
"offsetY",
";",
"eventCache",
".",
"type",
"=",
"helperEventName",
";",
"eventCache",
".",
"event",
"=",
"event",
";",
"// Redraw layers on every trigger of the event; don't redraw if at",
"// least one layer is draggable and there are no layers with",
"// explicit mouseover/mouseout/mousemove events",
"if",
"(",
"event",
".",
"type",
"!==",
"'mousemove'",
"||",
"data",
".",
"redrawOnMousemove",
"||",
"data",
".",
"drag",
".",
"dragging",
")",
"{",
"$canvas",
".",
"drawLayers",
"(",
"{",
"resetFire",
":",
"true",
"}",
")",
";",
"}",
"// Prevent default event behavior",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"// Ensure the event is not bound more than once",
"if",
"(",
"!",
"data",
".",
"events",
"[",
"helperEventName",
"]",
")",
"{",
"// Bind one canvas event which handles all layer events of that type",
"if",
"(",
"touchEventName",
"!==",
"helperEventName",
")",
"{",
"$canvas",
".",
"bind",
"(",
"helperEventName",
"+",
"'.jCanvas '",
"+",
"touchEventName",
"+",
"'.jCanvas'",
",",
"eventCallback",
")",
";",
"}",
"else",
"{",
"$canvas",
".",
"bind",
"(",
"helperEventName",
"+",
"'.jCanvas'",
",",
"eventCallback",
")",
";",
"}",
"// Prevent this event from being bound twice",
"data",
".",
"events",
"[",
"helperEventName",
"]",
"=",
"true",
";",
"}",
"}",
";",
"}"
] |
Bind event to jCanvas layer using standard jQuery events
|
[
"Bind",
"event",
"to",
"jCanvas",
"layer",
"using",
"standard",
"jQuery",
"events"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L2256-L2298
|
13,262
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_detectEvents
|
function _detectEvents(canvas, ctx, params) {
var layer, data, eventCache, intersects,
transforms, x, y, angle;
// Use the layer object stored by the given parameters object
layer = params._args;
// Canvas must have event bindings
if (layer) {
data = _getCanvasData(canvas);
eventCache = data.event;
if (eventCache.x !== null && eventCache.y !== null) {
// Respect user-defined pixel ratio
x = eventCache.x * data.pixelRatio;
y = eventCache.y * data.pixelRatio;
// Determine if the given coordinates are in the current path
intersects = ctx.isPointInPath(x, y) || (ctx.isPointInStroke && ctx.isPointInStroke(x, y));
}
transforms = data.transforms;
// Allow callback functions to retrieve the mouse coordinates
layer.eventX = eventCache.x;
layer.eventY = eventCache.y;
layer.event = eventCache.event;
// Adjust coordinates to match current canvas transformation
// Keep track of some transformation values
angle = data.transforms.rotate;
x = layer.eventX;
y = layer.eventY;
if (angle !== 0) {
// Rotate coordinates if coordinate space has been rotated
layer._eventX = (x * cos(-angle)) - (y * sin(-angle));
layer._eventY = (y * cos(-angle)) + (x * sin(-angle));
} else {
// Otherwise, no calculations need to be made
layer._eventX = x;
layer._eventY = y;
}
// Scale coordinates
layer._eventX /= transforms.scaleX;
layer._eventY /= transforms.scaleY;
// If layer intersects with cursor
if (intersects) {
// Add it to a list of layers that intersect with cursor
data.intersecting.push(layer);
}
layer.intersects = Boolean(intersects);
}
}
|
javascript
|
function _detectEvents(canvas, ctx, params) {
var layer, data, eventCache, intersects,
transforms, x, y, angle;
// Use the layer object stored by the given parameters object
layer = params._args;
// Canvas must have event bindings
if (layer) {
data = _getCanvasData(canvas);
eventCache = data.event;
if (eventCache.x !== null && eventCache.y !== null) {
// Respect user-defined pixel ratio
x = eventCache.x * data.pixelRatio;
y = eventCache.y * data.pixelRatio;
// Determine if the given coordinates are in the current path
intersects = ctx.isPointInPath(x, y) || (ctx.isPointInStroke && ctx.isPointInStroke(x, y));
}
transforms = data.transforms;
// Allow callback functions to retrieve the mouse coordinates
layer.eventX = eventCache.x;
layer.eventY = eventCache.y;
layer.event = eventCache.event;
// Adjust coordinates to match current canvas transformation
// Keep track of some transformation values
angle = data.transforms.rotate;
x = layer.eventX;
y = layer.eventY;
if (angle !== 0) {
// Rotate coordinates if coordinate space has been rotated
layer._eventX = (x * cos(-angle)) - (y * sin(-angle));
layer._eventY = (y * cos(-angle)) + (x * sin(-angle));
} else {
// Otherwise, no calculations need to be made
layer._eventX = x;
layer._eventY = y;
}
// Scale coordinates
layer._eventX /= transforms.scaleX;
layer._eventY /= transforms.scaleY;
// If layer intersects with cursor
if (intersects) {
// Add it to a list of layers that intersect with cursor
data.intersecting.push(layer);
}
layer.intersects = Boolean(intersects);
}
}
|
[
"function",
"_detectEvents",
"(",
"canvas",
",",
"ctx",
",",
"params",
")",
"{",
"var",
"layer",
",",
"data",
",",
"eventCache",
",",
"intersects",
",",
"transforms",
",",
"x",
",",
"y",
",",
"angle",
";",
"// Use the layer object stored by the given parameters object",
"layer",
"=",
"params",
".",
"_args",
";",
"// Canvas must have event bindings",
"if",
"(",
"layer",
")",
"{",
"data",
"=",
"_getCanvasData",
"(",
"canvas",
")",
";",
"eventCache",
"=",
"data",
".",
"event",
";",
"if",
"(",
"eventCache",
".",
"x",
"!==",
"null",
"&&",
"eventCache",
".",
"y",
"!==",
"null",
")",
"{",
"// Respect user-defined pixel ratio",
"x",
"=",
"eventCache",
".",
"x",
"*",
"data",
".",
"pixelRatio",
";",
"y",
"=",
"eventCache",
".",
"y",
"*",
"data",
".",
"pixelRatio",
";",
"// Determine if the given coordinates are in the current path",
"intersects",
"=",
"ctx",
".",
"isPointInPath",
"(",
"x",
",",
"y",
")",
"||",
"(",
"ctx",
".",
"isPointInStroke",
"&&",
"ctx",
".",
"isPointInStroke",
"(",
"x",
",",
"y",
")",
")",
";",
"}",
"transforms",
"=",
"data",
".",
"transforms",
";",
"// Allow callback functions to retrieve the mouse coordinates",
"layer",
".",
"eventX",
"=",
"eventCache",
".",
"x",
";",
"layer",
".",
"eventY",
"=",
"eventCache",
".",
"y",
";",
"layer",
".",
"event",
"=",
"eventCache",
".",
"event",
";",
"// Adjust coordinates to match current canvas transformation",
"// Keep track of some transformation values",
"angle",
"=",
"data",
".",
"transforms",
".",
"rotate",
";",
"x",
"=",
"layer",
".",
"eventX",
";",
"y",
"=",
"layer",
".",
"eventY",
";",
"if",
"(",
"angle",
"!==",
"0",
")",
"{",
"// Rotate coordinates if coordinate space has been rotated",
"layer",
".",
"_eventX",
"=",
"(",
"x",
"*",
"cos",
"(",
"-",
"angle",
")",
")",
"-",
"(",
"y",
"*",
"sin",
"(",
"-",
"angle",
")",
")",
";",
"layer",
".",
"_eventY",
"=",
"(",
"y",
"*",
"cos",
"(",
"-",
"angle",
")",
")",
"+",
"(",
"x",
"*",
"sin",
"(",
"-",
"angle",
")",
")",
";",
"}",
"else",
"{",
"// Otherwise, no calculations need to be made",
"layer",
".",
"_eventX",
"=",
"x",
";",
"layer",
".",
"_eventY",
"=",
"y",
";",
"}",
"// Scale coordinates",
"layer",
".",
"_eventX",
"/=",
"transforms",
".",
"scaleX",
";",
"layer",
".",
"_eventY",
"/=",
"transforms",
".",
"scaleY",
";",
"// If layer intersects with cursor",
"if",
"(",
"intersects",
")",
"{",
"// Add it to a list of layers that intersect with cursor",
"data",
".",
"intersecting",
".",
"push",
"(",
"layer",
")",
";",
"}",
"layer",
".",
"intersects",
"=",
"Boolean",
"(",
"intersects",
")",
";",
"}",
"}"
] |
Check if event fires when a drawing is drawn
|
[
"Check",
"if",
"event",
"fires",
"when",
"a",
"drawing",
"is",
"drawn"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L2324-L2377
|
13,263
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_addStartArrow
|
function _addStartArrow(canvas, ctx, params, path, x1, y1, x2, y2) {
if (!path._arrowAngleConverted) {
path.arrowAngle *= params._toRad;
path._arrowAngleConverted = true;
}
if (path.startArrow) {
_addArrow(canvas, ctx, params, path, x1, y1, x2, y2);
}
}
|
javascript
|
function _addStartArrow(canvas, ctx, params, path, x1, y1, x2, y2) {
if (!path._arrowAngleConverted) {
path.arrowAngle *= params._toRad;
path._arrowAngleConverted = true;
}
if (path.startArrow) {
_addArrow(canvas, ctx, params, path, x1, y1, x2, y2);
}
}
|
[
"function",
"_addStartArrow",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"path",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"{",
"if",
"(",
"!",
"path",
".",
"_arrowAngleConverted",
")",
"{",
"path",
".",
"arrowAngle",
"*=",
"params",
".",
"_toRad",
";",
"path",
".",
"_arrowAngleConverted",
"=",
"true",
";",
"}",
"if",
"(",
"path",
".",
"startArrow",
")",
"{",
"_addArrow",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"path",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
";",
"}",
"}"
] |
Optionally adds arrow to start of path
|
[
"Optionally",
"adds",
"arrow",
"to",
"start",
"of",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3102-L3110
|
13,264
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_addEndArrow
|
function _addEndArrow(canvas, ctx, params, path, x1, y1, x2, y2) {
if (!path._arrowAngleConverted) {
path.arrowAngle *= params._toRad;
path._arrowAngleConverted = true;
}
if (path.endArrow) {
_addArrow(canvas, ctx, params, path, x1, y1, x2, y2);
}
}
|
javascript
|
function _addEndArrow(canvas, ctx, params, path, x1, y1, x2, y2) {
if (!path._arrowAngleConverted) {
path.arrowAngle *= params._toRad;
path._arrowAngleConverted = true;
}
if (path.endArrow) {
_addArrow(canvas, ctx, params, path, x1, y1, x2, y2);
}
}
|
[
"function",
"_addEndArrow",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"path",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"{",
"if",
"(",
"!",
"path",
".",
"_arrowAngleConverted",
")",
"{",
"path",
".",
"arrowAngle",
"*=",
"params",
".",
"_toRad",
";",
"path",
".",
"_arrowAngleConverted",
"=",
"true",
";",
"}",
"if",
"(",
"path",
".",
"endArrow",
")",
"{",
"_addArrow",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"path",
",",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
";",
"}",
"}"
] |
Optionally adds arrow to end of path
|
[
"Optionally",
"adds",
"arrow",
"to",
"end",
"of",
"path"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3113-L3121
|
13,265
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_getVectorX
|
function _getVectorX(params, angle, length) {
angle *= params._toRad;
angle -= (PI / 2);
return (length * cos(angle));
}
|
javascript
|
function _getVectorX(params, angle, length) {
angle *= params._toRad;
angle -= (PI / 2);
return (length * cos(angle));
}
|
[
"function",
"_getVectorX",
"(",
"params",
",",
"angle",
",",
"length",
")",
"{",
"angle",
"*=",
"params",
".",
"_toRad",
";",
"angle",
"-=",
"(",
"PI",
"/",
"2",
")",
";",
"return",
"(",
"length",
"*",
"cos",
"(",
"angle",
")",
")",
";",
"}"
] |
Retrieves the x-coordinate for the given vector angle and length
|
[
"Retrieves",
"the",
"x",
"-",
"coordinate",
"for",
"the",
"given",
"vector",
"angle",
"and",
"length"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3366-L3370
|
13,266
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_getVectorY
|
function _getVectorY(params, angle, length) {
angle *= params._toRad;
angle -= (PI / 2);
return (length * sin(angle));
}
|
javascript
|
function _getVectorY(params, angle, length) {
angle *= params._toRad;
angle -= (PI / 2);
return (length * sin(angle));
}
|
[
"function",
"_getVectorY",
"(",
"params",
",",
"angle",
",",
"length",
")",
"{",
"angle",
"*=",
"params",
".",
"_toRad",
";",
"angle",
"-=",
"(",
"PI",
"/",
"2",
")",
";",
"return",
"(",
"length",
"*",
"sin",
"(",
"angle",
")",
")",
";",
"}"
] |
Retrieves the y-coordinate for the given vector angle and length
|
[
"Retrieves",
"the",
"y",
"-",
"coordinate",
"for",
"the",
"given",
"vector",
"angle",
"and",
"length"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3372-L3376
|
13,267
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_measureText
|
function _measureText(canvas, ctx, params, lines) {
var originalSize, curWidth, l,
propCache = caches.propCache;
// Used cached width/height if possible
if (propCache.text === params.text && propCache.fontStyle === params.fontStyle && propCache.fontSize === params.fontSize && propCache.fontFamily === params.fontFamily && propCache.maxWidth === params.maxWidth && propCache.lineHeight === params.lineHeight) {
params.width = propCache.width;
params.height = propCache.height;
} else {
// Calculate text dimensions only once
// Calculate width of first line (for comparison)
params.width = ctx.measureText(lines[0]).width;
// Get width of longest line
for (l = 1; l < lines.length; l += 1) {
curWidth = ctx.measureText(lines[l]).width;
// Ensure text's width is the width of its longest line
if (curWidth > params.width) {
params.width = curWidth;
}
}
// Save original font size
originalSize = canvas.style.fontSize;
// Temporarily set canvas font size to retrieve size in pixels
canvas.style.fontSize = params.fontSize;
// Save text width and height in parameters object
params.height = parseFloat($.css(canvas, 'fontSize')) * lines.length * params.lineHeight;
// Reset font size to original size
canvas.style.fontSize = originalSize;
}
}
|
javascript
|
function _measureText(canvas, ctx, params, lines) {
var originalSize, curWidth, l,
propCache = caches.propCache;
// Used cached width/height if possible
if (propCache.text === params.text && propCache.fontStyle === params.fontStyle && propCache.fontSize === params.fontSize && propCache.fontFamily === params.fontFamily && propCache.maxWidth === params.maxWidth && propCache.lineHeight === params.lineHeight) {
params.width = propCache.width;
params.height = propCache.height;
} else {
// Calculate text dimensions only once
// Calculate width of first line (for comparison)
params.width = ctx.measureText(lines[0]).width;
// Get width of longest line
for (l = 1; l < lines.length; l += 1) {
curWidth = ctx.measureText(lines[l]).width;
// Ensure text's width is the width of its longest line
if (curWidth > params.width) {
params.width = curWidth;
}
}
// Save original font size
originalSize = canvas.style.fontSize;
// Temporarily set canvas font size to retrieve size in pixels
canvas.style.fontSize = params.fontSize;
// Save text width and height in parameters object
params.height = parseFloat($.css(canvas, 'fontSize')) * lines.length * params.lineHeight;
// Reset font size to original size
canvas.style.fontSize = originalSize;
}
}
|
[
"function",
"_measureText",
"(",
"canvas",
",",
"ctx",
",",
"params",
",",
"lines",
")",
"{",
"var",
"originalSize",
",",
"curWidth",
",",
"l",
",",
"propCache",
"=",
"caches",
".",
"propCache",
";",
"// Used cached width/height if possible",
"if",
"(",
"propCache",
".",
"text",
"===",
"params",
".",
"text",
"&&",
"propCache",
".",
"fontStyle",
"===",
"params",
".",
"fontStyle",
"&&",
"propCache",
".",
"fontSize",
"===",
"params",
".",
"fontSize",
"&&",
"propCache",
".",
"fontFamily",
"===",
"params",
".",
"fontFamily",
"&&",
"propCache",
".",
"maxWidth",
"===",
"params",
".",
"maxWidth",
"&&",
"propCache",
".",
"lineHeight",
"===",
"params",
".",
"lineHeight",
")",
"{",
"params",
".",
"width",
"=",
"propCache",
".",
"width",
";",
"params",
".",
"height",
"=",
"propCache",
".",
"height",
";",
"}",
"else",
"{",
"// Calculate text dimensions only once",
"// Calculate width of first line (for comparison)",
"params",
".",
"width",
"=",
"ctx",
".",
"measureText",
"(",
"lines",
"[",
"0",
"]",
")",
".",
"width",
";",
"// Get width of longest line",
"for",
"(",
"l",
"=",
"1",
";",
"l",
"<",
"lines",
".",
"length",
";",
"l",
"+=",
"1",
")",
"{",
"curWidth",
"=",
"ctx",
".",
"measureText",
"(",
"lines",
"[",
"l",
"]",
")",
".",
"width",
";",
"// Ensure text's width is the width of its longest line",
"if",
"(",
"curWidth",
">",
"params",
".",
"width",
")",
"{",
"params",
".",
"width",
"=",
"curWidth",
";",
"}",
"}",
"// Save original font size",
"originalSize",
"=",
"canvas",
".",
"style",
".",
"fontSize",
";",
"// Temporarily set canvas font size to retrieve size in pixels",
"canvas",
".",
"style",
".",
"fontSize",
"=",
"params",
".",
"fontSize",
";",
"// Save text width and height in parameters object",
"params",
".",
"height",
"=",
"parseFloat",
"(",
"$",
".",
"css",
"(",
"canvas",
",",
"'fontSize'",
")",
")",
"*",
"lines",
".",
"length",
"*",
"params",
".",
"lineHeight",
";",
"// Reset font size to original size",
"canvas",
".",
"style",
".",
"fontSize",
"=",
"originalSize",
";",
"}",
"}"
] |
Measures canvas text
|
[
"Measures",
"canvas",
"text"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3537-L3573
|
13,268
|
caleb531/jcanvas
|
dist/jcanvas.js
|
_wrapText
|
function _wrapText(ctx, params) {
var allText = String(params.text),
// Maximum line width (optional)
maxWidth = params.maxWidth,
// Lines created by manual line breaks (\n)
manualLines = allText.split('\n'),
// All lines created manually and by wrapping
allLines = [],
// Other variables
lines, line, l,
text, words, w;
// Loop through manually-broken lines
for (l = 0; l < manualLines.length; l += 1) {
text = manualLines[l];
// Split line into list of words
words = text.split(' ');
lines = [];
line = '';
// If text is short enough initially
// Or, if the text consists of only one word
if (words.length === 1 || ctx.measureText(text).width < maxWidth) {
// No need to wrap text
lines = [text];
} else {
// Wrap lines
for (w = 0; w < words.length; w += 1) {
// Once line gets too wide, push word to next line
if (ctx.measureText(line + words[w]).width > maxWidth) {
// This check prevents empty lines from being created
if (line !== '') {
lines.push(line);
}
// Start new line and repeat process
line = '';
}
// Add words to line until the line is too wide
line += words[w];
// Do not add a space after the last word
if (w !== (words.length - 1)) {
line += ' ';
}
}
// The last word should always be pushed
lines.push(line);
}
// Remove extra space at the end of each line
allLines = allLines.concat(
lines
.join('\n')
.replace(/((\n))|($)/gi, '$2')
.split('\n')
);
}
return allLines;
}
|
javascript
|
function _wrapText(ctx, params) {
var allText = String(params.text),
// Maximum line width (optional)
maxWidth = params.maxWidth,
// Lines created by manual line breaks (\n)
manualLines = allText.split('\n'),
// All lines created manually and by wrapping
allLines = [],
// Other variables
lines, line, l,
text, words, w;
// Loop through manually-broken lines
for (l = 0; l < manualLines.length; l += 1) {
text = manualLines[l];
// Split line into list of words
words = text.split(' ');
lines = [];
line = '';
// If text is short enough initially
// Or, if the text consists of only one word
if (words.length === 1 || ctx.measureText(text).width < maxWidth) {
// No need to wrap text
lines = [text];
} else {
// Wrap lines
for (w = 0; w < words.length; w += 1) {
// Once line gets too wide, push word to next line
if (ctx.measureText(line + words[w]).width > maxWidth) {
// This check prevents empty lines from being created
if (line !== '') {
lines.push(line);
}
// Start new line and repeat process
line = '';
}
// Add words to line until the line is too wide
line += words[w];
// Do not add a space after the last word
if (w !== (words.length - 1)) {
line += ' ';
}
}
// The last word should always be pushed
lines.push(line);
}
// Remove extra space at the end of each line
allLines = allLines.concat(
lines
.join('\n')
.replace(/((\n))|($)/gi, '$2')
.split('\n')
);
}
return allLines;
}
|
[
"function",
"_wrapText",
"(",
"ctx",
",",
"params",
")",
"{",
"var",
"allText",
"=",
"String",
"(",
"params",
".",
"text",
")",
",",
"// Maximum line width (optional)",
"maxWidth",
"=",
"params",
".",
"maxWidth",
",",
"// Lines created by manual line breaks (\\n)",
"manualLines",
"=",
"allText",
".",
"split",
"(",
"'\\n'",
")",
",",
"// All lines created manually and by wrapping",
"allLines",
"=",
"[",
"]",
",",
"// Other variables",
"lines",
",",
"line",
",",
"l",
",",
"text",
",",
"words",
",",
"w",
";",
"// Loop through manually-broken lines",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"manualLines",
".",
"length",
";",
"l",
"+=",
"1",
")",
"{",
"text",
"=",
"manualLines",
"[",
"l",
"]",
";",
"// Split line into list of words",
"words",
"=",
"text",
".",
"split",
"(",
"' '",
")",
";",
"lines",
"=",
"[",
"]",
";",
"line",
"=",
"''",
";",
"// If text is short enough initially",
"// Or, if the text consists of only one word",
"if",
"(",
"words",
".",
"length",
"===",
"1",
"||",
"ctx",
".",
"measureText",
"(",
"text",
")",
".",
"width",
"<",
"maxWidth",
")",
"{",
"// No need to wrap text",
"lines",
"=",
"[",
"text",
"]",
";",
"}",
"else",
"{",
"// Wrap lines",
"for",
"(",
"w",
"=",
"0",
";",
"w",
"<",
"words",
".",
"length",
";",
"w",
"+=",
"1",
")",
"{",
"// Once line gets too wide, push word to next line",
"if",
"(",
"ctx",
".",
"measureText",
"(",
"line",
"+",
"words",
"[",
"w",
"]",
")",
".",
"width",
">",
"maxWidth",
")",
"{",
"// This check prevents empty lines from being created",
"if",
"(",
"line",
"!==",
"''",
")",
"{",
"lines",
".",
"push",
"(",
"line",
")",
";",
"}",
"// Start new line and repeat process",
"line",
"=",
"''",
";",
"}",
"// Add words to line until the line is too wide",
"line",
"+=",
"words",
"[",
"w",
"]",
";",
"// Do not add a space after the last word",
"if",
"(",
"w",
"!==",
"(",
"words",
".",
"length",
"-",
"1",
")",
")",
"{",
"line",
"+=",
"' '",
";",
"}",
"}",
"// The last word should always be pushed",
"lines",
".",
"push",
"(",
"line",
")",
";",
"}",
"// Remove extra space at the end of each line",
"allLines",
"=",
"allLines",
".",
"concat",
"(",
"lines",
".",
"join",
"(",
"'\\n'",
")",
".",
"replace",
"(",
"/",
"((\\n))|($)",
"/",
"gi",
",",
"'$2'",
")",
".",
"split",
"(",
"'\\n'",
")",
")",
";",
"}",
"return",
"allLines",
";",
"}"
] |
Wraps a string of text within a defined width
|
[
"Wraps",
"a",
"string",
"of",
"text",
"within",
"a",
"defined",
"width"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas.js#L3576-L3640
|
13,269
|
caleb531/jcanvas
|
dist/jcanvas-crescents.js
|
getIntersection
|
function getIntersection(x0, y0, r0, x1, y1, r1) {
var dx = x1 - x0,
dy = y1 - y0,
d = sqrt(pow(dx, 2) + pow(dy, 2)),
a = (pow(d, 2) + pow(r0, 2) - pow(r1, 2)) / (2 * d),
x2 = x0 + (dx * a / d),
y2 = y0 + (dy * a / d),
h = sqrt(pow(r0, 2) - pow(a, 2)),
rx = -dy * (h / d),
ry = dx * (h / d),
xi = x2 + rx,
yi = y2 + ry;
// Check if circles do not intersect or overlap completely
if (d > (r0 + r1) || d < Math.abs(r0 - r1)) {
return false;
}
return [xi, yi];
}
|
javascript
|
function getIntersection(x0, y0, r0, x1, y1, r1) {
var dx = x1 - x0,
dy = y1 - y0,
d = sqrt(pow(dx, 2) + pow(dy, 2)),
a = (pow(d, 2) + pow(r0, 2) - pow(r1, 2)) / (2 * d),
x2 = x0 + (dx * a / d),
y2 = y0 + (dy * a / d),
h = sqrt(pow(r0, 2) - pow(a, 2)),
rx = -dy * (h / d),
ry = dx * (h / d),
xi = x2 + rx,
yi = y2 + ry;
// Check if circles do not intersect or overlap completely
if (d > (r0 + r1) || d < Math.abs(r0 - r1)) {
return false;
}
return [xi, yi];
}
|
[
"function",
"getIntersection",
"(",
"x0",
",",
"y0",
",",
"r0",
",",
"x1",
",",
"y1",
",",
"r1",
")",
"{",
"var",
"dx",
"=",
"x1",
"-",
"x0",
",",
"dy",
"=",
"y1",
"-",
"y0",
",",
"d",
"=",
"sqrt",
"(",
"pow",
"(",
"dx",
",",
"2",
")",
"+",
"pow",
"(",
"dy",
",",
"2",
")",
")",
",",
"a",
"=",
"(",
"pow",
"(",
"d",
",",
"2",
")",
"+",
"pow",
"(",
"r0",
",",
"2",
")",
"-",
"pow",
"(",
"r1",
",",
"2",
")",
")",
"/",
"(",
"2",
"*",
"d",
")",
",",
"x2",
"=",
"x0",
"+",
"(",
"dx",
"*",
"a",
"/",
"d",
")",
",",
"y2",
"=",
"y0",
"+",
"(",
"dy",
"*",
"a",
"/",
"d",
")",
",",
"h",
"=",
"sqrt",
"(",
"pow",
"(",
"r0",
",",
"2",
")",
"-",
"pow",
"(",
"a",
",",
"2",
")",
")",
",",
"rx",
"=",
"-",
"dy",
"*",
"(",
"h",
"/",
"d",
")",
",",
"ry",
"=",
"dx",
"*",
"(",
"h",
"/",
"d",
")",
",",
"xi",
"=",
"x2",
"+",
"rx",
",",
"yi",
"=",
"y2",
"+",
"ry",
";",
"// Check if circles do not intersect or overlap completely",
"if",
"(",
"d",
">",
"(",
"r0",
"+",
"r1",
")",
"||",
"d",
"<",
"Math",
".",
"abs",
"(",
"r0",
"-",
"r1",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"[",
"xi",
",",
"yi",
"]",
";",
"}"
] |
Get the topmost intersection point of two circles
|
[
"Get",
"the",
"topmost",
"intersection",
"point",
"of",
"two",
"circles"
] |
d156506c4c0890419414af7de8dea1740c91884a
|
https://github.com/caleb531/jcanvas/blob/d156506c4c0890419414af7de8dea1740c91884a/dist/jcanvas-crescents.js#L15-L33
|
13,270
|
choojs/nanohtml
|
lib/babel.js
|
getElementName
|
function getElementName (props, tag) {
if (typeof props.id === 'string' && !placeholderRe.test(props.id)) {
return camelCase(props.id)
}
if (typeof props.className === 'string' && !placeholderRe.test(props.className)) {
return camelCase(props.className.split(' ')[0])
}
return tag || 'nanohtml'
}
|
javascript
|
function getElementName (props, tag) {
if (typeof props.id === 'string' && !placeholderRe.test(props.id)) {
return camelCase(props.id)
}
if (typeof props.className === 'string' && !placeholderRe.test(props.className)) {
return camelCase(props.className.split(' ')[0])
}
return tag || 'nanohtml'
}
|
[
"function",
"getElementName",
"(",
"props",
",",
"tag",
")",
"{",
"if",
"(",
"typeof",
"props",
".",
"id",
"===",
"'string'",
"&&",
"!",
"placeholderRe",
".",
"test",
"(",
"props",
".",
"id",
")",
")",
"{",
"return",
"camelCase",
"(",
"props",
".",
"id",
")",
"}",
"if",
"(",
"typeof",
"props",
".",
"className",
"===",
"'string'",
"&&",
"!",
"placeholderRe",
".",
"test",
"(",
"props",
".",
"className",
")",
")",
"{",
"return",
"camelCase",
"(",
"props",
".",
"className",
".",
"split",
"(",
"' '",
")",
"[",
"0",
"]",
")",
"}",
"return",
"tag",
"||",
"'nanohtml'",
"}"
] |
Try to return a nice variable name for an element based on its HTML id,
classname, or tagname.
|
[
"Try",
"to",
"return",
"a",
"nice",
"variable",
"name",
"for",
"an",
"element",
"based",
"on",
"its",
"HTML",
"id",
"classname",
"or",
"tagname",
"."
] |
535063575a2ff3ff0fbd8eb2d118d8f4279760c3
|
https://github.com/choojs/nanohtml/blob/535063575a2ff3ff0fbd8eb2d118d8f4279760c3/lib/babel.js#L17-L25
|
13,271
|
choojs/nanohtml
|
lib/babel.js
|
convertPlaceholders
|
function convertPlaceholders (value) {
// Probably AST nodes.
if (typeof value !== 'string') {
return [value]
}
const items = value.split(placeholderRe)
let placeholder = true
return items.map((item) => {
placeholder = !placeholder
return placeholder ? expressions[item] : t.stringLiteral(item)
})
}
|
javascript
|
function convertPlaceholders (value) {
// Probably AST nodes.
if (typeof value !== 'string') {
return [value]
}
const items = value.split(placeholderRe)
let placeholder = true
return items.map((item) => {
placeholder = !placeholder
return placeholder ? expressions[item] : t.stringLiteral(item)
})
}
|
[
"function",
"convertPlaceholders",
"(",
"value",
")",
"{",
"// Probably AST nodes.",
"if",
"(",
"typeof",
"value",
"!==",
"'string'",
")",
"{",
"return",
"[",
"value",
"]",
"}",
"const",
"items",
"=",
"value",
".",
"split",
"(",
"placeholderRe",
")",
"let",
"placeholder",
"=",
"true",
"return",
"items",
".",
"map",
"(",
"(",
"item",
")",
"=>",
"{",
"placeholder",
"=",
"!",
"placeholder",
"return",
"placeholder",
"?",
"expressions",
"[",
"item",
"]",
":",
"t",
".",
"stringLiteral",
"(",
"item",
")",
"}",
")",
"}"
] |
Convert placeholders used in the template string back to the AST nodes
they reference.
|
[
"Convert",
"placeholders",
"used",
"in",
"the",
"template",
"string",
"back",
"to",
"the",
"AST",
"nodes",
"they",
"reference",
"."
] |
535063575a2ff3ff0fbd8eb2d118d8f4279760c3
|
https://github.com/choojs/nanohtml/blob/535063575a2ff3ff0fbd8eb2d118d8f4279760c3/lib/babel.js#L206-L218
|
13,272
|
ekalinin/sitemap.js
|
lib/sitemap.js
|
buildSitemapIndex
|
function buildSitemapIndex (conf) {
var xml = [];
var lastmod;
xml.push('<?xml version="1.0" encoding="UTF-8"?>');
if (conf.xslUrl) {
xml.push('<?xml-stylesheet type="text/xsl" href="' + conf.xslUrl + '"?>');
}
if (!conf.xmlNs) {
xml.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' +
'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" ' +
'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' +
'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">');
} else {
xml.push('<sitemapindex ' + conf.xmlNs + '>')
}
if (conf.lastmodISO) {
lastmod = conf.lastmodISO;
} else if (conf.lastmodrealtime) {
lastmod = new Date().toISOString();
} else if (conf.lastmod) {
lastmod = new Date(conf.lastmod).toISOString();
}
conf.urls.forEach(url => {
if (url instanceof Object) {
lastmod = url.lastmod ? url.lastmod : lastmod;
url = url.url;
}
xml.push('<sitemap>');
xml.push('<loc>' + url + '</loc>');
if (lastmod) {
xml.push('<lastmod>' + lastmod + '</lastmod>');
}
xml.push('</sitemap>');
});
xml.push('</sitemapindex>');
return xml.join('\n');
}
|
javascript
|
function buildSitemapIndex (conf) {
var xml = [];
var lastmod;
xml.push('<?xml version="1.0" encoding="UTF-8"?>');
if (conf.xslUrl) {
xml.push('<?xml-stylesheet type="text/xsl" href="' + conf.xslUrl + '"?>');
}
if (!conf.xmlNs) {
xml.push('<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" ' +
'xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" ' +
'xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ' +
'xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">');
} else {
xml.push('<sitemapindex ' + conf.xmlNs + '>')
}
if (conf.lastmodISO) {
lastmod = conf.lastmodISO;
} else if (conf.lastmodrealtime) {
lastmod = new Date().toISOString();
} else if (conf.lastmod) {
lastmod = new Date(conf.lastmod).toISOString();
}
conf.urls.forEach(url => {
if (url instanceof Object) {
lastmod = url.lastmod ? url.lastmod : lastmod;
url = url.url;
}
xml.push('<sitemap>');
xml.push('<loc>' + url + '</loc>');
if (lastmod) {
xml.push('<lastmod>' + lastmod + '</lastmod>');
}
xml.push('</sitemap>');
});
xml.push('</sitemapindex>');
return xml.join('\n');
}
|
[
"function",
"buildSitemapIndex",
"(",
"conf",
")",
"{",
"var",
"xml",
"=",
"[",
"]",
";",
"var",
"lastmod",
";",
"xml",
".",
"push",
"(",
"'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'",
")",
";",
"if",
"(",
"conf",
".",
"xslUrl",
")",
"{",
"xml",
".",
"push",
"(",
"'<?xml-stylesheet type=\"text/xsl\" href=\"'",
"+",
"conf",
".",
"xslUrl",
"+",
"'\"?>'",
")",
";",
"}",
"if",
"(",
"!",
"conf",
".",
"xmlNs",
")",
"{",
"xml",
".",
"push",
"(",
"'<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" '",
"+",
"'xmlns:mobile=\"http://www.google.com/schemas/sitemap-mobile/1.0\" '",
"+",
"'xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\" '",
"+",
"'xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">'",
")",
";",
"}",
"else",
"{",
"xml",
".",
"push",
"(",
"'<sitemapindex '",
"+",
"conf",
".",
"xmlNs",
"+",
"'>'",
")",
"}",
"if",
"(",
"conf",
".",
"lastmodISO",
")",
"{",
"lastmod",
"=",
"conf",
".",
"lastmodISO",
";",
"}",
"else",
"if",
"(",
"conf",
".",
"lastmodrealtime",
")",
"{",
"lastmod",
"=",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"conf",
".",
"lastmod",
")",
"{",
"lastmod",
"=",
"new",
"Date",
"(",
"conf",
".",
"lastmod",
")",
".",
"toISOString",
"(",
")",
";",
"}",
"conf",
".",
"urls",
".",
"forEach",
"(",
"url",
"=>",
"{",
"if",
"(",
"url",
"instanceof",
"Object",
")",
"{",
"lastmod",
"=",
"url",
".",
"lastmod",
"?",
"url",
".",
"lastmod",
":",
"lastmod",
";",
"url",
"=",
"url",
".",
"url",
";",
"}",
"xml",
".",
"push",
"(",
"'<sitemap>'",
")",
";",
"xml",
".",
"push",
"(",
"'<loc>'",
"+",
"url",
"+",
"'</loc>'",
")",
";",
"if",
"(",
"lastmod",
")",
"{",
"xml",
".",
"push",
"(",
"'<lastmod>'",
"+",
"lastmod",
"+",
"'</lastmod>'",
")",
";",
"}",
"xml",
".",
"push",
"(",
"'</sitemap>'",
")",
";",
"}",
")",
";",
"xml",
".",
"push",
"(",
"'</sitemapindex>'",
")",
";",
"return",
"xml",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] |
Builds a sitemap index from urls
@param {Object} conf
@param {Array} conf.urls
@param {String} conf.xslUrl
@param {String} conf.xmlNs
@return {String} XML String of SitemapIndex
|
[
"Builds",
"a",
"sitemap",
"index",
"from",
"urls"
] |
682e9fc731b476e0c0263fe683fbd0e392b7b49b
|
https://github.com/ekalinin/sitemap.js/blob/682e9fc731b476e0c0263fe683fbd0e392b7b49b/lib/sitemap.js#L272-L315
|
13,273
|
cerebral/cerebral
|
packages/website/builder/pages/docs/nav.js
|
Headings
|
function Headings({ toc, path }) {
if (!toc.length) {
return null
}
return (
<ul>
{toc.map(function(item, index) {
const href = `${path}#${item.id}`
return (
<li key={index}>
{item.children.length > 0 && (
<input
id={href}
className="nav_toggle"
type="checkbox"
defaultChecked={false}
/>
)}
<a
className={`nav_toggle-label nav_item-name nav_sublink
${item.children.length ? '' : 'nav_childless'}`}
href={href}
>
{item.title}
</a>
<Headings toc={item.children} path={path} />
</li>
)
})}
</ul>
)
}
|
javascript
|
function Headings({ toc, path }) {
if (!toc.length) {
return null
}
return (
<ul>
{toc.map(function(item, index) {
const href = `${path}#${item.id}`
return (
<li key={index}>
{item.children.length > 0 && (
<input
id={href}
className="nav_toggle"
type="checkbox"
defaultChecked={false}
/>
)}
<a
className={`nav_toggle-label nav_item-name nav_sublink
${item.children.length ? '' : 'nav_childless'}`}
href={href}
>
{item.title}
</a>
<Headings toc={item.children} path={path} />
</li>
)
})}
</ul>
)
}
|
[
"function",
"Headings",
"(",
"{",
"toc",
",",
"path",
"}",
")",
"{",
"if",
"(",
"!",
"toc",
".",
"length",
")",
"{",
"return",
"null",
"}",
"return",
"(",
"<",
"ul",
">",
"\n ",
"{",
"toc",
".",
"map",
"(",
"function",
"(",
"item",
",",
"index",
")",
"{",
"const",
"href",
"=",
"`",
"${",
"path",
"}",
"${",
"item",
".",
"id",
"}",
"`",
"return",
"(",
"<",
"li",
"key",
"=",
"{",
"index",
"}",
">",
"\n ",
"{",
"item",
".",
"children",
".",
"length",
">",
"0",
"&&",
"(",
"<",
"input",
"id",
"=",
"{",
"href",
"}",
"className",
"=",
"\"nav_toggle\"",
"type",
"=",
"\"checkbox\"",
"defaultChecked",
"=",
"{",
"false",
"}",
"/",
">",
")",
"}",
"\n ",
"<",
"a",
"className",
"=",
"{",
"`",
"${",
"item",
".",
"children",
".",
"length",
"?",
"''",
":",
"'nav_childless'",
"}",
"`",
"}",
"href",
"=",
"{",
"href",
"}",
">",
"\n ",
"{",
"item",
".",
"title",
"}",
"\n ",
"<",
"/",
"a",
">",
"\n ",
"<",
"Headings",
"toc",
"=",
"{",
"item",
".",
"children",
"}",
"path",
"=",
"{",
"path",
"}",
"/",
">",
"\n ",
"<",
"/",
"li",
">",
")",
"}",
")",
"}",
"\n ",
"<",
"/",
"ul",
">",
")",
"}"
] |
To understand how navigation is composed, start from the bottom
|
[
"To",
"understand",
"how",
"navigation",
"is",
"composed",
"start",
"from",
"the",
"bottom"
] |
a5f1f5e584cbf570ace94347254e5e42b336156b
|
https://github.com/cerebral/cerebral/blob/a5f1f5e584cbf570ace94347254e5e42b336156b/packages/website/builder/pages/docs/nav.js#L6-L38
|
13,274
|
feross/spoof
|
index.js
|
findInterfaces
|
function findInterfaces (targets) {
if (!targets) targets = []
targets = targets.map(target => target.toLowerCase())
if (process.platform === 'darwin') {
return findInterfacesDarwin(targets)
} else if (process.platform === 'linux') {
return findInterfacesLinux(targets)
} else if (process.platform === 'win32') {
return findInterfacesWin32(targets)
}
}
|
javascript
|
function findInterfaces (targets) {
if (!targets) targets = []
targets = targets.map(target => target.toLowerCase())
if (process.platform === 'darwin') {
return findInterfacesDarwin(targets)
} else if (process.platform === 'linux') {
return findInterfacesLinux(targets)
} else if (process.platform === 'win32') {
return findInterfacesWin32(targets)
}
}
|
[
"function",
"findInterfaces",
"(",
"targets",
")",
"{",
"if",
"(",
"!",
"targets",
")",
"targets",
"=",
"[",
"]",
"targets",
"=",
"targets",
".",
"map",
"(",
"target",
"=>",
"target",
".",
"toLowerCase",
"(",
")",
")",
"if",
"(",
"process",
".",
"platform",
"===",
"'darwin'",
")",
"{",
"return",
"findInterfacesDarwin",
"(",
"targets",
")",
"}",
"else",
"if",
"(",
"process",
".",
"platform",
"===",
"'linux'",
")",
"{",
"return",
"findInterfacesLinux",
"(",
"targets",
")",
"}",
"else",
"if",
"(",
"process",
".",
"platform",
"===",
"'win32'",
")",
"{",
"return",
"findInterfacesWin32",
"(",
"targets",
")",
"}",
"}"
] |
Returns the list of interfaces found on this machine as reported by the
`networksetup` command.
@param {Array.<string>|null} targets
@return {Array.<Object>)}
|
[
"Returns",
"the",
"list",
"of",
"interfaces",
"found",
"on",
"this",
"machine",
"as",
"reported",
"by",
"the",
"networksetup",
"command",
"."
] |
4ccb8f916b348ed761bc69777902e5c8957ff1fe
|
https://github.com/feross/spoof/blob/4ccb8f916b348ed761bc69777902e5c8957ff1fe/index.js#L34-L46
|
13,275
|
feross/spoof
|
index.js
|
getInterfaceMAC
|
function getInterfaceMAC (device) {
if (process.platform === 'darwin' || process.platform === 'linux') {
let output
try {
output = cp.execSync(quote(['ifconfig', device]), { stdio: 'pipe' }).toString()
} catch (err) {
return null
}
const address = MAC_ADDRESS_RE.exec(output)
return address && normalize(address[0])
} else if (process.platform === 'win32') {
console.error('No windows support for this method yet - PR welcome!')
}
}
|
javascript
|
function getInterfaceMAC (device) {
if (process.platform === 'darwin' || process.platform === 'linux') {
let output
try {
output = cp.execSync(quote(['ifconfig', device]), { stdio: 'pipe' }).toString()
} catch (err) {
return null
}
const address = MAC_ADDRESS_RE.exec(output)
return address && normalize(address[0])
} else if (process.platform === 'win32') {
console.error('No windows support for this method yet - PR welcome!')
}
}
|
[
"function",
"getInterfaceMAC",
"(",
"device",
")",
"{",
"if",
"(",
"process",
".",
"platform",
"===",
"'darwin'",
"||",
"process",
".",
"platform",
"===",
"'linux'",
")",
"{",
"let",
"output",
"try",
"{",
"output",
"=",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'ifconfig'",
",",
"device",
"]",
")",
",",
"{",
"stdio",
":",
"'pipe'",
"}",
")",
".",
"toString",
"(",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"null",
"}",
"const",
"address",
"=",
"MAC_ADDRESS_RE",
".",
"exec",
"(",
"output",
")",
"return",
"address",
"&&",
"normalize",
"(",
"address",
"[",
"0",
"]",
")",
"}",
"else",
"if",
"(",
"process",
".",
"platform",
"===",
"'win32'",
")",
"{",
"console",
".",
"error",
"(",
"'No windows support for this method yet - PR welcome!'",
")",
"}",
"}"
] |
Returns currently-set MAC address of given interface. This is distinct from the
interface's hardware MAC address.
@return {string}
|
[
"Returns",
"currently",
"-",
"set",
"MAC",
"address",
"of",
"given",
"interface",
".",
"This",
"is",
"distinct",
"from",
"the",
"interface",
"s",
"hardware",
"MAC",
"address",
"."
] |
4ccb8f916b348ed761bc69777902e5c8957ff1fe
|
https://github.com/feross/spoof/blob/4ccb8f916b348ed761bc69777902e5c8957ff1fe/index.js#L253-L267
|
13,276
|
feross/spoof
|
index.js
|
setInterfaceMAC
|
function setInterfaceMAC (device, mac, port) {
if (!MAC_ADDRESS_RE.exec(mac)) {
throw new Error(mac + ' is not a valid MAC address')
}
const isWirelessPort = port && port.toLowerCase() === 'wi-fi'
if (process.platform === 'darwin') {
if (isWirelessPort) {
// Turn on the device, assuming it's an airport device.
try {
cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
} catch (err) {
throw new Error('Unable to power on wifi device')
}
}
// For some reason this seems to be required even when changing a non-airport device.
try {
cp.execSync(quote([PATH_TO_AIRPORT, '-z']))
} catch (err) {
throw new Error('Unable to disassociate from wifi networks')
}
// Change the MAC.
try {
cp.execSync(quote(['ifconfig', device, 'ether', mac]))
} catch (err) {
throw new Error('Unable to change MAC address')
}
// Restart airport so it will associate with known networks (if any)
if (isWirelessPort) {
try {
cp.execSync(quote(['networksetup', '-setairportpower', device, 'off']))
cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
} catch (err) {
throw new Error('Unable to set restart wifi device')
}
}
} else if (process.platform === 'linux') {
// Set the device's mac address.
// Handles shutting down and starting back up interface.
try {
cp.execSync(quote(['ifconfig', device, 'down', 'hw', 'ether', mac]))
cp.execSync(quote(['ifconfig', device, 'up']))
} catch (err) {
throw new Error('Unable to change MAC address')
}
} else if (process.platform === 'win32') {
// Locate adapter's registry and update network address (mac)
const regKey = new Winreg({
hive: Winreg.HKLM,
key: WIN_REGISTRY_PATH
})
regKey.keys((err, keys) => {
if (err) {
console.log('ERROR: ' + err)
} else {
// Loop over all available keys and find the right adapter
for (let i = 0; i < keys.length; i++) {
tryWindowsKey(keys[i].key, device, mac)
}
}
})
}
}
|
javascript
|
function setInterfaceMAC (device, mac, port) {
if (!MAC_ADDRESS_RE.exec(mac)) {
throw new Error(mac + ' is not a valid MAC address')
}
const isWirelessPort = port && port.toLowerCase() === 'wi-fi'
if (process.platform === 'darwin') {
if (isWirelessPort) {
// Turn on the device, assuming it's an airport device.
try {
cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
} catch (err) {
throw new Error('Unable to power on wifi device')
}
}
// For some reason this seems to be required even when changing a non-airport device.
try {
cp.execSync(quote([PATH_TO_AIRPORT, '-z']))
} catch (err) {
throw new Error('Unable to disassociate from wifi networks')
}
// Change the MAC.
try {
cp.execSync(quote(['ifconfig', device, 'ether', mac]))
} catch (err) {
throw new Error('Unable to change MAC address')
}
// Restart airport so it will associate with known networks (if any)
if (isWirelessPort) {
try {
cp.execSync(quote(['networksetup', '-setairportpower', device, 'off']))
cp.execSync(quote(['networksetup', '-setairportpower', device, 'on']))
} catch (err) {
throw new Error('Unable to set restart wifi device')
}
}
} else if (process.platform === 'linux') {
// Set the device's mac address.
// Handles shutting down and starting back up interface.
try {
cp.execSync(quote(['ifconfig', device, 'down', 'hw', 'ether', mac]))
cp.execSync(quote(['ifconfig', device, 'up']))
} catch (err) {
throw new Error('Unable to change MAC address')
}
} else if (process.platform === 'win32') {
// Locate adapter's registry and update network address (mac)
const regKey = new Winreg({
hive: Winreg.HKLM,
key: WIN_REGISTRY_PATH
})
regKey.keys((err, keys) => {
if (err) {
console.log('ERROR: ' + err)
} else {
// Loop over all available keys and find the right adapter
for (let i = 0; i < keys.length; i++) {
tryWindowsKey(keys[i].key, device, mac)
}
}
})
}
}
|
[
"function",
"setInterfaceMAC",
"(",
"device",
",",
"mac",
",",
"port",
")",
"{",
"if",
"(",
"!",
"MAC_ADDRESS_RE",
".",
"exec",
"(",
"mac",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"mac",
"+",
"' is not a valid MAC address'",
")",
"}",
"const",
"isWirelessPort",
"=",
"port",
"&&",
"port",
".",
"toLowerCase",
"(",
")",
"===",
"'wi-fi'",
"if",
"(",
"process",
".",
"platform",
"===",
"'darwin'",
")",
"{",
"if",
"(",
"isWirelessPort",
")",
"{",
"// Turn on the device, assuming it's an airport device.",
"try",
"{",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'networksetup'",
",",
"'-setairportpower'",
",",
"device",
",",
"'on'",
"]",
")",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to power on wifi device'",
")",
"}",
"}",
"// For some reason this seems to be required even when changing a non-airport device.",
"try",
"{",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"PATH_TO_AIRPORT",
",",
"'-z'",
"]",
")",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to disassociate from wifi networks'",
")",
"}",
"// Change the MAC.",
"try",
"{",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'ifconfig'",
",",
"device",
",",
"'ether'",
",",
"mac",
"]",
")",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to change MAC address'",
")",
"}",
"// Restart airport so it will associate with known networks (if any)",
"if",
"(",
"isWirelessPort",
")",
"{",
"try",
"{",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'networksetup'",
",",
"'-setairportpower'",
",",
"device",
",",
"'off'",
"]",
")",
")",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'networksetup'",
",",
"'-setairportpower'",
",",
"device",
",",
"'on'",
"]",
")",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to set restart wifi device'",
")",
"}",
"}",
"}",
"else",
"if",
"(",
"process",
".",
"platform",
"===",
"'linux'",
")",
"{",
"// Set the device's mac address.",
"// Handles shutting down and starting back up interface.",
"try",
"{",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'ifconfig'",
",",
"device",
",",
"'down'",
",",
"'hw'",
",",
"'ether'",
",",
"mac",
"]",
")",
")",
"cp",
".",
"execSync",
"(",
"quote",
"(",
"[",
"'ifconfig'",
",",
"device",
",",
"'up'",
"]",
")",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to change MAC address'",
")",
"}",
"}",
"else",
"if",
"(",
"process",
".",
"platform",
"===",
"'win32'",
")",
"{",
"// Locate adapter's registry and update network address (mac)",
"const",
"regKey",
"=",
"new",
"Winreg",
"(",
"{",
"hive",
":",
"Winreg",
".",
"HKLM",
",",
"key",
":",
"WIN_REGISTRY_PATH",
"}",
")",
"regKey",
".",
"keys",
"(",
"(",
"err",
",",
"keys",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: '",
"+",
"err",
")",
"}",
"else",
"{",
"// Loop over all available keys and find the right adapter",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"tryWindowsKey",
"(",
"keys",
"[",
"i",
"]",
".",
"key",
",",
"device",
",",
"mac",
")",
"}",
"}",
"}",
")",
"}",
"}"
] |
Sets the mac address for given `device` to `mac`.
Device varies by platform:
OS X, Linux: this is the interface name in ifconfig
Windows: this is the network adapter name in ipconfig
@param {string} device
@param {string} mac
@param {string=} port
|
[
"Sets",
"the",
"mac",
"address",
"for",
"given",
"device",
"to",
"mac",
"."
] |
4ccb8f916b348ed761bc69777902e5c8957ff1fe
|
https://github.com/feross/spoof/blob/4ccb8f916b348ed761bc69777902e5c8957ff1fe/index.js#L280-L347
|
13,277
|
feross/spoof
|
index.js
|
tryWindowsKey
|
function tryWindowsKey (key, device, mac) {
// Skip the Properties key to avoid problems with permissions
if (key.indexOf('Properties') > -1) {
return false
}
const networkAdapterKeyPath = new Winreg({
hive: Winreg.HKLM,
key: key
})
// we need to format the MAC a bit for Windows
mac = mac.replace(/:/g, '')
networkAdapterKeyPath.values((err, values) => {
let gotAdapter = false
if (err) {
console.log('ERROR: ' + err)
} else {
for (let x = 0; x < values.length; x++) {
if (values[x].name === 'AdapterModel') {
gotAdapter = true
break
}
}
if (gotAdapter) {
networkAdapterKeyPath.set('NetworkAddress', 'REG_SZ', mac, () => {
try {
cp.execSync('netsh interface set interface "' + device + '" disable')
cp.execSync('netsh interface set interface "' + device + '" enable')
} catch (err) {
throw new Error('Unable to restart device, is the cmd running as admin?')
}
})
}
}
})
}
|
javascript
|
function tryWindowsKey (key, device, mac) {
// Skip the Properties key to avoid problems with permissions
if (key.indexOf('Properties') > -1) {
return false
}
const networkAdapterKeyPath = new Winreg({
hive: Winreg.HKLM,
key: key
})
// we need to format the MAC a bit for Windows
mac = mac.replace(/:/g, '')
networkAdapterKeyPath.values((err, values) => {
let gotAdapter = false
if (err) {
console.log('ERROR: ' + err)
} else {
for (let x = 0; x < values.length; x++) {
if (values[x].name === 'AdapterModel') {
gotAdapter = true
break
}
}
if (gotAdapter) {
networkAdapterKeyPath.set('NetworkAddress', 'REG_SZ', mac, () => {
try {
cp.execSync('netsh interface set interface "' + device + '" disable')
cp.execSync('netsh interface set interface "' + device + '" enable')
} catch (err) {
throw new Error('Unable to restart device, is the cmd running as admin?')
}
})
}
}
})
}
|
[
"function",
"tryWindowsKey",
"(",
"key",
",",
"device",
",",
"mac",
")",
"{",
"// Skip the Properties key to avoid problems with permissions",
"if",
"(",
"key",
".",
"indexOf",
"(",
"'Properties'",
")",
">",
"-",
"1",
")",
"{",
"return",
"false",
"}",
"const",
"networkAdapterKeyPath",
"=",
"new",
"Winreg",
"(",
"{",
"hive",
":",
"Winreg",
".",
"HKLM",
",",
"key",
":",
"key",
"}",
")",
"// we need to format the MAC a bit for Windows",
"mac",
"=",
"mac",
".",
"replace",
"(",
"/",
":",
"/",
"g",
",",
"''",
")",
"networkAdapterKeyPath",
".",
"values",
"(",
"(",
"err",
",",
"values",
")",
"=>",
"{",
"let",
"gotAdapter",
"=",
"false",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"'ERROR: '",
"+",
"err",
")",
"}",
"else",
"{",
"for",
"(",
"let",
"x",
"=",
"0",
";",
"x",
"<",
"values",
".",
"length",
";",
"x",
"++",
")",
"{",
"if",
"(",
"values",
"[",
"x",
"]",
".",
"name",
"===",
"'AdapterModel'",
")",
"{",
"gotAdapter",
"=",
"true",
"break",
"}",
"}",
"if",
"(",
"gotAdapter",
")",
"{",
"networkAdapterKeyPath",
".",
"set",
"(",
"'NetworkAddress'",
",",
"'REG_SZ'",
",",
"mac",
",",
"(",
")",
"=>",
"{",
"try",
"{",
"cp",
".",
"execSync",
"(",
"'netsh interface set interface \"'",
"+",
"device",
"+",
"'\" disable'",
")",
"cp",
".",
"execSync",
"(",
"'netsh interface set interface \"'",
"+",
"device",
"+",
"'\" enable'",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to restart device, is the cmd running as admin?'",
")",
"}",
"}",
")",
"}",
"}",
"}",
")",
"}"
] |
Tries to set the "NetworkAddress" value on the specified registry key for given
`device` to `mac`.
@param {string} key
@param {string} device
@param {string} mac
|
[
"Tries",
"to",
"set",
"the",
"NetworkAddress",
"value",
"on",
"the",
"specified",
"registry",
"key",
"for",
"given",
"device",
"to",
"mac",
"."
] |
4ccb8f916b348ed761bc69777902e5c8957ff1fe
|
https://github.com/feross/spoof/blob/4ccb8f916b348ed761bc69777902e5c8957ff1fe/index.js#L357-L395
|
13,278
|
feross/spoof
|
index.js
|
randomize
|
function randomize (localAdmin) {
// Randomly assign a VM vendor's MAC address prefix, which should
// decrease chance of colliding with existing device's addresses.
const vendors = [
[ 0x00, 0x05, 0x69 ], // VMware
[ 0x00, 0x50, 0x56 ], // VMware
[ 0x00, 0x0C, 0x29 ], // VMware
[ 0x00, 0x16, 0x3E ], // Xen
[ 0x00, 0x03, 0xFF ], // Microsoft Hyper-V, Virtual Server, Virtual PC
[ 0x00, 0x1C, 0x42 ], // Parallels
[ 0x00, 0x0F, 0x4B ], // Virtual Iron 4
[ 0x08, 0x00, 0x27 ] // Sun Virtual Box
]
// Windows needs specific prefixes sometimes
// http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows
const windowsPrefixes = [
'D2',
'D6',
'DA',
'DE'
]
const vendor = vendors[random(0, vendors.length - 1)]
if (process.platform === 'win32') {
vendor[0] = windowsPrefixes[random(0, 3)]
}
const mac = [
vendor[0],
vendor[1],
vendor[2],
random(0x00, 0x7f),
random(0x00, 0xff),
random(0x00, 0xff)
]
if (localAdmin) {
// Universally administered and locally administered addresses are
// distinguished by setting the second least significant bit of the
// most significant byte of the address. If the bit is 0, the address
// is universally administered. If it is 1, the address is locally
// administered. In the example address 02-00-00-00-00-01 the most
// significant byte is 02h. The binary is 00000010 and the second
// least significant bit is 1. Therefore, it is a locally administered
// address.[3] The bit is 0 in all OUIs.
mac[0] |= 2
}
return mac
.map(byte => zeroFill(2, byte.toString(16)))
.join(':')
.toUpperCase()
}
|
javascript
|
function randomize (localAdmin) {
// Randomly assign a VM vendor's MAC address prefix, which should
// decrease chance of colliding with existing device's addresses.
const vendors = [
[ 0x00, 0x05, 0x69 ], // VMware
[ 0x00, 0x50, 0x56 ], // VMware
[ 0x00, 0x0C, 0x29 ], // VMware
[ 0x00, 0x16, 0x3E ], // Xen
[ 0x00, 0x03, 0xFF ], // Microsoft Hyper-V, Virtual Server, Virtual PC
[ 0x00, 0x1C, 0x42 ], // Parallels
[ 0x00, 0x0F, 0x4B ], // Virtual Iron 4
[ 0x08, 0x00, 0x27 ] // Sun Virtual Box
]
// Windows needs specific prefixes sometimes
// http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows
const windowsPrefixes = [
'D2',
'D6',
'DA',
'DE'
]
const vendor = vendors[random(0, vendors.length - 1)]
if (process.platform === 'win32') {
vendor[0] = windowsPrefixes[random(0, 3)]
}
const mac = [
vendor[0],
vendor[1],
vendor[2],
random(0x00, 0x7f),
random(0x00, 0xff),
random(0x00, 0xff)
]
if (localAdmin) {
// Universally administered and locally administered addresses are
// distinguished by setting the second least significant bit of the
// most significant byte of the address. If the bit is 0, the address
// is universally administered. If it is 1, the address is locally
// administered. In the example address 02-00-00-00-00-01 the most
// significant byte is 02h. The binary is 00000010 and the second
// least significant bit is 1. Therefore, it is a locally administered
// address.[3] The bit is 0 in all OUIs.
mac[0] |= 2
}
return mac
.map(byte => zeroFill(2, byte.toString(16)))
.join(':')
.toUpperCase()
}
|
[
"function",
"randomize",
"(",
"localAdmin",
")",
"{",
"// Randomly assign a VM vendor's MAC address prefix, which should",
"// decrease chance of colliding with existing device's addresses.",
"const",
"vendors",
"=",
"[",
"[",
"0x00",
",",
"0x05",
",",
"0x69",
"]",
",",
"// VMware",
"[",
"0x00",
",",
"0x50",
",",
"0x56",
"]",
",",
"// VMware",
"[",
"0x00",
",",
"0x0C",
",",
"0x29",
"]",
",",
"// VMware",
"[",
"0x00",
",",
"0x16",
",",
"0x3E",
"]",
",",
"// Xen",
"[",
"0x00",
",",
"0x03",
",",
"0xFF",
"]",
",",
"// Microsoft Hyper-V, Virtual Server, Virtual PC",
"[",
"0x00",
",",
"0x1C",
",",
"0x42",
"]",
",",
"// Parallels",
"[",
"0x00",
",",
"0x0F",
",",
"0x4B",
"]",
",",
"// Virtual Iron 4",
"[",
"0x08",
",",
"0x00",
",",
"0x27",
"]",
"// Sun Virtual Box",
"]",
"// Windows needs specific prefixes sometimes",
"// http://www.wikihow.com/Change-a-Computer's-Mac-Address-in-Windows",
"const",
"windowsPrefixes",
"=",
"[",
"'D2'",
",",
"'D6'",
",",
"'DA'",
",",
"'DE'",
"]",
"const",
"vendor",
"=",
"vendors",
"[",
"random",
"(",
"0",
",",
"vendors",
".",
"length",
"-",
"1",
")",
"]",
"if",
"(",
"process",
".",
"platform",
"===",
"'win32'",
")",
"{",
"vendor",
"[",
"0",
"]",
"=",
"windowsPrefixes",
"[",
"random",
"(",
"0",
",",
"3",
")",
"]",
"}",
"const",
"mac",
"=",
"[",
"vendor",
"[",
"0",
"]",
",",
"vendor",
"[",
"1",
"]",
",",
"vendor",
"[",
"2",
"]",
",",
"random",
"(",
"0x00",
",",
"0x7f",
")",
",",
"random",
"(",
"0x00",
",",
"0xff",
")",
",",
"random",
"(",
"0x00",
",",
"0xff",
")",
"]",
"if",
"(",
"localAdmin",
")",
"{",
"// Universally administered and locally administered addresses are",
"// distinguished by setting the second least significant bit of the",
"// most significant byte of the address. If the bit is 0, the address",
"// is universally administered. If it is 1, the address is locally",
"// administered. In the example address 02-00-00-00-00-01 the most",
"// significant byte is 02h. The binary is 00000010 and the second",
"// least significant bit is 1. Therefore, it is a locally administered",
"// address.[3] The bit is 0 in all OUIs.",
"mac",
"[",
"0",
"]",
"|=",
"2",
"}",
"return",
"mac",
".",
"map",
"(",
"byte",
"=>",
"zeroFill",
"(",
"2",
",",
"byte",
".",
"toString",
"(",
"16",
")",
")",
")",
".",
"join",
"(",
"':'",
")",
".",
"toUpperCase",
"(",
")",
"}"
] |
Generates and returns a random MAC address.
@param {boolean} localAdmin locally administered address
@return {string}
|
[
"Generates",
"and",
"returns",
"a",
"random",
"MAC",
"address",
"."
] |
4ccb8f916b348ed761bc69777902e5c8957ff1fe
|
https://github.com/feross/spoof/blob/4ccb8f916b348ed761bc69777902e5c8957ff1fe/index.js#L402-L457
|
13,279
|
Workshape/icon-font-generator
|
lib/utils.js
|
logOutput
|
function logOutput(options, parts) {
const msg = `${ 'Generated '.blue }${ path.resolve.apply(path, parts).cyan }`
log(options, msg)
}
|
javascript
|
function logOutput(options, parts) {
const msg = `${ 'Generated '.blue }${ path.resolve.apply(path, parts).cyan }`
log(options, msg)
}
|
[
"function",
"logOutput",
"(",
"options",
",",
"parts",
")",
"{",
"const",
"msg",
"=",
"`",
"${",
"'Generated '",
".",
"blue",
"}",
"${",
"path",
".",
"resolve",
".",
"apply",
"(",
"path",
",",
"parts",
")",
".",
"cyan",
"}",
"`",
"log",
"(",
"options",
",",
"msg",
")",
"}"
] |
Log output file generation
@param {Object} options
@param {[String]} parts
@return {void}
|
[
"Log",
"output",
"file",
"generation"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/utils.js#L26-L29
|
13,280
|
Workshape/icon-font-generator
|
lib/index.js
|
generate
|
async function generate(options = {}) {
options = Object.assign(DEFAULT_OPTIONS, options)
// Log start
let msg = `Generating font kit from ${ options.paths.length } SVG icons`.yellow
log(options, msg)
// Run validation over options
await validateOptions(options)
if (options.codepoints) {
options.codepointsMap = await getCodepointsMap(options.codepoints)
}
// Run font generation
const config = getGeneratorConfig(options)
const generatorResult = await fontGenerator(config)
// Clean up after generator
await deleteUnspecifiedTypes(options)
// If specified, generate JSON map
if (options.json) {
await generateJson(options, generatorResult)
}
// Log generated files
logReport(options)
}
|
javascript
|
async function generate(options = {}) {
options = Object.assign(DEFAULT_OPTIONS, options)
// Log start
let msg = `Generating font kit from ${ options.paths.length } SVG icons`.yellow
log(options, msg)
// Run validation over options
await validateOptions(options)
if (options.codepoints) {
options.codepointsMap = await getCodepointsMap(options.codepoints)
}
// Run font generation
const config = getGeneratorConfig(options)
const generatorResult = await fontGenerator(config)
// Clean up after generator
await deleteUnspecifiedTypes(options)
// If specified, generate JSON map
if (options.json) {
await generateJson(options, generatorResult)
}
// Log generated files
logReport(options)
}
|
[
"async",
"function",
"generate",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"options",
"=",
"Object",
".",
"assign",
"(",
"DEFAULT_OPTIONS",
",",
"options",
")",
"// Log start",
"let",
"msg",
"=",
"`",
"${",
"options",
".",
"paths",
".",
"length",
"}",
"`",
".",
"yellow",
"log",
"(",
"options",
",",
"msg",
")",
"// Run validation over options",
"await",
"validateOptions",
"(",
"options",
")",
"if",
"(",
"options",
".",
"codepoints",
")",
"{",
"options",
".",
"codepointsMap",
"=",
"await",
"getCodepointsMap",
"(",
"options",
".",
"codepoints",
")",
"}",
"// Run font generation",
"const",
"config",
"=",
"getGeneratorConfig",
"(",
"options",
")",
"const",
"generatorResult",
"=",
"await",
"fontGenerator",
"(",
"config",
")",
"// Clean up after generator",
"await",
"deleteUnspecifiedTypes",
"(",
"options",
")",
"// If specified, generate JSON map",
"if",
"(",
"options",
".",
"json",
")",
"{",
"await",
"generateJson",
"(",
"options",
",",
"generatorResult",
")",
"}",
"// Log generated files",
"logReport",
"(",
"options",
")",
"}"
] |
Generate icon font set asynchronously
@param {Object} options
@param {Function} callback
@return {void}
|
[
"Generate",
"icon",
"font",
"set",
"asynchronously"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L29-L57
|
13,281
|
Workshape/icon-font-generator
|
lib/index.js
|
getGeneratorConfig
|
function getGeneratorConfig(options) {
const { tag, classNames } = parseSelector(options.baseSelector)
const config = {
files : options.paths,
dest : options.outputDir,
types : options.types,
codepoints : options.codepointsMap,
startCodepoint : options.startCodepoint || 0xF101,
cssDest : options.cssPath,
cssFontsUrl : getCssFontsUrl(options),
htmlDest : options.htmlPath,
cssTemplate : options.cssTemplate || TEMPLATES.css,
htmlTemplate : options.htmlTemplate || TEMPLATES.html,
templateOptions : {
baseTag : tag || options.baseTag || 'i',
baseSelector : options.baseSelector || null,
baseClassNames : classNames.join(' '),
classPrefix : (options.classPrefix || 'icon') + '-',
htmlCssRelativePath : path.relative(
path.dirname(getResolvedPath(options, 'html')),
getResolvedPath(options, 'css')
)
}
}
// Normalise and add available optional configurations
OPTIONAL_PARAMS.forEach(key => {
if (typeof options[key] !== 'undefined') {
// Parse numeric values
if (`${ parseFloat(options[key]) }` === `${ options[key] }`) {
options[key] = parseFloat(options[key])
}
config[key] = options[key]
}
})
return config
}
|
javascript
|
function getGeneratorConfig(options) {
const { tag, classNames } = parseSelector(options.baseSelector)
const config = {
files : options.paths,
dest : options.outputDir,
types : options.types,
codepoints : options.codepointsMap,
startCodepoint : options.startCodepoint || 0xF101,
cssDest : options.cssPath,
cssFontsUrl : getCssFontsUrl(options),
htmlDest : options.htmlPath,
cssTemplate : options.cssTemplate || TEMPLATES.css,
htmlTemplate : options.htmlTemplate || TEMPLATES.html,
templateOptions : {
baseTag : tag || options.baseTag || 'i',
baseSelector : options.baseSelector || null,
baseClassNames : classNames.join(' '),
classPrefix : (options.classPrefix || 'icon') + '-',
htmlCssRelativePath : path.relative(
path.dirname(getResolvedPath(options, 'html')),
getResolvedPath(options, 'css')
)
}
}
// Normalise and add available optional configurations
OPTIONAL_PARAMS.forEach(key => {
if (typeof options[key] !== 'undefined') {
// Parse numeric values
if (`${ parseFloat(options[key]) }` === `${ options[key] }`) {
options[key] = parseFloat(options[key])
}
config[key] = options[key]
}
})
return config
}
|
[
"function",
"getGeneratorConfig",
"(",
"options",
")",
"{",
"const",
"{",
"tag",
",",
"classNames",
"}",
"=",
"parseSelector",
"(",
"options",
".",
"baseSelector",
")",
"const",
"config",
"=",
"{",
"files",
":",
"options",
".",
"paths",
",",
"dest",
":",
"options",
".",
"outputDir",
",",
"types",
":",
"options",
".",
"types",
",",
"codepoints",
":",
"options",
".",
"codepointsMap",
",",
"startCodepoint",
":",
"options",
".",
"startCodepoint",
"||",
"0xF101",
",",
"cssDest",
":",
"options",
".",
"cssPath",
",",
"cssFontsUrl",
":",
"getCssFontsUrl",
"(",
"options",
")",
",",
"htmlDest",
":",
"options",
".",
"htmlPath",
",",
"cssTemplate",
":",
"options",
".",
"cssTemplate",
"||",
"TEMPLATES",
".",
"css",
",",
"htmlTemplate",
":",
"options",
".",
"htmlTemplate",
"||",
"TEMPLATES",
".",
"html",
",",
"templateOptions",
":",
"{",
"baseTag",
":",
"tag",
"||",
"options",
".",
"baseTag",
"||",
"'i'",
",",
"baseSelector",
":",
"options",
".",
"baseSelector",
"||",
"null",
",",
"baseClassNames",
":",
"classNames",
".",
"join",
"(",
"' '",
")",
",",
"classPrefix",
":",
"(",
"options",
".",
"classPrefix",
"||",
"'icon'",
")",
"+",
"'-'",
",",
"htmlCssRelativePath",
":",
"path",
".",
"relative",
"(",
"path",
".",
"dirname",
"(",
"getResolvedPath",
"(",
"options",
",",
"'html'",
")",
")",
",",
"getResolvedPath",
"(",
"options",
",",
"'css'",
")",
")",
"}",
"}",
"// Normalise and add available optional configurations",
"OPTIONAL_PARAMS",
".",
"forEach",
"(",
"key",
"=>",
"{",
"if",
"(",
"typeof",
"options",
"[",
"key",
"]",
"!==",
"'undefined'",
")",
"{",
"// Parse numeric values",
"if",
"(",
"`",
"${",
"parseFloat",
"(",
"options",
"[",
"key",
"]",
")",
"}",
"`",
"===",
"`",
"${",
"options",
"[",
"key",
"]",
"}",
"`",
")",
"{",
"options",
"[",
"key",
"]",
"=",
"parseFloat",
"(",
"options",
"[",
"key",
"]",
")",
"}",
"config",
"[",
"key",
"]",
"=",
"options",
"[",
"key",
"]",
"}",
"}",
")",
"return",
"config",
"}"
] |
Transform options Object in a configuration accepted by the generator
@param {Object} options
@return {void}
|
[
"Transform",
"options",
"Object",
"in",
"a",
"configuration",
"accepted",
"by",
"the",
"generator"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L65-L103
|
13,282
|
Workshape/icon-font-generator
|
lib/index.js
|
parseSelector
|
function parseSelector(selector = '') {
const tagMatch = selector.match(/^[a-zA-Z0-9='"[\]_-]*/g)
const classNamesMatch = selector.match(/\.[a-zA-Z0-1_-]*/g)
return {
tag: tagMatch ? tagMatch[0] : undefined,
classNames: classNamesMatch ? classNamesMatch.map(cname => cname.substr(1)) : []
}
}
|
javascript
|
function parseSelector(selector = '') {
const tagMatch = selector.match(/^[a-zA-Z0-9='"[\]_-]*/g)
const classNamesMatch = selector.match(/\.[a-zA-Z0-1_-]*/g)
return {
tag: tagMatch ? tagMatch[0] : undefined,
classNames: classNamesMatch ? classNamesMatch.map(cname => cname.substr(1)) : []
}
}
|
[
"function",
"parseSelector",
"(",
"selector",
"=",
"''",
")",
"{",
"const",
"tagMatch",
"=",
"selector",
".",
"match",
"(",
"/",
"^[a-zA-Z0-9='\"[\\]_-]*",
"/",
"g",
")",
"const",
"classNamesMatch",
"=",
"selector",
".",
"match",
"(",
"/",
"\\.[a-zA-Z0-1_-]*",
"/",
"g",
")",
"return",
"{",
"tag",
":",
"tagMatch",
"?",
"tagMatch",
"[",
"0",
"]",
":",
"undefined",
",",
"classNames",
":",
"classNamesMatch",
"?",
"classNamesMatch",
".",
"map",
"(",
"cname",
"=>",
"cname",
".",
"substr",
"(",
"1",
")",
")",
":",
"[",
"]",
"}",
"}"
] |
Parse tag and classNames from given selector, if any are specified
@param {?String} selector
@return {Object}
|
[
"Parse",
"tag",
"and",
"classNames",
"from",
"given",
"selector",
"if",
"any",
"are",
"specified"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L111-L119
|
13,283
|
Workshape/icon-font-generator
|
lib/index.js
|
getCssFontsUrl
|
function getCssFontsUrl(options) {
if (options.cssFontsUrl) {
return options.cssFontsUrl
} if (options.cssPath) {
return path.relative(path.dirname(options.cssPath), options.outputDir)
}
return './'
}
|
javascript
|
function getCssFontsUrl(options) {
if (options.cssFontsUrl) {
return options.cssFontsUrl
} if (options.cssPath) {
return path.relative(path.dirname(options.cssPath), options.outputDir)
}
return './'
}
|
[
"function",
"getCssFontsUrl",
"(",
"options",
")",
"{",
"if",
"(",
"options",
".",
"cssFontsUrl",
")",
"{",
"return",
"options",
".",
"cssFontsUrl",
"}",
"if",
"(",
"options",
".",
"cssPath",
")",
"{",
"return",
"path",
".",
"relative",
"(",
"path",
".",
"dirname",
"(",
"options",
".",
"cssPath",
")",
",",
"options",
".",
"outputDir",
")",
"}",
"return",
"'./'",
"}"
] |
Based on given options, compute value that should be used as a base URL for font files from the generated CSS
If a `cssFontsUrl` option is explicitally provided, it overrides default behaviour
Else if the CSS was output at a custom filepath, compute a relative path from there
Just return './' otherwise
@param {Object} options
@return {void}
|
[
"Based",
"on",
"given",
"options",
"compute",
"value",
"that",
"should",
"be",
"used",
"as",
"a",
"base",
"URL",
"for",
"font",
"files",
"from",
"the",
"generated",
"CSS"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L133-L141
|
13,284
|
Workshape/icon-font-generator
|
lib/index.js
|
getCodepointsMap
|
async function getCodepointsMap(filepath) {
const content = await fsAsync.readFile(filepath)
let codepointsMap
try {
codepointsMap = JSON.parse(content)
} catch (e) {
throw new ValidationError('Codepoints map is invalid JSON')
}
for (let propName in codepointsMap) {
codepointsMap[propName] = Number.parseInt(codepointsMap[propName])
}
return codepointsMap
}
|
javascript
|
async function getCodepointsMap(filepath) {
const content = await fsAsync.readFile(filepath)
let codepointsMap
try {
codepointsMap = JSON.parse(content)
} catch (e) {
throw new ValidationError('Codepoints map is invalid JSON')
}
for (let propName in codepointsMap) {
codepointsMap[propName] = Number.parseInt(codepointsMap[propName])
}
return codepointsMap
}
|
[
"async",
"function",
"getCodepointsMap",
"(",
"filepath",
")",
"{",
"const",
"content",
"=",
"await",
"fsAsync",
".",
"readFile",
"(",
"filepath",
")",
"let",
"codepointsMap",
"try",
"{",
"codepointsMap",
"=",
"JSON",
".",
"parse",
"(",
"content",
")",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'Codepoints map is invalid JSON'",
")",
"}",
"for",
"(",
"let",
"propName",
"in",
"codepointsMap",
")",
"{",
"codepointsMap",
"[",
"propName",
"]",
"=",
"Number",
".",
"parseInt",
"(",
"codepointsMap",
"[",
"propName",
"]",
")",
"}",
"return",
"codepointsMap",
"}"
] |
Correctly parse codepoints map
@param {Object} options
@return {void}
|
[
"Correctly",
"parse",
"codepoints",
"map"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L149-L164
|
13,285
|
Workshape/icon-font-generator
|
lib/index.js
|
getResolvedPath
|
function getResolvedPath(options, type = 'html') {
const explicitPathKey = `${ type }Path`
if (options[explicitPathKey]) {
return path.resolve(options[explicitPathKey])
}
return path.resolve(options.outputDir, `${ options.fontName }.${ type }`)
}
|
javascript
|
function getResolvedPath(options, type = 'html') {
const explicitPathKey = `${ type }Path`
if (options[explicitPathKey]) {
return path.resolve(options[explicitPathKey])
}
return path.resolve(options.outputDir, `${ options.fontName }.${ type }`)
}
|
[
"function",
"getResolvedPath",
"(",
"options",
",",
"type",
"=",
"'html'",
")",
"{",
"const",
"explicitPathKey",
"=",
"`",
"${",
"type",
"}",
"`",
"if",
"(",
"options",
"[",
"explicitPathKey",
"]",
")",
"{",
"return",
"path",
".",
"resolve",
"(",
"options",
"[",
"explicitPathKey",
"]",
")",
"}",
"return",
"path",
".",
"resolve",
"(",
"options",
".",
"outputDir",
",",
"`",
"${",
"options",
".",
"fontName",
"}",
"${",
"type",
"}",
"`",
")",
"}"
] |
Assume the absolute path at which the file of given type should be written
@param {Object} options
@param {?String} type
@return {void}
|
[
"Assume",
"the",
"absolute",
"path",
"at",
"which",
"the",
"file",
"of",
"given",
"type",
"should",
"be",
"written"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L173-L181
|
13,286
|
Workshape/icon-font-generator
|
lib/index.js
|
logReport
|
function logReport(options) {
const { outputDir, fontName } = options
// Log font files output
for (let ext of options.types) { logOutput(options, [ outputDir, `${ fontName }.${ ext }` ]) }
// Log HTML file output
if (options.html) {
logOutput(options, [ getResolvedPath(options, 'html') ])
}
// Log CSS file output
if (options.css) {
logOutput(options, [ getResolvedPath(options, 'css') ])
}
// Log JSON map output
if (options.json) {
logOutput(options, [ getResolvedPath(options, 'json') ])
}
// Log final message
log(options, 'Done'.green)
}
|
javascript
|
function logReport(options) {
const { outputDir, fontName } = options
// Log font files output
for (let ext of options.types) { logOutput(options, [ outputDir, `${ fontName }.${ ext }` ]) }
// Log HTML file output
if (options.html) {
logOutput(options, [ getResolvedPath(options, 'html') ])
}
// Log CSS file output
if (options.css) {
logOutput(options, [ getResolvedPath(options, 'css') ])
}
// Log JSON map output
if (options.json) {
logOutput(options, [ getResolvedPath(options, 'json') ])
}
// Log final message
log(options, 'Done'.green)
}
|
[
"function",
"logReport",
"(",
"options",
")",
"{",
"const",
"{",
"outputDir",
",",
"fontName",
"}",
"=",
"options",
"// Log font files output",
"for",
"(",
"let",
"ext",
"of",
"options",
".",
"types",
")",
"{",
"logOutput",
"(",
"options",
",",
"[",
"outputDir",
",",
"`",
"${",
"fontName",
"}",
"${",
"ext",
"}",
"`",
"]",
")",
"}",
"// Log HTML file output",
"if",
"(",
"options",
".",
"html",
")",
"{",
"logOutput",
"(",
"options",
",",
"[",
"getResolvedPath",
"(",
"options",
",",
"'html'",
")",
"]",
")",
"}",
"// Log CSS file output",
"if",
"(",
"options",
".",
"css",
")",
"{",
"logOutput",
"(",
"options",
",",
"[",
"getResolvedPath",
"(",
"options",
",",
"'css'",
")",
"]",
")",
"}",
"// Log JSON map output",
"if",
"(",
"options",
".",
"json",
")",
"{",
"logOutput",
"(",
"options",
",",
"[",
"getResolvedPath",
"(",
"options",
",",
"'json'",
")",
"]",
")",
"}",
"// Log final message",
"log",
"(",
"options",
",",
"'Done'",
".",
"green",
")",
"}"
] |
Log report with all generated files and completion message
@param {Object} options
@return {void}
|
[
"Log",
"report",
"with",
"all",
"generated",
"files",
"and",
"completion",
"message"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L189-L212
|
13,287
|
Workshape/icon-font-generator
|
lib/index.js
|
generateJson
|
async function generateJson(options, generatorResult) {
const jsonPath = (
options.jsonPath ||
`${ path.join(options.outputDir, '/' + options.fontName) }.json`
)
const css = generatorResult.generateCss()
let map = {}
css.replace(CSS_PARSE_REGEX, (match, name, code) => map[name] = code)
await fsAsync.writeFile(jsonPath, JSON.stringify(map, null, 4))
}
|
javascript
|
async function generateJson(options, generatorResult) {
const jsonPath = (
options.jsonPath ||
`${ path.join(options.outputDir, '/' + options.fontName) }.json`
)
const css = generatorResult.generateCss()
let map = {}
css.replace(CSS_PARSE_REGEX, (match, name, code) => map[name] = code)
await fsAsync.writeFile(jsonPath, JSON.stringify(map, null, 4))
}
|
[
"async",
"function",
"generateJson",
"(",
"options",
",",
"generatorResult",
")",
"{",
"const",
"jsonPath",
"=",
"(",
"options",
".",
"jsonPath",
"||",
"`",
"${",
"path",
".",
"join",
"(",
"options",
".",
"outputDir",
",",
"'/'",
"+",
"options",
".",
"fontName",
")",
"}",
"`",
")",
"const",
"css",
"=",
"generatorResult",
".",
"generateCss",
"(",
")",
"let",
"map",
"=",
"{",
"}",
"css",
".",
"replace",
"(",
"CSS_PARSE_REGEX",
",",
"(",
"match",
",",
"name",
",",
"code",
")",
"=>",
"map",
"[",
"name",
"]",
"=",
"code",
")",
"await",
"fsAsync",
".",
"writeFile",
"(",
"jsonPath",
",",
"JSON",
".",
"stringify",
"(",
"map",
",",
"null",
",",
"4",
")",
")",
"}"
] |
Generate JSON icons map by parsing the generated CSS
@param {Object} options
@return {void}
|
[
"Generate",
"JSON",
"icons",
"map",
"by",
"parsing",
"the",
"generated",
"CSS"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L220-L232
|
13,288
|
Workshape/icon-font-generator
|
lib/index.js
|
deleteUnspecifiedTypes
|
async function deleteUnspecifiedTypes(options) {
const { outputDir, fontName, types } = options
for (let ext of FONT_TYPES) {
if (types.indexOf(ext) !== -1) { continue }
let filepath = path.resolve(outputDir, `${ fontName }.${ ext }`)
if (await fsAsync.exists(filepath)) {
await fsAsync.unlink(filepath)
}
}
}
|
javascript
|
async function deleteUnspecifiedTypes(options) {
const { outputDir, fontName, types } = options
for (let ext of FONT_TYPES) {
if (types.indexOf(ext) !== -1) { continue }
let filepath = path.resolve(outputDir, `${ fontName }.${ ext }`)
if (await fsAsync.exists(filepath)) {
await fsAsync.unlink(filepath)
}
}
}
|
[
"async",
"function",
"deleteUnspecifiedTypes",
"(",
"options",
")",
"{",
"const",
"{",
"outputDir",
",",
"fontName",
",",
"types",
"}",
"=",
"options",
"for",
"(",
"let",
"ext",
"of",
"FONT_TYPES",
")",
"{",
"if",
"(",
"types",
".",
"indexOf",
"(",
"ext",
")",
"!==",
"-",
"1",
")",
"{",
"continue",
"}",
"let",
"filepath",
"=",
"path",
".",
"resolve",
"(",
"outputDir",
",",
"`",
"${",
"fontName",
"}",
"${",
"ext",
"}",
"`",
")",
"if",
"(",
"await",
"fsAsync",
".",
"exists",
"(",
"filepath",
")",
")",
"{",
"await",
"fsAsync",
".",
"unlink",
"(",
"filepath",
")",
"}",
"}",
"}"
] |
Delete generated fonts with extensions that weren't specified
@param {Object} options
@return {void}
|
[
"Delete",
"generated",
"fonts",
"with",
"extensions",
"that",
"weren",
"t",
"specified"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L240-L252
|
13,289
|
Workshape/icon-font-generator
|
lib/index.js
|
validateOptions
|
async function validateOptions(options) {
// Check that input glob was passed
if (!options.paths.length) {
throw new ValidationError('No paths specified')
}
// Check that output path was passed
if (!options.outputDir) {
throw new ValidationError('Please specify an output directory with -o or --output')
}
// Check that the existance of output path
if (!await fsAsync.exists(options.outputDir)) {
throw new ValidationError('Output directory doesn\'t exist')
}
// Check that output path is a directory
const outStat = await fsAsync.stat(options.outputDir)
if (!outStat.isDirectory()) {
throw new ValidationError('Output path must be a directory')
}
// Check existance of CSS template (If set)
if (options.cssTemplate && !await fsAsync.exists(options.cssTemplate)) {
throw new ValidationError('CSS template not found')
}
// Check existance of HTML template (If set)
if (options.htmlTemplate && !await fsAsync.exists(options.htmlTemplate)) {
throw new ValidationError('HTML template not found')
}
// Validate codepoints file if passed
if (options.codepoints) {
if (!await fsAsync.exists(options.codepoints)) {
throw new ValidationError(`Cannot find json file @ ${options.codepoints}!`)
}
const codepointsStat = await fsAsync.stat(options.codepoints)
if (!codepointsStat.isFile() || path.extname(options.codepoints) !== '.json') {
throw new ValidationError([
'Codepoints file must be JSON',
`${options.codepoints} is not a valid file.`
].join(' '))
}
}
}
|
javascript
|
async function validateOptions(options) {
// Check that input glob was passed
if (!options.paths.length) {
throw new ValidationError('No paths specified')
}
// Check that output path was passed
if (!options.outputDir) {
throw new ValidationError('Please specify an output directory with -o or --output')
}
// Check that the existance of output path
if (!await fsAsync.exists(options.outputDir)) {
throw new ValidationError('Output directory doesn\'t exist')
}
// Check that output path is a directory
const outStat = await fsAsync.stat(options.outputDir)
if (!outStat.isDirectory()) {
throw new ValidationError('Output path must be a directory')
}
// Check existance of CSS template (If set)
if (options.cssTemplate && !await fsAsync.exists(options.cssTemplate)) {
throw new ValidationError('CSS template not found')
}
// Check existance of HTML template (If set)
if (options.htmlTemplate && !await fsAsync.exists(options.htmlTemplate)) {
throw new ValidationError('HTML template not found')
}
// Validate codepoints file if passed
if (options.codepoints) {
if (!await fsAsync.exists(options.codepoints)) {
throw new ValidationError(`Cannot find json file @ ${options.codepoints}!`)
}
const codepointsStat = await fsAsync.stat(options.codepoints)
if (!codepointsStat.isFile() || path.extname(options.codepoints) !== '.json') {
throw new ValidationError([
'Codepoints file must be JSON',
`${options.codepoints} is not a valid file.`
].join(' '))
}
}
}
|
[
"async",
"function",
"validateOptions",
"(",
"options",
")",
"{",
"// Check that input glob was passed",
"if",
"(",
"!",
"options",
".",
"paths",
".",
"length",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'No paths specified'",
")",
"}",
"// Check that output path was passed",
"if",
"(",
"!",
"options",
".",
"outputDir",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'Please specify an output directory with -o or --output'",
")",
"}",
"// Check that the existance of output path",
"if",
"(",
"!",
"await",
"fsAsync",
".",
"exists",
"(",
"options",
".",
"outputDir",
")",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'Output directory doesn\\'t exist'",
")",
"}",
"// Check that output path is a directory",
"const",
"outStat",
"=",
"await",
"fsAsync",
".",
"stat",
"(",
"options",
".",
"outputDir",
")",
"if",
"(",
"!",
"outStat",
".",
"isDirectory",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'Output path must be a directory'",
")",
"}",
"// Check existance of CSS template (If set)",
"if",
"(",
"options",
".",
"cssTemplate",
"&&",
"!",
"await",
"fsAsync",
".",
"exists",
"(",
"options",
".",
"cssTemplate",
")",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'CSS template not found'",
")",
"}",
"// Check existance of HTML template (If set)",
"if",
"(",
"options",
".",
"htmlTemplate",
"&&",
"!",
"await",
"fsAsync",
".",
"exists",
"(",
"options",
".",
"htmlTemplate",
")",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"'HTML template not found'",
")",
"}",
"// Validate codepoints file if passed",
"if",
"(",
"options",
".",
"codepoints",
")",
"{",
"if",
"(",
"!",
"await",
"fsAsync",
".",
"exists",
"(",
"options",
".",
"codepoints",
")",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"`",
"${",
"options",
".",
"codepoints",
"}",
"`",
")",
"}",
"const",
"codepointsStat",
"=",
"await",
"fsAsync",
".",
"stat",
"(",
"options",
".",
"codepoints",
")",
"if",
"(",
"!",
"codepointsStat",
".",
"isFile",
"(",
")",
"||",
"path",
".",
"extname",
"(",
"options",
".",
"codepoints",
")",
"!==",
"'.json'",
")",
"{",
"throw",
"new",
"ValidationError",
"(",
"[",
"'Codepoints file must be JSON'",
",",
"`",
"${",
"options",
".",
"codepoints",
"}",
"`",
"]",
".",
"join",
"(",
"' '",
")",
")",
"}",
"}",
"}"
] |
Asynchronously validate generation options, check existance of given files
and directories
@throws
@param {Object} options
@return {void}
|
[
"Asynchronously",
"validate",
"generation",
"options",
"check",
"existance",
"of",
"given",
"files",
"and",
"directories"
] |
a9ac3b34c7343ee6157176a6a2af00e29939b41c
|
https://github.com/Workshape/icon-font-generator/blob/a9ac3b34c7343ee6157176a6a2af00e29939b41c/lib/index.js#L262-L308
|
13,290
|
socketstream/socketstream
|
lib/http/index.js
|
sessionMiddleware
|
function sessionMiddleware(req,res,next) {
return ss.session.strategy.sessionMiddleware? ss.session.strategy.sessionMiddleware(req,res,next) : next();
}
|
javascript
|
function sessionMiddleware(req,res,next) {
return ss.session.strategy.sessionMiddleware? ss.session.strategy.sessionMiddleware(req,res,next) : next();
}
|
[
"function",
"sessionMiddleware",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"return",
"ss",
".",
"session",
".",
"strategy",
".",
"sessionMiddleware",
"?",
"ss",
".",
"session",
".",
"strategy",
".",
"sessionMiddleware",
"(",
"req",
",",
"res",
",",
"next",
")",
":",
"next",
"(",
")",
";",
"}"
] |
wrapped to allow using the middleware before the strategy is set
|
[
"wrapped",
"to",
"allow",
"using",
"the",
"middleware",
"before",
"the",
"strategy",
"is",
"set"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/http/index.js#L132-L134
|
13,291
|
socketstream/socketstream
|
lib/client/bundler/index.js
|
loadFile
|
function loadFile(entry, opts, formatter, cb, errCb) {
var type = entry.assetType || entry.bundle;
formatter = formatter || ss.client.formatters[entry.ext || type];
if (!formatter) {
throw new Error('Unsupported file extension \'.' + entry.ext + '\' when we were expecting some type of ' +
((type||'unknown').toUpperCase()) + ' file. Please provide a formatter for ' + (entry.file) + ' or move it to /client/static');
}
if (formatter.assetType !== type) {
throw new Error('Unable to render \'' + entry.file + '\' as this appears to be a ' + (type.toUpperCase()) +
' file. Expecting some type of ' + (type.toUpperCase()) + ' file in ' + (path.dirname(entry.file)) + ' instead');
}
// Use the formatter to pre-process the asset before bundling
try {
return formatter.call(this.clientFilePath(entry.file), opts, cb, errCb);
} catch (err) {
return errCb(err);
}
}
|
javascript
|
function loadFile(entry, opts, formatter, cb, errCb) {
var type = entry.assetType || entry.bundle;
formatter = formatter || ss.client.formatters[entry.ext || type];
if (!formatter) {
throw new Error('Unsupported file extension \'.' + entry.ext + '\' when we were expecting some type of ' +
((type||'unknown').toUpperCase()) + ' file. Please provide a formatter for ' + (entry.file) + ' or move it to /client/static');
}
if (formatter.assetType !== type) {
throw new Error('Unable to render \'' + entry.file + '\' as this appears to be a ' + (type.toUpperCase()) +
' file. Expecting some type of ' + (type.toUpperCase()) + ' file in ' + (path.dirname(entry.file)) + ' instead');
}
// Use the formatter to pre-process the asset before bundling
try {
return formatter.call(this.clientFilePath(entry.file), opts, cb, errCb);
} catch (err) {
return errCb(err);
}
}
|
[
"function",
"loadFile",
"(",
"entry",
",",
"opts",
",",
"formatter",
",",
"cb",
",",
"errCb",
")",
"{",
"var",
"type",
"=",
"entry",
".",
"assetType",
"||",
"entry",
".",
"bundle",
";",
"formatter",
"=",
"formatter",
"||",
"ss",
".",
"client",
".",
"formatters",
"[",
"entry",
".",
"ext",
"||",
"type",
"]",
";",
"if",
"(",
"!",
"formatter",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unsupported file extension \\'.'",
"+",
"entry",
".",
"ext",
"+",
"'\\' when we were expecting some type of '",
"+",
"(",
"(",
"type",
"||",
"'unknown'",
")",
".",
"toUpperCase",
"(",
")",
")",
"+",
"' file. Please provide a formatter for '",
"+",
"(",
"entry",
".",
"file",
")",
"+",
"' or move it to /client/static'",
")",
";",
"}",
"if",
"(",
"formatter",
".",
"assetType",
"!==",
"type",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to render \\''",
"+",
"entry",
".",
"file",
"+",
"'\\' as this appears to be a '",
"+",
"(",
"type",
".",
"toUpperCase",
"(",
")",
")",
"+",
"' file. Expecting some type of '",
"+",
"(",
"type",
".",
"toUpperCase",
"(",
")",
")",
"+",
"' file in '",
"+",
"(",
"path",
".",
"dirname",
"(",
"entry",
".",
"file",
")",
")",
"+",
"' instead'",
")",
";",
"}",
"// Use the formatter to pre-process the asset before bundling",
"try",
"{",
"return",
"formatter",
".",
"call",
"(",
"this",
".",
"clientFilePath",
"(",
"entry",
".",
"file",
")",
",",
"opts",
",",
"cb",
",",
"errCb",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"errCb",
"(",
"err",
")",
";",
"}",
"}"
] |
API for implementing bundlers
|
[
"API",
"for",
"implementing",
"bundlers"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/client/bundler/index.js#L220-L238
|
13,292
|
socketstream/socketstream
|
lib/client/bundler/index.js
|
function(paths) {
function relativePath(p, dirType) {
var relativeStart = p.indexOf('./') === 0 || p.indexOf('../') === 0;
return relativeStart? prefixPath(options.dirs.client,p) : prefixPath(options.dirs[dirType], p);
}
function prefixPath(base,p) {
base = base.replace(/^\//,'');
if (p === '*') {
return base;
}
p = p.replace(/\/\*$/,'');
return path.join(base,p);
}
function entries(from, dirType) {
if (from == null) {
return [];
}
var list = (from instanceof Array)? from : [from];
return list.map(function(value) {
return relativePath(value, dirType);
});
}
paths.css = entries(paths.css, 'css');
paths.code = entries(paths.code, 'code');
paths.tmpl = entries(paths.tmpl || paths.templates, 'templates');
if (paths.view) {
paths.view = relativePath(paths.view, 'views');
}
return paths;
}
|
javascript
|
function(paths) {
function relativePath(p, dirType) {
var relativeStart = p.indexOf('./') === 0 || p.indexOf('../') === 0;
return relativeStart? prefixPath(options.dirs.client,p) : prefixPath(options.dirs[dirType], p);
}
function prefixPath(base,p) {
base = base.replace(/^\//,'');
if (p === '*') {
return base;
}
p = p.replace(/\/\*$/,'');
return path.join(base,p);
}
function entries(from, dirType) {
if (from == null) {
return [];
}
var list = (from instanceof Array)? from : [from];
return list.map(function(value) {
return relativePath(value, dirType);
});
}
paths.css = entries(paths.css, 'css');
paths.code = entries(paths.code, 'code');
paths.tmpl = entries(paths.tmpl || paths.templates, 'templates');
if (paths.view) {
paths.view = relativePath(paths.view, 'views');
}
return paths;
}
|
[
"function",
"(",
"paths",
")",
"{",
"function",
"relativePath",
"(",
"p",
",",
"dirType",
")",
"{",
"var",
"relativeStart",
"=",
"p",
".",
"indexOf",
"(",
"'./'",
")",
"===",
"0",
"||",
"p",
".",
"indexOf",
"(",
"'../'",
")",
"===",
"0",
";",
"return",
"relativeStart",
"?",
"prefixPath",
"(",
"options",
".",
"dirs",
".",
"client",
",",
"p",
")",
":",
"prefixPath",
"(",
"options",
".",
"dirs",
"[",
"dirType",
"]",
",",
"p",
")",
";",
"}",
"function",
"prefixPath",
"(",
"base",
",",
"p",
")",
"{",
"base",
"=",
"base",
".",
"replace",
"(",
"/",
"^\\/",
"/",
",",
"''",
")",
";",
"if",
"(",
"p",
"===",
"'*'",
")",
"{",
"return",
"base",
";",
"}",
"p",
"=",
"p",
".",
"replace",
"(",
"/",
"\\/\\*$",
"/",
",",
"''",
")",
";",
"return",
"path",
".",
"join",
"(",
"base",
",",
"p",
")",
";",
"}",
"function",
"entries",
"(",
"from",
",",
"dirType",
")",
"{",
"if",
"(",
"from",
"==",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"var",
"list",
"=",
"(",
"from",
"instanceof",
"Array",
")",
"?",
"from",
":",
"[",
"from",
"]",
";",
"return",
"list",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"relativePath",
"(",
"value",
",",
"dirType",
")",
";",
"}",
")",
";",
"}",
"paths",
".",
"css",
"=",
"entries",
"(",
"paths",
".",
"css",
",",
"'css'",
")",
";",
"paths",
".",
"code",
"=",
"entries",
"(",
"paths",
".",
"code",
",",
"'code'",
")",
";",
"paths",
".",
"tmpl",
"=",
"entries",
"(",
"paths",
".",
"tmpl",
"||",
"paths",
".",
"templates",
",",
"'templates'",
")",
";",
"if",
"(",
"paths",
".",
"view",
")",
"{",
"paths",
".",
"view",
"=",
"relativePath",
"(",
"paths",
".",
"view",
",",
"'views'",
")",
";",
"}",
"return",
"paths",
";",
"}"
] |
input is decorated and returned
|
[
"input",
"is",
"decorated",
"and",
"returned"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/client/bundler/index.js#L274-L310
|
|
13,293
|
socketstream/socketstream
|
lib/session/memory.js
|
getSession
|
function getSession(sessions, sessionId) {
var sess = sessions[sessionId]
if (!sess) {
debug('no session in MemoryStore for %s',sessionId);
return;
}
// parse
sess = JSON.parse(sess)
var expires = typeof sess.cookie.expires === 'string' ?
new Date(sess.cookie.expires) :
sess.cookie.expires
// destroy expired session
if (expires && expires <= Date.now()) {
debug('Session %s is Expired in MemoryStore',sessionId);
delete sessions[sessionId];
return;
}
return sess
}
|
javascript
|
function getSession(sessions, sessionId) {
var sess = sessions[sessionId]
if (!sess) {
debug('no session in MemoryStore for %s',sessionId);
return;
}
// parse
sess = JSON.parse(sess)
var expires = typeof sess.cookie.expires === 'string' ?
new Date(sess.cookie.expires) :
sess.cookie.expires
// destroy expired session
if (expires && expires <= Date.now()) {
debug('Session %s is Expired in MemoryStore',sessionId);
delete sessions[sessionId];
return;
}
return sess
}
|
[
"function",
"getSession",
"(",
"sessions",
",",
"sessionId",
")",
"{",
"var",
"sess",
"=",
"sessions",
"[",
"sessionId",
"]",
"if",
"(",
"!",
"sess",
")",
"{",
"debug",
"(",
"'no session in MemoryStore for %s'",
",",
"sessionId",
")",
";",
"return",
";",
"}",
"// parse",
"sess",
"=",
"JSON",
".",
"parse",
"(",
"sess",
")",
"var",
"expires",
"=",
"typeof",
"sess",
".",
"cookie",
".",
"expires",
"===",
"'string'",
"?",
"new",
"Date",
"(",
"sess",
".",
"cookie",
".",
"expires",
")",
":",
"sess",
".",
"cookie",
".",
"expires",
"// destroy expired session",
"if",
"(",
"expires",
"&&",
"expires",
"<=",
"Date",
".",
"now",
"(",
")",
")",
"{",
"debug",
"(",
"'Session %s is Expired in MemoryStore'",
",",
"sessionId",
")",
";",
"delete",
"sessions",
"[",
"sessionId",
"]",
";",
"return",
";",
"}",
"return",
"sess",
"}"
] |
Get session from the store.
@private
|
[
"Get",
"session",
"from",
"the",
"store",
"."
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/session/memory.js#L172-L195
|
13,294
|
socketstream/socketstream
|
lib/http/cached.js
|
set
|
function set(url, content, mimeType) {
if (url.charAt(0) !== '/') { url = '/'+url; }
var point = getPoint(url) || new KnownPoint(url);
// console.info('new url:',url, mimeType);
point.content = content;
point.mimeType = mimeType;
}
|
javascript
|
function set(url, content, mimeType) {
if (url.charAt(0) !== '/') { url = '/'+url; }
var point = getPoint(url) || new KnownPoint(url);
// console.info('new url:',url, mimeType);
point.content = content;
point.mimeType = mimeType;
}
|
[
"function",
"set",
"(",
"url",
",",
"content",
",",
"mimeType",
")",
"{",
"if",
"(",
"url",
".",
"charAt",
"(",
"0",
")",
"!==",
"'/'",
")",
"{",
"url",
"=",
"'/'",
"+",
"url",
";",
"}",
"var",
"point",
"=",
"getPoint",
"(",
"url",
")",
"||",
"new",
"KnownPoint",
"(",
"url",
")",
";",
"// console.info('new url:',url, mimeType);",
"point",
".",
"content",
"=",
"content",
";",
"point",
".",
"mimeType",
"=",
"mimeType",
";",
"}"
] |
assumed to be dev time frame, if this is to be used for production it should be enhanced
|
[
"assumed",
"to",
"be",
"dev",
"time",
"frame",
"if",
"this",
"is",
"to",
"be",
"used",
"for",
"production",
"it",
"should",
"be",
"enhanced"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/http/cached.js#L146-L152
|
13,295
|
socketstream/socketstream
|
lib/session/channels.js
|
function(names, cb) {
if (!cb) {
cb = function() {};
}
if (!session.channels) {
session.channels = [];
}
forceArray(names).forEach(function(name) {
if (session.channels.indexOf(name) === -1) { // clients can only join a channel once
session.channels.push(name);
return ss.log.info('i'.green + ' subscribed sessionId '.grey + session.id + ' to channel '.grey + name);
}
});
this._bindToSocket();
return session.save(cb);
}
|
javascript
|
function(names, cb) {
if (!cb) {
cb = function() {};
}
if (!session.channels) {
session.channels = [];
}
forceArray(names).forEach(function(name) {
if (session.channels.indexOf(name) === -1) { // clients can only join a channel once
session.channels.push(name);
return ss.log.info('i'.green + ' subscribed sessionId '.grey + session.id + ' to channel '.grey + name);
}
});
this._bindToSocket();
return session.save(cb);
}
|
[
"function",
"(",
"names",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"cb",
")",
"{",
"cb",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"session",
".",
"channels",
")",
"{",
"session",
".",
"channels",
"=",
"[",
"]",
";",
"}",
"forceArray",
"(",
"names",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"if",
"(",
"session",
".",
"channels",
".",
"indexOf",
"(",
"name",
")",
"===",
"-",
"1",
")",
"{",
"// clients can only join a channel once",
"session",
".",
"channels",
".",
"push",
"(",
"name",
")",
";",
"return",
"ss",
".",
"log",
".",
"info",
"(",
"'i'",
".",
"green",
"+",
"' subscribed sessionId '",
".",
"grey",
"+",
"session",
".",
"id",
"+",
"' to channel '",
".",
"grey",
"+",
"name",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"_bindToSocket",
"(",
")",
";",
"return",
"session",
".",
"save",
"(",
"cb",
")",
";",
"}"
] |
Subscribes the client to one or more channels
|
[
"Subscribes",
"the",
"client",
"to",
"one",
"or",
"more",
"channels"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/session/channels.js#L20-L35
|
|
13,296
|
socketstream/socketstream
|
lib/session/channels.js
|
function(names, cb) {
if (!cb) {
cb = function() {};
}
if (!session.channels) {
session.channels = [];
}
forceArray(names).forEach(function(name) {
var i;
if ((i = session.channels.indexOf(name)) >= 0) {
session.channels.splice(i, 1);
subscriptions.channel.remove(name, socketId);
return ss.log.info('i'.green + ' unsubscribed sessionId '.grey + session.id + ' from channel '.grey + name);
}
});
return session.save(cb);
}
|
javascript
|
function(names, cb) {
if (!cb) {
cb = function() {};
}
if (!session.channels) {
session.channels = [];
}
forceArray(names).forEach(function(name) {
var i;
if ((i = session.channels.indexOf(name)) >= 0) {
session.channels.splice(i, 1);
subscriptions.channel.remove(name, socketId);
return ss.log.info('i'.green + ' unsubscribed sessionId '.grey + session.id + ' from channel '.grey + name);
}
});
return session.save(cb);
}
|
[
"function",
"(",
"names",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"cb",
")",
"{",
"cb",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"session",
".",
"channels",
")",
"{",
"session",
".",
"channels",
"=",
"[",
"]",
";",
"}",
"forceArray",
"(",
"names",
")",
".",
"forEach",
"(",
"function",
"(",
"name",
")",
"{",
"var",
"i",
";",
"if",
"(",
"(",
"i",
"=",
"session",
".",
"channels",
".",
"indexOf",
"(",
"name",
")",
")",
">=",
"0",
")",
"{",
"session",
".",
"channels",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"subscriptions",
".",
"channel",
".",
"remove",
"(",
"name",
",",
"socketId",
")",
";",
"return",
"ss",
".",
"log",
".",
"info",
"(",
"'i'",
".",
"green",
"+",
"' unsubscribed sessionId '",
".",
"grey",
"+",
"session",
".",
"id",
"+",
"' from channel '",
".",
"grey",
"+",
"name",
")",
";",
"}",
"}",
")",
";",
"return",
"session",
".",
"save",
"(",
"cb",
")",
";",
"}"
] |
Unsubscribes the client from one or more channels
|
[
"Unsubscribes",
"the",
"client",
"from",
"one",
"or",
"more",
"channels"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/session/channels.js#L38-L54
|
|
13,297
|
socketstream/socketstream
|
lib/utils/file.js
|
isDir
|
function isDir(abspath, found) {
var stat = fs.statSync(abspath),
abspathAry = abspath.split('/'),
data,
file_name;
if (!found) {
found = {dirs: [], files: [] }
}
if (stat.isDirectory() && !isHidden(abspathAry[abspathAry.length - 1])) {
found.dirs.push(abspath);
/* If we found a directory, recurse! */
data = exports.readDirSync(abspath);
found.dirs = found.dirs.concat(data.dirs);
found.files = found.files.concat(data.files);
} else {
abspathAry = abspath.split('/');
file_name = abspathAry[abspathAry.length - 1];
if (!isHidden(file_name)) {
found.files.push(abspath);
}
}
return found;
}
|
javascript
|
function isDir(abspath, found) {
var stat = fs.statSync(abspath),
abspathAry = abspath.split('/'),
data,
file_name;
if (!found) {
found = {dirs: [], files: [] }
}
if (stat.isDirectory() && !isHidden(abspathAry[abspathAry.length - 1])) {
found.dirs.push(abspath);
/* If we found a directory, recurse! */
data = exports.readDirSync(abspath);
found.dirs = found.dirs.concat(data.dirs);
found.files = found.files.concat(data.files);
} else {
abspathAry = abspath.split('/');
file_name = abspathAry[abspathAry.length - 1];
if (!isHidden(file_name)) {
found.files.push(abspath);
}
}
return found;
}
|
[
"function",
"isDir",
"(",
"abspath",
",",
"found",
")",
"{",
"var",
"stat",
"=",
"fs",
".",
"statSync",
"(",
"abspath",
")",
",",
"abspathAry",
"=",
"abspath",
".",
"split",
"(",
"'/'",
")",
",",
"data",
",",
"file_name",
";",
"if",
"(",
"!",
"found",
")",
"{",
"found",
"=",
"{",
"dirs",
":",
"[",
"]",
",",
"files",
":",
"[",
"]",
"}",
"}",
"if",
"(",
"stat",
".",
"isDirectory",
"(",
")",
"&&",
"!",
"isHidden",
"(",
"abspathAry",
"[",
"abspathAry",
".",
"length",
"-",
"1",
"]",
")",
")",
"{",
"found",
".",
"dirs",
".",
"push",
"(",
"abspath",
")",
";",
"/* If we found a directory, recurse! */",
"data",
"=",
"exports",
".",
"readDirSync",
"(",
"abspath",
")",
";",
"found",
".",
"dirs",
"=",
"found",
".",
"dirs",
".",
"concat",
"(",
"data",
".",
"dirs",
")",
";",
"found",
".",
"files",
"=",
"found",
".",
"files",
".",
"concat",
"(",
"data",
".",
"files",
")",
";",
"}",
"else",
"{",
"abspathAry",
"=",
"abspath",
".",
"split",
"(",
"'/'",
")",
";",
"file_name",
"=",
"abspathAry",
"[",
"abspathAry",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"isHidden",
"(",
"file_name",
")",
")",
"{",
"found",
".",
"files",
".",
"push",
"(",
"abspath",
")",
";",
"}",
"}",
"return",
"found",
";",
"}"
] |
Identifies if the path is directory
@param {String} abspath Absolute path, should be already have replaced '\' with '/' to support Windows
@param {Object} found Object: {dirs: [], files: [] }, contains information about directory's files and subdirectories
@return {Object} Updated 'found' object
|
[
"Identifies",
"if",
"the",
"path",
"is",
"directory"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/utils/file.js#L41-L69
|
13,298
|
socketstream/socketstream
|
lib/utils/require.js
|
projectOrHereRequire
|
function projectOrHereRequire(id,root) {
try {
return resolve.sync(id, {
package: path.join(root,'package.json'),
paths: [root],
basedir:root
});
} catch(ex) {
// console.error(ex);
}
var here = path.join(__dirname,'..','..');
try {
var p = resolve.sync(id, {
package: path.join(here,'package.json'),
paths: [here],
basedir:here
});
return p;
} catch(ex) {
// console.error(ex);
}
}
|
javascript
|
function projectOrHereRequire(id,root) {
try {
return resolve.sync(id, {
package: path.join(root,'package.json'),
paths: [root],
basedir:root
});
} catch(ex) {
// console.error(ex);
}
var here = path.join(__dirname,'..','..');
try {
var p = resolve.sync(id, {
package: path.join(here,'package.json'),
paths: [here],
basedir:here
});
return p;
} catch(ex) {
// console.error(ex);
}
}
|
[
"function",
"projectOrHereRequire",
"(",
"id",
",",
"root",
")",
"{",
"try",
"{",
"return",
"resolve",
".",
"sync",
"(",
"id",
",",
"{",
"package",
":",
"path",
".",
"join",
"(",
"root",
",",
"'package.json'",
")",
",",
"paths",
":",
"[",
"root",
"]",
",",
"basedir",
":",
"root",
"}",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"// console.error(ex);",
"}",
"var",
"here",
"=",
"path",
".",
"join",
"(",
"__dirname",
",",
"'..'",
",",
"'..'",
")",
";",
"try",
"{",
"var",
"p",
"=",
"resolve",
".",
"sync",
"(",
"id",
",",
"{",
"package",
":",
"path",
".",
"join",
"(",
"here",
",",
"'package.json'",
")",
",",
"paths",
":",
"[",
"here",
"]",
",",
"basedir",
":",
"here",
"}",
")",
";",
"return",
"p",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"// console.error(ex);",
"}",
"}"
] |
return path to found, project first
|
[
"return",
"path",
"to",
"found",
"project",
"first"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/utils/require.js#L138-L160
|
13,299
|
socketstream/socketstream
|
lib/client/bundler/proto.js
|
resolveAssetLink
|
function resolveAssetLink(client, type) {
var defaultPath = '/assets/' + client.name + '/' + client.id + '.' + type,
pack = options.packedAssets,
link = pack !== undefined ? (pack.cdn !== undefined ? pack.cdn[type] : void 0) : void 0;
if (link) {
if (typeof link === 'function') {
var file = {
id: client.id,
name: client.name,
extension: type,
path: defaultPath
};
return link(file);
} else if (typeof link === 'string') {
return link;
} else {
throw new Error('CDN ' + type + ' param must be a Function or String');
}
} else {
return defaultPath;
}
}
|
javascript
|
function resolveAssetLink(client, type) {
var defaultPath = '/assets/' + client.name + '/' + client.id + '.' + type,
pack = options.packedAssets,
link = pack !== undefined ? (pack.cdn !== undefined ? pack.cdn[type] : void 0) : void 0;
if (link) {
if (typeof link === 'function') {
var file = {
id: client.id,
name: client.name,
extension: type,
path: defaultPath
};
return link(file);
} else if (typeof link === 'string') {
return link;
} else {
throw new Error('CDN ' + type + ' param must be a Function or String');
}
} else {
return defaultPath;
}
}
|
[
"function",
"resolveAssetLink",
"(",
"client",
",",
"type",
")",
"{",
"var",
"defaultPath",
"=",
"'/assets/'",
"+",
"client",
".",
"name",
"+",
"'/'",
"+",
"client",
".",
"id",
"+",
"'.'",
"+",
"type",
",",
"pack",
"=",
"options",
".",
"packedAssets",
",",
"link",
"=",
"pack",
"!==",
"undefined",
"?",
"(",
"pack",
".",
"cdn",
"!==",
"undefined",
"?",
"pack",
".",
"cdn",
"[",
"type",
"]",
":",
"void",
"0",
")",
":",
"void",
"0",
";",
"if",
"(",
"link",
")",
"{",
"if",
"(",
"typeof",
"link",
"===",
"'function'",
")",
"{",
"var",
"file",
"=",
"{",
"id",
":",
"client",
".",
"id",
",",
"name",
":",
"client",
".",
"name",
",",
"extension",
":",
"type",
",",
"path",
":",
"defaultPath",
"}",
";",
"return",
"link",
"(",
"file",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"link",
"===",
"'string'",
")",
"{",
"return",
"link",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'CDN '",
"+",
"type",
"+",
"' param must be a Function or String'",
")",
";",
"}",
"}",
"else",
"{",
"return",
"defaultPath",
";",
"}",
"}"
] |
When packing assets the default path to the CSS or JS file can be overridden either with a string or a function, typically pointing to an resource on a CDN
|
[
"When",
"packing",
"assets",
"the",
"default",
"path",
"to",
"the",
"CSS",
"or",
"JS",
"file",
"can",
"be",
"overridden",
"either",
"with",
"a",
"string",
"or",
"a",
"function",
"typically",
"pointing",
"to",
"an",
"resource",
"on",
"a",
"CDN"
] |
bc783da043de558ee3ff9032ea15b9b8113a8659
|
https://github.com/socketstream/socketstream/blob/bc783da043de558ee3ff9032ea15b9b8113a8659/lib/client/bundler/proto.js#L126-L147
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.