From: Alexander Ebert Date: Fri, 16 Oct 2020 13:00:22 +0000 (+0200) Subject: Housekeeping X-Git-Tag: 5.4.0_Alpha_1~704^2~60 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f10d9af61553648a98363c26f7c92f5c98ad53e0;p=GitHub%2FWoltLab%2FWCF.git Housekeeping --- diff --git a/global.d.ts b/global.d.ts index ecfc37f173..bd55ce7231 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,6 +1,6 @@ import Devtools from './wcfsetup/install/files/ts/WoltLabSuite/Core/Devtools'; import DomUtil from './wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util'; -import ColorUtil from './wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil'; +import * as ColorUtil from './wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil'; declare global { interface Window { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Jsonp.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Jsonp.js index 47997ca831..6949054298 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Jsonp.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Jsonp.js @@ -57,6 +57,7 @@ define(["require", "exports", "../Core"], function (require, exports, Core) { }, (~~options.timeout || 10) * 1000); window[callbackName] = function () { window.clearTimeout(timeout); + //@ts-ignore success.apply(null, arguments); window[callbackName] = undefined; script.parentNode.removeChild(script); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js index 8d2626f1bc..78affbbe19 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/ColorUtil.js @@ -9,157 +9,165 @@ */ define(["require", "exports"], function (require, exports) { "use strict"; - const ColorUtil = { - /** - * Converts a HSV color into RGB. - * - * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV - */ - hsvToRgb(h, s, v) { - const rgb = { r: 0, g: 0, b: 0 }; - let h2, f, p, q, t; - h2 = Math.floor(h / 60); - f = h / 60 - h2; - s /= 100; - v /= 100; - p = v * (1 - s); - q = v * (1 - s * f); - t = v * (1 - s * (1 - f)); - if (s == 0) { - rgb.r = rgb.g = rgb.b = v; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.rgbToHex = exports.hexToRgb = exports.rgbToHsv = exports.hsvToRgb = void 0; + /** + * Converts a HSV color into RGB. + * + * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV + */ + function hsvToRgb(h, s, v) { + const rgb = { r: 0, g: 0, b: 0 }; + let h2, f, p, q, t; + h2 = Math.floor(h / 60); + f = h / 60 - h2; + s /= 100; + v /= 100; + p = v * (1 - s); + q = v * (1 - s * f); + t = v * (1 - s * (1 - f)); + if (s == 0) { + rgb.r = rgb.g = rgb.b = v; + } + else { + switch (h2) { + case 1: + rgb.r = q; + rgb.g = v; + rgb.b = p; + break; + case 2: + rgb.r = p; + rgb.g = v; + rgb.b = t; + break; + case 3: + rgb.r = p; + rgb.g = q; + rgb.b = v; + break; + case 4: + rgb.r = t; + rgb.g = p; + rgb.b = v; + break; + case 5: + rgb.r = v; + rgb.g = p; + rgb.b = q; + break; + case 0: + case 6: + rgb.r = v; + rgb.g = t; + rgb.b = p; + break; } - else { - switch (h2) { - case 1: - rgb.r = q; - rgb.g = v; - rgb.b = p; - break; - case 2: - rgb.r = p; - rgb.g = v; - rgb.b = t; - break; - case 3: - rgb.r = p; - rgb.g = q; - rgb.b = v; - break; - case 4: - rgb.r = t; - rgb.g = p; - rgb.b = v; - break; - case 5: - rgb.r = v; - rgb.g = p; - rgb.b = q; - break; - case 0: - case 6: - rgb.r = v; - rgb.g = t; - rgb.b = p; - break; - } + } + return { + r: Math.round(rgb.r * 255), + g: Math.round(rgb.g * 255), + b: Math.round(rgb.b * 255), + }; + } + exports.hsvToRgb = hsvToRgb; + /** + * Converts a RGB color into HSV. + * + * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV + */ + function rgbToHsv(r, g, b) { + let h, s, v; + let max, min, diff; + r /= 255; + g /= 255; + b /= 255; + max = Math.max(Math.max(r, g), b); + min = Math.min(Math.min(r, g), b); + diff = max - min; + h = 0; + if (max !== min) { + switch (max) { + case r: + h = 60 * ((g - b) / diff); + break; + case g: + h = 60 * (2 + (b - r) / diff); + break; + case b: + h = 60 * (4 + (r - g) / diff); + break; } - return { - r: Math.round(rgb.r * 255), - g: Math.round(rgb.g * 255), - b: Math.round(rgb.b * 255), - }; - }, - /** - * Converts a RGB color into HSV. - * - * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV - */ - rgbToHsv(r, g, b) { - let h, s, v; - let max, min, diff; - r /= 255; - g /= 255; - b /= 255; - max = Math.max(Math.max(r, g), b); - min = Math.min(Math.min(r, g), b); - diff = max - min; - h = 0; - if (max !== min) { - switch (max) { - case r: - h = 60 * ((g - b) / diff); - break; - case g: - h = 60 * (2 + (b - r) / diff); - break; - case b: - h = 60 * (4 + (r - g) / diff); - break; - } - if (h < 0) { - h += 360; - } + if (h < 0) { + h += 360; } - if (max === 0) { - s = 0; + } + if (max === 0) { + s = 0; + } + else { + s = diff / max; + } + v = max; + return { + h: Math.round(h), + s: Math.round(s * 100), + v: Math.round(v * 100), + }; + } + exports.rgbToHsv = rgbToHsv; + /** + * Converts HEX into RGB. + */ + function hexToRgb(hex) { + if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { + // only convert #abc and #abcdef + const parts = hex.split(''); + // drop the hashtag + if (parts[0] === '#') { + parts.shift(); } - else { - s = diff / max; + // parse shorthand #xyz + if (parts.length === 3) { + return { + r: parseInt(parts[0] + '' + parts[0], 16), + g: parseInt(parts[1] + '' + parts[1], 16), + b: parseInt(parts[2] + '' + parts[2], 16), + }; } - v = max; - return { - h: Math.round(h), - s: Math.round(s * 100), - v: Math.round(v * 100), - }; - }, - /** - * Converts HEX into RGB. - */ - hexToRgb(hex) { - if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { - // only convert #abc and #abcdef - const parts = hex.split(''); - // drop the hashtag - if (parts[0] === '#') { - parts.shift(); - } - // parse shorthand #xyz - if (parts.length === 3) { - return { - r: parseInt(parts[0] + '' + parts[0], 16), - g: parseInt(parts[1] + '' + parts[1], 16), - b: parseInt(parts[2] + '' + parts[2], 16), - }; - } - else { - return { - r: parseInt(parts[0] + '' + parts[1], 16), - g: parseInt(parts[2] + '' + parts[3], 16), - b: parseInt(parts[4] + '' + parts[5], 16), - }; - } + else { + return { + r: parseInt(parts[0] + '' + parts[1], 16), + g: parseInt(parts[2] + '' + parts[3], 16), + b: parseInt(parts[4] + '' + parts[5], 16), + }; } - return Number.NaN; - }, - /** - * Converts a RGB into HEX. - * - * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm - */ - rgbToHex(r, g, b) { - const charList = '0123456789ABCDEF'; - if (g === undefined) { - if (r.toString().match(/^rgba?\((\d+), ?(\d+), ?(\d+)(?:, ?[0-9.]+)?\)$/)) { - r = +RegExp.$1; - g = +RegExp.$2; - b = +RegExp.$3; - } + } + return Number.NaN; + } + exports.hexToRgb = hexToRgb; + /** + * Converts a RGB into HEX. + * + * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm + */ + function rgbToHex(r, g, b) { + const charList = '0123456789ABCDEF'; + if (g === undefined) { + if (r.toString().match(/^rgba?\((\d+), ?(\d+), ?(\d+)(?:, ?[0-9.]+)?\)$/)) { + r = +RegExp.$1; + g = +RegExp.$2; + b = +RegExp.$3; } - return (charList.charAt((r - r % 16) / 16) + '' + charList.charAt(r % 16)) + '' + (charList.charAt((g - g % 16) / 16) + '' + charList.charAt(g % 16)) + '' + (charList.charAt((b - b % 16) / 16) + '' + charList.charAt(b % 16)); - }, - }; + } + return (charList.charAt((r - r % 16) / 16) + '' + charList.charAt(r % 16)) + '' + (charList.charAt((g - g % 16) / 16) + '' + charList.charAt(g % 16)) + '' + (charList.charAt((b - b % 16) / 16) + '' + charList.charAt(b % 16)); + } + exports.rgbToHex = rgbToHex; // WCF.ColorPicker compatibility (color format conversion) - window.__wcf_bc_colorUtil = ColorUtil; - return ColorUtil; + window.__wcf_bc_colorUtil = { + hexToRgb, + hsvToRgb, + rgbToHex, + rgbToHsv, + }; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js index 25a9e82181..9cfdf25dc0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Core.js @@ -183,17 +183,10 @@ define(["require", "exports"], function (require, exports) { * Triggers a custom or built-in event. */ function triggerEvent(element, eventName) { - let event; - try { - event = new Event(eventName, { - bubbles: true, - cancelable: true, - }); - } - catch (e) { - event = document.createEvent('Event'); - event.initEvent(eventName, true, true); - } + const event = new Event(eventName, { + bubbles: true, + cancelable: true, + }); element.dispatchEvent(event); } exports.triggerEvent = triggerEvent; diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Devtools.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Devtools.js index 1445574aa5..68df46636c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Devtools.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Devtools.js @@ -22,7 +22,7 @@ define(["require", "exports"], function (require, exports) { /** * Prints the list of available commands. */ - help: () => { + help() { window.console.log(''); window.console.log('%cAvailable commands:', 'text-decoration: underline'); const commands = []; @@ -39,7 +39,7 @@ define(["require", "exports"], function (require, exports) { /** * Disables/re-enables the editor autosave feature. */ - toggleEditorAutosave: (forceDisable) => { + toggleEditorAutosave(forceDisable) { _settings.editorAutosave = forceDisable ? false : !_settings.editorAutosave; _updateConfig(); window.console.log('%c\tEditor autosave ' + (_settings.editorAutosave ? 'enabled' : 'disabled'), 'font-style: italic'); @@ -47,7 +47,7 @@ define(["require", "exports"], function (require, exports) { /** * Enables/disables logging for fired event listener events. */ - toggleEventLogging: function (forceEnable) { + toggleEventLogging(forceEnable) { _settings.eventLogging = forceEnable ? true : !_settings.eventLogging; _updateConfig(); window.console.log('%c\tEvent logging ' + (_settings.eventLogging ? 'enabled' : 'disabled'), 'font-style: italic'); @@ -56,7 +56,7 @@ define(["require", "exports"], function (require, exports) { * Internal methods not meant to be called directly. */ _internal_: { - enable: () => { + enable() { window.Devtools = Devtools; window.console.log('%cDevtools for WoltLab Suite loaded', 'font-weight: bold'); if (window.sessionStorage) { @@ -76,8 +76,10 @@ define(["require", "exports"], function (require, exports) { window.console.log('Settings are saved per browser session, enter `Devtools.help()` to learn more.'); window.console.log(''); }, - editorAutosave: () => _settings.editorAutosave, - eventLog: (identifier, action) => { + editorAutosave() { + return _settings.editorAutosave; + }, + eventLog(identifier, action) { if (_settings.eventLogging) { window.console.log('[Devtools.EventLogging] Firing event: ' + action + ' @ ' + identifier); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Dictionary.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Dictionary.js index 1f8c087eb3..5df7bc9b82 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Dictionary.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Dictionary.js @@ -1,23 +1,20 @@ +/** + * Dictionary implementation relying on an object or if supported on a Map to hold key => value data. + * + * If you're looking for a dictionary with object keys, please see `WoltLabSuite/Core/ObjectMap`. + * + * This is a legacy implementation, that does not implement all methods of `Map`, furthermore it has + * the side effect of converting all numeric keys to string values, treating 1 === "1". + * + * @author Tim Duesterhus, Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module Dictionary (alias) + * @module WoltLabSuite/Core/Dictionary + */ define(["require", "exports"], function (require, exports) { "use strict"; - /** - * Dictionary implementation relying on an object or if supported on a Map to hold key => value data. - * - * If you're looking for a dictionary with object keys, please see `WoltLabSuite/Core/ObjectMap`. - * - * This is a legacy implementation, that does not implement all methods of `Map`, furthermore it has - * the side effect of converting all numeric keys to string values, treating 1 === "1". - * - * @author Tim Duesterhus, Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module Dictionary (alias) - * @module WoltLabSuite/Core/Dictionary - * @deprecated 5.4 - */ - /** - * @constructor - */ + /** @deprecated 5.4 Use a `Map` instead. */ class Dictionary { constructor() { this._dictionary = new Map(); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js index ccfc0f59bc..1937434d56 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/FileUtil.js @@ -25,16 +25,12 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -define(["require", "exports", "./Dictionary", "./StringUtil"], function (require, exports, Dictionary_1, StringUtil) { +define(["require", "exports", "./StringUtil"], function (require, exports, StringUtil) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.blobToFile = exports.getExtensionByMimeType = exports.getIconNameByFilename = exports.formatFilesize = void 0; - Dictionary_1 = __importDefault(Dictionary_1); StringUtil = __importStar(StringUtil); - const _fileExtensionIconMapping = Dictionary_1.default.fromObject({ + const _fileExtensionIconMapping = new Map(Object.entries({ // archive zip: 'archive', rar: 'archive', @@ -80,8 +76,8 @@ define(["require", "exports", "./Dictionary", "./StringUtil"], function (require doc: 'word', docx: 'word', odt: 'word', - }); - const _mimeTypeExtensionMapping = Dictionary_1.default.fromObject({ + })); + const _mimeTypeExtensionMapping = new Map(Object.entries({ // archive 'application/zip': 'zip', 'application/x-zip-compressed': 'zip', @@ -129,7 +125,7 @@ define(["require", "exports", "./Dictionary", "./StringUtil"], function (require 'application/msword': 'doc', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx', 'application/vnd.oasis.opendocument.text': 'odt', - }); + })); /** * Formats the given filesize. */ diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js b/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js index 415a2ce2be..c31bd12921 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/I18n/Plural.js @@ -43,10 +43,10 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri languageCode = document.documentElement.lang; } // Fallback: handle unknown languages as English - if (typeof this[languageCode] !== 'function') { + if (typeof Plural[languageCode] !== 'function') { languageCode = 'en'; } - const category = this[languageCode](value); + const category = Plural[languageCode](value); if (category) { return category; } @@ -74,7 +74,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return parameters[key]; } } - let category = this.getCategory(value); + let category = Plural.getCategory(value); if (!parameters[category]) { category = PLURAL_OTHER; } @@ -164,8 +164,8 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Bosnian bs(n) { - const v = this.getV(n); - const f = this.getF(n); + const v = Plural.getV(n); + const f = Plural.getF(n); const mod10 = n % 10; const mod100 = n % 100; const fMod10 = f % 10; @@ -178,7 +178,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Czech cs(n) { - const v = this.getV(n); + const v = Plural.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; if (n >= 2 && n <= 4 && v === 0) @@ -220,7 +220,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri // Swahili (sw) // Urdu (ur) en(n) { - if (n == 1 && this.getV(n) === 0) + if (n == 1 && Plural.getV(n) === 0) return PLURAL_ONE; }, // Spanish @@ -261,7 +261,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Hebrew he(n) { - const v = this.getV(n); + const v = Plural.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; if (n == 2 && v === 0) @@ -277,7 +277,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri // Croatian hr(n) { // same as Bosnian - return this.bs(n); + return Plural.bs(n); }, // Hungarian hu(n) { @@ -294,7 +294,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Icelandic is(n) { - const f = this.getF(n); + const f = Plural.getF(n); if (f === 0 && n % 10 === 1 && !(n % 100 === 11) || !(f === 0)) return PLURAL_ONE; }, @@ -351,15 +351,15 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri return PLURAL_ONE; if (mod10 >= 2 && mod10 <= 9 && !(mod100 >= 11 && mod100 <= 19)) return PLURAL_FEW; - if (this.getF(n) != 0) + if (Plural.getF(n) != 0) return PLURAL_MANY; }, // Latvian lv(n) { const mod10 = n % 10; const mod100 = n % 100; - const v = this.getV(n); - const f = this.getF(n); + const v = Plural.getV(n); + const f = Plural.getF(n); const fMod10 = f % 10; const fMod100 = f % 100; if (mod10 == 0 || (mod100 >= 11 && mod100 <= 19) || (v == 2 && fMod100 >= 11 && fMod100 <= 19)) @@ -369,7 +369,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Macedonian mk(n) { - return this.bs(n); + return Plural.bs(n); }, // Malayalam ml(n) { @@ -424,7 +424,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Polish pl(n) { - const v = this.getV(n); + const v = Plural.getV(n); const mod10 = n % 10; const mod100 = n % 100; if (n == 1 && v == 0) @@ -446,7 +446,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Romanian ro(n) { - const v = this.getV(n); + const v = Plural.getV(n); const mod100 = n % 100; if (n == 1 && v === 0) return PLURAL_ONE; @@ -457,7 +457,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri ru(n) { const mod10 = n % 10; const mod100 = n % 100; - if (this.getV(n) == 0) { + if (Plural.getV(n) == 0) { if (mod10 == 1 && mod100 != 11) return PLURAL_ONE; if (mod10 >= 2 && mod10 <= 4 && !(mod100 >= 12 && mod100 <= 14)) @@ -473,17 +473,17 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri }, // Sinhala si(n) { - if (n == 0 || n == 1 || (Math.floor(n) == 0 && this.getF(n) == 1)) + if (n == 0 || n == 1 || (Math.floor(n) == 0 && Plural.getF(n) == 1)) return PLURAL_ONE; }, // Slovak sk(n) { // same as Czech - return this.cs(n); + return Plural.cs(n); }, // Slovenian sl(n) { - const v = this.getV(n); + const v = Plural.getV(n); const mod100 = n % 100; if (v == 0 && mod100 == 1) return PLURAL_ONE; @@ -500,7 +500,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri // Serbian sr(n) { // same as Bosnian - return this.bs(n); + return Plural.bs(n); }, // Tamil ta(n) { @@ -536,7 +536,7 @@ define(["require", "exports", "../StringUtil"], function (require, exports, Stri // Ukrainian uk(n) { // same as Russian - return this.ru(n); + return Plural.ru(n); }, // Uzbek uz(n) { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Language.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Language.js index 09fe230c19..df89816743 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Language.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Language.js @@ -1,18 +1,28 @@ +/** + * Manages language items. + * + * @author Tim Duesterhus + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module Language (alias) + * @module WoltLabSuite/Core/Language + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; -define(["require", "exports", "./Dictionary", "./Template"], function (require, exports, Dictionary_1, Template_1) { +define(["require", "exports", "./Template"], function (require, exports, Template_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.get = exports.add = exports.addObject = void 0; - Dictionary_1 = __importDefault(Dictionary_1); Template_1 = __importDefault(Template_1); - const _languageItems = new Dictionary_1.default(); + const _languageItems = new Map(); /** * Adds all the language items in the given object to the store. */ function addObject(object) { - _languageItems.merge(Dictionary_1.default.fromObject(object)); + Object.keys(object).forEach(key => { + _languageItems.set(key, object[key]); + }); } exports.addObject = addObject; /** diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/List.js index 6e2dfdf96d..cf0224b49e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/List.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/List.js @@ -1,17 +1,15 @@ +/** + * List implementation relying on an array or if supported on a Set to hold values. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module List (alias) + * @module WoltLabSuite/Core/List + */ define(["require", "exports"], function (require, exports) { "use strict"; - /** - * List implementation relying on an array or if supported on a Set to hold values. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module List (alias) - * @module WoltLabSuite/Core/List - */ - /** - * @constructor - */ + /** @deprecated 5.4 Use a `Set` instead. */ class List { constructor() { this._set = new Set(); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/ObjectMap.js b/wcfsetup/install/files/js/WoltLabSuite/Core/ObjectMap.js index 8ba48413b0..6fe18c8ec4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/ObjectMap.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/ObjectMap.js @@ -11,6 +11,7 @@ */ define(["require", "exports"], function (require, exports) { "use strict"; + /** @deprecated 5.4 Use a `WeakMap` instead. */ class ObjectMap { constructor() { this._map = new WeakMap(); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Permission.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Permission.js index a93125afe5..08eb9cc173 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Permission.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Permission.js @@ -28,7 +28,7 @@ define(["require", "exports"], function (require, exports) { function addObject(object) { for (const key in object) { if (object.hasOwnProperty(key)) { - this.add(key, object[key]); + add(key, object[key]); } } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/StringUtil.js b/wcfsetup/install/files/js/WoltLabSuite/Core/StringUtil.js index 9e40f6d42c..de3f2624ad 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/StringUtil.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/StringUtil.js @@ -1,3 +1,12 @@ +/** + * Provides helper functions for String handling. + * + * @author Tim Duesterhus, Joshua Ruesweg + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module StringUtil (alias) + * @module WoltLabSuite/Core/StringUtil + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -62,7 +71,7 @@ define(["require", "exports", "./Language", "./NumberUtil"], function (require, } let tmp = NumberUtil.round(number, decimalPlaces || -2).toString(); const numberParts = tmp.split('.'); - tmp = this.addThousandsSeparator(+numberParts[0]); + tmp = addThousandsSeparator(+numberParts[0]); if (numberParts.length > 1) tmp += Language.get('wcf.global.decimalPoint') + numberParts[1]; tmp = tmp.replace('-', '\u2212'); @@ -115,7 +124,7 @@ define(["require", "exports", "./Language", "./NumberUtil"], function (require, } unitSuffix = 'k'; } - return this.formatNumeric(number) + unitSuffix; + return formatNumeric(number) + unitSuffix; } exports.shortUnit = shortUnit; }); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Template.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Template.js index 2169387bd9..c3c3c7b2d1 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Template.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Template.js @@ -1,3 +1,14 @@ +/** + * WoltLabSuite/Core/Template provides a template scripting compiler similar + * to the PHP one of WoltLab Suite Core. It supports a limited + * set of useful commands and compiles templates down to a pure + * JavaScript Function. + * + * @author Tim Duesterhus + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Template + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); @@ -32,12 +43,6 @@ define(["require", "exports", "./Template.grammar", "./StringUtil", "./Language" Parser.prototype = parser; parser.Parser = Parser; parser = new Parser();*/ - /** - * Compiles the given template. - * - * @param {string} template Template to compile. - * @constructor - */ class Template { constructor(template) { // Fetch Language/StringUtil, as it cannot be provided because of a circular dependency diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/User.js b/wcfsetup/install/files/js/WoltLabSuite/Core/User.js index 9ecd7e92b4..9d9926326b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/User.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/User.js @@ -22,13 +22,13 @@ define(["require", "exports"], function (require, exports) { * Returns the link to the active user's profile or an empty string * if the active user is a guest. */ - getLink: () => { + getLink() { return user.link; }, /** * Initializes the user object. */ - init: (userId, username, link) => { + init(userId, username, link) { if (user) { throw new Error('User has already been initialized.'); } @@ -39,6 +39,6 @@ define(["require", "exports"], function (require, exports) { }, get username() { return user.username; - } + }, }; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ajax/Jsonp.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ajax/Jsonp.ts index 51abfe1d20..faae75626c 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ajax/Jsonp.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ajax/Jsonp.ts @@ -43,6 +43,7 @@ export function send(url: string, success: (...args: unknown[]) => void, failure window[callbackName] = function () { window.clearTimeout(timeout); + //@ts-ignore success.apply(null, arguments); window[callbackName] = undefined; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/CallbackList.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/CallbackList.ts index 036f544169..94a43a785c 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/CallbackList.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/CallbackList.ts @@ -8,8 +8,6 @@ * @module WoltLabSuite/Core/CallbackList */ -type Callback = () => void; - class CallbackList { private readonly _callbacks = new Map(); @@ -49,4 +47,6 @@ class CallbackList { } } +type Callback = () => void; + export = CallbackList; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts index afb2ab5a87..b8cd5029f8 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/ColorUtil.ts @@ -8,180 +8,178 @@ * @module WoltLabSuite/Core/ColorUtil */ -const ColorUtil = { - /** - * Converts a HSV color into RGB. - * - * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV - */ - hsvToRgb(h: number, s: number, v: number): RGB { - const rgb: RGB = {r: 0, g: 0, b: 0}; - let h2: number, f: number, p: number, q: number, t: number; - - h2 = Math.floor(h / 60); - f = h / 60 - h2; - - s /= 100; - v /= 100; - - p = v * (1 - s); - q = v * (1 - s * f); - t = v * (1 - s * (1 - f)); - - if (s == 0) { - rgb.r = rgb.g = rgb.b = v; - } else { - switch (h2) { - case 1: - rgb.r = q; - rgb.g = v; - rgb.b = p; - break; - - case 2: - rgb.r = p; - rgb.g = v; - rgb.b = t; - break; - - case 3: - rgb.r = p; - rgb.g = q; - rgb.b = v; - break; - - case 4: - rgb.r = t; - rgb.g = p; - rgb.b = v; - break; - - case 5: - rgb.r = v; - rgb.g = p; - rgb.b = q; - break; - - case 0: - case 6: - rgb.r = v; - rgb.g = t; - rgb.b = p; - break; - } +/** + * Converts a HSV color into RGB. + * + * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV + */ +export function hsvToRgb(h: number, s: number, v: number): RGB { + const rgb: RGB = {r: 0, g: 0, b: 0}; + let h2: number, f: number, p: number, q: number, t: number; + + h2 = Math.floor(h / 60); + f = h / 60 - h2; + + s /= 100; + v /= 100; + + p = v * (1 - s); + q = v * (1 - s * f); + t = v * (1 - s * (1 - f)); + + if (s == 0) { + rgb.r = rgb.g = rgb.b = v; + } else { + switch (h2) { + case 1: + rgb.r = q; + rgb.g = v; + rgb.b = p; + break; + + case 2: + rgb.r = p; + rgb.g = v; + rgb.b = t; + break; + + case 3: + rgb.r = p; + rgb.g = q; + rgb.b = v; + break; + + case 4: + rgb.r = t; + rgb.g = p; + rgb.b = v; + break; + + case 5: + rgb.r = v; + rgb.g = p; + rgb.b = q; + break; + + case 0: + case 6: + rgb.r = v; + rgb.g = t; + rgb.b = p; + break; + } + } + + return { + r: Math.round(rgb.r * 255), + g: Math.round(rgb.g * 255), + b: Math.round(rgb.b * 255), + }; +} + +/** + * Converts a RGB color into HSV. + * + * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV + */ +export function rgbToHsv(r: number, g: number, b: number): HSV { + let h: number, s: number, v: number; + let max: number, min: number, diff: number; + + r /= 255; + g /= 255; + b /= 255; + + max = Math.max(Math.max(r, g), b); + min = Math.min(Math.min(r, g), b); + diff = max - min; + + h = 0; + if (max !== min) { + switch (max) { + case r: + h = 60 * ((g - b) / diff); + break; + + case g: + h = 60 * (2 + (b - r) / diff); + break; + + case b: + h = 60 * (4 + (r - g) / diff); + break; } - return { - r: Math.round(rgb.r * 255), - g: Math.round(rgb.g * 255), - b: Math.round(rgb.b * 255), - }; - }, - - /** - * Converts a RGB color into HSV. - * - * @see https://secure.wikimedia.org/wikipedia/de/wiki/HSV-Farbraum#Transformation_von_RGB_und_HSV - */ - rgbToHsv(r: number, g: number, b: number): HSV { - let h: number, s: number, v: number; - let max: number, min: number, diff: number; - - r /= 255; - g /= 255; - b /= 255; - - max = Math.max(Math.max(r, g), b); - min = Math.min(Math.min(r, g), b); - diff = max - min; - - h = 0; - if (max !== min) { - switch (max) { - case r: - h = 60 * ((g - b) / diff); - break; - - case g: - h = 60 * (2 + (b - r) / diff); - break; - - case b: - h = 60 * (4 + (r - g) / diff); - break; - } - - if (h < 0) { - h += 360; - } + if (h < 0) { + h += 360; } + } - if (max === 0) { - s = 0; - } else { - s = diff / max; + if (max === 0) { + s = 0; + } else { + s = diff / max; + } + + v = max; + + return { + h: Math.round(h), + s: Math.round(s * 100), + v: Math.round(v * 100), + }; +} + +/** + * Converts HEX into RGB. + */ +export function hexToRgb(hex: string): RGB | typeof Number.NaN { + if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { + // only convert #abc and #abcdef + const parts = hex.split(''); + + // drop the hashtag + if (parts[0] === '#') { + parts.shift(); } - v = max; - - return { - h: Math.round(h), - s: Math.round(s * 100), - v: Math.round(v * 100), - }; - }, - - /** - * Converts HEX into RGB. - */ - hexToRgb(hex: string): RGB | typeof Number.NaN { - if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(hex)) { - // only convert #abc and #abcdef - const parts = hex.split(''); - - // drop the hashtag - if (parts[0] === '#') { - parts.shift(); - } - - // parse shorthand #xyz - if (parts.length === 3) { - return { - r: parseInt(parts[0] + '' + parts[0], 16), - g: parseInt(parts[1] + '' + parts[1], 16), - b: parseInt(parts[2] + '' + parts[2], 16), - }; - } else { - return { - r: parseInt(parts[0] + '' + parts[1], 16), - g: parseInt(parts[2] + '' + parts[3], 16), - b: parseInt(parts[4] + '' + parts[5], 16), - }; - } + // parse shorthand #xyz + if (parts.length === 3) { + return { + r: parseInt(parts[0] + '' + parts[0], 16), + g: parseInt(parts[1] + '' + parts[1], 16), + b: parseInt(parts[2] + '' + parts[2], 16), + }; + } else { + return { + r: parseInt(parts[0] + '' + parts[1], 16), + g: parseInt(parts[2] + '' + parts[3], 16), + b: parseInt(parts[4] + '' + parts[5], 16), + }; } + } + + return Number.NaN; +} - return Number.NaN; - }, - - /** - * Converts a RGB into HEX. - * - * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm - */ - rgbToHex(r: number, g: number, b: number): string { - const charList = '0123456789ABCDEF'; - - if (g === undefined) { - if (r.toString().match(/^rgba?\((\d+), ?(\d+), ?(\d+)(?:, ?[0-9.]+)?\)$/)) { - r = +RegExp.$1; - g = +RegExp.$2; - b = +RegExp.$3; - } +/** + * Converts a RGB into HEX. + * + * @see http://www.linuxtopia.org/online_books/javascript_guides/javascript_faq/rgbtohex.htm + */ +export function rgbToHex(r: number, g: number, b: number): string { + const charList = '0123456789ABCDEF'; + + if (g === undefined) { + if (r.toString().match(/^rgba?\((\d+), ?(\d+), ?(\d+)(?:, ?[0-9.]+)?\)$/)) { + r = +RegExp.$1; + g = +RegExp.$2; + b = +RegExp.$3; } + } - return (charList.charAt((r - r % 16) / 16) + '' + charList.charAt(r % 16)) + '' + (charList.charAt((g - g % 16) / 16) + '' + charList.charAt(g % 16)) + '' + (charList.charAt((b - b % 16) / 16) + '' + charList.charAt(b % 16)); - }, -}; + return (charList.charAt((r - r % 16) / 16) + '' + charList.charAt(r % 16)) + '' + (charList.charAt((g - g % 16) / 16) + '' + charList.charAt(g % 16)) + '' + (charList.charAt((b - b % 16) / 16) + '' + charList.charAt(b % 16)); +} interface RGB { r: number; @@ -196,6 +194,9 @@ interface HSV { } // WCF.ColorPicker compatibility (color format conversion) -window.__wcf_bc_colorUtil = ColorUtil; - -export = ColorUtil; +window.__wcf_bc_colorUtil = { + hexToRgb, + hsvToRgb, + rgbToHex, + rgbToHsv, +}; diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts index 37f50f12ea..10fba05246 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Core.ts @@ -31,7 +31,7 @@ const _cloneObject = function (obj: object | any[]): object | any[] | null { return newObj; }; -const _prefix = 'wsc' + window.WCF_PATH.hashCode() +'-'; +const _prefix = 'wsc' + window.WCF_PATH.hashCode() + '-'; /** * Deep clones an object. @@ -192,17 +192,10 @@ export function serialize(obj: object, prefix?: string): string { * Triggers a custom or built-in event. */ export function triggerEvent(element: Element, eventName: string): void { - let event: Event; - - try { - event = new Event(eventName, { - bubbles: true, - cancelable: true, - }); - } catch (e) { - event = document.createEvent('Event'); - event.initEvent(eventName, true, true); - } + const event = new Event(eventName, { + bubbles: true, + cancelable: true, + }); element.dispatchEvent(event); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Devtools.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Devtools.ts index 4b5d596e5c..4463c3fd52 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Devtools.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Devtools.ts @@ -23,7 +23,7 @@ const Devtools = { /** * Prints the list of available commands. */ - help: (): void => { + help(): void { window.console.log(''); window.console.log('%cAvailable commands:', 'text-decoration: underline'); @@ -43,7 +43,7 @@ const Devtools = { /** * Disables/re-enables the editor autosave feature. */ - toggleEditorAutosave: (forceDisable: boolean): void => { + toggleEditorAutosave(forceDisable: boolean): void { _settings.editorAutosave = forceDisable ? false : !_settings.editorAutosave; _updateConfig(); @@ -53,7 +53,7 @@ const Devtools = { /** * Enables/disables logging for fired event listener events. */ - toggleEventLogging: function (forceEnable: boolean): void { + toggleEventLogging(forceEnable: boolean): void { _settings.eventLogging = forceEnable ? true : !_settings.eventLogging; _updateConfig(); @@ -64,7 +64,7 @@ const Devtools = { * Internal methods not meant to be called directly. */ _internal_: { - enable: (): void => { + enable(): void { window.Devtools = Devtools; window.console.log('%cDevtools for WoltLab Suite loaded', 'font-weight: bold'); @@ -86,9 +86,11 @@ const Devtools = { window.console.log(''); }, - editorAutosave: (): boolean => _settings.editorAutosave, + editorAutosave(): boolean { + return _settings.editorAutosave; + }, - eventLog: (identifier: string, action: string): void => { + eventLog(identifier: string, action: string): void { if (_settings.eventLogging) { window.console.log('[Devtools.EventLogging] Firing event: ' + action + ' @ ' + identifier); } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts index 4aef6c8337..ac85fcb39a 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dictionary.ts @@ -11,11 +11,9 @@ * @license GNU Lesser General Public License * @module Dictionary (alias) * @module WoltLabSuite/Core/Dictionary - * @deprecated 5.4 - */ -/** - * @constructor */ + +/** @deprecated 5.4 Use a `Map` instead. */ class Dictionary { private readonly _dictionary = new Map(); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts index 9a86a8e61d..34530cc99d 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Dom/Util.ts @@ -10,7 +10,6 @@ import * as StringUtil from '../StringUtil'; - function _isBoundaryNode(element: Element, ancestor: Element, position: string): boolean { if (!ancestor.contains(element)) { throw new Error('Ancestor element does not contain target element.'); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts index d860cee7a7..5dc855ca04 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/FileUtil.ts @@ -7,11 +7,9 @@ * @module WoltLabSuite/Core/FileUtil */ -import Dictionary from './Dictionary'; import * as StringUtil from './StringUtil'; - -const _fileExtensionIconMapping = Dictionary.fromObject({ +const _fileExtensionIconMapping = new Map(Object.entries({ // archive zip: 'archive', rar: 'archive', @@ -66,9 +64,9 @@ const _fileExtensionIconMapping = Dictionary.fromObject({ doc: 'word', docx: 'word', odt: 'word', -}); +})); -const _mimeTypeExtensionMapping = Dictionary.fromObject({ +const _mimeTypeExtensionMapping = new Map(Object.entries({ // archive 'application/zip': 'zip', 'application/x-zip-compressed': 'zip', @@ -125,7 +123,7 @@ const _mimeTypeExtensionMapping = Dictionary.fromObject({ 'application/msword': 'doc', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx', 'application/vnd.oasis.opendocument.text': 'odt', -}); +})); /** * Formats the given filesize. diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts index a2e4e14518..f88e1f4423 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/I18n/Plural.ts @@ -26,11 +26,11 @@ const Plural = { } // Fallback: handle unknown languages as English - if (typeof this[languageCode] !== 'function') { + if (typeof Plural[languageCode] !== 'function') { languageCode = 'en'; } - const category = this[languageCode](value); + const category = Plural[languageCode](value); if (category) { return category; } @@ -63,7 +63,7 @@ const Plural = { } } - let category = this.getCategory(value); + let category = Plural.getCategory(value); if (!parameters[category]) { category = PLURAL_OTHER; } @@ -156,8 +156,8 @@ const Plural = { // Bosnian bs(n: number): string | undefined { - const v = this.getV(n); - const f = this.getF(n); + const v = Plural.getV(n); + const f = Plural.getF(n); const mod10 = n % 10; const mod100 = n % 100; const fMod10 = f % 10; @@ -170,7 +170,7 @@ const Plural = { // Czech cs(n: number): string | undefined { - const v = this.getV(n); + const v = Plural.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; if (n >= 2 && n <= 4 && v === 0) return PLURAL_FEW; @@ -207,7 +207,7 @@ const Plural = { // Swahili (sw) // Urdu (ur) en(n: number): string | undefined { - if (n == 1 && this.getV(n) === 0) return PLURAL_ONE; + if (n == 1 && Plural.getV(n) === 0) return PLURAL_ONE; }, // Spanish @@ -245,7 +245,7 @@ const Plural = { // Hebrew he(n: number): string | undefined { - const v = this.getV(n); + const v = Plural.getV(n); if (n == 1 && v === 0) return PLURAL_ONE; if (n == 2 && v === 0) return PLURAL_TWO; @@ -260,7 +260,7 @@ const Plural = { // Croatian hr(n: number): string | undefined { // same as Bosnian - return this.bs(n); + return Plural.bs(n); }, // Hungarian @@ -279,7 +279,7 @@ const Plural = { // Icelandic is(n: number): string | undefined { - const f = this.getF(n); + const f = Plural.getF(n); if (f === 0 && n % 10 === 1 && !(n % 100 === 11) || !(f === 0)) return PLURAL_ONE; }, @@ -341,15 +341,15 @@ const Plural = { if (mod10 == 1 && !(mod100 >= 11 && mod100 <= 19)) return PLURAL_ONE; if (mod10 >= 2 && mod10 <= 9 && !(mod100 >= 11 && mod100 <= 19)) return PLURAL_FEW; - if (this.getF(n) != 0) return PLURAL_MANY; + if (Plural.getF(n) != 0) return PLURAL_MANY; }, // Latvian lv(n: number): string | undefined { const mod10 = n % 10; const mod100 = n % 100; - const v = this.getV(n); - const f = this.getF(n); + const v = Plural.getV(n); + const f = Plural.getF(n); const fMod10 = f % 10; const fMod100 = f % 100; @@ -359,7 +359,7 @@ const Plural = { // Macedonian mk(n: number): string | undefined { - return this.bs(n); + return Plural.bs(n); }, // Malayalam @@ -416,7 +416,7 @@ const Plural = { // Polish pl(n: number): string | undefined { - const v = this.getV(n); + const v = Plural.getV(n); const mod10 = n % 10; const mod100 = n % 100; @@ -437,7 +437,7 @@ const Plural = { // Romanian ro(n: number): string | undefined { - const v = this.getV(n); + const v = Plural.getV(n); const mod100 = n % 100; if (n == 1 && v === 0) return PLURAL_ONE; @@ -449,7 +449,7 @@ const Plural = { const mod10 = n % 10; const mod100 = n % 100; - if (this.getV(n) == 0) { + if (Plural.getV(n) == 0) { if (mod10 == 1 && mod100 != 11) return PLURAL_ONE; if (mod10 >= 2 && mod10 <= 4 && !(mod100 >= 12 && mod100 <= 14)) return PLURAL_FEW; if (mod10 == 0 || (mod10 >= 5 && mod10 <= 9) || (mod100 >= 11 && mod100 <= 14)) return PLURAL_MANY; @@ -463,18 +463,18 @@ const Plural = { // Sinhala si(n: number): string | undefined { - if (n == 0 || n == 1 || (Math.floor(n) == 0 && this.getF(n) == 1)) return PLURAL_ONE; + if (n == 0 || n == 1 || (Math.floor(n) == 0 && Plural.getF(n) == 1)) return PLURAL_ONE; }, // Slovak sk(n: number): string | undefined { // same as Czech - return this.cs(n); + return Plural.cs(n); }, // Slovenian sl(n: number): string | undefined { - const v = this.getV(n); + const v = Plural.getV(n); const mod100 = n % 100; if (v == 0 && mod100 == 1) return PLURAL_ONE; @@ -490,7 +490,7 @@ const Plural = { // Serbian sr(n: number): string | undefined { // same as Bosnian - return this.bs(n); + return Plural.bs(n); }, // Tamil @@ -529,7 +529,7 @@ const Plural = { // Ukrainian uk(n: number): string | undefined { // same as Russian - return this.ru(n); + return Plural.ru(n); }, // Uzbek diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Language.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Language.ts index 474750ec95..b34e46d761 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Language.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Language.ts @@ -7,16 +7,18 @@ * @module Language (alias) * @module WoltLabSuite/Core/Language */ -import Dictionary from './Dictionary'; + import Template from './Template'; -const _languageItems = new Dictionary(); +const _languageItems = new Map(); /** * Adds all the language items in the given object to the store. */ -export function addObject(object: object): void { - _languageItems.merge(Dictionary.fromObject(object)); +export function addObject(object: LanguageItems): void { + Object.keys(object).forEach(key => { + _languageItems.set(key, object[key]); + }); } /** @@ -62,3 +64,7 @@ export function get(key: string, parameters?: object): string { return value as string; } + +interface LanguageItems { + [key: string]: string; +} diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/List.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/List.ts index 4ac69f736b..3089ade938 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/List.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/List.ts @@ -7,9 +7,8 @@ * @module List (alias) * @module WoltLabSuite/Core/List */ -/** - * @constructor - */ + +/** @deprecated 5.4 Use a `Set` instead. */ class List { private _set = new Set(); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/ObjectMap.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/ObjectMap.ts index 755ebe7261..fd366c2af9 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/ObjectMap.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/ObjectMap.ts @@ -10,6 +10,7 @@ * @module WoltLabSuite/Core/ObjectMap */ +/** @deprecated 5.4 Use a `WeakMap` instead. */ class ObjectMap { private _map = new WeakMap(); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Permission.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Permission.ts index 09a83f8638..eec3e32d87 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Permission.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Permission.ts @@ -27,8 +27,7 @@ export function add(permission: string, value: boolean): void { export function addObject(object: PermissionObject): void { for (const key in object) { if (object.hasOwnProperty(key)) { - - this.add(key, object[key]); + add(key, object[key]); } } } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/StringUtil.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/StringUtil.ts index ed67d0f263..ae9747d869 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/StringUtil.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/StringUtil.ts @@ -7,6 +7,7 @@ * @module StringUtil (alias) * @module WoltLabSuite/Core/StringUtil */ + import * as Language from './Language'; import * as NumberUtil from './NumberUtil'; @@ -52,7 +53,7 @@ export function formatNumeric(number: number, decimalPlaces?: number): string { let tmp = NumberUtil.round(number, decimalPlaces || -2).toString(); const numberParts = tmp.split('.'); - tmp = this.addThousandsSeparator(+numberParts[0]); + tmp = addThousandsSeparator(+numberParts[0]); if (numberParts.length > 1) tmp += Language.get('wcf.global.decimalPoint') + numberParts[1]; tmp = tmp.replace('-', '\u2212'); @@ -109,5 +110,5 @@ export function shortUnit(number: number): string { unitSuffix = 'k'; } - return this.formatNumeric(number) + unitSuffix; + return formatNumeric(number) + unitSuffix; } diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Template.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Template.ts index 4131a88300..a5d71e4fa9 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Template.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Template.ts @@ -9,6 +9,7 @@ * @license GNU Lesser General Public License * @module WoltLabSuite/Core/Template */ + import * as parser from './Template.grammar'; import * as StringUtil from './StringUtil'; import * as Language from './Language'; @@ -24,12 +25,6 @@ Parser.prototype = parser; parser.Parser = Parser; parser = new Parser();*/ -/** - * Compiles the given template. - * - * @param {string} template Template to compile. - * @constructor - */ class Template { constructor(template: string) { // Fetch Language/StringUtil, as it cannot be provided because of a circular dependency diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/User.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/User.ts index a1a7b2d276..5676fb2183 100644 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/User.ts +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/User.ts @@ -20,26 +20,26 @@ export = { * Returns the link to the active user's profile or an empty string * if the active user is a guest. */ - getLink: (): string => { + getLink(): string { return user.link; }, /** * Initializes the user object. */ - init: (userId: number, username: string, link: string): void => { + init(userId: number, username: string, link: string): void { if (user) { throw new Error('User has already been initialized.'); } - + user = new User(userId, username, link); }, - + get userId(): number { return user.userId; }, - + get username(): string { return user.username; - } + }, }