maplibre-gl
Version:
BSD licensed community fork of mapbox-gl, a WebGL interactive maps library
120 lines (111 loc) • 2.6 kB
text/typescript
import {charHasRotatedVerticalOrientation} from './script_detection';
export const verticalizedCharacterMap = {
'!': '︕',
'#': '#',
'$': '$',
'%': '%',
'&': '&',
'(': '︵',
')': '︶',
'*': '*',
'+': '+',
',': '︐',
'-': '︲',
'.': '・',
'/': '/',
':': '︓',
';': '︔',
'<': '︿',
'=': '=',
'>': '﹀',
'?': '︖',
'@': '@',
'[': '﹇',
'\\': '\',
']': '﹈',
'^': '^',
'_': '︳',
'`': '`',
'{': '︷',
'|': '―',
'}': '︸',
'~': '~',
'¢': '¢',
'£': '£',
'¥': '¥',
'¦': '¦',
'¬': '¬',
'¯': ' ̄',
'–': '︲',
'—': '︱',
'‘': '﹃',
'’': '﹄',
'“': '﹁',
'”': '﹂',
'…': '︙',
'⋯': '︙',
'‧': '・',
'₩': '₩',
'、': '︑',
'。': '︒',
'〈': '︿',
'〉': '﹀',
'《': '︽',
'》': '︾',
'「': '﹁',
'」': '﹂',
'『': '﹃',
'』': '﹄',
'【': '︻',
'】': '︼',
'〔': '︹',
'〕': '︺',
'〖': '︗',
'〗': '︘',
'!': '︕',
'(': '︵',
')': '︶',
',': '︐',
'-': '︲',
'.': '・',
':': '︓',
';': '︔',
'<': '︿',
'>': '﹀',
'?': '︖',
'[': '﹇',
']': '﹈',
'_': '︳',
'{': '︷',
'|': '―',
'}': '︸',
'⦅': '︵',
'⦆': '︶',
'。': '︒',
'「': '﹁',
'」': '﹂'
};
export function verticalizePunctuation(input: string) {
let output = '';
let prevChar = {premature: true, value: undefined};
const chars = input[Symbol.iterator]();
let char = chars.next();
const nextChars = input[Symbol.iterator]();
nextChars.next();
let nextChar = nextChars.next();
while (!char.done) {
const canReplacePunctuation = (
(nextChar.done || !charHasRotatedVerticalOrientation(nextChar.value.codePointAt(0)) || verticalizedCharacterMap[nextChar.value]) &&
(prevChar.premature || !charHasRotatedVerticalOrientation(prevChar.value.codePointAt(0)) || verticalizedCharacterMap[prevChar.value])
);
if (canReplacePunctuation && verticalizedCharacterMap[char.value]) {
output += verticalizedCharacterMap[char.value];
} else {
output += char.value;
}
prevChar = {value: char.value, premature: false};
char = chars.next();
nextChar = nextChars.next();
}
return output;
}