Skip to content

Commit

Permalink
Fix spacing in several other files
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaifroid committed Nov 13, 2023
1 parent 6f51226 commit 26078c0
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 72 deletions.
3 changes: 1 addition & 2 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2399,8 +2399,7 @@ function goToMainArticle () {
'<a href="https://pwa.kiwix.org" target="_blank">https://pwa.kiwix.org</a>.</p>' +
'<p>Alternatively, you can use Kiwix Serve to serve this archive to your browser from localhost. ' +
'Kiwix Serve is included with <a href="https://www.kiwix.org/applications/" target="_blank">Kiwix Desktop</a>.</p>',
translateUI.t('dialog-unsupported-archivetype-title') || 'Unsupported archive type!'
);
translateUI.t('dialog-unsupported-archivetype-title') || 'Unsupported archive type!');
document.getElementById('searchingArticles').style.display = 'none';
document.getElementById('welcomeText').style.display = '';
} else {
Expand Down
53 changes: 26 additions & 27 deletions www/js/lib/arrayFromPolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,33 @@
* Simple Array.from polyfill (with Set support) from https://stackoverflow.com/a/62682524/9727685
*/
(function () {
function arrayFrom (arr, callbackFn, thisArg) {
// if you need you can uncomment the following line
// if(!arr || typeof arr == 'function')throw new Error('This function requires an array-like object - not null, undefined or a function');

function arrayFrom(arr, callbackFn, thisArg) {
//if you need you can uncomment the following line
//if(!arr || typeof arr == 'function')throw new Error('This function requires an array-like object - not null, undefined or a function');
var arNew = [];
var k = []; // used for convert Set to an Array
var i = 0;
var v;

var arNew = [],
k = [], // used for convert Set to an Array
i = 0,
v;
// if you do not need a Set object support then
// you can comment or delete the following if statement
if (window.Set && arr instanceof Set) {
// we use forEach from Set object
arr.forEach(function (v) {
k.push(v)
});
arr = k;
}

//if you do not need a Set object support then
//you can comment or delete the following if statement
if (window.Set && arr instanceof Set) {
//we use forEach from Set object
arr.forEach(function (v) {
k.push(v)
});
arr = k;
}
for (; i < (arr.length || arr.size); i++) {
v = typeof arr[i] !== 'undefined' ? arr[i] : arr.get ? arr.get(i) : null;
arNew[i] = callbackFn
? callbackFn.call(thisArg, v, i, arr) : v;
}

for (; i < (arr.length || arr.size); i++) {
v = typeof arr[i] !== 'undefined' ? arr[i] : arr.get ? arr.get(i) : null;
arNew[i] = callbackFn ?
callbackFn.call(thisArg, v, i, arr) : v;
}

return arNew;
}
//You could also use it without the following line, but it is not recommended because native function is faster.
Array.from = Array.from || arrayFrom; //We set it as polyfill
}());
return arNew;
}
// You could also use it without the following line, but it is not recommended because native function is faster.
Array.from = Array.from || arrayFrom; // We set it as polyfill
}());
2 changes: 1 addition & 1 deletion www/js/lib/filecache.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ var read = function (file, begin, end) {

export default {
read: read
};
};
2 changes: 1 addition & 1 deletion www/js/lib/settingsStore.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

/* global define, params */
/* global params */

var regexpCookieKeysToMigrate = new RegExp([
'hideActiveContentWarning', 'showUIAnimations', 'appTheme', 'useCache',
Expand Down
2 changes: 1 addition & 1 deletion www/js/lib/utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ utf8.parse = function (data, zeroTerminated) {
export default {
toByteArray: utf8.toByteArray,
parse: utf8.parse
};
};
37 changes: 20 additions & 17 deletions www/js/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

'use strict';

/* eslint-disable indent */
/* eslint-disable one-var */

var regExpFindStringParts = /(?:^|.+?)(?:[\s$£\uFFE5^+=`~<>{}[\]|\u3000-\u303F!-#%-\x2A,-/:;\x3F@\x5B-\x5D_\x7B}\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]+|$)/g;

/**
Expand Down Expand Up @@ -198,29 +201,29 @@ function leftShift (int, bits) {
* @param {Integer} nChr Numerical character code
* @returns {Integer} Converted character code
*/
function b64ToUint6(nChr) {
return nChr > 64 && nChr < 91 ?
nChr - 65 :
nChr > 96 && nChr < 123 ?
nChr - 71 :
nChr > 47 && nChr < 58 ?
nChr + 4 :
nChr === 43 ?
62 :
nChr === 47 ?
63 :
0;
function b64ToUint6 (nChr) {
return nChr > 64 && nChr < 91
? nChr - 65
: nChr > 96 && nChr < 123
? nChr - 71
: nChr > 47 && nChr < 58
? nChr + 4
: nChr === 43
? 62
: nChr === 47
? 63
: 0;
}

/**
* Recommended rewrite of the faulty .btoa() function in JavaScript because of the problem with UTF-8-encoded data
* From https://developer.mozilla.org/en-US/docs/Glossary/Base64
* @param {String} sBase64 Base 64 encoded string
* @param {String} sBase64 Base 64 encoded string
* @param {Integer} nBlocksSize Optional block size
* @returns {Uint8Array} A Uint8Array containing the converted data
*/
function base64DecToArr(sBase64, nBlocksSize) {
var sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""),
function base64DecToArr (sBase64, nBlocksSize) {
var sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ''),
nInLen = sB64Enc.length,
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2,
taBytes = new Uint8Array(nOutLen);
Expand All @@ -242,7 +245,7 @@ function base64DecToArr(sBase64, nBlocksSize) {
* @param {String} dataURI The data URI to convert
* @returns {Uint8Array} A Uint8Array with the converted buffer
*/
function dataURItoUint8Array(dataURI) {
function dataURItoUint8Array (dataURI) {
var parsedString = dataURI.match(/^data:([^,]*),(.*)/i);
if (parsedString && /base64/i.test(parsedString[1])) {
return base64DecToArr(parsedString[2]);
Expand Down Expand Up @@ -282,7 +285,7 @@ var PromiseQueue = {
return new Promise(function (resolve, reject) {
// Don't allow more than four dialogues to queue up
if (that._queue.length >= 4) reject(new Error('PromiseQueue: queue length exceeded'));
else that._queue.push({promise: promiseFactory, resolve: resolve, reject: reject});
else that._queue.push({ promise: promiseFactory, resolve: resolve, reject: reject });
if (!that._working) that._dequeue();
});
},
Expand Down
45 changes: 22 additions & 23 deletions www/js/lib/xzdec_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
'use strict';

/* global self, params */

import uiUtil from './uiUtil.js';
import XZASM from './xzdec-asm.js';
import XZWASM from './xzdec-wasm.js';
Expand Down Expand Up @@ -64,13 +66,14 @@ if (XZMachineType === 'WASM') {
params.decompressorAPI.assemblerMachineType = XZMachineType;
xzdec = instance;
}).catch(function (err) {
console.warn('WASM xz decoder failed to load, falling back to ASM', err);
XZMachineType = 'ASM';
loadASM();
});
});
} else {
loadASM();
};

/**
* Number of milliseconds to wait for the decompressor to be available for another chunk
* @type Integer
Expand Down Expand Up @@ -99,7 +102,7 @@ var busy = false;
* @param {Integer} chunkSize
* @returns {Decompressor}
*/
function Decompressor(reader, chunkSize) {
function Decompressor (reader, chunkSize) {
params.decompressorAPI.decompressorLastUsed = 'XZ';
this._chunkSize = chunkSize || 1024 * 5;
this._reader = reader;
Expand All @@ -111,15 +114,15 @@ function Decompressor(reader, chunkSize) {
* @param {Integer} offset
* @param {Integer} length
*/
Decompressor.prototype.readSlice = function(offset, length) {
Decompressor.prototype.readSlice = function (offset, length) {
busy = true;
var that = this;
this._inStreamPos = 0;
this._outStreamPos = 0;
this._decHandle = xzdec._init_decompression(this._chunkSize);
this._outBuffer = new Int8Array(new ArrayBuffer(length));
this._outBufferPos = 0;
return this._readLoop(offset, length).then(function(data) {
return this._readLoop(offset, length).then(function (data) {
xzdec._release(that._decHandle);
busy = false;
return data;
Expand Down Expand Up @@ -151,14 +154,14 @@ Decompressor.prototype.readSliceSingleThread = function (offset, length) {
};

/**
*
*
* @param {Integer} offset
* @param {Integer} length
* @returns {Array}
*/
Decompressor.prototype._readLoop = function(offset, length) {
Decompressor.prototype._readLoop = function (offset, length) {
var that = this;
return this._fillInBufferIfNeeded().then(function() {
return this._fillInBufferIfNeeded().then(function () {
var ret = xzdec._decompress(that._decHandle);
var finished = false;
if (ret === 0) {
Expand All @@ -172,37 +175,33 @@ Decompressor.prototype._readLoop = function(offset, length) {
}

var outPos = xzdec._get_out_pos(that._decHandle);
if (outPos > 0 && that._outStreamPos + outPos >= offset)
{
if (outPos > 0 && that._outStreamPos + outPos >= offset) {
var outBuffer = xzdec._get_out_buffer(that._decHandle);
var copyStart = offset - that._outStreamPos;
if (copyStart < 0)
if (copyStart < 0) {
copyStart = 0;
for (var i = copyStart; i < outPos && that._outBufferPos < that._outBuffer.length; i++)
}
for (var i = copyStart; i < outPos && that._outBufferPos < that._outBuffer.length; i++) {
that._outBuffer[that._outBufferPos++] = xzdec.HEAP8[outBuffer + i];
}
}
that._outStreamPos += outPos;
if (outPos > 0)
xzdec._out_buffer_cleared(that._decHandle);
if (finished || that._outStreamPos >= offset + length)
return that._outBuffer;
else
return that._readLoop(offset, length);
if (outPos > 0) { xzdec._out_buffer_cleared(that._decHandle); }
if (finished || that._outStreamPos >= offset + length) { return that._outBuffer; } else { return that._readLoop(offset, length); }
});
};

/**
*
*
* @returns {Promise}
*/
Decompressor.prototype._fillInBufferIfNeeded = function() {
Decompressor.prototype._fillInBufferIfNeeded = function () {
if (!xzdec._input_empty(this._decHandle)) {
return Promise.resolve(0);
}
var that = this;
return this._reader(this._inStreamPos, this._chunkSize).then(function(data) {
if (data.length > that._chunkSize)
data = data.slice(0, that._chunkSize);
return this._reader(this._inStreamPos, this._chunkSize).then(function (data) {
if (data.length > that._chunkSize) { data = data.slice(0, that._chunkSize); }
// For some reason, xzdec.writeArrayToMemory does not seem to be available, and is equivalent to xzdec.HEAP8.set
xzdec.HEAP8.set(data, xzdec._get_in_buffer(that._decHandle));
that._inStreamPos += data.length;
Expand Down

0 comments on commit 26078c0

Please sign in to comment.