diff --git a/KiwixWebApp.jsproj b/KiwixWebApp.jsproj index ecbca497..e8bb05c9 100644 --- a/KiwixWebApp.jsproj +++ b/KiwixWebApp.jsproj @@ -162,9 +162,9 @@ + - diff --git a/package.json b/package.json index 447c806a..9454a0a0 100644 --- a/package.json +++ b/package.json @@ -1,93 +1,93 @@ -{ - "name": "kiwix-js-pwa", - "productName": "Kiwix JS PWA", - "version": "1.5.0", - "description": "Kiwix JS PWA packaged for the Electron framework", - "main": "main.js", - "build": { - "appId": "kiwix.js.pwa", - "productName": "Kiwix JS PWA", - "directories": { - "output": "bld/Electron", - "buildResources": "bld" - }, - "afterPack": "./scripts/appimage-fix.js", - "win": { - "target": [ - { - "target": "NSIS", - "arch": "ia32" - } - ] - }, - "linux": { - "target": [ - { - "target": "AppImage", - "arch": [ - "x64", - "ia32" - ] - }, - { - "target": "deb", - "arch": [ - "x64", - "ia32" - ] - } - ], - "category": "Education" - }, - "nsis": { - "oneClick": "false", - "allowElevation": "true", - "runAfterFinish": "true" - }, - "asar": false, - "files": [ - "archives/**", - "pwabuilder-sw.js", - "index.html", - "CHANGELOG.md", - "LICENCE", - "www/**", - "preload.js", - "main.js" - ] - }, - "scripts": { - "start": "electron .", - "dist-win": "electron-builder build --win", - "dist-linux": "electron-builder build --linux", - "package-mac": "electron-packager . kiwix-js-windows --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds", - "package-win": "electron-packager . kiwix-js-windows --electron-version='10.4.0' --ignore=archives --ignore=AppPackages --ignore=BundleArtifacts --ignore=images$ --ignore=bin$ --ignore=bld$ --ignore=KiwixWebApp.* --ignore=[pP]ackage.[aSl] --ignore=node_ --ignore=[.]git[hi][ug][bn] --ignore=[.]vs$ --ignore=vscode --overwrite --platform=win32 --arch=ia32 --icon=www/img/icons/kiwix-64.ico --prune=true --out=bld/electron --version-string.CompanyName=Kiwix --version-string.FileDescription='Kiwix JS ZIM File Reader' --version-string.ProductName='Kiwix JS Windows Electron Edition'", - "postpackage-win": "(robocopy archives bld\\Electron\\kiwix-js-windows-win32-ia32\\resources\\app\\archives\\ > null) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0", - "package-linux": "electron-packager . kiwix-js-windows --overwrite --platform=linux --icon=www/img/icons/kiwix-64.png --electron-version='10.4.0' --ignore=archives --ignore=AppPackages --ignore=BundleArtifacts --ignore=images$ --ignore=bin$ --ignore=bld$ --ignore=KiwixWebApp.* --ignore=[pP]ackage.[aSl] --ignore=node_ --ignore=[.]git[hi][ug][bn] --ignore=[.]vs$ --ignore=vscode --overwrite --arch=x64 --prune=true --out=bld/electron --version-string.CompanyName=Kiwix --version-string.FileDescription='Kiwix JS ZIM File Reader' --version-string.ProductName='Kiwix JS Windows Electron Edition'", - "postpackage-linux": "(robocopy archives bld\\Electron\\kiwix-js-windows-linux-x64\\archives\\ > null) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0" - }, - "repository": "https://github.com/kiwix/kiwix-js-windows", - "keywords": [ - "Kiwix", - "offline", - "Wikipedia", - "ZIM", - "reader" - ], - "author": { - "name": "Kiwix", - "email": "kiwix@kiwix.org" - }, - "maintainer": "Jaifroid", - "license": "CC0-1.0", - "devDependencies": { - "electron": "10.4.0", - "electron-builder": "^22.10.5", - "electron-packager": "^15.2.0" - }, - "dependencies": { - "@types/fs-extra": "^9.0.11" - } +{ + "name": "kiwix-js-pwa", + "productName": "Kiwix JS PWA", + "version": "1.5.0", + "description": "Kiwix JS PWA packaged for the Electron framework", + "main": "main.js", + "build": { + "appId": "kiwix.js.pwa", + "productName": "Kiwix JS PWA", + "directories": { + "output": "bld/Electron", + "buildResources": "bld" + }, + "afterPack": "./scripts/appimage-fix.js", + "win": { + "target": [ + { + "target": "NSIS", + "arch": "ia32" + } + ] + }, + "linux": { + "target": [ + { + "target": "AppImage", + "arch": [ + "x64", + "ia32" + ] + }, + { + "target": "deb", + "arch": [ + "x64", + "ia32" + ] + } + ], + "category": "Education" + }, + "nsis": { + "oneClick": "false", + "allowElevation": "true", + "runAfterFinish": "true" + }, + "asar": false, + "files": [ + "archives/**", + "pwabuilder-sw.js", + "index.html", + "CHANGELOG.md", + "LICENCE", + "www/**", + "preload.js", + "main.js" + ] + }, + "scripts": { + "start": "electron .", + "dist-win": "electron-builder build --win", + "dist-linux": "electron-builder build --linux", + "package-mac": "electron-packager . kiwix-js-windows --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds", + "package-win": "electron-packager . kiwix-js-windows --electron-version='10.4.0' --ignore=archives --ignore=AppPackages --ignore=BundleArtifacts --ignore=images$ --ignore=bin$ --ignore=bld$ --ignore=KiwixWebApp.* --ignore=[pP]ackage.[aSl] --ignore=node_ --ignore=[.]git[hi][ug][bn] --ignore=[.]vs$ --ignore=vscode --overwrite --platform=win32 --arch=ia32 --icon=www/img/icons/kiwix-64.ico --prune=true --out=bld/electron --version-string.CompanyName=Kiwix --version-string.FileDescription='Kiwix JS ZIM File Reader' --version-string.ProductName='Kiwix JS Windows Electron Edition'", + "postpackage-win": "(robocopy archives bld\\Electron\\kiwix-js-windows-win32-ia32\\resources\\app\\archives\\ > null) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0", + "package-linux": "electron-packager . kiwix-js-windows --overwrite --platform=linux --icon=www/img/icons/kiwix-64.png --electron-version='10.4.0' --ignore=archives --ignore=AppPackages --ignore=BundleArtifacts --ignore=images$ --ignore=bin$ --ignore=bld$ --ignore=KiwixWebApp.* --ignore=[pP]ackage.[aSl] --ignore=node_ --ignore=[.]git[hi][ug][bn] --ignore=[.]vs$ --ignore=vscode --overwrite --arch=x64 --prune=true --out=bld/electron --version-string.CompanyName=Kiwix --version-string.FileDescription='Kiwix JS ZIM File Reader' --version-string.ProductName='Kiwix JS Windows Electron Edition'", + "postpackage-linux": "(robocopy archives bld\\Electron\\kiwix-js-windows-linux-x64\\archives\\ > null) ^& IF %ERRORLEVEL% LSS 8 SET ERRORLEVEL = 0" + }, + "repository": "https://github.com/kiwix/kiwix-js-windows", + "keywords": [ + "Kiwix", + "offline", + "Wikipedia", + "ZIM", + "reader" + ], + "author": { + "name": "Kiwix", + "email": "kiwix@kiwix.org" + }, + "maintainer": "Jaifroid", + "license": "CC0-1.0", + "devDependencies": { + "electron": "10.4.0", + "electron-builder": "^22.10.5", + "electron-packager": "^15.2.0" + }, + "dependencies": { + "@types/fs-extra": "^9.0.11" + } } - + diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js index 03c79bf4..8d9ef77a 100644 --- a/pwabuilder-sw.js +++ b/pwabuilder-sw.js @@ -60,6 +60,7 @@ const precacheFiles = [ "www/article.html", "www/js/app.js", "www/js/init.js", + "www/js/lib/arrayFromPolyfill.js", "www/js/lib/bootstrap.js", "www/js/lib/bootstrap.min.js", "www/js/lib/cache.js", diff --git a/www/js/init.js b/www/js/init.js index 5dc7a35a..c1009a33 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -421,8 +421,7 @@ require.config({ //'jquery': 'jquery-3.2.1', //'bootstrap': 'bootstrap' 'bootstrap': 'bootstrap.min', - 'webpHeroBundle': 'webpHeroBundle_0.0.0-dev.27', - 'webpHeroPolyfills': 'webpHeroPolyfills_0.0.0-dev.27' + 'webpHeroBundle': 'webpHeroBundle_0.0.0-dev.27' }, shim: { 'jquery': { @@ -431,13 +430,11 @@ require.config({ 'bootstrap': { deps: ['jquery'] }, - 'webpHeroBundle': { - deps: ['webpHeroPolyfills'] - } + 'webpHeroBundle': '' } }); -requirejs(['bootstrap', 'promisePolyfill'], function () { +requirejs(['bootstrap', 'promisePolyfill', 'arrayFromPolyfill'], function () { requirejs(['../app']); }); diff --git a/www/js/lib/arrayFromPolyfill.js b/www/js/lib/arrayFromPolyfill.js new file mode 100644 index 00000000..4f55af9d --- /dev/null +++ b/www/js/lib/arrayFromPolyfill.js @@ -0,0 +1,172 @@ +/* globals + IsCallable, GetMethod, Symbol, IsConstructor, Construct, ArrayCreate, GetIterator, IteratorClose, + ToString, IteratorStep, IteratorValue, Call, CreateDataPropertyOrThrow, ToObject, ToLength, Get, CreateMethodProperty +*/ +(function () { + // Detection + if ('from' in Array && (function () { + try { + Array.from({ length: -Infinity }); + + if (Array.from(new self.Set(['a']))[0] !== 'a') { + return false; + } + + if (Array.from(new self.Map([['a', 'one']]))[0][0] !== 'a') { + return false; + } + + return true; + } catch (e) { + return false; + } + }())) { return; } + + var toString = Object.prototype.toString; + var stringMatch = String.prototype.match; + // A cross-realm friendly way to detect if a value is a String object or literal. + function isString(value) { + if (typeof value === 'string') { return true; } + if (typeof value !== 'object') { return false; } + return toString.call(value) === '[object String]'; + } + + // 22.1.2.1. Array.from ( items [ , mapfn [ , thisArg ] ] ) + CreateMethodProperty(Array, 'from', function from(items /* [ , mapfn [ , thisArg ] ] */) { // eslint-disable-line no-undef + // 1. Let C be the this value. + var C = this; + // 2. If mapfn is undefined, let mapping be false. + var mapfn = arguments.length > 1 ? arguments[1] : undefined; + if (mapfn === undefined) { + var mapping = false; + // 3. Else, + } else { + // a. If IsCallable(mapfn) is false, throw a TypeError exception. + if (IsCallable(mapfn) === false) { + throw new TypeError(Object.prototype.toString.call(mapfn) + ' is not a function.'); + } + // b. If thisArg is present, let T be thisArg; else let T be undefined. + var thisArg = arguments.length > 2 ? arguments[2] : undefined; + if (thisArg !== undefined) { + var T = thisArg; + } else { + T = undefined; + } + // c. Let mapping be true. + mapping = true; + + } + // 4. Let usingIterator be ? GetMethod(items, @@iterator). + var usingIterator = GetMethod(items, Symbol.iterator); + // 5. If usingIterator is not undefined, then + if (usingIterator !== undefined) { + // a. If IsConstructor(C) is true, then + if (IsConstructor(C)) { + // i. Let A be ? Construct(C). + var A = Construct(C); + // b. Else, + } else { + // i. Let A be ! ArrayCreate(0). + A = ArrayCreate(0); + } + // c. Let iteratorRecord be ? GetIterator(items, usingIterator). + var iteratorRecord = GetIterator(items, usingIterator); + // d. Let k be 0. + var k = 0; + // e. Repeat, + // eslint-disable-next-line no-constant-condition + while (true) { + // i. If k ≥ 2^53-1, then + if (k >= (Math.pow(2, 53) - 1)) { + // 1. Let error be Completion{[[Type]]: throw, [[Value]]: a newly created TypeError object, [[Target]]: empty}. + var error = new TypeError('Iteration count can not be greater than or equal 9007199254740991.'); + // 2. Return ? IteratorClose(iteratorRecord, error). + return IteratorClose(iteratorRecord, error); + } + // ii. Let Pk be ! ToString(k). + var Pk = ToString(k); + // iii. Let next be ? IteratorStep(iteratorRecord). + var next = IteratorStep(iteratorRecord); + // iv. If next is false, then + if (next === false) { + // 1. Perform ? Set(A, "length", k, true). + A.length = k; + // 2. Return A. + return A; + } + // v. Let nextValue be ? IteratorValue(next). + var nextValue = IteratorValue(next); + // vi. If mapping is true, then + if (mapping) { + try { + // Polyfill.io - The try catch accounts for step 2. + // 1. Let mappedValue be Call(mapfn, T, « nextValue, k »). + var mappedValue = Call(mapfn, T, [nextValue, k]); + // 2. If mappedValue is an abrupt completion, return ? IteratorClose(iteratorRecord, mappedValue). + // 3. Let mappedValue be mappedValue.[[Value]]. + } catch (e) { + return IteratorClose(iteratorRecord, e); + } + + // vii. Else, let mappedValue be nextValue. + } else { + mappedValue = nextValue; + } + try { + // Polyfill.io - The try catch accounts for step ix. + // viii. Let defineStatus be CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + // ix. If defineStatus is an abrupt completion, return ? IteratorClose(iteratorRecord, defineStatus). + } catch (e) { + return IteratorClose(iteratorRecord, e); + } + // x. Increase k by 1. + k = k + 1; + } + } + // 6. NOTE: items is not an Iterable so assume it is an array-like object. + // 7. Let arrayLike be ! ToObject(items). + // Polyfill.io - For Strings we need to split astral symbols into surrogate pairs. + if (isString(items)) { + var arrayLike = stringMatch.call(items, /[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || []; + } else { + arrayLike = ToObject(items); + } + // 8. Let len be ? ToLength(? Get(arrayLike, "length")). + var len = ToLength(Get(arrayLike, "length")); + // 9. If IsConstructor(C) is true, then + if (IsConstructor(C)) { + // a. Let A be ? Construct(C, « len »). + A = Construct(C, [len]); + // 10. Else, + } else { + // a. Let A be ? ArrayCreate(len). + A = ArrayCreate(len); + } + // 11. Let k be 0. + k = 0; + // 12. Repeat, while k < len + while (k < len) { + // a. Let Pk be ! ToString(k). + Pk = ToString(k); + // b. Let kValue be ? Get(arrayLike, Pk). + var kValue = Get(arrayLike, Pk); + // c. If mapping is true, then + if (mapping === true) { + // i. Let mappedValue be ? Call(mapfn, T, « kValue, k »). + mappedValue = Call(mapfn, T, [kValue, k]); + // d. Else, let mappedValue be kValue. + } else { + mappedValue = kValue; + } + // e. Perform ? CreateDataPropertyOrThrow(A, Pk, mappedValue). + CreateDataPropertyOrThrow(A, Pk, mappedValue); + // f. Increase k by 1. + k = k + 1; + } + // 13. Perform ? Set(A, "length", len, true). + A.length = len; + // 14. Return A. + return A; + }); +}()); diff --git a/www/js/lib/promisePolyfill.js b/www/js/lib/promisePolyfill.js index bbecc4eb..3924cc1b 100644 --- a/www/js/lib/promisePolyfill.js +++ b/www/js/lib/promisePolyfill.js @@ -1,4 +1,4 @@ -/* +/* Yaku v0.19.3 (c) 2015 Yad Smood. http://ysmood.org License MIT diff --git a/www/js/lib/webpHeroPolyfills_0.0.0-dev.27.js b/www/js/lib/webpHeroPolyfills_0.0.0-dev.27.js deleted file mode 100644 index 14a7d040..00000000 --- a/www/js/lib/webpHeroPolyfills_0.0.0-dev.27.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.ES6Promise=e()}(this,function(){"use strict";function t(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}function e(t){return"function"==typeof t}function n(t){W=t}function r(t){z=t}function o(){return function(){return process.nextTick(a)}}function i(){return"undefined"!=typeof U?function(){U(a)}:c()}function s(){var t=0,e=new H(a),n=document.createTextNode("");return e.observe(n,{characterData:!0}),function(){n.data=t=++t%2}}function u(){var t=new MessageChannel;return t.port1.onmessage=a,function(){return t.port2.postMessage(0)}}function c(){var t=setTimeout;return function(){return t(a,1)}}function a(){for(var t=0;t} Promise for an ArrayBuffer with decoded data */ Decompressor.prototype.readSlice = function(offset, length) { - busy = true; + appstate.zdBusy = true; this._inStreamPos = 0; this._inStreamChunkedPos = 0; this._outStreamPos = 0; @@ -139,7 +139,7 @@ define(['zstddec'], function() { // Should you need to free the decoder stream handle, use command below, but be sure to create a new stream control object // before attempting further decompression // zd._ZSTD_freeDStream(zd._decHandle); - busy = false; + appstate.zdBusy = false; return data; }); }; @@ -152,7 +152,7 @@ define(['zstddec'], function() { * @returns {Promise} A Promise for the readSlice() function */ Decompressor.prototype.readSliceSingleThread = function (offset, length) { - if (!busy) { + if (!appstate.zdBusy) { return this.readSlice(offset, length); } else { // The decompressor is already in progress. @@ -260,4 +260,4 @@ define(['zstddec'], function() { return { Decompressor: Decompressor }; -}); \ No newline at end of file +});