@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
96 lines • 4.42 kB
JavaScript
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
/** Zero width invisible characters, i.e. they do not change the space between 2 other characters. */
var internalInvisibleZeroWidthCharacterCodePoints = [
{ codePoint: 11, label: "Vertical Tabulation" },
{ codePoint: 173, label: "Soft hyphen" },
{ codePoint: 847, label: "Combining grapheme joiner" },
{ codePoint: 1564, label: "Arabic letter mark" },
{ codePoint: [6068, 6069], label: "Khmer vowel inherent" },
{ codePoint: [6155, 6158], label: "Mongolian special characters" },
{ codePoint: 8203, label: "Zero Width Space" },
{ codePoint: 8204, label: "Zero Width Non-Joiner" },
{ codePoint: 8205, label: "Zero Width Joiner" },
{ codePoint: 8206, label: "Left-To-Right Mark" },
{ codePoint: 8207, label: "Right-To-Left Mark" },
{ codePoint: [8234, 8238], label: "zero width character" },
// Word joiner - Nominal Digit Shapes
{ codePoint: [8288, 8303], label: "zero width character" },
{ codePoint: [65024, 65039], label: "Variation selectors" },
{ codePoint: 65279, label: "Zero Width No-Break Space" },
{ codePoint: [65520, 65528], label: "Specials" },
{ codePoint: 65532, label: "Object Replacement Character" },
{ codePoint: [119155, 119162], label: "Invisible Musical Symbol" },
{ codePoint: [917504, 917631], label: "Tags" },
{ codePoint: [917760, 917999], label: "Variation Selectors" },
];
var toHex = function (codepoint) { return codepoint.toString(16).toUpperCase(); };
var padWithZeroes = function (hexString) {
if (hexString.length % 2 === 1) {
return "0".concat(hexString);
}
return hexString;
};
/** All characters that are considered invisible zero-width characters that e.g. need to be handled in input fields. */
var invisibleZeroWidthCharacterCodePoints = internalInvisibleZeroWidthCharacterCodePoints
.map(function (cp) {
var create = function (codePoint, label) {
var hexString = toHex(codePoint);
var unicodeHexRepresentation = "U+".concat(padWithZeroes(hexString));
return {
codePoint: codePoint,
label: label !== null && label !== void 0 ? label : unicodeHexRepresentation,
hexString: hexString,
fullLabel: label ? "".concat(label, " (").concat(unicodeHexRepresentation, ")") : unicodeHexRepresentation,
};
};
if (Array.isArray(cp.codePoint)) {
var codePoints = [];
var _a = __read(cp.codePoint, 2), from = _a[0], to = _a[1];
if (from < 0 || to < 0 || from > to) {
throw new Error("Invalid code point range specified: [".concat(from, ", ").concat(to, "]"));
}
for (var currentCp = from; currentCp <= to; currentCp++) {
codePoints.push(create(currentCp, cp.label));
}
return codePoints;
}
else {
return create(cp.codePoint, cp.label);
}
})
.flat();
var createInvisibleZeroWidthCharacterCodePointsRegex = function () {
return new RegExp("([".concat(invisibleZeroWidthCharacterCodePoints.map(function (cp) { return "\\u{".concat(cp.hexString, "}"); }).join(""), "])"), "ug");
};
/** Map from codepoint to invisible character. */
var invisibleZeroWidthCharacterCodePointsMap = new Map(invisibleZeroWidthCharacterCodePoints.map(function (cp) { return [cp.codePoint, cp]; }));
var clearStringFromInvisibleCharacters = function (inputString) {
var regex = createInvisibleZeroWidthCharacterCodePointsRegex();
return inputString.replaceAll(regex, "");
};
export var invisibleZeroWidthCharacters = {
codePoints: invisibleZeroWidthCharacterCodePoints,
codePointMap: invisibleZeroWidthCharacterCodePointsMap,
createRegex: createInvisibleZeroWidthCharacterCodePointsRegex,
clearString: clearStringFromInvisibleCharacters,
};
var moduleObject = {
invisibleZeroWidthCharacters: invisibleZeroWidthCharacters,
};
export default moduleObject;
//# sourceMappingURL=characters.js.map