diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000000000000000000000000000000000000..4395511c69eb632aea58b1178383bc31348d7ab5 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +node_modules/* +build/* +lib/* \ No newline at end of file diff --git a/package.json b/package.json index 895748255601adfe3995d9b74f0c552b4eab1356..bff38fd72c5d9c5629b599a73022bbb54b19645e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "url": "https://github.com/molstar/molstar/issues" }, "scripts": { - "lint": "eslint src/**/*.{ts,tsx}", + "lint": "eslint ./**/*.{ts,tsx}", + "lint-fix": "eslint ./**/*.{ts,tsx} --fix", "test": "npm run lint && jest", "build": "npm run build-tsc && npm run build-extra && npm run build-webpack", "build-tsc": "tsc --incremental", diff --git a/src/mol-geo/geometry/mesh/mesh.ts b/src/mol-geo/geometry/mesh/mesh.ts index 13c84a55d7aa46f31d8d1447ceb5026b88f27ae2..8312a55eb631076a31c8c92b77387a47c82d5b9a 100644 --- a/src/mol-geo/geometry/mesh/mesh.ts +++ b/src/mol-geo/geometry/mesh/mesh.ts @@ -226,11 +226,11 @@ export namespace Mesh { Vec3.fromArray(vi, vb, i * 3) Vec3.fromArray(vj, vb, j * 3) Vec3.fromArray(vk, vb, k * 3) - Vec3.scale(vi, Vec3.add(vi, Vec3.add(vi, vi, vj), vk), 1/3) + Vec3.scale(vi, Vec3.add(vi, Vec3.add(vi, vi, vj), vk), 1 / 3) Vec3.fromArray(ni, nb, i * 3) Vec3.fromArray(nj, nb, j * 3) Vec3.fromArray(nk, nb, k * 3) - Vec3.scale(ni, Vec3.add(ni, Vec3.add(ni, ni, nj), nk), 1/3) + Vec3.scale(ni, Vec3.add(ni, Vec3.add(ni, ni, nj), nk), 1 / 3) ChunkedArray.add3(vertex, vi[0], vi[1], vi[2]) ChunkedArray.add3(normal, ni[0], ni[1], ni[2]) } diff --git a/src/mol-geo/geometry/text/text-builder.ts b/src/mol-geo/geometry/text/text-builder.ts index 577efb3a78947b81a8e959c64b2c0893dd16845b..a5932c03840562668f5967b05a86b464151a63ce 100644 --- a/src/mol-geo/geometry/text/text-builder.ts +++ b/src/mol-geo/geometry/text/text-builder.ts @@ -289,7 +289,7 @@ export namespace TextBuilder { const ib = ChunkedArray.compact(indices, true) as Uint32Array const gb = ChunkedArray.compact(groups, true) as Float32Array const tb = ChunkedArray.compact(tcoords, true) as Float32Array - return Text.create(ft, cb,mb, db, ib, gb, tb, indices.elementCount / 2, text) + return Text.create(ft, cb, mb, db, ib, gb, tb, indices.elementCount / 2, text) } } } diff --git a/src/mol-io/reader/csv/parser.ts b/src/mol-io/reader/csv/parser.ts index 894d100e9bf9b31fd68975c9f3dad53b15b8a4f5..18897338fc0d215f4b683c29232989f18bac8638 100644 --- a/src/mol-io/reader/csv/parser.ts +++ b/src/mol-io/reader/csv/parser.ts @@ -247,7 +247,7 @@ function init(state: State) { addColumn(state) state.columnCount = state.columnNames.length if (state.noColumnNamesRecord) { - state.columnNames.forEach((x, i, arr) => arr[i] = i+'') + state.columnNames.forEach((x, i, arr) => arr[i] = i + '') Tokenizer.reset(state.tokenizer) } } diff --git a/src/mol-math/geometry/_spec/lookup3d.spec.ts b/src/mol-math/geometry/_spec/lookup3d.spec.ts index afecd5d053b37b93b44a3f899884691d43acafd2..679593fc745cea23c9a15439ed57ec3eda412500 100644 --- a/src/mol-math/geometry/_spec/lookup3d.spec.ts +++ b/src/mol-math/geometry/_spec/lookup3d.spec.ts @@ -12,7 +12,7 @@ import { getBoundary } from '../boundary'; const xs = [0, 0, 1]; const ys = [0, 1, 0]; const zs = [0, 0, 0]; -const rs = [0, 0.5, 1/3]; +const rs = [0, 0.5, 1 / 3]; describe('GridLookup3d', () => { it('basic', () => { diff --git a/src/mol-math/geometry/spacegroup/construction.ts b/src/mol-math/geometry/spacegroup/construction.ts index c18763b15449add33bc4a91bb42407b8a044c1f5..6ac668ceefecadc84ac66f344210d3ab448c03ba 100644 --- a/src/mol-math/geometry/spacegroup/construction.ts +++ b/src/mol-math/geometry/spacegroup/construction.ts @@ -178,13 +178,13 @@ namespace Spacegroup { function getShift(s: number) { switch (s) { - case 1/2: return '1/2' - case 1/4: return '1/4' - case 3/4: return '3/4' - case 1/3: return '1/3' - case 2/3: return '2/3' - case 1/6: return '1/6' - case 5/6: return '5/6' + case 1 / 2: return '1/2' + case 1 / 4: return '1/4' + case 3 / 4: return '3/4' + case 1 / 3: return '1/3' + case 2 / 3: return '2/3' + case 1 / 6: return '1/6' + case 5 / 6: return '5/6' } return '' } diff --git a/src/mol-math/geometry/spacegroup/tables.ts b/src/mol-math/geometry/spacegroup/tables.ts index 996f4449fe70de22623b3ddc5c25e648c6bac1ed..4a1e2acd033952ff6f4bf0964684fa99c3463af1 100644 --- a/src/mol-math/geometry/spacegroup/tables.ts +++ b/src/mol-math/geometry/spacegroup/tables.ts @@ -32,26 +32,26 @@ export const TransformData = [ [0.0, 0.0, -1.0, 0.75], [1.0, -1.0, 0.0, 0.0], [-1.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 1.0, 1/3], - [0.0, 0.0, 1.0, 2/3], - [1.0, 0.0, 0.0, 2/3], - [0.0, 1.0, 0.0, 1/3], - [0.0, -1.0, 0.0, 2/3], - [1.0, -1.0, 0.0, 1/3], - [-1.0, 1.0, 0.0, 2/3], - [-1.0, 0.0, 0.0, 1/3], - [1.0, 0.0, 0.0, 1/3], - [0.0, 1.0, 0.0, 2/3], - [0.0, -1.0, 0.0, 1/3], - [1.0, -1.0, 0.0, 2/3], - [-1.0, 1.0, 0.0, 1/3], - [-1.0, 0.0, 0.0, 2/3], - [0.0, 0.0, -1.0, 1/3], - [0.0, 0.0, -1.0, 2/3], - [0.0, 0.0, 1.0, 5/6], - [0.0, 0.0, 1.0, 1/6], - [0.0, 0.0, -1.0, 5/6], - [0.0, 0.0, -1.0, 1/6], + [0.0, 0.0, 1.0, 1 / 3], + [0.0, 0.0, 1.0, 2 / 3], + [1.0, 0.0, 0.0, 2 / 3], + [0.0, 1.0, 0.0, 1 / 3], + [0.0, -1.0, 0.0, 2 / 3], + [1.0, -1.0, 0.0, 1 / 3], + [-1.0, 1.0, 0.0, 2 / 3], + [-1.0, 0.0, 0.0, 1 / 3], + [1.0, 0.0, 0.0, 1 / 3], + [0.0, 1.0, 0.0, 2 / 3], + [0.0, -1.0, 0.0, 1 / 3], + [1.0, -1.0, 0.0, 2 / 3], + [-1.0, 1.0, 0.0, 1 / 3], + [-1.0, 0.0, 0.0, 2 / 3], + [0.0, 0.0, -1.0, 1 / 3], + [0.0, 0.0, -1.0, 2 / 3], + [0.0, 0.0, 1.0, 5 / 6], + [0.0, 0.0, 1.0, 1 / 6], + [0.0, 0.0, -1.0, 5 / 6], + [0.0, 0.0, -1.0, 1 / 6], ]; export const OperatorData = [ diff --git a/src/mol-math/linear-algebra/3d/mat4.ts b/src/mol-math/linear-algebra/3d/mat4.ts index 6fd4bd0316504952edb1f460cb45aa5a4fabd592..e935e6ae3b8a1790a312eeaff188a86d14c93bcb 100644 --- a/src/mol-math/linear-algebra/3d/mat4.ts +++ b/src/mol-math/linear-algebra/3d/mat4.ts @@ -997,7 +997,7 @@ namespace Mat4 { z1 = eyey - target[1], z2 = eyez - target[2]; - let len = z0*z0 + z1*z1 + z2*z2; + let len = z0 * z0 + z1 * z1 + z2 * z2; if (len > 0) { len = 1 / Math.sqrt(len); z0 *= len; @@ -1009,7 +1009,7 @@ namespace Mat4 { x1 = upz * z0 - upx * z2, x2 = upx * z1 - upy * z0; - len = x0*x0 + x1*x1 + x2*x2; + len = x0 * x0 + x1 * x1 + x2 * x2; if (len > 0) { len = 1 / Math.sqrt(len); x0 *= len; diff --git a/src/mol-math/linear-algebra/3d/quat.ts b/src/mol-math/linear-algebra/3d/quat.ts index eaab0f5a6ef9ede22ef42316c06d6ce0b072fa10..d62524c853ff6658c47d6250548e73d837700169 100644 --- a/src/mol-math/linear-algebra/3d/quat.ts +++ b/src/mol-math/linear-algebra/3d/quat.ts @@ -215,7 +215,7 @@ namespace Quat { export function invert(out: Quat, a: Quat) { let a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3]; let dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3; - let invDot = dot ? 1.0/dot : 0; + let invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 @@ -254,24 +254,24 @@ namespace Quat { // |w| > 1/2, may as well choose w > 1/2 fRoot = Math.sqrt(fTrace + 1.0); // 2w out[3] = 0.5 * fRoot; - fRoot = 0.5/fRoot; // 1/(4w) - out[0] = (m[5]-m[7])*fRoot; - out[1] = (m[6]-m[2])*fRoot; - out[2] = (m[1]-m[3])*fRoot; + fRoot = 0.5 / fRoot; // 1/(4w) + out[0] = (m[5] - m[7]) * fRoot; + out[1] = (m[6] - m[2]) * fRoot; + out[2] = (m[1] - m[3]) * fRoot; } else { // |w| <= 1/2 let i = 0; if ( m[4] > m[0] ) i = 1; - if ( m[8] > m[i*3+i] ) i = 2; - let j = (i+1)%3; - let k = (i+2)%3; + if ( m[8] > m[i * 3 + i] ) i = 2; + let j = (i + 1) % 3; + let k = (i + 2) % 3; - fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0); + fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0); out[i] = 0.5 * fRoot; fRoot = 0.5 / fRoot; - out[3] = (m[j*3+k] - m[k*3+j]) * fRoot; - out[j] = (m[j*3+i] + m[i*3+j]) * fRoot; - out[k] = (m[k*3+i] + m[i*3+k]) * fRoot; + out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot; + out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot; + out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot; } return out; @@ -359,7 +359,7 @@ namespace Quat { let y = a[1]; let z = a[2]; let w = a[3]; - let len = x*x + y*y + z*z + w*w; + let len = x * x + y * y + z * z + w * w; if (len > 0) { len = 1 / Math.sqrt(len); out[0] = x * len; diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index 0a02c4efd3c48c8419e1ffe3ba2fca77465e36be..7d111c071ebfa5ab534637f1c2fb73d66e5bb9ab 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -373,7 +373,7 @@ namespace Vec3 { export function random(out: Vec3, scale: number) { const r = Math.random() * 2.0 * Math.PI; const z = (Math.random() * 2.0) - 1.0; - const zScale = Math.sqrt(1.0-z*z) * scale; + const zScale = Math.sqrt(1.0 - z * z) * scale; out[0] = Math.cos(r) * zScale; out[1] = Math.sin(r) * zScale; diff --git a/src/mol-model/structure/structure/util/unit-transforms.ts b/src/mol-model/structure/structure/util/unit-transforms.ts index 0fb9d319df145525766cb29df4675cc2a2725112..472147133be4821342c792d19b2821157ef400bb 100644 --- a/src/mol-model/structure/structure/util/unit-transforms.ts +++ b/src/mol-model/structure/structure/util/unit-transforms.ts @@ -28,7 +28,7 @@ export class StructureUnitTransforms { this.size = structure.units.length this.reset() // to set to identity let groupOffset = 0 - for (let i = 0, il = structure.unitSymmetryGroups.length; i <il; ++i) { + for (let i = 0, il = structure.unitSymmetryGroups.length; i < il; ++i) { const g = structure.unitSymmetryGroups[i] this.groupIndexMap.set(g.hashCode, i) const groupTransforms = this.unitTransforms.subarray(groupOffset, groupOffset + g.units.length * 16) diff --git a/src/mol-plugin-ui/controls/common.tsx b/src/mol-plugin-ui/controls/common.tsx index 0e9babd28c7a68d352293d451b043b2c9c80ff7a..d0df8ba15e38ad9d45f77481d0991e0e0bb08484 100644 --- a/src/mol-plugin-ui/controls/common.tsx +++ b/src/mol-plugin-ui/controls/common.tsx @@ -325,7 +325,7 @@ export function IconButton(props: { className += ` msp-btn-link-toggle-${props.toggleState ? 'on' : 'off'}` } if (props.transparent) { - className+= ' msp-transparent-bg' + className += ' msp-transparent-bg' } const iconStyle = props.small ? { fontSize: '80%' } : void 0; diff --git a/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx b/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx index 1503f5531a09fe3935bab6858e651e82711a02a2..0d88187a1839753eac903dc6d42c423d93ab68c6 100644 --- a/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx +++ b/src/mol-plugin-ui/controls/line-graph/line-graph-component.tsx @@ -51,12 +51,12 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo this.state.points.sort((a, b) => { if(a[0] === b[0]){ if(a[0] === 0){ - return a[1]-b[1]; + return a[1] - b[1]; } if(a[1] === 1){ - return b[1]-a[1]; + return b[1] - a[1]; } - return a[1]-b[1]; + return a[1] - b[1]; } return a[0] - b[0]; }); @@ -82,7 +82,7 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo <svg className="msp-canvas" ref={this.refCallBack} - viewBox={`0 0 ${this.width+this.padding} ${this.height+this.padding}`} + viewBox={`0 0 ${this.width + this.padding} ${this.height + this.padding}`} onMouseMove={this.handleDrag} onMouseUp={this.handlePointUpdate} onMouseLeave={this.handleLeave} @@ -128,7 +128,7 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo } private handleMouseDown = (id: number) => (event: any) => { - if(id === 0 || id === this.state.points.length-1){ + if(id === 0 || id === this.state.points.length - 1){ return; } @@ -156,20 +156,20 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo const pt = this.myRef.createSVGPoint(); let updatedCopyPoint; - const padding = this.padding/2; + const padding = this.padding / 2; pt.x = event.clientX; pt.y = event.clientY; const svgP = pt.matrixTransform(this.myRef.getScreenCTM().inverse()); updatedCopyPoint = Vec2.create(svgP.x, svgP.y); - if ((svgP.x < (padding) || svgP.x > (this.width+(padding))) && (svgP.y > (this.height+(padding)) || svgP.y < (padding))) { + if ((svgP.x < (padding) || svgP.x > (this.width + (padding))) && (svgP.y > (this.height + (padding)) || svgP.y < (padding))) { updatedCopyPoint = Vec2.create(this.updatedX, this.updatedY); } else if (svgP.x < padding) { updatedCopyPoint = Vec2.create(padding, svgP.y); - } else if( svgP.x > (this.width+(padding))) { - updatedCopyPoint = Vec2.create(this.width+padding, svgP.y); - } else if (svgP.y > (this.height+(padding))) { - updatedCopyPoint = Vec2.create(svgP.x, this.height+padding); + } else if( svgP.x > (this.width + (padding))) { + updatedCopyPoint = Vec2.create(this.width + padding, svgP.y); + } else if (svgP.y > (this.height + (padding))) { + updatedCopyPoint = Vec2.create(svgP.x, this.height + padding); } else if (svgP.y < (padding)) { updatedCopyPoint = Vec2.create(svgP.x, padding); } else { @@ -197,7 +197,7 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo return; } - if(selected === undefined || selected[0] === 0 || selected[0] === this.state.points.length-1) { + if(selected === undefined || selected[0] === 0 || selected[0] === this.state.points.length - 1) { this.setState({ copyPoint: undefined, }); @@ -206,17 +206,17 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo this.selected = undefined; const updatedPoint = this.unNormalizePoint(Vec2.create(this.updatedX, this.updatedY)); - const points = this.state.points.filter((_,i) => i !== selected[0]); + const points = this.state.points.filter((_, i) => i !== selected[0]); points.push(updatedPoint);; points.sort((a, b) => { if(a[0] === b[0]){ if(a[0] === 0){ - return a[1]-b[1]; + return a[1] - b[1]; } if(a[1] === 1){ - return b[1]-a[1]; + return b[1] - a[1]; } - return a[1]-b[1]; + return a[1] - b[1]; } return a[0] - b[0]; }); @@ -237,12 +237,12 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo pt.y = event.clientY; const svgP = pt.matrixTransform(this.myRef.getScreenCTM().inverse()); const points = this.state.points; - const padding = this.padding/2; + const padding = this.padding / 2; if( svgP.x < (padding) || - svgP.x > (this.width+(padding)) || - svgP.y > (this.height+(padding)) || - svgP.y < (this.padding/2)) { + svgP.x > (this.width + (padding)) || + svgP.y > (this.height + (padding)) || + svgP.y < (this.padding / 2)) { return; } newPoint = this.unNormalizePoint(Vec2.create(svgP.x, svgP.y)); @@ -250,12 +250,12 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo points.sort((a, b) => { if(a[0] === b[0]){ if(a[0] === 0){ - return a[1]-b[1]; + return a[1] - b[1]; } if(a[1] === 1){ - return b[1]-a[1]; + return b[1] - a[1]; } - return a[1]-b[1]; + return a[1] - b[1]; } return a[0] - b[0]; }); @@ -264,17 +264,17 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo } private deletePoint = (i: number) => (event: any) => { - if(i===0 || i===this.state.points.length-1){ return; } - const points = this.state.points.filter((_,j) => j !== i); + if(i === 0 || i === this.state.points.length - 1){ return; } + const points = this.state.points.filter((_, j) => j !== i); points.sort((a, b) => { if(a[0] === b[0]){ if(a[0] === 0){ - return a[1]-b[1]; + return a[1] - b[1]; } if(a[1] === 1){ - return b[1]-a[1]; + return b[1] - a[1]; } - return a[1]-b[1]; + return a[1] - b[1]; } return a[0] - b[0]; }); @@ -298,24 +298,24 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo } private normalizePoint(point: Vec2) { - const min = this.padding/2; - const maxX = this.width+min; - const maxY = this.height+min; - const normalizedX = (point[0]*(maxX-min))+min; - const normalizedY = (point[1]*(maxY-min))+min; - const reverseY = (this.height+this.padding)-normalizedY; + const min = this.padding / 2; + const maxX = this.width + min; + const maxY = this.height + min; + const normalizedX = (point[0] * (maxX - min)) + min; + const normalizedY = (point[1] * (maxY - min)) + min; + const reverseY = (this.height + this.padding) - normalizedY; const newPoint = Vec2.create(normalizedX, reverseY); return newPoint; } private unNormalizePoint(point: Vec2) { - const min = this.padding/2; - const maxX = this.width+min; - const maxY = this.height+min; - const unNormalizedX = (point[0]-min)/(maxX-min); + const min = this.padding / 2; + const maxX = this.width + min; + const maxY = this.height + min; + const unNormalizedX = (point[0] - min) / (maxX - min); // we have to take into account that we reversed y when we first normalized it. - const unNormalizedY = ((this.height+this.padding)-point[1]-min)/(maxY-min); + const unNormalizedY = ((this.height + this.padding) - point[1] - min) / (maxY - min); return Vec2.create(unNormalizedX, unNormalizedY); } @@ -330,7 +330,7 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo const points: any[] = []; let point: Vec2; for (let i = 0; i < this.state.points.length; i++){ - if(i !== 0 && i !== this.state.points.length-1){ + if(i !== 0 && i !== this.state.points.length - 1){ point = this.normalizePoint(this.state.points[i]); points.push(<PointComponent key={i} @@ -361,23 +361,23 @@ export default class LineGraphComponent extends React.Component<any, LineGraphCo let reverseY: number; for(const point of this.state.points){ - min = this.padding/2; - maxX = this.width+min; - maxY = this.height+min; - normalizedX = (point[0]*(maxX-min))+min; - normalizedY = (point[1]*(maxY-min))+min; - reverseY = this.height+this.padding-normalizedY; + min = this.padding / 2; + maxX = this.width + min; + maxY = this.height + min; + normalizedX = (point[0] * (maxX - min)) + min; + normalizedY = (point[1] * (maxY - min)) + min; + reverseY = this.height + this.padding - normalizedY; points.push(Vec2.create(normalizedX, reverseY)); } const data = points; const size = data.length; - for (let i=0; i<size-1;i++){ + for (let i = 0; i < size - 1;i++){ const x1 = data[i][0]; const y1 = data[i][1]; - const x2 = data[i+1][0]; - const y2 = data[i+1][1]; + const x2 = data[i + 1][0]; + const y2 = data[i + 1][1]; lines.push(<line key={`lineOf${i}`} x1={x1} x2={x2} y1={y1} y2={y2} stroke="#cec9ba" strokeWidth="5"/>) } diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts index 9a9051d9339dcb0e7358652de583a7626d748f97..f0f345cbed8aebc7508bd649bf8d51993a253aad 100644 --- a/src/mol-repr/structure/representation/ball-and-stick.ts +++ b/src/mol-repr/structure/representation/ball-and-stick.ts @@ -28,7 +28,7 @@ export const BallAndStickParams = { ...InterUnitBondParams, unitKinds: getUnitKindsParam(['atomic']), sizeFactor: PD.Numeric(0.15, { min: 0.01, max: 10, step: 0.01 }), - sizeAspectRatio: PD.Numeric(2/3, { min: 0.01, max: 3, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2 / 3, { min: 0.01, max: 3, step: 0.01 }), visuals: PD.MultiSelect(['element-sphere', 'intra-bond', 'inter-bond'], PD.objectToOptions(BallAndStickVisuals)) } export type BallAndStickParams = typeof BallAndStickParams diff --git a/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts b/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts index 6ab12e6477d19023cef0e4d2351736dbbc8dae51..32897cb6c1fa82d19ece83099f6cc24a0702bd00 100644 --- a/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts +++ b/src/mol-repr/structure/visual/bond-inter-unit-cylinder.ts @@ -109,7 +109,7 @@ export const InterUnitBondParams = { ...ComplexMeshParams, ...BondCylinderParams, sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), - sizeAspectRatio: PD.Numeric(2/3, { min: 0, max: 3, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2 / 3, { min: 0, max: 3, step: 0.01 }), ignoreHydrogens: PD.Boolean(false), } export type InterUnitBondParams = typeof InterUnitBondParams diff --git a/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts b/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts index f0ce51658c46ba8ac2a52f1df7bad4d359f7c0ee..5cb4f5a7ddada573b109eeb71faf74d485600e66 100644 --- a/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts +++ b/src/mol-repr/structure/visual/bond-intra-unit-cylinder.ts @@ -105,7 +105,7 @@ export const IntraUnitBondParams = { ...UnitsMeshParams, ...BondCylinderParams, sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), - sizeAspectRatio: PD.Numeric(2/3, { min: 0, max: 3, step: 0.01 }), + sizeAspectRatio: PD.Numeric(2 / 3, { min: 0, max: 3, step: 0.01 }), ignoreHydrogens: PD.Boolean(false), } export type IntraUnitBondParams = typeof IntraUnitBondParams diff --git a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts index 39ab381b91a15002eb6187e22dafa319d0fc98b2..8236030f2eec840c745e82e8d82147dd1e7f134a 100644 --- a/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts +++ b/src/mol-repr/structure/visual/carbohydrate-symbol-mesh.ts @@ -151,7 +151,7 @@ function createCarbohydrateSymbolMesh(ctx: VisualContext, structure: Structure, case SaccharideShape.FlatHexagon: default: Mat4.mul(t, t, Mat4.rotZYZ90) - Mat4.scale(t, t, Vec3.set(sVec, side / 1.5, side , side / 2)) + Mat4.scale(t, t, Vec3.set(sVec, side / 1.5, side, side / 2)) MeshBuilder.addPrimitive(builderState, t, shiftedHexagonalPrism) break } diff --git a/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts b/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts index 2631d7588926625f383c0ade64cd016cbbc1f7af..c8f8cb4bf27da90eb8154f579c3654fa4eeeb4bc 100644 --- a/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts +++ b/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts @@ -154,7 +154,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> private setControlPoint(out: Vec3, p1: Vec3, p2: Vec3, p3: Vec3, residueIndex: ResidueIndex) { const ss = this.getSecStruc(residueIndex) if (SecondaryStructureType.is(ss, SecondaryStructureType.Flag.Beta)) { - Vec3.scale(out, Vec3.add(out, p1, Vec3.add(out, p3, Vec3.add(out, p2, p2))), 1/4) + Vec3.scale(out, Vec3.add(out, p1, Vec3.add(out, p3, Vec3.add(out, p2, p2))), 1 / 4) } else { Vec3.copy(out, p2) } @@ -173,7 +173,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> private setDirection(out: Vec3, v1: Vec3, v2: Vec3, v3: Vec3) { Vec3.matchDirection(tmpVecA, v1, v2) Vec3.matchDirection(tmpVecB, v3, v2) - Vec3.scale(out, Vec3.add(out, tmpVecA, Vec3.add(out, tmpVecB, Vec3.add(out, v2, v2))), 1/4) + Vec3.scale(out, Vec3.add(out, tmpVecA, Vec3.add(out, tmpVecB, Vec3.add(out, v2, v2))), 1 / 4) } move() { diff --git a/src/mol-theme/color/entity-source.ts b/src/mol-theme/color/entity-source.ts index 955f0606a1dc5fde7f8dadba07797e1a443550d8..f8b4d65e5166cd71ac412a5eedc172b317eac80b 100644 --- a/src/mol-theme/color/entity-source.ts +++ b/src/mol-theme/color/entity-source.ts @@ -99,7 +99,7 @@ function getMaps(models: ReadonlyArray<Model>) { const seqToSrcByModelEntity = new Map<string, Int16Array>() const srcKeySerialMap = new Map<string, number>() // serial no starting from 1 - for (let i = 0, il = models.length; i <il; ++i) { + for (let i = 0, il = models.length; i < il; ++i) { const m = models[i] if (!MmcifFormat.is(m.sourceData)) continue const { entity_src_gen, entity_src_nat, pdbx_entity_src_syn } = m.sourceData.data.db diff --git a/src/mol-theme/color/model-index.ts b/src/mol-theme/color/model-index.ts index 2f7f8f213d055a08a768d47deddb286503f60fc0..34e49314be03dcd56e2cbf67b90aca7cb8366b56 100644 --- a/src/mol-theme/color/model-index.ts +++ b/src/mol-theme/color/model-index.ts @@ -37,7 +37,7 @@ export function ModelIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<Mod const palette = getPalette(size, props) legend = palette.legend const modelColor = new Map<number, Color>() - for (let i = 0, il = models.length; i <il; ++i) { + for (let i = 0, il = models.length; i < il; ++i) { const idx = models[i].trajectoryInfo.index; modelColor.set(models[i].trajectoryInfo.index, palette.color(idx)) } diff --git a/src/mol-theme/color/polymer-index.ts b/src/mol-theme/color/polymer-index.ts index a6eab08a892b90d7eebaba9fa82b5fb3f50f52a4..944adc4a9bef42bd508cf4ea1f1d92e8c6bfd4dc 100644 --- a/src/mol-theme/color/polymer-index.ts +++ b/src/mol-theme/color/polymer-index.ts @@ -40,7 +40,7 @@ export type PolymerIndexColorThemeProps = PD.Values<typeof PolymerIndexColorThem function getPolymerChainCount(structure: Structure) { let polymerChainCount = 0 const { units } = structure - for (let i = 0, il = units.length; i <il; ++i) { + for (let i = 0, il = units.length; i < il; ++i) { if (units[i].polymerElements.length > 0) ++polymerChainCount } return polymerChainCount @@ -56,7 +56,7 @@ export function PolymerIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<P const { units } = ctx.structure.root const unitIdColor = new Map<number, Color>() - for (let i = 0, j = 0, il = units.length; i <il; ++i) { + for (let i = 0, j = 0, il = units.length; i < il; ++i) { if (units[i].polymerElements.length > 0) { unitIdColor.set(units[i].id, palette.color(j)) ++j diff --git a/src/mol-theme/color/unit-index.ts b/src/mol-theme/color/unit-index.ts index db9b25a15f1aa107cd08e15921d4f1c17cb54c93..0cf9463e5619bacda457352bca8d672ebd137265 100644 --- a/src/mol-theme/color/unit-index.ts +++ b/src/mol-theme/color/unit-index.ts @@ -45,7 +45,7 @@ export function UnitIndexColorTheme(ctx: ThemeDataContext, props: PD.Values<Unit const palette = getPalette(units.length, props) legend = palette.legend const unitIdColor = new Map<number, Color>() - for (let i = 0, il = units.length; i <il; ++i) { + for (let i = 0, il = units.length; i < il; ++i) { unitIdColor.set(units[i].id, palette.color(i)) } diff --git a/src/mol-util/zip/bin.ts b/src/mol-util/zip/bin.ts index 6edbdc1c67d9831ce0a8d2db2b491c4fa1654fb6..c105a80db0c7dcce96a540a86a25742f7044fa77 100644 --- a/src/mol-util/zip/bin.ts +++ b/src/mol-util/zip/bin.ts @@ -15,27 +15,27 @@ export function toInt32(x: number) { } export function readUshort(buff: Uint8Array, p: number) { - return (buff[p]) | (buff[p+1]<<8); + return (buff[p]) | (buff[p + 1] << 8); } export function writeUshort(buff: Uint8Array, p: number, n: number) { - buff[p] = (n)&255; buff[p+1] = (n>>8)&255; + buff[p] = (n) & 255; buff[p + 1] = (n >> 8) & 255; } export function readUint(buff: Uint8Array, p: number) { - return (buff[p+3]*(256*256*256)) + ((buff[p+2]<<16) | (buff[p+1]<< 8) | buff[p]); + return (buff[p + 3] * (256 * 256 * 256)) + ((buff[p + 2] << 16) | (buff[p + 1] << 8) | buff[p]); } export function writeUint(buff: Uint8Array, p: number, n: number) { - buff[p] = n&255; - buff[p+1] = (n>>8)&255; - buff[p+2] = (n>>16)&255; - buff[p+3] = (n>>24)&255; + buff[p] = n & 255; + buff[p + 1] = (n >> 8) & 255; + buff[p + 2] = (n >> 16) & 255; + buff[p + 3] = (n >> 24) & 255; } function readASCII(buff: Uint8Array, p: number, l: number){ let s = ''; - for(let i=0; i<l; i++) s += String.fromCharCode(buff[p+i]); + for(let i = 0; i < l; i++) s += String.fromCharCode(buff[p + i]); return s; } @@ -49,7 +49,7 @@ function pad(n: string) { export function readUTF8(buff: Uint8Array, p: number, l: number) { let s = '', ns; - for(let i = 0; i<l; i++) s += '%' + pad(buff[p+i].toString(16)); + for(let i = 0; i < l; i++) s += '%' + pad(buff[p + i].toString(16)); try { ns = decodeURIComponent(s); } catch(e) { @@ -61,26 +61,26 @@ export function readUTF8(buff: Uint8Array, p: number, l: number) { export function writeUTF8(buff: Uint8Array, p: number, str: string) { const strl = str.length let i = 0; - for(let ci = 0; ci<strl; ci++) { + for(let ci = 0; ci < strl; ci++) { const code = str.charCodeAt(ci); - if((code&(0xffffffff-(1<< 7)+1)) === 0) { - buff[p+i] = ( code ); + if((code & (0xffffffff - (1 << 7) + 1)) === 0) { + buff[p + i] = ( code ); i++; - } else if((code&(0xffffffff-(1<<11)+1)) === 0) { - buff[p+i] = (192|(code>> 6)); - buff[p+i+1] = (128|((code>> 0)&63)); - i+=2; - } else if((code&(0xffffffff-(1<<16)+1)) === 0) { - buff[p+i] = (224|(code>>12)); - buff[p+i+1] = (128|((code>> 6)&63)); - buff[p+i+2] = (128|((code>>0)&63)); - i+=3; - } else if((code&(0xffffffff-(1<<21)+1)) === 0) { - buff[p+i] = (240|(code>>18)); - buff[p+i+1] = (128|((code>>12)&63)); - buff[p+i+2] = (128|((code>>6)&63)); - buff[p+i+3] = (128|((code>>0)&63)); - i+=4; + } else if((code & (0xffffffff - (1 << 11) + 1)) === 0) { + buff[p + i] = (192 | (code >> 6)); + buff[p + i + 1] = (128 | ((code >> 0) & 63)); + i += 2; + } else if((code & (0xffffffff - (1 << 16) + 1)) === 0) { + buff[p + i] = (224 | (code >> 12)); + buff[p + i + 1] = (128 | ((code >> 6) & 63)); + buff[p + i + 2] = (128 | ((code >> 0) & 63)); + i += 3; + } else if((code & (0xffffffff - (1 << 21) + 1)) === 0) { + buff[p + i] = (240 | (code >> 18)); + buff[p + i + 1] = (128 | ((code >> 12) & 63)); + buff[p + i + 2] = (128 | ((code >> 6) & 63)); + buff[p + i + 3] = (128 | ((code >> 0) & 63)); + i += 4; } else throw 'e'; } return i; @@ -91,14 +91,14 @@ export function sizeUTF8(str: string) { let i = 0; for(let ci = 0; ci < strl; ci++) { const code = str.charCodeAt(ci); - if ((code&(0xffffffff-(1<< 7)+1)) === 0) { + if ((code & (0xffffffff - (1 << 7) + 1)) === 0) { i++ ; - } else if((code&(0xffffffff-(1<<11)+1)) === 0) { - i+=2; - } else if((code&(0xffffffff-(1<<16)+1)) === 0) { - i+=3; - } else if((code&(0xffffffff-(1<<21)+1)) === 0) { - i+=4; + } else if((code & (0xffffffff - (1 << 11) + 1)) === 0) { + i += 2; + } else if((code & (0xffffffff - (1 << 16) + 1)) === 0) { + i += 3; + } else if((code & (0xffffffff - (1 << 21) + 1)) === 0) { + i += 4; } else { throw 'e'; } diff --git a/src/mol-util/zip/checksum.ts b/src/mol-util/zip/checksum.ts index aa9a9dcaacb59587710a7d5f5ef7e04741722e1e..380f4a0abd11c6dbea7e3ed319389034cd6536ff 100644 --- a/src/mol-util/zip/checksum.ts +++ b/src/mol-util/zip/checksum.ts @@ -9,9 +9,9 @@ const CrcTable = (function() { const tab = new Uint32Array(256); - for (let n=0; n<256; n++) { + for (let n = 0; n < 256; n++) { let c = n; - for (let k=0; k<8; k++) { + for (let k = 0; k < 8; k++) { if (c & 1) c = 0xedb88320 ^ (c >>> 1); else c = c >>> 1; } @@ -21,8 +21,8 @@ const CrcTable = (function() { })() function _crc(c: number, buf: Uint8Array, off: number, len: number) { - for (let i = 0; i<len; i++) { - c = CrcTable[(c ^ buf[off+i]) & 0xff] ^ (c >>> 8); + for (let i = 0; i < len; i++) { + c = CrcTable[(c ^ buf[off + i]) & 0xff] ^ (c >>> 8); } return c; } @@ -34,7 +34,7 @@ export function crc(b: Uint8Array, o: number, l: number) { export function adler(data: Uint8Array, o: number, len: number) { let a = 1, b = 0; let off = o - const end = o+len; + const end = o + len; while(off < end) { const eend = Math.min(off + 5552, end); while(off < eend) { diff --git a/src/mol-util/zip/deflate.ts b/src/mol-util/zip/deflate.ts index 25cec469ff31594089636c6020d0137e73425538..deaeaa3b1c557ebafb2e21b21a47e8661f6d85ee 100644 --- a/src/mol-util/zip/deflate.ts +++ b/src/mol-util/zip/deflate.ts @@ -34,35 +34,35 @@ export function _deflateRaw(data: Uint8Array, out: Uint8Array, opos: number, lvl const opt = opts[lvl]; - let i = 0, pos = opos<<3, cvrd = 0 + let i = 0, pos = opos << 3, cvrd = 0 const dlen = data.length; if(lvl === 0) { while(i < dlen) { - const len = Math.min(0xffff, dlen-i); + const len = Math.min(0xffff, dlen - i); _putsE(out, pos, (i + len === dlen ? 1 : 0)); pos = _copyExact(data, i, len, out, pos + 8); i += len; } - return pos>>>3; + return pos >>> 3; } const { lits, strt, prev } = U let li = 0, lc = 0, bs = 0, ebits = 0, c = 0, nc = 0; // last_item, literal_count, block_start if(dlen > 2) { - nc=_hash(data,0); - strt[nc]=0; + nc = _hash(data, 0); + strt[nc] = 0; } // let nmch = 0 // let nmci = 0 - for(i = 0; i<dlen; i++) { + for(i = 0; i < dlen; i++) { c = nc; //* if(i + 1 < dlen - 2) { - nc = _hash(data, i+1); - const ii = ((i+1)&0x7fff); + nc = _hash(data, i + 1); + const ii = ((i + 1) & 0x7fff); prev[ii] = strt[nc]; strt[nc] = ii; } // */ @@ -80,8 +80,8 @@ export function _deflateRaw(data: Uint8Array, out: Uint8Array, opos: number, lvl let mch = 0; // if(nmci==i) mch= nmch; else - if(i < dlen-2) { - mch = _bestMatch(data, i, prev, c, Math.min(opt[2],dlen-i), opt[3]); + if(i < dlen - 2) { + mch = _bestMatch(data, i, prev, c, Math.min(opt[2], dlen - i), opt[3]); } /* if(mch!=0 && opt[4]==1 && (mch>>>16)<opt[1] && i+1<dlen-2) { @@ -91,10 +91,10 @@ export function _deflateRaw(data: Uint8Array, out: Uint8Array, opos: number, lvl }//*/ // const len = mch>>>16, dst = mch & 0xffff; // if(i-dst<0) throw "e"; if(mch !== 0) { - const len = mch>>>16, dst = mch&0xffff; // if(i-dst<0) throw "e"; - const lgi = _goodIndex(len, U.of0); U.lhst[257+lgi]++; + const len = mch >>> 16, dst = mch & 0xffff; // if(i-dst<0) throw "e"; + const lgi = _goodIndex(len, U.of0); U.lhst[257 + lgi]++; const dgi = _goodIndex(dst, U.df0); U.dhst[ dgi]++; ebits += U.exb[lgi] + U.dxb[dgi]; - lits[li] = (len<<23)|(i-cvrd); lits[li+1] = (dst<<16)|(lgi<<8)|dgi; li+=2; + lits[li] = (len << 23) | (i - cvrd); lits[li + 1] = (dst << 16) | (lgi << 8) | dgi; li += 2; cvrd = i + len; } else { U.lhst[data[i]]++; @@ -104,60 +104,60 @@ export function _deflateRaw(data: Uint8Array, out: Uint8Array, opos: number, lvl } if(bs !== i || data.length === 0) { if(cvrd < i) { - lits[li]=i-cvrd; - li+=2; - cvrd=i; + lits[li] = i - cvrd; + li += 2; + cvrd = i; } - pos = _writeBlock(1, lits, li, ebits, data, bs, i-bs, out, pos); - li=0; - lc=0; - li = lc = ebits=0; - bs=i; + pos = _writeBlock(1, lits, li, ebits, data, bs, i - bs, out, pos); + li = 0; + lc = 0; + li = lc = ebits = 0; + bs = i; } - while((pos&7) !== 0) pos++; - return pos>>>3; + while((pos & 7) !== 0) pos++; + return pos >>> 3; } function _bestMatch(data: Uint8Array, i: number, prev: Uint16Array, c: number, nice: number, chain: number) { - let ci = (i&0x7fff), pi=prev[ci]; + let ci = (i & 0x7fff), pi = prev[ci]; // console.log("----", i); - let dif = ((ci-pi + (1<<15)) & 0x7fff); - if(pi === ci || c !== _hash(data,i-dif)) return 0; - let tl=0, td=0; // top length, top distance + let dif = ((ci - pi + (1 << 15)) & 0x7fff); + if(pi === ci || c !== _hash(data, i - dif)) return 0; + let tl = 0, td = 0; // top length, top distance const dlim = Math.min(0x7fff, i); - while(dif<=dlim && --chain !== 0 && pi !== ci /* && c==UZIP.F._hash(data,i-dif)*/) { - if(tl === 0 || (data[i+tl] === data[i+tl-dif])) { + while(dif <= dlim && --chain !== 0 && pi !== ci /* && c==UZIP.F._hash(data,i-dif)*/) { + if(tl === 0 || (data[i + tl] === data[i + tl - dif])) { let cl = _howLong(data, i, dif); - if(cl>tl) { - tl=cl; td=dif; if(tl>=nice) break; //* - if(dif+2<cl) cl = dif+2; + if(cl > tl) { + tl = cl; td = dif; if(tl >= nice) break; //* + if(dif + 2 < cl) cl = dif + 2; let maxd = 0; // pi does not point to the start of the word - for(let j=0; j<cl-2; j++) { - const ei = (i-dif+j+ (1<<15)) & 0x7fff; + for(let j = 0; j < cl - 2; j++) { + const ei = (i - dif + j + (1 << 15)) & 0x7fff; const li = prev[ei]; - const curd = (ei-li + (1<<15)) & 0x7fff; - if(curd>maxd) { maxd=curd; pi = ei; } + const curd = (ei - li + (1 << 15)) & 0x7fff; + if(curd > maxd) { maxd = curd; pi = ei; } } } } - ci=pi; pi = prev[ci]; - dif += ((ci-pi + (1<<15)) & 0x7fff); + ci = pi; pi = prev[ci]; + dif += ((ci - pi + (1 << 15)) & 0x7fff); } - return (tl<<16)|td; + return (tl << 16) | td; } function _howLong(data: Uint8Array, i: number, dif: number) { - if(data[i] !== data[i-dif] || data[i+1] !== data[i+1-dif] || data[i+2] !== data[i+2-dif]) return 0; - const oi=i, l = Math.min(data.length, i+258); - i+=3; + if(data[i] !== data[i - dif] || data[i + 1] !== data[i + 1 - dif] || data[i + 2] !== data[i + 2 - dif]) return 0; + const oi = i, l = Math.min(data.length, i + 258); + i += 3; // while(i+4<l && data[i]==data[i-dif] && data[i+1]==data[i+1-dif] && data[i+2]==data[i+2-dif] && data[i+3]==data[i+3-dif]) i+=4; - while(i<l && data[i] === data[i-dif]) i++; - return i-oi; + while(i < l && data[i] === data[i - dif]) i++; + return i - oi; } function _hash(data: Uint8Array, i: number) { - return (((data[i]<<8) | data[i+1])+(data[i+2]<<4))&0xffff; + return (((data[i] << 8) | data[i + 1]) + (data[i + 2] << 4)) & 0xffff; // var hash_shift = 0, hash_mask = 255; // var h = data[i+1] % 251; // h = (((h << 8) + data[i+2]) % 251); @@ -171,28 +171,28 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe U.lhst[256]++; const [ ML, MD, MH, numl, numd, numh, lset, dset ] = getTrees() - const cstSize = (((pos+3)&7) === 0 ? 0 : 8-((pos+3)&7)) + 32 + (l0<<3); + const cstSize = (((pos + 3) & 7) === 0 ? 0 : 8 - ((pos + 3) & 7)) + 32 + (l0 << 3); const fxdSize = ebits + contSize(U.fltree, U.lhst) + contSize(U.fdtree, U.dhst); - let dynSize = ebits + contSize(U.ltree , U.lhst) + contSize(U.dtree , U.dhst); - dynSize += 14 + 3 * numh + contSize(U.itree, U.ihst) + (U.ihst[16]*2 + U.ihst[17]*3 + U.ihst[18]*7); + let dynSize = ebits + contSize(U.ltree, U.lhst) + contSize(U.dtree, U.dhst); + dynSize += 14 + 3 * numh + contSize(U.itree, U.ihst) + (U.ihst[16] * 2 + U.ihst[17] * 3 + U.ihst[18] * 7); - for(let j=0; j<286; j++) U.lhst[j]=0; - for(let j=0; j<30; j++) U.dhst[j]=0; - for(let j=0; j<19; j++) U.ihst[j]=0; + for(let j = 0; j < 286; j++) U.lhst[j] = 0; + for(let j = 0; j < 30; j++) U.dhst[j] = 0; + for(let j = 0; j < 19; j++) U.ihst[j] = 0; - const BTYPE = (cstSize<fxdSize && cstSize<dynSize) ? 0 : ( fxdSize<dynSize ? 1 : 2 ); + const BTYPE = (cstSize < fxdSize && cstSize < dynSize) ? 0 : ( fxdSize < dynSize ? 1 : 2 ); _putsF(out, pos, BFINAL); - _putsF(out, pos+1, BTYPE); - pos+=3; + _putsF(out, pos + 1, BTYPE); + pos += 3; // let opos = pos; if(BTYPE === 0) { - while((pos&7) !== 0) pos++; + while((pos & 7) !== 0) pos++; pos = _copyExact(data, o0, l0, out, pos); } else { let ltree: number[], dtree: number[]; if(BTYPE === 1) { - ltree=U.fltree; dtree=U.fdtree; + ltree = U.fltree; dtree = U.fdtree; } else if(BTYPE === 2) { makeCodes(U.ltree, ML); revCodes(U.ltree, ML); makeCodes(U.dtree, MD); revCodes(U.dtree, MD); @@ -200,30 +200,30 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe ltree = U.ltree; dtree = U.dtree; - _putsE(out, pos,numl-257); pos+=5; // 286 - _putsE(out, pos,numd- 1); pos+=5; // 30 - _putsE(out, pos,numh- 4); pos+=4; // 19 + _putsE(out, pos, numl - 257); pos += 5; // 286 + _putsE(out, pos, numd - 1); pos += 5; // 30 + _putsE(out, pos, numh - 4); pos += 4; // 19 - for(let i=0; i<numh; i++) _putsE(out, pos+i*3, U.itree[(U.ordr[i]<<1)+1]); - pos+=3* numh; + for(let i = 0; i < numh; i++) _putsE(out, pos + i * 3, U.itree[(U.ordr[i] << 1) + 1]); + pos += 3 * numh; pos = _codeTiny(lset, U.itree, out, pos); pos = _codeTiny(dset, U.itree, out, pos); } else { throw new Error(`unknown BTYPE ${BTYPE}`) } - let off=o0; - for(let si=0; si<li; si+=2) { - const qb=lits[si], len=(qb>>>23), end = off+(qb&((1<<23)-1)); - while(off<end) pos = _writeLit(data[off++], ltree, out, pos); + let off = o0; + for(let si = 0; si < li; si += 2) { + const qb = lits[si], len = (qb >>> 23), end = off + (qb & ((1 << 23) - 1)); + while(off < end) pos = _writeLit(data[off++], ltree, out, pos); if(len !== 0) { - const qc = lits[si+1], dst=(qc>>16), lgi=(qc>>8)&255, dgi=(qc&255); - pos = _writeLit(257+lgi, ltree, out, pos); - _putsE(out, pos, len-U.of0[lgi]); pos+=U.exb[lgi]; + const qc = lits[si + 1], dst = (qc >> 16), lgi = (qc >> 8) & 255, dgi = (qc & 255); + pos = _writeLit(257 + lgi, ltree, out, pos); + _putsE(out, pos, len - U.of0[lgi]); pos += U.exb[lgi]; pos = _writeLit(dgi, dtree, out, pos); - _putsF(out, pos, dst-U.df0[dgi]); pos+=U.dxb[dgi]; off+=len; + _putsF(out, pos, dst - U.df0[dgi]); pos += U.dxb[dgi]; off += len; } } pos = _writeLit(256, ltree, out, pos); @@ -233,15 +233,15 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe } function _copyExact(data: Uint8Array, off: number, len: number, out: Uint8Array, pos: number) { - let p8 = (pos>>>3); - out[p8]=(len); - out[p8+1]=(len>>>8); - out[p8+2]=255-out[p8]; - out[p8+3]=255-out[p8+1]; - p8+=4; + let p8 = (pos >>> 3); + out[p8] = (len); + out[p8 + 1] = (len >>> 8); + out[p8 + 2] = 255 - out[p8]; + out[p8 + 3] = 255 - out[p8 + 1]; + p8 += 4; out.set(new Uint8Array(data.buffer, off, len), p8); // for(var i=0; i<len; i++) out[p8+i]=data[off+i]; - return pos + ((len+4)<<3); + return pos + ((len + 4) << 3); } @@ -257,28 +257,28 @@ function getTrees() { const numl = _lenCodes(U.ltree, lset); const dset: number[] = [] const numd = _lenCodes(U.dtree, dset); - for(let i=0; i<lset.length; i+=2) U.ihst[lset[i]]++; - for(let i=0; i<dset.length; i+=2) U.ihst[dset[i]]++; + for(let i = 0; i < lset.length; i += 2) U.ihst[lset[i]]++; + for(let i = 0; i < dset.length; i += 2) U.ihst[dset[i]]++; const MH = _hufTree(U.ihst, U.itree, 7); let numh = 19; - while(numh>4 && U.itree[(U.ordr[numh-1]<<1)+1] === 0) numh--; + while(numh > 4 && U.itree[(U.ordr[numh - 1] << 1) + 1] === 0) numh--; return [ML, MD, MH, numl, numd, numh, lset, dset] as const; } function contSize(tree: number[], hst: NumberArray) { - let s=0; - for(let i=0; i<hst.length; i++) s+= hst[i]*tree[(i<<1)+1]; + let s = 0; + for(let i = 0; i < hst.length; i++) s += hst[i] * tree[(i << 1) + 1]; return s; } function _codeTiny(set: number[], tree: number[], out: Uint8Array, pos: number) { - for(let i=0; i<set.length; i+=2) { - const l = set[i], rst = set[i+1]; // console.log(l, pos, tree[(l<<1)+1]); + for(let i = 0; i < set.length; i += 2) { + const l = set[i], rst = set[i + 1]; // console.log(l, pos, tree[(l<<1)+1]); pos = _writeLit(l, tree, out, pos); const rsl = l === 16 ? 2 : (l === 17 ? 3 : 7); - if(l>15) { + if(l > 15) { _putsE(out, pos, rst); - pos+=rsl; + pos += rsl; } } return pos; @@ -287,55 +287,55 @@ function _codeTiny(set: number[], tree: number[], out: Uint8Array, pos: number) function _lenCodes(tree: number[], set: number[]) { let len = tree.length; - while(len !== 2 && tree[len-1] === 0) len-=2; // when no distances, keep one code with length 0 - for(let i=0; i<len; i+=2) { - const l = tree[i+1], nxt = (i+3<len ? tree[i+3]:-1), nnxt = (i+5<len ? tree[i+5]:-1), prv = (i === 0 ? -1 : tree[i-1]); + while(len !== 2 && tree[len - 1] === 0) len -= 2; // when no distances, keep one code with length 0 + for(let i = 0; i < len; i += 2) { + const l = tree[i + 1], nxt = (i + 3 < len ? tree[i + 3] : -1), nnxt = (i + 5 < len ? tree[i + 5] : -1), prv = (i === 0 ? -1 : tree[i - 1]); if(l === 0 && nxt === l && nnxt === l) { - let lz = i+5; - while(lz+2<len && tree[lz+2] === l) lz+=2; - const zc = Math.min((lz+1-i)>>>1, 138); - if(zc<11) set.push(17, zc-3); - else set.push(18, zc-11); - i += zc*2-2; + let lz = i + 5; + while(lz + 2 < len && tree[lz + 2] === l) lz += 2; + const zc = Math.min((lz + 1 - i) >>> 1, 138); + if(zc < 11) set.push(17, zc - 3); + else set.push(18, zc - 11); + i += zc * 2 - 2; } else if(l === prv && nxt === l && nnxt === l) { - let lz = i+5; - while(lz+2<len && tree[lz+2] === l) lz+=2; - const zc = Math.min((lz+1-i)>>>1, 6); - set.push(16, zc-3); - i += zc*2-2; + let lz = i + 5; + while(lz + 2 < len && tree[lz + 2] === l) lz += 2; + const zc = Math.min((lz + 1 - i) >>> 1, 6); + set.push(16, zc - 3); + i += zc * 2 - 2; } else { set.push(l, 0); } } - return len>>>1; + return len >>> 1; } function _goodIndex(v: number, arr: number[]) { - let i=0; - if(arr[i|16]<=v) i|=16; - if(arr[i|8]<=v) i|=8; - if(arr[i|4]<=v) i|=4; - if(arr[i|2]<=v) i|=2; - if(arr[i|1]<=v) i|=1; + let i = 0; + if(arr[i | 16] <= v) i |= 16; + if(arr[i | 8] <= v) i |= 8; + if(arr[i | 4] <= v) i |= 4; + if(arr[i | 2] <= v) i |= 2; + if(arr[i | 1] <= v) i |= 1; return i; } function _writeLit(ch: number, ltree: number[], out: Uint8Array, pos: number) { - _putsF(out, pos, ltree[ch<<1]); - return pos+ltree[(ch<<1)+1]; + _putsF(out, pos, ltree[ch << 1]); + return pos + ltree[(ch << 1) + 1]; } function _putsE(dt: NumberArray, pos: number, val: number) { - val = val<<(pos&7); - const o=(pos>>>3); - dt[o]|=val; - dt[o+1]|=(val>>>8); + val = val << (pos & 7); + const o = (pos >>> 3); + dt[o] |= val; + dt[o + 1] |= (val >>> 8); } function _putsF(dt: NumberArray, pos: number, val: number) { - val = val<<(pos&7); - const o=(pos>>>3); - dt[o]|=val; - dt[o+1]|=(val>>>8); - dt[o+2]|=(val>>>16); + val = val << (pos & 7); + const o = (pos >>> 3); + dt[o] |= val; + dt[o + 1] |= (val >>> 8); + dt[o + 2] |= (val >>> 16); } diff --git a/src/mol-util/zip/huffman.ts b/src/mol-util/zip/huffman.ts index 1e2216034d2e5f6c22a2c9167ed4d7f3dff0d2c3..5d776c885fad239253e758ad2aabde10c3a2df58 100644 --- a/src/mol-util/zip/huffman.ts +++ b/src/mol-util/zip/huffman.ts @@ -18,22 +18,22 @@ export type HufTree = { } export function _hufTree(hst: NumberArray, tree: number[], MAXL: number) { const list: HufTree[] = [] - const hl = hst.length, tl=tree.length - for(let i=0; i<tl; i+=2) { - tree[i]=0; - tree[i+1]=0; + const hl = hst.length, tl = tree.length + for(let i = 0; i < tl; i += 2) { + tree[i] = 0; + tree[i + 1] = 0; } - for(let i=0; i<hl; i++) if(hst[i] !== 0) list.push({ lit: i, f: hst[i], d: undefined as any }); - const end = list.length, l2=list.slice(0); + for(let i = 0; i < hl; i++) if(hst[i] !== 0) list.push({ lit: i, f: hst[i], d: undefined as any }); + const end = list.length, l2 = list.slice(0); if(end === 0) return 0; // empty histogram (usually for dist) if(end === 1) { const lit = list[0].lit, l2 = lit === 0 ? 1 : 0; - tree[(lit<<1)+1]=1; - tree[(l2<<1)+1]=1; + tree[(lit << 1) + 1] = 1; + tree[(l2 << 1) + 1] = 1; return 1; } - list.sort(function(a,b){return a.f - b.f;}); - let a=list[0], b=list[1], i0=0, i1=1, i2=2; + list.sort(function(a, b){return a.f - b.f;}); + let a = list[0], b = list[1], i0 = 0, i1 = 1, i2 = 2; list[0] = { lit: -1, f: a.f + b.f, @@ -41,16 +41,16 @@ export function _hufTree(hst: NumberArray, tree: number[], MAXL: number) { r: b, d: 0 }; - while(i1 !== end-1) { - if(i0 !== i1 && (i2 === end || list[i0].f<list[i2].f)) { - a=list[i0++]; + while(i1 !== end - 1) { + if(i0 !== i1 && (i2 === end || list[i0].f < list[i2].f)) { + a = list[i0++]; } else { - a=list[i2++]; + a = list[i2++]; } - if(i0 !== i1 && (i2 === end || list[i0].f<list[i2].f)) { - b=list[i0++]; + if(i0 !== i1 && (i2 === end || list[i0].f < list[i2].f)) { + b = list[i0++]; } else { - b=list[i2++]; + b = list[i2++]; } list[i1++] = { lit: -1, @@ -60,12 +60,12 @@ export function _hufTree(hst: NumberArray, tree: number[], MAXL: number) { d: undefined as any }; } - let maxl = setDepth(list[i1-1], 0); + let maxl = setDepth(list[i1 - 1], 0); if(maxl > MAXL) { restrictDepth(l2, MAXL, maxl); maxl = MAXL; } - for(let i=0; i<end; i++) tree[(l2[i].lit<<1)+1] = l2[i].d; + for(let i = 0; i < end; i++) tree[(l2[i].lit << 1) + 1] = l2[i].d; return maxl; } @@ -74,34 +74,34 @@ function setDepth(t: HufTree, d: number): number { t.d = d; return d; } - return Math.max(setDepth(t.l!, d+1), setDepth(t.r!, d+1)); + return Math.max(setDepth(t.l!, d + 1), setDepth(t.r!, d + 1)); } function restrictDepth(dps: HufTree[], MD: number, maxl: number) { - let i=0, bCost=1<<(maxl-MD), dbt=0; + let i = 0, bCost = 1 << (maxl - MD), dbt = 0; dps.sort(function(a: HufTree, b: HufTree){return b.d === a.d ? a.f - b.f : b.d - a.d;}); - for(i=0; i<dps.length; i++) { - if(dps[i].d>MD) { - const od=dps[i].d; - dps[i].d=MD; - dbt+=bCost-(1<<(maxl-od)); + for(i = 0; i < dps.length; i++) { + if(dps[i].d > MD) { + const od = dps[i].d; + dps[i].d = MD; + dbt += bCost - (1 << (maxl - od)); } else { break; } } - dbt = dbt>>>(maxl-MD); - while(dbt>0) { - const od=dps[i].d; - if(od<MD) { + dbt = dbt >>> (maxl - MD); + while(dbt > 0) { + const od = dps[i].d; + if(od < MD) { dps[i].d++; - dbt-=(1<<(MD-od-1)); + dbt -= (1 << (MD - od - 1)); } else { i++; } } - for(; i>=0; i--) { - if(dps[i].d === MD && dbt<0) { + for(; i >= 0; i--) { + if(dps[i].d === MD && dbt < 0) { dps[i].d--; dbt++; } diff --git a/src/mol-util/zip/inflate.ts b/src/mol-util/zip/inflate.ts index 8b6208810b44fbe29c57ac01c98a122932cd47e3..e6dae79769fea9d301e994979e009ad65e27e387 100644 --- a/src/mol-util/zip/inflate.ts +++ b/src/mol-util/zip/inflate.ts @@ -13,7 +13,7 @@ import { RuntimeContext } from '../../mol-task'; function InflateContext(data: Uint8Array, buf?: Uint8Array) { const noBuf = buf === undefined; - if(buf === undefined) buf = new Uint8Array((data.length>>>2)<<3); + if(buf === undefined) buf = new Uint8Array((data.length >>> 2) << 3); return { data, buf, @@ -38,29 +38,29 @@ function inflateBlocks(ctx: InflateContext, count: number) { BFINAL = _bitsF(data, pos, 1); iBlock += 1 const BTYPE = _bitsF(data, pos + 1, 2); - pos+=3; + pos += 3; if(BTYPE === 0) { // uncompressed block - if((pos&7) !== 0) pos += 8 - (pos&7); - const p8 = (pos>>>3) + 4 - const len = data[p8-4] | (data[p8-3]<<8); - if(noBuf) buf=_check(buf, off + len); + if((pos & 7) !== 0) pos += 8 - (pos & 7); + const p8 = (pos >>> 3) + 4 + const len = data[p8 - 4] | (data[p8 - 3] << 8); + if(noBuf) buf = _check(buf, off + len); buf.set(new Uint8Array(data.buffer, data.byteOffset + p8, len), off); - pos = ((p8+len)<<3); + pos = ((p8 + len) << 3); off += len; continue; } // grow output buffer if not provided - if(noBuf) buf = _check(buf, off + (1<<17)); + if(noBuf) buf = _check(buf, off + (1 << 17)); if(BTYPE === 1) { // block compressed with fixed Huffman codes lmap = U.flmap; dmap = U.fdmap; - ML = (1<<9) - 1; - MD = (1<<5) - 1; + ML = (1 << 9) - 1; + MD = (1 << 5) - 1; } else if(BTYPE === 2) { // block compressed with dynamic Huffman codes const HLIT = _bitsE(data, pos, 5) + 257; @@ -68,15 +68,15 @@ function inflateBlocks(ctx: InflateContext, count: number) { const HCLEN = _bitsE(data, pos + 10, 4) + 4; pos += 14; - for(let i=0; i<38; i+=2) { - U.itree[i]=0; - U.itree[i+1]=0; + for(let i = 0; i < 38; i += 2) { + U.itree[i] = 0; + U.itree[i + 1] = 0; } let tl = 1; - for(let i=0; i<HCLEN; i++) { - const l=_bitsE(data, pos+i*3, 3); - U.itree[(U.ordr[i]<<1)+1] = l; - if(l>tl) tl = l; + for(let i = 0; i < HCLEN; i++) { + const l = _bitsE(data, pos + i * 3, 3); + U.itree[(U.ordr[i] << 1) + 1] = l; + if(l > tl) tl = l; } pos += 3 * HCLEN; makeCodes(U.itree, tl); @@ -84,11 +84,11 @@ function inflateBlocks(ctx: InflateContext, count: number) { lmap = U.lmap; dmap = U.dmap; - pos = _decodeTiny(U.imap, (1<<tl)-1, HLIT+HDIST, data, pos, U.ttree); - const mx0 = _copyOut(U.ttree, 0, HLIT , U.ltree); - ML = (1<<mx0)-1; + pos = _decodeTiny(U.imap, (1 << tl) - 1, HLIT + HDIST, data, pos, U.ttree); + const mx0 = _copyOut(U.ttree, 0, HLIT, U.ltree); + ML = (1 << mx0) - 1; const mx1 = _copyOut(U.ttree, HLIT, HDIST, U.dtree); - MD = (1<<mx1)-1; + MD = (1 << mx1) - 1; makeCodes(U.ltree, mx0); codes2map(U.ltree, mx0, lmap); @@ -101,33 +101,33 @@ function inflateBlocks(ctx: InflateContext, count: number) { while(true) { const code = lmap[_get17(data, pos) & ML]; - pos += code&15; + pos += code & 15; const lit = code >>> 4; if((lit >>> 8) === 0) { buf[off++] = lit; } else if(lit === 256) { break; } else { - let end = off+lit-254; + let end = off + lit - 254; if(lit > 264) { - const ebs = U.ldef[lit-257]; - end = off + (ebs>>>3) + _bitsE(data, pos, ebs&7); - pos += ebs&7; + const ebs = U.ldef[lit - 257]; + end = off + (ebs >>> 3) + _bitsE(data, pos, ebs & 7); + pos += ebs & 7; } const dcode = dmap[_get17(data, pos) & MD]; - pos += dcode&15; - const dlit = dcode>>>4; + pos += dcode & 15; + const dlit = dcode >>> 4; const dbs = U.ddef[dlit] - const dst = (dbs>>>4) + _bitsF(data, pos, dbs&15); - pos += dbs&15; - - if(noBuf) buf = _check(buf, off+(1<<17)); - while(off<end) { - buf[off] = buf[off++-dst]; - buf[off] = buf[off++-dst]; - buf[off] = buf[off++-dst]; - buf[off] = buf[off++-dst]; + const dst = (dbs >>> 4) + _bitsF(data, pos, dbs & 15); + pos += dbs & 15; + + if(noBuf) buf = _check(buf, off + (1 << 17)); + while(off < end) { + buf[off] = buf[off++ - dst]; + buf[off] = buf[off++ - dst]; + buf[off] = buf[off++ - dst]; + buf[off] = buf[off++ - dst]; } off = end; } @@ -165,18 +165,18 @@ function _check(buf: Uint8Array, len: number) { function _decodeTiny(lmap: NumberArray, LL: number, len: number, data: Uint8Array, pos: number, tree: number[]) { let i = 0; while(i < len) { - const code = lmap[_get17(data, pos)&LL]; - pos += code&15; - const lit = code>>>4; + const code = lmap[_get17(data, pos) & LL]; + pos += code & 15; + const lit = code >>> 4; if(lit <= 15) { - tree[i]=lit; + tree[i] = lit; i++; } else { let ll = 0, n = 0; if(lit === 16) { n = (3 + _bitsE(data, pos, 2)); pos += 2; - ll = tree[i-1]; + ll = tree[i - 1]; } else if(lit === 17) { n = (3 + _bitsE(data, pos, 3)); pos += 3; @@ -184,9 +184,9 @@ function _decodeTiny(lmap: NumberArray, LL: number, len: number, data: Uint8Arra n = (11 + _bitsE(data, pos, 7)); pos += 7; } - const ni = i+n; - while(i<ni) { - tree[i]=ll; + const ni = i + n; + while(i < ni) { + tree[i] = ll; i++; } } @@ -195,31 +195,31 @@ function _decodeTiny(lmap: NumberArray, LL: number, len: number, data: Uint8Arra } function _copyOut(src: number[], off: number, len: number, tree: number[]) { - let mx=0, i=0 - const tl=tree.length>>>1; + let mx = 0, i = 0 + const tl = tree.length >>> 1; while(i < len) { - let v=src[i+off]; - tree[(i<<1)]=0; - tree[(i<<1)+1]=v; - if(v>mx)mx=v; + let v = src[i + off]; + tree[(i << 1)] = 0; + tree[(i << 1) + 1] = v; + if(v > mx)mx = v; i++; } while(i < tl) { - tree[(i<<1)]=0; - tree[(i<<1)+1]=0; + tree[(i << 1)] = 0; + tree[(i << 1) + 1] = 0; i++; } return mx; } function _bitsE(dt: NumberArray, pos: number, length: number) { - return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8))>>>(pos&7))&((1<<length)-1); + return ((dt[pos >>> 3] | (dt[(pos >>> 3) + 1] << 8)) >>> (pos & 7)) & ((1 << length) - 1); } function _bitsF(dt: NumberArray, pos: number, length: number) { - return ((dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16))>>>(pos&7))&((1<<length)-1); + return ((dt[pos >>> 3] | (dt[(pos >>> 3) + 1] << 8) | (dt[(pos >>> 3) + 2] << 16)) >>> (pos & 7)) & ((1 << length) - 1); } function _get17(dt: NumberArray, pos: number) { // return at least 17 meaningful bytes - return (dt[pos>>>3] | (dt[(pos>>>3)+1]<<8) | (dt[(pos>>>3)+2]<<16) )>>>(pos&7); + return (dt[pos >>> 3] | (dt[(pos >>> 3) + 1] << 8) | (dt[(pos >>> 3) + 2] << 16) ) >>> (pos & 7); } \ No newline at end of file diff --git a/src/mol-util/zip/util.ts b/src/mol-util/zip/util.ts index 16230de92e9be1dc76a4d09ebfc9c2c1364c184e..a191ad3f1d2ca9db49c9da6a4f4b7610d2139b14 100644 --- a/src/mol-util/zip/util.ts +++ b/src/mol-util/zip/util.ts @@ -8,16 +8,16 @@ */ export const U = (function(){ - const u16=Uint16Array, u32=Uint32Array; + const u16 = Uint16Array, u32 = Uint32Array; return { next_code : new u16(16), bl_count : new u16(16), ordr : [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ], - of0 : [3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,999,999,999], - exb : [0,0,0,0,0,0,0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0], + of0 : [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 999, 999, 999], + exb : [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0, 0], ldef : new u16(32), - df0 : [1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577, 65535, 65535], - dxb : [0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0], + df0 : [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 65535, 65535], + dxb : [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 0, 0], ddef : new u32(32), flmap: new u16( 512), fltree: [] as number[], fdmap: new u16( 32), fdtree: [] as number[], @@ -25,38 +25,38 @@ export const U = (function(){ dmap : new u16(32768), dtree : [] as number[], imap : new u16( 512), itree : [] as number[], // rev9 : new u16( 512) - rev15: new u16(1<<15), + rev15: new u16(1 << 15), lhst : new u32(286), dhst : new u32( 30), ihst : new u32(19), lits : new u32(15000), - strt : new u16(1<<16), - prev : new u16(1<<15) + strt : new u16(1 << 16), + prev : new u16(1 << 15) }; })(); (function(){ - const len = 1<<15; - for(let i=0; i<len; i++) { + const len = 1 << 15; + for(let i = 0; i < len; i++) { let x = i; x = (((x & 0xaaaaaaaa) >>> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >>> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >>> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >>> 8) | ((x & 0x00ff00ff) << 8)); - U.rev15[i] = (((x >>> 16) | (x << 16)))>>>17; + U.rev15[i] = (((x >>> 16) | (x << 16))) >>> 17; } function pushV(tgt: number[], n: number, sv: number) { while(n-- !== 0) tgt.push(0, sv); } - for(let i=0; i<32; i++) { - U.ldef[i] = (U.of0[i]<<3)|U.exb[i]; - U.ddef[i] = (U.df0[i]<<4)|U.dxb[i]; + for(let i = 0; i < 32; i++) { + U.ldef[i] = (U.of0[i] << 3) | U.exb[i]; + U.ddef[i] = (U.df0[i] << 4) | U.dxb[i]; } pushV(U.fltree, 144, 8); - pushV(U.fltree, 255-143, 9); - pushV(U.fltree, 279-255, 7); - pushV(U.fltree,287-279,8); + pushV(U.fltree, 255 - 143, 9); + pushV(U.fltree, 279 - 255, 7); + pushV(U.fltree, 287 - 279, 8); /* var i = 0; for(; i<=143; i++) U.fltree.push(0,8); @@ -68,13 +68,13 @@ export const U = (function(){ codes2map(U.fltree, 9, U.flmap); revCodes (U.fltree, 9) - pushV(U.fdtree,32,5); + pushV(U.fdtree, 32, 5); // for(i=0;i<32; i++) U.fdtree.push(0,5); makeCodes(U.fdtree, 5); codes2map(U.fdtree, 5, U.fdmap); revCodes (U.fdtree, 5) - pushV(U.itree,19,0); pushV(U.ltree,286,0); pushV(U.dtree,30,0); pushV(U.ttree,320,0); + pushV(U.itree, 19, 0); pushV(U.ltree, 286, 0); pushV(U.dtree, 30, 0); pushV(U.ttree, 320, 0); /* for(var i=0; i< 19; i++) U.itree.push(0,0); for(var i=0; i<286; i++) U.ltree.push(0,0); @@ -86,17 +86,17 @@ export const U = (function(){ export function codes2map(tree: number[], MAX_BITS: number, map: Uint16Array) { const max_code = tree.length; const r15 = U.rev15; - for(let i=0; i<max_code; i+=2) { - if(tree[i+1] !== 0) { - const lit = i>>1; - const cl = tree[i+1], val = (lit<<4)|cl; // : (0x8000 | (U.of0[lit-257]<<7) | (U.exb[lit-257]<<4) | cl); - const rest = (MAX_BITS-cl) - let i0 = tree[i]<<rest - const i1 = i0 + (1<<rest); + for(let i = 0; i < max_code; i += 2) { + if(tree[i + 1] !== 0) { + const lit = i >> 1; + const cl = tree[i + 1], val = (lit << 4) | cl; // : (0x8000 | (U.of0[lit-257]<<7) | (U.exb[lit-257]<<4) | cl); + const rest = (MAX_BITS - cl) + let i0 = tree[i] << rest + const i1 = i0 + (1 << rest); // tree[i]=r15[i0]>>>(15-MAX_BITS); while(i0 !== i1) { - const p0 = r15[i0]>>>(15-MAX_BITS); - map[p0]=val; i0++; + const p0 = r15[i0] >>> (15 - MAX_BITS); + map[p0] = val; i0++; } } } @@ -106,20 +106,20 @@ export function makeCodes(tree: number[], MAX_BITS: number) { // code, length const max_code = tree.length; const bl_count = U.bl_count; - for(let i=0; i<=MAX_BITS; i++) bl_count[i]=0; - for(let i=1; i<max_code; i+=2) bl_count[tree[i]]++; + for(let i = 0; i <= MAX_BITS; i++) bl_count[i] = 0; + for(let i = 1; i < max_code; i += 2) bl_count[tree[i]]++; const next_code = U.next_code; // smallest code for each length let code = 0; bl_count[0] = 0; for (let bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits-1]) << 1; + code = (code + bl_count[bits - 1]) << 1; next_code[bits] = code; } - for (let n = 0; n < max_code; n+=2) { - const len = tree[n+1]; + for (let n = 0; n < max_code; n += 2) { + const len = tree[n + 1]; if (len !== 0) { tree[n] = next_code[len]; next_code[len]++; @@ -128,9 +128,9 @@ export function makeCodes(tree: number[], MAX_BITS: number) { // code, length } export function revCodes(tree: number[], MAX_BITS: number) { - const r15 = U.rev15, imb = 15-MAX_BITS; - for(let i=0; i<tree.length; i+=2) { - const i0 = (tree[i]<<(MAX_BITS-tree[i+1])); - tree[i] = r15[i0]>>>imb; + const r15 = U.rev15, imb = 15 - MAX_BITS; + for(let i = 0; i < tree.length; i += 2) { + const i0 = (tree[i] << (MAX_BITS - tree[i + 1])); + tree[i] = r15[i0] >>> imb; } } \ No newline at end of file diff --git a/src/mol-util/zip/zip.ts b/src/mol-util/zip/zip.ts index 081451dd0216d0a0402cb850997a3af241d20a27..25ca2ab06bb151cdc4053dd2aa34016acd5b55f1 100644 --- a/src/mol-util/zip/zip.ts +++ b/src/mol-util/zip/zip.ts @@ -18,7 +18,7 @@ import { RuntimeContext } from '../../mol-task'; export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames = false) { const out: { [k: string]: Uint8Array | { size: number, csize: number } } = Object.create(null); const data = new Uint8Array(buf); - let eocd = data.length-4; + let eocd = data.length - 4; while(readUint(data, eocd) !== 0x06054b50) eocd--; @@ -31,11 +31,11 @@ export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames o += 2; // const csize = readUint(data, o); - o+=4; - const coffs = readUint(data, o); o+=4; + o += 4; + const coffs = readUint(data, o); o += 4; o = coffs; - for(let i = 0; i<cnu; i++) { + for(let i = 0; i < cnu; i++) { // const sign = readUint(data, o); o += 4; o += 4; // versions; @@ -43,19 +43,19 @@ export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames o += 4; // time // const crc32 = readUint(data, o); - o+=4; + o += 4; const csize = readUint(data, o); - o+=4; + o += 4; const usize = readUint(data, o); - o+=4; + o += 4; const nl = readUshort(data, o) - const el = readUshort(data, o+2) - const cl = readUshort(data, o+4); + const el = readUshort(data, o + 2) + const cl = readUshort(data, o + 4); o += 6; // name, extra, comment o += 8; // disk, attribs - const roff = readUint(data, o); o+=4; + const roff = readUint(data, o); o += 4; o += nl + el + cl; await _readLocal(runtime, data, roff, out, csize, usize, onlyNames); @@ -66,28 +66,28 @@ export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames async function _readLocal(runtime: RuntimeContext, data: Uint8Array, o: number, out: { [k: string]: Uint8Array | { size: number, csize: number } }, csize: number, usize: number, onlyNames: boolean) { // const sign = readUint(data, o); - o+=4; + o += 4; // const ver = readUshort(data, o); - o+=2; + o += 2; // const gpflg = readUshort(data, o); - o+=2; + o += 2; // if((gpflg&8)!=0) throw "unknown sizes"; const cmpr = readUshort(data, o); - o+=2; + o += 2; // const time = readUint(data, o); - o+=4; + o += 4; // const crc32 = readUint(data, o); - o+=4; + o += 4; // var csize = rUi(data, o); o+=4; // var usize = rUi(data, o); o+=4; - o+=8; + o += 8; const nlen = readUshort(data, o); - o+=2; + o += 2; const elen = readUshort(data, o); - o+=2; + o += 2; const name = readUTF8(data, o, nlen); o += nlen; // console.log(name); @@ -100,7 +100,7 @@ async function _readLocal(runtime: RuntimeContext, data: Uint8Array, o: number, const file = new Uint8Array(data.buffer, o); if(cmpr === 0) { - out[name] = new Uint8Array(file.buffer.slice(o, o+csize)); + out[name] = new Uint8Array(file.buffer.slice(o, o + csize)); } else if(cmpr === 8) { const buf = new Uint8Array(usize); await inflateRaw(runtime, file, buf); @@ -120,7 +120,7 @@ export function inflate(runtime: RuntimeContext, file: Uint8Array, buf?: Uint8Ar // const CM = (CMF&15) // const CINFO = (CMF>>>4); // console.log(CM, CINFO,CMF,FLG); - return inflateRaw(runtime, new Uint8Array(file.buffer, file.byteOffset+2, file.length-6), buf); + return inflateRaw(runtime, new Uint8Array(file.buffer, file.byteOffset + 2, file.length - 6), buf); } // https://tools.ietf.org/html/rfc1952 @@ -175,17 +175,17 @@ export async function ungzip(runtime: RuntimeContext, file: Uint8Array, buf?: Ui } export function deflate(data: Uint8Array, opts?: { level: number }/* , buf, off*/) { - if(opts === undefined) opts={ level: 6 }; - let off=0 + if(opts === undefined) opts = { level: 6 }; + let off = 0 const buf = new Uint8Array(50 + Math.floor(data.length * 1.1)); - buf[off]=120; buf[off+1]=156; off+=2; + buf[off] = 120; buf[off + 1] = 156; off += 2; off = _deflateRaw(data, buf, off, opts.level); const crcValue = adler(data, 0, data.length); - buf[off+0] = ((crcValue>>>24)&255); - buf[off+1] = ((crcValue>>>16)&255); - buf[off+2] = ((crcValue>>> 8)&255); - buf[off+3] = ((crcValue>>> 0)&255); - return new Uint8Array(buf.buffer, 0, off+4); + buf[off + 0] = ((crcValue >>> 24) & 255); + buf[off + 1] = ((crcValue >>> 16) & 255); + buf[off + 2] = ((crcValue >>> 8) & 255); + buf[off + 3] = ((crcValue >>> 0) & 255); + return new Uint8Array(buf.buffer, 0, off + 4); } function deflateRaw(data: Uint8Array, opts?: { level: number }) { @@ -220,15 +220,15 @@ export function zip(obj: { [k: string]: Uint8Array }, noCmpr = false) { const file = zpd[p]; fof.push(o); o = _writeHeader(data, o, p, file, 0); } - let i=0, ioff = o; + let i = 0, ioff = o; for(const p in zpd) { const file = zpd[p]; fof.push(o); o = _writeHeader(data, o, p, file, 1, fof[i++]); } - const csize = o-ioff; + const csize = o - ioff; - writeUint(data, o, 0x06054b50); o+=4; + writeUint(data, o, 0x06054b50); o += 4; o += 4; // disks writeUshort(data, o, i); o += 2; writeUshort(data, o, i); o += 2; // number of c d records @@ -247,27 +247,27 @@ function _noNeed(fn: string) { function _writeHeader(data: Uint8Array, o: number, p: string, obj: { cpr: boolean, usize: number, crc: number, file: Uint8Array }, t: number, roff = 0) { const file = obj.file; - writeUint(data, o, t === 0 ? 0x04034b50 : 0x02014b50); o+=4; // sign - if(t === 1) o+=2; // ver made by - writeUshort(data, o, 20); o+=2; // ver - writeUshort(data, o, 0); o+=2; // gflip - writeUshort(data, o, obj.cpr?8:0); o+=2; // cmpr + writeUint(data, o, t === 0 ? 0x04034b50 : 0x02014b50); o += 4; // sign + if(t === 1) o += 2; // ver made by + writeUshort(data, o, 20); o += 2; // ver + writeUshort(data, o, 0); o += 2; // gflip + writeUshort(data, o, obj.cpr ? 8 : 0); o += 2; // cmpr - writeUint(data, o, 0); o+=4; // time - writeUint(data, o, obj.crc); o+=4; // crc32 - writeUint(data, o, file.length); o+=4; // csize - writeUint(data, o, obj.usize); o+=4; // usize + writeUint(data, o, 0); o += 4; // time + writeUint(data, o, obj.crc); o += 4; // crc32 + writeUint(data, o, file.length); o += 4; // csize + writeUint(data, o, obj.usize); o += 4; // usize - writeUshort(data, o, sizeUTF8(p)); o+=2; // nlen - writeUshort(data, o, 0); o+=2; // elen + writeUshort(data, o, sizeUTF8(p)); o += 2; // nlen + writeUshort(data, o, 0); o += 2; // elen if(t === 1) { o += 2; // comment length o += 2; // disk number o += 6; // attributes - writeUint(data, o, roff); o+=4; // usize + writeUint(data, o, roff); o += 4; // usize } - const nlen = writeUTF8(data, o, p); o+= nlen; + const nlen = writeUTF8(data, o, p); o += nlen; if(t === 0) { data.set(file, o); o += file.length; diff --git a/src/tests/browser/render-shape.ts b/src/tests/browser/render-shape.ts index cf7b748b6eeaa7d18605fc207aed8c578611909e..f191858dcad3a672578b38483bdce22f7d2bf6d6 100644 --- a/src/tests/browser/render-shape.ts +++ b/src/tests/browser/render-shape.ts @@ -81,7 +81,7 @@ async function getSphereMesh(ctx: RuntimeContext, centers: number[], mesh?: Mesh } const myData = { - centers: [0, 0, 0, 0, 3, 0, 1, 0 , 4], + centers: [0, 0, 0, 0, 3, 0, 1, 0, 4], colors: [ColorNames.tomato, ColorNames.springgreen, ColorNames.springgreen], labels: ['Sphere 0, Instance A', 'Sphere 1, Instance A', 'Sphere 0, Instance B', 'Sphere 1, Instance B'], transforms: [Mat4.identity(), Mat4.fromTranslation(Mat4.zero(), Vec3.create(3, 0, 0))]