repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
supersplat | github_2023 | playcanvas | typescript | Camera.rebuildRenderTargets | rebuildRenderTargets() {
const device = this.scene.graphicsDevice;
const { width, height } = this.scene.targetSize;
const rt = this.entity.camera.renderTarget;
if (rt && rt.width === width && rt.height === height) {
return;
}
// out with the old
if (... | // handle the viewer canvas resizing | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L356-L413 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.pickFocalPoint | pickFocalPoint(screenX: number, screenY: number) {
const scene = this.scene;
const cameraPos = this.entity.getPosition();
const target = scene.canvas;
const sx = screenX / target.clientWidth * scene.targetSize.width;
const sy = screenY / target.clientHeight * scene.targetSize.he... | // intersect the scene at the given screen coordinate and focus the camera on this location | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L509-L568 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.pickPrep | pickPrep(splat: Splat, op: 'add'|'remove'|'set') {
const { width, height } = this.scene.targetSize;
const worldLayer = this.scene.app.scene.layers.getLayerByName('World');
const device = this.scene.graphicsDevice;
const events = this.scene.events;
const alpha = events.invoke('ca... | // render picker contents | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L573-L596 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | dist | const dist = (x0: number, y0: number, x1: number, y1: number) => Math.sqrt((x1 - x0) ** 2 + (y1 - y0) ** 2); | // calculate the distance between two 2d points | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/controllers.ts#L10-L10 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | isMouseEvent | const isMouseEvent = (deltaX: number, deltaY: number) => {
return (Math.abs(deltaX) > 50 && deltaY === 0) ||
(Math.abs(deltaY) > 50 && deltaX === 0) ||
(deltaX === 0 && deltaY !== 0) && !Number.isInteger(deltaY);
}; | // fuzzy detection of mouse wheel events vs trackpad events | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/controllers.ts#L139-L143 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | DataProcessor.intersect | intersect(options: MaskOptions | RectOptions | SphereOptions, splat: Splat) {
const { device } = this;
const { scope } = device;
const numSplats = splat.splatData.numSplats;
const transformA = splat.entity.gsplat.instance.splat.transformATexture;
const splatTransform = splat.tra... | // calculate the intersection of a mask canvas with splat centers | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/data-processor.ts#L229-L311 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | DataProcessor.calcBound | calcBound(splat: Splat, boundingBox: BoundingBox, onlySelected: boolean) {
const device = splat.scene.graphicsDevice;
const { scope } = device;
const numSplats = splat.splatData.numSplats;
const transformA = splat.entity.gsplat.instance.splat.transformATexture;
const splatTransf... | // all visible splats | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/data-processor.ts#L315-L368 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | DataProcessor.calcPositions | calcPositions(splat: Splat) {
const { device } = this;
const { scope } = device;
const numSplats = splat.splatData.numSplats;
const transformA = splat.entity.gsplat.instance.splat.transformATexture;
const splatTransform = splat.transformTexture;
const transformPalette = ... | // calculate world-space splat positions | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/data-processor.ts#L371-L404 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | getResetConfirmation | const getResetConfirmation = async () => {
const result = await events.invoke('showPopup', {
type: 'yesno',
header: localize('doc.reset'),
message: localize(events.invoke('scene.dirty') ? 'doc.unsaved-message' : 'doc.reset-message')
});
if (result.action !== ... | // show the user a reset confirmation popup | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/doc.ts#L60-L72 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | resetScene | const resetScene = () => {
events.fire('scene.clear');
events.fire('camera.reset');
events.fire('doc.setName', null);
documentFileHandle = null;
}; | // reset the scene | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/doc.ts#L75-L80 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | loadDocument | const loadDocument = async (file: File) => {
events.fire('startSpinner');
try {
// reset the scene
resetScene();
// read the document
/* global JSZip */
// @ts-ignore
const zip = new JSZip();
await zip.loadAsync(file);
... | // load the document from the given file | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/doc.ts#L83-L133 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | CreateDropHandler | const CreateDropHandler = (target: HTMLElement, dropHandler: DropHandlerFunc) => {
const dragstart = (ev: DragEvent) => {
ev.preventDefault();
ev.stopPropagation();
ev.dataTransfer.effectAllowed = 'all';
};
const dragover = (ev: DragEvent) => {
ev.preventDefault();
... | // configure drag and drop | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/drop-handler.ts#L77-L123 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | buildIndex | const buildIndex = (total: number, pred: (i: number) => boolean) => {
let num = 0;
for (let i = 0; i < total; ++i) {
if (pred(i)) num++;
}
const result = new Uint32Array(num);
let idx = 0;
for (let i = 0; i < total; ++i) {
if (pred(i)) {
result[idx++] = i;
}
... | // build an index array based on a boolean predicate over indices | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/edit-ops.ts#L17-L32 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | registerEditorEvents | const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: Scene) => {
const vec = new Vec3();
const vec2 = new Vec3();
const vec4 = new Vec4();
const mat = new Mat4();
// get the list of selected splats (currently limited to just a single one)
const selectedSplats = () => {... | // register for editor and scene events | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/editor.ts#L13-L694 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | selectedSplats | const selectedSplats = () => {
const selected = events.invoke('selection') as Splat;
return selected?.visible ? [selected] : [];
}; | // get the list of selected splats (currently limited to just a single one) | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/editor.ts#L20-L23 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setGridVisible | const setGridVisible = (visible: boolean) => {
if (visible !== scene.grid.visible) {
scene.grid.visible = visible;
events.fire('grid.visible', visible);
}
}; | // grid.visible | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/editor.ts#L79-L84 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setCameraFov | const setCameraFov = (fov: number) => {
if (fov !== scene.camera.fov) {
scene.camera.fov = fov;
events.fire('camera.fov', scene.camera.fov);
}
}; | // camera.fov | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/editor.ts#L102-L107 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setFlySpeed | const setFlySpeed = (value: number) => {
if (value !== scene.camera.flySpeed) {
scene.camera.flySpeed = value;
events.fire('camera.flySpeed', value);
}
}; | // camera fly speed | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/editor.ts#L534-L539 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Events.function | function(name: string, fn: FunctionCallback) {
if (this.functions.has(name)) {
throw new Error(`error: function ${name} already exists`);
}
this.functions.set(name, fn);
} | // declare an editor function | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/events.ts#L9-L14 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Events.invoke | invoke(name: string, ...args: any[]) {
const fn = this.functions.get(name);
if (!fn) {
console.log(`error: function not found '${name}'`);
return;
}
return fn(...args);
} | // invoke an editor function | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/events.ts#L17-L24 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | download | const download = (filename: string, data: Uint8Array) => {
const blob = new Blob([data], { type: 'octet/stream' });
const url = window.URL.createObjectURL(blob);
const lnk = document.createElement('a');
lnk.download = filename;
lnk.href = url;
// create a "fake" click-event to trigger the down... | // download the data to the given filename | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L67-L88 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | sorter | const sorter = (a: any, b: any) => {
const avalue = a.img_name?.match(/\d*$/)?.[0];
const bvalue = b.img_name?.match(/\d*$/)?.[0];
return (avalue && bvalue) ? parseInt(avalue, 10) - parseInt(bvalue, 10) : 0;
}; | // sort entries by trailing number if it exists | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L103-L107 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | initFileHandler | const initFileHandler = (scene: Scene, events: Events, dropTarget: HTMLElement, remoteStorageDetails: RemoteStorageDetails) => {
// returns a promise that resolves when the file is loaded
const handleImport = async (url: string, filename?: string, focusCamera = true, animationFrame = false) => {
try {
... | // initialize file handler events | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L128-L431 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | handleImport | const handleImport = async (url: string, filename?: string, focusCamera = true, animationFrame = false) => {
try {
if (!filename) {
// extract filename from url if one isn't provided
try {
filename = new URL(url, document.baseURI).pathname.split('/... | // returns a promise that resolves when the file is loaded | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L131-L160 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | isSequence | const isSequence = () => {
// eslint-disable-next-line regexp/no-super-linear-backtracking
const regex = /(.*?)(\d+).ply$/;
const baseMatch = entries[0].file.name?.match(regex);
if (!baseMatch) {
return false;
}
... | // determine if all files share a common filename prefix followed by | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L212-L228 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | getSplats | const getSplats = () => {
return (scene.getElementsByType(ElementType.splat) as Splat[])
.filter(splat => splat.visible)
.filter(splat => splat.numSplats > 0);
}; | // get the list of visible splats containing gaussians | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/file-handler.ts#L245-L249 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | toColor | const toColor = (value: { r: number, g: number, b: number, a: number }) => {
return new Color(value.r, value.g, value.b, value.a);
}; | // initialize colors from application config | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/main.ts#L208-L210 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | getUser | const getUser = async () => {
try {
const urlResponse = await fetch(`${origin}/api/id`);
return urlResponse.ok && (await urlResponse.json() as User);
} catch (e) {
return null;
}
}; | // check whether user is logged in | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/publish.ts#L23-L30 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | kebabize | const kebabize = (s: string) => s.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase()); | // https://stackoverflow.com/a/67243723/2405687 | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/scene-config.ts#L76-L76 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | rec | const rec = (obj: any, path: string) => {
for (const child in obj) {
const childPath = `${path}${path.length ? '.' : ''}${child}`;
const childValue = obj[child];
switch (typeof childValue) {
case 'number':
obj[child] = params.getNumber(chil... | // recurse the object and replace concrete leaf values with overrides | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/scene-config.ts#L132-L162 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Scene.add | add(element: Element) {
if (!element.scene) {
// add the new element
element.scene = this;
element.add();
this.elements.push(element);
// notify all elements of scene addition
this.forEachElement(e => e !== element && e.onAdded(element));
... | // add a scene element | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/scene.ts#L230-L243 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Scene.remove | remove(element: Element) {
if (element.scene === this) {
// remove from list
this.elements.splice(this.elements.indexOf(element), 1);
// notify listeners
this.events.fire('scene.elementRemoved', element);
// notify all elements of scene removal
... | // remove an element from the scene | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/scene.ts#L246-L260 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Scene.bound | get bound() {
if (this.boundDirty) {
let valid = false;
this.forEachElement((e) => {
const bound = e.worldBound;
if (bound) {
if (!valid) {
valid = true;
this.boundStorage.copy(bound);
... | // get the scene bound | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/scene.ts#L263-L283 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | sigmoid | const sigmoid = (v: number) => 1 / (1 + Math.exp(-v)); | // used for converting PLY opacity | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L74-L74 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | countGaussians | const countGaussians = (splats: Splat[], filter: GaussianFilter) => {
return splats.reduce((accum, splat) => {
filter.set(splat);
for (let i = 0; i < splat.splatData.numSplats; ++i) {
accum += filter.test(i) ? 1 : 0;
}
return accum;
}, 0);
}; | // count the total number of gaussians given a filter | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L117-L125 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | calcSHBands | const calcSHBands = (data: Set<string>) => {
return { '9': 1, '24': 2, '-1': 3 }[shNames.findIndex(v => !data.has(v))] ?? 0;
}; | // determine the number of sh bands present given an object with 'f_rest_*' properties | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L169-L171 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | SingleSplat.constructor | constructor(members: string[], serializeSettings: SerializeSettings) {
const data: any = {};
members.forEach((name) => {
data[name] = 0;
});
const hasPosition = ['x', 'y', 'z'].every(v => data.hasOwnProperty(v));
const hasRotation = ['rot_0', 'rot_1', 'rot_2', 'rot_3... | // specify the data members required | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L285-L425 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | clamp | const clamp = (v: number, min: number, max: number) => Math.max(min, Math.min(max, v)); | // clamp scale because sometimes values are at infinity | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L594-L594 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | packRot | const packRot = (x: number, y: number, z: number, w: number) => {
q.set(x, y, z, w).normalize();
const a = [q.x, q.y, q.z, q.w];
const largest = a.reduce((curr, v, i) => (Math.abs(v) > Math.abs(a[curr]) ? i : curr), 0);
if (a[largest] < 0) {
a[0] = -a[0];... | // pack quaternion into 2,10,10,10 | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L633-L654 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | sortSplats | const sortSplats = (splats: Splat[], indices: CompressedIndex[]) => {
// https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
const encodeMorton3 = (x: number, y: number, z: number) : number => {
const Part1By2 = (x: number) => {
x &= 0x000003ff;
x = (x ^ (x << 16)) & ... | // sort the compressed indices into morton order | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L685-L762 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | encodeMorton3 | const encodeMorton3 = (x: number, y: number, z: number) : number => {
const Part1By2 = (x: number) => {
x &= 0x000003ff;
x = (x ^ (x << 16)) & 0xff0000ff;
x = (x ^ (x << 8)) & 0x0300f00f;
x = (x ^ (x << 4)) & 0x030c30c3;
x = (x ^ (x << 2)) & 0x09249... | // https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/ | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat-serialize.ts#L687-L698 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | createTexture | const createTexture = (name: string, format: number) => {
return new Texture(splatResource.device, {
name: name,
width: width,
height: height,
format: format,
mipmaps: false,
minFilter: FILTER_NEAREST,
... | // pack spherical harmonic data | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat.ts#L137-L149 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Splat.selectionBound | get selectionBound() {
const selectionBound = this.selectionBoundStorage;
if (this.selectionBoundDirty) {
this.scene.dataProcessor.calcBound(this, selectionBound, true);
this.selectionBoundDirty = false;
}
return selectionBound;
} | // get the selection bound | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat.ts#L429-L436 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Splat.localBound | get localBound() {
const localBound = this.localBoundStorage;
if (this.localBoundDirty) {
this.scene.dataProcessor.calcBound(this, localBound, false);
this.localBoundDirty = false;
this.entity.getWorldTransform().transformPoint(localBound.center, vec);
}
... | // get local space bound | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat.ts#L439-L447 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Splat.worldBound | get worldBound() {
const worldBound = this.worldBoundStorage;
if (this.worldBoundDirty) {
// calculate meshinstance aabb (transformed local bound)
worldBound.setFromTransformedAabb(this.localBound, this.entity.getWorldTransform());
// flag scene bound as dirty
... | // get world space bound | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/splat.ts#L450-L460 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | realloc | const realloc = (width: number, height: number) => {
const newTexture = new Texture(device, {
name: 'transformPalette',
width,
height,
format: PIXELFORMAT_RGBA32F,
mipmaps: false,
addressU: ADDRESS_CLAMP_TO_EDGE,... | // reallocate the storage texture and copy over old data | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/transform-palette.ts#L33-L56 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | CubicSpline.evaluateSegment | evaluateSegment(segment: number, t: number, result: number[]) {
const { knots, dim } = this;
const t2 = t * t;
const twot = t + t;
const omt = 1 - t;
const omt2 = omt * omt;
let idx = segment * 3 * dim;
for (let i = 0; i < dim; ++i) {
const p0 = knot... | // evaluate the spline segment at the given normalized time t | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/anim/spline.ts#L43-L65 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | CubicSpline.fromPoints | static fromPoints(times: number[], points: number[], tension = 0) {
const dim = points.length / times.length;
const knots = new Array<number>(times.length * dim * 3);
for (let i = 0; i < times.length; i++) {
const t = times[i];
for (let j = 0; j < dim; j++) {
... | // tension: level of smoothness, 0 = smooth, 1 = linear interpolation | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/anim/spline.ts#L71-L105 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | ZipWriter.file | async file(filename: string, content: string | Uint8Array) {
// start a new file
await this.start(filename);
// write file contents
await this.write(typeof content === 'string' ? new TextEncoder().encode(content) : content);
} | // helper function to start and write file contents | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/serialize/zip-writer.ts#L17-L23 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | ZipWriter.constructor | constructor(writer: Writer) {
const textEncoder = new TextEncoder();
const files: { filename: Uint8Array, crc: Crc, sizeBytes: number }[] = [];
const writeHeader = async (filename: string) => {
const header = new Uint8Array(30 + filename.length);
const view = new DataVie... | // write uncompressed data to a zip file using the passed-in writer | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/serialize/zip-writer.ts#L26-L113 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | reattach | const reattach = () => {
if (!active || !events.invoke('selection')) {
gizmo.detach();
} else if (!dragging) {
pivot = events.invoke('pivot') as Pivot;
pivotEntity.setLocalPosition(pivot.transform.position);
pivotEntity.setLocalRota... | // reattach the gizmo to the pivot | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/tools/transform-tool.ts#L39-L49 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | updateGizmoSize | const updateGizmoSize = () => {
const { camera, canvas } = scene;
if (camera.ortho) {
gizmo.size = 1125 / canvas.clientHeight;
} else {
gizmo.size = 1200 / Math.max(canvas.clientWidth, canvas.clientHeight);
}
}; | // set the gizmo size to remain a constant size in screen space. | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/tools/transform-tool.ts#L62-L69 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | createSvg | const createSvg = (svgString: string) => {
const decodedStr = decodeURIComponent(svgString.substring('data:image/svg+xml,'.length));
return new DOMParser().parseFromString(decodedStr, 'image/svg+xml').documentElement;
}; | // import cropSvg from './svg/crop.svg'; | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/bottom-toolbar.ts#L15-L18 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | stop | const stop = () => {
posePlay.text = '\uE131';
animHandle.off();
animHandle = null;
}; | // stop the playing animation | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/camera-panel.ts#L114-L118 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | play | const play = () => {
posePlay.text = '\uE135';
// construct the spline points to be interpolated
const times = poses.map((p, i) => i);
const points = [];
for (let i = 0; i < poses.length; ++i) {
const p = poses[i].pose;
points.... | // start playing the current camera poses animation | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/camera-panel.ts#L203-L233 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setVisible | const setVisible = (visible: boolean) => {
if (visible === this.hidden) {
this.hidden = !visible;
events.fire('cameraPanel.visible', visible);
}
}; | // handle panel visibility | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/camera-panel.ts#L281-L286 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setVisible | const setVisible = (visible: boolean) => {
if (visible === this.hidden) {
this.hidden = !visible;
events.fire('colorPanel.visible', visible);
}
}; | // handle panel visibility | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/color-panel.ts#L341-L346 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | sepLabel | const sepLabel = (labelText: string) => {
const container = new Container({
class: 'control-parent',
id: 'sep-container'
});
container.class.add('sep-container');
const label = new Label({
class: 'control-element-expand',
text: labelText
});
container.append(la... | // build a separator label | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/data-panel.ts#L27-L43 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | dataLabel | const dataLabel = (parent: Container, labelText: string) => {
const container = new Container({
class: 'control-parent'
});
const label = new Label({
class: 'control-label',
text: labelText
});
const value = new Label({
class: 'control-element-expand'
});
c... | // build a data label | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/data-panel.ts#L46-L66 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | getValueFunc | const getValueFunc = () => {
// @ts-ignore
const dataFunc = dataFuncs[dataSelector.value];
const data = splat.splatData.getProp(dataSelector.value);
let func: (i: number) => number;
if (dataFunc && data) {
func = i => dataFunc(data[i]);
... | // returns a function which will interpret the splat data for purposes of | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/data-panel.ts#L187-L246 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | reset | const reset = () => {
const splats = events.invoke('scene.splats');
const filename = splats[0].filename;
const dot = splats[0].filename.lastIndexOf('.');
const hasPoses = events.invoke('camera.poses').length > 0;
const bgClr = events.invoke('bgClr');
... | // reset UI and configure for current state | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/publish-settings-dialog.ts#L196-L214 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | updateUI | const updateUI = (pivot: Pivot) => {
uiUpdating = true;
const transform = pivot.transform;
transform.rotation.getEulerAngles(v);
positionVector.value = toArray(transform.position);
rotationVector.value = toArray(v);
scaleInput.value = transform.sca... | // update UI with pivot | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/transform.ts#L125-L133 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | updatePivot | const updatePivot = (pivot: Pivot) => {
const p = positionVector.value;
const r = rotationVector.value;
const q = new Quat().setFromEulerAngles(r[0], r[1], r[2]);
const s = scaleInput.value;
if (q.w < 0) {
q.mulScalar(-1);
}
... | // update pivot with UI | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/transform.ts#L136-L147 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | change | const change = () => {
if (!uiUpdating) {
const pivot = events.invoke('pivot') as Pivot;
if (mouseUpdating) {
updatePivot(pivot);
} else {
pivot.start();
updatePivot(pivot);
pivot.... | // handle a change in the UI state | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/transform.ts#L150-L161 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | setVisible | const setVisible = (visible: boolean) => {
if (visible === this.hidden) {
this.hidden = !visible;
events.fire('viewPanel.visible', visible);
}
}; | // handle panel visibility | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/ui/view-panel.ts#L294-L299 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
ChatterUI | github_2023 | Vali-98 | typescript | verifyJSON | const verifyJSON = (source: any, target: any): any => {
const fillFields = (sourceObj: any, targetObj: any): any => {
if (typeof sourceObj !== 'object' || sourceObj === null) {
sourceObj = Array.isArray(targetObj) ? [] : {}
}
for (const key of Object.keys(targetObj)) {
... | // recursively fill json in case it is incorrect | https://github.com/Vali-98/ChatterUI/blob/5b2c715cfa57cc9c7ec969408c71def313554bb9/lib/engine/API/APIManagerState.ts#L104-L120 | 5b2c715cfa57cc9c7ec969408c71def313554bb9 |
ChatterUI | github_2023 | Vali-98 | typescript | insertLogs | const insertLogs = (data: Log) => {
const logs = getLogs()
logs.push(data)
if (logs.length > maxloglength) logs.shift()
mmkv.set(Global.Logs, JSON.stringify(logs))
} | // new api | https://github.com/Vali-98/ChatterUI/blob/5b2c715cfa57cc9c7ec969408c71def313554bb9/lib/state/Logger.ts#L62-L67 | 5b2c715cfa57cc9c7ec969408c71def313554bb9 |
ChatterUI | github_2023 | Vali-98 | typescript | useSpacingState | const useSpacingState = () => {
const spacing = {
xs: 2,
s: 4,
sm: 6,
m: 8,
l: 12,
xl: 16,
xl2: 24,
xl3: 32,
}
return spacing
} | // TODO: State-ify | https://github.com/Vali-98/ChatterUI/blob/5b2c715cfa57cc9c7ec969408c71def313554bb9/lib/theme/ThemeManager.ts#L80-L92 | 5b2c715cfa57cc9c7ec969408c71def313554bb9 |
ChatterUI | github_2023 | Vali-98 | typescript | useFontState | const useFontState = () => {
return ''
} | // TODO: Research fonts | https://github.com/Vali-98/ChatterUI/blob/5b2c715cfa57cc9c7ec969408c71def313554bb9/lib/theme/ThemeManager.ts#L114-L116 | 5b2c715cfa57cc9c7ec969408c71def313554bb9 |
ChatterUI | github_2023 | Vali-98 | typescript | extractChunks | function extractChunks(data: Uint8Array) {
if (data[0] !== 0x89 || data[1] !== 0x50 || data[2] !== 0x4e || data[3] !== 0x47)
throw new Error('Invalid .png file header')
if (data[4] !== 0x0d || data[5] !== 0x0a || data[6] !== 0x1a || data[7] !== 0x0a)
throw new Error(
'Invalid .png f... | /// PNG DATA | https://github.com/Vali-98/ChatterUI/blob/5b2c715cfa57cc9c7ec969408c71def313554bb9/lib/utils/PNG.ts#L13-L89 | 5b2c715cfa57cc9c7ec969408c71def313554bb9 |
serwist | github_2023 | serwist | typescript | resolveEntry | const resolveEntry = (entry: string): string | null => {
if (fs.existsSync(entry)) {
const stats = fs.statSync(entry);
if (stats.isDirectory()) {
return resolveEntry(path.join(entry, "index"));
}
return entry;
}
const dir = path.dirname(entry);
if (fs.existsSync(dir)) {
const base = ... | // Source: https://github.com/sveltejs/kit/blob/6419d3eaa7bf1b0a756b28f06a73f71fe042de0a/packages/kit/src/utils/filesystem.js | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/docs/vite.config.ts#L21-L42 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | buildPlugin | const buildPlugin = (ctx: SerwistViteContext, api: SerwistViteApi) => {
return <Plugin>{
name: "@serwist/vite:build",
apply: "build",
enforce: "pre",
closeBundle: {
sequential: true,
order: ctx.userOptions?.integration?.closeBundleOrder,
async handler() {
if (api && !api.disa... | // We do not rely on `@serwist/vite`'s built-in `buildPlugin` because | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/docs/vite.config.ts#L53-L71 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | serwist | const serwist = (): Plugin[] => {
let buildAssetsDir = config.kit?.appDir ?? "_app/";
if (buildAssetsDir[0] === "/") {
buildAssetsDir = buildAssetsDir.slice(1);
}
if (buildAssetsDir[buildAssetsDir.length - 1] !== "/") {
buildAssetsDir += "/";
}
// This part is your Serwist configuration.
const opt... | // Here is the main logic: it stores your Serwist configuration, creates `@serwist/vite`'s | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/docs/vite.config.ts#L75-L167 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | processor | const processor = async (res: (value: ItemResult<K>[]) => void) => {
const results: ItemResult<K>[] = [];
while (true) {
const next = work.pop();
if (!next) {
return res(results);
}
const result = await func(next.item);
results.push({
result: result,
index: ... | // Process array items | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/$private/utils/src/parallel.ts#L20-L33 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | runBuildCommand | const runBuildCommand = async ({ config, watch }: BuildCommand) => {
const { count, filePaths, size, warnings } = await injectManifest(config);
for (const warning of warnings) {
logger.warn(warning);
}
if (filePaths.length === 1) {
logger.log(`The service worker file was written to ${config.swDest}`);... | /**
* Runs the specified build command with the provided configuration.
*
* @param options
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/cli/src/app.ts#L33-L55 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | getSubdirectories | const getSubdirectories = async (): Promise<string[]> => {
return await glob("*/", {
ignore: constants.ignoredDirectories.map((directory) => `${directory}/`),
});
}; | /**
* @returns The subdirectories of the current
* working directory, with hidden and ignored ones filtered out.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/cli/src/lib/ask-questions.ts#L15-L19 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | getAllFileExtensions | const getAllFileExtensions = async (globDirectory: string) => {
// Use a pattern to match any file that contains a '.', since that signifies
// the presence of a file extension.
const files: string[] = await glob("**/*.*", {
cwd: globDirectory,
nodir: true,
ignore: [
...constants.ignoredDirector... | /**
* @param globDirectory The directory used for the root of globbing.
* @returns The unique file extensions corresponding
* to all of the files under globDirectory.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/cli/src/lib/ask-questions.ts#L61-L83 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | NavigationRoute.constructor | constructor(handler: RouteHandler, { allowlist = [/./], denylist = [] }: NavigationRouteMatchOptions = {}) {
if (process.env.NODE_ENV !== "production") {
assert!.isArrayOfClass(allowlist, RegExp, {
moduleName: "serwist",
className: "NavigationRoute",
funcName: "constructor",
pa... | /**
* If both `denylist` and `allowlist` are provided, `denylist` will
* take precedence.
*
* The regular expressions in `allowlist` and `denylist`
* are matched against the concatenated
* [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
* and [`sear... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/NavigationRoute.ts#L59-L79 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | NavigationRoute._match | private _match({ url, request }: RouteMatchCallbackOptions): boolean {
if (request && request.mode !== "navigate") {
return false;
}
const pathnameAndSearch = url.pathname + url.search;
for (const regExp of this._denylist) {
if (regExp.test(pathnameAndSearch)) {
if (process.env.NOD... | /**
* Routes match handler.
*
* @param options
* @returns
* @private
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/NavigationRoute.ts#L88-L117 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | PrecacheRoute.constructor | constructor(serwist: Serwist, options?: PrecacheRouteOptions) {
const match: RouteMatchCallback = ({ request }: RouteMatchCallbackOptions) => {
const urlsToCacheKeys = serwist.getUrlsToPrecacheKeys();
for (const possibleURL of generateURLVariations(request.url, options)) {
const cacheKey = urlsT... | /**
* @param serwist A {@linkcode Serwist} instance.
* @param options Options to control how requests are matched
* against the list of precached URLs.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/PrecacheRoute.ts#L27-L44 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | RegExpRoute.constructor | constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod) {
if (process.env.NODE_ENV !== "production") {
assert!.isInstance(regExp, RegExp, {
moduleName: "serwist",
className: "RegExpRoute",
funcName: "constructor",
paramName: "pattern",
});
}
const... | /**
* If the regular expression contains
* [capture groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references),
* the captured values will be passed to the `params` argument.
*
* @param regExp The regular expression to match against URLs.
... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/RegExpRoute.ts#L33-L73 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Route.constructor | constructor(match: RouteMatchCallback, handler: RouteHandler, method: HTTPMethod = defaultMethod) {
if (process.env.NODE_ENV !== "production") {
assert!.isType(match, "function", {
moduleName: "serwist",
className: "Route",
funcName: "constructor",
paramName: "match",
});... | /**
* Constructor for Route class.
*
* @param match A callback function that determines whether the
* route matches a given `fetch` event by returning a truthy value.
* @param handler A callback function that returns a `Promise` resolving
* to a `Response`.
* @param method The HTTP method to match ... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Route.ts#L38-L57 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Route.setCatchHandler | setCatchHandler(handler: RouteHandler): void {
this.catchHandler = normalizeHandler(handler);
} | /**
*
* @param handler A callback function that returns a Promise resolving
* to a Response.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Route.ts#L64-L66 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.precacheStrategy | get precacheStrategy(): Strategy {
return this._precacheStrategy;
} | /**
* The strategy used to precache assets and respond to `fetch` events.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L243-L245 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.routes | get routes(): Map<HTTPMethod, Route[]> {
return this._routes;
} | /**
* A `Map` of HTTP method name (`'GET'`, etc.) to an array of all corresponding registered {@linkcode Route}
* instances.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L250-L252 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.addEventListeners | addEventListeners() {
self.addEventListener("install", this.handleInstall);
self.addEventListener("activate", this.handleActivate);
self.addEventListener("fetch", this.handleFetch);
self.addEventListener("message", this.handleCache);
} | /**
* Adds Serwist's event listeners for you. Before calling it, add your own listeners should you need to.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L257-L262 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.addToPrecacheList | addToPrecacheList(entries: (PrecacheEntry | string)[]): void {
if (process.env.NODE_ENV !== "production") {
assert!.isArray(entries, {
moduleName: "serwist",
className: "Serwist",
funcName: "addToCacheList",
paramName: "entries",
});
}
const urlsToWarnAbout: stri... | /**
* Adds items to the precache list, removing duplicates and ensuring the information is valid.
*
* @param entries Array of entries to precache.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L269-L323 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.handleInstall | handleInstall(event: ExtendableEvent): Promise<InstallResult> {
return waitUntil<InstallResult>(event, async () => {
const installReportPlugin = new PrecacheInstallReportPlugin();
this.precacheStrategy.plugins.push(installReportPlugin);
await parallel(this._concurrentPrecaching, Array.from(this._... | /**
* Precaches new and updated assets. Call this method from the service worker's
* `install` event.
*
* Note: this method calls `event.waitUntil()` for you, so you do not need
* to call it yourself in your event handlers.
*
* @param event
* @returns
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L335-L368 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.handleActivate | handleActivate(event: ExtendableEvent): Promise<CleanupResult> {
return waitUntil<CleanupResult>(event, async () => {
const cache = await self.caches.open(this.precacheStrategy.cacheName);
const currentlyCachedRequests = await cache.keys();
const expectedCacheKeys = new Set(this._urlsToCacheKeys.v... | /**
* Deletes assets that are no longer present in the current precache manifest.
* Call this method from the service worker's `activate` event.
*
* Note: this method calls `event.waitUntil()` for you, so you do not need
* to call it yourself in your event handlers.
*
* @param event
* @returns
... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L380-L401 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.handleFetch | handleFetch(event: FetchEvent) {
const { request } = event;
const responsePromise = this.handleRequest({ request, event });
if (responsePromise) {
event.respondWith(responsePromise);
}
} | /**
* Gets a `Response` from an appropriate `Route`'s handler. Call this method
* from the service worker's `fetch` event.
* @param event
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L408-L414 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.handleCache | handleCache(event: ExtendableMessageEvent) {
if (event.data && event.data.type === "CACHE_URLS") {
const { payload }: CacheURLsMessageData = event.data;
if (process.env.NODE_ENV !== "production") {
logger.debug("Caching URLs from the window", payload.urlsToCache);
}
const requestPr... | /**
* Caches new URLs on demand. Call this method from the service worker's
* `message` event. To trigger the handler, send a message of type `"CACHE_URLS"`
* alongside a list of URLs that should be cached as `urlsToCache`.
* @param event
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L422-L449 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.setDefaultHandler | setDefaultHandler(handler: RouteHandler, method: HTTPMethod = defaultMethod): void {
this._defaultHandlerMap.set(method, normalizeHandler(handler));
} | /**
* Define a default handler that's called when no routes explicitly
* match the incoming request.
*
* Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
*
* Without a default handler, unmatched requests will go against the
* network as if there were no service worker presen... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L464-L466 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.setCatchHandler | setCatchHandler(handler: RouteHandler): void {
this._catchHandler = normalizeHandler(handler);
} | /**
* If a {@linkcode Route} throws an error while handling a request, this handler
* will be called and given a chance to provide a response.
*
* @param handler A callback function that returns a `Promise` resulting
* in a `Response`.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L475-L477 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.registerCapture | registerCapture<T extends RegExp | string | RouteMatchCallback | Route>(
capture: T,
handler?: T extends Route ? never : RouteHandler,
method?: T extends Route ? never : HTTPMethod,
): Route {
const route = parseRoute(capture, handler, method);
this.registerRoute(route);
return route;
} | /**
* Registers a `RegExp`, string, or function with a caching
* strategy to the router.
*
* @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
* This parameter... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L489-L497 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.registerRoute | registerRoute(route: Route): void {
if (process.env.NODE_ENV !== "production") {
assert!.isType(route, "object", {
moduleName: "serwist",
className: "Serwist",
funcName: "registerRoute",
paramName: "route",
});
assert!.hasMethod(route, "match", {
moduleName... | /**
* Registers a {@linkcode Route} with the router.
*
* @param route The {@linkcode Route} to register.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L504-L549 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.unregisterRoute | unregisterRoute(route: Route): void {
if (!this._routes.has(route.method)) {
throw new SerwistError("unregister-route-but-not-found-with-method", {
method: route.method,
});
}
const routeIndex = this._routes.get(route.method)!.indexOf(route);
if (routeIndex > -1) {
this._route... | /**
* Unregisters a route from the router.
*
* @param route The {@linkcode Route} object to unregister.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L556-L569 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.getUrlsToPrecacheKeys | getUrlsToPrecacheKeys(): Map<string, string> {
return this._urlsToCacheKeys;
} | /**
* Returns a mapping of a precached URL to the corresponding cache key, taking
* into account the revision information for the URL.
*
* @returns A URL to cache key mapping.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L577-L579 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.getPrecachedUrls | getPrecachedUrls(): string[] {
return [...this._urlsToCacheKeys.keys()];
} | /**
* Returns a list of all the URLs that have been precached by the current
* service worker.
*
* @returns The precached URLs.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L587-L589 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.getPrecacheKeyForUrl | getPrecacheKeyForUrl(url: string): string | undefined {
const urlObject = new URL(url, location.href);
return this._urlsToCacheKeys.get(urlObject.href);
} | /**
* Returns the cache key used for storing a given URL. If that URL is
* unversioned, like "/index.html", then the cache key will be the original
* URL with a search parameter appended to it.
*
* @param url A URL whose cache key you want to look up.
* @returns The versioned URL that corresponds to a... | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L600-L603 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
serwist | github_2023 | serwist | typescript | Serwist.getIntegrityForPrecacheKey | getIntegrityForPrecacheKey(cacheKey: string): string | undefined {
return this._cacheKeysToIntegrities.get(cacheKey);
} | /**
* @param url A cache key whose SRI you want to look up.
* @returns The subresource integrity associated with the cache key,
* or undefined if it's not set.
*/ | https://github.com/serwist/serwist/blob/9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f/packages/core/src/Serwist.ts#L610-L612 | 9dc72e205f8079b7ace12d2d4ea9aad7bc1cb83f |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.