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 {
}, (~~options.timeout || 10) * 1000);
window[callbackName] = function () {
window.clearTimeout(timeout);
+ //@ts-ignore
success.apply(null, arguments);
window[callbackName] = undefined;
script.parentNode.removeChild(script);
*/
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,
+ };
});
* 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;
/**
* Prints the list of available commands.
*/
- help: () => {
+ help() {
window.console.log('');
window.console.log('%cAvailable commands:', 'text-decoration: underline');
const commands = [];
/**
* 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');
/**
* 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');
* 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) {
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);
}
+/**
+ * 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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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 <http://opensource.org/licenses/lgpl-license.php>
- * @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();
__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',
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',
'application/msword': 'doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
'application/vnd.oasis.opendocument.text': 'odt',
- });
+ }));
/**
* Formats the given filesize.
*/
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;
}
return parameters[key];
}
}
- let category = this.getCategory(value);
+ let category = Plural.getCategory(value);
if (!parameters[category]) {
category = PLURAL_OTHER;
}
},
// 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;
},
// 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)
// Swahili (sw)
// Urdu (ur)
en(n) {
- if (n == 1 && this.getV(n) === 0)
+ if (n == 1 && Plural.getV(n) === 0)
return PLURAL_ONE;
},
// Spanish
},
// 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)
// Croatian
hr(n) {
// same as Bosnian
- return this.bs(n);
+ return Plural.bs(n);
},
// Hungarian
hu(n) {
},
// 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;
},
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))
},
// Macedonian
mk(n) {
- return this.bs(n);
+ return Plural.bs(n);
},
// Malayalam
ml(n) {
},
// 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)
},
// 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;
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))
},
// 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;
// Serbian
sr(n) {
// same as Bosnian
- return this.bs(n);
+ return Plural.bs(n);
},
// Tamil
ta(n) {
// Ukrainian
uk(n) {
// same as Russian
- return this.ru(n);
+ return Plural.ru(n);
},
// Uzbek
uz(n) {
+/**
+ * Manages language items.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;
/**
+/**
+ * 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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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 <http://opensource.org/licenses/lgpl-license.php>
- * @module List (alias)
- * @module WoltLabSuite/Core/List
- */
- /**
- * @constructor
- */
+ /** @deprecated 5.4 Use a `Set` instead. */
class List {
constructor() {
this._set = new Set();
*/
define(["require", "exports"], function (require, exports) {
"use strict";
+ /** @deprecated 5.4 Use a `WeakMap` instead. */
class ObjectMap {
constructor() {
this._map = new WeakMap();
function addObject(object) {
for (const key in object) {
if (object.hasOwnProperty(key)) {
- this.add(key, object[key]);
+ add(key, object[key]);
}
}
}
+/**
+ * Provides helper functions for String handling.
+ *
+ * @author Tim Duesterhus, Joshua Ruesweg
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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]; } });
}
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');
}
unitSuffix = 'k';
}
- return this.formatNumeric(number) + unitSuffix;
+ return formatNumeric(number) + unitSuffix;
}
exports.shortUnit = shortUnit;
});
+/**
+ * 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 <http://opensource.org/licenses/lgpl-license.php>
+ * @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]; } });
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
* 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.');
}
},
get username() {
return user.username;
- }
+ },
};
});
window[callbackName] = function () {
window.clearTimeout(timeout);
+ //@ts-ignore
success.apply(null, arguments);
window[callbackName] = undefined;
* @module WoltLabSuite/Core/CallbackList
*/
-type Callback = () => void;
-
class CallbackList {
private readonly _callbacks = new Map<string, Callback[]>();
}
}
+type Callback = () => void;
+
export = CallbackList;
* @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;
}
// WCF.ColorPicker compatibility (color format conversion)
-window.__wcf_bc_colorUtil = ColorUtil;
-
-export = ColorUtil;
+window.__wcf_bc_colorUtil = {
+ hexToRgb,
+ hsvToRgb,
+ rgbToHex,
+ rgbToHsv,
+};
return newObj;
};
-const _prefix = 'wsc' + window.WCF_PATH.hashCode() +'-';
+const _prefix = 'wsc' + window.WCF_PATH.hashCode() + '-';
/**
* Deep clones an object.
* 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);
}
/**
* Prints the list of available commands.
*/
- help: (): void => {
+ help(): void {
window.console.log('');
window.console.log('%cAvailable commands:', 'text-decoration: underline');
/**
* Disables/re-enables the editor autosave feature.
*/
- toggleEditorAutosave: (forceDisable: boolean): void => {
+ toggleEditorAutosave(forceDisable: boolean): void {
_settings.editorAutosave = forceDisable ? false : !_settings.editorAutosave;
_updateConfig();
/**
* Enables/disables logging for fired event listener events.
*/
- toggleEventLogging: function (forceEnable: boolean): void {
+ toggleEventLogging(forceEnable: boolean): void {
_settings.eventLogging = forceEnable ? true : !_settings.eventLogging;
_updateConfig();
* 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');
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);
}
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @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<number | string, any>();
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.');
* @module WoltLabSuite/Core/FileUtil
*/
-import Dictionary from './Dictionary';
import * as StringUtil from './StringUtil';
-
-const _fileExtensionIconMapping = Dictionary.fromObject({
+const _fileExtensionIconMapping = new Map<string, string>(Object.entries({
// archive
zip: 'archive',
rar: 'archive',
doc: 'word',
docx: 'word',
odt: 'word',
-});
+}));
-const _mimeTypeExtensionMapping = Dictionary.fromObject({
+const _mimeTypeExtensionMapping = new Map<string, string>(Object.entries({
// archive
'application/zip': 'zip',
'application/x-zip-compressed': 'zip',
'application/msword': 'doc',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
'application/vnd.oasis.opendocument.text': 'odt',
-});
+}));
/**
* Formats the given filesize.
}
// 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;
}
}
}
- let category = this.getCategory(value);
+ let category = Plural.getCategory(value);
if (!parameters[category]) {
category = PLURAL_OTHER;
}
// 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;
// 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;
// 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
// 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;
// Croatian
hr(n: number): string | undefined {
// same as Bosnian
- return this.bs(n);
+ return Plural.bs(n);
},
// Hungarian
// 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;
},
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;
// Macedonian
mk(n: number): string | undefined {
- return this.bs(n);
+ return Plural.bs(n);
},
// Malayalam
// Polish
pl(n: number): string | undefined {
- const v = this.getV(n);
+ const v = Plural.getV(n);
const mod10 = n % 10;
const mod100 = n % 100;
// 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;
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;
// 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;
// Serbian
sr(n: number): string | undefined {
// same as Bosnian
- return this.bs(n);
+ return Plural.bs(n);
},
// Tamil
// Ukrainian
uk(n: number): string | undefined {
// same as Russian
- return this.ru(n);
+ return Plural.ru(n);
},
// Uzbek
* @module Language (alias)
* @module WoltLabSuite/Core/Language
*/
-import Dictionary from './Dictionary';
+
import Template from './Template';
-const _languageItems = new Dictionary();
+const _languageItems = new Map<string, string | Template>();
/**
* 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]);
+ });
}
/**
return value as string;
}
+
+interface LanguageItems {
+ [key: string]: string;
+}
* @module List (alias)
* @module WoltLabSuite/Core/List
*/
-/**
- * @constructor
- */
+
+/** @deprecated 5.4 Use a `Set` instead. */
class List {
private _set = new Set<any>();
* @module WoltLabSuite/Core/ObjectMap
*/
+/** @deprecated 5.4 Use a `WeakMap` instead. */
class ObjectMap {
private _map = new WeakMap<object, object>();
export function addObject(object: PermissionObject): void {
for (const key in object) {
if (object.hasOwnProperty(key)) {
-
- this.add(key, object[key]);
+ add(key, object[key]);
}
}
}
* @module StringUtil (alias)
* @module WoltLabSuite/Core/StringUtil
*/
+
import * as Language from './Language';
import * as NumberUtil from './NumberUtil';
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');
unitSuffix = 'k';
}
- return this.formatNumeric(number) + unitSuffix;
+ return formatNumeric(number) + unitSuffix;
}
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLabSuite/Core/Template
*/
+
import * as parser from './Template.grammar';
import * as StringUtil from './StringUtil';
import * as Language from './Language';
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
* 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;
- }
+ },
}