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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
8,700 | assaf/zombie | src/reroute.js | enableRerouting | function enableRerouting() {
if (enabled)
return;
enabled = true;
const connect = Net.Socket.prototype.connect;
Net.Socket.prototype.connect = function(options, callback) {
const hasNormalizedArgs = Object.getOwnPropertySymbols && Object.getOwnPropertySymbols(options).length > 0;
const isNode8 = Array.isArray(options) && hasNormalizedArgs;
if (isNode8) {
const reroutedOptions = rerouteOptions(options[0]);
callback = options[1];
return connect.call(this, reroutedOptions, callback);
} else if (typeof options === 'object') {
const reroutedOptions = rerouteOptions(options);
return connect.call(this, reroutedOptions, callback);
} else
return connect.apply(this, arguments);
};
} | javascript | function enableRerouting() {
if (enabled)
return;
enabled = true;
const connect = Net.Socket.prototype.connect;
Net.Socket.prototype.connect = function(options, callback) {
const hasNormalizedArgs = Object.getOwnPropertySymbols && Object.getOwnPropertySymbols(options).length > 0;
const isNode8 = Array.isArray(options) && hasNormalizedArgs;
if (isNode8) {
const reroutedOptions = rerouteOptions(options[0]);
callback = options[1];
return connect.call(this, reroutedOptions, callback);
} else if (typeof options === 'object') {
const reroutedOptions = rerouteOptions(options);
return connect.call(this, reroutedOptions, callback);
} else
return connect.apply(this, arguments);
};
} | [
"function",
"enableRerouting",
"(",
")",
"{",
"if",
"(",
"enabled",
")",
"return",
";",
"enabled",
"=",
"true",
";",
"const",
"connect",
"=",
"Net",
".",
"Socket",
".",
"prototype",
".",
"connect",
";",
"Net",
".",
"Socket",
".",
"prototype",
".",
"connect",
"=",
"function",
"(",
"options",
",",
"callback",
")",
"{",
"const",
"hasNormalizedArgs",
"=",
"Object",
".",
"getOwnPropertySymbols",
"&&",
"Object",
".",
"getOwnPropertySymbols",
"(",
"options",
")",
".",
"length",
">",
"0",
";",
"const",
"isNode8",
"=",
"Array",
".",
"isArray",
"(",
"options",
")",
"&&",
"hasNormalizedArgs",
";",
"if",
"(",
"isNode8",
")",
"{",
"const",
"reroutedOptions",
"=",
"rerouteOptions",
"(",
"options",
"[",
"0",
"]",
")",
";",
"callback",
"=",
"options",
"[",
"1",
"]",
";",
"return",
"connect",
".",
"call",
"(",
"this",
",",
"reroutedOptions",
",",
"callback",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
"===",
"'object'",
")",
"{",
"const",
"reroutedOptions",
"=",
"rerouteOptions",
"(",
"options",
")",
";",
"return",
"connect",
".",
"call",
"(",
"this",
",",
"reroutedOptions",
",",
"callback",
")",
";",
"}",
"else",
"return",
"connect",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
";",
"}"
] | Called once to hack Socket.connect | [
"Called",
"once",
"to",
"hack",
"Socket",
".",
"connect"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/reroute.js#L51-L70 |
8,701 | assaf/zombie | src/assert.js | assertMatch | function assertMatch(actual, expected, message) {
if (isRegExp(expected))
assert(expected.test(actual), message || `Expected "${actual}" to match "${expected}"`);
else if (typeof expected === 'function')
assert(expected(actual), message);
else
assert.deepEqual(actual, expected, message);
} | javascript | function assertMatch(actual, expected, message) {
if (isRegExp(expected))
assert(expected.test(actual), message || `Expected "${actual}" to match "${expected}"`);
else if (typeof expected === 'function')
assert(expected(actual), message);
else
assert.deepEqual(actual, expected, message);
} | [
"function",
"assertMatch",
"(",
"actual",
",",
"expected",
",",
"message",
")",
"{",
"if",
"(",
"isRegExp",
"(",
"expected",
")",
")",
"assert",
"(",
"expected",
".",
"test",
"(",
"actual",
")",
",",
"message",
"||",
"`",
"${",
"actual",
"}",
"${",
"expected",
"}",
"`",
")",
";",
"else",
"if",
"(",
"typeof",
"expected",
"===",
"'function'",
")",
"assert",
"(",
"expected",
"(",
"actual",
")",
",",
"message",
")",
";",
"else",
"assert",
".",
"deepEqual",
"(",
"actual",
",",
"expected",
",",
"message",
")",
";",
"}"
] | Used to assert that actual matches expected value, where expected may be a function or a string. | [
"Used",
"to",
"assert",
"that",
"actual",
"matches",
"expected",
"value",
"where",
"expected",
"may",
"be",
"a",
"function",
"or",
"a",
"string",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/assert.js#L10-L17 |
8,702 | assaf/zombie | src/eventloop.js | ontick | function ontick(next) {
// No point in waiting that long
if (next >= timeoutOn) {
timeout();
return;
}
const activeWindow = eventLoop.active;
if (completionFunction && activeWindow.document.documentElement)
try {
const waitFor = Math.max(next - Date.now(), 0);
// Event processed, are we ready to complete?
const completed = completionFunction(activeWindow, waitFor);
if (completed)
done();
} catch (error) {
done(error);
}
} | javascript | function ontick(next) {
// No point in waiting that long
if (next >= timeoutOn) {
timeout();
return;
}
const activeWindow = eventLoop.active;
if (completionFunction && activeWindow.document.documentElement)
try {
const waitFor = Math.max(next - Date.now(), 0);
// Event processed, are we ready to complete?
const completed = completionFunction(activeWindow, waitFor);
if (completed)
done();
} catch (error) {
done(error);
}
} | [
"function",
"ontick",
"(",
"next",
")",
"{",
"// No point in waiting that long",
"if",
"(",
"next",
">=",
"timeoutOn",
")",
"{",
"timeout",
"(",
")",
";",
"return",
";",
"}",
"const",
"activeWindow",
"=",
"eventLoop",
".",
"active",
";",
"if",
"(",
"completionFunction",
"&&",
"activeWindow",
".",
"document",
".",
"documentElement",
")",
"try",
"{",
"const",
"waitFor",
"=",
"Math",
".",
"max",
"(",
"next",
"-",
"Date",
".",
"now",
"(",
")",
",",
"0",
")",
";",
"// Event processed, are we ready to complete?",
"const",
"completed",
"=",
"completionFunction",
"(",
"activeWindow",
",",
"waitFor",
")",
";",
"if",
"(",
"completed",
")",
"done",
"(",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"done",
"(",
"error",
")",
";",
"}",
"}"
] | Fired after every event, decide if we want to stop waiting | [
"Fired",
"after",
"every",
"event",
"decide",
"if",
"we",
"want",
"to",
"stop",
"waiting"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/eventloop.js#L414-L433 |
8,703 | assaf/zombie | src/eventloop.js | done | function done(error) {
global.clearTimeout(timer);
eventLoop.removeListener('tick', ontick);
eventLoop.removeListener('idle', done);
eventLoop.browser.removeListener('error', done);
--eventLoop.waiting;
try {
callback(error);
} catch (error) {
// If callback makes an assertion that fails, we end here.
// If we throw error synchronously, it gets swallowed.
setImmediate(function() {
throw error;
});
}
} | javascript | function done(error) {
global.clearTimeout(timer);
eventLoop.removeListener('tick', ontick);
eventLoop.removeListener('idle', done);
eventLoop.browser.removeListener('error', done);
--eventLoop.waiting;
try {
callback(error);
} catch (error) {
// If callback makes an assertion that fails, we end here.
// If we throw error synchronously, it gets swallowed.
setImmediate(function() {
throw error;
});
}
} | [
"function",
"done",
"(",
"error",
")",
"{",
"global",
".",
"clearTimeout",
"(",
"timer",
")",
";",
"eventLoop",
".",
"removeListener",
"(",
"'tick'",
",",
"ontick",
")",
";",
"eventLoop",
".",
"removeListener",
"(",
"'idle'",
",",
"done",
")",
";",
"eventLoop",
".",
"browser",
".",
"removeListener",
"(",
"'error'",
",",
"done",
")",
";",
"--",
"eventLoop",
".",
"waiting",
";",
"try",
"{",
"callback",
"(",
"error",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"// If callback makes an assertion that fails, we end here.",
"// If we throw error synchronously, it gets swallowed.",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"throw",
"error",
";",
"}",
")",
";",
"}",
"}"
] | The wait is over ... | [
"The",
"wait",
"is",
"over",
"..."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/eventloop.js#L436-L452 |
8,704 | assaf/zombie | Gulpfile.js | changes | function changes() {
const version = require('./package.json').version;
const changelog = File.readFileSync('CHANGELOG.md', 'utf-8');
const match = changelog.match(/^## Version (.*) .*\n([\S\s]+?)\n##/m);
assert(match, 'CHANGELOG.md missing entry: ## Version ' + version);
assert.equal(match[1], version, 'CHANGELOG.md missing entry for version ' + version);
const changes = match[2].trim();
assert(changes, 'CHANGELOG.md empty entry for version ' + version);
File.writeFileSync('.changes', changes);
} | javascript | function changes() {
const version = require('./package.json').version;
const changelog = File.readFileSync('CHANGELOG.md', 'utf-8');
const match = changelog.match(/^## Version (.*) .*\n([\S\s]+?)\n##/m);
assert(match, 'CHANGELOG.md missing entry: ## Version ' + version);
assert.equal(match[1], version, 'CHANGELOG.md missing entry for version ' + version);
const changes = match[2].trim();
assert(changes, 'CHANGELOG.md empty entry for version ' + version);
File.writeFileSync('.changes', changes);
} | [
"function",
"changes",
"(",
")",
"{",
"const",
"version",
"=",
"require",
"(",
"'./package.json'",
")",
".",
"version",
";",
"const",
"changelog",
"=",
"File",
".",
"readFileSync",
"(",
"'CHANGELOG.md'",
",",
"'utf-8'",
")",
";",
"const",
"match",
"=",
"changelog",
".",
"match",
"(",
"/",
"^## Version (.*) .*\\n([\\S\\s]+?)\\n##",
"/",
"m",
")",
";",
"assert",
"(",
"match",
",",
"'CHANGELOG.md missing entry: ## Version '",
"+",
"version",
")",
";",
"assert",
".",
"equal",
"(",
"match",
"[",
"1",
"]",
",",
"version",
",",
"'CHANGELOG.md missing entry for version '",
"+",
"version",
")",
";",
"const",
"changes",
"=",
"match",
"[",
"2",
"]",
".",
"trim",
"(",
")",
";",
"assert",
"(",
"changes",
",",
"'CHANGELOG.md empty entry for version '",
"+",
"version",
")",
";",
"File",
".",
"writeFileSync",
"(",
"'.changes'",
",",
"changes",
")",
";",
"}"
] | Generate a change log summary for this release git tag uses the generated .changes file | [
"Generate",
"a",
"change",
"log",
"summary",
"for",
"this",
"release",
"git",
"tag",
"uses",
"the",
"generated",
".",
"changes",
"file"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/Gulpfile.js#L46-L57 |
8,705 | assaf/zombie | src/fetch.js | decompressStream | function decompressStream(stream, headers) {
const transferEncoding = headers.get('Transfer-Encoding');
const contentEncoding = headers.get('Content-Encoding');
if (contentEncoding === 'deflate' || transferEncoding === 'deflate')
return stream.pipe( Zlib.createInflate() );
if (contentEncoding === 'gzip' || transferEncoding === 'gzip')
return stream.pipe( Zlib.createGunzip() );
return stream;
} | javascript | function decompressStream(stream, headers) {
const transferEncoding = headers.get('Transfer-Encoding');
const contentEncoding = headers.get('Content-Encoding');
if (contentEncoding === 'deflate' || transferEncoding === 'deflate')
return stream.pipe( Zlib.createInflate() );
if (contentEncoding === 'gzip' || transferEncoding === 'gzip')
return stream.pipe( Zlib.createGunzip() );
return stream;
} | [
"function",
"decompressStream",
"(",
"stream",
",",
"headers",
")",
"{",
"const",
"transferEncoding",
"=",
"headers",
".",
"get",
"(",
"'Transfer-Encoding'",
")",
";",
"const",
"contentEncoding",
"=",
"headers",
".",
"get",
"(",
"'Content-Encoding'",
")",
";",
"if",
"(",
"contentEncoding",
"===",
"'deflate'",
"||",
"transferEncoding",
"===",
"'deflate'",
")",
"return",
"stream",
".",
"pipe",
"(",
"Zlib",
".",
"createInflate",
"(",
")",
")",
";",
"if",
"(",
"contentEncoding",
"===",
"'gzip'",
"||",
"transferEncoding",
"===",
"'gzip'",
")",
"return",
"stream",
".",
"pipe",
"(",
"Zlib",
".",
"createGunzip",
"(",
")",
")",
";",
"return",
"stream",
";",
"}"
] | Decompress stream based on content and transfer encoding headers. | [
"Decompress",
"stream",
"based",
"on",
"content",
"and",
"transfer",
"encoding",
"headers",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/fetch.js#L9-L17 |
8,706 | assaf/zombie | src/dom/forms.js | click | function click() {
const clickEvent = input.ownerDocument.createEvent('HTMLEvents');
clickEvent.initEvent('click', true, true);
const labelElementImpl = domSymbolTree.parent(idlUtils.implForWrapper(input));
const dispatchResult = input.dispatchEvent(clickEvent);
input._click && input._click(clickEvent);
return dispatchResult;
} | javascript | function click() {
const clickEvent = input.ownerDocument.createEvent('HTMLEvents');
clickEvent.initEvent('click', true, true);
const labelElementImpl = domSymbolTree.parent(idlUtils.implForWrapper(input));
const dispatchResult = input.dispatchEvent(clickEvent);
input._click && input._click(clickEvent);
return dispatchResult;
} | [
"function",
"click",
"(",
")",
"{",
"const",
"clickEvent",
"=",
"input",
".",
"ownerDocument",
".",
"createEvent",
"(",
"'HTMLEvents'",
")",
";",
"clickEvent",
".",
"initEvent",
"(",
"'click'",
",",
"true",
",",
"true",
")",
";",
"const",
"labelElementImpl",
"=",
"domSymbolTree",
".",
"parent",
"(",
"idlUtils",
".",
"implForWrapper",
"(",
"input",
")",
")",
";",
"const",
"dispatchResult",
"=",
"input",
".",
"dispatchEvent",
"(",
"clickEvent",
")",
";",
"input",
".",
"_click",
"&&",
"input",
".",
"_click",
"(",
"clickEvent",
")",
";",
"return",
"dispatchResult",
";",
"}"
] | First event we fire is click event | [
"First",
"event",
"we",
"fire",
"is",
"click",
"event"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/dom/forms.js#L182-L189 |
8,707 | assaf/zombie | src/document.js | windowLoaded | function windowLoaded(event) {
document.removeEventListener('DOMContentLoaded', windowLoaded);
// JSDom > 7.1 does not allow re-dispatching the same event, so
// a copy of the event needs to be created for the new dispatch
const windowContentLoaded = document.createEvent('HTMLEvents');
windowContentLoaded.initEvent('DOMContentLoaded', false, false);
window.dispatchEvent(windowContentLoaded);
} | javascript | function windowLoaded(event) {
document.removeEventListener('DOMContentLoaded', windowLoaded);
// JSDom > 7.1 does not allow re-dispatching the same event, so
// a copy of the event needs to be created for the new dispatch
const windowContentLoaded = document.createEvent('HTMLEvents');
windowContentLoaded.initEvent('DOMContentLoaded', false, false);
window.dispatchEvent(windowContentLoaded);
} | [
"function",
"windowLoaded",
"(",
"event",
")",
"{",
"document",
".",
"removeEventListener",
"(",
"'DOMContentLoaded'",
",",
"windowLoaded",
")",
";",
"// JSDom > 7.1 does not allow re-dispatching the same event, so",
"// a copy of the event needs to be created for the new dispatch",
"const",
"windowContentLoaded",
"=",
"document",
".",
"createEvent",
"(",
"'HTMLEvents'",
")",
";",
"windowContentLoaded",
".",
"initEvent",
"(",
"'DOMContentLoaded'",
",",
"false",
",",
"false",
")",
";",
"window",
".",
"dispatchEvent",
"(",
"windowContentLoaded",
")",
";",
"}"
] | JSDOM fires DCL event on document but not on window | [
"JSDOM",
"fires",
"DCL",
"event",
"on",
"document",
"but",
"not",
"on",
"window"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L468-L476 |
8,708 | assaf/zombie | src/document.js | createDocument | function createDocument(args) {
const { browser } = args;
const features = {
FetchExternalResources: [],
ProcessExternalResources: [],
MutationEvents: '2.0'
};
const window = new Window({
parsingMode: 'html',
contentType: 'text/html',
url: args.url,
referrer: args.referrer
});
const { document } = window;
const documentImpl = idlUtils.implForWrapper(document)
if (args.browser.hasFeature('scripts', true)) {
features.FetchExternalResources.push('script');
features.ProcessExternalResources.push('script');
window._runScripts = 'dangerously';
}
if (args.browser.hasFeature('css', false)) {
features.FetchExternalResources.push('css');
features.FetchExternalResources.push('link');
}
if (args.browser.hasFeature('img', false))
features.FetchExternalResources.push('img');
if (args.browser.hasFeature('iframe', true))
features.FetchExternalResources.push('iframe');
browserFeatures.applyDocumentFeatures(documentImpl, features);
setupWindow(window, args);
// Give event handler chance to register listeners.
args.browser.emit('loading', document);
return document;
} | javascript | function createDocument(args) {
const { browser } = args;
const features = {
FetchExternalResources: [],
ProcessExternalResources: [],
MutationEvents: '2.0'
};
const window = new Window({
parsingMode: 'html',
contentType: 'text/html',
url: args.url,
referrer: args.referrer
});
const { document } = window;
const documentImpl = idlUtils.implForWrapper(document)
if (args.browser.hasFeature('scripts', true)) {
features.FetchExternalResources.push('script');
features.ProcessExternalResources.push('script');
window._runScripts = 'dangerously';
}
if (args.browser.hasFeature('css', false)) {
features.FetchExternalResources.push('css');
features.FetchExternalResources.push('link');
}
if (args.browser.hasFeature('img', false))
features.FetchExternalResources.push('img');
if (args.browser.hasFeature('iframe', true))
features.FetchExternalResources.push('iframe');
browserFeatures.applyDocumentFeatures(documentImpl, features);
setupWindow(window, args);
// Give event handler chance to register listeners.
args.browser.emit('loading', document);
return document;
} | [
"function",
"createDocument",
"(",
"args",
")",
"{",
"const",
"{",
"browser",
"}",
"=",
"args",
";",
"const",
"features",
"=",
"{",
"FetchExternalResources",
":",
"[",
"]",
",",
"ProcessExternalResources",
":",
"[",
"]",
",",
"MutationEvents",
":",
"'2.0'",
"}",
";",
"const",
"window",
"=",
"new",
"Window",
"(",
"{",
"parsingMode",
":",
"'html'",
",",
"contentType",
":",
"'text/html'",
",",
"url",
":",
"args",
".",
"url",
",",
"referrer",
":",
"args",
".",
"referrer",
"}",
")",
";",
"const",
"{",
"document",
"}",
"=",
"window",
";",
"const",
"documentImpl",
"=",
"idlUtils",
".",
"implForWrapper",
"(",
"document",
")",
"if",
"(",
"args",
".",
"browser",
".",
"hasFeature",
"(",
"'scripts'",
",",
"true",
")",
")",
"{",
"features",
".",
"FetchExternalResources",
".",
"push",
"(",
"'script'",
")",
";",
"features",
".",
"ProcessExternalResources",
".",
"push",
"(",
"'script'",
")",
";",
"window",
".",
"_runScripts",
"=",
"'dangerously'",
";",
"}",
"if",
"(",
"args",
".",
"browser",
".",
"hasFeature",
"(",
"'css'",
",",
"false",
")",
")",
"{",
"features",
".",
"FetchExternalResources",
".",
"push",
"(",
"'css'",
")",
";",
"features",
".",
"FetchExternalResources",
".",
"push",
"(",
"'link'",
")",
";",
"}",
"if",
"(",
"args",
".",
"browser",
".",
"hasFeature",
"(",
"'img'",
",",
"false",
")",
")",
"features",
".",
"FetchExternalResources",
".",
"push",
"(",
"'img'",
")",
";",
"if",
"(",
"args",
".",
"browser",
".",
"hasFeature",
"(",
"'iframe'",
",",
"true",
")",
")",
"features",
".",
"FetchExternalResources",
".",
"push",
"(",
"'iframe'",
")",
";",
"browserFeatures",
".",
"applyDocumentFeatures",
"(",
"documentImpl",
",",
"features",
")",
";",
"setupWindow",
"(",
"window",
",",
"args",
")",
";",
"// Give event handler chance to register listeners.",
"args",
".",
"browser",
".",
"emit",
"(",
"'loading'",
",",
"document",
")",
";",
"return",
"document",
";",
"}"
] | Creates an returns a new document attached to the window. | [
"Creates",
"an",
"returns",
"a",
"new",
"document",
"attached",
"to",
"the",
"window",
"."
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L491-L531 |
8,709 | assaf/zombie | src/document.js | parseResponse | function parseResponse({ browser, history, document, response }) {
const window = document.defaultView;
window._request = response.request;
window._response = response;
history.updateLocation(window, response._url);
const done = window._eventQueue.waitForCompletion();
response
._consume()
.then(function(body) {
const contentType = response.headers.get('Content-Type') || '';
const html = getHTMLFromResponseBody(body, contentType);
response.body = html;
document.write(html || '<html></html>');
document.close();
browser.emit('loaded', document);
if (response.status >= 400)
throw new Error(`Server returned status code ${response.status} from ${response.url}`);
if (!document.documentElement)
throw new Error(`Could not parse document at ${response.url}`);
})
.then(function() {
// Handle meta refresh. Automatically reloads new location and counts
// as a redirect.
//
// If you need to check the page before refresh takes place, use this:
// browser.wait({
// function: function() {
// return browser.query('meta[http-equiv="refresh"]');
// }
// });
const refresh = getMetaRefresh(document);
if (refresh) {
const { refreshTimeout } = refresh;
const { refreshURL } = refresh;
window._eventQueue.setTimeout(function() {
// Allow completion function to run
window._eventQueue.enqueue(function() {
window._eventQueue.enqueue(function() {
// Count a meta-refresh in the redirects count.
history.replace(refreshURL);
// This results in a new window getting loaded
const newWindow = history.current.window;
newWindow.addEventListener('load', function() {
++newWindow._request._redirectCount;
});
});
});
}, refreshTimeout * 1000);
}
})
.catch(function(error) {
browser.emit('error', error);
})
.then(done);
} | javascript | function parseResponse({ browser, history, document, response }) {
const window = document.defaultView;
window._request = response.request;
window._response = response;
history.updateLocation(window, response._url);
const done = window._eventQueue.waitForCompletion();
response
._consume()
.then(function(body) {
const contentType = response.headers.get('Content-Type') || '';
const html = getHTMLFromResponseBody(body, contentType);
response.body = html;
document.write(html || '<html></html>');
document.close();
browser.emit('loaded', document);
if (response.status >= 400)
throw new Error(`Server returned status code ${response.status} from ${response.url}`);
if (!document.documentElement)
throw new Error(`Could not parse document at ${response.url}`);
})
.then(function() {
// Handle meta refresh. Automatically reloads new location and counts
// as a redirect.
//
// If you need to check the page before refresh takes place, use this:
// browser.wait({
// function: function() {
// return browser.query('meta[http-equiv="refresh"]');
// }
// });
const refresh = getMetaRefresh(document);
if (refresh) {
const { refreshTimeout } = refresh;
const { refreshURL } = refresh;
window._eventQueue.setTimeout(function() {
// Allow completion function to run
window._eventQueue.enqueue(function() {
window._eventQueue.enqueue(function() {
// Count a meta-refresh in the redirects count.
history.replace(refreshURL);
// This results in a new window getting loaded
const newWindow = history.current.window;
newWindow.addEventListener('load', function() {
++newWindow._request._redirectCount;
});
});
});
}, refreshTimeout * 1000);
}
})
.catch(function(error) {
browser.emit('error', error);
})
.then(done);
} | [
"function",
"parseResponse",
"(",
"{",
"browser",
",",
"history",
",",
"document",
",",
"response",
"}",
")",
"{",
"const",
"window",
"=",
"document",
".",
"defaultView",
";",
"window",
".",
"_request",
"=",
"response",
".",
"request",
";",
"window",
".",
"_response",
"=",
"response",
";",
"history",
".",
"updateLocation",
"(",
"window",
",",
"response",
".",
"_url",
")",
";",
"const",
"done",
"=",
"window",
".",
"_eventQueue",
".",
"waitForCompletion",
"(",
")",
";",
"response",
".",
"_consume",
"(",
")",
".",
"then",
"(",
"function",
"(",
"body",
")",
"{",
"const",
"contentType",
"=",
"response",
".",
"headers",
".",
"get",
"(",
"'Content-Type'",
")",
"||",
"''",
";",
"const",
"html",
"=",
"getHTMLFromResponseBody",
"(",
"body",
",",
"contentType",
")",
";",
"response",
".",
"body",
"=",
"html",
";",
"document",
".",
"write",
"(",
"html",
"||",
"'<html></html>'",
")",
";",
"document",
".",
"close",
"(",
")",
";",
"browser",
".",
"emit",
"(",
"'loaded'",
",",
"document",
")",
";",
"if",
"(",
"response",
".",
"status",
">=",
"400",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"response",
".",
"status",
"}",
"${",
"response",
".",
"url",
"}",
"`",
")",
";",
"if",
"(",
"!",
"document",
".",
"documentElement",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"response",
".",
"url",
"}",
"`",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"// Handle meta refresh. Automatically reloads new location and counts",
"// as a redirect.",
"//",
"// If you need to check the page before refresh takes place, use this:",
"// browser.wait({",
"// function: function() {",
"// return browser.query('meta[http-equiv=\"refresh\"]');",
"// }",
"// });",
"const",
"refresh",
"=",
"getMetaRefresh",
"(",
"document",
")",
";",
"if",
"(",
"refresh",
")",
"{",
"const",
"{",
"refreshTimeout",
"}",
"=",
"refresh",
";",
"const",
"{",
"refreshURL",
"}",
"=",
"refresh",
";",
"window",
".",
"_eventQueue",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"// Allow completion function to run",
"window",
".",
"_eventQueue",
".",
"enqueue",
"(",
"function",
"(",
")",
"{",
"window",
".",
"_eventQueue",
".",
"enqueue",
"(",
"function",
"(",
")",
"{",
"// Count a meta-refresh in the redirects count.",
"history",
".",
"replace",
"(",
"refreshURL",
")",
";",
"// This results in a new window getting loaded",
"const",
"newWindow",
"=",
"history",
".",
"current",
".",
"window",
";",
"newWindow",
".",
"addEventListener",
"(",
"'load'",
",",
"function",
"(",
")",
"{",
"++",
"newWindow",
".",
"_request",
".",
"_redirectCount",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
",",
"refreshTimeout",
"*",
"1000",
")",
";",
"}",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"browser",
".",
"emit",
"(",
"'error'",
",",
"error",
")",
";",
"}",
")",
".",
"then",
"(",
"done",
")",
";",
"}"
] | Parse HTML response and setup document | [
"Parse",
"HTML",
"response",
"and",
"setup",
"document"
] | 72e365ebd823e392ab48ccc6c19032ce7819c79f | https://github.com/assaf/zombie/blob/72e365ebd823e392ab48ccc6c19032ce7819c79f/src/document.js#L630-L692 |
8,710 | AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | expandQNames | function expandQNames(xpath) {
var namespaces = constants.XmlNamespaces;
var pathParts = xpath.split('/');
for (var i=0; i < pathParts.length; i++) {
if (pathParts[i].indexOf(':') !== -1) {
var QNameParts = pathParts[i].split(':');
if (QNameParts.length !== 2) {
throw new Error('Unable to parse XPath string : ' + xpath + ' : with QName : ' + pathParts[i]);
}
var expandedPath = XPATH_PATH_TEMPLATE.replace('LOCAL_NAME', QNameParts[1]);
expandedPath = expandedPath.replace('NAMESPACE', namespaces[QNameParts[0]]);
pathParts[i] = expandedPath;
}
}
return pathParts.join('/');
} | javascript | function expandQNames(xpath) {
var namespaces = constants.XmlNamespaces;
var pathParts = xpath.split('/');
for (var i=0; i < pathParts.length; i++) {
if (pathParts[i].indexOf(':') !== -1) {
var QNameParts = pathParts[i].split(':');
if (QNameParts.length !== 2) {
throw new Error('Unable to parse XPath string : ' + xpath + ' : with QName : ' + pathParts[i]);
}
var expandedPath = XPATH_PATH_TEMPLATE.replace('LOCAL_NAME', QNameParts[1]);
expandedPath = expandedPath.replace('NAMESPACE', namespaces[QNameParts[0]]);
pathParts[i] = expandedPath;
}
}
return pathParts.join('/');
} | [
"function",
"expandQNames",
"(",
"xpath",
")",
"{",
"var",
"namespaces",
"=",
"constants",
".",
"XmlNamespaces",
";",
"var",
"pathParts",
"=",
"xpath",
".",
"split",
"(",
"'/'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pathParts",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"pathParts",
"[",
"i",
"]",
".",
"indexOf",
"(",
"':'",
")",
"!==",
"-",
"1",
")",
"{",
"var",
"QNameParts",
"=",
"pathParts",
"[",
"i",
"]",
".",
"split",
"(",
"':'",
")",
";",
"if",
"(",
"QNameParts",
".",
"length",
"!==",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unable to parse XPath string : '",
"+",
"xpath",
"+",
"' : with QName : '",
"+",
"pathParts",
"[",
"i",
"]",
")",
";",
"}",
"var",
"expandedPath",
"=",
"XPATH_PATH_TEMPLATE",
".",
"replace",
"(",
"'LOCAL_NAME'",
",",
"QNameParts",
"[",
"1",
"]",
")",
";",
"expandedPath",
"=",
"expandedPath",
".",
"replace",
"(",
"'NAMESPACE'",
",",
"namespaces",
"[",
"QNameParts",
"[",
"0",
"]",
"]",
")",
";",
"pathParts",
"[",
"i",
"]",
"=",
"expandedPath",
";",
"}",
"}",
"return",
"pathParts",
".",
"join",
"(",
"'/'",
")",
";",
"}"
] | The xpath implementation being used does not have a way of matching expanded namespace.
This method takes an xpath query and expands all of the namespaces involved. It then
re-writes the query in to a longer form that directory matches the correct namespaces.
@private
@static
@memberOf XmlUtil
@param {string} xpath The expath query string to expand.
@returns {string} An expanded xpath query. | [
"The",
"xpath",
"implementation",
"being",
"used",
"does",
"not",
"have",
"a",
"way",
"of",
"matching",
"expanded",
"namespace",
".",
"This",
"method",
"takes",
"an",
"xpath",
"query",
"and",
"expands",
"all",
"of",
"the",
"namespaces",
"involved",
".",
"It",
"then",
"re",
"-",
"writes",
"the",
"query",
"in",
"to",
"a",
"longer",
"form",
"that",
"directory",
"matches",
"the",
"correct",
"namespaces",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L45-L60 |
8,711 | AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | function(node) {
var doc = '';
var sibling = node.firstChild;
var serializer = new XMLSerializer();
while (sibling) {
if (this.isElementNode(sibling)) {
doc += serializer.serializeToString(sibling);
}
sibling = sibling.nextSibling;
}
return doc !== '' ? doc : null;
} | javascript | function(node) {
var doc = '';
var sibling = node.firstChild;
var serializer = new XMLSerializer();
while (sibling) {
if (this.isElementNode(sibling)) {
doc += serializer.serializeToString(sibling);
}
sibling = sibling.nextSibling;
}
return doc !== '' ? doc : null;
} | [
"function",
"(",
"node",
")",
"{",
"var",
"doc",
"=",
"''",
";",
"var",
"sibling",
"=",
"node",
".",
"firstChild",
";",
"var",
"serializer",
"=",
"new",
"XMLSerializer",
"(",
")",
";",
"while",
"(",
"sibling",
")",
"{",
"if",
"(",
"this",
".",
"isElementNode",
"(",
"sibling",
")",
")",
"{",
"doc",
"+=",
"serializer",
".",
"serializeToString",
"(",
"sibling",
")",
";",
"}",
"sibling",
"=",
"sibling",
".",
"nextSibling",
";",
"}",
"return",
"doc",
"!==",
"''",
"?",
"doc",
":",
"null",
";",
"}"
] | Given a dom node serializes all immediate children that are xml elements.
@static
@memberOf XmlUtil
@param {object} node An xml dom node.
@return {string} Serialized xml. | [
"Given",
"a",
"dom",
"node",
"serializes",
"all",
"immediate",
"children",
"that",
"are",
"xml",
"elements",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L84-L97 |
|
8,712 | AzureAD/azure-activedirectory-library-for-nodejs | lib/xmlutil.js | function(node) {
var sibling = node.firstChild;
while (sibling && !sibling.data) {
sibling = sibling.nextSibling;
}
return sibling.data ? sibling.data : null;
} | javascript | function(node) {
var sibling = node.firstChild;
while (sibling && !sibling.data) {
sibling = sibling.nextSibling;
}
return sibling.data ? sibling.data : null;
} | [
"function",
"(",
"node",
")",
"{",
"var",
"sibling",
"=",
"node",
".",
"firstChild",
";",
"while",
"(",
"sibling",
"&&",
"!",
"sibling",
".",
"data",
")",
"{",
"sibling",
"=",
"sibling",
".",
"nextSibling",
";",
"}",
"return",
"sibling",
".",
"data",
"?",
"sibling",
".",
"data",
":",
"null",
";",
"}"
] | Given an xmldom node this function returns any text data contained within.
@static
@memberOf XmlUtil
@param {object} node An xmldom node from which the data should be extracted.
@return {string} Any data found within the element or null if none is found. | [
"Given",
"an",
"xmldom",
"node",
"this",
"function",
"returns",
"any",
"text",
"data",
"contained",
"within",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/xmlutil.js#L117-L124 |
|
8,713 | AzureAD/azure-activedirectory-library-for-nodejs | lib/authority.js | Authority | function Authority(authorityUrl, validateAuthority) {
this._log = null;
this._url = url.parse(authorityUrl);
this._validateAuthorityUrl();
this._validated = !validateAuthority;
this._host = null;
this._tenant = null;
this._parseAuthority();
this._authorizationEndpoint = null;
this._tokenEndpoint = null;
this._deviceCodeEndpoint = null;
this._isAdfsAuthority = (this._tenant.toLowerCase() === "adfs");
} | javascript | function Authority(authorityUrl, validateAuthority) {
this._log = null;
this._url = url.parse(authorityUrl);
this._validateAuthorityUrl();
this._validated = !validateAuthority;
this._host = null;
this._tenant = null;
this._parseAuthority();
this._authorizationEndpoint = null;
this._tokenEndpoint = null;
this._deviceCodeEndpoint = null;
this._isAdfsAuthority = (this._tenant.toLowerCase() === "adfs");
} | [
"function",
"Authority",
"(",
"authorityUrl",
",",
"validateAuthority",
")",
"{",
"this",
".",
"_log",
"=",
"null",
";",
"this",
".",
"_url",
"=",
"url",
".",
"parse",
"(",
"authorityUrl",
")",
";",
"this",
".",
"_validateAuthorityUrl",
"(",
")",
";",
"this",
".",
"_validated",
"=",
"!",
"validateAuthority",
";",
"this",
".",
"_host",
"=",
"null",
";",
"this",
".",
"_tenant",
"=",
"null",
";",
"this",
".",
"_parseAuthority",
"(",
")",
";",
"this",
".",
"_authorizationEndpoint",
"=",
"null",
";",
"this",
".",
"_tokenEndpoint",
"=",
"null",
";",
"this",
".",
"_deviceCodeEndpoint",
"=",
"null",
";",
"this",
".",
"_isAdfsAuthority",
"=",
"(",
"this",
".",
"_tenant",
".",
"toLowerCase",
"(",
")",
"===",
"\"adfs\"",
")",
";",
"}"
] | Constructs an Authority object with a specific authority URL.
@private
@constructor
@param {string} authorityUrl A URL that identifies a token authority.
@param {bool} validateAuthority Indicates whether the Authority url should be validated as an actual AAD
authority. The default is true. | [
"Constructs",
"an",
"Authority",
"object",
"with",
"a",
"specific",
"authority",
"URL",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/authority.js#L39-L53 |
8,714 | AzureAD/azure-activedirectory-library-for-nodejs | lib/log.js | function(options) {
if (!options) {
options = {};
}
if (options.log) {
if (!_.isFunction(options.log)) {
throw new Error('setLogOptions expects the log key in the options parameter to be a function');
}
} else {
// if no log function was passed set it to a default no op function.
options.log = function() {};
}
if (options.level) {
var level = options.level;
if (level < 0 || level > 3) {
throw new Error('setLogOptions expects the level key to be in the range 0 to 3 inclusive');
}
} else {
options.level = this.LOGGING_LEVEL.ERROR;
}
if (options.loggingWithPII != true) {
options.loggingWithPII = false;
}
this.LogOptions = options;
} | javascript | function(options) {
if (!options) {
options = {};
}
if (options.log) {
if (!_.isFunction(options.log)) {
throw new Error('setLogOptions expects the log key in the options parameter to be a function');
}
} else {
// if no log function was passed set it to a default no op function.
options.log = function() {};
}
if (options.level) {
var level = options.level;
if (level < 0 || level > 3) {
throw new Error('setLogOptions expects the level key to be in the range 0 to 3 inclusive');
}
} else {
options.level = this.LOGGING_LEVEL.ERROR;
}
if (options.loggingWithPII != true) {
options.loggingWithPII = false;
}
this.LogOptions = options;
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"options",
".",
"log",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isFunction",
"(",
"options",
".",
"log",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'setLogOptions expects the log key in the options parameter to be a function'",
")",
";",
"}",
"}",
"else",
"{",
"// if no log function was passed set it to a default no op function.",
"options",
".",
"log",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}",
"if",
"(",
"options",
".",
"level",
")",
"{",
"var",
"level",
"=",
"options",
".",
"level",
";",
"if",
"(",
"level",
"<",
"0",
"||",
"level",
">",
"3",
")",
"{",
"throw",
"new",
"Error",
"(",
"'setLogOptions expects the level key to be in the range 0 to 3 inclusive'",
")",
";",
"}",
"}",
"else",
"{",
"options",
".",
"level",
"=",
"this",
".",
"LOGGING_LEVEL",
".",
"ERROR",
";",
"}",
"if",
"(",
"options",
".",
"loggingWithPII",
"!=",
"true",
")",
"{",
"options",
".",
"loggingWithPII",
"=",
"false",
";",
"}",
"this",
".",
"LogOptions",
"=",
"options",
";",
"}"
] | Sets global logging options for ADAL.
@param {LoggingOptions} options | [
"Sets",
"global",
"logging",
"options",
"for",
"ADAL",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/log.js#L72-L100 |
|
8,715 | AzureAD/azure-activedirectory-library-for-nodejs | lib/self-signed-jwt.js | SelfSignedJwt | function SelfSignedJwt(callContext, authority, clientId) {
this._log = new Logger('SelfSignedJwt', callContext._logContext);
this._callContext = callContext;
this._authority = authority;
this._tokenEndpoint = authority.tokenEndpoint;
this._clientId = clientId;
} | javascript | function SelfSignedJwt(callContext, authority, clientId) {
this._log = new Logger('SelfSignedJwt', callContext._logContext);
this._callContext = callContext;
this._authority = authority;
this._tokenEndpoint = authority.tokenEndpoint;
this._clientId = clientId;
} | [
"function",
"SelfSignedJwt",
"(",
"callContext",
",",
"authority",
",",
"clientId",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'SelfSignedJwt'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_authority",
"=",
"authority",
";",
"this",
".",
"_tokenEndpoint",
"=",
"authority",
".",
"tokenEndpoint",
";",
"this",
".",
"_clientId",
"=",
"clientId",
";",
"}"
] | Constructs a new SelfSignedJwt object.
@param {object} callContext Context specific to this token request.
@param {Authority} authority The authority to be used as the JWT audience.
@param {string} clientId The client id of the calling app. | [
"Constructs",
"a",
"new",
"SelfSignedJwt",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/self-signed-jwt.js#L47-L54 |
8,716 | AzureAD/azure-activedirectory-library-for-nodejs | lib/cache-driver.js | CacheDriver | function CacheDriver(callContext, authority, resource, clientId, cache, refreshFunction) {
this._callContext = callContext;
this._log = new Logger('CacheDriver', callContext._logContext);
this._authority = authority;
this._resource = resource;
this._clientId = clientId;
this._cache = cache || nopCache;
this._refreshFunction = refreshFunction;
} | javascript | function CacheDriver(callContext, authority, resource, clientId, cache, refreshFunction) {
this._callContext = callContext;
this._log = new Logger('CacheDriver', callContext._logContext);
this._authority = authority;
this._resource = resource;
this._clientId = clientId;
this._cache = cache || nopCache;
this._refreshFunction = refreshFunction;
} | [
"function",
"CacheDriver",
"(",
"callContext",
",",
"authority",
",",
"resource",
",",
"clientId",
",",
"cache",
",",
"refreshFunction",
")",
"{",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'CacheDriver'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_authority",
"=",
"authority",
";",
"this",
".",
"_resource",
"=",
"resource",
";",
"this",
".",
"_clientId",
"=",
"clientId",
";",
"this",
".",
"_cache",
"=",
"cache",
"||",
"nopCache",
";",
"this",
".",
"_refreshFunction",
"=",
"refreshFunction",
";",
"}"
] | This is the callback that is passed to all acquireToken variants below.
@callback RefreshEntryFunction
@memberOf CacheDriver
@param {object} tokenResponse A token response to refresh.
@param {string} [resource] The resource for which to obtain the token if it is different from the original token.
@param {AcquireTokenCallback} callback Called on completion with an error or a new entry to add to the cache.
Constructs a new CacheDriver object.
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {string} authority
@param {TokenCache} [cache] A token cache to use. If none is passed then the CacheDriver instance
will not cache.
@param {RefreshEntryFunction} refreshFunction | [
"This",
"is",
"the",
"callback",
"that",
"is",
"passed",
"to",
"all",
"acquireToken",
"variants",
"below",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/cache-driver.js#L116-L124 |
8,717 | AzureAD/azure-activedirectory-library-for-nodejs | lib/oauth2client.js | OAuth2Client | function OAuth2Client(callContext, authority) {
this._tokenEndpoint = authority.tokenEndpoint;
this._deviceCodeEndpoint = authority.deviceCodeEndpoint;
this._log = new Logger('OAuth2Client', callContext._logContext);
this._callContext = callContext;
this._cancelPollingRequest = false;
} | javascript | function OAuth2Client(callContext, authority) {
this._tokenEndpoint = authority.tokenEndpoint;
this._deviceCodeEndpoint = authority.deviceCodeEndpoint;
this._log = new Logger('OAuth2Client', callContext._logContext);
this._callContext = callContext;
this._cancelPollingRequest = false;
} | [
"function",
"OAuth2Client",
"(",
"callContext",
",",
"authority",
")",
"{",
"this",
".",
"_tokenEndpoint",
"=",
"authority",
".",
"tokenEndpoint",
";",
"this",
".",
"_deviceCodeEndpoint",
"=",
"authority",
".",
"deviceCodeEndpoint",
";",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'OAuth2Client'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_cancelPollingRequest",
"=",
"false",
";",
"}"
] | Constructs an instances of OAuth2Client
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {string|url} authority An url that points to an authority. | [
"Constructs",
"an",
"instances",
"of",
"OAuth2Client"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/oauth2client.js#L72-L79 |
8,718 | AzureAD/azure-activedirectory-library-for-nodejs | lib/oauth2client.js | function (response, body) {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(body);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
callback(null, tokenResponse);
} | javascript | function (response, body) {
var tokenResponse;
try {
tokenResponse = self._handlePollingResponse(body);
} catch (e) {
self._log.error('Error validating get token response', e, true);
callback(null, e);
return;
}
callback(null, tokenResponse);
} | [
"function",
"(",
"response",
",",
"body",
")",
"{",
"var",
"tokenResponse",
";",
"try",
"{",
"tokenResponse",
"=",
"self",
".",
"_handlePollingResponse",
"(",
"body",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"self",
".",
"_log",
".",
"error",
"(",
"'Error validating get token response'",
",",
"e",
",",
"true",
")",
";",
"callback",
"(",
"null",
",",
"e",
")",
";",
"return",
";",
"}",
"callback",
"(",
"null",
",",
"tokenResponse",
")",
";",
"}"
] | success response callback | [
"success",
"response",
"callback"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/oauth2client.js#L420-L431 |
|
8,719 | AzureAD/azure-activedirectory-library-for-nodejs | lib/token-request.js | TokenRequest | function TokenRequest(callContext, authenticationContext, clientId, resource, redirectUri) {
this._log = new Logger('TokenRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
this._redirectUri = redirectUri;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
this._userRealm = null;
this._pollingClient = {};
} | javascript | function TokenRequest(callContext, authenticationContext, clientId, resource, redirectUri) {
this._log = new Logger('TokenRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
this._redirectUri = redirectUri;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
this._userRealm = null;
this._pollingClient = {};
} | [
"function",
"TokenRequest",
"(",
"callContext",
",",
"authenticationContext",
",",
"clientId",
",",
"resource",
",",
"redirectUri",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'TokenRequest'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_authenticationContext",
"=",
"authenticationContext",
";",
"this",
".",
"_resource",
"=",
"resource",
";",
"this",
".",
"_clientId",
"=",
"clientId",
";",
"this",
".",
"_redirectUri",
"=",
"redirectUri",
";",
"// This should be set at the beginning of getToken",
"// functions that have a userId.",
"this",
".",
"_userId",
"=",
"null",
";",
"this",
".",
"_userRealm",
"=",
"null",
";",
"this",
".",
"_pollingClient",
"=",
"{",
"}",
";",
"}"
] | Constructs a new TokenRequest object.
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {AuthenticationContext} authenticationContext
@param {string} resource
@param {string} clientId
@param {string} redirectUri | [
"Constructs",
"a",
"new",
"TokenRequest",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/token-request.js#L51-L65 |
8,720 | AzureAD/azure-activedirectory-library-for-nodejs | lib/user-realm.js | UserRealm | function UserRealm(callContext, userPrinciple, authority) {
this._log = new Logger('UserRealm', callContext._logContext);
this._callContext = callContext;
this._apiVersion = '1.0';
this._federationProtocol = null;
this._accountType = null;
this._federationMetadataUrl = null;
this._federationActiveAuthUrl = null;
this._userPrinciple = userPrinciple;
this._authority = authority;
} | javascript | function UserRealm(callContext, userPrinciple, authority) {
this._log = new Logger('UserRealm', callContext._logContext);
this._callContext = callContext;
this._apiVersion = '1.0';
this._federationProtocol = null;
this._accountType = null;
this._federationMetadataUrl = null;
this._federationActiveAuthUrl = null;
this._userPrinciple = userPrinciple;
this._authority = authority;
} | [
"function",
"UserRealm",
"(",
"callContext",
",",
"userPrinciple",
",",
"authority",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'UserRealm'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_apiVersion",
"=",
"'1.0'",
";",
"this",
".",
"_federationProtocol",
"=",
"null",
";",
"this",
".",
"_accountType",
"=",
"null",
";",
"this",
".",
"_federationMetadataUrl",
"=",
"null",
";",
"this",
".",
"_federationActiveAuthUrl",
"=",
"null",
";",
"this",
".",
"_userPrinciple",
"=",
"userPrinciple",
";",
"this",
".",
"_authority",
"=",
"authority",
";",
"}"
] | Create a new UserRealm object
@private
@constructor
@param {object} callContext Contains any context information that applies to the request.
@param {string} userPrinciple The username for which a realm needs to be discovered.
@param {string} authority The string url of the authority that owns the userPrinciple. | [
"Create",
"a",
"new",
"UserRealm",
"object"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/user-realm.js#L45-L55 |
8,721 | AzureAD/azure-activedirectory-library-for-nodejs | lib/wstrust-request.js | WSTrustRequest | function WSTrustRequest(callContext, wstrustEndpointUrl, appliesTo, wstrustEndpointVersion) {
this._log = new Logger('WSTrustRequest', callContext._logContext);
this._callContext = callContext;
this._wstrustEndpointUrl = wstrustEndpointUrl;
this._appliesTo = appliesTo;
this._wstrustEndpointVersion = wstrustEndpointVersion;
} | javascript | function WSTrustRequest(callContext, wstrustEndpointUrl, appliesTo, wstrustEndpointVersion) {
this._log = new Logger('WSTrustRequest', callContext._logContext);
this._callContext = callContext;
this._wstrustEndpointUrl = wstrustEndpointUrl;
this._appliesTo = appliesTo;
this._wstrustEndpointVersion = wstrustEndpointVersion;
} | [
"function",
"WSTrustRequest",
"(",
"callContext",
",",
"wstrustEndpointUrl",
",",
"appliesTo",
",",
"wstrustEndpointVersion",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'WSTrustRequest'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_wstrustEndpointUrl",
"=",
"wstrustEndpointUrl",
";",
"this",
".",
"_appliesTo",
"=",
"appliesTo",
";",
"this",
".",
"_wstrustEndpointVersion",
"=",
"wstrustEndpointVersion",
";",
"}"
] | Creates a new instance of WSTrustRequest
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {string} wstrustEndpointUrl An STS WS-Trust soap endpoint.
@param {string} appliesTo A URI that identifies a service for which the a token is to be obtained. | [
"Creates",
"a",
"new",
"instance",
"of",
"WSTrustRequest"
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/wstrust-request.js#L42-L48 |
8,722 | AzureAD/azure-activedirectory-library-for-nodejs | lib/wstrust-request.js | _datePlusMinutes | function _datePlusMinutes(date, minutes) {
var minutesInMilliSeconds = minutes * 60 * 1000;
var epochTime = date.getTime() + minutesInMilliSeconds;
return new Date(epochTime);
} | javascript | function _datePlusMinutes(date, minutes) {
var minutesInMilliSeconds = minutes * 60 * 1000;
var epochTime = date.getTime() + minutesInMilliSeconds;
return new Date(epochTime);
} | [
"function",
"_datePlusMinutes",
"(",
"date",
",",
"minutes",
")",
"{",
"var",
"minutesInMilliSeconds",
"=",
"minutes",
"*",
"60",
"*",
"1000",
";",
"var",
"epochTime",
"=",
"date",
".",
"getTime",
"(",
")",
"+",
"minutesInMilliSeconds",
";",
"return",
"new",
"Date",
"(",
"epochTime",
")",
";",
"}"
] | Given a Date object adds the minutes parameter and returns a new Date object.
@private
@static
@memberOf WSTrustRequest
@param {Date} date A Date object.
@param {Number} minutes The number of minutes to add to the date parameter.
@returns {Date} Returns a Date object. | [
"Given",
"a",
"Date",
"object",
"adds",
"the",
"minutes",
"parameter",
"and",
"returns",
"a",
"new",
"Date",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/wstrust-request.js#L59-L63 |
8,723 | AzureAD/azure-activedirectory-library-for-nodejs | lib/util.js | createRequestOptions | function createRequestOptions(self, options) {
var defaultOptions = {}; //{ strictSSL : true };
var mergedOptions = defaultOptions;
if (options) {
_.extend(mergedOptions, options);
}
if (self._callContext.options && self._callContext.options.http) {
_.extend(mergedOptions, self._callContext.options.http);
}
addDefaultRequestHeaders(self, mergedOptions);
return mergedOptions;
} | javascript | function createRequestOptions(self, options) {
var defaultOptions = {}; //{ strictSSL : true };
var mergedOptions = defaultOptions;
if (options) {
_.extend(mergedOptions, options);
}
if (self._callContext.options && self._callContext.options.http) {
_.extend(mergedOptions, self._callContext.options.http);
}
addDefaultRequestHeaders(self, mergedOptions);
return mergedOptions;
} | [
"function",
"createRequestOptions",
"(",
"self",
",",
"options",
")",
"{",
"var",
"defaultOptions",
"=",
"{",
"}",
";",
"//{ strictSSL : true };",
"var",
"mergedOptions",
"=",
"defaultOptions",
";",
"if",
"(",
"options",
")",
"{",
"_",
".",
"extend",
"(",
"mergedOptions",
",",
"options",
")",
";",
"}",
"if",
"(",
"self",
".",
"_callContext",
".",
"options",
"&&",
"self",
".",
"_callContext",
".",
"options",
".",
"http",
")",
"{",
"_",
".",
"extend",
"(",
"mergedOptions",
",",
"self",
".",
"_callContext",
".",
"options",
".",
"http",
")",
";",
"}",
"addDefaultRequestHeaders",
"(",
"self",
",",
"mergedOptions",
")",
";",
"return",
"mergedOptions",
";",
"}"
] | Central place for housing default request options. This is a place holder
for when SSL validation is implemented an all requests are subject to that
policy.
@static
@memberOf Util
@param {object} options A set of options that will be merged with teh default options
These will override any default options.
@returns {object} Returns the merged options. | [
"Central",
"place",
"for",
"housing",
"default",
"request",
"options",
".",
"This",
"is",
"a",
"place",
"holder",
"for",
"when",
"SSL",
"validation",
"is",
"implemented",
"an",
"all",
"requests",
"are",
"subject",
"to",
"that",
"policy",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/util.js#L80-L92 |
8,724 | AzureAD/azure-activedirectory-library-for-nodejs | lib/wstrust-response.js | scrubRSTRLogMessage | function scrubRSTRLogMessage(RSTR) {
var scrubbedRSTR = null;
var singleLineRSTR = RSTR.replace(/(\r\n|\n|\r)/gm,'');
var matchResult = assertionRegEx.exec(singleLineRSTR);
if (null === matchResult) {
// No Assertion was matched so just return the RSTR as is.
scrubbedRSTR = singleLineRSTR;
} else {
var samlAssertion = matchResult[1];
var samlAssertionStartTag = matchResult[2];
scrubbedRSTR = singleLineRSTR.replace(samlAssertion, samlAssertionStartTag + 'ASSERTION CONTENTS REDACTED</saml:Assertion>');
}
return 'RSTR Response: ' + scrubbedRSTR;
} | javascript | function scrubRSTRLogMessage(RSTR) {
var scrubbedRSTR = null;
var singleLineRSTR = RSTR.replace(/(\r\n|\n|\r)/gm,'');
var matchResult = assertionRegEx.exec(singleLineRSTR);
if (null === matchResult) {
// No Assertion was matched so just return the RSTR as is.
scrubbedRSTR = singleLineRSTR;
} else {
var samlAssertion = matchResult[1];
var samlAssertionStartTag = matchResult[2];
scrubbedRSTR = singleLineRSTR.replace(samlAssertion, samlAssertionStartTag + 'ASSERTION CONTENTS REDACTED</saml:Assertion>');
}
return 'RSTR Response: ' + scrubbedRSTR;
} | [
"function",
"scrubRSTRLogMessage",
"(",
"RSTR",
")",
"{",
"var",
"scrubbedRSTR",
"=",
"null",
";",
"var",
"singleLineRSTR",
"=",
"RSTR",
".",
"replace",
"(",
"/",
"(\\r\\n|\\n|\\r)",
"/",
"gm",
",",
"''",
")",
";",
"var",
"matchResult",
"=",
"assertionRegEx",
".",
"exec",
"(",
"singleLineRSTR",
")",
";",
"if",
"(",
"null",
"===",
"matchResult",
")",
"{",
"// No Assertion was matched so just return the RSTR as is.",
"scrubbedRSTR",
"=",
"singleLineRSTR",
";",
"}",
"else",
"{",
"var",
"samlAssertion",
"=",
"matchResult",
"[",
"1",
"]",
";",
"var",
"samlAssertionStartTag",
"=",
"matchResult",
"[",
"2",
"]",
";",
"scrubbedRSTR",
"=",
"singleLineRSTR",
".",
"replace",
"(",
"samlAssertion",
",",
"samlAssertionStartTag",
"+",
"'ASSERTION CONTENTS REDACTED</saml:Assertion>'",
")",
";",
"}",
"return",
"'RSTR Response: '",
"+",
"scrubbedRSTR",
";",
"}"
] | Creates a log message that contains the RSTR scrubbed of the actual SAML assertion.
@private
@return {string} A log message. | [
"Creates",
"a",
"log",
"message",
"that",
"contains",
"the",
"RSTR",
"scrubbed",
"of",
"the",
"actual",
"SAML",
"assertion",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/wstrust-response.js#L43-L60 |
8,725 | AzureAD/azure-activedirectory-library-for-nodejs | lib/wstrust-response.js | WSTrustResponse | function WSTrustResponse(callContext, response, wstrustVersion) {
this._log = new Logger('WSTrustResponse', callContext._logContext);
this._callContext = callContext;
this._response = response;
this._dom = null;
this._errorCode = null;
this._faultMessage = null;
this._tokenType = null;
this._token = null;
this._wstrustVersion = wstrustVersion;
this._log.verbose(function(){return scrubRSTRLogMessage(response);});
} | javascript | function WSTrustResponse(callContext, response, wstrustVersion) {
this._log = new Logger('WSTrustResponse', callContext._logContext);
this._callContext = callContext;
this._response = response;
this._dom = null;
this._errorCode = null;
this._faultMessage = null;
this._tokenType = null;
this._token = null;
this._wstrustVersion = wstrustVersion;
this._log.verbose(function(){return scrubRSTRLogMessage(response);});
} | [
"function",
"WSTrustResponse",
"(",
"callContext",
",",
"response",
",",
"wstrustVersion",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'WSTrustResponse'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_response",
"=",
"response",
";",
"this",
".",
"_dom",
"=",
"null",
";",
"this",
".",
"_errorCode",
"=",
"null",
";",
"this",
".",
"_faultMessage",
"=",
"null",
";",
"this",
".",
"_tokenType",
"=",
"null",
";",
"this",
".",
"_token",
"=",
"null",
";",
"this",
".",
"_wstrustVersion",
"=",
"wstrustVersion",
";",
"this",
".",
"_log",
".",
"verbose",
"(",
"function",
"(",
")",
"{",
"return",
"scrubRSTRLogMessage",
"(",
"response",
")",
";",
"}",
")",
";",
"}"
] | Creates a new WSTrustResponse instance.
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {string} response A soap response from a WS-Trust request.
@param {sting} wstrustVersion The version for the WS-Trust request. | [
"Creates",
"a",
"new",
"WSTrustResponse",
"instance",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/wstrust-response.js#L70-L82 |
8,726 | AzureAD/azure-activedirectory-library-for-nodejs | lib/code-request.js | CodeRequest | function CodeRequest(callContext, authenticationContext, clientId, resource) {
this._log = new Logger('DeviceCodeRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
} | javascript | function CodeRequest(callContext, authenticationContext, clientId, resource) {
this._log = new Logger('DeviceCodeRequest', callContext._logContext);
this._callContext = callContext;
this._authenticationContext = authenticationContext;
this._resource = resource;
this._clientId = clientId;
// This should be set at the beginning of getToken
// functions that have a userId.
this._userId = null;
} | [
"function",
"CodeRequest",
"(",
"callContext",
",",
"authenticationContext",
",",
"clientId",
",",
"resource",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'DeviceCodeRequest'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_authenticationContext",
"=",
"authenticationContext",
";",
"this",
".",
"_resource",
"=",
"resource",
";",
"this",
".",
"_clientId",
"=",
"clientId",
";",
"// This should be set at the beginning of getToken",
"// functions that have a userId.",
"this",
".",
"_userId",
"=",
"null",
";",
"}"
] | Constructs a new CodeRequest object.
@constructor
@private
@param {object} callContext Contains any context information that applies to the request.
@param {AuthenticationContext} authenticationContext
@param {string} resource
@param {string} clientId
TODO: probably need to modify the parameter list. | [
"Constructs",
"a",
"new",
"CodeRequest",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/code-request.js#L43-L53 |
8,727 | AzureAD/azure-activedirectory-library-for-nodejs | lib/mex.js | Mex | function Mex(callContext, url) {
this._log = new Logger('MEX', callContext._logContext);
this._callContext = callContext;
this._url = url;
this._dom = null;
this._mexDoc = null;
this._usernamePasswordPolicy = {};
this._log.verbose('Mex created');
this._log.verbose('Mex created with url: ' + url, true);
} | javascript | function Mex(callContext, url) {
this._log = new Logger('MEX', callContext._logContext);
this._callContext = callContext;
this._url = url;
this._dom = null;
this._mexDoc = null;
this._usernamePasswordPolicy = {};
this._log.verbose('Mex created');
this._log.verbose('Mex created with url: ' + url, true);
} | [
"function",
"Mex",
"(",
"callContext",
",",
"url",
")",
"{",
"this",
".",
"_log",
"=",
"new",
"Logger",
"(",
"'MEX'",
",",
"callContext",
".",
"_logContext",
")",
";",
"this",
".",
"_callContext",
"=",
"callContext",
";",
"this",
".",
"_url",
"=",
"url",
";",
"this",
".",
"_dom",
"=",
"null",
";",
"this",
".",
"_mexDoc",
"=",
"null",
";",
"this",
".",
"_usernamePasswordPolicy",
"=",
"{",
"}",
";",
"this",
".",
"_log",
".",
"verbose",
"(",
"'Mex created'",
")",
";",
"this",
".",
"_log",
".",
"verbose",
"(",
"'Mex created with url: '",
"+",
"url",
",",
"true",
")",
";",
"}"
] | Create a new Mex object.
@private
@constructor
@param {object} callContext Contains any context information that applies to the request.
@param {string} url The url of the mex endpoint. | [
"Create",
"a",
"new",
"Mex",
"object",
"."
] | 89ccef01b565d9f56a6f702f835aa2f9d1230aaf | https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/blob/89ccef01b565d9f56a6f702f835aa2f9d1230aaf/lib/mex.js#L43-L52 |
8,728 | stomp-js/stompjs | spec/unit/frame.spec.js | function(data, escapeHeaderValues) {
const onFrame = jasmine.createSpy('onFrame');
const onIncomingPing = jasmine.createSpy('onIncomingPing');
const parser = new StompJs.Parser(onFrame, onIncomingPing);
parser.parseChunk(data);
const rawFrame = onFrame.calls.first().args[0];
return StompJs.FrameImpl.fromRawFrame(rawFrame, escapeHeaderValues);
} | javascript | function(data, escapeHeaderValues) {
const onFrame = jasmine.createSpy('onFrame');
const onIncomingPing = jasmine.createSpy('onIncomingPing');
const parser = new StompJs.Parser(onFrame, onIncomingPing);
parser.parseChunk(data);
const rawFrame = onFrame.calls.first().args[0];
return StompJs.FrameImpl.fromRawFrame(rawFrame, escapeHeaderValues);
} | [
"function",
"(",
"data",
",",
"escapeHeaderValues",
")",
"{",
"const",
"onFrame",
"=",
"jasmine",
".",
"createSpy",
"(",
"'onFrame'",
")",
";",
"const",
"onIncomingPing",
"=",
"jasmine",
".",
"createSpy",
"(",
"'onIncomingPing'",
")",
";",
"const",
"parser",
"=",
"new",
"StompJs",
".",
"Parser",
"(",
"onFrame",
",",
"onIncomingPing",
")",
";",
"parser",
".",
"parseChunk",
"(",
"data",
")",
";",
"const",
"rawFrame",
"=",
"onFrame",
".",
"calls",
".",
"first",
"(",
")",
".",
"args",
"[",
"0",
"]",
";",
"return",
"StompJs",
".",
"FrameImpl",
".",
"fromRawFrame",
"(",
"rawFrame",
",",
"escapeHeaderValues",
")",
";",
"}"
] | un-marshall a data chunk, for ease of matching body is converted to string | [
"un",
"-",
"marshall",
"a",
"data",
"chunk",
"for",
"ease",
"of",
"matching",
"body",
"is",
"converted",
"to",
"string"
] | f11ad889211b9a8bd5c90d7309a23b832e1b60af | https://github.com/stomp-js/stompjs/blob/f11ad889211b9a8bd5c90d7309a23b832e1b60af/spec/unit/frame.spec.js#L4-L13 |
|
8,729 | eBay/ebayui-core | src/components/ebay-dialog/index.js | trap | function trap(opts) {
const { isTrapped: wasTrapped, restoreTrap } = this;
const isTrapped = this.isTrapped = this.state.open;
const isFirstRender = (opts && opts.firstRender);
const wasToggled = isTrapped !== wasTrapped;
const focusEl = (this.state.focus && document.getElementById(this.state.focus)) || this.closeEl;
if (restoreTrap || (isTrapped && !wasTrapped)) {
screenReaderTrap.trap(this.windowEl);
keyboardTrap.trap(this.windowEl);
}
// Ensure focus is set and body scroll prevented on initial render.
if (isFirstRender && isTrapped) {
focusEl.focus();
bodyScroll.prevent();
}
if (wasToggled) {
cancelAsync.call(this);
const onFinishTransition = () => {
this.cancelTransition = undefined;
if (isTrapped) {
focusEl.focus();
emitAndFire(this, 'dialog-show');
} else {
bodyScroll.restore();
emitAndFire(this, 'dialog-close');
// Reset dialog scroll position lazily to avoid jank.
// Note since the dialog is not in the dom at this point none of the scroll methods will work.
this.cancelScrollReset = setTimeout(() => {
this.dialogEl.parentNode.replaceChild(this.dialogEl, this.dialogEl);
this.cancelScrollReset = undefined;
}, 20);
}
};
if (isTrapped) {
if (!isFirstRender) {
bodyScroll.prevent();
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--show',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.removeAttribute('hidden');
} else {
if (!isFirstRender) {
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--hide',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.setAttribute('hidden', '');
}
}
} | javascript | function trap(opts) {
const { isTrapped: wasTrapped, restoreTrap } = this;
const isTrapped = this.isTrapped = this.state.open;
const isFirstRender = (opts && opts.firstRender);
const wasToggled = isTrapped !== wasTrapped;
const focusEl = (this.state.focus && document.getElementById(this.state.focus)) || this.closeEl;
if (restoreTrap || (isTrapped && !wasTrapped)) {
screenReaderTrap.trap(this.windowEl);
keyboardTrap.trap(this.windowEl);
}
// Ensure focus is set and body scroll prevented on initial render.
if (isFirstRender && isTrapped) {
focusEl.focus();
bodyScroll.prevent();
}
if (wasToggled) {
cancelAsync.call(this);
const onFinishTransition = () => {
this.cancelTransition = undefined;
if (isTrapped) {
focusEl.focus();
emitAndFire(this, 'dialog-show');
} else {
bodyScroll.restore();
emitAndFire(this, 'dialog-close');
// Reset dialog scroll position lazily to avoid jank.
// Note since the dialog is not in the dom at this point none of the scroll methods will work.
this.cancelScrollReset = setTimeout(() => {
this.dialogEl.parentNode.replaceChild(this.dialogEl, this.dialogEl);
this.cancelScrollReset = undefined;
}, 20);
}
};
if (isTrapped) {
if (!isFirstRender) {
bodyScroll.prevent();
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--show',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.removeAttribute('hidden');
} else {
if (!isFirstRender) {
this.cancelTransition = transition({
el: this.dialogEl,
className: 'dialog--hide',
waitFor: this.transitionEls
}, onFinishTransition);
}
this.dialogEl.setAttribute('hidden', '');
}
}
} | [
"function",
"trap",
"(",
"opts",
")",
"{",
"const",
"{",
"isTrapped",
":",
"wasTrapped",
",",
"restoreTrap",
"}",
"=",
"this",
";",
"const",
"isTrapped",
"=",
"this",
".",
"isTrapped",
"=",
"this",
".",
"state",
".",
"open",
";",
"const",
"isFirstRender",
"=",
"(",
"opts",
"&&",
"opts",
".",
"firstRender",
")",
";",
"const",
"wasToggled",
"=",
"isTrapped",
"!==",
"wasTrapped",
";",
"const",
"focusEl",
"=",
"(",
"this",
".",
"state",
".",
"focus",
"&&",
"document",
".",
"getElementById",
"(",
"this",
".",
"state",
".",
"focus",
")",
")",
"||",
"this",
".",
"closeEl",
";",
"if",
"(",
"restoreTrap",
"||",
"(",
"isTrapped",
"&&",
"!",
"wasTrapped",
")",
")",
"{",
"screenReaderTrap",
".",
"trap",
"(",
"this",
".",
"windowEl",
")",
";",
"keyboardTrap",
".",
"trap",
"(",
"this",
".",
"windowEl",
")",
";",
"}",
"// Ensure focus is set and body scroll prevented on initial render.",
"if",
"(",
"isFirstRender",
"&&",
"isTrapped",
")",
"{",
"focusEl",
".",
"focus",
"(",
")",
";",
"bodyScroll",
".",
"prevent",
"(",
")",
";",
"}",
"if",
"(",
"wasToggled",
")",
"{",
"cancelAsync",
".",
"call",
"(",
"this",
")",
";",
"const",
"onFinishTransition",
"=",
"(",
")",
"=>",
"{",
"this",
".",
"cancelTransition",
"=",
"undefined",
";",
"if",
"(",
"isTrapped",
")",
"{",
"focusEl",
".",
"focus",
"(",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'dialog-show'",
")",
";",
"}",
"else",
"{",
"bodyScroll",
".",
"restore",
"(",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'dialog-close'",
")",
";",
"// Reset dialog scroll position lazily to avoid jank.",
"// Note since the dialog is not in the dom at this point none of the scroll methods will work.",
"this",
".",
"cancelScrollReset",
"=",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"this",
".",
"dialogEl",
".",
"parentNode",
".",
"replaceChild",
"(",
"this",
".",
"dialogEl",
",",
"this",
".",
"dialogEl",
")",
";",
"this",
".",
"cancelScrollReset",
"=",
"undefined",
";",
"}",
",",
"20",
")",
";",
"}",
"}",
";",
"if",
"(",
"isTrapped",
")",
"{",
"if",
"(",
"!",
"isFirstRender",
")",
"{",
"bodyScroll",
".",
"prevent",
"(",
")",
";",
"this",
".",
"cancelTransition",
"=",
"transition",
"(",
"{",
"el",
":",
"this",
".",
"dialogEl",
",",
"className",
":",
"'dialog--show'",
",",
"waitFor",
":",
"this",
".",
"transitionEls",
"}",
",",
"onFinishTransition",
")",
";",
"}",
"this",
".",
"dialogEl",
".",
"removeAttribute",
"(",
"'hidden'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"isFirstRender",
")",
"{",
"this",
".",
"cancelTransition",
"=",
"transition",
"(",
"{",
"el",
":",
"this",
".",
"dialogEl",
",",
"className",
":",
"'dialog--hide'",
",",
"waitFor",
":",
"this",
".",
"transitionEls",
"}",
",",
"onFinishTransition",
")",
";",
"}",
"this",
".",
"dialogEl",
".",
"setAttribute",
"(",
"'hidden'",
",",
"''",
")",
";",
"}",
"}",
"}"
] | Ensures that if a component is supposed to be trapped that this is
trapped after rendering. | [
"Ensures",
"that",
"if",
"a",
"component",
"is",
"supposed",
"to",
"be",
"trapped",
"that",
"this",
"is",
"trapped",
"after",
"rendering",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-dialog/index.js#L76-L138 |
8,730 | eBay/ebayui-core | src/components/ebay-dialog/index.js | release | function release() {
if (this.isTrapped) {
this.restoreTrap = this.state.open;
screenReaderTrap.untrap(this.windowEl);
keyboardTrap.untrap(this.windowEl);
} else {
this.restoreTrap = false;
}
} | javascript | function release() {
if (this.isTrapped) {
this.restoreTrap = this.state.open;
screenReaderTrap.untrap(this.windowEl);
keyboardTrap.untrap(this.windowEl);
} else {
this.restoreTrap = false;
}
} | [
"function",
"release",
"(",
")",
"{",
"if",
"(",
"this",
".",
"isTrapped",
")",
"{",
"this",
".",
"restoreTrap",
"=",
"this",
".",
"state",
".",
"open",
";",
"screenReaderTrap",
".",
"untrap",
"(",
"this",
".",
"windowEl",
")",
";",
"keyboardTrap",
".",
"untrap",
"(",
"this",
".",
"windowEl",
")",
";",
"}",
"else",
"{",
"this",
".",
"restoreTrap",
"=",
"false",
";",
"}",
"}"
] | Releases the trap before each render and on destroy so
that Marko can update normally without the inserted dom nodes. | [
"Releases",
"the",
"trap",
"before",
"each",
"render",
"and",
"on",
"destroy",
"so",
"that",
"Marko",
"can",
"update",
"normally",
"without",
"the",
"inserted",
"dom",
"nodes",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-dialog/index.js#L144-L152 |
8,731 | eBay/ebayui-core | src/components/ebay-pagination/index.js | handlePageClick | function handlePageClick(originalEvent) {
const target = originalEvent.target;
emitAndFire(this, 'pagination-select', {
originalEvent,
el: target,
value: target.innerText
});
} | javascript | function handlePageClick(originalEvent) {
const target = originalEvent.target;
emitAndFire(this, 'pagination-select', {
originalEvent,
el: target,
value: target.innerText
});
} | [
"function",
"handlePageClick",
"(",
"originalEvent",
")",
"{",
"const",
"target",
"=",
"originalEvent",
".",
"target",
";",
"emitAndFire",
"(",
"this",
",",
"'pagination-select'",
",",
"{",
"originalEvent",
",",
"el",
":",
"target",
",",
"value",
":",
"target",
".",
"innerText",
"}",
")",
";",
"}"
] | Handle normal mouse click for item, next page and previous page respectively.
@param {MouseEvent} event | [
"Handle",
"normal",
"mouse",
"click",
"for",
"item",
"next",
"page",
"and",
"previous",
"page",
"respectively",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-pagination/index.js#L144-L151 |
8,732 | eBay/ebayui-core | src/common/transition/index.js | cancel | function cancel() {
if (ended) {
return;
}
ended = true;
for (let i = ran; i < pending; i++) {
const child = waitFor[i];
child.removeEventListener(TRANSITION_END, listener);
}
if (cancelFrame) {
cancelFrame();
classList.remove(initClass);
} else {
classList.remove(className);
}
} | javascript | function cancel() {
if (ended) {
return;
}
ended = true;
for (let i = ran; i < pending; i++) {
const child = waitFor[i];
child.removeEventListener(TRANSITION_END, listener);
}
if (cancelFrame) {
cancelFrame();
classList.remove(initClass);
} else {
classList.remove(className);
}
} | [
"function",
"cancel",
"(",
")",
"{",
"if",
"(",
"ended",
")",
"{",
"return",
";",
"}",
"ended",
"=",
"true",
";",
"for",
"(",
"let",
"i",
"=",
"ran",
";",
"i",
"<",
"pending",
";",
"i",
"++",
")",
"{",
"const",
"child",
"=",
"waitFor",
"[",
"i",
"]",
";",
"child",
".",
"removeEventListener",
"(",
"TRANSITION_END",
",",
"listener",
")",
";",
"}",
"if",
"(",
"cancelFrame",
")",
"{",
"cancelFrame",
"(",
")",
";",
"classList",
".",
"remove",
"(",
"initClass",
")",
";",
"}",
"else",
"{",
"classList",
".",
"remove",
"(",
"className",
")",
";",
"}",
"}"
] | Cancels the current transition and resets the className. | [
"Cancels",
"the",
"current",
"transition",
"and",
"resets",
"the",
"className",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/transition/index.js#L49-L67 |
8,733 | eBay/ebayui-core | src/common/transition/index.js | listener | function listener({ target }) {
target.removeEventListener(TRANSITION_END, listener);
if (++ran === pending) {
ended = true;
classList.remove(className);
if (cb) {
cb();
}
}
} | javascript | function listener({ target }) {
target.removeEventListener(TRANSITION_END, listener);
if (++ran === pending) {
ended = true;
classList.remove(className);
if (cb) {
cb();
}
}
} | [
"function",
"listener",
"(",
"{",
"target",
"}",
")",
"{",
"target",
".",
"removeEventListener",
"(",
"TRANSITION_END",
",",
"listener",
")",
";",
"if",
"(",
"++",
"ran",
"===",
"pending",
")",
"{",
"ended",
"=",
"true",
";",
"classList",
".",
"remove",
"(",
"className",
")",
";",
"if",
"(",
"cb",
")",
"{",
"cb",
"(",
")",
";",
"}",
"}",
"}"
] | Handles a single transition end event.
Once all child transitions have ended the overall animation is completed. | [
"Handles",
"a",
"single",
"transition",
"end",
"event",
".",
"Once",
"all",
"child",
"transitions",
"have",
"ended",
"the",
"overall",
"animation",
"is",
"completed",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/transition/index.js#L73-L84 |
8,734 | eBay/ebayui-core | src/common/transition/index.js | nextFrame | function nextFrame(fn) {
let frame;
let cancelFrame;
if (window.requestAnimationFrame) {
frame = requestAnimationFrame(() => {
frame = requestAnimationFrame(fn);
});
cancelFrame = cancelAnimationFrame;
} else {
frame = setTimeout(fn, 26); // 16ms to simulate RAF, 10ms to ensure called after the frame.
cancelFrame = clearTimeout;
}
return () => {
if (frame) {
cancelFrame(frame);
frame = undefined;
}
};
} | javascript | function nextFrame(fn) {
let frame;
let cancelFrame;
if (window.requestAnimationFrame) {
frame = requestAnimationFrame(() => {
frame = requestAnimationFrame(fn);
});
cancelFrame = cancelAnimationFrame;
} else {
frame = setTimeout(fn, 26); // 16ms to simulate RAF, 10ms to ensure called after the frame.
cancelFrame = clearTimeout;
}
return () => {
if (frame) {
cancelFrame(frame);
frame = undefined;
}
};
} | [
"function",
"nextFrame",
"(",
"fn",
")",
"{",
"let",
"frame",
";",
"let",
"cancelFrame",
";",
"if",
"(",
"window",
".",
"requestAnimationFrame",
")",
"{",
"frame",
"=",
"requestAnimationFrame",
"(",
"(",
")",
"=>",
"{",
"frame",
"=",
"requestAnimationFrame",
"(",
"fn",
")",
";",
"}",
")",
";",
"cancelFrame",
"=",
"cancelAnimationFrame",
";",
"}",
"else",
"{",
"frame",
"=",
"setTimeout",
"(",
"fn",
",",
"26",
")",
";",
"// 16ms to simulate RAF, 10ms to ensure called after the frame.",
"cancelFrame",
"=",
"clearTimeout",
";",
"}",
"return",
"(",
")",
"=>",
"{",
"if",
"(",
"frame",
")",
"{",
"cancelFrame",
"(",
"frame",
")",
";",
"frame",
"=",
"undefined",
";",
"}",
"}",
";",
"}"
] | Runs a function during the next animation frame.
@param {function} fn a function to run on the next animation frame.
@return {function} a function to cancel the callback. | [
"Runs",
"a",
"function",
"during",
"the",
"next",
"animation",
"frame",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/transition/index.js#L93-L113 |
8,735 | eBay/ebayui-core | src/common/html-attributes/index.js | processHtmlAttributes | function processHtmlAttributes(input = {}) {
const attributes = {};
const htmlAttributes = input.htmlAttributes;
const wildcardAttributes = input['*'];
let obj = htmlAttributes || wildcardAttributes;
if (htmlAttributes && wildcardAttributes) {
obj = Object.assign(wildcardAttributes, htmlAttributes);
}
if (obj) {
Object.keys(obj).forEach((key) => {
attributes[camelToKebab(key)] = obj[key];
});
}
return attributes;
} | javascript | function processHtmlAttributes(input = {}) {
const attributes = {};
const htmlAttributes = input.htmlAttributes;
const wildcardAttributes = input['*'];
let obj = htmlAttributes || wildcardAttributes;
if (htmlAttributes && wildcardAttributes) {
obj = Object.assign(wildcardAttributes, htmlAttributes);
}
if (obj) {
Object.keys(obj).forEach((key) => {
attributes[camelToKebab(key)] = obj[key];
});
}
return attributes;
} | [
"function",
"processHtmlAttributes",
"(",
"input",
"=",
"{",
"}",
")",
"{",
"const",
"attributes",
"=",
"{",
"}",
";",
"const",
"htmlAttributes",
"=",
"input",
".",
"htmlAttributes",
";",
"const",
"wildcardAttributes",
"=",
"input",
"[",
"'*'",
"]",
";",
"let",
"obj",
"=",
"htmlAttributes",
"||",
"wildcardAttributes",
";",
"if",
"(",
"htmlAttributes",
"&&",
"wildcardAttributes",
")",
"{",
"obj",
"=",
"Object",
".",
"assign",
"(",
"wildcardAttributes",
",",
"htmlAttributes",
")",
";",
"}",
"if",
"(",
"obj",
")",
"{",
"Object",
".",
"keys",
"(",
"obj",
")",
".",
"forEach",
"(",
"(",
"key",
")",
"=>",
"{",
"attributes",
"[",
"camelToKebab",
"(",
"key",
")",
"]",
"=",
"obj",
"[",
"key",
"]",
";",
"}",
")",
";",
"}",
"return",
"attributes",
";",
"}"
] | Create object of HTML attributes for pass-through to the DOM
@param {Object} input | [
"Create",
"object",
"of",
"HTML",
"attributes",
"for",
"pass",
"-",
"through",
"to",
"the",
"DOM"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/html-attributes/index.js#L14-L31 |
8,736 | eBay/ebayui-core | src/common/emit-and-fire/index.js | emitAndFire | function emitAndFire(widget, eventName, eventArg) {
const originalEmit = widget.emit;
let event;
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName, { detail: eventArg });
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, true, true, eventArg);
}
widget.el.dispatchEvent(event);
originalEmit.call(widget, eventName, eventArg);
} | javascript | function emitAndFire(widget, eventName, eventArg) {
const originalEmit = widget.emit;
let event;
if ('CustomEvent' in window && typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName, { detail: eventArg });
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, true, true, eventArg);
}
widget.el.dispatchEvent(event);
originalEmit.call(widget, eventName, eventArg);
} | [
"function",
"emitAndFire",
"(",
"widget",
",",
"eventName",
",",
"eventArg",
")",
"{",
"const",
"originalEmit",
"=",
"widget",
".",
"emit",
";",
"let",
"event",
";",
"if",
"(",
"'CustomEvent'",
"in",
"window",
"&&",
"typeof",
"window",
".",
"CustomEvent",
"===",
"'function'",
")",
"{",
"event",
"=",
"new",
"CustomEvent",
"(",
"eventName",
",",
"{",
"detail",
":",
"eventArg",
"}",
")",
";",
"}",
"else",
"{",
"event",
"=",
"document",
".",
"createEvent",
"(",
"'CustomEvent'",
")",
";",
"event",
".",
"initCustomEvent",
"(",
"eventName",
",",
"true",
",",
"true",
",",
"eventArg",
")",
";",
"}",
"widget",
".",
"el",
".",
"dispatchEvent",
"(",
"event",
")",
";",
"originalEmit",
".",
"call",
"(",
"widget",
",",
"eventName",
",",
"eventArg",
")",
";",
"}"
] | Emit marko event and fire custom event on the root element
@param {Object} widget
@param {String} eventName
@param {Object} eventArg | [
"Emit",
"marko",
"event",
"and",
"fire",
"custom",
"event",
"on",
"the",
"root",
"element"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/emit-and-fire/index.js#L7-L18 |
8,737 | eBay/ebayui-core | src/components/ebay-tab/index.js | processStateChange | function processStateChange(index) {
if (index >= 0 && index < this.state.headings.length && index !== this.state.index) {
this.setState('index', index);
emitAndFire(this, 'tab-select', { index });
}
} | javascript | function processStateChange(index) {
if (index >= 0 && index < this.state.headings.length && index !== this.state.index) {
this.setState('index', index);
emitAndFire(this, 'tab-select', { index });
}
} | [
"function",
"processStateChange",
"(",
"index",
")",
"{",
"if",
"(",
"index",
">=",
"0",
"&&",
"index",
"<",
"this",
".",
"state",
".",
"headings",
".",
"length",
"&&",
"index",
"!==",
"this",
".",
"state",
".",
"index",
")",
"{",
"this",
".",
"setState",
"(",
"'index'",
",",
"index",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'tab-select'",
",",
"{",
"index",
"}",
")",
";",
"}",
"}"
] | Common processing of index change via both UI and API
@param {Number} index | [
"Common",
"processing",
"of",
"index",
"change",
"via",
"both",
"UI",
"and",
"API"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-tab/index.js#L56-L61 |
8,738 | eBay/ebayui-core | src/components/ebay-tab/index.js | getHeadingEl | function getHeadingEl(e, isFake) {
let headingEl = e.target;
const headingClass = prefix(isFake, 'tabs__item');
while (!headingEl.classList.contains(headingClass)) {
headingEl = headingEl.parentNode;
}
return headingEl;
} | javascript | function getHeadingEl(e, isFake) {
let headingEl = e.target;
const headingClass = prefix(isFake, 'tabs__item');
while (!headingEl.classList.contains(headingClass)) {
headingEl = headingEl.parentNode;
}
return headingEl;
} | [
"function",
"getHeadingEl",
"(",
"e",
",",
"isFake",
")",
"{",
"let",
"headingEl",
"=",
"e",
".",
"target",
";",
"const",
"headingClass",
"=",
"prefix",
"(",
"isFake",
",",
"'tabs__item'",
")",
";",
"while",
"(",
"!",
"headingEl",
".",
"classList",
".",
"contains",
"(",
"headingClass",
")",
")",
"{",
"headingEl",
"=",
"headingEl",
".",
"parentNode",
";",
"}",
"return",
"headingEl",
";",
"}"
] | Get heading element from event
@param {Event} e
@param {Boolean} isFake - If the tabs are fake | [
"Get",
"heading",
"element",
"from",
"event"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-tab/index.js#L76-L83 |
8,739 | eBay/ebayui-core | src/components/ebay-tab/index.js | getElementIndex | function getElementIndex(headingEl) {
return Array.prototype.slice.call(headingEl.parentNode.children).indexOf(headingEl);
} | javascript | function getElementIndex(headingEl) {
return Array.prototype.slice.call(headingEl.parentNode.children).indexOf(headingEl);
} | [
"function",
"getElementIndex",
"(",
"headingEl",
")",
"{",
"return",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"headingEl",
".",
"parentNode",
".",
"children",
")",
".",
"indexOf",
"(",
"headingEl",
")",
";",
"}"
] | Get 0-based index of element within its parent
@param {HTMLElement} headingEl | [
"Get",
"0",
"-",
"based",
"index",
"of",
"element",
"within",
"its",
"parent"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-tab/index.js#L89-L91 |
8,740 | eBay/ebayui-core | src/components/ebay-menu/index.js | handleItemClick | function handleItemClick(e) {
let itemEl = e.target;
const parentEl = itemEl.closest('.menu__item, .fake-menu__item');
if (parentEl) { // nested click inside menu_item
itemEl = parentEl;
}
this.setCheckedItem(getItemElementIndex(itemEl), true);
} | javascript | function handleItemClick(e) {
let itemEl = e.target;
const parentEl = itemEl.closest('.menu__item, .fake-menu__item');
if (parentEl) { // nested click inside menu_item
itemEl = parentEl;
}
this.setCheckedItem(getItemElementIndex(itemEl), true);
} | [
"function",
"handleItemClick",
"(",
"e",
")",
"{",
"let",
"itemEl",
"=",
"e",
".",
"target",
";",
"const",
"parentEl",
"=",
"itemEl",
".",
"closest",
"(",
"'.menu__item, .fake-menu__item'",
")",
";",
"if",
"(",
"parentEl",
")",
"{",
"// nested click inside menu_item",
"itemEl",
"=",
"parentEl",
";",
"}",
"this",
".",
"setCheckedItem",
"(",
"getItemElementIndex",
"(",
"itemEl",
")",
",",
"true",
")",
";",
"}"
] | Handle normal mouse click for item
@param {MouseEvent} e | [
"Handle",
"normal",
"mouse",
"click",
"for",
"item"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-menu/index.js#L246-L255 |
8,741 | eBay/ebayui-core | src/components/ebay-menu/index.js | setCheckedItem | function setCheckedItem(itemIndex, toggle) {
const item = this.state.items[itemIndex];
if (item) {
if (this.state.isCheckbox && !toggle) {
item.checked = true;
} else if (this.state.isCheckbox && toggle) {
item.checked = !item.checked;
} else if (this.state.isRadio) {
this.state.items[itemIndex].checked = true;
}
if (this.state.isCheckbox || this.state.isRadio) {
this.setStateDirty('items');
}
if (this.state.isRadio || toggle) {
this.processAfterStateChange([itemIndex]);
}
}
} | javascript | function setCheckedItem(itemIndex, toggle) {
const item = this.state.items[itemIndex];
if (item) {
if (this.state.isCheckbox && !toggle) {
item.checked = true;
} else if (this.state.isCheckbox && toggle) {
item.checked = !item.checked;
} else if (this.state.isRadio) {
this.state.items[itemIndex].checked = true;
}
if (this.state.isCheckbox || this.state.isRadio) {
this.setStateDirty('items');
}
if (this.state.isRadio || toggle) {
this.processAfterStateChange([itemIndex]);
}
}
} | [
"function",
"setCheckedItem",
"(",
"itemIndex",
",",
"toggle",
")",
"{",
"const",
"item",
"=",
"this",
".",
"state",
".",
"items",
"[",
"itemIndex",
"]",
";",
"if",
"(",
"item",
")",
"{",
"if",
"(",
"this",
".",
"state",
".",
"isCheckbox",
"&&",
"!",
"toggle",
")",
"{",
"item",
".",
"checked",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"this",
".",
"state",
".",
"isCheckbox",
"&&",
"toggle",
")",
"{",
"item",
".",
"checked",
"=",
"!",
"item",
".",
"checked",
";",
"}",
"else",
"if",
"(",
"this",
".",
"state",
".",
"isRadio",
")",
"{",
"this",
".",
"state",
".",
"items",
"[",
"itemIndex",
"]",
".",
"checked",
"=",
"true",
";",
"}",
"if",
"(",
"this",
".",
"state",
".",
"isCheckbox",
"||",
"this",
".",
"state",
".",
"isRadio",
")",
"{",
"this",
".",
"setStateDirty",
"(",
"'items'",
")",
";",
"}",
"if",
"(",
"this",
".",
"state",
".",
"isRadio",
"||",
"toggle",
")",
"{",
"this",
".",
"processAfterStateChange",
"(",
"[",
"itemIndex",
"]",
")",
";",
"}",
"}",
"}"
] | Set the checked item based on the index
@param {Integer} itemIndex
@param {Boolean} toggle | [
"Set",
"the",
"checked",
"item",
"based",
"on",
"the",
"index"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-menu/index.js#L262-L282 |
8,742 | eBay/ebayui-core | src/components/ebay-menu/index.js | setCheckedList | function setCheckedList(indexArray) {
if (indexArray) {
this.state.items.forEach((item) => {
item.checked = false;
});
indexArray.forEach((index) => {
this.setCheckedItem(index);
});
this.processAfterStateChange(indexArray);
}
} | javascript | function setCheckedList(indexArray) {
if (indexArray) {
this.state.items.forEach((item) => {
item.checked = false;
});
indexArray.forEach((index) => {
this.setCheckedItem(index);
});
this.processAfterStateChange(indexArray);
}
} | [
"function",
"setCheckedList",
"(",
"indexArray",
")",
"{",
"if",
"(",
"indexArray",
")",
"{",
"this",
".",
"state",
".",
"items",
".",
"forEach",
"(",
"(",
"item",
")",
"=>",
"{",
"item",
".",
"checked",
"=",
"false",
";",
"}",
")",
";",
"indexArray",
".",
"forEach",
"(",
"(",
"index",
")",
"=>",
"{",
"this",
".",
"setCheckedItem",
"(",
"index",
")",
";",
"}",
")",
";",
"this",
".",
"processAfterStateChange",
"(",
"indexArray",
")",
";",
"}",
"}"
] | Set the list of options by their index
@param {Array} indexArray | [
"Set",
"the",
"list",
"of",
"options",
"by",
"their",
"index"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-menu/index.js#L353-L365 |
8,743 | eBay/ebayui-core | src/common/transformers/ebayui-attribute/index.js | transform | function transform(el, context) {
// Only runs on top level ebay ui templates (skips demos).
const isEbayUIComponentFile = COMPONENT_FILES.indexOf(context.filename) !== -1;
if (isEbayUIComponentFile && el.hasAttribute('w-bind')) {
el.setAttributeValue('data-ebayui', context.builder.literal(true));
}
} | javascript | function transform(el, context) {
// Only runs on top level ebay ui templates (skips demos).
const isEbayUIComponentFile = COMPONENT_FILES.indexOf(context.filename) !== -1;
if (isEbayUIComponentFile && el.hasAttribute('w-bind')) {
el.setAttributeValue('data-ebayui', context.builder.literal(true));
}
} | [
"function",
"transform",
"(",
"el",
",",
"context",
")",
"{",
"// Only runs on top level ebay ui templates (skips demos).",
"const",
"isEbayUIComponentFile",
"=",
"COMPONENT_FILES",
".",
"indexOf",
"(",
"context",
".",
"filename",
")",
"!==",
"-",
"1",
";",
"if",
"(",
"isEbayUIComponentFile",
"&&",
"el",
".",
"hasAttribute",
"(",
"'w-bind'",
")",
")",
"{",
"el",
".",
"setAttributeValue",
"(",
"'data-ebayui'",
",",
"context",
".",
"builder",
".",
"literal",
"(",
"true",
")",
")",
";",
"}",
"}"
] | Transform to add the `data-ebayui` attribute to top level elements for all components.
@param {Object} el
@param {Object} context | [
"Transform",
"to",
"add",
"the",
"data",
"-",
"ebayui",
"attribute",
"to",
"top",
"level",
"elements",
"for",
"all",
"components",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/transformers/ebayui-attribute/index.js#L14-L21 |
8,744 | eBay/ebayui-core | src/components/ebay-carousel/index.js | handleMove | function handleMove(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state } = this;
const direction = parseInt(target.getAttribute('data-direction'), 10);
const nextIndex = this.move(direction);
const slide = getSlide(state, nextIndex);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
emitAndFire(this, `carousel-${direction === 1 ? 'next' : 'previous'}`, { originalEvent });
} | javascript | function handleMove(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state } = this;
const direction = parseInt(target.getAttribute('data-direction'), 10);
const nextIndex = this.move(direction);
const slide = getSlide(state, nextIndex);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
emitAndFire(this, `carousel-${direction === 1 ? 'next' : 'previous'}`, { originalEvent });
} | [
"function",
"handleMove",
"(",
"originalEvent",
",",
"target",
")",
"{",
"if",
"(",
"this",
".",
"isMoving",
")",
"{",
"return",
";",
"}",
"const",
"{",
"state",
"}",
"=",
"this",
";",
"const",
"direction",
"=",
"parseInt",
"(",
"target",
".",
"getAttribute",
"(",
"'data-direction'",
")",
",",
"10",
")",
";",
"const",
"nextIndex",
"=",
"this",
".",
"move",
"(",
"direction",
")",
";",
"const",
"slide",
"=",
"getSlide",
"(",
"state",
",",
"nextIndex",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'carousel-slide'",
",",
"{",
"slide",
":",
"slide",
"+",
"1",
",",
"originalEvent",
"}",
")",
";",
"emitAndFire",
"(",
"this",
",",
"`",
"${",
"direction",
"===",
"1",
"?",
"'next'",
":",
"'previous'",
"}",
"`",
",",
"{",
"originalEvent",
"}",
")",
";",
"}"
] | Moves the carousel in the `data-direction` of the clicked element if possible.
@param {MouseEvent} originalEvent
@param {HTMLElement} target | [
"Moves",
"the",
"carousel",
"in",
"the",
"data",
"-",
"direction",
"of",
"the",
"clicked",
"element",
"if",
"possible",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L263-L273 |
8,745 | eBay/ebayui-core | src/components/ebay-carousel/index.js | handleDotClick | function handleDotClick(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state: { config, itemsPerSlide } } = this;
const slide = parseInt(target.getAttribute('data-slide'), 10);
config.preserveItems = true;
this.setState('index', slide * itemsPerSlide);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
} | javascript | function handleDotClick(originalEvent, target) {
if (this.isMoving) {
return;
}
const { state: { config, itemsPerSlide } } = this;
const slide = parseInt(target.getAttribute('data-slide'), 10);
config.preserveItems = true;
this.setState('index', slide * itemsPerSlide);
emitAndFire(this, 'carousel-slide', { slide: slide + 1, originalEvent });
} | [
"function",
"handleDotClick",
"(",
"originalEvent",
",",
"target",
")",
"{",
"if",
"(",
"this",
".",
"isMoving",
")",
"{",
"return",
";",
"}",
"const",
"{",
"state",
":",
"{",
"config",
",",
"itemsPerSlide",
"}",
"}",
"=",
"this",
";",
"const",
"slide",
"=",
"parseInt",
"(",
"target",
".",
"getAttribute",
"(",
"'data-slide'",
")",
",",
"10",
")",
";",
"config",
".",
"preserveItems",
"=",
"true",
";",
"this",
".",
"setState",
"(",
"'index'",
",",
"slide",
"*",
"itemsPerSlide",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'carousel-slide'",
",",
"{",
"slide",
":",
"slide",
"+",
"1",
",",
"originalEvent",
"}",
")",
";",
"}"
] | Moves the carousel to the slide at `data-slide` for the clicked element if possible.
@param {MouseEvent} originalEvent
@param {HTMLElement} target | [
"Moves",
"the",
"carousel",
"to",
"the",
"slide",
"at",
"data",
"-",
"slide",
"for",
"the",
"clicked",
"element",
"if",
"possible",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L281-L290 |
8,746 | eBay/ebayui-core | src/components/ebay-carousel/index.js | togglePlay | function togglePlay(originalEvent) {
const { state: { config, paused } } = this;
config.preserveItems = true;
this.setState('paused', !paused);
if (paused && !this.isMoving) {
this.move(RIGHT);
}
emitAndFire(this, `carousel-${paused ? 'play' : 'pause'}`, { originalEvent });
} | javascript | function togglePlay(originalEvent) {
const { state: { config, paused } } = this;
config.preserveItems = true;
this.setState('paused', !paused);
if (paused && !this.isMoving) {
this.move(RIGHT);
}
emitAndFire(this, `carousel-${paused ? 'play' : 'pause'}`, { originalEvent });
} | [
"function",
"togglePlay",
"(",
"originalEvent",
")",
"{",
"const",
"{",
"state",
":",
"{",
"config",
",",
"paused",
"}",
"}",
"=",
"this",
";",
"config",
".",
"preserveItems",
"=",
"true",
";",
"this",
".",
"setState",
"(",
"'paused'",
",",
"!",
"paused",
")",
";",
"if",
"(",
"paused",
"&&",
"!",
"this",
".",
"isMoving",
")",
"{",
"this",
".",
"move",
"(",
"RIGHT",
")",
";",
"}",
"emitAndFire",
"(",
"this",
",",
"`",
"${",
"paused",
"?",
"'play'",
":",
"'pause'",
"}",
"`",
",",
"{",
"originalEvent",
"}",
")",
";",
"}"
] | Toggles the play state of an autoplay carousel.
@param {MouseEvent} originalEvent | [
"Toggles",
"the",
"play",
"state",
"of",
"an",
"autoplay",
"carousel",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L297-L305 |
8,747 | eBay/ebayui-core | src/components/ebay-carousel/index.js | handleScroll | function handleScroll(scrollLeft) {
const { state } = this;
const { config, items, gap } = state;
let closest;
if (scrollLeft >= getMaxOffset(state) - gap) {
closest = items.length - 1;
} else {
// Find the closest item using a binary search on each carousel slide.
const itemsPerSlide = state.itemsPerSlide || 1;
const totalItems = items.length;
let low = 0;
let high = Math.ceil(totalItems / itemsPerSlide) - 1;
while (high - low > 1) {
const mid = Math.floor((low + high) / 2);
if (scrollLeft > items[mid * itemsPerSlide].left) {
low = mid;
} else {
high = mid;
}
}
const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
closest = normalizeIndex(state, (deltaLow > deltaHigh ? high : low) * itemsPerSlide);
}
if (state.index !== closest) {
config.skipScrolling = true;
config.preserveItems = true;
this.setState('index', closest);
emitAndFire(this, 'carousel-scroll', { index: closest });
}
} | javascript | function handleScroll(scrollLeft) {
const { state } = this;
const { config, items, gap } = state;
let closest;
if (scrollLeft >= getMaxOffset(state) - gap) {
closest = items.length - 1;
} else {
// Find the closest item using a binary search on each carousel slide.
const itemsPerSlide = state.itemsPerSlide || 1;
const totalItems = items.length;
let low = 0;
let high = Math.ceil(totalItems / itemsPerSlide) - 1;
while (high - low > 1) {
const mid = Math.floor((low + high) / 2);
if (scrollLeft > items[mid * itemsPerSlide].left) {
low = mid;
} else {
high = mid;
}
}
const deltaLow = Math.abs(scrollLeft - items[low * itemsPerSlide].left);
const deltaHigh = Math.abs(scrollLeft - items[high * itemsPerSlide].left);
closest = normalizeIndex(state, (deltaLow > deltaHigh ? high : low) * itemsPerSlide);
}
if (state.index !== closest) {
config.skipScrolling = true;
config.preserveItems = true;
this.setState('index', closest);
emitAndFire(this, 'carousel-scroll', { index: closest });
}
} | [
"function",
"handleScroll",
"(",
"scrollLeft",
")",
"{",
"const",
"{",
"state",
"}",
"=",
"this",
";",
"const",
"{",
"config",
",",
"items",
",",
"gap",
"}",
"=",
"state",
";",
"let",
"closest",
";",
"if",
"(",
"scrollLeft",
">=",
"getMaxOffset",
"(",
"state",
")",
"-",
"gap",
")",
"{",
"closest",
"=",
"items",
".",
"length",
"-",
"1",
";",
"}",
"else",
"{",
"// Find the closest item using a binary search on each carousel slide.",
"const",
"itemsPerSlide",
"=",
"state",
".",
"itemsPerSlide",
"||",
"1",
";",
"const",
"totalItems",
"=",
"items",
".",
"length",
";",
"let",
"low",
"=",
"0",
";",
"let",
"high",
"=",
"Math",
".",
"ceil",
"(",
"totalItems",
"/",
"itemsPerSlide",
")",
"-",
"1",
";",
"while",
"(",
"high",
"-",
"low",
">",
"1",
")",
"{",
"const",
"mid",
"=",
"Math",
".",
"floor",
"(",
"(",
"low",
"+",
"high",
")",
"/",
"2",
")",
";",
"if",
"(",
"scrollLeft",
">",
"items",
"[",
"mid",
"*",
"itemsPerSlide",
"]",
".",
"left",
")",
"{",
"low",
"=",
"mid",
";",
"}",
"else",
"{",
"high",
"=",
"mid",
";",
"}",
"}",
"const",
"deltaLow",
"=",
"Math",
".",
"abs",
"(",
"scrollLeft",
"-",
"items",
"[",
"low",
"*",
"itemsPerSlide",
"]",
".",
"left",
")",
";",
"const",
"deltaHigh",
"=",
"Math",
".",
"abs",
"(",
"scrollLeft",
"-",
"items",
"[",
"high",
"*",
"itemsPerSlide",
"]",
".",
"left",
")",
";",
"closest",
"=",
"normalizeIndex",
"(",
"state",
",",
"(",
"deltaLow",
">",
"deltaHigh",
"?",
"high",
":",
"low",
")",
"*",
"itemsPerSlide",
")",
";",
"}",
"if",
"(",
"state",
".",
"index",
"!==",
"closest",
")",
"{",
"config",
".",
"skipScrolling",
"=",
"true",
";",
"config",
".",
"preserveItems",
"=",
"true",
";",
"this",
".",
"setState",
"(",
"'index'",
",",
"closest",
")",
";",
"emitAndFire",
"(",
"this",
",",
"'carousel-scroll'",
",",
"{",
"index",
":",
"closest",
"}",
")",
";",
"}",
"}"
] | Find the closest item index to the scroll offset and triggers an update.
@param {number} scrollLeft The current scroll position of the carousel. | [
"Find",
"the",
"closest",
"item",
"index",
"to",
"the",
"scroll",
"offset",
"and",
"triggers",
"an",
"update",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L312-L346 |
8,748 | eBay/ebayui-core | src/components/ebay-carousel/index.js | move | function move(delta) {
const { state } = this;
const { index, items, itemsPerSlide, autoplayInterval, slideWidth, gap, peek, config } = state;
const nextIndex = getNextIndex(state, delta);
let offsetOverride;
config.preserveItems = true;
this.isMoving = true;
// When we are in autoplay mode we overshoot the desired index to land on a clone
// of one of the ends. Then after the transition is over we update to the proper position.
if (autoplayInterval) {
if (delta === RIGHT && nextIndex < index) {
// Transitions to one slide before the beginning.
offsetOverride = -slideWidth - gap;
// Move the items in the last slide to be before the first slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[items.length - i - 1];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap) * -1}px)`;
}
} else if (delta === LEFT && nextIndex > index) {
// Transitions one slide past the end.
offsetOverride = getMaxOffset(state) + slideWidth + gap;
// Moves the items in the first slide to be after the last slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[i];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap)}px)`;
}
}
config.offsetOverride = offsetOverride;
}
this.setState('index', nextIndex);
this.once('carousel-update', () => {
this.isMoving = false;
if (offsetOverride !== undefined) {
// If we are in autoplay mode and went outside of the normal offset
// We make sure to restore all of the items that got moved around.
items.forEach(item => { item.transform = undefined; });
}
});
return nextIndex;
} | javascript | function move(delta) {
const { state } = this;
const { index, items, itemsPerSlide, autoplayInterval, slideWidth, gap, peek, config } = state;
const nextIndex = getNextIndex(state, delta);
let offsetOverride;
config.preserveItems = true;
this.isMoving = true;
// When we are in autoplay mode we overshoot the desired index to land on a clone
// of one of the ends. Then after the transition is over we update to the proper position.
if (autoplayInterval) {
if (delta === RIGHT && nextIndex < index) {
// Transitions to one slide before the beginning.
offsetOverride = -slideWidth - gap;
// Move the items in the last slide to be before the first slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[items.length - i - 1];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap) * -1}px)`;
}
} else if (delta === LEFT && nextIndex > index) {
// Transitions one slide past the end.
offsetOverride = getMaxOffset(state) + slideWidth + gap;
// Moves the items in the first slide to be after the last slide.
for (let i = Math.ceil(itemsPerSlide + peek); i--;) {
const item = items[i];
item.transform = `translateX(${(getMaxOffset(state) + slideWidth + gap)}px)`;
}
}
config.offsetOverride = offsetOverride;
}
this.setState('index', nextIndex);
this.once('carousel-update', () => {
this.isMoving = false;
if (offsetOverride !== undefined) {
// If we are in autoplay mode and went outside of the normal offset
// We make sure to restore all of the items that got moved around.
items.forEach(item => { item.transform = undefined; });
}
});
return nextIndex;
} | [
"function",
"move",
"(",
"delta",
")",
"{",
"const",
"{",
"state",
"}",
"=",
"this",
";",
"const",
"{",
"index",
",",
"items",
",",
"itemsPerSlide",
",",
"autoplayInterval",
",",
"slideWidth",
",",
"gap",
",",
"peek",
",",
"config",
"}",
"=",
"state",
";",
"const",
"nextIndex",
"=",
"getNextIndex",
"(",
"state",
",",
"delta",
")",
";",
"let",
"offsetOverride",
";",
"config",
".",
"preserveItems",
"=",
"true",
";",
"this",
".",
"isMoving",
"=",
"true",
";",
"// When we are in autoplay mode we overshoot the desired index to land on a clone",
"// of one of the ends. Then after the transition is over we update to the proper position.",
"if",
"(",
"autoplayInterval",
")",
"{",
"if",
"(",
"delta",
"===",
"RIGHT",
"&&",
"nextIndex",
"<",
"index",
")",
"{",
"// Transitions to one slide before the beginning.",
"offsetOverride",
"=",
"-",
"slideWidth",
"-",
"gap",
";",
"// Move the items in the last slide to be before the first slide.",
"for",
"(",
"let",
"i",
"=",
"Math",
".",
"ceil",
"(",
"itemsPerSlide",
"+",
"peek",
")",
";",
"i",
"--",
";",
")",
"{",
"const",
"item",
"=",
"items",
"[",
"items",
".",
"length",
"-",
"i",
"-",
"1",
"]",
";",
"item",
".",
"transform",
"=",
"`",
"${",
"(",
"getMaxOffset",
"(",
"state",
")",
"+",
"slideWidth",
"+",
"gap",
")",
"*",
"-",
"1",
"}",
"`",
";",
"}",
"}",
"else",
"if",
"(",
"delta",
"===",
"LEFT",
"&&",
"nextIndex",
">",
"index",
")",
"{",
"// Transitions one slide past the end.",
"offsetOverride",
"=",
"getMaxOffset",
"(",
"state",
")",
"+",
"slideWidth",
"+",
"gap",
";",
"// Moves the items in the first slide to be after the last slide.",
"for",
"(",
"let",
"i",
"=",
"Math",
".",
"ceil",
"(",
"itemsPerSlide",
"+",
"peek",
")",
";",
"i",
"--",
";",
")",
"{",
"const",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"item",
".",
"transform",
"=",
"`",
"${",
"(",
"getMaxOffset",
"(",
"state",
")",
"+",
"slideWidth",
"+",
"gap",
")",
"}",
"`",
";",
"}",
"}",
"config",
".",
"offsetOverride",
"=",
"offsetOverride",
";",
"}",
"this",
".",
"setState",
"(",
"'index'",
",",
"nextIndex",
")",
";",
"this",
".",
"once",
"(",
"'carousel-update'",
",",
"(",
")",
"=>",
"{",
"this",
".",
"isMoving",
"=",
"false",
";",
"if",
"(",
"offsetOverride",
"!==",
"undefined",
")",
"{",
"// If we are in autoplay mode and went outside of the normal offset",
"// We make sure to restore all of the items that got moved around.",
"items",
".",
"forEach",
"(",
"item",
"=>",
"{",
"item",
".",
"transform",
"=",
"undefined",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"nextIndex",
";",
"}"
] | Causes the carousel to move to the provided index.
@param {-1|1} delta 1 for right and -1 for left.
@return {number} the updated index. | [
"Causes",
"the",
"carousel",
"to",
"move",
"to",
"the",
"provided",
"index",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L354-L401 |
8,749 | eBay/ebayui-core | src/components/ebay-carousel/index.js | getOffset | function getOffset(state) {
const { items, index } = state;
if (!items.length) {
return 0;
}
return Math.min(items[index].left, getMaxOffset(state)) || 0;
} | javascript | function getOffset(state) {
const { items, index } = state;
if (!items.length) {
return 0;
}
return Math.min(items[index].left, getMaxOffset(state)) || 0;
} | [
"function",
"getOffset",
"(",
"state",
")",
"{",
"const",
"{",
"items",
",",
"index",
"}",
"=",
"state",
";",
"if",
"(",
"!",
"items",
".",
"length",
")",
"{",
"return",
"0",
";",
"}",
"return",
"Math",
".",
"min",
"(",
"items",
"[",
"index",
"]",
".",
"left",
",",
"getMaxOffset",
"(",
"state",
")",
")",
"||",
"0",
";",
"}"
] | Given the current widget state, finds the active offset left of the selected item.
Also automatically caps the offset at the max offset.
@param {object} state The widget state.
@return {number} | [
"Given",
"the",
"current",
"widget",
"state",
"finds",
"the",
"active",
"offset",
"left",
"of",
"the",
"selected",
"item",
".",
"Also",
"automatically",
"caps",
"the",
"offset",
"at",
"the",
"max",
"offset",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L410-L416 |
8,750 | eBay/ebayui-core | src/components/ebay-carousel/index.js | getMaxOffset | function getMaxOffset({ items, slideWidth }) {
if (!items.length) {
return 0;
}
return Math.max(items[items.length - 1].right - slideWidth, 0) || 0;
} | javascript | function getMaxOffset({ items, slideWidth }) {
if (!items.length) {
return 0;
}
return Math.max(items[items.length - 1].right - slideWidth, 0) || 0;
} | [
"function",
"getMaxOffset",
"(",
"{",
"items",
",",
"slideWidth",
"}",
")",
"{",
"if",
"(",
"!",
"items",
".",
"length",
")",
"{",
"return",
"0",
";",
"}",
"return",
"Math",
".",
"max",
"(",
"items",
"[",
"items",
".",
"length",
"-",
"1",
"]",
".",
"right",
"-",
"slideWidth",
",",
"0",
")",
"||",
"0",
";",
"}"
] | Given the current widget state, finds the last valid offset.
@param {object} state The widget state.
@return {number} | [
"Given",
"the",
"current",
"widget",
"state",
"finds",
"the",
"last",
"valid",
"offset",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L424-L429 |
8,751 | eBay/ebayui-core | src/components/ebay-carousel/index.js | getSlide | function getSlide({ index, itemsPerSlide }, i = index) {
if (!itemsPerSlide) {
return;
}
return Math.ceil(i / itemsPerSlide);
} | javascript | function getSlide({ index, itemsPerSlide }, i = index) {
if (!itemsPerSlide) {
return;
}
return Math.ceil(i / itemsPerSlide);
} | [
"function",
"getSlide",
"(",
"{",
"index",
",",
"itemsPerSlide",
"}",
",",
"i",
"=",
"index",
")",
"{",
"if",
"(",
"!",
"itemsPerSlide",
")",
"{",
"return",
";",
"}",
"return",
"Math",
".",
"ceil",
"(",
"i",
"/",
"itemsPerSlide",
")",
";",
"}"
] | Gets the slide for a given index.
Defaults to the current index if none provided.
@param {object} state The widget state.
@param {number?} i the index to get the slide for.
@return {number} | [
"Gets",
"the",
"slide",
"for",
"a",
"given",
"index",
".",
"Defaults",
"to",
"the",
"current",
"index",
"if",
"none",
"provided",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L439-L445 |
8,752 | eBay/ebayui-core | src/components/ebay-carousel/index.js | normalizeIndex | function normalizeIndex({ items, itemsPerSlide }, index) {
let result = index;
result %= items.length || 1; // Ensure index is within bounds.
result -= result % (itemsPerSlide || 1); // Round index to the nearest valid slide index.
result = Math.abs(result); // Ensure positive value.
return result;
} | javascript | function normalizeIndex({ items, itemsPerSlide }, index) {
let result = index;
result %= items.length || 1; // Ensure index is within bounds.
result -= result % (itemsPerSlide || 1); // Round index to the nearest valid slide index.
result = Math.abs(result); // Ensure positive value.
return result;
} | [
"function",
"normalizeIndex",
"(",
"{",
"items",
",",
"itemsPerSlide",
"}",
",",
"index",
")",
"{",
"let",
"result",
"=",
"index",
";",
"result",
"%=",
"items",
".",
"length",
"||",
"1",
";",
"// Ensure index is within bounds.",
"result",
"-=",
"result",
"%",
"(",
"itemsPerSlide",
"||",
"1",
")",
";",
"// Round index to the nearest valid slide index.",
"result",
"=",
"Math",
".",
"abs",
"(",
"result",
")",
";",
"// Ensure positive value.",
"return",
"result",
";",
"}"
] | Ensures that an index is valid.
@param {object} state The widget state.
@param {number} index the index to normalize. | [
"Ensures",
"that",
"an",
"index",
"is",
"valid",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L453-L459 |
8,753 | eBay/ebayui-core | src/components/ebay-carousel/index.js | getNextIndex | function getNextIndex(state, delta) {
const { index, items, slideWidth, itemsPerSlide } = state;
let i = index;
let item;
// If going backward from 0, we go to the end.
if (delta === LEFT && i === 0) {
i = items.length - 1;
} else {
// Find the index of the next item that is not fully in view.
do {
item = items[i += delta];
} while (item && item.fullyVisible);
if (delta === LEFT && !itemsPerSlide) {
// If going left without items per slide, go as far left as possible while keeping this item fully in view.
const targetOffset = item.right - slideWidth;
do {
item = items[--i];
} while (item && item.left >= targetOffset);
i += 1;
}
}
return normalizeIndex(state, i);
} | javascript | function getNextIndex(state, delta) {
const { index, items, slideWidth, itemsPerSlide } = state;
let i = index;
let item;
// If going backward from 0, we go to the end.
if (delta === LEFT && i === 0) {
i = items.length - 1;
} else {
// Find the index of the next item that is not fully in view.
do {
item = items[i += delta];
} while (item && item.fullyVisible);
if (delta === LEFT && !itemsPerSlide) {
// If going left without items per slide, go as far left as possible while keeping this item fully in view.
const targetOffset = item.right - slideWidth;
do {
item = items[--i];
} while (item && item.left >= targetOffset);
i += 1;
}
}
return normalizeIndex(state, i);
} | [
"function",
"getNextIndex",
"(",
"state",
",",
"delta",
")",
"{",
"const",
"{",
"index",
",",
"items",
",",
"slideWidth",
",",
"itemsPerSlide",
"}",
"=",
"state",
";",
"let",
"i",
"=",
"index",
";",
"let",
"item",
";",
"// If going backward from 0, we go to the end.",
"if",
"(",
"delta",
"===",
"LEFT",
"&&",
"i",
"===",
"0",
")",
"{",
"i",
"=",
"items",
".",
"length",
"-",
"1",
";",
"}",
"else",
"{",
"// Find the index of the next item that is not fully in view.",
"do",
"{",
"item",
"=",
"items",
"[",
"i",
"+=",
"delta",
"]",
";",
"}",
"while",
"(",
"item",
"&&",
"item",
".",
"fullyVisible",
")",
";",
"if",
"(",
"delta",
"===",
"LEFT",
"&&",
"!",
"itemsPerSlide",
")",
"{",
"// If going left without items per slide, go as far left as possible while keeping this item fully in view.",
"const",
"targetOffset",
"=",
"item",
".",
"right",
"-",
"slideWidth",
";",
"do",
"{",
"item",
"=",
"items",
"[",
"--",
"i",
"]",
";",
"}",
"while",
"(",
"item",
"&&",
"item",
".",
"left",
">=",
"targetOffset",
")",
";",
"i",
"+=",
"1",
";",
"}",
"}",
"return",
"normalizeIndex",
"(",
"state",
",",
"i",
")",
";",
"}"
] | Calculates the next valid index in a direction.
@param {object} state The widget state.
@param {-1|1} delta 1 for right and -1 for left.
@return {number} | [
"Calculates",
"the",
"next",
"valid",
"index",
"in",
"a",
"direction",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L468-L493 |
8,754 | eBay/ebayui-core | src/components/ebay-carousel/index.js | forEls | function forEls(parent, fn) {
let i = 0;
let child = parent.firstElementChild;
while (child) {
fn(child, i++);
child = child.nextElementSibling;
}
} | javascript | function forEls(parent, fn) {
let i = 0;
let child = parent.firstElementChild;
while (child) {
fn(child, i++);
child = child.nextElementSibling;
}
} | [
"function",
"forEls",
"(",
"parent",
",",
"fn",
")",
"{",
"let",
"i",
"=",
"0",
";",
"let",
"child",
"=",
"parent",
".",
"firstElementChild",
";",
"while",
"(",
"child",
")",
"{",
"fn",
"(",
"child",
",",
"i",
"++",
")",
";",
"child",
"=",
"child",
".",
"nextElementSibling",
";",
"}",
"}"
] | Calls a function on each element within a parent element.
@param {HTMLElement} parent The parent to walk through.
@param {(el: HTMLElement, i: number) => any} fn The function to call. | [
"Calls",
"a",
"function",
"on",
"each",
"element",
"within",
"a",
"parent",
"element",
"."
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-carousel/index.js#L501-L508 |
8,755 | eBay/ebayui-core | src/common/property-observer/index.js | observeRoot | function observeRoot(widget, attributes, callback, skipSetState) {
attributes.forEach(attribute => {
Object.defineProperty(widget.el, attribute, {
get() {
return widget.state[attribute];
},
set(value) {
if (!skipSetState) {
widget.setState(attribute, value);
}
if (callback) {
callback(value);
}
}
});
});
} | javascript | function observeRoot(widget, attributes, callback, skipSetState) {
attributes.forEach(attribute => {
Object.defineProperty(widget.el, attribute, {
get() {
return widget.state[attribute];
},
set(value) {
if (!skipSetState) {
widget.setState(attribute, value);
}
if (callback) {
callback(value);
}
}
});
});
} | [
"function",
"observeRoot",
"(",
"widget",
",",
"attributes",
",",
"callback",
",",
"skipSetState",
")",
"{",
"attributes",
".",
"forEach",
"(",
"attribute",
"=>",
"{",
"Object",
".",
"defineProperty",
"(",
"widget",
".",
"el",
",",
"attribute",
",",
"{",
"get",
"(",
")",
"{",
"return",
"widget",
".",
"state",
"[",
"attribute",
"]",
";",
"}",
",",
"set",
"(",
"value",
")",
"{",
"if",
"(",
"!",
"skipSetState",
")",
"{",
"widget",
".",
"setState",
"(",
"attribute",
",",
"value",
")",
";",
"}",
"if",
"(",
"callback",
")",
"{",
"callback",
"(",
"value",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | For each attribute, define getter and setter on root DOM element of the widget
@param {Object} widget
@param {Array} attributes
@param {Function} callback
@param {Boolean} skipSetState: useful for handling setState in your component, rather than here | [
"For",
"each",
"attribute",
"define",
"getter",
"and",
"setter",
"on",
"root",
"DOM",
"element",
"of",
"the",
"widget"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/property-observer/index.js#L11-L27 |
8,756 | eBay/ebayui-core | src/common/property-observer/index.js | observeInner | function observeInner(widget, el, attribute, path, dirtyPath, callback) {
Object.defineProperty(el, attribute, {
get() {
return _get(widget.state, `${path}.${attribute}`);
},
set(value) {
_set(widget.state, `${path}.${attribute}`, value);
if (dirtyPath) {
widget.setStateDirty(dirtyPath);
}
callback(el);
}
});
} | javascript | function observeInner(widget, el, attribute, path, dirtyPath, callback) {
Object.defineProperty(el, attribute, {
get() {
return _get(widget.state, `${path}.${attribute}`);
},
set(value) {
_set(widget.state, `${path}.${attribute}`, value);
if (dirtyPath) {
widget.setStateDirty(dirtyPath);
}
callback(el);
}
});
} | [
"function",
"observeInner",
"(",
"widget",
",",
"el",
",",
"attribute",
",",
"path",
",",
"dirtyPath",
",",
"callback",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"el",
",",
"attribute",
",",
"{",
"get",
"(",
")",
"{",
"return",
"_get",
"(",
"widget",
".",
"state",
",",
"`",
"${",
"path",
"}",
"${",
"attribute",
"}",
"`",
")",
";",
"}",
",",
"set",
"(",
"value",
")",
"{",
"_set",
"(",
"widget",
".",
"state",
",",
"`",
"${",
"path",
"}",
"${",
"attribute",
"}",
"`",
",",
"value",
")",
";",
"if",
"(",
"dirtyPath",
")",
"{",
"widget",
".",
"setStateDirty",
"(",
"dirtyPath",
")",
";",
"}",
"callback",
"(",
"el",
")",
";",
"}",
"}",
")",
";",
"}"
] | Define getter and setter on a non-root DOM element of the widget
@param {Object} widget: Widget instance
@param {HTMLElement} el: Element for attaching observer
@param {String} attribute: Name of stateful property
@param {String} path: Path to part of state that needs to be accessed
@param {String} dirtyPath: Path to use with setStateDirty() | [
"Define",
"getter",
"and",
"setter",
"on",
"a",
"non",
"-",
"root",
"DOM",
"element",
"of",
"the",
"widget"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/property-observer/index.js#L37-L50 |
8,757 | eBay/ebayui-core | src/common/element-scroll/index.js | scroll | function scroll(el) {
if (!el) {
return;
}
const parentEl = el && el.parentElement;
const offsetBottom = el.offsetTop + el.offsetHeight;
const scrollBottom = parentEl.scrollTop + parentEl.offsetHeight;
if (el.offsetTop < parentEl.scrollTop) {
parentEl.scrollTop = el.offsetTop;
} else if (offsetBottom > scrollBottom) {
parentEl.scrollTop = offsetBottom - parentEl.offsetHeight;
}
} | javascript | function scroll(el) {
if (!el) {
return;
}
const parentEl = el && el.parentElement;
const offsetBottom = el.offsetTop + el.offsetHeight;
const scrollBottom = parentEl.scrollTop + parentEl.offsetHeight;
if (el.offsetTop < parentEl.scrollTop) {
parentEl.scrollTop = el.offsetTop;
} else if (offsetBottom > scrollBottom) {
parentEl.scrollTop = offsetBottom - parentEl.offsetHeight;
}
} | [
"function",
"scroll",
"(",
"el",
")",
"{",
"if",
"(",
"!",
"el",
")",
"{",
"return",
";",
"}",
"const",
"parentEl",
"=",
"el",
"&&",
"el",
".",
"parentElement",
";",
"const",
"offsetBottom",
"=",
"el",
".",
"offsetTop",
"+",
"el",
".",
"offsetHeight",
";",
"const",
"scrollBottom",
"=",
"parentEl",
".",
"scrollTop",
"+",
"parentEl",
".",
"offsetHeight",
";",
"if",
"(",
"el",
".",
"offsetTop",
"<",
"parentEl",
".",
"scrollTop",
")",
"{",
"parentEl",
".",
"scrollTop",
"=",
"el",
".",
"offsetTop",
";",
"}",
"else",
"if",
"(",
"offsetBottom",
">",
"scrollBottom",
")",
"{",
"parentEl",
".",
"scrollTop",
"=",
"offsetBottom",
"-",
"parentEl",
".",
"offsetHeight",
";",
"}",
"}"
] | Scrolls the parent element until the child element is in view | [
"Scrolls",
"the",
"parent",
"element",
"until",
"the",
"child",
"element",
"is",
"in",
"view"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/element-scroll/index.js#L4-L18 |
8,758 | eBay/ebayui-core | src/common/event-utils/index.js | handleKeydown | function handleKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) !== -1) {
callback();
}
} | javascript | function handleKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) !== -1) {
callback();
}
} | [
"function",
"handleKeydown",
"(",
"keyCodes",
",",
"e",
",",
"callback",
")",
"{",
"const",
"keyCode",
"=",
"e",
".",
"charCode",
"||",
"e",
".",
"keyCode",
";",
"if",
"(",
"keyCodes",
".",
"indexOf",
"(",
"keyCode",
")",
"!==",
"-",
"1",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}"
] | Generic keydown handler used by more specific cases
@param {Array} keyCodes: List of acceptable keyCodes
@param {KeyboardEvent} e
@param {Function} callback | [
"Generic",
"keydown",
"handler",
"used",
"by",
"more",
"specific",
"cases"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/event-utils/index.js#L7-L12 |
8,759 | eBay/ebayui-core | src/common/event-utils/index.js | handleNotKeydown | function handleNotKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) === -1) {
callback();
}
} | javascript | function handleNotKeydown(keyCodes, e, callback) {
const keyCode = e.charCode || e.keyCode;
if (keyCodes.indexOf(keyCode) === -1) {
callback();
}
} | [
"function",
"handleNotKeydown",
"(",
"keyCodes",
",",
"e",
",",
"callback",
")",
"{",
"const",
"keyCode",
"=",
"e",
".",
"charCode",
"||",
"e",
".",
"keyCode",
";",
"if",
"(",
"keyCodes",
".",
"indexOf",
"(",
"keyCode",
")",
"===",
"-",
"1",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}"
] | inverse of found keys | [
"inverse",
"of",
"found",
"keys"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/common/event-utils/index.js#L15-L20 |
8,760 | eBay/ebayui-core | demo/utils.js | isDirectory | function isDirectory(obj) {
return obj.sources.every(path => {
try {
return fs.lstatSync(path).isDirectory();
} catch (e) {
return false;
}
});
} | javascript | function isDirectory(obj) {
return obj.sources.every(path => {
try {
return fs.lstatSync(path).isDirectory();
} catch (e) {
return false;
}
});
} | [
"function",
"isDirectory",
"(",
"obj",
")",
"{",
"return",
"obj",
".",
"sources",
".",
"every",
"(",
"path",
"=>",
"{",
"try",
"{",
"return",
"fs",
".",
"lstatSync",
"(",
"path",
")",
".",
"isDirectory",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"}"
] | check that paths exist as directories | [
"check",
"that",
"paths",
"exist",
"as",
"directories"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/demo/utils.js#L4-L12 |
8,761 | eBay/ebayui-core | src/components/ebay-combobox-readonly/index.js | handleOptionClick | function handleOptionClick(event) {
let el;
// find the element with the data
// start with the target element
if (event.target.dataset.optionValue) {
el = event.target;
// check up the tree one level (in case option text or status was clicked)
} else if (event.target.parentNode.dataset.optionValue) {
el = event.target.parentNode;
}
this.processAfterStateChange(el);
this.expander.collapse();
this.el.querySelector(comboboxHostSelector).focus();
} | javascript | function handleOptionClick(event) {
let el;
// find the element with the data
// start with the target element
if (event.target.dataset.optionValue) {
el = event.target;
// check up the tree one level (in case option text or status was clicked)
} else if (event.target.parentNode.dataset.optionValue) {
el = event.target.parentNode;
}
this.processAfterStateChange(el);
this.expander.collapse();
this.el.querySelector(comboboxHostSelector).focus();
} | [
"function",
"handleOptionClick",
"(",
"event",
")",
"{",
"let",
"el",
";",
"// find the element with the data",
"// start with the target element",
"if",
"(",
"event",
".",
"target",
".",
"dataset",
".",
"optionValue",
")",
"{",
"el",
"=",
"event",
".",
"target",
";",
"// check up the tree one level (in case option text or status was clicked)",
"}",
"else",
"if",
"(",
"event",
".",
"target",
".",
"parentNode",
".",
"dataset",
".",
"optionValue",
")",
"{",
"el",
"=",
"event",
".",
"target",
".",
"parentNode",
";",
"}",
"this",
".",
"processAfterStateChange",
"(",
"el",
")",
";",
"this",
".",
"expander",
".",
"collapse",
"(",
")",
";",
"this",
".",
"el",
".",
"querySelector",
"(",
"comboboxHostSelector",
")",
".",
"focus",
"(",
")",
";",
"}"
] | Handle mouse click for option
@param {MouseEvent} event | [
"Handle",
"mouse",
"click",
"for",
"option"
] | a7250c25eaab355881947c159301a78865d0d5c9 | https://github.com/eBay/ebayui-core/blob/a7250c25eaab355881947c159301a78865d0d5c9/src/components/ebay-combobox-readonly/index.js#L117-L132 |
8,762 | mattermost/mattermost-redux | src/actions/websocket.js | handleChannelConvertedEvent | function handleChannelConvertedEvent(msg) {
return (dispatch, getState) => {
const channelId = msg.data.channel_id;
if (channelId) {
const channel = getChannel(getState(), channelId);
if (channel) {
dispatch({
type: ChannelTypes.RECEIVED_CHANNEL,
data: {...channel, type: General.PRIVATE_CHANNEL},
});
}
}
};
} | javascript | function handleChannelConvertedEvent(msg) {
return (dispatch, getState) => {
const channelId = msg.data.channel_id;
if (channelId) {
const channel = getChannel(getState(), channelId);
if (channel) {
dispatch({
type: ChannelTypes.RECEIVED_CHANNEL,
data: {...channel, type: General.PRIVATE_CHANNEL},
});
}
}
};
} | [
"function",
"handleChannelConvertedEvent",
"(",
"msg",
")",
"{",
"return",
"(",
"dispatch",
",",
"getState",
")",
"=>",
"{",
"const",
"channelId",
"=",
"msg",
".",
"data",
".",
"channel_id",
";",
"if",
"(",
"channelId",
")",
"{",
"const",
"channel",
"=",
"getChannel",
"(",
"getState",
"(",
")",
",",
"channelId",
")",
";",
"if",
"(",
"channel",
")",
"{",
"dispatch",
"(",
"{",
"type",
":",
"ChannelTypes",
".",
"RECEIVED_CHANNEL",
",",
"data",
":",
"{",
"...",
"channel",
",",
"type",
":",
"General",
".",
"PRIVATE_CHANNEL",
"}",
",",
"}",
")",
";",
"}",
"}",
"}",
";",
"}"
] | handleChannelConvertedEvent handles updating of channel which is converted from public to private | [
"handleChannelConvertedEvent",
"handles",
"updating",
"of",
"channel",
"which",
"is",
"converted",
"from",
"public",
"to",
"private"
] | a6b5a325126821c8e6fe22a3dbef747a4d325c5e | https://github.com/mattermost/mattermost-redux/blob/a6b5a325126821c8e6fe22a3dbef747a4d325c5e/src/actions/websocket.js#L546-L559 |
8,763 | zeit/ms | index.js | plural | function plural(ms, msAbs, n, name) {
var isPlural = msAbs >= n * 1.5;
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
} | javascript | function plural(ms, msAbs, n, name) {
var isPlural = msAbs >= n * 1.5;
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
} | [
"function",
"plural",
"(",
"ms",
",",
"msAbs",
",",
"n",
",",
"name",
")",
"{",
"var",
"isPlural",
"=",
"msAbs",
">=",
"n",
"*",
"1.5",
";",
"return",
"Math",
".",
"round",
"(",
"ms",
"/",
"n",
")",
"+",
"' '",
"+",
"name",
"+",
"(",
"isPlural",
"?",
"'s'",
":",
"''",
")",
";",
"}"
] | Pluralization helper. | [
"Pluralization",
"helper",
"."
] | d1add60365fe2340b750b1f7a254b83bea34e52d | https://github.com/zeit/ms/blob/d1add60365fe2340b750b1f7a254b83bea34e52d/index.js#L159-L162 |
8,764 | pqina/vue-filepond | dist/vue-filepond.js | getNativeConstructorFromType | function getNativeConstructorFromType(type) {
return {
string: String,
boolean: Boolean,
array: Array,
function: Function,
int: Number,
serverapi: Object,
object: Object
}[type];
} | javascript | function getNativeConstructorFromType(type) {
return {
string: String,
boolean: Boolean,
array: Array,
function: Function,
int: Number,
serverapi: Object,
object: Object
}[type];
} | [
"function",
"getNativeConstructorFromType",
"(",
"type",
")",
"{",
"return",
"{",
"string",
":",
"String",
",",
"boolean",
":",
"Boolean",
",",
"array",
":",
"Array",
",",
"function",
":",
"Function",
",",
"int",
":",
"Number",
",",
"serverapi",
":",
"Object",
",",
"object",
":",
"Object",
"}",
"[",
"type",
"]",
";",
"}"
] | Setup initial prop types and update when plugins are added | [
"Setup",
"initial",
"prop",
"types",
"and",
"update",
"when",
"plugins",
"are",
"added"
] | bf7ea99e11da095eb10b4f703be0827e807130b7 | https://github.com/pqina/vue-filepond/blob/bf7ea99e11da095eb10b4f703be0827e807130b7/dist/vue-filepond.js#L46-L56 |
8,765 | greggman/twgl.js | src/helper.js | copyExistingProperties | function copyExistingProperties(src, dst) {
Object.keys(dst).forEach(function(key) {
if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
dst[key] = src[key];
}
});
} | javascript | function copyExistingProperties(src, dst) {
Object.keys(dst).forEach(function(key) {
if (dst.hasOwnProperty(key) && src.hasOwnProperty(key)) {
dst[key] = src[key];
}
});
} | [
"function",
"copyExistingProperties",
"(",
"src",
",",
"dst",
")",
"{",
"Object",
".",
"keys",
"(",
"dst",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"dst",
".",
"hasOwnProperty",
"(",
"key",
")",
"&&",
"src",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"dst",
"[",
"key",
"]",
"=",
"src",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"}"
] | Copies properties from source to dest only if a matching key is in dest
@param {Object.<string, ?>} src the source
@param {Object.<string, ?>} dst the dest
@private | [
"Copies",
"properties",
"from",
"source",
"to",
"dest",
"only",
"if",
"a",
"matching",
"key",
"is",
"in",
"dest"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/helper.js#L49-L55 |
8,766 | greggman/twgl.js | src/twgl.js | setDefaults | function setDefaults(newDefaults) {
helper.copyExistingProperties(newDefaults, defaults);
attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
textures.setTextureDefaults_(newDefaults); // eslint-disable-line
} | javascript | function setDefaults(newDefaults) {
helper.copyExistingProperties(newDefaults, defaults);
attributes.setAttributeDefaults_(newDefaults); // eslint-disable-line
textures.setTextureDefaults_(newDefaults); // eslint-disable-line
} | [
"function",
"setDefaults",
"(",
"newDefaults",
")",
"{",
"helper",
".",
"copyExistingProperties",
"(",
"newDefaults",
",",
"defaults",
")",
";",
"attributes",
".",
"setAttributeDefaults_",
"(",
"newDefaults",
")",
";",
"// eslint-disable-line",
"textures",
".",
"setTextureDefaults_",
"(",
"newDefaults",
")",
";",
"// eslint-disable-line",
"}"
] | Various default settings for twgl.
Note: You can call this any number of times. Example:
twgl.setDefaults({ textureColor: [1, 0, 0, 1] });
twgl.setDefaults({ attribPrefix: 'a_' });
is equivalent to
twgl.setDefaults({
textureColor: [1, 0, 0, 1],
attribPrefix: 'a_',
});
@typedef {Object} Defaults
@property {string} [attribPrefix] The prefix to stick on attributes
When writing shaders I prefer to name attributes with `a_`, uniforms with `u_` and varyings with `v_`
as it makes it clear where they came from. But, when building geometry I prefer using unprefixed names.
In otherwords I'll create arrays of geometry like this
const arrays = {
position: ...
normal: ...
texcoord: ...
};
But need those mapped to attributes and my attributes start with `a_`.
Default: `""`
@property {number[]} [textureColor] Array of 4 values in the range 0 to 1
The default texture color is used when loading textures from
urls. Because the URL will be loaded async we'd like to be
able to use the texture immediately. By putting a 1x1 pixel
color in the texture we can start using the texture before
the URL has loaded.
Default: `[0.5, 0.75, 1, 1]`
@property {string} [crossOrigin]
If not undefined sets the crossOrigin attribute on images
that twgl creates when downloading images for textures.
Also see {@link module:twgl.TextureOptions}.
@property {bool} [addExtensionsToContext]
If true, then, when twgl will try to add any supported WebGL extensions
directly to the context under their normal GL names. For example
if ANGLE_instances_arrays exists then twgl would enable it,
add the functions `vertexAttribDivisor`, `drawArraysInstanced`,
`drawElementsInstanced`, and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR`
to the `WebGLRenderingContext`.
@memberOf module:twgl
Sets various defaults for twgl.
In the interest of terseness which is kind of the point
of twgl I've integrated a few of the older functions here
@param {module:twgl.Defaults} newDefaults The default settings.
@memberOf module:twgl | [
"Various",
"default",
"settings",
"for",
"twgl",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/twgl.js#L133-L137 |
8,767 | greggman/twgl.js | src/twgl.js | addExtensionsToContext | function addExtensionsToContext(gl) {
for (let ii = 0; ii < supportedExtensions.length; ++ii) {
addExtensionToContext(gl, supportedExtensions[ii]);
}
} | javascript | function addExtensionsToContext(gl) {
for (let ii = 0; ii < supportedExtensions.length; ++ii) {
addExtensionToContext(gl, supportedExtensions[ii]);
}
} | [
"function",
"addExtensionsToContext",
"(",
"gl",
")",
"{",
"for",
"(",
"let",
"ii",
"=",
"0",
";",
"ii",
"<",
"supportedExtensions",
".",
"length",
";",
"++",
"ii",
")",
"{",
"addExtensionToContext",
"(",
"gl",
",",
"supportedExtensions",
"[",
"ii",
"]",
")",
";",
"}",
"}"
] | Attempts to enable all of the following extensions
and add their functions and constants to the
`WebGLRenderingContext` using their normal non-extension like names.
ANGLE_instanced_arrays
EXT_blend_minmax
EXT_color_buffer_float
EXT_color_buffer_half_float
EXT_disjoint_timer_query
EXT_disjoint_timer_query_webgl2
EXT_frag_depth
EXT_sRGB
EXT_shader_texture_lod
EXT_texture_filter_anisotropic
OES_element_index_uint
OES_standard_derivatives
OES_texture_float
OES_texture_float_linear
OES_texture_half_float
OES_texture_half_float_linear
OES_vertex_array_object
WEBGL_color_buffer_float
WEBGL_compressed_texture_atc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_pvrtc
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_depth_texture
WEBGL_draw_buffers
For example if `ANGLE_instanced_arrays` exists then the functions
`drawArraysInstanced`, `drawElementsInstanced`, `vertexAttribDivisor`
and the constant `VERTEX_ATTRIB_ARRAY_DIVISOR` are added to the
`WebGLRenderingContext`.
Note that if you want to know if the extension exists you should
probably call `gl.getExtension` for each extension. Alternatively
you can check for the existance of the functions or constants that
are expected to be added. For example
if (gl.drawBuffers) {
// Either WEBGL_draw_buffers was enabled OR you're running in WebGL2
....
@param {WebGLRenderingContext} gl A WebGLRenderingContext
@memberOf module:twgl | [
"Attempts",
"to",
"enable",
"all",
"of",
"the",
"following",
"extensions",
"and",
"add",
"their",
"functions",
"and",
"constants",
"to",
"the",
"WebGLRenderingContext",
"using",
"their",
"normal",
"non",
"-",
"extension",
"like",
"names",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/twgl.js#L267-L271 |
8,768 | greggman/twgl.js | src/twgl.js | createContext | function createContext(canvas, opt_attribs) {
const names = ["webgl2", "webgl", "experimental-webgl"];
let context = null;
for (let ii = 0; ii < names.length; ++ii) {
context = canvas.getContext(names[ii], opt_attribs);
if (context) {
if (defaults.addExtensionsToContext) {
addExtensionsToContext(context);
}
break;
}
}
return context;
} | javascript | function createContext(canvas, opt_attribs) {
const names = ["webgl2", "webgl", "experimental-webgl"];
let context = null;
for (let ii = 0; ii < names.length; ++ii) {
context = canvas.getContext(names[ii], opt_attribs);
if (context) {
if (defaults.addExtensionsToContext) {
addExtensionsToContext(context);
}
break;
}
}
return context;
} | [
"function",
"createContext",
"(",
"canvas",
",",
"opt_attribs",
")",
"{",
"const",
"names",
"=",
"[",
"\"webgl2\"",
",",
"\"webgl\"",
",",
"\"experimental-webgl\"",
"]",
";",
"let",
"context",
"=",
"null",
";",
"for",
"(",
"let",
"ii",
"=",
"0",
";",
"ii",
"<",
"names",
".",
"length",
";",
"++",
"ii",
")",
"{",
"context",
"=",
"canvas",
".",
"getContext",
"(",
"names",
"[",
"ii",
"]",
",",
"opt_attribs",
")",
";",
"if",
"(",
"context",
")",
"{",
"if",
"(",
"defaults",
".",
"addExtensionsToContext",
")",
"{",
"addExtensionsToContext",
"(",
"context",
")",
";",
"}",
"break",
";",
"}",
"}",
"return",
"context",
";",
"}"
] | Creates a webgl context.
Will return a WebGL2 context if possible.
You can check if it's WebGL2 with
twgl.isWebGL2(gl);
@param {HTMLCanvasElement} canvas The canvas tag to get
context from. If one is not passed in one will be
created.
@return {WebGLRenderingContext} The created context. | [
"Creates",
"a",
"webgl",
"context",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/twgl.js#L327-L340 |
8,769 | greggman/twgl.js | src/draw.js | drawBufferInfo | function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
type = type === undefined ? gl.TRIANGLES : type;
const indices = bufferInfo.indices;
const elementType = bufferInfo.elementType;
const numElements = count === undefined ? bufferInfo.numElements : count;
offset = offset === undefined ? 0 : offset;
if (elementType || indices) {
if (instanceCount !== undefined) {
gl.drawElementsInstanced(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
} else {
gl.drawElements(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset);
}
} else {
if (instanceCount !== undefined) {
gl.drawArraysInstanced(type, offset, numElements, instanceCount);
} else {
gl.drawArrays(type, offset, numElements);
}
}
} | javascript | function drawBufferInfo(gl, bufferInfo, type, count, offset, instanceCount) {
type = type === undefined ? gl.TRIANGLES : type;
const indices = bufferInfo.indices;
const elementType = bufferInfo.elementType;
const numElements = count === undefined ? bufferInfo.numElements : count;
offset = offset === undefined ? 0 : offset;
if (elementType || indices) {
if (instanceCount !== undefined) {
gl.drawElementsInstanced(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset, instanceCount);
} else {
gl.drawElements(type, numElements, elementType === undefined ? gl.UNSIGNED_SHORT : bufferInfo.elementType, offset);
}
} else {
if (instanceCount !== undefined) {
gl.drawArraysInstanced(type, offset, numElements, instanceCount);
} else {
gl.drawArrays(type, offset, numElements);
}
}
} | [
"function",
"drawBufferInfo",
"(",
"gl",
",",
"bufferInfo",
",",
"type",
",",
"count",
",",
"offset",
",",
"instanceCount",
")",
"{",
"type",
"=",
"type",
"===",
"undefined",
"?",
"gl",
".",
"TRIANGLES",
":",
"type",
";",
"const",
"indices",
"=",
"bufferInfo",
".",
"indices",
";",
"const",
"elementType",
"=",
"bufferInfo",
".",
"elementType",
";",
"const",
"numElements",
"=",
"count",
"===",
"undefined",
"?",
"bufferInfo",
".",
"numElements",
":",
"count",
";",
"offset",
"=",
"offset",
"===",
"undefined",
"?",
"0",
":",
"offset",
";",
"if",
"(",
"elementType",
"||",
"indices",
")",
"{",
"if",
"(",
"instanceCount",
"!==",
"undefined",
")",
"{",
"gl",
".",
"drawElementsInstanced",
"(",
"type",
",",
"numElements",
",",
"elementType",
"===",
"undefined",
"?",
"gl",
".",
"UNSIGNED_SHORT",
":",
"bufferInfo",
".",
"elementType",
",",
"offset",
",",
"instanceCount",
")",
";",
"}",
"else",
"{",
"gl",
".",
"drawElements",
"(",
"type",
",",
"numElements",
",",
"elementType",
"===",
"undefined",
"?",
"gl",
".",
"UNSIGNED_SHORT",
":",
"bufferInfo",
".",
"elementType",
",",
"offset",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"instanceCount",
"!==",
"undefined",
")",
"{",
"gl",
".",
"drawArraysInstanced",
"(",
"type",
",",
"offset",
",",
"numElements",
",",
"instanceCount",
")",
";",
"}",
"else",
"{",
"gl",
".",
"drawArrays",
"(",
"type",
",",
"offset",
",",
"numElements",
")",
";",
"}",
"}",
"}"
] | Drawing related functions
For backward compatibily they are available at both `twgl.draw` and `twgl`
itself
See {@link module:twgl} for core functions
@module twgl/draw
Calls `gl.drawElements` or `gl.drawArrays`, whichever is appropriate
normally you'd call `gl.drawElements` or `gl.drawArrays` yourself
but calling this means if you switch from indexed data to non-indexed
data you don't have to remember to update your draw call.
@param {WebGLRenderingContext} gl A WebGLRenderingContext
@param {(module:twgl.BufferInfo|module:twgl.VertexArrayInfo)} bufferInfo A BufferInfo as returned from {@link module:twgl.createBufferInfoFromArrays} or
a VertexArrayInfo as returned from {@link module:twgl.createVertexArrayInfo}
@param {number} [type] eg (gl.TRIANGLES, gl.LINES, gl.POINTS, gl.TRIANGLE_STRIP, ...). Defaults to `gl.TRIANGLES`
@param {number} [count] An optional count. Defaults to bufferInfo.numElements
@param {number} [offset] An optional offset. Defaults to 0.
@param {number} [instanceCount] An optional instanceCount. if set then `drawArraysInstanced` or `drawElementsInstanced` will be called
@memberOf module:twgl/draw | [
"Drawing",
"related",
"functions"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/draw.js#L52-L71 |
8,770 | greggman/twgl.js | src/typedarrays.js | getGLTypeForTypedArray | function getGLTypeForTypedArray(typedArray) {
if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line
if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line
if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | javascript | function getGLTypeForTypedArray(typedArray) {
if (typedArray instanceof Int8Array) { return BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArray instanceof Int16Array) { return SHORT; } // eslint-disable-line
if (typedArray instanceof Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArray instanceof Int32Array) { return INT; } // eslint-disable-line
if (typedArray instanceof Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArray instanceof Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | [
"function",
"getGLTypeForTypedArray",
"(",
"typedArray",
")",
"{",
"if",
"(",
"typedArray",
"instanceof",
"Int8Array",
")",
"{",
"return",
"BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Uint8Array",
")",
"{",
"return",
"UNSIGNED_BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Uint8ClampedArray",
")",
"{",
"return",
"UNSIGNED_BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Int16Array",
")",
"{",
"return",
"SHORT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Uint16Array",
")",
"{",
"return",
"UNSIGNED_SHORT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Int32Array",
")",
"{",
"return",
"INT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Uint32Array",
")",
"{",
"return",
"UNSIGNED_INT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArray",
"instanceof",
"Float32Array",
")",
"{",
"return",
"FLOAT",
";",
"}",
"// eslint-disable-line",
"throw",
"\"unsupported typed array type\"",
";",
"}"
] | Get the GL type for a typedArray
@param {ArrayBufferView} typedArray a typedArray
@return {number} the GL type for array. For example pass in an `Int8Array` and `gl.BYTE` will
be returned. Pass in a `Uint32Array` and `gl.UNSIGNED_INT` will be returned
@memberOf module:twgl/typedArray | [
"Get",
"the",
"GL",
"type",
"for",
"a",
"typedArray"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/typedarrays.js#L87-L97 |
8,771 | greggman/twgl.js | src/typedarrays.js | getGLTypeForTypedArrayType | function getGLTypeForTypedArrayType(typedArrayType) {
if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line
if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line
if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line
if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | javascript | function getGLTypeForTypedArrayType(typedArrayType) {
if (typedArrayType === Int8Array) { return BYTE; } // eslint-disable-line
if (typedArrayType === Uint8Array) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Uint8ClampedArray) { return UNSIGNED_BYTE; } // eslint-disable-line
if (typedArrayType === Int16Array) { return SHORT; } // eslint-disable-line
if (typedArrayType === Uint16Array) { return UNSIGNED_SHORT; } // eslint-disable-line
if (typedArrayType === Int32Array) { return INT; } // eslint-disable-line
if (typedArrayType === Uint32Array) { return UNSIGNED_INT; } // eslint-disable-line
if (typedArrayType === Float32Array) { return FLOAT; } // eslint-disable-line
throw "unsupported typed array type";
} | [
"function",
"getGLTypeForTypedArrayType",
"(",
"typedArrayType",
")",
"{",
"if",
"(",
"typedArrayType",
"===",
"Int8Array",
")",
"{",
"return",
"BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Uint8Array",
")",
"{",
"return",
"UNSIGNED_BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Uint8ClampedArray",
")",
"{",
"return",
"UNSIGNED_BYTE",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Int16Array",
")",
"{",
"return",
"SHORT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Uint16Array",
")",
"{",
"return",
"UNSIGNED_SHORT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Int32Array",
")",
"{",
"return",
"INT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Uint32Array",
")",
"{",
"return",
"UNSIGNED_INT",
";",
"}",
"// eslint-disable-line",
"if",
"(",
"typedArrayType",
"===",
"Float32Array",
")",
"{",
"return",
"FLOAT",
";",
"}",
"// eslint-disable-line",
"throw",
"\"unsupported typed array type\"",
";",
"}"
] | Get the GL type for a typedArray type
@param {ArrayBufferView} typedArrayType a typedArray constructor
@return {number} the GL type for type. For example pass in `Int8Array` and `gl.BYTE` will
be returned. Pass in `Uint32Array` and `gl.UNSIGNED_INT` will be returned
@memberOf module:twgl/typedArray | [
"Get",
"the",
"GL",
"type",
"for",
"a",
"typedArray",
"type"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/typedarrays.js#L106-L116 |
8,772 | greggman/twgl.js | src/m4.js | negate | function negate(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = -m[ 0];
dst[ 1] = -m[ 1];
dst[ 2] = -m[ 2];
dst[ 3] = -m[ 3];
dst[ 4] = -m[ 4];
dst[ 5] = -m[ 5];
dst[ 6] = -m[ 6];
dst[ 7] = -m[ 7];
dst[ 8] = -m[ 8];
dst[ 9] = -m[ 9];
dst[10] = -m[10];
dst[11] = -m[11];
dst[12] = -m[12];
dst[13] = -m[13];
dst[14] = -m[14];
dst[15] = -m[15];
return dst;
} | javascript | function negate(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = -m[ 0];
dst[ 1] = -m[ 1];
dst[ 2] = -m[ 2];
dst[ 3] = -m[ 3];
dst[ 4] = -m[ 4];
dst[ 5] = -m[ 5];
dst[ 6] = -m[ 6];
dst[ 7] = -m[ 7];
dst[ 8] = -m[ 8];
dst[ 9] = -m[ 9];
dst[10] = -m[10];
dst[11] = -m[11];
dst[12] = -m[12];
dst[13] = -m[13];
dst[14] = -m[14];
dst[15] = -m[15];
return dst;
} | [
"function",
"negate",
"(",
"m",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"-",
"m",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"-",
"m",
"[",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"-",
"m",
"[",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"-",
"m",
"[",
"3",
"]",
";",
"dst",
"[",
"4",
"]",
"=",
"-",
"m",
"[",
"4",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"-",
"m",
"[",
"5",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"-",
"m",
"[",
"6",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"-",
"m",
"[",
"7",
"]",
";",
"dst",
"[",
"8",
"]",
"=",
"-",
"m",
"[",
"8",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"-",
"m",
"[",
"9",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"-",
"m",
"[",
"10",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"-",
"m",
"[",
"11",
"]",
";",
"dst",
"[",
"12",
"]",
"=",
"-",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"-",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"-",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"-",
"m",
"[",
"15",
"]",
";",
"return",
"dst",
";",
"}"
] | Negates a matrix.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} -m.
@memberOf module:twgl/m4 | [
"Negates",
"a",
"matrix",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L82-L103 |
8,773 | greggman/twgl.js | src/m4.js | copy | function copy(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
return dst;
} | javascript | function copy(m, dst) {
dst = dst || new MatType(16);
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
return dst;
} | [
"function",
"copy",
"(",
"m",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"m",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"m",
"[",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"m",
"[",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"m",
"[",
"3",
"]",
";",
"dst",
"[",
"4",
"]",
"=",
"m",
"[",
"4",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"m",
"[",
"5",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"m",
"[",
"6",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"m",
"[",
"7",
"]",
";",
"dst",
"[",
"8",
"]",
"=",
"m",
"[",
"8",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"m",
"[",
"9",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"m",
"[",
"10",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"m",
"[",
"11",
"]",
";",
"dst",
"[",
"12",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"m",
"[",
"15",
"]",
";",
"return",
"dst",
";",
"}"
] | Copies a matrix.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/m4.Mat4} [dst] The matrix.
@return {module:twgl/m4.Mat4} A copy of m.
@memberOf module:twgl/m4 | [
"Copies",
"a",
"matrix",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L112-L133 |
8,774 | greggman/twgl.js | src/m4.js | identity | function identity(dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | function identity(dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | [
"function",
"identity",
"(",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"1",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"1",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"1",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"0",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Creates an n-by-n identity matrix.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} An n-by-n identity matrix.
@memberOf module:twgl/m4 | [
"Creates",
"an",
"n",
"-",
"by",
"-",
"n",
"identity",
"matrix",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L142-L163 |
8,775 | greggman/twgl.js | src/m4.js | transpose | function transpose(m, dst) {
dst = dst || new MatType(16);
if (dst === m) {
let t;
t = m[1];
m[1] = m[4];
m[4] = t;
t = m[2];
m[2] = m[8];
m[8] = t;
t = m[3];
m[3] = m[12];
m[12] = t;
t = m[6];
m[6] = m[9];
m[9] = t;
t = m[7];
m[7] = m[13];
m[13] = t;
t = m[11];
m[11] = m[14];
m[14] = t;
return dst;
}
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
dst[ 0] = m00;
dst[ 1] = m10;
dst[ 2] = m20;
dst[ 3] = m30;
dst[ 4] = m01;
dst[ 5] = m11;
dst[ 6] = m21;
dst[ 7] = m31;
dst[ 8] = m02;
dst[ 9] = m12;
dst[10] = m22;
dst[11] = m32;
dst[12] = m03;
dst[13] = m13;
dst[14] = m23;
dst[15] = m33;
return dst;
} | javascript | function transpose(m, dst) {
dst = dst || new MatType(16);
if (dst === m) {
let t;
t = m[1];
m[1] = m[4];
m[4] = t;
t = m[2];
m[2] = m[8];
m[8] = t;
t = m[3];
m[3] = m[12];
m[12] = t;
t = m[6];
m[6] = m[9];
m[9] = t;
t = m[7];
m[7] = m[13];
m[13] = t;
t = m[11];
m[11] = m[14];
m[14] = t;
return dst;
}
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
dst[ 0] = m00;
dst[ 1] = m10;
dst[ 2] = m20;
dst[ 3] = m30;
dst[ 4] = m01;
dst[ 5] = m11;
dst[ 6] = m21;
dst[ 7] = m31;
dst[ 8] = m02;
dst[ 9] = m12;
dst[10] = m22;
dst[11] = m32;
dst[12] = m03;
dst[13] = m13;
dst[14] = m23;
dst[15] = m33;
return dst;
} | [
"function",
"transpose",
"(",
"m",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"if",
"(",
"dst",
"===",
"m",
")",
"{",
"let",
"t",
";",
"t",
"=",
"m",
"[",
"1",
"]",
";",
"m",
"[",
"1",
"]",
"=",
"m",
"[",
"4",
"]",
";",
"m",
"[",
"4",
"]",
"=",
"t",
";",
"t",
"=",
"m",
"[",
"2",
"]",
";",
"m",
"[",
"2",
"]",
"=",
"m",
"[",
"8",
"]",
";",
"m",
"[",
"8",
"]",
"=",
"t",
";",
"t",
"=",
"m",
"[",
"3",
"]",
";",
"m",
"[",
"3",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"m",
"[",
"12",
"]",
"=",
"t",
";",
"t",
"=",
"m",
"[",
"6",
"]",
";",
"m",
"[",
"6",
"]",
"=",
"m",
"[",
"9",
"]",
";",
"m",
"[",
"9",
"]",
"=",
"t",
";",
"t",
"=",
"m",
"[",
"7",
"]",
";",
"m",
"[",
"7",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"m",
"[",
"13",
"]",
"=",
"t",
";",
"t",
"=",
"m",
"[",
"11",
"]",
";",
"m",
"[",
"11",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"m",
"[",
"14",
"]",
"=",
"t",
";",
"return",
"dst",
";",
"}",
"const",
"m00",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m01",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m02",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m03",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m10",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m11",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m12",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m13",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m20",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m21",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m22",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m23",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m30",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m31",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m32",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m33",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"3",
"]",
";",
"dst",
"[",
"0",
"]",
"=",
"m00",
";",
"dst",
"[",
"1",
"]",
"=",
"m10",
";",
"dst",
"[",
"2",
"]",
"=",
"m20",
";",
"dst",
"[",
"3",
"]",
"=",
"m30",
";",
"dst",
"[",
"4",
"]",
"=",
"m01",
";",
"dst",
"[",
"5",
"]",
"=",
"m11",
";",
"dst",
"[",
"6",
"]",
"=",
"m21",
";",
"dst",
"[",
"7",
"]",
"=",
"m31",
";",
"dst",
"[",
"8",
"]",
"=",
"m02",
";",
"dst",
"[",
"9",
"]",
"=",
"m12",
";",
"dst",
"[",
"10",
"]",
"=",
"m22",
";",
"dst",
"[",
"11",
"]",
"=",
"m32",
";",
"dst",
"[",
"12",
"]",
"=",
"m03",
";",
"dst",
"[",
"13",
"]",
"=",
"m13",
";",
"dst",
"[",
"14",
"]",
"=",
"m23",
";",
"dst",
"[",
"15",
"]",
"=",
"m33",
";",
"return",
"dst",
";",
"}"
] | Takes the transpose of a matrix.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The transpose of m.
@memberOf module:twgl/m4 | [
"Takes",
"the",
"transpose",
"of",
"a",
"matrix",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L172-L238 |
8,776 | greggman/twgl.js | src/m4.js | setTranslation | function setTranslation(a, v, dst) {
dst = dst || identity();
if (a !== dst) {
dst[ 0] = a[ 0];
dst[ 1] = a[ 1];
dst[ 2] = a[ 2];
dst[ 3] = a[ 3];
dst[ 4] = a[ 4];
dst[ 5] = a[ 5];
dst[ 6] = a[ 6];
dst[ 7] = a[ 7];
dst[ 8] = a[ 8];
dst[ 9] = a[ 9];
dst[10] = a[10];
dst[11] = a[11];
}
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | javascript | function setTranslation(a, v, dst) {
dst = dst || identity();
if (a !== dst) {
dst[ 0] = a[ 0];
dst[ 1] = a[ 1];
dst[ 2] = a[ 2];
dst[ 3] = a[ 3];
dst[ 4] = a[ 4];
dst[ 5] = a[ 5];
dst[ 6] = a[ 6];
dst[ 7] = a[ 7];
dst[ 8] = a[ 8];
dst[ 9] = a[ 9];
dst[10] = a[10];
dst[11] = a[11];
}
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | [
"function",
"setTranslation",
"(",
"a",
",",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"identity",
"(",
")",
";",
"if",
"(",
"a",
"!==",
"dst",
")",
"{",
"dst",
"[",
"0",
"]",
"=",
"a",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"a",
"[",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"a",
"[",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"a",
"[",
"3",
"]",
";",
"dst",
"[",
"4",
"]",
"=",
"a",
"[",
"4",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"a",
"[",
"5",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"a",
"[",
"6",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"a",
"[",
"7",
"]",
";",
"dst",
"[",
"8",
"]",
"=",
"a",
"[",
"8",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"a",
"[",
"9",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"a",
"[",
"10",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"a",
"[",
"11",
"]",
";",
"}",
"dst",
"[",
"12",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"v",
"[",
"1",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"v",
"[",
"2",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Sets the translation component of a 4-by-4 matrix to the given
vector.
@param {module:twgl/m4.Mat4} a The matrix.
@param {module:twgl/v3.Vec3} v The vector.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none, a new one is created.
@return {module:twgl/m4.Mat4} a once modified.
@memberOf module:twgl/m4 | [
"Sets",
"the",
"translation",
"component",
"of",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"to",
"the",
"given",
"vector",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L407-L428 |
8,777 | greggman/twgl.js | src/m4.js | getTranslation | function getTranslation(m, dst) {
dst = dst || v3.create();
dst[0] = m[12];
dst[1] = m[13];
dst[2] = m[14];
return dst;
} | javascript | function getTranslation(m, dst) {
dst = dst || v3.create();
dst[0] = m[12];
dst[1] = m[13];
dst[2] = m[14];
return dst;
} | [
"function",
"getTranslation",
"(",
"m",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"v3",
".",
"create",
"(",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"return",
"dst",
";",
"}"
] | Returns the translation component of a 4-by-4 matrix as a vector with 3
entries.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/v3.Vec3} [dst] vector.
@return {module:twgl/v3.Vec3} The translation component of m.
@memberOf module:twgl/m4 | [
"Returns",
"the",
"translation",
"component",
"of",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"as",
"a",
"vector",
"with",
"3",
"entries",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L438-L444 |
8,778 | greggman/twgl.js | src/m4.js | getAxis | function getAxis(m, axis, dst) {
dst = dst || v3.create();
const off = axis * 4;
dst[0] = m[off + 0];
dst[1] = m[off + 1];
dst[2] = m[off + 2];
return dst;
} | javascript | function getAxis(m, axis, dst) {
dst = dst || v3.create();
const off = axis * 4;
dst[0] = m[off + 0];
dst[1] = m[off + 1];
dst[2] = m[off + 2];
return dst;
} | [
"function",
"getAxis",
"(",
"m",
",",
"axis",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"v3",
".",
"create",
"(",
")",
";",
"const",
"off",
"=",
"axis",
"*",
"4",
";",
"dst",
"[",
"0",
"]",
"=",
"m",
"[",
"off",
"+",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"m",
"[",
"off",
"+",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"m",
"[",
"off",
"+",
"2",
"]",
";",
"return",
"dst",
";",
"}"
] | Returns an axis of a 4x4 matrix as a vector with 3 entries
@param {module:twgl/m4.Mat4} m The matrix.
@param {number} axis The axis 0 = x, 1 = y, 2 = z;
@return {module:twgl/v3.Vec3} [dst] vector.
@return {module:twgl/v3.Vec3} The axis component of m.
@memberOf module:twgl/m4 | [
"Returns",
"an",
"axis",
"of",
"a",
"4x4",
"matrix",
"as",
"a",
"vector",
"with",
"3",
"entries"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L454-L461 |
8,779 | greggman/twgl.js | src/m4.js | setAxis | function setAxis(a, v, axis, dst) {
if (dst !== a) {
dst = copy(a, dst);
}
const off = axis * 4;
dst[off + 0] = v[0];
dst[off + 1] = v[1];
dst[off + 2] = v[2];
return dst;
} | javascript | function setAxis(a, v, axis, dst) {
if (dst !== a) {
dst = copy(a, dst);
}
const off = axis * 4;
dst[off + 0] = v[0];
dst[off + 1] = v[1];
dst[off + 2] = v[2];
return dst;
} | [
"function",
"setAxis",
"(",
"a",
",",
"v",
",",
"axis",
",",
"dst",
")",
"{",
"if",
"(",
"dst",
"!==",
"a",
")",
"{",
"dst",
"=",
"copy",
"(",
"a",
",",
"dst",
")",
";",
"}",
"const",
"off",
"=",
"axis",
"*",
"4",
";",
"dst",
"[",
"off",
"+",
"0",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"dst",
"[",
"off",
"+",
"1",
"]",
"=",
"v",
"[",
"1",
"]",
";",
"dst",
"[",
"off",
"+",
"2",
"]",
"=",
"v",
"[",
"2",
"]",
";",
"return",
"dst",
";",
"}"
] | Sets an axis of a 4x4 matrix as a vector with 3 entries
@param {module:twgl/v3.Vec3} v the axis vector
@param {number} axis The axis 0 = x, 1 = y, 2 = z;
@param {module:twgl/m4.Mat4} [dst] The matrix to set. If none, a new one is created.
@return {module:twgl/m4.Mat4} dst
@memberOf module:twgl/m4 | [
"Sets",
"an",
"axis",
"of",
"a",
"4x4",
"matrix",
"as",
"a",
"vector",
"with",
"3",
"entries"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L471-L480 |
8,780 | greggman/twgl.js | src/m4.js | perspective | function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
dst = dst || new MatType(16);
const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
const rangeInv = 1.0 / (zNear - zFar);
dst[0] = f / aspect;
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = f;
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = (zNear + zFar) * rangeInv;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = zNear * zFar * rangeInv * 2;
dst[15] = 0;
return dst;
} | javascript | function perspective(fieldOfViewYInRadians, aspect, zNear, zFar, dst) {
dst = dst || new MatType(16);
const f = Math.tan(Math.PI * 0.5 - 0.5 * fieldOfViewYInRadians);
const rangeInv = 1.0 / (zNear - zFar);
dst[0] = f / aspect;
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = f;
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = (zNear + zFar) * rangeInv;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = zNear * zFar * rangeInv * 2;
dst[15] = 0;
return dst;
} | [
"function",
"perspective",
"(",
"fieldOfViewYInRadians",
",",
"aspect",
",",
"zNear",
",",
"zFar",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"f",
"=",
"Math",
".",
"tan",
"(",
"Math",
".",
"PI",
"*",
"0.5",
"-",
"0.5",
"*",
"fieldOfViewYInRadians",
")",
";",
"const",
"rangeInv",
"=",
"1.0",
"/",
"(",
"zNear",
"-",
"zFar",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"f",
"/",
"aspect",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"f",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"(",
"zNear",
"+",
"zFar",
")",
"*",
"rangeInv",
";",
"dst",
"[",
"11",
"]",
"=",
"-",
"1",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"zNear",
"*",
"zFar",
"*",
"rangeInv",
"*",
"2",
";",
"dst",
"[",
"15",
"]",
"=",
"0",
";",
"return",
"dst",
";",
"}"
] | Computes a 4-by-4 perspective transformation matrix given the angular height
of the frustum, the aspect ratio, and the near and far clipping planes. The
arguments define a frustum extending in the negative z direction. The given
angle is the vertical angle of the frustum, and the horizontal angle is
determined to produce the given aspect ratio. The arguments near and far are
the distances to the near and far clipping planes. Note that near and far
are not z coordinates, but rather they are distances along the negative
z-axis. The matrix generated sends the viewing frustum to the unit box.
We assume a unit box extending from -1 to 1 in the x and y dimensions and
from 0 to 1 in the z dimension.
@param {number} fieldOfViewYInRadians The camera angle from top to bottom (in radians).
@param {number} aspect The aspect ratio width / height.
@param {number} zNear The depth (negative z coordinate)
of the near clipping plane.
@param {number} zFar The depth (negative z coordinate)
of the far clipping plane.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The perspective matrix.
@memberOf module:twgl/m4 | [
"Computes",
"a",
"4",
"-",
"by",
"-",
"4",
"perspective",
"transformation",
"matrix",
"given",
"the",
"angular",
"height",
"of",
"the",
"frustum",
"the",
"aspect",
"ratio",
"and",
"the",
"near",
"and",
"far",
"clipping",
"planes",
".",
"The",
"arguments",
"define",
"a",
"frustum",
"extending",
"in",
"the",
"negative",
"z",
"direction",
".",
"The",
"given",
"angle",
"is",
"the",
"vertical",
"angle",
"of",
"the",
"frustum",
"and",
"the",
"horizontal",
"angle",
"is",
"determined",
"to",
"produce",
"the",
"given",
"aspect",
"ratio",
".",
"The",
"arguments",
"near",
"and",
"far",
"are",
"the",
"distances",
"to",
"the",
"near",
"and",
"far",
"clipping",
"planes",
".",
"Note",
"that",
"near",
"and",
"far",
"are",
"not",
"z",
"coordinates",
"but",
"rather",
"they",
"are",
"distances",
"along",
"the",
"negative",
"z",
"-",
"axis",
".",
"The",
"matrix",
"generated",
"sends",
"the",
"viewing",
"frustum",
"to",
"the",
"unit",
"box",
".",
"We",
"assume",
"a",
"unit",
"box",
"extending",
"from",
"-",
"1",
"to",
"1",
"in",
"the",
"x",
"and",
"y",
"dimensions",
"and",
"from",
"0",
"to",
"1",
"in",
"the",
"z",
"dimension",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L503-L530 |
8,781 | greggman/twgl.js | src/m4.js | ortho | function ortho(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
dst[0] = 2 / (right - left);
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = 2 / (top - bottom);
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 2 / (near - far);
dst[11] = 0;
dst[12] = (right + left) / (left - right);
dst[13] = (top + bottom) / (bottom - top);
dst[14] = (far + near) / (near - far);
dst[15] = 1;
return dst;
} | javascript | function ortho(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
dst[0] = 2 / (right - left);
dst[1] = 0;
dst[2] = 0;
dst[3] = 0;
dst[4] = 0;
dst[5] = 2 / (top - bottom);
dst[6] = 0;
dst[7] = 0;
dst[8] = 0;
dst[9] = 0;
dst[10] = 2 / (near - far);
dst[11] = 0;
dst[12] = (right + left) / (left - right);
dst[13] = (top + bottom) / (bottom - top);
dst[14] = (far + near) / (near - far);
dst[15] = 1;
return dst;
} | [
"function",
"ortho",
"(",
"left",
",",
"right",
",",
"bottom",
",",
"top",
",",
"near",
",",
"far",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"2",
"/",
"(",
"right",
"-",
"left",
")",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"2",
"/",
"(",
"top",
"-",
"bottom",
")",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"2",
"/",
"(",
"near",
"-",
"far",
")",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"(",
"right",
"+",
"left",
")",
"/",
"(",
"left",
"-",
"right",
")",
";",
"dst",
"[",
"13",
"]",
"=",
"(",
"top",
"+",
"bottom",
")",
"/",
"(",
"bottom",
"-",
"top",
")",
";",
"dst",
"[",
"14",
"]",
"=",
"(",
"far",
"+",
"near",
")",
"/",
"(",
"near",
"-",
"far",
")",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Computes a 4-by-4 othogonal transformation matrix given the left, right,
bottom, and top dimensions of the near clipping plane as well as the
near and far clipping plane distances.
@param {number} left Left side of the near clipping plane viewport.
@param {number} right Right side of the near clipping plane viewport.
@param {number} bottom Bottom of the near clipping plane viewport.
@param {number} top Top of the near clipping plane viewport.
@param {number} near The depth (negative z coordinate)
of the near clipping plane.
@param {number} far The depth (negative z coordinate)
of the far clipping plane.
@param {module:twgl/m4.Mat4} [dst] Output matrix.
@return {module:twgl/m4.Mat4} The perspective matrix.
@memberOf module:twgl/m4 | [
"Computes",
"a",
"4",
"-",
"by",
"-",
"4",
"othogonal",
"transformation",
"matrix",
"given",
"the",
"left",
"right",
"bottom",
"and",
"top",
"dimensions",
"of",
"the",
"near",
"clipping",
"plane",
"as",
"well",
"as",
"the",
"near",
"and",
"far",
"clipping",
"plane",
"distances",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L548-L572 |
8,782 | greggman/twgl.js | src/m4.js | frustum | function frustum(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
const dx = (right - left);
const dy = (top - bottom);
const dz = (near - far);
dst[ 0] = 2 * near / dx;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 2 * near / dy;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = (left + right) / dx;
dst[ 9] = (top + bottom) / dy;
dst[10] = far / dz;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = near * far / dz;
dst[15] = 0;
return dst;
} | javascript | function frustum(left, right, bottom, top, near, far, dst) {
dst = dst || new MatType(16);
const dx = (right - left);
const dy = (top - bottom);
const dz = (near - far);
dst[ 0] = 2 * near / dx;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 2 * near / dy;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = (left + right) / dx;
dst[ 9] = (top + bottom) / dy;
dst[10] = far / dz;
dst[11] = -1;
dst[12] = 0;
dst[13] = 0;
dst[14] = near * far / dz;
dst[15] = 0;
return dst;
} | [
"function",
"frustum",
"(",
"left",
",",
"right",
",",
"bottom",
",",
"top",
",",
"near",
",",
"far",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"dx",
"=",
"(",
"right",
"-",
"left",
")",
";",
"const",
"dy",
"=",
"(",
"top",
"-",
"bottom",
")",
";",
"const",
"dz",
"=",
"(",
"near",
"-",
"far",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"2",
"*",
"near",
"/",
"dx",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"2",
"*",
"near",
"/",
"dy",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"(",
"left",
"+",
"right",
")",
"/",
"dx",
";",
"dst",
"[",
"9",
"]",
"=",
"(",
"top",
"+",
"bottom",
")",
"/",
"dy",
";",
"dst",
"[",
"10",
"]",
"=",
"far",
"/",
"dz",
";",
"dst",
"[",
"11",
"]",
"=",
"-",
"1",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"near",
"*",
"far",
"/",
"dz",
";",
"dst",
"[",
"15",
"]",
"=",
"0",
";",
"return",
"dst",
";",
"}"
] | Computes a 4-by-4 perspective transformation matrix given the left, right,
top, bottom, near and far clipping planes. The arguments define a frustum
extending in the negative z direction. The arguments near and far are the
distances to the near and far clipping planes. Note that near and far are not
z coordinates, but rather they are distances along the negative z-axis. The
matrix generated sends the viewing frustum to the unit box. We assume a unit
box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z
dimension.
@param {number} left The x coordinate of the left plane of the box.
@param {number} right The x coordinate of the right plane of the box.
@param {number} bottom The y coordinate of the bottom plane of the box.
@param {number} top The y coordinate of the right plane of the box.
@param {number} near The negative z coordinate of the near plane of the box.
@param {number} far The negative z coordinate of the far plane of the box.
@param {module:twgl/m4.Mat4} [dst] Output matrix.
@return {module:twgl/m4.Mat4} The perspective projection matrix.
@memberOf module:twgl/m4 | [
"Computes",
"a",
"4",
"-",
"by",
"-",
"4",
"perspective",
"transformation",
"matrix",
"given",
"the",
"left",
"right",
"top",
"bottom",
"near",
"and",
"far",
"clipping",
"planes",
".",
"The",
"arguments",
"define",
"a",
"frustum",
"extending",
"in",
"the",
"negative",
"z",
"direction",
".",
"The",
"arguments",
"near",
"and",
"far",
"are",
"the",
"distances",
"to",
"the",
"near",
"and",
"far",
"clipping",
"planes",
".",
"Note",
"that",
"near",
"and",
"far",
"are",
"not",
"z",
"coordinates",
"but",
"rather",
"they",
"are",
"distances",
"along",
"the",
"negative",
"z",
"-",
"axis",
".",
"The",
"matrix",
"generated",
"sends",
"the",
"viewing",
"frustum",
"to",
"the",
"unit",
"box",
".",
"We",
"assume",
"a",
"unit",
"box",
"extending",
"from",
"-",
"1",
"to",
"1",
"in",
"the",
"x",
"and",
"y",
"dimensions",
"and",
"from",
"0",
"to",
"1",
"in",
"the",
"z",
"dimension",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L593-L618 |
8,783 | greggman/twgl.js | src/m4.js | lookAt | function lookAt(eye, target, up, dst) {
dst = dst || new MatType(16);
const xAxis = tempV3a;
const yAxis = tempV3b;
const zAxis = tempV3c;
v3.normalize(
v3.subtract(eye, target, zAxis), zAxis);
v3.normalize(v3.cross(up, zAxis, xAxis), xAxis);
v3.normalize(v3.cross(zAxis, xAxis, yAxis), yAxis);
dst[ 0] = xAxis[0];
dst[ 1] = xAxis[1];
dst[ 2] = xAxis[2];
dst[ 3] = 0;
dst[ 4] = yAxis[0];
dst[ 5] = yAxis[1];
dst[ 6] = yAxis[2];
dst[ 7] = 0;
dst[ 8] = zAxis[0];
dst[ 9] = zAxis[1];
dst[10] = zAxis[2];
dst[11] = 0;
dst[12] = eye[0];
dst[13] = eye[1];
dst[14] = eye[2];
dst[15] = 1;
return dst;
} | javascript | function lookAt(eye, target, up, dst) {
dst = dst || new MatType(16);
const xAxis = tempV3a;
const yAxis = tempV3b;
const zAxis = tempV3c;
v3.normalize(
v3.subtract(eye, target, zAxis), zAxis);
v3.normalize(v3.cross(up, zAxis, xAxis), xAxis);
v3.normalize(v3.cross(zAxis, xAxis, yAxis), yAxis);
dst[ 0] = xAxis[0];
dst[ 1] = xAxis[1];
dst[ 2] = xAxis[2];
dst[ 3] = 0;
dst[ 4] = yAxis[0];
dst[ 5] = yAxis[1];
dst[ 6] = yAxis[2];
dst[ 7] = 0;
dst[ 8] = zAxis[0];
dst[ 9] = zAxis[1];
dst[10] = zAxis[2];
dst[11] = 0;
dst[12] = eye[0];
dst[13] = eye[1];
dst[14] = eye[2];
dst[15] = 1;
return dst;
} | [
"function",
"lookAt",
"(",
"eye",
",",
"target",
",",
"up",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"xAxis",
"=",
"tempV3a",
";",
"const",
"yAxis",
"=",
"tempV3b",
";",
"const",
"zAxis",
"=",
"tempV3c",
";",
"v3",
".",
"normalize",
"(",
"v3",
".",
"subtract",
"(",
"eye",
",",
"target",
",",
"zAxis",
")",
",",
"zAxis",
")",
";",
"v3",
".",
"normalize",
"(",
"v3",
".",
"cross",
"(",
"up",
",",
"zAxis",
",",
"xAxis",
")",
",",
"xAxis",
")",
";",
"v3",
".",
"normalize",
"(",
"v3",
".",
"cross",
"(",
"zAxis",
",",
"xAxis",
",",
"yAxis",
")",
",",
"yAxis",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"xAxis",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"xAxis",
"[",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"xAxis",
"[",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"yAxis",
"[",
"0",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"yAxis",
"[",
"1",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"yAxis",
"[",
"2",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"zAxis",
"[",
"0",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"zAxis",
"[",
"1",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"zAxis",
"[",
"2",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"eye",
"[",
"0",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"eye",
"[",
"1",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"eye",
"[",
"2",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Computes a 4-by-4 look-at transformation.
This is a matrix which positions the camera itself. If you want
a view matrix (a matrix which moves things in front of the camera)
take the inverse of this.
@param {module:twgl/v3.Vec3} eye The position of the eye.
@param {module:twgl/v3.Vec3} target The position meant to be viewed.
@param {module:twgl/v3.Vec3} up A vector pointing up.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The look-at matrix.
@memberOf module:twgl/m4 | [
"Computes",
"a",
"4",
"-",
"by",
"-",
"4",
"look",
"-",
"at",
"transformation",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L634-L664 |
8,784 | greggman/twgl.js | src/m4.js | translation | function translation(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | javascript | function translation(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = 1;
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = 1;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = v[0];
dst[13] = v[1];
dst[14] = v[2];
dst[15] = 1;
return dst;
} | [
"function",
"translation",
"(",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"1",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"1",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"1",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"v",
"[",
"1",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"v",
"[",
"2",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Creates a 4-by-4 matrix which translates by the given vector v.
@param {module:twgl/v3.Vec3} v The vector by
which to translate.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The translation matrix.
@memberOf module:twgl/m4 | [
"Creates",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"which",
"translates",
"by",
"the",
"given",
"vector",
"v",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L674-L694 |
8,785 | greggman/twgl.js | src/m4.js | translate | function translate(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const m00 = m[0];
const m01 = m[1];
const m02 = m[2];
const m03 = m[3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
if (m !== dst) {
dst[ 0] = m00;
dst[ 1] = m01;
dst[ 2] = m02;
dst[ 3] = m03;
dst[ 4] = m10;
dst[ 5] = m11;
dst[ 6] = m12;
dst[ 7] = m13;
dst[ 8] = m20;
dst[ 9] = m21;
dst[10] = m22;
dst[11] = m23;
}
dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;
dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;
dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;
dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;
return dst;
} | javascript | function translate(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const m00 = m[0];
const m01 = m[1];
const m02 = m[2];
const m03 = m[3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const m30 = m[3 * 4 + 0];
const m31 = m[3 * 4 + 1];
const m32 = m[3 * 4 + 2];
const m33 = m[3 * 4 + 3];
if (m !== dst) {
dst[ 0] = m00;
dst[ 1] = m01;
dst[ 2] = m02;
dst[ 3] = m03;
dst[ 4] = m10;
dst[ 5] = m11;
dst[ 6] = m12;
dst[ 7] = m13;
dst[ 8] = m20;
dst[ 9] = m21;
dst[10] = m22;
dst[11] = m23;
}
dst[12] = m00 * v0 + m10 * v1 + m20 * v2 + m30;
dst[13] = m01 * v0 + m11 * v1 + m21 * v2 + m31;
dst[14] = m02 * v0 + m12 * v1 + m22 * v2 + m32;
dst[15] = m03 * v0 + m13 * v1 + m23 * v2 + m33;
return dst;
} | [
"function",
"translate",
"(",
"m",
",",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"v0",
"=",
"v",
"[",
"0",
"]",
";",
"const",
"v1",
"=",
"v",
"[",
"1",
"]",
";",
"const",
"v2",
"=",
"v",
"[",
"2",
"]",
";",
"const",
"m00",
"=",
"m",
"[",
"0",
"]",
";",
"const",
"m01",
"=",
"m",
"[",
"1",
"]",
";",
"const",
"m02",
"=",
"m",
"[",
"2",
"]",
";",
"const",
"m03",
"=",
"m",
"[",
"3",
"]",
";",
"const",
"m10",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m11",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m12",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m13",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m20",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m21",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m22",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m23",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m30",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m31",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m32",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m33",
"=",
"m",
"[",
"3",
"*",
"4",
"+",
"3",
"]",
";",
"if",
"(",
"m",
"!==",
"dst",
")",
"{",
"dst",
"[",
"0",
"]",
"=",
"m00",
";",
"dst",
"[",
"1",
"]",
"=",
"m01",
";",
"dst",
"[",
"2",
"]",
"=",
"m02",
";",
"dst",
"[",
"3",
"]",
"=",
"m03",
";",
"dst",
"[",
"4",
"]",
"=",
"m10",
";",
"dst",
"[",
"5",
"]",
"=",
"m11",
";",
"dst",
"[",
"6",
"]",
"=",
"m12",
";",
"dst",
"[",
"7",
"]",
"=",
"m13",
";",
"dst",
"[",
"8",
"]",
"=",
"m20",
";",
"dst",
"[",
"9",
"]",
"=",
"m21",
";",
"dst",
"[",
"10",
"]",
"=",
"m22",
";",
"dst",
"[",
"11",
"]",
"=",
"m23",
";",
"}",
"dst",
"[",
"12",
"]",
"=",
"m00",
"*",
"v0",
"+",
"m10",
"*",
"v1",
"+",
"m20",
"*",
"v2",
"+",
"m30",
";",
"dst",
"[",
"13",
"]",
"=",
"m01",
"*",
"v0",
"+",
"m11",
"*",
"v1",
"+",
"m21",
"*",
"v2",
"+",
"m31",
";",
"dst",
"[",
"14",
"]",
"=",
"m02",
"*",
"v0",
"+",
"m12",
"*",
"v1",
"+",
"m22",
"*",
"v2",
"+",
"m32",
";",
"dst",
"[",
"15",
"]",
"=",
"m03",
"*",
"v0",
"+",
"m13",
"*",
"v1",
"+",
"m23",
"*",
"v2",
"+",
"m33",
";",
"return",
"dst",
";",
"}"
] | Modifies the given 4-by-4 matrix by translation by the given vector v.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/v3.Vec3} v The vector by
which to translate.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} m once modified.
@memberOf module:twgl/m4 | [
"Modifies",
"the",
"given",
"4",
"-",
"by",
"-",
"4",
"matrix",
"by",
"translation",
"by",
"the",
"given",
"vector",
"v",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L705-L749 |
8,786 | greggman/twgl.js | src/m4.js | rotateX | function rotateX(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m10 = m[4];
const m11 = m[5];
const m12 = m[6];
const m13 = m[7];
const m20 = m[8];
const m21 = m[9];
const m22 = m[10];
const m23 = m[11];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[4] = c * m10 + s * m20;
dst[5] = c * m11 + s * m21;
dst[6] = c * m12 + s * m22;
dst[7] = c * m13 + s * m23;
dst[8] = c * m20 - s * m10;
dst[9] = c * m21 - s * m11;
dst[10] = c * m22 - s * m12;
dst[11] = c * m23 - s * m13;
if (m !== dst) {
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | function rotateX(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m10 = m[4];
const m11 = m[5];
const m12 = m[6];
const m13 = m[7];
const m20 = m[8];
const m21 = m[9];
const m22 = m[10];
const m23 = m[11];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[4] = c * m10 + s * m20;
dst[5] = c * m11 + s * m21;
dst[6] = c * m12 + s * m22;
dst[7] = c * m13 + s * m23;
dst[8] = c * m20 - s * m10;
dst[9] = c * m21 - s * m11;
dst[10] = c * m22 - s * m12;
dst[11] = c * m23 - s * m13;
if (m !== dst) {
dst[ 0] = m[ 0];
dst[ 1] = m[ 1];
dst[ 2] = m[ 2];
dst[ 3] = m[ 3];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | [
"function",
"rotateX",
"(",
"m",
",",
"angleInRadians",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"m10",
"=",
"m",
"[",
"4",
"]",
";",
"const",
"m11",
"=",
"m",
"[",
"5",
"]",
";",
"const",
"m12",
"=",
"m",
"[",
"6",
"]",
";",
"const",
"m13",
"=",
"m",
"[",
"7",
"]",
";",
"const",
"m20",
"=",
"m",
"[",
"8",
"]",
";",
"const",
"m21",
"=",
"m",
"[",
"9",
"]",
";",
"const",
"m22",
"=",
"m",
"[",
"10",
"]",
";",
"const",
"m23",
"=",
"m",
"[",
"11",
"]",
";",
"const",
"c",
"=",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
";",
"const",
"s",
"=",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
";",
"dst",
"[",
"4",
"]",
"=",
"c",
"*",
"m10",
"+",
"s",
"*",
"m20",
";",
"dst",
"[",
"5",
"]",
"=",
"c",
"*",
"m11",
"+",
"s",
"*",
"m21",
";",
"dst",
"[",
"6",
"]",
"=",
"c",
"*",
"m12",
"+",
"s",
"*",
"m22",
";",
"dst",
"[",
"7",
"]",
"=",
"c",
"*",
"m13",
"+",
"s",
"*",
"m23",
";",
"dst",
"[",
"8",
"]",
"=",
"c",
"*",
"m20",
"-",
"s",
"*",
"m10",
";",
"dst",
"[",
"9",
"]",
"=",
"c",
"*",
"m21",
"-",
"s",
"*",
"m11",
";",
"dst",
"[",
"10",
"]",
"=",
"c",
"*",
"m22",
"-",
"s",
"*",
"m12",
";",
"dst",
"[",
"11",
"]",
"=",
"c",
"*",
"m23",
"-",
"s",
"*",
"m13",
";",
"if",
"(",
"m",
"!==",
"dst",
")",
"{",
"dst",
"[",
"0",
"]",
"=",
"m",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"m",
"[",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"m",
"[",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"m",
"[",
"3",
"]",
";",
"dst",
"[",
"12",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"m",
"[",
"15",
"]",
";",
"}",
"return",
"dst",
";",
"}"
] | Modifies the given 4-by-4 matrix by a rotation around the x-axis by the given
angle.
@param {module:twgl/m4.Mat4} m The matrix.
@param {number} angleInRadians The angle by which to rotate (in radians).
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} m once modified.
@memberOf module:twgl/m4 | [
"Modifies",
"the",
"given",
"4",
"-",
"by",
"-",
"4",
"matrix",
"by",
"a",
"rotation",
"around",
"the",
"x",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L793-L828 |
8,787 | greggman/twgl.js | src/m4.js | rotateY | function rotateY(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 - s * m20;
dst[ 1] = c * m01 - s * m21;
dst[ 2] = c * m02 - s * m22;
dst[ 3] = c * m03 - s * m23;
dst[ 8] = c * m20 + s * m00;
dst[ 9] = c * m21 + s * m01;
dst[10] = c * m22 + s * m02;
dst[11] = c * m23 + s * m03;
if (m !== dst) {
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | function rotateY(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m20 = m[2 * 4 + 0];
const m21 = m[2 * 4 + 1];
const m22 = m[2 * 4 + 2];
const m23 = m[2 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 - s * m20;
dst[ 1] = c * m01 - s * m21;
dst[ 2] = c * m02 - s * m22;
dst[ 3] = c * m03 - s * m23;
dst[ 8] = c * m20 + s * m00;
dst[ 9] = c * m21 + s * m01;
dst[10] = c * m22 + s * m02;
dst[11] = c * m23 + s * m03;
if (m !== dst) {
dst[ 4] = m[ 4];
dst[ 5] = m[ 5];
dst[ 6] = m[ 6];
dst[ 7] = m[ 7];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | [
"function",
"rotateY",
"(",
"m",
",",
"angleInRadians",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"m00",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m01",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m02",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m03",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m20",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m21",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m22",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m23",
"=",
"m",
"[",
"2",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"c",
"=",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
";",
"const",
"s",
"=",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"c",
"*",
"m00",
"-",
"s",
"*",
"m20",
";",
"dst",
"[",
"1",
"]",
"=",
"c",
"*",
"m01",
"-",
"s",
"*",
"m21",
";",
"dst",
"[",
"2",
"]",
"=",
"c",
"*",
"m02",
"-",
"s",
"*",
"m22",
";",
"dst",
"[",
"3",
"]",
"=",
"c",
"*",
"m03",
"-",
"s",
"*",
"m23",
";",
"dst",
"[",
"8",
"]",
"=",
"c",
"*",
"m20",
"+",
"s",
"*",
"m00",
";",
"dst",
"[",
"9",
"]",
"=",
"c",
"*",
"m21",
"+",
"s",
"*",
"m01",
";",
"dst",
"[",
"10",
"]",
"=",
"c",
"*",
"m22",
"+",
"s",
"*",
"m02",
";",
"dst",
"[",
"11",
"]",
"=",
"c",
"*",
"m23",
"+",
"s",
"*",
"m03",
";",
"if",
"(",
"m",
"!==",
"dst",
")",
"{",
"dst",
"[",
"4",
"]",
"=",
"m",
"[",
"4",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"m",
"[",
"5",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"m",
"[",
"6",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"m",
"[",
"7",
"]",
";",
"dst",
"[",
"12",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"m",
"[",
"15",
"]",
";",
"}",
"return",
"dst",
";",
"}"
] | Modifies the given 4-by-4 matrix by a rotation around the y-axis by the given
angle.
@param {module:twgl/m4.Mat4} m The matrix.
@param {number} angleInRadians The angle by which to rotate (in radians).
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} m once modified.
@memberOf module:twgl/m4 | [
"Modifies",
"the",
"given",
"4",
"-",
"by",
"-",
"4",
"matrix",
"by",
"a",
"rotation",
"around",
"the",
"y",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L872-L907 |
8,788 | greggman/twgl.js | src/m4.js | rotationZ | function rotationZ(angleInRadians, dst) {
dst = dst || new MatType(16);
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c;
dst[ 1] = s;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = -s;
dst[ 5] = c;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | function rotationZ(angleInRadians, dst) {
dst = dst || new MatType(16);
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c;
dst[ 1] = s;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = -s;
dst[ 5] = c;
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = 1;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | [
"function",
"rotationZ",
"(",
"angleInRadians",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"c",
"=",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
";",
"const",
"s",
"=",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"c",
";",
"dst",
"[",
"1",
"]",
"=",
"s",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"-",
"s",
";",
"dst",
"[",
"5",
"]",
"=",
"c",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"1",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"0",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Creates a 4-by-4 matrix which rotates around the z-axis by the given angle.
@param {number} angleInRadians The angle by which to rotate (in radians).
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The rotation matrix.
@memberOf module:twgl/m4 | [
"Creates",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"which",
"rotates",
"around",
"the",
"z",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L916-L940 |
8,789 | greggman/twgl.js | src/m4.js | rotateZ | function rotateZ(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 + s * m10;
dst[ 1] = c * m01 + s * m11;
dst[ 2] = c * m02 + s * m12;
dst[ 3] = c * m03 + s * m13;
dst[ 4] = c * m10 - s * m00;
dst[ 5] = c * m11 - s * m01;
dst[ 6] = c * m12 - s * m02;
dst[ 7] = c * m13 - s * m03;
if (m !== dst) {
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | function rotateZ(m, angleInRadians, dst) {
dst = dst || new MatType(16);
const m00 = m[0 * 4 + 0];
const m01 = m[0 * 4 + 1];
const m02 = m[0 * 4 + 2];
const m03 = m[0 * 4 + 3];
const m10 = m[1 * 4 + 0];
const m11 = m[1 * 4 + 1];
const m12 = m[1 * 4 + 2];
const m13 = m[1 * 4 + 3];
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
dst[ 0] = c * m00 + s * m10;
dst[ 1] = c * m01 + s * m11;
dst[ 2] = c * m02 + s * m12;
dst[ 3] = c * m03 + s * m13;
dst[ 4] = c * m10 - s * m00;
dst[ 5] = c * m11 - s * m01;
dst[ 6] = c * m12 - s * m02;
dst[ 7] = c * m13 - s * m03;
if (m !== dst) {
dst[ 8] = m[ 8];
dst[ 9] = m[ 9];
dst[10] = m[10];
dst[11] = m[11];
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | [
"function",
"rotateZ",
"(",
"m",
",",
"angleInRadians",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"m00",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m01",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m02",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m03",
"=",
"m",
"[",
"0",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"m10",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
";",
"const",
"m11",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
";",
"const",
"m12",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
";",
"const",
"m13",
"=",
"m",
"[",
"1",
"*",
"4",
"+",
"3",
"]",
";",
"const",
"c",
"=",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
";",
"const",
"s",
"=",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"c",
"*",
"m00",
"+",
"s",
"*",
"m10",
";",
"dst",
"[",
"1",
"]",
"=",
"c",
"*",
"m01",
"+",
"s",
"*",
"m11",
";",
"dst",
"[",
"2",
"]",
"=",
"c",
"*",
"m02",
"+",
"s",
"*",
"m12",
";",
"dst",
"[",
"3",
"]",
"=",
"c",
"*",
"m03",
"+",
"s",
"*",
"m13",
";",
"dst",
"[",
"4",
"]",
"=",
"c",
"*",
"m10",
"-",
"s",
"*",
"m00",
";",
"dst",
"[",
"5",
"]",
"=",
"c",
"*",
"m11",
"-",
"s",
"*",
"m01",
";",
"dst",
"[",
"6",
"]",
"=",
"c",
"*",
"m12",
"-",
"s",
"*",
"m02",
";",
"dst",
"[",
"7",
"]",
"=",
"c",
"*",
"m13",
"-",
"s",
"*",
"m03",
";",
"if",
"(",
"m",
"!==",
"dst",
")",
"{",
"dst",
"[",
"8",
"]",
"=",
"m",
"[",
"8",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"m",
"[",
"9",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"m",
"[",
"10",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"m",
"[",
"11",
"]",
";",
"dst",
"[",
"12",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"m",
"[",
"15",
"]",
";",
"}",
"return",
"dst",
";",
"}"
] | Modifies the given 4-by-4 matrix by a rotation around the z-axis by the given
angle.
@param {module:twgl/m4.Mat4} m The matrix.
@param {number} angleInRadians The angle by which to rotate (in radians).
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} m once modified.
@memberOf module:twgl/m4 | [
"Modifies",
"the",
"given",
"4",
"-",
"by",
"-",
"4",
"matrix",
"by",
"a",
"rotation",
"around",
"the",
"z",
"-",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L951-L986 |
8,790 | greggman/twgl.js | src/m4.js | axisRotation | function axisRotation(axis, angleInRadians, dst) {
dst = dst || new MatType(16);
let x = axis[0];
let y = axis[1];
let z = axis[2];
const n = Math.sqrt(x * x + y * y + z * z);
x /= n;
y /= n;
z /= n;
const xx = x * x;
const yy = y * y;
const zz = z * z;
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
const oneMinusCosine = 1 - c;
dst[ 0] = xx + (1 - xx) * c;
dst[ 1] = x * y * oneMinusCosine + z * s;
dst[ 2] = x * z * oneMinusCosine - y * s;
dst[ 3] = 0;
dst[ 4] = x * y * oneMinusCosine - z * s;
dst[ 5] = yy + (1 - yy) * c;
dst[ 6] = y * z * oneMinusCosine + x * s;
dst[ 7] = 0;
dst[ 8] = x * z * oneMinusCosine + y * s;
dst[ 9] = y * z * oneMinusCosine - x * s;
dst[10] = zz + (1 - zz) * c;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | function axisRotation(axis, angleInRadians, dst) {
dst = dst || new MatType(16);
let x = axis[0];
let y = axis[1];
let z = axis[2];
const n = Math.sqrt(x * x + y * y + z * z);
x /= n;
y /= n;
z /= n;
const xx = x * x;
const yy = y * y;
const zz = z * z;
const c = Math.cos(angleInRadians);
const s = Math.sin(angleInRadians);
const oneMinusCosine = 1 - c;
dst[ 0] = xx + (1 - xx) * c;
dst[ 1] = x * y * oneMinusCosine + z * s;
dst[ 2] = x * z * oneMinusCosine - y * s;
dst[ 3] = 0;
dst[ 4] = x * y * oneMinusCosine - z * s;
dst[ 5] = yy + (1 - yy) * c;
dst[ 6] = y * z * oneMinusCosine + x * s;
dst[ 7] = 0;
dst[ 8] = x * z * oneMinusCosine + y * s;
dst[ 9] = y * z * oneMinusCosine - x * s;
dst[10] = zz + (1 - zz) * c;
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | [
"function",
"axisRotation",
"(",
"axis",
",",
"angleInRadians",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"let",
"x",
"=",
"axis",
"[",
"0",
"]",
";",
"let",
"y",
"=",
"axis",
"[",
"1",
"]",
";",
"let",
"z",
"=",
"axis",
"[",
"2",
"]",
";",
"const",
"n",
"=",
"Math",
".",
"sqrt",
"(",
"x",
"*",
"x",
"+",
"y",
"*",
"y",
"+",
"z",
"*",
"z",
")",
";",
"x",
"/=",
"n",
";",
"y",
"/=",
"n",
";",
"z",
"/=",
"n",
";",
"const",
"xx",
"=",
"x",
"*",
"x",
";",
"const",
"yy",
"=",
"y",
"*",
"y",
";",
"const",
"zz",
"=",
"z",
"*",
"z",
";",
"const",
"c",
"=",
"Math",
".",
"cos",
"(",
"angleInRadians",
")",
";",
"const",
"s",
"=",
"Math",
".",
"sin",
"(",
"angleInRadians",
")",
";",
"const",
"oneMinusCosine",
"=",
"1",
"-",
"c",
";",
"dst",
"[",
"0",
"]",
"=",
"xx",
"+",
"(",
"1",
"-",
"xx",
")",
"*",
"c",
";",
"dst",
"[",
"1",
"]",
"=",
"x",
"*",
"y",
"*",
"oneMinusCosine",
"+",
"z",
"*",
"s",
";",
"dst",
"[",
"2",
"]",
"=",
"x",
"*",
"z",
"*",
"oneMinusCosine",
"-",
"y",
"*",
"s",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"x",
"*",
"y",
"*",
"oneMinusCosine",
"-",
"z",
"*",
"s",
";",
"dst",
"[",
"5",
"]",
"=",
"yy",
"+",
"(",
"1",
"-",
"yy",
")",
"*",
"c",
";",
"dst",
"[",
"6",
"]",
"=",
"y",
"*",
"z",
"*",
"oneMinusCosine",
"+",
"x",
"*",
"s",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"x",
"*",
"z",
"*",
"oneMinusCosine",
"+",
"y",
"*",
"s",
";",
"dst",
"[",
"9",
"]",
"=",
"y",
"*",
"z",
"*",
"oneMinusCosine",
"-",
"x",
"*",
"s",
";",
"dst",
"[",
"10",
"]",
"=",
"zz",
"+",
"(",
"1",
"-",
"zz",
")",
"*",
"c",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"0",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Creates a 4-by-4 matrix which rotates around the given axis by the given
angle.
@param {module:twgl/v3.Vec3} axis The axis
about which to rotate.
@param {number} angleInRadians The angle by which to rotate (in radians).
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} A matrix which rotates angle radians
around the axis.
@memberOf module:twgl/m4 | [
"Creates",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"which",
"rotates",
"around",
"the",
"given",
"axis",
"by",
"the",
"given",
"angle",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L999-L1034 |
8,791 | greggman/twgl.js | src/m4.js | scaling | function scaling(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = v[0];
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = v[1];
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = v[2];
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | javascript | function scaling(v, dst) {
dst = dst || new MatType(16);
dst[ 0] = v[0];
dst[ 1] = 0;
dst[ 2] = 0;
dst[ 3] = 0;
dst[ 4] = 0;
dst[ 5] = v[1];
dst[ 6] = 0;
dst[ 7] = 0;
dst[ 8] = 0;
dst[ 9] = 0;
dst[10] = v[2];
dst[11] = 0;
dst[12] = 0;
dst[13] = 0;
dst[14] = 0;
dst[15] = 1;
return dst;
} | [
"function",
"scaling",
"(",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"dst",
"[",
"0",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"0",
";",
"dst",
"[",
"2",
"]",
"=",
"0",
";",
"dst",
"[",
"3",
"]",
"=",
"0",
";",
"dst",
"[",
"4",
"]",
"=",
"0",
";",
"dst",
"[",
"5",
"]",
"=",
"v",
"[",
"1",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"0",
";",
"dst",
"[",
"7",
"]",
"=",
"0",
";",
"dst",
"[",
"8",
"]",
"=",
"0",
";",
"dst",
"[",
"9",
"]",
"=",
"0",
";",
"dst",
"[",
"10",
"]",
"=",
"v",
"[",
"2",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"0",
";",
"dst",
"[",
"12",
"]",
"=",
"0",
";",
"dst",
"[",
"13",
"]",
"=",
"0",
";",
"dst",
"[",
"14",
"]",
"=",
"0",
";",
"dst",
"[",
"15",
"]",
"=",
"1",
";",
"return",
"dst",
";",
"}"
] | Creates a 4-by-4 matrix which scales in each dimension by an amount given by
the corresponding entry in the given vector; assumes the vector has three
entries.
@param {module:twgl/v3.Vec3} v A vector of
three entries specifying the factor by which to scale in each dimension.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} The scaling matrix.
@memberOf module:twgl/m4 | [
"Creates",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"which",
"scales",
"in",
"each",
"dimension",
"by",
"an",
"amount",
"given",
"by",
"the",
"corresponding",
"entry",
"in",
"the",
"given",
"vector",
";",
"assumes",
"the",
"vector",
"has",
"three",
"entries",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L1120-L1141 |
8,792 | greggman/twgl.js | src/m4.js | scale | function scale(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[ 0] = v0 * m[0 * 4 + 0];
dst[ 1] = v0 * m[0 * 4 + 1];
dst[ 2] = v0 * m[0 * 4 + 2];
dst[ 3] = v0 * m[0 * 4 + 3];
dst[ 4] = v1 * m[1 * 4 + 0];
dst[ 5] = v1 * m[1 * 4 + 1];
dst[ 6] = v1 * m[1 * 4 + 2];
dst[ 7] = v1 * m[1 * 4 + 3];
dst[ 8] = v2 * m[2 * 4 + 0];
dst[ 9] = v2 * m[2 * 4 + 1];
dst[10] = v2 * m[2 * 4 + 2];
dst[11] = v2 * m[2 * 4 + 3];
if (m !== dst) {
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | javascript | function scale(m, v, dst) {
dst = dst || new MatType(16);
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[ 0] = v0 * m[0 * 4 + 0];
dst[ 1] = v0 * m[0 * 4 + 1];
dst[ 2] = v0 * m[0 * 4 + 2];
dst[ 3] = v0 * m[0 * 4 + 3];
dst[ 4] = v1 * m[1 * 4 + 0];
dst[ 5] = v1 * m[1 * 4 + 1];
dst[ 6] = v1 * m[1 * 4 + 2];
dst[ 7] = v1 * m[1 * 4 + 3];
dst[ 8] = v2 * m[2 * 4 + 0];
dst[ 9] = v2 * m[2 * 4 + 1];
dst[10] = v2 * m[2 * 4 + 2];
dst[11] = v2 * m[2 * 4 + 3];
if (m !== dst) {
dst[12] = m[12];
dst[13] = m[13];
dst[14] = m[14];
dst[15] = m[15];
}
return dst;
} | [
"function",
"scale",
"(",
"m",
",",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"new",
"MatType",
"(",
"16",
")",
";",
"const",
"v0",
"=",
"v",
"[",
"0",
"]",
";",
"const",
"v1",
"=",
"v",
"[",
"1",
"]",
";",
"const",
"v2",
"=",
"v",
"[",
"2",
"]",
";",
"dst",
"[",
"0",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
";",
"dst",
"[",
"3",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"3",
"]",
";",
"dst",
"[",
"4",
"]",
"=",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
";",
"dst",
"[",
"5",
"]",
"=",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
";",
"dst",
"[",
"6",
"]",
"=",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
";",
"dst",
"[",
"7",
"]",
"=",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"3",
"]",
";",
"dst",
"[",
"8",
"]",
"=",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
";",
"dst",
"[",
"9",
"]",
"=",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
";",
"dst",
"[",
"10",
"]",
"=",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
";",
"dst",
"[",
"11",
"]",
"=",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"3",
"]",
";",
"if",
"(",
"m",
"!==",
"dst",
")",
"{",
"dst",
"[",
"12",
"]",
"=",
"m",
"[",
"12",
"]",
";",
"dst",
"[",
"13",
"]",
"=",
"m",
"[",
"13",
"]",
";",
"dst",
"[",
"14",
"]",
"=",
"m",
"[",
"14",
"]",
";",
"dst",
"[",
"15",
"]",
"=",
"m",
"[",
"15",
"]",
";",
"}",
"return",
"dst",
";",
"}"
] | Modifies the given 4-by-4 matrix, scaling in each dimension by an amount
given by the corresponding entry in the given vector; assumes the vector has
three entries.
@param {module:twgl/m4.Mat4} m The matrix to be modified.
@param {module:twgl/v3.Vec3} v A vector of three entries specifying the
factor by which to scale in each dimension.
@param {module:twgl/m4.Mat4} [dst] matrix to hold result. If none new one is created..
@return {module:twgl/m4.Mat4} m once modified.
@memberOf module:twgl/m4 | [
"Modifies",
"the",
"given",
"4",
"-",
"by",
"-",
"4",
"matrix",
"scaling",
"in",
"each",
"dimension",
"by",
"an",
"amount",
"given",
"by",
"the",
"corresponding",
"entry",
"in",
"the",
"given",
"vector",
";",
"assumes",
"the",
"vector",
"has",
"three",
"entries",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L1154-L1182 |
8,793 | greggman/twgl.js | src/m4.js | transformPoint | function transformPoint(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];
dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;
dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;
dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;
return dst;
} | javascript | function transformPoint(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
const d = v0 * m[0 * 4 + 3] + v1 * m[1 * 4 + 3] + v2 * m[2 * 4 + 3] + m[3 * 4 + 3];
dst[0] = (v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0] + m[3 * 4 + 0]) / d;
dst[1] = (v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1] + m[3 * 4 + 1]) / d;
dst[2] = (v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2] + m[3 * 4 + 2]) / d;
return dst;
} | [
"function",
"transformPoint",
"(",
"m",
",",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"v3",
".",
"create",
"(",
")",
";",
"const",
"v0",
"=",
"v",
"[",
"0",
"]",
";",
"const",
"v1",
"=",
"v",
"[",
"1",
"]",
";",
"const",
"v2",
"=",
"v",
"[",
"2",
"]",
";",
"const",
"d",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"3",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"3",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"3",
"]",
"+",
"m",
"[",
"3",
"*",
"4",
"+",
"3",
"]",
";",
"dst",
"[",
"0",
"]",
"=",
"(",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
"+",
"m",
"[",
"3",
"*",
"4",
"+",
"0",
"]",
")",
"/",
"d",
";",
"dst",
"[",
"1",
"]",
"=",
"(",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
"+",
"m",
"[",
"3",
"*",
"4",
"+",
"1",
"]",
")",
"/",
"d",
";",
"dst",
"[",
"2",
"]",
"=",
"(",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
"+",
"m",
"[",
"3",
"*",
"4",
"+",
"2",
"]",
")",
"/",
"d",
";",
"return",
"dst",
";",
"}"
] | Takes a 4-by-4 matrix and a vector with 3 entries,
interprets the vector as a point, transforms that point by the matrix, and
returns the result as a vector with 3 entries.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/v3.Vec3} v The point.
@param {module:twgl/v3.Vec3} dst optional vec3 to store result
@return {module:twgl/v3.Vec3} dst or new vec3 if not provided
@memberOf module:twgl/m4 | [
"Takes",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"and",
"a",
"vector",
"with",
"3",
"entries",
"interprets",
"the",
"vector",
"as",
"a",
"point",
"transforms",
"that",
"point",
"by",
"the",
"matrix",
"and",
"returns",
"the",
"result",
"as",
"a",
"vector",
"with",
"3",
"entries",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L1194-L1206 |
8,794 | greggman/twgl.js | src/m4.js | transformDirection | function transformDirection(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];
dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];
dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];
return dst;
} | javascript | function transformDirection(m, v, dst) {
dst = dst || v3.create();
const v0 = v[0];
const v1 = v[1];
const v2 = v[2];
dst[0] = v0 * m[0 * 4 + 0] + v1 * m[1 * 4 + 0] + v2 * m[2 * 4 + 0];
dst[1] = v0 * m[0 * 4 + 1] + v1 * m[1 * 4 + 1] + v2 * m[2 * 4 + 1];
dst[2] = v0 * m[0 * 4 + 2] + v1 * m[1 * 4 + 2] + v2 * m[2 * 4 + 2];
return dst;
} | [
"function",
"transformDirection",
"(",
"m",
",",
"v",
",",
"dst",
")",
"{",
"dst",
"=",
"dst",
"||",
"v3",
".",
"create",
"(",
")",
";",
"const",
"v0",
"=",
"v",
"[",
"0",
"]",
";",
"const",
"v1",
"=",
"v",
"[",
"1",
"]",
";",
"const",
"v2",
"=",
"v",
"[",
"2",
"]",
";",
"dst",
"[",
"0",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"0",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"0",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"0",
"]",
";",
"dst",
"[",
"1",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"1",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"1",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"1",
"]",
";",
"dst",
"[",
"2",
"]",
"=",
"v0",
"*",
"m",
"[",
"0",
"*",
"4",
"+",
"2",
"]",
"+",
"v1",
"*",
"m",
"[",
"1",
"*",
"4",
"+",
"2",
"]",
"+",
"v2",
"*",
"m",
"[",
"2",
"*",
"4",
"+",
"2",
"]",
";",
"return",
"dst",
";",
"}"
] | Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a
direction, transforms that direction by the matrix, and returns the result;
assumes the transformation of 3-dimensional space represented by the matrix
is parallel-preserving, i.e. any combination of rotation, scaling and
translation, but not a perspective distortion. Returns a vector with 3
entries.
@param {module:twgl/m4.Mat4} m The matrix.
@param {module:twgl/v3.Vec3} v The direction.
@param {module:twgl/v3.Vec3} dst optional Vec3 to store result
@return {module:twgl/v3.Vec3} dst or new Vec3 if not provided
@memberOf module:twgl/m4 | [
"Takes",
"a",
"4",
"-",
"by",
"-",
"4",
"matrix",
"and",
"a",
"vector",
"with",
"3",
"entries",
"interprets",
"the",
"vector",
"as",
"a",
"direction",
"transforms",
"that",
"direction",
"by",
"the",
"matrix",
"and",
"returns",
"the",
"result",
";",
"assumes",
"the",
"transformation",
"of",
"3",
"-",
"dimensional",
"space",
"represented",
"by",
"the",
"matrix",
"is",
"parallel",
"-",
"preserving",
"i",
".",
"e",
".",
"any",
"combination",
"of",
"rotation",
"scaling",
"and",
"translation",
"but",
"not",
"a",
"perspective",
"distortion",
".",
"Returns",
"a",
"vector",
"with",
"3",
"entries",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/m4.js#L1221-L1233 |
8,795 | greggman/twgl.js | src/attributes.js | createBufferFromTypedArray | function createBufferFromTypedArray(gl, typedArray, type, drawType) {
if (helper.isBuffer(gl, typedArray)) {
return typedArray;
}
type = type || gl.ARRAY_BUFFER;
const buffer = gl.createBuffer();
setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
return buffer;
} | javascript | function createBufferFromTypedArray(gl, typedArray, type, drawType) {
if (helper.isBuffer(gl, typedArray)) {
return typedArray;
}
type = type || gl.ARRAY_BUFFER;
const buffer = gl.createBuffer();
setBufferFromTypedArray(gl, type, buffer, typedArray, drawType);
return buffer;
} | [
"function",
"createBufferFromTypedArray",
"(",
"gl",
",",
"typedArray",
",",
"type",
",",
"drawType",
")",
"{",
"if",
"(",
"helper",
".",
"isBuffer",
"(",
"gl",
",",
"typedArray",
")",
")",
"{",
"return",
"typedArray",
";",
"}",
"type",
"=",
"type",
"||",
"gl",
".",
"ARRAY_BUFFER",
";",
"const",
"buffer",
"=",
"gl",
".",
"createBuffer",
"(",
")",
";",
"setBufferFromTypedArray",
"(",
"gl",
",",
"type",
",",
"buffer",
",",
"typedArray",
",",
"drawType",
")",
";",
"return",
"buffer",
";",
"}"
] | Given typed array creates a WebGLBuffer and copies the typed array
into it.
@param {WebGLRenderingContext} gl A WebGLRenderingContext
@param {ArrayBuffer|SharedArrayBuffer|ArrayBufferView|WebGLBuffer} typedArray the typed array. Note: If a WebGLBuffer is passed in it will just be returned. No action will be taken
@param {number} [type] the GL bind type for the buffer. Default = `gl.ARRAY_BUFFER`.
@param {number} [drawType] the GL draw type for the buffer. Default = 'gl.STATIC_DRAW`.
@return {WebGLBuffer} the created WebGLBuffer
@memberOf module:twgl/attributes | [
"Given",
"typed",
"array",
"creates",
"a",
"WebGLBuffer",
"and",
"copies",
"the",
"typed",
"array",
"into",
"it",
"."
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/attributes.js#L91-L99 |
8,796 | greggman/twgl.js | src/attributes.js | setAttribInfoBufferFromArray | function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
array = makeTypedArray(array);
if (offset !== undefined) {
gl.bindBuffer(gl.ARRAY_BUFFER, attribInfo.buffer);
gl.bufferSubData(gl.ARRAY_BUFFER, offset, array);
} else {
setBufferFromTypedArray(gl, gl.ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
}
} | javascript | function setAttribInfoBufferFromArray(gl, attribInfo, array, offset) {
array = makeTypedArray(array);
if (offset !== undefined) {
gl.bindBuffer(gl.ARRAY_BUFFER, attribInfo.buffer);
gl.bufferSubData(gl.ARRAY_BUFFER, offset, array);
} else {
setBufferFromTypedArray(gl, gl.ARRAY_BUFFER, attribInfo.buffer, array, attribInfo.drawType);
}
} | [
"function",
"setAttribInfoBufferFromArray",
"(",
"gl",
",",
"attribInfo",
",",
"array",
",",
"offset",
")",
"{",
"array",
"=",
"makeTypedArray",
"(",
"array",
")",
";",
"if",
"(",
"offset",
"!==",
"undefined",
")",
"{",
"gl",
".",
"bindBuffer",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"attribInfo",
".",
"buffer",
")",
";",
"gl",
".",
"bufferSubData",
"(",
"gl",
".",
"ARRAY_BUFFER",
",",
"offset",
",",
"array",
")",
";",
"}",
"else",
"{",
"setBufferFromTypedArray",
"(",
"gl",
",",
"gl",
".",
"ARRAY_BUFFER",
",",
"attribInfo",
".",
"buffer",
",",
"array",
",",
"attribInfo",
".",
"drawType",
")",
";",
"}",
"}"
] | Sets the contents of a buffer attached to an attribInfo
This is helper function to dynamically update a buffer.
Let's say you make a bufferInfo
var arrays = {
position: new Float32Array([0, 0, 0, 10, 0, 0, 0, 10, 0, 10, 10, 0]),
texcoord: new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]),
normal: new Float32Array([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1]),
indices: new Uint16Array([0, 1, 2, 1, 2, 3]),
};
var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays);
And you want to dynamically upate the positions. You could do this
// assuming arrays.position has already been updated with new data.
twgl.setAttribInfoBufferFromArray(gl, bufferInfo.attribs.position, arrays.position);
@param {WebGLRenderingContext} gl
@param {AttribInfo} attribInfo The attribInfo who's buffer contents to set. NOTE: If you have an attribute prefix
the name of the attribute will include the prefix.
@param {ArraySpec} array Note: it is arguably ineffient to pass in anything but a typed array because anything
else will have to be converted to a typed array before it can be used by WebGL. During init time that
inefficiency is usually not important but if you're updating data dynamically best to be efficient.
@param {number} [offset] an optional offset into the buffer. This is only an offset into the WebGL buffer
not the array. To pass in an offset into the array itself use a typed array and create an `ArrayBufferView`
for the portion of the array you want to use.
var someArray = new Float32Array(1000); // an array with 1000 floats
var someSubArray = new Float32Array(someArray.buffer, offsetInBytes, sizeInUnits); // a view into someArray
Now you can pass `someSubArray` into setAttribInfoBufferFromArray`
@memberOf module:twgl/attributes | [
"Sets",
"the",
"contents",
"of",
"a",
"buffer",
"attached",
"to",
"an",
"attribInfo"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/attributes.js#L437-L445 |
8,797 | greggman/twgl.js | src/attributes.js | createBufferFromArray | function createBufferFromArray(gl, array, arrayName) {
const type = arrayName === "indices" ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
const typedArray = makeTypedArray(array, arrayName);
return createBufferFromTypedArray(gl, typedArray, type);
} | javascript | function createBufferFromArray(gl, array, arrayName) {
const type = arrayName === "indices" ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
const typedArray = makeTypedArray(array, arrayName);
return createBufferFromTypedArray(gl, typedArray, type);
} | [
"function",
"createBufferFromArray",
"(",
"gl",
",",
"array",
",",
"arrayName",
")",
"{",
"const",
"type",
"=",
"arrayName",
"===",
"\"indices\"",
"?",
"gl",
".",
"ELEMENT_ARRAY_BUFFER",
":",
"gl",
".",
"ARRAY_BUFFER",
";",
"const",
"typedArray",
"=",
"makeTypedArray",
"(",
"array",
",",
"arrayName",
")",
";",
"return",
"createBufferFromTypedArray",
"(",
"gl",
",",
"typedArray",
",",
"type",
")",
";",
"}"
] | Creates a buffer from an array, typed array, or array spec
Given something like this
[1, 2, 3],
or
new Uint16Array([1,2,3]);
or
{
data: [1, 2, 3],
type: Uint8Array,
}
returns a WebGLBuffer that constains the given data.
@param {WebGLRenderingContext} gl A WebGLRenderingContext.
@param {module:twgl.ArraySpec} array an array, typed array, or array spec.
@param {string} arrayName name of array. Used to guess the type if type can not be dervied other wise.
@return {WebGLBuffer} a WebGLBuffer containing the data in array.
@memberOf module:twgl/attributes | [
"Creates",
"a",
"buffer",
"from",
"an",
"array",
"typed",
"array",
"or",
"array",
"spec"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/attributes.js#L662-L666 |
8,798 | greggman/twgl.js | src/attributes.js | createBuffersFromArrays | function createBuffersFromArrays(gl, arrays) {
const buffers = { };
Object.keys(arrays).forEach(function(key) {
buffers[key] = createBufferFromArray(gl, arrays[key], key);
});
// Ugh!
if (arrays.indices) {
buffers.numElements = arrays.indices.length;
buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
} else {
buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
}
return buffers;
} | javascript | function createBuffersFromArrays(gl, arrays) {
const buffers = { };
Object.keys(arrays).forEach(function(key) {
buffers[key] = createBufferFromArray(gl, arrays[key], key);
});
// Ugh!
if (arrays.indices) {
buffers.numElements = arrays.indices.length;
buffers.elementType = typedArrays.getGLTypeForTypedArray(makeTypedArray(arrays.indices), 'indices');
} else {
buffers.numElements = getNumElementsFromNonIndexedArrays(arrays);
}
return buffers;
} | [
"function",
"createBuffersFromArrays",
"(",
"gl",
",",
"arrays",
")",
"{",
"const",
"buffers",
"=",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"arrays",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"buffers",
"[",
"key",
"]",
"=",
"createBufferFromArray",
"(",
"gl",
",",
"arrays",
"[",
"key",
"]",
",",
"key",
")",
";",
"}",
")",
";",
"// Ugh!",
"if",
"(",
"arrays",
".",
"indices",
")",
"{",
"buffers",
".",
"numElements",
"=",
"arrays",
".",
"indices",
".",
"length",
";",
"buffers",
".",
"elementType",
"=",
"typedArrays",
".",
"getGLTypeForTypedArray",
"(",
"makeTypedArray",
"(",
"arrays",
".",
"indices",
")",
",",
"'indices'",
")",
";",
"}",
"else",
"{",
"buffers",
".",
"numElements",
"=",
"getNumElementsFromNonIndexedArrays",
"(",
"arrays",
")",
";",
"}",
"return",
"buffers",
";",
"}"
] | Creates buffers from arrays or typed arrays
Given something like this
var arrays = {
positions: [1, 2, 3],
normals: [0, 0, 1],
}
returns something like
buffers = {
positions: WebGLBuffer,
normals: WebGLBuffer,
}
If the buffer is named 'indices' it will be made an ELEMENT_ARRAY_BUFFER.
@param {WebGLRenderingContext} gl A WebGLRenderingContext.
@param {module:twgl.Arrays} arrays
@return {Object<string, WebGLBuffer>} returns an object with one WebGLBuffer per array
@memberOf module:twgl/attributes | [
"Creates",
"buffers",
"from",
"arrays",
"or",
"typed",
"arrays"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/attributes.js#L692-L707 |
8,799 | greggman/twgl.js | src/programs.js | addLineNumbers | function addLineNumbers(src, lineOffset) {
lineOffset = lineOffset || 0;
++lineOffset;
return src.split("\n").map(function(line, ndx) {
return (ndx + lineOffset) + ": " + line;
}).join("\n");
} | javascript | function addLineNumbers(src, lineOffset) {
lineOffset = lineOffset || 0;
++lineOffset;
return src.split("\n").map(function(line, ndx) {
return (ndx + lineOffset) + ": " + line;
}).join("\n");
} | [
"function",
"addLineNumbers",
"(",
"src",
",",
"lineOffset",
")",
"{",
"lineOffset",
"=",
"lineOffset",
"||",
"0",
";",
"++",
"lineOffset",
";",
"return",
"src",
".",
"split",
"(",
"\"\\n\"",
")",
".",
"map",
"(",
"function",
"(",
"line",
",",
"ndx",
")",
"{",
"return",
"(",
"ndx",
"+",
"lineOffset",
")",
"+",
"\": \"",
"+",
"line",
";",
"}",
")",
".",
"join",
"(",
"\"\\n\"",
")",
";",
"}"
] | eslint-disable-line
Error Callback
@callback ErrorCallback
@param {string} msg error message.
@param {number} [lineOffset] amount to add to line number
@memberOf module:twgl | [
"eslint",
"-",
"disable",
"-",
"line",
"Error",
"Callback"
] | ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd | https://github.com/greggman/twgl.js/blob/ae88dfe4d7a7d44a5b739fcbe50bccccd0e1a1fd/src/programs.js#L457-L464 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.