From 01691f30502f74ded35535318fa0675d7926aa64 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sun, 12 Sep 2021 23:20:59 -0700 Subject: [PATCH] lint: add keyword-spacing rule --- .eslintrc.json | 6 +- src/extensions/anvil/algorithm.ts | 6 +- src/extensions/cellpack/model.ts | 2 +- src/extensions/cellpack/state.ts | 4 +- .../rcsb/assembly-symmetry/behavior.ts | 2 +- src/extensions/rcsb/validation-report/prop.ts | 2 +- src/mol-gl/shader-code.ts | 2 +- src/mol-io/reader/psf/parser.ts | 2 +- src/mol-math/linear-algebra/matrix/evd.ts | 6 +- src/mol-model-formats/structure/cif-core.ts | 2 +- .../shrake-rupley/radii.ts | 2 +- src/mol-model/loci.ts | 4 +- .../structure/structure/element/loci.ts | 2 +- .../structure/representation-preset.ts | 4 +- src/mol-plugin-state/manager/loci-label.ts | 2 +- src/mol-plugin-ui/base.tsx | 2 +- .../line-graph/line-graph-component.tsx | 44 ++++---- .../controls/line-graph/point-component.tsx | 2 +- src/mol-plugin-ui/structure/focus.tsx | 2 +- .../computed/accessible-surface-area.ts | 4 +- .../sequence/best-database-mapping.ts | 2 +- src/mol-plugin/util/toast.ts | 2 +- src/mol-repr/shape/representation.ts | 2 +- .../structure/visual/bond-inter-unit-line.ts | 2 +- src/mol-repr/structure/visual/util/bond.ts | 2 +- .../visual/util/polymer/trace-iterator.ts | 12 +- src/mol-repr/volume/direct-volume.ts | 4 +- src/mol-util/data-source.ts | 2 +- src/mol-util/zip/bin.ts | 24 ++-- src/mol-util/zip/checksum.ts | 4 +- src/mol-util/zip/deflate.ts | 104 +++++++++--------- src/mol-util/zip/huffman.ts | 34 +++--- src/mol-util/zip/inflate.ts | 58 +++++----- src/mol-util/zip/util.ts | 18 +-- src/mol-util/zip/zip.ts | 32 +++--- src/servers/model/server/query.ts | 2 +- 36 files changed, 204 insertions(+), 202 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 75507b37c..3c1eb87b4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -52,7 +52,8 @@ "space-before-function-paren": "off", "func-call-spacing": "off", "no-multi-spaces": "error", - "block-spacing": "error" + "block-spacing": "error", + "keyword-spacing": "off" }, "overrides": [ { @@ -109,7 +110,8 @@ "named": "never", "asyncArrow": "always" }], - "@typescript-eslint/func-call-spacing": ["error"] + "@typescript-eslint/func-call-spacing": ["error"], + "@typescript-eslint/keyword-spacing": ["error"] } } ] diff --git a/src/extensions/anvil/algorithm.ts b/src/extensions/anvil/algorithm.ts index 08bdcadd5..4427afb38 100644 --- a/src/extensions/anvil/algorithm.ts +++ b/src/extensions/anvil/algorithm.ts @@ -476,11 +476,11 @@ function adjustExtent(ctx: ANVILContext, membrane: MembraneCandidate, centroid: } function qValue(currentStats: HphobHphil, initialStats: HphobHphil): number { - if(initialStats.hphob < 1) { + if (initialStats.hphob < 1) { initialStats.hphob = 0.1; } - if(initialStats.hphil < 1) { + if (initialStats.hphil < 1) { initialStats.hphil += 1; } @@ -505,7 +505,7 @@ function generateSpherePoints(ctx: ANVILContext, numberOfSpherePoints: number): const { centroid, extent } = ctx; const points = []; let oldPhi = 0, h, theta, phi; - for(let k = 1, kl = numberOfSpherePoints + 1; k < kl; k++) { + for (let k = 1, kl = numberOfSpherePoints + 1; k < kl; k++) { h = -1 + 2 * (k - 1) / (2 * numberOfSpherePoints - 1); theta = Math.acos(h); phi = (k === 1 || k === numberOfSpherePoints) ? 0 : (oldPhi + 3.6 / Math.sqrt(2 * numberOfSpherePoints * (1 - h * h))) % (2 * Math.PI); diff --git a/src/extensions/cellpack/model.ts b/src/extensions/cellpack/model.ts index 8b060aafd..d57624cc3 100644 --- a/src/extensions/cellpack/model.ts +++ b/src/extensions/cellpack/model.ts @@ -415,7 +415,7 @@ export function createStructureFromCellPack(plugin: PluginContext, packing: Cell if (ctx.shouldUpdate) await ctx.update(`${name} - structure`); const structure = Structure.create(units); - for(let i = 0, il = structure.models.length; i < il; ++i) { + for (let i = 0, il = structure.models.length; i < il; ++i) { Model.TrajectoryInfo.set(structure.models[i], { size: il, index: i }); } return { structure, assets, colors: skipColors ? undefined : colors }; diff --git a/src/extensions/cellpack/state.ts b/src/extensions/cellpack/state.ts index bd5729272..e7bc842ab 100644 --- a/src/extensions/cellpack/state.ts +++ b/src/extensions/cellpack/state.ts @@ -84,7 +84,7 @@ const StructureFromCellpack = PluginStateTransform.BuiltIn({ }, dispose({ b, cache }) { const assets = (cache as any).assets as Asset.Wrapper[]; - if(assets) { + if (assets) { for (const a of assets) a.dispose(); } @@ -137,7 +137,7 @@ const StructureFromAssemblies = PluginStateTransform.BuiltIn({ offsetInvariantId += maxInvariantId + 1; } structure = builder.getStructure(); - for(let i = 0, il = structure.models.length; i < il; ++i) { + for (let i = 0, il = structure.models.length; i < il; ++i) { Model.TrajectoryInfo.set(structure.models[i], { size: il, index: i }); } } diff --git a/src/extensions/rcsb/assembly-symmetry/behavior.ts b/src/extensions/rcsb/assembly-symmetry/behavior.ts index eed3800e6..9e032c809 100644 --- a/src/extensions/rcsb/assembly-symmetry/behavior.ts +++ b/src/extensions/rcsb/assembly-symmetry/behavior.ts @@ -85,7 +85,7 @@ export const InitAssemblySymmetry3D = StateAction.build({ const assemblySymmetryData = AssemblySymmetryDataProvider.get(a.data).value; const symmetryIndex = assemblySymmetryData ? AssemblySymmetry.firstNonC1(assemblySymmetryData) : -1; await AssemblySymmetryProvider.attach(propCtx, a.data, { symmetryIndex }); - } catch(e) { + } catch (e) { plugin.log.error(`Assembly Symmetry: ${e}`); return; } diff --git a/src/extensions/rcsb/validation-report/prop.ts b/src/extensions/rcsb/validation-report/prop.ts index fa060c584..f1be4b10b 100644 --- a/src/extensions/rcsb/validation-report/prop.ts +++ b/src/extensions/rcsb/validation-report/prop.ts @@ -112,7 +112,7 @@ namespace ValidationReport { } export async function obtain(ctx: CustomProperty.Context, model: Model, props: ValidationReportProps): Promise<CustomProperty.Data<ValidationReport>> { - switch(props.source.name) { + switch (props.source.name) { case 'file': return open(ctx, model, props.source.params); case 'server': return fetch(ctx, model, props.source.params); } diff --git a/src/mol-gl/shader-code.ts b/src/mol-gl/shader-code.ts index 2e507084f..63836245a 100644 --- a/src/mol-gl/shader-code.ts +++ b/src/mol-gl/shader-code.ts @@ -137,7 +137,7 @@ import { cylinders_vert } from './shader/cylinders.vert'; import { cylinders_frag } from './shader/cylinders.frag'; export const CylindersShaderCode = ShaderCode('cylinders', cylinders_vert, cylinders_frag, { fragDepth: 'required', drawBuffers: 'optional' }); -import { text_vert }from './shader/text.vert'; +import { text_vert } from './shader/text.vert'; import { text_frag } from './shader/text.frag'; export const TextShaderCode = ShaderCode('text', text_vert, text_frag, { standardDerivatives: 'required', drawBuffers: 'optional' }); diff --git a/src/mol-io/reader/psf/parser.ts b/src/mol-io/reader/psf/parser.ts index 7acca9aaf..7ef359df3 100644 --- a/src/mol-io/reader/psf/parser.ts +++ b/src/mol-io/reader/psf/parser.ts @@ -174,7 +174,7 @@ async function parseInternal(data: string, ctx: RuntimeContext): Promise<Result< const id = readLine(state.tokenizer).trim(); - while(tokenizer.tokenEnd < tokenizer.length) { + while (tokenizer.tokenEnd < tokenizer.length) { const line = readLine(state.tokenizer).trim(); if (line.includes('!NTITLE')) { const numTitle = parseInt(line.split(reWhitespace)[0]); diff --git a/src/mol-math/linear-algebra/matrix/evd.ts b/src/mol-math/linear-algebra/matrix/evd.ts index 041048552..9feb5fcad 100644 --- a/src/mol-math/linear-algebra/matrix/evd.ts +++ b/src/mol-math/linear-algebra/matrix/evd.ts @@ -19,9 +19,9 @@ export namespace EVD { return { size, matrix: Matrix.create(size, size), - eigenValues: <any>new Float64Array(size), - D: <any>new Float64Array(size), - E: <any>new Float64Array(size) + eigenValues: <any> new Float64Array(size), + D: <any> new Float64Array(size), + E: <any> new Float64Array(size) }; } diff --git a/src/mol-model-formats/structure/cif-core.ts b/src/mol-model-formats/structure/cif-core.ts index 55f869a79..091853b77 100644 --- a/src/mol-model-formats/structure/cif-core.ts +++ b/src/mol-model-formats/structure/cif-core.ts @@ -160,7 +160,7 @@ async function getModels(db: CifCore_Database, format: CifCoreFormat, ctx: Runti ModelSymmetry.Provider.set(first, symmetry); const bondCount = db.geom_bond._rowCount; - if(bondCount > 0) { + if (bondCount > 0) { const labelIndexMap: { [label: string]: number } = {}; const { label } = db.atom_site; for (let i = 0, il = label.rowCount; i < il; ++i) { diff --git a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts index 80f24501e..ffb4a71ed 100644 --- a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts +++ b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts @@ -94,7 +94,7 @@ function determineRadiusAmino(atomId: string, element: ElementSymbol, compId: st return atomId === 'NZ' ? 4 : 3; case 'C': switch (atomId) { - case 'C': case 'CE1': case'CE2': case 'CE3': case 'CH2': case 'CZ': case 'CZ2': case 'CZ3': + case 'C': case 'CE1': case 'CE2': case 'CE3': case 'CH2': case 'CZ': case 'CZ2': case 'CZ3': return 1; case 'CA': case 'CB': case 'CE': case 'CG1': case 'CG2': return 2; diff --git a/src/mol-model/loci.ts b/src/mol-model/loci.ts index 6b90c0221..64d264efd 100644 --- a/src/mol-model/loci.ts +++ b/src/mol-model/loci.ts @@ -262,9 +262,9 @@ namespace Loci { export type Granularity = keyof typeof Granularity export const GranularityOptions = ParamDefinition.objectToOptions(Granularity, k => { switch (k) { - case 'element': return'Atom/Coarse Element'; + case 'element': return 'Atom/Coarse Element'; case 'elementInstances': return ['Atom/Coarse Element Instances', 'With Symmetry']; - case 'structure': return'Structure/Shape'; + case 'structure': return 'Structure/Shape'; default: return k.indexOf('Instances') ? [stringToWords(k), 'With Symmetry'] : stringToWords(k); } diff --git a/src/mol-model/structure/structure/element/loci.ts b/src/mol-model/structure/structure/element/loci.ts index 083ea9baa..617f869a5 100644 --- a/src/mol-model/structure/structure/element/loci.ts +++ b/src/mol-model/structure/structure/element/loci.ts @@ -67,7 +67,7 @@ export namespace Loci { export function isEmpty(loci: Loci) { for (const u of loci.elements) { - if(OrderedSet.size(u.indices) > 0) return false; + if (OrderedSet.size(u.indices) > 0) return false; } return true; } diff --git a/src/mol-plugin-state/builder/structure/representation-preset.ts b/src/mol-plugin-state/builder/structure/representation-preset.ts index 119dd0f15..de9e8caf7 100644 --- a/src/mol-plugin-state/builder/structure/representation-preset.ts +++ b/src/mol-plugin-state/builder/structure/representation-preset.ts @@ -260,12 +260,12 @@ const coarseSurface = StructureRepresentationPresetProvider({ smoothness: 1, visuals: ['structure-gaussian-surface-mesh'] }); - } else if(size === Structure.Size.Huge) { + } else if (size === Structure.Size.Huge) { Object.assign(gaussianProps, { radiusOffset: structure.isCoarseGrained ? 2 : 0, smoothness: 1, }); - } else if(structure.isCoarseGrained) { + } else if (structure.isCoarseGrained) { Object.assign(gaussianProps, { radiusOffset: 2, smoothness: 1, diff --git a/src/mol-plugin-state/manager/loci-label.ts b/src/mol-plugin-state/manager/loci-label.ts index 1b7322cec..e36300411 100644 --- a/src/mol-plugin-state/manager/loci-label.ts +++ b/src/mol-plugin-state/manager/loci-label.ts @@ -48,7 +48,7 @@ export class LociLabelManager { if (idx === -1 && action === MarkerAction.Highlight) { this.locis.push(loci); this.isDirty = true; - } else if(idx !== -1 && action === MarkerAction.RemoveHighlight) { + } else if (idx !== -1 && action === MarkerAction.RemoveHighlight) { arrayRemoveAtInPlace(this.locis, idx); this.isDirty = true; } diff --git a/src/mol-plugin-ui/base.tsx b/src/mol-plugin-ui/base.tsx index fef08ba42..20047db2e 100644 --- a/src/mol-plugin-ui/base.tsx +++ b/src/mol-plugin-ui/base.tsx @@ -85,7 +85,7 @@ export abstract class CollapsableControls<P = {}, S = {}, SS = {}> extends Plugi } componentDidUpdate(prevProps: P & CollapsableProps) { - if(this.props.initiallyCollapsed !== undefined && prevProps.initiallyCollapsed !== this.props.initiallyCollapsed) { + if (this.props.initiallyCollapsed !== undefined && prevProps.initiallyCollapsed !== this.props.initiallyCollapsed) { this.setState({ isCollapsed: this.props.initiallyCollapsed as any }); } } 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 dd9e62b7a..b080af9cf 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 @@ -49,11 +49,11 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } this.state.points.sort((a, b) => { - if(a[0] === b[0]){ - if(a[0] === 0){ + if (a[0] === b[0]){ + if (a[0] === 0){ return a[1] - b[1]; } - if(a[1] === 1){ + if (a[1] === 1){ return b[1] - a[1]; } return a[1] - b[1]; @@ -128,7 +128,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } 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; } @@ -150,7 +150,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } private handleDrag(event: any) { - if(this.selected === undefined){ + if (this.selected === undefined){ return; } @@ -166,7 +166,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS 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))) { + } 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); @@ -197,7 +197,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS 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, }); @@ -209,11 +209,11 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS 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){ + if (a[0] === b[0]){ + if (a[0] === 0){ return a[1] - b[1]; } - if(a[1] === 1){ + if (a[1] === 1){ return b[1] - a[1]; } return a[1] - b[1]; @@ -238,7 +238,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS const points = this.state.points; const padding = this.padding / 2; - if(svgP.x < (padding) || + if (svgP.x < (padding) || svgP.x > (this.width + (padding)) || svgP.y > (this.height + (padding)) || svgP.y < (this.padding / 2)) { @@ -247,11 +247,11 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS const newPoint = this.unNormalizePoint(Vec2.create(svgP.x, svgP.y)); points.push(newPoint); points.sort((a, b) => { - if(a[0] === b[0]){ - if(a[0] === 0){ + if (a[0] === b[0]){ + if (a[0] === 0){ return a[1] - b[1]; } - if(a[1] === 1){ + if (a[1] === 1){ return b[1] - a[1]; } return a[1] - b[1]; @@ -263,14 +263,14 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } private deletePoint = (i: number) => (event: any) => { - if(i === 0 || i === this.state.points.length - 1){ return; } + 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){ + if (a[0] === b[0]){ + if (a[0] === 0){ return a[1] - b[1]; } - if(a[1] === 1){ + if (a[1] === 1){ return b[1] - a[1]; } return a[1] - b[1]; @@ -283,7 +283,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } private handleLeave() { - if(this.selected === undefined) { + if (this.selected === undefined) { return; } @@ -320,7 +320,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS } private refCallBack(element: any) { - if(element){ + if (element){ this.myRef = element; } } @@ -329,7 +329,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS 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} @@ -359,7 +359,7 @@ export class LineGraphComponent extends React.Component<any, LineGraphComponentS let normalizedY: number; let reverseY: number; - for(const point of this.state.points){ + for (const point of this.state.points){ min = this.padding / 2; maxX = this.width + min; maxY = this.height + min; diff --git a/src/mol-plugin-ui/controls/line-graph/point-component.tsx b/src/mol-plugin-ui/controls/line-graph/point-component.tsx index d3c752eea..94c2a1e79 100644 --- a/src/mol-plugin-ui/controls/line-graph/point-component.tsx +++ b/src/mol-plugin-ui/controls/line-graph/point-component.tsx @@ -29,7 +29,7 @@ export class PointComponent extends React.Component<any, {show: boolean}> { } public render() { - return([ + return ([ <circle r="10" key={`${this.props.id}circle`} diff --git a/src/mol-plugin-ui/structure/focus.tsx b/src/mol-plugin-ui/structure/focus.tsx index a5ab8d5f2..1aa66ec00 100644 --- a/src/mol-plugin-ui/structure/focus.tsx +++ b/src/mol-plugin-ui/structure/focus.tsx @@ -77,7 +77,7 @@ function getFocusEntries(structure: Structure) { for (let i = 0, il = u.elements.length; i < il; ++i) { const eI = u.elements[i]; const rI = residueIndex[eI]; - if(rI !== prev) { + if (rI !== prev) { l.element = eI; addSymmetryGroupEntries(entityEntries, l, ug, 'residue'); prev = rI; diff --git a/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts b/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts index 44cd1568f..10a12d4c8 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts @@ -69,7 +69,7 @@ export const AccessibleSurfaceArea = PluginBehavior.create<{ autoAttach: boolean // function accessibleSurfaceAreaLabel(loci: Loci): string | undefined { - if(loci.kind === 'element-loci') { + if (loci.kind === 'element-loci') { if (loci.elements.length === 0) return; const accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(loci.structure).value; @@ -96,7 +96,7 @@ function accessibleSurfaceAreaLabel(loci: Loci): string | undefined { return `Accessible Surface Area ${residueCount}: ${cummulativeArea.toFixed(2)} \u212B<sup>2</sup>`; - } else if(loci.kind === 'structure-loci') { + } else if (loci.kind === 'structure-loci') { const accessibleSurfaceArea = AccessibleSurfaceAreaProvider.get(loci.structure).value; if (!accessibleSurfaceArea || loci.structure.customPropertyDescriptors.hasReference(AccessibleSurfaceAreaProvider.descriptor)) return; diff --git a/src/mol-plugin/behavior/dynamic/custom-props/sequence/best-database-mapping.ts b/src/mol-plugin/behavior/dynamic/custom-props/sequence/best-database-mapping.ts index 186ba57f0..9336cf6ac 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/sequence/best-database-mapping.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/sequence/best-database-mapping.ts @@ -58,7 +58,7 @@ export const BestDatabaseSequenceMapping = PluginBehavior.create<{ autoAttach: b // function bestDatabaseSequenceMappingLabel(loci: Loci): string | undefined { - if(loci.kind === 'element-loci') { + if (loci.kind === 'element-loci') { if (loci.elements.length === 0) return; const e = loci.elements[0]; diff --git a/src/mol-plugin/util/toast.ts b/src/mol-plugin/util/toast.ts index 7aa3d02cb..977b1155a 100644 --- a/src/mol-plugin/util/toast.ts +++ b/src/mol-plugin/util/toast.ts @@ -85,7 +85,7 @@ export class PluginToastManager extends StatefulPluginComponent<{ private hide(e: PluginToastManager.Entry | undefined) { if (!e) return; if (e.timeout !== void 0) clearTimeout(e.timeout); - e.hide = <any>void 0; + e.hide = <any> void 0; if (this.updateState({ entries: this.state.entries.delete(e.id) })) this.events.changed.next(void 0); } diff --git a/src/mol-repr/shape/representation.ts b/src/mol-repr/shape/representation.ts index af0b769ee..2ad1cf89d 100644 --- a/src/mol-repr/shape/representation.ts +++ b/src/mol-repr/shape/representation.ts @@ -217,7 +217,7 @@ export function ShapeRepresentation<D, G extends Geometry, P extends Geometry.Pa Representation.updateState(_state, state); }, setTheme(theme: Theme) { - if(isDebugMode) { + if (isDebugMode) { console.warn('The `ShapeRepresentation` theme is fixed to `ShapeGroupColorTheme` and `ShapeGroupSizeTheme`. Colors are taken from `Shape.getColor` and sizes from `Shape.getSize`'); } }, diff --git a/src/mol-repr/structure/visual/bond-inter-unit-line.ts b/src/mol-repr/structure/visual/bond-inter-unit-line.ts index f31a76652..5578b8011 100644 --- a/src/mol-repr/structure/visual/bond-inter-unit-line.ts +++ b/src/mol-repr/structure/visual/bond-inter-unit-line.ts @@ -75,7 +75,7 @@ function createInterUnitBondLines(ctx: VisualContext, structure: Structure, them return LinkStyle.Dashed; } else if (o === 3) { return LinkStyle.Triple; - }else if (aromaticBonds && BondType.is(f, BondType.Flag.Aromatic)) { + } else if (aromaticBonds && BondType.is(f, BondType.Flag.Aromatic)) { return LinkStyle.Aromatic; } else if (o === 2) { return LinkStyle.Double; diff --git a/src/mol-repr/structure/visual/util/bond.ts b/src/mol-repr/structure/visual/util/bond.ts index 983a7612a..5e2ddafd6 100644 --- a/src/mol-repr/structure/visual/util/bond.ts +++ b/src/mol-repr/structure/visual/util/bond.ts @@ -100,7 +100,7 @@ export function makeInterBondIgnoreTest(structure: Structure, props: BondProps): const b = edges[edgeIndex]; const uA = structure.unitMap.get(b.unitA); const uB = structure.unitMap.get(b.unitB); - if(isHydrogen(uA, uA.elements[b.indexA]) || isHydrogen(uB, uB.elements[b.indexB])) return true; + if (isHydrogen(uA, uA.elements[b.indexA]) || isHydrogen(uB, uB.elements[b.indexB])) return true; } if (!allBondTypes) { 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 d8561b58f..e191b3c01 100644 --- a/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts +++ b/src/mol-repr/structure/visual/util/polymer/trace-iterator.ts @@ -289,7 +289,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> Vec3.copy(this.p0, this.p3); Vec3.copy(this.p1, this.p3); Vec3.copy(this.p2, this.p3); - } else if(isHelixPrev1) { + } else if (isHelixPrev1) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p2, this.p3), 2); Vec3.add(this.p2, this.p3, tmpDir); Vec3.add(this.p1, this.p2, tmpDir); @@ -299,7 +299,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> if (isHelix) { Vec3.copy(this.p0, this.p2); Vec3.copy(this.p1, this.p2); - } else if(isHelixPrev2) { + } else if (isHelixPrev2) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p1, this.p2), 2); Vec3.add(this.p1, this.p2, tmpDir); Vec3.add(this.p0, this.p1, tmpDir); @@ -307,7 +307,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> } else if (isHelix !== isHelixPrev3) { if (isHelix) { Vec3.copy(this.p0, this.p1); - } else if(isHelixPrev3) { + } else if (isHelixPrev3) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p0, this.p1), 2); Vec3.add(this.p0, this.p1, tmpDir); } @@ -318,7 +318,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> Vec3.copy(this.p4, this.p3); Vec3.copy(this.p5, this.p3); Vec3.copy(this.p6, this.p3); - } else if(isHelixNext1) { + } else if (isHelixNext1) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p4, this.p3), 2); Vec3.add(this.p4, this.p3, tmpDir); Vec3.add(this.p5, this.p4, tmpDir); @@ -328,7 +328,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> if (isHelix) { Vec3.copy(this.p5, this.p4); Vec3.copy(this.p6, this.p4); - } else if(isHelixNext2) { + } else if (isHelixNext2) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p5, this.p4), 2); Vec3.add(this.p5, this.p4, tmpDir); Vec3.add(this.p6, this.p5, tmpDir); @@ -336,7 +336,7 @@ export class AtomicPolymerTraceIterator implements Iterator<PolymerTraceElement> } else if (isHelix !== isHelixNext3) { if (isHelix) { Vec3.copy(this.p6, this.p5); - } else if(isHelixNext3) { + } else if (isHelixNext3) { Vec3.scale(tmpDir, Vec3.sub(tmpDir, this.p6, this.p5), 2); Vec3.add(this.p6, this.p5, tmpDir); } diff --git a/src/mol-repr/volume/direct-volume.ts b/src/mol-repr/volume/direct-volume.ts index d4a7bfcec..042219514 100644 --- a/src/mol-repr/volume/direct-volume.ts +++ b/src/mol-repr/volume/direct-volume.ts @@ -35,7 +35,7 @@ function getBoundingBox(gridDimension: Vec3, transform: Mat4) { export function createDirectVolume2d(ctx: RuntimeContext, webgl: WebGLContext, volume: Volume, directVolume?: DirectVolume) { const gridDimension = volume.grid.cells.space.dimensions as Vec3; const { width, height } = getVolumeTexture2dLayout(gridDimension); - if(Math.max(width, height) > webgl.maxTextureSize / 2) { + if (Math.max(width, height) > webgl.maxTextureSize / 2) { throw new Error('volume too large for direct-volume rendering'); } @@ -77,7 +77,7 @@ function getUnitToCartn(grid: Grid) { export function createDirectVolume3d(ctx: RuntimeContext, webgl: WebGLContext, volume: Volume, directVolume?: DirectVolume) { const gridDimension = volume.grid.cells.space.dimensions as Vec3; - if(Math.max(...gridDimension) > webgl.max3dTextureSize / 2) { + if (Math.max(...gridDimension) > webgl.max3dTextureSize / 2) { throw new Error('volume too large for direct-volume rendering'); } diff --git a/src/mol-util/data-source.ts b/src/mol-util/data-source.ts index 609d1a9d5..794c2e4d4 100644 --- a/src/mol-util/data-source.ts +++ b/src/mol-util/data-source.ts @@ -247,7 +247,7 @@ function processAjax<T extends DataType>(req: XMLHttpRequest, type: T): DataResp } function getRequestResponseType(type: DataType): XMLHttpRequestResponseType { - switch(type) { + switch (type) { case 'json': return 'json'; case 'xml': return 'document'; case 'string': return 'text'; diff --git a/src/mol-util/zip/bin.ts b/src/mol-util/zip/bin.ts index a1a175389..38111eff9 100644 --- a/src/mol-util/zip/bin.ts +++ b/src/mol-util/zip/bin.ts @@ -35,7 +35,7 @@ export function writeUint(buff: Uint8Array, p: number, n: number) { 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,10 +49,10 @@ 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) { + } catch (e) { return readASCII(buff, p, l); } return ns; @@ -61,21 +61,21 @@ 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) { + if ((code & (0xffffffff - (1 << 7) + 1)) === 0) { buff[p + i] = (code); i++; - } else if((code & (0xffffffff - (1 << 11) + 1)) === 0) { + } 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) { + } 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) { + } 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)); @@ -89,15 +89,15 @@ export function writeUTF8(buff: Uint8Array, p: number, str: string) { export function sizeUTF8(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) { i++ ; - } else if((code & (0xffffffff - (1 << 11) + 1)) === 0) { + } else if ((code & (0xffffffff - (1 << 11) + 1)) === 0) { i += 2; - } else if((code & (0xffffffff - (1 << 16) + 1)) === 0) { + } else if ((code & (0xffffffff - (1 << 16) + 1)) === 0) { i += 3; - } else if((code & (0xffffffff - (1 << 21) + 1)) === 0) { + } else if ((code & (0xffffffff - (1 << 21) + 1)) === 0) { i += 4; } else { throw new Error('e'); diff --git a/src/mol-util/zip/checksum.ts b/src/mol-util/zip/checksum.ts index 2ea3851a4..5bfaa03f3 100644 --- a/src/mol-util/zip/checksum.ts +++ b/src/mol-util/zip/checksum.ts @@ -35,9 +35,9 @@ export function adler(data: Uint8Array, o: number, len: number) { let a = 1, b = 0; let off = o; const end = o + len; - while(off < end) { + while (off < end) { const eend = Math.min(off + 5552, end); - while(off < eend) { + while (off < eend) { a += data[off++]; b += a; } diff --git a/src/mol-util/zip/deflate.ts b/src/mol-util/zip/deflate.ts index 498f6e463..217f92993 100644 --- a/src/mol-util/zip/deflate.ts +++ b/src/mol-util/zip/deflate.ts @@ -45,19 +45,19 @@ function deflateChunk(ctx: DeflateContext, count: number) { const end = Math.min(i + count, dlen); - for(; i < end; i++) { + for (; i < end; i++) { c = nc; - if(i + 1 < dlen - 2) { + if (i + 1 < dlen - 2) { nc = _hash(data, i + 1); const ii = ((i + 1) & 0x7fff); prev[ii] = strt[nc]; strt[nc] = ii; } - if(cvrd <= i) { - if((li > 14000 || lc > 26697) && (dlen - i) > 100) { - if(cvrd < i) { + if (cvrd <= i) { + if ((li > 14000 || lc > 26697) && (dlen - i) > 100) { + if (cvrd < i) { lits[li] = i - cvrd; li += 2; cvrd = i; @@ -68,11 +68,11 @@ function deflateChunk(ctx: DeflateContext, count: number) { } let mch = 0; - if(i < dlen - 2) { + if (i < dlen - 2) { mch = _bestMatch(data, i, prev, c, Math.min(opt[2], dlen - i), opt[3]); } - if(mch !== 0) { + if (mch !== 0) { const len = mch >>> 16, dst = mch & 0xffff; 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]; @@ -120,10 +120,10 @@ export async function _deflateRaw(runtime: RuntimeContext, data: Uint8Array, out const ctx = DeflateContext(data, out, opos, lvl); const { dlen } = ctx; - if(lvl === 0) { + if (lvl === 0) { let { i, pos } = ctx; - while(i < dlen) { + while (i < dlen) { const len = Math.min(0xffff, dlen - i); _putsE(out, pos, (i + len === dlen ? 1 : 0)); pos = _copyExact(data, i, len, out, pos + 8); @@ -132,7 +132,7 @@ export async function _deflateRaw(runtime: RuntimeContext, data: Uint8Array, out return pos >>> 3; } - if(dlen > 2) { + if (dlen > 2) { ctx.nc = _hash(data, 0); ctx.strt[ctx.nc] = 0; } @@ -147,15 +147,15 @@ export async function _deflateRaw(runtime: RuntimeContext, data: Uint8Array, out let { li, cvrd, pos } = ctx; const { i, lits, bs, ebits } = ctx; - if(bs !== i || data.length === 0) { - if(cvrd < i) { + if (bs !== i || data.length === 0) { + if (cvrd < i) { lits[li] = i - cvrd; li += 2; cvrd = i; } pos = _writeBlock(1, lits, li, ebits, data, bs, i - bs, out, pos); } - while((pos & 7) !== 0) pos++; + while ((pos & 7) !== 0) pos++; return pos >>> 3; } @@ -163,21 +163,21 @@ function _bestMatch(data: Uint8Array, i: number, prev: Uint16Array, c: number, n 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; + 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++) { + 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; } + if (curd > maxd) { maxd = curd; pi = ei; } } } } @@ -189,11 +189,11 @@ function _bestMatch(data: Uint8Array, i: number, prev: Uint16Array, c: number, n } 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; + 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++; + while (i < l && data[i] === data[i - dif]) i++; return i - oi; } @@ -217,9 +217,9 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe 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); _putsF(out, pos, BFINAL); @@ -227,14 +227,14 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe pos += 3; // let opos = pos; - if(BTYPE === 0) { - while((pos & 7) !== 0) pos++; + if (BTYPE === 0) { + while ((pos & 7) !== 0) pos++; pos = _copyExact(data, o0, l0, out, pos); } else { let ltree: number[], dtree: number[]; - if(BTYPE === 1) { + if (BTYPE === 1) { ltree = U.fltree; dtree = U.fdtree; - } else if(BTYPE === 2) { + } else if (BTYPE === 2) { makeCodes(U.ltree, ML); revCodes(U.ltree, ML); makeCodes(U.dtree, MD); revCodes(U.dtree, MD); makeCodes(U.itree, MH); revCodes(U.itree, MH); @@ -245,7 +245,7 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe _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]); + 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); @@ -254,11 +254,11 @@ function _writeBlock(BFINAL: number, lits: Uint32Array, li: number, ebits: numbe } let off = o0; - for(let si = 0; si < li; si += 2) { + 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); + while (off < end) pos = _writeLit(data[off++], ltree, out, pos); - if(len !== 0) { + 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]; @@ -298,26 +298,26 @@ 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]; + 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) { + 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; } @@ -328,19 +328,19 @@ 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) { + 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) { + if (l === 0 && nxt === l && nnxt === l) { let lz = i + 5; - while(lz + 2 < len && tree[lz + 2] === l) lz += 2; + 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); + 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) { + } else if (l === prv && nxt === l && nnxt === l) { let lz = i + 5; - while(lz + 2 < len && tree[lz + 2] === l) lz += 2; + 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; @@ -353,11 +353,11 @@ function _lenCodes(tree: number[], set: number[]) { 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; + 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; } diff --git a/src/mol-util/zip/huffman.ts b/src/mol-util/zip/huffman.ts index 16d5263b4..6caf1f974 100644 --- a/src/mol-util/zip/huffman.ts +++ b/src/mol-util/zip/huffman.ts @@ -19,14 +19,14 @@ 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) { + 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 }); + 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) { + 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; @@ -41,13 +41,13 @@ 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)) { + while (i1 !== end - 1) { + if (i0 !== i1 && (i2 === end || list[i0].f < list[i2].f)) { a = list[i0++]; } else { a = list[i2++]; } - if(i0 !== i1 && (i2 === end || list[i0].f < list[i2].f)) { + if (i0 !== i1 && (i2 === end || list[i0].f < list[i2].f)) { b = list[i0++]; } else { b = list[i2++]; @@ -61,16 +61,16 @@ export function _hufTree(hst: NumberArray, tree: number[], MAXL: number) { }; } let maxl = setDepth(list[i1 - 1], 0); - if(maxl > MAXL) { + 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; } function setDepth(t: HufTree, d: number): number { - if(t.lit !== -1) { + if (t.lit !== -1) { t.d = d; return d; } @@ -82,8 +82,8 @@ function restrictDepth(dps: HufTree[], MD: number, maxl: number) { const bCost = 1 << (maxl - MD); 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) { + 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)); @@ -92,20 +92,20 @@ function restrictDepth(dps: HufTree[], MD: number, maxl: number) { } } dbt = dbt >>> (maxl - MD); - while(dbt > 0) { + while (dbt > 0) { const od = dps[i].d; - if(od < MD) { + if (od < MD) { dps[i].d++; 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++; } } - if(dbt !== 0) console.log('debt left'); + if (dbt !== 0) console.log('debt left'); } \ No newline at end of file diff --git a/src/mol-util/zip/inflate.ts b/src/mol-util/zip/inflate.ts index 0428a24f6..145a01c6e 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, @@ -31,7 +31,7 @@ function inflateBlocks(ctx: InflateContext, count: number) { let iBlock = 0; - while(BFINAL === 0 && iBlock < count) { + while (BFINAL === 0 && iBlock < count) { let lmap, dmap; let ML = 0, MD = 0; @@ -40,12 +40,12 @@ function inflateBlocks(ctx: InflateContext, count: number) { const BTYPE = _bitsF(data, pos + 1, 2); pos += 3; - if(BTYPE === 0) { + if (BTYPE === 0) { // uncompressed block - if((pos & 7) !== 0) pos += 8 - (pos & 7); + 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 (noBuf) buf = _check(buf, off + len); buf.set(new Uint8Array(data.buffer, data.byteOffset + p8, len), off); pos = ((p8 + len) << 3); off += len; @@ -53,30 +53,30 @@ function inflateBlocks(ctx: InflateContext, count: number) { } // 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) { + if (BTYPE === 1) { // block compressed with fixed Huffman codes lmap = U.flmap; dmap = U.fdmap; ML = (1 << 9) - 1; MD = (1 << 5) - 1; - } else if(BTYPE === 2) { + } else if (BTYPE === 2) { // block compressed with dynamic Huffman codes const HLIT = _bitsE(data, pos, 5) + 257; const HDIST = _bitsE(data, pos + 5, 5) + 1; const HCLEN = _bitsE(data, pos + 10, 4) + 4; pos += 14; - for(let i = 0; i < 38; i += 2) { + 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++) { + 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; + if (l > tl) tl = l; } pos += 3 * HCLEN; makeCodes(U.itree, tl); @@ -99,17 +99,17 @@ function inflateBlocks(ctx: InflateContext, count: number) { throw new Error(`unknown BTYPE ${BTYPE}`); } - while(true) { + while (true) { const code = lmap[_get17(data, pos) & ML]; pos += code & 15; const lit = code >>> 4; - if((lit >>> 8) === 0) { + if ((lit >>> 8) === 0) { buf[off++] = lit; - } else if(lit === 256) { + } else if (lit === 256) { break; } else { let end = off + lit - 254; - if(lit > 264) { + if (lit > 264) { const ebs = U.ldef[lit - 257]; end = off + (ebs >>> 3) + _bitsE(data, pos, ebs & 7); pos += ebs & 7; @@ -122,8 +122,8 @@ function inflateBlocks(ctx: InflateContext, count: number) { const dst = (dbs >>> 4) + _bitsF(data, pos, dbs & 15); pos += dbs & 15; - if(noBuf) buf = _check(buf, off + (1 << 17)); - while(off < end) { + 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]; @@ -142,10 +142,10 @@ function inflateBlocks(ctx: InflateContext, count: number) { // https://tools.ietf.org/html/rfc1951 export async function _inflate(runtime: RuntimeContext, data: Uint8Array, buf?: Uint8Array) { - if(data[0] === 3 && data[1] === 0) return (buf ? buf : new Uint8Array(0)); + if (data[0] === 3 && data[1] === 0) return (buf ? buf : new Uint8Array(0)); const ctx = InflateContext(data, buf); - while(ctx.BFINAL === 0) { + while (ctx.BFINAL === 0) { if (runtime.shouldUpdate) { await runtime.update({ message: 'Inflating blocks...', current: ctx.pos, max: data.length }); } @@ -156,7 +156,7 @@ export async function _inflate(runtime: RuntimeContext, data: Uint8Array, buf?: function _check(buf: Uint8Array, len: number) { const bl = buf.length; - if(len <= bl) return buf; + if (len <= bl) return buf; const nbuf = new Uint8Array(Math.max(bl << 1, len)); nbuf.set(buf, 0); return nbuf; @@ -164,28 +164,28 @@ 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) { + while (i < len) { const code = lmap[_get17(data, pos) & LL]; pos += code & 15; const lit = code >>> 4; - if(lit <= 15) { + if (lit <= 15) { tree[i] = lit; i++; } else { let ll = 0, n = 0; - if(lit === 16) { + if (lit === 16) { n = (3 + _bitsE(data, pos, 2)); pos += 2; ll = tree[i - 1]; - } else if(lit === 17) { + } else if (lit === 17) { n = (3 + _bitsE(data, pos, 3)); pos += 3; - } else if(lit === 18) { + } else if (lit === 18) { n = (11 + _bitsE(data, pos, 7)); pos += 7; } const ni = i + n; - while(i < ni) { + while (i < ni) { tree[i] = ll; i++; } @@ -197,14 +197,14 @@ 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; - while(i < len) { + while (i < len) { const v = src[i + off]; tree[(i << 1)] = 0; tree[(i << 1) + 1] = v; - if(v > mx)mx = v; + if (v > mx)mx = v; i++; } - while(i < tl) { + while (i < tl) { tree[(i << 1)] = 0; tree[(i << 1) + 1] = 0; i++; diff --git a/src/mol-util/zip/util.ts b/src/mol-util/zip/util.ts index f9b4eb732..f5eec31fd 100644 --- a/src/mol-util/zip/util.ts +++ b/src/mol-util/zip/util.ts @@ -35,7 +35,7 @@ export const U = (function (){ (function (){ const len = 1 << 15; - for(let i = 0; i < len; i++) { + for (let i = 0; i < len; i++) { let x = i; x = (((x & 0xaaaaaaaa) >>> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >>> 2) | ((x & 0x33333333) << 2)); @@ -45,10 +45,10 @@ export const U = (function (){ } function pushV(tgt: number[], n: number, sv: number) { - while(n-- !== 0) tgt.push(0, sv); + while (n-- !== 0) tgt.push(0, sv); } - for(let i = 0; i < 32; 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]; } @@ -86,15 +86,15 @@ 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) { + 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) { + while (i0 !== i1) { const p0 = r15[i0] >>> (15 - MAX_BITS); map[p0] = val; i0++; } @@ -106,8 +106,8 @@ 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 @@ -129,7 +129,7 @@ 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) { + for (let i = 0; i < tree.length; i += 2) { const i0 = (tree[i] << (MAX_BITS - tree[i + 1])); tree[i] = r15[i0] >>> imb; } diff --git a/src/mol-util/zip/zip.ts b/src/mol-util/zip/zip.ts index 173cd9f90..b81bccf49 100644 --- a/src/mol-util/zip/zip.ts +++ b/src/mol-util/zip/zip.ts @@ -20,7 +20,7 @@ export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames const data = new Uint8Array(buf); let eocd = data.length - 4; - while(readUint(data, eocd) !== 0x06054b50) eocd--; + while (readUint(data, eocd) !== 0x06054b50) eocd--; let o = eocd; o += 4; // sign = 0x06054b50 @@ -35,7 +35,7 @@ export async function unzip(runtime: RuntimeContext, buf: ArrayBuffer, onlyNames 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; @@ -93,15 +93,15 @@ async function _readLocal(runtime: RuntimeContext, data: Uint8Array, o: number, o += nlen; // console.log(name); o += elen; - if(onlyNames) { + if (onlyNames) { out[name] = { size: usize, csize }; return; } const file = new Uint8Array(data.buffer, o); - if(cmpr === 0) { + if (cmpr === 0) { out[name] = new Uint8Array(file.buffer.slice(o, o + csize)); - } else if(cmpr === 8) { + } else if (cmpr === 8) { const buf = new Uint8Array(usize); await inflateRaw(runtime, file, buf); out[name] = buf; @@ -141,14 +141,14 @@ export async function ungzip(runtime: RuntimeContext, file: Uint8Array, buf?: Ui } if (flg & 8) { // FNAME let zero = o; - while(file[zero] !== 0) ++zero; + while (file[zero] !== 0) ++zero; // const name = readUTF8(file, o, zero - o) // console.log('FNAME', name, zero - o) o = zero + 1; } if (flg & 16) { // FCOMMENT let zero = o; - while(file[zero] !== 0) ++zero; + while (file[zero] !== 0) ++zero; // const comment = readUTF8(file, o, zero - o) // console.log('FCOMMENT', comment) o = zero + 1; @@ -175,7 +175,7 @@ export async function ungzip(runtime: RuntimeContext, file: Uint8Array, buf?: Ui } export async function deflate(runtime: RuntimeContext, data: Uint8Array, opts?: { level: number }/* , buf, off*/) { - if(opts === undefined) opts = { level: 6 }; + 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; @@ -189,7 +189,7 @@ export async function deflate(runtime: RuntimeContext, data: Uint8Array, opts?: } async function deflateRaw(runtime: RuntimeContext, data: Uint8Array, opts?: { level: number }) { - if(opts === undefined) opts = { level: 6 }; + if (opts === undefined) opts = { level: 6 }; const buf = new Uint8Array(50 + Math.floor(data.length * 1.1)); const off = await _deflateRaw(runtime, data, buf, 0, opts.level); return new Uint8Array(buf.buffer, 0, off); @@ -202,7 +202,7 @@ export function Zip(obj: { [k: string]: Uint8Array }, noCmpr = false) { export async function zip(runtime: RuntimeContext, obj: { [k: string]: Uint8Array }, noCmpr = false) { let tot = 0; const zpd: { [k: string]: { cpr: boolean, usize: number, crc: number, file: Uint8Array } } = {}; - for(const p in obj) { + for (const p in obj) { const cpr = !_noNeed(p) && !noCmpr, buf = obj[p]; const crcValue = crc(buf, 0, buf.length); zpd[p] = { @@ -213,20 +213,20 @@ export async function zip(runtime: RuntimeContext, obj: { [k: string]: Uint8Arra }; } - for(const p in zpd) tot += zpd[p].file.length + 30 + 46 + 2 * sizeUTF8(p); + for (const p in zpd) tot += zpd[p].file.length + 30 + 46 + 2 * sizeUTF8(p); tot += 22; const data = new Uint8Array(tot); let o = 0; const fof = []; - for(const p in zpd) { + for (const p in zpd) { const file = zpd[p]; fof.push(o); o = _writeHeader(data, o, p, file, 0); } let i = 0; const ioff = o; - for(const p in zpd) { + for (const p in zpd) { const file = zpd[p]; fof.push(o); o = _writeHeader(data, o, p, file, 1, fof[i++]); @@ -253,7 +253,7 @@ function _writeHeader(data: Uint8Array, o: number, p: string, obj: { cpr: boolea const file = obj.file; writeUint(data, o, t === 0 ? 0x04034b50 : 0x02014b50); o += 4; // sign - if(t === 1) o += 2; // ver made by + 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 @@ -266,14 +266,14 @@ function _writeHeader(data: Uint8Array, o: number, p: string, obj: { cpr: boolea writeUshort(data, o, sizeUTF8(p)); o += 2; // nlen writeUshort(data, o, 0); o += 2; // elen - if(t === 1) { + if (t === 1) { o += 2; // comment length o += 2; // disk number o += 6; // attributes writeUint(data, o, roff); o += 4; // usize } const nlen = writeUTF8(data, o, p); o += nlen; - if(t === 0) { + if (t === 0) { data.set(file, o); o += file.length; } diff --git a/src/servers/model/server/query.ts b/src/servers/model/server/query.ts index 1fe8899a9..fc502db27 100644 --- a/src/servers/model/server/query.ts +++ b/src/servers/model/server/query.ts @@ -166,7 +166,7 @@ async function resolveMultiFile(job: Job) { encoder.startDataBlock(structure.cifFrame.header); hasDataBlock = true; await resolveJobEntry(entry, structure, encoder); - } catch(e) { + } catch (e) { if (!hasDataBlock) { header = createErrorDataBlock(entry, encoder); } -- GitLab