Comparing version 2.0.4 to 2.1.0
@@ -26,2 +26,15 @@ # Change Log | ||
## [2.1.0] - 2017-07-09 | ||
### Added | ||
- Set `autocapitalize="none"` on bound input fields | ||
- Handle multiple event listeners with separate options | ||
- Increased test coverage | ||
### Fixed | ||
- Hold onto merged options for dom utils via closure instead of global | ||
- Keep track of event listeners for removal on unbind | ||
### Changed | ||
- `bind`, `unbind` are now named exports in 'wanakana/domUtils' | ||
## [2.0.4] - 2017-07-07 | ||
@@ -68,2 +81,3 @@ ### Fixed | ||
[2.1.0]: https://github.com/WaniKani/WanaKana/compare/2.0.4...2.1.0 | ||
[2.0.4]: https://github.com/WaniKani/WanaKana/compare/2.0.3...2.0.4 | ||
@@ -70,0 +84,0 @@ [2.0.3]: https://github.com/WaniKani/WanaKana/compare/2.0.2...2.0.3 |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _bind = require('./bind'); | ||
var _domUtils = require('./domUtils'); | ||
@@ -13,12 +13,9 @@ Object.defineProperty(exports, 'bind', { | ||
get: function get() { | ||
return _interopRequireDefault(_bind).default; | ||
return _domUtils.bind; | ||
} | ||
}); | ||
var _unbind = require('./unbind'); | ||
Object.defineProperty(exports, 'unbind', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_unbind).default; | ||
return _domUtils.unbind; | ||
} | ||
@@ -25,0 +22,0 @@ }); |
@@ -672,3 +672,85 @@ /** | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
/** | ||
* Converts all fullwidth roman letters in string to proper ASCII | ||
* @param {String} text Full Width roman letters | ||
* @return {String} ASCII | ||
*/ | ||
function convertFullwidthCharsToASCII() { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var asciiChars = [].concat(toConsumableArray(text)).map(function (char, index) { | ||
var code = char.charCodeAt(0); | ||
var lower = isCharInRange(char, LOWERCASE_FULLWIDTH_START, LOWERCASE_FULLWIDTH_END); | ||
var upper = isCharInRange(char, UPPERCASE_FULLWIDTH_START, UPPERCASE_FULLWIDTH_END); | ||
if (lower) { | ||
return String.fromCharCode(code - LOWERCASE_FULLWIDTH_START + LOWERCASE_START); | ||
} else if (upper) { | ||
return String.fromCharCode(code - UPPERCASE_FULLWIDTH_START + UPPERCASE_START); | ||
} | ||
return char; | ||
}); | ||
return asciiChars.join(''); | ||
} | ||
/** | ||
* Tests if char is in English unicode uppercase range | ||
@@ -836,62 +918,2 @@ * @param {String} char | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
/** | ||
@@ -1008,3 +1030,3 @@ * Test if `input` is [Kana](https://en.wikipedia.org/wiki/Kana) ([Katakana](https://en.wikipedia.org/wiki/Katakana) and/or [Hiragana](https://en.wikipedia.org/wiki/Hiragana)) | ||
kanaChar = FROM_ROMAJI[chunkLC]; | ||
// console.log(`${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
// console.log(`${chunkLC}, ${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
if (kanaChar != null) { | ||
@@ -1054,56 +1076,8 @@ break; | ||
/** | ||
* Converts all fullwidth roman letters in string to proper ASCII | ||
* @param {String} text Full Width roman letters | ||
* @return {String} ASCII | ||
*/ | ||
function convertFullwidthCharsToASCII() { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var ELEMENTS = ['TEXTAREA', 'INPUT']; | ||
var LISTENERS = []; | ||
var asciiChars = [].concat(toConsumableArray(text)).map(function (char, index) { | ||
var code = char.charCodeAt(0); | ||
var lower = isCharInRange(char, LOWERCASE_FULLWIDTH_START, LOWERCASE_FULLWIDTH_END); | ||
var upper = isCharInRange(char, UPPERCASE_FULLWIDTH_START, UPPERCASE_FULLWIDTH_END); | ||
if (lower) { | ||
return String.fromCharCode(code - LOWERCASE_FULLWIDTH_START + LOWERCASE_START); | ||
} else if (upper) { | ||
return String.fromCharCode(code - UPPERCASE_FULLWIDTH_START + UPPERCASE_START); | ||
} | ||
return char; | ||
}); | ||
return asciiChars.join(''); | ||
} | ||
/** | ||
* Automagically replaces input values with converted text to kana | ||
* @param {Object} event DOM event to listen to | ||
* @param {defaultOptions} [options] user config overrides, {IMEMode: true} cannot be changed | ||
* @ignore | ||
*/ | ||
function onInput(event) { | ||
var config = Object.assign({}, DEFAULT_OPTIONS, window.wanakanaOptions, { IMEMode: true }); | ||
var input = event.target; | ||
// const startingCursor = input.selectionStart; | ||
// const startingLength = input.value.length; | ||
var normalizedInputString = convertFullwidthCharsToASCII(input.value); | ||
var newText = toKana(normalizedInputString, config); | ||
if (normalizedInputString !== newText) { | ||
input.value = newText; | ||
if (typeof input.selectionStart === 'number') { | ||
input.selectionStart = input.value.length; | ||
input.selectionEnd = input.value.length; | ||
return; | ||
} | ||
if (typeof input.createTextRange !== 'undefined') { | ||
input.focus(); | ||
var range = input.createTextRange(); | ||
range.collapse(false); | ||
range.select(); | ||
} | ||
} | ||
} | ||
/** | ||
* Binds eventListener for 'input' events to an input field to automagically replace values with kana | ||
* It is recommended to set `autocapitalize="none"` on the input field to prevent mobile devices from forcing the first input character to katakana. | ||
* Sets`autocapitalize="none"` on the input field to prevent mobile devices forcing the first input character to katakana. | ||
* @param {HTMLElement} input textarea, input[type="text"] etc | ||
@@ -1115,4 +1089,10 @@ * @param {DefaultOptions} [options=defaultOptions] user config overrides | ||
window.wanakanaOptions = options; | ||
input.addEventListener('input', onInput); | ||
var listener = onInput(options); | ||
if (input instanceof Element && ELEMENTS.includes(input.nodeName)) { | ||
input.autocapitalize = 'none'; // eslint-disable-line no-param-reassign | ||
input.addEventListener('input', listener); | ||
LISTENERS = LISTENERS.concat({ id: input.getAttribute('id'), handler: listener }); | ||
} else { | ||
console.warn('Input provided to wanakana.bind was not a valid input field.'); // eslint-disable-line no-console | ||
} | ||
} | ||
@@ -1125,6 +1105,52 @@ | ||
function unbind(input) { | ||
input.removeEventListener('input', onInput); | ||
var found = LISTENERS.find(function (_ref) { | ||
var id = _ref.id; | ||
return id === input.id; | ||
}); | ||
if (found != null) { | ||
input.removeEventListener('input', found.handler); | ||
LISTENERS = LISTENERS.filter(function (entry) { | ||
return entry.handler !== found.handler; | ||
}); | ||
} else { | ||
console.warn('Input had no listener registered.'); // eslint-disable-line no-console | ||
} | ||
} | ||
/** | ||
* Automagically replaces input values with converted text to kana | ||
* @param {Object} event DOM event to listen to | ||
* @param {defaultOptions} [options] user config overrides, {IMEMode: true} cannot be changed | ||
* @return {Function} event handler with bound options | ||
* @ignore | ||
*/ | ||
function onInput(options) { | ||
var config = Object.assign({}, DEFAULT_OPTIONS, options, { IMEMode: true }); | ||
return function listener(event) { | ||
var input = event.target; | ||
// const startingCursor = input.selectionStart; | ||
// const startingLength = input.value.length; | ||
var normalizedInputString = convertFullwidthCharsToASCII(input.value); | ||
var newText = toKana(normalizedInputString, config); | ||
if (normalizedInputString !== newText) { | ||
input.value = newText; | ||
// Modern browsers, set cursor to the end of the new text | ||
if (input.setSelectionRange != null && typeof input.selectionStart === 'number') { | ||
input.setSelectionRange(input.value.length, input.value.length); | ||
return; | ||
} | ||
// < IE 9 | ||
if (input.createTextRange != null) { | ||
input.focus(); | ||
var range = input.createTextRange(); | ||
range.collapse(false); | ||
range.select(); | ||
} | ||
} | ||
}; | ||
} | ||
/** | ||
* Tests a character. Returns true if the character is [Romaji](https://en.wikipedia.org/wiki/Romaji) | ||
@@ -1131,0 +1157,0 @@ * @param {String} char character string to test |
@@ -678,3 +678,85 @@ (function (global, factory) { | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
/** | ||
* Converts all fullwidth roman letters in string to proper ASCII | ||
* @param {String} text Full Width roman letters | ||
* @return {String} ASCII | ||
*/ | ||
function convertFullwidthCharsToASCII() { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var asciiChars = [].concat(toConsumableArray(text)).map(function (char, index) { | ||
var code = char.charCodeAt(0); | ||
var lower = isCharInRange(char, LOWERCASE_FULLWIDTH_START, LOWERCASE_FULLWIDTH_END); | ||
var upper = isCharInRange(char, UPPERCASE_FULLWIDTH_START, UPPERCASE_FULLWIDTH_END); | ||
if (lower) { | ||
return String.fromCharCode(code - LOWERCASE_FULLWIDTH_START + LOWERCASE_START); | ||
} else if (upper) { | ||
return String.fromCharCode(code - UPPERCASE_FULLWIDTH_START + UPPERCASE_START); | ||
} | ||
return char; | ||
}); | ||
return asciiChars.join(''); | ||
} | ||
/** | ||
* Tests if char is in English unicode uppercase range | ||
@@ -842,62 +924,2 @@ * @param {String} char | ||
var slicedToArray = function () { | ||
function sliceIterator(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"]) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
return function (arr, i) { | ||
if (Array.isArray(arr)) { | ||
return arr; | ||
} else if (Symbol.iterator in Object(arr)) { | ||
return sliceIterator(arr, i); | ||
} else { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
}; | ||
}(); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
/** | ||
@@ -1014,3 +1036,3 @@ * Test if `input` is [Kana](https://en.wikipedia.org/wiki/Kana) ([Katakana](https://en.wikipedia.org/wiki/Katakana) and/or [Hiragana](https://en.wikipedia.org/wiki/Hiragana)) | ||
kanaChar = FROM_ROMAJI[chunkLC]; | ||
// console.log(`${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
// console.log(`${chunkLC}, ${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
if (kanaChar != null) { | ||
@@ -1060,56 +1082,8 @@ break; | ||
/** | ||
* Converts all fullwidth roman letters in string to proper ASCII | ||
* @param {String} text Full Width roman letters | ||
* @return {String} ASCII | ||
*/ | ||
function convertFullwidthCharsToASCII() { | ||
var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; | ||
var ELEMENTS = ['TEXTAREA', 'INPUT']; | ||
var LISTENERS = []; | ||
var asciiChars = [].concat(toConsumableArray(text)).map(function (char, index) { | ||
var code = char.charCodeAt(0); | ||
var lower = isCharInRange(char, LOWERCASE_FULLWIDTH_START, LOWERCASE_FULLWIDTH_END); | ||
var upper = isCharInRange(char, UPPERCASE_FULLWIDTH_START, UPPERCASE_FULLWIDTH_END); | ||
if (lower) { | ||
return String.fromCharCode(code - LOWERCASE_FULLWIDTH_START + LOWERCASE_START); | ||
} else if (upper) { | ||
return String.fromCharCode(code - UPPERCASE_FULLWIDTH_START + UPPERCASE_START); | ||
} | ||
return char; | ||
}); | ||
return asciiChars.join(''); | ||
} | ||
/** | ||
* Automagically replaces input values with converted text to kana | ||
* @param {Object} event DOM event to listen to | ||
* @param {defaultOptions} [options] user config overrides, {IMEMode: true} cannot be changed | ||
* @ignore | ||
*/ | ||
function onInput(event) { | ||
var config = Object.assign({}, DEFAULT_OPTIONS, window.wanakanaOptions, { IMEMode: true }); | ||
var input = event.target; | ||
// const startingCursor = input.selectionStart; | ||
// const startingLength = input.value.length; | ||
var normalizedInputString = convertFullwidthCharsToASCII(input.value); | ||
var newText = toKana(normalizedInputString, config); | ||
if (normalizedInputString !== newText) { | ||
input.value = newText; | ||
if (typeof input.selectionStart === 'number') { | ||
input.selectionStart = input.value.length; | ||
input.selectionEnd = input.value.length; | ||
return; | ||
} | ||
if (typeof input.createTextRange !== 'undefined') { | ||
input.focus(); | ||
var range = input.createTextRange(); | ||
range.collapse(false); | ||
range.select(); | ||
} | ||
} | ||
} | ||
/** | ||
* Binds eventListener for 'input' events to an input field to automagically replace values with kana | ||
* It is recommended to set `autocapitalize="none"` on the input field to prevent mobile devices from forcing the first input character to katakana. | ||
* Sets`autocapitalize="none"` on the input field to prevent mobile devices forcing the first input character to katakana. | ||
* @param {HTMLElement} input textarea, input[type="text"] etc | ||
@@ -1121,4 +1095,10 @@ * @param {DefaultOptions} [options=defaultOptions] user config overrides | ||
window.wanakanaOptions = options; | ||
input.addEventListener('input', onInput); | ||
var listener = onInput(options); | ||
if (input instanceof Element && ELEMENTS.includes(input.nodeName)) { | ||
input.autocapitalize = 'none'; // eslint-disable-line no-param-reassign | ||
input.addEventListener('input', listener); | ||
LISTENERS = LISTENERS.concat({ id: input.getAttribute('id'), handler: listener }); | ||
} else { | ||
console.warn('Input provided to wanakana.bind was not a valid input field.'); // eslint-disable-line no-console | ||
} | ||
} | ||
@@ -1131,6 +1111,52 @@ | ||
function unbind(input) { | ||
input.removeEventListener('input', onInput); | ||
var found = LISTENERS.find(function (_ref) { | ||
var id = _ref.id; | ||
return id === input.id; | ||
}); | ||
if (found != null) { | ||
input.removeEventListener('input', found.handler); | ||
LISTENERS = LISTENERS.filter(function (entry) { | ||
return entry.handler !== found.handler; | ||
}); | ||
} else { | ||
console.warn('Input had no listener registered.'); // eslint-disable-line no-console | ||
} | ||
} | ||
/** | ||
* Automagically replaces input values with converted text to kana | ||
* @param {Object} event DOM event to listen to | ||
* @param {defaultOptions} [options] user config overrides, {IMEMode: true} cannot be changed | ||
* @return {Function} event handler with bound options | ||
* @ignore | ||
*/ | ||
function onInput(options) { | ||
var config = Object.assign({}, DEFAULT_OPTIONS, options, { IMEMode: true }); | ||
return function listener(event) { | ||
var input = event.target; | ||
// const startingCursor = input.selectionStart; | ||
// const startingLength = input.value.length; | ||
var normalizedInputString = convertFullwidthCharsToASCII(input.value); | ||
var newText = toKana(normalizedInputString, config); | ||
if (normalizedInputString !== newText) { | ||
input.value = newText; | ||
// Modern browsers, set cursor to the end of the new text | ||
if (input.setSelectionRange != null && typeof input.selectionStart === 'number') { | ||
input.setSelectionRange(input.value.length, input.value.length); | ||
return; | ||
} | ||
// < IE 9 | ||
if (input.createTextRange != null) { | ||
input.focus(); | ||
var range = input.createTextRange(); | ||
range.collapse(false); | ||
range.select(); | ||
} | ||
} | ||
}; | ||
} | ||
/** | ||
* Tests a character. Returns true if the character is [Romaji](https://en.wikipedia.org/wiki/Romaji) | ||
@@ -1137,0 +1163,0 @@ * @param {String} char character string to test |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.wanakana=e.wanakana||{})}(this,function(e){"use strict";function n(e){return"string"!=typeof e||!e.length}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments[1],a=arguments[2];if(n(e))return!1;var r=e.charCodeAt(0);return r>=t&&a>=r}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&t(e,G,N)}function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return Math.min(e,n)}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=arguments[2];return e.slice(n,t)}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=1>=arguments.length||void 0===arguments[1]||arguments[1];if(n(e))return!1;var a=t?/[bcdfghjklmnpqrstvwxyz]/:/[bcdfghjklmnpqrstvwxz]/;return-1!==e.toLowerCase().charAt(0).search(a)}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=1>=arguments.length||void 0===arguments[1]||arguments[1];if(n(e))return!1;var a=t?/[aeiouy]/:/[aeiou]/;return-1!==e.toLowerCase().charAt(0).search(a)}function y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&e.charCodeAt(0)===ae}function h(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&e.charCodeAt(0)===re}function c(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(!!y(e)||t(e,Q,V))}function s(){var e=[];return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").split("").forEach(function(n){if(y(n)||h(n))e.push(n);else if(c(n)){var t=n.charCodeAt(0)+(W-Q),a=String.fromCharCode(t);e.push(a)}else e.push(n)}),e.join("")}function f(){return t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",W,X)}function v(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(c(e)||f(e))}function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(v)}function l(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},y=arguments.length>2&&void 0!==arguments[2]&&arguments[2],h=Object.assign({},_,n),c=[],f=0,v=e.length,l=3,g="",w="";v>f;){var p=null;for(l=r(3,v-f);l>0;){if(g=o(e,f,f+l),w=g.toLowerCase(),ie.includes(w)&&v-f>=4)w=(g=o(e,f,f+(l+=1))).toLowerCase();else{if("n"===w.charAt(0)){if(2===l){if(!h.IMEMode&&" "===w.charAt(1)){p="ん ";break}if(h.IMEMode&&"n'"===w){p="ん";break}}i(w.charAt(1),!1)&&u(w.charAt(2))&&(w=(g=o(e,f,f+(l=1))).toLowerCase())}"n"!==w.charAt(0)&&i(w.charAt(0))&&g.charAt(0)===g.charAt(1)&&(l=1,t(g.charAt(0),G,N)?(w="ッ",g="ッ"):(w="っ",g="っ"))}if(null!=(p=ue[w]))break;l-=4===l?2:1}null==p&&(p=g),h.useObsoleteKana&&("wi"===w&&(p="ゐ"),"we"===w&&(p="ゑ")),h.IMEMode&&"n"===w.charAt(0)&&("y"===e.charAt(f+1).toLowerCase()&&!1===u(e.charAt(f+2))||f===v-1||d(e.charAt(f+1)))&&(p=g.charAt(0)),y||a(g.charAt(0))&&(p=s(p)),c.push(p),f+=l||1}return c.join("")}function g(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return[].concat(ce(e)).map(function(e,n){var a=e.charCodeAt(0),r=t(e,$,ee),o=t(e,ne,te);return r?String.fromCharCode(a-$+F):o?String.fromCharCode(a-ne+G):e}).join("")}function w(e){var n=Object.assign({},_,window.wanakanaOptions,{IMEMode:!0}),t=e.target,a=g(t.value),r=l(a,n);if(a!==r){if(t.value=r,"number"==typeof t.selectionStart)return t.selectionStart=t.value.length,void(t.selectionEnd=t.value.length);if(void 0!==t.createTextRange){t.focus();var o=t.createTextRange();o.collapse(!1),o.select()}}}function p(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};window.wanakanaOptions=n,e.addEventListener("input",w)}function k(e){e.removeEventListener("input",w)}function m(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&J.test(e)}function b(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(function(e){return m(e)})}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(function(e){return D.test(e)})}function A(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(c)}function x(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(f)}function q(){return t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",Y,Z)}function C(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(q)}function z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{passKanji:!0},t=[].concat(ce(e)),a=!1;return n.passKanji||(a=t.some(C)),(t.some(A)||t.some(x))&&t.some(b)&&!a}function M(){for(var e=[],n="",t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").split(""),a=0;t.length>a;a+=1){var r=t[a],o=[h(r),y(r)],i=o[0],u=o[1];if(i||u&&1>a)e.push(r);else if(u&&a>0){var c=ye[n].slice(-1);e.push(oe[c])}else if(f(r)){var s=r.charCodeAt(0)+(Q-W),v=String.fromCharCode(s);e.push(v),n=v}else e.push(r),n=""}return e.join("")}function K(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},_,n),a=e.length,i=[],u=0,y=2,h="",c="",s=void 0;a>u;){y=r(2,a-u);for(var f=!1;y>0;){if(h=o(e,u,u+y),x(h)&&(f=t.upcaseKatakana,h=M(h)),"っ"===h.charAt(0)&&1===y&&a-1>u){s=!0,c="";break}if(null!=(c=ye[h])&&s&&(c=c.charAt(0).concat(c),s=!1),null!=c)break;y-=1}null==c&&(c=h),f&&(c=c.toUpperCase()),i.push(c),u+=y||1}return i.join("")}function O(){return l(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},!0)}function E(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},_,n);return t.passRomaji?M(e):b(e)?O(e,t):z(e,{passKanji:!0})?O(M(e),t):M(e)}function L(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},_,n);return s(t.passRomaji?e:b(e)||z(e)?O(e,t):e)}function S(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&U.some(function(n){var a=he(n,2);return t(e,a[0],a[1])})}function R(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return B.some(function(n){var a=he(n,2);return t(e,a[0],a[1])})}function I(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(S(e)||R(e))}function T(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{all:!1};if(n(e)||!j(e)||d(e))return e;var a=[].concat(ce(e));if(t.all)return a.filter(function(e){return!v(e)}).join("");for(var r=a.reverse(),o=0,i=r.length;i>o;o+=1){var u=r[o];if(!I(u)){if(C(u))break;r[o]=""}}return r.reverse().join("")}function H(e){switch(!0){case R(e):return"japanesePunctuation";case q(e):return"kanji";case c(e):return"hiragana";case f(e):return"katakana";default:return"romaji"}}function P(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(n(e))return[""];var t=[].concat(ce(e)),a=t.shift(),r=H(a);return t.reduce(function(e,n){var t=H(n)===r;if(r=H(n),t){var a=e.pop();return e.concat(a.concat(n))}return e.concat(n)},[a])}var _={useObsoleteKana:!1,passRomaji:!1,upcaseKatakana:!1,IMEMode:!1},D=/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff01-\uff0f\u4e00-\u9faf\u3400-\u4dbf]/,J=/[\u0000-\u007f\u0100-\u0101\u0112-\u0113\u012a-\u012b\u014c-\u014d\u016a-\u016b\u2018-\u2019\u201C-\u201D]/,U=[[33,47],[58,63],[91,96],[123,126],[8216,8217],[8220,8221]],B=[[12289,12350],[12539,12540],[65281,65295],[65306,65311],[65339,65343],[65371,65376]],F=97,G=65,N=90,Q=12353,V=12438,W=12449,X=12540,Y=19968,Z=40879,$=65345,ee=65370,ne=65313,te=65338,ae=12540,re=12539,oe={a:"あ",i:"い",u:"う",e:"え",o:"う"},ie=["lts","chy","shy"],ue={".":"。",",":"、",":":":","/":"・","!":"!","?":"?","~":"〜","-":"ー","‘":"「","’":"」","“":"『","”":"』","[":"[","]":"]","(":"(",")":")","{":"{","}":"}",a:"あ",i:"い",u:"う",e:"え",o:"お",yi:"い",wu:"う",whu:"う",xa:"ぁ",xi:"ぃ",xu:"ぅ",xe:"ぇ",xo:"ぉ",xyi:"ぃ",xye:"ぇ",ye:"いぇ",wha:"うぁ",whi:"うぃ",whe:"うぇ",who:"うぉ",wi:"うぃ",we:"うぇ",va:"ゔぁ",vi:"ゔぃ",vu:"ゔ",ve:"ゔぇ",vo:"ゔぉ",vya:"ゔゃ",vyi:"ゔぃ",vyu:"ゔゅ",vye:"ゔぇ",vyo:"ゔょ",ka:"か",ki:"き",ku:"く",ke:"け",ko:"こ",lka:"ヵ",lke:"ヶ",xka:"ヵ",xke:"ヶ",kya:"きゃ",kyi:"きぃ",kyu:"きゅ",kye:"きぇ",kyo:"きょ",ca:"か",ci:"き",cu:"く",ce:"け",co:"こ",lca:"ヵ",lce:"ヶ",xca:"ヵ",xce:"ヶ",qya:"くゃ",qyu:"くゅ",qyo:"くょ",qwa:"くぁ",qwi:"くぃ",qwu:"くぅ",qwe:"くぇ",qwo:"くぉ",qa:"くぁ",qi:"くぃ",qe:"くぇ",qo:"くぉ",kwa:"くぁ",qyi:"くぃ",qye:"くぇ",ga:"が",gi:"ぎ",gu:"ぐ",ge:"げ",go:"ご",gya:"ぎゃ",gyi:"ぎぃ",gyu:"ぎゅ",gye:"ぎぇ",gyo:"ぎょ",gwa:"ぐぁ",gwi:"ぐぃ",gwu:"ぐぅ",gwe:"ぐぇ",gwo:"ぐぉ",sa:"さ",si:"し",shi:"し",su:"す",se:"せ",so:"そ",za:"ざ",zi:"じ",zu:"ず",ze:"ぜ",zo:"ぞ",ji:"じ",sya:"しゃ",syi:"しぃ",syu:"しゅ",sye:"しぇ",syo:"しょ",sha:"しゃ",shu:"しゅ",she:"しぇ",sho:"しょ",shya:"しゃ",shyu:"しゅ",shye:"しぇ",shyo:"しょ",swa:"すぁ",swi:"すぃ",swu:"すぅ",swe:"すぇ",swo:"すぉ",zya:"じゃ",zyi:"じぃ",zyu:"じゅ",zye:"じぇ",zyo:"じょ",ja:"じゃ",ju:"じゅ",je:"じぇ",jo:"じょ",jya:"じゃ",jyi:"じぃ",jyu:"じゅ",jye:"じぇ",jyo:"じょ",ta:"た",ti:"ち",tu:"つ",te:"て",to:"と",chi:"ち",tsu:"つ",ltu:"っ",xtu:"っ",tya:"ちゃ",tyi:"ちぃ",tyu:"ちゅ",tye:"ちぇ",tyo:"ちょ",cha:"ちゃ",chu:"ちゅ",che:"ちぇ",cho:"ちょ",cya:"ちゃ",cyi:"ちぃ",cyu:"ちゅ",cye:"ちぇ",cyo:"ちょ",chya:"ちゃ",chyu:"ちゅ",chye:"ちぇ",chyo:"ちょ",tsa:"つぁ",tsi:"つぃ",tse:"つぇ",tso:"つぉ",tha:"てゃ",thi:"てぃ",thu:"てゅ",the:"てぇ",tho:"てょ",twa:"とぁ",twi:"とぃ",twu:"とぅ",twe:"とぇ",two:"とぉ",da:"だ",di:"ぢ",du:"づ",de:"で",do:"ど",dya:"ぢゃ",dyi:"ぢぃ",dyu:"ぢゅ",dye:"ぢぇ",dyo:"ぢょ",dha:"でゃ",dhi:"でぃ",dhu:"でゅ",dhe:"でぇ",dho:"でょ",dwa:"どぁ",dwi:"どぃ",dwu:"どぅ",dwe:"どぇ",dwo:"どぉ",na:"な",ni:"に",nu:"ぬ",ne:"ね",no:"の",nya:"にゃ",nyi:"にぃ",nyu:"にゅ",nye:"にぇ",nyo:"にょ",ha:"は",hi:"ひ",hu:"ふ",he:"へ",ho:"ほ",fu:"ふ",hya:"ひゃ",hyi:"ひぃ",hyu:"ひゅ",hye:"ひぇ",hyo:"ひょ",fya:"ふゃ",fyu:"ふゅ",fyo:"ふょ",fwa:"ふぁ",fwi:"ふぃ",fwu:"ふぅ",fwe:"ふぇ",fwo:"ふぉ",fa:"ふぁ",fi:"ふぃ",fe:"ふぇ",fo:"ふぉ",fyi:"ふぃ",fye:"ふぇ",ba:"ば",bi:"び",bu:"ぶ",be:"べ",bo:"ぼ",bya:"びゃ",byi:"びぃ",byu:"びゅ",bye:"びぇ",byo:"びょ",pa:"ぱ",pi:"ぴ",pu:"ぷ",pe:"ぺ",po:"ぽ",pya:"ぴゃ",pyi:"ぴぃ",pyu:"ぴゅ",pye:"ぴぇ",pyo:"ぴょ",ma:"ま",mi:"み",mu:"む",me:"め",mo:"も",mya:"みゃ",myi:"みぃ",myu:"みゅ",mye:"みぇ",myo:"みょ",ya:"や",yu:"ゆ",yo:"よ",xya:"ゃ",xyu:"ゅ",xyo:"ょ",ra:"ら",ri:"り",ru:"る",re:"れ",ro:"ろ",rya:"りゃ",ryi:"りぃ",ryu:"りゅ",rye:"りぇ",ryo:"りょ",la:"ら",li:"り",lu:"る",le:"れ",lo:"ろ",lya:"りゃ",lyi:"りぃ",lyu:"りゅ",lye:"りぇ",lyo:"りょ",wa:"わ",wo:"を",lwe:"ゎ",xwa:"ゎ",n:"ん",nn:"ん","n'":"ん","n ":"ん",xn:"ん",ltsu:"っ"},ye={" ":" ","!":"!","?":"?","。":".",":":":","・":"/","、":",","〜":"~","ー":"-","「":"‘","」":"’","『":"“","』":"”","[":"[","]":"]","(":"(",")":")","{":"{","}":"}","あ":"a","い":"i","う":"u","え":"e","お":"o","ゔぁ":"va","ゔぃ":"vi","ゔ":"vu","ゔぇ":"ve","ゔぉ":"vo","か":"ka","き":"ki","きゃ":"kya","きぃ":"kyi","きゅ":"kyu","く":"ku","け":"ke","こ":"ko","が":"ga","ぎ":"gi","ぐ":"gu","げ":"ge","ご":"go","ぎゃ":"gya","ぎぃ":"gyi","ぎゅ":"gyu","ぎぇ":"gye","ぎょ":"gyo","さ":"sa","す":"su","せ":"se","そ":"so","ざ":"za","ず":"zu","ぜ":"ze","ぞ":"zo","し":"shi","しゃ":"sha","しゅ":"shu","しょ":"sho","じ":"ji","じゃ":"ja","じゅ":"ju","じょ":"jo","た":"ta","ち":"chi","ちゃ":"cha","ちゅ":"chu","ちょ":"cho","つ":"tsu","て":"te","と":"to","だ":"da","ぢ":"di","づ":"du","で":"de","ど":"do","な":"na","に":"ni","にゃ":"nya","にゅ":"nyu","にょ":"nyo","ぬ":"nu","ね":"ne","の":"no","は":"ha","ひ":"hi","ふ":"fu","へ":"he","ほ":"ho","ひゃ":"hya","ひゅ":"hyu","ひょ":"hyo","ふぁ":"fa","ふぃ":"fi","ふぇ":"fe","ふぉ":"fo","ば":"ba","び":"bi","ぶ":"bu","べ":"be","ぼ":"bo","びゃ":"bya","びゅ":"byu","びょ":"byo","ぱ":"pa","ぴ":"pi","ぷ":"pu","ぺ":"pe","ぽ":"po","ぴゃ":"pya","ぴゅ":"pyu","ぴょ":"pyo","ま":"ma","み":"mi","む":"mu","め":"me","も":"mo","みゃ":"mya","みゅ":"myu","みょ":"myo","や":"ya","ゆ":"yu","よ":"yo","ら":"ra","り":"ri","る":"ru","れ":"re","ろ":"ro","りゃ":"rya","りゅ":"ryu","りょ":"ryo","わ":"wa","を":"wo","ん":"n","ゐ":"wi","ゑ":"we","きぇ":"kye","きょ":"kyo","じぃ":"jyi","じぇ":"jye","ちぃ":"cyi","ちぇ":"che","ひぃ":"hyi","ひぇ":"hye","びぃ":"byi","びぇ":"bye","ぴぃ":"pyi","ぴぇ":"pye","みぇ":"mye","みぃ":"myi","りぃ":"ryi","りぇ":"rye","にぃ":"nyi","にぇ":"nye","しぃ":"syi","しぇ":"she","いぇ":"ye","うぁ":"wha","うぉ":"who","うぃ":"wi","うぇ":"we","ゔゃ":"vya","ゔゅ":"vyu","ゔょ":"vyo","すぁ":"swa","すぃ":"swi","すぅ":"swu","すぇ":"swe","すぉ":"swo","くゃ":"qya","くゅ":"qyu","くょ":"qyo","くぁ":"qwa","くぃ":"qwi","くぅ":"qwu","くぇ":"qwe","くぉ":"qwo","ぐぁ":"gwa","ぐぃ":"gwi","ぐぅ":"gwu","ぐぇ":"gwe","ぐぉ":"gwo","つぁ":"tsa","つぃ":"tsi","つぇ":"tse","つぉ":"tso","てゃ":"tha","てぃ":"thi","てゅ":"thu","てぇ":"the","てょ":"tho","とぁ":"twa","とぃ":"twi","とぅ":"twu","とぇ":"twe","とぉ":"two","ぢゃ":"dya","ぢぃ":"dyi","ぢゅ":"dyu","ぢぇ":"dye","ぢょ":"dyo","でゃ":"dha","でぃ":"dhi","でゅ":"dhu","でぇ":"dhe","でょ":"dho","どぁ":"dwa","どぃ":"dwi","どぅ":"dwu","どぇ":"dwe","どぉ":"dwo","ふぅ":"fwu","ふゃ":"fya","ふゅ":"fyu","ふょ":"fyo","ぁ":"a","ぃ":"i","ぇ":"e","ぅ":"u","ぉ":"o","ゃ":"ya","ゅ":"yu","ょ":"yo","っ":"","ゕ":"ka","ゖ":"ka","ゎ":"wa","んあ":"n'a","んい":"n'i","んう":"n'u","んえ":"n'e","んお":"n'o","んや":"n'ya","んゆ":"n'yu","んよ":"n'yo"},he=function(){function e(e,n){var t=[],a=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(a=(i=u.next()).done)&&(t.push(i.value),!n||t.length!==n);a=!0);}catch(e){r=!0,o=e}finally{try{!a&&u.return&&u.return()}finally{if(r)throw o}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),ce=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);e.length>n;n++)t[n]=e[n];return t}return Array.from(e)};e.bind=p,e.unbind=k,e.isRomaji=b,e.isJapanese=j,e.isKana=d,e.isHiragana=A,e.isKatakana=x,e.isMixed=z,e.isKanji=C,e.toRomaji=K,e.toKana=l,e.toHiragana=E,e.toKatakana=L,e.stripOkurigana=T,e.tokenize=P,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.wanakana=e.wanakana||{})}(this,function(e){"use strict";function n(e){return"string"!=typeof e||!e.length}function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments[1],a=arguments[2];if(n(e))return!1;var r=e.charCodeAt(0);return r>=t&&a>=r}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return[].concat(ce(e)).map(function(e,n){var a=e.charCodeAt(0),r=t(e,$,ee),o=t(e,ne,te);return r?String.fromCharCode(a-$+X):o?String.fromCharCode(a-ne+B):e}).join("")}function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&t(e,B,F)}function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return Math.min(e,n)}function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=arguments[2];return e.slice(n,t)}function u(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=1>=arguments.length||void 0===arguments[1]||arguments[1];if(n(e))return!1;var a=t?/[bcdfghjklmnpqrstvwxyz]/:/[bcdfghjklmnpqrstvwxz]/;return-1!==e.toLowerCase().charAt(0).search(a)}function y(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=1>=arguments.length||void 0===arguments[1]||arguments[1];if(n(e))return!1;var a=t?/[aeiouy]/:/[aeiou]/;return-1!==e.toLowerCase().charAt(0).search(a)}function h(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&e.charCodeAt(0)===ae}function c(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&e.charCodeAt(0)===re}function s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(!!h(e)||t(e,G,Q))}function f(){var e=[];return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").split("").forEach(function(n){if(h(n)||c(n))e.push(n);else if(s(n)){var t=n.charCodeAt(0)+(V-G),a=String.fromCharCode(t);e.push(a)}else e.push(n)}),e.join("")}function l(){return t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",V,W)}function d(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(s(e)||l(e))}function v(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(d)}function g(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],h=Object.assign({},N,n),c=[],s=0,l=e.length,d=3,g="",w="";l>s;){var p=null;for(d=o(3,l-s);d>0;){if(g=i(e,s,s+d),w=g.toLowerCase(),ie.includes(w)&&l-s>=4)w=(g=i(e,s,s+(d+=1))).toLowerCase();else{if("n"===w.charAt(0)){if(2===d){if(!h.IMEMode&&" "===w.charAt(1)){p="ん ";break}if(h.IMEMode&&"n'"===w){p="ん";break}}u(w.charAt(1),!1)&&y(w.charAt(2))&&(w=(g=i(e,s,s+(d=1))).toLowerCase())}"n"!==w.charAt(0)&&u(w.charAt(0))&&g.charAt(0)===g.charAt(1)&&(d=1,t(g.charAt(0),B,F)?(w="ッ",g="ッ"):(w="っ",g="っ"))}if(null!=(p=ue[w]))break;d-=4===d?2:1}null==p&&(p=g),h.useObsoleteKana&&("wi"===w&&(p="ゐ"),"we"===w&&(p="ゑ")),h.IMEMode&&"n"===w.charAt(0)&&("y"===e.charAt(s+1).toLowerCase()&&!1===y(e.charAt(s+2))||s===l-1||v(e.charAt(s+1)))&&(p=g.charAt(0)),a||r(g.charAt(0))&&(p=f(p)),c.push(p),s+=d||1}return c.join("")}function w(e){var n=m(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{});e instanceof Element&&se.includes(e.nodeName)?(e.autocapitalize="none",e.addEventListener("input",n),fe=fe.concat({id:e.getAttribute("id"),handler:n})):console.warn("Input provided to wanakana.bind was not a valid input field.")}function p(e){var n=fe.find(function(n){return n.id===e.id});null!=n?(e.removeEventListener("input",n.handler),fe=fe.filter(function(e){return e.handler!==n.handler})):console.warn("Input had no listener registered.")}function m(e){var n=Object.assign({},N,e,{IMEMode:!0});return function(e){var t=e.target,r=a(t.value),o=g(r,n);if(r!==o){if(t.value=o,null!=t.setSelectionRange&&"number"==typeof t.selectionStart)return void t.setSelectionRange(t.value.length,t.value.length);if(null!=t.createTextRange){t.focus();var i=t.createTextRange();i.collapse(!1),i.select()}}}}function b(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&_.test(e)}function k(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(function(e){return b(e)})}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(function(e){return U.test(e)})}function A(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(s)}function x(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(l)}function q(){return t(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",Y,Z)}function C(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&[].concat(ce(e)).every(q)}function z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{passKanji:!0},t=[].concat(ce(e)),a=!1;return n.passKanji||(a=t.some(C)),(t.some(A)||t.some(x))&&t.some(k)&&!a}function M(){for(var e=[],n="",t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").split(""),a=0;t.length>a;a+=1){var r=t[a],o=[c(r),h(r)],i=o[0],u=o[1];if(i||u&&1>a)e.push(r);else if(u&&a>0){var y=ye[n].slice(-1);e.push(oe[y])}else if(l(r)){var s=r.charCodeAt(0)+(G-V),f=String.fromCharCode(s);e.push(f),n=f}else e.push(r),n=""}return e.join("")}function E(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},N,n),a=e.length,r=[],u=0,y=2,h="",c="",s=void 0;a>u;){y=o(2,a-u);for(var f=!1;y>0;){if(h=i(e,u,u+y),x(h)&&(f=t.upcaseKatakana,h=M(h)),"っ"===h.charAt(0)&&1===y&&a-1>u){s=!0,c="";break}if(null!=(c=ye[h])&&s&&(c=c.charAt(0).concat(c),s=!1),null!=c)break;y-=1}null==c&&(c=h),f&&(c=c.toUpperCase()),r.push(c),u+=y||1}return r.join("")}function K(){return g(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},!0)}function O(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},N,n);return t.passRomaji?M(e):k(e)?K(e,t):z(e,{passKanji:!0})?K(M(e),t):M(e)}function R(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=Object.assign({},N,n);return f(t.passRomaji?e:k(e)||z(e)?K(e,t):e)}function I(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&D.some(function(n){var a=he(n,2);return t(e,a[0],a[1])})}function S(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return J.some(function(n){var a=he(n,2);return t(e,a[0],a[1])})}function L(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return!n(e)&&(I(e)||S(e))}function T(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{all:!1};if(n(e)||!j(e)||v(e))return e;var a=[].concat(ce(e));if(t.all)return a.filter(function(e){return!d(e)}).join("");for(var r=a.reverse(),o=0,i=r.length;i>o;o+=1){var u=r[o];if(!L(u)){if(C(u))break;r[o]=""}}return r.reverse().join("")}function P(e){switch(!0){case S(e):return"japanesePunctuation";case q(e):return"kanji";case s(e):return"hiragana";case l(e):return"katakana";default:return"romaji"}}function H(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if(n(e))return[""];var t=[].concat(ce(e)),a=t.shift(),r=P(a);return t.reduce(function(e,n){var t=P(n)===r;if(r=P(n),t){var a=e.pop();return e.concat(a.concat(n))}return e.concat(n)},[a])}var N={useObsoleteKana:!1,passRomaji:!1,upcaseKatakana:!1,IMEMode:!1},U=/[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff01-\uff0f\u4e00-\u9faf\u3400-\u4dbf]/,_=/[\u0000-\u007f\u0100-\u0101\u0112-\u0113\u012a-\u012b\u014c-\u014d\u016a-\u016b\u2018-\u2019\u201C-\u201D]/,D=[[33,47],[58,63],[91,96],[123,126],[8216,8217],[8220,8221]],J=[[12289,12350],[12539,12540],[65281,65295],[65306,65311],[65339,65343],[65371,65376]],X=97,B=65,F=90,G=12353,Q=12438,V=12449,W=12540,Y=19968,Z=40879,$=65345,ee=65370,ne=65313,te=65338,ae=12540,re=12539,oe={a:"あ",i:"い",u:"う",e:"え",o:"う"},ie=["lts","chy","shy"],ue={".":"。",",":"、",":":":","/":"・","!":"!","?":"?","~":"〜","-":"ー","‘":"「","’":"」","“":"『","”":"』","[":"[","]":"]","(":"(",")":")","{":"{","}":"}",a:"あ",i:"い",u:"う",e:"え",o:"お",yi:"い",wu:"う",whu:"う",xa:"ぁ",xi:"ぃ",xu:"ぅ",xe:"ぇ",xo:"ぉ",xyi:"ぃ",xye:"ぇ",ye:"いぇ",wha:"うぁ",whi:"うぃ",whe:"うぇ",who:"うぉ",wi:"うぃ",we:"うぇ",va:"ゔぁ",vi:"ゔぃ",vu:"ゔ",ve:"ゔぇ",vo:"ゔぉ",vya:"ゔゃ",vyi:"ゔぃ",vyu:"ゔゅ",vye:"ゔぇ",vyo:"ゔょ",ka:"か",ki:"き",ku:"く",ke:"け",ko:"こ",lka:"ヵ",lke:"ヶ",xka:"ヵ",xke:"ヶ",kya:"きゃ",kyi:"きぃ",kyu:"きゅ",kye:"きぇ",kyo:"きょ",ca:"か",ci:"き",cu:"く",ce:"け",co:"こ",lca:"ヵ",lce:"ヶ",xca:"ヵ",xce:"ヶ",qya:"くゃ",qyu:"くゅ",qyo:"くょ",qwa:"くぁ",qwi:"くぃ",qwu:"くぅ",qwe:"くぇ",qwo:"くぉ",qa:"くぁ",qi:"くぃ",qe:"くぇ",qo:"くぉ",kwa:"くぁ",qyi:"くぃ",qye:"くぇ",ga:"が",gi:"ぎ",gu:"ぐ",ge:"げ",go:"ご",gya:"ぎゃ",gyi:"ぎぃ",gyu:"ぎゅ",gye:"ぎぇ",gyo:"ぎょ",gwa:"ぐぁ",gwi:"ぐぃ",gwu:"ぐぅ",gwe:"ぐぇ",gwo:"ぐぉ",sa:"さ",si:"し",shi:"し",su:"す",se:"せ",so:"そ",za:"ざ",zi:"じ",zu:"ず",ze:"ぜ",zo:"ぞ",ji:"じ",sya:"しゃ",syi:"しぃ",syu:"しゅ",sye:"しぇ",syo:"しょ",sha:"しゃ",shu:"しゅ",she:"しぇ",sho:"しょ",shya:"しゃ",shyu:"しゅ",shye:"しぇ",shyo:"しょ",swa:"すぁ",swi:"すぃ",swu:"すぅ",swe:"すぇ",swo:"すぉ",zya:"じゃ",zyi:"じぃ",zyu:"じゅ",zye:"じぇ",zyo:"じょ",ja:"じゃ",ju:"じゅ",je:"じぇ",jo:"じょ",jya:"じゃ",jyi:"じぃ",jyu:"じゅ",jye:"じぇ",jyo:"じょ",ta:"た",ti:"ち",tu:"つ",te:"て",to:"と",chi:"ち",tsu:"つ",ltu:"っ",xtu:"っ",tya:"ちゃ",tyi:"ちぃ",tyu:"ちゅ",tye:"ちぇ",tyo:"ちょ",cha:"ちゃ",chu:"ちゅ",che:"ちぇ",cho:"ちょ",cya:"ちゃ",cyi:"ちぃ",cyu:"ちゅ",cye:"ちぇ",cyo:"ちょ",chya:"ちゃ",chyu:"ちゅ",chye:"ちぇ",chyo:"ちょ",tsa:"つぁ",tsi:"つぃ",tse:"つぇ",tso:"つぉ",tha:"てゃ",thi:"てぃ",thu:"てゅ",the:"てぇ",tho:"てょ",twa:"とぁ",twi:"とぃ",twu:"とぅ",twe:"とぇ",two:"とぉ",da:"だ",di:"ぢ",du:"づ",de:"で",do:"ど",dya:"ぢゃ",dyi:"ぢぃ",dyu:"ぢゅ",dye:"ぢぇ",dyo:"ぢょ",dha:"でゃ",dhi:"でぃ",dhu:"でゅ",dhe:"でぇ",dho:"でょ",dwa:"どぁ",dwi:"どぃ",dwu:"どぅ",dwe:"どぇ",dwo:"どぉ",na:"な",ni:"に",nu:"ぬ",ne:"ね",no:"の",nya:"にゃ",nyi:"にぃ",nyu:"にゅ",nye:"にぇ",nyo:"にょ",ha:"は",hi:"ひ",hu:"ふ",he:"へ",ho:"ほ",fu:"ふ",hya:"ひゃ",hyi:"ひぃ",hyu:"ひゅ",hye:"ひぇ",hyo:"ひょ",fya:"ふゃ",fyu:"ふゅ",fyo:"ふょ",fwa:"ふぁ",fwi:"ふぃ",fwu:"ふぅ",fwe:"ふぇ",fwo:"ふぉ",fa:"ふぁ",fi:"ふぃ",fe:"ふぇ",fo:"ふぉ",fyi:"ふぃ",fye:"ふぇ",ba:"ば",bi:"び",bu:"ぶ",be:"べ",bo:"ぼ",bya:"びゃ",byi:"びぃ",byu:"びゅ",bye:"びぇ",byo:"びょ",pa:"ぱ",pi:"ぴ",pu:"ぷ",pe:"ぺ",po:"ぽ",pya:"ぴゃ",pyi:"ぴぃ",pyu:"ぴゅ",pye:"ぴぇ",pyo:"ぴょ",ma:"ま",mi:"み",mu:"む",me:"め",mo:"も",mya:"みゃ",myi:"みぃ",myu:"みゅ",mye:"みぇ",myo:"みょ",ya:"や",yu:"ゆ",yo:"よ",xya:"ゃ",xyu:"ゅ",xyo:"ょ",ra:"ら",ri:"り",ru:"る",re:"れ",ro:"ろ",rya:"りゃ",ryi:"りぃ",ryu:"りゅ",rye:"りぇ",ryo:"りょ",la:"ら",li:"り",lu:"る",le:"れ",lo:"ろ",lya:"りゃ",lyi:"りぃ",lyu:"りゅ",lye:"りぇ",lyo:"りょ",wa:"わ",wo:"を",lwe:"ゎ",xwa:"ゎ",n:"ん",nn:"ん","n'":"ん","n ":"ん",xn:"ん",ltsu:"っ"},ye={" ":" ","!":"!","?":"?","。":".",":":":","・":"/","、":",","〜":"~","ー":"-","「":"‘","」":"’","『":"“","』":"”","[":"[","]":"]","(":"(",")":")","{":"{","}":"}","あ":"a","い":"i","う":"u","え":"e","お":"o","ゔぁ":"va","ゔぃ":"vi","ゔ":"vu","ゔぇ":"ve","ゔぉ":"vo","か":"ka","き":"ki","きゃ":"kya","きぃ":"kyi","きゅ":"kyu","く":"ku","け":"ke","こ":"ko","が":"ga","ぎ":"gi","ぐ":"gu","げ":"ge","ご":"go","ぎゃ":"gya","ぎぃ":"gyi","ぎゅ":"gyu","ぎぇ":"gye","ぎょ":"gyo","さ":"sa","す":"su","せ":"se","そ":"so","ざ":"za","ず":"zu","ぜ":"ze","ぞ":"zo","し":"shi","しゃ":"sha","しゅ":"shu","しょ":"sho","じ":"ji","じゃ":"ja","じゅ":"ju","じょ":"jo","た":"ta","ち":"chi","ちゃ":"cha","ちゅ":"chu","ちょ":"cho","つ":"tsu","て":"te","と":"to","だ":"da","ぢ":"di","づ":"du","で":"de","ど":"do","な":"na","に":"ni","にゃ":"nya","にゅ":"nyu","にょ":"nyo","ぬ":"nu","ね":"ne","の":"no","は":"ha","ひ":"hi","ふ":"fu","へ":"he","ほ":"ho","ひゃ":"hya","ひゅ":"hyu","ひょ":"hyo","ふぁ":"fa","ふぃ":"fi","ふぇ":"fe","ふぉ":"fo","ば":"ba","び":"bi","ぶ":"bu","べ":"be","ぼ":"bo","びゃ":"bya","びゅ":"byu","びょ":"byo","ぱ":"pa","ぴ":"pi","ぷ":"pu","ぺ":"pe","ぽ":"po","ぴゃ":"pya","ぴゅ":"pyu","ぴょ":"pyo","ま":"ma","み":"mi","む":"mu","め":"me","も":"mo","みゃ":"mya","みゅ":"myu","みょ":"myo","や":"ya","ゆ":"yu","よ":"yo","ら":"ra","り":"ri","る":"ru","れ":"re","ろ":"ro","りゃ":"rya","りゅ":"ryu","りょ":"ryo","わ":"wa","を":"wo","ん":"n","ゐ":"wi","ゑ":"we","きぇ":"kye","きょ":"kyo","じぃ":"jyi","じぇ":"jye","ちぃ":"cyi","ちぇ":"che","ひぃ":"hyi","ひぇ":"hye","びぃ":"byi","びぇ":"bye","ぴぃ":"pyi","ぴぇ":"pye","みぇ":"mye","みぃ":"myi","りぃ":"ryi","りぇ":"rye","にぃ":"nyi","にぇ":"nye","しぃ":"syi","しぇ":"she","いぇ":"ye","うぁ":"wha","うぉ":"who","うぃ":"wi","うぇ":"we","ゔゃ":"vya","ゔゅ":"vyu","ゔょ":"vyo","すぁ":"swa","すぃ":"swi","すぅ":"swu","すぇ":"swe","すぉ":"swo","くゃ":"qya","くゅ":"qyu","くょ":"qyo","くぁ":"qwa","くぃ":"qwi","くぅ":"qwu","くぇ":"qwe","くぉ":"qwo","ぐぁ":"gwa","ぐぃ":"gwi","ぐぅ":"gwu","ぐぇ":"gwe","ぐぉ":"gwo","つぁ":"tsa","つぃ":"tsi","つぇ":"tse","つぉ":"tso","てゃ":"tha","てぃ":"thi","てゅ":"thu","てぇ":"the","てょ":"tho","とぁ":"twa","とぃ":"twi","とぅ":"twu","とぇ":"twe","とぉ":"two","ぢゃ":"dya","ぢぃ":"dyi","ぢゅ":"dyu","ぢぇ":"dye","ぢょ":"dyo","でゃ":"dha","でぃ":"dhi","でゅ":"dhu","でぇ":"dhe","でょ":"dho","どぁ":"dwa","どぃ":"dwi","どぅ":"dwu","どぇ":"dwe","どぉ":"dwo","ふぅ":"fwu","ふゃ":"fya","ふゅ":"fyu","ふょ":"fyo","ぁ":"a","ぃ":"i","ぇ":"e","ぅ":"u","ぉ":"o","ゃ":"ya","ゅ":"yu","ょ":"yo","っ":"","ゕ":"ka","ゖ":"ka","ゎ":"wa","んあ":"n'a","んい":"n'i","んう":"n'u","んえ":"n'e","んお":"n'o","んや":"n'ya","んゆ":"n'yu","んよ":"n'yo"},he=function(){function e(e,n){var t=[],a=!0,r=!1,o=void 0;try{for(var i,u=e[Symbol.iterator]();!(a=(i=u.next()).done)&&(t.push(i.value),!n||t.length!==n);a=!0);}catch(e){r=!0,o=e}finally{try{!a&&u.return&&u.return()}finally{if(r)throw o}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),ce=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);e.length>n;n++)t[n]=e[n];return t}return Array.from(e)},se=["TEXTAREA","INPUT"],fe=[];e.bind=w,e.unbind=p,e.isRomaji=k,e.isJapanese=j,e.isKana=v,e.isHiragana=A,e.isKatakana=x,e.isMixed=z,e.isKanji=C,e.toRomaji=E,e.toKana=g,e.toHiragana=O,e.toKatakana=R,e.stripOkurigana=T,e.tokenize=H,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "wanakana", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -12,3 +12,2 @@ "homepage": "http://www.wanakana.com", | ||
"keywords": [ | ||
"english", | ||
"japanese", | ||
@@ -15,0 +14,0 @@ "hiragana", |
@@ -158,3 +158,3 @@ <div align="center"> | ||
- [Mims H. Wright](https://github.com/mimshwright) – Author | ||
- [Duncan Bay](https://github.com/DJTB) – Contributor | ||
- [Duncan Bay](https://github.com/DJTB) – Author | ||
- [James McNamee](https://github.com/dotfold) – Contributor | ||
@@ -161,0 +161,0 @@ |
@@ -131,3 +131,3 @@ 'use strict'; | ||
kanaChar = _constants.FROM_ROMAJI[chunkLC]; | ||
// console.log(`${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
// console.log(`${chunkLC}, ${cursor}x${chunkSize}:${chunk} => ${kanaChar}`); // DEBUG | ||
if (kanaChar != null) { | ||
@@ -134,0 +134,0 @@ break; |
186234
5075
44